checkAPIs.pl: support for new-style dissectors in check_hf_entries
[metze/wireshark/wip.git] / epan / dissectors / packet-dvb-eit.c
1 /* packet-dvb-eit.c
2  * Routines for DVB (ETSI EN 300 468) Event Information Table (EIT) 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 "packet-mpeg-sect.h"
16 #include "packet-mpeg-descriptor.h"
17
18 void proto_register_dvb_eit(void);
19 void proto_reg_handoff_dvb_eit(void);
20
21 static int proto_dvb_eit = -1;
22 static int hf_dvb_eit_service_id = -1;
23 static int hf_dvb_eit_reserved = -1;
24 static int hf_dvb_eit_version_number = -1;
25 static int hf_dvb_eit_current_next_indicator = -1;
26 static int hf_dvb_eit_section_number = -1;
27 static int hf_dvb_eit_last_section_number = -1;
28
29 static int hf_dvb_eit_transport_stream_id = -1;
30 static int hf_dvb_eit_original_network_id = -1;
31 static int hf_dvb_eit_segment_last_section_number = -1;
32 static int hf_dvb_eit_last_table_id = -1;
33
34 static int hf_dvb_eit_event_id = -1;
35 static int hf_dvb_eit_start_time = -1;
36 static int hf_dvb_eit_duration = -1;
37 static int hf_dvb_eit_running_status = -1;
38 static int hf_dvb_eit_free_ca_mode = -1;
39 static int hf_dvb_eit_descriptors_loop_length = -1;
40
41 static gint ett_dvb_eit = -1;
42 static gint ett_dvb_eit_event = -1;
43
44
45 #define DVB_EIT_RESERVED_MASK                     0xC0
46 #define DVB_EIT_VERSION_NUMBER_MASK               0x3E
47 #define DVB_EIT_CURRENT_NEXT_INDICATOR_MASK       0x01
48
49 #define DVB_EIT_RUNNING_STATUS_MASK             0xE000
50 #define DVB_EIT_FREE_CA_MODE_MASK               0x1000
51 #define DVB_EIT_DESCRIPTORS_LOOP_LENGTH_MASK    0x0FFF
52
53 static const value_string dvb_eit_cur_next_vals[] = {
54     { 0, "Not yet applicable" },
55     { 1, "Currently applicable" },
56
57     { 0, NULL }
58 };
59
60 static const value_string dvb_eit_running_status_vals[] = {
61     { 0, "Undefined" },
62     { 1, "Not Running" },
63     { 2, "Starts in a few seconds" },
64     { 3, "Pausing" },
65     { 4, "Running" },
66     { 5, "Service off-air" },
67
68     { 0, NULL }
69 };
70
71 static const value_string dvb_eit_free_ca_mode_vals[] = {
72     { 0, "Not Scrambled" },
73     { 1, "One or more component scrambled" },
74
75     { 0, NULL }
76 };
77
78 static int
79 dissect_dvb_eit(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
80 {
81
82     guint       offset = 0, length = 0;
83     guint       descriptor_len;
84     guint16     evt_id;
85
86     proto_item *ti;
87     proto_tree *dvb_eit_tree;
88     proto_tree *dvb_eit_event_tree;
89     proto_item *duration_item;
90
91     nstime_t    start_time;
92
93     col_set_str(pinfo->cinfo, COL_INFO, "Event Information Table (EIT)");
94
95     ti = proto_tree_add_item(tree, proto_dvb_eit, tvb, offset, -1, ENC_NA);
96     dvb_eit_tree = proto_item_add_subtree(ti, ett_dvb_eit);
97
98     offset += packet_mpeg_sect_header(tvb, offset, dvb_eit_tree, &length, NULL);
99     length -= 4;
100
101     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_service_id,                  tvb, offset, 2, ENC_BIG_ENDIAN);
102     offset += 2;
103
104     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_reserved,                    tvb, offset, 1, ENC_BIG_ENDIAN);
105     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_version_number,              tvb, offset, 1, ENC_BIG_ENDIAN);
106     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_current_next_indicator,      tvb, offset, 1, ENC_BIG_ENDIAN);
107     offset += 1;
108
109     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_section_number,              tvb, offset, 1, ENC_BIG_ENDIAN);
110     offset += 1;
111
112     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_last_section_number,         tvb, offset, 1, ENC_BIG_ENDIAN);
113     offset += 1;
114
115     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_transport_stream_id,         tvb, offset, 2, ENC_BIG_ENDIAN);
116     offset += 2;
117
118     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_original_network_id,         tvb, offset, 2, ENC_BIG_ENDIAN);
119     offset += 2;
120
121     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_segment_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
122     offset += 1;
123
124     proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_last_table_id, tvb, offset, 1, ENC_BIG_ENDIAN);
125     offset += 1;
126
127     if (offset >= length) {
128         packet_mpeg_sect_crc(tvb, pinfo, dvb_eit_tree, 0, offset);
129
130         return offset;
131     }
132
133     /* Parse all the events */
134     while (offset < length) {
135
136         evt_id = tvb_get_ntohs(tvb, offset);
137         dvb_eit_event_tree = proto_tree_add_subtree_format(dvb_eit_tree, tvb, offset, 12, ett_dvb_eit_event, NULL, "Event 0x%04hx", evt_id);
138
139         proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_event_id, tvb, offset, 2, ENC_BIG_ENDIAN);
140         offset += 2;
141
142         if (tvb_memeql(tvb, offset, "\xFF\xFF\xFF\xFF\xFF", 5)) {
143             if (packet_mpeg_sect_mjd_to_utc_time(tvb, offset, &start_time) < 0) {
144                 proto_tree_add_time_format(dvb_eit_event_tree, hf_dvb_eit_start_time, tvb, offset, 5,
145                                     &start_time, "Unparseable time");
146             } else {
147                 proto_tree_add_time(dvb_eit_event_tree, hf_dvb_eit_start_time, tvb, offset,
148                     5, &start_time);
149             }
150         } else {
151             start_time.secs = 0xFFFFFFFF;
152             start_time.nsecs = 0xFFFFFFFF;
153             proto_tree_add_time_format_value(tree, hf_dvb_eit_start_time, tvb, offset, 5, &start_time, "Undefined (0xFFFFFFFFFF)");
154         }
155         offset += 5;
156
157         duration_item = proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_duration, tvb, offset, 3, ENC_BIG_ENDIAN);
158         proto_item_append_text(duration_item, " (%02u:%02u:%02u)",
159             MPEG_SECT_BCD44_TO_DEC(tvb_get_guint8(tvb, offset)),
160             MPEG_SECT_BCD44_TO_DEC(tvb_get_guint8(tvb, offset + 1)),
161             MPEG_SECT_BCD44_TO_DEC(tvb_get_guint8(tvb, offset + 2)));
162         offset += 3;
163
164         proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_running_status,          tvb, offset, 2, ENC_BIG_ENDIAN);
165         proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_free_ca_mode,            tvb, offset, 2, ENC_BIG_ENDIAN);
166         proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_descriptors_loop_length, tvb, offset, 2, ENC_BIG_ENDIAN);
167         descriptor_len = tvb_get_ntohs(tvb, offset) & DVB_EIT_DESCRIPTORS_LOOP_LENGTH_MASK;
168         offset += 2;
169
170         offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, descriptor_len, dvb_eit_event_tree);
171     }
172
173     offset += packet_mpeg_sect_crc(tvb, pinfo, dvb_eit_tree, 0, offset);
174     proto_item_set_len(ti, offset);
175     return tvb_captured_length(tvb);
176 }
177
178
179 void
180 proto_register_dvb_eit(void)
181 {
182
183     static hf_register_info hf[] = {
184
185         { &hf_dvb_eit_service_id, {
186             "Service ID", "dvb_eit.sid",
187             FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
188         } },
189
190         { &hf_dvb_eit_reserved, {
191             "Reserved", "dvb_eit.reserved",
192             FT_UINT8, BASE_HEX, NULL, DVB_EIT_RESERVED_MASK, NULL, HFILL
193         } },
194
195         { &hf_dvb_eit_version_number, {
196             "Version Number", "dvb_eit.version",
197             FT_UINT8, BASE_HEX, NULL, DVB_EIT_VERSION_NUMBER_MASK, NULL, HFILL
198         } },
199
200         { &hf_dvb_eit_current_next_indicator, {
201             "Current/Next Indicator", "dvb_eit.cur_next_ind",
202             FT_UINT8, BASE_DEC, VALS(dvb_eit_cur_next_vals), DVB_EIT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
203         } },
204
205         { &hf_dvb_eit_section_number, {
206             "Section Number", "dvb_eit.sect_num",
207             FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
208         } },
209
210         { &hf_dvb_eit_last_section_number, {
211             "Last Section Number", "dvb_eit.last_sect_num",
212             FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
213         } },
214
215         { &hf_dvb_eit_transport_stream_id, {
216             "Transport Stream ID", "dvb_eit.tsid",
217             FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
218         } },
219
220         { &hf_dvb_eit_original_network_id, {
221             "Original Network ID", "dvb_eit.original_nid",
222             FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
223         } },
224
225         { &hf_dvb_eit_segment_last_section_number, {
226             "Segment Last Section Number", "dvb_eit.segment_last_sect_num",
227             FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
228         } },
229
230         { &hf_dvb_eit_last_table_id, {
231             "Last Table ID", "dvb_eit.last_tid",
232             FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL
233         } },
234
235         { &hf_dvb_eit_event_id, {
236             "Event ID", "dvb_eit.evt.id",
237             FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
238         } },
239
240         { &hf_dvb_eit_start_time, {
241             "UTC Start Time", "dvb_eit.evt.start_time",
242             FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL
243         } },
244
245         { &hf_dvb_eit_duration, {
246             "Duration", "dvb_eit.evt.duration",
247             FT_UINT24, BASE_HEX, NULL, 0, NULL, HFILL
248         } },
249
250         { &hf_dvb_eit_running_status, {
251             "Running Status", "dvb_eit.evt.running_status",
252             FT_UINT16, BASE_HEX, VALS(dvb_eit_running_status_vals), DVB_EIT_RUNNING_STATUS_MASK, NULL, HFILL
253         } },
254
255         { &hf_dvb_eit_free_ca_mode, {
256             "Free CA Mode", "dvb_eit.evt.free_ca_mode",
257             FT_UINT16, BASE_HEX, VALS(dvb_eit_free_ca_mode_vals), DVB_EIT_FREE_CA_MODE_MASK, NULL, HFILL
258         } },
259
260         { &hf_dvb_eit_descriptors_loop_length, {
261             "Descriptors Loop Length", "dvb_eit.evt.descr_loop_len",
262             FT_UINT16, BASE_HEX, NULL, DVB_EIT_DESCRIPTORS_LOOP_LENGTH_MASK, NULL, HFILL
263         } }
264     };
265
266     static gint *ett[] = {
267         &ett_dvb_eit,
268         &ett_dvb_eit_event
269     };
270
271     proto_dvb_eit = proto_register_protocol("DVB Event Information Table", "DVB EIT", "dvb_eit");
272
273     proto_register_field_array(proto_dvb_eit, hf, array_length(hf));
274     proto_register_subtree_array(ett, array_length(ett));
275
276 }
277
278
279 void proto_reg_handoff_dvb_eit(void)
280 {
281     int tid;
282     dissector_handle_t dvb_eit_handle;
283
284     dvb_eit_handle = create_dissector_handle(dissect_dvb_eit, proto_dvb_eit);
285
286     for (tid = DVB_EIT_TID_MIN; tid <= DVB_EIT_TID_MAX; tid++)
287         dissector_add_uint("mpeg_sect.tid", tid, dvb_eit_handle);
288 }
289
290
291 /*
292  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
293  *
294  * Local variables:
295  * c-basic-offset: 4
296  * tab-width: 8
297  * indent-tabs-mode: nil
298  * End:
299  *
300  * vi: set shiftwidth=4 tabstop=8 expandtab:
301  * :indentSize=4:tabSize=8:noTabs=true:
302  */