lin 发表于 2014-8-29 10:53:19

wpa_supplicant无线网络配置

wpa_supplicant是一个较好的选择,但缺点是它不支持所有的驱动。请浏览wpa_supplicant网站获得它所支持的驱动列表。另外,wpa_supplicant目前只能连接到那些你已经配置好ESSID的无线网络。wireless-tools支持几乎所有的无线网卡和驱动,但它不能连接到那些只支持WPA的AP。

执行:/system/bin/wpa_supplicant -d -Dwext -iwlan0-c/data/misc/wifi/wpa_supplicant.conf其中:-d :增加调试信息-Dwext :wext,驱动名称-iwlan0 :wlan0,网络接口名称/system/bin/wpa_supplicant:wpa_supplicant可执行程序path/data/misc/wifi/wpa_supplicant.conf:wpa_supplicant的配置文件path





2、运行命令行工具wpa_cli ;执行 :wpa_cli -iwlan0-p/data/system/wpa_supplicant注,-p/data/system/wpa_supplicant中的wpa_supplicant并不是可执行程序,而是个控制套接字。此时会进入交互模式。其中交互模式的命令如下表:


Full commandShort commandDescription
statusstatdisplays the current connection status
disconnectdiscprevents wpa_supplicant from connecting to anyaccess point
quitqexits wpa_cli
terminatetermkills wpa_supplicant
reconfigurereconreloads wpa_supplicant with the configuration filesupplied (-c parameter)
scanscanscans for available access points (onlyscans it, doesn't display anything)
scan_resultscan_rdisplays the results of the last scan
list_networkslist_ndisplays a list of configured networks and theirstatus (active or not, enabled or disabled)
select_networkselect_nselect a network among those defined to initiate aconnection (ie select_network 0)
enable_networkenable_nmakes a configured network available for selection(ie enable_network 0)
disable_networkdisable_nmakes a configured network unavailable forselection (ie disable_network 0)
remove_networkremove_nremoves a network and its configuration from thelist (ie remove_network 0)
add_networkadd_nadds a new network to the list. Its id will becreated automatically
set_networkset_nshows a very short list of available options toconfigure a network when supplied with no parameters.See next section for a list of extremely usefulparameters to be used with set_network and get_network.
get_networkget_ndisplays the required parameter for the specifiednetwork. See next section for a list of parameters
save_configsave_csaves the configuration


设置网络的基本格式:set_network <networkid> <key><parameter>[<parameter>]显示网络信息的基本格式:get_network<network id><key>相应的参数如下表:


KeyDescriptionParameters
ssidAccess point namestring
id_strString identifying the networkstring
priorityConnection priority over other APsnumber (0 being the default low priority)
bssidMac address of the access pointmac address
scan_ssidEnable/disbale ssid scan0, 1, 2
key_mgmtType of key managementWPA-PSK, WPA_EAP, None
pairwisePairwise ciphers for WPACCMP, TKIP
group=TKIPGroup ciphers for WPACCMP, TKIP, WEP104, WEP40
pskPre-Shared Key (clear or encrypted)string
wep_key0WEP key (up to 4: wep_key)string
eapExtensible Authentication ProtocolMD5, MSCHAPV2, OTP, GTC, TLS, PEAP, TTLS
identityEAP identity stringstring
passwordEAP passwordstring
ca_certPathname to CA certificate file/full/path/to/certificate
client_certPathname to client certificate/full/path/to/certificate (PEM/DER)
private_keyPathname to a client private key file/full/path/to/private_key (PEM/DER/PFX)


例1、连接无加密的AP>add_network (It will display a network id for you, assume itreturns 0)>set_network 0 ssid "666">set_network 0 key_mgmt NONE>enable_network 0>quit

例2、连接WEP加密AP>add_network   (assumereturn 1)>set_network 1 ssid "666">set_network 1 key_mgmt NONE>set_network 1 wep_key0 "your appassword">enable_network 1

例3、连接WPA-PSK/WPA2-PSK加密的AP>add_network   (assumereturn 2)>set_network 2 ssid "666">set_network 2 psk "your pre-sharedkey">enable_network2

3、以上是通过命令行工具wpa_cli来实现wifi网络的连接。当然,也可以通过wpa_supplicant的配置文件来实现连接。再回顾下运行wpa_supplicant时执行的命令:/system/bin/wpa_supplicant -d-Dwext -iwlan0-c/data/misc/wifi/wpa_supplicant.conf我们在执行时加上了-c/data/misc/wifi/wpa_supplicant.conf,我们可以将我们要连接的AP的设置以一定的格式写入wpa_supplicant.conf配置文件中即可。
例如:
ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=systemupdate_config=1network={ssid="my access point"proto=WPAkey_mgmt=WPA-PSKpsk="you pass words"}



页: [1]
查看完整版本: wpa_supplicant无线网络配置