aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/docsis/packet-docsis.c
blob: 29c31109b546532b2bc1580cdbd20ad2758501e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/* packet-docsis.c
 * Routines for docsis dissection
 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


/* This code is based on the DOCSIS 1.1 specification available at:
 * http://www.cablemodem.com/specifications/specifications11.html
 *
 * DOCSIS Captures can be facilitated using the Cable Monitor Feature
 * available on Cisco Cable Modem Termination Systems :
 * http://www.cisco.com/univercd/cc/td/doc/product/cable/cab_rout/cmtsfg/ufg_cmon.htm
 *
 * This dissector depends on the presence of a DOCSIS enapsulation type.
 * There is no simple way to distinguish DOCSIS Frames from Ethernet frames,
 * since the frames are copied from the RF interface on the CMTS to
 * a Fast Ethernet interface; thus a preference was needed to enable
 * the DOCSIS encapsulation type.
 *
 * The current CVS version of libpcap allows a link-layer header type to
 * be specified for some interfaces on some platforms; for Ethernet
 * interfaces, it allows DOCSIS to be specified.  If an Ethernet capture
 * is done with a link-layer type of DOCSIS, the file will have a link-
 * layer type of DLT_DOCSIS; Ethereal will treat the frames in that capture
 * as DOCSIS frames.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <epan/packet.h>

#include "packet-docsis.h"

#define FCTYPE_PACKET 0x00
#define FCTYPE_ATMPDU 0x01
#define FCTYPE_RESRVD 0x02
#define FCTYPE_MACSPC 0x03

#define EH_NULL_CONFIG 0
#define EH_REQUEST 1
#define EH_ACK_REQ 2
#define EH_BP_UP 3
#define EH_BP_DOWN 4
#define EH_SFLOW_HDR_DOWN 5
#define EH_SFLOW_HDR_UP 6
#define EH_RESERVED_7 7
#define EH_RESERVED_8 8
#define EH_RESERVED_9 9
#define EH_RESERVED_10 10
#define EH_RESERVED_11 11
#define EH_RESERVED_12 12
#define EH_RESERVED_13 13
#define EH_RESERVED_14 14
#define EH_EXTENDED 15

/* Initialize the protocol and registered fields */
static int proto_docsis = -1;
static int hf_docsis_fctype = -1;
static int hf_docsis_machdr_fcparm = -1;
static int hf_docsis_fcparm = -1;
static int hf_docsis_ehdron = -1;
static int hf_docsis_concat_cnt = -1;
static int hf_docsis_macparm = -1;
static int hf_docsis_ehdrlen = -1;
static int hf_docsis_lensid = -1;
static int hf_docsis_eh_type = -1;
static int hf_docsis_eh_len = -1;
static int hf_docsis_eh_val = -1;
static int hf_docsis_frag_rsvd = -1;
static int hf_docsis_frag_first = -1;
static int hf_docsis_frag_last = -1;
static int hf_docsis_frag_seq = -1;
static int hf_docsis_sid = -1;
static int hf_docsis_mini_slots = -1;
static int hf_docsis_hcs = -1;
static int hf_docsis_bpi_en = -1;
static int hf_docsis_toggle_bit = -1;
static int hf_docsis_key_seq = -1;
static int hf_docsis_ehdr_ver = -1;
static int hf_docsis_said = -1;
static int hf_docsis_ehdr_phsi = -1;
static int hf_docsis_ehdr_qind = -1;
static int hf_docsis_ehdr_grants = -1;
static int hf_docsis_reserved = -1;

static dissector_handle_t docsis_handle;
static dissector_handle_t eth_withoutfcs_handle;
static dissector_handle_t data_handle;
static dissector_handle_t docsis_mgmt_handle;
static dissector_table_t docsis_dissector_table;

/* Initialize the subtree pointers */
static gint ett_docsis = -1;
static gint ett_ehdr = -1;

static const value_string fctype_vals[] = {
  {FCTYPE_PACKET, "Packet PDU"},
  {FCTYPE_ATMPDU, "ATM PDU"},
  {FCTYPE_RESRVD, "Reserved"},
  {FCTYPE_MACSPC, "MAC Specific"},
  {0, NULL}
};

