天天看點

fl2440添加rt3070wifi子產品--關于sta模式

//

主機作業系統:CentOS6.7

終端調試:SecureCRT6.0

核心:linux-3.0

開發闆:fl2440

交叉編譯器:arm-linux-gcc-4.5.4

//

目的:實作RT3070無線網卡STA模式并使開發闆接入Wifi上網

RT3070的工作模式分為 STA(station)模式、SoftAP(Access Point)模式兩種。

STA模式:STA就是站點,每一個連接配接到無線網絡中的終端(如筆記本電腦、 PDA及其它可以聯網的使用者裝置)都可稱為一個站點。

AP模式:AP也就是無線接入點,是一個無線網絡的建立者,是網絡的中心節點。一般家庭或辦公室使用的無線路由器就是一個AP。

是以我們的驅動有兩種,分别支援無來線網卡工作在STA模式和AP模式。因為linux3.0以上的核心中已經含有了RT3070的通用驅動架構mac80211,是以直接基于此并借助wpa_suppicant軟體來實作(使能)Wifi的STA模式。

1.需要的檔案:

https://hewlettpackard.github.io/wireless-tools/wireless_tools.29.tar.gz

ftp://ftp.openssl.org/source/openssl-1.0.0t.tar.gz

http://w1.fi/releases/wpa_supplicant-0.7.3.tar.gz

https://coding.net/u/sfantree/p/self_use_OSS/git/raw/master/source/rt2870.bin

2.配置linux核心支援無線上網

[*] Networking support  --->

-*-   Wireless  --->

<*>   cfg80211 - wireless configuration API

                [*]     enable powersave by default

                [*]     cfg80211 wireless extensions compatibility

                [*]   Wireless extensions sysfs files

                [*]   Common routines for IEEE802.11 drivers

                <*>   Generic IEEE 802.11 Networking Stack (mac80211)

Device Drivers  --->

        Generic Driver Options  --->

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

[*] Network device support  --->

        [*]   Wireless LAN  --->

               <*>   IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)                    

                [*]     Support downloading firmware images with Host AP driver                   

                [*]       Support for non-volatile firmware download

          <*>   Ralink driver support  ---> 

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

                                        [*]   Ralink debug output

##注意M選項的一定要改成*,即按y選取。M代表子產品化(module),即要通過insmod加載.ko檔案,*代表編譯進核心.

如果M選項沒改成*,就會出現錯誤usb 1-1.1: device descriptor read/64, error -62

3.加載沒配置支援無線上網的核心,插上rt3070時的情況

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

>: lsusb 

Bus 001 Device 001: ID 1d6b:0001

Bus 001 Device 002: ID 05e3:0606

Bus 001 Device 003: ID 148f:3070

>: ifconfig wlan0

ifconfig: wlan0: error fetching interface information: Device not found

//因為沒添加裝置驅動,自然找不到裝置

4.配置後的核心,插上rt3070時的情況:

>: usb 1-1.1: USB disconnect, device number 4

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

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:22:C0:2F:E7:7A  

          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)

//添加裝置驅動後,裝置與驅動互相比對,是以可以檢視到裝置資訊,但是還不能夠使能,原因是缺少固件.

5.無線網絡配置工具wireless tools的移植,以及   openssl和wpa_supplicant的移植(注意先要移植openssl,再移植wpa_supplicant,因為後者依賴于前者的生成庫檔案)

目前可以使用wireless-tools或wpa_supplicant工具來配置無線網絡。但要注意對無線網絡的配置是全局性的,而非針對具體的接口,是以wpa_supplicant是一個較好的選擇,但缺點是它不支援所有的驅動。另外,wpa_supplicant目前隻能連接配接到那些你已經配置好ESSID的無線網絡。而wireless-tools支援幾乎所有的無線網卡和驅動,但它不能連接配接到那些隻支援WPA的AP。現在大部分路由器都使用wpa加密,是以使用iwconfig無論怎麼設定都無法連接配接到路由器AP上,除非路由器設定了WEP加密或者不設定密碼。

5.1 wireless tools的移植(在這個sta模式中,用不用都無所謂,因為主要用wpa_supplicant來配置)

tar zxvf wireless_tools.29.tar.gz

cd wireless_tools.29

vim Makefile

