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)
{
const struct rf2xx_config *conf = dev->config->config_info;
struct rf2xx_context *ctx = dev->driver_data;
u32_t *ptr = (u32_t *)(ctx->mac_addr);
if (!conf->has_mac) {
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
@ -821,28 +824,40 @@ static struct ieee802154_radio_api rf2xx_radio_api = {
/*
* 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), \
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), \
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), \
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), \
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), \
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), \
DT_INST_SPI_DEV_CS_GPIOS_FLAGS(n))
#define DRV_INST_LOCAL_MAC_ADDRESS(n) \
UTIL_AND(DT_INST_NODE_HAS_PROP(n, local_mac_address), \
UTIL_AND(DT_INST_PROP_LEN(n, local_mac_address) == 8, \
DT_INST_PROP(n, local_mac_address)))
#define IEEE802154_RF2XX_DEVICE_CONFIG(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), \
@ -870,10 +885,12 @@ static struct ieee802154_radio_api rf2xx_radio_api = {
.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;
static struct rf2xx_context rf2xx_ctx_data_##n = { \
.mac_addr = DRV_INST_LOCAL_MAC_ADDRESS(n) \
}
#define IEEE802154_RF2XX_RAW_DEVICE_INIT(n) \
DEVICE_AND_API_INIT( \

View file

@ -88,8 +88,6 @@ struct rf2xx_dt_spi_t {
};
struct rf2xx_config {
u8_t inst;
struct rf2xx_dt_gpio_t irq;
struct rf2xx_dt_gpio_t reset;
struct rf2xx_dt_gpio_t slptr;
@ -97,6 +95,9 @@ struct rf2xx_config {
struct rf2xx_dt_gpio_t clkm;
struct rf2xx_dt_spi_t spi;
u8_t inst;
u8_t has_mac;
};
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
description: ATMEL AT86RF2xx 802.15.4 wireless transceiver
@ -31,3 +31,8 @@ properties:
type: phandle-array
required: false
description: Master clock signal output
local-mac-address:
type: uint8-array
description:
Specifies the MAC address that was assigned to the network device