summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/MAC_PHY/include/macphyPib.h
blob: 36cb28b0a05e4fd36d9063e6538948fc4f6583bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/**************************************************************************//**
  \file macphyPib.h

  \brief Types', constants' and functions' declarations for IEEE 802.15.4-2006
    MAC and PHY PIB access.

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
    History:
      28/09/07 A. Mandychev - Created.
******************************************************************************/

#ifndef _MACPHYPIB_H
#define _MACPHYPIB_H

/******************************************************************************
                    Includes section
******************************************************************************/
#include <inttypes.h>
#include <phy.h>
#include <macAddr.h>

/******************************************************************************
                    Define(s) section
******************************************************************************/
/**
 * \brief The maximum PSDU size (in octets) the PHY shall be able to receive/send.
 * IEEE Std 802.15.4-2006. Table 22.
*/
#define PHY_MAX_PACKET_SIZE   127U

//! RX-to-TX or TX-to-RX maximum turnaround time. IEEE Std 802.15.4-2006. Table 22.
#define PHY_TURNARROUND_TIME  12

/**
 * \brief The number of symbols forming a superframe slot when the superframe
 * order is equal to 0. IEEE Std 802.15.4-2006. Table 85.
*/
#define MAC_BASE_SLOT_DURATION          60

//! The number of slots contained in any superframe. IEEE Std 802.15.4-2006. Table 85.
#define MAC_NUM_SUPERFRAME_SLOTS        16

/**
 * \brief The number of symbols forming a superframe when the superframe
 * order is equal to 0. IEEE Std 802.15.4-2006. Table 85.
*/
#define MAC_BASE_SUPERFRAME_DURATION    (MAC_BASE_SLOT_DURATION * MAC_NUM_SUPERFRAME_SLOTS)

/**
 * \brief The number of superframes in which a GTS descriptor
 * exists in the beacon frame of the PAN coordinator. IEEE Std 802.15.4-2006. Table 85.
*/
#define MAC_GTS_DESC_PERSISTENCE_TIME   4

/**
 * \brief The maximum number of octets added by the MAC
 * sublayer to the MAC payload of a beacon frame. IEEE Std 802.15.4-2006. Table 85.
*/
#define MAC_MAX_BEACON_OVERHEAD         75

/**
 * \brief The maximum size, in octets, of a beacon payload.
 * IEEE Std 802.15.4-2006. Table 85.
 */
#define MAC_MAX_BEACON_PAYLOAD_LENGTH   (PHY_MAX_PACKET_SIZE - MAC_MAX_BEACON_OVERHEAD)

/**
 * \brief The number of consecutive lost beacons that will cause the MAC
 * sublayer of a receiving device to declare a loss of synchronization.
 * IEEE Std 802.15.4-2006. Table 85.
 */
#define MAC_MAX_LOST_BEACONS            4

/**
 * \brief The maximum number of octets added by the MAC sublayer to the PSDU
 * without security. IEEE Std 802.15.4-2006. Table 85.
*/
/**
 * \brief ZigBee Document 053474r17: D.4 aMaxMACFrameSize.
 *
*/

#ifndef _IEEE_ZIGBEE_COMPLIANCE_
  #define MAC_MAX_MPDU_UNSECURED_OVERHEAD 25U
#else
  #define MAC_MAX_MPDU_UNSECURED_OVERHEAD 11U // 25 - 8*2(ext addr) + 2*2(short addr) - 2(dst panId)
#endif // _IEEE_ZIGBEE_COMPLIANCE_

/**************************************************************************//**
  \brief The minimum number of octets added by the MAC sublayer to the PSDU.

  IEEE Std 802.15.4-2006. Table 85.
******************************************************************************/
#define MAC_MIN_MPDU_OVERHEAD           9

/**
 * \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.
 * IEEE Std 802.15.4-2006. Table 85.
 */
