linux_Wifi模块移植——station模式
作者:杨正 QQ:1209758756yz2012ww@gmail.com>2013.7.13 前言wpa_supplicant本是开源项目源码,被谷歌修改后加入android移动平台,它主要是用来支持WEP,WPA/WAP2和WAPI无线协议和加密认证的,而实际上的工作内容是通过socket(不管是wpa_supplicant与上层还是wpa_supplicant与驱动都采用sock
作者:杨正 QQ:1209758756<yz2012ww@gmail.com>2013.7.13
前言
wpa_supplicant本是开源项目源码,被谷歌修改后加入android移动平台,它主要是用来支持WEP,WPA/WAP2和WAPI无线协议和加密认证的,而实际上的工作内容是通过socket(不管是wpa_supplicant与上层还是wpa_supplicant与驱动都采用socket通讯)与驱动交互上数据报给用户,而用户可以通过socket发送命令给wpa_supplicant调用驱动来对wifi芯片操作。简单的说,wpa_supplicant就是wifi驱动和用户的中转站外加对协议和加密认证的支持。
移植
从Linux-3.0开始,RT2070/3070的STA驱动已经作为正式版本加入了Linux内核源码中了(从Linux-2.6.32开始以实验版本加入Linux内核中)。本篇文章主要介绍如何在内核中编译支持RT3070的STA驱动,并连接到我的无线路由器上去。
1、配置linux内核支持RT3070,我们以build-in(内置)的方式将RT3070的驱动集成到linux内核里面去:
[lingyun@localhostyangzheng]$ cd linux-3.0
[lingyun@localhostlinux-3.0]$ vt100
[lingyun@localhostlinux-3.0]$ make menuconig
[*] Networking support --->
-*- Wireless --->
<*> cfg80211 - wireless configuration API
[ ] nl80211 testmode command
[ ] enable developer warnings
[ ] cfg80211 regulatory debugging
[*] enable powersave by default
[ ] use statically compiled regulatory rulesdatabase
[ ] cfg80211 wireless extensions compatibility
<*> Common routines for IEEE802.11 drivers
[ ] lib80211 debugging messages
<*> Generic IEEE 802.11 Networking Stack(mac80211)
[ ] PID controller based rate control algorithm
[*] Minstrel
[*] Minstrel 802.11n support
Default rate controlalgorithm (Minstrel) --->
[ ] Enable mac80211 mesh networking(pre-802.11s) support
[ ] Select mac80211 debugging features --->
Device Drivers --->
Generic Driver Options --->
(/sbin/hotplug) path to ueventhelper
[ ] Maintain a devtmpfsfilesystem to mount at /dev
[ ] Select only drivers thatdon't need compile-time external firmware
[ ] Prevent firmware from beingbuilt
-*- Userspace firmware loadingsupport
[*] Include in-kernel firmware blobs in kernelbinary
() External firmware blobs to build into thekernel binary
[*] Network device support --->
[*] Wireless LAN --->
<*> Ralink driversupport --->
--- Ralink driver support
< > Ralink rt2500 (USB) support
< > Ralink rt2501/rt73 (USB) support
<*> Ralink rt27xx/rt28xx/rt30xx (USB) support
[ ] rt2800usb - Include support for rt33xxdevices
[ ] rt2800usb - Include support for rt35xxdevices (EXPERIMENTAL)
[ ] rt2800usb - Include support for rt53xx devices(EXPERIMENTAL)
[ ] rt2800usb - Include support for unknown(USB) devices
[*] Ralink debug output
注:此过程默认linux内核已经能在开发板上跑了,这里只是添加对RT3070的支持。
2、重新编译内核,下载到开发板上,插入RT3070的无线网卡并启动内核:
……
usb 1-1.2: newfull speed USB device number 3 using s3c2410-ohci
usb 1-1.2: New USBdevice found, idVendor=148f,idProduct=3070
usb 1-1.2: New USBdevice strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.2:Product: 802.11 n WLAN
usb 1-1.2:Manufacturer: Ralink
usb 1-1.2:SerialNumber: 1.0
phy0 ->rt2x00_set_chip: Info - Chipset detected - rt: 3070, rf: 0005, rev: 0201.
dm9000 dm9000.0:eth0: link down
Copyright (C) 2013yangzheng<yz2012ww@gmail.com>
root login: root
>: lsusb
Bus 001 Device001: ID 1d6b:0001
Bus 001 Device002: ID 05e3:0606
Bus 001Device 003: ID 148f:3070 //RT3070的厂商ID和设备ID
>: ifconfigwlan0 up
phy0 -> rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'.
phy0 -> rt2x00lib_request_firmware:Error - Failed to request Firmware.
ifconfig: SIOCSIFFLAGS: No such file ordirectory
这时我们在使用RT3070的驱动时发现,R3070的驱动还需要rt2870.bin这个系统固件(firmware)。
3、linux官方网站下载rt2870.bin这个系统固件:
1)、在pc上下载rt2870.bin这个系统固件:
[lingyun@localhostlinux-3.0]$ git clonegit://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git
注:git 命令的讲解:http://blog.csdn.net/hudashi/article/details/7664396
2)、把rt2870.bin这个系统固件下载到开发板的/lib/filmware下,再重启网卡:
>: mkdir-p /lib/firmware
>: cdlib/firmware/
>: tftp -grrt2870.bin 192.168.1.3
>: ifconfigwlan0 up
phy0 -> rt2x00lib_request_firmware:Info - Loading firmware file 'rt2870.bin'.
phy0 ->rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 3, CWmax: 4, Aifs: 2,TXop: 102.
phy0 -> rt2x00mac_conf_tx:Info - Configured TX queue 1 - CWmin: 4, CWmax: 5, Aifs: 2, TXop: 188.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 5, CWmax: 10, Aifs: 3,TXop: 0.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 5, CWmax: 10, Aifs: 7,TXop: 0.
4、wireless_tools和wpa_supplicant的交叉编译及移植:
1)、编译wireless_tools
[lingyun@localhostwireless]$ wget http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz
[lingyun@localhostwireless]$ tar -zxfwireless_tools.29.tar.gz
[lingyun@localhostwireless]$ mkdir
[lingyun@localhostwireless]$ cd wireless_tools.29
[lingyun@localhostwireless_tools.29]$ vim Makefile
修改的地方如下:
PREFIX =/home/lingyun/yangzheng/wireless/wireless_tools
Endif
CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
## Compiler to use(modify this for cross compile).
CC=${CROSS}gcc
## Other tools youneed to modify for cross compile (static lib only).
AR=${CROSS}ar
RANLIB=${CROSS}ranlib
## Distributionsshould probably use /, but they probably know better...
ifndef PREFIX
PREFIX =/home/lingyun/yangzheng/wireless/wireless_tools //安装路径
endif
[lingyun@localhostwireless_tools.29]$ sudo make
[lingyun@localhostwireless_tools.29]$ ls
** iwlist ** iwspy ** iwgetid ** iwconfig ** ifrename ** iwpriv libiw.so.29 ** iwevent **
2)、编译wpa_supplicant
注意:由于wpa_supplicant依赖openssl库,所以这里我们得先交叉编译openssl,在交叉编译之前,我们得把wpa_supplicant-0.7.3.tar.gz源码中的openssl的补丁给打了
[lingyun@localhostwireless]$ wget http://hostap.epitest.fi/releases/wpa_supplicant-2.0.tar.gz
[lingyun@localhostwireless]$ wget http://www.openssl.org/source/openssl-0.9.8e.tar.gz
[lingyun@localhostwireless]$ tar -xzf openssl-0.9.8e.tar.gz
[lingyun@localhostwireless]$ tar -xzf wpa_supplicant-2.0.tar.gz
[lingyun@localhostwireless]$ cd wpa_supplicant-2.0
[lingyun@localhostwpa_supplicant-2.0]$ ls
COPYING patches README src wpa_supplicant
[lingyun@localhostopenssl-0.9.8e]$ cp../wpa_supplicant-2.0/patches/openssl-0.9.8e-tls-extensions.patch .
[lingyun@localhostopenssl-0.9.8e]$ patch -p1 <./openssl-0.9.8e-tls-extensions.patch
[lingyun@localhostopenssl-0.9.8e]$ vim Makefile
# equal 4.
# PKCS1_CHECK -pkcs1 tests.
CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
CC=${CROSS}gcc
CXX=${CROSS}g++
AR=${CROSS}ar$(ARFLAGS) r
AS=${CROSS}as
LD=${CROSS}ld
NM=${CROSS}nm
RANLIB=${CROSS}ranlib
STRIP=${CROSS}strip
INSTALL_PREFIX=
#INSTALLTOP=/usr/local/ssl
INSTALLTOP=/home/lingyun/yangzheng/wireless/install
# Do not edit thismanually. Use Configure --openssldir=DIR do change this!
#OPENSSLDIR=/usr/local/ssl
OPENSSLDIR=/home/lingyun/yangzheng/wireless/install
[lingyun@localhostwireless]$ mkdir install
[lingyun@localhostwireless]$ cd openssl-0.9.8e
[lingyun@localhostopenssl-0.9.8e]$ sudo make
[lingyun@localhostopenssl-0.9.8e]$ sudo make install
[lingyun@localhostwireless]$ cd install/
[lingyun@localhostinstall]$ ls
bin certs include lib man misc openssl.cnf private
[lingyun@localhostwpa_supplicant-2.0]$ cd wpa_supplicant/
[lingyun@localhostwpa_supplicant]$ cp defconfig .config
#LIBS = -lssl
###############################################################################
CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
OPENSSL_PATH=/home/lingyun/yangzheng/wireless
# Driver interfacefor Host AP driver
CONFIG_DRIVER_HOSTAP=y
CC=${CROSS}gcc
CFLAGS+=-I${OPENSSL_PATH}/install/include
LDFLAGS+=-L${OPENSSL_PATH}/install/lib–lssl
#CONFIG_DRIVER_ATMEL=y
CONFIG_DRIVER_RALINK=y
#CONFIG_PKCS12=y
#CONFIG_SMARTCARD=y
CONFIG_IEEE80211N=y
[lingyun@localhostwpa_supplicant]$ sudo make
[lingyun@localhostwpa_supplicant]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-stripwpa_supplicant
[lingyun@localhostwpa_supplicant]$ ls
wpa_passphrase ** wpa_supplicant** wpa_supplicant_conf.sh ** wpa_cli
3)、安装交叉编译出来的二进制文件到arm开发板上
>: cdapps/tools/
>: ls
iwconfig iwlist iwpriv wpa_passphrase wpa_supplicant
>:
5、wpa_supplicant.conf文件的生成
>: wpa_passphrase 无线路遥的用户名 无线路遥密码 >> wpa_supplicant.conf
>: cat /etc/wpa_supplicant.conf
#WPA-PSK/TKIP
#wpa_supplicant -Dwext -iwlan0-c/etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="Router_LingYun" //无线路遥用户名
key_mgmt=WPA-PSK
proto=WPA
pairwise=TKIP
group=TKIP
psk="password" //无线路遥密码
#psk=0f7b8ce91adcb61f1dcb6f76c87033c852fd3ebb7f4f2e2869860f077d376d9b
}
>: mkdir –p/var/run/wpa_supplicant
>: ifconfig -a
eth0 Link encap:Ethernet HWaddr 5A:51:DE:6D:A0:07
inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0overruns:0 frame:0
TX packets:0 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:51 Base address:0x4300
lo Link encap:Local Loopback
LOOPBACK MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0overruns:0 frame:0
TX packets:0 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 00:0C:43:30:72:81
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0overruns:0 frame:0
TX packets:0 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
>: ifconfigwlan0 192.168.1.198
>: ifconfig
eth0 Link encap:Ethernet HWaddr 5A:51:DE:6D:A0:07
inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0overruns:0 frame:0
TX packets:0 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Interrupt:51 Base address:0x4300
wlan0 Link encap:Ethernet HWaddr 00:0C:43:30:72:81
inet addr:192.168.1.198 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0overruns:0 frame:0
TX packets:0 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
>: ifconfigeth0 down
>: wpa_supplicant -Dwext -iwlan0-c/etc/wpa_supplicant.conf
Successfullyinitialized wpa_supplicant
wlan0: Trying toassociate with d8:5d:4c:18:04:7a (SSID='Router_LingYun' freq=2437 MHz)
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2,TXop: 47.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2,TXop: 94.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 4, CWmax: 10, Aifs: 3,TXop: 0.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7,TXop: 0.
wlan0: Associatedwith d8:5d:4c:18:04:7a
wlan0: WPA: Keynegotiation completed with d8:5d:4c:18:04:7a [PTK=TKIP GTK=TKIP]
wlan0:CTRL-EVENT-CONNECTED - Connection to d8:5d:4c:18:04:7a completed [id=0 id_str=]
wlan0: WPA: Grouprekeying completed with d8:5d:4c:18:04:7a [GTK=TKIP]
phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 -CWmin: 2, CWmax: 3, Aifs: 2, TXop: 47.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2,TXop: 94.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 4, CWmax: 10, Aifs: 3,TXop: 0.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7,TXop: 0.
cfg80211: CallingCRDA to update world regulatory domain
wlan0:CTRL-EVENT-DISCONNECTED bssid=d8:5d:4c:18:04:7a reason=3 locally_generated=1
wlan0:CTRL-EVENT-TERMINATING
>: wpa_supplicant -Dwext -iwlan0-c/etc/wpa_supplicant.conf & //后台运行
>: Successfullyinitialized wpa_supplicant
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2,TXop: 47.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2,TXop: 94.
phy0 -> rt2x00mac_conf_tx:Info - Configured TX queue 2 - CWmin: 4, CWmax: 10, Aifs: 3, TXop: 0.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7,TXop: 0.
phy0 ->rt2800usb_watchdog: Warning - TX HW queue 1 timed out, invoke forced kick
phy0 ->rt2x00usb_watchdog_tx_status: Warning - TX queue 0 status timed out, invokeforced tx handler
wlan0: Trying toassociate with d8:5d:4c:18:04:7a (SSID='Router_LingYun' freq=2437 MHz)
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2,TXop: 47.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2,TXop: 94.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 4, CWmax: 10, Aifs: 3,TXop: 0.
phy0 ->rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7,TXop: 0.
wlan0: Associatedwith d8:5d:4c:18:04:7a
wlan0: WPA: Keynegotiation completed with d8:5d:4c:18:04:7a [PTK=TKIP GTK=TKIP]
wlan0:CTRL-EVENT-CONNECTED - Connection to d8:5d:4c:18:04:7a completed [id=0 id_str=]
wlan0: WPA: Grouprekeying completed with d8:5d:4c:18:04:7a [GTK=TKIP]
>: udhcpc -iwlan0
udhcpc (v1.20.2)started
Sendingdiscover...
Sending select for192.168.1.112...
Lease of192.168.1.112 obtained, lease time 7200
>: ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2): 56 data bytes
64 bytes from192.168.1.2: seq=0 ttl=64 time=52.348 ms
64 bytes from192.168.1.2: seq=1 ttl=64 time=49.054 ms
64 bytes from192.168.1.2: seq=2 ttl=64 time=51.124 ms
64 bytes from192.168.1.2: seq=3 ttl=64 time=45.258 ms
64 bytes from192.168.1.2: seq=4 ttl=64 time=44.082 ms
参考:
wpa_supplicant的编译,使用参考:
http://blog.csdn.net/farsight2009/article/details/5660878
http://www.linuxidc.com/Linux/2011-10/45202.htm
http://www.cnblogs.com/zhuqing/archive/2011/04/06/2006763.html
http://blog.chinaunix.net/space.php?uid=22915173&do=blog&id=88182
到这里就可以就可以接到路由器上了!!!
AP模式还没做!!!!!
更多推荐
所有评论(0)