From ToddS via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5299 :
[obnox/wireshark/wip.git] / plugins / docsis / packet-mdd.c
1 /* packet-mdd.c
2  * $Id$
3  * Routines for MDD Message dissection
4  * Copyright 2007, Bruno Verstuyft  <bruno.verstuyft@excentis.com>
5  *
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., 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 #include <epan/packet.h>
31
32
33 #define DOWNSTREAM_ACTIVE_CHANNEL_LIST 1
34 #define MAC_DOMAIN_DOWNSTREAM_SERVICE_GROUP 2
35 #define DOWNSTREAM_AMBIGUITY_RESOLUTION_FREQUENCY_LIST 3
36 #define RECEIVE_CHANNEL_PROFILE_REPORTING_CONTROL 4
37 #define IP_INITIALIZATION_PARAMETERS 5
38 #define EARLY_AUTHENTICATION_AND_ENCRYPTION 6
39 #define UPSTREAM_ACTIVE_CHANNEL_LIST 7
40 #define UPSTREAM_AMBIGUITY_RESOLUTION_CHANNEL_LIST 8
41 #define UPSTREAM_FREQUENCY_RANGE 9
42 #define SYMBOL_CLOCK_LOCKING_INDICATOR 10
43 #define CM_STATUS_EVENT_CONTROL 11
44 #define UPSTREAM_TRANSMIT_POWER_REPORTING 12
45 #define DSG_DA_TO_DSID_ASSOCIATION_ENTRY 13
46 #define CM_STATUS_EVENT_ENABLE_NON_CHANNEL_SPECIFIC_EVENTS 15
47
48 /*Downstream Active Channel List*/
49 #define DOWNSTREAM_ACTIVE_CHANNEL_LIST_CHANNEL_ID 1
50 #define DOWNSTREAM_ACTIVE_CHANNEL_LIST_FREQUENCY 2
51 #define DOWNSTREAM_ACTIVE_CHANNEL_LIST_MODULATION_ORDER_ANNEX 3
52 #define DOWNSTREAM_ACTIVE_CHANNEL_LIST_PRIMARY_CAPABLE 4
53 #define DOWNSTREAM_ACTIVE_CHANNEL_LIST_CM_STATUS_EVENT_ENABLE_BITMASK 5
54
55 /*Mac Domain Downstream Service Group*/
56 #define MAC_DOMAIN_DOWNSTREAM_SERVICE_GROUP_MD_DS_SG_IDENTIFIER 1
57 #define MAC_DOMAIN_DOWNSTREAM_SERVICE_GROUP_CHANNEL_IDS 2
58
59 /*Modulation Orders*/
60 #define QAM64 0
61 #define QAM256 1
62
63 /*Annexes*/
64 #define J83_ANNEX_A 0
65 #define J83_ANNEX_B 1
66 #define J83_ANNEX_C 2
67
68 /*Primary Capable*/
69 #define NOT_PRIMARY_CAPABLE 0
70 #define PRIMARY_CAPABLE 1
71
72 /*Receive Channel Profile Reporting Control*/
73 #define RCP_CENTER_FREQUENCY_SPACING 1
74 #define VERBOSE_RCP_REPORTING 2
75
76 /*Frequency spacing*/
77 #define ASSUME_6MHZ_CENTER_FREQUENCY_SPACING 0
78 #define ASSUME_8MHZ_CENTER_FREQUENCY_SPACING 1
79
80 /*Verbose RCP reporting*/
81 #define RCP_NO_VERBOSE_REPORTING 0
82 #define RCP_VERBOSE_REPORTING 1
83
84 /*Sub-TLVs for IP Initialization Parameters*/
85 #define IP_PROVISIONING_MODE 1
86 #define PRE_REGISTRATION_DSID 2
87
88 /*IP Provisioning Modes*/
89 #define IPv4_ONLY 0
90 #define IPv6_ONLY 1
91 #define IP_ALTERNATE 2
92 #define DUAL_STACK 3
93
94 /*Early authentication and encryption*/
95 #define EAE_DISABLED 0
96 #define EAE_ENABLED 1
97
98 /*Upstream Active Channel List*/
99 #define UPSTREAM_ACTIVE_CHANNEL_LIST_UPSTREAM_CHANNEL_ID 1
100 #define UPSTREAM_ACTIVE_CHANNEL_LIST_CM_STATUS_EVENT_ENABLE_BITMASK 2
101
102 /*Upstream Frequency Range*/
103 #define STANDARD_UPSTREAM_FREQUENCY_RANGE 0
104 #define EXTENDED_UPSTREAM_FREQUENCY_RANGE 1
105
106 /*Symbol Clock Locking Indicator*/
107 #define NOT_LOCKED_TO_MASTER_CLOCK 0
108 #define LOCKED_TO_MASTER_CLOCK 1
109
110 /*CM-STATUS Event Control */
111 #define EVENT_TYPE_CODE 1
112 #define MAXIMUM_EVENT_HOLDOFF_TIMER 2
113 #define MAXIMUM_NUMBER_OF_REPORTS_PER_EVENT 3
114
115 /*CM-STATUS Events*/
116 #define SECONDARY_CHANNEL_MDD_TIMEOUT 1
117 #define QAM_FEC_LOCK_FAILURE 2
118 #define SEQUENCE_OUT_OF_RANGE 3
119 #define MDD_RECOVERY 4
120 #define QAM_FEC_LOCK_RECOVERY 5
121 #define T4_TIMEOUT 6
122 #define T3_RETRIES_EXCEEDED 7
123 #define SUCCESFUL_RANGING_AFTER_T3_RETRIES_EXCEEDED 8
124 #define CM_OPERATING_ON_BATTERY_BACKUP 9
125 #define CM_RETURNED_TO_AC_POWER 10
126
127 /*Upstream Transmit Power Reporting*/
128 #define CM_DOESNT_REPORT_TRANSMIT_POWER 0
129 #define CM_REPORTS_TRANSMIT_POWER 1
130
131
132 /*Dsg DA to DSID association entry*/
133 #define DSG_DA_TO_DSID_ASSOCIATION_DA 1
134 #define DSG_DA_TO_DSID_ASSOCIATION_DSID 2
135
136
137
138
139 static const value_string J83_annex_vals[] = {
140         {J83_ANNEX_A, "J.83 Annex A"},
141         {J83_ANNEX_B, "J.83 Annex B"},
142         {J83_ANNEX_C, "J.83 Annex C"},
143         {0, NULL}
144 };
145
146
147 static const value_string modulation_order_vals[] = {
148         {QAM64, "64 QAM"},
149         {QAM256, "256 QAM"},
150         {0, NULL}
151 };
152
153 static const value_string primary_capable_vals[] = {
154         {NOT_PRIMARY_CAPABLE, "Channel is not primary-capable"},
155         {PRIMARY_CAPABLE, "channel is primary-capable"},
156         {0, NULL}
157 };
158
159
160 static const value_string mdd_tlv_vals[] = {
161          {DOWNSTREAM_ACTIVE_CHANNEL_LIST, "Downstream Active Channel List"},
162          {MAC_DOMAIN_DOWNSTREAM_SERVICE_GROUP, "Mac Domain Downstream Service Group"},
163          {DOWNSTREAM_AMBIGUITY_RESOLUTION_FREQUENCY_LIST, "Downstream Ambiguity Resolution Frequency List "},
164          {RECEIVE_CHANNEL_PROFILE_REPORTING_CONTROL , "Receive Channel Profile Reporting Control"},
165          {IP_INITIALIZATION_PARAMETERS , "IP Initialization Parameters"},
166          {EARLY_AUTHENTICATION_AND_ENCRYPTION , "Early Authentication and Encryption"},
167          {UPSTREAM_ACTIVE_CHANNEL_LIST , "Upstream Active Channel List"},
168          {UPSTREAM_AMBIGUITY_RESOLUTION_CHANNEL_LIST , "Upstream Ambiguity Resolution Channel List"},
169          {UPSTREAM_FREQUENCY_RANGE  , "Upstream Frequency Range"},
170          {SYMBOL_CLOCK_LOCKING_INDICATOR  , "Symbol Clock Locking Indicator"},
171          {CM_STATUS_EVENT_CONTROL  , "CM-STATUS Event Control"},
172          {UPSTREAM_TRANSMIT_POWER_REPORTING  , "Upstream Transmit Power Reporting"},
173          {DSG_DA_TO_DSID_ASSOCIATION_ENTRY  , "DSG DA-to-DSID Association Entry"},
174         {0, NULL}
175 };
176
177
178 static const value_string rpc_center_frequency_spacing_vals[] = {
179         {ASSUME_6MHZ_CENTER_FREQUENCY_SPACING  , "CM MUST report only Receive Channel Profiles assuming 6 MHz center frequency spacing"},
180         {ASSUME_8MHZ_CENTER_FREQUENCY_SPACING  , "CM MUST report only Receive Channel Profiles assuming 8 MHz center frequency spacing"},
181         {0, NULL}
182 };
183
184 static const value_string verbose_rpc_reporting_vals[] = {
185         {RCP_NO_VERBOSE_REPORTING  , "CM MUST NOT provide verbose reporting of all its Receive Channel Profile(s) (both standard profiles and manufacturers profiles)."},
186         {RCP_VERBOSE_REPORTING  , "CM MUST provide verbose reporting of Receive Channel Profile(s) (both standard profiles and manufacturers profiles)."},
187         {0, NULL}
188 };
189
190 static const value_string ip_provisioning_mode_vals[] = {
191         {IPv4_ONLY  , "IPv4 Only"},
192         {IPv6_ONLY , "IPv6 Only"},
193         {IP_ALTERNATE, "Alternate"},
194         {DUAL_STACK , "Dual Stack"},
195         {0, NULL}
196 };
197
198 static const value_string eae_vals[] = {
199         {EAE_DISABLED  , "early authentication and encryption disabled"},
200         {EAE_ENABLED , "early authentication and encryption enabled"},
201         {0, NULL}
202 };
203
204 static const value_string upstream_frequency_range_vals[] = {
205         {STANDARD_UPSTREAM_FREQUENCY_RANGE, "Standard Upstream Frequency Range"},
206         {EXTENDED_UPSTREAM_FREQUENCY_RANGE, "Extended Upstream Frequency Range"},
207         {0, NULL}
208 };
209
210 static const value_string symbol_clock_locking_indicator_vals[] = {
211         {NOT_LOCKED_TO_MASTER_CLOCK, "Symbol Clock is not locked to Master Clock"},
212         {LOCKED_TO_MASTER_CLOCK, "Symbol Clock is locked to Master Clock"},
213         {0, NULL}
214 };
215
216 static const value_string symbol_cm_status_event_vals[] = {
217         {SECONDARY_CHANNEL_MDD_TIMEOUT, "Secondary Channel MDD timeout"},
218         {QAM_FEC_LOCK_FAILURE, "Qam FEC Lock Failure"},
219         {SEQUENCE_OUT_OF_RANGE, "Sequence out of Range"},
220         {MDD_RECOVERY, "MDD Recovery"},
221         {QAM_FEC_LOCK_RECOVERY, "Qam FEC Lock Recovery"},
222         {T4_TIMEOUT, "T4 Timeout"},
223         {T3_RETRIES_EXCEEDED, "T3 Retries Exceeded"},
224         {SUCCESFUL_RANGING_AFTER_T3_RETRIES_EXCEEDED, "Successful ranging after T3 Retries Exceeded"},
225         {CM_OPERATING_ON_BATTERY_BACKUP, "CM Operating on Battery Backup"},
226         {CM_RETURNED_TO_AC_POWER, "CM Returned to AC Power"},
227         {0, NULL}
228 };
229
230 static const value_string upstream_transmit_power_reporting_vals[] = {
231         {CM_DOESNT_REPORT_TRANSMIT_POWER, "CM does not report transmit power in RNG-REQ, INIT-RNG-REQ, and B-INIT-RNG-REQ messages"},
232         {CM_REPORTS_TRANSMIT_POWER, "CM reports transmit power in RNG-REQ, INIT-RNG-REQ, and B-INIT-RNG-REQ messages"},
233         {0, NULL}
234 };
235
236
237
238 /* Initialize the protocol and registered fields */
239 static int proto_docsis_mdd = -1;
240 static int hf_docsis_mdd = -1;
241 static int hf_docsis_mdd_ccc = -1;
242 static int hf_docsis_mdd_number_of_fragments = -1;
243 static int hf_docsis_mdd_fragment_sequence_number = -1;
244 static int hf_docsis_mdd_current_channel_dcid = -1;
245
246 static int hf_docsis_mdd_downstream_active_channel_list_channel_id = -1;
247 static int hf_docsis_mdd_downstream_active_channel_list_frequency = -1;
248 static int hf_docsis_mdd_downstream_active_channel_list_annex = -1;
249 static int hf_docsis_mdd_downstream_active_channel_list_modulation_order = -1;
250 static int hf_docsis_mdd_downstream_active_channel_list_primary_capable = -1;
251
252 static int hf_docsis_mdd_cm_status_event_enable_bitmask_mdd_timeout = -1;
253 static int hf_docsis_mdd_cm_status_event_enable_bitmask_qam_fec_lock_failure = -1;
254 static int hf_docsis_mdd_cm_status_event_enable_bitmask_mdd_recovery = -1;
255 static int hf_docsis_mdd_cm_status_event_enable_bitmask_qam_fec_lock_recovery = -1;
256 static int hf_docsis_mdd_cm_status_event_enable_bitmask_t4_timeout = -1;
257 static int hf_docsis_mdd_cm_status_event_enable_bitmask_t3_retries_exceeded = -1;
258 static int hf_docsis_mdd_cm_status_event_enable_bitmask_successful_ranging_after_t3_retries_exceeded = -1;
259
260
261 static int hf_docsis_mdd_mac_domain_downstream_service_group_md_ds_sg_identifier = -1;
262 static int hf_docsis_mdd_mac_domain_downstream_service_group_channel_id = -1;
263
264 static int hf_docsis_mdd_downstream_ambiguity_resolution_frequency = -1;
265
266 static int hf_docsis_mdd_rpc_center_frequency_spacing = -1;
267 static int hf_docsis_mdd_verbose_rcp_reporting = -1;
268
269 static int hf_docsis_mdd_ip_provisioning_mode = -1;
270 static int hf_docsis_mdd_pre_registration_dsid = -1;
271
272 static int hf_docsis_mdd_early_authentication_and_encryption = -1;
273
274 static int hf_docsis_mdd_upstream_active_channel_list_upstream_channel_id = -1;
275
276 static int hf_docsis_mdd_upstream_ambiguity_resolution_channel_list_channel_id = -1;
277
278 static int hf_docsis_mdd_upstream_frequency_range = -1;
279
280 static int hf_docsis_mdd_symbol_clock_locking_indicator = -1;
281
282 static int hf_docsis_mdd_event_type = -1;
283
284 static int hf_docsis_mdd_maximum_event_holdoff_timer = -1;
285
286 static int hf_docsis_mdd_maximum_number_of_reports_per_event = -1;
287 static int hf_docsis_mdd_upstream_transmit_power_reporting = -1;
288
289 static int hf_docsis_mdd_dsg_da_to_dsid_association_da = -1;
290 static int hf_docsis_mdd_dsg_da_to_dsid_association_dsid = -1;
291
292 static int hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_sequence_out_of_range = -1;
293 static int hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_cm_operating_on_battery_backup = -1;
294 static int hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_cm_returned_to_ac_power = -1;
295
296
297 /* Initialize the subtree pointers */
298 static gint ett_docsis_mdd = -1;
299 static gint ett_tlv = -1;
300 static gint ett_sub_tlv = -1;
301
302 static void
303 dissect_mdd (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
304 {
305         proto_item *it;
306         proto_tree *mdd_tree;
307
308         int pos;
309         int subpos = 0;
310         gint len;
311         guint8 type, length;
312         guint8 subtype, sublength;
313         int i;
314
315         proto_item *tlv_item;
316         proto_tree *tlv_tree;
317
318         proto_item *tlv_sub_item;
319         proto_tree *tlv_sub_tree;
320         proto_item *text_item;
321
322
323         len = tvb_reported_length_remaining (tvb, 0);
324
325         col_set_str(pinfo->cinfo, COL_INFO, "MDD Message:");
326
327         if (tree)
328         {
329                 it = proto_tree_add_protocol_format (tree, proto_docsis_mdd, tvb, 0, -1,"MDD Message");
330                 mdd_tree = proto_item_add_subtree (it, ett_docsis_mdd);
331
332                 proto_tree_add_item (mdd_tree, hf_docsis_mdd_ccc, tvb, 0, 1, FALSE);
333                 proto_tree_add_item (mdd_tree, hf_docsis_mdd_number_of_fragments, tvb, 1, 1, FALSE);
334                 proto_tree_add_item (mdd_tree, hf_docsis_mdd_fragment_sequence_number, tvb, 2, 1, FALSE);
335                 proto_tree_add_item (mdd_tree, hf_docsis_mdd_current_channel_dcid, tvb, 3, 1, FALSE);
336
337                 /*TLVs...*/
338                 pos = 4;
339                 while (pos < len)
340                 {
341                         type = tvb_get_guint8 (tvb, pos);
342                         length = tvb_get_guint8 (tvb, pos + 1);
343                         tlv_item = proto_tree_add_text (mdd_tree, tvb, pos, length + 2,"%s", val_to_str(type, mdd_tlv_vals, "Unknown TLV (%u)"));
344                         tlv_tree = proto_item_add_subtree (tlv_item, ett_tlv);
345
346                         switch(type) {
347
348                                 case DOWNSTREAM_ACTIVE_CHANNEL_LIST:
349                                         subpos = pos + 2;
350                                         while (subpos < pos + length + 2) {
351                                                 subtype = tvb_get_guint8 (tvb, subpos);
352                                                 sublength = tvb_get_guint8 (tvb, subpos + 1);
353                                                 switch(subtype) {
354                                                         case DOWNSTREAM_ACTIVE_CHANNEL_LIST_CHANNEL_ID:
355                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_downstream_active_channel_list_channel_id, tvb, subpos + 2 , 1, FALSE);
356                                                                 break;
357                                                         case DOWNSTREAM_ACTIVE_CHANNEL_LIST_FREQUENCY:
358                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_downstream_active_channel_list_frequency, tvb, subpos + 2 , 4, FALSE);
359                                                                 break;
360                                                         case DOWNSTREAM_ACTIVE_CHANNEL_LIST_MODULATION_ORDER_ANNEX:
361                                                                 tlv_sub_item = proto_tree_add_text (tlv_tree, tvb, subpos + 2, 1, "Modulation Order/Annex");
362                                                                 tlv_sub_tree = proto_item_add_subtree (tlv_sub_item, ett_sub_tlv);
363                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_downstream_active_channel_list_modulation_order, tvb, subpos + 2 , 1, FALSE);
364                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_downstream_active_channel_list_annex, tvb, subpos + 2 , 1, FALSE);
365                                                                 break;
366                                                         case DOWNSTREAM_ACTIVE_CHANNEL_LIST_PRIMARY_CAPABLE:
367                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_downstream_active_channel_list_primary_capable, tvb, subpos + 2 , 1, FALSE);
368                                                                 break;
369                                                         case DOWNSTREAM_ACTIVE_CHANNEL_LIST_CM_STATUS_EVENT_ENABLE_BITMASK:
370                                                                 tlv_sub_item = proto_tree_add_text (tlv_tree, tvb, subpos + 2, 2, "CM-STATUS Event Enable Bitmask");
371                                                                 tlv_sub_tree = proto_item_add_subtree (tlv_sub_item, ett_sub_tlv);
372                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_cm_status_event_enable_bitmask_mdd_timeout, tvb, subpos + 2 , 2,FALSE);
373                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_cm_status_event_enable_bitmask_qam_fec_lock_failure, tvb, subpos + 2 , 2, FALSE);
374                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_cm_status_event_enable_bitmask_mdd_recovery, tvb, subpos + 2 , 2,FALSE);
375                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_cm_status_event_enable_bitmask_qam_fec_lock_recovery, tvb, subpos + 2 , 2, FALSE);
376                                                                 break;
377                                                 }
378                                                 subpos += sublength + 2;
379                                         }
380                                         break;
381                                 case MAC_DOMAIN_DOWNSTREAM_SERVICE_GROUP:
382                                         subpos = pos + 2;
383                                         while (subpos < pos + length + 2) {
384                                                 subtype = tvb_get_guint8 (tvb, subpos);
385                                                 sublength = tvb_get_guint8 (tvb, subpos + 1);
386                                                 switch(subtype) {
387                                                         case MAC_DOMAIN_DOWNSTREAM_SERVICE_GROUP_MD_DS_SG_IDENTIFIER:
388                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_mac_domain_downstream_service_group_md_ds_sg_identifier, tvb, subpos + 2 , 1, FALSE);
389                                                                 break;
390                                                         case MAC_DOMAIN_DOWNSTREAM_SERVICE_GROUP_CHANNEL_IDS:
391                                                                 for (i = 0; i < sublength; i++) {
392                                                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_mac_domain_downstream_service_group_channel_id, tvb, subpos + 2 + i , 1, FALSE);
393                                                                 }
394                                                                 break;
395                                                 }
396                                                 subpos += sublength + 2;
397                                         }
398                                         break;
399                                 case DOWNSTREAM_AMBIGUITY_RESOLUTION_FREQUENCY_LIST:
400                                         subpos = pos + 2;
401                                         for (i = 0; i < length; i+=4) {
402                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_downstream_ambiguity_resolution_frequency, tvb, subpos + i , 4, FALSE);
403                                         }
404                                         break;
405                                 case RECEIVE_CHANNEL_PROFILE_REPORTING_CONTROL:
406                                         subpos = pos + 2;
407                                         while (subpos < pos + length + 2) {
408                                                 subtype = tvb_get_guint8 (tvb, subpos);
409                                                 sublength = tvb_get_guint8 (tvb, subpos + 1);
410                                                 switch(subtype) {
411                                                         case RCP_CENTER_FREQUENCY_SPACING:
412                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_rpc_center_frequency_spacing, tvb, subpos + 2 , 1, FALSE);
413                                                                 break;
414                                                         case VERBOSE_RCP_REPORTING:
415                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_verbose_rcp_reporting, tvb, subpos + 2 , 1, FALSE);
416                                                                 break;
417                                                 }
418                                                 subpos += sublength + 2;
419                                         }
420                                         break;
421                                 case IP_INITIALIZATION_PARAMETERS:
422                                         subpos = pos + 2;
423                                         while (subpos < pos + length + 2) {
424                                                 subtype = tvb_get_guint8 (tvb, subpos);
425                                                 sublength = tvb_get_guint8 (tvb, subpos + 1);
426                                                 switch(subtype) {
427                                                         case IP_PROVISIONING_MODE:
428                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_ip_provisioning_mode, tvb, subpos + 2 , 1, FALSE);
429                                                                 break;
430                                                         case PRE_REGISTRATION_DSID:
431                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_pre_registration_dsid, tvb, subpos + 2 , 3, FALSE);
432                                                                 break;
433                                                 }
434                                                 subpos += sublength + 2;
435                                         }
436                                         break;
437                                 case EARLY_AUTHENTICATION_AND_ENCRYPTION:
438                                         subpos = pos + 2;
439                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_early_authentication_and_encryption, tvb, subpos, 1, FALSE);
440                                         break;
441                                 case UPSTREAM_ACTIVE_CHANNEL_LIST:
442                                         subpos = pos + 2;
443                                         while (subpos < pos + length + 2) {
444                                                 subtype = tvb_get_guint8 (tvb, subpos);
445                                                 sublength = tvb_get_guint8 (tvb, subpos + 1);
446                                                 switch(subtype) {
447                                                         case UPSTREAM_ACTIVE_CHANNEL_LIST_UPSTREAM_CHANNEL_ID:
448                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_upstream_active_channel_list_upstream_channel_id, tvb, subpos + 2 , 1, FALSE);
449                                                                 break;
450                                                         case UPSTREAM_ACTIVE_CHANNEL_LIST_CM_STATUS_EVENT_ENABLE_BITMASK:
451                                                                 tlv_sub_item = proto_tree_add_text (tlv_tree, tvb, subpos + 2, 2, "CM-STATUS Event Enable Bitmask");
452                                                                 tlv_sub_tree = proto_item_add_subtree (tlv_sub_item, ett_sub_tlv);
453                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_cm_status_event_enable_bitmask_t4_timeout, tvb, subpos + 2 , 2, FALSE);
454                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_cm_status_event_enable_bitmask_t3_retries_exceeded, tvb, subpos + 2 , 2, FALSE);
455                                                                 proto_tree_add_item (tlv_sub_tree, hf_docsis_mdd_cm_status_event_enable_bitmask_successful_ranging_after_t3_retries_exceeded, tvb, subpos + 2 , 2, FALSE);
456                                                                 break;
457                                                 }
458                                                 subpos += sublength + 2;
459                                         }
460                                         break;
461                                 case UPSTREAM_AMBIGUITY_RESOLUTION_CHANNEL_LIST:
462                                         sublength = tvb_get_guint8 (tvb, subpos + 1);
463                                         for (i = 0; i < sublength; i++) {
464                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_upstream_ambiguity_resolution_channel_list_channel_id, tvb, pos + 2 + i , 1, FALSE);
465                                         }
466                                         break;
467                                 case UPSTREAM_FREQUENCY_RANGE:
468                                         subpos = pos + 2;
469                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_upstream_frequency_range, tvb, subpos, 1, FALSE);
470                                         break;
471                                 case SYMBOL_CLOCK_LOCKING_INDICATOR:
472                                         subpos = pos + 2;
473                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_symbol_clock_locking_indicator, tvb, subpos, 1, FALSE);
474                                         break;
475                                 case CM_STATUS_EVENT_CONTROL:
476                                         subpos = pos + 2;
477                                         while (subpos < pos + length + 2) {
478                                                 subtype = tvb_get_guint8 (tvb, subpos);
479                                                 sublength = tvb_get_guint8 (tvb, subpos + 1);
480                                                 switch(subtype) {
481                                                         case EVENT_TYPE_CODE:
482                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_event_type, tvb, subpos+2, 1, FALSE);
483                                                                 break;
484                                                         case MAXIMUM_EVENT_HOLDOFF_TIMER:
485                                                                 text_item = proto_tree_add_item (tlv_tree, hf_docsis_mdd_maximum_event_holdoff_timer, tvb, subpos, 2, FALSE);
486                                                                 proto_item_append_text(text_item, " (%d ms)", (256*tvb_get_guint8 (tvb, subpos) + tvb_get_guint8 (tvb, subpos + 1)) * 20);
487                                                                 break;
488                                                         case MAXIMUM_NUMBER_OF_REPORTS_PER_EVENT:
489                                                                 text_item = proto_tree_add_item (tlv_tree, hf_docsis_mdd_maximum_number_of_reports_per_event, tvb, subpos, 1, FALSE);
490                                                                 if ( tvb_get_guint8 (tvb, subpos) == 0) {
491                                                                         proto_item_append_text(text_item, " (Unlimited)");
492                                                                 }
493                                                                 break;
494                                                 }
495                                                 subpos += sublength + 2;
496                                         }
497                                         break;
498                                 case UPSTREAM_TRANSMIT_POWER_REPORTING:
499                                         subpos = pos + 2;
500                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_upstream_transmit_power_reporting, tvb, subpos, 1, FALSE);
501                                         break;
502                                 case DSG_DA_TO_DSID_ASSOCIATION_ENTRY:
503                                         subpos = pos + 2;
504                                         while (subpos < pos + length + 2) {
505                                                 subtype = tvb_get_guint8 (tvb, subpos);
506                                                 sublength = tvb_get_guint8 (tvb, subpos + 1);
507                                                 switch(subtype) {
508                                                         case DSG_DA_TO_DSID_ASSOCIATION_DA:
509                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_dsg_da_to_dsid_association_da, tvb, subpos, 6, FALSE);
510                                                                 break;
511                                                         case DSG_DA_TO_DSID_ASSOCIATION_DSID:
512                                                                 proto_tree_add_item (tlv_tree, hf_docsis_mdd_dsg_da_to_dsid_association_dsid, tvb, subpos, 3, FALSE);
513                                                                 break;
514                                                 }
515                                                 subpos += sublength + 2;
516                                         }
517                                         break;
518                                 case CM_STATUS_EVENT_ENABLE_NON_CHANNEL_SPECIFIC_EVENTS:
519                                         subpos = pos + 2;
520                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_sequence_out_of_range, tvb, subpos + 2 , 2,FALSE);
521                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_cm_operating_on_battery_backup, tvb, subpos + 2 , 2,FALSE);
522                                         proto_tree_add_item (tlv_tree, hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_cm_returned_to_ac_power, tvb, subpos + 2 , 2,FALSE);
523                                         break;
524                         }
525                         pos += length + 2;
526                 }
527         }                               /* if(tree) */
528 }
529
530
531
532
533 /* Register the protocol with Wireshark */
534
535 /* this format is require because a script is used to build the C function
536    that calls all the protocol registration.
537 */
538
539
540 void proto_register_docsis_mdd (void)
541 {
542         /* Setup list of header fields  See Section 1.6.1 for details*/
543         static hf_register_info hf[] = {
544                 {&hf_docsis_mdd,
545                 {"Map Message", "docsis_mdd",
546                 FT_BYTES, BASE_NONE, NULL, 0x0,
547                 NULL, HFILL}
548                 },
549                 {&hf_docsis_mdd_ccc,
550                 {"Configuration Change Count", "docsis_mdd.ccc",
551                 FT_UINT8, BASE_DEC, NULL, 0x0,
552                 "Mdd Configuration Change Count", HFILL}
553                 },
554                 {&hf_docsis_mdd_number_of_fragments,
555                 {"Number of Fragments", "docsis_mdd.number_of_fragments",
556                 FT_UINT8, BASE_DEC, NULL, 0x0,
557                 "Mdd Number of Fragments", HFILL}
558                 },
559                 {&hf_docsis_mdd_fragment_sequence_number,
560                 {"Fragment Sequence Number", "docsis_mdd.fragment_sequence_number",
561                 FT_UINT8, BASE_DEC, NULL, 0x0,
562                 "Mdd Fragment Sequence Number", HFILL}
563                 },
564                 {&hf_docsis_mdd_current_channel_dcid,
565                 {"Current Channel DCID", "docsis_mdd.current_channel_dcid",
566                 FT_UINT8, BASE_DEC, NULL, 0x0,
567                 "Mdd Current Channel DCID", HFILL}
568                 },
569                 {&hf_docsis_mdd_downstream_active_channel_list_channel_id,
570                 {"Channel ID", "docsis_mdd.downstream_active_channel_list_channel_id",
571                 FT_UINT8, BASE_DEC, NULL, 0x0,
572                 "Mdd Downstream Active Channel List Channel ID", HFILL}
573                 },
574                 {&hf_docsis_mdd_downstream_active_channel_list_frequency,
575                 {"Frequency", "docsis_mdd.downstream_active_channel_list_frequency",
576                 FT_UINT32, BASE_DEC, NULL, 0x0,
577                 "Mdd Downstream Active Channel List Frequency", HFILL}
578                 },
579                 {&hf_docsis_mdd_downstream_active_channel_list_annex,
580                 {"Annex", "docsis_mdd.downstream_active_channel_list_annex",
581                 FT_UINT8, BASE_DEC, VALS(J83_annex_vals), 0xF0,
582                 "Mdd Downstream Active Channel List Annex", HFILL}
583                 },
584                 {&hf_docsis_mdd_downstream_active_channel_list_modulation_order,
585                 {"Modulation Order", "docsis_mdd.downstream_active_channel_list_modulation_order",
586                 FT_UINT8, BASE_DEC, VALS(modulation_order_vals), 0x0F,
587                 "Mdd Downstream Active Channel List Modulation Order", HFILL}
588                 },
589                 {&hf_docsis_mdd_downstream_active_channel_list_primary_capable,
590                 {"Primary Capable", "docsis_mdd.downstream_active_channel_list_primary_capable",
591                 FT_UINT8, BASE_DEC, VALS(primary_capable_vals), 0x0,
592                 "Mdd Downstream Active Channel List Primary Capable", HFILL}
593                 },
594                 {&hf_docsis_mdd_cm_status_event_enable_bitmask_mdd_timeout,
595                 {"MDD Timeout", "docsis_mdd.downstream_active_channel_list_mdd_timeout",
596                 FT_UINT16, BASE_DEC, NULL, 0x0002,
597                 "Mdd Downstream Active Channel List MDD Timeout", HFILL}
598                 },
599                 {&hf_docsis_mdd_cm_status_event_enable_bitmask_qam_fec_lock_failure,
600                 {"QAM/FEC Lock Failure", "docsis_mdd.cm_status_event_enable_bitmask_qam_fec_lock_failure",
601                 FT_UINT16, BASE_DEC, NULL, 0x0004,
602                 "Mdd Downstream Active Channel List QAM/FEC Lock Failure", HFILL}
603                 },
604                 {&hf_docsis_mdd_cm_status_event_enable_bitmask_mdd_recovery,
605                 {"MDD Recovery", "docsis_mdd.cm_status_event_enable_bitmask_mdd_recovery",
606                 FT_UINT16, BASE_DEC, NULL, 0x0010,
607                 "CM-STATUS event MDD Recovery", HFILL}
608                 },
609                 {&hf_docsis_mdd_cm_status_event_enable_bitmask_qam_fec_lock_recovery,
610                 {"QAM/FEC Lock Recovery", "docsis_mdd.cm_status_event_enable_bitmask_qam_fec_lock_recovery",
611                 FT_UINT16, BASE_DEC, NULL, 0x0020,
612                 "CM-STATUS event QAM/FEC Lock Recovery", HFILL}
613                 },
614                 {&hf_docsis_mdd_cm_status_event_enable_bitmask_t4_timeout,
615                 {"T4 timeout", "docsis_mdd.cm_status_event_enable_bitmask_t4_timeout",
616                 FT_UINT16, BASE_DEC, NULL, 0x0040,
617                 "CM-STATUS event T4 timeout", HFILL}
618                 },
619                 {&hf_docsis_mdd_cm_status_event_enable_bitmask_t3_retries_exceeded,
620                 {"T3 Retries Exceeded", "docsis_mdd.cm_status_event_enable_bitmask_t3_retries_exceeded",
621                 FT_UINT16, BASE_DEC, NULL, 0x0080,
622                 "CM-STATUS event T3 Retries Exceeded", HFILL}
623                 },
624                 {&hf_docsis_mdd_cm_status_event_enable_bitmask_successful_ranging_after_t3_retries_exceeded,
625                 {"Successful Ranging after T3 Retries Exceeded", "docsis_mdd.cm_status_event_enable_bitmask_successful_ranging_after_t3_retries_exceeded",
626                 FT_UINT16, BASE_DEC, NULL, 0x0100,
627                 "CM-STATUS event Successful Ranging after T3 Retries Exceeded", HFILL}
628                 },
629                 {&hf_docsis_mdd_mac_domain_downstream_service_group_channel_id,
630                 {"Channel Id", "docsis_mdd.mac_domain_downstream_service_group_channel_id",
631                 FT_UINT8, BASE_DEC, NULL, 0x0,
632                 "Mdd Mac Domain Downstream Service Group Channel Id", HFILL}
633                 },
634                 {&hf_docsis_mdd_mac_domain_downstream_service_group_md_ds_sg_identifier,
635                 {"MD-DS-SG Identifier", "docsis_mdd.mac_domain_downstream_service_group_md_ds_sg_identifier",
636                 FT_UINT8, BASE_DEC, NULL, 0x0,
637                 "Mdd Mac Domain Downstream Service Group MD-DS-SG Identifier", HFILL}
638                 },
639                 {&hf_docsis_mdd_downstream_ambiguity_resolution_frequency,
640                 {"Frequency", "docsis_mdd.downstream_ambiguity_resolution_frequency",
641                 FT_UINT32, BASE_DEC, NULL, 0x0,
642                 "Mdd Downstream Ambiguity Resolution frequency", HFILL}
643                 },
644                 {&hf_docsis_mdd_rpc_center_frequency_spacing,
645                 {"RPC Center Frequency Spacing", "docsis_mdd.rpc_center_frequency_spacing",
646                 FT_UINT8, BASE_DEC, VALS(rpc_center_frequency_spacing_vals), 0x0,
647                 "Mdd RPC Center Frequency Spacing", HFILL}
648                 },
649                 {&hf_docsis_mdd_verbose_rcp_reporting,
650                 {"Verbose RCP reporting", "docsis_mdd.verbose_rpc_reporting",
651                 FT_UINT8, BASE_DEC, VALS(verbose_rpc_reporting_vals), 0x0,
652                 "Mdd Verbose RPC Reporting", HFILL}
653                 },
654                 {&hf_docsis_mdd_ip_provisioning_mode,
655                 {"IP Provisioning Mode", "docsis_mdd.ip_provisioning_mode",
656                 FT_UINT8, BASE_DEC, VALS(ip_provisioning_mode_vals), 0x0,
657                 "Mdd IP Provisioning Mode", HFILL}
658                 },
659                 {&hf_docsis_mdd_pre_registration_dsid,
660                 {"Pre-registration DSID", "docsis_mdd.pre_registration_dsid",
661                 FT_UINT24, BASE_DEC, NULL, 0x0FFFFF,
662                 "Mdd Pre-registration DSID", HFILL}
663                 },
664                 {&hf_docsis_mdd_early_authentication_and_encryption,
665                 {"Early Authentication and Encryption", "docsis_mdd.early_authentication_and_encryption",
666                 FT_UINT8, BASE_DEC, VALS(eae_vals), 0x0,
667                 "Mdd Early Authentication and Encryption", HFILL}
668                 },
669                 {&hf_docsis_mdd_upstream_active_channel_list_upstream_channel_id,
670                 {"Upstream Channel Id", "docsis_mdd.upstream_active_channel_list_upstream_channel_id",
671                 FT_UINT8, BASE_DEC, NULL, 0x0,
672                 "Mdd Upstream Active Channel List Upstream Channel Id", HFILL}
673                 },
674                 {&hf_docsis_mdd_upstream_ambiguity_resolution_channel_list_channel_id,
675                 {"Channel Id", "docsis_mdd.upstream_ambiguity_resolution_channel_list_channel_id",
676                 FT_UINT8, BASE_DEC, NULL, 0x0,
677                 "Mdd Mac Domain Upstream Ambiguity Resolution Channel List Channel Id", HFILL}
678                 },
679                 {&hf_docsis_mdd_upstream_frequency_range,
680                 {"Upstream Frequency Range", "docsis_mdd.upstream_frequency_range",
681                 FT_UINT8, BASE_DEC, VALS(upstream_frequency_range_vals), 0x0,
682                 "Mdd Upstream Frequency Range", HFILL}
683                 },
684                 {&hf_docsis_mdd_symbol_clock_locking_indicator,
685                 {"Symbol Clock Locking Indicator", "docsis_mdd.symbol_clock_locking_indicator",
686                 FT_UINT8, BASE_DEC, VALS(symbol_clock_locking_indicator_vals), 0x0,
687                 "Mdd Symbol Clock Locking Indicator", HFILL}
688                 },
689                 {&hf_docsis_mdd_event_type,
690                 {"Event Type", "docsis_mdd.event_type",
691                 FT_UINT8, BASE_DEC, VALS(symbol_cm_status_event_vals), 0x0,
692                 "Mdd CM-STATUS Event Type", HFILL}
693                 },
694                 {&hf_docsis_mdd_maximum_event_holdoff_timer,
695                 {"Maximum Event Holdoff Timer (units of 20 ms)", "docsis_mdd.maximum_event_holdoff_timer",
696                 FT_UINT16, BASE_DEC, NULL, 0x0,
697                 "Mdd Maximum Event Holdoff Timer", HFILL}
698                 },
699                 {&hf_docsis_mdd_maximum_number_of_reports_per_event,
700                 {"Maximum Number of Reports per Event", "docsis_mdd.maximum_number_of_reports_per_event",
701                 FT_UINT8, BASE_DEC, NULL, 0x0,
702                 "Mdd Maximum Number of Reports per Event", HFILL}
703                 },
704                 {&hf_docsis_mdd_upstream_transmit_power_reporting,
705                 {"Upstream Transmit Power Reporting", "docsis_mdd.upstream_transmit_power_reporting",
706                 FT_UINT8, BASE_DEC, VALS(upstream_transmit_power_reporting_vals), 0x0,
707                 "Mdd Upstream Transmit Power Reporting", HFILL}
708                 },
709                 {&hf_docsis_mdd_dsg_da_to_dsid_association_da,
710                 {"Destination Address", "docsis_mdd.dsg_da_to_dsid_association_da",
711                 FT_UINT8, BASE_HEX, NULL, 0x0,
712                 "Mdd DSG DA to DSID association Destination Address", HFILL}
713                 },
714                 {&hf_docsis_mdd_dsg_da_to_dsid_association_dsid,
715                 {"DSID", "docsis_mdd.dsg_da_to_dsid_association_dsid",
716                 FT_UINT24, BASE_DEC, NULL, 0x0FFFFF,
717                 "Mdd Mdd DSG DA to DSID association DSID", HFILL}
718                 },
719                 {&hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_sequence_out_of_range,
720                 {"Sequence out of range", "docsis_mdd.cm_status_event_enable_non_channel_specific_events_sequence_out_of_range",
721                 FT_UINT16, BASE_DEC, NULL, 0x0008,
722                 "CM-STATUS event non-channel-event Sequence out of range", HFILL}
723                 },
724                 {&hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_cm_operating_on_battery_backup,
725                 {"CM operating on battery backup", "docsis_mdd.cm_status_event_enable_non_channel_specific_events_cm_operating_on_battery_backup",
726                 FT_UINT16, BASE_DEC, NULL, 0x0200,
727                 "CM-STATUS event non-channel-event Cm operating on battery backup", HFILL}
728                 },
729                 {&hf_docsis_mdd_cm_status_event_enable_non_channel_specific_events_cm_returned_to_ac_power,
730                 {"Returned to AC power", "docsis_mdd.cm_status_event_enable_non_channel_specific_events_cm_returned_to_ac_power",
731                 FT_UINT16, BASE_DEC, NULL, 0x0400,
732                 "CM-STATUS event non-channel-event Cm returned to AC power", HFILL}
733                 },
734         };
735
736         /* Setup protocol subtree array */
737         static gint *ett[] = {
738                 &ett_docsis_mdd,
739                 &ett_tlv,
740                 &ett_sub_tlv
741         };
742
743         /* Register the protocol name and description */
744         proto_docsis_mdd =
745                 proto_register_protocol ("DOCSIS Mac Domain Description",
746                                         "DOCSIS Mdd", "docsis_mdd");
747
748         /* Required function calls to register the header fields and subtrees used */
749         proto_register_field_array (proto_docsis_mdd, hf, array_length (hf));
750         proto_register_subtree_array (ett, array_length (ett));
751
752         register_dissector ("docsis_mdd", dissect_mdd, proto_docsis_mdd);
753 }
754
755
756 /* If this dissector uses sub-dissector registration add a registration routine.
757    This format is required because a script is used to find these routines and
758    create the code that calls these routines.
759 */
760 void
761 proto_reg_handoff_docsis_mdd (void)
762 {
763         dissector_handle_t docsis_mdd_handle;
764
765         docsis_mdd_handle = find_dissector ("docsis_mdd");
766         dissector_add ("docsis_mgmt", 33, docsis_mdd_handle);
767 }