Skip to content
Snippets Groups Projects
Unverified Commit 06d0c0f2 authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

gluon-core: fix 200-wireless coding style

parent 2b9dd54f
No related branches found
No related tags found
No related merge requests found
...@@ -8,208 +8,196 @@ local uci = require('simple-uci').cursor() ...@@ -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', {
ifname = '@' .. name .. '.' .. config.vlan,
uci:section('network', 'interface', name .. '_vlan', proto = 'gluon_mesh',
{ })
ifname = '@' .. name .. '.' .. config.vlan, else
proto = 'gluon_mesh', uci:section('network', 'interface', name, {
} proto = 'gluon_mesh',
) })
else end
uci:section('network', 'interface', name,
{ uci:section('wireless', 'wifi-iface', name, {
proto = 'gluon_mesh', device = radio,
} network = name,
) mode = 'adhoc',
end ssid = config.ssid,
bssid = config.bssid,
uci:section('wireless', 'wifi-iface', name, macaddr = macaddr,
{ mcast_rate = config.mcast_rate,
device = radio, ifname = suffix and 'ibss' .. suffix,
network = name, disabled = disabled,
mode = 'adhoc', })
ssid = config.ssid,
bssid = config.bssid,
macaddr = macaddr,
mcast_rate = config.mcast_rate,
ifname = suffix and 'ibss' .. suffix,
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, {
device = radio,
uci:section('wireless', 'wifi-iface', name, network = name,
{ mode = 'mesh',
device = radio, mesh_id = config.id,
network = name, mesh_fwding = false,
mode = 'mesh', macaddr = macaddr,
mesh_id = config.id, mcast_rate = config.mcast_rate,
mesh_fwding = false, ifname = suffix and 'mesh' .. suffix,
macaddr = macaddr, disabled = disabled,
mcast_rate = config.mcast_rate, macfilter = macfilter,
ifname = suffix and 'mesh' .. suffix, maclist = maclist,
disabled = disabled, })
macfilter = macfilter,
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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment