From ada2c782356057efa24c615c9ed08f177ae52477 Mon Sep 17 00:00:00 2001 From: Aurelien Jarno Date: Sun, 28 Apr 2024 21:00:55 +0200 Subject: [PATCH] drivers: hwinfo: Add device EUI64 ID support Some devices, mostly with radio support, have an EUI64 ID (unique and attributed by IEEE), in addition to the standard device ID. Add support for reading it through the hwinfo API. As the size is always the same (8 bytes), there is no need to pass the size in the function, nor return the number of bytes copied. Signed-off-by: Aurelien Jarno --- drivers/hwinfo/hwinfo_handlers.c | 8 ++++++++ drivers/hwinfo/hwinfo_weak_impl.c | 5 +++++ include/zephyr/drivers/hwinfo.h | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/drivers/hwinfo/hwinfo_handlers.c b/drivers/hwinfo/hwinfo_handlers.c index 02058f9b955..a1eb9e2c830 100644 --- a/drivers/hwinfo/hwinfo_handlers.c +++ b/drivers/hwinfo/hwinfo_handlers.c @@ -15,6 +15,14 @@ ssize_t z_vrfy_hwinfo_get_device_id(uint8_t *buffer, size_t length) } #include +ssize_t z_vrfy_hwinfo_get_device_eui64(uint8_t *buffer) +{ + K_OOPS(K_SYSCALL_MEMORY_WRITE(buffer, 8)); + + return z_impl_hwinfo_get_device_eui64((uint8_t *)buffer); +} +#include + int z_vrfy_hwinfo_get_reset_cause(uint32_t *cause) { int ret; diff --git a/drivers/hwinfo/hwinfo_weak_impl.c b/drivers/hwinfo/hwinfo_weak_impl.c index c951d639ae2..a21745d8928 100644 --- a/drivers/hwinfo/hwinfo_weak_impl.c +++ b/drivers/hwinfo/hwinfo_weak_impl.c @@ -11,6 +11,11 @@ ssize_t __weak z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length) return -ENOSYS; } +int __weak z_impl_hwinfo_get_device_eui64(uint8_t *buffer) +{ + return -ENOSYS; +} + int __weak z_impl_hwinfo_get_reset_cause(uint32_t *cause) { return -ENOSYS; diff --git a/include/zephyr/drivers/hwinfo.h b/include/zephyr/drivers/hwinfo.h index df412cdf29d..468356284be 100644 --- a/include/zephyr/drivers/hwinfo.h +++ b/include/zephyr/drivers/hwinfo.h @@ -95,6 +95,22 @@ __syscall ssize_t hwinfo_get_device_id(uint8_t *buffer, size_t length); ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length); +/** + * @brief Copy the device EUI64 to a buffer + * + * This routine copies the device EUI64 (8 bytes) to the buffer. + * The EUI64 depends on the hardware and is guaranteed unique. + * + * @param buffer Buffer of 8 bytes to write the ID to. + * + * @retval zero if successful. + * @retval -ENOSYS if there is no implementation for the particular device. + * @retval any negative value on driver specific errors. + */ +__syscall int hwinfo_get_device_eui64(uint8_t *buffer); + +int z_impl_hwinfo_get_device_eui64(uint8_t *buffer); + /** * @brief Retrieve cause of device reset. *