Skip to content

Commit

Permalink
Added option to use task PID for EUI seed under native POSIX (#49)
Browse files Browse the repository at this point in the history
* Changed EUI seed to use task PID for native POSIX
* Use Kconfig to switch between RNG and PID based EUI generation
* Add BOARD_NATIVE_POSIX dependency to Kconfig

Co-authored-by: Simon Gilbert <Simon.Gilbert@Brillpower.com>
  • Loading branch information
sgilbert182 and SGilbert-bp authored Jun 19, 2024
1 parent b3382df commit b9ddc01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ config THINGSET_GENERATE_NODE_ID
select CRC
default y

config THINGSET_PID_EUI
bool "Use task PID as EUI basis for EUI generation"
depends on THINGSET_GENERATE_NODE_ID
depends on BOARD_NATIVE_POSIX

config THINGSET_NODE_NAME
string "Default ThingSet node name"
default "ThingSet Node"
Expand Down
13 changes: 13 additions & 0 deletions src/sdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include <thingset.h>
#include <thingset/sdk.h>

#ifdef CONFIG_THINGSET_PID_EUI
#include <unistd.h>
#endif

LOG_MODULE_REGISTER(thingset_sdk, CONFIG_THINGSET_SDK_LOG_LEVEL);

/*
Expand Down Expand Up @@ -119,10 +123,19 @@ static void generate_device_eui()
#ifndef CONFIG_BOARD_NATIVE_POSIX
hwinfo_get_device_id(buf, sizeof(buf));
#else

#ifndef CONFIG_THINGSET_PID_EUI
/* hwinfo is not available in native_posix, so we use random data instead */
for (int i = 0; i < sizeof(buf); i++) {
buf[i] = sys_rand32_get() & 0xFF;
}
#else
/* hwinfo is not available in native_posix, so we take task PID instead */
int pid = getpid();

snprintk(buf, sizeof(buf), "%X", pid);
#endif

#endif

crc = crc32_ieee(buf, 8);
Expand Down

0 comments on commit b9ddc01

Please sign in to comment.