Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to use task PID for EUI seed under native POSIX #49

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ 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
martinjaeger marked this conversation as resolved.
Show resolved Hide resolved

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