gluon/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless
David Bauer b1de28bab1 gluon-core: move wireless-related utils to wireless module
Separate wireless-related helper methods from the util module to a
new wireless module. This keeps them separated, as the amount of
wireless helpers increased in the past, justifying a separate module.
2020-05-28 21:46:23 +02:00

122 lines
3.0 KiB
Lua
Executable File

#!/usr/bin/lua
local platform = require 'gluon.platform'
local wireless = require 'gluon.wireless'
local uci = require('simple-uci').cursor()
local function is_disabled(config, name)
if uci:get('wireless', name) then
return uci:get_bool('wireless', name, 'disabled')
end
return config.disabled(false)
end
local function configure_ap(radio, index, config, radio_name)
local name = 'client_' .. radio_name
local suffix = radio_name:match('^radio(%d+)$')
local ap = config.ap
local disabled = is_disabled(ap, name)
uci:delete('wireless', name)
local macaddr = wireless.get_wlan_mac(uci, radio, index, 1)
if not ap.ssid() or not macaddr then
return
end
uci:section('wireless', 'wifi-iface', name, {
device = radio_name,
network = 'client',
mode = 'ap',
ssid = ap.ssid(),
macaddr = macaddr,
ifname = suffix and 'client' .. suffix,
disabled = disabled or false,
})
end
local function configure_owe(radio, index, config, radio_name)
local name = 'owe_' .. radio_name
local suffix = radio_name:match('^radio(%d+)$')
local ap = config.ap
local disabled = is_disabled(ap, 'client_' .. radio_name)
uci:delete('wireless', name)
-- Don't configure OWE in case our device
-- can't do MFP, as it's mandatory for OWE.
if not platform.device_supports_mfp(uci) then
return
end
local macaddr = wireless.get_wlan_mac(uci, radio, index, 3)
if not ap.owe_ssid() or not macaddr then
return
end
uci:section('wireless', 'wifi-iface', name, {
device = radio_name,
network = 'client',
mode = 'ap',
ssid = ap.owe_ssid(),
macaddr = macaddr,
ifname = suffix and 'owe' .. suffix,
disabled = disabled or false,
encryption = 'owe',
ieee80211w = 2,
})
end
local function configure_owe_transition_mode(config, radio_name)
local ap = config.ap
-- Don't configure OWE in case our device
-- can't do MFP, as it's mandatory for OWE.
if not platform.device_supports_mfp(uci) then
return
end
if not ap.owe_transition_mode(false) then
return
end
local name_client = 'client_' .. radio_name
local name_owe = 'owe_' .. radio_name
local ssid_client = uci:get('wireless', name_client, 'ssid')
local ssid_owe = uci:get('wireless', name_owe, 'ssid')
local macaddr_client = uci:get('wireless', name_client, 'macaddr')
local macaddr_owe = uci:get('wireless', name_owe, 'macaddr')
if not (ssid_client and ssid_owe and macaddr_client and macaddr_owe) then
return
end
uci:set('wireless', name_client, 'owe_transition_ssid', ssid_owe)
uci:set('wireless', name_client, 'owe_transition_bssid', macaddr_owe)
uci:set('wireless', name_owe, 'owe_transition_ssid', ssid_client)
uci:set('wireless', name_owe, 'owe_transition_bssid', macaddr_client)
uci:set('wireless', name_owe, 'hidden', '1')
end
wireless.foreach_radio(uci, function(radio, index, config)
local radio_name = radio['.name']
configure_ap(radio, index, config, radio_name)
configure_owe(radio, index, config, radio_name)
configure_owe_transition_mode(config, radio_name)
end)
uci:save('wireless')