gluon-core: wireless: support PHY lookup for multi-PHY devices
The PHY lookup helper "find_phy_by_path" could not lookup the PHY name for paths from multi-phy devices. An example for such a path would be: '1e140000.pcie/pci0000:00/0000:00:01.0/0000:02:00.0+1' The integer after the plus (+) character determines the PHY index of the specific device in relation to the PHY with the lowest index of the device. For example, if the device provides phy2 and phy3, the above path would describe phy3. In case the device provides phy0 and phy1, it would describe phy1. Rewrite the "find_phy_by_path" function to support those paths as well as regular device paths in a universal manner. Signed-off-by: David Bauer <mail@david-bauer.net>
This commit is contained in:
parent
2dce9fa3f4
commit
3b23f731c5
@ -2,16 +2,51 @@ local sysconfig = require 'gluon.sysconfig'
|
|||||||
local site = require 'gluon.site'
|
local site = require 'gluon.site'
|
||||||
local util = require 'gluon.util'
|
local util = require 'gluon.util'
|
||||||
|
|
||||||
|
local unistd = require 'posix.unistd'
|
||||||
|
local dirent = require 'posix.dirent'
|
||||||
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function find_phy_by_path(path)
|
local function find_phy_by_path(path)
|
||||||
local phy = util.glob('/sys/devices/' .. path .. '/ieee80211/phy*')[1]
|
local phy_path, phy_offset
|
||||||
or util.glob('/sys/devices/platform/' .. path .. '/ieee80211/phy*')[1]
|
-- Special handling required for multi-phy devices
|
||||||
|
if string.match(path, '+%d$') then
|
||||||
|
phy_path, phy_offset = string.match(path, "([^,]+)+(%d)$")
|
||||||
|
|
||||||
if phy then
|
-- The UCI radio path is split into the path and a PHY offset,
|
||||||
return phy:match('([^/]+)$')
|
-- which is incremented for each additional PHY available on
|
||||||
|
-- the device.
|
||||||
|
|
||||||
|
phy_idx = phy_offset
|
||||||
|
else
|
||||||
|
phy_path = path
|
||||||
|
phy_offset = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Find the PHY path. Either it's located at /sys/devices or /sys/devices/platform
|
||||||
|
local path_prefix = ''
|
||||||
|
if not unistd.access('/sys/devices/' .. phy_path .. '/ieee80211') then
|
||||||
|
path_prefix = 'platform/'
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get all available PHYs of the device and dertermine the one with the lowest index
|
||||||
|
local phy_names = dirent.dir('/sys/devices/' .. path_prefix .. phy_path .. '/ieee80211')
|
||||||
|
local lowest_phy = nil
|
||||||
|
for _, v in ipairs(phy_names) do
|
||||||
|
local phy_idx = v:match('(%d)$')
|
||||||
|
phy_idx = tonumber(phy_idx)
|
||||||
|
|
||||||
|
if phy_idx ~= nil and (lowest_phy == nil or lowest_phy > phy_idx) then
|
||||||
|
lowest_phy = phy_idx
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if lowest_phy == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return 'phy' .. lowest_phy + phy_offset
|
||||||
end
|
end
|
||||||
|
|
||||||
local function find_phy_by_macaddr(macaddr)
|
local function find_phy_by_macaddr(macaddr)
|
||||||
|
Loading…
Reference in New Issue
Block a user