linux USB无线网卡(RTL8188EUS)驱动

Posted 九章_

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux USB无线网卡(RTL8188EUS)驱动相关的知识,希望对你有一定的参考价值。

驱动简介

RTL8188EUS, usb无线网卡驱动

源码 RTL8188EUS
在这里插入图片描述

Kconfig是文件WIFI驱动的配置界面文档,图形界面配置文件
内容如下:

menuconfig REALTEK_WIFI
	tristate "Realtek wifi"	

if REALTEK_WIFI

choice 
	prompt "select wifi type"
	default RTL8189FS

config RTL8189FS
	depends on REALTEK_WIFI
	tristate "rtl8189fs/ftv sdio wifi"

config RTL8188EUS
	depends on REALTEK_WIFI
	tristate "rtl8188eus usb wifi"	

config RTL8192CU
	depends on REALTEK_WIFI
	tristate "Realtek 8192C USB WiFi"

endchoice 
endif

删除内核自带的RTL8192CU驱动

内核自带的RTL8192CU驱动不稳定需要删除,内核源码中,drivers/net/wireless/rtlwifi/Kconfig 删除

config RTL8192CU
tristate "Realtek RTL8192CU/RTL8188CU USB Wireless Network Adapter"
depends on USB
select RTLWIFI
select RTLWIFI_USB

select RTL8192C_COMMON
---help---
This is the driver for Realtek RTL8192CU/RTL8188CU 802.11n USB
wireless network adapters.

If you choose to build it as a module, it will be called rtl8192cu

drivers/net/wireless/rtlwifi/Makefile

obj-$(CONFIG_RTL8192CU) += rtl8192cu/

添加源码驱动

  1. 拷贝源码文件到内核文件中

2)修改Kconfig文件
打开 drivers/net/wireless/Kconfig
添加

source "drivers/net/wireless/realtek/Kconfig"

这样WIFI驱动的配置界面才会出现在linux内核配置界面上

3)修改Makefile文件
打开 drivers/net/wireless/Makefile
添加

obj-y += realtek/

编译realtek中的程序。

配置linux内核

配置RTL8188驱动,先要配置USB,WIFI,802.11内核中的支持。

配置USB支持

-> Device Drivers 
	-> <*> USB support
		-> <*> Support for Host-side USB 
			-> <*> EHCI HCD (USB 2.0) support
			-> <*> OHCI HCD (USB 1.1) support 
			-> <*> ChipIdea Highspeed Dual Role Controller 
				-> [*] ChipIdea device controller
				-> [*] ChipIdea host controller

配置WIFI支持

-> Device Drivers 
	-> [*] Network device support 
		-> [*] Wireless LAN
			-> <*> IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP) 
				-> [*] Support downloading firmware images with Host AP driver
				-> [*] Support for non-volatile firmware download

配置IEEE 802.11支持

-> Networking support 
	-> -*- Wireless 
		 -> [*] cfg80211 wireless extensions compatibility 
		 -> <*> Generic IEEE 802.11 Networking Stack (mac80211) 

编译WIFI驱动
将rtl81xx编译为驱动模块

-> Device Drivers 
	-> Network device support (NETDEVICES [=y]) 
		 -> Wireless LAN (WLAN [=y]) 
			 -> Realtek wifi (REALTEK_WIFI [=m]) 
				 -> (M) select wifi type
				 -> (M) rtl8189fs/ftv sdio wifi 
				 -> (M) rtl8188eus usb wifi 
				 -> (M) Realtek 8192C USB WiFi 

执行编译命令

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j16

在 rtl8189FS,rtl8188EUS,rtl8192CU目录下有相应的.ko文件生成。并将.ko文件复制到开发版的目录/lib/modules/4.1.15中

驱动加载:

depmod
modprobe 8188cu.ko
modprobe 8192cu.ko
root@ATK-IMX6U:~# modprobe 8188eu
root@ATK-IMX6U:~# modprobe 8192cu
[  182.035128] usbcore: registered new interface driver rtl8192cu

查看网卡是否存在,一般是wlan0

ifconfig -a  
...
wlan0     Link encap:Ethernet  HWaddr 00:13:ef:f1:3d:54
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

如何上网,需要移植工具 wirless tools

wirless tools移植

源码包: iwlist_for_visteon-master.tar.bz2
解压后Makefile修改变量

## Compiler to use (modify this for cross compile).
CC = arm-linux-gnueabihf-gcc
## Other tools you need to modify for cross compile (static lib only).
AR = arm-linux-gnueabihf-ar
RANLIB = arm-linux-gnueabihf-ranlib
make clean
make

