代码拉取完成,页面将自动刷新
From 79428c1a372c39ecabf310802bd6025fbfed6971 Mon Sep 17 00:00:00 2001
From: zhaoshenghua <zhaoshenghua1@huawei.com>
Date: Tue, 27 Aug 2024 10:33:20 +0800
Subject: [PATCH 4/4] fix codecheck
Signed-off-by: zhaoshenghua <zhaoshenghua1@huawei.com>
---
wifi/frameworks/cj/BUILD.gn | 6 +-
wifi/frameworks/cj/include/ffi_structs.h | 48 ++---
wifi/frameworks/cj/include/wifi_callback.h | 5 +
wifi/frameworks/cj/include/wifi_ffi.h | 27 ---
wifi/frameworks/cj/src/wifi_ffi.cpp | 218 ++++++++++++---------
5 files changed, 150 insertions(+), 154 deletions(-)
diff --git a/wifi/frameworks/cj/BUILD.gn b/wifi/frameworks/cj/BUILD.gn
index a83ae447e..c56e3973c 100644
--- a/wifi/frameworks/cj/BUILD.gn
+++ b/wifi/frameworks/cj/BUILD.gn
@@ -34,12 +34,12 @@ ohos_shared_library("cj_wifi_ffi") {
"$WIFI_ROOT_DIR/frameworks/native/src",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
"$WIFI_ROOT_DIR/utils/inc",
- "./include"
+ "./include",
]
sources = [
- "src/wifi_ffi.cpp",
"src/wifi_callback.cpp",
+ "src/wifi_ffi.cpp",
]
deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ]
@@ -67,4 +67,4 @@ ohos_shared_library("cj_wifi_ffi") {
innerapi_tags = [ "platformsdk" ]
part_name = "wifi"
subsystem_name = "communication"
-}
\ No newline at end of file
+}
diff --git a/wifi/frameworks/cj/include/ffi_structs.h b/wifi/frameworks/cj/include/ffi_structs.h
index e1f0d9b23..a729dbdcc 100644
--- a/wifi/frameworks/cj/include/ffi_structs.h
+++ b/wifi/frameworks/cj/include/ffi_structs.h
@@ -20,14 +20,12 @@
#include "cj_ffi/cj_common_ffi.h"
extern "C" {
- struct CWifiInfoElem
- {
+ struct CWifiInfoElem {
uint32_t eid;
CArrUI8 content;
};
- struct CWifiScanInfo
- {
+ struct CWifiScanInfo {
char *ssid;
char *bssid;
int32_t bssidType;
@@ -46,15 +44,12 @@ extern "C" {
bool isHiLinkNetwork;
};
- struct WifiScanInfoArr
- {
+ struct WifiScanInfoArr {
CWifiScanInfo *head;
int64_t size;
};
- // TODO figure out clientCertAlias
- struct CWifiEapConfig
- {
+ struct CWifiEapConfig {
int32_t eapMethod; /* EAP authentication mode:PEAP/TLS/TTLS/PWD/SIM/AKA/AKA' */
int32_t phase2Method; /* Second stage authentication method */
char *identity; /* Identity information */
@@ -73,16 +68,14 @@ extern "C" {
bool isNone;
};
- struct CWifiWapiConfig
- {
+ struct CWifiWapiConfig {
int32_t wapiPskType;
char *wapiAsCert;
char *wapiUserCert;
bool isNone;
};
- struct CIpInfo
- {
+ struct CIpInfo {
uint32_t ipAddress;
uint32_t gateway;
uint32_t netmask;
@@ -92,8 +85,7 @@ extern "C" {
uint32_t leaseDuration;
};
- struct CIpv6Info
- {
+ struct CIpv6Info {
char *linkIpV6Address;
char *globalIpV6Address;
char *randomGlobalIpV6Address;
@@ -105,8 +97,7 @@ extern "C" {
char *secondDNS;
};
- struct CWifiP2PConfig
- {
+ struct CWifiP2PConfig {
char *deviceAddress;
char *passphrase;
char *groupName;
@@ -115,15 +106,13 @@ extern "C" {
int32_t deviceAddressType;
};
- struct CWifiP2PLinkedInfo
- {
+ struct CWifiP2PLinkedInfo {
int32_t connectState;
bool isGroupOwner;
char *groupOwnerAddr;
};
- struct CWifiP2pDevice
- {
+ struct CWifiP2pDevice {
char *deviceName;
char *deviceAddress;
char *primaryDeviceType;
@@ -132,14 +121,12 @@ extern "C" {
int32_t deviceAddressType;
};
- struct WifiP2pDeviceArr
- {
+ struct WifiP2pDeviceArr {
CWifiP2pDevice *head;
int64_t size;
};
- struct CWifiP2PGroupInfo
- {
+ struct CWifiP2PGroupInfo {
bool isP2pGo;
CWifiP2pDevice ownerInfo;
char *passphrase;
@@ -152,8 +139,7 @@ extern "C" {
char *goIpAddress;
};
- struct CWifiLinkedInfo
- {
+ struct CWifiLinkedInfo {
char *ssid;
char *bssid;
int32_t rssi;
@@ -175,8 +161,7 @@ extern "C" {
bool isHiLinkNetwork;
};
- struct CWifiDeviceConfig
- {
+ struct CWifiDeviceConfig {
int32_t securityType;
int32_t bssidType;
bool isHiddenSsid;
@@ -187,13 +172,10 @@ extern "C" {
CWifiWapiConfig wapiConfig;
};
- struct WifiDeviceConfigArr
- {
+ struct WifiDeviceConfigArr {
CWifiDeviceConfig *head;
int64_t size;
};
}
-
-
#endif // CJ_WIFI_FFI_STRUCTS_H
\ No newline at end of file
diff --git a/wifi/frameworks/cj/include/wifi_callback.h b/wifi/frameworks/cj/include/wifi_callback.h
index dd49d04a9..e0af2d08c 100644
--- a/wifi/frameworks/cj/include/wifi_callback.h
+++ b/wifi/frameworks/cj/include/wifi_callback.h
@@ -13,6 +13,9 @@
* limitations under the License.
*/
+#ifndef CJ_WIFI_CALLBACK_H
+#define CJ_WIFI_CALLBACK_H
+
#include <shared_mutex>
#include "ffi_structs.h"
@@ -63,3 +66,5 @@ private:
OHOS::sptr<OHOS::ISystemAbilityStatusChange> mSaStatusListener = nullptr;
};
}
+
+#endif
\ No newline at end of file
diff --git a/wifi/frameworks/cj/include/wifi_ffi.h b/wifi/frameworks/cj/include/wifi_ffi.h
index e89d095ad..41eb646e5 100644
--- a/wifi/frameworks/cj/include/wifi_ffi.h
+++ b/wifi/frameworks/cj/include/wifi_ffi.h
@@ -19,33 +19,6 @@
#include "cj_ffi/cj_common_ffi.h"
#include "ffi_structs.h"
-char *MallocCString(const std::string &origin);
-
-enum class SecTypeCj {
- /** Invalid security type */
- SEC_TYPE_INVALID = 0,
- /** Open */
- SEC_TYPE_OPEN = 1,
- /** Wired Equivalent Privacy (WEP) */
- SEC_TYPE_WEP = 2,
- /** Pre-shared key (PSK) */
- SEC_TYPE_PSK = 3,
- /** Simultaneous Authentication of Equals (SAE) */
- SEC_TYPE_SAE = 4,
- /** EAP authentication. */
- SEC_TYPE_EAP = 5,
- /** SUITE_B_192 192 bit level. */
- SEC_TYPE_EAP_SUITE_B = 6,
-#ifdef ENABLE_NAPI_WIFI_MANAGER
- /** Opportunistic Wireless Encryption. */
- SEC_TYPE_OWE = 7,
-#endif
- /** WAPI certificate to be specified. */
- SEC_TYPE_WAPI_CERT = 8,
- /** WAPI pre-shared key to be specified. */
- SEC_TYPE_WAPI_PSK = 9,
-};
-
extern "C" {
FFI_EXPORT int32_t FfiWifiIsWifiActive(bool &ret);
FFI_EXPORT WifiScanInfoArr FfiWifiGetScanInfoList(int32_t &ret);
diff --git a/wifi/frameworks/cj/src/wifi_ffi.cpp b/wifi/frameworks/cj/src/wifi_ffi.cpp
index 35f3b10a9..cc88c220b 100644
--- a/wifi/frameworks/cj/src/wifi_ffi.cpp
+++ b/wifi/frameworks/cj/src/wifi_ffi.cpp
@@ -33,6 +33,31 @@ std::shared_ptr<WifiScan> cjWifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILIT
std::shared_ptr<WifiP2p> cjWifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
static const std::string EAP_METHOD[] = { "NONE", "PEAP", "TLS", "TTLS", "PWD", "SIM", "AKA", "AKA'" };
+enum class SecTypeCj {
+ /** Invalid security type */
+ SEC_TYPE_INVALID = 0,
+ /** Open */
+ SEC_TYPE_OPEN = 1,
+ /** Wired Equivalent Privacy (WEP) */
+ SEC_TYPE_WEP = 2,
+ /** Pre-shared key (PSK) */
+ SEC_TYPE_PSK = 3,
+ /** Simultaneous Authentication of Equals (SAE) */
+ SEC_TYPE_SAE = 4,
+ /** EAP authentication. */
+ SEC_TYPE_EAP = 5,
+ /** SUITE_B_192 192 bit level. */
+ SEC_TYPE_EAP_SUITE_B = 6,
+#ifdef ENABLE_NAPI_WIFI_MANAGER
+ /** Opportunistic Wireless Encryption. */
+ SEC_TYPE_OWE = 7,
+#endif
+ /** WAPI certificate to be specified. */
+ SEC_TYPE_WAPI_CERT = 8,
+ /** WAPI pre-shared key to be specified. */
+ SEC_TYPE_WAPI_PSK = 9,
+};
+
static std::string EapMethod2Str(const int& method)
{
if (method < 0 || method >= static_cast<int>(sizeof(EAP_METHOD) / sizeof(EAP_METHOD[0]))) {
@@ -133,44 +158,45 @@ static void ProcessPassphrase(const SecTypeCj& securityType, WifiDeviceConfig& c
}
}
-static void NativeInfoElems2Cj(const std::vector<WifiInfoElem>& infoElems, CWifiScanInfo &info)
+static void SetInfoElemContent(WifiInfoElem &infoElem, CWifiInfoElem &cinfo)
{
int valueStep = 2;
- int64_t size = static_cast<int64_t>(infoElems.size());
- if (size > 0) {
- info.infoElems = static_cast<CWifiInfoElem *>(malloc(sizeof(CWifiInfoElem) * size));
- if (info.infoElems == nullptr) {
- info.elemsSize = 0;
+ const char *uStr = &infoElem.content[0];
+ size_t len = infoElem.content.size();
+ size_t inLen = static_cast<size_t>(infoElem.content.size() * valueStep + 1);
+ char *buf = static_cast<char *>(calloc(inLen + 1, sizeof(char)));
+ if (buf == nullptr) {
+ return;
+ }
+ int pos = 0;
+ for (size_t k = 0; k < len; ++k) {
+ pos = (k << 1);
+ if (snprintf_s(buf + pos, inLen - pos, inLen - pos - 1, "%02x", uStr[k]) < 0) {
+ free(buf);
+ buf = NULL;
return;
}
- info.elemsSize = size;
- for (int64_t i = 0; i < size; i++) {
- CWifiInfoElem elem;
- elem.eid = infoElems[i].id;
-
- const char *uStr = &infoElems[i].content[0];
- size_t len = infoElems[i].content.size();
- size_t inLen = static_cast<size_t>(infoElems[i].content.size() * valueStep + 1);
- char *buf = (char *)calloc(inLen + 1, sizeof(char));
- if (buf == nullptr) {
- elem.content = CArrUI8{.head = nullptr, .size = 0};
- info.infoElems[i] = elem;
- continue;
- }
- int pos = 0;
- for (size_t k = 0; k < len; ++k) {
- pos = (k << 1);
- if (snprintf_s(buf + pos, inLen - pos, inLen - pos - 1, "%02x", uStr[k]) < 0) {
- free(buf);
- buf = NULL;
- elem.content = CArrUI8{.head = nullptr, .size = 0};
- info.infoElems[i] = elem;
- continue;
- }
- }
- elem.content = CArrUI8{.head = reinterpret_cast<uint8_t *>(buf), .size = inLen - 1}; // TODO check size
- info.infoElems[i] = elem;
- }
+ }
+ cinfo.content.head = reinterpret_cast<uint8_t *>(buf);
+ cinfo.content.size = inLen - 1;
+}
+
+static void NativeInfoElems2Cj(const std::vector<WifiInfoElem>& infoElems, CWifiScanInfo &info)
+{
+ info.infoElems == nullptr;
+ info.elemsSize = 0;
+ int64_t size = static_cast<int64_t>(infoElems.size());
+ if (size <= 0) {
+ return;
+ }
+ info.infoElems = static_cast<CWifiInfoElem *>(malloc(sizeof(CWifiInfoElem) * size));
+ if (info.infoElems == nullptr) {
+ return;
+ }
+ info.elemsSize = size;
+ for (int64_t i = 0; i < size; i++) {
+ info.infoElems[i] = CWifiInfoElem{ .eid = infoElems[i].id, .content = CArrUI8{.head = nullptr, .size = 0}};
+ SetInfoElemContent(infoElems[i], info.infoElems[i]);
}
}
@@ -187,7 +213,7 @@ static int32_t ScanInfo2Cj(const std::vector<WifiScanInfo>& scanInfos, WifiScanI
infos.size = size;
uint32_t idx = 0;
- for(auto& each : scanInfos) {
+ for (auto& each : scanInfos) {
CWifiScanInfo info;
info.ssid = MallocCString(each.ssid);
info.bssid = MallocCString(each.bssid);
@@ -275,6 +301,38 @@ static int Str2EapMethod(const std::string &str)
return 0;
}
+static void EapConfig2C(WifiEapConfig &wifiEapConfig, CWifiEapConfig &eapConfig)
+{
+ eapConfig.eapMethod = Str2EapMethod(wifiEapConfig.eap);
+ eapConfig.phase2Method = static_cast<int>(wifiEapConfig.phase2Method);
+ eapConfig.identity = MallocCString(wifiEapConfig.identity);
+ eapConfig.anonymousIdentity = MallocCString(wifiEapConfig.anonymousIdentity);
+ eapConfig.password = MallocCString(wifiEapConfig.password);
+ eapConfig.caCertAlias = MallocCString(wifiEapConfig.caCertAlias);
+ eapConfig.caPath = MallocCString(wifiEapConfig.caCertPath);
+ eapConfig.clientCertAlias = MallocCString(wifiEapConfig.caCertAlias);
+ CArrUI8 arr{.head = nullptr, .size = 0};
+ int64_t size = wifiEapConfig.certEntry.size();
+ if (size > 0) {
+ arr.head = static_cast<uint8_t *>(malloc(sizeof(uint8_t) * size));
+ if (arr.head != nullptr) {
+ uint32_t idx = 0;
+ for (auto& each : wifiEapConfig.certEntry) {
+ arr.head[idx] = each;
+ idx++;
+ }
+ }
+ }
+ eapConfig.certEntry = arr;
+ eapConfig.certPassword = MallocCString(wifiEapConfig.certPassword);
+ eapConfig.altSubjectMatch = MallocCString(wifiEapConfig.altSubjectMatch);
+ eapConfig.domainSuffixMatch = MallocCString(wifiEapConfig.domainSuffixMatch);
+ eapConfig.realm = MallocCString(wifiEapConfig.realm);
+ eapConfig.plmn = MallocCString(wifiEapConfig.plmn);
+ eapConfig.eapSubId = wifiEapConfig.eapSubId;
+ eapConfig.isNone = false;
+}
+
static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg)
{
UpdateSecurityTypeAndPreSharedKey(config);
@@ -288,32 +346,7 @@ static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg)
SecTypeCj type = ConvertKeyMgmtToSecType(config.keyMgmt);
cfg.securityType = static_cast<int32_t>(type);
if (type == SecTypeCj::SEC_TYPE_EAP || type == SecTypeCj::SEC_TYPE_EAP_SUITE_B) {
- cfg.eapConfig.eapMethod = Str2EapMethod(config.wifiEapConfig.eap);
- cfg.eapConfig.phase2Method = static_cast<int>(config.wifiEapConfig.phase2Method);
- cfg.eapConfig.identity = MallocCString(config.wifiEapConfig.identity);
- cfg.eapConfig.anonymousIdentity = MallocCString(config.wifiEapConfig.anonymousIdentity);
- cfg.eapConfig.password = MallocCString(config.wifiEapConfig.password);
- cfg.eapConfig.caCertAlias = MallocCString(config.wifiEapConfig.caCertAlias);
- cfg.eapConfig.caPath = MallocCString(config.wifiEapConfig.caCertPath);
- cfg.eapConfig.clientCertAlias = MallocCString(config.wifiEapConfig.caCertAlias); // ?
- CArrUI8 arr{.head = nullptr, .size = 0};
- int64_t size = config.wifiEapConfig.certEntry.size();
- arr.head = static_cast<uint8_t *>(malloc(sizeof(uint8_t) * size));
- if (arr.head != nullptr) {
- uint32_t idx = 0;
- for (auto& each : config.wifiEapConfig.certEntry) {
- arr.head[idx] = each;
- idx++;
- }
- }
- cfg.eapConfig.certEntry = arr;
- cfg.eapConfig.certPassword = MallocCString(config.wifiEapConfig.certPassword);
- cfg.eapConfig.altSubjectMatch = MallocCString(config.wifiEapConfig.altSubjectMatch);
- cfg.eapConfig.domainSuffixMatch = MallocCString(config.wifiEapConfig.domainSuffixMatch);
- cfg.eapConfig.realm = MallocCString(config.wifiEapConfig.realm);
- cfg.eapConfig.plmn = MallocCString(config.wifiEapConfig.plmn);
- cfg.eapConfig.eapSubId = config.wifiEapConfig.eapSubId;
- cfg.eapConfig.isNone = false;
+ EapConfig2C(config.wifiEapConfig, cfg.eapConfig);
}
if (type == SecTypeCj::SEC_TYPE_WAPI_CERT || type == SecTypeCj::SEC_TYPE_WAPI_PSK) {
cfg.wapiConfig.wapiPskType = config.wifiWapiConfig.wapiPskType;
@@ -525,31 +558,35 @@ int32_t FfiWifiGetCurrentGroup(CWifiP2PGroupInfo &info)
}
WifiP2pGroupInfo groupInfo;
ErrCode code = cjWifiP2pPtr->GetCurrentGroup(groupInfo);
- if (code == WIFI_OPT_SUCCESS) {
- info.isP2pGo = groupInfo.IsGroupOwner();
- DeviceInfo2Cj(groupInfo.GetOwner(), info.ownerInfo);
- info.passphrase = MallocCString(groupInfo.GetPassphrase());
- info.interfaceName = MallocCString(groupInfo.GetInterface());
- info.groupName = MallocCString(groupInfo.GetGroupName());
- info.goIpAddress = MallocCString(groupInfo.GetGoIpAddress());
- info.networkId = groupInfo.GetNetworkId();
- info.frequency = groupInfo.GetFrequency();
- info.clientSize = 0;
- if (!groupInfo.IsClientDevicesEmpty()) {
- const std::vector<OHOS::Wifi::WifiP2pDevice>& vecDevices = groupInfo.GetClientDevices();
- int64_t size = static_cast<int64_t>(vecDevices.size());
- info.clientDevices = static_cast<CWifiP2pDevice *>(malloc(sizeof(CWifiP2pDevice) * size));
- if (info.clientDevices != nullptr) {
- info.clientSize = size;
- uint32_t idx = 0;
- for (auto& each : vecDevices) {
- CWifiP2pDevice device;
- DeviceInfo2Cj(each, device);
- info.clientDevices[idx] = device;
- idx++;
- }
- }
- }
+ if (code != WIFI_OPT_SUCCESS) {
+ return code;
+ }
+ info.isP2pGo = groupInfo.IsGroupOwner();
+ DeviceInfo2Cj(groupInfo.GetOwner(), info.ownerInfo);
+ info.passphrase = MallocCString(groupInfo.GetPassphrase());
+ info.interfaceName = MallocCString(groupInfo.GetInterface());
+ info.groupName = MallocCString(groupInfo.GetGroupName());
+ info.goIpAddress = MallocCString(groupInfo.GetGoIpAddress());
+ info.networkId = groupInfo.GetNetworkId();
+ info.frequency = groupInfo.GetFrequency();
+ info.clientSize = 0;
+ info.clientDevices = nullptr;
+ if (groupInfo.IsClientDevicesEmpty()) {
+ return code;
+ }
+ const std::vector<OHOS::Wifi::WifiP2pDevice>& vecDevices = groupInfo.GetClientDevices();
+ int64_t size = static_cast<int64_t>(vecDevices.size());
+ info.clientDevices = static_cast<CWifiP2pDevice *>(malloc(sizeof(CWifiP2pDevice) * size));
+ if (info.clientDevices == nullptr) {
+ return code;
+ }
+ info.clientSize = size;
+ uint32_t idx = 0;
+ for (auto& each : vecDevices) {
+ CWifiP2pDevice device;
+ DeviceInfo2Cj(each, device);
+ info.clientDevices[idx] = device;
+ idx++;
}
return code;
}
@@ -669,7 +706,8 @@ int32_t FfiWifiAddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret)
config.wifiEapConfig.caCertPath = std::string(cfg.eapConfig.caPath);
config.wifiEapConfig.clientCert = std::string(cfg.eapConfig.clientCertAlias);
config.wifiEapConfig.privateKey = std::string(cfg.eapConfig.clientCertAlias);
- config.wifiEapConfig.certEntry = std::vector<uint8_t>(cfg.eapConfig.certEntry.head, cfg.eapConfig.certEntry.head + cfg.eapConfig.certEntry.size);
+ config.wifiEapConfig.certEntry = std::vector<uint8_t>(cfg.eapConfig.certEntry.head,
+ cfg.eapConfig.certEntry.head + cfg.eapConfig.certEntry.size);
if (strncpy_s(config.wifiEapConfig.certPassword, sizeof(config.wifiEapConfig.certPassword),
cfg.eapConfig.certPassword, strlen(cfg.eapConfig.certPassword)) != EOK) {
WIFI_LOGE("%{public}s: failed to copy", __func__);
@@ -706,14 +744,13 @@ WifiDeviceConfigArr FfiWifiGetCandidateConfigs(int32_t &code)
int64_t size = static_cast<int64_t>(vecDeviceConfigs.size());
if (code == WIFI_OPT_SUCCESS && size > 0) {
WIFI_LOGI("Get candidate device configs size: %{public}zu", vecDeviceConfigs.size());
- // transform
arr.head = static_cast<CWifiDeviceConfig *>(malloc(sizeof(CWifiDeviceConfig) * size));
if (arr.head == nullptr) {
code = WIFI_OPT_FAILED;
return arr;
}
arr.size = size;
- for(int64_t i = 0; i < size; i++) {
+ for (int64_t i = 0; i < size; i++) {
CWifiDeviceConfig cfg;
DeviceConfig2C(vecDeviceConfigs[i], cfg);
arr.head[i] = cfg;
@@ -739,6 +776,5 @@ int32_t FfiWifiWifiOff(char* type)
}
return CjEventRegister::GetInstance().UnRegister(eventType);
}
-
}
-}
\ No newline at end of file
+} //OHOS::Wifi
\ No newline at end of file
--
2.34.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。