Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-dvb-bat.c
Line
Count
Source
1
/* packet-dvb-bat.c
2
 * Routines for DVB (ETSI EN 300 468) Bouquet Association Table (BAT) 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_bat(void);
20
void proto_reg_handoff_dvb_bat(void);
21
22
static dissector_handle_t dvb_bat_handle;
23
24
static int proto_dvb_bat;
25
static int hf_dvb_bat_bouquet_id;
26
static int hf_dvb_bat_reserved1;
27
static int hf_dvb_bat_version_number;
28
static int hf_dvb_bat_current_next_indicator;
29
static int hf_dvb_bat_section_number;
30
static int hf_dvb_bat_last_section_number;
31
32
static int hf_dvb_bat_reserved2;
33
static int hf_dvb_bat_bouquet_descriptors_length;
34
35
static int hf_dvb_bat_reserved3;
36
static int hf_dvb_bat_transport_stream_loop_length;
37
38
static int hf_dvb_bat_transport_stream_id;
39
static int hf_dvb_bat_original_network_id;
40
static int hf_dvb_bat_reserved4;
41
static int hf_dvb_bat_transport_descriptors_length;
42
43
static int ett_dvb_bat;
44
static int ett_dvb_bat_transport_stream;
45
46
47
15
#define DVB_BAT_RESERVED1_MASK                      0xC0
48
15
#define DVB_BAT_VERSION_NUMBER_MASK                 0x3E
49
15
#define DVB_BAT_CURRENT_NEXT_INDICATOR_MASK         0x01
50
51
15
#define DVB_BAT_RESERVED2_MASK                    0xF000
52
33
#define DVB_BAT_BOUQUET_DESCRIPTORS_LENGTH_MASK   0x0FFF
53
54
15
#define DVB_BAT_RESERVED3_MASK                    0xF000
55
18
#define DVB_BAT_TRANSPORT_STREAM_LOOP_LENGTH_MASK 0x0FFF
56
57
15
#define DVB_BAT_RESERVED4_MASK                    0xF000
58
2
#define DVB_BAT_TRANSPORT_DESCRIPTORS_LENGTH_MASK 0x0FFF
59
60
#if 0
61
static const value_string dvb_bat_running_status_vals[] = {
62
    { 0, "Undefined" },
63
    { 1, "Not Running" },
64
    { 2, "Starts in a few seconds" },
65
    { 3, "Pausing" },
66
    { 4, "Running" },
67
    { 5, "Service off-air" },
68
69
    { 0, NULL }
70
};
71
72
static const value_string dvb_bat_free_ca_mode_vals[] = {
73
    { 0, "Not Scrambled" },
74
    { 1, "One or more component scrambled" },
75
76
    { 0, NULL }
77
};
78
#endif
79
80
static int
81
dissect_dvb_bat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
82
3
{
83
84
3
    unsigned   offset = 0, length = 0, ts_loop_end;
85
3
    uint16_t ts_id, descriptor_len, ts_loop_len;
86
87
3
    proto_item *ti;
88
3
    proto_tree *dvb_bat_tree;
89
3
    proto_tree *transport_stream_tree;
90
91
3
    col_set_str(pinfo->cinfo, COL_INFO, "Bouquet Association Table (BAT)");
92
93
3
    ti = proto_tree_add_item(tree, proto_dvb_bat,                              tvb, offset, -1, ENC_NA);
94
3
    dvb_bat_tree = proto_item_add_subtree(ti, ett_dvb_bat);
95
96
3
    offset += packet_mpeg_sect_header(tvb, offset, dvb_bat_tree, &length, NULL);
97
3
    length -= 4;
98
99
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_bouquet_id,                   tvb, offset, 2, ENC_BIG_ENDIAN);
100
3
    offset += 2;
101
102
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_reserved1,                    tvb, offset, 1, ENC_BIG_ENDIAN);
103
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_version_number,               tvb, offset, 1, ENC_BIG_ENDIAN);
104
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_current_next_indicator,       tvb, offset, 1, ENC_BIG_ENDIAN);
105
3
    offset += 1;
106
107
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_section_number,               tvb, offset, 1, ENC_BIG_ENDIAN);
108
3
    offset += 1;
109
110
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_last_section_number,          tvb, offset, 1, ENC_BIG_ENDIAN);
111
3
    offset += 1;
112
113
3
    descriptor_len = tvb_get_ntohs(tvb, offset) & DVB_BAT_BOUQUET_DESCRIPTORS_LENGTH_MASK;
114
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_reserved2,                    tvb, offset, 2, ENC_BIG_ENDIAN);
115
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_bouquet_descriptors_length,   tvb, offset, 2, ENC_BIG_ENDIAN);
116
3
    offset += 2;
117
118
3
    offset += proto_mpeg_descriptor_loop_dissect(tvb, pinfo, offset, descriptor_len, dvb_bat_tree);
119
120
3
    ts_loop_len = tvb_get_ntohs(tvb, offset) & DVB_BAT_TRANSPORT_STREAM_LOOP_LENGTH_MASK;
121
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_reserved3,                    tvb, offset, 2, ENC_BIG_ENDIAN);
122
3
    proto_tree_add_item(dvb_bat_tree, hf_dvb_bat_transport_stream_loop_length, tvb, offset, 2, ENC_BIG_ENDIAN);
123
3
    offset += 2;
124
125
3
    ts_loop_end = offset + ts_loop_len;
126
5
    while (offset < ts_loop_end) {
127
2
        ts_id = tvb_get_ntohs(tvb, offset);
128
2
        descriptor_len = tvb_get_ntohs(tvb, offset + 4) & DVB_BAT_TRANSPORT_DESCRIPTORS_LENGTH_MASK;
129
130
2
        transport_stream_tree = proto_tree_add_subtree_format(dvb_bat_tree, tvb, offset, 6 + descriptor_len,
131
2
            ett_dvb_bat_transport_stream, NULL, "Transport Stream 0x%04x", ts_id);
132
133
2
        proto_tree_add_item(transport_stream_tree, hf_dvb_bat_transport_stream_id, tvb, offset, 2, ENC_BIG_ENDIAN);
134
2
        offset += 2;
135
136
2
        proto_tree_add_item(transport_stream_tree, hf_dvb_bat_original_network_id, tvb, offset, 2, ENC_BIG_ENDIAN);
137
2
        offset += 2;
138
139
2
        proto_tree_add_item(transport_stream_tree, hf_dvb_bat_reserved4, tvb, offset, 2, ENC_BIG_ENDIAN);
140
2
        proto_tree_add_item(transport_stream_tree, hf_dvb_bat_transport_descriptors_length, tvb, offset, 2, ENC_BIG_ENDIAN);
141
2
        offset += 2;
142
143
2
        offset += proto_mpeg_descriptor_loop_dissect(tvb, pinfo, offset, descriptor_len, transport_stream_tree);
144
2
    }
145
146
3
    offset += packet_mpeg_sect_crc(tvb, pinfo, dvb_bat_tree, 0, offset);
147
3
    proto_item_set_len(ti, offset);
148
3
    return tvb_captured_length(tvb);
149
3
}
150
151
152
void
153
proto_register_dvb_bat(void)
154
15
{
155
156
15
    static hf_register_info hf[] = {
157
158
15
        { &hf_dvb_bat_bouquet_id, {
159
15
            "Bouquet ID", "dvb_bat.bouquet_id",
160
15
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
161
15
        } },
162
163
15
        { &hf_dvb_bat_reserved1, {
164
15
            "Reserved", "dvb_bat.reserved1",
165
15
            FT_UINT8, BASE_HEX, NULL, DVB_BAT_RESERVED1_MASK, NULL, HFILL
166
15
        } },
167
168
15
        { &hf_dvb_bat_version_number, {
169
15
            "Version Number", "dvb_bat.version",
170
15
            FT_UINT8, BASE_HEX, NULL, DVB_BAT_VERSION_NUMBER_MASK, NULL, HFILL
171
15
        } },
172
173
15
        { &hf_dvb_bat_current_next_indicator, {
174
15
            "Current/Next Indicator", "dvb_bat.cur_next_ind",
175
15
            FT_BOOLEAN, 8, TFS(&tfs_current_not_yet), DVB_BAT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
176
15
        } },
177
178
15
        { &hf_dvb_bat_section_number, {
179
15
            "Section Number", "dvb_bat.sect_num",
180
15
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
181
15
        } },
182
183
15
        { &hf_dvb_bat_last_section_number, {
184
15
            "Last Section Number", "dvb_bat.last_sect_num",
185
15
            FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
186
15
        } },
187
188
15
        { &hf_dvb_bat_reserved2, {
189
15
            "Reserved", "dvb_bat.reserved2",
190
15
            FT_UINT16, BASE_HEX, NULL, DVB_BAT_RESERVED2_MASK, NULL, HFILL
191
15
        } },
192
193
15
        { &hf_dvb_bat_bouquet_descriptors_length, {
194
15
            "Bouquet Descriptors Length", "dvb_bat.bouquet_desc_len",
195
15
            FT_UINT16, BASE_DEC, NULL, DVB_BAT_BOUQUET_DESCRIPTORS_LENGTH_MASK, NULL, HFILL
196
15
        } },
197
198
15
        { &hf_dvb_bat_reserved3, {
199
15
            "Reserved", "dvb_bat.reserved3",
200
15
            FT_UINT16, BASE_HEX, NULL, DVB_BAT_RESERVED3_MASK, NULL, HFILL
201
15
        } },
202
203
15
        { &hf_dvb_bat_transport_stream_loop_length, {
204
15
            "Transport Stream Loop Length", "dvb_bat.ts_loop_len",
205
15
            FT_UINT16, BASE_DEC, NULL, DVB_BAT_TRANSPORT_STREAM_LOOP_LENGTH_MASK, NULL, HFILL
206
15
        } },
207
208
15
        { &hf_dvb_bat_transport_stream_id, {
209
15
            "Transport Stream ID", "dvb_bat.ts.id",
210
15
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
211
15
        } },
212
213
15
        { &hf_dvb_bat_original_network_id, {
214
15
            "Original Network ID", "dvb_bat.ts.original_nid",
215
15
            FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
216
15
        } },
217
218
15
        { &hf_dvb_bat_reserved4, {
219
15
            "Reserved", "dvb_bat.ts.reserved",
220
15
            FT_UINT16, BASE_HEX, NULL, DVB_BAT_RESERVED4_MASK, NULL, HFILL
221
15
        } },
222
223
15
        { &hf_dvb_bat_transport_descriptors_length, {
224
15
            "Bouquet Descriptors Length", "dvb_bat.ts.desc_len",
225
15
            FT_UINT16, BASE_DEC, NULL, DVB_BAT_BOUQUET_DESCRIPTORS_LENGTH_MASK, NULL, HFILL
226
15
        } },
227
228
15
    };
229
230
15
    static int *ett[] = {
231
15
        &ett_dvb_bat,
232
15
        &ett_dvb_bat_transport_stream
233
15
    };
234
235
15
    proto_dvb_bat = proto_register_protocol("DVB Bouquet Association Table", "DVB BAT", "dvb_bat");
236
15
    dvb_bat_handle = register_dissector("dvb_bat", dissect_dvb_bat, proto_dvb_bat);
237
238
15
    proto_register_field_array(proto_dvb_bat, hf, array_length(hf));
239
15
    proto_register_subtree_array(ett, array_length(ett));
240
241
15
}
242
243
244
void proto_reg_handoff_dvb_bat(void)
245
15
{
246
15
    dissector_add_uint("mpeg_sect.tid", DVB_BAT_TID, dvb_bat_handle);
247
15
}
248
249
/*
250
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
251
 *
252
 * Local variables:
253
 * c-basic-offset: 4
254
 * tab-width: 8
255
 * indent-tabs-mode: nil
256
 * End:
257
 *
258
 * vi: set shiftwidth=4 tabstop=8 expandtab:
259
 * :indentSize=4:tabSize=8:noTabs=true:
260
 */