3 * Siemens AG, All rights reserved.
4 * Dmitry Eremin-Solenikov (dbaryshkov@gmail.com)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 /* \summary: IEEE 802.15.4 printer */
29 #include "netdissect-stdinc.h"
31 #include "netdissect.h"
32 #include "addrtoname.h"
36 #define CHECK_BIT(num,bit) (((num) >> (bit)) & 0x1)
38 #define BROKEN_6TISCH_PAN_ID_COMPRESSION 0
40 /* Frame types from Table 7-1 of 802.15.4-2015 */
41 static const char *ftypes
[] = {
47 "Multipurpose", /* 5 */
52 /* Element IDs for Header IEs from Table 7-7 of 802.15.4-2015 */
53 static const char *h_ie_names
[] = {
54 "Vendor Specific Header IE", /* 0x00 */
55 "Reserved 0x01", /* 0x01 */
56 "Reserved 0x02", /* 0x02 */
57 "Reserved 0x03", /* 0x03 */
58 "Reserved 0x04", /* 0x04 */
59 "Reserved 0x05", /* 0x05 */
60 "Reserved 0x06", /* 0x06 */
61 "Reserved 0x07", /* 0x07 */
62 "Reserved 0x08", /* 0x08 */
63 "Reserved 0x09", /* 0x09 */
64 "Reserved 0x0a", /* 0x0a */
65 "Reserved 0x0b", /* 0x0b */
66 "Reserved 0x0c", /* 0x0c */
67 "Reserved 0x0d", /* 0x0d */
68 "Reserved 0x0e", /* 0x0e */
69 "Reserved 0x0f", /* 0x0f */
70 "Reserved 0x10", /* 0x10 */
71 "Reserved 0x11", /* 0x11 */
72 "Reserved 0x12", /* 0x12 */
73 "Reserved 0x13", /* 0x13 */
74 "Reserved 0x14", /* 0x14 */
75 "Reserved 0x15", /* 0x15 */
76 "Reserved 0x16", /* 0x16 */
77 "Reserved 0x17", /* 0x17 */
78 "Reserved 0x18", /* 0x18 */
79 "Reserved 0x19", /* 0x19 */
80 "LE CSL IE", /* 0x1a */
81 "LE RIT IE", /* 0x1b */
82 "DSME PAN descriptor IE", /* 0x1c */
83 "Rendezvous Time IE", /* 0x1d */
84 "Time Correction IE", /* 0x1e */
85 "Reserved 0x1f", /* 0x1f */
86 "Reserved 0x20", /* 0x20 */
87 "Extended DSME PAN descriptor IE", /* 0x21 */
88 "Fragment Sequence Context Description IE", /* 0x22 */
89 "Simplified Superframe Specification IE", /* 0x23 */
90 "Simplified GTS Specification IE", /* 0x24 */
91 "LECIM Capabilities IE", /* 0x25 */
92 "TRLE Descriptor IE", /* 0x26 */
93 "RCC Capabilities IE", /* 0x27 */
94 "RCCN Descriptor IE", /* 0x28 */
95 "Global Time IE", /* 0x29 */
96 "Omnibus Header IE", /* 0x2a */
98 "Reserved 0x2c", /* 0x2c */
99 "Reserved 0x2d", /* 0x2d */
100 "Reserved 0x2e", /* 0x2e */
101 "Reserved 0x2f", /* 0x2f */
102 "Reserved 0x30", /* 0x30 */
103 "Reserved 0x31", /* 0x31 */
104 "Reserved 0x32", /* 0x32 */
105 "Reserved 0x33", /* 0x33 */
106 "Reserved 0x34", /* 0x34 */
107 "Reserved 0x35", /* 0x35 */
108 "Reserved 0x36", /* 0x36 */
109 "Reserved 0x37", /* 0x37 */
110 "Reserved 0x38", /* 0x38 */
111 "Reserved 0x39", /* 0x39 */
112 "Reserved 0x3a", /* 0x3a */
113 "Reserved 0x3b", /* 0x3b */
114 "Reserved 0x3c", /* 0x3c */
115 "Reserved 0x3d", /* 0x3d */
116 "Reserved 0x3e", /* 0x3e */
117 "Reserved 0x3f", /* 0x3f */
118 "Reserved 0x40", /* 0x40 */
119 "Reserved 0x41", /* 0x41 */
120 "Reserved 0x42", /* 0x42 */
121 "Reserved 0x43", /* 0x43 */
122 "Reserved 0x44", /* 0x44 */
123 "Reserved 0x45", /* 0x45 */
124 "Reserved 0x46", /* 0x46 */
125 "Reserved 0x47", /* 0x47 */
126 "Reserved 0x48", /* 0x48 */
127 "Reserved 0x49", /* 0x49 */
128 "Reserved 0x4a", /* 0x4a */
129 "Reserved 0x4b", /* 0x4b */
130 "Reserved 0x4c", /* 0x4c */
131 "Reserved 0x4d", /* 0x4d */
132 "Reserved 0x4e", /* 0x4e */
133 "Reserved 0x4f", /* 0x4f */
134 "Reserved 0x50", /* 0x50 */
135 "Reserved 0x51", /* 0x51 */
136 "Reserved 0x52", /* 0x52 */
137 "Reserved 0x53", /* 0x53 */
138 "Reserved 0x54", /* 0x54 */
139 "Reserved 0x55", /* 0x55 */
140 "Reserved 0x56", /* 0x56 */
141 "Reserved 0x57", /* 0x57 */
142 "Reserved 0x58", /* 0x58 */
143 "Reserved 0x59", /* 0x59 */
144 "Reserved 0x5a", /* 0x5a */
145 "Reserved 0x5b", /* 0x5b */
146 "Reserved 0x5c", /* 0x5c */
147 "Reserved 0x5d", /* 0x5d */
148 "Reserved 0x5e", /* 0x5e */
149 "Reserved 0x5f", /* 0x5f */
150 "Reserved 0x60", /* 0x60 */
151 "Reserved 0x61", /* 0x61 */
152 "Reserved 0x62", /* 0x62 */
153 "Reserved 0x63", /* 0x63 */
154 "Reserved 0x64", /* 0x64 */
155 "Reserved 0x65", /* 0x65 */
156 "Reserved 0x66", /* 0x66 */
157 "Reserved 0x67", /* 0x67 */
158 "Reserved 0x68", /* 0x68 */
159 "Reserved 0x69", /* 0x69 */
160 "Reserved 0x6a", /* 0x6a */
161 "Reserved 0x6b", /* 0x6b */
162 "Reserved 0x6c", /* 0x6c */
163 "Reserved 0x6d", /* 0x6d */
164 "Reserved 0x6e", /* 0x6e */
165 "Reserved 0x6f", /* 0x6f */
166 "Reserved 0x70", /* 0x70 */
167 "Reserved 0x71", /* 0x71 */
168 "Reserved 0x72", /* 0x72 */
169 "Reserved 0x73", /* 0x73 */
170 "Reserved 0x74", /* 0x74 */
171 "Reserved 0x75", /* 0x75 */
172 "Reserved 0x76", /* 0x76 */
173 "Reserved 0x77", /* 0x77 */
174 "Reserved 0x78", /* 0x78 */
175 "Reserved 0x79", /* 0x79 */
176 "Reserved 0x7a", /* 0x7a */
177 "Reserved 0x7b", /* 0x7b */
178 "Reserved 0x7c", /* 0x7c */
179 "Reserved 0x7d", /* 0x7d */
180 "Header Termination 1 IE", /* 0x7e */
181 "Header Termination 2 IE" /* 0x7f */
184 /* Payload IE Group IDs from Table 7-15 of 802.15.4-2015 */
185 static const char *p_ie_names
[] = {
186 "ESDU IE", /* 0x00 */
187 "MLME IE", /* 0x01 */
188 "Vendor Specific Nested IE", /* 0x02 */
189 "Multiplexed IE (802.15.9)", /* 0x03 */
190 "Omnibus Payload Group IE", /* 0x04 */
191 "IETF IE", /* 0x05 */
192 "Reserved 0x06", /* 0x06 */
193 "Reserved 0x07", /* 0x07 */
194 "Reserved 0x08", /* 0x08 */
195 "Reserved 0x09", /* 0x09 */
196 "Reserved 0x0a", /* 0x0a */
197 "Reserved 0x0b", /* 0x0b */
198 "Reserved 0x0c", /* 0x0c */
199 "Reserved 0x0d", /* 0x0d */
200 "Reserved 0x0e", /* 0x0e */
201 "List termination" /* 0x0f */
204 /* Sub-ID for short format from Table 7-16 of 802.15.4-2015 */
205 static const char *p_mlme_short_names
[] = {
206 "Reserved for long format 0x0", /* 0x00 */
207 "Reserved for long format 0x1", /* 0x01 */
208 "Reserved for long format 0x2", /* 0x02 */
209 "Reserved for long format 0x3", /* 0x03 */
210 "Reserved for long format 0x4", /* 0x04 */
211 "Reserved for long format 0x5", /* 0x05 */
212 "Reserved for long format 0x6", /* 0x06 */
213 "Reserved for long format 0x7", /* 0x07 */
214 "Reserved for long format 0x8", /* 0x08 */
215 "Reserved for long format 0x9", /* 0x09 */
216 "Reserved for long format 0xa", /* 0x0a */
217 "Reserved for long format 0xb", /* 0x0b */
218 "Reserved for long format 0xc", /* 0x0c */
219 "Reserved for long format 0xd", /* 0x0d */
220 "Reserved for long format 0xe", /* 0x0e */
221 "Reserved for long format 0xf", /* 0x0f */
222 "Reserved 0x10", /* 0x10 */
223 "Reserved 0x11", /* 0x11 */
224 "Reserved 0x12", /* 0x12 */
225 "Reserved 0x13", /* 0x13 */
226 "Reserved 0x14", /* 0x14 */
227 "Reserved 0x15", /* 0x15 */
228 "Reserved 0x16", /* 0x16 */
229 "Reserved 0x17", /* 0x17 */
230 "Reserved 0x18", /* 0x18 */
231 "Reserved 0x19", /* 0x19 */
232 "TSCH Synchronization IE", /* 0x1a */
233 "TSCH Slotframe and Link IE", /* 0x1b */
234 "TSCH Timeslot IE", /* 0x1c */
235 "Hopping timing IE", /* 0x1d */
236 "Enhanced Beacon Filter IE", /* 0x1e */
237 "MAC Metrics IE", /* 0x1f */
238 "All MAC Metrics IE", /* 0x20 */
239 "Coexistence Specification IE", /* 0x21 */
240 "SUN Device Capabilities IE", /* 0x22 */
241 "SUN FSK Generic PHY IE", /* 0x23 */
242 "Mode Switch Parameter IE", /* 0x24 */
243 "PHY Parameter Change IE", /* 0x25 */
244 "O-QPSK PHY Mode IE", /* 0x26 */
245 "PCA Allocation IE", /* 0x27 */
246 "LECIM DSSS Operating Mode IE", /* 0x28 */
247 "LECIM FSK Operating Mode IE", /* 0x29 */
248 "Reserved 0x2a", /* 0x2a */
249 "TVWS PHY Operating Mode Description IE", /* 0x2b */
250 "TVWS Device Capabilities IE", /* 0x2c */
251 "TVWS Device Category IE", /* 0x2d */
252 "TVWS Device Identiication IE", /* 0x2e */
253 "TVWS Device Location IE", /* 0x2f */
254 "TVWS Channel Information Query IE", /* 0x30 */
255 "TVWS Channel Information Source IE", /* 0x31 */
257 "Timestamp IE", /* 0x33 */
258 "Timestamp Difference IE", /* 0x34 */
259 "TMCTP Sepcification IE", /* 0x35 */
260 "RCC PHY Operating Mode IE", /* 0x36 */
261 "Reserved 0x37", /* 0x37 */
262 "Reserved 0x38", /* 0x38 */
263 "Reserved 0x39", /* 0x39 */
264 "Reserved 0x3a", /* 0x3a */
265 "Reserved 0x3b", /* 0x3b */
266 "Reserved 0x3c", /* 0x3c */
267 "Reserved 0x3d", /* 0x3d */
268 "Reserved 0x3e", /* 0x3e */
269 "Reserved 0x3f", /* 0x3f */
270 "Reserved 0x40", /* 0x40 */
271 "Reserved 0x41", /* 0x41 */
272 "Reserved 0x42", /* 0x42 */
273 "Reserved 0x43", /* 0x43 */
274 "Reserved 0x44", /* 0x44 */
275 "Reserved 0x45", /* 0x45 */
276 "Reserved 0x46", /* 0x46 */
277 "Reserved 0x47", /* 0x47 */
278 "Reserved 0x48", /* 0x48 */
279 "Reserved 0x49", /* 0x49 */
280 "Reserved 0x4a", /* 0x4a */
281 "Reserved 0x4b", /* 0x4b */
282 "Reserved 0x4c", /* 0x4c */
283 "Reserved 0x4d", /* 0x4d */
284 "Reserved 0x4e", /* 0x4e */
285 "Reserved 0x4f", /* 0x4f */
286 "Reserved 0x50", /* 0x50 */
287 "Reserved 0x51", /* 0x51 */
288 "Reserved 0x52", /* 0x52 */
289 "Reserved 0x53", /* 0x53 */
290 "Reserved 0x54", /* 0x54 */
291 "Reserved 0x55", /* 0x55 */
292 "Reserved 0x56", /* 0x56 */
293 "Reserved 0x57", /* 0x57 */
294 "Reserved 0x58", /* 0x58 */
295 "Reserved 0x59", /* 0x59 */
296 "Reserved 0x5a", /* 0x5a */
297 "Reserved 0x5b", /* 0x5b */
298 "Reserved 0x5c", /* 0x5c */
299 "Reserved 0x5d", /* 0x5d */
300 "Reserved 0x5e", /* 0x5e */
301 "Reserved 0x5f", /* 0x5f */
302 "Reserved 0x60", /* 0x60 */
303 "Reserved 0x61", /* 0x61 */
304 "Reserved 0x62", /* 0x62 */
305 "Reserved 0x63", /* 0x63 */
306 "Reserved 0x64", /* 0x64 */
307 "Reserved 0x65", /* 0x65 */
308 "Reserved 0x66", /* 0x66 */
309 "Reserved 0x67", /* 0x67 */
310 "Reserved 0x68", /* 0x68 */
311 "Reserved 0x69", /* 0x69 */
312 "Reserved 0x6a", /* 0x6a */
313 "Reserved 0x6b", /* 0x6b */
314 "Reserved 0x6c", /* 0x6c */
315 "Reserved 0x6d", /* 0x6d */
316 "Reserved 0x6e", /* 0x6e */
317 "Reserved 0x6f", /* 0x6f */
318 "Reserved 0x70", /* 0x70 */
319 "Reserved 0x71", /* 0x71 */
320 "Reserved 0x72", /* 0x72 */
321 "Reserved 0x73", /* 0x73 */
322 "Reserved 0x74", /* 0x74 */
323 "Reserved 0x75", /* 0x75 */
324 "Reserved 0x76", /* 0x76 */
325 "Reserved 0x77", /* 0x77 */
326 "Reserved 0x78", /* 0x78 */
327 "Reserved 0x79", /* 0x79 */
328 "Reserved 0x7a", /* 0x7a */
329 "Reserved 0x7b", /* 0x7b */
330 "Reserved 0x7c", /* 0x7c */
331 "Reserved 0x7d", /* 0x7d */
332 "Reserved 0x7e", /* 0x7e */
333 "Reserved 0x7f" /* 0x7f */
336 /* Sub-ID for long format from Table 7-17 of 802.15.4-2015 */
337 static const char *p_mlme_long_names
[] = {
338 "Reserved 0x00", /* 0x00 */
339 "Reserved 0x01", /* 0x01 */
340 "Reserved 0x02", /* 0x02 */
341 "Reserved 0x03", /* 0x03 */
342 "Reserved 0x04", /* 0x04 */
343 "Reserved 0x05", /* 0x05 */
344 "Reserved 0x06", /* 0x06 */
345 "Reserved 0x07", /* 0x07 */
346 "Vendor Specific MLME Nested IE", /* 0x08 */
347 "Channel Hopping IE", /* 0x09 */
348 "Reserved 0x0a", /* 0x0a */
349 "Reserved 0x0b", /* 0x0b */
350 "Reserved 0x0c", /* 0x0c */
351 "Reserved 0x0d", /* 0x0d */
352 "Reserved 0x0e", /* 0x0e */
353 "Reserved 0x0f" /* 0x0f */
356 /* MAC commands from Table 7-49 of 802.15.4-2015 */
357 static const char *mac_c_names
[] = {
358 "Reserved 0x00", /* 0x00 */
359 "Association Request command", /* 0x01 */
360 "Association Response command", /* 0x02 */
361 "Disassociation Notification command", /* 0x03 */
362 "Data Request command", /* 0x04 */
363 "PAN ID Conflict Notification command", /* 0x05 */
364 "Orphan Notification command", /* 0x06 */
365 "Beacon Request command", /* 0x07 */
366 "Coordinator realignment command", /* 0x08 */
367 "GTS request command", /* 0x09 */
368 "TRLE Management Request command", /* 0x0a */
369 "TRLE Management Response command", /* 0x0b */
370 "Reserved 0x0c", /* 0x0c */
371 "Reserved 0x0d", /* 0x0d */
372 "Reserved 0x0e", /* 0x0e */
373 "Reserved 0x0f", /* 0x0f */
374 "Reserved 0x10", /* 0x10 */
375 "Reserved 0x11", /* 0x11 */
376 "Reserved 0x12", /* 0x12 */
377 "DSME Association Request command", /* 0x13 */
378 "DSME Association Response command", /* 0x14 */
379 "DSME GTS Request command", /* 0x15 */
380 "DSME GTS Response command", /* 0x16 */
381 "DSME GTS Notify command", /* 0x17 */
382 "DSME Information Request command", /* 0x18 */
383 "DSME Information Response command", /* 0x19 */
384 "DSME Beacon Allocation Notification command", /* 0x1a */
385 "DSME Beacon Collision Notification command", /* 0x1b */
386 "DSME Link Report command", /* 0x1c */
387 "Reserved 0x1d", /* 0x1d */
388 "Reserved 0x1e", /* 0x1e */
389 "Reserved 0x1f", /* 0x1f */
390 "RIT Data Request command", /* 0x20 */
391 "DBS Request command", /* 0x21 */
392 "DBS Response command", /* 0x22 */
393 "RIT Data Response command", /* 0x23 */
394 "Vendor Specific command", /* 0x24 */
395 "Reserved 0x25", /* 0x25 */
396 "Reserved 0x26", /* 0x26 */
397 "Reserved 0x27", /* 0x27 */
398 "Reserved 0x28", /* 0x28 */
399 "Reserved 0x29", /* 0x29 */
400 "Reserved 0x2a", /* 0x2a */
401 "Reserved 0x2b", /* 0x2b */
402 "Reserved 0x2c", /* 0x2c */
403 "Reserved 0x2d", /* 0x2d */
404 "Reserved 0x2e", /* 0x2e */
405 "Reserved 0x2f" /* 0x2f */
409 * Frame Control subfields.
411 #define FC_FRAME_TYPE(fc) ((fc) & 0x7)
412 #define FC_FRAME_VERSION(fc) (((fc) >> 12) & 0x3)
414 #define FC_ADDRESSING_MODE_NONE 0x00
415 #define FC_ADDRESSING_MODE_RESERVED 0x01
416 #define FC_ADDRESSING_MODE_SHORT 0x02
417 #define FC_ADDRESSING_MODE_LONG 0x03
420 * IEEE 802.15.4 CRC 16 function. This is using CCITT polynomical of 0x1021,
421 * but the initial value is 0, and the bits are reversed for both in and out.
422 * See secton 7.2.10 of 802.15.4-2015 for more information.
425 ieee802_15_4_crc16(netdissect_options
*ndo
, const u_char
*p
,
431 crc
= 0x0000; /* Note, initial value is 0x0000 not 0xffff. */
433 while (data_len
!= 0){
436 /* Reverse bits on input */
437 y
= (((y
& 0xaa) >> 1) | ((y
& 0x55) << 1));
438 y
= (((y
& 0xcc) >> 2) | ((y
& 0x33) << 2));
439 y
= (((y
& 0xf0) >> 4) | ((y
& 0x0f) << 4));
443 crc
= ((uint16_t)(crc
<< 8)) ^
444 ((uint16_t)(x
<< 12)) ^
445 ((uint16_t)(x
<< 5)) ^
449 /* Reverse bits on output */
450 crc
= (((crc
& 0xaaaa) >> 1) | ((crc
& 0x5555) << 1));
451 crc
= (((crc
& 0xcccc) >> 2) | ((crc
& 0x3333) << 2));
452 crc
= (((crc
& 0xf0f0) >> 4) | ((crc
& 0x0f0f) << 4));
453 crc
= (((crc
& 0xff00) >> 8) | ((crc
& 0x00ff) << 8));
458 * Reverses the bits of the 32-bit word.
461 ieee802_15_4_reverse32(uint32_t x
)
463 x
= ((x
& 0x55555555) << 1) | ((x
>> 1) & 0x55555555);
464 x
= ((x
& 0x33333333) << 2) | ((x
>> 2) & 0x33333333);
465 x
= ((x
& 0x0F0F0F0F) << 4) | ((x
>> 4) & 0x0F0F0F0F);
466 x
= (x
<< 24) | ((x
& 0xFF00) << 8) |
467 ((x
>> 8) & 0xFF00) | (x
>> 24);
472 * IEEE 802.15.4 CRC 32 function. This is using ANSI X3.66-1979 polynomical of
473 * 0x04C11DB7, but the initial value is 0, and the bits are reversed for both
474 * in and out. See secton 7.2.10 of 802.15.4-2015 for more information.
477 ieee802_15_4_crc32(netdissect_options
*ndo
, const u_char
*p
,
483 crc
= 0x00000000; /* Note, initial value is 0x00000000 not 0xffffffff */
485 while (data_len
!= 0){
488 /* Reverse bits on input */
489 byte
= ieee802_15_4_reverse32(byte
);
491 for(b
= 0; b
<= 7; b
++) {
492 if ((int) (crc
^ byte
) < 0)
493 crc
= (crc
<< 1) ^ 0x04C11DB7;
500 /* Reverse bits on output */
501 crc
= ieee802_15_4_reverse32(crc
);
506 * Find out the address length based on the address type. See table 7-3 of
507 * 802.15.4-2015. Returns the address length.
510 ieee802_15_4_addr_len(uint16_t addr_type
)
513 case FC_ADDRESSING_MODE_NONE
: /* None. */
516 case FC_ADDRESSING_MODE_RESERVED
: /* Reserved, there used to be 8-bit
517 * address type in one amendment, but
518 * that and the feature using it was
519 * removed during 802.15.4-2015
520 * maintenance process. */
523 case FC_ADDRESSING_MODE_SHORT
: /* Short. */
526 case FC_ADDRESSING_MODE_LONG
: /* Extended. */
534 * Print out the ieee 802.15.4 address.
537 ieee802_15_4_print_addr(netdissect_options
*ndo
, const u_char
*p
,
540 switch (dst_addr_len
) {
545 ND_PRINT("%04x", GET_LE_U_2(p
));
548 ND_PRINT("%s", GET_LE64ADDR_STRING(p
));
555 * Beacon frame superframe specification structure. Used in the old Beacon
556 * frames, and in the DSME PAN Descriptor IE. See section 7.3.1.3 of the
560 ieee802_15_4_print_superframe_specification(netdissect_options
*ndo
,
563 if (ndo
->ndo_vflag
< 1) {
566 ND_PRINT("\n\tBeacon order = %d, Superframe order = %d, ",
567 (ss
& 0xf), ((ss
>> 4) & 0xf));
568 ND_PRINT("Final CAP Slot = %d",
570 if (CHECK_BIT(ss
, 12)) { ND_PRINT(", BLE enabled"); }
571 if (CHECK_BIT(ss
, 14)) { ND_PRINT(", PAN Coordinator"); }
572 if (CHECK_BIT(ss
, 15)) { ND_PRINT(", Assocation Permit"); }
576 * Beacon frame gts info structure. Used in the old Beacon frames, and
577 * in the DSME PAN Descriptor IE. See section 7.3.1.4 of 802.15.4-2015.
579 * Returns number of byts consumed from the packet or -1 in case of error.
582 ieee802_15_4_print_gts_info(netdissect_options
*ndo
,
586 uint8_t gts_spec
, gts_cnt
;
590 gts_spec
= GET_U_1(p
);
591 gts_cnt
= gts_spec
& 0x7;
594 if (ndo
->ndo_vflag
> 0) {
595 ND_PRINT("\n\tGTS Descriptor Count = %d, ", gts_cnt
);
599 len
= 1 + 1 + gts_cnt
* 3;
601 if (data_len
< len
) {
602 ND_PRINT(" [ERROR: Truncated GTS Info List]");
605 if (ndo
->ndo_vflag
< 2) {
608 ND_PRINT("GTS Descriptor Count = %d, ", gts_cnt
);
609 ND_PRINT("GTS Directions Mask = %02x, [ ",
610 GET_U_1(p
+ 1) & 0x7f);
612 for(i
= 0; i
< gts_cnt
; i
++) {
614 ieee802_15_4_print_addr(ndo
, p
+ 2 + i
* 3, 2);
615 ND_PRINT(", Start slot = %d, Length = %d ] ",
616 GET_U_1(p
+ 2 + i
* 3 + 1) & 0x0f,
617 (GET_U_1(p
+ 2 + i
* 3 + 1) >> 4) & 0x0f);
624 * Beacon frame pending address structure. Used in the old Beacon frames, and
625 * in the DSME PAN Descriptor IE. See section 7.3.1.5 of 802.15.4-2015.
627 * Returns number of byts consumed from the packet or -1 in case of error.
630 ieee802_15_4_print_pending_addresses(netdissect_options
*ndo
,
634 uint8_t pas
, s_cnt
, e_cnt
, len
, i
;
638 e_cnt
= (pas
>> 4) & 0x7;
639 len
= 1 + s_cnt
* 2 + e_cnt
* 8;
640 if (ndo
->ndo_vflag
> 0) {
641 ND_PRINT("\n\tPending address list, "
642 "# short addresses = %d, # extended addresses = %d",
645 if (data_len
< len
) {
646 ND_PRINT(" [ERROR: Pending address list truncated]");
649 if (ndo
->ndo_vflag
< 2) {
653 ND_PRINT(", Short address list = [ ");
654 for(i
= 0; i
< s_cnt
; i
++) {
655 ieee802_15_4_print_addr(ndo
, p
+ 1 + i
* 2, 2);
661 ND_PRINT(", Extended address list = [ ");
662 for(i
= 0; i
< e_cnt
; i
++) {
663 ieee802_15_4_print_addr(ndo
, p
+ 1 + s_cnt
* 2 +
673 * Print header ie content.
676 ieee802_15_4_print_header_ie(netdissect_options
*ndo
,
683 switch (element_id
) {
684 case 0x00: /* Vendor Specific Header IE */
686 ND_PRINT("[ERROR: Vendor OUI missing]");
688 ND_PRINT("OUI = 0x%02x%02x%02x, ", GET_U_1(p
),
689 GET_U_1(p
+ 1), GET_U_1(p
+ 2));
691 for(i
= 3; i
< ie_len
; i
++) {
692 ND_PRINT("%02x ", GET_U_1(p
+ i
));
696 case 0x1a: /* LE CSL IE */
698 ND_PRINT("[ERROR: Truncated CSL IE]");
700 ND_PRINT("CSL Phase = %d, CSL Period = %d",
701 GET_LE_U_2(p
), GET_LE_U_2(p
+ 2));
703 ND_PRINT(", Rendezvous time = %d",
706 if (ie_len
!= 4 && ie_len
!= 6) {
707 ND_PRINT(" [ERROR: CSL IE length wrong]");
711 case 0x1b: /* LE RIT IE */
713 ND_PRINT("[ERROR: Truncated RIT IE]");
715 ND_PRINT("Time to First Listen = %d, # of Repeat Listen = %d, Repeat Listen Interval = %d",
721 case 0x1c: /* DSME PAN Descriptor IE */
723 case 0x21: /* Extended DSME PAN descriptior IE */
725 ND_PRINT("[ERROR: Truncated DSME PAN IE]");
727 uint16_t ss
, ptr
, ulen
;
734 ieee802_15_4_print_superframe_specification(ndo
, ss
);
736 ND_PRINT("[ERROR: Truncated before pending addresses field]");
740 len
= ieee802_15_4_print_pending_addresses(ndo
,
749 if (element_id
== 0x21) {
750 /* Extended version. */
751 if (ie_len
< ptr
+ 2) {
752 ND_PRINT("[ERROR: Truncated before DSME Superframe Specification]");
755 ss
= GET_LE_U_2(p
+ ptr
);
757 ND_PRINT("Multi-superframe Order = %d", ss
& 0xff);
758 ND_PRINT(", %s", ((ss
& 0x100) ?
759 "Channel hopping mode" :
760 "Channel adaptation mode"));
762 ND_PRINT(", CAP reduction enabled");
765 ND_PRINT(", Deferred beacon enabled");
768 ND_PRINT(", Hopping Sequence Present");
772 if (ie_len
< ptr
+ 1) {
773 ND_PRINT("[ERROR: Truncated before DSME Superframe Specification]");
776 ss
= GET_U_1(p
+ ptr
);
778 ND_PRINT("Multi-superframe Order = %d",
780 ND_PRINT(", %s", ((ss
& 0x10) ?
781 "Channel hopping mode" :
782 "Channel adaptation mode"));
784 ND_PRINT(", CAP reduction enabled");
787 ND_PRINT(", Deferred beacon enabled");
790 if (ie_len
< ptr
+ 8) {
791 ND_PRINT(" [ERROR: Truncated before Time syncronization specification]");
794 ND_PRINT("Beacon timestamp = %" PRIu64
", offset = %d",
796 GET_LE_U_2(p
+ ptr
+ 6));
798 if (ie_len
< ptr
+ 4) {
799 ND_PRINT(" [ERROR: Truncated before Beacon Bitmap]");
803 ulen
= GET_LE_U_2(p
+ ptr
+ 2);
804 ND_PRINT("SD Index = %d, Bitmap len = %d, ",
805 GET_LE_U_2(p
+ ptr
), ulen
);
807 if (ie_len
< ptr
+ ulen
) {
808 ND_PRINT(" [ERROR: Truncated in SD bitmap]");
811 ND_PRINT(" SD Bitmap = ");
812 for(i
= 0; i
< ulen
; i
++) {
813 ND_PRINT("%02x ", GET_U_1(p
+ ptr
+ i
));
817 if (ie_len
< ptr
+ 5) {
818 ND_PRINT(" [ERROR: Truncated before Channel hopping specification]");
822 ulen
= GET_LE_U_2(p
+ ptr
+ 4);
823 ND_PRINT("Hopping Seq ID = %d, PAN Coordinator BSN = %d, "
824 "Channel offset = %d, Bitmap length = %d, ",
826 GET_U_1(p
+ ptr
+ 1),
827 GET_LE_U_2(p
+ ptr
+ 2),
830 if (ie_len
< ptr
+ ulen
) {
831 ND_PRINT(" [ERROR: Truncated in Channel offset bitmap]");
834 ND_PRINT(" Channel offset bitmap = ");
835 for(i
= 0; i
< ulen
; i
++) {
836 ND_PRINT("%02x ", GET_U_1(p
+ ptr
+ i
));
839 if (hopping_present
) {
840 if (ie_len
< ptr
+ 1) {
841 ND_PRINT(" [ERROR: Truncated in Hopping Sequence length]");
844 ulen
= GET_U_1(p
+ ptr
);
846 ND_PRINT("Hopping Seq length = %d [ ", ulen
);
848 /* The specification is not clear how the
849 hopping sequence is encoded, I assume two
850 octet unsigned integers for each channel. */
852 if (ie_len
< ptr
+ ulen
* 2) {
853 ND_PRINT(" [ERROR: Truncated in Channel offset bitmap]");
856 for(i
= 0; i
< ulen
; i
++) {
858 GET_LE_U_2(p
+ ptr
+ i
* 2));
865 case 0x1d: /* Rendezvous Tome IE */
867 ND_PRINT("[ERROR: Length != 2]");
869 uint16_t r_time
, w_u_interval
;
870 r_time
= GET_LE_U_2(p
);
871 w_u_interval
= GET_LE_U_2(p
+ 2);
873 ND_PRINT("Rendezvous time = %d, Wake-up Interval = %d",
874 r_time
, w_u_interval
);
877 case 0x1e: /* Time correction IE */
879 ND_PRINT("[ERROR: Length != 2]");
885 if (val
& 0x8000) { ND_PRINT("Negative "); }
891 ND_PRINT("Ack time correction = %d, ", timecorr
);
894 case 0x22: /* Frament Sequence Content Description IE */
895 /* XXX Not implemented */
896 case 0x23: /* Simplified Superframe Specification IE */
897 /* XXX Not implemented */
898 case 0x24: /* Simplified GTS Specification IE */
899 /* XXX Not implemented */
900 case 0x25: /* LECIM Capabilities IE */
901 /* XXX Not implemented */
902 case 0x26: /* TRLE Descriptor IE */
903 /* XXX Not implemented */
904 case 0x27: /* RCC Capabilities IE */
905 /* XXX Not implemented */
906 case 0x28: /* RCCN Descriptor IE */
907 /* XXX Not implemented */
908 case 0x29: /* Global Time IE */
909 /* XXX Not implemented */
910 case 0x2b: /* DA IE */
911 /* XXX Not implemented */
913 ND_PRINT("IE Data = ");
914 for(i
= 0; i
< ie_len
; i
++) {
915 ND_PRINT("%02x ", GET_U_1(p
+ i
));
922 * Parse and print Header IE list. See 7.4.2 of 802.15.4-2015 for
925 * Returns number of byts consumed from the packet or -1 in case of error.
928 ieee802_15_4_print_header_ie_list(netdissect_options
*ndo
,
931 int *payload_ie_present
)
933 int len
, ie
, element_id
, i
;
936 *payload_ie_present
= 0;
940 ND_PRINT("[ERROR: Truncated header IE]");
943 /* Extract IE Header */
945 if (CHECK_BIT(ie
, 15)) {
946 ND_PRINT("[ERROR: Header IE with type 1] ");
948 /* Get length and Element ID */
950 element_id
= (ie
>> 7) & 0xff;
951 if (element_id
> 127) {
952 ND_PRINT("Reserved Element ID %02x, length = %d ",
956 ND_PRINT("\n\t%s [", h_ie_names
[element_id
]);
958 ND_PRINT("\n\t%s [ length = %d, ",
959 h_ie_names
[element_id
], ie_len
);
962 if (caplen
< ie_len
) {
963 ND_PRINT("[ERROR: Truncated IE data]");
969 /* Parse and print content. */
970 if (ndo
->ndo_vflag
> 3 && ie_len
!= 0) {
971 ieee802_15_4_print_header_ie(ndo
, p
,
975 ND_PRINT("IE Data = ");
976 for(i
= 0; i
< ie_len
; i
++) {
977 ND_PRINT("%02x ", GET_U_1(p
+ i
));
984 caplen
-= 2 + ie_len
;
985 if (element_id
== 0x7e) {
986 *payload_ie_present
= 1;
989 if (element_id
== 0x7f) {
992 } while (caplen
> 0);
997 * Print MLME ie content.
1000 ieee802_15_4_print_mlme_ie(netdissect_options
*ndo
,
1002 uint16_t sub_ie_len
,
1008 /* Note, as there is no overlap with the long and short
1009 MLME sub IDs, we can just use one switch here. */
1011 case 0x08: /* Vendor Specific Nested IE */
1012 if (sub_ie_len
< 3) {
1013 ND_PRINT("[ERROR: Vendor OUI missing]");
1015 ND_PRINT("OUI = 0x%02x%02x%02x, ",
1019 ND_PRINT("Data = ");
1020 for(i
= 3; i
< sub_ie_len
; i
++) {
1021 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1025 case 0x09: /* Channel Hopping IE */
1026 if (sub_ie_len
< 1) {
1027 ND_PRINT("[ERROR: Hopping sequence ID missing]");
1028 } else if (sub_ie_len
== 1) {
1029 ND_PRINT("Hopping Sequence ID = %d", GET_U_1(p
));
1033 uint16_t channel_page
, number_of_channels
;
1035 ND_PRINT("Hopping Sequence ID = %d", GET_U_1(p
));
1038 if (sub_ie_len
< 7) {
1039 ND_PRINT("[ERROR: IE truncated]");
1042 channel_page
= GET_U_1(p
);
1043 number_of_channels
= GET_LE_U_2(p
+ 1);
1044 ND_PRINT("Channel Page = %d, Number of Channels = %d, ",
1045 channel_page
, number_of_channels
);
1046 ND_PRINT("Phy Configuration = 0x%08x, ",
1050 if (channel_page
== 9 || channel_page
== 10) {
1051 len
= (number_of_channels
+ 7) / 8;
1052 if (sub_ie_len
< len
) {
1053 ND_PRINT("[ERROR: IE truncated]");
1056 ND_PRINT("Extended bitmap = 0x");
1057 for(i
= 0; i
< len
; i
++) {
1058 ND_PRINT("%02x", GET_U_1(p
+ i
));
1064 if (sub_ie_len
< 2) {
1065 ND_PRINT("[ERROR: IE truncated]");
1068 len
= GET_LE_U_2(p
);
1071 ND_PRINT("Hopping Seq length = %d [ ", len
);
1073 if (sub_ie_len
< len
* 2) {
1074 ND_PRINT(" [ERROR: IE truncated]");
1077 for(i
= 0; i
< len
; i
++) {
1078 ND_PRINT("%02x ", GET_LE_U_2(p
+ i
* 2));
1082 sub_ie_len
-= len
* 2;
1083 if (sub_ie_len
< 2) {
1084 ND_PRINT("[ERROR: IE truncated]");
1087 ND_PRINT("Current hop = %d", GET_LE_U_2(p
));
1091 case 0x1a: /* TSCH Syncronization IE. */
1092 if (sub_ie_len
< 6) {
1093 ND_PRINT("[ERROR: Length != 6]");
1095 ND_PRINT("ASN = %010" PRIx64
", Join Metric = %d ",
1096 GET_LE_U_5(p
), GET_U_1(p
+ 5));
1098 case 0x1b: /* TSCH Slotframe and Link IE. */
1100 int sf_num
, off
, links
, opts
;
1102 if (sub_ie_len
< 1) {
1103 ND_PRINT("[ERROR: Truncated IE]");
1106 sf_num
= GET_U_1(p
);
1107 ND_PRINT("Slotframes = %d ", sf_num
);
1109 for(i
= 0; i
< sf_num
; i
++) {
1110 if (sub_ie_len
< off
+ 4) {
1111 ND_PRINT("[ERROR: Truncated IE before slotframes]");
1114 links
= GET_U_1(p
+ off
+ 3);
1115 ND_PRINT("\n\t\t\t[ Handle %d, size = %d, links = %d ",
1117 GET_LE_U_2(p
+ off
+ 1),
1120 for(j
= 0; j
< links
; j
++) {
1121 if (sub_ie_len
< off
+ 5) {
1122 ND_PRINT("[ERROR: Truncated IE links]");
1125 opts
= GET_U_1(p
+ off
+ 4);
1126 ND_PRINT("\n\t\t\t\t[ Timeslot = %d, Offset = %d, Options = ",
1127 GET_LE_U_2(p
+ off
),
1128 GET_LE_U_2(p
+ off
+ 2));
1129 if (opts
& 0x1) { ND_PRINT("TX "); }
1130 if (opts
& 0x2) { ND_PRINT("RX "); }
1131 if (opts
& 0x4) { ND_PRINT("Shared "); }
1133 ND_PRINT("Timekeeping ");
1136 ND_PRINT("Priority ");
1145 case 0x1c: /* TSCH Timeslot IE. */
1146 if (sub_ie_len
== 1) {
1147 ND_PRINT("Time slot ID = %d ", GET_U_1(p
));
1148 } else if (sub_ie_len
== 25) {
1149 ND_PRINT("Time slot ID = %d, CCA Offset = %d, CCA = %d, TX Offset = %d, RX Offset = %d, RX Ack Delay = %d, TX Ack Delay = %d, RX Wait = %d, Ack Wait = %d, RX TX = %d, Max Ack = %d, Max TX = %d, Time slot Length = %d ",
1162 GET_LE_U_2(p
+ 23));
1163 } else if (sub_ie_len
== 27) {
1164 ND_PRINT("Time slot ID = %d, CCA Offset = %d, CCA = %d, TX Offset = %d, RX Offset = %d, RX Ack Delay = %d, TX Ack Delay = %d, RX Wait = %d, Ack Wait = %d, RX TX = %d, Max Ack = %d, Max TX = %d, Time slot Length = %d ",
1177 GET_LE_U_3(p
+ 24));
1179 ND_PRINT("[ERROR: Length not 1, 25, or 27]");
1180 ND_PRINT("\n\t\t\tIE Data = ");
1181 for(i
= 0; i
< sub_ie_len
; i
++) {
1182 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1186 case 0x1d: /* Hopping timing IE */
1187 /* XXX Not implemented */
1188 case 0x1e: /* Enhanced Beacon Filter IE */
1189 /* XXX Not implemented */
1190 case 0x1f: /* MAC Metrics IE */
1191 /* XXX Not implemented */
1192 case 0x20: /* All MAC Metrics IE */
1193 /* XXX Not implemented */
1194 case 0x21: /* Coexistence Specification IE */
1195 /* XXX Not implemented */
1196 case 0x22: /* SUN Device Capabilities IE */
1197 /* XXX Not implemented */
1198 case 0x23: /* SUN FSK Generic PHY IE */
1199 /* XXX Not implemented */
1200 case 0x24: /* Mode Switch Parameter IE */
1201 /* XXX Not implemented */
1202 case 0x25: /* PHY Parameter Change IE */
1203 /* XXX Not implemented */
1204 case 0x26: /* O-QPSK PHY Mode IE */
1205 /* XXX Not implemented */
1206 case 0x27: /* PCA Allocation IE */
1207 /* XXX Not implemented */
1208 case 0x28: /* LECIM DSSS Operating Mode IE */
1209 /* XXX Not implemented */
1210 case 0x29: /* LECIM FSK Operating Mode IE */
1211 /* XXX Not implemented */
1212 case 0x2b: /* TVWS PHY Operating Mode Description IE */
1213 /* XXX Not implemented */
1214 case 0x2c: /* TVWS Device Capabilities IE */
1215 /* XXX Not implemented */
1216 case 0x2d: /* TVWS Device Catagory IE */
1217 /* XXX Not implemented */
1218 case 0x2e: /* TVWS Device Identification IE */
1219 /* XXX Not implemented */
1220 case 0x2f: /* TVWS Device Location IE */
1221 /* XXX Not implemented */
1222 case 0x30: /* TVWS Channel Information Query IE */
1223 /* XXX Not implemented */
1224 case 0x31: /* TVWS Channel Information Source IE */
1225 /* XXX Not implemented */
1226 case 0x32: /* CTM IE */
1227 /* XXX Not implemented */
1228 case 0x33: /* Timestamp IE */
1229 /* XXX Not implemented */
1230 case 0x34: /* Timestamp Difference IE */
1231 /* XXX Not implemented */
1232 case 0x35: /* TMCTP Specification IE */
1233 /* XXX Not implemented */
1234 case 0x36: /* TCC PHY Operating Mode IE */
1235 /* XXX Not implemented */
1237 ND_PRINT("IE Data = ");
1238 for(i
= 0; i
< sub_ie_len
; i
++) {
1239 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1246 * MLME IE list parsing and printing. See 7.4.3.2 of 802.15.4-2015
1247 * for more information.
1250 ieee802_15_4_print_mlme_ie_list(netdissect_options
*ndo
,
1254 int ie
, sub_id
, i
, type
;
1255 uint16_t sub_ie_len
;
1259 ND_PRINT("[ERROR: Truncated MLME IE]");
1262 /* Extract IE header */
1264 type
= CHECK_BIT(ie
, 15);
1267 sub_ie_len
= ie
& 0x3ff;
1268 sub_id
= (ie
>> 11) & 0x0f;
1270 sub_ie_len
= ie
& 0xff;
1271 sub_id
= (ie
>> 8) & 0x7f;
1274 /* Skip the IE header */
1278 ND_PRINT("\n\t\t%s [ length = %d, ",
1279 p_mlme_short_names
[sub_id
], sub_ie_len
);
1281 ND_PRINT("\n\t\t%s [ length = %d, ",
1282 p_mlme_long_names
[sub_id
], sub_ie_len
);
1285 if (ie_len
< sub_ie_len
) {
1286 ND_PRINT("[ERROR: Truncated IE data]");
1289 if (sub_ie_len
!= 0) {
1290 if (ndo
->ndo_vflag
> 3) {
1291 ieee802_15_4_print_mlme_ie(ndo
, p
, sub_ie_len
, sub_id
);
1292 } else if (ndo
->ndo_vflag
> 2) {
1293 ND_PRINT("IE Data = ");
1294 for(i
= 0; i
< sub_ie_len
; i
++) {
1295 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1301 ie_len
-= 2 + sub_ie_len
;
1302 } while (ie_len
> 0);
1307 * Multiplexd IE (802.15.9) parsing and printing.
1309 * Returns number of bytes consumed from packet or -1 in case of error.
1312 ieee802_15_4_print_mpx_ie(netdissect_options
*ndo
,
1316 int transfer_type
, tid
;
1317 int fragment_number
, data_start
;
1322 ND_PRINT("[ERROR: Transaction control byte missing]");
1326 transfer_type
= GET_U_1(p
) & 0x7;
1327 tid
= GET_U_1(p
) >> 3;
1328 switch (transfer_type
) {
1329 case 0x00: /* Full upper layer frame. */
1330 case 0x01: /* Full upper layer frame with small Multiplex ID. */
1331 ND_PRINT("Type = Full upper layer fragment%s, ",
1332 (transfer_type
== 0x01 ?
1333 " with small Multiplex ID" : ""));
1334 if (transfer_type
== 0x00) {
1336 ND_PRINT("[ERROR: Multiplex ID missing]");
1340 ND_PRINT("tid = 0x%02x, Multiplex ID = 0x%04x, ",
1341 tid
, GET_LE_U_2(p
+ 1));
1344 ND_PRINT("Multiplex ID = 0x%04x, ", tid
);
1347 case 0x02: /* First, or middle, Fragments */
1348 case 0x04: /* Last fragment */
1350 ND_PRINT("[ERROR: fragment number missing]");
1354 fragment_number
= GET_U_1(p
+ 1);
1355 ND_PRINT("Type = %s, tid = 0x%02x, fragment = 0x%02x, ",
1356 (transfer_type
== 0x02 ?
1357 (fragment_number
== 0 ?
1358 "First fragment" : "Middle fragment") :
1359 "Last fragment"), tid
,
1362 if (fragment_number
== 0) {
1363 int total_size
, multiplex_id
;
1366 ND_PRINT("[ERROR: Total upper layer size or multiplex ID missing]");
1369 total_size
= GET_LE_U_2(p
+ 2);
1370 multiplex_id
= GET_LE_U_2(p
+ 4);
1371 ND_PRINT("Total upper layer size = 0x%04x, Multiplex ID = 0x%04x, ",
1372 total_size
, multiplex_id
);
1376 case 0x06: /* Abort code */
1378 ND_PRINT("Type = Abort, tid = 0x%02x, no max size given",
1380 } else if (ie_len
== 3) {
1381 ND_PRINT("Type = Abort, tid = 0x%02x, max size = 0x%04x",
1382 tid
, GET_LE_U_2(p
+ 1));
1384 ND_PRINT("Type = Abort, tid = 0x%02x, invalid length = %d (not 1 or 3)",
1386 ND_PRINT("Abort data = ");
1387 for(i
= 1; i
< ie_len
; i
++) {
1388 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1394 case 0x03: /* Reserved */
1395 case 0x05: /* Reserved */
1396 case 0x07: /* Reserved */
1397 ND_PRINT("Type = %d (Reserved), tid = 0x%02x, ",
1398 transfer_type
, tid
);
1403 ND_PRINT("Upper layer data = ");
1404 for(i
= data_start
; i
< ie_len
; i
++) {
1405 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1410 * Payload IE list parsing and printing. See 7.4.3 of 802.15.4-2015
1411 * for more information.
1413 * Returns number of byts consumed from the packet or -1 in case of error.
1416 ieee802_15_4_print_payload_ie_list(netdissect_options
*ndo
,
1420 int len
, ie
, group_id
, i
;
1426 ND_PRINT("[ERROR: Truncated header IE]");
1429 /* Extract IE header */
1431 if ((CHECK_BIT(ie
, 15)) == 0) {
1432 ND_PRINT("[ERROR: Payload IE with type 0] ");
1434 ie_len
= ie
& 0x3ff;
1435 group_id
= (ie
>> 11) & 0x0f;
1437 /* Skip the IE header */
1440 ND_PRINT("\n\t%s [", p_ie_names
[group_id
]);
1442 ND_PRINT("\n\t%s [ length = %d, ",
1443 p_ie_names
[group_id
], ie_len
);
1445 if (caplen
< ie_len
) {
1446 ND_PRINT("[ERROR: Truncated IE data]");
1449 if (ndo
->ndo_vflag
> 3 && ie_len
!= 0) {
1451 case 0x1: /* MLME IE */
1452 ieee802_15_4_print_mlme_ie_list(ndo
, p
, ie_len
);
1454 case 0x2: /* Vendor Specific Nested IE */
1456 ND_PRINT("[ERROR: Vendor OUI missing]");
1458 ND_PRINT("OUI = 0x%02x%02x%02x, ",
1462 ND_PRINT("Data = ");
1463 for(i
= 3; i
< ie_len
; i
++) {
1469 case 0x3: /* Multiplexed IE (802.15.9) */
1470 ieee802_15_4_print_mpx_ie(ndo
, p
, ie_len
);
1472 case 0x5: /* IETF IE */
1474 ND_PRINT("[ERROR: Subtype ID missing]");
1476 ND_PRINT("Subtype ID = 0x%02x, Subtype content = ",
1478 for(i
= 1; i
< ie_len
; i
++) {
1485 ND_PRINT("IE Data = ");
1486 for(i
= 0; i
< ie_len
; i
++) {
1487 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1493 ND_PRINT("IE Data = ");
1494 for(i
= 0; i
< ie_len
; i
++) {
1495 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1502 caplen
-= 2 + ie_len
;
1503 if (group_id
== 0xf) {
1506 } while (caplen
> 0);
1511 * Parse and print auxiliary security header.
1513 * Returns number of byts consumed from the packet or -1 in case of error.
1516 ieee802_15_4_print_aux_sec_header(netdissect_options
*ndo
,
1519 int *security_level
)
1521 int sc
, key_id_mode
, len
;
1524 ND_PRINT("[ERROR: Truncated before Aux Security Header]");
1529 *security_level
= sc
& 0x7;
1530 key_id_mode
= (sc
>> 3) & 0x3;
1535 if (ndo
->ndo_vflag
> 0) {
1536 ND_PRINT("\n\tSecurity Level %d, Key Id Mode %d, ",
1537 *security_level
, key_id_mode
);
1539 if ((CHECK_BIT(sc
, 5)) == 0) {
1541 ND_PRINT("[ERROR: Truncated before Frame Counter]");
1544 if (ndo
->ndo_vflag
> 1) {
1545 ND_PRINT("Frame Counter 0x%08x ",
1552 switch (key_id_mode
) {
1553 case 0x00: /* Implicit. */
1554 if (ndo
->ndo_vflag
> 1) {
1555 ND_PRINT("Implicit");
1559 case 0x01: /* Key Index, nothing to print here. */
1561 case 0x02: /* PAN and Short address Key Source, and Key Index. */
1563 ND_PRINT("[ERROR: Truncated before Key Source]");
1566 if (ndo
->ndo_vflag
> 1) {
1567 ND_PRINT("KeySource 0x%04x:%0x4x, ",
1568 GET_LE_U_2(p
), GET_LE_U_2(p
+ 2));
1574 case 0x03: /* Extended address and Key Index. */
1576 ND_PRINT("[ERROR: Truncated before Key Source]");
1579 if (ndo
->ndo_vflag
> 1) {
1580 ND_PRINT("KeySource %s, ", GET_LE64ADDR_STRING(p
));
1588 ND_PRINT("[ERROR: Truncated before Key Index]");
1591 if (ndo
->ndo_vflag
> 1) {
1592 ND_PRINT("KeyIndex 0x%02x, ", GET_U_1(p
));
1601 * Print command data.
1603 * Returns number of byts consumed from the packet or -1 in case of error.
1606 ieee802_15_4_print_command_data(netdissect_options
*ndo
,
1613 switch (command_id
) {
1614 case 0x01: /* Assocation Request */
1616 ND_PRINT("Invalid Assocation request command length");
1620 cap_info
= GET_U_1(p
);
1621 ND_PRINT("%s%s%s%s%s%s",
1622 ((cap_info
& 0x02) ?
1624 ((cap_info
& 0x04) ?
1625 "AC powered, " : ""),
1626 ((cap_info
& 0x08) ?
1627 "Receiver on when idle, " : ""),
1628 ((cap_info
& 0x10) ?
1629 "Fast association, " : ""),
1630 ((cap_info
& 0x40) ?
1631 "Security supported, " : ""),
1632 ((cap_info
& 0x80) ?
1633 "Allocate address, " : ""));
1637 case 0x02: /* Assocation Response */
1639 ND_PRINT("Invalid Assocation response command length");
1642 ND_PRINT("Short address = ");
1643 ieee802_15_4_print_addr(ndo
, p
, 2);
1644 switch (GET_U_1(p
+ 2)) {
1646 ND_PRINT(", Association successful");
1649 ND_PRINT(", PAN at capacity");
1652 ND_PRINT(", PAN access denied");
1655 ND_PRINT(", Hooping sequence offset duplication");
1658 ND_PRINT(", Fast association successful");
1661 ND_PRINT(", Status = 0x%02x",
1668 case 0x03: /* Diassociation Notification command */
1670 ND_PRINT("Invalid Disassociation Notification command length");
1673 switch (GET_U_1(p
)) {
1675 ND_PRINT("Reserved");
1678 ND_PRINT("Reason = The coordinator wishes the device to leave PAN");
1681 ND_PRINT("Reason = The device wishes to leave the PAN");
1684 ND_PRINT("Reason = 0x%02x", GET_U_1(p
+ 2));
1690 /* Following ones do not have any data. */
1691 case 0x04: /* Data Request command */
1692 case 0x05: /* PAN ID Conflict Notification command */
1693 case 0x06: /* Orphan Notification command */
1694 case 0x07: /* Beacon Request command */
1695 /* Should not have any data. */
1697 case 0x08: /* Coordinator Realignment command */
1698 if (caplen
< 7 || caplen
> 8) {
1699 ND_PRINT("Invalid Coordinator Realignment command length");
1702 uint16_t channel
, page
;
1704 ND_PRINT("Pan ID = 0x%04x, Coordinator short address = ",
1706 ieee802_15_4_print_addr(ndo
, p
+ 2, 2);
1707 channel
= GET_U_1(p
+ 4);
1710 page
= GET_U_1(p
+ 7);
1714 if (CHECK_BIT(page
, 7)) {
1715 /* No page present, instead we have msb of
1716 channel in the page. */
1717 channel
|= (page
& 0x7f) << 8;
1718 ND_PRINT(", Channel Number = %d", channel
);
1720 ND_PRINT(", Channel Number = %d, page = %d",
1723 ND_PRINT(", Short address = ");
1724 ieee802_15_4_print_addr(ndo
, p
+ 5, 2);
1728 case 0x09: /* GTS Request command */
1730 ND_PRINT("Invalid GTS Request command length");
1736 ND_PRINT("GTS Length = %d, %s, %s",
1738 (CHECK_BIT(gts
, 4) ?
1739 "Receive-only GTS" : "Transmit-only GTS"),
1740 (CHECK_BIT(gts
, 5) ?
1741 "GTS allocation" : "GTS deallocations"));
1745 case 0x13: /* DSME Association Request command */
1746 /* XXX Not implemented */
1747 case 0x14: /* DSME Association Response command */
1748 /* XXX Not implemented */
1749 case 0x15: /* DSME GTS Request command */
1750 /* XXX Not implemented */
1751 case 0x16: /* DSME GTS Response command */
1752 /* XXX Not implemented */
1753 case 0x17: /* DSME GTS Notify command */
1754 /* XXX Not implemented */
1755 case 0x18: /* DSME Information Request command */
1756 /* XXX Not implemented */
1757 case 0x19: /* DSME Information Response command */
1758 /* XXX Not implemented */
1759 case 0x1a: /* DSME Beacon Allocation Notification command */
1760 /* XXX Not implemented */
1761 case 0x1b: /* DSME Beacon Collision Notification command */
1762 /* XXX Not implemented */
1763 case 0x1c: /* DSME Link Report command */
1764 /* XXX Not implemented */
1765 case 0x20: /* RIT Data Request command */
1766 /* XXX Not implemented */
1767 case 0x21: /* DBS Request command */
1768 /* XXX Not implemented */
1769 case 0x22: /* DBS Response command */
1770 /* XXX Not implemented */
1771 case 0x23: /* RIT Data Response command */
1772 /* XXX Not implemented */
1773 case 0x24: /* Vendor Specific command */
1774 /* XXX Not implemented */
1775 case 0x0a: /* TRLE Management Request command */
1776 /* XXX Not implemented */
1777 case 0x0b: /* TRLE Management Response command */
1778 /* XXX Not implemented */
1780 ND_PRINT("Command Data = ");
1781 for(i
= 0; i
< caplen
; i
++) {
1782 ND_PRINT("%02x ", GET_U_1(p
+ i
));
1790 * Parse and print frames folloing standard format.
1792 * Returns FALSE in case of error.
1795 ieee802_15_4_std_frames(netdissect_options
*ndo
,
1796 const u_char
*p
, u_int caplen
,
1799 int len
, frame_version
, pan_id_comp
;
1801 int src_pan
, dst_pan
, src_addr_len
, dst_addr_len
;
1802 int security_level
, miclen
= 0;
1803 int payload_ie_present
;
1805 uint32_t fcs
, crc_check
;
1806 const u_char
*mic_start
= NULL
;
1808 payload_ie_present
= 0;
1811 /* Assume 2 octet FCS, the FCS length depends on the PHY, and we do not
1814 /* Cannot have FCS, assume no FCS. */
1817 /* Test for 4 octet FCS. */
1818 fcs
= GET_LE_U_4(p
+ caplen
- 4);
1819 crc_check
= ieee802_15_4_crc32(ndo
, p
, caplen
- 4);
1820 if (crc_check
== fcs
) {
1824 /* Test for 2 octet FCS. */
1825 fcs
= GET_LE_U_2(p
+ caplen
- 2);
1826 crc_check
= ieee802_15_4_crc16(ndo
, p
, caplen
- 2);
1827 if (crc_check
== fcs
) {
1831 /* Wrong FCS, FCS might not be included in the
1832 captured frame, do not remove it. */
1837 /* Frame version. */
1838 frame_version
= FC_FRAME_VERSION(fc
);
1839 frame_type
= FC_FRAME_TYPE(fc
);
1840 ND_PRINT("v%d ", frame_version
);
1842 if (ndo
->ndo_vflag
> 2) {
1843 if (CHECK_BIT(fc
, 3)) { ND_PRINT("Security Enabled, "); }
1844 if (CHECK_BIT(fc
, 4)) { ND_PRINT("Frame Pending, "); }
1845 if (CHECK_BIT(fc
, 5)) { ND_PRINT("AR, "); }
1846 if (CHECK_BIT(fc
, 6)) { ND_PRINT("PAN ID Compression, "); }
1847 if (CHECK_BIT(fc
, 8)) { ND_PRINT("Sequence Number Suppression, "); }
1848 if (CHECK_BIT(fc
, 9)) { ND_PRINT("IE present, "); }
1851 /* Check for the sequence number supression. */
1852 if (CHECK_BIT(fc
, 8)) {
1853 /* Sequence number is suppressed. */
1854 if (frame_version
< 2) {
1855 /* Sequence number can only be supressed for frame
1856 version 2 or higher, this is invalid frame. */
1857 ND_PRINT("[ERROR: Sequence number suppressed on frames where version < 2]");
1860 ND_PRINT("seq suppressed ");
1864 seq
= GET_U_1(p
+ 2);
1868 ND_PRINT("seq %02x ", seq
);
1871 /* See which parts of addresses we have. */
1872 dst_addr_len
= ieee802_15_4_addr_len((fc
>> 10) & 0x3);
1873 src_addr_len
= ieee802_15_4_addr_len((fc
>> 14) & 0x3);
1874 if (src_addr_len
< 0) {
1875 ND_PRINT("[ERROR: Invalid src address mode]");
1878 if (dst_addr_len
< 0) {
1879 ND_PRINT("[ERROR: Invalid dst address mode]");
1884 pan_id_comp
= CHECK_BIT(fc
, 6);
1886 /* The PAN ID Compression rules are complicated. */
1888 /* First check old versions, where the rules are simple. */
1889 if (frame_version
< 2) {
1893 if (dst_addr_len
<= 0 || src_addr_len
<= 0) {
1894 /* Invalid frame, PAN ID Compression must be 0
1895 if only one address in the frame. */
1896 ND_PRINT("[ERROR: PAN ID Compression != 0, and only one address with frame version < 2]");
1902 if (dst_addr_len
<= 0) {
1905 if (src_addr_len
<= 0) {
1909 /* Frame version 2 rules are more complicated, and they depend
1910 on the address modes of the frame, generic rules are same,
1911 but then there are some special cases. */
1919 if (dst_addr_len
<= 0) {
1922 if (src_addr_len
<= 0) {
1926 if (src_addr_len
== 0 &&
1927 dst_addr_len
== 0) {
1928 /* Both addresses are missing, but PAN ID
1929 compression set, special case we have
1930 destination PAN but no addresses. */
1932 } else if ((src_addr_len
== 0 &&
1933 dst_addr_len
> 0) ||
1934 (src_addr_len
> 0 &&
1935 dst_addr_len
== 0)) {
1936 /* Only one address present, and PAN ID
1937 compression is set, we do not have PAN id at
1941 } else if (src_addr_len
== 8 &&
1942 dst_addr_len
== 8) {
1943 /* Both addresses are Extended, and PAN ID
1944 compression set, we do not have PAN ID at
1950 /* Special cases where PAN ID Compression is not set. */
1951 if (src_addr_len
== 8 &&
1952 dst_addr_len
== 8) {
1953 /* Both addresses are Extended, and PAN ID
1954 compression not set, we do have only one PAN
1955 ID (destination). */
1959 #ifdef BROKEN_6TISCH_PAN_ID_COMPRESSION
1960 if (src_addr_len
== 8 &&
1961 dst_addr_len
== 2) {
1962 /* Special case for the broken 6tisch
1966 #endif /* BROKEN_6TISCH_PAN_ID_COMPRESSION */
1970 /* Print dst PAN and address. */
1973 ND_PRINT("[ERROR: Truncated before dst_pan]");
1976 ND_PRINT("%04x:", GET_LE_U_2(p
));
1982 if (caplen
< (u_int
) dst_addr_len
) {
1983 ND_PRINT("[ERROR: Truncated before dst_addr]");
1986 ieee802_15_4_print_addr(ndo
, p
, dst_addr_len
);
1988 caplen
-= dst_addr_len
;
1992 /* Print src PAN and address. */
1995 ND_PRINT("[ERROR: Truncated before dst_pan]");
1998 ND_PRINT("%04x:", GET_LE_U_2(p
));
2004 if (caplen
< (u_int
) src_addr_len
) {
2005 ND_PRINT("[ERROR: Truncated before dst_addr]");
2008 ieee802_15_4_print_addr(ndo
, p
, src_addr_len
);
2011 caplen
-= src_addr_len
;
2012 if (CHECK_BIT(fc
, 3)) {
2014 * XXX - if frame_version is 0, this is the 2003
2015 * spec, and you don't have the auxiliary security
2016 * header, you have a frame counter and key index
2017 * for the AES-CTR and AES-CCM security suites but
2018 * not for the AES-CBC-MAC security suite.
2020 len
= ieee802_15_4_print_aux_sec_header(ndo
, p
, caplen
,
2031 switch (security_level
) {
2032 case 0: /*FALLTHOUGH */
2036 case 1: /*FALLTHOUGH */
2040 case 2: /*FALLTHOUGH */
2044 case 3: /*FALLTHOUGH */
2052 if (caplen
< (u_int
) miclen
) {
2053 ND_PRINT("[ERROR: Truncated before MIC]");
2057 mic_start
= p
+ caplen
;
2060 /* Parse Information elements if present */
2061 if (CHECK_BIT(fc
, 9)) {
2062 /* Yes we have those. */
2063 len
= ieee802_15_4_print_header_ie_list(ndo
, p
, caplen
,
2064 &payload_ie_present
);
2072 if (payload_ie_present
) {
2073 if (security_level
>= 4) {
2074 ND_PRINT("Payload IEs present, but encrypted, cannot print ");
2076 len
= ieee802_15_4_print_payload_ie_list(ndo
, p
, caplen
);
2086 if (ndo
->ndo_vflag
> 2 && miclen
!= 0) {
2087 ND_PRINT("\n\tMIC ");
2089 for(len
= 0; len
< miclen
; len
++) {
2090 ND_PRINT("%02x", GET_U_1(mic_start
+ len
));
2096 if (ndo
->ndo_vflag
> 2) {
2097 if (crc_check
== fcs
) {
2098 ND_PRINT("FCS %x ", fcs
);
2100 ND_PRINT("wrong FCS %x vs %x (assume no FCS stored) ",
2106 switch (frame_type
) {
2107 case 0x00: /* Beacon */
2108 if (frame_version
< 2) {
2110 ND_PRINT("[ERROR: Truncated before beacon information]");
2116 ieee802_15_4_print_superframe_specification(ndo
, ss
);
2122 ND_PRINT("[ERROR: Truncated before GTS info]");
2126 len
= ieee802_15_4_print_gts_info(ndo
, p
, caplen
);
2134 /* Pending Addresses */
2136 ND_PRINT("[ERROR: Truncated before pending addresses]");
2139 len
= ieee802_15_4_print_pending_addresses(ndo
, p
, caplen
);
2147 if (!ndo
->ndo_suppress_default_print
)
2148 ND_DEFAULTPRINT(p
, caplen
);
2151 case 0x01: /* Data */
2152 case 0x02: /* Acknowledgement */
2153 if (!ndo
->ndo_suppress_default_print
)
2154 ND_DEFAULTPRINT(p
, caplen
);
2156 case 0x03: /* MAC Command */
2158 ND_PRINT("[ERROR: Truncated before Command ID]");
2162 command_id
= GET_U_1(p
);
2163 if (command_id
>= 0x30) {
2164 ND_PRINT("Command ID = Reserved 0x%02x ",
2167 ND_PRINT("Command ID = %s ",
2168 mac_c_names
[command_id
]);
2173 len
= ieee802_15_4_print_command_data(ndo
, command_id
, p
, caplen
);
2180 if (!ndo
->ndo_suppress_default_print
)
2181 ND_DEFAULTPRINT(p
, caplen
);
2188 * Print and parse Multipurpose frames.
2190 * Returns FALSE in case of error.
2193 ieee802_15_4_mp_frame(netdissect_options
*ndo
,
2194 const u_char
*p
, u_int caplen
,
2197 int len
, frame_version
, pan_id_present
;
2198 int src_addr_len
, dst_addr_len
;
2199 int security_level
, miclen
= 0;
2200 int ie_present
, payload_ie_present
, security_enabled
;
2202 uint32_t fcs
, crc_check
;
2203 const u_char
*mic_start
= NULL
;
2207 payload_ie_present
= 0;
2208 security_enabled
= 0;
2211 /* Assume 2 octet FCS, the FCS length depends on the PHY, and we do not
2214 /* Cannot have FCS, assume no FCS. */
2218 /* Test for 4 octet FCS. */
2219 fcs
= GET_LE_U_4(p
+ caplen
- 4);
2220 crc_check
= ieee802_15_4_crc32(ndo
, p
, caplen
- 4);
2221 if (crc_check
== fcs
) {
2225 fcs
= GET_LE_U_2(p
+ caplen
- 2);
2226 crc_check
= ieee802_15_4_crc16(ndo
, p
, caplen
- 2);
2227 if (crc_check
== fcs
) {
2233 fcs
= GET_LE_U_2(p
+ caplen
- 2);
2234 crc_check
= ieee802_15_4_crc16(ndo
, p
, caplen
- 2);
2235 if (crc_check
== fcs
) {
2242 if (CHECK_BIT(fc
, 3)) {
2243 /* Long Frame Control */
2245 /* Frame version. */
2246 frame_version
= FC_FRAME_VERSION(fc
);
2247 ND_PRINT("v%d ", frame_version
);
2249 pan_id_present
= CHECK_BIT(fc
, 8);
2250 ie_present
= CHECK_BIT(fc
, 15);
2251 security_enabled
= CHECK_BIT(fc
, 9);
2253 if (ndo
->ndo_vflag
> 2) {
2254 if (security_enabled
) { ND_PRINT("Security Enabled, "); }
2255 if (CHECK_BIT(fc
, 11)) { ND_PRINT("Frame Pending, "); }
2256 if (CHECK_BIT(fc
, 14)) { ND_PRINT("AR, "); }
2257 if (pan_id_present
) { ND_PRINT("PAN ID Present, "); }
2258 if (CHECK_BIT(fc
, 10)) {
2259 ND_PRINT("Sequence Number Suppression, ");
2261 if (ie_present
) { ND_PRINT("IE present, "); }
2264 /* Check for the sequence number supression. */
2265 if (CHECK_BIT(fc
, 10)) {
2266 /* Sequence number is suppressed, but long version. */
2270 seq
= GET_U_1(p
+ 2);
2274 ND_PRINT("seq %02x ", seq
);
2277 /* Short format of header, but with seq no */
2278 seq
= GET_U_1(p
+ 1);
2282 ND_PRINT("seq %02x ", seq
);
2285 /* See which parts of addresses we have. */
2286 dst_addr_len
= ieee802_15_4_addr_len((fc
>> 4) & 0x3);
2287 src_addr_len
= ieee802_15_4_addr_len((fc
>> 6) & 0x3);
2288 if (src_addr_len
< 0) {
2289 ND_PRINT("[ERROR: Invalid src address mode]");
2292 if (dst_addr_len
< 0) {
2293 ND_PRINT("[ERROR: Invalid dst address mode]");
2297 /* Print dst PAN and address. */
2298 if (pan_id_present
) {
2300 ND_PRINT("[ERROR: Truncated before dst_pan]");
2303 ND_PRINT("%04x:", GET_LE_U_2(p
));
2309 if (caplen
< (u_int
) dst_addr_len
) {
2310 ND_PRINT("[ERROR: Truncated before dst_addr]");
2313 ieee802_15_4_print_addr(ndo
, p
, dst_addr_len
);
2315 caplen
-= dst_addr_len
;
2319 /* Print src PAN and address. */
2321 if (caplen
< (u_int
) src_addr_len
) {
2322 ND_PRINT("[ERROR: Truncated before dst_addr]");
2325 ieee802_15_4_print_addr(ndo
, p
, src_addr_len
);
2328 caplen
-= src_addr_len
;
2330 if (security_enabled
) {
2331 len
= ieee802_15_4_print_aux_sec_header(ndo
, p
, caplen
,
2342 switch (security_level
) {
2343 case 0: /*FALLTHOUGH */
2347 case 1: /*FALLTHOUGH */
2351 case 2: /*FALLTHOUGH */
2355 case 3: /*FALLTHOUGH */
2363 if (caplen
< (u_int
) miclen
) {
2364 ND_PRINT("[ERROR: Truncated before MIC]");
2368 mic_start
= p
+ caplen
;
2371 /* Parse Information elements if present */
2373 /* Yes we have those. */
2374 len
= ieee802_15_4_print_header_ie_list(ndo
, p
, caplen
,
2375 &payload_ie_present
);
2383 if (payload_ie_present
) {
2384 if (security_level
>= 4) {
2385 ND_PRINT("Payload IEs present, but encrypted, cannot print ");
2387 len
= ieee802_15_4_print_payload_ie_list(ndo
, p
,
2398 if (ndo
->ndo_vflag
> 2 && miclen
!= 0) {
2399 ND_PRINT("\n\tMIC ");
2401 for(len
= 0; len
< miclen
; len
++) {
2402 ND_PRINT("%02x", GET_U_1(mic_start
+ len
));
2409 if (ndo
->ndo_vflag
> 2) {
2410 if (crc_check
== fcs
) {
2411 ND_PRINT("FCS %x ", fcs
);
2413 ND_PRINT("wrong FCS %x vs %x (assume no FCS stored) ",
2418 if (!ndo
->ndo_suppress_default_print
)
2419 ND_DEFAULTPRINT(p
, caplen
);
2427 * Returns FALSE in case of error.
2430 ieee802_15_4_frag_frame(netdissect_options
*ndo _U_
,
2431 const u_char
*p _U_
,
2435 /* Not implement yet, might be bit hard to implement, as the
2436 * information to set up the fragment is coming in the previous frame
2437 * in the Fragment Sequence Context Description IE, thus we need to
2438 * store information from there, so we can use it here. */
2443 * Interal call to dissector taking packet + len instead of pcap_pkthdr.
2445 * Returns FALSE in case of error.
2448 ieee802_15_4_print(netdissect_options
*ndo
,
2449 const u_char
*p
, u_int caplen
)
2454 ndo
->ndo_protocol
= "802.15.4";
2457 nd_print_trunc(ndo
);
2463 /* First we need to check the frame type to know how to parse the rest
2464 of the FC. Frame type is the first 3 bit of the frame control field.
2467 frame_type
= FC_FRAME_TYPE(fc
);
2468 ND_PRINT("IEEE 802.15.4 %s packet ", ftypes
[frame_type
]);
2470 switch (frame_type
) {
2471 case 0x00: /* Beacon */
2472 case 0x01: /* Data */
2473 case 0x02: /* Acknowledgement */
2474 case 0x03: /* MAC Command */
2475 return ieee802_15_4_std_frames(ndo
, p
, caplen
, fc
);
2477 case 0x04: /* Reserved */
2480 case 0x05: /* Multipurpose */
2481 return ieee802_15_4_mp_frame(ndo
, p
, caplen
, fc
);
2483 case 0x06: /* Fragment or Frak */
2484 return ieee802_15_4_frag_frame(ndo
, p
, caplen
, fc
);
2486 case 0x07: /* Extended */
2494 * Main function to print packets.
2498 ieee802_15_4_if_print(netdissect_options
*ndo
,
2499 const struct pcap_pkthdr
*h
, const u_char
*p
)
2501 u_int caplen
= h
->caplen
;
2502 ndo
->ndo_protocol
= "802.15.4";
2503 ndo
->ndo_ll_hdr_len
+= ieee802_15_4_print(ndo
, p
, caplen
);
2506 /* For DLT_IEEE802_15_4_TAP */
2507 /* https://github.com/jkcko/ieee802.15.4-tap */
2509 ieee802_15_4_tap_if_print(netdissect_options
*ndo
,
2510 const struct pcap_pkthdr
*h
, const u_char
*p
)
2515 ndo
->ndo_protocol
= "802.15.4_tap";
2516 if (h
->caplen
< 4) {
2517 nd_print_trunc(ndo
);
2518 ndo
->ndo_ll_hdr_len
+= h
->caplen
;
2522 version
= GET_U_1(p
);
2523 length
= GET_LE_U_2(p
+ 2);
2524 if (version
!= 0 || length
< 4) {
2525 nd_print_invalid(ndo
);
2529 if (h
->caplen
< length
) {
2530 nd_print_trunc(ndo
);
2531 ndo
->ndo_ll_hdr_len
+= h
->caplen
;
2535 ndo
->ndo_ll_hdr_len
+= ieee802_15_4_print(ndo
, p
+length
, h
->caplen
-length
) + length
;