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 <chrono>
31#include <cstdint>
32#include <electro/decibel>
33#include <esp_idf_version.h>
34#include <esp_wifi_types.h>
35#include <optional>
36#include <soc/soc_caps.h>
37#include <span>
38#include <string>
39#include <string_view>
40#include <vector>
41
42namespace idfxx::wifi {
43
44// =============================================================================
45// Enumerations
46// =============================================================================
47
56enum class role : uint32_t {
57 // clang-format off
58 sta = 1,
59 ap = 2,
60 // clang-format on
61};
62
67enum class auth_mode : int {
68 // clang-format off
69 open = 0,
70 wep = 1,
71 wpa_psk = 2,
72 wpa2_psk = 3,
73 wpa_wpa2_psk = 4,
74 wpa2_enterprise = 5,
75 wpa3_psk = 6,
76 wpa2_wpa3_psk = 7,
77 wapi_psk = 8,
78 owe = 9,
79 wpa3_ent_192 = 10,
80 dpp = 13,
81 wpa3_enterprise = 14,
83 wpa_enterprise = 16,
84 // clang-format on
85};
86
91enum class power_save : int {
92 // clang-format off
93 none = 0,
94 min_modem = 1,
95 max_modem = 2,
96 // clang-format on
97};
98
103enum class bandwidth : int {
104 // clang-format off
105 ht20 = 1,
106 ht40 = 2,
107 bw80 = 3,
108 bw160 = 4,
109 bw80_80 = 5,
110 // clang-format on
111};
112
117enum class scan_type : int {
118 // clang-format off
119 active = 0,
120 passive = 1,
121 // clang-format on
122};
123
128enum class second_channel : int {
129 // clang-format off
130 above = 1,
131 below = 2,
132 // clang-format on
133};
134
139enum class sort_method : int {
140 // clang-format off
141 by_rssi = 0,
142 by_security = 1,
143 // clang-format on
144};
145
153enum class disconnect_reason : uint16_t {
154 // clang-format off
155 // IEEE 802.11 standard reasons
156 unspecified = 1,
157 auth_expire = 2,
158 auth_leave = 3,
159 assoc_expire = 4,
160 assoc_toomany = 5,
161 not_authed = 6,
162 not_assoced = 7,
163 assoc_leave = 8,
164 assoc_not_authed = 9,
168 ie_invalid = 13,
169 mic_failure = 14,
172 ie_in_4way_differs = 17,
175 akmp_invalid = 20,
177 invalid_rsn_ie_cap = 22,
181 tdls_unspecified = 26,
184 bad_cipher_or_akm = 29,
187 unspecified_qos = 32,
189 missing_acks = 34,
190 exceeded_txop = 35,
191 sta_leaving = 36,
192 end_ba = 37,
193 unknown_ba = 38,
194 timeout = 39,
195 peer_initiated = 46,
196 ap_initiated = 47,
198 invalid_pmkid = 49,
199 invalid_mde = 50,
200 invalid_fte = 51,
204 // Vendor-specific reasons (200+)
205 beacon_timeout = 200,
206 no_ap_found = 201,
207 auth_fail = 202,
208 assoc_fail = 203,
209 handshake_timeout = 204,
210 connection_fail = 205,
211 ap_tsf_reset = 206,
212 roaming = 207,
214 sa_query_timeout = 209,
218 // clang-format on
219};
220
225enum class cipher_type : int {
226 // clang-format off
227 none = 0,
228 wep40 = 1,
229 wep104 = 2,
230 tkip = 3,
231 ccmp = 4,
232 tkip_ccmp = 5,
233 aes_cmac128 = 6,
234 sms4 = 7,
235 gcmp = 8,
236 gcmp256 = 9,
237 aes_gmac128 = 10,
238 aes_gmac256 = 11,
239 unknown = 12,
240 // clang-format on
241};
242
247enum class phy_mode : int {
248 // clang-format off
249 lr = 0,
250 b11b = 1,
251 b11g = 2,
252 b11a = 3,
253 ht20 = 4,
254 ht40 = 5,
255 he20 = 6,
256 vht20 = 7,
257 // clang-format on
258};
259
264enum class band : int {
265 // clang-format off
266 ghz_2g = 1,
267 ghz_5g = 2,
268 // clang-format on
269};
270
275enum class band_mode : int {
276 // clang-format off
277 ghz_2g_only = 1,
278 ghz_5g_only = 2,
279 auto_mode = 3,
280 // clang-format on
281};
282
290enum class channel_5g : uint32_t {
291 // clang-format off
292 ch36 = 1u << 1,
293 ch40 = 1u << 2,
294 ch44 = 1u << 3,
295 ch48 = 1u << 4,
296 ch52 = 1u << 5,
297 ch56 = 1u << 6,
298 ch60 = 1u << 7,
299 ch64 = 1u << 8,
300 ch100 = 1u << 9,
301 ch104 = 1u << 10,
302 ch108 = 1u << 11,
303 ch112 = 1u << 12,
304 ch116 = 1u << 13,
305 ch120 = 1u << 14,
306 ch124 = 1u << 15,
307 ch128 = 1u << 16,
308 ch132 = 1u << 17,
309 ch136 = 1u << 18,
310 ch140 = 1u << 19,
311 ch144 = 1u << 20,
312 ch149 = 1u << 21,
313 ch153 = 1u << 22,
314 ch157 = 1u << 23,
315 ch161 = 1u << 24,
316 ch165 = 1u << 25,
317 ch169 = 1u << 26,
318 ch173 = 1u << 27,
319 ch177 = 1u << 28,
320 all = 0x1FFFFFFE,
321 // clang-format on
322};
323
328enum class storage : int {
329 // clang-format off
330 flash = 0,
331 ram = 1,
332 // clang-format on
333};
334
339enum class country_policy : int {
340 // clang-format off
341 auto_policy = 0,
342 manual = 1,
343 // clang-format on
344};
345
350enum class scan_method : int {
351 // clang-format off
352 fast = 0,
353 all_channel = 1,
354 // clang-format on
355};
356
361enum class sae_pwe_method : int {
362 // clang-format off
363 hunt_and_peck = 1,
364 hash_to_element = 2,
365 // clang-format on
366};
367
372enum class sae_pk_mode : int {
373 // clang-format off
374 automatic = 0,
375 only = 1,
376 disabled = 2,
377 // clang-format on
378};
379
386enum class protocol : uint8_t {
387 // clang-format off
388 b11b = 0x01,
389 b11g = 0x02,
390 b11n = 0x04,
391 lr = 0x08,
392 b11a = 0x10,
393 b11ac = 0x20,
394 b11ax = 0x40,
395 // clang-format on
396};
397
402enum class promiscuous_pkt_type : int {
403 // clang-format off
404 mgmt = 0,
405 ctrl = 1,
406 data = 2,
407 misc = 3,
408 // clang-format on
409};
410
417enum class promiscuous_filter : uint32_t {
418 // clang-format off
419 all = 0xFFFFFFFF,
420 mgmt = 1u << 0,
421 ctrl = 1u << 1,
422 data = 1u << 2,
423 misc = 1u << 3,
424 data_mpdu = 1u << 4,
425 data_ampdu = 1u << 5,
426 fcsfail = 1u << 6,
427 // clang-format on
428};
429
436enum class promiscuous_ctrl_filter : uint32_t {
437 // clang-format off
438 all = 0xFF800000,
439 wrapper = 1u << 23,
440 bar = 1u << 24,
441 ba = 1u << 25,
442 pspoll = 1u << 26,
443 rts = 1u << 27,
444 cts = 1u << 28,
445 ack = 1u << 29,
446 cfend = 1u << 30,
447 cfendack = 1u << 31,
448 // clang-format on
449};
450
458enum class event_mask : uint32_t {
459 // clang-format off
460 all = 0xFFFFFFFF,
461 none = 0,
462 ap_probe_req_rx = 1u << 0,
463 // clang-format on
464};
465
473enum class statis_module : uint32_t {
474 // clang-format off
475 buffer = 1u << 0,
476 rxtx = 1u << 1,
477 hw = 1u << 2,
478 diag = 1u << 3,
479 ps = 1u << 4,
480 all = 0xFFFFFFFF,
481 // clang-format on
482};
483
488enum class vendor_ie_type : int {
489 // clang-format off
490 beacon = 0,
491 probe_req = 1,
492 probe_resp = 2,
493 assoc_req = 3,
494 assoc_resp = 4,
495 // clang-format on
496};
497
502enum class vendor_ie_id : int {
503 // clang-format off
504 id_0 = 0,
505 id_1 = 1,
506 // clang-format on
507};
508
513enum class ftm_status : int {
514 // clang-format off
515 success = 0,
516 unsupported = 1,
517 conf_rejected = 2,
518 no_response = 3,
519 fail = 4,
520 no_valid_msmt = 5,
521 user_term = 6,
522 // clang-format on
523};
524
533enum class phy_rate : int {
534 // clang-format off
535 // 802.11b long preamble
536 rate_1m_l = 0x00,
537 rate_2m_l = 0x01,
538 rate_5m_l = 0x02,
539 rate_11m_l = 0x03,
540 // 802.11b short preamble
541 rate_2m_s = 0x05,
542 rate_5m_s = 0x06,
543 rate_11m_s = 0x07,
544 // OFDM (802.11a/g)
545 rate_48m = 0x08,
546 rate_24m = 0x09,
547 rate_12m = 0x0A,
548 rate_6m = 0x0B,
549 rate_54m = 0x0C,
550 rate_36m = 0x0D,
551 rate_18m = 0x0E,
552 rate_9m = 0x0F,
553 // HT (802.11n) long GI
554 mcs0_lgi = 0x10,
555 mcs1_lgi = 0x11,
556 mcs2_lgi = 0x12,
557 mcs3_lgi = 0x13,
558 mcs4_lgi = 0x14,
559 mcs5_lgi = 0x15,
560 mcs6_lgi = 0x16,
561 mcs7_lgi = 0x17,
562#if SOC_WIFI_HE_SUPPORT
563 mcs8_lgi = 0x18,
564 mcs9_lgi = 0x19,
565#endif
566 // HT (802.11n) short GI
567#if SOC_WIFI_HE_SUPPORT
568 mcs0_sgi = 0x1A,
569#else
570 mcs0_sgi = 0x18,
571#endif
572 mcs1_sgi = mcs0_sgi + 1,
573 mcs2_sgi = mcs0_sgi + 2,
574 mcs3_sgi = mcs0_sgi + 3,
575 mcs4_sgi = mcs0_sgi + 4,
576 mcs5_sgi = mcs0_sgi + 5,
577 mcs6_sgi = mcs0_sgi + 6,
578 mcs7_sgi = mcs0_sgi + 7,
579#if SOC_WIFI_HE_SUPPORT
580 mcs8_sgi = mcs0_sgi + 8,
581 mcs9_sgi = mcs0_sgi + 9,
582#endif
583 // Long Range (Espressif proprietary)
584 lora_250k = 0x29,
585 lora_500k = 0x2A,
586 // clang-format on
587};
588
589} // namespace idfxx::wifi
590
592template<>
593inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::role> = true;
594template<>
595inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::protocol> = true;
596template<>
597inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::promiscuous_filter> = true;
598template<>
599inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::promiscuous_ctrl_filter> = true;
600template<>
601inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::channel_5g> = true;
602template<>
603inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::event_mask> = true;
604template<>
605inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::sae_pwe_method> = true;
606template<>
607inline constexpr bool idfxx::enable_flags_operators<idfxx::wifi::statis_module> = true;
610namespace idfxx::wifi {
611
612// =============================================================================
613// Error handling
614// =============================================================================
615
625enum class errc : esp_err_t {
626 // clang-format off
627 // ----- 0x3001..0x301C — ESP_ERR_WIFI_* aliases -----
628 not_init = 0x3001,
629 not_started = 0x3002,
630 not_stopped = 0x3003,
631 if_error = 0x3004,
632 mode = 0x3005,
633 state = 0x3006,
634 conn = 0x3007,
635 nvs = 0x3008,
636 mac = 0x3009,
637 ssid = 0x300A,
638 password = 0x300B,
639 timeout = 0x300C,
640 wake_fail = 0x300D,
641 would_block = 0x300E,
642 not_connect = 0x300F,
643 post = 0x3012,
644 init_state = 0x3013,
645 stop_state = 0x3014,
646 not_assoc = 0x3015,
647 tx_disallow = 0x3016,
648 twt_full = 0x3017,
649 twt_setup_timeout = 0x3018,
650 twt_setup_txfail = 0x3019,
651 twt_setup_reject = 0x301A,
652 discard = 0x301B,
653 roc_in_progress = 0x301C,
655 // ----- idfxx-only validation codes (no ESP-IDF counterpart) -----
656 value_too_large = 1,
657 // clang-format on
658};
659
664class error_category : public std::error_category {
665public:
667 [[nodiscard]] const char* name() const noexcept override final;
668
670 [[nodiscard]] std::string message(int ec) const override final;
671
687 [[nodiscard]] bool equivalent(int code, const std::error_condition& condition) const noexcept override final;
688};
689
690// =============================================================================
691// Data types
692// =============================================================================
693
701 uint8_t bss_color;
704 uint8_t bssid_index;
706 [[nodiscard]] constexpr bool operator==(const he_ap_info&) const noexcept = default;
707};
708
714 std::array<char, 3> cc = {'0', '1', '\0'};
715 uint8_t start_channel = 1;
716 uint8_t num_channels = 11;
717 electro::dbm max_tx_power{20};
718 enum country_policy policy = country_policy::auto_policy;
719#if SOC_WIFI_SUPPORT_5G
720 flags<channel_5g> channels_5g{};
721#endif
722
723 [[nodiscard]] constexpr bool operator==(const country_config&) const noexcept = default;
724};
725
732struct ap_record {
734 std::string ssid;
735 electro::dbm rssi;
737 std::optional<enum second_channel> second;
741 bool phy_11b;
742 bool phy_11g;
743 bool phy_11n;
744 bool phy_lr;
745 bool phy_11a;
746 bool phy_11ac;
747 bool phy_11ax;
748 bool wps;
751 struct country_config country;
752 struct he_ap_info he_ap;
754 uint8_t vht_ch_freq1;
755 uint8_t vht_ch_freq2;
757 [[nodiscard]] bool operator==(const ap_record&) const = default;
758};
759
764struct sta_info {
766 electro::dbm rssi;
767 bool phy_11b;
768 bool phy_11g;
769 bool phy_11n;
770 bool phy_lr;
771 bool phy_11a;
772 bool phy_11ac;
773 bool phy_11ax;
775 [[nodiscard]] constexpr bool operator==(const sta_info&) const noexcept = default;
776};
777
783 uint8_t dlog_token;
784 electro::dbm rssi;
785 uint32_t rtt;
786 uint64_t t1;
787 uint64_t t2;
788 uint64_t t3;
789 uint64_t t4;
791 [[nodiscard]] constexpr bool operator==(const ftm_report_entry&) const noexcept = default;
792};
793
794// =============================================================================
795// Configuration structs
796// =============================================================================
797
815 std::optional<unsigned int> static_rx_buf_num;
816 std::optional<unsigned int> dynamic_rx_buf_num;
817 std::optional<unsigned int> static_tx_buf_num;
818 std::optional<unsigned int> dynamic_tx_buf_num;
819 std::optional<unsigned int> cache_tx_buf_num;
820 std::optional<unsigned int> rx_ba_win;
821 std::optional<bool> ampdu_rx_enable;
822 std::optional<bool> ampdu_tx_enable;
823 std::optional<bool> nvs_enable;
824 std::optional<core_id> wifi_task_core_id;
826 [[nodiscard]] constexpr bool operator==(const init_config&) const noexcept = default;
827};
828
834 bool capable = false;
835 bool required = false;
837 [[nodiscard]] constexpr bool operator==(const pmf_config&) const noexcept = default;
838};
839
845 std::string ssid;
846 std::string password;
847 std::optional<mac_address> bssid = {};
848 uint8_t channel = 0;
849 enum scan_method scan_method = scan_method::fast;
850 enum sort_method sort_method = sort_method::by_rssi;
851 enum auth_mode auth_threshold = auth_mode::open;
852 electro::dbm rssi_threshold{-127};
853 struct pmf_config pmf = {};
854 uint16_t listen_interval = 0;
855 bool rm_enabled = false;
856 bool btm_enabled = false;
857 bool mbo_enabled = false;
858 bool ft_enabled = false;
859 bool owe_enabled = false;
860 bool transition_disable = false;
861 flags<sae_pwe_method> sae_pwe_h2e = {};
862 enum sae_pk_mode sae_pk_mode = sae_pk_mode::automatic;
863 uint8_t failure_retry_cnt = 0;
865 [[nodiscard]] bool operator==(const sta_config&) const = default;
866};
867
872struct ap_config {
873 std::string ssid;
874 std::string password;
875 uint8_t channel = 1;
876 enum auth_mode authmode = auth_mode::open;
877 uint8_t ssid_hidden = 0;
878 uint8_t max_connection = 4;
879 uint16_t beacon_interval = 100;
880 enum cipher_type pairwise_cipher = cipher_type::tkip_ccmp;
881 bool ftm_responder = false;
882 struct pmf_config pmf = {};
883 flags<sae_pwe_method> sae_pwe_h2e = {};
885 [[nodiscard]] bool operator==(const ap_config&) const = default;
886};
887
893 std::string ssid;
894 uint8_t channel = 0;
895 bool show_hidden = false;
896 enum scan_type scan_type = scan_type::active;
898 [[nodiscard]] bool operator==(const scan_config&) const = default;
899};
900
906 std::chrono::milliseconds active_scan_min{0};
907 std::chrono::milliseconds active_scan_max{120};
908 std::chrono::milliseconds passive_scan{360};
909 std::chrono::milliseconds home_chan_dwell_time{30};
911 [[nodiscard]] constexpr bool operator==(const scan_default_params&) const noexcept = default;
912};
913
922 [[nodiscard]] constexpr bool operator==(const protocols_config&) const noexcept = default;
923};
924
930 enum bandwidth ghz_2g = bandwidth::ht20;
931 enum bandwidth ghz_5g = bandwidth::ht20;
933 [[nodiscard]] constexpr bool operator==(const bandwidths_config&) const noexcept = default;
934};
935
941 uint8_t primary;
942 std::optional<enum second_channel> second;
944 [[nodiscard]] constexpr bool operator==(const channel_info&) const noexcept = default;
945};
946
953 uint8_t channel = 0;
954 uint8_t frame_count = 0;
955 std::chrono::milliseconds burst_period{
956 0
957 };
958#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 0, 0)
959 bool use_get_report_api = false;
960#endif
961
962 [[nodiscard]] constexpr bool operator==(const ftm_initiator_config&) const noexcept = default;
963};
964
981#if !SOC_WIFI_HE_SUPPORT
983 bool lltf_en = true;
984 bool htltf_en = true;
985 bool stbc_htltf2_en = true;
986 bool ltf_merge_en = true;
987 bool channel_filter_en = true;
988 bool manu_scale = false;
989 uint8_t shift = 0;
990 bool dump_ack_en = false;
992 [[nodiscard]] constexpr bool operator==(const csi_config&) const noexcept = default;
993};
994#elif SOC_WIFI_MAC_VERSION_NUM == 3
995struct csi_config {
996 bool enable = false;
997 bool acquire_csi_legacy = false;
998 bool acquire_csi_force_lltf = false;
999 bool acquire_csi_ht20 = false;
1000 bool acquire_csi_ht40 = false;
1001 bool acquire_csi_vht = false;
1002 bool acquire_csi_su = false;
1003 bool acquire_csi_mu = false;
1004 bool acquire_csi_dcm = false;
1005 bool acquire_csi_beamformed = false;
1006 uint8_t acquire_csi_he_stbc_mode = 0;
1007 uint8_t val_scale_cfg = 0;
1008 bool dump_ack_en = false;
1009 bool lltf_bit_mode = false;
1011 [[nodiscard]] constexpr bool operator==(const csi_config&) const noexcept = default;
1012};
1013#else
1014struct csi_config {
1015 bool enable = false;
1016 bool acquire_csi_legacy = false;
1017 bool acquire_csi_ht20 = false;
1018 bool acquire_csi_ht40 = false;
1019 bool acquire_csi_su = false;
1020 bool acquire_csi_mu = false;
1021 bool acquire_csi_dcm = false;
1022 bool acquire_csi_beamformed = false;
1023 uint8_t acquire_csi_he_stbc = 0;
1024 uint8_t val_scale_cfg = 0;
1025 bool dump_ack_en = false;
1027 [[nodiscard]] constexpr bool operator==(const csi_config&) const noexcept = default;
1028};
1029#endif
1030
1031// =============================================================================
1032// WiFi events
1033// =============================================================================
1034
1048enum class event_id : int32_t {
1049 // clang-format off
1050 ready = 0,
1051 scan_done = 1,
1052 sta_start = 2,
1053 sta_stop = 3,
1054 sta_connected = 4,
1055 sta_disconnected = 5,
1057 sta_wps_er_success = 7,
1058 sta_wps_er_failed = 8,
1059 sta_wps_er_timeout = 9,
1060 sta_wps_er_pin = 10,
1062 ap_start = 12,
1063 ap_stop = 13,
1064 ap_sta_connected = 14,
1065 ap_sta_disconnected = 15,
1067 ftm_report = 17,
1068 sta_bss_rssi_low = 18,
1069 action_tx_status = 19,
1070 roc_done = 20,
1071 sta_beacon_timeout = 21,
1073 ap_wps_rg_success = 23,
1074 ap_wps_rg_failed = 24,
1075 ap_wps_rg_timeout = 25,
1076 ap_wps_rg_pin = 26,
1078 itwt_setup = 28,
1079 itwt_teardown = 29,
1080 itwt_probe = 30,
1081 itwt_suspend = 31,
1082 twt_wakeup = 32,
1083 btwt_setup = 33,
1084 btwt_teardown = 34,
1085 nan_started = 35,
1086 nan_stopped = 36,
1087 nan_svc_match = 37,
1088 nan_replied = 38,
1089 nan_receive = 39,
1090 ndp_indication = 40,
1091 ndp_confirm = 41,
1092 ndp_terminated = 42,
1093 home_channel_change = 43,
1094 sta_neighbor_rep = 44,
1095 ap_wrong_password = 45,
1097 dpp_uri_ready = 47,
1098 dpp_cfg_recvd = 48,
1099 dpp_failed = 49,
1100 // clang-format on
1101};
1102
1110extern const event_base<event_id> events;
1111
1113inline event_base<event_id> idfxx_get_event_base(event_id*) {
1114 return events;
1115}
1118// =============================================================================
1119// Event data wrappers
1120// =============================================================================
1121
1130 std::string ssid;
1131 uint8_t channel;
1135 static connected_event_data from_opaque(const void* event_data);
1137
1138 [[nodiscard]] bool operator==(const connected_event_data&) const = default;
1139};
1140
1149 std::string ssid;
1153 static disconnected_event_data from_opaque(const void* event_data);
1155
1156 [[nodiscard]] bool operator==(const disconnected_event_data&) const = default;
1157};
1158
1166 uint32_t status;
1167 uint8_t number;
1168 uint8_t scan_id;
1171 static scan_done_event_data from_opaque(const void* event_data);
1173
1174 [[nodiscard]] constexpr bool operator==(const scan_done_event_data&) const noexcept = default;
1175};
1176
1188 static authmode_change_event_data from_opaque(const void* event_data);
1190
1191 [[nodiscard]] constexpr bool operator==(const authmode_change_event_data&) const noexcept = default;
1192};
1193
1202 uint8_t aid;
1205 static ap_sta_connected_event_data from_opaque(const void* event_data);
1207
1208 [[nodiscard]] constexpr bool operator==(const ap_sta_connected_event_data&) const noexcept = default;
1209};
1210
1219 uint8_t aid;
1223 static ap_sta_disconnected_event_data from_opaque(const void* event_data);
1225
1226 [[nodiscard]] constexpr bool operator==(const ap_sta_disconnected_event_data&) const noexcept = default;
1227};
1228
1236 electro::dbm rssi;
1240 static ap_probe_req_event_data from_opaque(const void* event_data);
1242
1243 [[nodiscard]] constexpr bool operator==(const ap_probe_req_event_data&) const noexcept = default;
1244};
1245
1253 electro::dbm rssi;
1256 static bss_rssi_low_event_data from_opaque(const void* event_data);
1258
1259 [[nodiscard]] constexpr bool operator==(const bss_rssi_low_event_data&) const noexcept = default;
1260};
1261
1269 uint8_t old_primary;
1270 std::optional<enum second_channel> old_second;
1271 uint8_t new_primary;
1272 std::optional<enum second_channel> new_second;
1275 static home_channel_change_event_data from_opaque(const void* event_data);
1277
1278 [[nodiscard]] constexpr bool operator==(const home_channel_change_event_data&) const noexcept = default;
1279};
1280
1290 uint32_t rtt_raw;
1291 uint32_t rtt_est;
1292 uint32_t dist_est;
1293 std::vector<ftm_report_entry> entries;
1296 static ftm_report_event_data from_opaque(const void* event_data);
1298
1299 [[nodiscard]] bool operator==(const ftm_report_event_data&) const = default;
1300};
1301
1302// =============================================================================
1303// Typed events
1304// =============================================================================
1305
1306// WiFi events with data
1331
1332// WiFi events without data
1415
1416// =============================================================================
1417// Free function API — Lifecycle
1418// =============================================================================
1419
1420#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1432void init(const init_config& cfg = {});
1433
1440void deinit();
1441
1451void start();
1452
1459void stop();
1460
1469void restore();
1470#endif
1471
1481[[nodiscard]] result<void> try_init(const init_config& cfg = {});
1482
1489
1498[[nodiscard]] result<void> try_start();
1499
1506
1515
1516// =============================================================================
1517// Free function API — Roles
1518// =============================================================================
1519
1520#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1530
1539[[nodiscard]] flags<role> get_roles();
1540#endif
1541
1549
1556
1557// =============================================================================
1558// Free function API — STA config
1559// =============================================================================
1560
1561#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1571
1581#endif
1582
1590
1597
1598// =============================================================================
1599// Free function API — AP config
1600// =============================================================================
1601
1602#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1611void set_ap_config(const ap_config& cfg);
1612
1621[[nodiscard]] ap_config get_ap_config();
1622
1631void deauth_sta(uint16_t aid);
1632
1641[[nodiscard]] std::vector<sta_info> get_sta_list();
1642
1652[[nodiscard]] uint16_t ap_get_sta_aid(mac_address mac);
1653#endif
1654
1661[[nodiscard]] result<void> try_set_ap_config(const ap_config& cfg);
1662
1669
1676[[nodiscard]] result<void> try_deauth_sta(uint16_t aid);
1677
1684
1692
1693// =============================================================================
1694// Free function API — Connect / disconnect
1695// =============================================================================
1696
1697#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1707void connect();
1708
1736template<typename Rep, typename Period>
1737[[nodiscard]] net::ipv4_info connect_sta(const sta_config& cfg, std::chrono::duration<Rep, Period> timeout);
1738
1746
1754
1763[[nodiscard]] uint16_t sta_get_aid();
1764
1774#endif
1775
1785
1806[[nodiscard]] result<net::ipv4_info> try_connect_sta(const sta_config& cfg, std::chrono::milliseconds timeout);
1807
1811template<typename Rep, typename Period>
1812[[nodiscard]] result<net::ipv4_info>
1813try_connect_sta(const sta_config& cfg, std::chrono::duration<Rep, Period> timeout) {
1814 return try_connect_sta(cfg, std::chrono::ceil<std::chrono::milliseconds>(timeout));
1815}
1816
1823
1830
1837
1844
1845// =============================================================================
1846// Free function API — Scanning
1847// =============================================================================
1848
1849#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
1861[[nodiscard]] std::vector<ap_record> scan(const scan_config& cfg = {});
1862
1875void scan_start(const scan_config& cfg = {});
1876
1887[[nodiscard]] std::vector<ap_record> scan_get_results();
1888
1896
1905[[nodiscard]] uint16_t scan_get_ap_num();
1906
1914
1924
1934#endif
1935
1945
1956[[nodiscard]] result<void> try_scan_start(const scan_config& cfg = {});
1957
1966
1973
1980
1987
1995
2002
2003// =============================================================================
2004// Free function API — Power save
2005// =============================================================================
2006
2007#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2017
2026[[nodiscard]] enum power_save get_power_save();
2027#endif
2028
2036
2043
2044// =============================================================================
2045// Free function API — Bandwidth
2046// =============================================================================
2047
2048#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2058void set_bandwidth(enum role iface, enum bandwidth bw);
2059
2069[[nodiscard]] enum bandwidth get_bandwidth(enum role iface);
2070
2080void set_bandwidths(enum role iface, const bandwidths_config& bw);
2081
2091[[nodiscard]] bandwidths_config get_bandwidths(enum role iface);
2092#endif
2093
2101[[nodiscard]] result<void> try_set_bandwidth(enum role iface, enum bandwidth bw);
2102
2110
2118[[nodiscard]] result<void> try_set_bandwidths(enum role iface, const bandwidths_config& bw);
2119
2127
2128// =============================================================================
2129// Free function API — MAC
2130// =============================================================================
2131
2132#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2142void set_mac(enum role iface, mac_address mac);
2143
2153[[nodiscard]] mac_address get_mac(enum role iface);
2154#endif
2155
2163[[nodiscard]] result<void> try_set_mac(enum role iface, mac_address mac);
2164
2171[[nodiscard]] result<mac_address> try_get_mac(enum role iface);
2172
2173// =============================================================================
2174// Free function API — AP info
2175// =============================================================================
2176
2177#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2186[[nodiscard]] ap_record get_ap_info();
2187#endif
2188
2195
2196// =============================================================================
2197// Free function API — Channel
2198// =============================================================================
2199
2200#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2210void set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2211
2221#endif
2222
2230[[nodiscard]] result<void> try_set_channel(uint8_t primary, std::optional<enum second_channel> second = std::nullopt);
2231
2238
2239// =============================================================================
2240// Free function API — Country
2241// =============================================================================
2242
2243#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2253
2263
2273void set_country_code(std::string_view cc, bool ieee80211d_enabled);
2274
2283[[nodiscard]] std::string get_country_code();
2284#endif
2285
2293
2300
2308[[nodiscard]] result<void> try_set_country_code(std::string_view cc, bool ieee80211d_enabled);
2309
2316
2317// =============================================================================
2318// Free function API — TX power
2319// =============================================================================
2320
2321#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2331void set_max_tx_power(electro::centi_dbm power);
2332
2341[[nodiscard]] electro::centi_dbm get_max_tx_power();
2342#endif
2343
2351[[nodiscard]] result<void> try_set_max_tx_power(electro::centi_dbm power);
2352
2360
2361// =============================================================================
2362// Free function API — RSSI
2363// =============================================================================
2364
2365#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2374void set_rssi_threshold(electro::dbm threshold);
2375
2384[[nodiscard]] electro::dbm get_rssi();
2385#endif
2386
2393[[nodiscard]] result<void> try_set_rssi_threshold(electro::dbm threshold);
2394
2401
2402// =============================================================================
2403// Free function API — Protocol
2404// =============================================================================
2405
2406#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2416void set_protocol(enum role iface, flags<protocol> protos);
2417
2427[[nodiscard]] flags<protocol> get_protocol(enum role iface);
2428
2438void set_protocols(enum role iface, const protocols_config& cfg);
2439
2449[[nodiscard]] protocols_config get_protocols(enum role iface);
2450#endif
2451
2459[[nodiscard]] result<void> try_set_protocol(enum role iface, flags<protocol> protos);
2460
2468
2476[[nodiscard]] result<void> try_set_protocols(enum role iface, const protocols_config& cfg);
2477
2485
2486// =============================================================================
2487// Free function API — Band
2488// =============================================================================
2489
2490#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2499void set_band(enum band b);
2500
2509[[nodiscard]] enum band get_band();
2510
2520
2529[[nodiscard]] enum band_mode get_band_mode();
2530#endif
2531
2538[[nodiscard]] result<void> try_set_band(enum band b);
2539
2546
2554
2561
2562// =============================================================================
2563// Free function API — Storage
2564// =============================================================================
2565
2566#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2576#endif
2577
2585
2586// =============================================================================
2587// Free function API — Inactive time
2588// =============================================================================
2589
2590#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2600void set_inactive_time(enum role iface, std::chrono::seconds timeout);
2601
2611[[nodiscard]] std::chrono::seconds get_inactive_time(enum role iface);
2612#endif
2613
2621[[nodiscard]] result<void> try_set_inactive_time(enum role iface, std::chrono::seconds timeout);
2622
2630
2631// =============================================================================
2632// Free function API — Event mask
2633// =============================================================================
2634
2635#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2647
2657#endif
2658
2668
2675
2676// =============================================================================
2677// Free function API — Force wakeup
2678// =============================================================================
2679
2680#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2690
2698#endif
2699
2708
2715
2716// =============================================================================
2717// Free function API — Promiscuous mode
2718// =============================================================================
2719
2728using promiscuous_rx_cb = void (*)(const wifi_promiscuous_pkt_t* pkt, promiscuous_pkt_type type);
2729
2730#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2739void set_promiscuous(bool en);
2740
2749[[nodiscard]] bool get_promiscuous();
2750
2764
2774
2784
2794
2804#endif
2805
2812[[nodiscard]] result<void> try_set_promiscuous(bool en);
2813
2820
2832
2840
2847
2855
2862
2863// =============================================================================
2864// Free function API — Raw 802.11
2865// =============================================================================
2866
2872using tx_80211_done_cb = void (*)(const esp_80211_tx_info_t* tx_info);
2873
2874#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2885void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2886
2899#endif
2900
2909[[nodiscard]] result<void> try_tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq);
2910
2921
2922// =============================================================================
2923// Free function API — Vendor IE
2924// =============================================================================
2925
2933 void (*)(void* ctx, enum vendor_ie_type type, mac_address sa, const vendor_ie_data_t* ie, electro::dbm rssi);
2934
2935#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
2947void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2948
2958void set_vendor_ie_cb(vendor_ie_cb cb, void* ctx);
2959#endif
2960
2970[[nodiscard]] result<void>
2971try_set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie);
2972
2981
2982// =============================================================================
2983// Free function API — CSI
2984// =============================================================================
2985
2992using csi_rx_cb = void (*)(void* ctx, const wifi_csi_info_t* info);
2993
2994#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3003void set_csi(bool en);
3004
3014
3024
3034void set_csi_rx_cb(csi_rx_cb cb, void* ctx);
3035#endif
3036
3043[[nodiscard]] result<void> try_set_csi(bool en);
3044
3052
3059
3067[[nodiscard]] result<void> try_set_csi_rx_cb(csi_rx_cb cb, void* ctx);
3068
3069// =============================================================================
3070// Free function API — FTM
3071// =============================================================================
3072
3073#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3083
3091
3100void ftm_resp_set_offset(int16_t offset);
3101
3111[[nodiscard]] std::vector<ftm_report_entry> ftm_get_report(size_t max_entries);
3112#endif
3113
3121
3128
3135[[nodiscard]] result<void> try_ftm_resp_set_offset(int16_t offset);
3136
3144
3145// =============================================================================
3146// Free function API — Miscellaneous
3147// =============================================================================
3148
3157[[nodiscard]] int64_t get_tsf_time(enum role iface);
3158
3159#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3169
3179void config_11b_rate(enum role iface, bool disable);
3180
3190void config_80211_tx_rate(enum role iface, enum phy_rate rate);
3191
3200void disable_pmf_config(enum role iface);
3201
3210void set_dynamic_cs(bool enabled);
3211
3221void connectionless_module_set_wake_interval(std::chrono::milliseconds interval);
3222#endif
3223
3231
3239[[nodiscard]] result<void> try_config_11b_rate(enum role iface, bool disable);
3240
3248[[nodiscard]] result<void> try_config_80211_tx_rate(enum role iface, enum phy_rate rate);
3249
3256[[nodiscard]] result<void> try_disable_pmf_config(enum role iface);
3257
3264[[nodiscard]] result<void> try_set_dynamic_cs(bool enabled);
3265
3273[[nodiscard]] result<void> try_connectionless_module_set_wake_interval(std::chrono::milliseconds interval);
3274
3275// =============================================================================
3276// Inline definitions — exception-based API
3277// =============================================================================
3278
3281#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3282
3283// Lifecycle
3284inline void init(const init_config& cfg) {
3285 unwrap(try_init(cfg));
3286}
3287inline void deinit() {
3288 unwrap(try_deinit());
3289}
3290inline void start() {
3291 unwrap(try_start());
3292}
3293inline void stop() {
3294 unwrap(try_stop());
3295}
3296inline void restore() {
3298}
3299
3300// Roles
3301inline void set_roles(flags<role> roles) {
3302 unwrap(try_set_roles(roles));
3303}
3304inline flags<role> get_roles() {
3305 return unwrap(try_get_roles());
3306}
3307
3308// STA config
3309inline void set_sta_config(const sta_config& cfg) {
3311}
3312inline sta_config get_sta_config() {
3313 return unwrap(try_get_sta_config());
3314}
3315
3316// AP config
3317inline void set_ap_config(const ap_config& cfg) {
3319}
3320inline ap_config get_ap_config() {
3321 return unwrap(try_get_ap_config());
3322}
3323inline void deauth_sta(uint16_t aid) {
3324 unwrap(try_deauth_sta(aid));
3325}
3326inline std::vector<sta_info> get_sta_list() {
3327 return unwrap(try_get_sta_list());
3328}
3329inline uint16_t ap_get_sta_aid(mac_address mac) {
3330 return unwrap(try_ap_get_sta_aid(mac));
3331}
3332
3333// Connect / disconnect
3334template<typename Rep, typename Period>
3335[[nodiscard]] net::ipv4_info connect_sta(const sta_config& cfg, std::chrono::duration<Rep, Period> timeout) {
3336 return unwrap(try_connect_sta(cfg, std::chrono::ceil<std::chrono::milliseconds>(timeout)));
3337}
3338inline void connect() {
3340}
3341inline void disconnect() {
3343}
3344inline void clear_fast_connect() {
3346}
3347inline uint16_t sta_get_aid() {
3348 return unwrap(try_sta_get_aid());
3349}
3350inline enum phy_mode get_negotiated_phymode() {
3352}
3353
3354// Scanning
3355inline std::vector<ap_record> scan(const scan_config& cfg) {
3356 return unwrap(try_scan(cfg));
3357}
3358inline void scan_start(const scan_config& cfg) {
3359 unwrap(try_scan_start(cfg));
3360}
3361inline std::vector<ap_record> scan_get_results() {
3362 return unwrap(try_scan_get_results());
3363}
3364inline void scan_stop() {
3366}
3367inline uint16_t scan_get_ap_num() {
3368 return unwrap(try_scan_get_ap_num());
3369}
3370inline void clear_ap_list() {
3372}
3373inline void set_scan_parameters(const scan_default_params& params) {
3375}
3376inline scan_default_params get_scan_parameters() {
3378}
3379
3380// Power save
3381inline void set_power_save(enum power_save ps) {
3383}
3384inline enum power_save get_power_save() {
3385 return unwrap(try_get_power_save());
3386}
3387
3388// Bandwidth
3389inline void set_bandwidth(enum role iface, enum bandwidth bw) {
3390 unwrap(try_set_bandwidth(iface, bw));
3391}
3392inline enum bandwidth get_bandwidth(enum role iface) {
3393 return unwrap(try_get_bandwidth(iface));
3394}
3395inline void set_bandwidths(enum role iface, const bandwidths_config& bw) {
3396 unwrap(try_set_bandwidths(iface, bw));
3397}
3398inline bandwidths_config get_bandwidths(enum role iface) {
3399 return unwrap(try_get_bandwidths(iface));
3400}
3401
3402// MAC
3403inline void set_mac(enum role iface, mac_address mac) {
3404 unwrap(try_set_mac(iface, mac));
3405}
3406inline mac_address get_mac(enum role iface) {
3407 return unwrap(try_get_mac(iface));
3408}
3409
3410// AP info
3411inline ap_record get_ap_info() {
3412 return unwrap(try_get_ap_info());
3413}
3414
3415// Channel
3416inline void set_channel(uint8_t primary, std::optional<enum second_channel> second) {
3417 unwrap(try_set_channel(primary, second));
3418}
3419inline channel_info get_channel() {
3420 return unwrap(try_get_channel());
3421}
3422
3423// Country
3424inline void set_country(const country_config& cfg) {
3425 unwrap(try_set_country(cfg));
3426}
3427inline country_config get_country() {
3428 return unwrap(try_get_country());
3429}
3430inline void set_country_code(std::string_view cc, bool ieee80211d_enabled) {
3431 unwrap(try_set_country_code(cc, ieee80211d_enabled));
3432}
3433inline std::string get_country_code() {
3434 return unwrap(try_get_country_code());
3435}
3436
3437// TX power
3438inline void set_max_tx_power(electro::centi_dbm power) {
3440}
3441inline electro::centi_dbm get_max_tx_power() {
3442 return unwrap(try_get_max_tx_power());
3443}
3444
3445// RSSI
3446inline void set_rssi_threshold(electro::dbm threshold) {
3447 unwrap(try_set_rssi_threshold(threshold));
3448}
3449inline electro::dbm get_rssi() {
3450 return unwrap(try_get_rssi());
3451}
3452
3453// Protocol
3454inline void set_protocol(enum role iface, flags<protocol> protos) {
3455 unwrap(try_set_protocol(iface, protos));
3456}
3457inline flags<protocol> get_protocol(enum role iface) {
3458 return unwrap(try_get_protocol(iface));
3459}
3460inline void set_protocols(enum role iface, const protocols_config& cfg) {
3461 unwrap(try_set_protocols(iface, cfg));
3462}
3463inline protocols_config get_protocols(enum role iface) {
3464 return unwrap(try_get_protocols(iface));
3465}
3466
3467// Band
3468inline void set_band(enum band b) {
3469 unwrap(try_set_band(b));
3470}
3471inline enum band get_band() {
3472 return unwrap(try_get_band());
3473}
3474inline void set_band_mode(enum band_mode m) {
3476}
3477inline enum band_mode get_band_mode() {
3478 return unwrap(try_get_band_mode());
3479}
3480
3481// Storage
3482inline void set_storage(enum storage s) {
3484}
3485
3486// Inactive time
3487inline void set_inactive_time(enum role iface, std::chrono::seconds timeout) {
3489}
3490inline std::chrono::seconds get_inactive_time(enum role iface) {
3491 return unwrap(try_get_inactive_time(iface));
3492}
3493
3494// Event mask
3495inline void set_event_mask(flags<event_mask> mask) {
3497}
3498inline flags<event_mask> get_event_mask() {
3499 return unwrap(try_get_event_mask());
3500}
3501
3502// Force wakeup
3503inline void force_wakeup_acquire() {
3505}
3506inline void force_wakeup_release() {
3508}
3509
3510// Promiscuous mode
3511inline void set_promiscuous(bool en) {
3513}
3514inline bool get_promiscuous() {
3515 return unwrap(try_get_promiscuous());
3516}
3519}
3520inline void set_promiscuous_filter(flags<promiscuous_filter> filter) {
3522}
3523inline flags<promiscuous_filter> get_promiscuous_filter() {
3525}
3526inline void set_promiscuous_ctrl_filter(flags<promiscuous_ctrl_filter> filter) {
3528}
3529inline flags<promiscuous_ctrl_filter> get_promiscuous_ctrl_filter() {
3531}
3532
3533// Raw 802.11
3534inline void tx_80211(enum role iface, std::span<const uint8_t> buffer, bool en_sys_seq) {
3535 unwrap(try_tx_80211(iface, buffer, en_sys_seq));
3536}
3537inline void register_80211_tx_cb(tx_80211_done_cb cb) {
3539}
3540
3541// Vendor IE
3542inline void set_vendor_ie(bool enable, enum vendor_ie_type type, enum vendor_ie_id id, const void* vnd_ie) {
3543 unwrap(try_set_vendor_ie(enable, type, id, vnd_ie));
3544}
3545inline void set_vendor_ie_cb(vendor_ie_cb cb, void* ctx) {
3546 unwrap(try_set_vendor_ie_cb(cb, ctx));
3547}
3548
3549// CSI
3550inline void set_csi(bool en) {
3551 unwrap(try_set_csi(en));
3552}
3553inline void set_csi_config(const csi_config& cfg) {
3555}
3556inline csi_config get_csi_config() {
3557 return unwrap(try_get_csi_config());
3558}
3559inline void set_csi_rx_cb(csi_rx_cb cb, void* ctx) {
3560 unwrap(try_set_csi_rx_cb(cb, ctx));
3561}
3562
3563// FTM
3564inline void ftm_initiate_session(const ftm_initiator_config& cfg) {
3566}
3567inline void ftm_end_session() {
3569}
3570inline void ftm_resp_set_offset(int16_t offset) {
3572}
3573inline std::vector<ftm_report_entry> ftm_get_report(size_t max_entries) {
3574 return unwrap(try_ftm_get_report(max_entries));
3575}
3576
3577// Miscellaneous
3578inline void statis_dump(flags<statis_module> modules) {
3579 unwrap(try_statis_dump(modules));
3580}
3581inline void config_11b_rate(enum role iface, bool disable) {
3582 unwrap(try_config_11b_rate(iface, disable));
3583}
3584inline void config_80211_tx_rate(enum role iface, enum phy_rate rate) {
3585 unwrap(try_config_80211_tx_rate(iface, rate));
3586}
3587inline void disable_pmf_config(enum role iface) {
3589}
3590inline void set_dynamic_cs(bool enabled) {
3591 unwrap(try_set_dynamic_cs(enabled));
3592}
3593inline void connectionless_module_set_wake_interval(std::chrono::milliseconds interval) {
3595}
3596
3597#endif // CONFIG_COMPILER_CXX_EXCEPTIONS
3598
3601// =============================================================================
3602// Default netif creation helpers
3603// =============================================================================
3604
3605#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
3618
3631#endif
3632
3642
3652
3653} // namespace idfxx::wifi
3654
3655namespace idfxx {
3656
3662[[nodiscard]] const wifi::error_category& wifi_category() noexcept;
3663
3674[[nodiscard]] std::unexpected<std::error_code> wifi_error(esp_err_t e);
3675
3676// =============================================================================
3677// String conversion
3678// =============================================================================
3679
3687[[nodiscard]] std::string to_string(flags<wifi::role> roles);
3688
3696[[nodiscard]] std::string to_string(wifi::auth_mode m);
3697
3705[[nodiscard]] std::string to_string(wifi::cipher_type c);
3706
3714[[nodiscard]] std::string to_string(wifi::disconnect_reason r);
3715
3716} // namespace idfxx
3717
3718namespace idfxx::wifi {
3719
3727[[nodiscard]] inline std::error_code make_error_code(errc e) noexcept {
3728 return {std::to_underlying(e), wifi_category()};
3729}
3730
3731} // namespace idfxx::wifi
3732
3734namespace std {
3735template<>
3736struct is_error_code_enum<idfxx::wifi::errc> : true_type {};
3737} // namespace std
3740#include "sdkconfig.h"
3741#ifdef CONFIG_IDFXX_STD_FORMAT
3743#include <algorithm>
3744#include <format>
3745namespace std {
3746
3747template<>
3748struct formatter<idfxx::flags<idfxx::wifi::role>> {
3749 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3750
3751 template<typename FormatContext>
3752 auto format(idfxx::flags<idfxx::wifi::role> roles, FormatContext& ctx) const {
3753 auto s = idfxx::to_string(roles);
3754 return std::copy(s.begin(), s.end(), ctx.out());
3755 }
3756};
3757
3758template<>
3759struct formatter<idfxx::wifi::auth_mode> {
3760 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3761
3762 template<typename FormatContext>
3763 auto format(idfxx::wifi::auth_mode m, FormatContext& ctx) const {
3764 auto s = idfxx::to_string(m);
3765 return std::copy(s.begin(), s.end(), ctx.out());
3766 }
3767};
3768
3769template<>
3770struct formatter<idfxx::wifi::cipher_type> {
3771 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3772
3773 template<typename FormatContext>
3774 auto format(idfxx::wifi::cipher_type c, FormatContext& ctx) const {
3775 auto s = idfxx::to_string(c);
3776 return std::copy(s.begin(), s.end(), ctx.out());
3777 }
3778};
3779
3780template<>
3781struct formatter<idfxx::wifi::disconnect_reason> {
3782 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
3783
3784 template<typename FormatContext>
3785 auto format(idfxx::wifi::disconnect_reason r, FormatContext& ctx) const {
3786 auto s = idfxx::to_string(r);
3787 return std::copy(s.begin(), s.end(), ctx.out());
3788 }
3789};
3790
3791} // namespace std
3793#endif // CONFIG_IDFXX_STD_FORMAT
3794
// end of idfxx_wifi
Typed event base template.
Definition event.hpp:90
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:664
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
constexpr bool operator==(const allocator< T, Caps, Alignment > &, const allocator< U, Caps, Alignment > &) noexcept
Equality comparison for allocator.
Definition memory.hpp:439
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:1316
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:1394
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:1386
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:1330
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:264
result< void > try_set_csi_rx_cb(csi_rx_cb cb, void *ctx)
Registers a callback for CSI data reception.
constexpr idfxx::event< event_id, ap_sta_disconnected_event_data > ap_sta_disconnected
Station disconnected from soft-AP event.
Definition wifi.hpp:1318
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:103
void(*)(void *ctx, enum vendor_ie_type type, mac_address sa, const vendor_ie_data_t *ie, electro::dbm rssi) vendor_ie_cb
Callback invoked when a matching vendor-specific IE is received.
Definition wifi.hpp:2933
void(*)(const wifi_promiscuous_pkt_t *pkt, promiscuous_pkt_type type) promiscuous_rx_cb
Callback invoked for each packet received in promiscuous mode.
Definition wifi.hpp:2728
constexpr idfxx::event< event_id > connectionless_module_wake_interval_start
Connectionless module wake interval start event.
Definition wifi.hpp:1360
event_mask
WiFi event mask flags.
Definition wifi.hpp:458
void set_rssi_threshold(electro::dbm threshold)
Sets the RSSI threshold for the sta_bss_rssi_low event.
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:1378
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:1412
void set_max_tx_power(electro::centi_dbm power)
Sets the maximum transmit power.
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:1338
promiscuous_pkt_type
Promiscuous mode packet type.
Definition wifi.hpp:402
constexpr idfxx::event< event_id > sta_wps_er_timeout
WPS enrollee timeout event.
Definition wifi.hpp:1350
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.
result< void > try_set_max_tx_power(electro::centi_dbm power)
Sets the maximum transmit power.
storage
WiFi configuration storage location.
Definition wifi.hpp:328
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:1366
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:417
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_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:1340
constexpr idfxx::event< event_id > twt_wakeup
TWT wakeup event.
Definition wifi.hpp:1382
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< net::ipv4_info > try_connect_sta(const sta_config &cfg, std::chrono::milliseconds timeout)
Connects to an access point as a station and waits for an IPv4 address.
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:1358
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.
result< void > try_set_inactive_time(enum role iface, std::chrono::seconds timeout)
Sets the inactive time before a station is deauthenticated.
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:1406
auth_mode
WiFi authentication mode.
Definition wifi.hpp:67
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.
promiscuous_ctrl_filter
Promiscuous mode control frame sub-type filter flags.
Definition wifi.hpp:436
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:1354
void force_wakeup_acquire()
Acquires a WiFi wakeup lock.
void set_csi_rx_cb(csi_rx_cb cb, void *ctx)
Registers a callback for CSI data reception.
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:1048
@ connectionless_module_wake_interval_start
result< std::vector< sta_info > > try_get_sta_list()
Gets the list of stations connected to the soft-AP.
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:372
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:502
constexpr idfxx::event< event_id, ap_probe_req_event_data > ap_probe_req_received
Probe request received by soft-AP event.
Definition wifi.hpp:1322
constexpr idfxx::event< event_id > itwt_teardown
Individual TWT teardown event.
Definition wifi.hpp:1376
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< netif::interface > try_make_sta_netif()
Creates a default WiFi station network interface.
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.
electro::dbm get_rssi()
Gets the current RSSI of the connected AP.
bool get_promiscuous()
Gets whether promiscuous mode is enabled.
constexpr idfxx::event< event_id > itwt_setup
Individual TWT setup event.
Definition wifi.hpp:1374
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:1310
protocols_config get_protocols(enum role iface)
Gets the enabled WiFi protocols for dual-band operation.
scan_method
WiFi scan method.
Definition wifi.hpp:350
void register_80211_tx_cb(tx_80211_done_cb cb)
Registers a callback for 802.11 TX completion.
constexpr idfxx::event< event_id > action_tx_status
Action frame TX status event.
Definition wifi.hpp:1356
second_channel
WiFi secondary channel position relative to the primary channel.
Definition wifi.hpp:128
statis_module
WiFi statistics module flags.
Definition wifi.hpp:473
std::chrono::seconds get_inactive_time(enum role iface)
Gets the inactive time before a station is deauthenticated.
netif::interface make_ap_netif()
Creates a default WiFi access point network interface.
result< netif::interface > try_make_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:139
constexpr idfxx::event< event_id > ap_wps_rg_pbc_overlap
AP WPS PBC overlap detected event.
Definition wifi.hpp:1372
errc
Error codes for WiFi operations.
Definition wifi.hpp:625
cipher_type
WiFi cipher type.
Definition wifi.hpp:225
scan_type
WiFi scan type.
Definition wifi.hpp:117
constexpr idfxx::event< event_id > sta_neighbor_rep
Station neighbor report received event.
Definition wifi.hpp:1404
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:275
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:533
result< void > try_set_vendor_ie_cb(vendor_ie_cb cb, void *ctx)
Registers a callback for received vendor-specific IEs.
constexpr idfxx::event< event_id, home_channel_change_event_data > home_channel_change
Home channel changed event.
Definition wifi.hpp:1326
void set_bandwidth(enum role iface, enum bandwidth bw)
Sets the channel bandwidth for the specified interface.
result< electro::centi_dbm > try_get_max_tx_power()
Gets the current maximum transmit power.
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:1384
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:1346
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:386
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:1368
result< void > try_connectionless_module_set_wake_interval(std::chrono::milliseconds interval)
Sets the connectionless module wake interval.
void set_promiscuous_rx_cb(promiscuous_rx_cb cb)
Sets the promiscuous mode receive callback.
void statis_dump(flags< statis_module > modules)
Dumps WiFi statistics for the specified modules.
vendor_ie_type
Vendor-specific IE type.
Definition wifi.hpp:488
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.
result< std::chrono::seconds > try_get_inactive_time(enum role iface)
Gets the inactive time before a station is deauthenticated.
void set_power_save(enum power_save ps)
Sets the power save mode.
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.
void connectionless_module_set_wake_interval(std::chrono::milliseconds interval)
Sets the connectionless module wake interval.
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_vendor_ie_cb(vendor_ie_cb cb, void *ctx)
Registers a callback for received vendor-specific IEs.
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:1396
disconnect_reason
WiFi disconnection reason codes.
Definition wifi.hpp:153
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:1308
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:247
void(*)(const esp_80211_tx_info_t *tx_info) tx_80211_done_cb
Callback invoked when a raw 802.11 frame transmission completes.
Definition wifi.hpp:2872
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:1410
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.
result< void > try_set_rssi_threshold(electro::dbm threshold)
Sets the RSSI threshold for the sta_bss_rssi_low event.
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.
netif::interface make_sta_netif()
Creates a default WiFi station network interface.
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.
constexpr idfxx::event< event_id > sta_wps_er_pin
WPS enrollee PIN received event.
Definition wifi.hpp:1352
constexpr idfxx::event< event_id, bss_rssi_low_event_data > sta_bss_rssi_low
BSS RSSI dropped below threshold event.
Definition wifi.hpp:1324
constexpr idfxx::event< event_id > ndp_indication
NDP indication event.
Definition wifi.hpp:1398
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:1380
void set_protocols(enum role iface, const protocols_config &cfg)
Sets the enabled WiFi protocols for dual-band operation.
ftm_status
FTM (Fine Timing Measurement) session status.
Definition wifi.hpp:513
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:91
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:1408
constexpr idfxx::event< event_id > nan_svc_match
NAN service match event.
Definition wifi.hpp:1392
role
WiFi role (station and/or access point).
Definition wifi.hpp:56
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:1312
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:1364
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:1348
void(*)(void *ctx, const wifi_csi_info_t *info) csi_rx_cb
Callback invoked for each received CSI (Channel State Information) record.
Definition wifi.hpp:2992
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:1336
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.
electro::centi_dbm get_max_tx_power()
Gets the current maximum transmit power.
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.
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:290
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.
constexpr idfxx::event< event_id > ready
WiFi ready event.
Definition wifi.hpp:1334
result< flags< protocol > > try_get_protocol(enum role iface)
Gets the enabled WiFi protocols for the specified interface.
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:1414
result< void > try_connect()
Connects to the configured access point.
constexpr idfxx::event< event_id > nan_stopped
NAN stopped event.
Definition wifi.hpp:1390
void set_inactive_time(enum role iface, std::chrono::seconds timeout)
Sets the inactive time before a station is deauthenticated.
constexpr idfxx::event< event_id, authmode_change_event_data > sta_authmode_change
Station authentication mode changed event.
Definition wifi.hpp:1314
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:1370
result< void > try_register_80211_tx_cb(tx_80211_done_cb cb)
Registers a callback for 802.11 TX completion.
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< void > try_set_promiscuous_rx_cb(promiscuous_rx_cb cb)
Sets the promiscuous mode receive callback.
net::ipv4_info connect_sta(const sta_config &cfg, std::chrono::duration< Rep, Period > timeout)
Connects to an access point as a station and waits for an IPv4 address.
constexpr idfxx::event< event_id > ndp_terminated
NDP terminated event.
Definition wifi.hpp:1402
constexpr idfxx::event< event_id > ndp_confirm
NDP confirm event.
Definition wifi.hpp:1400
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:361
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:339
constexpr idfxx::event< event_id > nan_started
NAN started event.
Definition wifi.hpp:1388
result< electro::dbm > try_get_rssi()
Gets the current RSSI of the connected AP.
constexpr idfxx::event< event_id > sta_beacon_timeout
Station beacon timeout event.
Definition wifi.hpp:1344
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:1342
Definition adc.hpp:48
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.
A typed event that pairs an event ID with its data type.
Definition event.hpp:195
IPv4 network interface information.
Definition net.hpp:232
Configuration for WiFi access point mode.
Definition wifi.hpp:872
bool operator==(const ap_config &) const =default
std::string ssid
Definition wifi.hpp:873
std::string password
Definition wifi.hpp:874
Information about a probe request received by the soft-AP.
Definition wifi.hpp:1235
constexpr bool operator==(const ap_probe_req_event_data &) const noexcept=default
Information about a discovered access point.
Definition wifi.hpp:732
uint8_t primary_channel
Definition wifi.hpp:736
enum cipher_type pairwise_cipher
Definition wifi.hpp:739
electro::dbm rssi
Definition wifi.hpp:735
std::optional< enum second_channel > second
Definition wifi.hpp:737
bool operator==(const ap_record &) const =default
std::string ssid
Definition wifi.hpp:734
mac_address bssid
Definition wifi.hpp:733
enum auth_mode authmode
Definition wifi.hpp:738
enum bandwidth bw
Definition wifi.hpp:753
enum cipher_type group_cipher
Definition wifi.hpp:740
Information about a station connecting to the soft-AP.
Definition wifi.hpp:1200
constexpr bool operator==(const ap_sta_connected_event_data &) const noexcept=default
Information about a station disconnecting from the soft-AP.
Definition wifi.hpp:1217
constexpr bool operator==(const ap_sta_disconnected_event_data &) const noexcept=default
Information about an authentication mode change.
Definition wifi.hpp:1183
constexpr bool operator==(const authmode_change_event_data &) const noexcept=default
Bandwidth configuration for dual-band operation.
Definition wifi.hpp:929
constexpr bool operator==(const bandwidths_config &) const noexcept=default
Information about BSS RSSI dropping below threshold.
Definition wifi.hpp:1252
constexpr bool operator==(const bss_rssi_low_event_data &) const noexcept=default
WiFi channel information.
Definition wifi.hpp:940
std::optional< enum second_channel > second
Definition wifi.hpp:942
constexpr bool operator==(const channel_info &) const noexcept=default
Information about a successful station connection.
Definition wifi.hpp:1128
bool operator==(const connected_event_data &) const =default
WiFi country configuration.
Definition wifi.hpp:713
constexpr bool operator==(const country_config &) const noexcept=default
CSI (Channel State Information) configuration.
Definition wifi.hpp:982
constexpr bool operator==(const csi_config &) const noexcept=default
Information about a station disconnection.
Definition wifi.hpp:1147
enum disconnect_reason reason
Definition wifi.hpp:1150
bool operator==(const disconnected_event_data &) const =default
FTM initiator session configuration.
Definition wifi.hpp:951
constexpr bool operator==(const ftm_initiator_config &) const noexcept=default
Single FTM report measurement entry.
Definition wifi.hpp:782
uint64_t t2
Definition wifi.hpp:787
constexpr bool operator==(const ftm_report_entry &) const noexcept=default
uint64_t t1
Definition wifi.hpp:786
uint64_t t3
Definition wifi.hpp:788
uint32_t rtt
Definition wifi.hpp:785
uint8_t dlog_token
Definition wifi.hpp:783
electro::dbm rssi
Definition wifi.hpp:784
uint64_t t4
Definition wifi.hpp:789
Information about an FTM report.
Definition wifi.hpp:1287
std::vector< ftm_report_entry > entries
Definition wifi.hpp:1293
bool operator==(const ftm_report_event_data &) const =default
HE (High Efficiency) AP information.
Definition wifi.hpp:700
constexpr bool operator==(const he_ap_info &) const noexcept=default
Information about a home channel change.
Definition wifi.hpp:1268
std::optional< enum second_channel > old_second
Definition wifi.hpp:1270
constexpr bool operator==(const home_channel_change_event_data &) const noexcept=default
std::optional< enum second_channel > new_second
Definition wifi.hpp:1272
Configuration for WiFi initialization.
Definition wifi.hpp:814
std::optional< bool > nvs_enable
Definition wifi.hpp:823
std::optional< bool > ampdu_rx_enable
Definition wifi.hpp:821
std::optional< unsigned int > static_rx_buf_num
Definition wifi.hpp:815
std::optional< unsigned int > dynamic_rx_buf_num
Definition wifi.hpp:816
std::optional< unsigned int > rx_ba_win
Definition wifi.hpp:820
constexpr bool operator==(const init_config &) const noexcept=default
std::optional< unsigned int > dynamic_tx_buf_num
Definition wifi.hpp:818
std::optional< unsigned int > static_tx_buf_num
Definition wifi.hpp:817
std::optional< unsigned int > cache_tx_buf_num
Definition wifi.hpp:819
std::optional< bool > ampdu_tx_enable
Definition wifi.hpp:822
std::optional< core_id > wifi_task_core_id
Definition wifi.hpp:824
Protected Management Frame (PMF) configuration.
Definition wifi.hpp:833
constexpr bool operator==(const pmf_config &) const noexcept=default
Protocol configuration for dual-band operation.
Definition wifi.hpp:918
flags< protocol > ghz_5g
Definition wifi.hpp:920
constexpr bool operator==(const protocols_config &) const noexcept=default
flags< protocol > ghz_2g
Definition wifi.hpp:919
Configuration for a WiFi scan operation.
Definition wifi.hpp:892
bool operator==(const scan_config &) const =default
Default scan timing parameters.
Definition wifi.hpp:905
constexpr bool operator==(const scan_default_params &) const noexcept=default
Information about a completed scan.
Definition wifi.hpp:1165
constexpr bool operator==(const scan_done_event_data &) const noexcept=default
Configuration for WiFi station mode.
Definition wifi.hpp:844
std::string password
Definition wifi.hpp:846
bool operator==(const sta_config &) const =default
Information about a station connected to the soft-AP.
Definition wifi.hpp:764
mac_address mac
Definition wifi.hpp:765
constexpr bool operator==(const sta_info &) const noexcept=default
electro::dbm rssi
Definition wifi.hpp:766