#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # 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 . # # # ############################################################################### PHY_DIR="/sys/class/ieee80211" cli_device_status_phy() { local phy="${1}" assert phy_exists "${phy}" local address="$(phy_get_address "${phy}")" cli_print_fmt1 1 "Address" "${address}" # Show kernel module local driver="$(phy_get_driver "${phy}")" if isset driver; then cli_print_fmt1 1 "Driver" "${driver}" fi cli_space local devices="$(phy_get_devices "${phy}")" if isset devices; then cli_headline 2 "Soft interfaces" local device for device in ${devices}; do cli_print 2 "* %s" "${device}" done cli_space fi cli_headline 2 "Features" cli_print_fmt1 2 "Automatic Channel Selection" \ "$(phy_supports_acs "${phy}" && print "Supported" || print "Not Supported")" cli_print_fmt1 2 "DFS" \ "$(phy_supports_dfs "${phy}" && print "Supported" || print "Not Supported")" cli_space return ${EXIT_OK} } phy_dir() { local phy=${1} echo "${PHY_DIR}/${phy}" } phy_exists() { local phy=${1} assert isset phy [ -d "$(phy_dir ${phy})" ] } phy_list() { list_directory "$(phy_dir)" } phy_get() { local info="${1}" local phy # As this is already a valid phy, we don't need to search on... if phy_exists "${info}"; then print "${info}" return ${EXIT_OK} fi # If this is an existing device, we can figure out the name of the # phy directly. if device_exists ${info}; then phy="$(device_get_phy ${info})" # If we just got the MAC address we need to walk though all # available phys and find the right one. elif mac_is_valid ${info}; then local i for i in $(phy_list); do if [ "${info}" = "$(phy_get_address ${i})" ]; then phy=${i} break fi done fi log DEBUG "Searching for phy = ${info}, found ${phy:-none}" if [ -z "${phy}" ]; then return ${EXIT_ERROR} fi echo "${phy}" return ${EXIT_OK} } phy_get_address() { local phy=${1} assert isset phy local path="$(phy_dir ${phy})/macaddress" [ -r "${path}" ] || return ${EXIT_ERROR} print "$(<${path})" } phy_get_driver() { local phy="${1}" assert isset phy get_driver_from_path "$(phy_dir "${phy}")/device/driver/module" } phy_get_devices() { local phy="${1}" assert isset phy local device for device in $(device_list); do local p="$(device_get_phy "${device}")" if [ "${phy}" = "${p}" ]; then print "${device}" fi done } phy_list_leds() { local phy="${1}" # Check if the PHY exists assert phy_exists "${phy}" local led for led in $(list_directory /sys/class/leds); do # Get basename of the LED led=${led%*/} if [[ ${led} =~ ${phy}(:.*)?$ ]]; then print "${led}" fi done } # This function tries to automatically configure LEDs to # something useful phy_leds_autoconf() { local phy="${1}" assert isset phy local led for led in $(phy_list_leds "${phy}"); do # Skip some types of LEDs case "${led}" in # Pretty much everything we tested from Ralink # locked up the kernel after a couple of seconds rt*) continue ;; esac # We try to set the LED into tpt mode (flashing on activity), # but will fallback to tx mode if that isn't supported local trigger for trigger in "${phy}tpt" "${phy}tx"; do if led_set_trigger "${led}" "${trigger}"; then break fi done done return ${EXIT_OK} } phy_supports_channel() { local phy="${1}" assert isset phy local channel="${2}" assert isinteger channel local _channel _frequency _dfs _max_tx_power while read -r _channel _frequency _dfs _max_tx_power; do if [ "${channel}" = "${_channel}" ]; then return ${EXIT_TRUE} fi done <<< "$(network-phy-list-channels "${phy}")" return ${EXIT_FALSE} } __phy_list_ht_capabilities() { local phy="${1}" assert isset phy local capabilities="$(network-phy-list-ht-caps "${phy}")" print "${capabilities//[\[\]]/ }" } phy_supports_ht_capability() { local phy="${1}" assert isset phy local capability="${2}" assert isset capability list_match "${capability}" $(__phy_list_ht_capabilities "${phy}") } # Returns TRUE if the PHY supports ACS phy_supports_acs() { local phy="${1}" assert isset phy local driver="$(phy_get_driver "${phy}")" if ! isset driver; then return ${EXIT_ERROR} fi # This is basically a whilelist of drivers which support this # There is no better detection case "${driver}" in ath10k_*|ath9k|ath5k) return ${EXIT_TRUE} ;; *) return ${EXIT_FALSE} ;; esac } # Returns TRUE if the PHY supports DFS phy_supports_dfs() { local phy="${1}" assert isset phy local driver="$(phy_get_driver "${phy}")" if ! isset driver; then return ${EXIT_ERROR} fi # This is basically a whilelist of drivers which support this # There is no better detection case "${driver}" in ath10k_*|ath9k|ath5k) return ${EXIT_TRUE} ;; *) return ${EXIT_FALSE} ;; esac }