Skip to content

Commit

Permalink
xbee: fixed that _set_addr destructed given address.
Browse files Browse the repository at this point in the history
`_set_addr` is called from `xbee_init` with lower bytes of the long address.
If `_set_addr` destructs the given address, the long address is also destructed.
  • Loading branch information
Yonezawa-T2 committed Feb 29, 2016
1 parent 42d761b commit 495be09
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions drivers/xbee/xbee.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,26 @@ static int _set_short_addr(xbee_t *dev, uint8_t *address)

static int _set_addr(xbee_t *dev, uint8_t *val, size_t len)
{
uint8_t addr[2];

/* device only supports setting the short address */
if (len != 2) {
return -ENOTSUP;
}

if (dev->addr_flags & XBEE_ADDR_FLAGS_LONG ||
_set_short_addr(dev, val) == 0) {
addr[0] = val[0];
addr[1] = val[1];

#ifdef MODULE_SIXLOWPAN
/* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit
* to 0 for unicast addresses */
val[1] &= 0x7F;
/* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit
* to 0 for unicast addresses */
addr[1] &= 0x7F;
#endif

memcpy(dev->addr_short, val, 2);
if (dev->addr_flags & XBEE_ADDR_FLAGS_LONG ||
_set_short_addr(dev, addr) == 0) {

memcpy(dev->addr_short, addr, 2);

return 2;
}
Expand Down

0 comments on commit 495be09

Please sign in to comment.