/src/wireshark/epan/dissectors/packet-mpeg-pmt.c
Line | Count | Source |
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 <epan/tfs.h> |
16 | | #include <wsutil/array.h> |
17 | | #include "packet-mp2t.h" |
18 | | #include "packet-mpeg-sect.h" |
19 | | #include "packet-mpeg-descriptor.h" |
20 | | |
21 | | void proto_register_mpeg_pmt(void); |
22 | | void proto_reg_handoff_mpeg_pmt(void); |
23 | | |
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; |
35 | | |
36 | | |
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; |
42 | | |
43 | | static int ett_mpeg_pmt; |
44 | | static int ett_mpeg_pmt_stream; |
45 | | |
46 | | static dissector_handle_t mpeg_pmt_handle; |
47 | | |
48 | 14 | #define MPEG_PMT_RESERVED1_MASK 0xC0 |
49 | 14 | #define MPEG_PMT_VERSION_NUMBER_MASK 0x3E |
50 | 14 | #define MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK 0x01 |
51 | | |
52 | 14 | #define MPEG_PMT_RESERVED2_MASK 0xE000 |
53 | 14 | #define MPEG_PMT_PCR_PID_MASK 0x1FFF |
54 | 14 | #define MPEG_PMT_RESERVED3_MASK 0xF000 |
55 | 108 | #define MPEG_PMT_PROGRAM_INFO_LENGTH_MASK 0x0FFF |
56 | | |
57 | 14 | #define MPEG_PMT_STREAM_RESERVED1_MASK 0xE000 |
58 | 128 | #define MPEG_PMT_STREAM_ELEMENTARY_PID_MASK 0x1FFF |
59 | | |
60 | 14 | #define MPEG_PMT_STREAM_RESERVED2_MASK 0xF000 |
61 | 128 | #define MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK 0x0FFF |
62 | | |
63 | | |
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" }, |
99 | | { 0x00, NULL } |
100 | | }; |
101 | | value_string_ext mpeg_pmt_stream_type_vals_ext = VALUE_STRING_EXT_INIT(mpeg_pmt_stream_type_vals); |
102 | | |
103 | | static int |
104 | | dissect_mpeg_pmt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) |
105 | 94 | { |
106 | | |
107 | 94 | unsigned offset = 0, length = 0; |
108 | 94 | unsigned prog_info_len, es_info_len; |
109 | 94 | uint32_t stream_type; |
110 | 94 | uint16_t pid; |
111 | 94 | bool current; |
112 | | |
113 | 94 | proto_item *ti; |
114 | 94 | proto_tree *mpeg_pmt_tree; |
115 | 94 | proto_tree *mpeg_pmt_stream_tree; |
116 | | |
117 | | /* The TVB should start right after the section_length in the Section packet */ |
118 | | |
119 | 94 | col_set_str(pinfo->cinfo, COL_INFO, "Program Map Table (PMT)"); |
120 | | |
121 | 94 | ti = proto_tree_add_item(tree, proto_mpeg_pmt, tvb, offset, -1, ENC_NA); |
122 | 94 | mpeg_pmt_tree = proto_item_add_subtree(ti, ett_mpeg_pmt); |
123 | | |
124 | 94 | offset += packet_mpeg_sect_header(tvb, offset, mpeg_pmt_tree, &length, NULL); |
125 | 94 | length -= 4; |
126 | | |
127 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_program_number, tvb, offset, 2, ENC_BIG_ENDIAN); |
128 | 94 | offset += 2; |
129 | | |
130 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved1, tvb, offset, 1, ENC_BIG_ENDIAN); |
131 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_version_number, tvb, offset, 1, ENC_BIG_ENDIAN); |
132 | 94 | proto_tree_add_item_ret_boolean(mpeg_pmt_tree, hf_mpeg_pmt_current_next_indicator, tvb, offset, 1, ENC_BIG_ENDIAN, ¤t); |
133 | 94 | offset += 1; |
134 | | |
135 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_section_number, tvb, offset, 1, ENC_BIG_ENDIAN); |
136 | 94 | offset += 1; |
137 | | |
138 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN); |
139 | 94 | offset += 1; |
140 | | |
141 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved2, tvb, offset, 2, ENC_BIG_ENDIAN); |
142 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_pcr_pid, tvb, offset, 2, ENC_BIG_ENDIAN); |
143 | 94 | offset += 2; |
144 | | |
145 | 94 | prog_info_len = tvb_get_ntohs(tvb, offset) & MPEG_PMT_PROGRAM_INFO_LENGTH_MASK; |
146 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved3, tvb, offset, 2, ENC_BIG_ENDIAN); |
147 | 94 | proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_program_info_length, tvb, offset, 2, ENC_BIG_ENDIAN); |
148 | 94 | offset += 2; |
149 | | |
150 | 94 | offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, prog_info_len, mpeg_pmt_tree); |
151 | | |
152 | 208 | while (offset < length) { |
153 | | |
154 | 114 | pid = tvb_get_ntohs(tvb, offset + 1) & MPEG_PMT_STREAM_ELEMENTARY_PID_MASK; |
155 | 114 | es_info_len = tvb_get_ntohs(tvb, offset + 3) & MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK; |
156 | | |
157 | 114 | mpeg_pmt_stream_tree = proto_tree_add_subtree_format(mpeg_pmt_tree, tvb, offset, 5 + es_info_len, |
158 | 114 | ett_mpeg_pmt_stream, NULL, "Stream PID=0x%04hx", pid); |
159 | | |
160 | 114 | proto_tree_add_item_ret_uint(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_type, tvb, offset, 1, ENC_BIG_ENDIAN, &stream_type); |
161 | 114 | if (current) { |
162 | 66 | mp2t_add_stream_type(pinfo, pid, stream_type); |
163 | 66 | } |
164 | 114 | offset += 1; |
165 | | |
166 | 114 | proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_reserved1, tvb, offset, 2, ENC_BIG_ENDIAN); |
167 | 114 | proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_elementary_pid, tvb, offset, 2, ENC_BIG_ENDIAN); |
168 | 114 | offset += 2; |
169 | | |
170 | 114 | proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_reserved2, tvb, offset, 2, ENC_BIG_ENDIAN); |
171 | 114 | proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_es_info_length, tvb, offset, 2, ENC_BIG_ENDIAN); |
172 | 114 | offset += 2; |
173 | | |
174 | 114 | offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, es_info_len, mpeg_pmt_stream_tree); |
175 | 114 | } |
176 | | |
177 | 94 | offset += packet_mpeg_sect_crc(tvb, pinfo, mpeg_pmt_tree, 0, offset); |
178 | | |
179 | 94 | proto_item_set_len(ti, offset); |
180 | 94 | return offset; |
181 | 94 | } |
182 | | |
183 | | |
184 | | void |
185 | | proto_register_mpeg_pmt(void) |
186 | 14 | { |
187 | | |
188 | 14 | static hf_register_info hf[] = { |
189 | | |
190 | 14 | { &hf_mpeg_pmt_program_number, { |
191 | 14 | "Program Number", "mpeg_pmt.pg_num", |
192 | 14 | FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL |
193 | 14 | } }, |
194 | | |
195 | 14 | { &hf_mpeg_pmt_reserved1, { |
196 | 14 | "Reserved", "mpeg_pmt.reserved1", |
197 | 14 | FT_UINT8, BASE_HEX, NULL, MPEG_PMT_RESERVED1_MASK, NULL, HFILL |
198 | 14 | } }, |
199 | | |
200 | 14 | { &hf_mpeg_pmt_version_number, { |
201 | 14 | "Version Number", "mpeg_pmt.version", |
202 | 14 | FT_UINT8, BASE_HEX, NULL, MPEG_PMT_VERSION_NUMBER_MASK, NULL, HFILL |
203 | 14 | } }, |
204 | | |
205 | 14 | { &hf_mpeg_pmt_current_next_indicator, { |
206 | 14 | "Current/Next Indicator", "mpeg_pmt.cur_next_ind", |
207 | 14 | FT_BOOLEAN, 8, TFS(&tfs_current_not_yet), MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL |
208 | 14 | } }, |
209 | | |
210 | 14 | { &hf_mpeg_pmt_section_number, { |
211 | 14 | "Section Number", "mpeg_pmt.sect_num", |
212 | 14 | FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL |
213 | 14 | } }, |
214 | | |
215 | 14 | { &hf_mpeg_pmt_last_section_number, { |
216 | 14 | "Last Section Number", "mpeg_pmt.last_sect_num", |
217 | 14 | FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL |
218 | 14 | } }, |
219 | | |
220 | 14 | { &hf_mpeg_pmt_reserved2, { |
221 | 14 | "Reserved", "mpeg_pmt.reserved2", |
222 | 14 | FT_UINT16, BASE_HEX, NULL, MPEG_PMT_RESERVED2_MASK, NULL, HFILL |
223 | 14 | } }, |
224 | | |
225 | 14 | { &hf_mpeg_pmt_pcr_pid, { |
226 | 14 | "PCR PID", "mpeg_pmt.pcr_pid", |
227 | 14 | FT_UINT16, BASE_HEX, NULL, MPEG_PMT_PCR_PID_MASK, NULL, HFILL |
228 | 14 | } }, |
229 | | |
230 | 14 | { &hf_mpeg_pmt_reserved3, { |
231 | 14 | "Reserved", "mpeg_pmt.reserved3", |
232 | 14 | FT_UINT16, BASE_HEX, NULL, MPEG_PMT_RESERVED3_MASK, NULL, HFILL |
233 | 14 | } }, |
234 | | |
235 | 14 | { &hf_mpeg_pmt_program_info_length, { |
236 | 14 | "Program Info Length", "mpeg_pmt.prog_info_len", |
237 | 14 | FT_UINT16, BASE_DEC, NULL, MPEG_PMT_PROGRAM_INFO_LENGTH_MASK, NULL, HFILL |
238 | 14 | } }, |
239 | | |
240 | | |
241 | 14 | { &hf_mpeg_pmt_stream_type, { |
242 | 14 | "Stream type", "mpeg_pmt.stream.type", |
243 | 14 | FT_UINT8, BASE_HEX | BASE_EXT_STRING, &mpeg_pmt_stream_type_vals_ext, 0, NULL, HFILL |
244 | 14 | } }, |
245 | | |
246 | 14 | { &hf_mpeg_pmt_stream_reserved1, { |
247 | 14 | "Reserved", "mpeg_pmt.stream.reserved1", |
248 | 14 | FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_RESERVED1_MASK, NULL, HFILL |
249 | 14 | } }, |
250 | | |
251 | 14 | { &hf_mpeg_pmt_stream_elementary_pid, { |
252 | 14 | "Elementary PID", "mpeg_pmt.stream.elementary_pid", |
253 | 14 | FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_ELEMENTARY_PID_MASK, NULL, HFILL |
254 | 14 | } }, |
255 | | |
256 | 14 | { &hf_mpeg_pmt_stream_reserved2, { |
257 | 14 | "Reserved", "mpeg_pmt.stream.reserved2", |
258 | 14 | FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_RESERVED2_MASK, NULL, HFILL |
259 | 14 | } }, |
260 | | |
261 | 14 | { &hf_mpeg_pmt_stream_es_info_length, { |
262 | 14 | "ES Info Length", "mpeg_pmt.stream.es_info_len", |
263 | 14 | FT_UINT16, BASE_DEC, NULL, MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK, NULL, HFILL |
264 | 14 | } }, |
265 | | |
266 | 14 | }; |
267 | | |
268 | 14 | static int *ett[] = { |
269 | 14 | &ett_mpeg_pmt, |
270 | 14 | &ett_mpeg_pmt_stream, |
271 | 14 | }; |
272 | | |
273 | 14 | proto_mpeg_pmt = proto_register_protocol("MPEG2 Program Map Table", "MPEG PMT", "mpeg_pmt"); |
274 | | |
275 | 14 | proto_register_field_array(proto_mpeg_pmt, hf, array_length(hf)); |
276 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
277 | | |
278 | 14 | mpeg_pmt_handle = register_dissector("mpeg_pmt", dissect_mpeg_pmt, proto_mpeg_pmt); |
279 | 14 | } |
280 | | |
281 | | |
282 | | void |
283 | | proto_reg_handoff_mpeg_pmt(void) |
284 | 14 | { |
285 | 14 | dissector_add_uint("mpeg_sect.tid", MPEG_PMT_TID, mpeg_pmt_handle); |
286 | 14 | } |
287 | | |
288 | | /* |
289 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
290 | | * |
291 | | * Local variables: |
292 | | * c-basic-offset: 4 |
293 | | * tab-width: 8 |
294 | | * indent-tabs-mode: nil |
295 | | * End: |
296 | | * |
297 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
298 | | * :indentSize=4:tabSize=8:noTabs=true: |
299 | | */ |