RK3399使用rtl8821cu wifi芯片
2020-10-27 本文已影响0人
Mr_Michael
一、添加内核驱动
1.下载驱动文件
# 将官方驱动程序下载到内核drivers/net/wireless/realtek路径下
cp -r rtl8821CU_rtl8731AU_WiFi_linux_v5.8.1.4_36409.20200313_COEX20191014-4141 kernel/drivers/net/wireless/realtek/rtl8821cu
2.修改Makefile
122c122
< CONFIG_PLATFORM_I386_PC = y
---
> CONFIG_PLATFORM_I386_PC = n
147a148
> CONFIG_PLATFORM_ARM_RK3399 = y
1683a1685,1696
>
> ifeq ($(CONFIG_PLATFORM_ARM_RK3399), y)
> EXTRA_CFLAGS += -DCONFIG_LITTLE_ENDIAN -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT -DCONFIG_CONCURRENT_MODE -DCONFIG_PLATFORM_ROCKCHIPS
> ARCH := arm64
> #CROSS_COMPILE := /home/michael/project/rk3399/linux-sdk-jiangxing/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
> #KSRC := /home/michael/project/rk3399/linux-sdk-jiangxing/kernel
> MODULE_NAME := rtl8821cu
> endif
>
3.修改上一级Makefile
diff --git a/drivers/net/wireless/realtek/Makefile b/drivers/net/wireless/realtek/Makefile
index 9c78deb..cda39ff 100644
--- a/drivers/net/wireless/realtek/Makefile
+++ b/drivers/net/wireless/realtek/Makefile
@@ -6,4 +6,5 @@ obj-$(CONFIG_RTL8180) += rtl818x/
obj-$(CONFIG_RTL8187) += rtl818x/
obj-$(CONFIG_RTLWIFI) += rtlwifi/
obj-$(CONFIG_RTL8XXXU) += rtl8xxxu/
+obj-$(CONFIG_RTL8821CU) += rtl8821cu/
4.修改上上级Kconfig
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index d2735fa..6ede54d 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -287,6 +287,7 @@ source "drivers/net/wireless/rt2x00/Kconfig"
source "drivers/net/wireless/realtek/rtl8xxxu/Kconfig"
+source "drivers/net/wireless/realtek/rtl8821cu/Kconfig"
source "drivers/net/wireless/rockchip_wlan/Kconfig"
5.修改配置选项
--- a/arch/arm64/configs/jiangxing_um1b_mg_rk3399_defconfig
+++ b/arch/arm64/configs/jiangxing_um1b_mg_rk3399_defconfig
@@ -176,9 +176,11 @@ CONFIG_BT_HCIBFUSB=y
+CONFIG_CFG80211=y
+CONFIG_MAC80211=y
@@ -229,10 +231,7 @@ CONFIG_HOSTAP=y
-CONFIG_WL_ROCKCHIP=y
-CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP=y
-CONFIG_AP6XXX=y
-CONFIG_RTL8188EU=y
+CONFIG_RTL8821CU=y
二、系统操作wifi模块
1.查看系统wifi设备
- 加入WG217驱动后,系统将新增wlan0(wlx30eb1f1f3b8f)和wlan1两个接口设备。wlan0用于station模式,wlan1用于AP模式。
$ lsusb |grep Realtek
Bus 007 Device 003: ID 0bda:c811 Realtek Semiconductor Corp.
$ dmesg |grep rtl8821cu
[ 1.440770] RTW: rtl8821cu v5.8.1.4_36402.20200302_beta
[ 1.441666] RTW: rtl8821cu BT-Coex version = COEX20191014-4141
[ 1.442702] usbcore: registered new interface driver rtl8821cu
[ 3.339141] rtl8821cu 7-1.1:1.0 wlx30eb1f1f3b8f: renamed from wlan0
$ ls /sys/class/net/
eth0 eth1 lo sit0 usb0 usb1 wlan1 wlx30eb1f1f3b8f wwan0 wwan1
# 出现wlan0和wlan1,其中wlan0被系统重命名为wlx30eb1f1f3b8f
2.使用wifi模块连接热点
1)基础信息
sudo apt-get install wireless-tools
sudo apt-get install iw
sudo ifconfig wlx30eb1f1f3b8f
# 搜索附近wifi
sudo iwlist wlx30eb1f1f3b8f scanning
Cell 03 - Address: 74:F8:DB:63:A1:6C
ESSID:"4G-WIFI-A16C"
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.462 GHz (Channel 11)
Encryption key:on
Bit Rates:300 Mb/s
Extra:wpa_ie=dd160050f20101000050f20401000050f20401000050f202
IE: WPA Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Extra:
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Quality=60/100 Signal level=-32 dBm
Extra:fm=0003
# 显示频道信息
sudo iwlist wlx30eb1f1f3b8f frequen
wlx30eb1f1f3b8f 32 channels in total; available frequencies :
Channel 01 : 2.412 GHz
Channel 02 : 2.417 GHz
Channel 03 : 2.422 GHz
Channel 04 : 2.427 GHz
Channel 05 : 2.432 GHz
Channel 06 : 2.437 GHz
Channel 07 : 2.442 GHz
Channel 08 : 2.447 GHz
Channel 09 : 2.452 GHz
Channel 10 : 2.457 GHz
Channel 11 : 2.462 GHz
Channel 12 : 2.467 GHz
Channel 13 : 2.472 GHz
Channel 36 : 5.18 GHz
Channel 40 : 5.2 GHz
Channel 44 : 5.22 GHz
Channel 48 : 5.24 GHz
Channel 52 : 5.26 GHz
Channel 56 : 5.28 GHz
Channel 60 : 5.3 GHz
Channel 64 : 5.32 GHz
Channel 100 : 5.5 GHz
Channel 104 : 5.52 GHz
Channel 108 : 5.54 GHz
Channel 112 : 5.56 GHz
Channel 116 : 5.58 GHz
Channel 120 : 5.6 GHz
Channel 124 : 5.62 GHz
Channel 128 : 5.64 GHz
Channel 132 : 5.66 GHz
Channel 136 : 5.68 GHz
Channel 140 : 5.7 GHz
Current Frequency:5.785 GHz
# 显示连接速度
sudo iwlist wlx30eb1f1f3b8f rate
wlx30eb1f1f3b8f 4 available bit-rates :
1 Mb/s
2 Mb/s
5.5 Mb/s
11 Mb/s
Current Bit Rate:434 Mb/s
# 显示无线网络设备信息
iwconfig
wlan1 unassociated Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency=5.785 GHz Access Point: Not-Associated
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=0/100 Signal level=0 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
wlx30eb1f1f3b8f IEEE 802.11AC ESSID:"jxoffice5g" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:5.785 GHz Access Point: 74:05:A5:82:58:B4
Bit Rate:434 Mb/s Sensitivity:60/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:****-****-****-****-****-****-****-**** Security mode:open
Power Management:off
Link Quality=86/100 Signal level=-60 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
2)使用配置文件默认连接wifi热点
wpa_supplicant是wifi客户端(client)加密认证工具,wpa_supplicant支持wep、wpa、wpa2等完整的加密认证,而iwconfig只能支持wep。
wpa_supplicant运行于后台,它需要借助控制台工具wpa_cli来进行手动操作,使用wpa_cli来搜索、设置、和连接网络。
- 常用命令
usage:
wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] [-g<global ctrl>] \
[-G<group>] \
-i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
[-b<br_ifname>] [-e<entropy file>] [-f<debug file>] \
[-o<override driver>] [-O<override ctrl>] \
[-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
[-m<P2P Device config file>] \
[-p<driver_param>] [-b<br_ifname>] [-I<config file>] ...]
drivers:
nl80211 = Linux nl80211/cfg80211
wext = Linux wireless extensions (generic)
wired = Wired Ethernet driver
none = no driver (RADIUS server/WPS ER)
options:
-b = optional bridge interface name
-B = run daemon in the background
-c = Configuration file
-C = ctrl_interface parameter (only used if -c is not)
-d = increase debugging verbosity (-dd even more)
-D = driver name (can be multiple drivers: nl80211,wext)
-e = entropy file
-f = log output to debug file instead of stdout
-g = global ctrl_interface
-G = global ctrl_interface group
-h = show this help text
-i = interface name
-I = additional configuration file
-K = include keys (passwords, etc.) in debug output
-L = show license (BSD)
-m = Configuration file for the P2P Device interface
-N = start describing new interface
-o = override driver parameter for new interfaces
-O = override ctrl_interface parameter for new interfaces
-p = driver parameters
-P = PID file
-q = decrease debugging verbosity (-qq even less)
-s = log output to syslog instead of stdout
-t = include timestamp in debug messages
-T = record to Linux tracing in addition to logging
(records all messages regardless of debug verbosity)
-u = enable DBus control interface
-v = show version
-W = wait for a control interface monitor before starting
example:
wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf
-
添加配置文件
sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
# 填入以下信息
country=CN
ctrl_interface=/var/run/wpa_supplicant
update_config=1
network={
ssid="4G-WIFI-A16C"
psk="12345678"
scan_ssid=1
proto=RSN WPA2
key_mgmt=WPA-PSK
pairwise=TKIP
group=TKIP
}
# 精简写法
ctrl_interface=/var/run/wpa_supplicant
update_config=1
country=CN
network={
ssid="4G-WIFI-A16C"
psk="12345678"
}
# 注意:如果需要修改WIFI网络名称和密码只需修改上文的:
ssid="JX-4423"
psk="jiangxing123"
# 或者
ssid="jxoffice5g"
psk="jiangxing111222333"
- 运行wpa_supplicant
sudo wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlx30eb1f1f3b8f -D nl80211
Successfully initialized wpa_supplicant
$ iwconfig wlx30eb1f1f3b8f
wlx30eb1f1f3b8f IEEE 802.11bgn ESSID:"4G-WIFI-A16C" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:2.462 GHz Access Point: 74:F8:DB:63:A1:6C
Bit Rate:150 Mb/s Sensitivity:29/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:****-****-****-****-****-****-****-**** Security mode:open
Power Management:off
Link Quality=98/100 Signal level=-29 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
# 动态分配ip
sudo dhclient wlx30eb1f1f3b8f
$ ifconfig wlx30eb1f1f3b8f
wlx30eb1f1f3b8f: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.69 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::32eb:1fff:fe1f:3b8f prefixlen 64 scopeid 0x20<link>
ether 30:eb:1f:1f:3b:8f txqueuelen 1000 (Ethernet)
RX packets 56 bytes 359297 (359.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15 bytes 15095 (15.0 KB)
TX errors 0 dropped 94 overruns 0 carrier 0 collisions 0
- 停止wpa_supplicant,断开wifi连接
# sudo apt-get install psmisc
sudo killall dhclient wpa_supplicant
# 会自动删除旧节点
# sudo rm /var/run/wpa_supplicant/wlx30eb1f1f3b8f
3)使用wpa_cli来搜索、设置、和连接网络
# 需要预先启动wpa_supplicant
sudo wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf -i wlx30eb1f1f3b8f -D nl80211
# 扫描热点
sudo wpa_cli -i wlx30eb1f1f3b8f scan
OK
# 列出热点
sudo wpa_cli -i wlx30eb1f1f3b8f scan_results
74:f8:db:63:a1:6c 2462 -28 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] 4G-WIFI-A16C
7a:05:a5:82:58:b4 5785 -58 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] jxtest5g
d0:76:e7:5e:44:28 5745 -59 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] TP-LINK_5G_4423
74:05:a5:82:58:b4 5785 -59 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] jxoffice5g
76:40:bb:3c:fb:0d 5785 -64 [WPA2-PSK-CCMP][WPS][ESS] DIRECT-0d-HP M227f LaserJet
74:05:a5:82:58:af 2412 -48 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] jxoffice
d0:76:e7:5e:44:23 2462 -51 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] JX-4423
# 增加一个网络连接:
sudo wpa_cli -i wlx30eb1f1f3b8f add_network
# 配置WiFi热点的名称ssid,注意双引号外要有单引号
sudo wpa_cli -i wlx30eb1f1f3b8f set_network 1 ssid '"jxoffice5g"'
# 配置WiFi热点的密码psk
sudo wpa_cli -i wlx30eb1f1f3b8f set_network 1 psk '"jiangxing111222333"'
# 使能连接
sudo wpa_cli -i wlx30eb1f1f3b8f enable_network 1
# 失能连接
sudo wpa_cli -i wlx30eb1f1f3b8f disable_network 1
# 断开热点:
sudo wpa_cli -i wlx30eb1f1f3b8f disconnect
# 重连热点:
sudo wpa_cli -i wlx30eb1f1f3b8f reconnect
# 删除热点:
sudo wpa_cli -i wlx30eb1f1f3b8f remove_network 1
# 保存连接
sudo wpa_cli -i wlx30eb1f1f3b8f save_config
# 保存热点后,配置文件会自动更新
$ cat /etc/wpa_supplicant/wpa_supplicant.conf
/*
ctrl_interface=/var/run/wpa_supplicant
update_config=1
country=CN
network={
ssid="4G-WIFI-A16C"
psk="12345678"
disabled=1
}
network={
ssid="jxoffice5g"
psk="jiangxing111222333"
}
*/
# 查看已有连接
sudo wpa_cli -i wlx30eb1f1f3b8f list_network
network id / ssid / bssid / flags
0 4G-WIFI-A16C any [DISABLED]
1 jxoffice5g any [CURRENT]
# 选择连接
sudo wpa_cli -i wlx30eb1f1f3b8f select_network 1
$ iwconfig wlx30eb1f1f3b8f
wlx30eb1f1f3b8f IEEE 802.11AC ESSID:"jxoffice5g" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:5.785 GHz Access Point: 74:05:A5:82:58:B4
Bit Rate:434 Mb/s Sensitivity:62/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:****-****-****-****-****-****-****-**** Security mode:open
Power Management:off
Link Quality=61/100 Signal level=-62 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:
# 切换网络需要重新分配ip
sudo dhclient wlx30eb1f1f3b8f
# 查看热点状态
sudo wpa_cli -i wlx30eb1f1f3b8f status
bssid=74:05:a5:82:58:b4
freq=5785
ssid=jxoffice5g
id=1
mode=station
pairwise_cipher=CCMP
group_cipher=TKIP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=10.50.1.58
address=30:eb:1f:1f:3b:8f
uuid=a66aa087-2085-555d-866d-06d4b544b59f
3.wifi模块的AP模式
1)安装网络工具
sudo apt-get install -y hostapd
sudo apt-get install libnl-3-dev
sudo apt-get install -y dnsmasq
sudo apt-get install -y isc-dhcp-server
2)设置分配IP的范围
sudo vim /etc/dhcp/dhcpd.conf
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.2 192.168.2.254;
option domain-name-servers 192.168.2.1;
option routers 192.168.2.1;
}
3)使用hostapd创建普通热点
开启普通热点,只有一个无线网卡,无法上网的热点
- 2.4G频段配置
sudo vim /etc/hostapd/rtl_hostapd_2G.conf
interface=wlan1
ctrl_interface=/var/run/hostapd
ssid=RK3399-UM1B-2G
channel=6
wpa=2
wpa_passphrase=12345678
# wpa_key_mgmt=WPA-PSK
# Device Name
# User-friendly description of device; up to 32 octets encoded in UTF-8
device_name=RTL8821CU
# Model Name
# Model of the device (up to 32 ASCII characters)
model_name=RTW_SOFTAP
driver=nl80211
- 5G频段配置
sudo vim /etc/hostapd/rtl_hostapd_5G.conf
interface=wlan1
ctrl_interface=/var/run/hostapd
ssid=RK3399-UM1B-5G
channel=36
wpa=2
wpa_passphrase=12345678
# Device Name
# User-friendly description of device; up to 32 octets encoded in UTF-8
device_name=RTL8821CU
# Model Name
# Model of the device (up to 32 ASCII characters)
model_name=RTW_SOFTAP
driver=nl80211
- 启动hostapd和dhcpd
sudo ifconfig wlan1 up
sudo hostapd /etc/hostapd/rtl_hostapd_2G.conf -B
Configuration file: /etc/hostapd/rtl_hostapd_2G.conf
Using interface wlan1 with hwaddr 32:eb:1f:1f:3b:8f and ssid "RK3399-UM1B-2G"
wlan1: interface state UNINITIALIZED->ENABLED
wlan1: AP-ENABLED
#sudo hostapd /etc/hostapd/rtl_hostapd_5G.conf -B
sudo fconfig wlan1 192.168.2.1
sudo dhcpd -cf /etc/dhcp/dhcpd.conf wlan1
Internet Systems Consortium DHCP Server 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Config file: /etc/dhcp/dhcpd.conf
Database file: /var/lib/dhcp/dhcpd.leases
PID file: /var/run/dhcpd.pid
Wrote 1 leases to leases file.
Listening on LPF/wlan1/32:eb:1f:1f:3b:8f/192.168.2.0/24
Sending on LPF/wlan1/32:eb:1f:1f:3b:8f/192.168.2.0/24
Sending on Socket/fallback/fallback-net
$ iwconfig wlan1
wlan1 IEEE 802.11a ESSID:"RK3399-UM1B-2G" Nickname:"<WIFI@REALTEK>"
Mode:Master Frequency:5.785 GHz Access Point: 32:EB:1F:1F:3B:8F
Bit Rate:78 Mb/s Sensitivity:99/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=1/100 Signal level=-99 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
# 查看wlan1信息
sudo iw wlan1 info
Interface wlan1
ifindex 6
wdev 0x100000001
addr 32:eb:1f:1f:3b:8f
ssid RK3399-UM1B-2G
type AP
wiphy 1
txpower 12.00 dBm
此时用STA设备可以扫描到AP的SSID,输入密码能正常连接,但不能通过AP上网。
- 关闭AP热点
sudo killall dhcpd hostapd
4)设置桥接
sudo apt-get install bridge-utils