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