Use tvb accessors rather than directly accessing tvb struct.
[obnox/wireshark/wip.git] / asn1 / gsm_map / packet-gsm_map-template.c
index 0e5389c9d9a6876020c9f1bc0334c4b949b71f16..2ae8f3b45d082bbbd2501cabe2560d2c177e52c7 100644 (file)
@@ -139,6 +139,7 @@ static int hf_gsm_map_ie_tag = -1;
 static int hf_gsm_map_len = -1;
 static int hf_gsm_map_disc_par = -1;
 static int hf_gsm_map_dlci = -1;
+static int hf_gsm_apn_str = -1;
 
 #include "packet-gsm_map-hf.c"
 
@@ -165,6 +166,7 @@ static gint ett_gsm_map_externalsignalinfo = -1;
 static gint ett_gsm_map_cbs_data_coding = -1;
 static gint ett_gsm_map_GlobalCellId = -1;
 static gint ett_gsm_map_GeographicalInformation = -1;
+static gint ett_gsm_map_apn_str = -1;
 
 #include "packet-gsm_map-ett.c"
 
@@ -173,7 +175,9 @@ static dissector_handle_t   data_handle;
 static dissector_handle_t      ranap_handle;
 static dissector_handle_t      dtap_handle;
 static dissector_handle_t      map_handle;
-
+static dissector_table_t       map_prop_arg_opcode_table; /* prorietary operation codes */
+static dissector_table_t       map_prop_res_opcode_table; /* prorietary operation codes */
+static dissector_table_t       map_prop_err_opcode_table; /* prorietary operation codes */
 /* Preferenc settings default */
 #define MAX_SSN 254
 static range_t *global_ssn_range;
@@ -313,17 +317,17 @@ dissect_gsm_map_ext_qos_subscribed(tvbuff_t *tvb, packet_info *pinfo _U_, proto_
                6-13.
         */
        /* Allocation/Retention Priority */
-       proto_tree_add_item(subtree, hf_gsm_map_ext_qos_subscribed_pri, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_ext_qos_subscribed_pri, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset++;
 
        /* Quality of Service Octets 6-13.( Octet 2 - 9 Here) */
 
        /* Traffic class, octet 6 (see 3GPP TS 23.107) Bits 8 7 6 */
-       proto_tree_add_item(subtree, hf_gsm_map_qos_traffic_cls, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_qos_traffic_cls, tvb, offset, 1, ENC_BIG_ENDIAN);
        /* Delivery order, octet 6 (see 3GPP TS 23.107) Bits 5 4 */
-       proto_tree_add_item(subtree, hf_gsm_map_qos_del_order, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_qos_del_order, tvb, offset, 1, ENC_BIG_ENDIAN);
        /* Delivery of erroneous SDUs, octet 6 (see 3GPP TS 23.107) Bits 3 2 1 */
-       proto_tree_add_item(subtree, hf_gsm_map_qos_del_of_err_sdu, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_qos_del_of_err_sdu, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset++;
 
        /* Maximum SDU size, octet 7 (see 3GPP TS 23.107) */
@@ -371,15 +375,15 @@ dissect_gsm_map_ext_qos_subscribed(tvbuff_t *tvb, packet_info *pinfo _U_, proto_
        }
        offset++;
        /* Residual Bit Error Rate (BER), octet 10 (see 3GPP TS 23.107) Bits 8 7 6 5 */
-       proto_tree_add_item(subtree, hf_gsm_map_qos_ber, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_qos_ber, tvb, offset, 1, ENC_BIG_ENDIAN);
        /* SDU error ratio, octet 10 (see 3GPP TS 23.107) */
-       proto_tree_add_item(subtree, hf_gsm_map_qos_sdu_err_rat, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_qos_sdu_err_rat, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset++;
 
        /* Transfer delay, octet 11 (See 3GPP TS 23.107) Bits 8 7 6 5 4 3 */
-       proto_tree_add_item(subtree, hf_gsm_map_qos_transfer_delay, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_qos_transfer_delay, tvb, offset, 1, ENC_BIG_ENDIAN);
        /* Traffic handling priority, octet 11 (see 3GPP TS 23.107) Bits 2 1 */
-       proto_tree_add_item(subtree, hf_gsm_map_qos_traff_hdl_pri, tvb, offset, 1, FALSE);
+       proto_tree_add_item(subtree, hf_gsm_map_qos_traff_hdl_pri, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset++;
 
        /*      Guaranteed bit rate for uplink, octet 12 (See 3GPP TS 23.107)
@@ -608,16 +612,16 @@ dissect_cbs_data_coding_scheme(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree
 
        octet = tvb_get_guint8(tvb,0);
        coding_grp = octet >>4;
-       proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp, tvb, 0, 1, FALSE);
+       proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp, tvb, 0, 1, ENC_BIG_ENDIAN);
 
        sms_encoding = SMS_ENCODING_NOT_SET;
        switch (coding_grp){
        case 0:
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp0_lang, tvb, 0, 1, FALSE);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp0_lang, tvb, 0, 1, ENC_BIG_ENDIAN);
                sms_encoding = SMS_ENCODING_7BIT;
                break;
        case 1:
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp1_lang, tvb, 0, 1, FALSE);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp1_lang, tvb, 0, 1, ENC_BIG_ENDIAN);
                if ((octet & 0x0f)== 0){
                        sms_encoding = SMS_ENCODING_7BIT_LANG;
                }else{
@@ -625,11 +629,11 @@ dissect_cbs_data_coding_scheme(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree
                }
                break;
        case 2:
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp2_lang, tvb, 0, 1, FALSE);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp2_lang, tvb, 0, 1, ENC_BIG_ENDIAN);
                sms_encoding = SMS_ENCODING_7BIT;
                break;
        case 3:
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp3_lang, tvb, 0, 1, FALSE);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp3_lang, tvb, 0, 1, ENC_BIG_ENDIAN);
                sms_encoding = SMS_ENCODING_7BIT;
                break;
                /* Coding_grp 01xx */
@@ -641,11 +645,11 @@ dissect_cbs_data_coding_scheme(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree
                  /* FALLTHRU */
        case 7:
                  /* FALLTHRU */
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_comp, tvb, 0, 1, FALSE);
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_class_ind, tvb, 0, 1, FALSE);
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_char_set, tvb, 0, 1, FALSE);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_comp, tvb, 0, 1, ENC_BIG_ENDIAN);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_class_ind, tvb, 0, 1, ENC_BIG_ENDIAN);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_char_set, tvb, 0, 1, ENC_BIG_ENDIAN);
                if ((octet & 0x10)== 0x10){
-                       proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_class, tvb, 0, 1, FALSE);
+                       proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_class, tvb, 0, 1, ENC_BIG_ENDIAN);
                }
                /* Bits 3 and 2 indicate the character set being used, */
                character_set = (octet&0x0c)>>2;
