#ifndef MAC_HIGH_LEVEL_H
#define MAC_HIGH_LEVEL_H
#include "mac_api.h"
def MAC_INTERNAL_API
#define MAC_INTERNAL_API
#endif
/* RX flag masks */
#define MAC_RX_FLAG_VERSION 0x03 /* received frame's version */
#define MAC_RX_FLAG_ACK_PENDING 0x04 /* outgoing ACK has pending bit set */
#define MAC_RX_FLAG_SECURITY 0x08 /* received frame has security bit set */
#define MAC_RX_FLAG_PENDING 0x10 /* received frame has pending bit set */
#define MAC_RX_FLAG_ACK_REQUEST 0x20 /* received frame has ack request bit set */
#define MAC_RX_FLAG_INTRA_PAN 0x40 /* received frame has intra pan fcf bit set */
#define MAC_RX_FLAG_CRC_OK 0x80 /* received frame CRC OK bit */
/* Structure for internal data tx */
typedef struct
{
macEventHdr_t hdr;
sData_t msdu;
macTxIntData_t internal;
macSec_t sec;
} macTx_t;
/* Structure for internal data rx */
typedef struct
{
macEventHdr_t hdr;
sData_t msdu;
macRxIntData_t internal;
macSec_t sec;
macDataInd_t mac;
sData_t mhr;
} macRx_t;
/* Function pointer for the 16 byte random seed callback */
typedef void (*macRNGFcn_t )(uint8* seed);
/* pointer to current tx frame */
extern macTx_t *pMacDataTx;
/* TRUE if operating as a PAN coordinator */
extern bool macPanCoordinator;
/* functions located in mac_data.c */
MAC_INTERNAL_API uint8 *macDataRxMemAlloc(uint16 len);
MAC_INTERNAL_API uint8 macDataRxMemFree(uint8 **pMsg);
MAC_INTERNAL_API uint8 macDataTxTimeAvailable(void);
#endif /* MAC_HIGH_LEVEL_H */
#ifndef MAC_SPEC_H
#define MAC_SPEC_H
#define MAC_PHY_SHR_LEN 5 /* preamble bytes plus SFD byte */
#define MAC_PHY_PHR_LEN 1 /* length byte */
/* MAC frame field lengths in bytes */
#define MAC_FCF_FIELD_LEN 2 /* frame control field */
#define MAC_SEQ_NUM_FIELD_LEN 1 /* sequence number */
#define MAC_PAN_ID_FIELD_LEN 2 /* PAN ID */
#define MAC_EXT_ADDR_FIELD_LEN 8 /* Extended address */
#define MAC_SHORT_ADDR_FIELD_LEN 2 /* Short address */
#define MAC_FCS_FIELD_LEN 2 /* FCS field */
#define MAC_SEC_CONTROL_FIELD_LEN 1 /* Security control field */
/* Frame offsets in bytes */
#define MAC_FCF_OFFSET 0 /* offset to frame control field */
#define MAC_SEQ_NUM_OFFSET 2 /* offset to sequence number */
#define MAC_DEST_PAN_ID_OFFSET 3 /* offset to destination PAN ID */
#define MAC_DEST_ADDR_OFFSET 5 /* offset to destination address */
/* Frame control field bit masks */
#define MAC_FCF_FRAME_TYPE_MASK 0x0007
#define MAC_FCF_SEC_ENABLED_MASK 0x0008
#define MAC_FCF_FRAME_PENDING_MASK 0x0010
#define MAC_FCF_ACK_REQUEST_MASK 0x0020
#define MAC_FCF_INTRA_PAN_MASK 0x0040
#define MAC_FCF_DST_ADDR_MODE_MASK 0x0C00
#define MAC_FCF_FRAME_VERSION_MASK 0x3000
#define MAC_FCF_SRC_ADDR_MODE_MASK 0xC000
/* Frame control field bit positions */
#define MAC_FCF_FRAME_TYPE_POS 0
#define MAC_FCF_SEC_ENABLED_POS 3
#define MAC_FCF_FRAME_PENDING_POS 4
#define MAC_FCF_ACK_REQUEST_POS 5
#define MAC_FCF_INTRA_PAN_POS 6
#define MAC_FCF_DST_ADDR_MODE_POS 10
#define MAC_FCF_FRAME_VERSION_POS 12
#define MAC_FCF_SRC_ADDR_MODE_POS 14
/* Security control field bit masks */
#define MAC_SCF_SECURITY_LEVEL_MASK 0x07
#define MAC_SCF_KEY_IDENTIFIER_MASK 0x18
/* Security control field bit positions */
#define MAC_SCF_SECURITY_LEVEL_POS 0
#define MAC_SCF_KEY_IDENTIFIER_POS 3
/* MAC Payload offsets in bytes */
#define MAC_SFS_OFFSET 0
#define MAC_PENDING_ADDR_OFFSET 3 /* if GTS is not in use */
/* Beacon superframe spec bit positions, low byte */
#define MAC_SFS_BEACON_ORDER_POS 0
#define MAC_SFS_SUPERFRAME_ORDER_POS 4
/* Beacon superframe spec bit positions, high byte */
#define MAC_SFS_FINAL_CAP_SLOT_POS 0
#define MAC_SFS_BATT_LIFE_EXT_POS 4
#define MAC_SFS_PAN_COORD_POS 6
#define MAC_SFS_ASSOC_PERMIT_POS 7
/* Frame type */
#define MAC_FRAME_TYPE_BEACON 0
#define MAC_FRAME_TYPE_DATA 1
#define MAC_FRAME_TYPE_ACK 2
#define MAC_FRAME_TYPE_COMMAND 3
#define MAC_FRAME_TYPE_MAX_VALID MAC_FRAME_TYPE_COMMAND
/* Command frame identifiers */
#define MAC_ASSOC_REQ_FRAME 1
#define MAC_ASSOC_RSP_FRAME 2
#define MAC_DISASSOC_NOTIF_FRAME 3
#define MAC_DATA_REQ_FRAME 4
#define MAC_PAN_CONFLICT_FRAME 5
#define MAC_ORPHAN_NOTIF_FRAME 6
#define MAC_BEACON_REQ_FRAME 7
#define MAC_COORD_REALIGN_FRAME 8
#define MAC_GTS_REQ_FRAME 9
/* Length of command frame payload (includes command ID byte) */
#define MAC_ZERO_DATA_PAYLOAD 0
#define MAC_ASSOC_REQ_PAYLOAD 2
#define MAC_ASSOC_RSP_PAYLOAD 4
#define MAC_DISASSOC_NOTIF_PAYLOAD 2
#define MAC_DATA_REQ_PAYLOAD 1
#define MAC_PAN_CONFLICT_PAYLOAD 1
#define MAC_ORPHAN_NOTIF_PAYLOAD 1
#define MAC_BEACON_REQ_PAYLOAD 1
#define MAC_COORD_REALIGN_PAYLOAD 9
#define MAC_GTS_REQ_PAYLOAD 2
/* Length of command frames (max header plus payload) */
#define MAC_ZERO_DATA_FRAME_LEN (21 + MAC_ZERO_DATA_PAYLOAD)
#define MAC_ASSOC_REQ_FRAME_LEN (23 + MAC_ASSOC_REQ_PAYLOAD)
#define MAC_ASSOC_RSP_FRAME_LEN (23 + MAC_ASSOC_RSP_PAYLOAD)
#define MAC_DISASSOC_NOTIF_FRAME_LEN (17 + MAC_DISASSOC_NOTIF_PAYLOAD)
#define MAC_DATA_REQ_FRAME_LEN (23 + MAC_DATA_REQ_PAYLOAD)
#define MAC_PAN_CONFLICT_FRAME_LEN (23 + MAC_PAN_CONFLICT_PAYLOAD)
#define MAC_ORPHAN_NOTIF_FRAME_LEN (17 + MAC_ORPHAN_NOTIF_PAYLOAD)
#define MAC_BEACON_REQ_FRAME_LEN (7 + MAC_BEACON_REQ_PAYLOAD)
#define MAC_COORD_REALIGN_FRAME_LEN (23 + MAC_COORD_REALIGN_PAYLOAD)
#define MAC_GTS_REQ_FRAME_LEN (7 + MAC_GTS_REQ_PAYLOAD)
/* Beacon frame base length (max header plus minimum payload) */
#define MAC_BEACON_FRAME_BASE_LEN (13 + 4)
/* Maximum number of pending addresses in a beacon */
#define MAC_PEND_ADDR_MAX 7
/* Associate response command frame status values */
#define MAC_ASSOC_SUCCESS 0 /* association successful */
#define MAC_ASSOC_CAPACITY 1 /* PAN at capacity */
#define MAC_ASSOC_DENIED 2 /* PAN access denied */
/* Beacon order and superframe order maximum values */
#define MAC_BO_NON_BEACON 15
#define MAC_SO_NONE 15
/* Broadcast PAN ID */
#define MAC_PAN_ID_BROADCAST 0xFFFF
/* Number of symbols per octet */
#define MAC_SYMBOLS_PER_OCTET 2
/* Maximum phy frame size in bytes */
#define MAC_A_MAX_PHY_PACKET_SIZE 127
/* Phy RX <--> TX turnaround time in symbols */
#define MAC_A_TURNAROUND_TIME 12
/* Number of backoffs forming a superframe slot when the superframe order is equal to 0 */
#define MAC_A_BASE_SLOT_DURATION 3
/* Number of backoffs forming a superframe when the superframe order is equal to 0 */
#define MAC_A_BASE_SUPERFRAME_DURATION (MAC_A_BASE_SLOT_DURATION * MAC_A_NUM_SUPERFRAME_SLOTS)
/* Maximum number of bytes added by the MAC sublayer to the payload of its beacon frame */
#define MAC_A_MAX_BEACON_OVERHEAD 75
/* Maximum size in bytes of a beacon payload */
#define MAC_A_MAX_BEACON_PAYLOAD_LENGTH (MAC_A_MAX_PHY_PACKET_SIZE - MAC_A_MAX_BEACON_OVERHEAD)
/* The number of superframes a GTS descriptor exists for in the beacon frame */
#define MAC_A_GTS_DESC_PERSISTENCE_TIME 4
/* Maximum size in bytes of a MAC frame header */
#define MAC_A_MAX_FRAME_OVERHEAD 25
/* The number of consecutive lost beacons that will case the MAC to declare a sync loss */
#define MAC_A_MAX_LOST_BEACONS 4
/* The maximum number of bytes that can be transmitted in the MAC frame payload */
#define MAC_A_MAX_FRAME_SIZE (MAC_A_MAX_PHY_PACKET_SIZE - MAC_A_MAX_FRAME_OVERHEAD)
/* The maximum frame size in bytes that can be followed by a short interframe spacing period */
#define MAC_A_MAX_SIFS_FRAME_SIZE 18
/* The minimum number of symbols forming the CAP */
#define MAC_A_MIN_CAP_LENGTH 440
/* The minimum number of symbols forming a long interframe spacing period */
#define MAC_A_MIN_LIFS_PERIOD 40
/* The minimum number of symbols forming a short interframe spacing period */
#define MAC_A_MIN_SIFS_PERIOD 12
/* The number of slots contained in any superframe */
#define MAC_A_NUM_SUPERFRAME_SLOTS 16
/* The number of symbols forming a basic CSMA-CA time period */
#define MAC_A_UNIT_BACKOFF_PERIOD 20
/* Maximum value for energy detect */
#define MAC_SPEC_ED_MAX 0xFF
/* Threshold above receiver sensitivity for minimum energy detect in dBm (see 6.9.7) */
#define MAC_SPEC_ED_MIN_DBM_ABOVE_RECEIVER_SENSITIVITY 10
#define MAC_SPEC_MIN_RECEIVER_SENSITIVITY -85
/* Length of preamble field in symbols */
#define MAC_SPEC_PREAMBLE_FIELD_LENGTH 8
/* Length of SFD field in symbols */
#define MAC_SPEC_SFD_FIELD_LENGTH 2
/* Microseconds in one symbol */
#define MAC_SPEC_USECS_PER_SYMBOL 16
/* Microseconds in one backoff period */
#define MAC_SPEC_USECS_PER_BACKOFF (MAC_SPEC_USECS_PER_SYMBOL * MAC_A_UNIT_BACKOFF_PERIOD)
/* octets (or bytes) per symbol */
#define MAC_SPEC_OCTETS_PER_SYMBOL 2
/* Length of GTS fields in a beacon, not including one byte for GTS specification */
#define MAC_GTS_FIELDS_LEN(gtsSpec) ((uint8)((((gtsSpec) & 0x07) * 3) + (((gtsSpec) & 0x07) ? 1 : 0)))
#define MAC_FRAME_TYPE(p) ((p)[MAC_FCF_OFFSET+0] & 0x07)
#define MAC_SEC_ENABLED(p) ((p)[MAC_FCF_OFFSET+0] & 0x08) /* note: value is *non-zero* if true */
#define MAC_FRAME_PENDING(p) ((p)[MAC_FCF_OFFSET+0] & 0x10) /* note: value is *non-zero* if true */
#define MAC_ACK_REQUEST(p) ((p)[MAC_FCF_OFFSET+0] & 0x20) /* note: value is *non-zero* if true */
#define MAC_INTRA_PAN(p) ((p)[MAC_FCF_OFFSET+0] & 0x40) /* note: value is *non-zero* if true */
#define MAC_DEST_ADDR_MODE(p) (((p)[MAC_FCF_OFFSET+1] >> 2) & 0x3)
#define MAC_FRAME_VERSION(p) (((p)[MAC_FCF_OFFSET+1] >> 4) & 0x3)
#define MAC_SRC_ADDR_MODE(p) (((p)[MAC_FCF_OFFSET+1] >> 6) & 0x3)
#define MAC_SEQ_NUMBER(p) ((p)[MAC_SEQ_NUM_OFFSET])
#endif /* MAC_SPEC_H */
Include
mac_api.h
#ifndef MAC_API_H
#define MAC_API_H
#ifdef __cplusplus
extern "C" {
#endif
#include "hal_types.h"
#include "saddr.h"
#include "sdata.h"
#define MAC_SUCCESS 0x00 /* Operation successful */
#define MAC_AUTOACK_PENDING_ALL_ON 0xFE /* The AUTOPEND pending all is turned on */
#define MAC_AUTOACK_PENDING_ALL_OFF 0xFF /* The AUTOPEND pending all is turned off */
#define MAC_BEACON_LOSS 0xE0 /* The beacon was lost following a synchronization request */
#define MAC_CHANNEL_ACCESS_FAILURE 0xE1 /* The operation or data request failed because of
activity on the channel */
#define MAC_COUNTER_ERROR 0xDB /* The frame counter puportedly applied by the originator of
the received frame is invalid */
#define MAC_DENIED 0xE2 /* The MAC was not able to enter low power mode. */
#define MAC_DISABLE_TRX_FAILURE 0xE3 /* Unused */
#define MAC_FRAME_TOO_LONG 0xE5 /* The received frame or frame resulting from an operation
or data request is too long to be processed by the MAC */
#define MAC_IMPROPER_KEY_TYPE 0xDC /* The key purportedly applied by the originator of the
received frame is not allowed */
#define MAC_IMPROPER_SECURITY_LEVEL 0xDD /* The security level purportedly applied by the originator of
the received frame does not meet the minimum security level */
#define MAC_INVALID_ADDRESS 0xF5 /* The data request failed because neither the source address nor
destination address parameters were present */
#define MAC_INVALID_GTS 0xE6 /* Unused */
#define MAC_INVALID_HANDLE 0xE7 /* The purge request contained an invalid handle */
#define MAC_INVALID_INDEX 0xF9 /* Unused */
#define MAC_INVALID_PARAMETER 0xE8 /* The API function parameter is out of range */
#define MAC_LIMIT_REACHED 0xFA /* The scan terminated because the PAN descriptor storage limit
was reached */
#define MAC_NO_ACK 0xE9 /* The operation or data request failed because no
acknowledgement was received */
#define MAC_NO_BEACON 0xEA /* The scan request failed because no beacons were received or the
orphan scan failed because no coordinator realignment was received */
#define MAC_NO_DATA 0xEB /* The associate request failed because no associate response was received
or the poll request did not return any data */
#define MAC_NO_SHORT_ADDRESS 0xEC /* The short address parameter of the start request was invalid */
#define MAC_ON_TIME_TOO_LONG 0xF6 /* Unused */
#define MAC_OUT_OF_CAP 0xED /* Unused */
#define MAC_PAN_ID_CONFLICT 0xEE /* A PAN identifier conflict has been detected and
communicated to the PAN coordinator */
#define MAC_PAST_TIME 0xF7 /* Unused */
#define MAC_READ_ONLY 0xFB /* A set request was issued with a read-only identifier */
#define MAC_REALIGNMENT 0xEF /* A coordinator realignment command has been received */
#define MAC_SCAN_IN_PROGRESS 0xFC /* The scan request failed because a scan is already in progress */
#define MAC_SECURITY_ERROR 0xE4 /* Cryptographic processing of the received secure frame failed */
#define MAC_SUPERFRAME_OVERLAP 0xFD /* The beacon start time overlapped the coordinator transmission time */
#define MAC_TRACKING_OFF 0xF8 /* The start request failed because the device is not tracking
the beacon of its coordinator */
#define MAC_TRANSACTION_EXPIRED 0xF0 /* The associate response, disassociate request, or indirect
data transmission failed because the peer device did not respond
before the transaction expired or was purged */
#define MAC_TRANSACTION_OVERFLOW 0xF1 /* The request failed because MAC data buffers are full */
#define MAC_TX_ACTIVE 0xF2 /* Unused */
#define MAC_UNAVAILABLE_KEY 0xF3 /* The operation or data request failed because the
security key is not available */
#define MAC_UNSUPPORTED_ATTRIBUTE 0xF4 /* The set or get request failed because the attribute is not supported */
#define MAC_UNSUPPORTED_LEGACY 0xDE /* The received frame was secured with legacy security which is
not supported */
#define MAC_UNSUPPORTED_SECURITY 0xDF /* The security of the received frame is not supported */
#define MAC_UNSUPPORTED 0x18 /* The operation is not supported in the current configuration */
#define MAC_BAD_STATE 0x19 /* The operation could not be performed in the current state */
#define MAC_NO_RESOURCES 0x1A /* The operation could not be completed because no
memory resources were available */
#define MAC_ACK_PENDING 0x1B /* For internal use only */
#define MAC_NO_TIME 0x1C /* For internal use only */
#define MAC_TX_ABORTED 0x1D /* For internal use only */
#define MAC_DUPLICATED_ENTRY 0x1E /* For internal use only - A duplicated entry is added to the source matching table */
/* MAC Security Level */
#define MAC_SEC_LEVEL_NONE 0x00 /* No security is used */
#define MAC_SEC_LEVEL_MIC_32 0x01 /* MIC-32 authentication is used */
#define MAC_SEC_LEVEL_MIC_64 0x02 /* MIC-64 authentication is used */
#define MAC_SEC_LEVEL_MIC_128 0x03 /* MIC-128 authentication is used */
#define MAC_SEC_LEVEL_ENC 0x04 /* AES encryption is used */
#define MAC_SEC_LEVEL_ENC_MIC_32 0x05 /* AES encryption and MIC-32 authentication are used */
#define MAC_SEC_LEVEL_ENC_MIC_64 0x06 /* AES encryption and MIC-64 authentication are used */
#define MAC_SEC_LEVEL_ENC_MIC_128 0x07 /* AES encryption and MIC-128 authentication are used */
/* Key Identifier Mode */
#define MAC_KEY_ID_MODE_NONE 0x00 /* Key is is not used */
#define MAC_KEY_ID_MODE_IMPLICIT 0x00 /* Key is determined implicitly */
#define MAC_KEY_ID_MODE_1 0x01 /* Key is determined from the 1-byte key index */
#define MAC_KEY_ID_MODE_4 0x02 /* Key is determined from the 4-byte key index */
#define MAC_KEY_ID_MODE_8 0x03 /* Key is determined from the 8-byte key index */
/* Key identifier field length in bytes */
#define MAC_KEY_ID_IMPLICIT_LEN 0
#define MAC_KEY_ID_1_LEN 1
#define MAC_KEY_ID_4_LEN 5
#define MAC_KEY_ID_8_LEN 9
/* Key source maximum length in bytes */
#define MAC_KEY_SOURCE_MAX_LEN 8
/* Key index length in bytes */
#define MAC_KEY_INDEX_LEN 1
/* Frame counter length in bytes */
#define MAC_FRAME_COUNTER_LEN 4
/* Key length in bytes */
#define MAC_KEY_MAX_LEN 16
/* Key lookup data length in bytes */
#define MAC_KEY_LOOKUP_SHORT_LEN 5
#define MAC_KEY_LOOKUP_LONG_LEN 9
#define MAC_MAX_KEY_LOOKUP_LEN MAC_KEY_LOOKUP_LONG_LEN
/* Data constants */
#if !defined ( MAC_MAX_FRAME_SIZE )
#define MAC_MAX_FRAME_SIZE 102 /* Maximum application data length without security */
#endif
#define MAC_DATA_OFFSET 24 /* Bytes required for MAC header in data frame */
#define MAC_ENC_OFFSET 5 /* Data offset required for encryption header */
#define MAC_MIC_32_LEN 4 /* Length required for MIC-32 authentication */
#define MAC_MIC_64_LEN 8 /* Length required for MIC-64 authentication */
#define MAC_MIC_128_LEN 16 /* Length required for MIC-128 authentication */
/* MHR length for received frame */
#define MAC_MHR_LEN 37 /* FCF (2) + Seq (1) + Addr Fields (20) + Security HDR (14) */
/* TX Options */
#define MAC_TXOPTION_ACK 0x01 /* Acknowledged transmission. The MAC will attempt to retransmit
the frame until it is acknowledged */
#define MAC_TXOPTION_GTS 0x02 /* GTS transmission (unused) */
#define MAC_TXOPTION_INDIRECT 0x04 /* Indirect transmission. The MAC will queue the data and wait
for the destination device to poll for it. This can only be used
by a coordinator device */
#define MAC_TXOPTION_PEND_BIT 0x08 /* This proprietary option forces the pending bit set for direct
transmission */
#define MAC_TXOPTION_NO_RETRANS 0x10 /* This proprietary option prevents the frame from being retransmitted */
#define MAC_TXOPTION_NO_CNF 0x20 /* This proprietary option prevents a MAC_MCPS_DATA_CNF
event from being sent for this frame */
#define MAC_TXOPTION_ALT_BE 0x40 /* Use PIB value MAC_ALT_BE for the minimum backoff exponent */
#define MAC_TXOPTION_PWR_CHAN 0x80 /* Use the power and channel values in macDataReq_t
instead of the PIB values */
/* Channels */
#define MAC_CHAN_11 11
#define MAC_CHAN_12 12
#define MAC_CHAN_13 13
#define MAC_CHAN_14 14
#define MAC_CHAN_15 15
#define MAC_CHAN_16 16
#define MAC_CHAN_17 17
#define MAC_CHAN_18 18
#define MAC_CHAN_19 19
#define MAC_CHAN_20 20
#define MAC_CHAN_21 21
#define MAC_CHAN_22 22
#define MAC_CHAN_23 23
#define MAC_CHAN_24 24
#define MAC_CHAN_25 25
#define MAC_CHAN_26 26
#define MAC_CHAN_27 27
#define MAC_CHAN_28 28
/* This macro converts a channel to a mask */
#define MAC_CHAN_MASK(chan) ((uint32) 1 << (chan))
/* Channel Masks */
#define MAC_CHAN_11_MASK MAC_CHAN_MASK(MAC_CHAN_11)
#define MAC_CHAN_12_MASK MAC_CHAN_MASK(MAC_CHAN_12)
#define MAC_CHAN_13_MASK MAC_CHAN_MASK(MAC_CHAN_13)
#define MAC_CHAN_14_MASK MAC_CHAN_MASK(MAC_CHAN_14)
#define MAC_CHAN_15_MASK MAC_CHAN_MASK(MAC_CHAN_15)
#define MAC_CHAN_16_MASK MAC_CHAN_MASK(MAC_CHAN_16)
#define MAC_CHAN_17_MASK MAC_CHAN_MASK(MAC_CHAN_17)
#define MAC_CHAN_18_MASK MAC_CHAN_MASK(MAC_CHAN_18)
#define MAC_CHAN_19_MASK MAC_CHAN_MASK(MAC_CHAN_19)
#define MAC_CHAN_20_MASK MAC_CHAN_MASK(MAC_CHAN_20)
#define MAC_CHAN_21_MASK MAC_CHAN_MASK(MAC_CHAN_21)
#define MAC_CHAN_22_MASK MAC_CHAN_MASK(MAC_CHAN_22)
#define MAC_CHAN_23_MASK MAC_CHAN_MASK(MAC_CHAN_23)
#define MAC_CHAN_24_MASK MAC_CHAN_MASK(MAC_CHAN_24)
#define MAC_CHAN_25_MASK MAC_CHAN_MASK(MAC_CHAN_25)
#define MAC_CHAN_26_MASK MAC_CHAN_MASK(MAC_CHAN_26)
#define MAC_CHAN_27_MASK MAC_CHAN_MASK(MAC_CHAN_27)
#define MAC_CHAN_28_MASK MAC_CHAN_MASK(MAC_CHAN_28)
/* Channel Page */
#define MAC_CHANNEL_PAGE_0 0 /* 2.4 GHz band using O-QPSK */
#define MAC_CHANNEL_PAGE_1 1 /* 868 and 915 MHz bands using ASK */
#define MAC_CHANNEL_PAGE_2 2 /* 868 and 915 MHz bands using O-QPSK */
/* Capability Information */
#define MAC_CAPABLE_PAN_COORD 0x01 /* Device is capable of becoming a PAN coordinator */
#define MAC_CAPABLE_FFD 0x02 /* Device is an FFD */
#define MAC_CAPABLE_MAINS_POWER 0x04 /* Device is mains powered rather than battery powered */
#define MAC_CAPABLE_RX_ON_IDLE 0x08 /* Device has its receiver on when idle */
#define MAC_CAPABLE_SECURITY 0x40 /* Device is capable of sending and receiving secured frames */
#define MAC_CAPABLE_ALLOC_ADDR 0x80 /* Request allocation of a short address in the associate procedure */
/* Standard PIB Get and Set Attributes */
#define MAC_ACK_WAIT_DURATION 0x40 /* The maximum number of symbols to wait for an acknowledgment frame */
#define MAC_ASSOCIATION_PERMIT 0x41 /* TRUE if a coordinator is currently allowing association */
#define MAC_AUTO_REQUEST 0x42 /* TRUE if a device automatically sends a data request if its address
is listed in the beacon frame */
#define MAC_BATT_LIFE_EXT 0x43 /* TRUE if battery life extension is enabled */
#define MAC_BATT_LIFE_EXT_PERIODS 0x44 /* The number of backoff periods during which the receiver is
enabled following a beacon in battery life extension mode */
#define MAC_BEACON_PAYLOAD 0x45 /* The contents of the beacon payload */
#define MAC_BEACON_PAYLOAD_LENGTH 0x46 /* The length in bytes of the beacon payload */
#define MAC_BEACON_ORDER 0x47 /* How often the coordinator transmits a beacon */
#define MAC_BEACON_TX_TIME 0x48 /* The time the device transmitted its last beacon frame,
in backoff period units */
#define MAC_BSN 0x49 /* The beacon sequence number */
#define MAC_COORD_EXTENDED_ADDRESS 0x4A /* The extended address of the coordinator with which the device
is associated */
#define MAC_COORD_SHORT_ADDRESS 0x4B /* The short address assigned to the coordinator with which the
device is associated. A value of MAC_ADDR_USE_EXT indicates
that the coordinator is using its extended address */
#define MAC_DSN 0x4C /* The data or MAC command frame sequence number */
#define MAC_GTS_PERMIT 0x4D /* TRUE if the PAN coordinator accepts GTS requests */
#define MAC_MAX_CSMA_BACKOFFS 0x4E /* The maximum number of backoffs the CSMA-CA algorithm will attempt
before declaring a channel failure */
#define MAC_MIN_BE 0x4F /* The minimum value of the backoff exponent in the CSMA-CA algorithm.
If this value is set to 0, collision avoidance is disabled during
the first iteration of the algorithm. Also for the slotted version
of the CSMA-CA algorithm with the battery life extension enabled,
the minimum value of the backoff exponent will be at least 2 */
#define MAC_PAN_ID 0x50 /* The PAN identifier. If this value is 0xffff, the device is not
associated */
#define MAC_PROMISCUOUS_MODE 0x51 /* TRUE if the MAC is in promiscuous mode */
#define MAC_RX_ON_WHEN_IDLE 0x52 /* TRUE if the MAC enables its receiver during idle periods */
#define MAC_SHORT_ADDRESS 0x53 /* The short address that the device uses to communicate in the PAN.
If the device is a PAN coordinator, this value shall be set before
calling MAC_StartReq(). Otherwise the value is allocated during
association. Value MAC_ADDR_USE_EXT indicates that the device is
associated but not using a short address */
#define MAC_SUPERFRAME_ORDER 0x54 /* This specifies the length of the active portion of the superframe */
#define MAC_TRANSACTION_PERSISTENCE_TIME 0x55 /* The maximum time in beacon intervals that a transaction is stored by
a coordinator and indicated in the beacon */
#define MAC_ASSOCIATED_PAN_COORD 0x56 /* TRUE if the device is associated to the PAN coordinator */
#define MAC_MAX_BE 0x57 /* The maximum value of the backoff exponent in the CSMA-CA algorithm */
#define MAC_MAX_FRAME_TOTAL_WAIT_TIME 0x58 /* The maximum number of CAP symbols in a beacon-enabled PAN, or
symbols in a non beacon-enabled PAN, to wait for a frame intended
as a response to a data request frame */
#define MAC_MAX_FRAME_RETRIES 0x59 /* The maximum number of retries allowed after a transmission failure */
#define MAC_RESPONSE_WAIT_TIME 0x5A /* The maximum number of symbols a device shall wait for a response
command to be available following a request command in multiples
of aBaseSuperframeDuration */
#define MAC_SYNC_SYMBOL_OFFSET 0x5B /* The timestamp offset from SFD in symbols */
#define MAC_TIMESTAMP_SUPPORTED 0x5C /* TRUE if the MAC supports RX and TX timestamps */
#define MAC_SECURITY_ENABLED 0x5D /* TRUE if security is enabled */
/* Security PIB Get and Set Attributes */
#define MAC_KEY_TABLE 0x71 /* A table of KeyDescriptor, entries, each containing keys and related
information required for secured communications */
#define MAC_KEY_TABLE_ENTRIES 0x72 /* The number of entries in macKeyTable */
#define MAC_DEVICE_TABLE 0x73 /* A table of Device-Descriptor entries, each indicating a remote device
with which this device securely communicates */
#define MAC_DEVICE_TABLE_ENTRIES 0x74 /* The number of entries in macDeviceTable. */
#define MAC_SECURITY_LEVEL_TABLE 0x75 /* A table of SecurityLevel-Descriptor entries, each with information
about the minimum security level expected depending on incoming frame
type and subtype. */
#define MAC_SECURITY_LEVEL_TABLE_ENTRIES 0x76 /* The number of entries in macSecurityLevelTable. */
#define MAC_FRAME_COUNTER 0x77 /* The outgoing frame counter for this device */
#define MAC_AUTO_REQUEST_SECURITY_LEVEL 0x78 /* The security level used for automatic data requests. */
#define MAC_AUTO_REQUEST_KEY_ID_MODE 0x79 /* The key identifier mode used for automatic data requests */
#define MAC_AUTO_REQUEST_KEY_SOURCE 0x7A /* The originator of the key used for automatic data requests. */
#define MAC_AUTO_REQUEST_KEY_INDEX 0x7B /* The index of the key used for automatic data requests. */
#define MAC_DEFAULT_KEY_SOURCE 0x7C /* The originator of the default key used for key ID mode 0x01 */
#define MAC_PAN_COORD_EXTENDED_ADDRESS 0x7D /* The 64-bit address of the PAN coordinator. */
#define MAC_PAN_COORD_SHORT_ADDRESS 0x7E /* The 16-bit short address assigned to the PAN coordinator. */
/* Proprietary Security PIB Get and Set Attributes */
#define MAC_KEY_ID_LOOKUP_ENTRY 0xD0 /* The key lookup table entry, part of an entry of the key table */
#define MAC_KEY_DEVICE_ENTRY 0xD1 /* The key device entry, part of an entry of the key table */
#define MAC_KEY_USAGE_ENTRY 0xD2 /* The key usage entry, part of an entry of the key table */
#define MAC_KEY_ENTRY 0xD3 /* The MAC key entry, an entry of the key table */
#define MAC_DEVICE_ENTRY 0xD4 /* The MAC device entry, an entry of the device table */
#define MAC_SECURITY_LEVEL_ENTRY 0xD5 /* The AMC security level entry, an entry of the security level table */
/* Proprietary PIB Get and Set Attributes */
#define MAC_PHY_TRANSMIT_POWER 0xE0 /* The transmit power in units of -1 dBm */
#define MAC_LOGICAL_CHANNEL 0xE1 /* The logical channel */
#define MAC_EXTENDED_ADDRESS 0xE2 /* The extended address of the device */
#define MAC_ALT_BE 0xE3 /* alternate minimum backoff exponent */
#define MAC_DEVICE_BEACON_ORDER 0xE4 /* Device beacon order */
#define MAC_PHY_TRANSMIT_POWER_SIGNED 0xE5 /* Duplicate transmit power attribute in signed
(2's complement) dBm unit */
/* Disassociate Reason */
#define MAC_DISASSOC_COORD 1 /* The coordinator wishes the device to disassociate */
#define MAC_DISASSOC_DEVICE 2 /* The device itself wishes to disassociate */
/* Scan Type */
#define MAC_SCAN_ED 0 /* Energy detect scan. The device will tune to each channel and
perform and energy measurement. The list of channels and their
associated measurements will be returned at the end of the scan */
#define MAC_SCAN_ACTIVE 1 /* Active scan. The device tunes to each channel, sends a beacon
request and listens for beacons. The PAN descriptors are returned
at the end of the scan */
#define MAC_SCAN_PASSIVE 2 /* Passive scan. The device tunes to each channel and listens for
beacons. The PAN descriptors are returned at the end of the scan */
#define MAC_SCAN_ORPHAN 3 /* Orphan scan. The device tunes to each channel and sends an orphan
notification to try and find its coordinator. The status is returned
at the end of the scan */
/* Special address values */
#define MAC_ADDR_USE_EXT 0xFFFE /* Short address value indicating extended address is used */
#define MAC_SHORT_ADDR_BROADCAST 0xFFFF /* Broadcast short address */
#define MAC_SHORT_ADDR_NONE 0xFFFF /* Short address when there is no short address */
/* Comm status indication reasons */
#define MAC_COMM_ASSOCIATE_RSP 0 /* Event sent in response to MAC_AssociateRsp() */
#define MAC_COMM_ORPHAN_RSP 1 /* Event sent in response to MAC_OrphanRsp() */
#define MAC_COMM_RX_SECURE 2 /* Event sent as a result of receiving a secure frame */
/* Power Mode */
#define MAC_PWR_ON 0 /* MAC and radio hardware is powered on */
#define MAC_PWR_SLEEP_LITE 1 /* MAC and radio hardware are partially powered off */
#define MAC_PWR_SLEEP_DEEP 2 /* MAC and radio hardware are fully powered off */
/* MAC Callback Events */
#define MAC_MLME_ASSOCIATE_IND 1 /* Associate indication */
#define MAC_MLME_ASSOCIATE_CNF 2 /* Associate confirm */
#define MAC_MLME_DISASSOCIATE_IND 3 /* Disassociate indication */
#define MAC_MLME_DISASSOCIATE_CNF 4 /* Disassociate confirm */
#define MAC_MLME_BEACON_NOTIFY_IND 5 /* Beacon notify indication */
#define MAC_MLME_ORPHAN_IND 6 /* Orphan indication */
#define MAC_MLME_SCAN_CNF 7 /* Scan confirm */
#define MAC_MLME_START_CNF 8 /* Start confirm */
#define MAC_MLME_SYNC_LOSS_IND 9 /* Sync loss indication */
#define MAC_MLME_POLL_CNF 10 /* Poll confirm */
#define MAC_MLME_COMM_STATUS_IND 11 /* Communication status indication */
#define MAC_MCPS_DATA_CNF 12 /* Data confirm */
#define MAC_MCPS_DATA_IND 13 /* Data indication */
#define MAC_MCPS_PURGE_CNF 14 /* Purge confirm */
#define MAC_PWR_ON_CNF 15 /* Power on confirm */
#define MAC_MLME_POLL_IND 16 /* Poll indication */
#define MAC_RANDOM_SEED_LEN 16
/* Returns the number of short addresses in the pending address specification */
#define MAC_PEND_NUM_SHORT(pendAddrSpec) ((pendAddrSpec) & 0x07)
/* Returns the number of extended addresses in the pending address specification */
#define MAC_PEND_NUM_EXT(pendAddrSpec) (((pendAddrSpec) & 0x70) >> 4)
/* Returns the length in bytes of the pending address fields in the beacon */
#define MAC_PEND_FIELDS_LEN(pendAddrSpec) ((MAC_PEND_NUM_SHORT(pendAddrSpec) * 2) + \
(MAC_PEND_NUM_EXT(pendAddrSpec) * 8))
/* The following macros are provided to help parse the superframe specification */
#define MAC_SFS_BEACON_ORDER(s) ((s) & 0x0F) /* returns the beacon order */
#define MAC_SFS_SUPERFRAME_ORDER(s) (((s) >> 4) & 0x0F) /* returns the beacon order */
#define MAC_SFS_FINAL_CAP_SLOT(s) (((s) >> 8) & 0x0F) /* returns the final CAP slot */
#define MAC_SFS_BLE(s) (((s) >> 12) & 0x01) /* returns the battery life extension bit */
#define MAC_SFS_PAN_COORDINATOR(s) (((s) >> 14) & 0x01) /* returns the PAN coordinator bit */
#define MAC_SFS_ASSOCIATION_PERMIT(s) ((s) >> 15) /* returns the association permit bit */
/* MAC event header type */
typedef struct
{
uint8 event; /* MAC event */
uint8 status; /* MAC status */
} macEventHdr_t;
/* Common security type */
typedef struct
{
uint8 keySource[MAC_KEY_SOURCE_MAX_LEN]; /* Key source */
uint8 securityLevel; /* Security level */
uint8 keyIdMode; /* Key identifier mode */
uint8 keyIndex; /* Key index */
} macSec_t;
/* Key ID Lookup Descriptor */
typedef struct
{
uint8 lookupData[MAC_MAX_KEY_LOOKUP_LEN]; /* Data used to identify the key */
uint8 lookupDataSize; /* 0x00 indicates 5 octets; 0x01 indicates 9 octets. */
} keyIdLookupDescriptor_t;
/* Key Device Descriptor */
typedef struct
{
uint8 deviceDescriptorHandle; /* Handle to the DeviceDescriptor */
bool uniqueDevice; /* Is it a link key or a group key? */
bool blackListed; /* This key exhausted the frame counter. */
} keyDeviceDescriptor_t;
/* Key Usage Descriptor */
typedef struct
{
uint8 frameType; /* Frame Type */
uint8 cmdFrameId; /* Command Frame Identifier */
} keyUsageDescriptor_t;
/* Key Descriptor */
typedef struct
{
keyIdLookupDescriptor_t *keyIdLookupList; /* A list identifying this KeyDescriptor */
uint8 keyIdLookupEntries; /* The number of entries in KeyIdLookupList */
keyDeviceDescriptor_t *keyDeviceList; /* A list indicating which devices are
currently using this key, including
their blacklist status. */
uint8 keyDeviceListEntries; /* The number of entries in KeyDeviceList */
keyUsageDescriptor_t *keyUsageList; /* A list indicating which frame types
* this key may be used with. */
uint8 keyUsageListEntries; /* The number of entries in KeyUsageList */
uint8 key[MAC_KEY_MAX_LEN]; /* The actual value of the key */
} keyDescriptor_t;
/* Device Descriptor */
typedef struct
{
uint16 panID; /* The 16-bit PAN identifier of the device */
uint16 shortAddress; /* The 16-bit short address of the device */
sAddrExt_t extAddress; /* The 64-bit IEEE extended address of the
device. This element is also used in
unsecuring operations on incoming frames. */
uint32 frameCounter; /* The incoming frame counter of the device.
This value is used to ensure sequential
freshness of frames. */
bool exempt; /* Device may override the minimum security
level settings. */
} deviceDescriptor_t;
/* Security Level Descriptor */
typedef struct
{
uint8 frameType; /* Frame Type */
uint8 commandFrameIdentifier; /* Command Frame ID */
uint8 securityMinimum; /* The minimal required/expected security
level for incoming MAC frames. */
bool securityOverrideSecurityMinimum;
/* 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. */
} securityLevelDescriptor_t;
/* For internal use only */
typedef struct
{
uint32 timestamp;
uint16 timestamp2;
uint16 timeToLive;
uint8 frameType;
uint8 txOptions;
uint8 txMode;
uint8 txSched;
uint8 retries;
uint8 channel;
uint8 power;
uint8 mpduLinkQuality;
uint8 correlation;
int8 rssi;
} macTxIntData_t;
/* For internal use only */
typedef struct
{
uint8 frameType;
uint8 flags;
} macRxIntData_t;
/* Data request parameters type */
typedef struct
{
sAddr_t dstAddr; /* The address of the destination device */
uint16 dstPanId; /* The PAN ID of the destination device */
uint8 srcAddrMode; /* The source address mode */
uint8 msduHandle; /* Application-defined handle value associated with this data request */
uint8 txOptions; /* TX options bit mask */
uint8 channel; /* Transmit the data frame on this channel */
uint8 power; /* Transmit the data frame at this power level */
} macDataReq_t;
/* MCPS data request type */
typedef struct
{
macEventHdr_t hdr; /* Internal use only */
sData_t msdu; /* Data pointer and length */
macTxIntData_t internal; /* Internal use only */
macSec_t sec; /* Security parameters */
macDataReq_t mac; /* Data request parameters */
} macMcpsDataReq_t;
/* Data indication parameters type */
typedef struct
{
sAddr_t srcAddr; /* The address of the sending device */
sAddr_t dstAddr; /* The address of the destination device */
uint32 timestamp; /* The time, in backoffs, at which the data were received */
uint16 timestamp2; /* The time, in internal MAC timer units, at which the
data were received */
uint16 srcPanId; /* The PAN ID of the sending device */
uint16 dstPanId; /* The PAN ID of the destination device */
uint8 mpduLinkQuality; /* The link quality of the received data frame */
uint8 correlation; /* The raw correlation value of the received data frame */
int8 rssi; /* The received RF power in units dBm */
uint8 dsn; /* The data sequence number of the received frame */
} macDataInd_t;
/* MCPS data indication type */
typedef struct
{
macEventHdr_t hdr; /* Internal use only */
sData_t msdu; /* Data pointer and length */
macRxIntData_t internal; /* Internal use only */
macSec_t sec; /* Security parameters */
macDataInd_t mac; /* Data indication parameters */
} macMcpsDataInd_t;
/* MCPS data confirm type */
typedef struct
{
macEventHdr_t hdr; /* Contains the status of the data request operation */
uint8 msduHandle; /* Application-defined handle value associated with the data request */
macMcpsDataReq_t *pDataReq; /* Pointer to the data request buffer for this data confirm */
uint32 timestamp; /* The time, in backoffs, at which the frame was transmitted */
uint16 timestamp2; /* The time, in internal MAC timer units, at which the
frame was transmitted */
uint8 retries; /* The number of retries required to transmit the data frame */
uint8 mpduLinkQuality; /* The link quality of the received ack frame */
uint8 correlation; /* The raw correlation value of the received ack frame */
int8 rssi; /* The RF power of the received ack frame in units dBm */
} macMcpsDataCnf_t;
/* MCPS purge confirm type */
typedef struct
{
macEventHdr_t hdr; /* Contains the status of the purge request operation */
uint8 msduHandle; /* Application-defined handle value associated with the data request */
} macMcpsPurgeCnf_t;
/* PAN descriptor type */
typedef struct
{
sAddr_t coordAddress; /* The address of the coordinator sending the beacon */
uint16 coordPanId; /* The PAN ID of the network */
uint16 superframeSpec; /* The superframe specification of the network */
uint8 logicalChannel; /* The logical channel of the network */
uint8 channelPage; /* The current channel page occupied by the network */
bool gtsPermit; /* TRUE if coordinator accepts GTS requests */
uint8 linkQuality; /* The link quality of the received beacon */
uint32 timestamp; /* The time at which the beacon was received, in backoffs */
bool securityFailure; /* Set to TRUE if there was an error in the security processing */
macSec_t sec; /* The security parameters for the received beacon frame */
} macPanDesc_t;
/* MLME associate request type */
typedef struct
{
uint8 logicalChannel; /* The channel on which to attempt association */
uint8 channelPage; /* The channel page on which to attempt association */
sAddr_t coordAddress; /* Address of the coordinator with which to associate */
uint16 coordPanId; /* The identifier of the PAN with which to associate */
uint8 capabilityInformation; /* The operational capabilities of this device */
macSec_t sec; /* The security parameters for this message */
} macMlmeAssociateReq_t;
/* MLME associate response type */
typedef struct
{
sAddrExt_t deviceAddress; /* The address of the device requesting association */
uint16 assocShortAddress; /* The short address allocated to the device */
uint8 status; /* The status of the association attempt */
macSec_t sec; /* The security parameters for this message */
} macMlmeAssociateRsp_t;
/* MLME disassociate request type */
typedef struct
{
sAddr_t deviceAddress; /* The address of the device with which to disassociate */
uint16 devicePanId; /* The PAN ID of the device */
uint8 disassociateReason; /* The disassociate reason */
bool txIndirect; /* Transmit Indirect */
macSec_t sec; /* The security parameters for this message */
} macMlmeDisassociateReq_t;
/* MLME orphan response type */
typedef struct
{
sAddrExt_t orphanAddress; /* The extended address of the device sending the orphan notification */
uint16 shortAddress; /* The short address of the orphaned device */
bool associatedMember; /* Set to TRUE if the orphaned device is associated with this coordinator */
macSec_t sec; /* The security parameters for this message */
} macMlmeOrphanRsp_t;
/* MLME poll request type */
typedef struct
{
sAddr_t coordAddress; /* The address of the coordinator device to poll */
uint16 coordPanId; /* The PAN ID of the coordinator */
macSec_t sec; /* The security parameters for this message */
} macMlmePollReq_t;
/* MLME scan request type */
typedef struct
{
uint32 scanChannels; /* Bit mask indicating which channels to scan */
uint8 scanType; /* The type of scan */
uint8 scanDuration; /* The exponent used in the scan duration calculation */
uint8 channelPage; /* The channel page on which to perform the scan */
uint8 maxResults; /* The maximum number of PAN descriptor results */
macSec_t sec; /* The security parameters for orphan scan */
union {
uint8 *pEnergyDetect; /* Pointer to a buffer to store energy detect measurements */
macPanDesc_t *pPanDescriptor; /* Pointer to a buffer to store PAN descriptors */
} result;
} macMlmeScanReq_t;
/* MLME start request type */
typedef struct
{
uint32 startTime; /* The time to begin transmitting beacons relative to the received beacon */
uint16 panId; /* The PAN ID to use. This parameter is ignored if panCoordinator is FALSE */
uint8 logicalChannel; /* The logical channel to use. This parameter is ignored if panCoordinator is FALSE */
uint8 channelPage; /* The channel page to use. This parameter is ignored if panCoordinator is FALSE */
uint8 beaconOrder; /* The exponent used to calculate the beacon interval */
uint8 superframeOrder; /* The exponent used to calculate the superframe duration */
bool panCoordinator; /* Set to TRUE to start a network as PAN coordinator */
bool batteryLifeExt; /* If this value is TRUE, the receiver is disabled after MAC_BATT_LIFE_EXT_PERIODS
full backoff periods following the interframe spacing period of the beacon frame */
bool coordRealignment; /* Set to TRUE to transmit a coordinator realignment prior to changing
the superframe configuration */
macSec_t realignSec; /* Security parameters for the coordinator realignment frame */
macSec_t beaconSec; /* Security parameters for the beacon frame */
} macMlmeStartReq_t;
/* MAC_MlmeSyncReq type */
typedef struct
{
uint8 logicalChannel; /* The logical channel to use */
uint8 channelPage; /* The channel page to use */
bool trackBeacon; /* Set to TRUE to continue tracking beacons after synchronizing with the
first beacon. Set to FALSE to only synchronize with the first beacon */
} macMlmeSyncReq_t;
/* MAC_MLME_ASSOCIATE_IND type */
typedef struct
{
macEventHdr_t hdr; /* The event header */
sAddrExt_t deviceAddress; /* The address of the device requesting association */
uint8 capabilityInformation; /* The operational capabilities of the device requesting association */
macSec_t sec; /* The security parameters for this message */
} macMlmeAssociateInd_t;
/* MAC_MLME_ASSOCIATE_CNF type */
typedef struct
{
macEventHdr_t hdr; /* Event header contains the status of the associate attempt */
uint16 assocShortAddress; /* If successful, the short address allocated to this device */
macSec_t sec; /* The security parameters for this message */
} macMlmeAssociateCnf_t;
/* MAC_MLME_DISASSOCIATE_IND type */
typedef struct
{
macEventHdr_t hdr; /* The event header */
sAddrExt_t deviceAddress; /* The address of the device sending the disassociate command */
uint8 disassociateReason; /* The disassociate reason */
macSec_t sec; /* The security parameters for this message */
} macMlmeDisassociateInd_t;
/* MAC_MLME_DISASSOCIATE_CNF type */
typedef struct
{
macEventHdr_t hdr; /* Event header contains the status of the disassociate attempt */
sAddr_t deviceAddress; /* The address of the device that has either requested disassociation
or been instructed to disassociate by its coordinator */
uint16 panId; /* The pan ID of the device that has either requested disassociation
or been instructed to disassociate by its coordinator */
} macMlmeDisassociateCnf_t;
/* MAC_MLME_BEACON_NOTIFY_IND type */
typedef struct
{
macEventHdr_t hdr; /* The event header */
uint8 bsn; /* The beacon sequence number */
macPanDesc_t *pPanDesc; /* The PAN descriptor for the received beacon */
uint8 pendAddrSpec; /* The beacon pending address specification */
uint8 *pAddrList; /* The list of device addresses for which the sender of the beacon has data */
uint8 sduLength; /* The number of bytes in the beacon payload of the beacon frame */
uint8 *pSdu; /* The beacon payload */
} macMlmeBeaconNotifyInd_t;
/* MAC_MLME_ORPHAN_IND type */
typedef struct
{
macEventHdr_t hdr; /* The event header */
sAddrExt_t orphanAddress; /* The address of the orphaned device */
macSec_t sec; /* The security parameters for this message */
} macMlmeOrphanInd_t;
/* MAC_MLME_SCAN_CNF type */
typedef struct
{
macEventHdr_t hdr; /* Event header contains the status of the scan request */
uint8 scanType; /* The type of scan requested */
uint8 channelPage; /* The channel page of the scan */
uint32 unscannedChannels; /* Bit mask of channels that were not scanned */
uint8 resultListSize; /* The number of PAN descriptors returned in the results list */
union
{
uint8 *pEnergyDetect; /* The list of energy measurements, one for each channel scanned */
macPanDesc_t *pPanDescriptor; /* The list of PAN descriptors, one for each beacon found */
} result;
} macMlmeScanCnf_t;
/* MAC_MLME_START_CNF type */
typedef struct
{
macEventHdr_t hdr; /* Event header contains the status of the start request */
} macMlmeStartCnf_t;
/* MAC_MLME_SYNC_LOSS_IND type */
typedef struct
{
macEventHdr_t hdr; /* Event header contains the reason that synchronization was lost */
uint16 panId; /* The PAN ID of the realignment */
uint8 logicalChannel; /* The logical channel of the realignment */
uint8 channelPage; /* The channel page of the realignment */
macSec_t sec; /* The security parameters for this message */
} macMlmeSyncLossInd_t;
/* MAC_MLME_POLL_CNF type */
typedef struct
{
macEventHdr_t hdr; /* Event header contains the status of the poll request */
} macMlmePollCnf_t;
/* MAC_MLME_COMM_STATUS_IND type */
typedef struct
{
macEventHdr_t hdr; /* Event header contains the status for this event */
sAddr_t srcAddr; /* The source address associated with the event */
sAddr_t dstAddr; /* The destination address associated with the event */
uint16 panId; /* The PAN ID associated with the event */
uint8 reason; /* The reason the event was generated */
macSec_t sec; /* The security parameters for this message */
} macMlmeCommStatusInd_t;
/* MAC_MLME_POLL_IND type */
typedef struct
{
macEventHdr_t hdr;
uint16 srcShortAddr; /* Short address of the device sending the data request */
uint16 srcPanId; /* Pan ID of the device sending the data request */
} macMlmePollInd_t;
/* Union of callback structures */
typedef union
{
macEventHdr_t hdr;
macMlmeAssociateInd_t associateInd; /* MAC_MLME_ASSOCIATE_IND */
macMlmeAssociateCnf_t associateCnf; /* MAC_MLME_ASSOCIATE_CNF */
macMlmeDisassociateInd_t disassociateInd; /* MAC_MLME_DISASSOCIATE_IND */
macMlmeDisassociateCnf_t disassociateCnf; /* MAC_MLME_DISASSOCIATE_CNF */
macMlmeBeaconNotifyInd_t beaconNotifyInd; /* MAC_MLME_BEACON_NOTIFY_IND */
macMlmeOrphanInd_t orphanInd; /* MAC_MLME_ORPHAN_IND */
macMlmeScanCnf_t scanCnf; /* MAC_MLME_SCAN_CNF */
macMlmeStartCnf_t startCnf; /* MAC_MLME_START_CNF */
macMlmeSyncLossInd_t syncLossInd; /* MAC_MLME_SYNC_LOSS_IND */
macMlmePollCnf_t pollCnf; /* MAC_MLME_POLL_CNF */
macMlmeCommStatusInd_t commStatusInd; /* MAC_MLME_COMM_STATUS_IND */
macMlmePollInd_t pollInd; /* MAC_MLME_POLL_IND */
macMcpsDataCnf_t dataCnf; /* MAC_MCPS_DATA_CNF */
macMcpsDataInd_t dataInd; /* MAC_MCPS_DATA_IND */
macMcpsPurgeCnf_t purgeCnf; /* MAC_MCPS_PURGE_CNF */
} macCbackEvent_t;
/* Configurable parameters */
typedef struct
{
uint8 txDataMax; /* maximum number of data frames in transmit queue */
uint8 txMax; /* maximum number of frames of all types in transmit queue */
uint8 rxMax; /* maximum number of command and data frames in receive queue */
uint8 dataIndOffset; /* allocate additional bytes in the data indication for
application-defined headers */
bool appPendingQueue; /* determine whether MAC_MLME_POLL_IND will be sent to the application or not
when data request is received and no pending frame is found in the MAC */
} macCfg_t;
/* These functions are used when creating the OSAL MAC task. They must not be used for any
* other purpose.
*/
extern void macTaskInit(uint8 taskId);
extern uint16 macEventLoop(uint8 taskId, uint16 events);
extern void MAC_Init(void);
extern void MAC_InitDevice(void);
extern void MAC_InitCoord(void);
extern void MAC_InitSecurity(void);
extern void MAC_InitBeaconCoord(void);
extern void MAC_InitBeaconDevice(void);
extern void MAC_McpsDataReq(macMcpsDataReq_t *pData);
extern void MAC_McpsPurgeReq(uint8 msduHandle);
extern macMcpsDataReq_t *MAC_McpsDataAlloc(uint8 len, uint8 securityLevel, uint8 keyIdMode);
extern void MAC_MlmeAssociateReq(macMlmeAssociateReq_t *pData);
extern uint8 MAC_MlmeAssociateRsp(macMlmeAssociateRsp_t *pData);
extern void MAC_MlmeDisassociateReq(macMlmeDisassociateReq_t *pData);
extern uint8 MAC_MlmeGetReq(uint8 pibAttribute, void *pValue);
extern uint8 MAC_MlmeGetSecurityReq(uint8 pibAttribute, void *pValue);
extern void MAC_MlmeOrphanRsp(macMlmeOrphanRsp_t *pData);
extern void MAC_MlmePollReq(macMlmePollReq_t *pData);
extern uint8 MAC_MlmeResetReq(bool setDefaultPib);
extern void MAC_MlmeScanReq(macMlmeScanReq_t *pData);
extern uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue);
extern uint8 MAC_MlmeSetSecurityReq(uint8 pibAttribute, void *pValue);
extern void MAC_MlmeStartReq(macMlmeStartReq_t *pData);
extern void MAC_MlmeSyncReq(macMlmeSyncReq_t *pData);
extern uint8 MAC_PwrOffReq(uint8 mode);
extern void MAC_PwrOnReq(void);
extern uint8 MAC_PwrMode(void);
extern uint32 MAC_PwrNextTimeout(void);
extern uint8 MAC_RandomByte(void);
extern uint8 MAC_SrcMatchEnable ( uint8 addrType, uint8 num );
extern uint8 MAC_SrcMatchAddEntry ( sAddr_t *addr, uint16 panID );
extern uint8 MAC_SrcMatchDeleteEntry ( sAddr_t *addr, uint16 panID );
extern void MAC_SrcMatchAckAllPending ( uint8 option );
extern uint8 MAC_SrcMatchCheckAllPending ( void );
extern void MAC_SetRadioRegTable ( uint8 txPwrTblIdx, uint8 rssiAdjIdx );
extern void MAC_CbackEvent(macCbackEvent_t *pData);
extern uint8 MAC_CbackCheckPending(void);
#ifdef __cplusplus
};
#endif
#endif /* MAC_API_H */
#include "hal_types.h"
/* high-level */
#include "mac_pib.h"
/* exported low-level */
#include "mac_low_level.h"
/* low-level specific */
#include "mac_radio.h"
#include "mac_tx.h"
#include "mac_rx.h"
#include "mac_rx_onoff.h"
#include "mac_sleep.h"
#include "mac_backoff_timer.h"
/* target specific */
#include "mac_radio_defs.h"
/* debug */
#include "mac_assert.h"
#define ED_RF_POWER_MIN_DBM (MAC_RADIO_RECEIVER_SENSITIVITY_DBM + MAC_SPEC_ED_MIN_DBM_ABOVE_RECEIVER_SENSITIVITY)
#define ED_RF_POWER_MAX_DBM MAC_RADIO_RECEIVER_SATURATION_DBM
uint8 macPhyTxPower;
uint8 macPhyChannel;
static uint8 reqChannel;
static uint8 reqTxPower;
static uint8 radioComputeED(int8 rssiDbm);
MAC_INTERNAL_API void macRadioInit(void)
{
/* variable initialization for this module */
reqChannel = MAC_RADIO_CHANNEL_DEFAULT;
macPhyChannel = MAC_RADIO_CHANNEL_INVALID;
reqTxPower = MAC_RADIO_TX_POWER_INVALID;
macPhyTxPower = MAC_RADIO_TX_POWER_INVALID;
}
MAC_INTERNAL_API void macRadioReset(void)
{
macRadioStopScan();
macRadioEnergyDetectStop();
}
MAC_INTERNAL_API uint8 macRadioRandomByte(void)
{
return(MAC_RADIO_RANDOM_BYTE());
}
MAC_INTERNAL_API void macRadioSetPanCoordinator(uint8 panCoordFlag)
{
/* abstracted radio configuration */
MAC_RADIO_SET_PAN_COORDINATOR(panCoordFlag);
}
void macRadioSetPanID(uint16 panID)
{
/* abstracted radio configuration */
MAC_RADIO_SET_PAN_ID(panID);
}
MAC_INTERNAL_API void macRadioSetShortAddr(uint16 shortAddr)
{
/* abstracted radio configuration */
MAC_RADIO_SET_SHORT_ADDR(shortAddr);
}
MAC_INTERNAL_API void macRadioSetIEEEAddr(uint8 * pIEEEAddr)
{
/* abstracted radio configuration */
MAC_RADIO_SET_IEEE_ADDR(pIEEEAddr);
}
#ifndef HAL_MAC_USE_REGISTER_POWER_VALUES
MAC_INTERNAL_API uint8 macRadioSetTxPower(uint8 txPower)
{
halIntState_t s;
#if defined MAC_RUNTIME_CC2591 || defined MAC_RUNTIME_CC2590
const uint8 CODE *pTable = macRadioDefsTxPwrTables[macRadioDefsRefTableId >> 4];
#elif defined HAL_PA_LNA || defined HAL_PA_LNA_CC2590
const uint8 CODE *pTable = macRadioDefsTxPwrTables[0];
#else
const uint8 CODE *pTable = macRadioDefsTxPwrBare;
#endif
/* if the selected dBm is out of range, use the closest available */
if ((int8)txPower > (int8)pTable[MAC_RADIO_DEFS_TBL_TXPWR_FIRST_ENTRY])
{
/* greater than base value -- out of table range */
txPower = pTable[MAC_RADIO_DEFS_TBL_TXPWR_FIRST_ENTRY];
}
else if ((int8)txPower < (int8)pTable[MAC_RADIO_DEFS_TBL_TXPWR_LAST_ENTRY])
{
/* smaller than the lowest power level -- out of table range */
txPower = pTable[MAC_RADIO_DEFS_TBL_TXPWR_LAST_ENTRY];
}
HAL_ENTER_CRITICAL_SECTION(s);
/* When calculating index to the power register value table,
* either txPower (of uint8 type) has to be explicitly type-casted to int8
* or the subtraction expression has to be type-casted to uint8 to work
* with the integral promotions.
* The latter is more code size efficient and hence the latter is used.
*/
{
uint8 index = pTable[MAC_RADIO_DEFS_TBL_TXPWR_FIRST_ENTRY] - txPower
+ MAC_RADIO_DEFS_TBL_TXPWR_ENTRIES;
reqTxPower = pTable[index];
}
HAL_EXIT_CRITICAL_SECTION(s);
/* update the radio power setting */
macRadioUpdateTxPower();
return txPower;
}
#else
MAC_INTERNAL_API uint8 macRadioSetTxPower(uint8 txPower)
{
halIntState_t s;
/* same as above but with no lookup table, use raw register value */
HAL_ENTER_CRITICAL_SECTION(s);
reqTxPower = txPower;
HAL_EXIT_CRITICAL_SECTION(s);
/* update the radio power setting */
macRadioUpdateTxPower();
return txPower;
}
#endif
MAC_INTERNAL_API void macRadioUpdateTxPower(void)
{
halIntState_t s;
HAL_ENTER_CRITICAL_SECTION(s);
if (reqTxPower != macPhyTxPower)
{
if (!macRxOutgoingAckFlag && !MAC_TX_IS_PHYSICALLY_ACTIVE())
{
macPhyTxPower = reqTxPower;
MAC_RADIO_SET_TX_POWER(macPhyTxPower);
}
}
HAL_EXIT_CRITICAL_SECTION(s);
}
MAC_INTERNAL_API void macRadioSetChannel(uint8 channel)
{
halIntState_t s;
MAC_ASSERT((channel >= 11) && (channel <= 28)); /* illegal channel */
/* critical section to make sure transmit does not start while updating channel */
HAL_ENTER_CRITICAL_SECTION(s);
/* set requested channel */
reqChannel = channel;
if (!macTxActive)
{
macRadioUpdateChannel();
}
HAL_EXIT_CRITICAL_SECTION(s);
}
MAC_INTERNAL_API void macRadioUpdateChannel(void)
{
halIntState_t s;
MAC_ASSERT(!macTxActive); /* cannot change channel during a transmit */
/* if the channel has changed, set the radio to the new channel */
HAL_ENTER_CRITICAL_SECTION(s);
if (reqChannel != macPhyChannel)
{
macPhyChannel = reqChannel;
HAL_EXIT_CRITICAL_SECTION(s);
/* changing the channel stops any receive in progress */
macRxOff();
MAC_RADIO_SET_CHANNEL(macPhyChannel);
macRxHaltCleanup();
macRxOnRequest();
}
else
{
HAL_EXIT_CRITICAL_SECTION(s);
}
}
MAC_INTERNAL_API void macRadioStartScan(uint8 scanMode)
{
MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_AWAKE); /* radio must be awake */
MAC_ASSERT(macRxFilter == RX_FILTER_OFF); /* all filtering must be off to start scan */
/* set the receive filter based on the selected scan mode */
if (scanMode == MAC_SCAN_ED)
{
macRxFilter = RX_FILTER_ALL;
}
else if (scanMode == MAC_SCAN_ORPHAN)
{
macRxFilter = RX_FILTER_NON_COMMAND_FRAMES;
}
else
{
MAC_ASSERT((scanMode == MAC_SCAN_ACTIVE) || (scanMode == MAC_SCAN_PASSIVE)); /* invalid scan type */
macRxFilter = RX_FILTER_NON_BEACON_FRAMES;
/* for active and passive scans, per spec the pan ID must be 0xFFFF */
MAC_RADIO_SET_PAN_ID(0xFFFF);
}
}
MAC_INTERNAL_API void macRadioStopScan(void)
{
macRxFilter = RX_FILTER_OFF;
/* restore the pan ID (passive and active scans set pan ID to 0xFFFF) */
MAC_RADIO_SET_PAN_ID(macPib.panId);
}
void macRadioEnergyDetectStart(void)
{
/* Energy Detection Scan should be run with CC2591 compresson workaround off */
COMPRESSION_WORKAROUND_OFF();
MAC_RADIO_RECORD_MAX_RSSI_START();
}
uint8 macRadioEnergyDetectStop(void)
{
uint8 rssiDbm;
uint8 energyDetectMeasurement;
rssiDbm = MAC_RADIO_RECORD_MAX_RSSI_STOP() + MAC_RADIO_RSSI_OFFSET;
MAC_RADIO_RSSI_LNA_OFFSET(rssiDbm);
energyDetectMeasurement = radioComputeED(rssiDbm);
/* Trun on CC2591 compresson workaround */
COMPRESSION_WORKAROUND_ON();
return(energyDetectMeasurement);
}
static uint8 radioComputeED(int8 rssiDbm)
{
uint8 ed;
if (rssiDbm < ED_RF_POWER_MIN_DBM)
{
rssiDbm = ED_RF_POWER_MIN_DBM;
}
else if (rssiDbm > ED_RF_POWER_MAX_DBM)
{
rssiDbm = ED_RF_POWER_MAX_DBM;
}
ed = (MAC_SPEC_ED_MAX * (rssiDbm - ED_RF_POWER_MIN_DBM)) / (ED_RF_POWER_MAX_DBM - ED_RF_POWER_MIN_DBM);
return(ed);
}
MAC_INTERNAL_API uint8 macRadioComputeLQI(int8 rssiDbm, uint8 corr)
{
(void) corr; /* suppress compiler warning of unused parameter */
return(radioComputeED(rssiDbm));
}
#include "hal_types.h"
/* high-level */
#include "mac_pib.h"
/* exported low-level */
#include "mac_low_level.h"
/* low-level specific */
#include "mac_sleep.h"
#include "mac_radio.h"
#include "mac_tx.h"
#include "mac_rx.h"
#include "mac_rx_onoff.h"
/* target specific */
#include "mac_radio_defs.h"
/* debug */
#include "mac_assert.h"
uint8 macSleepState = MAC_SLEEP_STATE_RADIO_OFF;
MAC_INTERNAL_API void macSleepWakeUp(void)
{
/* don't wake up radio if it's already awake */
if (macSleepState == MAC_SLEEP_STATE_AWAKE)
{
return;
}
/* wake up MAC timer */
MAC_RADIO_TIMER_WAKE_UP();
/* if radio was completely off, restore from that state first */
if (macSleepState == MAC_SLEEP_STATE_RADIO_OFF)
{
/* turn on radio power (turns on oscillator too) */
MAC_RADIO_TURN_ON_POWER();
/* power-up initialization of receive logic */
macRxRadioPowerUpInit();
}
else
{
MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_OSC_OFF);
/* turn on the oscillator */
MAC_RADIO_TURN_ON_OSC();
}
/* update sleep state here before requesting to turn on receiver */
macSleepState = MAC_SLEEP_STATE_AWAKE;
/* turn on the receiver if enabled */
macRxOnRequest();
}
MAC_INTERNAL_API uint8 macSleep(uint8 sleepState)
{
halIntState_t s;
/* disable interrupts until macSleepState can be set */
HAL_ENTER_CRITICAL_SECTION(s);
/* assert checks */
MAC_ASSERT(macSleepState == MAC_SLEEP_STATE_AWAKE); /* radio must be awake to put it to sleep */
MAC_ASSERT(macRxFilter == RX_FILTER_OFF); /* do not sleep when scanning or in promiscuous mode */
/* if either RX or TX is active or any RX enable flags are set, it's not OK to sleep */
if (macRxActive || macRxOutgoingAckFlag || macTxActive || macRxEnableFlags)
{
HAL_EXIT_CRITICAL_SECTION(s);
return(FALSE);
}
/* turn off the receiver */
macRxOff();
/* update sleep state variable */
macSleepState = sleepState;
/* macSleepState is now set, re-enable interrupts */
HAL_EXIT_CRITICAL_SECTION(s);
/* put MAC timer to sleep */
MAC_RADIO_TIMER_SLEEP();
/* put radio in selected sleep mode */
if (sleepState == MAC_SLEEP_STATE_OSC_OFF)
{
MAC_RADIO_TURN_OFF_OSC();
}
else
{
MAC_ASSERT(sleepState == MAC_SLEEP_STATE_RADIO_OFF); /* unknown sleep state */
MAC_RADIO_TURN_OFF_POWER();
}
/* radio successfully entered sleep mode */
return(TRUE);
}
#if ((MAC_SLEEP_STATE_AWAKE == MAC_SLEEP_STATE_OSC_OFF) || \
(MAC_SLEEP_STATE_AWAKE == MAC_SLEEP_STATE_RADIO_OFF))
#error "ERROR! Non-unique state values."
#endif