Introduce dissect_e212_mcc_mnc_ep_str()
authoretxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 4 Jan 2011 16:58:07 +0000 (16:58 +0000)
committeretxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 4 Jan 2011 16:58:07 +0000 (16:58 +0000)
Which can be useful to make nice lables like:
+ Serving Network : MCC 311 United States of America, MNC 28

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@35360 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/packet-e212.c
epan/dissectors/packet-e212.h

index 5c7a78a3c534e97f02263ac6a421497397809ea4..c6d7909148bc7cfc372b275bbffb4d5e48169307 100644 (file)
@@ -2216,14 +2216,20 @@ static int hf_E212_msin                                         = -1;
  * |  MNC digit 3  |  MNC digit 2  |  octet x+2
  * +---------------+---------------+
  */
-int
-dissect_e212_mcc_mnc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gboolean little_endian){
+
+/*
+ * Return MCC MNC in a ep allocated string that can be used in labels.
+ */
+gchar *
+dissect_e212_mcc_mnc_ep_str(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gboolean little_endian)
+{
 
        int                     start_offset;
        guint8          octet;
        guint16         mcc, mnc;
        guint8          mcc1, mcc2, mcc3, mnc1, mnc2, mnc3;
        proto_item      *item;
+       gchar           *mcc_mnc_str;
 
        start_offset = offset;
        /* Mobile country code MCC */
@@ -2252,24 +2258,47 @@ dissect_e212_mcc_mnc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int of
        if ((mcc1 > 9) || (mcc2 > 9) || (mcc3 > 9))
                expert_add_info_format(pinfo, item, PI_MALFORMED, PI_WARN, "MCC contains non-decimal digits");
 
-       if(mnc3 != 0x0f)
+       if(mnc3 != 0x0f){
                item = proto_tree_add_uint_format(tree, hf_E212_mnc , tvb, start_offset + 1, 2, mnc,
                                   "Mobile Network Code (MNC): %s (%03u)",
                                   val_to_str_ext_const(mcc * 1000 + mnc, &mcc_mnc_codes_ext, "Unknown"),
                                   mnc);
-       else
+               /* Preapre a string with the MCC and MNC including the country and Operator if
+                * known, do NOT print unknown.
+                */
+               mcc_mnc_str = ep_strdup_printf("MCC %u %s, MNC %03u %s",
+                       mcc, 
+                       val_to_str_ext_const(mcc,&E212_codes_ext,""),
+                       mnc,
+                       val_to_str_ext_const(mcc * 1000 + mnc, &mcc_mnc_codes_ext, ""));
+       }else{
                item = proto_tree_add_uint_format(tree, hf_E212_mnc , tvb, start_offset + 1, 2, mnc,
                                   "Mobile Network Code (MNC): %s (%02u)",
                                   val_to_str_ext_const(mcc * 1000 + 10 * mnc, &mcc_mnc_codes_ext, "Unknown"),
                                   mnc);
+               /* Preapre a string with the MCC and MNC including the country and Operator if
+                * known, do NOT print unknown.
+                */
+               mcc_mnc_str = ep_strdup_printf("MCC %u %s, MNC %02u %s",
+                       mcc, 
+                       val_to_str_ext_const(mcc,&E212_codes_ext,""),
+                       mnc,
+                       val_to_str_ext_const(mcc * 1000 + mnc, &mcc_mnc_codes_ext, ""));
+       }
 
        if ((mnc1 > 9) || (mnc2 > 9) || ((mnc3 > 9) && (mnc3 != 0x0f)))
                expert_add_info_format(pinfo, item, PI_MALFORMED, PI_WARN, "MNC contains non-decimal digits");
 
        offset++;
-       return offset;
+       return mcc_mnc_str;
 }
 
+int
+dissect_e212_mcc_mnc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gboolean little_endian)
+{
+       dissect_e212_mcc_mnc_ep_str(tvb, pinfo, tree, offset, little_endian);
+       return offset +3;
+}
 
 /*
  * When we want to decode the MCC/MNC pair in an address that is encoded according to E.212
index da677dc9a19c83cca46c5216edc9a494029809c9..9efbf158af82ff628efe0e2f84d20e2ce3e6ff4f 100644 (file)
@@ -30,6 +30,7 @@
 
 extern value_string_ext E212_codes_ext;
 
+gchar* dissect_e212_mcc_mnc_ep_str(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gboolean little_endian);
 int dissect_e212_mcc_mnc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, gboolean little_endian);
 int dissect_e212_mcc_mnc_in_address(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset);