Remove a bunch of duplicate semicolons.
[obnox/wireshark/wip.git] / packet-mtp3.c
index 5edf6cfacdcc88e328f6c9069418ffc2a9a4548c..1c1c0e4501e87192a98c0a335f797facc0568244 100644 (file)
@@ -1,9 +1,15 @@
 /* packet-mtp3.c
  * Routines for Message Transfer Part Level 3 dissection
- * Copyright 2001, Michael Tuexen <Michael.Tuexen@icn.siemens.de>
- * Updated for ANSI support by Jeff Morriss <jeff.morriss[AT]ulticom.com>
  *
- * $Id: packet-mtp3.c,v 1.14 2003/01/28 23:56:39 guy Exp $
+ * It is (hopefully) compliant to:
+ *   ANSI T1.111.4-1996
+ *   ITU-T Q.704 7/1996
+ *   GF 001-9001 (Chinese ITU variant)
+ *
+ * Copyright 2001, Michael Tuexen <tuexen [AT] fh-muenster.de>
+ * Updated for ANSI and Chinese ITU support by Jeff Morriss <jeff.morriss[AT]ulticom.com>
+ *
+ * $Id: packet-mtp3.c,v 1.22 2003/09/06 00:03:23 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -49,17 +55,20 @@ static int hf_mtp3_itu_spare = -1;
 static int hf_mtp3_ansi_priority = -1;
 static int hf_mtp3_itu_opc = -1;
 static int hf_mtp3_ansi_opc = -1;
+static int hf_mtp3_chinese_opc = -1;
 static int hf_mtp3_opc_network = -1;
 static int hf_mtp3_opc_cluster = -1;
 static int hf_mtp3_opc_member = -1;
 static int hf_mtp3_itu_dpc = -1;
 static int hf_mtp3_ansi_dpc = -1;
+static int hf_mtp3_chinese_dpc = -1;
 static int hf_mtp3_dpc_network = -1;
 static int hf_mtp3_dpc_cluster = -1;
 static int hf_mtp3_dpc_member = -1;
 static int hf_mtp3_itu_sls = -1;
 static int hf_mtp3_ansi_5_bit_sls = -1;
 static int hf_mtp3_ansi_8_bit_sls = -1;
+static int hf_mtp3_chinese_itu_sls = -1;
 
 /* Initialize the subtree pointers */
 static gint ett_mtp3 = -1;
@@ -73,7 +82,7 @@ static dissector_table_t mtp3_sio_dissector_table;
 #include <packet-mtp3.h>
 Standard_Type mtp3_standard = ITU_STANDARD;
 
-gboolean mtp3_use_ansi_5_bit_sls = FALSE;
+static gboolean mtp3_use_ansi_5_bit_sls = FALSE;
 
 #define SIO_LENGTH                1
 
@@ -109,6 +118,7 @@ gboolean mtp3_use_ansi_5_bit_sls = FALSE;
 #define ANSI_MEMBER_MASK               0xFF0000
 #define ANSI_5BIT_SLS_MASK             0x1F
 #define ANSI_8BIT_SLS_MASK             0xFF
+#define CHINESE_ITU_SLS_MASK           0xF
 
 static const value_string service_indicator_code_vals[] = {
        { 0x0,  "Signalling Network Management Message (SNM)" },
@@ -161,6 +171,7 @@ dissect_mtp3_sio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *mtp3_tree)
                        SIO_LENGTH, sio);
     break;
   case ITU_STANDARD:
+  case CHINESE_ITU_STANDARD:
     proto_tree_add_uint(sio_tree, hf_mtp3_itu_spare, tvb, SIO_OFFSET,
                        SIO_LENGTH, sio);
     break;
@@ -181,6 +192,9 @@ dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
   proto_item *label_item, *label_dpc_item, *label_opc_item;
   proto_tree *label_tree, *label_dpc_tree, *label_opc_tree;
   char pc[ANSI_PC_STRING_LENGTH];
