2 * Routines for H.324/SRP dissection
3 * 2004 Richard van der Hoff <richardv@mxtelecom.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <epan/bitswap.h>
33 #include <epan/circuit.h>
34 #include <epan/packet.h>
35 #include <epan/stream.h>
36 #include <epan/reassemble.h>
37 #include <epan/crc16.h>
39 #include "packet-srp.h"
41 /* Ethereal ID of the protocols */
42 static int proto_srp = -1;
43 static int proto_ccsrl = -1;
45 /* The following hf_* variables are used to hold the ethereal IDs of
46 * our header fields; they are filled out when we call
47 * proto_register_field_array() in proto_register_srp()
49 static int hf_srp_header = -1;
50 static int hf_srp_seqno = -1;
51 static int hf_srp_crc = -1;
52 static int hf_srp_crc_bad = -1;
53 static int hf_ccsrl_ls = -1;
55 /* These are the ids of the subtrees that we may be creating */
56 static gint ett_srp = -1;
57 static gint ett_ccsrl = -1;
59 static dissector_handle_t data_handle=NULL;
60 static dissector_handle_t ccsrl_handle=NULL;
61 static dissector_handle_t h245dg_handle=NULL;
63 /*****************************************************************************/
64 #define SRP_SRP_COMMAND 249
65 #define SRP_SRP_RESPONSE 251
66 #define SRP_NSRP_RESPONSE 247
68 static const value_string srp_frame_types[] = {
69 {SRP_SRP_COMMAND, "SRP command"},
70 {SRP_SRP_RESPONSE, "SRP response"},
71 {SRP_NSRP_RESPONSE, "NSRP response"},
75 static const value_string ccsrl_ls_vals[] = {
81 /*****************************************************************************/
83 static void dissect_ccsrl(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
85 proto_item *ccsrl_item;
86 proto_tree *ccsrl_tree=NULL;
87 guint8 lastseg = tvb_get_guint8(tvb,0);
90 /* add the 'ccsrl' tree to the main tree */
92 ccsrl_item = proto_tree_add_item (tree, proto_ccsrl, tvb, 0, -1, FALSE);
93 ccsrl_tree = proto_item_add_subtree (ccsrl_item, ett_ccsrl);
94 proto_tree_add_uint(ccsrl_tree,hf_ccsrl_ls,tvb,0,1,lastseg);
97 /* XXX add support for reassembly of fragments */
99 /* XXX currently, we always dissect as H245. It's not necessarily
102 next_tvb = tvb_new_subset(tvb, 1, -1, -1 );
103 call_dissector( h245dg_handle, next_tvb, pinfo, ccsrl_tree );
106 static void dissect_srp_command(tvbuff_t * tvb, packet_info * pinfo, proto_tree * srp_tree)
112 proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,FALSE);
114 payload_len = tvb_reported_length_remaining(tvb,4);
115 next_tvb = tvb_new_subset(tvb, 2, payload_len, payload_len );
117 /* XXX currently, we always dissect as CCSRL. It's only that in
118 * H324/Annex C though.
120 call_dissector(ccsrl_handle, next_tvb, pinfo, srp_tree );
123 static void dissect_srp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
125 proto_item *srp_item = NULL;
126 proto_tree *srp_tree = NULL;
128 guint8 header = tvb_get_guint8(tvb,0);
130 /* add the 'srp' tree to the main tree */
132 srp_item = proto_tree_add_item (tree, proto_srp, tvb, 0, -1, FALSE);
133 srp_tree = proto_item_add_subtree (srp_item, ett_srp);
134 proto_tree_add_uint(srp_tree,hf_srp_header,tvb,0,1,header);
138 case SRP_SRP_COMMAND:
139 dissect_srp_command(tvb,pinfo,srp_tree);
142 case SRP_SRP_RESPONSE:
145 case SRP_NSRP_RESPONSE:
147 proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,FALSE);
155 guint16 crc, calc_crc;
156 guint crc_offset = tvb_reported_length(tvb)-2;
157 crc = tvb_get_letohs(tvb,-2);
159 /* crc includes the header */
160 calc_crc = crc16_ccitt_tvb(tvb,crc_offset);
162 if( crc == calc_crc ) {
163 proto_tree_add_uint_format(srp_tree, hf_srp_crc, tvb,
165 "CRC: 0x%04x (correct)", crc);
167 proto_tree_add_boolean_hidden(srp_tree, hf_srp_crc_bad, tvb,
168 crc_offset, 2, TRUE);
169 proto_tree_add_uint_format(srp_tree, hf_srp_crc, tvb,
171 "CRC: 0x%04x (incorrect, should be 0x%04x)",
179 void proto_register_ccsrl (void)
181 static hf_register_info hf[] = {
183 { "Last Segment","ccsrl.ls",FT_UINT8, BASE_HEX, ccsrl_ls_vals, 0x0,
184 "Last segment indicator", HFILL}},
187 static gint *ett[] = {
191 if (proto_ccsrl == -1) { /* execute protocol initialization only once */
193 proto_register_protocol ("H.324/CCSRL", "CCSRL", "ccsrl");
195 proto_register_field_array (proto_ccsrl, hf, array_length (hf));
196 proto_register_subtree_array (ett, array_length (ett));
197 register_dissector("ccsrl", dissect_ccsrl, proto_ccsrl);
201 void proto_register_srp (void)
203 static hf_register_info hf[] = {
205 { "Header", "srp.header", FT_UINT8, BASE_DEC, srp_frame_types, 0x0,
206 "SRP header octet", HFILL }},
208 { "Sequence Number", "srp.seqno", FT_UINT8, BASE_DEC, NULL, 0x0,
209 "Sequence Number", HFILL }},
211 { "CRC", "srp.crc", FT_UINT16, BASE_HEX, NULL, 0x0,
214 { "Bad CRC","srp.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
218 static gint *ett[] = {
222 if (proto_srp == -1) { /* execute protocol initialization only once */
224 proto_register_protocol ("H.324/SRP", "SRP", "srp");
226 proto_register_field_array (proto_srp, hf, array_length (hf));
227 proto_register_subtree_array (ett, array_length (ett));
228 register_dissector("srp", dissect_srp, proto_srp);
230 /* register our init routine to be called at the start of a capture,
231 to clear out our hash tables etc */
232 /* register_init_routine(&srp_init_protocol); */
238 void proto_reg_handoff_srp(void) {
239 data_handle = find_dissector("data");
240 ccsrl_handle = find_dissector("ccsrl");
241 h245dg_handle = find_dissector("h245dg");