2017-06-14 14:49:27 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_getset.c
|
|
|
|
*
|
2021-09-06 19:39:36 +08: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 14:49:27 +08: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 17:51:21 +08:00
|
|
|
* Public Functions
|
2017-06-14 14:49:27 +08: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 17:51:21 +08: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 14:49:27 +08: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 17:26:32 +08:00
|
|
|
{
|
|
|
|
IEEE802154_PANIDCOPY(attrval->mac.panid, priv->addr.panid);
|
|
|
|
}
|
2017-06-14 14:49:27 +08:00
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
|
2017-06-26 06:07:50 +08:00
|
|
|
case IEEE802154_ATTR_MAC_SADDR:
|
2017-06-30 17:26:32 +08:00
|
|
|
{
|
|
|
|
IEEE802154_SADDRCOPY(attrval->mac.saddr, priv->addr.saddr);
|
|
|
|
}
|
2017-06-14 14:49:27 +08:00
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
|
2017-06-26 06:07:50 +08:00
|
|
|
case IEEE802154_ATTR_MAC_EADDR:
|
2017-06-30 17:26:32 +08:00
|
|
|
{
|
|
|
|
IEEE802154_EADDRCOPY(attrval->mac.eaddr, priv->addr.eaddr);
|
|
|
|
}
|
2017-06-14 14:49:27 +08:00
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
|
2017-06-28 06:08:32 +08:00
|
|
|
case IEEE802154_ATTR_MAC_COORD_SADDR:
|
2017-06-30 17:26:32 +08:00
|
|
|
{
|
2020-04-23 17:51:21 +08:00
|
|
|
IEEE802154_SADDRCOPY(attrval->mac.coordsaddr,
|
|
|
|
priv->pandesc.coordaddr.saddr);
|
2017-06-30 17:26:32 +08:00
|
|
|
}
|
2017-06-28 06:08:32 +08:00
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
|
2017-06-28 06:08:32 +08:00
|
|
|
case IEEE802154_ATTR_MAC_COORD_EADDR:
|
2017-06-30 17:26:32 +08:00
|
|
|
{
|
2020-04-23 17:51:21 +08:00
|
|
|
IEEE802154_EADDRCOPY(attrval->mac.coordeaddr,
|
|
|
|
priv->pandesc.coordaddr.eaddr);
|
2017-06-30 17:26:32 +08:00
|
|
|
}
|
2017-06-28 06:08:32 +08:00
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
|
2017-06-14 14:49:27 +08:00
|
|
|
case IEEE802154_ATTR_MAC_DEVMODE:
|
2017-06-30 17:26:32 +08:00
|
|
|
{
|
|
|
|
attrval->mac.devmode = priv->devmode;
|
|
|
|
}
|
2017-06-14 14:49:27 +08:00
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
|
|
|
|
case IEEE802154_ATTR_MAC_RESPONSE_WAIT_TIME:
|
|
|
|
{
|
|
|
|
attrval->mac.resp_waittime = priv->resp_waittime;
|
|
|
|
}
|
2017-11-23 02:22:35 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IEEE802154_ATTR_MAC_PROMISCUOUS_MODE:
|
|
|
|
{
|
|
|
|
attrval->mac.promisc_mode = priv->promisc;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
|
2019-08-11 01:04:08 +08: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 14:49:27 +08:00
|
|
|
default:
|
2017-06-30 17:26:32 +08:00
|
|
|
{
|
2020-02-23 02:31:14 +08:00
|
|
|
/* The attribute may be handled solely in the radio driver, so pass
|
2017-06-30 17:26:32 +08:00
|
|
|
* it along.
|
|
|
|
*/
|
2017-06-14 14:49:27 +08:00
|
|
|
|
2017-06-30 17:26:32 +08:00
|
|
|
ret = priv->radio->getattr(priv->radio, attr, attrval);
|
|
|
|
}
|
2017-06-14 14:49:27 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-06-16 00:46:48 +08:00
|
|
|
|
2017-06-14 14:49:27 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_req_set
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-SET.request primitive attempts to write the given value to the
|
2017-06-16 00:46:48 +08:00
|
|
|
* indicated MAC PIB attribute.
|
2017-06-14 14:49:27 +08:00
|
|
|
*
|
2017-06-16 00:46:48 +08:00
|
|
|
* NOTE: The standard specifies that confirmation should be indicated via
|
2020-04-23 17:51:21 +08: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 14:49:27 +08: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 17:26:32 +08:00
|
|
|
int ret = IEEE802154_STATUS_SUCCESS;
|
2017-06-14 14:49:27 +08:00
|
|
|
|
|
|
|
switch (attr)
|
|
|
|
{
|
|
|
|
case IEEE802154_ATTR_MAC_PANID:
|
|
|
|
{
|
2017-06-26 06:07:50 +08:00
|
|
|
mac802154_setpanid(priv, attrval->mac.panid);
|
2017-06-14 14:49:27 +08:00
|
|
|
}
|
|
|
|
break;
|
2017-06-26 06:07:50 +08:00
|
|
|
case IEEE802154_ATTR_MAC_SADDR:
|
2017-06-14 14:49:27 +08:00
|
|
|
{
|
2017-06-26 06:07:50 +08:00
|
|
|
mac802154_setsaddr(priv, attrval->mac.saddr);
|
2017-06-14 14:49:27 +08:00
|
|
|
}
|
|
|
|
break;
|
2017-06-26 06:07:50 +08:00
|
|
|
case IEEE802154_ATTR_MAC_EADDR:
|
2017-06-14 14:49:27 +08:00
|
|
|
{
|
2019-08-11 02:25:13 +08:00
|
|
|
/* macExtendedAddress is a read-only attribute */
|
|
|
|
|
|
|
|
ret = IEEE802154_STATUS_DENIED;
|
2017-06-26 06:07:50 +08: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 14:49:27 +08:00
|
|
|
}
|
|
|
|
break;
|
2017-06-21 00:57:24 +08:00
|
|
|
case IEEE802154_ATTR_MAC_ASSOCIATION_PERMIT:
|
|
|
|
{
|
2017-06-26 06:07:50 +08:00
|
|
|
priv->sfspec.assocpermit = attrval->mac.assocpermit;
|
2017-06-21 00:57:24 +08:00
|
|
|
priv->beaconupdate = true;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
case IEEE802154_ATTR_MAC_RESPONSE_WAIT_TIME:
|
|
|
|
{
|
|
|
|
priv->resp_waittime = attrval->mac.resp_waittime;
|
|
|
|
}
|
2017-11-02 04:15:21 +08:00
|
|
|
break;
|
2017-06-30 17:26:32 +08:00
|
|
|
case IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE:
|
|
|
|
{
|
|
|
|
mac802154_setrxonidle(priv, attrval->mac.rxonidle);
|
|
|
|
}
|
2017-11-02 04:15:21 +08: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-11 01:04:08 +08:00
|
|
|
case IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES:
|
|
|
|
{
|
|
|
|
priv->maxretries = attrval->mac.max_retries;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-14 14:49:27 +08:00
|
|
|
default:
|
|
|
|
{
|
2020-02-23 02:31:14 +08:00
|
|
|
/* The attribute may be handled solely in the radio driver, so pass
|
2017-06-14 14:49:27 +08:00
|
|
|
* it along.
|
|
|
|
*/
|
|
|
|
|
2017-06-26 13:31:01 +08:00
|
|
|
ret = priv->radio->setattr(priv->radio, attr, attrval);
|
2017-06-14 14:49:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-04-23 17:51:21 +08:00
|
|
|
|
2017-06-14 14:49:27 +08:00
|
|
|
return ret;
|
2020-02-07 21:17:25 +08:00
|
|
|
}
|