p802_15_4mac.h
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:26k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /********************************************/
  2. /*     NS2 Simulator for IEEE 802.15.4      */
  3. /*           (per P802.15.4/D18)            */
  4. /*------------------------------------------*/
  5. /* by:        Jianliang Zheng               */
  6. /*        (zheng@ee.ccny.cuny.edu)          */
  7. /*              Myung J. Lee                */
  8. /*          (lee@ccny.cuny.edu)             */
  9. /*        ~~~~~~~~~~~~~~~~~~~~~~~~~         */
  10. /*           SAIT-CUNY Joint Lab            */
  11. /********************************************/
  12. // File:  p802_15_4mac.h
  13. // Mode:  C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t
  14. // $Header: /cvsroot/nsnam/ns-2/wpan/p802_15_4mac.h,v 1.3 2007/01/30 05:00:52 tom_henderson Exp $
  15. /*
  16.  * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and
  17.  * The City University of New York. All rights reserved.
  18.  *
  19.  * Redistribution and use in source and binary forms, with or without
  20.  * modification, are permitted provided that the following conditions
  21.  * are met:
  22.  * 1. Redistributions of source code must retain the above copyright
  23.  *    notice, this list of conditions and the following disclaimer.
  24.  * 2. Redistributions in binary form must reproduce the above copyright
  25.  *    notice, this list of conditions and the following disclaimer in the
  26.  *    documentation and/or other materials provided with the distribution.
  27.  * 3. All advertising materials mentioning features or use of this software
  28.  *    must display the following acknowledgement:
  29.  * This product includes software developed by the Joint Lab of Samsung 
  30.  *      Advanced Institute of Technology and The City University of New York.
  31.  * 4. Neither the name of Samsung Advanced Institute of Technology nor of 
  32.  *    The City University of New York may be used to endorse or promote 
  33.  *    products derived from this software without specific prior written 
  34.  *    permission.
  35.  *
  36.  * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE
  37.  * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS 
  38.  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
  39.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 
  40.  * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK 
  41.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  42.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
  43.  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  44.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
  45.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
  46.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  */
  48. #ifndef p802_15_4mac_h
  49. #define p802_15_4mac_h
  50. #include "p802_15_4pkt.h"
  51. #include "p802_15_4phy.h"
  52. #include "p802_15_4timer.h"
  53. #include "p802_15_4hlist.h"
  54. #include "p802_15_4transac.h"
  55. //Elements of PAN descriptor (Table 41)
  56. struct PAN_ELE
  57. {
  58. UINT_8 CoordAddrMode;
  59. UINT_16 CoordPANId;
  60. union
  61. {
  62. UINT_16 CoordAddress_16;
  63. IE3ADDR CoordAddress_64;
  64. };
  65. UINT_8 LogicalChannel;
  66. UINT_16 SuperframeSpec;
  67. bool GTSPermit;
  68. UINT_8 LinkQuality;
  69. UINT_32 TimeStamp:24;
  70. bool SecurityUse;
  71. UINT_8 ACLEntry;
  72. bool SecurityFailure;
  73. //add one field for cluster tree
  74. UINT_16 clusTreeDepth;
  75. };
  76. //task pending (callback)
  77. #define TP_mcps_data_request 1
  78. #define TP_mlme_associate_request 2
  79. #define TP_mlme_associate_response 3
  80. #define TP_mlme_disassociate_request 4
  81. #define TP_mlme_orphan_response 5
  82. #define TP_mlme_reset_request 6
  83. #define TP_mlme_rx_enable_request 7
  84. #define TP_mlme_scan_request 8
  85. #define TP_mlme_start_request 9
  86. #define TP_mlme_sync_request 10
  87. #define TP_mlme_poll_request 11
  88. #define TP_CCA_csmaca 12
  89. #define TP_RX_ON_csmaca 13
  90. struct taskPending
  91. {
  92. taskPending()
  93. {
  94. init();
  95. }
  96. inline void init()
  97. {
  98. mcps_data_request = false;
  99. mcps_data_request_STEP = 0;
  100. mlme_associate_request = false;
  101. mlme_associate_request_STEP = 0;
  102. mlme_associate_response = false;
  103. mlme_associate_response_STEP = 0;
  104. mlme_disassociate_request = false;
  105. mlme_disassociate_request_STEP = 0;
  106. mlme_orphan_response = false;
  107. mlme_orphan_response_STEP = 0;
  108. mlme_reset_request = false;
  109. mlme_reset_request_STEP = 0;
  110. mlme_rx_enable_request = false;
  111. mlme_rx_enable_request_STEP = 0;
  112. mlme_scan_request = false;
  113. mlme_scan_request_STEP = 0;
  114. mlme_start_request = false;
  115. mlme_start_request_STEP = 0;
  116. mlme_sync_request = false;
  117. mlme_sync_request_STEP = 0;
  118. mlme_sync_request_tracking = false;
  119. mlme_poll_request = false;
  120. mlme_poll_request_STEP = 0;
  121. CCA_csmaca = false;
  122. CCA_csmaca_STEP = 0;
  123. RX_ON_csmaca = false;
  124. RX_ON_csmaca_STEP = 0;
  125. }
  126. bool &taskStatus(UINT_8 task)
  127. {
  128. switch (task)
  129. {
  130. case TP_mcps_data_request:
  131. return mcps_data_request;
  132. case TP_mlme_associate_request:
  133. return mlme_associate_request;
  134. case TP_mlme_associate_response:
  135. return mlme_associate_response;
  136. case TP_mlme_disassociate_request:
  137. return mlme_disassociate_request;
  138. case TP_mlme_orphan_response:
  139. return mlme_orphan_response;
  140. case TP_mlme_reset_request:
  141. return mlme_reset_request;
  142. case TP_mlme_rx_enable_request:
  143. return mlme_rx_enable_request;
  144. case TP_mlme_scan_request:
  145. return mlme_scan_request;
  146. case TP_mlme_start_request:
  147. return mlme_start_request;
  148. case TP_mlme_sync_request:
  149. return mlme_sync_request;
  150. case TP_mlme_poll_request:
  151. return mlme_poll_request;
  152. case TP_CCA_csmaca:
  153. return CCA_csmaca;
  154. case TP_RX_ON_csmaca:
  155. return RX_ON_csmaca;
  156. default:
  157. assert(0);
  158. // shutup the compiler.
  159. return RX_ON_csmaca;
  160. }
  161. }
  162. UINT_8 &taskStep(UINT_8 task)
  163. {
  164. switch (task)
  165. {
  166. case TP_mcps_data_request:
  167. return mcps_data_request_STEP;
  168. case TP_mlme_associate_request:
  169. return mlme_associate_request_STEP;
  170. case TP_mlme_associate_response:
  171. return mlme_associate_response_STEP;
  172. case TP_mlme_disassociate_request:
  173. return mlme_disassociate_request_STEP;
  174. case TP_mlme_orphan_response:
  175. return mlme_orphan_response_STEP;
  176. case TP_mlme_reset_request:
  177. return mlme_reset_request_STEP;
  178. case TP_mlme_rx_enable_request:
  179. return mlme_rx_enable_request_STEP;
  180. case TP_mlme_scan_request:
  181. return mlme_scan_request_STEP;
  182. case TP_mlme_start_request:
  183. return mlme_start_request_STEP;
  184. case TP_mlme_sync_request:
  185. return mlme_sync_request_STEP;
  186. case TP_mlme_poll_request:
  187. return mlme_poll_request_STEP;
  188. case TP_CCA_csmaca:
  189. return CCA_csmaca_STEP;
  190. case TP_RX_ON_csmaca:
  191. return RX_ON_csmaca_STEP;
  192. default:
  193. assert(0);
  194. // shutup compiler.
  195. return RX_ON_csmaca_STEP;
  196. }
  197. }
  198. char *taskFrFunc(UINT_8 task)
  199. {
  200. switch (task)
  201. {
  202. case TP_mcps_data_request:
  203. return mcps_data_request_frFunc;
  204. case TP_mlme_associate_request:
  205. return mlme_associate_request_frFunc;
  206. case TP_mlme_associate_response:
  207. return mlme_associate_response_frFunc;
  208. case TP_mlme_disassociate_request:
  209. return mlme_disassociate_request_frFunc;
  210. case TP_mlme_orphan_response:
  211. return mlme_orphan_response_frFunc;
  212. case TP_mlme_reset_request:
  213. return mlme_reset_request_frFunc;
  214. case TP_mlme_rx_enable_request:
  215. return mlme_rx_enable_request_frFunc;
  216. case TP_mlme_scan_request:
  217. return mlme_scan_request_frFunc;
  218. case TP_mlme_start_request:
  219. return mlme_start_request_frFunc;
  220. case TP_mlme_sync_request:
  221. return mlme_sync_request_frFunc;
  222. case TP_mlme_poll_request:
  223. return mlme_poll_request_frFunc;
  224. default:
  225. assert(0);
  226. // shutup compiler.
  227. return mlme_poll_request_frFunc;
  228. }
  229. }
  230. //----------------
  231. bool mcps_data_request;
  232. UINT_8 mcps_data_request_STEP;
  233. char mcps_data_request_frFunc[81];
  234. UINT_8 mcps_data_request_TxOptions;
  235. Packet *mcps_data_request_pendPkt;
  236. //----------------
  237. bool mlme_associate_request;
  238. UINT_8 mlme_associate_request_STEP;
  239. char mlme_associate_request_frFunc[81];
  240. bool mlme_associate_request_SecurityEnable;
  241. UINT_8 mlme_associate_request_CoordAddrMode;
  242. Packet *mlme_associate_request_pendPkt;
  243. //----------------
  244. bool mlme_associate_response;
  245. UINT_8 mlme_associate_response_STEP;
  246. char mlme_associate_response_frFunc[81];
  247. IE3ADDR mlme_associate_response_DeviceAddress;
  248. Packet *mlme_associate_response_pendPkt;
  249. //----------------
  250. bool mlme_disassociate_request;
  251. UINT_8 mlme_disassociate_request_STEP;
  252. char mlme_disassociate_request_frFunc[81];
  253. bool mlme_disassociate_request_toCoor;
  254. Packet *mlme_disassociate_request_pendPkt;
  255. //----------------
  256. bool mlme_orphan_response;
  257. UINT_8 mlme_orphan_response_STEP;
  258. char mlme_orphan_response_frFunc[81];
  259. IE3ADDR mlme_orphan_response_OrphanAddress;
  260. //----------------
  261. bool mlme_reset_request;
  262. UINT_8 mlme_reset_request_STEP;
  263. char mlme_reset_request_frFunc[81];
  264. bool mlme_reset_request_SetDefaultPIB;
  265. //----------------
  266. bool mlme_rx_enable_request;
  267. UINT_8 mlme_rx_enable_request_STEP;
  268. char mlme_rx_enable_request_frFunc[81];
  269. UINT_32 mlme_rx_enable_request_RxOnTime;
  270. UINT_32 mlme_rx_enable_request_RxOnDuration;
  271. double mlme_rx_enable_request_currentTime;
  272. //----------------
  273. bool mlme_scan_request;
  274. UINT_8 mlme_scan_request_STEP;
  275. char mlme_scan_request_frFunc[81];
  276. UINT_8 mlme_scan_request_ScanType;
  277. UINT_8 mlme_scan_request_orig_macBeaconOrder;
  278. UINT_8 mlme_scan_request_orig_macBeaconOrder2;
  279. UINT_8 mlme_scan_request_orig_macBeaconOrder3;
  280. UINT_16 mlme_scan_request_orig_macPANId;
  281. UINT_32 mlme_scan_request_ScanChannels;
  282. UINT_8 mlme_scan_request_ScanDuration;
  283. UINT_8 mlme_scan_request_CurrentChannel;
  284. UINT_8 mlme_scan_request_ListNum;
  285. UINT_8 mlme_scan_request_EnergyDetectList[27];
  286. PAN_ELE mlme_scan_request_PANDescriptorList[27];
  287. //----------------
  288. bool mlme_start_request;
  289. UINT_8 mlme_start_request_STEP;
  290. char mlme_start_request_frFunc[81];
  291. UINT_8 mlme_start_request_BeaconOrder;
  292. UINT_8 mlme_start_request_SuperframeOrder;
  293. bool mlme_start_request_BatteryLifeExtension;
  294. bool mlme_start_request_SecurityEnable;
  295. bool mlme_start_request_PANCoordinator;
  296. UINT_16 mlme_start_request_PANId;
  297. UINT_8 mlme_start_request_LogicalChannel;
  298. //----------------
  299. bool mlme_sync_request;
  300. UINT_8 mlme_sync_request_STEP;
  301. char mlme_sync_request_frFunc[81];
  302. UINT_8 mlme_sync_request_numSearchRetry;
  303. bool mlme_sync_request_tracking;
  304. //----------------
  305. bool mlme_poll_request;
  306. UINT_8 mlme_poll_request_STEP;
  307. char mlme_poll_request_frFunc[81];
  308. UINT_8 mlme_poll_request_CoordAddrMode;
  309. UINT_16 mlme_poll_request_CoordPANId;
  310. IE3ADDR mlme_poll_request_CoordAddress;
  311. bool mlme_poll_request_SecurityEnable;
  312. bool mlme_poll_request_autoRequest;
  313. bool mlme_poll_request_pending;
  314. //----------------
  315. bool CCA_csmaca;
  316. UINT_8 CCA_csmaca_STEP;
  317. //----------------
  318. bool RX_ON_csmaca;
  319. UINT_8 RX_ON_csmaca_STEP;
  320. //----------------
  321. };
  322. //Elements of ACL entry descriptor (Table 73)
  323. struct MAC_ACL
  324. {
  325. IE3ADDR ACLExtendedAddress;
  326. UINT_16 ACLShortAddress;
  327. UINT_16 ACLPANId;
  328. UINT_8 ACLSecurityMaterialLength;
  329. UINT_8 *ACLSecurityMaterial;
  330. UINT_8 ACLSecuritySuite;
  331. };
  332. //MAC enumerations description (Table 64)
  333. typedef enum
  334. {
  335. m_SUCCESS = 0,
  336. //--- following from Table 68) ---
  337. m_PAN_at_capacity,
  338. m_PAN_access_denied,
  339. //--------------------------------
  340. m_BEACON_LOSS = 0xe0,
  341. m_CHANNEL_ACCESS_FAILURE,
  342. m_DENIED,
  343. m_DISABLE_TRX_FAILURE,
  344. m_FAILED_SECURITY_CHECK,
  345. m_FRAME_TOO_LONG,
  346. m_INVALID_GTS,
  347. m_INVALID_HANDLE,
  348. m_INVALID_PARAMETER,
  349. m_NO_ACK,
  350. m_NO_BEACON,
  351. m_NO_DATA,
  352. m_NO_SHORT_ADDRESS,
  353. m_OUT_OF_CAP,
  354. m_PAN_ID_CONFLICT,
  355. m_REALIGNMENT,
  356. m_TRANSACTION_EXPIRED,
  357. m_TRANSACTION_OVERFLOW,
  358. m_TX_ACTIVE,
  359. m_UNAVAILABLE_KEY,
  360. m_UNSUPPORTED_ATTRIBUTE,
  361. m_UNDEFINED //we added this for handling any case not specified in the draft
  362. }MACenum;
  363. //MAC PIB attributes (Tables 71,72)
  364. typedef enum {
  365. //attributes from Table 71
  366. macAckWaitDuration,
  367. macAssociationPermit,
  368. macAutoRequest,
  369. macBattLifeExt,
  370. macBattLifeExtPeriods,
  371. macBeaconPayload,
  372. macBeaconPayloadLength,
  373. macBeaconOrder,
  374. macBeaconTxTime,
  375. macBSN,
  376. macCoordExtendedAddress,
  377. macCoordShortAddress,
  378. macDSN,
  379. macGTSPermit,
  380. macMaxCSMABackoffs,
  381. macMinBE,
  382. macPANId,
  383. macPromiscuousMode,
  384. macRxOnWhenIdle,
  385. macShortAddress,
  386. macSuperframeOrder,
  387. macTransactionPersistenceTime,
  388. //attributes from Table 72 (security attributes)
  389. macACLEntryDescriptorSet,
  390. macACLEntryDescriptorSetSize,
  391. macDefaultSecurity,
  392. macACLDefaultSecurityMaterialLength,
  393. macDefaultSecurityMaterial,
  394. macDefaultSecuritySuite,
  395. macSecurityMode
  396. }MPIBAenum;
  397. struct MAC_PIB
  398. {
  399. //attributes from Table 71
  400. UINT_8 macAckWaitDuration;
  401. bool macAssociationPermit;
  402. bool macAutoRequest;
  403. bool macBattLifeExt;
  404. UINT_8 macBattLifeExtPeriods;
  405. /*
  406. UINT_8 macBeaconPayload[aMaxPHYPacketSize-(6+9+2+1)+1]; //beacon length in octets (w/o payload):
  407. // max: 6(phy) + 15(mac) + 23 (GTSs) + 57 (pending addresses)
  408. // min: 6(phy) + 9(mac) + 2 (GTSs) + 1 (pending addresses)
  409. */
  410. UINT_8 macBeaconPayload[aMaxBeaconPayloadLength+1];
  411. UINT_8 macBeaconPayloadLength;
  412. UINT_8 macBeaconOrder;
  413. UINT_32 macBeaconTxTime:24;
  414. UINT_8 macBSN;
  415. IE3ADDR macCoordExtendedAddress;
  416. UINT_16 macCoordShortAddress;
  417. UINT_8 macDSN;
  418. bool macGTSPermit;
  419. UINT_8 macMaxCSMABackoffs;
  420. UINT_8 macMinBE;
  421. UINT_16 macPANId;
  422. bool macPromiscuousMode;
  423. bool macRxOnWhenIdle;
  424. UINT_16 macShortAddress;
  425. UINT_8 macSuperframeOrder;
  426. UINT_16 macTransactionPersistenceTime;
  427. //attributes from Table 72 (security attributes)
  428. MAC_ACL *macACLEntryDescriptorSet;
  429. UINT_8 macACLEntryDescriptorSetSize;
  430. bool macDefaultSecurity;
  431. UINT_8 macACLDefaultSecurityMaterialLength;
  432. UINT_8 *macDefaultSecurityMaterial;
  433. UINT_8 macDefaultSecuritySuite;
  434. UINT_8 macSecurityMode;
  435. };
  436. #define macTxBcnCmdDataHType 1
  437. #define macIFSHType 2
  438. #define macBackoffBoundType 3
  439. class Mac802_15_4;
  440. class Mac802_15_4Handler : public Handler
  441. {
  442. friend class Mac802_15_4;
  443. public:
  444. Mac802_15_4Handler(Mac802_15_4 *m, int tp) : Handler()
  445. {
  446. mac = m;
  447. type = tp;
  448. nullEvent.uid_ = 0;
  449. }
  450. virtual void handle(Event* e);
  451. protected:
  452. Mac802_15_4 *mac;
  453. int type;
  454. Event nullEvent;
  455. };
  456. #define TxOp_Acked 0x01
  457. #define TxOp_GTS 0x02
  458. #define TxOp_Indirect 0x04
  459. #define TxOp_SecEnabled 0x08
  460. class Phy802_15_4;
  461. class CsmaCA802_15_4;
  462. class SSCS802_15_4;
  463. class Nam802_15_4;
  464. class Mac802_15_4 : public Mac
  465. {
  466. friend class Phy802_15_4;
  467. friend class Mac802_15_4Handler;
  468. friend class macTxOverTimer;
  469. friend class macTxTimer;
  470. friend class macExtractTimer;
  471. friend class macAssoRspWaitTimer;
  472. friend class macDataWaitTimer;
  473. friend class macRxEnableTimer;
  474. friend class macScanTimer;
  475. friend class macBeaconTxTimer;
  476. friend class macBeaconRxTimer;
  477. friend class macBeaconSearchTimer;
  478. friend class macWakeupTimer; // 2.31 change: 
  479. friend class CsmaCA802_15_4;
  480. friend class SSCS802_15_4;
  481. friend class Nam802_15_4;
  482. public:
  483. Mac802_15_4(MAC_PIB *mp);
  484. ~Mac802_15_4();
  485. void init(bool reset = false);
  486. //interfaces between MAC and PHY
  487. void PD_DATA_confirm(PHYenum status);
  488. void PLME_CCA_confirm(PHYenum status);
  489. void PLME_ED_confirm(PHYenum status,UINT_8 EnergyLevel);
  490. void PLME_GET_confirm(PHYenum status,PPIBAenum PIBAttribute,PHY_PIB *PIBAttributeValue);
  491. void PLME_SET_TRX_STATE_confirm(PHYenum status);
  492. void PLME_SET_confirm(PHYenum status,PPIBAenum PIBAttribute);
  493. //interfaces between MAC and SSCS (or some other upper layer)
  494. void MCPS_DATA_request(UINT_8 SrcAddrMode,UINT_16 SrcPANId,IE3ADDR SrcAddr,
  495.        UINT_8 DstAddrMode,UINT_16 DstPANId,IE3ADDR DstAddr,
  496.        UINT_8 msduLength,Packet *msdu,UINT_8 msduHandle,UINT_8 TxOptions);
  497. void MCPS_DATA_indication(UINT_8 SrcAddrMode,UINT_16 SrcPANId,IE3ADDR SrcAddr,
  498.   UINT_8 DstAddrMode,UINT_16 DstPANId,IE3ADDR DstAddr,
  499.   UINT_8 msduLength,Packet *msdu,UINT_8 mpduLinkQuality,
  500.   bool SecurityUse,UINT_8 ACLEntry);
  501. void MCPS_PURGE_request(UINT_8 msduHandle);
  502. void MLME_ASSOCIATE_request(UINT_8 LogicalChannel,UINT_8 CoordAddrMode,UINT_16 CoordPANId,IE3ADDR CoordAddress,
  503.     UINT_8 CapabilityInformation,bool SecurityEnable);
  504. void MLME_ASSOCIATE_response(IE3ADDR DeviceAddress,UINT_16 AssocShortAddress,MACenum status,bool SecurityEnable);
  505. void MLME_DISASSOCIATE_request(IE3ADDR DeviceAddress,UINT_8 DisassociateReason,bool SecurityEnable);
  506. void MLME_DISASSOCIATE_indication(IE3ADDR DeviceAddress,UINT_8 DisassociateReason,bool SecurityUse,UINT_8 ACLEntry);
  507. void MLME_GET_request(MPIBAenum PIBAttribute);
  508. /*TBD*/ void MLME_GTS_request(UINT_8 GTSCharacteristics,bool SecurityEnable);
  509. /*TBD*/ void MLME_GTS_confirm(UINT_8 GTSCharacteristics,MACenum status);
  510. /*TBD*/ void MLME_GTS_indication(UINT_16 DevAddress,UINT_8 GTSCharacteristics,
  511.  bool SecurityUse, UINT_8 ACLEntry);
  512. void MLME_ORPHAN_response(IE3ADDR OrphanAddress,UINT_16 ShortAddress,bool AssociatedMember,bool SecurityEnable);
  513. void MLME_RESET_request(bool SetDefaultPIB);
  514. void MLME_RX_ENABLE_request(bool DeferPermit,UINT_32 RxOnTime,UINT_32 RxOnDuration);
  515. void MLME_SCAN_request(UINT_8 ScanType,UINT_32 ScanChannels,UINT_8 ScanDuration);
  516. void MLME_SET_request(MPIBAenum PIBAttribute,MAC_PIB *PIBAttributeValue);
  517. void MLME_START_request(UINT_16 PANId,UINT_8 LogicalChannel,UINT_8 BeaconOrder,
  518. UINT_8 SuperframeOrder,bool PANCoordinator,bool BatteryLifeExtension,
  519. bool CoordRealignment,bool SecurityEnable);
  520. void MLME_SYNC_request(UINT_8 LogicalChannel, bool TrackBeacon);
  521. void MLME_POLL_request(UINT_8 CoordAddrMode,UINT_16 CoordPANId,IE3ADDR CoordAddress,bool SecurityEnable);
  522. inline int hdr_dst(char* hdr,int dst = -2);
  523. inline int hdr_src(char* hdr,int src = -2);
  524. inline int hdr_type(char* hdr, UINT_16 type = 0);
  525. inline Tap *tap(){return tap_;}
  526. void recv(Packet *p, Handler *h);
  527. void recvBeacon(Packet *p);
  528. void recvAck(Packet *p);
  529. void recvCommand(Packet *p);
  530. void recvData(Packet *p);
  531. bool toParent(Packet *p);
  532. protected:
  533. void set_trx_state_request(PHYenum state,const char *frFile,const char *frFunc,int line);
  534. double locateBoundary(bool parent,double wtime);
  535. void txOverHandler(void); //transmission over timer handler
  536. void txHandler(void); //ack expiration timer handler
  537. void extractHandler(void); //data extraction timer handler
  538. void assoRspWaitHandler(void); //association response wait timer handler
  539. void dataWaitHandler(void); //data wait timer handler (for indirect transmission)
  540. void rxEnableHandler(void); //receiver enable timer handler
  541. void scanHandler(void); //scan done for current channel
  542. void beaconTxHandler(bool forTX); //periodic beacon transmission
  543. void beaconRxHandler(void); //periodic beacon reception
  544. void beaconSearchHandler(void); //beacon searching times out during synchronization
  545. void isPanCoor(bool isPC);
  546. private:
  547. void checkTaskOverflow(UINT_8 task);
  548. void dispatch(PHYenum status,const char *frFunc,PHYenum req_state = p_SUCCESS,MACenum mStatus = m_SUCCESS);
  549. void sendDown(Packet *p,Handler* h);
  550. void mcps_data_request(UINT_8 SrcAddrMode,UINT_16 SrcPANId,IE3ADDR SrcAddr,
  551.        UINT_8 DstAddrMode,UINT_16 DstPANId,IE3ADDR DstAddr,
  552.        UINT_8 msduLength,Packet *msdu,UINT_8 msduHandle,UINT_8 TxOptions,
  553.        bool frUpper = false,PHYenum status = p_SUCCESS,MACenum mStatus = m_SUCCESS);
  554. void mlme_associate_request(UINT_8 LogicalChannel,UINT_8 CoordAddrMode,UINT_16 CoordPANId,IE3ADDR CoordAddress,
  555.     UINT_8 CapabilityInformation,bool SecurityEnable,
  556.     bool frUpper = false,PHYenum status = p_SUCCESS,MACenum mStatus = m_SUCCESS);
  557. void mlme_associate_response(IE3ADDR DeviceAddress,UINT_16 AssocShortAddress,MACenum Status,bool SecurityEnable,
  558.      bool frUpper = false,PHYenum status = p_SUCCESS);
  559. void mlme_disassociate_request(IE3ADDR DeviceAddress,UINT_8 DisassociateReason,bool SecurityEnable,bool frUpper = false,PHYenum status = p_SUCCESS);
  560. void mlme_orphan_response(IE3ADDR OrphanAddress,UINT_16 ShortAddress,bool AssociatedMember,bool SecurityEnable,bool frUpper = false,PHYenum status = p_SUCCESS);
  561. void mlme_reset_request(bool SetDefaultPIB,bool frUpper = false,PHYenum status = p_SUCCESS);
  562. void mlme_rx_enable_request(bool DeferPermit,UINT_32 RxOnTime,UINT_32 RxOnDuration,bool frUpper = false,PHYenum status = p_SUCCESS);
  563. void mlme_scan_request(UINT_8 ScanType,UINT_32 ScanChannels,UINT_8 ScanDuration,bool frUpper = false,PHYenum status = p_SUCCESS);
  564. void mlme_start_request(UINT_16 PANId,UINT_8 LogicalChannel,UINT_8 BeaconOrder,
  565. UINT_8 SuperframeOrder,bool PANCoordinator,bool BatteryLifeExtension,
  566. bool CoordRealignment,bool SecurityEnable,
  567. bool frUpper = false,PHYenum status = p_SUCCESS);
  568. void mlme_sync_request(UINT_8 LogicalChannel, bool TrackBeacon,bool frUpper = false,PHYenum status = p_SUCCESS);
  569. void mlme_poll_request(UINT_8 CoordAddrMode,UINT_16 CoordPANId,IE3ADDR CoordAddress,bool SecurityEnable,
  570.        bool autoRequest = false,bool firstTime = false,PHYenum status = p_SUCCESS);
  571. void csmacaBegin(char pktType);
  572. void csmacaResume(void);
  573. void csmacaCallBack(PHYenum status);
  574. int getBattLifeExtSlotNum(void);
  575. double getCAP(bool small);
  576. double getCAPbyType(int type);
  577. bool canProceedWOcsmaca(Packet *p); //can we proceed w/o CSMA-CA?
  578. void transmitCmdData(void);
  579. void reset_TRX(const char *frFile,const char *frFunc,int line);
  580. void taskSuccess(char task,bool csmacaRes = true);
  581. void taskFailed(char task,MACenum status,bool csmacaRes = true);
  582. void freePkt(Packet *pkt);
  583. UINT_8 macHeaderLen(UINT_16 FrmCtrl);
  584. void constructACK(Packet *p);
  585. void constructMPDU(UINT_8 msduLength,Packet *msdu, UINT_16 FrmCtrl,UINT_8 BDSN,panAddrInfo DstAddrInfo,
  586.     panAddrInfo SrcAddrInfo,UINT_16 SuperSpec,UINT_8 CmdType,UINT_16 FCS);
  587. void constructCommandHeader(Packet *p,FrameCtrl *frmCtrl,UINT_8 CmdType,
  588.    UINT_8 dstAddrMode,UINT_16 dstPANId,IE3ADDR dstAddr,
  589.    UINT_8 srcAddrMode,UINT_16 srcPANId,IE3ADDR srcAddr,
  590.    bool secuEnable,bool pending,bool ackreq);
  591. void log(Packet *p);
  592. void resetCounter(int dst);
  593. int command(int argc, const char*const* argv);
  594. void changeNodeColor(double atTime,const char *newColor,bool save = true);
  595. void txBcnCmdDataHandler(void);
  596. void IFSHandler(void);
  597. void backoffBoundHandler(void);
  598. public:
  599. static bool verbose;
  600. static UINT_8 txOption; //0x02=GTS; 0x04=Indirect; 0x00=Direct (only for 802.15.4-unaware upper layer app. packet)
  601. static bool ack4data;
  602. static UINT_8 callBack; //0=no call back; 1=call back for failures; 2=call back for failures and successes
  603. static UINT_32 DBG_UID;
  604. protected:
  605. taskPending taskP;
  606. MAC_PIB mpib;
  607. PHY_PIB tmp_ppib;
  608. DevCapability capability; //device capability (refer to Figure 49)
  609. //--- for beacon ---
  610. //(most are temp. variables which should be populated before being used)
  611. bool secuBeacon;
  612. SuperframeSpec sfSpec,sfSpec2,sfSpec3; //superframe specification
  613. GTSSpec gtsSpec,gtsSpec2; //GTS specification
  614. PendAddrSpec pendAddrSpec; //pending address specification
  615. UINT_8 beaconPeriods,beaconPeriods2; //# of backoff periods it takes to transmit the beacon
  616. PAN_ELE panDes,panDes2; //PAN descriptor
  617. Packet *rxBeacon; //the beacon packet just received
  618. double macBcnTxTime; //the time last beacon sent (in symbol) (we use this double variable instead of integer mpib.macBeaconTxTime for accuracy reason)
  619. double macBcnRxTime; //the time last beacon received from within PAN (in symbol)
  620. double macBcnOtherRxTime; //the time last beacon received from outside PAN (in symbol)
  621. //To support beacon enabled mode in multi-hop envirionment, we use {<mpib.macBeaconOrder>,<mpib.macSuperframeOrder>}
  622. //for coordinators (transmitting beacons) and the following two parameters for devices (receiving beacons). Note that,
  623. //in such an environment, a node can act as a coordinator and a device at the same time. More complicated algorithm 
  624. //is required for slotted CSMA-CA in this case.
  625. //(does 802.15.4 have this in mind?) 
  626. UINT_8 macBeaconOrder2;
  627. UINT_8 macSuperframeOrder2;
  628. UINT_8 macBeaconOrder3;
  629. UINT_8 macSuperframeOrder3;
  630. bool oneMoreBeacon;
  631. UINT_8 numLostBeacons; //# of beacons lost in a row
  632. //------------------
  633. UINT_16 rt_myNodeID;
  634. UINT_8 energyLevel;
  635. //for association and transaction
  636. DEVICELINK *deviceLink1;
  637. DEVICELINK *deviceLink2;
  638. TRANSACLINK *transacLink1;
  639. TRANSACLINK *transacLink2;
  640. private:
  641. IE3ADDR aExtendedAddress;
  642. //timers
  643. macTxOverTimer *txOverT;
  644. macTxTimer *txT;
  645. macExtractTimer *extractT;
  646. macAssoRspWaitTimer *assoRspWaitT;
  647. macDataWaitTimer *dataWaitT;
  648. macRxEnableTimer *rxEnableT;
  649. macScanTimer *scanT;
  650. macBeaconTxTimer *bcnTxT; //beacon transmission timer
  651. macBeaconRxTimer *bcnRxT; //beacon reception timer
  652. macBeaconSearchTimer *bcnSearchT; //beacon search timer
  653. macWakeupTimer *wakeupT;  // 2.31 change:
  654. //handlers
  655. Mac802_15_4Handler txCmdDataH;
  656. Mac802_15_4Handler IFSH;
  657. Mac802_15_4Handler backoffBoundH;
  658. bool isPANCoor; //is a PAN coordinator?
  659. Phy802_15_4 *phy;
  660. CsmaCA802_15_4 *csmaca;
  661. SSCS802_15_4 *sscs;
  662. Nam802_15_4 *nam;
  663. PHYenum trx_state_req; //tranceiver state required: TRX_OFF/TX_ON/RX_ON
  664. bool inTransmission; //in the middle of transmission
  665. bool beaconWaiting; //it's about time to transmit beacon (suppress all other transmissions)
  666. Packet *txBeacon; //beacon packet to be transmitted (w/o using CSMA-CA)
  667. Packet *txAck; //ack. packet to be transmitted (no waiting)
  668. Packet *txBcnCmd; //beacon or command packet waiting for transmission (using CSMA-CA) -- triggered by receiving a packet
  669. Packet *txBcnCmd2; //beacon or command packet waiting for transmission (using CSMA-CA) -- triggered by upper layer
  670. Packet *txData; //data packet waiting for transmission (using CSMA-CA)
  671. Packet *txCsmaca; //for which packet (txBcnCmd/txBcnCmd2/txData) is CSMA-CA performed
  672. Packet *txPkt; //packet (any type) currently being transmitted
  673. Packet *rxData; //data packet received (waiting for passing up)
  674. Packet *rxCmd; //command packet received (will be handled after the transmission of ack.)
  675. UINT_32 txPkt_uid; //for debug purpose
  676. double rxDataTime; //the time when data packet received by MAC
  677. bool waitBcnCmdAck; //only used if (txBcnCmd): waiting for an ack. or not
  678. bool waitBcnCmdAck2; //only used if (txBcnCmd2): waiting for an ack. or not
  679. bool waitDataAck; //only used if (txData): waiting for an ack. or not
  680. UINT_8 backoffStatus; //0=no backoff yet;1=backoff successful;2=backoff failed;99=in the middle of backoff
  681. UINT_8 numDataRetry; //# of retries (retransmissions) for data packet
  682. UINT_8 numBcnCmdRetry; //# of retries (retransmissions) for beacon or command packet
  683. UINT_8 numBcnCmdRetry2; //# of retries (retransmissions) for beacon or command packet
  684. NsObject *logtarget_;
  685. //packet duplication detection
  686. HLISTLINK *hlistBLink1;
  687. HLISTLINK *hlistBLink2;
  688. HLISTLINK *hlistDLink1;
  689. HLISTLINK *hlistDLink2;
  690. };
  691. #define plme_set_trx_state_request(state) 
  692. set_trx_state_request(state,__FILE__,__FUNCTION__,__LINE__)
  693. #define resetTRX() 
  694. reset_TRX(__FILE__,__FUNCTION__,__LINE__)
  695. #endif
  696. // End of file: p802_15_4mac.h