From 1336251a511af05f4150d26d45f32c9e325772ac Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Tue, 31 Dec 2024 15:45:48 +0100 Subject: [PATCH 1/2] Revert "gluon-core: lua: wireless: use libiwinfo-lua for find_phy()" This reverts commit 29e281f759cf019d323fc0ae8c8202ad2476ce9f. --- .../luasrc/usr/lib/lua/gluon/wireless.lua | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua index 01379a1d11..d7d5ec063b 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua @@ -3,13 +3,62 @@ local site = require 'gluon.site' local util = require 'gluon.util' local unistd = require 'posix.unistd' +local dirent = require 'posix.dirent' -local iwinfo = require 'iwinfo' local M = {} +local function find_phy_by_path(path) + local device_path, phy_offset = string.match(path, "^(.+)%+(%d+)$") + + -- Special handling required for multi-phy devices + if device_path == nil then + device_path = path + phy_offset = '0' + end + + -- Find the device path. Either it's located at /sys/devices or /sys/devices/platform + local path_prefix = '' + if not unistd.access('/sys/devices/' .. device_path .. '/ieee80211') then + path_prefix = 'platform/' + end + + -- Get all available PHYs of the device and determine the one with the lowest index + local phy_names = dirent.dir('/sys/devices/' .. path_prefix .. device_path .. '/ieee80211') + local device_phy_idxs = {} + for _, v in ipairs(phy_names) do + local phy_idx = v:match('^phy(%d+)$') + + if phy_idx ~= nil then + table.insert(device_phy_idxs, tonumber(phy_idx)) + end + end + + table.sort(device_phy_idxs) + + -- Index starts at 1 + return 'phy' .. device_phy_idxs[tonumber(phy_offset) + 1] +end + +local function find_phy_by_macaddr(macaddr) + local addr = macaddr:lower() + for _, file in ipairs(util.glob('/sys/class/ieee80211/*/macaddress')) do + if util.trim(util.readfile(file)) == addr then + return file:match('([^/]+)/macaddress$') + end + end +end + function M.find_phy(config) - return iwinfo.nl80211.phyname(config['.name']) + if not config or config.type ~= 'mac80211' then + return nil + elseif config.path then + return find_phy_by_path(config.path) + elseif config.macaddr then + return find_phy_by_macaddr(config.macaddr) + else + return nil + end end local function get_addresses(radio) From 5b67512f703ea30219fb4b1a74492ee2120d3929 Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Tue, 31 Dec 2024 15:48:12 +0100 Subject: [PATCH 2/2] core: add iwinfo.nl80211.phyname find_phy from iwinfo.nl80211.phyname at first if it is nil, check by path or macaddr --- package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua index d7d5ec063b..eace2cf874 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/wireless.lua @@ -5,6 +5,8 @@ local util = require 'gluon.util' local unistd = require 'posix.unistd' local dirent = require 'posix.dirent' +local iwinfo = require 'iwinfo' + local M = {} @@ -50,8 +52,9 @@ local function find_phy_by_macaddr(macaddr) end function M.find_phy(config) - if not config or config.type ~= 'mac80211' then - return nil + phyname = iwinfo.nl80211.phyname(config['.name']) + if phyname then + return phyname elseif config.path then return find_phy_by_path(config.path) elseif config.macaddr then