wireless: Show channel number as well as frequency
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Aug 2017 13:30:12 +0000 (13:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Aug 2017 13:30:12 +0000 (13:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.wireless
src/hooks/zones/wireless

index 38b1936..581bdbf 100644 (file)
@@ -210,6 +210,45 @@ wireless_channel_to_frequency() {
        return ${EXIT_ERROR}
 }
 
+wireless_frequency_to_channel() {
+       local frequency=${1}
+
+       assert isinteger frequency
+
+       # Everything that is too high
+       if [ ${frequency} -gt 5825 ]; then
+               return ${EXIT_ERROR}
+
+       # 5 GHz Band
+       elif [ ${frequency} -gt 5000 ]; then
+               (( frequency = frequency - 5000 ))
+
+               # Must be divisible by 5
+               [ "$(( frequency % 5 ))" -ne 0 ] && return ${EXIT_ERROR}
+
+               print "$(( frequency / 5 ))"
+
+       # 2.4 GHz Band - Channel 14
+       elif [ ${frequency} -eq 2484 ]; then
+               print "14"
+
+       # 2.4 GHz Band
+       elif [ ${frequency} -gt 2407 ]; then
+               (( frequency = frequency - 2407 ))
+
+               # Must be divisible by 5
+               [ "$(( frequency % 5 ))" -ne 0 ] && return ${EXIT_ERROR}
+
+               print "$(( frequency / 5 ))"
+
+       # Everything else
+       else
+               return ${EXIT_ERROR}
+       fi
+
+       return ${EXIT_OK}
+}
+
 wireless_set_channel() {
        local device=${1}
        assert isset device
index 402a159..962f5fc 100644 (file)
@@ -137,9 +137,9 @@ hook_status() {
        local bssid=$(wpa_cli_status_get ${zone} bssid)
        assert isset bssid
 
+       local frequency=$(wpa_cli_bss_get_frequency "${zone}" "${bssid}")
+       cli_print_fmt1 3 "Channel" "$(wireless_frequency_to_channel ${frequency}) (${frequency} MHz)"
        cli_print_fmt1 3 "BSSID" "${bssid}"
-       cli_print_fmt1 3 "Frequency" \
-               "$(wpa_cli_bss_get_frequency ${zone} ${bssid}) MHz"
        cli_print_fmt1 3 "Noise" \
                "$(wpa_cli_bss_get_noise ${zone} ${bssid})"
        cli_print_fmt1 3 "Quality" \