WIRELESS_DEFAULT_ENCRYPTION_MODE="NONE"
WIRELESS_VALID_ENCRYPTION_MODES="WPA2-PSK-SHA256 WPA2-PSK \
- WPA-PSK-SHA256 WPA-PSK WEP NONE"
+ WPA-PSK-SHA256 WPA-PSK NONE"
cli_wireless() {
local action=${1}
# Set the channel
if isset channel; then
- wireless_set_channel "${device}" "${channel}" || return $?
+ wireless_set_channel "${device}" "${channel}" "auto" || return $?
fi
return ${ret}
return ${EXIT_FALSE}
}
+wireless_channel_is_ht40_plus() {
+ local channel="${1}"
+ assert isinteger channel
+
+ # 2.4 GHz
+ if [ ${channel} -le 6 ]; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
+wireless_channel_is_ht40_minus() {
+ local channel="${1}"
+ assert isinteger channel
+
+ # 2.4 GHz
+ if [ ${channel} -ge 6 ]; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
wireless_set_channel() {
- local device=${1}
- local channel=${2}
+ local device="${1}"
+ local channel="${2}"
+ local bandwidth="${3}"
# Check if the device exists
if ! device_exists "${device}"; then
return ${EXIT_ERROR}
fi
+ local ht_flag
+ if [ "${bandwidth}" = "auto" ]; then
+ local phy="$(device_get_phy "${device}")"
+
+ # Offset of a 40 MHz channel
+ local ht_offset=5
+
+ if wireless_channel_is_ht40_plus "${channel}" \
+ && phy_supports_ht_capability "${phy}" "HT40+" \
+ && phy_supports_channel "${phy}" $(( channel + ht_offset )); then
+ ht_flag="HT40+"
+
+ elif wireless_channel_is_ht40_minus "${channel}" \
+ && phy_supports_ht_capability "${phy}" "HT40-" \
+ && phy_supports_channel "${phy}" $(( channel - ht_offset )); then
+ ht_flags="HT40-"
+ fi
+ fi
+
log DEBUG "Setting wireless channel on device '${device}' to channel '${channel}'"
- cmd iw dev "${device}" set channel "${channel}"
+ cmd iw dev "${device}" set channel "${channel}" "${ht_flag}"
+}
+
+wireless_pre_shared_key_is_valid() {
+ local encryption_mode="${1}"
+ local psk="${2}"
+
+ # Length of the PSK
+ local l="${#psk}"
+
+ case "${encryption_mode}" in
+ # For WPA*, the key must be between 8 and 63 chars
+ WPA2-PSK|WPA2-PSK-SHA256|WPA-PSK|WPA-PSK-SHA256)
+ if [ ${l} -ge 8 ] && [ ${l} -le 63 ]; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+ ;;
+ esac
+
+ return ${EXIT_ERROR}
+}
+
+wireless_client_is_connected() {
+ local device="${1}"
+
+ device_has_carrier "${device}"
}
wireless_ibss_join() {
return ${EXIT_OK}
}
+
+wireless_get_ht_caps() {
+ local device="${1}"
+ assert isset device
+
+ local phy="$(device_get_phy "${device}")"
+ if ! isset phy; then
+ log ERROR "Could not determine PHY for ${device}"
+ return ${EXIT_ERROR}
+ fi
+
+ network-phy-list-ht-caps "${phy}"
+}
+
+wireless_get_vht_caps() {
+ local device="${1}"
+ assert isset device
+
+ local phy="$(device_get_phy "${device}")"
+ if ! isset phy; then
+ log ERROR "Could not determine PHY for ${device}"
+ return ${EXIT_ERROR}
+ fi
+
+ network-phy-list-vht-caps "${phy}"
+}