Improve dual radio customization support (#961)

This commit is contained in:
Tim Wilkinson 2023-10-13 22:38:05 -07:00 committed by GitHub
parent 88d543498c
commit cdeb1b1d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 117 additions and 76 deletions

View File

@ -178,19 +178,42 @@
"maxpower": "30"
},
"mikrotik routerboard 921gs-5hpacd-15s": {
"maxpower": "31"
"maxpower": "31",
"bandwidths": [ 10, 20 ]
},
"mikrotik routerboard 921gs-5hpacd-19s": {
"maxpower": "31"
"maxpower": "31",
"bandwidths": [ 10, 20 ]
},
"mikrotik routerboard 952ui-5ac2nd": {
"maxpower": "22"
"wlan0": {
"maxpower": 22,
"bandwidths": [ 5, 10, 20 ]
},
"wlan1": {
"maxpower": 22,
"bandwidths": [ 10, 20 ]
}
},
"mikrotik routerboard rb952ui-5ac2nd": {
"maxpower": "22"
"wlan0": {
"maxpower": 22,
"bandwidths": [ 5, 10, 20 ]
},
"wlan1": {
"maxpower": 22,
"bandwidths": [ 10, 20 ]
}
},
"mikrotik routerboard 952ui-5ac2nd (hap ac lite)": {
"maxpower": "22"
"wlan0": {
"maxpower": 22,
"bandwidths": [ 5, 10, 20 ]
},
"wlan1": {
"maxpower": 22,
"bandwidths": [ 10, 20 ]
}
},
"mikrotik routerboard 912uag-2hpnd": {
"maxpower": "30"
@ -217,7 +240,8 @@
"maxpower": "28"
},
"mikrotik ldf 5 ac (rbldfg-5acd)": {
"maxpower": "25"
"maxpower": "25",
"bandwidths": [ 10, 20 ]
},
"mikrotik routerboard rbldf-5nd": {
"maxpower": "25"
@ -259,10 +283,12 @@
"maxpower": "28"
},
"mikrotik lhg 5 ac (rblhgg-5acd)": {
"maxpower": "25"
"maxpower": "25",
"bandwidths": [ 10, 20 ]
},
"mikrotik lhg 5 ac xl (rblhgg-5acd-xl)": {
"maxpower": "25"
"maxpower": "25",
"bandwidths": [ 10, 20 ]
},
"mikrotik routerboard sxtsq 5nd": {
"maxpower": "25"
@ -292,19 +318,28 @@
"maxpower": "28"
},
"mikrotik sxtsq 5 ac (rbsxtsqg-5acd)": {
"maxpower": "25"
"maxpower": "25",
"bandwidths": [ 10, 20 ]
},
"mikrotik hap ac2": {
"maxpower": [
"27",
"26"
]
"wlan0": {
"maxpower": 27,
"bandwidths": [ 5, 10, 20 ]
},
"wlan1": {
"maxpower": 26,
"bandwidths": [ 10, 20 ]
}
},
"mikrotik hap ac3": {
"maxpower": [
"26",
"26"
]
"wlan0": {
"maxpower": 26,
"bandwidths": [ 5, 10, 20 ]
},
"wlan1": {
"maxpower": 26,
"bandwidths": [ 10, 20 ]
}
},
"0xe005": {
"name": "Ubiquiti NanoStation M5",
@ -546,14 +581,14 @@
},
"0xe7fc": {
"name": "Ubiquiti NanoBeam AC Gen2 (WA)",
"maxpower": [
"25",
"20"
],
"pwroffset": [
"2",
"0"
]
"wlan0": {
"maxpower": 25,
"pwroffset": 2
},
"wlan1": {
"maxpower": 20,
"pwroffset": 0
}
},
"0xe7f9": {
"name": "Ubiquiti LiteBeam 5AC Gen2",

View File

@ -41,6 +41,7 @@ local hardware = {}
local radio_json = nil
local board_json = nil
local channels_cache = {}
function hardware.get_board()
if not board_json then
@ -70,16 +71,21 @@ function hardware.get_radio()
return radio_json
end
function hardware.wifi_maxpower(wifiintf, channel)
function hardware.get_radio_intf(wifiintf)
local radio = hardware.get_radio()
if radio and radio[wifiintf] then
return radio[wifiintf]
else
return radio
end
end
function hardware.wifi_maxpower(wifiintf, channel)
local radio = hardware.get_radio_intf(wifiintf)
if radio then
local maxpower = radio.maxpower
local chanpower = radio.chanpower
local intf = tonumber(wifiintf:match("(%d+)$") or 0)
if chanpower then
if type(maxpower) == "table" then
chanpower = chanpower[1 + intf]
end
for k, v in pairs(chanpower)
do
if channel <= tonumber(k) then
@ -87,9 +93,6 @@ function hardware.wifi_maxpower(wifiintf, channel)
end
end
end
if type(maxpower) == "table" then
maxpower = maxpower[1 + intf]
end
maxpower = tonumber(maxpower)
if maxpower then
return maxpower
@ -112,14 +115,9 @@ function hardware.wifi_poweroffset(wifiintf)
end
f:close()
end
local radio = hardware.get_radio()
local radio = hardware.get_radio_intf(wifiintf)
if radio then
local pwroffset = radio.pwroffset
local intf = tonumber(wifiintf:match("(%d+)$") or 0)
if type(pwroffset) == "table" then
pwroffset = pwroffset[1 + intf]
end
pwroffset = tonumber(pwroffset)
local pwroffset = tonumber(radio.pwroffset)
if pwroffset then
return pwroffset
end
@ -268,6 +266,10 @@ function hardware.has_wifi()
end
function hardware.get_rfbandwidths(wifiintf)
local radio = hardware.get_radio_intf(wifiintf)
if radio and radio.bandwidths then
return radio.bandwidths
end
return { 5, 10, 20 }
end
@ -275,61 +277,65 @@ function hardware.get_default_channel(wifiintf)
for _, channel in ipairs(hardware.get_rfchannels(wifiintf))
do
if channel.frequency == 912 then
return { channel = 5, bandwidth = 5 }
return { channel = 5, bandwidth = 5, rfband = "900MHz" }
end
if channel.frequency == 2397 then
return { channel = -2, bandwidth = 10 }
return { channel = -2, bandwidth = 10, rfband = "2.4GHz" }
end
if channel.frequency == 2412 then
return { channel = 1, bandwidth = 10 }
return { channel = 1, bandwidth = 10, rfband = "2.4GHz" }
end
if channel.frequency == 3420 then
return { channel = 84, bandwidth = 10 }
return { channel = 84, bandwidth = 10, rfband = "3GHz" }
end
if channel.frequency == 5745 then
return { channel = 149, bandwidth = 10 }
return { channel = 149, bandwidth = 10, rfband = "5GHz" }
end
end
return nil
end
function hardware.get_rfchannels(wifiintf)
local channels = {}
local f = io.popen("iwinfo " .. wifiintf .. " freqlist")
if f then
local freq_adjust = 0
local freq_min = 0
local freq_max = 0x7FFFFFFF
if wifiintf == "wlan0" then
local radio = hardware.get_radio()
if radio then
if radio.name:match("M9") then
freq_adjust = -1520;
freq_min = 907
freq_max = 922
elseif radio.name:match("M3") then
freq_adjust = -2000;
freq_min = 3380
freq_max = 3495
local channels = channels_cache[wifiintf]
if not channels then
channels = {}
local f = io.popen("iwinfo " .. wifiintf .. " freqlist")
if f then
local freq_adjust = 0
local freq_min = 0
local freq_max = 0x7FFFFFFF
if wifiintf == "wlan0" then
local radio = hardware.get_radio()
if radio then
if radio.name:match("M9") then
freq_adjust = -1520;
freq_min = 907
freq_max = 922
elseif radio.name:match("M3") then
freq_adjust = -2000;
freq_min = 3380
freq_max = 3495
end
end
end
end
for line in f:lines()
do
local freq, num = line:match("(%d+%.%d+) GHz %(Channel (%-?%d+)%)")
if freq and not line:match("restricted") and not line:match("disabled") then
freq = tonumber("" .. freq:gsub("%.", "")) + freq_adjust
if freq >= freq_min and freq <= freq_max then
num = tonumber("" .. num:gsub("^0+", ""))
channels[#channels + 1] = {
label = freq_adjust == 0 and (num .. " (" .. freq .. ")") or (freq),
number = num,
frequency = freq
}
for line in f:lines()
do
local freq, num = line:match("(%d+%.%d+) GHz %(Channel (%-?%d+)%)")
if freq and not line:match("restricted") and not line:match("disabled") then
freq = tonumber("" .. freq:gsub("%.", "")) + freq_adjust
if freq >= freq_min and freq <= freq_max then
num = tonumber("" .. num:gsub("^0+", ""))
channels[#channels + 1] = {
label = freq_adjust == 0 and (num .. " (" .. freq .. ")") or (freq),
number = num,
frequency = freq
}
end
end
end
f:close()
channels_cache[wifiintf] = channels
end
f:close()
end
return channels
end