From 423aafbd29ecfe1c3a4f74000e187c60dcc9c8a2 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Wed, 28 Feb 2018 02:57:12 +0100 Subject: [PATCH] gluon-core: improve channel and add chanlist validation --- package/gluon-core/check_site.lua | 14 ++++++++++--- scripts/check_site.lua | 33 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/package/gluon-core/check_site.lua b/package/gluon-core/check_site.lua index a18aee43..b1482508 100644 --- a/package/gluon-core/check_site.lua +++ b/package/gluon-core/check_site.lua @@ -33,9 +33,17 @@ for _, config in ipairs({'wifi24', 'wifi5'}) do if need_table({config}, nil, false) then need_string(in_site({'regdom'})) -- regdom is only required when wifi24 or wifi5 is configured - need_number({config, 'channel'}) - if config == 'wifi5' then - need_string_match({config, 'outdoor_chanlist'}, '^[%d%s-]+$', false) + if config == "wifi24" then + local channels = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14} + need_one_of({config, 'channel'}, channels) + elseif config == 'wifi5' then + local channels = { + 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, + 64, 96, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, + 120, 122, 124, 126, 128, 132, 134, 136, 138, 140, 142, 144, + 149, 151, 153, 155, 157, 159, 161, 165, 169, 173 } + need_one_of({config, 'channel'}, channels) + need_chanlist({config, 'outdoor_chanlist'}, channels, false) end obsolete({config, 'supported_rates'}, '802.11b rates are disabled by default.') diff --git a/scripts/check_site.lua b/scripts/check_site.lua index 9d65bb69..507fce83 100644 --- a/scripts/check_site.lua +++ b/scripts/check_site.lua @@ -203,6 +203,33 @@ function alternatives(...) end +local function check_chanlist(channels) + local is_valid_channel = check_one_of(channels) + return function(chanlist) + for group in chanlist:gmatch("%S+") do + if group:match("^%d+$") then + channel = tonumber(group) + if not is_valid_channel(channel) then + return false + end + elseif group:match("^%d+-%d+$") then + from, to = group:match("^(%d+)-(%d+)$") + from = tonumber(from) + to = tonumber(to) + if from >= to then + return false + end + if not is_valid_channel(from) or not is_valid_channel(to) then + return false + end + else + return false + end + end + return true + end +end + function need(path, check, required, msg) local val = loadvar(path) if required == false and val == nil then @@ -307,6 +334,12 @@ function need_array_of(path, array, required) return need_array(path, function(e) need_one_of(e, array) end, required) end +function need_chanlist(path, channels, required) + local valid_chanlist = check_chanlist(channels) + return need(path, valid_chanlist, required, 'be a space-separated list of WiFi channels or channel-ranges (separated by a hyphen). ' .. + 'Valid channels are: ' .. array_to_string(channels)) +end + function need_domain_name(path) need_string(path) need(path, function(domain_name)