e3815b6466636b68fe0e855cbd5e35dbcc0c928c
[obnox/wireshark/wip.git] / epan / dissectors / packet-mp2t.c
1 /* packet-mp2t.c
2  *
3  * Routines for RFC 2250 MPEG2 (ISO/IEC 13818-1) Transport Stream dissection
4  *
5  * $Id$
6  *
7  * Copyright 2006, Erwin Rol <erwin@erwinrol.com>
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <glib.h>
33 #include <epan/packet.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include <epan/rtp_pt.h>
39
40 /* The MPEG2 TS packet size */
41 #define MP2T_PACKET_SIZE 188
42 #define MP2T_SYNC_BYTE 0x47
43
44 static dissector_handle_t pes_handle;
45
46 static int proto_mp2t = -1;
47 static gint ett_mp2t = -1;
48 static gint ett_mp2t_header = -1;
49 static gint ett_mp2t_af = -1;
50
51 static int hf_mp2t_header = -1;
52 static int hf_mp2t_sync_byte = -1;
53 static int hf_mp2t_tei = -1;
54 static int hf_mp2t_pusi = -1;
55 static int hf_mp2t_tp = -1;
56 static int hf_mp2t_pid = -1;
57 static int hf_mp2t_tsc = -1;
58 static int hf_mp2t_afc = -1;
59 static int hf_mp2t_cc = -1;
60
61 #define MP2T_SYNC_BYTE_MASK     0xFF000000
62 #define MP2T_TEI_MASK           0x00800000
63 #define MP2T_PUSI_MASK          0x00400000
64 #define MP2T_TP_MASK            0x00200000
65 #define MP2T_PID_MASK           0x001FFF00
66 #define MP2T_TSC_MASK           0x000000C0
67 #define MP2T_AFC_MASK           0x00000030
68 #define MP2T_CC_MASK            0x0000000F
69
70 #define MP2T_SYNC_BYTE_SHIFT    24
71 #define MP2T_TEI_SHIFT          23
72 #define MP2T_PUSI_SHIFT         22
73 #define MP2T_TP_SHIFT           21
74 #define MP2T_PID_SHIFT          8
75 #define MP2T_TSC_SHIFT          6
76 #define MP2T_AFC_SHIFT          4
77 #define MP2T_CC_SHIFT           0
78
79 static int hf_mp2t_af = -1;
80 static int hf_mp2t_af_length = -1;
81 static int hf_mp2t_af_di = -1;
82 static int hf_mp2t_af_rai = -1;
83 static int hf_mp2t_af_espi = -1;
84 static int hf_mp2t_af_pcr_flag = -1;
85 static int hf_mp2t_af_opcr_flag = -1;
86 static int hf_mp2t_af_sp_flag = -1;
87 static int hf_mp2t_af_tpd_flag = -1;
88 static int hf_mp2t_af_afe_flag = -1;
89
90 #define MP2T_AF_DI_MASK         0x80
91 #define MP2T_AF_RAI_MASK        0x40
92 #define MP2T_AF_ESPI_MASK       0x20
93 #define MP2T_AF_PCR_MASK        0x10
94 #define MP2T_AF_OPCR_MASK       0x08
95 #define MP2T_AF_SP_MASK         0x04
96 #define MP2T_AF_TPD_MASK        0x02
97 #define MP2T_AF_AFE_MASK        0x01
98
99 #define MP2T_AF_DI_SHIFT        7
100 #define MP2T_AF_RAI_SHIFT       6
101 #define MP2T_AF_ESPI_SHIFT      5
102 #define MP2T_AF_PCR_SHIFT       4
103 #define MP2T_AF_OPCR_SHIFT      3
104 #define MP2T_AF_SP_SHIFT        2
105 #define MP2T_AF_TPD_SHIFT       1
106 #define MP2T_AF_AFE_SHIFT       0
107
108 static int hf_mp2t_af_pcr = -1;
109 static int hf_mp2t_af_opcr = -1;
110
111 static int hf_mp2t_af_sc = -1;
112
113 static int hf_mp2t_af_tpd_length = -1;
114 static int hf_mp2t_af_tpd = -1;
115
116 static int hf_mp2t_af_e_length = -1;
117 static int hf_mp2t_af_e_ltw_flag = -1;
118 static int hf_mp2t_af_e_pr_flag = -1;
119 static int hf_mp2t_af_e_ss_flag = -1;
120 static int hf_mp2t_af_e_reserved = -1;
121
122 #define MP2T_AF_E_LTW_FLAG_MASK 0x80 
123 #define MP2T_AF_E_PR_FLAG_MASK  0x40
124 #define MP2T_AF_E_SS_FLAG_MASK  0x20
125
126 static int hf_mp2t_af_e_reserved_bytes = -1;
127 static int hf_mp2t_af_stuffing_bytes = -1;
128
129 static int hf_mp2t_af_e_ltwv_flag = -1;
130 static int hf_mp2t_af_e_ltwo = -1;
131
132 static int hf_mp2t_af_e_pr_reserved = -1;
133 static int hf_mp2t_af_e_pr = -1;
134
135 static int hf_mp2t_af_e_st = -1;
136 static int hf_mp2t_af_e_dnau_32_30 = -1;
137 static int hf_mp2t_af_e_m_1 = -1;
138 static int hf_mp2t_af_e_dnau_29_15 = -1;
139 static int hf_mp2t_af_e_m_2 = -1;
140 static int hf_mp2t_af_e_dnau_14_0 = -1;
141 static int hf_mp2t_af_e_m_3 = -1;
142
143 static int hf_mp2t_payload = -1;
144 static int hf_mp2t_malformed_payload = -1;
145
146 static const value_string mp2t_sync_byte_vals[] = {
147         { MP2T_SYNC_BYTE, "Correct" },
148         { 0, NULL }
149 };
150
151
152 static const value_string mp2t_pid_vals[] = {
153         { 0x0000, "Program Association Table" },
154         { 0x0001, "Conditional Access Table" },
155         { 0x0002, "Transport Stream Description Table" },
156         { 0x0003, "Reserved" },
157         { 0x0004, "Reserved" },
158         { 0x0005, "Reserved" },
159         { 0x0006, "Reserved" },
160         { 0x0007, "Reserved" },
161         { 0x0008, "Reserved" },
162         { 0x0009, "Reserved" },
163         { 0x000A, "Reserved" },
164         { 0x000B, "Reserved" },
165         { 0x000C, "Reserved" },
166         { 0x000D, "Reserved" },
167         { 0x000E, "Reserved" },
168         { 0x000F, "Reserved" },
169         { 0x1FFF, "Null packet" },
170         { 0, NULL }
171 };
172
173 static const value_string mp2t_tsc_vals[] = {
174         { 0, "Not scrambled" },
175         { 1, "User-defined" },
176         { 2, "User-defined" },
177         { 3, "User-defined" },
178         { 0, NULL }
179 };
180
181 static const value_string mp2t_afc_vals[] = {
182         { 0, "Reserved" },
183         { 1, "Payload only" },
184         { 2, "Adaptation Field only" },
185         { 3, "Adaptation Field and Payload" },
186         { 0, NULL }
187 };
188
189 static gint
190 dissect_tsp( tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, proto_tree *tree ) 
191 {
192         guint32 header;
193         guint afc;
194         gint start_offset = offset;
195         gint payload_len;
196
197         proto_item *ti = NULL;
198         proto_item *hi = NULL;
199         proto_tree *mp2t_tree = NULL;
200         proto_tree *mp2t_header_tree = NULL;
201         proto_tree *mp2t_af_tree = NULL;
202
203         ti = proto_tree_add_item( tree, proto_mp2t, tvb, offset, MP2T_PACKET_SIZE, FALSE );
204         mp2t_tree = proto_item_add_subtree( ti, ett_mp2t );
205         
206         header = tvb_get_ntohl(tvb, offset);
207
208         proto_item_append_text(ti, " PID=0x%x CC=%d", (header & MP2T_PID_MASK) >> MP2T_PID_SHIFT, (header & MP2T_CC_MASK) >> MP2T_CC_SHIFT );
209
210
211         hi = proto_tree_add_item( mp2t_tree, hf_mp2t_header, tvb, offset, 4, FALSE);
212         mp2t_header_tree = proto_item_add_subtree( hi, ett_mp2t_header );
213
214         proto_tree_add_item( mp2t_header_tree, hf_mp2t_sync_byte, tvb, offset, 4, FALSE);
215         proto_tree_add_item( mp2t_header_tree, hf_mp2t_tei, tvb, offset, 4, FALSE);
216         proto_tree_add_item( mp2t_header_tree, hf_mp2t_pusi, tvb, offset, 4, FALSE);
217         proto_tree_add_item( mp2t_header_tree, hf_mp2t_tp, tvb, offset, 4, FALSE);
218         proto_tree_add_item( mp2t_header_tree, hf_mp2t_pid, tvb, offset, 4, FALSE);
219         proto_tree_add_item( mp2t_header_tree, hf_mp2t_tsc, tvb, offset, 4, FALSE);
220         proto_tree_add_item( mp2t_header_tree, hf_mp2t_afc, tvb, offset, 4, FALSE);
221         proto_tree_add_item( mp2t_header_tree, hf_mp2t_cc, tvb, offset, 4, FALSE);
222         offset += 4;
223
224         afc = (header & MP2T_AFC_MASK) >> MP2T_AFC_SHIFT;
225
226         if (afc == 2 || afc == 3) 
227         {
228                 gint af_start_offset = offset;
229         
230                 guint8 af_length;
231                 guint8 af_flags;
232                 gint stuffing_len;
233
234
235                 af_length = tvb_get_guint8(tvb, offset);
236
237                 proto_tree_add_item( mp2t_tree, hf_mp2t_af_length, tvb, offset, 1, FALSE);
238                 offset += 1;
239                 /* fix issues where afc==3 but af_length==0 
240                  *  Adaptaion field...spec section 2.4.3.5: The value 0 is for inserting a single 
241                  *  stuffing byte in a Transport Stream packet. When the adaptation_field_control 
242                  *  value is '11', the value of the adaptation_field_length shall be in the range 0 to 182.
243                  */
244                 if (af_length > 0 ) {
245                         hi = proto_tree_add_item( mp2t_tree, hf_mp2t_af, tvb, offset, af_length, FALSE);
246                         mp2t_af_tree = proto_item_add_subtree( hi, ett_mp2t_af );
247         
248                         af_flags = tvb_get_guint8(tvb, offset);
249         
250                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_di, tvb, offset, 1, FALSE);
251                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_rai, tvb, offset, 1, FALSE);
252                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_espi, tvb, offset, 1, FALSE);
253                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_pcr_flag, tvb, offset, 1, FALSE);
254                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_opcr_flag, tvb, offset, 1, FALSE);
255                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_sp_flag, tvb, offset, 1, FALSE);
256                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_tpd_flag, tvb, offset, 1, FALSE);
257                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_afe_flag, tvb, offset, 1, FALSE);
258         
259                         offset += 1;
260         
261                         if (af_flags &  MP2T_AF_PCR_MASK) {
262                                 guint64 pcr_base = 0;
263                                 guint32 pcr_ext = 0;
264                                 guint8 tmp;
265
266                                 tmp = tvb_get_guint8(tvb, offset);
267                                 pcr_base = (pcr_base << 8) | tmp;
268                                 offset += 1;
269                         
270                                 tmp = tvb_get_guint8(tvb, offset);
271                                 pcr_base = (pcr_base << 8) | tmp;
272                                 offset += 1;
273                                 
274                                 tmp = tvb_get_guint8(tvb, offset);
275                                 pcr_base = (pcr_base << 8) | tmp;
276                                 offset += 1;
277         
278                                 tmp = tvb_get_guint8(tvb, offset);
279                                 pcr_base = (pcr_base << 8) | tmp;
280                                 offset += 1;
281
282                                 tmp = tvb_get_guint8(tvb, offset);
283                                 pcr_base = (pcr_base << 1) | ((tmp >> 7) & 0x01);
284                                 pcr_ext = (tmp & 0x01);
285                                 offset += 1;
286
287                                 tmp = tvb_get_guint8(tvb, offset);
288                                 pcr_ext = (pcr_ext << 8) | tmp;
289                                 offset += 1;
290
291                                 proto_tree_add_none_format(mp2t_af_tree, hf_mp2t_af_pcr, tvb, offset - 6, 6, 
292                                                 "Program Clock Reference: base(%" G_GINT64_MODIFIER "u) * 300 + ext(%u) = %" G_GINT64_MODIFIER "u", 
293                                                 pcr_base, pcr_ext, pcr_base * 300 + pcr_ext);
294                         }
295
296                         if (af_flags &  MP2T_AF_OPCR_MASK) {
297                                 guint64 opcr_base = 0;
298                                 guint32 opcr_ext = 0;
299                                 guint8 tmp = 0;
300
301                                 tmp = tvb_get_guint8(tvb, offset);
302                                 opcr_base = (opcr_base << 8) | tmp;
303                                 offset += 1;
304                         
305                                 tmp = tvb_get_guint8(tvb, offset);
306                                 opcr_base = (opcr_base << 8) | tmp;
307                                 offset += 1;
308                         
309                                 tmp = tvb_get_guint8(tvb, offset);
310                                 opcr_base = (opcr_base << 8) | tmp;
311                                 offset += 1;
312         
313                                 tmp = tvb_get_guint8(tvb, offset);
314                                 opcr_base = (opcr_base << 8) | tmp;
315                                 offset += 1;
316
317                                 tmp = tvb_get_guint8(tvb, offset);
318                                 opcr_base = (opcr_base << 1) | ((tmp >> 7) & 0x01);
319                                 opcr_ext = (tmp & 0x01);
320                                 offset += 1;
321
322                                 tmp = tvb_get_guint8(tvb, offset);
323                                 opcr_ext = (opcr_ext << 8) | tmp;
324                                 offset += 1;
325
326                                 proto_tree_add_none_format(mp2t_af_tree, hf_mp2t_af_opcr, tvb, offset - 6, 6, 
327                                                 "Original Program Clock Reference: base(%" G_GINT64_MODIFIER "u) * 300 + ext(%u) = %" G_GINT64_MODIFIER "u", 
328                                                 opcr_base, opcr_ext, opcr_base * 300 + opcr_ext);
329         
330                                 offset += 6;
331                         }
332         
333                         if (af_flags &  MP2T_AF_SP_MASK) {
334                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_sc, tvb, offset, 1, FALSE);
335                                 offset += 1;
336                         }
337
338                         if (af_flags &  MP2T_AF_TPD_MASK) {
339                                 guint8 tpd_len;
340                         
341                                 tpd_len = tvb_get_guint8(tvb, offset);
342                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_tpd_length, tvb, offset, 1, FALSE);
343                                 offset += 1;
344
345                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_tpd, tvb, offset, tpd_len, FALSE);
346                                 offset += tpd_len;
347                         }
348
349                         if (af_flags &  MP2T_AF_AFE_MASK) {
350                                 guint8 e_len;
351                                 guint8 e_flags;
352                                 gint e_start_offset = offset;
353                                 gint reserved_len = 0;
354
355                                 e_len = tvb_get_guint8(tvb, offset);
356                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_length, tvb, offset, 1, FALSE);
357                                 offset += 1;
358
359                                 e_flags = tvb_get_guint8(tvb, offset);
360                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ltw_flag, tvb, offset, 1, FALSE);
361                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_pr_flag, tvb, offset, 1, FALSE);
362                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ss_flag, tvb, offset, 1, FALSE);
363                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_reserved, tvb, offset, 1, FALSE);                       
364                                 offset += 1;
365                         
366                                 if (e_flags & MP2T_AF_E_LTW_FLAG_MASK) {
367                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ltwv_flag, tvb, offset, 2, FALSE);
368                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_ltwo, tvb, offset, 2, FALSE);
369                                         offset += 2;
370                                 }
371
372                                 if (e_flags & MP2T_AF_E_PR_FLAG_MASK) {
373                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_pr_reserved, tvb, offset, 3, FALSE);
374                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_pr, tvb, offset, 3, FALSE);
375                                         offset += 3;
376                                 }
377
378                                 if (e_flags & MP2T_AF_E_SS_FLAG_MASK) {
379                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_st, tvb, offset, 1, FALSE);
380                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_dnau_32_30, tvb, offset, 1, FALSE);
381                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_m_1, tvb, offset, 1, FALSE);
382                                         offset += 1;
383                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_dnau_29_15, tvb, offset, 2, FALSE);
384                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_m_2, tvb, offset, 2, FALSE);
385                                         offset += 2;
386                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_dnau_14_0, tvb, offset, 2, FALSE);
387                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_m_3, tvb, offset, 2, FALSE);
388                                         offset += 2;
389                                 }
390
391                                 reserved_len = (e_len + 1) - (offset - e_start_offset);
392                                 if (reserved_len > 0) {
393                                         proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_e_reserved_bytes, tvb, offset, reserved_len, FALSE);
394                                         offset += reserved_len;
395                                 }
396                         }
397
398                         stuffing_len = (af_length + 1) - (offset - af_start_offset);
399                         if (stuffing_len > 0) {
400                                 proto_tree_add_item( mp2t_af_tree, hf_mp2t_af_stuffing_bytes, tvb, offset, stuffing_len, FALSE);
401                                 offset += stuffing_len;
402                         }
403                 }
404         }
405
406         payload_len = MP2T_PACKET_SIZE - (offset - start_offset);
407         if (payload_len > 0) {
408                 if (afc == 2) { /* AF only */
409                         /* Packet is malformed */
410                         proto_tree_add_item( mp2t_tree, hf_mp2t_malformed_payload, tvb, offset, payload_len, FALSE);
411                         offset += payload_len;
412                 } else {
413                         /* Check to make sure if we are not at end of payload, if we have less than 3 bytes, the tvb_get_ntoh24 fails. */
414                         if (payload_len >=3 ) {
415                                 if (tvb_get_ntoh24(tvb, offset) == 0x000001) {
416                                         tvbuff_t *next_tvb = tvb_new_subset(tvb, offset, payload_len, payload_len);
417                                         call_dissector(pes_handle, next_tvb, pinfo, mp2t_tree);
418                                 } else {
419                                         proto_tree_add_item( mp2t_tree, hf_mp2t_payload, tvb, offset, payload_len, FALSE);
420                                 }
421                         } else {
422                                 proto_tree_add_item( mp2t_tree, hf_mp2t_payload, tvb, offset, payload_len, FALSE);
423                         }
424                         offset += payload_len;
425                 }
426         }
427
428         return offset;
429 }
430
431
432 static void
433 dissect_mp2t( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
434 {
435         guint offset = 0;
436
437         if (tree) {
438                 while ( tvb_reported_length_remaining(tvb, offset) >= MP2T_PACKET_SIZE ) {
439                         offset = dissect_tsp( tvb, offset, pinfo, tree);
440                 }
441         }
442 }
443
444 static gboolean
445 heur_dissect_mp2t( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
446 {
447         guint offset = 0;
448
449         if (tvb_length_remaining(tvb, offset) % MP2T_PACKET_SIZE) {
450                 return FALSE;
451         } else {
452                 while (tvb_length_remaining(tvb, offset)) {
453                         if (tvb_get_guint8(tvb, offset) != MP2T_SYNC_BYTE)
454                                 return FALSE;
455                         offset += MP2T_PACKET_SIZE;
456                 }
457         }
458
459         dissect_mp2t(tvb, pinfo, tree);
460         return TRUE;
461 }
462
463 void
464 proto_register_mp2t(void)
465 {
466         static hf_register_info hf[] = { 
467                 { &hf_mp2t_header, {
468                         "Header", "mp2t.header",
469                         FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL
470                 } } ,
471                 { &hf_mp2t_sync_byte, {
472                         "Sync Byte", "mp2t.sync_byte",
473                         FT_UINT32, BASE_HEX, VALS(mp2t_sync_byte_vals), MP2T_SYNC_BYTE_MASK, NULL, HFILL
474                 } } ,
475                 { &hf_mp2t_tei, { 
476                         "Transport Error Indicator", "mp2t.tei",
477                         FT_UINT32, BASE_DEC, NULL, MP2T_TEI_MASK, NULL, HFILL
478                 } } ,
479                 { &hf_mp2t_pusi, {
480                         "Payload Unit Start Indicator", "mp2t.pusi",
481                         FT_UINT32, BASE_DEC, NULL, MP2T_PUSI_MASK, NULL, HFILL
482                 } } ,
483                 { &hf_mp2t_tp, {
484                         "Transport Priority", "mp2t.tp",
485                         FT_UINT32, BASE_DEC, NULL, MP2T_TP_MASK, NULL, HFILL
486                 } } ,
487                 { &hf_mp2t_pid, {
488                         "PID", "mp2t.pid",
489                         FT_UINT32, BASE_HEX, VALS(mp2t_pid_vals), MP2T_PID_MASK, NULL, HFILL
490                 } } ,
491                 { &hf_mp2t_tsc, {
492                         "Transport Scrambling Control", "mp2t.tsc",
493                         FT_UINT32, BASE_HEX, VALS(mp2t_tsc_vals), MP2T_TSC_MASK, NULL, HFILL
494                 } } ,
495                 { &hf_mp2t_afc, {
496                         "Adaption Field Control", "mp2t.afc",
497                         FT_UINT32, BASE_HEX, VALS(mp2t_afc_vals) , MP2T_AFC_MASK, NULL, HFILL
498                 } } ,
499                 { &hf_mp2t_cc, {
500                         "Continuity Counter", "mp2t.cc",
501                         FT_UINT32, BASE_DEC, NULL, MP2T_CC_MASK, NULL, HFILL
502                 } } ,
503                 { &hf_mp2t_af, {
504                         "Adaption field", "mp2t.af",
505                         FT_NONE, BASE_HEX, NULL, 0, NULL, HFILL
506                 } } ,
507                 { &hf_mp2t_af_length, {
508                         "Adaptation Field Length", "mp2t.af.length",
509                         FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
510                 } } ,
511                 { &hf_mp2t_af_di, {
512                         "Discontinuity Indicator", "mp2t.af.di",
513                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_DI_MASK, NULL, HFILL
514                 } } ,
515                 { &hf_mp2t_af_rai, {
516                         "Random Access Indicator", "mp2t.af.rai",
517                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_RAI_MASK, NULL, HFILL
518                 } } ,
519                 { &hf_mp2t_af_espi, {
520                         "Elementary Stream Priority Indicator", "mp2t.af.espi",
521                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_ESPI_MASK, NULL, HFILL
522                 } } ,
523                 { &hf_mp2t_af_pcr_flag, {
524                         "PCR Flag", "mp2t.af.pcr_flag",
525                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_PCR_MASK, NULL, HFILL
526                 } } ,
527                 { &hf_mp2t_af_opcr_flag, {
528                         "OPCR Flag", "mp2t.af.opcr_flag",
529                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_OPCR_MASK, NULL, HFILL
530                 } } ,
531                 { &hf_mp2t_af_sp_flag, {
532                         "Splicing Point Flag", "mp2t.af.sp_flag",
533                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_SP_MASK, NULL, HFILL
534                 } } ,
535                 { &hf_mp2t_af_tpd_flag, {
536                         "Transport Private Data Flag", "mp2t.af.tpd_flag",
537                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_TPD_MASK, NULL, HFILL
538                 } } ,
539                 { &hf_mp2t_af_afe_flag, {
540                         "Adaptation Field Extension Flag", "mp2t.af.afe_flag",
541                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_AFE_MASK, NULL, HFILL
542                 } } ,
543                 { &hf_mp2t_af_pcr, {
544                         "Program Clock Reference", "mp2t.af.pcr",
545                         FT_NONE, BASE_DEC, NULL, 0, NULL, HFILL
546                 } } ,
547                 { &hf_mp2t_af_opcr, {
548                         "Original Program Clock Reference", "mp2t.af.opcr",
549                         FT_NONE, BASE_DEC, NULL, 0, NULL, HFILL
550                 } } ,
551                 { &hf_mp2t_af_sc, {
552                         "Splice Countdown", "mp2t.af.sc",
553                         FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
554                 } } ,
555                 { &hf_mp2t_af_tpd_length, {
556                         "Transport Private Data Length", "mp2t.af.tpd_length",
557                         FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
558                 } } ,
559                 { &hf_mp2t_af_tpd, {
560                         "Transport Private Data", "mp2t.af.tpd",
561                         FT_BYTES, BASE_DEC, NULL, 0, NULL, HFILL
562                 } } ,
563                 { &hf_mp2t_af_e_length, {
564                         "Adaptation Field Extension Length", "mp2t.af.e_length",
565                         FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
566                 } } ,
567                 { &hf_mp2t_af_e_ltw_flag, {
568                         "LTW Flag", "mp2t.af.e.ltw_flag",
569                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_LTW_FLAG_MASK, NULL, HFILL
570                 } } ,
571                 { &hf_mp2t_af_e_pr_flag, {
572                         "Piecewise Rate Flag", "mp2t.af.e.pr_flag",
573                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_PR_FLAG_MASK, NULL, HFILL
574                 } } ,
575                 { &hf_mp2t_af_e_ss_flag, {
576                         "Seamless Splice Flag", "mp2t.af.e.ss_flag",
577                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_SS_FLAG_MASK, NULL, HFILL
578                 } } ,
579                 { &hf_mp2t_af_e_reserved, {
580                         "Reserved", "mp2t.af.e.reserved",
581                         FT_UINT8, BASE_DEC, NULL, 0x1F, NULL, HFILL
582                 } } ,
583                 { &hf_mp2t_af_e_reserved_bytes, {
584                         "Reserved", "mp2t.af.e.reserved_bytes",
585                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
586                 } } ,
587                 { &hf_mp2t_af_stuffing_bytes, {
588                         "Stuffing", "mp2t.af.stuffing_bytes",
589                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
590                 } } ,
591                 { &hf_mp2t_af_e_ltwv_flag, {
592                         "LTW Valid Flag", "mp2t.af.e.ltwv_flag",
593                         FT_UINT16, BASE_DEC, NULL, 0x8000, NULL, HFILL
594                 } } ,
595                 { &hf_mp2t_af_e_ltwo, {
596                         "LTW Offset", "mp2t.af.e.ltwo",
597                         FT_UINT16, BASE_DEC, NULL, 0x7FFF, NULL, HFILL
598                 } } ,
599                 { &hf_mp2t_af_e_pr_reserved, {
600                         "Reserved", "mp2t.af.e.pr_reserved",
601                         FT_UINT24, BASE_DEC, NULL, 0xC00000, NULL, HFILL
602                 } } ,
603                 { &hf_mp2t_af_e_pr, {
604                         "Piecewise Rate", "mp2t.af.e.pr",
605                         FT_UINT24, BASE_DEC, NULL, 0x3FFFFF, NULL, HFILL
606                 } } ,
607                 { &hf_mp2t_af_e_st, {
608                         "Splice Type", "mp2t.af.e.st",
609                         FT_UINT8, BASE_DEC, NULL, 0xF0, NULL, HFILL
610                 } } ,
611                 { &hf_mp2t_af_e_dnau_32_30, {
612                         "DTS Next AU[32...30]", "mp2t.af.e.dnau_32_30",
613                         FT_UINT8, BASE_DEC, NULL, 0x0E, NULL, HFILL
614                 } } ,
615                 { &hf_mp2t_af_e_m_1, {
616                         "Marker Bit", "mp2t.af.e.m_1",
617                         FT_UINT8, BASE_DEC, NULL, 0x01, NULL, HFILL
618                 } } ,
619                 { &hf_mp2t_af_e_dnau_29_15, {
620                         "DTS Next AU[29...15]", "mp2t.af.e.dnau_29_15",
621                         FT_UINT16, BASE_DEC, NULL, 0xFFFE, NULL, HFILL
622                 } } ,
623                 { &hf_mp2t_af_e_m_2, {
624                         "Marker Bit", "mp2t.af.e.m_2",
625                         FT_UINT16, BASE_DEC, NULL, 0x0001, NULL, HFILL
626                 } } ,
627                 { &hf_mp2t_af_e_dnau_14_0, {
628                         "DTS Next AU[14...0]", "mp2t.af.e.dnau_14_0",
629                         FT_UINT16, BASE_DEC, NULL, 0xFFFE, NULL, HFILL
630                 } } ,
631                 { &hf_mp2t_af_e_m_3, {
632                         "Marker Bit", "mp2t.af.e.m_3",
633                         FT_UINT16, BASE_DEC, NULL, 0x0001, NULL, HFILL
634                 } } ,
635                 { &hf_mp2t_payload, {
636                         "Payload", "mp2t.payload",
637                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
638                 } } ,
639                 { &hf_mp2t_malformed_payload, {
640                         "Malformed Payload", "mp2t.malformed_payload",
641                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
642                 } }
643         };
644
645         static gint *ett[] =
646         {
647                 &ett_mp2t,
648                 &ett_mp2t_header,
649                 &ett_mp2t_af
650         };
651
652         proto_mp2t = proto_register_protocol("ISO/IEC 13818-1", "MP2T", "mp2t");
653         proto_register_field_array(proto_mp2t, hf, array_length(hf));
654         proto_register_subtree_array(ett, array_length(ett));
655 }
656
657
658
659 void
660 proto_reg_handoff_mp2t(void)
661 {
662         dissector_handle_t mp2t_handle;
663
664         heur_dissector_add("udp", heur_dissect_mp2t, proto_mp2t);
665
666         mp2t_handle = create_dissector_handle(dissect_mp2t, proto_mp2t);
667         dissector_add("rtp.pt", PT_MP2T, mp2t_handle);
668         dissector_add("udp.port", 0, mp2t_handle);
669
670         pes_handle = find_dissector("mpeg-pes");
671 }
672