2 * Routines for MPEG2 (ISO/ISO 13818-1) Section 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>
15 #include <epan/prefs.h>
16 #include <epan/crc32-tvb.h>
17 #include <epan/expert.h>
18 #include <epan/decode_as.h>
19 #include <epan/proto_data.h>
20 #include "packet-mpeg-sect.h"
22 void proto_register_mpeg_sect(void);
24 static int proto_mpeg_sect
;
25 static int hf_mpeg_sect_table_id
;
26 static int hf_mpeg_sect_syntax_indicator
;
27 static int hf_mpeg_sect_reserved
;
28 static int hf_mpeg_sect_length
;
29 static int hf_mpeg_sect_crc
;
30 static int hf_mpeg_sect_crc_status
;
32 static int ett_mpeg_sect
;
34 static expert_field ei_mpeg_sect_crc
;
36 static dissector_table_t mpeg_sect_tid_dissector_table
;
38 static bool mpeg_sect_check_crc
;
40 /* minimum length of the entire section ==
41 bytes from table_id to section_length == 3 bytes */
42 #define MPEG_SECT_MIN_LEN 3
43 /* the section_length field is 12 bits, it can add up to 4096 bytes
44 after the initial bytes */
45 #define MPEG_SECT_MAX_LEN MPEG_SECT_MIN_LEN+4096
48 #define MPEG_SECT_SYNTAX_INDICATOR_MASK 0x8000
49 #define MPEG_SECT_RESERVED_MASK 0x7000
50 #define MPEG_SECT_LENGTH_MASK 0x0FFF
52 /* From ISO/IEC 13818-1 */
63 /* From ETSI EN 300 468 */
88 TID_EIT_SC0_OTH
= 0x60,
111 /* From ETSI EN 301 790 */
113 TID_RMT
= 0x41, /* Conflict with TID_NIT_OTHER */
124 /* From ETSI EN 301 192 */
129 /* From OC-SP-ETV-AM 1.0-IO5 */
136 /* From ETSI TS 102 899 */
142 static const value_string mpeg_sect_table_id_vals
[] = {
144 { TID_PAT
, "Program Association Table (PAT)" },
145 { TID_CA
, "Conditional Access (CA)" },
146 { TID_PMT
, "Program Map Table (PMT)" },
147 { TID_TS_DESC
, "Transport Stream Description" },
148 { TID_SCENE_DESC
, "ISO/IEC 14496 Scene Description" },
149 { TID_OBJECT_DESC
, "ISO/IEC 14496 Object Description" },
150 { TID_NIT
, "Network Information Table (NIT), current network" },
151 { TID_NIT_OTHER
, "Network Information Table (NIT), other network" },
152 { TID_SDT
, "Service Description Table (SDT), current network" },
153 { TID_SDT_OTHER
, "Service Description (SDT), other network" },
154 { TID_BAT
, "Bouquet Association Table (BAT)" },
155 { TID_EIT_PF
, "Event Information Table (EIT), present/following, actual TS" },
156 { TID_EIT_PF_OTHER
,"Event Information Table (EIT), present/following, other TS" },
157 { TID_EIT_SC0
, "Event Information Table (EIT), schedule 0, actual TS" },
158 { TID_EIT_SC1
, "Event Information Table (EIT), schedule 1, actual TS" },
159 { TID_EIT_SC2
, "Event Information Table (EIT), schedule 2, actual TS" },
160 { TID_EIT_SC3
, "Event Information Table (EIT), schedule 3, actual TS" },
161 { TID_EIT_SC4
, "Event Information Table (EIT), schedule 4, actual TS" },
162 { TID_EIT_SC5
, "Event Information Table (EIT), schedule 5, actual TS" },
163 { TID_EIT_SC6
, "Event Information Table (EIT), schedule 6, actual TS" },
164 { TID_EIT_SC7
, "Event Information Table (EIT), schedule 7, actual TS" },
165 { TID_EIT_SC8
, "Event Information Table (EIT), schedule 8, actual TS" },
166 { TID_EIT_SC9
, "Event Information Table (EIT), schedule 9, actual TS" },
167 { TID_EIT_SCA
, "Event Information Table (EIT), schedule A, actual TS" },
168 { TID_EIT_SCB
, "Event Information Table (EIT), schedule B, actual TS" },
169 { TID_EIT_SCC
, "Event Information Table (EIT), schedule C, actual TS" },
170 { TID_EIT_SCD
, "Event Information Table (EIT), schedule D, actual TS" },
171 { TID_EIT_SCE
, "Event Information Table (EIT), schedule E, actual TS" },
172 { TID_EIT_SCF
, "Event Information Table (EIT), schedule F, actual TS" },
173 { TID_EIT_SC0_OTH
, "Event Information Table (EIT), schedule 0, other TS" },
174 { TID_EIT_SC1_OTH
, "Event Information Table (EIT), schedule 1, other TS" },
175 { TID_EIT_SC2_OTH
, "Event Information Table (EIT), schedule 2, other TS" },
176 { TID_EIT_SC3_OTH
, "Event Information Table (EIT), schedule 3, other TS" },
177 { TID_EIT_SC4_OTH
, "Event Information Table (EIT), schedule 4, other TS" },
178 { TID_EIT_SC5_OTH
, "Event Information Table (EIT), schedule 5, other TS" },
179 { TID_EIT_SC6_OTH
, "Event Information Table (EIT), schedule 6, other TS" },
180 { TID_EIT_SC7_OTH
, "Event Information Table (EIT), schedule 7, other TS" },
181 { TID_EIT_SC8_OTH
, "Event Information Table (EIT), schedule 8, other TS" },
182 { TID_EIT_SC9_OTH
, "Event Information Table (EIT), schedule 9, other TS" },
183 { TID_EIT_SCA_OTH
, "Event Information Table (EIT), schedule A, other TS" },
184 { TID_EIT_SCB_OTH
, "Event Information Table (EIT), schedule B, other TS" },
185 { TID_EIT_SCC_OTH
, "Event Information Table (EIT), schedule C, other TS" },
186 { TID_EIT_SCD_OTH
, "Event Information Table (EIT), schedule D, other TS" },
187 { TID_EIT_SCE_OTH
, "Event Information Table (EIT), schedule E, other TS" },
188 { TID_EIT_SCF_OTH
, "Event Information Table (EIT), schedule F, other TS" },
189 { TID_TDT
, "Time and Date Table (TDT)" },
190 { TID_RST
, "Running Status Table (RST)" },
191 { TID_ST
, "Stuffing Table (ST)" },
192 { TID_TOT
, "Time Offset Table (TOT)" },
193 { TID_AIT
, "Application Information Table (AIT)" },
194 { TID_SIT
, "Selection Information Table (SIT)" },
195 { TID_SCT
, "Superframe Composition Table (SCT)" },
196 { TID_FCT
, "Frame Composition Table (FCT)" },
197 { TID_TCT
, "Time-Slot Composition Table (TCT)" },
198 { TID_SPT
, "Satellite Position Table (SPT)" },
199 { TID_CMT
, "Correction Message Table (CMT)" },
200 { TID_TBTP
, "Terminal Burst Time Plan (TBTP)" },
201 { TID_TIM
, "Terminal Information Message (TIM)" },
202 { TID_DVB_MPE
, "DVB MultiProtocol Encapsulation (MPE)" },
203 { TID_ETV_EISS
, "ETV Integrated Signaling Stream (EISS)" },
204 { TID_ETV_DII
, "ETV Download Info Indication" },
205 { TID_ETV_DDB
, "ETV Download Data Block" },
206 { TID_FORBIDEN
, "Forbidden" },
210 static void mpeg_sect_prompt(packet_info
*pinfo
, char* result
)
212 snprintf(result
, MAX_DECODE_AS_PROMPT_LEN
, "Table ID %u as",
213 GPOINTER_TO_UINT(p_get_proto_data(pinfo
->pool
, pinfo
, proto_mpeg_sect
, MPEG_SECT_TID_KEY
)));
216 static void *mpeg_sect_value(packet_info
*pinfo
)
218 return p_get_proto_data(pinfo
->pool
, pinfo
, proto_mpeg_sect
, MPEG_SECT_TID_KEY
);
221 /* read a utc_time field in a tvb and write it to the utc_time struct
222 the encoding of the field is according to DVB-SI specification, section 5.2.5
223 16bit modified julian day (MJD), 24bit 6*4bit BCD digits hhmmss
224 return the length in bytes or -1 for error */
226 packet_mpeg_sect_mjd_to_utc_time(tvbuff_t
*tvb
, int offset
, nstime_t
*utc_time
)
228 int bcd_time_offset
; /* start offset of the bcd time in the tvbuff */
229 uint8_t hour
, min
, sec
;
234 nstime_set_zero(utc_time
);
235 utc_time
->secs
= (tvb_get_ntohs(tvb
, offset
) - 40587) * 86400;
236 bcd_time_offset
= offset
+2;
237 hour
= MPEG_SECT_BCD44_TO_DEC(tvb_get_uint8(tvb
, bcd_time_offset
));
238 min
= MPEG_SECT_BCD44_TO_DEC(tvb_get_uint8(tvb
, bcd_time_offset
+1));
239 sec
= MPEG_SECT_BCD44_TO_DEC(tvb_get_uint8(tvb
, bcd_time_offset
+2));
240 if (hour
>23 || min
>59 || sec
>59)
243 utc_time
->secs
+= hour
*3600 + min
*60 + sec
;
248 packet_mpeg_sect_header(tvbuff_t
*tvb
, unsigned offset
,
249 proto_tree
*tree
, unsigned *sect_len
, bool *ssi
)
251 return packet_mpeg_sect_header_extra(tvb
, offset
, tree
, sect_len
,
256 packet_mpeg_sect_header_extra(tvbuff_t
*tvb
, unsigned offset
, proto_tree
*tree
,
257 unsigned *sect_len
, unsigned *reserved
, bool *ssi
,
262 proto_item
*pi
[PACKET_MPEG_SECT_PI__SIZE
];
265 for (i
= 0; i
< PACKET_MPEG_SECT_PI__SIZE
; i
++) {
270 pi
[PACKET_MPEG_SECT_PI__TABLE_ID
] =
271 proto_tree_add_item(tree
, hf_mpeg_sect_table_id
,
272 tvb
, offset
+ len
, 1, ENC_BIG_ENDIAN
);
278 pi
[PACKET_MPEG_SECT_PI__SSI
] =
279 proto_tree_add_item(tree
, hf_mpeg_sect_syntax_indicator
,
280 tvb
, offset
+ len
, 2, ENC_BIG_ENDIAN
);
282 pi
[PACKET_MPEG_SECT_PI__RESERVED
] =
283 proto_tree_add_item(tree
, hf_mpeg_sect_reserved
, tvb
,
284 offset
+ len
, 2, ENC_BIG_ENDIAN
);
286 pi
[PACKET_MPEG_SECT_PI__LENGTH
] =
287 proto_tree_add_item(tree
, hf_mpeg_sect_length
, tvb
,
288 offset
+ len
, 2, ENC_BIG_ENDIAN
);
291 tmp
= tvb_get_ntohs(tvb
, offset
+ len
);
294 *sect_len
= MPEG_SECT_LENGTH_MASK
& tmp
;
297 *reserved
= (MPEG_SECT_RESERVED_MASK
& tmp
) >> 12;
300 *ssi
= (MPEG_SECT_SYNTAX_INDICATOR_MASK
& tmp
);
303 for (i
= 0; i
< PACKET_MPEG_SECT_PI__SIZE
; i
++) {
315 packet_mpeg_sect_crc(tvbuff_t
*tvb
, packet_info
*pinfo
,
316 proto_tree
*tree
, unsigned start
, unsigned end
)
318 if (mpeg_sect_check_crc
) {
319 proto_tree_add_checksum(tree
, tvb
, end
, hf_mpeg_sect_crc
, hf_mpeg_sect_crc_status
, &ei_mpeg_sect_crc
, pinfo
, crc32_mpeg2_tvb_offset(tvb
, start
, end
),
320 ENC_BIG_ENDIAN
, PROTO_CHECKSUM_VERIFY
);
322 proto_tree_add_checksum(tree
, tvb
, end
, hf_mpeg_sect_crc
, hf_mpeg_sect_crc_status
, &ei_mpeg_sect_crc
, pinfo
, crc32_mpeg2_tvb_offset(tvb
, start
, end
),
323 ENC_BIG_ENDIAN
, PROTO_CHECKSUM_NO_FLAGS
);
331 dissect_mpeg_sect(tvbuff_t
*tvb
, packet_info
*pinfo
,
332 proto_tree
*tree
, void *data _U_
)
336 unsigned section_length
= 0;
337 bool syntax_indicator
= false;
341 proto_tree
*mpeg_sect_tree
;
343 /* the incoming tvb contains only one section, no additional data */
345 tvb_len
= (int)tvb_reported_length(tvb
);
346 if (tvb_len
<MPEG_SECT_MIN_LEN
|| tvb_len
>MPEG_SECT_MAX_LEN
)
349 table_id
= tvb_get_uint8(tvb
, offset
);
350 p_add_proto_data(pinfo
->pool
, pinfo
, proto_mpeg_sect
, MPEG_SECT_TID_KEY
, GUINT_TO_POINTER(table_id
));
352 /* Check if a dissector can parse the current table */
353 if (dissector_try_uint(mpeg_sect_tid_dissector_table
, table_id
, tvb
, pinfo
, tree
))
356 /* If no dissector is registered, use the common one */
357 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MPEG SECT");
358 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Table ID 0x%02x", table_id
);
360 ti
= proto_tree_add_item(tree
, proto_mpeg_sect
, tvb
, offset
, -1, ENC_NA
);
361 mpeg_sect_tree
= proto_item_add_subtree(ti
, ett_mpeg_sect
);
363 proto_item_append_text(ti
, " Table_ID=0x%02x", table_id
);
365 packet_mpeg_sect_header(tvb
, offset
, mpeg_sect_tree
,
366 §ion_length
, &syntax_indicator
);
368 if (syntax_indicator
)
369 packet_mpeg_sect_crc(tvb
, pinfo
, mpeg_sect_tree
, 0, (section_length
-1));
376 proto_register_mpeg_sect(void)
378 static hf_register_info hf
[] = {
379 { &hf_mpeg_sect_table_id
, {
380 "Table ID", "mpeg_sect.tid",
381 FT_UINT8
, BASE_HEX
, VALS(mpeg_sect_table_id_vals
), 0, NULL
, HFILL
384 { &hf_mpeg_sect_syntax_indicator
, {
385 "Syntax indicator", "mpeg_sect.syntax_indicator",
386 FT_UINT16
, BASE_DEC
, NULL
, MPEG_SECT_SYNTAX_INDICATOR_MASK
, NULL
, HFILL
389 { &hf_mpeg_sect_reserved
, {
390 "Reserved", "mpeg_sect.reserved",
391 FT_UINT16
, BASE_HEX
, NULL
, MPEG_SECT_RESERVED_MASK
, NULL
, HFILL
394 { &hf_mpeg_sect_length
, {
395 "Length", "mpeg_sect.len",
396 FT_UINT16
, BASE_DEC
, NULL
, MPEG_SECT_LENGTH_MASK
, NULL
, HFILL
399 { &hf_mpeg_sect_crc
, {
400 "CRC 32", "mpeg_sect.crc",
401 FT_UINT32
, BASE_HEX
, NULL
, 0, NULL
, HFILL
404 { &hf_mpeg_sect_crc_status
, {
405 "CRC 32 Status", "mpeg_sect.crc.status",
406 FT_UINT8
, BASE_NONE
, VALS(proto_checksum_vals
), 0, NULL
, HFILL
411 static int *ett
[] = {
415 static ei_register_info ei
[] = {
416 { &ei_mpeg_sect_crc
, { "mpeg_sect.crc.invalid", PI_CHECKSUM
, PI_WARN
, "Invalid CRC", EXPFILL
}},
419 /* Decode As handling */
420 static build_valid_func mpeg_sect_da_build_value
[1] = {mpeg_sect_value
};
421 static decode_as_value_t mpeg_sect_da_values
= {mpeg_sect_prompt
, 1, mpeg_sect_da_build_value
};
422 static decode_as_t mpeg_sect_da
= {"mpeg_sect", "mpeg_sect.tid", 1, 0, &mpeg_sect_da_values
, NULL
, NULL
, decode_as_default_populate_list
, decode_as_default_reset
, decode_as_default_change
, NULL
};
424 module_t
*mpeg_sect_module
;
425 expert_module_t
* expert_mpeg_sect
;
427 proto_mpeg_sect
= proto_register_protocol("MPEG2 Section", "MPEG SECT", "mpeg_sect");
428 register_dissector("mpeg_sect", dissect_mpeg_sect
, proto_mpeg_sect
);
430 proto_register_field_array(proto_mpeg_sect
, hf
, array_length(hf
));
431 proto_register_subtree_array(ett
, array_length(ett
));
432 expert_mpeg_sect
= expert_register_protocol(proto_mpeg_sect
);
433 expert_register_field_array(expert_mpeg_sect
, ei
, array_length(ei
));
435 mpeg_sect_module
= prefs_register_protocol(proto_mpeg_sect
, NULL
);
437 prefs_register_bool_preference(mpeg_sect_module
,
439 "Verify the section CRC",
440 "Whether the section dissector should verify the CRC",
441 &mpeg_sect_check_crc
);
443 mpeg_sect_tid_dissector_table
= register_dissector_table("mpeg_sect.tid",
444 "MPEG SECT Table ID",
445 proto_mpeg_sect
, FT_UINT8
, BASE_HEX
);
447 register_decode_as(&mpeg_sect_da
);
451 * Editor modelines - https://www.wireshark.org/tools/modelines.html
456 * indent-tabs-mode: nil
459 * vi: set shiftwidth=4 tabstop=8 expandtab:
460 * :indentSize=4:tabSize=8:noTabs=true: