Android:使用wpa_supplicant和dhcpd簡單測試wifi
原文: http://blog.csdn.net/laojing123/article/details/7719132
Android系統中對於WIFI的設定整合到了“設定”中,其實跟手動設定差不多。這裡介紹下如何手動連線WIFI,以方便以後除錯WIFI。
第一步要做的就是要載入WIFI模組驅動了。當然如果你的WIFI是編譯到核心裡面的,就不需要的。我們的WIFI晶片用的是BCM4330,編譯為模組。
insmod /system/lib/modules/kernel/drivers/net/wireless/bcm4330/bcm4330.ko firmware_path=/system/vendor/firmware/bcm4330.bin \ nvram_path=/system/vendor/firmware/nvram.txt
這樣驅動模組載入後,需要啟動wpa_supplicant
[email protected]:/ # wpa_supplicant -Dwext -iwlan0 -C/data/system/wpa_supplicant -c/data/misc/wifi/wpa_supplicant.conf &
然後ps|grep wpa看看有沒有起來,在wifi工作過程中,這個程序要始終都在的。
接著啟動客戶端wpa_cli進行配置並連線wifi熱點
130|[email protected]:/ # wpa_cli -p/data/system/wpa_supplicant -iwlan0
wpa_cli v0.8.x
Copyright (c) 2004-2011, Jouni Malinen <
This program is free software. You can distribute it and/or modify it
under the terms of the GNU General Public License version 2.
Alternatively, this software may be distributed under the terms of the
BSD license. See README and COPYING for more details.
Interactive mode
>
其中/data/system/wpa_supplicant 是剛剛啟動wpa_supplicant的時候建立的一個套接字
接著進行搜尋wifi
> scan
OK
<3>CTRL-EVENT-SCAN-RESULTS
檢視搜到的有哪些熱點
> scan_result
bssid / frequency / signal level / flags / ssid
40:16:9f:67:0f:00 2462 -42 [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][WPS][ESS] HHCN-NET
b0:48:7a:49:44:68 2437 -58 [WPA2-PSK-CCMP][WPS][ESS] HHTech.Arch
e0:05:c5:97:d8:5a 2412 -71 [WPA-PSK-CCMP][WPA2-PSK-CCMP-preauth][ESS] 1103-5
40:16:9f:67:0c:a6 2412 -74 [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][WPS][ESS] hardware
b0:48:7a:49:65:54 2437 -58 [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS] Dept_driver
接著設定wifi,就連線Dept_driver這個熱點吧
> add_net
3
> set_net 3 ssid "Dept_driver"
OK
Dept_driver的加密方式是WPA2-PSK
> set_net 3 psk "password"
OK
> select_net 3
OK
<3>CTRL-EVENT-STATE-CHANGE id=0 state=0 BSSID=00:00:00:00:0[ 2752.332061] dhd_aoe_hostip_clr failed code -23
0:00
<3>CTR[ 2752.337768] dhd_aoe_arp_clr failed code 1
L-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00
<3>CTRL-EVENT-DISCONNECTED bssid=00:00:00:00:00:00 reason=0
<3>CTRL-EVENT-STATE-CHANGE id=-1 state=0 BSSID=00:00:00:00:00:00
<3>CTRL-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>Trying to associate with b0:48:7a:49:65:54 (SSID='Dept_driver' freq=2437 MHz)
<3>CTRL-EVENT-STATE-CHANGE id=-1 state=5 BSSID=b0:48:7a:49:65:54
[ 2753.153717] wl_iw_set_essid: join SSID=Dept_driver ch=6
<3>CTRL-EVENT-STATE-CHANGE id=3 state=6 BSSID=b0:48:7a:49:65:54
<3>Associated with b0:48:7a:49:65:54
<3>CTRL-EVENT-STATE-CHANGE id=3 state=7 BSSID=00:00:00:00:00:00
<3>CTRL-EVENT-STATE-CHANGE id=3 state=8 BSSID=00:00:00:00:00:00
<3>WPA: Key negotiation completed with b0:48:7a:49:65:54 [PTK=CCMP GTK=CCMP]
<3>CTRL-EVENT-CONNECTED - Connection to b0:48:7a:49:65:54 completed (reauth) [id=3 id_str=]
<3>CTRL-EVENT-STATE-CHANGE id=3 state=9 BSSID=00:00:00:00:00:00
> enable_net 3
OK
> q
這樣,就都設定好了,接著用dhcpd分配一個IP地址
[email protected]:/ # dhcpcd wlan0
dhcpcd[3940]: version 5.2.10 starting
dhcpcd[3940]: host does not support a monotonic clock - timing can skew
dhcpcd[3940]: wlan0: rebinding lease of 192.168.1.216
dhcpcd[3940]: wlan0: acknowledged 192.168.1.216 from 192.168.1.1 `�'
dhcpcd[3940]: wlan0: leased 192.168.1.216 for 7200 seconds
dhcpcd[3940]: forked to background, child pid 3971
[email protected]:/ # busybox ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr AC:E8:7B:89:D3:C0
inet addr:192.168.1.216 Bcast:255.255.255.255 Mask:255.255.255.0
inet6 addr: fe80::aee8:7bff:fe89:d3c0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6637 errors:0 dropped:25 overruns:0 frame:0
TX packets:4357 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3825961 (3.6 MiB) TX bytes:704832 (688.3 KiB)
這樣就完成了。可以上網了。