• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "ap.h"
10 #include <osal_mem.h>
11 #include <securec.h>
12 #include "message/message_router.h"
13 #include "message/sidecar.h"
14 #include "wifi_base.h"
15 #include "wifi_mac80211_ops.h"
16 #include "hdf_wlan_services.h"
17 #include "hdf_wlan_utils.h"
18 
19 #define HDF_LOG_TAG HDF_WIFI_CORE
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
ChangeBeacon(struct NetDevice * netDev,WifiApSetting * apSettings)24 static uint32_t ChangeBeacon(struct NetDevice *netDev, WifiApSetting *apSettings)
25 {
26     struct WlanBeaconConf beaconConf = { 0 };
27     struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
28     if (chipDriver == NULL) {
29         HDF_LOGE("%s:bad net device found!", __func__);
30         return HDF_FAILURE;
31     }
32     if (netDev == NULL || apSettings == NULL) {
33         HDF_LOGE("%s: parameter null", __func__);
34         return HDF_FAILURE;
35     }
36     beaconConf.interval = apSettings->beaconInterval;
37     beaconConf.DTIMPeriod = apSettings->dtimPeriod;
38     beaconConf.hiddenSSID = (apSettings->hiddenSsid == 1);
39     beaconConf.headIEs = apSettings->beaconData.head;
40     beaconConf.headIEsLength = apSettings->beaconData.headLen;
41     beaconConf.tailIEs = apSettings->beaconData.tail;
42     beaconConf.tailIEsLength = apSettings->beaconData.tailLen;
43     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, ConfigBeacon);
44     return chipDriver->apOps->ConfigBeacon(netDev, &beaconConf);
45 }
46 
StartAp(struct NetDevice * netDev,WifiApSetting * apSettings)47 static int32_t StartAp(struct NetDevice *netDev, WifiApSetting *apSettings)
48 {
49     struct WlanAPConf apConf = { 0 };
50     int32_t ret;
51     struct HdfChipDriver *chipDriver = NULL;
52     errno_t err;
53     HDF_LOGI("%s:starting ap...", __func__);
54     chipDriver = GetChipDriver(netDev);
55     if (chipDriver == NULL) {
56         HDF_LOGE("%s:bad net device found!", __func__);
57         return HDF_FAILURE;
58     }
59     err = memcpy_s(apConf.ssidConf.ssid, IEEE80211_MAX_SSID_LEN, apSettings->ssid, apSettings->ssidLen);
60     if (err != EOK) {
61         HDF_LOGE("%s: memcpy_s failed!ret=%d", __func__, err);
62         return HDF_FAILURE;
63     }
64     apConf.ssidConf.ssidLen = apSettings->ssidLen;
65     apConf.centerFreq1 = apSettings->freqParams.centerFreq1;
66     apConf.channel = apSettings->freqParams.channel;
67     apConf.width = apSettings->freqParams.bandwidth;
68     apConf.band = apSettings->freqParams.band;
69     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, ConfigAp);
70     ret = chipDriver->apOps->ConfigAp(netDev, &apConf);
71     if (ret != HDF_SUCCESS) {
72         HDF_LOGE("%s:ConfigAp failed!ret=%d", __func__, ret);
73         return HDF_FAILURE;
74     }
75     ret = ChangeBeacon(netDev, apSettings);
76     if (ret != HDF_SUCCESS) {
77         HDF_LOGE("%s:ChangeBeacon failed!ret=%d", __func__, ret);
78         return HDF_FAILURE;
79     }
80     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, StartAp);
81     ret = chipDriver->apOps->StartAp(netDev);
82     if (ret != HDF_SUCCESS) {
83         HDF_LOGE("%s:StartAp failed!ret=%d", __func__, ret);
84         return HDF_FAILURE;
85     }
86     return NetIfSetStatus(netDev, NETIF_UP);
87 }
88 
StopAp(struct NetDevice * netDev)89 static uint32_t StopAp(struct NetDevice *netDev)
90 {
91     uint32_t ret;
92     struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
93     if (chipDriver == NULL) {
94         HDF_LOGE("%s:bad net device found!", __func__);
95         return HDF_FAILURE;
96     }
97     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, StopAp);
98     ret = chipDriver->apOps->StopAp(netDev);
99     if (ret != HDF_SUCCESS) {
100         HDF_LOGE("StopAp:failed, error[%d]", ret);
101         return ret;
102     }
103     return NetIfSetStatus(netDev, NETIF_DOWN);
104 }
105 
DelStation(struct NetDevice * netDev,struct StationDelParameters * params)106 static uint32_t DelStation(struct NetDevice *netDev, struct StationDelParameters *params)
107 {
108     struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
109     if (chipDriver == NULL) {
110         HDF_LOGE("%s:bad net device found!", __func__);
111         return HDF_FAILURE;
112     }
113     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, DelStation);
114     return chipDriver->apOps->DelStation(netDev, params->mac);
115 }
116 
SetCountryCode(struct NetDevice * netDev,const char * code,uint32_t len)117 static uint32_t SetCountryCode(struct NetDevice *netDev, const char *code, uint32_t len)
118 {
119     struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
120     if (chipDriver == NULL) {
121         HDF_LOGE("%s:bad net device found!", __func__);
122         return HDF_FAILURE;
123     }
124     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, SetCountryCode);
125     return chipDriver->apOps->SetCountryCode(netDev, code, len);
126 }
127 
GetAssociatedStasCount(struct NetDevice * netDev,uint32_t * num)128 static uint32_t GetAssociatedStasCount(struct NetDevice *netDev, uint32_t *num)
129 {
130     struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
131     if (chipDriver == NULL) {
132         HDF_LOGE("%s:bad net device found!", __func__);
133         return HDF_FAILURE;
134     }
135     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, GetAssociatedStasCount);
136     return chipDriver->apOps->GetAssociatedStasCount(netDev, num);
137 }
138 
GetAssociatedStasInfo(struct NetDevice * netDev,WifiStaInfo * staInfo,uint32_t num)139 static uint32_t GetAssociatedStasInfo(struct NetDevice *netDev, WifiStaInfo *staInfo, uint32_t num)
140 {
141     struct HdfChipDriver *chipDriver = GetChipDriver(netDev);
142     if (chipDriver == NULL) {
143         HDF_LOGE("%s:bad net device found!", __func__);
144         return HDF_FAILURE;
145     }
146     RETURN_IF_CHIPOPS_NOT_IMPLEMENT(chipDriver->apOps, GetAssociatedStasInfo);
147     return chipDriver->apOps->GetAssociatedStasInfo(netDev, staInfo, num);
148 }
149 
WifiFillApSettingsParams(struct HdfSBuf * reqData,WifiApSetting * apSettings)150 static int32_t WifiFillApSettingsParams(struct HdfSBuf *reqData,  WifiApSetting *apSettings)
151 {
152     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.mode))) {
153         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "mode");
154         return HDF_FAILURE;
155     }
156     HDF_LOGI("%s:apSettings->freqParams.mode=%d", __func__, apSettings->freqParams.mode);
157     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.freq))) {
158         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "freq");
159         return HDF_FAILURE;
160     }
161     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.channel))) {
162         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "channel");
163         return HDF_FAILURE;
164     }
165     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.htEnabled))) {
166         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "htEnabled");
167         return HDF_FAILURE;
168     }
169     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.secChannelOffset))) {
170         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "secChannelOffset");
171         return HDF_FAILURE;
172     }
173     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.vhtEnabled))) {
174         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "vhtEnabled");
175         return HDF_FAILURE;
176     }
177     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.centerFreq1))) {
178         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "centerFreq1");
179         return HDF_FAILURE;
180     }
181     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.centerFreq2))) {
182         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "centerFreq2");
183         return HDF_FAILURE;
184     }
185     if (!HdfSbufReadInt32(reqData, &(apSettings->freqParams.bandwidth))) {
186         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "bandwidth");
187         return HDF_FAILURE;
188     }
189     if (!HdfSbufReadUint8(reqData, &(apSettings->freqParams.band))) {
190         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "band");
191         return HDF_FAILURE;
192     }
193     return HDF_SUCCESS;
194 }
195 
WifiCmdSetApInner(struct HdfSBuf * reqData,WifiApSetting * apSettings)196 static int32_t WifiCmdSetApInner(struct HdfSBuf *reqData,  WifiApSetting *apSettings)
197 {
198     if (WifiFillApSettingsParams(reqData, apSettings) != HDF_SUCCESS) {
199         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "apSettings");
200         return HDF_FAILURE;
201     }
202     if (!HdfSbufReadInt32(reqData, &(apSettings->beaconInterval))) {
203         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "beaconInterval");
204         return HDF_FAILURE;
205     }
206     if (!HdfSbufReadInt32(reqData, &(apSettings->dtimPeriod))) {
207         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "dtimPeriod");
208         return HDF_FAILURE;
209     }
210     if (!HdfSbufReadUint8(reqData, &(apSettings->hiddenSsid))) {
211         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "hiddenSsid");
212         return HDF_FAILURE;
213     }
214     if (!HdfSbufReadUint8(reqData, &(apSettings->authType))) {
215         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "authType");
216         return HDF_FAILURE;
217     }
218     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings->beaconData.head), &(apSettings->beaconData.headLen))) {
219         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "head");
220         return HDF_FAILURE;
221     }
222     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings->beaconData.tail), &(apSettings->beaconData.tailLen))) {
223         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "tail");
224         return HDF_FAILURE;
225     }
226     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings->ssid), &(apSettings->ssidLen))) {
227         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ssid");
228         return HDF_FAILURE;
229     }
230     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings->meshSsid), &(apSettings->meshSsidLen))) {
231         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "meshSsid");
232         return HDF_FAILURE;
233     }
234     return HDF_SUCCESS;
235 }
236 
WifiCmdSetAp(const RequestContext * context,struct HdfSBuf * reqData,struct HdfSBuf * rspData)237 static int32_t WifiCmdSetAp(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
238 {
239     WifiApSetting apSettings;
240     const char *ifName = NULL;
241     struct NetDevice *netdev = NULL;
242     int32_t ret = 0;
243     (void)context;
244     (void)rspData;
245     if (reqData == NULL) {
246         HDF_LOGE("%s: reqData is NULL", __func__);
247         return HDF_ERR_INVALID_PARAM;
248     }
249 
250     ifName = HdfSbufReadString(reqData);
251     if (ifName == NULL) {
252         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
253         return HDF_FAILURE;
254     }
255 
256     if (WifiCmdSetApInner(reqData, &apSettings) != HDF_SUCCESS) {
257         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "apSettings");
258         return HDF_FAILURE;
259     }
260 
261     netdev = NetDeviceGetInstByName(ifName);
262     if (netdev == NULL) {
263         HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
264         return HDF_FAILURE;
265     }
266     HDF_LOGI("%s:%s starting AP ...", __func__, ifName);
267     ret = StartAp(netdev, &apSettings);
268     return ret;
269 }
270 
WifiCmdStopAp(const RequestContext * context,struct HdfSBuf * reqData,struct HdfSBuf * rspData)271 static int32_t WifiCmdStopAp(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
272 {
273     const char *ifName = NULL;
274     struct NetDevice *netdev = NULL;
275     (void)context;
276     (void)rspData;
277     if (reqData == NULL) {
278         HDF_LOGE("%s: reqData is NULL", __func__);
279         return HDF_ERR_INVALID_PARAM;
280     }
281     ifName = HdfSbufReadString(reqData);
282     if (ifName == NULL) {
283         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
284         return HDF_FAILURE;
285     }
286     netdev = NetDeviceGetInstByName(ifName);
287     if (netdev == NULL) {
288         HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
289         return HDF_FAILURE;
290     }
291     HDF_LOGI("%s:%s stopping AP ...", __func__, ifName);
292     return StopAp(netdev);
293 }
294 
WifiCmdChangeBeacon(const RequestContext * context,struct HdfSBuf * reqData,struct HdfSBuf * rspData)295 static int32_t WifiCmdChangeBeacon(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
296 {
297     struct NetDevice *netdev = NULL;
298     WifiApSetting apSettings;
299     const char *ifName = NULL;
300     (void)context;
301     (void)rspData;
302     if (reqData == NULL) {
303         HDF_LOGE("%s: reqData is NULL", __func__);
304         return HDF_ERR_INVALID_PARAM;
305     }
306     ifName = HdfSbufReadString(reqData);
307     if (ifName == NULL) {
308         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
309         return HDF_FAILURE;
310     }
311     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings.beaconData.head), &(apSettings.beaconData.headLen))) {
312         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "head");
313         return HDF_FAILURE;
314     }
315     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings.beaconData.tail), &(apSettings.beaconData.tailLen))) {
316         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "tail");
317         return HDF_FAILURE;
318     }
319     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings.ssid), &(apSettings.ssidLen))) {
320         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ssid");
321         return HDF_FAILURE;
322     }
323     if (!HdfSbufReadBuffer(reqData, (const void **)&(apSettings.meshSsid), &(apSettings.meshSsidLen))) {
324         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "meshSsid");
325         return HDF_FAILURE;
326     }
327     netdev = NetDeviceGetInstByName(ifName);
328     if (netdev == NULL) {
329         HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
330         return HDF_FAILURE;
331     }
332     return ChangeBeacon(netdev, &apSettings);
333 }
334 
WifiCmdStaRemove(const RequestContext * context,struct HdfSBuf * reqData,struct HdfSBuf * rspData)335 static int32_t WifiCmdStaRemove(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
336 {
337     struct NetDevice *netdev = NULL;
338     struct StationDelParameters params;
339     const char *ifName = NULL;
340     uint32_t dataSize = 0;
341     int32_t ret;
342     (void)context;
343     (void)rspData;
344     if (reqData == NULL) {
345         HDF_LOGE("%s: reqData is NULL", __func__);
346         return HDF_ERR_INVALID_PARAM;
347     }
348     ifName = HdfSbufReadString(reqData);
349     if (ifName == NULL) {
350         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
351         return HDF_FAILURE;
352     }
353     netdev = NetDeviceGetInstByName(ifName);
354     if (netdev == NULL) {
355         HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
356         return HDF_FAILURE;
357     }
358     params.subtype = 0;
359     params.reasonCode = 0;
360     if (!HdfSbufReadBuffer(reqData, (const void **)&params.mac, &dataSize) || dataSize != ETH_ADDR_LEN) {
361         HDF_LOGE("%s: %s!ParamName=%s,readSize=%u", __func__, ERROR_DESC_READ_REQ_FAILED, "mac", dataSize);
362         return HDF_FAILURE;
363     }
364     ret = DelStation(netdev, &params);
365     HDF_LOGI("%s:del station XX:XX:XX:XX:XX:%02X ret=%d", __func__, params.mac[ETH_ADDR_LEN - 1], ret);
366     return ret;
367 }
368 
GetAssociatedStas(struct NetDevice * netdev,uint32_t num,struct HdfSBuf * rspData)369 static int32_t GetAssociatedStas(struct NetDevice *netdev, uint32_t num, struct HdfSBuf *rspData)
370 {
371     int32_t ret;
372     WifiStaInfo *staInfo = NULL;
373     staInfo = (WifiStaInfo *)OsalMemCalloc(sizeof(WifiStaInfo) * num);
374     if (staInfo == NULL) {
375         HDF_LOGE("%s: OsalMemCalloc failed!", __func__);
376         return HDF_FAILURE;
377     }
378     ret = GetAssociatedStasInfo(netdev, staInfo, num);
379     if (ret != HDF_SUCCESS) {
380         HDF_LOGE("%s: fail to get sta info,%d", __func__, ret);
381         OsalMemFree(staInfo);
382         return ret;
383     }
384     if (!HdfSbufWriteBuffer(rspData, staInfo, sizeof(WifiStaInfo) * num)) {
385         HDF_LOGE("%s: %s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
386         OsalMemFree(staInfo);
387         return HDF_FAILURE;
388     }
389     OsalMemFree(staInfo);
390     return HDF_SUCCESS;
391 }
392 
WifiCmdGetAssociatedStas(const RequestContext * context,struct HdfSBuf * reqData,struct HdfSBuf * rspData)393 static int32_t WifiCmdGetAssociatedStas(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
394 {
395     int32_t ret;
396     struct NetDevice *netdev = NULL;
397     const char *ifName = NULL;
398     uint32_t num;
399     (void)context;
400     if (reqData == NULL || rspData == NULL) {
401         return HDF_ERR_INVALID_PARAM;
402     }
403     ifName = HdfSbufReadString(reqData);
404     if (ifName == NULL) {
405         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
406         return HDF_FAILURE;
407     }
408     netdev = NetDeviceGetInstByName(ifName);
409     if (netdev == NULL) {
410         HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
411         return HDF_FAILURE;
412     }
413     ret = GetAssociatedStasCount(netdev, &num);
414     if (ret != HDF_SUCCESS) {
415         HDF_LOGE("%s: fail to get user num,ret=%d", __func__, ret);
416         return ret;
417     }
418     if (!HdfSbufWriteUint32(rspData, num)) {
419         HDF_LOGE("%s: %s!", __func__, ERROR_DESC_WRITE_RSP_FAILED);
420         return HDF_FAILURE;
421     }
422     if (num == 0) {
423         return HDF_SUCCESS;
424     }
425     ret = GetAssociatedStas(netdev, num, rspData);
426     if (ret != HDF_SUCCESS) {
427         HDF_LOGE("%s: fail to GetAssociatedStas,%d", __func__, ret);
428     }
429     return ret;
430 }
431 
WifiCmdSetCountryCode(const RequestContext * context,struct HdfSBuf * reqData,struct HdfSBuf * rspData)432 static int32_t WifiCmdSetCountryCode(const RequestContext *context, struct HdfSBuf *reqData, struct HdfSBuf *rspData)
433 {
434     int32_t ret;
435     struct NetDevice *netdev = NULL;
436     const char *ifName = NULL;
437     const char *code = NULL;
438     uint32_t replayDataSize;
439     (void)context;
440     if (reqData == NULL || rspData == NULL) {
441         return HDF_ERR_INVALID_PARAM;
442     }
443     ifName = HdfSbufReadString(reqData);
444     if (ifName == NULL) {
445         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "ifName");
446         return HDF_FAILURE;
447     }
448     netdev = NetDeviceGetInstByName(ifName);
449     if (netdev == NULL) {
450         HDF_LOGE("%s:netdev not found!ifName=%s", __func__, ifName);
451         return HDF_FAILURE;
452     }
453     if (!HdfSbufReadBuffer(reqData, (const void **)&code, &replayDataSize)) {
454         HDF_LOGE("%s: %s!ParamName=%s", __func__, ERROR_DESC_READ_REQ_FAILED, "code");
455         return HDF_FAILURE;
456     }
457     ret = SetCountryCode(netdev, code, replayDataSize);
458     if (ret != HDF_SUCCESS) {
459         HDF_LOGE("%s: fail to set country code,%d", __func__, ret);
460     }
461     return ret;
462 }
463 
464 static struct MessageDef g_wifiApFeatureCmds[] = {
465     DUEMessage(CMD_AP_START, WifiCmdSetAp, 0),
466     DUEMessage(CMD_AP_STOP, WifiCmdStopAp, 0),
467     DUEMessage(CMD_AP_CHANGE_BEACON, WifiCmdChangeBeacon, 0),
468     DUEMessage(CMD_AP_DEL_STATION, WifiCmdStaRemove, 0),
469     DUEMessage(CMD_AP_GET_ASSOC_STA, WifiCmdGetAssociatedStas, 0),
470     DUEMessage(CMD_AP_SET_COUNTRY_CODE, WifiCmdSetCountryCode, 0)
471 };
472 ServiceDefine(APService, AP_SERVICE_ID, g_wifiApFeatureCmds);
473 
474 static Service *g_apService = NULL;
475 
ApInit(struct WifiFeature * feature)476 int32_t ApInit(struct WifiFeature *feature)
477 {
478     (void)feature;
479     if (g_apService == NULL) {
480         ServiceCfg cfg = {
481             .dispatcherId = DEFAULT_DISPATCHER_ID
482         };
483         g_apService = CreateService(APService, &cfg);
484         if (g_apService == NULL) {
485             return HDF_FAILURE;
486         }
487     }
488     return HDF_SUCCESS;
489 }
490 
ApDeinit(struct WifiFeature * feature)491 int32_t ApDeinit(struct WifiFeature *feature)
492 {
493     (void)feature;
494     if (g_apService != NULL && g_apService->Destroy != NULL) {
495         g_apService->Destroy(g_apService);
496         g_apService = NULL;
497     }
498     return HDF_SUCCESS;
499 }
500 
501 struct WifiFeature g_apFeature = {
502     .name = "ap",
503     .init = ApInit,
504     .deInit = ApDeinit
505 };
506 
GetWifiApFeature(void)507 struct WifiFeature *GetWifiApFeature(void)
508 {
509     return &g_apFeature;
510 }
511 
512 #ifdef __cplusplus
513 }
514 #endif
515