Let the dissector call its subdissectors, even when tree==NULL.
[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, 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         while ( tvb_reported_length_remaining(tvb, offset) >= MP2T_PACKET_SIZE ) {
438                 offset = dissect_tsp( tvb, offset, pinfo, tree);
439         }
440 }
441
442 static gboolean
443 heur_dissect_mp2t( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree )
444 {
445         guint offset = 0;
446
447         if (tvb_length_remaining(tvb, offset) % MP2T_PACKET_SIZE) {
448                 return FALSE;
449         } else {
450                 while (tvb_length_remaining(tvb, offset)) {
451                         if (tvb_get_guint8(tvb, offset) != MP2T_SYNC_BYTE)
452                                 return FALSE;
453                         offset += MP2T_PACKET_SIZE;
454                 }
455         }
456
457         dissect_mp2t(tvb, pinfo, tree);
458         return TRUE;
459 }
460
461 void
462 proto_register_mp2t(void)
463 {
464         static hf_register_info hf[] = { 
465                 { &hf_mp2t_header, {
466                         "Header", "mp2t.header",
467                         FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL
468                 } } ,
469                 { &hf_mp2t_sync_byte, {
470                         "Sync Byte", "mp2t.sync_byte",
471                         FT_UINT32, BASE_HEX, VALS(mp2t_sync_byte_vals), MP2T_SYNC_BYTE_MASK, NULL, HFILL
472                 } } ,
473                 { &hf_mp2t_tei, { 
474                         "Transport Error Indicator", "mp2t.tei",
475                         FT_UINT32, BASE_DEC, NULL, MP2T_TEI_MASK, NULL, HFILL
476                 } } ,
477                 { &hf_mp2t_pusi, {
478                         "Payload Unit Start Indicator", "mp2t.pusi",
479                         FT_UINT32, BASE_DEC, NULL, MP2T_PUSI_MASK, NULL, HFILL
480                 } } ,
481                 { &hf_mp2t_tp, {
482                         "Transport Priority", "mp2t.tp",
483                         FT_UINT32, BASE_DEC, NULL, MP2T_TP_MASK, NULL, HFILL
484                 } } ,
485                 { &hf_mp2t_pid, {
486                         "PID", "mp2t.pid",
487                         FT_UINT32, BASE_HEX, VALS(mp2t_pid_vals), MP2T_PID_MASK, NULL, HFILL
488                 } } ,
489                 { &hf_mp2t_tsc, {
490                         "Transport Scrambling Control", "mp2t.tsc",
491                         FT_UINT32, BASE_HEX, VALS(mp2t_tsc_vals), MP2T_TSC_MASK, NULL, HFILL
492                 } } ,
493                 { &hf_mp2t_afc, {
494                         "Adaption Field Control", "mp2t.afc",
495                         FT_UINT32, BASE_HEX, VALS(mp2t_afc_vals) , MP2T_AFC_MASK, NULL, HFILL
496                 } } ,
497                 { &hf_mp2t_cc, {
498                         "Continuity Counter", "mp2t.cc",
499                         FT_UINT32, BASE_DEC, NULL, MP2T_CC_MASK, NULL, HFILL
500                 } } ,
501                 { &hf_mp2t_af, {
502                         "Adaption field", "mp2t.af",
503                         FT_NONE, BASE_HEX, NULL, 0, NULL, HFILL
504                 } } ,
505                 { &hf_mp2t_af_length, {
506                         "Adaptation Field Length", "mp2t.af.length",
507                         FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
508                 } } ,
509                 { &hf_mp2t_af_di, {
510                         "Discontinuity Indicator", "mp2t.af.di",
511                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_DI_MASK, NULL, HFILL
512                 } } ,
513                 { &hf_mp2t_af_rai, {
514                         "Random Access Indicator", "mp2t.af.rai",
515                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_RAI_MASK, NULL, HFILL
516                 } } ,
517                 { &hf_mp2t_af_espi, {
518                         "Elementary Stream Priority Indicator", "mp2t.af.espi",
519                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_ESPI_MASK, NULL, HFILL
520                 } } ,
521                 { &hf_mp2t_af_pcr_flag, {
522                         "PCR Flag", "mp2t.af.pcr_flag",
523                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_PCR_MASK, NULL, HFILL
524                 } } ,
525                 { &hf_mp2t_af_opcr_flag, {
526                         "OPCR Flag", "mp2t.af.opcr_flag",
527                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_OPCR_MASK, NULL, HFILL
528                 } } ,
529                 { &hf_mp2t_af_sp_flag, {
530                         "Splicing Point Flag", "mp2t.af.sp_flag",
531                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_SP_MASK, NULL, HFILL
532                 } } ,
533                 { &hf_mp2t_af_tpd_flag, {
534                         "Transport Private Data Flag", "mp2t.af.tpd_flag",
535                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_TPD_MASK, NULL, HFILL
536                 } } ,
537                 { &hf_mp2t_af_afe_flag, {
538                         "Adaptation Field Extension Flag", "mp2t.af.afe_flag",
539                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_AFE_MASK, NULL, HFILL
540                 } } ,
541                 { &hf_mp2t_af_pcr, {
542                         "Program Clock Reference", "mp2t.af.pcr",
543                         FT_NONE, BASE_DEC, NULL, 0, NULL, HFILL
544                 } } ,
545                 { &hf_mp2t_af_opcr, {
546                         "Original Program Clock Reference", "mp2t.af.opcr",
547                         FT_NONE, BASE_DEC, NULL, 0, NULL, HFILL
548                 } } ,
549                 { &hf_mp2t_af_sc, {
550                         "Splice Countdown", "mp2t.af.sc",
551                         FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
552                 } } ,
553                 { &hf_mp2t_af_tpd_length, {
554                         "Transport Private Data Length", "mp2t.af.tpd_length",
555                         FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
556                 } } ,
557                 { &hf_mp2t_af_tpd, {
558                         "Transport Private Data", "mp2t.af.tpd",
559                         FT_BYTES, BASE_DEC, NULL, 0, NULL, HFILL
560                 } } ,
561                 { &hf_mp2t_af_e_length, {
562                         "Adaptation Field Extension Length", "mp2t.af.e_length",
563                         FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
564                 } } ,
565                 { &hf_mp2t_af_e_ltw_flag, {
566                         "LTW Flag", "mp2t.af.e.ltw_flag",
567                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_LTW_FLAG_MASK, NULL, HFILL
568                 } } ,
569                 { &hf_mp2t_af_e_pr_flag, {
570                         "Piecewise Rate Flag", "mp2t.af.e.pr_flag",
571                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_PR_FLAG_MASK, NULL, HFILL
572                 } } ,
573                 { &hf_mp2t_af_e_ss_flag, {
574                         "Seamless Splice Flag", "mp2t.af.e.ss_flag",
575                         FT_UINT8, BASE_DEC, NULL, MP2T_AF_E_SS_FLAG_MASK, NULL, HFILL
576                 } } ,
577                 { &hf_mp2t_af_e_reserved, {
578                         "Reserved", "mp2t.af.e.reserved",
579                         FT_UINT8, BASE_DEC, NULL, 0x1F, NULL, HFILL
580                 } } ,
581                 { &hf_mp2t_af_e_reserved_bytes, {
582                         "Reserved", "mp2t.af.e.reserved_bytes",
583                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
584                 } } ,
585                 { &hf_mp2t_af_stuffing_bytes, {
586                         "Stuffing", "mp2t.af.stuffing_bytes",
587                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
588                 } } ,
589                 { &hf_mp2t_af_e_ltwv_flag, {
590                         "LTW Valid Flag", "mp2t.af.e.ltwv_flag",
591                         FT_UINT16, BASE_DEC, NULL, 0x8000, NULL, HFILL
592                 } } ,
593                 { &hf_mp2t_af_e_ltwo, {
594                         "LTW Offset", "mp2t.af.e.ltwo",
595                         FT_UINT16, BASE_DEC, NULL, 0x7FFF, NULL, HFILL
596                 } } ,
597                 { &hf_mp2t_af_e_pr_reserved, {
598                         "Reserved", "mp2t.af.e.pr_reserved",
599                         FT_UINT24, BASE_DEC, NULL, 0xC00000, NULL, HFILL
600                 } } ,
601                 { &hf_mp2t_af_e_pr, {
602                         "Piecewise Rate", "mp2t.af.e.pr",
603                         FT_UINT24, BASE_DEC, NULL, 0x3FFFFF, NULL, HFILL
604                 } } ,
605                 { &hf_mp2t_af_e_st, {
606                         "Splice Type", "mp2t.af.e.st",
607                         FT_UINT8, BASE_DEC, NULL, 0xF0, NULL, HFILL
608                 } } ,
609                 { &hf_mp2t_af_e_dnau_32_30, {
610                         "DTS Next AU[32...30]", "mp2t.af.e.dnau_32_30",
611                         FT_UINT8, BASE_DEC, NULL, 0x0E, NULL, HFILL
612                 } } ,
613                 { &hf_mp2t_af_e_m_1, {
614                         "Marker Bit", "mp2t.af.e.m_1",
615                         FT_UINT8, BASE_DEC, NULL, 0x01, NULL, HFILL
616                 } } ,
617                 { &hf_mp2t_af_e_dnau_29_15, {
618                         "DTS Next AU[29...15]", "mp2t.af.e.dnau_29_15",
619                         FT_UINT16, BASE_DEC, NULL, 0xFFFE, NULL, HFILL
620                 } } ,
621                 { &hf_mp2t_af_e_m_2, {
622                         "Marker Bit", "mp2t.af.e.m_2",
623                         FT_UINT16, BASE_DEC, NULL, 0x0001, NULL, HFILL
624                 } } ,
625                 { &hf_mp2t_af_e_dnau_14_0, {
626                         "DTS Next AU[14...0]", "mp2t.af.e.dnau_14_0",
627                         FT_UINT16, BASE_DEC, NULL, 0xFFFE, NULL, HFILL
628                 } } ,
629                 { &hf_mp2t_af_e_m_3, {
630                         "Marker Bit", "mp2t.af.e.m_3",
631                         FT_UINT16, BASE_DEC, NULL, 0x0001, NULL, HFILL
632                 } } ,
633                 { &hf_mp2t_payload, {
634                         "Payload", "mp2t.payload",
635                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
636                 } } ,
637                 { &hf_mp2t_malformed_payload, {
638                         "Malformed Payload", "mp2t.malformed_payload",
639                         FT_BYTES, BASE_DEC, NULL, 0x0, NULL, HFILL
640                 } }
641         };
642
643         static gint *ett[] =
644         {
645                 &ett_mp2t,
646                 &ett_mp2t_header,
647                 &ett_mp2t_af
648         };
649
650         proto_mp2t = proto_register_protocol("ISO/IEC 13818-1", "MP2T", "mp2t");
651         proto_register_field_array(proto_mp2t, hf, array_length(hf));
652         proto_register_subtree_array(ett, array_length(ett));
653 }
654
655
656
657 void
658 proto_reg_handoff_mp2t(void)
659 {
660         dissector_handle_t mp2t_handle;
661
662         heur_dissector_add("udp", heur_dissect_mp2t, proto_mp2t);
663
664         mp2t_handle = create_dissector_handle(dissect_mp2t, proto_mp2t);
665         dissector_add("rtp.pt", PT_MP2T, mp2t_handle);
666         dissector_add("udp.port", 0, mp2t_handle);
667
668         pes_handle = find_dissector("mpeg-pes");
669 }
670