]> The Tcpdump Group git mirrors - tcpdump/blob - print-zep.c
Fixed warnings
[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
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <netdissect-stdinc.h>
28
29 #include "netdissect.h"
30
31 #include "extract.h"
32
33 /* From wireshark packet-zep.c:
34 *
35 ***********************************************************************
36 *
37 * ZEP Packets must be received in the following format:
38 *
39 * |UDP Header| ZEP Header |IEEE 802.15.4 Packet|
40 * | 8 bytes | 16/32 bytes | <= 127 bytes |
41 *
42 ***********************************************************************
43 *
44 * ZEP v1 Header will have the following format:
45 *
46 * |Preamble|Version|Channel ID|Device ID|CRC/LQI Mode|LQI Val|Reserved|Length|
47 * |2 bytes |1 byte | 1 byte | 2 bytes | 1 byte |1 byte |7 bytes |1 byte|
48 *
49 * ZEP v2 Header will have the following format (if type=1/Data):
50 * |Prmbl|Ver |Type |ChnlID|DevID|C/L Mode|LQI|NTP TS|Seq#|Res |Len|
51 * | 2 | 1 | 1 | 1 | 2 | 1 | 1 | 8 | 4 | 10 | 1 |
52 *
53 * ZEP v2 Header will have the following format (if type=2/Ack):
54 * |Preamble|Version| Type |Sequence#|
55 * |2 bytes |1 byte |1 byte| 4 bytes |
56 *------------------------------------------------------------
57 */
58
59 #define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */
60 #define JAN_1970 2208988800U
61
62 /* Print timestamp */
63 static void zep_print_ts(netdissect_options *ndo, const u_char *p)
64 {
65 int32_t i;
66 uint32_t uf;
67 uint32_t f;
68 float ff;
69
70 i = EXTRACT_32BITS(p);
71 uf = EXTRACT_32BITS(p + 4);
72 ff = uf;
73 if (ff < 0.0) /* some compilers are buggy */
74 ff += FMAXINT;
75 ff = ff / FMAXINT; /* shift radix point by 32 bits */
76 f = ff * 1000000000.0; /* treat fraction as parts per billion */
77 ND_PRINT((ndo, "%u.%09d", i, f));
78
79 #ifdef HAVE_STRFTIME
80 /*
81 * print the time in human-readable format.
82 */
83 if (i) {
84 time_t seconds = i - JAN_1970;
85 struct tm *tm;
86 char time_buf[128];
87
88 tm = localtime(&seconds);
89 strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm);
90 ND_PRINT((ndo, " (%s)", time_buf));
91 }
92 #endif
93 }
94
95 /*
96 * Main function to print packets.
97 */
98
99 void
100 zep_print(netdissect_options *ndo,
101 const u_char *bp, u_int len)
102 {
103 uint8_t version, inner_len;
104 uint32_t seq_no;
105
106 ND_PRINT((ndo, "ZEP"));
107
108 ND_TCHECK2(*bp, 8);
109
110 if (*bp != 'E' || *(bp+1) != 'X') goto trunc;
111
112 version = *(bp + 2);
113 ND_PRINT((ndo, "v%d ", version));
114
115 if (version == 1) {
116 /* ZEP v1 packet. */
117 ND_TCHECK2(*bp, 16);
118 ND_PRINT((ndo, "Channel ID %d, Device ID 0x%04x, ",
119 *(bp + 3), EXTRACT_16BITS(bp + 4)));
120 if (*(bp + 6))
121 ND_PRINT((ndo, "CRC, "));
122 else
123 ND_PRINT((ndo, "LQI %d, ", *(bp + 7)));
124 inner_len = *(bp + 15);
125 ND_PRINT((ndo, "inner len = %d", inner_len));
126
127 bp += 16;
128 len -= 16;
129 } else {
130 /* ZEP v2 packet. */
131 if (*(bp + 3) == 2) {
132 /* ZEP v2 ack. */
133 seq_no = EXTRACT_32BITS(bp + 4);
134 ND_PRINT((ndo, "ACK, seq# = %d", seq_no));
135 inner_len = 0;
136 bp += 8;
137 len -= 8;
138 } else {
139 /* ZEP v2 data, or some other. */
140 ND_TCHECK2(*bp, 32);
141
142 ND_PRINT((ndo, "Type %d, Channel ID %d, Device ID 0x%04x, ",
143 *(bp + 3), *(bp + 4), EXTRACT_16BITS(bp + 5)));
144 if (*(bp + 7))
145 ND_PRINT((ndo, "CRC, "));
146 else
147 ND_PRINT((ndo, "LQI %d, ", *(bp + 8)));
148
149 zep_print_ts(ndo, bp + 9);
150 seq_no = EXTRACT_32BITS(bp + 17);
151 inner_len = *(bp + 31);
152 ND_PRINT((ndo, ", seq# = %d, inner len = %d", seq_no, inner_len));
153 bp += 32;
154 len -= 32;
155 }
156 }
157
158 if (inner_len != 0) {
159 /* Call 802.15.4 dissector. */
160 ND_PRINT((ndo, "\n\t"));
161 if (ieee802_15_4_print(ndo, bp, inner_len)) {
162 bp += len;
163 len = 0;
164 }
165 }
166
167 if (!ndo->ndo_suppress_default_print)
168 ND_DEFAULTPRINT(bp, len);
169
170 return;
171 trunc:
172 ND_PRINT((ndo, " [|ZEP]"));
173 }