#define MAC_MAX_SAFE_PAYLOAD_SIZE       (PHY_MAX_PACKET_SIZE - MAC_MAX_MPDU_UNSECURED_OVERHEAD)

/**
 * \brief The maximum number of octets that can be transmitted in the MAC Payload field.
 * IEEE Std 802.15.4-2006. Table 85.
 */
#define MAC_MAX_PAYLOAD_SIZE            (PHY_MAX_PACKET_SIZE - MAC_MIN_MPDU_OVERHEAD)

/**
 * \brief The maximum size of an MPDU, in octets, that can be followed by a SIFS period.
 * IEEE Std 802.15.4-2006. Table 85.
 */
#define MAC_MAX_SIFS_FRAME_SIZE         18

//! The minimum number of symbols forming the CAP.IEEE Std 802.15.4-2006. Table 85.
#define MAC_MIN_CAP_LENGTH              440

/**
 * \brief The number of symbols forming the basic time period used
 * by the CSMA-CA algorithm.
 * IEEE Std 802.15.4-2006. Table 85.
 */
#define MAC_UNIT_BACKOFF_PERIOD         20

/** Bit mask of frequency bands that are supported by the underlying
 * IEEE 802.15.4 radio. */
#define PHY_FREQUENCY_BAND_868  0x01
#define PHY_FREQUENCY_BAND_902  0x04
#define PHY_FREQUENCY_BAND_2400 0x08

/**************************************************************************//**
  \def PHY_PIB_TRANSMIT_POWER_DEFAULT
  \brief Default transmit power for the radio trancivier.
******************************************************************************/
/**************************************************************************//**
  \def PHY_PIB_CURRENT_CHANNEL_DEFAULT
  \brief Default channel to start for the radio trancivier.
******************************************************************************/
/**************************************************************************//**
  \def PHY_PIB_CURRENT_PAGE_DEFAULT
  \brief Default page to start for the radio trancivier.
******************************************************************************/
#ifdef AT86RF230
  #define PHY_PIB_TRANSMIT_POWER_DEFAULT    DBM_3
  #define PHY_PIB_CURRENT_CHANNEL_DEFAULT   0x0B
  #define PHY_PIB_CURRENT_PAGE_DEFAULT      0
  #define PHY_FREQUENCY_BANDS               PHY_FREQUENCY_BAND_2400
#endif // AT86RF230
#ifdef AT86RF230B
  #define PHY_PIB_TRANSMIT_POWER_DEFAULT    DBM_3
  #define PHY_PIB_CURRENT_CHANNEL_DEFAULT   0x0B
  #define PHY_PIB_CURRENT_PAGE_DEFAULT      0
  #define PHY_FREQUENCY_BANDS               PHY_FREQUENCY_BAND_2400
#endif // AT86RF230B
#ifdef AT86RF231
  #define PHY_PIB_TRANSMIT_POWER_DEFAULT    DBM_3
  #define PHY_PIB_CURRENT_CHANNEL_DEFAULT   0x0B
  #define PHY_PIB_CURRENT_PAGE_DEFAULT      0
  #define PHY_FREQUENCY_BANDS               PHY_FREQUENCY_BAND_2400
#endif // AT86RF231
#ifdef AT86RF212
  #define PHY_PIB_TRANSMIT_POWER_DEFAULT    DBM_3
  #define PHY_PIB_CURRENT_CHANNEL_DEFAULT   0x05
  #define PHY_PIB_CURRENT_PAGE_DEFAULT      0
  #define PHY_FREQUENCY_BANDS               (PHY_FREQUENCY_BAND_868 | PHY_FREQUENCY_BAND_902)
#endif // AT86RF212
#ifdef ATMEGA128RFA1
  #define PHY_PIB_TRANSMIT_POWER_DEFAULT    DBM_3
  #define PHY_PIB_CURRENT_CHANNEL_DEFAULT   0x0B
  #define PHY_PIB_CURRENT_PAGE_DEFAULT      0
  #define PHY_FREQUENCY_BANDS               PHY_FREQUENCY_BAND_2400
#endif // ATMEGA128RFA1
#ifdef CUSTOMRF3
  #define PHY_PIB_TRANSMIT_POWER_DEFAULT    DBM_0
  #define PHY_PIB_CURRENT_CHANNEL_DEFAULT   0x05
  #define PHY_PIB_CURRENT_PAGE_DEFAULT      0
  #define PHY_FREQUENCY_BANDS               (PHY_FREQUENCY_BAND_868 | PHY_FREQUENCY_BAND_902)
#endif // CUSTOMRF3

//! Default channel access mode.
#define PHY_PIB_CCA_MODE_DEFAULT            PHY_CCA_MODE_1

// Default values of MAC PIB attributes.
#ifdef AT86RF230
#  define MAC_PIB_ACK_WAIT_DURATION_DEFAULT          54
#endif
#ifdef AT86RF230B
#  define MAC_PIB_ACK_WAIT_DURATION_DEFAULT          54
#endif
#ifdef AT86RF231
#  define MAC_PIB_ACK_WAIT_DURATION_DEFAULT          54
#endif
#ifdef AT86RF212
#  if PHY_PIB_CURRENT_PAGE_DEFAULT == 0
#    define MAC_PIB_ACK_WAIT_DURATION_DEFAULT        120
#  endif
#endif
#ifdef CUSTOMRF3
#  define MAC_PIB_ACK_WAIT_DURATION_DEFAULT          120
#endif
#ifdef ATMEGA128RFA1
#  define MAC_PIB_ACK_WAIT_DURATION_DEFAULT          54
#endif
#define MAC_PIB_ASSOCIATION_PERMIT_DEFAULT           false
#define MAC_PIB_AUTO_REQUEST_DEFAULT                 true
#define MAC_PIB_BATT_LIFE_EXT_DEFAULT                false
#define MAC_PIB_BEACON_PAYLOAD_DEFAULT               NULL
#define MAC_PIB_BEACON_PAYLOAD_LENGTH_DEFAULT        0
#define MAC_PIB_BEACON_ORDER_DEFAULT                 15
#define MAC_PIB_BEACON_TX_TIME_DEFAULT               0
#define MAC_PIB_COORD_SHORT_ADDR_DEFAULT             0xFFFF
#define MAC_PIB_COORD_EXT_ADDR_DEFAULT               0xFFFFFFFFFFFFFFFFLL ///< Not defined in standard.
#define MAC_PIB_GTS_PERMIT_DEFAULT                   true
#define MAC_PIB_MAX_CSMA_BACKOFFS_DEFAULT            4
#define MAC_PIB_MAX_BE_DEFAULT                       5
#define MAC_PIB_MIN_BE_DEFAULT                       3
#define MAC_PIB_PANID_DEFAULT                        0xFFFF
#define MAC_PIB_PROMISCUOUS_MODE_DEFAULT             false
#define MAC_PIB_RX_ON_WHEN_IDLE_DEFAULT              false
#define MAC_PIB_SHORT_ADDR_DEFAULT                   0xFFFF
#define MAC_PIB_SUPERFRAME_ORDER_DEFAULT             15
#define MAC_PIB_TRANSACTION_PERSISTENCE_TIME_DEFAULT 0x01F4
#define MAC_PIB_ASSOCIATED_PAN_COORD_DEFAULT         false
#define MAC_PIB_MAX_FRAME_RETRIES_DEFAULT            3
#define MAC_PIB_RESPONSE_WAIT_TIME_DEFAULT           32
#define MAC_PIB_SECURITY_ENABLED_DEFAULT             false

