# CRDA regulatory domain hell

## Erlend

i don't seem to be able to set the country to GB, it reverts to CN.

Does anyone know how to fix this?

```
ath9k 0000:04:00.0: PCI INT A -> GSI 18 (level, low) -> IRQ 18

ath9k 0000:04:00.0: setting latency timer to 64

cfg80211: World regulatory domain updated:

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

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

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

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

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

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

cfg80211: Calling CRDA for country: GB

cfg80211: Regulatory domain changed to country: GB

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

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

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

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

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

ath: EEPROM regdomain: 0x809c

ath: EEPROM indicates we should expect a country code

ath: doing EEPROM country->regdmn map search

ath: country maps to regdmn code: 0x52

ath: Country alpha2 being used: CN

ath: Regpair used: 0x52

ieee80211 phy0: Selected rate control algorithm 'ath9k_rate_control'

cfg80211: Calling CRDA for country: CN

Registered led device: ath9k-phy0

ieee80211 phy0: Atheros AR9285 Rev:2 mem=0xffffc900047c0000, irq=18

cfg80211: Current regulatory domain intersected:

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

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

udevd[31720]: renamed network interface wlan0 to wlan2
```

----------

## swimmer

I'm not sure how you set the domain but you could try to modify the cfg80211 options ...

```
ack regdom /etc/modprobe.d/options.conf 

options cfg80211 ieee80211_regdom=UK
```

HTH

swimmer

----------

## cwr

AFAIK you can't - I  got the region to set with kernel 2.6.34, but haven't managed

it since.  You could start by adding the wireless drivers as modules, not built-in,

which is what solved the problem for me last time.

I've attacked the problem intermittently for the last year or so, and got no further,

so if you find a solution I'd like to know it  (This is with the ath9k drivers).

Will

----------

## Erlend

 *swimmer wrote:*   

