开发板STA模式下使用RT3070无线网卡接入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无线上网

[*] 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支持几乎所有的无线网卡和驱动,但它不能连接到那些只支持WPAAP

===================================================================

 

 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

 

 1.3修改Makefile

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. 11 ## Compiler to use (modify this for cross compile).  
  2. 12 CC = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc  
  3. 13 ## Other tools you need to modify for cross compile (static lib only).  
  4. 14 AR = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar  
  5. 15 RANLIB = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib  
1.4编译

[hongfuhao@centos6 wireless_tools.29]$ ls

19-udev-ifrename.rules  iwconfig.o  iwlist.o       sample_pm.c

CHANGELOG.h             iwevent     iwmulticall.c  sample_priv_addr.c

COPYING           iwevent.8   iwpriv         udev.import_devpath.diff

cs                      iwevent.c   iwpriv.8       wireless.10.h

DISTRIBUTIONS.txt       iwevent.d   iwpriv.c       wireless.11.h

fr                      iwevent.o   iwpriv.d       wireless.12.h

HOTPLUG.txt             iwgetid     iwpriv.o       wireless.13.h

ifrename                iwgetid.8   iwspy         wireless.14.h

ifrename.8              iwgetid.c   iwspy.8        wireless.15.h

ifrename.c              iwgetid.d   iwspy.c        wireless.16.h

ifrename.d              iwgetid.o   iwspy.d        wireless.17.h

ifrename.o              iwlib.c     iwspy.o        wireless.18.h

IFRENAME-VS-XXX.txt     iwlib.d     libiw.so.29    wireless.19.h

iftab.5                 iwlib.h     macaddr.c      wireless.20.h

INSTALL                 iwlib.so    Makefile       wireless.21.h

iwconfig                iwlist     PCMCIA.txt     wireless.22.h

iwconfig.8              iwlist.8    README         wireless.7

iwconfig.c              iwlist.c    README.fr      wireless.h

iwconfig.d              iwlist.d    sample_enc.c

1.5拷贝

将生成的命令工具:iwlistiwconfigiwprivlibiw.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

 

.2解压后创建指定的安装目录

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

2.3修改Makefile

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. 29INSTALLTOP=/home/leiyuxing/fl2440/kernel/linux-3.0/openssl-0.9.8i/install//指定ssl的安装目录  
  2. 32 OPENSSLDIR=/home/leiyuxing/fl2440/kernel/linux-3.0/openssl-0.9.8i/install  
  3. 62 CC= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc  
  4. 69 AR= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar $(ARFLAGS) r  
  5. 70 RANLIB= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib  

2.4编译

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

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

并拷贝libcrypto.a  libssl.a到开发板的/lib

 

3.wpa_supplicant驱动移植

3.1下载wpa_supplicant源码

wpa_supplicant-0.7.3.tar.gz

http://download.csdn.NET/detail/u010944778/8918325

3.2解压后修改.config配置文件

[hongfuhao@centos6 wpa_supplicant-0.7.3]$ ls

COPYING  patches  README  src  wpa_supplicant

[hongfuhao@centos6 wpa_supplicant-0.7.3]$ cd wpa_supplicant/

[hongfuhao@centos6 wpa_supplicant]$ cp defconfig .config

[hongfuhao@centos6 wpa_supplicant]$ vim .config

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. 27 #CC=/opt/brcm/hndtools-mipsel-uclibc/bin/mipsel-uclibc-gcc  
  2. 28 CC =/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc -L/home/leiyuxing/fl2440/kernel/linux-3.0/openssl-0.9.8i/install/lib  
  3. 29 #CFLAGS += -Os  
  4. 30 CFLAGS +=-I/home/leiyuxing/fl2440/kernel/linux-3.0/openssl-0.9.8i/install/include  
  5. 31 #CPPFLAGS += -I../src/include -I../../src/router/openssl/include  
  6. 32 #LIBS += -L/opt/brcm/hndtools-mipsel-uclibc-0.9.19/lib -lssl  
  7. 33 LIBS += -L/home/leiyuxing/fl2440/kernel/linux-3.0/openssl-0.9.8i/install/lib  
[hongfuhao@centos6 wpa_supplicant]$ make

 

 

然后将wpa_cli,wpa_supplicant,wpa_passphrase拷贝到开发板的/bin目录下切记wpa_cli,wpa_supplicant,wpa_passphrase都要给777权限!!!!

 

三.插上RT2070无线网卡并加载新内核启动

>内核信息打印部分

>: usb 1-1.2: new full speed USB device number 3 using s3c2410-ohci

phy0 -> 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 003: ID 148f:3070

>如果是热插拔的话会,在插入的那一刻,串口会打印如下信息:

>: usb 1-1.2: USB disconnect, device number 3

usb 1-1.2: new full speed USB device number 4 using s3c2410-ohci

