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
commit 5c357702aa
11 changed files with 510 additions and 237 deletions

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__ */

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);

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 ((fc1 & IEEE802154_FC1_INTRA) != IEEE802154_INTRA)
if (!(frame_ctrl & IEEE802154_FRAMECTRL_INTRA))
{
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;
}

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 *******************************************/

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
****************************************************************************/
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H*/

View File

@ -41,9 +41,13 @@
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/wireless/ieee802154/ieee802154.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
@ -51,8 +55,63 @@
/* Configuration ************************************************************/
/* None at the moment */
/* IEEE 802.15.4 MAC Character Driver IOCTL Commands ************************/
/* The IEEE 802.15.4 standard specifies a MLME Service Access Point (SAP)
* including a series of primitives that are used as an interface between
* the MLME and the next highest layer. There are 4 types of primitives:
* - Request
* - Indication
* - Response
* - Confirm
*
* Of these, Request and Response primitives are sent from the next highest layer
* to the MLME. Indication and Confirm primitives are used to notify the next
* highest layer of changes or actions that have taken place.
*
* The MAC802154 character driver exposed here provides IOCTL hooks for all
* Request and Response primitives.
*/
#define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0001)
#define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0002)
#define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0003)
#define MAC802154IOC_MLME_GET_REQUEST _MAC802154IOC(0x0004)
#define MAC802154IOC_MLME_GTS_REQUEST _MAC802154IOC(0x0005)
#define MAC802154IOC_MLME_ORPHAN_RESPONSE _MAC802154IOC(0x0006)
#define MAC802154IOC_MLME_RESET_REQUEST _MAC802154IOC(0x0007)
#define MAC802154IOC_MLME_RXENABLE_REQUEST _MAC802154IOC(0x0008)
#define MAC802154IOC_MLME_SCAN_REQUEST _MAC802154IOC(0x0009)
#define MAC802154IOC_MLME_SET_REQUEST _MAC802154IOC(0x000A)
#define MAC802154IOC_MLME_START_REQUEST _MAC802154IOC(0x000B)
#define MAC802154IOC_MLME_SYNC_REQUEST _MAC802154IOC(0x000C)
#define MAC802154IOC_MLME_POLL_REQUEST _MAC802154IOC(0x000D)
#define MAC802154IOC_MLME_DPS_REQUEST _MAC802154IOC(0x000E)
#define MAC802154IOC_MLME_SOUNDING_REQUEST _MAC802154IOC(0x000F)
#define MAC802154IOC_MLME_CALIBRATE_REQUEST _MAC802154IOC(0x0010)
/* IEEE 802.15.4 MAC Interface **********************************************/
/* 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_DISASSOC_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
/* Some addresses */
#define IEEE802154_PAN_UNSPEC (uint16_t)0xFFFF
@ -60,31 +119,53 @@
#define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE
#define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff"
/* Frame control field masks, 2 bytes
* Seee IEEE 802.15.4/2011 5.2.1.1 page 57
*/
#define IEEE802154_FRAMECTRL_FTYPE 0x0007 /* Frame type, bits 0-2 */
#define IEEE802154_FRAMECTRL_SEC 0x0008 /* Security Enabled, bit 3 */
#define IEEE802154_FRAMECTRL_PEND 0x0010 /* Frame pending, bit 4 */
#define IEEE802154_FRAMECTRL_ACKREQ 0x0020 /* Acknowledge request, bit 5 */
#define IEEE802154_FRAMECTRL_INTRA 0x0040 /* Intra PAN, bit 6 */
#define IEEE802154_FRAMECTRL_DADDR 0x0C00 /* Dest addressing mode, bits 10-11 */
#define IEEE802154_FRAMECTRL_VERSION 0x3000 /* Source addressing mode, bits 12-13 */
#define IEEE802154_FRAMECTRL_SADDR 0xC000 /* Source addressing mode, bits 14-15 */
#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */
#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */
#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */
#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */
#define IEEE802154_FRAMECTRL_SHIFT_INTRA 6 /* Intra PAN, bit 6 */
#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */
#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */
#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */
/* IEEE 802.15.4 PHY constants */
#define MAC802154_aMaxPHYPacketSize 127
#define MAC802154_aTurnaroundTime 12 /*symbol periods*/
#define IEEE802154_aMaxPHYPacketSize 127
#define IEEE802154_aTurnaroundTime 12 /*symbol periods*/
/* IEEE 802.15.4 MAC constants */
#define MAC802154_aBaseSlotDuration 60
#define MAC802154_aNumSuperframeSlots 16
#define MAC802154_aBaseSuperframeDuration (MAC802154_aBaseSlotDuration * MAC802154_aNumSuperframeSlots)
#define MAC802154_aMaxBE 5
#define MAC802154_aMaxBeaconOverhead 75
#define MAC802154_aMaxBeaconPayloadLength (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxBeaconOverhead)
#define MAC802154_aGTSDescPersistenceTime 4
#define MAC802154_aMaxFrameOverhead 25
#define MAC802154_aMaxFrameResponseTime 1220
#define MAC802154_aMaxFrameRetries 3
#define MAC802154_aMaxLostBeacons 4
#define MAC802154_aMaxMACFrameSize (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxFrameOverhead)
#define MAC802154_aMaxSIFSFrameSize 18
#define MAC802154_aMinCAPLength 440
#define MAC802154_aMinLIFSPeriod 40
#define MAC802154_aMinSIFSPeriod 12
#define MAC802154_aResponseWaitTime (32 * MAC802154_aBaseSuperframeDuration)
#define MAC802154_aUnitBackoffPeriod 20
#define IEEE802154_aBaseSlotDuration 60
#define IEEE802154_aNumSuperframeSlots 16
#define IEEE802154_aBaseSuperframeDuration (IEEE802154_aBaseSlotDuration * IEEE802154_aNumSuperframeSlots)
#define IEEE802154_aMaxBE 5
#define IEEE802154_aMaxBeaconOverhead 75
#define IEEE802154_aMaxBeaconPayloadLength (IEEE802154_aMaxPHYPacketSize - IEEE802154_aMaxBeaconOverhead)
#define IEEE802154_aGTSDescPersistenceTime 4
#define IEEE802154_aMaxFrameOverhead 25
#define IEEE802154_aMaxFrameResponseTime 1220
#define IEEE802154_aMaxFrameRetries 3
#define IEEE802154_aMaxLostBeacons 4
#define IEEE802154_aMaxMACFrameSize (IEEE802154_aMaxPHYPacketSize - IEEE802154_aMaxFrameOverhead)
#define IEEE802154_aMaxSIFSFrameSize 18
#define IEEE802154_aMinCAPLength 440
#define IEEE802154_aMinLIFSPeriod 40
#define IEEE802154_aMinSIFSPeriod 12
#define IEEE802154_aResponseWaitTime (32 * IEEE802154_aBaseSuperframeDuration)
#define IEEE802154_aUnitBackoffPeriod 20
/****************************************************************************
* Public Types
@ -92,97 +173,279 @@
/* IEEE 802.15.4 MAC status codes */
enum
enum ieee802154_status_e
{
MAC802154_STATUS_OK = 0,
MAC802154_STATUS_BEACON_LOSS = 0xE0,
MAC802154_STATUS_CHANNEL_ACCESS_FAILURE,
MAC802154_STATUS_DENIED,
MAC802154_STATUS_DISABLE_TRX_FAILURE,
MAC802154_STATUS_FAILED_SECURITY_CHECK,
MAC802154_STATUS_FRAME_TOO_LONG,
MAC802154_STATUS_INVALID_GTS,
MAC802154_STATUS_INVALID_HANDLE,
MAC802154_STATUS_INVALID_PARAMETER,
MAC802154_STATUS_NO_ACK,
MAC802154_STATUS_NO_BEACON,
MAC802154_STATUS_NO_DATA,
MAC802154_STATUS_NO_SHORT_ADDRESS,
MAC802154_STATUS_OUT_OF_CAP,
MAC802154_STATUS_PAN_ID_CONFLICT,
MAC802154_STATUS_REALIGNMENT,
MAC802154_STATUS_TRANSACTION_EXPIRED,
MAC802154_STATUS_TRANSACTION_OVERFLOW,
MAC802154_STATUS_TX_ACTIVE,
MAC802154_STATUS_UNAVAILABLE_KEY,
MAC802154_STATUS_UNSUPPORTED_ATTRIBUTE
IEEE802154_STATUS_OK = 0,
IEEE802154_STATUS_BEACON_LOSS = 0xE0,
IEEE802154_STATUS_CHANNEL_ACCESS_FAILURE,
IEEE802154_STATUS_DENIED,
IEEE802154_STATUS_DISABLE_TRX_FAILURE,
IEEE802154_STATUS_FAILED_SECURITY_CHECK,
IEEE802154_STATUS_FRAME_TOO_LONG,
IEEE802154_STATUS_INVALID_GTS,
IEEE802154_STATUS_INVALID_HANDLE,
IEEE802154_STATUS_INVALID_PARAMETER,
IEEE802154_STATUS_NO_ACK,
IEEE802154_STATUS_NO_BEACON,
IEEE802154_STATUS_NO_DATA,
IEEE802154_STATUS_NO_SHORT_ADDRESS,
IEEE802154_STATUS_OUT_OF_CAP,
IEEE802154_STATUS_PAN_ID_CONFLICT,
IEEE802154_STATUS_REALIGNMENT,
IEEE802154_STATUS_TRANSACTION_EXPIRED,
IEEE802154_STATUS_TRANSACTION_OVERFLOW,
IEEE802154_STATUS_TX_ACTIVE,
IEEE802154_STATUS_UNAVAILABLE_KEY,
IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE
};
/* IEEE 802.15.4 PHY/MAC PIB attributes IDs */
enum
{
MAC802154_phyCurrentChannel = 0x00,
MAC802154_phyChannelsSupported,
MAC802154_phyTransmitPower,
MAC802154_phyCCAMode,
MAC802154_macAckWaitDuration = 0x40,
MAC802154_macAssociationPermit,
MAC802154_macAutoRequest,
MAC802154_macBattLifeExt,
MAC802154_macBattLifeExtPeriods,
MAC802154_macBeaconPayload,
MAC802154_macBeaconPayloadLength,
MAC802154_macBeaconOrder,
MAC802154_macBeaconTxTime,
MAC802154_macBSN,
MAC802154_macCoordExtendedAddress,
MAC802154_macCoordShortAddress,
MAC802154_macDSN,
MAC802154_macGTSPermit,
MAC802154_macMaxCSMABackoffs,
MAC802154_macMinBE,
MAC802154_macPANId,
MAC802154_macPromiscuousMode,
MAC802154_macRxOnWhenIdle,
MAC802154_macShortAddress,
MAC802154_macSuperframeOrder,
MAC802154_macTransactionPersistenceTime,
MAC802154_macACLEntryDescriptorSet = 0x70,
MAC802154_macACLEntryDescriptorSetSize,
MAC802154_macDefaultSecurity,
MAC802154_macDefaultSecurityMaterialLength,
MAC802154_macDefaultSecurityMaterial,
MAC802154_macDefaultSecuritySuite,
MAC802154_macSecurityMode
IEEE802154_phyCurrentChannel = 0x00,
IEEE802154_phyChannelsSupported,
IEEE802154_phyTransmitPower,
IEEE802154_phyCCAMode,
IEEE802154_macAckWaitDuration = 0x40,
IEEE802154_macAssociationPermit,
IEEE802154_macAutoRequest,
IEEE802154_macBattLifeExt,
IEEE802154_macBattLifeExtPeriods,
IEEE802154_macBeaconPayload,
IEEE802154_macBeaconPayloadLength,
IEEE802154_macBeaconOrder,
IEEE802154_macBeaconTxTime,
IEEE802154_macBSN,
IEEE802154_macCoordExtendedAddress,
IEEE802154_macCoordShortAddress,
IEEE802154_macDSN,
IEEE802154_macGTSPermit,
IEEE802154_macMaxCSMABackoffs,
IEEE802154_macMinBE,
IEEE802154_macPANId,
IEEE802154_macPromiscuousMode,
IEEE802154_macRxOnWhenIdle,
IEEE802154_macShortAddress,
IEEE802154_macSuperframeOrder,
IEEE802154_macTransactionPersistenceTime,
IEEE802154_macACLEntryDescriptorSet = 0x70,
IEEE802154_macACLEntryDescriptorSetSize,
IEEE802154_macDefaultSecurity,
IEEE802154_macDefaultSecurityMaterialLength,
IEEE802154_macDefaultSecurityMaterial,
IEEE802154_macDefaultSecuritySuite,
IEEE802154_macSecurityMode
};
/****************************************************************************
* Public Types
****************************************************************************/
/* 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
*/
struct ieee802154_addr_s
struct ieee802154_capability_info_s
{
uint8_t ia_len; /* structure length, 0/2/8 */
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
uint8_t reserved_0 : 1; /* Reserved */
uint8_t device_type : 1; /* 0=RFD, 1=FFD */
uint8_t power_source : 1; /* 1=AC, 0=Other */
uint8_t rx_on_idle : 1; /* 0=Receiver off when idle
* 1=Receiver on when idle */
uint8_t reserved_45 : 2; /* Reserved */
uint8_t security : 1; /* 0=disabled, 1=enabled */
uint8_t allocate_addr : 1; /* 1=Coordinator allocates short address
* 0=otherwise */
};
#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */
#ifdef CONFIG_IEEE802154_SECURITY
struct ieee802154_security_s
{
uint8_t level; /* Security level to be used */
uint8_t key_id_mode; /* Mode used to identify the key to be used */
uint8_t key_source[8]; /* Originator of the key to be used */
uint8_t key_index; /* Index of the key to be used */
};
#endif
struct ieee802154_superframe_spec_s
{
uint16_t beacon_order : 4; /* Transmission interval of beacon */
uint16_t superframe_order : 4; /* Length of superframe */
uint16_t final_cap_slot : 4; /* Last slot utilized by CAP */
uint16_t ble : 1; /* Battery Life Extension (BLE) */
uint16_t reserved : 1; /* Reserved bit */
uint16_t pan_coordinator : 1; /* 1 if beacon sent by pan coordinator */
uint16_t assoc_permit : 1; /* 1 if coordinator is accepting associaton */
};
struct ieee802154_pan_desc_s
{
/* The coordinator address of the received beacon frame */
struct ieee802154_addr_s coord_addr;
uint8_t channel; /* current channel occupied by the network */
uint8_t channel_page; /* current channel page occupied by the network */
/* The superframe specifications received in the beacon frame */
struct ieee802154_superframe_spec_s superframe_spec;
uint8_t gts_permit; /* 0=No GTS requests allowed
* 1=GTS request allowed */
uint8_t link_quality; /* LQI at which beacon was received */
uint32_t timestamp; /* Time at which the beacon frame was received
* in symbols */
};
struct ieee802154_pend_addr_s
{
union {
uint8_t pa_spec;
struct {
uint8_t num_short_addr : 3; /* Number of short addresses pending */
uint8_t reserved_3 : 1; /* Reserved bit */
uint8_t num_ext_addr : 3; /* Number of extended addresses pending */
uint8_t reserved_7 : 1; /* Reserved bit */
};
};
struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */
};
/* Primitive Semantics */
struct ieee802154_assoc_request_s
{
uint8_t channel; /* Channel number to attempt association */
uint8_t channel_page; /* Channel page to attempt association */
/* Coordinator Address with which to associate */
struct ieee802154_addr_s coord_addr;
/* Capabilities of associating device */
struct ieee802154_capability_info_s capabilities;
#ifdef CONFIG_IEEE802154_SECURITY
/* Security information if enabled */
struct ieee802154_security_s security;
#endif
};
struct ieee802154_assoc_indication_s
{
/* Address of device requesting association. Always in extended mode */
struct ieee802154_addr_s dev_addr;
/* Capabilities of associating device */
struct ieee802154_capability_info_s capabilities;
#ifdef CONFIG_IEEE802154_SECURITY
/* Security information if enabled */
struct ieee802154_security_s security;
#endif
};
struct ieee802154_assoc_response_s
{
/* Address of device requesting association. Always in extended mode */
struct ieee802154_addr_s dev_addr;
/* Status of association attempt */
enum ieee802154_status_e status;
#ifdef CONFIG_IEEE802154_SECURITY
/* Security information if enabled */
struct ieee802154_security_s security;
#endif
};
struct ieee802154_assoc_confirm_s
{
/* Associated device address ALWAYS passed in short address mode. The
* address will be IEEE802154_SADDR_UNSPEC if association was unsuccessful */
struct ieee802154_addr_s dev_addr;
/* Status of association attempt */
enum ieee802154_status_e status;
#ifdef CONFIG_IEEE802154_SECURITY
/* Security information if enabled */
struct ieee802154_security_s security;
#endif
};
struct ieee802154_disassoc_request_s
{
/* Address of device to send disassociation notification */
struct ieee802154_addr_s dev_addr;
/* Reason for the disassosiation */
enum ieee802154_status_e disassoc_reason;
uint8_t tx_indirect; /* 0=Send Direct, 1=Send Indirect */
#ifdef CONFIG_IEEE802154_SECURITY
/* Security information if enabled */
struct ieee802154_security_s security;
#endif
};
struct ieee802154_disassoc_indication_s
{
/* Address of device requesting disassociation. Always extended mode */
struct ieee802154_addr_s dev_addr;
/* Reason for the disassosiation */
enum ieee802154_status_e disassoc_reason;
#ifdef CONFIG_IEEE802154_SECURITY
/* Security information if enabled */
struct ieee802154_security_s security;
#endif
};
struct ieee802154_disassoc_confirm_s
{
/* Status of the disassociation attempt */
enum ieee802154_status_e status;
/* Address of device either requesting or being intructed to disassociate */
struct ieee802154_addr_s dev_addr;
};
struct ieee802154_beaconnotify_indication_s
{
uint8_t bsn; /* Beacon sequence number */
/* PAN descriptor for the received beacon */
struct ieee802154_pan_desc_s pan_desc;
/* Beacon pending addresses */
struct ieee802154_pend_addr_s pend_addr;
uint8_t sdu_length; /* Number of octets contained in the beacon
* payload of the received beacond frame */
/* Beacon payload */
uint8_t sdu[IEEE802154_aMaxBeaconPayloadLength];
};
/* Operations */
@ -203,13 +466,13 @@ struct ieee802154_macops_s
/* Start association with coordinator */
CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac, uint16_t panid,
uint8_t *coordeadr);
CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac,
FAR struct ieee802154_assoc_request_s *request);
/* Start disassociation with coordinator */
CODE int (*req_disassociate)(FAR struct ieee802154_mac_s *mac,
FAR uint8_t *eadr, uint8_t reason);
FAR struct ieee802154_disassoc_request_s *request);
/* Read the PIB */
@ -337,7 +600,7 @@ struct ieee802154_maccb_s
/* Beacon notification */
CODE int (*ind_beaconnotify)(FAR struct ieee802154_mac_s *mac,
FAR uint8_t *bsn, FAR uint_t *pandesc,
FAR uint8_t *bsn, FAR struct ieee802154_pan_desc_s *pandesc,
FAR uint8_t *sdu, int sdulen);
/* GTS management request received */

View File

@ -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 */

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.

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

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];

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;