[html]  view plain  copy

  1. <span style="font-size:18px;"> 7 ifndef PREFIX  
  2.   8   PREFIX = /home/luminqi/fl2440/3rdparty/wirelesstool  
  3.   9 endif  
  4.  10   
  5.  11 ## Compiler to use (modify this for cross compile).  
  6.  12 CC = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc  
  7.  13 ## Other tools you need to modify for cross compile (static lib only).  
  8.  14 AR = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar  
  9.  15 RANLIB = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib</span>  

make

make install

移植動态庫檔案到開發闆的/lib

/home/luminqi/fl2440/3rdparty/wirelesstool/lib/libiw.so.29

移植指令工具到開發闆的/bin

/home/luminqi/fl2440/3rdparty/wirelesstool/sbin/iwconfig(還有iwevent iwgetid iwlist iwpriv iwspy)

5.2 openssl移植(直接解壓縮得到的Makefile不能編譯成功,估計太舊,是以要重新配置Makefile,檢視README,裡面說明Unix類的安裝說明在INSTALL檔案裡)

openssl 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協定,并提供豐富的應用程式供測試或其它目的使用。

tar zxvf openssl-1.0.0t.tar.gz

cd openssl-1.0.0t

./config no-asm shared --prefix=/home/luminqi/fl2440/3rdparty/openssl  

vim Makefile

[html]  view plain  copy

  1. <span style="font-size:18px;">CC= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc  
  2. AR= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar $(ARFLAGS) r  
  3. RANLIB= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib  
  4. NM= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-nm</span>  

make

make install

//openssl移植

參考連結:http://blog.csdn.net/miaodichiyou/article/details/50385049

将下面兩個動态庫檔案移植到開發闆/lib下

/home/luminqi/fl2440/3rdparty/openssl/lib/libcrypto.so.1.0.0

/home/luminqi/fl2440/3rdparty/openssl/lib/libssl.so.1.0.0

5.3 wpa_supplicant移植(同樣檢視README)

//wpa_supplicant就是WiFi驅動和使用者的中轉站外加對協定和加密認證的支援。

tar zxvf wpa_supplicant-0.7.3.tar.gz

cd wpa_supplicant-0.7.3

cd wpa_supplicant

cp defconfig .config

vim .config

[html]  view plain  copy

  1. 25 #### sveasoft (e.g., for Linksys WRT54G) ######################################  
  2. 26 #CC=mipsel-uclibc-gcc  
  3. 27 #CC=/opt/brcm/hndtools-mipsel-uclibc/bin/mipsel-uclibc-gcc  
  4. 28 #CFLAGS += -Os  
  5. 29 #CPPFLAGS += -I../src/include -I../../src/router/openssl/include  
  6. 30 #LIBS += -L/opt/brcm/hndtools-mipsel-uclibc-0.9.19/lib -lssl  
  7. 31 ###############################################################################  
  8. 32 CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc  -L/luminqi/fl2440/3rdparty/openssl/lib/  
  9. 33 CFLAGS += -I/home/luminqi/fl2440/3rdparty/openssl/include/  
  10. 34 LIBS += -L/home/luminqi/fl2440/3rdparty/openssl/lib  

make

這裡可以不用make install,直接在解壓縮目錄下查找檔案.

移植下列指令工具到開發闆的/bin

/home/luminqi/rt3070/sta/wpa_supplicant-0.7.3/wpa_supplicant/ wpa_cli

/home/luminqi/rt3070/sta/wpa_supplicant-0.7.3/wpa_supplicant/ wpa_passphrase

/home/luminqi/rt3070/sta/wpa_supplicant-0.7.3/wpa_supplicant/ wpa_supplicant

wpa_supplicant是核心程式,它和wpa_cli的關系就是服務和用戶端的關系:背景運作wpa_supplicant,使用wpa_cli來搜尋、設定、和連接配接網絡。

一般的無線接入點可以用wpa_passphrase來自動生成

6.加載固件rt2870.bin,初始化rt3070無線網卡并使能

通常情況下,load firmware的動作是通過使用者空間的hotplug handler,也就是/proc/sys/kernel/hotplug裡設定的執行檔來完成。我們可以在/etc/init.d/rcS裡将/proc/sys/kernel/hotplug設定為/sbin/mdev,即busybox的mdev子產品。首先rt3070裝置向核心請求加載rt2870.bin,然後核心向使用者空間(檔案系統)發出通知,mdev在收到來自核心的請求加載rt2870.bin這個firmware的消息後,就會會在/lib/firmware目錄下尋找rt2870.bin,如果能找到就加載到記憶體中,再由驅動傳輸到rt3070晶片。傳輸完成後rt3070晶片進行初始化,初始化完成之後就可以使能.

