summaryrefslogtreecommitdiff
path: root/include/linux/ieee802154.h
diff options
context:
space:
mode:
authorAlexander Aring <alex.aring@gmail.com>2014-11-05 20:51:22 +0100
committerMarcel Holtmann <marcel@holtmann.org>2014-11-05 21:53:04 +0100
commit35d5a374a559a1ba9c6810739cf3ad1d672c2de2 (patch)
treefa9ae6bd39528a62f2d61cc63cc9f2b2a4b40f88 /include/linux/ieee802154.h
parent1906bbbddbe085b19be2c21cd132335260f551c3 (diff)
ieee802154: add ieee802154_random_extended_addr
This patch adds a new function to generate a random IEEE 802.15.4 extended address. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'include/linux/ieee802154.h')
-rw-r--r--include/linux/ieee802154.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h
index a907fe59b1d1..d043449a079d 100644
--- a/include/linux/ieee802154.h
+++ b/include/linux/ieee802154.h
@@ -24,6 +24,7 @@
#define LINUX_IEEE802154_H
#include <linux/types.h>
+#include <linux/random.h>
#include <asm/byteorder.h>
#define IEEE802154_MTU 127
@@ -215,4 +216,17 @@ static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
(addr != cpu_to_le64(0xffffffffffffffffULL)));
}
+/**
+ * ieee802154_random_extended_addr - generates a random extended address
+ * @addr: extended addr pointer to place the random address
+ */
+static inline void ieee802154_random_extended_addr(__le64 *addr)
+{
+ get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
+
+ /* toggle some bit if we hit an invalid extended addr */
+ if (!ieee802154_is_valid_extended_addr(*addr))
+ ((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] ^= 0x01;
+}
+
#endif /* LINUX_IEEE802154_H */