Merged in merlin17/nuttx/ieee802154 (pull request #297)

wireless/ieee802154: Clean up code, adding MAC layer defines, and data structures

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Anthony Merlino
2017-03-24 15:55:46 +00:00
committed by Gregory Nutt
11 changed files with 510 additions and 237 deletions
+1 -1
View File
@@ -299,7 +299,7 @@ int stm32_can_setup(void);
****************************************************************************/
#if defined(CONFIG_CLICKER2_STM32_MB1_BEE) || defined(CONFIG_CLICKER2_STM32_MB2_BEE)
int stm32_mrf24j40_initialize(void)
int stm32_mrf24j40_initialize(void);
#endif
#endif /* __ASSEMBLY__ */
+12 -10
View File
@@ -47,9 +47,9 @@
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/wireless/ieee80154/ieee802154_radio.h>
#include <nuttx/wireless/ieee80154/ieee802154_mac.h>
#include <nuttx/wireless/ieee80154/mrf24j40.h>
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
#include <nuttx/wireless/ieee802154/mrf24j40.h>
#include "stm32_gpio.h"
#include "stm32_exti.h"
@@ -120,7 +120,7 @@ static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower,
xcpt_t handler);
static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower,
int state);
static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)'
static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv);
/****************************************************************************
* Private Data
@@ -172,12 +172,12 @@ static struct stm32_priv_s g_mrf24j40_mb2_priv =
* irq_enable - Enable or disable the GPIO interrupt
*/
static int stm32_attach_irq(FAR struct mrf24j40_lower_s *lower,
static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower,
xcpt_t handler)
{
FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower;
FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower;
DEBUASSERT(priv != NULL);
DEBUGASSERT(priv != NULL);
/* Just save the handler for use when the interrupt is enabled */
@@ -185,9 +185,9 @@ static int stm32_attach_irq(FAR struct mrf24j40_lower_s *lower,
return OK;
}
static void stm32_enable_irq(FAR struct mrf24j40_lower_s *lower, int state)
static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, int state)
{
FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower;
FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower;
/* The caller should not attempt to enable interrupts if the handler
* has not yet been 'attached'
@@ -201,7 +201,7 @@ static void stm32_enable_irq(FAR struct mrf24j40_lower_s *lower, int state)
if (state != 0)
{
(void)stm32_gpiosetevent(priv->intcfg, true, true, true,
priv->handler, lower);
priv->handler, NULL);
}
else
{
@@ -230,6 +230,8 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)
#endif
FAR struct spi_dev_s *spi;
int ret;
/* Configure the interrupt pin */
stm32_configgpio(priv->intcfg);
+13 -59
View File
@@ -57,6 +57,7 @@
#include <nuttx/wireless/ieee802154/mrf24j40.h>
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
#include "mrf24j40.h"
@@ -92,44 +93,6 @@
#define MRF24J40_PA_ED 2
#define MRF24J40_PA_SLEEP 3
/* IEEE 802.15.4 frame specifics */
/* Security Enabled */
#define IEEE802154_SEC_OFF 0x00
#define IEEE802154_SEC_ON 0x08
/* Flags */
#define IEEE802154_PEND 0x10
#define IEEE802154_ACK_REQ 0x20
#define IEEE802154_INTRA 0x40
/* Dest Addressing modes */
#define IEEE802154_DADDR_NONE 0x00
#define IEEE802154_DADDR_SHORT 0x08
#define IEEE802154_DADDR_EXT 0x0A
/* Src Addressing modes */
#define IEEE802154_SADDR_NONE 0x00
#define IEEE802154_SADDR_SHORT 0x80
#define IEEE802154_SADDR_EXT 0xA0
/* Frame control field masks, 2 bytes
* Seee IEEE 802.15.4/2003 7.2.1.1 page 112
*/
#define IEEE802154_FC1_FTYPE 0x03 /* Frame type, bits 0-2 */
#define IEEE802154_FC1_SEC 0x08 /* Security Enabled, bit 3 */
#define IEEE802154_FC1_PEND 0x10 /* Frame pending, bit 4 */
#define IEEE802154_FC1_ACKREQ 0x20 /* Acknowledge request, bit 5 */
#define IEEE802154_FC1_INTRA 0x40 /* Intra PAN, bit 6 */
#define IEEE802154_FC2_DADDR 0x0C /* Dest addressing mode, bits 10-11 */
#define IEEE802154_FC2_VERSION 0x30 /* Source addressing mode, bits 12-13 */
#define IEEE802154_FC2_SADDR 0xC0 /* Source addressing mode, bits 14-15 */
/****************************************************************************
* Private Types
****************************************************************************/
@@ -1110,7 +1073,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee,
uint8_t reg;
int ret;
int hlen = 3; /* Include frame control and seq number */
uint8_t fc1, fc2;
uint16_t frame_ctrl;
mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO);
@@ -1124,41 +1087,32 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee,
/* Analyze frame control to compute header length */
fc1 = packet->data[0];
fc2 = packet->data[1];
frame_ctrl = packet->data[0];
frame_ctrl |= packet->data[1] << 8;
//wlinfo("fc1 %02X fc2 %02X\n", fc1,fc2);
if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_SHORT)
if ((frame_ctrl & IEEE802154_FRAMECTRL_DADDR)== IEEE802154_ADDRMODE_SHORT)
{
hlen += 2 + 2; /* Destination PAN + shortaddr */
}
else if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_EXT)
else if ((frame_ctrl & IEEE802154_FRAMECTRL_DADDR) == IEEE802154_ADDRMODE_EXTENDED)
{
hlen += 2 + 8; /* Destination PAN + extaddr */
}
if ((fc2 & IEEE802154_FC2_SADDR) == IEEE802154_SADDR_SHORT)
if (!(frame_ctrl & IEEE802154_FRAMECTRL_INTRA))
{
if ((fc1 & IEEE802154_FC1_INTRA) != IEEE802154_INTRA)
{
hlen += 2; /* No PAN compression, source PAN is different from dest PAN */
}
hlen += 2; /* No PAN compression, source PAN is different from dest PAN */
}
if ((frame_ctrl & IEEE802154_FRAMECTRL_SADDR)== IEEE802154_ADDRMODE_SHORT)
{
hlen += 2; /* Source saddr */
}
else if ((fc2 & IEEE802154_FC2_SADDR) == IEEE802154_SADDR_EXT)
else if ((frame_ctrl & IEEE802154_FRAMECTRL_SADDR) == IEEE802154_ADDRMODE_EXTENDED)
{
if ((fc1 & IEEE802154_FC1_INTRA) != IEEE802154_INTRA)
{
hlen += 2; /* No PAN compression, source PAN is different from dest PAN */
}
hlen += 8; /* Ext saddr */
}
//wlinfo("hlen %d\n",hlen);
/* Header len, 0, TODO for security modes */
mrf24j40_setreg(dev->spi, addr++, hlen);
@@ -1180,7 +1134,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee,
*/
reg = MRF24J40_TXNCON_TXNTRIG;
if (fc1 & IEEE802154_FC1_ACKREQ)
if (frame_ctrl & IEEE802154_FRAMECTRL_ACKREQ)
{
reg |= MRF24J40_TXNCON_TXNACKREQ;
}
+3 -3
View File
@@ -87,7 +87,7 @@
#define _GPIOBASE (0x2200) /* GPIO driver commands */
#define _CLIOCBASE (0x2300) /* Contactless modules ioctl commands */
#define _MAC802154BASE (0x2400) /* 802.15.4 MAC ioctl commands */
#define _RAD802154BASE (0x2500) /* 802.15.4 Radio ioctl commands */
#define _PHY802154BASE (0x2500) /* 802.15.4 Radio ioctl commands */
/* boardctl() commands share the same number space */
@@ -412,8 +412,8 @@
/* 802.15.4 Radio driver ioctl definitions *******************************************/
/* (see nuttx/ieee802154/wireless/ieee802154_radio.h */
#define _RAD802154IOCVALID(c) (_IOC_TYPE(c)==_RADIO802154BASE)
#define _RAD802154IOC(nr) _IOC(_RADIO802154BASE,nr)
#define _PHY802154IOCVALID(c) (_IOC_TYPE(c)==_PHY802154BASE)
#define _PHY802154IOC(nr) _IOC(_PHY802154BASE,nr)
/* boardctl() command definitions *******************************************/
+60 -11
View File
@@ -1,11 +1,10 @@
/****************************************************************************
* include/nuttx/net/ieee802154.h
* include/nuttx/wireless/ieee802154/ieee802154.h
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Includes some definitions that a compatible with the LGPL GNU C Library
* header file of the same name.
* Copyright (C) 2014-2016 Sebastien Lorquet. All rights reserved.
* Copyright (C) 2017 Verge Inc. All rights reserved.
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
* Author: Anthony Merlino <anthony@vergeaero.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -44,19 +43,69 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/net/netconfig.h>
#include <stdint.h>
#include <stdbool.h>
/****************************************************************************
* Public Type Definitions
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Public Data
* Public Types
****************************************************************************/
struct ieee802154_packet_s
{
uint8_t len;
uint8_t data[127];
uint8_t lqi;
uint8_t rssi;
};
/* IEEE 802.15.4 Device address
* The addresses in ieee802154 have several formats:
* No address : [none]
* Short address + PAN id : PPPP/SSSS
* Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL
*/
enum ieee802154_addr_mode_e {
IEEE802154_ADDRMODE_NONE = 0,
IEEE802154_ADDRMODE_SHORT = 2,
IEEE802154_ADDRMODE_EXTENDED
};
struct ieee802154_addr_s
{
enum ieee802154_addr_mode_e ia_mode; /* Address mode. Short or Extended */
uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */
union
{
uint16_t _ia_saddr; /* short address */
uint8_t _ia_eaddr[8]; /* extended address */
} ia_addr;
#define ia_saddr ia_addr._ia_saddr
#define ia_eaddr ia_addr._ia_eaddr
};
#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H */
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H*/
File diff suppressed because it is too large Load Diff
@@ -2,7 +2,9 @@
* include/nuttx/wireless/ieee802154/ieee802154_radio.h
*
* Copyright (C) 2014-2016 Sebastien Lorquet. All rights reserved.
* Copyright (C) 2017 Verge Inc. All rights reserved.
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
* Author: Anthony Merlino <anthony@vergeaero.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -44,6 +46,8 @@
#include <stdint.h>
#include <stdbool.h>
#include <semaphore.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/wireless/ieee802154/ieee802154.h>
/****************************************************************************
* Pre-Processor Definitions
@@ -62,18 +66,38 @@
#define IEEE802154_MODE_COORD 0x01 /* avail in mrf24j40, but why? */
#define IEEE802154_MODE_PANCOORD 0x02
/* IEEE 802.15.4 Radio Character Driver IOCTL ********************************/
#define PHY802154IOC_SET_CHAN _PHY802154IOC(0x0001)
#define PHY802154IOC_GET_CHAN _PHY802154IOC(0x0002)
#define PHY802154IOC_SET_PANID _PHY802154IOC(0x0003)
#define PHY802154IOC_GET_PANID _PHY802154IOC(0x0004)
#define PHY802154IOC_SET_SADDR _PHY802154IOC(0x0005)
#define PHY802154IOC_GET_SADDR _PHY802154IOC(0x0006)
#define PHY802154IOC_SET_EADDR _PHY802154IOC(0x0007)
#define PHY802154IOC_GET_EADDR _PHY802154IOC(0x0008)
#define PHY802154IOC_SET_PROMISC _PHY802154IOC(0x0009)
#define PHY802154IOC_GET_PROMISC _PHY802154IOC(0x000A)
#define PHY802154IOC_SET_DEVMODE _PHY802154IOC(0x000B)
#define PHY802154IOC_GET_DEVMODE _PHY802154IOC(0x000C)
#define PHY802154IOC_SET_TXPWR _PHY802154IOC(0x000D)
#define PHY802154IOC_GET_TXPWR _PHY802154IOC(0x000E)
#define PHY802154IOC_SET_CCA _PHY802154IOC(0x000F)
#define PHY802154IOC_GET_CCA _PHY802154IOC(0x0010)
#define PHY802154IOC_ENERGYDETECT _PHY802154IOC(0x0011)
/****************************************************************************
* Public Types
****************************************************************************/
struct ieee802154_packet_s
{
uint8_t len;
uint8_t data[127];
uint8_t lqi;
uint8_t rssi;
};
struct ieee802154_cca_s
{
uint8_t use_ed : 1; /* CCA using ED */
+3 -3
View File
@@ -10,12 +10,12 @@ config WIRELESS_IEEE802154
---help---
Enables support for the IEEE 802.14.5 Wireless library.
if IEEE802154
if WIRELESS_IEEE802154
config IEEE802154_MAC
bool "Generic Media Access Control layer for 802.15.4 radios"
default n
depends on IEEE802154
depends on WIRELESS_IEEE802154
---help---
Enables a Media Access Controller for any IEEE802.15.4 radio
device. This in turn can be used by higher layer entities
@@ -25,7 +25,7 @@ config IEEE802154_MAC
config IEEE802154_DEV
bool "Debug character driver for ieee802.15.4 radio interfaces"
default n
depends on IEEE802154
depends on WIRELESS_IEEE802154
---help---
Enables a device driver to expose ieee802.15.4 radio controls
to user space as IOCTLs.
+1 -1
View File
@@ -45,7 +45,7 @@ CSRCS += ieee802154/mac802154.c
endif
ifeq ($(CONFIG_IEEE802154_DEV),y)
CSRCS += ieee802154/ieee802154_device.c
CSRCS += ieee802154/radio802154_device.c
endif
DEPPATH += --dep-path wireless/ieee802154
+1 -19
View File
@@ -48,24 +48,6 @@
* Pre-processor Definitions
****************************************************************************/
/* Frame Type */
#define IEEE802154_FRAME_BEACON 0x00
#define IEEE802154_FRAME_DATA 0x01
#define IEEE802154_FRAME_ACK 0x02
#define IEEE802154_FRAME_COMMAND 0x03
/* MAC commands */
#define IEEE802154_CMD_ASSOC_REQ 0x01
#define IEEE802154_CMD_ASSOC_RSP 0x02
#define IEEE802154_CMD_DIS_NOT 0x03
#define IEEE802154_CMD_DATA_REQ 0x04
#define IEEE802154_CMD_PANID_CONF_NOT 0x05
#define IEEE802154_CMD_ORPHAN_NOT 0x06
#define IEEE802154_CMD_BEACON_REQ 0x07
#define IEEE802154_CMD_COORD_REALIGN 0x08
#define IEEE802154_CMD_GTS_REQ 0x09
/****************************************************************************
* Private Types
@@ -97,7 +79,7 @@ struct ieee802154_privmac_s
uint32_t macPad : 3;
/* 0x48 */ uint32_t macBeaconTxTime : 24;
/* 0x45 */ uint8_t macBeaconPayload[MAC802154_aMaxBeaconPayloadLength];
/* 0x45 */ uint8_t macBeaconPayload[IEEE802154_aMaxBeaconPayloadLength];
/* 0x46 */ uint8_t macBeaconPayloadLength;
/* 0x49 */ uint8_t macBSN;
/* 0x4A */ uint8_t macCoordExtendedAddress[8];
+18 -19
View File
@@ -51,7 +51,6 @@
#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
#include <nuttx/ieee802154/ieee802154_dev.h>
/****************************************************************************
* Private Types
@@ -383,78 +382,78 @@ static int radio802154dev_ioctl(FAR struct file *filep, int cmd,
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
inode = filep->f_inode;
dev = inode->i_private;
DEBUGASSERT(dev != NULL && dev->child != NULL;
DEBUGASSERT(dev != NULL && dev->child != NULL);
child = dev->child;
/* Get exclusive access to the driver data structures */
switch (cmd)
{
case MAC854IOCSCHAN:
case PHY802154IOC_SET_CHAN:
ret = child->ops->setchannel(child, (uint8_t)arg);
break;
case MAC854IOCGCHAN:
case PHY802154IOC_GET_CHAN:
ret = child->ops->getchannel(child, (FAR uint8_t*)arg);
break;
case MAC854IOCSPANID:
case PHY802154IOC_SET_PANID:
ret = child->ops->setpanid(child, (uint16_t)arg);
break;
case MAC854IOCGPANID:
case PHY802154IOC_GET_PANID:
ret = child->ops->getpanid(child, (FAR uint16_t*)arg);
break;
case MAC854IOCSSADDR:
case PHY802154IOC_SET_SADDR:
ret = child->ops->setsaddr(child, (uint16_t)arg);
break;
case MAC854IOCGSADDR:
case PHY802154IOC_GET_SADDR:
ret = child->ops->getsaddr(child, (FAR uint16_t*)arg);
break;
case MAC854IOCSEADDR:
case PHY802154IOC_SET_EADDR:
ret = child->ops->seteaddr(child, (FAR uint8_t*)arg);
break;
case MAC854IOCGEADDR:
case PHY802154IOC_GET_EADDR:
ret = child->ops->geteaddr(child, (FAR uint8_t*)arg);
break;
case MAC854IOCSPROMISC:
case PHY802154IOC_SET_PROMISC:
ret = child->ops->setpromisc(child, (bool)arg);
break;
case MAC854IOCGPROMISC:
case PHY802154IOC_GET_PROMISC:
ret = child->ops->getpromisc(child, (FAR bool*)arg);
break;
case MAC854IOCSDEVMODE:
case PHY802154IOC_SET_DEVMODE:
ret = child->ops->setdevmode(child, (uint8_t)arg);
break;
case MAC854IOCGDEVMODE:
case PHY802154IOC_GET_DEVMODE:
ret = child->ops->getdevmode(child, (FAR uint8_t*)arg);
break;
case MAC854IOCSTXP:
case PHY802154IOC_SET_TXPWR:
ret = child->ops->settxpower(child, (int32_t)arg);
break;
case MAC854IOCGTXP:
case PHY802154IOC_GET_TXPWR:
ret = child->ops->gettxpower(child, (FAR int32_t*)arg);
break;
case MAC854IOCSCCA:
case PHY802154IOC_SET_CCA:
ret = child->ops->setcca(child, (FAR struct ieee802154_cca_s*)arg);
break;
case MAC854IOCGCCA:
case PHY802154IOC_GET_CCA:
ret = child->ops->getcca(child, (FAR struct ieee802154_cca_s*)arg);
break;
case MAC854IOCGED:
case PHY802154IOC_ENERGYDETECT:
ret = child->ops->energydetect(child, (FAR uint8_t*)arg);
break;