WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] how to set country and make it visible to wifi drivers?  (Read 6430 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
As you may know, my home's wireless router is actually a laptop running TCL13.1 Pure64. I'm trying to upgrade my network from 2.4 GHz to 5 GHz. My new wireless USB adapter (AWUS036ACHM) supports 5 GHz frequencies but I think it can only use them if it can verify that the requested frequency is allowed in my country.

The trouble is that the country code seems to be unset, which results in the adapter not being able to use any of the 5 GHz frequencies:
[forum error - see attached]

I describe the problem in more detail here: https://github.com/morrownr/USB-WiFi/issues/84

Please, how do I set the country on a TCL box, and how do I make that setting visible to wifi drivers (e.g., nl80211)?
« Last Edit: July 03, 2022, 07:20:25 AM by Rich »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: how to set country and make it visible to wifi drivers?
« Reply #1 on: July 02, 2022, 08:40:14 PM »
Hi GNUser
According to this:
https://unix.stackexchange.com/questions/253933/wifi-iw-reg-set-us-has-no-effect
You should be able to do it like this (probably needs sudo):
Code: [Select]
iw reg set US
It also shows how to set it when loading the  cfg80211  driver.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
Re: how to set country and make it visible to wifi drivers?
« Reply #2 on: July 02, 2022, 10:17:06 PM »
Thanks to your tip I discovered this linux kernel boot parameter: cfg80211.ieee80211_regdom=US

Unfortunately, after a reboot it still doesn't work. It seems that for the parameter to work, some kind of regulatory database is needed but is missing from my system and not available in the repository. [forum error, see attached]

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
Re: how to set country and make it visible to wifi drivers?
« Reply #3 on: July 02, 2022, 10:38:33 PM »
Kernel seems to rely on crda (this thing: https://github.com/mcgrof/crda) to make regulatory domain changes. I will try my hand at building crda but it seems a bit complicated.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: how to set country and make it visible to wifi drivers?
« Reply #4 on: July 02, 2022, 11:02:20 PM »
Hi GNUser
crda.tcz  used to be in the repo. According to this the db format changed in kernel 4.15:
https://unix.stackexchange.com/questions/459518/where-to-paste-regulatory-db-and-how

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
Re: how to set country and make it visible to wifi drivers?
« Reply #5 on: July 02, 2022, 11:29:46 PM »
Hi, Rich. I put all the  regulatory.*  files in  /lib/firmware/  directory as suggested. I still cannot set the country:
[form error. see attached]

Setting the country as in the attachment works fine in Devuan, without having to reload any kernel modules. I'm stuck.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: how to set country and make it visible to wifi drivers?
« Reply #6 on: July 02, 2022, 11:58:32 PM »
Hi GNUser
... Setting the country as in the attachment works fine in Devuan, without having to reload any kernel modules. I'm stuck.
Devuan has a persistent file system, Tinycore does not. Unless you added the  regulatory.*  files to the  rootfs , they may be
showing up too late. You might need to reload the drivers or create an additional initrd containing just the  regulatory.*  files.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
Re: how to set country and make it visible to wifi drivers?
« Reply #7 on: July 03, 2022, 12:57:29 AM »
1. I added  /lib/firmware/regulatory.db  and  /lib/firmware/regulatory.db.p7s  to corepure64.gz
2. I added this command to top of /opt/bootlocal.sh: iw reg set US

Then I rebooted and voila, everything works as expected :o
My home wireless network is now 5 GHz. Download speeds for wireless clients increased from 30 Mbps to 90 Mbps. Rich, there's absolutely no way I could have solved this without your help. THANK YOU!
« Last Edit: July 03, 2022, 01:07:25 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: [Solved] how to set country and make it visible to wifi drivers?
« Reply #8 on: July 03, 2022, 08:24:04 AM »
Hi GNUser
If you create a separate initrd it will make it obvious there is a special modification. Plus it
is now portable so you don't have to remaster  corepure64.gz  anytime you want to test
a new release.

Create the file system:
Code: [Select]
mkdir -p tempdir/lib/firmware/
cp regulatory.db tempdir/lib/firmware/
cp regulatory.db.p7s tempdir/lib/firmware/
cd tempdir

Pack it up:
Sorry, forum error, see attachment.

Finish:
Code: [Select]
cd ..
Code: [Select]
rm -rf tempdir
cp regulatory.gz /boot

I think the syntax for loading multiple initrd files in grub2 would look like this:
Code: [Select]
initrd /boot/corepure64.gz /boot/regulatory.gz

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: [Solved] how to set country and make it visible to wifi drivers?
« Reply #9 on: July 03, 2022, 10:06:11 AM »
I have found that as long as regulatory.db and it’s signature is loaded before your WiFi firmware/drivers.  It works fine in an extension….. at least on a rpi.  There is a regdb.tcz extension in the piCore repos.

And yes, crda is obsolete with modern kernels.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: [Solved] how to set country and make it visible to wifi drivers?
« Reply #10 on: July 03, 2022, 10:54:29 PM »
Hi Paul_123
Thanks for that. I wasn't sure whether or not any wireless components are included as part
of the base system, and this seemed like the most foolproof solution.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
Re: [Solved] how to set country and make it visible to wifi drivers?
« Reply #11 on: July 03, 2022, 10:55:12 PM »
I can confirm that providing the files as a custom initrd works. Providing them as a custom extension works as well.

I decided to go with custom initrd plus the  cfg80211.ieee80211_regdom=US  boot parameter. Everything is working like a charm. Thanks for the help!

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
Re: [Solved] how to set country and make it visible to wifi drivers?
« Reply #12 on: January 18, 2023, 10:43:20 AM »
Short version:
Does anyone know whether the location of the regulatory files has changed for linux kernel 6.1.2?

Long version:
My homebrewed laptop-turned-wireless router runs TCL x86_64. When I upgrade it from TCL13.1 to TCL14-alpha1 everything works except hostapd in 5 GHz mode.

Now, when hostapd creates a 5 GHz AP, wireless clients can see the AP but cannot successfully authenticate. Then, after about a minute, the router becomes completely unresponsive to keyboard input, necessitating a hard reboot.

I recompiled hostapd for TCL14 but it makes no difference. hostapd does not show any helpful error messages. My guess is that this has to do with regulatory files for the 5 GHz channels.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1509
Re: [Solved] how to set country and make it visible to wifi drivers?
« Reply #13 on: January 18, 2023, 12:21:27 PM »
Short answer: No, I don't think the location of the files has changed.

Long answer:

My custom initrd (regulatory.gz) is loaded at boot along with rootfs and modules. The initrd contains these two files:
Code: [Select]
/lib/firmware/regulatory.db
/lib/firmware/regulatory.db.p7s
Setting the country code works:
Code: [Select]
$ sudo iw reg set US
$ iw reg get
global
country US: DFS-FCC
...

Still, even with hostapd compiled on TCL14 x86_64, I cannot generate a 5 GHz 802.11ac hotspot as I could with TCL13.1. I will report this in the alpha release page.