2 * Routines for MPEG2 (ISO/ISO 13818-1) Program Map Table (PMT) dissection
3 * Copyright 2012, Guy Martin <gmsoft@tuxicoman.be>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
16 #include <wsutil/array.h>
17 #include "packet-mp2t.h"
18 #include "packet-mpeg-sect.h"
19 #include "packet-mpeg-descriptor.h"
21 void proto_register_mpeg_pmt(void);
22 void proto_reg_handoff_mpeg_pmt(void);
24 static int proto_mpeg_pmt
;
25 static int hf_mpeg_pmt_program_number
;
26 static int hf_mpeg_pmt_reserved1
;
27 static int hf_mpeg_pmt_version_number
;
28 static int hf_mpeg_pmt_current_next_indicator
;
29 static int hf_mpeg_pmt_section_number
;
30 static int hf_mpeg_pmt_last_section_number
;
31 static int hf_mpeg_pmt_reserved2
;
32 static int hf_mpeg_pmt_pcr_pid
;
33 static int hf_mpeg_pmt_reserved3
;
34 static int hf_mpeg_pmt_program_info_length
;
37 static int hf_mpeg_pmt_stream_type
;
38 static int hf_mpeg_pmt_stream_reserved1
;
39 static int hf_mpeg_pmt_stream_elementary_pid
;
40 static int hf_mpeg_pmt_stream_reserved2
;
41 static int hf_mpeg_pmt_stream_es_info_length
;
43 static int ett_mpeg_pmt
;
44 static int ett_mpeg_pmt_stream
;
46 static dissector_handle_t mpeg_pmt_handle
;
48 #define MPEG_PMT_RESERVED1_MASK 0xC0
49 #define MPEG_PMT_VERSION_NUMBER_MASK 0x3E
50 #define MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK 0x01
52 #define MPEG_PMT_RESERVED2_MASK 0xE000
53 #define MPEG_PMT_PCR_PID_MASK 0x1FFF
54 #define MPEG_PMT_RESERVED3_MASK 0xF000
55 #define MPEG_PMT_PROGRAM_INFO_LENGTH_MASK 0x0FFF
57 #define MPEG_PMT_STREAM_RESERVED1_MASK 0xE000
58 #define MPEG_PMT_STREAM_ELEMENTARY_PID_MASK 0x1FFF
60 #define MPEG_PMT_STREAM_RESERVED2_MASK 0xF000
61 #define MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK 0x0FFF
64 static const value_string mpeg_pmt_stream_type_vals
[] = {
65 { 0x00, "ITU-T | ISO/IEC Reserved" },
66 { 0x01, "ISO/IEC 11172 Video" },
67 { 0x02, "ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream" },
68 { 0x03, "ISO/IEC 11172 Audio" },
69 { 0x04, "ISO/IEC 13818-3 Audio" },
70 { 0x05, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections" },
71 { 0x06, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data" },
72 { 0x07, "ISO/IEC 13522 MHEG" },
73 { 0x08, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC" },
74 { 0x09, "ITU-T Rec. H.222.1" },
75 { 0x0A, "ISO/IEC 13818-6 type A" },
76 { 0x0B, "ISO/IEC 13818-6 type B" },
77 { 0x0C, "ISO/IEC 13818-6 type C" },
78 { 0x0D, "ISO/IEC 13818-6 type D" },
79 { 0x0E, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 auxiliary" },
80 { 0x0F, "ISO/IEC 13818-7 Audio with ADTS transport syntax" },
81 { 0x10, "ISO/IEC 14496-2 Visual" },
82 { 0x11, "ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3 / AMD 1" },
83 { 0x12, "ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets" },
84 { 0x13, "ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC14496_sections" },
85 { 0x14, "ISO/IEC 13818-6 Synchronized Download Protocol" },
86 { 0x15, "Metadata carried in PES packets" },
87 { 0x16, "Metadata carried in metadata sections" },
88 { 0x17, "Metadata carried in ISO/IEC 13818-6 Data Carousel" },
89 { 0x18, "Metadata carried in ISO/IEC 13818-6 Object Carousel" },
90 { 0x19, "Metadata carried in ISO/IEC 13818-6 Synchronized Download Protocol" },
91 { 0x1A, "IPMP stream (defined in ISO/IEC 13818-11, MPEG-2 IPMP)" },
92 { 0x1B, "AVC video stream as defined in ITU-T Rec. H.264 | ISO/IEC 14496-10 Video" },
93 { 0x24, "ITU-T Rec. H.265 and ISO/IEC 23008-2 (Ultra HD video) in a packetized stream" },
94 { 0x7F, "IPMP stream" },
95 { 0x81, "ATSC A/52 Audio" },
96 { 0x86, "SCTE-35 Splice Information" },
97 { 0xA1, "ETV-AM BIF Data Stream" },
98 { 0xC0, "ETV-AM EISS Signaling" },
101 value_string_ext mpeg_pmt_stream_type_vals_ext
= VALUE_STRING_EXT_INIT(mpeg_pmt_stream_type_vals
);
104 dissect_mpeg_pmt(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
107 unsigned offset
= 0, length
= 0;
108 unsigned prog_info_len
, es_info_len
;
109 uint32_t stream_type
;
114 proto_tree
*mpeg_pmt_tree
;
115 proto_tree
*mpeg_pmt_stream_tree
;
117 /* The TVB should start right after the section_length in the Section packet */
119 col_set_str(pinfo
->cinfo
, COL_INFO
, "Program Map Table (PMT)");
121 ti
= proto_tree_add_item(tree
, proto_mpeg_pmt
, tvb
, offset
, -1, ENC_NA
);
122 mpeg_pmt_tree
= proto_item_add_subtree(ti
, ett_mpeg_pmt
);
124 offset
+= packet_mpeg_sect_header(tvb
, offset
, mpeg_pmt_tree
, &length
, NULL
);
127 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_program_number
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
130 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_reserved1
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
131 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_version_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
132 proto_tree_add_item_ret_boolean(mpeg_pmt_tree
, hf_mpeg_pmt_current_next_indicator
, tvb
, offset
, 1, ENC_BIG_ENDIAN
, ¤t
);
135 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_section_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
138 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_last_section_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
141 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_reserved2
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
142 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_pcr_pid
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
145 prog_info_len
= tvb_get_ntohs(tvb
, offset
) & MPEG_PMT_PROGRAM_INFO_LENGTH_MASK
;
146 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_reserved3
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
147 proto_tree_add_item(mpeg_pmt_tree
, hf_mpeg_pmt_program_info_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
150 offset
+= proto_mpeg_descriptor_loop_dissect(tvb
, offset
, prog_info_len
, mpeg_pmt_tree
);
152 while (offset
< length
) {
154 pid
= tvb_get_ntohs(tvb
, offset
+ 1) & MPEG_PMT_STREAM_ELEMENTARY_PID_MASK
;
155 es_info_len
= tvb_get_ntohs(tvb
, offset
+ 3) & MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK
;
157 mpeg_pmt_stream_tree
= proto_tree_add_subtree_format(mpeg_pmt_tree
, tvb
, offset
, 5 + es_info_len
,
158 ett_mpeg_pmt_stream
, NULL
, "Stream PID=0x%04hx", pid
);
160 proto_tree_add_item_ret_uint(mpeg_pmt_stream_tree
, hf_mpeg_pmt_stream_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
, &stream_type
);
162 mp2t_add_stream_type(pinfo
, pid
, stream_type
);
166 proto_tree_add_item(mpeg_pmt_stream_tree
, hf_mpeg_pmt_stream_reserved1
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
167 proto_tree_add_item(mpeg_pmt_stream_tree
, hf_mpeg_pmt_stream_elementary_pid
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
170 proto_tree_add_item(mpeg_pmt_stream_tree
, hf_mpeg_pmt_stream_reserved2
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
171 proto_tree_add_item(mpeg_pmt_stream_tree
, hf_mpeg_pmt_stream_es_info_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
174 offset
+= proto_mpeg_descriptor_loop_dissect(tvb
, offset
, es_info_len
, mpeg_pmt_stream_tree
);
177 offset
+= packet_mpeg_sect_crc(tvb
, pinfo
, mpeg_pmt_tree
, 0, offset
);
179 proto_item_set_len(ti
, offset
);
185 proto_register_mpeg_pmt(void)
188 static hf_register_info hf
[] = {
190 { &hf_mpeg_pmt_program_number
, {
191 "Program Number", "mpeg_pmt.pg_num",
192 FT_UINT16
, BASE_HEX
, NULL
, 0, NULL
, HFILL
195 { &hf_mpeg_pmt_reserved1
, {
196 "Reserved", "mpeg_pmt.reserved1",
197 FT_UINT8
, BASE_HEX
, NULL
, MPEG_PMT_RESERVED1_MASK
, NULL
, HFILL
200 { &hf_mpeg_pmt_version_number
, {
201 "Version Number", "mpeg_pmt.version",
202 FT_UINT8
, BASE_HEX
, NULL
, MPEG_PMT_VERSION_NUMBER_MASK
, NULL
, HFILL
205 { &hf_mpeg_pmt_current_next_indicator
, {
206 "Current/Next Indicator", "mpeg_pmt.cur_next_ind",
207 FT_BOOLEAN
, 8, TFS(&tfs_current_not_yet
), MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK
, NULL
, HFILL
210 { &hf_mpeg_pmt_section_number
, {
211 "Section Number", "mpeg_pmt.sect_num",
212 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
215 { &hf_mpeg_pmt_last_section_number
, {
216 "Last Section Number", "mpeg_pmt.last_sect_num",
217 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
220 { &hf_mpeg_pmt_reserved2
, {
221 "Reserved", "mpeg_pmt.reserved2",
222 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PMT_RESERVED2_MASK
, NULL
, HFILL
225 { &hf_mpeg_pmt_pcr_pid
, {
226 "PCR PID", "mpeg_pmt.pcr_pid",
227 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PMT_PCR_PID_MASK
, NULL
, HFILL
230 { &hf_mpeg_pmt_reserved3
, {
231 "Reserved", "mpeg_pmt.reserved3",
232 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PMT_RESERVED3_MASK
, NULL
, HFILL
235 { &hf_mpeg_pmt_program_info_length
, {
236 "Program Info Length", "mpeg_pmt.prog_info_len",
237 FT_UINT16
, BASE_DEC
, NULL
, MPEG_PMT_PROGRAM_INFO_LENGTH_MASK
, NULL
, HFILL
241 { &hf_mpeg_pmt_stream_type
, {
242 "Stream type", "mpeg_pmt.stream.type",
243 FT_UINT8
, BASE_HEX
| BASE_EXT_STRING
, &mpeg_pmt_stream_type_vals_ext
, 0, NULL
, HFILL
246 { &hf_mpeg_pmt_stream_reserved1
, {
247 "Reserved", "mpeg_pmt.stream.reserved1",
248 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PMT_STREAM_RESERVED1_MASK
, NULL
, HFILL
251 { &hf_mpeg_pmt_stream_elementary_pid
, {
252 "Elementary PID", "mpeg_pmt.stream.elementary_pid",
253 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PMT_STREAM_ELEMENTARY_PID_MASK
, NULL
, HFILL
256 { &hf_mpeg_pmt_stream_reserved2
, {
257 "Reserved", "mpeg_pmt.stream.reserved2",
258 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PMT_STREAM_RESERVED2_MASK
, NULL
, HFILL
261 { &hf_mpeg_pmt_stream_es_info_length
, {
262 "ES Info Length", "mpeg_pmt.stream.es_info_len",
263 FT_UINT16
, BASE_DEC
, NULL
, MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK
, NULL
, HFILL
268 static int *ett
[] = {
270 &ett_mpeg_pmt_stream
,
273 proto_mpeg_pmt
= proto_register_protocol("MPEG2 Program Map Table", "MPEG PMT", "mpeg_pmt");
275 proto_register_field_array(proto_mpeg_pmt
, hf
, array_length(hf
));
276 proto_register_subtree_array(ett
, array_length(ett
));
278 mpeg_pmt_handle
= register_dissector("mpeg_pmt", dissect_mpeg_pmt
, proto_mpeg_pmt
);
283 proto_reg_handoff_mpeg_pmt(void)
285 dissector_add_uint("mpeg_sect.tid", MPEG_PMT_TID
, mpeg_pmt_handle
);
289 * Editor modelines - https://www.wireshark.org/tools/modelines.html
294 * indent-tabs-mode: nil
297 * vi: set shiftwidth=4 tabstop=8 expandtab:
298 * :indentSize=4:tabSize=8:noTabs=true: