From d46568212dcd90fe6b7a3f3b430f48a2aaf8f175 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Sun, 25 Jan 2015 17:32:40 -0500 Subject: Roll functionality of h225-persistentdata module into packet-h225.c Change-Id: I19b2a1b19e1e77a6456e2310daf64ddff572b0d2 Reviewed-on: https://code.wireshark.org/review/6788 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- asn1/h225/packet-h225-template.c | 142 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 138 insertions(+), 4 deletions(-) (limited to 'asn1') diff --git a/asn1/h225/packet-h225-template.c b/asn1/h225/packet-h225-template.c index 51e509dc49..df5a63cecc 100644 --- a/asn1/h225/packet-h225-template.c +++ b/asn1/h225/packet-h225-template.c @@ -44,7 +44,6 @@ #include "packet-tpkt.h" #include "packet-per.h" #include "packet-h225.h" -#include #include "packet-h235.h" #include "packet-h245.h" #include "packet-h323.h" @@ -63,11 +62,39 @@ void proto_register_h225(void); static void reset_h225_packet_info(h225_packet_info *pi); +static void h225_init_routine(void); static void ras_call_matching(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, h225_packet_info *pi); +/* Item of ras request list*/ +typedef struct _h225ras_call_t { + guint32 requestSeqNum; + e_guid_t guid; + guint32 req_num; /* frame number request seen */ + guint32 rsp_num; /* frame number response seen */ + nstime_t req_time; /* arrival time of request */ + gboolean responded; /* true, if request has been responded */ + struct _h225ras_call_t *next_call; /* pointer to next ras request with same SequenceNumber and conversation handle */ +} h225ras_call_t; + + +/* Item of ras-request key list*/ +typedef struct _h225ras_call_info_key { + guint reqSeqNum; + conversation_t *conversation; +} h225ras_call_info_key; + static h225_packet_info pi_arr[5]; /* We assuming a maximum of 5 H225 messaages per packet */ static int pi_current=0; -h225_packet_info *h225_pi=&pi_arr[0]; +static h225_packet_info *h225_pi=&pi_arr[0]; + +/* Global Memory Chunks for lists and Global hash tables*/ + +static GHashTable *ras_calls[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + +/* functions, needed using ras-request and halfcall matching*/ +static h225ras_call_t * find_h225ras_call(h225ras_call_info_key *h225ras_call_key ,int category); +static h225ras_call_t * new_h225ras_call(h225ras_call_info_key *h225ras_call_key, packet_info *pinfo, e_guid_t *guid, int category); +static h225ras_call_t * append_h225ras_call(h225ras_call_t *prev_call, packet_info *pinfo, e_guid_t *guid, int category); static dissector_handle_t data_handle; /* Subdissector tables */ @@ -133,6 +160,113 @@ static const char *tpOID; /* Forward declaration we need below */ void proto_reg_handoff_h225(void); +/* + * Functions needed for Ras-Hash-Table + */ + +/* compare 2 keys */ +static gint h225ras_call_equal(gconstpointer k1, gconstpointer k2) +{ + const h225ras_call_info_key* key1 = (const h225ras_call_info_key*) k1; + const h225ras_call_info_key* key2 = (const h225ras_call_info_key*) k2; + + return (key1->reqSeqNum == key2->reqSeqNum && + key1->conversation == key2->conversation); +} + +/* calculate a hash key */ +static guint h225ras_call_hash(gconstpointer k) +{ + const h225ras_call_info_key* key = (const h225ras_call_info_key*) k; + + return key->reqSeqNum + GPOINTER_TO_UINT(key->conversation); +} + + +h225ras_call_t * find_h225ras_call(h225ras_call_info_key *h225ras_call_key ,int category) +{ + h225ras_call_t *h225ras_call = NULL; + h225ras_call = (h225ras_call_t *)g_hash_table_lookup(ras_calls[category], h225ras_call_key); + + return h225ras_call; +} + +h225ras_call_t * new_h225ras_call(h225ras_call_info_key *h225ras_call_key, packet_info *pinfo, e_guid_t *guid, int category) +{ + h225ras_call_info_key *new_h225ras_call_key; + h225ras_call_t *h225ras_call = NULL; + + + /* Prepare the value data. + "req_num" and "rsp_num" are frame numbers; + frame numbers are 1-origin, so we use 0 + to mean "we don't yet know in which frame + the reply for this call appears". */ + new_h225ras_call_key = wmem_new(wmem_file_scope(), h225ras_call_info_key); + new_h225ras_call_key->reqSeqNum = h225ras_call_key->reqSeqNum; + new_h225ras_call_key->conversation = h225ras_call_key->conversation; + h225ras_call = wmem_new(wmem_file_scope(), h225ras_call_t); + h225ras_call->req_num = pinfo->fd->num; + h225ras_call->rsp_num = 0; + h225ras_call->requestSeqNum = h225ras_call_key->reqSeqNum; + h225ras_call->responded = FALSE; + h225ras_call->next_call = NULL; + h225ras_call->req_time=pinfo->fd->abs_ts; + h225ras_call->guid=*guid; + /* store it */ + g_hash_table_insert(ras_calls[category], new_h225ras_call_key, h225ras_call); + + return h225ras_call; +} + +h225ras_call_t * append_h225ras_call(h225ras_call_t *prev_call, packet_info *pinfo, e_guid_t *guid, int category _U_) +{ + h225ras_call_t *h225ras_call = NULL; + + /* Prepare the value data. + "req_num" and "rsp_num" are frame numbers; + frame numbers are 1-origin, so we use 0 + to mean "we don't yet know in which frame + the reply for this call appears". */ + h225ras_call = wmem_new(wmem_file_scope(), h225ras_call_t); + h225ras_call->req_num = pinfo->fd->num; + h225ras_call->rsp_num = 0; + h225ras_call->requestSeqNum = prev_call->requestSeqNum; + h225ras_call->responded = FALSE; + h225ras_call->next_call = NULL; + h225ras_call->req_time=pinfo->fd->abs_ts; + h225ras_call->guid=*guid; + + prev_call->next_call = h225ras_call; + return h225ras_call; +} + +/* Init routine for hash tables and delay calculation + This routine will be called by Wireshark, before it + is (re-)dissecting a trace file from beginning. + We need to discard and init any state we've saved */ + +void +h225_init_routine(void) +{ + int i; + + /* free hash-tables for RAS SRT */ + for(i=0;i<7;i++) { + if (ras_calls[i] != NULL) { + g_hash_table_destroy(ras_calls[i]); + ras_calls[i] = NULL; + } + } + + /* create new hash-tables for RAS SRT */ + + for(i=0;i<7;i++) { + ras_calls[i] = g_hash_table_new(h225ras_call_hash, h225ras_call_equal); + } + +} + static int dissect_h225_H323UserInformation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) { @@ -209,8 +343,8 @@ void proto_register_h225(void) { /* List of fields */ static hf_register_info hf[] = { { &hf_h221Manufacturer, - { "H.221 Manufacturer", "h221.Manufacturer", FT_UINT32, BASE_HEX, - VALS(H221ManufacturerCode_vals), 0, NULL, HFILL }}, + { "H.225 Manufacturer", "h225.Manufacturer", FT_UINT32, BASE_HEX, + VALS(H221ManufacturerCode_vals), 0, "h225.H.221 Manufacturer", HFILL }}, { &hf_h225_ras_req_frame, { "RAS Request Frame", "h225.ras.reqframe", FT_FRAMENUM, BASE_NONE, NULL, 0, NULL, HFILL }}, -- cgit v1.2.3