2017-06-14 08:49:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_poll.c
|
|
|
|
*
|
2024-09-11 09:04:25 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-09-06 13:39:36 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
2021-09-06 13:39:36 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
2021-09-06 13:39:36 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "mac802154.h"
|
|
|
|
#include "mac802154_internal.h"
|
|
|
|
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
static void mac802154_polltimeout(FAR void *arg);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2020-04-23 11:51:21 +02:00
|
|
|
* Public Functions
|
2017-06-14 08:49:27 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_req_poll
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-POLL.request primitive prompts the device to request data from
|
|
|
|
* the coordinator. Confirmation is returned via the
|
|
|
|
* struct mac802154_maccb_s->conf_poll callback, followed by a
|
|
|
|
* struct mac802154_maccb_s->ind_data callback.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)mac;
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc;
|
|
|
|
int ret;
|
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* On receipt of the MLME-POLL.request primitive, the MLME requests data
|
|
|
|
* from the coordinator, as described in 5.1.6.3. If the poll is directed
|
|
|
|
* to the PAN coordinator, the data request command may be generated
|
|
|
|
* without any destination address information present. Otherwise, the data
|
|
|
|
* request command is always generated with the destination address
|
|
|
|
* information in the CoordPANId and CoordAddress parameters.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
2019-09-17 18:46:23 +02:00
|
|
|
/* Get exclusive access to the operation semaphore. This must happen before
|
2020-04-23 11:51:21 +02:00
|
|
|
* getting exclusive access to the MAC struct or else there could be a
|
|
|
|
* lockup condition. This would occur if another thread is using the
|
|
|
|
* cmdtrans but needs access to the MAC in order to unlock it.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxsem_wait_uninterruptible(&priv->opsem);
|
2017-06-14 08:49:27 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get exclusive access to the MAC */
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->lock);
|
2020-04-23 11:51:21 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
nxsem_post(&priv->opsem);
|
2020-04-23 11:51:21 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-17 20:56:42 +02:00
|
|
|
priv->curr_op = MAC802154_OP_POLL;
|
|
|
|
priv->curr_cmd = IEEE802154_CMD_DATA_REQ;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Allocate the txdesc, waiting if necessary */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = mac802154_txdesc_alloc(priv, &txdesc);
|
2017-06-14 08:49:27 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
|
|
|
nxsem_post(&priv->opsem);
|
2017-06-14 08:49:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The Source Addressing Mode field shall be set according to the value of
|
2020-04-23 11:51:21 +02:00
|
|
|
* macShortAddress.
|
|
|
|
* If macShortAddress is less than 0xfffe, short addressing shall be used.
|
|
|
|
* Extended addressing shall be used otherwise.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
2017-09-15 16:04:38 +02:00
|
|
|
if (priv->addr.saddr[0] >= 0xfe && priv->addr.saddr[1] == 0xff)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
mac802154_createdatareq(priv,
|
|
|
|
&req->coordaddr,
|
|
|
|
IEEE802154_ADDRMODE_EXTENDED,
|
2017-06-19 21:59:21 +02:00
|
|
|
txdesc);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
mac802154_createdatareq(priv,
|
|
|
|
&req->coordaddr,
|
|
|
|
IEEE802154_ADDRMODE_SHORT,
|
2017-06-19 21:59:21 +02:00
|
|
|
txdesc);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
2017-06-17 22:13:25 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* Save a copy of the destination addressing information into the tx
|
|
|
|
* descriptor. We only do this for commands to help with handling their
|
|
|
|
* progession.
|
2017-06-19 21:55:02 +02:00
|
|
|
*/
|
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
memcpy(&txdesc->destaddr,
|
|
|
|
&req->coordaddr,
|
|
|
|
sizeof(struct ieee802154_addr_s));
|
2017-06-19 21:55:02 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Save a reference of the tx descriptor */
|
|
|
|
|
|
|
|
priv->cmd_desc = txdesc;
|
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
wlinfo("Queuing POLL.request in CSMA queue\n");
|
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Link the transaction into the CSMA transaction list */
|
|
|
|
|
|
|
|
sq_addlast((FAR sq_entry_t *)txdesc, &priv->csma_queue);
|
|
|
|
|
|
|
|
/* We no longer need to have the MAC layer locked. */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Notify the radio driver that there is data available */
|
|
|
|
|
|
|
|
priv->radio->txnotify(priv->radio, false);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Internal MAC Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_txdone_datareq_poll
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle the completion (success/failure) of transmitting a data request
|
|
|
|
* command in an effort to extract data from the coordinator triggered by
|
|
|
|
* a POLL.request from the next highest layer
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called with the MAC locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void mac802154_txdone_datareq_poll(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc)
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s * primitive =
|
|
|
|
(FAR struct ieee802154_primitive_s *)txdesc->conf;
|
2017-06-14 08:49:27 +02:00
|
|
|
enum ieee802154_status_e status;
|
|
|
|
|
|
|
|
/* If the data request failed to be sent, notify the next layer
|
|
|
|
* that the poll has failed.
|
|
|
|
* OR
|
|
|
|
* On receipt of the Ack frame with the Frame Pending field set
|
|
|
|
* to zero, the device shall conclude that there are no data
|
|
|
|
* pending at the coordinator. [1] pg. 43
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (txdesc->conf->status != IEEE802154_STATUS_SUCCESS ||
|
2017-06-14 08:49:27 +02:00
|
|
|
txdesc->framepending == 0)
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
if (txdesc->conf->status != IEEE802154_STATUS_SUCCESS)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
status = txdesc->conf->status;
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = IEEE802154_STATUS_NO_DATA;
|
|
|
|
}
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->type = IEEE802154_PRIMITIVE_CONF_POLL;
|
|
|
|
txdesc->conf->status = status;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* We are now done the operation, and can release the command */
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
|
|
|
priv->cmd_desc = NULL;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxsem_post(&priv->opsem);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_notify(priv, primitive);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* On receipt of the acknowledgment frame with the Frame
|
|
|
|
* Pending field set to one, a device shall enable its
|
|
|
|
* receiver for at most macMaxFrameTotalWaitTime to receive
|
|
|
|
* the corresponding data frame from the coordinator. [1] pg.43
|
|
|
|
*/
|
|
|
|
|
2017-06-26 19:03:44 +02:00
|
|
|
mac802154_rxenable(priv);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Start a timer, if we receive the data frame, we will cancel
|
|
|
|
* the timer, otherwise it will expire and we will notify the
|
|
|
|
* next highest layer of the failure.
|
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
mac802154_timerstart(priv, priv->max_frame_waittime,
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_polltimeout);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Deallocate the data conf primitive as it is no longer needed. */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
ieee802154_primitive_free(primitive);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-06-26 00:07:50 +02:00
|
|
|
* Name: mac802154_polltimeout
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2020-04-23 11:51:21 +02:00
|
|
|
* Function registered with MAC timer that gets called via the work queue
|
|
|
|
* to handle a timeout for extracting a response from the Coordinator.
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
void mac802154_polltimeout(FAR void *arg)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)arg;
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *primitive;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
/* If there is work scheduled for the rxframe_worker, we want to reschedule
|
2020-04-23 11:51:21 +02:00
|
|
|
* this work, so that we make sure if the frame we were waiting for was
|
|
|
|
* just received, we don't timeout
|
2017-07-10 05:55:48 +02:00
|
|
|
*/
|
2017-07-10 19:04:27 +02:00
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
if (!work_available(&priv->rx_work))
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
work_queue(HPWORK, &priv->timer_work, mac802154_polltimeout, priv, 0);
|
2017-07-10 05:55:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
DEBUGASSERT(priv->curr_op == MAC802154_OP_POLL);
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive = ieee802154_primitive_allocate();
|
|
|
|
primitive->type = IEEE802154_PRIMITIVE_CONF_POLL;
|
|
|
|
primitive->u.pollconf.status = IEEE802154_STATUS_NO_DATA;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_lock(&priv->lock);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* We are no longer performing the association operation */
|
2020-04-23 11:51:21 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
|
|
|
priv->cmd_desc = NULL;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxsem_post(&priv->opsem);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_notify(priv, primitive);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2019-09-17 18:46:23 +02:00
|
|
|
}
|