phy1 -> rt2x00_set_chip: Info - Chipset detected - rt: 3070, rf: 0005, rev: 0201.

 

>ifconfig查看网卡信息

>: ifconfig wlan0

wlan0     Link encap:Ethernet  HWaddr 00:A1:B0:40:6E:F7  

          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无线网卡模块

>: 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无线模块连接路由器

>: cd apps/

>: ls

>:mkdir etc

>:cd etc

>:mkdir wireless

>:cd wireless

在开发板上输入命令:wpa_passphrase ssid psk>>wpa_supplicant.conf  (ssid就是你wifi的名字 psk就是密码)

例如:

>: wpa_passphrase fuhaogege>>wpa_supplicant.conf

修改我的配置文件:

>: vi wpa_supplicant.conf

[html] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. # WPA-PSK/TKIP  
  2. # wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf  
  3. ctrl_interface=/var/run/wpa_supplicant  
  4. network={                                                                     
  5.         ssid="fuhaogege"                                                 
  6.         key_mgmt=WPA-PSK                                                      
  7.         proto=WPA                                                             
  8.         pairwise=TKIP CCMP                                                    
  9.         #psk="fuhaogege123"                                                    
  10.         psk=a9a3f0b958b887804e71fe58694f82b5972dfc658827a366d6eea0c8abe9a42e  
  11. }  

五.连接你的路由器:

>: 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=2417 MHz)
phy2 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 5, 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=56.992 ms

64 bytes from 192.168.199.1: seq=2 ttl=64 time=45.916 ms

64 bytes from 192.168.199.1: seq=3 ttl=64 time=47.709 ms

64 bytes from 192.168.199.1: seq=4 ttl=64 time=47.760 ms

64 bytes from 192.168.199.1: seq=5 ttl=64 time=46.920 ms

64 bytes from 192.168.199.1: seq=6 ttl=64 time=47.732 ms

64 bytes from 192.168.199.1: seq=7 ttl=64 time=45.949 ms

64 bytes from 192.168.199.1: seq=8 ttl=64 time=50.674 ms

64 bytes from 192.168.199.1: seq=9 ttl=64 time=50.893 ms

64 bytes from 192.168.199.1: seq=10 ttl=64 time=45.923 ms

64 bytes from 192.168.199.1: seq=11 ttl=64 time=45.972 ms

64 bytes from 192.168.199.1: seq=12 ttl=64 time=45.994 ms

64 bytes from 192.168.199.1: seq=13 ttl=64 time=46.058 ms

64 bytes from 192.168.199.1: seq=14 ttl=64 time=45.983 ms

64 bytes from 192.168.199.1: seq=15 ttl=64 time=46.060 ms

64 bytes from 192.168.199.1: seq=16 ttl=64 time=46.877 ms

Ping自己的主机不好玩,那我们来试试外网的链接

在开发板目录/etc/创建一个resolv.conf的文件,因为在内核启动的时候内核会在

resolv.conf文件中找dns

>: vi resolv.conf

#search localdomain

nameserver 4.2.2.2

nameserver 8.8.8.8

添加网关后试试

>: route add default gw 192.168.199.1

>: ping www.baidu.com

PING www.baidu.com (119.75.217.109): 56 data bytes

64 bytes from 119.75.217.109: seq=0 ttl=53 time=25.603 ms

64 bytes from 119.75.217.109: seq=1 ttl=53 time=65.629 ms

64 bytes from 119.75.217.109: seq=2 ttl=53 time=77.645 ms

64 bytes from 119.75.217.109: seq=3 ttl=53 time=66.636 ms

64 bytes from 119.75.217.109: seq=4 ttl=53 time=67.671 ms

遇到的问题:

问题一:

 >: ifconfig wlan0 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 or directory

通常情况下,load firmware的动作是通过用户空间的hotplug handler,也就是/proc/sys/kernel/hotplug里设定的执行档,来完成。root_qtopia默认会在/etc/init.d/rcS里将/proc/sys/kernel/hotplug设定为/sbin/mdev,即busyboxmdev模块。它在收到来自内核的请求加载rt73.bin这个firmware消息后,会从/lib/firmware目录下去找rt73.bin,如果能找到就加载。

解决方法:

将下载好的固件RT2870.bin放入/lib文件下新创建的firmware目录中就可以解决。

问题二:

>: wpa_passphrase CMCC 2b2072b207 >> wpa_supplicant.conf

-sh: wpa_passphrase: Permission denied

解决方法:

>: ll wpa_passphrase

-rw-r--r--    1 root     root        474555 Dec 31 17:06 wpa_passphrase

>: chmod 777 wpa_passphrase

>: ll wpa_passphrase

-rwxrwxrwx    1 root     root        474555 Dec 31 17:06 wpa_passphrase

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章