Skip to content

feat: add support for setting/getting the wireless regulatory region#162

Open
tomasff wants to merge 4 commits into
mdlayher:mainfrom
tomasff:feat/set-reg-region
Open

feat: add support for setting/getting the wireless regulatory region#162
tomasff wants to merge 4 commits into
mdlayher:mainfrom
tomasff:feat/set-reg-region

Conversation

@tomasff

@tomasff tomasff commented Apr 5, 2026

Copy link
Copy Markdown

Allows setting the regulatory region so that we can use channels that are not available everywhere e.g. channel 13 on the 2.4ghz band.

ReloadRegulatoryDatabase - To reload the regulatory db if it was not available during early boot when cfg80211 is loaded. For example, in gokrazy cfg80211 is built into the kernel and attempts to load the regulatory.db before the root fs can be read.

SetRegulatoryRegion - To set the regulatory region used by all devices

Tested on gokrazy's wifi succesfully with region GB and channel 13 on a Pi Zero 2W.

@tomasff tomasff changed the title Add ability to reload reg db and set region Add support for reloading and setting the wireless regulatory region Apr 5, 2026
@tomasff tomasff changed the title Add support for reloading and setting the wireless regulatory region feat: add support for setting the wireless regulatory region Apr 5, 2026
@tomasff

tomasff commented Apr 8, 2026

Copy link
Copy Markdown
Author

Hi @SuperQ @nickgarlis - sorry for the direct ping, tried to add you as reviewer but GH won't let me 😅
Adding the ability to change the region, not sure if this would be in-scope for this package, but think it would be nice for environments like gokrazy.org.

Let me know what you think - thanks!

Comment thread client_linux.go
@nickgarlis

Copy link
Copy Markdown

Hi @tomasff

I don't see any reason why this shouldn't be part of the package. Do you think it'd be possible to add some integration tests for it ? Not sure what would be the best way to test it but I believe cfg80211 should be loaded on the GHA runners.

}
}

func TestClient_SetRegulatoryRegion(t *testing.T) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Intentionally simple as we cannot assume the regulatory database is available.

Could maybe check the region after with the caveat that the test may be flaky if the regulatory DB is not available.

@tomasff

tomasff commented Apr 9, 2026

Copy link
Copy Markdown
Author

Thanks!
Added some tests and an additional attribute (regulatory hint) that was previously missing.

Included a GetRegulatoryDomain method too - for now I've only populated the Region which I suspect will be the most used. There are a few others that can be added later if need be.

@tomasff tomasff requested a review from nickgarlis April 9, 2026 21:15
@tomasff tomasff changed the title feat: add support for setting the wireless regulatory region feat: add support for setting/getting the wireless regulatory region Apr 9, 2026
Comment thread client_linux.go
// See
// - https://wireless.docs.kernel.org/en/latest/en/developers/regulatory/wireless-regdb.html
// - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/wireless/nl80211.c?h=a55f7f5f29b32c2c53cc291899cf9b0c25a07f7c#n9920
func (c *client) GetRegulatoryDomain() (*RegulatoryDomain, error) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This supports specifying the radio instead of globally scoped, however, given SetRegulatoryRegion is already globally scopped it seemed appropriate to make it consistent.

If needed, we can add a GetInterfaceRegulatoryDomain(*Interface) later and extract this to a common handler - let me know what you think

Comment thread client_linux.go
// region must be an ISO 3166-1 alpha-2 country code (e.g. "GB" or "US").
//
// See https://wireless.docs.kernel.org/en/latest/en/developers/regulatory/wireless-regdb.html
func (c *client) SetRegulatoryRegion(region string, hint RegulatoryHint) error {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it make sense for SetRegulatoryRegion to accept a struct in case it ever accepts more attributes ?

I had a look at net/wireless/nl80211.c and it seems like more attributes are used ? Can you double check ? I am not familiar with this family but it seems like it's one of the less documented ones.

https://github.com/torvalds/linux/blob/e774d5f1bc27a85f858bce7688509e866f8e8a4e/net/wireless/nl80211.c#L10125

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also worth checking for the rest of the requests

@tomasff tomasff Apr 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The one currently implemented only has the hint, the one linked is very similar but slightly different 😅
This also tripped me up while I was reading, there's nl80211_req_set_reg and nl80211_set_reg.

It seems the set_reg variant can be used to provide the specific the regulatory rules, whereas req_set_reg takes the region + hint and looks up the rules from the regulatory database

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