From 06d0c0f211205c1b16f494c96ea4dac42b963571 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 8 Aug 2017 04:09:00 +0200 Subject: [PATCH] gluon-core: fix 200-wireless coding style --- .../luasrc/lib/gluon/upgrade/200-wireless | 284 +++++++++--------- 1 file changed, 136 insertions(+), 148 deletions(-) diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless index ba844950..4415a197 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless @@ -8,208 +8,196 @@ local uci = require('simple-uci').cursor() -- Initial if not sysconfig.gluon_version then - uci:delete_all('wireless', 'wifi-iface') + uci:delete_all('wireless', 'wifi-iface') end local function get_channel(radio, config) - if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then - return uci:get('wireless', radio, 'channel') or config.channel - else - return config.channel - end + if uci:get_first('gluon-core', 'wireless', 'preserve_channels') then + return uci:get('wireless', radio, 'channel') or config.channel + else + return config.channel + end end local function is_disabled(name) - if uci:get('wireless', name) then - return uci:get_bool('wireless', name, 'disabled') - else - return false - end + if uci:get('wireless', name) then + return uci:get_bool('wireless', name, 'disabled') + else + return false + end end -- Returns the first argument that is not nil; don't call without any non-nil arguments! local function first_non_nil(first, ...) - if first ~= nil then - return first - else - return first_non_nil(...) - end + if first ~= nil then + return first + else + return first_non_nil(...) + end end 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 .. '_vlan') - uci:delete('wireless', name) + uci:delete('network', name) + uci:delete('network', name .. '_vlan') + uci:delete('wireless', name) - if not config then - return - end + if not config then + return + end - local macaddr = util.get_wlan_mac(uci, radio, index, 3) - if not macaddr then - return - end + local macaddr = util.get_wlan_mac(uci, radio, index, 3) + if not macaddr then + return + end - if config.vlan then - uci:section('network', 'interface', name, - { - proto = 'none', - } - ) + if config.vlan then + uci:section('network', 'interface', name, { + proto = 'none', + }) - uci:section('network', 'interface', name .. '_vlan', - { - ifname = '@' .. name .. '.' .. config.vlan, - proto = 'gluon_mesh', - } - ) - else - uci:section('network', 'interface', name, - { - proto = 'gluon_mesh', - } - ) - end + uci:section('network', 'interface', name .. '_vlan', { + ifname = '@' .. name .. '.' .. config.vlan, + proto = 'gluon_mesh', + }) + else + uci:section('network', 'interface', name, { + proto = 'gluon_mesh', + }) + end - uci:section('wireless', 'wifi-iface', name, - { - device = radio, - network = name, - mode = 'adhoc', - ssid = config.ssid, - bssid = config.bssid, - macaddr = macaddr, - mcast_rate = config.mcast_rate, - ifname = suffix and 'ibss' .. suffix, - disabled = disabled, - } - ) + uci:section('wireless', 'wifi-iface', name, { + device = radio, + network = name, + mode = 'adhoc', + ssid = config.ssid, + bssid = config.bssid, + macaddr = macaddr, + mcast_rate = config.mcast_rate, + ifname = suffix and 'ibss' .. suffix, + disabled = disabled, + }) end local function configure_mesh(config, radio, index, suffix, disabled) - local name = 'mesh_' .. radio - local macfilter = uci:get('wireless', name, 'macfilter') - local maclist = uci:get('wireless', name, 'maclist') + local name = 'mesh_' .. radio + local macfilter = uci:get('wireless', name, 'macfilter') + local maclist = uci:get('wireless', name, 'maclist') - uci:delete('network', name) - uci:delete('network', name .. '_vlan') - uci:delete('wireless', name) + uci:delete('network', name) + uci:delete('network', name .. '_vlan') + uci:delete('wireless', name) - if not config then - return - end + if not config then + return + end - local macaddr = util.get_wlan_mac(uci, radio, index, 2) - if not macaddr then - return - end + local macaddr = util.get_wlan_mac(uci, radio, index, 2) + if not macaddr then + return + end - uci:section('network', 'interface', name, - { - proto = 'gluon_mesh', - } - ) + uci:section('network', 'interface', name, { + proto = 'gluon_mesh', + }) - uci:section('wireless', 'wifi-iface', name, - { - device = radio, - network = name, - mode = 'mesh', - mesh_id = config.id, - mesh_fwding = false, - macaddr = macaddr, - mcast_rate = config.mcast_rate, - ifname = suffix and 'mesh' .. suffix, - disabled = disabled, - macfilter = macfilter, - maclist = maclist, - } - ) + uci:section('wireless', 'wifi-iface', name, { + device = radio, + network = name, + mode = 'mesh', + mesh_id = config.id, + mesh_fwding = false, + macaddr = macaddr, + mcast_rate = config.mcast_rate, + ifname = suffix and 'mesh' .. suffix, + disabled = disabled, + macfilter = macfilter, + maclist = maclist, + }) end local function fixup_wan(radio, index) - local name = 'wan_' .. radio + local name = 'wan_' .. radio - if not uci:get('wireless', name) then - return - end + if not uci:get('wireless', name) then + return + end - local macaddr = util.get_wlan_mac(uci, radio, index, 4) - if not macaddr then - return - end + local macaddr = util.get_wlan_mac(uci, radio, index, 4) + if not macaddr then + return + end - uci:set('wireless', name, 'macaddr', macaddr) + uci:set('wireless', name, 'macaddr', macaddr) end local function configure_radio(radio, index, config) - if not config then - return - end + if not config then + return + end - local suffix = radio:match('^radio(%d+)$') - if not suffix then - return - end + local suffix = radio:match('^radio(%d+)$') + if not suffix then + return + 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, 'htmode', 'HT20') - uci:set('wireless', radio, 'country', site.regdom) + uci:set('wireless', radio, 'channel', channel) + uci:set('wireless', radio, 'htmode', 'HT20') + uci:set('wireless', radio, 'country', site.regdom) - if config.supported_rates then - uci:set_list('wireless', radio, 'supported_rates', config.supported_rates) - else - uci:delete('wireless', radio, 'supported_rates') - end + if config.supported_rates then + uci:set_list('wireless', radio, 'supported_rates', config.supported_rates) + else + uci:delete('wireless', radio, 'supported_rates') + end - if config.basic_rate then - uci:set_list('wireless', radio, 'basic_rate', config.basic_rate) - else - uci:delete('wireless', radio, 'basic_rate') - end + if config.basic_rate then + uci:set_list('wireless', radio, 'basic_rate', config.basic_rate) + else + uci:delete('wireless', radio, 'basic_rate') + end - local ibss_disabled = is_disabled('ibss_' .. radio) - local mesh_disabled = is_disabled('mesh_' .. radio) + local ibss_disabled = is_disabled('ibss_' .. radio) + local mesh_disabled = is_disabled('mesh_' .. radio) - configure_ibss(config.ibss, radio, index, suffix, - first_non_nil( - ibss_disabled, - mesh_disabled, - (config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset - false - ) - ) - configure_mesh(config.mesh, radio, index, suffix, - first_non_nil( - mesh_disabled, - ibss_disabled, - (config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset - false - ) - ) + configure_ibss(config.ibss, radio, index, suffix, + first_non_nil( + ibss_disabled, + mesh_disabled, + (config.ibss or {}).disabled, -- will be nil if config.ibss or config.ibss.disabled is unset + false + ) + ) + configure_mesh(config.mesh, radio, index, suffix, + first_non_nil( + mesh_disabled, + ibss_disabled, + (config.mesh or {}).disabled, -- will be nil if config.mesh or config.mesh.disabled is unset + false + ) + ) - fixup_wan(radio, index) + fixup_wan(radio, index) end util.iterate_radios(uci, configure_radio) if uci:get('system', 'rssid_wlan0') then - if uci:get('wireless', 'mesh_radio0') then - uci:set('system', 'rssid_wlan0', 'dev', 'mesh0') - else - uci:set('system', 'rssid_wlan0', 'dev', 'ibss0') - end + if uci:get('wireless', 'mesh_radio0') then + uci:set('system', 'rssid_wlan0', 'dev', 'mesh0') + else + uci:set('system', 'rssid_wlan0', 'dev', 'ibss0') + end - uci:save('system') + uci:save('system') end uci:save('wireless')