提交 35d5a374 编写于 作者: A Alexander Aring 提交者: Marcel Holtmann

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: NAlexander Aring <alex.aring@gmail.com>
Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
上级 1906bbbd
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define LINUX_IEEE802154_H #define LINUX_IEEE802154_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/random.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#define IEEE802154_MTU 127 #define IEEE802154_MTU 127
...@@ -215,4 +216,17 @@ static inline bool ieee802154_is_valid_extended_addr(const __le64 addr) ...@@ -215,4 +216,17 @@ static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
(addr != cpu_to_le64(0xffffffffffffffffULL))); (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 */ #endif /* LINUX_IEEE802154_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册