生成 iwlist、iwconfig、iwspy、iwpriv、ifrename 这 5 个工具,还有 libiw.so.29 这个库文件。

工具复制到/usr/bin 目录下,libiw.so.29复制到/usr/lib 目录下

工具测试:


root@ATK-IMX6U:~# iwlist
Usage: iwlist [interface] scanning [essid NNN] [last]
              [interface] frequency
              [interface] channel
              [interface] bitrate
              [interface] rate
              [interface] encryption
              [interface] keys
              [interface] power
              [interface] txpower
              [interface] retry
              [interface] ap
              [interface] accesspoints
              [interface] peers
              [interface] event
              [interface] auth
              [interface] wpakeys
              [interface] genie
              [interface] modulation

root@ATK-IMX6U:~# ifconfig wlan0 up
[  595.734197] ==> rtl8188e_iol_efuse_patch
[  596.192262] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
root@ATK-IMX6U:~# iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 0C:72:2C:FD:2E:BD
                    ESSID:"TP-LINK_2.4GHz_FD2EBD"
                    Protocol:IEEE 802.11bgn
                    Mode:Master
                    Frequency:2.437 GHz (Channel 6)
                    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
                    IE: Unknown: DD940050F204104A0001101044000102103B0001031047001019679A75CA6B508686663B369BF4B3E21021000754502D4C494E4B1023000A544C2D5744523735303010240003322E301042000A313233343536373839301054000800060050F20400011011001A576972656C65737320526F7574657220544C2D57445237353030100800022008103C0001031049000600372A000120
                    Quality=48/100  Signal level=74/100
                    Extra:fm=0003

扫描结果,热点名字:"TP-LINK_2.4GHz_FD2EBD"可以连接。连接需要使用wpa_supplicant工具。

wps_supplicant移植

openssl工具移植

源码 openssl-1.1.1d.tar.gz

tar -vxzf openssl-1.1.1d.tar.gz

在openssl文件夹下执行配置文件

./Configure linux-armv4 shared no-asm --prefix=/home/wy/imx6ull/tools/openssl CROSS_COMPILE=arm-linux-gnueabihf-

prefix:安装的目录

make 
make install

将/home/wy/imx6ull/tools/openssl/lib文件夹下的 libcrypto 和 libssl 库,拷贝到开发版/lib中

cp  libcrypto.so*  /lib/ -af
cp  libssl.so*  /lib/ -af

libnl库移植

源码 libnl-3.2.23.tar.gz
先安装 biosn 和 flex

sudo apt-get install bison
sudo apt-get install flex

源码文件libnl-3.2.23.tar.gz

tar -vxzf libnl-3.2.23.tar.gz

执行配置文件

./configure --host=arm-linux-gnueabihf --prefix=/home/wy/imx6ull/tools/libnl/

拷贝生成的/home/wy/imx6ull/tools/libnl/lib目录到开发版/usr/lib目录下

