• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Driver interaction with hdf wifi
3  * Copyright (c) 2020 Huawei Device Co., Ltd.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "utils/common.h"
11 #include "driver.h"
12 #include "eloop.h"
13 #include "l2_packet/l2_packet.h"
14 #include "wpa_hal.h"
15 #include "wpa_supplicant_i.h"
16 #include "securec.h"
17 
18 #ifdef __cplusplus
19 #if __cplusplus
20 extern "C" {
21 #endif
22 #endif
23 
WpaMemFree(void * mem)24 static void WpaMemFree(void *mem)
25 {
26     if (mem != NULL) {
27         free(mem);
28     }
29 }
30 
IsZeroAddr(const uint8_t * addr,const uint8_t len)31 static inline int IsZeroAddr(const uint8_t *addr, const uint8_t len)
32 {
33     if (len != ETH_ADDR_LEN) {
34         return -EFAIL;
35     }
36     // 0 1 2 3 4 5 : mac index
37     return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
38 }
39 
WifiWpaEventNewStaProcess(void * ctx,void * data)40 static void WifiWpaEventNewStaProcess(void *ctx, void *data)
41 {
42     if (ctx == NULL || data == NULL) {
43         return;
44     }
45     WifiDriverData *drv = (WifiDriverData *)ctx;
46     WifiNewStaInfo *staInfo = (WifiNewStaInfo *)data;
47     union wpa_event_data event;
48 
49     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
50     if (IsZeroAddr(staInfo->macAddr, ETH_ADDR_LEN)) {
51         wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
52     } else {
53         event.assoc_info.reassoc     = staInfo->reassoc;
54         event.assoc_info.req_ies     = staInfo->ie;
55         event.assoc_info.req_ies_len = staInfo->ieLen;
56         event.assoc_info.addr        = staInfo->macAddr;
57         wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event);
58     }
59     WpaMemFree(staInfo->ie);
60     WpaMemFree(staInfo->macAddr);
61     WpaMemFree(staInfo);
62     wpa_printf(MSG_INFO, "WifiWpaEventNewStaProcess done");
63 }
64 
WifiWpaEventDelStaProcess(void * ctx,void * data)65 static void WifiWpaEventDelStaProcess(void *ctx, void *data)
66 {
67     if (ctx == NULL || data == NULL) {
68         return;
69     }
70     wpa_printf(MSG_INFO, "WifiWpaEventDelStaProcess enter.");
71     WifiDriverData *drv = (WifiDriverData *)ctx;
72     uint8_t *addr = (uint8_t *)data;
73     union wpa_event_data event;
74     struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)drv->ctx;
75     if (wpa_s == NULL || wpa_s->disconnected == 1) {
76         wpa_printf(MSG_INFO, "WifiWpaEventDelStaProcess: already disconnected, return.");
77         return;
78     }
79     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
80     event.disassoc_info.addr = addr;
81     if (drv->ctx != NULL) {
82         wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, &event);
83         wpa_printf(MSG_INFO, "WifiWpaEventDelStaProcess done.");
84     }
85     WpaMemFree(addr);
86 }
87 
WifiWpaEventRxMgmtProcess(void * ctx,void * data)88 static void WifiWpaEventRxMgmtProcess(void *ctx, void *data)
89 {
90     if (ctx == NULL || data == NULL) {
91         return;
92     }
93     WifiDriverData *drv = (WifiDriverData *)ctx;
94     WifiRxMgmt *rxMgmt = (WifiRxMgmt *)data;
95     union wpa_event_data event;
96 
97     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
98     event.rx_mgmt.frame = rxMgmt->buf;
99     event.rx_mgmt.frame_len = rxMgmt->len;
100     event.rx_mgmt.ssi_signal = rxMgmt->sigMbm;
101     event.rx_mgmt.freq = rxMgmt->freq;
102 
103     wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
104     WpaMemFree(rxMgmt->buf);
105     WpaMemFree(rxMgmt);
106     wpa_printf(MSG_INFO, "WifiWpaEventRxMgmtProcess done");
107 }
108 
WifiWpaEventTxStatusProcess(void * ctx,void * data)109 static void WifiWpaEventTxStatusProcess(void *ctx, void *data)
110 {
111     if (ctx == NULL || data == NULL) {
112         return;
113     }
114     WifiDriverData *drv = (WifiDriverData *)ctx;
115     WifiTxStatus *txStatus = (WifiTxStatus *)data;
116     uint16_t fc;
117     struct ieee80211_hdr *hdr = NULL;
118     union wpa_event_data event;
119 
120     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
121     hdr = (struct ieee80211_hdr *)txStatus->buf;
122     fc = le_to_host16(hdr->frame_control);
123     event.tx_status.type = WLAN_FC_GET_TYPE(fc);
124     event.tx_status.stype = WLAN_FC_GET_STYPE(fc);
125     event.tx_status.dst = hdr->addr1;
126     event.tx_status.data = txStatus->buf;
127     event.tx_status.data_len = txStatus->len;
128     event.tx_status.ack = (txStatus->ack != FALSE);
129 
130     wpa_supplicant_event(drv->ctx, EVENT_TX_STATUS, &event);
131     WpaMemFree(txStatus->buf);
132     WpaMemFree(txStatus);
133     wpa_printf(MSG_INFO, "WifiWpaEventTxStatusProcess done");
134 }
135 
WifiWpaEventScanDoneProcess(void * ctx,void * data)136 static void WifiWpaEventScanDoneProcess(void *ctx, void *data)
137 {
138     if (ctx == NULL || data == NULL) {
139         return;
140     }
141     WifiDriverData *drv = (WifiDriverData *)ctx;
142     uint32_t *status = (uint32_t *)data;
143     if (drv->ctx == NULL) {
144         wpa_printf(MSG_ERROR, "%s: ctx is null", __func__);
145         goto failed;
146     }
147     eloop_cancel_timeout(WifiWpaScanTimeout, drv, drv->ctx);
148     if (*status != WIFI_SCAN_SUCCESS) {
149         goto failed;
150     }
151     wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, NULL);
152     wpa_printf(MSG_INFO, "WifiWpaEventScanDoneProcess done");
153 
154 failed:
155     WpaMemFree(status);
156 }
157 
WifiWpaEventScanResultProcess(void * ctx,void * data)158 static void WifiWpaEventScanResultProcess(void *ctx, void *data)
159 {
160     if (ctx == NULL || data == NULL) {
161         return;
162     }
163     WifiDriverData *drv = (WifiDriverData *)ctx;
164     WifiScanResult *scanResult = (WifiScanResult *)data;
165     struct wpa_scan_res *res = NULL;
166     errno_t rc;
167 
168     wpa_printf(MSG_INFO, "%s: ie_len=%d, beacon_ie_len=%d", __func__, scanResult->ieLen, scanResult->beaconIeLen);
169     res = (struct wpa_scan_res *)os_zalloc(sizeof(struct wpa_scan_res) + scanResult->ieLen + scanResult->beaconIeLen);
170     if (res == NULL) {
171         goto failed;
172     }
173     res->flags      = scanResult->flags;
174     res->freq       = scanResult->freq;
175     res->caps       = scanResult->caps;
176     res->beacon_int = scanResult->beaconInt;
177     res->qual       = 0;
178     res->level      = scanResult->level;
179     res->level /= 100;  /* mBm to dBm */
180     res->age        = 0;
181     res->ie_len     = scanResult->ieLen;
182     res->beacon_ie_len = scanResult->beaconIeLen;
183     rc = memcpy_s(res->bssid, ETH_ADDR_LEN, scanResult->bssid, ETH_ADDR_LEN);
184     if (rc != EOK) {
185         goto failed;
186     }
187     rc = memcpy_s(&res[1], scanResult->ieLen, scanResult->ie, scanResult->ieLen);
188     if (rc != EOK) {
189         goto failed;
190     }
191     rc = memcpy_s(((uint8_t *)(&res[1]) + scanResult->ieLen), scanResult->beaconIeLen, scanResult->beaconIe, scanResult->beaconIeLen);
192     if (rc != EOK) {
193         goto failed;
194     }
195     if (drv->scanNum >= SCAN_AP_LIMIT) {
196         wpa_printf(MSG_ERROR, "WifiWpaEventScanResultProcess: drv->scanNum >= SCAN_AP_LIMIT");
197         goto failed;
198     }
199     drv->scanRes[drv->scanNum++] = res;
200     WpaMemFree(scanResult->ie);
201     WpaMemFree(scanResult->bssid);
202     WpaMemFree(scanResult->beaconIe);
203     WpaMemFree(scanResult);
204     wpa_printf(MSG_INFO, "WifiWpaEventScanResultProcess done");
205     return;
206 
207 failed:
208     if (res != NULL) {
209         os_free(res);
210         res = NULL;
211     }
212     WpaMemFree(scanResult->ie);
213     WpaMemFree(scanResult->bssid);
214     WpaMemFree(scanResult->beaconIe);
215     WpaMemFree(scanResult);
216 }
217 
WifiWpaEventConnectResultProcess(void * ctx,void * data)218 static void WifiWpaEventConnectResultProcess(void *ctx, void *data)
219 {
220     if (ctx == NULL || data == NULL) {
221         return;
222     }
223     WifiDriverData *drv = (WifiDriverData *)ctx;
224     WifiConnectResult *result = (WifiConnectResult *)data;
225     union wpa_event_data event;
226     errno_t rc;
227 
228     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
229     if (result->status != 0) {
230         drv->associated = WIFI_DISCONNECT;
231         wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
232     } else {
233         drv->associated = WIFI_CONNECT;
234         rc = memcpy_s(drv->bssid, ETH_ADDR_LEN, result->bssid, ETH_ALEN);
235         if (rc != EOK) {
236             goto failed;
237         }
238         event.assoc_info.req_ies      = result->reqIe;
239         event.assoc_info.req_ies_len  = result->reqIeLen;
240         event.assoc_info.resp_ies     = result->respIe;
241         event.assoc_info.resp_ies_len = result->respIeLen;
242         event.assoc_info.addr         = result->bssid;
243         event.assoc_info.freq         = result->freq;
244         wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event);
245     }
246     wpa_printf(MSG_INFO, "WifiWpaEventConnectResultProcess done");
247 
248 failed:
249     WpaMemFree(result->bssid);
250     WpaMemFree(result->reqIe);
251     WpaMemFree(result->respIe);
252     WpaMemFree(result);
253 }
254 
WifiWpaEventDisconnectProcess(void * ctx,void * data)255 static void WifiWpaEventDisconnectProcess(void *ctx, void *data)
256 {
257     if (ctx == NULL || data == NULL) {
258         return;
259     }
260     wpa_printf(MSG_INFO, "WifiWpaEventDisconnectProcess enter.");
261     WifiDriverData *drv = (WifiDriverData *)ctx;
262     WifiDisconnect *result = (WifiDisconnect *)data;
263     union wpa_event_data event;
264     struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)drv->ctx;
265     if (wpa_s == NULL || wpa_s->disconnected == 1) {
266         wpa_printf(MSG_INFO, "WifiWpaEventDisconnectProcess: already disconnected, return.");
267         return;
268     }
269 
270     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
271     drv->associated = WIFI_DISCONNECT;
272     event.disassoc_info.reason_code = result->reason;
273     event.disassoc_info.ie          = result->ie;
274     event.disassoc_info.ie_len      = result->ieLen;
275     wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, &event);
276     wpa_printf(MSG_INFO, "WifiWpaEventDisconnectProcess done");
277     WpaMemFree(result->ie);
278     WpaMemFree(result);
279 }
280 
281 extern void l2_packet_receive(void *eloop_ctx, void *sock_ctx);
WifiWpaDriverEventEapolRecvProcess(void * ctx,void * data)282 static inline void WifiWpaDriverEventEapolRecvProcess(void *ctx, void *data)
283 {
284     WifiDriverData *drv = (WifiDriverData *)ctx;
285     wpa_printf(MSG_INFO, "WifiWpaDriverEventEapolRecvProcess call");
286     eloop_register_timeout(0, 0, l2_packet_receive, drv->eapolSock, NULL);
287 }
288 
WifiWpaEventRemainOnChannelProcess(void * ctx,void * data)289 static void WifiWpaEventRemainOnChannelProcess(void *ctx, void *data)
290 {
291     if (ctx == NULL || data == NULL) {
292         return;
293     }
294     WifiDriverData *drv = (WifiDriverData *)ctx;
295     WifiOnChannel *result = (WifiOnChannel *)data;
296     union wpa_event_data event;
297     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
298 
299     event.remain_on_channel.freq = result->freq;
300     event.remain_on_channel.duration = result->duration;
301     wpa_supplicant_event(drv->ctx, EVENT_REMAIN_ON_CHANNEL, &event);
302     wpa_printf(MSG_INFO, "%s done.", __FUNCTION__);
303     WpaMemFree(result);
304 }
305 
WifiWpaEventCancelRemainOnChannelProcess(void * ctx,void * data)306 static void WifiWpaEventCancelRemainOnChannelProcess(void *ctx, void *data)
307 {
308     if (ctx == NULL || data == NULL) {
309         return;
310     }
311     WifiDriverData *drv = (WifiDriverData *)ctx;
312     WifiOnChannel *result = (WifiOnChannel *)data;
313     union wpa_event_data event;
314     (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
315 
316     event.remain_on_channel.freq = result->freq;
317     wpa_supplicant_event(drv->ctx, EVENT_CANCEL_REMAIN_ON_CHANNEL, &event);
318     wpa_printf(MSG_INFO, "%s done.", __FUNCTION__);
319     WpaMemFree(result);
320 }
AllocAndCopyIe(uint8_t * dstIe,uint32_t ieLen,uint8_t * srcIe)321 static int32_t AllocAndCopyIe(uint8_t *dstIe, uint32_t ieLen, uint8_t *srcIe)
322 {
323     int32_t ret = 0;
324     if (ieLen == 0) {
325         dstIe = NULL;
326         return SUCC;
327     }
328     dstIe = (uint8_t *)os_zalloc(ieLen);
329     if (dstIe == NULL) {
330         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
331         return -EFAIL;
332     }
333     ret = memcpy_s(dstIe, ieLen, srcIe, ieLen);
334     if (ret != SUCC) {
335         WpaMemFree(dstIe);
336         return -EFAIL;
337     }
338 	return SUCC;
339 }
340 
WifiWpaNewStaProcess(WifiDriverData * drv,WifiNewStaInfo * staInfo)341 void WifiWpaNewStaProcess(WifiDriverData *drv, WifiNewStaInfo *staInfo)
342 {
343     WifiNewStaInfo *copyStaInfo = NULL;
344     uint8_t *ie = NULL;
345     uint8_t *macAddr = NULL;
346     int ret = 0;
347 
348     copyStaInfo = (WifiNewStaInfo *)os_zalloc(sizeof(WifiNewStaInfo));
349     if (copyStaInfo == NULL) {
350         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
351         return;
352     }
353     ie = (uint8_t *)os_zalloc(staInfo->ieLen);
354     if (ie == NULL) {
355         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
356         goto failed3;
357     }
358     ret = memcpy_s(ie, staInfo->ieLen, staInfo->ie, staInfo->ieLen);
359     if (ret != SUCC) {
360         goto failed2;
361     }
362     macAddr = (uint8_t *)os_zalloc(ETH_ADDR_LEN);
363     if (macAddr == NULL) {
364         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
365         goto failed2;
366     }
367     ret = memcpy_s(macAddr, ETH_ADDR_LEN, staInfo->macAddr, ETH_ADDR_LEN);
368     if (ret != SUCC) {
369         goto failed1;
370     }
371 
372     copyStaInfo->reassoc     = staInfo->reassoc;
373     copyStaInfo->ie     = ie;
374     copyStaInfo->ieLen = staInfo->ieLen;
375     copyStaInfo->macAddr        = macAddr;
376     eloop_register_timeout(0, 0, WifiWpaEventNewStaProcess, drv, copyStaInfo);
377     return;
378 
379 failed1:
380     WpaMemFree(macAddr);
381 failed2:
382     WpaMemFree(ie);
383 failed3:
384     WpaMemFree(copyStaInfo);
385 }
386 
WifiWpaDelStaProcess(WifiDriverData * drv,uint8_t * addr)387 void WifiWpaDelStaProcess(WifiDriverData *drv, uint8_t *addr)
388 {
389     uint8_t *copyAddr = NULL;
390     int ret = 0;
391 
392     copyAddr = (uint8_t *)os_zalloc(sizeof(ETH_ADDR_LEN));
393     if (copyAddr == NULL) {
394         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
395         return;
396     }
397     ret = memcpy_s(copyAddr, ETH_ADDR_LEN, addr, ETH_ADDR_LEN);
398     if (ret != SUCC) {
399         WpaMemFree(copyAddr);
400         return;
401     }
402     eloop_register_timeout(0, 0, WifiWpaEventDelStaProcess, drv, copyAddr);
403 }
404 
WifiWpaRxMgmtProcess(WifiDriverData * drv,WifiRxMgmt * rxMgmt)405 void WifiWpaRxMgmtProcess(WifiDriverData *drv, WifiRxMgmt *rxMgmt)
406 {
407     WifiRxMgmt *copyRxMgmt = NULL;
408     uint8_t *buf = NULL;
409     int ret = 0;
410 
411     copyRxMgmt = (WifiRxMgmt *)os_zalloc(sizeof(WifiRxMgmt));
412     if (copyRxMgmt == NULL) {
413         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
414         return;
415     }
416     buf = (uint8_t *)os_zalloc(rxMgmt->len);
417     if (buf == NULL) {
418         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
419         WpaMemFree(copyRxMgmt);
420         return;
421     }
422     ret = memcpy_s(buf, rxMgmt->len, rxMgmt->buf, rxMgmt->len);
423     if (ret != SUCC) {
424         WpaMemFree(copyRxMgmt);
425         WpaMemFree(buf);
426         return;
427     }
428     copyRxMgmt->buf = buf;
429     copyRxMgmt->len = rxMgmt->len;
430     copyRxMgmt->sigMbm = rxMgmt->sigMbm;
431     copyRxMgmt->freq = rxMgmt->freq;
432     eloop_register_timeout(0, 0, WifiWpaEventRxMgmtProcess, drv, copyRxMgmt);
433 }
434 
WifiWpaTxStatusProcess(WifiDriverData * drv,WifiTxStatus * txStatus)435 void WifiWpaTxStatusProcess(WifiDriverData *drv, WifiTxStatus *txStatus)
436 {
437     WifiTxStatus *copyTxStatus = NULL;
438     uint8_t *buf = NULL;
439     int ret = 0;
440 
441     copyTxStatus = (WifiTxStatus *)os_zalloc(sizeof(WifiTxStatus));
442     if (copyTxStatus == NULL) {
443         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
444         return;
445     }
446     buf = (uint8_t *)os_zalloc(txStatus->len);
447     if (buf == NULL) {
448         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
449         WpaMemFree(copyTxStatus);
450         return;
451     }
452     ret = memcpy_s(buf, txStatus->len, txStatus->buf, txStatus->len);
453     if (ret != SUCC) {
454         WpaMemFree(copyTxStatus);
455         WpaMemFree(buf);
456         return;
457     }
458     copyTxStatus->buf = buf;
459     copyTxStatus->ack = txStatus->ack;
460     copyTxStatus->len = txStatus->len;
461     eloop_register_timeout(0, 0, WifiWpaEventTxStatusProcess, drv, copyTxStatus);
462 }
463 
WifiWpaScanDoneProcess(WifiDriverData * drv,uint32_t * status)464 void WifiWpaScanDoneProcess(WifiDriverData *drv, uint32_t *status)
465 {
466     uint32_t *copyStatus = NULL;
467     int ret = 0;
468 
469     copyStatus = (uint32_t *)os_zalloc(sizeof(uint32_t));
470     if (copyStatus == NULL) {
471         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
472         return;
473     }
474     ret = memcpy_s(copyStatus, sizeof(uint32_t), status, sizeof(uint32_t));
475     if (ret != SUCC) {
476         WpaMemFree(copyStatus);
477         return;
478     }
479     eloop_register_timeout(0, 0, WifiWpaEventScanDoneProcess, drv, copyStatus);
480 }
481 
WifiWpaScanResultProcess(WifiDriverData * drv,WifiScanResult * scanResult)482 void WifiWpaScanResultProcess(WifiDriverData *drv, WifiScanResult *scanResult)
483 {
484     WifiScanResult *copyScanResult = NULL;
485     uint8_t *ie = NULL;
486     uint8_t *beaconIe = NULL;
487     uint8_t *bssid = NULL;
488     int ret = 0;
489 
490     copyScanResult = (WifiScanResult *)os_zalloc(sizeof(WifiScanResult));
491     if (copyScanResult == NULL) {
492         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
493         return;
494     }
495     bssid = (uint8_t *)os_zalloc(ETH_ADDR_LEN);
496     if (bssid == NULL) {
497         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
498         goto failed4;
499     }
500     ret = memcpy_s(bssid, ETH_ADDR_LEN, scanResult->bssid, ETH_ADDR_LEN);
501     if (ret != SUCC) {
502         goto failed3;
503     }
504 
505     ie = (uint8_t *)os_zalloc(scanResult->ieLen);
506     if (ie == NULL) {
507         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
508         goto failed3;
509     }
510     ret = memcpy_s(ie, scanResult->ieLen, scanResult->ie, scanResult->ieLen);
511     if (ret != SUCC) {
512         goto failed2;
513     }
514 
515     beaconIe = (uint8_t *)os_zalloc(scanResult->beaconIeLen);
516     if (beaconIe == NULL) {
517         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
518         goto failed2;
519     }
520     ret = memcpy_s(beaconIe, scanResult->beaconIeLen, scanResult->beaconIe, scanResult->beaconIeLen);
521     if (ret != SUCC) {
522         goto failed1;
523     }
524 
525     copyScanResult->flags      = scanResult->flags;
526     copyScanResult->freq       = scanResult->freq;
527     copyScanResult->caps       = scanResult->caps;
528     copyScanResult->beaconInt = scanResult->beaconInt;
529     copyScanResult->level      = scanResult->level;
530     copyScanResult->ieLen     = scanResult->ieLen;
531     copyScanResult->beaconIeLen = scanResult->beaconIeLen;
532     copyScanResult->bssid = bssid;
533     copyScanResult->ie = ie;
534     copyScanResult->beaconIe = beaconIe;
535     eloop_register_timeout(0, 0, WifiWpaEventScanResultProcess, drv, copyScanResult);
536     return;
537 
538 failed1:
539     WpaMemFree(beaconIe);
540 failed2:
541     WpaMemFree(ie);
542 failed3:
543     WpaMemFree(bssid);
544 failed4:
545     WpaMemFree(copyScanResult);
546 }
547 
WifiWpaConnectResultProcess(WifiDriverData * drv,WifiConnectResult * result)548 void WifiWpaConnectResultProcess(WifiDriverData *drv, WifiConnectResult *result)
549 {
550     WifiConnectResult *copyResult = NULL;
551     uint8_t *reqIe = NULL;
552     uint8_t *respIe = NULL;
553     uint8_t *bssid = NULL;
554     int ret = 0;
555 
556     copyResult = (WifiConnectResult *)os_zalloc(sizeof(WifiConnectResult));
557     if (copyResult == NULL) {
558         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
559         return;
560     }
561     bssid = (uint8_t *)os_zalloc(ETH_ADDR_LEN);
562     if (bssid == NULL) {
563         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
564         goto failed4;
565     }
566     ret = memcpy_s(bssid, ETH_ADDR_LEN, result->bssid, ETH_ADDR_LEN);
567     if (ret != SUCC) {
568         goto failed3;
569     }
570 
571     reqIe = (uint8_t *)os_zalloc(result->reqIeLen);
572     if (reqIe == NULL) {
573         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
574         goto failed3;
575     }
576     ret = memcpy_s(reqIe, result->reqIeLen, result->reqIe, result->reqIeLen);
577     if (ret != SUCC) {
578         goto failed2;
579     }
580 
581     respIe = (uint8_t *)os_zalloc(result->respIeLen);
582     if (respIe == NULL) {
583         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
584         goto failed2;
585     }
586     ret = memcpy_s(respIe, result->respIeLen, result->respIe, result->respIeLen);
587     if (ret != SUCC) {
588         goto failed1;
589     }
590 
591     copyResult->status = result->status;
592     copyResult->freq = result->freq;
593     copyResult->reqIeLen = result->reqIeLen;
594     copyResult->respIeLen = result->respIeLen;
595     copyResult->reqIe = reqIe;
596     copyResult->respIe = respIe;
597     copyResult->bssid = bssid;
598     eloop_register_timeout(0, 0, WifiWpaEventConnectResultProcess, drv, copyResult);
599     return;
600 
601 failed1:
602     WpaMemFree(respIe);
603 failed2:
604     WpaMemFree(reqIe);
605 failed3:
606     WpaMemFree(bssid);
607 failed4:
608     WpaMemFree(copyResult);
609 }
610 
WifiWpaDisconnectProcess(WifiDriverData * drv,WifiDisconnect * result)611 void WifiWpaDisconnectProcess(WifiDriverData *drv, WifiDisconnect *result)
612 {
613     WifiDisconnect *copyResult = NULL;
614     uint8_t *ie = NULL;
615     int32_t ret = 0;
616 
617     copyResult = (WifiDisconnect *)os_zalloc(sizeof(WifiDisconnect));
618     if (copyResult == NULL) {
619         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
620         return;
621     }
622     ret = AllocAndCopyIe(ie, result->ieLen, result->ie);
623     if (ret != SUCC) {
624         WpaMemFree(copyResult);
625         return;
626     }
627     copyResult->ie = ie;
628     copyResult->ieLen = result->ieLen;
629     copyResult->reason = result->reason;
630     eloop_register_timeout(0, 0, WifiWpaEventDisconnectProcess, drv, copyResult);
631 }
632 
WifiWpaDriverEapolRecvProcess(WifiDriverData * drv,void * data)633 void WifiWpaDriverEapolRecvProcess(WifiDriverData *drv, void *data)
634 {
635     eloop_register_timeout(0, 0, WifiWpaDriverEventEapolRecvProcess, drv, data);
636 }
637 
WifiWpaRemainOnChannelProcess(WifiDriverData * drv,WifiOnChannel * result)638 void WifiWpaRemainOnChannelProcess(WifiDriverData *drv, WifiOnChannel *result)
639 {
640     WifiOnChannel *copyResult = NULL;
641 
642     copyResult = (WifiOnChannel *)os_zalloc(sizeof(WifiOnChannel));
643     if (copyResult == NULL) {
644         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
645         return;
646     }
647     copyResult->freq = result->freq;
648     copyResult->duration = result->duration;
649     eloop_register_timeout(0, 0, WifiWpaEventRemainOnChannelProcess, drv, copyResult);
650 }
651 
WifiWpaCancelRemainOnChannelProcess(WifiDriverData * drv,WifiOnChannel * result)652 void WifiWpaCancelRemainOnChannelProcess(WifiDriverData *drv, WifiOnChannel *result)
653 {
654     WifiOnChannel *copyResult = NULL;
655 
656     copyResult = (WifiOnChannel *)os_zalloc(sizeof(WifiOnChannel));
657     if (copyResult == NULL) {
658         wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
659         return;
660     }
661     copyResult->freq = result->freq;
662     eloop_register_timeout(0, 0, WifiWpaEventCancelRemainOnChannelProcess, drv, copyResult);
663 }
664 
665 #ifdef __cplusplus
666 #if __cplusplus
667 }
668 #endif
669 #endif
670