HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-srp.c
blob3f3b55afe55bbeec51d345f7857d12af938c0d1d
1 /* packet-srp.c
2 * Routines for H.324/SRP dissection
3 * 2004 Richard van der Hoff <richardv@mxtelecom.com>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
30 #include <epan/bitswap.h>
31 #include <epan/circuit.h>
32 #include <epan/stream.h>
33 #include <epan/crc16-tvb.h>
35 /* Wireshark ID of the protocols */
36 static int proto_srp = -1;
37 static int proto_ccsrl = -1;
39 /* The following hf_* variables are used to hold the Wireshark IDs of
40 * our header fields; they are filled out when we call
41 * proto_register_field_array() in proto_register_srp()
43 static int hf_srp_header = -1;
44 static int hf_srp_seqno = -1;
45 static int hf_srp_crc = -1;
46 static int hf_srp_crc_bad = -1;
47 static int hf_ccsrl_ls = -1;
49 /* These are the ids of the subtrees that we may be creating */
50 static gint ett_srp = -1;
51 static gint ett_ccsrl = -1;
53 static dissector_handle_t ccsrl_handle;
54 static dissector_handle_t h245dg_handle;
56 /*****************************************************************************/
57 #define SRP_SRP_COMMAND 249
58 #define SRP_SRP_RESPONSE 251
59 #define SRP_NSRP_RESPONSE 247
61 static const value_string srp_frame_types[] = {
62 {SRP_SRP_COMMAND, "SRP command"},
63 {SRP_SRP_RESPONSE, "SRP response"},
64 {SRP_NSRP_RESPONSE, "NSRP response"},
65 {0,NULL}
68 static const value_string ccsrl_ls_vals[] = {
69 {0xFF, "Yes"},
70 {0x00, "No"},
71 {0,NULL}
74 /*****************************************************************************/
76 static void dissect_ccsrl(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
78 proto_item *ccsrl_item;
79 proto_tree *ccsrl_tree=NULL;
80 guint8 lastseg = tvb_get_guint8(tvb,0);
81 tvbuff_t *next_tvb;
83 /* add the 'ccsrl' tree to the main tree */
84 if (tree) {
85 ccsrl_item = proto_tree_add_item (tree, proto_ccsrl, tvb, 0, -1, ENC_NA);
86 ccsrl_tree = proto_item_add_subtree (ccsrl_item, ett_ccsrl);
87 proto_tree_add_uint(ccsrl_tree,hf_ccsrl_ls,tvb,0,1,lastseg);
90 /* XXX add support for reassembly of fragments */
92 /* XXX currently, we always dissect as H245. It's not necessarily
93 that though.
95 next_tvb = tvb_new_subset_remaining(tvb, 1);
96 call_dissector( h245dg_handle, next_tvb, pinfo, ccsrl_tree );
99 static void dissect_srp_command(tvbuff_t * tvb, packet_info * pinfo, proto_tree * srp_tree)
101 tvbuff_t *next_tvb;
102 guint payload_len;
104 if( srp_tree )
105 proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,ENC_BIG_ENDIAN);
107 payload_len = tvb_reported_length_remaining(tvb,4);
108 next_tvb = tvb_new_subset(tvb, 2, payload_len, payload_len );
110 /* XXX currently, we always dissect as CCSRL. It's only that in
111 * H324/Annex C though.
113 call_dissector(ccsrl_handle, next_tvb, pinfo, srp_tree );
116 static void dissect_srp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
118 proto_item *srp_item = NULL;
119 proto_tree *srp_tree = NULL;
120 proto_item *hidden_item;
122 guint8 header = tvb_get_guint8(tvb,0);
124 /* add the 'srp' tree to the main tree */
125 if (tree) {
126 srp_item = proto_tree_add_item (tree, proto_srp, tvb, 0, -1, ENC_NA);
127 srp_tree = proto_item_add_subtree (srp_item, ett_srp);
128 proto_tree_add_uint(srp_tree,hf_srp_header,tvb,0,1,header);
131 switch( header ) {
132 case SRP_SRP_COMMAND:
133 dissect_srp_command(tvb,pinfo,srp_tree);
134 break;
136 case SRP_SRP_RESPONSE:
137 break;
139 case SRP_NSRP_RESPONSE:
140 if( srp_tree )
141 proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,ENC_BIG_ENDIAN);
142 break;
144 default:
145 break;
148 if( srp_tree ) {
149 guint16 crc, calc_crc;
150 guint crc_offset = tvb_reported_length(tvb)-2;
151 crc = tvb_get_letohs(tvb,-2);
153 /* crc includes the header */
154 calc_crc = crc16_ccitt_tvb(tvb,crc_offset);
156 if( crc == calc_crc ) {
157 proto_tree_add_uint_format_value(srp_tree, hf_srp_crc, tvb,
158 crc_offset, 2, crc,
159 "0x%04x (correct)", crc);
160 } else {
161 hidden_item = proto_tree_add_boolean(srp_tree, hf_srp_crc_bad, tvb,
162 crc_offset, 2, TRUE);
163 PROTO_ITEM_SET_HIDDEN(hidden_item);
164 proto_tree_add_uint_format_value(srp_tree, hf_srp_crc, tvb,
165 crc_offset, 2, crc,
166 "0x%04x (incorrect, should be 0x%04x)",
167 crc,
168 calc_crc);
174 void proto_register_ccsrl (void)
176 static hf_register_info hf[] = {
177 { &hf_ccsrl_ls,
178 { "Last Segment","ccsrl.ls",FT_UINT8, BASE_HEX, ccsrl_ls_vals, 0x0,
179 "Last segment indicator", HFILL}},
182 static gint *ett[] = {
183 &ett_ccsrl,
186 proto_ccsrl = proto_register_protocol ("H.324/CCSRL", "CCSRL", "ccsrl");
187 proto_register_field_array (proto_ccsrl, hf, array_length (hf));
188 proto_register_subtree_array (ett, array_length (ett));
189 register_dissector("ccsrl", dissect_ccsrl, proto_ccsrl);
192 void proto_register_srp (void)
194 static hf_register_info hf[] = {
195 {&hf_srp_header,
196 { "Header", "srp.header", FT_UINT8, BASE_DEC, srp_frame_types, 0x0,
197 "SRP header octet", HFILL }},
198 {&hf_srp_seqno,
199 { "Sequence Number", "srp.seqno", FT_UINT8, BASE_DEC, NULL, 0x0,
200 NULL, HFILL }},
201 {&hf_srp_crc,
202 { "CRC", "srp.crc", FT_UINT16, BASE_HEX, NULL, 0x0,
203 NULL, HFILL }},
204 { &hf_srp_crc_bad,
205 { "Bad CRC","srp.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
206 NULL, HFILL }},
209 static gint *ett[] = {
210 &ett_srp,
213 proto_srp = proto_register_protocol ("H.324/SRP", "SRP", "srp");
214 proto_register_field_array (proto_srp, hf, array_length (hf));
215 proto_register_subtree_array (ett, array_length (ett));
216 register_dissector("srp", dissect_srp, proto_srp);
218 /* register our init routine to be called at the start of a capture,
219 to clear out our hash tables etc */
220 /* register_init_routine(&srp_init_protocol); */
225 void proto_reg_handoff_srp(void) {
226 ccsrl_handle = find_dissector("ccsrl");
227 h245dg_handle = find_dissector("h245dg");