How do I create a unique ID in VxWorks 6.8?
How can I create a unique ID in VxWorks 6.8 that is unique on a closed network ?
Each device on the network requires an associated ID, set it once at startup and save it until shutdown. They don't have to be random or cryptographically secure - just unique on a closed network.
The available length is 6 bytes .
Limitations:
- Devices can boot immediately (or very close to each other), as well as separate in time
- Devices can vary in types / architectures (however, each one supports
dTSEC
oreTSEC
) - Devices start with the same (at least or similar) VxWorks 6.8 Kernel
- ID cannot be set manually or hardcoded
- No third party libraries
- No network connection / negotiation
I've made some testing and development attempts using some kind of "random voodoo" (see code below for example); they have worked without collision so far, but I'm not sure if they are unique enough to stay safe.
I need a real solution .
I am currently using nanosecond time CLOCK_MONOTONIC
and ID for each microcontroller architecture:
#ifdef ARCH_1
# define MC_ARCH_ID 0x01
#elif defined(ARCH_2)
# define MC_ARCH_ID 0x02
/* ... */
#else
# define MC_ARCH_ID 0x00
#endif /* MC_ARCH_ID */
/* ... */
char id[6];
struct timespec tspec;
clock_gettime(CLOCK_MONOTONIC, &tspec);
UINT32 t = htonl(tspec.tv_nsec); /* consistent endian */
id[0] = MC_ARCH_ID; /* 1 Byte ID set for each arch. */
id[1] = (UINT8) ((UINT8*) &t)[0];
id[2] = (UINT8) ((UINT8*) &t)[1];
id[3] = (UINT8) ((UINT8*) &t)[2];
id[4] = (UINT8) ((UINT8*) &t)[3];
id[5] = 0x00; /* Not used yet */
(Hopefully) monotonous nanoseconds are different throughout the network (remember: these IDs are set once at startup) - hence the ID is "unique". But, as "hopefully" points out, there is a chance that it is not. Time is not the best choice here.
I considered using a MAC address as a better and more secure solution. Unfortunately
char mac[6];
muxIoctl(muxCookie, EIOCGADDR, mac);
only returns garbage.
source to share
No one has answered this question yet
See similar questions:
or similar: