HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-dmx-sip.c
blobdd1bd5c20e4e49eee2c54a7f59cf62d711c3fc00
1 /* packet-dmx-sip.c
2 * DMX SIP packet disassembly.
4 * $Id$
6 * This dissector is written by
8 * Erwin Rol <erwin@erwinrol.com>
9 * Copyright 2011 Erwin Rol
11 * Wireshark - Network traffic analyzer
12 * Gerald Combs <gerald@wireshark.org>
13 * Copyright 1999 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor
28 * Boston, MA 02110-1301, USA.
32 * This dissector is based on;
33 * American National Standard E1.11 - 2004
34 * Entertainment Technology USITT DMX512-A
35 * Asynchronous Serial Digital Data Transmission Standard
36 * for Controlling Lighting Equipment and Accessories
39 #include "config.h"
41 #include <epan/packet.h>
43 #define DMX_SC_SIP 0xCF
45 void proto_register_dmx_sip(void);
47 static int proto_dmx_sip = -1;
49 static int hf_dmx_sip_byte_count = -1;
50 static int hf_dmx_sip_control_bit_field = -1;
51 static int hf_dmx_sip_prev_packet_checksum = -1;
52 static int hf_dmx_sip_seq_nr = -1;
53 static int hf_dmx_sip_dmx_universe_nr = -1;
54 static int hf_dmx_sip_dmx_proc_level = -1;
55 static int hf_dmx_sip_dmx_software_version = -1;
56 static int hf_dmx_sip_dmx_packet_len = -1;
57 static int hf_dmx_sip_dmx_nr_packets = -1;
58 static int hf_dmx_sip_orig_dev_id = -1;
59 static int hf_dmx_sip_sec_dev_id = -1;
60 static int hf_dmx_sip_third_dev_id = -1;
61 static int hf_dmx_sip_fourth_dev_id = -1;
62 static int hf_dmx_sip_fifth_dev_id = -1;
63 static int hf_dmx_sip_reserved = -1;
64 static int hf_dmx_sip_checksum = -1;
65 static int hf_dmx_sip_checksum_good = -1;
66 static int hf_dmx_sip_checksum_bad = -1;
67 static int hf_dmx_sip_trailer = -1;
69 static int ett_dmx_sip = -1;
71 static guint8
72 dmx_sip_checksum(tvbuff_t *tvb, guint length)
74 guint8 sum = DMX_SC_SIP;
75 guint i;
76 for (i = 0; i < length; i++)
77 sum += tvb_get_guint8(tvb, i);
78 return sum;
81 static void
82 dissect_dmx_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
84 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DMX SIP");
85 col_clear(pinfo->cinfo, COL_INFO);
87 if (tree != NULL) {
88 guint offset = 0;
89 guint byte_count;
90 guint checksum, checksum_shouldbe;
91 proto_item *item;
92 proto_tree *checksum_tree;
94 proto_tree *ti = proto_tree_add_item(tree, proto_dmx_sip, tvb,
95 offset, -1, FALSE);
96 proto_tree *dmx_sip_tree = proto_item_add_subtree(ti, ett_dmx_sip);
99 byte_count = tvb_get_guint8(tvb, offset);
100 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_byte_count, tvb,
101 offset, 1, ENC_BIG_ENDIAN);
102 offset++;
104 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_control_bit_field, tvb,
105 offset, 1, ENC_BIG_ENDIAN);
106 offset++;
108 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_prev_packet_checksum, tvb,
109 offset, 2, ENC_BIG_ENDIAN);
110 offset += 2;
112 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_seq_nr, tvb,
113 offset, 1, ENC_BIG_ENDIAN);
114 offset++;
116 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_dmx_universe_nr, tvb,
117 offset, 1, ENC_BIG_ENDIAN);
118 offset++;
120 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_dmx_proc_level, tvb,
121 offset, 1, ENC_BIG_ENDIAN);
122 offset++;
124 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_dmx_software_version, tvb,
125 offset, 1, ENC_BIG_ENDIAN);
126 offset++;
128 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_dmx_packet_len, tvb,
129 offset, 2, ENC_BIG_ENDIAN);
130 offset += 2;
132 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_dmx_nr_packets, tvb,
133 offset, 2, ENC_BIG_ENDIAN);
134 offset += 2;
136 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_orig_dev_id, tvb,
137 offset, 2, ENC_BIG_ENDIAN);
138 offset += 2;
140 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_sec_dev_id, tvb,
141 offset, 2, ENC_BIG_ENDIAN);
142 offset += 2;
144 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_third_dev_id, tvb,
145 offset, 2, ENC_BIG_ENDIAN);
146 offset += 2;
148 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_fourth_dev_id, tvb,
149 offset, 2, ENC_BIG_ENDIAN);
150 offset += 2;
152 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_fifth_dev_id, tvb,
153 offset, 2, ENC_BIG_ENDIAN);
154 offset += 2;
156 if (offset < byte_count) {
157 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_reserved, tvb,
158 offset, byte_count - offset, ENC_BIG_ENDIAN);
159 offset += (byte_count - offset);
162 dmx_sip_checksum(tvb, offset);
164 checksum_shouldbe = dmx_sip_checksum(tvb, offset);
165 checksum = tvb_get_guint8(tvb, offset);
166 item = proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_checksum, tvb,
167 offset, 1, ENC_BIG_ENDIAN);
168 if (checksum == checksum_shouldbe) {
169 proto_item_append_text(item, " [correct]");
171 checksum_tree = proto_item_add_subtree(item, ett_dmx_sip);
172 item = proto_tree_add_boolean(checksum_tree, hf_dmx_sip_checksum_good, tvb,
173 offset, 1, TRUE);
174 PROTO_ITEM_SET_GENERATED(item);
175 item = proto_tree_add_boolean(checksum_tree, hf_dmx_sip_checksum_bad, tvb,
176 offset, 1, FALSE);
177 PROTO_ITEM_SET_GENERATED(item);
178 } else {
179 proto_item_append_text(item, " [incorrect, should be 0x%02x]", checksum_shouldbe);
181 checksum_tree = proto_item_add_subtree(item, ett_dmx_sip);
182 item = proto_tree_add_boolean(checksum_tree, hf_dmx_sip_checksum_good, tvb,
183 offset, 1, FALSE);
184 PROTO_ITEM_SET_GENERATED(item);
185 item = proto_tree_add_boolean(checksum_tree, hf_dmx_sip_checksum_bad, tvb,
186 offset, 1, TRUE);
187 PROTO_ITEM_SET_GENERATED(item);
190 offset += 1;
192 if (offset < tvb_length(tvb))
193 proto_tree_add_item(dmx_sip_tree, hf_dmx_sip_trailer, tvb,
194 offset, -1, ENC_NA);
198 void
199 proto_register_dmx_sip(void)
201 static hf_register_info hf[] = {
202 { &hf_dmx_sip_byte_count,
203 { "Byte Count", "dmx_sip.byte_count",
204 FT_UINT8, BASE_DEC, NULL, 0x0,
205 NULL, HFILL }},
207 { &hf_dmx_sip_control_bit_field,
208 { "Control Bit Field", "dmx_sip.control_bit_field",
209 FT_UINT8, BASE_HEX, NULL, 0x0,
210 NULL, HFILL }},
212 { &hf_dmx_sip_prev_packet_checksum,
213 { "Checksum of prev. packet", "dmx_sip.prev_packet_checksum",
214 FT_UINT16, BASE_HEX, NULL, 0x0,
215 NULL, HFILL }},
217 { &hf_dmx_sip_seq_nr,
218 { "SIP sequence nr.", "dmx_sip.seq_nr",
219 FT_UINT8, BASE_DEC, NULL, 0x0,
220 NULL, HFILL }},
222 { &hf_dmx_sip_dmx_universe_nr,
223 { "DMX512 universe nr.", "dmx_sip.dmx_universe_nr",
224 FT_UINT8, BASE_DEC, NULL, 0x0,
225 NULL, HFILL }},
227 { &hf_dmx_sip_dmx_proc_level,
228 { "DMX512 processing level", "dmx_sip.dmx_proc_level",
229 FT_UINT8, BASE_DEC, NULL, 0x0,
230 NULL, HFILL }},
232 { &hf_dmx_sip_dmx_software_version,
233 { "Software Version", "dmx_sip.dmx_software_version",
234 FT_UINT8, BASE_HEX, NULL, 0x0,
235 NULL, HFILL }},
237 { &hf_dmx_sip_dmx_packet_len,
238 { "Standard Packet Len", "dmx_sip.dmx_packet_len",
239 FT_UINT16, BASE_HEX, NULL, 0x0,
240 NULL, HFILL }},
242 { &hf_dmx_sip_dmx_nr_packets,
243 { "Number of Packets", "dmx_sip.dmx_nr_packets",
244 FT_UINT16, BASE_DEC, NULL, 0x0,
245 NULL, HFILL }},
247 { &hf_dmx_sip_orig_dev_id,
248 { "1st Device's ID", "dmx_sip.orig_dev_id",
249 FT_UINT16, BASE_HEX, NULL, 0x0,
250 NULL, HFILL }},
252 { &hf_dmx_sip_sec_dev_id,
253 { "2nd Device's ID", "dmx_sip.sec_dev_id",
254 FT_UINT16, BASE_HEX, NULL, 0x0,
255 NULL, HFILL }},
257 { &hf_dmx_sip_third_dev_id,
258 { "3rd Device's ID", "dmx_sip.third_dev_id",
259 FT_UINT16, BASE_HEX, NULL, 0x0,
260 NULL, HFILL }},
262 { &hf_dmx_sip_fourth_dev_id,
263 { "4th Device's ID", "dmx_sip.fourth_dev_id",
264 FT_UINT16, BASE_HEX, NULL, 0x0,
265 NULL, HFILL }},
267 { &hf_dmx_sip_fifth_dev_id,
268 { "5th Device's ID", "dmx_sip.fifth_dev_id",
269 FT_UINT16, BASE_HEX, NULL, 0x0,
270 NULL, HFILL }},
272 { &hf_dmx_sip_reserved,
273 { "Reserved", "dmx_sip.reserved",
274 FT_BYTES, BASE_NONE, NULL, 0x0,
275 NULL, HFILL }},
277 { &hf_dmx_sip_checksum,
278 { "Checksum", "dmx_sip.checksum",
279 FT_UINT8, BASE_HEX, NULL, 0x0,
280 NULL, HFILL }},
282 { &hf_dmx_sip_checksum_good,
283 { "Good Checksum", "dmx_sip.checksum_good",
284 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
285 "True: checksum matches packet content; False: doesn't match content", HFILL }},
287 { &hf_dmx_sip_checksum_bad,
288 { "Bad Checksum", "dmx_sip.checksum_bad",
289 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
290 "True: checksum doesn't match packet content; False: matches content", HFILL }},
292 { &hf_dmx_sip_trailer,
293 { "Trailer", "dmx_sip.trailer",
294 FT_BYTES, BASE_NONE, NULL, 0x0,
295 NULL, HFILL }},
298 static gint *ett[] = {
299 &ett_dmx_sip
302 proto_dmx_sip = proto_register_protocol("DMX SIP", "DMX SIP", "dmx-sip");
303 proto_register_field_array(proto_dmx_sip, hf, array_length(hf));
304 proto_register_subtree_array(ett, array_length(ett));
305 register_dissector("dmx-sip", dissect_dmx_sip, proto_dmx_sip);