mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #10534 from bergzand/pr/kw2xrf/undedup_address
kw2xrf: Don't use netdev_ieee802154_t for link layer address
This commit is contained in:
commit
4ab3d1a77b
@ -25,6 +25,7 @@
|
||||
#include "kw2xrf_reg.h"
|
||||
#include "kw2xrf_getset.h"
|
||||
#include "kw2xrf_intern.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
@ -265,12 +266,10 @@ void kw2xrf_set_addr_short(kw2xrf_t *dev, uint16_t addr)
|
||||
uint8_t val_ar[2];
|
||||
val_ar[0] = (addr >> 8);
|
||||
val_ar[1] = (uint8_t)addr;
|
||||
dev->netdev.short_addr[0] = val_ar[1];
|
||||
dev->netdev.short_addr[1] = val_ar[0];
|
||||
#ifdef MODULE_SIXLOWPAN
|
||||
/* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit to
|
||||
* 0 for unicast addresses */
|
||||
dev->netdev.short_addr[1] &= 0x7F;
|
||||
val_ar[0] &= 0x7F;
|
||||
#endif
|
||||
kw2xrf_write_iregs(dev, MKW2XDMI_MACSHORTADDRS0_LSB, val_ar,
|
||||
IEEE802154_SHORT_ADDRESS_LEN);
|
||||
@ -282,7 +281,6 @@ void kw2xrf_set_addr_long(kw2xrf_t *dev, uint64_t addr)
|
||||
uint8_t *ap = (uint8_t *)(&tmp);
|
||||
|
||||
for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) {
|
||||
dev->netdev.long_addr[i] = (uint8_t)(addr >> (i * 8));
|
||||
ap[i] = (addr >> ((IEEE802154_LONG_ADDRESS_LEN - 1 - i) * 8));
|
||||
}
|
||||
|
||||
@ -292,7 +290,11 @@ void kw2xrf_set_addr_long(kw2xrf_t *dev, uint64_t addr)
|
||||
|
||||
uint16_t kw2xrf_get_addr_short(kw2xrf_t *dev)
|
||||
{
|
||||
return (dev->netdev.short_addr[0] << 8) | dev->netdev.short_addr[1];
|
||||
uint16_t addr;
|
||||
uint8_t *ap = (uint8_t *)(&addr);
|
||||
kw2xrf_read_iregs(dev, MKW2XDMI_MACSHORTADDRS0_LSB, ap,
|
||||
IEEE802154_SHORT_ADDRESS_LEN);
|
||||
return byteorder_swaps(addr);
|
||||
}
|
||||
|
||||
uint64_t kw2xrf_get_addr_long(kw2xrf_t *dev)
|
||||
@ -303,7 +305,8 @@ uint64_t kw2xrf_get_addr_long(kw2xrf_t *dev)
|
||||
kw2xrf_read_iregs(dev, MKW2XDMI_MACLONGADDRS0_0, ap,
|
||||
IEEE802154_LONG_ADDRESS_LEN);
|
||||
|
||||
return addr;
|
||||
/* Address is always read as little endian and API specifies big endian */
|
||||
return byteorder_swapll(addr);
|
||||
}
|
||||
|
||||
int8_t kw2xrf_get_cca_threshold(kw2xrf_t *dev)
|
||||
|
@ -258,6 +258,20 @@ int _get(netdev_t *netdev, netopt_t opt, void *value, size_t len)
|
||||
}
|
||||
|
||||
switch (opt) {
|
||||
case NETOPT_ADDRESS:
|
||||
if (len < sizeof(uint16_t)) {
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
*((uint16_t *)value) = kw2xrf_get_addr_short(dev);
|
||||
return sizeof(uint16_t);
|
||||
|
||||
case NETOPT_ADDRESS_LONG:
|
||||
if (len < sizeof(uint64_t)) {
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
*((uint64_t *)value) = kw2xrf_get_addr_long(dev);
|
||||
return sizeof(uint64_t);
|
||||
|
||||
case NETOPT_STATE:
|
||||
if (len < sizeof(netopt_state_t)) {
|
||||
return -EOVERFLOW;
|
||||
@ -392,7 +406,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t len)
|
||||
}
|
||||
else {
|
||||
kw2xrf_set_addr_short(dev, *((uint16_t *)value));
|
||||
/* don't set res to set netdev_ieee802154_t::short_addr */
|
||||
res = sizeof(uint16_t);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -402,7 +416,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t len)
|
||||
}
|
||||
else {
|
||||
kw2xrf_set_addr_long(dev, *((uint64_t *)value));
|
||||
/* don't set res to set netdev_ieee802154_t::short_addr */
|
||||
res = sizeof(uint64_t);
|
||||
}
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user