Skip to content

Commit

Permalink
drivers/mrf24j40: use uuid module for addr gen
Browse files Browse the repository at this point in the history
  • Loading branch information
bergzand committed Jan 20, 2017
1 parent e878f38 commit dec8822
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
1 change: 1 addition & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ endif

ifneq (,$(filter mrf24j40,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += uuid
USEMODULE += netif
USEMODULE += ieee802154
USEMODULE += netdev2_ieee802154
Expand Down
8 changes: 0 additions & 8 deletions drivers/include/mrf24j40.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@
extern "C" {
#endif

/**
* @brief Default addresses used if the CPUID module is not present
* @{
*/
#define MRF24J40_DEFAULT_ADDR_SHORT (0x0230)
#define MRF24J40_DEFAULT_ADDR_LONG (0x1222334455667788)
/** @} */

/**
* @brief Default TX power (0dBm)
* 0 -> -36dB
Expand Down
37 changes: 7 additions & 30 deletions drivers/mrf24j40/mrf24j40.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @}
*/

#include "periph/cpuid.h"
#include "uuid.h"
#include "byteorder.h"
#include "net/gnrc.h"
#include "mrf24j40_registers.h"
Expand All @@ -45,45 +45,22 @@ void mrf24j40_setup(mrf24j40_t *dev, const mrf24j40_params_t *params)

void mrf24j40_reset(mrf24j40_t *dev)
{
#if CPUID_LEN
/* make sure that the buffer is always big enough to store a 64bit value */
# if CPUID_LEN < IEEE802154_LONG_ADDRESS_LEN
uint8_t cpuid[IEEE802154_LONG_ADDRESS_LEN];
# else
uint8_t cpuid[CPUID_LEN];
#endif
eui64_t addr_long;
#endif

mrf24j40_init(dev);

/* reset options and sequence number */
dev->netdev.seq = 0;
dev->netdev.flags = 0;
/* set short and long address */
#if CPUID_LEN
/* in case CPUID_LEN < 8, fill missing bytes with zeros */
memset(cpuid, 0, CPUID_LEN);

cpuid_get(cpuid);

#if CPUID_LEN > IEEE802154_LONG_ADDRESS_LEN
for (int i = IEEE802154_LONG_ADDRESS_LEN; i < CPUID_LEN; i++) {
cpuid[i & 0x07] ^= cpuid[i];
}
#endif

/* make sure we mark the address as non-multicast and not globally unique */
cpuid[0] &= ~(0x01);
cpuid[0] |= 0x02;
/* copy and set long address */
memcpy(&addr_long, cpuid, IEEE802154_LONG_ADDRESS_LEN);
/* get an 8-byte unique ID to use as hardware address */
uuid_get(addr_long.uint8, IEEE802154_LONG_ADDRESS_LEN);
addr_long.uint8[0] &= ~(0x01);
addr_long.uint8[0] |= (0x02);
/* set short and long address */
mrf24j40_set_addr_long(dev, NTOHLL(addr_long.uint64.u64));
mrf24j40_set_addr_short(dev, NTOHS(addr_long.uint16[0].u16));
#else
mrf24j40_set_addr_long(dev, MRF24J40_DEFAULT_ADDR_LONG);
mrf24j40_set_addr_short(dev, MRF24J40_DEFAULT_ADDR_SHORT);
#endif

/* set default PAN id */
mrf24j40_set_pan(dev, IEEE802154_DEFAULT_PANID);
mrf24j40_set_chan(dev, IEEE802154_DEFAULT_CHANNEL);
Expand Down

0 comments on commit dec8822

Please sign in to comment.