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

drivers/cc2420: use uuid module for addr gen

This commit is contained in:
Hauke Petersen 2017-01-10 15:28:24 +01:00
parent 84246d1687
commit 88636b6919
4 changed files with 8 additions and 43 deletions

View File

@ -42,6 +42,7 @@ endif
ifneq (,$(filter cc2420,$(USEMODULE)))
USEMODULE += xtimer
USEMODULE += uuid
USEMODULE += netif
USEMODULE += ieee802154
USEMODULE += netdev2_ieee802154

View File

@ -20,7 +20,7 @@
* @}
*/
#include "periph/cpuid.h"
#include "uuid.h"
#include "byteorder.h"
#include "net/ieee802154.h"
#include "net/gnrc.h"
@ -32,36 +32,6 @@
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @todo Move this function to a global module
*/
#if CPUID_ID_LEN
static void addr_from_cpuid(uint8_t *addr)
{
/* option 1: generate addresses from CPUID */
uint8_t cpuid[CPUID_ID_LEN];
cpuid_get(cpuid);
memcpy(addr, cpuid, 8);
#if CPUID_ID_LEN < 8
/* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */
for (int i = CPUID_ID_LEN; i < 8; i++) {
addr_long[i] = 0;
}
#else
/* in case CPUID_ID_LEN > 8, XOR those bytes on top of the first 8 */
for (int i = 8; i < CPUID_ID_LEN; i++) {
addr_long[i & 0x07] ^= cpuid[i];
}
#endif
/* make sure we mark the address as non-multicast and not globally unique */
addr_long[0] &= ~(0x01);
addr_long[0] |= 0x02;
}
#endif
void cc2420_setup(cc2420_t * dev, const cc2420_params_t *params)
{
@ -78,16 +48,17 @@ void cc2420_setup(cc2420_t * dev, const cc2420_params_t *params)
int cc2420_init(cc2420_t *dev)
{
uint16_t reg;
uint8_t addr[8] = CC2420_ADDR_FALLBACK;
uint8_t addr[8];
/* reset options and sequence number */
dev->netdev.seq = 0;
dev->netdev.flags = 0;
/* set default address, channel, PAN ID, and TX power */
#if CPUID_ID_LEN
addr_from_cpuid(addr);
#endif
uuid_get(addr, sizeof(addr));
/* make sure we mark the address as non-multicast and not globally unique */
addr[0] &= ~(0x01);
addr[0] |= 0x02;
cc2420_set_addr_short(dev, &addr[6]);
cc2420_set_addr_long(dev, addr);
cc2420_set_pan(dev, CC2420_PANID_DEFAULT);

View File

@ -21,6 +21,7 @@
*/
#include <string.h>
#include <errno.h>
#include "cc2420.h"
#include "cc2420_internal.h"

View File

@ -38,14 +38,6 @@ extern "C" {
*/
#define CC2420_PKT_MAXLEN (IEEE802154_FRAME_LEN_MAX)
/**
* @brief Default addresses used if the CPUID module is not present
*
* In case this address is used, that short address will be created by using the
* last two bytes of the long address.
*/
#define CC2420_ADDR_FALLBACK {0x12, 0x22, 0x33, 0x44, 0x55, 0x66, 0x08, 0x15}
/**
* @brief PAN ID configuration
*/