static const value_string eh_type_vals[] = {
  {0, "NULL Configuration Parameter"},
  {EH_REQUEST, "Request"},
  {EH_ACK_REQ, "Acknowledgement Requested"},
  {EH_BP_UP, "Upstream Privacy Element"},
  {EH_BP_DOWN, "Downstream  Privacy Element"},
  {EH_SFLOW_HDR_UP, "Service Flow EH; PHS Header Upstream"},
  {EH_SFLOW_HDR_DOWN, "Service Flow EH; PHS Header Downstream"},
  {EH_RESERVED_7, "Reserved"},
  {EH_RESERVED_8, "Reserved"},
  {EH_RESERVED_9, "Reserved"},
  {EH_RESERVED_10, "Reserved"},
  {EH_RESERVED_10, "Reserved"},
  {EH_RESERVED_11, "Reserved"},
  {EH_RESERVED_12, "Reserved"},
  {EH_RESERVED_13, "Reserved"},
  {EH_RESERVED_14, "Reserved"},
  {EH_EXTENDED, "Extended"},
  {0, NULL}
};

static const value_string fcparm_vals[] = {
  {0x0, "Timing Header"},
  {0x1, "Mac Management Message"},
  {0x2, "Request Frame"},
  {0x3, "Fragmentation Header"},
  {0x1C, "Concatenation Header"},
  {0, NULL}
};

static const true_false_string ehdron_tfs = {
  "Extended Header Present",
  "Extended Header Absent"
};

static const true_false_string ena_dis_tfs = {
  "Enabled",
  "Disabled"
};

static const true_false_string qind_tfs = {
  "Rate overrun",
  "Rate non-overrun"
};

static const true_false_string odd_even_tfs = {
  "Odd Key",
  "Even Key",
};

