初始版本

This commit is contained in:
xiaozhengsheng
2025-08-19 09:49:41 +08:00
parent 10f1ddf1c1
commit 6df0f7d96e
2974 changed files with 1712873 additions and 54 deletions

View File

@@ -0,0 +1,61 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_AUTO_REQUEST_H_INCLUDED
#define MAC_AUTO_REQUEST_H_INCLUDED
/** @file
*
* @defgroup mac_auto_request MAC auto request
* @ingroup mac_15_4
* @{
*/
/**
* @brief This function is called when a new beacon has been sent.
*
* @param[in] p_ind - Pointer to beacon indication structure.
*/
void mac_auto_request_notify_ind(mac_beacon_ind_t * p_ind);
/** @} */
#endif /* MAC_AUTO_REQUEST_H_INCLUDED_ */

View File

@@ -0,0 +1,467 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_COMMON_H_INCLUDED
#define MAC_COMMON_H_INCLUDED
#include <stdint.h>
#include "phy_common.h"
#if (CONFIG_SECURE == 1)
#include "mac_security.h"
#endif
/** @file
* Types and declarations common for different MLME transactions listed here.
*
* @defgroup mac_common MAC Common API
* @ingroup mac_15_4
* @{
* @brief Module for declaring MAC Common API.
* @details The Common MAC module contains declarations of commonly used MAC routines and necessary
* macros and types.
*/
/**@brief Maximum interval for acknowledgement frame to arrive in microseconds.
*
* macAckWaitDuration = aUnitBackoffPeriod(only for beacon enabled PAN) +
* aTurnaroundTime +
* phySHRDuration + ceil(6 * phySymbolsPerOctet) =
* 20 + 12 + 10 + 6 * 2 =
* 54 symbols / 62.5 ksymbols/s = 864 us (544 us for beacon disabled PAN)
*/
#if (CONFIG_BEACON_ENABLED == 1)
#define macAckWaitDuration 864
#else
#define macAckWaitDuration 544
#endif
/**@brief The maximum number of octets added by the MAC
* sublayer to the MAC payload of a beacon frame.
*/
#define aMaxBeaconOverhead 75
/**@brief The number of symbols forming the basic time period
* used by the CSMA-CA algorithm.
*/
#define aUnitBackoffPeriod 20UL
/**@brief The number of symbols forming a superframe slot
* when the superframe order is equal to 0.
*/
#define aBaseSlotDuration 60UL
/**@brief The number of slots contained in any superframe. */
#define aNumSuperframeSlots 16UL
/**@brief The number of symbols forming a superframe when
* the superframe order is equal to 0.
*/
#define aBaseSuperframeDuration (aBaseSlotDuration * aNumSuperframeSlots)
/**@brief The maximum size, in octets, of a beacon payload. */
#define aMaxBeaconPayloadLength (aMaxPHYPacketSize - aMaxBeaconOverhead)
/**@brief The maximum number of octets added by the MAC
* sublayer to the PSDU without security.
*/
#define aMaxMPDUUnsecuredOverhead 25
/**@brief The maximum number of octets that can be transmitted in the MAC Payload
* field of an unsecured MAC frame that will be guaranteed not to exceed aMaxPHYPacketSize.
*/
#define aMaxMACSafePayloadSize (aMaxPHYPacketSize - aMaxMPDUUnsecuredOverhead)
/**@brief The minimum number of octets added by the MAC sublayer to the PSDU.*/
#define aMinMPDUOverhead 9
/**@brief The maximum number of octets that can be transmitted in the MAC
* Payload field.
*/
#define aMaxMACPayloadSize (aMaxPHYPacketSize - aMinMPDUOverhead)
/**@brief The maximum size of an MPDU, in octets, that can be followed by a SIFS period. */
#define aMaxSIFSFrameSize 18
/**@brief The minimum number of symbols forming the CAP.
*
* @details This ensures that MAC commands can still be transferred to devices
* when GTSs are being used.
*/
#define aMinCAPLength 440
/**@brief The number of superframes in which a GTS descriptor exists
* in the beacon frame of the PAN coordinator.
*/
#define aGTSDescPersistenceTime 4
/**@brief The number of consecutive lost beacons that will cause the MAC sublayer
* of a receiving device to declare a loss of synchronization.
*/
#define aMaxLostBeacons 4
/**@brief Maximum number of battery life extension periods. */
#define MAC_MIN_BATT_LIFE_EXT_PERIODS 6
/**@brief Minimum number of battery life extension periods. */
#define MAC_MAX_BATT_LIFE_EXT_PERIODS 41
/**@brief Minimum value for macBeaconOrder parameter. */
#define MAC_MIN_BEACON_ORDER 0
/**@brief Maximum value for macBeaconOrder parameter. */
#define MAC_MAX_BEACON_ORDER 15
/**@brief Minimum value for macMaxCSMABackoffs parameter. */
#define MAC_MIN_MAX_CSMA_BACKOFFS 0
/**@brief Maximum value for macMaxCSMABackoffs parameter. */
#define MAC_MAX_MAX_CSMA_BACKOFFS 5
/**@brief Minimum value for macMinBE parameter. */
#define MAC_MIN_MIN_BE 0
/**@brief Minimum value for macMaxBE parameter. */
#define MAC_MIN_MAX_BE 3
/**@brief Maximum value for macMaxBE parameter. */
#define MAC_MAX_MAX_BE 8
/**@brief Minimum value for macSuperframeOrder parameter. */
#define MAC_MIN_SUPERFRAME_ORDER 0
/**@brief Maximum value for macSuperframeOrder parameter. */
#define MAC_MAX_SUPERFRAME_ORDER 15
/**@brief Minimum value for macMaxFrameRetries parameter. */
#define MAC_MIN_MAX_FRAME_RETRIES 0
/**@brief Maximum value for macMaxFrameRetries parameter. */
#define MAC_MAX_MAX_FRAME_RETRIES 7
/**@brief Minimum value for macResponseWaitTime parameter. */
#define MAC_MIN_RESPONSE_WAIT_TIME 2
/**@brief Maximum value for macResponseWaitTime parameter. */
#define MAC_MAX_RESPONSE_WAIT_TIME 64
/**@brief A handy macro for a never initialized short address. */
#define MAC_SHORT_ADDRESS_NOT_SET 0xFFFF
/**@brief A handy macro for a never initialized short address. */
#define MAC_EXTENDED_ADDRESS_NOT_SET 0xFFFFFFFFFFFFFFFFULL
/**@brief A value of MAC beacon order attribute which determines
* a state with no periodic beacons.
*/
#define MAC_NO_BEACONS 15
/**@brief A handy macro for broadcast address. */
#define MAC_BROADCAST_SHORT_ADDRESS 0xFFFF
/**@brief A handy macro for unknown PAN ID. */
#define MAC_BROADCAST_PANID 0xFFFF
/**@brief Short address field value that is used when the device does not
* support short addressing mode.
*/
#define MAC_EXTENDED_ADDRESS_ONLY 0xFFFE
/**@brief Final CAP slot field value in the beacon for non-beacon enabled PAN. */
#define MAC_FINAL_CAP_SLOT_NBPAN 15
/**@brief Total amount of slots available in beacon enabled PAN. */
#define MAC_SLOT_AMOUNT 16
/**@brief This is the value of auto request key index until it has been set. */
#define MAC_SECURITY_KEY_INDEX_NOT_SET 0xFF
/**@brief Length of short MAC address in bytes. */
#define MAC_ADDR_SHORT_LEN 2
/**@brief Length of extended MAC address in bytes. */
#define MAC_ADDR_EXTENDED_LEN 8
/**@brief Length of PAN ID field in bytes. */
#define MAC_PAN_ID_LEN 2
/**@brief MAC footer (FCS) size. */
#define MAC_MFR_SIZE 2
/**@brief Maximum auxiliary header length */
#if (CONFIG_SECURE == 1)
#define MAC_MAX_AUX_HEADER_SIZE 14
#else
#define MAC_MAX_AUX_HEADER_SIZE 0
#endif
/**@brief Maximum MAC header length */
#define MAC_MAX_MHR_SIZE (PHY_MAX_HEADER_SIZE + \
2 /* Frame control */ + \
1 /* Data sequence number */ + \
2 * (sizeof(uint16_t) + (sizeof(uint64_t))) /* Two PAN IDs and extended addresses */ + \
MAC_MAX_AUX_HEADER_SIZE)
/**@brief Maximum MAC header length for beacon frame */
#define MAC_MAX_BCN_MHR_SIZE (PHY_MAX_HEADER_SIZE + \
2 /* Frame control field */ + \
1 /* Beacon sequence number */ + \
sizeof(uint16_t) /* PAN ID */ + \
sizeof(uint64_t) /* Extended address */ + \
MAC_MAX_AUX_HEADER_SIZE)
/**@brief Memory which should be reserved for MAC fields */
#if (CONFIG_SECURE == 1)
#define MAC_MEMORY_RESERVE (MAC_MAX_MHR_SIZE + MAX_MIC_SIZE + MAC_MFR_SIZE)
#else
#define MAC_MEMORY_RESERVE (MAC_MAX_MHR_SIZE + MAC_MFR_SIZE)
#endif
/**@brief Offset of MAC payload in the frame buffer */
#define MAC_MAX_MSDU_OFFSET MAC_MAX_MHR_SIZE
/**@brief Possible MAC frame types. */
typedef enum
{
MAC_BEACON, /**< Frame is a beacon. */
MAC_DATA, /**< Frame is a data frame. */
MAC_ACK, /**< Frame is a MAC ACKnowledgement. */
MAC_COMMAND /**< Frame is a MAC command. */
} mac_frame_type_t;
/**@brief MAC ADDRESS. */
typedef union
{
uint16_t short_address; /**< 16-bit short address. */
uint64_t long_address; /**< 64-bit long address. */
} mac_addr_t;
/**@brief MAC ADDR MODE. */
typedef enum
{
MAC_ADDR_NONE = 0, /**< NO address is used. */
MAC_ADDR_SHORT = 2, /**< Short address is used. */
MAC_ADDR_LONG = 3 /**< Long address is used. */
} mac_addr_mode_t;
typedef enum
{
MAC_FRAME_VERSION_2003, /**< IEEE 802.15.4-2003 compliant. */
MAC_FRAME_VERSION_2006 /**< IEEE 802.15.4-2006 compliant. */
} mac_frame_version_t;
/**
* @brief MAC status
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.17
* excluding:
* MAC_IS_NOT_AVAILABLE
* This status is necessary for synchronous API.
*/
typedef enum
{
MAC_SUCCESS = 0x00, /* 0 */ /**< Operation is successful. */
MAC_COUNTER_ERROR = 0xDB, /* 219 */ /**< The frame counter purportedly applied
by the originator of the received
frame is invalid. */
MAC_IMPROPER_KEY_TYPE = 0xDC, /* 220 */ /**< The key purportedly applied by the
originator of the received frame is
not allowed to be used with that
frame type according to the key usage
policy of the recipient. */
MAC_IMPROPER_SECURITY_LEVEL = 0xDD, /* 221 */ /**< The security level purportedly applied
by the originator of the received
frame does not meet the minimum
security level required/expected by
the recipient for that frame type. */
MAC_UNSUPPORTED_LEGACY = 0xDE, /* 222 */ /**< The received frame was purportedly
secured using security based on IEEE
Std 802.15.4-2003, and such security
is not supported by this standard. */
MAC_UNSUPPORTED_SECURITY = 0xDF, /* 223 */ /**< The security purportedly applied by
the originator of the received frame
is not supported. */
MAC_BEACON_LOSS = 0xE0, /* 224 */ /**< The beacon was lost following a
synchronization request. */
MAC_CHANNEL_ACCESS_FAILURE = 0xE1, /* 225 */ /**< A transmission could not take place
due to activity on the channel, i.e.
the CSMA-CA mechanism has failed. */
MAC_DENIED = 0xE2, /* 226 */ /**< The GTS request has been denied by
the PAN coordinator. */
MAC_DISABLE_TRX_FAILURE = 0xE3, /* 227 */ /**< The attempt to disable the
transceiver has failed. */
MAC_SECURITY_ERROR = 0xE4, /* 228 */ /**< Cryptographic processing of the
received secured frame failed. */
MAC_FRAME_TOO_LONG = 0xE5, /* 229 */ /**< Either a frame resulting from
processing has a length that is
greater than aMaxPHYPacketSize or
a requested transaction is too large
to fit in the CAP or GTS. */
MAC_INVALID_GTS = 0xE6, /* 230 */ /**< The requested GTS transmission failed
because the specified GTS either did
not have a transmit GTS direction or
was not defined. */
MAC_INVALID_HANDLE = 0xE7, /* 231 */ /**< A request to purge an MSDU from the
transaction queue was made using an
MSDU handle that was not found in
the transaction table. */
MAC_INVALID_PARAMETER = 0xE8, /* 232 */ /**< A parameter in the primitive is
either not supported or is out of
the valid range. */
MAC_NO_ACK = 0xE9, /* 233 */ /**< No acknowledgment was received after
macMaxFrameRetries. */
MAC_NO_BEACON = 0xEA, /* 234 */ /**< A scan operation failed to find any
network beacons. */
MAC_NO_DATA = 0xEB, /* 235 */ /**< No response data was available
following a request. */
MAC_NO_SHORT_ADDRESS = 0xEC, /* 236 */ /**< The operation failed because a 16-bit
short address was not allocated. */
MAC_OUT_OF_CAP = 0xED, /* 237 */ /**< A receiver enable request was
unsuccessful because it could not be
completed within the CAP.
@note The enumeration description is
not used in this standard, and it is
included only to meet the backwards
compatibility requirements for
IEEE Std 802.15.4-2003. */
MAC_PAN_ID_CONFLICT = 0xEE, /* 238 */ /**< A PAN identifier conflict has been
detected and communicated to the PAN
coordinator. */
MAC_REALIGNMENT = 0xEF, /* 239 */ /**< A coordinator realignment command has
been received. */
MAC_TRANSACTION_EXPIRED = 0xF0, /* 240 */ /**< The transaction has expired and its
information was discarded. */
MAC_TRANSACTION_OVERFLOW = 0xF1, /* 241 */ /**< There is no capacity to store the
transaction. */
MAC_TX_ACTIVE = 0xF2, /* 242 */ /**< The transceiver was in the transmitter
enabled state when the receiver was
requested to be enabled.
@note The enumeration description is
not used in this standard, and it is
included only to meet the backwards
compatibility requirements for
IEEE Std 802.15.4-2003. */
MAC_UNAVAILABLE_KEY = 0xF3, /* 243 */ /**< The key purportedly used by the
originator of the received frame is
not available or, if available, the
originating device is not known or is
blacklisted with that particular
key. */
MAC_UNSUPPORTED_ATTRIBUTE = 0xF4, /* 244 */ /**< A SET/GET request was issued with the
identifier of a PIB attribute that is
not supported. */
MAC_INVALID_ADDRESS = 0xF5, /* 245 */ /**< A request to send data was
unsuccessful because neither the source
address parameters nor the destination
address parameters were present. */
MAC_ON_TIME_TOO_LONG = 0xF6, /* 246 */ /**< A receiver enable request was
unsuccessful because it specified a
number of symbols that was longer than
the beacon interval. */
MAC_PAST_TIME = 0xF7, /* 247 */ /**< A receiver enable request was
unsuccessful because it could not be
completed within the current superframe
and was not permitted to be deferred
until the next superframe. */
MAC_TRACKING_OFF = 0xF8, /* 248 */ /**< The device was instructed to start
sending beacons based on the timing
of the beacon transmissions of its
coordinator, but the device is not
currently tracking the beacon of its
coordinator. */
MAC_INVALID_INDEX = 0xF9, /* 249 */ /**< An attempt to write to a MAC PIB
attribute that is in a table failed
because the specified table index
was out of range. */
MAC_LIMIT_REACHED = 0xFA, /* 250 */ /**< A scan operation terminated
prematurely because the number of
PAN descriptors stored reached an
implementation specified maximum. */
MAC_READ_ONLY = 0xFB, /* 251 */ /**< A SET/GET request was issued with the
identifier of an attribute that is
read only. */
MAC_SCAN_IN_PROGRESS = 0xFC, /* 252 */ /**< A request to perform a scan operation
failed because the MLME was in the
process of performing a previously
initiated scan operation. */
MAC_SUPERFRAME_OVERLAP = 0xFD, /* 253 */ /**< The device was instructed to start
sending beacons based on the timing
of the beacon transmissions of its
coordinator, but the instructed start
time overlapped the transmission time
of the beacon of its coordinator. */
/* Statuses out from standard. It is used for synchronous API */
MAC_IS_NOT_AVAILABLE = 0xFF /* 255 */ /**< MAC is not available. */
} mac_status_t;
/**
* @brief Payload descriptor.
*
* @details Not covered by the standard.
* Contains information sufficient to allow the next higher layer to clean
* the memory allocated for incoming frames.
*/
typedef struct
{
/**
* Pointer to the set of octets forming the frame payload being indicated by
* the MAC sublayer entity.
*/
uint8_t * p_payload;
/**
* Offset of the payload data relative to the beginning of the frame.
* Equal to the MAC header.
*/
uint8_t payload_offset;
} mac_payload_descriptor_t;
/** @brief Command frame IDs defined by the MAC sublayer that are listed
* in Table 82 of the standard.
*/
typedef enum
{
MAC_CMD_ASSOC_REQ = 0x01, /**< Association request.*/
MAC_CMD_ASSOC_RESP = 0x02, /**< Association response.*/
MAC_CMD_DISASSOC_NTF = 0x03, /**< Disassociation notification.*/
MAC_CMD_DATA_REQ = 0x04, /**< Data request.*/
MAC_CMD_PANID_CONFLICT_NTF = 0x05, /**< PAN ID conflict notification.*/
MAC_CMD_ORPHAN_NTF = 0x06, /**< Orphan notification.*/
MAC_CMD_BEACON_REQ = 0x07, /**< Beacon request.*/
MAC_CMD_COORD_REALIGN = 0x08, /**< Coordinator realignment.*/
MAC_CMD_GTS_REQ = 0x09 /**< GTS request.*/
} mac_command_id_t;
/** @} */
#endif // MAC_COMMON_H_INCLUDED

