2 * Routines for MPEG2 (ISO/ISO 13818-1) Program Associate Table (PAT) dissection
3 * Copyright 2012, Guy Martin <gmsoft@tuxicoman.be>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/prefs.h>
32 #include <epan/dissectors/packet-mpeg-sect.h>
34 static int proto_mpeg_pat
= -1;
35 static int hf_mpeg_pat_transport_stream_id
= -1;
36 static int hf_mpeg_pat_reserved
= -1;
37 static int hf_mpeg_pat_version_number
= -1;
38 static int hf_mpeg_pat_current_next_indicator
= -1;
39 static int hf_mpeg_pat_section_number
= -1;
40 static int hf_mpeg_pat_last_section_number
= -1;
42 static int hf_mpeg_pat_program_number
= -1;
43 static int hf_mpeg_pat_program_reserved
= -1;
44 static int hf_mpeg_pat_program_map_pid
= -1;
47 static gint ett_mpeg_pat
= -1;
48 static gint ett_mpeg_pat_prog
= -1;
50 #define MPEG_PAT_TID 0x00
52 #define MPEG_PAT_RESERVED_MASK 0xC0
53 #define MPEG_PAT_VERSION_NUMBER_MASK 0x3E
54 #define MPEG_PAT_CURRENT_NEXT_INDICATOR_MASK 0x01
56 #define MPEG_PAT_PROGRAM_RESERVED_MASK 0xE000
57 #define MPEG_PAT_PROGRAM_MAP_PID_MASK 0x1FFF
59 static const true_false_string mpeg_pat_cur_next_vals
= {
61 "Currently applicable", "Not yet applicable"
66 dissect_mpeg_pat(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
69 guint offset
= 0, length
= 0;
70 guint16 prog_num
, prog_pid
;
73 proto_tree
*mpeg_pat_tree
;
75 proto_tree
*mpeg_pat_prog_tree
;
77 /* The TVB should start right after the section_length in the Section packet */
79 col_set_str(pinfo
->cinfo
, COL_INFO
, "Program Association Table (PAT)");
81 ti
= proto_tree_add_item(tree
, proto_mpeg_pat
, tvb
, offset
, -1, ENC_NA
);
82 mpeg_pat_tree
= proto_item_add_subtree(ti
, ett_mpeg_pat
);
84 offset
+= packet_mpeg_sect_header(tvb
, offset
, mpeg_pat_tree
, &length
, NULL
);
87 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_transport_stream_id
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
90 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_reserved
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
91 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_version_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
92 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_current_next_indicator
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
95 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_section_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
98 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_last_section_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
101 if (offset
>= length
)
105 /* Parse all the programs */
106 while (offset
< length
) {
108 prog_num
= tvb_get_ntohs(tvb
, offset
);
109 prog_pid
= tvb_get_ntohs(tvb
, offset
+ 2) & MPEG_PAT_PROGRAM_MAP_PID_MASK
;
111 pi
= proto_tree_add_text(mpeg_pat_tree
, tvb
, offset
, 4, "Program 0x%04hx -> PID 0x%04hx", prog_num
, prog_pid
);
112 mpeg_pat_prog_tree
= proto_item_add_subtree(pi
, ett_mpeg_pat_prog
);
114 proto_tree_add_item(mpeg_pat_prog_tree
, hf_mpeg_pat_program_number
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
117 proto_tree_add_item(mpeg_pat_prog_tree
, hf_mpeg_pat_program_reserved
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
118 proto_tree_add_item(mpeg_pat_prog_tree
, hf_mpeg_pat_program_map_pid
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
123 offset
+= packet_mpeg_sect_crc(tvb
, pinfo
, mpeg_pat_tree
, 0, offset
);
124 proto_item_set_len(ti
, offset
);
129 proto_register_mpeg_pat(void)
132 static hf_register_info hf
[] = {
134 { &hf_mpeg_pat_transport_stream_id
, {
135 "Transport Stream ID", "mpeg_pat.tsid",
136 FT_UINT16
, BASE_HEX
, NULL
, 0, NULL
, HFILL
139 { &hf_mpeg_pat_reserved
, {
140 "Reserved", "mpeg_pat.reserved",
141 FT_UINT8
, BASE_HEX
, NULL
, MPEG_PAT_RESERVED_MASK
, NULL
, HFILL
144 { &hf_mpeg_pat_version_number
, {
145 "Version Number", "mpeg_pat.version",
146 FT_UINT8
, BASE_HEX
, NULL
, MPEG_PAT_VERSION_NUMBER_MASK
, NULL
, HFILL
149 { &hf_mpeg_pat_current_next_indicator
, {
150 "Current/Next Indicator", "mpeg_pat.cur_next_ind",
151 FT_BOOLEAN
, 8, TFS(&mpeg_pat_cur_next_vals
), MPEG_PAT_CURRENT_NEXT_INDICATOR_MASK
, NULL
, HFILL
154 { &hf_mpeg_pat_section_number
, {
155 "Section Number", "mpeg_pat.sect_num",
156 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
159 { &hf_mpeg_pat_last_section_number
, {
160 "Last Section Number", "mpeg_pat.last_sect_num",
161 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
164 { &hf_mpeg_pat_program_number
, {
165 "Program Number", "mpeg_pat.prog_num",
166 FT_UINT16
, BASE_HEX
, NULL
, 0, NULL
, HFILL
169 { &hf_mpeg_pat_program_reserved
, {
170 "Reserved", "mpeg_pat.prog_reserved",
171 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PAT_PROGRAM_RESERVED_MASK
, NULL
, HFILL
174 { &hf_mpeg_pat_program_map_pid
, {
175 "Program Map PID", "mpeg_pat.prog_map_pid",
176 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PAT_PROGRAM_MAP_PID_MASK
, NULL
, HFILL
181 static gint
*ett
[] = {
186 proto_mpeg_pat
= proto_register_protocol("MPEG2 Program Association Table", "MPEG PAT", "mpeg_pat");
188 proto_register_field_array(proto_mpeg_pat
, hf
, array_length(hf
));
189 proto_register_subtree_array(ett
, array_length(ett
));
194 void proto_reg_handoff_mpeg_pat(void)
196 dissector_handle_t mpeg_pat_handle
;
198 mpeg_pat_handle
= create_dissector_handle(dissect_mpeg_pat
, proto_mpeg_pat
);
199 dissector_add_uint("mpeg_sect.tid", MPEG_PAT_TID
, mpeg_pat_handle
);
203 * Editor modelines - http://www.wireshark.org/tools/modelines.html
208 * indent-tabs-mode: nil
211 * vi: set shiftwidth=4 tabstop=8 expandtab:
212 * :indentSize=4:tabSize=8:noTabs=true: