Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-dvb-eit.c
blob6c95b1a673b01ef855565549188f9c424b7f5618
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>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/tfs.h>
16 #include "packet-mpeg-sect.h"
17 #include "packet-mpeg-descriptor.h"
19 void proto_register_dvb_eit(void);
20 void proto_reg_handoff_dvb_eit(void);
22 static dissector_handle_t dvb_eit_handle;
24 static int proto_dvb_eit;
25 static int hf_dvb_eit_service_id;
26 static int hf_dvb_eit_reserved;
27 static int hf_dvb_eit_version_number;
28 static int hf_dvb_eit_current_next_indicator;
29 static int hf_dvb_eit_section_number;
30 static int hf_dvb_eit_last_section_number;
32 static int hf_dvb_eit_transport_stream_id;
33 static int hf_dvb_eit_original_network_id;
34 static int hf_dvb_eit_segment_last_section_number;
35 static int hf_dvb_eit_last_table_id;
37 static int hf_dvb_eit_event_id;
38 static int hf_dvb_eit_start_time;
39 static int hf_dvb_eit_duration;
40 static int hf_dvb_eit_running_status;
41 static int hf_dvb_eit_free_ca_mode;
42 static int hf_dvb_eit_descriptors_loop_length;
44 static int ett_dvb_eit;
45 static int ett_dvb_eit_event;
48 #define DVB_EIT_RESERVED_MASK 0xC0
49 #define DVB_EIT_VERSION_NUMBER_MASK 0x3E
50 #define DVB_EIT_CURRENT_NEXT_INDICATOR_MASK 0x01
52 #define DVB_EIT_RUNNING_STATUS_MASK 0xE000
53 #define DVB_EIT_FREE_CA_MODE_MASK 0x1000
54 #define DVB_EIT_DESCRIPTORS_LOOP_LENGTH_MASK 0x0FFF
56 static const value_string dvb_eit_running_status_vals[] = {
57 { 0, "Undefined" },
58 { 1, "Not Running" },
59 { 2, "Starts in a few seconds" },
60 { 3, "Pausing" },
61 { 4, "Running" },
62 { 5, "Service off-air" },
64 { 0, NULL }
67 static const value_string dvb_eit_free_ca_mode_vals[] = {
68 { 0, "Not Scrambled" },
69 { 1, "One or more component scrambled" },
71 { 0, NULL }
74 static int
75 dissect_dvb_eit(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
78 unsigned offset = 0, length = 0;
79 unsigned descriptor_len;
80 uint16_t evt_id;
82 proto_item *ti;
83 proto_tree *dvb_eit_tree;
84 proto_tree *dvb_eit_event_tree;
85 proto_item *duration_item;
87 nstime_t start_time;
89 col_set_str(pinfo->cinfo, COL_INFO, "Event Information Table (EIT)");
91 ti = proto_tree_add_item(tree, proto_dvb_eit, tvb, offset, -1, ENC_NA);
92 dvb_eit_tree = proto_item_add_subtree(ti, ett_dvb_eit);
94 offset += packet_mpeg_sect_header(tvb, offset, dvb_eit_tree, &length, NULL);
95 length -= 4;
97 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_service_id, tvb, offset, 2, ENC_BIG_ENDIAN);
98 offset += 2;
100 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_reserved, tvb, offset, 1, ENC_BIG_ENDIAN);
101 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_version_number, tvb, offset, 1, ENC_BIG_ENDIAN);
102 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_current_next_indicator, tvb, offset, 1, ENC_BIG_ENDIAN);
103 offset += 1;
105 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
106 offset += 1;
108 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
109 offset += 1;
111 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_transport_stream_id, tvb, offset, 2, ENC_BIG_ENDIAN);
112 offset += 2;
114 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_original_network_id, tvb, offset, 2, ENC_BIG_ENDIAN);
115 offset += 2;
117 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_segment_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
118 offset += 1;
120 proto_tree_add_item(dvb_eit_tree, hf_dvb_eit_last_table_id, tvb, offset, 1, ENC_BIG_ENDIAN);
121 offset += 1;
123 if (offset >= length) {
124 packet_mpeg_sect_crc(tvb, pinfo, dvb_eit_tree, 0, offset);
126 return offset;
129 /* Parse all the events */
130 while (offset < length) {
132 evt_id = tvb_get_ntohs(tvb, offset);
133 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);
135 proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_event_id, tvb, offset, 2, ENC_BIG_ENDIAN);
136 offset += 2;
138 if (tvb_memeql(tvb, offset, (const uint8_t*)"\xFF\xFF\xFF\xFF\xFF", 5)) {
139 if (packet_mpeg_sect_mjd_to_utc_time(tvb, offset, &start_time) < 0) {
140 proto_tree_add_time_format(dvb_eit_event_tree, hf_dvb_eit_start_time, tvb, offset, 5,
141 &start_time, "Unparseable time");
142 } else {
143 proto_tree_add_time(dvb_eit_event_tree, hf_dvb_eit_start_time, tvb, offset,
144 5, &start_time);
146 } else {
147 start_time.secs = 0xFFFFFFFF;
148 start_time.nsecs = 0xFFFFFFFF;
149 proto_tree_add_time_format_value(tree, hf_dvb_eit_start_time, tvb, offset, 5, &start_time, "Undefined (0xFFFFFFFFFF)");
151 offset += 5;
153 duration_item = proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_duration, tvb, offset, 3, ENC_BIG_ENDIAN);
154 proto_item_append_text(duration_item, " (%02u:%02u:%02u)",
155 MPEG_SECT_BCD44_TO_DEC(tvb_get_uint8(tvb, offset)),
156 MPEG_SECT_BCD44_TO_DEC(tvb_get_uint8(tvb, offset + 1)),
157 MPEG_SECT_BCD44_TO_DEC(tvb_get_uint8(tvb, offset + 2)));
158 offset += 3;
160 proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_running_status, tvb, offset, 2, ENC_BIG_ENDIAN);
161 proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_free_ca_mode, tvb, offset, 2, ENC_BIG_ENDIAN);
162 proto_tree_add_item(dvb_eit_event_tree, hf_dvb_eit_descriptors_loop_length, tvb, offset, 2, ENC_BIG_ENDIAN);
163 descriptor_len = tvb_get_ntohs(tvb, offset) & DVB_EIT_DESCRIPTORS_LOOP_LENGTH_MASK;
164 offset += 2;
166 offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, descriptor_len, dvb_eit_event_tree);
169 offset += packet_mpeg_sect_crc(tvb, pinfo, dvb_eit_tree, 0, offset);
170 proto_item_set_len(ti, offset);
171 return tvb_captured_length(tvb);
175 void
176 proto_register_dvb_eit(void)
179 static hf_register_info hf[] = {
181 { &hf_dvb_eit_service_id, {
182 "Service ID", "dvb_eit.sid",
183 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
184 } },
186 { &hf_dvb_eit_reserved, {
187 "Reserved", "dvb_eit.reserved",
188 FT_UINT8, BASE_HEX, NULL, DVB_EIT_RESERVED_MASK, NULL, HFILL
189 } },
191 { &hf_dvb_eit_version_number, {
192 "Version Number", "dvb_eit.version",
193 FT_UINT8, BASE_HEX, NULL, DVB_EIT_VERSION_NUMBER_MASK, NULL, HFILL
194 } },
196 { &hf_dvb_eit_current_next_indicator, {
197 "Current/Next Indicator", "dvb_eit.cur_next_ind",
198 FT_BOOLEAN, 8, TFS(&tfs_current_not_yet), DVB_EIT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
199 } },
201 { &hf_dvb_eit_section_number, {
202 "Section Number", "dvb_eit.sect_num",
203 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
204 } },
206 { &hf_dvb_eit_last_section_number, {
207 "Last Section Number", "dvb_eit.last_sect_num",
208 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
209 } },
211 { &hf_dvb_eit_transport_stream_id, {
212 "Transport Stream ID", "dvb_eit.tsid",
213 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
214 } },
216 { &hf_dvb_eit_original_network_id, {
217 "Original Network ID", "dvb_eit.original_nid",
218 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
219 } },
221 { &hf_dvb_eit_segment_last_section_number, {
222 "Segment Last Section Number", "dvb_eit.segment_last_sect_num",
223 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
224 } },
226 { &hf_dvb_eit_last_table_id, {
227 "Last Table ID", "dvb_eit.last_tid",
228 FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL
229 } },
231 { &hf_dvb_eit_event_id, {
232 "Event ID", "dvb_eit.evt.id",
233 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
234 } },
236 { &hf_dvb_eit_start_time, {
237 "UTC Start Time", "dvb_eit.evt.start_time",
238 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC, NULL, 0, NULL, HFILL
239 } },
241 { &hf_dvb_eit_duration, {
242 "Duration", "dvb_eit.evt.duration",
243 FT_UINT24, BASE_HEX, NULL, 0, NULL, HFILL
244 } },
246 { &hf_dvb_eit_running_status, {
247 "Running Status", "dvb_eit.evt.running_status",
248 FT_UINT16, BASE_HEX, VALS(dvb_eit_running_status_vals), DVB_EIT_RUNNING_STATUS_MASK, NULL, HFILL
249 } },
251 { &hf_dvb_eit_free_ca_mode, {
252 "Free CA Mode", "dvb_eit.evt.free_ca_mode",
253 FT_UINT16, BASE_HEX, VALS(dvb_eit_free_ca_mode_vals), DVB_EIT_FREE_CA_MODE_MASK, NULL, HFILL
254 } },
256 { &hf_dvb_eit_descriptors_loop_length, {
257 "Descriptors Loop Length", "dvb_eit.evt.descr_loop_len",
258 FT_UINT16, BASE_DEC, NULL, DVB_EIT_DESCRIPTORS_LOOP_LENGTH_MASK, NULL, HFILL
262 static int *ett[] = {
263 &ett_dvb_eit,
264 &ett_dvb_eit_event
267 proto_dvb_eit = proto_register_protocol("DVB Event Information Table", "DVB EIT", "dvb_eit");
269 proto_register_field_array(proto_dvb_eit, hf, array_length(hf));
270 proto_register_subtree_array(ett, array_length(ett));
272 dvb_eit_handle = register_dissector("dvb_eit", dissect_dvb_eit, proto_dvb_eit);
276 void proto_reg_handoff_dvb_eit(void)
278 int tid;
280 for (tid = DVB_EIT_TID_MIN; tid <= DVB_EIT_TID_MAX; tid++)
281 dissector_add_uint("mpeg_sect.tid", tid, dvb_eit_handle);
286 * Editor modelines - https://www.wireshark.org/tools/modelines.html
288 * Local variables:
289 * c-basic-offset: 4
290 * tab-width: 8
291 * indent-tabs-mode: nil
292 * End:
294 * vi: set shiftwidth=4 tabstop=8 expandtab:
295 * :indentSize=4:tabSize=8:noTabs=true: