3 * Routines for RFC 2250 MPEG2 (ISO/IEC 13818-1) Transport Stream dissection
5 * Copyright 2006, Erwin Rol <erwin@erwinrol.com>
6 * Copyright 2012-2014, Guy Martin <gmsoft@tuxicoman.be>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <epan/packet.h>
18 #include <wiretap/wtap.h>
20 #include <epan/rtp_pt.h>
22 #include <epan/conversation.h>
23 #include <epan/expert.h>
24 #include <epan/reassemble.h>
25 #include <epan/proto_data.h>
26 #include <epan/exported_pdu.h>
28 #include <epan/follow.h>
29 #include <epan/exceptions.h>
30 #include <epan/show_exception.h>
31 #include <epan/addr_resolv.h>
32 #include "packet-l2tp.h"
33 #include "packet-udp.h"
34 #include "packet-mp2t.h"
36 void proto_register_mp2t(void);
37 void proto_reg_handoff_mp2t(void);
39 #define MP2T_PID_DOCSIS 0x1FFE
40 #define MP2T_PID_NULL 0x1FFF
42 static dissector_handle_t mp2t_handle
;
44 static dissector_handle_t docsis_handle
;
45 static dissector_handle_t mpeg_pes_handle
;
46 static dissector_handle_t mpeg_sect_handle
;
48 static heur_dissector_list_t heur_subdissector_list
;
50 static int exported_pdu_tap
;
51 static int mp2t_follow_tap
;
53 static int proto_mp2t
;
55 static int ett_mp2t_header
;
56 static int ett_mp2t_af
;
57 static int ett_mp2t_analysis
;
60 static int hf_mp2t_stream
;
61 static int hf_mp2t_header
;
62 static int hf_mp2t_sync_byte
;
63 static int hf_mp2t_tei
;
64 static int hf_mp2t_pusi
;
65 static int hf_mp2t_tp
;
66 static int hf_mp2t_pid
;
67 static int hf_mp2t_tsc
;
68 static int hf_mp2t_afc
;
69 static int hf_mp2t_cc
;
71 /* static int hf_mp2t_analysis_flags; */
72 static int hf_mp2t_analysis_skips
;
73 static int hf_mp2t_analysis_drops
;
75 #define MP2T_SYNC_BYTE_MASK 0xFF000000
76 #define MP2T_TEI_MASK 0x00800000
77 #define MP2T_PUSI_MASK 0x00400000
78 #define MP2T_TP_MASK 0x00200000
79 #define MP2T_PID_MASK 0x001FFF00
80 #define MP2T_TSC_MASK 0x000000C0
81 #define MP2T_AFC_MASK 0x00000030
82 #define MP2T_CC_MASK 0x0000000F
84 #define MP2T_SYNC_BYTE_SHIFT 24
85 #define MP2T_TEI_SHIFT 23
86 #define MP2T_PUSI_SHIFT 22
87 #define MP2T_TP_SHIFT 21
88 #define MP2T_PID_SHIFT 8
89 #define MP2T_TSC_SHIFT 6
90 #define MP2T_AFC_SHIFT 4
91 #define MP2T_CC_SHIFT 0
93 static int hf_mp2t_af
;
94 static int hf_mp2t_af_length
;
95 static int hf_mp2t_af_di
;
96 static int hf_mp2t_af_rai
;
97 static int hf_mp2t_af_espi
;
98 static int hf_mp2t_af_pcr_flag
;
99 static int hf_mp2t_af_opcr_flag
;
100 static int hf_mp2t_af_sp_flag
;
101 static int hf_mp2t_af_tpd_flag
;
102 static int hf_mp2t_af_afe_flag
;
104 #define MP2T_AF_DI_MASK 0x80
105 #define MP2T_AF_RAI_MASK 0x40
106 #define MP2T_AF_ESPI_MASK 0x20
107 #define MP2T_AF_PCR_MASK 0x10
108 #define MP2T_AF_OPCR_MASK 0x08
109 #define MP2T_AF_SP_MASK 0x04
110 #define MP2T_AF_TPD_MASK 0x02
111 #define MP2T_AF_AFE_MASK 0x01
113 #define MP2T_AF_DI_SHIFT 7
114 #define MP2T_AF_RAI_SHIFT 6
115 #define MP2T_AF_ESPI_SHIFT 5
116 #define MP2T_AF_PCR_SHIFT 4
117 #define MP2T_AF_OPCR_SHIFT 3
118 #define MP2T_AF_SP_SHIFT 2
119 #define MP2T_AF_TPD_SHIFT 1
120 #define MP2T_AF_AFE_SHIFT 0
122 static int hf_mp2t_af_pcr
;
123 static int hf_mp2t_af_opcr
;
125 static int hf_mp2t_af_sc
;
127 static int hf_mp2t_af_tpd_length
;
128 static int hf_mp2t_af_tpd
;
130 static int hf_mp2t_af_e_length
;
131 static int hf_mp2t_af_e_ltw_flag
;
132 static int hf_mp2t_af_e_pr_flag
;
133 static int hf_mp2t_af_e_ss_flag
;
134 static int hf_mp2t_af_e_reserved
;
136 #define MP2T_AF_E_LTW_FLAG_MASK 0x80
137 #define MP2T_AF_E_PR_FLAG_MASK 0x40
138 #define MP2T_AF_E_SS_FLAG_MASK 0x20
140 static int hf_mp2t_af_e_reserved_bytes
;
141 static int hf_mp2t_af_stuffing_bytes
;
143 static int hf_mp2t_af_e_ltwv_flag
;
144 static int hf_mp2t_af_e_ltwo
;
146 static int hf_mp2t_af_e_pr_reserved
;
147 static int hf_mp2t_af_e_pr
;
149 static int hf_mp2t_af_e_st
;
150 static int hf_mp2t_af_e_dnau_32_30
;
151 static int hf_mp2t_af_e_m_1
;
152 static int hf_mp2t_af_e_dnau_29_15
;
153 static int hf_mp2t_af_e_m_2
;
154 static int hf_mp2t_af_e_dnau_14_0
;
155 static int hf_mp2t_af_e_m_3
;
157 /* static int hf_mp2t_payload; */
158 static int hf_mp2t_stuff_bytes
;
159 static int hf_mp2t_pointer
;
161 /* proto data keys. Note that the packet_analysis_data structure is stored
162 * using the layer number, but since that is at wmem_file_scope() while
163 * the stream information is at pinfo->pool, they don't actually clash.
165 #define MP2T_PROTO_DATA_STREAM 1
166 #define MP2T_PROTO_DATA_PID 2
168 static const value_string mp2t_sync_byte_vals
[] = {
169 { MP2T_SYNC_BYTE
, "Correct" },
173 static const value_string mp2t_pid_vals
[] = {
174 { 0x0000, "Program Association Table" },
175 { 0x0001, "Conditional Access Table" },
176 { 0x0002, "Transport Stream Description Table" },
177 { 0x0003, "Reserved" },
178 { 0x0004, "Reserved" },
179 { 0x0005, "Reserved" },
180 { 0x0006, "Reserved" },
181 { 0x0007, "Reserved" },
182 { 0x0008, "Reserved" },
183 { 0x0009, "Reserved" },
184 { 0x000A, "Reserved" },
185 { 0x000B, "Reserved" },
186 { 0x000C, "Reserved" },
187 { 0x000D, "Reserved" },
188 { 0x000E, "Reserved" },
189 { 0x000F, "Reserved" },
190 { 0x0010, "Network Information or Stuffing Table" },
191 { 0x0011, "Service Description or Bouquet Association or Stuffing Table" },
192 { 0x0012, "Event Information or Stuffing or Content Identifier Table" },
193 { 0x0013, "Running Status or Stuffing Table" },
194 { 0x0014, "Time and Date or Time Offset or Stuffing Table" },
195 { 0x0015, "Network Synchronization" },
196 { 0x0016, "Resolution Authority Record Notification Table" },
197 { 0x0017, "Reserved For Future Use" },
198 { 0x0018, "Reserved For Future Use" },
199 { 0x0019, "Reserved For Future Use" },
200 { 0x001A, "Reserved For Future Use" },
201 { 0x001B, "Reserved For Future Use" },
202 { 0x001C, "Inband Signaling" },
203 { 0x001D, "Measurement" },
204 { 0x001E, "Discontinuity Information Table" },
205 { 0x001F, "Selection Information Table" },
206 { 0x1FFE, "DOCSIS Data-over-cable well-known PID" },
207 { 0x1FFF, "Null packet" },
212 /* Values below according ETSI ETR 289 */
213 static const value_string mp2t_tsc_vals
[] = {
214 { 0, "Not scrambled" },
216 { 2, "Packet scrambled with Even Key" },
217 { 3, "Packet scrambled with Odd Key" },
221 static const value_string mp2t_afc_vals
[] = {
223 { 1, "Payload only" },
224 { 2, "Adaptation Field only" },
225 { 3, "Adaptation Field and Payload" },
229 static int ett_msg_fragment
;
230 static int ett_msg_fragments
;
231 static int hf_msg_fragments
;
232 static int hf_msg_fragment
;
233 static int hf_msg_fragment_overlap
;
234 static int hf_msg_fragment_overlap_conflicts
;
235 static int hf_msg_fragment_multiple_tails
;
236 static int hf_msg_fragment_too_long_fragment
;
237 static int hf_msg_fragment_error
;
238 static int hf_msg_fragment_count
;
239 static int hf_msg_reassembled_in
;
240 static int hf_msg_reassembled_length
;
242 static int hf_msg_ts_packet_reassembled
;
244 static expert_field ei_mp2t_pointer
;
245 static expert_field ei_mp2t_cc_drop
;
246 static expert_field ei_mp2t_invalid_afc
;
248 static const fragment_items mp2t_msg_frag_items
= {
249 /* Fragment subtrees */
252 /* Fragment fields */
255 &hf_msg_fragment_overlap
,
256 &hf_msg_fragment_overlap_conflicts
,
257 &hf_msg_fragment_multiple_tails
,
258 &hf_msg_fragment_too_long_fragment
,
259 &hf_msg_fragment_error
,
260 &hf_msg_fragment_count
,
261 /* Reassembled in field */
262 &hf_msg_reassembled_in
,
263 /* Reassembled length field */
264 &hf_msg_reassembled_length
,
265 /* Reassembled data field */
272 /* Data structure used for detecting CC drops
274 * conversation + direction
276 * +-> mp2t_analysis_data
278 * +-> pid_table (RB tree) (key: pid)
280 * | +-> pid_analysis_data (per pid)
281 * | +-> pid_analysis_data
282 * | +-> pid_analysis_data
284 * +-> frame_table (RB tree) (key: pinfo->num)
286 * +-> frame_analysis_data (only created if drop detected)
288 * +-> ts_table (RB tree)
290 * +-> ts_analysis_data (per TS subframe)
291 * +-> ts_analysis_data
292 * +-> ts_analysis_data
295 static wmem_map_t
*mp2t_stream_hashtable
;
297 static uint32_t mp2t_stream_count
;
300 const conversation_t
* conv
;
306 mp2t_stream_equal(const void *v
, const void *w
)
308 const mp2t_stream_key
*v1
= (const mp2t_stream_key
*)v
;
309 const mp2t_stream_key
*v2
= (const mp2t_stream_key
*)w
;
311 result
= (v1
->conv
== v2
->conv
&& v1
->dir
== v2
->dir
);
316 mp2t_stream_hash(const void *v
)
318 const mp2t_stream_key
*key
= (const mp2t_stream_key
*)v
;
319 /* Actually getting multiple streams in opposite directions is
320 * quite unlikely, so to optimize don't include it in the hash */
321 unsigned hash_val
= GPOINTER_TO_UINT(key
->conv
);
325 typedef struct mp2t_analysis_data
{
327 /* This structure contains a tree containing data for the
328 * individual pid's, this is only used when packets are
329 * processed sequentially.
331 wmem_tree_t
*pid_table
;
333 /* When detecting a CC drop, store that information for the
334 * given frame. This info is needed, when clicking around in
335 * wireshark, as the pid table data only makes sense during
336 * sequential processing. The flag pinfo->fd->visited is
337 * used to tell the difference.
340 wmem_tree_t
*frame_table
;
344 /* Total counters per conversation / multicast stream */
345 uint32_t total_skips
;
346 uint32_t total_discontinuity
;
348 } mp2t_analysis_data_t
;
350 enum pid_payload_type
{
358 typedef struct subpacket_analysis_data
{
359 uint32_t frag_cur_pos
;
360 uint32_t frag_tot_len
;
363 } subpacket_analysis_data_t
;
365 typedef struct packet_analysis_data
{
367 /* Contain information for each MPEG2-TS packet in the current big packet */
368 wmem_tree_t
*subpacket_table
;
369 } packet_analysis_data_t
;
371 /* Analysis TS frame info needed during sequential processing */
372 typedef struct pid_analysis_data
{
374 int8_t cc_prev
; /* Previous CC number */
375 enum pid_payload_type pload_type
;
376 wmem_tree_t
*stream_types
;
378 /* Fragments information used for first pass */
380 uint32_t frag_cur_pos
;
381 uint32_t frag_tot_len
;
383 } pid_analysis_data_t
;
385 /* Analysis info stored for a TS frame */
386 typedef struct ts_analysis_data
{
388 int8_t cc_prev
; /* Previous CC number */
389 uint8_t skips
; /* Skips between Ccs max 14 */
390 } ts_analysis_data_t
;
393 typedef struct frame_analysis_data
{
395 /* As each frame has several pid's, thus need a pid data
396 * structure per TS frame.
398 wmem_tree_t
*ts_table
;
400 } frame_analysis_data_t
;
402 static mp2t_analysis_data_t
*
403 init_mp2t_conversation_data(void)
405 mp2t_analysis_data_t
*mp2t_data
;
407 mp2t_data
= wmem_new0(wmem_file_scope(), struct mp2t_analysis_data
);
409 mp2t_data
->stream
= mp2t_stream_count
++;
410 mp2t_data
->pid_table
= wmem_tree_new(wmem_file_scope());
412 mp2t_data
->frame_table
= wmem_tree_new(wmem_file_scope());
414 mp2t_data
->total_skips
= 0;
415 mp2t_data
->total_discontinuity
= 0;
420 static mp2t_analysis_data_t
*
421 get_mp2t_conversation_data(mp2t_stream_key
*key
)
423 mp2t_stream_key
*new_key
;
424 mp2t_analysis_data_t
*mp2t_data
;
426 mp2t_data
= (mp2t_analysis_data_t
*)wmem_map_lookup(mp2t_stream_hashtable
, key
);
428 new_key
= wmem_new(wmem_file_scope(), mp2t_stream_key
);
430 mp2t_data
= init_mp2t_conversation_data();
431 wmem_map_insert(mp2t_stream_hashtable
, new_key
, mp2t_data
);
437 static frame_analysis_data_t
*
438 init_frame_analysis_data(mp2t_analysis_data_t
*mp2t_data
, packet_info
*pinfo
)
440 frame_analysis_data_t
*frame_analysis_data_p
;
442 frame_analysis_data_p
= wmem_new0(wmem_file_scope(), struct frame_analysis_data
);
443 frame_analysis_data_p
->ts_table
= wmem_tree_new(wmem_file_scope());
444 /* Insert into mp2t tree */
445 wmem_tree_insert32(mp2t_data
->frame_table
, pinfo
->num
,
446 (void *)frame_analysis_data_p
);
448 return frame_analysis_data_p
;
452 static frame_analysis_data_t
*
453 get_frame_analysis_data(mp2t_analysis_data_t
*mp2t_data
, packet_info
*pinfo
)
455 frame_analysis_data_t
*frame_analysis_data_p
;
456 frame_analysis_data_p
= (frame_analysis_data_t
*)wmem_tree_lookup32(mp2t_data
->frame_table
, pinfo
->num
);
457 return frame_analysis_data_p
;
460 static pid_analysis_data_t
*
461 get_pid_analysis(mp2t_analysis_data_t
*mp2t_data
, uint32_t pid
)
463 pid_analysis_data_t
*pid_data
;
465 pid_data
= (pid_analysis_data_t
*)wmem_tree_lookup32(mp2t_data
->pid_table
, pid
);
467 pid_data
= wmem_new0(wmem_file_scope(), struct pid_analysis_data
);
468 pid_data
->cc_prev
= -1;
470 pid_data
->stream_types
= wmem_tree_new(wmem_file_scope());
471 pid_data
->frag_id
= (pid
<< (32 - 13)) | 0x1;
473 wmem_tree_insert32(mp2t_data
->pid_table
, pid
, (void *)pid_data
);
479 mp2t_get_stream_count(void)
481 return mp2t_stream_count
;
487 mp2t_stream_count
= 0;
491 mp2t_stream_find(void *key _U_
, void *value
, void *user_data
)
493 uint32_t stream
= GPOINTER_TO_UINT(user_data
);
494 mp2t_analysis_data_t
*mp2t_data
= (mp2t_analysis_data_t
*)value
;
495 if (mp2t_data
->stream
== stream
) {
502 mp2t_get_sub_stream_id(unsigned stream
, unsigned sub_stream
, bool le
, unsigned *sub_stream_out
)
504 mp2t_analysis_data_t
*mp2t_data
= wmem_map_find(mp2t_stream_hashtable
, mp2t_stream_find
, GUINT_TO_POINTER(stream
));
505 pid_analysis_data_t
*pid_data
;
510 pid_data
= wmem_tree_lookup32_le(mp2t_data
->pid_table
, sub_stream
);
512 pid_data
= wmem_tree_lookup32_ge(mp2t_data
->pid_table
, sub_stream
);
518 *sub_stream_out
= pid_data
->pid
;
522 char *mp2t_follow_conv_filter(epan_dissect_t
*edt _U_
, packet_info
*pinfo
, unsigned *stream
, unsigned *sub_stream
)
525 mp2t_stream_key
*stream_key
;
528 stream_key
= (mp2t_stream_key
*)p_get_proto_data(pinfo
->pool
, pinfo
, proto_mp2t
, MP2T_PROTO_DATA_STREAM
);
530 mp2t_analysis_data_t
*mp2t_data
= get_mp2t_conversation_data(stream_key
);
531 pid
= GPOINTER_TO_UINT(p_get_proto_data(pinfo
->pool
, pinfo
, proto_mp2t
, MP2T_PROTO_DATA_PID
));
532 *stream
= mp2t_data
->stream
;
534 filter
= ws_strdup_printf("mp2t.stream == %u && mp2t.pid == 0x%04x", *stream
, pid
);
539 char *mp2t_follow_index_filter(unsigned stream
, unsigned sub_stream
)
541 return ws_strdup_printf("mp2t.stream == %u && mp2t.pid == 0x%04x", stream
, sub_stream
);
544 /* Structure to handle packets, spanned across
545 * multiple MPEG packets
548 /* Reassembly functions */
549 typedef struct _mp2t_fragment_key
{
550 uint32_t conv_index
; /* Just use the unique index */
556 mp2t_fragment_hash(const void *k
)
558 const mp2t_fragment_key
* key
= (const mp2t_fragment_key
*) k
;
563 /* In most captures there is only one conversation so optimize on
564 * only using the id for the hash. */
565 // hash_val += (key->conv_index << 2) + key->dir;
573 mp2t_fragment_equal(const void *k1
, const void *k2
)
575 const mp2t_fragment_key
* key1
= (const mp2t_fragment_key
*) k1
;
576 const mp2t_fragment_key
* key2
= (const mp2t_fragment_key
*) k2
;
578 /* Compare the id first since it's the most likely to differ */
579 return (key1
->id
== key2
->id
) &&
580 (key1
->conv_index
== key2
->conv_index
) &&
581 (key1
->dir
== key2
->dir
);
585 * Create a fragment key for permanent use; we are only copying ints,
586 * so our temporary keys are the same as permanent ones.
589 mp2t_fragment_persistent_key(const packet_info
*pinfo _U_
, const uint32_t id
, const void *data
)
591 mp2t_fragment_key
*key
= g_slice_new(mp2t_fragment_key
);
592 DISSECTOR_ASSERT(data
);
593 mp2t_stream_key
*stream
= (mp2t_stream_key
*)data
;
595 key
->conv_index
= stream
->conv
->conv_index
;
596 key
->dir
= stream
->dir
;
603 mp2t_fragment_free_persistent_key(void *ptr
)
605 mp2t_fragment_key
*key
= (mp2t_fragment_key
*)ptr
;
606 g_slice_free(mp2t_fragment_key
, key
);
609 static const reassembly_table_functions
610 mp2t_reassembly_table_functions
= {
613 mp2t_fragment_persistent_key
,
614 mp2t_fragment_persistent_key
,
615 mp2t_fragment_free_persistent_key
,
616 mp2t_fragment_free_persistent_key
619 static reassembly_table mp2t_reassembly_table
;
622 mp2t_add_stream_type(packet_info
*pinfo
, uint32_t pid
, uint32_t stream_type
)
624 mp2t_stream_key
*stream
;
626 stream
= (mp2t_stream_key
*)p_get_proto_data(pinfo
->pool
, pinfo
, proto_mp2t
, MP2T_PROTO_DATA_STREAM
);
631 mp2t_analysis_data_t
*mp2t_data
= get_mp2t_conversation_data(stream
);
632 pid_analysis_data_t
*pid_data
= get_pid_analysis(mp2t_data
, pid
);
634 if (!pid_data
->stream_types
) {
635 pid_data
->stream_types
= wmem_tree_new(wmem_file_scope());
638 wmem_tree_insert32(pid_data
->stream_types
, pinfo
->num
, GUINT_TO_POINTER(stream_type
));
642 mp2t_dissect_packet(tvbuff_t
*tvb
, const pid_analysis_data_t
*pid_analysis
,
643 packet_info
*pinfo
, proto_tree
*tree
)
645 if (have_tap_listener(mp2t_follow_tap
)) {
646 tap_queue_packet(mp2t_follow_tap
, pinfo
, tvb
);
649 switch (pid_analysis
->pload_type
) {
650 case pid_pload_docsis
:
651 call_dissector(docsis_handle
, tvb
, pinfo
, tree
);
654 call_dissector_with_data(mpeg_pes_handle
, tvb
, pinfo
, tree
, wmem_tree_lookup32_le(pid_analysis
->stream_types
, pinfo
->num
));
657 call_dissector(mpeg_sect_handle
, tvb
, pinfo
, tree
);
660 /* Should not happen */
661 call_data_dissector(tvb
, pinfo
, tree
);
666 /* Determine the length of a payload packet. If there aren't enough
667 * bytes to determine the length, returns -1. This will usually be
668 * called on the first fragment of a packet, but will be called
669 * on the second fragment if it returned -1 previously. (Returning
670 * -1 a second time indicates issues with dropped packets, etc.)
673 mp2t_get_packet_length(tvbuff_t
*tvb
, unsigned offset
, packet_info
*pinfo
,
674 uint32_t frag_id
, enum pid_payload_type pload_type
)
676 mp2t_stream_key
*stream
;
677 fragment_head
*frag_head
;
678 fragment_item
*frag
= NULL
;
679 tvbuff_t
*len_tvb
= NULL
, *frag_tvb
= NULL
, *data_tvb
= NULL
;
681 unsigned remaining_len
;
683 stream
= (mp2t_stream_key
*)p_get_proto_data(pinfo
->pool
, pinfo
, proto_mp2t
, MP2T_PROTO_DATA_STREAM
);
684 if (pinfo
->fd
->visited
) {
685 frag_head
= fragment_get_reassembled_id(&mp2t_reassembly_table
, pinfo
, frag_id
);
687 len_tvb
= frag_head
->tvb_data
;
690 /* Not reassembled on the first pass. There are two possibilities:
691 * 1) An entire packet contained within a TSP, so it never was
693 * 2) Dangling fragments at the end of the capture.
695 frag_head
= fragment_get(&mp2t_reassembly_table
, pinfo
, frag_id
, stream
);
697 /* This is the entire packet */
700 /* Dangling packets at the end that failed to reassemble the
701 * first time around, so don't bother this time
707 frag_head
= fragment_get(&mp2t_reassembly_table
, pinfo
, frag_id
, stream
);
709 frag
= frag_head
->next
;
712 if (!frag
) { /* First frame */
715 /* Create a composite tvb out of the two */
716 frag_tvb
= tvb_new_subset_remaining(frag
->tvb_data
, 0);
717 len_tvb
= tvb_new_composite();
718 tvb_composite_append(len_tvb
, frag_tvb
);
720 data_tvb
= tvb_new_subset_remaining(tvb
, offset
);
721 tvb_composite_append(len_tvb
, data_tvb
);
722 tvb_composite_finalize(len_tvb
);
724 offset
= frag
->offset
;
728 /* Get the next packet's size if possible; if not, return -1 */
729 remaining_len
= tvb_reported_length_remaining(len_tvb
, offset
);
730 /* Normally the only time we would not enough info to determine the size
731 * of the encapsulated packet is when the first fragment is at the very end
732 * of a TSP, but prevent exceptions in the case of dropped and OOO frames.
734 switch (pload_type
) {
735 case pid_pload_docsis
:
736 if (remaining_len
< 4)
738 pkt_len
= tvb_get_ntohs(len_tvb
, offset
+ 2) + 6;
741 if (remaining_len
< 6)
743 pkt_len
= tvb_get_ntohs(len_tvb
, offset
+ 4);
744 if (pkt_len
) /* A size of 0 means size not bounded */
748 if (remaining_len
< 3)
750 pkt_len
= (tvb_get_ntohs(len_tvb
, offset
+ 1) & 0xFFF) + 3;
753 /* Should not happen */
761 mp2t_fragment_handle(tvbuff_t
*tvb
, unsigned offset
, packet_info
*pinfo
,
762 proto_tree
*tree
, uint32_t frag_id
,
763 unsigned frag_offset
, unsigned frag_len
,
764 bool fragment_last
, const pid_analysis_data_t
*pid_analysis
)
766 fragment_head
*frag_msg
;
769 const char *save_proto
;
770 mp2t_stream_key
*stream
;
771 bool save_fragmented
;
773 save_fragmented
= pinfo
->fragmented
;
774 pinfo
->fragmented
= true;
775 /* It's possible that a fragment in the same packet set an address already
776 * (e.g., with MPE), which is why we use the conversation and direction not
777 * the addresses in the packet_info to reassemble.
780 stream
= (mp2t_stream_key
*)p_get_proto_data(pinfo
->pool
, pinfo
, proto_mp2t
, MP2T_PROTO_DATA_STREAM
);
781 /* check length; send frame for reassembly */
782 frag_msg
= fragment_add_check(&mp2t_reassembly_table
,
783 tvb
, offset
, pinfo
, frag_id
, stream
,
788 /* We only want to call subdissectors on the last fragment.
789 * processed_reassembled_data checks the frame number and layer number,
790 * but when there is more than one TSP in a frame, the fragment at the
791 * end of one TSP and the first fragment of the next have the same layer
792 * number. So use our own information about whether this is the last
793 * fragment to avoid calling subdissectors early and often.
796 new_tvb
= process_reassembled_data(tvb
, offset
, pinfo
,
798 frag_msg
, &mp2t_msg_frag_items
,
802 if (frag_msg
!= NULL
) {
803 ti
= proto_tree_add_uint(tree
, hf_msg_reassembled_in
, tvb
, 0, 0, frag_msg
->reassembled_in
);
804 proto_item_set_generated(ti
);
809 proto_tree_add_item(tree
, hf_msg_ts_packet_reassembled
, tvb
, 0, 0, ENC_NA
);
810 save_proto
= pinfo
->current_proto
;
812 * Dissect the reassembled packet.
814 * Because there isn't an explicit fragment ID (other than one
815 * we've made ourselves) if frames were dropped or out of order
816 * it's quite likely that a subdissector throws an exception.
817 * However, that doesn't mean we must stop dissecting, since we have
818 * the pointer to where the next upper level packet begins in the
819 * TSP begins. (Also, we want to make sure we increment our fragment
820 * ID and store the packet analysis data, which happens after this
821 * back in the calling function.)
824 mp2t_dissect_packet(new_tvb
, pid_analysis
, pinfo
, tree
);
826 CATCH_NONFATAL_ERRORS
{
827 show_exception(tvb
, pinfo
, tree
, EXCEPT_CODE
, GET_MESSAGE
);
829 pinfo
->current_proto
= save_proto
;
833 col_set_str(pinfo
->cinfo
, COL_INFO
, "[MP2T fragment of a reassembled packet]");
836 pinfo
->fragmented
= save_fragmented
;
841 * Reassembly of various payload types.
843 * DOCSIS MAC frames, PES packets, etc. may begin anywhere within an MPEG-TS
844 * packet or span multiple MPEG packets.
846 * The payload_unit_start_indicator bit in the MPEG-TS header, and the pointer
847 * field, are used to reassemble fragmented frames from MPEG-TS packets.
849 * If that bit is set, a higher-level packet begins in this MPEG-TS
850 * packet, and the MPEG-TS header is followed by a 1-octet pointer field.
851 * The value of the pointer field indicates at which byte the higher-
852 * level packet begins. If that bit is not set, the packet begun in
853 * an earlier MPEG-TS packet continues in this packet, with the data
854 * in the payload going after the data in the previous MPEG-TS packet
855 * (there can be more than one continuing packet).
857 * If the pointer field is non-zero, this MPEG-TS packet contains
858 * the conclusion of one higher-level packet and the beginning of
861 * As the MPEG-TS packets are of a fixed size, stuff bytes are used
862 * as padding before the first byte of a higher-level packet as
865 * This diagram is from Data-Over-Cable Service Interface Specifications,
866 * Downstream RF Interface Specification, CM-SP-DRFI-I16-170111, section 7
867 * "DOWNSTREAM TRANSMISSION CONVERGENCE SUBLAYER", and shows how the
868 * higher-level packets are transported over the MPEG Transport Stream:
870 *+--------------------------------------------------------------------------------+
871 *|MPEG Header | pointer_field | stuff_bytes | Start of Packet #1 |
872 *|(PUSI = 1) | (= 0) | (0 or more) | (up to 183 bytes) |
873 *+--------------------------------------------------------------------------------+
874 *+--------------------------------------------------------------------------------+
875 *|MPEG Header | Continuation of Packet #1 |
876 *|(PUSI = 0) | (up to 183 bytes) |
877 *+--------------------------------------------------------------------------------+
878 *+---------------------------------------------------------------------------------+
879 *|MPEG Header | pointer_field |Tail of Packet #1 | stuff_bytes |Start of Packet #2 |
880 *|(PUSI = 1) | (= M) |(M bytes) | (0 or more) |(N bytes) |
881 *+---------------------------------------------------------------------------------+
883 * For PES and PSI, see ISO/IEC 13818-1 / ITU-T Rec. H.222.0 (05/2006),
884 * section 2.4.3.3 "Semantic definition of fields in Transport Stream packet
885 * layer", which says much the same thing.
887 * When the payload is PES packet data, note that there is no pointer_field;
888 * if the PUSI is 1 then the TS payload "will commence with the first byte
889 * of a PES packet" and "one and only one PES packet starts in this Transport
890 * Stream packet". Furthermore, section 2.4.3.5 "Semantic definition of
891 * fields in adaptation field" mentions that stuffing in an adaptation field
892 * is "the only method of stuffing allowed for Transport Stream packets
893 * carrying PES packets." Thus stuff_bytes is not relevant for MPEG-TS payloads
894 * carrying PES. (It is possible to have stuffing *inside* the PES packet,
895 * as seen in section 2.4.3.6 "PES packet" and 2.4.3.7 "Semantic definition
896 * of fields in PES packet", which is handled in the MPEG PES dissector.)
898 * For MPEG-TS packets carrying PSI (which includes private data sections), an
899 * alternative stuffing method is allowed. This method involves stuff bytes
900 * at the end of a MPEG-TS packet after the last section contained within
901 * (similar to the stuff_bytes that may appear after a continued section
902 * before the byte referenced by pointer_field). According to Section 2.4.4
903 * "Program specific information", once a packet stuffing byte 0xFF appears,
904 * "all bytes until the end of the Transport Stream packet shall also be
905 * stuffing bytes of value 0xFF." In other words, as section C.3 "The Mapping
906 * of Sections into Transport Stream Packets" elaborates, while multiple
907 * entire sections are allowed within a TS packet, "no gaps between sections
908 * within a Transport Stream packet are allowed by the syntax".
910 * However, this function is permissive in what it accepts to the extent
911 * possible; it will allow multiple PES packets in the same TS packet and
912 * stuffing bytes to follow PES packets (at least those that indicate their
913 * length) and will allow stuffing bytes between complete PSI sections.
916 mp2t_process_fragmented_payload(tvbuff_t
*tvb
, int offset
, unsigned remaining_len
, packet_info
*pinfo
,
917 proto_tree
*tree
, proto_tree
*header_tree
, uint32_t pusi_flag
,
918 pid_analysis_data_t
*pid_analysis
)
923 unsigned stuff_len
= 0;
924 proto_tree
*stuff_tree
;
925 packet_analysis_data_t
*pdata
= NULL
;
926 subpacket_analysis_data_t
*spdata
= NULL
;
927 uint32_t frag_cur_pos
= 0, frag_tot_len
= 0;
928 bool fragmentation
= false;
929 uint32_t frag_id
= 0;
931 if (pusi_flag
&& pid_analysis
->pload_type
== pid_pload_unknown
932 && remaining_len
> 3) {
933 /* We should already have identified if it was a DOCSIS packet
934 * Remaining possibility is PES or SECT */
935 if (tvb_get_ntoh24(tvb
, offset
) == 0x000001) {
936 /* Looks like a PES packet to me ... */
937 pid_analysis
->pload_type
= pid_pload_pes
;
939 /* Most probably a SECT packet */
940 pid_analysis
->pload_type
= pid_pload_sect
;
944 /* Unable to determine the payload type, do nothing */
945 if (pid_analysis
->pload_type
== pid_pload_unknown
)
948 /* PES packet don't have pointer fields, others do */
949 if (pusi_flag
&& pid_analysis
->pload_type
!= pid_pload_pes
) {
950 pointer
= tvb_get_uint8(tvb
, offset
);
951 pi
= proto_tree_add_item(header_tree
, hf_mp2t_pointer
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
954 if (pointer
> remaining_len
) {
956 expert_add_info_format(pinfo
, pi
, &ei_mp2t_pointer
,
957 "Pointer value is too large (> remaining data length %u)",
962 if (!pinfo
->fd
->visited
) {
963 /* Get values from our current PID analysis */
964 frag_cur_pos
= pid_analysis
->frag_cur_pos
;
965 frag_tot_len
= pid_analysis
->frag_tot_len
;
966 fragmentation
= pid_analysis
->fragmentation
;
967 frag_id
= pid_analysis
->frag_id
;
968 pdata
= (packet_analysis_data_t
*)p_get_proto_data(wmem_file_scope(), pinfo
, proto_mp2t
, pinfo
->curr_layer_num
);
970 pdata
= wmem_new0(wmem_file_scope(), packet_analysis_data_t
);
971 pdata
->subpacket_table
= wmem_tree_new(wmem_file_scope());
972 /* Since the subpacket data is indexed by offset in the tvb,
973 * lacking a fragment id transmitted in the protocol,
974 * we need a different table for each mp2t layer.
976 p_add_proto_data(wmem_file_scope(), pinfo
, proto_mp2t
, pinfo
->curr_layer_num
, pdata
);
979 spdata
= (subpacket_analysis_data_t
*)wmem_tree_lookup32(pdata
->subpacket_table
, offset
);
983 spdata
= wmem_new0(wmem_file_scope(), subpacket_analysis_data_t
);
984 /* Save the info into pdata from pid_analysis */
985 spdata
->frag_cur_pos
= frag_cur_pos
;
986 spdata
->frag_tot_len
= frag_tot_len
;
987 spdata
->fragmentation
= fragmentation
;
988 spdata
->frag_id
= frag_id
;
989 wmem_tree_insert32(pdata
->subpacket_table
, offset
, (void *)spdata
);
992 /* Get saved values */
993 pdata
= (packet_analysis_data_t
*)p_get_proto_data(wmem_file_scope(), pinfo
, proto_mp2t
, pinfo
->curr_layer_num
);
995 /* Occurs for the first packets in the capture which cannot be reassembled */
999 spdata
= (subpacket_analysis_data_t
*)wmem_tree_lookup32(pdata
->subpacket_table
, offset
);
1001 /* Occurs for the first sub packets in the capture which cannot be reassembled */
1005 frag_cur_pos
= spdata
->frag_cur_pos
;
1006 frag_tot_len
= spdata
->frag_tot_len
;
1007 fragmentation
= spdata
->fragmentation
;
1008 frag_id
= spdata
->frag_id
;
1011 if (frag_tot_len
== (unsigned)-1) {
1012 /* We couldn't determine the total length of the reassembly from
1013 * the first fragment (too short), so get it now that we have the
1016 frag_tot_len
= mp2t_get_packet_length(tvb
, offset
, pinfo
, frag_id
, pid_analysis
->pload_type
);
1018 if (frag_tot_len
== (unsigned)-1) {
1019 /* We still don't have enough to determine the length; this can
1020 * only happen with dropped or out of order packets. Bail out.
1021 * XXX: This just skips the packet and tries the next one, but
1022 * there are probably better ways to handle it, especially if
1023 * the PUSI flag is set in this packet.
1029 /* The beginning of a new packet is present */
1031 if (pointer
> remaining_len
) {
1033 * Quit, so we don't use the bogus pointer value;
1034 * that could cause remaining_len to become
1035 * "negative", meaning it becomes a very large
1041 /* "pointer" contains the number of bytes until the
1042 * start of the new section
1044 * if the new section does not start immediately after the
1045 * pointer field (i.e. pointer>0), the remaining bytes before the
1046 * start of the section are another fragment of the
1049 * if pointer is 0, a new upper-layer packet starts at the
1050 * beginning of this TS packet
1051 * if we have pending fragments, the last TS packet contained the
1052 * last fragment and at the time we processed it, we couldn't figure
1053 * out that it is the last fragment
1054 * this is the case e.g. for PES packets with a 0 length field
1055 * ("unbounded length")
1056 * to handle this case, we add an empty fragment (pointer==0)
1057 * and reassemble, then we process the current TS packet as
1060 if (fragmentation
) {
1061 mp2t_fragment_handle(tvb
, offset
, pinfo
, tree
, frag_id
, frag_cur_pos
,
1062 pointer
, true, pid_analysis
);
1067 remaining_len
-= pointer
;
1068 fragmentation
= false;
1072 if (!remaining_len
) {
1073 /* Shouldn't happen */
1077 while (remaining_len
> 0) {
1078 /* Don't let subsequent packets overwrite the Info column */
1079 col_append_str(pinfo
->cinfo
, COL_INFO
, " ");
1080 col_set_fence(pinfo
->cinfo
, COL_INFO
);
1082 /* Skip stuff bytes */
1084 while ((tvb_get_uint8(tvb
, offset
+ stuff_len
) == 0xFF)) {
1086 if (stuff_len
>= remaining_len
) {
1093 stuff_tree
= proto_tree_add_subtree_format(tree
, tvb
, offset
, stuff_len
, ett_stuff
, NULL
, "Stuffing");
1094 proto_tree_add_item(stuff_tree
, hf_mp2t_stuff_bytes
, tvb
, offset
, stuff_len
, ENC_NA
);
1095 offset
+= stuff_len
;
1096 if (stuff_len
>= remaining_len
) {
1099 remaining_len
-= stuff_len
;
1102 /* Get the next packet's size if possible */
1103 frag_tot_len
= mp2t_get_packet_length(tvb
, offset
, pinfo
, frag_id
, pid_analysis
->pload_type
);
1104 if (frag_tot_len
== (unsigned)-1 || !frag_tot_len
) {
1105 mp2t_fragment_handle(tvb
, offset
, pinfo
, tree
, frag_id
, 0, remaining_len
, false, pid_analysis
);
1106 fragmentation
= true;
1107 /*offset += remaining_len;*/
1108 frag_cur_pos
+= remaining_len
;
1112 /* Check for full packets within this TS frame */
1113 if (frag_tot_len
<= remaining_len
) {
1114 next_tvb
= tvb_new_subset_length(tvb
, offset
, frag_tot_len
);
1115 mp2t_dissect_packet(next_tvb
, pid_analysis
, pinfo
, tree
);
1116 remaining_len
-= frag_tot_len
;
1117 offset
+= frag_tot_len
;
1125 if (remaining_len
== 0) {
1126 pid_analysis
->frag_cur_pos
= 0;
1127 pid_analysis
->frag_tot_len
= 0;
1134 /* There are remaining bytes. Add them to the fragment list */
1136 if (frag_tot_len
&& frag_cur_pos
+ remaining_len
> frag_tot_len
) {
1137 /* The case where PUSI was 0, a continuing SECT ended, and stuff
1139 stuff_len
= frag_cur_pos
+ remaining_len
- frag_tot_len
;
1140 mp2t_fragment_handle(tvb
, offset
, pinfo
, tree
, frag_id
, frag_cur_pos
, remaining_len
- stuff_len
, true, pid_analysis
);
1141 offset
+= remaining_len
- stuff_len
;
1143 fragmentation
= false;
1146 stuff_tree
= proto_tree_add_subtree_format(tree
, tvb
, offset
, stuff_len
, ett_stuff
, NULL
, "Stuffing");
1147 proto_tree_add_item(stuff_tree
, hf_mp2t_stuff_bytes
, tvb
, offset
, stuff_len
, ENC_NA
);
1148 } else if ((frag_tot_len
&& frag_cur_pos
+ remaining_len
== frag_tot_len
) || (!frag_tot_len
&& pusi_flag
)) {
1149 mp2t_fragment_handle(tvb
, offset
, pinfo
, tree
, frag_id
, frag_cur_pos
, remaining_len
, true, pid_analysis
);
1151 fragmentation
= false;
1155 mp2t_fragment_handle(tvb
, offset
, pinfo
, tree
, frag_id
, frag_cur_pos
, remaining_len
, false, pid_analysis
);
1156 fragmentation
= true;
1157 frag_cur_pos
+= remaining_len
;
1160 /* XXX: Ideally this would be handled with a TRY...FINALLY or
1161 * similar, with more care taken to keep things consistent even
1162 * with fatal errors in subdissectors.
1165 pid_analysis
->fragmentation
= fragmentation
;
1166 pid_analysis
->frag_cur_pos
= frag_cur_pos
;
1167 pid_analysis
->frag_tot_len
= frag_tot_len
;
1168 pid_analysis
->frag_id
= frag_id
;
1173 /* Calc the number of skipped CC numbers. Note that this can easy
1174 * overflow, and a value above 7 indicate several network packets
1178 calc_skips(int32_t curr
, int32_t prev
)
1182 /* Only count the missing TS frames in between prev and curr.
1183 * The "prev" frame CC number seen is confirmed received, it's
1184 * the next frames CC counter which is the first known missing
1189 /* Calc missing TS frame 'skips' */
1192 /* Handle wrap around */
1199 #define KEY(pid, cc) ((pid << 4)|cc)
1202 detect_cc_drops(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
,
1203 uint32_t pid
, int32_t cc_curr
, mp2t_analysis_data_t
*mp2t_data
)
1205 int32_t cc_prev
= -1;
1206 pid_analysis_data_t
*pid_data
= NULL
;
1207 ts_analysis_data_t
*ts_data
= NULL
;
1208 frame_analysis_data_t
*frame_analysis_data_p
= NULL
;
1209 proto_item
*flags_item
;
1211 bool detected_drop
= false;
1214 /* The initial sequential processing stage */
1215 if (!pinfo
->fd
->visited
) {
1216 /* This is the sequential processing stage */
1217 pid_data
= get_pid_analysis(mp2t_data
, pid
);
1219 cc_prev
= pid_data
->cc_prev
;
1220 pid_data
->cc_prev
= cc_curr
;
1222 /* Null packet always have a CC value equal 0 */
1226 /* Its allowed that (cc_prev == cc_curr) if adaptation field */
1227 if (cc_prev
== cc_curr
)
1230 /* Have not seen this pid before */
1234 /* Detect if CC is not increasing by one all the time */
1235 if (cc_curr
!= ((cc_prev
+1) & MP2T_CC_MASK
)) {
1236 detected_drop
= true;
1238 skips
= calc_skips(cc_curr
, cc_prev
);
1240 mp2t_data
->total_skips
+= skips
;
1241 mp2t_data
->total_discontinuity
++;
1242 /* TODO: if (skips > 7) signal_loss++; ??? */
1246 /* Save the info about the dropped packet */
1247 if (detected_drop
&& !pinfo
->fd
->visited
) {
1248 /* Lookup frame data, contains TS pid data objects */
1249 frame_analysis_data_p
= get_frame_analysis_data(mp2t_data
, pinfo
);
1250 if (!frame_analysis_data_p
)
1251 frame_analysis_data_p
= init_frame_analysis_data(mp2t_data
, pinfo
);
1253 /* Create and store a new TS frame pid_data object.
1254 This indicate that we have a drop
1256 ts_data
= wmem_new0(wmem_file_scope(), struct ts_analysis_data
);
1257 ts_data
->cc_prev
= cc_prev
;
1259 ts_data
->skips
= skips
;
1260 wmem_tree_insert32(frame_analysis_data_p
->ts_table
, KEY(pid
, cc_curr
),
1264 /* See if we stored info about drops */
1265 if (pinfo
->fd
->visited
) {
1267 /* Lookup frame data, contains TS pid data objects */
1268 frame_analysis_data_p
= get_frame_analysis_data(mp2t_data
, pinfo
);
1269 if (!frame_analysis_data_p
)
1270 return 0; /* No stored frame data -> no drops*/
1272 ts_data
= (struct ts_analysis_data
*)wmem_tree_lookup32(frame_analysis_data_p
->ts_table
,
1276 if (ts_data
->skips
> 0) {
1277 detected_drop
= true;
1278 cc_prev
= ts_data
->cc_prev
;
1279 skips
= ts_data
->skips
;
1285 /* Add info to the proto tree about drops */
1286 if (detected_drop
) {
1287 expert_add_info_format(pinfo
, tree
, &ei_mp2t_cc_drop
,
1288 "Detected %d missing TS frames before this (last_cc:%d total skips:%d discontinuity:%d)",
1290 mp2t_data
->total_skips
,
1291 mp2t_data
->total_discontinuity
1294 flags_item
= proto_tree_add_uint(tree
, hf_mp2t_analysis_skips
,
1296 proto_item_set_generated(flags_item
);
1298 flags_item
= proto_tree_add_uint(tree
, hf_mp2t_analysis_drops
,
1300 proto_item_set_generated(flags_item
);
1306 dissect_mp2t_adaptation_field(tvbuff_t
*tvb
, int offset
, proto_tree
*tree
)
1308 int af_start_offset
;
1310 proto_tree
*mp2t_af_tree
;
1315 af_length
= tvb_get_uint8(tvb
, offset
);
1316 proto_tree_add_item(tree
, hf_mp2t_af_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1318 /* fix issues where afc==3 but af_length==0
1319 * Adaptaion field...spec section 2.4.3.5: The value 0 is for inserting a single
1320 * stuffing byte in a Transport Stream packet. When the adaptation_field_control
1321 * value is '11', the value of the adaptation_field_length shall be in the range 0 to 182.
1326 af_start_offset
= offset
;
1328 hi
= proto_tree_add_item( tree
, hf_mp2t_af
, tvb
, offset
, af_length
, ENC_NA
);
1329 mp2t_af_tree
= proto_item_add_subtree( hi
, ett_mp2t_af
);
1331 af_flags
= tvb_get_uint8(tvb
, offset
);
1332 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_di
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1333 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_rai
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1334 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_espi
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1335 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_pcr_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1336 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_opcr_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1337 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_sp_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1338 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_tpd_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1339 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_afe_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1342 if (af_flags
& MP2T_AF_PCR_MASK
) {
1346 /* 33 bit PCR base, 6 bit reserved, 9 bit PCR ext */
1347 pcr_base
= tvb_get_ntoh48(tvb
, offset
) >> (48-33);
1348 pcr_ext
= (uint16_t)(tvb_get_ntoh48(tvb
, offset
) & 0x1FF);
1350 proto_tree_add_uint64(mp2t_af_tree
, hf_mp2t_af_pcr
, tvb
, offset
, 6,
1351 pcr_base
*300 + pcr_ext
);
1356 if (af_flags
& MP2T_AF_OPCR_MASK
) {
1360 /* the same format as PCR above */
1361 opcr_base
= tvb_get_ntoh48(tvb
, offset
) >> (48-33);
1362 opcr_ext
= (uint16_t)(tvb_get_ntoh48(tvb
, offset
) & 0x1FF);
1364 proto_tree_add_uint64(mp2t_af_tree
, hf_mp2t_af_opcr
, tvb
, offset
, 6,
1365 opcr_base
*300 + opcr_ext
);
1370 if (af_flags
& MP2T_AF_SP_MASK
) {
1371 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_sc
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1375 if (af_flags
& MP2T_AF_TPD_MASK
) {
1378 tpd_len
= tvb_get_uint8(tvb
, offset
);
1379 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_tpd_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1382 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_tpd
, tvb
, offset
, tpd_len
, ENC_NA
);
1386 if (af_flags
& MP2T_AF_AFE_MASK
) {
1389 int e_start_offset
= offset
;
1390 int reserved_len
= 0;
1392 e_len
= tvb_get_uint8(tvb
, offset
);
1393 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1396 e_flags
= tvb_get_uint8(tvb
, offset
);
1397 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_ltw_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1398 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_pr_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1399 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_ss_flag
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1400 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_reserved
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1403 if (e_flags
& MP2T_AF_E_LTW_FLAG_MASK
) {
1404 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_ltwv_flag
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
1405 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_ltwo
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
1409 if (e_flags
& MP2T_AF_E_PR_FLAG_MASK
) {
1410 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_pr_reserved
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
1411 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_pr
, tvb
, offset
, 3, ENC_BIG_ENDIAN
);
1415 if (e_flags
& MP2T_AF_E_SS_FLAG_MASK
) {
1416 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_st
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1417 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_dnau_32_30
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1418 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_m_1
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
1420 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_dnau_29_15
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
1421 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_m_2
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
1423 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_dnau_14_0
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
1424 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_m_3
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
1428 reserved_len
= (e_len
+ 1) - (offset
- e_start_offset
);
1429 if (reserved_len
> 0) {
1430 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_e_reserved_bytes
, tvb
, offset
, reserved_len
, ENC_NA
);
1431 offset
+= reserved_len
;
1435 stuffing_len
= af_length
- (offset
- af_start_offset
);
1436 if (stuffing_len
> 0) {
1437 proto_tree_add_item( mp2t_af_tree
, hf_mp2t_af_stuffing_bytes
, tvb
, offset
, stuffing_len
, ENC_NA
);
1438 offset
+= stuffing_len
;
1445 dissect_tsp(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
,
1446 proto_tree
*tree
, mp2t_analysis_data_t
*mp2t_data
)
1450 int start_offset
= offset
;
1452 pid_analysis_data_t
*pid_analysis
;
1463 proto_item
*item
= NULL
;
1464 proto_tree
*mp2t_tree
;
1465 proto_tree
*mp2t_header_tree
;
1466 proto_tree
*mp2t_analysis_tree
;
1469 ti
= proto_tree_add_item( tree
, proto_mp2t
, tvb
, offset
, MP2T_PACKET_SIZE
, ENC_NA
);
1470 mp2t_tree
= proto_item_add_subtree( ti
, ett_mp2t
);
1472 header
= tvb_get_ntohl(tvb
, offset
);
1473 pusi_flag
= (header
& 0x00400000);
1474 pid
= (header
& MP2T_PID_MASK
) >> MP2T_PID_SHIFT
;
1475 tsc
= (header
& MP2T_TSC_MASK
);
1476 afc
= (header
& MP2T_AFC_MASK
) >> MP2T_AFC_SHIFT
;
1477 cc
= (header
& MP2T_CC_MASK
) >> MP2T_CC_SHIFT
;
1479 p_add_proto_data(pinfo
->pool
, pinfo
, proto_mp2t
, MP2T_PROTO_DATA_PID
, GUINT_TO_POINTER(pid
));
1480 proto_item_append_text(ti
, " PID=0x%x CC=%d", pid
, cc
);
1481 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MPEG TS");
1483 hi
= proto_tree_add_uint(mp2t_tree
, hf_mp2t_stream
, tvb
, 0, 0, mp2t_data
->stream
);
1484 proto_item_set_generated(hi
);
1486 hi
= proto_tree_add_item( mp2t_tree
, hf_mp2t_header
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1487 mp2t_header_tree
= proto_item_add_subtree( hi
, ett_mp2t_header
);
1489 proto_tree_add_item( mp2t_header_tree
, hf_mp2t_sync_byte
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1490 proto_tree_add_item( mp2t_header_tree
, hf_mp2t_tei
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1491 proto_tree_add_item( mp2t_header_tree
, hf_mp2t_pusi
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1492 proto_tree_add_item( mp2t_header_tree
, hf_mp2t_tp
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1493 proto_tree_add_item( mp2t_header_tree
, hf_mp2t_pid
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1494 proto_tree_add_item( mp2t_header_tree
, hf_mp2t_tsc
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1495 afci
= proto_tree_add_item( mp2t_header_tree
, hf_mp2t_afc
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1496 proto_tree_add_item( mp2t_header_tree
, hf_mp2t_cc
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
1498 pid_analysis
= get_pid_analysis(mp2t_data
, pid
);
1500 if (pid_analysis
->pload_type
== pid_pload_unknown
) {
1501 if (pid
== MP2T_PID_NULL
) {
1502 pid_analysis
->pload_type
= pid_pload_null
;
1503 } else if (pid
== MP2T_PID_DOCSIS
) {
1504 pid_analysis
->pload_type
= pid_pload_docsis
;
1508 if (pid_analysis
->pload_type
== pid_pload_docsis
&& (afc
!= 1)) {
1509 /* DOCSIS packets should not have an adaptation field */
1510 expert_add_info_format(pinfo
, afci
, &ei_mp2t_invalid_afc
,
1511 "Adaptation Field Control for DOCSIS packets must be 0x01");
1514 if (pid_analysis
->pload_type
== pid_pload_null
) {
1515 col_set_str(pinfo
->cinfo
, COL_INFO
, "NULL packet");
1517 expert_add_info_format(pinfo
, afci
, &ei_mp2t_invalid_afc
,
1518 "Adaptation Field Control for NULL packets must be 0x01");
1520 /* Nothing more to do */
1526 /* Create a subtree for analysis stuff */
1527 mp2t_analysis_tree
= proto_tree_add_subtree_format(mp2t_tree
, tvb
, offset
, 0, ett_mp2t_analysis
, &item
, "MPEG2 PCR Analysis");
1528 proto_item_set_generated(item
);
1530 skips
= detect_cc_drops(tvb
, mp2t_analysis_tree
, pinfo
, pid
, cc
, mp2t_data
);
1533 proto_item_append_text(ti
, " skips=%d", skips
);
1535 if (afc
== 2 || afc
== 3)
1536 offset
= dissect_mp2t_adaptation_field(tvb
, offset
, mp2t_tree
);
1538 if ((offset
- start_offset
) < MP2T_PACKET_SIZE
)
1539 payload_len
= MP2T_PACKET_SIZE
- (offset
- start_offset
);
1547 col_set_str(pinfo
->cinfo
, COL_INFO
, "Adaptation field only");
1548 /* The rest of the packet is stuffing bytes */
1549 proto_tree_add_item( mp2t_tree
, hf_mp2t_stuff_bytes
, tvb
, offset
, payload_len
, ENC_NA
);
1550 offset
+= payload_len
;
1554 mp2t_process_fragmented_payload(tvb
, offset
, payload_len
, pinfo
, tree
, mp2t_tree
, pusi_flag
, pid_analysis
);
1556 /* Payload is scrambled */
1557 col_set_str(pinfo
->cinfo
, COL_INFO
, "Scrambled TS payload");
1562 export_pdu(tvbuff_t
*tvb
, packet_info
*pinfo
)
1564 if (have_tap_listener(exported_pdu_tap
)) {
1565 exp_pdu_data_t
*exp_pdu_data
= wmem_new0(pinfo
->pool
, exp_pdu_data_t
);
1567 exp_pdu_data
->tvb_captured_length
= tvb_captured_length(tvb
);
1568 exp_pdu_data
->tvb_reported_length
= tvb_reported_length(tvb
);
1569 exp_pdu_data
->pdu_tvb
= tvb
;
1570 tap_queue_packet(exported_pdu_tap
, pinfo
, exp_pdu_data
);
1575 dissect_mp2t( tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
1577 volatile unsigned offset
= 0;
1578 conversation_t
*conv
;
1579 mp2t_stream_key
*stream
;
1580 mp2t_analysis_data_t
*mp2t_data
;
1581 const char *saved_proto
;
1583 conv
= find_or_create_conversation(pinfo
);
1584 stream
= wmem_new(pinfo
->pool
, mp2t_stream_key
);
1585 stream
->conv
= conv
;
1586 /* Conversations on UDP, etc. are bidirectional, but in the odd case
1587 * that we have two MP2T streams in the opposite directions, we have to
1588 * separately track their Continuity Counters, manage their fragmentation
1589 * status information, etc.
1591 if (addresses_equal(&pinfo
->src
, conversation_key_addr1(conv
->key_ptr
))) {
1592 stream
->dir
= P2P_DIR_SENT
;
1593 } else if (addresses_equal(&pinfo
->dst
, conversation_key_addr1(conv
->key_ptr
))) {
1594 stream
->dir
= P2P_DIR_RECV
;
1596 /* DVB Base Band Frames, or some other endpoint that doesn't set the
1597 * address, presumably unidirectional.
1599 stream
->dir
= P2P_DIR_SENT
;
1602 p_add_proto_data(pinfo
->pool
, pinfo
, proto_mp2t
, MP2T_PROTO_DATA_STREAM
, stream
);
1604 for (; tvb_reported_length_remaining(tvb
, offset
) >= MP2T_PACKET_SIZE
; offset
+= MP2T_PACKET_SIZE
) {
1608 * If it gets an error that means there's no point in
1609 * dissecting any more TSPs, rethrow the exception in
1612 * If it gets any other error, report it and continue, as that
1613 * means that TSP got an error, but that doesn't mean we should
1614 * stop dissecting TSPs within this frame or chunk of reassembled
1617 saved_proto
= pinfo
->current_proto
;
1618 export_pdu(tvb_new_subset_length(tvb
, offset
, MP2T_PACKET_SIZE
), pinfo
);
1620 mp2t_data
= get_mp2t_conversation_data(stream
);
1621 dissect_tsp(tvb
, offset
, pinfo
, tree
, mp2t_data
);
1623 CATCH_NONFATAL_ERRORS
{
1624 show_exception(tvb
, pinfo
, tree
, EXCEPT_CODE
, GET_MESSAGE
);
1627 * Restore the saved protocol as well; we do this after
1628 * show_exception(), so that the "Malformed packet" indication
1629 * shows the protocol for which dissection failed.
1631 pinfo
->current_proto
= saved_proto
;
1635 return tvb_captured_length(tvb
);
1639 heur_dissect_mp2t( tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
1642 unsigned offset
= 0;
1644 length
= tvb_reported_length_remaining(tvb
, offset
);
1646 /* Nothing to check for */
1649 if ((length
% MP2T_PACKET_SIZE
) != 0) {
1650 /* Not a multiple of the MPEG-2 transport packet size */
1653 while (tvb_offset_exists(tvb
, offset
)) {
1654 if (tvb_get_uint8(tvb
, offset
) != MP2T_SYNC_BYTE
) {
1655 /* No sync byte at the appropriate offset */
1658 offset
+= MP2T_PACKET_SIZE
;
1662 dissect_mp2t(tvb
, pinfo
, tree
, data
);
1668 proto_register_mp2t(void)
1670 static hf_register_info hf
[] = {
1671 { &hf_mp2t_stream
, {
1672 "Stream index", "mp2t.stream",
1673 FT_UINT32
, BASE_DEC
, NULL
, 0, NULL
, HFILL
1675 { &hf_mp2t_header
, {
1676 "Header", "mp2t.header",
1677 FT_UINT32
, BASE_HEX
, NULL
, 0, NULL
, HFILL
1679 { &hf_mp2t_sync_byte
, {
1680 "Sync Byte", "mp2t.sync_byte",
1681 FT_UINT32
, BASE_HEX
, VALS(mp2t_sync_byte_vals
), MP2T_SYNC_BYTE_MASK
, NULL
, HFILL
1684 "Transport Error Indicator", "mp2t.tei",
1685 FT_UINT32
, BASE_DEC
, NULL
, MP2T_TEI_MASK
, NULL
, HFILL
1688 "Payload Unit Start Indicator", "mp2t.pusi",
1689 FT_UINT32
, BASE_DEC
, NULL
, MP2T_PUSI_MASK
, NULL
, HFILL
1692 "Transport Priority", "mp2t.tp",
1693 FT_UINT32
, BASE_DEC
, NULL
, MP2T_TP_MASK
, NULL
, HFILL
1697 FT_UINT32
, BASE_HEX
, VALS(mp2t_pid_vals
), MP2T_PID_MASK
, NULL
, HFILL
1700 "Transport Scrambling Control", "mp2t.tsc",
1701 FT_UINT32
, BASE_HEX
, VALS(mp2t_tsc_vals
), MP2T_TSC_MASK
, NULL
, HFILL
1704 "Adaptation Field Control", "mp2t.afc",
1705 FT_UINT32
, BASE_HEX
, VALS(mp2t_afc_vals
) , MP2T_AFC_MASK
, NULL
, HFILL
1708 "Continuity Counter", "mp2t.cc",
1709 FT_UINT32
, BASE_DEC
, NULL
, MP2T_CC_MASK
, NULL
, HFILL
1712 { &hf_mp2t_analysis_flags
, {
1713 "MPEG2-TS Analysis Flags", "mp2t.analysis.flags",
1714 FT_NONE
, BASE_NONE
, NULL
, 0x0,
1715 "This frame has some of the MPEG2 analysis flags set", HFILL
1718 { &hf_mp2t_analysis_skips
, {
1719 "TS Continuity Counter Skips", "mp2t.analysis.skips",
1720 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1721 "Missing TS frames according to CC counter values", HFILL
1723 { &hf_mp2t_analysis_drops
, {
1724 "Some frames dropped", "mp2t.analysis.drops",
1725 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1726 "Discontinuity: A number of TS frames were dropped", HFILL
1729 "Adaptation Field", "mp2t.af",
1730 FT_NONE
, BASE_NONE
, NULL
, 0, NULL
, HFILL
1732 { &hf_mp2t_af_length
, {
1733 "Adaptation Field Length", "mp2t.af.length",
1734 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
1737 "Discontinuity Indicator", "mp2t.af.di",
1738 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_DI_MASK
, NULL
, HFILL
1740 { &hf_mp2t_af_rai
, {
1741 "Random Access Indicator", "mp2t.af.rai",
1742 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_RAI_MASK
, NULL
, HFILL
1744 { &hf_mp2t_af_espi
, {
1745 "Elementary Stream Priority Indicator", "mp2t.af.espi",
1746 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_ESPI_MASK
, NULL
, HFILL
1748 { &hf_mp2t_af_pcr_flag
, {
1749 "PCR Flag", "mp2t.af.pcr_flag",
1750 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_PCR_MASK
, NULL
, HFILL
1752 { &hf_mp2t_af_opcr_flag
, {
1753 "OPCR Flag", "mp2t.af.opcr_flag",
1754 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_OPCR_MASK
, NULL
, HFILL
1756 { &hf_mp2t_af_sp_flag
, {
1757 "Splicing Point Flag", "mp2t.af.sp_flag",
1758 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_SP_MASK
, NULL
, HFILL
1760 { &hf_mp2t_af_tpd_flag
, {
1761 "Transport Private Data Flag", "mp2t.af.tpd_flag",
1762 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_TPD_MASK
, NULL
, HFILL
1764 { &hf_mp2t_af_afe_flag
, {
1765 "Adaptation Field Extension Flag", "mp2t.af.afe_flag",
1766 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_AFE_MASK
, NULL
, HFILL
1768 { &hf_mp2t_af_pcr
, {
1769 "Program Clock Reference", "mp2t.af.pcr",
1770 FT_UINT64
, BASE_HEX
, NULL
, 0, NULL
, HFILL
1772 { &hf_mp2t_af_opcr
, {
1773 "Original Program Clock Reference", "mp2t.af.opcr",
1774 FT_UINT64
, BASE_HEX
, NULL
, 0, NULL
, HFILL
1777 "Splice Countdown", "mp2t.af.sc",
1778 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
1780 { &hf_mp2t_af_tpd_length
, {
1781 "Transport Private Data Length", "mp2t.af.tpd_length",
1782 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
1784 { &hf_mp2t_af_tpd
, {
1785 "Transport Private Data", "mp2t.af.tpd",
1786 FT_BYTES
, BASE_NONE
, NULL
, 0, NULL
, HFILL
1788 { &hf_mp2t_af_e_length
, {
1789 "Adaptation Field Extension Length", "mp2t.af.e_length",
1790 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
1792 { &hf_mp2t_af_e_ltw_flag
, {
1793 "LTW Flag", "mp2t.af.e.ltw_flag",
1794 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_E_LTW_FLAG_MASK
, NULL
, HFILL
1796 { &hf_mp2t_af_e_pr_flag
, {
1797 "Piecewise Rate Flag", "mp2t.af.e.pr_flag",
1798 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_E_PR_FLAG_MASK
, NULL
, HFILL
1800 { &hf_mp2t_af_e_ss_flag
, {
1801 "Seamless Splice Flag", "mp2t.af.e.ss_flag",
1802 FT_UINT8
, BASE_DEC
, NULL
, MP2T_AF_E_SS_FLAG_MASK
, NULL
, HFILL
1804 { &hf_mp2t_af_e_reserved
, {
1805 "Reserved", "mp2t.af.e.reserved",
1806 FT_UINT8
, BASE_DEC
, NULL
, 0x1F, NULL
, HFILL
1808 { &hf_mp2t_af_e_reserved_bytes
, {
1809 "Reserved", "mp2t.af.e.reserved_bytes",
1810 FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
1812 { &hf_mp2t_af_stuffing_bytes
, {
1813 "Stuffing", "mp2t.af.stuffing_bytes",
1814 FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
1816 { &hf_mp2t_af_e_ltwv_flag
, {
1817 "LTW Valid Flag", "mp2t.af.e.ltwv_flag",
1818 FT_UINT16
, BASE_DEC
, NULL
, 0x8000, NULL
, HFILL
1820 { &hf_mp2t_af_e_ltwo
, {
1821 "LTW Offset", "mp2t.af.e.ltwo",
1822 FT_UINT16
, BASE_DEC
, NULL
, 0x7FFF, NULL
, HFILL
1824 { &hf_mp2t_af_e_pr_reserved
, {
1825 "Reserved", "mp2t.af.e.pr_reserved",
1826 FT_UINT24
, BASE_DEC
, NULL
, 0xC00000, NULL
, HFILL
1828 { &hf_mp2t_af_e_pr
, {
1829 "Piecewise Rate", "mp2t.af.e.pr",
1830 FT_UINT24
, BASE_DEC
, NULL
, 0x3FFFFF, NULL
, HFILL
1832 { &hf_mp2t_af_e_st
, {
1833 "Splice Type", "mp2t.af.e.st",
1834 FT_UINT8
, BASE_DEC
, NULL
, 0xF0, NULL
, HFILL
1836 { &hf_mp2t_af_e_dnau_32_30
, {
1837 "DTS Next AU[32...30]", "mp2t.af.e.dnau_32_30",
1838 FT_UINT8
, BASE_DEC
, NULL
, 0x0E, NULL
, HFILL
1840 { &hf_mp2t_af_e_m_1
, {
1841 "Marker Bit", "mp2t.af.e.m_1",
1842 FT_UINT8
, BASE_DEC
, NULL
, 0x01, NULL
, HFILL
1844 { &hf_mp2t_af_e_dnau_29_15
, {
1845 "DTS Next AU[29...15]", "mp2t.af.e.dnau_29_15",
1846 FT_UINT16
, BASE_DEC
, NULL
, 0xFFFE, NULL
, HFILL
1848 { &hf_mp2t_af_e_m_2
, {
1849 "Marker Bit", "mp2t.af.e.m_2",
1850 FT_UINT16
, BASE_DEC
, NULL
, 0x0001, NULL
, HFILL
1852 { &hf_mp2t_af_e_dnau_14_0
, {
1853 "DTS Next AU[14...0]", "mp2t.af.e.dnau_14_0",
1854 FT_UINT16
, BASE_DEC
, NULL
, 0xFFFE, NULL
, HFILL
1856 { &hf_mp2t_af_e_m_3
, {
1857 "Marker Bit", "mp2t.af.e.m_3",
1858 FT_UINT16
, BASE_DEC
, NULL
, 0x0001, NULL
, HFILL
1861 { &hf_mp2t_payload
, {
1862 "Payload", "mp2t.payload",
1863 FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
1866 { &hf_mp2t_stuff_bytes
, {
1867 "Stuffing", "mp2t.stuff_bytes",
1868 FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
1870 { &hf_mp2t_pointer
, {
1871 "Pointer", "mp2t.pointer",
1872 FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
1874 { &hf_msg_fragments
, {
1875 "Message fragments", "mp2t.msg.fragments",
1876 FT_NONE
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1878 { &hf_msg_fragment
, {
1879 "Message fragment", "mp2t.msg.fragment",
1880 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1882 { &hf_msg_fragment_overlap
, {
1883 "Message fragment overlap", "mp2t.msg.fragment.overlap",
1884 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1886 { &hf_msg_fragment_overlap_conflicts
, {
1887 "Message fragment overlapping with conflicting data",
1888 "mp2t.msg.fragment.overlap.conflicts",
1889 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1891 { &hf_msg_fragment_multiple_tails
, {
1892 "Message has multiple tail fragments",
1893 "mp2t.msg.fragment.multiple_tails",
1894 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1896 { &hf_msg_fragment_too_long_fragment
, {
1897 "Message fragment too long", "mp2t.msg.fragment.too_long_fragment",
1898 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1900 { &hf_msg_fragment_error
, {
1901 "Message defragmentation error", "mp2t.msg.fragment.error",
1902 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1904 { &hf_msg_fragment_count
, {
1905 "Message fragment count", "mp2t.msg.fragment.count",
1906 FT_UINT32
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
1908 { &hf_msg_reassembled_in
, {
1909 "Reassembled in", "mp2t.msg.reassembled.in",
1910 FT_FRAMENUM
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1912 { &hf_msg_reassembled_length
, {
1913 "Reassembled MP2T length", "mp2t.msg.reassembled.length",
1914 FT_UINT32
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
1916 { &hf_msg_ts_packet_reassembled
, {
1917 "MPEG TS Packet (reassembled)", "mp2t.ts_packet_reassembled",
1918 FT_NONE
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
1933 static ei_register_info ei
[] = {
1934 { &ei_mp2t_pointer
, { "mp2t.pointer_too_large", PI_MALFORMED
, PI_ERROR
, "Pointer value is too large", EXPFILL
}},
1935 { &ei_mp2t_cc_drop
, { "mp2t.cc.drop", PI_SEQUENCE
, PI_ERROR
, "Detected missing TS frames", EXPFILL
}},
1936 { &ei_mp2t_invalid_afc
, { "mp2t.afc.invalid", PI_PROTOCOL
, PI_WARN
,
1937 "Adaptation Field Control contains an invalid value", EXPFILL
}}
1940 expert_module_t
* expert_mp2t
;
1942 proto_mp2t
= proto_register_protocol("ISO/IEC 13818-1", "MP2T", "mp2t");
1944 mp2t_handle
= register_dissector("mp2t", dissect_mp2t
, proto_mp2t
);
1946 proto_register_field_array(proto_mp2t
, hf
, array_length(hf
));
1947 proto_register_subtree_array(ett
, array_length(ett
));
1948 expert_mp2t
= expert_register_protocol(proto_mp2t
);
1949 expert_register_field_array(expert_mp2t
, ei
, array_length(ei
));
1951 heur_subdissector_list
= register_heur_dissector_list_with_description("mp2t.pid", "Unused", proto_mp2t
);
1952 /* Register init of processing of fragmented DEPI packets */
1953 reassembly_table_register(&mp2t_reassembly_table
,
1954 &mp2t_reassembly_table_functions
);
1956 mp2t_stream_hashtable
= wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), mp2t_stream_hash
, mp2t_stream_equal
);
1958 register_init_routine(mp2t_init
);
1960 exported_pdu_tap
= register_export_pdu_tap_with_encap("MP2T", WTAP_ENCAP_MPEG_2_TS
);
1961 mp2t_follow_tap
= register_tap("mp2t_follow");
1963 /* MPEG2 TS is sometimes carried on UDP or RTP over UDP so using the UDP
1964 * address filter is better than nothing for tshark. */
1965 register_follow_stream(proto_mp2t
, "mp2t_follow", mp2t_follow_conv_filter
, mp2t_follow_index_filter
, udp_follow_address_filter
, udp_port_to_display
, follow_tvb_tap_listener
, mp2t_get_stream_count
, mp2t_get_sub_stream_id
);
1971 proto_reg_handoff_mp2t(void)
1973 heur_dissector_add("udp", heur_dissect_mp2t
, "MP2T over UDP", "mp2t_udp", proto_mp2t
, HEURISTIC_ENABLE
);
1975 dissector_add_uint("rtp.pt", PT_MP2T
, mp2t_handle
);
1976 dissector_add_for_decode_as_with_preference("tcp.port", mp2t_handle
);
1977 dissector_add_for_decode_as_with_preference("udp.port", mp2t_handle
);
1978 heur_dissector_add("usb.bulk", heur_dissect_mp2t
, "MP2T USB bulk endpoint", "mp2t_usb_bulk", proto_mp2t
, HEURISTIC_ENABLE
);
1979 dissector_add_uint("wtap_encap", WTAP_ENCAP_MPEG_2_TS
, mp2t_handle
);
1980 dissector_add_uint("l2tp.pw_type", L2TPv3_PW_DOCSIS_DMPT
, mp2t_handle
);
1981 dissector_add_string("media_type", "video/mp2t", mp2t_handle
);
1983 docsis_handle
= find_dissector("docsis");
1984 mpeg_pes_handle
= find_dissector("mpeg-pes");
1985 mpeg_sect_handle
= find_dissector("mpeg_sect");
1989 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1994 * indent-tabs-mode: nil
1997 * vi: set shiftwidth=4 tabstop=8 expandtab:
1998 * :indentSize=4:tabSize=8:noTabs=true: