Fix ralink-rt305x/vocore mac schema generation.

The VIF mac addresses in the ralink-rt305x chip must be sequential in
the last bit, since they are using a hardware mac filter.

1. Hash the original primary mac, since the addresses of devices bought
   together could be sequential in the last byte.

2. Increment the last byte for the VIF on the vocore (generate_mac routine)

Implements #648
This commit is contained in:
lemoer 2016-04-01 23:43:39 +02:00
parent 4f051061de
commit 6058736100
2 changed files with 36 additions and 4 deletions

View File

@ -10,8 +10,9 @@ end
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local fs = require 'nixio.fs' local sys = require 'luci.sys'
local util = require 'luci.util' local util = require 'luci.util'
local nixio = require 'nixio'
local try_files = { local try_files = {
@ -32,9 +33,15 @@ end
for _, file in ipairs(try_files) do for _, file in ipairs(try_files) do
local addr = fs.readfile(file) local addr = nixio.fs.readfile(file)
if addr then if addr then
if platform.match('ramips', 'rt305x', {'vocore'}) then
-- Hash the mac address since we need to iterate in the last bits for
-- the VIF. (This chip uses a hardware mac filter)
addr = util.hash_mac(addr)
end
sysconfig.primary_mac = util.trim(addr) sysconfig.primary_mac = util.trim(addr)
break break
end end

View File

@ -31,6 +31,7 @@ local table = table
local nixio = require 'nixio' local nixio = require 'nixio'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local platform = require 'gluon.platform'
local site = require 'gluon.site_config' local site = require 'gluon.site_config'
local uci = require('luci.model.uci').cursor() local uci = require('luci.model.uci').cursor()
@ -83,10 +84,34 @@ end
function generate_mac(f, i) function generate_mac(f, i)
local m1, m2, m3, m4, m5, m6 = string.match(sysconfig.primary_mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)') local m1, m2, m3, m4, m5, m6 = string.match(sysconfig.primary_mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)')
m1 = nixio.bit.bor(tonumber(m1, 16), 0x02) m1 = nixio.bit.bor(tonumber(m1, 16), 0x02)
m2 = (tonumber(m2, 16)+f) % 0x100 m2 = tonumber(m2, 16)
m3 = (tonumber(m3, 16)+i) % 0x100 m3 = (tonumber(m3, 16)+i) % 0x100
m6 = tonumber(m6, 16)
return string.format('%02x:%02x:%02x:%s:%s:%s', m1, m2, m3, m4, m5, m6) if platform.match('ramips', 'rt305x', {'vocore'}) then
-- We need to iterate in the last byte, since the vocore does
-- hardware mac filtering on the wlan interface.
m6 = (m6+f) % 0x100
else
m2 = (m2+f) % 0x100
end
return string.format('%02x:%02x:%02x:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
end
-- Generates a mac hashed from the original
-- The last three bits will be zeroed, since these bits are
-- iterated on some devices for the VIF.
function hash_mac(original)
local hashed = string.sub(sys.exec('echo -n "' .. original .. '" | sha512sum'),0,12)
local m1, m2, m3, m4, m5, m6 = string.match(hashed, '(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)')
local m1 = nixio.bit.bor(tonumber(m1, 16), 0x02)
local m6 = nixio.bit.band(tonumber(m6, 16), 0xF8) -- zero the last three bits
-- It's necessary that the upper bits of the mac do
-- not vary on a single interface, since they are using
-- a hardware mac filter. (e.g 'ramips-rt305x')
return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
end end
-- Iterate over all radios defined in UCI calling -- Iterate over all radios defined in UCI calling