diff --git a/wifi/bundle.json b/wifi/bundle.json index 9c3c4fd98e189ef6c033187e0021ed68528bb0bd..5bdeeefc9163454f43ff454b5e04c6282d48799f 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -172,6 +172,9 @@ "header_files": [] }, "name": "//foundation/communication/wifi/wifi/frameworks/cj:cj_wifi_ffi" + }, + { + "name": "//foundation/communication/wifi/wifi/frameworks/ets/taihe/wifiManager:copy_wifiManager" } ], "test": [ diff --git a/wifi/frameworks/BUILD.gn b/wifi/frameworks/BUILD.gn index 3420689afd95cac873dafc62166bc42ae26fee5d..a48078efd26adece45d7c2c9bf7e7383a5fd9e06 100644 --- a/wifi/frameworks/BUILD.gn +++ b/wifi/frameworks/BUILD.gn @@ -25,6 +25,7 @@ group("wifi_kits") { deps += [ "$WIFI_ROOT_DIR/frameworks/cj:cj_wifi_ffi", "$WIFI_ROOT_DIR/frameworks/ets/ani:wifi_ani", + "$WIFI_ROOT_DIR/frameworks/ets/taihe/wifiManager:wifiManager_framework_taihe", "$WIFI_ROOT_DIR/frameworks/js/napi:wifi", "$WIFI_ROOT_DIR/frameworks/js/napi:wifiext", "$WIFI_ROOT_DIR/frameworks/js/napi:wifimanager", diff --git a/wifi/frameworks/ets/taihe/wifiManager/BUILD.gn b/wifi/frameworks/ets/taihe/wifiManager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e0f3f1d6f51d76f2950940d956740cf7491f73b4 --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/BUILD.gn @@ -0,0 +1,83 @@ +# Copyright (C) 2025-2025 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. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/communication/wifi/wifi/wifi.gni") # 导入taihe.gni + +copy_taihe_idl("copy_wifiManager") { + sources = [ + "./idl/ohos.wifiManager.taihe" + ] +} + +subsystem_name = "communication" +part_name = "wifi" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_wifiManager" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.wifiManager.ani.cpp", + "$taihe_generated_file_path/src/ohos.wifiManager.abi.c", + ] +} + +taihe_shared_library("wifiManager_taihe_native") { #调用taihe_shared_library模板编译so + sanitize = { + cfi = true # Enable/disable control flow integrity detection + boundary_sanitize = true # Enable boundary san detection + cfi_cross_dso = true # Cross-SO CFI Checks + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + sources += [ + "./src/ani_constructor.cpp", + "./src/ohos.wifiManager.impl.cpp", + ] + deps = [ + ":run_taihe", + "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" + ] + external_deps = [ + "c_utils:utils" + ] +} + +generate_static_abc("wifiManager_framework_abc") { #调用generate_static_abc编译abc + base_url = "$taihe_generated_file_path" #base_url直接设置为taihe_generated_file_path + files = [ "$taihe_generated_file_path/@ohos.wifiManager.ets" ] #files传入生成的ets文件 + is_boot_abc = "True" + device_dst_file = "/system/framework/wifimanager_framework_abc.abc" + dependencies = [ ":run_taihe" ] #编译abc依赖太和工具链调用 +} + +ohos_prebuilt_etc("wifiManager_framework_etc") { #调用ohos_prebuilt_etc将abc拷贝到/system/framework下 + source = "$target_out_dir/wifiManager_framework_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":wifiManager_framework_abc" ] #拷贝abc依赖编译abc +} + +group("wifiManager_framework_taihe") { + deps = [ + ":wifiManager_framework_etc", + ":wifiManager_taihe_native" + ] +} \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe b/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe new file mode 100644 index 0000000000000000000000000000000000000000..391ffa5a950de6836fdb1cec176f1953c866e5ba --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2025 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. + */ + +@!namespace("@ohos.wifiManager", "wifiManager") +@!sts_inject(""" +static { loadLibrary("wifiManager_taihe_native.z")} +""") +enum WifiSecurityType: i32 { + WIFI_SEC_TYPE_INVALID = 0, + WIFI_SEC_TYPE_OPEN = 1, + WIFI_SEC_TYPE_WEP = 2, + WIFI_SEC_TYPE_PSK = 3, + WIFI_SEC_TYPE_SAE = 4, + WIFI_SEC_TYPE_EAP = 5, + WIFI_SEC_TYPE_EAP_SUITE_B = 6, + WIFI_SEC_TYPE_OWE = 7, + WIFI_SEC_TYPE_WAPI_CERT = 8, + WIFI_SEC_TYPE_WAPI_PSK = 9 +} + +enum ConnState: i32 { + SCANNING = 0, + CONNECTING = 1, + AUTHENTICATING = 2, + OBTAINING_IPADDR = 3, + CONNECTED = 4, + DISCONNECTING = 5, + DISCONNECTED = 6, + UNKNOWN = 7 +} + +enum WifiCategory: i32 { + DEFAULT = 1, + WIFI6 = 2, + WIFI6_PLUS = 3, + WIFI7 = 4, + WIFI7_PLUS = 5 +} + +enum WifiDetailState: i32 { + UNKNOWN = -1, + INACTIVE = 0, + ACTIVATED = 1, + ACTIVATING = 2, + DEACTIVATING = 3, + SEMI_ACTIVATING = 4, + SEMI_ACTIVE = 5 +} + +enum P2pDeviceStatus: i32 { + CONNECTED = 0, + INVITED = 1, + FAILED = 2, + AVAILABLE = 3, + UNAVAILABLE = 4, +} + +enum P2pConnectState: i32 { + DISCONNECTED = 0, + CONNECTED = 1 +} + +struct WifiDeviceConfig { + ssid: String; + bssid: Optional; + preSharedKey: String; + securityType: WifiSecurityType; +} + +function MakeWifiDeviceConfig(ssid: String, bssid: Optional, preSharedKey: String, securityType: WifiSecurityType): WifiDeviceConfig; + +struct WifiScanInfo { + ssid: String; + bssid: String; + securityType: WifiSecurityType; + rssi: i32; + band: i32; + supportedWifiCategory: WifiCategory; +} + +function MakeWifiScanInfo(ssid: String, bssid: String, securityType: WifiSecurityType, rssi: i32, band: i32, supportedWifiCategory: WifiCategory): WifiScanInfo; + +struct WifiLinkedInfo { + ssid: String; + bssid: String; + rssi: i32; + band: i32; + macAddress: String; + connState: ConnState; + supportedWifiCategory: WifiCategory; +} + +function MakeWifiLinkedInfo(ssid: String, bssid: String, rssi: i32, band: i32, macAddress: String, connState: ConnState, supportedWifiCategory: WifiCategory): WifiLinkedInfo; + +struct IpInfo { + ipAddress: i32; +} + +function MakeIpInfo(ipAddress: i32): IpInfo; + +struct Ipv6Info { + linkIpv6Address: String; +} + +function MakeIpv6Info(linkIpv6Address: String): Ipv6Info; + +struct StationInfo { + macAddress: String; +} + +function MakeStationInfo(macAddress: String): StationInfo; + +struct HotspotConfig { + ssid: String; + securityType: WifiSecurityType; + band: i32; + preSharedKey: String; +} + +function MakeHotspotConfig(ssid: String, securityType: WifiSecurityType, band: i32, preSharedKey: String): HotspotConfig; + +struct WifiP2pLinkedInfo { + connectState: P2pConnectState; + isGroupOwner: bool; + groupOwnerAddr: String; +} + +enum DeviceAddressType: i32 { + RANDOM_DEVICE_ADDRESS = 0, + REAL_DEVICE_ADDRESS = 1, +} + +struct WifiP2pDevice { + deviceName: String; + deviceAddress: String; + deviceAddressType: DeviceAddressType; + primaryDeviceType: String; + deviceStatus: P2pDeviceStatus; + groupCapabilities: i32; +} + +// 函数 +function IsConnected(): bool; +function IsWifiActive(): bool; +function GetSignalLevel(rssi: f64, band: f64): f64; +function GetIpInfo(): IpInfo; +function GetIpv6Info(): Ipv6Info; \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/src/ani_constructor.cpp b/wifi/frameworks/ets/taihe/wifiManager/src/ani_constructor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85f5275cf34a93e85b5a45146e138eb23556a6a7 --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/src/ani_constructor.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 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 "ohos.wifiManager.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::wifiManager::ANIRegister(env)) { + std::cerr << "Error from ohos::wifiManager::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp b/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..411c9b8c58be85ffd63942c0f88f4f9d5a66a40b --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2025 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 "ohos.wifiManager.proj.hpp" +#include "ohos.wifiManager.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "wifi_device.h" +#include "wifi_device_impl.h" +#include "wifi_hotspot.h" +#include "wifi_hotspot_impl.h" +#include "wifi_scan.h" +#include "wifi_scan_impl.h" +#include "wifi_msg.h" +#include "wifi_p2p.h" +#include "wifi_p2p_impl.h" +using namespace OHOS::Wifi; + +static std::shared_ptr g_wifiDevicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID); +std::shared_ptr g_wifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID); +static std::shared_ptr g_wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); +std::shared_ptr g_wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID); +namespace { + +::ohos::wifiManager::WifiDeviceConfig MakeWifiDeviceConfig(::taihe::string_view ssid, + ::taihe::optional_view<::taihe::string> bssid, ::taihe::string_view preSharedKey, + ::ohos::wifiManager::WifiSecurityType securityType) +{ + return {ssid, bssid, preSharedKey, securityType}; +} + +::ohos::wifiManager::WifiScanInfo MakeWifiScanInfo(::taihe::string_view ssid, ::taihe::string_view bssid, + ::ohos::wifiManager::WifiSecurityType securityType, int32_t rssi, int32_t band, + ::ohos::wifiManager::WifiCategory supportedWifiCategory) +{ + return {ssid, bssid, securityType, rssi, band, supportedWifiCategory}; +} + +::ohos::wifiManager::WifiScanInfo MakeTmpWifiScanInfo() +{ + return {"", "", ::ohos::wifiManager::WifiSecurityType::key_t::WIFI_SEC_TYPE_INVALID, 0, 0, + ::ohos::wifiManager::WifiCategory::key_t::DEFAULT}; +} + +::ohos::wifiManager::WifiLinkedInfo MakeWifiLinkedInfo(::taihe::string_view ssid, + ::taihe::string_view bssid, int32_t rssi, int32_t band, ::taihe::string_view macAddress, + ::ohos::wifiManager::ConnState connState, ::ohos::wifiManager::WifiCategory supportedWifiCategory) +{ + return {ssid, bssid, rssi, band, macAddress, connState, supportedWifiCategory}; +} + +::ohos::wifiManager::IpInfo MakeIpInfo(int32_t ipAddress) +{ + return {ipAddress}; +} + +::ohos::wifiManager::Ipv6Info MakeIpv6Info(::taihe::string_view linkIpv6Address) +{ + return {linkIpv6Address}; +} + +::ohos::wifiManager::StationInfo MakeStationInfo(::taihe::string_view macAddress) +{ + return {macAddress}; +} + +::ohos::wifiManager::StationInfo MakeTmpStationInfo() +{ + return {""}; +} + +::ohos::wifiManager::HotspotConfig MakeHotspotConfig(::taihe::string_view ssid, + ::ohos::wifiManager::WifiSecurityType securityType, int32_t band, ::taihe::string_view preSharedKey) +{ + return {ssid, securityType, band, preSharedKey}; +} + +bool IsConnected() +{ + bool isConnected = false; + ErrCode ret = g_wifiDevicePtr->IsConnected(isConnected); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("IsConnected return error"); + } + return static_cast(isConnected); +} + +bool IsWifiActive() +{ + bool activeStatus = false; + ErrCode ret = g_wifiDevicePtr->IsWifiActive(activeStatus); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("isWifiActive return error"); + } + return static_cast(activeStatus); +} + +double GetSignalLevel(double rssi, double band) +{ + int level = -1; + int tmpRssi = static_cast(rssi); + int tmpBand = static_cast(band); + ErrCode ret = g_wifiDevicePtr->GetSignalLevel(tmpRssi, tmpBand, level); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getSignalLevel return error"); + } + return static_cast(level); +} + +::ohos::wifiManager::IpInfo GetIpInfo() +{ + IpInfo ipInfo; + ErrCode ret = g_wifiDevicePtr->GetIpInfo(ipInfo); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getIpInfo return error"); + } + ::ohos::wifiManager::IpInfo result = MakeIpInfo(ipInfo.ipAddress); + return result; +} + +::ohos::wifiManager::Ipv6Info GetIpv6Info() +{ + IpV6Info ipInfo; + ErrCode ret = g_wifiDevicePtr->GetIpv6Info(ipInfo); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getIpv6Info return error"); + } + ::ohos::wifiManager::Ipv6Info result = MakeIpv6Info(ipInfo.linkIpV6Address); + return result; +} \ No newline at end of file