通过命令行打开wifi,打开supplicant,从而运行wpa_cli,
可以解决客户没有显示屏而无法操作WIFI的问题,
还可以避免UI的问题带到driver
[SOLUTION]
1 ICS2及以前版本
打开wifi:
#adb shell
#cd /sys/class/rfkill/rfkill1/
#cat type #输出值如果为wlan,则直接下一步,否则进入rfkill0,然后执行下一步
#echo 1>state
关闭wifi:
前面一样
#echo 0>state
如果要执行具体的命令,比如扫描,连接等,那么就需要wpa_cli工具,但是该工具是建立在supplicant启动基础上的,而supplicant的执行又建立在wifi加载的基础上。
打开supplicant:
#adb shell
#cd system/bin/
#./wpa_supplicant -Dwext -iwlan0 -c /data/misc/wifi/wpa_supplicant.conf
(如果配置文件不在上述目录,请使用这个路径:/system/etc/wifi/wpa_supplicant.conf)
(上述命令执行后会阻塞在命令行,如果要执行其他命令,请另开一个命令行界面)
( 判断 wifi 或者 supplicant 是否运行起来,可以通过 ps 命令查看是否有 tx_thread 和 ./wpa_supplicant 进程 )
运行wpa_cli:
#adb shell
#wpa_cli
(如果上面命令不成功,请执行:wpa_cli –p /data/misc/wpa_supplicant)
接着就可以执行各种命令了,可以使用h参数查看wpa_cli有哪些命令可用,
比如有scan,scan_results等
============================================================
2 JB版本
1. 启动wifi driver
echo 1 > /dev/wmtWifi
2. 启动supplicant
cd /system/bin
./wpa_supplicant -iwlan0 -Dnl80211 -c/system/etc/wifi/wpa_supplicant.conf
3. 启动wpa_cli
cd /system/bin
wpa_cli -p /data/misc/wpa_supplicant
启动以后可以通过help获得帮助信息。
3 JB2版本
1. 启动wifi driver
echo 1 > /dev/wmtWifi
2. 启动supplicant
cd /system/bin
iwpriv wlan0 set_p2p_mode 0 0
iwpriv wlan0 set_p2p_mode 10
./wpa_supplicant -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf -N -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf
3. 启动wpa_cli
cd /system/bin
wpa_cli -p /data/misc/wpa_supplicant
启动以后可以通过help获得帮助信息。
4. 常用命令
关于wpa_cli的使用网上有很多文档(搜索wpa_cli即可获得)。
some common command:
> scan = to scan the neighboring AP
> scan_results = show the scan results
> status = check out the current connection information
> terminate = terminate wpa_supplicant
> quit = exit wpa_cli
> add_network = it will return a network id to you
> set_network <network id> <variable> <value> = set network variables (shows list of variables when run without arguments), success will return OK, or will return Fail
> select_network <network id> = select a network (disable others)
> disable_network <network id> = disable a network
> enable_network <network id> = enable a network
> set_network 0 priority 0
> list_network
> save_config
Full command | Short command | Description |
status | stat | displays the current connection status |
disconnect | disc | prevents wpa_supplicant from connecting to any access point |
quit | q | exits wpa_cli |
terminate | term | kills wpa_supplicant |
reconfigure | recon | reloads wpa_supplicant with the configuration file supplied (-c parameter) |
scan | scan | scans for available access points (on |
scan_result | scan_r | displays the results of the last scan |
list_networks | list_n | displays a list of configured networks and their status (active or not, enabled or disabled) |
select_network | select_n | select a network among those defined to initiate a connection (ie select_network 0) |
enable_network | enable_n | makes a configured network available for selection (ie enable_network 0) |
disable_network | disable_n | makes a configured network unavailable for selection (ie disable_network 0) |
remove_network | remove_n | removes a network and its configuration from the list (ie remove_network 0) |
add_network | add_n | adds a new network to the list. Its id will be created automatically |
set_network | set_n | shows a very short list of available options to configure a network when supplied with no parameters. See next section for a list of extremely useful parameters to be used with set_network and get_network. |
get_network | get_n | displays the required parameter for the specified network. See next section for a list of parameters |
save_config | save_c | saves the configuration |
5. 运用举例
for AP that doesn`t have encryption
> add_network (It will display a network id for you, assume it returns 0)
> set_network 0 ssid “666”
>set_network 0 key_mgmt NONE
> enable_network 0
> quit
for AP that has WEP
> add_network (assume returns 1)
> set_network 1 ssid “666”
>set_network 1 key_mgmt NONE
> set_network 1 wep_key0 “your ap passwork”(if usting ASCII, it need double quotation marks, if using hex, then don`t need the double quotation marks)
> set_network 1 wep_tx_keyidx 0
> select_network 1 (optional, remember, if you are connecting with another AP, you should select it to disable the another)
> enable_network 1
for AP that has WPA-PSK/WPA2-PSK
> add_network (assume returns 2)
> set_network 2 ssid “666”
>set_network 2 psk “your pre-shared key”
>select_network 2 (optional, remember, if you are connecting with another AP, you should select it to disable the another)
> enable_network 2