/* Code to actually dissect the packets */
/* Code to Dissect the extended header */
static void
dissect_ehdr (tvbuff_t * tvb, proto_tree * tree, gboolean isfrag)
{
  proto_tree *ehdr_tree;
  proto_item *it;
  gint ehdrlen;
  int pos;
  guint8 type;
  guint8 len;
  guint8 val;
  guint8 mini_slots;
  guint16 sid;

  ehdrlen = tvb_get_guint8 (tvb, 1);
  pos = 4;

  it = proto_tree_add_text (tree, tvb, pos, ehdrlen, "Extended Header");
  ehdr_tree = proto_item_add_subtree (it, ett_ehdr);
  while (pos < ehdrlen + 4)
    {
      type = (tvb_get_guint8 (tvb, pos) & 0xF0);
      len = (tvb_get_guint8 (tvb, pos) & 0x0F);
      if ((((type >> 4) & 0x0F)== 6) && (len == 2)) 
        {
          proto_tree_add_item_hidden (ehdr_tree, hf_docsis_eh_type, tvb, pos, 1, FALSE);
	  proto_tree_add_text(ehdr_tree, tvb, pos, 1, "0110 ....  = Unsolicited Grant Sync EHDR Sub-Element" );
        }
      else
        proto_tree_add_item (ehdr_tree, hf_docsis_eh_type, tvb, pos, 1, FALSE);
      proto_tree_add_item (ehdr_tree, hf_docsis_eh_len, tvb, pos, 1, FALSE);
      switch ((type >> 4) & 0x0F)
	{
	case EH_REQUEST:
	  if (len == 3)
	    {
	      mini_slots = tvb_get_guint8 (tvb, pos + 1);
	      sid = tvb_get_ntohs (tvb, pos + 2);
	      proto_tree_add_uint (ehdr_tree, hf_docsis_mini_slots, tvb,
				   pos + 1, 1, mini_slots);
	      proto_tree_add_uint (ehdr_tree, hf_docsis_sid, tvb, pos + 2, 2,
				   sid);
	    }
	  else
	    {
	      THROW (ReportedBoundsError);
	    }
	  break;
	case EH_ACK_REQ:
	  if (len == 2)
	    {
	      sid = tvb_get_ntohs (tvb, pos + 1);
	      proto_tree_add_uint (ehdr_tree, hf_docsis_sid, tvb, pos + 2, 2,
				   sid);
	    }
	  else
	    {
	      THROW (ReportedBoundsError);
	    }
	case EH_BP_UP:
	  proto_tree_add_item (ehdr_tree, hf_docsis_key_seq, tvb, pos + 1, 1,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ver, tvb, pos + 1, 1,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_bpi_en, tvb, pos + 2, 1,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_toggle_bit, tvb, pos + 2,
			       1, FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_sid, tvb, pos + 2, 2,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_mini_slots, tvb, pos + 4,
			       1, FALSE);
	  if (isfrag)
	    {
	      proto_tree_add_item (ehdr_tree, hf_docsis_frag_rsvd, tvb, pos+5,
	                          1, FALSE);
	      proto_tree_add_item (ehdr_tree, hf_docsis_frag_first, tvb, pos+5,
			          1, FALSE);
	      proto_tree_add_item (ehdr_tree, hf_docsis_frag_last, tvb, pos+5,
			          1, FALSE);
	      proto_tree_add_item (ehdr_tree, hf_docsis_frag_seq, tvb, pos+5,
			          1, FALSE);
	    }
	  break;
	case EH_BP_DOWN:
	  proto_tree_add_item (ehdr_tree, hf_docsis_key_seq, tvb, pos + 1, 1,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_ver, tvb, pos + 1, 1,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_bpi_en, tvb, pos + 2, 1,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_toggle_bit, tvb, pos + 2,
			       1, FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_said, tvb, pos + 2, 2,
			       FALSE);
	  proto_tree_add_item (ehdr_tree, hf_docsis_reserved, tvb, pos + 4, 1,
			       FALSE);
	  break;
	case EH_SFLOW_HDR_DOWN:
	case EH_SFLOW_HDR_UP:
	  val = tvb_get_guint8 (tvb, pos+1);
	  if (val == 0)
	  {
	    proto_tree_add_item_hidden (ehdr_tree, hf_docsis_ehdr_phsi, tvb, pos+1, 1, FALSE);
	    proto_tree_add_text (ehdr_tree, tvb, pos+1, 1, "0000 0000 = No PHS on current packet" );
	  }
	  else
	    proto_tree_add_item(ehdr_tree, hf_docsis_ehdr_phsi, tvb, pos+1, 1, FALSE);

	  if (len == 2) 
	  {
	    proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_qind, tvb, pos+2, 1, FALSE);
	    proto_tree_add_item (ehdr_tree, hf_docsis_ehdr_grants, tvb, pos+2, 1, FALSE);
	  }
	  break;
	default:
	  if (len > 0)
	    proto_tree_add_item (ehdr_tree, hf_docsis_eh_val, tvb, pos + 1,
				  len, FALSE);
	}
      pos += len + 1;
    }

  return;
}


