| 1 | /********************************************/ |
| 2 | /* NS2 Simulator for IEEE 802.15.4 */ |
| 3 | /* (per P802.15.4/D18) */ |
| 4 | /*------------------------------------------*/ |
| 5 | /* by: Jianliang Zheng */ |
| 6 | /* ([email protected]) */ |
| 7 | /* Myung J. Lee */ |
| 8 | /* ([email protected]) */ |
| 9 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
| 10 | /* SAIT-CUNY Joint Lab */ |
| 11 | /********************************************/ |
| 12 | |
| 13 | // File: p802_15_4pkt.h |
| 14 | // Mode: C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t |
| 15 | |
| 16 | // $Header: /cvsroot/nsnam/ns-2/wpan/p802_15_4pkt.h,v 1.2 2011/06/22 04:03:26 tom_henderson Exp $ |
| 17 | |
| 18 | /* |
| 19 | * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and |
| 20 | * The City University of New York. All rights reserved. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the above copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
| 30 | * 3. Neither the name of Samsung Advanced Institute of Technology nor of |
| 31 | * The City University of New York may be used to endorse or promote |
| 32 | * products derived from this software without specific prior written |
| 33 | * permission. |
| 34 | * |
| 35 | * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE |
| 36 | * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS |
| 37 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 38 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 39 | * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK |
| 40 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 41 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 42 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 44 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 46 | */ |
| 47 | |
| 48 | |
| 49 | #ifndef p802_15_4pkt_h |
| 50 | #define p802_15_4pkt_h |
| 51 | |
| 52 | #include <packet.h> |
| 53 | #include "p802_15_4const.h" |
| 54 | #include "p802_15_4field.h" |
| 55 | |
| 56 | #define HDR_LRWPAN(p) (hdr_lrwpan::access(p)) |
| 57 | |
| 58 | struct panAddrInfo |
| 59 | { |
| 60 | UINT_16 panID; |
| 61 | union |
| 62 | { |
| 63 | UINT_16 addr_16; |
| 64 | IE3ADDR addr_64; |
| 65 | }; |
| 66 | }; |
| 67 | |
| 68 | //---PHY header--- |
| 69 | #define defSHR_PreSeq 0x00000000 |
| 70 | #define defSHR_SFD 0xe5 |
| 71 | #define defPHY_HEADER_LEN 6 |
| 72 | |
| 73 | struct lrwpan_beacon_frame |
| 74 | { |
| 75 | //---beacon frame (Figures 10,37)--- |
| 76 | UINT_32 SHR_PreSeq; //(PPDU) Preamble Sequence (const 0x00000000)(sec. 6.3.1.1) |
| 77 | UINT_8 SHR_SFD; //(PPDU) Start of Frame Delimiter (const 0xe5)(sec 6.3.1.2) |
| 78 | UINT_8 PHR_FrmLen; //(PPDU) Frame Length (sec. 6.3.1.3) |
| 79 | UINT_16 MHR_FrmCtrl; //(PSDU/MPDU) Frame Control (Figure 35) |
| 80 | // --leftmost bit numbered 0 and transmitted first |
| 81 | // --(012): Frame type (Table 65) |
| 82 | // --(210)=000: Beacon |
| 83 | // --(210)=001: Data |
| 84 | // --(210)=010: Ack. |
| 85 | // --(210)=011: MAC command |
| 86 | // --(210)=others: Reserved |
| 87 | // --(3): Security enabled |
| 88 | // --(4): Frame pending |
| 89 | // --(5): Ack. req. |
| 90 | // --(6): Intra PAN |
| 91 | // --(789): Reserved |
| 92 | // --(ab): Dest. addressing mode (Table 66) |
| 93 | // --(ba)=00: PAN ID and Addr. field not present |
| 94 | // --(ba)=01: Reserved |
| 95 | // --(ba)=10: 16-bit short address |
| 96 | // --(ba)=11: 64-bit extended address |
| 97 | // --(cd): Reserved |
| 98 | // --(ef): Source addressing mode (see Dest. addressing mode) |
| 99 | UINT_8 MHR_BSN; //(PSDU/MPDU) Beacon Sequence Number |
| 100 | panAddrInfo MHR_SrcAddrInfo; //(PSDU/MPDU) Source Address Information |
| 101 | UINT_16 MSDU_SuperSpec; //(MSDU) Superframe Specification (Figures 40,59) |
| 102 | // --(0123): Beacon order |
| 103 | // --(4567): Superframe order |
| 104 | // --(89ab): Final CAP slot |
| 105 | // --(c): Battery life extension |
| 106 | // --(d): Reserved |
| 107 | // --(e): PAN Coordinator |
| 108 | // --(f): Association permit |
| 109 | GTSFields MSDU_GTSFields; //GTS Fields (Figure 38) |
| 110 | PendAddrFields MSDU_PendAddrFields; //(MSDU) Address Fields (Figure 39) |
| 111 | // --(012): # of short addressing pending |
| 112 | // --(3): Reserved |
| 113 | // --(456): # of extended addressing pending |
| 114 | // --(7): Reserved |
| 115 | //MSDU_BeaconPL; //(MSDU) Beacon Payload |
| 116 | UINT_16 MFR_FCS; //(PSDU/MPDU) FCS |
| 117 | }; |
| 118 | |
| 119 | struct lrwpan_data_frame |
| 120 | { |
| 121 | //---data frame (Figures 11,45)--- |
| 122 | UINT_32 SHR_PreSeq; //same as above |
| 123 | UINT_8 SHR_SFD; //same as above |
| 124 | UINT_8 PHR_FrmLen; //same as above |
| 125 | UINT_16 MHR_FrmCtrl; //same as above |
| 126 | UINT_8 MHR_DSN; //Date Sequence Number |
| 127 | panAddrInfo MHR_DstAddrInfo; //(PSDU/MPDU) Source Address Information |
| 128 | panAddrInfo MHR_SrcAddrInfo; //(PSDU/MPDU) Destination Address Information |
| 129 | //MSDU_DataPL; //(MSDU) Data Payload |
| 130 | UINT_16 MFR_FCS; //same as above |
| 131 | }; |
| 132 | |
| 133 | struct lrwpan_ack_frame |
| 134 | { |
| 135 | //---acknowledgement frame (Figures 12,46)--- |
| 136 | UINT_32 SHR_PreSeq; //same as above |
| 137 | UINT_8 SHR_SFD; //same as above |
| 138 | UINT_8 PHR_FrmLen; //same as above |
| 139 | UINT_16 MHR_FrmCtrl; //same as above |
| 140 | UINT_8 MHR_DSN; //same as above |
| 141 | UINT_16 MFR_FCS; //same as above |
| 142 | }; |
| 143 | |
| 144 | struct lrwpan_command_frame |
| 145 | { |
| 146 | //---MAC command frame (Figures 13,47)--- |
| 147 | UINT_32 SHR_PreSeq; //same as above |
| 148 | UINT_8 SHR_SFD; //same as above |
| 149 | UINT_8 PHR_FrmLen; //same as above |
| 150 | UINT_16 MHR_FrmCtrl; //same as above |
| 151 | UINT_8 MHR_DSN; //same as above |
| 152 | panAddrInfo MHR_DstAddrInfo; //same as above |
| 153 | panAddrInfo MHR_SrcAddrInfo; //same as above |
| 154 | UINT_8 MSDU_CmdType; //(MSDU) Command Type/Command frame identifier (Table 67) |
| 155 | // --0x01: Association request (Figures 48 -> 49) |
| 156 | // --0x02: Association response (Figure 50;Table 68) |
| 157 | // --0x03: Disassociation notification (Figure 51;Table 69) |
| 158 | // --0x04: Data request (Figure 52) |
| 159 | // --0x05: PAN ID conflict notification (Figure 53) |
| 160 | // --0x06: Orphan notification (Figure 54) |
| 161 | // --0x07: Beacon request (Figure 55) |
| 162 | // --0x08: Coordinator realignment (Figure 56 |
| 163 | // --0x09: GTS request (Figures 57 -> 58) |
| 164 | // --0x0a-0xff: Reserved |
| 165 | //MSDU_CmdPL; //(MSDU) Command Payload |
| 166 | UINT_16 MFR_FCS; //same as above |
| 167 | }; |
| 168 | |
| 169 | struct hdr_lrwpan |
| 170 | { |
| 171 | //---PHY header--- |
| 172 | UINT_32 SHR_PreSeq; |
| 173 | UINT_8 SHR_SFD; |
| 174 | UINT_8 PHR_FrmLen; |
| 175 | |
| 176 | //---MAC header--- |
| 177 | UINT_16 MHR_FrmCtrl; |
| 178 | UINT_8 MHR_BDSN; |
| 179 | panAddrInfo MHR_DstAddrInfo; |
| 180 | panAddrInfo MHR_SrcAddrInfo; |
| 181 | |
| 182 | //---PHY layer--- |
| 183 | UINT_8 ppduLinkQuality; |
| 184 | double rxTotPower; |
| 185 | |
| 186 | //---MAC sublayer--- |
| 187 | UINT_16 MFR_FCS; |
| 188 | UINT_16 MSDU_SuperSpec; |
| 189 | GTSFields MSDU_GTSFields; |
| 190 | PendAddrFields MSDU_PendAddrFields; |
| 191 | UINT_8 MSDU_CmdType; |
| 192 | UINT_8 MSDU_PayloadLen; |
| 193 | UINT_16 pad; |
| 194 | UINT_8 MSDU_Payload[aMaxMACFrameSize]; //MSDU_BeaconPL/MSDU_DataPL/MSDU_CmdPL |
| 195 | bool SecurityUse; |
| 196 | UINT_8 ACLEntry; |
| 197 | |
| 198 | //---SSCS entity--- |
| 199 | UINT_8 msduHandle; |
| 200 | |
| 201 | //---Other--- |
| 202 | bool setSN; //SN already been set |
| 203 | UINT_8 phyCurrentChannel; |
| 204 | bool indirect; //this is a pending packet (indirect transmission) |
| 205 | UINT_32 uid; //for debug purpose |
| 206 | UINT_16 clusTreeDepth; |
| 207 | UINT_16 clusTreeParentNodeID; |
| 208 | |
| 209 | bool colFlag; //for nam purpose |
| 210 | int attribute; //for nam purpose |
| 211 | |
| 212 | |
| 213 | //---Packet header access functions--- |
| 214 | static int offset_; |
| 215 | inline static int& offset() {return offset_;} |
| 216 | inline static hdr_lrwpan* access(const Packet* p) |
| 217 | { |
| 218 | return (hdr_lrwpan*) p->access(offset_); |
| 219 | } |
| 220 | }; |
| 221 | |
| 222 | #endif |
| 223 | |
| 224 | // End of file: p802_15_4pkt.h |