2017-07-10 00:53:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_internal.h
|
|
|
|
*
|
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-07-10 00:53:08 +02:00
|
|
|
*
|
2021-09-06 13:39:36 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-07-10 00:53:08 +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-07-10 00:53:08 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __WIRELESS_IEEE802154__MAC802154_INTERNAL_H
|
|
|
|
#define __WIRELESS_IEEE802154__MAC802154_INTERNAL_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <nuttx/wdog.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2017-10-04 23:22:27 +02:00
|
|
|
#include <nuttx/semaphore.h>
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Configuration ************************************************************/
|
2020-04-13 10:08:03 +02:00
|
|
|
|
2017-07-10 00:53:08 +02:00
|
|
|
/* If processing is not done at the interrupt level, then work queue support
|
|
|
|
* is required.
|
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
#if !defined(CONFIG_SCHED_HPWORK) || !defined(CONFIG_SCHED_LPWORK)
|
|
|
|
# error Both Low and High priority work queues are required for this driver
|
2017-07-10 00:53:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(CONFIG_MAC802154_NTXDESC) || CONFIG_MAC802154_NTXDESC <= 0
|
|
|
|
# undef CONFIG_MAC802154_NTXDESC
|
2017-11-01 21:15:21 +01:00
|
|
|
# define CONFIG_MAC802154_NTXDESC 5
|
2017-07-10 00:53:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(CONFIG_IEEE802154_DEFAULT_EADDR)
|
|
|
|
# define CONFIG_IEEE802154_DEFAULT_EADDR 0xFFFFFFFFFFFFFFFF
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-04-13 10:08:03 +02:00
|
|
|
* Public Types
|
2017-07-10 00:53:08 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct mac802154_radiocb_s
|
|
|
|
{
|
|
|
|
struct ieee802154_radiocb_s cb;
|
|
|
|
FAR struct ieee802154_privmac_s *priv;
|
|
|
|
};
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* Enumeration for representing what operation the MAC layer is currently
|
|
|
|
* doing. There can only be one command being handled at any given time, but
|
|
|
|
* certain operations such as association requires more than one command to
|
|
|
|
* be sent. Therefore, the need to track not only what command is currently
|
|
|
|
* active, but also, what overall operation the command is apart of is
|
|
|
|
* necessary.
|
2017-07-10 00:53:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
enum mac802154_operation_e
|
|
|
|
{
|
|
|
|
MAC802154_OP_NONE,
|
|
|
|
MAC802154_OP_ASSOC,
|
|
|
|
MAC802154_OP_POLL,
|
|
|
|
MAC802154_OP_SCAN,
|
|
|
|
MAC802154_OP_AUTOEXTRACT,
|
2018-03-28 17:49:34 +02:00
|
|
|
MAC802154_OP_RXENABLE,
|
2017-07-10 00:53:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The privmac structure holds the internal state of the MAC and is the
|
|
|
|
* underlying represention of the opaque MACHANDLE. It contains storage for
|
|
|
|
* the IEEE802.15.4 MIB attributes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ieee802154_privmac_s
|
|
|
|
{
|
2020-04-13 10:08:03 +02:00
|
|
|
/*************************** General Fields *******************************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */
|
|
|
|
FAR struct mac802154_maccb_s *cb; /* Head of a list of MAC callbacks */
|
|
|
|
FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t lock; /* Support exclusive access */
|
|
|
|
uint8_t nclients; /* Number of notification clients */
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
/* Only support a single command at any given time. As of now I see no
|
2020-04-13 10:08:03 +02:00
|
|
|
* condition where you need to have more than one command frame
|
|
|
|
* simultaneously
|
2017-07-10 00:53:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
sem_t opsem; /* Exclusive operations */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/******************* Fields related to MAC operations *********************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
enum mac802154_operation_e curr_op; /* The current overall operation */
|
|
|
|
enum ieee802154_cmdid_e curr_cmd; /* Type of the current cmd */
|
|
|
|
FAR struct ieee802154_txdesc_s *cmd_desc; /* TX descriptor for current cmd */
|
|
|
|
uint8_t nrxusers;
|
2019-08-19 17:17:01 +02:00
|
|
|
struct work_s macop_work;
|
2017-07-10 00:53:08 +02:00
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/******************* Fields related to SCAN operation *********************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
uint8_t scanindex;
|
2019-08-10 19:03:24 +02:00
|
|
|
uint8_t edlist[15];
|
2017-07-10 00:53:08 +02:00
|
|
|
uint8_t npandesc;
|
|
|
|
struct ieee802154_pandesc_s pandescs[MAC802154_NPANDESC];
|
|
|
|
uint8_t panidbeforescan[IEEE802154_PANIDSIZE];
|
|
|
|
struct ieee802154_scan_req_s currscan;
|
|
|
|
uint32_t scansymdur;
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/******************* Fields related to notifications **********************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
sq_queue_t primitive_queue; /* Queue of primitives to pass via notify()
|
2020-04-13 10:08:03 +02:00
|
|
|
* callback to registered receivers
|
|
|
|
*/
|
|
|
|
struct work_s notifwork; /* For deferring notifications to LPWORK queue */
|
2017-07-10 00:53:08 +02:00
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/******************* Tx descriptor queues and pools ***********************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
struct ieee802154_txdesc_s txdesc_pool[CONFIG_MAC802154_NTXDESC];
|
|
|
|
sem_t txdesc_sem;
|
|
|
|
sq_queue_t txdesc_queue;
|
|
|
|
sq_queue_t txdone_queue;
|
|
|
|
|
|
|
|
/* Support a singly linked list of transactions that will be sent using the
|
|
|
|
* CSMA algorithm. On a non-beacon enabled PAN, these transactions will be
|
|
|
|
* sent whenever. On a beacon-enabled PAN, these transactions will be sent
|
|
|
|
* during the CAP of the Coordinator's superframe.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sq_queue_t csma_queue;
|
|
|
|
sq_queue_t gts_queue;
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* Support a singly linked list of transactions that will be sent
|
|
|
|
* indirectly. This list should only be used by a MAC acting as a
|
|
|
|
* coordinator. These transactions will stay here until the data
|
|
|
|
* is extracted by the destination device sending a Data Request
|
|
|
|
* MAC command or if too much time passes. This list should also
|
|
|
|
* be used to populate the address list of the outgoing beacon
|
|
|
|
* frame.
|
2017-07-10 00:53:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
sq_queue_t indirect_queue;
|
|
|
|
|
|
|
|
/* Support a singly linked list of frames received */
|
|
|
|
|
|
|
|
sq_queue_t dataind_queue;
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/************* Fields related to addressing and coordinator ***************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* Holds all address information (Extended, Short, and PAN ID) for MAC */
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
struct ieee802154_addr_s addr;
|
|
|
|
|
|
|
|
struct ieee802154_pandesc_s pandesc;
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/*************** Fields related to beacon-enabled networks ****************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
/* Holds attributes pertaining to the superframe specification */
|
|
|
|
|
|
|
|
struct ieee802154_superframespec_s sfspec;
|
|
|
|
|
|
|
|
/* We use 2 beacon frame structures so that we can ping-pong between them
|
|
|
|
* while updating the beacon
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ieee802154_beaconframe_s beaconframe[2];
|
|
|
|
|
|
|
|
/* Contents of beacon payload */
|
|
|
|
|
|
|
|
uint8_t beaconpayload[IEEE802154_MAX_BEACON_PAYLOAD_LEN];
|
|
|
|
uint8_t beaconpayloadlength;
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/****************** Fields related to offloading work *********************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
/* Work structures for offloading aynchronous work */
|
|
|
|
|
2019-08-19 17:17:01 +02:00
|
|
|
struct work_s txdone_work;
|
2017-07-10 00:53:08 +02:00
|
|
|
struct work_s rx_work;
|
|
|
|
struct work_s purge_work;
|
2017-07-10 05:55:48 +02:00
|
|
|
struct work_s timer_work;
|
2017-07-10 00:53:08 +02:00
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/****************** Uncategorized MAC PIB attributes **********************/
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
/* The maximum time to wait either for a frame intended as a response to a
|
|
|
|
* data request frame or for a broadcast frame following a beacon with the
|
|
|
|
* Frame Pending field set to one. [1] pg. 127
|
|
|
|
*
|
|
|
|
* NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't
|
|
|
|
* sure at the time what the range of reasonable values was.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t max_frame_waittime;
|
|
|
|
|
|
|
|
/* The maximum time (in unit periods) that a transaction is stored by a
|
|
|
|
* coordinator and indicated in its beacon.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint16_t trans_persisttime;
|
|
|
|
|
|
|
|
uint8_t dsn; /* Seq. num added to tx data or MAC frame */
|
|
|
|
|
2020-04-13 10:08:03 +02: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. [1] 128.
|
2017-07-10 00:53:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t resp_waittime;
|
|
|
|
|
|
|
|
/* The total transmit duration (including PHY header and FCS) specified in
|
|
|
|
* symbols. [1] pg. 129.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t tx_totaldur;
|
|
|
|
|
|
|
|
/* Start of 8-bit bitfield */
|
|
|
|
|
|
|
|
uint32_t trackingbeacon : 1; /* Are we tracking the beacon */
|
|
|
|
uint32_t isassoc : 1; /* Are we associated to the PAN */
|
|
|
|
uint32_t autoreq : 1; /* Automatically send data req. if addr
|
|
|
|
* addr is in the beacon frame */
|
|
|
|
|
|
|
|
uint32_t gtspermit : 1; /* Is PAN Coord. accepting GTS reqs. */
|
|
|
|
uint32_t promisc : 1; /* Is promiscuous mode on? */
|
|
|
|
uint32_t rngsupport : 1; /* Does MAC sublayer support ranging */
|
|
|
|
uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */
|
|
|
|
uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */
|
|
|
|
|
|
|
|
/* End of 8-bit bitfield */
|
|
|
|
|
|
|
|
/* Start of 32-bit bitfield */
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* The offset, measured is symbols, between the symbol boundary at which
|
2017-07-10 00:53:08 +02:00
|
|
|
* MLME captures the timestamp of each transmitted and received frame, and
|
|
|
|
* the onset of the first symbol past the SFD, namely the first symbol of
|
|
|
|
* the frames [1] pg. 129.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32_t sync_symboffset : 12;
|
|
|
|
|
|
|
|
uint32_t txctrl_activedur : 17; /* Duration for which tx is permitted to
|
|
|
|
* be active */
|
|
|
|
uint32_t txctrl_pausedur : 1; /* Duration after tx before another tx is
|
|
|
|
* permitted. 0=2000, 1= 10000 */
|
|
|
|
|
|
|
|
/* What type of device is this node acting as */
|
|
|
|
|
|
|
|
enum ieee802154_devmode_e devmode : 2;
|
|
|
|
|
|
|
|
/* End of 32-bit bitfield */
|
|
|
|
|
|
|
|
/* Start of 32-bit bitfield */
|
|
|
|
|
|
|
|
uint32_t beacon_txtime : 24; /* Time of last beacon transmit */
|
|
|
|
uint32_t minbe : 4; /* Min value of backoff exponent (BE) */
|
|
|
|
uint32_t maxbe : 4; /* Max value of backoff exponent (BE) */
|
|
|
|
|
|
|
|
/* End of 32-bit bitfield */
|
|
|
|
|
|
|
|
/* Start of 8-bit bitfield */
|
|
|
|
|
|
|
|
uint8_t bf_ind : 1; /* Ping-pong index for beacon frame */
|
|
|
|
uint8_t beaconupdate : 1; /* Does the beacon frame need to be updated */
|
|
|
|
uint8_t max_csmabackoffs : 3; /* Max num backoffs for CSMA algorithm
|
|
|
|
* before declaring ch access failure */
|
|
|
|
uint8_t maxretries : 3; /* Max # of retries allowed after tx fail */
|
2020-04-13 10:08:03 +02:00
|
|
|
|
2017-07-10 00:53:08 +02:00
|
|
|
/* End of 8-bit bitfield. */
|
|
|
|
|
|
|
|
/* Start of 8-bit bitfield */
|
|
|
|
|
|
|
|
uint8_t rxonidle : 1; /* Receiver on when idle? */
|
|
|
|
|
|
|
|
/* End of 8-bit bitfield. */
|
|
|
|
|
|
|
|
/* TODO: Add Security-related MAC PIB attributes */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
int mac802154_txdesc_alloc(FAR struct ieee802154_privmac_s *priv,
|
2023-08-08 10:18:19 +02:00
|
|
|
FAR struct ieee802154_txdesc_s **txdesc);
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
void mac802154_setupindirect(FAR struct ieee802154_privmac_s *priv,
|
2023-08-08 10:18:19 +02:00
|
|
|
FAR struct ieee802154_txdesc_s *txdesc);
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
void mac802154_createdatareq(FAR struct ieee802154_privmac_s *priv,
|
2023-08-08 10:18:19 +02:00
|
|
|
FAR struct ieee802154_addr_s *coordaddr,
|
|
|
|
enum ieee802154_addrmode_e srcmode,
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc);
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
void mac802154_updatebeacon(FAR struct ieee802154_privmac_s *priv);
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
void mac802154_notify(FAR struct ieee802154_privmac_s *priv,
|
2023-08-08 10:18:19 +02:00
|
|
|
FAR struct ieee802154_primitive_s *primitive);
|
2017-11-01 21:15:21 +01:00
|
|
|
|
2017-07-10 00:53:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Helper Macros/Inline Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define mac802154_putpanid(iob, panid) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
IEEE802154_PANIDCOPY(&iob->io_data[iob->io_len], panid); \
|
|
|
|
iob->io_len += IEEE802154_PANIDSIZE; \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
#define mac802154_putsaddr(iob, saddr) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
IEEE802154_SADDRCOPY(&iob->io_data[iob->io_len], saddr); \
|
|
|
|
iob->io_len += IEEE802154_SADDRSIZE; \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
2019-08-10 20:25:13 +02:00
|
|
|
/* The IEEE 802.15.4 Standard is confusing with regards to byte-order for
|
|
|
|
* extended address. More research discovers that the extended address should
|
|
|
|
* be sent in reverse-canonical form.
|
|
|
|
*/
|
|
|
|
|
2017-07-10 00:53:08 +02:00
|
|
|
#define mac802154_puteaddr(iob, eaddr) \
|
|
|
|
do \
|
|
|
|
{ \
|
2023-08-08 10:18:19 +02:00
|
|
|
int index; \
|
|
|
|
for (index = IEEE802154_EADDRSIZE - 1; index >= 0; index--) \
|
2019-08-10 20:25:13 +02:00
|
|
|
{ \
|
|
|
|
iob->io_data[iob->io_len++] = eaddr[index]; \
|
|
|
|
} \
|
2017-07-10 00:53:08 +02:00
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
#define mac802154_takepanid(iob, panid) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
IEEE802154_PANIDCOPY(panid, &iob->io_data[iob->io_offset]); \
|
|
|
|
iob->io_offset += IEEE802154_PANIDSIZE; \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
#define mac802154_takesaddr(iob, saddr) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
IEEE802154_SADDRCOPY(saddr, &iob->io_data[iob->io_offset]); \
|
|
|
|
iob->io_offset += IEEE802154_SADDRSIZE; \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
2019-08-10 20:25:13 +02:00
|
|
|
/* The IEEE 802.15.4 Standard is confusing with regards to byte-order for
|
|
|
|
* extended address. More research discovers that the extended address should
|
|
|
|
* be sent in reverse-canonical form.
|
|
|
|
*/
|
|
|
|
|
2017-07-10 00:53:08 +02:00
|
|
|
#define mac802154_takeeaddr(iob, eaddr) \
|
|
|
|
do \
|
|
|
|
{ \
|
2023-08-08 10:18:19 +02:00
|
|
|
int index; \
|
|
|
|
for (index = IEEE802154_EADDRSIZE - 1; index >= 0; index--) \
|
2019-08-10 20:25:13 +02:00
|
|
|
{ \
|
|
|
|
eaddr[index] = iob->io_data[iob->io_offset++]; \
|
|
|
|
} \
|
2017-07-10 00:53:08 +02:00
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
/* General helper macros ****************************************************/
|
|
|
|
|
|
|
|
/* GET 16-bit data: source in network order, result in host order */
|
|
|
|
|
|
|
|
#define GETHOST16(ptr,index) \
|
|
|
|
((((uint16_t)((ptr)[(index) + 1])) << 8) | ((uint16_t)(((ptr)[index]))))
|
|
|
|
|
|
|
|
/* GET 16-bit data: source in network order, result in network order */
|
|
|
|
|
|
|
|
#define GETNET16(ptr,index) \
|
|
|
|
((((uint16_t)((ptr)[index])) << 8) | ((uint16_t)(((ptr)[(index) + 1]))))
|
|
|
|
|
|
|
|
/* PUT 16-bit data: source in host order, result in network order */
|
|
|
|
|
|
|
|
#define PUTHOST16(ptr,index,value) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
(ptr)[index] = (uint16_t)(value) & 0xff; \
|
|
|
|
(ptr)[index + 1] = ((uint16_t)(value) >> 8) & 0xff; \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
/* Set bit in 16-bit value: source in host order, result in network order. */
|
|
|
|
|
|
|
|
#define IEEE802154_SETBITS_U16(ptr,index,value) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
(ptr)[index] |= (uint16_t)(value) & 0xff; \
|
|
|
|
(ptr)[index + 1] |= ((uint16_t)(value) >> 8) & 0xff; \
|
|
|
|
} \
|
|
|
|
while(0)
|
|
|
|
|
|
|
|
/* Helper macros for setting/receiving bits for frame control field */
|
|
|
|
|
|
|
|
#define IEEE802154_SETFTYPE(ptr, index, ftype) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, (ftype << IEEE802154_FRAMECTRL_SHIFT_FTYPE))
|
|
|
|
|
|
|
|
#define IEEE802154_SETACKREQ(ptr, index) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, IEEE802154_FRAMECTRL_ACKREQ)
|
|
|
|
|
|
|
|
#define IEEE802154_SETDADDRMODE(ptr, index, mode) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, (mode << IEEE802154_FRAMECTRL_SHIFT_DADDR))
|
|
|
|
|
|
|
|
#define IEEE802154_SETSADDRMODE(ptr, index, mode) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, (mode << IEEE802154_FRAMECTRL_SHIFT_SADDR))
|
|
|
|
|
|
|
|
#define IEEE802154_SETPANIDCOMP(ptr, index) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, IEEE802154_FRAMECTRL_PANIDCOMP)
|
|
|
|
|
|
|
|
#define IEEE802154_SETVERSION(ptr, index, version) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, (version << IEEE802154_FRAMECTRL_SHIFT_VERSION))
|
|
|
|
|
|
|
|
/* Helper macros for setting/receiving bits for superframe specification */
|
|
|
|
|
|
|
|
#define IEEE802154_SETBEACONORDER(ptr, index, val) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, (val << IEEE802154_SFSPEC_SHIFT_BEACONORDER))
|
|
|
|
|
|
|
|
#define IEEE802154_SETSFORDER(ptr, index, val) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, (val << IEEE802154_SFSPEC_SHIFT_SFORDER))
|
|
|
|
|
|
|
|
#define IEEE802154_SETFINCAPSLOT(ptr, index, val) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, (val << IEEE802154_SFSPEC_SHIFT_FINCAPSLOT))
|
|
|
|
|
|
|
|
#define IEEE802154_SETBLE(ptr, index) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, IEEE802154_SFSPEC_BLE)
|
|
|
|
|
|
|
|
#define IEEE802154_SETPANCOORD(ptr, index) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, IEEE802154_SFSPEC_PANCOORD)
|
|
|
|
|
|
|
|
#define IEEE802154_SETASSOCPERMIT(ptr, index) \
|
|
|
|
IEEE802154_SETBITS_U16(ptr, index, IEEE802154_SFSPEC_ASSOCPERMIT)
|
|
|
|
|
|
|
|
#define IEEE802154_GETBEACONORDER(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_SFSPEC_BEACONORDER) >> \
|
|
|
|
IEEE802154_SFSPEC_SHIFT_BEACONORDER)
|
|
|
|
|
|
|
|
#define IEEE802154_GETSFORDER(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_SFSPEC_SFORDER) >> \
|
|
|
|
IEEE802154_SFSPEC_SHIFT_SFORDER)
|
|
|
|
|
|
|
|
#define IEEE802154_GETFINCAPSLOT(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_SFSPEC_FINCAPSLOT) >> \
|
|
|
|
IEEE802154_SFSPEC_SHIFT_FINCAPSLOT)
|
|
|
|
|
|
|
|
#define IEEE802154_GETBLE(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_SFSPEC_BLE) >> \
|
|
|
|
IEEE802154_SFSPEC_SHIFT_BLE)
|
|
|
|
|
|
|
|
#define IEEE802154_GETPANCOORD(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_SFSPEC_PANCOORD) >> \
|
|
|
|
IEEE802154_SFSPEC_SHIFT_PANCOORD)
|
|
|
|
|
|
|
|
#define IEEE802154_GETASSOCPERMIT(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_SFSPEC_ASSOCPERMIT) >> \
|
|
|
|
IEEE802154_SFSPEC_SHIFT_ASSOCPERMIT)
|
|
|
|
|
|
|
|
/* Helper macros for setting/receiving bits for GTS specification */
|
|
|
|
|
|
|
|
#define IEEE802154_GETGTSDESCCOUNT(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_GTSSPEC_DESCCOUNT) >> \
|
|
|
|
IEEE802154_GTSSPEC_SHIFT_DESCCOUNT)
|
|
|
|
|
|
|
|
#define IEEE802154_GETGTSPERMIT(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_GTSSPEC_PERMIT) >> \
|
|
|
|
IEEE802154_GTSSPEC_SHIFT_PERMIT)
|
|
|
|
|
|
|
|
/* Helper macros for setting/receiving bits for GTS Directions */
|
|
|
|
|
|
|
|
#define IEEE802154_GETGTSDIRMASK(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_GTSDIR_MASK) >> \
|
|
|
|
IEEE802154_GTSDIR_SHIFT_MASK)
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* Helper macros for setting/receiving bits for Pending Address */
|
2017-07-10 00:53:08 +02:00
|
|
|
|
|
|
|
#define IEEE802154_GETNPENDSADDR(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_PENDADDR_NSADDR) >> \
|
|
|
|
IEEE802154_PENDADDR_SHIFT_NSADDR)
|
|
|
|
|
|
|
|
#define IEEE802154_GETNPENDEADDR(ptr, index) \
|
|
|
|
((GETHOST16(ptr, index) & IEEE802154_PENDADDR_NEADDR) >> \
|
|
|
|
IEEE802154_PENDADDR_SHIFT_NEADDR)
|
|
|
|
|
|
|
|
/* General helpers **********************************************************/
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_txdesc_free(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR struct ieee802154_txdesc_s *txdesc)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
sq_addlast((FAR sq_entry_t *)txdesc, &priv->txdesc_queue);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxsem_post(&priv->txdesc_sem);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2017-07-10 05:55:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_symtoticks
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Helper function for converting symbols to system clock ticks
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* priv MAC struct is locked when calling.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline uint32_t
|
|
|
|
mac802154_symtoticks(FAR struct ieee802154_privmac_s *priv, uint32_t symbols)
|
2017-07-10 05:55:48 +02:00
|
|
|
{
|
|
|
|
union ieee802154_attr_u attrval;
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
/* First, get the symbol duration from the radio layer. Symbol duration is
|
|
|
|
* returned in picoseconds to ensure precision is kept when multiplying to
|
|
|
|
* get overall times.
|
|
|
|
*/
|
|
|
|
|
|
|
|
priv->radio->getattr(priv->radio, IEEE802154_ATTR_PHY_SYMBOL_DURATION,
|
2023-08-08 10:18:19 +02:00
|
|
|
&attrval);
|
2017-07-10 05:55:48 +02:00
|
|
|
|
|
|
|
/* After this step, ret represents microseconds */
|
|
|
|
|
|
|
|
ret = ((uint64_t)attrval.phy.symdur_picosec * symbols) / (1000 * 1000);
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* This method should only be used for things that can be late. For
|
|
|
|
* instance, it's always okay to wait a little longer before disabling
|
|
|
|
* your receiver. Therefore, we force the tick count to round up.
|
2017-07-10 05:55:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret % USEC_PER_TICK == 0)
|
|
|
|
{
|
2023-08-08 10:18:19 +02:00
|
|
|
ret /= USEC_PER_TICK;
|
2017-07-10 05:55:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-08 10:18:19 +02:00
|
|
|
ret /= USEC_PER_TICK;
|
2017-07-10 05:55:48 +02:00
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_timerstart
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Helper function wrapping the watchdog timer interface. Helps isolate
|
|
|
|
* different operations from having to worry about work queues and watchdog
|
|
|
|
* timers.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* priv MAC struct is locked when calling.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_timerstart(FAR struct ieee802154_privmac_s *priv,
|
2017-07-10 05:55:48 +02:00
|
|
|
uint32_t numsymbols, worker_t worker)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(work_available(&priv->timer_work));
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
/* Schedule the work
|
|
|
|
* converting the number of symbols to the number of CPU ticks
|
|
|
|
*/
|
2017-07-10 05:55:48 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
work_queue(HPWORK, &priv->timer_work, worker, priv,
|
2017-07-10 05:55:48 +02:00
|
|
|
mac802154_symtoticks(priv, numsymbols));
|
|
|
|
}
|
|
|
|
|
2017-07-10 00:53:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mac802154_timercancel
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Cancel timer and remove reference to callback function
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* priv MAC struct is locked when calling.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline int
|
|
|
|
mac802154_timercancel(FAR struct ieee802154_privmac_s *priv)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
work_cancel(HPWORK, &priv->timer_work);
|
2017-07-10 00:53:08 +02:00
|
|
|
wlinfo("Timer cancelled\n");
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_rxenable(FAR struct ieee802154_privmac_s *priv)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
priv->nrxusers++;
|
|
|
|
|
|
|
|
/* If this is the first user, actually enable the receiver */
|
|
|
|
|
|
|
|
if (priv->nrxusers == 1)
|
|
|
|
{
|
|
|
|
wlinfo("Receiver enabled\n");
|
|
|
|
priv->radio->rxenable(priv->radio, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_rxdisable(FAR struct ieee802154_privmac_s *priv)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
priv->nrxusers--;
|
|
|
|
|
|
|
|
/* If this is the first user, actually enable the receiver */
|
|
|
|
|
|
|
|
if (priv->nrxusers == 0)
|
|
|
|
{
|
|
|
|
wlinfo("Receiver disabled\n");
|
|
|
|
priv->radio->rxenable(priv->radio, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setchannel(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
uint8_t channel)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_PHY_CHAN,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)&channel);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setchpage(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
uint8_t chpage)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_PHY_CURRENT_PAGE,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)&chpage);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setpanid(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR const uint8_t *panid)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
IEEE802154_PANIDCOPY(priv->addr.panid, panid);
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_PANID,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)panid);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setsaddr(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR const uint8_t *saddr)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
IEEE802154_SADDRCOPY(priv->addr.saddr, saddr);
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_SADDR,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)saddr);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setcoordsaddr(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR const uint8_t *saddr)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
IEEE802154_SADDRCOPY(priv->pandesc.coordaddr.saddr, saddr);
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_SADDR,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)saddr);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setcoordeaddr(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR const uint8_t *eaddr)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
IEEE802154_EADDRCOPY(priv->pandesc.coordaddr.eaddr, eaddr);
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_EADDR,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)eaddr);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setcoordaddr(FAR struct ieee802154_privmac_s *priv,
|
|
|
|
FAR const struct ieee802154_addr_s *addr)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
|
|
|
memcpy(&priv->pandesc.coordaddr, addr, sizeof(struct ieee802154_addr_s));
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_EADDR,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)addr->eaddr);
|
2017-07-10 00:53:08 +02:00
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_COORD_SADDR,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)addr->saddr);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setrxonidle(FAR struct ieee802154_privmac_s *priv, bool rxonidle)
|
2017-07-10 00:53:08 +02:00
|
|
|
{
|
2017-09-15 16:04:38 +02:00
|
|
|
priv->rxonidle = rxonidle;
|
2017-07-10 00:53:08 +02:00
|
|
|
if (priv->rxonidle)
|
|
|
|
{
|
|
|
|
mac802154_rxenable(priv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mac802154_rxdisable(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_RX_ON_WHEN_IDLE,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)&rxonidle);
|
2017-07-10 00:53:08 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 10:08:03 +02:00
|
|
|
static inline void
|
|
|
|
mac802154_setdevmode(FAR struct ieee802154_privmac_s *priv, uint8_t mode)
|
2017-07-12 06:53:04 +02:00
|
|
|
{
|
|
|
|
priv->devmode = mode;
|
2017-07-13 09:17:05 +02:00
|
|
|
priv->radio->setattr(priv->radio, IEEE802154_ATTR_MAC_DEVMODE,
|
2023-08-08 10:18:19 +02:00
|
|
|
(FAR const union ieee802154_attr_u *)&mode);
|
2017-07-12 06:53:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-10 00:53:08 +02:00
|
|
|
#endif /* __WIRELESS_IEEE802154__MAC802154_INTERNAL_H */
|