Skip to content

Commit

Permalink
Added option to use task PID for EUI seed under native POSIX (ThingSe…
Browse files Browse the repository at this point in the history
…t#49)

* 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 <[email protected]>
  • Loading branch information
2 people authored and garethpotter committed Aug 11, 2024
1 parent 46e598c commit fcebb52
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 fcebb52

Please sign in to comment.