From 7a2cd66cb9ad7462245bb2ad7735fe7b49c0d44a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 13 Sep 2021 17:37:59 +0200 Subject: [PATCH] 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. --- .../upgrade/320-gluon-client-bridge-wireless | 5 +-- .../gluon/config-mode/wizard/0250-outdoor.lua | 2 +- .../luasrc/lib/gluon/upgrade/180-outdoors | 3 +- .../luasrc/usr/lib/lua/gluon/platform.lua | 39 ------------------- .../luasrc/usr/lib/lua/gluon/wireless.lua | 37 ++++++++++++++++++ .../config-mode/model/admin/privatewifi.lua | 7 ++-- 6 files changed, 45 insertions(+), 48 deletions(-) diff --git a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless index 972b9b61..b74af5bf 100755 --- a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless +++ b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless @@ -1,6 +1,5 @@ #!/usr/bin/lua -local platform = require 'gluon.platform' local wireless = require 'gluon.wireless' 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 -- 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 end @@ -80,7 +79,7 @@ local function configure_owe_transition_mode(config, radio_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 + if not wireless.device_supports_mfp(uci) then return end diff --git a/package/gluon-config-mode-outdoor/luasrc/lib/gluon/config-mode/wizard/0250-outdoor.lua b/package/gluon-config-mode-outdoor/luasrc/lib/gluon/config-mode/wizard/0250-outdoor.lua index 2fbc0fba..2ddf0a85 100644 --- a/package/gluon-config-mode-outdoor/luasrc/lib/gluon/config-mode/wizard/0250-outdoor.lua +++ b/package/gluon-config-mode-outdoor/luasrc/lib/gluon/config-mode/wizard/0250-outdoor.lua @@ -2,7 +2,7 @@ return function(form, uci) local platform = require 'gluon.platform' 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 return end diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors b/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors index 5c5a92e2..59704bff 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors @@ -13,6 +13,7 @@ end local sysconfig = require 'gluon.sysconfig' local platform = require 'gluon.platform' +local wireless = require 'gluon.wireless' local config = site.wifi5.outdoors('preset') local outdoor @@ -22,7 +23,7 @@ if sysconfig.gluon_version then outdoor = false elseif config == 'preset' then -- 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 -- enable/disable outdoor mode unconditionally on new installs outdoor = config diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua index 9c4974ea..df0eda08 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/platform.lua @@ -1,7 +1,5 @@ local platform_info = require 'platform_info' local util = require 'gluon.util' -local wireless = require 'gluon.wireless' -local unistd = require 'posix.unistd' local M = setmetatable({}, { @@ -48,41 +46,4 @@ function M.is_outdoor_device() return false 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 diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua index 0eb68023..0eec8a83 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua @@ -126,4 +126,41 @@ function M.preserve_channels(uci) return uci:get_first('gluon-core', 'wireless', 'preserve_channels') 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 diff --git a/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua b/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua index a3b80432..8be95ed6 100644 --- a/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua +++ b/package/gluon-web-private-wifi/luasrc/lib/gluon/config-mode/model/admin/privatewifi.lua @@ -1,5 +1,4 @@ local uci = require("simple-uci").cursor() -local platform = require 'gluon.platform' local wireless = require 'gluon.wireless' -- 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")) encryption:depends(enabled, true) 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", translate("WPA3")) 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")) mfp:depends(enabled, true) 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("2", translate("Required")) end @@ -68,7 +67,7 @@ function f:write() }) -- 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) else uci:delete('wireless', name, 'ieee80211w')