实现RT3070无线网卡STA模式并使开发板接入Wifi上网
主机操作系统:Centos 6.7
交叉编译器环境:arm-linux-gcc-4.5.4
开发板平台: FL2440
Linux内核版本: 3.0
STA模式:笔记本上无线网卡模式,用来连接到无线路由器上上网。通俗点说,就是客户端模式(笔记本)
所以我们的驱动有两种,分别支持无来线网卡工作在STA模式和AP模式。因为linux3.0以上的内核中已经含有了RT3070的通用mac80211驱动框架,所以我首先直接基于此并借助wpa_suppicant软件来实现Wifi的STA模式。
一、配置Linux内核支持wireless无线上网
[luxibao@centos linux-3.0]$ make menuconfig
[*] Networking support --->
-*- Wireless --->
<*> cfg80211 - wireless configuration API
[ ] nl80211 testmode command
[ ] enable developer warnings
[ ] cfg80211 regulatory debugging
[*] enable powersave by default
[ ] cfg80211 DebugFS entries
[*] cfg80211 wireless extensions compatibility
[*] Wireless extensions sysfs files
{*} Common routines for IEEE802.11 drivers
[ ] lib80211 debugging messages
<*> Generic IEEE 802.11 Networking Stack (mac80211)
Default rate control algorithm (Minstrel) --->
[ ] Enable mac80211 mesh networking (pre-802.11s) support
[ ] Export mac80211 internals in DebugFS
[ ] Select mac80211 debugging features --->
Device Drivers --->
Generic Driver Options --->
(/sbin/hotplug) path to uevent helper
[ ] Maintain a devtmpfs filesystem to mount at /dev
[ ] Select only drivers that don't need compile-time external firmware
[ ] Prevent firmware from being built
-*- Userspace firmware loading support
[*] Include in-kernel firmware blobs in kernel binary
() External firmware blobs to build into the kernel binary
[ ] Driver Core verbose debug messages
[ ] Managed device resources verbose debug messages
[*] Network device support --->
[*] Wireless LAN --->
<*> Ralink driver support --->
< > Ralink rt2500 (USB) support
< > Ralink rt2501/rt73 (USB) support
<*> Ralink rt27xx/rt28xx/rt30xx (USB) support
[ ] rt2800usb - Include support for rt33xx devices
[ ] rt2800usb - Include support for rt35xx devices (EXPERIMENTAL)
[ ] rt2800usb - Include support for rt53xx devices (EXPERIMENTAL)
[ ] rt2800usb - Include support for unknown (USB) devices
[*] Ralink debug output
二.资源下载无线网络配置工具Wireless tools和Wpa_supplicant以及Openssl移植
目前可以使用wireless-tools或wpa_supplicant工具来配置无线网络。但要注意对无线网络的配置是全局性的,而非针对具体的接口。wpa_supplicant是一个较好的选择,但缺点是它不支持所有的驱动。另外,wpa_supplicant目前只能连接到那些你已经配置好ESSID的无线网络。而wireless-tools支持几乎所有的无线网卡和驱动,但它不能连接到那些只支持WPA的AP。
1. 1 Wireless tools移植
wireless_tools.29.tar.gz
http://download.csdn.net/detail/u010944778/8916883
1.2解压
$ tar zxvf wireless_tools.29.tar.gz
$ cd wireless_tools.29
[luxibao@centos wireless_tools.29]$ ls
19-udev-ifrename.rules IFRENAME-VS-XXX.txt iwlib.c macaddr.c wireless.10.h wireless.19.h
CHANGELOG.h iftab.5 iwlib.h Makefile wireless.11.h wireless.20.h
COPYING INSTALL iwlist.8 PCMCIA.txt wireless.12.h wireless.21.h
cs iwconfig.8 iwlist.c README wireless.13.h wireless.22.h
DISTRIBUTIONS.txt iwconfig.c iwmulticall.c README.fr wireless.14.h wireless.7
fr iwevent.8 iwpriv.8 sample_enc.c wireless.15.h
HOTPLUG.txt iwevent.c iwpriv.c sample_pm.c wireless.16.h
ifrename.8 iwgetid.8 iwspy.8 sample_priv_addr.c wireless.17.h
ifrename.c iwgetid.c iwspy.c udev.import_devpath.diff wireless.18.h
1.3修改Makefile
11 ## Compiler to use (modify this for cross compile).
12 CC = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
13 ## Other tools you need to modify for cross compile (static lib only).
14 AR = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar
15 RANLIB = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib
1.4编译
[luxibao@centos wireless_tools.29]$ make
[luxibao@centos wireless_tools.29]$ ls
19-udev-ifrename.rules iwconfig iwlib.c iwspy wireless.10.h
CHANGELOG.h iwconfig.8 iwlib.d iwspy.8 wireless.11.h
COPYING iwconfig.c iwlib.h iwspy.c wireless.12.h
cs iwconfig.d iwlib.so iwspy.d wireless.13.h
DISTRIBUTIONS.txt iwconfig.o iwlist iwspy.o wireless.14.h
fr iwevent iwlist.8 libiw.so.29 wireless.15.h
HOTPLUG.txt iwevent.8 iwlist.c macaddr.c wireless.16.h
ifrename iwevent.c iwlist.d Makefile wireless.17.h
ifrename.8 iwevent.d iwlist.o PCMCIA.txt wireless.18.h
ifrename.c iwevent.o iwmulticall.c README wireless.19.h
ifrename.d iwgetid iwpriv README.fr wireless.20.h
ifrename.o iwgetid.8 iwpriv.8 sample_enc.c wireless.21.h
IFRENAME-VS-XXX.txt iwgetid.c iwpriv.c sample_pm.c wireless.22.h
iftab.5 iwgetid.d iwpriv.d sample_priv_addr.c wireless.7
INSTALL iwgetid.o iwpriv.o udev.import_devpath.diff wireless.h
1.5拷贝
将生成的命令工具:iwlist、iwconfig、iwpriv,libiw.so.29 等拷贝到目标板上,路径为:分别把他们放到开发板的/bin和/lib目录下,并赋予权限
chmod 777 iw* libiw.so.29
如下:
2.Openssl工具移植
===================================================================现在的wifi网络肯定都是加密的。而大多都是WPA加密,所以wpa_supplicant对我们来说除了配置无线网络的需求之外,它更主要是用来支持WEP,WPA/WPA2和WAPI无线协议和加密认证的。而要加密就要使用到相关的加密算法,常用的密钥等,所以我们要先移植Openssl工具再移植wpa-supplicant。因为后面编译wpa_supplicant要依赖openssl中的lib和include
===================================================================
2.1、下载openssl驱动源码
Openssl-0.9.8i
http://download.csdn.net/detail/u010944778/8918317
解压 tar zxvf openssl-0.9.8i.tar.gz
2.2解压后创建指定的安装目录
[luxibao@centos openssl-0.9.8i]$ mkdir install
3修改Makefile
l 29INSTALLTOP=/home/luxibao/fl2440/kernel/linux-3.0/openssl-0.9.8i/install//指定ssl的安装目录
32 OPENSSLDIR=/home/luxibao/fl2440/kernel/linux-3.0/openssl-0.9.8i/install
62 CC= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
69 AR= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar $(ARFLAGS) r
70 RANLIB= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib
2.4编译
[luxibao@centos openssl-0.9.8i]$ make
[luxibao@centos openssl-0.9.8i]$ make install
[luxibao@centos openssl-0.9.8i]$ cd install
[luxibao@centos install]$ ls
bin certs include lib man misc openssl.cnf private
[luxibao@centos install]$ cd lib
[luxibao@centos lib]$ ls
engines libcrypto.a libssl.a pkgconfig
并拷贝libcrypto.a ; libssl.a到开发板的/lib下
libcrypto.a ; libssl.a 都要给777权限!!!!
3.wpa_supplicant驱动移植
3.1、下载wpa_supplicant源码
wpa_supplicant-0.7.3.tar.gz
http://download.csdn.net/detail/u010944778/8918325
$ tar zxvf wpa_supplicant-0.7.3.tar.gz
3.2、解压后修改.config配置文件
[luxibao@centos linux-3.0]$ cd wpa_supplicant-0.7.3
[luxibao@centos wpa_supplicant-0.7.3]$ ls
COPYING patches README src wpa_supplicant
[luxibao@centos wpa_supplicant-0.7.3]$ cd wpa_supplicant/
[luxibao@centos wpa_supplicant]$ cp defconfig .config
27 #CC=/opt/brcm/hndtools-mipsel-uclibc/bin/mipsel-uclibc-gcc
28 CC =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc -L/home/luxibao/fl2440/kernel/linux-3.0/openssl-0.9.8i/install/lib
29 #CFLAGS += -Os
30 CFLAGS +=-I/home/luxibao/fl2440/kernel/linux-3.0/openssl-0.9.8i/install/include
31 #CPPFLAGS += -I../src/include -I../../src/router/openssl/include
32 #LIBS += -L/opt/brcm/hndtools-mipsel-uclibc-0.9.19/lib -lssl
33 LIBS += -L/home/luxibao/fl2440/kernel/linux-3.0/openssl-0.9.8i/install/lib
[luxibao@centos wpa_supplicant]$ make
[luxibao@centos wpa_supplicant]$ ls
ap.c ctrl_iface.h main_symbian.cpp win_if_list.c
ap.h ctrl_iface_named_pipe.c main_winmain.c wpa_cli
bgscan.c ctrl_iface.o main_winsvc.c wpa_cli.c
bgscan.h ctrl_iface_udp.c Makefile wpa_cli.d
bgscan_simple.c ctrl_iface_unix.c mlme.c wpa_cli.o
blacklist.c ctrl_iface_unix.d mlme.h wpa_gui
blacklist.d ctrl_iface_unix.o nmake.mak wpa_gui-qt4
blacklist.h dbus notify.c wpa_passphrase
blacklist.o defconfig notify.d wpa_passphrase.c
bss.c doc notify.h wpa_passphrase.d
bss.d driver_i.h notify.o wpa_passphrase.o
bss.h eapol_test.c preauth_test.c wpa_priv.c
bss.o eap_register.c README wpas_glue.c
ChangeLog eap_register.d README-Windows.txt wpas_glue.d
config.c eap_register.o README-WPS wpas_glue.h
config.d eap_testing.txt scan.c wpas_glue.o
config_file.c events.c scan.d wpa_supplicant
config_file.d events.d scan.h wpa_supplicant.c
config_file.o events.o scan.o wpa_supplicant.conf
config.h examples sme.c wpa_supplicant.d
config_none.c ibss_rsn.c sme.h wpa_supplicant_i.h
config.o ibss_rsn.h symbian wpa_supplicant.nsi
config_ssid.h main.c tests wpa_supplicant.o
config_winreg.c main.d todo.txt wps_supplicant.c
ctrl_iface.c main_none.c vs2005 wps_supplicant.h
ctrl_iface.d main.o win_example.reg xcode
然后将wpa_cli,wpa_supplicant,wpa_passphrase拷贝到开发板的/bin目录下切记wpa_cli,wpa_supplicant,wpa_passphrase都要给777权限!!!!
三.插上RT2070无线网卡并加载新内核启动
>如果是热插拔的话会,在插入的那一刻,串口会打印如下信息:
>: usb 1-1.1: USB disconnect, device number 3
dm9000 dm9000: eth0: link down
usb 1-1.1: new full speed USB device number 4 using s3c2410-ohci
phy1 -> rt2x00_set_chip: Info - Chipset detected - rt: 3070, rf: 0005, rev: 0201.
>使用lsusb命令查看:
>: lsusb
Bus 001 Device 001: ID 1d6b:0001
Bus 001 Device 002: ID 05e3:0606
Bus 001 Device 004: ID 148f:3070
>ifconfig查看网卡信息
>: ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:24:25:50:A9:4D
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)
//第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)
第三行:MULTICAST(支持组播)MTU:1500(最大传输单元):1500字节
第四、五行:接收、发送数据包情况统计
第七行:接收、发送数据字节数统计信息
>使能RT3070无线网卡模块
>: ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr
>: cd lib/
>: mkdir firmware
>: cd firmware/
>: tftp -gr rt2870.bin 192.168.1.2
rt2870.bin 100% |*******************************| 8192 0:00:00 ETA
>: ifconfig wlan0 up
phy1 -> rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'.
phy1 -> rt2x00lib_request_firmware: Info - Firmware detected - version: 0.36.
phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 102.
phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 4, CWmax: 5, Aifs: 2, TXop: 188.
phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 5, CWmax: 10, Aifs: 3, TXop: 0.
phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 5, CWmax: 10, Aifs: 7, TXop: 0.
四.启动RT3070无线模块连接路由器
>: ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr
>: cd apps/
>: ls
>: mkdir etc
>: ls
etc
>: cd etc/
>: mkdir wireless
>: cd wireless/
在开发板上输入命令:wpa_passphrase ssid psk>>wpa_supplicant.conf (ssid就是你wifi的名字 psk就是密码)
例如我的设置:
>: wpa_passphrase HiWiFi_LingYun lingyun-emb>>wpa_supplicant.conf
修改我的配置文件:
>: vi wpa_supplicant.conf
wpa_supplicant.conf
# WPA-PSK/TKIP
# wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="HiWiFi_LingYun"
key_mgmt=WPA-PSK
proto=WPA
pairwise=TKIP CCMP
#psk="lingyun-emb"
psk=a9a3f0b958b887804e71fe58694f82b5972dfc658827a366d6eea0c8abe9a42e
}
五.连接路由器:
>: wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf &
>: Trying to associate with d4:ee:07:22:6b:5c (SSID='HiWiFi_LingYun' freq=2452 MHz)
phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 6, CWmax: 10, Aifs: 3, TXop: 0.
phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7, TXop: 0.
phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 94.
phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2, TXop: 47.
Associated with d4:ee:07:22:6b:5c
WPA: Key negotiation completed with d4:ee:07:22:6b:5c [PTK=CCMP GTK=CCMP]
CTRL-EVENT-CONNECTED - Connection to d4:ee:07:22:6b:5c completed (auth) [id=0 id_str=]
设置无限网卡IP和子网掩码
>: ifconfig wlan0 192.168.199.234 netmask 255.255.255.0
你可以ping一下你的主机IP(192.168.199.1是博主的主机IP)
>: ping 192.168.199.1
PING 192.168.199.1 (192.168.199.1): 56 data bytes
64 bytes from 192.168.199.1: seq=0 ttl=64 time=52.890 ms
64 bytes from 192.168.199.1: seq=1 ttl=64 time=49.526 ms
64 bytes from 192.168.199.1: seq=2 ttl=64 time=45.649 ms
64 bytes from 192.168.199.1: seq=3 ttl=64 time=45.608 ms
64 bytes from 192.168.199.1: seq=4 ttl=64 time=45.690 ms
64 bytes from 192.168.199.1: seq=5 ttl=64 time=47.531 ms
64 bytes from 192.168.199.1: seq=6 ttl=64 time=45.970 ms
64 bytes from 192.168.199.1: seq=7 ttl=64 time=45.810 ms
64 bytes from 192.168.199.1: seq=8 ttl=64 time=51.653 ms
64 bytes from 192.168.199.1: seq=9 ttl=64 time=52.527 ms
64 bytes from 192.168.199.1: seq=10 ttl=64 time=45.868 ms
64 bytes from 192.168.199.1: seq=11 ttl=64 time=45.866 ms
64 bytes from 192.168.199.1: seq=12 ttl=64 time=45.904 ms
64 bytes from 192.168.199.1: seq=13 ttl=64 time=45.808 ms
64 bytes from 192.168.199.1: seq=14 ttl=64 time=45.769 ms
64 bytes from 192.168.199.1: seq=15 ttl=64 time=64.155 ms
64 bytes from 192.168.199.1: seq=17 ttl=64 time=47.548 ms
64 bytes from 192.168.199.1: seq=18 ttl=64 time=46.635 ms
试试外网连接
在开发板目录/etc/创建一个resolv.conf的文件,因为在内核启动的时候内核会在resolv.conf中查找dns.
>: vi resolv.conf
#search localdomain
nameserver 4.2.2.2
nameserver 8.8.8.8
添加网关后试试
>: cp resolv.conf /etc/
>: route add default gw 192.168.199.1
>: ping www.baidu.com
PING www.baidu.com (119.75.218.70): 56 data bytes
64 bytes from 119.75.218.70: seq=0 ttl=53 time=24.688 ms
64 bytes from 119.75.218.70: seq=1 ttl=53 time=71.602 ms
64 bytes from 119.75.218.70: seq=2 ttl=53 time=70.429 ms
64 bytes from 119.75.218.70: seq=3 ttl=53 time=72.577 ms
--- www.baidu.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 24.688/59.824/72.577 ms
遇到的问题:
1.
解决:
发现arm-linux-gcc没有编译成功,重新做wpa_supplicant驱动移植时发现
添加代码回车转下一行时自动生成了#号导致代码没有执行,去掉#号后重新编译后就可以了。
2./etc/下没有执行文件,导致:
解决:>: cp resolv.conf /etc/