mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-11-27 01:01:03 +00:00
fix codecheck
Signed-off-by: zhaoshenghua <zhaoshenghua1@huawei.com>
This commit is contained in:
parent
a4a810d20f
commit
2d9c5b9063
1144
0001-wifi.patch
Normal file
1144
0001-wifi.patch
Normal file
File diff suppressed because it is too large
Load Diff
742
0002-callback.patch
Normal file
742
0002-callback.patch
Normal file
@ -0,0 +1,742 @@
|
|||||||
|
From cfc04fdab06a83cae0737b5a1b8ca8f6dfc21fbf Mon Sep 17 00:00:00 2001
|
||||||
|
From: zhaoshenghua <zhaoshenghua1@huawei.com>
|
||||||
|
Date: Thu, 15 Aug 2024 19:27:45 +0800
|
||||||
|
Subject: [PATCH 2/4] callback
|
||||||
|
|
||||||
|
Change-Id: Ib59d9795eb4d154e06dc2615285cbd86f7683bb7
|
||||||
|
Signed-off-by: zhaoshenghua <zhaoshenghua1@huawei.com>
|
||||||
|
---
|
||||||
|
wifi/frameworks/cj/BUILD.gn | 1 +
|
||||||
|
wifi/frameworks/cj/include/ffi_structs.h | 6 +-
|
||||||
|
wifi/frameworks/cj/include/wifi_callback.h | 80 +++
|
||||||
|
wifi/frameworks/cj/include/wifi_ffi.h | 2 +-
|
||||||
|
wifi/frameworks/cj/src/wifi_callback.cpp | 534 +++++++++++++++++++++
|
||||||
|
wifi/frameworks/cj/src/wifi_ffi.cpp | 15 +-
|
||||||
|
6 files changed, 631 insertions(+), 7 deletions(-)
|
||||||
|
create mode 100644 wifi/frameworks/cj/include/wifi_callback.h
|
||||||
|
create mode 100644 wifi/frameworks/cj/src/wifi_callback.cpp
|
||||||
|
|
||||||
|
diff --git a/wifi/frameworks/cj/BUILD.gn b/wifi/frameworks/cj/BUILD.gn
|
||||||
|
index 71fed17cc..a83ae447e 100644
|
||||||
|
--- a/wifi/frameworks/cj/BUILD.gn
|
||||||
|
+++ b/wifi/frameworks/cj/BUILD.gn
|
||||||
|
@@ -39,6 +39,7 @@ ohos_shared_library("cj_wifi_ffi") {
|
||||||
|
|
||||||
|
sources = [
|
||||||
|
"src/wifi_ffi.cpp",
|
||||||
|
+ "src/wifi_callback.cpp",
|
||||||
|
]
|
||||||
|
|
||||||
|
deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ]
|
||||||
|
diff --git a/wifi/frameworks/cj/include/ffi_structs.h b/wifi/frameworks/cj/include/ffi_structs.h
|
||||||
|
index ca174fecf..e1f0d9b23 100644
|
||||||
|
--- a/wifi/frameworks/cj/include/ffi_structs.h
|
||||||
|
+++ b/wifi/frameworks/cj/include/ffi_structs.h
|
||||||
|
@@ -45,14 +45,14 @@ extern "C" {
|
||||||
|
int32_t supportedWifiCategory;
|
||||||
|
bool isHiLinkNetwork;
|
||||||
|
};
|
||||||
|
-
|
||||||
|
+
|
||||||
|
struct WifiScanInfoArr
|
||||||
|
{
|
||||||
|
CWifiScanInfo *head;
|
||||||
|
int64_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
- // TODO figure out clientCert
|
||||||
|
+ // TODO figure out clientCertAlias
|
||||||
|
struct CWifiEapConfig
|
||||||
|
{
|
||||||
|
int32_t eapMethod; /* EAP authentication mode:PEAP/TLS/TTLS/PWD/SIM/AKA/AKA' */
|
||||||
|
@@ -112,7 +112,7 @@ extern "C" {
|
||||||
|
char *groupName;
|
||||||
|
int32_t netId;
|
||||||
|
int32_t goBand;
|
||||||
|
- int32_t deviceAddressType;
|
||||||
|
+ int32_t deviceAddressType;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CWifiP2PLinkedInfo
|
||||||
|
diff --git a/wifi/frameworks/cj/include/wifi_callback.h b/wifi/frameworks/cj/include/wifi_callback.h
|
||||||
|
new file mode 100644
|
||||||
|
index 000000000..7039f9605
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/wifi/frameworks/cj/include/wifi_callback.h
|
||||||
|
@@ -0,0 +1,80 @@
|
||||||
|
+/*
|
||||||
|
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||||
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
+ * you may not use this file except in compliance with the License.
|
||||||
|
+ * You may obtain a copy of the License at
|
||||||
|
+ *
|
||||||
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
+ *
|
||||||
|
+ * Unless required by applicable law or agreed to in writing, software
|
||||||
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
+ * See the License for the specific language governing permissions and
|
||||||
|
+ * limitations under the License.
|
||||||
|
+ */
|
||||||
|
+
|
||||||
|
+#include <shared_mutex>
|
||||||
|
+
|
||||||
|
+#include "ffi_structs.h"
|
||||||
|
+#include "wifi_errcode.h"
|
||||||
|
+#include "wifi_p2p.h"
|
||||||
|
+#include "wifi_hotspot.h"
|
||||||
|
+#include "wifi_logger.h"
|
||||||
|
+#include "wifi_sa_event.h"
|
||||||
|
+
|
||||||
|
+namespace OHOS::Wifi {
|
||||||
|
+
|
||||||
|
+class CjWifiAbilityStatusChange : public WifiAbilityStatusChange {
|
||||||
|
+public:
|
||||||
|
+ void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+class CjEventRegister {
|
||||||
|
+public:
|
||||||
|
+ CjEventRegister()
|
||||||
|
+ {
|
||||||
|
+ int32_t ret;
|
||||||
|
+ auto samgrProxy = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||||
|
+ if (samgrProxy == nullptr) {
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ mSaStatusListener = new OHOS::Wifi::CjWifiAbilityStatusChange();
|
||||||
|
+ if (mSaStatusListener == nullptr) {
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ ret = samgrProxy->SubscribeSystemAbility((int32_t)WIFI_DEVICE_ABILITY_ID, mSaStatusListener);
|
||||||
|
+ samgrProxy->SubscribeSystemAbility((int32_t)WIFI_SCAN_ABILITY_ID, mSaStatusListener);
|
||||||
|
+ samgrProxy->SubscribeSystemAbility((int32_t)WIFI_HOTSPOT_ABILITY_ID, mSaStatusListener);
|
||||||
|
+ samgrProxy->SubscribeSystemAbility((int32_t)WIFI_P2P_ABILITY_ID, mSaStatusListener);
|
||||||
|
+ }
|
||||||
|
+ ~CjEventRegister()
|
||||||
|
+ {}
|
||||||
|
+
|
||||||
|
+ static CjEventRegister& GetInstance();
|
||||||
|
+
|
||||||
|
+ int32_t Register(const std::string& type, void (* callback)());
|
||||||
|
+ int32_t UnRegister(const std::string& type);
|
||||||
|
+ ErrCode RegisterDeviceEvents(const std::vector<std::string> &event);
|
||||||
|
+ ErrCode RegisterScanEvents(const std::vector<std::string> &event);
|
||||||
|
+ ErrCode RegisterHotspotEvents(const std::vector<std::string> &event);
|
||||||
|
+ ErrCode RegisterP2PEvents(const std::vector<std::string> &event);
|
||||||
|
+
|
||||||
|
+private:
|
||||||
|
+ // std::function<void(int32_t)> wifiStateChange{nullptr};
|
||||||
|
+ // std::function<void(int32_t)> wifiConnectionChange{nullptr};
|
||||||
|
+ // std::function<void(int32_t)> wifiRssiChange{nullptr};
|
||||||
|
+ // std::function<void(int32_t)> wifiScanStateChange{nullptr};
|
||||||
|
+ // std::function<void(int32_t)> hotspotStateChange{nullptr};
|
||||||
|
+ // std::function<void(int32_t)> p2pStateChange{nullptr};
|
||||||
|
+ // std::function<void(CWifiP2PLinkedInfo)> p2pConnectionChange{nullptr};
|
||||||
|
+ // std::function<void(CWifiP2pDevice)> p2pDeviceChange{nullptr};
|
||||||
|
+ // std::function<void(WifiP2pDeviceArr)> p2pPeerDeviceChange{nullptr};
|
||||||
|
+ // std::function<void()> p2pPersistentGroupChange{nullptr};
|
||||||
|
+ // std::function<void(int32_t)> p2pDiscoveryChange{nullptr};
|
||||||
|
+ OHOS::sptr<OHOS::ISystemAbilityStatusChange> mSaStatusListener = nullptr;
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+}
|
||||||
|
\ 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 5525813ed..f7f59dcb9 100644
|
||||||
|
--- a/wifi/frameworks/cj/include/wifi_ffi.h
|
||||||
|
+++ b/wifi/frameworks/cj/include/wifi_ffi.h
|
||||||
|
@@ -72,7 +72,7 @@ FFI_EXPORT int32_t CJ_CreateGroup(CWifiP2PConfig &cfg);
|
||||||
|
FFI_EXPORT int32_t CJ_GetLinkedInfo(CWifiLinkedInfo &info);
|
||||||
|
FFI_EXPORT int32_t CJ_AddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret);
|
||||||
|
FFI_EXPORT WifiDeviceConfigArr CJ_GetCandidateConfigs(int32_t &code);
|
||||||
|
-FFI_EXPORT int32_t CJ_WifiOn(char *type, int64_t id);
|
||||||
|
+FFI_EXPORT int32_t CJ_WifiOn(char *type, void (*callback)());
|
||||||
|
FFI_EXPORT int32_t CJ_WifiOff(char* type);
|
||||||
|
}
|
||||||
|
|
||||||
|
diff --git a/wifi/frameworks/cj/src/wifi_callback.cpp b/wifi/frameworks/cj/src/wifi_callback.cpp
|
||||||
|
new file mode 100644
|
||||||
|
index 000000000..cbd564eb0
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/wifi/frameworks/cj/src/wifi_callback.cpp
|
||||||
|
@@ -0,0 +1,534 @@
|
||||||
|
+/*
|
||||||
|
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||||
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
+ * you may not use this file except in compliance with the License.
|
||||||
|
+ * You may obtain a copy of the License at
|
||||||
|
+ *
|
||||||
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
+ *
|
||||||
|
+ * Unless required by applicable law or agreed to in writing, software
|
||||||
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
+ * See the License for the specific language governing permissions and
|
||||||
|
+ * limitations under the License.
|
||||||
|
+ */
|
||||||
|
+
|
||||||
|
+#include "wifi_callback.h"
|
||||||
|
+
|
||||||
|
+#include "ffi_structs.h"
|
||||||
|
+#include "accesstoken_kit.h"
|
||||||
|
+#include "ipc_skeleton.h"
|
||||||
|
+#include "wifi_device.h"
|
||||||
|
+#include "wifi_logger.h"
|
||||||
|
+#include "wifi_scan.h"
|
||||||
|
+#include "cj_lambda.h"
|
||||||
|
+
|
||||||
|
+DEFINE_WIFILOG_LABEL("CJ_Wifi_Callback");
|
||||||
|
+
|
||||||
|
+namespace OHOS::Wifi {
|
||||||
|
+
|
||||||
|
+std::shared_ptr<WifiDevice> g_cjWifiStaPtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
|
||||||
|
+std::shared_ptr<WifiScan> g_cjWifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
|
||||||
|
+std::shared_ptr<WifiHotspot> g_cjWifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
|
||||||
|
+std::shared_ptr<WifiP2p> g_cjWifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
|
||||||
|
+
|
||||||
|
+CjEventRegister& CjEventRegister::GetInstance()
|
||||||
|
+{
|
||||||
|
+ static CjEventRegister inst;
|
||||||
|
+ return inst;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+class CjWifiDeviceEventCallback : public IWifiDeviceCallBack {
|
||||||
|
+public:
|
||||||
|
+ CjWifiDeviceEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ virtual ~CjWifiDeviceEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+public:
|
||||||
|
+ void OnWifiStateChanged(int state) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("OnWifiStateChanged event: %{public}d [0:DISABLING, 1:DISABLED, 2:ENABLING, 3:ENABLED]",
|
||||||
|
+ state);
|
||||||
|
+ if (wifiStateChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnWifiStateChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ if (m_wifiStateConvertMap.find(state) == m_wifiStateConvertMap.end()) {
|
||||||
|
+ WIFI_LOGW("not find state.");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ wifiStateChange(m_wifiStateConvertMap[state]);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnWifiConnectionChanged(int state, const WifiLinkedInfo &info) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("OnWifiConnectionChanged event: %{public}d [4:CONNECTED, 6:DISCONNECTED, 7:SPECIAL_CONNECT]", state);
|
||||||
|
+ if (wifiConnectionChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnWifiConnectionChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ if (m_connectStateConvertMap.find(state) == m_connectStateConvertMap.end()) {
|
||||||
|
+ WIFI_LOGW("not find connect state.");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ wifiConnectionChange(m_connectStateConvertMap[state]);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnWifiRssiChanged(int rssi) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("OnWifiRssiChanged event: %{public}d", rssi);
|
||||||
|
+ if (wifiRssiChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnWifiConnectionChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ wifiRssiChange(rssi);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnWifiWpsStateChanged(int state, const std::string &pinCode) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnStreamChanged(int direction) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnDeviceConfigChanged(ConfigChange value) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ OHOS::sptr<OHOS::IRemoteObject> AsObject() override
|
||||||
|
+ {
|
||||||
|
+ return nullptr;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void SetCallback(const std::string &type, void (* callback)(int32_t))
|
||||||
|
+ {
|
||||||
|
+ if (type == EVENT_STA_POWER_STATE_CHANGE) {
|
||||||
|
+ wifiStateChange = CJLambda::Create(callback);
|
||||||
|
+ }
|
||||||
|
+ if (type == EVENT_STA_CONN_STATE_CHANGE) {
|
||||||
|
+ wifiConnectionChange = CJLambda::Create(callback);
|
||||||
|
+ }
|
||||||
|
+ if (type == EVENT_STA_RSSI_STATE_CHANGE) {
|
||||||
|
+ wifiRssiChange = CJLambda::Create(callback);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+private:
|
||||||
|
+
|
||||||
|
+ std::function<void(int32_t)> wifiStateChange{nullptr};
|
||||||
|
+ std::function<void(int32_t)> wifiConnectionChange{nullptr};
|
||||||
|
+ std::function<void(int32_t)> wifiRssiChange{nullptr};
|
||||||
|
+
|
||||||
|
+ enum class JsLayerWifiState {
|
||||||
|
+ DISABLED = 0,
|
||||||
|
+ ENABLED = 1,
|
||||||
|
+ ENABLING = 2,
|
||||||
|
+ DISABLING = 3
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ enum class JsLayerConnectStatus {
|
||||||
|
+ DISCONNECTED = 0,
|
||||||
|
+ CONNECTED = 1,
|
||||||
|
+ SPECIAL_CONNECT = 2,
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ enum class JsLayerStreamDirection {
|
||||||
|
+ STREAM_DIRECTION_NONE = 0,
|
||||||
|
+ STREAM_DIRECTION_DOWN = 1,
|
||||||
|
+ STREAM_DIRECTION_UP = 2,
|
||||||
|
+ STREAM_DIRECTION_UPDOWN = 3
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ std::map<int, int> m_wifiStateConvertMap = {
|
||||||
|
+ { static_cast<int>(WifiState::DISABLING), static_cast<int>(JsLayerWifiState::DISABLING) },
|
||||||
|
+ { static_cast<int>(WifiState::DISABLED), static_cast<int>(JsLayerWifiState::DISABLED) },
|
||||||
|
+ { static_cast<int>(WifiState::ENABLING), static_cast<int>(JsLayerWifiState::ENABLING) },
|
||||||
|
+ { static_cast<int>(WifiState::ENABLED), static_cast<int>(JsLayerWifiState::ENABLED) },
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ std::map<int, int> m_connectStateConvertMap = {
|
||||||
|
+ { static_cast<int>(ConnState::CONNECTED), static_cast<int>(JsLayerConnectStatus::CONNECTED) },
|
||||||
|
+ { static_cast<int>(ConnState::DISCONNECTED), static_cast<int>(JsLayerConnectStatus::DISCONNECTED) },
|
||||||
|
+ { static_cast<int>(ConnState::SPECIAL_CONNECT), static_cast<int>(JsLayerConnectStatus::SPECIAL_CONNECT) },
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ std::map<int, int> m_streamDirectionConvertMap = {
|
||||||
|
+ { static_cast<int>(StreamDirection::STREAM_DIRECTION_NONE),
|
||||||
|
+ static_cast<int>(JsLayerStreamDirection::STREAM_DIRECTION_NONE) },
|
||||||
|
+ { static_cast<int>(StreamDirection::STREAM_DIRECTION_DOWN),
|
||||||
|
+ static_cast<int>(JsLayerStreamDirection::STREAM_DIRECTION_DOWN) },
|
||||||
|
+ { static_cast<int>(StreamDirection::STREAM_DIRECTION_UP),
|
||||||
|
+ static_cast<int>(JsLayerStreamDirection::STREAM_DIRECTION_UP) },
|
||||||
|
+ { static_cast<int>(StreamDirection::STREAM_DIRECTION_UPDOWN),
|
||||||
|
+ static_cast<int>(JsLayerStreamDirection::STREAM_DIRECTION_UPDOWN) },
|
||||||
|
+ };
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+class CjWifiScanEventCallback : public IWifiScanCallback {
|
||||||
|
+public:
|
||||||
|
+ CjWifiScanEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ virtual ~CjWifiScanEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+public:
|
||||||
|
+ void OnWifiScanStateChanged(int state) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("scan received state changed event: %{public}d", state);
|
||||||
|
+ if (wifiScanStateChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnWifiScanStateChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ wifiScanStateChange(state);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ OHOS::sptr<OHOS::IRemoteObject> AsObject() override
|
||||||
|
+ {
|
||||||
|
+ return nullptr;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void SetScanStateChange(void (* callback)(int32_t))
|
||||||
|
+ {
|
||||||
|
+ wifiScanStateChange = CJLambda::Create(callback);
|
||||||
|
+ }
|
||||||
|
+private:
|
||||||
|
+ std::function<void(int32_t)> wifiScanStateChange{nullptr};
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+class CjWifiHotspotEventCallback : public IWifiHotspotCallback {
|
||||||
|
+public:
|
||||||
|
+ CjWifiHotspotEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ virtual ~CjWifiHotspotEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+public:
|
||||||
|
+ void OnHotspotStateChanged(int state) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("Hotspot received state changed event: %{public}d", state);
|
||||||
|
+ if (hotspotStateChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnHotspotStateChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ if (m_apStateConvertMap.find(state) == m_apStateConvertMap.end()) {
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ hotspotStateChange(m_apStateConvertMap[state]);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnHotspotStaJoin(const StationInfo &info) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnHotspotStaLeave(const StationInfo &info) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void SetHotspotStateChanged(void (* callback)(int32_t))
|
||||||
|
+ {
|
||||||
|
+ hotspotStateChange = CJLambda::Create(callback);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ OHOS::sptr<OHOS::IRemoteObject> AsObject() override
|
||||||
|
+ {
|
||||||
|
+ return nullptr;
|
||||||
|
+ }
|
||||||
|
+private:
|
||||||
|
+ std::function<void(int32_t)> hotspotStateChange{nullptr};
|
||||||
|
+
|
||||||
|
+ enum class JsLayerApState {
|
||||||
|
+ DISABLED = 0,
|
||||||
|
+ ENABLED = 1,
|
||||||
|
+ ENABLING = 2,
|
||||||
|
+ DISABLING = 3
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ std::map<int, int> m_apStateConvertMap = {
|
||||||
|
+ { static_cast<int>(ApState::AP_STATE_STARTING), static_cast<int>(JsLayerApState::ENABLING) },
|
||||||
|
+ { static_cast<int>(ApState::AP_STATE_STARTED), static_cast<int>(JsLayerApState::ENABLED) },
|
||||||
|
+ { static_cast<int>(ApState::AP_STATE_CLOSING), static_cast<int>(JsLayerApState::DISABLING) },
|
||||||
|
+ { static_cast<int>(ApState::AP_STATE_CLOSED), static_cast<int>(JsLayerApState::DISABLED) },
|
||||||
|
+ };
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+class CjWifiP2pEventCallback : public IWifiP2pCallback {
|
||||||
|
+public:
|
||||||
|
+ CjWifiP2pEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ virtual ~CjWifiP2pEventCallback() {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+public:
|
||||||
|
+ void OnP2pStateChanged(int state) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("received p2p state changed event: %{public}d", state);
|
||||||
|
+ if (p2pStateChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnP2pStateChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ p2pStateChange(state);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pPersistentGroupsChanged(void) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("received persistent group changed event");
|
||||||
|
+ if (p2pPersistentGroupChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnP2pPersistentGroupsChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ p2pPersistentGroupChange();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pThisDeviceChanged(const WifiP2pDevice& device) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("received this device changed event");
|
||||||
|
+ if (p2pDeviceChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnP2pThisDeviceChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ CWifiP2pDevice cdevice;
|
||||||
|
+ cdevice.deviceName = const_cast<char*>(device.GetDeviceName().c_str());
|
||||||
|
+ cdevice.deviceAddress = const_cast<char*>(device.GetDeviceAddress().c_str());
|
||||||
|
+ cdevice.primaryDeviceType = const_cast<char*>(device.GetPrimaryDeviceType().c_str());
|
||||||
|
+ cdevice.deviceStatus = static_cast<int32_t>(device.GetP2pDeviceStatus());
|
||||||
|
+ cdevice.groupCapabilities = device.GetGroupCapabilitys();
|
||||||
|
+ cdevice.deviceAddressType = device.GetDeviceAddressType();
|
||||||
|
+ p2pDeviceChange(cdevice);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pPeersChanged(const std::vector<WifiP2pDevice>& devices) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("received p2p peers changed event, devices count: %{public}d", static_cast<int>(devices.size()));
|
||||||
|
+ if (p2pPeerDeviceChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnP2pPeersChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ int64_t size = static_cast<int64_t>(devices.size());
|
||||||
|
+ if (size <= 0) {
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ CWifiP2pDevice cdevices[size];
|
||||||
|
+ WifiP2pDeviceArr arr{.head = cdevices, .size = size};
|
||||||
|
+ uint32_t idx = 0;
|
||||||
|
+ for (auto& each : devices) {
|
||||||
|
+ cdevices[idx].deviceName = const_cast<char*>(each.GetDeviceName().c_str());
|
||||||
|
+ cdevices[idx].deviceAddress = const_cast<char*>(each.GetDeviceAddress().c_str());
|
||||||
|
+ cdevices[idx].primaryDeviceType = const_cast<char*>(each.GetPrimaryDeviceType().c_str());
|
||||||
|
+ cdevices[idx].deviceStatus = static_cast<int32_t>(each.GetP2pDeviceStatus());
|
||||||
|
+ cdevices[idx].groupCapabilities = each.GetGroupCapabilitys();
|
||||||
|
+ cdevices[idx].deviceAddressType = each.GetDeviceAddressType();
|
||||||
|
+ idx++;
|
||||||
|
+ }
|
||||||
|
+ p2pPeerDeviceChange(arr);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pServicesChanged(const std::vector<WifiP2pServiceInfo>& srvInfo) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pConnectionChanged(const WifiP2pLinkedInfo& info) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("received p2p connection changed event, state: %{public}d",
|
||||||
|
+ static_cast<int>(info.GetConnectState()));
|
||||||
|
+ if (p2pConnectionChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnP2pConnectionChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ CWifiP2PLinkedInfo cinfo;
|
||||||
|
+ cinfo.connectState = static_cast<int32_t>(info.GetConnectState());
|
||||||
|
+ cinfo.isGroupOwner = info.IsGroupOwner();
|
||||||
|
+ cinfo.groupOwnerAddr = const_cast<char*>(info.GetGroupOwnerAddress().c_str());
|
||||||
|
+ p2pConnectionChange(cinfo);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pDiscoveryChanged(bool isChange) override
|
||||||
|
+ {
|
||||||
|
+ WIFI_LOGI("received discovery state changed event");
|
||||||
|
+ if (p2pDiscoveryChange == nullptr) {
|
||||||
|
+ WIFI_LOGI("OnP2pDiscoveryChanged not registered");
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ p2pDiscoveryChange(static_cast<int32_t>(isChange));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pActionResult(P2pActionCallback action, ErrCode code) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnConfigChanged(CfgType type, char* data, int dataLen) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pGcJoinGroup(const OHOS::Wifi::GcInfo &info) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pGcLeaveGroup(const OHOS::Wifi::GcInfo &info) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void OnP2pPrivatePeersChanged(const std::string &priWfdInfo) override
|
||||||
|
+ {
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ OHOS::sptr<OHOS::IRemoteObject> AsObject() override
|
||||||
|
+ {
|
||||||
|
+ return nullptr;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void SetCallback(const std::string &type, void (* callback)())
|
||||||
|
+ {
|
||||||
|
+ if (type == EVENT_P2P_STATE_CHANGE) {
|
||||||
|
+ p2pStateChange = CJLambda::Create(reinterpret_cast<void (*)(int32_t)>(callback));
|
||||||
|
+ }
|
||||||
|
+ if (type == EVENT_P2P_PERSISTENT_GROUP_CHANGE) {
|
||||||
|
+ p2pPersistentGroupChange = CJLambda::Create(callback);
|
||||||
|
+ }
|
||||||
|
+ if (type == EVENT_P2P_DEVICE_STATE_CHANGE) {
|
||||||
|
+ p2pDeviceChange = CJLambda::Create(reinterpret_cast<void (*)(CWifiP2pDevice)>(callback));
|
||||||
|
+ }
|
||||||
|
+ if (type == EVENT_P2P_PEER_DEVICE_CHANGE) {
|
||||||
|
+ p2pPeerDeviceChange = CJLambda::Create(reinterpret_cast<void (*)(WifiP2pDeviceArr)>(callback));
|
||||||
|
+ }
|
||||||
|
+ if (type == EVENT_P2P_CONN_STATE_CHANGE) {
|
||||||
|
+ p2pConnectionChange = CJLambda::Create(reinterpret_cast<void (*)(CWifiP2PLinkedInfo)>(callback));
|
||||||
|
+ }
|
||||||
|
+ if (type == EVENT_P2P_DISCOVERY_CHANGE) {
|
||||||
|
+ p2pDiscoveryChange = CJLambda::Create(reinterpret_cast<void (*)(int32_t)>(callback));
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+private:
|
||||||
|
+ std::function<void(int32_t)> p2pStateChange{nullptr};
|
||||||
|
+ std::function<void(CWifiP2PLinkedInfo)> p2pConnectionChange{nullptr};
|
||||||
|
+ std::function<void(CWifiP2pDevice)> p2pDeviceChange{nullptr};
|
||||||
|
+ std::function<void(WifiP2pDeviceArr)> p2pPeerDeviceChange{nullptr};
|
||||||
|
+ std::function<void()> p2pPersistentGroupChange{nullptr};
|
||||||
|
+ std::function<void(int32_t)> p2pDiscoveryChange{nullptr};
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+sptr<CjWifiDeviceEventCallback> cjWifiDeviceCallback =
|
||||||
|
+ sptr<CjWifiDeviceEventCallback>(new (std::nothrow) CjWifiDeviceEventCallback());
|
||||||
|
+
|
||||||
|
+sptr<CjWifiScanEventCallback> cjWifiScanCallback =
|
||||||
|
+ sptr<CjWifiScanEventCallback>(new (std::nothrow) CjWifiScanEventCallback());
|
||||||
|
+
|
||||||
|
+sptr<CjWifiHotspotEventCallback> cjWifiHotspotCallback =
|
||||||
|
+ sptr<CjWifiHotspotEventCallback>(new (std::nothrow) CjWifiHotspotEventCallback());
|
||||||
|
+
|
||||||
|
+sptr<CjWifiP2pEventCallback> cjWifiP2pCallback =
|
||||||
|
+ sptr<CjWifiP2pEventCallback>(new (std::nothrow) CjWifiP2pEventCallback());
|
||||||
|
+
|
||||||
|
+int32_t CjEventRegister::Register(const std::string& type, void (* callback)())
|
||||||
|
+{
|
||||||
|
+ WIFI_LOGI("Register event: %{public}s", type.c_str());
|
||||||
|
+ std::vector<std::string> event = {type};
|
||||||
|
+
|
||||||
|
+ if (type == EVENT_STA_POWER_STATE_CHANGE || type == EVENT_STA_CONN_STATE_CHANGE
|
||||||
|
+ || type == EVENT_STA_RSSI_STATE_CHANGE) {
|
||||||
|
+ cjWifiDeviceCallback->SetCallback(type, reinterpret_cast<void (*)(int32_t)>(callback));
|
||||||
|
+ CjEventRegister::GetInstance().RegisterDeviceEvents(event);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (type == EVENT_STA_SCAN_STATE_CHANGE) {
|
||||||
|
+ cjWifiScanCallback->SetScanStateChange(reinterpret_cast<void (*)(int32_t)>(callback));
|
||||||
|
+ CjEventRegister::GetInstance().RegisterScanEvents(event);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (type == EVENT_HOTSPOT_STATE_CHANGE) {
|
||||||
|
+ cjWifiHotspotCallback->SetHotspotStateChanged(reinterpret_cast<void (*)(int32_t)>(callback));
|
||||||
|
+ CjEventRegister::GetInstance().RegisterHotspotEvents(event);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (type == EVENT_P2P_STATE_CHANGE || type == EVENT_P2P_PERSISTENT_GROUP_CHANGE ||
|
||||||
|
+ type == EVENT_P2P_DEVICE_STATE_CHANGE || type == EVENT_P2P_PEER_DEVICE_CHANGE ||
|
||||||
|
+ type == EVENT_P2P_CONN_STATE_CHANGE || type == EVENT_P2P_DISCOVERY_CHANGE) {
|
||||||
|
+ cjWifiP2pCallback->SetCallback(type, callback);
|
||||||
|
+ CjEventRegister::GetInstance().RegisterP2PEvents(event);
|
||||||
|
+ }
|
||||||
|
+ return WIFI_OPT_SUCCESS;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int32_t CjEventRegister::UnRegister(const std::string& type)
|
||||||
|
+{
|
||||||
|
+ return WIFI_OPT_SUCCESS;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+ErrCode CjEventRegister::RegisterDeviceEvents(const std::vector<std::string> &event)
|
||||||
|
+{
|
||||||
|
+ if (g_cjWifiStaPtr == nullptr) {
|
||||||
|
+ WIFI_LOGE("Register sta event get instance failed!");
|
||||||
|
+ return WIFI_OPT_FAILED;
|
||||||
|
+ }
|
||||||
|
+ return g_cjWifiStaPtr->RegisterCallBack(cjWifiDeviceCallback, event);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+ErrCode CjEventRegister::RegisterScanEvents(const std::vector<std::string> &event)
|
||||||
|
+{
|
||||||
|
+ if (g_cjWifiScanPtr == nullptr) {
|
||||||
|
+ WIFI_LOGE("Register scan event get instance failed!");
|
||||||
|
+ return WIFI_OPT_FAILED;
|
||||||
|
+ }
|
||||||
|
+ return g_cjWifiScanPtr->RegisterCallBack(cjWifiScanCallback, event);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+ErrCode CjEventRegister::RegisterHotspotEvents(const std::vector<std::string> &event)
|
||||||
|
+{
|
||||||
|
+ if (g_cjWifiHotspotPtr == nullptr) {
|
||||||
|
+ WIFI_LOGE("Register hotspot event get instance failed!");
|
||||||
|
+ return WIFI_OPT_FAILED;
|
||||||
|
+ }
|
||||||
|
+ return g_cjWifiHotspotPtr->RegisterCallBack(cjWifiHotspotCallback, event);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+ErrCode CjEventRegister::RegisterP2PEvents(const std::vector<std::string> &event)
|
||||||
|
+{
|
||||||
|
+ if (g_cjWifiP2pPtr == nullptr) {
|
||||||
|
+ WIFI_LOGE("Register p2p event get instance failed!");
|
||||||
|
+ return WIFI_OPT_FAILED;
|
||||||
|
+ }
|
||||||
|
+ return g_cjWifiP2pPtr->RegisterCallBack(cjWifiP2pCallback, event);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void CjWifiAbilityStatusChange::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
|
||||||
|
+{
|
||||||
|
+ WIFI_LOGI("OnAddSystemAbility systemAbilityId:%{public}d", systemAbilityId);
|
||||||
|
+ std::vector<std::string> event;
|
||||||
|
+ switch (systemAbilityId) {
|
||||||
|
+ case WIFI_DEVICE_ABILITY_ID: {
|
||||||
|
+ event.push_back(EVENT_STA_POWER_STATE_CHANGE);
|
||||||
|
+ event.push_back(EVENT_STA_CONN_STATE_CHANGE);
|
||||||
|
+ event.push_back(EVENT_STA_RSSI_STATE_CHANGE);
|
||||||
|
+ CjEventRegister::GetInstance().RegisterDeviceEvents(event);
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ case WIFI_SCAN_ABILITY_ID: {
|
||||||
|
+ event.push_back(EVENT_STA_SCAN_STATE_CHANGE);
|
||||||
|
+ CjEventRegister::GetInstance().RegisterScanEvents(event);
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ case WIFI_HOTSPOT_ABILITY_ID: {
|
||||||
|
+ event.push_back(EVENT_HOTSPOT_STATE_CHANGE);
|
||||||
|
+ CjEventRegister::GetInstance().RegisterHotspotEvents(event);
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ case WIFI_P2P_ABILITY_ID: {
|
||||||
|
+ event.push_back(EVENT_P2P_STATE_CHANGE);
|
||||||
|
+ event.push_back(EVENT_P2P_PERSISTENT_GROUP_CHANGE);
|
||||||
|
+ event.push_back(EVENT_P2P_DEVICE_STATE_CHANGE);
|
||||||
|
+ event.push_back(EVENT_P2P_PEER_DEVICE_CHANGE);
|
||||||
|
+ event.push_back(EVENT_P2P_CONN_STATE_CHANGE);
|
||||||
|
+ event.push_back(EVENT_P2P_DISCOVERY_CHANGE);
|
||||||
|
+ CjEventRegister::GetInstance().RegisterP2PEvents(event);
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ default:
|
||||||
|
+ WIFI_LOGI("OnAddSystemAbility unhandled sysabilityId:%{public}d", systemAbilityId);
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/wifi/frameworks/cj/src/wifi_ffi.cpp b/wifi/frameworks/cj/src/wifi_ffi.cpp
|
||||||
|
index 2673fee55..3b1346526 100644
|
||||||
|
--- a/wifi/frameworks/cj/src/wifi_ffi.cpp
|
||||||
|
+++ b/wifi/frameworks/cj/src/wifi_ffi.cpp
|
||||||
|
@@ -22,6 +22,7 @@
|
||||||
|
#include "wifi_p2p.h"
|
||||||
|
#include "wifi_common_util.h"
|
||||||
|
#include "wifi_logger.h"
|
||||||
|
+#include "wifi_callback.h"
|
||||||
|
|
||||||
|
DEFINE_WIFILOG_LABEL("CJ_WIFI_FFI");
|
||||||
|
|
||||||
|
@@ -721,14 +722,22 @@ WifiDeviceConfigArr CJ_GetCandidateConfigs(int32_t &code)
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_WifiOn(char *type, int64_t id)
|
||||||
|
+int32_t CJ_WifiOn(char *type, void (*callback)())
|
||||||
|
{
|
||||||
|
- return 0;
|
||||||
|
+ std::string eventType(type);
|
||||||
|
+ if (eventType.empty()) {
|
||||||
|
+ return WIFI_OPT_FAILED;
|
||||||
|
+ }
|
||||||
|
+ return CjEventRegister::GetInstance().Register(eventType, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t CJ_WifiOff(char* type)
|
||||||
|
{
|
||||||
|
- return 0;
|
||||||
|
+ std::string eventType(type);
|
||||||
|
+ if (eventType.empty()) {
|
||||||
|
+ return WIFI_OPT_FAILED;
|
||||||
|
+ }
|
||||||
|
+ return CjEventRegister::GetInstance().UnRegister(eventType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.34.1
|
||||||
|
|
357
0003-rename-ffi.patch
Normal file
357
0003-rename-ffi.patch
Normal file
@ -0,0 +1,357 @@
|
|||||||
|
From 3c02a0a469b36213c86cf6584591035a5a9f36cd Mon Sep 17 00:00:00 2001
|
||||||
|
From: zhaoshenghua <zhaoshenghua1@huawei.com>
|
||||||
|
Date: Thu, 22 Aug 2024 11:35:29 +0800
|
||||||
|
Subject: [PATCH 3/4] rename ffi
|
||||||
|
|
||||||
|
Change-Id: I86acda2cf1be9e51284145bb5e9296916f714747
|
||||||
|
Signed-off-by: zhaoshenghua <zhaoshenghua1@huawei.com>
|
||||||
|
---
|
||||||
|
wifi/frameworks/cj/include/wifi_callback.h | 17 +------
|
||||||
|
wifi/frameworks/cj/include/wifi_ffi.h | 54 +++++++++++-----------
|
||||||
|
wifi/frameworks/cj/src/wifi_ffi.cpp | 54 +++++++++++-----------
|
||||||
|
3 files changed, 55 insertions(+), 70 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/wifi/frameworks/cj/include/wifi_callback.h b/wifi/frameworks/cj/include/wifi_callback.h
|
||||||
|
index 7039f9605..dd49d04a9 100644
|
||||||
|
--- a/wifi/frameworks/cj/include/wifi_callback.h
|
||||||
|
+++ b/wifi/frameworks/cj/include/wifi_callback.h
|
||||||
|
@@ -60,21 +60,6 @@ public:
|
||||||
|
ErrCode RegisterP2PEvents(const std::vector<std::string> &event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
- // std::function<void(int32_t)> wifiStateChange{nullptr};
|
||||||
|
- // std::function<void(int32_t)> wifiConnectionChange{nullptr};
|
||||||
|
- // std::function<void(int32_t)> wifiRssiChange{nullptr};
|
||||||
|
- // std::function<void(int32_t)> wifiScanStateChange{nullptr};
|
||||||
|
- // std::function<void(int32_t)> hotspotStateChange{nullptr};
|
||||||
|
- // std::function<void(int32_t)> p2pStateChange{nullptr};
|
||||||
|
- // std::function<void(CWifiP2PLinkedInfo)> p2pConnectionChange{nullptr};
|
||||||
|
- // std::function<void(CWifiP2pDevice)> p2pDeviceChange{nullptr};
|
||||||
|
- // std::function<void(WifiP2pDeviceArr)> p2pPeerDeviceChange{nullptr};
|
||||||
|
- // std::function<void()> p2pPersistentGroupChange{nullptr};
|
||||||
|
- // std::function<void(int32_t)> p2pDiscoveryChange{nullptr};
|
||||||
|
OHOS::sptr<OHOS::ISystemAbilityStatusChange> mSaStatusListener = nullptr;
|
||||||
|
};
|
||||||
|
-
|
||||||
|
-
|
||||||
|
-
|
||||||
|
-
|
||||||
|
-}
|
||||||
|
\ 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 f7f59dcb9..e89d095ad 100644
|
||||||
|
--- a/wifi/frameworks/cj/include/wifi_ffi.h
|
||||||
|
+++ b/wifi/frameworks/cj/include/wifi_ffi.h
|
||||||
|
@@ -47,33 +47,33 @@ enum class SecTypeCj {
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
-FFI_EXPORT int32_t CJ_IsWifiActive(bool &ret);
|
||||||
|
-FFI_EXPORT WifiScanInfoArr CJ_GetScanInfoList(int32_t &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_RemoveCandidateConfig(int32_t id);
|
||||||
|
-FFI_EXPORT int32_t CJ_ConnectToCandidateConfig(int32_t id);
|
||||||
|
-FFI_EXPORT int32_t CJ_GetSignalLevel(int32_t rssi, int32_t band, uint32_t &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_IsConnected(bool &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_IsFeatureSupported(int64_t featureId, bool &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_GetIpInfo(CIpInfo &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_GetIpv6Info(CIpv6Info &ret);
|
||||||
|
-FFI_EXPORT char *CJ_GetCountryCode(int32_t &code);
|
||||||
|
-FFI_EXPORT int32_t CJ_IsBandTypeSupported(int32_t bandType, bool &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_IsMeteredHotspot(bool &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_RemoveGroup();
|
||||||
|
-FFI_EXPORT int32_t CJ_P2pConnect(CWifiP2PConfig &cfg);
|
||||||
|
-FFI_EXPORT int32_t CJ_P2pCancelConnect();
|
||||||
|
-FFI_EXPORT int32_t CJ_StartDiscoverDevices();
|
||||||
|
-FFI_EXPORT int32_t CJ_StopDiscoverDevices();
|
||||||
|
-FFI_EXPORT int32_t CJ_GetP2pLinkedInfo(CWifiP2PLinkedInfo &info);
|
||||||
|
-FFI_EXPORT int32_t CJ_GetCurrentGroup(CWifiP2PGroupInfo &info);
|
||||||
|
-FFI_EXPORT WifiP2pDeviceArr CJ_GetP2pPeerDevices(int32_t &ret);
|
||||||
|
-FFI_EXPORT int32_t CJ_GetP2pLocalDevice(CWifiP2pDevice &info);
|
||||||
|
-FFI_EXPORT int32_t CJ_CreateGroup(CWifiP2PConfig &cfg);
|
||||||
|
-FFI_EXPORT int32_t CJ_GetLinkedInfo(CWifiLinkedInfo &info);
|
||||||
|
-FFI_EXPORT int32_t CJ_AddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret);
|
||||||
|
-FFI_EXPORT WifiDeviceConfigArr CJ_GetCandidateConfigs(int32_t &code);
|
||||||
|
-FFI_EXPORT int32_t CJ_WifiOn(char *type, void (*callback)());
|
||||||
|
-FFI_EXPORT int32_t CJ_WifiOff(char* type);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiIsWifiActive(bool &ret);
|
||||||
|
+FFI_EXPORT WifiScanInfoArr FfiWifiGetScanInfoList(int32_t &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiRemoveCandidateConfig(int32_t id);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiConnectToCandidateConfig(int32_t id);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiGetSignalLevel(int32_t rssi, int32_t band, uint32_t &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiIsConnected(bool &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiIsFeatureSupported(int64_t featureId, bool &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiGetIpInfo(CIpInfo &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiGetIpv6Info(CIpv6Info &ret);
|
||||||
|
+FFI_EXPORT char *FfiWifiGetCountryCode(int32_t &code);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiIsBandTypeSupported(int32_t bandType, bool &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiIsMeteredHotspot(bool &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiRemoveGroup();
|
||||||
|
+FFI_EXPORT int32_t FfiWifiP2pConnect(CWifiP2PConfig &cfg);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiP2pCancelConnect();
|
||||||
|
+FFI_EXPORT int32_t FfiWifiStartDiscoverDevices();
|
||||||
|
+FFI_EXPORT int32_t FfiWifiStopDiscoverDevices();
|
||||||
|
+FFI_EXPORT int32_t FfiWifiGetP2pLinkedInfo(CWifiP2PLinkedInfo &info);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiGetCurrentGroup(CWifiP2PGroupInfo &info);
|
||||||
|
+FFI_EXPORT WifiP2pDeviceArr FfiWifiGetP2pPeerDevices(int32_t &ret);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiGetP2pLocalDevice(CWifiP2pDevice &info);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiCreateGroup(CWifiP2PConfig &cfg);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiGetLinkedInfo(CWifiLinkedInfo &info);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiAddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret);
|
||||||
|
+FFI_EXPORT WifiDeviceConfigArr FfiWifiGetCandidateConfigs(int32_t &code);
|
||||||
|
+FFI_EXPORT int32_t FfiWifiWifiOn(char *type, void (*callback)());
|
||||||
|
+FFI_EXPORT int32_t FfiWifiWifiOff(char* type);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CJ_WIFI_FFI_H
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/wifi/frameworks/cj/src/wifi_ffi.cpp b/wifi/frameworks/cj/src/wifi_ffi.cpp
|
||||||
|
index 3b1346526..35f3b10a9 100644
|
||||||
|
--- a/wifi/frameworks/cj/src/wifi_ffi.cpp
|
||||||
|
+++ b/wifi/frameworks/cj/src/wifi_ffi.cpp
|
||||||
|
@@ -325,7 +325,7 @@ static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg)
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
-int32_t CJ_IsWifiActive(bool &ret)
|
||||||
|
+int32_t FfiWifiIsWifiActive(bool &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -333,7 +333,7 @@ int32_t CJ_IsWifiActive(bool &ret)
|
||||||
|
return cjWifiDevicePtr->IsWifiActive(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
-WifiScanInfoArr CJ_GetScanInfoList(int32_t &ret)
|
||||||
|
+WifiScanInfoArr FfiWifiGetScanInfoList(int32_t &ret)
|
||||||
|
{
|
||||||
|
WifiScanInfoArr infos{ .head = nullptr, .size = 0 };
|
||||||
|
if (cjWifiScanPtr == nullptr) {
|
||||||
|
@@ -348,7 +348,7 @@ WifiScanInfoArr CJ_GetScanInfoList(int32_t &ret)
|
||||||
|
return infos;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_RemoveCandidateConfig(int32_t id)
|
||||||
|
+int32_t FfiWifiRemoveCandidateConfig(int32_t id)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -356,7 +356,7 @@ int32_t CJ_RemoveCandidateConfig(int32_t id)
|
||||||
|
return static_cast<int32_t>(cjWifiDevicePtr->RemoveCandidateConfig(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_ConnectToCandidateConfig(int32_t id)
|
||||||
|
+int32_t FfiWifiConnectToCandidateConfig(int32_t id)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -364,7 +364,7 @@ int32_t CJ_ConnectToCandidateConfig(int32_t id)
|
||||||
|
return static_cast<int32_t>(cjWifiDevicePtr->ConnectToNetwork(id, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_GetSignalLevel(int32_t rssi, int32_t band, uint32_t &ret)
|
||||||
|
+int32_t FfiWifiGetSignalLevel(int32_t rssi, int32_t band, uint32_t &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -375,7 +375,7 @@ int32_t CJ_GetSignalLevel(int32_t rssi, int32_t band, uint32_t &ret)
|
||||||
|
return static_cast<int32_t>(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_IsConnected(bool &ret)
|
||||||
|
+int32_t FfiWifiIsConnected(bool &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -383,7 +383,7 @@ int32_t CJ_IsConnected(bool &ret)
|
||||||
|
return static_cast<int32_t>(cjWifiDevicePtr->IsConnected(ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_IsFeatureSupported(int64_t featureId, bool &ret)
|
||||||
|
+int32_t FfiWifiIsFeatureSupported(int64_t featureId, bool &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -391,7 +391,7 @@ int32_t CJ_IsFeatureSupported(int64_t featureId, bool &ret)
|
||||||
|
return static_cast<int32_t>(cjWifiDevicePtr->IsFeatureSupported(featureId, ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_GetIpInfo(CIpInfo &ret)
|
||||||
|
+int32_t FfiWifiGetIpInfo(CIpInfo &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -410,7 +410,7 @@ int32_t CJ_GetIpInfo(CIpInfo &ret)
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_GetIpv6Info(CIpv6Info &ret)
|
||||||
|
+int32_t FfiWifiGetIpv6Info(CIpv6Info &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -431,7 +431,7 @@ int32_t CJ_GetIpv6Info(CIpv6Info &ret)
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
-char *CJ_GetCountryCode(int32_t &code)
|
||||||
|
+char *FfiWifiGetCountryCode(int32_t &code)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
code = WIFI_OPT_FAILED;
|
||||||
|
@@ -445,7 +445,7 @@ char *CJ_GetCountryCode(int32_t &code)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_IsBandTypeSupported(int32_t bandType, bool &ret)
|
||||||
|
+int32_t FfiWifiIsBandTypeSupported(int32_t bandType, bool &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -453,7 +453,7 @@ int32_t CJ_IsBandTypeSupported(int32_t bandType, bool &ret)
|
||||||
|
return cjWifiDevicePtr->IsBandTypeSupported(bandType, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_IsMeteredHotspot(bool &ret)
|
||||||
|
+int32_t FfiWifiIsMeteredHotspot(bool &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -461,7 +461,7 @@ int32_t CJ_IsMeteredHotspot(bool &ret)
|
||||||
|
return cjWifiDevicePtr->IsMeteredHotspot(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_RemoveGroup()
|
||||||
|
+int32_t FfiWifiRemoveGroup()
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -469,7 +469,7 @@ int32_t CJ_RemoveGroup()
|
||||||
|
return cjWifiP2pPtr->RemoveGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_P2pConnect(CWifiP2PConfig &cfg)
|
||||||
|
+int32_t FfiWifiP2pConnect(CWifiP2PConfig &cfg)
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -479,7 +479,7 @@ int32_t CJ_P2pConnect(CWifiP2PConfig &cfg)
|
||||||
|
return cjWifiP2pPtr->P2pConnect(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_P2pCancelConnect()
|
||||||
|
+int32_t FfiWifiP2pCancelConnect()
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -487,7 +487,7 @@ int32_t CJ_P2pCancelConnect()
|
||||||
|
return cjWifiP2pPtr->P2pCancelConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_StartDiscoverDevices()
|
||||||
|
+int32_t FfiWifiStartDiscoverDevices()
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -495,7 +495,7 @@ int32_t CJ_StartDiscoverDevices()
|
||||||
|
return cjWifiP2pPtr->DiscoverDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_StopDiscoverDevices()
|
||||||
|
+int32_t FfiWifiStopDiscoverDevices()
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -503,7 +503,7 @@ int32_t CJ_StopDiscoverDevices()
|
||||||
|
return cjWifiP2pPtr->StopDiscoverDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_GetP2pLinkedInfo(CWifiP2PLinkedInfo &info)
|
||||||
|
+int32_t FfiWifiGetP2pLinkedInfo(CWifiP2PLinkedInfo &info)
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -518,7 +518,7 @@ int32_t CJ_GetP2pLinkedInfo(CWifiP2PLinkedInfo &info)
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_GetCurrentGroup(CWifiP2PGroupInfo &info)
|
||||||
|
+int32_t FfiWifiGetCurrentGroup(CWifiP2PGroupInfo &info)
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -554,7 +554,7 @@ int32_t CJ_GetCurrentGroup(CWifiP2PGroupInfo &info)
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
-WifiP2pDeviceArr CJ_GetP2pPeerDevices(int32_t &ret)
|
||||||
|
+WifiP2pDeviceArr FfiWifiGetP2pPeerDevices(int32_t &ret)
|
||||||
|
{
|
||||||
|
WifiP2pDeviceArr arr{.head = nullptr, .size = 0};
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
@@ -585,7 +585,7 @@ WifiP2pDeviceArr CJ_GetP2pPeerDevices(int32_t &ret)
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_GetP2pLocalDevice(CWifiP2pDevice &info)
|
||||||
|
+int32_t FfiWifiGetP2pLocalDevice(CWifiP2pDevice &info)
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -598,7 +598,7 @@ int32_t CJ_GetP2pLocalDevice(CWifiP2pDevice &info)
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_CreateGroup(CWifiP2PConfig &cfg)
|
||||||
|
+int32_t FfiWifiCreateGroup(CWifiP2PConfig &cfg)
|
||||||
|
{
|
||||||
|
if (cjWifiP2pPtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -608,7 +608,7 @@ int32_t CJ_CreateGroup(CWifiP2PConfig &cfg)
|
||||||
|
return cjWifiP2pPtr->CreateGroup(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_GetLinkedInfo(CWifiLinkedInfo &info)
|
||||||
|
+int32_t FfiWifiGetLinkedInfo(CWifiLinkedInfo &info)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -639,7 +639,7 @@ int32_t CJ_GetLinkedInfo(CWifiLinkedInfo &info)
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_AddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret)
|
||||||
|
+int32_t FfiWifiAddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret)
|
||||||
|
{
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
return WIFI_OPT_FAILED;
|
||||||
|
@@ -694,7 +694,7 @@ int32_t CJ_AddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret)
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
-WifiDeviceConfigArr CJ_GetCandidateConfigs(int32_t &code)
|
||||||
|
+WifiDeviceConfigArr FfiWifiGetCandidateConfigs(int32_t &code)
|
||||||
|
{
|
||||||
|
WifiDeviceConfigArr arr{.head = nullptr, .size = 0};
|
||||||
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
|
@@ -722,7 +722,7 @@ WifiDeviceConfigArr CJ_GetCandidateConfigs(int32_t &code)
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_WifiOn(char *type, void (*callback)())
|
||||||
|
+int32_t FfiWifiWifiOn(char *type, void (*callback)())
|
||||||
|
{
|
||||||
|
std::string eventType(type);
|
||||||
|
if (eventType.empty()) {
|
||||||
|
@@ -731,7 +731,7 @@ int32_t CJ_WifiOn(char *type, void (*callback)())
|
||||||
|
return CjEventRegister::GetInstance().Register(eventType, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
-int32_t CJ_WifiOff(char* type)
|
||||||
|
+int32_t FfiWifiWifiOff(char* type)
|
||||||
|
{
|
||||||
|
std::string eventType(type);
|
||||||
|
if (eventType.empty()) {
|
||||||
|
--
|
||||||
|
2.34.1
|
||||||
|
|
546
0004-fix-codecheck.patch
Normal file
546
0004-fix-codecheck.patch
Normal file
@ -0,0 +1,546 @@
|
|||||||
|
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
|
||||||
|
|
@ -23,11 +23,11 @@ group("wifi_kits") {
|
|||||||
deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ]
|
deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ]
|
||||||
if (!defined(ohos_lite)) {
|
if (!defined(ohos_lite)) {
|
||||||
deps += [
|
deps += [
|
||||||
|
"$WIFI_ROOT_DIR/frameworks/cj:cj_wifi_ffi",
|
||||||
"$WIFI_ROOT_DIR/frameworks/js/napi:wifi",
|
"$WIFI_ROOT_DIR/frameworks/js/napi:wifi",
|
||||||
"$WIFI_ROOT_DIR/frameworks/js/napi:wifiext",
|
"$WIFI_ROOT_DIR/frameworks/js/napi:wifiext",
|
||||||
"$WIFI_ROOT_DIR/frameworks/js/napi:wifimanager",
|
"$WIFI_ROOT_DIR/frameworks/js/napi:wifimanager",
|
||||||
"$WIFI_ROOT_DIR/frameworks/js/napi:wifimanagerext",
|
"$WIFI_ROOT_DIR/frameworks/js/napi:wifimanagerext",
|
||||||
"$WIFI_ROOT_DIR/frameworks/cj:cj_wifi_ffi",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,12 @@ ohos_shared_library("cj_wifi_ffi") {
|
|||||||
"$WIFI_ROOT_DIR/frameworks/native/src",
|
"$WIFI_ROOT_DIR/frameworks/native/src",
|
||||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
|
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
|
||||||
"$WIFI_ROOT_DIR/utils/inc",
|
"$WIFI_ROOT_DIR/utils/inc",
|
||||||
"./include"
|
"./include",
|
||||||
]
|
]
|
||||||
|
|
||||||
sources = [
|
sources = [
|
||||||
"src/wifi_ffi.cpp",
|
|
||||||
"src/wifi_callback.cpp",
|
"src/wifi_callback.cpp",
|
||||||
|
"src/wifi_ffi.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ]
|
deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ]
|
||||||
@ -67,4 +67,4 @@ ohos_shared_library("cj_wifi_ffi") {
|
|||||||
innerapi_tags = [ "platformsdk" ]
|
innerapi_tags = [ "platformsdk" ]
|
||||||
part_name = "wifi"
|
part_name = "wifi"
|
||||||
subsystem_name = "communication"
|
subsystem_name = "communication"
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,12 @@
|
|||||||
#include "cj_ffi/cj_common_ffi.h"
|
#include "cj_ffi/cj_common_ffi.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
struct CWifiInfoElem
|
struct CWifiInfoElem {
|
||||||
{
|
|
||||||
uint32_t eid;
|
uint32_t eid;
|
||||||
CArrUI8 content;
|
CArrUI8 content;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiScanInfo
|
struct CWifiScanInfo {
|
||||||
{
|
|
||||||
char *ssid;
|
char *ssid;
|
||||||
char *bssid;
|
char *bssid;
|
||||||
int32_t bssidType;
|
int32_t bssidType;
|
||||||
@ -46,15 +44,12 @@ extern "C" {
|
|||||||
bool isHiLinkNetwork;
|
bool isHiLinkNetwork;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WifiScanInfoArr
|
struct WifiScanInfoArr {
|
||||||
{
|
|
||||||
CWifiScanInfo *head;
|
CWifiScanInfo *head;
|
||||||
int64_t size;
|
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 eapMethod; /* EAP authentication mode:PEAP/TLS/TTLS/PWD/SIM/AKA/AKA' */
|
||||||
int32_t phase2Method; /* Second stage authentication method */
|
int32_t phase2Method; /* Second stage authentication method */
|
||||||
char *identity; /* Identity information */
|
char *identity; /* Identity information */
|
||||||
@ -73,16 +68,14 @@ extern "C" {
|
|||||||
bool isNone;
|
bool isNone;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiWapiConfig
|
struct CWifiWapiConfig {
|
||||||
{
|
|
||||||
int32_t wapiPskType;
|
int32_t wapiPskType;
|
||||||
char *wapiAsCert;
|
char *wapiAsCert;
|
||||||
char *wapiUserCert;
|
char *wapiUserCert;
|
||||||
bool isNone;
|
bool isNone;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CIpInfo
|
struct CIpInfo {
|
||||||
{
|
|
||||||
uint32_t ipAddress;
|
uint32_t ipAddress;
|
||||||
uint32_t gateway;
|
uint32_t gateway;
|
||||||
uint32_t netmask;
|
uint32_t netmask;
|
||||||
@ -92,8 +85,7 @@ extern "C" {
|
|||||||
uint32_t leaseDuration;
|
uint32_t leaseDuration;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CIpv6Info
|
struct CIpv6Info {
|
||||||
{
|
|
||||||
char *linkIpV6Address;
|
char *linkIpV6Address;
|
||||||
char *globalIpV6Address;
|
char *globalIpV6Address;
|
||||||
char *randomGlobalIpV6Address;
|
char *randomGlobalIpV6Address;
|
||||||
@ -105,8 +97,7 @@ extern "C" {
|
|||||||
char *secondDNS;
|
char *secondDNS;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiP2PConfig
|
struct CWifiP2PConfig {
|
||||||
{
|
|
||||||
char *deviceAddress;
|
char *deviceAddress;
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
char *groupName;
|
char *groupName;
|
||||||
@ -115,15 +106,13 @@ extern "C" {
|
|||||||
int32_t deviceAddressType;
|
int32_t deviceAddressType;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiP2PLinkedInfo
|
struct CWifiP2PLinkedInfo {
|
||||||
{
|
|
||||||
int32_t connectState;
|
int32_t connectState;
|
||||||
bool isGroupOwner;
|
bool isGroupOwner;
|
||||||
char *groupOwnerAddr;
|
char *groupOwnerAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiP2pDevice
|
struct CWifiP2pDevice {
|
||||||
{
|
|
||||||
char *deviceName;
|
char *deviceName;
|
||||||
char *deviceAddress;
|
char *deviceAddress;
|
||||||
char *primaryDeviceType;
|
char *primaryDeviceType;
|
||||||
@ -132,14 +121,12 @@ extern "C" {
|
|||||||
int32_t deviceAddressType;
|
int32_t deviceAddressType;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WifiP2pDeviceArr
|
struct WifiP2pDeviceArr {
|
||||||
{
|
|
||||||
CWifiP2pDevice *head;
|
CWifiP2pDevice *head;
|
||||||
int64_t size;
|
int64_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiP2PGroupInfo
|
struct CWifiP2PGroupInfo {
|
||||||
{
|
|
||||||
bool isP2pGo;
|
bool isP2pGo;
|
||||||
CWifiP2pDevice ownerInfo;
|
CWifiP2pDevice ownerInfo;
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
@ -152,8 +139,7 @@ extern "C" {
|
|||||||
char *goIpAddress;
|
char *goIpAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiLinkedInfo
|
struct CWifiLinkedInfo {
|
||||||
{
|
|
||||||
char *ssid;
|
char *ssid;
|
||||||
char *bssid;
|
char *bssid;
|
||||||
int32_t rssi;
|
int32_t rssi;
|
||||||
@ -175,8 +161,7 @@ extern "C" {
|
|||||||
bool isHiLinkNetwork;
|
bool isHiLinkNetwork;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CWifiDeviceConfig
|
struct CWifiDeviceConfig {
|
||||||
{
|
|
||||||
int32_t securityType;
|
int32_t securityType;
|
||||||
int32_t bssidType;
|
int32_t bssidType;
|
||||||
bool isHiddenSsid;
|
bool isHiddenSsid;
|
||||||
@ -187,13 +172,10 @@ extern "C" {
|
|||||||
CWifiWapiConfig wapiConfig;
|
CWifiWapiConfig wapiConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WifiDeviceConfigArr
|
struct WifiDeviceConfigArr {
|
||||||
{
|
|
||||||
CWifiDeviceConfig *head;
|
CWifiDeviceConfig *head;
|
||||||
int64_t size;
|
int64_t size;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // CJ_WIFI_FFI_STRUCTS_H
|
#endif // CJ_WIFI_FFI_STRUCTS_H
|
@ -13,6 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef CJ_WIFI_CALLBACK_H
|
||||||
|
#define CJ_WIFI_CALLBACK_H
|
||||||
|
|
||||||
#include <shared_mutex>
|
#include <shared_mutex>
|
||||||
|
|
||||||
#include "ffi_structs.h"
|
#include "ffi_structs.h"
|
||||||
@ -63,3 +66,5 @@ private:
|
|||||||
OHOS::sptr<OHOS::ISystemAbilityStatusChange> mSaStatusListener = nullptr;
|
OHOS::sptr<OHOS::ISystemAbilityStatusChange> mSaStatusListener = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -19,33 +19,6 @@
|
|||||||
#include "cj_ffi/cj_common_ffi.h"
|
#include "cj_ffi/cj_common_ffi.h"
|
||||||
#include "ffi_structs.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" {
|
extern "C" {
|
||||||
FFI_EXPORT int32_t FfiWifiIsWifiActive(bool &ret);
|
FFI_EXPORT int32_t FfiWifiIsWifiActive(bool &ret);
|
||||||
FFI_EXPORT WifiScanInfoArr FfiWifiGetScanInfoList(int32_t &ret);
|
FFI_EXPORT WifiScanInfoArr FfiWifiGetScanInfoList(int32_t &ret);
|
||||||
|
@ -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);
|
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'" };
|
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)
|
static std::string EapMethod2Str(const int& method)
|
||||||
{
|
{
|
||||||
if (method < 0 || method >= static_cast<int>(sizeof(EAP_METHOD) / sizeof(EAP_METHOD[0]))) {
|
if (method < 0 || method >= static_cast<int>(sizeof(EAP_METHOD) / sizeof(EAP_METHOD[0]))) {
|
||||||
@ -133,44 +158,47 @@ static void ProcessPassphrase(const SecTypeCj& securityType, WifiDeviceConfig& c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NativeInfoElems2Cj(const std::vector<WifiInfoElem>& infoElems, CWifiScanInfo &info)
|
static void SetInfoElemContent(const WifiInfoElem &infoElem, CWifiInfoElem &cinfo)
|
||||||
{
|
{
|
||||||
int valueStep = 2;
|
int valueStep = 2;
|
||||||
int64_t size = static_cast<int64_t>(infoElems.size());
|
const char *uStr = &infoElem.content[0];
|
||||||
if (size > 0) {
|
size_t len = infoElem.content.size();
|
||||||
info.infoElems = static_cast<CWifiInfoElem *>(malloc(sizeof(CWifiInfoElem) * size));
|
size_t inLen = static_cast<size_t>(infoElem.content.size() * valueStep + 1);
|
||||||
if (info.infoElems == nullptr) {
|
char *buf = static_cast<char *>(calloc(inLen + 1, sizeof(char)));
|
||||||
info.elemsSize = 0;
|
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 = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
info.elemsSize = size;
|
}
|
||||||
for (int64_t i = 0; i < size; i++) {
|
cinfo.content.head = reinterpret_cast<uint8_t *>(buf);
|
||||||
CWifiInfoElem elem;
|
cinfo.content.size = inLen - 1;
|
||||||
elem.eid = infoElems[i].id;
|
}
|
||||||
|
|
||||||
const char *uStr = &infoElems[i].content[0];
|
static void NativeInfoElems2Cj(const std::vector<WifiInfoElem>& infoElems, CWifiScanInfo &info)
|
||||||
size_t len = infoElems[i].content.size();
|
{
|
||||||
size_t inLen = static_cast<size_t>(infoElems[i].content.size() * valueStep + 1);
|
info.infoElems = nullptr;
|
||||||
char *buf = (char *)calloc(inLen + 1, sizeof(char));
|
info.elemsSize = 0;
|
||||||
if (buf == nullptr) {
|
int64_t size = static_cast<int64_t>(infoElems.size());
|
||||||
elem.content = CArrUI8{.head = nullptr, .size = 0};
|
if (size <= 0) {
|
||||||
info.infoElems[i] = elem;
|
return;
|
||||||
continue;
|
}
|
||||||
}
|
info.infoElems = static_cast<CWifiInfoElem *>(malloc(sizeof(CWifiInfoElem) * size));
|
||||||
int pos = 0;
|
if (info.infoElems == nullptr) {
|
||||||
for (size_t k = 0; k < len; ++k) {
|
return;
|
||||||
pos = (k << 1);
|
}
|
||||||
if (snprintf_s(buf + pos, inLen - pos, inLen - pos - 1, "%02x", uStr[k]) < 0) {
|
info.elemsSize = size;
|
||||||
free(buf);
|
int64_t idx = 0;
|
||||||
buf = NULL;
|
for (auto& each : infoElems) {
|
||||||
elem.content = CArrUI8{.head = nullptr, .size = 0};
|
info.infoElems[idx] = CWifiInfoElem{ .eid = each.id, .content = CArrUI8{.head = nullptr, .size = 0}};
|
||||||
info.infoElems[i] = elem;
|
SetInfoElemContent(each, info.infoElems[idx]);
|
||||||
continue;
|
idx++;
|
||||||
}
|
|
||||||
}
|
|
||||||
elem.content = CArrUI8{.head = reinterpret_cast<uint8_t *>(buf), .size = inLen - 1}; // TODO check size
|
|
||||||
info.infoElems[i] = elem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +215,7 @@ static int32_t ScanInfo2Cj(const std::vector<WifiScanInfo>& scanInfos, WifiScanI
|
|||||||
infos.size = size;
|
infos.size = size;
|
||||||
|
|
||||||
uint32_t idx = 0;
|
uint32_t idx = 0;
|
||||||
for(auto& each : scanInfos) {
|
for (auto& each : scanInfos) {
|
||||||
CWifiScanInfo info;
|
CWifiScanInfo info;
|
||||||
info.ssid = MallocCString(each.ssid);
|
info.ssid = MallocCString(each.ssid);
|
||||||
info.bssid = MallocCString(each.bssid);
|
info.bssid = MallocCString(each.bssid);
|
||||||
@ -275,6 +303,38 @@ static int Str2EapMethod(const std::string &str)
|
|||||||
return 0;
|
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)
|
static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg)
|
||||||
{
|
{
|
||||||
UpdateSecurityTypeAndPreSharedKey(config);
|
UpdateSecurityTypeAndPreSharedKey(config);
|
||||||
@ -288,32 +348,7 @@ static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg)
|
|||||||
SecTypeCj type = ConvertKeyMgmtToSecType(config.keyMgmt);
|
SecTypeCj type = ConvertKeyMgmtToSecType(config.keyMgmt);
|
||||||
cfg.securityType = static_cast<int32_t>(type);
|
cfg.securityType = static_cast<int32_t>(type);
|
||||||
if (type == SecTypeCj::SEC_TYPE_EAP || type == SecTypeCj::SEC_TYPE_EAP_SUITE_B) {
|
if (type == SecTypeCj::SEC_TYPE_EAP || type == SecTypeCj::SEC_TYPE_EAP_SUITE_B) {
|
||||||
cfg.eapConfig.eapMethod = Str2EapMethod(config.wifiEapConfig.eap);
|
EapConfig2C(config.wifiEapConfig, cfg.eapConfig);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
if (type == SecTypeCj::SEC_TYPE_WAPI_CERT || type == SecTypeCj::SEC_TYPE_WAPI_PSK) {
|
if (type == SecTypeCj::SEC_TYPE_WAPI_CERT || type == SecTypeCj::SEC_TYPE_WAPI_PSK) {
|
||||||
cfg.wapiConfig.wapiPskType = config.wifiWapiConfig.wapiPskType;
|
cfg.wapiConfig.wapiPskType = config.wifiWapiConfig.wapiPskType;
|
||||||
@ -324,7 +359,6 @@ static void DeviceConfig2C(WifiDeviceConfig &config, CWifiDeviceConfig &cfg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
int32_t FfiWifiIsWifiActive(bool &ret)
|
int32_t FfiWifiIsWifiActive(bool &ret)
|
||||||
{
|
{
|
||||||
if (cjWifiDevicePtr == nullptr) {
|
if (cjWifiDevicePtr == nullptr) {
|
||||||
@ -525,31 +559,35 @@ int32_t FfiWifiGetCurrentGroup(CWifiP2PGroupInfo &info)
|
|||||||
}
|
}
|
||||||
WifiP2pGroupInfo groupInfo;
|
WifiP2pGroupInfo groupInfo;
|
||||||
ErrCode code = cjWifiP2pPtr->GetCurrentGroup(groupInfo);
|
ErrCode code = cjWifiP2pPtr->GetCurrentGroup(groupInfo);
|
||||||
if (code == WIFI_OPT_SUCCESS) {
|
if (code != WIFI_OPT_SUCCESS) {
|
||||||
info.isP2pGo = groupInfo.IsGroupOwner();
|
return code;
|
||||||
DeviceInfo2Cj(groupInfo.GetOwner(), info.ownerInfo);
|
}
|
||||||
info.passphrase = MallocCString(groupInfo.GetPassphrase());
|
info.isP2pGo = groupInfo.IsGroupOwner();
|
||||||
info.interfaceName = MallocCString(groupInfo.GetInterface());
|
DeviceInfo2Cj(groupInfo.GetOwner(), info.ownerInfo);
|
||||||
info.groupName = MallocCString(groupInfo.GetGroupName());
|
info.passphrase = MallocCString(groupInfo.GetPassphrase());
|
||||||
info.goIpAddress = MallocCString(groupInfo.GetGoIpAddress());
|
info.interfaceName = MallocCString(groupInfo.GetInterface());
|
||||||
info.networkId = groupInfo.GetNetworkId();
|
info.groupName = MallocCString(groupInfo.GetGroupName());
|
||||||
info.frequency = groupInfo.GetFrequency();
|
info.goIpAddress = MallocCString(groupInfo.GetGoIpAddress());
|
||||||
info.clientSize = 0;
|
info.networkId = groupInfo.GetNetworkId();
|
||||||
if (!groupInfo.IsClientDevicesEmpty()) {
|
info.frequency = groupInfo.GetFrequency();
|
||||||
const std::vector<OHOS::Wifi::WifiP2pDevice>& vecDevices = groupInfo.GetClientDevices();
|
info.clientSize = 0;
|
||||||
int64_t size = static_cast<int64_t>(vecDevices.size());
|
info.clientDevices = nullptr;
|
||||||
info.clientDevices = static_cast<CWifiP2pDevice *>(malloc(sizeof(CWifiP2pDevice) * size));
|
if (groupInfo.IsClientDevicesEmpty()) {
|
||||||
if (info.clientDevices != nullptr) {
|
return code;
|
||||||
info.clientSize = size;
|
}
|
||||||
uint32_t idx = 0;
|
const std::vector<OHOS::Wifi::WifiP2pDevice>& vecDevices = groupInfo.GetClientDevices();
|
||||||
for (auto& each : vecDevices) {
|
int64_t size = static_cast<int64_t>(vecDevices.size());
|
||||||
CWifiP2pDevice device;
|
info.clientDevices = static_cast<CWifiP2pDevice *>(malloc(sizeof(CWifiP2pDevice) * size));
|
||||||
DeviceInfo2Cj(each, device);
|
if (info.clientDevices == nullptr) {
|
||||||
info.clientDevices[idx] = device;
|
return code;
|
||||||
idx++;
|
}
|
||||||
}
|
info.clientSize = size;
|
||||||
}
|
uint32_t idx = 0;
|
||||||
}
|
for (auto& each : vecDevices) {
|
||||||
|
CWifiP2pDevice device;
|
||||||
|
DeviceInfo2Cj(each, device);
|
||||||
|
info.clientDevices[idx] = device;
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
@ -669,7 +707,8 @@ int32_t FfiWifiAddCandidateConfig(CWifiDeviceConfig cfg, int32_t &ret)
|
|||||||
config.wifiEapConfig.caCertPath = std::string(cfg.eapConfig.caPath);
|
config.wifiEapConfig.caCertPath = std::string(cfg.eapConfig.caPath);
|
||||||
config.wifiEapConfig.clientCert = std::string(cfg.eapConfig.clientCertAlias);
|
config.wifiEapConfig.clientCert = std::string(cfg.eapConfig.clientCertAlias);
|
||||||
config.wifiEapConfig.privateKey = 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),
|
if (strncpy_s(config.wifiEapConfig.certPassword, sizeof(config.wifiEapConfig.certPassword),
|
||||||
cfg.eapConfig.certPassword, strlen(cfg.eapConfig.certPassword)) != EOK) {
|
cfg.eapConfig.certPassword, strlen(cfg.eapConfig.certPassword)) != EOK) {
|
||||||
WIFI_LOGE("%{public}s: failed to copy", __func__);
|
WIFI_LOGE("%{public}s: failed to copy", __func__);
|
||||||
@ -706,14 +745,13 @@ WifiDeviceConfigArr FfiWifiGetCandidateConfigs(int32_t &code)
|
|||||||
int64_t size = static_cast<int64_t>(vecDeviceConfigs.size());
|
int64_t size = static_cast<int64_t>(vecDeviceConfigs.size());
|
||||||
if (code == WIFI_OPT_SUCCESS && size > 0) {
|
if (code == WIFI_OPT_SUCCESS && size > 0) {
|
||||||
WIFI_LOGI("Get candidate device configs size: %{public}zu", vecDeviceConfigs.size());
|
WIFI_LOGI("Get candidate device configs size: %{public}zu", vecDeviceConfigs.size());
|
||||||
// transform
|
|
||||||
arr.head = static_cast<CWifiDeviceConfig *>(malloc(sizeof(CWifiDeviceConfig) * size));
|
arr.head = static_cast<CWifiDeviceConfig *>(malloc(sizeof(CWifiDeviceConfig) * size));
|
||||||
if (arr.head == nullptr) {
|
if (arr.head == nullptr) {
|
||||||
code = WIFI_OPT_FAILED;
|
code = WIFI_OPT_FAILED;
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
arr.size = size;
|
arr.size = size;
|
||||||
for(int64_t i = 0; i < size; i++) {
|
for (int64_t i = 0; i < size; i++) {
|
||||||
CWifiDeviceConfig cfg;
|
CWifiDeviceConfig cfg;
|
||||||
DeviceConfig2C(vecDeviceConfigs[i], cfg);
|
DeviceConfig2C(vecDeviceConfigs[i], cfg);
|
||||||
arr.head[i] = cfg;
|
arr.head[i] = cfg;
|
||||||
@ -739,6 +777,5 @@ int32_t FfiWifiWifiOff(char* type)
|
|||||||
}
|
}
|
||||||
return CjEventRegister::GetInstance().UnRegister(eventType);
|
return CjEventRegister::GetInstance().UnRegister(eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} //OHOS::Wifi
|
||||||
|
Loading…
Reference in New Issue
Block a user