diff --git a/wifi/bundle.json b/wifi/bundle.json index 88119f861c1292933f45ce33d99de5302c640e16..134474e0535afc3696cd40e066e3bd6edae9c4aa 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -49,7 +49,8 @@ "wifi_feature_with_ap_intf", "wifi_feature_with_ap_num", "wifi_feature_with_auth_disable", - "wifi_feature_with_dhcp_disable" + "wifi_feature_with_dhcp_disable", + "wifi_feature_is_hdi_supported" ], "adapted_system_type": [ "standard" diff --git a/wifi/services/wifi_standard/wifi_hal/BUILD.gn b/wifi/services/wifi_standard/wifi_hal/BUILD.gn index 4e2263880d3d8f2cb3a1d79c2c82536271714a10..e3a51385f552dbfb82dffe80550f867d1d89d0b1 100644 --- a/wifi/services/wifi_standard/wifi_hal/BUILD.gn +++ b/wifi/services/wifi_standard/wifi_hal/BUILD.gn @@ -21,7 +21,10 @@ if (defined(ohos_lite)) { local_base_sources = [ "common/wifi_hal_common_func.c", - "hdi/wifi_hdi_ap_instance.c", + "hdi/src/wifi_hdi_ap_impl.c", + "hdi/src/wifi_hdi_p2p_impl.c", + "hdi/src/wifi_hdi_proxy.c", + "hdi/src/wifi_hdi_sta_impl.c", "main.c", "wifi_hal_adapter.c", "wifi_hal_ap_interface.c", @@ -56,7 +59,7 @@ local_base_include_dirs = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_p2p_hal", - "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/inc", ] if (defined(ohos_lite)) { @@ -99,28 +102,33 @@ if (defined(ohos_lite)) { "//third_party/wpa_supplicant/wpa_supplicant-2.9_standard/src/", "//third_party/bounds_checking_function/include/", "//drivers/peripheral/wlan/interfaces/include/", - "//drivers/peripheral/wlan/client/include/", ] deps = [ "$WIFI_ROOT_DIR/services/wifi_standard/ipc_framework/cRPC:crpc_server", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/etc/init:etc", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//drivers/peripheral/wlan/hal:wifi_hal", "//third_party/wpa_supplicant/wpa_supplicant-2.9_standard:wpa_client", ] external_deps = [ "c_utils:utils" ] - cflags_cc = [ "-fno-rtti" ] defines = [ "AP_INTF=\"$wifi_feature_with_ap_intf\"", "AP_NUM=$wifi_feature_with_ap_num", ] + + if (wifi_feature_is_hdi_supported) { + defines += [ "HDI_INTERFACE_SUPPORT" ] + external_deps += [ "drivers_interface_wlanlibwlan_proxy_1.0" ] + } + if (product_name == "rk3568") { defines += [ "NON_SEPERATE_P2P" ] } + cflags_cc = [ "-fno-rtti" ] + part_name = "wifi" subsystem_name = "communication" } diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.h b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_ap_impl.h similarity index 73% rename from wifi/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.h rename to wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_ap_impl.h index 5c6369752c93db6f4cc099d9c027771cf46a8ee2..67783effad51e1ce466f9b850f1a8202d97043f4 100644 --- a/wifi/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.h +++ b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_ap_impl.h @@ -13,21 +13,17 @@ * limitations under the License. */ -#ifndef OHOS_HDI_INSTANCE_H -#define OHOS_HDI_INSTANCE_H +#ifndef OHOS_HDI_AP_IMPL_H +#define OHOS_HDI_AP_IMPL_H -#include "wifi_hal.h" -#include "wifi_hal_ap_feature.h" #include "wifi_hal_define.h" #ifdef __cplusplus extern "C" { #endif - -WifiErrorNo HdiGetAp(struct IWiFi **wifi, struct IWiFiAp **apFeature); - -WifiErrorNo HdiReleaseAp(struct IWiFi *wifi, struct IWiFiAp *apFeature); - +WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id); +WifiErrorNo WifiSetPowerModel(const int mode, int id); +WifiErrorNo WifiGetPowerModel(int* mode, int id); #ifdef __cplusplus } #endif diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_p2p_impl.h b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_p2p_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..df84dd683ef1bea1931baf311c36677cee3c3549 --- /dev/null +++ b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_p2p_impl.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef OHOS_HDI_P2P_IMPL_H +#define OHOS_HDI_P2P_IMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_proxy.h b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..4dfda8a3da12e53b79eabe177bd99f86dd4689c4 --- /dev/null +++ b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_proxy.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef OHOS_HDI_PROXY_H +#define OHOS_HDI_PROXY_H + +#include "wifi_hal_define.h" +#include "v1_0/iwlan_interface.h" +#include "wifi_hal_base_feature.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct WifiHdiProxy { + struct IWlanInterface* wlanObj; + struct HdfFeatureInfo* feature; +} WifiHdiProxy; + +#ifndef CHECK_HDI_PROXY_AND_RETURN +#define CHECK_HDI_PROXY_AND_RETURN(proxy, retValue) \ +if (proxy.wlanObj == NULL || proxy.feature == NULL) { \ + LOGE("Hdi proxy: %{public}s in %{public}s is NULL!", #proxy, __func__); \ + return retValue; \ +} +#endif + +/** + * @Description Create a channel between the HAL and the driver. + * + * @return WifiErrorNo - operation result + */ +WifiErrorNo HdiStart(); + +/** + * @Description Stop the created channel. + * + * @return WifiErrorNo - operation result + */ +WifiErrorNo HdiStop(); + +/** + * @Description Create the WiFi object. + * + * @return WifiErrorNo - operation result + */ +struct IWlanInterface* GetWlanInterface(); + +/** + * @Description Get the hdi proxy by wlan type. + * + * @param wlanType - wlan type + * @return WifiHdiProxy - interface proxy object + */ +WifiHdiProxy GetHdiProxy(const int32_t wlanType); + +/** + * @Description Release hdi proxy by wlan type. + * This interface will be automatic called in the hid stop function, + * So you can use it without releasing. + * + * @param wlanType - wlan type + * @return WifiErrorNo - operation result + */ +WifiErrorNo ReleaseHdiProxy(const int32_t wlanType); +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_sta_impl.h b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_sta_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..aee195356742706733c59396888814e88f027125 --- /dev/null +++ b/wifi/services/wifi_standard/wifi_hal/hdi/inc/wifi_hdi_sta_impl.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifndef OHOS_HDI_STA_IMPL_H +#define OHOS_HDI_STA_IMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_ap_impl.c b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_ap_impl.c new file mode 100644 index 0000000000000000000000000000000000000000..b7061b9232fbe6e272260b569780172cde0ea593 --- /dev/null +++ b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_ap_impl.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifdef HDI_INTERFACE_SUPPORT + +#include "wifi_hdi_ap_impl.h" +#include "wifi_hdi_proxy.h" +#include "wifi_log.h" + +#undef LOG_TAG +#define LOG_TAG "WifiHdiApImpl" + +#define NUMS_BAND 2 + +static int32_t ConvertToNl80211Band(int32_t band) +{ + return (band > 0 && band <= NUMS_BAND) ? (band - 1) : band; +} + +WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id) +{ + if (frequencies == NULL || size == NULL) { + LOGE("%{public}s frequencies or size is null.", __func__); + return WIFI_HAL_FAILED; + } + WifiHdiProxy proxy = GetHdiProxy(PROTOCOL_80211_IFTYPE_AP); + CHECK_HDI_PROXY_AND_RETURN(proxy, WIFI_HAL_FAILED); + struct HdfWifiInfo wifiInfo; + wifiInfo.band = ConvertToNl80211Band(band); + wifiInfo.size = *size; + uint32_t count = 0xff; + LOGI("Get freqs parameters [band: %{public}d, alloc size: %{public}d]", wifiInfo.band, wifiInfo.size); + int32_t ret = proxy.wlanObj->GetFreqsWithBand(proxy.wlanObj, proxy.feature, &wifiInfo, frequencies, &count); + LOGI("Get freqs result, actual size: %{public}d", count); + *size = count; + if (ret != 0) { + LOGE("Get freqs with band failed: %{public}d", ret); + } + return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED; +} + +WifiErrorNo WifiSetPowerModel(const int mode, int id) +{ + LOGI("Instance %{public}d WifiSetPowerModel: %{public}d", id, mode); + WifiHdiProxy proxy = GetHdiProxy(PROTOCOL_80211_IFTYPE_AP); + CHECK_HDI_PROXY_AND_RETURN(proxy, WIFI_HAL_FAILED); + int32_t ret = proxy.wlanObj->SetPowerMode(proxy.wlanObj, proxy.feature, mode); + if (ret != 0) { + LOGE("Set power mode failed: %{public}d", ret); + } + return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED; +} + +WifiErrorNo WifiGetPowerModel(int* mode, int id) +{ + LOGI("Instance %{public}d WifiGetPowerModel", id); + WifiHdiProxy proxy = GetHdiProxy(PROTOCOL_80211_IFTYPE_AP); + CHECK_HDI_PROXY_AND_RETURN(proxy, WIFI_HAL_FAILED); + int32_t ret = proxy.wlanObj->GetPowerMode(proxy.wlanObj, proxy.feature, (uint8_t *)mode); + if (ret != 0) { + LOGE("Get power mode failed: %{public}d", ret); + } + LOGI("Get power mode: %{public}d", *mode); + return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED; +} +#endif diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.c b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_p2p_impl.c similarity index 32% rename from wifi/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.c rename to wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_p2p_impl.c index f9523efd8ba3a45e2d2ee714e3a5e9a0403a5a35..152fffa9a0b958bb39f3434395fb3d3c5fac1a61 100644 --- a/wifi/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.c +++ b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_p2p_impl.c @@ -13,57 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_ARCH_LITE -#include "wifi_hdi_ap_instance.h" -#include "wifi_hal_define.h" +#ifdef HDI_INTERFACE_SUPPORT + +#include "wifi_hdi_p2p_impl.h" +#include "wifi_hdi_proxy.h" #include "wifi_log.h" #undef LOG_TAG -#define LOG_TAG "WifiHdiInstance" - -WifiErrorNo HdiGetAp(struct IWiFi **wifi, struct IWiFiAp **apFeature) -{ - if (wifi == NULL || apFeature == NULL) { - return WIFI_HAL_FAILED; - } - - LOGD("HdiGetAp"); - int32_t ret; - ret = WifiConstruct(wifi); - if (ret != 0 || *wifi == NULL) { - LOGE("%{public}s WifiConstruct failed", __func__); - return WIFI_HAL_FAILED; - } - - ret = (*wifi)->start(*wifi); - if (ret != 0) { - (void)WifiDestruct(wifi); - LOGE("%{public}s start failed", __func__); - return WIFI_HAL_FAILED; - } - - ret = (*wifi)->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)apFeature); - if (ret != 0 || *apFeature == NULL) { - (void)(*wifi)->stop(*wifi); - (void)WifiDestruct(wifi); - LOGE("%{public}s createFeature failed", __func__); - return WIFI_HAL_FAILED; - } - return WIFI_HAL_SUCCESS; -} +#define LOG_TAG "WifiHdiP2pImpl" -WifiErrorNo HdiReleaseAp(struct IWiFi *wifi, struct IWiFiAp *apFeature) -{ - if (wifi == NULL) { - return WIFI_HAL_FAILED; - } - LOGD("HdiReleaseAp"); - if (apFeature != NULL) { - (void)wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature); - } - (void)wifi->stop(wifi); - (void)WifiDestruct(&wifi); - return WIFI_HAL_SUCCESS; -} #endif diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_proxy.c b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_proxy.c new file mode 100644 index 0000000000000000000000000000000000000000..26af6978b00fac42d5008935d2d23f14c11cfabb --- /dev/null +++ b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_proxy.c @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifdef HDI_INTERFACE_SUPPORT +#include "wifi_hdi_proxy.h" +#include +#include +#include "wifi_log.h" + +#undef LOG_TAG +#define LOG_TAG "WifiHdiProxy" + +#define MAX_FEATURE_NUMBER 16 + +const char *WLAN_SERVICE_NAME = "wlan_interface_service"; // Move the define to HDF module + +static pthread_mutex_t g_mutex; +static unsigned int g_wlanRefCount = 0; +static struct IWlanInterface *g_wlanObj = NULL; +static struct HdfFeatureInfo* g_featureArray[MAX_FEATURE_NUMBER] = {NULL}; + +static WifiErrorNo ReleaseFeatureInner(const int32_t wlanType) +{ + WifiErrorNo ret = WIFI_HAL_SUCCESS; + if (g_wlanObj == NULL) { + LOGE("%{public}s g_wlanObj is null", __func__); + return WIFI_HAL_FAILED; + } + for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) { + if (g_featureArray[i] == NULL || g_featureArray[i]->type != wlanType) { + continue; + } + LOGI("%{public}s destory feature begin.", __func__); + ret = g_wlanObj->DestroyFeature(g_wlanObj, g_featureArray[i]); + if (ret != HDF_SUCCESS) { + LOGE("Destroy feature %{public}d failed: %{public}d", g_featureArray[i]->type, ret); + } + LOGI("%{public}s destory feature end.", __func__); + free(g_featureArray[i]); + g_featureArray[i] = NULL; + break; + } + return ret; +} + +static struct HdfFeatureInfo* GetFeatureInner(const int32_t wlanType) +{ + struct HdfFeatureInfo *feature = NULL; + if (g_wlanObj == NULL) { + LOGE("%{public}s g_wlanObj is null!", __func__); + return NULL; + } + for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) { + if (g_featureArray[i] == NULL) { + continue; + } + if (g_featureArray[i]->type == wlanType) { + LOGI("%{public}s get an exist feature.", __func__); + feature = g_featureArray[i]; + return feature; + } + } + + /* allocate 1 struct */ + feature = (struct HdfFeatureInfo *)calloc(1, sizeof(struct HdfFeatureInfo)); + if (feature == NULL) { + LOGE("%{public}s calloc failed!", __func__); + return NULL; + } + LOGI("Create feature type: %{public}d", wlanType); + int32_t ret = g_wlanObj->CreateFeature(g_wlanObj, wlanType, feature); + if (ret != HDF_SUCCESS) { + LOGE("CreateFeature %{public}d failed: %{public}d", wlanType, ret); + goto FAILURE; + } + LOGI("Create feature end, ifname: %{public}s", feature->ifName); + bool isAdd = false; + for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) { + if (g_featureArray[i] == NULL) { + g_featureArray[i] = feature; + isAdd = true; + break; + } + } + if (!isAdd) { + LOGE("%{public}s g_featureArray is full!", __func__); + goto FAILURE; + } + return feature; + +FAILURE: + if (feature != NULL) { + free(feature); + } + return NULL; +} + +static void ReleaseAllFeatures() +{ + if (g_wlanObj == NULL) { + return; + } + WifiErrorNo ret = WIFI_HAL_SUCCESS; + for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) { + if (g_featureArray[i] == NULL) { + continue; + } + LOGI("%{public}s destory feature[all] begin.", __func__); + ret = g_wlanObj->DestroyFeature(g_wlanObj, g_featureArray[i]); + if (ret != HDF_SUCCESS) { + LOGE("Destroy feature %{public}d failed: %{public}d", g_featureArray[i]->type, ret); + } + LOGI("%{public}s destory feature[all] end.", __func__); + free(g_featureArray[i]); + g_featureArray[i] = NULL; + } +} + +WifiErrorNo HdiStart() +{ + LOGI("%{public}s start...", __func__); + pthread_mutex_lock(&g_mutex); + if (g_wlanRefCount != 0) { + ++g_wlanRefCount; + pthread_mutex_unlock(&g_mutex); + LOGI("%{public}s wlan ref count: %d", __func__, g_wlanRefCount); + return WIFI_HAL_SUCCESS; + } + g_wlanObj = IWlanInterfaceGetInstance(WLAN_SERVICE_NAME, false); + if (g_wlanObj == NULL) { + pthread_mutex_unlock(&g_mutex); + LOGE("%{public}s WlanInterfaceGetInstance failed", __func__); + return WIFI_HAL_FAILED; + } + int32_t ret = g_wlanObj->Start(g_wlanObj); + if (ret != HDF_SUCCESS) { + LOGE("%{public}s Start failed: %{public}d", __func__, ret); + IWlanInterfaceReleaseInstance(WLAN_SERVICE_NAME, g_wlanObj, false); + g_wlanObj = NULL; + pthread_mutex_unlock(&g_mutex); + return WIFI_HAL_FAILED; + } + ++g_wlanRefCount; + pthread_mutex_unlock(&g_mutex); + LOGI("%{public}s is started", __func__); + return WIFI_HAL_SUCCESS; +} + +WifiErrorNo HdiStop() +{ + LOGI("%{public}s stop...", __func__); + pthread_mutex_lock(&g_mutex); + if (g_wlanObj == NULL || g_wlanRefCount == 0) { + pthread_mutex_unlock(&g_mutex); + LOGE("%{public}s g_wlanObj is NULL or ref count is 0", __func__); + return WIFI_HAL_FAILED; + } + + const unsigned int ONE_REF_COUNT = 1; + if (g_wlanRefCount > ONE_REF_COUNT) { + --g_wlanRefCount; + pthread_mutex_unlock(&g_mutex); + LOGI("%{public}s wlan ref count: %d", __func__, g_wlanRefCount); + return WIFI_HAL_SUCCESS; + } + ReleaseAllFeatures(); + int32_t ret = g_wlanObj->Stop(g_wlanObj); + if (ret != HDF_SUCCESS) { + LOGE("%{public}s Stop failed: %{public}d", __func__, ret); + } + IWlanInterfaceReleaseInstance(WLAN_SERVICE_NAME, g_wlanObj, false); + --g_wlanRefCount; + g_wlanObj = NULL; + pthread_mutex_unlock(&g_mutex); + LOGI("%{public}s is stopped", __func__); + return (ret == HDF_SUCCESS) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED; +} + +struct IWlanInterface* GetWlanInterface() +{ + struct IWlanInterface *wlanObj = NULL; + pthread_mutex_lock(&g_mutex); + wlanObj = g_wlanObj; + pthread_mutex_unlock(&g_mutex); + return wlanObj; +} + +WifiHdiProxy GetHdiProxy(const int32_t wlanType) +{ + WifiHdiProxy proxy = {.wlanObj = NULL, .feature = NULL}; + pthread_mutex_lock(&g_mutex); + struct HdfFeatureInfo* feature = GetFeatureInner(wlanType); + if (feature == NULL) { + pthread_mutex_unlock(&g_mutex); + LOGE("%{public}s GetFeature failed!", __func__); + return proxy; + } + proxy.wlanObj = g_wlanObj; + proxy.feature = feature; + pthread_mutex_unlock(&g_mutex); + return proxy; +} + +WifiErrorNo ReleaseHdiProxy(const int32_t wlanType) +{ + WifiErrorNo ret = WIFI_HAL_FAILED; + pthread_mutex_lock(&g_mutex); + ret = ReleaseFeatureInner(wlanType); + pthread_mutex_unlock(&g_mutex); + return ret; +} +#endif diff --git a/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_sta_impl.c b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_sta_impl.c new file mode 100644 index 0000000000000000000000000000000000000000..3c1f218fbe23137e67af8f7271fb8a0efab15841 --- /dev/null +++ b/wifi/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_sta_impl.c @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2022 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. + */ + +#ifdef HDI_INTERFACE_SUPPORT + +#include "wifi_hdi_sta_impl.h" +#include "wifi_hdi_proxy.h" +#include "wifi_log.h" + +#undef LOG_TAG +#define LOG_TAG "WifiHdiStaImpl" + + +#endif diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.c index b3e4b126b974ed27f3e80aa97ae07ee272574f2c..25684c76336ce3343cdfd01a5a417e0b5db481c1 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.c @@ -16,15 +16,12 @@ #include "wifi_hal_ap_interface.h" #include #include -#ifdef OHOS_ARCH_LITE #include "wifi_hal_adapter.h" -#else -#include "wifi_hal.h" -#include "wifi_hal_adapter.h" -#include "wifi_hdi_ap_instance.h" -#endif #include "wifi_hal_module_manage.h" #include "wifi_hal_common_func.h" +#ifdef HDI_INTERFACE_SUPPORT +#include "wifi_hdi_proxy.h" +#endif #include "wifi_log.h" #include "wifi_wpa_hal.h" #include "wifi_hostapd_hal.h" @@ -32,7 +29,6 @@ #undef LOG_TAG #define LOG_TAG "WifiHalApInterface" -#define NUMS_BAND 2 #define DISABLE_AP_WAIT_MS 50000 #define ABLE_AP_WAIT_MS 50000 #define WIFI_MULTI_CMD_MAX_LEN 1024 @@ -47,18 +43,15 @@ WifiErrorNo StartSoftAp(int id) LOGE("hostapd start failed!"); return WIFI_HAL_OPEN_HOSTAPD_FAILED; } - if (StartHostapdHal(id) != WIFI_HAL_SUCCESS) { LOGE("hostapd init failed!"); return WIFI_HAL_HOSTAPD_NOT_INIT; } - WifiHostapdHalDevice *hostapdHalDevice = GetWifiHostapdDev(id); if (hostapdHalDevice == NULL) { LOGE("hostapdHalDevice is NULL!"); return WIFI_HAL_HOSTAPD_NOT_INIT; } - int ret = sprintf_s(ifaceName, IFCAE_NAME_LEN, AP_INTF"%d", id); if (ret == -1) { LOGE("StartSoftAp failed! ret=%{public}d", ret); @@ -71,7 +64,12 @@ WifiErrorNo StartSoftAp(int id) return WIFI_HAL_FAILED; } } - +#ifdef HDI_INTERFACE_SUPPORT + if (HdiStart() != WIFI_HAL_SUCCESS) { + LOGE("[Ap] Start hdi failed!"); + return WIFI_HAL_FAILED; + } +#endif LOGI("AP start successfully, id:%{public}d!", id); return WIFI_HAL_SUCCESS; } @@ -127,6 +125,12 @@ WifiErrorNo StartHostapdHal(int id) WifiErrorNo StopSoftAp(int id) { +#ifdef HDI_INTERFACE_SUPPORT + if (HdiStop() != WIFI_HAL_SUCCESS) { + LOGE("[Ap] Stop hdi failed!"); + return WIFI_HAL_FAILED; + } +#endif WifiHostapdHalDevice *hostapdHalDevice = GetWifiHostapdDev(id); if (hostapdHalDevice != NULL) { int ret = hostapdHalDevice->disableAp(id); @@ -136,18 +140,15 @@ WifiErrorNo StopSoftAp(int id) } else { LOGE("cant not get hostapd dev"); } - if (StopHostapd() != WIFI_HAL_SUCCESS) { LOGE("hostapd stop failed!"); return WIFI_HAL_FAILED; } - if (StopHostapdHal(id) != WIFI_HAL_SUCCESS) { LOGE("hostapd_hal stop failed!"); return WIFI_HAL_FAILED; } - - LOGD("AP stop successfully!"); + LOGI("AP stop successfully!"); return WIFI_HAL_SUCCESS; } @@ -314,79 +315,24 @@ WifiErrorNo DisassociateSta(const unsigned char *mac, int lenMac, int id) return WIFI_HAL_SUCCESS; } -static int32_t ConvertToNl80211Band(int32_t band) -{ - return (band > 0 && band <= NUMS_BAND) ? (band - 1) : band; -} - WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id) { if (frequencies == NULL || size == NULL) { LOGE("%{public}s frequencies or size is null.", __func__); return WIFI_HAL_FAILED; } -#ifdef OHOS_ARCH_LITE + LOGE("%{public}s func is not support!", __func__); return WIFI_HAL_FAILED; -#else - uint32_t count = 0; - struct IWiFi *wifi = NULL; - struct IWiFiAp *apFeature = NULL; - WifiErrorNo ret = HdiGetAp(&wifi, &apFeature); - if (ret != WIFI_HAL_SUCCESS) { - return WIFI_HAL_FAILED; - } - ret = apFeature->baseFeature.getValidFreqsWithBand((struct IWiFiBaseFeature *)apFeature, - ConvertToNl80211Band(band), frequencies, *size, &count); - *size = count; - if (ret != 0) { - LOGE("%{public}s failed", __func__); - } - HdiReleaseAp(wifi, apFeature); - return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED; -#endif } WifiErrorNo WifiSetPowerModel(const int mode, int id) { -#ifdef OHOS_ARCH_LITE + LOGE("%{public}s func is not support!", __func__); return WIFI_HAL_FAILED; -#else - LOGD("Instance %{public}d WifiSetPowerModel: %{public}d", id, mode); - - struct IWiFi *wifi = NULL; - struct IWiFiAp *apFeature = NULL; - WifiErrorNo ret = HdiGetAp(&wifi, &apFeature); - if (ret != WIFI_HAL_SUCCESS) { - return WIFI_HAL_FAILED; - } - ret = wifi->setPowerMode(apFeature->baseFeature.ifName, mode); - if (ret != 0) { - LOGE("%{public}s failed", __func__); - } - HdiReleaseAp(wifi, apFeature); - return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED; -#endif } WifiErrorNo WifiGetPowerModel(int* mode, int id) { -#ifdef OHOS_ARCH_LITE + LOGE("%{public}s func is not support!", __func__); return WIFI_HAL_FAILED; -#else - LOGD("Instance %{public}d WifiGetPowerModel", id); - - struct IWiFi *wifi = NULL; - struct IWiFiAp *apFeature = NULL; - WifiErrorNo ret = HdiGetAp(&wifi, &apFeature); - if (ret != WIFI_HAL_SUCCESS) { - return WIFI_HAL_FAILED; - } - ret = wifi->getPowerMode(apFeature->baseFeature.ifName, (uint8_t *)mode); - if (ret != 0) { - LOGE("%{public}s failed", __func__); - } - LOGD("getPowerModel: %{public}d", *mode); - HdiReleaseAp(wifi, apFeature); - return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED; -#endif } diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.h b/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.h index 34cee161784c47f5ec74720ae0c5ed1a66c5ccaf..5613563d70b5fa9f69419943acc09756672263b4 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.h +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.h @@ -144,7 +144,7 @@ WifiErrorNo DisassociateSta(const unsigned char *mac, int lenMac, int id); * @param id - ap id * @return WifiErrorNo */ -WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id); +WifiErrorNo WEAK_FUNC GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id); /** * @Description Set the power mode. @@ -153,7 +153,7 @@ WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t * * @param id - ap id * @return WifiErrorNo */ -WifiErrorNo WifiSetPowerModel(const int mode, int id); +WifiErrorNo WEAK_FUNC WifiSetPowerModel(const int mode, int id); /** * @Description Get the power mode. @@ -162,7 +162,7 @@ WifiErrorNo WifiSetPowerModel(const int mode, int id); * @param id - ap id * @return WifiErrorNo */ -WifiErrorNo WifiGetPowerModel(int* mode, int id); +WifiErrorNo WEAK_FUNC WifiGetPowerModel(int* mode, int id); #ifdef __cplusplus } #endif diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_ap.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_ap.c index 45298fd8df6f46697aa6100c0c22c8344a601dbe..4896602f204cb92b47a3ae3ed922dd69f6eb4255 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_ap.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_ap.c @@ -16,6 +16,7 @@ #include "wifi_hal_crpc_ap.h" #include #include "serial.h" +#include "wifi_hdi_ap_impl.h" #include "wifi_hal_ap_interface.h" #include "wifi_hal_define.h" diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h b/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h index 525bdc4d062dd3cb4b0e20bb7c8d5823deeb7dfd..d5fc765463eb89d0784a0a1822a28cf4066aa8ba 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h @@ -41,6 +41,8 @@ extern "C" { #define WIFI_HAL_FALSE 0 #define WIFI_HAL_TRUE 1 +#define WEAK_FUNC __attribute__((weak)) + typedef enum WifiErrorNo { WIFI_HAL_SUCCESS = 0, /* Success. */ WIFI_HAL_FAILED = 1, /* Failed. */ diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c index df6203c16a4f2c3eca926c5268bf63e1f4a70f21..ac161d27bea0e048bc8b9fdf9ddcb58fbe2e79d1 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c @@ -17,9 +17,12 @@ #include "securec.h" #include "wifi_hal_adapter.h" #include "wifi_hal_module_manage.h" +#ifdef HDI_INTERFACE_SUPPORT +#include "wifi_hdi_proxy.h" +#endif #include "wifi_log.h" -#include "wifi_wpa_hal.h" #include "wifi_supplicant_hal.h" +#include "wifi_wpa_hal.h" #undef LOG_TAG #define LOG_TAG "WifiHalStaInterface" @@ -109,7 +112,7 @@ WifiErrorNo Start(void) LOGE("wpa_supplicant start failed!"); return WIFI_HAL_OPEN_SUPPLICANT_FAILED; } - LOGD("wpa_supplicant start successfully!"); + LOGI("wpa_supplicant start successfully!"); if (AddWpaIface(0) != WIFI_HAL_SUCCESS) { LOGE("Failed to add wpa interface!"); @@ -122,7 +125,12 @@ WifiErrorNo Start(void) StopWpaAndWpaHal(0); return WIFI_HAL_CONN_SUPPLICANT_FAILED; } - LOGD("SupplicantHal connect wpa_supplicant successfully!"); +#ifdef HDI_INTERFACE_SUPPORT + if (HdiStart() != WIFI_HAL_SUCCESS) { + LOGE("[STA] Start hdi failed!"); + return WIFI_HAL_FAILED; + } +#endif LOGI("Start wifi successfully"); return WIFI_HAL_SUCCESS; } @@ -130,18 +138,30 @@ WifiErrorNo Start(void) WifiErrorNo Stop(void) { LOGI("Ready to Stop wifi"); +#ifdef HDI_INTERFACE_SUPPORT + if (HdiStop() != WIFI_HAL_SUCCESS) { + LOGE("[Ap] Stop hdi failed!"); + return WIFI_HAL_FAILED; + } +#endif WifiErrorNo err = StopWpaAndWpaHal(0); if (err == WIFI_HAL_FAILED) { - LOGD("Wifi stop failed!"); + LOGE("Wifi stop failed!"); return WIFI_HAL_FAILED; } - LOGD("Wifi stop successfully!"); + LOGI("Wifi stop successfully!"); return WIFI_HAL_SUCCESS; } WifiErrorNo ForceStop(void) { LOGI("Ready force Stop wifi"); +#ifdef HDI_INTERFACE_SUPPORT + if (HdiStop() != WIFI_HAL_SUCCESS) { + LOGE("[Ap] Stop hdi failed!"); + return WIFI_HAL_FAILED; + } +#endif WifiWpaStaInterface *p = TraversalWifiStaInterface(); while (p != NULL) { StopWpaAndWpaHal(p->staNo); diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_common/Mock/mock_chip_capability.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_common/Mock/mock_chip_capability.cpp old mode 100755 new mode 100644 diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_common/Mock/mock_chip_capability.h b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_common/Mock/mock_chip_capability.h old mode 100755 new mode 100644 diff --git a/wifi/test/wifi_standard/wifi_hal/unittest/BUILD.gn b/wifi/test/wifi_standard/wifi_hal/unittest/BUILD.gn index b5517a8323c2d0d2467cdb0be38f79d917a6dd12..3244571843596fd5a77348140b520664101586b7 100644 --- a/wifi/test/wifi_standard/wifi_hal/unittest/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_hal/unittest/BUILD.gn @@ -27,7 +27,6 @@ ohos_unittest("wifi_hal_unittest") { module_out_path = module_output_path sources = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/common/wifi_hal_common_func.c", - "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.c", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_adapter.c", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.c", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_base_interface.c", @@ -74,17 +73,16 @@ ohos_unittest("wifi_hal_unittest") { "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_p2p_hal", "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", - "//third_party/wpa_supplicant/wpa_supplicant-2.9_standard/src/", - "//third_party/bounds_checking_function/include/", - "//drivers/peripheral/wlan/interfaces/include/", - "//drivers/peripheral/wlan/client/include/", - "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi", + "//third_party/wpa_supplicant/wpa_supplicant-2.9_standard/src", + "//third_party/bounds_checking_function/include", + "//drivers/peripheral/wlan/interfaces/include", + "//drivers/peripheral/wlan/client/include", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/inc", ] deps = [ "$WIFI_ROOT_DIR/services/wifi_standard/ipc_framework/cRPC:crpc_server", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//drivers/peripheral/wlan/hal:wifi_hal", ] ldflags = [ @@ -96,9 +94,16 @@ ohos_unittest("wifi_hal_unittest") { "c_utils:utils", "hiviewdfx_hilog_native:libhilog", ] - configs = [ ":module_private_config" ] + defines = [ "AP_INTF=\"$wifi_feature_with_ap_intf\"" ] + if (wifi_feature_is_hdi_supported) { + defines += [ "HDI_INTERFACE_SUPPORT" ] + external_deps += [ "drivers_interface_wlan:libwlan_proxy_1.0" ] + } + + configs = [ ":module_private_config" ] + part_name = "wifi" subsystem_name = "communication" testonly = true diff --git a/wifi/wifi.gni b/wifi/wifi.gni index 6675f3f78b11050d1b8101bc2aedf79e188f3131..5ffdbcf359746787c0f3640078e87a53f80b0b6c 100644 --- a/wifi/wifi.gni +++ b/wifi/wifi.gni @@ -22,4 +22,5 @@ declare_args() { wifi_feature_with_ap_num = 1 wifi_feature_with_auth_disable = false wifi_feature_with_dhcp_disable = false + wifi_feature_is_hdi_supported = false } diff --git a/wifi/wifi_lite.gni b/wifi/wifi_lite.gni index d7a8a77c65e3dbed3deb9c64e5d146691bd88e69..3dd85109dcc12face87470130396809174d9bf01 100644 --- a/wifi/wifi_lite.gni +++ b/wifi/wifi_lite.gni @@ -25,4 +25,5 @@ declare_args() { wifi_feature_with_ap_num = 1 wifi_feature_with_auth_disable = false wifi_feature_with_dhcp_disable = false + wifi_feature_is_hdi_supported = false }