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