+  int *hf_dpc_string;
+  int *hf_opc_string;
+
 
   switch (mtp3_standard) {
   case ITU_STANDARD:
@@ -189,7 +203,7 @@ dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
     label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
 
     label = tvb_get_letohl(tvb, ITU_ROUTING_LABEL_OFFSET);
-    sls   = tvb_get_guint8(tvb, ITU_ROUTING_LABEL_OFFSET);
+    sls   = tvb_get_guint8(tvb, ITU_SLS_OFFSET);
 
     proto_tree_add_uint(label_tree, hf_mtp3_itu_dpc, tvb,
                        ITU_ROUTING_LABEL_OFFSET, ITU_ROUTING_LABEL_LENGTH,
@@ -202,27 +216,29 @@ dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
     break;
 
   case ANSI_STANDARD:
+  case CHINESE_ITU_STANDARD:
+    if (mtp3_standard == ANSI_STANDARD)
+    {
+      hf_dpc_string = &hf_mtp3_ansi_dpc;
+      hf_opc_string = &hf_mtp3_ansi_opc;
+    } else /* CHINESE_ITU_STANDARD */ {
+      hf_dpc_string = &hf_mtp3_chinese_dpc;
+      hf_opc_string = &hf_mtp3_chinese_opc;
+    }
+
     /* Create the Routing Label Tree */
     label_item = proto_tree_add_text(mtp3_tree, tvb, ANSI_ROUTING_LABEL_OFFSET,
                                     ANSI_ROUTING_LABEL_LENGTH,
                                     "Routing label");
     label_tree = proto_item_add_subtree(label_item, ett_mtp3_label);
 
-    /* SLS */
-    if (mtp3_use_ansi_5_bit_sls)
-      proto_tree_add_item(label_tree, hf_mtp3_ansi_5_bit_sls, tvb,
-                         ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
-    else
-      proto_tree_add_item(label_tree, hf_mtp3_ansi_8_bit_sls, tvb,
-                         ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
-
     /* create the DPC tree */
     dpc = tvb_get_ntoh24(tvb, ANSI_DPC_OFFSET);
     snprintf(pc, sizeof(pc), "%d-%d-%d", (dpc & ANSI_NETWORK_MASK),
                                         ((dpc & ANSI_CLUSTER_MASK) >> 8),
                                         ((dpc & ANSI_MEMBER_MASK) >> 16));
 
-    label_dpc_item = proto_tree_add_string_format(label_tree, hf_mtp3_ansi_dpc,
+    label_dpc_item = proto_tree_add_string_format(label_tree, *hf_dpc_string,
                                                  tvb, ANSI_DPC_OFFSET,
                                                  ANSI_PC_LENGTH, pc,
                                                  "DPC (%s)", pc);
@@ -244,7 +260,7 @@ dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
     snprintf(pc, sizeof(pc), "%d-%d-%d", (opc & ANSI_NETWORK_MASK),
                                         ((opc & ANSI_CLUSTER_MASK) >> 8),
                                         ((opc & ANSI_MEMBER_MASK) >> 16));
-    label_opc_item = proto_tree_add_string_format(label_tree, hf_mtp3_ansi_opc,
+    label_opc_item = proto_tree_add_string_format(label_tree, *hf_opc_string,
                                                  tvb, ANSI_OPC_OFFSET,
                                                  ANSI_PC_LENGTH, pc,
                                                  "OPC (%s)", pc);
@@ -260,6 +276,21 @@ dissect_mtp3_routing_label(tvbuff_t *tvb, proto_tree *mtp3_tree)
     proto_tree_add_uint(label_opc_tree, hf_mtp3_opc_network,tvb,
                        ANSI_OPC_OFFSET + ANSI_NETWORK_OFFSET, ANSI_NCM_LENGTH,
                        opc);
+
+    /* SLS */
+    if (mtp3_standard == ANSI_STANDARD)
+    {
+       if (mtp3_use_ansi_5_bit_sls)
+           proto_tree_add_item(label_tree, hf_mtp3_ansi_5_bit_sls, tvb,
+                               ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
+       else
+           proto_tree_add_item(label_tree, hf_mtp3_ansi_8_bit_sls, tvb,
+                               ANSI_SLS_OFFSET, ANSI_SLS_LENGTH, TRUE);
+    } else /* CHINESE_ITU_STANDARD */ {
+       proto_tree_add_item(label_tree, hf_mtp3_chinese_itu_sls, tvb,
+                           ANSI_SLS_OFFSET, ITU_SLS_LENGTH, FALSE);
+    }
+
     break;
   }
 }
@@ -279,16 +310,17 @@ dissect_mtp3_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     payload_tvb = tvb_new_subset(tvb, ITU_MTP_PAYLOAD_OFFSET, -1, -1);
     break;
   case ANSI_STANDARD:
+  case CHINESE_ITU_STANDARD:
     payload_tvb = tvb_new_subset(tvb, ANSI_MTP_PAYLOAD_OFFSET, -1, -1);
     break;
   }
 
+  if (check_col(pinfo->cinfo, COL_INFO))
+      col_set_str(pinfo->cinfo, COL_INFO, "DATA ");
+
   if (!dissector_try_port(mtp3_sio_dissector_table, service_indicator,
-                         payload_tvb, pinfo, tree)) {
+                         payload_tvb, pinfo, tree))
     call_dissector(data_handle, payload_tvb, pinfo, tree);
-    if (check_col(pinfo->cinfo, COL_INFO))
-      col_append_str(pinfo->cinfo, COL_INFO, "DATA ");
-  }
 }
 
 /* Code to actually dissect the packets */
@@ -300,9 +332,19 @@ dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
   proto_item *mtp3_item = NULL;
   proto_tree *mtp3_tree = NULL;
 
-  /* Make entries in Protocol column and Info column on summary display */
+  /* Make entries in Protocol column on summary display */
   if (check_col(pinfo->cinfo, COL_PROTOCOL))
-    col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3");
+    switch(mtp3_standard) {
+      case ITU_STANDARD:
+        col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Int. ITU)");
+        break;
+      case ANSI_STANDARD:
+        col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (ANSI)");
+        break;
+      case CHINESE_ITU_STANDARD:
+        col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP3 (Chin. ITU)");
+        break;
+    };      
 
   if (tree) {
     /* create display subtree for the protocol */
@@ -312,6 +354,7 @@ dissect_mtp3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                      ITU_HEADER_LENGTH, TRUE);
       break;
     case ANSI_STANDARD:
