gluon-core: improve channel and add chanlist validation
This commit is contained in:
parent
bf55249159
commit
423aafbd29
@ -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.')
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user