Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions drivers/include/xbee.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "periph/uart.h"
#include "periph/gpio.h"
#include "net/ng_netbase.h"
#include "net/ng_ieee802154.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -59,11 +60,6 @@
#define XBEE_DEFAULT_PROTOCOL (NG_NETTYPE_UNDEF)
#endif

/**
* @brief Default short address used after initialization
*/
#define XBEE_DEFAULT_SHORT_ADDR (0x0230)

/**
* @brief Default PAN ID used after initialization
*/
Expand Down Expand Up @@ -109,7 +105,7 @@ typedef struct {
ng_nettype_t proto; /**< protocol the interface speaks */
uint8_t options; /**< options field */
uint8_t addr_short[2]; /**< onw 802.15.4 short address */
uint8_t addr_long[8]; /**< own 802.15.4 long address */
eui64_t addr_long; /**< own 802.15.4 long address */
/* general variables for the UART RX state machine */
xbee_rx_state_t int_state; /**< current state if the UART RX FSM */
uint16_t int_size; /**< temporary space for parsing the
Expand Down
17 changes: 7 additions & 10 deletions drivers/ng_at86rf2xx/ng_at86rf2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
* @author Thomas Eichinger <[email protected]>
* @author Hauke Petersen <[email protected]>
* @author Kaspar Schleiser <[email protected]>
* @author Oliver Hahm <[email protected]>
*
* @}
*/

#include "hwtimer.h"
#include "periph/cpuid.h"
#include "byteorder.h"
#include "net/ng_ieee802154.h"
#include "net/ng_netbase.h"
#include "ng_at86rf2xx_registers.h"
Expand Down Expand Up @@ -87,8 +89,7 @@ void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev)
{
#if CPUID_ID_LEN
uint8_t cpuid[CPUID_ID_LEN];
uint16_t addr_short;
uint64_t addr_long;
eui64_t addr_long;
#endif

/* trigger hardware reset */
Expand All @@ -101,7 +102,8 @@ void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev)
/* set short and long address */
#if CPUID_ID_LEN
cpuid_get(cpuid);
#if 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++) {
cpuid[i] = 0;
Expand All @@ -116,13 +118,8 @@ void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev)
cpuid[0] |= 0x02;
/* copy and set long address */
memcpy(&addr_long, cpuid, 8);
ng_at86rf2xx_set_addr_long(dev, addr_long);
/* now compress the long addr to form the short address */
for (int i = 2; i < 8; i++) {
cpuid[i & 0x01] ^= cpuid[i];
}
memcpy(&addr_short, cpuid, 2);
ng_at86rf2xx_set_addr_short(dev, addr_short);
ng_at86rf2xx_set_addr_long(dev, NTOHLL(addr_long.uint64.u64));
ng_at86rf2xx_set_addr_short(dev, NTOHS(addr_long.uint16[0].u16));
#else
ng_at86rf2xx_set_addr_long(dev, NG_AT86RF2XX_DEFAULT_ADDR_LONG);
ng_at86rf2xx_set_addr_short(dev, NG_AT86RF2XX_DEFAULT_ADDR_SHORT);
Expand Down
24 changes: 3 additions & 21 deletions drivers/xbee/xbee.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
#include <string.h>

#include "xbee.h"
#include "mutex.h"
#include "hwtimer.h"
#include "msg.h"
#include "periph/uart.h"
#include "periph/gpio.h"
#include "periph/cpuid.h"
#include "net/ng_netbase.h"

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand Down Expand Up @@ -452,24 +448,10 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate,
/* exit command mode */
_at_cmd(dev, "ATCN\r");

/* set default short address, use CPU ID if available */
#if CPUID_ID_LEN
/* get CPU ID */
uint8_t id[CPUID_ID_LEN];
cpuid_get(id);
/* set address */
memset(dev->addr_short, 0, 2);
for (int i = 0; i < CPUID_ID_LEN; i++) {
dev->addr_short[i & 0x01] ^= id[i];
}
#else
dev->addr_short[0] = (uint8_t)(XBEE_DEFAULT_SHORT_ADDR >> 8);
dev->addr_short[1] = (uint8_t)(XBEE_DEFAULT_SHORT_ADDR);
#endif
_set_addr(dev, dev->addr_short, 2);
/* load long address (we can not set it, its read only for Xbee devices) */
_get_addr_long(dev, dev->addr_long, 8);
_get_addr_long(dev, dev->addr_long.uint8, 8);
/* set default channel */
_set_addr(dev, &((dev->addr_long).uint8[6]), 2);
tmp[1] = 0;
tmp[0] = XBEE_DEFAULT_CHANNEL;
_set_channel(dev, tmp, 2);
Expand Down Expand Up @@ -709,7 +691,7 @@ static void _isr_event(ng_netdev_t *netdev, uint32_t event_type)
ng_netif_hdr_set_dst_addr(hdr, dev->addr_short, 2);
}
else {
ng_netif_hdr_set_dst_addr(hdr, dev->addr_long, 8);
ng_netif_hdr_set_dst_addr(hdr, dev->addr_long.uint8, 8);
}
pos = 3 + addr_len;
/* allocate and copy payload */
Expand Down
12 changes: 12 additions & 0 deletions sys/include/net/ng_ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#ifndef NG_IEEE802154_H_
#define NG_IEEE802154_H_

#include <stdint.h>
#include "byteorder.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -58,6 +61,15 @@ extern "C" {
#define NG_IEEE802154_FCF_SRC_ADDR_LONG (0xc0)
/** @} */

/**
* @brief Data type to represent an EUI-64.
*/
typedef union {
le_uint64_t uint64; /**< represented as 64 bit value */
uint8_t uint8[8]; /**< split into 8 8-bit words. */
le_uint16_t uint16[4]; /**< split into 4 16-bit words. */
} eui64_t ;

#ifdef __cplusplus
}
#endif
Expand Down