diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2013-09-20 07:47:43 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-22 20:27:12 +0200 |
commit | 3293c860ab539de5e35bc29907ed7bd2cd1e5ad6 (patch) | |
tree | da88069675be1541f12332efbe72736e5bb2052e /include/local_mac_address.h | |
parent | 189678dc6763271e7fad16ef1ee25806e79c4b4f (diff) | |
download | barebox-3293c860ab539de5e35bc29907ed7bd2cd1e5ad6.tar.gz barebox-3293c860ab539de5e35bc29907ed7bd2cd1e5ad6.tar.xz |
introduce helper to generate mac address with OUI
use random mac address with fixed OUI provided
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/local_mac_address.h')
-rw-r--r-- | include/local_mac_address.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/include/local_mac_address.h b/include/local_mac_address.h new file mode 100644 index 0000000000..3d1ec66b1f --- /dev/null +++ b/include/local_mac_address.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnio@jcrosoft.com> + * + * Under GPLv2 only + */ + +#ifndef __LOCAL_MAC_ADDRESS_H__ +#define __LOCAL_MAC_ADDRESS_H__ + +#include <net.h> + +/** + * 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__ */ |