# [Solved]Prob setting regulatory domain for home built router

## Bullet Dodger

I have a home built wifi ap/router for which I'm having a problem setting the correct regulatory domain.

It is currently set to the most restrictive "world" domain.

It was previously set to "GB". I'm not sure when this changed.

See this post where I originally worked through this problem, to successfully set the "GB" domain.

https://forums.gentoo.org/viewtopic-t-911400-highlight-.html

Working through that post again gives the following results.

```

# iw reg get

country 00:

        (2402 - 2472 @ 40), (3, 20)

        (2457 - 2482 @ 20), (3, 20), PASSIVE-SCAN, NO-IBSS

        (2474 - 2494 @ 20), (3, 20), NO-OFDM, PASSIVE-SCAN, NO-IBSS

        (5170 - 5250 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

        (5735 - 5835 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

```

I have 2 hostapd config files

```

# grep country /etc/hostapd/hostapd.wlan0.conf 

country_code=GB

# grep country /etc/hostapd/hostapd.wlan1.conf

country_code=GB

```

```

# grep -i crda /var/log/messages

Jun  1 02:53:01 olympus kernel: [ 1058.928070] cfg80211: Calling CRDA to update world regulatory domain

Jun  1 02:53:01 olympus kernel: [ 1058.937728] cfg80211: Calling CRDA for country: 97

```

crda is installed

```

# emerge -p crda

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R    ] net-wireless/crda-1.1.2-r3 

```

EEPROM looks ok

```

# grep EEPROM /var/log/messages -3

May 29 09:15:56 olympus kernel: [   19.313256] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

May 29 09:15:56 olympus kernel: [   19.313264] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

May 29 09:15:56 olympus kernel: [   19.313299] cfg80211: Calling CRDA for country: GB

May 29 09:15:56 olympus kernel: [   19.319844] ath: EEPROM regdomain: 0xff

May 29 09:15:56 olympus kernel: [   19.319852] ath: EEPROM indicates we should expect a direct regpair map

May 29 09:15:56 olympus kernel: [   19.319861] ath: Country alpha2 being used: JP

May 29 09:15:56 olympus kernel: [   19.319866] ath: Regpair used: 0xff

May 29 09:15:56 olympus kernel: [   19.326720] cfg80211: Regulatory domain changed to country: GB

--

May 29 09:15:56 olympus kernel: [   19.366335] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (N/A, 2000 mBm)

May 29 09:15:56 olympus kernel: [   19.366341] cfg80211:   (5250000 KHz - 5330000 KHz @ 40000 KHz), (N/A, 2000 mBm)

May 29 09:15:56 olympus kernel: [   19.366347] cfg80211:   (5490000 KHz - 5710000 KHz @ 40000 KHz), (N/A, 2300 mBm)

May 29 09:15:56 olympus kernel: [   19.411539] ath: EEPROM regdomain: 0xff

May 29 09:15:56 olympus kernel: [   19.411546] ath: EEPROM indicates we should expect a direct regpair map

May 29 09:15:56 olympus kernel: [   19.411555] ath: Country alpha2 being used: JP

May 29 09:15:56 olympus kernel: [   19.411561] ath: Regpair used: 0xff

May 29 09:15:56 olympus kernel: [   19.417475] ieee80211 phy1: Selected rate control algorithm 'ath9k_rate_control'

--

Jun  1 02:35:57 olympus kernel: [   21.461609] vgaarb: device changed decodes: PCI:0000:00:02.0,olddecodes=io+mem,decodes=io+mem:owns=io+mem

Jun  1 02:35:57 olympus kernel: [   21.505365] asix 1-4:1.0: eth1: register 'asix' at usb-0000:00:1d.7-4, ASIX AX88178 USB 2.0 Ethernet, 00:0e:c6:88:9a:e9

Jun  1 02:35:57 olympus kernel: [   21.505626] usbcore: registered new interface driver asix

Jun  1 02:35:57 olympus kernel: [   21.621948] ath: EEPROM regdomain: 0xff

Jun  1 02:35:57 olympus kernel: [   21.621954] ath: EEPROM indicates we should expect a direct regpair map

Jun  1 02:35:57 olympus kernel: [   21.621962] ath: Country alpha2 being used: JP

Jun  1 02:35:57 olympus kernel: [   21.621967] ath: Regpair used: 0xff

Jun  1 02:35:57 olympus kernel: [   21.655458] ieee80211 phy0: Selected rate control algorithm 'ath9k_rate_control'

Jun  1 02:35:57 olympus kernel: [   21.658102] Registered led device: ath9k-phy0

Jun  1 02:35:57 olympus kernel: [   21.658132] ieee80211 phy0: Atheros AR5418 MAC/BB Rev:2 AR5133 RF Rev:81 mem=0xffffc90021720000, irq=17

Jun  1 02:35:57 olympus kernel: [   21.708685] ath: EEPROM regdomain: 0xff

Jun  1 02:35:57 olympus kernel: [   21.708691] ath: EEPROM indicates we should expect a direct regpair map

Jun  1 02:35:57 olympus kernel: [   21.708699] ath: Country alpha2 being used: JP

Jun  1 02:35:57 olympus kernel: [   21.708704] ath: Regpair used: 0xff

Jun  1 02:35:57 olympus kernel: [   21.711877] ieee80211 phy1: Selected rate control algorithm 'ath9k_rate_control'

```

