通过命令行打开wifi,打开supplicant,从而运行wpa_cli,
可以解决客户没有显示屏而无法操作WIFI的问题,
还可以避免UI的问题带到driver
打开wifi:
#adb shell
#cd /sys/class/rfkill/rfkill1/
#cat type #输出值如果为wlan,则直接下一步,否则进入rfkill0,然后执行下一步
#echo 1 > state
关闭wifi:
同理,如果wifi已经打开,关闭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
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