diff --git a/wlan/client/include/wifi_driver_client.h b/wlan/client/include/wifi_driver_client.h index daeb5c1f40c81c939b9ae11fcb7c76316bd59efa..0e84a826347edbeff3c75060a0f4f40fbdb50cdb 100644 --- a/wlan/client/include/wifi_driver_client.h +++ b/wlan/client/include/wifi_driver_client.h @@ -44,6 +44,14 @@ extern "C" { #define WIFI_POWER_MODE_THROUGH_WALL 2 #define WIFI_POWER_MODE_NUM 3 +typedef enum { + CMD_CLOSE_GO_CAC, + CMD_SET_GO_CSA_CHANNEL, + CMD_SET_GO_RADAR_DETECT, + CMD_ID_MCC_STA_P2P_QUOTA_TIME, + CMD_ID_CTRL_ROAM_CHANNEL +} ProjectionScreenCmd; + /* common related interface */ enum WifiDriverClientResultCode { RET_CODE_SUCCESS = 0, @@ -224,6 +232,12 @@ struct MeasResult { int32_t noise; }; +typedef struct { + int32_t cmdId; + uint32_t bufLen; + int8_t buf[0]; +} ProjScrnCmdParam; + int32_t WifiDriverClientInit(void); void WifiDriverClientDeinit(void); @@ -231,15 +245,13 @@ int32_t GetUsableNetworkInfo(struct NetworkInfoResult *result); int32_t IsSupportCombo(uint8_t *isSupportCombo); int32_t GetComboInfo(uint64_t *comboInfo, uint32_t size); int32_t SetMacAddr(const char *ifName, unsigned char *mac, uint8_t len); -int32_t GetDevMacAddr(const char *ifName, - int32_t type, uint8_t *mac, uint8_t len); +int32_t GetDevMacAddr(const char *ifName, int32_t type, uint8_t *mac, uint8_t len); int32_t GetValidFreqByBand(const char *ifName, int32_t band, struct FreqInfoResult *result, uint32_t size); int32_t SetTxPower(const char *ifName, int32_t power); int32_t GetAssociatedStas(const char *ifName, struct AssocStaInfoResult *result); int32_t WifiSetCountryCode(const char *ifName, const char *code, uint32_t len); int32_t SetScanMacAddr(const char *ifName, uint8_t *scanMac, uint8_t len); - int32_t AcquireChipId(const char *ifName, uint8_t *chipId); int32_t GetIfNamesByChipId(const uint8_t chipId, char **ifNames, uint32_t *num); int32_t SetResetDriver(const uint8_t chipId, const char *ifName); @@ -248,6 +260,7 @@ int32_t GetCurrentPowerMode(const char *ifName, uint8_t *mode); int32_t SetPowerMode(const char *ifName, uint8_t mode); int32_t StartChannelMeas(const char *ifName, const struct MeasParam *measParam); int32_t GetChannelMeasResult(const char *ifName, struct MeasResult *measResult); +int32_t SetProjectionScreenParam(const char *ifName, const ProjScrnCmdParam *param); /* wpa related interface */ #define MAX_SSID_LEN 32 @@ -464,9 +477,9 @@ int32_t WifiCmdSetNetdev(const char *ifName, WifiSetNewDev *info); int32_t WifiCmdStaRemove(const char *ifName, const uint8_t *addr, uint32_t addrLen); int32_t WifiCmdSendAction(const char *ifName, WifiActionData *actionData); int32_t WifiCmdSetClient(uint32_t clientNum); -int32_t WifiCmdProbeReqReport(const char* ifName, const int32_t *report); -int32_t WifiCmdRemainOnChannel(const char* ifName, const WifiOnChannel *onChannel); -int32_t WifiCmdCancelRemainOnChannel(const char* ifName); +int32_t WifiCmdProbeReqReport(const char *ifName, const int32_t *report); +int32_t WifiCmdRemainOnChannel(const char *ifName, const WifiOnChannel *onChannel); +int32_t WifiCmdCancelRemainOnChannel(const char *ifName); int32_t WifiCmdAddIf(const char *ifname, const WifiIfAdd *ifAdd); int32_t WifiCmdRemoveIf(const char *ifname, const WifiIfRemove *ifRemove); int32_t WifiCmdSetApWpsP2pIe(const char *ifname, const WifiAppIe *appIe); diff --git a/wlan/client/src/netlink/netlink_cmd_adapter.c b/wlan/client/src/netlink/netlink_cmd_adapter.c index 94f12acc380cfe3c8509b15defdcef8dea4066b5..3731a911404148ffec5fa6c62899d88b9203de33 100644 --- a/wlan/client/src/netlink/netlink_cmd_adapter.c +++ b/wlan/client/src/netlink/netlink_cmd_adapter.c @@ -51,14 +51,27 @@ #define STR_WLAN1 "wlan1" #define STR_P2P0 "p2p0" #define STR_P2P0_X "p2p0-" +#define NET_DEVICE_INFO_PATH "/sys/class/net" -#define PRIMARY_ID_POWER_MODE 0x8bfd +#define PRIMARY_ID_POWER_MODE 0x8bfd #define SECONDARY_ID_POWER_MODE 0x101 #define SET_POWER_MODE_SLEEP "pow_mode sleep" #define SET_POWER_MODE_INIT "pow_mode init" #define SET_POWER_MODE_THIRD "pow_mode third" #define GET_POWER_MODE "get_pow_mode" +#define CMD_SET_CLOSE_GO_CAC "SET_CLOSE_GO_CAC" +#define CMD_SET_CHANGE_GO_CHANNEL "CMD_SET_CHANGE_GO_CHANNEL" +#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 P2P_BUF_SIZE 64 +#define MAX_PRIV_CMD_SIZE 4096 +#define 2_4G_LOW_LITMIT_FREQ 2400 +#define 2_4G_HIGH_LIMIT_FREQ 2500 +#define 5G_LOW_LIMIT_FREQ 5100 +#define 5G_HIGH_LIMIT_FREQ 5900 + // vendor attr enum AndrWifiAttr { ANDR_WIFI_ATTRIBUTE_NUM_FEATURE_SET, @@ -70,13 +83,13 @@ enum AndrWifiAttr { struct FamilyData { const char *group; - int id; + int32_t id; }; struct WifiHalInfo { struct nl_sock *cmdSock; struct nl_sock *eventSock; - int familyId; + int32_t familyId; // thread controller info pthread_t thread; @@ -101,6 +114,12 @@ typedef struct { union HwprivReqData data; } HwprivIoctlData; +typedef struct { + uint32_t size; + uint32_t len; + uint8_t *buf; +} WifiPrivCmd; + static struct WifiHalInfo g_wifiHalInfo = {0}; static struct nl_sock *OpenNetlinkSocket(void) @@ -157,7 +176,7 @@ static void DisconnectCmdSocket(void) static int32_t CmdSocketErrorHandler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) { - int *ret = (int *)arg; + int32_t *ret = (int32_t *)arg; *ret = err->error; return NL_SKIP; @@ -165,7 +184,7 @@ static int32_t CmdSocketErrorHandler(struct sockaddr_nl *nla, struct nlmsgerr *e static int32_t CmdSocketFinishHandler(struct nl_msg *msg, void *arg) { - int *ret = (int *)arg; + int32_t *ret = (int32_t *)arg; *ret = 0; return NL_SKIP; @@ -173,7 +192,7 @@ static int32_t CmdSocketFinishHandler(struct nl_msg *msg, void *arg) static int32_t CmdSocketAckHandler(struct nl_msg *msg, void *arg) { - int *err = (int *)arg; + int32_t *err = (int32_t *)arg; *err = 0; return NL_STOP; @@ -207,77 +226,94 @@ int32_t NetlinkSendCmdSync(struct nl_msg *msg, const RespHandler handler, void * return RET_CODE_FAILURE; } - rc = nl_send_auto(g_wifiHalInfo.cmdSock, msg); // seq num auto add - if (rc < 0) { - HILOG_ERROR(LOG_CORE, "%s: nl_send_auto failed", __FUNCTION__); - goto out; - } - - cb = nl_cb_alloc(NL_CB_DEFAULT); - if (cb == NULL) { - HILOG_ERROR(LOG_CORE, "%s: nl_cb_alloc failed", __FUNCTION__); - rc = RET_CODE_FAILURE; - goto out; - } - nl_cb_err(cb, NL_CB_CUSTOM, CmdSocketErrorHandler, &error); - nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, CmdSocketFinishHandler, &error); - nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, CmdSocketAckHandler, &error); - if (handler != NULL) { - nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, handler, data); - } - /* wait for reply */ - error = 1; - while (error > 0) { - rc = nl_recvmsgs(g_wifiHalInfo.cmdSock, cb); + do { + rc = nl_send_auto(g_wifiHalInfo.cmdSock, msg); if (rc < 0) { - HILOG_ERROR(LOG_CORE, "%s: nl_recvmsgs failed: rc = %d, errno = %d, (%s)", __FUNCTION__, rc, errno, - strerror(errno)); + HILOG_ERROR(LOG_CORE, "%s: nl_send_auto failed", __FUNCTION__); + break; } - } - nl_cb_put(cb); -out: + + cb = nl_cb_alloc(NL_CB_DEFAULT); + if (cb == NULL) { + HILOG_ERROR(LOG_CORE, "%s: nl_cb_alloc failed", __FUNCTION__); + rc = RET_CODE_FAILURE; + break; + } + nl_cb_err(cb, NL_CB_CUSTOM, CmdSocketErrorHandler, &error); + nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, CmdSocketFinishHandler, &error); + nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, CmdSocketAckHandler, &error); + if (handler != NULL) { + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, handler, data); + } + /* wait for reply */ + error = 1; + while (error > 0) { + rc = nl_recvmsgs(g_wifiHalInfo.cmdSock, cb); + if (rc < 0) { + HILOG_ERROR(LOG_CORE, "%s: nl_recvmsgs failed: rc = %d, errno = %d, (%s)", __FUNCTION__, rc, errno, + strerror(errno)); + } + } + nl_cb_put(cb); + } while (0); + pthread_mutex_unlock(&g_wifiHalInfo.mutex); return ((rc == 0) ? RET_CODE_SUCCESS : RET_CODE_FAILURE); } -static int FamilyIdHandler(struct nl_msg *msg, void *arg) +static void ParseFamilyId(struct nlattr *attr, struct FamilyData *familyData) +{ + struct nlattr *tmp = NULL; + void *data = NULL; + int32_t len; + int32_t i; + + nla_for_each_nested(tmp, attr, i) { + struct nlattr *attrMcastGrp[CTRL_ATTR_MCAST_GRP_MAX + 1]; + data = nla_data(tmp); + len = nla_len(tmp); + nla_parse(attrMcastGrp, CTRL_ATTR_MCAST_GRP_MAX, data, len, NULL); + data = nla_data(attrMcastGrp[CTRL_ATTR_MCAST_GRP_NAME]); + len = nla_len(attrMcastGrp[CTRL_ATTR_MCAST_GRP_NAME]); + if (attrMcastGrp[CTRL_ATTR_MCAST_GRP_NAME] && attrMcastGrp[CTRL_ATTR_MCAST_GRP_ID] && + strncmp((char *)data, familyData->group, len) == 0) { + familyData->id = nla_get_u32(attrMcastGrp[CTRL_ATTR_MCAST_GRP_ID]); + } + } +} + +static int32_t FamilyIdHandler(struct nl_msg *msg, void *arg) { struct FamilyData *familyData = (struct FamilyData *)arg; - struct genlmsghdr *hdr = nlmsg_data(nlmsg_hdr(msg)); + struct genlmsghdr *hdr = NULL; struct nlattr *attr[CTRL_ATTR_MAX + 1]; - struct nlattr *mcastGrp = NULL; - int i; + void *data = NULL; + int32_t len; + hdr = nlmsg_data(nlmsg_hdr(msg)); if (hdr == NULL) { HILOG_ERROR(LOG_CORE, "%s: get nlmsg header fail", __FUNCTION__); return NL_SKIP; } - nla_parse(attr, CTRL_ATTR_MAX, genlmsg_attrdata(hdr, 0), genlmsg_attrlen(hdr, 0), NULL); + data = genlmsg_attrdata(hdr, 0); + len = genlmsg_attrlen(hdr, 0) + nla_parse(attr, CTRL_ATTR_MAX, data, len, NULL); if (!attr[CTRL_ATTR_MCAST_GROUPS]) { return NL_SKIP; } - nla_for_each_nested(mcastGrp, attr[CTRL_ATTR_MCAST_GROUPS], i) { - struct nlattr *attrMcastGrp[CTRL_ATTR_MCAST_GRP_MAX + 1]; - nla_parse(attrMcastGrp, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcastGrp), nla_len(mcastGrp), NULL); - if (attrMcastGrp[CTRL_ATTR_MCAST_GRP_NAME] && attrMcastGrp[CTRL_ATTR_MCAST_GRP_ID] && - strncmp(nla_data(attrMcastGrp[CTRL_ATTR_MCAST_GRP_NAME]), familyData->group, - nla_len(attrMcastGrp[CTRL_ATTR_MCAST_GRP_NAME])) == 0) { - familyData->id = nla_get_u32(attrMcastGrp[CTRL_ATTR_MCAST_GRP_ID]); - break; - } - }; + ParseFamilyId(attr[CTRL_ATTR_MCAST_GROUPS], familyData); return NL_SKIP; } -static int GetMulticastId(const char *family, const char *group) +static int32_t GetMulticastId(const char *family, const char *group) { struct nl_msg *msg = NULL; - int ret; + int32_t ret; static struct FamilyData familyData; - int familyId = genl_ctrl_resolve(g_wifiHalInfo.cmdSock, "nlctrl"); + int32_t familyId = genl_ctrl_resolve(g_wifiHalInfo.cmdSock, "nlctrl"); familyData.group = group; familyData.id = -ENOENT; @@ -304,10 +340,10 @@ static int GetMulticastId(const char *family, const char *group) return ret; } -static int NlsockAddMembership(struct nl_sock *sock, const char *group) +static int32_t NlsockAddMembership(struct nl_sock *sock, const char *group) { - int id; - int ret; + int32_t id; + int32_t ret; id = GetMulticastId(NL80211_GENL_NAME, group); if (id < 0) { @@ -327,7 +363,7 @@ static int NlsockAddMembership(struct nl_sock *sock, const char *group) static int32_t ConnectEventSocket(void) { - int ret; + int32_t ret; g_wifiHalInfo.eventSock = OpenNetlinkSocket(); if (g_wifiHalInfo.eventSock == NULL) { @@ -343,19 +379,19 @@ static int32_t ConnectEventSocket(void) ret = NlsockAddMembership(g_wifiHalInfo.eventSock, NL80211_MULTICAST_GROUP_MLME); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: nlsock add membership for mlme failed.\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: nlsock add membership for mlme failed.", __FUNCTION__); goto err; } ret = NlsockAddMembership(g_wifiHalInfo.eventSock, NL80211_MULTICAST_GROUP_REG); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: nlsock add membership for regulatory failed.\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: nlsock add membership for regulatory failed.", __FUNCTION__); goto err; } ret = NlsockAddMembership(g_wifiHalInfo.eventSock, NL80211_MULTICAST_GROUP_VENDOR); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: nlsock add membership for vendor failed.\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: nlsock add membership for vendor failed.", __FUNCTION__); goto err; } @@ -432,12 +468,12 @@ int32_t WifiDriverClientInit(void) } if (ConnectEventSocket() != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: connect event socket failed\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: connect event socket failed", __FUNCTION__); goto err_event; } if (WifiMsgRegisterEventListener() != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: WifiMsgRegisterEventListener failed\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: WifiMsgRegisterEventListener failed", __FUNCTION__); goto err_reg; } @@ -574,58 +610,89 @@ struct PrivDevMac { uint8_t len; }; -static int32_t ParserValidFreq(struct nl_msg *msg, void *arg) +static nlattr *GetWiphyBands(struct genlmsghdr *hdr) { - struct FreqInfoResult *result = (struct FreqInfoResult *)arg; - struct genlmsghdr *hdr = nlmsg_data(nlmsg_hdr(msg)); struct nlattr *attrMsg[NL80211_ATTR_MAX + 1]; - struct nlattr *attrBand[NL80211_BAND_ATTR_MAX + 1]; + void *data = genlmsg_attrdata(hdr, 0); + int32_t len = genlmsg_attrlen(hdr, 0); + nla_parse(attrMsg, NL80211_ATTR_MAX, data, len, NULL); + if (!attrMsg[NL80211_ATTR_WIPHY_BANDS]) { + HILOG_ERROR(LOG_CORE, "%s: no wiphy bands", __FUNCTION__); + } + return attrMsg[NL80211_ATTR_WIPHY_BANDS]; +} + +static void GetCenterFreq(struct nlattr *bands, struct FreqInfoResult *result) +{ struct nlattr *attrFreq[NL80211_FREQUENCY_ATTR_MAX + 1]; - struct nlattr *nlBand = NULL, *nlFreq = NULL; - int i, j; + struct nlattr *nlFreq = NULL; + void *data = NULL; + int32_t len; + int32_t i; int32_t freq; static struct nla_policy freqPolicy[NL80211_FREQUENCY_ATTR_MAX + 1]; freqPolicy[NL80211_FREQUENCY_ATTR_FREQ].type = NLA_U32; freqPolicy[NL80211_FREQUENCY_ATTR_MAX_TX_POWER].type = NLA_U32; - nla_parse(attrMsg, NL80211_ATTR_MAX, genlmsg_attrdata(hdr, 0), genlmsg_attrlen(hdr, 0), NULL); - if (!attrMsg[NL80211_ATTR_WIPHY_BANDS]) { - HILOG_ERROR(LOG_CORE, "%s: no wiphy bands", __FUNCTION__); - return NL_SKIP; - } - // get each ieee80211_supported_band - nla_for_each_nested(nlBand, attrMsg[NL80211_ATTR_WIPHY_BANDS], i) + // get each ieee80211_channel + nla_for_each_nested(nlFreq, bands, i) { - nla_parse(attrBand, NL80211_BAND_ATTR_MAX, nla_data(nlBand), nla_len(nlBand), NULL); - if (attrBand[NL80211_BAND_ATTR_FREQS] == NULL) + data = nla_data(nlFreq); + len = nla_len(nlFreq); + nla_parse(attrFreq, NL80211_FREQUENCY_ATTR_MAX, data, len, freqPolicy); + // get center freq + if (attrFreq[NL80211_FREQUENCY_ATTR_FREQ] == NULL) { continue; - // get each ieee80211_channel - nla_for_each_nested(nlFreq, attrBand[NL80211_BAND_ATTR_FREQS], j) - { - nla_parse(attrFreq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nlFreq), nla_len(nlFreq), freqPolicy); - // get center freq - if (!attrFreq[NL80211_FREQUENCY_ATTR_FREQ] && attrFreq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) - continue; - freq = nla_get_u32(attrFreq[NL80211_FREQUENCY_ATTR_FREQ]); - switch (result->band) { - case NL80211_BAND_2GHZ: - if (freq > 2400 && freq < 2500) { + } + freq = nla_get_u32(attrFreq[NL80211_FREQUENCY_ATTR_FREQ]); + switch (result->band) { + case NL80211_BAND_2GHZ: + if (attrFreq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) { + if (freq > 2_4G_LOW_LITMIT_FREQ && freq < 2_4G_HIGH_LITMIT_FREQ) { result->freqs[result->nums] = freq; result->txPower[result->nums] = nla_get_u32(attrFreq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]); result->nums++; } - break; - case NL80211_BAND_5GHZ: - if (freq > 5100 && freq < 5900) { - result->freqs[result->nums] = freq; - result->nums++; - } - break; - default: - break; - } + } + break; + case NL80211_BAND_5GHZ: + if (freq > 5G_LOW_LIMIT_FREQ && freq < 5G_HIGH_LIMIT_FREQ) { + result->freqs[result->nums] = freq; + result->nums++; + } + break; + default: + break; } } +} + +static int32_t ParserValidFreq(struct nl_msg *msg, void *arg) +{ + struct FreqInfoResult *result = (struct FreqInfoResult *)arg; + struct genlmsghdr *hdr = nlmsg_data(nlmsg_hdr(msg)); + struct nalttr *attrWiphyBands = NULL; + struct nlattr *attrBand[NL80211_BAND_ATTR_MAX + 1]; + struct nlattr *nlBand = NULL; + int32_t i, j; + void *data = NULL; + int32_t len; + + attrWiphyBands = GetWiphyBands(hdr); + if (GetWiphyBands == NULL) { + return NL_SKIP; + } + + // get each ieee80211_supported_band + nla_for_each_nested(nlBand, attrWiphyBands, i) + { + data = nla_data(nlBand); + len = nla_len(nlBand); + nla_parse(attrBand, NL80211_BAND_ATTR_MAX, data, len, NULL); + if (attrBand[NL80211_BAND_ATTR_FREQS] == NULL) + continue; + GetCenterFreq(attrBand[NL80211_BAND_ATTR_FREQS], result); + } return NL_SKIP; } @@ -642,9 +709,8 @@ static bool IsWifiIface(const char *name) static int32_t GetAllIfaceInfo(struct NetworkInfoResult *infoResult) { struct dirent *de; - - DIR *d = opendir("/sys/class/net"); - if (d == 0) { + DIR *dir = opendir(NET_DEVICE_INFO_PATH); + if (dir == NULL) { return RET_CODE_FAILURE; } infoResult->nums = 0; @@ -655,14 +721,16 @@ static int32_t GetAllIfaceInfo(struct NetworkInfoResult *infoResult) if (IsWifiIface(de->d_name)) { if (strncpy_s(infoResult->infos[infoResult->nums].name, IFNAMSIZ, de->d_name, sizeof(de->d_name)) != EOK) { HILOG_ERROR(LOG_CORE, "%s: strncpy_s infoResult->infos failed", __FUNCTION__); + closedir(dir); return RET_CODE_FAILURE; } infoResult->nums++; } } - closedir(d); - if (infoResult->nums == 0) + closedir(dir); + if (infoResult->nums == 0) { return RET_CODE_NOT_AVAILABLE; + } return RET_CODE_SUCCESS; } @@ -800,7 +868,7 @@ int32_t SetMacAddr(const char *ifName, unsigned char *mac, uint8_t len) } ret = ioctl(fd, SIOCSIFHWADDR, &req); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)\n", __FUNCTION__, errno, strerror(errno)); + HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)", __FUNCTION__, errno, strerror(errno)); if (errno == EPERM) { ret = RET_CODE_NOT_SUPPORT; } else if (errno == EBUSY) { @@ -838,7 +906,7 @@ static int32_t ParserChipId(struct nl_msg *msg, void *arg) int32_t GetDevMacAddr(const char *ifName, int32_t type, uint8_t *mac, uint8_t len) { (void)type; - int fd, ret; + int32_t fd, ret; struct ifreq req; fd = socket(AF_INET, SOCK_DGRAM, 0); @@ -850,7 +918,7 @@ int32_t GetDevMacAddr(const char *ifName, int32_t type, uint8_t *mac, uint8_t le strncpy_s(req.ifr_name, IFNAMSIZ, ifName, strlen(ifName)); ret = ioctl(fd, SIOCGIFHWADDR, &req); if (ret != 0) { - HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)\n", __FUNCTION__, errno, strerror(errno)); + HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)", __FUNCTION__, errno, strerror(errno)); close(fd); return RET_CODE_FAILURE; } @@ -1058,7 +1126,7 @@ int32_t AcquireChipId(const char *ifName, uint8_t *chipId) ret = NetlinkSendCmdSync(msg, ParserChipId, chipId); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: NetlinkSendCmdSync failed.\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: NetlinkSendCmdSync failed.", __FUNCTION__); } nlmsg_free(msg); @@ -1098,21 +1166,29 @@ int32_t SetResetDriver(const uint8_t chipId, const char *ifName) return RET_CODE_SUCCESS; } -static int NetDeviceInfoHandler(struct nl_msg *msg, void *arg) +static int32_t NetDeviceInfoHandler(struct nl_msg *msg, struct NetDeviceInfo *info) { struct nlattr *attr[NL80211_ATTR_MAX + 1]; - struct genlmsghdr *hdr = nlmsg_data(nlmsg_hdr(msg)); - struct NetDeviceInfo *info = (struct NetDeviceInfo *)arg; - - nla_parse(attr, NL80211_ATTR_MAX, genlmsg_attrdata(hdr, 0), genlmsg_attrlen(hdr, 0), NULL); + struct genlmsghdr *hdr = NULL; + void *data = NULL; + int32_t len; + hdr = nlmsg_data(nlmsg_hdr(msg)); + if (hdr == NULL) { + HILOG_ERROR(LOG_CORE, "%s: get nlmsg header fail", __FUNCTION__); + return NL_SKIP; + } + data = genlmsg_attrdata(hdr, 0); + len = genlmsg_attrlen(hdr, 0); + nla_parse(attr, NL80211_ATTR_MAX, data, len, NULL); if (attr[NL80211_ATTR_IFTYPE]) { info->iftype = nla_get_u32(attr[NL80211_ATTR_IFTYPE]); - HILOG_ERROR(LOG_CORE, "%s: %s iftype is %hhu\n", __FUNCTION__, info->ifName, info->iftype); + HILOG_ERROR(LOG_CORE, "%s: %s iftype is %hhu", __FUNCTION__, info->ifName, info->iftype); } - if (attr[NL80211_ATTR_MAC]) { - memcpy_s(info->mac, ETH_ADDR_LEN, nla_data(attr[NL80211_ATTR_MAC]), ETH_ADDR_LEN); + if (memcpy_s(info->mac, ETH_ADDR_LEN, nla_data(attr[NL80211_ATTR_MAC]), ETH_ADDR_LEN) != EOK) { + HILOG_ERROR(LOG_CORE, "%s: memcpy_s mac address fail", __FUNCTION__); + } } return NL_SKIP; @@ -1121,10 +1197,10 @@ static int NetDeviceInfoHandler(struct nl_msg *msg, void *arg) static uint32_t GetIftypeAndMac(struct NetDeviceInfo *info) { struct nl_msg *msg = nlmsg_alloc(); - int ret; + int32_t ret; if (msg == NULL) { - HILOG_ERROR(LOG_CORE, "%s: nlmsg_alloc failed.\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: nlmsg_alloc failed.", __FUNCTION__); return RET_CODE_FAILURE; } @@ -1133,7 +1209,7 @@ static uint32_t GetIftypeAndMac(struct NetDeviceInfo *info) ret = NetlinkSendCmdSync(msg, NetDeviceInfoHandler, info); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: NetlinkSendCmdSync failed.\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: NetlinkSendCmdSync failed.", __FUNCTION__); nlmsg_free(msg); return RET_CODE_FAILURE; } @@ -1168,10 +1244,10 @@ int32_t GetNetDeviceInfo(struct NetDeviceInfoResult *netDeviceInfoResult) return RET_CODE_SUCCESS; } -static int CmdScanPutMsg(struct nl_msg *msg, const WifiScan *scan) +static int32_t CmdScanPutMsg(struct nl_msg *msg, const WifiScan *scan) { struct nlattr *nest = NULL; - int i; + int32_t i; if (scan->ssids) { nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); @@ -1230,13 +1306,13 @@ int32_t WifiCmdScan(const char *ifName, WifiScan *scan) ret = CmdScanPutMsg(msg, scan); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: put msg failed\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: put msg failed", __FUNCTION__); goto err; } ret = NetlinkSendCmdSync(msg, NULL, NULL); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: send cmd failed\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: send cmd failed", __FUNCTION__); goto err; } @@ -1304,7 +1380,7 @@ int32_t GetCurrentPowerMode(const char *ifName, uint8_t *mode) } ret = ioctl(fd, PRIMARY_ID_POWER_MODE, &ioctlData); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)\n", __FUNCTION__, errno, strerror(errno)); + HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)", __FUNCTION__, errno, strerror(errno)); if (errno == EOPNOTSUPP) { ret = RET_CODE_NOT_SUPPORT; } else { @@ -1314,7 +1390,7 @@ int32_t GetCurrentPowerMode(const char *ifName, uint8_t *mode) } ret = ParsePowerMode(ioctlData.data.point.buf, ioctlData.data.point.length, mode); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: ParsePowerMode failed\n", __FUNCTION__); + HILOG_ERROR(LOG_CORE, "%s: ParsePowerMode failed", __FUNCTION__); break; } } while (0); @@ -1371,7 +1447,7 @@ int32_t SetPowerMode(const char *ifName, uint8_t mode) } ret = ioctl(fd, PRIMARY_ID_POWER_MODE, &ioctlData); if (ret != RET_CODE_SUCCESS) { - HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)\n", __FUNCTION__, errno, strerror(errno)); + HILOG_ERROR(LOG_CORE, "%s: ioctl failed, errno = %d, (%s)", __FUNCTION__, errno, strerror(errno)); if (errno == EOPNOTSUPP) { ret = RET_CODE_NOT_SUPPORT; } else { @@ -1401,3 +1477,172 @@ int32_t GetChannelMeasResult(const char *ifName, struct MeasResult *measResult) (void)measResult; return RET_CODE_NOT_SUPPORT; } + +static int32_t SendCommandToDriver(const char *cmd, uint32_t len, const char *ifName) +{ + struct ifreq ifr = {0}; + WifiPrivCmd privCmd = {0}; + char 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__); + return RET_CODE_INVALID_PARAM; + } + if (len > MAX_PRIV_CMD_SIZE) { + HILOG_ERROR(LOG_CORE, "%{public}s: Size of command is too large", __FUNCTION__); + return RET_CODE_INVALID_PARAM; + } + if (memcpy_s(buf, MAX_PRIV_CMD_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 = &privCmd; + if (strcpy_s(ifr.ifr_name, IFNAMSIZ, ifName) != EOK) { + HILOG_ERROR(LOG_CORE, "%s: strcpy_s error", __FUNCTION__); + return RET_CODE_FAILURE; + } + int32_t sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + HILOG_ERROR(LOG_CORE, "%{public}s: socket failed, errno = %{public}d, (%{public}s)", __FUNCTION__, errno, + strerror(errno)); + return ret; + } + do { + ret = ioctl(sock, SIOCDEVPRIVATE + 1, &ifr); + if (ret < 0) { + HILOG_ERROR(LOG_CORE, "%{public}s: ioctl failed, errno = %{public}d, (%{public}s)", __FUNCTION__, errno, + strerror(errno)); + 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); + return ret; +} + +static int32_t DisableNextCacOnce(const char *ifName) +{ + char cmdBuf[P2P_BUF_SIZE] = {CMD_SET_CLOSE_GO_CAC}; + + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); +} + +static int32_t SetGoChannel(const char *ifName, const int8_t *data, uint32_t len) +{ + int32_t ret = RET_CODE_FAILURE; + char cmdBuf[P2P_BUF_SIZE] = {0}; + uint32_t cmdLen; + + cmdLen = strlen(CMD_SET_CHANGE_GO_CHANNEL); + if ((cmdLen + len) >= P2P_BUF_SIZE) { + HILOG_ERROR(LOG_CORE, "%{public}s: the length of input data is too large", __FUNCTION__); + return ret; + } + ret = snprintf_s(cmdBuf, P2P_BUF_SIZE, P2P_BUF_SIZE - 1, "%s %d", CMD_SET_CHANGE_GO_CHANNEL, *data); + if (ret < RET_CODE_SUCCESS) { + HILOG_ERROR(LOG_CORE, "%{public}s: ifName: %{public}s, ret = %{public}d", __FUNCTION__, ifName, ret); + return RET_CODE_FAILURE; + } + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); +} + +static int32_t SetGoDetectRadar(const char *ifName, const int8_t *data, uint32_t len) +{ + int32_t ret = RET_CODE_FAILURE; + char cmdBuf[P2P_BUF_SIZE] = {0}; + uint32_t cmdLen; + + cmdLen = strlen(CMD_SET_GO_DETECT_RADAR); + if ((cmdLen + len) >= P2P_BUF_SIZE) { + HILOG_ERROR(LOG_CORE, "%{public}s: the length of input data is too large", __FUNCTION__); + return ret; + } + ret = snprintf_s(cmdBuf, P2P_BUF_SIZE, P2P_BUF_SIZE - 1, "%s %d", CMD_SET_GO_DETECT_RADAR, *data); + if (ret < RET_CODE_SUCCESS) { + HILOG_ERROR(LOG_CORE, "%{public}s: ifName: %{public}s, ret = %{public}d", __FUNCTION__, ifName, ret); + return RET_CODE_FAILURE; + } + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); +} + +static int32_t SetP2pScenes(const char *ifName, const int8_t *data, uint32_t len) +{ + int32_t ret = RET_CODE_FAILURE; + char cmdBuf[P2P_BUF_SIZE] = {0}; + uint32_t cmdLen; + + cmdLen = strlen(CMD_SET_P2P_SCENES); + if ((cmdLen + len) >= P2P_BUF_SIZE) { + HILOG_ERROR(LOG_CORE, "%{public}s: the length of input data is too large", __FUNCTION__); + return ret; + } + ret = snprintf_s(cmdBuf, P2P_BUF_SIZE, P2P_BUF_SIZE - 1, "%s %d", CMD_SET_P2P_SCENES, *data); + if (ret < RET_CODE_SUCCESS) { + HILOG_ERROR(LOG_CORE, "%{public}s: ifName: %{public}s, ret = %{public}d", __FUNCTION__, ifName, ret); + return RET_CODE_FAILURE; + } + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); +} + +static int32_t SetDynamicDbacMode(const char *ifName, int8_t *data, uint32_t len) +{ + int32_t ret = RET_CODE_FAILURE; + char cmdBuf[P2P_BUF_SIZE] = {0}; + uint32_t cmdLen; + + cmdLen = strlen(CMD_SET_DYNAMIC_DBAC_MODE); + if ((cmdLen + len) >= P2P_BUF_SIZE) { + HILOG_ERROR(LOG_CORE, "%{public}s: the length of input data is too large", __FUNCTION__); + return ret; + } + ret = snprintf_s(cmdBuf, P2P_BUF_SIZE, P2P_BUF_SIZE - 1, "%s %d", CMD_SET_DYNAMIC_DBAC_MODE, *data); + if (ret < RET_CODE_SUCCESS) { + HILOG_ERROR(LOG_CORE, "%{public}s: ifName: %{public}s, ret = %{public}d", __FUNCTION__, ifName, ret); + return RET_CODE_FAILURE; + } + return SendCommandToDriver(cmdBuf, P2P_BUF_SIZE, ifName); +} + +int32_t SetProjectionScreenParam(const char *ifName, const ProjScrnCmdParam *param) +{ + int32_t ret; + + if (strcmp(ifName, STR_WLAN0) != EOK) { + HILOG_ERROR(LOG_CORE, "%{public}s: %{public}s is not supported", __FUNCTION__, ifName); + return RET_CODE_NOT_SUPPORT; + } + switch (param->cmdId) { + case CMD_CLOSE_GO_CAC: + ret = DisableNextCacOnce(ifName); + break; + case CMD_SET_GO_CSA_CHANNEL: + ret = SetGoChannel(ifName, param->buf, param->bufLen); + break; + case CMD_SET_GO_RADAR_DETECT: + ret = SetGoDetectRadar(ifName, param->buf, param->bufLen); + break; + case CMD_ID_MCC_STA_P2P_QUOTA_TIME: + ret = SetDynamicDbacMode(ifName, param->buf, param->bufLen); + break; + case CMD_ID_CTRL_ROAM_CHANNEL: + ret = SetP2pScenes(ifName, param->buf, param->bufLen); + break; + default: + HILOG_ERROR(LOG_CORE, "%{public}s: Invalid command id", __FUNCTION__); + return RET_CODE_NOT_SUPPORT; + } + if (ret != RET_CODE_SUCCESS) { + HILOG_ERROR(LOG_CORE, "%{public}s: Config projection screen fail, ret = %{public}d", __FUNCTION__, ret); + } + return ret; +} \ No newline at end of file diff --git a/wlan/client/src/sbuf/sbuf_cmd_adapter.c b/wlan/client/src/sbuf/sbuf_cmd_adapter.c index 99911494059a08f2bd369338faeb9c6ac060a965..59a3302e74593cbc0889749f635f3ac5a2d70898 100644 --- a/wlan/client/src/sbuf/sbuf_cmd_adapter.c +++ b/wlan/client/src/sbuf/sbuf_cmd_adapter.c @@ -873,6 +873,39 @@ int32_t StartChannelMeas(const char *ifName, const struct MeasParam *measParam) return ret; } +int32_t SetProjectionScreenParam(const char *ifName, const ProjScrnCmdParam *param) +{ + int32_t ret = RET_CODE_FAILURE; + struct HdfSBuf *req = NULL; + + req = HdfSbufObtainDefaultSize(); + if (req == NULL) { + HDF_LOGE("%{public}s: HdfSbufObtainDefaultSize fail!", __FUNCTION__); + return ret; + } + + do { + if (!HdfSbufWriteString(req, ifName)) { + HDF_LOGE("%{public}s: write ifName fail!", __FUNCTION__); + break; + } + if (!HdfSbufWriteInt32(req, param->cmdId)) { + HDF_LOGE("%{public}s: write cmd fail!", __FUNCTION__); + break; + } + if (!HdfSbufWriteBuffer(req, param->buf, param->bufLen)) { + HDF_LOGE("%{public}s: write buffer data fail!", __FUNCTION__); + break; + } + ret = SendCmdSync(WIFI_HAL_CMD_CONFIG_PROJECTION_SCREEN, req, NULL); + if (ret != RET_CODE_SUCCESS) { + HDF_LOGE("%{public}s: SendCmdSync fail, ret = %{public}d!", __FUNCTION__, ret); + } + } while (0); + + HdfSbufRecycle(req); + return ret; +} #ifdef __cplusplus #if __cplusplus } diff --git a/wlan/client/src/wifi_common_cmd.h b/wlan/client/src/wifi_common_cmd.h index 2c9142cbf53b1372e7c7d80f564d47e81ec75adc..ac1d920ac93d6d014f079cf8d9958af06f4d45fa 100644 --- a/wlan/client/src/wifi_common_cmd.h +++ b/wlan/client/src/wifi_common_cmd.h @@ -56,7 +56,8 @@ enum BaseCommands { CMD_BASE_DO_RESET_PRIVATE, CMD_BASE_GET_POWER_MODE, CMD_BASE_SET_POWER_MODE, - CMD_BASE_START_CHANNEL_MEAS + CMD_BASE_START_CHANNEL_MEAS, + CMD_BASE_SET_PROJECTION_SCREEN_PARAM }; enum APCommands { @@ -107,6 +108,7 @@ typedef enum { WIFI_HAL_CMD_GET_POWER_MODE = HDF_WIFI_CMD(BASE_SERVICE_ID, CMD_BASE_GET_POWER_MODE), WIFI_HAL_CMD_SET_POWER_MODE = HDF_WIFI_CMD(BASE_SERVICE_ID, CMD_BASE_SET_POWER_MODE), WIFI_HAL_CMD_START_CHANNEL_MEAS = HDF_WIFI_CMD(BASE_SERVICE_ID, CMD_BASE_START_CHANNEL_MEAS), + WIFI_HAL_CMD_CONFIG_PROJECTION_SCREEN = HDF_WIFI_CMD(BASE_SERVICE_ID, CMD_BASE_SET_PROJECTION_SCREEN_PARAM), } WifiHalCmd; typedef enum { diff --git a/wlan/client/src/wifi_driver_client.c b/wlan/client/src/wifi_driver_client.c index 3e755a75ab8d48409b62b1a219e84abdd9f7d229..08a7c1a590255ed21911952ad1406876763c6408 100644 --- a/wlan/client/src/wifi_driver_client.c +++ b/wlan/client/src/wifi_driver_client.c @@ -15,6 +15,7 @@ #include #include +#include #include "wifi_common_cmd.h" #include "hdf_log.h" #include "securec.h" diff --git a/wlan/hal/src/wifi_hal.c b/wlan/hal/src/wifi_hal.c index d3f9266bcbfdeef806cb64479b05c99a91e806a6..72eb4bc9176ee643814220d6b44dcacdb1e41a1e 100644 --- a/wlan/hal/src/wifi_hal.c +++ b/wlan/hal/src/wifi_hal.c @@ -282,7 +282,7 @@ static int32_t StartChannelMeasInner(const char *ifName, const struct MeasParam return StartChannelMeas(ifName, measParam); } -static int32_t GetChannelMeasResultInner(const char *ifName, struct MeasResult* measResult) +static int32_t GetChannelMeasResultInner(const char *ifName, struct MeasResult *measResult) { if (ifName == NULL || measResult == NULL) { HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); @@ -291,6 +291,15 @@ static int32_t GetChannelMeasResultInner(const char *ifName, struct MeasResult* return HDF_ERR_NOT_SUPPORT; } +static int32_t SetProjectionScreenParamInner(const char *ifName, const ProjScrnCmdParam *param) +{ + if (ifName == NULL || param == NULL) { + HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); + return HDF_ERR_INVALID_PARAM; + } + return SetProjectionScreenParam(ifName, param); +} + static int32_t Start(struct IWiFi *iwifi) { HalMutexLock(); @@ -403,7 +412,7 @@ static int32_t WifiStartChannelMeas(const char *ifName, const struct MeasParam * return ret; } -static int32_t WifiGetChannelMeasResult(const char *ifName, struct MeasResult* measResult) +static int32_t WifiGetChannelMeasResult(const char *ifName, struct MeasResult *measResult) { HalMutexLock(); int32_t ret = GetChannelMeasResultInner(ifName, measResult); @@ -411,6 +420,14 @@ static int32_t WifiGetChannelMeasResult(const char *ifName, struct MeasResult* m return ret; } +static int32_t WifiSetProjectionScreenParam(const char *ifName, const ProjScrnCmdParam *param) +{ + HalMutexLock(); + int32_t ret = SetProjectionScreenParamInner(ifName, param); + HalMutexUnlock(); + return ret; +} + int32_t WifiConstruct(struct IWiFi **wifiInstance) { static bool isInited = false; @@ -437,6 +454,7 @@ int32_t WifiConstruct(struct IWiFi **wifiInstance) singleWifiInstance.setPowerMode = WifiSetPowerMode; singleWifiInstance.startChannelMeas = WifiStartChannelMeas; singleWifiInstance.getChannelMeasResult = WifiGetChannelMeasResult; + singleWifiInstance.setProjectionScreenParam = WifiSetProjectionScreenParam; InitIWiFiList(); isInited = true; } diff --git a/wlan/hdi_service/service_common/wlan_common_cmd.c b/wlan/hdi_service/service_common/wlan_common_cmd.c index 9e1b643d6d526abf184d7f27f10d960d465b7922..3ba6eed5ffaa1a904293ea55877c542a55ec0963 100644 --- a/wlan/hdi_service/service_common/wlan_common_cmd.c +++ b/wlan/hdi_service/service_common/wlan_common_cmd.c @@ -18,6 +18,7 @@ #include #include #include +#include "wlan_extend_cmd.h" #include "v1_0/iwlan_callback.h" #include "v1_0/iwlan_interface.h" #include "v1_0/wlan_interface_service.h" @@ -181,7 +182,7 @@ int32_t WlanInterfaceGetAsscociatedStas(struct IWlanInterface *self, const struc OsalMemFree(wifiStaInfo); return ret; } - for (int i = 0; i < *staInfoLen; i++) { + for (uint32_t i = 0; i < *staInfoLen; i++) { staInfo[i].mac = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * ETH_ADDR_LEN); if (staInfo[i].mac != NULL) { if (memcpy_s(staInfo[i].mac, WIFI_MAC_ADDR_LENGTH, wifiStaInfo[i].mac, WIFI_MAC_ADDR_LENGTH) != EOK) { @@ -576,6 +577,23 @@ static int32_t HdfWLanCallbackFun(uint32_t event, void *data, const char *ifName return ret; } +static void HdfWlanDelRemoteObj(struct IWlanCallback *self) +{ + struct HdfWlanRemoteNode *pos = NULL; + struct HdfWlanRemoteNode *tmp = NULL; + struct DListHead *head = &HdfStubDriver()->remoteListHead; + + DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, struct HdfWlanRemoteNode, node) { + if (pos->service->index == self->AsObject(self)->index) { + DListRemove(&(pos->node)); + WlanCallbackRelease(pos->callbackObj); + OsalMemFree(pos); + break; + } + } + WlanCallbackRelease(self); +} + int32_t WlanInterfaceRegisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc, const char *ifName) { @@ -586,6 +604,10 @@ int32_t WlanInterfaceRegisterEventCallback(struct IWlanInterface *self, struct I HDF_LOGE("%{public}s: input parameter invalid!", __func__); return HDF_ERR_INVALID_PARAM; } + if (g_wifi == NULL) { + HDF_LOGE("%{public}s g_wifi is NULL!", __func__); + return HDF_FAILURE; + } (void)OsalMutexLock(&HdfStubDriver()->mutex); ret = HdfWlanAddRemoteObj(cbFunc); if (ret != HDF_SUCCESS) { @@ -593,37 +615,16 @@ int32_t WlanInterfaceRegisterEventCallback(struct IWlanInterface *self, struct I HDF_LOGE("%{public}s: HdfSensorAddRemoteObj false", __func__); return ret; } - if (g_wifi == NULL) { - HDF_LOGE("%{public}s g_wifi is NULL!", __func__); - (void)OsalMutexUnlock(&HdfStubDriver()->mutex); - return HDF_FAILURE; - } ret = g_wifi->registerEventCallback(HdfWLanCallbackFun, ifName); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret); + HdfWlanDelRemoteObj(cbFunc); } + (void)OsalMutexUnlock(&HdfStubDriver()->mutex); return ret; } -static void HdfWlanDelRemoteObj(struct IWlanCallback *self) -{ - struct HdfWlanRemoteNode *pos = NULL; - struct HdfWlanRemoteNode *tmp = NULL; - struct DListHead *head = &HdfStubDriver()->remoteListHead; - - (void)self; - DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, struct HdfWlanRemoteNode, node) { - if (pos->service->index == self->AsObject(self)->index) { - DListRemove(&(pos->node)); - WlanCallbackRelease(pos->callbackObj); - OsalMemFree(pos); - break; - } - } - WlanCallbackRelease(self); -} - int32_t WlanInterfaceUnregisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc, const char *ifName) { @@ -634,18 +635,17 @@ int32_t WlanInterfaceUnregisterEventCallback(struct IWlanInterface *self, struct HDF_LOGE("%{public}s: input parameter invalid!", __func__); return HDF_ERR_INVALID_PARAM; } - (void)OsalMutexLock(&HdfStubDriver()->mutex); - HdfWlanDelRemoteObj(cbFunc); if (g_wifi == NULL) { HDF_LOGE("%{public}s g_wifi is NULL!", __func__); - (void)OsalMutexUnlock(&HdfStubDriver()->mutex); return HDF_FAILURE; } + (void)OsalMutexLock(&HdfStubDriver()->mutex); + HdfWlanDelRemoteObj(cbFunc); if (DListIsEmpty(&HdfStubDriver()->remoteListHead)) { ret = g_wifi->unregisterEventCallback(HdfWLanCallbackFun, ifName); if (ret != HDF_SUCCESS) { - (void)OsalMutexUnlock(&HdfStubDriver()->mutex); HDF_LOGE("%{public}s: Unregister failed!, error code: %{public}d", __func__, ret); + (void)OsalMutexUnlock(&HdfStubDriver()->mutex); return ret; } } @@ -820,7 +820,7 @@ int32_t WlanInterfaceGetNetDevInfo(struct IWlanInterface *self, struct HdfNetDev return HDF_FAILURE; } netDeviceInfoResult->deviceInfosLen = MAX_NETDEVICE_COUNT; - for (int i = 0; i < netDeviceInfoResult->deviceInfosLen; i++) { + for (uint32_t i = 0; i < netDeviceInfoResult->deviceInfosLen; i++) { netDeviceInfoResult->deviceInfos[i].index = netDeviceInfo->deviceInfos[i].index; netDeviceInfoResult->deviceInfos[i].iftype = netDeviceInfo->deviceInfos[i].iftype; netDeviceInfoResult->deviceInfos[i].ifName = (char *)OsalMemCalloc(sizeof(char) * IFNAMSIZ); @@ -1001,6 +1001,45 @@ int32_t WlanInterfaceSetPowerMode(struct IWlanInterface *self, const struct HdfF return ret; } +int32_t WlanInterfaceSetProjectionScreenParam(struct IWlanInterface *self, const char *ifName, + const struct ProjectionScreenCmdParam *param) +{ + int32_t ret; + ProjScrnCmdParam *projScrnCmdParam = NULL; + + (void)self; + if (ifName == NULL || param == NULL) { + HDF_LOGE("%{public}s input parameter invalid!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (g_wifi == NULL) { + HDF_LOGE("%{public}s g_wifi is NULL!", __func__); + return HDF_FAILURE; + } + + projScrnCmdParam = OsalMemCalloc(sizeof(ProjScrnCmdParam) + param->bufLen); + if (projScrnCmdParam == NULL) { + HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__); + return HDF_FAILURE; + } + projScrnCmdParam->cmdId = param->cmdId; + projScrnCmdParam->bufLen = param->bufLen; + do { + if (memcpy_s(projScrnCmdParam->buf, projScrnCmdParam->bufLen, param->buf, param->bufLen) != EOK) { + HDF_LOGE("%{public}s: memcpy_s failed", __func__); + ret = HDF_FAILURE; + break; + } + ret = g_wifi->setProjectionScreenParam(ifName, projScrnCmdParam); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%{public}s: get channel meas result failed!, error code: %{public}d", __func__, ret); + } + } while (0); + + OsalMemFree(projScrnCmdParam); + 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 5c56d6ceabc2959ace809f21fda1194a6fee0b41..ee1757e4c670af002832718366d3b7316a469574 100644 --- a/wlan/hdi_service/service_common/wlan_common_cmd.h +++ b/wlan/hdi_service/service_common/wlan_common_cmd.h @@ -55,6 +55,8 @@ int32_t WlanInterfaceStartScan(struct IWlanInterface *self, const struct HdfFeat const struct HdfWifiScan *scan); int32_t WlanInterfaceGetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t *mode); int32_t WlanInterfaceSetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t mode); +int32_t WlanInterfaceSetProjectionScreenParam(struct IWlanInterface *self, const char *ifName, + const struct ProjectionScreenCmdParam *param); int32_t WlanInterfaceWifiConstruct(void); int32_t WlanInterfaceWifiDestruct(void); #endif diff --git a/wlan/hdi_service/service_extend/BUILD.gn b/wlan/hdi_service/service_extend/BUILD.gn index 48767d413c8b9421d0460965f0dec3f215ee4842..78592538568ab5f3f2becc0312afaa6b1d4a725c 100644 --- a/wlan/hdi_service/service_extend/BUILD.gn +++ b/wlan/hdi_service/service_extend/BUILD.gn @@ -23,8 +23,11 @@ ohos_shared_library("libwlan_service_extend") { "//drivers/peripheral/wlan/hdi_service/service_extend", ] sources = [ "wlan_extend_cmd.c" ] - configs = [ "//drivers/interface/wlan/v1_0:wlan_idl_headers" ] - deps = [ "//drivers/peripheral/wlan/hal:wifi_hal" ] + + deps = [ + "//drivers/interface/wlan/v1_0:wlan_idl_headers", + "//drivers/peripheral/wlan/hal:wifi_hal", + ] defines = [ "__OHOS__USER__" ] diff --git a/wlan/hdi_service/service_extend/wlan_extend_cmd.c b/wlan/hdi_service/service_extend/wlan_extend_cmd.c index 4f547c40c7ea02c2c78933c65f426741f62ab82b..534eb26575261ef8795abbeed8b9e77a400460d1 100644 --- a/wlan/hdi_service/service_extend/wlan_extend_cmd.c +++ b/wlan/hdi_service/service_extend/wlan_extend_cmd.c @@ -70,7 +70,7 @@ int32_t WlanExtendInterfaceWifiConstruct(void) int32_t ret; ret = WifiConstruct(&g_wifi); if (ret != HDF_SUCCESS) { - HDF_LOGE("%{public}s conxtruct WiFi failed! error code: %{public}d", __func__, ret); + HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret); } return ret; } diff --git a/wlan/hdi_service/wlan_interface_drivers.c b/wlan/hdi_service/wlan_interface_drivers.c index 634927e7390f47fab23d249f770405abfd66ea29..7fb0cbc2e7367ad19c210c9ba1816ffabbac8990 100644 --- a/wlan/hdi_service/wlan_interface_drivers.c +++ b/wlan/hdi_service/wlan_interface_drivers.c @@ -60,6 +60,7 @@ int HdfWlanInterfaceDriverInit(struct HdfDeviceObject *deviceObject) } if (WlanInterfaceServiceInit() != HDF_SUCCESS) { HDF_LOGE("%{public}s: wlan interface service init failed!", __func__); + OsalMutexDestroy(&stubData->mutex); return HDF_FAILURE; } return HDF_SUCCESS; diff --git a/wlan/hdi_service/wlan_interface_service.c b/wlan/hdi_service/wlan_interface_service.c index 498c59bfb277b02831fbf110502198b3eeca9f05..d5b7c3f9901173f54b17831ca0da1bf3058f650b 100644 --- a/wlan/hdi_service/wlan_interface_service.c +++ b/wlan/hdi_service/wlan_interface_service.c @@ -66,6 +66,7 @@ struct WlanInterfaceService *WlanInterfaceServiceGet(void) service->stub.interface.SetPowerMode = WlanInterfaceSetPowerMode; service->stub.interface.StartChannelMeas = WlanInterfaceStartChannelMeas; service->stub.interface.GetChannelMeasResult = WlanInterfaceGetChannelMeasResult; + service->stub.interface.SetProjectionScreenParam = WlanInterfaceSetProjectionScreenParam; return service; } diff --git a/wlan/interfaces/include/wifi_hal.h b/wlan/interfaces/include/wifi_hal.h index f8e88a8db84e9f49b1b34d5e84596313d75d8418..c85e27b31263f0009d42a9f88d58cea9504d347e 100644 --- a/wlan/interfaces/include/wifi_hal.h +++ b/wlan/interfaces/include/wifi_hal.h @@ -265,6 +265,19 @@ struct IWiFi { * @version 1.0 */ int32_t (*getChannelMeasResult)(const char *ifName, struct MeasResult *measResult); + + /** + * @brief Config projection screen parameters. + * + * @param ifName Indicates the pointer to the network interface name. + * @param param Indicates the parameters used to config projection screen. + * + * @return Returns 0 if Config projection screen parameters successful; returns a negative value otherwise. + * + * @since 3.2 + * @version 1.0 + */ + int32_t (*setProjectionScreenParam)(const char *ifName, const ProjScrnCmdParam *param); }; /** diff --git a/wlan/test/hdi_service/wlan_callback_impl.c b/wlan/test/hdi_service/wlan_callback_impl.c index 7d517523fdf872bf16d2b290e07afd58a0728faf..385bab8849ff65651cc5626ec2865f48ecedbc87 100644 --- a/wlan/test/hdi_service/wlan_callback_impl.c +++ b/wlan/test/hdi_service/wlan_callback_impl.c @@ -30,8 +30,8 @@ int32_t WlanCallbackResetDriver(struct IWlanCallback *self, uint32_t event, int3 return HDF_SUCCESS; } -int32_t WlanCallbackScanResult( - struct IWlanCallback *self, uint32_t event, const struct HdfWifiScanResult *scanResult, const char *ifName) +int32_t WlanCallbackScanResult(struct IWlanCallback *self, uint32_t event, const struct HdfWifiScanResult *scanResult, + const char *ifName) { (void)self; if (scanResult == NULL || ifName == NULL) { 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 9d5634a6fcb73884a7f13839c994a7bc7ba6e686..c53edaefc54303b03637b7561b5974bf992f5814 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 @@ -786,4 +786,27 @@ HWTEST_F(HdfWifiServiceCTest, StartChannelMeasTest_034, TestSize.Level1) flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT || rc == HDF_DEV_ERR_NODATA); ASSERT_TRUE(flag); } + +/** + * @tc.name: SetProjectionScreenParam_035 + * @tc.desc: Wifi hdi set paramters to optimize projectino screen function test + * @tc.type: FUNC + * @tc.require: AR000HDUEE + */ +HWTEST_F(HdfWifiServiceCTest, SetProjectionScreenParam_035, TestSize.Level1) +{ + const char *ifName = "wlan0"; + int32_t rc; + struct ProjectionScreenCmdParam param; + int8_t data = 0; + param.buf = &data; + param.bufLen = sizeof(data); + + for (int i = CMD_CLOSE_GO_CAC; i <= CMD_ID_CTRL_ROAM_CHANNEL; i++) { + param.cmdId = i; + rc = g_wlanObj->SetProjectionScreenParam(g_wlanObj, ifName, ¶m); + bool flag = (rc == HDF_SUCCESS || rc == HDF_ERR_NOT_SUPPORT); + ASSERT_TRUE(flag); + } +} }; diff --git a/wlan/test/unittest/hal/wifi_hal_test.cpp b/wlan/test/unittest/hal/wifi_hal_test.cpp index c787b30d7df45552a7ac68c874745a0278e8fcf8..d5b7fbe7013f85ed2419ef42a5ab79474491c077 100644 --- a/wlan/test/unittest/hal/wifi_hal_test.cpp +++ b/wlan/test/unittest/hal/wifi_hal_test.cpp @@ -14,6 +14,7 @@ */ #include +#include #include "hdf_base.h" #include "hdf_sbuf.h" #include "wifi_hal.h" @@ -30,7 +31,9 @@ const int32_t WLAN_TX_POWER = 160; const uint32_t IFNAME_MIN_NUM = 0; const uint32_t IFNAME_MAX_NUM = 32; const uint32_t MAX_IF_NAME_LENGTH = 16; +const uint32_t TEST_PARAM_BUF_SIZE = 64; const uint32_t SIZE = 4; +const int32_t TEST_CMD = 123; class WifiHalTest : public testing::Test { public: @@ -78,10 +81,10 @@ void WifiHalTest::TearDown() static void ParseScanResult(WifiScanResult *scanResult) { - printf("ParseScanResult: flags=%d, caps=%d, freq=%d, beaconInt=%d,\n", - scanResult->flags, scanResult->caps, scanResult->freq, scanResult->beaconInt); - printf("ParseScanResult: qual=%d, beaconIeLen=%d, level=%d, age=%d, ieLen=%d,\n", - scanResult->qual, scanResult->beaconIeLen, scanResult->level, scanResult->age, scanResult->ieLen); + printf("ParseScanResult: flags=%d, caps=%d, freq=%d, beaconInt=%d,\n", scanResult->flags, scanResult->caps, + scanResult->freq, scanResult->beaconInt); + printf("ParseScanResult: qual=%d, beaconIeLen=%d, level=%d, age=%d, ieLen=%d,\n", scanResult->qual, + scanResult->beaconIeLen, scanResult->level, scanResult->age, scanResult->ieLen); } /** @@ -1229,6 +1232,86 @@ HWTEST_F(WifiHalTest, SetScanningMacAddress001, TestSize.Level1) EXPECT_EQ(ret, HDF_SUCCESS); } +/** + * @tc.name: SetProjectionScreenParam001 + * @tc.desc: wifi hal config projection screen function test + * @tc.type: FUNC + * @tc.require: AR000HDUEE + */ +HWTEST_F(WifiHalTest, SetProjectionScreenParam001, TestSize.Level1) +{ + int32_t ret; + bool flag; + struct IWiFiAp *apFeature = nullptr; + ProjScrnCmdParam *param; + + param = (ProjScrnCmdParam *)OsalMemCalloc(sizeof(ProjScrnCmdParam) + TEST_PARAM_BUF_SIZE); + EXPECT_NE(nullptr, param); + param->cmdId = TEST_CMD; + param->bufLen = 1; + param->buf[0] = 0; + ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&apFeature); + EXPECT_EQ(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(nullptr, nullptr); + EXPECT_NE(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(apFeature->baseFeature.ifName, nullptr); + EXPECT_NE(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(nullptr, param); + EXPECT_NE(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(apFeature->baseFeature.ifName, param); + EXPECT_NE(ret, HDF_SUCCESS); + for (int i = CMD_CLOSE_GO_CAC; i <= CMD_ID_CTRL_ROAM_CHANNEL; i++) { + param->cmdId = i; + ret = g_wifi->setProjectionScreenParam(apFeature->baseFeature.ifName, param); + printf("SetProjectionScreenParam001_%d: ret = %d\n", __LINE__, ret); + flag = (ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT); + ASSERT_TRUE(flag); + } + ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature); + EXPECT_EQ(ret, HDF_SUCCESS); + OsalMemFree(param); +} + +/** + * @tc.name: SetProjectionScreenParam002 + * @tc.desc: wifi hal config projection screen function test + * @tc.type: FUNC + * @tc.require: AR000HDUEE + */ +HWTEST_F(WifiHalTest, SetProjectionScreenParam002, TestSize.Level1) +{ + int32_t ret; + bool flag; + struct IWiFiSta *staFeature = nullptr; + ProjScrnCmdParam *param; + + param = (ProjScrnCmdParam *)OsalMemCalloc(sizeof(ProjScrnCmdParam) + TEST_PARAM_BUF_SIZE); + EXPECT_NE(nullptr, param); + param->cmdId = TEST_CMD; + param->bufLen = 1; + param->buf[0] = 0; + ret = g_wifi->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)&staFeature); + EXPECT_EQ(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(nullptr, nullptr); + EXPECT_NE(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(staFeature->baseFeature.ifName, nullptr); + EXPECT_NE(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(nullptr, param); + EXPECT_NE(ret, HDF_SUCCESS); + ret = g_wifi->setProjectionScreenParam(staFeature->baseFeature.ifName, param); + EXPECT_NE(ret, HDF_SUCCESS); + for (int i = CMD_CLOSE_GO_CAC; i <= CMD_ID_CTRL_ROAM_CHANNEL; i++) { + param->cmdId = i; + ret = g_wifi->setProjectionScreenParam(staFeature->baseFeature.ifName, param); + printf("SetProjectionScreenParam001_%d: ret = %d\n", __LINE__, ret); + flag = (ret == HDF_SUCCESS || ret == HDF_ERR_NOT_SUPPORT); + ASSERT_TRUE(flag); + } + ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)staFeature); + EXPECT_EQ(ret, HDF_SUCCESS); + OsalMemFree(param); +} + /** * @tc.name: ResetDriver001 * @tc.desc: wifi hal reset driver function test @@ -1290,4 +1373,4 @@ HWTEST_F(WifiHalTest, ResetDriver002, TestSize.Level1) ret = g_wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature); EXPECT_EQ(HDF_SUCCESS, ret); } -}; +}; // namespace HalTest