#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2012 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### WPA_SUPPLICANT_SOCKET_DIR="${RUN_DIR}/wpa_supplicant/ctrl" wpa_supplicant_config_header() { config_header "WPA supplicant configuration file" # Set control socket directory. print "ctrl_interface=${WPA_SUPPLICANT_SOCKET_DIR}" # Honour country local country="$(wireless_get_reg_domain)" if isset country; then print "country=${country}" fi print print "# Privacy" # Use a random MAC address for any pre-association # operations like scanning or ANQP print "preassoc_mac_addr=1" print # end of header } wpa_supplicant_config_destroy() { local device="${1}" assert isset device file_delete "${WPA_SUPPLICANT_CONF_DIR}/${device}.conf" } wpa_supplicant_start() { local device=${1} assert isset device service_start "wpa_supplicant@${device}.service" } wpa_supplicant_stop() { local device=${1} assert isset device service_stop "wpa_supplicant@${device}.service" } wpa_supplicant_client() { local device=${1} assert isset device shift local cmd="$@" assert isset cmd # Run the command and return the output. cmd wpa_cli -p${WPA_SUPPLICANT_SOCKET_DIR} -i${device} ${cmd} } wpa_cli_status() { local device=${1} assert isset device wpa_supplicant_client ${device} status verbose } wpa_cli_status_get() { local device=${1} assert isset device local arg=${2} assert isset arg local line key while read -r line; do key=$(cli_get_key ${line}) if [ "${key}" = "${arg}" ]; then cli_get_val "${line}" return ${EXIT_OK} fi done <<< "$(wpa_cli_status ${device})" return ${EXIT_ERROR} } wpa_cli_bss() { local device=${1} assert isset device local bss=${2} assert isset bss wpa_supplicant_client ${device} bss ${bss} } wpa_cli_bss_get() { local device=${1} assert isset device local bss=${2} assert isset bss local arg=${3} assert isset arg local line key while read -r line; do key=$(cli_get_key ${line}) if [ "${key}" = "${arg}" ]; then cli_get_val "${line}" return ${EXIT_OK} fi done <<< "$(wpa_cli_bss ${device} ${bss})" return ${EXIT_ERROR} } wpa_cli_bss_get_frequency() { local device=${1} assert isset device local bssid=${2} assert isset bssid wpa_cli_bss_get ${device} ${bssid} freq } wpa_cli_bss_get_noise() { local device=${1} assert isset device local bssid=${2} assert isset bssid wpa_cli_bss_get ${device} ${bssid} noise } wpa_cli_bss_get_quality() { local device=${1} assert isset device local bssid=${2} assert isset bssid local quality=$(wpa_cli_bss_get ${device} ${bssid} qual) # Convert to percent print $(( ${quality} * 100 / 70 )) } wpa_cli_bss_get_flags() { local device=${1} assert isset device local bssid=${2} assert isset bssid wpa_cli_bss_get ${device} ${bssid} flags }