From b1ff257215280007303b7d5a173246e7333feb47 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 1 May 2017 09:27:06 -0400 Subject: [PATCH 1/2] wireless/ieee802154: Minor fixes to account for moved IOCTL definitions --- include/nuttx/wireless/ieee802154/ieee802154_ioctl.h | 6 +++++- wireless/ieee802154/mac802154_device.c | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h index 24ac37369f..533e2f3853 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h @@ -67,7 +67,11 @@ * Public Types ************************************************************************************/ -/* To be provided */ +struct mac802154dev_notify_s +{ + uint8_t mn_signo; /* Signal number to use in the notification */ +}; + #endif /* CONFIG_WIRELESS_IEEE802154 */ #endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_IOCTL_H */ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 19d3a5bc41..9721a5a7fe 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -50,6 +50,7 @@ #include #include +#include #include #include "mac802154.h" @@ -67,11 +68,6 @@ * Private Types ****************************************************************************/ -struct mac802154dev_notify_s -{ - uint8_t mn_signo; /* Signal number to use in the notification */ -}; - /* This structure describes the state of one open mac driver instance */ struct mac802154dev_open_s From c4007a111c2d22abd25320386d8999c3599a23ae Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 1 May 2017 09:27:40 -0400 Subject: [PATCH 2/2] wireless/ieee802154: Fixes semaphore logic and list logic --- drivers/wireless/ieee802154/mrf24j40.c | 4 + .../wireless/ieee802154/ieee802154_mac.h | 5 +- wireless/ieee802154/mac802154.c | 94 +++++++++++++++++-- wireless/ieee802154/mac802154_device.c | 8 +- 4 files changed, 97 insertions(+), 14 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index e65e48c108..6b602b739d 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1819,6 +1819,10 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, return NULL; } + /* Allow exclusive access to the privmac struct */ + + sem_init(&dev->exclsem, 0, 1); + dev->radio.ops = &mrf24j40_devops; dev->lower = lower; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index fc2b57c8f7..1a8e324ce2 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -536,11 +536,12 @@ struct ieee802154_data_req_s * to continue and make the struct "variable length" */ - uint8_t msdu[1]; + uint8_t msdu[IEEE802154_MAX_MAC_PAYLOAD_SIZE]; }; #define SIZEOF_IEEE802154_DATA_REQ_S(n) \ - (sizeof(struct ieee802154_data_req_s) + (n) - 1) + (sizeof(struct ieee802154_data_req_s) \ + - IEEE802154_MAX_MAC_PAYLOAD_SIZE + (n)) /***************************************************************************** * Primitive: MCPS-DATA.confirm diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 54e5782b41..f6b5f5f455 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -337,6 +337,78 @@ static inline int mac802154_takesem(sem_t *sem) return OK; } +/**************************************************************************** + * Name: mac802154_push_csma + * + * Description: + * Push a CSMA transaction onto the list + * + ****************************************************************************/ + +static void mac802154_push_csma(FAR struct ieee802154_privmac_s *priv, + FAR struct mac802154_trans_s *trans) +{ + /* Ensure the transactions forward link is NULL */ + + trans->flink = NULL; + + /* If the tail is not empty, make the transaction pointed to by the tail, + * point to the new transaction */ + + if (priv->csma_tail != NULL) + { + priv->csma_tail->flink = trans; + } + + /* Point the tail at the new transaction */ + + priv->csma_tail = trans; + + /* If the head is NULL, we need to point it at the transaction since there + * is only one transaction in the list at this point */ + + if (priv->csma_head == NULL) + { + priv->csma_head = trans; + } +} + +/**************************************************************************** + * Name: mac802154_pop_csma + * + * Description: + * Pop a CSMA transaction from the list + * + ****************************************************************************/ + +static FAR struct mac802154_trans_s * + mac802154_pop_csma(FAR struct ieee802154_privmac_s *priv) +{ + FAR struct mac802154_trans_s *trans; + + if (priv->csma_head == NULL) + { + return NULL; + } + + /* Get the transaction from the head of the list */ + + trans = priv->csma_head; + + /* Move the head pointer to the next transaction */ + + priv->csma_head = trans->flink; + + /* If the head is now NULL, the list is empty, so clear the tail too */ + + if (priv->csma_head == NULL) + { + priv->csma_tail = NULL; + } + + return trans; +} + /**************************************************************************** * Name: mac802154_defaultmib * @@ -398,14 +470,11 @@ static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, /* Check to see if there are any CSMA transactions waiting */ - if (priv->csma_head) + trans = mac802154_pop_csma(priv); + mac802154_givesem(&priv->exclsem); + + if (trans != NULL) { - /* Pop a CSMA transaction off the list */ - - trans = priv->csma_head; - priv->csma_head = priv->csma_head->flink; - - mac802154_givesem(&priv->exclsem); /* Setup the transmit descriptor */ @@ -426,7 +495,6 @@ static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, return (trans->mhr_len + trans->d_len); } - mac802154_givesem(&priv->exclsem); return 0; } @@ -673,6 +741,10 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) { return NULL; } + + /* Allow exclusive access to the privmac struct */ + + sem_init(&mac->exclsem, 0, 1); /* Initialize fields */ @@ -939,6 +1011,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) trans.msdu_handle = req->msdu_handle; + sem_init(&trans.sem, 0, 1); + /* If the TxOptions parameter specifies that a GTS transmission is required, * the MAC sublayer will determine whether it has a valid GTS as described * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard @@ -1000,8 +1074,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { /* Link the transaction into the CSMA transaction list */ - priv->csma_tail->flink = &trans; - priv->csma_tail = &trans; + mac802154_push_csma(priv, &trans); /* We no longer need to have the MAC layer locked. */ @@ -1015,6 +1088,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) } } + sem_destroy(&trans.sem); return OK; } diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 9721a5a7fe..5c31cdf140 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -425,8 +425,8 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Check to make sure that the buffer is big enough to hold at least one * packet. */ - if ((len >= SIZEOF_IEEE802154_DATA_REQ_S(1)) && - (len <= SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) + if ((len < SIZEOF_IEEE802154_DATA_REQ_S(1)) || + (len > SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) { wlerr("ERROR: buffer isn't an ieee802154_data_req_s: %lu\n", (unsigned long)len); @@ -463,6 +463,8 @@ static ssize_t mac802154dev_write(FAR struct file *filep, dwait.mw_flink = dev->md_dwait; dev->md_dwait = &dwait; + sem_init(&dwait.mw_sem, 0, 1); + mac802154dev_givesem(&dev->md_exclsem); } @@ -484,6 +486,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, { /* This should only happen if the wait was canceled by an signal */ + sem_destroy(&dwait.mw_sem); DEBUGASSERT(errno == EINTR); return -EINTR; } @@ -493,6 +496,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, * the list in order to perform the sem_post. */ + sem_destroy(&dwait.mw_sem); return dwait.mw_status; }