[PATCH 2/8] w1: introduce helper to generate mac address from 1-wire id

Sascha Hauer s.hauer at pengutronix.de
Mon Oct 29 18:24:16 EDT 2012


On Mon, Oct 29, 2012 at 02:46:58PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> use the first 3 byte of the id of a 1-wire
> or 6 if no OUI provided device to provide an Ethernet address
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> ---
>  include/w1_mac_address.h |   72 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 72 insertions(+)
>  create mode 100644 include/w1_mac_address.h
> + *
> + * Generate a Ethernet address (MAC) that is not multicast using a 1-wire id.
> + */
> +static inline int w1_mac_address_register(int ethid, bool local,
> +					 char * oui, char *w1_dev)

Please drop the local parameter. I believe that it may have a valid
use, but really until someone proves he has such a usecase I do not
want to have this in the tree. This only increases the risk that some
users slip through the review which do not make valid use of this flag.

> +{
> +	char addr[6];
> +	const char *val;
> +	u64 id;
> +	int nb_oui = 0;
> +	int i, shift;
> +	char *tmp = NULL;
> +	int ret = 0;
> +
> +	if (!local && !oui)
> +		return -EINVAL;
> +
> +	if (oui) {
> +		nb_oui = 3;
> +
> +		for (i = 0; i < nb_oui; i++)
> +			addr[i] = oui[i];
> +	}
> +
> +	tmp = asprintf("%s.id", w1_dev);
> +	if (!tmp)
> +		return -ENOMEM;
> +
> +	val = getenv(tmp);
> +	if (!val) {
> +		ret = -EINVAL;
> +		goto err;
> +	}
> +
> +	id = simple_strtoull(val, NULL, 16);
> +	if (!id) {
> +		ret = -EINVAL;
> +		goto err;
> +	}
> +
> +	for (i = nb_oui, shift = 40; i < 6; i++, shift -= 8)
> +		addr[i] = (id >> shift) & 0xff;
> +
> +	if (local) {
> +		addr[0] &= 0xfe;	/* clear multicast bit */

Shouldn't this bit always be cleared?

Sascha

-- 
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