開發環境:fl2440開發板,linux3.0內核,交叉編譯器路徑/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-,無線網卡RT3070linux
平時開發板聯網都須要接一根網線,十分不方便,因而想到能夠添加wifi功能。下面詳細說明整個開發流程。git
一.配置linux內核支持wireless無線上網算法
[*] Networking support ---> vim
-*- Wireless --->centos
<*> cfg80211 - wireless configuration API網絡
[ ] nl80211 testmode commandsession
[ ] enable developer warningsapp
[ ] cfg80211 regulatory debuggingless
[*] enable powersave by defaultsocket
[ ] use statically compiled regulatory rules database
[ ] cfg80211 wireless extensions compatibility
<*> Common routines for IEEE802.11 drivers
[ ] lib80211 debugging messages
<*> Generic IEEE 802.11 Networking Stack (mac80211)
[ ] PID controller based rate control algorithm
[*] Minstrel
[*] Minstrel 802.11n support
Default rate control algorithm (Minstrel) --->
[ ] Enable mac80211 mesh networking (pre-802.11s) support
[ ] 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
[*] Network device support --->
[*] Wireless LAN --->
<*> Ralink driver support --->
--- Ralink driver support
< > Ralink rt2500 (USB) support
< > Ralink rt2501/rt73 (USB) support
<*> Ralink rt27xx/rt28xx/rt30xx (USB) support //由於咱們用的是RT3070,因此選擇這個選項,之後大家用其餘芯片的話,就選擇其餘選項
[ ] 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
二.RT3070無線模塊驅動移植到開發板
1.下載wireless_tools固件
下載地址:http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/
若是連接失效了,能夠本身百度下載
2.解壓wireless_tools安裝包,並修改makefile
[weishusheng@localhost wifi]$ tar -zxf wireless_tools.29.tar.gz
[weishusheng@localhost wifi]$ cd wireless_tools.29
[weishusheng@localhost wireless_tools.29]$ vim Makefile
添加本身的交叉編譯器路徑和交叉編譯器的庫,這些工具的編譯能夠先在本身的虛擬機或者PC上編譯,將編譯生成的可執行文件拷貝到開發板的相應目錄下!
修改以下:( 紅色部分爲修改部分)
## Compiler to use (modify this for cross compile).
CC = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
## Other tools you need to modify for cross compile (static lib only).
AR = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar
RANLIB = /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib
3.編譯wireless_tools安裝包,生成iwconfig、iwpriv、 iwevent、libiw.so.29等文件
[weishusheng@localhost wireless_tools.29]$ make
。。。
[weishusheng@localhost wireless_tools.29]$ ls
4. 將iwconfig, iwpriv, iwevent、iwspy拷貝到開發板的bin目錄下,將libiw.so.29拷貝到開發板的/lib下:(用tftp傳送文件,這裏不在贅述)
如下是我拷貝完畢後查看相應安裝包的結果:
修改他們的權限
>: chmod 777 iw* libiw.so.29
wpa_supplicant本是開源項目源碼,被谷歌修改後加入Android移動平臺,它主要是用來支持WEP,WPA/WPA2和WAPI無線協議和加密認證的,而實際上的工做內容是經過socket(不論是wpa_supplicant與上層仍是 wpa_supplicant與驅動都採用socket通信)與驅動交互上報數據給用戶,而用戶能夠經過socket發送命令給wpa_supplicant調動驅動來對WiFi芯片操做。 簡單的說,wpa_supplicant就是WiFi驅動和用戶的中轉站外加對協議和加密認證的支持。
1.下載後解壓wpa_supplicant壓縮包文件:
[weishusheng@localhost wifi]$ tar -zxf wpa_supplicant-0.7.3.tar.gz
1.下載地址:http://www.openssl.org/source/ openssl-0.9.8i.tar.gz
我以前用上面的連接下載的時候,這個連接已經失效了,你們能夠百度openssl-0.9.8i進行下載,我最後是在CSDN上花積分下載的
在編譯openssl-0.9.8i數據包前,須要用到wpa_supplicant的一個補丁,因此將wpa_supplicant-0.7.3的patches拷貝到openssl數據包的patch目錄下,這裏能夠本身建立一個install目錄和patch目錄,install目錄用來存放編譯openssl-0.9.8i時生成的可執行文件,patch目錄用來存放wpa_supplicant-0.7.3的patches補丁,具體操做以下:
[weishusheng@localhost openssl-0.9.8i]$ mkdir install patch
2.將wpa_supplicant中的補丁拷貝到openssl中:
[weishusheng@localhost wifi]$ cd wpa_supplicant-0.7.3
[weishusheng@localhost wpa_supplicant-0.7.3]$ ls
COPYING patches README src wpa_supplicant
[weishusheng@localhost wpa_supplicant-0.7.3]$ cd patches/
[weishusheng@localhost patches]$ ls
openssl-0.9.8d-tls-extensions.patch openssl-0.9.8i-tls-extensions.patch
openssl-0.9.8e-tls-extensions.patch openssl-0.9.8-tls-extensions.patch
openssl-0.9.8g-tls-extensions.patch openssl-0.9.9-session-ticket.patch
openssl-0.9.8h-tls-extensions.patch
[weishusheng@localhost patches]$ cp openssl-0.9.8i-tls-extensions.patch /home/weishusheng/modules/wifi/openssl-0.9.8i/patch
3.修改openssl-0.9.8i目錄下的makefile以下:
CC= /opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-gcc
AR=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ar $(ARFLAGS) r
RANLIB= /opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-ranlib
添加編譯後可執行文件的存放目錄,這個目錄的設置不惟一,你能夠本身選擇存放路徑,紅色部分爲要修改的部分,修改爲你本身的目錄:
# INSTALL_PREFIX is for package builders so that they can configure
# for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
# Normally it is left empty.
INSTALL_PREFIX=
INSTALLTOP=/home/weishusheng/modules/wifi/openssl-0.9.8i/install //29行
# Do not edit this manually. Use Configure --openssldir=DIR do change this!
OPENSSLDIR=/home/weishusheng/modules/wifi/openssl-0.9.8i/install //32行
4.編譯安裝openssl-0.9.8i
[skyyang@centos6 openssl-0.9.8x]$ make && make install
5.編譯經過後,能夠看到install目錄下生成了不少文件
[weishusheng@localhost openssl-0.9.8i]$ ls install/lib/
engines libcrypto.a libssl.a pkgconfig
6.拷貝libcrypto.a libssl.a到開發板的/lib下
[weishusheng@localhost wifi]$ cd wpa_supplicant-0.7.3
[weishusheng@localhost wpa_supplicant-0.7.3]$ ls
COPYING patches README src wpa_supplicant
[weishusheng@localhost wpa_supplicant-0.7.3]$ cd wpa_supplicant/
1.複製defconfig 更名爲.config,並修改以下:
[weishusheng@localhost wpa_supplicant]$ cp defconfig .config
[weishusheng@localhost wpa_supplicant]$ vim .config
27 #CC=/opt/brcm/hndtools-mipsel-uclibc/bin/mipsel-uclibc-gcc
28 CC=/opt/buildroot-2011.11/arm920t/usr/bin/arm-linux-gcc -L/home/weishusheng/modules/wifi/openssl-
0.9.8i/install/lib
29 #CFLAGS += -Os
30 CFLAGS += -I/home/weishusheng/modules/wifi/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/weishusheng/modules/wifi/openssl-0.9.8i/install/lib
2.編譯wpa_supplicant
[weishusheng@localhost wpa_supplicant]$ make
[weishusheng@localhost wpa_supplicant]$ ls
3.將wpa_cli,wpa_supplicant,wpa_passphrase拷貝到開發板的bin目錄下:
~ # ls bin/
1.使用wpa_passphrase建立wpa_supplicant的配置文件,使用加密後的密碼,不用明文。固然使用明文密碼也能夠鏈接到無線路由器:
如下命令是在開發板上進行的操做:
/apps/wireless # wpa_passphrase CMCC 9b4019b401 >> wpa_supplicant.conf
/apps/wireless # cat wpa_supplicant.conf
2.修改wpa_supplicant.conf配置文件,添加密碼加密算法和使用明文密碼:
>: vi wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="Router_LingYun"
key_mgmt=WPA-PSK
#proto=WPA
#psk="lingyun-emb"
proto=WPA2
pairwise=TKIP CCMP
group=TKIP CCMP
psk="lingyun-emb"
#psk=20a17fe2e0482c0db4e4dcf6c4494cebbd88ae4f166015115ca83ce9022b8cd2
}
2.4.2 使能RT3070無線網卡模塊
>: ifconfig wlan0 up
一般狀況下,load firmware的動做是經過用戶空間的hotplug handler,也就是/proc/sys/kernel/hotplug裏設定的執行檔,來完成。root_qtopia默認會在/etc/init.d/rcS裏將/proc/sys/kernel/hotplug設定爲/sbin/mdev,即busybox的mdev模塊。它在收到來自內核的請求加載rt3070.bin這個firmware消息後,會從/lib/firmware目錄下去找rt3070.bin,若是能找到就加載。
具體解釋看這個連接:
http://www.linuxidc.com/Linux/2012-01/50806.htm
可是那時候我按照這個連接上的方法作了,仍是不行,後來找了其餘博客,說是要移植RT2870和RT3070這兩個系統固件,纔可使能無線網卡!因而我到官網去下載了這兩個固件:(其實咱們用的是RT3070,因此只須要加載RT3070.bin文件就好了)
[weishusheng@localhost ~]$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git
[weishusheng@localhost ~]$ cd linux-firmware/
將RT3070.bin固件下載到開發板的/lib/firmware目錄下:
/lib >: mkdir -p /lib/firmware
/lib >: cd firmware/
/lib/firmware >: tget rt3070.bin
Rt3070.bin 100% |*******************************| 8192 0:00:00 ETA
>: ifconfig wlan0 up
>: ifconfig
eth0 Link encap:Ethernet HWaddr FA:BF:B1:79:4B:F5
inet addr:192.168.1.23 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2838 errors:0 dropped:0 overruns:0 frame:0
TX packets:1544 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1768351 (1.6 MiB) TX bytes:243628 (237.9 KiB)
Interrupt:51 Base address:0x2300
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 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:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 00:24:25:50:A9:4D
UP 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)
>:
咱們注意到當你第一次使能無線網卡的時候,你只是使能了它,可是這張網卡的參數還未配置,尚未IP,因此如今仍是不能上網,要配置網卡參數、鏈接路由器以後才能上網!
1.啓動命令:
~#wpa_supplicant -B -Dwext -iwlan0 -c/apps/wireless/wpa_supplicant.conf -d
-d :增長調試信息
-D :驅動名稱,無線網卡爲wext
-i :網絡接口名稱,這裏無線爲wlan0
-B:後臺守護進程
-c:指定配置文件
2.配置無線網卡IP和子網掩碼:
>: ifconfig wlan0 192.168.1.244 broadcast 192.168.1.1 netmask 255.255.255.0 up
3.測試開發板是否能夠無線上網:
>: ifconfig eth0 down
>: ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 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:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
wlan0 Link encap:Ethernet HWaddr 00:24:25:50:A9:4D
inet addr:192.168.1.244 Bcast:192.168.1.1 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:499 errors:0 dropped:147 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:50920 (49.7 KiB) TX bytes:2916 (2.8 KiB)
>: ping 192.168.1.3
看到了沒,能夠上網了!若是你想上外網,那麼就要給開發板添加DNS域名解析服務!還有添加默認網關!
此時咱們把開發板上的網線拔了依舊能夠上網ping通。