##核心産生hotplug事件找firmware都是到/lib/firmware這個路徑 ,這是固定的;rt2870.bin也不能夠修改名稱,因為rt3070裝置隻認識這個檔案##

##談談個人對rt2870.bin這個固件的了解:因為Linux-3.0沒有具體的rt3070驅動,隻有基本構架的驅動,而基本構架的驅動隻是做了一小部分初始化rt3070裝置的工作,是以需要固件來繼續完成所有的初始化工作.廢話到此為止,下面是相關步驟:

1)檔案系統的/etc/init.d/rcS最後加:"echo /sbin/mdev > /proc/sys/kernel/hotplug" 這樣一句,可通過vi打開并寫入。

2)加載rt2870.bin到開發闆的/lib/firmware目錄下(沒有firmware則建立),tftp -gr rt2870.bin 192.168.1.2(Windows有線網卡IP)

3)ifconfig wlan0 up

7.制作連接配接WiFi的配置檔案wpa_supplicant.conf,并通過此檔案連接配接WiFi.

>: cd /apps/etc/wireless(沒有此路徑則建立相關目錄,不一定要将此配置檔案放在這裡)

>: wpa_passphrase ssid psk >> wpa_supplicant.conf  (注意ssid是wifi的名稱,psk是wifi密碼)

>: vi wpa_supplicant.conf

作如下修改:

[html]  view plain  copy

  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="super318"                                                   
  6.         key_mgmt=WPA-PSK        //認證密鑰管理協定                                                
  7.         proto=WPA                                                               
  8.         pairwise=TKIP CCMP        //加密方式  TKIP和CCMP是兩種資料加密算法,在WPA和WPA2中都可以使用           #psk="5423874a"                                                      
  9.         psk=1acfb6ae7be84ad7d7a040b7d5423874ae8fb1f29aac239037c680a59d93214d    
  10. }  

>: ifconfig eth0 down  (禁用eth0,不禁用就會預設eth0連接配接WiFi,會出錯)

>: wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf &    //連接配接WiFi

[html]  view plain  copy

  1. >: Trying to associate with c8:e7:d8:1d:1a:e8 (SSID='super318' freq=2412 MHz)  
  2. phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 2 - CWmin: 4, CWmax: 10, Aifs: 3, TXop: 0.  
  3. phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 3 - CWmin: 4, CWmax: 10, Aifs: 7, TXop: 0.  
  4. phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 1 - CWmin: 3, CWmax: 4, Aifs: 2, TXop: 94.  
  5. phy0 -> rt2x00mac_conf_tx: Info - Configured TX queue 0 - CWmin: 2, CWmax: 3, Aifs: 2, TXop: 47.  
  6. Associated with c8:e7:d8:1d:1a:e8  
  7. WPA: Key negotiation completed with c8:e7:d8:1d:1a:e8 [PTK=CCMP GTK=CCMP]  
  8. CTRL-EVENT-CONNECTED - Connection to c8:e7:d8:1d:1a:e8 completed (auth) [id=0 id_str=]  

-Dwext:wext是驅動名稱,wext(Wireless Extensions無線擴充接口)

-iwlan0 :wlan0,網絡接口名稱

-c:指定配置檔案的路徑

7.1 手動設定無線網卡IP和子網路遮罩,實作ping通區域網路内(同一網段)的ip

>: ifconfig wlan0 192.168.1.100 netmask 255.255.255.0     (注意要和WiFi的IP在同一網段,我這裡WiFi是192.168.1.1)

>: ping 192.168.1.1   (wifi的ip)

PING 192.168.1.1 (192.168.1.1): 56 data bytes

64 bytes from 192.168.1.1: seq=2 ttl=64 time=83.188 ms

64 bytes from 192.168.1.1: seq=1 ttl=64 time=1089.456 ms

64 bytes from 192.168.1.1: seq=0 ttl=64 time=2095.726 ms

64 bytes from 192.168.1.1: seq=3 ttl=64 time=43.601 ms

64 bytes from 192.168.1.1: seq=4 ttl=64 time=43.651 ms

64 bytes from 192.168.1.1: seq=5 ttl=64 time=47.849 ms

--- 192.168.1.1 ping statistics ---

6 packets transmitted, 6 packets received, 0% packet loss

round-trip min/avg/max = 43.601/567.245/2095.726 ms