View File

@@ -0,0 +1,333 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MCPS_DATA_H_INCLUDED
#define MAC_MCPS_DATA_H_INCLUDED
#include <stdint.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC Data module declares the MAC Data transmittion routines and necessary types
* according to the MAC specification.
*
* @defgroup mac_data MAC MCPS Data API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MCPS Data API.
* @details The MAC MCPS Data module declares the MAC Data transmission routines and necessary types according
* to the MAC specification. More specifically, MAC data request mcps_data_req(), and MAC Data
* indication mcps_data_ind() primitives are declared. The confirmation callback typedef is
* declared as mcps_data_conf_cb_t.
*/
/**
* @brief TX options bit fields.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.1.
*/
#define TX_ACKNOWLEDGED_BIT (0)
#define TX_GTS_BIT (1)
#define TX_INDIRECT_BIT (2)
/**
* @brief TX options for MAC data transmission.
*
* @details The three bits (b0, b1, b2) indicate the transmission options for this MSDU.
* For b0, 1 = acknowledged transmission, 0 = unacknowledged transmission.
* For b1, 1 = GTS transmission, 0 = CAP transmission for a beacon-enabled PAN.
* For b2, 1 = indirect transmission, 0 = direct transmission.
* For a nonbeacon-enabled PAN, bit b1 should always be set to 0.
*/
typedef struct
{
uint8_t ack : 1;
uint8_t gts : 1;
uint8_t indirect : 1;
uint8_t : 5;
} mac_tx_options_t;
/**
* @brief MCPS-DATA.confirm.
*
* @details The MCPS-DATA.confirm primitive reports the results of a request to transfer
* a data SPDU (MSDU) from a local SSCS entity to a single peer SSCS entity.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.2.
*/
typedef struct
{
/** The handle associated with the MSDU being confirmed. */
uint8_t msdu_handle;
/** The status of the last MSDU transmission. */
mac_status_t status;
/**
* Optional. The time, in symbols, at which the data was transmitted (see 7.5.4.1).
*
* The value of this parameter will be considered valid only if the value of the
* status parameter is SUCCESS; if the status parameter is not equal to
* SUCCESS, the value of the Timestamp parameter will not be used for any other
* purpose. The symbol boundary is described by macSyncSymbolOffset (see Table 86 in 7.4.1).
*
* This is a 24-bit value, and the precision of this value will be a minimum of 20 bits,
* with the lowest 4 bits being the least significant.
*/
uint32_t timestamp;
} mcps_data_conf_t;
/**
* @brief MCPS-DATA.request.
*
* @details The MCPS-DATA.request primitive requests the transfer of
* a data SPDU (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.1.
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mcps_data_conf_t confirm;
/**
* The source addressing mode for this primitive and
* subsequent MPDU. This value can take one of the following values:
* @ref mac_addr_mode_t
* 0x00 = no address (addressing fields omitted, see 7.2.1.1.8).
* 0x01 = reserved.
* 0x02 = 16-bit short address.
* 0x03 = 64-bit extended address.
*/
mac_addr_mode_t src_addr_mode;
/**
* The destination addressing mode for this primitive
* and subsequent MPDU.
* According to 7.1.1.1.1, Table 41.
*/
mac_addr_mode_t dst_addr_mode;
/** The 16-bit PAN identifier of the entity to which the MSDU is being transferred. */
uint16_t dst_pan_id;
/** The individual device address of the entity to which the MSDU is being transferred. */
mac_addr_t dst_addr;
/** The number of octets contained in the MSDU to be transmitted by
* the MAC sublayer entity.
*/
uint8_t msdu_length;
/**
* The pointer to the set of octets forming the MSDU
* to be transmitted by the MAC sublayer entity.
*
* Caller must provide enough space for MAC and PHY header before this pointer.
*/
uint8_t * msdu;
/** The handle associated with the MSDU to be transmitted by the MAC sublayer entity. */
uint8_t msdu_handle;
/**
* The bits (b0, b1, b2) indicate the transmission options for this MSDU.
* For b0, 1 = acknowledged transmission, 0 = unacknowledged transmission.
* For b1, 1 = GTS transmission, 0 = CAP transmission for a beacon-enabled PAN.
* For b2, 1 = indirect transmission, 0 = direct transmission.
* For a nonbeacon-enabled PAN, bit b1 should always be set to 0.
*/
mac_tx_options_t tx_options;
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID node. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mcps_data_req_t;
/**
* @brief Private information passed with MCPS-DATA.indication.
* Not covered by the standard.
*/
typedef struct
{
/** RSSI value, which corresponds to packet that caused this indication. */
int8_t rssi;
/** Value of a pending bit from MHR. */
uint8_t pending_bit;
} mcps_data_ind_private_t;
/**
* @brief MCPS-DATA.indication
*
* @details The MCPS-DATA.indication primitive indicates the transfer of
* a data SPDU (i.e., MSDU) from the MAC sublayer to the local SSCS entity.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.3
*/
typedef struct
{
mcps_data_ind_private_t service;
/**
* The source addressing mode for this primitive corresponding to the received MPDU.
* According to 7.1.1.1.1, Table 43.
*/
mac_addr_mode_t src_addr_mode;
/** The 16-bit PAN identifier of the entity from which the MSDU was received. */
uint16_t src_pan_id;
/** The individual device address of the entity from which the MSDU was received. */
mac_addr_t src_addr;
/**
* The destination addressing mode for this primitive corresponding to the received MPDU.
* According to 7.1.1.1.1, Table 43.
*/
mac_addr_mode_t dst_addr_mode;
/** The 16-bit PAN identifier of the entity to which the MSDU is being transferred. */
uint16_t dst_pan_id;
/** The individual device address of the entity to which the MSDU is being transferred. */
mac_addr_t dst_addr;
/** The number of octets contained in the MSDU being indicated by the MAC sublayer entity. */
uint8_t msdu_length;
/**
* The information that is required for the next higher layer to read incoming message and to
* free the memory allocated for this message.
*/
mac_payload_descriptor_t msdu;
/**
* LQI value measured during reception of the MPDU.
* Lower values represent lower LQI (see 6.9.8).
*/
uint8_t mpdu_link_quality;
/** The DSN of the received data frame. */
uint8_t dsn;
/**
* Optional. The time, in symbols, at which the data was received (see 7.5.4.1).
* The symbol boundary is described by macSyncSymbolOffset (see Table 86 in 7.4.1).
*
* This is a 24-bit value, and the precision of this value shall be a minimum of 20 bits,
* with the lowest 4 bits being the least significant.
*/
uint32_t timestamp;
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID node. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mcps_data_ind_t;
/**
* @brief Confirmation function.
*
* @details The MCPS-DATA.confirm primitive is generated by the MAC sublayer
* entity in response to an MCPS-DATA. request primitive. The MCPS-DATA.confirm
* primitive returns a status of either SUCCESS, indicating that the request to
* transmit was successful, or the appropriate error code.
* The status values are fully described in 7.1.1.1.3 and subclauses referenced by 7.1.1.1.3.
*
* @param Pointer to confirmation primitive.
*/
typedef void (* mcps_data_conf_cb_t)(mcps_data_conf_t *);
/**
* @brief MCPS-DATA.request service
*
* @details The MCPS-DATA.request primitive is generated by a local SSCS entity
* when a data SPDU (i.e., MSDU) is to be transferred to a peer SSCS entity.
* After request completion, user callback will be issued with
* valid data stored in structure @ref mcps_data_conf_t.
*
* @param req Pointer to MCPS-DATA request structure.
* @param conf_cb Pointer to confirmation function (user callback).
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.2.
*/
void mcps_data_req(mcps_data_req_t * req, mcps_data_conf_cb_t conf_cb);
/**
* @brief MCPS-DATA.indication handler.
*
* @details The MCPS-DATA.indication primitive is generated by the MAC sublayer and
* issued to the SSCS on receipt of a data frame at the local MAC sublayer entity
* that passes the appropriate message filtering operations as described in 7.5.6.2.
*
* @param ind MCPS-DATA.indication structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.3.
*/
extern void mcps_data_ind(mcps_data_ind_t * ind);
/**
* @brief Free memory allocated for incoming message.
*
* @details The function will be invoked after all manipulations
* with MSDU are completed. That is necessary to return the memory allocated by MAC
* into the heap.
*
* @param p_payload_descriptor - Pointer to MSDU descriptor.
*/
void mac_mem_msdu_free(mac_payload_descriptor_t * p_payload_descriptor);
/** @} */
#endif // MAC_MCPS_DATA_H_INCLUDED

View File

@@ -0,0 +1,152 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MCPS_PURGE_H_INCLUDED
#define MAC_MCPS_PURGE_H_INCLUDED
#if (CONFIG_PURGE_ENABLED == 1)
#include <stdint.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC Purge module declares the MAC Purge routines and necessary types
* according to the MAC specification.
*
* @defgroup mac_purge MAC MCPS Purge API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MCPS Purge API.
* @details The MAC MCPS Purge module declares the MAC Purge routines and necessary types according to
* the MAC specification. More specifically, MAC purge request mcps_purge_req(), and the
* confirmation callback typedef is declared as mcps_purge_conf_cb_t. An additional primitive
* not covered by the standard is declared. This is mpcs_purge() which is a synchronous version
* of mcps_purge_req().
*/
/**
* @brief MCPS-PURGE.confirm.
*
* @details The MCPS-PURGE.confirm primitive allows the MAC sublayer to notify the next higher layer
* of the success of its request to purge an MSDU from the transaction queue.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.5.
*/
typedef struct
{
/** The handle of the MSDU to be purged from the transaction queue. */
uint8_t msdu_handle;
/** The status of the request to be purged an MSDU from the transaction queue. */
mac_status_t status;
} mcps_purge_conf_t;
/**
* @brief MCPS-PURGE.request.
*
* @details The MCPS-PURGE.request primitive allows the next higher layer
* to purge an MSDU from the transaction queue.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.4.
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirmation to this request. */
mcps_purge_conf_t confirm;
/** The handle of the MSDU to be purged from the transaction queue. */
uint8_t msdu_handle;
} mcps_purge_req_t;
/**
* @brief Confirmation function.
*
* @details The MCPS-PURGE.confirm primitive is generated by the MAC sublayer
* entity in response to an MCPS-PURGE.request primitive. The MCPS-PURGE.confirm
* primitive returns a status of either SUCCESS, indicating that the purge request
* was successful, or INVALID_HANDLE, indicating an error.
* The status values are fully described in 7.1.1.4.3.
*
* @param Pointer to confirmation primitive.
*/
typedef void (* mcps_purge_conf_cb_t)(mcps_purge_conf_t *);
/**
* @brief MCPS-PURGE.request service.
*
* @details The MCPS-PURGE.request primitive is generated by the next higher layer
* whenever an MSDU is to be purged from the transaction queue.
* After request completion, user callback will be issued with
* valid data stored in structure mcps_purge_conf_t.
*
* @param req Pointer to MCPS-PURGE request structure.
* @param conf_cb Pointer to the confirmation function (user callback).
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.1.4.
*/
void mcps_purge_req(mcps_purge_req_t * req, mcps_purge_conf_cb_t conf_cb);
/**
* @brief Performs MCPS-PURGE.request directly (without request - confirm approach).
*
* @details Optional. Not covered by the standard.
*
* The MCPS-PURGE.request primitive is generated by the next higher layer
* whenever an MSDU is to be purged from the transaction queue.
*
* @param req Pointer to MCPS-PURGE request structure.
*
* @return Result of the purge procedure.
*/
mac_status_t mcps_purge(mcps_purge_req_t * req);
/** @} */
#endif // (CONFIG_PURGE_ENABLED == 1)
#endif // MAC_MCPS_PURGE_H_INCLUDED