@@ -675,8 +679,8 @@ dissect_cbs_data_coding_scheme(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree
                break;
        case 9:
                /* Message with User Data Header (UDH) structure:*/
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_char_set, tvb, 0, 1, FALSE);
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_class, tvb, 0, 1, FALSE);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_char_set, tvb, 0, 1, ENC_BIG_ENDIAN);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp4_7_class, tvb, 0, 1, ENC_BIG_ENDIAN);
                character_set = (octet&0x0c)>>2;
                switch (character_set){
                case 0:
@@ -716,8 +720,8 @@ dissect_cbs_data_coding_scheme(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree
                break;
        case 15:
                /* Data coding / message handling */
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp15_mess_code, tvb, 0, 1, FALSE);
-               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp15_class, tvb, 0, 1, FALSE);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp15_mess_code, tvb, 0, 1, ENC_BIG_ENDIAN);
+               proto_tree_add_item(tree, hf_gsm_map_cbs_coding_grp15_class, tvb, 0, 1, ENC_BIG_ENDIAN);
                character_set = (octet&0x04)>>2;
                if (character_set == 0){
                        sms_encoding = SMS_ENCODING_7BIT;
@@ -739,9 +743,9 @@ dissect_gsm_map_msisdn(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
  guint8                na;
  guint8                np;
 
- proto_tree_add_item(tree, hf_gsm_map_extension, tvb, 0,1,FALSE);
- proto_tree_add_item(tree, hf_gsm_map_nature_of_number, tvb, 0,1,FALSE);
- proto_tree_add_item(tree, hf_gsm_map_number_plan, tvb, 0,1,FALSE);
+ proto_tree_add_item(tree, hf_gsm_map_extension, tvb, 0,1,ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_gsm_map_nature_of_number, tvb, 0,1,ENC_BIG_ENDIAN);
+ proto_tree_add_item(tree, hf_gsm_map_number_plan, tvb, 0,1,ENC_BIG_ENDIAN);
 
  digit_str = unpack_digits(tvb, 1);
 
@@ -836,11 +840,11 @@ const gchar* gsm_map_opr_code(guint32 val) {
   case 46: /*mo-forwardSM*/
          /* FALLTHRU */
     if (application_context_version < 3) {
-      return val_to_str(val, gsm_map_V1V2_opr_code_strings, "Unknown GSM-MAP (%u)");
+      return val_to_str_const(val, gsm_map_V1V2_opr_code_strings, "Unknown GSM-MAP opcode");
     }
     /* Else use the default map operation translation */
   default:
-    return val_to_str(val, gsm_old_GSMMAPOperationLocalvalue_vals, "Unknown GSM-MAP opcode (%u)");
+    return val_to_str_ext_const(val, &gsm_old_GSMMAPOperationLocalvalue_vals_ext, "Unknown GSM-MAP opcode");
     break;
   }
 }
@@ -1262,9 +1266,13 @@ static int dissect_invokeData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_
   case 126: /*SS-protocol explicitCT no Argument*/
     break;
   default:
-    cause=proto_tree_add_text(tree, tvb, offset, -1, "Unknown invokeData blob");
-    proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
-    expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "Unknown invokeData %d",opcode);
+    if(!dissector_try_uint(map_prop_arg_opcode_table, (guint8)opcode, tvb, actx->pinfo, tree)){
+        cause=proto_tree_add_text(tree, tvb, offset, -1, "Unknown invokeData blob");
+        proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
+        expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "Unknown invokeData %d",opcode);
+       }
+       offset+= tvb_length_remaining(tvb,offset);
+       break;
   }
   return offset;
 }
