Revert "In get_unicode_or_ascii_string(), check if the length is odd/even, not the...
[wireshark-wip.git] / plugins / docsis / packet-dccreq.c
blobdb5e4d155561e2a8366f7b841676d8b7bf82960c
1 /* packet-dccreq.c
2 * Routines for DCC Request 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 DCCREQ_UP_CHAN_ID 1
32 #define DCCREQ_DS_PARAMS 2
33 #define DCCREQ_INIT_TECH 3
34 #define DCCREQ_UCD_SUB 4
35 #define DCCREQ_SAID_SUB 6
36 #define DCCREQ_SF_SUB 7
37 #define DCCREQ_CMTS_MAC_ADDR 8
38 #define DCCREQ_KEY_SEQ_NUM 31
39 #define DCCREQ_HMAC_DIGEST 27
41 /* Define Downstrean Parameters subtypes
42 * These are subtype of DCCREQ_DS_PARAMS (2)
45 #define DCCREQ_DS_FREQ 1
46 #define DCCREQ_DS_MOD_TYPE 2
47 #define DCCREQ_DS_SYM_RATE 3
48 #define DCCREQ_DS_INTLV_DEPTH 4
49 #define DCCREQ_DS_CHAN_ID 5
50 #define DCCREQ_DS_SYNC_SUB 6
52 /* Define Service Flow Substitution subtypes
53 * These are subtypes of DCCREQ_SF_SUB (7)
55 #define DCCREQ_SF_SFID 1
56 #define DCCREQ_SF_SID 2
57 #define DCCREQ_SF_UNSOL_GRANT_TREF 5
59 /* Initialize the protocol and registered fields */
60 static int proto_docsis_dccreq = -1;
62 static int hf_docsis_dccreq_tran_id = -1;
63 static int hf_docsis_dccreq_up_chan_id = -1;
64 static int hf_docsis_dccreq_ds_freq = -1;
65 static int hf_docsis_dccreq_ds_mod_type = -1;
66 static int hf_docsis_dccreq_ds_sym_rate = -1;
67 static int hf_docsis_dccreq_ds_intlv_depth_i = -1;
68 static int hf_docsis_dccreq_ds_intlv_depth_j = -1;
69 static int hf_docsis_dccreq_ds_chan_id = -1;
70 static int hf_docsis_dccreq_ds_sync_sub = -1;
71 static int hf_docsis_dccreq_init_tech = -1;
72 static int hf_docsis_dccreq_ucd_sub = -1;
73 static int hf_docsis_dccreq_said_sub_cur = -1;
74 static int hf_docsis_dccreq_said_sub_new = -1;
75 static int hf_docsis_dccreq_sf_sfid_cur = -1;
76 static int hf_docsis_dccreq_sf_sfid_new = -1;
77 static int hf_docsis_dccreq_sf_sid_cur = -1;
78 static int hf_docsis_dccreq_sf_sid_new = -1;
79 static int hf_docsis_dccreq_sf_unsol_grant_tref = -1;
80 static int hf_docsis_dccreq_cmts_mac_addr = -1;
81 static int hf_docsis_dccreq_key_seq_num = -1;
82 static int hf_docsis_dccreq_hmac_digest = -1;
84 /* Initialize the subtree pointers */
85 static gint ett_docsis_dccreq = -1;
86 static gint ett_docsis_dccreq_ds_params = -1;
87 static gint ett_docsis_dccreq_sf_sub = -1;
90 value_string ds_mod_type_vals[] = {
91 {0 , "64 QAM"},
92 {1 , "256 QAM"},
93 {0, NULL}
96 value_string ds_sym_rate_vals[] = {
97 {0 , "5.056941 Msym/sec"},
98 {1 , "5.360537 Msym/sec"},
99 {2 , "6.952 Msym/sec"},
100 {0, NULL}
102 value_string init_tech_vals[] = {
103 {0 , "Reinitialize MAC"},
104 {1 , "Broadcast Init RNG on new chanbefore normal op"},
105 {2 , "Unicast RNG on new chan before normal op"},
106 {3 , "Either Unicast or broadcast RNG on new chan before normal op"},
107 {4 , "Use new chan directly without re-init or RNG"},
108 {0, NULL}
110 /* Code to actually dissect the packets */
111 static void
112 dissect_dccreq_ds_params (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
114 guint8 type, length;
115 proto_item *dcc_item;
116 proto_tree *dcc_tree;
117 int pos;
119 pos = start;
120 dcc_item = proto_tree_add_text ( tree, tvb, start, len, "2 DCC-REQ Downstream Params Encodings (Length = %u)", len);
121 dcc_tree = proto_item_add_subtree ( dcc_item , ett_docsis_dccreq_ds_params);
123 while ( pos < ( start + len) )
125 type = tvb_get_guint8 (tvb, pos++);
126 length = tvb_get_guint8 (tvb, pos++);
128 switch (type)
130 case DCCREQ_DS_FREQ:
131 if (length == 4)
133 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ds_freq, tvb,
134 pos, length, ENC_BIG_ENDIAN);
136 else
138 THROW (ReportedBoundsError);
140 break;
141 case DCCREQ_DS_MOD_TYPE:
142 if (length == 1)
144 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ds_mod_type, tvb,
145 pos, length, ENC_BIG_ENDIAN);
147 else
149 THROW (ReportedBoundsError);
151 break;
152 case DCCREQ_DS_SYM_RATE:
153 if (length == 1)
155 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ds_sym_rate, tvb,
156 pos, length, ENC_BIG_ENDIAN);
158 else
160 THROW (ReportedBoundsError);
162 break;
163 case DCCREQ_DS_INTLV_DEPTH:
164 if (length == 2)
166 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ds_intlv_depth_i, tvb,
167 pos, 1, ENC_BIG_ENDIAN);
168 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ds_intlv_depth_j, tvb,
169 pos + 1, 1, ENC_BIG_ENDIAN);
171 else
173 THROW (ReportedBoundsError);
175 break;
176 case DCCREQ_DS_CHAN_ID:
177 if (length == 1)
179 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ds_chan_id, tvb,
180 pos, length, ENC_BIG_ENDIAN);
182 else
184 THROW (ReportedBoundsError);
186 break;
187 case DCCREQ_DS_SYNC_SUB:
188 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ds_sync_sub, tvb,
189 pos, length, ENC_BIG_ENDIAN);
190 break;
193 pos = pos + length;
196 static void
197 dissect_dccreq_sf_sub (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
199 guint8 type, length;
200 proto_item *dcc_item;
201 proto_tree *dcc_tree;
202 int pos;
204 pos = start;
205 dcc_item = proto_tree_add_text ( tree, tvb, start, len, "7 DCC-REQ Service Flow Substitution Encodings (Length = %u)", len);
206 dcc_tree = proto_item_add_subtree ( dcc_item , ett_docsis_dccreq_sf_sub);
208 while ( pos < ( start + len) )
210 type = tvb_get_guint8 (tvb, pos++);
211 length = tvb_get_guint8 (tvb, pos++);
213 switch (type)
215 case DCCREQ_SF_SFID:
216 if (length == 8)
218 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_sf_sfid_cur, tvb,
219 pos, 4, ENC_BIG_ENDIAN);
220 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_sf_sfid_new, tvb,
221 pos + 4, 4, ENC_BIG_ENDIAN);
223 else
225 THROW (ReportedBoundsError);
227 break;
228 case DCCREQ_SF_SID:
229 if (length == 4)
231 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_sf_sid_cur, tvb,
232 pos, 2, ENC_BIG_ENDIAN);
233 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_sf_sid_new, tvb,
234 pos + 2, 2, ENC_BIG_ENDIAN);
236 else
238 THROW (ReportedBoundsError);
240 break;
241 case DCCREQ_SF_UNSOL_GRANT_TREF:
242 if (length == 4)
244 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_sf_unsol_grant_tref, tvb,
245 pos, length, ENC_BIG_ENDIAN);
247 else
249 THROW (ReportedBoundsError);
251 break;
253 pos = pos + length;
256 static void
257 dissect_dccreq (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
259 guint16 pos;
260 guint8 type, length;
261 proto_tree *dcc_tree;
262 proto_item *dcc_item;
263 guint16 len;
265 len = tvb_length_remaining (tvb, 0);
267 col_set_str(pinfo->cinfo, COL_INFO, "DCC-REQ Message: ");
269 if (tree)
271 dcc_item =
272 proto_tree_add_protocol_format (tree, proto_docsis_dccreq, tvb, 0,
273 tvb_length_remaining (tvb, 0),
274 "DCC-REQ Message");
275 dcc_tree = proto_item_add_subtree (dcc_item, ett_docsis_dccreq);
276 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_tran_id, tvb, 0, 2, ENC_BIG_ENDIAN);
278 pos = 2;
279 while (pos < len)
281 type = tvb_get_guint8 (tvb, pos++);
282 length = tvb_get_guint8 (tvb, pos++);
284 switch (type)
286 case DCCREQ_UP_CHAN_ID:
287 if (length == 1)
289 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_up_chan_id, tvb,
290 pos, length, ENC_BIG_ENDIAN);
292 else
294 THROW (ReportedBoundsError);
296 break;
297 case DCCREQ_DS_PARAMS:
298 dissect_dccreq_ds_params (tvb , dcc_tree , pos , length );
299 break;
300 case DCCREQ_INIT_TECH:
301 if (length == 1)
303 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_init_tech, tvb,
304 pos, length, ENC_BIG_ENDIAN);
306 else
308 THROW (ReportedBoundsError);
310 break;
311 case DCCREQ_UCD_SUB:
312 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_ucd_sub, tvb,
313 pos, length, ENC_NA);
314 break;
315 case DCCREQ_SAID_SUB:
316 if (length == 4)
318 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_said_sub_cur, tvb,
319 pos, 2, ENC_BIG_ENDIAN);
320 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_said_sub_new, tvb,
321 pos + 2, 2, ENC_BIG_ENDIAN);
323 else
325 THROW (ReportedBoundsError);
327 break;
328 case DCCREQ_SF_SUB:
329 dissect_dccreq_sf_sub (tvb , dcc_tree , pos , length );
330 break;
331 case DCCREQ_CMTS_MAC_ADDR:
332 if (length == 6)
334 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_cmts_mac_addr, tvb,
335 pos, length, ENC_NA);
337 else
339 THROW (ReportedBoundsError);
341 break;
342 case DCCREQ_KEY_SEQ_NUM:
343 if (length == 1)
345 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_key_seq_num, tvb,
346 pos, length, ENC_BIG_ENDIAN);
348 else
350 THROW (ReportedBoundsError);
352 break;
353 case DCCREQ_HMAC_DIGEST:
354 if (length == 20)
356 proto_tree_add_item (dcc_tree, hf_docsis_dccreq_hmac_digest, tvb,
357 pos, length, ENC_NA);
359 else
361 THROW (ReportedBoundsError);
363 break;
364 } /* switch(type) */
365 pos = pos + length;
366 } /* while (pos < len) */
367 } /* if (tree) */
370 /* Register the protocol with Wireshark */
372 /* this format is require because a script is used to build the C function
373 that calls all the protocol registration.
377 void
378 proto_register_docsis_dccreq (void)
380 /* Setup list of header fields See Section 1.6.1 for details*/
381 static hf_register_info hf[] = {
382 {&hf_docsis_dccreq_tran_id ,
384 "Transaction ID",
385 "docsis_dccreq.tran_id",
386 FT_UINT16, BASE_DEC, NULL, 0x0,
387 NULL,
388 HFILL
391 {&hf_docsis_dccreq_up_chan_id ,
393 "Up Channel ID",
394 "docsis_dccreq.up_chan_id",
395 FT_UINT8, BASE_DEC, NULL, 0x0,
396 NULL,
397 HFILL
400 {&hf_docsis_dccreq_ds_freq ,
402 "Frequency",
403 "docsis_dccreq.ds_freq",
404 FT_UINT32, BASE_DEC, NULL, 0x0,
405 NULL,
406 HFILL
409 {&hf_docsis_dccreq_ds_mod_type ,
411 "Modulation Type",
412 "docsis_dccreq.ds_mod_type",
413 FT_UINT8, BASE_DEC, VALS (ds_mod_type_vals), 0x0,
414 NULL,
415 HFILL
418 {&hf_docsis_dccreq_ds_sym_rate ,
420 "Symbol Rate",
421 "docsis_dccreq.ds_sym_rate",
422 FT_UINT8, BASE_DEC, VALS (ds_sym_rate_vals), 0x0,
423 NULL,
424 HFILL
427 {&hf_docsis_dccreq_ds_intlv_depth_i ,
429 "Interleaver Depth I Value",
430 "docsis_dccreq.ds_intlv_depth_i",
431 FT_UINT8, BASE_DEC, NULL, 0x0,
432 NULL,
433 HFILL
436 {&hf_docsis_dccreq_ds_intlv_depth_j ,
438 "Interleaver Depth J Value",
439 "docsis_dccreq.ds_intlv_depth_j",
440 FT_UINT8, BASE_DEC, NULL, 0x0,
441 NULL,
442 HFILL
445 {&hf_docsis_dccreq_ds_chan_id ,
447 "Downstream Channel ID",
448 "docsis_dccreq.ds_chan_id",
449 FT_UINT8, BASE_DEC, NULL, 0x0,
450 NULL,
451 HFILL
454 {&hf_docsis_dccreq_ds_sync_sub ,
456 "SYNC Substitution",
457 "docsis_dccreq.ds_sync_sub",
458 FT_UINT8, BASE_DEC, NULL, 0x0,
459 NULL,
460 HFILL
463 {&hf_docsis_dccreq_init_tech ,
465 "Initialization Technique",
466 "docsis_dccreq.init_tech",
467 FT_UINT8, BASE_DEC, VALS (init_tech_vals), 0x0,
468 NULL,
469 HFILL
472 {&hf_docsis_dccreq_ucd_sub ,
474 "UCD Substitution",
475 "docsis_dccreq.ucd_sub",
476 FT_BYTES, BASE_NONE, NULL, 0x0,
477 NULL,
478 HFILL
481 {&hf_docsis_dccreq_said_sub_cur ,
483 "SAID Sub - Current Value",
484 "docsis_dccreq.said_sub_cur",
485 FT_UINT16, BASE_DEC, NULL, 0x0,
486 NULL,
487 HFILL
490 {&hf_docsis_dccreq_said_sub_new ,
492 "SAID Sub - New Value",
493 "docsis_dccreq.said_sub_new",
494 FT_UINT16, BASE_DEC, NULL, 0x0,
495 NULL,
496 HFILL
499 {&hf_docsis_dccreq_sf_sfid_cur ,
501 "SF Sub - SFID Current Value",
502 "docsis_dccreq.sf_sfid_cur",
503 FT_UINT32, BASE_DEC, NULL, 0x0,
504 NULL,
505 HFILL
508 {&hf_docsis_dccreq_sf_sfid_new ,
510 "SF Sub - SFID New Value",
511 "docsis_dccreq.sf_sfid_new",
512 FT_UINT32, BASE_DEC, NULL, 0x0,
513 NULL,
514 HFILL
517 {&hf_docsis_dccreq_sf_sid_cur ,
519 "SF Sub - SID Current Value",
520 "docsis_dccreq.sf_sid_cur",
521 FT_UINT16, BASE_DEC, NULL, 0x0,
522 NULL,
523 HFILL
526 {&hf_docsis_dccreq_sf_sid_new ,
528 "SF Sub - SID New Value",
529 "docsis_dccreq.sf_sid_new",
530 FT_UINT16, BASE_DEC, NULL, 0x0,
531 NULL,
532 HFILL
535 {&hf_docsis_dccreq_sf_unsol_grant_tref ,
537 "SF Sub - Unsolicited Grant Time Reference",
538 "docsis_dccreq.sf_unsol_grant_tref",
539 FT_UINT32, BASE_DEC, NULL, 0x0,
540 NULL,
541 HFILL
544 {&hf_docsis_dccreq_cmts_mac_addr ,
546 "CMTS Mac Address",
547 "docsis_dccreq.cmts_mac_addr",
548 FT_ETHER, BASE_NONE, NULL, 0x0,
549 NULL,
550 HFILL
553 {&hf_docsis_dccreq_key_seq_num ,
555 "Auth Key Sequence Number",
556 "docsis_dccreq.key_seq_num",
557 FT_UINT8, BASE_DEC, NULL, 0x0,
558 NULL,
559 HFILL
562 {&hf_docsis_dccreq_hmac_digest ,
564 "HMAC-DigestNumber",
565 "docsis_dccreq.hmac_digest",
566 FT_BYTES, BASE_NONE, NULL, 0x0,
567 NULL,
568 HFILL
574 /* Setup protocol subtree array */
575 static gint *ett[] = {
576 &ett_docsis_dccreq,
577 &ett_docsis_dccreq_sf_sub,
578 &ett_docsis_dccreq_ds_params,
581 /* Register the protocol name and description */
582 proto_docsis_dccreq =
583 proto_register_protocol ("DOCSIS Downstream Channel Change Request",
584 "DOCSIS DCC-REQ", "docsis_dccreq");
586 /* Required function calls to register the header fields and subtrees used */
587 proto_register_field_array (proto_docsis_dccreq, hf, array_length (hf));
588 proto_register_subtree_array (ett, array_length (ett));
590 register_dissector ("docsis_dccreq", dissect_dccreq, proto_docsis_dccreq);
594 /* If this dissector uses sub-dissector registration add a registration routine.
595 This format is required because a script is used to find these routines and
596 create the code that calls these routines.
598 void
599 proto_reg_handoff_docsis_dccreq (void)
601 dissector_handle_t docsis_dccreq_handle;
603 docsis_dccreq_handle = find_dissector ("docsis_dccreq");
604 dissector_add_uint ("docsis_mgmt", 0x17, docsis_dccreq_handle);