IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> wireless中添加country code的方法(wireless-regdb crda) -> 正文阅读

[系统运维]wireless中添加country code的方法(wireless-regdb crda)

最近接到一个活,当前的产品中需要添加某个国家的wireless的country code,因为在已有的固件中,没有这个国家的country code,需要人为添加进去。
这个应该算是屠龙技,要添加country code的几率很少,都是事先配置好,不允许开发者随便更改country code的配置,所以整的比较复杂。
这个country code如何工作的,相信研究这块的人事先都会找其他资料了解,这里不再多说。这篇文章主要是写给我自己看,防止以后忘记。
work flow: application use crda , crda send message to regulatory.bin , regulatory.bin cmd to nl80211, then to wireless-chip.
在这里插入图片描述

CRDA和wireless-regdb的官方规格文档

CRDA https://wireless.wiki.kernel.org/en/developers/Regulatory/CRDA
如果kernel中使能了 CONFIG_CFG80211_INTERNAL_REGDB, 可以把wireless-regdb下的db.txt拷贝到kernel/net/wireless/db.txt下,然后重新编译kernel
CONFIG_CFG80211_INTERNAL_REGDB
If you do not want to install CRDA on a host, you can simply enable the CONFIG_CFG80211_INTERNAL_REGDB on your kernel. Once enabled you can place the db.txt from the wireless-regdb into net/wireless/db.txt. The downside to using this option is that you will need to rebuild your kernel for any regulatory updates, therefore using CONFIG_CFG80211_INTERNAL_REGDB is not recommended.

If using CONFIG_CFG80211_INTERNAL_REGDB without updating net/wireless/db.txt you’ll end up with the static world regulatory domain, so if using CONFIG_CFG80211_INTERNAL_REGDB you should be sure to update net/wireless/db.txt otherwise you may end up spending a lot of time debugging an issue that does not exist. To help with this a patch has been sent to print a warning when a kernel has been built with CONFIG_CFG80211_INTERNAL_REGDB but the database is emtpy. If you happen to also have CONFIG_CFG80211_REG_DEBUG then compiling of the kernel will simply fail.

Build requirements

python and the m2crypto package (python-m2crypto)
libgcrypt or libssl (openssl) header files
nl library and header files (libnl1 and libnl-dev) available at git:git.kernel.org/pub/scm/libs/netlink/libnl.git * RSA public key of Seth Forshee, we include this as part of this package so you do not need to install it. This RSA public key comes from the wireless-regdb.git tree and we keep it up to date here. * regulatory database (regulatory.bin, no need to build just put the file in REG_BIN location) from: git:git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git

Letting the kernel call CRDA
We use userspace events (uevents) to let the kernel speak to userspace. Below is an example udev rule you can place into your distribution’s udev rules directory (usually /etc/udev/rules.d/). Note that most distributions have udev configured with inotify on the udev rules directory, so there is no need to restart udev after adding the new rule.

Example file, should be put in /etc/udev/rules.d/regulatory.rules
KERNEL==“regulatory*”, ACTION==“change”, SUBSYSTEM==“platform”, RUN+="/sbin/crda"
这个设备的路径为 😕# cat ./usr/lib/udev/rules.d/85-regulatory.rules

How to test

		iw reg get 
		iw reg set MM
		iw reg get 

yocto system use default wireless-regdb output: regulatory.bin sforshee.key.pub.pem, and copy regulatory.bin and sforshee.key.pub.pem to crda source codes path to let crda compile. But crda codes just use its sforshee.key.pub.pem to compile, so need to manually copy sforshee.key.pub.pem into pubkeys/ firstly, and then manually compile crda codes to generate crda and libreg.so.

Action:

step1: modify db.txt, compile wireless-regdb-2018 codes on Linux system to generate regulatory.bin and joy.key.pub.pem. use gcc toolchain(PC自带的gcc,这里是把txt转换成bin), not use CROSS_COMPILE toolchain.

modify db.txt
country ZA: DFS-ETSI
(2402 - 2482 @ 40), (20)
(5170 - 5250 @ 80), (20), AUTO-BW
(5250 - 5330 @ 80), (20), DFS, AUTO-BW
(5490 - 5710 @ 160), (30)

编译报错 error: wireless-regdb-2018.10.24$ make