> I'm not sure how you set the domain but you could try to modify the cfg80211 options ...
> 
> ```
> ack regdom /etc/modprobe.d/options.conf 
> 
> ...

 

I've got this.  Actually I've set the regdom to GB, not UK, but I think that's correct.

----------

## Erlend

 *cwr wrote:*   

> AFAIK you can't - I  got the region to set with kernel 2.6.34, but haven't managed
> 
> it since.  You could start by adding the wireless drivers as modules, not built-in,
> 
> which is what solved the problem for me last time.
> ...

 

The ath9k is compiled as a kernel module.

 *cwr wrote:*   

> 
> 
> I've attacked the problem intermittently for the last year or so, and got no further,
> 
> so if you find a solution I'd like to know it  (This is with the ath9k drivers).
> ...

 

Is it a bug or a design choice?  What's actually going on?  I bought this card because I thought the ath9k drivers were supposed to be very stable.

----------

## kimmie

Is that log is what you get when setting the domain manually using 'iw reg set GB'?

Have you merged net-wireless/crda?

----------

## Erlend

 *kimmie wrote:*   

> Is that log is what you get when setting the domain manually using 'iw reg set GB'?
> 
> Have you merged net-wireless/crda?

 

Yes, to both questions.  I also merged wireless-regdb.

----------

## kimmie

I doubt I'm saying anything you don't already know, but anyway... I had a trawl through the driver code and http://wireless.kernel.org/en/users/Drivers/ath#Regulatory

As I understand it, your card is approved for use in china, that's locked in the EEPROM. You're telling it you're in the UK. So the driver is doing the right thing (in a regulatory sense) and finding the intersection of channels available for those two countries.

If you think your card is 5GHz-capable and you want to use it in the UK, then you have a problem, the driver isn't going to let you do that, because the card isn't approved for use in those bands.

On the other hand you're completely fine at 2.4 GHz, because the available channels in UK and CN are exactly the same.

----------

## Erlend

 *kimmie wrote:*   

> I doubt I'm saying anything you don't already know, but anyway... I had a trawl through the driver code and http://wireless.kernel.org/en/users/Drivers/ath#Regulatory
> 
> As I understand it, your card is approved for use in china, that's locked in the EEPROM. You're telling it you're in the UK. So the driver is doing the right thing (in a regulatory sense) and finding the intersection of channels available for those two countries.
> 
> If you think your card is 5GHz-capable and you want to use it in the UK, then you have a problem, the driver isn't going to let you do that, because the card isn't approved for use in those bands.
> ...

 

Ah that's what it meant by "intersection" then.  Ok, thanks for your help!

----------

## cwr

In fact, there have been significant changes in the ath9k drivers.

With a 2.6.32 kernel I can run "iw reg set GB", and "iw reg get"

then gives:

country GB:

	(2402 - 2482 @ 40), (N/A, 20)

	(5170 - 5250 @ 40), (N/A, 20)

	(5250 - 5330 @ 40), (N/A, 20), DFS

	(5490 - 5710 @ 40), (N/A, 27), DFS

which looks about right. (BTW it would be really, really nice if CRDA

documented its database format and units somewhere other than in the

source code. An explanation of the various TLAs is too much to hope for.)

With the same hardware and regulatory setup, and any later kernel,

"iw reg set GB" fails and "iw reg get" gives:

country 00:

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

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

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

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

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

According to the (fairly confusing) linux ath9k documentation, Atheros

uses the 00 domain to mean US.  The set-up doesn't quite look like the

standard US regulatory environment to me, but I could well be mistaken.

I'm not especially bothered about the 5GHz settings, but I'd like to keep

all the standard UK 2.5GHz settings, some of which seem to have been lost

in recent driver changes.  As I said, I'll keep investigating.

Will

----------

## kimmie

Some good info on regulatory rules and their processing is at http://linuxwireless.org/en/developers/Regulatory/processing_rules - that might help you with the TLAs.

The country "00" data you are seeing in the output of iw reg get is not for the US, that is the "world" regulatory domain. This is a domain that is supposed to be usable the world over by putting limits on transmission power and some other things. In the absence of better info (from a driver, from the user configuration, or from connected AP's) that's what the linux CRDA infrastructure will use.

The atheros EEPROM 0x0 code is a different thing. It maps to the "US" domain, not to the "00" world domain. In any case, your EEPROM code is not 0x0, but 0x809c, which maps to "CN".  

I'm not sure why you can no longer set the domain with iw reg set, what error do you see? It may help to have your kernel built with CFG80211_REG_DEBUG so you get some additional info in the syslog. Also, you do not have to use module parameters to set the regulatory domain; at least with wpa_supplicant you can put a "country=GB" line in /etc/wpa_supplicant/wpa_supplicant.conf. 

In any case, if your system is using the "00" domain, you are meeting all regulatory requirements.

----------

## cwr

It took quite a bit of work to get CRDA working on 2.6.32, and util I have to,

I don't plan to start over.  I'd just like to be able to use the full range UK

channels at 2.5 GHz, which the current kernels apparently can't do.

(and OFDM and DFS took some hunting down ...)

Will

----------

## pimguilherme

I know this post is old, but the same thing was happening to me and it took me quite a while to figure out why the regulatory domain was being reset after the preconfigured value I put into the /etc/default/crda had been applied.

I set the default to country BR, and could see the following pattern for cfg80211 in dmesg:

- cfg80211 sets the default "world" regulatory domain

- cfg80211 sets BR as the regulatory domain

- cfg80211 sets US as the regulatory domain

I was concentrating debugging at dmesg too much and missed some obvious log lines in /var/log/messages and journalctl, which showed that the regulatory domain was being reset based on my timezone. My timezone was set to Americas/New_York. I changed it to Americas/Sao_Paulo and there you go, BR became the default regulatory domain. I don't even need the /etc/default/crda config any longer.

The error in my case was very silly, but maybe this helps someone else.

Best of luck

----------

