aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorAlexander Aring <alex.aring@gmail.com>2014-11-05 14:51:22 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-11-05 15:53:04 -0500
commit35d5a374a559a1ba9c6810739cf3ad1d672c2de2 (patch)
treefa9ae6bd39528a62f2d61cc63cc9f2b2a4b40f88 /include/linux
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')
-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 @@
24#define LINUX_IEEE802154_H 24#define LINUX_IEEE802154_H
25 25
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/random.h>
27#include <asm/byteorder.h> 28#include <asm/byteorder.h>
28 29
29#define IEEE802154_MTU 127 30#define IEEE802154_MTU 127
@@ -215,4 +216,17 @@ static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
215 (addr != cpu_to_le64(0xffffffffffffffffULL))); 216 (addr != cpu_to_le64(0xffffffffffffffffULL)));
216} 217}
217 218
219/**
220 * ieee802154_random_extended_addr - generates a random extended address
221 * @addr: extended addr pointer to place the random address
222 */
223static inline void ieee802154_random_extended_addr(__le64 *addr)
224{
225 get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
226
227 /* toggle some bit if we hit an invalid extended addr */
228 if (!ieee802154_is_valid_extended_addr(*addr))
229 ((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] ^= 0x01;
230}
231
218#endif /* LINUX_IEEE802154_H */ 232#endif /* LINUX_IEEE802154_H */