summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-06-11 14:11:12 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-06-22 15:44:44 +0200
commit7867ceb8dc5c4d2c64d337aa130c57a05d9b556a (patch)
tree713bf6da05815625f1c33440fc40266b3220542b
parent738d70e430b0f4cb9ac71d2811b3f6a4c74abbf6 (diff)
downloadbarebox-7867ceb8dc5c4d2c64d337aa130c57a05d9b556a.tar.gz
barebox-7867ceb8dc5c4d2c64d337aa130c57a05d9b556a.tar.xz
net: implement random_ether_addr
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/net.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/net.h b/include/net.h
index 709e76c895..c695e5f72a 100644
--- a/include/net.h
+++ b/include/net.h
@@ -17,6 +17,7 @@
#include <param.h>
#include <malloc.h>
#include <stdlib.h>
+#include <clock.h>
#include <asm/byteorder.h> /* for nton* / ntoh* stuff */
@@ -332,6 +333,21 @@ static inline int is_broadcast_ether_addr(const u8 *addr)
}
/**
+ * random_ether_addr - Generate software assigned random Ethernet address
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Generate a random Ethernet address (MAC) that is not multicast
+ * and has the local assigned bit set.
+ */
+static inline void random_ether_addr(u8 *addr)
+{
+ srand(get_time_ns());
+ get_random_bytes(addr, 6);
+ addr [0] &= 0xfe; /* clear multicast bit */
+ addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
+}
+
+/**
* is_valid_ether_addr - Determine if the given Ethernet address is valid
* @addr: Pointer to a six-byte array containing the Ethernet address
*