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.
22 /* \summary: ZigBee Encapsulation Protocol (ZEP) printer */
28 #include "netdissect-stdinc.h"
30 #include "netdissect.h"
34 /* From wireshark packet-zep.c:
36 ***********************************************************************
38 * ZEP Packets must be received in the following format:
40 * |UDP Header| ZEP Header |IEEE 802.15.4 Packet|
41 * | 8 bytes | 16/32 bytes | <= 127 bytes |
43 ***********************************************************************
45 * 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 JAN_1970 2208988800U
62 static void zep_print_ts(netdissect_options
*ndo
, const u_char
*p
)
70 uf
= GET_BE_U_4(p
+ 4);
72 if (ff
< 0.0) /* some compilers are buggy */
74 ff
= (float) (ff
/ FMAXINT
); /* shift radix point by 32 bits */
75 f
= (uint32_t) (ff
* 1000000000.0); /* treat fraction as parts per
77 ND_PRINT("%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(" (%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 ndo
->ndo_protocol
= "zep";
108 nd_print_protocol_caps(ndo
);
110 ND_TCHECK_LEN(bp
, 8);
112 /* Preamble Code (must be "EX") */
113 if (GET_U_1(bp
) != 'E' || GET_U_1(bp
+ 1) != 'X') {
114 ND_PRINT(" [Preamble Code: ");
115 fn_print_char(ndo
, GET_U_1(bp
));
116 fn_print_char(ndo
, GET_U_1(bp
+ 1));
118 nd_print_invalid(ndo
);
122 version
= GET_U_1(bp
+ 2);
123 ND_PRINT("v%u ", version
);
127 ND_TCHECK_LEN(bp
, 16);
128 ND_PRINT("Channel ID %u, Device ID 0x%04x, ",
129 GET_U_1(bp
+ 3), GET_BE_U_2(bp
+ 4));
133 ND_PRINT("LQI %u, ", GET_U_1(bp
+ 7));
134 inner_len
= GET_U_1(bp
+ 15);
135 ND_PRINT("inner len = %u", inner_len
);
141 if (GET_U_1(bp
+ 3) == 2) {
143 seq_no
= GET_BE_U_4(bp
+ 4);
144 ND_PRINT("ACK, seq# = %u", seq_no
);
149 /* ZEP v2 data, or some other. */
150 ND_TCHECK_LEN(bp
, 32);
152 ND_PRINT("Type %u, Channel ID %u, Device ID 0x%04x, ",
153 GET_U_1(bp
+ 3), GET_U_1(bp
+ 4),
158 ND_PRINT("LQI %u, ", GET_U_1(bp
+ 8));
160 zep_print_ts(ndo
, bp
+ 9);
161 seq_no
= GET_BE_U_4(bp
+ 17);
162 inner_len
= GET_U_1(bp
+ 31);
163 ND_PRINT(", seq# = %u, inner len = %u",
170 if (inner_len
!= 0) {
171 /* Call 802.15.4 dissector. */
173 if (ieee802_15_4_print(ndo
, bp
, inner_len
)) {
179 if (!ndo
->ndo_suppress_default_print
)
180 ND_DEFAULTPRINT(bp
, len
);