1From 79428c1a372c39ecabf310802bd6025fbfed6971 Mon Sep 17 00:00:00 2001 2From: zhaoshenghua <zhaoshenghua1@huawei.com> 3Date: Tue, 27 Aug 2024 10:33:20 +0800 4Subject: [PATCH 4/4] fix codecheck 5 6Signed-off-by: zhaoshenghua <zhaoshenghua1@huawei.com> 7--- 8 wifi/frameworks/cj/BUILD.gn | 6 +- 9 wifi/frameworks/cj/include/ffi_structs.h | 48 ++--- 10 wifi/frameworks/cj/include/wifi_callback.h | 5 + 11 wifi/frameworks/cj/include/wifi_ffi.h | 27 --- 12 wifi/frameworks/cj/src/wifi_ffi.cpp | 218 ++++++++++++--------- 13 5 files changed, 150 insertions(+), 154 deletions(-) 14 15diff --git a/wifi/frameworks/cj/BUILD.gn b/wifi/frameworks/cj/BUILD.gn 16index a83ae447e..c56e3973c 100644 17--- a/wifi/frameworks/cj/BUILD.gn 18+++ b/wifi/frameworks/cj/BUILD.gn 19@@ -34,12 +34,12 @@ ohos_shared_library("cj_wifi_ffi") { 20 "$WIFI_ROOT_DIR/frameworks/native/src", 21 "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper", 22 "$WIFI_ROOT_DIR/utils/inc", 23- "./include" 24+ "./include", 25 ] 26 27 sources = [ 28- "src/wifi_ffi.cpp", 29 "src/wifi_callback.cpp", 30+ "src/wifi_ffi.cpp", 31 ] 32 33 deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ] 34@@ -67,4 +67,4 @@ ohos_shared_library("cj_wifi_ffi") { 35 innerapi_tags = [ "platformsdk" ] 36 part_name = "wifi" 37 subsystem_name = "communication" 38-} 39\ No newline at end of file 40+} 41diff --git a/wifi/frameworks/cj/include/ffi_structs.h b/wifi/frameworks/cj/include/ffi_structs.h 42index e1f0d9b23..a729dbdcc 100644 43--- a/wifi/frameworks/cj/include/ffi_structs.h 44+++ b/wifi/frameworks/cj/include/ffi_structs.h 45@@ -20,14 +20,12 @@ 46 #include "cj_ffi/cj_common_ffi.h" 47 48 extern "C" { 49- struct CWifiInfoElem 50- { 51+ struct CWifiInfoElem { 52 uint32_t eid; 53 CArrUI8 content; 54 }; 55 56- struct CWifiScanInfo 57- { 58+ struct CWifiScanInfo { 59 char *ssid; 60 char *bssid; 61 int32_t bssidType; 62@@ -46,15 +44,12 @@ extern "C" { 63 bool isHiLinkNetwork; 64 }; 65 66- struct WifiScanInfoArr 67- { 68+ struct WifiScanInfoArr { 69 CWifiScanInfo *head; 70 int64_t size; 71 }; 72 73- // TODO figure out clientCertAlias 74- struct CWifiEapConfig 75- { 76+ struct CWifiEapConfig { 77 int32_t eapMethod; /* EAP authentication mode:PEAP/TLS/TTLS/PWD/SIM/AKA/AKA' */ 78 int32_t phase2Method; /* Second stage authentication method */ 79 char *identity; /* Identity information */ 80@@ -73,16 +68,14 @@ extern "C" { 81 bool isNone; 82 }; 83 84- struct CWifiWapiConfig 85- { 86+ struct CWifiWapiConfig { 87 int32_t wapiPskType; 88 char *wapiAsCert; 89 char *wapiUserCert; 90 bool isNone; 91 }; 92 93- struct CIpInfo 94- { 95+ struct CIpInfo { 96 uint32_t ipAddress; 97 uint32_t gateway; 98 uint32_t netmask; 99@@ -92,8 +85,7 @@ extern "C" { 100 uint32_t leaseDuration; 101 }; 102 103- struct CIpv6Info 104- { 105+ struct CIpv6Info { 106 char *linkIpV6Address; 107 char *globalIpV6Address; 108 char *randomGlobalIpV6Address; 109@@ -105,8 +97,7 @@ extern "C" { 110 char *secondDNS; 111 }; 112 113- struct CWifiP2PConfig 114- { 115+ struct CWifiP2PConfig { 116 char *deviceAddress; 117 char *passphrase; 118 char *groupName; 119@@ -115,15 +106,13 @@ extern "C" { 120 int32_t deviceAddressType; 121 }; 122 123- struct CWifiP2PLinkedInfo 124- { 125+ struct CWifiP2PLinkedInfo { 126 int32_t connectState; 127 bool isGroupOwner; 128 char *groupOwnerAddr; 129 }; 130 131- struct CWifiP2pDevice 132- { 133+ struct CWifiP2pDevice { 134 char *deviceName; 135 char *deviceAddress; 136 char *primaryDeviceType; 137@@ -132,14 +121,12 @@ extern "C" { 138 int32_t deviceAddressType; 139 }; 140 141- struct WifiP2pDeviceArr 142- { 143+ struct WifiP2pDeviceArr { 144 CWifiP2pDevice *head; 145 int64_t size; 146 }; 147 148- struct CWifiP2PGroupInfo 149- { 150+ struct CWifiP2PGroupInfo { 151 bool isP2pGo; 152 CWifiP2pDevice ownerInfo; 153 char *passphrase; 154@@ -152,8 +139,7 @@ extern "C" { 155 char *goIpAddress; 156 }; 157 158- struct CWifiLinkedInfo 159- { 160+ struct CWifiLinkedInfo { 161 char *ssid; 162 char *bssid; 163 int32_t rssi; 164@@ -175,8 +161,7 @@ extern "C" { 165 bool isHiLinkNetwork; 166 }; 167 168- struct CWifiDeviceConfig 169- { 170+ struct CWifiDeviceConfig { 171 int32_t securityType; 172 int32_t bssidType; 173 bool isHiddenSsid; 174@@ -187,13 +172,10 @@ extern "C" { 175 CWifiWapiConfig wapiConfig; 176 }; 177 178- struct WifiDeviceConfigArr 179- { 180+ struct WifiDeviceConfigArr { 181 CWifiDeviceConfig *head; 182 int64_t size; 183 }; 184 } 185 186- 187- 188 #endif // CJ_WIFI_FFI_STRUCTS_H 189\ No newline at end of file 190diff --git a/wifi/frameworks/cj/include/wifi_callback.h b/wifi/frameworks/cj/include/wifi_callback.h 191index dd49d04a9..e0af2d08c 100644 192--- a/wifi/frameworks/cj/include/wifi_callback.h 193+++ b/wifi/frameworks/cj/include/wifi_callback.h 194@@ -13,6 +13,9 @@ 195 * limitations under the License. 196 */ 197 198+#ifndef CJ_WIFI_CALLBACK_H 199+#define CJ_WIFI_CALLBACK_H 200+ 201 #include <shared_mutex> 202 203 #include "ffi_structs.h" 204@@ -63,3 +66,5 @@ private: 205 OHOS::sptr<OHOS::ISystemAbilityStatusChange> mSaStatusListener = nullptr; 206 }; 207 } 208+ 209+#endif 210\ No newline at end of file 211diff --git a/wifi/frameworks/cj/include/wifi_ffi.h b/wifi/frameworks/cj/include/wifi_ffi.h 212index e89d095ad..41eb646e5 100644 213--- a/wifi/frameworks/cj/include/wifi_ffi.h 214+++ b/wifi/frameworks/cj/include/wifi_ffi.h 215@@ -19,33 +19,6 @@ 216 #include "cj_ffi/cj_common_ffi.h" 217 #include "ffi_structs.h" 218 219-char *MallocCString(const std::string &origin); 220- 221-enum class SecTypeCj { 222- /** Invalid security type */ 223- SEC_TYPE_INVALID = 0, 224- /** Open */ 225- SEC_TYPE_OPEN = 1, 226- /** Wired Equivalent Privacy (WEP) */ 227- SEC_TYPE_WEP = 2, 228- /** Pre-shared key (PSK) */ 229- SEC_TYPE_PSK = 3, 230- /** Simultaneous Authentication of Equals (SAE) */ 231- SEC_TYPE_SAE = 4, 232- /** EAP authentication. */ 233- SEC_TYPE_EAP = 5, 234- /** SUITE_B_192 192 bit level. */ 235- SEC_TYPE_EAP_SUITE_B = 6, 236-#ifdef ENABLE_NAPI_WIFI_MANAGER 237- /** Opportunistic Wireless Encryption. */ 238- SEC_TYPE_OWE = 7, 239-#endif 240- /** WAPI certificate to be specified. */ 241- SEC_TYPE_WAPI_CERT = 8, 242- /** WAPI pre-shared key to be specified. */ 243- SEC_TYPE_WAPI_PSK = 9, 244-}; 245- 246 extern "C" { 247 FFI_EXPORT int32_t FfiWifiIsWifiActive(bool &ret); 248 FFI_EXPORT WifiScanInfoArr FfiWifiGetScanInfoList(int32_t &ret); 249diff --git a/wifi/frameworks/cj/src/wifi_ffi.cpp b/wifi/frameworks/cj/src/wifi_ffi.cpp 250index 35f3b10a9..cc88c220b 100644 251--- a/wifi/frameworks/cj/src/wifi_ffi.cpp 252+++ b/wifi/frameworks/cj/src/wifi_ffi.cpp 253@@ -33,6 +33,31 @@ std::shared_ptr<WifiScan> cjWifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILIT 254 std::shared_ptr<WifiP2p> cjWifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID); 255 static const std::string EAP_METHOD[] = { "NONE", "PEAP", "TLS", "TTLS", "PWD", "SIM", "AKA", "AKA'" }; 256 257+enum class SecTypeCj { 258+ /** Invalid security type */ 259+ SEC_TYPE_INVALID = 0, 260+ /** Open */ 261+ SEC_TYPE_OPEN = 1, 262+ /** Wired Equivalent Privacy (WEP) */ 263+ SEC_TYPE_WEP = 2, 264+ /** Pre-shared key (PSK) */ 265+ SEC_TYPE_PSK = 3, 266+ /** Simultaneous Authentication of Equals (SAE) */ 267+ SEC_TYPE_SAE = 4, 268+ /** EAP authentication. */ 269+ SEC_TYPE_EAP = 5, 270+ /** SUITE_B_192 192 bit level. */ 271+ SEC_TYPE_EAP_SUITE_B = 6, 272+#ifdef ENABLE_NAPI_WIFI_MANAGER 273+ /** Opportunistic Wireless Encryption. */ 274+ SEC_TYPE_OWE = 7, 275+#endif 276+ /** WAPI certificate to be specified. */ 277+ SEC_TYPE_WAPI_CERT = 8, 278+ /** WAPI pre-shared key to be specified. */ 279+ SEC_TYPE_WAPI_PSK = 9, 280+}; 281+ 282 static std::string EapMethod2Str(const int& method) 283 { 284 if (method < 0 || method >= static_cast<int>(sizeof(EAP_METHOD) / sizeof(EAP_METHOD[0]))) { 285@@ -133,44 +158,45 @@ static void ProcessPassphrase(const SecTypeCj& securityType, WifiDeviceConfig& c 286 } 287 } 288 289-static void NativeInfoElems2Cj(const std::vector<WifiInfoElem>& infoElems, CWifiScanInfo &info) 290+static void SetInfoElemContent(WifiInfoElem &infoElem, CWifiInfoElem &cinfo) 291 { 292 int valueStep = 2; 293- int64_t size = static_cast<int64_t>(infoElems.size()); 294- if (size > 0) { 295- info.infoElems = static_cast<CWifiInfoElem *>(malloc(sizeof(CWifiInfoElem) * size)); 296- if (info.infoElems == nullptr) { 297- info.elemsSize = 0; 298+ const char *uStr = &infoElem.content[0]; 299+ size_t len = infoElem.content.size(); 300+ size_t inLen = static_cast<size_t>(infoElem.content.size() * valueStep + 1); 301+ char *buf = static_cast<char *>(calloc(inLen + 1, sizeof(char))); 302+ if (buf == nullptr) { 303+ return; 304+ } 305+ int pos = 0; 306+ for (size_t k = 0; k < len; ++k) { 307+ pos = (k << 1); 308+ if (snprintf_s(buf + pos, inLen - pos, inLen - pos - 1, "%02x", uStr[k]) < 0) { 309+ free(buf); 310+ buf = NULL; 311 return; 312 } 313- info.elemsSize = size; 314- for (int64_t i = 0; i < size; i++) { 315- CWifiInfoElem elem; 316- elem.eid = infoElems[i].id; 317- 318- const char *uStr = &infoElems[i].content[0]; 319- size_t len = infoElems[i].content.size(); 320- size_t inLen = static_cast<size_t>(infoElems[i].content.size() * valueStep + 1); 321- char *buf = (char *)calloc(inLen + 1, sizeof(char)); 322- if (buf == nullptr) { 323- elem.content = CArrUI8{.head = nullptr, .size = 0}; 324- info.infoElems[i] = elem; 325- continue; 326- } 327- int pos = 0; 328- for (size_t k = 0; k < len; ++k) { 329- pos = (k << 1); 330- if (snprintf_s(buf + pos, inLen - pos, inLen - pos - 1, "%02x", uStr[k]) < 0) { 331- free(buf); 332- buf = NULL; 333- elem.content = CArrUI8{.head = nullptr, .size = 0}; 334- info.infoElems[i] = elem; 335- continue; 336- } 337- } 338- elem.content = CArrUI8{.head = reinterpret_cast<uint8_t *>(buf), .size = inLen - 1}; // TODO check size 339- info.infoElems[i] = elem; 340- } 341+ } 342+ cinfo.content.head = reinterpret_cast<uint8_t *>(buf); 343+ cinfo.content.size = inLen - 1; 344+} 345+ 346+static void NativeInfoElems2Cj(const std::vector<WifiInfoElem>& infoElems, CWifiScanInfo &info) 347+{ 348+ info.infoElems == nullptr; 349+ info.elemsSize = 0; 350+ int64_t size = static_cast<int64_t>(infoElems.size()); 351+ if (size <= 0) { 352+ return; 353+ } 354+ info.infoElems = static_cast<CWifiInfoElem *>(malloc(sizeof(CWifiInfoElem) * size)); 355+ if (info.infoElems == nullptr) { 356+ return; 357+ } 358+ info.elemsSize = size; 359+ for (int64_t i = 0; i < size; i++) { 360+ info.infoElems[i] = CWifiInfoElem{ .eid = infoElems[i].id, .content = CArrUI8{.head = nullptr, .size = 0}}; 361+ SetInfoElemContent(infoElems[i], info.infoElems[i]); 362 } 363 } 364 365@@ -187,7 +213,7 @@ static int32_t ScanInfo2Cj(const std::vector<WifiScanInfo>& scanInfos, WifiScanI 366 infos.size = size; 367 368 uint32_t idx = 0; 369- for(auto& each : scanInfos) { 370+ for (auto& each : scanInfos) { 371 CWifiScanInfo info; 372 info.ssid = MallocCString(each.ssid); 373 info.bssid = MallocCString(each.bssid); 374@@ -275,6 +301,38 @@ static int Str2EapMethod(const std::string &str) 375 return 0; 376 } 377 378+static void EapConfig2C(WifiEapConfig &wifiEapConfig, CWifiEapConfig &eapConfig) 379+{ 380+ eapConfig.eapMethod = Str2EapMethod(wifiEapConfig.eap); 381+ eapConfig.phase2Method = static_cast<int>(wifiEapConfig.phase2Method); 382+ eapConfig.identity = MallocCString(wifiEapConfig.identity); 383+ eapConfig.anonymousIdentity = MallocCString(wifiEapConfig.anonymousIdentity); 384+ eapConfig.password = MallocCString(wifiEapConfig.password); 385+ eapConfig.caCertAlias = MallocCString(wifiEapConfig.caCertAlias); 386+ eapConfig.caPath = MallocCString(wifiEapConfig.caCertPath); 387+ eapConfig.clientCertAlias = MallocCString(wifiEapConfig.caCertAlias); 388+ CArrUI8 arr{.head = nullptr, .size = 0}; 389+ int64_t size = wifiEapConfig.certEntry.size(); 390+ if (size > 0) { 391+ arr.head = static_cast<uint8_t *>(malloc(sizeof(uint8_t) * size)); 392+ if (arr.head != nullptr) { 393+ uint32_t idx = 0; 394+ for (auto& each : wifiEapConfig.certEntry) { 395+ arr.head[idx] = each; 396+ idx++; 397+ } 398+ } 399+ } 400+ eapConfig.certEntry = arr; 401+ eapConfig.certPassword = MallocCString(wifiEapConfig.certPassword); 402+ eapConfig.altSubjectMatch = MallocCString(wifiEapConfig.altSubjectMatch); 403+ eapConfig.domainSuffixMatch = MallocCString(wifiEapConfig.domainSuffixMatch); 404+ eapConfig.realm = MallocCString(wifiEapConfig.realm); 405+ eapConfig.plmn = MallocCString(wifiEapConfig.plmn); 406+ eapConfig.eapSubId = wifiEapConfig.eapSubId; 407+ eapConfig.isNone = false; 408+} 409+ 410 static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg) 411 { 412 UpdateSecurityTypeAndPreSharedKey(config); 413@@ -288,32 +346,7 @@ static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg) 414 SecTypeCj type = ConvertKeyMgmtToSecType(config.keyMgmt); 415 cfg.securityType = static_cast<int32_t>(type); 416 if (type == SecTypeCj::SEC_TYPE_EAP || type == SecTypeCj::SEC_TYPE_EAP_SUITE_B) { 417- cfg.eapConfig.eapMethod = Str2EapMethod(config.wifiEapConfig.eap); 418- cfg.eapConfig.phase2Method = static_cast<int>(config.wifiEapConfig.phase2Method); 419- cfg.eapConfig.identity = MallocCString(config.wifiEapConfig.identity); 420- cfg.eapConfig.anonymousIdentity = MallocCString(config.wifiEapConfig.anonymousIdentity); 421- cfg.eapConfig.password = MallocCString(config.wifiEapConfig.password); 422- cfg.eapConfig.caCertAlias = MallocCString(config.wifiEapConfig.caCertAlias); 423- cfg.eapConfig.caPath = MallocCString(config.wifiEapConfig.caCertPath); 424- cfg.eapConfig.clientCertAlias = MallocCString(config.wifiEapConfig.caCertAlias); // ? 425- CArrUI8 arr{.head = nullptr, .size = 0}; 426- int64_t size = config.wifiEapConfig.certEntry.size(); 427- arr.head = static_cast<uint8_t *>(malloc(sizeof(uint8_t) * size)); 428- if (arr.head != nullptr) { 429- uint32_t idx = 0; 430- for (auto& each : config.wifiEapConfig.certEntry) { 431- arr.head[idx] = each; 432- idx++; 433- } 434- } 435- cfg.eapConfig.certEntry = arr; 436- cfg.eapConfig.certPassword = MallocCString(config.wifiEapConfig.certPassword); 437- cfg.eapConfig.altSubjectMatch = MallocCString(config.wifiEapConfig.altSubjectMatch); 438- cfg.eapConfig.domainSuffixMatch = MallocCString(config.wifiEapConfig.domainSuffixMatch); 439- cfg.eapConfig.realm = MallocCString(config.wifiEapConfig.realm); 440- cfg.eapConfig.plmn = MallocCString(config.wifiEapConfig.plmn); 441- cfg.eapConfig.eapSubId = config.wifiEapConfig.eapSubId; 442- cfg.eapConfig.isNone = false; 443+ EapConfig2C(config.wifiEapConfig, cfg.eapConfig); 444 } 445 if (type == SecTypeCj::SEC_TYPE_WAPI_CERT || type == SecTypeCj::SEC_TYPE_WAPI_PSK) { 446 cfg.wapiConfig.wapiPskType = config.wifiWapiConfig.wapiPskType; 447@@ -525,31 +558,35 @@ int32_t FfiWifiGetCurrentGroup(CWifiP2PGroupInfo &info) 448 } 449 WifiP2pGroupInfo groupInfo; 450 ErrCode code = cjWifiP2pPtr->GetCurrentGroup(groupInfo); 451- if (code == WIFI_OPT_SUCCESS) { 452- info.isP2pGo = groupInfo.IsGroupOwner(); 453- DeviceInfo2Cj(groupInfo.GetOwner(), info.ownerInfo); 454- info.passphrase = MallocCString(groupInfo.GetPassphrase()); 455- info.interfaceName = MallocCString(groupInfo.GetInterface()); 456- info.groupName = MallocCString(groupInfo.GetGroupName()); 457- info.goIpAddress = MallocCString(groupInfo.GetGoIpAddress()); 458- info.networkId = groupInfo.GetNetworkId(); 459- info.frequency = groupInfo.GetFrequency(); 460- info.clientSize = 0; 461- if (!groupInfo.IsClientDevicesEmpty()) { 462- const std::vector<OHOS::Wifi::WifiP2pDevice>& vecDevices = groupInfo.GetClientDevices(); 463- int64_t size = static_cast<int64_t>(vecDevices.size()); 464- info.clientDevices = static_cast<CWifiP2pDevice *>(malloc(sizeof(CWifiP2pDevice) * size)); 465- if (info.clientDevices != nullptr) { 466- info.clientSize = size; 467- uint32_t idx = 0; 468- for (auto& each : vecDevices) { 469- CWifiP2pDevice device; 470- DeviceInfo2Cj(each, device); 471- info.clientDevices[idx] = device; 472- idx++; 473- } 474- } 475- } 476+ if (code != WIFI_OPT_SUCCESS) { 477+ return code; 478+ } 479+ info.isP2pGo = groupInfo.IsGroupOwner(); 480+ DeviceInfo2Cj(groupInfo.GetOwner(), info.ownerInfo); 481+ info.passphrase = MallocCString(groupInfo.GetPassphrase()); 482+ info.interfaceName = MallocCString(groupInfo.GetInterface()); 483+ info.groupName = MallocCString(groupInfo.GetGroupName()); 484+ info.goIpAddress = MallocCString(groupInfo.GetGoIpAddress()); 485+ info.networkId = groupInfo.GetNetworkId(); 486+ info.frequency = groupInfo.GetFrequency(); 487+ info.clientSize = 0; 488+ info.clientDevices = nullptr; 489+ if (groupInfo.IsClientDevicesEmpty()) { 490+ return code; 491+ } 492+ const std::vector<OHOS::Wifi::WifiP2pDevice>& vecDevices = groupInfo.GetClientDevices(); 493+ int64_t size = static_cast<int64_t>(vecDevices.size()); 494+ info.clientDevices = static_cast<CWifiP2pDevice *>(malloc(sizeof(CWifiP2pDevice) * size)); 495+ if (info.clientDevices == nullptr) { 496+ return code; 497+ } 498+ info.clientSize = size; 499+ uint32_t idx = 0; 500+ for (auto& each : vecDevices) { 501+ CWifiP2pDevice device; 502+ DeviceInfo2Cj(each, device); 503+ info.clientDevices[idx] = device; 504+ idx++; 505 } 506 return code; 507 } 508@@ -669,7 +706,8 @@ int32_t FfiWifiAddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret) 509 config.wifiEapConfig.caCertPath = std::string(cfg.eapConfig.caPath); 510 config.wifiEapConfig.clientCert = std::string(cfg.eapConfig.clientCertAlias); 511 config.wifiEapConfig.privateKey = std::string(cfg.eapConfig.clientCertAlias); 512- config.wifiEapConfig.certEntry = std::vector<uint8_t>(cfg.eapConfig.certEntry.head, cfg.eapConfig.certEntry.head + cfg.eapConfig.certEntry.size); 513+ config.wifiEapConfig.certEntry = std::vector<uint8_t>(cfg.eapConfig.certEntry.head, 514+ cfg.eapConfig.certEntry.head + cfg.eapConfig.certEntry.size); 515 if (strncpy_s(config.wifiEapConfig.certPassword, sizeof(config.wifiEapConfig.certPassword), 516 cfg.eapConfig.certPassword, strlen(cfg.eapConfig.certPassword)) != EOK) { 517 WIFI_LOGE("%{public}s: failed to copy", __func__); 518@@ -706,14 +744,13 @@ WifiDeviceConfigArr FfiWifiGetCandidateConfigs(int32_t &code) 519 int64_t size = static_cast<int64_t>(vecDeviceConfigs.size()); 520 if (code == WIFI_OPT_SUCCESS && size > 0) { 521 WIFI_LOGI("Get candidate device configs size: %{public}zu", vecDeviceConfigs.size()); 522- // transform 523 arr.head = static_cast<CWifiDeviceConfig *>(malloc(sizeof(CWifiDeviceConfig) * size)); 524 if (arr.head == nullptr) { 525 code = WIFI_OPT_FAILED; 526 return arr; 527 } 528 arr.size = size; 529- for(int64_t i = 0; i < size; i++) { 530+ for (int64_t i = 0; i < size; i++) { 531 CWifiDeviceConfig cfg; 532 DeviceConfig2C(vecDeviceConfigs[i], cfg); 533 arr.head[i] = cfg; 534@@ -739,6 +776,5 @@ int32_t FfiWifiWifiOff(char* type) 535 } 536 return CjEventRegister::GetInstance().UnRegister(eventType); 537 } 538- 539 } 540-} 541\ No newline at end of file 542+} //OHOS::Wifi 543\ No newline at end of file 544-- 5452.34.1 546 547