idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
wifi.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
22#include <idfxx/cpu>
23#include <idfxx/error>
24#include <idfxx/event>
25#include <idfxx/flags>
26#include <idfxx/mac>
27#include <idfxx/netif>
28
29#include <array>
30#include <cstdint>
31#include <optional>
32#include <soc/soc_caps.h>
33#include <span>
34#include <string>
35#include <string_view>
36#include <vector>
37
38namespace idfxx::wifi {
39
40// =============================================================================
41// Enumerations
42// =============================================================================
43
52enum class role : int {
53 // clang-format off
54 sta = 1,
55 ap = 2,
56 // clang-format on
57};
58
63enum class auth_mode : int {
64 // clang-format off
65 open = 0,
66 wep = 1,
67 wpa_psk = 2,
68 wpa2_psk = 3,
69 wpa_wpa2_psk = 4,
70 wpa2_enterprise = 5,
71 wpa3_psk = 6,
72 wpa2_wpa3_psk = 7,
73 wapi_psk = 8,
74 owe = 9,
75 wpa3_ent_192 = 10,
76 dpp = 13,
77 wpa3_enterprise = 14,
79 wpa_enterprise = 16,
80 // clang-format on
81};
82
87enum class power_save : int {
88 // clang-format off
89 none = 0,
90 min_modem = 1,
91 max_modem = 2,
92 // clang-format on
93};
94
99enum class bandwidth : int {
100 // clang-format off
101 ht20 = 1,
102 ht40 = 2,
103 bw80 = 3,
104 bw160 = 4,
105 bw80_80 = 5,
106 // clang-format on
107};
108
113enum class scan_type : int {
114 // clang-format off
115 active = 0,
116 passive = 1,
117 // clang-format on
118};
119
124enum class second_channel : int {
125 // clang-format off
126 above = 1,
127 below = 2,
128 // clang-format on
129};
130
135enum class sort_method : int {
136 // clang-format off
137 by_rssi = 0,
138 by_security = 1,
139 // clang-format on
140};
141
150 // clang-format off
151 // IEEE 802.11 standard reasons
152 unspecified = 1,
153 auth_expire = 2,
154 auth_leave = 3,
155 assoc_expire = 4,
156 assoc_toomany = 5,
157 not_authed = 6,
158 not_assoced = 7,
159 assoc_leave = 8,
160 assoc_not_authed = 9,
164 ie_invalid = 13,
165 mic_failure = 14,
168 ie_in_4way_differs = 17,
171 akmp_invalid = 20,
173 invalid_rsn_ie_cap = 22,
177 tdls_unspecified = 26,
180 bad_cipher_or_akm = 29,
183 unspecified_qos = 32,
185 missing_acks = 34,
186 exceeded_txop = 35,
187 sta_leaving = 36,
188 end_ba = 37,
189 unknown_ba = 38,
190 timeout = 39,
191 peer_initiated = 46,
192 ap_initiated = 47,
194 invalid_pmkid = 49,
195 invalid_mde = 50,
196 invalid_fte = 51,
200 // Vendor-specific reasons (200+)
201 beacon_timeout = 200,
202 no_ap_found = 201,
203 auth_fail = 202,
204 assoc_fail = 203,
205 handshake_timeout = 204,
206 connection_fail = 205,
207 ap_tsf_reset = 206,
208 roaming = 207,
210 sa_query_timeout = 209,
214 // clang-format on
215};
216
221enum class cipher_type : int {
222 // clang-format off
223 none = 0,
224 wep40 = 1,
225 wep104 = 2,
226 tkip = 3,
227 ccmp = 4,
228 tkip_ccmp = 5,
229 aes_cmac128 = 6,
230 sms4 = 7,
231 gcmp = 8,
232 gcmp256 = 9,
233 aes_gmac128 = 10,
234 aes_gmac256 = 11,
235 unknown = 12,
236 // clang-format on
237};
238
243enum class phy_mode : int {
244 // clang-format off
245 lr = 0,
246 b11b = 1,
247 b11g = 2,
248 b11a = 3,
249 ht20 = 4,
250 ht40 = 5,
251 he20 = 6,
252 vht20 = 7,
253 // clang-format on
254};
255
260enum class band : int {
261 // clang-format off
262 ghz_2g = 1,
263 ghz_5g = 2,
264 // clang-format on
265};
266
271enum class band_mode : int {
272 // clang-format off
273 ghz_2g_only = 1,
274 ghz_5g_only = 2,
275 auto_mode = 3,
276 // clang-format on
277};
278
286enum class channel_5g : uint32_t {
287 // clang-format off
288 ch36 = 1u << 1,
289 ch40 = 1u << 2,
290 ch44 = 1u << 3,
291 ch48 = 1u << 4,
292 ch52 = 1u << 5,
293 ch56 = 1u << 6,
294 ch60 = 1u << 7,
295 ch64 = 1u << 8,
296 ch100 = 1u << 9,
297 ch104 = 1u << 10,
298 ch108 = 1u << 11,
299 ch112 = 1u << 12,
300 ch116 = 1u << 13,
301 ch120 = 1u << 14,
302 ch124 = 1u << 15,
303 ch128 = 1u << 16,
304 ch132 = 1u << 17,
305 ch136 = 1u << 18,
306 ch140 = 1u << 19,
307 ch144 = 1u << 20,
308 ch149 = 1u << 21,
309 ch153 = 1u << 22,
310 ch157 = 1u << 23,
311 ch161 = 1u << 24,
312 ch165 = 1u << 25,
313 ch169 = 1u << 26,
314 ch173 = 1u << 27,
315 ch177 = 1u << 28,
316 all = 0x1FFFFFFE,
317 // clang-format on
318};
319
324enum class storage : int {
325 // clang-format off
326 flash = 0,
327 ram = 1,
328 // clang-format on
329};
330
335enum class country_policy : int {
336 // clang-format off
337 auto_policy = 0,
338 manual = 1,
339 // clang-format on
340};
341
346enum class scan_method : int {
347 // clang-format off
348 fast = 0,
349 all_channel = 1,
350 // clang-format on
351};
352
357enum class sae_pwe_method : int {
358 // clang-format off
359 hunt_and_peck = 1,
360 hash_to_element = 2,
361 // clang-format on
362};
363
368enum class sae_pk_mode : int {
369 // clang-format off
370 automatic = 0,
371 only = 1,
372 disabled = 2,
373 // clang-format on
374};
375
382enum class protocol : uint8_t {
383 // clang-format off
384 b11b = 0x01,
385 b11g = 0x02,
386 b11n = 0x04,
387 lr = 0x08,
388 b11a = 0x10,
389 b11ac = 0x20,
390 b11ax = 0x40,
391 // clang-format on
392};
393
398enum class promiscuous_pkt_type : int {
399 // clang-format off
400 mgmt = 0,
401 ctrl = 1,
402 data = 2,
403 misc = 3,
404 // clang-format on
405};
406
414 // clang-format off
415 all = 0xFFFFFFFF,
416 mgmt = 1u << 0,
417 ctrl = 1u << 1,
418 data = 1u << 2,
419 misc = 1u << 3,
420 data_mpdu = 1u << 4,
421 data_ampdu = 1u << 5,
422 fcsfail = 1u << 6,
423 // clang-format on
424};
425
433 // clang-format off
434 all = 0xFF800000,
435 wrapper = 1u << 23,
436 bar = 1u << 24,
437 ba = 1u << 25,
438 pspoll = 1u << 26,
439 rts = 1u << 27,
440 cts = 1u << 28,
441 ack = 1u << 29,
442 cfend = 1u << 30,
443 cfendack = 1u << 31,
444 // clang-format on
445};
446
454enum class event_mask : uint32_t {
455 // clang-format off
456 all = 0xFFFFFFFF,
457 none = 0,
458 ap_probe_req_rx = 1u << 0,
459 // clang-format on
460};
461
470 // clang-format off
471 buffer = 1u << 0,
472 rxtx = 1u << 1,
473 hw = 1u << 2,
474 diag = 1u << 3,
475 ps = 1u << 4,
476 all = 0xFFFFFFFF,
477 // clang-format on
478};
479
484enum class vendor_ie_type : int {
485 // clang-format off
486 beacon = 0,
487 probe_req = 1,
488 probe_resp = 2,
489 assoc_req = 3,
490 assoc_resp = 4,
491 // clang-format on
492};
493
498enum class vendor_ie_id : int {
499 // clang-format off
500 id_0 = 0,
501 id_1 = 1,
502 // clang-format on
503};
504
509enum class ftm_status : int {
510 // clang-format off
511 success = 0,
512 unsupported = 1,
513 conf_rejected = 2,
514 no_response = 3,
515 fail = 4,
516 no_valid_msmt = 5,
517 user_term = 6,
518 // clang-format on
519};
520
529enum class phy_rate : int {
530 // clang-format off
531 // 802.11b long preamble
532 rate_1m_l = 0x00,
533 rate_2m_l = 0x01,
534 rate_5m_l = 0x02,
535 rate_11m_l = 0x03,
536 // 802.11b short preamble
537 rate_2m_s = 0x05,
538 rate_5m_s = 0x06,
539 rate_11m_s = 0x07,
540 // OFDM (802.11a/g)
541 rate_48m = 0x08,
542 rate_24m = 0x09,
543 rate_12m = 0x0A,
544 rate_6m = 0x0B,
545 rate_54m = 0x0C,
546 rate_36m = 0x0D,
547 rate_18m = 0x0E,
548 rate_9m = 0x0F,
549 // HT (802.11n) long GI
550 mcs0_lgi = 0x10,
551 mcs1_lgi = 0x11,
552 mcs2_lgi = 0x12,
553 mcs3_lgi = 0x13,
554 mcs4_lgi = 0x14,
555 mcs5_lgi = 0x15,
556 mcs6_lgi = 0x16,
557 mcs7_lgi = 0x17,
558#if SOC_WIFI_HE_SUPPORT
559 mcs8_lgi = 0x18,
560 mcs9_lgi = 0x19,
561#endif
562 // HT (802.11n) short GI
563#if SOC_WIFI_HE_SUPPORT
564 mcs0_sgi = 0x1A,
565#else
566 mcs0_sgi = 0x18,
567#endif
568 mcs1_sgi = mcs0_sgi + 1,
569 mcs2_sgi = mcs0_sgi + 2,
570 mcs3_sgi = mcs0_sgi + 3,
571 mcs4_sgi = mcs0_sgi + 4,
572 mcs5_sgi = mcs0_sgi + 5,
573 mcs6_sgi = mcs0_sgi + 6,
574 mcs7_sgi = mcs0_sgi + 7,
575#if SOC_WIFI_HE_SUPPORT
576 mcs8_sgi = mcs0_sgi + 8,
577 mcs9_sgi = mcs0_sgi + 9,
578#endif
579 // Long Range (Espressif proprietary)
580 lora_250k = 0x29,
581 lora_500k = 0x2A,
582 // clang-format on
583};
584
585} // namespace idfxx::wifi
586
588template<>
589inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::role> = true;
590template<>
592template<>
594template<>
596template<>
598template<>
600template<>
602template<>
606namespace idfxx::wifi {
607
608// =============================================================================
609// Error handling
610// =============================================================================
611
616enum class errc : esp_err_t {
617 // clang-format off
618 not_init = 0x3001,
619 not_started = 0x3002,
620 not_stopped = 0x3003,
621 if_error = 0x3004,
622 mode = 0x3005,
623 state = 0x3006,
624 conn = 0x3007,
625 nvs = 0x3008,
626 mac = 0x3009,
627 ssid = 0x300A,
628 password = 0x300B,
629 timeout = 0x300C,
630 wake_fail = 0x300D,
631 would_block = 0x300E,
632 not_connect = 0x300F,
633 post = 0x3012,
634 init_state = 0x3013,
635 stop_state = 0x3014,
636 not_assoc = 0x3015,
637 tx_disallow = 0x3016,
638 twt_full = 0x3017,
639 twt_setup_timeout = 0x3018,
640 twt_setup_txfail = 0x3019,
641 twt_setup_reject = 0x301A,
642 discard = 0x301B,
643 roc_in_progress = 0x301C,
644 // clang-format on
645};
646
651class error_category : public std::error_category {
652public:
655
657 [[nodiscard]] std::string message(int ec) const override final;
658};
659
660// =============================================================================
661// Data types
662// =============================================================================
663
676
682 std::array<char, 3> cc = {'0', '1', '\0'};
683 uint8_t start_channel = 1;
684 uint8_t num_channels = 11;
685 int8_t max_tx_power = 20;
686 enum country_policy policy = country_policy::auto_policy;
687#if SOC_WIFI_SUPPORT_5G
689#endif
690};
691
723
739
753
754// =============================================================================
755// Configuration structs
756// =============================================================================
757
775 std::optional<unsigned int> static_rx_buf_num;
776 std::optional<unsigned int> dynamic_rx_buf_num;
777 std::optional<unsigned int> static_tx_buf_num;
778 std::optional<unsigned int> dynamic_tx_buf_num;
779 std::optional<unsigned int> cache_tx_buf_num;
780 std::optional<unsigned int> rx_ba_win;
781 std::optional<bool> ampdu_rx_enable;
782 std::optional<bool> ampdu_tx_enable;
783 std::optional<bool> nvs_enable;
784 std::optional<core_id> wifi_task_core_id;
785};
786
792 bool capable = false;
793 bool required = false;
794};
795
801 std::string ssid;
802 std::string password;
803 std::optional<mac_address> bssid = {};
804 uint8_t channel = 0;
805 enum scan_method scan_method = scan_method::fast;
806 enum sort_method sort_method = sort_method::by_rssi;
807 enum auth_mode auth_threshold = auth_mode::open;
808 int8_t rssi_threshold = -127;
809 struct pmf_config pmf = {};
810 uint16_t listen_interval = 0;
811 bool rm_enabled = false;
812 bool btm_enabled = false;
813 bool mbo_enabled = false;
814 bool ft_enabled = false;
815 bool owe_enabled = false;
816 bool transition_disable = false;
817 flags<sae_pwe_method> sae_pwe_h2e = {};
818 enum sae_pk_mode sae_pk_mode = sae_pk_mode::automatic;
819 uint8_t failure_retry_cnt = 0;
820};
821
826struct ap_config {
827 std::string ssid;
828 std::string password;
829 uint8_t channel = 1;
830 enum auth_mode authmode = auth_mode::open;
831 uint8_t ssid_hidden = 0;
832 uint8_t max_connection = 4;
833 uint16_t beacon_interval = 100;
834 enum cipher_type pairwise_cipher = cipher_type::tkip_ccmp;
835 bool ftm_responder = false;
836 struct pmf_config pmf = {};
837 flags<sae_pwe_method> sae_pwe_h2e = {};
838};
839
845 std::string ssid;
846 uint8_t channel = 0;
847 bool show_hidden = false;
848 enum scan_type scan_type = scan_type::active;
849};
850
856 uint32_t active_scan_min_ms = 0;
857 uint32_t active_scan_max_ms = 120;
858 uint32_t passive_scan_ms = 360;
859 uint8_t home_chan_dwell_time_ms = 30;
860};
861
870
879
886 std::optional<enum second_channel> second;
887};
888
895 uint8_t channel = 0;
896 uint8_t frame_count = 0;
897 uint16_t burst_period = 0;
898 bool use_get_report_api = false;
899};
900
906 bool lltf_en = true;
907 bool htltf_en = true;
908 bool stbc_htltf2_en = true;
909 bool ltf_merge_en = true;
910 bool channel_filter_en = true;
911 bool manu_scale = false;
912 uint8_t shift = 0;
913 bool dump_ack_en = false;
914};
915
916// =============================================================================
917// WiFi events
918// =============================================================================
919
933enum class event_id : int32_t {
934 // clang-format off
935 ready = 0,
936 scan_done = 1,
937 sta_start = 2,
938 sta_stop = 3,
939 sta_connected = 4,
940 sta_disconnected = 5,
945 sta_wps_er_pin = 10,
947 ap_start = 12,
948 ap_stop = 13,
949 ap_sta_connected = 14,
952 ftm_report = 17,
953 sta_bss_rssi_low = 18,
954 action_tx_status = 19,
955 roc_done = 20,
956 sta_beacon_timeout = 21,
958 ap_wps_rg_success = 23,
959 ap_wps_rg_failed = 24,
960 ap_wps_rg_timeout = 25,
961 ap_wps_rg_pin = 26,
963 itwt_setup = 28,
964 itwt_teardown = 29,
965 itwt_probe = 30,
966 itwt_suspend = 31,
967 twt_wakeup = 32,
968 btwt_setup = 33,
969 btwt_teardown = 34,
970 nan_started = 35,
971 nan_stopped = 36,
972 nan_svc_match = 37,
973 nan_replied = 38,
974 nan_receive = 39,
975 ndp_indication = 40,
976 ndp_confirm = 41,
977 ndp_terminated = 42,
979 sta_neighbor_rep = 44,
980 ap_wrong_password = 45,
982 dpp_uri_ready = 47,
983 dpp_cfg_recvd = 48,
984 dpp_failed = 49,
985 // clang-format on
986};
987
995extern const event_base<event_id> events;
996
999 return events;
1000}
1003// =============================================================================
1004// Event data wrappers
1005// =============================================================================
1006
1023
1039
1055
1070
1085
1101
1116
1130
1139 std::optional<enum second_channel> old_second;
1141 std::optional<enum second_channel> new_second;
1146};
1147
1166
1167// =============================================================================
1168// Typed events
1169// =============================================================================
1170
1171// WiFi events with data
1196
1197// WiFi events without data
1280
1281// =============================================================================
1282// Free function API — Lifecycle
1283// =============================================================================
1284
1285#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1297void init(const init_config& cfg = {});
1298
1305void deinit();
1306
1316void start();
1317
1324void stop();
1325
1334void restore();
1335#endif
1336
1347
1354
1364
1371
1380
1381// =============================================================================
1382// Free function API — Roles
1383// =============================================================================
1384
1385#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1395
1405#endif
1406
1414
1421
1422// =============================================================================
1423// Free function API — STA config
1424// =============================================================================
1425
1426#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1436
1446#endif
1447
1455
1462
1463// =============================================================================
1464// Free function API — AP config
1465// =============================================================================
1466
1467#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1477
1487
1497
1506[[nodiscard]] std::vector<sta_info> get_sta_list();
1507
1518#endif
1519
1527
1534
1542
1549
1557
1558// =============================================================================
1559// Free function API — Connect / disconnect
1560// =============================================================================
1561
1562#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1572void connect();
1573
1581
1589
1599
1609#endif
1610
1620
1627
1634
1641
1648
1649// =============================================================================
1650// Free function API — Scanning
1651// =============================================================================
1652
1653#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1665[[nodiscard]] std::vector<ap_record> scan(const scan_config& cfg = {});
1666
1679void scan_start(const scan_config& cfg = {});
1680
1691[[nodiscard]] std::vector<ap_record> scan_get_results();
1692
1700
1710
1718
1728
1738#endif
1739
1749
1761
1770
1777
1784
1791
1799
1806
1807// =============================================================================
1808// Free function API — Power save
1809// =============================================================================
1810
1811#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1821
1831#endif
1832
1840
1847
1848// =============================================================================
1849// Free function API — Bandwidth
1850// =============================================================================
1851
1852#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1862void set_bandwidth(enum role iface, enum bandwidth bw);
1863
1874
1885
1896#endif
1897
1906
1914
1923
1931
1932// =============================================================================
1933// Free function API — MAC
1934// =============================================================================
1935
1936#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1947
1958#endif
1959
1968
1976
1977// =============================================================================
1978// Free function API — AP info
1979// =============================================================================
1980
1981#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1991#endif
1992
1999
2000// =============================================================================
2001// Free function API — Channel
2002// =============================================================================
2003
2004#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2014void set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2015
2025#endif
2026
2034[[nodiscard]] result<void> try_set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2035
2042
2043// =============================================================================
2044// Free function API — Country
2045// =============================================================================
2046
2047#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2057
2067
2077void set_country_code(std::string_view cc, bool ieee80211d_enabled);
2078
2087[[nodiscard]] std::string get_country_code();
2088#endif
2089
2097
2104
2113
2120
2121// =============================================================================
2122// Free function API — TX power
2123// =============================================================================
2124
2125#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2135
2145#endif
2146
2154
2161
2162// =============================================================================
2163// Free function API — RSSI
2164// =============================================================================
2165
2166#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2176
2186#endif
2187
2195
2202
2203// =============================================================================
2204// Free function API — Protocol
2205// =============================================================================
2206
2207#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2218
2229
2240
2251#endif
2252
2261
2269
2278
2286
2287// =============================================================================
2288// Free function API — Band
2289// =============================================================================
2290
2291#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2300void set_band(enum band b);
2301
2311
2321
2331#endif
2332
2340
2347
2355
2362
2363// =============================================================================
2364// Free function API — Storage
2365// =============================================================================
2366
2367#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2377#endif
2378
2386
2387// =============================================================================
2388// Free function API — Inactive time
2389// =============================================================================
2390
2391#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2402
2413#endif
2414
2423
2431
2432// =============================================================================
2433// Free function API — Event mask
2434// =============================================================================
2435
2436#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2448
2458#endif
2459
2469
2476
2477// =============================================================================
2478// Free function API — Force wakeup
2479// =============================================================================
2480
2481#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2491
2499#endif
2500
2509
2516
2517// =============================================================================
2518// Free function API — Promiscuous mode
2519// =============================================================================
2520
2521#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2531
2541
2553void set_promiscuous_rx_cb(void (*cb)(void*, int));
2554
2564
2574
2584
2594#endif
2595
2603
2610
2621
2629
2636
2644
2651
2652// =============================================================================
2653// Free function API — Raw 802.11
2654// =============================================================================
2655
2656#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2667void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2668
2679void register_80211_tx_cb(void (*cb)(const void*));
2680#endif
2681
2690[[nodiscard]] result<void> try_tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2691
2701
2702// =============================================================================
2703// Free function API — Vendor IE
2704// =============================================================================
2705
2706#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2718void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2719
2729void set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx);
2730#endif
2731
2742try_set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2743
2751result<void> try_set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx);
2752
2753// =============================================================================
2754// Free function API — CSI
2755// =============================================================================
2756
2757#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2766void set_csi(bool en);
2767
2777
2787
2797void set_csi_rx_cb(void (*cb)(void*, void*), void* ctx);
2798#endif
2799
2807
2815
2822
2830result<void> try_set_csi_rx_cb(void (*cb)(void*, void*), void* ctx);
2831
2832// =============================================================================
2833// Free function API — FTM
2834// =============================================================================
2835
2836#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2846
2854
2864
2876[[nodiscard]] std::vector<ftm_report_entry> ftm_get_report(size_t max_entries);
2877#endif
2878
2886
2893
2901
2911
2912// =============================================================================
2913// Free function API — Miscellaneous
2914// =============================================================================
2915
2925
2926#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2936
2946void config_11b_rate(enum role iface, bool disable);
2947
2958
2968
2978
2988#endif
2989
2997
3006
3015
3023
3031
3039
3040// =============================================================================
3041// Inline definitions — exception-based API
3042// =============================================================================
3043
3046#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3047
3048// Lifecycle
3049inline void init(const init_config& cfg) {
3051}
3052inline void deinit() {
3053 unwrap(try_deinit());
3054}
3055inline void start() {
3056 unwrap(try_start());
3057}
3058inline void stop() {
3059 unwrap(try_stop());
3060}
3061inline void restore() {
3063}
3064
3065// Roles
3066inline void set_roles(flags<role> roles) {
3068}
3069inline flags<role> get_roles() {
3070 return unwrap(try_get_roles());
3071}
3072
3073// STA config
3074inline void set_sta_config(const sta_config& cfg) {
3076}
3077inline sta_config get_sta_config() {
3078 return unwrap(try_get_sta_config());
3079}
3080
3081// AP config
3082inline void set_ap_config(const ap_config& cfg) {
3084}
3085inline ap_config get_ap_config() {
3086 return unwrap(try_get_ap_config());
3087}
3088inline void deauth_sta(uint16_t aid) {
3089 unwrap(try_deauth_sta(aid));
3090}
3091inline std::vector<sta_info> get_sta_list() {
3092 return unwrap(try_get_sta_list());
3093}
3094inline uint16_t ap_get_sta_aid(mac_address mac) {
3095 return unwrap(try_ap_get_sta_aid(mac));
3096}
3097
3098// Connect / disconnect
3099inline void connect() {
3101}
3102inline void disconnect() {
3104}
3105inline void clear_fast_connect() {
3107}
3108inline uint16_t sta_get_aid() {
3109 return unwrap(try_sta_get_aid());
3110}
3111inline enum phy_mode get_negotiated_phymode() {
3113}
3114
3115// Scanning
3116inline std::vector<ap_record> scan(const scan_config& cfg) {
3117 return unwrap(try_scan(cfg));
3118}
3119inline void scan_start(const scan_config& cfg) {
3121}
3122inline std::vector<ap_record> scan_get_results() {
3123 return unwrap(try_scan_get_results());
3124}
3125inline void scan_stop() {
3127}
3128inline uint16_t scan_get_ap_num() {
3129 return unwrap(try_scan_get_ap_num());
3130}
3131inline void clear_ap_list() {
3133}
3134inline void set_scan_parameters(const scan_default_params& params) {
3136}
3137inline scan_default_params get_scan_parameters() {
3139}
3140
3141// Power save
3142inline void set_power_save(enum power_save ps) {
3144}
3145inline enum power_save get_power_save() {
3146 return unwrap(try_get_power_save());
3147}
3148
3149// Bandwidth
3150inline void set_bandwidth(enum role iface, enum bandwidth bw) {
3152}
3153inline enum bandwidth get_bandwidth(enum role iface) {
3155}
3156inline void set_bandwidths(enum role iface, const bandwidths_config& bw) {
3158}
3159inline bandwidths_config get_bandwidths(enum role iface) {
3161}
3162
3163// MAC
3164inline void set_mac(enum role iface, mac_address mac) {
3166}
3167inline mac_address get_mac(enum role iface) {
3168 return unwrap(try_get_mac(iface));
3169}
3170
3171// AP info
3172inline ap_record get_ap_info() {
3173 return unwrap(try_get_ap_info());
3174}
3175
3176// Channel
3177inline void set_channel(uint8_t primary, std::optional<enum second_channel> second) {
3178 unwrap(try_set_channel(primary, second));
3179}
3180inline channel_info get_channel() {
3181 return unwrap(try_get_channel());
3182}
3183
3184// Country
3185inline void set_country(const country_config& cfg) {
3187}
3188inline country_config get_country() {
3189 return unwrap(try_get_country());
3190}
3191inline void set_country_code(std::string_view cc, bool ieee80211d_enabled) {
3193}
3194inline std::string get_country_code() {
3195 return unwrap(try_get_country_code());
3196}
3197
3198// TX power
3199inline void set_max_tx_power(int8_t power) {
3201}
3202inline int8_t get_max_tx_power() {
3203 return unwrap(try_get_max_tx_power());
3204}
3205
3206// RSSI
3207inline void set_rssi_threshold(int32_t rssi) {
3209}
3210inline int get_rssi() {
3211 return unwrap(try_get_rssi());
3212}
3213
3214// Protocol
3215inline void set_protocol(enum role iface, flags<protocol> protos) {
3217}
3218inline flags<protocol> get_protocol(enum role iface) {
3219 return unwrap(try_get_protocol(iface));
3220}
3221inline void set_protocols(enum role iface, const protocols_config& cfg) {
3223}
3224inline protocols_config get_protocols(enum role iface) {
3226}
3227
3228// Band
3229inline void set_band(enum band b) {
3231}
3232inline enum band get_band() {
3233 return unwrap(try_get_band());
3234}
3235inline void set_band_mode(enum band_mode m) {
3237}
3238inline enum band_mode get_band_mode() {
3239 return unwrap(try_get_band_mode());
3240}
3241
3242// Storage
3243inline void set_storage(enum storage s) {
3245}
3246
3247// Inactive time
3248inline void set_inactive_time(enum role iface, uint16_t sec) {
3250}
3251inline uint16_t get_inactive_time(enum role iface) {
3253}
3254
3255// Event mask
3258}
3260 return unwrap(try_get_event_mask());
3261}
3262
3263// Force wakeup
3264inline void force_wakeup_acquire() {
3266}
3267inline void force_wakeup_release() {
3269}
3270
3271// Promiscuous mode
3272inline void set_promiscuous(bool en) {
3274}
3275inline bool get_promiscuous() {
3276 return unwrap(try_get_promiscuous());
3277}
3278inline void set_promiscuous_rx_cb(void (*cb)(void*, int)) {
3280}
3283}
3286}
3289}
3292}
3293
3294// Raw 802.11
3295inline void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq) {
3297}
3298inline void register_80211_tx_cb(void (*cb)(const void*)) {
3300}
3301
3302// Vendor IE
3303inline void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie) {
3305}
3306inline void set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx) {
3308}
3309
3310// CSI
3311inline void set_csi(bool en) {
3313}
3314inline void set_csi_config(const csi_config& cfg) {
3316}
3317inline csi_config get_csi_config() {
3318 return unwrap(try_get_csi_config());
3319}
3320inline void set_csi_rx_cb(void (*cb)(void*, void*), void* ctx) {
3322}
3323
3324// FTM
3325inline void ftm_initiate_session(const ftm_initiator_config& cfg) {
3327}
3328inline void ftm_end_session() {
3330}
3331inline void ftm_resp_set_offset(int16_t offset) {
3333}
3334inline std::vector<ftm_report_entry> ftm_get_report(size_t max_entries) {
3336}
3337
3338// Miscellaneous
3341}
3342inline void config_11b_rate(enum role iface, bool disable) {
3343 unwrap(try_config_11b_rate(iface, disable));
3344}
3345inline void config_80211_tx_rate(enum role iface, enum phy_rate rate) {
3347}
3348inline void disable_pmf_config(enum role iface) {
3350}
3351inline void set_dynamic_cs(bool enabled) {
3353}
3356}
3357
3358#endif // CONFIG_COMPILER_CXX_EXCEPTIONS
3359
3362// =============================================================================
3363// Default netif creation helpers
3364// =============================================================================
3365
3366#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3379
3392#endif
3393
3403
3413
3414} // namespace idfxx::wifi
3415
3416namespace idfxx {
3417
3424
3435[[nodiscard]] std::unexpected<std::error_code> wifi_error(esp_err_t e);
3436
3437// =============================================================================
3438// String conversion
3439// =============================================================================
3440
3448[[nodiscard]] std::string to_string(flags<wifi::role> roles);
3449
3457[[nodiscard]] std::string to_string(wifi::auth_mode m);
3458
3466[[nodiscard]] std::string to_string(wifi::cipher_type c);
3467
3475[[nodiscard]] std::string to_string(wifi::disconnect_reason r);
3476
3477} // namespace idfxx
3478
3479namespace idfxx::wifi {
3480
3488[[nodiscard]] inline std::error_code make_error_code(errc e) noexcept {
3489 return {std::to_underlying(e), wifi_category()};
3490}
3491
3492} // namespace idfxx::wifi
3493
3495namespace std {
3496template<>
3497struct is_error_code_enum<idfxx::wifi::errc> : true_type {};
3498} // namespace std
3501#include "sdkconfig.h"
3502#ifdef CONFIG_IDFXX_STD_FORMAT
3504#include <algorithm>
3505#include <format>
3506namespace std {
3507
3508template<>
3509struct formatter<idfxx::flags<idfxx::wifi::role>> {
3510 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3511
3512 template<typename FormatContext>
3513 auto format(idfxx::flags<idfxx::wifi::role> roles, FormatContext& ctx) const {
3514 auto s = idfxx::to_string(roles);
3515 return std::copy(s.begin(), s.end(), ctx.out());
3516 }
3517};
3518
3519template<>
3520struct formatter<idfxx::wifi::auth_mode> {
3521 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3522
3523 template<typename FormatContext>
3524 auto format(idfxx::wifi::auth_mode m, FormatContext& ctx) const {
3525 auto s = idfxx::to_string(m);
3526 return std::copy(s.begin(), s.end(), ctx.out());
3527 }
3528};
3529
3530template<>
3531struct formatter<idfxx::wifi::cipher_type> {
3532 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3533
3534 template<typename FormatContext>
3535 auto format(idfxx::wifi::cipher_type c, FormatContext& ctx) const {
3536 auto s = idfxx::to_string(c);
3537 return std::copy(s.begin(), s.end(), ctx.out());
3538 }
3539};
3540
3541template<>
3542struct formatter<idfxx::wifi::disconnect_reason> {
3543 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3544
3545 template<typename FormatContext>
3546 auto format(idfxx::wifi::disconnect_reason r, FormatContext& ctx) const {
3547 auto s = idfxx::to_string(r);
3548 return std::copy(s.begin(), s.end(), ctx.out());
3549 }
3550};
3551
3552} // namespace std
3554#endif // CONFIG_IDFXX_STD_FORMAT
3555
// end of idfxx_wifi
Type-safe set of flags from a scoped enum.
Definition flags.hpp:88
A MAC-48 (6-byte) hardware address.
Definition mac.hpp:62
Network interface handle.
Definition netif.hpp:354
Non-Volatile Storage handle.
Definition nvs.hpp:58
Error category for WiFi errors.
Definition wifi.hpp:651
std::string message(int ec) const override final
Returns a human-readable message for the given error code.
const char * name() const noexcept override final
Returns the name of the error category.
Concept for types that can be both received and posted as event data.
Definition event.hpp:164
int esp_err_t
Definition error.hpp:35
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
Definition cpu.hpp:52
constexpr idfxx::event< event_id, ap_sta_connected_event_data > ap_sta_connected
Station connected to soft-AP event.
Definition wifi.hpp:1181
void disable_pmf_config(enum role iface)
Disables PMF (Protected Management Frames) for the specified interface.
result< channel_info > try_get_channel()
Gets the current primary and secondary channel.
constexpr idfxx::event< event_id > nan_replied
NAN replied event.
Definition wifi.hpp:1259
void set_csi_rx_cb(void(*cb)(void *, void *), void *ctx)
Registers a callback for CSI data reception.
result< void > try_set_band_mode(enum band_mode m)
Sets the WiFi band mode.
constexpr idfxx::event< event_id > btwt_teardown
Broadcast TWT teardown event.
Definition wifi.hpp:1251
result< enum power_save > try_get_power_save()
Gets the current power save mode.
void set_ap_config(const ap_config &cfg)
Sets the WiFi access point configuration.
constexpr idfxx::event< event_id, ftm_report_event_data > ftm_report
FTM report received event.
Definition wifi.hpp:1195
void deauth_sta(uint16_t aid)
Deauthenticates a station from the soft-AP.
result< void > try_set_roles(flags< role > roles)
Sets the active WiFi roles.
result< uint16_t > try_scan_get_ap_num()
Gets the number of APs found in the last scan.
result< std::string > try_get_country_code()
Gets the current country code.
band
WiFi frequency band.
Definition wifi.hpp:260
constexpr idfxx::event< event_id, ap_sta_disconnected_event_data > ap_sta_disconnected
Station disconnected from soft-AP event.
Definition wifi.hpp:1183
void set_promiscuous_rx_cb(void(*cb)(void *, int))
Sets the promiscuous mode receive callback.
void set_max_tx_power(int8_t power)
Sets the maximum transmit power.
flags< promiscuous_ctrl_filter > get_promiscuous_ctrl_filter()
Gets the current promiscuous mode control frame sub-type filter.
void ftm_end_session()
Ends the current FTM session.
void set_csi_config(const csi_config &cfg)
Sets the CSI configuration.
bandwidth
WiFi channel bandwidth.
Definition wifi.hpp:99
uint16_t get_inactive_time(enum role iface)
Gets the inactive time before a station is deauthenticated.
constexpr idfxx::event< event_id > connectionless_module_wake_interval_start
Connectionless module wake interval start event.
Definition wifi.hpp:1225
event_mask
WiFi event mask flags.
Definition wifi.hpp:454
void set_storage(enum storage s)
Sets the WiFi configuration storage location.
constexpr idfxx::event< event_id > itwt_probe
Individual TWT probe event.
Definition wifi.hpp:1243
void set_promiscuous(bool en)
Enables or disables promiscuous mode.
result< void > try_ftm_initiate_session(const ftm_initiator_config &cfg)
Initiates an FTM (Fine Timing Measurement) session.
constexpr idfxx::event< event_id > dpp_cfg_recvd
DPP configuration received event.
Definition wifi.hpp:1277
result< void > try_set_rssi_threshold(int32_t rssi)
Sets the RSSI threshold for the sta_bss_rssi_low event.
void config_11b_rate(enum role iface, bool disable)
Enables or disables 802.11b rate for the specified interface.
void deinit()
Deinitializes the WiFi subsystem and frees resources.
constexpr idfxx::event< event_id > sta_stop
Station stopped event.
Definition wifi.hpp:1203
promiscuous_pkt_type
Promiscuous mode packet type.
Definition wifi.hpp:398
constexpr idfxx::event< event_id > sta_wps_er_timeout
WPS enrollee timeout event.
Definition wifi.hpp:1215
void restore()
Restores WiFi stack persistent settings to defaults.
uint16_t ap_get_sta_aid(mac_address mac)
Gets the association ID for a station connected to the soft-AP.
void set_sta_config(const sta_config &cfg)
Sets the WiFi station configuration.
storage
WiFi configuration storage location.
Definition wifi.hpp:324
result< void > try_config_80211_tx_rate(enum role iface, enum phy_rate rate)
Sets the 802.11 TX rate for the specified interface.
result< flags< promiscuous_filter > > try_get_promiscuous_filter()
Gets the current promiscuous mode packet type filter.
result< void > try_set_csi(bool en)
Enables or disables CSI (Channel State Information) collection.
constexpr idfxx::event< event_id > ap_wps_rg_failed
AP WPS registrar failed event.
Definition wifi.hpp:1231
std::vector< ap_record > scan(const scan_config &cfg={})
Performs a blocking scan for access points.
promiscuous_filter
Promiscuous mode filter flags.
Definition wifi.hpp:413
result< bandwidths_config > try_get_bandwidths(enum role iface)
Gets bandwidths for dual-band operation on the specified interface.
result< void > try_set_sta_config(const sta_config &cfg)
Sets the WiFi station configuration.
result< void > try_connectionless_module_set_wake_interval(uint16_t interval)
Sets the connectionless module wake interval.
result< void > try_statis_dump(flags< statis_module > modules)
Dumps WiFi statistics for the specified modules.
enum band_mode get_band_mode()
Gets the current WiFi band mode.
void set_roles(flags< role > roles)
Sets the active WiFi roles.
constexpr idfxx::event< event_id > ap_start
Soft-AP started event.
Definition wifi.hpp:1205
constexpr idfxx::event< event_id > twt_wakeup
TWT wakeup event.
Definition wifi.hpp:1247
result< void > try_config_11b_rate(enum role iface, bool disable)
Enables or disables 802.11b rate for the specified interface.
void scan_start(const scan_config &cfg={})
Starts a non-blocking scan for access points.
result< void > try_set_promiscuous(bool en)
Enables or disables promiscuous mode.
constexpr idfxx::event< event_id > roc_done
Remain-on-channel done event.
Definition wifi.hpp:1223
result< void > try_stop()
Stops the WiFi subsystem.
result< void > try_deinit()
Deinitializes the WiFi subsystem and frees resources.
result< flags< promiscuous_ctrl_filter > > try_get_promiscuous_ctrl_filter()
Gets the current promiscuous mode control frame sub-type filter.
void set_band(enum band b)
Sets the WiFi band.
result< enum band_mode > try_get_band_mode()
Gets the current WiFi band mode.
constexpr idfxx::event< event_id > ap_wrong_password
AP detected wrong password from station event.
Definition wifi.hpp:1271
auth_mode
WiFi authentication mode.
Definition wifi.hpp:63
const event_base< event_id > events
WiFi event base.
result< void > try_ftm_resp_set_offset(int16_t offset)
Sets the FTM responder offset.
std::vector< ftm_report_entry > ftm_get_report(size_t max_entries)
Retrieves the FTM measurement report entries.
result< void > try_deauth_sta(uint16_t aid)
Deauthenticates a station from the soft-AP.
result< enum band > try_get_band()
Gets the current WiFi band.
csi_config get_csi_config()
Gets the current CSI configuration.
result< netif::interface > try_create_default_sta_netif()
Creates a default WiFi station network interface.
promiscuous_ctrl_filter
Promiscuous mode control frame sub-type filter flags.
Definition wifi.hpp:432
result< void > try_set_power_save(enum power_save ps)
Sets the power save mode.
void tx_80211(enum role iface, std::span< const uint8_t > buffer, bool en_sys_seq)
Transmits a raw 802.11 frame.
constexpr idfxx::event< event_id > sta_wps_er_pbc_overlap
WPS PBC overlap detected event.
Definition wifi.hpp:1219
void force_wakeup_acquire()
Acquires a WiFi wakeup lock.
void register_80211_tx_cb(void(*cb)(const void *))
Registers a callback for 802.11 TX completion.
int get_rssi()
Gets the current RSSI of the connected AP.
result< void > try_set_country(const country_config &cfg)
Sets the WiFi country configuration.
result< void > try_set_promiscuous_ctrl_filter(flags< promiscuous_ctrl_filter > filter)
Sets the promiscuous mode control frame sub-type filter.
event_id
WiFi event IDs.
Definition wifi.hpp:933
@ connectionless_module_wake_interval_start
result< std::vector< sta_info > > try_get_sta_list()
Gets the list of stations connected to the soft-AP.
result< void > try_set_inactive_time(enum role iface, uint16_t sec)
Sets the inactive time before a station is deauthenticated.
bandwidths_config get_bandwidths(enum role iface)
Gets bandwidths for dual-band operation on the specified interface.
enum bandwidth get_bandwidth(enum role iface)
Gets the current channel bandwidth for the specified interface.
result< enum bandwidth > try_get_bandwidth(enum role iface)
Gets the current channel bandwidth for the specified interface.
sae_pk_mode
SAE-PK (Public Key) mode.
Definition wifi.hpp:368
void init(const init_config &cfg={})
Initializes the WiFi subsystem.
void set_promiscuous_ctrl_filter(flags< promiscuous_ctrl_filter > filter)
Sets the promiscuous mode control frame sub-type filter.
vendor_ie_id
Vendor-specific IE index.
Definition wifi.hpp:498
constexpr idfxx::event< event_id, ap_probe_req_event_data > ap_probe_req_received
Probe request received by soft-AP event.
Definition wifi.hpp:1187
constexpr idfxx::event< event_id > itwt_teardown
Individual TWT teardown event.
Definition wifi.hpp:1241
result< void > try_set_ap_config(const ap_config &cfg)
Sets the WiFi access point configuration.
result< void > try_scan_stop()
Stops an in-progress scan.
result< void > try_start()
Starts the WiFi subsystem.
result< void > try_tx_80211(enum role iface, std::span< const uint8_t > buffer, bool en_sys_seq)
Transmits a raw 802.11 frame.
bool get_promiscuous()
Gets whether promiscuous mode is enabled.
constexpr idfxx::event< event_id > itwt_setup
Individual TWT setup event.
Definition wifi.hpp:1239
result< void > try_set_scan_parameters(const scan_default_params &params)
Sets the default scan timing parameters.
constexpr idfxx::event< event_id, disconnected_event_data > sta_disconnected
Station disconnected event with disconnection details.
Definition wifi.hpp:1175
protocols_config get_protocols(enum role iface)
Gets the enabled WiFi protocols for dual-band operation.
scan_method
WiFi scan method.
Definition wifi.hpp:346
constexpr idfxx::event< event_id > action_tx_status
Action frame TX status event.
Definition wifi.hpp:1221
second_channel
WiFi secondary channel position relative to the primary channel.
Definition wifi.hpp:124
statis_module
WiFi statistics module flags.
Definition wifi.hpp:469
netif::interface create_default_ap_netif()
Creates a default WiFi access point network interface.
void connect()
Connects to the configured access point.
sort_method
WiFi AP sort method for connection.
Definition wifi.hpp:135
constexpr idfxx::event< event_id > ap_wps_rg_pbc_overlap
AP WPS PBC overlap detected event.
Definition wifi.hpp:1237
errc
Error codes for WiFi operations.
Definition wifi.hpp:616
cipher_type
WiFi cipher type.
Definition wifi.hpp:221
scan_type
WiFi scan type.
Definition wifi.hpp:113
result< uint16_t > try_get_inactive_time(enum role iface)
Gets the inactive time before a station is deauthenticated.
constexpr idfxx::event< event_id > sta_neighbor_rep
Station neighbor report received event.
Definition wifi.hpp:1269
result< csi_config > try_get_csi_config()
Gets the current CSI configuration.
result< void > try_disable_pmf_config(enum role iface)
Disables PMF (Protected Management Frames) for the specified interface.
result< uint16_t > try_ap_get_sta_aid(mac_address mac)
Gets the association ID for a station connected to the soft-AP.
sta_config get_sta_config()
Gets the current WiFi station configuration.
band_mode
WiFi band mode.
Definition wifi.hpp:271
result< void > try_force_wakeup_release()
Releases a WiFi wakeup lock.
result< flags< event_mask > > try_get_event_mask()
Gets the current WiFi event mask.
phy_rate
WiFi PHY transmission rate.
Definition wifi.hpp:529
constexpr idfxx::event< event_id, home_channel_change_event_data > home_channel_change
Home channel changed event.
Definition wifi.hpp:1191
void set_bandwidth(enum role iface, enum bandwidth bw)
Sets the channel bandwidth for the specified interface.
uint16_t sta_get_aid()
Gets the association ID assigned by the AP in station mode.
constexpr idfxx::event< event_id > btwt_setup
Broadcast TWT setup event.
Definition wifi.hpp:1249
void connectionless_module_set_wake_interval(uint16_t interval)
Sets the connectionless module wake interval.
void config_80211_tx_rate(enum role iface, enum phy_rate rate)
Sets the 802.11 TX rate for the specified interface.
constexpr idfxx::event< event_id > sta_wps_er_success
WPS enrollee success event.
Definition wifi.hpp:1211
enum band get_band()
Gets the current WiFi band.
flags< event_mask > get_event_mask()
Gets the current WiFi event mask.
result< void > try_set_bandwidths(enum role iface, const bandwidths_config &bw)
Sets bandwidths for dual-band operation on the specified interface.
result< protocols_config > try_get_protocols(enum role iface)
Gets the enabled WiFi protocols for dual-band operation.
result< void > try_set_protocol(enum role iface, flags< protocol > protos)
Sets the enabled WiFi protocols for the specified interface.
protocol
WiFi protocol flags.
Definition wifi.hpp:382
netif::interface create_default_sta_netif()
Creates a default WiFi station network interface.
result< ap_config > try_get_ap_config()
Gets the current WiFi access point configuration.
scan_default_params get_scan_parameters()
Gets the current default scan timing parameters.
enum power_save get_power_save()
Gets the current power save mode.
result< bool > try_get_promiscuous()
Gets whether promiscuous mode is enabled.
void set_promiscuous_filter(flags< promiscuous_filter > filter)
Sets the promiscuous mode packet type filter.
result< void > try_disconnect()
Disconnects from the current access point.
constexpr idfxx::event< event_id > ap_wps_rg_timeout
AP WPS registrar timeout event.
Definition wifi.hpp:1233
void statis_dump(flags< statis_module > modules)
Dumps WiFi statistics for the specified modules.
vendor_ie_type
Vendor-specific IE type.
Definition wifi.hpp:484
void ftm_initiate_session(const ftm_initiator_config &cfg)
Initiates an FTM (Fine Timing Measurement) session.
result< void > try_set_protocols(enum role iface, const protocols_config &cfg)
Sets the enabled WiFi protocols for dual-band operation.
result< void > try_init(const init_config &cfg={})
Initializes the WiFi subsystem.
role
WiFi role (station and/or access point).
Definition wifi.hpp:52
void set_power_save(enum power_save ps)
Sets the power save mode.
result< void > try_set_max_tx_power(int8_t power)
Sets the maximum transmit power.
void set_mac(enum role iface, mac_address mac)
Sets the MAC address for the specified interface.
result< uint16_t > try_sta_get_aid()
Gets the association ID assigned by the AP in station mode.
result< void > try_set_storage(enum storage s)
Sets the WiFi configuration storage location.
std::vector< ap_record > scan_get_results()
Retrieves results from a completed scan.
country_config get_country()
Gets the current WiFi country configuration.
void set_country(const country_config &cfg)
Sets the WiFi country configuration.
constexpr idfxx::event< event_id > nan_receive
NAN receive event.
Definition wifi.hpp:1261
disconnect_reason
WiFi disconnection reason codes.
Definition wifi.hpp:149
std::string get_country_code()
Gets the current country code.
result< void > try_set_mac(enum role iface, mac_address mac)
Sets the MAC address for the specified interface.
ap_record get_ap_info()
Gets information about the currently connected access point.
constexpr idfxx::event< event_id, connected_event_data > sta_connected
Station connected event with connection details.
Definition wifi.hpp:1173
void start()
Starts the WiFi subsystem.
void scan_stop()
Stops an in-progress scan.
void disconnect()
Disconnects from the current access point.
void clear_ap_list()
Clears the AP list stored from a previous scan.
void set_protocol(enum role iface, flags< protocol > protos)
Sets the enabled WiFi protocols for the specified interface.
phy_mode
WiFi PHY mode.
Definition wifi.hpp:243
result< void > try_set_dynamic_cs(bool enabled)
Enables or disables dynamic CS (Carrier Sense).
result< ap_record > try_get_ap_info()
Gets information about the currently connected access point.
constexpr idfxx::event< event_id > dpp_uri_ready
DPP URI ready event.
Definition wifi.hpp:1275
void set_country_code(std::string_view cc, bool ieee80211d_enabled)
Sets the country code.
result< void > try_scan_start(const scan_config &cfg={})
Starts a non-blocking scan for access points.
std::vector< sta_info > get_sta_list()
Gets the list of stations connected to the soft-AP.
ap_config get_ap_config()
Gets the current WiFi access point configuration.
int64_t get_tsf_time(enum role iface)
Gets the TSF (Timing Synchronization Function) time for the specified interface.
void set_rssi_threshold(int32_t rssi)
Sets the RSSI threshold for the sta_bss_rssi_low event.
void set_dynamic_cs(bool enabled)
Enables or disables dynamic CS (Carrier Sense).
result< void > try_set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void *vnd_ie)
Sets a vendor-specific information element.
result< void > try_register_80211_tx_cb(void(*cb)(const void *))
Registers a callback for 802.11 TX completion.
constexpr idfxx::event< event_id > sta_wps_er_pin
WPS enrollee PIN received event.
Definition wifi.hpp:1217
constexpr idfxx::event< event_id, bss_rssi_low_event_data > sta_bss_rssi_low
BSS RSSI dropped below threshold event.
Definition wifi.hpp:1189
constexpr idfxx::event< event_id > ndp_indication
NDP indication event.
Definition wifi.hpp:1263
result< std::vector< ftm_report_entry > > try_ftm_get_report(size_t max_entries)
Retrieves the FTM measurement report entries.
constexpr idfxx::event< event_id > itwt_suspend
Individual TWT suspend event.
Definition wifi.hpp:1245
void set_protocols(enum role iface, const protocols_config &cfg)
Sets the enabled WiFi protocols for dual-band operation.
void set_vendor_ie_cb(void(*cb)(void *, int, const uint8_t *, const void *, int), void *ctx)
Registers a callback for received vendor-specific IEs.
int8_t get_max_tx_power()
Gets the current maximum transmit power.
ftm_status
FTM (Fine Timing Measurement) session status.
Definition wifi.hpp:509
flags< promiscuous_filter > get_promiscuous_filter()
Gets the current promiscuous mode packet type filter.
result< void > try_set_band(enum band b)
Sets the WiFi band.
power_save
WiFi power save mode.
Definition wifi.hpp:87
channel_info get_channel()
Gets the current primary and secondary channel.
constexpr idfxx::event< event_id > sta_beacon_offset_unstable
Station beacon offset unstable event.
Definition wifi.hpp:1273
constexpr idfxx::event< event_id > nan_svc_match
NAN service match event.
Definition wifi.hpp:1257
void ftm_resp_set_offset(int16_t offset)
Sets the FTM responder offset.
mac_address get_mac(enum role iface)
Gets the MAC address for the specified interface.
constexpr idfxx::event< event_id, scan_done_event_data > scan_done
Scan completed event with scan results summary.
Definition wifi.hpp:1177
result< enum phy_mode > try_get_negotiated_phymode()
Gets the PHY mode negotiated with the connected AP.
result< void > try_set_channel(uint8_t primary, std::optional< enum second_channel > second=std::nullopt)
Sets the primary and secondary channel.
result< void > try_clear_fast_connect()
Clears the fast-connect data stored in memory.
constexpr idfxx::event< event_id > ap_wps_rg_success
AP WPS registrar success event.
Definition wifi.hpp:1229
void clear_fast_connect()
Clears the fast-connect data stored in memory.
result< country_config > try_get_country()
Gets the current WiFi country configuration.
constexpr idfxx::event< event_id > sta_wps_er_failed
WPS enrollee failed event.
Definition wifi.hpp:1213
void set_scan_parameters(const scan_default_params &params)
Sets the default scan timing parameters.
constexpr idfxx::event< event_id > sta_start
Station started event.
Definition wifi.hpp:1201
void set_csi(bool en)
Enables or disables CSI (Channel State Information) collection.
flags< protocol > get_protocol(enum role iface)
Gets the enabled WiFi protocols for the specified interface.
result< int > try_get_rssi()
Gets the current RSSI of the connected AP.
result< sta_config > try_get_sta_config()
Gets the current WiFi station configuration.
result< void > try_set_promiscuous_filter(flags< promiscuous_filter > filter)
Sets the promiscuous mode packet type filter.
void set_event_mask(flags< event_mask > mask)
Sets the WiFi event mask.
result< void > try_set_event_mask(flags< event_mask > mask)
Sets the WiFi event mask.
void set_inactive_time(enum role iface, uint16_t sec)
Sets the inactive time before a station is deauthenticated.
result< std::vector< ap_record > > try_scan_get_results()
Retrieves results from a completed scan.
void set_channel(uint8_t primary, std::optional< enum second_channel > second=std::nullopt)
Sets the primary and secondary channel.
result< void > try_restore()
Restores WiFi stack persistent settings to defaults.
result< void > try_set_country_code(std::string_view cc, bool ieee80211d_enabled)
Sets the country code.
result< void > try_ftm_end_session()
Ends the current FTM session.
void set_band_mode(enum band_mode m)
Sets the WiFi band mode.
channel_5g
5 GHz WiFi channel flags.
Definition wifi.hpp:286
flags< role > get_roles()
Gets the currently active WiFi roles.
result< scan_default_params > try_get_scan_parameters()
Gets the current default scan timing parameters.
result< void > try_set_csi_config(const csi_config &cfg)
Sets the CSI configuration.
result< int8_t > try_get_max_tx_power()
Gets the current maximum transmit power.
constexpr idfxx::event< event_id > ready
WiFi ready event.
Definition wifi.hpp:1199
result< flags< protocol > > try_get_protocol(enum role iface)
Gets the enabled WiFi protocols for the specified interface.
result< void > try_set_vendor_ie_cb(void(*cb)(void *, int, const uint8_t *, const void *, int), void *ctx)
Registers a callback for received vendor-specific IEs.
result< void > try_set_promiscuous_rx_cb(void(*cb)(void *, int))
Sets the promiscuous mode receive callback.
void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void *vnd_ie)
Sets a vendor-specific information element.
result< void > try_force_wakeup_acquire()
Acquires a WiFi wakeup lock.
result< void > try_set_bandwidth(enum role iface, enum bandwidth bw)
Sets the channel bandwidth for the specified interface.
void force_wakeup_release()
Releases a WiFi wakeup lock.
constexpr idfxx::event< event_id > dpp_failed
DPP failed event.
Definition wifi.hpp:1279
result< void > try_connect()
Connects to the configured access point.
constexpr idfxx::event< event_id > nan_stopped
NAN stopped event.
Definition wifi.hpp:1255
constexpr idfxx::event< event_id, authmode_change_event_data > sta_authmode_change
Station authentication mode changed event.
Definition wifi.hpp:1179
void stop()
Stops the WiFi subsystem.
result< void > try_clear_ap_list()
Clears the AP list stored from a previous scan.
constexpr idfxx::event< event_id > ap_wps_rg_pin
AP WPS registrar PIN received event.
Definition wifi.hpp:1235
enum phy_mode get_negotiated_phymode()
Gets the PHY mode negotiated with the connected AP.
void set_bandwidths(enum role iface, const bandwidths_config &bw)
Sets bandwidths for dual-band operation on the specified interface.
result< flags< role > > try_get_roles()
Gets the currently active WiFi roles.
result< netif::interface > try_create_default_ap_netif()
Creates a default WiFi access point network interface.
constexpr idfxx::event< event_id > ndp_terminated
NDP terminated event.
Definition wifi.hpp:1267
constexpr idfxx::event< event_id > ndp_confirm
NDP confirm event.
Definition wifi.hpp:1265
result< std::vector< ap_record > > try_scan(const scan_config &cfg={})
Performs a blocking scan for access points.
sae_pwe_method
SAE PWE (Password Element) derivation method.
Definition wifi.hpp:357
result< mac_address > try_get_mac(enum role iface)
Gets the MAC address for the specified interface.
country_policy
WiFi country policy.
Definition wifi.hpp:335
constexpr idfxx::event< event_id > nan_started
NAN started event.
Definition wifi.hpp:1253
constexpr idfxx::event< event_id > sta_beacon_timeout
Station beacon timeout event.
Definition wifi.hpp:1209
result< void > try_set_csi_rx_cb(void(*cb)(void *, void *), void *ctx)
Registers a callback for CSI data reception.
uint16_t scan_get_ap_num()
Gets the number of APs found in the last scan.
constexpr idfxx::event< event_id > ap_stop
Soft-AP stopped event.
Definition wifi.hpp:1207
std::error_code make_error_code(errc e) noexcept
Creates a std::error_code from an idfxx::errc value.
Definition error.hpp:101
const wifi::error_category & wifi_category() noexcept
Returns a reference to the WiFi error category singleton.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
Definition error.hpp:307
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
flags(E) -> flags< E >
Class template argument deduction guide.
Configuration for WiFi access point mode.
Definition wifi.hpp:826
std::string ssid
Definition wifi.hpp:827
std::string password
Definition wifi.hpp:828
Information about a probe request received by the soft-AP.
Definition wifi.hpp:1108
Information about a discovered access point.
Definition wifi.hpp:698
uint8_t primary_channel
Definition wifi.hpp:702
enum cipher_type pairwise_cipher
Definition wifi.hpp:705
std::optional< enum second_channel > second
Definition wifi.hpp:703
std::string ssid
Definition wifi.hpp:700
mac_address bssid
Definition wifi.hpp:699
enum auth_mode authmode
Definition wifi.hpp:704
enum bandwidth bw
Definition wifi.hpp:719
enum cipher_type group_cipher
Definition wifi.hpp:706
Information about a station connecting to the soft-AP.
Definition wifi.hpp:1077
Information about a station disconnecting from the soft-AP.
Definition wifi.hpp:1092
Information about an authentication mode change.
Definition wifi.hpp:1062
Bandwidth configuration for dual-band operation.
Definition wifi.hpp:875
Information about BSS RSSI dropping below threshold.
Definition wifi.hpp:1123
WiFi channel information.
Definition wifi.hpp:884
std::optional< enum second_channel > second
Definition wifi.hpp:886
Information about a successful station connection.
Definition wifi.hpp:1013
WiFi country configuration.
Definition wifi.hpp:681
CSI (Channel State Information) configuration.
Definition wifi.hpp:905
Information about a station disconnection.
Definition wifi.hpp:1030
enum disconnect_reason reason
Definition wifi.hpp:1033
FTM initiator session configuration.
Definition wifi.hpp:893
Single FTM report measurement entry.
Definition wifi.hpp:744
uint64_t t2
Definition wifi.hpp:749
int8_t rssi
Definition wifi.hpp:746
uint64_t t1
Definition wifi.hpp:748
uint64_t t3
Definition wifi.hpp:750
uint32_t rtt
Definition wifi.hpp:747
uint8_t dlog_token
Definition wifi.hpp:745
uint64_t t4
Definition wifi.hpp:751
Information about an FTM report.
Definition wifi.hpp:1154
std::vector< ftm_report_entry > entries
Definition wifi.hpp:1160
HE (High Efficiency) AP information.
Definition wifi.hpp:670
Information about a home channel change.
Definition wifi.hpp:1137
std::optional< enum second_channel > old_second
Definition wifi.hpp:1139
std::optional< enum second_channel > new_second
Definition wifi.hpp:1141
Configuration for WiFi initialization.
Definition wifi.hpp:774
std::optional< bool > nvs_enable
Definition wifi.hpp:783
std::optional< bool > ampdu_rx_enable
Definition wifi.hpp:781
std::optional< unsigned int > static_rx_buf_num
Definition wifi.hpp:775
std::optional< unsigned int > dynamic_rx_buf_num
Definition wifi.hpp:776
std::optional< unsigned int > rx_ba_win
Definition wifi.hpp:780
std::optional< unsigned int > dynamic_tx_buf_num
Definition wifi.hpp:778
std::optional< unsigned int > static_tx_buf_num
Definition wifi.hpp:777
std::optional< unsigned int > cache_tx_buf_num
Definition wifi.hpp:779
std::optional< bool > ampdu_tx_enable
Definition wifi.hpp:782
std::optional< core_id > wifi_task_core_id
Definition wifi.hpp:784
Protected Management Frame (PMF) configuration.
Definition wifi.hpp:791
Protocol configuration for dual-band operation.
Definition wifi.hpp:866
flags< protocol > ghz_5g
Definition wifi.hpp:868
flags< protocol > ghz_2g
Definition wifi.hpp:867
Configuration for a WiFi scan operation.
Definition wifi.hpp:844
Default scan timing parameters.
Definition wifi.hpp:855
Information about a completed scan.
Definition wifi.hpp:1046
Configuration for WiFi station mode.
Definition wifi.hpp:800
std::string password
Definition wifi.hpp:802
Information about a station connected to the soft-AP.
Definition wifi.hpp:728
mac_address mac
Definition wifi.hpp:729