View File

@@ -0,0 +1,336 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_ASSOCIATE_H_INCLUDED
#define MAC_MLME_ASSOCIATE_H_INCLUDED
#include <stdint.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC Association module declares the MAC Association routines and necessary types/macros
* according to the MAC specification.
*
* @defgroup mac_assoc MAC MLME Association API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Association API.
* @details The MLME Association module declares Association MAC routines and necessary macros/types according
* to the MAC specification. More specifically, MLME Association request aka mlme_associate_req(),
* MLME Association confirm callback typedef aka mlme_associate_conf_cb_t, MLME Association indication
* as mlme_associate_ind(), and MLME Response aka mlme_associate_resp() primitives are declared.
*/
/**
* @brief Capability information field.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.3.1.2.
*/
#define ALTERNATE_PAN_COORDINATOR_BIT (0)
#define DEVICE_TYPE_BIT (1)
#define POWER_SOURCE_BIT (2)
#define RECEIVER_ON_WHEN_IDLE_BIT (3)
#define SECURITY_CAPABILITY_BIT (6)
#define ALLOCATE_ADDRESS_BIT (7)
/**
* @brief Valid values of the Association Status field
*
* In accordance with IEEE Std 802.15.4-2006, section 7.3.2.3
*/
typedef enum
{
MAC_ASSOCIATION_SUCCESSFUL = 0,
MAC_PAN_AT_CAPACITY,
MAC_PAN_ACCESS_DENIED
} mac_association_status_t;
/**
* @brief Capability information field
*
* In accordance with IEEE Std 802.15.4-2006, section 7.3.1.2.
*/
typedef struct
{
uint8_t alternate_pan_coordinator : 1;
uint8_t device_type : 1;
uint8_t power_source : 1;
uint8_t rx_on_when_idle : 1;
uint8_t reserved : 2;
uint8_t security_capability : 1;
uint8_t allocate_address : 1;
} mac_capability_t;
/**@brief The Alternate PAN Coordinator subfield of the Capability Information field. */
typedef enum
{
MAC_CAP_CANNOT_BE_PAN_COORD = 0, /**< Device is not capable of becoming
the PAN coordinator.*/
MAC_CAP_CAN_BE_PAN_COORD /**< Device is capable of becoming
the PAN coordinator.*/
} mac_cap_alt_pan_coord_t;
/**@brief The Device Type subfield of the Capability Information field. */
typedef enum
{
MAC_CAP_RFD_DEVICE = 0, /**< Device is an RFD.*/
MAC_CAP_FFD_DEVICE /**< Device is an FFD.*/
} mac_cap_device_type_t;
/**@brief The Power Source subfield of the Capability Information field. */
typedef enum
{
MAC_CAP_BATTERY_POWERED = 0, /**< Device is not AC-powered.*/
MAC_CAP_MAINS_POWERED /**< Device is receiving power from the
alternating current mains.*/
} mac_cap_power_source_t;
/**@brief The Receiver On When Idle subfield of the Capability Information field. */
typedef enum
{
MAC_CAP_RX_OFF_WHEN_IDLE = 0, /**< Device conserves power during idle.*/
MAC_CAP_RX_ON_WHEN_IDLE /**< Device does not disable its receiver
to conserve power during idle periods.*/
} mac_cap_rx_when_idle_t;
/**@brief The Security Capability subfield of the Capability Information field. */
typedef enum
{
MAC_CAP_CANNOT_SECURE = 0, /**< Device does not support securing.*/
MAC_CAP_CAN_SECURE /**< Device is capable of sending and receiving
cryptographically protected MAC frames.*/
} mac_cap_secure_t;
/**@brief The Allocate Address subfield of the Capability Information field. */
typedef enum
{
MAC_CAP_SHORT_ADDR_NOT_REQ = 0, /**< The coordinator will not allocate a
16-bit short address as a result of
the association procedure.*/
MAC_CAP_SHORT_ADDR_REQ /**< The coordinator will allocate a
16-bit short address as a result of
the association procedure.*/
} mac_cap_allocate_addr_t;
#if (CONFIG_ASSOCIATE_REQ_ENABLED == 1)
/**
* @brief MLME-ASSOCIATE.confirm
*
* The MLME-ASSOCIATE.confirm primitive is generated by the initiating MLME and
* issued to its next higher layer in response to an MLME-ASSOCIATE.request primitive.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.3.4.
*/
typedef struct
{
uint16_t assoc_short_address; /**< Association short 16-bit address. */
mac_status_t status; /**< Status of operation. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_associate_conf_t;
/**
* @brief MLME-ASSOCIATE.request.
*
* @details Allows a device to request an association with a coordinator.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.3.1.
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirmation to this request. */
mlme_associate_conf_t confirm;
/**
* A total of 27 channels numbered 0 to 26.
* are available per channel page (section 6.1.2.1).
*/
uint8_t logical_channel;
/**
* A total of 32 channel pages are available
* with channel pages 3 to 31 being reserved
* for future use (section 6.1.2.2).
*/
#ifdef CONFIG_SUB_GHZ
uint8_t channel_page; /**< Channel page. */
#endif
mac_addr_mode_t coord_addr_mode; /**< Coordinator address mode. */
uint16_t coord_pan_id; /**< Coordinator PAN ID. */
mac_addr_t coord_address; /**< Coordinator address. */
mac_capability_t capability_information; /**< Capability information. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_associate_req_t;
#if (CONFIG_ASSOCIATE_IND_ENABLED == 1)
/**
* @brief MLME-ASSOCIATE.indication.
*
* @details The MLME-ASSOCIATE.indication primitive is generated by the MLME of
* the coordinator and issued to its next higher layer to indicate the reception
* of an association request command.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.3.2.
*/
typedef struct
{
uint64_t device_address; /**< 64-bit IEEE address. */
uint8_t capability_information; /**< Capability information. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_associate_ind_t;
/**
* @brief MLME-ASSOCIATE.response.
*
* @details Generated by the next higher layer of a coordinator and issued
* to its MLME in order to respond to the MLME-ASSOCIATE.indication primitive.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.3.3.
*/
typedef struct
{
uint64_t device_address; /**< 64-bit IEEE address. */
uint16_t assoc_short_address; /**< Association short 16-bit address. */
mac_association_status_t status; /**< Status of operation. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_associate_resp_t;
#endif // (CONFIG_ASSOCIATE_IND_ENABLED == 1)
/**
* @brief Confirmation function.
*
* @details The MLME-ASSOCIATE.confirm primitive is generated by the
* initiating MLME and issued to its next higher layer in response to
* an MLME-ASSOCIATE.request primitive. If the request was successful,
* the status parameter will indicate a successful association, as
* contained in the Status field of the association response command.
* Otherwise, the status parameter indicates either an error code from
* the received association response command or the appropriate error
* code from Table 50.
* The status values are fully described in 7.1.3.1.3 and subclauses referenced by 7.1.3.1.3.
*
* @param Pointer to confirmation primitive.
*/
typedef void (* mlme_associate_conf_cb_t)(mlme_associate_conf_t *);
/**
* @brief MLME-ASSOCIATE request.
*
* @details Requests an association with a PAN through a coordinator
* After request completion, user callback will be issued with
* valid data stored in structure mlme_set_conf_t.
*
* @param req MLME_ASSOCIATE request structure.
* @param conf_cb Pointer to user callback.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.3.5
*/
void mlme_associate_req(mlme_associate_req_t * req, mlme_associate_conf_cb_t conf_cb);
#if (CONFIG_ASSOCIATE_IND_ENABLED == 1)
/**
* @brief MLME-ASSOCIATE indication handler.
*
* @details Indicates an association with a PAN through a coordinator
* next higher layer of a coordinator receives the MLME-ASSOCIATE.indication
* primitive to determine whether to accept or reject the unassociated device
* using an algorithm outside the scope of standard.
*
* @param ind MLME ASSOCIATE indication structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.3.5.
*/
extern void mlme_associate_ind(mlme_associate_ind_t * ind);
/**
* @brief MLME-ASSOCIATE response.
*
* @details Respond to an association with a PAN and issue to its MLME in order to
* respond to the MLME-ASSOCIATE.indication.
* Response structure passed as a parameter to this function must be retained
* in memory until the related MLME-COMM-STATUS.indication is received.
*
* @param resp MLME_ASSOCIATE response structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.3.5.
*/
void mlme_associate_resp(mlme_associate_resp_t * resp);
#endif // (CONFIG_ASSOCIATE_IND_ENABLED == 1)
#endif // (CONFIG_ASSOCIATE_REQ_ENABLED == 1)
/** @} */
#endif // MAC_MLME_ASSOCIATE_H_INCLUDED

View File

@@ -0,0 +1,175 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_BEACON_NOTIFY_H_INCLUDED
#define MAC_MLME_BEACON_NOTIFY_H_INCLUDED
#include <stdint.h>
#include <stdbool.h>
#include "mac_common.h"
#include "mac_time.h"
/** @file
* The MAC Beacon notify module declares the MAC beacon notification routine and necessary
* types/macros according to the MAC specification.
*
* @defgroup mac_beacon_notify MAC MLME Beacon Notify API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Beacon Notify API.
* @details The MAC Beacon Notify module declares Beacon Notify MLME routines and necessary macros/types
* according to the MAC specification. MAC MLME Beacon notify indication is declared as
* mlme_beacon_notify_ind().
*/
/**@brief This constant is defined in 7.2.2.1.7 Address List field
*
* @details The maximum number of addresses pending shall be limited to seven and may comprise
* both short and extended addresses.
*/
#define MAC_PENDING_ADDR_MAX 7
/*@brief The maximum length of GTS fields inside beacon in octets.
*
* @details This definition is used to allocate memory for outgoing beacon.
*/
#define MAC_MAX_GTS_FIELD_LEN 23
/**@brief Superframe specification structure.*/
typedef struct
{
uint16_t beacon_order : 4;
uint16_t superframe_order : 4;
uint16_t final_cap_slot : 4;
uint16_t battery_life_extension : 1;
uint16_t reserved : 1;
uint16_t pan_coordinator : 1;
uint16_t association_permit : 1;
} mac_superframe_spec_t;
/** @brief List of pending addresses
* Short addresses are at the top of the table.
*/
typedef struct
{
mac_addr_t addr_list[MAC_PENDING_ADDR_MAX];
/**< Addresses array. */
uint8_t short_addr_number; /**< Number of short addresses in the array. */
uint8_t ext_addr_number; /**< Number of long addresses in the array. */
} mac_pending_addr_list_t;
/**@brief PAN Descriptor structure.
*
* @details See Table 55-Elements of PANDescriptor.
*/
typedef struct
{
mac_addr_mode_t coord_addr_mode; /**< Coordinator addressing mode. */
uint16_t coord_pan_id; /**< Coordinator PAN ID. */
mac_addr_t coord_address; /**< Coordinator address. */
uint8_t logical_channel; /**< Logical channel. */
#ifdef CONFIG_SUB_GHZ
uint8_t channel_page; /**< Channel page. */
#endif
mac_superframe_spec_t superframe_spec; /**< Superframe specification. */
bool gts_permit; /**< Is GTS permitted? */
uint8_t link_quality; /**< Link quality. */
mac_timestamp_t timestamp; /**< Timestamp. */
#if (CONFIG_SECURE == 1)
uint8_t security_failure; /**< Security failure. */
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mac_pan_descriptor_t;
/**@brief Pending Address Specification
*
* @details See Figure 51-Format of the Pending Address Specification field.
*/
typedef struct
{
uint8_t pending_short : 3;
uint8_t : 1;
uint8_t pending_extended : 3;
uint8_t : 1;
} mac_pend_addr_spec_t;
/**@brief MLME-BEACON-NOTIFY.indication parameters
*
* @details See 7.1.5.1 MLME-BEACON-NOTIFY.indication
*/
typedef struct
{
uint8_t bsn; /**< Beacon sequence number. */
mac_pan_descriptor_t pan_descriptor; /**< PAN descriptor. */
mac_pend_addr_spec_t pend_addr_spec; /**< Pending address specification. */
mac_addr_t addr_list[MAC_PENDING_ADDR_MAX];
/**< Addresses array. */
uint8_t sdu_length; /**< SDU length. */
mac_payload_descriptor_t sdu; /**< SDU. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_beacon_notify_ind_t;
/**@brief User implemented function, which handles MLME-BEACON-NOTIFY.indication.
*
* @details The MLME-BEACON-NOTIFY.indication primitive is used to send parameters contained
* within a beacon frame received by the MAC sublayer to the next higher layer.
* The primitive also sends a measure of the LQI and the time the beacon frame
* was received. See 7.1.5.1 MLME-BEACON-NOTIFY.indication.
*
* @param ind MLME-BEACON-NOTIFY.indication parameters. See @ref mlme_beacon_notify_ind_t.
*/
extern void mlme_beacon_notify_ind(mlme_beacon_notify_ind_t * ind);
/** @} */
#endif // MAC_MLME_BEACON_NOTIFY_H_INCLUDED

View File

@@ -0,0 +1,135 @@
// Terms and conditions of usage are described in detail in NORDIC
// SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
//
// Licensees are granted free, non-transferable use of the information. NO
// WARRANTY of ANY KIND is provided. This heading must NOT be removed from
// the file.
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_COMM_STATUS_H_INCLUDED
#define MAC_MLME_COMM_STATUS_H_INCLUDED
#include <stdint.h>
#include "mac_common.h"
/** @file
* The MAC Comm Status module declares the MAC communication status indication routine and
* necessary types/macros according to the MAC specification.
*
* @defgroup mac_comm_status MAC MLME Comm Status API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Comm Status API.
* @details The MAC Comm Status module declares communication status indication MLME routine and necessary
* macros/types according to the MAC specification. MAC MLME Comm Status indication is declared as
* mlme_comm_status_ind().
*/
/**
* @brief MLME-COMM-STATUS.indication
*
* @details The MLME-COMM-STATUS.indication primitive allows the MLME to indicate a
* communication status.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.12.1
*/
typedef struct
{
/**
* The 16-bit PAN identifier of the device from which the frame was received or to
* which the frame was being sent.
*/
uint16_t pan_id;
/**
* The source addressing mode for this primitive. This value can take one of the
* following values:
* @ref mac_addr_mode_t
* 0x00 = no address (addressing fields omitted).
* 0x01 = reserved.
* 0x02 = 16-bit short address.
* 0x03 = 64-bit extended address.
*/
mac_addr_mode_t src_addr_mode;
/**
* The individual device address of the entity from which the frame causing the error
* originated.
*/
mac_addr_t src_addr;
/**
* The destination addressing mode for this primitive.
* According to 7.1.12.1.1, Table 69.
*/
mac_addr_mode_t dst_addr_mode;
/** The individual device address of the device for which the frame was intended. */
mac_addr_t dst_addr;
/** The communications status. */
mac_status_t status;
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
} mlme_comm_status_ind_t;
/**
* @brief MLME-COMM-STATUS.indication handler
*
* @details The MLME-COMM-STATUS.indication primitive is generated by the MLME and issued to its next higher
* layer either following a transmission instigated through a response primitive or on receipt of a frame that
* generates an error in its security processing (see 7.5.8.2.3).
*
* @param ind MLME-COMM-STATUS.indication structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.12.1
*/
extern void mlme_comm_status_ind(mlme_comm_status_ind_t * ind);
/** @} */
#endif // MAC_MLME_COMM_STATUS_H_INCLUDED

View File

@@ -0,0 +1,199 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_DISASSOCIATE_H_INCLUDED
#define MAC_MLME_DISASSOCIATE_H_INCLUDED
#if (CONFIG_DISASSOCIATE_ENABLED == 1)
#include <stdint.h>
#include <stdbool.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME Disassociate module declares the MAC disassociation routines and
* necessary types/macros according to the MAC specification.
*
* @defgroup mac_diassociate MAC MLME Disassociate API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Disassociate API.
* @details The MLME Disassociation module declares Disassociation MAC routines and necessary types
* according to the MAC specification. More specifically, MLME Disassociation request aka
* mlme_disassociate_req(), MLME Disassociation confirm callback typedef aka
* mlme_disassociate_conf_cb_t, and MLME Disassociation indication as mlme_disassociate_ind()
* primitives are declared.
*/
/**
* @brief MAC Disassociation Reason field
*
* In accordance with IEEE Std 802.15.4-2006, section 7.3.2.2
*/
typedef enum
{
/** The coordinator wishes the device to leave the PAN. */
MAC_COORD_REASON = 1,
/** The device wishes to leave the PAN. */
MAC_DEV_REASON = 2
} mac_disassociate_reason_t;
/**
* @brief MLME-DISASSOCIATE.confirm
*
* @details On receipt of the MLME-DISASSOCIATE.confirm primitive, the next
* higher layer of the initiating device is notified of the result of the
* disassociation attempt. If the disassociation attempt was successful,
* the status parameter will be set to SUCCESS. Otherwise, the status parameter
* indicates the error.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.4.3
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
mac_addr_mode_t device_addr_mode; /**< Device addressing mode. */
uint16_t device_pan_id; /**< Device PAN ID. */
mac_addr_t device_address; /**< Device address. */
} mlme_disassociate_conf_t;
/**
* @brief MLME-DISASSOCIATE.request
*
* @details The MLME-DISASSOCIATE.request primitive is generated by the next
* higher layer of an associated device and issued to its MLME to request
* disassociation from the PAN. It is also generated by the next higher layer
* of the coordinator and issued to its MLME to instruct an
* associated device to leave the PAN.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.4.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_disassociate_conf_t confirm;
mac_addr_mode_t device_addr_mode; /**< Device addressing mode. */
uint16_t device_pan_id; /**< Device PAN ID. */
mac_addr_t device_address; /**< Device address. */
mac_disassociate_reason_t disassociate_reason; /**< Disassociation reason. */
bool tx_indirect; /**< Is TX indirect? */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_disassociate_req_t;
/**
* @brief MLME-DISASSOCIATE.indication
*
* @details Is generated by the MLME and issued to its next higher
* layer on receipt of a disassociation notification command.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.4.2
*/
typedef struct
{
uint64_t device_address; /**< Device address. */
mac_disassociate_reason_t disassociate_reason; /**< Disassociation reason. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_disassociate_ind_t;
/**
* @brief Customer's function of confirmation
*
* @details The MLME-DISASSOCIATE.confirm primitive is generated by the initiating
* MLME and issued to its next higher layer in response to an MLME-DISASSOCIATE.request
* primitive. This primitive returns a status of either SUCCESS, indicating that the
* disassociation request was successful, or the appropriate error code.
* The status values are fully described in 7.1.4.1.3 and subclauses referenced by 7.1.4.1.3.
*
* @param pointer to confirmation primitive
*/
typedef void (* mlme_disassociate_conf_cb_t)(mlme_disassociate_conf_t *);
/**
* @brief MLME-DISASSOCIATE request
*
* @details Request disassociation with a PAN
* After request completion, user callback will be issued with
* valid data stored in structure @ref mlme_disassociate_conf_t.
*
* @param req MLME_DISASSOCIATE request structure.
* @param conf_cb pointer to user callback.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.4.4
*/
void mlme_disassociate_req(mlme_disassociate_req_t * req, mlme_disassociate_conf_cb_t conf_cb);
/**
* @brief MLME-DISASSOCIATE indication handler
*
* @details Indicates an disassociation with a PAN
*
* @param ind MLME_DISASSOCIATE indication structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.4.4
*/
extern void mlme_disassociate_ind(mlme_disassociate_ind_t * ind);
/** @} */
#endif // (CONFIG_DISASSOCIATE_ENABLED == 1)
#endif // MAC_MLME_DISASSOCIATE_H_INCLUDED

View File

@@ -0,0 +1,211 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_GTS_H_INCLUDED
#define MAC_MLME_GTS_H_INCLUDED
#if (CONFIG_GTS_ENABLED == 1)
#include <stdint.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME GTS module declares the MAC Guaranteed time slots routines and
* necessary types/macros according to the MAC specification.
*
* @defgroup mac_gts MAC MLME GTS API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME GTS API.
* @details The MAC GTS module declares MAC Guaranteed Time Slots routines and necessary types according to
* the MAC specification. More specifically, MLME GTS request aka mlme_gts_req(), MLME GTS indicaton
* aka mlme_gts_ind(), and MLME GTS confirm callback typedef aka mlme_gts_conf_cb_t primitives are
* declared.
*/
/**@brief GTS directions, from device side. */
typedef enum
{
MAC_GTS_DIR_TXONLY = 0, /**< TX only direction. */
MAC_GTS_DIR_RXONLY = 1 /**< RX only direction. */
} mac_gts_direction_t;
/**@brief GTS characteristics type. */
typedef enum
{
MAC_GTS_DEALLOC = 0, /**< GTS Dealloc. */
MAC_GTS_ALLOC = 1 /**< GTS Alloc. */
} mac_gts_characteristics_type_t;
/**@brief MAC GTS characteristics (not packed)
*
* @details See Section 7.3.9.2
*/
typedef union
{
struct
{
uint8_t gts_length : 4;
uint8_t gts_direction : 1;
uint8_t characterictics_type : 1;
uint8_t : 2;
} bit;
uint8_t all;
} mac_gts_characteristics_t;
/**
* @brief MLME-GTS.confirm
*
* @details The MLME-GTS.confirm primitive reports the results of a
* request to allocate a new GTS or deallocate an existing GTS.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.7.2
*/
typedef struct
{
mac_gts_characteristics_t gts_characteristics; /**< GTS characteristics. */
mac_status_t status; /**< Status of operation. */
} mlme_gts_conf_t;
/**
* @brief MLME-GTS.request
*
* @details The MLME-GTS.request primitive allows a device to send a request
* to the PAN coordinator to allocate a new GTS or to deallocate an existing GTS.
* This primitive is also used by the PAN coordinator to initiate a GTS deallocation.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.7.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_gts_conf_t confirm;
mac_gts_characteristics_t gts_characteristics; /**< GTS characteristics. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_gts_req_t;
/**
* @brief MLME-GTS.indication
*
* @details The MLME-GTS.indication primitive indicates that a
* GTS has been allocated or that a previously allocated GTS
* has been deallocated.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.7.3
*/
typedef struct
{
uint16_t device_address; /**< Device address. */
mac_gts_characteristics_t gts_characteristics; /**< GTS characteristics. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_gts_ind_t;
/**
* @brief MLME-GTS confirm callback
*
* @details The MLME-GTS.confirm primitive is generated by the MLME and
* issued to its next higher layer in response to a previously
* issued MLME-GTS.request primitive.
*
* @param MLME_GTS callback structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.7.4
*/
typedef void (* mlme_gts_conf_cb_t)(mlme_gts_conf_t *);
/**
* @brief MLME-GTS request
*
* @details The MLME-GTS.request primitive is generated by the next higher
* layer of a device and issued to its MLME to request the allocation of a
* new GTS or to request the deallocation of an existing GTS. It is also
* generated by the next higher layer of the PAN coordinator and issued to
* its MLME to request the deallocation of an existing GTS.
*
* @param req MLME_GTS request structure.
* @param conf_cb pointer to user callback.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.7.4
*/
void mlme_gts_req(mlme_gts_req_t * req, mlme_gts_conf_cb_t conf_cb);
/**
* @brief MLME-GTS indication handler
*
* @details The MLME-GTS.indication primitive is generated by the MLME of
* the PAN coordinator to its next higher layer whenever a GTS is allocated
* or deallocated following the reception of a GTS request command (see 7.3.9)
* by the MLME. The MLME of the PAN coordinator also generates this primitive when a GTS
* deallocation is initiated by the PAN coordinator itself.
*
* @param ind MLME_GTS indication structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.7.4
*/
extern void mlme_gts_ind(mlme_gts_ind_t * ind);
/** @} */
#endif // (CONFIG_GTS_ENABLED == 1)
#endif // MAC_MLME_GTS_H_INCLUDED

View File

@@ -0,0 +1,151 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_ORPHAN_H_INCLUDED
#define MAC_MLME_ORPHAN_H_INCLUDED
#if (CONFIG_ORPHAN_ENABLED == 1)
#include <stdint.h>
#include <stdbool.h>
#include "mac_common.h"
/** @file
* The MAC MLME Orphan module declares the MAC Orphan routines and
* necessary types/macros according to the MAC specification.
*
* @defgroup mac_orphan MAC MLME Orphan API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Orphan API.
* @details The MAC Orphan module declares routines and necessary types to deal with the Orphan devices
* according to the MAC specification. More specifically, MAC MLME Orphan indication aka
* mlme_orphan_ind(), MAC MLME Orphan response aka mlme_orphan_resp() primitives are declared.
*/
/**
* @brief MLME-ORPHAN.indication
*
* @details The MLME-ORPHAN.indication primitive allows the MLME of a coordinator
* to notify the next higher layer of the presence of an orphaned device.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.8.1
*/
typedef struct
{
/** The address of the orphaned device. */
uint64_t orphan_address;
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_orphan_ind_t;
/**
* @brief MLME-ORPHAN.response
*
* @details The MLME-ORPHAN.response primitive allows the next higher layer of a coordinator
* to respond to the MLME-ORPHAN.indication primitive.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.8.2
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** The address of the orphaned device. */
uint64_t orphan_address;
/**
* The 16-bit short address allocated to the orphaned device if it is associated with this
* coordinator. The special short address 0xfffe indicates that no short address was
* allocated, and the device will use its 64-bit extended address in all communications.
* If the device was not associated with this coordinator, this field will contain the
* value 0xffff and be ignored on receipt.
*/
uint16_t short_address;
/** TRUE if the orphaned device is associated with this coordinator or FALSE otherwise. */
bool associated_member;
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_orphan_resp_t;
/**
* @brief MLME-ORPHAN.indication handler
*
* @details The MLME-ORPHAN.indication primitive is generated by the MLME of a coordinator
* and issued to its next higher layer on receipt of an orphan notification command (see 7.3.6).
*
* @param ind MLME-ORPHAN.indication structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.8.1
*/
extern void mlme_orphan_ind(mlme_orphan_ind_t * ind);
/**
* @brief MLME-ORPHAN.response handler
*
* @details The MLME-ORPHAN.response primitive is generated by the next higher layer and issued to its MLME
* when it reaches a decision about whether the orphaned device indicated in the MLME-ORPHAN.indication
* primitive is associated.
*
* @param resp MLME-ORPHAN.response structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.8.2
*/
void mlme_orphan_resp(mlme_orphan_resp_t * resp);
/** @} */
#endif // (CONFIG_ORPHAN_ENABLED == 1)
#endif // MAC_MLME_ORPHAN_H_INCLUDED

View File

@@ -0,0 +1,508 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_PIB_H_INCLUDED
#define MAC_MLME_PIB_H_INCLUDED
#include <stdint.h>
#include "mac_common.h"
#include "phy_plme_pib.h"
#include "mac_task_scheduler.h"
#include "mac_security.h"
#include "sys_debug.h"
/** @file
* The MAC MLME PIB module declares the MAC PHY Information Base routines and
* necessary types/macros according to the MAC specification.
*
* @defgroup mac_pib MAC MLME PIB API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME PIB API.
* @details The MAC PIB module declares routines and necessary types to deal with the PHY Information Base
* functionality related to MAC. More specifically, MLME PIB Get request aka mlme_get_req(), MLME
* PIB Set request aka mlme_set_req(), MLME PIB confirmation callbacks aka mlme_get_conf_cb_t, and
* mlme_set_conf_cb_t primitives are declared. Two additional primitives not covered by the
* standard are declared. These are mlme_get() and mlme_set() which are synchronous versions of
* mlme_get_req() and mlme_set_req() accordingly. There is one helper informational routine
* mlme_pib_attr_size_calc() to count MLME attribute size in bytes. Refer to the
* mac_pib_param_test application for detailed samples of implementation of these primitives.
* This module also defines the MAC Table API. The tables can be used to deal with MAC attributes.
* A special initialization routine mac_table_init() should be called before using of any other MAC
* table API. The mac_table_reset() routine is used to clean up an existing (initialized) table.
* mac_table_idx_get() searches through a MAC table to find the item with requested idx. The
* mac_table_item_set() routine is needed to substitute a table item with a new value. The
* mac_table_item_remove() routine removes the item with the given index from the table and
* frees all resources associated with the item. mac_table_item_front() and mac_table_item_next()
* return the first and next item from the table. The mac_table_size_get() routine returns the
* number of items in the table, while mac_table_is_empty() checks if the table is empty.
*/
/**
* @brief MAC PIB attribute identifiers
*
* In accordance with IEEE Std 802.15.4-2006, section 7.4.2
*/
typedef enum
{
MAC_ACK_WAIT_DURATION = 0x40,
MAC_ASSOCIATION_PERMIT,
MAC_AUTO_REQUEST,
MAC_BATT_LIFE_EXT,
MAC_BATT_LIFE_EXT_PERIODS,
MAC_BEACON_PAYLOAD, /* 0x45 */
MAC_BEACON_PAYLOAD_LENGTH,
MAC_BEACON_ORDER, /**< Specification of how often the
coordinator transmits its
beacon. If BO = 15, the
coordinator will not transmit
a periodic beacon.*/
MAC_BEACON_TX_TIME,
MAC_BSN,
MAC_COORD_EXTENDED_ADDRESS, /* 0x4A */
MAC_COORD_SHORT_ADDRESS,
MAC_DSN,
MAC_GTS_PERMIT,
MAC_MAX_CSMA_BACKOFFS,
MAC_MIN_BE,
MAC_PAN_ID, /**< PAN Identifier.*/
/* 0x50 */
MAC_PROMISCUOUS_MODE,
MAC_RX_ON_WHEN_IDLE,
MAC_SHORT_ADDRESS, /**< MAC Short Address.*/
MAC_SUPERFRAME_ORDER,
MAC_TRANSACTION_PERSISTENCE_TIME, /* 0x55 */
MAC_ASSOCIATED_PAN_COORD,
MAC_MAX_BE,
MAC_MAX_FRAME_TOTAL_WAIT_TIME,
MAC_MAX_FRAME_RETRIES,
MAC_RESPONSE_WAIT_TIME, /* 0x5A */
MAC_SYNC_SYMBOL_OFFSET,
MAC_TIMESTAMP_SUPPORTED,
MAC_SECURITY_ENABLED,
MAC_MIN_LIFS_PERIOD, /* 0x5E No attribute id in Table 86.*/
MAC_MIN_SIFS_PERIOD, /* 0x5F No attribute id in Table 86.*/
MAC_EXTENDED_ADDRESS, /**< MAC Extended Address.*/
/* 0x60 Not covered by standard.*/
MAC_IS_PAN_COORD,
#if (CONFIG_SECURE == 1)
MAC_KEY_TABLE = 0x71,
MAC_KEY_TABLE_ENTRIES,
MAC_DEVICE_TABLE,
MAC_DEVICE_TABLE_ENTRIES,
MAC_SECURITY_LEVEL_TABLE, /* 0x75 */
MAC_SECURITY_LEVEL_TABLE_ENTRIES,
MAC_FRAME_COUNTER,
MAC_AUTO_REQUEST_SECURITY_LEVEL,
MAC_AUTO_REQUEST_KEY_ID_MODE,
MAC_AUTO_REQUEST_KEY_SOURCE, /* 0x7A */
MAC_AUTO_REQUEST_KEY_INDEX,
MAC_DEFAULT_KEY_SOURCE,
MAC_PAN_COORD_EXTENDED_ADDRESS,
MAC_PAN_COORD_SHORT_ADDRESS,
/* Items below do not covered by the standard */
// these three IDs are used to make access to the root of security tables
MAC_KEY_TABLE_POINTER,
MAC_DEVICE_TABLE_POINTER,
MAC_SECURITY_LEVEL_TABLE_POINTER,
// these three IDs are stored inside PIB base and
// used to get table item sizes
MAC_KEY_ID_LOOKUP_LIST,
MAC_KEY_DEVICE_LIST,
MAC_KEY_USAGE_LIST,
#endif
} mlme_pib_attr_id_t;
/**
* @brief United PIB attribute identifiers
*
* To unite access to MAC and PHY PIB by one API
*/
typedef union
{
mlme_pib_attr_id_t mlme_id; /**< PIB is MAC-based. */
plme_pib_attr_id_t plme_id; /**< PIB is PHY-based. */
} pib_id_t;
/**
* @brief MLME-GET.confirm
*
* @details structure for confirming information about a given PIB attribute.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.6.2
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
pib_id_t pib_attribute; /**< PIB Attribute. */
uint8_t pib_attribute_idx; /**< PIB Attribute index. */
/** value size is calculated with 'mlme_pib_attr_size_calc' */
uint8_t * value; /**< Attribute value. */
} mlme_get_conf_t;
/**
* @brief MLME-GET.request
*
* @details structure for requesting information about a given PIB attribute.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.6.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_get_conf_t confirm;
pib_id_t pib_attribute; /**< PIB Attribute. */
uint8_t pib_attribute_idx; /**< PIB Attribute index. */
} mlme_get_req_t;
/**
* @brief MLME-SET.confirm
*
* @details structure for reporting the results of an attempt to write a value
* to a PIB attribute.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.13.2
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
pib_id_t pib_attribute; /**< PIB Attribute. */
uint8_t pib_attribute_idx; /**< PIB Attribute index. */
} mlme_set_conf_t;
/**
* @brief MLME-SET.request
*
* @details structure for setting a PIB attribute.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.13.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_set_conf_t confirm;
pib_id_t pib_attribute; /**< PIB Attribute. */
uint8_t pib_attribute_idx; /**< PIB Attribute index. */
uint8_t * value; /**< Attribute value. The value size is calculated
with mlme_pib_attr_size_calc. */
} mlme_set_req_t;
/**
* @brief Customer's function of confirmation
*
* @details The MLME-GET.confirm primitive is generated by the MLME and issued
* to its next higher layer in response to an MLME-GET.request primitive.
* This primitive returns a status of either SUCCESS, indicating that the request
* to read a PIB attribute was successful, or an error code of UNSUPPORTED_ATTRIBUTE.
* When an error code of UNSUPPORTED_ATTRIBUTE is returned, the PIBAttribute value
* parameter will be set to length zero. The status values are fully described in 7.1.6.1.3.
*
* @param pointer to confirmation primitive
*/
typedef void (* mlme_get_conf_cb_t)(mlme_get_conf_t *);
/**
* @brief Customer's function of confirmation
*
* @details The MLME-SET.confirm primitive is generated by the MLME and issued to its
* next higher layer in response to an MLME-SET.request primitive. The MLME-SET.confirm
* primitive returns a status of either SUCCESS, indicating that the requested value was
* written to the indicated PIB attribute, or the appropriate error code.
* The status values are fully described in 7.1.13.1.3.
*
* @param pointer to confirmation primitive
*/
typedef void (* mlme_set_conf_cb_t)(mlme_set_conf_t *);
/**
* @brief MLME-GET request
*
* @details Request information about a given PIB attribute.
*
* @param[in] req pointer to request structure.
* @param[in] conf_cb pointer to user callback.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.6.
* See \a mlme_get() for more details.
*/
void mlme_get_req(mlme_get_req_t * req, mlme_get_conf_cb_t conf_cb);
/**
* @brief MLME-SET request
*
* @details Request to set a PIB attribute.
* After request completion, user callback will be issued with
* valid data stored in structure @ref mlme_set_conf_t.
*
* See \a mlme_set() for more details.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.13
*
* @param[in] req MLME_SET request structure.
* @param[in] conf_cb pointer to user callback.
*/
void mlme_set_req(mlme_set_req_t * req, mlme_set_conf_cb_t conf_cb);
/**
* @brief Counts MLME attribute size
*
* @details This is an implementation-specific function not covered by the standard.
*
* @param[in] id attribute id.
* @param[in] idx index inside the table in case the attribute is a table.
*
* @return size of attribute in bytes.
*/
size_t mlme_pib_attr_size_calc(pib_id_t id, uint8_t idx);
/**
* @brief Gets parameters from PIB directly (without request - confirm approach)
*
* @details Optional. Not covered by a standard.
*
* For non-tabled attributes this function will return value to location
* passed to the last argument.
*
* For tabled attributes this function will return pointer to
* a descriptor structure of corresponding table.
*
* @param[in] id attribute id.
* @param[in] idx index inside the table in case the attribute is a table.
* @param[out] mem either pointer to memory where attribute value is returned
* (for all attributes except MAC_KEY_TABLE, MAC_DEVICE_TABLE,
* MAC_SECURITY_LEVEL_TABLE), or pointer to memory where pointer
* to attribute storage place is returned.
*
* @return status of operation
*/
mac_status_t mlme_get(pib_id_t id, uint8_t idx, void * mem);
/**
* @brief Sets parameters to PIB directly (without request - confirm approach)
*
* @details Optional. Not covered by a standard.
*
* This function performs copying or replacement of some attribute value
* into the PIB base memory.
*
* Note, that all security tables are copied into dynamic memory, that
* mlme_set is responsible to allocate. For nested tables copying is done
* in a shallow manner (in Python sense). It means that passed \a mac_key_descr_t
* is copied as-is, without creating copies of internal tables.
* Caller must allocate and prepare all nested tables such as
* #MAC_KEY_DEVICE_LIST, #MAC_KEY_ID_LOOKUP_LIST and #MAC_KEY_USAGE_LIST
* before calling this function.
*
* Passed attribute value will replace the current one, if the item with such
* \a id and \a idx already exists. This function is responsible for
* freeing all items during destruction of existing objects.
*
* @note Nested tables may be expanded and reduced with \a mac_table_item_set()
* and other similar functions.
*
* @param[in] id attribute id.
* @param[in] idx index inside the table in case the attribute is a table.
* @param[out] mem pointer to memory for parameter storing.
*
* @return status of operation
*/
mac_status_t mlme_set(pib_id_t id, uint8_t idx, void * mem);
#if (CONFIG_SECURE == 1)
/**
* @brief Initializes a table. This function MUST be called before accessing
* to a newly allocated table.
*
* @param[out] p_table Pointer to a fresh table.
*/
void mac_table_init(mac_table_t * p_table);
/**
* @brief Resets a table, freeing all its elements.
*
* @param[in] p_table Pointer to the table to reset.
* @param[in] id One of #MAC_KEY_TABLE, #MAC_DEVICE_TABLE, #MAC_SECURITY_LEVEL_TABLE,
* #MAC_KEY_ID_LOOKUP_LIST, #MAC_KEY_DEVICE_LIST, #MAC_KEY_USAGE_LIST to let
* function know about the size of p_item.
*/
void mac_table_reset(mac_table_t * p_table, mlme_pib_attr_id_t id);
/**
* @brief Searches through mac_table_t and finds the item with requested idx.
*
* @param[in] p_table Table to search through.
* @param[in] idx Item idx to match.
*
* @return Pointer to mac_table_item_t with requested idx or NULL if such
* an item cannot be found.
*/
mac_table_item_t * mac_table_idx_get(const mac_table_t * p_table, uint8_t idx);
/**
* @brief Sets new value item for mac_table_t.
*
* @param[out] p_table Pointer to the table to add item to.
* @param[in] p_item Pointer to a new item. This item must include appropriate idx
* (less than the maximum table size).
* @param[in] id One of #MAC_KEY_TABLE, #MAC_DEVICE_TABLE, #MAC_SECURITY_LEVEL_TABLE,
* #MAC_KEY_ID_LOOKUP_LIST, #MAC_KEY_DEVICE_LIST, #MAC_KEY_USAGE_LIST to let
* function know about the size of p_item.
* @param[in] idx Item index inside the selected table.
*
* @details This function performs a "deep copy" of passed table item to conform with
* mlme_set behavior. New copy resides in the heap memory. If an item with requested
* idx has been already set earlier, this function frees the old item and pushes
* a new one instead.
*
* @retval #MAC_INVALID_INDEX if idx exceeds allowed maximum number of items in
* the table.
* @retval #MAC_LIMIT_REACHED if there is no enough dynamic memory to put this item
* into the security table.
* @retval #MAC_SUCCESS if insertion has been performed successfully.
*/
mac_status_t mac_table_item_set(mac_table_t * p_table,
const mac_table_item_t * p_item,
mlme_pib_attr_id_t id,
uint8_t idx);
/**
* @brief Removes an item from a mac_table_t instance and frees all resources,
* associated with this item.
*
* @param[out] p_table Pointer to the table to remove item from.
* @param[in] id One of #MAC_KEY_TABLE, #MAC_DEVICE_TABLE, #MAC_SECURITY_LEVEL_TABLE,
* #MAC_KEY_ID_LOOKUP_LIST, #MAC_KEY_DEVICE_LIST, #MAC_KEY_USAGE_LIST to let
* function perform down-casting correctly.
* @param[in] idx Item index inside of selected table.
*
* @retval #MAC_INVALID_INDEX if passed index is not found in the table or exceeds
* the allowed maximum.
* @retval #MAC_SUCCESS if no errors happen during removing.
*/
mac_status_t mac_table_item_remove(mac_table_t * p_table,
mlme_pib_attr_id_t id,
uint8_t idx);
/**
* @brief Gets first available item from a table.
*
* @details This function might be used along with \a mac_table_item_next to
* search through some table.
*
* @param[in] p_table Pointer to a MAC table.
*
* @return Pointer to the first table item or NULL if the table is empty.
*/
mac_table_item_t * mac_table_item_front(const mac_table_t * p_table);
/**
* @brief Returns the next available item in table.
*
* @details MAC tables are stored unsorted in memory, so there is no guarantee that
* index of the next item is always greater or smaller than the current one.
* Items are not stored in chronological order either.
*
* @param[in] p_table Pointer to a table to select item from.
* @param[in] p_current_item Pointer to the current item.
*
* @return Pointer to the next item in table or NULL, if the item is the last one.
*/
mac_table_item_t * mac_table_item_next(const mac_table_t * p_table,
const mac_table_item_t * p_current_item);
/**
* @brief Gets number of items used inside mac_table_t.
*
* @param[in] p_table Pointer to interested table.
*
* @return 8-bit integer equal to number of items inside the table that have
* been set at least once.
*/
static inline uint8_t mac_table_size_get(const mac_table_t * p_table)
{
ASSERT(p_table != NULL);
return p_table->size;
}
/**
* @brief This function checks if a MAC table is empty.
*
* @param[in] p_table Pointer to a MAC table.
*
* @return true if there are no items inside table, false otherwise.
*/
static inline bool mac_table_is_empty(const mac_table_t * p_table)
{
ASSERT(p_table != NULL);
return sys_queue_is_empty(&p_table->queue);
}
#endif
/** @} */
#endif // MAC_MLME_PIB_H_INCLUDED

View File

@@ -0,0 +1,151 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_POLL_H_INCLUDED
#define MAC_MLME_POLL_H_INCLUDED
#include <stdint.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME Poll module declares the MAC Poll primitives and necessary types
* according to the MAC specification.
*
* @defgroup mac_poll MAC MLME Poll API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Poll API.
* @details The MAC Poll module declares MLME Poll primitives and necessary types according to
* the MAC specification. More specifically, MLME Poll request aka mlme_poll_req(), MLME Poll
* indicaton aka mlme_poll_ind(), and MLME Poll confirm callback typedef aka mlme_poll_conf_cb_t
* primitives are declared.
*/
/**@brief MLME-POLL.confirm
*
* @details The MLME-POLL.confirm primitive reports the results of a request
* to poll the coordinator for data.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.16.2
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
} mlme_poll_conf_t;
/**@brief MLME-POLL.request
*
* @details The MLME-POLL.request primitive prompts the device
* to request data from the coordinator.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.16.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_poll_conf_t confirm;
mac_addr_mode_t coord_addr_mode; /**< Coordinator address mode. */
uint16_t coord_pan_id; /**< Coordinator PAN ID. */
mac_addr_t coord_address; /**< Coordinator address. */
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_poll_req_t;
/** @brief MLME-Poll.indication
*
* @details The MLME-POLL.indication primitive indicates the reception
* of a Data request command frame by the MAC sub-layer and issued to
* the local SSCS (service specific convergence sublayer).
*/
typedef struct
{
mac_addr_mode_t src_addr_mode; /**< Source address mode. */
mac_addr_t src_address; /**< Source address. */
} mlme_poll_ind_t;
/**@brief Prototype of the user-implemented MLME-POLL.confirm callback function.
*
* @details The MLME-POLL.confirm primitive is generated by the MLME and issued
* to its next higher layer in response to an MLME-POLL.request primitive.
* If the request was successful, the status parameter will be equal to SUCCESS,
* indicating a successful poll for data. Otherwise, the status parameter indicates the
* appropriate error code. The status values are fully described in 7.1.16.1.3 and
* the subclauses referenced by 7.1.16.1.3.
*
* @param pointer to a confirmation primitive.
*/
typedef void (* mlme_poll_conf_cb_t)(mlme_poll_conf_t *);
/**@brief MLME-POLL.request
*
* @details The MLME-POLL.request primitive is generated by the next higher layer and
* issued to its MLME when data are to be requested from a coordinator.
*
* @param[in] req MLME-POLL.request parameters
* @param[in] conf_cb User-implemented callback function, which will be
* called by MLME in order to pass MLME-POLL.confirm to the user.
*/
void mlme_poll_req(mlme_poll_req_t * req, mlme_poll_conf_cb_t conf_cb);
/**@brief MLME-POLL.indication
*
* @details The MLME-Poll.indication primitive notifies the next higher level that
* a request for data has been received.
*
* @param[in] p_ind pointer to a poll indication structure
*/
extern void mlme_poll_ind(mlme_poll_ind_t * p_ind);
/** @} */
#endif // MAC_MLME_POLL_H_INCLUDED

View File

@@ -0,0 +1,125 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_RESET_H_INCLUDED
#define MAC_MLME_RESET_H_INCLUDED
#include <stdint.h>
#include <stdbool.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME Reset module declares the MAC Reset primitives and necessary types
* according to the MAC specification.
*
* @defgroup mac_reset MAC MLME Reset API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Reset API.
* @details The MAC Reset module declares MLME Reset primitives and necessary types according to
* the MAC specification. More specifically, MLME Reset request aka mlme_reset_req(), and MLME
* Reset confirm callback typedef aka mlme_reset_conf_cb_t primitives are declared.
*/
/**@brief MLME-Reset.confirm
*
* @details The MLME-Reset.confirm primitive reports the results of a request
* to reset MAC layer of the device.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.9.2
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
} mlme_reset_conf_t;
/**@brief MLME-RESET.request
*
* @details The MLME-RESET.request primitive allows the next
* higher layer to request that the MLME performs a reset operation.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.9.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_reset_conf_t confirm;
bool set_default_pib; /**< Set the default PIB. */
} mlme_reset_req_t;
/**
* @brief MLME-RESET confirm callback
*
* @details The MLME-RESET.confirm primitive is generated by the MLME and
* issued to its next higher layer in response to an MLME-RESET.request primitive and
* following the receipt of the PLME-SET-TRXSTATE.confirm primitive.
*
* @param reset status (@c MAC_SUCCESS only).
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.9.2
*/
typedef void (* mlme_reset_conf_cb_t)(mlme_reset_conf_t *);
/**
* @brief MLME-RESET request
*
* @details The MLME-RESET.request primitive is generated by the next higher layer and
* issued to the MLME to request a reset of the MAC sublayer to its initial conditions.
* The MLME-RESET.request primitive is issued prior to the use of the MLME-START.request
* or the MLME-ASSOCIATE.request primitives.
*
* @param[in] req pointer to MCPS-RESET.request structure.
* @param[in] conf_cb pointer to user callback.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.9.1
*/
void mlme_reset_req(mlme_reset_req_t * req, mlme_reset_conf_cb_t conf_cb);
/** @} */
#endif // MAC_MLME_RESET_H_INCLUDED

View File

@@ -0,0 +1,181 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_RX_ENABLE_H_INCLUDED
#define MAC_MLME_RX_ENABLE_H_INCLUDED
#if (CONFIG_RXE_ENABLED == 1)
#include <stdint.h>
#include <stdbool.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME RX-Enable module declares the MAC RX-Enable primitives and necessary types
* according to the MAC specification.
*
* @defgroup mac_rx_enable MAC MLME RX-Enable API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME RX-Enable API.
* @details The MAC RX-Enable module declares MLME RX-Enable primitives and necessary types according to
* the MAC specification. More specifically, MLME RX-Enable request aka mlme_rx_enable_req(),
* and MLME RX-Enable confirm callback typedef aka mlme_rx_enable_conf_cb_t primitives are
* declared. One additional primitive not covered by the standard is declared. This is
* mlme_rx_enable() which is synchronous (i.e. does not require confirmation) version of
* mlme_rx_enable_req().
*/
/**
* @brief MLME-RX-ENABLE.confirm
*
* @details The MLME-RX-ENABLE.confirm primitive reports the results of an attempt
* to enable or disable the receiver.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.10.2
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
} mlme_rx_enable_conf_t;
/**
* @brief MLME-RX-ENABLE.request
*
* @details The MLME-RX-ENABLE.request primitive allows the next higher layer
* to request that the receiver is either enabled for a finite period of time or disabled.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.10.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_rx_enable_conf_t confirm;
/**
* @details
* TRUE if the requested operation can be deferred until the next superframe
* if the requested time has already passed.
* FALSE if the requested operation is only to be attempted in the current superframe.
*
* If the issuing device is the PAN coordinator, the term superframe refers to its own
* superframe. Otherwise, the term refers to the superframe of the coordinator through
* which the issuing device is associated.
*
* @note This parameter is ignored for nonbeacon-enabled PANs.
*/
bool defer_permit;
/**
* @details
* The number of symbols measured from the start of the superframe before the receiver is
* to be enabled or disabled.
* This is a 24-bit value, and the precision of this value shall be a minimum of 20 bits,
* with the lowest 4 bits being the least significant.
*
* If the issuing device is the PAN coordinator, the term superframe refers to its own
* superframe. Otherwise, the term refers to the superframe of the coordinator through
* which the issuing device is associated.
*
* @note This parameter is ignored for nonbeacon-enabled PANs.
*/
uint32_t rx_on_time;
/**
* The number of symbols the receiver is to be enabled for.
*
* If this parameter is equal to 0x000000, the receiver is to be disabled.
*/
uint32_t rx_on_duration;
} mlme_rx_enable_req_t;
/**
* @brief Customer's function of confirmation.
*
* @details The MLME-RX-ENABLE.confirm primitive is generated by the MLME and issued to
* its next higher layer in response to an MLME-RX-ENABLE.request primitive.
*
* @param pointer to a confirmation primitive.
*/
typedef void (* mlme_rx_enable_conf_cb_t)(mlme_rx_enable_conf_t *);
/**
* @brief MLME-RX-ENABLE.request service
*
* @details The MLME-RX-ENABLE.request primitive is generated by the next higher layer and
* issued to the MLME to enable the receiver for a fixed duration, at a time relative to the
* start of the current or next superframe on a beacon-enabled PAN or immediately on a
* nonbeacon-enabled PAN. This primitive may also be generated to cancel a previously generated
* request to enable the receiver. After request completion, user callback will be issued with
* valid data stored in structure mlme_rx_enable_conf_t.
*
* @note The receiver is enabled or disabled exactly once per primitive request.
*
* @param[in] req pointer to MLME-RX-ENABLE request structure.
* @param[in] conf_cb - pointer to confirm function (user callback).
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.10.1
*/
void mlme_rx_enable_req(mlme_rx_enable_req_t * req, mlme_rx_enable_conf_cb_t conf_cb);
/**
* @brief Enables permission for receiving.
*
* @details Optional. Not covered by a standard.
*
* @param[in] req pointer to MLME-RX-ENABLE request structure.
*
* @return status of operation.
*/
mac_status_t mlme_rx_enable(mlme_rx_enable_req_t * req);
/** @} */
#endif // (CONFIG_RXE_ENABLED == 1)
#endif // MAC_MLME_RX_ENABLE_H_INCLUDED

View File

@@ -0,0 +1,160 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_SCAN_H_INCLUDED
#define MAC_MLME_SCAN_H_INCLUDED
#include <stdint.h>
#include "mac_common.h"
#include "mac_mlme_beacon_notify.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME Scan module declares the MAC Scan primitives and necessary types
* according to the MAC specification.
*
* @defgroup mac_scan MAC MLME Scan API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Scan API.
* @details The MAC Scan module declares MLME Scan primitives and necessary types according to
* the MAC specification. More specifically, MLME Scan request aka mlme_scan_req(), and MLME
* Scan confirm callback typedef aka mlme_scan_conf_cb_t primitives are declared.
*/
/**@brief Type of scan. */
typedef enum
{
ED_SCAN = 0, /**< Energy detection scan. */
ACTIVE_SCAN, /**< Active scan. */
PASSIVE_SCAN, /**< Passive scan. */
ORPHAN_SCAN /**< Orphan scan. */
} mac_scan_type_t;
/**
* @brief MLME-SCAN.confirm
*
* @details The MLME-SCAN.confirm reports the result of the channel scan request.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.11.2
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
mac_scan_type_t scan_type; /**< Scan type. */
#ifdef CONFIG_SUB_GHZ
uint8_t channel_page; /**< Channel page. */
#endif
uint32_t unscanned_channels; /**< Unscanned channels. */
uint8_t result_list_size; /**< Result list size. */
uint8_t * energy_detect_list; /**< Energy detection list. */
mac_pan_descriptor_t * pan_descriptor_list; /**< PAN descriptor list. */
} mlme_scan_conf_t;
/**
* @brief MLME-SCAN.request
*
* @details The MLME-SCAN.request primitive is used to initiate a channel
* scan over a given list of channels.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.11.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_scan_conf_t confirm;
mac_scan_type_t scan_type; /**< Scan type. */
uint32_t scan_channels; /**< Scan channels. */
uint8_t scan_duration; /**< Scan duration. */
uint8_t pan_descriptors_buf_size; /**< PAN descriptor buffer size. */
mac_pan_descriptor_t * pan_descriptors_buf; /**< PAN descriptor buffer. */
uint8_t energy_detect_buf_size; /**< Energy detection buffer size. */
uint8_t * energy_detect_buf; /**< Energy detection buffer. */
#ifdef CONFIG_SUB_GHZ
uint8_t channel_page; /**< Channel page. */
#endif
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_scan_req_t;
/**
* @brief User callback to scan request.
*
* @details The MLME-SCAN.confirm primitive is generated by the MLME and issued to
* its next higher layer when the channel scan initiated with
* the MLME-SCAN.request primitive has completed.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.11.2
*/
typedef void (* mlme_scan_conf_cb_t)(mlme_scan_conf_t *);
/**
* @brief MLME-SCAN request
*
* @details The MLME-SCAN.request primitive is generated by the next higher layer and
* issued to its MLME to initiate a channel scan to search for activity within the POS
* of the device. This primitive can be used to perform an ED scan to determine channel
* usage, an active or passive scan to locate beacon frames containing any PAN identifier,
* or an orphan scan to locate a PAN to which the device is currently associated.
*
* @param[in] req MLME-SCAN request structure.
* @param[in] conf_cb pointer to user callback.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.11.1
*/
void mlme_scan_req(mlme_scan_req_t * req, mlme_scan_conf_cb_t conf_cb);
/** @} */
#endif // MAC_MLME_SCAN_H_INCLUDED

