HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-dvb-nit.c
blobe7193c48ce3b8ddb871a0e8809193cc078863467
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>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/dissectors/packet-mpeg-sect.h>
33 #include "packet-mpeg-descriptor.h"
35 void proto_register_dvb_nit(void);
36 void proto_reg_handoff_dvb_nit(void);
38 static int proto_dvb_nit = -1;
39 static int hf_dvb_nit_network_id = -1;
40 static int hf_dvb_nit_reserved1 = -1;
41 static int hf_dvb_nit_version_number = -1;
42 static int hf_dvb_nit_current_next_indicator = -1;
43 static int hf_dvb_nit_section_number = -1;
44 static int hf_dvb_nit_last_section_number = -1;
45 static int hf_dvb_nit_reserved2 = -1;
47 static int hf_dvb_nit_network_descriptors_length = -1;
48 static int hf_dvb_nit_reserved3 = -1;
49 static int hf_dvb_nit_transport_stream_loop_length = -1;
51 static int hf_dvb_nit_transport_stream_id = -1;
52 static int hf_dvb_nit_original_network_id = -1;
53 static int hf_dvb_nit_reserved4 = -1;
54 static int hf_dvb_nit_transport_descriptors_length = -1;
56 static gint ett_dvb_nit = -1;
57 static gint ett_dvb_nit_ts = -1;
60 #define DVB_NIT_TID 0x40
61 #define DVB_NIT_TID_OTHER 0x41
63 #define DVB_NIT_RESERVED1_MASK 0xC0
64 #define DVB_NIT_VERSION_NUMBER_MASK 0x3E
65 #define DVB_NIT_CURRENT_NEXT_INDICATOR_MASK 0x01
66 #define DVB_NIT_RESERVED2_MASK 0xF000
67 #define DVB_NIT_NETWORK_DESCRIPTORS_LENGTH_MASK 0x0FFF
68 #define DVB_NIT_RESERVED3_MASK 0xF000
69 #define DVB_NIT_TRANSPORT_STREAM_LOOP_LENGTH_MASK 0x0FFF
70 #define DVB_NIT_RESERVED4_MASK 0xF000
71 #define DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK 0x0FFF
73 static const value_string dvb_nit_cur_next_vals[] = {
74 { 0, "Not yet applicable" },
75 { 1, "Currently applicable" },
77 { 0, NULL }
81 static int
82 dissect_dvb_nit(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
85 guint offset = 0;
86 guint ts_desc_len, desc_loop_len, ts_end;
88 guint16 tsid;
90 proto_item *ti;
91 proto_tree *dvb_nit_tree;
92 proto_item *tsi;
93 proto_tree *dvb_nit_ts_tree;
95 col_set_str(pinfo->cinfo, COL_INFO, "Network Information Table (NIT)");
97 ti = proto_tree_add_item(tree, proto_dvb_nit, tvb, offset, -1, ENC_NA);
98 dvb_nit_tree = proto_item_add_subtree(ti, ett_dvb_nit);
100 offset += packet_mpeg_sect_header(tvb, offset, dvb_nit_tree, NULL, NULL);
102 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_network_id, tvb, offset, 2, ENC_BIG_ENDIAN);
103 offset += 2;
105 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_reserved1, tvb, offset, 1, ENC_BIG_ENDIAN);
106 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_version_number, tvb, offset, 1, ENC_BIG_ENDIAN);
107 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_current_next_indicator, tvb, offset, 1, ENC_BIG_ENDIAN);
108 offset += 1;
110 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
111 offset += 1;
113 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_last_section_number, tvb, offset, 1, ENC_BIG_ENDIAN);
114 offset += 1;
116 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_reserved2, tvb, offset, 2, ENC_BIG_ENDIAN);
117 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_network_descriptors_length, tvb, offset, 2, ENC_BIG_ENDIAN);
118 desc_loop_len = tvb_get_ntohs(tvb, offset) & DVB_NIT_NETWORK_DESCRIPTORS_LENGTH_MASK;
119 offset += 2;
121 offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, desc_loop_len, dvb_nit_tree);
123 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_reserved3, tvb, offset, 2, ENC_BIG_ENDIAN);
124 proto_tree_add_item(dvb_nit_tree, hf_dvb_nit_transport_stream_loop_length, tvb, offset, 2, ENC_BIG_ENDIAN);
125 ts_end = offset + (tvb_get_ntohs(tvb, offset) & DVB_NIT_TRANSPORT_STREAM_LOOP_LENGTH_MASK);
126 offset += 2;
128 while (offset < ts_end) {
129 tsid = tvb_get_ntohs(tvb, offset);
130 ts_desc_len = 3 + (tvb_get_ntohs(tvb, offset + 4) & DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK);
132 tsi = proto_tree_add_text(dvb_nit_tree, tvb, offset, ts_desc_len, "Stream ID=0x%04hx", tsid);
133 dvb_nit_ts_tree = proto_item_add_subtree(tsi, ett_dvb_nit_ts);
135 proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_transport_stream_id, tvb, offset, 2, ENC_BIG_ENDIAN);
136 offset += 2;
138 proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_original_network_id, tvb, offset, 2, ENC_BIG_ENDIAN);
139 offset += 2;
141 proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_reserved4, tvb, offset, 2, ENC_BIG_ENDIAN);
142 proto_tree_add_item(dvb_nit_ts_tree, hf_dvb_nit_transport_descriptors_length, tvb, offset, 2, ENC_BIG_ENDIAN);
143 desc_loop_len = tvb_get_ntohs(tvb, offset) & DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK;
144 offset += 2;
146 offset += proto_mpeg_descriptor_loop_dissect(tvb, offset, desc_loop_len, dvb_nit_ts_tree);
149 offset += packet_mpeg_sect_crc(tvb, pinfo, dvb_nit_tree, 0, offset);
151 proto_item_set_len(ti, offset);
152 return offset;
156 void
157 proto_register_dvb_nit(void)
160 static hf_register_info hf[] = {
162 { &hf_dvb_nit_network_id, {
163 "Network ID", "dvb_nit.sid",
164 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
165 } },
167 { &hf_dvb_nit_reserved1, {
168 "Reserved", "dvb_nit.reserved1",
169 FT_UINT8, BASE_HEX, NULL, DVB_NIT_RESERVED1_MASK, NULL, HFILL
170 } },
172 { &hf_dvb_nit_version_number, {
173 "Version Number", "dvb_nit.version",
174 FT_UINT8, BASE_HEX, NULL, DVB_NIT_VERSION_NUMBER_MASK, NULL, HFILL
175 } },
177 { &hf_dvb_nit_current_next_indicator, {
178 "Current/Next Indicator", "dvb_nit.cur_next_ind",
179 FT_UINT8, BASE_DEC, VALS(dvb_nit_cur_next_vals), DVB_NIT_CURRENT_NEXT_INDICATOR_MASK, NULL, HFILL
180 } },
182 { &hf_dvb_nit_section_number, {
183 "Section Number", "dvb_nit.sect_num",
184 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
185 } },
187 { &hf_dvb_nit_last_section_number, {
188 "Last Section Number", "dvb_nit.last_sect_num",
189 FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL
190 } },
192 { &hf_dvb_nit_reserved2, {
193 "Reserved", "dvb_nit.reserved2",
194 FT_UINT16, BASE_HEX, NULL, DVB_NIT_RESERVED2_MASK, NULL, HFILL
195 } },
197 { &hf_dvb_nit_network_descriptors_length, {
198 "Network Descriptors Length", "dvb_nit.network_desc_len",
199 FT_UINT16, BASE_DEC, NULL, DVB_NIT_NETWORK_DESCRIPTORS_LENGTH_MASK, NULL, HFILL
200 } },
202 { &hf_dvb_nit_reserved3, {
203 "Reserved", "dvb_nit.reserved3",
204 FT_UINT16, BASE_HEX, NULL, DVB_NIT_RESERVED3_MASK, NULL, HFILL
205 } },
207 { &hf_dvb_nit_transport_stream_loop_length, {
208 "Transport Stream Loop Length", "dvb_nit.ts_loop_len",
209 FT_UINT16, BASE_DEC, NULL, DVB_NIT_TRANSPORT_STREAM_LOOP_LENGTH_MASK, NULL, HFILL
210 } },
212 { &hf_dvb_nit_transport_stream_id, {
213 "Transport Stream ID", "dvb_nit.ts.id",
214 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
215 } },
217 { &hf_dvb_nit_original_network_id, {
218 "Original Network ID", "dvb_nit.ts.original_network_id",
219 FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL
220 } },
222 { &hf_dvb_nit_reserved4, {
223 "Reserved", "dvb_nit.ts.reserved",
224 FT_UINT16, BASE_HEX, NULL, DVB_NIT_RESERVED4_MASK, NULL, HFILL
225 } },
227 { &hf_dvb_nit_transport_descriptors_length, {
228 "Transport Descriptors Length", "dvb_nit.ts.desc_len",
229 FT_UINT16, BASE_DEC, NULL, DVB_NIT_TRANSPORT_DESCRIPTORS_LENGTH_MASK, NULL, HFILL
230 } },
234 static gint *ett[] = {
235 &ett_dvb_nit,
236 &ett_dvb_nit_ts
239 proto_dvb_nit = proto_register_protocol("DVB Network Information Table", "DVB NIT", "dvb_nit");
241 proto_register_field_array(proto_dvb_nit, hf, array_length(hf));
242 proto_register_subtree_array(ett, array_length(ett));
244 new_register_dissector("dvb_nit", dissect_dvb_nit, proto_dvb_nit);
248 void proto_reg_handoff_dvb_nit(void)
250 dissector_handle_t dvb_nit_handle;
252 dvb_nit_handle = find_dissector("dvb_nit");
254 dissector_add_uint("mpeg_sect.tid", DVB_NIT_TID, dvb_nit_handle);
255 dissector_add_uint("mpeg_sect.tid", DVB_NIT_TID_OTHER, dvb_nit_handle);
260 * Editor modelines - http://www.wireshark.org/tools/modelines.html
262 * Local variables:
263 * c-basic-offset: 4
264 * tab-width: 8
265 * indent-tabs-mode: nil
266 * End:
268 * vi: set shiftwidth=4 tabstop=8 expandtab:
269 * :indentSize=4:tabSize=8:noTabs=true: