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