View File

@@ -0,0 +1,150 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_START_H_INCLUDED
#define MAC_MLME_START_H_INCLUDED
#if (CONFIG_START_ENABLED == 1)
#include <stdint.h>
#include "mac_common.h"
#include "sys_utils.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME Start module declares the MAC Start primitives and necessary types
* according to the MAC specification.
*
* @defgroup mac_start MAC MLME Start API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Start API.
* @details The MAC Start module declares MLME Start primitives and necessary types according to
* the MAC specification. More specifically, MLME Start request aka mlme_start_req(), and MLME
* Start confirm callback typedef aka mlme_start_conf_cb_t primitives are declared.
*/
/**@brief MLME-Start.confirm
*
* @details The MLME-Start.confirm primitive reports the results of a request
* to start the device.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.14.1.2
*/
typedef struct
{
mac_status_t status; /**< Status of operation. */
} mlme_start_conf_t;
/**
* @brief MLME-START.request
*
* @details The MLME-START.request primitive allows the PAN coordinator
* to initiate a new PAN or to start using a new superframe configuration.
* This primitive may also be used by a device already associated with an
* existing PAN to start using a new superframe configuration.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.14.1.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
/** Confirm to this request. */
mlme_start_conf_t confirm;
uint16_t pan_id; /**< PAN ID. */
uint8_t logical_channel; /**< Logical channel. */
#ifdef CONFIG_SUB_GHZ
uint8_t channel_page; /**< Channel page. */
#endif
uint32_t start_time; /**< Start time. */
uint8_t beacon_order; /**< Beacon order. */
uint8_t superframe_order; /**< Superframe order. */
bool pan_coordinator; /**< Is PAN Coordinator? */
bool battery_life_extension; /**< Is battery life long? */
bool coord_realignment; /**< Is coordinator realignment? */
#if (CONFIG_SECURE == 1)
/* The security parameters for the coordinator realignment are declared below. */
uint8_t coord_realign_security_level; /**< Security level. */
uint8_t coord_realign_key_id_mode; /**< Key ID mode. */
uint64_t coord_realign_key_source; /**< Key source. */
uint8_t coord_realign_key_index; /**< Key index. */
/* The security parameters for the beacon are declared below. */
uint8_t beacon_security_level; /**< Security level. */
uint8_t beacon_key_id_mode; /**< Key ID mode. */
uint64_t beacon_key_source; /**< Key source. */
uint8_t beacon_key_index; /**< Key index. */
#endif
} mlme_start_req_t;
/**
* @brief Callback to the next higher layer.
*
* @details After request completion, passed callback
* will be issued with status provided as a parameter.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.14.2.2
*/
typedef void (* mlme_start_conf_cb_t)(mlme_start_conf_t *);
/**
* @brief MLME-START request.
*
* @details Generated by the next higher layer and issued to its MLME to
* request that a device starts using a new superframe configuration.
*
* @param[in] req MLME-START request structure.
* @param[in] conf_cb pointer to user callback.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.14.1.2
*/
void mlme_start_req(mlme_start_req_t * req, mlme_start_conf_cb_t conf_cb);
/** @} */
#endif // (CONFIG_START_ENABLED == 1)
#endif // MAC_MLME_START_H_INCLUDED

