2012-05-28 15:24:54 +00:00
|
|
|
/* packet-dmx-chan.c
|
|
|
|
* DMX Channel Data packet disassembly.
|
|
|
|
*
|
|
|
|
* This dissector is written by
|
|
|
|
*
|
|
|
|
* Erwin Rol <erwin@erwinrol.com>
|
|
|
|
* Copyright 2011 Erwin Rol
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1999 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This dissector is based on;
|
|
|
|
* American National Standard E1.11 - 2004
|
|
|
|
* Entertainment Technology USITT DMX512-A
|
|
|
|
* Asynchronous Serial Digital Data Transmission Standard
|
|
|
|
* for Controlling Lighting Equipment and Accessories
|
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2012-05-28 15:24:54 +00:00
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
2013-03-16 16:25:41 +00:00
|
|
|
void proto_register_dmx_chan(void);
|
|
|
|
|
2012-05-28 15:24:54 +00:00
|
|
|
static int proto_dmx_chan = -1;
|
|
|
|
|
|
|
|
static int hf_dmx_chan_output_dmx_data = -1;
|
|
|
|
static int hf_dmx_chan_output_data_filter = -1;
|
|
|
|
|
|
|
|
static int ett_dmx_chan = -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here are the global variables associated with the preferences for DMX
|
|
|
|
*/
|
|
|
|
static gint global_disp_chan_val_type = 0;
|
2012-07-16 12:34:33 +00:00
|
|
|
static gint global_disp_col_count = 16;
|
|
|
|
static gint global_disp_chan_nr_type = 0;
|
2012-05-28 15:24:54 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_dmx_chan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "DMX Channels");
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
|
|
|
|
|
|
|
if (tree != NULL) {
|
2012-07-16 12:34:33 +00:00
|
|
|
static const char *chan_format[] = {
|
2012-05-28 15:24:54 +00:00
|
|
|
"%2u%% ",
|
|
|
|
"0x%02x ",
|
|
|
|
"%3u "
|
|
|
|
};
|
2012-07-16 12:34:33 +00:00
|
|
|
static const char *string_format[] = {
|
2012-05-28 15:24:54 +00:00
|
|
|
"0x%03x: %s",
|
|
|
|
"%3u: %s"
|
|
|
|
};
|
2013-09-14 10:53:29 +00:00
|
|
|
wmem_strbuf_t *chan_str = wmem_strbuf_new_label(wmem_packet_scope());
|
2012-07-16 12:34:33 +00:00
|
|
|
proto_item *item;
|
|
|
|
guint16 length,r,c,row_count;
|
|
|
|
guint8 v;
|
2013-01-04 05:22:43 +00:00
|
|
|
guint offset = 0;
|
2012-05-28 15:24:54 +00:00
|
|
|
|
2012-10-18 18:11:56 +00:00
|
|
|
proto_tree *ti = proto_tree_add_item(tree, proto_dmx_chan, tvb, offset, -1, ENC_NA);
|
2012-07-16 12:34:33 +00:00
|
|
|
proto_tree *dmx_chan_tree = proto_item_add_subtree(ti, ett_dmx_chan);
|
2012-05-28 15:24:54 +00:00
|
|
|
|
|
|
|
length = tvb_reported_length_remaining(tvb, offset);
|
|
|
|
|
|
|
|
row_count = (length / global_disp_col_count) + ((length % global_disp_col_count) == 0 ? 0 : 1);
|
|
|
|
for (r = 0; r < row_count;r++) {
|
2013-12-29 18:45:09 +00:00
|
|
|
wmem_strbuf_truncate(chan_str, 0);
|
2012-05-28 15:24:54 +00:00
|
|
|
for (c = 0;(c < global_disp_col_count) && (((r * global_disp_col_count) + c) < length);c++) {
|
2012-05-31 20:24:04 +00:00
|
|
|
if ((global_disp_col_count >= 2) && ((c % (global_disp_col_count / 2)) == 0)) {
|
2013-09-14 10:53:29 +00:00
|
|
|
wmem_strbuf_append(chan_str, " ");
|
2012-05-28 15:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v = tvb_get_guint8(tvb, (offset + (r * global_disp_col_count) + c));
|
|
|
|
if (global_disp_chan_val_type == 0) {
|
|
|
|
v = (v * 100) / 255;
|
|
|
|
if (v == 100) {
|
2013-09-14 10:53:29 +00:00
|
|
|
wmem_strbuf_append(chan_str, "FL ");
|
2012-05-28 15:24:54 +00:00
|
|
|
} else {
|
2013-09-14 10:53:29 +00:00
|
|
|
wmem_strbuf_append_printf(chan_str, chan_format[global_disp_chan_val_type], v);
|
2012-05-28 15:24:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-09-14 10:53:29 +00:00
|
|
|
wmem_strbuf_append_printf(chan_str, chan_format[global_disp_chan_val_type], v);
|
2012-05-28 15:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proto_tree_add_none_format(dmx_chan_tree, hf_dmx_chan_output_dmx_data, tvb,
|
|
|
|
offset+(r * global_disp_col_count), c,
|
|
|
|
string_format[global_disp_chan_nr_type],
|
2013-09-14 10:53:29 +00:00
|
|
|
(r * global_disp_col_count) + 1, wmem_strbuf_get_str(chan_str));
|
2012-05-28 15:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the real type hidden */
|
|
|
|
item = proto_tree_add_item(dmx_chan_tree, hf_dmx_chan_output_data_filter, tvb,
|
|
|
|
offset, length, ENC_NA );
|
|
|
|
PROTO_ITEM_SET_HIDDEN(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_dmx_chan(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_dmx_chan_output_data_filter,
|
|
|
|
{ "DMX data filter",
|
|
|
|
"dmx_chan.data_filter",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
|
|
|
|
{ &hf_dmx_chan_output_dmx_data,
|
|
|
|
{ "DMX data",
|
|
|
|
"dmx_chan.dmx_data",
|
|
|
|
FT_NONE, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }},
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_dmx_chan
|
|
|
|
};
|
|
|
|
|
|
|
|
module_t *dmx_chan_module;
|
|
|
|
|
2012-11-29 20:15:37 +00:00
|
|
|
static const enum_val_t disp_chan_val_types[] = {
|
2012-05-28 15:24:54 +00:00
|
|
|
{ "pro", "Percent", 0 },
|
|
|
|
{ "hex", "Hexadecimal", 1 },
|
|
|
|
{ "dec", "Decimal", 2 },
|
|
|
|
{ NULL, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2012-11-29 20:15:37 +00:00
|
|
|
static const enum_val_t disp_chan_nr_types[] = {
|
2012-05-28 15:24:54 +00:00
|
|
|
{ "hex", "Hexadecimal", 0 },
|
|
|
|
{ "dec", "Decimal", 1 },
|
|
|
|
{ NULL, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2012-11-29 20:15:37 +00:00
|
|
|
static const enum_val_t col_count[] = {
|
2012-10-18 18:11:56 +00:00
|
|
|
{ "6", "6", 6 },
|
2012-05-28 15:24:54 +00:00
|
|
|
{ "10", "10", 10 },
|
|
|
|
{ "12", "12", 12 },
|
|
|
|
{ "16", "16", 16 },
|
|
|
|
{ "24", "24", 24 },
|
|
|
|
{ NULL, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_dmx_chan = proto_register_protocol("DMX Channels","DMX Channels", "dmx-chan");
|
|
|
|
proto_register_field_array(proto_dmx_chan, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
register_dissector("dmx-chan", dissect_dmx_chan, proto_dmx_chan);
|
|
|
|
|
|
|
|
dmx_chan_module = prefs_register_protocol(proto_dmx_chan, NULL);
|
|
|
|
|
|
|
|
prefs_register_enum_preference(dmx_chan_module, "dmx_disp_chan_val_type",
|
|
|
|
"DMX Display channel value type",
|
|
|
|
"The way DMX values are displayed",
|
|
|
|
&global_disp_chan_val_type,
|
2012-10-18 18:11:56 +00:00
|
|
|
disp_chan_val_types, FALSE);
|
2012-05-28 15:24:54 +00:00
|
|
|
|
|
|
|
prefs_register_enum_preference(dmx_chan_module, "dmx_disp_chan_nr_type",
|
|
|
|
"DMX Display channel nr. type",
|
|
|
|
"The way DMX channel numbers are displayed",
|
|
|
|
&global_disp_chan_nr_type,
|
2012-10-18 18:11:56 +00:00
|
|
|
disp_chan_nr_types, FALSE);
|
2012-05-28 15:24:54 +00:00
|
|
|
|
|
|
|
prefs_register_enum_preference(dmx_chan_module, "dmx_disp_col_count",
|
|
|
|
"DMX Display Column Count",
|
|
|
|
"The number of columns for the DMX display",
|
|
|
|
&global_disp_col_count,
|
2012-10-18 18:11:56 +00:00
|
|
|
col_count, FALSE);
|
2012-05-28 15:24:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 20:59:17 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|