More multi-radio support (#860)

* Multi-radio: Support different powers for different radios
* Use arrays for powers
* Update APIs to take wifi interface
This commit is contained in:
Tim Wilkinson 2023-06-02 18:47:34 -07:00 committed by GitHub
parent 225773cf06
commit 60a2627989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 27 deletions

View File

@ -225,10 +225,10 @@
"maxpower" : "25" "maxpower" : "25"
}, },
"MikroTik hAP ac2" : { "MikroTik hAP ac2" : {
"maxpower" : "27" "maxpower" : [ "27", "26" ]
}, },
"MikroTik hAP ac3" : { "MikroTik hAP ac3" : {
"maxpower" : "27" "maxpower" : [ "26", "26" ]
}, },
"0xe005" : { "0xe005" : {
"name" : "Ubiquiti NanoStation M5", "name" : "Ubiquiti NanoStation M5",
@ -470,8 +470,8 @@
}, },
"0xe7fc": { "0xe7fc": {
"name" : "Ubiquiti NanoBeam AC Gen2 (WA)", "name" : "Ubiquiti NanoBeam AC Gen2 (WA)",
"maxpower" : "25", "maxpower" : [ "25", "20" ],
"pwroffset" : "2" "pwroffset" : [ "2", "0" ]
}, },
"0xe7f9": { "0xe7f9": {
"name" : "Ubiquiti LiteBeam 5AC Gen2", "name" : "Ubiquiti LiteBeam 5AC Gen2",

View File

@ -83,8 +83,8 @@ function module:GET()
data.meshrf.distance = aredn_info.getMeshRadioDistance(radio) data.meshrf.distance = aredn_info.getMeshRadioDistance(radio)
data.meshrf.bw = aredn_info.getChannelBW(radio) data.meshrf.bw = aredn_info.getChannelBW(radio)
data.meshrf.channel = aredn_info.getChannel(radio) data.meshrf.channel = aredn_info.getChannel(radio)
data.meshrf.power = aredn_info.getTXPower() data.meshrf.power = aredn_info.getTXPower(radio)
data.meshrf.maxpower = aredn_hardware.wifi_maxpower(data['meshrf']['channel']) data.meshrf.maxpower = aredn_hardware.wifi_maxpower(radio, data['meshrf']['channel'])
-- LAN -- LAN

View File

@ -70,21 +70,31 @@ function hardware.get_radio()
return radio_json return radio_json
end end
function hardware.wifi_maxpower(channel) function hardware.wifi_maxpower(wifiintf, channel)
local radio = hardware.get_radio() local radio = hardware.get_radio()
if radio then if radio then
if radio.chanpower then local maxpower = radio.maxpower
for k, v in pairs(radio.chanpower) local chanpower = radio.chanpower
if chanpower then
if type(maxpower) == "table" then
chanpower = chanpower[1 + tonumber(wifiintf:match("(%d+)$"))]
end
for k, v in pairs(chanpower)
do do
if channel <= tonumber(k) then if channel <= tonumber(k) then
return tonumber(v) return tonumber(v)
end end
end end
elseif radio.maxpower then end
return tonumber(radio.maxpower) if type(maxpower) == "table" then
maxpower = maxpower[1 + tonumber(wifiintf:match("(%d+)$"))]
end
maxpower = tonumber(maxpower)
if maxpower then
return maxpower
end end
end end
return 27 -- if all else fails return 27 -- default
end end
function hardware.wifi_poweroffset(wifiintf) function hardware.wifi_poweroffset(wifiintf)
@ -102,10 +112,17 @@ function hardware.wifi_poweroffset(wifiintf)
f:close() f:close()
end end
local radio = hardware.get_radio() local radio = hardware.get_radio()
if radio and tonumber(radio.pwroffset) then if radio then
return tonumber(radio.pwroffset) local pwroffset = radio.pwroffset
if type(pwroffset) == "table" then
pwroffset = pwroffset[1 + tonumber(wifiintf:match("(%d+)$"))]
end
pwroffset = tonumber(pwroffset)
if pwroffset then
return pwroffset
end
end end
return 0 -- if all else fails return 0 -- default
end end
function hardware.get_board_id() function hardware.get_board_id()

View File

@ -256,8 +256,7 @@ end
------------------------------------- -------------------------------------
-- Return TX Power -- Return TX Power
------------------------------------- -------------------------------------
function model.getTXPower() function model.getTXPower(wlanInf)
local wlanInf=get_ifname('wifi')
local api=iwinfo.type(wlanInf) local api=iwinfo.type(wlanInf)
local iw = iwinfo[api] local iw = iwinfo[api]
local power = iw.txpower(wlanInf) local power = iw.txpower(wlanInf)
@ -267,8 +266,7 @@ end
------------------------------------- -------------------------------------
-- Return Frequency -- Return Frequency
------------------------------------- -------------------------------------
function model.getFreq() function model.getFreq(wlanInf)
local wlanInf=get_ifname('wifi')
local api=iwinfo.type(wlanInf) local api=iwinfo.type(wlanInf)
local iw = iwinfo[api] local iw = iwinfo[api]
local freq = iw.frequency(wlanInf) local freq = iw.frequency(wlanInf)

View File

@ -650,8 +650,8 @@ if sf then
sf:write("#!/bin/sh\n") sf:write("#!/bin/sh\n")
if cfg.wifi_proto ~= "disabled" then if cfg.wifi_proto ~= "disabled" then
local wifi_channel = tonumber(cfg.wifi_channel) local wifi_channel = tonumber(cfg.wifi_channel)
if is_null(cfg.wifi_txpower) or tonumber(cfg.wifi_txpower) > aredn.hardware.wifi_maxpower(wifi_channel) then if is_null(cfg.wifi_txpower) or tonumber(cfg.wifi_txpower) > aredn.hardware.wifi_maxpower(cfg.wifi_intf, wifi_channel) then
cfg.wifi_txpower = aredn.hardware.wifi_maxpower(wifi_channel) cfg.wifi_txpower = aredn.hardware.wifi_maxpower(cfg.wifi_intf, wifi_channel)
elseif tonumber(cfg.wifi_txpower) < 1 then elseif tonumber(cfg.wifi_txpower) < 1 then
cfg.wifi_txpower = 1 cfg.wifi_txpower = 1
end end

View File

@ -170,7 +170,7 @@ if loops == 0 then
end end
local myssid = aredn.info.getSSID() local myssid = aredn.info.getSSID()
local myfreq = tonumber(aredn.info.getFreq()) local myfreq = tonumber(aredn.info.getFreq(iface))
for _ = 1,loops for _ = 1,loops
do do

View File

@ -111,7 +111,7 @@ local f = io.popen("iw dev " .. wifiiface .. " station dump")
if f then if f then
local scan = {} local scan = {}
local myssid = aredn_info.getSSID() local myssid = aredn_info.getSSID()
local myfreq = tonumber(aredn_info.getFreq()) local myfreq = tonumber(aredn_info.getFreq(wifiiface))
for line in f:lines() for line in f:lines()
do do
local m = line:match("^Station ([%da-fA-F:]+) %(on " .. wifiiface .. "%)") local m = line:match("^Station ([%da-fA-F:]+) %(on " .. wifiiface .. "%)")

View File

@ -362,8 +362,8 @@ if cursor:get("aredn", "@lqm[0]", "enable") == "1" then
end end
-- sanitize the active settings -- sanitize the active settings
if not wifi_txpower or wifi_txpower > aredn.hardware.wifi_maxpower(wifi_channel) then if not wifi_txpower or wifi_txpower > aredn.hardware.wifi_maxpower(wifi_intf, wifi_channel) then
wifi_txpower = aredn.hardware.wifi_maxpower(wifi_channel) wifi_txpower = aredn.hardware.wifi_maxpower(wifi_intf, wifi_channel)
end end
if not wifi_power or wifi_power < 1 then if not wifi_power or wifi_power < 1 then
wifi_power = 1 wifi_power = 1
@ -1113,7 +1113,7 @@ if wifi_enable == "1" then
end end
html.print("<tr><td><nobr>Tx Power</nobr></td><td><select name=wifi_txpower>") html.print("<tr><td><nobr>Tx Power</nobr></td><td><select name=wifi_txpower>")
local txpoweroffset = aredn.hardware.wifi_poweroffset(wifi_intf) local txpoweroffset = aredn.hardware.wifi_poweroffset(wifi_intf)
for i = aredn.hardware.wifi_maxpower(wifi_channel),1,-1 for i = aredn.hardware.wifi_maxpower(wifi_intf, wifi_channel),1,-1
do do
html.print("<option value='" .. i .. "'".. (i == tonumber(wifi_txpower) and " selected" or "") .. ">" .. (txpoweroffset + i) .. " dBm</option>") html.print("<option value='" .. i .. "'".. (i == tonumber(wifi_txpower) and " selected" or "") .. ">" .. (txpoweroffset + i) .. " dBm</option>")
end end

View File

@ -93,7 +93,7 @@ if ( radio ~= nil and radio ~= "" ) then
info['meshrf']['ssid']=aredn_info.getSSID() info['meshrf']['ssid']=aredn_info.getSSID()
info['meshrf']['channel']=aredn_info.getChannel(radio) info['meshrf']['channel']=aredn_info.getChannel(radio)
info['meshrf']['chanbw']=aredn_info.getChannelBW(radio) info['meshrf']['chanbw']=aredn_info.getChannelBW(radio)
info['meshrf']['freq']=aredn_info.getFreq() info['meshrf']['freq']=aredn_info.getFreq(radio)
else else
info['meshrf']['status']="off" info['meshrf']['status']="off"
end end