@@ -1566,9 +1574,13 @@ static int dissect_returnResultData(proto_tree *tree, tvbuff_t *tvb, int offset,
     break;
 
  default:
-   cause=proto_tree_add_text(tree, tvb, offset, -1, "Unknown returnResultData blob");
-   proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
-   expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "Unknown invokeData %d",opcode);
+   if(!dissector_try_uint(map_prop_res_opcode_table, (guint8)opcode, tvb, actx->pinfo, tree)){
+       cause=proto_tree_add_text(tree, tvb, offset, -1, "Unknown returnResultData blob");
+       proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
+       expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "Unknown invokeData %d",opcode);
+   }
+   offset+= tvb_length_remaining(tvb,offset);
+   break;
   }
   return offset;
 }
@@ -1727,9 +1739,12 @@ static int dissect_returnErrorData(proto_tree *tree, tvbuff_t *tvb, int offset,
          offset=dissect_gsm_map_er_InformationNotAvailableParam(FALSE, tvb, offset, actx, tree, -1);
          break;
   default:
-    cause=proto_tree_add_text(tree, tvb, offset, -1, "Unknown returnErrorData blob");
-    proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
-    expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "Unknown invokeData %d",errorCode);
+    if(!dissector_try_uint(map_prop_err_opcode_table, (guint8)opcode, tvb, actx->pinfo, tree)){
+        cause=proto_tree_add_text(tree, tvb, offset, -1, "Unknown returnErrorData blob");
+        proto_item_set_expert_flags(cause, PI_MALFORMED, PI_WARN);
+        expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN, "Unknown invokeData %d",errorCode);
+    }
+       offset+= tvb_length_remaining(tvb,offset);
     break;
   }
   return offset;
@@ -1775,7 +1790,7 @@ dissect_gsm_map_GSMMAPPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,
   /* Get the length and add 2 */
   gsm_map_pdu_size = tvb_get_guint8(tvb, offset+1)+2;
 
-  col_add_str(actx->pinfo->cinfo, COL_INFO, val_to_str(gsmmap_pdu_type, gsm_old_Component_vals, "Unknown GSM-MAP PDU (%u)"));
+  col_add_str(actx->pinfo->cinfo, COL_INFO, val_to_str_const(gsmmap_pdu_type, gsm_old_Component_vals, "Unknown GSM-MAP Component"));
   col_append_fstr(actx->pinfo->cinfo, COL_INFO, " ");
   offset = dissect_gsm_old_Component(FALSE, tvb, 0, actx, tree, hf_gsm_map_old_Component_PDU);
 /*
@@ -1798,7 +1813,6 @@ dissect_gsm_map(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
 
        asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
 
-
     col_set_str(pinfo->cinfo, COL_PROTOCOL, "GSM MAP");
 
     top_tree = parent_tree;
@@ -2460,6 +2474,10 @@ void proto_register_gsm_map(void) {
         { "DLCI", "gsm_map.disc_par",
           FT_UINT8, BASE_DEC, NULL, 0,
           "Data Link Connection Indicator", HFILL }},
+      { &hf_gsm_apn_str,
+        { "APN", "gsm_map.apn_str",
+          FT_STRING, BASE_NONE, NULL, 0,
+          NULL, HFILL }},
 
 #include "packet-gsm_map-hfarr.c"
   };
@@ -2488,6 +2506,7 @@ void proto_register_gsm_map(void) {
     &ett_gsm_map_cbs_data_coding,
     &ett_gsm_map_GlobalCellId,
     &ett_gsm_map_GeographicalInformation,
+       &ett_gsm_map_apn_str,
 
 #include "packet-gsm_map-ettarr.c"
   };
@@ -2505,6 +2524,10 @@ void proto_register_gsm_map(void) {
                                                 "GSM SMS TPDU", FT_UINT8,
                                                 BASE_DEC);
 
+  map_prop_arg_opcode_table = register_dissector_table("gsm_map.prop.arg.opcode", "Proprietary Opcodes", FT_UINT8, BASE_DEC);
+  map_prop_res_opcode_table = register_dissector_table("gsm_map.prop.res.opcode", "Proprietary Opcodes", FT_UINT8, BASE_DEC);
+  map_prop_err_opcode_table = register_dissector_table("gsm_map.prop.err.opcode", "Proprietary Opcodes", FT_UINT8, BASE_DEC);
+
   gsm_map_tap = register_tap("gsm_map");
 
 #include "packet-gsm_map-dis-tab.c" */