raspap-webgui icon indicating copy to clipboard operation
raspap-webgui copied to clipboard

Auto-set country code

Open Kzitold opened this issue 6 months ago • 5 comments

You can get the selected country code with sudo raspi-config nonint get_wifi_country

Maybe copy that output to the RaspAP country code?

Kzitold avatar Jul 06 '25 14:07 Kzitold

The selected country code is set with iw reg set:

https://github.com/RaspAP/raspap-webgui/blob/7883514f40d1aba0d1398b738ab1099f528258e8/includes/hostapd.php#L595-L608

billz avatar Jul 06 '25 17:07 billz

I misread your feature request. Yes, the country code could be assigned this way.

billz avatar Jul 06 '25 17:07 billz

This is what I found to automatically set country code after the install. Maybe you can find a good place to put it in the installer?

tag="country_code="
find=$(cat /etc/hostapd/hostapd.conf | grep -a "$tag")
replace="$tag"$(sudo raspi-config nonint get_wifi_country)
sudo sed -i "s/$find/$replace/g" /etc/hostapd/hostapd.conf

Kzitold avatar Jul 07 '25 16:07 Kzitold

raspi-config returns the regulatory domain value that gets applied at boot time. you can find this in /proc/cmdline:

cfg80211.ieee80211_regdom=US

In my case, I set to "US" in the RPi Imager tool. RaspAP uses iw reg get/set (as above) which interacts with different parts of the wireless stack. This is what WLAN drivers and the kernel actually use to determine channel restrictions, etc.

So hostapd.conf could initially be populated from raspi-config, but thereafter this is ignored and iw is used.

billz avatar Jul 07 '25 17:07 billz

As long as hostapd gets on the same country code as Raspberry itself.

Kzitold avatar Jul 07 '25 17:07 Kzitold