wpa_supplicant and wpa_cli method


1. Summary

wpa_supplicant is a connection, WIFI configuration's tool. It mainly includes two programs: wpa_supplicant and wpa_cli. teh relationship between the two is server and client. Usually, we can process the WIFI's configuration and connection through wpa_cli, if there is special need you can write applications directly. We can directly use wpa_supplicant interface in order to write applications.

This article mainly discribes how to use wpa_cli in order to access WIFI's configuration and connection.

2. Usage method

2.1 Start wpa_supplicant application

$ wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B

Notes:add the following codes to this file /etc/wpa_supplicant.conf.

ctrl_interface=/var/run/wpa_supplicant
update_config=1

2.2 Start wpa_cli application

$ wpa_cli -i wlan0 scan             Search for wifi network
$ wpa_cli -i wlan0 scan_result      Display the search result.
$ wpa_cli -i wlan0 add_network      Add a network connection.

If you want to connect(WPA encryption mode):[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] (wpa encrypted)
wifi name:wifi_name
wifi password:wifi_psk

$ wpa_cli -i wlan0 set_network 0 ssid '"wifi_name"'
$ wpa_cli -i wlan0 set_network 0 psk '"wifi_psk"'
$ wpa_cli -i wlan0 enable_network 0

If you want to connect(WEP encryption mode):[WEP][ESS] (wep encrypted)
wifi name:wifi_name
wifi password:wifi_psk

$ wpa_cli -i wlan0 set_network 0 ssid '"wpa_name"'
$ wpa_cli -i wlan0 set_network 0 key_mgmt NONE
$ wpa_cli -i wlan0 set_network 0 wep_key0 '"wap_psk"'
$ wpa_cli -i wlan0 enable_network 0

If you want to connect(No encryption mode):[ESS] (No encryption)
wifi name:wifi_name

$ wpa_cli -i wlan0 set_network 0 ssid '"wifi_name"'
$ wpa_cli -i wlan0 set_network 0 key_mgmt NONE
$ wpa_cli -i wlan0 enable_network 0

2.3 Allocation for ip,netmask,gateway,dns

$ udhcpc -i wlan0 -s /etc/udhcpc.script -q

Once the execution is complete, you can connect to the network.

2.4 Save connection

$ wpa_cli -i wlan0 save_config

2.5 Disconnection

$ wpa_cli -i wlan0 disable_network 0

2.6 Connect to an existing connection

$ wpa_cli -i wlan0 list_network             List all saved connections
$ wpa_cli -i wlan0 select_network 0         Connect to the first saved connection.
$ wpa_cli -i wlan0 enable_network 0         Enable  the first saved connection.

2.7 Disconnect wifi

$ ifconfig wlan0 down
$ killall udhcpc
$ killall wpa_supplicant

3. wpa_wifi_tool method

wpa_wifi_tool is based on wpa_supplicant and wpa_cli's tool for wifi quick setup. It is used during debugging for easy connection to wifi. Users do not need to run step2's complex commands, they are used to achieve wifi settings and connections and other functions.

Notes:This tool is only used as a debugging tool, It is recommended to use wpa_cli or directly use wpa_supplicant to achieve actual wifi function's development.

Method:

For other methods, please refer to help.