From 735eada5f1fe25bafcf6c58af12edcd72b9b42db Mon Sep 17 00:00:00 2001 From: Dane Slattery Date: Wed, 29 Oct 2025 11:05:18 +0200 Subject: [PATCH 1/7] [feat] Add method to get current access point info controller (#4401) --- esp-radio/src/wifi/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index f4959c121cf..1aff16e516b 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -3135,6 +3135,33 @@ impl WifiController<'_> { } } + + /// Get the Access Point information of AP to which the device is associated with. + /// The value is obtained from the last beacon. + /// + ///
+ /// + /// - Use this API only in STA or AP-STA mode. + /// - This API should be called after the station has connected to an access point. + ///
+ /// + /// # Errors + /// This function returns [`WifiError::Unsupported`] if the STA side isn't + /// running. For example, when configured for AP only. + pub fn get_apinfo(&self) -> Result { + if self.mode()?.is_sta() { + let mut record: MaybeUninit = MaybeUninit::uninit(); + + esp_wifi_result!(unsafe { esp_wifi_sta_get_ap_info(record) })?; + + let ap_info = convert_ap_info(record); + Ok(ap_info) + } else { + Err(WifiError::Unsupported) + } + } + + /// Get the supported capabilities of the controller. pub fn capabilities(&self) -> Result, WifiError> { let caps = From 8658e3b03b054712ee6603ca0228208d2bf26779 Mon Sep 17 00:00:00 2001 From: Dane Slattery Date: Wed, 29 Oct 2025 11:10:12 +0200 Subject: [PATCH 2/7] add changelog entry --- esp-radio/CHANGELOG.md | 1 + esp-radio/src/wifi/mod.rs | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/esp-radio/CHANGELOG.md b/esp-radio/CHANGELOG.md index 7eb55f8f7f3..c5220e9c741 100644 --- a/esp-radio/CHANGELOG.md +++ b/esp-radio/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- It's now possible to obtain the access point info of the currently connected AP, by using `WifiController::ap_info(&self)` (#4401) ### Changed diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 1aff16e516b..9ebebc8d20e 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -3135,7 +3135,6 @@ impl WifiController<'_> { } } - /// Get the Access Point information of AP to which the device is associated with. /// The value is obtained from the last beacon. /// @@ -3148,7 +3147,7 @@ impl WifiController<'_> { /// # Errors /// This function returns [`WifiError::Unsupported`] if the STA side isn't /// running. For example, when configured for AP only. - pub fn get_apinfo(&self) -> Result { + pub fn ap_info(&self) -> Result { if self.mode()?.is_sta() { let mut record: MaybeUninit = MaybeUninit::uninit(); @@ -3161,7 +3160,6 @@ impl WifiController<'_> { } } - /// Get the supported capabilities of the controller. pub fn capabilities(&self) -> Result, WifiError> { let caps = From 58ba6a27f56e05e5130408a30838e138b37b0951 Mon Sep 17 00:00:00 2001 From: Dane Slattery Date: Wed, 29 Oct 2025 13:31:22 +0200 Subject: [PATCH 3/7] fix build errors --- esp-radio/src/wifi/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 9ebebc8d20e..9998cd712f7 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -125,6 +125,7 @@ use crate::binary::{ esp_wifi_set_protocol, esp_wifi_set_tx_done_cb, esp_wifi_sta_get_rssi, + esp_wifi_sta_get_ap_info, esp_wifi_start, esp_wifi_stop, g_wifi_default_wpa_crypto_funcs, From ca7ad54fc6e52413280dbf2c2d0cd7b63bf50d4d Mon Sep 17 00:00:00 2001 From: Dane Slattery Date: Wed, 29 Oct 2025 13:31:48 +0200 Subject: [PATCH 4/7] fix error unwrap --- esp-radio/src/wifi/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 9998cd712f7..0db62266a68 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -3151,8 +3151,8 @@ impl WifiController<'_> { pub fn ap_info(&self) -> Result { if self.mode()?.is_sta() { let mut record: MaybeUninit = MaybeUninit::uninit(); - - esp_wifi_result!(unsafe { esp_wifi_sta_get_ap_info(record) })?; + let record = unsafe { MaybeUninit::assume_init_mut(&mut record) }; + esp_wifi_result!(unsafe { include::esp_wifi_sta_get_ap_info(record) })?; let ap_info = convert_ap_info(record); Ok(ap_info) From 7f18a252b1738c816de0e1ea7a5b9a9c88ceec4b Mon Sep 17 00:00:00 2001 From: Dane Slattery Date: Wed, 29 Oct 2025 13:41:52 +0200 Subject: [PATCH 5/7] use the use --- esp-radio/src/wifi/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 0db62266a68..683b5efa442 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -3152,7 +3152,7 @@ impl WifiController<'_> { if self.mode()?.is_sta() { let mut record: MaybeUninit = MaybeUninit::uninit(); let record = unsafe { MaybeUninit::assume_init_mut(&mut record) }; - esp_wifi_result!(unsafe { include::esp_wifi_sta_get_ap_info(record) })?; + esp_wifi_result!(unsafe { esp_wifi_sta_get_ap_info(record) })?; let ap_info = convert_ap_info(record); Ok(ap_info) From 1cdd84279c385409c5419fbc6938d5e7433c47db Mon Sep 17 00:00:00 2001 From: Dane Slattery Date: Thu, 30 Oct 2025 08:50:02 +0200 Subject: [PATCH 6/7] Adjust PR comments --- esp-radio/src/wifi/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 683b5efa442..da69d313e9d 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -3151,10 +3151,10 @@ impl WifiController<'_> { pub fn ap_info(&self) -> Result { if self.mode()?.is_sta() { let mut record: MaybeUninit = MaybeUninit::uninit(); - let record = unsafe { MaybeUninit::assume_init_mut(&mut record) }; - esp_wifi_result!(unsafe { esp_wifi_sta_get_ap_info(record) })?; + esp_wifi_result!(unsafe { esp_wifi_sta_get_ap_info(record.as_mut_ptr()) })?; - let ap_info = convert_ap_info(record); + let record = unsafe { MaybeUninit::assume_init( record) }; + let ap_info = convert_ap_info(&record); Ok(ap_info) } else { Err(WifiError::Unsupported) From 327260ac56108791c8b9e61df51a5ed7f150bbe3 Mon Sep 17 00:00:00 2001 From: Dane Slattery Date: Thu, 30 Oct 2025 08:58:33 +0200 Subject: [PATCH 7/7] fmt --- esp-radio/src/wifi/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index da69d313e9d..b063aaa64fb 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -124,8 +124,8 @@ use crate::binary::{ esp_wifi_set_mode, esp_wifi_set_protocol, esp_wifi_set_tx_done_cb, - esp_wifi_sta_get_rssi, esp_wifi_sta_get_ap_info, + esp_wifi_sta_get_rssi, esp_wifi_start, esp_wifi_stop, g_wifi_default_wpa_crypto_funcs, @@ -3153,7 +3153,7 @@ impl WifiController<'_> { let mut record: MaybeUninit = MaybeUninit::uninit(); esp_wifi_result!(unsafe { esp_wifi_sta_get_ap_info(record.as_mut_ptr()) })?; - let record = unsafe { MaybeUninit::assume_init( record) }; + let record = unsafe { MaybeUninit::assume_init(record) }; let ap_info = convert_ap_info(&record); Ok(ap_info) } else {