无线网卡(RTL8188EU)驱动编译、使用DHCP配置无线网络(1)
http://www.openloongson.org/forum.php?mod=viewthread&tid=220
(出处: 龙芯俱乐部开源社区)
1 驱动编译进入内核
内核主界面下进入:
(1
)
WIFI
设备支持配置及打开
CONFIG_WIRELESS_EXT=y CONFIG_WEXT_PRIV=y
Device Drivers --->
Network device support --->
WirelessLAN --->
--- WirelessLAN
<*> IEEE802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)
<*> Realtck 8188E/8188ETV USB WiFi
file:///Z:/TEMP/msohtmlclip1/01/clip_image002.jpg
(2
)Wifi
增加802.11
协议栈的支持
Networking support --->
-*- Wireless --->
选中
<*> cfg80211 - wireless configuration API
file:///Z:/TEMP/msohtmlclip1/01/clip_image004.jpg
(3) USB 支持WIFI 的配置
USB 支持WIFI 的配置选项位于Device Drivers >USB support 配置菜单下USB Wireless
DeviceManagement support。
file:///Z:/TEMP/msohtmlclip1/01/clip_image006.jpg
(4
)
用户空间的mdev
和firmware
支持配置
进入Device Driver > Generic Driver Options
配置菜单,按照下图所示配置用户空间的mdev
和firmware
支持
file:///Z:/TEMP/msohtmlclip1/01/clip_image008.jpg
内核RAWsocket
支持宏 CONFIG_PACKET=y
编译好的内核下载到开发板后,用命令lsusb,
查看无线网卡的USB ID
号可看到:
[root@Loongson:/]#PHY: 0:13 - Link is Up - 100/Full
lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0001
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 0bda:8179
[root@Loongson:/]#
硬件
id
为
0bda:8179
的即为无线网卡。
2 下载wifitools.tar.gz使用
从网站http://www.linuxfromscratch.org/blfs/view/svn/basicnet/wireless_tools.html
下载wireless_tools.29.tar.gz
#tar xvfj wireless_tools.29.tar.bz2
#cd wireless_tools.29
Makefile
修改
CC= mipsel-linux-gcc
AR = mipsel-linux-ar
RANLIB = mipsel-linux-ranlib
运行make
#make
复制文件到开发板iwpriv,iwconfig
、iwlist, iwevent, iwspy, iwgetid, ifrename,libiw.so.29
。
解压,将wireless-tools
文件夹内除了libiw.so.29
外复制进/bin
文件夹内,将libiw.so.29
复制进/lib
文件夹,将wpa_supplicant
文件夹内所有文件也复制进/bin
内
。
使用命令chmod u+x ***修改以上文件权限。
出现以下信息,其中设备名为wlan0
的网卡设备即是驱动识别出来的无线网卡,驱动程序安装成功。
[root@Loongson:/]# #iwconfig wlan0
RTL871X: rtw_wx_get_rts, rts_thresh=2347
RTL871X: rtw_wx_get_frag, frag_len=2346
wlan0 unassociated Nickname:"<WIFI@REALTEK>"
Mode:Auto Frequency=2.412GHz Access Point: Not-Associated
Sensitivity:0/0
Retry
ff RTS thr
ff Fragment thr
ff
![](http://www.openloongson.org/static/image/smiley/default/shocked.gif)
![](http://www.openloongson.org/static/image/smiley/default/shocked.gif)
![](http://www.openloongson.org/static/image/smiley/default/shocked.gif)
Encryption key
ff
![](http://www.openloongson.org/static/image/smiley/default/shocked.gif)
Power Management
ff
![](http://www.openloongson.org/static/image/smiley/default/shocked.gif)
Link Quality:0 Signal level:0 Noise level:0
Rxinvalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Txexcessive retries:0 Invalid misc:0 Missed beacon:0
查看wifi信号强度,速度,频段等信息用的 iwconfig iwlist 程序
5 安装wpa_supplicant 以下在虚拟机上编译。 (1) 首先安装支持库 libnl 在http://www.openssl.org/source/下载最新源码libnl-1.1.tar.gz 解压后,配置安装信息: 执行./configure -prefix=/usr/local/arm/libnl1.1,配置libnl安装路径 执行make CC= mipsel -linux-gcc,完成编译, 执行make install,将libnl库安装至/usr/local/arm/libnl1.1路径下,生成二个目录include lib,在lib中得到libnl库:libnl.so等文件。 将/usr/local/arm/libnl1.1/lib下所有文件拷贝至开发板的/lib目录下,确保hostapd在开发板上运行,能够正确找到libnl库的位置。 (2)安装支持库libopenssl 在http://www.openssl.org/source/下载最新源码openssl-1.0.1c.tar.gz 解压后, 配置安装信息: ./config no-asm shared --prefix=/usr/local/arm/openssl/openssl-install --cross-compile-prefix=/opt/gcc-4.3-ls232/bin/mipsel-linux- no-asm意思是关于汇编的模块部进行编译,因为部分汇编会报错 shared 意思是编译成动态链接库 --prefix=/usr/local/arm/openssl/openssl-install意思是 指定make install的安装路径 --cross-compile-prefix=/opt/gcc-4.3-ls232/bin/mipsel-linux-指定交叉编译工具链路径 然后运行 make make install 在/usr/local/arm/openssl/openssl-install 下生成四个目录bin include lib ssl,在lib中得到libopenssl库:libcrypto.so等文件。 (3)编译wpa_supplicant 在http://wireless.kernel.org/en/users/Documentation/wpa_supplicant下载最新源码wpa_supplicant-2.2.tar.gz 解压后,拷备配置文件 cp defconfig .config 修改.config加上一行: CONFIG_LIBNL32=y 目的是:Use libnl 3.2 libraries (if this is selected, CONFIG_LIBNL20 is ignored) 并添加: CFLAGS += -I/usr/local/arm/openssl/openssl-install/include/ CFLAGS += -I/usr/local/arm/libnl1.1/include/ LDFLAGS += -I/usr/local/arm/openssl/openssl-install/include/ LDFLAGS += -I/usr/local/arm/libnl1.1/include/ LIBS += -L/usr/local/arm/openssl/openssl-install/lib LIBS += -L/usr/local/arm/libnl1.1/lib 修改Makefile: CC = mipsel-linux-gcc Make后出现错误:cannot find -lcryptocollect2: ld returned 1 exit statusMakefile:1622: recipe for target 'wpa_passphrase' failed , 提示找不到lib。 修改Makefile: CC = mipsel-linux-gcc -L/usr/local/arm/openssl/openssl-install/lib -L参数跟着的是库文件所在的目录名, 把所有目标文件链接成可执行文件。 库文件中,分为两大类分别是动态链接库(通常以.so结尾)和静态链接库(通常以.a结尾),二者的区别仅在于程序执行时所需的代码是在运行时动态加载的,还是在编译时静态加载的。 静态库链接时搜索路径顺序: 1. ld会去找GCC命令中的参数-L 2. 再找gcc的环境变量LIBRARY_PATH 3. 再找内定目录 /lib /usr/lib /usr/local/lib 这是当初compile gcc时写在程序内的 动态链接时、执行时搜索路径顺序: 1. 编译目标代码时指定的动态库搜索路径 2. 环境变量LD_LIBRARY_PATH指定的动态库搜索路径 3. 配置文件/etc/ld.so.conf中指定的动态库搜索路径 4. 默认的动态库搜索路径/lib 5. 默认的动态库搜索路径/usr/lib 有关环境变量: LIBRARY_PATH环境变量:指定程序静态链接库文件搜索路径 LD_LIBRARY_PATH环境变量:指定程序动态链接库文件搜索路径 |
3 建立连接 Wireless-tools(支持很多无线网卡,仅能访问WEP加密AP) 启动无线网卡:ifconfig wlan0 up 192.168.1.123,配置无线网卡IP地址。 [root@Loongson:/]#ifconfig wlan0 up 192.168.1.123 RTL871X: +871x_drv - drv_open, bup=0 RTL871X: rtl8188e_FirmwareDownload: fw_ver=11 fw_subver=1 sig=0x88e1 RTL871X: rtl8188e_FirmwareDownload writeFW_retry:0, time after fwdl_start_time:56ms RTL871X: _FWFreeToGo: Checksum report OK! REG_MCUFWDL:0x00030004 RTL871X: =====> _8051Reset88E(): 8051 reset success . RTL871X: _FWFreeToGo: Polling FW ready success!! REG_MCUFWDL:0x000300c6 ==> rtl8188e_iol_efuse_patch RTL871X: pDM_Odm TxPowerTrackControl = 1 RTL871X: rtl8188eu_hal_init in 1048ms RTL871X: MAC Address = 00:0b:81:96:76:24 RTL871X: -871x_drv - drv_open, bup=13. 扫描AP(假设为MYESSID):iwlist wlan0 scanning 扫描无线网络:iwlist wlan0 scanning [root@Loongson:/]#iwlist wlan0 scanning RTL871X: survey done event(2d) RTL871X: rtw_wx_get_scan: Njtech RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: sundm RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: Njtech RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: CMCC-EDU RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: Njtech RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: newstart RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: 602 RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: CMCC-EDU RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: FTTBEST RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: Njtech RTL871X: rtw_wx_get_scan: ssid = 0 RTL871X: rtw_wx_get_scan: Njtech RTL871X: rtw_wx_get_scan: ssid = 0 wlan0 Scan completed : Cell 01 - Address: 0A:69:6C:2F:AC:C1 ESSID:"Njtech" Protocol:IEEE 802.11bgn Mode:Master Frequency:2.412 GHz (Channel 1) Encryption key ![]() Bit Rates:144 Mb/s Quality=0/100 Signal level=44/100 Extra:fm=0001 Cell 02 - Address: E0:06:E6:C8:6C:9D ESSID:"sundm" Protocol:IEEE 802.11bgn Mode:Master Frequency:2.437 GHz (Channel 6) Encryption key ![]() Bit Rates:72 Mb/s Extra:rsn_ie=30140100000fac040100000fac040100000fac020000 IE: IEEE 802.11i/WPA2 Version 1 Group Cipher : CCMP Pairwise Ciphers (1) : CCMP Authentication Suites (1) : PSK Quality=0/100 Signal level=84/100 Extra:fm=0003 至此,已经检测出能够成功加载驱动。 4 使用wpa_supplicant连接无线网络 修改wpa_supplicant文件夹中的wpa_supplicant.conf内容为: network={ ssid=”your wireless” Psk=”your password” } network={ ssid="*******" # your wireless psk="*****" # your password priority=1 #设置优先级 key_mgmt=WPA-PSK #加密类型 } 通过wpa_supplicant的配置文件来实现连接。 将文件wpa_supplicant.conf传入开发板的bin文件夹: 在开发板上运行以下命令: ifconfig eth0 down //关闭有线网络 ifconfig wlan0 up 192.168.1.123 //打开无线网络 配置无线网络IP地址 wpa_supplicant -d -Dwext -iwlan0 -c/bin/wpa_supplicant.conf & //后台运行 wpa_supplicant程序,以支持WEP,WPA/WPA2和WAPI无线协议和加密认证 这里的& 表示在后台运行。-d增加调试信息输出。-i所需要配置的网口名称。-Dwext指使用的驱动。 -c指定配置文件。 wpa可执行文件和配置文件命令格式: wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] [-g<global ctrl>] \ -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \ [-b<br_ifname>] [-f<debug file>] \ [-o<override driver>] [-O<override ctrl>] \ [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \ [-p<driver_param>] [-b<br_ifname>] ...] 驱动(一般常使用的就是wext): wext = Linux wireless extensions (generic) hostap = Host AP driver (Intersil Prism2/2.5/3) atmel = ATMEL AT76C5XXx (USB, PCMCIA) wired = Wired Ethernet driver 各个选项及其含义: -b = optional bridge interface name 增加网桥名称 -B = run daemon in the background 后台执行 -c = Configuration file 附加配置文件,即根据配置文件执行操作 -C = ctrl_interface parameter (only used if -c is not) 控制网口参数 -i = interface name 网口名称 -d = increase debugging verbosity (-dd even more) 增加调试信息输出 -D = driver name (can be multiple drivers: nl80211,wext) 驱动名称 -g = global ctrl_interface 全局网口配置 -K = include keys (passwords, etc.) in debug output 在debug输出中包含keys -t = include timestamp in debug messages 将各个debug信息前输出时间标签 -h = show this help text 显示帮助信息 -L = show license (GPL and BSD) 显示license -o = override driver parameter for new interfaces 覆盖driver参数 -O = override ctrl_interface parameter for new interfaces 覆盖ctrl_interface参数 -p = driver parameters 携带驱动参数 -P = PID file 进程文件 -q = decrease debugging verbosity (-qq even less) 在debug中不输出指定参数 -v = show version 显示版本信息 -W = wait for a control interface monitor before starting 启动前等待控制接口 -N = start describing new interface 启动对新接口的描述 4 命令举例: wpa_supplicant -d -Dwext -i wlan0 -c /data/misc/wifi/wpa_supplicant.conf -t -d /data/misc/wifi/log.txt 使用linux通用驱动,网络接口为wlan0,读取文件为/data/misc/wifi/wpa_supplicant.conf, 输出带时间戳的调试信息到/data/misc/wifi/log.txt中,执行无线配置 运行命令后,产生错误: ioctl[SIOCSIWAP]: Operation not permitted WEXT: Failed to set bogus BSSID/SSID to disconnect 分析后,问题在于网友提供的wpa_supplicant有问题,于是重新编译wpa_supplicant。 |
6 继续使用wpa_supplicant连接无线网络 编译结束后,在当前目录下生成三个文件:wpa_supplicant 、wpa_passphrase、wpa_cli。拷备到开发板,运行wpa_supplicant。将这三个文件传入开发板/usr/bin下,运行wpa_supplicant,启动wpa_supplicant守护进程。以下显示调试信息。 [root@Loongson:/]#wpa_supplicant -d -Dwext -iwlan0 -c/bin/wpa_supplicant.conf & [root@Loongson:/]#wpa_supplicant v2.2 random: Trying to read entropy from /dev/random Successfully initialized wpa_supplicant Initializing interface 'wlan0' conf '/bin/wpa_supplicant.conf' driver 'wext' ctr l_interface 'N/A' bridge 'N/A' Configuration file '/bin/wpa_supplicant.conf' -> '/bin/wpa_supplicant.conf' Reading configuration file '/bin/wpa_supplicant.conf' eapol_version=1 ap_scan=1 fast_reauth=1 Priority group 1 id=0 ssid='sundm75_502' RTL871X: [rtw_wx_set_pmkid] IW_PMKSA_FLUSH! rfkill: Cannot oRTL871X: set_mode = IW_MODE_INFRA pen RFKILL control device WEXT:RTL871X: hw_var_set_opmode()-3378 mode = 2 RFKILL status nRTL871X: set bssid:00:00:00:00:00:00 ot available SIOCGIWRANGE: WE(compiled)=22 WE(sRTL871X: =>rtw_wx_set_essid ource)=16 enc_caRTL871X: ssid=g▒isQ▒J▒)ͺ▒▒▒▒F|▒T▒▒vZ.c3▒ɚ, len=32 pa=0xf capabiRTL871X: set ssid [g▒isQ▒J▒)ͺ▒▒▒▒F|▒T▒▒vZ.c3▒ɚ] fw_state=0x00000008 lities: key_mgmtRTL871X: Set SSID under fw_state=0x00000008 0xf enc 0x1f flRTL871X: <=rtw_wx_set_essid, ret 0 ags 0x0 ioctl[SIOCSIWAP]: Operation not permitted WEXT: Failed to clear BSSID selection on disconnect netlink: Operstate: ifindex=3 linkmode=1 (userspRTL871X: [rtw_wx_set_pmkid] IW_P MKSA_FLUSH! ace-control), operstate=5 (IF_OPER_DORMANT) Add interface wlan0 to a new radio N/A wlan0: Own MAC address: 00:0b:81:96:76:24 wpa_driver_wext_set_key: alg=0 key_idx=0 set_tx=0 seq_len=0 key_len=0 wpa_driver_wext_set_key: alg=0 key_idx=1 set_tx=0 seq_len=0 key_len=0 wpa_driver_wext_set_key: alg=0 key_idx=2 set_tx=0 seq_len=0 key_len=0 wpa_driver_wext_set_key: alg=0 key_idx=3 set_tx=0 seq_len=0 key_len=0 wpa_driver_wext_set_countermeasures wlan0: RSN: flushing PMKID list in the driver wlan0: Setting scan request: 0.100000 sec EAPOL: SUPP_PAE entering state DISCONNECTED EAPOL: Supplicant port status: Unauthorized EAPOL: KEY_RX entering state NO_KEY_RECEIVE EAPOL: SUPP_BE entering state INITIALIZE EAP: EAP entering state DISABLED wlan0: Added interface wlan0 wlan0: State: DISCONNECTED -> DISCONNECTED wpa_driver_wext_set_operstate: operstate 0->0 (DORMANT) ……………… RSN: received GTK in pairwise handshake - hexdump(len=18): [REMOVED] WPA: Group Key - hexdump(len=16): [REMOVED] wlan0: WPA: Installing GTK to the driver (keyidx=2 tx=0 len=16) WPA: RSC - hexdump(len=6): d3 0e 00 00 00 00 wpa_driver_wext_set_key: alg=3 key_idx=2 set_tx=0 seq_len=6 key_len=16 wlan0: WPA: Key negotiation completed with 08:57:00:7c:fd:90 [PTK=CCMP GTK=CCMP] wlan0: Cancelling authentication timeout wlan0: State: GROUP_HANDSHAKE -> COMPLETED wlan0: Radio work 'connect'@0x58e400 done in 0.916960 seconds wlan0: CTRL-EVENT-CONNECTED - Connection to 08:57:00:7c:fd:90 completed [id=0 id_str=] wpa_driver_wext_set_operstate: operstate 0->1 (UP) netlink: Operstate: ifindex=3 linkmode=-1 (no change), operstate=6 (IF_OPER_UP) EAPOL: External notification - portValid=1 EAPOL: External notification - EAP success=1 EAPOL: SUPP_PAE entering state AUTHENTICATING EAPOL: SUPP_BE entering state SUCCESS EAP: EAP entering state DISABLED EAPOL: SUPP_PAE entering state AUTHENTICATED EAPOL: Supplicant port status: Authorized EAPOL: SUPP_BE entering state IDLE EAPOL authentication completed - result=SUCCESS RTM_NEWLINK: operstate=1 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP]) RTM_NEWLINK, IFLA_IFNAME: Interface 'wlan0' added WEXT: if_removed already cleared - ignore event EAPOL: startWhen --> 0 EAPOL: disable timer tick 以上CTRL-EVENT-CONNECTED说明,授权完成,联网进入路由器成功。 关闭eth0,否则会默认使用eth0来连接网络。添加网关,否则无法连通网络。 # ifconfig eth0 down Ignore event for foreign ifindex 2 # route add default gw 192.168.1.253 #route add default netmask 255.255.255.0 # ping www.baidu.com 记住:当出现『SIOCADDRT: Network is unreachable』这个错误时,肯定是由于 gw 后面接的IP无法直接网域沟通 (Gateway 并不在你的网域内),需要检查一下是否输入错误。 在移植无线网卡的过程中出现这个错误,原因是路由器的无线网加密方式为wpa,所以需要移植wpa_supplicant工具.如果不移植wpa_supplicant,可以设置路由器的加密方式为wep,密钥设置为64位,如设置为128位会报错。 总结,开机后,开启无线网卡并配置的命令: #ifconfig eth0 down #wpa_supplicant -d -Dwext -iwlan0 -c/bin/wpa_supplicant.conf & #ifconfig wlan0 192.168.1.111 #route add default gw 192.168.1.1 #ping 221.226.0.186 |
首先在内核和根文件系统的配置中打开DHCP。
(1)配置Linux内核使能DHCP相关选项:
[*]Networking support -->
Networking support
Networking options -->
[*] Packet socket
[*] IP:kernel level autoconfiguration
[*] IP
![](http://www.openloongson.org/static/image/smiley/default/biggrin.gif)
[*] Network packet filtering framework(Netfilter) --> //下层子选项可不作配置
重新编译并下载进开发板。
(2)配置Busybox,使能以下选项:
Networking Utilities -->
[*]udhcp server (udhcpd)
[*] dhcprelay
[*] Lease display utility (dumpleases)
[*] Rewrite the lease file at every new acknowledge
[*]udhcp client (udhcpc)
[*] Verify that the offered address is free,using ARP ping
[*] Do not pass malformed host and domain names
重新编译并下载进开发板。
(3) 运行命令udhcpc
[root@Loongson:/]#udhcpc -i wlan0
udhcpc (v1.22.1) started
Sending discover...
Sending select for 192.168.1.111...
Lease of 192.168.1.111 obtained, lease time 7200
[root@Loongson:/]#
以上只是自动获得了IP地址,并没有配置到网卡上。
需要把/busybox-1.23.0/examples/udhcp下的脚本simple.script改名为default.script,放在开发板上的/usr/share/dhcpc/目录下,且用命令#chmod +x usr/share/udhcpc/default.script 增加该文件的执行权限,才能将获取的IP写到指定的网卡中。
[root@Loongson:/]#chmod +x usr/share/udhcpc/default.script
[root@Loongson:/]#udhcpc -i wlan0
udhcpc (v1.22.1) started
Setting IP address 0.0.0.0 on wlan0
Sending discover...
Sending discover...
Sending select for 192.168.1.101...
Lease of 192.168.1.101 obtained, lease time 7200
Setting IP address 192.168.1.101 on wlan0
Deleting routers
route: SIOCDELRT: No such process
Adding router 192.168.1.253
Recreating /etc/resolv.conf
Adding DNS server 192.168.1.253
以上内容为DHCP配置IP地址为192.168.1.101,路由为192.168.1.253,DNS 为192.168.1.253。
现在可ping 通网关。
[root@Loongson:/]#ping 192.168.1.253
PING 192.168.1.253 (192.168.1.253): 56 data bytes
64 bytes from 192.168.1.253: seq=0 ttl=64 time=5.932 ms
64 bytes from 192.168.1.253: seq=1 ttl=64 time=2.230 ms
8 DHCP配置成开机启动
建立一个脚本文件wifiup,开机后自动执行。
#!/bin/sh
#Set ip
ifconfig eth0 down
ifconfig wlan0 up
sleep 2s
wpa_supplicant -Dwext -iwlan0 -c/bin/wpa_supplicant.conf &
sleep 5s
udhcpc -i wlan0