From 1403e695b732cb6a1814b4780e7093bcdd674e8e Mon Sep 17 00:00:00 2001 From: Jared McNeill Date: Sat, 3 Sep 2016 15:28:09 +0000 Subject: [PATCH] Use the root key in the Security ID EFUSE (when valid) to generate a MAC address instead of creating a random one each boot. --- sys/arm/allwinner/if_awg.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sys/arm/allwinner/if_awg.c b/sys/arm/allwinner/if_awg.c index 66f5a429ea4d..ddd771d7561c 100644 --- a/sys/arm/allwinner/if_awg.c +++ b/sys/arm/allwinner/if_awg.c @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -1277,6 +1278,7 @@ awg_get_eaddr(device_t dev, uint8_t *eaddr) { struct awg_softc *sc; uint32_t maclo, machi, rnd; + u_char rootkey[16]; sc = device_get_softc(dev); @@ -1285,9 +1287,19 @@ awg_get_eaddr(device_t dev, uint8_t *eaddr) if (maclo == 0xffffffff && machi == 0xffff) { /* MAC address in hardware is invalid, create one */ - rnd = arc4random(); - maclo = 0x00f2 | (rnd & 0xffff0000); - machi = rnd & 0xffff; + if (aw_sid_get_rootkey(rootkey) == 0 && + (rootkey[3] | rootkey[12] | rootkey[13] | rootkey[14] | + rootkey[15]) != 0) { + /* MAC address is derived from the root key in SID */ + maclo = (rootkey[13] << 24) | (rootkey[12] << 16) | + (rootkey[3] << 8) | 0x02; + machi = (rootkey[15] << 8) | rootkey[14]; + } else { + /* Create one */ + rnd = arc4random(); + maclo = 0x00f2 | (rnd & 0xffff0000); + machi = rnd & 0xffff; + } } eaddr[0] = maclo & 0xff;