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 wpa_supplicant_config_write
() {
33 local ap_scan
=1 mode key ssid
39 ap_scan
=$
(cli_get_val
${arg})
42 mode
=$
(cli_get_val
${arg})
44 # Empty signals no encryption.
45 isset mode || mode
="NONE"
48 ssid
=$
(cli_get_val
${arg})
51 key
=$
(cli_get_val
${arg})
54 error
"Unrecognized argument: ${arg}"
60 assert isinteger ap_scan
63 local auth_alg key_mgmt proto ssid psk wep_key0 wep_tx_keyidx
64 local country_code
="$(wireless_get_reg_domain)"
73 group
="CCMP TKIP WEP104 WEP40"
76 # WPA with stronger algorithms.
79 key_mgmt
="WPA-PSK-SHA256"
82 group
="CCMP TKIP WEP104 WEP40"
85 # Normal WPA2 (802.11i).
91 group
="CCMP TKIP WEP104 WEP40"
94 # WPA2 with stronger algorithms.
97 key_mgmt
="WPA-PSK-SHA256"
100 group
="CCMP TKIP WEP104 WEP40"
118 # No encryption. DANGEROUS!
124 log ERROR
"Unknown mode: ${mode}"
129 local config_dir
=$
(dirname ${file})
130 mkdir
-p ${config_dir} 2>/dev
/null
132 config_header
"WPA supplicant configuration file" > ${file}
134 # AP scanning/selection
135 print
"ap_scan=${ap_scan}" >> ${file}
137 # Set country code, if known.
138 if isset country_code
; then
139 print
"country=\"${country_code}\"" >> ${file}
142 # Set control socket directory.
143 print
"ctrl_interface=${WPA_SUPPLICANT_SOCKET_DIR}" >> ${file}
146 print
# Network section
149 if isset auth_alg
; then
150 print
" auth_alg=${auth_alg}"
153 if isset key_mgmt
; then
154 print
" key_mgmt=${key_mgmt}"
158 print
" proto=${proto}"
162 print
" ssid=\"${ssid}\""
166 print
" psk=\"${key}\""
169 if isset wep_key0
; then
170 print
" wep_key0=\"${wep_key0}\""
173 if isset wep_tx_keyidx
; then
174 print
" wep_tx_keyidx=${wep_tx_keyidx}"
183 wpa_supplicant_config_dir
() {
187 echo "${RUN_DIR}/wpa_supplicant/${device}"
190 wpa_supplicant_start
() {
194 service_start
"wpa_supplicant@${device}.service"
197 wpa_supplicant_stop
() {
201 service_stop
"wpa_supplicant@${device}.service"
204 wpa_supplicant_client
() {
212 # Run the command and return the output.
213 cmd wpa_cli
-p${WPA_SUPPLICANT_SOCKET_DIR} -i${device} ${cmd}
220 wpa_supplicant_client
${device} status verbose
223 wpa_cli_status_get
() {
231 while read -r line
; do
232 key
=$
(cli_get_key
${line})
234 if [ "${key}" = "${arg}" ]; then
235 cli_get_val
"${line}"
238 done <<< "$(wpa_cli_status ${device})"
250 wpa_supplicant_client
${device} bss
${bss}
264 while read -r line
; do
265 key
=$
(cli_get_key
${line})
267 if [ "${key}" = "${arg}" ]; then
268 cli_get_val
"${line}"
271 done <<< "$(wpa_cli_bss ${device} ${bss})"
276 wpa_cli_bss_get_frequency
() {
283 wpa_cli_bss_get
${device} ${bssid} freq
286 wpa_cli_bss_get_noise
() {
293 wpa_cli_bss_get
${device} ${bssid} noise
296 wpa_cli_bss_get_quality
() {
303 local quality
=$
(wpa_cli_bss_get
${device} ${bssid} qual
)
306 print $
(( ${quality} * 100 / 70 ))
309 wpa_cli_bss_get_flags
() {
316 wpa_cli_bss_get
${device} ${bssid} flags