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 /* Wireshark ID of the protocols */
40 static int proto_srp = -1;
41 static int proto_ccsrl = -1;
43 /* The following hf_* variables are used to hold the Wireshark IDs of
44 * our header fields; they are filled out when we call
45 * proto_register_field_array() in proto_register_srp()
47 static int hf_srp_header = -1;
48 static int hf_srp_seqno = -1;
49 static int hf_srp_crc = -1;
50 static int hf_srp_crc_bad = -1;
51 static int hf_ccsrl_ls = -1;
53 /* These are the ids of the subtrees that we may be creating */
54 static gint ett_srp = -1;
55 static gint ett_ccsrl = -1;
57 static dissector_handle_t ccsrl_handle;
58 static dissector_handle_t h245dg_handle;
60 /*****************************************************************************/
61 #define SRP_SRP_COMMAND 249
62 #define SRP_SRP_RESPONSE 251
63 #define SRP_NSRP_RESPONSE 247
65 static const value_string srp_frame_types[] = {
66 {SRP_SRP_COMMAND, "SRP command"},
67 {SRP_SRP_RESPONSE, "SRP response"},
68 {SRP_NSRP_RESPONSE, "NSRP response"},
72 static const value_string ccsrl_ls_vals[] = {
78 /*****************************************************************************/
80 static void dissect_ccsrl(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
82 proto_item *ccsrl_item;
83 proto_tree *ccsrl_tree=NULL;
84 guint8 lastseg = tvb_get_guint8(tvb,0);
87 /* add the 'ccsrl' tree to the main tree */
89 ccsrl_item = proto_tree_add_item (tree, proto_ccsrl, tvb, 0, -1, FALSE);
90 ccsrl_tree = proto_item_add_subtree (ccsrl_item, ett_ccsrl);
91 proto_tree_add_uint(ccsrl_tree,hf_ccsrl_ls,tvb,0,1,lastseg);
94 /* XXX add support for reassembly of fragments */
96 /* XXX currently, we always dissect as H245. It's not necessarily
99 next_tvb = tvb_new_subset(tvb, 1, -1, -1 );
100 call_dissector( h245dg_handle, next_tvb, pinfo, ccsrl_tree );
103 static void dissect_srp_command(tvbuff_t * tvb, packet_info * pinfo, proto_tree * srp_tree)
109 proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,FALSE);
111 payload_len = tvb_reported_length_remaining(tvb,4);
112 next_tvb = tvb_new_subset(tvb, 2, payload_len, payload_len );
114 /* XXX currently, we always dissect as CCSRL. It's only that in
115 * H324/Annex C though.
117 call_dissector(ccsrl_handle, next_tvb, pinfo, srp_tree );
120 static void dissect_srp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
122 proto_item *srp_item = NULL;
123 proto_tree *srp_tree = NULL;
124 proto_item *hidden_item;
126 guint8 header = tvb_get_guint8(tvb,0);
128 /* add the 'srp' tree to the main tree */
130 srp_item = proto_tree_add_item (tree, proto_srp, tvb, 0, -1, FALSE);
131 srp_tree = proto_item_add_subtree (srp_item, ett_srp);
132 proto_tree_add_uint(srp_tree,hf_srp_header,tvb,0,1,header);
136 case SRP_SRP_COMMAND:
137 dissect_srp_command(tvb,pinfo,srp_tree);
140 case SRP_SRP_RESPONSE:
143 case SRP_NSRP_RESPONSE:
145 proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,FALSE);
153 guint16 crc, calc_crc;
154 guint crc_offset = tvb_reported_length(tvb)-2;
155 crc = tvb_get_letohs(tvb,-2);
157 /* crc includes the header */
158 calc_crc = crc16_ccitt_tvb(tvb,crc_offset);
160 if( crc == calc_crc ) {
161 proto_tree_add_uint_format(srp_tree, hf_srp_crc, tvb,
163 "CRC: 0x%04x (correct)", crc);
165 hidden_item = proto_tree_add_boolean(srp_tree, hf_srp_crc_bad, tvb,
166 crc_offset, 2, TRUE);
167 PROTO_ITEM_SET_HIDDEN(hidden_item);
168 proto_tree_add_uint_format(srp_tree, hf_srp_crc, tvb,
170 "CRC: 0x%04x (incorrect, should be 0x%04x)",
178 void proto_register_ccsrl (void)
180 static hf_register_info hf[] = {
182 { "Last Segment","ccsrl.ls",FT_UINT8, BASE_HEX, ccsrl_ls_vals, 0x0,
183 "Last segment indicator", HFILL}},
186 static gint *ett[] = {
190 proto_ccsrl = proto_register_protocol ("H.324/CCSRL", "CCSRL", "ccsrl");
191 proto_register_field_array (proto_ccsrl, hf, array_length (hf));
192 proto_register_subtree_array (ett, array_length (ett));
193 register_dissector("ccsrl", dissect_ccsrl, proto_ccsrl);
196 void proto_register_srp (void)
198 static hf_register_info hf[] = {
200 { "Header", "srp.header", FT_UINT8, BASE_DEC, srp_frame_types, 0x0,
201 "SRP header octet", HFILL }},
203 { "Sequence Number", "srp.seqno", FT_UINT8, BASE_DEC, NULL, 0x0,
204 "Sequence Number", HFILL }},
206 { "CRC", "srp.crc", FT_UINT16, BASE_HEX, NULL, 0x0,
209 { "Bad CRC","srp.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
213 static gint *ett[] = {
217 proto_srp = proto_register_protocol ("H.324/SRP", "SRP", "srp");
218 proto_register_field_array (proto_srp, hf, array_length (hf));
219 proto_register_subtree_array (ett, array_length (ett));
220 register_dissector("srp", dissect_srp, proto_srp);
222 /* register our init routine to be called at the start of a capture,
223 to clear out our hash tables etc */
224 /* register_init_routine(&srp_init_protocol); */
229 void proto_reg_handoff_srp(void) {
230 ccsrl_handle = find_dissector("ccsrl");
231 h245dg_handle = find_dissector("h245dg");