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
617enum class errc : esp_err_t {
618 // clang-format off
619 not_init = 0x3001,
620 not_started = 0x3002,
621 not_stopped = 0x3003,
622 if_error = 0x3004,
623 mode = 0x3005,
624 state = 0x3006,
625 conn = 0x3007,
626 nvs = 0x3008,
627 mac = 0x3009,
628 ssid = 0x300A,
629 password = 0x300B,
630 timeout = 0x300C,
631 wake_fail = 0x300D,
632 would_block = 0x300E,
633 not_connect = 0x300F,
634 post = 0x3012,
635 init_state = 0x3013,
636 stop_state = 0x3014,
637 not_assoc = 0x3015,
638 tx_disallow = 0x3016,
639 twt_full = 0x3017,
640 twt_setup_timeout = 0x3018,
641 twt_setup_txfail = 0x3019,
642 twt_setup_reject = 0x301A,
643 discard = 0x301B,
644 roc_in_progress = 0x301C,
645 // clang-format on
646};
647
652class error_category : public std::error_category {
653public:
656
658 [[nodiscard]] std::string message(int ec) const override final;
659};
660
661// =============================================================================
662// Data types
663// =============================================================================
664
677
683 std::array<char, 3> cc = {'0', '1', '\0'};
684 uint8_t start_channel = 1;
685 uint8_t num_channels = 11;
686 int8_t max_tx_power = 20;
687 enum country_policy policy = country_policy::auto_policy;
688#if SOC_WIFI_SUPPORT_5G
690#endif
691};
692
724
740
754
755// =============================================================================
756// Configuration structs
757// =============================================================================
758
776 std::optional<unsigned int> static_rx_buf_num;
777 std::optional<unsigned int> dynamic_rx_buf_num;
778 std::optional<unsigned int> static_tx_buf_num;
779 std::optional<unsigned int> dynamic_tx_buf_num;
780 std::optional<unsigned int> cache_tx_buf_num;
781 std::optional<unsigned int> rx_ba_win;
782 std::optional<bool> ampdu_rx_enable;
783 std::optional<bool> ampdu_tx_enable;
784 std::optional<bool> nvs_enable;
785 std::optional<core_id> wifi_task_core_id;
786};
787
793 bool capable = false;
794 bool required = false;
795};
796
802 std::string ssid;
803 std::string password;
804 std::optional<mac_address> bssid = {};
805 uint8_t channel = 0;
806 enum scan_method scan_method = scan_method::fast;
807 enum sort_method sort_method = sort_method::by_rssi;
808 enum auth_mode auth_threshold = auth_mode::open;
809 int8_t rssi_threshold = -127;
810 struct pmf_config pmf = {};
811 uint16_t listen_interval = 0;
812 bool rm_enabled = false;
813 bool btm_enabled = false;
814 bool mbo_enabled = false;
815 bool ft_enabled = false;
816 bool owe_enabled = false;
817 bool transition_disable = false;
818 flags<sae_pwe_method> sae_pwe_h2e = {};
819 enum sae_pk_mode sae_pk_mode = sae_pk_mode::automatic;
820 uint8_t failure_retry_cnt = 0;
821};
822
827struct ap_config {
828 std::string ssid;
829 std::string password;
830 uint8_t channel = 1;
831 enum auth_mode authmode = auth_mode::open;
832 uint8_t ssid_hidden = 0;
833 uint8_t max_connection = 4;
834 uint16_t beacon_interval = 100;
835 enum cipher_type pairwise_cipher = cipher_type::tkip_ccmp;
836 bool ftm_responder = false;
837 struct pmf_config pmf = {};
838 flags<sae_pwe_method> sae_pwe_h2e = {};
839};
840
846 std::string ssid;
847 uint8_t channel = 0;
848 bool show_hidden = false;
849 enum scan_type scan_type = scan_type::active;
850};
851
857 uint32_t active_scan_min_ms = 0;
858 uint32_t active_scan_max_ms = 120;
859 uint32_t passive_scan_ms = 360;
860 uint8_t home_chan_dwell_time_ms = 30;
861};
862
871
880
887 std::optional<enum second_channel> second;
888};
889
896 uint8_t channel = 0;
897 uint8_t frame_count = 0;
898 uint16_t burst_period = 0;
899#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 0, 0)
900 bool use_get_report_api = false;
901#endif
902};
903
920#if !SOC_WIFI_HE_SUPPORT
922 bool lltf_en = true;
923 bool htltf_en = true;
924 bool stbc_htltf2_en = true;
925 bool ltf_merge_en = true;
926 bool channel_filter_en = true;
927 bool manu_scale = false;
928 uint8_t shift = 0;
929 bool dump_ack_en = false;
930};
931#elif SOC_WIFI_MAC_VERSION_NUM == 3
932struct csi_config {
933 bool enable = false;
934 bool acquire_csi_legacy = false;
935 bool acquire_csi_force_lltf = false;
936 bool acquire_csi_ht20 = false;
937 bool acquire_csi_ht40 = false;
938 bool acquire_csi_vht = false;
939 bool acquire_csi_su = false;
940 bool acquire_csi_mu = false;
941 bool acquire_csi_dcm = false;
942 bool acquire_csi_beamformed = false;
945 bool dump_ack_en = false;
946 bool lltf_bit_mode = false;
947};
948#else
949struct csi_config {
950 bool enable = false;
951 bool acquire_csi_legacy = false;
952 bool acquire_csi_ht20 = false;
953 bool acquire_csi_ht40 = false;
954 bool acquire_csi_su = false;
955 bool acquire_csi_mu = false;
956 bool acquire_csi_dcm = false;
957 bool acquire_csi_beamformed = false;
960 bool dump_ack_en = false;
961};
962#endif
963
964// =============================================================================
965// WiFi events
966// =============================================================================
967
981enum class event_id : int32_t {
982 // clang-format off
983 ready = 0,
984 scan_done = 1,
985 sta_start = 2,
986 sta_stop = 3,
987 sta_connected = 4,
988 sta_disconnected = 5,
993 sta_wps_er_pin = 10,
995 ap_start = 12,
996 ap_stop = 13,
997 ap_sta_connected = 14,
1000 ftm_report = 17,
1001 sta_bss_rssi_low = 18,
1002 action_tx_status = 19,
1003 roc_done = 20,
1004 sta_beacon_timeout = 21,
1006 ap_wps_rg_success = 23,
1007 ap_wps_rg_failed = 24,
1008 ap_wps_rg_timeout = 25,
1009 ap_wps_rg_pin = 26,
1011 itwt_setup = 28,
1012 itwt_teardown = 29,
1013 itwt_probe = 30,
1014 itwt_suspend = 31,
1015 twt_wakeup = 32,
1016 btwt_setup = 33,
1017 btwt_teardown = 34,
1018 nan_started = 35,
1019 nan_stopped = 36,
1020 nan_svc_match = 37,
1021 nan_replied = 38,
1022 nan_receive = 39,
1023 ndp_indication = 40,
1024 ndp_confirm = 41,
1025 ndp_terminated = 42,
1026 home_channel_change = 43,
1027 sta_neighbor_rep = 44,
1028 ap_wrong_password = 45,
1030 dpp_uri_ready = 47,
1031 dpp_cfg_recvd = 48,
1032 dpp_failed = 49,
1033 // clang-format on
1034};
1035
1043extern const event_base<event_id> events;
1044
1047 return events;
1048}
1051// =============================================================================
1052// Event data wrappers
1053// =============================================================================
1054
1071
1087
1103
1118
1133
1149
1164
1178
1187 std::optional<enum second_channel> old_second;
1189 std::optional<enum second_channel> new_second;
1194};
1195
1214
1215// =============================================================================
1216// Typed events
1217// =============================================================================
1218
1219// WiFi events with data
1244
1245// WiFi events without data
1328
1329// =============================================================================
1330// Free function API — Lifecycle
1331// =============================================================================
1332
1333#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1345void init(const init_config& cfg = {});
1346
1353void deinit();
1354
1364void start();
1365
1372void stop();
1373
1382void restore();
1383#endif
1384
1395
1402
1412
1419
1428
1429// =============================================================================
1430// Free function API — Roles
1431// =============================================================================
1432
1433#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1443
1453#endif
1454
1462
1469
1470// =============================================================================
1471// Free function API — STA config
1472// =============================================================================
1473
1474#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1484
1494#endif
1495
1503
1510
1511// =============================================================================
1512// Free function API — AP config
1513// =============================================================================
1514
1515#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1525
1535
1545
1554[[nodiscard]] std::vector<sta_info> get_sta_list();
1555
1566#endif
1567
1575
1582
1590
1597
1605
1606// =============================================================================
1607// Free function API — Connect / disconnect
1608// =============================================================================
1609
1610#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1620void connect();
1621
1629
1637
1647
1657#endif
1658
1668
1675
1682
1689
1696
1697// =============================================================================
1698// Free function API — Scanning
1699// =============================================================================
1700
1701#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1713[[nodiscard]] std::vector<ap_record> scan(const scan_config& cfg = {});
1714
1727void scan_start(const scan_config& cfg = {});
1728
1739[[nodiscard]] std::vector<ap_record> scan_get_results();
1740
1748
1758
1766
1776
1786#endif
1787
1797
1809
1818
1825
1832
1839
1847
1854
1855// =============================================================================
1856// Free function API — Power save
1857// =============================================================================
1858
1859#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1869
1879#endif
1880
1888
1895
1896// =============================================================================
1897// Free function API — Bandwidth
1898// =============================================================================
1899
1900#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1910void set_bandwidth(enum role iface, enum bandwidth bw);
1911
1922
1933
1944#endif
1945
1954
1962
1971
1979
1980// =============================================================================
1981// Free function API — MAC
1982// =============================================================================
1983
1984#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1995
2006#endif
2007
2016
2024
2025// =============================================================================
2026// Free function API — AP info
2027// =============================================================================
2028
2029#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2039#endif
2040
2047
2048// =============================================================================
2049// Free function API — Channel
2050// =============================================================================
2051
2052#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2062void set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2063
2073#endif
2074
2082[[nodiscard]] result<void> try_set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2083
2090
2091// =============================================================================
2092// Free function API — Country
2093// =============================================================================
2094
2095#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2105
2115
2125void set_country_code(std::string_view cc, bool ieee80211d_enabled);
2126
2135[[nodiscard]] std::string get_country_code();
2136#endif
2137
2145
2152
2161
2168
2169// =============================================================================
2170// Free function API — TX power
2171// =============================================================================
2172
2173#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2183
2193#endif
2194
2202
2209
2210// =============================================================================
2211// Free function API — RSSI
2212// =============================================================================
2213
2214#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2224
2234#endif
2235
2243
2250
2251// =============================================================================
2252// Free function API — Protocol
2253// =============================================================================
2254
2255#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2266
2277
2288
2299#endif
2300
2309
2317
2326
2334
2335// =============================================================================
2336// Free function API — Band
2337// =============================================================================
2338
2339#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2348void set_band(enum band b);
2349
2359
2369
2379#endif
2380
2388
2395
2403
2410
2411// =============================================================================
2412// Free function API — Storage
2413// =============================================================================
2414
2415#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2425#endif
2426
2434
2435// =============================================================================
2436// Free function API — Inactive time
2437// =============================================================================
2438
2439#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2450
2461#endif
2462
2471
2479
2480// =============================================================================
2481// Free function API — Event mask
2482// =============================================================================
2483
2484#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2496
2506#endif
2507
2517
2524
2525// =============================================================================
2526// Free function API — Force wakeup
2527// =============================================================================
2528
2529#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2539
2547#endif
2548
2557
2564
2565// =============================================================================
2566// Free function API — Promiscuous mode
2567// =============================================================================
2568
2569#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2579
2589
2601void set_promiscuous_rx_cb(void (*cb)(void*, int));
2602
2612
2622
2632
2642#endif
2643
2651
2658
2669
2677
2684
2692
2699
2700// =============================================================================
2701// Free function API — Raw 802.11
2702// =============================================================================
2703
2704#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2715void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2716
2727void register_80211_tx_cb(void (*cb)(const void*));
2728#endif
2729
2738[[nodiscard]] result<void> try_tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2739
2749
2750// =============================================================================
2751// Free function API — Vendor IE
2752// =============================================================================
2753
2754#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2766void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2767
2777void set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx);
2778#endif
2779
2790try_set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2791
2799result<void> try_set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx);
2800
2801// =============================================================================
2802// Free function API — CSI
2803// =============================================================================
2804
2805#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2814void set_csi(bool en);
2815
2825
2835
2845void set_csi_rx_cb(void (*cb)(void*, void*), void* ctx);
2846#endif
2847
2855
2863
2870
2878result<void> try_set_csi_rx_cb(void (*cb)(void*, void*), void* ctx);
2879
2880// =============================================================================
2881// Free function API — FTM
2882// =============================================================================
2883
2884#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2894
2902
2912
2922[[nodiscard]] std::vector<ftm_report_entry> ftm_get_report(size_t max_entries);
2923#endif
2924
2932
2939
2947
2955
2956// =============================================================================
2957// Free function API — Miscellaneous
2958// =============================================================================
2959
2969
2970#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2980
2990void config_11b_rate(enum role iface, bool disable);
2991
3002
3012
3022
3032#endif
3033
3041
3050
3059
3067
3075
3083
3084// =============================================================================
3085// Inline definitions — exception-based API
3086// =============================================================================
3087
3090#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3091
3092// Lifecycle
3093inline void init(const init_config& cfg) {
3095}
3096inline void deinit() {
3097 unwrap(try_deinit());
3098}
3099inline void start() {
3100 unwrap(try_start());
3101}
3102inline void stop() {
3103 unwrap(try_stop());
3104}
3105inline void restore() {
3107}
3108
3109// Roles
3110inline void set_roles(flags<role> roles) {
3112}
3113inline flags<role> get_roles() {
3114 return unwrap(try_get_roles());
3115}
3116
3117// STA config
3118inline void set_sta_config(const sta_config& cfg) {
3120}
3121inline sta_config get_sta_config() {
3122 return unwrap(try_get_sta_config());
3123}
3124
3125// AP config
3126inline void set_ap_config(const ap_config& cfg) {
3128}
3129inline ap_config get_ap_config() {
3130 return unwrap(try_get_ap_config());
3131}
3132inline void deauth_sta(uint16_t aid) {
3133 unwrap(try_deauth_sta(aid));
3134}
3135inline std::vector<sta_info> get_sta_list() {
3136 return unwrap(try_get_sta_list());
3137}
3138inline uint16_t ap_get_sta_aid(mac_address mac) {
3139 return unwrap(try_ap_get_sta_aid(mac));
3140}
3141
3142// Connect / disconnect
3143inline void connect() {
3145}
3146inline void disconnect() {
3148}
3149inline void clear_fast_connect() {
3151}
3152inline uint16_t sta_get_aid() {
3153 return unwrap(try_sta_get_aid());
3154}
3155inline enum phy_mode get_negotiated_phymode() {
3157}
3158
3159// Scanning
3160inline std::vector<ap_record> scan(const scan_config& cfg) {
3161 return unwrap(try_scan(cfg));
3162}
3163inline void scan_start(const scan_config& cfg) {
3165}
3166inline std::vector<ap_record> scan_get_results() {
3167 return unwrap(try_scan_get_results());
3168}
3169inline void scan_stop() {
3171}
3172inline uint16_t scan_get_ap_num() {
3173 return unwrap(try_scan_get_ap_num());
3174}
3175inline void clear_ap_list() {
3177}
3178inline void set_scan_parameters(const scan_default_params& params) {
3180}
3181inline scan_default_params get_scan_parameters() {
3183}
3184
3185// Power save
3186inline void set_power_save(enum power_save ps) {
3188}
3189inline enum power_save get_power_save() {
3190 return unwrap(try_get_power_save());
3191}
3192
3193// Bandwidth
3194inline void set_bandwidth(enum role iface, enum bandwidth bw) {
3196}
3197inline enum bandwidth get_bandwidth(enum role iface) {
3199}
3200inline void set_bandwidths(enum role iface, const bandwidths_config& bw) {
3202}
3203inline bandwidths_config get_bandwidths(enum role iface) {
3205}
3206
3207// MAC
3208inline void set_mac(enum role iface, mac_address mac) {
3210}
3211inline mac_address get_mac(enum role iface) {
3212 return unwrap(try_get_mac(iface));
3213}
3214
3215// AP info
3216inline ap_record get_ap_info() {
3217 return unwrap(try_get_ap_info());
3218}
3219
3220// Channel
3221inline void set_channel(uint8_t primary, std::optional<enum second_channel> second) {
3222 unwrap(try_set_channel(primary, second));
3223}
3224inline channel_info get_channel() {
3225 return unwrap(try_get_channel());
3226}
3227
3228// Country
3229inline void set_country(const country_config& cfg) {
3231}
3232inline country_config get_country() {
3233 return unwrap(try_get_country());
3234}
3235inline void set_country_code(std::string_view cc, bool ieee80211d_enabled) {
3237}
3238inline std::string get_country_code() {
3239 return unwrap(try_get_country_code());
3240}
3241
3242// TX power
3243inline void set_max_tx_power(int8_t power) {
3245}
3246inline int8_t get_max_tx_power() {
3247 return unwrap(try_get_max_tx_power());
3248}
3249
3250// RSSI
3251inline void set_rssi_threshold(int32_t rssi) {
3253}
3254inline int get_rssi() {
3255 return unwrap(try_get_rssi());
3256}
3257
3258// Protocol
3259inline void set_protocol(enum role iface, flags<protocol> protos) {
3261}
3262inline flags<protocol> get_protocol(enum role iface) {
3263 return unwrap(try_get_protocol(iface));
3264}
3265inline void set_protocols(enum role iface, const protocols_config& cfg) {
3267}
3268inline protocols_config get_protocols(enum role iface) {
3270}
3271
3272// Band
3273inline void set_band(enum band b) {
3275}
3276inline enum band get_band() {
3277 return unwrap(try_get_band());
3278}
3279inline void set_band_mode(enum band_mode m) {
3281}
3282inline enum band_mode get_band_mode() {
3283 return unwrap(try_get_band_mode());
3284}
3285
3286// Storage
3287inline void set_storage(enum storage s) {
3289}
3290
3291// Inactive time
3292inline void set_inactive_time(enum role iface, uint16_t sec) {
3294}
3295inline uint16_t get_inactive_time(enum role iface) {
3297}
3298
3299// Event mask
3302}
3304 return unwrap(try_get_event_mask());
3305}
3306
3307// Force wakeup
3308inline void force_wakeup_acquire() {
3310}
3311inline void force_wakeup_release() {
3313}
3314
3315// Promiscuous mode
3316inline void set_promiscuous(bool en) {
3318}
3319inline bool get_promiscuous() {
3320 return unwrap(try_get_promiscuous());
3321}
3322inline void set_promiscuous_rx_cb(void (*cb)(void*, int)) {
3324}
3327}
3330}
3333}
3336}
3337
3338// Raw 802.11
3339inline void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq) {
3341}
3342inline void register_80211_tx_cb(void (*cb)(const void*)) {
3344}
3345
3346// Vendor IE
3347inline void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie) {
3349}
3350inline void set_vendor_ie_cb(void (*cb)(void*, int, const uint8_t*, const void*, int), void* ctx) {
3352}
3353
3354// CSI
3355inline void set_csi(bool en) {
3357}
3358inline void set_csi_config(const csi_config& cfg) {
3360}
3361inline csi_config get_csi_config() {
3362 return unwrap(try_get_csi_config());
3363}
3364inline void set_csi_rx_cb(void (*cb)(void*, void*), void* ctx) {
3366}
3367
3368// FTM
3369inline void ftm_initiate_session(const ftm_initiator_config& cfg) {
3371}
3372inline void ftm_end_session() {
3374}
3375inline void ftm_resp_set_offset(int16_t offset) {
3377}
3378inline std::vector<ftm_report_entry> ftm_get_report(size_t max_entries) {
3380}
3381
3382// Miscellaneous
3385}
3386inline void config_11b_rate(enum role iface, bool disable) {
3387 unwrap(try_config_11b_rate(iface, disable));
3388}
3389inline void config_80211_tx_rate(enum role iface, enum phy_rate rate) {
3391}
3392inline void disable_pmf_config(enum role iface) {
3394}
3395inline void set_dynamic_cs(bool enabled) {
3397}
3400}
3401
3402#endif // CONFIG_COMPILER_CXX_EXCEPTIONS
3403
3406// =============================================================================
3407// Default netif creation helpers
3408// =============================================================================
3409
3410#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3423
3436#endif
3437
3447
3457
3458} // namespace idfxx::wifi
3459
3460namespace idfxx {
3461
3468
3479[[nodiscard]] std::unexpected<std::error_code> wifi_error(esp_err_t e);
3480
3481// =============================================================================
3482// String conversion
3483// =============================================================================
3484
3492[[nodiscard]] std::string to_string(flags<wifi::role> roles);
3493
3501[[nodiscard]] std::string to_string(wifi::auth_mode m);
3502
3510[[nodiscard]] std::string to_string(wifi::cipher_type c);
3511
3519[[nodiscard]] std::string to_string(wifi::disconnect_reason r);
3520
3521} // namespace idfxx
3522
3523namespace idfxx::wifi {
3524
3532[[nodiscard]] inline std::error_code make_error_code(errc e) noexcept {
3533 return {std::to_underlying(e), wifi_category()};
3534}
3535
3536} // namespace idfxx::wifi
3537
3539namespace std {
3540template<>
3541struct is_error_code_enum<idfxx::wifi::errc> : true_type {};
3542} // namespace std
3545#include "sdkconfig.h"
3546#ifdef CONFIG_IDFXX_STD_FORMAT
3548#include <algorithm>
3549#include <format>
3550namespace std {
3551
3552template<>
3553struct formatter<idfxx::flags<idfxx::wifi::role>> {
3554 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3555
3556 template<typename FormatContext>
3557 auto format(idfxx::flags<idfxx::wifi::role> roles, FormatContext& ctx) const {
3558 auto s = idfxx::to_string(roles);
3559 return std::copy(s.begin(), s.end(), ctx.out());
3560 }
3561};
3562
3563template<>
3564struct formatter<idfxx::wifi::auth_mode> {
3565 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3566
3567 template<typename FormatContext>
3568 auto format(idfxx::wifi::auth_mode m, FormatContext& ctx) const {
3569 auto s = idfxx::to_string(m);
3570 return std::copy(s.begin(), s.end(), ctx.out());
3571 }
3572};
3573
3574template<>
3575struct formatter<idfxx::wifi::cipher_type> {
3576 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3577
3578 template<typename FormatContext>
3579 auto format(idfxx::wifi::cipher_type c, FormatContext& ctx) const {
3580 auto s = idfxx::to_string(c);
3581 return std::copy(s.begin(), s.end(), ctx.out());
3582 }
3583};
3584
3585template<>
3586struct formatter<idfxx::wifi::disconnect_reason> {
3587 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3588
3589 template<typename FormatContext>
3590 auto format(idfxx::wifi::disconnect_reason r, FormatContext& ctx) const {
3591 auto s = idfxx::to_string(r);
3592 return std::copy(s.begin(), s.end(), ctx.out());
3593 }
3594};
3595
3596} // namespace std
3598#endif // CONFIG_IDFXX_STD_FORMAT
3599
// 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:652
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:1229
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:1307
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:1299
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:1243
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:1231
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:1273
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:1291
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:1325
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:1251
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:1263
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:1279
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:1253
constexpr idfxx::event< event_id > twt_wakeup
TWT wakeup event.
Definition wifi.hpp:1295
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:1271
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:1319
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:1267
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:981
@ 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:1235
constexpr idfxx::event< event_id > itwt_teardown
Individual TWT teardown event.
Definition wifi.hpp:1289
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:1287
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:1223
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:1269
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:1285
errc
Error codes for WiFi operations.
Definition wifi.hpp:617
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:1317
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:1239
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:1297
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:1259
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:1281
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:1309
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:1221
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:1323
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:1265
constexpr idfxx::event< event_id, bss_rssi_low_event_data > sta_bss_rssi_low
BSS RSSI dropped below threshold event.
Definition wifi.hpp:1237
constexpr idfxx::event< event_id > ndp_indication
NDP indication event.
Definition wifi.hpp:1311
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:1293
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:1321
constexpr idfxx::event< event_id > nan_svc_match
NAN service match event.
Definition wifi.hpp:1305
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:1225
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:1277
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:1261
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:1249
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:1247
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:1327
result< void > try_connect()
Connects to the configured access point.
constexpr idfxx::event< event_id > nan_stopped
NAN stopped event.
Definition wifi.hpp:1303
constexpr idfxx::event< event_id, authmode_change_event_data > sta_authmode_change
Station authentication mode changed event.
Definition wifi.hpp:1227
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:1283
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:1315
constexpr idfxx::event< event_id > ndp_confirm
NDP confirm event.
Definition wifi.hpp:1313
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:1301
constexpr idfxx::event< event_id > sta_beacon_timeout
Station beacon timeout event.
Definition wifi.hpp:1257
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:1255
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:827
std::string ssid
Definition wifi.hpp:828
std::string password
Definition wifi.hpp:829
Information about a probe request received by the soft-AP.
Definition wifi.hpp:1156
Information about a discovered access point.
Definition wifi.hpp:699
uint8_t primary_channel
Definition wifi.hpp:703
enum cipher_type pairwise_cipher
Definition wifi.hpp:706
std::optional< enum second_channel > second
Definition wifi.hpp:704
std::string ssid
Definition wifi.hpp:701
mac_address bssid
Definition wifi.hpp:700
enum auth_mode authmode
Definition wifi.hpp:705
enum bandwidth bw
Definition wifi.hpp:720
enum cipher_type group_cipher
Definition wifi.hpp:707
Information about a station connecting to the soft-AP.
Definition wifi.hpp:1125
Information about a station disconnecting from the soft-AP.
Definition wifi.hpp:1140
Information about an authentication mode change.
Definition wifi.hpp:1110
Bandwidth configuration for dual-band operation.
Definition wifi.hpp:876
Information about BSS RSSI dropping below threshold.
Definition wifi.hpp:1171
WiFi channel information.
Definition wifi.hpp:885
std::optional< enum second_channel > second
Definition wifi.hpp:887
Information about a successful station connection.
Definition wifi.hpp:1061
WiFi country configuration.
Definition wifi.hpp:682
CSI (Channel State Information) configuration.
Definition wifi.hpp:921
Information about a station disconnection.
Definition wifi.hpp:1078
enum disconnect_reason reason
Definition wifi.hpp:1081
FTM initiator session configuration.
Definition wifi.hpp:894
Single FTM report measurement entry.
Definition wifi.hpp:745
uint64_t t2
Definition wifi.hpp:750
int8_t rssi
Definition wifi.hpp:747
uint64_t t1
Definition wifi.hpp:749
uint64_t t3
Definition wifi.hpp:751
uint32_t rtt
Definition wifi.hpp:748
uint8_t dlog_token
Definition wifi.hpp:746
uint64_t t4
Definition wifi.hpp:752
Information about an FTM report.
Definition wifi.hpp:1202
std::vector< ftm_report_entry > entries
Definition wifi.hpp:1208
HE (High Efficiency) AP information.
Definition wifi.hpp:671
Information about a home channel change.
Definition wifi.hpp:1185
std::optional< enum second_channel > old_second
Definition wifi.hpp:1187
std::optional< enum second_channel > new_second
Definition wifi.hpp:1189
Configuration for WiFi initialization.
Definition wifi.hpp:775
std::optional< bool > nvs_enable
Definition wifi.hpp:784
std::optional< bool > ampdu_rx_enable
Definition wifi.hpp:782
std::optional< unsigned int > static_rx_buf_num
Definition wifi.hpp:776
std::optional< unsigned int > dynamic_rx_buf_num
Definition wifi.hpp:777
std::optional< unsigned int > rx_ba_win
Definition wifi.hpp:781
std::optional< unsigned int > dynamic_tx_buf_num
Definition wifi.hpp:779
std::optional< unsigned int > static_tx_buf_num
Definition wifi.hpp:778
std::optional< unsigned int > cache_tx_buf_num
Definition wifi.hpp:780
std::optional< bool > ampdu_tx_enable
Definition wifi.hpp:783
std::optional< core_id > wifi_task_core_id
Definition wifi.hpp:785
Protected Management Frame (PMF) configuration.
Definition wifi.hpp:792
Protocol configuration for dual-band operation.
Definition wifi.hpp:867
flags< protocol > ghz_5g
Definition wifi.hpp:869
flags< protocol > ghz_2g
Definition wifi.hpp:868
Configuration for a WiFi scan operation.
Definition wifi.hpp:845
Default scan timing parameters.
Definition wifi.hpp:856
Information about a completed scan.
Definition wifi.hpp:1094
Configuration for WiFi station mode.
Definition wifi.hpp:801
std::string password
Definition wifi.hpp:803
Information about a station connected to the soft-AP.
Definition wifi.hpp:729
mac_address mac
Definition wifi.hpp:730