crda-3.18-r0 do_compile: oe_runmake failed  ERROR: Failed to import the "M2Crypto" module: No module named M2Crypto
15:00:29  |   Trusted pubkeys: pubkeys/linville.key.pub.pem pubkeys/sforshee.key.pub.pem
15:00:29  | ERROR: Failed to import the "M2Crypto" module: No module named M2Crypto
15:00:29  | Please install the "M2Crypto" Python module.
15:00:29  | On Debian GNU/Linux the package is called "python-m2crypto".
15:00:29  | Makefile:113: recipe for target 'keys-gcrypt.c' failed

yocto compile fail, download wireless-regdb-2018 codes and compile with gcc also fail, no module named M2Crtpto. So need intall M2Crtpto firstly.


在Ubuntu上安装 python的 M2Crypto 库,需要如下步骤:
一、环境说明
1.操作系统:Ubuntu Desktop 18.04;
2.python版本:python3.6;
3.官网地址:https://gitlab.com/m2crypto/m2crypto

二、安装
1、安装依赖,命令如下:
sudo apt install libssl-dev swig

2、安装m2crypto模块,命令如下:
pip3 install M2Crypto

三、FAQ
Q:ubuntu操做系统如何安装pip
A:命令如下:
sudo apt-get install python3-pip

期间报错 sudo apt install libssl-dev swig, 
今天重装网络工具的时候突然报错:
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

查了一下
直接sudo rm /var/lib/dpkg/lock-frontend就行了
如果仍然出现,需要手动删除 /var/lib/dpkg/lock即可。
lgj@lgj-Lenovo-G470:~$ rm -rf /var/lib/dpkg/lock

Err:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates/main amd64 libssl1.1 amd64 1.1.1-1ubuntu2.1~18.04.13
  Could not connect to 3.28.29.242:9400 (3.28.29.242). - connect (111: Connection refused)

导致上述的报错是因为linux电脑上proxy中的ip设置不完善造成的,咨询 他人, 修改如下代码后,可以正常安装 pip  install M2Crypto 
xx:/etc/apt$ cat apt.conf
Acquire::http::Proxy "http://3.20.128.6:88/";
Acquire::https::Proxy "http://3.20.128.6:88/";

xx:/opt/Python-3.6.3$ pip3 install M2Crypto
Collecting M2Crypto
  Using cached https://files.pythonhosted.org/packages/2c/52/c35ec79dd97a8ecf6b2bbd651df528abb47705def774a4a15b99977274e8/M2Crypto-0.38.0.tar.gz
Building wheels for collected packages: M2Crypto
  Running setup.py bdist_wheel for M2Crypto ... done
  Stored in directory: /home/heyi/.cache/pip/wheels/a7/93/af/959d45139d9d61d1acc6be9fc093ef968df270fb3b6abbfb7a
Successfully built M2Crypto
Installing collected packages: M2Crypto
Successfully installed M2Crypto-0.38.0
You are using pip version 8.1.1, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
xx:/opt/Python-3.6.3$


上述编译成功后,编译wireless-regdb代码(make)仍然编译报错,error:  主要是这里使用了默认的url来下载 M2Crypto, 这个URL在国内是被屏蔽了,使用如下的指令 切换源url可以下载,
pip is configured with locations that require TLS/SSL
Could not fetch URL https://pypi.org/simple/pywinauto/: There was a problem co


pip install M2Crypto -i http://pypi.douban.com/simple --trusted-host pypi.douban.com  这里使用了豆瓣的url,也可以使用清华等镜像,但安装过程中又报错了,说是没有权限,
阿里云: -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
http://pypi.douban.com/  豆瓣

http://pypi.hustunique.com/  华中理工大学

http://pypi.sdutlinux.org/  山东理工大学

http://pypi.mirrors.ustc.edu.cn/  中国科学技术大学

error: could not delete '/usr/local/lib/python3.6/site-packages/pip/_internal/configuration.py': Per
执行如下指令, xx:/usr/local/lib/python3.6$ sudo chown -R $(whoami) *   输入这条指令在更改权限
xx:/usr/local/lib/python3.6$ ls -ll
total 4636
-rw-r--r--  1 xx root   8648 8月  23 10:37 abc.py
再重新执行上面的安装指令,即安装成功,
这时候再在wireless-regdb目录下输入make,则make sucessfully;
xx:~/wireless-regdb-2018/wireless-regdb-2018.10.24$ make        
make sucessfully
Generating regulatory.bin digitally signed by xx...
./db2bin.py regulatory.bin db.txt ~/.wireless-regdb-xx.key.priv.pem
Generating certificate for xx...
./gen-pubcert.sh ~/.wireless-regdb-heyi.xx.priv.pem xx.x509.pem
Signing regulatory.db (by xx)...

