wpa_cli與wpa_supplicant的交互命令


1)通過adb命令行,可以直接打開supplicant,從而運行wpa_cli,可以解決客戶沒有顯示屏而無法操作WIFI的問題,還可以避免UI的問題帶到driver。進一步來說,可以用在很多沒有鍵盤輸入和LCD輸出的安卓終端產品的操作上。

        wpa_supplicant包含兩個主要的可執行工具:wpa_supplicant和wpa_cli。wpa_supplicant是核心程序,它和wpa_cli的關系就是服務和客戶端的關系:后台運行wpa_supplicant,使用wpa_cli來搜索、設置、和連接網絡。

(2)在wpa_cli交互模式下可以執行很多命令,列表如下:

 

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 (only scans it, doesn‘t display anything)

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 nextsection for a list of parameters

save_config

save_c

saves the configuration

 

(3)平台操作實例(僅限於MTK平台 且具ROOT權限)

 

        A,首先保證ADB連入,且能運行adb remount,這樣避免系統文件只讀。然后設置wpa_cli和wpa_supplicant有較強權限。

        B,運行echo 1 > /dev/wmtWifi,啟動WIFI驅動。但是這個使能不會表現在安卓界面上層,默認是要在啟動安卓時開啟WIFI模塊的,也即設置中的WIFI要默認ON。

        C,進入/system/bin目錄,首先運行服務端wpa_supplicant。

./wpa_supplicant -iwlan0 -Dnl80211 -c/system/etc/wifi/wpa_supplicant.conf

正常啟動后的回顯如下:

技術分享

不可收入態表明該服務端已經在運行了(也可能是可輸入狀態,只要后面的wpa_cali可連接就行)。-i -D -c的參數意義可直接在Help中查詢,具體有些參數可能因平台不同而有差異。

        D,另開啟一個ADB SHELL,作客戶端運行wpa_cali。如下:

cd /system/bin

wpa_cli -p /data/misc/wpa_supplicant

回顯如下說明正常並處於交互模式:

技術分享

      E,執行一系列命令看看

scan

技術分享

scan_results

技術分享

        F,連WIFI的命令行,有以下幾種:

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

     我自己的實驗圖如下:

技術分享

以上過程就說明聯網OK,可以上網了。

 

參考原文:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246100024b8ed7a66471980853a3c50f11e41bca770216c5d61aa9bc98b4addb9922b3bcd7a742613d51742c419de8a1c729f7e875a98ea42b3e1&p=8b2a975bcd8711a052eedb2f4a4c&newp=8b2a971f81822dec08e29e7d495d92695c02dc3051dcd14f2895ff0b&user=baidu&fm=sc&query=adb+shell+wifi&qid=&p1=4

參考原文:http://blog.sina.com.cn/s/blog_55465b470100l73l.html

wpa_cli與wpa_supplicant的交互命令


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM