因为现在的无线wifi网络大多是wpa加密。所以需要移植wpa_supplicant工具。
一、下载源码
下载wpa_supplicant-0.7.3.tar.gz (openssl用到0.7.3提供的补丁)
#tar xvfz wpa_supplicant-0.7.3.tar.gz
下载
#tar zxvf openssl-0.9.8e.tar.gz
二、编译openssl库
将wpa_supplicant中的补丁拷贝到openssl中
# cp wpa_supplicant-0.7.3/patches/openssl-0.9.8e-tls-extensions.patch openssl-0.9.8e/
#cd openssl-0.9.8e
#mkdir /usr/local/ssl
#vim Makefile
CC= arm-linux-gnu-gcc
AR= arm-linux-gnu-ar $(ARFLAGS) r
RANLIB= arm-linux-gnu-ranlib
INSTALLTOP=/usr/local/ssl
OPENSSLDIR=/usr/local/ssl
#make
#make install
在/usr/local/ssl目录下安装了ssl库
#ls /usr/local/ssl
#bin certs include lib man misc openssl.cnf private
后面编译wpa_supplicant要依赖openssl中的lib和include
三、编译wpa_supplicant
进入wpa_supplicant-0.7.3.tar.gz解压生成的wpa_supplicant-0.7.3/wpa_supplicant目录中:
#cp defconfig .config
#vim .config
CC= arm-linux-gnu-gcc -L/usr/local/ssl/lib/
CFLAGS += -I/usr/local/ssl/include/
LIBS += -L/usr/local/ssl/lib/
#make
经过编译后的wpa_supplicant源程序可以看到两个主要的可执行工具:wpa_supplicant和wpa_cli。wpa_supplicant是核心程序,它和wpa_cli的关系就是服务和客户端的关系:后台运行wpa_supplicant,使用wpa_cli来搜索、设置、和连接网络。
四、配置wpa_supplicant
(1)首先拷贝wpa_supplicant和wpa-psk-tkip.conf到开发板根文件系统中,并改名wpa-psk-tkip.conf为wpa_supplicant.conf
#cp wpa_supplicant /rootfs/filesystem/bin
#cp wpa_supplicant-0.7.3/wpa_supplicant/examples/wpa-psk-tkip.conf /rootfs/filesystem/etc/wpa_supplicant.conf
(2)修改wpa_supplicant.conf配置文件
#vim /rootfs/filesystem/etc/wpa_supplicant.conf
修改内容如下:
# WPA-PSK/TKIP
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="FS2410" //填写无线网络的的用户名
key_mgmt=WPA-PSK
proto=WPA
pairwise=TKIP
group=TKIP
psk="1234567890" //填写密码
}
五、测试
(1)在开发板终端:
#mkdir –p /var/run/wpa_supplicant
(2)编写驱动加载脚本
#vim load.sh (我放在根文件系统/sdio目录中,内容如下:)
#!/bin/sh
cd /sdio
insmod libertas.ko
insmod libertas_sdio.ko helper_name=/lib/firmware/mrvl/helper_sd.bin fw_name=/lib/firmware/mrvl/sd8686.bin
并修改load.sh权限:chmod 777 load.sh
(3)加载驱动
在开发板终端进入/sdio目录,执行./load.sh加载驱动
#cd /sdio
#./load.sh
驱动加载完成会提示:(如果没有,则再次热插拔你的sdio wifi卡便可以看到)
libertas_sdio: Libertas SDIO driver
libertas_sdio: Copyright Pierre Ossman
libertas: 00:0b:6c:89:62:4b, fw 9.70.3p23, cap 0x00000303
libertas: unidentified region code; using the default (USA)
libertas: wlan0: Marvell WLAN 802.11 adapter
ifconfig -a查看是否创建wlan0这个节点。
分配IP地址:
#ifconfig wlan0 192.168.1.5 //也可以动态分配 dhclient wlan0 不过你得移植dhcp
(4)创建连接暗文密码(PSK密码),通过明码转换
#cd /etc
#wpa_passphrase FS2410 1234567890 >> wpa_supplicant.conf
此时将在wpa_supplicant.conf文件中生成:
network={
ssid="FS2410"
#psk="1234567890"
psk=4b2bc7cbb3710e9ea43f09e8d57e8bdb3b2a2127af44960d73216c3612f6baba
}
(5)然后修改wpa_supplicant.conf配置文件,把 psk="1234567890" 这一行明文密码改成生成的暗文密码,即:
psk=4b2bc7cbb3710e9ea43f09e8d57e8bdb3b2a2127af44960d73216c3612f6baba
其它生成的多余信息删除,最后wpa_supplicant.conf文件如下:
# WPA-PSK/TKIP
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="FS2410" //填写无线网络的的用户名
key_mgmt=WPA-PSK
proto=WPA
pairwise=TKIP
group=TKIP
psk=4b2bc7cbb3710e9ea43f09e8d57e8bdb3b2a2127af44960d73216c3612f6baba
}
(6)连接AP
在开发板终端输入wpa_supplicant回车,会显示帮助信息,最后有个:
example:
wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
拷贝example用法,执行:
# wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf &(需要一直放在后台运行)
打印信息有:
Trying to associate with 00:26:f2:0d:5a:c4 (SSID='FS2410' freq=2412 MHz)
Associated with 00:23:68:28:4e:a8
CTRL-EVENT-DISCONNECTED bssid=00:23:68:28:4e:a8 reason=0
Associated with 00:26:f2:0d:5a:c4
WPA: Key negotiation completed with 00:26:f2:0d:5a:c4 [PTK=TKIP GTK=TKIP]
CTRL-EVENT-CONNECTED - Connection to 00:26:f2:0d:5a:c4 completed (auth) [id=0 id_str=]
……
再ping下网关,是否连接成功:
#ping 192.168.1.1
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 17.627/20.023/24.631 ms
……
无线网卡连接成功!