]> git.ipfire.org Git - people/ms/network.git/commitdiff
wireless: Validate channels
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Aug 2017 21:41:17 +0000 (21:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Aug 2017 21:41:17 +0000 (21:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.wireless
src/hooks/ports/wireless-mesh

index d32c79046fa1c305cbd20e6bbcb6f51a37e6ced4..ad6a437761c32e9b2c97274d8bc1cdb088c70ee6 100644 (file)
@@ -199,14 +199,15 @@ wireless_list_reg_domains() {
        done <<< "$(regdbdump ${WIRELESS_REGULATORY_DOMAIN_DATABASE})"
 }
 
+# http://en.wikipedia.org/wiki/List_of_WLAN_channels
 wireless_channel_to_frequency() {
-       # http://en.wikipedia.org/wiki/List_of_WLAN_channels
-
        local channel=${1}
-       assert isset channel
 
-       # Channel number must be positive.
-       assert [ "${channel}" -gt 0 ]
+       # Works only for valid channel numbers
+       if ! wireless_channel_is_valid "${channel}"; then
+               log ERROR "Invalid wireless channel: ${channel}"
+               return ${EXIT_ERROR}
+       fi
 
        # 2.4 GHz band
        case "${channel}" in
@@ -270,17 +271,43 @@ wireless_frequency_to_channel() {
        return ${EXIT_OK}
 }
 
+wireless_channel_is_valid() {
+       local channel=${1}
+
+       case "${channel}" in
+               # 2.4 GHz Band
+               [123456789]|1[0123]|14)
+                       return ${EXIT_TRUE}
+                       ;;
+
+               # 5 GHz Band
+               3[68]|4[02468]|5[26]|6[04]|10[048]|11[26]|12[048]|13[26]|14[09]|15[37]|16[15])
+                       return ${EXIT_TRUE}
+                       ;;
+       esac
+
+       # Invalid channel number given
+       return ${EXIT_FALSE}
+}
+
 wireless_set_channel() {
        local device=${1}
-       assert isset device
-
        local channel=${2}
-       assert isset channel
 
-       device_exists ${device} || return ${EXIT_ERROR}
+       # Check if the device exists
+       if ! device_exists "${device}"; then
+               log ERROR "No such device: ${device}"
+               return ${EXIT_ERROR}
+       fi
+
+       # Check if the channel number is valid
+       if ! wireless_channel_is_valid "${channel}"; then
+               log ERROR "Invalid wireless channel: ${channel}"
+               return ${EXIT_ERROR}
+       fi
 
        log DEBUG "Setting wireless channel on device '${device}' to channel '${channel}'"
-       cmd_quiet iw dev ${device} set channel ${channel}
+       cmd iw dev "${device}" set channel "${channel}"
 }
 
 wireless_ibss_join() {
index 813777ac03c9480880cce1fb6c281cef0b01b5e6..cee8d2604d1b190c52f1fe98d126debdb6409250 100644 (file)
@@ -70,6 +70,11 @@ hook_parse_cmdline() {
        fi
 
        # XXX check if wireless channel is valid
+       # Check if channel is valid
+       if ! wireless_channel_is_valid "${CHANNEL}"; then
+               log ERROR "Channel is invalid: ${CHANNEL}"
+               return ${EXIT_ERROR}
+       fi
 }
 
 hook_create() {