Make dissection of AVP: 3GPP-User-Location-Info(22) l=15 f=V-- vnd=TGPP val=303231...
[obnox/wireshark/wip.git] / epan / h225-persistentdata.c
1 /*
2  * h225-persistentdata.c
3  * Source for lists and hash tables used in wireshark's h225 dissector
4  * for calculation of delays in h225-calls
5  *
6  * Copyright 2003 Lars Roland
7  *
8  * $Id$
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <glib.h>
34 #include <epan/packet.h>
35 #include <epan/emem.h>
36
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "h225-persistentdata.h"
41
42 /* Global Memory Chunks for lists and Global hash tables*/
43
44 static GHashTable *ras_calls[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
45
46 /*
47  * Functions needed for Ras-Hash-Table
48  */
49
50 /* compare 2 keys */
51 static gint h225ras_call_equal(gconstpointer k1, gconstpointer k2)
52 {
53         const h225ras_call_info_key* key1 = (const h225ras_call_info_key*) k1;
54         const h225ras_call_info_key* key2 = (const h225ras_call_info_key*) k2;
55
56         return (key1->reqSeqNum == key2->reqSeqNum &&
57             key1->conversation == key2->conversation);
58 }
59
60 /* calculate a hash key */
61 static guint h225ras_call_hash(gconstpointer k)
62 {
63         const h225ras_call_info_key* key = (const h225ras_call_info_key*) k;
64
65         return key->reqSeqNum + GPOINTER_TO_UINT(key->conversation);
66 }
67
68
69 h225ras_call_t * find_h225ras_call(h225ras_call_info_key *h225ras_call_key ,int category)
70 {
71         h225ras_call_t *h225ras_call = NULL;
72         h225ras_call = (h225ras_call_t *)g_hash_table_lookup(ras_calls[category], h225ras_call_key);
73
74         return h225ras_call;
75 }
76
77 h225ras_call_t * new_h225ras_call(h225ras_call_info_key *h225ras_call_key, packet_info *pinfo, e_guid_t *guid, int category)
78 {
79         h225ras_call_info_key *new_h225ras_call_key;
80         h225ras_call_t *h225ras_call = NULL;
81
82
83         /* Prepare the value data.
84            "req_num" and "rsp_num" are frame numbers;
85            frame numbers are 1-origin, so we use 0
86            to mean "we don't yet know in which frame
87            the reply for this call appears". */
88         new_h225ras_call_key = se_alloc(sizeof(h225ras_call_info_key));
89         new_h225ras_call_key->reqSeqNum = h225ras_call_key->reqSeqNum;
90         new_h225ras_call_key->conversation = h225ras_call_key->conversation;
91         h225ras_call = se_alloc(sizeof(h225ras_call_t));
92         h225ras_call->req_num = pinfo->fd->num;
93         h225ras_call->rsp_num = 0;
94         h225ras_call->requestSeqNum = h225ras_call_key->reqSeqNum;
95         h225ras_call->responded = FALSE;
96         h225ras_call->next_call = NULL;
97         h225ras_call->req_time=pinfo->fd->abs_ts;
98         h225ras_call->guid=*guid;
99         /* store it */
100         g_hash_table_insert(ras_calls[category], new_h225ras_call_key, h225ras_call);
101
102         return h225ras_call;
103 }
104
105 h225ras_call_t * append_h225ras_call(h225ras_call_t *prev_call, packet_info *pinfo, e_guid_t *guid, int category _U_)
106 {
107         h225ras_call_t *h225ras_call = NULL;
108
109         /* Prepare the value data.
110            "req_num" and "rsp_num" are frame numbers;
111            frame numbers are 1-origin, so we use 0
112            to mean "we don't yet know in which frame
113            the reply for this call appears". */
114         h225ras_call = se_alloc(sizeof(h225ras_call_t));
115         h225ras_call->req_num = pinfo->fd->num;
116         h225ras_call->rsp_num = 0;
117         h225ras_call->requestSeqNum = prev_call->requestSeqNum;
118         h225ras_call->responded = FALSE;
119         h225ras_call->next_call = NULL;
120         h225ras_call->req_time=pinfo->fd->abs_ts;
121         h225ras_call->guid=*guid;
122
123         prev_call->next_call = h225ras_call;
124         return h225ras_call;
125 }
126
127
128 /* Init routine for hash tables and delay calculation
129    This routine will be called by Wireshark, before it
130    is (re-)dissecting a trace file from beginning.
131    We need to discard and init any state we've saved */
132
133 void
134 h225_init_routine(void)
135 {
136         int i;
137
138         /* free hash-tables for RAS SRT */
139         for(i=0;i<7;i++) {
140                 if (ras_calls[i] != NULL) {
141                         g_hash_table_destroy(ras_calls[i]);
142                         ras_calls[i] = NULL;
143                 }
144         }
145
146         /* create new hash-tables for RAS SRT */
147
148         for(i=0;i<7;i++) {
149                 ras_calls[i] = g_hash_table_new(h225ras_call_hash, h225ras_call_equal);
150         }
151
152 }