------------------------------------------------------------------------------------------------------------------------------

交叉编译器:arm-linux-gcc-4.5.4

Linux内核版本:Linux-3.0

开发板:FL2440

本文章的内核已经已经添加了DM9000的网卡,USB驱动,使用的是initramfs的文件系统。

------------------------------------------------------------------------------------------------------------------------------

便于理解,在这里把rt3070 sta模式一直的大体步骤说一下:添加内核支持-->编译Wireless tools生成一些库函数放到开发板的/lib/下-->编译Openssl生成一些库函数(一是放在开发板的/lib/目录下用作开发板移植所需,二是wpa_supplicant编译所需)-->编译wpa_supplicant生成命令文件(wpa_passphrase、wpa_supplicant、wpa_cli)-->开发板配置sta模式:wpa_passphrase生成配置文件,wpa_supplicant命令执行配置文件。

一、添加内核:

Linux-3.0以上的版本中,rt3070的驱动已经加入了内核源码中去了,本篇用的是Linux-3.0的内核,只需要在内核的make menuconfig中选择支持rt3070的station模式就可以了。

修改如下:

[*] Networking support  --->

-*-   Wireless  --->

<*>   cfg80211 - wireless configuration API

[*]     enable powersave by default

<*>   Common routines for IEEE802.11 drivers

<*>   Generic IEEE 802.11 Networking Stack (mac80211)

[*]   Minstrel

[*]     Minstrel 802.11n support

Default rate control algorithm (Minstrel)  --->

Device Drivers  --->

Generic Driver Options  --->

-*- Userspace firmware loading support

[*]   Include in-kernel firmware blobs in kernel binary

   [*] Network device support  --->

[*]   Wireless LAN  --->

<*>   Ralink driver support  --->

--- Ralink driver support

<*>   Ralink rt27xx/rt28xx/rt30xx (USB) support

[*]   Ralink debug output

编译内核烧录到开发板并插上rt3070模块显示如下:

usb 1-1.1: new full speed USB device number 4 using s3c2410-ohci
usb 1-1.1: New USB device found, idVendor=148f, idProduct=3070
usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.1: Product: 802.11 n WLAN
usb 1-1.1: Manufacturer: Ralink
phy1 -> rt2x00_set_chip: Info - Chipset detected - rt: 3070, rf: 0005, rev: 0201.

>: lsusb
Bus 001 Device 001: ID 1d6b:0001
Bus 001 Device 002: ID 05e3:0606
Bus 001 Device 004: ID 148f:3070

>: ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:A1:B0:40:6F:9A
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)

如果想要启动wlan0还需要一个rt2870的固件。下载地址:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git

在开发板下创建/lib/firmware文件夹,将下载下来的linux-firmware/rt2870.bin拷贝到开发板的firmware文件夹下。

二、无线网络配置工具移植

wireless_tools.29.tar.gz    下载地址http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29

openssl-0.9.8i.tar.gz    下载地址http://www.openssl.org/source/openssl-0.9.8i

wpa_supplicant-0.7.3.tar.gz    下载地址http://hostap.epitest.fi/releases/wpa_supplicant-0.7.3

(1)wireless_tools的配置:

[xiaohexiansheng@centos6 test]$ tar xzvf wireless_tools.29.tar.gz

[xiaohexiansheng@centos6 test]$ cd wireless_tools.29

[xiaohexiansheng@centos6 wireless_tools.29]$ vim Makefile

修改如下:

CC =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc

AR = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar

RANLIB =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib

[xiaohexiansheng@centos6 wireless_tools.29]$ make

这时可以在当前目录下找到生成的文件:iwlist iwconfig iwpriv libiw.so.29 把文件分别拷贝到开发板的/lib/ /bin/目录下,并修改权限为可执行文件:

(2)openssl的配置

因为wpa_supplicant的编译需要openssl编译出来的库文件,所以这里需要首先编译openssl。

[xiaohexiansheng@centos6 rt3070]$ tar -xzf openssl-0.9.8i.tar.gz
[xiaohexiansheng@centos6 rt3070]$ cd openssl-0.9.8i

[xiaohexiansheng@centos6 openssl-0.9.8i]$ mkdir install

[xiaohexiansheng@centos6 openssl-0.9.8i]$ vim Makefile

修改如下:

INSTALLTOP=/home/xiaohexiansheng/fl2440/3rdparty/rt3070/openssl-0.9.8i/install

OPENSSLDIR=/home/xiaohexiansheng/fl2440/3rdparty/rt3070/openssl-0.9.8i/install

CC= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc

