418. Wireless regulatory domain
A Wi-Fi radio may use only the channels and the transmit power the country it is in allows. The kernel learns the rules from the signed wireless regulatory database and the country from its regulatory domain. Until something names a country, it stays in the world domain 00, which keeps every 5 GHz channel that needs radar detection (DFS) closed and caps transmit power. This page is for anyone whose Wi-Fi shows fewer networks or channels than it should, or who runs an access point. It covers where the database and the country come from on KDOS, how to see and change the country, and how to tell when the radio is stuck on the world rules.
Installation
| Port | Provides |
|---|---|
| wireless-regdb | /lib/firmware/regulatory.db and its signature, regulatory.db.p7s |
| iw | iw reg get and iw reg set |
| linux | cfg80211, the kernel’s wireless layer, built as a module |
| kdos-settingsd | org.freedesktop.timedate1, whose time zone also sets the country |
| kdos-tools | kdos doctor, which checks the database and the domain |
All five are part of the base system, so the live medium and every installation have them. No service script is involved: cfg80211 reads the country from its module options when it loads, and loads the database itself.
The kernel accepts regulatory.db only with a valid regulatory.db.p7s beside it, signed by a key it trusts. The port builds the database from upstream’s db.txt, checks the result against upstream’s signature, and refuses to package it when the two disagree, so an edited database never ships; see Firmware.
Configuration
The database
install -dm755 "$PKG/lib/firmware"
install -m644 regulatory.db.built "$PKG/lib/firmware/regulatory.db"
install -m644 regulatory.db.p7s "$PKG/lib/firmware/regulatory.db.p7s"
ports/core/boot/wireless-regdb/build.sh, lines 28–30
Both files must stay as the package installed them. A database regenerated locally fails the signature check in silence and leaves the radio exactly where it was, on the world domain.
The country: /etc/modprobe.d/kdos-regdom.conf
One setting, options cfg80211 ieee80211_regdom=<CC>, where <CC> is a two-letter country code; the file kdos-settingsd writes puts a two-line comment naming the zone above it. The image ships no such file; two programs write it from the time zone, looking the zone up in tzdata’s zone.tab, which gives each zone one country.
The installer writes it from the zone chosen on its Time page:
if (cc[0]) {
mkpath(TARGET "/etc/modprobe.d");
wr("/etc/modprobe.d/kdos-regdom.conf",
"# Written by the KDOS installer from the timezone (%s):\n"
"# the country the Wi-Fi radio's channels and transmit\n"
"# power are set for.\n"
"options cfg80211 ieee80211_regdom=%s\n",
cfg.tz_label, cc);
}
src/system/kinstall-core/install.c, lines 3074–3082
kdos-settingsd writes it whenever the time zone is changed later, and runs iw reg set so the running radio follows at once; for a zone with no country, such as UTC, it runs iw reg set 00, which returns the running radio to the world domain. Such a zone removes the file, from src/daemons/kdos-settingsd/store.c:
if (!zone_country(zone, cc)) {
unlink(reg);
return 0;
}
if (ks_etc_path(dir, sizeof(dir), "modprobe.d"))
kb_mkdir_p(dir);
snprintf(body, sizeof(body),
"# Written by kdos-settingsd from the timezone (%s): the country\n"
"# the Wi-Fi radio's channels and transmit power are set for.\n"
"options cfg80211 ieee80211_regdom=%s\n", zone, cc);
/* The regulatory domain is the radio's, and a machine with no radio
* still has a time zone: failing here does not fail the zone. */
kb_write_file_atomic(reg, body);
src/daemons/kdos-settingsd/store.c, lines 1003–1015
The file is read when cfg80211 loads, which is during boot, as the first wireless driver loads, or, on a machine with no wireless driver, when a program such as iw first asks for the wireless layer. A change to the file alone, made with an editor, takes effect at the next boot; the time zone changes the running kernel’s country too, through iw. The key is described in /etc/modprobe.d/kdos-regdom.conf.
Usage
Seeing the country in force
iw reg get
The global entry is the country the kernel applies; an entry per wireless device (phy#0) follows for a driver that keeps its own. country 00: DFS-UNSET is the world domain; a country names its radar-detection region, as in country DE: DFS-ETSI, and each line after it is a frequency range with its limits and flags.
Setting the country
Set the time zone; the country follows it. From the desktop, choose the zone on System Settings → Date & Time. From a terminal, as in Setting the time zone. Either rewrites
/etc/modprobe.d/kdos-regdom.confand runsiw reg setfor the running boot.Check the result with
iw reg get, and later withkdos doctor.
Setting the country for this boot only
When the machine is somewhere other than its time zone says, set the country by hand. It lasts until the next boot:
sudo iw reg set DE
The file the time zone writes is rewritten, or removed, at every change of zone, so it is not the place for a country that differs from the zone’s.
Checking with kdos doctor
kdos doctor
The Hardware section has one line for the database. It reads both files and the country cfg80211 was loaded with, and reports ok with that country when the files are in place and it is not 00; warn when either file is missing, or when the country is 00 on a machine with a radio; and skip when the country is 00 and there is no wireless device, as in a virtual machine, where the line reads [skip] regulatory.db and signature present; no wireless device here to load them. The country it reads is the module’s load-time value, so a later iw reg set does not change the line.
On the live medium and on an installed system
The live medium ships no kdos-regdom.conf, so it boots on the world domain. Setting the time zone in the live session writes the file and sets the running radio’s country, and the file lasts until the next reboot unless the medium has a persistence store. An installed system carries the file the installer wrote from the zone you chose, so it boots with a country from the start. For a zone with no country, such as UTC, the installer writes nothing, and the disk keeps whatever file the live session had, since the installer copies the live tree.
Tips
iw listshows, per band, which channels are open and which aredisabledorno IR(no initiating radiation: the radio may answer on them but not start a transmission). The same machine shows more 5 GHz channels open once a country is set.- A
hostapdaccess point carries its owncountry_codekey; set it to the same country, see Access point. - Some drivers adopt the country an access point announces, others never do; the module option is what makes the country independent of the network you join.
Troubleshooting
kdos doctor warns that the domain is 00. No country was set at boot. Set the time zone, as in Setting the country, which sets the country for this boot and every later one. Use sudo iw reg set <CC> alone only when the machine is somewhere other than its time zone says.
kdos doctor warns that regulatory.db or regulatory.db.p7s is missing. The package’s files are gone or damaged. sudo kpkg check wireless-regdb compares them with the package database.
No 5 GHz networks show, or a 5 GHz access point will not start. Run iw reg get. On country 00 the DFS channels are closed; set the country. With the right country set, iw list shows whether the card itself supports the band.
The country is set and iw reg get still says 00. Check that the file holds a line options cfg80211 ieee80211_regdom=<CC> with a two-letter code, and that it is read: cat /sys/module/cfg80211/parameters/ieee80211_regdom prints the value the module was loaded with. sudo dmesg | grep -i regulatory shows whether the kernel loaded the database and accepted its signature (the kernel log is root’s alone). Its first line is cfg80211: Loading compiled-in X.509 certificates for regulatory database; a missing file adds cfg80211: failed to load regulatory.db, and a database that fails the signature check adds cfg80211: loaded regulatory.db is malformed or signature is missing/invalid.
Known gaps
- kdos doctor cannot check hardware a machine does not have: the database check is a
skipwith no wireless device.
See also
- Firmware: the database, its signature and the country
- 3. Time: the installer’s zone, and the country it sets
- Time and NTP: setting the time zone
- kdos doctor
- NetworkManager, Access point
- Time and NTP, Microcode and firmware