From 0532afdbbfdca3b0e60f221d32e343434a766d20 Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Sun, 25 Jun 2023 19:10:07 -0700 Subject: [PATCH] Fix Mikrotik first install where the radios are not necessarily available. (#882) --- files/usr/local/bin/nvram-setup | 41 ++++++++++++++++++--------------- files/www/cgi-bin/status | 13 +++++++---- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/files/usr/local/bin/nvram-setup b/files/usr/local/bin/nvram-setup index 7947b9e9..af9b969b 100755 --- a/files/usr/local/bin/nvram-setup +++ b/files/usr/local/bin/nvram-setup @@ -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 diff --git a/files/www/cgi-bin/status b/files/www/cgi-bin/status index d7586c5d..ead817d3 100755 --- a/files/www/cgi-bin/status +++ b/files/www/cgi-bin/status @@ -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"