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