drivers: ieee802154: rf2xx: Add local-mac-address

Add local-mac-address on DT and enable it on rf2xx driver. If user
define local-mac-address this value will be used as default mac address.
Otherwise driver automatically add a random mac address.

On application level user can change default mac address using net_mgmt
command with NET_REQUEST_IEEE802154_SET_EXT_ADDR parameter defined on
include/net/ieee802154_mgmt.h header.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
Gerson Fernando Budke 2020-03-03 22:37:13 -03:00 committed by Jukka Rissanen
commit c755821608
3 changed files with 74 additions and 51 deletions

View file

@ -307,12 +307,15 @@ static void rf2xx_thread_main(void *arg)
static inline u8_t *get_mac(struct device *dev) static inline u8_t *get_mac(struct device *dev)
{ {
const struct rf2xx_config *conf = dev->config->config_info;
struct rf2xx_context *ctx = dev->driver_data; struct rf2xx_context *ctx = dev->driver_data;
u32_t *ptr = (u32_t *)(ctx->mac_addr); u32_t *ptr = (u32_t *)(ctx->mac_addr);
UNALIGNED_PUT(sys_rand32_get(), ptr); if (!conf->has_mac) {
ptr = (u32_t *)(ctx->mac_addr + 4); UNALIGNED_PUT(sys_rand32_get(), ptr);
UNALIGNED_PUT(sys_rand32_get(), ptr); ptr = (u32_t *)(ctx->mac_addr + 4);
UNALIGNED_PUT(sys_rand32_get(), ptr);
}
/* /*
* Clear bit 0 to ensure it isn't a multicast address and set * Clear bit 0 to ensure it isn't a multicast address and set
@ -821,59 +824,73 @@ static struct ieee802154_radio_api rf2xx_radio_api = {
/* /*
* Optional features place holders, get a 0 if the "gpio" doesn't exist * Optional features place holders, get a 0 if the "gpio" doesn't exist
*/ */
#define DRV_INST_GPIO_LABEL(n, gpio_pha) \
UTIL_AND(DT_INST_NODE_HAS_PROP(n, gpio_pha), \ #define DRV_INST_GPIO_LABEL(n, gpio_pha) \
UTIL_AND(DT_INST_NODE_HAS_PROP(n, gpio_pha), \
DT_INST_GPIO_LABEL(n, gpio_pha)) DT_INST_GPIO_LABEL(n, gpio_pha))
#define DRV_INST_GPIO_PIN(n, gpio_pha) \
UTIL_AND(DT_INST_NODE_HAS_PROP(n, gpio_pha), \ #define DRV_INST_GPIO_PIN(n, gpio_pha) \
UTIL_AND(DT_INST_NODE_HAS_PROP(n, gpio_pha), \
DT_INST_GPIO_PIN(n, gpio_pha)) DT_INST_GPIO_PIN(n, gpio_pha))
#define DRV_INST_GPIO_FLAGS(n, gpio_pha) \
UTIL_AND(DT_INST_NODE_HAS_PROP(n, gpio_pha), \ #define DRV_INST_GPIO_FLAGS(n, gpio_pha) \
UTIL_AND(DT_INST_NODE_HAS_PROP(n, gpio_pha), \
DT_INST_GPIO_FLAGS(n, gpio_pha)) DT_INST_GPIO_FLAGS(n, gpio_pha))
#define DRV_INST_SPI_DEV_CS_GPIOS_LABEL(n) \
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \ #define DRV_INST_SPI_DEV_CS_GPIOS_LABEL(n) \
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \
DT_INST_SPI_DEV_CS_GPIOS_LABEL(n)) DT_INST_SPI_DEV_CS_GPIOS_LABEL(n))
#define DRV_INST_SPI_DEV_CS_GPIOS_PIN(n) \
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \ #define DRV_INST_SPI_DEV_CS_GPIOS_PIN(n) \
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \
DT_INST_SPI_DEV_CS_GPIOS_PIN(n)) DT_INST_SPI_DEV_CS_GPIOS_PIN(n))
#define DRV_INST_SPI_DEV_CS_GPIOS_FLAGS(n) \
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \ #define DRV_INST_SPI_DEV_CS_GPIOS_FLAGS(n) \
UTIL_AND(DT_INST_SPI_DEV_HAS_CS_GPIOS(n), \
DT_INST_SPI_DEV_CS_GPIOS_FLAGS(n)) DT_INST_SPI_DEV_CS_GPIOS_FLAGS(n))
#define IEEE802154_RF2XX_DEVICE_CONFIG(n) \ #define DRV_INST_LOCAL_MAC_ADDRESS(n) \
static const struct rf2xx_config rf2xx_ctx_config_##n = { \ UTIL_AND(DT_INST_NODE_HAS_PROP(n, local_mac_address), \
.inst = n, \ UTIL_AND(DT_INST_PROP_LEN(n, local_mac_address) == 8, \
\ DT_INST_PROP(n, local_mac_address)))
.irq.devname = DRV_INST_GPIO_LABEL(n, irq_gpios), \
.irq.pin = DRV_INST_GPIO_PIN(n, irq_gpios), \
.irq.flags = DRV_INST_GPIO_FLAGS(n, irq_gpios), \
\
.reset.devname = DRV_INST_GPIO_LABEL(n, reset_gpios), \
.reset.pin = DRV_INST_GPIO_PIN(n, reset_gpios), \
.reset.flags = DRV_INST_GPIO_FLAGS(n, reset_gpios), \
\
.slptr.devname = DRV_INST_GPIO_LABEL(n, slptr_gpios), \
.slptr.pin = DRV_INST_GPIO_PIN(n, slptr_gpios), \
.slptr.flags = DRV_INST_GPIO_FLAGS(n, slptr_gpios), \
\
.dig2.devname = DRV_INST_GPIO_LABEL(n, dig2_gpios), \
.dig2.pin = DRV_INST_GPIO_PIN(n, dig2_gpios), \
.dig2.flags = DRV_INST_GPIO_FLAGS(n, dig2_gpios), \
\
.clkm.devname = DRV_INST_GPIO_LABEL(n, clkm_gpios), \
.clkm.pin = DRV_INST_GPIO_PIN(n, clkm_gpios), \
.clkm.flags = DRV_INST_GPIO_FLAGS(n, clkm_gpios), \
\
.spi.devname = DT_INST_BUS_LABEL(n), \
.spi.addr = DT_INST_REG_ADDR(n), \
.spi.freq = DT_INST_PROP(n, spi_max_frequency), \
.spi.cs.devname = DRV_INST_SPI_DEV_CS_GPIOS_LABEL(n), \
.spi.cs.pin = DRV_INST_SPI_DEV_CS_GPIOS_PIN(n), \
.spi.cs.flags = DRV_INST_SPI_DEV_CS_GPIOS_FLAGS(n), \
};
#define IEEE802154_RF2XX_DEVICE_DATA(n) \ #define IEEE802154_RF2XX_DEVICE_CONFIG(n) \
static struct rf2xx_context rf2xx_ctx_data_##n; static const struct rf2xx_config rf2xx_ctx_config_##n = { \
.inst = n, \
.has_mac = DT_INST_NODE_HAS_PROP(n, local_mac_address), \
\
.irq.devname = DRV_INST_GPIO_LABEL(n, irq_gpios), \
.irq.pin = DRV_INST_GPIO_PIN(n, irq_gpios), \
.irq.flags = DRV_INST_GPIO_FLAGS(n, irq_gpios), \
\
.reset.devname = DRV_INST_GPIO_LABEL(n, reset_gpios), \
.reset.pin = DRV_INST_GPIO_PIN(n, reset_gpios), \
.reset.flags = DRV_INST_GPIO_FLAGS(n, reset_gpios), \
\
.slptr.devname = DRV_INST_GPIO_LABEL(n, slptr_gpios), \
.slptr.pin = DRV_INST_GPIO_PIN(n, slptr_gpios), \
.slptr.flags = DRV_INST_GPIO_FLAGS(n, slptr_gpios), \
\
.dig2.devname = DRV_INST_GPIO_LABEL(n, dig2_gpios), \
.dig2.pin = DRV_INST_GPIO_PIN(n, dig2_gpios), \
.dig2.flags = DRV_INST_GPIO_FLAGS(n, dig2_gpios), \
\
.clkm.devname = DRV_INST_GPIO_LABEL(n, clkm_gpios), \
.clkm.pin = DRV_INST_GPIO_PIN(n, clkm_gpios), \
.clkm.flags = DRV_INST_GPIO_FLAGS(n, clkm_gpios), \
\
.spi.devname = DT_INST_BUS_LABEL(n), \
.spi.addr = DT_INST_REG_ADDR(n), \
.spi.freq = DT_INST_PROP(n, spi_max_frequency), \
.spi.cs.devname = DRV_INST_SPI_DEV_CS_GPIOS_LABEL(n), \
.spi.cs.pin = DRV_INST_SPI_DEV_CS_GPIOS_PIN(n), \
.spi.cs.flags = DRV_INST_SPI_DEV_CS_GPIOS_FLAGS(n), \
}
#define IEEE802154_RF2XX_DEVICE_DATA(n) \
static struct rf2xx_context rf2xx_ctx_data_##n = { \
.mac_addr = DRV_INST_LOCAL_MAC_ADDRESS(n) \
}
#define IEEE802154_RF2XX_RAW_DEVICE_INIT(n) \ #define IEEE802154_RF2XX_RAW_DEVICE_INIT(n) \
DEVICE_AND_API_INIT( \ DEVICE_AND_API_INIT( \

View file

@ -88,8 +88,6 @@ struct rf2xx_dt_spi_t {
}; };
struct rf2xx_config { struct rf2xx_config {
u8_t inst;
struct rf2xx_dt_gpio_t irq; struct rf2xx_dt_gpio_t irq;
struct rf2xx_dt_gpio_t reset; struct rf2xx_dt_gpio_t reset;
struct rf2xx_dt_gpio_t slptr; struct rf2xx_dt_gpio_t slptr;
@ -97,6 +95,9 @@ struct rf2xx_config {
struct rf2xx_dt_gpio_t clkm; struct rf2xx_dt_gpio_t clkm;
struct rf2xx_dt_spi_t spi; struct rf2xx_dt_spi_t spi;
u8_t inst;
u8_t has_mac;
}; };
struct rf2xx_context { struct rf2xx_context {

View file

@ -1,4 +1,4 @@
# Copyright (c) 2019, Gerson Fernando Budke # Copyright (c) 2019-2020 Gerson Fernando Budke <nandojve@gmail.com>
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
description: ATMEL AT86RF2xx 802.15.4 wireless transceiver description: ATMEL AT86RF2xx 802.15.4 wireless transceiver
@ -31,3 +31,8 @@ properties:
type: phandle-array type: phandle-array
required: false required: false
description: Master clock signal output description: Master clock signal output
local-mac-address:
type: uint8-array
description:
Specifies the MAC address that was assigned to the network device