?? mac.h
字號:
//----------------------------------------------------//
//-------Institute Of Computing Technology-----------//
//------------Chinese Academic Science---------------//
//-----中國科學院計算技術研究所先進測試技術實驗室-----//
//----------------------------------------------------//
/**
* @copyright:nbicc_lpp
* @this is mac layer header
* @author liulingyi (lingyiliu@ict.ac.cn)
* zhouqiang (zhouhongren@163.com)
*
* @data:2005.11.07
* @version:0.0.1
* @updata:$
*
*/
#ifndef _MAC_H_
#define _MAC_H_
#include "phy.h"
#include "generic.h"
//--------------------------------------------------//
//-----------幀控制字段設置的一些預定義常數---------//
//--------------------------------------------------//
#define aMaxPHYPacketSize 127
//幀類型字段bit[2:0]
#define MAC_FRAME_BEACON (0x00)
#define MAC_FRAME_DATA (0x01)
#define MAC_FRAME_ACK (0x02)
#define MAC_FRAME_CMD (0x03)
//該幀的傳送是否采用MAC層的安全策略bit[3]
#define MAC_SECURITY_YES (0x08)
#define MAC_SECURITY_NO (0x00)
//用在間接通信中,表示還有數據沒傳完,需要繼續發data request命令幀bit[4]
#define MAC_FRAME_PENDING_YES (0x10)
#define MAC_FRAME_PENDING_NO (0x00)
//對當前幀的傳送,是否需要收方的應答bit[5]
#define MAC_ACK_YES (0x20)
#define MAC_ACK_NO (0x00)
//是否為同一個PAN內的傳送劉bit[6]
#define MAC_INTRA_PAN_YES (0x40)
#define MAC_INTRA_PAN_NO (0x00)
//源地址模式定義字段bit[11:10]
#define MAC_DST_NO_ADDR (0x00)
#define MAC_DST_SHORT_ADDR (0x08)
#define MAC_DST_LONG_ADDR (0x0c)
#define MAC_DST_ADDR_RESERVED (0x04)
//目標地址模式定義字段bit[15:14]
#define MAC_SRC_NO_ADDR (0x00)
#define MAC_SRC_SHORT_ADDR (0x80)
#define MAC_SRC_LONG_ADDR (0xc0)
#define MAC_SRC_ADDR_RESERVED (0x40)
//九種命令幀類型信息字段
#define MAC_CMD_ASSOCIATE_REQ (0x01)
#define MAC_CMD_ASSOCIATE_RPLY (0x02)
#define MAC_CMD_DISASSOCIATE_NOTICE (0x03)
#define MAC_CMD_DATA_REQ (0x04)
#define MAC_CMD_PAN_ID_CONFLICT (0x05)
#define MAC_CMD_ORPHAN_NOTICE (0x06)
#define MAC_CMD_BEACON_REQ (0x07)
#define MAC_CMD_COORD_REALIGNMENT (0x08)
#define MAC_CMD_GTS_REQ (0x09)
#define ED_SCAN (0x00)
#define ACTIVE_PASSIVE_SCAN (0x01)
//#define PASSIVE_SCAN (0x02)
#define ORPHAN_SCAN (0x03)
//通過條件編譯確定本設備是否為協調者
#ifdef I_AM_COORDINATOR
#define IS_COORDINATOR (0x01) // 1 is yes, 0 if no.
//#define IS_FFD (0x02)
#else
#define IS_COORDINATOR (0x00)
#endif
//通過條件編譯確定是否采用MAC層的安全策略
#ifdef I_AM_SECURITY_CAPABLE
#define MAC_OPT_SECURITY MAC_SECURITY_YES
#define MAC_OPT_ACL_SIZE 0x10
#else
#define MAC_OPT_SECURITY MAC_SECURITY_NO
#define MAC_OPT_ACL_SIZE 0x00
#endif
//通過條件編譯確定本設備是否為FFD設備
#ifdef I_AM_RFD
#define IS_FFD (0x00) // 0x02 if yes, 0x00 if RFD
#define IS_RFD TRUE
#else
#define IS_FFD (0x02)
#define IS_RFD FALSE
#endif
#ifdef I_AM_FFD
#define IS_FFD (0x02)
#else
#define IS_FFD (0x00)
#endif
//通過條件編譯確定本設備的供電模式
#ifdef I_AM_MAINS_POWERED
#define IS_MAINS_POWERED (0x04)
#else
#define IS_MAINS_POWERED (0x00)
#endif
//通過條件編譯確定本設備射頻空閑時候,接收是否打開
#ifdef MY_RX_IS_ALWAYS_ON_WHEN_IDLE
#define IS_RX_ALWAYS_ON (0x08)
#else
#define IS_RX_ALWAYS_ON (0x00)
#endif
//通過條件編譯確定本設備的MAC安全是否使能
#ifdef I_AM_SECURITY_CAPABLE
#define IS_SECURITY_ENABLED (0x40)
#else
#define IS_SECURITY_ENABLED (0x00)
#endif
//通過條件編譯確定本設備是否希望協調設備給他分配短地址(pg125)
#ifdef MAC_USE_SHORT_ADDR
#define IS_SHORT_ADDRESS (0x80)
#else
#define IS_SHORT_ADDRESS (0x00)
#endif
//關聯網絡時候使用的本設備的有用信息
#define MAC_CAP_INFO (IS_COORDINATOR | \
IS_FFD | \
IS_MAINS_POWERED | \
IS_RX_ALWAYS_ON | \
IS_SECURITY_ENABLED | \
IS_SHORT_ADDRESS);
//MAC層的枚舉常數,反映MAC層各原語的狀態值.(pg110)
#define SUCCESS 0
#define BEACON_LOSS 0xE0
#define CHANNEL_ACCESS_FAILURE 0xE1
#define DENIED 0xE2
#define DISABLE_TRX_FAILURE 0xE3
#define FAILED_SECURITY_CHECK 0xE4
#define FRAME_TOO_LONG 0xE5
#define INVALID_GTS 0xE6
#define INVALID_HANDLE 0xE7
#define INVALID_PARAMETER 0xE8
#define NO_ACK 0xE9
#define NO_BEACON 0xEA
#define NO_DATA 0xEB
#define NO_SHORT_ADDRESS 0xEC
#define OUT_OF_CAP 0xED
#define PAN_ID_CONFLICT 0xEE
#define REALIGNMENT 0xEF
#define TRANSACTION_EXPIRED 0xF0
#define TRANSACTION_OVERFLOW 0xF1
#define TX_ACTIVE 0xF2
#define UNAVAILABLE_KEY 0xF3
#define UNSUPPORTED_ATTRIBUTE 0xF4
#define RX_DEFERRED 0xF5
// 反映關聯的狀態值(pg126)
#define PAN_AT_CAPACITY 0x01
#define PAN_ACCESS_DENIED 0x02
//反映取消關聯的原因狀態值 (pg127)
#define COORD_WISH_TO_LEAVE 0x01
#define DIVICE_TO_LEAVE 0x02
//反映MAC層特征的一些常數
#define aBaseSlotDuration 20
#define aNumSuperframeSlots 8
#define aBaseSuperframeDuration (aBaseSlotDuration * aNumSuperframeSlots)
#define aMaxBE 5
#define aMaxBeaconOverhead 75
#define aMaxBeaconPayloadLength (aMaxPHYPacketSize - aMaxBeaconOverhead)
#define aGTSDescPersistenceTime 4
#define aMaxFrameOverhead 25
#define aMaxFrameResponseTime 1220
#define aMaxFrameRetries 2
#define aMaxLostBeacons 4
#define aMaxMACFrameSize (aMaxPHYPacketSize - aMaxFrameOverhead)
#define aMaxSIFSFrameSize 18
#define aMinCAPLength 440
#define aMinLIFSPeriod 40
#define aMinSIFSPeriod 12
#define aResponseWaitTime (10 * aBaseSuperframeDuration)
//#define aUnitBackoffPeriod
//其他的涉及MAC層的常數定義
#define MAX_PENDING_LIST_SIZE 2
//反映安全策略的一些參數,包括MAC層的和PHY層的
// MAC ACL and security information bases
#ifdef I_AM_SECURITY_CAPABLE
#define MAC_SECURITY_NONE 0x00
#define MAC_SECURITY_AES_CTR 0x01
#define MAC_SECURITY_AES_CCM128 0x02
#define MAC_SECURITY_AES_CCM64 0x03
#define MAC_SECURITY_AES_CCM32 0x04
#define MAC_SECURITY_AES_CBC_MAC128 0x05
#define MAC_SECURITY_AES_CBC_MAC64 0x06
#define MAC_SECURITY_AES_CBC_MAC32 0x07
#define MAC_HIGHEST_SECURITY_MODE MAC_SECURITY_AES_CBC_MAC32
#define MAC_UNSECURED_MODE 0x00
#define MAC_ACL_MODE 0x01
#define MAC_SECURED_MODE 0x02
#define TX_OPTION_ACK_NEED 0x01;
#define TX_OPTION_GTS_TRANSMIT 0x02;
#define TX_OPTION_INDIRECT 0x04;
#define TX_OPTION_SECURITY 0x08;
// MAC Security flags definitions.
// Note that the bits are shifted compared to the actual security flags //defined by IEEE 802.15.4,
// please see the CC2420 datasheet for details.
#define MAC_CC2420_CTR_FLAGS 0x42
#define MAC_CC2420_CCM_FLAGS 0x09
#endif
//--------------------------------------------------//
//---下面為Zigbee中MAC層用到的專用的數據類型定義----//
//--------------------------------------------------//
//MAC層安全策略相關的類型定義
#if ((MAC_OPT_SECURITY) || (MAC_OPT_ACL_SIZE>0))
typedef BYTE KEY[16];
typedef struct _SECURITY_MATERIAL {
KEY pSymmetricKey;
DWORD frameCounter;
BYTE keySequenceCounter;
#if MAC_OPT_SEQUENTIAL_FRESHNESS
DWORD externalFrameCounter;
BYTE externalKeySequenceCounter;
#endif
} SECURITY_MATERIAL;
// Access Control List
typedef struct _ACL_ENTRY {
QWORD extendedAddress;
WORD shortAddress;
WORD panId;
BYTE securityMaterialLength;
SECURITY_MATERIAL* pSecurityMaterial;
BYTE securitySuite;
} ACL_ENTRY;
typedef ACL_ENTRY ACL_ENTRY_SET[MAC_OPT_ACL_SIZE];
#endif
//8字節長地址類型定義
//PAN地址類型定義
typedef SHORT_ADDR PAN_ADDR;
//MAC層的PIB存儲結構定義
typedef struct _MAC_PIB{
BYTE macAckWaitDuration;
bool macAssociationPermit;
bool macAutoRequest;
bool macBattLifeExt;
BYTE macBattLifeExtPeriods;
BYTE* pMacBeaconPayload;
BYTE macBeaconPayloadLength;
uint8_t macBeaconOrder;
DWORD macBeaconTxTime;
BYTE macBSN;
LONG_ADDR macCoordExtendedAddress;
SHORT_ADDR macCoordShortAddress;
BYTE macDSN;
bool macGTSPermit;
BYTE macMaxCsmaBackoffs;
BYTE macMinBE;
SHORT_ADDR macPANId;
bool macPromiscuousMode;
bool macRxOnWhenIdle;
SHORT_ADDR macShortAddress;
LONG_ADDR macExtAddress;
uint8_t macSuperframeOrder;
WORD macTransactionPersistenceTime;
#if MAC_OPT_ACL_SIZE>0
// ACL attributes
ACL_ENTRY_SET* ppMacACLEntryDescriptorSet;
BYTE macACLEntryDescriptorSetSize;
#endif
#if MAC_OPT_SECURITY
// Security attributes
bool macDefaultSecurity;
BYTE macDefaultSecurityMaterialLength;
SECURITY_MATERIAL* pMacDefaultSecurityMaterial;
BYTE macDefaultSecuritySuite;
#endif
#if ((MAC_OPT_SECURITY) || (MAC_OPT_ACL_SIZE>0))
BYTE macSecurityMode;
#endif
} MAC_PIB;
//給MAC PIB中的屬性一個ID編號,從而用于訪問
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,
MAC_BEACON_PAYLOAD_LENGTH,
MAC_BEACON_ORDER,
MAC_BEACON_TX_TIME,
MAC_BSN,
MAC_COORD_EXTENDED_ADDRESS,
MAC_COORD_SHORT_ADDRESS,
MAC_DSN,
MAC_GTS_PERMIT,
MAC_MAX_CSMA_BACKOFFS,
MAC_MIN_BE,
MAC_PAN_ID,
MAC_PROMISCUOUS_MODE,
MAC_RX_ON_WHEN_IDLE,
MAC_SHORT_ADDRESS,
MAC_SUPERFRAME_ORDER,
MAC_TRANSACTION_PERSISTENCE_TIME,
MAC_ACL_ENTRY_DESCRIPTOR_SET = 0x70,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -