2017-06-14 08:49:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_start.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>
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-04-23 11:51:21 +02:00
|
|
|
* Public Functions
|
2017-06-14 08:49:27 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_req_start
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-START.request primitive makes a request for the device to start
|
|
|
|
* using a new superframe configuration. Confirmation is returned
|
|
|
|
* via the struct mac802154_maccb_s->conf_start callback.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
int mac802154_req_start(MACHANDLE mac,
|
|
|
|
FAR struct ieee802154_start_req_s *req)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)mac;
|
|
|
|
int 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);
|
2017-06-14 08:49:27 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* When the CoordRealignment parameter is set to TRUE, the coordinator
|
2020-04-23 11:51:21 +02:00
|
|
|
* attempts to transmit a coordinator realignment command frame as
|
|
|
|
* described in 5.1.2.3.2. If the transmission of the coordinator
|
|
|
|
* realignment command fails due to a channel access failure, the MLME
|
|
|
|
* will not make any changes to the superframe configuration. (i.e., no
|
|
|
|
* PIB attributes will be changed). If the coordinator realignment
|
|
|
|
* command is successfully transmitted, the MLME updates the PIB
|
|
|
|
* attributes BeaconOrder, SuperframeOrder, PANId, ChannelPage, and
|
|
|
|
* ChannelNumber parameters. [1] pg. 106
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (req->coordrealign)
|
|
|
|
{
|
|
|
|
/* TODO: Finish the realignment functionality */
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Set the PANID attribute */
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_setpanid(priv, req->panid);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-20 18:57:24 +02:00
|
|
|
/* Tell the radio layer to set the channel number and channel page */
|
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
priv->radio->setattr(priv->radio,
|
|
|
|
IEEE802154_ATTR_PHY_CHAN,
|
|
|
|
(FAR const union ieee802154_attr_u *)&req->chan);
|
|
|
|
priv->radio->setattr(priv->radio,
|
|
|
|
IEEE802154_ATTR_PHY_CURRENT_PAGE,
|
|
|
|
(FAR const union ieee802154_attr_u *)&req->chpage);
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-20 18:57:24 +02:00
|
|
|
/* The address used in the Source Address field of the beacon frame shall
|
|
|
|
* contain the value of macExtendedAddress if macShortAddress is equal to
|
|
|
|
* 0xfffe or macShortAddress otherwise. [1] pg. 32
|
|
|
|
*/
|
2017-06-26 19:03:44 +02:00
|
|
|
|
2017-06-20 18:57:24 +02:00
|
|
|
if (IEEE802154_SADDRCMP(priv->addr.saddr, &IEEE802154_SADDR_BCAST))
|
|
|
|
{
|
|
|
|
priv->addr.mode = IEEE802154_ADDRMODE_EXTENDED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->addr.mode = IEEE802154_ADDRMODE_SHORT;
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Set the beacon order */
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
if (req->beaconorder > 15)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->sfspec.beaconorder = req->beaconorder;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* The value of macSuperframeOrder shall be ignored if
|
|
|
|
* macBeaconOrder = 15. pg. 19
|
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
if (priv->sfspec.beaconorder < 15)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
/* Set the superframe order */
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
if (req->superframeorder > 15)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->sfspec.sforder = req->superframeorder;
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req->pancoord)
|
|
|
|
{
|
2017-07-13 09:17:05 +02:00
|
|
|
mac802154_setdevmode(priv, IEEE802154_DEVMODE_PANCOORD);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-13 09:17:05 +02:00
|
|
|
mac802154_setdevmode(priv, IEEE802154_DEVMODE_COORD);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->sfspec.pancoord = req->pancoord;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
if (priv->sfspec.beaconorder < 15)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
/* If the BeaconOrder parameter is less than 15, the MLME sets
|
|
|
|
* macBattLifeExt to the value of the BatteryLifeExtension parameter.
|
|
|
|
* If the BeaconOrder parameter equals 15, the value of the
|
|
|
|
* BatteryLifeExtension parameter is ignored. [1] pg. 106
|
2017-06-20 18:57:24 +02:00
|
|
|
*/
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->sfspec.ble = req->battlifeext;
|
2017-06-20 18:57:24 +02:00
|
|
|
|
|
|
|
/* For now we just set the CAP Slot to 15 */
|
2017-06-26 19:03:44 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->sfspec.final_capslot = 15;
|
2017-06-20 18:57:24 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* If the PAN coordinator parameter is set to TRUE, the MLME ignores
|
|
|
|
* the StartTime parameter and begins beacon transmissions immediately.
|
2017-06-20 18:57:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (req->pancoord)
|
|
|
|
{
|
|
|
|
/* Update the beacon frame to start sending */
|
|
|
|
|
|
|
|
mac802154_updatebeacon(priv);
|
|
|
|
|
|
|
|
/* Tell the radio to start transmitting beacon frames */
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->radio->beaconstart(priv->radio, &priv->sfspec,
|
2017-06-20 18:57:24 +02:00
|
|
|
&priv->beaconframe[priv->bf_ind]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* TODO: Finish non-PAN coordinator delayed start */
|
|
|
|
|
|
|
|
ret = -ENOTTY;
|
|
|
|
goto errout;
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2017-06-14 08:49:27 +02:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout:
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2017-06-14 08:49:27 +02:00
|
|
|
return ret;
|
2017-07-11 18:58:01 +02:00
|
|
|
}
|