Coverage Report

Created: 2025-08-04 07:15

/src/wireshark/epan/dissectors/packet-dvb-nit.c
Line
Count
Source
1
/* packet-dvb-nit.c
2
 * Routines for DVB (ETSI EN 300 468) Network Information Table (NIT) 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 "packet-mpeg-sect.h"
17
#include "packet-mpeg-descriptor.h"
18
19
void proto_register_dvb_nit(void);
20
void proto_reg_handoff_dvb_nit(void);
21
22
static int proto_dvb_nit;
23
static int hf_dvb_nit_network_id;
24
static int hf_dvb_nit_reserved1;
25
static int hf_dvb_nit_version_number;
26
static int hf_dvb_nit_current_next_indicator;
27
static int hf_dvb_nit_section_number;
28
static int hf_dvb_nit_last_section_number;
29
static int hf_dvb_nit_reserved2;
30
31
static int hf_dvb_nit_network_descriptors_length;
32
static int hf_dvb_nit_reserved3;
33
static int hf_dvb_nit_transport_stream_loop_length;
34
35
static int hf_dvb_nit_transport_stream_id;
36
static int hf_dvb_nit_original_network_id;
37
static int hf_dvb_nit_reserved4;
38
static int hf_dvb_nit_transport_descriptors_length;
39
40
static int ett_dvb_nit;
41
static int ett_dvb_nit_ts;
42
43
static dissector_handle_t dvb_nit_handle;
44
45
14
#define DVB_NIT_RESERVED1_MASK                            0xC0
46
14
#define DVB_NIT_VERSION_NUMBER_MASK                       0x3E
47
14
#define DVB_NIT_CURRENT_NEXT_INDICATOR_MASK               0x01
48
14
#define DVB_NIT_RESERVED2_MASK                          0xF000
49
30
#define DVB_NIT_NETWORK_DESCRIPTORS_LENGTH_MASK         0x0FFF
50
14
#define DVB_NIT_RESERVED3_MASK                          0xF000
51
30
#define DVB_NIT_TRANSPORT_STREAM_LOOP_LENGTH_MASK       0x0FFF
52
14
#define DVB_NIT_RESERVED4_MASK                          0xF000
53
32
#define DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK       0x0FFF
54
55
static int
56
dissect_dvb_nit(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
57
16
{
58
59
16
    unsigned    offset = 0;
60
16
    unsigned    ts_desc_len, desc_loop_len, ts_end;
61
62
16
    uint16_t    tsid;
63
64
16
    proto_item *ti;
65
16
    proto_tree *dvb_nit_tree;
66
16
    proto_tree *dvb_nit_ts_tree;
67
68
16
    col_set_str(pinfo->cinfo, COL_INFO, "Network Information Table (NIT)");
69
70
16
    ti = proto_tree_add_item(tree, proto_dvb_nit, tvb, offset, -1, ENC_NA);
71
16
    dvb_nit_tree = proto_item_add_subtree(ti, ett_dvb_nit);
72
73
16
    offset += packet_mpeg_sect_header(tvb, offset, dvb_nit_tree, NULL, NULL);
74
75
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_network_id,                 tvb, offset, 2, ENC_BIG_ENDIAN);
76
16
    offset += 2;
77
78
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_reserved1,                  tvb, offset, 1, ENC_BIG_ENDIAN);
79
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_version_number,             tvb, offset, 1, ENC_BIG_ENDIAN);
80
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_current_next_indicator,     tvb, offset, 1, ENC_BIG_ENDIAN);
81
16
    offset += 1;
82
83
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_section_number,             tvb, offset, 1, ENC_BIG_ENDIAN);
84
16
    offset += 1;
85
86
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_last_section_number,        tvb, offset, 1, ENC_BIG_ENDIAN);
87
16
    offset += 1;
88
89
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_reserved2,                  tvb, offset, 2, ENC_BIG_ENDIAN);
90
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_network_descriptors_length, tvb, offset, 2, ENC_BIG_ENDIAN);
91
16
    desc_loop_len = tvb_get_ntohs(tvb, offset) & DVB_NIT_NETWORK_DESCRIPTORS_LENGTH_MASK;
92
16
    offset += 2;
93
94
16
    offset += proto_mpeg_descriptor_loop_dissect(tvb, pinfo, offset, desc_loop_len, dvb_nit_tree);
95
96
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_reserved3,                    tvb, offset, 2, ENC_BIG_ENDIAN);
97
16
    proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_transport_stream_loop_length, tvb, offset, 2, ENC_BIG_ENDIAN);
98
16
    ts_end = offset + (tvb_get_ntohs(tvb, offset) & DVB_NIT_TRANSPORT_STREAM_LOOP_LENGTH_MASK);
99
16
    offset += 2;
100
101
25
    while (offset < ts_end) {
102
9
        tsid = tvb_get_ntohs(tvb, offset);
103
9
        ts_desc_len = 3 + (tvb_get_ntohs(tvb, offset + 4) & DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK);
104
105
9
        dvb_nit_ts_tree = proto_tree_add_subtree_format(dvb_nit_tree, tvb, offset, ts_desc_len,
106
9
                               ett_dvb_nit_ts, NULL, "Stream ID=0x%04hx", tsid);
107
108
9
        proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_transport_stream_id, tvb, offset, 2, ENC_BIG_ENDIAN);
109
9
        offset += 2;
110
111
9
        proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_original_network_id, tvb, offset, 2, ENC_BIG_ENDIAN);
112
9
        offset += 2;
113
114
9
        proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_reserved4,                    tvb, offset, 2, ENC_BIG_ENDIAN);
115
9
        proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_transport_descriptors_length, tvb, offset, 2, ENC_BIG_ENDIAN);
116
9
        desc_loop_len = tvb_get_ntohs(tvb, offset) & DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK;
117
9
        offset += 2;
118
119
9
        offset += proto_mpeg_descriptor_loop_dissect(tvb, pinfo, offset, desc_loop_len, dvb_nit_ts_tree);
120
9
    }
121
122
16
    offset += packet_mpeg_sect_crc(tvb, pinfo, dvb_nit_tree, 0, offset);
123
124
16
    proto_item_set_len(ti, offset);
125
16
    return offset;
126
16
}
127
128
129
void
130
proto_register_dvb_nit(void)
131
14
{
132
133
14
    static hf_register_info hf[] = {
134
135
14
        { &hf_dvb_nit_network_id, {
136
14
            "Network ID", "dvb_nit.sid",
137
14
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
138
14
        } },
139
140
14
        { &hf_dvb_nit_reserved1, {
141
14
            "Reserved", "dvb_nit.reserved1",
142
14
            FT_UINT8, BASE_HEX, NULL, DVB_NIT_RESERVED1_MASK, NULL, HFILL
143
14
        } },
144
145
14
        { &hf_dvb_nit_version_number, {
146
14
            "Version Number", "dvb_nit.version",
147
14
            FT_UINT8, BASE_HEX, NULL, DVB_NIT_VERSION_NUMBER_MASK, NULL, HFILL
148
14
        } },
149
150
14
        { &hf_dvb_nit_current_next_indicator, {
151
14
            "Current/Next Indicator", "dvb_nit.cur_next_ind",
152
14
            FT_BOOLEAN, 8, TFS(&tfs_current_not_yet), DVB_NIT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
153
14
        } },
154
155
14
        { &hf_dvb_nit_section_number, {
156
14
            "Section Number", "dvb_nit.sect_num",
157
14
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
158
14
        } },
159
160
14
        { &hf_dvb_nit_last_section_number, {
161
14
            "Last Section Number", "dvb_nit.last_sect_num",
162
14
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
163
14
        } },
164
165
14
        { &hf_dvb_nit_reserved2, {
166
14
            "Reserved", "dvb_nit.reserved2",
167
14
            FT_UINT16, BASE_HEX, NULL, DVB_NIT_RESERVED2_MASK, NULL, HFILL
168
14
        } },
169
170
14
        { &hf_dvb_nit_network_descriptors_length, {
171
14
            "Network Descriptors Length", "dvb_nit.network_desc_len",
172
14
            FT_UINT16, BASE_DEC, NULL, DVB_NIT_NETWORK_DESCRIPTORS_LENGTH_MASK, NULL, HFILL
173
14
        } },
174
175
14
        { &hf_dvb_nit_reserved3, {
176
14
            "Reserved", "dvb_nit.reserved3",
177
14
            FT_UINT16, BASE_HEX, NULL, DVB_NIT_RESERVED3_MASK, NULL, HFILL
178
14
        } },
179
180
14
        { &hf_dvb_nit_transport_stream_loop_length, {
181
14
            "Transport Stream Loop Length", "dvb_nit.ts_loop_len",
182
14
            FT_UINT16, BASE_DEC, NULL, DVB_NIT_TRANSPORT_STREAM_LOOP_LENGTH_MASK, NULL, HFILL
183
14
        } },
184
185
14
        { &hf_dvb_nit_transport_stream_id, {
186
14
            "Transport Stream ID", "dvb_nit.ts.id",
187
14
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
188
14
        } },
189
190
14
        { &hf_dvb_nit_original_network_id, {
191
14
            "Original Network ID", "dvb_nit.ts.original_network_id",
192
14
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
193
14
        } },
194
195
14
        { &hf_dvb_nit_reserved4, {
196
14
            "Reserved", "dvb_nit.ts.reserved",
197
14
            FT_UINT16, BASE_HEX, NULL, DVB_NIT_RESERVED4_MASK, NULL, HFILL
198
14
        } },
199
200
14
        { &hf_dvb_nit_transport_descriptors_length, {
201
14
            "Transport Descriptors Length", "dvb_nit.ts.desc_len",
202
14
            FT_UINT16, BASE_DEC, NULL, DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK, NULL, HFILL
203
14
        } },
204
205
14
    };
206
207
14
    static int *ett[] = {
208
14
        &ett_dvb_nit,
209
14
        &ett_dvb_nit_ts
210
14
    };
211
212
14
    proto_dvb_nit = proto_register_protocol("DVB Network Information Table", "DVB NIT", "dvb_nit");
213
214
14
    proto_register_field_array(proto_dvb_nit, hf, array_length(hf));
215
14
    proto_register_subtree_array(ett, array_length(ett));
216
217
14
    dvb_nit_handle = register_dissector("dvb_nit", dissect_dvb_nit, proto_dvb_nit);
218
14
}
219
220
221
void proto_reg_handoff_dvb_nit(void)
222
14
{
223
14
    dissector_add_uint("mpeg_sect.tid", DVB_NIT_TID, dvb_nit_handle);
224
14
    dissector_add_uint("mpeg_sect.tid", DVB_NIT_TID_OTHER, dvb_nit_handle);
225
14
}
226
227
228
/*
229
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
230
 *
231
 * Local variables:
232
 * c-basic-offset: 4
233
 * tab-width: 8
234
 * indent-tabs-mode: nil
235
 * End:
236
 *
237
 * vi: set shiftwidth=4 tabstop=8 expandtab:
238
 * :indentSize=4:tabSize=8:noTabs=true:
239
 */