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