Clone the source code from git libraries
Get CRDA source code from CRDA
Get the wireless-regdb source code from here wireless-regdb
Compile wireless-regdb
root@PC3039:/home/thomas/work/refers/wireless-regdb# make
Generating regulatory.bin digitally signed by root...
./db2bin.py regulatory.bin db.txt ~/.wireless-regdb-root.key.priv.pem
Traceback (most recent call last):
File "./db2bin.py", line 126, in <module>
from M2Crypto import RSA
ImportError: No module named M2Crypto
Makefile:56: recipe for target 'regulatory.bin' failed
make: *** [regulatory.bin] Error 1
root@PC3039:/home/thomas/work/refers/wireless-regdb# make clean
root@PC3039:/home/thomas/work/refers/wireless-regdb# make
Generating regulatory.bin digitally signed by root...
./db2bin.py regulatory.bin db.txt ~/.wireless-regdb-root.key.priv.pem
Traceback (most recent call last):
File "./db2bin.py", line 126, in <module>
from M2Crypto import RSA
ImportError: No module named M2Crypto
Makefile:56: recipe for target 'regulatory.bin' failed
make: *** [regulatory.bin] Error 1
It generates a RSA key pair to sign the regulaory binary file. It depends on two python libraries.
- apt-get install python-dev
- apt-get install python-m2crypto
Then modify the db.txt , generating regulatory.bin and sign it by run make.
thomas@PC3039:~/work/refers/wireless-regdb$ vi db.txt
thomas@PC3039:~/work/refers/wireless-regdb$ make
Generating regulatory.bin digitally signed by thomas...
./db2bin.py regulatory.bin db.txt ~/.wireless-regdb-thomas.key.priv.pem
sha1sum db.txt > sha1sum.txt
Then your can install the generations to your destionation directory.
thomas@PC3039:~/work/refers/wireless-regdb$ make install DESTDIR=~/work/cm/
gzip < regulatory.bin.5 > regulatory.bin.5.gz
install -m 755 -d /home/thomas/work/cm///usr/lib/crda
install -m 755 -d /home/thomas/work/cm///etc/wireless-regdb/pubkeys/
if [ -f .custom ]; then \
install -m 644 -t /home/thomas/work/cm///etc/wireless-regdb/pubkeys// thomas.key.pub.pem; \
fi
install -m 644 -t /home/thomas/work/cm///etc/wireless-regdb/pubkeys// sforshee.key.pub.pem
install -m 644 -t /home/thomas/work/cm///usr/lib/crda/ regulatory.bin
install -m 755 -d /home/thomas/work/cm///usr/share/man//man5/
install -m 644 -t /home/thomas/work/cm///usr/share/man//man5/ regulatory.bin.5.gz
Cross compile CRDA
As we can see wireless-regdb compiling just use local gcc, but for CRDA we need build it with cross compiling. Let’s modify the Makefile like below.
diff --git a/Makefile b/Makefile
index a3ead30..c4215db 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,12 @@
# Modify as you see fit, note this is built into crda,
# so if you change it here you will have to change crda.c
-REG_BIN?=/usr/lib/crda/regulatory.bin
REG_GIT?=git://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git
-PREFIX ?= /usr/
+PREFIX = /home/work/cm/targetNFS/usr
MANDIR ?= $(PREFIX)/share/man/
INCLUDE_DIR ?= $(PREFIX)/include/reglib/
LIBDIR ?= $(PREFIX)/lib
+REG_BIN?=$(PREFIX)/lib/crda/regulatory.bin
SBINDIR ?= /sbin/
@@ -27,7 +27,7 @@ RUNTIME_PUBKEY_DIR?=/etc/wireless-regdb/pubkeys
CFLAGS += -O2 -fpic
CFLAGS += -std=gnu99 -Wall -Werror -pedantic
-CFLAGS += -Wall -g
+CFLAGS += -Wall -g --sysroot=/home/thomas/work/ti/tisdk/build/arago-tmp-external-linaro-toolchain/sysroots/am57xx-evm/
LDLIBREG += -lreg
LDLIBS += $(LDLIBREG)
LDLIBS += -lm
@@ -127,7 +127,6 @@ install-libreg:
$(NQ) ' INSTALL libreg'
$(Q)mkdir -p $(DESTDIR)/$(LIBDIR)
$(Q)cp $(LIBREG) $(DESTDIR)/$(LIBDIR)/
- $(Q)ldconfig
%.o: %.c regdb.h $(LIBREG)
$(NQ) ' CC ' $@
@@ -157,7 +156,7 @@ verify: $(REG_BIN) regdbdump
$(NQ) ' CHK $(REG_BIN)'
$(Q)\
LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) \
- ./regdbdump $(REG_BIN) >/dev/null
- regdbdump $(REG_BIN) >/dev/null
%.gz: %
@$(NQ) ' GZIP' $<
The CFLAG set with -sysroot=, assign the root directory of embeded development system.
- Copy the public key that is used to sign the regulatory.bin when compile wireless-regdb
thomas@PC3039:~/work/refers/crda/pubkeys$ cp ../../wireless-regdb/root.key.pub.pem .
thomas@PC3039:~/work/refers/crda/pubkeys$ ls
linville.key.pub.pem root.key.pub.pem sforshee.key.pub.pem thomas.key.pub.pem
- Compile crda program
thomas@PC3039:~/work/refers/crda$ make
GEN keys-gcrypt.c
Trusted pubkeys: pubkeys/linville.key.pub.pem pubkeys/root.key.pub.pem pubkeys/thomas.key.pub.pem pubkeys/sforshee.key.pub.pem
CC libreg.so
CC crda.o
LD crda
CC intersect.o
LD intersect
CC regdbdump.o
LD regdbdump
CC db2rd.o
LD db2rd
CC optimize.o
LD optimize
EXIST /home/work/cm/targetNFS/usr/lib/crda/regulatory.bin
ERROR: The file: /home/work/cm/targetNFS/usr/lib/crda/regulatory.bin is missing. You need this in place in order
to verify CRDA. You can get it from:
git://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git
Once cloned (no need to build) cp regulatory.bin to /home/work/cm/targetNFS/usr/lib/crda/regulatory.bin
Use "make noverify" to disable verification
Makefile:100: recipe for target '/home/work/cm/targetNFS/usr/lib/crda/regulatory.bin' failed
make: *** [/home/work/cm/targetNFS/usr/lib/crda/regulatory.bin] Error 1
To fix the above error, Just copy the regulatory.bin to /home/work/cm/targetNFS/usr/lib/crda/regulatory.bin. or you can ignore it.
- Install crda
thomas@PC3039:~/work/refers/crda$ make install DESTDIR=~/work/cm/targetNFS
INSTALL libreg
INSTALL libreg-headers
GZIP crda.8
GZIP regdbdump.8
INSTALL crda
INSTALL regdbdump
INSTALL 85-regulatory.rules
INSTALL crda.8.gz
INSTALL regdbdump.8.gz
- Copy public keys
thomas@PC3039:~/work/refers/wireless-regdb$ cp * ~/work/cm/targetNFS/etc/wireless-regdb/pubkeys/
Test crda regulatory management
~# 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 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
- enable DYNAMIC DEBUG
oot@am57xx-evm:~# echo 'file net/wireless/reg.c' > /sys/kernel/debug/dynamic_debug/control
Then
root@am57xx-evm:~# dmesg -c
root@am57xx-evm:~#
root@am57xx-evm:~#
root@am57xx-evm:~# iw reg set CN
root@am57xx-evm:~# dmesg -c
[ 1256.500100] cfg80211: Calling CRDA for country: CN
[ 1256.524562] cfg80211: Disabling freq 5500 MHz
[ 1256.524574] cfg80211: Disabling freq 5520 MHz
[ 1256.524584] cfg80211: Disabling freq 5540 MHz
[ 1256.524592] cfg80211: Disabling freq 5560 MHz
[ 1256.524601] cfg80211: Disabling freq 5580 MHz
[ 1256.524609] cfg80211: Disabling freq 5600 MHz
[ 1256.524617] cfg80211: Disabling freq 5620 MHz
[ 1256.524625] cfg80211: Disabling freq 5640 MHz
[ 1256.524632] cfg80211: Disabling freq 5660 MHz
[ 1256.524640] cfg80211: Disabling freq 5680 MHz
[ 1256.524648] cfg80211: Disabling freq 5700 MHz
[ 1256.524656] cfg80211: Disabling freq 5720 MHz
[ 1256.524674] cfg80211: Regulatory domain changed to country: CN
[ 1256.524683] cfg80211: DFS Master region: FCC
[ 1256.524692] cfg80211: (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)
[ 1256.524704] cfg80211: (2402000 KHz - 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
[ 1256.524714] cfg80211: (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2300 mBm), (N/A)
[ 1256.524725] cfg80211: (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2300 mBm), (0 s)
[ 1256.524735] cfg80211: (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 3000 mBm), (N/A)
[ 1256.524744] cfg80211: (57240000 KHz - 59400000 KHz @ 2160000 KHz), (N/A, 2800 mBm), (N/A)
[ 1256.524754] cfg80211: (59400000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 4400 mBm), (N/A)
[ 1256.524763] cfg80211: (63720000 KHz - 65880000 KHz @ 2160000 KHz), (N/A, 2800 mBm), (N/A)
root@am57xx-evm:~# iw reg set US
root@am57xx-evm:~# dmesg -c
[ 1268.202462] cfg80211: Calling CRDA for country: US
[ 1268.222993] cfg80211: Regulatory domain changed to country: US
[ 1268.223004] cfg80211: DFS Master region: FCC
[ 1268.223014] cfg80211: (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)
[ 1268.223026] cfg80211: (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 3000 mBm), (N/A)
[ 1268.223037] cfg80211: (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2300 mBm), (N/A)
[ 1268.223048] cfg80211: (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2300 mBm), (0 s)
[ 1268.223058] cfg80211: (5490000 KHz - 5730000 KHz @ 160000 KHz), (N/A, 2300 mBm), (0 s)
[ 1268.223068] cfg80211: (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 3000 mBm), (N/A)
[ 1268.223078] cfg80211: (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 4000 mBm), (N/A)
root@am57xx-evm:~# iw reg set 00
root@am57xx-evm:~# dmesg -c
[ 1280.208233] cfg80211: Calling CRDA to update world regulatory domain
[ 1280.228062] cfg80211: World regulatory domain updated:
[ 1280.228073] cfg80211: DFS Master region: unset
[ 1280.228083] cfg80211: (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)
[ 1280.228095] cfg80211: (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
[ 1280.228107] cfg80211: (2457000 KHz - 2482000 KHz @ 20000 KHz, 92000 KHz AUTO), (N/A, 2000 mBm), (N/A)
[ 1280.228116] cfg80211: (2474000 KHz - 2494000 KHz @ 20000 KHz), (N/A, 2000 mBm), (N/A)
[ 1280.228126] cfg80211: (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (N/A)
[ 1280.228137] cfg80211: (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (0 s)
[ 1280.228146] cfg80211: (5490000 KHz - 5730000 KHz @ 160000 KHz), (N/A, 2000 mBm), (0 s)
[ 1280.228155] cfg80211: (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 2000 mBm), (N/A)
[ 1280.228165] cfg80211: (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0 mBm), (N/A)
!! BUT the applied values are not my designated value in db.txt. Something must be wrong.
The checking process is like below,
root@am57xx-evm:/lib/udev/rules.d# cat 85-regulatory.rules
KERNEL=="regulatory*", ACTION=="change", SUBSYSTEM=="platform", RUN+="/usr/sbin/crda"
root@am57xx-evm:/lib/udev/rules.d# which crda
/usr/sbin/crda
root@am57xx-evm:/lib/udev/rules.d# crda
failed to open db file: No such file or directory
root@am57xx-evm:/usr/lib# export COUNTRY=CN
root@am57xx-evm:/usr/lib# crda
Failed to set regulatory domain: -7
Try to find the reason of return -7 by search internet, but did not find a suitable answer.
https://bbs.archlinux.org/viewtopic.php?id=150092
https://ubuntuforums.org/showthread.php?t=1860818
https://community.nxp.com/thread/352772
READ IT FROM DOWN TO UP!!
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: Timeout while waiting for CRDA to reply, restoring regulatory settings
Dec 11 13:40:53 am57xx-evm kernel[380]: [13333.441708] cfg80211: Calling CRDA to update world regulatory domain
Dec 11 13:40:53 am57xx-evm kernel[380]: [13333.441676] cfg80211: Restoring regulatory settings
Dec 11 13:40:53 am57xx-evm kernel: cfg80211: Calling CRDA to update world regulatory domain
Dec 11 13:40:53 am57xx-evm kernel: cfg80211: Kicking the queue
Dec 11 13:40:53 am57xx-evm kernel: cfg80211: Restoring regulatory settings
Dec 11 13:40:53 am57xx-evm kernel: cfg80211: Timeout while waiting for CRDA to reply, restoring regulatory settings
Dec 11 13:40:53 am57xx-evm systemd-udevd[1559]: [[0;1;39mProcess '/sbin/crda' failed with exit code 2.[[0m
Dec 11 13:40:53 am57xx-evm systemd-udevd[1560]: [[0;1;31mfailed to execute '/sbin/crda' '/sbin/crda': No such file or directory[[0m
Dec 11 13:40:52 am57xx-evm oracast.sh[694]: [12-11/13:40:52:133680]No network, retry!!!
Dec 11 13:40:50 am57xx-evm kernel[380]: [13330.241703] cfg80211: Calling CRDA to update world regulatory domain
Dec 11 13:40:50 am57xx-evm kernel[380]: [13330.241671] cfg80211: Restoring regulatory settings
Dec 11 13:40:50 am57xx-evm kernel[380]: [13330.241657] cfg80211: Timeout while waiting for CRDA to reply, restoring regulatory settings
Dec 11 13:40:50 am57xx-evm kernel: cfg80211: Calling CRDA to update world regulatory domain
Dec 11 13:40:50 am57xx-evm kernel: cfg80211: Kicking the queue
Dec 11 13:40:50 am57xx-evm kernel: cfg80211: Restoring regulatory settings
Dec 11 13:40:50 am57xx-evm kernel: cfg80211: Timeout while waiting for CRDA to reply, restoring regulatory settings
Dec 11 13:40:50 am57xx-evm systemd-udevd[1557]: [[0;1;39mProcess '/sbin/crda' failed with exit code 2.[[0m
Dec 11 13:40:50 am57xx-evm systemd-udevd[1558]: [[0;1;31mfailed to execute '/sbin/crda' '/sbin/crda': No such file or directory[[0m
Dec 11 13:40:47 am57xx-evm oracast.sh[694]: [12-11/13:40:47:133249]No network, retry!!!
Dec 11 13:40:47 am57xx-evm systemd-udevd[1555]: [[0;1;39mProcess '**/sbin/crda**' failed with exit code 2.
we do not have /sbin/crda, so link it to /usr/sbin/crda, then -7 probem solved.
READ IT FROM DOWN TO UP!!
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675129] cfg80211: (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675119] cfg80211: (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675110] cfg80211: (5490000 KHz - 5730000 KHz @ 160000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675100] cfg80211: (5250000 KHz - 5330000 KHz @ 80000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675090] cfg80211: (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675080] cfg80211: (2474000 KHz - 2494000 KHz @ 20000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675059] cfg80211: (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675037] cfg80211: DFS Master region: unset
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675027] cfg80211: World regulatory domain updated:
Dec 11 13:40:56 am57xx-evm kernel[380]: [13336.675009] cfg80211: Ignoring regulatory request set by core since the driver uses its own custom regulatory domain
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (5490000 KHz - 5730000 KHz @ 160000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (5250000 KHz - 5330000 KHz @ 80000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (2474000 KHz - 2494000 KHz @ 20000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (2457000 KHz - 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: DFS Master region: unset
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: World regulatory domain updated:
Dec 11 13:40:56 am57xx-evm kernel: cfg80211: Ignoring regulatory request set by core since the driver uses its own custom regulatory domain
The values is what I set in db.txt
REFERENCE:
http://networkgeekstuff.com/networking/how-to-create-custom-linux-wi-fi-regulatory-database-to-unlock-30db1000mw/
https://blog.csdn.net/Yao_GUET/article/details/25067241