2017-06-14 08:49:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_getset.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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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_get
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-GET.request primitive requests information about a given PIB
|
|
|
|
* attribute.
|
|
|
|
*
|
|
|
|
* NOTE: The standard specifies that the attribute value should be returned
|
2020-04-23 11:51:21 +02:00
|
|
|
* via the asynchronous MLME-GET.confirm primitive.
|
|
|
|
* However, in our implementation, we synchronously return the value
|
|
|
|
* immediately. Therefore, we merge the functionality of the
|
|
|
|
* MLME-GET.request and MLME-GET.confirm primitives together.
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mac802154_req_get(MACHANDLE mac, enum ieee802154_attr_e attr,
|
|
|
|
FAR union ieee802154_attr_u *attrval)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)mac;
|
|
|
|
int ret = IEEE802154_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
switch (attr)
|
|
|
|
{
|
|
|
|
case IEEE802154_ATTR_MAC_PANID:
|
2017-06-30 11:26:32 +02:00
|
|
|
{
|
|
|
|
IEEE802154_PANIDCOPY(attrval->mac.panid, priv->addr.panid);
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_SADDR:
|
2017-06-30 11:26:32 +02:00
|
|
|
{
|
|
|
|
IEEE802154_SADDRCOPY(attrval->mac.saddr, priv->addr.saddr);
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_EADDR:
|
2017-06-30 11:26:32 +02:00
|
|
|
{
|
|
|
|
IEEE802154_EADDRCOPY(attrval->mac.eaddr, priv->addr.eaddr);
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-28 00:08:32 +02:00
|
|
|
case IEEE802154_ATTR_MAC_COORD_SADDR:
|
2017-06-30 11:26:32 +02:00
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
IEEE802154_SADDRCOPY(attrval->mac.coordsaddr,
|
|
|
|
priv->pandesc.coordaddr.saddr);
|
2017-06-30 11:26:32 +02:00
|
|
|
}
|
2017-06-28 00:08:32 +02:00
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-28 00:08:32 +02:00
|
|
|
case IEEE802154_ATTR_MAC_COORD_EADDR:
|
2017-06-30 11:26:32 +02:00
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
IEEE802154_EADDRCOPY(attrval->mac.coordeaddr,
|
|
|
|
priv->pandesc.coordaddr.eaddr);
|
2017-06-30 11:26:32 +02:00
|
|
|
}
|
2017-06-28 00:08:32 +02:00
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
case IEEE802154_ATTR_MAC_DEVMODE:
|
2017-06-30 11:26:32 +02:00
|
|
|
{
|
|
|
|
attrval->mac.devmode = priv->devmode;
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
|
|
|
|
case IEEE802154_ATTR_MAC_RESPONSE_WAIT_TIME:
|
|
|
|
{
|
|
|
|
attrval->mac.resp_waittime = priv->resp_waittime;
|
|
|
|
}
|
2017-11-22 19:22:35 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IEEE802154_ATTR_MAC_PROMISCUOUS_MODE:
|
|
|
|
{
|
|
|
|
attrval->mac.promisc_mode = priv->promisc;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2019-08-10 19:04:08 +02:00
|
|
|
case IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES:
|
|
|
|
{
|
|
|
|
attrval->mac.max_retries = priv->maxretries;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE:
|
|
|
|
{
|
|
|
|
attrval->mac.rxonidle = priv->rxonidle;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
default:
|
2017-06-30 11:26:32 +02:00
|
|
|
{
|
2020-02-22 19:31:14 +01:00
|
|
|
/* The attribute may be handled solely in the radio driver, so pass
|
2017-06-30 11:26:32 +02:00
|
|
|
* it along.
|
|
|
|
*/
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-30 11:26:32 +02:00
|
|
|
ret = priv->radio->getattr(priv->radio, attr, attrval);
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_req_set
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-SET.request primitive attempts to write the given value to the
|
2017-06-15 18:46:48 +02:00
|
|
|
* indicated MAC PIB attribute.
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
2017-06-15 18:46:48 +02:00
|
|
|
* NOTE: The standard specifies that confirmation should be indicated via
|
2020-04-23 11:51:21 +02:00
|
|
|
* the asynchronous MLME-SET.confirm primitive.
|
|
|
|
* However, in our implementation we synchronously return the status from
|
|
|
|
* the request. Therefore, we do merge the functionality of the
|
|
|
|
* MLME-SET.request and MLME-SET.confirm primitives together.
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mac802154_req_set(MACHANDLE mac, enum ieee802154_attr_e attr,
|
|
|
|
FAR const union ieee802154_attr_u *attrval)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)mac;
|
2017-06-30 11:26:32 +02:00
|
|
|
int ret = IEEE802154_STATUS_SUCCESS;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
switch (attr)
|
|
|
|
{
|
|
|
|
case IEEE802154_ATTR_MAC_PANID:
|
|
|
|
{
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_setpanid(priv, attrval->mac.panid);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_SADDR:
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_setsaddr(priv, attrval->mac.saddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_EADDR:
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2019-08-10 20:25:13 +02:00
|
|
|
/* macExtendedAddress is a read-only attribute */
|
|
|
|
|
|
|
|
ret = IEEE802154_STATUS_DENIED;
|
2017-06-26 00:07:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE802154_ATTR_MAC_COORD_SADDR:
|
|
|
|
{
|
|
|
|
mac802154_setcoordsaddr(priv, attrval->mac.coordsaddr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IEEE802154_ATTR_MAC_COORD_EADDR:
|
|
|
|
{
|
|
|
|
mac802154_setcoordeaddr(priv, attrval->mac.coordeaddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-06-20 18:57:24 +02:00
|
|
|
case IEEE802154_ATTR_MAC_ASSOCIATION_PERMIT:
|
|
|
|
{
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->sfspec.assocpermit = attrval->mac.assocpermit;
|
2017-06-20 18:57:24 +02:00
|
|
|
priv->beaconupdate = true;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
case IEEE802154_ATTR_MAC_RESPONSE_WAIT_TIME:
|
|
|
|
{
|
|
|
|
priv->resp_waittime = attrval->mac.resp_waittime;
|
|
|
|
}
|
2017-11-01 21:15:21 +01:00
|
|
|
break;
|
2017-06-30 11:26:32 +02:00
|
|
|
case IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE:
|
|
|
|
{
|
|
|
|
mac802154_setrxonidle(priv, attrval->mac.rxonidle);
|
|
|
|
}
|
2017-11-01 21:15:21 +01:00
|
|
|
break;
|
|
|
|
case IEEE802154_ATTR_MAC_PROMISCUOUS_MODE:
|
|
|
|
{
|
|
|
|
ret = priv->radio->setattr(priv->radio, attr, attrval);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
priv->promisc = attrval->mac.promisc_mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-08-10 19:04:08 +02:00
|
|
|
case IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES:
|
|
|
|
{
|
|
|
|
priv->maxretries = attrval->mac.max_retries;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-14 08:49:27 +02:00
|
|
|
default:
|
|
|
|
{
|
2020-02-22 19:31:14 +01:00
|
|
|
/* The attribute may be handled solely in the radio driver, so pass
|
2017-06-14 08:49:27 +02:00
|
|
|
* it along.
|
|
|
|
*/
|
|
|
|
|
2017-06-26 07:31:01 +02:00
|
|
|
ret = priv->radio->setattr(priv->radio, attr, attrval);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-04-23 11:51:21 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
return ret;
|
2020-02-07 14:17:25 +01:00
|
|
|
}
|