2 * DMX Channel Data packet disassembly.
4 * This dissector is written by
6 * Erwin Rol <erwin@erwinrol.com>
7 * Copyright 2011 Erwin Rol
9 * Wireshark - Network traffic analyzer
10 * Gerald Combs <gerald@wireshark.org>
11 * Copyright 1999 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor
26 * Boston, MA 02110-1301, USA.
30 * This dissector is based on;
31 * American National Standard E1.11 - 2004
32 * Entertainment Technology USITT DMX512-A
33 * Asynchronous Serial Digital Data Transmission Standard
34 * for Controlling Lighting Equipment and Accessories
39 #include <epan/packet.h>
40 #include <epan/prefs.h>
42 void proto_register_dmx_chan(void);
44 static int proto_dmx_chan = -1;
46 static int hf_dmx_chan_output_dmx_data = -1;
47 static int hf_dmx_chan_output_data_filter = -1;
49 static int ett_dmx_chan = -1;
52 * Here are the global variables associated with the preferences for DMX
54 static gint global_disp_chan_val_type = 0;
55 static gint global_disp_col_count = 16;
56 static gint global_disp_chan_nr_type = 0;
59 dissect_dmx_chan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
61 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DMX Channels");
62 col_clear(pinfo->cinfo, COL_INFO);
65 static const char *chan_format[] = {
70 static const char *string_format[] = {
74 wmem_strbuf_t *chan_str = wmem_strbuf_new_label(wmem_packet_scope());
76 guint16 length,r,c,row_count;
80 proto_tree *ti = proto_tree_add_item(tree, proto_dmx_chan, tvb, offset, -1, ENC_NA);
81 proto_tree *dmx_chan_tree = proto_item_add_subtree(ti, ett_dmx_chan);
83 length = tvb_reported_length_remaining(tvb, offset);
85 row_count = (length / global_disp_col_count) + ((length % global_disp_col_count) == 0 ? 0 : 1);
86 for (r = 0; r < row_count;r++) {
87 wmem_strbuf_truncate(chan_str, 0);
88 for (c = 0;(c < global_disp_col_count) && (((r * global_disp_col_count) + c) < length);c++) {
89 if ((global_disp_col_count >= 2) && ((c % (global_disp_col_count / 2)) == 0)) {
90 wmem_strbuf_append(chan_str, " ");
93 v = tvb_get_guint8(tvb, (offset + (r * global_disp_col_count) + c));
94 if (global_disp_chan_val_type == 0) {
97 wmem_strbuf_append(chan_str, "FL ");
99 wmem_strbuf_append_printf(chan_str, chan_format[global_disp_chan_val_type], v);
102 wmem_strbuf_append_printf(chan_str, chan_format[global_disp_chan_val_type], v);
106 proto_tree_add_none_format(dmx_chan_tree, hf_dmx_chan_output_dmx_data, tvb,
107 offset+(r * global_disp_col_count), c,
108 string_format[global_disp_chan_nr_type],
109 (r * global_disp_col_count) + 1, wmem_strbuf_get_str(chan_str));
112 /* Add the real type hidden */
113 item = proto_tree_add_item(dmx_chan_tree, hf_dmx_chan_output_data_filter, tvb,
114 offset, length, ENC_NA );
115 PROTO_ITEM_SET_HIDDEN(item);
120 proto_register_dmx_chan(void)
122 static hf_register_info hf[] = {
123 { &hf_dmx_chan_output_data_filter,
125 "dmx_chan.data_filter",
126 FT_BYTES, BASE_NONE, NULL, 0x0,
129 { &hf_dmx_chan_output_dmx_data,
132 FT_NONE, BASE_NONE, NULL, 0x0,
136 static gint *ett[] = {
140 module_t *dmx_chan_module;
142 static const enum_val_t disp_chan_val_types[] = {
143 { "pro", "Percent", 0 },
144 { "hex", "Hexadecimal", 1 },
145 { "dec", "Decimal", 2 },
149 static const enum_val_t disp_chan_nr_types[] = {
150 { "hex", "Hexadecimal", 0 },
151 { "dec", "Decimal", 1 },
155 static const enum_val_t col_count[] = {
164 proto_dmx_chan = proto_register_protocol("DMX Channels","DMX Channels", "dmx-chan");
165 proto_register_field_array(proto_dmx_chan, hf, array_length(hf));
166 proto_register_subtree_array(ett, array_length(ett));
167 register_dissector("dmx-chan", dissect_dmx_chan, proto_dmx_chan);
169 dmx_chan_module = prefs_register_protocol(proto_dmx_chan, NULL);
171 prefs_register_enum_preference(dmx_chan_module, "dmx_disp_chan_val_type",
172 "DMX Display channel value type",
173 "The way DMX values are displayed",
174 &global_disp_chan_val_type,
175 disp_chan_val_types, FALSE);
177 prefs_register_enum_preference(dmx_chan_module, "dmx_disp_chan_nr_type",
178 "DMX Display channel nr. type",
179 "The way DMX channel numbers are displayed",
180 &global_disp_chan_nr_type,
181 disp_chan_nr_types, FALSE);
183 prefs_register_enum_preference(dmx_chan_module, "dmx_disp_col_count",
184 "DMX Display Column Count",
185 "The number of columns for the DMX display",
186 &global_disp_col_count,
191 * Editor modelines - http://www.wireshark.org/tools/modelines.html
196 * indent-tabs-mode: t
199 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
200 * :indentSize=8:tabSize=8:noTabs=false: