# 前缘

comfast无线网卡

去年在淘宝上买了一个无线网卡,由于是给办公室电脑用,系统是 Windows 10 ,就买了个便宜的,只支持 Windows 和 MAC 。

期间也尝试过插在蜗牛星际上(Ubuntu Server 18.04),只看到多了一个usb设备,并不能产生无线网络接口,问淘宝卖家,给了一个驱动链接

CF-811AC驱动下载地址:http://www.comfast.cn/index.php?m=content&c=index&a=show&catid=30&id=335

下载下来也没编过,结果就没在Linux上用上。

# 再续

最近在研究 Wi-Fi ,又把它掏了出来,看看能不能在 Linux 上 用起来。

直接插在树莓派上,还是和之前一样,只显示多了一个usb设备,并没有无线网络接口产生。

网上搜到了这篇教程 《Linux安装comfast 811AC usb网卡驱动》 ,就跟着上面的步骤下载编译。

由于树莓派里面没有装内核头文件,所以编译报错,解决办法,安装内核头文件

sudo apt install raspberrypi-kernel-headers

注意,ARM 架构的话要执行 README.md 里的三句指令

sudo cp /lib/modules/$(uname -r)/build/arch/arm/Makefile /lib/modules/$(uname -r)/build/arch/arm/Makefile.$(date +%Y%m%d%H%M)
sudo sed -i 's/-msoft-float//' /lib/modules/$(uname -r)/build/arch/arm/Makefile
sudo ln -s /lib/modules/$(uname -r)/build/arch/arm /lib/modules/$(uname -r)/build/arch/armv7l

继续编译,又报错

/home/pi/project/c/DRIVERS/rtl8821CU/core/rtw_debug.c: In function ‘dump_drv_version’:
/home/pi/project/c/DRIVERS/rtl8821CU/core/rtw_debug.c:45:62: error: macro "__DATE__" might prevent reproducible builds [-Werror=date-time]
  RTW_PRINT_SEL(sel, "build time: %s %s\n", __DATE__, __TIME__);
                                                              ^
/home/pi/project/c/DRIVERS/rtl8821CU/core/rtw_debug.c:45:62: error: macro "__TIME__" might prevent reproducible builds [-Werror=date-time]
/home/pi/project/c/DRIVERS/rtl8821CU/core/rtw_debug.c:45:62: error: macro "__DATE__" might prevent reproducible builds [-Werror=date-time]
/home/pi/project/c/DRIVERS/rtl8821CU/core/rtw_debug.c:45:62: error: macro "__TIME__" might prevent reproducible builds [-Werror=date-time]
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:304: /home/pi/project/c/DRIVERS/rtl8821CU/core/rtw_debug.o] Error 1
make[1]: *** [Makefile:1522: _module_/home/pi/project/c/DRIVERS/rtl8821CU] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.19.97-v7+'
make: *** [Makefile:2217: modules] Error 2

提示没有 __TIME____DATE__ 宏,grep查看一下哪些地方使用了这些宏

pi@raspberrypi:~/project/c/DRIVERS/rtl8821CU $ grep -rn "__DATE__"
core/rtw_debug.c:45:	RTW_PRINT_SEL(sel, "build time: %s %s\n", __DATE__, __TIME__);

发现只有一句,本来想给它手动改个时间日期填上,结果感觉不是什么重要的语句,就直接注释掉了

void dump_drv_version(void *sel)
{
        RTW_PRINT_SEL(sel, "%s %s\n", DRV_NAME, DRIVERVERSION);
        //RTW_PRINT_SEL(sel, "build time: %s %s\n", __DATE__, __TIME__);
}

编译通过,安装到内核

pi@raspberrypi:~/project/c/DRIVERS/rtl8821CU$ sudo modprobe 8821cu

查看安装是否成功

pi@raspberrypi:~/project/c/DRIVERS/rtl8821CU$ lsmod
Module                  Size  Used by
8821cu               2404352  0
r8188eu               438272  0
lib80211               16384  1 r8188eu
nls_ascii              16384  1
btsdio                 20480  0
bluetooth             557056  1 btsdio
ecdh_generic           16384  1 bluetooth
ecc                    36864  1 ecdh_generic
brcmfmac              385024  0
brcmutil               24576  1 brcmfmac
bcm2835_v4l2           45056  0
bcm2835_mmal_vchiq     40960  1 bcm2835_v4l2
vc_sm_cma              45056  1 bcm2835_mmal_vchiq
v4l2_common            16384  1 bcm2835_v4l2
videobuf2_vmalloc      20480  1 bcm2835_v4l2
videobuf2_memops       20480  1 videobuf2_vmalloc
cfg80211              692224  3 r8188eu,brcmfmac,8821cu
videobuf2_v4l2         28672  1 bcm2835_v4l2

出现了 8821cu 说明驱动模块载入内核成功。

接着,拔插无线网卡,

pi@raspberrypi:~/project/c/DRIVERS/rtl8821CU $ ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.116  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::c294:4582:7476:70d5  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:8a:bc:f4  txqueuelen 1000  (Ethernet)
        RX packets 1122  bytes 123550 (120.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 849  bytes 280450 (273.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 172  bytes 14084 (13.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 172  bytes 14084 (13.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.211  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::7186:984c:b898:8ef3  prefixlen 64  scopeid 0x20<link>
        ether de:88:c4:e0:37:89  txqueuelen 1000  (Ethernet)
        RX packets 330  bytes 42876 (41.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 225  bytes 31375 (30.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.178  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::5ca7:f148:acc7:565a  prefixlen 64  scopeid 0x20<link>
        ether 6e:b8:f3:2a:7b:76  txqueuelen 1000  (Ethernet)
        RX packets 462  bytes 76567 (74.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 245  bytes 34741 (33.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

搞定,wlan0 是树莓派自带的无线网卡,wlan0 就是 confast 无线网卡。

树莓派-无线网卡