Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-ieee802154.h
1 /* packet-ieee802154.h
2  *
3  * IEEE 802.15.4 Dissectors for Wireshark
4  * By Owen Kirby <osk@exegin.com>
5  * Copyright 2007 Exegin Technologies Limited
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 #ifndef PACKET_IEEE802154_H
26 #define PACKET_IEEE802154_H
27
28 /* Protocol Abbreviation */
29 #define IEEE802154_PROTOABBREV_WPAN         "wpan"
30 #define IEEE802154_PROTOABBREV_WPAN_BEACON  "wpan.beacon"
31 /* PANID dissector list is for Decode-As and stateful dissection only. */
32 #define IEEE802154_PROTOABBREV_WPAN_PANID   "wpan.panid"
33
34 /*  Packet Overhead from MAC header + footer (excluding addressing) */
35 #define IEEE802154_MAX_FRAME_LEN            127
36 #define IEEE802154_FCS_LEN                  2
37
38 /*  Command Frame Identifier Types Definions */
39 #define IEEE802154_CMD_ASRQ                 0x01
40 #define IEEE802154_CMD_ASRSP                0x02
41 #define IEEE802154_CMD_DISAS                0x03
42 #define IEEE802154_CMD_DATA_RQ              0x04
43 #define IEEE802154_CMD_PANID_ERR            0x05
44 #define IEEE802154_CMD_ORPH_NOTIF           0x06
45 #define IEEE802154_CMD_BCN_RQ               0x07
46 #define IEEE802154_CMD_COORD_REAL           0x08
47 #define IEEE802154_CMD_GTS_REQ              0x09
48 #define IEEE802145_CMD_MAX_ID               0x09
49
50 /*  Definitions for Association Response Command */
51 #define IEEE802154_CMD_ASRSP_AS_SUCCESS     0x00
52 #define IEEE802154_CMD_ASRSP_PAN_FULL       0x01
53 #define IEEE802154_CMD_ASRSP_PAN_DENIED     0x02
54
55 /*  Bit Masks for Capability Information Field
56     Included in Association Req. command    */
57 #define IEEE802154_CMD_CINFO_ALT_PAN_COORD  0x01
58 #define IEEE802154_CMD_CINFO_DEVICE_TYPE    0x02
59 #define IEEE802154_CMD_CINFO_POWER_SRC      0x04
60 #define IEEE802154_CMD_CINFO_IDLE_RX        0x08
61 #define IEEE802154_CMD_CINFO_SEC_CAPABLE    0x40
62 #define IEEE802154_CMD_CINFO_ALLOC_ADDR     0x80
63
64 #define IEEE802154_CMD_GTS_REQ_LEN          0x0F
65 #define IEEE802154_CMD_GTS_REQ_DIR          0x10
66 #define IEEE802154_CMD_GTS_REQ_TYPE         0x20
67
68 /*  Bit masks & shifts for various beacon fields */
69 #define IEEE802154_BEACON_ORDER_MASK        0x000F
70 #define IEEE802154_SUPERFRAME_ORDER_MASK    0x00F0
71 #define IEEE802154_SUPERFRAME_CAP_MASK      0x0F00
72 #define IEEE802154_BATT_EXTENSION_MASK      0x1000
73 #define IEEE802154_SUPERFRAME_COORD_MASK    0x4000
74 #define IEEE802154_ASSOC_PERMIT_MASK        0x8000
75 #define IEEE802154_SUPERFRAME_ORDER_SHIFT   4
76 #define IEEE802154_SUPERFRAME_CAP_SHIFT     8
77
78 #define IEEE802154_GTS_COUNT_MASK           0x07
79 #define IEEE802154_GTS_PERMIT_MASK          0x80
80 #define IEEE802154_GTS_DIRECTION_SLOT(i)    (0x01<<(i))
81 #define IEEE802154_GTS_MAX_SLOTS            7
82 #define IEEE802154_GTS_DIRECTION_SLOT1      0x01
83 #define IEEE802154_GTS_DIRECTION_SLOT2      0x02
84 #define IEEE802154_GTS_DIRECTION_SLOT3      0x04
85 #define IEEE802154_GTS_DIRECTION_SLOT4      0x08
86 #define IEEE802154_GTS_DIRECTION_SLOT5      0x10
87 #define IEEE802154_GTS_DIRECTION_SLOT6      0x20
88 #define IEEE802154_GTS_DIRECTION_SLOT7      0x40
89 #define IEEE802154_GTS_SLOT_MASK            0x0F
90 #define IEEE802154_GTS_LENGTH_MASK          0xF0
91 #define IEEE802154_GTS_LENGTH_SHIFT         4
92
93 #define IEEE802154_PENDADDR_SHORT_MASK      0x07
94 #define IEEE802154_PENDADDR_LONG_MASK       0x70
95 #define IEEE802154_PENDADDR_LONG_SHIFT      4
96
97 #define IEEE802154_SUPERFRAME_DURATION      (IEEE802154_BASE_SLOT_DURATION * IEEE802154_SUPERFRAME_SLOTS)
98 #define IEEE802154_BASE_SLOT_DURATION       60
99 #define IEEE802154_SUPERFRAME_SLOTS         16
100
101 /*  Bit-masks for the FCF */
102 #define IEEE802154_FCF_TYPE_MASK            0x0007  /* Frame Type Mask */
103 #define IEEE802154_FCF_SEC_EN               0x0008
104 #define IEEE802154_FCF_FRAME_PND            0x0010
105 #define IEEE802154_FCF_ACK_REQ              0x0020
106 #define IEEE802154_FCF_INTRA_PAN            0x0040  /* known as PAN ID Compression in IEEE 802.15.4-2006 */
107 #define IEEE802154_FCF_DADDR_MASK           0x0C00  /* destination addressing mask */
108 #define IEEE802154_FCF_VERSION              0x3000
109 #define IEEE802154_FCF_SADDR_MASK           0xC000  /* source addressing mask */
110
111 /* Frame Type Definitions */
112 #define IEEE802154_FCF_BEACON               0x0000  /* Beacon Frame */
113 #define IEEE802154_FCF_DATA                 0x0001  /* Data Frame */
114 #define IEEE802154_FCF_ACK                  0x0002  /* Acknowlegement Frame */
115 #define IEEE802154_FCF_CMD                  0x0003  /* Command Frame */
116
117 /* Frame version definitions. */
118 #define IEEE802154_VERSION_2003             0x0
119 #define IEEE802154_VERSION_2006             0x1
120
121 /* Address Mode Definitions */
122 #define IEEE802154_FCF_ADDR_NONE            0x0000
123 #define IEEE802154_FCF_ADDR_SHORT           0x0002
124 #define IEEE802154_FCF_ADDR_EXT             0x0003
125
126 /*  Bit-masks for CC24xx style FCS */
127 #define IEEE802154_CC24xx_CORRELATION       0x7F00
128 #define IEEE802154_CC24xx_CRC_OK            0x8000
129 #define IEEE802154_CC24xx_RSSI              0x00FF
130
131 /*  Special IEEE802.15.4 Addresses */
132 #define IEEE802154_NO_ADDR16                0xFFFE
133 #define IEEE802154_BCAST_ADDR               0xFFFF
134 #define IEEE802154_BCAST_PAN                0xFFFF
135
136 /*  Bit mask for PHY length field */
137 #define IEEE802154_PHY_LENGTH_MASK          0x7f
138
139 /* Auxiliary Security Header */
140 #define IEEE802154_AUX_SEC_LEVEL_MASK       0x07  /* Security Level */
141 #define IEEE802154_AUX_KEY_ID_MODE_MASK     0x18  /* Key Identifier Mode */
142 #define IEEE802154_AUX_KEY_ID_MODE_SHIFT    3
143 #define IEEE802154_AUX_KEY_RESERVED_MASK    0xE0  /* Reserved */
144
145 typedef enum {
146     SECURITY_LEVEL_NONE = 0x00,
147     SECURITY_LEVEL_MIC_32 = 0x01,
148     SECURITY_LEVEL_MIC_64 = 0x02,
149     SECURITY_LEVEL_MIC_128 = 0x03,
150     SECURITY_LEVEL_ENC = 0x04,
151     SECURITY_LEVEL_ENC_MIC_32 = 0x05,
152     SECURITY_LEVEL_ENC_MIC_64 = 0x06,
153     SECURITY_LEVEL_ENC_MIC_128 = 0x07
154 } ieee802154_security_level;
155
156 typedef enum {
157     KEY_ID_MODE_IMPLICIT = 0x00,
158     KEY_ID_MODE_KEY_INDEX = 0x01,
159     KEY_ID_MODE_KEY_EXPLICIT_4 = 0x02,
160     KEY_ID_MODE_KEY_EXPLICIT_8 = 0x03
161 } ieee802154_key_id_mode;
162
163 /* IEEE 802.15.4 cipher block size. */
164 #define IEEE802154_CIPHER_SIZE              16
165
166 /* Macro to compute the MIC length. */
167 #define IEEE802154_MIC_LENGTH(_level_) ((0x2 << ((_level_) & 0x3)) & ~0x3)
168 /* Macro to check for payload encryption. */
169 #define IEEE802154_IS_ENCRYPTED(_level_) ((_level_) & 0x4)
170
171 /*  Structure containing information regarding all necessary packet fields. */
172 typedef struct {
173     /* Frame control field. */
174     gint32      version;
175     gint32      frame_type;
176     gint32      dst_addr_mode;
177     gint32      src_addr_mode;
178     gboolean    security_enable;
179     gboolean    frame_pending;
180     gboolean    ack_request;
181     gboolean    intra_pan;
182
183     guint8      seqno;
184
185     /* Addressing Info. */
186     guint16     dst_pan;
187     guint16     src_pan;
188     guint16     dst16;
189     guint64     dst64;
190     guint16     src16;
191     guint64     src64;
192
193     /* Security Info. */
194     ieee802154_security_level   security_level;
195     ieee802154_key_id_mode      key_id_mode;
196     guint32     frame_counter;
197     guint8      key_sequence_counter;    /* Only for 802.15.4-2003 security suite with encryption */
198
199     union {
200         guint32 addr32;
201         guint64 addr64;
202     } key_source;
203     guint8      key_index;
204
205     /* Command ID (only if frame_type == 0x3) */
206     guint8      command_id;
207     GHashTable *short_table;
208 } ieee802154_packet;
209
210 /* Structure for two-way mapping table */
211 typedef struct {
212     GHashTable *long_table;
213     GHashTable *short_table;
214 } ieee802154_map_tab_t;
215
216 /* Key used by the short address hash table. */
217 typedef struct {
218     guint16     pan;
219     guint16     addr;
220 } ieee802154_short_addr;
221
222 /* Key used by the long address hash table. */
223 typedef struct {
224     guint64     addr;
225 } ieee802154_long_addr;
226
227 /* A mapping record for a frame, pointed to by hash table */
228 typedef struct {
229     const char *proto; /* name of protocol that created this record */
230     guint       start_fnum;
231     guint       end_fnum;
232     guint64     addr64;
233     /*guint32   frame_counter;   TODO for frame counter sequence checks. */
234 } ieee802154_map_rec;
235
236 #define IEEE802154_USER_MAPPING 0
237
238 typedef struct {
239     guint16             src_pan;
240     guint16             src16;
241     guint16             dst16;
242     ieee802154_map_rec *map_rec;
243 } ieee802154_hints_t;
244
245 /* Short to Extended Address Prototypes */
246 extern ieee802154_map_rec *ieee802154_addr_update(ieee802154_map_tab_t *, guint16, guint16, guint64,
247         const char *, guint);
248 extern guint    ieee802154_short_addr_hash(gconstpointer);
249 extern guint    ieee802154_long_addr_hash(gconstpointer key);
250 extern gboolean ieee802154_short_addr_equal(gconstpointer, gconstpointer);
251 extern gboolean ieee802154_long_addr_equal(gconstpointer a, gconstpointer b);
252
253 extern gboolean ieee802154_short_addr_invalidate(guint16, guint16, guint);
254 extern gboolean ieee802154_long_addr_invalidate(guint64, guint);
255
256 #endif /* PACKET_IEEE802154_H */