HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / epan / dissectors / packet-mpeg-pmt.c
1 /* packet-mpeg-pmt.c
2  * Routines for MPEG2 (ISO/ISO 13818-1) Program Map Table (PMT) dissection
3  * Copyright 2012, Guy Martin <gmsoft@tuxicoman.be>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "config.h"
13
14 #include <epan/packet.h>
15 #include "packet-mpeg-sect.h"
16 #include "packet-mpeg-descriptor.h"
17
18 void proto_register_mpeg_pmt(void);
19 void proto_reg_handoff_mpeg_pmt(void);
20
21 static int proto_mpeg_pmt = -1;
22 static int hf_mpeg_pmt_program_number = -1;
23 static int hf_mpeg_pmt_reserved1 = -1;
24 static int hf_mpeg_pmt_version_number = -1;
25 static int hf_mpeg_pmt_current_next_indicator = -1;
26 static int hf_mpeg_pmt_section_number = -1;
27 static int hf_mpeg_pmt_last_section_number = -1;
28 static int hf_mpeg_pmt_reserved2 = -1;
29 static int hf_mpeg_pmt_pcr_pid = -1;
30 static int hf_mpeg_pmt_reserved3 = -1;
31 static int hf_mpeg_pmt_program_info_length = -1;
32
33
34 static int hf_mpeg_pmt_stream_type = -1;
35 static int hf_mpeg_pmt_stream_reserved1 = -1;
36 static int hf_mpeg_pmt_stream_elementary_pid = -1;
37 static int hf_mpeg_pmt_stream_reserved2 = -1;
38 static int hf_mpeg_pmt_stream_es_info_length = -1;
39
40 static gint ett_mpeg_pmt = -1;
41 static gint ett_mpeg_pmt_stream = -1;
42
43 static dissector_handle_t mpeg_pmt_handle;
44
45 #define MPEG_PMT_RESERVED1_MASK                   0xC0
46 #define MPEG_PMT_VERSION_NUMBER_MASK              0x3E
47 #define MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK      0x01
48
49 #define MPEG_PMT_RESERVED2_MASK                 0xE000
50 #define MPEG_PMT_PCR_PID_MASK                   0x1FFF
51 #define MPEG_PMT_RESERVED3_MASK                 0xF000
52 #define MPEG_PMT_PROGRAM_INFO_LENGTH_MASK       0x0FFF
53
54 #define MPEG_PMT_STREAM_RESERVED1_MASK          0xE000
55 #define MPEG_PMT_STREAM_ELEMENTARY_PID_MASK     0x1FFF
56
57 #define MPEG_PMT_STREAM_RESERVED2_MASK          0xF000
58 #define MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK     0x0FFF
59
60
61 static const value_string mpeg_pmt_cur_next_vals[] = {
62
63     { 0x0, "Not yet applicable" },
64     { 0x1, "Currently applicable" },
65
66     { 0x0, NULL }
67
68 };
69
70 static const value_string mpeg_pmt_stream_type_vals[] = {
71     { 0x00, "ITU-T | ISO/IEC Reserved" },
72     { 0x01, "ISO/IEC 11172 Video" },
73     { 0x02, "ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream" },
74     { 0x03, "ISO/IEC 11172 Audio" },
75     { 0x04, "ISO/IEC 13818-3 Audio" },
76     { 0x05, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections" },
77     { 0x06, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data" },
78     { 0x07, "ISO/IEC 13522 MHEG" },
79     { 0x08, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC" },
80     { 0x09, "ITU-T Rec. H.222.1" },
81     { 0x0A, "ISO/IEC 13818-6 type A" },
82     { 0x0B, "ISO/IEC 13818-6 type B" },
83     { 0x0C, "ISO/IEC 13818-6 type C" },
84     { 0x0D, "ISO/IEC 13818-6 type D" },
85     { 0x0E, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 auxiliary" },
86     { 0x0F, "ISO/IEC 13818-7 Audio with ADTS transport syntax" },
87     { 0x10, "ISO/IEC 14496-2 Visual" },
88     { 0x11, "ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3 / AMD 1" },
89     { 0x12, "ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets" },
90     { 0x13, "ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC14496_sections" },
91     { 0x14, "ISO/IEC 13818-6 Synchronized Download Protocol" },
92     { 0x15, "Metadata carried in PES packets" },
93     { 0x16, "Metadata carried in metadata sections" },
94     { 0x17, "Metadata carried in ISO/IEC 13818-6 Data Carousel" },
95     { 0x18, "Metadata carried in ISO/IEC 13818-6 Object Carousel" },
96     { 0x19, "Metadata carried in ISO/IEC 13818-6 Synchronized Download Protocol" },
97     { 0x1A, "IPMP stream (defined in ISO/IEC 13818-11, MPEG-2 IPMP)" },
98     { 0x1B, "AVC video stream as defined in ITU-T Rec. H.264 | ISO/IEC 14496-10 Video" },
99     { 0x24, "ITU-T Rec. H.265 and ISO/IEC 23008-2 (Ultra HD video) in a packetized stream" },
100     { 0x7F, "IPMP stream" },
101     { 0x81, "ATSC A/52 Audio" },
102     { 0x86, "SCTE-35 Splice Information" },
103     { 0xA1, "ETV-AM BIF Data Stream" },
104     { 0xC0, "ETV-AM EISS Signaling" },
105     { 0x00, NULL }
106 };
107 value_string_ext mpeg_pmt_stream_type_vals_ext = VALUE_STRING_EXT_INIT(mpeg_pmt_stream_type_vals);
108
109 static int
110 dissect_mpeg_pmt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
111 {
112
113     guint   offset = 0, length = 0;
114     guint   prog_info_len, es_info_len;
115     guint16 pid;
116
117     proto_item *ti;
118     proto_tree *mpeg_pmt_tree;
119     proto_tree *mpeg_pmt_stream_tree;
120
121     /* The TVB should start right after the section_length in the Section packet */
122
123     col_set_str(pinfo->cinfo, COL_INFO, "Program Map Table (PMT)");
124
125     ti = proto_tree_add_item(tree, proto_mpeg_pmt, tvb, offset, -1, ENC_NA);
126     mpeg_pmt_tree = proto_item_add_subtree(ti, ett_mpeg_pmt);
127
128     offset += packet_mpeg_sect_header(tvb, offset, mpeg_pmt_tree, &length, NULL);
129     length -= 4;
130
131     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_program_number, tvb, offset, 2, ENC_BIG_ENDIAN);
132     offset += 2;
133
134     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved1, tvb, offset, 1, ENC_BIG_ENDIAN);
135     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_version_number, tvb, offset, 1, ENC_BIG_ENDIAN);
136     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_current_next_indicator, tvb, offset, 1, ENC_BIG_ENDIAN);
137     offset += 1;
138
139     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
140     offset += 1;
141
142     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
143     offset += 1;
144
145     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved2, tvb, offset, 2, ENC_BIG_ENDIAN);
146     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_pcr_pid, tvb, offset, 2, ENC_BIG_ENDIAN);
147     offset += 2;
148
149     prog_info_len = tvb_get_ntohs(tvb, offset) & MPEG_PMT_PROGRAM_INFO_LENGTH_MASK;
150     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved3, tvb, offset, 2, ENC_BIG_ENDIAN);
151     proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_program_info_length, tvb, offset, 2, ENC_BIG_ENDIAN);
152     offset += 2;
153
154     offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, prog_info_len, mpeg_pmt_tree);
155
156     while (offset < length) {
157
158         pid = tvb_get_ntohs(tvb, offset + 1) & MPEG_PMT_STREAM_ELEMENTARY_PID_MASK;
159         es_info_len = tvb_get_ntohs(tvb, offset + 3) & MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK;
160
161         mpeg_pmt_stream_tree = proto_tree_add_subtree_format(mpeg_pmt_tree, tvb, offset, 5 + es_info_len,
162                             ett_mpeg_pmt_stream, NULL, "Stream PID=0x%04hx", pid);
163
164         proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_type,      tvb, offset, 1, ENC_BIG_ENDIAN);
165         offset += 1;
166
167         proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_reserved1,     tvb, offset, 2, ENC_BIG_ENDIAN);
168         proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_elementary_pid,    tvb, offset, 2, ENC_BIG_ENDIAN);
169         offset += 2;
170
171         proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_reserved2,     tvb, offset, 2, ENC_BIG_ENDIAN);
172         proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_es_info_length,    tvb, offset, 2, ENC_BIG_ENDIAN);
173         offset += 2;
174
175         offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, es_info_len, mpeg_pmt_stream_tree);
176     }
177
178     offset += packet_mpeg_sect_crc(tvb, pinfo, mpeg_pmt_tree, 0, offset);
179
180     proto_item_set_len(ti, offset);
181     return offset;
182 }
183
184
185 void
186 proto_register_mpeg_pmt(void)
187 {
188
189     static hf_register_info hf[] = {
190
191         { &hf_mpeg_pmt_program_number, {
192             "Program Number", "mpeg_pmt.pg_num",
193             FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
194         } },
195
196         { &hf_mpeg_pmt_reserved1, {
197             "Reserved", "mpeg_pmt.reserved1",
198             FT_UINT8, BASE_HEX, NULL, MPEG_PMT_RESERVED1_MASK, NULL, HFILL
199         } },
200
201         { &hf_mpeg_pmt_version_number, {
202             "Version Number", "mpeg_pmt.version",
203             FT_UINT8, BASE_HEX, NULL, MPEG_PMT_VERSION_NUMBER_MASK, NULL, HFILL
204         } },
205
206         { &hf_mpeg_pmt_current_next_indicator, {
207             "Current/Next Indicator", "mpeg_pmt.cur_next_ind",
208             FT_UINT8, BASE_HEX, VALS(mpeg_pmt_cur_next_vals), MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
209         } },
210
211         { &hf_mpeg_pmt_section_number, {
212             "Section Number", "mpeg_pmt.sect_num",
213             FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
214         } },
215
216         { &hf_mpeg_pmt_last_section_number, {
217             "Last Section Number", "mpeg_pmt.last_sect_num",
218             FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
219         } },
220
221         { &hf_mpeg_pmt_reserved2, {
222             "Reserved", "mpeg_pmt.reserved2",
223             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_RESERVED2_MASK, NULL, HFILL
224         } },
225
226         { &hf_mpeg_pmt_pcr_pid, {
227             "PCR PID", "mpeg_pmt.pcr_pid",
228             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_PCR_PID_MASK, NULL, HFILL
229         } },
230
231         { &hf_mpeg_pmt_reserved3, {
232             "Reserved", "mpeg_pmt.reserved3",
233             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_RESERVED3_MASK, NULL, HFILL
234         } },
235
236         { &hf_mpeg_pmt_program_info_length, {
237             "Program Info Length", "mpeg_pmt.prog_info_len",
238             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_PROGRAM_INFO_LENGTH_MASK, NULL, HFILL
239         } },
240
241
242         { &hf_mpeg_pmt_stream_type, {
243             "Stream type", "mpeg_pmt.stream.type",
244             FT_UINT8, BASE_HEX | BASE_EXT_STRING, &mpeg_pmt_stream_type_vals_ext, 0, NULL, HFILL
245         } },
246
247         { &hf_mpeg_pmt_stream_reserved1, {
248             "Reserved", "mpeg_pmt.stream.reserved1",
249             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_RESERVED1_MASK, NULL, HFILL
250         } },
251
252         { &hf_mpeg_pmt_stream_elementary_pid, {
253             "Elementary PID", "mpeg_pmt.stream.elementary_pid",
254             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_ELEMENTARY_PID_MASK, NULL, HFILL
255         } },
256
257         { &hf_mpeg_pmt_stream_reserved2, {
258             "Reserved", "mpeg_pmt.stream.reserved2",
259             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_RESERVED2_MASK, NULL, HFILL
260         } },
261
262         { &hf_mpeg_pmt_stream_es_info_length, {
263             "ES Info Length", "mpeg_pmt.stream.es_info_len",
264             FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK, NULL, HFILL
265         } },
266
267     };
268
269     static gint *ett[] = {
270         &ett_mpeg_pmt,
271         &ett_mpeg_pmt_stream,
272     };
273
274     proto_mpeg_pmt = proto_register_protocol("MPEG2 Program Map Table", "MPEG PMT", "mpeg_pmt");
275
276     proto_register_field_array(proto_mpeg_pmt, hf, array_length(hf));
277     proto_register_subtree_array(ett, array_length(ett));
278
279     mpeg_pmt_handle = register_dissector("mpeg_pmt", dissect_mpeg_pmt, proto_mpeg_pmt);
280 }
281
282
283 void
284 proto_reg_handoff_mpeg_pmt(void)
285 {
286     dissector_add_uint("mpeg_sect.tid", MPEG_PMT_TID, mpeg_pmt_handle);
287 }
288
289 /*
290  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
291  *
292  * Local variables:
293  * c-basic-offset: 4
294  * tab-width: 8
295  * indent-tabs-mode: nil
296  * End:
297  *
298  * vi: set shiftwidth=4 tabstop=8 expandtab:
299  * :indentSize=4:tabSize=8:noTabs=true:
300  */