樹莓派使用 comfast 無線網卡

Li-Yongjun 2021-09-18 06:01:26 阅读数:367

使用 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查看一下哪些地方使用了這些宏

[email protected]:~/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__);
}

編譯通過,安裝到內核

[email protected]:~/project/c/DRIVERS/rtl8821CU$ sudo modprobe 8821cu

查看驅動是否安裝成功

[email protected]:~/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 說明驅動模塊載入內核成功。

接著,拔插無線網卡,看到無線網卡已經被成功驅動,並且可以正常使用了,wlan0 是樹莓派自帶的無線網卡,wlan1 就是 comfast 無線網卡。

[email protected]:~/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
版权声明:本文为[Li-Yongjun]所创,转载请带上原文链接,感谢。 https://gsmany.com/2021/09/20210918060126465h.html