summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-mpeg-pmt.c
blob: a38ce9762729a7e5e65a824876c91204792a4fc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/* packet-mpeg-pmt.c
 * Routines for MPEG2 (ISO/ISO 13818-1) Program Map Table (PMT) dissection
 * Copyright 2012, Guy Martin <gmsoft@tuxicoman.be>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include <epan/packet.h>
#include "packet-mp2t.h"
#include "packet-mpeg-sect.h"
#include "packet-mpeg-descriptor.h"

void proto_register_mpeg_pmt(void);
void proto_reg_handoff_mpeg_pmt(void);

static int proto_mpeg_pmt = -1;
static int hf_mpeg_pmt_program_number = -1;
static int hf_mpeg_pmt_reserved1 = -1;
static int hf_mpeg_pmt_version_number = -1;
static int hf_mpeg_pmt_current_next_indicator = -1;
static int hf_mpeg_pmt_section_number = -1;
static int hf_mpeg_pmt_last_section_number = -1;
static int hf_mpeg_pmt_reserved2 = -1;
static int hf_mpeg_pmt_pcr_pid = -1;
static int hf_mpeg_pmt_reserved3 = -1;
static int hf_mpeg_pmt_program_info_length = -1;


static int hf_mpeg_pmt_stream_type = -1;
static int hf_mpeg_pmt_stream_reserved1 = -1;
static int hf_mpeg_pmt_stream_elementary_pid = -1;
static int hf_mpeg_pmt_stream_reserved2 = -1;
static int hf_mpeg_pmt_stream_es_info_length = -1;

static gint ett_mpeg_pmt = -1;
static gint ett_mpeg_pmt_stream = -1;

static dissector_handle_t mpeg_pmt_handle;

#define MPEG_PMT_RESERVED1_MASK                   0xC0
#define MPEG_PMT_VERSION_NUMBER_MASK              0x3E
#define MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK      0x01

#define MPEG_PMT_RESERVED2_MASK                 0xE000
#define MPEG_PMT_PCR_PID_MASK                   0x1FFF
#define MPEG_PMT_RESERVED3_MASK                 0xF000
#define MPEG_PMT_PROGRAM_INFO_LENGTH_MASK       0x0FFF

#define MPEG_PMT_STREAM_RESERVED1_MASK          0xE000
#define MPEG_PMT_STREAM_ELEMENTARY_PID_MASK     0x1FFF

#define MPEG_PMT_STREAM_RESERVED2_MASK          0xF000
#define MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK     0x0FFF


static const value_string mpeg_pmt_stream_type_vals[] = {
    { 0x00, "ITU-T | ISO/IEC Reserved" },
    { 0x01, "ISO/IEC 11172 Video" },
    { 0x02, "ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream" },
    { 0x03, "ISO/IEC 11172 Audio" },
    { 0x04, "ISO/IEC 13818-3 Audio" },
    { 0x05, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections" },
    { 0x06, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data" },
    { 0x07, "ISO/IEC 13522 MHEG" },
    { 0x08, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC" },
    { 0x09, "ITU-T Rec. H.222.1" },
    { 0x0A, "ISO/IEC 13818-6 type A" },
    { 0x0B, "ISO/IEC 13818-6 type B" },
    { 0x0C, "ISO/IEC 13818-6 type C" },
    { 0x0D, "ISO/IEC 13818-6 type D" },
    { 0x0E, "ITU-T Rec. H.222.0 | ISO/IEC 13818-1 auxiliary" },
    { 0x0F, "ISO/IEC 13818-7 Audio with ADTS transport syntax" },
    { 0x10, "ISO/IEC 14496-2 Visual" },
    { 0x11, "ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3 / AMD 1" },
    { 0x12, "ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets" },
    { 0x13, "ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC14496_sections" },
    { 0x14, "ISO/IEC 13818-6 Synchronized Download Protocol" },
    { 0x15, "Metadata carried in PES packets" },
    { 0x16, "Metadata carried in metadata sections" },
    { 0x17, "Metadata carried in ISO/IEC 13818-6 Data Carousel" },
    { 0x18, "Metadata carried in ISO/IEC 13818-6 Object Carousel" },
    { 0x19, "Metadata carried in ISO/IEC 13818-6 Synchronized Download Protocol" },
    { 0x1A, "IPMP stream (defined in ISO/IEC 13818-11, MPEG-2 IPMP)" },
    { 0x1B, "AVC video stream as defined in ITU-T Rec. H.264 | ISO/IEC 14496-10 Video" },
    { 0x24, "ITU-T Rec. H.265 and ISO/IEC 23008-2 (Ultra HD video) in a packetized stream" },
    { 0x7F, "IPMP stream" },
    { 0x81, "ATSC A/52 Audio" },
    { 0x86, "SCTE-35 Splice Information" },
    { 0xA1, "ETV-AM BIF Data Stream" },
    { 0xC0, "ETV-AM EISS Signaling" },
    { 0x00, NULL }
};
value_string_ext mpeg_pmt_stream_type_vals_ext = VALUE_STRING_EXT_INIT(mpeg_pmt_stream_type_vals);

static int
dissect_mpeg_pmt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{

    guint   offset = 0, length = 0;
    guint   prog_info_len, es_info_len;
    guint32 stream_type;
    guint16 pid;
    gboolean current;

    proto_item *ti;
    proto_tree *mpeg_pmt_tree;
    proto_tree *mpeg_pmt_stream_tree;

    /* The TVB should start right after the section_length in the Section packet */

    col_set_str(pinfo->cinfo, COL_INFO, "Program Map Table (PMT)");

    ti = proto_tree_add_item(tree, proto_mpeg_pmt, tvb, offset, -1, ENC_NA);
    mpeg_pmt_tree = proto_item_add_subtree(ti, ett_mpeg_pmt);

    offset += packet_mpeg_sect_header(tvb, offset, mpeg_pmt_tree, &length, NULL);
    length -= 4;

    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_program_number, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved1, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_version_number, tvb, offset, 1, ENC_BIG_ENDIAN);
    proto_tree_add_item_ret_boolean(mpeg_pmt_tree, hf_mpeg_pmt_current_next_indicator, tvb, offset, 1, ENC_BIG_ENDIAN, &current);
    offset += 1;

    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
    offset += 1;

    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved2, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_pcr_pid, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    prog_info_len = tvb_get_ntohs(tvb, offset) & MPEG_PMT_PROGRAM_INFO_LENGTH_MASK;
    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_reserved3, tvb, offset, 2, ENC_BIG_ENDIAN);
    proto_tree_add_item(mpeg_pmt_tree, hf_mpeg_pmt_program_info_length, tvb, offset, 2, ENC_BIG_ENDIAN);
    offset += 2;

    offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, prog_info_len, mpeg_pmt_tree);

    while (offset < length) {

        pid = tvb_get_ntohs(tvb, offset + 1) & MPEG_PMT_STREAM_ELEMENTARY_PID_MASK;
        es_info_len = tvb_get_ntohs(tvb, offset + 3) & MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK;

        mpeg_pmt_stream_tree = proto_tree_add_subtree_format(mpeg_pmt_tree, tvb, offset, 5 + es_info_len,
                            ett_mpeg_pmt_stream, NULL, "Stream PID=0x%04hx", pid);

        proto_tree_add_item_ret_uint(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_type,      tvb, offset, 1, ENC_BIG_ENDIAN, &stream_type);
        if (current) {
            mp2t_add_stream_type(pinfo, pid, stream_type);
        }
        offset += 1;

        proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_reserved1,     tvb, offset, 2, ENC_BIG_ENDIAN);
        proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_elementary_pid,    tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_reserved2,     tvb, offset, 2, ENC_BIG_ENDIAN);
        proto_tree_add_item(mpeg_pmt_stream_tree, hf_mpeg_pmt_stream_es_info_length,    tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, es_info_len, mpeg_pmt_stream_tree);
    }

    offset += packet_mpeg_sect_crc(tvb, pinfo, mpeg_pmt_tree, 0, offset);

    proto_item_set_len(ti, offset);
    return offset;
}