>: ping 192.168.1.105    (Windows的無線網卡ip,前提是關掉防火牆和360)

PING 192.168.1.105 (192.168.1.105): 56 data bytes

64 bytes from 192.168.1.105: seq=0 ttl=128 time=48.168 ms

64 bytes from 192.168.1.105: seq=1 ttl=128 time=45.469 ms

64 bytes from 192.168.1.105: seq=2 ttl=128 time=47.548 ms

64 bytes from 192.168.1.105: seq=3 ttl=128 time=45.971 ms

64 bytes from 192.168.1.105: seq=4 ttl=128 time=52.497 ms

--- 192.168.1.105 ping statistics ---

5 packets transmitted, 5 packets received, 0% packet loss

round-trip min/avg/max = 45.469/47.930/52.497 ms

7.2 添加域名和網關實作ping通外網

在開發闆目錄/etc/建立一個resolv.conf的檔案,因為在核心啟動的時候核心會在resolv.conf檔案中找DNS

>: vi resolv.conf

[html]  view plain  copy

  1. <span style="font-size:18px;">#search localdomain  
  2. nameserver 4.2.2.2  
  3. nameserver 8.8.8.8</span>  

添加網關後試試

>: route add default gw 192.168.1.1

>: ping www.baidu.com

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

64 bytes from 115.239.211.112: seq=0 ttl=48 time=609.658 ms

64 bytes from 115.239.211.112: seq=1 ttl=48 time=326.596 ms

64 bytes from 115.239.211.112: seq=2 ttl=48 time=404.329 ms

64 bytes from 115.239.211.112: seq=3 ttl=48 time=268.019 ms

64 bytes from 115.239.211.112: seq=4 ttl=48 time=281.682 ms 

--- www.baidu.com ping statistics ---

5 packets transmitted, 5 packets received, 0% packet loss

round-trip min/avg/max = 268.019/378.056/609.658 ms

8.自動(DHCP)設定無線網卡,包括無線網卡IP和子網路遮罩以及網關

1)核心部分,

[html]  view plain  copy

  1. <span style="font-size:18px;">Networking --->  
  2.     Networking support     
  3.     Networking options --->   
  4.            Packet socket                 //添加.配置CONFIG_PACKET  
  5.           [ * ]     IP: DHCP support         //添加動态擷取IP  
  6.           [ * ] Network packet filtering (replaces ipchains)</span>  

當然修改之後要重新移植核心

2)busybox部分

進入busybox,make menuconfig

[html]  view plain  copy

  1. <span style="font-size:18px;">[*]udhcp server(udhcpd)  
  2. [*]udhcp client(udhcpc)都選上  
  3. udhcpd就是終端裝置作為DHCP伺服器 ;udhcpc就是終端裝置作為DHCP用戶端  
  4. Networking Utilities --->                                              
  5.  [*] udhcp server (udhcpd)  //生成udhcpc指令 </span>  

從busybox的examples/udhcp/下copy好simple.script檔案到開發闆/usr/share/udhcpc/下,并重命名為default.script.注意更改default.script的權限!

注:(busybox裡面預設的目錄檔案是/usr/share/udhcpc/default.script)

>: chmod a+x default.script

>: wpa_supplicant -Dwext -iwlan0 -c/apps/etc/wireless/wpa_supplicant.conf &

3)動态擷取IP位址:

>: udhcpc -i wlan0

udhcpc (v1.20.2) started

Setting IP address 0.0.0.0 on wlan0

Sending discover...

Sending select for 192.168.1.110...

Lease of 192.168.1.110 obtained, lease time 7200

Setting IP address 192.168.1.110 on wlan0

Deleting routers

route: SIOCDELRT: No such process

Adding router 192.168.1.1

Recreating /etc/resolv.conf

 Adding DNS server 210.42.144.100

 Adding DNS server 210.42.159.2

之後同樣ping 192.168.1.1 ping 192.168.1.105 ping www.baidu.com驗證即可

大緻流程:

(使用者空間)插上rt3070裝置-->(核心空間)找到相關驅動(因為核心裡并沒有具體的rt3070驅動)與之比對 -->/sbin/mdev加載固件(rt2870.bin)到記憶體,并傳輸到裝置上,完成rt3070裝置初始化-->(使用者空間)使能網卡-->(使用者空間)通過wpa_supplicant配置無線網卡-->無線網卡網卡可以正常工作.

繼續閱讀