2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 WPA_SUPPLICANT_SOCKET_DIR
="${RUN_DIR}/wpa_supplicant/ctrl"
24 function wpa_supplicant_config_write
() {
33 local ap_scan
=1 country_code mode key ssid
39 ap_scan
=$
(cli_get_val
${arg})
42 country_code
=$
(cli_get_val
${arg})
45 mode
=$
(cli_get_val
${arg})
47 # Empty signals no encryption.
48 isset mode || mode
="NONE"
51 ssid
=$
(cli_get_val
${arg})
54 key
=$
(cli_get_val
${arg})
57 error
"Unrecognized argument: ${arg}"
63 assert isinteger ap_scan
66 local auth_alg key_mgmt proto ssid psk wep_key0 wep_tx_keyidx
75 group
="CCMP TKIP WEP104 WEP40"
78 # WPA with stronger algorithms.
81 key_mgmt
="WPA-PSK-SHA256"
84 group
="CCMP TKIP WEP104 WEP40"
87 # Normal WPA2 (802.11i).
93 group
="CCMP TKIP WEP104 WEP40"
96 # WPA2 with stronger algorithms.
99 key_mgmt
="WPA-PSK-SHA256"
102 group
="CCMP TKIP WEP104 WEP40"
120 # No encryption. DANGEROUS!
126 log ERROR
"Unknown mode: ${mode}"
131 local config_dir
=$
(dirname ${file})
132 mkdir
-p ${config_dir} 2>/dev
/null
134 config_header
"WPA supplicant configuration file" > ${file}
136 # AP scanning/selection
137 print
"ap_scan=${ap_scan}" >> ${file}
139 # Set country code, if known.
140 if isset country_code
; then
141 print
"country=\"${country_code}\"" >> ${file}
144 # Set control socket directory.
145 print
"ctrl_interface=${WPA_SUPPLICANT_SOCKET_DIR}" >> ${file}
148 print
# Network section
151 if isset auth_alg
; then
152 print
" auth_alg=${auth_alg}"
155 if isset key_mgmt
; then
156 print
" key_mgmt=${key_mgmt}"
160 print
" proto=${proto}"
164 print
" ssid=${ssid}"
168 print
" psk=\"${key}\""
171 if isset wep_key0
; then
172 print
" wep_key0=\"${wep_key0}\""
175 if isset wep_tx_keyidx
; then
176 print
" wep_tx_keyidx=${wep_tx_keyidx}"
185 function wpa_supplicant_config_dir
() {
189 echo "${RUN_DIR}/wpa_supplicant/${device}"
192 function wpa_supplicant_start
() {
196 service_start
"wpa_supplicant@${device}.service"
199 function wpa_supplicant_stop
() {
203 service_stop
"wpa_supplicant@${device}.service"
206 function wpa_supplicant_client
() {
214 # Run the command and return the output.
215 cmd wpa_cli
-p${WPA_SUPPLICANT_SOCKET_DIR} -i${device} ${cmd}
218 function wpa_cli_status
() {
222 wpa_supplicant_client
${device} status verbose
225 function wpa_cli_status_get
() {
233 while read -r line
; do
234 key
=$
(cli_get_key
${line})
236 if [ "${key}" = "${arg}" ]; then
237 cli_get_val
"${line}"
240 done <<< "$(wpa_cli_status ${device})"
245 function wpa_cli_bss
() {
252 wpa_supplicant_client
${device} bss
${bss}
255 function wpa_cli_bss_get
() {
266 while read -r line
; do
267 key
=$
(cli_get_key
${line})
269 if [ "${key}" = "${arg}" ]; then
270 cli_get_val
"${line}"
273 done <<< "$(wpa_cli_bss ${device} ${bss})"
278 function wpa_cli_bss_get_frequency
() {
285 wpa_cli_bss_get
${device} ${bssid} freq
288 function wpa_cli_bss_get_noise
() {
295 wpa_cli_bss_get
${device} ${bssid} noise
298 function wpa_cli_bss_get_quality
() {
305 wpa_cli_bss_get
${device} ${bssid} qual
308 function wpa_cli_bss_get_flags
() {
315 wpa_cli_bss_get
${device} ${bssid} flags