View File

@@ -0,0 +1,153 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_MLME_SYNC_H_INCLUDED
#define MAC_MLME_SYNC_H_INCLUDED
#if (CONFIG_SYNC_ENABLED == 1)
#include <stdint.h>
#include "mac_common.h"
#include "mac_task_scheduler.h"
/** @file
* The MAC MLME Sync module declares the MAC Sync primitives and necessary types
* according to the MAC specification.
*
* @defgroup mac_sync MAC MLME Sync API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Sync API.
* @details The MAC Sync module declares MLME Sync and sync loss primitives and necessary types according to
* the MAC specification. More specifically, MLME Sync request aka mlme_sync_req(), and MLME
* Sync Loss indication aka mlme_sync_loss_ind() primitives are declared.
*/
/**@brief Sync Loss reason enumeration. */
typedef enum
{
MAC_SYNC_BEACON_LOST, /**< Beacon lost. */
MAC_SYNC_REALIGNMENT, /**< Realignment. */
MAC_SYNC_PAN_ID_CONFLICT /**< PAN ID Conflict. */
} mlme_sync_loss_reason_t;
/**
* @brief MLME-SYNC-LOSS.indication
*
* @details On receipt of the MLME-SYNC-LOSS.indication primitive, the next
* higher layer is notified of a loss of synchronization.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.15.2
*/
typedef struct
{
mlme_sync_loss_reason_t loss_reason; /**< Loss reason. */
uint16_t pan_id; /**< PAN ID. */
uint8_t logical_channel; /**< Logical channel. */
#ifdef CONFIG_SUB_GHZ
uint8_t channel_page; /**< Channel page. */
#endif
#if (CONFIG_SECURE == 1)
uint8_t security_level; /**< Security level. */
uint8_t key_id_mode; /**< Key ID mode. */
uint64_t key_source; /**< Key source. */
uint8_t key_index; /**< Key index. */
#endif
} mlme_sync_loss_ind_t;
#if (CONFIG_SYNC_REQ_ENABLED == 1)
/**
* @brief MLME-SYNC.request
*
* @details The MLME-SYNC.request primitive is generated by the next higher
* layer of a device on a beacon-enabled PAN and issued to its MLME to
* synchronize with the coordinator.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.15.1
*/
typedef struct
{
/** Do not edit this field. */
mac_abstract_req_t service;
uint8_t logical_channel; /**< Logical channel. */
#ifdef CONFIG_SUB_GHZ
uint8_t channel_page; /**< Channel page. */
#endif
bool track_beacon; /**< Track beacon? */
} mlme_sync_req_t;
/**
* @brief MLME-SYNC-LOSS indication.
*
* @details Generated by the MLME of a device and issued to its next
* higher layer in the event of a loss of synchronization with the
* coordinator. It is also generated by the MLME of the PAN coordinator
* and issued to its next higher layer in the event of a PAN ID conflict.
*
* @param[in] ind MLME-SYNC-LOSS indication structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.7.4
*/
extern void mlme_sync_loss_ind(mlme_sync_loss_ind_t * ind);
/**
* @brief MLME-SYNC request.
*
* @details Generated by the next higher layer of a device on a
* beacon-enabled PAN and issued to its MLME to synchronize with
* the coordinator.
*
* @param[in] req MLME_SYNC request structure.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.1.15.1
*/
void mlme_sync_req(mlme_sync_req_t * req);
#endif // (CONFIG_SYNC_REQ_ENABLED == 1)
/** @} */
#endif // (CONFIG_SYNC_ENABLED == 1)
#endif // MAC_MLME_SYNC_H_INCLUDED

