2017-06-14 08:49:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_rxenable.c
|
|
|
|
*
|
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"
|
2018-03-28 17:49:34 +02:00
|
|
|
#include "mac802154_internal.h"
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-03-28 17:49:34 +02:00
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void mac802154_rxenabletimeout(FAR void *arg);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_rxenabletimeout
|
|
|
|
*
|
|
|
|
* 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 the Association Response from the
|
2019-02-27 15:41:08 +01:00
|
|
|
* Coordinator.
|
2018-03-28 17:49:34 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void mac802154_rxenabletimeout(FAR void *arg)
|
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)arg;
|
2018-03-28 17:49:34 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
while (mac802154_lock(priv, true) != 0);
|
2018-03-28 17:49:34 +02:00
|
|
|
|
|
|
|
if (priv->curr_op != MAC802154_OP_RXENABLE)
|
|
|
|
{
|
|
|
|
mac802154_unlock(priv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac802154_rxdisable(priv);
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
|
|
|
mac802154_givesem(&priv->opsem);
|
|
|
|
|
|
|
|
mac802154_unlock(priv)
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
2017-06-14 08:49:27 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_req_rxenable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-RX-ENABLE.request primitive allows the next higher layer to
|
|
|
|
* request that the receiver is enable for a finite period of time.
|
|
|
|
* Confirmation is returned via the
|
|
|
|
* struct mac802154_maccb_s->conf_rxenable callback.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mac802154_req_rxenable(MACHANDLE mac,
|
|
|
|
FAR struct ieee802154_rxenable_req_s *req)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s * priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)mac;
|
2018-03-28 17:49:34 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* If this is a Beacon-enabled network */
|
|
|
|
|
|
|
|
if (priv->sfspec.sforder < 15)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
goto errout_with_sem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Non-beacon enabled network */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (req->rxon_dur > 0)
|
|
|
|
{
|
2019-09-17 18:46:23 +02:00
|
|
|
/* Get exclusive access to the operation semaphore. This must
|
2019-02-27 15:41:08 +01:00
|
|
|
* happen before 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.
|
2018-03-28 17:49:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
ret = mac802154_takesem(&priv->opsem, true);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_RXENABLE;
|
|
|
|
|
|
|
|
/* Get exclusive access to the MAC */
|
|
|
|
|
|
|
|
ret = mac802154_lock(priv, true);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Should only fail if interrupted by a signal */
|
|
|
|
|
|
|
|
wlwarn("WARNING: mac802154_takesem failed: %d\n", ret);
|
|
|
|
|
|
|
|
mac802154_givesem(&priv->opsem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac802154_rxenable(priv);
|
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
if (req->rxon_dur != 0xffffffff)
|
2018-03-28 17:49:34 +02:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
mac802154_timerstart(priv, req->rxon_dur,
|
|
|
|
mac802154_rxenabletimeout);
|
2018-03-28 17:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = mac802154_lock(priv, true);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Should only fail if interrupted by a signal */
|
|
|
|
|
|
|
|
wlwarn("WARNING: mac802154_takesem failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->curr_op != MAC802154_OP_RXENABLE)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto errout_with_sem;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac802154_timercancel(priv);
|
|
|
|
mac802154_rxdisable(priv);
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
|
|
|
mac802154_givesem(&priv->opsem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mac802154_unlock(priv)
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout_with_sem:
|
|
|
|
mac802154_unlock(priv)
|
|
|
|
return ret;
|
2019-02-27 15:41:08 +01:00
|
|
|
}
|