Set Country code before scanning for WiFi
Description
Problem
By default WiFi interfaces are in the global domain (country code "00"). However, in this domain WiFis running on certain frequencies (e.g. Channel 153 running on 5765MHz) is disabled, thus not allowing to even see the access point.
This came up previously in the OS issue tracker: https://github.com/home-assistant/operating-system/issues/785 https://github.com/home-assistant/operating-system/issues/1530 https://github.com/home-assistant/operating-system/issues/2755
Solution
Setting the country before scanning allows to scan those APs.
WPA supplicant allows to set the country code per WiFi interface. According to the D-Bus documentation (https://w1.fi/wpa_supplicant/devel/dbus.html#dbus_interface) this matches the setting in wpa_supplicant.conf.
In a quick test setting the country before scanning enables frequencies which are otherwise disabled (as shown by iw reg get)
busctl set-property fi.w1.wpa_supplicant1 /fi/w1/wpa_supplicant1/Interfaces/0 fi.w1.wpa_supplicant1.Interface Country s US
Implementation
The country code used in WiFi regulatory domain is a ISO3166-alpha2 country code. From what I can tell this is what our whoami server is using, so we can reuse this information. However, in case the user wants to on-board via terminal/CLI, we should offer a override/fallback, e.g.
ha network scan --country=US
Open quesitons:
Do we need to store that override country? What if it differes with what the API returns?
busctl get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Devices/3 org.freedesktop.NetworkManager.Device Interface
busctl get-property fi.w1.wpa_supplicant1 /fi/w1/wpa_supplicant1/Interfaces/0 fi.w1.wpa_supplicant1.Interface Ifname
Additional context
No response
The NetworkManager and WPA Supplicant interface can be linked using
busctl get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Devices/3 org.freedesktop.NetworkManager.Device Interface
busctl get-property fi.w1.wpa_supplicant1 /fi/w1/wpa_supplicant1/Interfaces/0 fi.w1.wpa_supplicant1.Interface Ifname
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.