wpa_supplicant, wpa_cli用法

        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

root@android:/ # wpa_supplicant -Dwext -iwlan0 -C/data/system/wpa_supplicant -c/data/misc/wifi/wpa_supplicant.conf &  

然后ps|grep wpa看看有没有起来,在wifi工作过程中,这个进程要始终都在的。

        接着启动客户端wpa_cli进行配置并连接wifi热点

130|root@android:/ # wpa_cli -p/data/system/wpa_supplicant -iwlan0
wpa_cli v0.8.x
Copyright (c) 2004-2011, Jouni Malinen and contributors


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地址

root@android:/ # 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
root@android:/ # 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)


这样就完成了。可以上网了。























































































































































































































 CTRL-A Z for help |115200 8N1 | NOR | Minicom 2.5    | VT102 |      Offline                                                                                                                              




























































































































dhcpcd[1382]: wlan0: ignoring offer of 192.168.1.100 from 192.168.1.1 `�'
dhcpcd[1382]: wlan0: NAK: via 192.168.1.1
dhcpcd[1382]: wlan0: broadcasting for a lease
dhcpcd[1382]: wlan0: offered 10.12.3.223 from 10.12.3.254
dhcpcd[1382]: wlan0: ignoring offer of 192.168.1.100 from 192.168.1.1 `�'
dhcpcd[1382]: timed out
dhcpcd[1382]: allowing 8 seconds for IPv4LL timeout
dhcpcd[1382]: wlan0: NAK: via 192.168.1.1
dhcpcd[1382]: wlan0: broadcasting for a lease
dhcpcd[1382]: wlan0: offered 10.12.3.223 from 10.12.3.254
dhcpcd[1382]: wlan0: NAK: via 192.168.1.1


dhcpcd[1382]: wlan0: broadcasting for a lease
dhcpcd[1382]: wlan0: offered 10.12.3.223 from 10.12.3.254
dhcpcd[1382]: wlan0: NAK: via 192.168.1.1
dhcpcd[1382]: wlan0: broadcasting for a lease
dhcpcd[1382]: wlan0: offered 10.12.3.223 from 10.12.3.254
dhcpcd[1382]: wlan0: NAK: via 192.168.1.1
dhcpcd[1382]: timed out
1|root@android:/ # 
1|root@android:/ # 
1|root@android:/ # 









你可能感兴趣的:(Application)