Skip to content

Commit

Permalink
Merge pull request #11666 from bergzand/pr/ether/helpers
Browse files Browse the repository at this point in the history
EUI48: Add address flag helper functions
  • Loading branch information
miri64 committed Jun 10, 2019
2 parents 632da8a + 44f9c3f commit 4318af3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/enc28j60/enc28j60.c
Expand Up @@ -26,6 +26,7 @@
#include "xtimer.h"
#include "assert.h"
#include "net/ethernet.h"
#include "net/eui48.h"
#include "net/netdev/eth.h"

#include "enc28j60.h"
Expand Down Expand Up @@ -427,8 +428,8 @@ static int nd_init(netdev_t *netdev)
/* set default MAC address */
uint8_t macbuf[ETHERNET_ADDR_LEN];
luid_get(macbuf, ETHERNET_ADDR_LEN);
macbuf[0] |= 0x02; /* locally administered address */
macbuf[0] &= ~0x01; /* unicast address */
eui48_set_local((eui48_t*)macbuf); /* locally administered address */
eui48_clear_group((eui48_t*)macbuf); /* unicast address */
mac_set(dev, macbuf);

/* PHY configuration */
Expand Down
44 changes: 44 additions & 0 deletions sys/include/net/eui48.h
Expand Up @@ -56,6 +56,24 @@ static inline void eui48_to_eui64(eui64_t *eui64, const eui48_t *addr)
eui64->uint8[7] = addr->uint8[5];
}

/**
* @name EUI-48 bit flags contained in the first octet
*
* @see IEEE 802-2001 section 9.2
* @{
*/

/**
* @brief Locally administered address.
*/
#define EUI48_LOCAL_FLAG 0x02

/**
* @brief Group type address.
*/
#define EUI48_GROUP_FLAG 0x01
/** @} */

/**
* @brief Generates an IPv6 interface identifier from a 48-bit device address
*
Expand Down Expand Up @@ -88,6 +106,32 @@ static inline void eui48_from_ipv6_iid(eui48_t *addr, const eui64_t *iid)
addr->uint8[5] = iid->uint8[7];
}

/**
* @brief Set the locally administrated bit in the EUI-48 address.
*
* @see IEEE 802-2001 section 9.2
*
* @param addr ethernet address
*/
static inline void eui48_set_local(eui48_t *addr)
{
addr->uint8[0] |= EUI48_LOCAL_FLAG;
}

/**
* @brief Clear the group address bit to signal the address as individual
* address
*
* @see IEEE 802-2001 section 9.2
*
* @param addr ethernet address
*/
static inline void eui48_clear_group(eui48_t *addr)
{
addr->uint8[0] &= ~EUI48_GROUP_FLAG;
}


#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 4318af3

Please sign in to comment.