wsgcrypt.h checks internally if we HAVE_LIBGCRYPT
[metze/wireshark/wip.git] / epan / dissectors / packet-pdcp-lte.c
index 162011bce238774d684529b9374df589bb2d7116..0f4313b7296b637dfaadf40f5bc279458a558597 100644 (file)
 #include <epan/prefs.h>
 #include <epan/expert.h>
 #include <epan/uat.h>
-
-#ifdef HAVE_LIBGCRYPT
 #include <wsutil/wsgcrypt.h>
-#endif /* HAVE_LIBGCRYPT */
 
 /* Define this symbol if you have a working implementation of SNOW3G f8() and f9() available.
    Note that the use of this algorithm is restricted, and that an administrative charge
@@ -101,6 +98,7 @@ static int hf_pdcp_lte_fms = -1;
 static int hf_pdcp_lte_reserved4 = -1;
 static int hf_pdcp_lte_fms2 = -1;
 static int hf_pdcp_lte_bitmap = -1;
+static int hf_pdcp_lte_bitmap_byte = -1;
 
 
 /* Sequence Analysis */
@@ -1231,9 +1229,6 @@ static dissector_handle_t lookup_rrc_dissector_handle(struct pdcp_lte_info  *p_p
 /* Forwad declarations */
 static void dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
-/* Heuristic dissection */
-static gboolean global_pdcp_lte_heur = FALSE;
-
 /* Heuristic dissector looks for supported framing protocol (see wiki page)  */
 static gboolean dissect_pdcp_lte_heur(tvbuff_t *tvb, packet_info *pinfo,
                                      proto_tree *tree, void *data _U_)
@@ -1245,15 +1240,6 @@ static gboolean dissect_pdcp_lte_heur(tvbuff_t *tvb, packet_info *pinfo,
     gboolean              infoAlreadySet         = FALSE;
     gboolean              seqnumLengthTagPresent = FALSE;
 
-    /* This is a heuristic dissector, which means we get all the UDP
-     * traffic not sent to a known dissector and not claimed by
-     * a heuristic dissector called before us!
-     */
-
-    if (!global_pdcp_lte_heur) {
-        return FALSE;
-    }
-
     /* Do this again on re-dissection to re-discover offset of actual PDU */
 
     /* Needs to be at least as long as:
@@ -1852,7 +1838,7 @@ static void dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
             write_pdu_label_and_info(root_ti, pinfo, " sn=%-2u ", seqnum);
             offset++;
 
-            if (tvb_reported_length_remaining(tvb, offset) == 0) {
+            if (tvb_captured_length_remaining(tvb, offset) == 0) {
                 /* Only PDCP header was captured, stop dissection here */
                 return;
             }
@@ -1987,7 +1973,7 @@ static void dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
                                             not_received++;
                                         }
                                     }
-                                    proto_tree_add_text(bitmap_tree, tvb, bit_offset/8, 1, "%s", buff);
+                                    proto_tree_add_uint_format(bitmap_tree, hf_pdcp_lte_bitmap_byte, tvb, bit_offset/8, 1, bits, "%s", buff);
                                     bit_offset += 8;
                                 }
                             }
@@ -2136,7 +2122,7 @@ static void dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
         col_append_fstr(pinfo->cinfo, COL_INFO, " MAC=0x%08x (%u bytes data)",
                         mac, data_length);
     }
-    else {
+    else if (tvb_captured_length_remaining(payload_tvb, offset)) {
         /* User-plane payload here */
 
         /* If not compressed with ROHC, show as user-plane data */
@@ -2227,25 +2213,6 @@ static void dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
  * file is loaded or re-loaded in wireshark */
 static void pdcp_lte_init_protocol(void)
 {
-    /* Destroy any existing hashes. */
-    if (pdcp_sequence_analysis_channel_hash) {
-        g_hash_table_destroy(pdcp_sequence_analysis_channel_hash);
-    }
-    if (pdcp_lte_sequence_analysis_report_hash) {
-        g_hash_table_destroy(pdcp_lte_sequence_analysis_report_hash);
-    }
-    if (pdcp_security_hash) {
-        g_hash_table_destroy(pdcp_security_hash);
-    }
-    if (pdcp_security_result_hash) {
-        g_hash_table_destroy(pdcp_security_result_hash);
-    }
-    if (pdcp_security_key_hash) {
-        g_hash_table_destroy(pdcp_security_key_hash);
-    }
-
-
-    /* Now create them over */
     pdcp_sequence_analysis_channel_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
     pdcp_lte_sequence_analysis_report_hash = g_hash_table_new(pdcp_result_hash_func, pdcp_result_hash_equal);
     pdcp_security_hash = g_hash_table_new(pdcp_lte_ueid_hash_func, pdcp_lte_ueid_hash_equal);
@@ -2253,6 +2220,15 @@ static void pdcp_lte_init_protocol(void)
     pdcp_security_key_hash = g_hash_table_new(pdcp_lte_ueid_hash_func, pdcp_lte_ueid_hash_equal);
 }
 
+static void pdcp_lte_cleanup_protocol(void)
+{
+    g_hash_table_destroy(pdcp_sequence_analysis_channel_hash);
+    g_hash_table_destroy(pdcp_lte_sequence_analysis_report_hash);
+    g_hash_table_destroy(pdcp_security_hash);
+    g_hash_table_destroy(pdcp_security_result_hash);
+    g_hash_table_destroy(pdcp_security_key_hash);
+}
+
 
 
 void proto_register_pdcp(void)
@@ -2443,7 +2419,12 @@ void proto_register_pdcp(void)
               "Status report bitmap (0=error, 1=OK)", HFILL
             }
         },
-
+        { &hf_pdcp_lte_bitmap_byte,
+            { "Bitmap byte",
+              "pdcp-lte.bitmap.byte", FT_UINT8, BASE_HEX, NULL, 0x0,
+              NULL, HFILL
+            }
+        },
 
         { &hf_pdcp_lte_sequence_analysis,
             { "Sequence Analysis",
@@ -2643,11 +2624,7 @@ void proto_register_pdcp(void)
         "Attempt to decode ROHC data",
         &global_pdcp_dissect_rohc);
 
-    prefs_register_bool_preference(pdcp_lte_module, "heuristic_pdcp_lte_over_udp",
-        "Try Heuristic LTE-PDCP over UDP framing",
-        "When enabled, use heuristic dissector to find PDCP-LTE frames sent with "
-        "UDP framing",
-        &global_pdcp_lte_heur);
+    prefs_register_obsolete_preference(pdcp_lte_module, "heuristic_pdcp_lte_over_udp");
 
     prefs_register_enum_preference(pdcp_lte_module, "layer_to_show",
         "Which layer info to show in Info column",
@@ -2703,12 +2680,13 @@ void proto_register_pdcp(void)
         &global_pdcp_check_integrity);
 
     register_init_routine(&pdcp_lte_init_protocol);
+    register_cleanup_routine(&pdcp_lte_cleanup_protocol);
 }
 
 void proto_reg_handoff_pdcp_lte(void)
 {
     /* Add as a heuristic UDP dissector */
-    heur_dissector_add("udp", dissect_pdcp_lte_heur, proto_pdcp_lte);
+    heur_dissector_add("udp", dissect_pdcp_lte_heur, "PDCP-LTE over UDP", "pdcp_lte_udp", proto_pdcp_lte, HEURISTIC_DISABLE);
 
     ip_handle   = find_dissector("ip");
     ipv6_handle = find_dissector("ipv6");