static void
dissect_docsis (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
{
  guint8 fc;
  guint8 fctype;
  guint8 fcparm;
  guint8 ehdron;
  gint mac_parm;
  gint hdrlen;
  guint16 len_sid;
  tvbuff_t *next_tvb, *mgt_tvb;
  gint pdulen, captured_length;
  gint framelen;
  gboolean isfrag = FALSE;
  gint oldconcatlen;

/* Set up structures needed to add the protocol subtree and manage it */
  proto_item *ti;
  proto_tree *docsis_tree;
/* concatlen and concatpos are declared static to allow for recursive calls to
 * the dissect_docsis routine when dissecting Concatenated frames
 */
  static gint concatlen;
  static gint concatpos;

/* Extract important fields */
  fc = tvb_get_guint8 (tvb, 0);	/* Frame Control Byte */
  fctype = (fc >> 6) & 0x03;	/* Frame Control Type:  2 MSB Bits */
  fcparm = (fc >> 1) & 0x1F;	/* Frame Control Parameter: Next 5 Bits */
  ehdron = (fc & 0x01);		/* Extended Header Bit: LSB */

  mac_parm = tvb_get_guint8 (tvb, 1);	/* Mac Parm */
  len_sid = tvb_get_ntohs (tvb, 2);	/* Length Or SID */

/* set Header length based on presence of Extended header */
  if (ehdron == 0x00)
    hdrlen = 6;
  else
    hdrlen = 6 + mac_parm;

/* Captured PDU Length is based on the length of the header */
  captured_length = tvb_length_remaining (tvb, hdrlen);

/* If this is a Request Frame, then pdulen is 0 and framelen is 6 */
  if ((fctype == FCTYPE_MACSPC) && fcparm == 0x02)
    {
      pdulen = 0;
      framelen = 6;
    }
  else
    {
      framelen = 6 + len_sid;
      pdulen = len_sid - (mac_parm + 2);
    }

/* if this is a concatenated frame setup the length of the concatenated
 * frame and set the position to the first byte of the first frame */
  if ((fctype == FCTYPE_MACSPC) && (fcparm == 0x1c))
    {
      concatlen = len_sid;
      concatpos = 6;
    }

/* Make entries in Protocol column and Info column on summary display */
  if (check_col (pinfo->cinfo, COL_PROTOCOL))
    col_set_str (pinfo->cinfo, COL_PROTOCOL, "DOCSIS");

  if (check_col (pinfo->cinfo, COL_INFO))
    {
      col_clear (pinfo->cinfo, COL_INFO);
      switch (fctype)
	{
	case FCTYPE_PACKET:
	  col_set_str (pinfo->cinfo, COL_INFO, "Packet PDU");
	  break;
	case FCTYPE_ATMPDU:
	  col_set_str (pinfo->cinfo, COL_INFO, "ATM PDU");
	  break;
	case FCTYPE_RESRVD:
	  col_set_str (pinfo->cinfo, COL_INFO, "Reserved PDU");
	  break;
	case FCTYPE_MACSPC:
	  if (fcparm == 0x02)
	    col_add_fstr (pinfo->cinfo, COL_INFO,
			  "Request Frame SID = %u Mini Slots = %u", len_sid,
			  mac_parm);
	  else if (fcparm == 0x03)
	    col_set_str (pinfo->cinfo, COL_INFO, "Fragmented Frame");
	  else
	    col_set_str (pinfo->cinfo, COL_INFO, "Mac Specific");
	  break;
	}			/* switch */
    }				/* if */

/* In the interest of speed, if "tree" is NULL, don't do any work not
   necessary to generate protocol tree items. */
  if (tree)
    {
      ti = proto_tree_add_protocol_format (tree, proto_docsis, tvb, 0,
					   hdrlen, "DOCSIS");
      docsis_tree = proto_item_add_subtree (ti, ett_docsis);

/* add an item to the subtree, see section 1.6 for more information */
      proto_tree_add_item (docsis_tree, hf_docsis_fctype, tvb, 0, 1, FALSE);
      switch (fctype)
	{
	case FCTYPE_PACKET:
	case FCTYPE_ATMPDU:
	case FCTYPE_RESRVD:
	  proto_tree_add_item (docsis_tree, hf_docsis_fcparm, tvb, 0, 1,
			       FALSE);
	  proto_tree_add_item (docsis_tree, hf_docsis_ehdron, tvb, 0, 1,
			       FALSE);
	  if (ehdron == 0x01)
	    {
	      proto_tree_add_item (docsis_tree, hf_docsis_ehdrlen, tvb, 1, 1,
				   FALSE);
	      proto_tree_add_item (docsis_tree, hf_docsis_lensid, tvb, 2, 2,
				   FALSE);
	      dissect_ehdr (tvb, docsis_tree, isfrag);
	      proto_tree_add_item (docsis_tree, hf_docsis_hcs, tvb,
				   4 + mac_parm, 2, FALSE);
	    }
	  else
	    {
	      proto_tree_add_item (docsis_tree, hf_docsis_macparm, tvb, 1, 1,
				   FALSE);
	      proto_tree_add_item (docsis_tree, hf_docsis_lensid, tvb, 2, 2,
				   FALSE);
	      proto_tree_add_item (docsis_tree, hf_docsis_hcs, tvb, 4, 2,
				   FALSE);
	    }
	  break;
	case FCTYPE_MACSPC:
	  proto_tree_add_item (docsis_tree, hf_docsis_machdr_fcparm, tvb, 0,
			       1, FALSE);
	  proto_tree_add_item (docsis_tree, hf_docsis_ehdron, tvb, 0, 1,
			       FALSE);
	  /* Decode for a Request Frame.  No extended header */
	  if (fcparm == 0x02)
	    {
	      proto_tree_add_uint (docsis_tree, hf_docsis_mini_slots, tvb, 1,
				   1, mac_parm);
	      proto_tree_add_uint (docsis_tree, hf_docsis_sid, tvb, 2, 2,
				   len_sid);
	      proto_tree_add_item (docsis_tree, hf_docsis_hcs, tvb, 4, 2,
				   FALSE);
	      break;
	    }
	  /* Check if this is a fragmentation header */
	  if (fcparm == 0x03)
	    {
	      isfrag = TRUE;
	    }
	  /* Decode for a Concatenated Header.  No Extended Header */
	  if (fcparm == 0x1c)
	    {
	      proto_item_append_text (ti, " (Concatenated Header)");
	      proto_tree_add_item (docsis_tree, hf_docsis_concat_cnt, tvb, 1,
				   1, FALSE);
	      proto_tree_add_item (docsis_tree, hf_docsis_lensid, tvb, 2, 2,
				   FALSE);
	      proto_tree_add_item (docsis_tree, hf_docsis_hcs, tvb, 4, 2,
				   FALSE);
	      break;
	    }
	  /* If Extended header is present then decode it */
	  if (ehdron == 0x01)
	    {
	      proto_tree_add_item (docsis_tree, hf_docsis_ehdrlen, tvb, 1, 1,
				   FALSE);
	      proto_tree_add_item (docsis_tree, hf_docsis_lensid, tvb, 2, 2,
				   FALSE);
	      dissect_ehdr (tvb, docsis_tree, isfrag);
	      proto_tree_add_item (docsis_tree, hf_docsis_hcs, tvb,
				   4 + mac_parm, 2, FALSE);
	      break;
	    }
	  /* default case for all other Mac Frame Types */
	  proto_tree_add_item (docsis_tree, hf_docsis_macparm, tvb, 1, 1,
			       FALSE);
	  proto_tree_add_item (docsis_tree, hf_docsis_lensid, tvb, 2, 2,
			       FALSE);
	  proto_tree_add_item (docsis_tree, hf_docsis_hcs, tvb, 4, 2, FALSE);
	  break;
	}
    }

/* If this protocol has a sub-dissector call it here, see section 1.8 */
  switch (fctype)
    {
    case FCTYPE_PACKET:
      if (pdulen >= 0)
	{
	  if (pdulen > 0)
	    {
	      next_tvb = tvb_new_subset (tvb, hdrlen, captured_length, pdulen);
	      call_dissector (eth_withoutfcs_handle, next_tvb, pinfo, tree);
	    }
	  if (concatlen > 0)
	    {
	      concatlen = concatlen - framelen;
	      concatpos += framelen;
	    }
	}
      break;
    case FCTYPE_MACSPC:
      switch (fcparm)
	{
	case 0x00:
	case 0x01:
	  if (pdulen > 0)
	    {
	      mgt_tvb = tvb_new_subset (tvb, hdrlen, captured_length, pdulen);
	      call_dissector (docsis_mgmt_handle, mgt_tvb, pinfo, tree);
	    }
	  if (concatlen > 0)
	    {
	      concatlen = concatlen - framelen;
	      concatpos += framelen;
	    }
	  break;
	case 0x02:
	  /* Don't do anything for a Request Frame */
	  break;
	case 0x03:
	  /* For Fragmentation Frames simply dissect using the data
	   * dissector as we don't handle them yet
	   */
	  if (pdulen > 0)
	    {
	      mgt_tvb = tvb_new_subset (tvb, hdrlen, captured_length, pdulen);
	      call_dissector (data_handle, mgt_tvb, pinfo, tree);
	    }
	  if (concatlen > 0)
	    {
	      concatlen = concatlen - framelen;
	      concatpos += framelen;
	    }
	  break;
	case 0x1c:
	  /* call the docsis dissector on the same frame
	   * to dissect DOCSIS frames within the concatenated
	   * frame.  concatpos and concatlen are declared
	   * static and are decremented and incremented
	   * respectively when the inner
	   * docsis frames are dissected. */
	  while (concatlen > 0)
	    {
	      oldconcatlen = concatlen;
	      next_tvb = tvb_new_subset (tvb, concatpos, -1, concatlen);
	      call_dissector (docsis_handle, next_tvb, pinfo, tree);
	      if (oldconcatlen <= concatlen)
		THROW(ReportedBoundsError);
	    }
	  concatlen = 0;
	  concatpos = 0;
	  if (check_col (pinfo->cinfo, COL_INFO))
	    col_set_str (pinfo->cinfo, COL_INFO, "Concatenated Frame");
	  break;
	}
      break;
    }
}


/* Register the protocol with Ethereal */

/* this format is require because a script is used to build the C function
   that calls all the protocol registration.
*/


void
proto_register_docsis (void)
{

/* Setup list of header fields  See Section 1.6.1 for details*/
  static hf_register_info hf[] = {
    {&hf_docsis_fctype,
     {"FCType", "docsis.fctype",
      FT_UINT8, BASE_HEX, VALS (fctype_vals), 0xC0,
      "Frame Control Type", HFILL}
     },
    {&hf_docsis_fcparm,
     {"FCParm", "docsis.fcparm",
      FT_UINT8, BASE_DEC, NULL, 0x3E,
      "Parameter Field", HFILL}
     },
    {&hf_docsis_machdr_fcparm,
     {"FCParm", "docsis.fcparm",
      FT_UINT8, BASE_HEX, VALS (fcparm_vals), 0x3E,
      "Parameter Field", HFILL}
     },
    {&hf_docsis_ehdron,
     {"EHDRON", "docsis.ehdron",
      FT_BOOLEAN, 8, TFS (&ehdron_tfs), 0x01,
      "Extended Header Presence", HFILL}
     },
    {&hf_docsis_macparm,
     {"MacParm", "docsis.macparm",
      FT_UINT8, BASE_HEX, NULL, 0x0,
      "Mac Parameter Field", HFILL}
     },
    {&hf_docsis_concat_cnt,
     {"Number of Concatenated Frames", "docsis.macparm",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Number of Concatenated Frames", HFILL}
     },
    {&hf_docsis_ehdrlen,
     {"Extended Header Length (bytes)", "docsis.macparm",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Mac Parameter Field", HFILL}
     },
    {&hf_docsis_lensid,
     {"Length after HCS (bytes)", "docsis.lensid",
      FT_UINT16, BASE_DEC, NULL, 0x0,
      "Length or SID", HFILL}
     },
    {&hf_docsis_eh_type,
     {"Type", "docsis.ehdr.type",
      FT_UINT8, BASE_DEC, VALS (eh_type_vals), 0xF0,
      "TLV Type", HFILL}
     },
    {&hf_docsis_eh_len,
     {"Length", "docsis.ehdr.len",
      FT_UINT8, BASE_DEC, NULL, 0x0F,
      "TLV Len", HFILL}
     },
    {&hf_docsis_eh_val,
     {"Value", "docsis.ehdr.value",
      FT_BYTES, BASE_HEX, NULL, 0x0,
      "TLV Value", HFILL}
     },
    {&hf_docsis_frag_rsvd,
     {"Reserved", "docsis.frag_rsvd",
      FT_UINT8, BASE_DEC, NULL, 0xC0,
      "Reserved", HFILL}
     },
    {&hf_docsis_frag_first,
     {"First Frame", "docsis.frag_first",
      FT_BOOLEAN, 8, NULL, 0x20,
      "First Frame", HFILL}
     },
    {&hf_docsis_frag_last,
     {"Last Frame", "docsis.frag_last",
      FT_BOOLEAN, 8, NULL, 0x10,
      "Last Frame", HFILL}
     },
    {&hf_docsis_frag_seq,
     {"Fragmentation Sequence #", "docsis.frag_seq",
      FT_UINT8, BASE_DEC, NULL, 0x0F,
      "Fragmentation Sequence Number", HFILL}
     },
    {&hf_docsis_sid,
     {"SID", "docsis.ehdr.sid",
      FT_UINT16, BASE_DEC, NULL, 0x3FFF,
      "Service Identifier", HFILL}
     },
    {&hf_docsis_said,
     {"SAID", "docsis.ehdr.said",
      FT_UINT16, BASE_DEC, NULL, 0x3FFF,
      "Security Association Identifier", HFILL}
     },
    {&hf_docsis_reserved,
     {"Reserved", "docsis.ehdr.rsvd",
      FT_UINT8, BASE_HEX, NULL, 0x3FFF,
      "Reserved Byte", HFILL}
     },
    {&hf_docsis_mini_slots,
     {"MiniSlots", "docsis.ehdr.minislots",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Mini Slots Requested", HFILL}
     },
    {&hf_docsis_key_seq,
     {"Key Sequence", "docsis.ehdr.keyseq",
      FT_UINT8, BASE_DEC, NULL, 0xF0,
      "Key Sequence", HFILL}
     },
    {&hf_docsis_ehdr_ver,
     {"Version", "docsis.ehdr.ver",
      FT_UINT8, BASE_DEC, NULL, 0x0F,
      "Version", HFILL}
     },
    {&hf_docsis_ehdr_phsi,
     {"Payload Header Suppression Index", "docsis.ehdr.phsi",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Payload Header Suppression Index", HFILL}
     },
    {&hf_docsis_ehdr_qind,
     {"Queue Indicator", "docsis.ehdr.qind",
      FT_BOOLEAN, 8, TFS(&qind_tfs), 0x80,
      "Queue Indicator", HFILL}
     },
    {&hf_docsis_ehdr_grants,
     {"Active Grants", "docsis.ehdr.act_grants",
      FT_UINT8, BASE_DEC, NULL, 0x7F,
      "Active Grants", HFILL}
     },
    {&hf_docsis_hcs,
     {"Header check sequence", "docsis.hcs",
      FT_UINT16, BASE_HEX, NULL, 0x0,
      "Header check sequence", HFILL},
     },
    {&hf_docsis_bpi_en,
     {"Encryption", "docsis.bpi_en",
      FT_BOOLEAN, 8, TFS (&ena_dis_tfs), 0x80,
      "BPI Enable", HFILL},
     },
    {&hf_docsis_toggle_bit,
     {"Toggle", "docsis.toggle_bit",
      FT_BOOLEAN, 8, TFS (&odd_even_tfs), 0x40,
      "Toggle", HFILL},
     },

  };

/* Setup protocol subtree array */
  static gint *ett[] = {
    &ett_docsis,
    &ett_ehdr,
  };

  docsis_dissector_table = register_dissector_table ("docsis",
						     "DOCSIS Encapsulation Type",
						     FT_UINT8, BASE_DEC);

/* Register the protocol name and description */
  proto_docsis = proto_register_protocol ("DOCSIS 1.1", "DOCSIS", "docsis");

/* Required function calls to register the header fields and subtrees used */
  proto_register_field_array (proto_docsis, hf, array_length (hf));
  proto_register_subtree_array (ett, array_length (ett));

  register_dissector ("docsis", dissect_docsis, proto_docsis);
}


/* If this dissector uses sub-dissector registration add a registration routine.
   This format is required because a script is used to find these routines and
   create the code that calls these routines.
*/
void
proto_reg_handoff_docsis (void)
{


  docsis_handle = find_dissector ("docsis");
  data_handle = find_dissector ("data");
  dissector_add ("wtap_encap", WTAP_ENCAP_DOCSIS, docsis_handle);

  docsis_mgmt_handle = find_dissector ("docsis_mgmt");
  eth_withoutfcs_handle = find_dissector ("eth_withoutfcs");
}