原文:https://blog.csdn.net/hanlunko2016/article/details/81276248
一. Wpa_supplicant 启动脚本:
wpa_supplicant -Dnl80211 -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf -O/data/misc/wifi/sockets
二. Wpa_cli 启动:
wpa_cli是命令行界面下的无线网连接工具,在wpa_supplicant运行的基础上,打开wpa_cli:
wpa_cli -iwlan0 -p/data/misc/wifi/sockets
三. wpa_cli 整套指令如下:
root@:/system/bin # wpa_cli -iwlan0 -p/data/misc/wifi/sockets
wpa_cli v2.5-devel-6.0
Copyright (c) 2004-2015, Jouni Malinen
This software may be distributed under the terms of the BSD license.
See README for more details.
Interactive mode
> help
commands:
status [verbose] = get current WPA/EAPOL/EAP status
ifname = get current interface name
ping = pings wpa_supplicant
relog = re-open log-file (allow rolling logs)
note
mib = get MIB variables (dot1x, dot11)
help [command] = show usage help
interface [ifname] = show interfaces/select interface
level
license = show full wpa_cli license
quit = exit wpa_cli
set = set variables (shows list of variables when run without arguments)
dump = dump config variables
get
logon = IEEE 802.1X EAPOL state machine logon
logoff = IEEE 802.1X EAPOL state machine logoff
pmksa = show PMKSA cache
pmksa_flush = flush PMKSA cache entries
reassociate = force reassociation
reattach = force reassociation back to the same BSS
preauthenticate
identity
password
new_password
pin
otp
passphrase
for an SSID
sim
bssid
blacklist
blacklist clear = clear the blacklist
blacklist = display the blacklist
log_level
log_level = display the current log level and log options
list_networks = list configured networks
select_network
enable_network
disable_network
add_network = add a network
remove_network
set_network
list of variables when run without arguments)
get_network
dup_network
list_creds = list configured credentials
add_cred = add a credential
remove_cred
set_cred
get_cred
save_config = save the current configuration
disconnect = disconnect and wait for reassociate/reconnect command before
connecting
reconnect = like reassociate, but only takes effect if already disconnected
scan = request new BSS scan
scan_results = get latest scan results
bss <
get_capability
reconfigure = force wpa_supplicant to re-read its configuration file
terminate = terminate wpa_supplicant
interface_add
are optional
interface_remove
interface_list = list available interfaces
ap_scan
scan_interval
bss_expire_age
bss_expire_count
bss_flush
stkstart
ft_ds
wps_pbc [BSSID] = start Wi-Fi Protected Setup: Push Button Configuration
wps_pin
wps_check_pin
wps_cancel Cancels the pending WPS operation
wps_nfc [BSSID] = start Wi-Fi Protected Setup: NFC
wps_nfc_config_token
wps_nfc_token
wps_nfc_tag_read
nfc_get_handover_req
nfc_get_handover_sel
nfc_report_handover
wps_reg
wps_ap_pin [params..] = enable/disable AP PIN
wps_er_start [IP address] = start Wi-Fi Protected Setup External Registrar
wps_er_stop = stop Wi-Fi Protected Setup External Registrar
wps_er_pin
wps_er_pbc
wps_er_learn
wps_er_set_config
wps_er_config
wps_er_nfc_config_token
ibss_rsn
sta
all_sta = get information about all associated stations (AP)
deauthenticate
disassociate
chan_switch
suspend = notification of suspend/hibernate
resume = notification of resume/thaw
roam
p2p_find [timeout] [type=*] = find P2P Devices for up-to timeout seconds
p2p_stop_find = stop P2P Devices search
p2p_asp_provision
p2p_asp_provision_resp
p2p_connect
p2p_listen [timeout] = listen for P2P Devices for up-to timeout seconds
p2p_group_remove
p2p_group_add [ht40] = add a new P2P group (local end as GO)
p2p_prov_disc
p2p_get_passphrase = get the passphrase for a group (GO only)
p2p_serv_disc_req
p2p_serv_disc_cancel_req
p2p_serv_disc_resp
p2p_service_update = indicate change in local services
p2p_serv_disc_external
p2p_service_flush = remove all stored service entries
p2p_service_add
p2p_service_rep asp
p2p_service_del
p2p_reject
p2p_invite
p2p_peers [discovered] = list known (optionally, only fully discovered) P2P peers
p2p_peer
= show information about known P2P peer p2p_set
p2p_flush = flush P2P state
p2p_cancel = cancel P2P group formation
p2p_unauthorize
= unauthorize a peer p2p_presence_req [
p2p_ext_listen [
p2p_remove_client
= remove a peer from all groups wfd_subelem_set
wfd_subelem_get
fetch_anqp = fetch ANQP information for all APs
stop_fetch_anqp = stop fetch_anqp operation
interworking_select [auto] = perform Interworking network selection
interworking_connect
interworking_add_network
anqp_get
gas_request
gas_response_get
hs20_anqp_get
nai_home_realm_list
hs20_icon_request
fetch_osu = fetch OSU provider information from all APs
cancel_fetch_osu = cancel fetch_osu command
sta_autoconnect <0/1> = disable/enable automatic reconnection
tdls_discover
tdls_setup
tdls_teardown
tdls_link_status
wmm_ac_addts
wmm_ac_delts
wmm_ac_status = show status for Wireless Multi-Media Admission-Control
tdls_chan_switch
tdls_cancel_chan_switch
signal_poll = get signal parameters
pktcnt_poll = get TX/RX packet counters
reauthenticate = trigger IEEE 802.1X/EAPOL reauthentication
wnm_sleep
wnm_bss_query
raw
flush = flush wpa_supplicant state
driver
radio_work = radio_work
vendor
neighbor_rep_request [ssid=
erp_flush = flush ERP keys
mac_rand_scan
>
常用的指令如下:
1. 打开debug log : wpa_cli -iwlan0 -p/data/misc/wifi/sockets log_level debug
2. scan:打开后扫描AP
3. scan_results:显示扫描结果
4. status:列出目前的联网状态。
5. ist_networks:列出所有备选网络。目前正连接到的网络会标[CURRENT],禁用的网络会标[DISABLE]。
6. add_network:增加一个备选网络,输出新网络的号码(这个号码替代下文的[network_id])。注意新网络此时是禁用状态。
7. set_network [network_id] ssid “Your SSID”:设置无线网的名称(SSID)
8. set_network [network_id] key_mgmt WPA-PSK:设置无线网的加密方式为WPA-PSK/WPA2-PSK
9. set_network [network_id] psk “Your Password”:设置无线网的PSK密码
10. enable_network [network_id]:启用网络。启用后如果系统搜索到了这个网络,就会尝试连接。
11. disable_network [network_id]:禁用网络。
12. save_config:保存配置。
e.g.
>add_network
0<--- 新网络的号码
>set_network 0 ssid "TP-LINK_HyFi_75"
ok
>set_network 0 key_mgmt WPA-PSK
ok
>set_network 0 psk "147258369"
ok
>enable_network 0
ok
>save_config<--------别忘了这个,否则重启之后网络配置可能丢失
ok
四. demo
wpa_supplicant log:
wlan0: Control interface command 'SCAN TYPE=ONLY' //scan
wlan0: Control interface command 'ADD_NETWORK' //add_network x : 增加一个备选网络,输出新网络的号码(这个号码替代下文的[network_id])。注意新网络此时是禁用状态
CTRL_IFACE: ADD_NETWORK
wlan0: Control interface command 'SET_NETWORK [REMOVED]' //set_network [network_id] ssid “Your SSID”:设置无线网的名称(SSID)
CTRL_IFACE: SET_NETWORK id=0 name='ssid'
ssid - hexdump(len=15): 54 50 2d 4c 49 4e 4b 5f 5a 48 45 4e 32 2e 34
wlan0: Control interface command 'SET_NETWORK [REMOVED]' //set_network [network_id] key_mgmt WPA-PSK:设置无线网的加密方式为WPA-PSK/WPA2-PSK
CTRL_IFACE: SET_NETWORK id=0 name='key_mgmt'
key_mgmt: 0x4
wlan0: Control interface command 'SET_NETWORK [REMOVED]' //set_network [network_id] priority x:设置network 的优先级
CTRL_IFACE: SET_NETWORK id=0 name='priority'
priority=0 (0x0)
wlan0: Control interface command 'ENABLE_NETWORK 0' //enable_network [network_id]:启用网络。启用后如果系统搜索到了这个网络,就会尝试连接
CTRL_IFACE: ENABLE_NETWORK id=0
wlan0: Control interface command 'SELECT_NETWORK 0' //select_network [networi_id]: 选择network进行连接
CTRL_IFACE: SELECT_NETWORK id=0
Fast associate: Old scan results
wlan0: Setting scan request: 0.000000 sec
wlan0: Control interface command 'RECONNECT' // reconnect : like reassociate, but only takes effect if already disconnected
实操:
> scan
OK
<3>CTRL-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00 SSID=
<3>CTRL-EVENT-SCAN-STARTED
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>CTRL-EVENT-STATE-CHANGE id=-1 state=2 BSSID=00:00:00:00:00:00 SSID=
<3>CTRL-EVENT-NETWORK-NOT-FOUND
>
> scan_results
bssid / frequency / signal level / flags / ssid
04:a1:51:8a:9c:ae 5745 -53 [WPA2-PSK-CCMP][WPS][ESS] NETGEAR-63-5G
8c:be:be:2d:3f:28 5785 -60 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] XIaomi_5G
50:bd:5f:15:36:18 5785 -63 [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS] TP-LINK_ZHEN_5G
ec:26:ca:3a:fa:ba 5745 -68 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] Lw_5G
50:bd:5f:15:36:19 2442 -53 [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS] TP-LINK_ZHEN_2.4G
8c:be:be:2d:3f:27 2437 -55 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] Xiaomi_2.4G
80:89:17:ab:c0:7f 2437 -62 [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS] sa10
ec:26:ca:87:83:02 2437 -64 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] TP-LINK_8302
ec:26:ca:3a:fa:bb 2422 -65 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS] Lw_24G
80:89:17:ab:c0:7e 5745 -73 [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS] sa10_5G
28:6c:07:51:1b:46 2447 -55 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] Xiaomi_test_ZZ
40:e3:d6:8f:59:62 2462 -56 [WPA2-EAP-CCMP][ESS] mtkinternet
40:e3:d6:8f:59:61 2462 -59 [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]
98:fc:11:4d:c7:a2 2412 -61 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] linksys
50:bd:5f:93:ee:ac 2412 -63 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] abcd
28:6c:07:51:1b:47 5745 -82 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] Xiaomi_test_ZZ_5G
38:97:d6:18:c4:12 2412 -60 [WPA-PSK-TKIP][WPA2-PSK-TKIP][ESS] wnw
c8:02:10:b4:ab:61 2462 -69 [WPA2-PSK-CCMP][ESS] LG_MusicFlow_DL_3193
70:f9:6d:31:e0:00 2462 -75 [WPA2-PSK-CCMP][ESS] MPR-wifi
80:89:17:f4:cb:77 2437 -78 [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS] TP-LINK_2.4G_MT3
6c:f3:7f:38:ff:eb 5785 -85 [WPA2-EAP-CCMP][ESS] mtkemp
6c:f3:7f:38:ff:ea 5785 -86 [WPA2-EAP-CCMP][ESS] mtkinternet
64:09:80:1f:17:be 2462 -75 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] SS2_Xiaomi
40:e3:d6:8f:59:41 2462 -75 [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]
ec:6c:9f:22:de:01 2437 -75 [WPA2-PSK-CCMP][ESS] estar
40:e3:d6:8f:59:43 2462 -76 [WPA2-EAP-CCMP][ESS] mtkemp
38:97:d6:18:d4:32 2412 -76 [WPA-PSK-TKIP][WPA2-PSK-TKIP][ESS] wnw
40:e3:d6:8f:59:42 2462 -77 [WPA2-EAP-CCMP][ESS] mtkinternet
6c:f3:7f:38:ff:e9 5785 -87 [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]
80:89:17:f4:cb:76 5785 -89 [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS][ESS] TP-LINK_5G_MT3
b8:a3:86:55:8f:b2 2437 -79 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] SS7_VPN
40:e3:d6:8f:59:83 2462 -81 [WPA2-EAP-CCMP][ESS] mtkemp
38:97:d6:18:c4:00 5805 -85 [WPA-PSK-TKIP][WPA2-PSK-TKIP][ESS] wnwyanfa
40:e3:d6:8f:59:81 2462 -82 [WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP][ESS]
0c:72:2c:4f:41:66 2427 -88 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] 0000aaaa
40:e3:d6:8f:59:64 2462 -57 [WEP][ESS] mtklab
40:e3:d6:8f:59:44 2462 -75 [WEP][ESS] mtklab
6c:f3:7f:38:ff:ec 5785 -86 [WEP][ESS] mtklab
04:a1:51:8a:9c:ac 2422 -56 [WPS][ESS] NETGEAR-63-2.4G
e4:d3:32:cd:74:b3 2412 -57 [WPS][ESS] rongweim
40:e3:d6:8f:59:60 2462 -57 [ESS] mtkguest
fc:75:16:a3:95:d0 2462 -76 [WPS][ESS] dlink
00:0c:43:28:08:88 2437 -78 [ESS] MT7623_AP_2.4G
6c:f3:7f:38:ff:e8 5785 -85 [ESS] mtkguest
40:e3:d6:8f:59:40 2462 -75 [ESS] mtkguest
6c:f3:7f:38:ff:e0 2462 -85 [ESS] mtkguest
> list_network
network id / ssid / bssid / flags
0 Xiaomi_5G any [DISABLED]
1 D8_5GHZ any [DISABLED]
2 SS7_VPN any [DISABLED]
3 Xiaomi_2.4G any [DISABLED]
4 XIaomi_5G any [DISABLED]
5 hello any [DISABLED]
6 NETGEAR6200 any [DISABLED]
7 NETGEAR6200_5G any [DISABLED]
8 NETGEAR-63-2.4G any [DISABLED]
9 DLink88_24G any [DISABLED]
> add_network 10
10
> set_network 10 ssid "NETGEAR-63-5G"
OK
> list_network
network id / ssid / bssid / flags
0 Xiaomi_5G any [DISABLED]
1 D8_5GHZ any [DISABLED]
2 SS7_VPN any [DISABLED]
3 Xiaomi_2.4G any [DISABLED]
4 XIaomi_5G any [DISABLED]
5 hello any [DISABLED]
6 NETGEAR6200 any [DISABLED]
7 NETGEAR6200_5G any [DISABLED]
8 NETGEAR-63-2.4G any [DISABLED]
9 DLink88_24G any [DISABLED]
10 NETGEAR-63-5G any [DISABLED]
> set_network 10 key_mgmt WPA-PSK
OK
> set_network 10 psk "11111111"
OK
> get_network 10 key_mgmt
WPA-PSK
> get_network 10 psk
*
> enable_network 10
OK
<3>CTRL-EVENT-STATE-CHANGE id=-1 state=3 BSSID=00:00:00:00:00:00 SSID=
<3>CTRL-EVENT-SCAN-STARTED
<3>CTRL-EVENT-SCAN-RESULTS
<3>WPS-AP-AVAILABLE
<3>Trying to associate with [18434.676000] 80211> Connect bssid 04:a1:51:8a:9c:ae
> select_network 10
OK
> reconnect
OK
> list_network
network id / ssid / bssid / flags
0 Xiaomi_5G any [DISABLED]
1 D8_5GHZ any [DISABLED]
2 SS7_VPN any [DISABLED]
3 Xiaomi_2.4G any [DISABLED]
4 XIaomi_5G any [DISABLED]
5 hello any [DISABLED]
6 NETGEAR6200 any [DISABLED]
7 NETGEAR6200_5G any [DISABLED]
8 NETGEAR-63-2.4G any [DISABLED]
9 DLink88_24G any [DISABLED]
10 NETGEAR-63-5G any [CURRENT]
> save_config
OK
> status
bssid=04:a1:51:8a:9c:ae
freq=5745
ssid=NETGEAR-63-5G
id=10
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
ip_address=10.0.0.5
address=00:6c:fd:ab:68:be
uuid=12345678-9abc-def0-1234-56789abcdef0
<3>CTRL-EVENT-STATE-CHANGE id=10 state=9 BSSID=04:a1:51:8a:9c:ae SSID=NETGEAR-63-5G
<3>CTRL-EVENT-CONNECTED - connection to 04:a1:51:8a:9c:ae completed (auth) [id=10 id_str=]
保存后的wap_supplicant.conf
root@:/system/bin # cd /data/misc/wifi/
root@:/data/misc/wifi # cat wpa_supplicant
wpa_supplicant.conf wpa_supplicant/
at wpa_supplicant.conf <
ctrl_interface=/data/misc/wifi/sockets
driver_param=p2p_capable=0
update_config=1
uuid=12345678-9abc-def0-1234-56789abcdef0
device_name=full
manufacturer= Group Co., Ltd
model_name=Android TV
model_number=Android TV
serial_number=123456789
device_type=10-0050F204-5
os_version=01020300
config_methods=physical_display virtual_push_button
external_sim=1
wowlan_triggers=magic_pkt
network={
ssid="Xiaomi_5G"
psk="26630099"
key_mgmt=WPA-PSK
priority=12
disabled=1
}
network={
ssid="D8_5GHZ"
key_mgmt=NONE
priority=9
disabled=1
}
network={
ssid="SS7_VPN"
psk="12345678"
key_mgmt=WPA-PSK
priority=11
disabled=1
}
network={
ssid="Xiaomi_2.4G"
psk="26630099"
key_mgmt=WPA-PSK
priority=13
disabled=1
}
network={
ssid="XIaomi_5G"
psk="26630099"
key_mgmt=WPA-PSK
priority=18
disabled=1
}
network={
ssid="hello"
key_mgmt=NONE
priority=17
disabled=1
}
network={
ssid="NETGEAR6200"
psk="12345678"
key_mgmt=WPA-PSK
priority=19
disabled=1
}
network={
ssid="NETGEAR6200_5G"
psk="12345678"
key_mgmt=WPA-PSK
priority=27
disabled=1
}
network={
ssid="NETGEAR-63-2.4G"
psk="11111111"
key_mgmt=WPA-PSK
priority=56
disabled=1
}
network={
ssid="DLink88_24G"
psk="12345678"
key_mgmt=WPA-PSK
priority=38
disabled=1
}
network={
ssid="NETGEAR-63-5G"
psk="11111111"
key_mgmt=WPA-PSK
}