2017-06-14 08:49:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_rxenable.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"
|
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
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
while (nxmutex_lock(&priv->lock) != 0);
|
2018-03-28 17:49:34 +02:00
|
|
|
|
|
|
|
if (priv->curr_op != MAC802154_OP_RXENABLE)
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2018-03-28 17:49:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac802154_rxdisable(priv);
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxsem_post(&priv->opsem);
|
2018-03-28 17:49:34 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2018-03-28 17:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2018-03-28 17:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxsem_wait_uninterruptible(&priv->opsem);
|
2018-03-28 17:49:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_RXENABLE;
|
|
|
|
|
|
|
|
/* Get exclusive access to the MAC */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->lock);
|
2018-03-28 17:49:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Should only fail if interrupted by a signal */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
wlwarn("WARNING: nxmutex_lock failed: %d\n", ret);
|
2018-03-28 17:49:34 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxsem_post(&priv->opsem);
|
2018-03-28 17:49:34 +02:00
|
|
|
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
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->lock);
|
2018-03-28 17:49:34 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Should only fail if interrupted by a signal */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
wlwarn("WARNING: nxmutex_lock failed: %d\n", ret);
|
2018-03-28 17:49:34 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->curr_op != MAC802154_OP_RXENABLE)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2018-03-28 17:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mac802154_timercancel(priv);
|
|
|
|
mac802154_rxdisable(priv);
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxsem_post(&priv->opsem);
|
2018-03-28 17:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2018-03-28 17:49:34 +02:00
|
|
|
return OK;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&priv->lock);
|
2018-03-28 17:49:34 +02:00
|
|
|
return ret;
|
2019-02-27 15:41:08 +01:00
|
|
|
}
|