/******************************************************************************
                    Types section
******************************************************************************/
//! PHY PIB attribute identifiers (IEEE Std 802.15.4-2006. - table 23).
typedef enum
{
  PHY_PIB_CURRENT_CHANNEL_ID    = 0x00,
  PHY_PIB_CHANNELS_SUPPORTED_ID = 0x01,   // Read-only
  PHY_PIB_TRANSMIT_POWER_ID     = 0x02,
  PHY_PIB_CCA_MODE_ID           = 0x03,
  PHY_PIB_CURRENT_PAGE_ID       = 0x04,
  PHY_PIB_MAX_FRAME_DURATION_ID = 0x05,   // Read-only
  PHY_PIB_SHR_DURATION_ID       = 0x06,   // Read-only
  PHY_PIB_SYMBOLS_PER_OCTET_ID  = 0x07,   // Read-only
} PHY_PibId_t;

//! PHY PIB attribute types (IEEE Std 802.15.4-2006. - table 23).
typedef union
{
  uint8_t         channel;
  uint32_t        channelsSupported;
  int8_t          transmitPower;
  PHY_CcaMode_t   ccaMode;
  uint8_t         currentPage;
  uint16_t        maxFrameDuration;
  uint8_t         shrDuration;
  uint8_t         symbolsPerOctet;
} PHY_PibAttr_t;

//! MAC PIB attribute ID type.
typedef enum
{
  MAC_PIB_ACK_WAIT_DURATION_ID            = 0x40,
  MAC_PIB_ASSOCIATION_PERMIT_ID           = 0x41,
  MAC_PIB_AUTO_REQUEST_ID                 = 0x42,
  MAC_PIB_BATT_LIFE_EXT_ID                = 0x43,
  MAC_PIB_BATT_LIFE_EXT_PERIODS_ID        = 0x44,
  MAC_PIB_BEACON_PAYLOAD_ID               = 0x45,
  MAC_PIB_BEACON_PAYLOAD_LENGTH_ID        = 0x46,
  MAC_PIB_BEACON_ORDER_ID                 = 0x47,
  MAC_PIB_BEACON_TX_TIME_ID               = 0x48,
  MAC_PIB_BSN_ID                          = 0x49,
  MAC_PIB_COORD_EXT_ADDR_ID               = 0x4A,
  MAC_PIB_COORD_SHORT_ADDR_ID             = 0x4B,
  MAC_PIB_DSN_ID                          = 0x4C,
  MAC_PIB_GTS_PERMIT_ID                   = 0x4D,
  MAC_PIB_MAX_CSMA_BACKOFFS_ID            = 0x4E,
  MAC_PIB_MIN_BE_ID                       = 0x4F,
  MAC_PIB_PANID_ID                        = 0x50,
  MAC_PIB_PROMISCUOUS_MODE_ID             = 0x51,
  MAC_PIB_RX_ON_WHEN_IDLE_ID              = 0x52,
  MAC_PIB_SHORT_ADDR_ID                   = 0x53,
  MAC_PIB_SUPERFRAME_ORDER_ID             = 0x54,
  MAC_PIB_TRANSACTION_PERSISTENCE_TIME_ID = 0x55,
  MAC_PIB_ASSOCIATED_PAN_COORD_ID         = 0x56,
  MAC_PIB_MAX_BE_ID                       = 0x57,
  MAC_PIB_MAX_FRAME_TOTAL_WAIT_TIME_ID    = 0x58,
  MAC_PIB_MAX_FRAME_RETRIES_ID            = 0x59,
  MAC_PIB_RESPONSE_WAIT_TIME_ID           = 0x5A, ///< There is in additional parameter exist in PIB - MAC_PIB_RESPONSE_WAIT_TIME_MS_ID. Time in ms.
  MAC_PIB_SYNC_SYMBOL_OFFSET_ID           = 0x5B,
  MAC_PIB_TIMESTAMP_SUPPORTED_ID          = 0x5C,
  MAC_PIB_SECURITY_ENABLED_ID             = 0x5D,

  MAC_PIB_EXT_ADDR_ID                     = 0x6F,

  MAC_PIB_KEY_TABLE_ID                        = 0x71,
  MAC_PIB_KEY_TABLE_ENTRIES_ID                = 0x72,
  MAC_PIB_DEVICE_TABLE_ID                     = 0x73,
  MAC_PIB_DEVICE_TABLE_ENTRIES_ID             = 0x74,
  MAC_PIB_SECURITY_LEVEL_TABLE_ID             = 0x75,
  MAC_PIB_SECUTITY_LEVEL_TABLE_ENTRIES_ID     = 0x76,
  MAC_PIB_FRAME_COUNTER_ID                    = 0x77,
  MAC_PIB_AUTO_REQ_SECURITY_LEVEL_ID          = 0x78,
  MAC_PIB_AUTO_REQ_SECUTITY_KEY_ID_MODE_ID    = 0x79,
  MAC_PIB_AUTO_REQ_KEY_SOURCE_ID              = 0x7A,
  MAC_PIB_AUTO_REQUEST_KEY_INDEX_ID           = 0x7B,
  MAC_PIB_DEFAULT_KEY_SOURCE_ID               = 0x7C,
  MAC_PIB_PAN_COORD_EXT_ADDR_ID               = 0x7D,
  MAC_PIB_PAN_COORD_SHORT_ADDR_ID             = 0x7E,

  MAC_PIB_BEACON_TX_ENABLE_ID                 = 0x80, ///< Additional identifier. NOT described in the standard.
  MAC_PIB_RESPONSE_WAIT_TIME_MS_ID            = 0x81, ///< Additional identifier. NOT described in the standard. Time in ms. Read only.
  MAC_PIB_TRANSACTION_PERSIST_TIME_MS_ID      = 0x83, ///

} MAC_PibId_t;

