From dbf63579790d57b118dd3ba17cf9d998abc05064 Mon Sep 17 00:00:00 2001 From: wdh122119 Date: Wed, 20 Sep 2023 14:56:26 +0800 Subject: [PATCH] fit: add new interface:resetToFactoryMacAddress and getApBandwidth Signed-off-by: wdh122119 --- wlan/README_zh.md | 4 +- wlan/client/include/wifi_driver_client.h | 1 + wlan/client/src/netlink/netlink_cmd_adapter.c | 82 ++++++++++++++----- wlan/client/src/sbuf/sbuf_cmd_adapter.c | 34 ++++++++ wlan/client/src/wifi_common_cmd.h | 2 + wlan/hal/include/wifi_hal_cmd.h | 3 + wlan/hal/src/wifi_hal.c | 21 +---- wlan/hal/src/wifi_hal_ap_feature.c | 9 ++ wlan/hal/src/wifi_hal_base_feature.c | 9 ++ wlan/hal/src/wifi_hal_cmd.c | 52 ++++++++++++ wlan/hdi_service/BUILD.gn | 10 +-- .../service_common/wlan_common_cmd.c | 52 +++++++++++- .../service_common/wlan_common_cmd.h | 3 + .../service_extend_direct/wlan_extend_cmd.c | 2 +- .../service_extend_vdi/wlan_extend_cmd.c | 2 +- .../service_extend_vdi/wlan_extend_cmd_vdi.h | 2 +- wlan/hdi_service/wlan_impl.h | 2 +- wlan/hdi_service/wlan_interface_drivers.c | 2 +- wlan/hdi_service/wlan_interface_service.c | 8 +- wlan/interfaces/include/wifi_hal_ap_feature.h | 14 ++++ .../include/wifi_hal_base_feature.h | 13 +++ wlan/test/fuzztest/ap_fuzzer/BUILD.gn | 2 +- wlan/test/fuzztest/sta_fuzzer/BUILD.gn | 2 +- wlan/test/fuzztest/wlan_common_fuzzer.h | 4 +- wlan/test/hdi_service/BUILD.gn | 2 +- wlan/test/hdi_service/wlan_callback_impl.h | 8 +- .../test/hdi_service/wlan_hdi_direct_test.cpp | 2 +- .../wlan_hdi_hal_services_c_test.cpp | 65 ++++++++++++++- 28 files changed, 343 insertions(+), 69 deletions(-) diff --git a/wlan/README_zh.md b/wlan/README_zh.md index b8e05ccfda..93c9ea22df 100644 --- a/wlan/README_zh.md +++ b/wlan/README_zh.md @@ -51,7 +51,7 @@ WLAN驱动模块通过HAL/HDI层(HAL是直调,HDI是通过IPC调用)对Wi-Fi S -

v1_1/iwlan_interface.h(V1_1为版本号,随着接口的增加而改变)

+

v1_2/iwlan_interface.h(V1_2为版本号,随着接口的增加而改变)

int32_t (*Start)(struct IWlanInterface *self);

