]> The Tcpdump Group git mirrors - tcpdump/blob - print-zep.c
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / print-zep.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 /* \summary: ZigBee Encapsulation Protocol (ZEP) printer */
23
24 #include <config.h>
25
26 #include "netdissect-stdinc.h"
27
28 #define ND_LONGJMP_FROM_TCHECK
29 #include "netdissect.h"
30
31 #include "extract.h"
32
33 #include "ntp.h"
34
35 /* From wireshark packet-zep.c:
36 *
37 ***********************************************************************
38 *
39 * ZEP Packets must be received in the following format:
40 *
41 * |UDP Header| ZEP Header |IEEE 802.15.4 Packet|
42 * | 8 bytes | 16/32 bytes | <= 127 bytes |
43 *
44 ***********************************************************************
45 *
46 * ZEP v1 Header will have the following format:
47 * |Preamble|Version|Channel ID|Device ID|CRC/LQI Mode|LQI Val|Reserved|Length|
48 * |2 bytes |1 byte | 1 byte | 2 bytes | 1 byte |1 byte |7 bytes |1 byte|
49 *
50 * ZEP v2 Header will have the following format (if type=1/Data):
51 * |Prmbl|Ver |Type |ChnlID|DevID|C/L Mode|LQI|NTP TS|Seq#|Res |Len|
52 * | 2 | 1 | 1 | 1 | 2 | 1 | 1 | 8 | 4 | 10 | 1 |
53 *
54 * ZEP v2 Header will have the following format (if type=2/Ack):
55 * |Preamble|Version| Type |Sequence#|
56 * |2 bytes |1 byte |1 byte| 4 bytes |
57 *------------------------------------------------------------
58 */
59
60 /*
61 * Main function to print packets.
62 */
63
64 void
65 zep_print(netdissect_options *ndo,
66 const u_char *bp, u_int len)
67 {
68 uint8_t version, inner_len;
69 uint32_t seq_no;
70
71 ndo->ndo_protocol = "zep";
72
73 nd_print_protocol_caps(ndo);
74
75 /* Preamble Code (must be "EX") */
76 if (GET_U_1(bp) != 'E' || GET_U_1(bp + 1) != 'X') {
77 ND_PRINT(" [Preamble Code: ");
78 fn_print_char(ndo, GET_U_1(bp));
79 fn_print_char(ndo, GET_U_1(bp + 1));
80 ND_PRINT("]");
81 nd_print_invalid(ndo);
82 return;
83 }
84
85 version = GET_U_1(bp + 2);
86 ND_PRINT("v%u ", version);
87
88 if (version == 1) {
89 /* ZEP v1 packet. */
90 ND_ICHECK_U(len, <, 16);
91 ND_PRINT("Channel ID %u, Device ID 0x%04x, ",
92 GET_U_1(bp + 3), GET_BE_U_2(bp + 4));
93 if (GET_U_1(bp + 6))
94 ND_PRINT("CRC, ");
95 else
96 ND_PRINT("LQI %u, ", GET_U_1(bp + 7));
97 inner_len = GET_U_1(bp + 15);
98 ND_PRINT("inner len = %u", inner_len);
99
100 bp += 16;
101 len -= 16;
102 } else {
103 /* ZEP v2 packet. */
104 if (GET_U_1(bp + 3) == 2) {
105 /* ZEP v2 ack. */
106 ND_ICHECK_U(len, <, 8);
107 seq_no = GET_BE_U_4(bp + 4);
108 ND_PRINT("ACK, seq# = %u", seq_no);
109 inner_len = 0;
110 bp += 8;
111 len -= 8;
112 } else {
113 /* ZEP v2 data, or some other. */
114 ND_ICHECK_U(len, <, 32);
115 ND_PRINT("Type %u, Channel ID %u, Device ID 0x%04x, ",
116 GET_U_1(bp + 3), GET_U_1(bp + 4),
117 GET_BE_U_2(bp + 5));
118 if (GET_U_1(bp + 7))
119 ND_PRINT("CRC, ");
120 else
121 ND_PRINT("LQI %u, ", GET_U_1(bp + 8));
122
123 /*
124 * XXX - why a space rather than a "T"
125 * between the date and time?
126 */
127 p_ntp_time_fmt(ndo, "%Y-%m-%d %H:%M:%S",
128 (const struct l_fixedpt *)(bp + 9));
129 seq_no = GET_BE_U_4(bp + 17);
130 inner_len = GET_U_1(bp + 31);
131 ND_PRINT(", seq# = %u, inner len = %u",
132 seq_no, inner_len);
133 bp += 32;
134 len -= 32;
135 }
136 }
137
138 if (inner_len != 0) {
139 /* Call 802.15.4 dissector. */
140 ND_PRINT("\n\t");
141 if (ieee802_15_4_print(ndo, bp, inner_len)) {
142 ND_TCHECK_LEN(bp, len);
143 bp += len;
144 len = 0;
145 }
146 }
147
148 if (!ndo->ndo_suppress_default_print)
149 ND_DEFAULTPRINT(bp, len);
150 return;
151 invalid:
152 nd_print_invalid(ndo);
153 }