+    case CHINESE_ITU_STANDARD:
       mtp3_item = proto_tree_add_item(tree, proto_mtp3, tvb, 0,
                                      ANSI_HEADER_LENGTH, TRUE);
       break;
@@ -357,6 +400,10 @@ proto_register_mtp3(void)
       { "DPC", "mtp3.ansi_opc",
              FT_STRING, BASE_NONE, NULL, 0x0,
              "", HFILL }},
+    { &hf_mtp3_chinese_opc,
+      { "DPC", "mtp3.chinese_opc",
+             FT_STRING, BASE_NONE, NULL, 0x0,
+             "", HFILL }},
     { &hf_mtp3_opc_network,
      { "OPC Network", "mtp3.opc.network",
             FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
@@ -377,6 +424,10 @@ proto_register_mtp3(void)
       { "DPC", "mtp3.ansi_dpc",
              FT_STRING, BASE_NONE, NULL, 0x0,
              "", HFILL }},
+    { &hf_mtp3_chinese_dpc,
+      { "DPC", "mtp3.chinese_dpc",
+             FT_STRING, BASE_NONE, NULL, 0x0,
+             "", HFILL }},
     { &hf_mtp3_dpc_network,
       { "DPC Network", "mtp3.dpc.network",
              FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
@@ -400,6 +451,10 @@ proto_register_mtp3(void)
     { &hf_mtp3_ansi_8_bit_sls,
       { "Signalling Link Selector", "mtp3.sls",
              FT_UINT8, BASE_DEC, NULL, ANSI_8BIT_SLS_MASK,
+             "", HFILL }},
+    { &hf_mtp3_chinese_itu_sls,
+      { "Signalling Link Selector", "mtp3.sls",
+             FT_UINT8, BASE_DEC, NULL, CHINESE_ITU_SLS_MASK,
              "", HFILL }}
   };
 
@@ -413,8 +468,9 @@ proto_register_mtp3(void)
   };
 
   static enum_val_t mtp3_options[] = {
-    { "ITU",  ITU_STANDARD },
-    { "ANSI", ANSI_STANDARD },
+    { "ITU",         ITU_STANDARD },
+    { "ANSI",        ANSI_STANDARD },
+    { "Chinese ITU", CHINESE_ITU_STANDARD },
     { NULL, 0 }
   };