2 * Routines for ENTTEC packet disassembly
6 * Copyright (c) 2003,2004 by Erwin Rol <erwin@erwinrol.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1999 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
37 #include <epan/addr_resolv.h>
38 #include <epan/prefs.h>
39 #include <epan/strutil.h>
44 * http://www.enttec.com/docs/enttec_protocol.pdf
47 /* Define UDP/TCP ports for ENTTEC */
49 #define UDP_PORT_ENTTEC 0x0D05
50 #define TCP_PORT_ENTTEC 0x0D05
53 #define ENTTEC_HEAD_ESPR 0x45535052
54 #define ENTTEC_HEAD_ESPP 0x45535050
55 #define ENTTEC_HEAD_ESAP 0x45534150
56 #define ENTTEC_HEAD_ESDD 0x45534444
57 #define ENTTEC_HEAD_ESNC 0x45534E43
58 #define ENTTEC_HEAD_ESZZ 0x45535A5A
60 static const value_string enttec_head_vals[] = {
61 { ENTTEC_HEAD_ESPR, "Poll Reply" },
62 { ENTTEC_HEAD_ESPP, "Poll" },
63 { ENTTEC_HEAD_ESAP, "Ack/nAck" },
64 { ENTTEC_HEAD_ESDD, "DMX Data" },
65 { ENTTEC_HEAD_ESNC, "Config" },
66 { ENTTEC_HEAD_ESZZ, "Reset" },
70 #define ENTTEC_DATA_TYPE_DMX 0x01
71 #define ENTTEC_DATA_TYPE_CHAN_VAL 0x02
72 #define ENTTEC_DATA_TYPE_RLE 0x04
74 static const value_string enttec_data_type_vals[] = {
75 { ENTTEC_DATA_TYPE_DMX, "Uncompressed DMX" },
76 { ENTTEC_DATA_TYPE_CHAN_VAL, "Channel+Value" },
77 { ENTTEC_DATA_TYPE_RLE, "RLE Compressed DMX" },
81 void proto_reg_handoff_enttec(void);
83 /* Define the enttec proto */
84 static int proto_enttec = -1;
87 static int hf_enttec_head = -1;
90 static int hf_enttec_poll_type = -1;
93 static int hf_enttec_poll_reply_mac = -1;
94 static int hf_enttec_poll_reply_node_type = -1;
95 static int hf_enttec_poll_reply_version = -1;
96 static int hf_enttec_poll_reply_switch = -1;
97 static int hf_enttec_poll_reply_name = -1;
98 static int hf_enttec_poll_reply_option = -1;
99 static int hf_enttec_poll_reply_tos = -1;
100 static int hf_enttec_poll_reply_ttl = -1;
103 static int hf_enttec_dmx_data_universe = -1;
104 static int hf_enttec_dmx_data_start_code = -1;
105 static int hf_enttec_dmx_data_type = -1;
106 static int hf_enttec_dmx_data_size = -1;
107 static int hf_enttec_dmx_data_data = -1;
108 static int hf_enttec_dmx_data_data_filter = -1;
109 static int hf_enttec_dmx_data_dmx_data = -1;
111 /* Define the tree for enttec */
112 static int ett_enttec = -1;
115 * Here are the global variables associated with the preferences
119 static guint global_udp_port_enttec = UDP_PORT_ENTTEC;
120 static guint global_tcp_port_enttec = TCP_PORT_ENTTEC;
122 static gint global_disp_chan_val_type = 0;
123 static gint global_disp_col_count = 16;
124 static gint global_disp_chan_nr_type = 0;
127 dissect_enttec_poll_reply(tvbuff_t *tvb, guint offset, proto_tree *tree)
129 proto_tree_add_item(tree, hf_enttec_poll_reply_mac, tvb,
133 proto_tree_add_item(tree, hf_enttec_poll_reply_node_type, tvb,
137 proto_tree_add_item(tree, hf_enttec_poll_reply_version, tvb,
141 proto_tree_add_item(tree, hf_enttec_poll_reply_switch, tvb,
145 proto_tree_add_item(tree, hf_enttec_poll_reply_name, tvb,
149 proto_tree_add_item(tree, hf_enttec_poll_reply_option, tvb,
153 proto_tree_add_item(tree, hf_enttec_poll_reply_tos, tvb,
157 proto_tree_add_item(tree, hf_enttec_poll_reply_ttl, tvb,
167 dissect_enttec_poll(tvbuff_t *tvb, guint offset, proto_tree *tree)
169 proto_tree_add_item(tree, hf_enttec_poll_type, tvb,
177 dissect_enttec_ack(tvbuff_t *tvb _U_, guint offset, proto_tree *tree _U_)
184 dissect_enttec_dmx_data(tvbuff_t *tvb, guint offset, proto_tree *tree)
186 const char* chan_format[] = {
191 const char* string_format[] = {
196 static guint8 dmx_data[512];
197 static guint16 dmx_data_offset[513]; /* 1 extra for last offset */
198 emem_strbuf_t *dmx_epstr;
202 guint16 length,r,c,row_count;
204 guint16 ci,ui,i,start_offset,end_offset;
206 proto_tree_add_item(tree, hf_enttec_dmx_data_universe, tvb,
210 proto_tree_add_item(tree, hf_enttec_dmx_data_start_code, tvb,
214 type = tvb_get_guint8(tvb, offset);
215 proto_tree_add_item(tree, hf_enttec_dmx_data_type, tvb,
219 length = tvb_get_ntohs(tvb, offset);
220 proto_tree_add_item(tree, hf_enttec_dmx_data_size, tvb,
227 if (type == ENTTEC_DATA_TYPE_RLE) {
228 /* uncompres the DMX data */
231 while (ci < length) {
232 v = tvb_get_guint8(tvb, offset+ci);
235 count = tvb_get_guint8(tvb, offset+ci);
237 v = tvb_get_guint8(tvb, offset+ci);
239 for (i=0;i < count;i++) {
241 dmx_data_offset[ui] = ci-3;
244 } else if (v == 0xFD) {
246 v = tvb_get_guint8(tvb, offset+ci);
248 dmx_data_offset[ui] = ci;
253 dmx_data_offset[ui] = ci;
258 dmx_data_offset[ui] = ci;
260 for (ui=0; ui < length;ui++) {
261 dmx_data[ui] = tvb_get_guint8(tvb, offset+ui);
262 dmx_data_offset[ui] = ui;
264 dmx_data_offset[ui] = ui;
268 if (type == ENTTEC_DATA_TYPE_DMX || type == ENTTEC_DATA_TYPE_RLE) {
269 hi = proto_tree_add_item(tree,
270 hf_enttec_dmx_data_data,
276 si = proto_item_add_subtree(hi, ett_enttec);
278 row_count = (ui/global_disp_col_count) + ((ui%global_disp_col_count) == 0 ? 0 : 1);
279 dmx_epstr = ep_strbuf_new_label(NULL);
280 for (r=0; r < row_count;r++) {
281 for (c=0;(c < global_disp_col_count) && (((r*global_disp_col_count)+c) < ui);c++) {
282 if ((c % (global_disp_col_count/2)) == 0) {
283 ep_strbuf_append_c(dmx_epstr, ' ');
285 v = dmx_data[(r*global_disp_col_count)+c];
286 if (global_disp_chan_val_type == 0) {
289 ep_strbuf_append(dmx_epstr, "FL ");
291 ep_strbuf_append_printf(dmx_epstr, chan_format[global_disp_chan_val_type], v);
294 ep_strbuf_append_printf(dmx_epstr, chan_format[global_disp_chan_val_type], v);
298 start_offset = dmx_data_offset[(r*global_disp_col_count)];
299 end_offset = dmx_data_offset[(r*global_disp_col_count)+c];
301 proto_tree_add_none_format(si,hf_enttec_dmx_data_dmx_data, tvb,
303 end_offset-start_offset,
304 string_format[global_disp_chan_nr_type], (r*global_disp_col_count)+1, dmx_epstr->str);
305 ep_strbuf_truncate(dmx_epstr, 0);
308 item = proto_tree_add_item(si, hf_enttec_dmx_data_data_filter, tvb,
309 offset, length, FALSE );
310 PROTO_ITEM_SET_HIDDEN(item);
313 } else if (type == ENTTEC_DATA_TYPE_CHAN_VAL) {
314 proto_tree_add_item(tree, hf_enttec_dmx_data_data_filter, tvb,
315 offset, length, FALSE);
318 proto_tree_add_item(tree, hf_enttec_dmx_data_data_filter, tvb,
319 offset, length, FALSE);
329 dissect_enttec_config(tvbuff_t *tvb _U_, guint offset, proto_tree *tree _U_)
336 dissect_enttec_reset(tvbuff_t *tvb _U_, guint offset, proto_tree *tree _U_)
343 dissect_enttec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
347 proto_tree *ti,*enttec_tree=NULL;
349 /* Set the protocol column */
350 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ENTTEC");
352 head = tvb_get_ntohl(tvb, offset);
354 /* Clear out stuff in the info column */
355 if (check_col(pinfo->cinfo,COL_INFO)) {
356 col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
357 val_to_str(head, enttec_head_vals, "Unknown (0x%08x)"));
361 ti = proto_tree_add_item(tree, proto_enttec, tvb, offset, -1, FALSE);
362 enttec_tree = proto_item_add_subtree(ti, ett_enttec);
366 proto_tree_add_item(enttec_tree, hf_enttec_head, tvb,
371 case ENTTEC_HEAD_ESPR:
372 offset = dissect_enttec_poll_reply( tvb, offset, enttec_tree);
375 case ENTTEC_HEAD_ESPP:
376 offset = dissect_enttec_poll( tvb, offset, enttec_tree);
379 case ENTTEC_HEAD_ESAP:
380 offset = dissect_enttec_ack( tvb, offset, enttec_tree);
383 case ENTTEC_HEAD_ESDD:
384 offset = dissect_enttec_dmx_data( tvb, offset, enttec_tree);
387 case ENTTEC_HEAD_ESNC:
388 offset = dissect_enttec_config( tvb, offset, enttec_tree);
391 case ENTTEC_HEAD_ESZZ:
392 offset = dissect_enttec_reset( tvb, offset, enttec_tree);
400 proto_register_enttec(void)
402 static hf_register_info hf[] = {
405 { "Head", "enttec.head",
406 FT_UINT32, BASE_HEX, VALS(enttec_head_vals), 0x0,
408 { &hf_enttec_poll_reply_mac,
409 { "MAC", "enttec.poll_reply.mac",
410 FT_ETHER, BASE_NONE, NULL, 0x0,
412 { &hf_enttec_poll_reply_node_type,
413 { "Node Type", "enttec.poll_reply.node_type",
414 FT_UINT16, BASE_HEX, NULL, 0x0,
416 { &hf_enttec_poll_reply_version,
417 { "Version", "enttec.poll_reply.version",
418 FT_UINT8, BASE_DEC, NULL, 0x0,
420 { &hf_enttec_poll_reply_switch,
421 { "Switch settings", "enttec.poll_reply.switch_settings",
422 FT_UINT8, BASE_HEX, NULL, 0x0,
424 { &hf_enttec_poll_reply_name,
425 { "Name", "enttec.poll_reply.name",
426 FT_STRING, BASE_NONE, NULL, 0x0,
428 { &hf_enttec_poll_reply_option,
429 { "Option Field", "enttec.poll_reply.option_field",
430 FT_UINT8, BASE_HEX, NULL, 0x0,
432 { &hf_enttec_poll_reply_tos,
433 { "TOS", "enttec.poll_reply.tos",
434 FT_UINT8, BASE_HEX, NULL, 0x0,
436 { &hf_enttec_poll_reply_ttl,
437 { "TTL", "enttec.poll_reply.ttl",
438 FT_UINT8, BASE_DEC, NULL, 0x0,
440 { &hf_enttec_dmx_data_universe,
441 { "Universe", "enttec.dmx_data.universe",
442 FT_UINT8, BASE_DEC, NULL, 0x0,
444 { &hf_enttec_dmx_data_start_code,
445 { "Start Code", "enttec.dmx_data.start_code",
446 FT_UINT8, BASE_DEC, NULL, 0x0,
448 { &hf_enttec_dmx_data_type,
449 { "Data Type", "enttec.dmx_data.type",
450 FT_UINT8, BASE_HEX, VALS(enttec_data_type_vals), 0x0,
452 { &hf_enttec_dmx_data_size,
453 { "Data Size", "enttec.dmx_data.size",
454 FT_UINT16, BASE_DEC, NULL, 0x0,
456 { &hf_enttec_dmx_data_data,
457 { "DMX Data", "enttec.dmx_data.data",
458 FT_NONE, BASE_NONE, NULL, 0x0,
460 { &hf_enttec_dmx_data_data_filter,
461 { "DMX Data", "enttec.dmx_data.data_filter",
462 FT_BYTES, BASE_NONE, NULL, 0x0,
464 { &hf_enttec_dmx_data_dmx_data,
465 { "DMX Data", "enttec.dmx_data.dmx_data",
466 FT_NONE, BASE_NONE, NULL, 0x0,
468 { &hf_enttec_poll_type,
469 { "Reply Type", "enttec.poll.reply_type",
470 FT_UINT8, BASE_DEC, NULL, 0x0,
474 static gint *ett[] = {
478 module_t *enttec_module;
480 static enum_val_t disp_chan_val_types[] = {
481 { "pro", "Percent", 0 },
482 { "hex", "Hexadecimal", 1 },
483 { "dec", "Decimal", 2 },
487 static enum_val_t disp_chan_nr_types[] = {
488 { "hex", "Hexadecimal", 0 },
489 { "dec", "Decimal", 1 },
493 static enum_val_t col_count[] = {
502 proto_enttec = proto_register_protocol("ENTTEC", "ENTTEC","enttec");
503 proto_register_field_array(proto_enttec,hf,array_length(hf));
504 proto_register_subtree_array(ett,array_length(ett));
506 enttec_module = prefs_register_protocol(proto_enttec,
507 proto_reg_handoff_enttec);
508 prefs_register_uint_preference(enttec_module, "udp_port",
510 "The UDP port on which ENTTEC packets will be sent",
511 10,&global_udp_port_enttec);
513 prefs_register_uint_preference(enttec_module, "tcp_port",
515 "The TCP port on which ENTTEC packets will be sent",
516 10,&global_tcp_port_enttec);
518 prefs_register_enum_preference(enttec_module, "dmx_disp_chan_val_type",
519 "DMX Display channel value type",
520 "The way DMX values are displayed",
521 &global_disp_chan_val_type,
522 disp_chan_val_types, FALSE);
524 prefs_register_enum_preference(enttec_module, "dmx_disp_chan_nr_type",
525 "DMX Display channel nr. type",
526 "The way DMX channel numbers are displayed",
527 &global_disp_chan_nr_type,
528 disp_chan_nr_types, FALSE);
530 prefs_register_enum_preference(enttec_module, "dmx_disp_col_count",
531 "DMX Display Column Count",
532 "The number of columns for the DMX display",
533 &global_disp_col_count,
537 /* The registration hand-off routing */
539 proto_reg_handoff_enttec(void) {
540 static gboolean enttec_initialized = FALSE;
541 static dissector_handle_t enttec_handle;
542 static guint udp_port_enttec;
543 static guint tcp_port_enttec;
545 if(!enttec_initialized) {
546 enttec_handle = create_dissector_handle(dissect_enttec,proto_enttec);
547 enttec_initialized = TRUE;
549 dissector_delete("udp.port",udp_port_enttec,enttec_handle);
550 dissector_delete("tcp.port",tcp_port_enttec,enttec_handle);
553 udp_port_enttec = global_udp_port_enttec;
554 tcp_port_enttec = global_tcp_port_enttec;
556 dissector_add("udp.port",global_udp_port_enttec,enttec_handle);
557 dissector_add("tcp.port",global_tcp_port_enttec,enttec_handle);