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 static const char *ftypes
[] = {
41 "Reserved (0x4)", /* 4 */
42 "Reserved (0x5)", /* 5 */
43 "Reserved (0x6)", /* 6 */
44 "Reserved (0x7)", /* 7 */
48 * Frame Control subfields.
50 #define FC_FRAME_TYPE(fc) ((fc) & 0x7)
51 #define FC_SECURITY_ENABLED 0x0008
52 #define FC_FRAME_PENDING 0x0010
53 #define FC_ACK_REQUEST 0x0020
54 #define FC_PAN_ID_COMPRESSION 0x0040
55 #define FC_DEST_ADDRESSING_MODE(fc) (((fc) >> 10) & 0x3)
56 #define FC_FRAME_VERSION(fc) (((fc) >> 12) & 0x3)
57 #define FC_SRC_ADDRESSING_MODE(fc) (((fc) >> 14) & 0x3)
59 #define FC_ADDRESSING_MODE_NONE 0x00
60 #define FC_ADDRESSING_MODE_RESERVED 0x01
61 #define FC_ADDRESSING_MODE_SHORT 0x02
62 #define FC_ADDRESSING_MODE_LONG 0x03
65 ieee802_15_4_print(netdissect_options
*ndo
,
66 const u_char
*p
, u_int caplen
)
74 ND_PRINT("[|802.15.4]");
79 fc
= EXTRACT_LE_U_2(p
);
80 seq
= EXTRACT_U_1(p
+ 2);
85 ND_PRINT("IEEE 802.15.4 %s packet ", ftypes
[FC_FRAME_TYPE(fc
)]);
87 ND_PRINT("seq %02x ", seq
);
90 * Destination address and PAN ID, if present.
92 switch (FC_DEST_ADDRESSING_MODE(fc
)) {
93 case FC_ADDRESSING_MODE_NONE
:
94 if (fc
& FC_PAN_ID_COMPRESSION
) {
96 * PAN ID compression; this requires that both
97 * the source and destination addresses be present,
98 * but the destination address is missing.
100 ND_PRINT("[|802.15.4]");
106 case FC_ADDRESSING_MODE_RESERVED
:
108 ND_PRINT("reserved destination addressing mode");
110 case FC_ADDRESSING_MODE_SHORT
:
112 ND_PRINT("[|802.15.4]");
115 panid
= EXTRACT_LE_U_2(p
);
120 ND_PRINT("[|802.15.4]");
124 ND_PRINT("%04x:%04x ", panid
, EXTRACT_LE_U_2(p
));
129 case FC_ADDRESSING_MODE_LONG
:
131 ND_PRINT("[|802.15.4]");
134 panid
= EXTRACT_LE_U_2(p
);
139 ND_PRINT("[|802.15.4]");
143 ND_PRINT("%04x:%s ", panid
, le64addr_string(ndo
, p
));
153 * Source address and PAN ID, if present.
155 switch (FC_SRC_ADDRESSING_MODE(fc
)) {
156 case FC_ADDRESSING_MODE_NONE
:
160 case FC_ADDRESSING_MODE_RESERVED
:
162 ND_PRINT("reserved source addressing mode");
164 case FC_ADDRESSING_MODE_SHORT
:
165 if (!(fc
& FC_PAN_ID_COMPRESSION
)) {
167 * The source PAN ID is not compressed out, so
168 * fetch it. (Otherwise, we'll use the destination
169 * PAN ID, fetched above.)
172 ND_PRINT("[|802.15.4]");
175 panid
= EXTRACT_LE_U_2(p
);
181 ND_PRINT("[|802.15.4]");
185 ND_PRINT("%04x:%04x ", panid
, EXTRACT_LE_U_2(p
));
190 case FC_ADDRESSING_MODE_LONG
:
191 if (!(fc
& FC_PAN_ID_COMPRESSION
)) {
193 * The source PAN ID is not compressed out, so
194 * fetch it. (Otherwise, we'll use the destination
195 * PAN ID, fetched above.)
198 ND_PRINT("[|802.15.4]");
201 panid
= EXTRACT_LE_U_2(p
);
207 ND_PRINT("[|802.15.4]");
211 ND_PRINT("%04x:%s ", panid
, le64addr_string(ndo
, p
));
218 if (!ndo
->ndo_suppress_default_print
)
219 ND_DEFAULTPRINT(p
, caplen
);
224 /* For DLT_IEEE802_15_4 and DLT_IEEE802_15_4_NOFCS */
226 ieee802_15_4_if_print(netdissect_options
*ndo
,
227 const struct pcap_pkthdr
*h
, const u_char
*p
)
229 return ieee802_15_4_print(ndo
, p
, h
->caplen
);