View File

@@ -0,0 +1,82 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_PANID_CONFLICT_H_INCLUDED
#define MAC_PANID_CONFLICT_H_INCLUDED
#if (CONFIG_PANID_CONFLICT_ENABLED == 1)
#include "mac_common.h"
/** @file
* @defgroup mac_pan_id PAN ID Conflict API
* @ingroup mac_15_4
* @{
* @brief Module for handling PAN ID conflicts.
*/
/**
* @brief A callback function used to notify Pan ID conflict detection algorithm about
* a new beacon frame.
*
* @param p_beacon - pointer to beacon descriptor struct.
*/
void mac_panid_conflict_beacon_notify_ind(const mac_beacon_ind_t * p_beacon);
#if (CONFIG_PANID_CONFLICT_RESOLUTION_ENABLED == 1)
/**@brief Callback function which handles end of Pan ID conflict cmd TX,
* called by FP
* @param[in] status Confirmation status to be raised
*/
void mac_panid_conflict_cb(mac_status_t status);
#endif
/**@brief Indicates whether the pan id conflict was detected
*
* @return Result of pan id conflict detection
*/
bool mac_panid_conflict_detected(void);
/** @} */
#endif
#endif /* MAC_PANID_CONFLICT_H_INCLUDED */

View File

@@ -0,0 +1,318 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_SECURITY_H_INCLUDED
#define MAC_SECURITY_H_INCLUDED
#include "sys_queue.h"
#include "sec_aes_ccm.h"
/** @file
* The MAC MLME Security module declares the MAC Security types
* according to the MAC specification.
*
* @defgroup mac_security MAC MLME Security API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC MLME Security API.
* @details The MAC Security module declares types/macros needed to implement and use the MAC security
* engine according to the MAC specification. No routines or callbacks are declared here.
*/
/**
* @brief MAC sublayer security levels.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.6.2.2.1
*/
typedef enum
{
MAC_SEC_OFF = 0, /**< Security is OFF. */
MAC_SEC_MIC32, /**< MIC32 security. */
MAC_SEC_MIC64, /**< MIC64 security. */
MAC_SEC_MIC128, /**< MIC128 security. */
MAC_SEC_ENC, /**< ENC security. */
MAC_SEC_ENC_MIC32, /**< ENC/MIC32 security. */
MAC_SEC_ENC_MIC64, /**< ENC/MIC64 security. */
MAC_SEC_ENC_MIC128 /**< ENC/MIC128 security. */
} mac_security_level_t;
/**
* @brief MAC key identifier mode.
*
* In accordance with IEEE Std 802.15.4-2006, section 7.6.2.2.2
*/
typedef enum
{
MAC_KEY_ID_IMPL = 0, /**< Impl. */
MAC_KEY_ID_ONE_OCTET, /**< One octet. */
MAC_KEY_ID_FOUR_OCTET, /**< 4 octets. */
MAC_KEY_ID_EIGHT_OCTET /**< 8 octets. */
} mac_key_id_mode_t;
/**@brief Size (in bytes) of short security look up item. This size is
* set when lookup size equals to 0.
*/
#define MAC_LOOKUP_DATA_SIZE_SHORT 5
/**@brief Size (in bytes) of long security Key look up item. This size is
* set when lookup size equals to 1.
*/
#define MAC_KEY_LOOKUP_DATA_SIZE_LONG 9
/**@brief Size (in bytes) of long security Data look up item. This size is
* set when lookup size equals to 1.
*/
#define MAC_DATA_LOOKUP_DATA_SIZE_LONG 8
/**@brief Length of \a mac_key_source_t. Equals to extended address length. */
#define MAC_KEY_SOURCE_SIZE 8
/**@brief This bit-mask is used to get UniqueDevice field value of
* \a mac_key_device_descr_t.
*/
#define MAC_KEY_DEVICE_FLAG_UNIQUE 0x01
/**@brief This bit-mask is used to get BlackListed field value of
* \a mac_key_device_descr_t.
*/
#define MAC_KEY_DEVICE_FLAG_BLACKLISTED 0x02
/**@brief Length of key. */
#define MAC_SECURITY_KEY_SIZE 16
/**@brief Length of nonce for aes-ccm algorithm .*/
#define MAC_SECURITY_NONCE_SIZE 13
/**@brief Maximum MIC size .*/
#define MAX_MIC_SIZE 16
/**@brief This type is used to store security key .*/
typedef uint8_t mac_key_t[MAC_SECURITY_KEY_SIZE];
/**@brief This type is used to store security key lookup data .*/
typedef uint8_t mac_key_lookup_data_t[MAC_KEY_LOOKUP_DATA_SIZE_LONG];
/**@brief This type is used to store security data lookup data .*/
typedef uint8_t mac_data_lookup_data_t[MAC_DATA_LOOKUP_DATA_SIZE_LONG];
/**@brief This type is used to store security key source address .*/
typedef uint64_t mac_key_source_t;
/**@brief This type represents key LookupDataSize according to Table 94 .*/
typedef enum
{
KEY_LOOKUP_SIZE_FIVE = 0, /**< Size is 5. */
KEY_LOOKUP_SIZE_NINE = 1 /**< Size is 9. */
} mac_key_lookup_size_t;
/**@brief This type represents real size of key LookupData .*/
typedef enum
{
KEY_LOOKUP_SIZE_FIVE_VAL = 5, /**< Size is 5. */
KEY_LOOKUP_SIZE_NINE_VAL = 9 /**< Size is 9. */
} mac_key_lookup_size_val_t;
/**@brief This type represents data LookupDataSize .*/
typedef enum
{
DATA_LOOKUP_SIZE_FOUR_VAL = 4, /**< Size is 4. */
DATA_LOOKUP_SIZE_EIGHT_VAL = 8 /**< Size is 8. */
} mac_data_lookup_size_val_t;
/**@brief Abstract type to work with growing tables such as some of MAC
* security attributes.
*/
typedef struct
{
sys_queue_t queue; /**< Service field .*/
uint8_t size; /**< Number of currently allocated
items inside the table .*/
} mac_table_t;
/**@brief Due to processing algorithm this field MUST be the first inside a
* table or list.
*/
typedef struct
{
sys_queue_item_t item; /**< Service field .*/
uint8_t idx; /**< Index inside table .*/
} mac_table_item_t;
/**@brief KeyIdLookupDescriptor as described in Table 94 .*/
typedef struct
{
mac_table_item_t table_service; /**< Service field .*/
mac_key_lookup_data_t data; /**< Set of 5 or 9 bytes.
Data used to identify the key .*/
mac_key_lookup_size_t size; /**< A value of LOOKUP_SIZE_FIVE indicates a set
of 5 bytes; a value of LOOKUP_SIZE_NINE
indicates a set of 9 bytes .*/
} mac_key_id_lookup_descr_t;
/**@brief KeyIdLookupLis as described in Table 89 .*/
typedef mac_table_t mac_key_id_lookup_list_t;
/**@brief DeviceDescriptor as described in Table 93 .*/
typedef struct
{
mac_table_item_t table_service; /**< Service field .*/
uint16_t pan_id; /**< The 16-bit PAN identifier of the device in
this DeviceDescriptor .*/
uint16_t short_address; /**< The 16-bit short address of the device in
this DeviceDescriptor. A value of
#MAC_EXTENDED_ADDRESS_ONLY
indicates that this device is using only its
extended address. A value of
#MAC_BROADCAST_SHORT_ADDRESS
indicates that this value is unknown .*/
uint64_t extended_address; /**< The 64-bit IEEE extended address of the
device in this DeviceDescriptor. This
element is also used in unsecuring
operations on incoming frames .*/
uint32_t frame_counter; /**< The incoming frame counter of the device
in this DeviceDescriptor. This value is used
to ensure sequential freshness of frames .*/
bool exempt; /**< Indication of whether the device may
override the minimum security level
settings defined in \a mac_security_level_table_t .*/
} mac_device_descr_t;
/**@brief DeviceTable as described in Table 93 .*/
typedef mac_table_t mac_device_table_t;
/**@brief KeyDeviceDescriptor as described in Table 91 .*/
typedef struct
{
mac_table_item_t table_service; /**< Service field .*/
uint8_t device_handle; /**< Handle to the DeviceDescriptor
corresponding to the device (see
\a mac_device_descr_t).
The value is an index of the device descriptor
instance from device table .*/
uint8_t unique_device : 1; /**< Indication of whether the device indicated
by DeviceDescriptorHandle is uniquely
associated with the KeyDescriptor, i.e., it
is a link key as opposed to a group key .*/
uint8_t blacklisted : 1; /**< Indication of whether the device indicated
by DeviceDescriptorHandle previously
communicated with this key prior to the
exhaustion of the frame counter. If TRUE,
this indicates that the device shall not use
this key further because it exhausted its
use of the frame counter used with this
key .*/
} mac_key_device_descr_t;
/**@brief KeyDeviceList as described in Table 89 .*/
typedef mac_table_t mac_key_device_list_t;
/**@brief KeyUsageDescriptor as described in Table 90 .*/
typedef struct
{
mac_table_item_t table_service; /**< Service field .*/
uint8_t frame_type : 3; /**< See \a mac_frame_type_t .*/
uint8_t cmd_frame_id : 4; /**< See \a mac_command_id_t .*/
} mac_key_usage_descr_t;
/**@brief KeyUsageList as described in Table 89 .*/
typedef mac_table_t mac_key_usage_list_t;
/**@brief KeyDescriptor as described in Table 89 .*/
typedef struct
{
mac_table_item_t table_service; /**< Service field .*/
mac_key_id_lookup_list_t id_lookup_list; /**< A list of KeyIdLookupDescriptor entries
used to identify this KeyDescriptor .*/
mac_key_device_list_t key_device_list; /**< A list of KeyDeviceDescriptor entries
indicating which devices are currently
using this key, including their blacklist
status .*/
mac_key_usage_list_t key_usage_list; /**< A list of KeyUsageDescriptor entries
indicating which frame types this key may
be used with .*/
mac_key_t key; /**< The actual value of the key .*/
} mac_key_descr_t;
/**@brief KeyTable as described in Table 88 .*/
typedef mac_table_t mac_key_table_t;
/**@brief SecurityLevelDescriptor as described in Table 93 .*/
typedef struct
{
mac_table_item_t table_service; /**< Service field. */
uint16_t frame_type : 3; /**< See \a mac_frame_type_t .*/
uint16_t cmd_frame_id : 4; /**< See \a mac_command_id_t .*/
uint16_t security_min : 3; /**< The minimal required/expected security
level for incoming MAC frames with the
indicated frame type and, if present,
command frame type (see
\a mac_security_level_t) .*/
uint16_t override_min : 1; /**< Indication of whether originating devices
for which the Exempt flag is set may
override the minimum security level
indicated by the SecurityMinimum
element. If TRUE, this indicates that for
originating devices with Exempt status,
the incoming security level zero is
acceptable, in addition to the incoming
security levels meeting the minimum
expected security level indicated by the
SecurityMinimum element .*/
} mac_security_level_descr_t;
typedef mac_table_t mac_security_level_table_t;
/** @} */
#endif // MAC_SECURITY_H_INCLUDED

