Skip to content

survey: implement Nl80211SurveyInfo #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sh3Rm4n
Copy link
Contributor

@Sh3Rm4n Sh3Rm4n commented Apr 15, 2025

This adds the ability to trigger and parse the NL80211_ATTR_SURVEY_INFO similar to iw DEVICE survey dump.

I've added and example, which does dump the survey info. The device was set to AP mode via iw before

iw DEVICE set type __ap

The wifi chip I used is the Intel AX210NGW and the kernel loaded the firmware version 89. With this I was able to read out noise measurement values.

Depends on #23

src/handle.rs Outdated
@@ -41,6 +42,12 @@ impl Nl80211Handle {
Nl80211ScanHandle::new(self.clone())
}

// equivalent to `iw DEVICE survey dump` command
#[must_use]
Copy link
Member

Choose a reason for hiding this comment

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

This seems no fit for a crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

pub struct Nl80211SurveyHandle(Nl80211Handle);

impl Nl80211SurveyHandle {
#[must_use]
Copy link
Member

Choose a reason for hiding this comment

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

This seems not ideal for crate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@Sh3Rm4n Sh3Rm4n force-pushed the feature/survey-dump branch from fae8d2e to 5700ad9 Compare April 15, 2025 13:05
@cathay4t
Copy link
Member

Could you provide a script for me to try it out?

@Sh3Rm4n
Copy link
Contributor Author

Sh3Rm4n commented Apr 15, 2025

Could you provide a script for me to try it out?

Of course. As I've said, I'm using the Intel AX210 wifi card to obtain noise levels, but I'm sure there are other cards, which provide some detail in the survey info.

I've ran the script on a raspberry pi (kernel version 6.11 and iw version 6.9) setting it into AP mode with root privilages

# as wpa_supplicant is running by default on the raspberry pi stop it
systemctl stop wpa_supplicant
pkill wpa_supplicant
# now configure the Wifi Card (the Intel AX210 is enumrated as wlan1 for me)
ip link set wlan1 down
iw wlan set type __ap
ip link set wlan0 up
# this should now show the WLAN card in AP mode
iw wlan0 info

# now to trigger a scan to botain the survey info, run the nl80211_trigger_scan example (
cargo run --example nl80211_trigger_scan 4
# after that the dump survey should provide some info
cargo run --example dump_nl80211_survey 4

The iw approximate equivalent for the cargo examples would be

iw wlan1 scan passive
iw wlan1 survey dump

@Sh3Rm4n
Copy link
Contributor Author

Sh3Rm4n commented Apr 22, 2025

I've also added optional support for SurveyRadioStats in 10c1d6f similar to the --radio flag in iw.

For that I'd had to add the Nl80211Survey builder. Similar to scan the dump method can now receive all kinds of attributes instead of only the interface index and instead the builder is used to specify the correct attributes. I'm not sure if this is to open, but I've used scan as a reference.

@Sh3Rm4n Sh3Rm4n requested a review from cathay4t April 22, 2025 09:45
@cathay4t cathay4t force-pushed the feature/survey-dump branch from 6eaf204 to a64a093 Compare May 5, 2025 01:35
Copy link
Member

@cathay4t cathay4t left a comment

Choose a reason for hiding this comment

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

Could you add a document line indicate even kernel said NL80211_SURVEY_INFO_NOISE is u8, the iw and real world still treat it as i8.

#[allow(clippy::cast_sign_loss)]
match self {
Self::Frequency(d) => write_u32(buffer, *d),
Self::Noise(d) => buffer[0] = *d as u8,
Copy link
Member

Choose a reason for hiding this comment

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

i8::cast_unsigned()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to be a nightly feature https://doc.rust-lang.org/std/primitive.u8.html#method.cast_signed/, should I still use it? I'd prefer not to use nightly features, if no other nightly feature is used yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this was just stabilized, so I'll use it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've used cast_signed and uncast_signed instead of the as cast in the latest revision.

@cathay4t
Copy link
Member

cathay4t commented May 5, 2025

Please also squash these commits into single one. Thanks.

@Sh3Rm4n Sh3Rm4n force-pushed the feature/survey-dump branch from a64a093 to 3a3e82f Compare May 5, 2025 08:48
@Sh3Rm4n
Copy link
Contributor Author

Sh3Rm4n commented May 5, 2025

I've squashed the commits and added the comment as you suggested.

@Sh3Rm4n Sh3Rm4n force-pushed the feature/survey-dump branch from 3a3e82f to 6b77fa8 Compare May 5, 2025 09:06
@Sh3Rm4n Sh3Rm4n force-pushed the feature/survey-dump branch 3 times, most recently from d9da877 to 7d334b2 Compare May 20, 2025 15:08
@Sh3Rm4n Sh3Rm4n force-pushed the feature/survey-dump branch from 7d334b2 to ba42308 Compare May 21, 2025 10:00
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.

2 participants