Fix Mikrotik first install where the radios are not necessarily available. (#882)

This commit is contained in:
Tim Wilkinson 2023-06-25 19:10:07 -07:00 committed by GitHub
parent adab218868
commit 0532afdbbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 23 deletions

View File

@ -55,35 +55,40 @@ local dtdmac = aredn_info.get_nvram("dtdmac")
local hardware_mac
if wifi_mac == "" or mac2 == "" then
local wlan = get_ifname("wifi")
if wlan then
if aredn.hardware.has_wifi() then
local phy
for i = 1,5
do
local f = io.popen("iwinfo " .. wlan .. " info")
if f then
for line in f:lines()
for _, wlan in ipairs({ "wlan0", "wlan1" })
do
local f = io.popen("iwinfo " .. wlan .. " info")
if f then
for line in f:lines()
do
phy = line:match("PHY name:%s*([a-z0-4]+)")
if phy then
break
end
end
f:close()
end
if phy then
break
end
end
if phy then
for line in io.lines("/sys/class/ieee80211/" .. phy .. "/macaddress")
do
phy = line:match("PHY name:%s*([a-z0-4]+)")
if phy then
local m = line:match("(%w%w:%w%w:%w%w:%w%w:%w%w:%w%w)")
if m then
hardware_mac = m
break
end
end
f:close()
end
if phy then
break
end
sleep(5)
end
for line in io.lines("/sys/class/ieee80211/" .. phy .. "/macaddress")
do
local m = line:match("(%w%w:%w%w:%w%w:%w%w:%w%w:%w%w)")
if m then
hardware_mac = m
break
end
end
end
if not hardware_mac then
if not aredn.hardware.has_wifi() then

View File

@ -171,11 +171,14 @@ local wifi_ssid
if not wifi_disabled then
wifi_channel = cursor:get("wireless", radio, "channel")
wifi_channel = tonumber(wifi_channel) or 0
local basefreq = aredn.hardware.get_rfchannels(wifi_iface)[1].frequency
if basefreq > 3000 and basefreq < 5000 then
wifi_channel = wifi_channel * 5 + 3000
elseif basefreq > 900 and basefreq < 2300 then
wifi_channel = wifi_channel * 5 + 887
local rfchans = aredn.hardware.get_rfchannels(wifi_iface)
if rfchans and rfchans[1] then
local basefreq = rfchans[1].frequency
if basefreq > 3000 and basefreq < 5000 then
wifi_channel = wifi_channel * 5 + 3000
elseif basefreq > 900 and basefreq < 2300 then
wifi_channel = wifi_channel * 5 + 887
end
end
wifi_chanbw = cursor:get("wireless", radio, "chanbw") or "20"
wifi_ssid = "none"