2 * Routines for MPEG2 (ISO/ISO 13818-1) Program Associate Table (PAT) dissection
3 * Copyright 2012, Guy Martin <gmsoft@tuxicoman.be>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
16 #include <wsutil/array.h>
17 #include "packet-mpeg-sect.h"
19 void proto_register_mpeg_pat(void);
20 void proto_reg_handoff_mpeg_pat(void);
22 static dissector_handle_t mpeg_pat_handle
;
24 static int proto_mpeg_pat
;
25 static int hf_mpeg_pat_transport_stream_id
;
26 static int hf_mpeg_pat_reserved
;
27 static int hf_mpeg_pat_version_number
;
28 static int hf_mpeg_pat_current_next_indicator
;
29 static int hf_mpeg_pat_section_number
;
30 static int hf_mpeg_pat_last_section_number
;
32 static int hf_mpeg_pat_program_number
;
33 static int hf_mpeg_pat_program_reserved
;
34 static int hf_mpeg_pat_program_map_pid
;
37 static int ett_mpeg_pat
;
38 static int ett_mpeg_pat_prog
;
40 #define MPEG_PAT_RESERVED_MASK 0xC0
41 #define MPEG_PAT_VERSION_NUMBER_MASK 0x3E
42 #define MPEG_PAT_CURRENT_NEXT_INDICATOR_MASK 0x01
44 #define MPEG_PAT_PROGRAM_RESERVED_MASK 0xE000
45 #define MPEG_PAT_PROGRAM_MAP_PID_MASK 0x1FFF
48 dissect_mpeg_pat(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
50 unsigned offset
= 0, length
= 0;
51 uint16_t prog_num
, prog_pid
;
54 proto_tree
*mpeg_pat_tree
;
55 proto_tree
*mpeg_pat_prog_tree
;
57 /* The TVB should start right after the section_length in the Section packet */
59 col_set_str(pinfo
->cinfo
, COL_INFO
, "Program Association Table (PAT)");
61 ti
= proto_tree_add_item(tree
, proto_mpeg_pat
, tvb
, offset
, -1, ENC_NA
);
62 mpeg_pat_tree
= proto_item_add_subtree(ti
, ett_mpeg_pat
);
64 offset
+= packet_mpeg_sect_header(tvb
, offset
, mpeg_pat_tree
, &length
, NULL
);
67 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_transport_stream_id
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
70 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_reserved
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
71 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_version_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
72 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_current_next_indicator
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
75 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_section_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
78 proto_tree_add_item(mpeg_pat_tree
, hf_mpeg_pat_last_section_number
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
81 /* Parse all the programs */
82 while (offset
< length
) {
84 prog_num
= tvb_get_ntohs(tvb
, offset
);
85 prog_pid
= tvb_get_ntohs(tvb
, offset
+ 2) & MPEG_PAT_PROGRAM_MAP_PID_MASK
;
87 mpeg_pat_prog_tree
= proto_tree_add_subtree_format(mpeg_pat_tree
, tvb
, offset
, 4,
88 ett_mpeg_pat_prog
, NULL
, "Program 0x%04hx -> PID 0x%04hx", prog_num
, prog_pid
);
90 proto_tree_add_item(mpeg_pat_prog_tree
, hf_mpeg_pat_program_number
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
93 proto_tree_add_item(mpeg_pat_prog_tree
, hf_mpeg_pat_program_reserved
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
94 proto_tree_add_item(mpeg_pat_prog_tree
, hf_mpeg_pat_program_map_pid
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
99 offset
+= packet_mpeg_sect_crc(tvb
, pinfo
, mpeg_pat_tree
, 0, offset
);
100 proto_item_set_len(ti
, offset
);
101 return tvb_captured_length(tvb
);
106 proto_register_mpeg_pat(void)
109 static hf_register_info hf
[] = {
111 { &hf_mpeg_pat_transport_stream_id
, {
112 "Transport Stream ID", "mpeg_pat.tsid",
113 FT_UINT16
, BASE_HEX
, NULL
, 0, NULL
, HFILL
116 { &hf_mpeg_pat_reserved
, {
117 "Reserved", "mpeg_pat.reserved",
118 FT_UINT8
, BASE_HEX
, NULL
, MPEG_PAT_RESERVED_MASK
, NULL
, HFILL
121 { &hf_mpeg_pat_version_number
, {
122 "Version Number", "mpeg_pat.version",
123 FT_UINT8
, BASE_HEX
, NULL
, MPEG_PAT_VERSION_NUMBER_MASK
, NULL
, HFILL
126 { &hf_mpeg_pat_current_next_indicator
, {
127 "Current/Next Indicator", "mpeg_pat.cur_next_ind",
128 FT_BOOLEAN
, 8, TFS(&tfs_current_not_yet
), MPEG_PAT_CURRENT_NEXT_INDICATOR_MASK
, NULL
, HFILL
131 { &hf_mpeg_pat_section_number
, {
132 "Section Number", "mpeg_pat.sect_num",
133 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
136 { &hf_mpeg_pat_last_section_number
, {
137 "Last Section Number", "mpeg_pat.last_sect_num",
138 FT_UINT8
, BASE_DEC
, NULL
, 0, NULL
, HFILL
141 { &hf_mpeg_pat_program_number
, {
142 "Program Number", "mpeg_pat.prog_num",
143 FT_UINT16
, BASE_HEX
, NULL
, 0, NULL
, HFILL
146 { &hf_mpeg_pat_program_reserved
, {
147 "Reserved", "mpeg_pat.prog_reserved",
148 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PAT_PROGRAM_RESERVED_MASK
, NULL
, HFILL
151 { &hf_mpeg_pat_program_map_pid
, {
152 "Program Map PID", "mpeg_pat.prog_map_pid",
153 FT_UINT16
, BASE_HEX
, NULL
, MPEG_PAT_PROGRAM_MAP_PID_MASK
, NULL
, HFILL
158 static int *ett
[] = {
163 proto_mpeg_pat
= proto_register_protocol("MPEG2 Program Association Table", "MPEG PAT", "mpeg_pat");
165 proto_register_field_array(proto_mpeg_pat
, hf
, array_length(hf
));
166 proto_register_subtree_array(ett
, array_length(ett
));
168 mpeg_pat_handle
= register_dissector("mpeg_pat", dissect_mpeg_pat
, proto_mpeg_pat
);
172 void proto_reg_handoff_mpeg_pat(void)
174 dissector_add_uint("mpeg_sect.tid", MPEG_PAT_TID
, mpeg_pat_handle
);
178 * Editor modelines - https://www.wireshark.org/tools/modelines.html
183 * indent-tabs-mode: nil
186 * vi: set shiftwidth=4 tabstop=8 expandtab:
187 * :indentSize=4:tabSize=8:noTabs=true: