gluon-core: fix 200-wireless coding style

This commit is contained in:
Matthias Schiffer 2017-08-08 04:09:00 +02:00
parent 2b9dd54f00
commit 06d0c0f211
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C

View File

@ -8,208 +8,196 @@ local uci = require('simple-uci').cursor()
-- Initial -- Initial
if not sysconfig.gluon_version then if not sysconfig.gluon_version then
uci:delete_all('wireless', 'wifi-iface') uci:delete_all('wireless', 'wifi-iface')
end end
local function get_channel(radio, config) local function get_channel(radio, config)
if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then
return uci:get('wireless', radio, 'channel') or config.channel return uci:get('wireless', radio, 'channel') or config.channel
else else
return config.channel return config.channel
end end
end end
local function is_disabled(name) local function is_disabled(name)
if uci:get('wireless', name) then if uci:get('wireless', name) then
return uci:get_bool('wireless', name, 'disabled') return uci:get_bool('wireless', name, 'disabled')
else else
return false return false
end end
end end
-- Returns the first argument that is not nil; don't call without any non-nil arguments! -- Returns the first argument that is not nil; don't call without any non-nil arguments!
local function first_non_nil(first, ...) local function first_non_nil(first, ...)
if first ~= nil then if first ~= nil then
return first return first
else else
return first_non_nil(...) return first_non_nil(...)
end end
end end
local function configure_ibss(config, radio, index, suffix, disabled) local function configure_ibss(config, radio, index, suffix, disabled)
local name = 'ibss_' .. radio local name = 'ibss_' .. radio
uci:delete('network', name) uci:delete('network', name)
uci:delete('network', name .. '_vlan') uci:delete('network', name .. '_vlan')
uci:delete('wireless', name) uci:delete('wireless', name)
if not config then if not config then
return return
end end
local macaddr = util.get_wlan_mac(uci, radio, index, 3) local macaddr = util.get_wlan_mac(uci, radio, index, 3)
if not macaddr then if not macaddr then
return return
end end
if config.vlan then if config.vlan then
uci:section('network', 'interface', name, uci:section('network', 'interface', name, {
{ proto = 'none',
proto = 'none', })
}
)
uci:section('network', 'interface', name .. '_vlan', uci:section('network', 'interface', name .. '_vlan', {
{ ifname = '@' .. name .. '.' .. config.vlan,
ifname = '@' .. name .. '.' .. config.vlan, proto = 'gluon_mesh',
proto = 'gluon_mesh', })
} else
) uci:section('network', 'interface', name, {
else proto = 'gluon_mesh',
uci:section('network', 'interface', name, })
{ end
proto = 'gluon_mesh',
}
)
end
uci:section('wireless', 'wifi-iface', name, uci:section('wireless', 'wifi-iface', name, {
{ device = radio,
device = radio, network = name,
network = name, mode = 'adhoc',
mode = 'adhoc', ssid = config.ssid,
ssid = config.ssid, bssid = config.bssid,
bssid = config.bssid, macaddr = macaddr,
macaddr = macaddr, mcast_rate = config.mcast_rate,
mcast_rate = config.mcast_rate, ifname = suffix and 'ibss' .. suffix,
ifname = suffix and 'ibss' .. suffix, disabled = disabled,
disabled = disabled, })
}
)
end end
local function configure_mesh(config, radio, index, suffix, disabled) local function configure_mesh(config, radio, index, suffix, disabled)
local name = 'mesh_' .. radio local name = 'mesh_' .. radio
local macfilter = uci:get('wireless', name, 'macfilter') local macfilter = uci:get('wireless', name, 'macfilter')
local maclist = uci:get('wireless', name, 'maclist') local maclist = uci:get('wireless', name, 'maclist')
uci:delete('network', name) uci:delete('network', name)
uci:delete('network', name .. '_vlan') uci:delete('network', name .. '_vlan')
uci:delete('wireless', name) uci:delete('wireless', name)
if not config then if not config then
return return
end end
local macaddr = util.get_wlan_mac(uci, radio, index, 2) local macaddr = util.get_wlan_mac(uci, radio, index, 2)
if not macaddr then if not macaddr then
return return
end end
uci:section('network', 'interface', name, uci:section('network', 'interface', name, {
{ proto = 'gluon_mesh',
proto = 'gluon_mesh', })
}
)
uci:section('wireless', 'wifi-iface', name, uci:section('wireless', 'wifi-iface', name, {
{ device = radio,
device = radio, network = name,
network = name, mode = 'mesh',
mode = 'mesh', mesh_id = config.id,
mesh_id = config.id, mesh_fwding = false,
mesh_fwding = false, macaddr = macaddr,
macaddr = macaddr, mcast_rate = config.mcast_rate,
mcast_rate = config.mcast_rate, ifname = suffix and 'mesh' .. suffix,
ifname = suffix and 'mesh' .. suffix, disabled = disabled,
disabled = disabled, macfilter = macfilter,
macfilter = macfilter, maclist = maclist,
maclist = maclist, })
}
)
end end
local function fixup_wan(radio, index) local function fixup_wan(radio, index)
local name = 'wan_' .. radio local name = 'wan_' .. radio
if not uci:get('wireless', name) then if not uci:get('wireless', name) then
return return
end end
local macaddr = util.get_wlan_mac(uci, radio, index, 4) local macaddr = util.get_wlan_mac(uci, radio, index, 4)
if not macaddr then if not macaddr then
return return
end end
uci:set('wireless', name, 'macaddr', macaddr) uci:set('wireless', name, 'macaddr', macaddr)
end end
local function configure_radio(radio, index, config) local function configure_radio(radio, index, config)
if not config then if not config then
return return
end end
local suffix = radio:match('^radio(%d+)$') local suffix = radio:match('^radio(%d+)$')
if not suffix then if not suffix then
return return
end end
local channel = get_channel(radio, config) local channel = get_channel(radio, config)
uci:delete('wireless', radio, 'disabled') uci:delete('wireless', radio, 'disabled')
uci:set('wireless', radio, 'channel', channel) uci:set('wireless', radio, 'channel', channel)
uci:set('wireless', radio, 'htmode', 'HT20') uci:set('wireless', radio, 'htmode', 'HT20')
uci:set('wireless', radio, 'country', site.regdom) uci:set('wireless', radio, 'country', site.regdom)
if config.supported_rates then if config.supported_rates then
uci:set_list('wireless', radio, 'supported_rates', config.supported_rates) uci:set_list('wireless', radio, 'supported_rates', config.supported_rates)
else else
uci:delete('wireless', radio, 'supported_rates') uci:delete('wireless', radio, 'supported_rates')
end end
if config.basic_rate then if config.basic_rate then
uci:set_list('wireless', radio, 'basic_rate', config.basic_rate) uci:set_list('wireless', radio, 'basic_rate', config.basic_rate)
else else
uci:delete('wireless', radio, 'basic_rate') uci:delete('wireless', radio, 'basic_rate')
end end
local ibss_disabled = is_disabled('ibss_' .. radio) local ibss_disabled = is_disabled('ibss_' .. radio)
local mesh_disabled = is_disabled('mesh_' .. radio) local mesh_disabled = is_disabled('mesh_' .. radio)
configure_ibss(config.ibss, radio, index, suffix, configure_ibss(config.ibss, radio, index, suffix,
first_non_nil( first_non_nil(
ibss_disabled, ibss_disabled,
mesh_disabled, mesh_disabled,
(config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset (config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset
false false
) )
) )
configure_mesh(config.mesh, radio, index, suffix, configure_mesh(config.mesh, radio, index, suffix,
first_non_nil( first_non_nil(
mesh_disabled, mesh_disabled,
ibss_disabled, ibss_disabled,
(config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset (config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset
false false
) )
) )
fixup_wan(radio, index) fixup_wan(radio, index)
end end
util.iterate_radios(uci, configure_radio) util.iterate_radios(uci, configure_radio)
if uci:get('system', 'rssid_wlan0') then if uci:get('system', 'rssid_wlan0') then
if uci:get('wireless', 'mesh_radio0') then if uci:get('wireless', 'mesh_radio0') then
uci:set('system', 'rssid_wlan0', 'dev', 'mesh0') uci:set('system', 'rssid_wlan0', 'dev', 'mesh0')
else else
uci:set('system', 'rssid_wlan0', 'dev', 'ibss0') uci:set('system', 'rssid_wlan0', 'dev', 'ibss0')
end end
uci:save('system') uci:save('system')
end end
uci:save('wireless') uci:save('wireless')