print # end of header
}
-wpa_supplicant_config_write() {
- local device="${1}"
- shift
-
- assert isset device
-
- local file="${WPA_SUPPLICANT_CONF_DIR}/${device}.conf"
-
- local ap_scan=1 mode key ssid
- local channel
-
- local arg
- for arg in "$@"; do
- case "${arg}" in
- --ap-scan=*)
- ap_scan=$(cli_get_val "${arg}")
- ;;
- --channel=*)
- channel=$(cli_get_val "${arg}")
- ;;
- --mode=*)
- mode=$(cli_get_val "${arg}")
-
- # Empty signals no encryption.
- isset mode || mode="NONE"
- ;;
- --ssid=*)
- ssid=$(cli_get_val "${arg}")
- ;;
- --key=*)
- key=$(cli_get_val "${arg}")
- ;;
- *)
- error "Unrecognized argument: ${arg}"
- return ${EXIT_ERROR}
- ;;
- esac
- done
-
- assert isinteger ap_scan
- assert isset mode
-
- local auth_alg key_mgmt proto ssid psk wep_key0 wep_tx_keyidx
- local operation_mode
- local country_code="$(wireless_get_reg_domain)"
-
- case "${mode}" in
- # Normal WPA.
- WPA-PSK)
- auth_alg="OPEN"
- key_mgmt="WPA-PSK"
- proto="WPA"
- pairwise="CCMP TKIP"
- group="CCMP TKIP WEP104 WEP40"
- ;;
-
- # WPA with stronger algorithms.
- WPA-PSK-SHA256)
- auth_alg="OPEN"
- key_mgmt="WPA-PSK-SHA256"
- proto="WPA"
- pairwise="CCMP TKIP"
- group="CCMP TKIP WEP104 WEP40"
- ;;
-
- # Normal WPA2 (802.11i).
- WPA2-PSK)
- auth_alg="OPEN"
- key_mgmt="WPA-PSK"
- proto="RSN"
- pairwise="CCMP TKIP"
- group="CCMP TKIP WEP104 WEP40"
- ;;
-
- # WPA2 with stronger algorithms.
- WPA2-PSK-SHA256)
- auth_alg="OPEN"
- key_mgmt="WPA-PSK-SHA256"
- proto="RSN"
- pairwise="CCMP TKIP"
- group="CCMP TKIP WEP104 WEP40"
- ;;
-
- # WEP.
- WEP)
- auth_alg="SHARED"
- wep_key0="${key}"
- wep_tx_keyidx="0"
-
- # Reset PSK.
- psk=""
- ;;
-
- # IEEE 802.1X
- 8021X)
- key_mgmt="IEEE8021X"
- ;;
-
- # IEEE 802.11s without authentication
- 802.11s)
- operation_mode="mesh"
-
- # Use SAE when we got a PSK
- if isset key; then
- key_mgmt="SAE"
- else
- key_mgmt="NONE"
- fi
- ;;
-
- # No encryption. DANGEROUS!
- NONE)
- auth_alg="OPEN"
- key_mgmt="NONE"
- ;;
- *)
- log ERROR "Unknown mode: ${mode}"
- return ${EXIT_ERROR}
- ;;
- esac
-
- # Ensure we can write the file
- make_parent_directory "${file}"
-
- config_header "WPA supplicant configuration file" > ${file}
-
- # AP scanning/selection
- print "ap_scan=${ap_scan}" >> ${file}
-
- # Set country code, if known.
- if isset country_code; then
- print "country=\"${country_code}\"" >> ${file}
- fi
-
- # Set control socket directory.
- print "ctrl_interface=${WPA_SUPPLICANT_SOCKET_DIR}" >> ${file}
-
- (
- print # Network section
- print "network={"
-
- if isset auth_alg; then
- print " auth_alg=${auth_alg}"
- fi
-
- if isset key_mgmt; then
- print " key_mgmt=${key_mgmt}"
- fi
-
- if isset proto; then
- print " proto=${proto}"
- fi
-
- if isset ssid; then
- print " ssid=\"${ssid}\""
- fi
-
- if isset key; then
- print " psk=\"${key}\""
- fi
-
- # Operation Mode
- case "${operation_mode}" in
- ibss)
- print " mode=1"
- ;;
- mesh)
- print " mode=5"
- ;;
- esac
-
- # Frequency
- if isset channel; then
- print " frequency=$(wireless_channel_to_frequency "${channel}")"
- fi
-
- if isset wep_key0; then
- print " wep_key0=\"${wep_key0}\""
- fi
-
- if isset wep_tx_keyidx; then
- print " wep_tx_keyidx=${wep_tx_keyidx}"
- fi
-
- print "}"
- ) >> ${file}
-
- return ${EXIT_OK}
-}
-
wpa_supplicant_config_destroy() {
local device="${1}"
assert isset device