Skip to content

Conversation

@DaneSlattery
Copy link

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the latest Migration Guide.
  • My changes are in accordance to the esp-rs developer guidelines

Extra:

Pull Request Details 📖

Description

Resolves this issue #4401 by exposing the c api esp_wifi_sta_get_ap_info from the esp-wifi-sys crate

Testing

I tested this on an esp32 dev kit, modifying the example for embassy_dhcp:
I can include this change in the PR if required

     match controller.connect_async().await {
            Ok(_) => {
                println!("Wifi connected!");
                let ap = controller.ap_info().unwrap();
                println!("AP Info={ap:?}")
            }
            Err(e) => {
                println!("Failed to connect to wifi: {e:?}");
                Timer::after(Duration::from_millis(5000)).await
            }
        }

pub fn ap_info(&self) -> Result<AccessPointInfo, WifiError> {
if self.mode()?.is_sta() {
let mut record: MaybeUninit<include::wifi_ap_record_t> = MaybeUninit::uninit();
let record = unsafe { MaybeUninit::assume_init_mut(&mut record) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is UB, you can't do this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that now, assume_init_mut before is not the way to go.

TBH, I don’t know this FFI stuff to well so I just used the same idea as line 3047, should I fix that as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, we'll do that, just don't introduce more code like it, please :)

Copy link
Contributor

@bugadani bugadani Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #4408 - it's okay to pass a pointer like that to the C code, and assume C code has initialized the data if the call succeeds.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 7, 2025

this somehow fell off my radar - probably #4460 should get in first

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

Binary Size Report

esp32

sleep-timer Diff (PR vs. Base)
FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%      +5  [ = ]       0    [Unmapped]
-0.0%    -180  [ = ]       0    TOTAL

embassy-dhcp Diff (PR vs. Base)
FILE SIZE        VM SIZE    
--------------  -------------- 
+0.8% +3.23Ki  +0.8% +3.23Ki    .text
+33% +2.25Ki  [ = ]       0    [Unmapped]
+2.6% +1.52Ki  +2.7% +1.52Ki    .rodata
+1.3%    +136  +1.3%    +136    .data
+0.8%    +100  +0.8%    +100    .rwtext
[ = ]       0  -0.1%    -136    .stack
+0.8% +53.7Ki  +0.6% +4.85Ki    TOTAL

esp32c3

sleep-timer Diff (PR vs. Base)
FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%      +4  [ = ]       0    TOTAL

embassy-dhcp Diff (PR vs. Base)
FILE SIZE        VM SIZE    
--------------  -------------- 
+0.7% +2.82Ki  +0.7% +2.82Ki    .text
+2.7% +1.15Ki  +2.7% +1.15Ki    .rodata
+1.1%    +204  [ = ]       0    .eh_frame
+1.1%     +64  +1.1%     +64    .data
[ = ]       0  +0.0%      +8    .bss
[ = ]       0  +0.0%      +8    .rwdata_dummy
+0.1%      +8  +0.1%      +8    .rwtext
-0.2%     -41  [ = ]       0    [Unmapped]
[ = ]       0  -0.0%     -80    .stack
+0.6% +42.0Ki  +0.4% +3.98Ki    TOTAL

esp32c6

sleep-timer Diff (PR vs. Base)
FILE SIZE        VM SIZE    
--------------  -------------- 
-0.0%      -3  [ = ]       0    [Unmapped]
[ = ]       0  [ = ]       0    TOTAL

embassy-dhcp Diff (PR vs. Base)
FILE SIZE        VM SIZE    
--------------  -------------- 
+0.8% +3.48Ki  +0.8% +3.48Ki    .text
+2.2% +1.20Ki  +2.2% +1.20Ki    .rodata
+1.0%    +220  [ = ]       0    .eh_frame
+1.3%     +96  +1.3%     +96    .data
+0.7%     +76  +0.7%     +76    .rwtext
[ = ]       0  +0.0%      +8    .bss
[ = ]       0  -0.1%    -176    .stack
-6.9%    -867  [ = ]       0    [Unmapped]
+0.6% +49.7Ki  +0.4% +4.68Ki    TOTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants