Fixing WiFi regulatory rule in Unix

Wifi routers usually specify the regulatory rules for all devices connected to their network. In rare cases a router may go rouge and specify the wrong regulatory domain, which might effect the quality of the connection and at times may make the network unreachable even if the network says that its connected.

Below are the debug messages from the command “dmesg” in one such case:

[ 8036.527533] cfg80211: 2402000 KHz – 2482000 KHz @ KHz), (N/A mBi, 2000 mBm)
[ 8036.527538] cfg80211: Updating information on frequency 2472 MHz for a 20 MHz width channel with regulatory rule:
[ 8036.527544] cfg80211: 2402000 KHz – 2482000 KHz @ KHz), (N/A mBi, 2000 mBm)
[ 8036.527549] cfg80211: Disabling freq 2484 MHz
[ 8036.527558] cfg80211: Regulatory domain changed to country: GB
[ 8036.527561] cfg80211: (start_freq – end_freq @ bandwidth), (max_antenna_gain, max_eirp)
[ 8036.527567] cfg80211: (2402000 KHz – 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm)
[ 8036.527573] cfg80211: (5170000 KHz – 5250000 KHz @ 40000 KHz), (N/A, 2000 mBm)
[ 8036.527578] cfg80211: (5250000 KHz – 5330000 KHz @ 40000 KHz), (N/A, 2000 mBm)
[ 8036.527583] cfg80211: (5490000 KHz – 5710000 KHz @ 40000 KHz), (N/A, 2700 mBm)
[ 8310.345982] cfg80211: Calling CRDA to update world regulatory domain

{adinserter 2}
To fix the above error we need to force the correct domain onto the wireless device. This can be done with the “iw” command in unix.

You can install “iw” on ubuntu using the following command

sudo apt-get install iw

Once installed you can view your current setting using the following command:

sudo iw reg get

It should return you an output similar to this (provided you are in the US)

country US:
(2402000 KHz – 2472000 KHz @ 40000 KHz), (300 mBi, 2700 mBm)
(5170000 KHz – 5250000 KHz @ 40000 KHz), (300 mBi, 1700 mBm)
(5250000 KHz – 5330000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
(5490000 KHz – 5710000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
(5735000 KHz – 5835000 KHz @ 40000 KHz), (300 mBi, 3000 mBm)

The country code can be decoded as follows:
if USA then country code = US
if china then country code = CN
if Australia then country code = AU
if Great Britain then country code = GB
if India then country code = IN
ect.

To set the correct country code, use the following command (change the country code to the one your router supports)

sudo iw reg set US

PS: If you have problems with ‘sudo apt-get install iw’ command. Make sure in your Software Sources that you have a tick next to “Community-maintained Open Source software (Universe)”