From Yi Zhang:
[obnox/wireshark/wip.git] / plugins / docsis / packet-dcd.c
index 230adbc2d2bffa35d50ba1adfdf53bf2b015f2f9..7dec7e067580b5b986f126650b49482b9b2cf6d6 100644 (file)
 #include "config.h"
 #endif
 
-
-#include "moduleinfo.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <gmodule.h>
-
 #include <epan/packet.h>
 
 #define DCD_DOWN_CLASSIFIER 23
@@ -111,6 +102,7 @@ static int hf_docsis_dcd_cfr_tcpudp_dstport_end = -1;
 static int hf_docsis_dcd_rule_id = -1;
 static int hf_docsis_dcd_rule_pri = -1;
 static int hf_docsis_dcd_rule_ucid_list = -1;
+static int hf_docsis_dcd_clid_bcast_id = -1;
 static int hf_docsis_dcd_clid_known_mac_addr = -1;
 static int hf_docsis_dcd_clid_ca_sys_id = -1;
 static int hf_docsis_dcd_clid_app_id = -1;
@@ -156,7 +148,7 @@ dissect_dcd_dsg_cfg (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 4)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfg_chan, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -167,7 +159,7 @@ dissect_dcd_dsg_cfg (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfg_tdsg1, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_BIG_ENDIAN);
                }
               else 
                {
@@ -178,7 +170,7 @@ dissect_dcd_dsg_cfg (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfg_tdsg2, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_BIG_ENDIAN);
                }
               else 
                {
@@ -189,7 +181,7 @@ dissect_dcd_dsg_cfg (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfg_tdsg3, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_BIG_ENDIAN);
                }
               else 
                {
@@ -200,7 +192,7 @@ dissect_dcd_dsg_cfg (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfg_tdsg4, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_BIG_ENDIAN);
                }
               else 
                {
@@ -209,7 +201,7 @@ dissect_dcd_dsg_cfg (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              break;
            case DCD_CFG_VENDOR_SPEC:
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfg_vendor_spec, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_NA);
              break;
 
            }
@@ -239,7 +231,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 4)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_ip_source_addr, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -250,7 +242,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 4)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_ip_source_mask, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -261,7 +253,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 4)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_ip_dest_addr, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -272,7 +264,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 4)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_ip_dest_mask, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -283,7 +275,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_tcpudp_srcport_start, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -294,7 +286,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_tcpudp_srcport_end, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -305,7 +297,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_tcpudp_dstport_start, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -316,7 +308,7 @@ dissect_dcd_down_classifier_ip (tvbuff_t * tvb, proto_tree * tree, int start, gu
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_tcpudp_dstport_end, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -346,11 +338,21 @@ dissect_dcd_clid (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
        
        switch (type)
          {
+               case DCD_CLID_BCAST_ID:
+                       if (length == 2)
+                       {
+                               proto_tree_add_item(dcd_tree, hf_docsis_dcd_clid_bcast_id, tvb, pos, length, ENC_BIG_ENDIAN);
+                       }
+                       else
+                       {
+                               THROW (ReportedBoundsError);
+                       }
+                       break;
            case DCD_CLID_KNOWN_MAC_ADDR:
              if (length == 6)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_clid_known_mac_addr, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_NA);
                }
              else
                {
@@ -361,7 +363,7 @@ dissect_dcd_clid (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_clid_ca_sys_id, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -372,7 +374,7 @@ dissect_dcd_clid (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_clid_app_id, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -406,7 +408,7 @@ dissect_dcd_dsg_rule (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 1)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_rule_id, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -417,7 +419,7 @@ dissect_dcd_dsg_rule (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 1)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_rule_pri, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_BIG_ENDIAN);
                }
               else 
                {
@@ -426,7 +428,7 @@ dissect_dcd_dsg_rule (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              break;
            case DCD_RULE_UCID_RNG:
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_rule_ucid_list, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_NA);
              break;
            case DCD_RULE_CLIENT_ID:
              dissect_dcd_clid (tvb , dcd_tree , pos , length );
@@ -435,7 +437,7 @@ dissect_dcd_dsg_rule (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 6)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_rule_tunl_addr, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_NA);
                }
               else 
                {
@@ -446,7 +448,7 @@ dissect_dcd_dsg_rule (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_rule_cfr_id, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_BIG_ENDIAN);
                }
               else 
                {
@@ -455,7 +457,7 @@ dissect_dcd_dsg_rule (tvbuff_t * tvb, proto_tree * tree, int start, guint16 len)
              break;
            case DCD_RULE_VENDOR_SPEC:
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_rule_vendor_spec, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_NA);
              break;
 
            }
