On 09.04.2019 16:54, Ganbold Tsagaankhuu wrote:
> Author: ganbold
> Date: Tue Apr  9 13:54:08 2019
> New Revision: 346052
> URL: https://svnweb.freebsd.org/changeset/base/346052
> 
> Log:
>   In some cases like NanoPI R1, its second USB ethernet
>   RTL8152 (chip version URE_CHIP_VER_4C10) doesn't
>   have hardwired MAC address, in other words, it is all zeros.
>   This commit fixes it by setting random MAC address
>   when MAC address is all zeros.
>   
> -     if (sc->sc_chip & URE_CHIP_VER_4C00)
> +     if ((sc->sc_chip & URE_CHIP_VER_4C00) ||
> +         (sc->sc_chip & URE_CHIP_VER_4C10))
>               ure_read_mem(sc, URE_PLA_IDR, URE_MCU_TYPE_PLA,
>                   ue->ue_eaddr, 8);
>       else
>               ure_read_mem(sc, URE_PLA_BACKUP, URE_MCU_TYPE_PLA,
>                   ue->ue_eaddr, 8);
> +
> +     if (ETHER_IS_ZERO(sc->sc_ue.ue_eaddr)) {
> +             device_printf(sc->sc_ue.ue_dev, "MAC assigned randomly\n");
> +             arc4rand(sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN, 0);
> +             sc->sc_ue.ue_eaddr[0] &= ~0x01; /* unicast */
> +             sc->sc_ue.ue_eaddr[0] |= 0x02;  /* locally administered */
> +     }
>  }

Hi,

there is ether_fakeaddr() function that is used for such purpose.
Maybe is it better to use it? Look at this commit:
        https://svnweb.freebsd.org/base?view=revision&revision=345139

-- 
WBR, Andrey V. Elsukov

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to