Merge pull request #2963 from OlegHahm/fix_2962
at86rf2xx: fix EUI64 computation
This commit is contained in:
commit
354e5db5a8
@ -30,6 +30,7 @@
|
|||||||
#include "periph/uart.h"
|
#include "periph/uart.h"
|
||||||
#include "periph/gpio.h"
|
#include "periph/gpio.h"
|
||||||
#include "net/ng_netbase.h"
|
#include "net/ng_netbase.h"
|
||||||
|
#include "net/ng_ieee802154.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -59,11 +60,6 @@
|
|||||||
#define XBEE_DEFAULT_PROTOCOL (NG_NETTYPE_UNDEF)
|
#define XBEE_DEFAULT_PROTOCOL (NG_NETTYPE_UNDEF)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Default short address used after initialization
|
|
||||||
*/
|
|
||||||
#define XBEE_DEFAULT_SHORT_ADDR (0x0230)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default PAN ID used after initialization
|
* @brief Default PAN ID used after initialization
|
||||||
*/
|
*/
|
||||||
@ -109,7 +105,7 @@ typedef struct {
|
|||||||
ng_nettype_t proto; /**< protocol the interface speaks */
|
ng_nettype_t proto; /**< protocol the interface speaks */
|
||||||
uint8_t options; /**< options field */
|
uint8_t options; /**< options field */
|
||||||
uint8_t addr_short[2]; /**< onw 802.15.4 short address */
|
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 */
|
/* general variables for the UART RX state machine */
|
||||||
xbee_rx_state_t int_state; /**< current state if the UART RX FSM */
|
xbee_rx_state_t int_state; /**< current state if the UART RX FSM */
|
||||||
uint16_t int_size; /**< temporary space for parsing the
|
uint16_t int_size; /**< temporary space for parsing the
|
||||||
|
|||||||
@ -18,12 +18,14 @@
|
|||||||
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hwtimer.h"
|
#include "hwtimer.h"
|
||||||
#include "periph/cpuid.h"
|
#include "periph/cpuid.h"
|
||||||
|
#include "byteorder.h"
|
||||||
#include "net/ng_ieee802154.h"
|
#include "net/ng_ieee802154.h"
|
||||||
#include "net/ng_netbase.h"
|
#include "net/ng_netbase.h"
|
||||||
#include "ng_at86rf2xx_registers.h"
|
#include "ng_at86rf2xx_registers.h"
|
||||||
@ -87,8 +89,7 @@ void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev)
|
|||||||
{
|
{
|
||||||
#if CPUID_ID_LEN
|
#if CPUID_ID_LEN
|
||||||
uint8_t cpuid[CPUID_ID_LEN];
|
uint8_t cpuid[CPUID_ID_LEN];
|
||||||
uint16_t addr_short;
|
eui64_t addr_long;
|
||||||
uint64_t addr_long;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* trigger hardware reset */
|
/* trigger hardware reset */
|
||||||
@ -101,7 +102,8 @@ void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev)
|
|||||||
/* set short and long address */
|
/* set short and long address */
|
||||||
#if CPUID_ID_LEN
|
#if CPUID_ID_LEN
|
||||||
cpuid_get(cpuid);
|
cpuid_get(cpuid);
|
||||||
#if CPUID < 8
|
|
||||||
|
#if CPUID_ID_LEN < 8
|
||||||
/* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */
|
/* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */
|
||||||
for (int i = CPUID_ID_LEN; i < 8; i++) {
|
for (int i = CPUID_ID_LEN; i < 8; i++) {
|
||||||
cpuid[i] = 0;
|
cpuid[i] = 0;
|
||||||
@ -116,13 +118,8 @@ void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev)
|
|||||||
cpuid[0] |= 0x02;
|
cpuid[0] |= 0x02;
|
||||||
/* copy and set long address */
|
/* copy and set long address */
|
||||||
memcpy(&addr_long, cpuid, 8);
|
memcpy(&addr_long, cpuid, 8);
|
||||||
ng_at86rf2xx_set_addr_long(dev, addr_long);
|
ng_at86rf2xx_set_addr_long(dev, NTOHLL(addr_long.uint64.u64));
|
||||||
/* now compress the long addr to form the short address */
|
ng_at86rf2xx_set_addr_short(dev, NTOHS(addr_long.uint16[0].u16));
|
||||||
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);
|
|
||||||
#else
|
#else
|
||||||
ng_at86rf2xx_set_addr_long(dev, NG_AT86RF2XX_DEFAULT_ADDR_LONG);
|
ng_at86rf2xx_set_addr_long(dev, NG_AT86RF2XX_DEFAULT_ADDR_LONG);
|
||||||
ng_at86rf2xx_set_addr_short(dev, NG_AT86RF2XX_DEFAULT_ADDR_SHORT);
|
ng_at86rf2xx_set_addr_short(dev, NG_AT86RF2XX_DEFAULT_ADDR_SHORT);
|
||||||
|
|||||||
@ -23,13 +23,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "xbee.h"
|
#include "xbee.h"
|
||||||
#include "mutex.h"
|
|
||||||
#include "hwtimer.h"
|
#include "hwtimer.h"
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
#include "periph/uart.h"
|
|
||||||
#include "periph/gpio.h"
|
|
||||||
#include "periph/cpuid.h"
|
#include "periph/cpuid.h"
|
||||||
#include "net/ng_netbase.h"
|
|
||||||
|
|
||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -452,24 +448,10 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate,
|
|||||||
/* exit command mode */
|
/* exit command mode */
|
||||||
_at_cmd(dev, "ATCN\r");
|
_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) */
|
/* 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 default channel */
|
||||||
|
_set_addr(dev, &((dev->addr_long).uint8[6]), 2);
|
||||||
tmp[1] = 0;
|
tmp[1] = 0;
|
||||||
tmp[0] = XBEE_DEFAULT_CHANNEL;
|
tmp[0] = XBEE_DEFAULT_CHANNEL;
|
||||||
_set_channel(dev, tmp, 2);
|
_set_channel(dev, tmp, 2);
|
||||||
@ -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);
|
ng_netif_hdr_set_dst_addr(hdr, dev->addr_short, 2);
|
||||||
}
|
}
|
||||||
else {
|
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;
|
pos = 3 + addr_len;
|
||||||
/* allocate and copy payload */
|
/* allocate and copy payload */
|
||||||
|
|||||||
@ -21,6 +21,9 @@
|
|||||||
#ifndef NG_IEEE802154_H_
|
#ifndef NG_IEEE802154_H_
|
||||||
#define NG_IEEE802154_H_
|
#define NG_IEEE802154_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "byteorder.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -58,6 +61,15 @@ extern "C" {
|
|||||||
#define NG_IEEE802154_FCF_SRC_ADDR_LONG (0xc0)
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user