@@ -485,7 +487,7 @@ dissect_dcd_down_classifier (tvbuff_t * tvb, proto_tree * tree, int start, guint
              if (length == 2)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_id, tvb,
-                                      pos, length, FALSE);
+                                      pos, length, ENC_BIG_ENDIAN);
                }
              else
                {
@@ -496,7 +498,7 @@ dissect_dcd_down_classifier (tvbuff_t * tvb, proto_tree * tree, int start, guint
              if (length == 1)
                {
                  proto_tree_add_item (dcd_tree, hf_docsis_dcd_cfr_rule_pri, tvb,
-                                  pos, length, FALSE);
+                                  pos, length, ENC_BIG_ENDIAN);
                }
               else 
                {
@@ -522,11 +524,7 @@ dissect_dcd (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
 
   len = tvb_length_remaining (tvb, 0);
 
-  if (check_col (pinfo->cinfo, COL_INFO))
-    {
-      col_clear (pinfo->cinfo, COL_INFO);
-      col_add_fstr (pinfo->cinfo, COL_INFO,"DCD Message: ");
-    }
+  col_set_str(pinfo->cinfo, COL_INFO, "DCD Message: ");
 
   if (tree)
     {
@@ -535,9 +533,9 @@ dissect_dcd (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
                                        tvb_length_remaining (tvb, 0),
                                        "DCD Message");
       dcd_tree = proto_item_add_subtree (dcd_item, ett_docsis_dcd);
-      proto_tree_add_item (dcd_tree, hf_docsis_dcd_config_ch_cnt, tvb, 0, 1, FALSE);
-      proto_tree_add_item (dcd_tree, hf_docsis_dcd_num_of_frag, tvb, 1, 1, FALSE);
-      proto_tree_add_item (dcd_tree, hf_docsis_dcd_frag_sequence_num, tvb, 2, 1, FALSE);
+      proto_tree_add_item (dcd_tree, hf_docsis_dcd_config_ch_cnt, tvb, 0, 1, ENC_BIG_ENDIAN);
+      proto_tree_add_item (dcd_tree, hf_docsis_dcd_num_of_frag, tvb, 1, 1, ENC_BIG_ENDIAN);
+      proto_tree_add_item (dcd_tree, hf_docsis_dcd_frag_sequence_num, tvb, 2, 1, ENC_BIG_ENDIAN);
 
       pos = 3;
       while (pos < len)
@@ -717,11 +715,20 @@ proto_register_docsis_dcd (void)
       HFILL
       }
     },
+       {&hf_docsis_dcd_clid_bcast_id,
+               {
+                       "DSG Rule Client ID Broadcast ID",
+                       "docsis_dcd.clid_bcast_id",
+                       FT_UINT16, BASE_DEC, NULL, 0x0,
+                       NULL,
+                       HFILL
+               }
+       },
     {&hf_docsis_dcd_clid_known_mac_addr,
       {
       "DSG Rule Client ID Known MAC Address", 
       "docsis_dcd.clid_known_mac_addr",
-      FT_ETHER, BASE_DEC, NULL, 0x0,
+      FT_ETHER, BASE_NONE, NULL, 0x0,
       NULL, 
       HFILL
       }
@@ -748,7 +755,7 @@ proto_register_docsis_dcd (void)
       {
       "DSG Rule Tunnel MAC Address", 
       "docsis_dcd.rule_tunl_addr",
-      FT_ETHER, BASE_DEC, NULL, 0x0,
+      FT_ETHER, BASE_NONE, NULL, 0x0,
       NULL, 
       HFILL
       }
@@ -840,7 +847,7 @@ proto_register_docsis_dcd (void)
 
 /* Register the protocol name and description */
   proto_docsis_dcd =
-    proto_register_protocol ("DOCSIS Downstream Channel Descriptor ",
+    proto_register_protocol ("DOCSIS Downstream Channel Descriptor",
                             "DOCSIS DCD", "docsis_dcd");
 
 /* Required function calls to register the header fields and subtrees used */
@@ -861,6 +868,6 @@ proto_reg_handoff_docsis_dcd (void)
   dissector_handle_t docsis_dcd_handle;
 
   docsis_dcd_handle = find_dissector ("docsis_dcd");
-  dissector_add ("docsis_mgmt", 0x20, docsis_dcd_handle);
+  dissector_add_uint ("docsis_mgmt", 0x20, docsis_dcd_handle);
 
 }