Remove all $Id$ from top of file
[metze/wireshark/wip.git] / epan / dissectors / packet-dmx-text.c
1 /* packet-dmx-text.c
2  * DMX Text packet disassembly.
3  *
4  * This dissector is written by
5  *
6  *  Erwin Rol <erwin@erwinrol.com>
7  *  Copyright 2011 Erwin Rol
8  *
9  *  Wireshark - Network traffic analyzer
10  *  Gerald Combs <gerald@wireshark.org>
11  *  Copyright 1999 Gerald Combs
12  *
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.
17  *
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.
22  *
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.
27  */
28
29 /*
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
35  */
36
37 #include "config.h"
38
39 #include <epan/packet.h>
40
41 void proto_register_dmx_text(void);
42
43 static int proto_dmx_text = -1;
44
45 static int hf_dmx_text_page_nr = -1;
46 static int hf_dmx_text_line_len = -1;
47 static int hf_dmx_text_string = -1;
48
49 static int ett_dmx_text = -1;
50
51 static void
52 dissect_dmx_text(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
53 {
54         col_set_str(pinfo->cinfo, COL_PROTOCOL, "DMX Text");
55         col_clear(pinfo->cinfo, COL_INFO);
56
57         if (tree != NULL) {
58                 guint offset = 0;
59                 guint size;
60
61                 proto_tree *ti = proto_tree_add_item(tree, proto_dmx_text, tvb,
62                                                         offset, -1, FALSE);
63                 proto_tree *dmx_text_tree = proto_item_add_subtree(ti, ett_dmx_text);
64
65                 proto_tree_add_item(dmx_text_tree, hf_dmx_text_page_nr, tvb,
66                                                         offset, 1, ENC_BIG_ENDIAN);
67                 offset++;
68
69                 proto_tree_add_item(dmx_text_tree, hf_dmx_text_line_len, tvb,
70                                                         offset, 1, ENC_BIG_ENDIAN);
71                 offset++;
72
73                 size = tvb_reported_length_remaining(tvb, offset);
74
75                 proto_tree_add_item(dmx_text_tree, hf_dmx_text_string, tvb,
76                                                         offset, size, ENC_BIG_ENDIAN);
77         }
78 }
79
80 void
81 proto_register_dmx_text(void)
82 {
83         static hf_register_info hf[] = {
84                 { &hf_dmx_text_page_nr,
85                         { "Page Number",
86                                 "dmx_text.page_nr",
87                                 FT_UINT8, BASE_DEC, NULL, 0x0,
88                                 NULL, HFILL }},
89                 { &hf_dmx_text_line_len,
90                         { "Line Length",
91                                 "dmx_text.line_length",
92                                 FT_UINT8, BASE_DEC, NULL, 0x0,
93                                 NULL, HFILL }},
94                 { &hf_dmx_text_string,
95                         { "Text String",
96                                 "dmx_text.string",
97                                 FT_STRING, BASE_NONE, NULL, 0x0,
98                                 NULL, HFILL }},
99         };
100
101         static gint *ett[] = {
102                 &ett_dmx_text
103         };
104
105         proto_dmx_text = proto_register_protocol("DMX Text Frame", "DMX Text Frame", "dmx-text");
106         proto_register_field_array(proto_dmx_text, hf, array_length(hf));
107         proto_register_subtree_array(ett, array_length(ett));
108         register_dissector("dmx-text", dissect_dmx_text, proto_dmx_text);
109 }
110