Coverage Report

Created: 2026-11-12 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-mpeg-pat.c
Line
Count
Source
1
/* packet-mpeg-pat.c
2
 * Routines for MPEG2 (ISO/ISO 13818-1) Program Associate Table (PAT) dissection
3
 * Copyright 2012, Guy Martin <gmsoft@tuxicoman.be>
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
12
#include "config.h"
13
14
#include <epan/packet.h>
15
#include <epan/tfs.h>
16
#include <wsutil/array.h>
17
#include "packet-mpeg-sect.h"
18
19
void proto_register_mpeg_pat(void);
20
void proto_reg_handoff_mpeg_pat(void);
21
22
static dissector_handle_t mpeg_pat_handle;
23
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;
31
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;
35
36
37
static int ett_mpeg_pat;
38
static int ett_mpeg_pat_prog;
39
40
16
#define MPEG_PAT_RESERVED_MASK                    0xC0
41
16
#define MPEG_PAT_VERSION_NUMBER_MASK              0x3E
42
16
#define MPEG_PAT_CURRENT_NEXT_INDICATOR_MASK      0x01
43
44
16
#define MPEG_PAT_PROGRAM_RESERVED_MASK          0xE000
45
998
#define MPEG_PAT_PROGRAM_MAP_PID_MASK           0x1FFF
46
47
static int
48
dissect_mpeg_pat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
49
80
{
50
80
    unsigned offset = 0, length = 0;
51
80
    uint16_t prog_num, prog_pid;
52
53
80
    proto_item *ti;
54
80
    proto_tree *mpeg_pat_tree;
55
80
    proto_tree *mpeg_pat_prog_tree;
56
57
    /* The TVB should start right after the section_length in the Section packet */
58
59
80
    col_set_str(pinfo->cinfo, COL_INFO, "Program Association Table (PAT)");
60
61
80
    ti = proto_tree_add_item(tree, proto_mpeg_pat, tvb, offset, -1, ENC_NA);
62
80
    mpeg_pat_tree = proto_item_add_subtree(ti, ett_mpeg_pat);
63
64
80
    offset += packet_mpeg_sect_header(tvb, offset, mpeg_pat_tree, &length, NULL);
65
80
    length -= 4;
66
67
80
    proto_tree_add_item(mpeg_pat_tree, hf_mpeg_pat_transport_stream_id, tvb, offset, 2, ENC_BIG_ENDIAN);
68
80
    offset += 2;