void
proto_register_mpeg_pmt(void)
{

    static hf_register_info hf[] = {

        { &hf_mpeg_pmt_program_number, {
            "Program Number", "mpeg_pmt.pg_num",
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
        } },

        { &hf_mpeg_pmt_reserved1, {
            "Reserved", "mpeg_pmt.reserved1",
            FT_UINT8, BASE_HEX, NULL, MPEG_PMT_RESERVED1_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_version_number, {
            "Version Number", "mpeg_pmt.version",
            FT_UINT8, BASE_HEX, NULL, MPEG_PMT_VERSION_NUMBER_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_current_next_indicator, {
            "Current/Next Indicator", "mpeg_pmt.cur_next_ind",
            FT_BOOLEAN, 8, TFS(&tfs_current_not_yet), MPEG_PMT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_section_number, {
            "Section Number", "mpeg_pmt.sect_num",
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
        } },

        { &hf_mpeg_pmt_last_section_number, {
            "Last Section Number", "mpeg_pmt.last_sect_num",
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
        } },

        { &hf_mpeg_pmt_reserved2, {
            "Reserved", "mpeg_pmt.reserved2",
            FT_UINT16, BASE_HEX, NULL, MPEG_PMT_RESERVED2_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_pcr_pid, {
            "PCR PID", "mpeg_pmt.pcr_pid",
            FT_UINT16, BASE_HEX, NULL, MPEG_PMT_PCR_PID_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_reserved3, {
            "Reserved", "mpeg_pmt.reserved3",
            FT_UINT16, BASE_HEX, NULL, MPEG_PMT_RESERVED3_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_program_info_length, {
            "Program Info Length", "mpeg_pmt.prog_info_len",
            FT_UINT16, BASE_DEC, NULL, MPEG_PMT_PROGRAM_INFO_LENGTH_MASK, NULL, HFILL
        } },


        { &hf_mpeg_pmt_stream_type, {
            "Stream type", "mpeg_pmt.stream.type",
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &mpeg_pmt_stream_type_vals_ext, 0, NULL, HFILL
        } },

        { &hf_mpeg_pmt_stream_reserved1, {
            "Reserved", "mpeg_pmt.stream.reserved1",
            FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_RESERVED1_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_stream_elementary_pid, {
            "Elementary PID", "mpeg_pmt.stream.elementary_pid",
            FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_ELEMENTARY_PID_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_stream_reserved2, {
            "Reserved", "mpeg_pmt.stream.reserved2",
            FT_UINT16, BASE_HEX, NULL, MPEG_PMT_STREAM_RESERVED2_MASK, NULL, HFILL
        } },

        { &hf_mpeg_pmt_stream_es_info_length, {
            "ES Info Length", "mpeg_pmt.stream.es_info_len",
            FT_UINT16, BASE_DEC, NULL, MPEG_PMT_STREAM_ES_INFO_LENGTH_MASK, NULL, HFILL
        } },

    };

    static gint *ett[] = {
        &ett_mpeg_pmt,
        &ett_mpeg_pmt_stream,
    };

    proto_mpeg_pmt = proto_register_protocol("MPEG2 Program Map Table", "MPEG PMT", "mpeg_pmt");

    proto_register_field_array(proto_mpeg_pmt, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    mpeg_pmt_handle = register_dissector("mpeg_pmt", dissect_mpeg_pmt, proto_mpeg_pmt);
}


void
proto_reg_handoff_mpeg_pmt(void)
{
    dissector_add_uint("mpeg_sect.tid", MPEG_PMT_TID, mpeg_pmt_handle);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */