无线网卡(RTL8188EU)驱动编译、使用DHCP配置无线网络(1

匿名 (未验证) 提交于 2019-12-03 00:40:02


无线网卡(RTL8188EU)驱动编译、使用DHCP配置无线网络(1)
http://www.openloongson.org/forum.php?mod=viewthread&tid=220
(出处: 龙芯俱乐部开源社区)

1

file:///Z:/TEMP/msohtmlclip1/01/clip_image002.jpg
2Wifi
Networking support --->
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
file:///Z:/TEMP/msohtmlclip1/01/clip_image008.jpg
RAWsocket

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
wifitools.tar.gz
1编译wireless_tools
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,iwconfigiwlist, iwevent, iwspy, iwgetid, ifrename,libiw.so.29
wireless-toolslibiw.so.29/binlibiw.so.29/libwpa_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

ff

ff

ff
查看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安装路径


将/usr/local/arm/libnl1.1/lib下所有文件拷贝至开发板的/lib目录下,确保hostapd在开发板上运行,能够正确找到libnl库的位置。
(2)安装支持库libopenssl
http://www.openssl.org/source/下载最新源码openssl-1.0.1c.tar.gz
解压后,
配置安装信息:

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/


LIBS += -L/usr/local/arm/openssl/openssl-install/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

扫描无线网络:iwlist wlan0 scanning
[root@Loongson:/]#iwlist wlan0 scanning
RTL871X: survey done event(2d)






ff








n








至此,已经检测出能够成功加载驱动。
4 使用wpa_supplicant连接无线网络
修改wpa_supplicant文件夹中的wpa_supplicant.conf内容为:
network={
ssid=”your wireless”
Psk=”your password”
}
network={




}
通过wpa_supplicant的配置文件来实现连接。
将文件wpa_supplicant.conf传入开发板的bin文件夹:
在开发板上运行以下命令:


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>] \





驱动(一般常使用的就是wext):




各个选项及其含义:








































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

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

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

pa=0xf

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

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
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
7 配置DHCP
首先在内核和根文件系统的配置中打开DHCP。
(1)配置Linux内核使能DHCP相关选项:
[*]Networking support -->
Networking support
Networking options -->


HCP support


重新编译并下载进开发板。


Networking Utilities -->
[*]udhcp server (udhcpd)



[*]udhcp client (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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!