gluon-core: move a few WLAN-specific functions from gluon.platform to gluon.wireless

Avoid requiring gluon.wireless from gluon.platform, and requiring
gluon.platform from various other scripts.
This commit is contained in:
Matthias Schiffer 2021-09-13 17:37:59 +02:00
parent 077439de46
commit 7a2cd66cb9
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
6 changed files with 45 additions and 48 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/lua #!/usr/bin/lua
local platform = require 'gluon.platform'
local wireless = require 'gluon.wireless' local wireless = require 'gluon.wireless'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
@ -52,7 +51,7 @@ local function configure_owe(radio, index, config, radio_name)
-- Don't configure OWE in case our device -- Don't configure OWE in case our device
-- can't do MFP, as it's mandatory for OWE. -- can't do MFP, as it's mandatory for OWE.
if not platform.device_supports_mfp(uci) then if not wireless.device_supports_mfp(uci) then
return return
end end
@ -80,7 +79,7 @@ local function configure_owe_transition_mode(config, radio_name)
-- Don't configure OWE in case our device -- Don't configure OWE in case our device
-- can't do MFP, as it's mandatory for OWE. -- can't do MFP, as it's mandatory for OWE.
if not platform.device_supports_mfp(uci) then if not wireless.device_supports_mfp(uci) then
return return
end end

View File

@ -2,7 +2,7 @@ return function(form, uci)
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local wireless = require 'gluon.wireless' local wireless = require 'gluon.wireless'
if not (platform.is_outdoor_device() and platform.device_uses_11a(uci)) then if not (platform.is_outdoor_device() and wireless.device_uses_11a(uci)) then
-- only visible on wizard for outdoor devices -- only visible on wizard for outdoor devices
return return
end end

View File

@ -13,6 +13,7 @@ end
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local wireless = require 'gluon.wireless'
local config = site.wifi5.outdoors('preset') local config = site.wifi5.outdoors('preset')
local outdoor local outdoor
@ -22,7 +23,7 @@ if sysconfig.gluon_version then
outdoor = false outdoor = false
elseif config == 'preset' then elseif config == 'preset' then
-- enable outdoor mode through presets on new installs -- enable outdoor mode through presets on new installs
outdoor = platform.is_outdoor_device() and platform.device_uses_11a(uci) outdoor = platform.is_outdoor_device() and wireless.device_uses_11a(uci)
else else
-- enable/disable outdoor mode unconditionally on new installs -- enable/disable outdoor mode unconditionally on new installs
outdoor = config outdoor = config

View File

@ -1,7 +1,5 @@
local platform_info = require 'platform_info' local platform_info = require 'platform_info'
local util = require 'gluon.util' local util = require 'gluon.util'
local wireless = require 'gluon.wireless'
local unistd = require 'posix.unistd'
local M = setmetatable({}, { local M = setmetatable({}, {
@ -48,41 +46,4 @@ function M.is_outdoor_device()
return false return false
end end
function M.device_supports_wpa3()
return unistd.access('/lib/gluon/features/wpa3')
end
function M.device_supports_mfp(uci)
local supports_mfp = true
if not M.device_supports_wpa3() then
return false
end
uci:foreach('wireless', 'wifi-device', function(radio)
local phy = wireless.find_phy(radio)
local phypath = '/sys/kernel/debug/ieee80211/' .. phy .. '/'
if not util.file_contains_line(phypath .. 'hwflags', 'MFP_CAPABLE') then
supports_mfp = false
return false
end
end)
return supports_mfp
end
function M.device_uses_11a(uci)
local ret = false
uci:foreach('wireless', 'wifi-device', function(radio)
if radio.hwmode == '11a' or radio.hwmode == '11na' then
ret = true
return false
end
end)
return ret
end
return M return M

View File

@ -126,4 +126,41 @@ function M.preserve_channels(uci)
return uci:get_first('gluon-core', 'wireless', 'preserve_channels') return uci:get_first('gluon-core', 'wireless', 'preserve_channels')
end end
function M.device_supports_wpa3()
return unistd.access('/lib/gluon/features/wpa3')
end
function M.device_supports_mfp(uci)
local supports_mfp = true
if not M.device_supports_wpa3() then
return false
end
uci:foreach('wireless', 'wifi-device', function(radio)
local phy = M.find_phy(radio)
local phypath = '/sys/kernel/debug/ieee80211/' .. phy .. '/'
if not util.file_contains_line(phypath .. 'hwflags', 'MFP_CAPABLE') then
supports_mfp = false
return false
end
end)
return supports_mfp
end
function M.device_uses_11a(uci)
local ret = false
uci:foreach('wireless', 'wifi-device', function(radio)
if radio.hwmode == '11a' or radio.hwmode == '11na' then
ret = true
return false
end
end)
return ret
end
return M return M

View File

@ -1,5 +1,4 @@
local uci = require("simple-uci").cursor() local uci = require("simple-uci").cursor()
local platform = require 'gluon.platform'
local wireless = require 'gluon.wireless' local wireless = require 'gluon.wireless'
-- where to read the configuration from -- where to read the configuration from
@ -30,7 +29,7 @@ key.default = uci:get('wireless', primary_iface, "key")
local encryption = s:option(ListValue, "encryption", translate("Encryption")) local encryption = s:option(ListValue, "encryption", translate("Encryption"))
encryption:depends(enabled, true) encryption:depends(enabled, true)
encryption:value("psk2", translate("WPA2")) encryption:value("psk2", translate("WPA2"))
if platform.device_supports_wpa3() then if wireless.device_supports_wpa3() then
encryption:value("psk3-mixed", translate("WPA2 / WPA3")) encryption:value("psk3-mixed", translate("WPA2 / WPA3"))
encryption:value("psk3", translate("WPA3")) encryption:value("psk3", translate("WPA3"))
end end
@ -39,7 +38,7 @@ encryption.default = uci:get('wireless', primary_iface, 'encryption') or "psk2"
local mfp = s:option(ListValue, "mfp", translate("Management Frame Protection")) local mfp = s:option(ListValue, "mfp", translate("Management Frame Protection"))
mfp:depends(enabled, true) mfp:depends(enabled, true)
mfp:value("0", translate("Disabled")) mfp:value("0", translate("Disabled"))
if platform.device_supports_mfp(uci) then if wireless.device_supports_mfp(uci) then
mfp:value("1", translate("Optional")) mfp:value("1", translate("Optional"))
mfp:value("2", translate("Required")) mfp:value("2", translate("Required"))
end end
@ -68,7 +67,7 @@ function f:write()
}) })
-- hostapd-mini won't start in case 802.11w is configured -- hostapd-mini won't start in case 802.11w is configured
if platform.device_supports_mfp(uci) then if wireless.device_supports_mfp(uci) then
uci:set('wireless', name, 'ieee80211w', mfp.data) uci:set('wireless', name, 'ieee80211w', mfp.data)
else else
uci:delete('wireless', name, 'ieee80211w') uci:delete('wireless', name, 'ieee80211w')