2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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 PHY_DIR
="/sys/class/ieee80211"
24 cli_device_status_phy
() {
26 assert phy_exists
"${phy}"
28 local address
="$(phy_get_address "${phy}")"
29 cli_print_fmt1
1 "Address" "${address}"
32 local driver
="$(phy_get_driver "${phy}")"
34 cli_print_fmt1
1 "Driver" "${driver}"
39 local devices
="$(phy_get_devices "${phy}")"
40 if isset devices
; then
41 cli_headline
2 "Soft interfaces"
44 for device
in ${devices}; do
45 cli_print
2 "* %s" "${device}"
50 cli_headline
2 "Features"
52 cli_print_fmt1
2 "Automatic Channel Selection" \
53 "$(phy_supports_acs "${phy}" && print "Supported
" || print "Not Supported
")"
54 cli_print_fmt1
2 "DFS" \
55 "$(phy_supports_dfs "${phy}" && print "Supported
" || print "Not Supported
")"
65 echo "${PHY_DIR}/${phy}"
72 [ -d "$(phy_dir ${phy})" ]
76 list_directory
"$(phy_dir)"
83 # As this is already a valid phy, we don't need to search on...
84 if phy_exists
"${info}"; then
89 # If this is an existing device, we can figure out the name of the
91 if device_exists
${info}; then
92 phy
="$(device_get_phy ${info})"
94 # If we just got the MAC address we need to walk though all
95 # available phys and find the right one.
96 elif mac_is_valid
${info}; then
98 for i
in $
(phy_list
); do
99 if [ "${info}" = "$(phy_get_address ${i})" ]; then
106 log DEBUG
"Searching for phy = ${info}, found ${phy:-none}"
108 if [ -z "${phy}" ]; then
120 local path
="$(phy_dir ${phy})/macaddress"
121 [ -r "${path}" ] ||
return ${EXIT_ERROR}
130 get_driver_from_path
"$(phy_dir "${phy}")/device/driver/module"
138 for device
in $
(device_list
); do
139 local p
="$(device_get_phy "${device}")"
141 if [ "${phy}" = "${p}" ]; then
150 # Check if the PHY exists
151 assert phy_exists
"${phy}"
154 for led
in $
(list_directory
/sys
/class
/leds
); do
155 # Get basename of the LED
158 if [[ ${led} =~
${phy}(:.
*)?$
]]; then
164 # This function tries to automatically configure LEDs to
166 phy_leds_autoconf
() {
171 for led
in $
(phy_list_leds
"${phy}"); do
172 # Skip some types of LEDs
174 # Pretty much everything we tested from Ralink
175 # locked up the kernel after a couple of seconds
181 # We try to set the LED into tpt mode (flashing on activity),
182 # but will fallback to tx mode if that isn't supported
184 for trigger
in "${phy}tpt" "${phy}tx"; do
185 if led_set_trigger
"${led}" "${trigger}"; then
194 phy_supports_channel
() {
199 assert isinteger channel
201 local _channel _frequency _dfs _max_tx_power
202 while read -r _channel _frequency _dfs _max_tx_power
; do
203 if [ "${channel}" = "${_channel}" ]; then
206 done <<< "$(network-phy-list-channels "${phy}")"
215 network-phy-list-ciphers
"${phy}"
218 phy_supports_cipher
() {
225 list_match
"${cipher}" $
(phy_list_ciphers
"${phy}")
228 __phy_list_ht_capabilities
() {
232 local capabilities
="$(network-phy-list-ht-caps "${phy}")"
234 print
"${capabilities//[\[\]]/ }"
237 phy_supports_ht_capability
() {
241 local capability
="${2}"
242 assert isset capability
244 list_match
"${capability}" $
(__phy_list_ht_capabilities
"${phy}")
247 # Returns TRUE if the PHY supports ACS
252 local driver
="$(phy_get_driver "${phy}")"
253 if ! isset driver
; then
257 # This is basically a whilelist of drivers which support this
258 # There is no better detection
260 ath10k_
*|ath9k|ath5k
)
269 # Returns TRUE if the PHY supports DFS
274 local driver
="$(phy_get_driver "${phy}")"
275 if ! isset driver
; then
279 # This is basically a whilelist of drivers which support this
280 # There is no better detection
282 ath10k_
*|ath9k|ath5k
)