Skip to content
Snippets Groups Projects
Unverified Commit 20c7fd98 authored by Matthias Schiffer's avatar Matthias Schiffer Committed by GitHub
Browse files

Merge pull request #2011 from freifunk-gluon/board-json-addresses

Look up primary MAC address through board.json for LAN/WAN
parents b1de28ba e93dca7c
No related branches found
No related tags found
No related merge requests found
...@@ -12,30 +12,44 @@ local json = require 'jsonc' ...@@ -12,30 +12,44 @@ local json = require 'jsonc'
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local util = require 'gluon.util' local util = require 'gluon.util'
local board_data = json.load('/etc/board.json')
local network_data = (board_data or {}).network
local function sysfs(...) local function read(...)
local path = string.format(...) local addr = util.readfile(string.format(...))
return function() if addr then
local addr = util.readfile(path) return util.trim(addr)
if addr then
return util.trim(addr)
end
end end
end end
local function eth(index) local function get_netdev_addr(ifname)
return sysfs('/sys/class/net/eth%d/address', index) return read('/sys/class/net/%s/address', ifname)
end
local function strip_vlan(ifname)
return (ifname:gsub('%..*', ''))
end
local function netdev(ifname)
return function()
return get_netdev_addr(ifname)
end
end end
local function phy(index) local function phy(index)
return sysfs('/sys/class/ieee80211/phy%d/macaddress', index) return function()
return read('/sys/class/ieee80211/phy%d/macaddress', index)
end
end end
local function board(iface) local function interface(name)
return function() return function()
local data = json.load('/etc/board.json') local ifdata = network_data[name] or {}
if data and data.network and data.network[iface] then if ifdata.macaddr then
return data.network[iface].macaddr return ifdata.macaddr
elseif ifdata.ifname then
return get_netdev_addr(strip_vlan(ifdata.ifname))
end end
end end
end end
...@@ -43,14 +57,13 @@ end ...@@ -43,14 +57,13 @@ end
-- Entries are matched in the order they are listed -- Entries are matched in the order they are listed
local primary_addrs = { local primary_addrs = {
{eth(0), { {interface('lan'), {
{'x86'},
{'brcm2708'},
{'ar71xx', 'generic', { {'ar71xx', 'generic', {
'a40', 'archer-c5',
'a60', 'archer-c58-v1',
'archer-c25-v1', 'archer-c59-v1',
'archer-c60-v2', 'archer-c60-v1',
'archer-c7',
'archer-c7-v4', 'archer-c7-v4',
'archer-c7-v5', 'archer-c7-v5',
'carambola2', 'carambola2',
...@@ -63,11 +76,9 @@ local primary_addrs = { ...@@ -63,11 +76,9 @@ local primary_addrs = {
'mr1750v2', 'mr1750v2',
'om2p', 'om2p',
'om2pv2', 'om2pv2',
'om2pv4',
'om2p-hs', 'om2p-hs',
'om2p-hsv2', 'om2p-hsv2',
'om2p-hsv3', 'om2p-hsv3',
'om2p-hsv4',
'om2p-lc', 'om2p-lc',
'om5p', 'om5p',
'om5p-an', 'om5p-an',
...@@ -85,32 +96,45 @@ local primary_addrs = { ...@@ -85,32 +96,45 @@ local primary_addrs = {
'glinet,gl-ar750s-nor', 'glinet,gl-ar750s-nor',
'ocedo,raccoon', 'ocedo,raccoon',
}}, }},
{'brcm2708'},
{'ipq40xx', 'generic', { {'ipq40xx', 'generic', {
'avm,fritzbox-4040', 'avm,fritzbox-4040',
'openmesh,a42',
'openmesh,a62',
}}, }},
{'mpc85xx', 'p1020', { {'ipq806x', 'generic', {
'aerohive,hiveap-330', 'netgear,r7800',
}},
{'lantiq', 'xway', {
'netgear,dgn3500b',
}}, }},
{'ramips', 'mt7620', { {'ramips', 'mt7620', {
'miwifi-mini', 'tplink,c2-v1', 'c20-v1', 'c20i', 'c50', 'c20-v1',
'c20i',
'c50',
'tplink,c2-v1',
}}, }},
{'x86'},
}}, }},
{eth(1), { {interface('wan'), {
{'ar71xx', 'generic', { {'ar71xx', 'generic', {
'archer-c5', 'a40',
'archer-c58-v1', 'a60',
'archer-c59-v1', 'archer-c25-v1',
'archer-c60-v1', 'archer-c60-v2',
'archer-c7', 'om2pv4',
'om2p-hsv4',
}}, }},
{'ipq806x', 'generic', { {'ipq40xx', 'generic', {
'netgear,r7800', 'linksys,ea6350v3',
'openmesh,a42',
'openmesh,a62',
}}, }},
{'mpc85xx', 'p1020', { {'mpc85xx', 'p1020', {
'aerohive,hiveap-330',
'ocedo,panda', 'ocedo,panda',
}}, }},
{'ramips', 'mt7620', {
'miwifi-mini',
}},
}}, }},
{phy(1), { {phy(1), {
{'ar71xx', 'generic', { {'ar71xx', 'generic', {
...@@ -122,22 +146,12 @@ local primary_addrs = { ...@@ -122,22 +146,12 @@ local primary_addrs = {
'dir-860l-b1', 'dir-860l-b1',
}}, }},
}}, }},
{board('lan'), {
{'lantiq', 'xway', {
'netgear,dgn3500b',
}},
}},
{board('wan'), {
{'ipq40xx', 'generic', {
'linksys,ea6350v3',
}},
}},
-- phy0 default -- phy0 default
{phy(0), { {phy(0), {
{}, -- matches everything {}, -- matches everything
}}, }},
-- eth0 fallback when phy0 does not exist -- eth0 fallback when phy0 does not exist
{eth(0), { {netdev('eth0'), {
{}, -- matches everything {}, -- matches everything
}}, }},
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment