From c4613c4e8d6b888d6402818aeb4e8656959e5fcf Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 11 Apr 2017 01:38:53 +0200 Subject: [PATCH] gluon-core: gluon.util: pass UCI cursor to get_wlan_mac(), get rid of local UCI context --- .../gluon/upgrade/320-gluon-client-bridge-wireless | 2 +- .../gluon-core/luasrc/lib/gluon/upgrade/200-wireless | 6 +++--- package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua | 11 +++++------ .../luasrc/lib/gluon/web/model/admin/privatewifi.lua | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless index 63a7ed32..058dc351 100755 --- a/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless +++ b/package/gluon-client-bridge/luasrc/lib/gluon/upgrade/320-gluon-client-bridge-wireless @@ -27,7 +27,7 @@ local function configure_client(config, radio, index, suffix) return end - local macaddr = util.get_wlan_mac(radio, index, 1) + local macaddr = util.get_wlan_mac(uci, radio, index, 1) if not macaddr then return end diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless index caf23c33..ba844950 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless @@ -48,7 +48,7 @@ local function configure_ibss(config, radio, index, suffix, disabled) return end - local macaddr = util.get_wlan_mac(radio, index, 3) + local macaddr = util.get_wlan_mac(uci, radio, index, 3) if not macaddr then return end @@ -102,7 +102,7 @@ local function configure_mesh(config, radio, index, suffix, disabled) return end - local macaddr = util.get_wlan_mac(radio, index, 2) + local macaddr = util.get_wlan_mac(uci, radio, index, 2) if not macaddr then return end @@ -137,7 +137,7 @@ local function fixup_wan(radio, index) return end - local macaddr = util.get_wlan_mac(radio, index, 4) + local macaddr = util.get_wlan_mac(uci, radio, index, 4) if not macaddr then return end diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua index 0290c349..80888c8b 100644 --- a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua +++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua @@ -36,7 +36,6 @@ local nixio = require 'nixio' local hash = require 'hash' local sysconfig = require 'gluon.sysconfig' local site = require 'gluon.site_config' -local uci = require('simple-uci').cursor() local fs = require 'nixio.fs' @@ -165,7 +164,7 @@ function find_phy(config) end end -local function get_addresses(radio) +local function get_addresses(uci, radio) local phy = find_phy(uci:get_all('wireless', radio)) if not phy then return function() end @@ -208,11 +207,11 @@ function generate_mac(i) return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6) end -local function get_wlan_mac_from_driver(radio, vif) +local function get_wlan_mac_from_driver(uci, radio, vif) local primary = sysconfig.primary_mac:lower() local i = 1 - for addr in get_addresses(radio) do + for addr in get_addresses(uci, radio) do if addr:lower() ~= primary then if i == vif then return addr @@ -223,8 +222,8 @@ local function get_wlan_mac_from_driver(radio, vif) end end -function get_wlan_mac(radio, index, vif) - local addr = get_wlan_mac_from_driver(radio, vif) +function get_wlan_mac(uci, radio, index, vif) + local addr = get_wlan_mac_from_driver(uci, radio, vif) if addr then return addr end diff --git a/package/gluon-web-private-wifi/luasrc/lib/gluon/web/model/admin/privatewifi.lua b/package/gluon-web-private-wifi/luasrc/lib/gluon/web/model/admin/privatewifi.lua index e38e7537..ed5d55c7 100644 --- a/package/gluon-web-private-wifi/luasrc/lib/gluon/web/model/admin/privatewifi.lua +++ b/package/gluon-web-private-wifi/luasrc/lib/gluon/web/model/admin/privatewifi.lua @@ -31,7 +31,7 @@ function f:write() local name = "wan_" .. radio if enabled.data then - local macaddr = util.get_wlan_mac(radio, index, 4) + local macaddr = util.get_wlan_mac(uci, radio, index, 4) uci:section('wireless', "wifi-iface", name, { device = radio,