How can i generate a unique ID in VxWorks 6.8 that are unique within a closed net?
Each device in the net requires a associated ID, set once on startup and are kept until shutdown. They don't have to be random nor cryptographically secure - just unique within the closed net.
The available length is 6 Byte.
Restrictions:
- Devices may boot at once (or very close together) as well as separated in time
- Devices may vary in types / architectures (however, each supports whether
dTSEC
oreTSEC
) - Devices run with same (at least or similar) VxWorks 6.8 Kernel
- ID's cant be set manually or hard coded
- No 3rd Party libraries
- No network communication / negotiation
I've made some attempts for testing and development purposes using some kind of "random voodoo" (e.g. see code below); until now they worked without a collision but i'm not sure if they are unique enough to stay secure.
What i need is a real solution.
At the moment i use the nanosecond time of CLOCK_MONOTONIC
and an 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) the monotonic nanoseconds are different everywhere in the net (remember: those ID's are set once at startup) - hence the ID is "unique". But as the "hopefully" indicates: there's a chance they are not. Time is not the best choice here.
As a better and more secure solution i considered the usage of the MAC-address. Unfortunately
char mac[6];
muxIoctl(muxCookie, EIOCGADDR, mac);
returns just garbage.