2017-06-14 08:49:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_assoc.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
|
|
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
|
|
|
|
#include "mac802154.h"
|
|
|
|
#include "mac802154_internal.h"
|
|
|
|
#include "mac802154_assoc.h"
|
|
|
|
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
static void mac802154_assoctimeout(FAR void *arg);
|
2019-08-19 17:17:01 +02:00
|
|
|
static void mac802154_extract_assocresp(FAR void *arg);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public MAC Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_req_associate
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-ASSOCIATE.request primitive allows a device to request an
|
|
|
|
* association with a coordinator. Confirmation is returned via the
|
|
|
|
* struct mac802154_maccb_s->conf_associate callback.
|
|
|
|
*
|
|
|
|
* On receipt of the MLME-ASSOCIATE.request primitive, the MLME of an
|
|
|
|
* unassociated device first updates the appropriate PHY and MAC PIB
|
|
|
|
* attributes, as described in 5.1.3.1, and then generates an association
|
|
|
|
* request command, as defined in 5.3.1 [1] pg.80
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mac802154_req_associate(MACHANDLE mac,
|
|
|
|
FAR struct ieee802154_assoc_req_s *req)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)mac;
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc;
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
int ret;
|
2017-06-28 04:01:40 +02:00
|
|
|
int i;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
if (req->coordaddr.mode == IEEE802154_ADDRMODE_NONE)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-09-17 18:46:23 +02:00
|
|
|
/* Get exclusive access to the operation semaphore. This must happen before
|
2019-02-27 15:41:08 +01:00
|
|
|
* 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.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
2017-06-22 06:48:02 +02:00
|
|
|
ret = mac802154_takesem(&priv->opsem, true);
|
2017-06-14 08:49:27 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_ASSOC;
|
|
|
|
priv->curr_cmd = IEEE802154_CMD_ASSOC_REQ;
|
|
|
|
|
|
|
|
/* Get exclusive access to the MAC */
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
ret = mac802154_lock(priv, true);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
mac802154_givesem(&priv->opsem);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Set the channel and channel page of the PHY layer */
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_setchannel(priv, req->chan);
|
|
|
|
mac802154_setchpage(priv, req->chpage);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
/* Set the coordinator address attributes */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_setcoordaddr(priv, &req->coordaddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
/* Copy the coordinator PAN ID to our PAN ID */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_setpanid(priv, req->coordaddr.panid);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Copy in the capabilities information bitfield */
|
|
|
|
|
2017-07-12 06:53:04 +02:00
|
|
|
if (req->capabilities.devtype)
|
|
|
|
{
|
|
|
|
mac802154_setdevmode(priv, IEEE802154_DEVMODE_COORD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mac802154_setdevmode(priv, IEEE802154_DEVMODE_ENDPOINT);
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-30 11:26:32 +02:00
|
|
|
mac802154_setrxonidle(priv, req->capabilities.rxonidle);
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Allocate an IOB to put the frame in */
|
|
|
|
|
2019-08-17 00:42:25 +02:00
|
|
|
iob = iob_alloc(false, IOBUSER_WIRELESS_MAC802154);
|
2017-06-14 08:49:27 +02:00
|
|
|
DEBUGASSERT(iob != NULL);
|
|
|
|
|
|
|
|
iob->io_flink = NULL;
|
|
|
|
iob->io_len = 0;
|
|
|
|
iob->io_offset = 0;
|
|
|
|
iob->io_pktlen = 0;
|
|
|
|
|
|
|
|
/* Allocate the txdesc, waiting if necessary */
|
|
|
|
|
|
|
|
ret = mac802154_txdesc_alloc(priv, &txdesc, true);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-08-17 00:42:25 +02:00
|
|
|
iob_free(iob, IOBUSER_WIRELESS_MAC802154);
|
2017-07-08 05:31:13 +02:00
|
|
|
mac802154_unlock(priv)
|
2017-06-22 06:48:02 +02:00
|
|
|
mac802154_givesem(&priv->opsem);
|
2017-06-14 08:49:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a uin16_t reference to the first two bytes. ie frame control field */
|
|
|
|
|
2017-06-19 21:54:36 +02:00
|
|
|
iob->io_data[0] = 0;
|
|
|
|
iob->io_data[1] = 0;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-19 21:54:36 +02:00
|
|
|
IEEE802154_SETACKREQ(iob->io_data, 0);
|
|
|
|
IEEE802154_SETFTYPE(iob->io_data, 0, IEEE802154_FRAME_COMMAND);
|
2017-06-26 00:07:50 +02:00
|
|
|
IEEE802154_SETDADDRMODE(iob->io_data, 0, priv->pandesc.coordaddr.mode);
|
2017-06-19 21:54:36 +02:00
|
|
|
IEEE802154_SETSADDRMODE(iob->io_data, 0, IEEE802154_ADDRMODE_EXTENDED);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
iob->io_len = 2;
|
|
|
|
|
|
|
|
/* Each time a data or a MAC command frame is generated, the MAC sublayer
|
|
|
|
* shall copy the value of macDSN into the Sequence Number field of the MHR
|
|
|
|
* of the outgoing frame and then increment it by one. [1] pg. 40.
|
|
|
|
*/
|
|
|
|
|
|
|
|
iob->io_data[iob->io_len++] = priv->dsn++;
|
|
|
|
|
|
|
|
/* The Destination PAN Identifier field shall contain the identifier of the
|
|
|
|
* PAN to which to associate. [1] pg. 68
|
|
|
|
*/
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_putpanid(iob, priv->pandesc.coordaddr.panid);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* The Destination Address field shall contain the address from the beacon
|
|
|
|
* frame that was transmitted by the coordinator to which the association
|
|
|
|
* request command is being sent. [1] pg. 68
|
|
|
|
*/
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
if (priv->pandesc.coordaddr.mode == IEEE802154_ADDRMODE_SHORT)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_putsaddr(iob, priv->pandesc.coordaddr.saddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
2017-06-26 00:07:50 +02:00
|
|
|
else if (priv->pandesc.coordaddr.mode == IEEE802154_ADDRMODE_EXTENDED)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_puteaddr(iob, priv->pandesc.coordaddr.eaddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/* The Source PAN Identifier field shall contain the broadcast PAN identifier. */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_putsaddr(iob, &IEEE802154_SADDR_BCAST);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* The Source Address field shall contain the value of macExtendedAddress. */
|
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_puteaddr(iob, priv->addr.eaddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Copy in the Command Frame Identifier */
|
|
|
|
|
|
|
|
iob->io_data[iob->io_len++] = IEEE802154_CMD_ASSOC_REQ;
|
|
|
|
|
|
|
|
/* Copy in the capability information bits */
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
iob->io_data[iob->io_len] = 0;
|
2017-06-15 18:46:48 +02:00
|
|
|
iob->io_data[iob->io_len] |= (req->capabilities.devtype <<
|
2017-06-14 08:49:27 +02:00
|
|
|
IEEE802154_CAPABILITY_SHIFT_DEVTYPE);
|
2017-06-15 18:46:48 +02:00
|
|
|
iob->io_data[iob->io_len] |= (req->capabilities.powersource <<
|
2017-06-14 08:49:27 +02:00
|
|
|
IEEE802154_CAPABILITY_SHIFT_PWRSRC);
|
2017-06-15 18:46:48 +02:00
|
|
|
iob->io_data[iob->io_len] |= (req->capabilities.rxonidle <<
|
2017-06-14 08:49:27 +02:00
|
|
|
IEEE802154_CAPABILITY_SHIFT_RXONIDLE);
|
2017-06-15 18:46:48 +02:00
|
|
|
iob->io_data[iob->io_len] |= (req->capabilities.security <<
|
2017-06-14 08:49:27 +02:00
|
|
|
IEEE802154_CAPABILITY_SHIFT_SECURITY);
|
2017-06-15 18:46:48 +02:00
|
|
|
iob->io_data[iob->io_len] |= (req->capabilities.allocaddr <<
|
2017-06-14 08:49:27 +02:00
|
|
|
IEEE802154_CAPABILITY_SHIFT_ALLOCADDR);
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
iob->io_len++;
|
|
|
|
|
|
|
|
txdesc->frame = iob;
|
|
|
|
txdesc->frametype = IEEE802154_FRAME_COMMAND;
|
2019-08-10 20:27:49 +02:00
|
|
|
txdesc->ackreq = true;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/* Save a copy of the destination addressing infromation into the tx
|
|
|
|
* descriptor. We only do this for commands to help with handling their
|
|
|
|
* progession.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
memcpy(&txdesc->destaddr, &req->coordaddr,
|
|
|
|
sizeof(struct ieee802154_addr_s));
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Save a reference of the tx descriptor */
|
|
|
|
|
|
|
|
priv->cmd_desc = txdesc;
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/* Search the list of PAN descriptors, that would have been populated by
|
|
|
|
* the latest scan procedure. If we have seen a beacon from the
|
|
|
|
* coordinator that we are about to associate with, we can check the
|
|
|
|
* beacon order to determine whether we can send the command during the
|
|
|
|
* CAP. If we haven't received a beacon frame from the desired
|
|
|
|
* coordinator address, we have to just send the frame out immediately.
|
2017-06-28 04:01:40 +02:00
|
|
|
*/
|
2017-07-03 18:08:49 +02:00
|
|
|
|
2017-06-28 04:01:40 +02:00
|
|
|
for (i = 0; i < priv->npandesc; i++)
|
|
|
|
{
|
|
|
|
/* Check to make sure the beacon is from the same channel as the request */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-28 04:01:40 +02:00
|
|
|
if (req->chan != priv->pandescs[i].chan)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(&req->coordaddr, &priv->pandescs[i].coordaddr,
|
|
|
|
sizeof(struct ieee802154_addr_s)) == 0)
|
|
|
|
{
|
|
|
|
wlinfo("Found matching beacon to use for settings\n");
|
|
|
|
|
|
|
|
/* We have a beacon frame from this coordinator, we can set the
|
|
|
|
* sfspec and send accordingly.
|
|
|
|
*/
|
2017-07-03 18:08:49 +02:00
|
|
|
|
2017-06-28 04:01:40 +02:00
|
|
|
/* Copy in the new superframe spec */
|
|
|
|
|
|
|
|
memcpy(&priv->sfspec, &priv->pandescs[i].sfspec,
|
|
|
|
sizeof(struct ieee802154_superframespec_s));
|
|
|
|
|
|
|
|
/* Tell the radio layer about the superframe spec update */
|
|
|
|
|
|
|
|
priv->radio->sfupdate(priv->radio, &priv->pandescs[i].sfspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->sfspec.beaconorder == 15)
|
|
|
|
{
|
|
|
|
wlinfo("Transmitting assoc request\n");
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-28 04:01:40 +02:00
|
|
|
/* Association Request command gets sent out immediately */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-28 04:01:40 +02:00
|
|
|
priv->radio->txdelayed(priv->radio, txdesc, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wlinfo("Queuing assoc request for CAP\n");
|
|
|
|
|
|
|
|
/* Link the transaction into the CSMA transaction list */
|
|
|
|
|
|
|
|
sq_addlast((FAR sq_entry_t *)txdesc, &priv->csma_queue);
|
|
|
|
|
|
|
|
/* Notify the radio driver that there is data available */
|
|
|
|
|
|
|
|
priv->radio->txnotify(priv->radio, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We no longer need to have the MAC layer locked. */
|
|
|
|
|
2017-07-08 05:31:13 +02:00
|
|
|
mac802154_unlock(priv)
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_resp_associate
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The MLME-ASSOCIATE.response primitive is used to initiate a response to
|
|
|
|
* an MLME-ASSOCIATE.indication primitive.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mac802154_resp_associate(MACHANDLE mac,
|
|
|
|
FAR struct ieee802154_assoc_resp_s *resp)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)mac;
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc;
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
int ret;
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Allocate an IOB to put the frame in */
|
|
|
|
|
2019-08-17 00:42:25 +02:00
|
|
|
iob = iob_alloc(false, IOBUSER_WIRELESS_MAC802154);
|
2017-06-14 08:49:27 +02:00
|
|
|
DEBUGASSERT(iob != NULL);
|
|
|
|
|
|
|
|
iob->io_flink = NULL;
|
|
|
|
iob->io_len = 0;
|
|
|
|
iob->io_offset = 0;
|
|
|
|
iob->io_pktlen = 0;
|
|
|
|
|
|
|
|
/* The Destination Addressing Mode and Source Addressing Mode fields shall
|
|
|
|
* each be set to indicate extended addressing.
|
|
|
|
*
|
|
|
|
* The Frame Pending field shall be set to zero and ignored upon reception,
|
|
|
|
* and the AR field shall be set to one.
|
|
|
|
*
|
|
|
|
* The PAN ID Compression field shall be set to one. [1] pg. 69
|
|
|
|
*/
|
|
|
|
|
2017-06-19 21:54:36 +02:00
|
|
|
iob->io_data[0] = 0;
|
|
|
|
iob->io_data[1] = 0;
|
|
|
|
IEEE802154_SETACKREQ(iob->io_data, 0);
|
|
|
|
IEEE802154_SETPANIDCOMP(iob->io_data, 0);
|
|
|
|
IEEE802154_SETFTYPE(iob->io_data, 0, IEEE802154_FRAME_COMMAND);
|
|
|
|
IEEE802154_SETDADDRMODE(iob->io_data, 0, IEEE802154_ADDRMODE_EXTENDED);
|
|
|
|
IEEE802154_SETSADDRMODE(iob->io_data, 0, IEEE802154_ADDRMODE_EXTENDED);
|
2017-06-14 08:49:27 +02:00
|
|
|
iob->io_len = 2;
|
|
|
|
|
|
|
|
/* Each time a data or a MAC command frame is generated, the MAC sublayer
|
|
|
|
* shall copy the value of macDSN into the Sequence Number field of the MHR
|
|
|
|
* of the outgoing frame and then increment it by one. [1] pg. 40.
|
|
|
|
*/
|
|
|
|
|
|
|
|
iob->io_data[iob->io_len++] = priv->dsn++;
|
|
|
|
|
|
|
|
/* In accordance with this value of the PAN ID Compression field, the
|
2019-02-27 15:41:08 +01:00
|
|
|
* Destination PAN Identifier field shall contain the value of macPANId,
|
|
|
|
* while the Source PAN Identifier field shall be omitted. [1] pg. 69
|
2017-06-15 18:46:48 +02:00
|
|
|
*/
|
2017-06-26 19:03:44 +02:00
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_putpanid(iob, priv->addr.panid);
|
2017-06-26 19:03:44 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* The Destination Address field shall contain the extended address of the
|
2019-02-27 15:41:08 +01:00
|
|
|
* device requesting association. [1] pg. 69
|
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_puteaddr(iob, resp->devaddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* The Source Address field shall contain the value of macExtendedAddress. */
|
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_puteaddr(iob, priv->addr.eaddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Copy in the Command Frame Identifier */
|
|
|
|
|
|
|
|
iob->io_data[iob->io_len++] = IEEE802154_CMD_ASSOC_RESP;
|
|
|
|
|
|
|
|
/* Copy in the assigned short address */
|
|
|
|
|
2017-06-15 19:01:19 +02:00
|
|
|
if (resp->status == IEEE802154_STATUS_SUCCESS)
|
|
|
|
{
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_putsaddr(iob, resp->assocsaddr);
|
2017-06-15 19:01:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_putsaddr(iob, &IEEE802154_SADDR_UNSPEC);
|
2017-06-15 19:01:19 +02:00
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Copy in the association status */
|
|
|
|
|
|
|
|
iob->io_data[iob->io_len++] = resp->status;
|
|
|
|
|
|
|
|
/* Get exclusive access to the MAC */
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-07-08 05:31:13 +02:00
|
|
|
ret = mac802154_lock(priv, true);
|
2017-06-14 08:49:27 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-08-17 00:42:25 +02:00
|
|
|
iob_free(iob, IOBUSER_WIRELESS_MAC802154);
|
2017-06-14 08:49:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the txdesc, waiting if necessary */
|
|
|
|
|
|
|
|
ret = mac802154_txdesc_alloc(priv, &txdesc, true);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-08-17 00:42:25 +02:00
|
|
|
iob_free(iob, IOBUSER_WIRELESS_MAC802154);
|
2017-07-08 05:31:13 +02:00
|
|
|
mac802154_unlock(priv)
|
2017-06-14 08:49:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
txdesc->frame = iob;
|
|
|
|
txdesc->frametype = IEEE802154_FRAME_COMMAND;
|
2019-08-10 20:27:49 +02:00
|
|
|
txdesc->ackreq = true;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
txdesc->destaddr.mode = IEEE802154_ADDRMODE_EXTENDED;
|
2017-06-19 11:55:28 +02:00
|
|
|
IEEE802154_PANIDCOPY(txdesc->destaddr.panid, priv->addr.panid);
|
|
|
|
IEEE802154_EADDRCOPY(txdesc->destaddr.eaddr, resp->devaddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
mac802154_setupindirect(priv, txdesc);
|
|
|
|
|
2017-07-08 05:31:13 +02:00
|
|
|
mac802154_unlock(priv)
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Internal MAC Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_txdone_assocreq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle the completion (success/failure) of transmitting an association
|
|
|
|
* request command.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called with the MAC locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void mac802154_txdone_assocreq(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc)
|
|
|
|
{
|
|
|
|
enum ieee802154_status_e status;
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *primitive =
|
|
|
|
(FAR struct ieee802154_primitive_s *)txdesc->conf;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
if (txdesc->conf->status != IEEE802154_STATUS_SUCCESS)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
/* if the association request command cannot be sent due to a
|
|
|
|
* channel access failure, the MAC sublayer shall notify the next
|
|
|
|
* higher layer. [1] pg. 33
|
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* We can actually high-jack the data conf notification since it
|
2017-11-01 21:15:21 +01:00
|
|
|
* is allocated as an ieee80215_primitive_s anyway. Before we overwrite
|
2017-06-14 08:49:27 +02:00
|
|
|
* any data though, we need to get the status from the data
|
|
|
|
* confirmation as that is the method we use to get the reason
|
|
|
|
* why the tx failed from the radio layer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
status = txdesc->conf->status;
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->type = IEEE802154_PRIMITIVE_CONF_ASSOC;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->u.assocconf.status = status;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* The short device address allocated by the coordinator on
|
|
|
|
* successful association. This parameter will be equal to 0xffff
|
|
|
|
* if the association attempt was unsuccessful. [1] pg. 81
|
|
|
|
*/
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
IEEE802154_SADDRCOPY(primitive->u.assocconf.saddr,
|
|
|
|
&IEEE802154_SADDR_UNSPEC);
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* We are now done the operation, unlock the semaphore */
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
|
|
|
priv->cmd_desc = NULL;
|
2017-06-22 06:48:02 +02:00
|
|
|
mac802154_givesem(&priv->opsem);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Release the MAC, call the callback, get exclusive access again */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_notify(priv, primitive);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* On receipt of the acknowledgment to the association request
|
|
|
|
* command, the device shall wait for at most macResponseWaitTime
|
|
|
|
* for the coordinator to make its association decision; the PIB
|
|
|
|
* attribute macResponseWaitTime is a network-topology-dependent
|
|
|
|
* parameter and may be set to match the specific requirements of
|
|
|
|
* the network that a device is trying to join. If the device is
|
|
|
|
* tracking the beacon, it shall attempt to extract the association
|
|
|
|
* response command from the coordinator whenever it is indicated in
|
|
|
|
* the beacon frame. If the device is not tracking the beacon, it
|
|
|
|
* shall attempt to extract the association response command from
|
|
|
|
* the coordinator after macResponseWaitTime. [1] pg. 34
|
|
|
|
*/
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
if (priv->sfspec.beaconorder < 15)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
/* We are tracking the beacon, so we should see our address in the
|
2019-02-27 15:41:08 +01:00
|
|
|
* beacon frame within macResponseWaitTime if the coordinator is
|
|
|
|
* going to respond. Setup a timeout for macResponseWaitTime so
|
|
|
|
* that we can inform the next highest layer if the association
|
|
|
|
* attempt fails due to NO_DATA.
|
2017-06-30 11:26:32 +02:00
|
|
|
*
|
|
|
|
* TODO: The standard defines macResponseWaitTime as:
|
2019-02-27 15:41:08 +01:00
|
|
|
* The maximum time, in multiples of aBaseSuperframeDuration, a
|
|
|
|
* device shall wait for a response command frame to be available
|
|
|
|
* following a request command frame.
|
2017-06-30 11:26:32 +02:00
|
|
|
*
|
|
|
|
* However, on beacon-enabled networks, it seems the maximum value
|
2019-02-27 15:41:08 +01:00
|
|
|
* isn't really that large of a value, AKA: assoc always fails
|
|
|
|
* from timeout even though everything is working as expected.
|
|
|
|
* The definition does say after we've sent a data request, which
|
|
|
|
* we, haven't sent yet, but we do need a timeout for association
|
|
|
|
* in general. Not sure what the correct answer is. For now, I am
|
|
|
|
* going to change the way macResponseWaitTime is used with beacon-
|
|
|
|
* enabled networks and make the timeout (BI * macResponseWaitTime)
|
|
|
|
* where BI is Beacon Interval = aBaseSuperframeDuration *
|
|
|
|
* 2^macBeaconOrder
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-07-01 23:04:02 +02:00
|
|
|
wlinfo("Starting timeout timer\n");
|
2017-06-17 20:56:42 +02:00
|
|
|
mac802154_timerstart(priv, (priv->resp_waittime *
|
2019-02-27 15:41:08 +01:00
|
|
|
(IEEE802154_BASE_SUPERFRAME_DURATION *
|
|
|
|
(1 << priv->sfspec.beaconorder))),
|
2017-06-30 11:26:32 +02:00
|
|
|
mac802154_assoctimeout);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-30 11:26:32 +02:00
|
|
|
/* Make sure the coordinator address mode is not set to none. This
|
|
|
|
* shouldn't happen since the association request should have set
|
|
|
|
* the mode to short or extended
|
2017-06-17 20:56:42 +02:00
|
|
|
*/
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
DEBUGASSERT(priv->pandesc.coordaddr.mode !=
|
|
|
|
IEEE802154_ADDRMODE_NONE);
|
2017-06-17 20:56:42 +02:00
|
|
|
|
2019-08-19 17:17:01 +02:00
|
|
|
/* Off-load extracting the Association Response to the work queue to
|
|
|
|
* avoid locking up the calling thread.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
2019-08-19 17:17:01 +02:00
|
|
|
DEBUGASSERT(work_available(&priv->macop_work));
|
|
|
|
work_queue(LPWORK, &priv->macop_work, mac802154_extract_assocresp,
|
|
|
|
priv, 0);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
2017-06-26 06:58:41 +02:00
|
|
|
/* Deallocate the data conf notification as it is no longer needed. */
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
ieee802154_primitive_free(primitive);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_txdone_datareq_assoc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle the completion (success/failure) of transmitting a data request
|
|
|
|
* command in an effort to extract the association response from the
|
|
|
|
* coordinator.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called with the MAC locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void mac802154_txdone_datareq_assoc(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc)
|
|
|
|
{
|
|
|
|
enum ieee802154_status_e status;
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *primitive =
|
|
|
|
(FAR struct ieee802154_primitive_s *)txdesc->conf;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* If the data request failed to be sent, notify the next layer
|
|
|
|
* that the association has failed.
|
|
|
|
* OR
|
|
|
|
* On receipt of the Ack frame with the Frame Pending field set
|
|
|
|
* to zero, the device shall conclude that there are no data
|
|
|
|
* pending at the coordinator. [1] pg. 43
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (primitive->u.dataconf.status != IEEE802154_STATUS_SUCCESS ||
|
2017-06-14 08:49:27 +02:00
|
|
|
txdesc->framepending == 0)
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
if (primitive->u.dataconf.status != IEEE802154_STATUS_SUCCESS)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
status = primitive->u.dataconf.status;
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the device does not extract an association response
|
|
|
|
* command frame from the coordinator within macResponseWaitTime,
|
|
|
|
* the MLME shall issue the MLME-ASSOCIATE.confirm primitive,
|
|
|
|
* as described in 6.2.2.4, with a status of NO_DATA, and the
|
|
|
|
* association attempt shall be deemed a failure. [1] pg. 34
|
|
|
|
*/
|
|
|
|
|
|
|
|
status = IEEE802154_STATUS_NO_DATA;
|
|
|
|
}
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->type = IEEE802154_PRIMITIVE_CONF_ASSOC;
|
|
|
|
primitive->u.assocconf.status = status;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* The short device address allocated by the coordinator on
|
|
|
|
* successful association. This parameter will be equal to 0xffff
|
|
|
|
* if the association attempt was unsuccessful. [1] pg. 81
|
|
|
|
*/
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
IEEE802154_SADDRCOPY(primitive->u.assocconf.saddr,
|
|
|
|
&IEEE802154_SADDR_UNSPEC);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* We are now done the operation, and can release the command */
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
|
|
|
priv->cmd_desc = NULL;
|
2017-06-22 06:48:02 +02:00
|
|
|
mac802154_givesem(&priv->opsem);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_notify(priv, primitive);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* On receipt of the acknowledgment frame with the Frame
|
|
|
|
* Pending field set to one, a device shall enable its
|
|
|
|
* receiver for at most macMaxFrameTotalWaitTime to receive
|
|
|
|
* the corresponding data frame from the coordinator. [1] pg.43
|
|
|
|
*/
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
mac802154_rxenable(priv);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/* If we are on a beacon-enabled network, we already have the
|
|
|
|
* association timeout timer scheduled. So we only need to start the
|
|
|
|
* timeout timer if we are operating on a non-beacon enabled network.
|
2017-06-30 11:26:32 +02:00
|
|
|
*
|
|
|
|
* NOTE: This may create a bad side-effect where the receiver is on
|
|
|
|
* for longer than it needs to be during association. Revisit if power
|
|
|
|
* is ever an issue.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-30 11:26:32 +02:00
|
|
|
if (priv->sfspec.beaconorder == 15)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Start a timer, if we receive the data frame, we will cancel
|
|
|
|
* the timer, otherwise it will expire and we will notify the
|
|
|
|
* next highest layer of the failure.
|
|
|
|
*/
|
|
|
|
|
2017-07-01 23:04:02 +02:00
|
|
|
wlinfo("Starting timeout timer\n");
|
2017-06-30 11:26:32 +02:00
|
|
|
mac802154_timerstart(priv, priv->max_frame_waittime,
|
|
|
|
mac802154_assoctimeout);
|
|
|
|
|
|
|
|
}
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-06-26 06:58:41 +02:00
|
|
|
/* Deallocate the data conf notification as it is no longer needed. */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
ieee802154_primitive_free(primitive);
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_rx_assocreq
|
|
|
|
*
|
|
|
|
* Description:
|
2017-06-15 18:46:48 +02:00
|
|
|
* Function called from the generic RX Frame worker to parse and handle the
|
2017-06-14 08:49:27 +02:00
|
|
|
* reception of an Association Request MAC command frame.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void mac802154_rx_assocreq(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR struct ieee802154_data_ind_s *ind)
|
|
|
|
{
|
|
|
|
FAR struct iob_s *frame = ind->frame;
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *primitive;
|
2017-06-14 08:49:27 +02:00
|
|
|
uint8_t cap;
|
|
|
|
|
|
|
|
/* Allocate a notification to pass to the next highest layer */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive = ieee802154_primitive_allocate();
|
|
|
|
primitive->type = IEEE802154_PRIMITIVE_IND_ASSOC;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Association Requests should always be sent from a device with source
|
|
|
|
* addressing mode set to extended mode. Throw out any request received
|
|
|
|
* without addressing set to extended
|
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
if (ind->src.mode != IEEE802154_ADDRMODE_EXTENDED)
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
return;
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the extended address of the requesting device */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
IEEE802154_EADDRCOPY(primitive->u.assocind.devaddr, ind->src.eaddr);
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Copy in the capability information from the frame to the notification */
|
|
|
|
|
|
|
|
cap = frame->io_data[frame->io_offset++];
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->u.assocind.capabilities.devtype =
|
2017-06-14 08:49:27 +02:00
|
|
|
(cap >> IEEE802154_CAPABILITY_SHIFT_DEVTYPE) & 0x01;
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->u.assocind.capabilities.powersource =
|
2017-06-14 08:49:27 +02:00
|
|
|
(cap >> IEEE802154_CAPABILITY_SHIFT_PWRSRC) & 0x01;
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->u.assocind.capabilities.rxonidle =
|
2017-06-14 08:49:27 +02:00
|
|
|
(cap >> IEEE802154_CAPABILITY_SHIFT_RXONIDLE) & 0x01;
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->u.assocind.capabilities.security =
|
2017-06-14 08:49:27 +02:00
|
|
|
(cap >> IEEE802154_CAPABILITY_SHIFT_SECURITY) & 0x01;
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->u.assocind.capabilities.allocaddr =
|
2017-06-14 08:49:27 +02:00
|
|
|
(cap >> IEEE802154_CAPABILITY_SHIFT_ALLOCADDR) & 0x01;
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE802154_SECURITY
|
2019-02-27 15:41:08 +01:00
|
|
|
# error Missing security logic
|
2017-06-14 08:49:27 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Get exclusive access to the MAC */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_lock(priv, false);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Notify the next highest layer of the association status */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_notify(priv, primitive);
|
2017-07-08 05:31:13 +02:00
|
|
|
mac802154_unlock(priv)
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_rx_assocresp
|
|
|
|
*
|
|
|
|
* Description:
|
2017-06-15 18:46:48 +02:00
|
|
|
* Function called from the generic RX Frame worker to parse and handle the
|
2017-06-14 08:49:27 +02:00
|
|
|
* reception of an Association Response MAC command frame.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void mac802154_rx_assocresp(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR struct ieee802154_data_ind_s *ind)
|
|
|
|
{
|
2017-06-19 11:55:28 +02:00
|
|
|
FAR struct iob_s *iob = ind->frame;
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *primitive;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/* Check if we are performing an Association operation, if not, we will
|
|
|
|
* just ignore the frame.
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->curr_op != MAC802154_OP_ASSOC)
|
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
/* This situation can occur in a beacon-enabled network if the
|
|
|
|
* association request has timed out, but the Coordinator has already
|
|
|
|
* queued the response. Which means the beacon would contain our
|
|
|
|
* address, causing us to extract the response.
|
2017-06-30 11:26:32 +02:00
|
|
|
*
|
2019-02-27 15:41:08 +01:00
|
|
|
* TODO: What is supposed to happen in this situation. Are we supposed
|
|
|
|
* to accept the request? Are we supposed to Disassociate with the
|
|
|
|
* network as a convienience to the PAN Coordinator. So that it does
|
|
|
|
* not need to waste space holding our information?
|
2017-06-30 11:26:32 +02:00
|
|
|
*/
|
|
|
|
|
2017-07-01 23:04:02 +02:00
|
|
|
wlinfo("Ignoring association response frame\n");
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Cancel the timeout used if we didn't get a response */
|
|
|
|
|
|
|
|
mac802154_timercancel(priv);
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Allocate a notification to pass to the next highest layer */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive = ieee802154_primitive_allocate();
|
|
|
|
primitive->type = IEEE802154_PRIMITIVE_CONF_ASSOC;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Get exclusive access to the MAC */
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_lock(priv, false);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Parse the short address from the response */
|
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
mac802154_takesaddr(iob, priv->addr.saddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* Inform the radio of the address change */
|
|
|
|
|
2017-06-26 07:31:01 +02:00
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_SADDR,
|
2017-06-19 11:55:28 +02:00
|
|
|
(FAR union ieee802154_attr_u *)priv->addr.saddr);
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/* A Short Address field value equal to 0xfffe shall indicate that the
|
|
|
|
* device has been successfully associated with a PAN but has not been
|
|
|
|
* allocated a short address. In this case, the device shall communicate
|
|
|
|
* on the PAN using only its extended address. [1] pg. 70
|
2017-06-14 08:49:27 +02:00
|
|
|
*/
|
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
if (IEEE802154_SADDRCMP(priv->addr.saddr, &IEEE802154_SADDR_BCAST))
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
/* TODO: Figure out if this is sufficient */
|
|
|
|
|
|
|
|
priv->addr.mode = IEEE802154_ADDRMODE_SHORT;
|
|
|
|
}
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Parse the status from the response */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive->u.assocconf.status = iob->io_data[iob->io_offset++];
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (primitive->u.assocconf.status == IEEE802154_STATUS_SUCCESS)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
|
|
|
priv->isassoc = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->isassoc = false;
|
|
|
|
}
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
IEEE802154_SADDRCOPY(primitive->u.assocconf.saddr, priv->addr.saddr);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* We are no longer performing the association operation */
|
|
|
|
|
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
|
|
|
priv->cmd_desc = NULL;
|
2017-06-22 06:48:02 +02:00
|
|
|
mac802154_givesem(&priv->opsem);
|
2017-06-30 11:26:32 +02:00
|
|
|
mac802154_rxdisable(priv);
|
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Notify the next highest layer of the association status */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_notify(priv, primitive);
|
|
|
|
mac802154_unlock(priv)
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-06-26 00:07:50 +02:00
|
|
|
* Name: mac802154_assoctimeout
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2019-02-27 15:41:08 +01:00
|
|
|
* Function registered with MAC timer that gets called via the work queue
|
|
|
|
* to handle a timeout for extracting the Association Response from the
|
|
|
|
* Coordinator.
|
2017-06-14 08:49:27 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
static void mac802154_assoctimeout(FAR void *arg)
|
2017-06-14 08:49:27 +02:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)arg;
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *primitive;
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
/* If there is work scheduled for the rxframe_worker, we want to reschedule
|
|
|
|
* this work, so that we make sure if the frame we were waiting for was just
|
|
|
|
* received, we don't timeout
|
|
|
|
*/
|
2017-07-10 19:04:27 +02:00
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
if (!work_available(&priv->rx_work))
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
work_queue(HPWORK, &priv->timer_work, mac802154_assoctimeout, priv, 0);
|
2017-07-10 05:55:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
DEBUGASSERT(priv->curr_op == MAC802154_OP_ASSOC);
|
|
|
|
|
|
|
|
/* If the device does not extract an association response command
|
|
|
|
* frame from the coordinator within macResponseWaitTime, the MLME
|
|
|
|
* shall issue the MLME-ASSOCIATE.confirm primitive, as described
|
|
|
|
* in 6.2.2.4, with a status of NO_DATA, and the association attempt
|
|
|
|
* shall be deemed a failure. [1] pg. 33
|
|
|
|
*/
|
2017-06-15 18:46:48 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
/* Allocate a notification struct to pass to the next highest layer.
|
|
|
|
* Don't allow EINTR to interrupt.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive = ieee802154_primitive_allocate();
|
|
|
|
primitive->type = IEEE802154_PRIMITIVE_CONF_ASSOC;
|
|
|
|
|
|
|
|
primitive->u.assocconf.status = IEEE802154_STATUS_NO_DATA;
|
2019-02-27 15:41:08 +01:00
|
|
|
IEEE802154_SADDRCOPY(primitive->u.assocconf.saddr,
|
|
|
|
&IEEE802154_SADDR_UNSPEC);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
|
|
|
/* We are no longer performing the association operation */
|
2017-06-30 11:26:32 +02:00
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
priv->curr_op = MAC802154_OP_NONE;
|
2017-06-26 00:07:50 +02:00
|
|
|
priv->cmd_desc = NULL;
|
2017-06-22 06:48:02 +02:00
|
|
|
mac802154_givesem(&priv->opsem);
|
2017-06-30 11:26:32 +02:00
|
|
|
mac802154_rxdisable(priv);
|
2017-06-14 08:49:27 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
mac802154_lock(priv, false);
|
|
|
|
mac802154_notify(priv, primitive);
|
2017-07-08 05:31:13 +02:00
|
|
|
mac802154_unlock(priv)
|
2017-06-14 08:49:27 +02:00
|
|
|
}
|
2019-08-19 17:17:01 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_extract_assocrespj
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create and send a Data request command to extract the Association response
|
|
|
|
* from the Coordinator.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called with the MAC unlocked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void mac802154_extract_assocresp(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_privmac_s *priv =
|
|
|
|
(FAR struct ieee802154_privmac_s *)arg;
|
|
|
|
FAR struct ieee802154_txdesc_s *respdesc;
|
|
|
|
|
|
|
|
mac802154_lock(priv, false);
|
|
|
|
|
|
|
|
mac802154_txdesc_alloc(priv, &respdesc, false);
|
|
|
|
|
|
|
|
mac802154_createdatareq(priv, &priv->pandesc.coordaddr,
|
|
|
|
IEEE802154_ADDRMODE_EXTENDED, respdesc);
|
|
|
|
|
|
|
|
mac802154_unlock(priv)
|
|
|
|
|
|
|
|
priv->curr_cmd = IEEE802154_CMD_DATA_REQ;
|
|
|
|
|
|
|
|
priv->radio->txdelayed(priv->radio, respdesc,
|
|
|
|
(priv->resp_waittime*IEEE802154_BASE_SUPERFRAME_DURATION));
|
2019-09-17 18:46:23 +02:00
|
|
|
}
|