mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/at86rf2xx: move addr logic to netdev
This commit is contained in:
parent
ba6c0d845e
commit
2965419028
@ -96,26 +96,19 @@ static const uint8_t dbm_to_tx_pow[] = { 0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
|
||||
|
||||
void at86rf2xx_set_addr_short(at86rf2xx_t *dev, const network_uint16_t *addr)
|
||||
{
|
||||
memcpy(dev->netdev.short_addr, addr, sizeof(*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;
|
||||
#endif
|
||||
/* device use lsb first, not network byte order */
|
||||
at86rf2xx_reg_write(dev, AT86RF2XX_REG__SHORT_ADDR_0,
|
||||
dev->netdev.short_addr[1]);
|
||||
addr->u8[1]);
|
||||
at86rf2xx_reg_write(dev, AT86RF2XX_REG__SHORT_ADDR_1,
|
||||
dev->netdev.short_addr[0]);
|
||||
addr->u8[0]);
|
||||
}
|
||||
|
||||
void at86rf2xx_set_addr_long(at86rf2xx_t *dev, const eui64_t *addr)
|
||||
{
|
||||
memcpy(dev->netdev.long_addr, addr, sizeof(*addr));
|
||||
for (int i = 0; i < 8; i++) {
|
||||
/* device use lsb first, not network byte order */
|
||||
at86rf2xx_reg_write(dev, (AT86RF2XX_REG__IEEE_ADDR_0 + i),
|
||||
dev->netdev.long_addr[IEEE802154_LONG_ADDRESS_LEN - 1 - i]);
|
||||
addr->uint8[IEEE802154_LONG_ADDRESS_LEN - 1 - i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,11 +486,18 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
||||
switch (opt) {
|
||||
case NETOPT_ADDRESS:
|
||||
assert(len == sizeof(network_uint16_t));
|
||||
memcpy(dev->netdev.short_addr, val, len);
|
||||
#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;
|
||||
#endif
|
||||
at86rf2xx_set_addr_short(dev, val);
|
||||
/* don't set res to set netdev_ieee802154_t::short_addr */
|
||||
break;
|
||||
case NETOPT_ADDRESS_LONG:
|
||||
assert(len == sizeof(eui64_t));
|
||||
memcpy(dev->netdev.long_addr, val, len);
|
||||
at86rf2xx_set_addr_long(dev, val);
|
||||
/* don't set res to set netdev_ieee802154_t::long_addr */
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user