1 /* packet-pcap_pktdata.c
2 * Dissect packet data from a pcap or pcapng file or from a "remote pcap"
5 * Copyright 2015, Michal Labedzki for Tieto Corporation
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include <epan/packet.h>
17 #include <epan/expert.h>
19 #include <wiretap/pcap-encap.h>
21 #include "packet-pcap_pktdata.h"
23 void proto_register_pcap_pktdata(void);
24 void proto_reg_handoff_pcap_pktdata(void);
26 static int proto_pcap_pktdata
;
28 static int hf_pcap_pktdata_pseudoheader
;
29 static int hf_pcap_pktdata_pseudoheader_bluetooth_direction
;
30 static int hf_pcap_pktdata_undecoded_data
;
32 static int ett_pcap_pktdata_pseudoheader
;
34 static expert_field ei_pcap_pktdata_linktype_unknown
;
35 static expert_field ei_pcap_pktdata_cant_generate_phdr
;
37 static dissector_table_t wtap_encap_table
;
40 * Link-layer header type values.
42 * Includes both the official documented values from
44 * http://www.tcpdump.org/linktypes.html
46 * and values not listed there. The names are, in most cases, the
47 * LINKTYPE_ names with LINKTYPE_ stripped off.
49 const value_string link_type_vals
[] = {
52 { 2, "EXP_ETHERNET" }, /* 3Mb experimental Ethernet */
54 { 4, "PRONET" }, /* Proteon PRONET */
55 { 5, "CHAOS" }, /* MIT Chaosnet */
61 { 32, "REDBACK" }, /* Redback SmartEdge 400/800 */
64 { 99, "SYMANTEC_FIREWALL" },
65 { 100, "ATM_RFC1483" },
67 { 102, "BSD/OS SLIP" },
68 { 103, "BSD/OS PPP" },
70 { 105, "IEEE802_11" },
71 { 106, "LINUX_ATM_CLIP" },
75 { 110, "LANE8023" }, /* ATM LANE + 802.3 */
76 { 111, "HIPPI" }, /* NetBSD HIPPI */
77 { 112, "HDLC" }, /* NetBSD HDLC framing */
80 { 115, "ECONET" }, /* Acorn Econet */
81 { 116, "IPFILTER" }, /* Reserved for use with OpenBSD ipfilter */
83 { 118, "CISCO_IOS" }, /* for Cisco-internal use */
84 { 119, "IEEE802_11_PRISM" },
85 { 120, "IEEE802_11_AIRONET" }, /* 802.11 plus FreeBSD Aironet drive metadata header */
86 { 121, "HHDLC" }, /* reserved for Siemens HiPath HDLC - never used */
87 { 122, "IP_OVER_FC" },
89 { 124, "RIO" }, /* Private use for RapidIO */
90 { 125, "PCI_EXP" }, /* Private use for PCI Express */
91 { 126, "AURORA" }, /* Xilinx Aurora link layer */
92 { 127, "IEEE802_11_RADIOTAP" },
93 { 128, "TZSP" }, /* reserved for TZSP encapsulation - never used */
94 { 129, "ARCNET_LINUX" },
95 { 130, "JUNIPER_MLPPP" }, /* Juniper-private, but handled by tcpdump and Wireshark */
96 { 131, "JUNIPER_MLFR" }, /* Juniper-private, but handled by tcpdump and Wireshark */
97 { 132, "JUNIPER_ES" }, /* Juniper-private, but handled by tcpdump */
98 { 133, "JUNIPER_GGSN" }, /* Juniper-private, but handled by tcpdump and Wireshark */
99 { 134, "JUNIPER_MFR" }, /* Juniper-private, but handled by tcpdump and Wireshark */
100 { 135, "JUNIPER_ATM2" }, /* Juniper-private, but handled by tcpdump and Wireshark */
101 { 136, "JUNIPER_SVCS" }, /* Juniper-private, but handled by tcpdump and Wireshark */
102 { 137, "JUNIPER_ATM1" }, /* Juniper-private, but handled by tcpdump and Wireshark */
103 { 138, "APPLE_IP_OVER_IEEE1394" },
104 { 139, "MTP2_WITH_PHDR" },
109 { 144, "LINUX_IRDA" },
110 { 145, "IBM_SP" }, /* Reserved for IBM SP switch */
111 { 146, "IBM_SN" }, /* Reserved for IBM Next Federation switch */
128 { 163, "IEEE802_11_AVS" },
129 { 164, "JUNIPER_MONITOR" }, /* Juniper-private, but handled by tcpdump */
130 { 165, "BACNET_MS_TP" },
132 { 167, "JUNIPER_PPPOE" }, /* Juniper-private, but handled by tcpdump and Wireshark */
133 { 168, "JUNIPER_PPPOE_ATM" }, /* Juniper-private, but handled by tcpdump */
135 { 170, "GPF_T" }, /* GPF-T (ITU-T G.7041/Y.1303) */
136 { 171, "GPF_F" }, /* GPF-F (ITU-T G.7041/Y.1303) */
137 { 172, "GCOM_TIE1" }, /* Reserved for Gcom's T1/E1 line monitoring equipment */
138 { 173, "GCOM_SERIAL" }, /* Reserved for Gcom's T1/E1 line monitoring equipment */
139 { 174, "JUNIPER_PIC_PEER" }, /* Juniper-private */
140 { 175, "ERF_ETH" }, /* ERF header followed by Ethernet */
141 { 176, "ERF_POS" }, /* ERF header followed by Packet-over-SONET */
142 { 177, "LINUX_LAPD" },
143 { 178, "JUNIPER_ETHER" }, /* Juniper-private, but handled by tcpdump and Wireshark */
144 { 179, "JUNIPER_PPP" }, /* Juniper-private, but handled by tcpdump and Wireshark */
145 { 180, "JUNIPER_FRELAY" }, /* Juniper-private, but handled by tcpdump and Wireshark */
146 { 181, "JUNIPER_CHDLC" }, /* Juniper-private, but handled by tcpdump and Wireshark */
147 { 182, "MFR" }, /* Multi Link Frame Relay (FRF.16) */
148 { 183, "JUNIPER_VP" }, /* Juniper-private, but handled by tcpdump and Wireshark */
149 { 184, "A429" }, /* Arinc 429 frames */
150 { 185, "A653_ICM" }, /* Aricn 653 Interpartition Communication messages */
151 { 186, "USB" }, /* Older USB header */
152 { 187, "BLUETOOTH_HCI_H4" },
153 { 188, "IEEE802_16_MAC_CPS" }, /* IEEE 802.16 MAC Common Part Sublayer */
154 { 189, "USB_LINUX" },
155 { 190, "CAN20B" }, /* CAN v2.0B packets */
156 { 191, "IEEE802_15_4_LINUX" }, /* IEEE 802.15.4, with address fields padded, as is done by Linux drivers */
158 { 193, "IEEE802_16_MAC_CPS_RADIO" }, /* 802.16 MAC Common Part Sublayer plus a radiotap radio header */
159 { 194, "JUNIPER_ISM" }, /* Juniper-private */
160 { 195, "IEEE802_15_4" },
163 { 198, "RAIF1" }, /* Special header prepended to Ethernet packets when capturing from a u10 Networks board */
164 { 199, "IPMB" }, /* IPMB packet for IPMI */
165 { 200, "JUNIPER_ST" }, /* Juniper-private */
166 { 201, "BLUETOOTH_HCI_H4_WITH_PHDR" },
167 { 202, "AX25_KISS" },
169 { 204, "PPP_WITH_DIR" },
170 { 205, "C_HDLC_WITH_DIR" },
171 { 206, "FRELAY_WITH_DIR" },
172 { 207, "LAPB_WITH_DIR" }, /* LAPB with direction pseudo-header */
173 { 209, "I2C_LINUX" },
174 { 210, "FLEXRAY" }, /* FlexRay automotive bus */
175 { 211, "MOST" }, /* Media Oriented Systems Transport */
176 { 212, "LIN" }, /* Local Interconnect Network */
177 { 213, "X2E_SERIAL" }, /* X2E-private for serial line capture */
178 { 214, "X2E_XORAYA" }, /* X2E-private for Xoraya data logger family */
179 { 215, "IEEE802_15_4_NONASK_PHY" },
180 { 216, "LINUX_EVDEV" }, /* Linux evdev messages */
181 { 217, "GSMTAP_UM" }, /* "gsmtap" header followed by GSM Um interface packets */
182 { 218, "GSMTAP_Abis" }, /* "gsmtap" header followed by GSM Abis interface packets */
183 { 219, "MPLS" }, /* MPLS label (stack?) as the link-layer header */
184 { 220, "USB_LINUX_MMAPPED" },
185 { 221, "DECT" }, /* DECT packets, with a pseudo-header */
186 { 222, "AOS" }, /* AOS Space Data Link Protocol */
187 { 223, "WIHART" }, /* Wireless HART */
189 { 225, "FC_2_WITH_FRAME_DELIMS" },
191 { 227, "CAN_SOCKETCAN" },
194 { 230, "IEEE802_15_4_NOFCS" },
196 { 232, "JUNIPER_VS" }, /* Juniper-private */
197 { 233, "JUNIPER_SRX_E2E" }, /* Juniper-private */
198 { 234, "JUNIPER_FIBRECHANNEL" }, /* Juniper-private */
201 { 237, "STANAG_5066_D_PDU" },
202 { 238, "JUNIPER_ATM_CEMIC" }, /* Juniper-private */
204 { 240, "NETANALYZER" },
205 { 241, "NETANALYZER_TRANSPARENT" },
207 { 243, "MPEG_2_TS" },
211 { 247, "INFINIBAND" },
214 { 250, "RTAC_SERIAL" },
215 { 251, "BLUETOOTH_LE_LL" },
216 { 252, "WIRESHARK_UPPER_PDU" }, /* Upper-layer protocol saves from Wireshark */
218 { 254, "BLUETOOTH_LINUX_MONITOR" },
219 { 255, "BLUETOOTH_BREDR_BB" },
220 { 256, "BLUETOOTH_LE_LL_WITH_PHDR" },
221 { 257, "PROFIBUS_DL" },
224 { 260, "IPMI_HPM_2" },
225 { 261, "ZWAVE_R1_R2" },
227 { 263, "WATTSTOPPER_DLM" },
228 { 264, "ISO_14443" },
230 { 266, "USB_DARWIN" },
233 { 269, "TI_LLN_SNIFFER" },
236 { 272, "NORDIC_BLE" },
237 { 273, "DOCSIS31_XRA31" },
238 { 274, "ETHERNET_MPACKET" },
239 { 275, "DISPLAYPORT_AUX" },
240 { 276, "LINUX_SLL2" },
241 { 277, "SERCOS_MONITOR" },
242 { 278, "OPENVIZSLA" },
244 { 280, "VPP_DISPATCH" },
245 { 281, "DSA_TAG_BRCM" },
246 { 282, "DSA_TAG_BRCM_PREPEND" },
247 { 283, "IEEE802_15_4_TAP" },
248 { 284, "DSA_TAG_DSA" },
249 { 285, "DSA_TAG_EDSA" },
254 { 291, "NETANALYZER_NG" },
255 { 292, "ZBOSS_NCP" },
256 { 293, "USB_2_0_LOW_SPEED" },
257 { 294, "USB_2_0_FULL_SPEED" },
258 { 295, "USB_2_0_HIGH_SPEED" },
259 { 296, "AUERSWALD_LOG" },
260 { 297, "ZWAVE_TAP" },
261 { 298, "SILABS_DEBUG_CHANNEL" },
268 static const value_string pseudoheader_bluetooth_direction_vals
[] = {
275 dissect_pcap_pktdata(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
280 proto_item
*pseudoheader_item
;
281 proto_tree
*pseudoheader_tree
= NULL
;
282 proto_item
*packet_item
;
286 DISSECTOR_ASSERT(data
);
288 link_type
= (uint32_t *) data
;
291 * We're passed a pointer to a LINKTYPE_ value.
292 * Find the Wiretap encapsulation for that value.
294 pinfo
->rec
->rec_header
.packet_header
.pkt_encap
= wtap_pcap_encap_to_wtap_encap(*link_type
);
297 * Do we know that type?
299 if (pinfo
->rec
->rec_header
.packet_header
.pkt_encap
== WTAP_ENCAP_UNKNOWN
) {
302 * Just report that and give up.
304 packet_item
= proto_tree_add_item(tree
, hf_pcap_pktdata_undecoded_data
, tvb
, offset
, tvb_reported_length(tvb
), ENC_NA
);
305 expert_add_info_format(pinfo
, packet_item
,
306 &ei_pcap_pktdata_linktype_unknown
,
307 "Link-layer header type %u is not supported",
309 return tvb_captured_length(tvb
);
313 * You can't just call an arbitrary subdissector based on a
314 * WTAP_ENCAP_ value, because they may expect a particular
315 * pseudo-header to be passed to them, and may not accept
316 * a null pseudo-header pointer.
318 * First, check whether this WTAP_ENCAP_ value corresponds
319 * to a link-layer header type where Wiretap generates a
320 * pseudo-header from the bytes at the beginning of the
323 if (wtap_encap_requires_phdr(pinfo
->rec
->rec_header
.packet_header
.pkt_encap
)) {
325 * It does. Do we have code to do that?
327 switch (pinfo
->rec
->rec_header
.packet_header
.pkt_encap
) {
329 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR
:
330 pseudoheader_item
= proto_tree_add_item(tree
, hf_pcap_pktdata_pseudoheader
, tvb
, offset
, 4, ENC_NA
);
331 pseudoheader_tree
= proto_item_add_subtree(pseudoheader_item
, ett_pcap_pktdata_pseudoheader
);
332 proto_tree_add_item(pseudoheader_tree
, hf_pcap_pktdata_pseudoheader_bluetooth_direction
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
333 if (tvb_get_uint32(tvb
, offset
, ENC_BIG_ENDIAN
) == 0)
334 pinfo
->p2p_dir
= P2P_DIR_SENT
;
335 else if (tvb_get_uint32(tvb
, offset
, ENC_BIG_ENDIAN
) == 1)
336 pinfo
->p2p_dir
= P2P_DIR_RECV
;
338 pinfo
->p2p_dir
= P2P_DIR_UNKNOWN
;
343 case WTAP_ENCAP_ATM_PDUS
:
345 case WTAP_ENCAP_IRDA
:
347 case WTAP_ENCAP_MTP2_WITH_PHDR
:
348 /* TODO no description for pseudoheader at http://www.tcpdump.org/linktypes.html */
349 case WTAP_ENCAP_LINUX_LAPD
:
351 case WTAP_ENCAP_SITA
:
353 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR
:
355 case WTAP_ENCAP_NFC_LLCP
:
357 case WTAP_ENCAP_PPP_WITH_PHDR
:
360 /* TODO no description for pseudoheader at http://www.tcpdump.org/linktypes.html */
361 case WTAP_ENCAP_I2C_LINUX
:
367 packet_item
= proto_tree_add_item(tree
, hf_pcap_pktdata_undecoded_data
, tvb
, offset
, tvb_reported_length(tvb
), ENC_NA
);
368 expert_add_info_format(pinfo
, packet_item
,
369 &ei_pcap_pktdata_cant_generate_phdr
,
370 "No pseudo-header can be generated for link-layer header type %u",
372 return tvb_captured_length(tvb
);
376 * These also require a pseudo-header, but it's not constructed
379 switch (pinfo
->rec
->rec_header
.packet_header
.pkt_encap
) {
381 case WTAP_ENCAP_ETHERNET
:
382 eth
.fcs_len
= -1; /* Unknown whether we have an FCS */
392 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
394 offset
= dissector_try_uint_with_data(wtap_encap_table
, pinfo
->rec
->rec_header
.packet_header
.pkt_encap
, next_tvb
, pinfo
, tree
, true, phdr
);
400 proto_register_pcap_pktdata(void)
402 static hf_register_info hf
[] = {
403 { &hf_pcap_pktdata_pseudoheader
,
404 { "Pseudoheader", "pcap_pktdata.data.pseudoheader",
405 FT_NONE
, BASE_NONE
, NULL
, 0x00,
408 { &hf_pcap_pktdata_pseudoheader_bluetooth_direction
,
409 { "Direction", "pcap_pktdata.pseudoheader.bluetooth.direction",
410 FT_UINT32
, BASE_HEX
, VALS(pseudoheader_bluetooth_direction_vals
), 0x00,
413 { &hf_pcap_pktdata_undecoded_data
,
414 { "Undecoded data", "pcap_pktdata.undecoded_data",
415 FT_NONE
, BASE_NONE
, NULL
, 0x00,
420 static int *ett
[] = {
421 &ett_pcap_pktdata_pseudoheader
,
424 static ei_register_info ei
[] = {
425 { &ei_pcap_pktdata_linktype_unknown
, { "pcap_pktdata.linktype_unknown", PI_UNDECODED
, PI_NOTE
, "That link-layer header type is not supported", EXPFILL
}},
426 { &ei_pcap_pktdata_cant_generate_phdr
, { "pcap_pktdata.cant_generate_phdr", PI_UNDECODED
, PI_NOTE
, "No pseudo-header can be generated for that link-layer header type", EXPFILL
}},
429 expert_module_t
*expert_pcap_pktdata
;
431 proto_pcap_pktdata
= proto_register_protocol("pcap/pcapng packet data", "pcap_pktdata", "pcap_pktdata");
432 proto_register_field_array(proto_pcap_pktdata
, hf
, array_length(hf
));
433 proto_register_subtree_array(ett
, array_length(ett
));
434 expert_pcap_pktdata
= expert_register_protocol(proto_pcap_pktdata
);
435 expert_register_field_array(expert_pcap_pktdata
, ei
, array_length(ei
));
437 register_dissector("pcap_pktdata", dissect_pcap_pktdata
, proto_pcap_pktdata
);
441 proto_reg_handoff_pcap_pktdata(void)
443 wtap_encap_table
= find_dissector_table("wtap_encap");