mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-23 11:18:54 +00:00
if_emac: Before generating a random MAC address, try using the SID rootkey
to generate one. This is was U-Boot does to generate a random MAC so we end up with the same MAC address as if U-Boot did generate it. MFC after: 1 week
This commit is contained in:
parent
354b6f0fd9
commit
bee987e3c8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=304509
@ -77,6 +77,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <dev/mii/miivar.h>
|
||||
|
||||
#include <arm/allwinner/if_emacreg.h>
|
||||
#include <arm/allwinner/aw_sid.h>
|
||||
|
||||
#include <dev/extres/clk/clk.h>
|
||||
|
||||
@ -167,12 +168,17 @@ static void
|
||||
emac_get_hwaddr(struct emac_softc *sc, uint8_t *hwaddr)
|
||||
{
|
||||
uint32_t val0, val1, rnd;
|
||||
u_char rootkey[16];
|
||||
|
||||
/*
|
||||
* Try to get MAC address from running hardware.
|
||||
* If there is something non-zero there just use it.
|
||||
*
|
||||
* Otherwise set the address to a convenient locally assigned address,
|
||||
* using the SID rootkey.
|
||||
* This is was uboot does so we end up with the same mac as if uboot
|
||||
* did set it.
|
||||
* If we can't get the root key, generate a random one,
|
||||
* 'bsd' + random 24 low-order bits. 'b' is 0x62, which has the locally
|
||||
* assigned bit set, and the broadcast/multicast bit clear.
|
||||
*/
|
||||
@ -186,13 +192,23 @@ emac_get_hwaddr(struct emac_softc *sc, uint8_t *hwaddr)
|
||||
hwaddr[4] = (val0 >> 8) & 0xff;
|
||||
hwaddr[5] = (val0 >> 0) & 0xff;
|
||||
} else {
|
||||
rnd = arc4random() & 0x00ffffff;
|
||||
hwaddr[0] = 'b';
|
||||
hwaddr[1] = 's';
|
||||
hwaddr[2] = 'd';
|
||||
hwaddr[3] = (rnd >> 16) & 0xff;
|
||||
hwaddr[4] = (rnd >> 8) & 0xff;
|
||||
hwaddr[5] = (rnd >> 0) & 0xff;
|
||||
if (aw_sid_get_rootkey(rootkey) == 0) {
|
||||
hwaddr[0] = 0x2;
|
||||
hwaddr[1] = rootkey[3];
|
||||
hwaddr[2] = rootkey[12];
|
||||
hwaddr[3] = rootkey[13];
|
||||
hwaddr[4] = rootkey[14];
|
||||
hwaddr[5] = rootkey[15];
|
||||
}
|
||||
else {
|
||||
rnd = arc4random() & 0x00ffffff;
|
||||
hwaddr[0] = 'b';
|
||||
hwaddr[1] = 's';
|
||||
hwaddr[2] = 'd';
|
||||
hwaddr[3] = (rnd >> 16) & 0xff;
|
||||
hwaddr[4] = (rnd >> 8) & 0xff;
|
||||
hwaddr[5] = (rnd >> 0) & 0xff;
|
||||
}
|
||||
}
|
||||
if (bootverbose)
|
||||
printf("MAC address: %s\n", ether_sprintf(hwaddr));
|
||||
|
Loading…
Reference in New Issue
Block a user