View File

@@ -0,0 +1,205 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_TASK_SCHEDULER_H_INCLUDED
#define MAC_TASK_SCHEDULER_H_INCLUDED
#include <stdint.h>
#include "sys_queue.h"
#include "sys_time.h"
/** @file
*
* @defgroup mac_task_scheduler MAC task scheduler
* @ingroup mac_15_4
* @{
* @brief Module for MAC task scheduling.
*/
/**@brief Identifiers for external requests.
*/
typedef enum
{
#if (CONFIG_PURGE_ENABLED == 1)
MAC_PURGE_REQ_ID,
#endif
#if (CONFIG_ASSOCIATE_REQ_ENABLED == 1)
MAC_ASSOCIATE_REQ_ID,
#endif
#if (CONFIG_DISASSOCIATE_ENABLED == 1)
MAC_DISASSOCIATE_REQ_ID,
#endif
MAC_GET_REQ_ID,
#if (CONFIG_GTS_ENABLED == 1)
MAC_GTS_REQ_ID,
#endif
MAC_RESET_REQ_ID,
#if (CONFIG_RXE_ENABLED == 1)
MAC_RX_ENABLE_REQ_ID,
#endif
MAC_SCAN_REQ_ID,
MAC_SET_REQ_ID,
#if (CONFIG_SYNC_REQ_ENABLED == 1)
MAC_SYNC_REQ_ID,
#endif
MAC_POLL_REQ_ID,
#if (CONFIG_START_ENABLED == 1)
MAC_START_REQ_ID,
#endif
MAC_DATA_REQ_ID,
#if (CONFIG_ORPHAN_ENABLED == 1)
MAC_ORPHAN_RESP_ID,
#endif
MAC_REQS_AMOUNT
} mac_req_id_t;
/**@brief Identifiers for internal handlers.
*
* These handlers are used for private MAC task scheduling.
*/
typedef enum
{
#if (CONFIG_FFD_DEVICE == 1) && (CONFIG_BEACON_ENABLED == 1)
MAC_SUPERFRAME_OUT_TASK_ID,
#endif
MAC_CSMA_CA_TASK_ID,
#if (CONFIG_START_ENABLED == 1)
MAC_START_TASK_ID,
#endif
MAC_FP_TX_TASK_ID,
MAC_DATA_DIR_CONF_ID,
#if (CONFIG_INDIRECT_ENGINE_ENABLED == 1)
MAC_INDIR_ENGINE_REQ_ID,
#endif
MAC_FP_RX_TASK_ID,
#if (CONFIG_ORPHAN_ENABLED == 1)
MAC_ORPHAN_IND_ID,
#endif
#if (CONFIG_DISASSOCIATE_ENABLED == 1)
MAC_DISASSOC_IND_ID,
#endif
#if (CONFIG_SYNC_ENABLED == 1)
MAC_SYNC_LOSS_IND_ID,
#endif
MAC_GET_CONF_ID,
MAC_SET_CONF_ID,
MAC_REQ_QUEUE_TASK_ID,
MAC_POLL_TASK_ID,
MAC_SCAN_CONF_ID,
MAC_MEM_ALLOCATOR_TASK_ID,
MAC_TASKS_AMOUNT
} mac_task_id_t;
/**@brief MAC request descriptor.
*/
typedef struct
{
sys_queue_item_t item;
mac_req_id_t id;
void * p_conf_cb; //pointer to confirmation primitive
} mac_abstract_req_t;
/**@brief scheduler memory.
*/
typedef struct
{
sys_queue_t outer_req_queue;
volatile uint32_t pending_tasks;
bool mac_scheduler_busy;
} mac_scheduler_mem_t;
/**@brief MAC task handler prototype.
*
* @details Handler which will be called by the MAC scheduler.
*/
typedef void (* mac_task_handler_t)(void);
/**@brief MAC external requests queue task handler prototype.
*
* @details Handler which will be called by the MAC scheduler inside
* corresponding task handler.
*/
typedef void (* mac_req_handler_t)(mac_abstract_req_t *);
/**@brief Initialize MAC scheduler.
*
* @details Clean up MAC request's queue.
*/
void mac_init(void);
/**@brief MAC task handler.
*
* @details Handler invokes a MAC primitives routine for a request according to
* the requests identification.
*/
void mac_task_handler(void);
/**@brief Scheduler request from some MAC primitive.
*
* @details Place request to MAC scheduler queue for a further handling.
*
* @param[in] p_req Pointer to a request structure.
*/
void mac_request_schedule(mac_abstract_req_t * p_req);
/**@brief Internal function of MAC API.
*
* This function is used to post tasks between MAC primitives.
*
* @param[in] id MAC task ID.
*
*/
void mac_internal_task_post(mac_task_id_t id);
/**@brief Internal function of MAC API.
*
* Notifies mac scheduler that incoming request has been completely
* served and may be safely removed from MAC task queue.
*
* @param[in] p_req Pointer to a request structure.
*/
void mac_close_request(mac_abstract_req_t * p_req);
/** @} */
#endif // MAC_TASK_SCHEDULER_H_INCLUDED