Step 2: build crda,
reference url: https://blog.csdn.net/subplot/article/details/80541525 , but not OK.
download crda_3.18 codes, and compile, modify Makefile, use CROSS_COMPILE(if this toolchian generate many errors, can use gcc default firstly) to compile, but compile fail.

error:
当前系统使用的gcc版本号

xx:/usr/bin$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	


@@ -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' $<
————————————————
版权声明:本文为CSDN博主「subplot」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/subplot/article/details/80541525


编译crda的源码,需要使用cross_compile进行编译,修改Makefile,编译报错,修改gcc的编译路径 lib库,仍旧失败,后找不到libnl-3.0失败,强制找到;后发现python编译报错,找不到相应的库,网上找资料
发现当前的crda版本不支持python3编译,找patch修改代码后,发现还是报错,网上找解决原有;
要装rsa, 失败后再uninstall pycryptodome,然后再重新install,这时候报错消失,


export PKG_CONFIG_PATH=/home/xx/tmp/sysroots-components/cortexa9t2hf-neon/libnl/usr/lib/pkgconfig  可以找到libnl-3.so这个库文件

单独编译crda仍旧报错,无法使用python2来编译,后网上发现需要对crda_3.18源码打补丁,才行,按照网上的例子,对源码打补丁,仍旧报错;


1)网上范围yocto资料, 修改wireless-2018的bb文档, 把xx.pb.key.pem改名称默认的sfore.pem,编译成功,也生成想要的pem,把对应的regulatory.bin拷贝到了 crda_3.18想要编译的目录下,
2)crda3.18编译的时候,使用的是网上的源码,默认的sfore.pem,即使调用了正确的regulatory.bin, 生成的crda是根据老的sfore.pem来编译,可能不匹配。  不过可以尝试下使用老的sfore.pem 新的regulatory.bin 新的crda来测试一下; libreg.so是否也要替换?     
都替换后,没有作用; 后续先恢复原样,然后一个个替换,确定哪些文件替换后会造成影响;  目前发现regulatory.bin crda libreg.so heyi.pub.key.pem必须替换掉;

regulatory.bin crda 即使什么都不改动,重新编译一下,regulatory.bin,放进去仍旧报错,因为作者不一样,生成的pubkey已经改动了,需要根据这个改动的pubkey生成的crda才能配套使用;

3)后续尝试改crda的bb文件,把新的sfore.pem 放进去打包,使用本地的源码来进行编译,看是否可行;

4)把yocto编译的打了patch的crda源码拷贝出来,在此基础上进行编译;
5)编译yocto的toolchain, 然后在此基础上进行编译crda代码;	

crda在yocto中编译成功,拷贝到设备里后(需要把这几个文件替换即可:crda xx.key.pub.pem libreg.so regulatory.bin sforshee.key.pub.pem),set country code sucessfully。

设置指令:iw reg set MM
root@:~# iw reg get
global
country MM: DFS-FCC
		(2402 - 2482 @ 40), (N/A, 20), (N/A)
		(5170 - 5250 @ 80), (N/A, 24), (N/A), AUTO-BW
		(5250 - 5330 @ 80), (N/A, 24), (0 ms), DFS, AUTO-BW
		(5490 - 5730 @ 160), (N/A, 24), (0 ms), DFS
		(5735 - 5835 @ 80), (N/A, 30), (N/A)

crda的编译方式如下,先把wireless-regdb中编译的xx.key.pub.pem(regulatory.bin可以不用拷贝,最重要的文件就只有xx.key.pub.pem)拷贝到crda目录下,然后用下面的指令手动进行编译,就能编译成功自己需要的库。
bitbake -b foo_1.0.bb
bitbake -b foo.bb -c clean

bitbake -b wireless-regdb_2018.10.24.bb -D
bitbake -b crda_3.18.bb -C compile

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-03-06 13:35:20  更:2022-03-06 13:37:30 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/16 3:38:08-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码