歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

基於FS2410的wpa_supplicant移植

因為現在的無線wifi網絡大多是wpa加密。所以需要移植wpa_supplicant工具。

一、下載源碼
        http://hostap.epitest.fi/wpa_supplicant/
        下載wpa_supplicant-0.7.3.tar.gz (openssl用到0.7.3提供的補丁)
                #tar xvfz wpa_supplicant-0.7.3.tar.gz
        下載www.openssl.org/source/openssl-0.9.8e.tar.gz
                #tar zxvf openssl-0.9.8e.tar.gz

二、編譯openssl庫
將wpa_supplicant中的補丁拷貝到openssl中
        # cp wpa_supplicant-0.7.3/patches/openssl-0.9.8e-tls-extensions.patch openssl-0.9.8e/
        #cd openssl-0.9.8e
        #mkdir /usr/local/ssl
        #vim Makefile
                CC= arm-linux-gnu-gcc
                AR= arm-linux-gnu-ar $(ARFLAGS) r
                RANLIB= arm-linux-gnu-ranlib
                INSTALLTOP=/usr/local/ssl
                OPENSSLDIR=/usr/local/ssl
        #make
        #make install

在/usr/local/ssl目錄下安裝了ssl庫
 #ls /usr/local/ssl
 #bin  certs  include  lib  man  misc  openssl.cnf  private

後面編譯wpa_supplicant要依賴openssl中的lib和include

三、編譯wpa_supplicant
進入wpa_supplicant-0.7.3.tar.gz解壓生成的wpa_supplicant-0.7.3/wpa_supplicant目錄中:
        #cp defconfig        .config
        #vim .config
                CC= arm-linux-gnu-gcc -L/usr/local/ssl/lib/
                CFLAGS += -I/usr/local/ssl/include/
                LIBS += -L/usr/local/ssl/lib/
        #make

        經過編譯後的wpa_supplicant源程序可以看到兩個主要的可執行工具:wpa_supplicant和wpa_cli。wpa_supplicant是核心程序,它和wpa_cli的關系就是服務和客戶端的關系:後台運行wpa_supplicant,使用wpa_cli來搜索、設置、和連接網絡。

四、配置wpa_supplicant
(1)首先拷貝wpa_supplicant和wpa-psk-tkip.conf到開發板根文件系統中,並改名wpa-psk-tkip.confwpa_supplicant.conf

#cp wpa_supplicant /rootfs/filesystem/bin
#cp wpa_supplicant-0.7.3/wpa_supplicant/examples/wpa-psk-tkip.conf  /rootfs/filesystem/etc/wpa_supplicant.conf

(2)修改wpa_supplicant.conf配置文件
#vim /rootfs/filesystem/etc/wpa_supplicant.conf

修改內容如下:

# WPA-PSK/TKIP

ctrl_interface=/var/run/wpa_supplicant

network={
                ssid="FS2410"     //填寫無線網絡的的用戶名
                key_mgmt=WPA-PSK
                proto=WPA
                pairwise=TKIP
                group=TKIP
                psk="1234567890" //填寫密碼
}

五、測試
(1)在開發板終端:

#mkdir –p /var/run/wpa_supplicant

(2)編寫驅動加載腳本
#vim load.sh (我放在根文件系統/sdio目錄中,內容如下:)

#!/bin/sh
cd /sdio
insmod libertas.ko
insmod libertas_sdio.ko helper_name=/lib/firmware/mrvl/helper_sd.bin fw_name=/lib/firmware/mrvl/sd8686.bin

並修改load.sh權限:chmod 777 load.sh

(3)加載驅動
在開發板終端進入/sdio目錄,執行./load.sh加載驅動
#cd /sdio
#./load.sh
驅動加載完成會提示:(如果沒有,則再次熱插拔你的sdio wifi卡便可以看到)
libertas_sdio: Libertas SDIO driver
libertas_sdio: Copyright Pierre Ossman
libertas: 00:0b:6c:89:62:4b, fw 9.70.3p23, cap 0x00000303
libertas: unidentified region code; using the default (USA)
libertas: wlan0: Marvell WLAN 802.11 adapter


ifconfig -a查看是否創建wlan0這個節點。
分配IP地址:
#ifconfig wlan0 192.168.1.5  //也可以動態分配 dhclient wlan0 不過你得移植dhcp

(4)創建連接暗文密碼(PSK密碼),通過明碼轉換
#cd /etc
#wpa_passphrase FS2410 1234567890 >> wpa_supplicant.conf
此時將在wpa_supplicant.conf文件中生成:
network={
      ssid="FS2410"
      #psk="1234567890"
      psk=4b2bc7cbb3710e9ea43f09e8d57e8bdb3b2a2127af44960d73216c3612f6baba
}

(5)然後修改wpa_supplicant.conf配置文件,把 psk="1234567890" 這一行明文密碼改成生成的暗文密碼,即:
        psk=4b2bc7cbb3710e9ea43f09e8d57e8bdb3b2a2127af44960d73216c3612f6baba
其它生成的多余信息刪除,最後wpa_supplicant.conf文件如下:

# WPA-PSK/TKIP

ctrl_interface=/var/run/wpa_supplicant

network={
           ssid="FS2410"     //填寫無線網絡的的用戶名
           key_mgmt=WPA-PSK
           proto=WPA
           pairwise=TKIP
           group=TKIP         
           psk=4b2bc7cbb3710e9ea43f09e8d57e8bdb3b2a2127af44960d73216c3612f6baba
}


(6)連接AP
在開發板終端輸入wpa_supplicant回車,會顯示幫助信息,最後有個:
example:
      wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
拷貝example用法,執行:
# wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf &(需要一直放在後台運行)
打印信息有:
Trying to associate with 00:26:f2:0d:5a:c4 (SSID='FS2410' freq=2412 MHz)
Associated with 00:23:68:28:4e:a8
CTRL-EVENT-DISCONNECTED bssid=00:23:68:28:4e:a8 reason=0
Associated with 00:26:f2:0d:5a:c4
WPA: Key negotiation completed with 00:26:f2:0d:5a:c4 [PTK=TKIP GTK=TKIP]
CTRL-EVENT-CONNECTED - Connection to 00:26:f2:0d:5a:c4 completed (auth) [id=0 id_str=]
……
再ping下網關,是否連接成功:
#ping 192.168.1.1

3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 17.627/20.023/24.631 ms
……

無線網卡連接成功!

Copyright © Linux教程網 All Rights Reserved