2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
27 #include <netdissect-stdinc.h>
29 #include "netdissect.h"
33 /* From wireshark packet-zep.c:
35 ***********************************************************************
37 * ZEP Packets must be received in the following format:
39 * |UDP Header| ZEP Header |IEEE 802.15.4 Packet|
40 * | 8 bytes | 16/32 bytes | <= 127 bytes |
42 ***********************************************************************
44 * ZEP v1 Header will have the following format:
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|
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 |
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 *------------------------------------------------------------
59 #define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */
60 #define JAN_1970 2208988800U
63 static void zep_print_ts(netdissect_options
*ndo
, const u_char
*p
)
70 i
= EXTRACT_32BITS(p
);
71 uf
= EXTRACT_32BITS(p
+ 4);
73 if (ff
< 0.0) /* some compilers are buggy */
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
));
81 * print the time in human-readable format.
84 time_t seconds
= i
- JAN_1970
;
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
));
96 * Main function to print packets.
100 zep_print(netdissect_options
*ndo
,
101 const u_char
*bp
, u_int len
)
103 uint8_t version
, inner_len
;
106 ND_PRINT((ndo
, "ZEP"));
110 if (*bp
!= 'E' || *(bp
+1) != 'X') goto trunc
;
113 ND_PRINT((ndo
, "v%d ", version
));
118 ND_PRINT((ndo
, "Channel ID %d, Device ID 0x%04x, ",
119 *(bp
+ 3), EXTRACT_16BITS(bp
+ 4)));
121 ND_PRINT((ndo
, "CRC, "));
123 ND_PRINT((ndo
, "LQI %d, ", *(bp
+ 7)));
124 inner_len
= *(bp
+ 15);
125 ND_PRINT((ndo
, "inner len = %d", inner_len
));
131 if (*(bp
+ 3) == 2) {
133 seq_no
= EXTRACT_32BITS(bp
+ 4);
134 ND_PRINT((ndo
, "ACK, seq# = %d", seq_no
));
139 /* ZEP v2 data, or some other. */
142 ND_PRINT((ndo
, "Type %d, Channel ID %d, Device ID 0x%04x, ",
143 *(bp
+ 3), *(bp
+ 4), EXTRACT_16BITS(bp
+ 5)));
145 ND_PRINT((ndo
, "CRC, "));
147 ND_PRINT((ndo
, "LQI %d, ", *(bp
+ 8)));
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
));
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
)) {
167 if (!ndo
->ndo_suppress_default_print
)
168 ND_DEFAULTPRINT(bp
, len
);
172 ND_PRINT((ndo
, " [|ZEP]"));