/
wifi_mgmt.c
749 lines (636 loc) · 19.4 KB
/
wifi_mgmt.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
739
740
741
742
743
744
745
746
747
748
749
/*
* Copyright (c) 2016 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL);
#include <errno.h>
#include <string.h>
#include <zephyr/net/net_core.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/wifi_mgmt.h>
#ifdef CONFIG_WIFI_NM
#include <zephyr/net/wifi_nm.h>
#endif /* CONFIG_WIFI_NM */
const char * const wifi_security_txt(enum wifi_security_type security)
{
switch (security) {
case WIFI_SECURITY_TYPE_NONE:
return "OPEN";
case WIFI_SECURITY_TYPE_WEP:
return "WEP";
case WIFI_SECURITY_TYPE_WPA_PSK:
return "WPA-PSK";
case WIFI_SECURITY_TYPE_PSK:
return "WPA2-PSK";
case WIFI_SECURITY_TYPE_PSK_SHA256:
return "WPA2-PSK-SHA256";
case WIFI_SECURITY_TYPE_SAE:
return "WPA3-SAE";
case WIFI_SECURITY_TYPE_WAPI:
return "WAPI";
case WIFI_SECURITY_TYPE_EAP:
return "EAP";
case WIFI_SECURITY_TYPE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char * const wifi_mfp_txt(enum wifi_mfp_options mfp)
{
switch (mfp) {
case WIFI_MFP_DISABLE:
return "Disable";
case WIFI_MFP_OPTIONAL:
return "Optional";
case WIFI_MFP_REQUIRED:
return "Required";
case WIFI_MFP_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char * const wifi_band_txt(enum wifi_frequency_bands band)
{
switch (band) {
case WIFI_FREQ_BAND_2_4_GHZ:
return "2.4GHz";
case WIFI_FREQ_BAND_5_GHZ:
return "5GHz";
case WIFI_FREQ_BAND_6_GHZ:
return "6GHz";
case WIFI_FREQ_BAND_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char * const wifi_state_txt(enum wifi_iface_state state)
{
switch (state) {
case WIFI_STATE_DISCONNECTED:
return "DISCONNECTED";
case WIFI_STATE_INACTIVE:
return "INACTIVE";
case WIFI_STATE_INTERFACE_DISABLED:
return "INTERFACE_DISABLED";
case WIFI_STATE_SCANNING:
return "SCANNING";
case WIFI_STATE_AUTHENTICATING:
return "AUTHENTICATING";
case WIFI_STATE_ASSOCIATING:
return "ASSOCIATING";
case WIFI_STATE_ASSOCIATED:
return "ASSOCIATED";
case WIFI_STATE_4WAY_HANDSHAKE:
return "4WAY_HANDSHAKE";
case WIFI_STATE_GROUP_HANDSHAKE:
return "GROUP_HANDSHAKE";
case WIFI_STATE_COMPLETED:
return "COMPLETED";
case WIFI_STATE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char * const wifi_mode_txt(enum wifi_iface_mode mode)
{
switch (mode) {
case WIFI_MODE_INFRA:
return "STATION";
case WIFI_MODE_IBSS:
return "ADHOC";
case WIFI_MODE_AP:
return "ACCESS POINT";
case WIFI_MODE_P2P_GO:
return "P2P GROUP OWNER";
case WIFI_MODE_P2P_GROUP_FORMATION:
return "P2P GROUP FORMATION";
case WIFI_MODE_MESH:
return "MESH";
case WIFI_MODE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char * const wifi_link_mode_txt(enum wifi_link_mode link_mode)
{
switch (link_mode) {
case WIFI_0:
return "WIFI 0 (802.11)";
case WIFI_1:
return "WIFI 1 (802.11b)";
case WIFI_2:
return "WIFI 2 (802.11a)";
case WIFI_3:
return "WIFI 3 (802.11g)";
case WIFI_4:
return "WIFI 4 (802.11n/HT)";
case WIFI_5:
return "WIFI 5 (802.11ac/VHT)";
case WIFI_6:
return "WIFI 6 (802.11ax/HE)";
case WIFI_6E:
return "WIFI 6E (802.11ax 6GHz/HE)";
case WIFI_7:
return "WIFI 7 (802.11be/EHT)";
case WIFI_LINK_MODE_UNKNOWN:
default:
return "UNKNOWN";
}
}
const char * const wifi_ps_txt(enum wifi_ps ps_name)
{
switch (ps_name) {
case WIFI_PS_DISABLED:
return "Power save disabled";
case WIFI_PS_ENABLED:
return "Power save enabled";
default:
return "UNKNOWN";
}
}
const char * const wifi_ps_mode_txt(enum wifi_ps_mode ps_mode)
{
switch (ps_mode) {
case WIFI_PS_MODE_LEGACY:
return "Legacy power save";
case WIFI_PS_MODE_WMM:
return "WMM power save";
default:
return "UNKNOWN";
}
}
const char * const wifi_twt_operation_txt(enum wifi_twt_operation twt_operation)
{
switch (twt_operation) {
case WIFI_TWT_SETUP:
return "TWT setup";
case WIFI_TWT_TEARDOWN:
return "TWT teardown";
default:
return "UNKNOWN";
}
}
const char * const wifi_twt_negotiation_type_txt(enum wifi_twt_negotiation_type twt_negotiation)
{
switch (twt_negotiation) {
case WIFI_TWT_INDIVIDUAL:
return "TWT individual negotiation";
case WIFI_TWT_BROADCAST:
return "TWT broadcast negotiation";
case WIFI_TWT_WAKE_TBTT:
return "TWT wake TBTT negotiation";
default:
return "UNKNOWN";
}
}
const char * const wifi_twt_setup_cmd_txt(enum wifi_twt_setup_cmd twt_setup)
{
switch (twt_setup) {
case WIFI_TWT_SETUP_CMD_REQUEST:
return "TWT request";
case WIFI_TWT_SETUP_CMD_SUGGEST:
return "TWT suggest";
case WIFI_TWT_SETUP_CMD_DEMAND:
return "TWT demand";
case WIFI_TWT_SETUP_CMD_GROUPING:
return "TWT grouping";
case WIFI_TWT_SETUP_CMD_ACCEPT:
return "TWT accept";
case WIFI_TWT_SETUP_CMD_ALTERNATE:
return "TWT alternate";
case WIFI_TWT_SETUP_CMD_DICTATE:
return "TWT dictate";
case WIFI_TWT_SETUP_CMD_REJECT:
return "TWT reject";
default:
return "UNKNOWN";
}
}
const char * const wifi_ps_wakeup_mode_txt(enum wifi_ps_wakeup_mode ps_wakeup_mode)
{
switch (ps_wakeup_mode) {
case WIFI_PS_WAKEUP_MODE_DTIM:
return "PS wakeup mode DTIM";
case WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL:
return "PS wakeup mode listen interval";
default:
return "UNKNOWN";
}
}
static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface)
{
const struct device *dev = net_if_get_device(iface);
struct net_wifi_mgmt_offload *off_api =
(struct net_wifi_mgmt_offload *) dev->api;
#ifdef CONFIG_WIFI_NM
struct wifi_nm_instance *nm = wifi_nm_get_instance_iface(iface);
if (nm) {
return nm->ops;
}
#endif /* CONFIG_WIFI_NM */
return off_api ? off_api->wifi_mgmt_api : NULL;
}
static int wifi_connect(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
struct wifi_connect_req_params *params =
(struct wifi_connect_req_params *)data;
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
if (wifi_mgmt_api == NULL || wifi_mgmt_api->connect == NULL) {
return -ENOTSUP;
}
LOG_HEXDUMP_DBG(params->ssid, params->ssid_length, "ssid");
LOG_HEXDUMP_DBG(params->psk, params->psk_length, "psk");
if (params->sae_password) {
LOG_HEXDUMP_DBG(params->sae_password, params->sae_password_length, "sae");
}
NET_DBG("ch %u sec %u", params->channel, params->security);
if ((params->security > WIFI_SECURITY_TYPE_MAX) ||
(params->ssid_length > WIFI_SSID_MAX_LEN) ||
(params->ssid_length == 0U) ||
((params->security == WIFI_SECURITY_TYPE_PSK ||
params->security == WIFI_SECURITY_TYPE_WPA_PSK ||
params->security == WIFI_SECURITY_TYPE_PSK_SHA256) &&
((params->psk_length < 8) || (params->psk_length > 64) ||
(params->psk_length == 0U) || !params->psk)) ||
((params->security == WIFI_SECURITY_TYPE_SAE) &&
((params->psk_length == 0U) || !params->psk) &&
((params->sae_password_length == 0U) || !params->sae_password)) ||
((params->channel != WIFI_CHANNEL_ANY) &&
(params->channel > WIFI_CHANNEL_MAX)) ||
!params->ssid) {
return -EINVAL;
}
return wifi_mgmt_api->connect(dev, params);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONNECT, wifi_connect);
static void scan_result_cb(struct net_if *iface, int status,
struct wifi_scan_result *entry)
{
if (!iface) {
return;
}
if (!entry) {
struct wifi_status scan_status = {
.status = status,
};
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_SCAN_DONE,
iface, &scan_status,
sizeof(struct wifi_status));
return;
}
#ifndef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_SCAN_RESULT, iface,
entry, sizeof(struct wifi_scan_result));
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS_ONLY */
}
static int wifi_scan(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
struct wifi_scan_params *params = data;
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
if (wifi_mgmt_api == NULL || wifi_mgmt_api->scan == NULL) {
return -ENOTSUP;
}
#ifdef CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN
struct wifi_scan_params default_params = {0};
if (params == NULL) {
params = &default_params;
}
params->scan_type = WIFI_SCAN_TYPE_PASSIVE;
#endif /* CONFIG_WIFI_MGMT_FORCED_PASSIVE_SCAN */
return wifi_mgmt_api->scan(dev, params, scan_result_cb);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_SCAN, wifi_scan);
static int wifi_disconnect(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
if (wifi_mgmt_api == NULL || wifi_mgmt_api->disconnect == NULL) {
return -ENOTSUP;
}
return wifi_mgmt_api->disconnect(dev);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_DISCONNECT, wifi_disconnect);
void wifi_mgmt_raise_connect_result_event(struct net_if *iface, int status)
{
struct wifi_status cnx_status = {
.status = status,
};
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_CONNECT_RESULT,
iface, &cnx_status,
sizeof(struct wifi_status));
}
void wifi_mgmt_raise_disconnect_result_event(struct net_if *iface, int status)
{
struct wifi_status cnx_status = {
.status = status,
};
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_DISCONNECT_RESULT,
iface, &cnx_status,
sizeof(struct wifi_status));
}
static int wifi_ap_enable(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
struct wifi_connect_req_params *params =
(struct wifi_connect_req_params *)data;
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
if (wifi_mgmt_api == NULL || wifi_mgmt_api->ap_enable == NULL) {
return -ENOTSUP;
}
return wifi_mgmt_api->ap_enable(dev, params);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_ENABLE, wifi_ap_enable);
static int wifi_ap_disable(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
if (wifi_mgmt_api == NULL || wifi_mgmt_api->ap_enable == NULL) {
return -ENOTSUP;
}
return wifi_mgmt_api->ap_disable(dev);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_DISABLE, wifi_ap_disable);
static int wifi_iface_status(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_iface_status *status = data;
if (wifi_mgmt_api == NULL || wifi_mgmt_api->iface_status == NULL) {
return -ENOTSUP;
}
if (!data || len != sizeof(*status)) {
return -EINVAL;
}
return wifi_mgmt_api->iface_status(dev, status);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_IFACE_STATUS, wifi_iface_status);
void wifi_mgmt_raise_iface_status_event(struct net_if *iface,
struct wifi_iface_status *iface_status)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_IFACE_STATUS,
iface, iface_status,
sizeof(struct wifi_iface_status));
}
#ifdef CONFIG_NET_STATISTICS_WIFI
static int wifi_iface_stats(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct net_stats_wifi *stats = data;
if (wifi_mgmt_api == NULL || wifi_mgmt_api->get_stats == NULL) {
return -ENOTSUP;
}
if (!data || len != sizeof(*stats)) {
return -EINVAL;
}
return wifi_mgmt_api->get_stats(dev, stats);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_WIFI, wifi_iface_stats);
#endif /* CONFIG_NET_STATISTICS_WIFI */
static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_ps_params *ps_params = data;
struct wifi_iface_status info = { 0 };
if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_power_save == NULL) {
return -ENOTSUP;
}
switch (ps_params->type) {
case WIFI_PS_PARAM_LISTEN_INTERVAL:
case WIFI_PS_PARAM_MODE:
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
sizeof(struct wifi_iface_status))) {
ps_params->fail_reason =
WIFI_PS_PARAM_FAIL_UNABLE_TO_GET_IFACE_STATUS;
return -EIO;
}
if (info.state == WIFI_STATE_COMPLETED) {
ps_params->fail_reason =
WIFI_PS_PARAM_FAIL_DEVICE_CONNECTED;
return -ENOTSUP;
}
break;
case WIFI_PS_PARAM_STATE:
case WIFI_PS_PARAM_WAKEUP_MODE:
case WIFI_PS_PARAM_TIMEOUT:
break;
default:
ps_params->fail_reason =
WIFI_PS_PARAM_FAIL_OPERATION_NOT_SUPPORTED;
return -ENOTSUP;
}
return wifi_mgmt_api->set_power_save(dev, ps_params);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PS, wifi_set_power_save);
static int wifi_get_power_save_config(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_ps_config *ps_config = data;
if (wifi_mgmt_api == NULL || wifi_mgmt_api->get_power_save_config == NULL) {
return -ENOTSUP;
}
if (!data || len != sizeof(*ps_config)) {
return -EINVAL;
}
return wifi_mgmt_api->get_power_save_config(dev, ps_config);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_CONFIG, wifi_get_power_save_config);
static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_twt_params *twt_params = data;
struct wifi_iface_status info = { 0 };
if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_twt == NULL) {
twt_params->fail_reason =
WIFI_TWT_FAIL_OPERATION_NOT_SUPPORTED;
return -ENOTSUP;
}
if (twt_params->operation == WIFI_TWT_TEARDOWN) {
return wifi_mgmt_api->set_twt(dev, twt_params);
}
if (net_mgmt(NET_REQUEST_WIFI_IFACE_STATUS, iface, &info,
sizeof(struct wifi_iface_status))) {
twt_params->fail_reason =
WIFI_TWT_FAIL_UNABLE_TO_GET_IFACE_STATUS;
goto fail;
}
if (info.state != WIFI_STATE_COMPLETED) {
twt_params->fail_reason =
WIFI_TWT_FAIL_DEVICE_NOT_CONNECTED;
goto fail;
}
#ifdef CONFIG_WIFI_MGMT_TWT_CHECK_IP
if ((!net_if_ipv4_get_global_addr(iface, NET_ADDR_PREFERRED)) &&
(!net_if_ipv6_get_global_addr(NET_ADDR_PREFERRED, &iface))) {
twt_params->fail_reason =
WIFI_TWT_FAIL_IP_NOT_ASSIGNED;
goto fail;
}
#else
NET_WARN("Check for valid IP address been disabled. "
"Device might be unreachable or might not receive traffic.\n");
#endif /* CONFIG_WIFI_MGMT_TWT_CHECK_IP */
if (info.link_mode < WIFI_6) {
twt_params->fail_reason =
WIFI_TWT_FAIL_PEER_NOT_HE_CAPAB;
goto fail;
}
if (!info.twt_capable) {
twt_params->fail_reason =
WIFI_TWT_FAIL_PEER_NOT_TWT_CAPAB;
goto fail;
}
return wifi_mgmt_api->set_twt(dev, twt_params);
fail:
return -ENOEXEC;
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_TWT, wifi_set_twt);
void wifi_mgmt_raise_twt_event(struct net_if *iface, struct wifi_twt_params *twt_params)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_TWT,
iface, twt_params,
sizeof(struct wifi_twt_params));
}
static int wifi_reg_domain(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_reg_domain *reg_domain = data;
if (wifi_mgmt_api == NULL || wifi_mgmt_api->reg_domain == NULL) {
return -ENOTSUP;
}
if (!data || len != sizeof(*reg_domain)) {
return -EINVAL;
}
return wifi_mgmt_api->reg_domain(dev, reg_domain);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_REG_DOMAIN, wifi_reg_domain);
void wifi_mgmt_raise_twt_sleep_state(struct net_if *iface,
int twt_sleep_state)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_TWT_SLEEP_STATE,
iface, &twt_sleep_state,
sizeof(twt_sleep_state));
}
static int wifi_mode(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_mode_info *mode_info = data;
if (dev == NULL) {
return -ENODEV;
}
if (wifi_mgmt_api == NULL || wifi_mgmt_api->mode == NULL) {
return -ENOTSUP;
}
return wifi_mgmt_api->mode(dev, mode_info);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_MODE, wifi_mode);
static int wifi_packet_filter(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_filter_info *filter_info = data;
if (dev == NULL) {
return -ENODEV;
}
if (wifi_mgmt_api == NULL || wifi_mgmt_api->filter == NULL) {
return -ENOTSUP;
}
return wifi_mgmt_api->filter(dev, filter_info);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER, wifi_packet_filter);
static int wifi_channel(uint32_t mgmt_request, struct net_if *iface,
void *data, size_t len)
{
const struct device *dev = net_if_get_device(iface);
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
struct wifi_channel_info *channel_info = data;
if (dev == NULL) {
return -ENODEV;
}
if (wifi_mgmt_api == NULL || wifi_mgmt_api->channel == NULL) {
return -ENOTSUP;
}
return wifi_mgmt_api->channel(dev, channel_info);
}
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL, wifi_channel);
#ifdef CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS
void wifi_mgmt_raise_raw_scan_result_event(struct net_if *iface,
struct wifi_raw_scan_result *raw_scan_result)
{
if (raw_scan_result->frame_length > CONFIG_WIFI_MGMT_RAW_SCAN_RESULT_LENGTH) {
LOG_INF("raw scan result frame length = %d too big,"
"saving upto max raw scan length = %d",
raw_scan_result->frame_length,
CONFIG_WIFI_MGMT_RAW_SCAN_RESULT_LENGTH);
}
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_RAW_SCAN_RESULT,
iface, raw_scan_result,
sizeof(*raw_scan_result));
}
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
void wifi_mgmt_raise_disconnect_complete_event(struct net_if *iface,
int status)
{
struct wifi_status cnx_status = {
.status = status,
};
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_DISCONNECT_COMPLETE,
iface, &cnx_status,
sizeof(struct wifi_status));
}
void wifi_mgmt_raise_ap_enable_result_event(struct net_if *iface,
enum wifi_ap_status status)
{
struct wifi_status cnx_status = {
.status = status,
};
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_ENABLE_RESULT,
iface, &cnx_status,
sizeof(enum wifi_ap_status));
}
void wifi_mgmt_raise_ap_disable_result_event(struct net_if *iface,
enum wifi_ap_status status)
{
struct wifi_status cnx_status = {
.status = status,
};
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_DISABLE_RESULT,
iface, &cnx_status,
sizeof(enum wifi_ap_status));
}
void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface,
struct wifi_ap_sta_info *sta_info)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_CONNECTED,
iface, sta_info,
sizeof(struct wifi_ap_sta_info));
}
void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface,
struct wifi_ap_sta_info *sta_info)
{
net_mgmt_event_notify_with_info(NET_EVENT_WIFI_AP_STA_DISCONNECTED,
iface, sta_info,
sizeof(struct wifi_ap_sta_info));
}