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