From e195e0269cc8ca77549080e6d73b27ef5e630416 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 4 May 2020 16:29:35 +0200 Subject: [PATCH] sys/luid: provide luid_get_lb(), fix documentation This does two things: The documentation of `luid_get()` is wrong, or at least confusing. It talks about > an 8-bit incrementing counter value into the most significant byte while the implementation does ((uint8_t *)buf)[0] ^= lastused++; // 0 is LSB! Now it could be argued that the intention was that the ID is supposed to be used in Big Endian contexts and that was an omission, however to keep everyone's sanity, let's keep it simple and just state that this actually changes the LSB. Also add a `luid_get_lb()` function that does the same, but modifies the most significant byte - or the last byte if looking at the index. This can then be used directly by e.g. #13743 --- sys/include/luid.h | 17 ++++++++++++++++- sys/luid/luid.c | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/sys/include/luid.h b/sys/include/luid.h index b647958b4418..b87ef0407f28 100644 --- a/sys/include/luid.h +++ b/sys/include/luid.h @@ -74,7 +74,7 @@ extern "C" { * @brief Get a unique ID * * The resulting ID is built from the base ID generated with luid_base(), which - * isXORed with an 8-bit incrementing counter value into the most significant + * isXORed with an 8-bit incrementing counter value into the first (lowest index) * byte. * * @note The resulting LUID will repeat after 255 calls. @@ -85,6 +85,21 @@ extern "C" { */ void luid_get(void *buf, size_t len); +/** + * @brief Get a unique ID with change in the last byte + * + * The resulting ID is built from the base ID generated with luid_base(), which + * isXORed with an 8-bit incrementing counter value into the last (highest index) + * byte. + * + * @note The resulting LUID will repeat after 255 calls. + * + * @param[out] buf memory location to copy the LUID into. MUST be able to + * hold at least @p len bytes + * @param[in] len length of the LUID in bytes + */ +void luid_get_lb(void *buf, size_t len); + /** * @brief Get a unique short unicast address * diff --git a/sys/luid/luid.c b/sys/luid/luid.c index 544eeb1c3fba..bdaff93ff4b3 100644 --- a/sys/luid/luid.c +++ b/sys/luid/luid.c @@ -54,6 +54,13 @@ void luid_get(void *buf, size_t len) ((uint8_t *)buf)[0] ^= lastused++; } +void luid_get_lb(void *buf, size_t len) +{ + luid_base(buf, len); + + ((uint8_t *)buf)[len - 1] ^= lastused++; +} + void luid_custom(void *buf, size_t len, int gen) { luid_base(buf, len);