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
40 ap_scan
=$
(cli_get_val
"${arg}")
43 channel
=$
(cli_get_val
"${arg}")
46 mode
=$
(cli_get_val
"${arg}")
48 # Empty signals no encryption.
49 isset mode || mode
="NONE"
52 ssid
=$
(cli_get_val
"${arg}")
55 key
=$
(cli_get_val
"${arg}")
58 error
"Unrecognized argument: ${arg}"
64 assert isinteger ap_scan
67 local auth_alg key_mgmt proto ssid psk wep_key0 wep_tx_keyidx
69 local country_code
="$(wireless_get_reg_domain)"
78 group
="CCMP TKIP WEP104 WEP40"
81 # WPA with stronger algorithms.
84 key_mgmt
="WPA-PSK-SHA256"
87 group
="CCMP TKIP WEP104 WEP40"
90 # Normal WPA2 (802.11i).
96 group
="CCMP TKIP WEP104 WEP40"
99 # WPA2 with stronger algorithms.
102 key_mgmt
="WPA-PSK-SHA256"
105 group
="CCMP TKIP WEP104 WEP40"
123 # IEEE 802.11s without authentication
125 operation_mode
="mesh"
127 # Use SAE when we got a PSK
135 # No encryption. DANGEROUS!
141 log ERROR
"Unknown mode: ${mode}"
146 local config_dir
=$
(dirname ${file})
147 mkdir
-p ${config_dir} 2>/dev
/null
149 config_header
"WPA supplicant configuration file" > ${file}
151 # AP scanning/selection
152 print
"ap_scan=${ap_scan}" >> ${file}
154 # Set country code, if known.
155 if isset country_code
; then
156 print
"country=\"${country_code}\"" >> ${file}
159 # Set control socket directory.
160 print
"ctrl_interface=${WPA_SUPPLICANT_SOCKET_DIR}" >> ${file}
163 print
# Network section
166 if isset auth_alg
; then
167 print
" auth_alg=${auth_alg}"
170 if isset key_mgmt
; then
171 print
" key_mgmt=${key_mgmt}"
175 print
" proto=${proto}"
179 print
" ssid=\"${ssid}\""
183 print
" psk=\"${key}\""
187 case "${operation_mode}" in
197 if isset channel
; then
198 print
" frequency=$(wireless_channel_to_frequency "${channel}")"
201 if isset wep_key0
; then
202 print
" wep_key0=\"${wep_key0}\""
205 if isset wep_tx_keyidx
; then
206 print
" wep_tx_keyidx=${wep_tx_keyidx}"
215 wpa_supplicant_config_dir
() {
219 echo "${RUN_DIR}/wpa_supplicant/${device}"
222 wpa_supplicant_start
() {
226 service_start
"wpa_supplicant@${device}.service"
229 wpa_supplicant_stop
() {
233 service_stop
"wpa_supplicant@${device}.service"
236 wpa_supplicant_client
() {
244 # Run the command and return the output.
245 cmd wpa_cli
-p${WPA_SUPPLICANT_SOCKET_DIR} -i${device} ${cmd}
252 wpa_supplicant_client
${device} status verbose
255 wpa_cli_status_get
() {
263 while read -r line
; do
264 key
=$
(cli_get_key
${line})
266 if [ "${key}" = "${arg}" ]; then
267 cli_get_val
"${line}"
270 done <<< "$(wpa_cli_status ${device})"
282 wpa_supplicant_client
${device} bss
${bss}
296 while read -r line
; do
297 key
=$
(cli_get_key
${line})
299 if [ "${key}" = "${arg}" ]; then
300 cli_get_val
"${line}"
303 done <<< "$(wpa_cli_bss ${device} ${bss})"
308 wpa_cli_bss_get_frequency
() {
315 wpa_cli_bss_get
${device} ${bssid} freq
318 wpa_cli_bss_get_noise
() {
325 wpa_cli_bss_get
${device} ${bssid} noise
328 wpa_cli_bss_get_quality
() {
335 local quality
=$
(wpa_cli_bss_get
${device} ${bssid} qual
)
338 print $
(( ${quality} * 100 / 70 ))
341 wpa_cli_bss_get_flags
() {
348 wpa_cli_bss_get
${device} ${bssid} flags