View File

@@ -0,0 +1,151 @@
/**
* Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
*
* All Rights Reserved.
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
*
*/
#ifndef MAC_TIME_H_INCLUDED
#define MAC_TIME_H_INCLUDED
#include <stdint.h>
#include "sys_time.h"
#include "hal_timer.h"
#include "hal_timer_critical.h"
#include "sys_debug.h"
/** @file
* The MAC Time module declares some useful macros/types and routines that deal with the MAC
* timer.
*
* @defgroup mac_time MAC Time API
* @ingroup mac_15_4
* @{
* @brief Module to declare MAC Time API.
* @details The MAC Time module declares some useful macros/types and routines that deal with the MAC
* timer. More specifically, some convertion routines such as mac_timestamp_from_systime(),
* mac_time_from_us(), and mac_time_to_us() are declared here.
*/
/**@brief This mask shall always be used after any mathematical operation on
* mac_time_t to avoid overflow.
*/
#define MAC_TIME_MASK 0xFFFFFFULL
/**@brief Type of MAC time in symbols. */
typedef uint32_t mac_time_t;
/**@brief Type is used to save timestamps with microsecond precision. */
typedef uint32_t mac_timestamp_t;
/**@brief Gets timestamp from system time.
*
* @param[in] time_us System time.
*
* @return Time in us but smaller type size.
*/
static inline mac_timestamp_t mac_timestamp_from_systime(sys_time_t time_us)
{
return (mac_timestamp_t)time_us;
}
/**@brief Converts microseconds to symbol time.
*
* @details Symbol time is measured in PHY Symbol Periods (16 us).
*
* @param[in] time_us Time in microseconds.
*
* @return Time in PHY Symbol Periods (16 us).
*/
static inline mac_time_t mac_time_from_us(sys_time_t time_us)
{
return (mac_time_t)((time_us >> 4ull) & MAC_TIME_MASK);
}
/**@brief Converts symbol time to microseconds.
*
* @details Symbol time is measured in PHY Symbol Periods (16 us).
*
* @param[in] time_symbol Time in PHY Symbol Periods (16 us).
*
* @return Time in microseconds.
*/
static inline sys_time_t mac_time_to_us(mac_time_t time_symbol)
{
return time_symbol << 4u;
}
/**@brief Starts the critical MAC timer.
*
* @details The callback function of the critical MAC timer will be called from
* the timer's interrupt routine. Only one critical MAC timer can run
* at the same time.
*
* @warning This is internal MAC functionality, needed for the realtime channel access.
* This function must not be used by other modules.
*
* @param[in] interval_us Interval in microseconds, after which the callback
* function will be called.
* @param[in] callback Callback function to be called after the specified inteval.
*/
static inline void mac_timer_critical_start(sys_time_t interval_us, void (* callback)(void))
{
// Make sure interval_us fits into 32 bits, since hardware critical timer is 32 bit.
ASSERT(interval_us < (1ULL << 32));
hal_timer_critical_start((uint32_t)interval_us, callback);
}
/**@brief Stops the critical MAC timer.
*
* @details After critical MAC timer is stopped with this function, its callback will not be called.
*
* @warning This is internal MAC functionality, needed for the realtime channel access.
* This function must not be used by other modules.
*/
static inline void mac_timer_critical_stop(void)
{
hal_timer_critical_stop();
}
/** @} */
#endif // MAC_TIME_H_INCLUDED