[PATCH 1/3] introduce helper to generate mac address with OUI

Sascha Hauer s.hauer at pengutronix.de
Sun Sep 22 14:28:21 EDT 2013


On Fri, Sep 20, 2013 at 07:47:43AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> use random mac address with fixed OUI provided
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> ---
>  include/local_mac_address.h | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
>  create mode 100644 include/local_mac_address.h
> 
> diff --git a/include/local_mac_address.h b/include/local_mac_address.h
> new file mode 100644
> index 0000000..3920334
> --- /dev/null
> +++ b/include/local_mac_address.h
> @@ -0,0 +1,40 @@
> +/*
> + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio at jcrosoft.com>
> + *
> + * Under GPLv2 only
> + */
> +
> +#ifndef __LOCAL_MAC_ADDRESS_H__
> +#define __LOCAL_MAC_ADDRESS_H__
> +

This file needs a include <net.h>. Added while applying.

Sascha

> +/**
> + * local_mac_address_register - use random number with fix
> + * OUI provided device to provide an Ethernet address
> + * @ethid: ethernet device id
> + * @oui: Ethernet OUI (3 bytes)
> + *
> + * Generate a local Ethernet address (MAC) that is not multicast using a 1-wire id.
> + */
> +static inline int local_mac_address_register(int ethid, char * oui)
> +{
> +	char addr[6];
> +	int nb_oui = 3;
> +	int i;
> +
> +	if (!oui)
> +		return -EINVAL;
> +
> +	random_ether_addr(addr);
> +
> +	for (i = 0; i < nb_oui; i++)
> +		addr[i] = oui[i];
> +
> +	addr[0] &= 0xfe;	/* clear multicast bit */
> +	addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */
> +
> +	eth_register_ethaddr(ethid, addr);
> +
> +	return 0;
> +}
> +
> +#endif /* __LOCAL_MAC_ADDRESS_H__ */
> -- 
> 1.8.4.rc1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list