Skip to content

Commit

Permalink
gluon-core: deactivate client radios in case a dedicated client radio…
Browse files Browse the repository at this point in the history
… is present
  • Loading branch information
blocktrron authored and maurerle committed Oct 13, 2024
1 parent 294b291 commit ed03658
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
local wireless = require 'gluon.wireless'

local uci = require('simple-uci').cursor()
local sysconfig = require 'gluon.sysconfig'
local iwinfo = require 'iwinfo'


local function is_disabled(config, name)
Expand All @@ -13,13 +15,19 @@ local function is_disabled(config, name)
return config.disabled(false)
end

local has_client_radio = false

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)

if not util.supports_channel(radio, config.channel()) then
has_client_radio = true
end

uci:delete('wireless', name)

local macaddr = wireless.get_wlan_mac(uci, radio, index, 1)
Expand Down Expand Up @@ -112,4 +120,16 @@ wireless.foreach_radio(uci, function(radio, index, config)
configure_owe_transition_mode(config, radio_name)
end)

if not sysconfig.gluon_version and has_client_radio then
util.foreach_radio(uci, function(radio, index, config)
local radio_name = radio['.name']

local name = 'client_' .. radio_name

if util.supports_channel(radio, config.channel()) and (radio.hwmode == '11a' or radio.hwmode == '11na') then
uci:set('wireless', name, 'disabled', true)
end
end)
end

uci:save('wireless')
4 changes: 2 additions & 2 deletions package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local function is_outdoor()
end

local function get_channel(radio, config)
if radio.band == '5g' and is_outdoor() then
if radio.band == '5g' and (is_outdoor() or not util.supports_channel(radio, config.channel())) then
-- actual channel will be picked and probed from chanlist
return 'auto'
end
Expand Down Expand Up @@ -227,7 +227,7 @@ wireless.foreach_radio(uci, function(radio, index, config)
util.remove_from_set(hostapd_options, 'country3=0x4f')
uci:set_list('wireless', radio_name, 'hostapd_options', hostapd_options)

if is_outdoor() then
if is_outdoor() or not util.supports_channel(radio, config.channel()) then
-- enforce outdoor channels by filtering the regdom for outdoor channels
uci:set('wireless', radio_name, 'country3', '0x4f')
configure_mesh_wireless(radio, index, config, true)
Expand Down
10 changes: 10 additions & 0 deletions package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ function M.get_role_interfaces(uci, role, exclusive)
return ret
end

local function supports_channel(radio, channel)
local phy = M.find_phy(radio)
for i, chan in ipairs(iwinfo.nl80211.freqlist(phy)) do
if channel == chan.channel then
return true
end
end
return false
end

-- Safe glob: returns an empty table when the glob fails because of
-- a non-existing path
function M.glob(pattern)
Expand Down

0 comments on commit ed03658

Please sign in to comment.