769a74975fa1b7f967294a80b88336fa0d7eba2a
[obnox/wireshark/wip.git] / plugins / docsis / packet-type29ucd.c
1 /* packet-type29ucd.c
2  * Routines for Type 29 UCD - DOCSIS 2.0 only - Message dissection
3  * Copyright 2003, Brian Wheeler <brian.wheeler[AT]arrisi.com>
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30
31 #include "plugins/plugin_api.h"
32 #include "plugins/plugin_api_defs.h"
33 #include "moduleinfo.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include <gmodule.h>
40
41 #include <epan/packet.h>
42
43 #define type29ucd_SYMBOL_RATE 1
44 #define type29ucd_FREQUENCY 2
45 #define type29ucd_PREAMBLE 3
46 #define type29ucd_BURST_DESCR 4
47 #define type29ucd_BURST_DESCR5 5
48 #define type29ucd_EXT_PREAMBLE 6
49 #define type29ucd_SCDMA_MODE_ENABLE 7
50 #define type29ucd_SCDMA_SPREADING_INTERVAL 8
51 #define type29ucd_SCDMA_CODES_PER_MINI_SLOT 9
52 #define type29ucd_SCDMA_ACTIVE_CODES 10
53 #define type29ucd_SCDMA_CODE_HOPPING_SEED 11
54 #define type29ucd_SCDMA_US_RATIO_NUM 12
55 #define type29ucd_SCDMA_US_RATIO_DENOM 13
56 #define type29ucd_SCDMA_TIMESTAMP_SNAPSHOT 14
57 #define type29ucd_MAINTAIN_POWER_SPECTRAL_DENSITY 15
58 #define type29ucd_RANGING_REQUIRED 16
59
60 #define type29ucd_MODULATION 1
61 #define type29ucd_DIFF_ENCODING 2
62 #define type29ucd_PREAMBLE_LEN 3
63 #define type29ucd_PREAMBLE_VAL_OFF 4
64 #define type29ucd_FEC 5
65 #define type29ucd_FEC_CODEWORD 6
66 #define type29ucd_SCRAMBLER_SEED 7
67 #define type29ucd_MAX_BURST 8
68 #define type29ucd_GUARD_TIME 9
69 #define type29ucd_LAST_CW_LEN 10
70 #define type29ucd_SCRAMBLER_ONOFF 11
71 #define type29ucd_RS_INT_DEPTH 12
72 #define type29ucd_RS_INT_BLOCK 13
73 #define type29ucd_PREAMBLE_TYPE 14
74 #define type29ucd_SCMDA_SCRAMBLER_ONOFF 15
75 #define type29ucd_SCDMA_CODES_PER_SUBFRAME 16
76 #define type29ucd_SCDMA_FRAMER_INT_STEP_SIZE 17
77 #define type29ucd_TCM_ENABLED 18
78
79 #define IUC_REQUEST 1
80 #define IUC_REQ_DATA 2
81 #define IUC_INIT_MAINT 3
82 #define IUC_STATION_MAINT 4
83 #define IUC_SHORT_DATA_GRANT 5
84 #define IUC_LONG_DATA_GRANT 6
85 #define IUC_NULL_IE 7
86 #define IUC_DATA_ACK 8
87 #define IUC_ADV_PHY_SHORT_DATA_GRANT 9
88 #define IUC_ADV_PHY_LONG_DATA_GRANT 10
89 #define IUC_ADV_PHY_UGS 11
90 #define IUC_RESERVED12 12
91 #define IUC_RESERVED13 13
92 #define IUC_RESERVED14 14
93 #define IUC_EXPANSION 15
94
95 /* Initialize the protocol and registered fields */
96 static int proto_docsis_type29ucd = -1;
97
98 static int hf_docsis_type29ucd_upstream_chid = -1;
99 static int hf_docsis_type29ucd_config_ch_cnt = -1;
100 static int hf_docsis_type29ucd_mini_slot_size = -1;
101 static int hf_docsis_type29ucd_down_chid = -1;
102 static int hf_docsis_type29ucd_symbol_rate = -1;
103 static int hf_docsis_type29ucd_frequency = -1;
104 static int hf_docsis_type29ucd_preamble_pat = -1;
105 static int hf_docsis_type29ucd_iuc = -1;
106 static int hf_docsis_type29ucd_ext_preamble = -1;
107 static int hf_docsis_type29ucd_scdma_mode_enable = -1;
108 static int hf_docsis_type29ucd_scdma_spreading_interval = -1;
109 static int hf_docsis_type29ucd_scdma_codes_per_mini_slot = -1;
110 static int hf_docsis_type29ucd_scdma_active_codes = -1;
111 static int hf_docsis_type29ucd_scdma_code_hopping_seed = -1;
112 static int hf_docsis_type29ucd_scdma_us_ratio_num = -1;
113 static int hf_docsis_type29ucd_scdma_us_ratio_denom = -1;
114 static int hf_docsis_type29ucd_scdma_timestamp_snapshot = -1;
115 static int hf_docsis_type29ucd_maintain_power_spectral_density = -1;
116 static int hf_docsis_type29ucd_ranging_required = -1;
117
118 static int hf_docsis_burst_mod_type = -1;
119 static int hf_docsis_burst_diff_encoding = -1;
120 static int hf_docsis_burst_preamble_len = -1;
121 static int hf_docsis_burst_preamble_val_off = -1;
122 static int hf_docsis_burst_fec = -1;
123 static int hf_docsis_burst_fec_codeword = -1;
124 static int hf_docsis_burst_scrambler_seed = -1;
125 static int hf_docsis_burst_max_burst = -1;
126 static int hf_docsis_burst_guard_time = -1;
127 static int hf_docsis_burst_last_cw_len = -1;
128 static int hf_docsis_burst_scrambler_onoff = -1;
129 static int hf_docsis_rs_int_depth = -1;
130 static int hf_docsis_rs_int_block = -1;
131 static int hf_docsis_preamble_type = -1;
132 static int hf_docsis_scdma_scrambler_onoff = -1;
133 static int hf_docsis_scdma_codes_per_subframe = -1;
134 static int hf_docsis_scdma_framer_int_step_size = -1;
135 static int hf_docsis_tcm_enabled = -1;
136
137
138 /* Initialize the subtree pointers */
139 static gint ett_docsis_type29ucd = -1;
140 static gint ett_burst_descr = -1;
141
142 static const value_string channel_tlv_vals[] = {
143      {type29ucd_SYMBOL_RATE, "Symbol Rate"},
144      {type29ucd_FREQUENCY, "Frequency"},
145      {type29ucd_PREAMBLE, "Preamble Pattern"},
146      {type29ucd_BURST_DESCR, "Burst Descriptor"},
147      {type29ucd_BURST_DESCR5, "Burst Descriptor DOCSIS 2.0"},
148      {type29ucd_EXT_PREAMBLE, "Extended Preamble Pattern"},
149      {type29ucd_SCDMA_MODE_ENABLE, "SCDMA Mode Enabled"},
150      {type29ucd_SCDMA_SPREADING_INTERVAL, "SCDMA Spreading Intervals per Frame"},
151      {type29ucd_SCDMA_CODES_PER_MINI_SLOT, "SCDMA Codes per Mini-slot"},
152      {type29ucd_SCDMA_ACTIVE_CODES, "SCDMA Number of Active Codes"},
153      {type29ucd_SCDMA_CODE_HOPPING_SEED, "SCDMA Code Hopping Seed"},
154      {type29ucd_SCDMA_US_RATIO_NUM, "SCDMA US ratio numerator M"},
155      {type29ucd_SCDMA_US_RATIO_DENOM, "SCDMA US ratio denominator N"},
156      {type29ucd_SCDMA_TIMESTAMP_SNAPSHOT, "SCDMA Timestamp Snapshot"},
157      {type29ucd_MAINTAIN_POWER_SPECTRAL_DENSITY, "Maintain Power Spectral Density"},
158      {type29ucd_RANGING_REQUIRED, "Ranging Required"},
159      {0, NULL}
160 };
161
162 static const value_string on_off_vals[] = {
163   {1, "On"},
164   {2, "Off"},
165   {0, NULL}
166 };
167
168 static const value_string mod_vals2[] = {
169      {1, "QPSK"},
170      {2, "QAM16"},
171      {3, "QAM8"},
172      {4, "QAM32"},
173      {5, "QAM64"},
174      {6, "QAM128 (S-CDMA)"},
175      {0, NULL}
176 };
177
178 value_string iuc_vals2[] = {
179      {IUC_REQUEST, "Request"},
180      {IUC_REQ_DATA, "REQ/Data"},
181      {IUC_INIT_MAINT, "Initial Maintenance"},
182      {IUC_STATION_MAINT, "Station Maintenance"},
183      {IUC_SHORT_DATA_GRANT, "Short Data Grant"},
184      {IUC_LONG_DATA_GRANT, "Long Data Grant"},
185      {IUC_NULL_IE, "NULL IE"},
186      {IUC_DATA_ACK, "Data Ack"},
187      {IUC_ADV_PHY_SHORT_DATA_GRANT, "Advanced Phy Short Data Grant"},
188      {IUC_ADV_PHY_LONG_DATA_GRANT, "Advanced Phy Long Data Grant"},
189      {IUC_ADV_PHY_UGS, "Advanced Phy UGS"},
190      {IUC_RESERVED12, "Reserved 12"},
191      {IUC_RESERVED13, "Reserved 13"},
192      {IUC_RESERVED14, "Reserved 14"},
193      {IUC_EXPANSION, "IUC Expansion"},
194      {0, NULL}
195 };
196
197 static const value_string last_cw_len_vals[] = {
198   {1, "Fixed"},
199   {2, "Shortened"},
200   {0, NULL}
201 };
202 /* Code to actually dissect the packets */
203 static void
204 dissect_type29ucd (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
205 {
206   guint16 pos, endtlvpos;
207   guint8 type, length;
208   guint8 tlvlen, tlvtype;
209   proto_tree *burst_descr_tree;
210   proto_item *it;
211   proto_tree *type29ucd_tree;
212   proto_item *type29ucd_item;
213   guint16 len;
214   guint8 upchid, symrate;
215
216   len = tvb_length_remaining (tvb, 0);
217   upchid = tvb_get_guint8 (tvb, 0);
218
219   /* if the upstream Channel ID is 0 then this is for Telephony Return) */
220   if (check_col (pinfo->cinfo, COL_INFO))
221     {
222       col_clear (pinfo->cinfo, COL_INFO);
223       if (upchid > 0)
224         col_add_fstr (pinfo->cinfo, COL_INFO,
225                       "type29ucd Message:  Channel ID = %u (U%u)", upchid,
226                       upchid - 1);
227       else
228         col_add_fstr (pinfo->cinfo, COL_INFO,
229                       "type29ucd Message:  Channel ID = %u (Telephony Return)",
230                       upchid);
231     }
232
233   if (tree)
234     {
235       type29ucd_item =
236         proto_tree_add_protocol_format (tree, proto_docsis_type29ucd, tvb, 0,
237                                         tvb_length_remaining (tvb, 0),
238                                         "type29ucd Message");
239       type29ucd_tree = proto_item_add_subtree (type29ucd_item, ett_docsis_type29ucd);
240       proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_upstream_chid, tvb, 0, 1,
241                            FALSE);
242       proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_config_ch_cnt, tvb, 1, 1,
243                            FALSE);
244       proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_mini_slot_size, tvb, 2, 1,
245                            FALSE);
246       proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_down_chid, tvb, 3, 1,
247                            FALSE);
248
249       pos = 4;
250       while (pos < len)
251         {
252           type = tvb_get_guint8 (tvb, pos++);
253           length = tvb_get_guint8 (tvb, pos++);
254           switch (type)
255             {
256             case type29ucd_SYMBOL_RATE:
257               if (length == 1)
258                 {
259                   symrate = tvb_get_guint8 (tvb, pos);
260                   proto_tree_add_uint (type29ucd_tree, hf_docsis_type29ucd_symbol_rate,
261                                        tvb, pos, length, symrate * 160);
262                 }
263               else
264                 {
265                   THROW (ReportedBoundsError);
266                 }
267               pos = pos + length;
268               break;
269             case type29ucd_FREQUENCY:
270               if (length == 4)
271                 {
272                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_frequency, tvb,
273                                        pos, length, FALSE);
274                   pos = pos + length;
275                 }
276               else
277                 {
278                   THROW (ReportedBoundsError);
279                 }
280               break;
281             case type29ucd_PREAMBLE:
282               proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_preamble_pat, tvb,
283                                    pos, length, FALSE);
284               pos = pos + length;
285               break;
286 /* DOCSIS 2.0 UCD TLV definitions 
287  * #define type29ucd_EXT_PREAMBLE 6
288  * #define type29ucd_SCDMA_MODE_ENABLE 7
289  * #define type29ucd_SCDMA_SPREADING_INTERVAL 8
290  * #define type29ucd_SCDMA_CODES_PER_MINI_SLOT 9
291  * #define type29ucd_SCDMA_ACTIVE_CODES 10
292  * #define type29ucd_SCDMA_CODE_HOPPING_SEED 11
293  * #define type29ucd_SCDMA_US_RATIO_NUM 12
294  * #define type29ucd_SCDMA_US_RATIO_DENOM 13
295  * #define type29ucd_SCDMA_TIMESTAMP_SNAPSHOT 14
296  * #define type29ucd_MAINTAIN_POWER_SPECTRAL_DENSITY 15
297  * #define type29ucd_RANGING_REQUIRED 16
298  */
299             case type29ucd_EXT_PREAMBLE:
300               proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_ext_preamble, tvb,
301                                    pos, length, FALSE);
302               pos = pos + length;
303               break;
304             case type29ucd_SCDMA_MODE_ENABLE:
305               if (length == 1)
306                 {
307                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_mode_enable,
308                                        tvb, pos, length, FALSE);
309                 }
310               else
311                 {
312                   THROW (ReportedBoundsError);
313                 }
314               pos = pos + length;
315               break;
316             case type29ucd_SCDMA_SPREADING_INTERVAL:
317               if (length == 1)
318                 {
319                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_spreading_interval,
320                                        tvb, pos, length, FALSE);
321                 }
322               else
323                 {
324                   THROW (ReportedBoundsError);
325                 }
326               pos = pos + length;
327               break;
328             case type29ucd_SCDMA_CODES_PER_MINI_SLOT:
329               if (length == 1)
330                 {
331                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_codes_per_mini_slot,
332                                        tvb, pos, length, FALSE);
333                 }
334               else
335                 {
336                   THROW (ReportedBoundsError);
337                 }
338               pos = pos + length;
339               break;
340             case type29ucd_SCDMA_ACTIVE_CODES:
341               if (length == 1)
342                 {
343                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_active_codes,
344                                        tvb, pos, length, FALSE);
345                 }
346               else
347                 {
348                   THROW (ReportedBoundsError);
349                 }
350               pos = pos + length;
351               break;
352             case type29ucd_SCDMA_CODE_HOPPING_SEED:
353               if (length == 2)
354                 {
355                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_code_hopping_seed,
356                                        tvb, pos, length, FALSE);
357                 }
358               else
359                 {
360                   THROW (ReportedBoundsError);
361                 }
362               pos = pos + length;
363               break;
364             case type29ucd_SCDMA_US_RATIO_NUM:
365               if (length == 2)
366                 {
367                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_us_ratio_num,
368                                        tvb, pos, length, FALSE);
369                 }
370               else
371                 {
372                   THROW (ReportedBoundsError);
373                 }
374               pos = pos + length;
375               break;
376             case type29ucd_SCDMA_US_RATIO_DENOM:
377               if (length == 2)
378                 {
379                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_us_ratio_denom,
380                                        tvb, pos, length, FALSE);
381                 }
382               else
383                 {
384                   THROW (ReportedBoundsError);
385                 }
386               pos = pos + length;
387               break;
388             case type29ucd_SCDMA_TIMESTAMP_SNAPSHOT:
389               if (length == 9)
390                 {
391                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_scdma_timestamp_snapshot,
392                                        tvb, pos, length, FALSE);
393                 }
394               else
395                 {
396                   THROW (ReportedBoundsError);
397                 }
398               pos = pos + length;
399               break;
400             case type29ucd_MAINTAIN_POWER_SPECTRAL_DENSITY:
401               if (length == 1)
402                 {
403                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_maintain_power_spectral_density,
404                                        tvb, pos, length, FALSE);
405                 }
406               else
407                 {
408                   THROW (ReportedBoundsError);
409                 }
410               pos = pos + length;
411               break;
412             case type29ucd_RANGING_REQUIRED:
413               if (length == 1)
414                 {
415                   proto_tree_add_item (type29ucd_tree, hf_docsis_type29ucd_ranging_required,
416                                        tvb, pos, length, FALSE);
417                 }
418               else
419                 {
420                   THROW (ReportedBoundsError);
421                 }
422               pos = pos + length;
423               break;           
424 /* DOCSIS 1.1 BURST DESCRIPTOR */
425              case type29ucd_BURST_DESCR:
426               it =
427                 proto_tree_add_text (type29ucd_tree, tvb, pos, length,
428                                      "4 Burst Descriptor (Length = %u)",
429                                      length);
430               burst_descr_tree = proto_item_add_subtree (it, ett_burst_descr);
431               proto_tree_add_item (burst_descr_tree, hf_docsis_type29ucd_iuc, tvb,
432                                    pos++, 1, FALSE);
433               endtlvpos = pos + length - 1;
434               while (pos < endtlvpos)
435                 {
436                   tlvtype = tvb_get_guint8 (tvb, pos++);
437                   tlvlen = tvb_get_guint8 (tvb, pos++);
438                   switch (tlvtype)
439                     {
440                     case type29ucd_MODULATION:
441                       if (tlvlen == 1)
442                         {
443                           proto_tree_add_item (burst_descr_tree,
444                                                hf_docsis_burst_mod_type, tvb,
445                                                pos, tlvlen, FALSE);
446                         }
447                       else
448                         {
449                           THROW (ReportedBoundsError);
450                         }
451                       break;
452                     case type29ucd_DIFF_ENCODING:
453                       if (tlvlen == 1)
454                         {
455                           proto_tree_add_item (burst_descr_tree,
456                                                hf_docsis_burst_diff_encoding,
457                                                tvb, pos, tlvlen, FALSE);
458                         }
459                       else
460                         {
461                           THROW (ReportedBoundsError);
462                         }
463                       break;
464                     case type29ucd_PREAMBLE_LEN:
465                       if (tlvlen == 2)
466                         {
467                           proto_tree_add_item (burst_descr_tree,
468                                                hf_docsis_burst_preamble_len,
469                                                tvb, pos, tlvlen, FALSE);
470                         }
471                       else
472                         {
473                           THROW (ReportedBoundsError);
474                         }
475                       break;
476                     case type29ucd_PREAMBLE_VAL_OFF:
477                       if (tlvlen == 2)
478                         {
479                           proto_tree_add_item (burst_descr_tree,
480                                                hf_docsis_burst_preamble_val_off,
481                                                tvb, pos, tlvlen, FALSE);
482                         }
483                       else
484                         {
485                           THROW (ReportedBoundsError);
486                         }
487                       break;
488                     case type29ucd_FEC:
489                       if (tlvlen == 1)
490                         {
491                           proto_tree_add_item (burst_descr_tree,
492                                                hf_docsis_burst_fec, tvb, pos,
493                                                tlvlen, FALSE);
494                         }
495                       else
496                         {
497                           THROW (ReportedBoundsError);
498                         }
499                       break;
500                     case type29ucd_FEC_CODEWORD:
501                       if (tlvlen == 1)
502                         {
503                           proto_tree_add_item (burst_descr_tree,
504                                                hf_docsis_burst_fec_codeword,
505                                                tvb, pos, tlvlen, FALSE);
506                         }
507                       else
508                         {
509                           THROW (ReportedBoundsError);
510                         }
511                       break;
512                     case type29ucd_SCRAMBLER_SEED:
513                       if (tlvlen == 2)
514                         {
515                           proto_tree_add_item (burst_descr_tree,
516                                                hf_docsis_burst_scrambler_seed,
517                                                tvb, pos, tlvlen, FALSE);
518                         }
519                       else
520                         {
521                           THROW (ReportedBoundsError);
522                         }
523                       break;
524                     case type29ucd_MAX_BURST:
525                       if (tlvlen == 1)
526                         {
527                           proto_tree_add_item (burst_descr_tree,
528                                                hf_docsis_burst_max_burst, tvb,
529                                                pos, tlvlen, FALSE);
530                         }
531                       else
532                         {
533                           THROW (ReportedBoundsError);
534                         }
535                       break;
536                     case type29ucd_GUARD_TIME:
537                       if (tlvlen == 1)
538                         {
539                           proto_tree_add_item (burst_descr_tree,
540                                                hf_docsis_burst_guard_time,
541                                                tvb, pos, tlvlen, FALSE);
542                         }
543                       else
544                         {
545                           THROW (ReportedBoundsError);
546                         }
547                       break;
548                     case type29ucd_LAST_CW_LEN:
549                       if (tlvlen == 1)
550                         {
551                           proto_tree_add_item (burst_descr_tree,
552                                                hf_docsis_burst_last_cw_len,
553                                                tvb, pos, tlvlen, FALSE);
554                         }
555                       else
556                         {
557                           THROW (ReportedBoundsError);
558                         }
559                       break;
560                      case type29ucd_SCRAMBLER_ONOFF:
561                        if (tlvlen == 1)
562                          {
563                             proto_tree_add_item (burst_descr_tree,
564                                                  hf_docsis_burst_scrambler_onoff,
565                                                  tvb, pos, tlvlen, FALSE);
566                          }
567                        else
568                          {
569                             THROW (ReportedBoundsError);
570                          }
571                        break;
572                     }           /* switch(tlvtype) */
573                    pos = pos + tlvlen;
574                 }               /* while (pos < endtlvpos) */
575                break;
576 /* DOCSIS 2.0 Upstream Channel Descriptor */
577              case type29ucd_BURST_DESCR5:
578               it =
579                 proto_tree_add_text (type29ucd_tree, tvb, pos, length,
580                                      "5 Burst Descriptor (Length = %u)",
581                                      length);
582               burst_descr_tree = proto_item_add_subtree (it, ett_burst_descr);
583               proto_tree_add_item (burst_descr_tree, hf_docsis_type29ucd_iuc, tvb,
584                                    pos++, 1, FALSE);
585               endtlvpos = pos + length - 1;
586               while (pos < endtlvpos)
587                 {
588                   tlvtype = tvb_get_guint8 (tvb, pos++);
589                   tlvlen = tvb_get_guint8 (tvb, pos++);
590                   switch (tlvtype)
591                     {
592                     case type29ucd_MODULATION:
593                       if (tlvlen == 1)
594                         {
595                           proto_tree_add_item (burst_descr_tree,
596                                                hf_docsis_burst_mod_type, tvb,
597                                                pos, tlvlen, FALSE);
598                         }
599                       else
600                         {
601                           THROW (ReportedBoundsError);
602                         }
603                       break;
604                     case type29ucd_DIFF_ENCODING:
605                       if (tlvlen == 1)
606                         {
607                           proto_tree_add_item (burst_descr_tree,
608                                                hf_docsis_burst_diff_encoding,
609                                                tvb, pos, tlvlen, FALSE);
610                         }
611                       else
612                         {
613                           THROW (ReportedBoundsError);
614                         }
615                       break;
616                     case type29ucd_PREAMBLE_LEN:
617                       if (tlvlen == 2)
618                         {
619                           proto_tree_add_item (burst_descr_tree,
620                                                hf_docsis_burst_preamble_len,
621                                                tvb, pos, tlvlen, FALSE);
622                         }
623                       else
624                         {
625                           THROW (ReportedBoundsError);
626                         }
627                       break;
628                     case type29ucd_PREAMBLE_VAL_OFF:
629                       if (tlvlen == 2)
630                         {
631                           proto_tree_add_item (burst_descr_tree,
632                                                hf_docsis_burst_preamble_val_off,
633                                                tvb, pos, tlvlen, FALSE);
634                         }
635                       else
636                         {
637                           THROW (ReportedBoundsError);
638                         }
639                       break;
640                     case type29ucd_FEC:
641                       if (tlvlen == 1)
642                         {
643                           proto_tree_add_item (burst_descr_tree,
644                                                hf_docsis_burst_fec, tvb, pos,
645                                                tlvlen, FALSE);
646                         }
647                       else
648                         {
649                           THROW (ReportedBoundsError);
650                         }
651                       break;
652                     case type29ucd_FEC_CODEWORD:
653                       if (tlvlen == 1)
654                         {
655                           proto_tree_add_item (burst_descr_tree,
656                                                hf_docsis_burst_fec_codeword,
657                                                tvb, pos, tlvlen, FALSE);
658                         }
659                       else
660                         {
661                           THROW (ReportedBoundsError);
662                         }
663                       break;
664                     case type29ucd_SCRAMBLER_SEED:
665                       if (tlvlen == 2)
666                         {
667                           proto_tree_add_item (burst_descr_tree,
668                                                hf_docsis_burst_scrambler_seed,
669                                                tvb, pos, tlvlen, FALSE);
670                         }
671                       else
672                         {
673                           THROW (ReportedBoundsError);
674                         }
675                       break;
676                     case type29ucd_MAX_BURST:
677                       if (tlvlen == 1)
678                         {
679                           proto_tree_add_item (burst_descr_tree,
680                                                hf_docsis_burst_max_burst, tvb,
681                                                pos, tlvlen, FALSE);
682                         }
683                       else
684                         {
685                           THROW (ReportedBoundsError);
686                         }
687                       break;
688                     case type29ucd_GUARD_TIME:
689                       if (tlvlen == 1)
690                         {
691                           proto_tree_add_item (burst_descr_tree,
692                                                hf_docsis_burst_guard_time,
693                                                tvb, pos, tlvlen, FALSE);
694                         }
695                       else
696                         {
697                           THROW (ReportedBoundsError);
698                         }
699                       break;
700                     case type29ucd_LAST_CW_LEN:
701                       if (tlvlen == 1)
702                         {
703                           proto_tree_add_item (burst_descr_tree,
704                                                hf_docsis_burst_last_cw_len,
705                                                tvb, pos, tlvlen, FALSE);
706                         }
707                       else
708                         {
709                           THROW (ReportedBoundsError);
710                         }
711                       break;
712                     case type29ucd_SCRAMBLER_ONOFF:
713                       if (tlvlen == 1)
714                         {
715                           proto_tree_add_item (burst_descr_tree,
716                                                hf_docsis_burst_scrambler_onoff,
717                                                tvb, pos, tlvlen, FALSE);
718                         }
719                       else
720                         {
721                           THROW (ReportedBoundsError);
722                         }
723                       break;
724 /* New cases added for DOCSIS 2.0 US Physical Burst Descriptor TLV */
725 /* #define type29ucd_RS_INT_DEPTH 12
726  * #define type29ucd_RS_INT_BLOCK 13
727  * #define type29ucd_PREAMBLE_TYPE 14
728  * #define type29ucd_SCMDA_SCRAMBLER_ONOFF 15
729  * #define type29ucd_SCDMA_CODES_PER_SUBFRAME 16
730  * #define type29ucd_SCDMA_FRAMER_INT_STEP_SIZE 17
731  * #define type29ucd_TCM_ENABLED 18
732  */
733                      case type29ucd_RS_INT_DEPTH:
734                       if (tlvlen == 1)
735                         {
736                           proto_tree_add_item (burst_descr_tree,
737                                                hf_docsis_rs_int_depth,
738                                                tvb, pos, tlvlen, FALSE);
739                         }
740                       else
741                         {
742                           THROW (ReportedBoundsError);
743                         }
744                       break;
745                      case type29ucd_RS_INT_BLOCK:
746                       if (tlvlen == 2)
747                         {
748                           proto_tree_add_item (burst_descr_tree,
749                                                hf_docsis_rs_int_block,
750                                                tvb, pos, tlvlen, FALSE);
751                         }
752                       else
753                         {
754                           THROW (ReportedBoundsError);
755                         }
756                       break;
757                      case type29ucd_PREAMBLE_TYPE:
758                       if (tlvlen == 1)
759                         {
760                           proto_tree_add_item (burst_descr_tree,
761                                                hf_docsis_preamble_type,
762                                                tvb, pos, tlvlen, FALSE);
763                         }
764                       else
765                         {
766                           THROW (ReportedBoundsError);
767                         }
768                       break;
769                      case type29ucd_SCMDA_SCRAMBLER_ONOFF:
770                       if (tlvlen == 1)
771                         {
772                           proto_tree_add_item (burst_descr_tree,
773                                                hf_docsis_scdma_scrambler_onoff,
774                                                tvb, pos, tlvlen, FALSE);
775                         }
776                       else
777                         {
778                           THROW (ReportedBoundsError);
779                         }
780                       break;
781                      case type29ucd_SCDMA_CODES_PER_SUBFRAME:
782                       if (tlvlen == 1)
783                         {
784                           proto_tree_add_item (burst_descr_tree,
785                                                hf_docsis_scdma_codes_per_subframe,
786                                                tvb, pos, tlvlen, FALSE);
787                         }
788                       else
789                         {
790                           THROW (ReportedBoundsError);
791                         }
792                       break;
793                      case type29ucd_SCDMA_FRAMER_INT_STEP_SIZE:
794                       if (tlvlen == 1)
795                         {
796                           proto_tree_add_item (burst_descr_tree,
797                                                hf_docsis_scdma_framer_int_step_size,
798                                                tvb, pos, tlvlen, FALSE);
799                         }
800                       else
801                         {
802                           THROW (ReportedBoundsError);
803                         }
804                       break;
805                      case type29ucd_TCM_ENABLED:
806                       if (tlvlen == 1)
807                         {
808                           proto_tree_add_item (burst_descr_tree,
809                                                hf_docsis_tcm_enabled,
810                                                tvb, pos, tlvlen, FALSE);
811                         }
812                       else
813                         {
814                           THROW (ReportedBoundsError);
815                         }
816                       break;
817 /* End of DOCSIS 2.0 US burst Descriptor Changes */
818                     }           /* switch(tlvtype) */
819                   pos = pos + tlvlen;
820                 }               /* while (pos < endtlvpos) */
821               break;
822             }                   /* switch(type) */
823         }                       /* while (pos < len) */
824     }                           /* if (tree) */
825
826 }
827
828 /* Register the protocol with Ethereal */
829
830 /* this format is require because a script is used to build the C function
831    that calls all the protocol registration.
832 */
833
834
835 void
836 proto_register_docsis_type29ucd (void)
837 {
838
839 /* Setup list of header fields  See Section 1.6.1 for details*/
840   static hf_register_info hf[] = {
841     {&hf_docsis_type29ucd_upstream_chid,
842      {"Upstream Channel ID", "docsis.type29ucd.upchid",
843       FT_UINT8, BASE_DEC, NULL, 0x0,
844       "Upstream Channel ID", HFILL}
845      },
846     {&hf_docsis_type29ucd_config_ch_cnt,
847      {"Config Change Count", "docsis.type29ucd.confcngcnt",
848       FT_UINT8, BASE_DEC, NULL, 0x0,
849       "Configuration Change Count", HFILL}
850      },
851     {&hf_docsis_type29ucd_mini_slot_size,
852      {"Mini Slot Size (6.25us TimeTicks)", "docsis.type29ucd.mslotsize",
853       FT_UINT8, BASE_DEC, NULL, 0x0,
854       "Mini Slot Size (6.25us TimeTicks)", HFILL}
855      },
856     {&hf_docsis_type29ucd_down_chid,
857      {"Downstream Channel ID", "docsis.type29ucd.downchid",
858       FT_UINT8, BASE_DEC, NULL, 0x0,
859       "Management Message", HFILL}
860      },
861     {&hf_docsis_type29ucd_symbol_rate,
862      {"1 Symbol Rate (ksym/sec)", "docsis.type29ucd.symrate",
863       FT_UINT8, BASE_DEC, NULL, 0x0,
864       "Symbol Rate", HFILL}
865      },
866     {&hf_docsis_type29ucd_frequency,
867      {"2 Frequency (Hz)", "docsis.type29ucd.freq",
868       FT_UINT32, BASE_DEC, NULL, 0x0,
869       "Upstream Center Frequency", HFILL}
870      },
871     {&hf_docsis_type29ucd_preamble_pat,
872      {"3 Preamble Pattern", "docsis.type29ucd.preamble",
873       FT_BYTES, BASE_HEX, NULL, 0x0,
874       "Preamble Superstring", HFILL}
875      },
876     {&hf_docsis_type29ucd_iuc,
877      {"Interval Usage Code", "docsis.type29ucd.iuc",
878       FT_UINT8, BASE_DEC, VALS (iuc_vals2), 0x0,
879       "Interval Usage Code", HFILL}
880      },
881     {&hf_docsis_burst_mod_type,
882      {"1 Modulation Type", "docsis.type29ucd.burst.modtype",
883       FT_UINT8, BASE_DEC, VALS (mod_vals2), 0x0,
884       "Modulation Type", HFILL}
885      },
886     {&hf_docsis_burst_diff_encoding,
887      {"2 Differential Encoding", "docsis.type29ucd.burst.diffenc",
888       FT_UINT8, BASE_DEC, VALS (on_off_vals), 0x0,
889       "Differential Encoding", HFILL}
890      },
891     {&hf_docsis_burst_preamble_len,
892      {"3 Preamble Length (Bits)", "docsis.type29ucd.burst.preamble_len",
893       FT_UINT16, BASE_DEC, NULL, 0x0,
894       "Preamble Length (Bits)", HFILL}
895      },
896     {&hf_docsis_burst_preamble_val_off,
897      {"4 Preamble Offset (Bits)", "docsis.type29ucd.burst.preamble_off",
898       FT_UINT16, BASE_DEC, NULL, 0x0,
899       "Preamble Offset (Bits)", HFILL}
900      },
901     {&hf_docsis_burst_fec,
902      {"5 FEC (T)", "docsis.type29ucd.burst.fec",
903       FT_UINT8, BASE_DEC, NULL, 0x0,
904       "FEC (T) Codeword Parity Bits = 2^T", HFILL}
905      },
906     {&hf_docsis_burst_fec_codeword,
907      {"6 FEC Codeword Info bytes (k)", "docsis.type29ucd.burst.fec_codeword",
908       FT_UINT8, BASE_DEC, NULL, 0x0,
909       "FEC Codeword Info Bytes (k)", HFILL}
910      },
911     {&hf_docsis_burst_scrambler_seed,
912      {"7 Scrambler Seed", "docsis.type29ucd.burst.scrambler_seed",
913       FT_UINT16, BASE_HEX, NULL, 0x0,
914       "Burst Descriptor", HFILL}
915      },
916     {&hf_docsis_burst_max_burst,
917      {"8 Max Burst Size (Minislots)", "docsis.type29ucd.burst.maxburst",
918       FT_UINT8, BASE_DEC, NULL, 0x0,
919       "Max Burst Size (Minislots)", HFILL}
920      },
921     {&hf_docsis_burst_guard_time,
922      {"9 Guard Time Size (Symbol Times)", "docsis.type29ucd.burst.guardtime",
923       FT_UINT8, BASE_DEC, NULL, 0x0,
924       "Guard Time Size", HFILL}
925      },
926     {&hf_docsis_burst_last_cw_len,
927      {"10 Last Codeword Length", "docsis.type29ucd.burst.last_cw_len",
928       FT_UINT8, BASE_DEC, VALS (last_cw_len_vals), 0x0,
929       "Last Codeword Length", HFILL}
930      },
931     {&hf_docsis_burst_scrambler_onoff,
932      {"11 Scrambler On/Off", "docsis.type29ucd.burst.scrambleronoff",
933       FT_UINT8, BASE_DEC, VALS (on_off_vals), 0x0,
934       "Scrambler On/Off", HFILL}
935      },
936 /* DOCSIS 2.0 UCD TLV definitions
937  *  * #define type29ucd_EXT_PREAMBLE 6
938  *  * #define type29ucd_SCDMA_MODE_ENABLE 7
939  *  * #define type29ucd_SCDMA_SPREADING_INTERVAL 8
940  *  * #define type29ucd_SCDMA_CODES_PER_MINI_SLOT 9
941  *  * #define type29ucd_SCDMA_ACTIVE_CODES 10
942  *  * #define type29ucd_SCDMA_CODE_HOPPING_SEED 11
943  *  * #define type29ucd_SCDMA_US_RATIO_NUM 12
944  *  * #define type29ucd_SCDMA_US_RATIO_DENOM 13
945  *  * #define type29ucd_SCDMA_TIMESTAMP_SNAPSHOT 14
946  *  * #define type29ucd_MAINTAIN_POWER_SPECTRAL_DENSITY 15
947  *  * #define type29ucd_RANGING_REQUIRED 16
948  *  */
949     {&hf_docsis_type29ucd_ext_preamble,
950      {"6 Extended Preamble Pattern", "docsis.type29ucd.extpreamble",
951       FT_BYTES, BASE_HEX, NULL, 0x0,
952       "Extended Preamble Pattern", HFILL}
953      },
954     {&hf_docsis_type29ucd_scdma_mode_enable,
955      {"7 SCDMA Mode Enable", "docsis.type29ucd.scdmaenable",
956       FT_BYTES, BASE_HEX, NULL, 0x0,
957       "SCDMA Mode Enable", HFILL}
958      },
959     {&hf_docsis_type29ucd_scdma_spreading_interval,
960      {"8 SCDMA Spreading Interval", "docsis.type29ucd.scdmaspreadinginterval",
961       FT_BYTES, BASE_HEX, NULL, 0x0,
962       "SCDMA Spreading Interval", HFILL}
963      },
964     {&hf_docsis_type29ucd_scdma_codes_per_mini_slot,
965      {"9 SCDMA Codes per mini slot", "docsis.type29ucd.scdmacodesperminislot",
966       FT_BYTES, BASE_HEX, NULL, 0x0,
967       "SCDMA Codes per mini slot", HFILL}
968      },
969     {&hf_docsis_type29ucd_scdma_active_codes,
970      {"10 SCDMA Active Codes", "docsis.type29ucd.scdmaactivecodes",
971       FT_BYTES, BASE_HEX, NULL, 0x0,
972       "SCDMA Active Codes", HFILL}
973      },
974     {&hf_docsis_type29ucd_scdma_code_hopping_seed,
975      {"11 SCDMA Code Hopping Seed", "docsis.type29ucd.scdmacodehoppingseed",
976       FT_BYTES, BASE_HEX, NULL, 0x0,
977       "SCDMA Code Hopping Seed", HFILL}
978      },
979     {&hf_docsis_type29ucd_scdma_us_ratio_num,
980      {"12 SCDMA US Ratio Numerator", "docsis.type29ucd.scdmausrationum",
981       FT_BYTES, BASE_HEX, NULL, 0x0,
982       "SCDMA US Ratio Numerator", HFILL}
983      },
984     {&hf_docsis_type29ucd_scdma_us_ratio_denom,
985      {"13 SCDMA US Ratio Denominator", "docsis.type29ucd.scdmausratiodenom",
986       FT_BYTES, BASE_HEX, NULL, 0x0,
987       "SCDMA US Ratio Denominator", HFILL}
988      },
989     {&hf_docsis_type29ucd_scdma_timestamp_snapshot,
990      {"14 SCDMA Timestamp Snapshot", "docsis.type29ucd.scdmatimestamp",
991       FT_BYTES, BASE_HEX, NULL, 0x0,
992       "SCDMA Timestamp Snapshot", HFILL}
993      },
994     {&hf_docsis_type29ucd_maintain_power_spectral_density,
995      {"15 Maintain power spectral density", "docsis.type29ucd.maintainpowerspectraldensity",
996       FT_BYTES, BASE_HEX, NULL, 0x0,
997       "Maintain power spectral density", HFILL}
998      },
999     {&hf_docsis_type29ucd_ranging_required,
1000      {"16 Ranging Required", "docsis.type29ucd.rangingrequired",
1001       FT_BYTES, BASE_HEX, NULL, 0x0,
1002       "Ranging Required", HFILL}
1003      },
1004 /* #define type29ucd_RS_INT_DEPTH 12
1005  * #define type29ucd_RS_INT_BLOCK 13
1006  * #define type29ucd_PREAMBLE_TYPE 14
1007  * #define type29ucd_SCMDA_SCRAMBLER_ONOFF 15
1008  * #define type29ucd_SCDMA_CODES_PER_SUBFRAME 16
1009  * #define type29ucd_SCDMA_FRAMER_INT_STEP_SIZE 17
1010  * #define type29ucd_TCM_ENABLED 18
1011  */
1012     {&hf_docsis_rs_int_depth,
1013      {"12 Scrambler On/Off", "docsis.type29ucd.burst.rsintdepth",
1014       FT_UINT8, BASE_DEC, NULL, 0x0,
1015       "R-S Interleaver Depth", HFILL}
1016      },
1017     {&hf_docsis_rs_int_block,
1018      {"13 Scrambler On/Off", "docsis.type29ucd.burst.rsintblock",
1019       FT_UINT8, BASE_DEC, NULL, 0x0,
1020       "R-S Interleaver Block", HFILL}
1021      },
1022     {&hf_docsis_preamble_type,
1023      {"14 Scrambler On/Off", "docsis.type29ucd.burst.preambletype",
1024       FT_UINT8, BASE_DEC, NULL, 0x0,
1025       "Preamble Type", HFILL}
1026      },
1027     {&hf_docsis_scdma_scrambler_onoff,
1028      {"15 Scrambler On/Off", "docsis.type29ucd.burst.scdmascrambleronoff",
1029       FT_UINT8, BASE_DEC, VALS (on_off_vals), 0x0,
1030       "SCDMA Scrambler On/Off", HFILL}
1031      },
1032     {&hf_docsis_scdma_codes_per_subframe,
1033      {"16 Scrambler On/Off", "docsis.type29ucd.burst.scdmacodespersubframe",
1034       FT_UINT8, BASE_DEC, NULL, 0x0,
1035       "SCDMA Codes per Subframe", HFILL}
1036      },
1037     {&hf_docsis_scdma_framer_int_step_size,
1038      {"17 Scrambler On/Off", "docsis.type29ucd.burst.scdmaframerintstepsize",
1039       FT_UINT8, BASE_DEC, NULL, 0x0,
1040       "SCDMA Framer Interleaving Step Size", HFILL}
1041      },
1042     {&hf_docsis_tcm_enabled,
1043      {"18 Scrambler On/Off", "docsis.type29ucd.burst.tcmenabled",
1044       FT_UINT8, BASE_DEC, VALS (on_off_vals), 0x0,
1045       "TCM Enabled", HFILL}
1046      },
1047   };
1048
1049 /* Setup protocol subtree array */
1050   static gint *ett[] = {
1051     &ett_docsis_type29ucd,
1052     &ett_burst_descr,
1053   };
1054
1055 /* Register the protocol name and description */
1056   proto_docsis_type29ucd =
1057     proto_register_protocol ("DOCSIS Upstream Channel Descriptor Type 29",
1058                              "DOCSIS type29ucd", "docsis_type29ucd");
1059
1060 /* Required function calls to register the header fields and subtrees used */
1061   proto_register_field_array (proto_docsis_type29ucd, hf, array_length (hf));
1062   proto_register_subtree_array (ett, array_length (ett));
1063
1064   register_dissector ("docsis_type29ucd", dissect_type29ucd, proto_docsis_type29ucd);
1065 }
1066
1067
1068 /* If this dissector uses sub-dissector registration add a registration routine.
1069    This format is required because a script is used to find these routines and
1070    create the code that calls these routines.
1071 */
1072 void
1073 proto_reg_handoff_docsis_type29ucd (void)
1074 {
1075   dissector_handle_t docsis_type29ucd_handle;
1076
1077   docsis_type29ucd_handle = find_dissector ("docsis_type29ucd");
1078   dissector_add ("docsis_mgmt", 0x1D, docsis_type29ucd_handle);
1079
1080 }