1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

net/eui48: add eui64_to_eui48()

Provide helper function to mangle a EUI-64 into an EUI-48.
This can be useful to get predictable, locally unique addreses.
This commit is contained in:
Benjamin Valentin 2020-09-30 11:17:53 +02:00
parent d7943a49aa
commit 307ea6224a

View File

@ -99,6 +99,31 @@ static inline void eui48_to_eui64(eui64_t *eui64, const eui48_t *addr)
eui64->uint8[7] = addr->uint8[5];
}
/**
* @brief Generates an EUI-48 from a 64-bit device address
*
* @warning The resulting EUI-48 is not guaranteed to be unique
* and, hence, marked as only locally unique.
*
* @param[out] eui48 the resulting EUI-48.
* @param[in] addr a 64-bit device address
*/
static inline void eui64_to_eui48(eui48_t *eui48, const eui64_t *addr)
{
/* Preserve vendor id */
eui48->uint8[0] = addr->uint8[0];
eui48->uint8[1] = addr->uint8[1];
eui48->uint8[2] = addr->uint8[2];
/* Use most volatile bits */
eui48->uint8[3] = addr->uint8[5];
eui48->uint8[4] = addr->uint8[6];
eui48->uint8[5] = addr->uint8[7];
/* EUI is only locally unique */
eui48_set_local(eui48);
}
/**
* @brief Generates an IPv6 interface identifier from a 48-bit device address
*