//! MAC PIB attribute type.
typedef union
{
  uint32_t              ackWaitDuration;
  bool                  associationPermit;
  bool                  autoRequest;
  //bool                  battLifeExt;
  //uint8_t               battLifeExtPeriods;
  uint8_t               *beaconPayload;
  uint8_t               beaconPayloadLength;
  //uint8_t               beaconOrder;
  //uint32_t              beaconTxTime;
  uint8_t               bsn;
  ExtAddr_t             coordExtAddr;
  ShortAddr_t           coordShortAddr;
  uint8_t               dsn;
  bool                  gtsPermit;
  uint8_t               maxCsmaBackoffs;
  uint8_t               minBe;
  PanId_t               panId;
  //bool                  promiscuousMode;
  bool                  rxOnWhenIdle;
  ShortAddr_t           shortAddr;
  ExtAddr_t             extAddr;                   // Additional parameter. NOT described in the standard.
                                                   // This parameter replaces MAC_EXTENDED_ADDRESS constant.
                                                   // Device own extended address.
  //uint8_t               superframeOrder;
  uint16_t              transactionPersistenceTime;
  uint32_t              transactionPersistenceTimeInMs;
  bool                  associatedPanCoord;
  uint8_t               maxBe;
  //uint8_t               maxFrameTotalWaitTime;
  uint8_t               maxFrameRetries;
  uint8_t               responseWaitTime;
  bool                  timestampSupported;
  bool                  securityEnabled;
  bool                  beaconTxEnable;
  uint32_t              responseWaitTimeMs; // MAC response wait time in !!!milliseconds!!!.
} MAC_PibAttr_t;

//! Union of MAC and PHY PIB attributes.
typedef union
{
  MAC_PibAttr_t macPibAttr;
  PHY_PibAttr_t phyPibAttr;
} MACPHY_PibAttr_t;

//! Union of MAC and PHY PIB attributes IDs.
typedef union
{
  MAC_PibId_t macPibId;
  PHY_PibId_t phyPibId;
} MACPHY_PibId_t;

/******************************************************************************
                   Constants section
******************************************************************************/

#endif /* _MACPHYPIB_H */

// eof macphyPib.h