The above also appears to show the correct domain setting on the 29th May.

The correct parameter is set for the cfg80211 module.

```

# cat /etc/modprobe.d/cfg80211.conf

options cfg80211 ieee80211_regdom=GB

```

I think I have the correct kernel modules compiled

```

# zcat /proc/config.gz | grep -i ath9k 

CONFIG_ATH9K_HW=m

CONFIG_ATH9K_COMMON=m

CONFIG_ATH9K_BTCOEX_SUPPORT=y

CONFIG_ATH9K=m

CONFIG_ATH9K_PCI=y

CONFIG_ATH9K_AHB=y

# CONFIG_ATH9K_DEBUGFS is not set

CONFIG_ATH9K_RATE_CONTROL=y

CONFIG_ATH9K_HTC=m

# CONFIG_ATH9K_HTC_DEBUGFS is not set

# zcat /proc/config.gz | grep -i cfg80211

CONFIG_CFG80211=m

# CONFIG_CFG80211_DEVELOPER_WARNINGS is not set

# CONFIG_CFG80211_REG_DEBUG is not set

CONFIG_CFG80211_DEFAULT_PS=y

CONFIG_CFG80211_DEBUGFS=y

# CONFIG_CFG80211_INTERNAL_REGDB is not set

CONFIG_CFG80211_WEXT=y

```

net-wireless/wireless-regdb is installed.

```

# emerge -p net-wireless/wireless-regdb

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R    ] net-wireless/wireless-regdb-20110428-r1 

```

I have the correct udev rule.

```

# cat /etc/udev/rules.d/60-cdra.rules 

# Example file, should be put in /etc/udev/rules.d/regulatory.rules

KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/sbin/crda"

```

http://linuxwireless.org/en/developers/Regulatory/CRDA

I have recently had a problem with an updated to udev blocking itself.

https://forums.gentoo.org/viewtopic-t-924404-highlight-.html

```

# emerge -p udev

These are the packages that would be merged, in order:

Calculating dependencies... done!

[ebuild   R    ] sys-fs/udev-171-r6 

```

Running crda

```

# crda

COUNTRY environment variable not set.

# export COUNTRY='GB'

# crda               

Failed to set regulatory domain: -7

# iw reg get

country 00:

        (2402 - 2472 @ 40), (3, 20)

        (2457 - 2482 @ 20), (3, 20), PASSIVE-SCAN, NO-IBSS

        (2474 - 2494 @ 20), (3, 20), NO-OFDM, PASSIVE-SCAN, NO-IBSS

        (5170 - 5250 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

        (5735 - 5835 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

# grep regulatory /var/log/messages

Jun  1 03:18:29 olympus kernel: [ 2587.008076] cfg80211: Calling CRDA to update world regulatory domain

Jun  1 03:18:29 olympus kernel: [ 2587.015392] cfg80211: World regulatory domain updated:

```

I now need some help where to look next.Last edited by Bullet Dodger on Sun Jul 01, 2012 10:03 pm; edited 1 time in total

----------

## Bullet Dodger

During boot, dmesg records the following

```

[   19.220119] cfg80211: World regulatory domain updated:

[   19.220130] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   19.220141] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   19.220151] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   19.220160] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   19.220170] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   19.220179] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   19.220216] cfg80211: Calling CRDA for country: GB

[   19.231496] cfg80211: Regulatory domain changed to country: GB

[   19.231504] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   19.231512] cfg80211:   (2402000 KHz - 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.231519] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.231525] cfg80211:   (5250000 KHz - 5330000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.231532] cfg80211:   (5490000 KHz - 5710000 KHz @ 40000 KHz), (N/A, 2700 mBm)

[   19.275853] [drm] initialized overlay support

[   19.293072] fbcon: inteldrmfb (fb0) is primary device

[   19.296794] [drm] Changing LVDS panel from (+hsync, +vsync) to (-hsync, -vsync)

[   19.475089] ath: EEPROM regdomain: 0xff

[   19.475096] ath: EEPROM indicates we should expect a direct regpair map

[   19.475106] ath: Country alpha2 being used: JP

[   19.475113] ath: Regpair used: 0xff

[   19.507151] ieee80211 phy0: Selected rate control algorithm 'ath9k_rate_control'

[   19.508983] cfg80211: Calling CRDA for country: JP

[   19.510217] Registered led device: ath9k-phy0

[   19.510252] ieee80211 phy0: Atheros AR5418 MAC/BB Rev:2 AR5133 RF Rev:81 mem=0xffffc900115a0000, irq=17

[   19.516940] cfg80211: Current regulatory domain intersected:

[   19.516948] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   19.516956] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.516963] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (N/A, 2000 mBm)

[   19.516970] cfg80211:   (2474000 KHz - 2482000 KHz @ 8000 KHz), (N/A, 2000 mBm)

[   19.516977] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.516984] cfg80211:   (5250000 KHz - 5330000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.516991] cfg80211:   (5490000 KHz - 5710000 KHz @ 40000 KHz), (N/A, 2300 mBm)

[   19.561322] ath: EEPROM regdomain: 0xff

[   19.561327] ath: EEPROM indicates we should expect a direct regpair map

[   19.561334] ath: Country alpha2 being used: JP

[   19.561337] ath: Regpair used: 0xff

[   19.564396] udevd[10102]: renamed network interface wlan0 to wlan1

[   19.564862] ieee80211 phy1: Selected rate control algorithm 'ath9k_rate_control'

[   19.567712] Registered led device: ath9k-phy1

[   19.567733] ieee80211 phy1: Atheros AR9285 Rev:2 mem=0xffffc90021760000, irq=19

[   19.570104] cfg80211: Calling CRDA for country: JP

[   19.579983] cfg80211: Current regulatory domain intersected:

[   19.579992] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   19.580002] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.580051] cfg80211:   (2457000 KHz - 2472000 KHz @ 15000 KHz), (N/A, 2000 mBm)

[   19.580060] cfg80211:   (2457000 KHz - 2472000 KHz @ 15000 KHz), (N/A, 2000 mBm)

[   19.580069] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (N/A, 2000 mBm)

[   19.580078] cfg80211:   (2474000 KHz - 2482000 KHz @ 8000 KHz), (N/A, 2000 mBm)

[   19.580086] cfg80211:   (2474000 KHz - 2482000 KHz @ 8000 KHz), (N/A, 2000 mBm)

[   19.580095] cfg80211:   (2474000 KHz - 2482000 KHz @ 8000 KHz), (N/A, 2000 mBm)

[   19.580104] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.580113] cfg80211:   (5250000 KHz - 5330000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   19.580121] cfg80211:   (5490000 KHz - 5710000 KHz @ 40000 KHz), (N/A, 2300 mBm)

```

This appears to be ok.

but then

```

[   46.928063] cfg80211: Calling CRDA to update world regulatory domain

[   46.935732] cfg80211: World regulatory domain updated:

[   46.935743] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   46.935754] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   46.935764] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   46.935774] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   46.935784] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   46.935794] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   46.936090] cfg80211: Calling CRDA for country: 97

[   50.080100] cfg80211: Calling CRDA to update world regulatory domain

[   50.088814] cfg80211: World regulatory domain updated:

[   50.088824] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   50.088835] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   50.088845] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   50.088854] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   50.088864] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   50.088874] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   50.089149] cfg80211: Calling CRDA for country: 97

[   53.240058] cfg80211: Calling CRDA to update world regulatory domain

[   53.246670] cfg80211: World regulatory domain updated:

[   53.246678] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   53.246686] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   53.246694] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   53.246701] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)

[   53.246708] cfg80211:   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   53.246715] cfg80211:   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)

[   53.246768] cfg80211: Calling CRDA for country: 97

```

Repeated constantly.

iw doesn't change the reg domain.

```

# iw reg get 

country 00:

        (2402 - 2472 @ 40), (3, 20)

        (2457 - 2482 @ 20), (3, 20), PASSIVE-SCAN, NO-IBSS

        (2474 - 2494 @ 20), (3, 20), NO-OFDM, PASSIVE-SCAN, NO-IBSS

        (5170 - 5250 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

        (5735 - 5835 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

# iw reg set GB

# iw reg get   

country 00:

        (2402 - 2472 @ 40), (3, 20)

        (2457 - 2482 @ 20), (3, 20), PASSIVE-SCAN, NO-IBSS

        (2474 - 2494 @ 20), (3, 20), NO-OFDM, PASSIVE-SCAN, NO-IBSS

        (5170 - 5250 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

        (5735 - 5835 @ 40), (3, 20), PASSIVE-SCAN, NO-IBSS

```

udev also constantly reports

```

# udevadm monitor --environment kernel

monitor will print the received events for:

UDEV - the event which udev sends out after rule processing

KERNEL - the kernel uevent

KERNEL[1339611519.344857] change   /devices/platform/regulatory.0 (platform)

ACTION=change

DEVPATH=/devices/platform/regulatory.0

SUBSYSTEM=platform

MODALIAS=platform:regulatory

COUNTRY=00

SEQNUM=1842

KERNEL[1339611519.351126] change   /devices/platform/regulatory.0 (platform)

ACTION=change

DEVPATH=/devices/platform/regulatory.0

SUBSYSTEM=platform

MODALIAS=platform:regulatory

COUNTRY=97

SEQNUM=1843

UDEV  [1339611519.356276] change   /devices/platform/regulatory.0 (platform)

ACTION=change

DEVPATH=/devices/platform/regulatory.0

SUBSYSTEM=platform

MODALIAS=platform:regulatory

COUNTRY=00

SEQNUM=1842

```

I might try 1 wifi card at a time, but don't think that is a problem.

Is there any way to find out why cfg80211 is selecting the world domain?

----------

## Bullet Dodger

The only way I have found to fix this is to build my own regulatory database, setting the world domain to be the least restrictive. http://vimeo.com/22938112

----------

