diff --git a/wlan/bundle.json b/wlan/bundle.json index 17aa99973f6d399f4168a3cf6bafc2ebf2a9bd47..4077c6545d8481c100bbd5ff5503d5a8306251cd 100644 --- a/wlan/bundle.json +++ b/wlan/bundle.json @@ -14,7 +14,8 @@ "subsystem": "hdf", "features": [ "drivers_peripheral_wlan_feature_enable_HDF_NL80211", - "drivers_peripheral_wlan_feature_enable_HDF_UT" + "drivers_peripheral_wlan_feature_enable_HDF_UT", + "drivers_peripheral_wlan_feature_enable_HDF_WLAN_EXTEND_VDI" ], "adapted_system_type": ["standard", "small"], "rom": "660KB", diff --git a/wlan/hdi_service/BUILD.gn b/wlan/hdi_service/BUILD.gn index 2794b7d0cd6da7859c51a9ed214f1603650862b9..e086c1e868feefeb08947be89d86f5b77770fc9f 100644 --- a/wlan/hdi_service/BUILD.gn +++ b/wlan/hdi_service/BUILD.gn @@ -13,33 +13,25 @@ import("//build/ohos.gni") -HDI_WLAN_SERVICE_PATH = rebase_path("../../adapter/wlan") -cmd = "if [ -f ${HDI_WLAN_SERVICE_PATH}/BUILD.gn ]; then echo true; else echo false; fi" -HAVE_WLAN_DAL_SERVICE = - exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") - ohos_shared_library("libwlan_interface_service_1.1") { include_dirs = [ "../interfaces/include", "../client/include", "../hal/include", "./service_common", + "./service_extend", ] sources = [ "service_common/wlan_common_cmd.c", "wlan_interface_service.c", ] - deps = [ "../hal:wifi_hal" ] + deps = [ + "../hal:wifi_hal", + "service_extend:libwlan_service_extend", + ] external_deps = [ "drivers_interface_wlan:libwlan_stub_1.1" ] - if (HAVE_WLAN_DAL_SERVICE) { - external_deps += [ "hidl_adapter:service_extend" ] - include_dirs += [ "../../adapter/wlan" ] - } else { - deps += [ "service_extend:libwlan_service_extend" ] - include_dirs += [ "service_extend" ] - } defines = [ "__OHOS__USER__" ] cflags = [ @@ -72,21 +64,17 @@ ohos_shared_library("libwifi_hdi_c_device") { "../interfaces/include", "../client/include", "../hal/include", + "./service_extend", ] sources = [ "wlan_interface_drivers.c" ] - deps = [ ":libwlan_interface_service_1.1" ] + deps = [ + ":libwlan_interface_service_1.1", + "service_extend:libwlan_service_extend", + ] external_deps = [ "drivers_interface_wlan:libwlan_stub_1.1" ] - if (HAVE_WLAN_DAL_SERVICE) { - external_deps += [ "hidl_adapter:service_extend" ] - include_dirs += [ "../../adapter/wlan" ] - } else { - deps += [ "service_extend:libwlan_service_extend" ] - include_dirs += [ "service_extend" ] - } - cflags = [ "-Wall", "-Wextra", diff --git a/wlan/hdi_service/service_extend/BUILD.gn b/wlan/hdi_service/service_extend/BUILD.gn index af1bd67a59cc1ae9f1662fda4a28ab7568d1b8d1..77e2c927d66546319ed845cdc707a0e52c40b5ba 100644 --- a/wlan/hdi_service/service_extend/BUILD.gn +++ b/wlan/hdi_service/service_extend/BUILD.gn @@ -13,6 +13,7 @@ import("//build/ohos.gni") import("../../../../hdf_core/adapter/uhdf2/uhdf.gni") +import("../../wlan.gni") HDI_SERVICE_ROOT_DIR = "../.." @@ -24,7 +25,13 @@ ohos_shared_library("libwlan_service_extend") { "$HDI_SERVICE_ROOT_DIR/hdi_service/service_common", "$HDI_SERVICE_ROOT_DIR/hdi_service/service_extend", ] - sources = [ "wlan_extend_cmd.c" ] + sources = [] + + if (drivers_peripheral_wlan_feature_enable_HDF_WLAN_EXTEND_VDI) { + sources += [ "service_extend_vdi/wlan_extend_cmd.c" ] + } else { + sources += [ "service_extend_direct/wlan_extend_cmd.c" ] + } deps = [ "$HDI_SERVICE_ROOT_DIR/hal:wifi_hal" ] diff --git a/wlan/hdi_service/service_extend/wlan_extend_cmd.c b/wlan/hdi_service/service_extend/service_extend_direct/wlan_extend_cmd.c similarity index 100% rename from wlan/hdi_service/service_extend/wlan_extend_cmd.c rename to wlan/hdi_service/service_extend/service_extend_direct/wlan_extend_cmd.c diff --git a/wlan/hdi_service/service_extend/service_extend_vdi/wlan_extend_cmd.c b/wlan/hdi_service/service_extend/service_extend_vdi/wlan_extend_cmd.c new file mode 100644 index 0000000000000000000000000000000000000000..b8c423c0eb4bcf85902cbc6e46a81954103b2e08 --- /dev/null +++ b/wlan/hdi_service/service_extend/service_extend_vdi/wlan_extend_cmd.c @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2023 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 +#include +#include +#include +#include +#include +#include "v1_1/iwlan_interface.h" +#include "wifi_hal.h" +#include "wlan_common_cmd.h" +#include "wlan_extend_cmd_vdi.h" + +#define VDI_VERSION_ONE 1 + +struct WlanExtendInterfaceVdi *g_wlanExtendVdiImpl = NULL; +struct HdfVdiObject *g_vdi = NULL; + +static void CloseVdi() +{ + if (g_vdi != NULL) { + HdfCloseVdi(g_vdi); + g_vdi = NULL; + } +} + +static int32_t InitWlanExtendVdiImpl() +{ + uint32_t version = 0; + g_vdi = HdfLoadVdi(WLAN_EXTEND_VDI_LIBNAME); + if (g_vdi == NULL || g_vdi->vdiBase == NULL) { + HDF_LOGE("%{public}s: load wlan extend vdi failed", __func__); + return HDF_FAILURE; + } + + version = HdfGetVdiVersion(g_vdi); + if (version != VDI_VERSION_ONE) { + HDF_LOGE("%{public}s: get wlan extend vdi version failed", __func__); + CloseVdi(); + return HDF_FAILURE; + } + + struct VdiWrapperWlanExtend *vdiWrapperWlanExtend = NULL; + vdiWrapperWlanExtend = (struct VdiWrapperWlanExtend *)(g_vdi->vdiBase); + g_wlanExtendVdiImpl = vdiWrapperWlanExtend->wlanExtendModule; + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGE("%{public}s: get vibrator impl failed", __func__); + CloseVdi(); + return HDF_FAILURE; + } + + return HDF_SUCCESS; +} + +int32_t WlanInterfaceStartChannelMeas(struct IWlanInterface *self, const char *ifName, + const struct MeasChannelParam *measChannelParam) +{ + int32_t ret; + + (void)self; + if (ifName == NULL || measChannelParam == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__); + return HDF_FAILURE; + } + ret = g_wlanExtendVdiImpl->startChannelMeas(self, ifName, measChannelParam); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: start channel meas failed!, error code: %{public}d", __func__, ret); + } + return ret; +} + +int32_t WlanInterfaceGetChannelMeasResult(struct IWlanInterface *self, const char *ifName, + struct MeasChannelResult *measChannelResult) +{ + int32_t ret; + + (void)self; + if (ifName == NULL || measChannelResult == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGE("%{public}s g_wlanExtendVdiImplis NULL!", __func__); + return HDF_FAILURE; + } + ret = g_wlanExtendVdiImpl->getChannelMeasResult(self, ifName, measChannelResult); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: get channel meas result failed!, error code: %{public}d", __func__, ret); + } + return ret; +} + +int32_t WlanInterfaceWifiSendCmdIoctl(struct IWlanInterface *self, const char *ifName, int32_t cmdId, + const int8_t *paramBuf, uint32_t paramBufLen) +{ + int32_t ret; + + (void)self; + if (ifName == NULL || paramBuf == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__); + return HDF_FAILURE; + } + ret = g_wlanExtendVdiImpl->sendCmdIoctl(self, ifName, cmdId, paramBuf, paramBufLen); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: send ioctl command failed!, error code: %{public}d", __func__, ret); + } + return ret; +} + +int32_t WlanInterfaceRegisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName) +{ + int ret; + + if (func == NULL || ifName == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__); + return HDF_FAILURE; + } + ret = g_wlanExtendVdiImpl->registerHid2dCallback(func, ifName); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: Register hid2d callback failed!, error code: %{public}d", __func__, ret); + } + return ret; +} + +int32_t WlanInterfaceUnregisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName) +{ + int ret; + + if (func == NULL || ifName == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__); + return HDF_FAILURE; + } + ret = g_wlanExtendVdiImpl->unregisterHid2dCallback(func, ifName); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: Unregister hid2d callback failed!, error code: %{public}d", __func__, ret); + } + return ret; +} + +int32_t WlanExtendInterfaceWifiConstruct(void) +{ + if (g_wlanExtendVdiImpl != NULL) { + HDF_LOGI("%{public}s wlanExtendVdiImpl is not NULL!", __func__); + return HDF_SUCCESS; + } + + int32_t ret; + ret = InitWlanExtendVdiImpl(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret); + return HDF_FAILURE; + } + + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGE("%{public}s wlanExtendVdiImpl init failed!", __func__); + CloseVdi(); + return HDF_FAILURE; + } + ret = g_wlanExtendVdiImpl->wifiConstruct(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret); + CloseVdi(); + } + return ret; +} + +int32_t WlanExtendInterfaceWifiDestruct(void) +{ + if (g_wlanExtendVdiImpl == NULL) { + HDF_LOGI("%{public}s wlanExtendVdiImpl is NULL!", __func__); + return HDF_SUCCESS; + } + + int32_t ret; + ret = g_wlanExtendVdiImpl->wifiDestruct(); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s destruct WiFi failed! error code: %{public}d", __func__, ret); + } + CloseVdi(); + g_wlanExtendVdiImpl = NULL; + return ret; +} diff --git a/wlan/hdi_service/service_extend/service_extend_vdi/wlan_extend_cmd_vdi.h b/wlan/hdi_service/service_extend/service_extend_vdi/wlan_extend_cmd_vdi.h new file mode 100644 index 0000000000000000000000000000000000000000..f155b3660588ea6cbf097d128f8e06906a5c197e --- /dev/null +++ b/wlan/hdi_service/service_extend/service_extend_vdi/wlan_extend_cmd_vdi.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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 WLAN_EXTEND_VDI_CMD_H +#define WLAN_EXTEND_VDI_CMD_H + +#include "v1_1/iwlan_interface.h" +#include "hdf_load_vdi.h" +#include "wifi_hal.h" + +#define WLAN_EXTEND_VDI_LIBNAME "libhdi_wlan_impl.z.so" + +struct WlanExtendInterfaceVdi { + int32_t (*startChannelMeas)(struct IWlanInterface *self, const char *ifName, + const struct MeasChannelParam *measChannelParam); + int32_t (*getChannelMeasResult)(struct IWlanInterface *self, const char *ifName, + struct MeasChannelResult *measChannelResult); + int32_t (*sendCmdIoctl)(struct IWlanInterface *self, const char *ifName, int32_t cmdId, + const int8_t *paramBuf, uint32_t paramBufLen); + int32_t (*registerHid2dCallback)(Hid2dCallbackFunc func, const char *ifName); + int32_t (*unregisterHid2dCallback)(Hid2dCallbackFunc func, const char *ifName); + int32_t (*wifiConstruct)(void); + int32_t (*wifiDestruct)(void); +}; + +struct VdiWrapperWlanExtend { + struct HdfVdiBase base; + struct WlanExtendInterfaceVdi *wlanExtendModule; +}; +#endif diff --git a/wlan/hdi_service/service_extend/wlan_extend_cmd.h b/wlan/hdi_service/service_extend/wlan_extend_cmd.h index 104a596fe103799f35094948f8dcef76cb5be669..3e42fecd3ef5d1377b42a8ea614b46924c5765f7 100644 --- a/wlan/hdi_service/service_extend/wlan_extend_cmd.h +++ b/wlan/hdi_service/service_extend/wlan_extend_cmd.h @@ -16,6 +16,9 @@ #define WLAN_EXTEND_CMD_H #include "../wlan_impl.h" +#undef HDF_LOG_TAG +#define HDF_LOG_TAG "HDF_WIFI_CORE" + int32_t WlanInterfaceStartChannelMeas(struct IWlanInterface *self, const char *ifName, const struct MeasChannelParam *measChannelParam); int32_t WlanInterfaceGetChannelMeasResult(struct IWlanInterface *self, const char *ifName, diff --git a/wlan/wlan.gni b/wlan/wlan.gni index c0b019d4b1f71541b3ef76ad9b42b1eb626306f4..4f3e5306c02f591f4da92cacf9433143e8d1397e 100644 --- a/wlan/wlan.gni +++ b/wlan/wlan.gni @@ -14,4 +14,5 @@ declare_args() { drivers_peripheral_wlan_feature_enable_HDF_NL80211 = true drivers_peripheral_wlan_feature_enable_HDF_UT = false + drivers_peripheral_wlan_feature_enable_HDF_WLAN_EXTEND_VDI = false }