-
Notifications
You must be signed in to change notification settings - Fork 7k
/
esp_common.c
738 lines (637 loc) · 18.4 KB
/
esp_common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/*
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "utils/includes.h"
#include "utils/common.h"
#include "esp_event.h"
#include "esp_wifi.h"
#include "esp_wifi_types.h"
#include "esp_wifi_driver.h"
#include "drivers/driver.h"
#include "common/bss.h"
#include "common/rrm.h"
#include "common/wnm_sta.h"
#include "common/wpa_supplicant_i.h"
#include "esp_scan_i.h"
#include "esp_common_i.h"
#include "common/ieee802_11_common.h"
#include "esp_rrm.h"
#include "esp_wnm.h"
#include "rsn_supp/wpa.h"
#include "esp_private/wifi.h"
struct wpa_supplicant g_wpa_supp;
#if defined(CONFIG_WPA_11KV_SUPPORT)
static TaskHandle_t s_supplicant_task_hdl = NULL;
static void *s_supplicant_evt_queue = NULL;
static void *s_supplicant_api_lock = NULL;
static bool s_supplicant_task_init_done;
static int handle_action_frm(u8 *frame, size_t len,
u8 *sender, int8_t rssi, u8 channel)
{
struct ieee_mgmt_frame *frm = os_malloc(sizeof(struct ieee_mgmt_frame) + len);
if (!frm) {
wpa_printf(MSG_ERROR, "memory allocation failed");
return -1;
}
os_memcpy(frm->sender, sender, ETH_ALEN);
frm->len = len;
frm->channel = channel;
frm->rssi = rssi;
os_memcpy(frm->payload, frame, len);
if (esp_supplicant_post_evt(SIG_SUPPLICANT_RX_ACTION, (u32)frm) != 0) {
os_free(frm);
return -1;
}
return 0;
}
static void handle_rrm_frame(struct wpa_supplicant *wpa_s, u8 *sender,
u8 *payload, size_t len, int8_t rssi)
{
if (payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
/* neighbor report parsing */
wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, len - 1);
} else if (payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
/* Beacon measurement */
wpas_rrm_handle_radio_measurement_request(wpa_s, NULL,
sender, payload + 1, len - 1);
} else if (payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
/* Link measurement */
wpas_rrm_handle_link_measurement_request(wpa_s, NULL,
payload + 1, len - 1, rssi);
}
}
static int mgmt_rx_action(u8 *sender, u8 *payload, size_t len, u8 channel, int8_t rssi)
{
u8 category;
u8 bssid[ETH_ALEN];
struct wpa_supplicant *wpa_s = &g_wpa_supp;
int ret = esp_wifi_get_assoc_bssid_internal(bssid);
if (ret < 0) {
wpa_printf(MSG_INFO, "STA not associated");
return -1;
}
category = *payload++;
len--;
if (category == WLAN_ACTION_WNM) {
ieee802_11_rx_wnm_action(wpa_s, sender, payload, len);
} else if (category == WLAN_ACTION_RADIO_MEASUREMENT) {
handle_rrm_frame(wpa_s, sender, payload, len, rssi);
}
return 0;
}
static void btm_rrm_task(void *pvParameters)
{
supplicant_event_t *evt;
bool task_del = false;
while(1) {
if (xQueueReceive(s_supplicant_evt_queue, &evt, portMAX_DELAY) != pdTRUE)
continue;
/* event validation failed */
if (evt->id >= SIG_SUPPLICANT_MAX) {
os_free(evt);
continue;
}
switch (evt->id) {
case SIG_SUPPLICANT_RX_ACTION:
{
struct ieee_mgmt_frame *frm = (struct ieee_mgmt_frame *)evt->data;
mgmt_rx_action(frm->sender, frm->payload, frm->len, frm->channel, frm->rssi);
os_free(frm);
break;
}
case SIG_SUPPLICANT_SCAN_DONE:
esp_supplicant_handle_scan_done_evt();
break;
case SIG_SUPPLICANT_DEL_TASK:
task_del = true;
break;
default:
break;
}
os_free(evt);
if (task_del)
break;
}
vQueueDelete(s_supplicant_evt_queue);
s_supplicant_evt_queue = NULL;
/* At this point, we completed */
vTaskDelete(NULL);
}
static void clear_bssid_flag(struct wpa_supplicant *wpa_s)
{
wifi_config_t *config;
/* Reset only if btm is enabled */
if (esp_wifi_is_btm_enabled_internal(WIFI_IF_STA) == false)
return;
config = os_zalloc(sizeof(wifi_config_t));
if (!config) {
wpa_printf(MSG_ERROR, "failed to allocate memory");
return;
}
esp_wifi_get_config(WIFI_IF_STA, config);
if (config->sta.bssid_set) {
config->sta.bssid_set = 0;
esp_wifi_set_config(WIFI_IF_STA, config);
}
os_free(config);
wpa_printf(MSG_DEBUG, "cleared bssid flag");
}
static void register_action_frame(struct wpa_supplicant *wpa_s)
{
wpa_s->type &= ~(1 << WLAN_FC_STYPE_ACTION);
/* subtype is defined only for action frame */
wpa_s->subtype = 0;
/* current supported features in supplicant: rrm and btm */
if (esp_wifi_is_rm_enabled_internal(WIFI_IF_STA))
wpa_s->subtype = 1 << WLAN_ACTION_RADIO_MEASUREMENT;
if (esp_wifi_is_btm_enabled_internal(WIFI_IF_STA))
wpa_s->subtype |= 1 << WLAN_ACTION_WNM;
if (wpa_s->subtype)
wpa_s->type |= 1 << WLAN_FC_STYPE_ACTION;
esp_wifi_register_mgmt_frame_internal(wpa_s->type, wpa_s->subtype);
}
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
void esp_supplicant_unset_all_appie(void)
{
uint8_t appie;
for (appie = WIFI_APPIE_PROBEREQ; appie < WIFI_APPIE_RAM_MAX; appie++) {
esp_wifi_unset_appie_internal(appie);
}
}
static int ieee80211_handle_rx_frm(u8 type, u8 *frame, size_t len, u8 *sender,
int8_t rssi, u8 channel, u64 current_tsf)
{
int ret = 0;
switch (type) {
#if defined(CONFIG_WPA_11KV_SUPPORT)
case WLAN_FC_STYPE_BEACON:
case WLAN_FC_STYPE_PROBE_RESP:
ret = esp_handle_beacon_probe(type, frame, len, sender, rssi, channel, current_tsf);
break;
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
case WLAN_FC_STYPE_ASSOC_RESP:
case WLAN_FC_STYPE_REASSOC_RESP:
wpa_sm_notify_assoc(&gWpaSm, sender);
break;
#if defined(CONFIG_WPA_11KV_SUPPORT)
case WLAN_FC_STYPE_ACTION:
ret = handle_action_frm(frame, len, sender, rssi, channel);
break;
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
default:
ret = -1;
break;
}
return ret;
}
#if defined(CONFIG_WPA_11KV_SUPPORT)
#ifdef CONFIG_MBO
static bool bss_profile_match(u8 *sender)
{
/* Incase supplicant wants drivers to skip this BSS, return false */
struct wpa_bss *bss = wpa_bss_get_bssid(&g_wpa_supp, sender);
if (!bss) {
return true;
}
const u8 *assoc_disallow = wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_ASSOC_DISALLOW);
if (assoc_disallow && assoc_disallow[1] >= 1) {
wpa_printf(MSG_DEBUG,
"skip - MBO association disallowed (reason %u)", assoc_disallow[2]);
return false;
}
if (wpa_is_bss_tmp_disallowed(&g_wpa_supp, bss)) {
wpa_printf(MSG_DEBUG,
"skip - BSS is temporary disallowed");
return false;
}
return true;
}
#endif /* CONFIG_MBO */
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
int esp_supplicant_common_init(struct wpa_funcs *wpa_cb)
{
struct wpa_supplicant *wpa_s = &g_wpa_supp;
int ret;
#if defined(CONFIG_WPA_11KV_SUPPORT)
if (!s_supplicant_api_lock) {
s_supplicant_api_lock = xSemaphoreCreateRecursiveMutex();
}
if (!s_supplicant_api_lock) {
wpa_printf(MSG_ERROR, "%s: failed to create Supplicant API lock", __func__);
ret = -1;
goto err;
}
s_supplicant_evt_queue = xQueueCreate(3, sizeof(supplicant_event_t));
if (!s_supplicant_evt_queue) {
wpa_printf(MSG_ERROR, "%s: failed to create Supplicant event queue", __func__);
ret = -1;
goto err;
}
ret = xTaskCreate(btm_rrm_task, "btm_rrm_t", SUPPLICANT_TASK_STACK_SIZE, NULL, 2, &s_supplicant_task_hdl);
if (ret != pdPASS) {
wpa_printf(MSG_ERROR, "btm: failed to create task");
ret = -1;
goto err;
}
s_supplicant_task_init_done = true;
esp_scan_init(wpa_s);
wpas_rrm_reset(wpa_s);
wpas_clear_beacon_rep_data(wpa_s);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
wpa_s->type = 0;
wpa_s->subtype = 0;
wpa_s->type |= (1 << WLAN_FC_STYPE_ASSOC_RESP) | (1 << WLAN_FC_STYPE_REASSOC_RESP) | (1 << WLAN_FC_STYPE_AUTH);
if (esp_wifi_register_mgmt_frame_internal(wpa_s->type, wpa_s->subtype) != ESP_OK) {
ret = -1;
goto err;
}
wpa_cb->wpa_sta_rx_mgmt = ieee80211_handle_rx_frm;
#if defined(CONFIG_WPA_11KV_SUPPORT)
/* Matching is done only for MBO at the moment, this can be extended for other features*/
#ifdef CONFIG_MBO
wpa_cb->wpa_sta_profile_match = bss_profile_match;
dl_list_init(&wpa_s->bss_tmp_disallowed);
#else
wpa_cb->wpa_sta_profile_match = NULL;
#endif
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
return 0;
err:
esp_supplicant_common_deinit();
return ret;
}
void esp_supplicant_common_deinit(void)
{
struct wpa_supplicant *wpa_s = &g_wpa_supp;
#if defined(CONFIG_WPA_11KV_SUPPORT)
esp_scan_deinit(wpa_s);
wpas_rrm_reset(wpa_s);
wpas_clear_beacon_rep_data(wpa_s);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
if (wpa_s->type) {
wpa_s->type = 0;
esp_wifi_register_mgmt_frame_internal(wpa_s->type, wpa_s->subtype);
}
#if defined(CONFIG_WPA_11KV_SUPPORT)
if (!s_supplicant_task_hdl) {
/*We have failed to create a task, delete queue and exit*/
if (s_supplicant_evt_queue) {
vQueueDelete(s_supplicant_evt_queue);
s_supplicant_evt_queue = NULL;
}
}else if (esp_supplicant_post_evt(SIG_SUPPLICANT_DEL_TASK, 0) != 0) {
/*Failed to post delete event, just delete the event queue and exit*/
if (s_supplicant_evt_queue) {
vQueueDelete(s_supplicant_evt_queue);
s_supplicant_evt_queue = NULL;
}
wpa_printf(MSG_ERROR, "failed to send task delete event");
}
s_supplicant_task_init_done = false;
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
}
void supplicant_sta_conn_handler(uint8_t *bssid)
{
#if defined(CONFIG_WPA_11KV_SUPPORT)
u8 *ie;
struct wpa_supplicant *wpa_s = &g_wpa_supp;
struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, bssid);
if (!bss) {
wpa_printf(MSG_INFO, "connected bss entry not present in scan cache");
return;
}
wpa_s->current_bss = bss;
ie = (u8 *)bss;
ie += sizeof(struct wpa_bss);
ieee802_11_parse_elems(wpa_s, ie, bss->ie_len);
wpa_bss_flush(wpa_s);
/* Register for action frames */
register_action_frame(wpa_s);
/* clear set bssid flag */
clear_bssid_flag(wpa_s);
#endif /* defined(CONFIG_WPA_11KV_SUPPORT)*/
}
void supplicant_sta_disconn_handler(void)
{
#if defined(CONFIG_WPA_11KV_SUPPORT)
struct wpa_supplicant *wpa_s = &g_wpa_supp;
wpas_rrm_reset(wpa_s);
if (wpa_s->current_bss) {
wpa_s->current_bss = NULL;
}
#endif /* defined(CONFIG_WPA_11KV_SUPPORT) */
}
#if defined(CONFIG_WPA_11KV_SUPPORT)
bool esp_rrm_is_rrm_supported_connection(void)
{
struct wpa_supplicant *wpa_s = &g_wpa_supp;
if (!wpa_s->current_bss) {
wpa_printf(MSG_DEBUG, "STA not associated, return");
return false;
}
if (!(wpa_s->rrm_ie[0] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
wpa_printf(MSG_DEBUG,
"RRM: No network support for Neighbor Report.");
return false;
}
return true;
}
int esp_rrm_send_neighbor_rep_request(neighbor_rep_request_cb cb,
void *cb_ctx)
{
struct wpa_supplicant *wpa_s = &g_wpa_supp;
struct wpa_ssid_value wpa_ssid = {0};
struct wifi_ssid *ssid;
if (!wpa_s->current_bss) {
wpa_printf(MSG_ERROR, "STA not associated, return");
return -2;
}
if (!(wpa_s->rrm_ie[0] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
wpa_printf(MSG_ERROR,
"RRM: No network support for Neighbor Report.");
return -1;
}
ssid = esp_wifi_sta_get_prof_ssid_internal();
os_memcpy(wpa_ssid.ssid, ssid->ssid, ssid->len);
wpa_ssid.ssid_len = ssid->len;
return wpas_rrm_send_neighbor_rep_request(wpa_s, &wpa_ssid, 0, 0, cb, cb_ctx);
}
bool esp_wnm_is_btm_supported_connection(void)
{
struct wpa_supplicant *wpa_s = &g_wpa_supp;
if (!wpa_s->current_bss) {
wpa_printf(MSG_DEBUG, "STA not associated, return");
return false;
}
if (!wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_BSS_TRANSITION)) {
wpa_printf(MSG_DEBUG, "AP doesn't support BTM, return");
return false;
}
return true;
}
int esp_wnm_send_bss_transition_mgmt_query(enum btm_query_reason query_reason,
const char *btm_candidates,
int cand_list)
{
struct wpa_supplicant *wpa_s = &g_wpa_supp;
if (!wpa_s->current_bss) {
wpa_printf(MSG_ERROR, "STA not associated, return");
return -2;
}
if (!wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_BSS_TRANSITION)) {
wpa_printf(MSG_ERROR, "AP doesn't support BTM, return");
return -1;
}
return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason, btm_candidates, cand_list);
}
int esp_mbo_update_non_pref_chan(struct non_pref_chan_s *non_pref_chan)
{
int ret = wpas_mbo_update_non_pref_chan(&g_wpa_supp, non_pref_chan);
return ret;
}
void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
struct wpa_bss *bss, char *ssid)
{
wifi_config_t *config = os_zalloc(sizeof(wifi_config_t));
if (!config) {
wpa_printf(MSG_ERROR, "failed to allocate memory");
return;
}
esp_wifi_get_config(WIFI_IF_STA, config);
/* We only support roaming in same ESS, therefore only bssid setting is needed */
os_memcpy(config->sta.bssid, bss->bssid, ETH_ALEN);
config->sta.bssid_set = 1;
/* supplicant connect will only be called in case of bss transition(roaming) */
esp_wifi_internal_issue_disconnect(WIFI_REASON_BSS_TRANSITION_DISASSOC);
esp_wifi_set_config(WIFI_IF_STA, config);
os_free(config);
esp_wifi_connect();
}
static size_t get_rm_enabled_ie(uint8_t *ie, size_t len)
{
uint8_t rrm_ie[7] = {0};
uint8_t rrm_ie_len = 5;
uint8_t *pos = rrm_ie;
if (!esp_wifi_is_rm_enabled_internal(WIFI_IF_STA)) {
return 0;
}
*pos++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
*pos++ = rrm_ie_len;
*pos |= WLAN_RRM_CAPS_LINK_MEASUREMENT;
*pos |= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
#ifdef SCAN_CACHE_SUPPORTED
WLAN_RRM_CAPS_BEACON_REPORT_TABLE |
#endif /* SCAN_CACHE_SUPPORTED */
WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE;
os_memcpy(ie, rrm_ie, sizeof(rrm_ie));
return rrm_ie_len + 2;
}
#ifdef CONFIG_MBO
static size_t get_mbo_oce_scan_ie(uint8_t *ie, size_t len)
{
uint8_t mbo_ie[32] = {0};
uint8_t mbo_ie_len = 32;
/* Return if MBO IE is not enabled in driver */
if (!esp_wifi_is_mbo_enabled_internal(WIFI_IF_STA)) {
return 0;
}
struct wpabuf *default_ies = NULL;
if (wpabuf_resize(&default_ies, 18) == 0) {
wpas_mbo_scan_ie(&g_wpa_supp, default_ies);
os_memcpy(mbo_ie, wpabuf_head_u8(default_ies), wpabuf_len(default_ies));
mbo_ie_len = wpabuf_len(default_ies);
wpabuf_free(default_ies);
}
os_memcpy(ie, mbo_ie, mbo_ie_len);
return mbo_ie_len;
}
static size_t get_mbo_oce_assoc_ie(uint8_t *ie, size_t len)
{
uint8_t mbo_ie[32] = {0};
uint8_t mbo_ie_len = 32;
/* Return if MBO IE is not enabled in driver */
if (!esp_wifi_is_mbo_enabled_internal(WIFI_IF_STA)) {
return 0;
}
mbo_ie_len = wpas_mbo_ie(&g_wpa_supp, mbo_ie, mbo_ie_len, 0);
os_memcpy(ie, mbo_ie, mbo_ie_len);
return mbo_ie_len;
}
#endif
#endif
static uint8_t get_extended_caps_ie(uint8_t *ie, size_t len)
{
uint8_t ext_caps_ie[5] = {0};
uint8_t ext_caps_ie_len = 3;
uint8_t *pos = ext_caps_ie;
wifi_ioctl_config_t cfg = {0};
if (!esp_wifi_is_btm_enabled_internal(WIFI_IF_STA)) {
return 0;
}
*pos++ = WLAN_EID_EXT_CAPAB;
*pos++ = ext_caps_ie_len;
esp_err_t err = esp_wifi_internal_ioctl(WIFI_IOCTL_GET_STA_HT2040_COEX, &cfg);
if (err == ESP_OK && cfg.data.ht2040_coex.enable) {
*pos++ |= BIT(WLAN_EXT_CAPAB_20_40_COEX);
} else {
*pos++ = 0;
}
*pos++ = 0;
#define CAPAB_BSS_TRANSITION BIT(3)
*pos |= CAPAB_BSS_TRANSITION;
#undef CAPAB_BSS_TRANSITION
os_memcpy(ie, ext_caps_ie, sizeof(ext_caps_ie));
return ext_caps_ie_len + 2;
}
#if defined(CONFIG_WPA_11KV_SUPPORT)
static uint8_t get_operating_class_ie(uint8_t *ie, size_t len)
{
uint8_t op_class_ie[4] = {0};
uint8_t op_class_ie_len = 2;
uint8_t *pos = op_class_ie;
*pos++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
*pos++ = op_class_ie_len;
#define OPER_CLASS 0x51
/* Current Operating Class */
*pos++ = OPER_CLASS;
#undef OPER_CLASS
*pos = 0;
os_memcpy(ie, op_class_ie, sizeof(op_class_ie));
return op_class_ie_len + 2;
}
void esp_set_scan_ie(void)
{
#define SCAN_IE_LEN 64
uint8_t *ie, *pos;
size_t len = SCAN_IE_LEN, ie_len;
ie = os_malloc(SCAN_IE_LEN);
if (!ie) {
wpa_printf(MSG_ERROR, "failed to allocate ie");
return;
}
pos = ie;
ie_len = get_extended_caps_ie(pos, len);
pos += ie_len;
len -= ie_len;
#ifdef CONFIG_MBO
ie_len = get_mbo_oce_scan_ie(pos, len);
pos += ie_len;
len -= ie_len;
#endif /* CONFIG_MBO */
esp_wifi_unset_appie_internal(WIFI_APPIE_PROBEREQ);
esp_wifi_set_appie_internal(WIFI_APPIE_PROBEREQ, ie, SCAN_IE_LEN - len, 0);
os_free(ie);
#undef SCAN_IE_LEN
}
#endif
void esp_set_assoc_ie(uint8_t *bssid, const u8 *ies, size_t ies_len, bool mdie)
{
#define ASSOC_IE_LEN 128
uint8_t *ie, *pos;
size_t len = ASSOC_IE_LEN, ie_len;
ie = os_malloc(ASSOC_IE_LEN + ies_len);
if (!ie) {
wpa_printf(MSG_ERROR, "failed to allocate ie");
return;
}
pos = ie;
ie_len = get_extended_caps_ie(pos, len);
pos += ie_len;
len -= ie_len;
#ifdef CONFIG_WPA_11KV_SUPPORT
ie_len = get_rm_enabled_ie(pos, len);
pos += ie_len;
len -= ie_len;
#ifdef CONFIG_MBO
ie_len = get_operating_class_ie(pos, len);
pos += ie_len;
len -= ie_len;
ie_len = get_mbo_oce_assoc_ie(pos, len);
pos += ie_len;
len -= ie_len;
#endif /* CONFIG_MBO */
#endif
if (ies_len) {
os_memcpy(pos, ies, ies_len);
pos += ies_len;
len -= ies_len;
}
esp_wifi_unset_appie_internal(WIFI_APPIE_ASSOC_REQ);
esp_wifi_set_appie_internal(WIFI_APPIE_ASSOC_REQ, ie, ASSOC_IE_LEN - len, 0);
os_free(ie);
#undef ASSOC_IE_LEN
}
#ifdef CONFIG_WPA_11KV_SUPPORT
void esp_get_tx_power(uint8_t *tx_power)
{
#define DEFAULT_MAX_TX_POWER 19 /* max tx power is 19.5 dbm */
s8 power;
/* esp sends management frames at max tx power configured */
int ret = esp_wifi_get_max_tx_power(&power);
if (ret != 0) {
wpa_printf(MSG_ERROR, "failed to get tx power");
*tx_power = DEFAULT_MAX_TX_POWER;
return;
}
*tx_power = power/4;
#undef DEFAULT_MAX_TX_POWER
}
int wpa_drv_send_action(struct wpa_supplicant *wpa_s,
unsigned int channel,
unsigned int wait,
const u8 *data, size_t data_len,
int no_cck)
{
int ret = 0;
wifi_mgmt_frm_req_t *req = os_zalloc(sizeof(*req) + data_len);;
if (!req)
return -1;
if (!wpa_s->current_bss) {
wpa_printf(MSG_ERROR, "STA not associated, return");
ret = -1;
goto cleanup;
}
req->ifx = WIFI_IF_STA;
req->subtype = WLAN_FC_STYPE_ACTION;
req->data_len = data_len;
os_memcpy(req->data, data, req->data_len);
if (esp_wifi_send_mgmt_frm_internal(req) != 0) {
wpa_printf(MSG_ERROR, "action frame sending failed");
ret = -1;
goto cleanup;
}
wpa_printf(MSG_INFO, "action frame sent");
cleanup:
os_free(req);
return ret;
}
int esp_supplicant_post_evt(uint32_t evt_id, uint32_t data)
{
supplicant_event_t *evt = os_zalloc(sizeof(supplicant_event_t));
if (!evt) {
wpa_printf(MSG_ERROR, "Failed to allocate memory.");
return -1;
}
evt->id = evt_id;
evt->data = data;
SUPPLICANT_API_LOCK();
/*Make sure no event can be sent when deletion event is sent or the task is not initialized*/
if (!s_supplicant_task_init_done) {
SUPPLICANT_API_UNLOCK();
os_free(evt);
return -1;
}
if (xQueueSend(s_supplicant_evt_queue, &evt, 10 / portTICK_PERIOD_MS ) != pdPASS) {
SUPPLICANT_API_UNLOCK();
os_free(evt);
return -1;
}
if (evt_id == SIG_SUPPLICANT_DEL_TASK) {
s_supplicant_task_init_done = false;
}
SUPPLICANT_API_UNLOCK();
return 0;
}
#endif