Merge branch 'ieee802154'

This commit is contained in:
Gregory Nutt 2017-05-19 15:51:31 -06:00
commit 36d5f5085c
8 changed files with 1061 additions and 705 deletions

View File

@ -107,13 +107,6 @@
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
struct mrf24j40_txdesc_s
{
struct ieee802154_txdesc_s pub;
uint8_t busy : 1; /* Is this txdesc being used */
};
/* A MRF24J40 device instance */ /* A MRF24J40 device instance */
struct mrf24j40_radio_s struct mrf24j40_radio_s
@ -145,11 +138,13 @@ struct mrf24j40_radio_s
/* Buffer Allocations */ /* Buffer Allocations */
struct mrf24j40_txdesc_s csma_desc; struct ieee802154_txdesc_s *csma_desc;
FAR struct iob_s *csma_frame; FAR struct iob_s *csma_frame;
bool csma_busy;
struct mrf24j40_txdesc_s gts_desc[MRF24J40_GTS_SLOTS]; struct ieee802154_txdesc_s *gts_desc[MRF24J40_GTS_SLOTS];
FAR struct iob_s *gts_frame[MRF24J40_GTS_SLOTS]; FAR struct iob_s *gts_frame[MRF24J40_GTS_SLOTS];
bool gts_busy[MRF24J40_GTS_SLOTS];
}; };
/**************************************************************************** /****************************************************************************
@ -189,7 +184,6 @@ static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts,
static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev,
FAR struct iob_s *frame, uint32_t fifo_addr); FAR struct iob_s *frame, uint32_t fifo_addr);
static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *dev,
uint8_t chan); uint8_t chan);
static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev,
@ -206,10 +200,6 @@ static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev,
FAR const uint8_t *eaddr); FAR const uint8_t *eaddr);
static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev,
FAR uint8_t *eaddr); FAR uint8_t *eaddr);
static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *dev,
bool promisc);
static int mrf24j40_getpromisc(FAR struct mrf24j40_radio_s *dev,
FAR bool *promisc);
static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev,
uint8_t mode); uint8_t mode);
static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *dev,
@ -446,17 +436,17 @@ static void mrf24j40_dopoll_csma(FAR void *arg)
/* If this a CSMA transaction and we have room in the CSMA fifo */ /* If this a CSMA transaction and we have room in the CSMA fifo */
if (!dev->csma_desc.busy) if (!dev->csma_busy)
{ {
/* need to somehow allow for a handle to be passed */ /* need to somehow allow for a handle to be passed */
len = dev->radiocb->poll_csma(dev->radiocb, &dev->csma_desc.pub, len = dev->radiocb->poll_csma(dev->radiocb, &dev->csma_desc,
&dev->csma_frame); &dev->csma_frame);
if (len > 0) if (len > 0)
{ {
/* Now the txdesc is in use */ /* Now the txdesc is in use */
dev->csma_desc.busy = 1; dev->csma_busy = 1;
/* Setup the transaction on the device in the CSMA FIFO */ /* Setup the transaction on the device in the CSMA FIFO */
@ -501,15 +491,15 @@ static void mrf24j40_dopoll_gts(FAR void *arg)
for (gts = 0; gts < MRF24J40_GTS_SLOTS; gts++) for (gts = 0; gts < MRF24J40_GTS_SLOTS; gts++)
{ {
if (!dev->gts_desc[gts].busy) if (!dev->gts_busy[gts])
{ {
len = dev->radiocb->poll_gts(dev->radiocb, &dev->gts_desc[gts].pub, len = dev->radiocb->poll_gts(dev->radiocb, &dev->gts_desc[gts],
&dev->gts_frame[0]); &dev->gts_frame[0]);
if (len > 0) if (len > 0)
{ {
/* Now the txdesc is in use */ /* Now the txdesc is in use */
dev->gts_desc[gts].busy = 1; dev->gts_busy[gts]= 1;
/* Setup the transaction on the device in the open GTS FIFO */ /* Setup the transaction on the device in the open GTS FIFO */
@ -1406,15 +1396,15 @@ static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev)
*/ */
txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT);
dev->csma_desc.pub.status = txstat & MRF24J40_TXSTAT_TXNSTAT; dev->csma_desc->conf->status = txstat & MRF24J40_TXSTAT_TXNSTAT;
/* Inform the next layer of the transmission success/failure */ /* Inform the next layer of the transmission success/failure */
dev->radiocb->txdone(dev->radiocb, &dev->csma_desc.pub); dev->radiocb->txdone(dev->radiocb, dev->csma_desc);
/* We are now done with the transaction */ /* We are now done with the transaction */
dev->csma_desc.busy = 0; dev->csma_busy = 0;
/* Free the IOB */ /* Free the IOB */
@ -1451,20 +1441,20 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev,
if (gts == 0) if (gts == 0)
{ {
dev->csma_desc.pub.status = txstat & MRF24J40_TXSTAT_TXG1STAT; dev->csma_desc->conf->status = txstat & MRF24J40_TXSTAT_TXG1STAT;
} }
else if (gts == 1) else if (gts == 1)
{ {
dev->csma_desc.pub.status = txstat & MRF24J40_TXSTAT_TXG2STAT; dev->csma_desc->conf->status = txstat & MRF24J40_TXSTAT_TXG2STAT;
} }
/* Inform the next layer of the transmission success/failure */ /* Inform the next layer of the transmission success/failure */
dev->radiocb->txdone(dev->radiocb, &dev->gts_desc[gts].pub); dev->radiocb->txdone(dev->radiocb, dev->gts_desc[gts]);
/* We are now done with the transaction */ /* We are now done with the transaction */
dev->gts_desc[gts].busy = 0; dev->gts_busy[gts]= 0;
/* Free the IOB */ /* Free the IOB */

View File

@ -62,8 +62,9 @@
/* IEEE 802.15.4 MAC Character Driver IOCTL commands ********************************/ /* IEEE 802.15.4 MAC Character Driver IOCTL commands ********************************/
#define MAC802154IOC_MCPS_REGISTER _WLCIOC(IEEE802154_FIRST) #define MAC802154IOC_NOTIFY_REGISTER _WLCIOC(IEEE802154_FIRST)
#define MAC802154IOC_MLME_REGISTER _WLCIOC(IEEE802154_FIRST+1) #define MAC802154IOC_GET_EVENT _WLCIOC(IEEE802154_FIRST+1)
#define MAC802154IOC_ENABLE_EVENTS _WLCIOC(IEEE802154_FIRST+2)
/************************************************************************************ /************************************************************************************
* Public Types * Public Types

View File

@ -102,31 +102,12 @@
/* IEEE 802.15.4 MAC Interface **********************************************/ /* 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_RESP 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 */ /* Some addresses */
#define IEEE802154_PAN_UNSPEC (uint16_t)0xFFFF #define IEEE802154_PAN_UNSPEC (uint16_t)0xFFFF
#define IEEE802154_SADDR_UNSPEC (uint16_t)0xFFFF #define IEEE802154_SADDR_UNSPEC (uint16_t)0xFFFF
#define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE #define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE
#define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff" #define IEEE802154_EADDR_UNSPEC (uint8_t[]){0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}
/* Frame control field masks, 2 bytes /* Frame control field masks, 2 bytes
* Seee IEEE 802.15.4/2011 5.2.1.1 page 57 * Seee IEEE 802.15.4/2011 5.2.1.1 page 57
@ -150,6 +131,22 @@
#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */ #define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */
#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */ #define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */
/* Capability Information Bitfield
*
*/
#define IEEE802154_CAPABILITY_DEVTYPE 0x02
#define IEEE802154_CAPABILITY_PWRSRC 0x04
#define IEEE802154_CAPABILITY_RXONIDLE 0x08
#define IEEE802154_CAPABILITY_SECURITY 0x40
#define IEEE802154_CAPABILITY_ALLOCADDR 0x80
#define IEEE802154_CAPABILITY_SHIFT_DEVTYPE 1
#define IEEE802154_CAPABILITY_SHIFT_PWRSRC 2
#define IEEE802154_CAPABILITY_SHIFT_RXONIDLE 3
#define IEEE802154_CAPABILITY_SHIFT_SECURITY 6
#define IEEE802154_CAPABILITY_SHIFT_ALLOCADDR 7
/* IEEE 802.15.4 PHY constants */ /* IEEE 802.15.4 PHY constants */
#define IEEE802154_MAX_PHY_PACKET_SIZE 127 #define IEEE802154_MAX_PHY_PACKET_SIZE 127
@ -194,7 +191,6 @@
#define MAX_ORPHAN_ADDR 32 /* REVISIT */ #define MAX_ORPHAN_ADDR 32 /* REVISIT */
// TODO: Add macros
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
@ -329,6 +325,31 @@ enum ieee802154_pib_attr_e
IEEE802154_PIB_MAC_PANCOORD_SHORT_ADDR, IEEE802154_PIB_MAC_PANCOORD_SHORT_ADDR,
}; };
/* Frame Type */
enum ieee802154_frametype_e
{
IEEE802154_FRAME_BEACON = 0,
IEEE802154_FRAME_DATA,
IEEE802154_FRAME_ACK,
IEEE802154_FRAME_COMMAND
};
/* MAC command IDs */
enum ieee802154_cmdid_e
{
IEEE802154_CMD_ASSOC_REQ = 1,
IEEE802154_CMD_ASSOC_RESP,
IEEE802154_CMD_DISASSOC_NOT,
IEEE802154_CMD_DATA_REQ,
IEEE802154_CMD_PANID_CONF_NOT,
IEEE802154_CMD_ORPHAN_NOT,
IEEE802154_CMD_BEACON_REQ,
IEEE802154_CMD_COORD_REALIGN,
IEEE802154_CMD_GTS_REQ,
};
enum ieee802154_devmode_e enum ieee802154_devmode_e
{ {
IEEE802154_DEVMODE_ENDPOINT, IEEE802154_DEVMODE_ENDPOINT,
@ -405,13 +426,13 @@ enum ieee802154_ranging_e
struct ieee802154_capability_info_s struct ieee802154_capability_info_s
{ {
uint8_t reserved_0 : 1; /* Reserved */ uint8_t reserved_0 : 1; /* Reserved */
uint8_t device_type : 1; /* 0=RFD, 1=FFD */ uint8_t devtype : 1; /* 0=RFD, 1=FFD */
uint8_t power_source : 1; /* 1=AC, 0=Other */ uint8_t powersource : 1; /* 1=AC, 0=Other */
uint8_t rx_on_idle : 1; /* 0=Receiver off when idle uint8_t rxonidle : 1; /* 0=Receiver off when idle
* 1=Receiver on when idle */ * 1=Receiver on when idle */
uint8_t reserved_45 : 2; /* Reserved */ uint8_t reserved_45 : 2; /* Reserved */
uint8_t security : 1; /* 0=disabled, 1=enabled */ uint8_t security : 1; /* 0=disabled, 1=enabled */
uint8_t allocate_addr : 1; /* 1=Coordinator allocates short address uint8_t allocaddr : 1; /* 1=Coordinator allocates short address
* 0=otherwise */ * 0=otherwise */
}; };
@ -462,31 +483,6 @@ struct ieee802154_pend_addr_s
struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */ struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */
}; };
#ifdef CONFIG_IEEE802154_RANGING
#define IEEE802154_TXDESC_FIELDS \
uint8_t handle; \
uint32_t timestamp; \
uint8_t status;
#else
#define IEEE802154_TXDESC_FIELDS \
uint8_t handle; \
uint32_t timestamp; \
uint8_t status;
bool rng_rcvd; \
uint32_t rng_counter_start; \
uint32_t rng_counter_stop; \
uint32_t rng_tracking_interval; \
uint32_t rng_offset;\
uint8_t rng_fom;
#endif
struct ieee802154_txdesc_s
{
IEEE802154_TXDESC_FIELDS
/* TODO: Add slotting information for GTS transactions */
};
struct ieee802154_cca_s struct ieee802154_cca_s
{ {
uint8_t use_ed : 1; /* CCA using ED */ uint8_t use_ed : 1; /* CCA using ED */
@ -631,7 +627,44 @@ struct ieee802154_frame_meta_s
struct ieee802154_data_conf_s struct ieee802154_data_conf_s
{ {
IEEE802154_TXDESC_FIELDS uint8_t handle; /* Handle assoc. with MSDU */
/* The time, in symbols, at which the data were transmitted */
uint32_t timestamp;
enum ieee802154_status_e status; /* The status of the MSDU transmission */
#ifdef CONFIG_IEEE802154_RANGING
bool rng_rcvd; /* Ranging indicated by MSDU */
/* A count of the time units corresponding to an RMARKER at the antenna at
* the beginning of the ranging exchange
*/
uint32_t rng_counter_start;
/* A count of the time units corresponding to an RMARKER at the antenna at
* end of the ranging exchange
*/
uint32_t rng_counter_stop;
/* A count of the time units in a message exchange over which the tracking
* offset was measured
*/
uint32_t rng_tracking_interval;
/* A count of the time units slipped or advanced by the radio tracking
* system over the course of the entire tracking interval
*/
uint32_t rng_offset;
/* The Figure of Merit (FoM) characterizing the ranging measurement */
uint8_t rng_fom;
#endif
}; };
/***************************************************************************** /*****************************************************************************
@ -734,12 +767,12 @@ struct ieee802154_purge_req_s
struct ieee802154_assoc_req_s struct ieee802154_assoc_req_s
{ {
uint8_t channel; /* Channel number to attempt association */ uint8_t chnum; /* Channel number to attempt association */
uint8_t channel_page; /* Channel page to attempt association */ uint8_t chpage; /* Channel page to attempt association */
/* Coordinator Address with which to associate */ /* Coordinator Address with which to associate */
struct ieee802154_addr_s coord_addr; struct ieee802154_addr_s coordaddr;
/* Capabilities of associating device */ /* Capabilities of associating device */
@ -1307,8 +1340,42 @@ struct ieee802154_poll_conf_s
enum ieee802154_status_e status; enum ieee802154_status_e status;
}; };
union ieee802154_mlme_notify_u /* MAC Service Notifications */
enum ieee802154_notify_e
{ {
/* MCPS Notifications */
IEEE802154_NOTIFY_CONF_DATA = 0x00,
/* MLME Notifications */
IEEE802154_NOTIFY_CONF_ASSOC,
IEEE802154_NOTIFY_CONF_DISASSOC,
IEEE802154_NOTIFY_CONF_GTS,
IEEE802154_NOTIFY_CONF_RESET,
IEEE802154_NOTIFY_CONF_RXENABLE,
IEEE802154_NOTIFY_CONF_SCAN,
IEEE802154_NOTIFY_CONF_START,
IEEE802154_NOTIFY_CONF_POLL,
IEEE802154_NOTIFY_IND_ASSOC,
IEEE802154_NOTIFY_IND_DISASSOC,
IEEE802154_NOTIFY_IND_BEACONNOTIFY,
IEEE802154_NOTIFY_IND_GTS,
IEEE802154_NOTIFY_IND_ORPHAN,
IEEE802154_NOTIFY_IND_COMMSTATUS,
IEEE802154_NOTIFY_IND_SYNCLOSS
};
union ieee802154_notif_u
{
/* MCPS Notifications */
struct ieee802154_data_conf_s dataconf;
/* MLME Notifications */
struct ieee802154_assoc_conf_s assocconf; struct ieee802154_assoc_conf_s assocconf;
struct ieee802154_disassoc_conf_s disassocconf; struct ieee802154_disassoc_conf_s disassocconf;
struct ieee802154_gts_conf_s gtsconf; struct ieee802154_gts_conf_s gtsconf;
@ -1326,10 +1393,18 @@ union ieee802154_mlme_notify_u
struct ieee802154_syncloss_ind_s synclossind; struct ieee802154_syncloss_ind_s synclossind;
}; };
union ieee802154_mcps_notify_u struct ieee802154_notif_s
{ {
struct ieee802154_data_conf_s dataconf; /* Must be first member so that we can interchange between the actual
struct ieee802154_data_ind_s *dataind; *notification and this extended struct.
*/
union ieee802154_notif_u u;
enum ieee802154_notify_e notiftype;
/* Support a singly linked list */
FAR struct ieee802154_notif_s *flink;
}; };
/* A pointer to this structure is passed as the argument of each IOCTL /* A pointer to this structure is passed as the argument of each IOCTL
@ -1376,51 +1451,6 @@ struct ieee802154_netmac_s
typedef FAR void *MACHANDLE; typedef FAR void *MACHANDLE;
/* MAC Service Notifications */
enum ieee802154_macnotify_e
{
/* MCPS Notifications */
IEEE802154_NOTIFY_CONF_DATA = 0x00,
IEEE802154_NOTIFY_IND_DATA,
/* MLME Notifications */
IEEE802154_NOTIFY_CONF_ASSOC,
IEEE802154_NOTIFY_CONF_DISASSOC,
IEEE802154_NOTIFY_CONF_GTS,
IEEE802154_NOTIFY_CONF_RESET,
IEEE802154_NOTIFY_CONF_RXENABLE,
IEEE802154_NOTIFY_CONF_SCAN,
IEEE802154_NOTIFY_CONF_START,
IEEE802154_NOTIFY_CONF_POLL,
IEEE802154_NOTIFY_IND_ASSOC,
IEEE802154_NOTIFY_IND_DISASSOC,
IEEE802154_NOTIFY_IND_BEACONNOTIFY,
IEEE802154_NOTIFY_IND_GTS,
IEEE802154_NOTIFY_IND_ORPHAN,
IEEE802154_NOTIFY_IND_COMMSTATUS,
IEEE802154_NOTIFY_IND_SYNCLOSS
};
/* Callback operations to notify the next highest layer of various asynchronous
* events, usually triggered by some previous request or response invoked by the
* upper layer.
*/
struct ieee802154_maccb_s
{
CODE void (*mlme_notify)(FAR const struct ieee802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif,
FAR const union ieee802154_mlme_notify_u *arg);
CODE void (*mcps_notify)(FAR const struct ieee802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif,
FAR const union ieee802154_mcps_notify_u *arg);
};
#ifdef __cplusplus #ifdef __cplusplus
#define EXTERN extern "C" #define EXTERN extern "C"
extern "C" extern "C"

View File

@ -58,15 +58,35 @@
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
/* Data only used between radio and MAC layer */
struct ieee802154_txdesc_s
{
/* Support a singly linked list of tx descriptors */
FAR struct ieee802154_txdesc_s *flink;
/* Pointer to the data confirmation structure to be populated upon
* success/failure of the transmission.
*/
FAR struct ieee802154_data_conf_s *conf;
enum ieee802154_frametype_e frametype; /* Frame type. Used by MAC layer to
* control how tx done is handled */
/* TODO: Add slotting information for GTS transactions */
};
/* IEEE802.15.4 Radio Interface Operations **********************************/ /* IEEE802.15.4 Radio Interface Operations **********************************/
struct ieee802154_radiocb_s struct ieee802154_radiocb_s
{ {
CODE int (*poll_csma) (FAR const struct ieee802154_radiocb_s *radiocb, CODE int (*poll_csma) (FAR const struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc, FAR struct ieee802154_txdesc_s **tx_desc,
FAR struct iob_s **frame); FAR struct iob_s **frame);
CODE int (*poll_gts) (FAR const struct ieee802154_radiocb_s *radiocb, CODE int (*poll_gts) (FAR const struct ieee802154_radiocb_s *radiocb,
FAR struct ieee802154_txdesc_s *tx_desc, FAR struct ieee802154_txdesc_s **tx_desc,
FAR struct iob_s **frame); FAR struct iob_s **frame);
CODE void (*txdone) (FAR const struct ieee802154_radiocb_s *radiocb, CODE void (*txdone) (FAR const struct ieee802154_radiocb_s *radiocb,
FAR const struct ieee802154_txdesc_s *tx_desc); FAR const struct ieee802154_txdesc_s *tx_desc);

File diff suppressed because it is too large Load Diff

View File

@ -54,6 +54,26 @@
#include <nuttx/wireless/ieee802154/ieee802154_mac.h> #include <nuttx/wireless/ieee802154/ieee802154_mac.h>
/****************************************************************************
* Public Data Types
****************************************************************************/
/* Callback operations to notify the next highest layer of various asynchronous
* events, usually triggered by some previous request or response invoked by the
* upper layer.
*/
struct mac802154_maccb_s
{
CODE void (*notify)(FAR const struct mac802154_maccb_s *maccb,
FAR struct ieee802154_notif_s *notif);
CODE void (*rxframe)(FAR const struct mac802154_maccb_s *maccb,
FAR struct ieee802154_data_ind_s *ind);
};
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
@ -75,7 +95,7 @@ struct iob_s; /* Forward reference */
* *
****************************************************************************/ ****************************************************************************/
int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb); int mac802154_bind(MACHANDLE mac, FAR const struct mac802154_maccb_s *cb);
/**************************************************************************** /****************************************************************************
* Name: mac802154_ioctl * Name: mac802154_ioctl
@ -117,7 +137,7 @@ int mac802154_get_mhrlen(MACHANDLE mac,
* The MCPS-DATA.request primitive requests the transfer of a data SPDU * The MCPS-DATA.request primitive requests the transfer of a data SPDU
* (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity.
* Confirmation is returned via the * Confirmation is returned via the
* struct ieee802154_maccb_s->conf_data callback. * struct mac802154_maccb_s->conf_data callback.
* *
****************************************************************************/ ****************************************************************************/
@ -131,7 +151,7 @@ int mac802154_req_data(MACHANDLE mac,
* Description: * Description:
* The MCPS-PURGE.request primitive allows the next higher layer to purge * The MCPS-PURGE.request primitive allows the next higher layer to purge
* an MSDU from the transaction queue. Confirmation is returned via * an MSDU from the transaction queue. Confirmation is returned via
* the struct ieee802154_maccb_s->conf_purge callback. * the struct mac802154_maccb_s->conf_purge callback.
* *
* NOTE: The standard specifies that confirmation should be indicated via * NOTE: The standard specifies that confirmation should be indicated via
* the asynchronous MLME-PURGE.confirm primitve. However, in our * the asynchronous MLME-PURGE.confirm primitve. However, in our
@ -149,7 +169,7 @@ int mac802154_req_purge(MACHANDLE mac, uint8_t msdu_handle);
* Description: * Description:
* The MLME-ASSOCIATE.request primitive allows a device to request an * The MLME-ASSOCIATE.request primitive allows a device to request an
* association with a coordinator. Confirmation is returned via the * association with a coordinator. Confirmation is returned via the
* struct ieee802154_maccb_s->conf_associate callback. * struct mac802154_maccb_s->conf_associate callback.
* *
****************************************************************************/ ****************************************************************************/
@ -166,7 +186,7 @@ int mac802154_req_associate(MACHANDLE mac,
* PAN. * PAN.
* *
* Confirmation is returned via the * Confirmation is returned via the
* struct ieee802154_maccb_s->conf_disassociate callback. * struct mac802154_maccb_s->conf_disassociate callback.
* *
****************************************************************************/ ****************************************************************************/
@ -180,7 +200,7 @@ int mac802154_req_disassociate(MACHANDLE mac,
* The MLME-GTS.request primitive allows a device to send a request to the * The MLME-GTS.request primitive allows a device to send a request to the
* PAN coordinator to allocate a new GTS or to deallocate an existing GTS. * PAN coordinator to allocate a new GTS or to deallocate an existing GTS.
* Confirmation is returned via the * Confirmation is returned via the
* struct ieee802154_maccb_s->conf_gts callback. * struct mac802154_maccb_s->conf_gts callback.
* *
****************************************************************************/ ****************************************************************************/
@ -214,7 +234,7 @@ int mac802154_req_reset(MACHANDLE mac, bool rst_pibattr);
* The MLME-RX-ENABLE.request primitive allows the next higher layer to * The MLME-RX-ENABLE.request primitive allows the next higher layer to
* request that the receiver is enable for a finite period of time. * request that the receiver is enable for a finite period of time.
* Confirmation is returned via the * Confirmation is returned via the
* struct ieee802154_maccb_s->conf_rxenable callback. * struct mac802154_maccb_s->conf_rxenable callback.
* *
****************************************************************************/ ****************************************************************************/
@ -230,7 +250,7 @@ int mac802154_req_rxenable(MACHANDLE mac,
* the energy on the channel, search for the coordinator with which it * the energy on the channel, search for the coordinator with which it
* associated, or search for all coordinators transmitting beacon frames * associated, or search for all coordinators transmitting beacon frames
* within the POS of the scanning device. Scan results are returned * within the POS of the scanning device. Scan results are returned
* via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan * via MULTIPLE calls to the struct mac802154_maccb_s->conf_scan
* callback. This is a difference with the official 802.15.4 * callback. This is a difference with the official 802.15.4
* specification, implemented here to save memory. * specification, implemented here to save memory.
* *
@ -280,7 +300,7 @@ int mac802154_req_set(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr,
* Description: * Description:
* The MLME-START.request primitive makes a request for the device to * The MLME-START.request primitive makes a request for the device to
* start using a new superframe configuration. Confirmation is returned * start using a new superframe configuration. Confirmation is returned
* via the struct ieee802154_maccb_s->conf_start callback. * via the struct mac802154_maccb_s->conf_start callback.
* *
****************************************************************************/ ****************************************************************************/
@ -293,7 +313,7 @@ int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req);
* The MLME-SYNC.request primitive requests to synchronize with the * The MLME-SYNC.request primitive requests to synchronize with the
* coordinator by acquiring and, if specified, tracking its beacons. * coordinator by acquiring and, if specified, tracking its beacons.
* Confirmation is returned via the * Confirmation is returned via the
* struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. * struct mac802154_maccb_s->int_commstatus callback. TOCHECK.
* *
****************************************************************************/ ****************************************************************************/
@ -305,8 +325,8 @@ int mac802154_req_sync(MACHANDLE mac, FAR struct ieee802154_sync_req_s *req);
* Description: * Description:
* The MLME-POLL.request primitive prompts the device to request data from * The MLME-POLL.request primitive prompts the device to request data from
* the coordinator. Confirmation is returned via the * the coordinator. Confirmation is returned via the
* struct ieee802154_maccb_s->conf_poll callback, followed by a * struct mac802154_maccb_s->conf_poll callback, followed by a
* struct ieee802154_maccb_s->ind_data callback. * struct mac802154_maccb_s->ind_data callback.
* *
****************************************************************************/ ****************************************************************************/
@ -336,6 +356,18 @@ int mac802154_resp_associate(MACHANDLE mac,
int mac802154_resp_orphan(MACHANDLE mac, int mac802154_resp_orphan(MACHANDLE mac,
FAR struct ieee802154_orphan_resp_s *resp); FAR struct ieee802154_orphan_resp_s *resp);
/****************************************************************************
* Name: mac802154_notif_free
*
* Description:
* When the MAC calls the registered callback, it passes a reference
* to a mac802154_notify_s structure. This structure needs to be freed
* after the callback handler is done using it.
*
****************************************************************************/
int mac802154_notif_free(MACHANDLE mac,
FAR struct ieee802154_notif_s *notif);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -83,22 +83,11 @@ struct mac802154dev_open_s
volatile bool md_closing; volatile bool md_closing;
}; };
struct mac802154dev_dwait_s
{
uint8_t mw_handle; /* The msdu handle identifying the frame */
sem_t mw_sem; /* The semaphore used to signal the completion */
int mw_status; /* The success/error of the transaction */
/* Supports a singly linked list */
FAR struct mac802154dev_dwait_s *mw_flink;
};
struct mac802154dev_callback_s struct mac802154dev_callback_s
{ {
/* This holds the information visible to the MAC layer */ /* This holds the information visible to the MAC layer */
struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */ struct mac802154_maccb_s mc_cb; /* Interface understood by the MAC layer */
FAR struct mac802154_chardevice_s *mc_priv; /* Our priv data */ FAR struct mac802154_chardevice_s *mc_priv; /* Our priv data */
}; };
@ -108,31 +97,33 @@ struct mac802154_chardevice_s
struct mac802154dev_callback_s md_cb; /* Callback information */ struct mac802154dev_callback_s md_cb; /* Callback information */
sem_t md_exclsem; /* Exclusive device access */ sem_t md_exclsem; /* Exclusive device access */
bool readpending; /* Is there a read using the semaphore? */ /* Hold a list of events */
sem_t readsem; /* Signaling semaphore for waiting read */
bool enableevents : 1; /* Are events enabled? */
bool geteventpending : 1; /* Is there a get event using the semaphore? */
sem_t geteventsem; /* Signaling semaphore for waiting get event */
FAR struct ieee802154_notif_s *event_head;
FAR struct ieee802154_notif_s *event_tail;
/* The following is a singly linked list of open references to the /* The following is a singly linked list of open references to the
* MAC device. * MAC device.
*/ */
FAR struct mac802154dev_open_s *md_open; FAR struct mac802154dev_open_s *md_open;
FAR struct mac802154dev_dwait_s *md_dwait;
/* Hold a list of transactions as a "readahead" buffer */ /* Hold a list of transactions as a "readahead" buffer */
FAR struct ieee802154_data_ind_s *dataind_head; bool readpending; /* Is there a read using the semaphore? */
FAR struct ieee802154_data_ind_s *dataind_tail; sem_t readsem; /* Signaling semaphore for waiting read */
sq_queue_t dataind_queue;
#ifndef CONFIG_DISABLE_SIGNALS #ifndef CONFIG_DISABLE_SIGNALS
/* MCPS Service notification information */ /* MAC Service notification information */
struct mac802154dev_notify_s md_mcps_notify; bool notify_registered;
pid_t md_mcps_pid; struct mac802154dev_notify_s md_notify;
pid_t md_notify_pid;
/* MLME Service notification information */
struct mac802154dev_notify_s md_mlme_notify;
pid_t md_mlme_pid;
#endif #endif
}; };
@ -145,19 +136,16 @@ struct mac802154_chardevice_s
static inline int mac802154dev_takesem(sem_t *sem); static inline int mac802154dev_takesem(sem_t *sem);
#define mac802154dev_givesem(s) sem_post(s); #define mac802154dev_givesem(s) sem_post(s);
static void mac802154dev_push_dataind(FAR struct mac802154_chardevice_s *dev, static inline void mac802154dev_pushevent(FAR struct mac802154_chardevice_s *dev,
FAR struct ieee802154_data_ind_s *ind); FAR struct ieee802154_notif_s *notif);
static FAR struct ieee802154_data_ind_s * static inline FAR struct ieee802154_notif_s *
mac802154dev_pop_dataind(FAR struct mac802154_chardevice_s *dev); mac802154dev_popevent(FAR struct mac802154_chardevice_s *dev);
static void mac802154dev_notify(FAR const struct mac802154_maccb_s *maccb,
FAR struct ieee802154_notif_s *notif);
static void mac802154dev_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, static void mac802154dev_rxframe(FAR const struct mac802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif, FAR struct ieee802154_data_ind_s *ind);
FAR const union ieee802154_mlme_notify_u *arg);
static void mac802154dev_mcps_notify(FAR const struct ieee802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif,
FAR const union ieee802154_mcps_notify_u *arg);
static int mac802154dev_open(FAR struct file *filep); static int mac802154dev_open(FAR struct file *filep);
static int mac802154dev_close(FAR struct file *filep); static int mac802154dev_close(FAR struct file *filep);
@ -168,13 +156,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
static int mac802154dev_ioctl(FAR struct file *filep, int cmd, static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
unsigned long arg); unsigned long arg);
/* MAC callback helpers */
static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev,
FAR const struct ieee802154_data_conf_s *conf);
static void mac802154dev_ind_data(FAR struct mac802154_chardevice_s *dev,
FAR struct ieee802154_data_ind_s *ind);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
@ -224,76 +205,60 @@ static inline int mac802154dev_takesem(sem_t *sem)
} }
/**************************************************************************** /****************************************************************************
* Name: mac802154dev_push_dataind * Name: mac802154dev_pushevent
* *
* Description: * Description:
* Push a data indication onto the list to be processed * Push event onto the event queue
*
* Assumptions:
* Called with the char device struct locked.
* *
****************************************************************************/ ****************************************************************************/
static void mac802154dev_push_dataind(FAR struct mac802154_chardevice_s *dev, static inline void mac802154dev_pushevent(FAR struct mac802154_chardevice_s *dev,
FAR struct ieee802154_data_ind_s *ind) FAR struct ieee802154_notif_s *notif)
{ {
/* Ensure the forward link is NULL */ notif->flink = NULL;
if (!dev->event_head)
ind->flink = NULL;
/* If the tail is not empty, make the frame pointed to by the tail,
* point to the new data indication */
if (dev->dataind_tail != NULL)
{ {
dev->dataind_tail->flink = ind; dev->event_head = notif;
dev->event_tail = notif;
} }
else
/* Point the tail at the new frame */
dev->dataind_tail = ind;
/* If the head is NULL, we need to point it at the data indication since there
* is only one indication in the list at this point */
if (dev->dataind_head == NULL)
{ {
dev->dataind_head = ind; dev->event_tail->flink = notif;
dev->event_tail = notif;
} }
} }
/**************************************************************************** /****************************************************************************
* Name: mac802154dev_pop_dataind * Name: mac802154dev_popevent
* *
* Description: * Description:
* Pop a data indication from the list * Pop an event off of the event queue
*
* Assumptions:
* Called with the char device struct locked.
* *
****************************************************************************/ ****************************************************************************/
static FAR struct ieee802154_data_ind_s * static inline FAR struct ieee802154_notif_s *
mac802154dev_pop_dataind(FAR struct mac802154_chardevice_s *dev) mac802154dev_popevent(FAR struct mac802154_chardevice_s *dev)
{ {
FAR struct ieee802154_data_ind_s *ind; FAR struct ieee802154_notif_s *notif = dev->event_head;
if (dev->dataind_head == NULL) if (notif)
{ {
return NULL; dev->event_head = notif->flink;
if (!dev->event_head)
{
dev->event_head = NULL;
}
notif->flink = NULL;
} }
/* Get the data indication from the head of the list */ return notif;
ind = dev->dataind_head;
ind->flink = NULL;
/* Move the head pointer to the next data indication */
dev->dataind_head = ind->flink;
/* If the head is now NULL, the list is empty, so clear the tail too */
if (dev->dataind_head == NULL)
{
dev->dataind_tail = NULL;
}
return ind;
} }
/**************************************************************************** /****************************************************************************
@ -383,7 +348,7 @@ static int mac802154dev_close(FAR struct file *filep)
* *
* This is actually a pretty feeble attempt to handle this. The * This is actually a pretty feeble attempt to handle this. The
* improbable race condition occurs if two different threads try to * improbable race condition occurs if two different threads try to
* close the joystick driver at the same time. The rule: don't do * close the driver at the same time. The rule: don't do
* that! It is feeble because we do not really enforce stale pointer * that! It is feeble because we do not really enforce stale pointer
* detection anyway. * detection anyway.
*/ */
@ -437,6 +402,23 @@ static int mac802154dev_close(FAR struct file *filep)
/* And free the open structure */ /* And free the open structure */
kmm_free(opriv); kmm_free(opriv);
/* If there are now no open instances of the driver and a signal handler is
* not registered, purge the list of events.
*/
if (dev->md_open)
{
FAR struct ieee802154_notif_s *notif;
while (dev->event_head != NULL)
{
notif = mac802154dev_popevent(dev);
DEBUGASSERT(notif != NULL);
mac802154_notif_free(dev->md_mac, notif);
}
}
ret = OK; ret = OK;
errout_with_exclsem: errout_with_exclsem:
@ -491,7 +473,7 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer,
/* Try popping a data indication off the list */ /* Try popping a data indication off the list */
ind = mac802154dev_pop_dataind(dev); ind = (FAR struct ieee802154_data_ind_s *)sq_remfirst(&dev->dataind_queue);
/* If the indication is not null, we can exit the loop and copy the data */ /* If the indication is not null, we can exit the loop and copy the data */
@ -522,11 +504,7 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer,
if (sem_wait(&dev->readsem) < 0) if (sem_wait(&dev->readsem) < 0)
{ {
DEBUGASSERT(errno == EINTR); DEBUGASSERT(errno == EINTR);
/* Need to get exclusive access again to change the pending bool */
ret = mac802154dev_takesem(&dev->md_exclsem);
dev->readpending = false; dev->readpending = false;
mac802154dev_givesem(&dev->md_exclsem);
return -EINTR; return -EINTR;
} }
@ -571,7 +549,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
FAR struct mac802154_chardevice_s *dev; FAR struct mac802154_chardevice_s *dev;
FAR struct mac802154dev_txframe_s *tx; FAR struct mac802154dev_txframe_s *tx;
FAR struct iob_s *iob; FAR struct iob_s *iob;
struct mac802154dev_dwait_s dwait;
int ret; int ret;
DEBUGASSERT(filep && filep->f_inode); DEBUGASSERT(filep && filep->f_inode);
@ -579,7 +556,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
DEBUGASSERT(inode->i_private); DEBUGASSERT(inode->i_private);
dev = (FAR struct mac802154_chardevice_s *)inode->i_private; dev = (FAR struct mac802154_chardevice_s *)inode->i_private;
/* Check if the struct is write */ /* Check if the struct is the correct size */
if (len != sizeof(struct mac802154dev_txframe_s)) if (len != sizeof(struct mac802154dev_txframe_s))
{ {
@ -618,38 +595,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
iob->io_len += tx->length; iob->io_len += tx->length;
/* If this is a blocking operation, we need to setup a wait struct so we
* can unblock when the packet transmission has finished. If this is a
* non-blocking write, we pass off the data and then move along. Technically
* we stil have to wait for the transaction to get put into the buffer, but we
* won't wait for the transaction to actually finish. */
if (!(filep->f_oflags & O_NONBLOCK))
{
/* Get exclusive access to the driver structure */
ret = mac802154dev_takesem(&dev->md_exclsem);
if (ret < 0)
{
wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret);
return ret;
}
/* Setup the wait struct */
dwait.mw_handle = tx->meta.msdu_handle;
/* Link the wait struct */
dwait.mw_flink = dev->md_dwait;
dev->md_dwait = &dwait;
sem_init(&dwait.mw_sem, 0, 0);
sem_setprotocol(&dwait.mw_sem, SEM_PRIO_NONE);
mac802154dev_givesem(&dev->md_exclsem);
}
/* Pass the request to the MAC layer */ /* Pass the request to the MAC layer */
ret = mac802154_req_data(dev->md_mac, &tx->meta, iob); ret = mac802154_req_data(dev->md_mac, &tx->meta, iob);
@ -659,28 +604,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
return ret; return ret;
} }
if (!(filep->f_oflags & O_NONBLOCK))
{
/* Wait for the DATA.confirm callback to be called for our handle */
if (sem_wait(&dwait.mw_sem) < 0)
{
/* This should only happen if the wait was canceled by an signal */
sem_destroy(&dwait.mw_sem);
DEBUGASSERT(errno == EINTR);
return -EINTR;
}
/* The unlinking of the wait struct happens inside the callback. This
* is more efficient since it will already have to find the struct in
* the list in order to perform the sem_post.
*/
sem_destroy(&dwait.mw_sem);
return dwait.mw_status;
}
return OK; return OK;
} }
@ -688,7 +611,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
* Name: mac802154dev_ioctl * Name: mac802154dev_ioctl
* *
* Description: * Description:
* Control the MAC layer via MLME IOCTL commands. * Control the MAC layer via IOCTL commands.
* *
****************************************************************************/ ****************************************************************************/
@ -728,7 +651,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
* failure with the errno value set appropriately. * failure with the errno value set appropriately.
*/ */
case MAC802154IOC_MLME_REGISTER: case MAC802154IOC_NOTIFY_REGISTER:
{ {
FAR struct mac802154dev_notify_s *notify = FAR struct mac802154dev_notify_s *notify =
(FAR struct mac802154dev_notify_s *)((uintptr_t)arg); (FAR struct mac802154dev_notify_s *)((uintptr_t)arg);
@ -737,38 +660,101 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
{ {
/* Save the notification events */ /* Save the notification events */
dev->md_mlme_notify.mn_signo = notify->mn_signo; dev->md_notify.mn_signo = notify->mn_signo;
dev->md_mlme_pid = getpid(); dev->md_notify_pid = getpid();
dev->notify_registered = true;
return OK; ret = OK;
} }
} else
break;
case MAC802154IOC_MCPS_REGISTER:
{
FAR struct mac802154dev_notify_s *notify =
(FAR struct mac802154dev_notify_s *)((uintptr_t)arg);
if (notify)
{ {
/* Save the notification events */ ret = -EINVAL;
dev->md_mcps_notify.mn_signo = notify->mn_signo;
dev->md_mcps_pid = getpid();
return OK;
} }
} }
break; break;
#endif #endif
case MAC802154IOC_GET_EVENT:
{
FAR struct ieee802154_notif_s *usr_notif =
(FAR struct ieee802154_notif_s *)((uintptr_t)arg);
FAR struct ieee802154_notif_s *notif;
while (1)
{
/* Try popping an event off the queue */
notif = mac802154dev_popevent(dev);
/* If there was an event to pop off, copy it into the user data and
* free it from the MAC layer's memory.
*/
if (notif != NULL)
{
memcpy(usr_notif, notif, sizeof(struct ieee802154_notif_s));
/* Free the notification */
mac802154_notif_free(dev->md_mac, notif);
ret = OK;
break;
}
/* If this is a non-blocking call, or if there is another getevent
* operation already pending, don't block. This driver returns
* EAGAIN even when configured as non-blocking if another getevent
* operation is already pending This situation should be rare.
* It will only occur when there are 2 calls from separate threads
* and there was no events in the queue.
*/
if ((filep->f_oflags & O_NONBLOCK) || dev->geteventpending)
{
ret = -EAGAIN;
break;
}
dev->geteventpending = true;
mac802154dev_givesem(&dev->md_exclsem);
/* Wait to be signaled when an event is queued */
if (sem_wait(&dev->geteventsem) < 0)
{
DEBUGASSERT(errno == EINTR);
dev->geteventpending = false;
return -EINTR;
}
/* Get exclusive access again, then loop back around and try and
* pop an event off the queue
*/
ret = mac802154dev_takesem(&dev->md_exclsem);
if (ret < 0)
{
wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret);
return ret;
}
}
}
break;
case MAC802154IOC_ENABLE_EVENTS:
{
dev->enableevents = (bool)arg;
ret = OK;
}
break;
default: default:
{ {
/* Forward any unrecognized commands to the MAC layer */ /* Forward any unrecognized commands to the MAC layer */
mac802154_ioctl(dev->md_mac, cmd, arg); ret = mac802154_ioctl(dev->md_mac, cmd, arg);
} }
break; break;
} }
@ -776,9 +762,8 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
return ret; return ret;
} }
static void mac802154dev_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, static void mac802154dev_notify(FAR const struct mac802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif, FAR struct ieee802154_notif_s *notif)
FAR const union ieee802154_mlme_notify_u *arg)
{ {
FAR struct mac802154dev_callback_s *cb = FAR struct mac802154dev_callback_s *cb =
(FAR struct mac802154dev_callback_s *)maccb; (FAR struct mac802154dev_callback_s *)maccb;
@ -787,108 +772,70 @@ static void mac802154dev_mlme_notify(FAR const struct ieee802154_maccb_s *maccb,
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
dev = cb->mc_priv; dev = cb->mc_priv;
switch (notif)
{
#warning Handle MLME notifications
default:
break;
}
}
static void mac802154dev_mcps_notify(FAR const struct ieee802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif,
FAR const union ieee802154_mcps_notify_u *arg)
{
FAR struct mac802154dev_callback_s *cb =
(FAR struct mac802154dev_callback_s *)maccb;
FAR struct mac802154_chardevice_s *dev;
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
dev = cb->mc_priv;
switch (notif)
{
case IEEE802154_NOTIFY_CONF_DATA:
{
mac802154dev_conf_data(dev, &arg->dataconf);
}
break;
case IEEE802154_NOTIFY_IND_DATA:
{
mac802154dev_ind_data(dev, arg->dataind);
}
break;
default:
break;
}
}
static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev,
FAR const struct ieee802154_data_conf_s *conf)
{
FAR struct mac802154dev_dwait_s *curr;
FAR struct mac802154dev_dwait_s *prev;
/* Get exclusive access to the driver structure. We don't care about any /* Get exclusive access to the driver structure. We don't care about any
* signals so if we see one, just go back to trying to get access again */ * signals so if we see one, just go back to trying to get access again */
while (mac802154dev_takesem(&dev->md_exclsem) != 0); while (mac802154dev_takesem(&dev->md_exclsem) != 0);
/* Search to see if there is a dwait pending for this transaction */ /* If there is a registered notification receiver, queue the event and signal
* the receiver. Events should be popped from the queue from the application
* at a reasonable rate in order for the MAC layer to be able to allocate new
* notifications.
*/
for (prev = NULL, curr = dev->md_dwait; if (dev->enableevents && (dev->md_open != NULL || dev->notify_registered))
curr && curr->mw_handle != conf->handle; {
prev = curr, curr = curr->mw_flink); mac802154dev_pushevent(dev, notif);
/* If a dwait is found */ /* Check if there is a read waiting for data */
if (curr) if (dev->geteventpending)
{
/* Unlink the structure from the list. The struct should be allocated on
* the calling write's stack, so we don't need to worry about deallocating
* here */
if (prev)
{ {
prev->mw_flink = curr->mw_flink; /* Wake the thread waiting for the data transmission */
}
else dev->geteventpending = false;
{ sem_post(&dev->geteventsem);
dev->md_dwait = curr->mw_flink;
} }
/* Copy the transmission status into the dwait struct */ #ifndef CONFIG_DISABLE_SIGNALS
if (dev->notify_registered)
curr->mw_status = conf->status; {
/* Wake the thread waiting for the data transmission */
sem_post(&curr->mw_sem);
/* Release the driver */
mac802154dev_givesem(&dev->md_exclsem);
}
#ifndef CONFIG_DISABLE_SIGNALS
/* Send a signal to the registered application */
#ifdef CONFIG_CAN_PASS_STRUCTS #ifdef CONFIG_CAN_PASS_STRUCTS
/* Copy the status as the signal data to be optionally used by app */ union sigval value;
value.sival_int = (int)notif->notiftype;
union sigval value; (void)sigqueue(dev->md_notify_pid, dev->md_notify.mn_signo, value);
value.sival_int = (int)conf->status;
(void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, value);
#else #else
(void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, (void)sigqueue(dev->md_notify_pid, dev->md_notify.mn_signo,
value.sival_ptr); (FAR void *)notif->notiftype);
#endif
#endif #endif
}
#endif
}
else
{
/* Just free the event if the driver is closed and there isn't a registered
* signal number.
*/
mac802154_notif_free(dev->md_mac, notif);
}
/* Release the driver */
mac802154dev_givesem(&dev->md_exclsem);
} }
static void mac802154dev_ind_data(FAR struct mac802154_chardevice_s *dev, static void mac802154dev_rxframe(FAR const struct mac802154_maccb_s *maccb,
FAR struct ieee802154_data_ind_s *ind) FAR struct ieee802154_data_ind_s *ind)
{ {
FAR struct mac802154dev_callback_s *cb =
(FAR struct mac802154dev_callback_s *)maccb;
FAR struct mac802154_chardevice_s *dev;
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
dev = cb->mc_priv;
/* Get exclusive access to the driver structure. We don't care about any /* Get exclusive access to the driver structure. We don't care about any
* signals so if we see one, just go back to trying to get access again */ * signals so if we see one, just go back to trying to get access again */
@ -896,7 +843,7 @@ static void mac802154dev_ind_data(FAR struct mac802154_chardevice_s *dev,
/* Push the indication onto the list */ /* Push the indication onto the list */
mac802154dev_push_dataind(dev, ind); sq_addlast((FAR sq_entry_t *)ind, &dev->dataind_queue);
/* Check if there is a read waiting for data */ /* Check if there is a read waiting for data */
@ -911,21 +858,6 @@ static void mac802154dev_ind_data(FAR struct mac802154_chardevice_s *dev,
/* Release the driver */ /* Release the driver */
mac802154dev_givesem(&dev->md_exclsem); mac802154dev_givesem(&dev->md_exclsem);
#ifndef CONFIG_DISABLE_SIGNALS
/* Send a signal to the registered application */
#ifdef CONFIG_CAN_PASS_STRUCTS
/* Copy the status as the signal data to be optionally used by app */
union sigval value;
value.sival_int = IEEE802154_STATUS_SUCCESS;
(void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, value);
#else
(void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo,
value.sival_ptr);
#endif
#endif
} }
/**************************************************************************** /****************************************************************************
@ -953,7 +885,7 @@ static void mac802154dev_ind_data(FAR struct mac802154_chardevice_s *dev,
int mac802154dev_register(MACHANDLE mac, int minor) int mac802154dev_register(MACHANDLE mac, int minor)
{ {
FAR struct mac802154_chardevice_s *dev; FAR struct mac802154_chardevice_s *dev;
FAR struct ieee802154_maccb_s *maccb; FAR struct mac802154_maccb_s *maccb;
char devname[DEVNAME_FMTLEN]; char devname[DEVNAME_FMTLEN];
int ret; int ret;
@ -974,13 +906,25 @@ int mac802154dev_register(MACHANDLE mac, int minor)
sem_setprotocol(&dev->readsem, SEM_PRIO_NONE); sem_setprotocol(&dev->readsem, SEM_PRIO_NONE);
dev->readpending = false; dev->readpending = false;
sq_init(&dev->dataind_queue);
dev->geteventpending = false;
sem_init(&dev->geteventsem, 0, 0);
sem_setprotocol(&dev->geteventsem, SEM_PRIO_NONE);
dev->event_head = NULL;
dev->event_tail = NULL;
dev->enableevents = true;
dev->notify_registered = false;
/* Initialize the MAC callbacks */ /* Initialize the MAC callbacks */
dev->md_cb.mc_priv = dev; dev->md_cb.mc_priv = dev;
maccb = &dev->md_cb.mc_cb; maccb = &dev->md_cb.mc_cb;
maccb->mlme_notify = mac802154dev_mlme_notify; maccb->notify = mac802154dev_notify;
maccb->mcps_notify = mac802154dev_mcps_notify; maccb->rxframe = mac802154dev_rxframe;
/* Bind the callback structure */ /* Bind the callback structure */

View File

@ -109,7 +109,7 @@ struct macnet_callback_s
{ {
/* This holds the information visible to the MAC layer */ /* This holds the information visible to the MAC layer */
struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */ struct mac802154_maccb_s mc_cb; /* Interface understood by the MAC layer */
FAR struct macnet_driver_s *mc_priv; /* Our priv data */ FAR struct macnet_driver_s *mc_priv; /* Our priv data */
}; };
@ -138,12 +138,10 @@ struct macnet_driver_s
/* IEE802.15.4 MAC callback functions ***************************************/ /* IEE802.15.4 MAC callback functions ***************************************/
static void macnet_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, static void macnet_notify(FAR const struct mac802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif, FAR struct ieee802154_notif_s *notif);
FAR const union ieee802154_mlme_notify_u *arg); static void macnet_rxframe(FAR const struct mac802154_maccb_s *maccb,
static void macnet_mcps_notify(FAR const struct ieee802154_maccb_s *maccb, FAR struct ieee802154_data_ind_s *ind);
enum ieee802154_macnotify_e notif,
FAR const union ieee802154_mcps_notify_u *arg);
/* Asynchronous confirmations to requests */ /* Asynchronous confirmations to requests */
@ -166,8 +164,6 @@ static void macnet_conf_poll(FAR struct macnet_driver_s *priv,
/* Asynchronous event indications, replied to synchronously with responses */ /* Asynchronous event indications, replied to synchronously with responses */
static void macnet_ind_data(FAR struct macnet_driver_s *priv,
FAR struct ieee802154_data_ind_s *conf);
static void macnet_ind_associate(FAR struct macnet_driver_s *priv, static void macnet_ind_associate(FAR struct macnet_driver_s *priv,
FAR struct ieee802154_assoc_ind_s *conf); FAR struct ieee802154_assoc_ind_s *conf);
static void macnet_ind_disassociate(FAR struct macnet_driver_s *priv, static void macnet_ind_disassociate(FAR struct macnet_driver_s *priv,
@ -221,15 +217,14 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev,
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: macnet_mlme_notify * Name: macnet_notify
* *
* Description: * Description:
* *
****************************************************************************/ ****************************************************************************/
static void macnet_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, static void macnet_notify(FAR const struct mac802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif, FAR struct ieee802154_notif_s *notif)
FAR const union ieee802154_mlme_notify_u *arg)
{ {
FAR struct macnet_callback_s *cb = FAR struct macnet_callback_s *cb =
(FAR struct macnet_callback_s *)maccb; (FAR struct macnet_callback_s *)maccb;
@ -238,8 +233,13 @@ static void macnet_mlme_notify(FAR const struct ieee802154_maccb_s *maccb,
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
priv = cb->mc_priv; priv = cb->mc_priv;
switch (notif) switch (notif->notiftype)
{ {
case IEEE802154_NOTIFY_CONF_DATA:
{
macnet_conf_data(priv, &notif->u.dataconf);
}
break;
default: default:
break; break;
@ -247,40 +247,38 @@ static void macnet_mlme_notify(FAR const struct ieee802154_maccb_s *maccb,
} }
/**************************************************************************** /****************************************************************************
* Name: macnet_mcps_notify * Name: macnet_rxframe
* *
* Description: * Description:
* *
****************************************************************************/ ****************************************************************************/
static void macnet_mcps_notify(FAR const struct ieee802154_maccb_s *maccb, static void macnet_rxframe(FAR const struct mac802154_maccb_s *maccb,
enum ieee802154_macnotify_e notif, FAR struct ieee802154_data_ind_s *ind)
FAR const union ieee802154_mcps_notify_u *arg)
{ {
FAR struct macnet_callback_s *cb = FAR struct macnet_callback_s *cb =
(FAR struct macnet_callback_s *)maccb; (FAR struct macnet_callback_s *)maccb;
FAR struct macnet_driver_s *priv; FAR struct macnet_driver_s *priv;
FAR struct iob_s *iob;
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
priv = cb->mc_priv; priv = cb->mc_priv;
switch (notif) /* Extract the IOB containing the frame from the struct ieee802154_data_ind_s */
{
case IEEE802154_NOTIFY_CONF_DATA:
{
macnet_conf_data(priv, &arg->dataconf);
}
break;
case IEEE802154_NOTIFY_IND_DATA: DEBUGASSERT(priv != NULL && ind != NULL && ind->frame != NULL);
{ iob = ind->frame;
macnet_ind_data(priv, arg->dataind); ind->frame = NULL;
}
break;
default: /* Transfer the frame to the network logic */
break;
} sixlowpan_input(&priv->md_dev, iob, ind);
/* sixlowpan_input() will free the IOB, but we must free the struct
* ieee802154_data_ind_s container here.
*/
ieee802154_ind_free(ind);
} }
/**************************************************************************** /****************************************************************************
@ -391,36 +389,6 @@ static void macnet_conf_poll(FAR struct macnet_driver_s *priv,
} }
/****************************************************************************
* Name: macnet_ind_data
*
* Description:
* Data frame received
*
****************************************************************************/
static void macnet_ind_data(FAR struct macnet_driver_s *priv,
FAR struct ieee802154_data_ind_s *ind)
{
FAR struct iob_s *iob;
/* Extract the IOB containing the frame from the struct ieee802154_data_ind_s */
DEBUGASSERT(priv != NULL && ind != NULL && ind->frame != NULL);
iob = ind->frame;
ind->frame = NULL;
/* Transfer the frame to the network logic */
sixlowpan_input(&priv->md_dev, iob, ind);
/* sixlowpan_input() will free the IOB, but we must free the struct
* ieee802154_data_ind_s container here.
*/
ieee802154_ind_free(ind);
}
/**************************************************************************** /****************************************************************************
* Name: macnet_ind_associate * Name: macnet_ind_associate
* *
@ -1041,7 +1009,7 @@ int mac802154netdev_register(MACHANDLE mac)
FAR struct macnet_driver_s *priv; FAR struct macnet_driver_s *priv;
FAR struct ieee802154_driver_s *ieee; FAR struct ieee802154_driver_s *ieee;
FAR struct net_driver_s *dev; FAR struct net_driver_s *dev;
FAR struct ieee802154_maccb_s *maccb; FAR struct mac802154_maccb_s *maccb;
FAR uint8_t *pktbuf; FAR uint8_t *pktbuf;
int ret; int ret;
@ -1103,9 +1071,9 @@ int mac802154netdev_register(MACHANDLE mac)
priv->md_cb.mc_priv = priv; priv->md_cb.mc_priv = priv;
maccb = &priv->md_cb.mc_cb; maccb = &priv->md_cb.mc_cb;
maccb->mlme_notify = macnet_mlme_notify; maccb->notify = macnet_notify;
maccb->mcps_notify = macnet_mcps_notify; maccb->rxframe = macnet_rxframe;
/* Bind the callback structure */ /* Bind the callback structure */