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->age = 0;
180 res->ie_len = scanResult->ieLen;
181 res->beacon_ie_len = scanResult->beaconIeLen;
182 rc = memcpy_s(res->bssid, ETH_ADDR_LEN, scanResult->bssid, ETH_ADDR_LEN);
183 if (rc != EOK) {
184 goto failed;
185 }
186 rc = memcpy_s(&res[1], scanResult->ieLen, scanResult->ie, scanResult->ieLen);
187 if (rc != EOK) {
188 goto failed;
189 }
190 rc = memcpy_s(((uint8_t *)(&res[1]) + scanResult->ieLen), scanResult->beaconIeLen, scanResult->beaconIe, scanResult->beaconIeLen);
191 if (rc != EOK) {
192 goto failed;
193 }
194 if (drv->scanNum >= SCAN_AP_LIMIT) {
195 wpa_printf(MSG_ERROR, "WifiWpaEventScanResultProcess: drv->scanNum >= SCAN_AP_LIMIT");
196 goto failed;
197 }
198 drv->scanRes[drv->scanNum++] = res;
199 WpaMemFree(scanResult->ie);
200 WpaMemFree(scanResult->bssid);
201 WpaMemFree(scanResult->beaconIe);
202 WpaMemFree(scanResult);
203 wpa_printf(MSG_INFO, "WifiWpaEventScanResultProcess done");
204 return;
205
206 failed:
207 if (res != NULL) {
208 os_free(res);
209 res = NULL;
210 }
211 WpaMemFree(scanResult->ie);
212 WpaMemFree(scanResult->bssid);
213 WpaMemFree(scanResult->beaconIe);
214 WpaMemFree(scanResult);
215 }
216
WifiWpaEventConnectResultProcess(void * ctx,void * data)217 static void WifiWpaEventConnectResultProcess(void *ctx, void *data)
218 {
219 if (ctx == NULL || data == NULL) {
220 return;
221 }
222 WifiDriverData *drv = (WifiDriverData *)ctx;
223 WifiConnectResult *result = (WifiConnectResult *)data;
224 union wpa_event_data event;
225 errno_t rc;
226
227 (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
228 if (result->status != 0) {
229 drv->associated = WIFI_DISCONNECT;
230 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
231 } else {
232 drv->associated = WIFI_CONNECT;
233 rc = memcpy_s(drv->bssid, ETH_ADDR_LEN, result->bssid, ETH_ALEN);
234 if (rc != EOK) {
235 goto failed;
236 }
237 event.assoc_info.req_ies = result->reqIe;
238 event.assoc_info.req_ies_len = result->reqIeLen;
239 event.assoc_info.resp_ies = result->respIe;
240 event.assoc_info.resp_ies_len = result->respIeLen;
241 event.assoc_info.addr = result->bssid;
242 event.assoc_info.freq = result->freq;
243 wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event);
244 }
245 wpa_printf(MSG_INFO, "WifiWpaEventConnectResultProcess done");
246
247 failed:
248 WpaMemFree(result->bssid);
249 WpaMemFree(result->reqIe);
250 WpaMemFree(result->respIe);
251 WpaMemFree(result);
252 }
253
WifiWpaEventDisconnectProcess(void * ctx,void * data)254 static void WifiWpaEventDisconnectProcess(void *ctx, void *data)
255 {
256 if (ctx == NULL || data == NULL) {
257 return;
258 }
259 wpa_printf(MSG_INFO, "WifiWpaEventDisconnectProcess enter.");
260 WifiDriverData *drv = (WifiDriverData *)ctx;
261 WifiDisconnect *result = (WifiDisconnect *)data;
262 union wpa_event_data event;
263 struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)drv->ctx;
264 if (wpa_s == NULL || wpa_s->disconnected == 1) {
265 wpa_printf(MSG_INFO, "WifiWpaEventDisconnectProcess: already disconnected, return.");
266 return;
267 }
268
269 (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
270 drv->associated = WIFI_DISCONNECT;
271 event.disassoc_info.reason_code = result->reason;
272 event.disassoc_info.ie = result->ie;
273 event.disassoc_info.ie_len = result->ieLen;
274 wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, &event);
275 wpa_printf(MSG_INFO, "WifiWpaEventDisconnectProcess done");
276 WpaMemFree(result->ie);
277 WpaMemFree(result);
278 }
279
280 extern void l2_packet_receive(void *eloop_ctx, void *sock_ctx);
WifiWpaDriverEventEapolRecvProcess(void * ctx,void * data)281 static inline void WifiWpaDriverEventEapolRecvProcess(void *ctx, void *data)
282 {
283 WifiDriverData *drv = (WifiDriverData *)ctx;
284 wpa_printf(MSG_INFO, "WifiWpaDriverEventEapolRecvProcess call");
285 eloop_register_timeout(0, 0, l2_packet_receive, drv->eapolSock, NULL);
286 }
287
WifiWpaEventRemainOnChannelProcess(void * ctx,void * data)288 static void WifiWpaEventRemainOnChannelProcess(void *ctx, void *data)
289 {
290 if (ctx == NULL || data == NULL) {
291 return;
292 }
293 WifiDriverData *drv = (WifiDriverData *)ctx;
294 WifiOnChannel *result = (WifiOnChannel *)data;
295 union wpa_event_data event;
296 (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
297
298 event.remain_on_channel.freq = result->freq;
299 event.remain_on_channel.duration = result->duration;
300 wpa_supplicant_event(drv->ctx, EVENT_REMAIN_ON_CHANNEL, &event);
301 wpa_printf(MSG_INFO, "%s done.", __FUNCTION__);
302 WpaMemFree(result);
303 }
304
WifiWpaEventCancelRemainOnChannelProcess(void * ctx,void * data)305 static void WifiWpaEventCancelRemainOnChannelProcess(void *ctx, void *data)
306 {
307 if (ctx == NULL || data == NULL) {
308 return;
309 }
310 WifiDriverData *drv = (WifiDriverData *)ctx;
311 WifiOnChannel *result = (WifiOnChannel *)data;
312 union wpa_event_data event;
313 (void)memset_s(&event, sizeof(union wpa_event_data), 0, sizeof(union wpa_event_data));
314
315 event.remain_on_channel.freq = result->freq;
316 wpa_supplicant_event(drv->ctx, EVENT_CANCEL_REMAIN_ON_CHANNEL, &event);
317 wpa_printf(MSG_INFO, "%s done.", __FUNCTION__);
318 WpaMemFree(result);
319 }
AllocAndCopyIe(uint8_t * dstIe,uint32_t ieLen,uint8_t * srcIe)320 static int32_t AllocAndCopyIe(uint8_t *dstIe, uint32_t ieLen, uint8_t *srcIe)
321 {
322 int32_t ret = 0;
323 if (ieLen == 0) {
324 dstIe = NULL;
325 return SUCC;
326 }
327 dstIe = (uint8_t *)os_zalloc(ieLen);
328 if (dstIe == NULL) {
329 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
330 return -EFAIL;
331 }
332 ret = memcpy_s(dstIe, ieLen, srcIe, ieLen);
333 if (ret != SUCC) {
334 WpaMemFree(dstIe);
335 return -EFAIL;
336 }
337 return SUCC;
338 }
339
WifiWpaNewStaProcess(WifiDriverData * drv,WifiNewStaInfo * staInfo)340 void WifiWpaNewStaProcess(WifiDriverData *drv, WifiNewStaInfo *staInfo)
341 {
342 WifiNewStaInfo *copyStaInfo = NULL;
343 uint8_t *ie = NULL;
344 uint8_t *macAddr = NULL;
345 int ret = 0;
346
347 copyStaInfo = (WifiNewStaInfo *)os_zalloc(sizeof(WifiNewStaInfo));
348 if (copyStaInfo == NULL) {
349 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
350 return;
351 }
352 ie = (uint8_t *)os_zalloc(staInfo->ieLen);
353 if (ie == NULL) {
354 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
355 goto failed3;
356 }
357 ret = memcpy_s(ie, staInfo->ieLen, staInfo->ie, staInfo->ieLen);
358 if (ret != SUCC) {
359 goto failed2;
360 }
361 macAddr = (uint8_t *)os_zalloc(ETH_ADDR_LEN);
362 if (macAddr == NULL) {
363 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
364 goto failed2;
365 }
366 ret = memcpy_s(macAddr, ETH_ADDR_LEN, staInfo->macAddr, ETH_ADDR_LEN);
367 if (ret != SUCC) {
368 goto failed1;
369 }
370
371 copyStaInfo->reassoc = staInfo->reassoc;
372 copyStaInfo->ie = ie;
373 copyStaInfo->ieLen = staInfo->ieLen;
374 copyStaInfo->macAddr = macAddr;
375 eloop_register_timeout(0, 0, WifiWpaEventNewStaProcess, drv, copyStaInfo);
376 return;
377
378 failed1:
379 WpaMemFree(macAddr);
380 failed2:
381 WpaMemFree(ie);
382 failed3:
383 WpaMemFree(copyStaInfo);
384 }
385
WifiWpaDelStaProcess(WifiDriverData * drv,uint8_t * addr)386 void WifiWpaDelStaProcess(WifiDriverData *drv, uint8_t *addr)
387 {
388 uint8_t *copyAddr = NULL;
389 int ret = 0;
390
391 copyAddr = (uint8_t *)os_zalloc(sizeof(ETH_ADDR_LEN));
392 if (copyAddr == NULL) {
393 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
394 return;
395 }
396 ret = memcpy_s(copyAddr, ETH_ADDR_LEN, addr, ETH_ADDR_LEN);
397 if (ret != SUCC) {
398 WpaMemFree(copyAddr);
399 return;
400 }
401 eloop_register_timeout(0, 0, WifiWpaEventDelStaProcess, drv, copyAddr);
402 }
403
WifiWpaRxMgmtProcess(WifiDriverData * drv,WifiRxMgmt * rxMgmt)404 void WifiWpaRxMgmtProcess(WifiDriverData *drv, WifiRxMgmt *rxMgmt)
405 {
406 WifiRxMgmt *copyRxMgmt = NULL;
407 uint8_t *buf = NULL;
408 int ret = 0;
409
410 copyRxMgmt = (WifiRxMgmt *)os_zalloc(sizeof(WifiRxMgmt));
411 if (copyRxMgmt == NULL) {
412 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
413 return;
414 }
415 buf = (uint8_t *)os_zalloc(rxMgmt->len);
416 if (buf == NULL) {
417 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
418 WpaMemFree(copyRxMgmt);
419 return;
420 }
421 ret = memcpy_s(buf, rxMgmt->len, rxMgmt->buf, rxMgmt->len);
422 if (ret != SUCC) {
423 WpaMemFree(copyRxMgmt);
424 WpaMemFree(buf);
425 return;
426 }
427 copyRxMgmt->buf = buf;
428 copyRxMgmt->len = rxMgmt->len;
429 copyRxMgmt->sigMbm = rxMgmt->sigMbm;
430 copyRxMgmt->freq = rxMgmt->freq;
431 eloop_register_timeout(0, 0, WifiWpaEventRxMgmtProcess, drv, copyRxMgmt);
432 }
433
WifiWpaTxStatusProcess(WifiDriverData * drv,WifiTxStatus * txStatus)434 void WifiWpaTxStatusProcess(WifiDriverData *drv, WifiTxStatus *txStatus)
435 {
436 WifiTxStatus *copyTxStatus = NULL;
437 uint8_t *buf = NULL;
438 int ret = 0;
439
440 copyTxStatus = (WifiTxStatus *)os_zalloc(sizeof(WifiTxStatus));
441 if (copyTxStatus == NULL) {
442 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
443 return;
444 }
445 buf = (uint8_t *)os_zalloc(txStatus->len);
446 if (buf == NULL) {
447 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
448 WpaMemFree(copyTxStatus);
449 return;
450 }
451 ret = memcpy_s(buf, txStatus->len, txStatus->buf, txStatus->len);
452 if (ret != SUCC) {
453 WpaMemFree(copyTxStatus);
454 WpaMemFree(buf);
455 return;
456 }
457 copyTxStatus->buf = buf;
458 copyTxStatus->ack = txStatus->ack;
459 copyTxStatus->len = txStatus->len;
460 eloop_register_timeout(0, 0, WifiWpaEventTxStatusProcess, drv, copyTxStatus);
461 }
462
WifiWpaScanDoneProcess(WifiDriverData * drv,uint32_t * status)463 void WifiWpaScanDoneProcess(WifiDriverData *drv, uint32_t *status)
464 {
465 uint32_t *copyStatus = NULL;
466 int ret = 0;
467
468 copyStatus = (uint32_t *)os_zalloc(sizeof(uint32_t));
469 if (copyStatus == NULL) {
470 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
471 return;
472 }
473 ret = memcpy_s(copyStatus, sizeof(uint32_t), status, sizeof(uint32_t));
474 if (ret != SUCC) {
475 WpaMemFree(copyStatus);
476 return;
477 }
478 eloop_register_timeout(0, 0, WifiWpaEventScanDoneProcess, drv, copyStatus);
479 }
480
WifiWpaScanResultProcess(WifiDriverData * drv,WifiScanResult * scanResult)481 void WifiWpaScanResultProcess(WifiDriverData *drv, WifiScanResult *scanResult)
482 {
483 WifiScanResult *copyScanResult = NULL;
484 uint8_t *ie = NULL;
485 uint8_t *beaconIe = NULL;
486 uint8_t *bssid = NULL;
487 int ret = 0;
488
489 copyScanResult = (WifiScanResult *)os_zalloc(sizeof(WifiScanResult));
490 if (copyScanResult == NULL) {
491 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
492 return;
493 }
494 bssid = (uint8_t *)os_zalloc(ETH_ADDR_LEN);
495 if (bssid == NULL) {
496 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
497 goto failed4;
498 }
499 ret = memcpy_s(bssid, ETH_ADDR_LEN, scanResult->bssid, ETH_ADDR_LEN);
500 if (ret != SUCC) {
501 goto failed3;
502 }
503
504 ie = (uint8_t *)os_zalloc(scanResult->ieLen);
505 if (ie == NULL) {
506 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
507 goto failed3;
508 }
509 ret = memcpy_s(ie, scanResult->ieLen, scanResult->ie, scanResult->ieLen);
510 if (ret != SUCC) {
511 goto failed2;
512 }
513
514 beaconIe = (uint8_t *)os_zalloc(scanResult->beaconIeLen);
515 if (beaconIe == NULL) {
516 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
517 goto failed2;
518 }
519 ret = memcpy_s(beaconIe, scanResult->beaconIeLen, scanResult->beaconIe, scanResult->beaconIeLen);
520 if (ret != SUCC) {
521 goto failed1;
522 }
523
524 copyScanResult->flags = scanResult->flags;
525 copyScanResult->freq = scanResult->freq;
526 copyScanResult->caps = scanResult->caps;
527 copyScanResult->beaconInt = scanResult->beaconInt;
528 copyScanResult->level = scanResult->level;
529 copyScanResult->ieLen = scanResult->ieLen;
530 copyScanResult->beaconIeLen = scanResult->beaconIeLen;
531 copyScanResult->bssid = bssid;
532 copyScanResult->ie = ie;
533 copyScanResult->beaconIe = beaconIe;
534 eloop_register_timeout(0, 0, WifiWpaEventScanResultProcess, drv, copyScanResult);
535 return;
536
537 failed1:
538 WpaMemFree(beaconIe);
539 failed2:
540 WpaMemFree(ie);
541 failed3:
542 WpaMemFree(bssid);
543 failed4:
544 WpaMemFree(copyScanResult);
545 }
546
WifiWpaConnectResultProcess(WifiDriverData * drv,WifiConnectResult * result)547 void WifiWpaConnectResultProcess(WifiDriverData *drv, WifiConnectResult *result)
548 {
549 WifiConnectResult *copyResult = NULL;
550 uint8_t *reqIe = NULL;
551 uint8_t *respIe = NULL;
552 uint8_t *bssid = NULL;
553 int ret = 0;
554
555 copyResult = (WifiConnectResult *)os_zalloc(sizeof(WifiConnectResult));
556 if (copyResult == NULL) {
557 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
558 return;
559 }
560 bssid = (uint8_t *)os_zalloc(ETH_ADDR_LEN);
561 if (bssid == NULL) {
562 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
563 goto failed4;
564 }
565 ret = memcpy_s(bssid, ETH_ADDR_LEN, result->bssid, ETH_ADDR_LEN);
566 if (ret != SUCC) {
567 goto failed3;
568 }
569
570 reqIe = (uint8_t *)os_zalloc(result->reqIeLen);
571 if (reqIe == NULL) {
572 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
573 goto failed3;
574 }
575 ret = memcpy_s(reqIe, result->reqIeLen, result->reqIe, result->reqIeLen);
576 if (ret != SUCC) {
577 goto failed2;
578 }
579
580 respIe = (uint8_t *)os_zalloc(result->respIeLen);
581 if (respIe == NULL) {
582 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
583 goto failed2;
584 }
585 ret = memcpy_s(respIe, result->respIeLen, result->respIe, result->respIeLen);
586 if (ret != SUCC) {
587 goto failed1;
588 }
589
590 copyResult->status = result->status;
591 copyResult->freq = result->freq;
592 copyResult->reqIeLen = result->reqIeLen;
593 copyResult->respIeLen = result->respIeLen;
594 copyResult->reqIe = reqIe;
595 copyResult->respIe = respIe;
596 copyResult->bssid = bssid;
597 eloop_register_timeout(0, 0, WifiWpaEventConnectResultProcess, drv, copyResult);
598 return;
599
600 failed1:
601 WpaMemFree(respIe);
602 failed2:
603 WpaMemFree(reqIe);
604 failed3:
605 WpaMemFree(bssid);
606 failed4:
607 WpaMemFree(copyResult);
608 }
609
WifiWpaDisconnectProcess(WifiDriverData * drv,WifiDisconnect * result)610 void WifiWpaDisconnectProcess(WifiDriverData *drv, WifiDisconnect *result)
611 {
612 WifiDisconnect *copyResult = NULL;
613 uint8_t *ie = NULL;
614 int32_t ret = 0;
615
616 copyResult = (WifiDisconnect *)os_zalloc(sizeof(WifiDisconnect));
617 if (copyResult == NULL) {
618 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
619 return;
620 }
621 ret = AllocAndCopyIe(ie, result->ieLen, result->ie);
622 if (ret != SUCC) {
623 WpaMemFree(copyResult);
624 return;
625 }
626 copyResult->ie = ie;
627 copyResult->ieLen = result->ieLen;
628 copyResult->reason = result->reason;
629 eloop_register_timeout(0, 0, WifiWpaEventDisconnectProcess, drv, copyResult);
630 }
631
WifiWpaDriverEapolRecvProcess(WifiDriverData * drv,void * data)632 void WifiWpaDriverEapolRecvProcess(WifiDriverData *drv, void *data)
633 {
634 eloop_register_timeout(0, 0, WifiWpaDriverEventEapolRecvProcess, drv, data);
635 }
636
WifiWpaRemainOnChannelProcess(WifiDriverData * drv,WifiOnChannel * result)637 void WifiWpaRemainOnChannelProcess(WifiDriverData *drv, WifiOnChannel *result)
638 {
639 WifiOnChannel *copyResult = NULL;
640
641 copyResult = (WifiOnChannel *)os_zalloc(sizeof(WifiOnChannel));
642 if (copyResult == NULL) {
643 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
644 return;
645 }
646 copyResult->freq = result->freq;
647 copyResult->duration = result->duration;
648 eloop_register_timeout(0, 0, WifiWpaEventRemainOnChannelProcess, drv, copyResult);
649 }
650
WifiWpaCancelRemainOnChannelProcess(WifiDriverData * drv,WifiOnChannel * result)651 void WifiWpaCancelRemainOnChannelProcess(WifiDriverData *drv, WifiOnChannel *result)
652 {
653 WifiOnChannel *copyResult = NULL;
654
655 copyResult = (WifiOnChannel *)os_zalloc(sizeof(WifiOnChannel));
656 if (copyResult == NULL) {
657 wpa_printf(MSG_ERROR, "%s fail: os_zalloc fail!", __func__);
658 return;
659 }
660 copyResult->freq = result->freq;
661 eloop_register_timeout(0, 0, WifiWpaEventCancelRemainOnChannelProcess, drv, copyResult);
662 }
663
664 #ifdef __cplusplus
665 #if __cplusplus
666 }
667 #endif
668 #endif
669