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 <esp_idf_version.h>
32#include <optional>
33#include <soc/soc_caps.h>
34#include <span>
35#include <string>
36#include <string_view>
37#include <vector>
38
39namespace idfxx::wifi {
40
41// =============================================================================
42// Enumerations
43// =============================================================================
44
53enum class role : int {
54 // clang-format off
55 sta = 1,
56 ap = 2,
57 // clang-format on
58};
59
64enum class auth_mode : int {
65 // clang-format off
66 open = 0,
67 wep = 1,
68 wpa_psk = 2,
69 wpa2_psk = 3,
70 wpa_wpa2_psk = 4,
71 wpa2_enterprise = 5,
72 wpa3_psk = 6,
73 wpa2_wpa3_psk = 7,
74 wapi_psk = 8,
75 owe = 9,
76 wpa3_ent_192 = 10,
77 dpp = 13,
78 wpa3_enterprise = 14,
80 wpa_enterprise = 16,
81 // clang-format on
82};
83
88enum class power_save : int {
89 // clang-format off
90 none = 0,
91 min_modem = 1,
92 max_modem = 2,
93 // clang-format on
94};
95
100enum class bandwidth : int {
101 // clang-format off
102 ht20 = 1,
103 ht40 = 2,
104 bw80 = 3,
105 bw160 = 4,
106 bw80_80 = 5,
107 // clang-format on
108};
109
114enum class scan_type : int {
115 // clang-format off
116 active = 0,
117 passive = 1,
118 // clang-format on
119};
120
125enum class second_channel : int {
126 // clang-format off
127 above = 1,
128 below = 2,
129 // clang-format on
130};
131
136enum class sort_method : int {
137 // clang-format off
138 by_rssi = 0,
139 by_security = 1,
140 // clang-format on
141};
142
151 // clang-format off
152 // IEEE 802.11 standard reasons
153 unspecified = 1,
154 auth_expire = 2,
155 auth_leave = 3,
156 assoc_expire = 4,
157 assoc_toomany = 5,
158 not_authed = 6,
159 not_assoced = 7,
160 assoc_leave = 8,
161 assoc_not_authed = 9,
165 ie_invalid = 13,
166 mic_failure = 14,
169 ie_in_4way_differs = 17,
172 akmp_invalid = 20,
174 invalid_rsn_ie_cap = 22,
178 tdls_unspecified = 26,
181 bad_cipher_or_akm = 29,
184 unspecified_qos = 32,
186 missing_acks = 34,
187 exceeded_txop = 35,
188 sta_leaving = 36,
189 end_ba = 37,
190 unknown_ba = 38,
191 timeout = 39,
192 peer_initiated = 46,
193 ap_initiated = 47,
195 invalid_pmkid = 49,
196 invalid_mde = 50,
197 invalid_fte = 51,
201 // Vendor-specific reasons (200+)
202 beacon_timeout = 200,
203 no_ap_found = 201,
204 auth_fail = 202,
205 assoc_fail = 203,
206 handshake_timeout = 204,
207 connection_fail = 205,
208 ap_tsf_reset = 206,
209 roaming = 207,
211 sa_query_timeout = 209,
215 // clang-format on
216};
217
222enum class cipher_type : int {
223 // clang-format off
224 none = 0,
225 wep40 = 1,
226 wep104 = 2,
227 tkip = 3,
228 ccmp = 4,
229 tkip_ccmp = 5,
230 aes_cmac128 = 6,
231 sms4 = 7,
232 gcmp = 8,
233 gcmp256 = 9,
234 aes_gmac128 = 10,
235 aes_gmac256 = 11,
236 unknown = 12,
237 // clang-format on
238};
239
244enum class phy_mode : int {
245 // clang-format off
246 lr = 0,
247 b11b = 1,
248 b11g = 2,
249 b11a = 3,
250 ht20 = 4,
251 ht40 = 5,
252 he20 = 6,
253 vht20 = 7,
254 // clang-format on
255};
256
261enum class band : int {
262 // clang-format off
263 ghz_2g = 1,
264 ghz_5g = 2,
265 // clang-format on
266};
267
272enum class band_mode : int {
273 // clang-format off
274 ghz_2g_only = 1,
275 ghz_5g_only = 2,
276 auto_mode = 3,
277 // clang-format on
278};
279
287enum class channel_5g : uint32_t {
288 // clang-format off
289 ch36 = 1u << 1,
290 ch40 = 1u << 2,
291 ch44 = 1u << 3,
292 ch48 = 1u << 4,
293 ch52 = 1u << 5,
294 ch56 = 1u << 6,
295 ch60 = 1u << 7,
296 ch64 = 1u << 8,
297 ch100 = 1u << 9,
298 ch104 = 1u << 10,
299 ch108 = 1u << 11,
300 ch112 = 1u << 12,
301 ch116 = 1u << 13,
302 ch120 = 1u << 14,
303 ch124 = 1u << 15,
304 ch128 = 1u << 16,
305 ch132 = 1u << 17,
306 ch136 = 1u << 18,
307 ch140 = 1u << 19,
308 ch144 = 1u << 20,
309 ch149 = 1u << 21,
310 ch153 = 1u << 22,
311 ch157 = 1u << 23,
312 ch161 = 1u << 24,
313 ch165 = 1u << 25,
314 ch169 = 1u << 26,
315 ch173 = 1u << 27,
316 ch177 = 1u << 28,
317 all = 0x1FFFFFFE,
318 // clang-format on
319};
320
325enum class storage : int {
326 // clang-format off
327 flash = 0,
328 ram = 1,
329 // clang-format on
330};
331
336enum class country_policy : int {
337 // clang-format off
338 auto_policy = 0,
339 manual = 1,
340 // clang-format on
341};
342
347enum class scan_method : int {
348 // clang-format off
349 fast = 0,
350 all_channel = 1,
351 // clang-format on
352};
353
358enum class sae_pwe_method : int {
359 // clang-format off
360 hunt_and_peck = 1,
361 hash_to_element = 2,
362 // clang-format on
363};
364
369enum class sae_pk_mode : int {
370 // clang-format off
371 automatic = 0,
372 only = 1,
373 disabled = 2,
374 // clang-format on
375};
376
383enum class protocol : uint8_t {
384 // clang-format off
385 b11b = 0x01,
386 b11g = 0x02,
387 b11n = 0x04,
388 lr = 0x08,
389 b11a = 0x10,
390 b11ac = 0x20,
391 b11ax = 0x40,
392 // clang-format on
393};
394
399enum class promiscuous_pkt_type : int {
400 // clang-format off
401 mgmt = 0,
402 ctrl = 1,
403 data = 2,
404 misc = 3,
405 // clang-format on
406};
407
415 // clang-format off
416 all = 0xFFFFFFFF,
417 mgmt = 1u << 0,
418 ctrl = 1u << 1,
419 data = 1u << 2,
420 misc = 1u << 3,
421 data_mpdu = 1u << 4,
422 data_ampdu = 1u << 5,
423 fcsfail = 1u << 6,
424 // clang-format on
425};
426
434 // clang-format off
435 all = 0xFF800000,
436 wrapper = 1u << 23,
437 bar = 1u << 24,
438 ba = 1u << 25,
439 pspoll = 1u << 26,
440 rts = 1u << 27,
441 cts = 1u << 28,
442 ack = 1u << 29,
443 cfend = 1u << 30,
444 cfendack = 1u << 31,
445 // clang-format on
446};
447
455enum class event_mask : uint32_t {
456 // clang-format off
457 all = 0xFFFFFFFF,
458 none = 0,
459 ap_probe_req_rx = 1u << 0,
460 // clang-format on
461};
462
471 // clang-format off
472 buffer = 1u << 0,
473 rxtx = 1u << 1,
474 hw = 1u << 2,
475 diag = 1u << 3,
476 ps = 1u << 4,
477 all = 0xFFFFFFFF,
478 // clang-format on
479};
480
485enum class vendor_ie_type : int {
486 // clang-format off
487 beacon = 0,
488 probe_req = 1,
489 probe_resp = 2,
490 assoc_req = 3,
491 assoc_resp = 4,
492 // clang-format on
493};
494
499enum class vendor_ie_id : int {
500 // clang-format off
501 id_0 = 0,
502 id_1 = 1,
503 // clang-format on
504};
505
510enum class ftm_status : int {
511 // clang-format off
512 success = 0,
513 unsupported = 1,
514 conf_rejected = 2,
515 no_response = 3,
516 fail = 4,
517 no_valid_msmt = 5,
518 user_term = 6,
519 // clang-format on
520};
521
530enum class phy_rate : int {
531 // clang-format off
532 // 802.11b long preamble
533 rate_1m_l = 0x00,
534 rate_2m_l = 0x01,
535 rate_5m_l = 0x02,
536 rate_11m_l = 0x03,
537 // 802.11b short preamble
538 rate_2m_s = 0x05,
539 rate_5m_s = 0x06,
540 rate_11m_s = 0x07,
541 // OFDM (802.11a/g)
542 rate_48m = 0x08,
543 rate_24m = 0x09,
544 rate_12m = 0x0A,
545 rate_6m = 0x0B,
546 rate_54m = 0x0C,
547 rate_36m = 0x0D,
548 rate_18m = 0x0E,
549 rate_9m = 0x0F,
550 // HT (802.11n) long GI
551 mcs0_lgi = 0x10,
552 mcs1_lgi = 0x11,
553 mcs2_lgi = 0x12,
554 mcs3_lgi = 0x13,
555 mcs4_lgi = 0x14,
556 mcs5_lgi = 0x15,
557 mcs6_lgi = 0x16,
558 mcs7_lgi = 0x17,
559#if SOC_WIFI_HE_SUPPORT
560 mcs8_lgi = 0x18,
561 mcs9_lgi = 0x19,
562#endif
563 // HT (802.11n) short GI
564#if SOC_WIFI_HE_SUPPORT
565 mcs0_sgi = 0x1A,
566#else
567 mcs0_sgi = 0x18,
568#endif
569 mcs1_sgi = mcs0_sgi + 1,
570 mcs2_sgi = mcs0_sgi + 2,
571 mcs3_sgi = mcs0_sgi + 3,
572 mcs4_sgi = mcs0_sgi + 4,
573 mcs5_sgi = mcs0_sgi + 5,
574 mcs6_sgi = mcs0_sgi + 6,
575 mcs7_sgi = mcs0_sgi + 7,
576#if SOC_WIFI_HE_SUPPORT
577 mcs8_sgi = mcs0_sgi + 8,
578 mcs9_sgi = mcs0_sgi + 9,
579#endif
580 // Long Range (Espressif proprietary)
581 lora_250k = 0x29,
582 lora_500k = 0x2A,
583 // clang-format on
584};
585
586} // namespace idfxx::wifi
587
589template<>
590inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::role> = true;
591template<>
593template<>
595template<>
597template<>
599template<>
601template<>
603template<>
607namespace idfxx::wifi {
608
609// =============================================================================
610// Error handling
611// =============================================================================
612
622enum class errc : esp_err_t {
623 // clang-format off
624 // ----- 0x3001..0x301C — ESP_ERR_WIFI_* aliases -----
625 not_init = 0x3001,
626 not_started = 0x3002,
627 not_stopped = 0x3003,
628 if_error = 0x3004,
629 mode = 0x3005,
630 state = 0x3006,
631 conn = 0x3007,
632 nvs = 0x3008,
633 mac = 0x3009,
634 ssid = 0x300A,
635 password = 0x300B,
636 timeout = 0x300C,
637 wake_fail = 0x300D,
638 would_block = 0x300E,
639 not_connect = 0x300F,
640 post = 0x3012,
641 init_state = 0x3013,
642 stop_state = 0x3014,
643 not_assoc = 0x3015,
644 tx_disallow = 0x3016,
645 twt_full = 0x3017,
646 twt_setup_timeout = 0x3018,
647 twt_setup_txfail = 0x3019,
648 twt_setup_reject = 0x301A,
649 discard = 0x301B,
650 roc_in_progress = 0x301C,
652 // ----- idfxx-only validation codes (no ESP-IDF counterpart) -----
653 value_too_large = 1,
654 // clang-format on
655};
656
661class error_category : public std::error_category {
662public:
665
667 [[nodiscard]] std::string message(int ec) const override final;
668
685};
686
687// =============================================================================
688// Data types
689// =============================================================================
690
703
709 std::array<char, 3> cc = {'0', '1', '\0'};
710 uint8_t start_channel = 1;
711 uint8_t num_channels = 11;
712 int8_t max_tx_power = 20;
713 enum country_policy policy = country_policy::auto_policy;
714#if SOC_WIFI_SUPPORT_5G
716#endif
717};
718
750
766
780
781// =============================================================================
782// Configuration structs
783// =============================================================================
784
802 std::optional<unsigned int> static_rx_buf_num;
803 std::optional<unsigned int> dynamic_rx_buf_num;
804 std::optional<unsigned int> static_tx_buf_num;
805 std::optional<unsigned int> dynamic_tx_buf_num;
806 std::optional<unsigned int> cache_tx_buf_num;
807 std::optional<unsigned int> rx_ba_win;
808 std::optional<bool> ampdu_rx_enable;
809 std::optional<bool> ampdu_tx_enable;
810 std::optional<bool> nvs_enable;
811 std::optional<core_id> wifi_task_core_id;
812};
813
819 bool capable = false;
820 bool required = false;
821};
822
828 std::string ssid;
829 std::string password;
830 std::optional<mac_address> bssid = {};
831 uint8_t channel = 0;
832 enum scan_method scan_method = scan_method::fast;
833 enum sort_method sort_method = sort_method::by_rssi;
834 enum auth_mode auth_threshold = auth_mode::open;
835 int8_t rssi_threshold = -127;
836 struct pmf_config pmf = {};
837 uint16_t listen_interval = 0;
838 bool rm_enabled = false;
839 bool btm_enabled = false;
840 bool mbo_enabled = false;
841 bool ft_enabled = false;
842 bool owe_enabled = false;
843 bool transition_disable = false;
844 flags<sae_pwe_method> sae_pwe_h2e = {};
845 enum sae_pk_mode sae_pk_mode = sae_pk_mode::automatic;
846 uint8_t failure_retry_cnt = 0;
847};
848
853struct ap_config {
854 std::string ssid;
855 std::string password;
856 uint8_t channel = 1;
857 enum auth_mode authmode = auth_mode::open;
858 uint8_t ssid_hidden = 0;
859 uint8_t max_connection = 4;
860 uint16_t beacon_interval = 100;
861 enum cipher_type pairwise_cipher = cipher_type::tkip_ccmp;
862 bool ftm_responder = false;
863 struct pmf_config pmf = {};
864 flags<sae_pwe_method> sae_pwe_h2e = {};
865};
866
872 std::string ssid;
873 uint8_t channel = 0;
874 bool show_hidden = false;
875 enum scan_type scan_type = scan_type::active;
876};
877
883 uint32_t active_scan_min_ms = 0;
884 uint32_t active_scan_max_ms = 120;
885 uint32_t passive_scan_ms = 360;
886 uint8_t home_chan_dwell_time_ms = 30;
887};
888
897
906
913 std::optional<enum second_channel> second;
914};
915
922 uint8_t channel = 0;
923 uint8_t frame_count = 0;
924 uint16_t burst_period = 0;
925#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 0, 0)
926 bool use_get_report_api = false;
927#endif
928};
929
946#if !SOC_WIFI_HE_SUPPORT
948 bool lltf_en = true;
949 bool htltf_en = true;
950 bool stbc_htltf2_en = true;
951 bool ltf_merge_en = true;
952 bool channel_filter_en = true;
953 bool manu_scale = false;
954 uint8_t shift = 0;
955 bool dump_ack_en = false;
956};
957#elif SOC_WIFI_MAC_VERSION_NUM == 3
958struct csi_config {
959 bool enable = false;
960 bool acquire_csi_legacy = false;
961 bool acquire_csi_force_lltf = false;
962 bool acquire_csi_ht20 = false;
963 bool acquire_csi_ht40 = false;
964 bool acquire_csi_vht = false;
965 bool acquire_csi_su = false;
966 bool acquire_csi_mu = false;
967 bool acquire_csi_dcm = false;
968 bool acquire_csi_beamformed = false;
971 bool dump_ack_en = false;
972 bool lltf_bit_mode = false;
973};
974#else
975struct csi_config {
976 bool enable = false;
977 bool acquire_csi_legacy = false;
978 bool acquire_csi_ht20 = false;
979 bool acquire_csi_ht40 = false;
980 bool acquire_csi_su = false;
981 bool acquire_csi_mu = false;
982 bool acquire_csi_dcm = false;
983 bool acquire_csi_beamformed = false;
986 bool dump_ack_en = false;
987};
988#endif
989
990// =============================================================================
991// WiFi events
992// =============================================================================
993
1007enum class event_id : int32_t {
1008 // clang-format off
1009 ready = 0,
1010 scan_done = 1,
1011 sta_start = 2,
1012 sta_stop = 3,
1013 sta_connected = 4,
1014 sta_disconnected = 5,
1016 sta_wps_er_success = 7,
1017 sta_wps_er_failed = 8,
1018 sta_wps_er_timeout = 9,
1019 sta_wps_er_pin = 10,
1021 ap_start = 12,
1022 ap_stop = 13,
1023 ap_sta_connected = 14,
1024 ap_sta_disconnected = 15,
1026 ftm_report = 17,
1027 sta_bss_rssi_low = 18,
1028 action_tx_status = 19,
1029 roc_done = 20,
1030 sta_beacon_timeout = 21,
1032 ap_wps_rg_success = 23,
1033 ap_wps_rg_failed = 24,
1034 ap_wps_rg_timeout = 25,
1035 ap_wps_rg_pin = 26,
1037 itwt_setup = 28,
1038 itwt_teardown = 29,
1039 itwt_probe = 30,
1040 itwt_suspend = 31,
1041 twt_wakeup = 32,
1042 btwt_setup = 33,
1043 btwt_teardown = 34,
1044 nan_started = 35,
1045 nan_stopped = 36,
1046 nan_svc_match = 37,
1047 nan_replied = 38,
1048 nan_receive = 39,
1049 ndp_indication = 40,
1050 ndp_confirm = 41,
1051 ndp_terminated = 42,
1052 home_channel_change = 43,
1053 sta_neighbor_rep = 44,
1054 ap_wrong_password = 45,
1056 dpp_uri_ready = 47,
1057 dpp_cfg_recvd = 48,
1058 dpp_failed = 49,
1059 // clang-format on
1060};
1061
1069extern const event_base<event_id> events;
1070
1073 return events;
1074}
1077// =============================================================================
1078// Event data wrappers
1079// =============================================================================
1080
1097
1113
1129
1144
1159
1175
1190
1204
1213 std::optional<enum second_channel> old_second;
1215 std::optional<enum second_channel> new_second;
1220};
1221
1240
1241// =============================================================================
1242// Typed events
1243// =============================================================================
1244
1245// WiFi events with data
1270
1271// WiFi events without data
1354
1355// =============================================================================
1356// Free function API — Lifecycle
1357// =============================================================================
1358
1359#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1371void init(const init_config& cfg = {});
1372
1379void deinit();
1380
1390void start();
1391
1398void stop();
1399
1408void restore();
1409#endif
1410
1421
1428
1438
1445
1454
1455// =============================================================================
1456// Free function API — Roles
1457// =============================================================================
1458
1459#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1469
1479#endif
1480
1488
1495
1496// =============================================================================
1497// Free function API — STA config
1498// =============================================================================
1499
1500#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1510
1520#endif
1521
1529
1536
1537// =============================================================================
1538// Free function API — AP config
1539// =============================================================================
1540
1541#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1551
1561
1571
1580[[nodiscard]] std::vector<sta_info> get_sta_list();
1581
1592#endif
1593
1601
1608
1616
1623
1631
1632// =============================================================================
1633// Free function API — Connect / disconnect
1634// =============================================================================
1635
1636#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1646void connect();
1647
1655
1663
1673
1683#endif
1684
1694
1701
1708
1715
1722
1723// =============================================================================
1724// Free function API — Scanning
1725// =============================================================================
1726
1727#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1739[[nodiscard]] std::vector<ap_record> scan(const scan_config& cfg = {});
1740
1753void scan_start(const scan_config& cfg = {});
1754
1765[[nodiscard]] std::vector<ap_record> scan_get_results();
1766
1774
1784
1792
1802
1812#endif
1813
1823
1835
1844
1851
1858
1865
1873
1880
1881// =============================================================================
1882// Free function API — Power save
1883// =============================================================================
1884
1885#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1895
1905#endif
1906
1914
1921
1922// =============================================================================
1923// Free function API — Bandwidth
1924// =============================================================================
1925
1926#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1936void set_bandwidth(enum role iface, enum bandwidth bw);
1937
1948
1959
1970#endif
1971
1980
1988
1997
2005
2006// =============================================================================
2007// Free function API — MAC
2008// =============================================================================
2009
2010#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2021
2032#endif
2033
2042
2050
2051// =============================================================================
2052// Free function API — AP info
2053// =============================================================================
2054
2055#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2065#endif
2066
2073
2074// =============================================================================
2075// Free function API — Channel
2076// =============================================================================
2077
2078#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2088void set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2089
2099#endif
2100
2108[[nodiscard]] result<void> try_set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2109
2116
2117// =============================================================================
2118// Free function API — Country
2119// =============================================================================
2120
2121#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2131
2141
2151void set_country_code(std::string_view cc, bool ieee80211d_enabled);
2152
2161[[nodiscard]] std::string get_country_code();
2162#endif
2163
2171
2178
2187
2194
2195// =============================================================================
2196// Free function API — TX power
2197// =============================================================================
2198
2199#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2209
2219#endif
2220
2228
2235
2236// =============================================================================
2237// Free function API — RSSI
2238// =============================================================================
2239
2240#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2250
2260#endif
2261
2269
2276
2277// =============================================================================
2278// Free function API — Protocol
2279// =============================================================================
2280
2281#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2292
2303
2314
2325#endif
2326
2335
2343
2352
2360
2361// =============================================================================
2362// Free function API — Band
2363// =============================================================================
2364
2365#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2374void set_band(enum band b);
2375
2385
2395
2405#endif
2406
2414
2421
2429
2436
2437// =============================================================================
2438// Free function API — Storage
2439// =============================================================================
2440
2441#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2451#endif
2452
2460
2461// =============================================================================
2462// Free function API — Inactive time
2463// =============================================================================
2464
2465#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2476
2487#endif
2488
2497
2505
2506// =============================================================================
2507// Free function API — Event mask
2508// =============================================================================
2509
2510#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2522
2532#endif
2533
2543
2550
2551// =============================================================================
2552// Free function API — Force wakeup
2553// =============================================================================
2554
2555#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2565
2573#endif
2574
2583
2590
2591// =============================================================================
2592// Free function API — Promiscuous mode
2593// =============================================================================
2594
2595#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2605
2615
2627void set_promiscuous_rx_cb(void (*cb)(void*, int));
2628
2638
2648
2658
2668#endif
2669
2677
2684
2695
2703
2710
2718
2725
2726// =============================================================================
2727// Free function API — Raw 802.11
2728// =============================================================================
2729
2730#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2741void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2742
2753void register_80211_tx_cb(void (*cb)(const void*));
2754#endif
2755
2764[[nodiscard]] result<void> try_tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2765
2775
2776// =============================================================================
2777// Free function API — Vendor IE
2778// =============================================================================
2779
2780#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2792void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2793
2803void set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx);
2804#endif
2805
2816try_set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2817
2825result<void> try_set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx);
2826
2827// =============================================================================
2828// Free function API — CSI
2829// =============================================================================
2830
2831#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2840void set_csi(bool en);
2841
2851
2861
2871void set_csi_rx_cb(void (*cb)(void*, void*), void* ctx);
2872#endif
2873
2881
2889
2896
2904result<void> try_set_csi_rx_cb(void (*cb)(void*, void*), void* ctx);
2905
2906// =============================================================================
2907// Free function API — FTM
2908// =============================================================================
2909
2910#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2920
2928
2938
2948[[nodiscard]] std::vector<ftm_report_entry> ftm_get_report(size_t max_entries);
2949#endif
2950
2958
2965
2973
2981
2982// =============================================================================
2983// Free function API — Miscellaneous
2984// =============================================================================
2985
2995
2996#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3006
3016void config_11b_rate(enum role iface, bool disable);
3017
3028
3038
3048
3058#endif
3059
3067
3076
3085
3093
3101
3109
3110// =============================================================================
3111// Inline definitions — exception-based API
3112// =============================================================================
3113
3116#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3117
3118// Lifecycle
3119inline void init(const init_config& cfg) {
3121}
3122inline void deinit() {
3123 unwrap(try_deinit());
3124}
3125inline void start() {
3126 unwrap(try_start());
3127}
3128inline void stop() {
3129 unwrap(try_stop());
3130}
3131inline void restore() {
3133}
3134
3135// Roles
3136inline void set_roles(flags<role> roles) {
3138}
3139inline flags<role> get_roles() {
3140 return unwrap(try_get_roles());
3141}
3142
3143// STA config
3144inline void set_sta_config(const sta_config& cfg) {
3146}
3147inline sta_config get_sta_config() {
3148 return unwrap(try_get_sta_config());
3149}
3150
3151// AP config
3152inline void set_ap_config(const ap_config& cfg) {
3154}
3155inline ap_config get_ap_config() {
3156 return unwrap(try_get_ap_config());
3157}
3158inline void deauth_sta(uint16_t aid) {
3159 unwrap(try_deauth_sta(aid));
3160}
3161inline std::vector<sta_info> get_sta_list() {
3162 return unwrap(try_get_sta_list());
3163}
3164inline uint16_t ap_get_sta_aid(mac_address mac) {
3165 return unwrap(try_ap_get_sta_aid(mac));
3166}
3167
3168// Connect / disconnect
3169inline void connect() {
3171}
3172inline void disconnect() {
3174}
3175inline void clear_fast_connect() {
3177}
3178inline uint16_t sta_get_aid() {
3179 return unwrap(try_sta_get_aid());
3180}
3181inline enum phy_mode get_negotiated_phymode() {
3183}
3184
3185// Scanning
3186inline std::vector<ap_record> scan(const scan_config& cfg) {
3187 return unwrap(try_scan(cfg));
3188}
3189inline void scan_start(const scan_config& cfg) {
3191}
3192inline std::vector<ap_record> scan_get_results() {
3193 return unwrap(try_scan_get_results());
3194}
3195inline void scan_stop() {
3197}
3198inline uint16_t scan_get_ap_num() {
3199 return unwrap(try_scan_get_ap_num());
3200}
3201inline void clear_ap_list() {
3203}
3204inline void set_scan_parameters(const scan_default_params& params) {
3206}
3207inline scan_default_params get_scan_parameters() {
3209}
3210
3211// Power save
3212inline void set_power_save(enum power_save ps) {
3214}
3215inline enum power_save get_power_save() {
3216 return unwrap(try_get_power_save());
3217}
3218
3219// Bandwidth
3220inline void set_bandwidth(enum role iface, enum bandwidth bw) {
3222}
3223inline enum bandwidth get_bandwidth(enum role iface) {
3225}
3226inline void set_bandwidths(enum role iface, const bandwidths_config& bw) {
3228}
3229inline bandwidths_config get_bandwidths(enum role iface) {
3231}
3232
3233// MAC
3234inline void set_mac(enum role iface, mac_address mac) {
3236}
3237inline mac_address get_mac(enum role iface) {
3238 return unwrap(try_get_mac(iface));
3239}
3240
3241// AP info
3242inline ap_record get_ap_info() {
3243 return unwrap(try_get_ap_info());
3244}
3245
3246// Channel
3247inline void set_channel(uint8_t primary, std::optional<enum second_channel> second) {
3248 unwrap(try_set_channel(primary, second));
3249}
3250inline channel_info get_channel() {
3251 return unwrap(try_get_channel());
3252}
3253
3254// Country
3255inline void set_country(const country_config& cfg) {
3257}
3258inline country_config get_country() {
3259 return unwrap(try_get_country());
3260}
3261inline void set_country_code(std::string_view cc, bool ieee80211d_enabled) {
3263}
3264inline std::string get_country_code() {
3265 return unwrap(try_get_country_code());
3266}
3267
3268// TX power
3269inline void set_max_tx_power(int8_t power) {
3271}
3272inline int8_t get_max_tx_power() {
3273 return unwrap(try_get_max_tx_power());
3274}
3275
3276// RSSI
3277inline void set_rssi_threshold(int32_t rssi) {
3279}
3280inline int get_rssi() {
3281 return unwrap(try_get_rssi());
3282}
3283
3284// Protocol
3285inline void set_protocol(enum role iface, flags<protocol> protos) {
3287}
3288inline flags<protocol> get_protocol(enum role iface) {
3289 return unwrap(try_get_protocol(iface));
3290}
3291inline void set_protocols(enum role iface, const protocols_config& cfg) {
3293}
3294inline protocols_config get_protocols(enum role iface) {
3296}
3297
3298// Band
3299inline void set_band(enum band b) {
3301}
3302inline enum band get_band() {
3303 return unwrap(try_get_band());
3304}
3305inline void set_band_mode(enum band_mode m) {
3307}
3308inline enum band_mode get_band_mode() {
3309 return unwrap(try_get_band_mode());
3310}
3311
3312// Storage
3313inline void set_storage(enum storage s) {
3315}
3316
3317// Inactive time
3318inline void set_inactive_time(enum role iface, uint16_t sec) {
3320}
3321inline uint16_t get_inactive_time(enum role iface) {
3323}
3324
3325// Event mask
3328}
3330 return unwrap(try_get_event_mask());
3331}
3332
3333// Force wakeup
3334inline void force_wakeup_acquire() {
3336}
3337inline void force_wakeup_release() {
3339}
3340
3341// Promiscuous mode
3342inline void set_promiscuous(bool en) {
3344}
3345inline bool get_promiscuous() {
3346 return unwrap(try_get_promiscuous());
3347}
3348inline void set_promiscuous_rx_cb(void (*cb)(void*, int)) {
3350}
3353}
3356}
3359}
3362}
3363
3364// Raw 802.11
3365inline void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq) {
3367}
3368inline void register_80211_tx_cb(void (*cb)(const void*)) {
3370}
3371
3372// Vendor IE
3373inline void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie) {
3375}
3376inline void set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx) {
3378}
3379
3380// CSI
3381inline void set_csi(bool en) {
3383}
3384inline void set_csi_config(const csi_config& cfg) {
3386}
3387inline csi_config get_csi_config() {
3388 return unwrap(try_get_csi_config());
3389}
3390inline void set_csi_rx_cb(void (*cb)(void*, void*), void* ctx) {
3392}
3393
3394// FTM
3395inline void ftm_initiate_session(const ftm_initiator_config& cfg) {
3397}
3398inline void ftm_end_session() {
3400}
3401inline void ftm_resp_set_offset(int16_t offset) {
3403}
3404inline std::vector<ftm_report_entry> ftm_get_report(size_t max_entries) {
3406}
3407
3408// Miscellaneous
3411}
3412inline void config_11b_rate(enum role iface, bool disable) {
3413 unwrap(try_config_11b_rate(iface, disable));
3414}
3415inline void config_80211_tx_rate(enum role iface, enum phy_rate rate) {
3417}
3418inline void disable_pmf_config(enum role iface) {
3420}
3421inline void set_dynamic_cs(bool enabled) {
3423}
3426}
3427
3428#endif // CONFIG_COMPILER_CXX_EXCEPTIONS
3429
3432// =============================================================================
3433// Default netif creation helpers
3434// =============================================================================
3435
3436#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3449
3462#endif
3463
3473
3483
3484} // namespace idfxx::wifi
3485
3486namespace idfxx {
3487
3494
3505[[nodiscard]] std::unexpected<std::error_code> wifi_error(esp_err_t e);
3506
3507// =============================================================================
3508// String conversion
3509// =============================================================================
3510
3518[[nodiscard]] std::string to_string(flags<wifi::role> roles);
3519
3527[[nodiscard]] std::string to_string(wifi::auth_mode m);
3528
3536[[nodiscard]] std::string to_string(wifi::cipher_type c);
3537
3545[[nodiscard]] std::string to_string(wifi::disconnect_reason r);
3546
3547} // namespace idfxx
3548
3549namespace idfxx::wifi {
3550
3558[[nodiscard]] inline std::error_code make_error_code(errc e) noexcept {
3559 return {std::to_underlying(e), wifi_category()};
3560}
3561
3562} // namespace idfxx::wifi
3563
3565namespace std {
3566template<>
3567struct is_error_code_enum<idfxx::wifi::errc> : true_type {};
3568} // namespace std
3571#include "sdkconfig.h"
3572#ifdef CONFIG_IDFXX_STD_FORMAT
3574#include <algorithm>
3575#include <format>
3576namespace std {
3577
3578template<>
3579struct formatter<idfxx::flags<idfxx::wifi::role>> {
3580 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3581
3582 template<typename FormatContext>
3583 auto format(idfxx::flags<idfxx::wifi::role> roles, FormatContext& ctx) const {
3584 auto s = idfxx::to_string(roles);
3585 return std::copy(s.begin(), s.end(), ctx.out());
3586 }
3587};
3588
3589template<>
3590struct formatter<idfxx::wifi::auth_mode> {
3591 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3592
3593 template<typename FormatContext>
3594 auto format(idfxx::wifi::auth_mode m, FormatContext& ctx) const {
3595 auto s = idfxx::to_string(m);
3596 return std::copy(s.begin(), s.end(), ctx.out());
3597 }
3598};
3599
3600template<>
3601struct formatter<idfxx::wifi::cipher_type> {
3602 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3603
3604 template<typename FormatContext>
3605 auto format(idfxx::wifi::cipher_type c, FormatContext& ctx) const {
3606 auto s = idfxx::to_string(c);
3607 return std::copy(s.begin(), s.end(), ctx.out());
3608 }
3609};
3610
3611template<>
3612struct formatter<idfxx::wifi::disconnect_reason> {
3613 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3614
3615 template<typename FormatContext>
3616 auto format(idfxx::wifi::disconnect_reason r, FormatContext& ctx) const {
3617 auto s = idfxx::to_string(r);
3618 return std::copy(s.begin(), s.end(), ctx.out());
3619 }
3620};
3621
3622} // namespace std
3624#endif // CONFIG_IDFXX_STD_FORMAT
3625
// 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:359
Non-Volatile Storage handle.
Definition nvs.hpp:58
Error category for WiFi errors.
Definition wifi.hpp:661
std::string message(int ec) const override final
Returns a human-readable message for the given error code.
bool equivalent(int code, const std::error_condition &condition) const noexcept override final
Tests whether an errc value is equivalent to a standard condition.
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:1255
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:1333
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:1325
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:1269
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:261
constexpr idfxx::event< event_id, ap_sta_disconnected_event_data > ap_sta_disconnected
Station disconnected from soft-AP event.
Definition wifi.hpp:1257
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:100
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:1299
event_mask
WiFi event mask flags.
Definition wifi.hpp:455
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:1317
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:1351
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:1277
promiscuous_pkt_type
Promiscuous mode packet type.
Definition wifi.hpp:399
constexpr idfxx::event< event_id > sta_wps_er_timeout
WPS enrollee timeout event.
Definition wifi.hpp:1289
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:325
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:1305
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:414
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:1279
constexpr idfxx::event< event_id > twt_wakeup
TWT wakeup event.
Definition wifi.hpp:1321
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:1297
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:1345
auth_mode
WiFi authentication mode.
Definition wifi.hpp:64
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:433
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:1293
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:1007
@ 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:369
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:499
constexpr idfxx::event< event_id, ap_probe_req_event_data > ap_probe_req_received
Probe request received by soft-AP event.
Definition wifi.hpp:1261
constexpr idfxx::event< event_id > itwt_teardown
Individual TWT teardown event.
Definition wifi.hpp:1315
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:1313
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:1249
protocols_config get_protocols(enum role iface)
Gets the enabled WiFi protocols for dual-band operation.
scan_method
WiFi scan method.
Definition wifi.hpp:347
constexpr idfxx::event< event_id > action_tx_status
Action frame TX status event.
Definition wifi.hpp:1295
second_channel
WiFi secondary channel position relative to the primary channel.
Definition wifi.hpp:125
statis_module
WiFi statistics module flags.
Definition wifi.hpp:470
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:136
constexpr idfxx::event< event_id > ap_wps_rg_pbc_overlap
AP WPS PBC overlap detected event.
Definition wifi.hpp:1311
errc
Error codes for WiFi operations.
Definition wifi.hpp:622
cipher_type
WiFi cipher type.
Definition wifi.hpp:222
scan_type
WiFi scan type.
Definition wifi.hpp:114
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:1343
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:272
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:530
constexpr idfxx::event< event_id, home_channel_change_event_data > home_channel_change
Home channel changed event.
Definition wifi.hpp:1265
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:1323
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:1285
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:383
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:1307
void statis_dump(flags< statis_module > modules)
Dumps WiFi statistics for the specified modules.
vendor_ie_type
Vendor-specific IE type.
Definition wifi.hpp:485
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:53
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:1335
disconnect_reason
WiFi disconnection reason codes.
Definition wifi.hpp:150
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:1247
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:244
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:1349
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:1291
constexpr idfxx::event< event_id, bss_rssi_low_event_data > sta_bss_rssi_low
BSS RSSI dropped below threshold event.
Definition wifi.hpp:1263
constexpr idfxx::event< event_id > ndp_indication
NDP indication event.
Definition wifi.hpp:1337
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:1319
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:510
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:88
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:1347
constexpr idfxx::event< event_id > nan_svc_match
NAN service match event.
Definition wifi.hpp:1331
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:1251
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:1303
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:1287
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:1275
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:287
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:1273
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:1353
result< void > try_connect()
Connects to the configured access point.
constexpr idfxx::event< event_id > nan_stopped
NAN stopped event.
Definition wifi.hpp:1329
constexpr idfxx::event< event_id, authmode_change_event_data > sta_authmode_change
Station authentication mode changed event.
Definition wifi.hpp:1253
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:1309
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:1341
constexpr idfxx::event< event_id > ndp_confirm
NDP confirm event.
Definition wifi.hpp:1339
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:358
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:336
constexpr idfxx::event< event_id > nan_started
NAN started event.
Definition wifi.hpp:1327
constexpr idfxx::event< event_id > sta_beacon_timeout
Station beacon timeout event.
Definition wifi.hpp:1283
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:1281
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:853
std::string ssid
Definition wifi.hpp:854
std::string password
Definition wifi.hpp:855
Information about a probe request received by the soft-AP.
Definition wifi.hpp:1182
Information about a discovered access point.
Definition wifi.hpp:725
uint8_t primary_channel
Definition wifi.hpp:729
enum cipher_type pairwise_cipher
Definition wifi.hpp:732
std::optional< enum second_channel > second
Definition wifi.hpp:730
std::string ssid
Definition wifi.hpp:727
mac_address bssid
Definition wifi.hpp:726
enum auth_mode authmode
Definition wifi.hpp:731
enum bandwidth bw
Definition wifi.hpp:746
enum cipher_type group_cipher
Definition wifi.hpp:733
Information about a station connecting to the soft-AP.
Definition wifi.hpp:1151
Information about a station disconnecting from the soft-AP.
Definition wifi.hpp:1166
Information about an authentication mode change.
Definition wifi.hpp:1136
Bandwidth configuration for dual-band operation.
Definition wifi.hpp:902
Information about BSS RSSI dropping below threshold.
Definition wifi.hpp:1197
WiFi channel information.
Definition wifi.hpp:911
std::optional< enum second_channel > second
Definition wifi.hpp:913
Information about a successful station connection.
Definition wifi.hpp:1087
WiFi country configuration.
Definition wifi.hpp:708
CSI (Channel State Information) configuration.
Definition wifi.hpp:947
Information about a station disconnection.
Definition wifi.hpp:1104
enum disconnect_reason reason
Definition wifi.hpp:1107
FTM initiator session configuration.
Definition wifi.hpp:920
Single FTM report measurement entry.
Definition wifi.hpp:771
uint64_t t2
Definition wifi.hpp:776
int8_t rssi
Definition wifi.hpp:773
uint64_t t1
Definition wifi.hpp:775
uint64_t t3
Definition wifi.hpp:777
uint32_t rtt
Definition wifi.hpp:774
uint8_t dlog_token
Definition wifi.hpp:772
uint64_t t4
Definition wifi.hpp:778
Information about an FTM report.
Definition wifi.hpp:1228
std::vector< ftm_report_entry > entries
Definition wifi.hpp:1234
HE (High Efficiency) AP information.
Definition wifi.hpp:697
Information about a home channel change.
Definition wifi.hpp:1211
std::optional< enum second_channel > old_second
Definition wifi.hpp:1213
std::optional< enum second_channel > new_second
Definition wifi.hpp:1215
Configuration for WiFi initialization.
Definition wifi.hpp:801
std::optional< bool > nvs_enable
Definition wifi.hpp:810
std::optional< bool > ampdu_rx_enable
Definition wifi.hpp:808
std::optional< unsigned int > static_rx_buf_num
Definition wifi.hpp:802
std::optional< unsigned int > dynamic_rx_buf_num
Definition wifi.hpp:803
std::optional< unsigned int > rx_ba_win
Definition wifi.hpp:807
std::optional< unsigned int > dynamic_tx_buf_num
Definition wifi.hpp:805
std::optional< unsigned int > static_tx_buf_num
Definition wifi.hpp:804
std::optional< unsigned int > cache_tx_buf_num
Definition wifi.hpp:806
std::optional< bool > ampdu_tx_enable
Definition wifi.hpp:809
std::optional< core_id > wifi_task_core_id
Definition wifi.hpp:811
Protected Management Frame (PMF) configuration.
Definition wifi.hpp:818
Protocol configuration for dual-band operation.
Definition wifi.hpp:893
flags< protocol > ghz_5g
Definition wifi.hpp:895
flags< protocol > ghz_2g
Definition wifi.hpp:894
Configuration for a WiFi scan operation.
Definition wifi.hpp:871
Default scan timing parameters.
Definition wifi.hpp:882
Information about a completed scan.
Definition wifi.hpp:1120
Configuration for WiFi station mode.
Definition wifi.hpp:827
std::string password
Definition wifi.hpp:829
Information about a station connected to the soft-AP.
Definition wifi.hpp:755
mac_address mac
Definition wifi.hpp:756