69
70
80
    proto_tree_add_item(mpeg_pat_tree, hf_mpeg_pat_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
71
80
    proto_tree_add_item(mpeg_pat_tree, hf_mpeg_pat_version_number, tvb, offset, 1, ENC_BIG_ENDIAN);
72
80
    proto_tree_add_item(mpeg_pat_tree, hf_mpeg_pat_current_next_indicator, tvb, offset, 1, ENC_BIG_ENDIAN);
73
80
    offset += 1;
74
75
80
    proto_tree_add_item(mpeg_pat_tree, hf_mpeg_pat_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
76
80
    offset += 1;
77
78
80
    proto_tree_add_item(mpeg_pat_tree, hf_mpeg_pat_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
79
80
    offset += 1;
80
81
    /* Parse all the programs */
82
1.06k
    while (offset < length) {
83
84
982
        prog_num = tvb_get_ntohs(tvb, offset);
85
982
        prog_pid = tvb_get_ntohs(tvb, offset + 2) & MPEG_PAT_PROGRAM_MAP_PID_MASK;
86
87
982
        mpeg_pat_prog_tree = proto_tree_add_subtree_format(mpeg_pat_tree, tvb, offset, 4,
88
982
                        ett_mpeg_pat_prog, NULL, "Program 0x%04hx -> PID 0x%04hx", prog_num, prog_pid);
89
90
982
        proto_tree_add_item(mpeg_pat_prog_tree, hf_mpeg_pat_program_number, tvb, offset, 2, ENC_BIG_ENDIAN);
91
982
        offset += 2;
92
93
982
        proto_tree_add_item(mpeg_pat_prog_tree, hf_mpeg_pat_program_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
94
982
        proto_tree_add_item(mpeg_pat_prog_tree, hf_mpeg_pat_program_map_pid, tvb, offset, 2, ENC_BIG_ENDIAN);
95
982
        offset += 2;
96
97
982
    }
98
99
80
    offset += packet_mpeg_sect_crc(tvb, pinfo, mpeg_pat_tree, 0, offset);
100
80
    proto_item_set_len(ti, offset);
101
80
    return tvb_captured_length(tvb);
102
80
}
103
104
105
void
106
proto_register_mpeg_pat(void)
107
16
{
108
109
16
    static hf_register_info hf[] = {
110
111
16
        { &hf_mpeg_pat_transport_stream_id, {
112
16
            "Transport Stream ID", "mpeg_pat.tsid",
113
16
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
114
16
        } },
115
116
16
        { &hf_mpeg_pat_reserved, {
117
16
            "Reserved", "mpeg_pat.reserved",
118
16
            FT_UINT8, BASE_HEX, NULL, MPEG_PAT_RESERVED_MASK, NULL, HFILL
119
16
        } },
120
121
16
        { &hf_mpeg_pat_version_number, {
122
16
            "Version Number", "mpeg_pat.version",
123
16
            FT_UINT8, BASE_HEX, NULL, MPEG_PAT_VERSION_NUMBER_MASK, NULL, HFILL
124
16
        } },
125
126
16
        { &hf_mpeg_pat_current_next_indicator, {
127
16
            "Current/Next Indicator", "mpeg_pat.cur_next_ind",
128
16
            FT_BOOLEAN, 8, TFS(&tfs_current_not_yet), MPEG_PAT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
129
16
        } },
130
131
16
        { &hf_mpeg_pat_section_number, {
132
16
            "Section Number", "mpeg_pat.sect_num",
133
16
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
134
16
        } },
135
136
16
        { &hf_mpeg_pat_last_section_number, {
137
16
            "Last Section Number", "mpeg_pat.last_sect_num",
138
16
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
139
16
        } },
140
141
16
        { &hf_mpeg_pat_program_number, {
142
16
            "Program Number", "mpeg_pat.prog_num",
143
16
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
144
16
        } },
145
146
16
        { &hf_mpeg_pat_program_reserved, {
147
16
            "Reserved", "mpeg_pat.prog_reserved",
148
16
            FT_UINT16, BASE_HEX, NULL, MPEG_PAT_PROGRAM_RESERVED_MASK, NULL, HFILL
149
16
        } },
150
151
16
        { &hf_mpeg_pat_program_map_pid, {
152
16
            "Program Map PID", "mpeg_pat.prog_map_pid",
153
16
            FT_UINT16, BASE_HEX, NULL, MPEG_PAT_PROGRAM_MAP_PID_MASK, NULL, HFILL
154
16
        } },
155
156
16
    };
157
158
16
    static int *ett[] = {
159
16
        &ett_mpeg_pat,
160
16
        &ett_mpeg_pat_prog
161
16
    };
162
163
16
    proto_mpeg_pat = proto_register_protocol("MPEG2 Program Association Table", "MPEG PAT", "mpeg_pat");
164
165
16
    proto_register_field_array(proto_mpeg_pat, hf, array_length(hf));
166
16
    proto_register_subtree_array(ett, array_length(ett));
167
168
16
    mpeg_pat_handle = register_dissector("mpeg_pat", dissect_mpeg_pat, proto_mpeg_pat);
169
16
}
170
171
172
void proto_reg_handoff_mpeg_pat(void)
173
16
{
174
16
    dissector_add_uint("mpeg_sect.tid", MPEG_PAT_TID, mpeg_pat_handle);
175
16
}
176
177
/*
178
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
179
 *
180
 * Local variables:
181
 * c-basic-offset: 4
182
 * tab-width: 8
183
 * indent-tabs-mode: nil
184
 * End:
185
 *
186
 * vi: set shiftwidth=4 tabstop=8 expandtab:
187
 * :indentSize=4:tabSize=8:noTabs=true:
188
 */