MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / plugins / docsis / packet-dccrsp.c
blob1e88a6f76007fbdb0153c05bd6b203590f4f71e8
1 /* packet-dccrsp.c
2 * Routines for DCC Response Message dissection
3 * Copyright 2004, Darryl Hymel <darryl.hymel[AT]arrisi.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 <epan/packet.h>
29 #include <epan/exceptions.h>
31 #define DCCRSP_CM_JUMP_TIME 1
32 #define DCCRSP_KEY_SEQ_NUM 31
33 #define DCCRSP_HMAC_DIGEST 27
35 /* Define DCC-RSP CM Jump Time subtypes
36 * These are subtype of DCCRSP_CM_JUMP_TIME (1)
38 #define DCCRSP_CM_JUMP_TIME_LENGTH 1
39 #define DCCRSP_CM_JUMP_TIME_START 2
41 /* Initialize the protocol and registered fields */
42 static int proto_docsis_dccrsp = -1;
44 static int hf_docsis_dccrsp_tran_id = -1;
45 static int hf_docsis_dccrsp_conf_code = -1;
46 static int hf_docsis_dccrsp_cm_jump_time_length = -1;
47 static int hf_docsis_dccrsp_cm_jump_time_start = -1;
48 static int hf_docsis_dccrsp_key_seq_num = -1;
49 static int hf_docsis_dccrsp_hmac_digest = -1;
51 /* Initialize the subtree pointers */
52 static gint ett_docsis_dccrsp = -1;
53 static gint ett_docsis_dccrsp_cm_jump_time = -1;
56 /* Code to actually dissect the packets */
57 static void
58 dissect_dccrsp_cm_jump_time (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
60 guint8 type, length;
61 proto_item *dcc_item;
62 proto_tree *dcc_tree;
63 int pos;
65 pos = start;
66 dcc_item = proto_tree_add_text ( tree, tvb, start, len, "2 DCC-RSP CM Time Jump Encodings (Length = %u)", len);
67 dcc_tree = proto_item_add_subtree ( dcc_item , ett_docsis_dccrsp_cm_jump_time);
69 while ( pos < ( start + len) )
71 type = tvb_get_guint8 (tvb, pos++);
72 length = tvb_get_guint8 (tvb, pos++);
74 switch (type)
76 case DCCRSP_CM_JUMP_TIME_LENGTH:
77 if (length == 4)
79 proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_cm_jump_time_length, tvb,
80 pos, length, ENC_BIG_ENDIAN);
82 else
84 THROW (ReportedBoundsError);
86 break;
87 case DCCRSP_CM_JUMP_TIME_START:
88 if (length == 8)
90 proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_cm_jump_time_start, tvb,
91 pos, length, ENC_BIG_ENDIAN);
93 else
95 THROW (ReportedBoundsError);
97 break;
99 pos = pos + length;
102 static void
103 dissect_dccrsp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
105 guint16 pos;
106 guint8 type, length;
107 proto_tree *dcc_tree;
108 proto_item *dcc_item;
109 guint16 len;
111 len = tvb_length_remaining (tvb, 0);
113 col_set_str(pinfo->cinfo, COL_INFO, "DCC-RSP Message: ");
115 if (tree)
117 dcc_item =
118 proto_tree_add_protocol_format (tree, proto_docsis_dccrsp, tvb, 0,
119 tvb_length_remaining (tvb, 0),
120 "DCC-RSP Message");
121 dcc_tree = proto_item_add_subtree (dcc_item, ett_docsis_dccrsp);
122 proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_tran_id, tvb, 0, 2, ENC_BIG_ENDIAN);
123 proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_conf_code, tvb, 2, 1, ENC_BIG_ENDIAN);
125 pos = 3;
126 while (pos < len)
128 type = tvb_get_guint8 (tvb, pos++);
129 length = tvb_get_guint8 (tvb, pos++);
130 switch (type)
132 case DCCRSP_CM_JUMP_TIME:
133 dissect_dccrsp_cm_jump_time (tvb , dcc_tree , pos , length );
134 break;
135 case DCCRSP_KEY_SEQ_NUM:
136 if (length == 1)
138 proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_key_seq_num, tvb,
139 pos, length, ENC_BIG_ENDIAN);
141 else
143 THROW (ReportedBoundsError);
145 break;
146 case DCCRSP_HMAC_DIGEST:
147 if (length == 20)
149 proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_hmac_digest, tvb,
150 pos, length, ENC_NA);
152 else
154 THROW (ReportedBoundsError);
156 break;
157 } /* switch(type) */
158 pos = pos + length;
159 } /* while (pos < len) */
160 } /* if (tree) */
163 /* Register the protocol with Wireshark */
165 /* this format is require because a script is used to build the C function
166 that calls all the protocol registration.
170 void
171 proto_register_docsis_dccrsp (void)
173 /* Setup list of header fields See Section 1.6.1 for details*/
174 static hf_register_info hf[] = {
175 {&hf_docsis_dccrsp_tran_id ,
177 "Transaction ID",
178 "docsis_dccrsp.tran_id",
179 FT_UINT16, BASE_DEC, NULL, 0x0,
180 NULL,
181 HFILL
184 {&hf_docsis_dccrsp_conf_code ,
186 "Confirmation Code",
187 "docsis_dccrsp.conf_code",
188 FT_UINT8, BASE_DEC, NULL, 0x0,
189 NULL,
190 HFILL
193 {&hf_docsis_dccrsp_cm_jump_time_length ,
195 "Jump Time Length",
196 "docsis_dccrsp.cm_jump_time_length",
197 FT_UINT32, BASE_DEC, NULL, 0x0,
198 NULL,
199 HFILL
202 {&hf_docsis_dccrsp_cm_jump_time_start ,
204 "Jump Time Start",
205 "docsis_dccrsp.cm_jump_time_start",
206 FT_UINT64, BASE_DEC, NULL, 0x0,
207 NULL,
208 HFILL
211 {&hf_docsis_dccrsp_key_seq_num ,
213 "Auth Key Sequence Number",
214 "docsis_dccrsp.key_seq_num",
215 FT_UINT8, BASE_DEC, NULL, 0x0,
216 NULL,
217 HFILL
220 {&hf_docsis_dccrsp_hmac_digest ,
222 "HMAC-DigestNumber",
223 "docsis_dccrsp.hmac_digest",
224 FT_BYTES, BASE_NONE, NULL, 0x0,
225 NULL,
226 HFILL
232 /* Setup protocol subtree array */
233 static gint *ett[] = {
234 &ett_docsis_dccrsp,
235 &ett_docsis_dccrsp_cm_jump_time,
238 /* Register the protocol name and description */
239 proto_docsis_dccrsp =
240 proto_register_protocol ("DOCSIS Downstream Channel Change Response",
241 "DOCSIS DCC-RSP", "docsis_dccrsp");
243 /* Required function calls to register the header fields and subtrees used */
244 proto_register_field_array (proto_docsis_dccrsp, hf, array_length (hf));
245 proto_register_subtree_array (ett, array_length (ett));
247 register_dissector ("docsis_dccrsp", dissect_dccrsp, proto_docsis_dccrsp);
251 /* If this dissector uses sub-dissector registration add a registration routine.
252 This format is required because a script is used to find these routines and
253 create the code that calls these routines.
255 void
256 proto_reg_handoff_docsis_dccrsp (void)
258 dissector_handle_t docsis_dccrsp_handle;
260 docsis_dccrsp_handle = find_dissector ("docsis_dccrsp");
261 dissector_add_uint ("docsis_mgmt", 0x18, docsis_dccrsp_handle);