1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #10402 from bergzand/pr/mrf24j40/undedup_address

mrf24j40: Don't use netdev_ieee802154_t for link layer address
This commit is contained in:
Martine Lenders 2019-01-13 13:17:40 +01:00 committed by GitHub
commit 35868a3474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 15 deletions

View File

@ -20,6 +20,7 @@
* @}
*/
#include "byteorder.h"
#include "mrf24j40.h"
#include "mrf24j40_internal.h"
#include "mrf24j40_registers.h"
@ -122,42 +123,48 @@ static const uint8_t RSSI_value[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
uint16_t mrf24j40_get_addr_short(mrf24j40_t *dev)
{
return (dev->netdev.short_addr[0] << 8) | dev->netdev.short_addr[1];
network_uint16_t naddr;
naddr.u8[1] = mrf24j40_reg_read_short(dev, MRF24J40_REG_SADRL);
naddr.u8[0] = mrf24j40_reg_read_short(dev, MRF24J40_REG_SADRH);
return naddr.u16;
}
void mrf24j40_set_addr_short(mrf24j40_t *dev, uint16_t addr)
{
network_uint16_t naddr;
naddr.u16 = addr;
#ifdef MODULE_SIXLOWPAN
/* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit to
* 0 for unicast addresses */
dev->netdev.short_addr[0] &= 0x7F;
naddr.u8[0] &= 0x7F;
#endif
dev->netdev.short_addr[0] = (uint8_t)(addr);
dev->netdev.short_addr[1] = (uint8_t)(addr >> 8);
mrf24j40_reg_write_short(dev, MRF24J40_REG_SADRL,
dev->netdev.short_addr[1]);
naddr.u8[1]);
mrf24j40_reg_write_short(dev, MRF24J40_REG_SADRH,
dev->netdev.short_addr[0]);
naddr.u8[0]);
}
uint64_t mrf24j40_get_addr_long(mrf24j40_t *dev)
{
uint64_t addr;
uint8_t *ap = (uint8_t *)(&addr);
network_uint64_t naddr;
for (int i = 0; i < 8; i++) {
ap[i] = dev->netdev.long_addr[i];
naddr.u8[7 - i] = mrf24j40_reg_read_short(dev, (MRF24J40_REG_EADR0 + i));
}
return addr;
return naddr.u64;
}
void mrf24j40_set_addr_long(mrf24j40_t *dev, uint64_t addr)
{
network_uint64_t naddr;
naddr.u64 = addr;
for (int i = 0; i < 8; i++) {
dev->netdev.long_addr[i] = (uint8_t)(addr >> (i * 8));
mrf24j40_reg_write_short(dev, (MRF24J40_REG_EADR0 + i),
(addr >> ((7 - i) * 8)));
(naddr.u8[7 - i]));
}
}

View File

@ -174,6 +174,26 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
int res;
switch (opt) {
case NETOPT_ADDRESS:
if (max_len < sizeof(uint16_t)) {
res = -EOVERFLOW;
}
else {
*(uint16_t*)val = mrf24j40_get_addr_short(dev);
res = sizeof(uint16_t);
}
break;
case NETOPT_ADDRESS_LONG:
if (max_len < sizeof(uint64_t)) {
res = -EOVERFLOW;
}
else {
*(uint64_t*)val = mrf24j40_get_addr_long(dev);
res = sizeof(uint64_t);
}
break;
case NETOPT_CHANNEL_PAGE:
if (max_len < sizeof(uint16_t)) {
res = -EOVERFLOW;
@ -351,7 +371,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
}
else {
mrf24j40_set_addr_short(dev, *((const uint16_t *)val));
/* don't set res to set netdev_ieee802154_t::short_addr */
res = sizeof(uint16_t);
}
break;
@ -361,7 +381,7 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
}
else {
mrf24j40_set_addr_long(dev, *((const uint64_t *)val));
/* don't set res to set netdev_ieee802154_t::long_addr */
res = sizeof(uint64_t);
}
break;