@@ -371,7 +371,7 @@ HDI接口使用步骤: 代码示例: ``` -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" #include "wlan_callback_impl.h" #include "wlan_impl.h" diff --git a/wlan/client/include/wifi_driver_client.h b/wlan/client/include/wifi_driver_client.h index e50b1ed71b..f6154e53c2 100644 --- a/wlan/client/include/wifi_driver_client.h +++ b/wlan/client/include/wifi_driver_client.h @@ -345,6 +345,7 @@ int32_t GetStationInfo(const char *ifName, StationInfo *info, const uint8_t *mac int32_t WifiStartPnoScan(const char *ifName, const WifiPnoSettings *pnoSettings); int32_t WifiStopPnoScan(const char *ifName); int32_t WifiGetSignalPollInfo(const char *ifName, struct SignalResult *signalResult); +int32_t ClientGetApBandwidth(const char *ifName, uint8_t *bandwidth); /* wpa related interface */ #define MAX_NR_CIPHER_SUITES 5 diff --git a/wlan/client/src/netlink/netlink_cmd_adapter.c b/wlan/client/src/netlink/netlink_cmd_adapter.c index cabc2813b7..cdd50b1430 100644 --- a/wlan/client/src/netlink/netlink_cmd_adapter.c +++ b/wlan/client/src/netlink/netlink_cmd_adapter.c @@ -69,6 +69,8 @@ #define CMD_SET_GO_DETECT_RADAR "CMD_SET_GO_DETECT_RADAR" #define CMD_SET_DYNAMIC_DBAC_MODE "SET_DYNAMIC_DBAC_MODE" #define CMD_SET_P2P_SCENES "CMD_SET_P2P_SCENES" +#define CMD_GET_AP_BANDWIDTH "GET_AP_BANDWIDTH" + #define P2P_BUF_SIZE 64 #define MAX_PRIV_CMD_SIZE 4096 #define LOW_LITMIT_FREQ_2_4G 2400 @@ -1599,18 +1601,16 @@ int32_t GetChannelMeasResult(const char *ifName, struct MeasResult *measResult) return RET_CODE_NOT_SUPPORT; } -static int32_t SendCommandToDriver(const char *cmd, uint32_t len, const char *ifName) +static int32_t SendCommandToDriver(const char *cmd, uint32_t len, const char *ifName, WifiPrivCmd *out) { struct ifreq ifr; - WifiPrivCmd privCmd = {0}; - uint8_t buf[MAX_PRIV_CMD_SIZE] = {0}; int32_t ret = RET_CODE_FAILURE; - if (cmd == NULL) { - HILOG_ERROR(LOG_CORE, "%{public}s: cmd is null", __FUNCTION__); + if (cmd == NULL || out == NULL) { + HILOG_ERROR(LOG_CORE, "%{public}s: cmd or out is null", __FUNCTION__); return RET_CODE_INVALID_PARAM; } - if (len > MAX_PRIV_CMD_SIZE) { + if (len > out->size) { HILOG_ERROR(LOG_CORE, "%{public}s: Size of command is too large", __FUNCTION__); return RET_CODE_INVALID_PARAM; } @@ -1618,14 +1618,12 @@ static int32_t SendCommandToDriver(const char *cmd, uint32_t len, const char *if HILOG_ERROR(LOG_CORE, "%s: memset_s ifr failed", __FUNCTION__); return RET_CODE_FAILURE; } - if (memcpy_s(buf, MAX_PRIV_CMD_SIZE, cmd, len) != EOK) { + if (memcpy_s(out->buf, out->size, cmd, len) != EOK) { HILOG_ERROR(LOG_CORE, "%{public}s: memcpy_s error", __FUNCTION__); return RET_CODE_FAILURE; } - privCmd.buf = buf; - privCmd.size = sizeof(buf); - privCmd.len = len; - ifr.ifr_data = (void *)&privCmd; + out->len = len; + ifr.ifr_data = (void *)out; if (strcpy_s(ifr.ifr_name, IFNAMSIZ, ifName) != EOK) { HILOG_ERROR(LOG_CORE, "%s: strcpy_s error", __FUNCTION__); return RET_CODE_FAILURE; @@ -1644,11 +1642,6 @@ static int32_t SendCommandToDriver(const char *cmd, uint32_t len, const char *if ret = (errno == EOPNOTSUPP) ? RET_CODE_NOT_SUPPORT : RET_CODE_FAILURE; break; } - (void)memset_s((void *)cmd, len, 0, len); - if (memcpy_s((void *)cmd, len, privCmd.buf, len - 1) != EOK) { - HILOG_ERROR(LOG_CORE, "%{public}s: memcpy_s error", __FUNCTION__); - ret = RET_CODE_FAILURE; - } } while (0); close(sock); @@ -1694,7 +1687,11 @@ static int32_t DisableNextCacOnce(const char *ifName) { char cmdBuf[P2P_BUF_SIZE] = {CMD_SET_CLOSE_GO_CAC}; - return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); + uint8_t buf[MAX_PRIV_CMD_SIZE] = {0}; + WifiPrivCmd out = {0}; + out.buf = buf; + out.size = MAX_PRIV_CMD_SIZE; + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName, &out); } static int32_t SetGoChannel(const char *ifName, const int8_t *data, uint32_t len) @@ -1718,7 +1715,12 @@ static int32_t SetGoChannel(const char *ifName, const int8_t *data, uint32_t len HILOG_ERROR(LOG_CORE, "%{public}s: interface state is not OK.", __FUNCTION__); return RET_CODE_NETDOWN; } - return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); + + uint8_t buf[MAX_PRIV_CMD_SIZE] = {0}; + WifiPrivCmd out = {0}; + out.buf = buf; + out.size = MAX_PRIV_CMD_SIZE; + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName, &out); } static int32_t SetGoDetectRadar(const char *ifName, const int8_t *data, uint32_t len) @@ -1742,7 +1744,12 @@ static int32_t SetGoDetectRadar(const char *ifName, const int8_t *data, uint32_t HILOG_ERROR(LOG_CORE, "%{public}s: interface state is not OK.", __FUNCTION__); return RET_CODE_NETDOWN; } - return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); + + uint8_t buf[MAX_PRIV_CMD_SIZE] = {0}; + WifiPrivCmd out = {0}; + out.buf = buf; + out.size = MAX_PRIV_CMD_SIZE; + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName, &out); } static int32_t SetP2pScenes(const char *ifName, const int8_t *data, uint32_t len) @@ -1766,7 +1773,12 @@ static int32_t SetP2pScenes(const char *ifName, const int8_t *data, uint32_t len HILOG_ERROR(LOG_CORE, "%{public}s: interface state is not OK.", __FUNCTION__); return RET_CODE_NETDOWN; } - return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); + + uint8_t buf[MAX_PRIV_CMD_SIZE] = {0}; + WifiPrivCmd out = {0}; + out.buf = buf; + out.size = MAX_PRIV_CMD_SIZE; + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName, &out); } static int32_t SetDynamicDbacMode(const char *ifName, const int8_t *data, uint32_t len) @@ -1790,7 +1802,12 @@ static int32_t SetDynamicDbacMode(const char *ifName, const int8_t *data, uint32 HILOG_ERROR(LOG_CORE, "%{public}s: interface state is not OK.", __FUNCTION__); return RET_CODE_NETDOWN; } - return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); + + uint8_t buf[MAX_PRIV_CMD_SIZE] = {0}; + WifiPrivCmd out = {0}; + out.buf = buf; + out.size = MAX_PRIV_CMD_SIZE; + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName, &out); } int32_t SetProjectionScreenParam(const char *ifName, const ProjectionScreenParam *param) @@ -2647,6 +2664,29 @@ static int32_t SignalInfoHandler(struct nl_msg *msg, void *arg) return NL_SKIP; } +int32_t ClientGetApBandwidth(const char *ifName, uint8_t *bandwidth) +{ + if (ifName == NULL || bandwidth == NULL) { + HILOG_ERROR(LOG_CORE, "%s: param is NULL.", __FUNCTION__); + return RET_CODE_FAILURE; + } + + const char *cmd = CMD_GET_AP_BANDWIDTH; + uint8_t buf[MAX_PRIV_CMD_SIZE] = {0}; + WifiPrivCmd out = {0}; + out.buf = buf; + out.size = MAX_PRIV_CMD_SIZE; + int32_t ret = SendCommandToDriver(cmd, strlen(cmd), ifName, &out); + if (ret != RET_CODE_SUCCESS) { + HILOG_ERROR(LOG_CORE, "%s: send command to driver failed, code=%d", __FUNCTION__, ret); + return ret; + } + *bandwidth = *out.buf; + + HILOG_INFO(LOG_CORE, "%s: AP bandwidth: %d", __FUNCTION__, *bandwidth); + return RET_CODE_SUCCESS; +} + int32_t WifiGetSignalPollInfo(const char *ifName, struct SignalResult *signalResult) { struct nl_msg *msg = NULL; diff --git a/wlan/client/src/sbuf/sbuf_cmd_adapter.c b/wlan/client/src/sbuf/sbuf_cmd_adapter.c index a6a2d8c185..5e6fe4c090 100644 --- a/wlan/client/src/sbuf/sbuf_cmd_adapter.c +++ b/wlan/client/src/sbuf/sbuf_cmd_adapter.c @@ -1083,6 +1083,40 @@ int32_t WifiStopPnoScan(const char *ifName) return ret; } +int32_t ClientGetApBandwidth(const char *ifName, uint8_t *bandwidth) +{ + int32_t ret; + struct HdfSBuf *data = NULL; + struct HdfSBuf *reply = NULL; + + if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) { + HDF_LOGE("%s: HdfSbufObtainDefault fail", __FUNCTION__); + return RET_CODE_FAILURE; + } + + do { + if (!HdfSbufWriteString(data, ifName)) { + HDF_LOGE("%s: write ifName fail!", __FUNCTION__); + ret = RET_CODE_FAILURE; + break; + } + ret = SendCmdSync(WIFI_HAL_CMD_GET_AP_BANDWIDTH, data, reply); + if (ret != RET_CODE_SUCCESS) { + HDF_LOGE("%s: SendCmdSync fail, code=%d", __FUNCTION__, ret); + break; + } + if (!HdfSbufReadUint8(reply, bandwidth)) { + HDF_LOGE("%s: HdfSbufReadUint8 failed", __FUNCTION__); + ret = RET_CODE_FAILURE; + break; + } + } while (0); + + HdfSbufRecycle(data); + HdfSbufRecycle(reply); + return ret; +} + int32_t WifiGetSignalPollInfo(const char *ifName, struct SignalResult *signalResult) { int32_t ret = RET_CODE_FAILURE; diff --git a/wlan/client/src/wifi_common_cmd.h b/wlan/client/src/wifi_common_cmd.h index 35cd5c4956..3ba0c2e636 100644 --- a/wlan/client/src/wifi_common_cmd.h +++ b/wlan/client/src/wifi_common_cmd.h @@ -69,6 +69,7 @@ enum APCommands { CMD_AP_DEL_STATION, CMD_AP_GET_ASSOC_STA, CMD_AP_SET_COUNTRY_CODE, + CMD_AP_GET_BANDWIDTH, }; enum STACommands { @@ -119,6 +120,7 @@ typedef enum { WIFI_HAL_CMD_START_PNO_SCAN = HDF_WIFI_CMD(STA_SERVICE_ID, CMD_STA_START_PNO_SCAN), WIFI_HAL_CMD_STOP_PNO_SCAN = HDF_WIFI_CMD(STA_SERVICE_ID, CMD_STA_STOP_PNO_SCAN), WIFI_HAL_CMD_GET_SIGNAL_INFO = HDF_WIFI_CMD(STA_SERVICE_ID, CMD_STA_GET_SIGNAL_INFO), + WIFI_HAL_CMD_GET_AP_BANDWIDTH = HDF_WIFI_CMD(AP_SERVICE_ID, CMD_AP_GET_BANDWIDTH), } WifiHalCmd; typedef enum { diff --git a/wlan/hal/include/wifi_hal_cmd.h b/wlan/hal/include/wifi_hal_cmd.h index 352aea6d6b..80ccfc5664 100644 --- a/wlan/hal/include/wifi_hal_cmd.h +++ b/wlan/hal/include/wifi_hal_cmd.h @@ -44,6 +44,9 @@ int32_t HalCmdStartScanInner(const char *ifName, WifiScan *scan); int32_t HalCmdStartPnoScan(const char *ifName, const WifiPnoSettings *pnoSettings); int32_t HalCmdStopPnoScan(const char *ifName); int32_t HalCmdGetSignalPollInfo(const char *ifName, struct SignalResult *signalResult); +int32_t HalCmdGetFeatureByIfName(const char *ifName, struct IWiFiBaseFeature **ifeature); +int32_t HalCmdGetApBandwidth(const char *ifName, uint8_t *bandwidth); +int32_t HalCmdResetToFactoryMacAddress(const char *ifNames); struct DListHead *GetNetworkHead(void); void ClearIWiFiList(void); diff --git a/wlan/hal/src/wifi_hal.c b/wlan/hal/src/wifi_hal.c index 7fa39533cb..72c20b80a5 100644 --- a/wlan/hal/src/wifi_hal.c +++ b/wlan/hal/src/wifi_hal.c @@ -182,25 +182,6 @@ static int32_t CreateFeatureInner(int32_t type, struct IWiFiBaseFeature **ifeatu return HDF_SUCCESS; } -static int32_t GetFeatureByIfNameInner(const char *ifName, struct IWiFiBaseFeature **ifeature) -{ - struct DListHead *networkHead = GetNetworkHead(); - struct IWiFiList *networkNode = NULL; - - if (ifName == NULL) { - HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); - return HDF_ERR_INVALID_PARAM; - } - DLIST_FOR_EACH_ENTRY(networkNode, networkHead, struct IWiFiList, entry) { - if (strcmp(networkNode->ifName, ifName) == HDF_SUCCESS) { - *ifeature = networkNode->ifeature; - return HDF_SUCCESS; - } - } - HDF_LOGE("%s: cannot find feature by ifName, line: %d", __FUNCTION__, __LINE__); - return HDF_FAILURE; -} - static int32_t DestroyFeatureInner(struct IWiFiBaseFeature *ifeature) { struct DListHead *networkHead = GetNetworkHead(); @@ -394,7 +375,7 @@ static int32_t CreateFeature(int32_t type, struct IWiFiBaseFeature **ifeature) static int32_t GetFeatureByIfName(const char *ifName, struct IWiFiBaseFeature **ifeature) { HalMutexLock(); - int32_t ret = GetFeatureByIfNameInner(ifName, ifeature); + int32_t ret = HalCmdGetFeatureByIfName(ifName, ifeature); HalMutexUnlock(); return ret; } diff --git a/wlan/hal/src/wifi_hal_ap_feature.c b/wlan/hal/src/wifi_hal_ap_feature.c index 9303993d13..7de24ea75d 100644 --- a/wlan/hal/src/wifi_hal_ap_feature.c +++ b/wlan/hal/src/wifi_hal_ap_feature.c @@ -62,6 +62,14 @@ static int32_t HalSetCountryCode(const struct IWiFiAp *apFeature, const char *co return ret; } +static int32_t HalGetApBandwidth(const char *ifName, uint8_t *bandwidth) +{ + HalMutexLock(); + int32_t ret = HalCmdGetApBandwidth(ifName, bandwidth); + HalMutexUnlock(); + return ret; +} + int32_t InitApFeature(struct IWiFiAp **fe) { if (fe == NULL || *fe == NULL) { @@ -74,6 +82,7 @@ int32_t InitApFeature(struct IWiFiAp **fe) } (*fe)->getAssociatedStas = HalGetAssociatedStas; (*fe)->setCountryCode = HalSetCountryCode; + (*fe)->getApBandwidth = HalGetApBandwidth; return HDF_SUCCESS; } diff --git a/wlan/hal/src/wifi_hal_base_feature.c b/wlan/hal/src/wifi_hal_base_feature.c index 35c568d7a2..6d5cf11102 100644 --- a/wlan/hal/src/wifi_hal_base_feature.c +++ b/wlan/hal/src/wifi_hal_base_feature.c @@ -164,6 +164,14 @@ static int32_t HalGetIfNamesByChipId(const uint8_t chipId, char **ifNames, uint3 return ret; } +static int32_t HalResetToFactoryMacAddress(const char *ifName) +{ + HalMutexLock(); + int32_t ret = HalCmdResetToFactoryMacAddress(ifName); + HalMutexUnlock(); + return ret; +} + int32_t InitBaseFeature(struct IWiFiBaseFeature **fe) { if (fe == NULL || *fe == NULL) { @@ -178,6 +186,7 @@ int32_t InitBaseFeature(struct IWiFiBaseFeature **fe) (*fe)->setTxPower = HalSetTxPower; (*fe)->getChipId = HalGetChipId; (*fe)->getIfNamesByChipId = HalGetIfNamesByChipId; + (*fe)->resetToFactoryMacAddress = HalResetToFactoryMacAddress; return HDF_SUCCESS; } diff --git a/wlan/hal/src/wifi_hal_cmd.c b/wlan/hal/src/wifi_hal_cmd.c index fbd7e23edb..4dd6cc7264 100644 --- a/wlan/hal/src/wifi_hal_cmd.c +++ b/wlan/hal/src/wifi_hal_cmd.c @@ -296,6 +296,58 @@ int32_t HalCmdSetResetDriver(const uint8_t chipId, const char *ifName) return ret; } +int32_t HalCmdGetFeatureByIfName(const char *ifName, struct IWiFiBaseFeature **ifeature) +{ + struct DListHead *networkHead = GetNetworkHead(); + struct IWiFiList *networkNode = NULL; + + if (ifName == NULL || ifeature == NULL) { + HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + DLIST_FOR_EACH_ENTRY(networkNode, networkHead, struct IWiFiList, entry) { + if (strcmp(networkNode->ifName, ifName) == HDF_SUCCESS) { + *ifeature = networkNode->ifeature; + return HDF_SUCCESS; + } + } + HDF_LOGE("%s: cannot find feature by ifName, line: %d", __FUNCTION__, __LINE__); + return HDF_FAILURE; +} + +int32_t HalCmdGetApBandwidth(const char *ifName, uint8_t *bandwidth) +{ + int32_t ret = ClientGetApBandwidth(ifName, bandwidth); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: get ap bandwidth failed, code=%d", __FUNCTION__, ret); + } + return ret; +} + +int32_t HalCmdResetToFactoryMacAddress(const char *ifName) +{ + int32_t ret; + struct IWiFiBaseFeature *ifeature = NULL; + ret = HalCmdGetFeatureByIfName(ifName, &ifeature); + if (ret != HDF_SUCCESS || ifeature == NULL) { + HDF_LOGE("%s: hal cmd get devmac addr failed, code=%d", __FUNCTION__, ret); + return ret; + } + + unsigned char mac[ETH_ADDR_LEN] = {0}; + ret = HalCmdGetDevMacAddr(ifName, ifeature->type, mac, ETH_ADDR_LEN); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: hal cmd get devmac addr failed, code=%d", __FUNCTION__, ret); + return ret; + } + + ret = HalCmdSetMacAddr(ifName, mac, ETH_ADDR_LEN); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: hal cmd set mac addr failed, code=%d", __FUNCTION__, ret); + } + return ret; +} + void ClearIWiFiList(void) { struct IWiFiList *networkList = NULL; diff --git a/wlan/hdi_service/BUILD.gn b/wlan/hdi_service/BUILD.gn index e086c1e868..c2f6da7575 100644 --- a/wlan/hdi_service/BUILD.gn +++ b/wlan/hdi_service/BUILD.gn @@ -13,7 +13,7 @@ import("//build/ohos.gni") -ohos_shared_library("libwlan_interface_service_1.1") { +ohos_shared_library("libwlan_interface_service_1.2") { include_dirs = [ "../interfaces/include", "../client/include", @@ -30,7 +30,7 @@ ohos_shared_library("libwlan_interface_service_1.1") { "../hal:wifi_hal", "service_extend:libwlan_service_extend", ] - external_deps = [ "drivers_interface_wlan:libwlan_stub_1.1" ] + external_deps = [ "drivers_interface_wlan:libwlan_stub_1.2" ] defines = [ "__OHOS__USER__" ] @@ -70,10 +70,10 @@ ohos_shared_library("libwifi_hdi_c_device") { sources = [ "wlan_interface_drivers.c" ] deps = [ - ":libwlan_interface_service_1.1", + ":libwlan_interface_service_1.2", "service_extend:libwlan_service_extend", ] - external_deps = [ "drivers_interface_wlan:libwlan_stub_1.1" ] + external_deps = [ "drivers_interface_wlan:libwlan_stub_1.2" ] cflags = [ "-Wall", @@ -106,6 +106,6 @@ ohos_shared_library("libwifi_hdi_c_device") { group("hdi_wlan_service") { deps = [ ":libwifi_hdi_c_device", - ":libwlan_interface_service_1.1", + ":libwlan_interface_service_1.2", ] } diff --git a/wlan/hdi_service/service_common/wlan_common_cmd.c b/wlan/hdi_service/service_common/wlan_common_cmd.c index 41f4bd692a..d9e172daee 100644 --- a/wlan/hdi_service/service_common/wlan_common_cmd.c +++ b/wlan/hdi_service/service_common/wlan_common_cmd.c @@ -19,8 +19,8 @@ #include #include #include "wlan_extend_cmd.h" -#include "v1_1/iwlan_callback.h" -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_callback.h" +#include "v1_2/iwlan_interface.h" struct IWiFi *g_wifi = NULL; struct IWiFiAp *g_apFeature = NULL; @@ -1428,6 +1428,54 @@ int32_t WlanInterfaceGetSignalPollInfo(struct IWlanInterface *self, const char * return ret; } +int32_t WlanInterfaceGetApBandwidth(struct IWlanInterface *self, const char *ifName, + uint8_t *bandwidth) +{ + int32_t ret; + (void)self; + + if (ifName == NULL || bandwidth == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_apFeature == NULL || g_apFeature->getApBandwidth == NULL) { + HDF_LOGE("%{public}s g_apFeature or g_staFeature->getApBandwidth is NULL!", __func__); + return HDF_FAILURE; + } + ret = g_apFeature->getApBandwidth(ifName, bandwidth); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: get signal information failed!, error code: %d", __func__, ret); + } + return ret; +} + +int32_t WlanInterfaceResetToFactoryMacAddress(struct IWlanInterface *self, const char *ifName) +{ + int32_t ret; + + (void)self; + if (ifName == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (g_staFeature != NULL) { + HDF_LOGD("%{public}s g_staFeature is not NULL!", __func__); + ret = g_staFeature->baseFeature.resetToFactoryMacAddress(ifName); + } else if (g_apFeature != NULL) { + HDF_LOGD("%{public}s g_apFeature is not NULL!", __func__); + ret = g_apFeature->baseFeature.resetToFactoryMacAddress(ifName); + } else { + HDF_LOGE("%{public}s: ap and sta feature is Invalid.", __func__); + ret = HDF_FAILURE; + } + + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s get name failed!, error code: %{public}d", __func__, ret); + } + return ret; +} + int32_t WlanInterfaceWifiConstruct(void) { int32_t ret; diff --git a/wlan/hdi_service/service_common/wlan_common_cmd.h b/wlan/hdi_service/service_common/wlan_common_cmd.h index b9122a46ef..953c4c3bb8 100644 --- a/wlan/hdi_service/service_common/wlan_common_cmd.h +++ b/wlan/hdi_service/service_common/wlan_common_cmd.h @@ -64,6 +64,9 @@ int32_t WlanInterfaceStartPnoScan(struct IWlanInterface *self, const char *ifNam int32_t WlanInterfaceStopPnoScan(struct IWlanInterface *self, const char *ifName); int32_t WlanInterfaceGetSignalPollInfo(struct IWlanInterface *self, const char *ifName, struct SignalPollResult *signalResult); +int32_t WlanInterfaceGetApBandwidth(struct IWlanInterface *self, const char *ifName, + uint8_t *bandwidth); +int32_t WlanInterfaceResetToFactoryMacAddress(struct IWlanInterface *self, const char *ifName); int32_t WlanInterfaceWifiConstruct(void); int32_t WlanInterfaceWifiDestruct(void); #endif diff --git a/wlan/hdi_service/service_extend/service_extend_direct/wlan_extend_cmd.c b/wlan/hdi_service/service_extend/service_extend_direct/wlan_extend_cmd.c index b48bd470c9..7197244816 100644 --- a/wlan/hdi_service/service_extend/service_extend_direct/wlan_extend_cmd.c +++ b/wlan/hdi_service/service_extend/service_extend_direct/wlan_extend_cmd.c @@ -17,7 +17,7 @@ #include #include #include -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" #include "wifi_hal.h" #include "wlan_common_cmd.h" 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 index c54279d7af..05d12b3132 100644 --- 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 @@ -18,7 +18,7 @@ #include #include #include -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" #include "wifi_hal.h" #include "wlan_common_cmd.h" #include "wlan_extend_cmd_vdi.h" 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 index f155b36605..304fe37755 100644 --- 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 @@ -15,7 +15,7 @@ #ifndef WLAN_EXTEND_VDI_CMD_H #define WLAN_EXTEND_VDI_CMD_H -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" #include "hdf_load_vdi.h" #include "wifi_hal.h" diff --git a/wlan/hdi_service/wlan_impl.h b/wlan/hdi_service/wlan_impl.h index 01c4b99f64..9a60b1dd2c 100644 --- a/wlan/hdi_service/wlan_impl.h +++ b/wlan/hdi_service/wlan_impl.h @@ -25,7 +25,7 @@ #include "hdf_dlist.h" #include "osal_mutex.h" #include "securec.h" -#include "v1_1/wlan_interface_stub.h" +#include "v1_2/wlan_interface_stub.h" #include "wifi_hal.h" #include "wifi_hal_ap_feature.h" #include "wifi_hal_base_feature.h" diff --git a/wlan/hdi_service/wlan_interface_drivers.c b/wlan/hdi_service/wlan_interface_drivers.c index 6e101ab3af..39804be4b6 100644 --- a/wlan/hdi_service/wlan_interface_drivers.c +++ b/wlan/hdi_service/wlan_interface_drivers.c @@ -21,7 +21,7 @@ #include #include #include -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" #include "wlan_impl.h" struct HdfWlanInterfaceHost { diff --git a/wlan/hdi_service/wlan_interface_service.c b/wlan/hdi_service/wlan_interface_service.c index 6260274d88..c33de526a8 100644 --- a/wlan/hdi_service/wlan_interface_service.c +++ b/wlan/hdi_service/wlan_interface_service.c @@ -17,12 +17,12 @@ #include #include #include -#include "v1_1/iwlan_callback.h" -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_callback.h" +#include "v1_2/iwlan_interface.h" #include "wlan_common_cmd.h" #include "wlan_extend_cmd.h" #include "wlan_impl.h" -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" struct WlanInterfaceService { struct IWlanInterface interface; @@ -70,6 +70,8 @@ struct IWlanInterface *WlanInterfaceImplGetInstance(void) service->interface.StartPnoScan = WlanInterfaceStartPnoScan; service->interface.StopPnoScan = WlanInterfaceStopPnoScan; service->interface.GetSignalPollInfo = WlanInterfaceGetSignalPollInfo; + service->interface.GetApBandwidth = WlanInterfaceGetApBandwidth; + service->interface.ResetToFactoryMacAddress = WlanInterfaceResetToFactoryMacAddress; return &service->interface; } diff --git a/wlan/interfaces/include/wifi_hal_ap_feature.h b/wlan/interfaces/include/wifi_hal_ap_feature.h index 0fc9d34025..8486e937f3 100644 --- a/wlan/interfaces/include/wifi_hal_ap_feature.h +++ b/wlan/interfaces/include/wifi_hal_ap_feature.h @@ -96,6 +96,20 @@ struct IWiFiAp { * @version 1.0 */ int32_t (*setCountryCode)(const struct IWiFiAp *apFeature, const char *code, uint32_t len); + + /** + * @brief Obtain ap current bandwidth. + * + * @param ifName Indicates the NIC name. + * @param bandwidth ap current bandwidth, 1(20M), 2(40M), 4(80M), 8(160M). + * + * @return Returns 0 if the operation is successful. + * @return Returns a negative value if the operation fails. + * + * @since 4.1 + * @version 1.2 + */ + int32_t (*getApBandwidth)(const char *ifName, uint8_t *bandwidth); }; /** diff --git a/wlan/interfaces/include/wifi_hal_base_feature.h b/wlan/interfaces/include/wifi_hal_base_feature.h index 03870c095d..4cf787f9a5 100644 --- a/wlan/interfaces/include/wifi_hal_base_feature.h +++ b/wlan/interfaces/include/wifi_hal_base_feature.h @@ -210,6 +210,19 @@ struct IWiFiBaseFeature { * @version 1.0 */ int32_t (*getIfNamesByChipId)(const uint8_t chipId, char **ifNames, uint32_t *num); + + /** + * @brief reset to factory mac address(permanent hardware address). + * + * @param ifName Indicates the NIC name. + * + * @return Returns 0 if the operation is successful. + * @return Returns a negative value if the operation fails. + * + * @since 4.1 + * @version 1.2 + */ + int32_t (*resetToFactoryMacAddress)(const char *ifNames); }; /** diff --git a/wlan/test/fuzztest/ap_fuzzer/BUILD.gn b/wlan/test/fuzztest/ap_fuzzer/BUILD.gn index 7fdaa51a26..51ea2349d4 100644 --- a/wlan/test/fuzztest/ap_fuzzer/BUILD.gn +++ b/wlan/test/fuzztest/ap_fuzzer/BUILD.gn @@ -32,7 +32,7 @@ ohos_fuzztest("ApFuzzTest") { deps = [ "$TEST_ROOT_DIR/hdi_service:hdi_wlan_service" ] external_deps = [ - "drivers_interface_wlan:libwlan_proxy_1.1", + "drivers_interface_wlan:libwlan_proxy_1.2", "hdf_core:libhdf_utils", "hilog:libhilog", ] diff --git a/wlan/test/fuzztest/sta_fuzzer/BUILD.gn b/wlan/test/fuzztest/sta_fuzzer/BUILD.gn index 6ab9848cae..b28abe5cf7 100644 --- a/wlan/test/fuzztest/sta_fuzzer/BUILD.gn +++ b/wlan/test/fuzztest/sta_fuzzer/BUILD.gn @@ -34,7 +34,7 @@ ohos_fuzztest("StaFuzzTest") { public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ] external_deps = [ - "drivers_interface_wlan:libwlan_proxy_1.1", + "drivers_interface_wlan:libwlan_proxy_1.2", "hdf_core:libhdf_utils", "hilog:libhilog", ] diff --git a/wlan/test/fuzztest/wlan_common_fuzzer.h b/wlan/test/fuzztest/wlan_common_fuzzer.h index 1bc81666ac..749d1d4978 100644 --- a/wlan/test/fuzztest/wlan_common_fuzzer.h +++ b/wlan/test/fuzztest/wlan_common_fuzzer.h @@ -16,8 +16,8 @@ #ifndef WLAN_COMMON_FUZZER_H #define WLAN_COMMON_FUZZER_H #include "hdf_log.h" -#include "v1_1/iwlan_interface.h" -#include "v1_1/wlan_types.h" +#include "v1_2/iwlan_interface.h" +#include "v1_2/wlan_types.h" #include "wlan_callback_impl.h" #include "wifi_hal_base_feature.h" #include "securec.h" diff --git a/wlan/test/hdi_service/BUILD.gn b/wlan/test/hdi_service/BUILD.gn index cd96936ebc..3ee6ea1fc9 100644 --- a/wlan/test/hdi_service/BUILD.gn +++ b/wlan/test/hdi_service/BUILD.gn @@ -44,7 +44,7 @@ ohos_unittest("WlanHdiServiceTestC") { if (is_standard_system) { external_deps = [ "c_utils:utils", - "drivers_interface_wlan:libwlan_proxy_1.1", + "drivers_interface_wlan:libwlan_proxy_1.2", "hdf_core:libhdf_host", "hdf_core:libhdf_utils", "hilog:libhilog", diff --git a/wlan/test/hdi_service/wlan_callback_impl.h b/wlan/test/hdi_service/wlan_callback_impl.h index 4e0b100340..395477d850 100644 --- a/wlan/test/hdi_service/wlan_callback_impl.h +++ b/wlan/test/hdi_service/wlan_callback_impl.h @@ -13,10 +13,10 @@ * limitations under the License. */ -#ifndef OHOS_HDI_WLAN_V1_1_WLANCALLBACKSERVICE_H -#define OHOS_HDI_WLAN_V1_1_WLANCALLBACKSERVICE_H +#ifndef OHOS_HDI_WLAN_V1_2_WLANCALLBACKSERVICE_H +#define OHOS_HDI_WLAN_V1_2_WLANCALLBACKSERVICE_H -#include "v1_1/iwlan_callback.h" +#include "v1_2/iwlan_callback.h" #ifdef __cplusplus extern "C" { @@ -33,4 +33,4 @@ void WlanCallbackServiceRelease(struct IWlanCallback *instance); } #endif /* __cplusplus */ -#endif // OHOS_HDI_WLAN_V1_1_WLANCALLBACKSERVICE_H \ No newline at end of file +#endif // OHOS_HDI_WLAN_V1_2_WLANCALLBACKSERVICE_H \ No newline at end of file diff --git a/wlan/test/hdi_service/wlan_hdi_direct_test.cpp b/wlan/test/hdi_service/wlan_hdi_direct_test.cpp index d956c20771..d730ad8185 100644 --- a/wlan/test/hdi_service/wlan_hdi_direct_test.cpp +++ b/wlan/test/hdi_service/wlan_hdi_direct_test.cpp @@ -14,7 +14,7 @@ */ #include #include -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" #include "wlan_callback_impl.h" #include "wlan_impl.h" diff --git a/wlan/test/hdi_service/wlan_hdi_hal_services_c_test.cpp b/wlan/test/hdi_service/wlan_hdi_hal_services_c_test.cpp index c7c512439e..6d43378eb2 100644 --- a/wlan/test/hdi_service/wlan_hdi_hal_services_c_test.cpp +++ b/wlan/test/hdi_service/wlan_hdi_hal_services_c_test.cpp @@ -14,7 +14,7 @@ */ #include #include -#include "v1_1/iwlan_interface.h" +#include "v1_2/iwlan_interface.h" #include "wlan_callback_impl.h" #include "wlan_impl.h" @@ -1269,4 +1269,67 @@ HWTEST_F(HdfWifiServiceCTest, StartScanTest_051, TestSize.Level1) OsalMemFree(scan.freqs); OsalMemFree(scan.ssids); } + +/** + * @tc.name: GetApBandwidthTest_052 + * @tc.desc: Wifi hdi get AP bandwidth function test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HdfWifiServiceCTest, GetApBandwidthTest_052, TestSize.Level1) +{ + uint8_t bandwidth = 0; + const char *ifName = "wlan0"; + + struct HdfFeatureInfo ifeature; + const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP; + + int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature); + if (rc == HDF_SUCCESS) { + rc = g_wlanObj->GetApBandwidth(g_wlanObj, nullptr, &bandwidth); + ASSERT_EQ(rc, HDF_ERR_INVALID_PARAM); + + rc = g_wlanObj->GetApBandwidth(g_wlanObj, ifName, &bandwidth); + bool flag = (rc == HDF_SUCCESS || rc == HDF_FAILURE); + ASSERT_TRUE(flag); + + printf("bandwidth: %u\n", bandwidth); + + rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature); + ASSERT_EQ(rc, HDF_SUCCESS); + } +} + +/** + * @tc.name: ResetToFactoryMacAddressTest_0053 + * @tc.desc: Wifi hdi reset to factory maca address function test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HdfWifiServiceCTest, ResetToFactoryMacAddressTest_0053, TestSize.Level1) +{ + const int32_t wlanType = PROTOCOL_80211_IFTYPE_AP; + struct HdfFeatureInfo ifeature; + + int32_t rc = g_wlanObj->CreateFeature(g_wlanObj, wlanType, &ifeature); + if (rc == HDF_SUCCESS) { + uint8_t mac[ETH_ADDR_LEN] = {0}; + uint32_t macLen = ETH_ADDR_LEN; + rc = g_wlanObj->GetDeviceMacAddress(g_wlanObj, &ifeature, mac, &macLen, ETH_ADDR_LEN); + ASSERT_EQ(rc, HDF_SUCCESS); + + uint8_t tmpMac[ETH_ADDR_LEN] = {0x12, 0x34, 0x56, 0x78, 0xab, 0xcd}; + rc = g_wlanObj->SetMacAddress(g_wlanObj, &ifeature, tmpMac, macLen); + bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_ERR_DEVICE_BUSY); + ASSERT_TRUE(flag); + + const char *ifName = "wlan0"; + rc = g_wlanObj->ResetToFactoryMacAddress(g_wlanObj, ifName); + ASSERT_EQ(rc, HDF_SUCCESS); + + rc = g_wlanObj->DestroyFeature(g_wlanObj, &ifeature); + ASSERT_EQ(rc, HDF_SUCCESS); + } +} + }; -- Gitee