Skip to content

Commit

Permalink
gluon-setup-mode: rename phys before starting setup mode
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Feb 1, 2025
1 parent cd074cc commit ae0a46b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ start_service() {
init_switch
iw reg set "$(lua -e 'print(require("gluon.site").regdom())')"

/usr/bin/lua -e 'require("gluon.setup-mode").rename_phys()'

procd_open_instance
procd_set_param command /sbin/netifd -c /var/gluon/setup-mode/config
procd_set_param respawn
Expand Down
40 changes: 40 additions & 0 deletions package/gluon-setup-mode/luasrc/usr/lib/lua/gluon/setup-mode.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local platform = require 'gluon.platform'
local json = require 'jsonc'


local M = {}
Expand All @@ -11,4 +12,43 @@ function M.get_status_led()
end
end

function M.rename_phys()
-- Load board data from JSON file
local board_data = json.load('/etc/board.json')
local wlan_data = board_data.wlan or {}

-- Iterate over all entries in wlan_data
for phyname, data in pairs(wlan_data) do
local path = data.path
if path then
-- Get the phyname using iwinfo
-- lua iwinfo does return nil by path instead
-- local other_phyname = iwinfo.nl80211.phyname('path=' .. path)

local cmd = "iwinfo nl80211 phyname path=" .. path
local f = io.popen(cmd)
local other_phyname = f:read("*a")
f:close()

-- Trim whitespace from the result
other_phyname = other_phyname:gsub("^%s*(.-)%s*$", "%1")

-- Check if the retrieved phyname doesn't match the key
if other_phyname ~= "" and other_phyname ~= phyname then
-- Construct the command to rename the phy
local cmd = string.format("iw %s set name %s", other_phyname, phyname)

-- Execute the command
os.execute(cmd)

print(string.format("Renamed %s to %s", other_phyname, phyname))
else
print(string.format("No renaming needed for %s", phyname))
end
else
print(string.format("No path found for %s", phyname))
end
end
end

return M

0 comments on commit ae0a46b

Please sign in to comment.