2 * Routines for RDM packet disassembly
6 * Copyright (c) 2003 by Erwin Rol <erwin@erwinrol.com>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
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.
33 #include "moduleinfo.h"
41 #include <epan/packet.h>
42 #include <epan/addr_resolv.h>
43 #include <epan/etypes.h>
44 #include <epan/strutil.h>
46 /* Define version if we are not building ethereal statically */
49 G_MODULE_EXPORT const gchar version[] = VERSION;
53 * See http://www.esta.org/tsp/E1-20inst.htm
57 void proto_reg_handoff_rdm(void);
59 /* Define the rdm proto */
60 static int proto_rdm = -1;
63 static int hf_rdm_sub_start_code = -1;
64 static int hf_rdm_slot_count = -1;
65 static int hf_rdm_dest_uid = -1;
66 static int hf_rdm_src_uid = -1;
67 static int hf_rdm_seq_nr = -1;
68 static int hf_rdm_res_type = -1;
69 static int hf_rdm_msg_count = -1;
70 static int hf_rdm_sub_device = -1;
71 static int hf_rdm_mdb = -1;
72 static int hf_rdm_checksum = -1;
74 /* Define the tree for rdm */
75 static int ett_rdm = -1;
78 dissect_rdm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
79 gint offset = 0, start_offset,i;
80 guint16 checksum,calc_checksum;
82 proto_tree *ti=NULL,*rdm_tree=NULL;
85 /* Set the protocol column */
86 if(check_col(pinfo->cinfo,COL_PROTOCOL)){
87 col_set_str(pinfo->cinfo,COL_PROTOCOL,"RDM");
90 /* Clear out stuff in the info column */
91 if(check_col(pinfo->cinfo,COL_INFO)){
92 col_clear(pinfo->cinfo,COL_INFO);
96 ti = proto_tree_add_item(tree, proto_rdm, tvb, offset, -1, FALSE);
97 rdm_tree = proto_item_add_subtree(ti, ett_rdm);
100 if (check_col(pinfo->cinfo, COL_INFO)) {
101 col_append_fstr(pinfo->cinfo, COL_INFO, "%s",
107 start_offset = offset;
109 proto_tree_add_item(rdm_tree, hf_rdm_sub_start_code, tvb,
113 mdb_size = tvb_get_guint8(tvb, offset) - 19;
116 proto_tree_add_text(rdm_tree, tvb, offset, 1, "Invalid MDB size: %d",
121 proto_tree_add_item(rdm_tree, hf_rdm_slot_count, tvb,
125 proto_tree_add_item(rdm_tree, hf_rdm_dest_uid, tvb,
129 proto_tree_add_item(rdm_tree, hf_rdm_src_uid, tvb,
133 proto_tree_add_item(rdm_tree, hf_rdm_seq_nr, tvb,
137 proto_tree_add_item(rdm_tree, hf_rdm_res_type, tvb,
141 proto_tree_add_item(rdm_tree, hf_rdm_msg_count, tvb,
145 proto_tree_add_item(rdm_tree, hf_rdm_sub_device, tvb,
149 tvb_ensure_bytes_exist(tvb, offset, mdb_size);
150 proto_tree_add_item(rdm_tree, hf_rdm_mdb, tvb,
151 offset, mdb_size, FALSE);
154 calc_checksum = 0x00f0;
155 for( i = start_offset; i < offset; i++)
157 calc_checksum += tvb_get_guint8( tvb, i );
160 checksum = tvb_get_ntohs( tvb, offset );
161 item = proto_tree_add_item(rdm_tree, hf_rdm_checksum, tvb,
164 if( calc_checksum != checksum )
165 proto_item_append_text( item, " ( INCORRECT should be 0x%04x )", calc_checksum );
167 proto_item_append_text( item, " ( CORRECT )" );
174 proto_register_rdm(void) {
175 static hf_register_info hf[] = {
176 { &hf_rdm_sub_start_code,
178 "rdm.sub_start_code",
179 FT_UINT8, BASE_HEX, NULL, 0x0,
180 "Sub Start Code", HFILL }},
182 { &hf_rdm_slot_count,
185 FT_UINT8, BASE_DEC, NULL, 0x0,
186 "Slot Count", HFILL }},
191 FT_BYTES, BASE_HEX, NULL, 0x0,
192 "Dest. UID", HFILL }},
197 FT_BYTES, BASE_HEX, NULL, 0x0,
198 "Source UID", HFILL }},
203 FT_UINT8, BASE_DEC, NULL, 0x0,
204 "Sequence Number", HFILL }},
209 FT_UINT8, BASE_HEX, NULL, 0x0,
210 "Response Type", HFILL }},
215 FT_UINT8, BASE_DEC, NULL, 0x0,
216 "Message Count", HFILL }},
218 { &hf_rdm_sub_device,
221 FT_UINT8, BASE_HEX, NULL, 0x0,
222 "Sub Device", HFILL }},
227 FT_BYTES, BASE_HEX, NULL, 0x0,
233 FT_UINT16, BASE_HEX, NULL, 0x0,
237 static gint *ett[] = {
241 proto_rdm = proto_register_protocol("RDM","RDM","rdm");
243 proto_register_field_array(proto_rdm,hf,array_length(hf));
244 proto_register_subtree_array(ett,array_length(ett));
246 register_dissector("rdm", dissect_rdm, proto_rdm);
249 /* The registration hand-off routing */
252 proto_reg_handoff_rdm(void) {
253 static int rdm_initialized = FALSE;
254 static dissector_handle_t rdm_handle;
256 if(!rdm_initialized) {
257 rdm_handle = create_dissector_handle(dissect_rdm,proto_rdm);
258 rdm_initialized = TRUE;
260 dissector_delete("udp.port",0,rdm_handle);
263 dissector_add("udp.port",0,rdm_handle);
266 /* Start the functions we need for the plugin stuff */
268 #ifndef ENABLE_STATIC
271 plugin_register(void)
273 /* register the new protocol, protocol fields, and subtrees */
274 if (proto_rdm == -1) { /* execute protocol initialization only once */
275 proto_register_rdm();
280 plugin_reg_handoff(void){
281 proto_reg_handoff_rdm();
286 /* End the functions we need for plugin stuff */