Skip to content

Implement nl80211 and mac80211_hwsim generic Netlink constants#302

Draft
a-gavin wants to merge 3 commits intojbaublitz:mainfrom
a-gavin:dev
Draft

Implement nl80211 and mac80211_hwsim generic Netlink constants#302
a-gavin wants to merge 3 commits intojbaublitz:mainfrom
a-gavin:dev

Conversation

@a-gavin
Copy link
Contributor

@a-gavin a-gavin commented Oct 7, 2025

Something to chew on while I continue to add more to the neli-side of the nl80211 constants for a project I'm working on. I expect to add several more enums over the next month or so to the nl80211 definitions (mac80211_hwsim should be okay as is, pending any feedback).

Given this and this blocking feature request/issue I raised regarding NlattrType serialized types, I'm raising this as a draft. For a finalized PR, I plan to properly document the the nl80211 constants, update the existing nl80211 example to use the constants, and of course update the commit message.

For some quick context, the nl80211 generic Netlink interface is the primary method used to configure and query WiFi interfaces in the Linux kernel (e.g. wpa_supplicant/hostapd, iwd, iw). The mac80211_hwsim generic Netlink Interface is the communication method used to configure and query virtual WiFi radios in the Linux kernel and is used by several projects for virtualized testing (e.g. wpa_supplicant/hostapd, iwd).

To grab nl80211 definitions, this PR uses the linux-raw-sys crate as previously discussed. Support for all nl80211 Linux 6.16 constants landed in the linux-raw-sys crate which is included in the v0.11.0 release. Unlike nl80211, the mac80211_hwsim generic Netlink constants are only defined in the kernel module itself, so definitions are added manually.

Add support for Linux 'mac80211_hwsim' virtual WiFi driver
https://www.kernel.org/doc/html/next/networking/mac80211_hwsim/mac80211_hwsim.html

Unlike other netlink constants (e.g. 'nl80211'), these constants
are presently only available in the 'mac80211_hwsim' kernel driver
(specifically in 'mac80211_hwsim.h').

Somewhat confusingly, this header file includes both netlink API
constants and structs in addition to those which are driver-internal
only. To the best of my knowledge, the constants added in this commit
constitute all of the netlink API.
Copy link
Owner

@jbaublitz jbaublitz left a comment

Choose a reason for hiding this comment

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

Hi @a-gavin, thanks for the contribution.

I have a few notes about this PR. First of all, can you provide more information on where the constants are defined for the hardcoded constants? Are they not included in the crate that you pulled in?

Overall, I'll do a final review and probably include this as soon as you fix the documentation bug popping up in CI.

@a-gavin
Copy link
Contributor Author

a-gavin commented Nov 12, 2025

Hi @a-gavin, thanks for the contribution.

I have a few notes about this PR. First of all, can you provide more information on where the constants are defined for the hardcoded constants? Are they not included in the crate that you pulled in?

I detailed some info on the mac80211_hwsim constants both in the commit message as well as in a note in the mac80211_hwsim.rs constants file. Copying the commit message below:

mac80211_hwsim generic netlink support

Add support for Linux 'mac80211_hwsim' virtual WiFi driver
https://www.kernel.org/doc/html/next/networking/mac80211_hwsim/mac80211_hwsim.html

Unlike other netlink constants (e.g. 'nl80211'), these constants
are presently only available in the 'mac80211_hwsim' kernel driver
(specifically in 'mac80211_hwsim.h').

Somewhat confusingly, this header file includes both netlink API
constants and structs in addition to those which are driver-internal
only. To the best of my knowledge, the constants added in this commit
constitute all of the netlink API.

Definitions for mac80211_hwsim commands and attributes are available here, which is part of the driver and not "includable" from userspace (and thus not likely to be added to either linux-raw-sys or libc).

Overall, I'll do a final review and probably include this as soon as you fix the documentation bug popping up in CI.

Do you mind if I resubmit the mac80211_hwsim constants as one PR and follow up later with nl80211 constants later?

I submitted this as a draft to get feedback and would like to sort out the non-u16 netlink attribute issue before PR'ing nl80211 constants, as quite a few are affected there. This issue is also present for an attribute in mac80211_hwsim as well, but I'd be fine to submit and fix that later.

@a-gavin
Copy link
Contributor Author

a-gavin commented Nov 27, 2025

Submitted PR for just mac80211_hwsim here.

@jbaublitz
Copy link
Owner

Hi @a-gavin, I've finally found the time to reply to your issue. Please take a look at my response and let me know what you think. As for the new PR, I'll take a look once we've gotten on the same page about what we're seeing in the Wireshark dump.

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