o cp lib/*  /usr/lib/ -rf

wpa_supplicant移植

源码 wpa_supplicant-2.7.tar.gz

tar -vxzf wpa_supplicant-2.7.tar.gz

进入解压后的文件,进入wpa_supplicant子文件夹
要将 wpa_supplicant 下的 defconfig 文件拷贝一份并重命名为.config并进入配置

#openssl库文件和头文件
CFLAGS += -I/home/wy/imx6ull/tools/openssl/include
LIBS += -L/home/wy/imx6ull/tools/openssl/lib -lssl -lcrypto
#libnl库文件和头文件
CFLAGS += -I/home/wy/imx6ull/tools/libnl/include/libnl3
LIBS += -L/home/wy/imx6ull/tools/libnl/lib

CC=arm-linux-gnueabihf-gcc

到出环境变量PKG_CONFIG_PATH

export PKG_CONFIG_PATH=/home/wy/imx6ull/tools/libnl/lib/pkgconfig

编译

make -j12

目录下会生成wpa-supplicantwpa_cli两个可执行文件,复制到开发版/usr/bin目录下

开发板下,查看wpa_supplicant 版本

root@ATK-IMX6U:~# wpa_supplicant -v
wpa_supplicant v2.7
Copyright (c) 2003-2018, Jouni Malinen <j@w1.fi> and contributors

在/etc目录下新建 “wpa_supplicant.conf”的配置文件,
设置网络名ssid,和密码psk

ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
network={
        ssid="TP-LINK_2.4GHz_FD2EBD"
        psk="15869151017"
}

创建一个新的目录

mkdir /var/run/wpa_supplicant -p

测试上网功能

wpa_supplicant -D wext -c /etc/wpa_supplicant.conf -i wlan0 &
[ 2065.431974] RTL871X: set bssid:00:00:00:00:00:00
ioctl[SIOCSIWAP]: Operation not p[ 2065.438524] RTL871X: set ssid [p▒>▒A▒▒g>~▒▒▒k▒▒8\\*▒;▒2▒<T▒▒\\▒▒▒▒펀▒] fw_state=0x00000008
ermitted
wlan0: CTRL-EVENT-DISCONNECTED bssid=0c:72:2c:fd:2e:bd reason=3 locally_generated=1
wlan0: CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid="TP-LINK_2.4GHz_FD2EBD" auth_failures=1 duration=10 reason=CONN_FAILED
ioctl[SIOCGIWSCAN]: Resource temporarily unavailable
ioctl[SIOCGIWSCAN]: Resource temporarily unavailable
[ 2066.770343] RTL871X: indicate disassoc
wlan0: CTRL-EVENT-SSID-REENABLED [ 2077.183469] RTL871X: set ssid [TP-LINK_2.4GHz_FD2EBD] fw_state=0x00000008
id=0 ssid="TP-LINK_2.4GHz_FD2EBD"[ 2077.192950] RTL871X: set bssid:0c:72:2c:fd:2e:bd

wlan0: Trying to associate with 0c:72:2c:fd:2e:bd (SSID='TP-LINK_2.4GHz_FD2EBD' freq=2437 MHz)
[ 2077.308041] RTL871X: start auth
[ 2077.313502] RTL871X: auth success, start assoc
[ 2077.328205] RTL871X: assoc success
[ 2077.331927] RTL871X: recv eapol packet
wlan0: Associated with 0c:72:2c:fd:2e:bd
[ 2077.349569] RTL871X: send eapol packet
[ 2077.357809] RsvdPageNum: 8
[ 2077.361396] RTL871X: recv eapol packet
[ 2077.367405] RTL871X: send eapol packet
wlan0: WPA: Key negotiation completed with 0c:72:2c:fd:2e:bd [PTK[ 2077.376877] RTL871X: set pairwise key camid:4, addr:0c:72:2c:fd:2e:bd, kid:0, type:AES
=CCMP GTK=CCMP]
wlan0: CTRL-EVENT-CONNECTED - Connection to 0c:72:2c:fd:2e:bd completed [id=0 id[ 2077.391572] RTL871X: set group key camid:5, addr:0c:72:2c:fd:2e:bd, kid:2, type:AES

需要几秒钟的时间,最终有 CTRL-EVENT-CONNECTED 连接状态

动态获取IP地址

udhcpc -i wlan0
root@ATK-IMX6U:~# udhcpc -i wlan0
udhcpc (v1.24.1) started
Sending discover...
Sending select for 192.168.11.107...
Lease of 192.168.11.107 obtained, lease time 7200
/etc/udhcpc.d/50default: Adding DNS 192.168.11.1

查看网卡信息

root@ATK-IMX6U:~# ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr 00:13:ef:f1:3d:54
          inet addr:192.168.11.107  Bcast:192.168.11.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:19703 errors:0 dropped:98 overruns:0 frame:0
          TX packets:19654 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1749865 (1.6 MiB)  TX bytes:952586 (930.2 KiB)

访问外网 ping


root@ATK-IMX6U:~# ping www.baidu.com
PING www.a.shifen.com (180.101.49.12) 56(84) bytes of data.
64 bytes from 180.101.49.12: icmp_seq=1 ttl=52 time=17.8 ms
64 bytes from 180.101.49.12: icmp_seq=2 ttl=52 time=25.5 ms
64 bytes from 180.101.49.12: icmp_seq=3 ttl=52 time=15.9 ms
64 bytes from 180.101.49.12: icmp_seq=4 ttl=52 time=26.0 ms
64 bytes from 180.101.49.12: icmp_seq=5 ttl=52 time=15.6 ms
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 15.641/20.195/26.008/4.633 ms

以上是关于linux USB无线网卡(RTL8188EUS)驱动的主要内容,如果未能解决你的问题,请参考以下文章

am335x system upgrade usb wifi rtl8188eus(十九)

linux(debian)安装USB无线网卡(tp-link TL-WN725N rtl8188eu )

ubuntu装配rtl8712,8188,8191,8192SU usb无线网卡的驱动怎么解决

i.MX6ULL驱动开发 | 29 - 使用USB WIFI网卡(RTL8188EU)

i.MX6ULL驱动开发 | 29 - 使用USB WIFI网卡(RTL8188EU)

树莓派怎么安装无线网卡rtl8188cus驱动