We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
[metze/wireshark/wip.git] / plugins / docsis / packet-dccrsp.c
1 /* packet-dccrsp.c
2  * Routines for DCC Response Message  dissection
3  * Copyright 2004, Darryl Hymel <darryl.hymel[AT]arrisi.com>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  */
25
26 #include "config.h"
27
28 #include <epan/packet.h>
29
30 #define DCCRSP_CM_JUMP_TIME 1
31 #define DCCRSP_KEY_SEQ_NUM 31
32 #define DCCRSP_HMAC_DIGEST 27
33
34 /* Define DCC-RSP CM Jump Time subtypes
35  * These are subtype of DCCRSP_CM_JUMP_TIME (1)
36  */
37 #define DCCRSP_CM_JUMP_TIME_LENGTH 1
38 #define DCCRSP_CM_JUMP_TIME_START 2
39
40 /* Initialize the protocol and registered fields */
41 static int proto_docsis_dccrsp = -1;
42
43 static int hf_docsis_dccrsp_tran_id = -1;
44 static int hf_docsis_dccrsp_conf_code = -1;
45 static int hf_docsis_dccrsp_cm_jump_time_length = -1;
46 static int hf_docsis_dccrsp_cm_jump_time_start = -1;
47 static int hf_docsis_dccrsp_key_seq_num = -1;
48 static int hf_docsis_dccrsp_hmac_digest = -1;
49
50 /* Initialize the subtree pointers */
51 static gint ett_docsis_dccrsp = -1;
52 static gint ett_docsis_dccrsp_cm_jump_time = -1;
53
54
55 /* Code to actually dissect the packets */
56 static void
57 dissect_dccrsp_cm_jump_time (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
58 {
59   guint8 type, length;
60   proto_item *dcc_item;
61   proto_tree *dcc_tree;
62   int pos;
63    
64   pos = start;
65   dcc_item = proto_tree_add_text ( tree, tvb, start, len, "2 DCC-RSP CM Time Jump Encodings (Length = %u)", len);
66   dcc_tree = proto_item_add_subtree ( dcc_item , ett_docsis_dccrsp_cm_jump_time);
67   
68   while ( pos < ( start + len) ) 
69     {
70         type = tvb_get_guint8 (tvb, pos++);
71         length = tvb_get_guint8 (tvb, pos++);
72         
73         switch (type)
74           {
75             case DCCRSP_CM_JUMP_TIME_LENGTH:
76               if (length == 4)
77                 {
78                   proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_cm_jump_time_length, tvb,
79                                        pos, length, ENC_BIG_ENDIAN);
80                 }
81               else
82                 {
83                   THROW (ReportedBoundsError);
84                 }
85               break;
86             case DCCRSP_CM_JUMP_TIME_START:
87               if (length == 8)
88                 {
89                   proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_cm_jump_time_start, tvb,
90                                    pos, length, ENC_BIG_ENDIAN);
91                 }
92               else 
93                 {
94                   THROW (ReportedBoundsError);
95                 }
96               break;
97             }
98           pos = pos + length;
99       }
100 }
101 static void
102 dissect_dccrsp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
103 {
104   guint16 pos;
105   guint8 type, length;
106   proto_tree *dcc_tree;
107   proto_item *dcc_item;
108   guint16 len;
109
110   len = tvb_length_remaining (tvb, 0);
111
112   col_set_str(pinfo->cinfo, COL_INFO, "DCC-RSP Message: ");
113
114   if (tree)
115     {
116       dcc_item =
117         proto_tree_add_protocol_format (tree, proto_docsis_dccrsp, tvb, 0,
118                                         tvb_length_remaining (tvb, 0),
119                                         "DCC-RSP Message");
120       dcc_tree = proto_item_add_subtree (dcc_item, ett_docsis_dccrsp);
121       proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_tran_id, tvb, 0, 2, ENC_BIG_ENDIAN);
122       proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_conf_code, tvb, 2, 1, ENC_BIG_ENDIAN);
123
124       pos = 3;
125       while (pos < len)
126         {
127           type = tvb_get_guint8 (tvb, pos++);
128           length = tvb_get_guint8 (tvb, pos++);
129           switch (type)
130             {
131             case DCCRSP_CM_JUMP_TIME:
132               dissect_dccrsp_cm_jump_time (tvb , dcc_tree , pos , length );
133               break;
134             case DCCRSP_KEY_SEQ_NUM:
135               if (length == 1)
136                 {
137                   proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_key_seq_num, tvb,
138                                        pos, length, ENC_BIG_ENDIAN);
139                 }
140               else
141                 {
142                   THROW (ReportedBoundsError);
143                 }
144               break;
145             case DCCRSP_HMAC_DIGEST:
146               if (length == 20)
147                 {
148                   proto_tree_add_item (dcc_tree, hf_docsis_dccrsp_hmac_digest, tvb,
149                                        pos, length, ENC_NA);
150                 }
151               else
152                 {
153                   THROW (ReportedBoundsError);
154                 }
155               break;
156             }                   /* switch(type) */
157           pos = pos + length;
158         }                       /* while (pos < len) */
159     }                           /* if (tree) */
160
161 }
162 /* Register the protocol with Wireshark */
163
164 /* this format is require because a script is used to build the C function
165    that calls all the protocol registration.
166 */
167
168
169 void
170 proto_register_docsis_dccrsp (void)
171 {
172 /* Setup list of header fields  See Section 1.6.1 for details*/
173   static hf_register_info hf[] = {
174     {&hf_docsis_dccrsp_tran_id ,
175       {
176       "Transaction ID", 
177       "docsis_dccrsp.tran_id",
178       FT_UINT16, BASE_DEC, NULL, 0x0,
179       NULL, 
180       HFILL
181       }
182     },
183     {&hf_docsis_dccrsp_conf_code ,
184       {
185       "Confirmation Code", 
186       "docsis_dccrsp.conf_code",
187       FT_UINT8, BASE_DEC, NULL, 0x0,
188       NULL, 
189       HFILL
190       }
191     },
192     {&hf_docsis_dccrsp_cm_jump_time_length ,
193       {
194       "Jump Time Length", 
195       "docsis_dccrsp.cm_jump_time_length",
196       FT_UINT32, BASE_DEC, NULL, 0x0,
197       NULL, 
198       HFILL
199       }
200     },
201     {&hf_docsis_dccrsp_cm_jump_time_start ,
202       {
203       "Jump Time Start", 
204       "docsis_dccrsp.cm_jump_time_start",
205       FT_UINT64, BASE_DEC, NULL, 0x0,
206       NULL, 
207       HFILL
208       }
209     },
210     {&hf_docsis_dccrsp_key_seq_num ,
211       {
212       "Auth Key Sequence Number",
213       "docsis_dccrsp.key_seq_num",
214       FT_UINT8, BASE_DEC, NULL, 0x0,
215       NULL,
216       HFILL
217       }
218     },
219     {&hf_docsis_dccrsp_hmac_digest ,
220       {
221       "HMAC-DigestNumber",
222       "docsis_dccrsp.hmac_digest",
223       FT_BYTES, BASE_NONE, NULL, 0x0,
224       NULL,
225       HFILL
226       }
227     },
228
229   };
230
231 /* Setup protocol subtree array */
232   static gint *ett[] = {
233     &ett_docsis_dccrsp,
234     &ett_docsis_dccrsp_cm_jump_time,
235   };
236
237 /* Register the protocol name and description */
238   proto_docsis_dccrsp =
239     proto_register_protocol ("DOCSIS Downstream Channel Change Response",
240                              "DOCSIS DCC-RSP", "docsis_dccrsp");
241
242 /* Required function calls to register the header fields and subtrees used */
243   proto_register_field_array (proto_docsis_dccrsp, hf, array_length (hf));
244   proto_register_subtree_array (ett, array_length (ett));
245
246   register_dissector ("docsis_dccrsp", dissect_dccrsp, proto_docsis_dccrsp);
247 }
248
249
250 /* If this dissector uses sub-dissector registration add a registration routine.
251    This format is required because a script is used to find these routines and
252    create the code that calls these routines.
253 */
254 void
255 proto_reg_handoff_docsis_dccrsp (void)
256 {
257   dissector_handle_t docsis_dccrsp_handle;
258
259   docsis_dccrsp_handle = find_dissector ("docsis_dccrsp");
260   dissector_add_uint ("docsis_mgmt", 0x18, docsis_dccrsp_handle);
261
262 }