juci.wireless: use standard wlan channel list if not broadcom
authorSukru Senli <sukru.senli@inteno.se>
Wed, 14 Mar 2018 17:19:21 +0000 (18:19 +0100)
committerSukru Senli <sukru.senli@inteno.se>
Wed, 14 Mar 2018 17:19:21 +0000 (18:19 +0100)
plugins/juci-wireless/ubus/juci.wireless

index e2e9302..6871463 100755 (executable)
@@ -5,7 +5,6 @@
 case "$1" in
        list)
                echo '{ "set_credentials" : {"ssid":"str", "encryption":"str", "key":"str", "import":true}, "get_channels" : {"radio":"str", "bandwidth":"str", "dfsc":true} }'
-
        ;;
        call)
                case "$2" in
@@ -49,31 +48,59 @@ case "$1" in
                                json_get_var bandwidth bandwidth
                                json_get_var dfsc dfsc
 
-                               frequency=2
+                               if [ -f /usr/sbin/wlctl ]; then
+                                       frequency=2
 
-                               test `wlctl -i $radio band` = "a" && frequency=5
+                                       test `wlctl -i $radio band` = "a" && frequency=5
 
-                               tmpFile="/tmp/tmpRpcdJuciWireless"
-                               wlctl -i $radio chanspecs -b $frequency -w $bandwidth | tr A-Z a-z | sed -e 's/[^0-9]/ /g' | cut -d ' ' -f1 | sort -n | uniq > $tmpFile
+                                       json_init
 
-                               json_init
+                                       cmd="cat $tmpFile"
+
+                                       json_add_array "channels"
 
-                               if [ $dfsc -eq 0 -a `grep 48 -B100 $tmpFile | wc -l` -gt 0 ]; then
-                                       cmd="grep 48 -B100 $tmpFile"
+                                       for ch in $(wlctl -i $radio chanspecs -b $frequency -w $bandwidth | tr A-Z a-z | sed -e 's/[^0-9]/ /g' | cut -d ' ' -f1 | sort -n | uniq); do
+                                               [ $dfsc -eq 1 -o $ch -lt 52 -o $ch -gt 144 ] && json_add_int "channels" $ch
+                                       done
+
+                                       json_close_array
+                                       json_dump
                                else
-                                       cmd="cat $tmpFile"
-                               fi
+                                       band="$(uci -q get wireless.$radio.band)"
+                                       country="$(uci -q get wireless.$radio.country)"
+                                       if [ "$band" == "a" ]; then
+                                               if [ "$bandwidth" == "80" ]; then
+                                                       uschannels="36 40 44 48 52 56 60 64 100 104 108 112 116 120 124 128 132 136 140 144 149 153 157 161"
+                                                       defchannels="36 40 44 48 52 56 60 64 100 104 108 112"
+                                               elif  [ "$bandwidth" == "40" ]; then
+                                                       uschannels="36 40 44 48 52 56 60 64 100 104 108 112 116 120 124 128 132 136 140 144 149 153 157 161"
+                                                       defchannels="36 40 44 48 52 56 60 64 100 104 108 112 132 136"
+                                               else
+                                                       uschannels="36 40 44 48 52 56 60 64 100 104 108 112 116 120 124 128 132 136 140 144 149 153 157 161 165"
+                                                       defchannels="36 40 44 48 52 56 60 64 100 104 108 112 116 132 136 140"
+                                               fi
+                                       else
+                                               uschannels="1 2 3 4 5 6 7 8 9 10 11"
+                                               defchannels="1 2 3 4 5 6 7 8 9 10 11 12 13"
+                                       fi
+
+                                       if [ "${country:0:2}" == "US" ]; then
+                                               chanlist="$uschannels"
+                                       else
+                                               chanlist="$defchannels"
+                                       fi
 
-                               json_add_array "channels"
+                                       json_init
 
-                               for i in `$cmd`; do
-                                       json_add_int "channels" $i
-                               done
+                                       json_add_array "channels"
 
-                               json_close_array
-                               json_dump
+                                       for ch in $chanlist; do
+                                               [ $dfsc -eq 1 -o $ch -lt 52 -o $ch -gt 144 ] && json_add_int "channels" $ch
+                                       done
 
-                               rm $tmpFile
+                                       json_close_array
+                                       json_dump
+                               fi
                        ;;
                esac
        ;;