AR= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar $(ARFLAGS) r

RANLIB= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib

[xiaohexiansheng@centos6 openssl-0.9.8i]$ sudo make

[xiaohexiansheng@centos6 openssl-0.9.8i]$ sudo make install

[xiaohexiansheng@centos6 openssl-0.9.8i]$ ls install/lib/
engines  libcrypto.a  libssl.a   pkgconfig

将libcrypto.a  libssl.a拷贝到开发板的/lib/目录下

(3)wpa_supplicant配置

[xiaohexiansheng@centos6 rt3070]$ tar -xzf wpa_supplicant-0.7.3.tar.gz
[xiaohexiansheng@centos6 rt3070]$ cd wpa_supplicant-0.7.3
[xiaohexiansheng@centos6 wpa_supplicant-0.7.3]$ ls
COPYING patches README src wpa_supplicant
[xiaohexiansheng@centos6 wpa_supplicant-0.7.3]$ cd wpa_supplicant/

[xiaohexiansheng@centos6 wpa_supplicant]$ cp defconfig .config
[xiaohexiansheng@centos6 wpa_supplicant]$ vim .config

修改如下:

CC= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc -L/home/guanlei/fl2440/3rdparty/rt3070/openssl-0.9.8i/install/lib

CFLAGS += -I/home/xiaohexiansheng/fl2440/3rdparty/rt3070/openssl-0.9.8i/install/include

LIBS += -L/home/xiaohexiansheng/fl2440/3rdparty/rt3070/openssl-0.9.8i/install/lib

[xiaohexiansheng@centos6 wpa_supplicant]$ make

生成的文件中我们所需要的文件有:wpa_passphrase wpa_supplicant wpa_cli

三、开发板文件配置

理一下所需要的文件及所在的位置:

/lib/:iwlist iwconfig iwpriv libiw.so.29 libcrypto.a libssl.a

/bin/:iwlist iwconfig iwpriv libiw.so.29

wpa_supplicant下生成的wpa_passphrase wpa_supplicant wpa_cli这三个文件是命令文件。

wpa_passphrase用来生成wpa_supplicant.conf的配置文件:

>: ./wpa_passphrase ssid psk >> wpa_supplicant.conf  (ssid就是wifi名字 psk是密码)

这时生成的.conf文件还不能用,需要修改一下,最终的文件是这种形式:

# WPA-PSK/TKIP
# wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
network={
  ssid="ssid"
  key_mgmt=WPA-PSK     // 加密模式 这里一定要和的你要连的wifi保持一致

  proto=WPA
  pairwise=TKIP CCMP
  #psk="psk"
  psk=a9a3f0b958b887804e71fe58694f82b5972dfc658827a366d6eea0c8abe9a42e
}

>: ./wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf &
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.
Trying to associate with d4:ee:07:22:6b:5c (SSID='HiWiFi_LingYun' freq=2427 MHz)
phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 7, CWmax: 10, Aifs: 3, TXop: 0.
phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7, TXop: 0.
phy1 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 94.
phy1 -> 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=]

>: ./iwconfig
lo no wireless extensions.

eth0 no wireless extensions.

wlan0 IEEE 802.11bgn ESSID:"HiWiFi_LingYun"
Mode:Managed Frequency:2.427 GHz Access Point: D4:EE:07:22:6B:5C
Bit Rate=60 Mb/s Tx-Power=20 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:on
Link Quality=53/70 Signal level=-57 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:1 Missed beacon:0

>: ifconfig wlan0 192.168.199.234 up
>: 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=59.740 ms
64 bytes from 192.168.199.1: seq=1 ttl=64 time=46.335 ms
64 bytes from 192.168.199.1: seq=2 ttl=64 time=49.224 ms

--- 192.168.199.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 46.335/51.766/59.740 ms

好了,这时开发板就可以通过rt3070这个模块来连接路由器了。

四、登陆外网

>: ifconfig wlan0 192.168.199.234 netmask 255.255.255.0 up

>: ifconfig eth0 down

>: ifconfig
wlan0 Link encap:Ethernet HWaddr 00:A1:B0:40:6F:9A
inet addr:192.168.199.234 Bcast:192.168.199.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:690 errors:0 dropped:170 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:63943 (62.4 KiB) TX bytes:901 (901.0 B)

添加resolv.conf来进行域名解析:

>: vi /etc/resolv.conf

earch localdomain
nameserver 4.2.2.2
nameserver 8.8.8.8

>: 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.430 ms
64 bytes from 119.75.218.70: seq=1 ttl=53 time=66.255 ms

05-11 19:48