MCPcopy Create free account
hub / github.com/F-Stack/f-stack / awg_get_eaddr

Function awg_get_eaddr

freebsd/arm/allwinner/if_awg.c:495–533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495static void
496awg_get_eaddr(device_t dev, uint8_t *eaddr)
497{
498 struct awg_softc *sc;
499 uint32_t maclo, machi, rnd;
500 u_char rootkey[16];
501 uint32_t rootkey_size;
502
503 sc = device_get_softc(dev);
504
505 machi = RD4(sc, EMAC_ADDR_HIGH(0)) & 0xffff;
506 maclo = RD4(sc, EMAC_ADDR_LOW(0));
507
508 rootkey_size = sizeof(rootkey);
509 if (maclo == 0xffffffff && machi == 0xffff) {
510 /* MAC address in hardware is invalid, create one */
511 if (aw_sid_get_fuse(AW_SID_FUSE_ROOTKEY, rootkey,
512 &rootkey_size) == 0 &&
513 (rootkey[3] | rootkey[12] | rootkey[13] | rootkey[14] |
514 rootkey[15]) != 0) {
515 /* MAC address is derived from the root key in SID */
516 maclo = (rootkey[13] << 24) | (rootkey[12] << 16) |
517 (rootkey[3] << 8) | 0x02;
518 machi = (rootkey[15] << 8) | rootkey[14];
519 } else {
520 /* Create one */
521 rnd = arc4random();
522 maclo = 0x00f2 | (rnd & 0xffff0000);
523 machi = rnd & 0xffff;
524 }
525 }
526
527 eaddr[0] = maclo & 0xff;
528 eaddr[1] = (maclo >> 8) & 0xff;
529 eaddr[2] = (maclo >> 16) & 0xff;
530 eaddr[3] = (maclo >> 24) & 0xff;
531 eaddr[4] = machi & 0xff;
532 eaddr[5] = (machi >> 8) & 0xff;
533}
534
535/*
536 * DMA functions

Callers 1

awg_attachFunction · 0.85

Calls 4

device_get_softcFunction · 0.85
aw_sid_get_fuseFunction · 0.85
RD4Function · 0.50
arc4randomFunction · 0.50

Tested by

no test coverage detected