Merge pull request #2312 from freifunk-gluon/gluon-web-wifi-cleanup

Hide WLAN config on devices without WLAN + related cleanup
This commit is contained in:
Matthias Schiffer 2021-12-16 20:03:27 +01:00 committed by GitHub
commit b40b1c82e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 63 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -126,4 +126,52 @@ 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_wlan(uci)
local ret = false
uci:foreach('wireless', 'wifi-device', function()
ret = true
return false
end)
return ret
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

View File

@ -1,3 +1,8 @@
local uci = require("simple-uci").cursor()
local wireless = require 'gluon.wireless'
package 'gluon-web-private-wifi'
if wireless.device_uses_wlan(uci) then
entry({"admin", "privatewifi"}, model("admin/privatewifi"), _("Private WLAN"), 30)
end

View File

@ -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')

View File

@ -1,3 +1,8 @@
local uci = require("simple-uci").cursor()
local wireless = require 'gluon.wireless'
package 'gluon-web-wifi-config'
if wireless.device_uses_wlan(uci) then
entry({"admin", "wifi-config"}, model("admin/wifi-config"), _("WLAN"), 20)
end

View File

@ -24,18 +24,6 @@ local function txpower_list(phy)
return new
end
local function has_5ghz_radio()
local result = false
uci:foreach('wireless', 'wifi-device', function(config)
local radio = config['.name']
local hwmode = uci:get('wireless', radio, 'hwmode')
result = result or (hwmode == '11a' or hwmode == '11na')
end)
return result
end
local f = Form(translate("WLAN"))
f:section(Section, nil, translate(
@ -142,7 +130,7 @@ uci:foreach('wireless', 'wifi-device', function(config)
end)
if has_5ghz_radio() and not wireless.preserve_channels(uci) then
if wireless.device_uses_11a(uci) and not wireless.preserve_channels(uci) then
local r = f:section(Section, translate("Outdoor Installation"), translate(
"Configuring the node for outdoor use tunes the 5 GHz radio to a frequency "
.. "and transmission power that conforms with the local regulatory requirements. "