Added mockups for LSA_SECRET and LSA_SECURITY_DESCRIPTOR inside
[obnox/wireshark/wip.git] / packet-gtp.c
1 /* packet-gtp.c
2  * 
3  * Routines for GTP dissection
4  * Copyright 2001, Michal Melerowicz <michal.melerowicz@nokia.com>
5  *                 Nicolas Balkota <balkota@mac.com>
6  *
7  * $Id: packet-gtp.c,v 1.24 2002/01/31 12:10:58 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
38 #endif
39
40 #ifdef HAVE_NETINET_IN_H
41 # include <netinet/in.h>
42 #endif
43
44 #include <glib.h>
45
46 #ifdef NEED_SNPRINTF_H
47 # include "snprintf.h"
48 #endif
49
50 #include <epan/packet.h>
51 #include "packet-ipv6.h"
52 #include "prefs.h"
53
54 /* 
55  * All data related to GTP v0 (GPRS) uses "gtpv0" or "GTPv0",
56  * all data related to GTP v1 (UMTS) uses "gtpv1" or "GTPv1",
57  * if there is any gtp alone statement it means that this data is common 
58  * for both: GPRS and UMTS
59  */
60
61 #define GTPv0_PORT 3386
62 #define GTPv1C_PORT 2123                        /* 3G Control PDU */
63 #define GTPv1U_PORT 2152                        /* 3G T-PDU */
64
65 #define GTPv0_HDR_LENGTH 20
66 #define GTPv1_HDR_LENGTH 12
67
68 /* for function checking compliance with ETSI  */
69 #define MANDATORY       1                       
70 #define OPTIONAL        2 
71 #define CONDITIONAL     4
72
73 static int g_gtpv0_port                 = GTPv0_PORT;
74 static int g_gtpv1c_port                = GTPv1C_PORT;
75 static int g_gtpv1u_port                = GTPv1U_PORT;
76
77 void proto_reg_handoff_gtp(void);
78
79 static int proto_gtpv0                  = -1;
80 static int proto_gtpv1                  = -1;
81
82 static int hf_gtpv0_flags                       = -1;
83 static int hf_gtpv0_flags_ver           = -1;
84 static int hf_gtpv0_flags_pt            = -1;
85 static int hf_gtpv0_flags_spare         = -1;
86 static int hf_gtpv0_flags_e             = -1;
87 static int hf_gtpv0_flags_s             = -1;
88 static int hf_gtpv0_flags_pn            = -1;
89 static int hf_gtpv0_flags_snn           = -1;
90 static int hf_gtpv0_message_type                = -1;
91 static int hf_gtpv0_length              = -1;
92 static int hf_gtpv0_seq_number          = -1;
93 static int hf_gtpv0_flow_label          = -1;
94 static int hf_gtpv0_sndcp_number                = -1;
95 static int hf_gtpv0_npdu_number         = -1;
96 static int hf_gtpv0_tid                 = -1;
97 static int hf_gtpv0_teid                        = -1;
98 static int hf_gtpv0_next                        = -1;
99 static int hf_gtpv0_cause                       = -1;
100 static int hf_gtpv0_imsi                        = -1;
101 static int hf_gtpv0_rai_mcc             = -1;
102 static int hf_gtpv0_rai_mnc             = -1;
103 static int hf_gtpv0_rai_rac             = -1;
104 static int hf_gtpv0_rai_lac             = -1;
105 static int hf_gtpv0_tlli                        = -1;
106 static int hf_gtpv0_ptmsi                       = -1;
107 static int hf_gtpv0_qos_spare1          = -1;
108 static int hf_gtpv0_qos_delay           = -1;
109 static int hf_gtpv0_qos_mean            = -1;
110 static int hf_gtpv0_qos_peak            = -1;
111 static int hf_gtpv0_qos_spare2          = -1;
112 static int hf_gtpv0_qos_precedence      = -1;
113 static int hf_gtpv0_qos_spare3          = -1;
114 static int hf_gtpv0_qos_reliability     = -1;
115 static int hf_gtpv0_reorder             = -1;
116 static int hf_gtpv0_map_cause           = -1;
117 static int hf_gtpv0_ptmsi_sig           = -1;
118 static int hf_gtpv0_ms_valid            = -1;
119 static int hf_gtpv0_recovery            = -1;
120 static int hf_gtpv0_sel_mode            = -1;
121 static int hf_gtpv0_ext_flow_label      = -1;
122 static int hf_gtpv0_teid_data           = -1;   /* 3G */
123 static int hf_gtpv0_flow_sig            = -1;
124 static int hf_gtpv0_teid_cp             = -1;   /* 3G */
125 static int hf_gtpv0_nsapi                       = -1;
126 static int hf_gtpv0_flow_ii             = -1;
127 static int hf_gtpv0_teid_ii             = -1;   /* 3G */
128 static int hf_gtpv0_ms_reason           = -1;
129 static int hf_gtpv0_tear_ind            = -1;   /* 3G */
130 static int hf_gtpv0_ranap_cause         = -1;   /* 3G */
131 static int hf_gtpv0_rab_gtpu_dn         = -1;   /* 3G */
132 static int hf_gtpv0_rab_gtpu_up         = -1;   /* 3G */
133 static int hf_gtpv0_rab_pdu_dn          = -1;   /* 3G */
134 static int hf_gtpv0_rab_pdu_up          = -1;   /* 3G */
135 static int hf_gtpv0_rp_sms              = -1;   /* 3G */
136 static int hf_gtpv0_rp_spare            = -1;   /* 3G */
137 static int hf_gtpv0_rp_nsapi            = -1;   /* 3G */
138 static int hf_gtpv0_rp                  = -1;   /* 3G */
139 static int hf_gtpv0_pkt_flow_id         = -1;   /* 3G */
140 static int hf_gtpv0_chrg_char_s         = -1;   /* 3G */
141 static int hf_gtpv0_chrg_char_n         = -1;   /* 3G */
142 static int hf_gtpv0_chrg_char_p         = -1;   /* 3G */
143 static int hf_gtpv0_chrg_char_f         = -1;   /* 3G */
144 static int hf_gtpv0_chrg_char_h         = -1;   /* 3G */
145 static int hf_gtpv0_chrg_char_r         = -1;   /* 3G */
146 static int hf_gtpv0_trace_ref           = -1;   /* 3G */
147 static int hf_gtpv0_trace_type          = -1;   /* 3G */
148 static int hf_gtpv0_tr_comm             = -1;   /* charging */
149 static int hf_gtpv0_chrg_id             = -1;
150 static int hf_gtpv0_user_ipv4           = -1;
151 static int hf_gtpv0_user_ipv6           = -1;
152 static int hf_gtpv0_user_addr_pdp_org   = -1;
153 static int hf_gtpv0_user_addr_pdp_type  = -1;
154 static int hf_gtpv0_apn                 = -1;
155 static int hf_gtpv0_gsn_ipv4            = -1;
156 static int hf_gtpv0_gsn_ipv6            = -1;
157 static int hf_gtpv0_gsn_addr_type               = -1;
158 static int hf_gtpv0_gsn_addr_len                = -1;
159 static int hf_gtpv0_msisdn              = -1;
160 static int hf_gtpv0_qos_al_ret_priority = -1;
161 static int hf_gtpv0_qos_traf_class      = -1;
162 static int hf_gtpv0_qos_del_order               = -1;
163 static int hf_gtpv0_qos_del_err_sdu     = -1;
164 static int hf_gtpv0_qos_max_sdu_size    = -1;
165 static int hf_gtpv0_qos_max_ul          = -1;
166 static int hf_gtpv0_qos_max_dl          = -1;
167 static int hf_gtpv0_qos_res_ber         = -1;
168 static int hf_gtpv0_qos_sdu_err_ratio   = -1;
169 static int hf_gtpv0_qos_trans_delay     = -1;
170 static int hf_gtpv0_qos_traf_handl_prio = -1;
171 static int hf_gtpv0_qos_guar_ul         = -1;
172 static int hf_gtpv0_qos_guar_dl         = -1;
173 static int hf_gtpv0_rnc_ipv4            = -1;
174 static int hf_gtpv0_rnc_ipv6            = -1;
175 static int hf_gtpv0_chrg_ipv4           = -1;
176 static int hf_gtpv0_chrg_ipv6           = -1;
177 static int hf_gtpv0_node_ipv4           = -1;
178 static int hf_gtpv0_node_ipv6           = -1;
179 static int hf_gtpv0_ext_id              = -1;
180 static int hf_gtpv0_ext_val             = -1;
181 static int hf_gtpv0_unknown             = -1;
182
183 static int hf_gtpv1_flags                       = -1;
184 static int hf_gtpv1_flags_ver           = -1;
185 static int hf_gtpv1_flags_pt            = -1;
186 static int hf_gtpv1_flags_spare         = -1;
187 static int hf_gtpv1_flags_e             = -1;
188 static int hf_gtpv1_flags_s             = -1;
189 static int hf_gtpv1_flags_pn            = -1;
190 static int hf_gtpv1_flags_snn           = -1;
191 static int hf_gtpv1_message_type                = -1;
192 static int hf_gtpv1_length              = -1;
193 static int hf_gtpv1_seq_number          = -1;
194 static int hf_gtpv1_flow_label          = -1;
195 static int hf_gtpv1_sndcp_number                = -1;
196 static int hf_gtpv1_npdu_number         = -1;
197 static int hf_gtpv1_tid                 = -1;
198 static int hf_gtpv1_teid                        = -1;
199 static int hf_gtpv1_next                        = -1;
200 static int hf_gtpv1_cause                       = -1;
201 static int hf_gtpv1_imsi                        = -1;
202 static int hf_gtpv1_rai_mcc             = -1;
203 static int hf_gtpv1_rai_mnc             = -1;
204 static int hf_gtpv1_rai_rac             = -1;
205 static int hf_gtpv1_rai_lac             = -1;
206 static int hf_gtpv1_tlli                        = -1;
207 static int hf_gtpv1_ptmsi                       = -1;
208 static int hf_gtpv1_qos_spare1          = -1;
209 static int hf_gtpv1_qos_delay           = -1;
210 static int hf_gtpv1_qos_mean            = -1;
211 static int hf_gtpv1_qos_peak            = -1;
212 static int hf_gtpv1_qos_spare2          = -1;
213 static int hf_gtpv1_qos_precedence      = -1;
214 static int hf_gtpv1_qos_spare3          = -1;
215 static int hf_gtpv1_qos_reliability     = -1;
216 static int hf_gtpv1_reorder             = -1;
217 static int hf_gtpv1_map_cause           = -1;
218 static int hf_gtpv1_ptmsi_sig           = -1;
219 static int hf_gtpv1_ms_valid            = -1;
220 static int hf_gtpv1_recovery            = -1;
221 static int hf_gtpv1_sel_mode            = -1;
222 static int hf_gtpv1_ext_flow_label      = -1;
223 static int hf_gtpv1_teid_data           = -1;   /* 3G */
224 static int hf_gtpv1_flow_sig            = -1;
225 static int hf_gtpv1_teid_cp             = -1;   /* 3G */
226 static int hf_gtpv1_nsapi                       = -1;
227 static int hf_gtpv1_flow_ii             = -1;
228 static int hf_gtpv1_teid_ii             = -1;   /* 3G */
229 static int hf_gtpv1_ms_reason           = -1;
230 static int hf_gtpv1_tear_ind            = -1;   /* 3G */
231 static int hf_gtpv1_ranap_cause         = -1;   /* 3G */
232 static int hf_gtpv1_rab_gtpu_dn         = -1;   /* 3G */
233 static int hf_gtpv1_rab_gtpu_up         = -1;   /* 3G */
234 static int hf_gtpv1_rab_pdu_dn          = -1;   /* 3G */
235 static int hf_gtpv1_rab_pdu_up          = -1;   /* 3G */
236 static int hf_gtpv1_rp_sms              = -1;   /* 3G */
237 static int hf_gtpv1_rp_spare            = -1;   /* 3G */
238 static int hf_gtpv1_rp_nsapi            = -1;   /* 3G */
239 static int hf_gtpv1_rp                  = -1;   /* 3G */
240 static int hf_gtpv1_pkt_flow_id         = -1;   /* 3G */
241 static int hf_gtpv1_chrg_char_s         = -1;   /* 3G */
242 static int hf_gtpv1_chrg_char_n         = -1;   /* 3G */
243 static int hf_gtpv1_chrg_char_p         = -1;   /* 3G */
244 static int hf_gtpv1_chrg_char_f         = -1;   /* 3G */
245 static int hf_gtpv1_chrg_char_h         = -1;   /* 3G */
246 static int hf_gtpv1_chrg_char_r         = -1;   /* 3G */
247 static int hf_gtpv1_trace_ref           = -1;   /* 3G */
248 static int hf_gtpv1_trace_type          = -1;   /* 3G */
249 static int hf_gtpv1_tr_comm             = -1;   /* charging */
250 static int hf_gtpv1_chrg_id             = -1;
251 static int hf_gtpv1_user_ipv4           = -1;
252 static int hf_gtpv1_user_ipv6           = -1;
253 static int hf_gtpv1_user_addr_pdp_org   = -1;
254 static int hf_gtpv1_user_addr_pdp_type  = -1;
255 static int hf_gtpv1_apn                 = -1;
256 static int hf_gtpv1_gsn_ipv4            = -1;
257 static int hf_gtpv1_gsn_ipv6            = -1;
258 static int hf_gtpv1_gsn_addr_type               = -1;
259 static int hf_gtpv1_gsn_addr_len                = -1;
260 static int hf_gtpv1_msisdn              = -1;
261 static int hf_gtpv1_qos_al_ret_priority = -1;
262 static int hf_gtpv1_qos_traf_class      = -1;
263 static int hf_gtpv1_qos_del_order               = -1;
264 static int hf_gtpv1_qos_del_err_sdu     = -1;
265 static int hf_gtpv1_qos_max_sdu_size    = -1;
266 static int hf_gtpv1_qos_max_ul          = -1;
267 static int hf_gtpv1_qos_max_dl          = -1;
268 static int hf_gtpv1_qos_res_ber         = -1;
269 static int hf_gtpv1_qos_sdu_err_ratio   = -1;
270 static int hf_gtpv1_qos_trans_delay     = -1;
271 static int hf_gtpv1_qos_traf_handl_prio = -1;
272 static int hf_gtpv1_qos_guar_ul         = -1;
273 static int hf_gtpv1_qos_guar_dl         = -1;
274 static int hf_gtpv1_rnc_ipv4            = -1;
275 static int hf_gtpv1_rnc_ipv6            = -1;
276 static int hf_gtpv1_chrg_ipv4           = -1;
277 static int hf_gtpv1_chrg_ipv6           = -1;
278 static int hf_gtpv1_node_ipv4           = -1;
279 static int hf_gtpv1_node_ipv6           = -1;
280 static int hf_gtpv1_ext_id              = -1;
281 static int hf_gtpv1_ext_val             = -1;
282 static int hf_gtpv1_unknown             = -1;
283
284 /* Initialize the subtree pointers */
285 static gint ett_gtp                     = -1;
286 static gint ett_gtp_flags               = -1;
287 static gint ett_gtp_ext                 = -1;
288 static gint ett_gtp_rai                 = -1;
289 static gint ett_gtp_qos                 = -1;
290 static gint ett_gtp_auth_tri            = -1;
291 static gint ett_gtp_flow_ii             = -1;
292 static gint ett_gtp_rab_cntxt           = -1;
293 static gint ett_gtp_rp                  = -1;
294 static gint ett_gtp_pkt_flow_id         = -1;
295 static gint ett_gtp_chrg_char           = -1;
296 static gint ett_gtp_user                = -1;
297 static gint ett_gtp_mm                  = -1;
298 static gint ett_gtp_trip                = -1;
299 static gint ett_gtp_quint               = -1;
300 static gint ett_gtp_pdp                 = -1;
301 static gint ett_gtp_apn                 = -1;
302 static gint ett_gtp_proto               = -1;
303 static gint ett_gtp_gsn_addr            = -1;
304 static gint ett_gtp_tft                 = -1;
305 static gint ett_gtp_tft_pf              = -1;
306 static gint ett_gtp_rab_setup           = -1;
307 static gint ett_gtp_hdr_list            = -1;
308 static gint ett_gtp_chrg_addr           = -1;
309 static gint ett_gtp_node_addr           = -1;
310 static gint ett_gtp_rel_pack            = -1;
311 static gint ett_gtp_can_pack            = -1;
312 static gint ett_gtp_data_resp           = -1;
313 static gint ett_gtp_priv_ext            = -1;
314
315 /* Definition of user preferences panel fields */
316 #define DONT_DISSECT_CDRS       2
317
318 static gboolean gtp_tpdu                = TRUE;
319 static gint     gtpv0_cdr_as            = DONT_DISSECT_CDRS;                    /* 2 = do not dissect */
320 static gboolean gtpv0_etsi_order        = FALSE;
321 static gboolean gtpv1_etsi_order        = FALSE;
322 static int      gtpv0_port              = 0;
323 static int      gtpv1c_port             = 0;
324 static int      gtpv1u_port             = 0;
325 static gboolean ppp_reorder             = TRUE;
326
327 /* Definition of flags masks */
328 #define GTP_VER_MASK 0xE0
329
330 static const value_string ver_types[] = {
331         { 0, "GTP release 97/98 version" },
332         { 1, "GTP release 99 version" },
333         { 2, "None" },
334         { 3, "None" },
335         { 4, "None" },
336         { 5, "None" },
337         { 6, "None" },
338         { 7, "None" },
339         { 0, NULL }
340 };
341
342 #define GTP_PT_MASK             0x10
343 #define GTP_SPARE_MASK          0x0E
344 #define GTPv1_SPARE_MASK                0x08
345 #define GTPv1_E_MASK            0x04
346 #define GTPv1_S_MASK            0x02
347 #define GTP_SNN_MASK            0x01
348 #define GTPv1_PN_MASK           0x01
349
350 /* Definition of 3G charging characteristics masks */
351 #define GTP_MASK_CHRG_CHAR_S    0xF000
352 #define GTP_MASK_CHRG_CHAR_N    0x0800
353 #define GTP_MASK_CHRG_CHAR_P    0x0400
354 #define GTP_MASK_CHRG_CHAR_F    0x0200
355 #define GTP_MASK_CHRG_CHAR_H    0x0100
356 #define GTP_MASK_CHRG_CHAR_R    0x00FF
357
358
359 /* Definition of GSN Address masks */
360 #define GTP_EXT_GSN_ADDR_TYPE_MASK              0xC0
361 #define GTP_EXT_GSN_ADDR_LEN_MASK               0x3F
362
363 /* Definition of QoS masks */
364 #define GTP_EXT_QOS_SPARE1_MASK                 0xC0
365 #define GTP_EXT_QOS_DELAY_MASK                  0x38
366 #define GTP_EXT_QOS_RELIABILITY_MASK            0x07
367 #define GTP_EXT_QOS_PEAK_MASK                   0xF0
368 #define GTP_EXT_QOS_SPARE2_MASK                 0x08
369 #define GTP_EXT_QOS_PRECEDENCE_MASK             0x07
370 #define GTP_EXT_QOS_SPARE3_MASK                 0xE0
371 #define GTP_EXT_QOS_MEAN_MASK                   0x1F
372 #define GTP_EXT_QOS_TRAF_CLASS_MASK             0xE0
373 #define GTP_EXT_QOS_DEL_ORDER_MASK              0x18
374 #define GTP_EXT_QOS_DEL_ERR_SDU_MASK            0x07
375 #define GTP_EXT_QOS_RES_BER_MASK                0xF0
376 #define GTP_EXT_QOS_SDU_ERR_RATIO_MASK          0x0F
377 #define GTP_EXT_QOS_TRANS_DELAY_MASK            0xFC
378 #define GTP_EXT_QOS_TRAF_HANDL_PRIORITY_MASK    0x03
379
380 /* Definition of Radio Priority's masks */
381 #define GTPv1_EXT_RP_NSAPI_MASK                 0xF0
382 #define GTPv1_EXT_RP_SPARE_MASK                 0x08
383 #define GTPv1_EXT_RP_MASK                       0x07
384
385 /* definitions of GTP messages */
386 #define GTP_MSG_UNKNOWN                 0x00
387 #define GTP_MSG_ECHO_REQ                0x01
388 #define GTP_MSG_ECHO_RESP               0x02
389 #define GTP_MSG_VER_NOT_SUPP            0x03
390 #define GTP_MSG_NODE_ALIVE_REQ          0x04
391 #define GTP_MSG_NODE_ALIVE_RESP         0x05
392 #define GTP_MSG_REDIR_REQ               0x06
393 #define GTP_MSG_REDIR_RESP              0x07
394 #define GTP_MSG_CREATE_PDP_REQ          0x10
395 #define GTP_MSG_CREATE_PDP_RESP         0x11
396 #define GTP_MSG_UPDATE_PDP_REQ          0x12
397 #define GTP_MSG_UPDATE_PDP_RESP         0x13
398 #define GTP_MSG_DELETE_PDP_REQ          0x14
399 #define GTP_MSG_DELETE_PDP_RESP         0x15
400 #define GTP_MSG_CREATE_AA_PDP_REQ       0x16    /* 2G */
401 #define GTP_MSG_CREATE_AA_PDP_RESP      0x17    /* 2G */
402 #define GTP_MSG_DELETE_AA_PDP_REQ       0x18    /* 2G */
403 #define GTP_MSG_DELETE_AA_PDP_RESP      0x19    /* 2G */
404 #define GTP_MSG_ERR_IND                 0x1A
405 #define GTP_MSG_PDU_NOTIFY_REQ          0x1B
406 #define GTP_MSG_PDU_NOTIFY_RESP         0x1C
407 #define GTP_MSG_PDU_NOTIFY_REJ_REQ      0x1D
408 #define GTP_MSG_PDU_NOTIFY_REJ_RESP     0x1E
409 #define GTP_MSG_SUPP_EXT_HDR            0x1F
410 #define GTP_MSG_SEND_ROUT_INFO_REQ      0x20
411 #define GTP_MSG_SEND_ROUT_INFO_RESP     0x21
412 #define GTP_MSG_FAIL_REP_REQ            0x22
413 #define GTP_MSG_FAIL_REP_RESP           0x23
414 #define GTP_MSG_MS_PRESENT_REQ          0x24
415 #define GTP_MSG_MS_PRESENT_RESP         0x25
416 #define GTP_MSG_IDENT_REQ               0x30
417 #define GTP_MSG_IDENT_RESP              0x31
418 #define GTP_MSG_SGSN_CNTXT_REQ          0x32
419 #define GTP_MSG_SGSN_CNTXT_RESP         0x33
420 #define GTP_MSG_SGSN_CNTXT_ACK          0x34
421 #define GTP_MSG_FORW_RELOC_REQ          0x35
422 #define GTP_MSG_FORW_RELOC_RESP         0x36
423 #define GTP_MSG_FORW_RELOC_COMP         0x37
424 #define GTP_MSG_RELOC_CANCEL_REQ        0x38
425 #define GTP_MSG_RELOC_CANCEL_RESP       0x39
426 #define GTP_MSG_FORW_SRNS_CNTXT         0x3A
427 #define GTP_MSG_FORW_RELOC_ACK          0x3B
428 #define GTP_MSG_FORW_SRNS_CNTXT_ACK     0x3C
429 #define GTP_MSG_DATA_TRANSF_REQ         0xF0
430 #define GTP_MSG_DATA_TRANSF_RESP        0xF1
431 #define GTP_MSG_TPDU                    0xFF
432
433 static const value_string message_type[] = {
434         { GTP_MSG_UNKNOWN,              "For future use" },
435         { GTP_MSG_ECHO_REQ,             "Echo request" },
436         { GTP_MSG_ECHO_RESP,            "Echo response" },
437         { GTP_MSG_VER_NOT_SUPP,         "Version not supported" },
438         { GTP_MSG_NODE_ALIVE_REQ,       "Node alive request" },
439         { GTP_MSG_NODE_ALIVE_RESP,      "Node alive response" },
440         { GTP_MSG_REDIR_REQ,            "Redirection request" },
441         { GTP_MSG_REDIR_RESP,           "Redirection response" },
442         { GTP_MSG_CREATE_PDP_REQ,       "Create PDP context request" },
443         { GTP_MSG_CREATE_PDP_RESP,      "Create PDP context response" },
444         { GTP_MSG_UPDATE_PDP_REQ,       "Update PDP context request" },
445         { GTP_MSG_UPDATE_PDP_RESP,      "Update PDP context response" },
446         { GTP_MSG_DELETE_PDP_REQ,       "Delete PDP context request" },
447         { GTP_MSG_DELETE_PDP_RESP,      "Delete PDP context response" },
448         { GTP_MSG_CREATE_AA_PDP_REQ,    "Create AA PDP Context Request" },
449         { GTP_MSG_CREATE_AA_PDP_RESP,   "Create AA PDP Context Response" },
450         { GTP_MSG_DELETE_AA_PDP_REQ,    "Delete AA PDP Context Request" },
451         { GTP_MSG_DELETE_AA_PDP_RESP,   "Delete AA PDP Context Response" },
452         { GTP_MSG_ERR_IND,              "Error indication" },
453         { GTP_MSG_PDU_NOTIFY_REQ,       "PDU notification request" },
454         { GTP_MSG_PDU_NOTIFY_RESP,      "PDU notification response" },
455         { GTP_MSG_PDU_NOTIFY_REJ_REQ,   "PDU notification reject request" },
456         { GTP_MSG_PDU_NOTIFY_REJ_RESP,  "PDU notification reject response" },
457         { GTP_MSG_SUPP_EXT_HDR,         "Supported extension header notification" },
458         { GTP_MSG_SEND_ROUT_INFO_REQ,   "Send routing information for GPRS request" },
459         { GTP_MSG_SEND_ROUT_INFO_RESP,  "Send routing information for GPRS response" },
460         { GTP_MSG_FAIL_REP_REQ,         "Failure report request" },
461         { GTP_MSG_FAIL_REP_RESP,        "Failure report response" },
462         { GTP_MSG_MS_PRESENT_REQ,       "Note MS GPRS present request" },
463         { GTP_MSG_MS_PRESENT_RESP,      "Note MS GPRS present response" },
464         { GTP_MSG_IDENT_REQ,            "Identification request" },
465         { GTP_MSG_IDENT_RESP,           "Identification response" },
466         { GTP_MSG_SGSN_CNTXT_REQ,       "SGSN context request" },
467         { GTP_MSG_SGSN_CNTXT_RESP,      "SGSN context response" },
468         { GTP_MSG_SGSN_CNTXT_ACK,       "SGSN context acknowledgement" },
469         { GTP_MSG_FORW_RELOC_REQ,       "Forward relocation request" },
470         { GTP_MSG_FORW_RELOC_RESP,      "Forward relocation response" },
471         { GTP_MSG_FORW_RELOC_COMP,      "Forward relocation complete" },
472         { GTP_MSG_RELOC_CANCEL_REQ,     "Relocation cancel request" },
473         { GTP_MSG_RELOC_CANCEL_RESP,    "Relocation cancel response" },
474         { GTP_MSG_FORW_SRNS_CNTXT,      "Forward SRNS context" },
475         { GTP_MSG_FORW_RELOC_ACK,       "Forward relocation complete acknowledge" },
476         { GTP_MSG_FORW_SRNS_CNTXT_ACK,  "Forward SRNS context acknowledge" },
477         { GTP_MSG_DATA_TRANSF_REQ,      "Data record transfer request" },
478         { GTP_MSG_DATA_TRANSF_RESP,     "Data record transfer response" },
479         { GTP_MSG_TPDU,                 "T-PDU" },
480         { 0, NULL }
481 };
482
483 /* definitions of fields in extension header */
484 #define GTP_EXT_CAUSE           0x01
485 #define GTP_EXT_IMSI            0x02
486 #define GTP_EXT_RAI             0x03
487 #define GTP_EXT_TLLI            0x04
488 #define GTP_EXT_PTMSI           0x05
489 #define GTP_EXT_QOS_GPRS        0x06
490 #define GTP_EXT_REORDER         0x08
491 #define GTP_EXT_AUTH_TRI        0x09
492 #define GTP_EXT_MAP_CAUSE       0x0B
493 #define GTP_EXT_PTMSI_SIG       0x0C
494 #define GTP_EXT_MS_VALID        0x0D
495 #define GTP_EXT_RECOVER         0x0E
496 #define GTP_EXT_SEL_MODE        0x0F
497
498 #define GTP_EXT_16              0x10
499 #define GTP_EXT_FLOW_LABEL      0x10    
500 #define GTP_EXT_TEID            0x10    /* 0xFF10 3G */
501
502 #define GTP_EXT_17              0x11
503 #define GTP_EXT_FLOW_SIG        0x11    
504 #define GTP_EXT_TEID_CP         0x11    /* 0xFF11 3G */
505
506 #define GTP_EXT_18              0x12
507 #define GTP_EXT_FLOW_II         0x12    
508 #define GTP_EXT_TEID_II         0x12    /* 0xFF12 3G*/
509
510 #define GTP_EXT_19              0x13
511 #define GTP_EXT_MS_REASON       0x13    /* same as 0x1D GTPv1_EXT_MS_REASON */
512 #define GTP_EXT_TEAR_IND        0x13    /* 0xFF13 3G*/
513
514 #define GTP_EXT_NSAPI           0x14    /* 3G */
515 #define GTP_EXT_RANAP_CAUSE     0x15    /* 3G */
516 #define GTP_EXT_RAB_CNTXT       0x16    /* 3G */
517 #define GTP_EXT_RP_SMS          0x17    /* 3G */
518 #define GTP_EXT_RP              0x18    /* 3G */
519 #define GTP_EXT_PKT_FLOW_ID     0x19    /* 3G */
520 #define GTP_EXT_CHRG_CHAR       0x1A    /* 3G */
521 #define GTP_EXT_TRACE_REF       0x1B    /* 3G */
522 #define GTP_EXT_TRACE_TYPE      0x1C    /* 3G */
523 #define GTPv1_EXT_MS_REASON     0x1D    /* 3G */
524 #define GTP_EXT_TR_COMM         0x7E    /* charging */
525 #define GTP_EXT_CHRG_ID         0x7F
526 #define GTP_EXT_USER_ADDR       0x80
527 #define GTP_EXT_MM_CNTXT        0x81
528 #define GTP_EXT_PDP_CNTXT       0x82
529 #define GTP_EXT_APN             0x83
530 #define GTP_EXT_PROTO_CONF      0x84
531 #define GTP_EXT_GSN_ADDR        0x85
532 #define GTP_EXT_MSISDN          0x86
533 #define GTP_EXT_QOS_UMTS        0x87    /* 3G */
534 #define GTP_EXT_AUTH_QUI        0x88    /* 3G */
535 #define GTP_EXT_TFT             0x89    /* 3G */
536 #define GTP_EXT_TARGET_ID       0x8A    /* 3G */
537 #define GTP_EXT_UTRAN_CONT      0x8B    /* 3G */
538 #define GTP_EXT_RAB_SETUP       0x8C    /* 3G */
539 #define GTP_EXT_HDR_LIST        0x8D    /* 3G */
540 #define GTP_EXT_TRIGGER_ID      0x8E    /* 3G */
541 #define GTP_EXT_OMC_ID          0x8F    /* 3G */
542 #define GTP_EXT_REL_PACK        0xF9    /* charging */
543 #define GTP_EXT_CAN_PACK        0xFA    /* charging */
544 #define GTP_EXT_CHRG_ADDR       0xFB
545 #define GTP_EXT_DATA_REQ        0xFC    /* charging */
546 #define GTP_EXT_DATA_RESP       0xFD    /* charging */
547 #define GTP_EXT_NODE_ADDR       0xFE    /* charging */
548 #define GTP_EXT_PRIV_EXT        0xFF
549
550 static const value_string gtp_val[] = {
551         { GTP_EXT_CAUSE,        "Cause of operation" },
552         { GTP_EXT_IMSI,         "IMSI " },
553         { GTP_EXT_RAI,          "Routing Area Identity" },
554         { GTP_EXT_TLLI,         "Temporary Logical Link Identity" },
555         { GTP_EXT_PTMSI,        "Packet TMSI" },
556         { GTP_EXT_QOS_GPRS,     "Quality of Service" },
557         { GTP_EXT_REORDER,      "Reorder required" },
558         { GTP_EXT_AUTH_TRI,     "Authentication triplets" },
559         { GTP_EXT_MAP_CAUSE,    "MAP cause" },
560         { GTP_EXT_PTMSI_SIG,    "P-TMSI signature" },
561         { GTP_EXT_MS_VALID,     "MS validated" },
562         { GTP_EXT_RECOVER,      "Recovery" },
563         { GTP_EXT_SEL_MODE,     "Selection mode" },
564
565         { GTP_EXT_16,           "Flow label data I" },
566         { GTP_EXT_FLOW_LABEL,   "Flow label data I" },
567         { GTP_EXT_TEID,         "Tunnel Endpoint Identifier Data I" },          /* 3G */
568         
569         { GTP_EXT_17,           "Flow label signalling" },
570         { GTP_EXT_FLOW_SIG,     "Flow label signalling" },
571         { GTP_EXT_TEID_CP,      "Tunnel Endpoint Identifier Data Control Plane" },      /* 3G */
572         
573         { GTP_EXT_18,           "Flow label data II" },
574         { GTP_EXT_FLOW_II,      "Flow label data II" },
575         { GTP_EXT_TEID_II,      "Tunnel Endpoint Identifier Data II" },         /* 3G */
576         
577         { GTP_EXT_19,           "MS not reachable reason" },
578         { GTP_EXT_MS_REASON,    "MS not reachable reason" },
579         { GTP_EXT_TEAR_IND,     "Teardown ID" },                                        /* 3G */
580         
581         { GTP_EXT_NSAPI,        "NSAPI" },                                              /* 3G */
582         { GTP_EXT_RANAP_CAUSE,  "RANAP cause" },                                        /* 3G */
583         { GTP_EXT_RAB_CNTXT,    "RAB context" },                                        /* 3G */
584         { GTP_EXT_RP_SMS,       "Radio Priority for MO SMS" },                  /* 3G */
585         { GTP_EXT_RP,           "Radio Priority" },                                     /* 3G */
586         { GTP_EXT_PKT_FLOW_ID,  "Packet Flow ID " },                                    /* 3G */
587         { GTP_EXT_CHRG_CHAR,    "Charging characteristics" },                           /* 3G */
588         { GTP_EXT_TRACE_REF,    "Trace references" },                                   /* 3G */
589         { GTP_EXT_TRACE_TYPE,   "Trace type" },                                 /* 3G */
590         { GTPv1_EXT_MS_REASON,  "MS not reachable reason" },                            /* 3G */
591         { GTP_EXT_TR_COMM,      "Packet transfer command" },                            /* charging */
592         { GTP_EXT_CHRG_ID,      "Charging ID" },
593         { GTP_EXT_USER_ADDR,    "End user address " },
594         { GTP_EXT_MM_CNTXT,     "MM context" },
595         { GTP_EXT_PDP_CNTXT,    "PDP context" },
596         { GTP_EXT_APN,          "Access Point Name" },
597         { GTP_EXT_PROTO_CONF,   "Protocol configuration options" },
598         { GTP_EXT_GSN_ADDR,     "GSN address" },
599         { GTP_EXT_MSISDN,       "MS international PSTN/ISDN number" },
600         { GTP_EXT_QOS_UMTS,     "Quality of service (UMTS)" },                  /* 3G */
601         { GTP_EXT_AUTH_QUI,     "Authentication quintuplets" },                 /* 3G */
602         { GTP_EXT_TFT,          "Traffic Flow Template (TFT)" },                        /* 3G */
603         { GTP_EXT_TARGET_ID,    "Target (RNC) identification" },                        /* 3G */
604         { GTP_EXT_UTRAN_CONT,   "UTRAN transparent field" },                            /* 3G */
605         { GTP_EXT_RAB_SETUP,    "RAB setup information" },                              /* 3G */
606         { GTP_EXT_HDR_LIST,     "Extension Header Types List " },                       /* 3G */
607         { GTP_EXT_TRIGGER_ID,   "Trigger Id " },                                        /* 3G */
608         { GTP_EXT_OMC_ID,       "OMC Identity " },                                      /* 3G */
609         { GTP_EXT_REL_PACK,     "Sequence numbers of released packets IE" },            /* charging */
610         { GTP_EXT_CAN_PACK,     "Sequence numbers of canceled packets IE" },            /* charging */
611         { GTP_EXT_CHRG_ADDR,    "Charging Gateway address" },
612         { GTP_EXT_DATA_REQ,     "Data record packet" },                         /* charging */
613         { GTP_EXT_DATA_RESP,    "Requests responded" },                         /* charging */
614         { GTP_EXT_NODE_ADDR,    "Address of recommended node" },                        /* charging */
615         { GTP_EXT_PRIV_EXT,     "Private Extension " },
616         { 0, NULL }
617 };
618
619 /* GPRS:        9.60 v7.6.0, page 37
620  * UMTS:        29.060 v4.0, page 45 
621  */
622 static const value_string cause_type[] = {
623         { 0,    "Request IMSI" },
624         { 1,    "Request IMEI" },
625         { 2,    "Request IMSI and IMEI" },
626         { 3,    "No identity needed" },
627         { 4,    "MS refuses" },
628         { 5,    "MS is not GPRS responding" },
629         { 59,   "System failure" },     /* charging */
630         { 60,   "The transmit buffers are becoming full" },     /* charging */
631         { 61,   "The receive buffers are becoming full" },      /* charging */
632         { 62,   "Another node is about to go down" },   /* charging */
633         { 63,   "This node is about to go down" },      /* charging */
634         { 128,  "Request accepted" },
635         { 192,  "Non-existent" },
636         { 193,  "Invalid message format" },
637         { 194,  "IMSI not known" },
638         { 195,  "MS is GPRS detached" },
639         { 196,  "MS is not GPRS responding" },
640         { 197,  "MS refuses" },
641         { 198,  "Version not supported" },
642         { 199,  "No resource available" },
643         { 200,  "Service not supported" },
644         { 201,  "Mandatory IE incorrect" },
645         { 202,  "Mandatory IE missing" },
646         { 203,  "Optional IE incorrect" },
647         { 204,  "System failure" },
648         { 205,  "Roaming restriction" },
649         { 206,  "P-TMSI signature mismatch" },
650         { 207,  "GPRS connection suspended" },
651         { 208,  "Authentication failure" },
652         { 209,  "User authentication failed" },
653         { 210,  "Context not found" },
654         { 211,  "All PDP dynamic addresses are occupied" },
655         { 212,  "No memory is available" },
656         { 213,  "Relocation failure" },
657         { 214,  "Unknown mandatory extension header" },
658         { 215,  "Semantic error in the TFT operation" },
659         { 216,  "Syntactic error in the TFT operation" },
660         { 217,  "Semantic errors in packet filter(s)" },
661         { 218,  "Syntactic errors in packet filter(s)" },
662         { 219,  "Missing or unknown APN" },
663         { 220,  "Unknown PDP address or PDP type" },
664         { 252,  "Request related to possibly duplicated packets already fulfilled" },   /* charging */
665         { 253,  "Request already fulfilled" },  /* charging */
666         { 254,  "Sequence numbers of released/cancelled packets IE incorrect" },        /* charging */
667         { 255,  "Request not fulfilled" },      /* charging */
668         { 0, NULL }
669 };
670
671 /* GPRS:        9.02 v7.7.0
672  * UMTS:        29.002 v4.2.1, chapter 17.5, page 268
673  * TODO: Check if all map_cause values are included
674  */
675 static const value_string map_cause_type[] = {
676         { 1, "Unknown subscriber" },
677         { 8, "Roaming not allowed" },
678         { 10, "Bearer service not provisioned" },
679         { 11, "Teleservice not provisioned" },
680         { 13, "Call barred" },
681         { 21, "Facility not supported" },
682         { 23, "Update GPRS location" },
683         { 24, "Send routing info for GPRS" },
684         { 26, "Note MS present for GPRS" },
685         { 27, "Absent subscriber" },
686         { 34, "System failure" },
687         { 35, "Data missing" },
688         { 36, "Unexpected data value" },
689         { 44, "Number chenged" },
690         { 45, "Busy subscriber" },
691         { 46, "No subscriber reply" },
692         { 48, "Facility not allowed" },
693         { 0, NULL }
694 };
695
696 static const value_string gsn_addr_type[] = {
697         { 0x00, "IPv4" },
698         { 0x01, "IPv6" },
699         { 0,    NULL },
700 };
701
702 static const value_string pdp_type[] = {
703         { 0x00, "X.25" },
704         { 0x01, "PPP" },
705         { 0x02, "OSP:IHOSS" },
706         { 0x21, "IPv4" },
707         { 0x57, "IPv6" },
708         { 0, NULL }
709 };
710
711 static const value_string pdp_org_type[] = {
712         { 0, "ETSI" },
713         { 1, "IETF" },
714         { 0, NULL }
715 };
716
717 static const value_string qos_delay_type[] = {
718         { 0x00, "Subsribed delay class (in MS to network direction)" },
719         { 0x01, "Delay class 1" },
720         { 0x02, "Delay class 2" },
721         { 0x03, "Delay class 3" },
722         { 0x04, "Delay class 4 (best effort)" },
723         { 0x07, "Reserved" },
724         { 0, NULL }
725 };
726
727 static const value_string qos_reliability_type[] = {
728         { 0x00, "Subscribed reliability class (in MS to network direction)" },
729         { 0x01, "Ack GTP/LLC/RLC, Protected data" },
730         { 0x02, "Unack GTP, Ack LLC/RLC, Protected data" },
731         { 0x03, "Unack GTP/LLC, Ack RLC, Protected data" },
732         { 0x04, "Unack GTP/LLC/RLC, Protected data" },
733         { 0x05, "Unack GTP/LLC/RLC, Unprotected data" },
734         { 0x07, "Reserved" },
735         { 0, NULL }
736 };
737
738 static const value_string qos_peak_type[] = {
739         { 0x00, "Subscribed peak throughput (in MS to network direction)" },
740         { 0x01, "Up to 1 000 oct/s" },
741         { 0x02, "Up to 2 000 oct/s" },
742         { 0x03, "Up to 4 000 oct/s" },
743         { 0x04, "Up to 8 000 oct/s" },
744         { 0x05, "Up to 16 000 oct/s" },
745         { 0x06, "Up to 32 000 oct/s" },
746         { 0x07, "Up to 64 000 oct/s" },
747         { 0x08, "Up to 128 000 oct/s" },
748         { 0x09, "Up to 256 000 oct/s" },
749 /* QoS Peak throughput classes from 0x0A to 0x0F (from 10 to 15) are subscribed */ 
750         { 0x0A, "Reserved" },
751         { 0x0B, "Reserved" },
752         { 0x0C, "Reserved" },
753         { 0x0D, "Reserved" },
754         { 0x0E, "Reserved" },
755         { 0x0F, "Reserved" },
756         { 0, NULL }
757 };
758
759 static const value_string qos_precedence_type[] = {
760         { 0x00, "Subscribed precedence (in MS to network direction)" },
761         { 0x01, "High priority" },
762         { 0x02, "Normal priority" },
763         { 0x03, "Low priority" },
764         { 0x07, "Reserved" },
765         { 0, NULL }
766 };
767
768 static const value_string qos_mean_type[] = {
769         { 0x00, "Subscribed mean throughput (in MS to network direction)" },
770         { 0x01, "100 oct/h" },          /* Class 2 */
771         { 0x02, "200 oct/h" },          /* Class 3 */
772         { 0x03, "500 oct/h" },          /* Class 4 */
773         { 0x04, "1 000 oct/h" },        /* Class 5 */
774         { 0x05, "2 000 oct/h" },        /* Class 6 */
775         { 0x06, "5 000 oct/h" },        /* Class 7 */
776         { 0x07, "10 000 oct/h" },       /* Class 8 */
777         { 0x08, "20 000 oct/h" },       /* Class 9 */
778         { 0x09, "50 000 oct/h" },       /* Class 10 */
779         { 0x0A, "100 000 oct/h" },      /* Class 11 */
780         { 0x0B, "200 000 oct/h" },      /* Class 12 */
781         { 0x0C, "500 000 oct/h" },      /* Class 13 */
782         { 0x0D, "1 000 000 oct/h" },    /* Class 14 */
783         { 0x0E, "2 000 000 oct/h" },    /* Class 15 */
784         { 0x0F, "5 000 000 oct/h" },    /* Class 16 */
785         { 0x10, "10 000 000 oct/h" },   /* Class 17 */
786         { 0x11, "20 000 000 oct/h" },   /* Class 18 */
787         { 0x12, "50 000 000 oct/h" },   /* Class 19 */
788 /* QoS Mean throughput classes from 0x13 to 0x1E (from 19 to 30) are subscribed */
789         { 0x13, "Reserved" },
790         { 0x14, "Reserved" },
791         { 0x15, "Reserved" },
792         { 0x16, "Reserved" },
793         { 0x17, "Reserved" },
794         { 0x18, "Reserved" },
795         { 0x19, "Reserved" },
796         { 0x1A, "Reserved" },
797         { 0x1B, "Reserved" },
798         { 0x1C, "Reserved" },
799         { 0x1D, "Reserved" },
800         { 0x1E, "Reserved" },
801         { 0x1F, "Best effort" },        /* Class 1 */
802         { 0, NULL }
803 };
804
805 static const value_string qos_del_err_sdu[] = {
806         { 0x00, "Subscribed delivery of erroneous SDUs (in MS to network direction)" },
807         { 0x01, "No detect ('-')" },
808         { 0x02, "Erroneous SDUs are delivered ('yes')" },
809         { 0x03, "Erroneous SDUs are not delivered ('no')" },
810         { 0x07, "Reserved" },           /* All other values are reserved */
811         { 0, NULL }
812 };
813
814 static const value_string qos_del_order[] = {
815         { 0x00, "Subscribed delivery order (in MS to network direction)" },
816         { 0x01, "With delivery order ('yes')" },
817         { 0x02, "Without delivery order ('no')" },
818         { 0x03, "Reserved" },           /* All other values are reserved */
819         { 0, NULL }
820 };
821
822 static const value_string qos_traf_class[] = {
823         { 0x00, "Subscribed traffic class (in MS to network direction)" },
824         { 0x01, "Conversational class" },
825         { 0x02, "Streaming class" },
826         { 0x03, "Interactive class" },
827         { 0x04, "Background class" },
828         { 0x07, "Reserved" },           /* All other values are reserved */
829         { 0, NULL }
830 };
831
832 static const value_string qos_max_sdu_size[] = {
833         { 0x00, "Subscribed maximum SDU size (in MS to network direction" },
834         /* For values from 0x01 to 0x96 (from 1 to 150), use a granularity of 10 octets */ 
835         { 0x97, "1502 octets" },
836         { 0x98, "1510 octets" },
837         { 0x99, "1520 octets" },
838         { 0, NULL }                                     /* All other values are reserved */
839 };
840
841 static const value_string qos_max_ul[] = {
842         { 0x00, "Subscribed maximum bit rate for uplink (in MS to network direction)" },
843         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
844         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
845         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
846         { 0xFF, "0 kbps" },
847         { 0, NULL }
848 };
849
850 static const value_string qos_max_dl[] = {
851         { 0x00, "Subscribed maximum bit rate for downlink (in MS to network direction)" },
852         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
853         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
854         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
855         { 0xFF, "0 kbps" },
856         { 0, NULL }
857 };
858
859 static const value_string qos_res_ber[] = {
860         { 0x00, "Subscribed residual BER (in MS to network direction)" },
861         { 0x01, "1/20 = 5x10^-2" },
862         { 0x02, "1/100 = 1x10^-2" },
863         { 0x03, "1/200 = 5x10^-3" },
864         { 0x04, "1/250 = 4x10^-3" },
865         { 0x05, "1/1 000 = 1x10^-3" },
866         { 0x06, "1/10 000 = 1x10^-4" },
867         { 0x07, "1/100 000 = 1x10^-5" },
868         { 0x08, "1/1 000 000 = 1x10^-6" },
869         { 0x09, "3/50 000 000 = 6x10^-8" },
870         { 0x0F, "Reserved" },           /* All other values are reserved */
871         { 0, NULL }
872 };
873
874 static const value_string qos_sdu_err_ratio[] = {
875         { 0x00, "Subscribed SDU error ratio (in MS to network direction)" },
876         { 0x01, "1/100 = 1x10^-2" },
877         { 0x02, "7/1000 = 7x10^-3" },
878         { 0x03, "1/1 000 = 1x10^-3" },
879         { 0x04, "1/10 000 = 1x10^-4" },
880         { 0x05, "1/100 000 = 1x10^-5" },
881         { 0x06, "1/1 000 000 = 1x10^-6" },
882         { 0x07, "1/10 = 1x10^-1" },
883         { 0x0F, "Reserved" },           /* All other values are reserved */
884         { 0, NULL }
885 }; 
886
887 static const value_string qos_traf_handl_prio[] = {
888         { 0x00, "Subscribed traffic handling priority (in MS to network direction)" },
889         { 0x01, "Priority level 1" },
890         { 0x02, "Priority level 2" },
891         { 0x03, "Priority level 3" },
892         { 0, NULL }
893 };
894
895 static const value_string qos_trans_delay[] = {
896         { 0x00, "Subscribed Transfer Delay (in MS to network direction)" },
897         { 0x01, "10 ms" },      /* Using a granularity of 10 ms */
898         { 0x02, "20 ms" },
899         { 0x03, "30 ms" },
900         { 0x04, "40 ms" },
901         { 0x05, "50 ms" },
902         { 0x06, "60 ms" },
903         { 0x07, "70 ms" },
904         { 0x08, "80 ms" },
905         { 0x09, "90 ms" },
906         { 0x0A, "100 ms" },
907         { 0x0B, "110 ms" },
908         { 0x0C, "120 ms" },
909         { 0x0D, "130 ms" },
910         { 0x0E, "140 ms" },
911         { 0x0F, "150 ms" },
912         { 0x10, "200 ms" },     /* (For values from 0x10 to 0x1F, value = 200 ms + (value - 0x10) * 50 ms */
913         { 0x11, "250 ms" },
914         { 0x12, "300 ms" },
915         { 0x13, "350 ms" },
916         { 0x14, "400 ms" },
917         { 0x15, "450 ms" },
918         { 0x16, "500 ms" },
919         { 0x17, "550 ms" },
920         { 0x18, "600 ms" },
921         { 0x19, "650 ms" },
922         { 0x1A, "700 ms" },
923         { 0x1B, "750 ms" },
924         { 0x1C, "800 ms" },
925         { 0x1D, "850 ms" },
926         { 0x1E, "900 ms" },
927         { 0x1F, "950 ms" },
928         { 0x20, "1000 ms" },    /* For values from 0x20 to 0x3E, value = 1000 ms + (value - 0x20) * 100 ms */
929         { 0x21, "1100 ms" },
930         { 0x22, "1200 ms" },
931         { 0x23, "1300 ms" },
932         { 0x24, "1400 ms" },
933         { 0x25, "1500 ms" },
934         { 0x26, "1600 ms" },
935         { 0x27, "1700 ms" },
936         { 0x28, "1800 ms" },
937         { 0x29, "1900 ms" },
938         { 0x2A, "2000 ms" },
939         { 0x2B, "2100 ms" },
940         { 0x2C, "2200 ms" },
941         { 0x2D, "2300 ms" },
942         { 0x2E, "2400 ms" },
943         { 0x2F, "2500 ms" },
944         { 0x30, "2600 ms" },
945         { 0x31, "2700 ms" },
946         { 0x32, "2800 ms" },
947         { 0x33, "2900 ms" },
948         { 0x34, "3000 ms" },
949         { 0x35, "3100 ms" },
950         { 0x36, "3200 ms" },
951         { 0x37, "3300 ms" },
952         { 0x38, "3400 ms" },
953         { 0x39, "3500 ms" },
954         { 0x3A, "3600 ms" },
955         { 0x3B, "3700 ms" },
956         { 0x3C, "3800 ms" },
957         { 0x3D, "3900 ms" },
958         { 0x3E, "4000 ms" },
959         { 0x3F, "Reserved"},
960         { 0, NULL }
961 };
962
963 static const value_string qos_guar_ul[] = {
964         { 0x00, "Subscribed guaranteed bit rate for uplink (in MS to network direction)" },
965         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
966         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
967         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
968         { 0xFF, "0 kbps" },
969         { 0, NULL }
970 };
971
972 static const value_string qos_guar_dl[] = {
973         { 0x00, "Subscribed guaranteed bit rate for downlink (in MS to network direction)" },
974         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
975         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
976         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
977         { 0xFF, "0 kbps" },
978         { 0, NULL }
979 };
980
981 static const value_string sel_mode_type[] = {
982         { 0,    "MS or network provided APN, subscriber verified" },
983         { 1,    "MS provided APN, subscription not verified" },
984         { 2,    "Network provided APN, subscription not verified" },
985         { 3,    "For future use (Network provided APN, subscription not verified" },/* Shall not be sent. If received, shall be sent as value 2 */
986         { 0,    NULL }
987 };
988
989 static const value_string tr_comm_type[] = {
990         { 1,    "Send data record packet" },
991         { 2,    "Send possibly duplicated data record packet" },
992         { 3,    "Cancel data record packet" },
993         { 4,    "Release data record packet"},
994         { 0,    NULL }
995 };
996
997 /* TODO: CHeck if all ms_reasons are included */
998 static const value_string ms_not_reachable_type[] = {
999         { 0,    "No paging response via the MSC" },
1000         { 1,    "IMSI detached" },
1001         { 2,    "Roaming restriction" },
1002         { 3,    "Deregistered in the HLR for non GPRS" },
1003         { 4,    "MS purge for non GPRS" },
1004         { 5,    "No paging response via the SGSN" },
1005         { 6,    "GPRS detached" },
1006         { 7,    "Deregistered in the HLR for non GPRS" },
1007         { 8,    "MS purged for GPRS" },
1008         { 9,    "Unidentified subscriber via the MSC" },
1009         { 10,   "Unidentified subscriber via the SGSN" },
1010         { 0,    NULL }
1011 };
1012
1013 /* UMTS:        25.413 v3.4.0, chapter 9.2.1.4, page 80
1014  */
1015 static const value_string ranap_cause_type[] = {
1016 /* Radio Network Layer Cause (1-->64) */
1017         { 1, "RAB preempted" },
1018         { 2, "Trelocoverall Expiry" },
1019         { 3, "Trelocprep Expiry" },
1020         { 4, "Treloccomplete Expiry" },
1021         { 5, "Tqueing Expiry" },
1022         { 6, "Relocation Triggered" },
1023         { 7, "TRELOCalloc Expiry" },
1024         { 8, "Unable to Estabish During Relocation" },
1025         { 9, "Unknown Target RNC" },
1026         { 10, "Relocation Cancelled" },
1027         { 11, "Successful Relocation" },
1028         { 12, "Requested Ciphering and/or Integrity Protection Algorithms not Supported" },
1029         { 13, "Change of Ciphering and/or Integrity Protection is not supported" },
1030         { 14, "Failure in the Radio Interface Procedure" },
1031         { 15, "Release due to UTRAN Generated Reason" },
1032         { 16, "User Inactivity" },
1033         { 17, "Time Critical Relocation" },
1034         { 18, "Requested Traffic Class not Available" },
1035         { 19, "Invalid RAB Parameters Value" },
1036         { 20, "Requested Maximum Bit Rate not Available" },
1037         { 21, "Requested Guaranteed Bit Rate not Available" },
1038         { 22, "Requested Transfer Delay not Achievable" },
1039         { 23, "Invalid RAB Parameters Combination" },
1040         { 24, "Condition Violation for SDU Parameters" },
1041         { 25, "Condition Violation for Traffic Handling Priority" },
1042         { 26, "Condition Violation for Guaranteed Bit Rate" },
1043         { 27, "User Plane Versions not Supported" },
1044         { 28, "Iu UP Failure" },
1045         { 29, "Relocation Failure in Target CN/RNC or Target System" },
1046         { 30, "Invalid RAB ID" },
1047         { 31, "No Remaining RAB" },
1048         { 32, "Interaction with other procedure" },
1049         { 33, "Requested Maximum Bit Rate for DL not Available" },
1050         { 34, "Requested Maximum Bit Rate for UL not Available" },
1051         { 35, "Requested Guaranteed Bit Rate for DL not Available" },
1052         { 36, "Requested Guaranteed Bit Rate for UL not Available" },
1053         { 37, "Repeated Integrity Checking Failure" },
1054         { 38, "Requested Report Type not supported" },
1055         { 39, "Request superseded" },
1056         { 40, "Release due to UE generated signalling connection release" },
1057         { 41, "Resource Optimisation Relocation" },
1058         { 42, "Requested Information Not Available" },
1059         { 43, "Relocation desirable for radio reasons" },
1060         { 44, "Relocation not supported in Target RNC or Target System" },
1061         { 45, "Directed Retry" },
1062         { 46, "Radio Connection With UE Lost" },
1063 /* Transport Layer Cause (65-->80) */
1064         { 65, "Signalling Transport Resource Failure" },
1065         { 66, "Iu Transport Connection Failed to Establish" },
1066 /* NAS Cause (81-->96) */
1067         { 81, "User Restriction Start Indication" },
1068         { 82, "User Restriction End Indication" },
1069         { 83, "Normal Release" },
1070 /* Protocol Cause (97-->112) */
1071         { 97, "Transfer Syntax Error" },
1072         { 98, "Semantic Error" },
1073         { 99, "Message not compatible with receiver state" },
1074         { 100, "Abstract Syntax Error (Reject)" },
1075         { 101, "Abstract Syntax Error (Ignore and Notify)" },
1076         { 102, "Abstract Syntax Error (Falsely Constructed Message" },
1077 /* Miscellaneous Cause (113-->128) */
1078         { 113, "O & M Intervention" },
1079         { 114, "No Resource Available" },
1080         { 115, "Unspecified Failure" },
1081         { 116, "Network Opimisation" },
1082 /* Non-standard Cause (129-->255) */
1083         { 0, NULL }
1084 };
1085
1086 static const value_string mm_sec_modep[] = {
1087         { 0,    "Used cipher value, UMTS keys and Quintuplets" },
1088         { 1,    "GSM key and triplets" },
1089         { 2,    "UMTS key and quintuplets" },
1090         { 3,    "GSM key and quintuplets" },
1091         { 0,    NULL }
1092 };
1093
1094 static const value_string mm_proto_disc[] = {
1095         { 0x00, "Group call control" },
1096         { 0x01, "Broadcast call control" },
1097         { 0x02, "PDSS1" },
1098         { 0x03, "Call control; call related SS messages" },
1099         { 0x04, "PDSS2" },
1100         { 0x05, "Mobility Management messages for non-GPRS services" },
1101         { 0x06, "Radio Resource management messages" },
1102         { 0x08, "Mobility Management messages for GPRS services" },
1103         { 0x09, "SMS" },
1104         { 0x0A, "Session Management messages" },
1105         { 0x0B, "Non-call related SS messages" },
1106         { 0, NULL }
1107 };
1108
1109 static const value_string mm_rr_mess[] = {
1110         { 0x3C, "RR initialization request" },
1111         { 0x3B, "Additional assignment" },
1112         { 0x3F, "Immediate assignment" },
1113         { 0x39, "Immediate assignment extended" },
1114         { 0x3A, "Immediate assignment reject" },
1115
1116         { 0x35, "Ciphering mode command" },
1117         { 0x32, "Ciphering mode complete" },
1118
1119         { 0x30, "Configuration change command" },
1120         { 0x31, "Configuration change ack" },
1121         { 0x33, "Configuration change reject" },
1122         
1123         { 0x2E, "Assignment command" },
1124         { 0x29, "Assignment complete" },
1125         { 0x2F, "Assigment failure" },
1126         { 0x2B, "Handover command" },
1127         { 0x2C, "Handover complete" },
1128         { 0x28, "Handover failure" },
1129         { 0x2D, "Physical information" },
1130
1131         { 0x08, "RR-cell change order" },
1132         { 0x23, "PDCH assignment command" },
1133
1134         { 0x0D, "Channel release" },
1135         { 0x0A, "Partial release" },
1136         { 0x0F, "PArtial release complete" },
1137
1138         { 0x21, "Paging request type 1" },
1139         { 0x22, "Paging request type 2" },
1140         { 0x24, "Paging request type 3" },
1141         { 0x27, "Paging response" },
1142         { 0x20, "Notification/NCH" },
1143         { 0x25, "Notification/FACCH" },
1144         { 0x26, "Reserved" },
1145         { 0x0B, "Reserved" },
1146
1147         { 0x18, "System information type 8" },
1148         { 0x19, "System information type 1" },
1149         { 0x1A, "System information type 2" },
1150         { 0x1B, "System information type 3" },
1151         { 0x1C, "System information type 4" },
1152         { 0x1D, "System information type 5" },
1153         { 0x1E, "System information type 6" },
1154         { 0x1F, "System information type 7" },
1155
1156         { 0x02, "System information type 2bis" },
1157         { 0x03, "System information type 2ter" },
1158         { 0x05, "System information type 5bis" },
1159         { 0x06, "System information type 5ter" },
1160         { 0x04, "System information 9" },
1161         { 0x00, "System information 13" },
1162         { 0x01, "System information 14" },
1163
1164         { 0x3D, "System information type 16" },
1165         { 0x3E, "System information type 17" },
1166
1167         { 0x10, "Channel mode modify" },
1168         { 0x12, "RR status" },
1169         { 0x17, "Channel mode modify ack" },
1170         { 0x14, "Frequency redefinition " },
1171         { 0x15, "Measurement report" },
1172         { 0x16, "Classmark change" },
1173         { 0x13, "Classmark enquiry" },
1174         { 0x36, "Extended measurement report" },
1175         { 0x37, "Extended measurement order" },
1176         { 0x34, "GPRS suspension request" },
1177
1178         { 0x09, "VGCS uplink grant" },
1179         { 0x0E, "Uplink release" },
1180         { 0x0C, "Uplink free" },
1181         { 0x2A, "Uplink busy" },
1182         { 0x11, "Talker indication" },
1183
1184         { 0, NULL }
1185 };
1186
1187 static const value_string mm_mm_mess[] = {
1188         { 0x01, "IMSI DETACH INDICATION" },
1189         { 0x02, "LOCATION UPDATING ACCEPT" },
1190         { 0x04, "LOCATION UPDATING REJECT" },
1191         { 0x08, "LOCATION UPDATING REQUEST" },
1192         { 0x11, "AUTHENTICATION REJECT" },
1193         { 0x12, "AUTHENTICATION REQUEST" },
1194         { 0x14, "AUTHENTICATION RESPONSE" },
1195         { 0x18, "IDENTITY REQUEST" },
1196         { 0x19, "IDENTITY RESPONSE" },
1197         { 0x1A, "TMSI REALLOCATION COMMAND" },
1198         { 0x1B, "TMSI REALLOCATION COMPLETE" },
1199         { 0x21, "CM SERVICE ACCEPT" },
1200         { 0x22, "CM SERVICE REJECT" },
1201         { 0x23, "CM SERVICE ABORT" },
1202         { 0x24, "CM SERVICE REQUEST" },
1203         { 0x25, "CM SERVICE PROMPT" },
1204         { 0x26, "NOTIFICATION RESPONSE" },
1205         { 0x28, "CM RE-ESTABLISHMENT REQUEST" },
1206         { 0x29, "ABORT" },
1207         { 0x30, "MM NULL" },
1208         { 0x31, "MM STATUS" },
1209         { 0x32, "MM INFORMATION" },
1210         { 0, NULL }
1211 };
1212
1213 static const value_string mm_cc_mess[] = {                      
1214         { 0x00, "escape to nationally specific" },
1215 /*{ 0 x 0 0, "- - - Call establishment messages:" },*/
1216         { 0x01, "ALERTING" },
1217         { 0x08, "CALL CONFIRMED" },
1218         { 0x02, "CALL PROCEEDING" },
1219         { 0x07, "CONNECT" },
1220         { 0x0F, "CONNECT ACKNOWLEDGE" },
1221         { 0x0E, "EMERGENCY SETUP" },
1222         { 0x03, "PROGRESS" },
1223         { 0x04, "CC-ESTABLISHMENT" },
1224         { 0x06, "CC-ESTABLISHMENT CONFIRMED" },
1225         { 0x0B, "RECALL" },
1226         { 0x09, "START CC" },
1227         { 0x05, "SETUP" },
1228 /*{ 0 x 0 1, "- - - Call information phase messages:" },*/
1229         { 0x17, "MODIFY" },
1230         { 0x1F, "MODIFY COMPLETE" },
1231         { 0x13, "MODIFY REJECT" },
1232         { 0x10, "USER INFORMATION" },
1233         { 0x18, "HOLD" },
1234         { 0x19, "HOLD ACKNOWLEDGE" },
1235         { 0x1A, "HOLD REJECT" },
1236         { 0x1C, "RETRIEVE" },
1237         { 0x1D, "RETRIEVE ACKNOWLEDGE" },
1238         { 0x1E, "RETRIEVE REJECT" },
1239 /*{ 0 x 1 0, "- - - Call clearing messages:" },*/
1240         { 0x25, "DISCONNECT" },
1241         { 0x2D, "RELEASE" },
1242         { 0x2A, "RELEASE COMPLETE" },
1243 /*{ 0 x 1 1, "- - - Miscellaneous messages:" },*/
1244         { 0x39, "CONGESTION CONTROL" },
1245         { 0x3E, "NOTIFY" },
1246         { 0x3D, "STATUS" },
1247         { 0x34, "STATUS ENQUIRY" },
1248         { 0x35, "START DTMF" },
1249         { 0x31, "STOP DTMF" },
1250         { 0x32, "STOP DTMF ACKNOWLEDGE" },
1251         { 0x36, "START DTMF ACKNOWLEDGE" },
1252         { 0x37, "START DTMF REJECT" },
1253         { 0x3A, "FACILITY" },
1254         { 0, NULL }
1255 };
1256
1257 static const value_string mm_gprs_mess[] = {
1258         { 0x01, "Attach request" },
1259         { 0x02, "Attach accept" },
1260         { 0x03, "Attach complete" },
1261         { 0x04, "Attach reject" },
1262         { 0x05, "Detach request" },
1263         { 0x06, "Detach accept" },
1264         { 0x08, "Routing area update request" },
1265         { 0x09, "Routing area update accept" },
1266         { 0x0A, "Routing area update complete" },
1267         { 0x0B, "Routing area update reject" },
1268         { 0x10, "P-TMSI reallocation command" },
1269         { 0x11, "P-TMSI reallocation complete" },
1270         { 0x12, "Authentication and ciphering req" },
1271         { 0x13, "Authentication and ciphering resp" },
1272         { 0x14, "Authentication and ciphering rej" },
1273         { 0x15, "Identity request" },
1274         { 0x16, "Identity response" },
1275         { 0x20, "GMM status" },
1276         { 0x21, "GMM information" },
1277         { 0, NULL }
1278 };
1279
1280 static const value_string tft_code_type[] = {
1281         { 0, "Spare" },
1282         { 1, "Create new TFT" },
1283         { 2, "Delete existing TFT" },
1284         { 3, "Add packet filters to existing TFT" },
1285         { 4, "Replace packet filters in existing TFT" },
1286         { 5, "Delete packet filters from existing TFT" },
1287         { 6, "Reserved" },
1288         { 7, "Reserved" },
1289         { 0, NULL }
1290 };
1291
1292 static const value_string cdr_close_type[] = {
1293         { 0, "PDP release" },
1294         { 1, "Volume limit" },
1295         { 2, "Time limit" },
1296         { 3, "SGSN change" },
1297         { 4, "Max changes" },
1298         { 6, "Management" },
1299         { 7, "Abnormal" },
1300         { 0, NULL }
1301 };
1302                         
1303 static dissector_handle_t ip_handle;
1304 static dissector_handle_t ppp_handle;
1305
1306 static int decode_gtp_cause             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1307 static int decode_gtp_imsi              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1308 static int decode_gtp_rai               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1309 static int decode_gtp_tlli              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1310 static int decode_gtp_ptmsi             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1311 static int decode_gtp_qos_gprs          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1312 static int decode_gtp_reorder           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1313 static int decode_gtp_auth_tri          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1314 static int decode_gtp_map_cause         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1315 static int decode_gtp_ptmsi_sig         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1316 static int decode_gtp_ms_valid          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1317 static int decode_gtp_recovery          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1318 static int decode_gtp_sel_mode          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1319 static int decode_gtp_16                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1320 static int decode_gtp_17                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1321 static int decode_gtp_18                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1322 static int decode_gtp_19                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1323 static int decode_gtp_nsapi             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1324 static int decode_gtp_ranap_cause       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1325 static int decode_gtp_rab_cntxt         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1326 static int decode_gtp_rp_sms            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1327 static int decode_gtp_rp                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1328 static int decode_gtp_pkt_flow_id       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1329 static int decode_gtp_chrg_char         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1330 static int decode_gtp_trace_ref         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1331 static int decode_gtp_trace_type        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1332 static int decode_gtp_ms_reason         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1333 static int decode_gtp_tr_comm           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1334 static int decode_gtp_chrg_id           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1335 static int decode_gtp_user_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1336 static int decode_gtp_mm_cntxt          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1337 static int decode_gtp_pdp_cntxt         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1338 static int decode_gtp_apn               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1339 static int decode_gtp_gsn_addr          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1340 static int decode_gtp_proto_conf        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1341 static int decode_gtp_msisdn            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1342 static int decode_gtp_qos_umts          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1343 static int decode_gtp_auth_qui          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1344 static int decode_gtp_tft               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1345 static int decode_gtp_target_id         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1346 static int decode_gtp_utran_cont        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1347 static int decode_gtp_rab_setup         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1348 static int decode_gtp_hdr_list          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1349 static int decode_gtp_trigger_id        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1350 static int decode_gtp_omc_id            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1351 static int decode_gtp_chrg_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1352 static int decode_gtp_rel_pack          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1353 static int decode_gtp_can_pack          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1354 static int decode_gtp_data_req          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1355 static int decode_gtp_data_resp         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1356 static int decode_gtp_node_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1357 static int decode_gtp_priv_ext          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1358 static int decode_gtp_unknown           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1359
1360 typedef struct _gtp_opt {
1361         int   optcode; 
1362 /*      char  *name; */
1363         int  (*decode)(tvbuff_t  *, int, packet_info *, proto_tree *);
1364 } gtp_opt_t;
1365
1366 static const gtp_opt_t gtpopt[] = {
1367         { GTP_EXT_CAUSE,        decode_gtp_cause },
1368         { GTP_EXT_IMSI,         decode_gtp_imsi },
1369         { GTP_EXT_RAI,          decode_gtp_rai },
1370         { GTP_EXT_TLLI,         decode_gtp_tlli },
1371         { GTP_EXT_PTMSI,        decode_gtp_ptmsi },
1372         { GTP_EXT_QOS_GPRS,     decode_gtp_qos_gprs },
1373         { GTP_EXT_REORDER,      decode_gtp_reorder },
1374         { GTP_EXT_AUTH_TRI,     decode_gtp_auth_tri },
1375         { GTP_EXT_MAP_CAUSE,    decode_gtp_map_cause },
1376         { GTP_EXT_PTMSI_SIG,    decode_gtp_ptmsi_sig },
1377         { GTP_EXT_MS_VALID,     decode_gtp_ms_valid },
1378         { GTP_EXT_RECOVER,      decode_gtp_recovery },
1379         { GTP_EXT_SEL_MODE,     decode_gtp_sel_mode },
1380         { GTP_EXT_16,           decode_gtp_16 },
1381         { GTP_EXT_17,           decode_gtp_17 },
1382         { GTP_EXT_18,           decode_gtp_18 },
1383         { GTP_EXT_19,           decode_gtp_19 },
1384         { GTP_EXT_NSAPI,        decode_gtp_nsapi },
1385         { GTP_EXT_RANAP_CAUSE,  decode_gtp_ranap_cause },
1386         { GTP_EXT_RAB_CNTXT,    decode_gtp_rab_cntxt },
1387         { GTP_EXT_RP_SMS,       decode_gtp_rp_sms },
1388         { GTP_EXT_RP,           decode_gtp_rp },
1389         { GTP_EXT_PKT_FLOW_ID,  decode_gtp_pkt_flow_id },
1390         { GTP_EXT_CHRG_CHAR,    decode_gtp_chrg_char },
1391         { GTP_EXT_TRACE_REF,    decode_gtp_trace_ref },
1392         { GTP_EXT_TRACE_TYPE,   decode_gtp_trace_type },
1393         { GTPv1_EXT_MS_REASON,  decode_gtp_ms_reason },
1394         { GTP_EXT_TR_COMM,      decode_gtp_tr_comm },
1395         { GTP_EXT_CHRG_ID,      decode_gtp_chrg_id },
1396         { GTP_EXT_USER_ADDR,    decode_gtp_user_addr },
1397         { GTP_EXT_MM_CNTXT,     decode_gtp_mm_cntxt },
1398         { GTP_EXT_PDP_CNTXT,    decode_gtp_pdp_cntxt },
1399         { GTP_EXT_APN,          decode_gtp_apn },
1400         { GTP_EXT_PROTO_CONF,   decode_gtp_proto_conf },
1401         { GTP_EXT_GSN_ADDR,     decode_gtp_gsn_addr },
1402         { GTP_EXT_MSISDN,       decode_gtp_msisdn },
1403         { GTP_EXT_QOS_UMTS,     decode_gtp_qos_umts },                          /* 3G */
1404         { GTP_EXT_AUTH_QUI,     decode_gtp_auth_qui },                          /* 3G */
1405         { GTP_EXT_TFT,          decode_gtp_tft },                               /* 3G */
1406         { GTP_EXT_TARGET_ID,    decode_gtp_target_id },                 /* 3G */
1407         { GTP_EXT_UTRAN_CONT,   decode_gtp_utran_cont },                        /* 3G */
1408         { GTP_EXT_RAB_SETUP,    decode_gtp_rab_setup },                 /* 3G */
1409         { GTP_EXT_HDR_LIST,     decode_gtp_hdr_list },                          /* 3G */
1410         { GTP_EXT_TRIGGER_ID,   decode_gtp_trigger_id },                        /* 3G */
1411         { GTP_EXT_OMC_ID,       decode_gtp_omc_id },                            /* 3G */
1412         { GTP_EXT_REL_PACK,     decode_gtp_rel_pack },                          /* charging */
1413         { GTP_EXT_CAN_PACK,     decode_gtp_can_pack },                  /* charging */
1414         { GTP_EXT_CHRG_ADDR,    decode_gtp_chrg_addr },
1415         { GTP_EXT_DATA_REQ,     decode_gtp_data_req },                          /* charging */
1416         { GTP_EXT_DATA_RESP,    decode_gtp_data_resp },                 /* charging */
1417         { GTP_EXT_NODE_ADDR,    decode_gtp_node_addr },
1418         { GTP_EXT_PRIV_EXT,     decode_gtp_priv_ext },
1419         { 0,                    decode_gtp_unknown }
1420 };
1421
1422 typedef struct {
1423         guint8          flags;
1424         guint8          message;
1425         guint16         length;
1426         guint16         seq_no;
1427         guint16         flow_label;
1428         guint8          sndcp_no;
1429         guint8          spare[3];
1430         guint8          tid[8];
1431 } _gtpv0_hdr;
1432
1433 typedef struct {
1434         guint8          flags;
1435         guint8          message;
1436         guint16         length;
1437         guint32         teid;
1438 } _gtpv1_hdr;
1439
1440 struct gcdr_ {                                  /* GCDR 118B */
1441         guint8          imsi[8];
1442         guint32         ggsnaddr;
1443         guint32         chrgid;
1444         guint32         sgsnaddr;
1445         gchar           apn[63];
1446         guint8          pdporg;
1447         guint8          pdptype;
1448         guint32         pdpaddr;
1449         guint8          addrflag;
1450         guint8          qos[3];
1451         guint32         uplink;
1452         guint32         downlink;
1453         guint32         timestamp;
1454         guint32         opening;
1455         guint32         duration;
1456         guint8          closecause;
1457         guint32         seqno;
1458         guint8          msisdn[9];
1459 } gcdr;
1460
1461 typedef struct change_ {
1462         guint8          change;
1463         guint32         time1;
1464         guint32         time2;
1465         guint32         uplink;
1466         guint32         downlink;
1467         guint8          qos_req[3];
1468         guint8          qos_neg[3];
1469 } change_t;
1470
1471 struct _scdr {                                  /* SCDR 277B */
1472         guint16         len;
1473         guint8          netini;
1474         guint8          anon;
1475         guint8          imsilen;
1476         guint8          imsi[8];
1477         guint8          imei[8];
1478         guint8          msisdnlen;
1479         guint8          msisdn[10];
1480         guint32         sgsnaddr;
1481         guint8          msclass_notused[12];
1482         guint8          msclass_caplen;
1483         guint8          msclass_cap;
1484         guint16         msclass_capomit;
1485         guint16         lac;
1486         guint8          rac;
1487         guint16         cid;
1488         guint32         chrgid;
1489         guint32         ggsnaddr;
1490         gchar           apn[64];
1491         guint8          pdporg;
1492         guint8          pdptype;
1493         guint32         pdpaddr;
1494         guint8          listind;
1495         change_t        change[5];
1496         guint32         timestamp;
1497         guint32         opening;
1498         guint32         duration;
1499         guint8          sgsnchange;
1500         guint8          closecause;
1501         guint8          diag1;
1502         guint8          diag2;
1503         guint8          diag3;
1504         guint8          diag4;
1505         guint32         diag5;
1506         guint32         seqno;
1507 } scdr;
1508
1509 typedef struct mmchange_ {
1510         guint16         lac;
1511         guint8          rac;
1512         guint16         cid;
1513         guint8          omit[8];
1514 } mmchange_t;
1515
1516 struct _mcdr {                                  /* MCDR 147B */
1517         guint16         len;
1518         guint8          imsilen;
1519         guint8          imsi[8];
1520         guint8          imei[8];
1521         guint8          msisdnlen;
1522         guint8          msisdn[10];
1523         guint32         sgsnaddr;
1524         guint8          msclass_notused[12];
1525         guint8          msclass_caplen;
1526         guint8          msclass_cap;
1527         guint16         msclass_capomit;
1528         guint16         lac;
1529         guint8          rac;
1530         guint16         cid;
1531         guint8          change_count;
1532         mmchange_t      change[5];
1533         guint32         timestamp;
1534         guint32         opening;
1535 /*      guint8          opening[8]; */
1536         guint32         duration;
1537         guint8          sgsnchange;
1538         guint8          closecause;
1539         guint8          diag1;
1540         guint8          diag2;
1541         guint8          diag3;
1542         guint8          diag4;
1543         guint32         diag5;
1544         guint32         seqno;
1545 } mcdr;
1546
1547 struct _socdr {                                         /* SOCDR 80B */
1548         guint16         len;
1549         guint8          imsilen;
1550         guint8          imsi[8];
1551         guint8          imei[8];
1552         guint8          msisdnlen;
1553         guint8          msisdn[10];
1554         guint8          msclass_notused[12];
1555         guint8          msclass_caplen;
1556         guint8          msclass_cap;
1557         guint16         msclass_capomit;
1558         guint8          serv_centr[9];
1559         guint8          rec_ent[9];
1560         guint16         lac;
1561         guint8          rac;
1562         guint16         cid;
1563         guint32         time1;
1564         guint32         time2;
1565         guint8          messref;
1566         guint16         smsres;
1567 } socdr;
1568
1569
1570 struct _stcdr {                                         /* STCDR 79B */
1571         guint16         len;
1572         guint8          imsilen;
1573         guint8          imsi[8];
1574         guint8          imei[8];
1575         guint8          msisdnlen;
1576         guint8          msisdn[10];
1577         guint8          msclass_notused[12];
1578         guint8          msclass_caplen;
1579         guint8          msclass_cap;
1580         guint16         msclass_capomit;
1581         guint8          serv_centr[9];
1582         guint8          rec_ent[9];
1583         guint16         lac;
1584         guint8          rac;
1585         guint16         cid;
1586         guint32         time1;
1587         guint32         time2;
1588         guint16         smsres;
1589 } stcdr;
1590         
1591         guint8          gtp_version = 0;
1592         char            *yesno[] = { "False", "True" };
1593         
1594 static void
1595 col_append_str_gtp(column_info *cinfo, gint el, gchar *proto_name) {
1596         
1597         int     i;
1598         int     max_len;
1599         gchar   _tmp[COL_MAX_LEN];
1600
1601         max_len = COL_MAX_LEN;
1602
1603         for (i = 0; i < cinfo->num_cols; i++) {
1604                 if (cinfo->fmt_matx[i][el]) {
1605                         if (cinfo->col_data[i] != cinfo->col_buf[i]) {
1606                                 
1607                                 strncpy(cinfo->col_buf[i], cinfo->col_data[i], max_len);
1608                                 cinfo->col_buf[i][max_len - 1] = '\0';
1609                         }
1610         
1611                         _tmp[0] = '\0';
1612                         strcat(_tmp, proto_name);
1613                         strcat(_tmp, " <");
1614                         strcat(_tmp, cinfo->col_buf[i]);
1615                         strcat(_tmp, ">");
1616                         cinfo->col_buf[i][0] = '\0';
1617                         strcat(cinfo->col_buf[i], _tmp);
1618                         cinfo->col_data[i] = cinfo->col_buf[i];
1619                 }
1620         }
1621 }
1622
1623 static gchar *
1624 id_to_str(const guint8 *ad) {
1625                 
1626         static gchar    *str[17];
1627         gchar           *p;
1628         guint8          bits8to5, bits4to1, i;
1629         static const    gchar hex_digits[10] = "0123456789";
1630
1631         p = (gchar *)&str[17];
1632         *--p = '\0';
1633         i = 7;
1634         for (;;) {
1635                 bits8to5 = (ad[i] >> 4) & 0x0F;
1636                 bits4to1 = ad[i] & 0x0F;
1637                 if (bits8to5 < 0xA) *--p = hex_digits[bits8to5]; 
1638                 if (bits4to1 < 0xA) *--p = hex_digits[bits4to1];
1639                 if (i == 0) break;
1640                 i--;
1641         }
1642         return p;
1643 }
1644
1645 static gchar *
1646 msisdn_to_str(const guint8 *ad, int len) {
1647                 
1648         static gchar    *str[17];
1649         gchar           *p;
1650         guint8          bits8to5, bits4to1, i;
1651         static const    gchar hex_digits[16] = "0123456789      ";
1652
1653         p = (gchar *)&str[0];
1654         *p = '+';
1655         i = 1;
1656         for (;;) {
1657                 bits8to5 = (ad[i] >> 4) & 0x0F;
1658                 bits4to1 = ad[i] & 0x0F;
1659                 if (bits4to1 < 0xA) *++p = hex_digits[bits4to1];
1660                 if (bits8to5 < 0xA) *++p = hex_digits[bits8to5];
1661                 if (i == len-1) break;
1662                 i++;
1663         }
1664         *++p = '\0';
1665         return (gchar *)&str[0];
1666 }
1667
1668 gchar *
1669 time_int_to_str (guint32 time)
1670 {
1671
1672         nstime_t        nstime;
1673
1674         nstime.secs = time;
1675         nstime.nsecs = 0;
1676
1677         return abs_time_to_str (&nstime);
1678 }
1679
1680 gchar *
1681 rel_time_int_to_str (guint32 time)
1682 {
1683
1684         nstime_t        nstime;
1685
1686         nstime.secs = time;
1687         nstime.nsecs = 0;
1688
1689         return rel_time_to_str (&nstime);
1690 }
1691
1692 /* Next definitions and function check_field_presence checks if given field 
1693  * in GTP packet is compliant with ETSI 
1694  */
1695 typedef struct _header {
1696         guint8          code;
1697         guint8          presence;
1698 } ext_header;
1699
1700 typedef struct _message {
1701         guint8          code;
1702         ext_header      fields[32];
1703 } _gtp_mess_items;
1704
1705 /* ---------------------
1706  * GPRS messages 
1707  * ---------------------*/
1708 _gtp_mess_items gprs_mess_items[] = {
1709
1710 {
1711         GTP_MSG_ECHO_REQ, {                                     
1712                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1713                 { 0,                    0 }
1714         }
1715 },
1716 {
1717         GTP_MSG_ECHO_RESP, {
1718                 { GTP_EXT_RECOVER,      MANDATORY },
1719                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1720                 { 0,                    0 }
1721         }
1722 },
1723 {
1724         GTP_MSG_VER_NOT_SUPP, {
1725                 { 0,                    0 }
1726         }
1727 },
1728 {
1729         GTP_MSG_NODE_ALIVE_REQ, {
1730                 { GTP_EXT_NODE_ADDR,    MANDATORY },
1731                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1732                 { 0,                    0 }
1733         }
1734 },
1735 {
1736         GTP_MSG_NODE_ALIVE_RESP, {
1737                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1738                 { 0,                    0 }
1739         }
1740 },
1741 {
1742         GTP_MSG_REDIR_REQ, {
1743                 { GTP_EXT_CAUSE,        MANDATORY },
1744                 { GTP_EXT_NODE_ADDR,    OPTIONAL },
1745                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1746                 { 0,                    0 }
1747         }
1748 },
1749 {
1750         GTP_MSG_REDIR_RESP, {
1751                 { GTP_EXT_CAUSE,        MANDATORY },
1752                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1753                 { 0,                    0 }
1754         }
1755 },
1756
1757         GTP_MSG_CREATE_PDP_REQ, {
1758                 { GTP_EXT_QOS_GPRS,     MANDATORY },
1759                 { GTP_EXT_RECOVER,      OPTIONAL },
1760                 { GTP_EXT_SEL_MODE,     MANDATORY },
1761                 { GTP_EXT_FLOW_LABEL,   MANDATORY },
1762                 { GTP_EXT_FLOW_SIG,     MANDATORY },
1763                 { GTP_EXT_MSISDN,       MANDATORY },
1764                 { GTP_EXT_USER_ADDR,    MANDATORY },
1765                 { GTP_EXT_APN,          MANDATORY },
1766                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1767                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1768                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1769                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1770                 { 0,                    0 }
1771         }
1772 },
1773
1774         GTP_MSG_CREATE_PDP_RESP, {
1775                 { GTP_EXT_CAUSE,        MANDATORY },
1776                 { GTP_EXT_QOS_GPRS,     CONDITIONAL },
1777                 { GTP_EXT_REORDER,      CONDITIONAL },
1778                 { GTP_EXT_RECOVER,      OPTIONAL },
1779                 { GTP_EXT_FLOW_LABEL,   CONDITIONAL },
1780                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
1781                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
1782                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
1783                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1784                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1785                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1786                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
1787                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1788                 { 0,                    0 }
1789         }
1790 },
1791 {       
1792         GTP_MSG_UPDATE_PDP_REQ, {
1793                 { GTP_EXT_QOS_GPRS,     MANDATORY },
1794                 { GTP_EXT_RECOVER,      OPTIONAL },
1795                 { GTP_EXT_FLOW_LABEL,   MANDATORY },
1796                 { GTP_EXT_FLOW_SIG,     MANDATORY },
1797                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1798                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1799                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1800                 { 0,                    0 },
1801         }
1802 },
1803 {
1804         GTP_MSG_UPDATE_PDP_RESP, {
1805                 { GTP_EXT_CAUSE,        MANDATORY },
1806                 { GTP_EXT_QOS_GPRS,     CONDITIONAL },
1807                 { GTP_EXT_RECOVER,      OPTIONAL },
1808                 { GTP_EXT_FLOW_LABEL,   CONDITIONAL },
1809                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
1810                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
1811                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1812                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1813                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
1814                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1815                 { 0,                    0 }
1816         }
1817 },
1818 {
1819         GTP_MSG_DELETE_PDP_REQ, {
1820                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1821                 { 0,                    0 }
1822         }
1823 },
1824 {
1825         GTP_MSG_DELETE_PDP_RESP, {
1826                 { GTP_EXT_CAUSE,        MANDATORY },
1827                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1828                 { 0,                    0 },
1829         }
1830 },
1831 {
1832         GTP_MSG_CREATE_AA_PDP_REQ, {
1833                 { GTP_EXT_QOS_GPRS,     MANDATORY },
1834                 { GTP_EXT_RECOVER,      OPTIONAL },
1835                 { GTP_EXT_SEL_MODE,     MANDATORY },
1836                 { GTP_EXT_FLOW_LABEL,   MANDATORY },
1837                 { GTP_EXT_FLOW_SIG,     MANDATORY },
1838                 { GTP_EXT_USER_ADDR,    MANDATORY },
1839                 { GTP_EXT_APN,          MANDATORY },
1840                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1841                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1842                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1843                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1844                 { 0,                    0 }
1845         }
1846 },
1847 {
1848         GTP_MSG_CREATE_AA_PDP_RESP, {                                   
1849                 { GTP_EXT_CAUSE,        MANDATORY },
1850                 { GTP_EXT_QOS_GPRS,     CONDITIONAL },
1851                 { GTP_EXT_REORDER,      CONDITIONAL },
1852                 { GTP_EXT_RECOVER,      OPTIONAL },
1853                 { GTP_EXT_FLOW_LABEL,   CONDITIONAL },
1854                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
1855                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
1856                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
1857                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1858                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1859                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1860                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
1861                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1862                 { 0,                    0 }
1863         }
1864 },
1865 {
1866         GTP_MSG_DELETE_AA_PDP_REQ, {
1867                 { GTP_EXT_CAUSE,        MANDATORY },
1868                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1869                 { 0,                    0 }
1870         }
1871 },
1872 {
1873         GTP_MSG_DELETE_AA_PDP_RESP, {
1874                 { GTP_EXT_CAUSE,        MANDATORY },
1875                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1876                 { 0,                    0 }
1877         }
1878 },
1879 {
1880         GTP_MSG_ERR_IND, {
1881                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1882                 { 0,                    0 }
1883         }
1884 },
1885 {
1886         GTP_MSG_PDU_NOTIFY_REQ, {
1887                 { GTP_EXT_USER_ADDR,    MANDATORY },
1888                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1889                 { 0,                    0 }
1890         }
1891 },
1892 {       
1893         GTP_MSG_PDU_NOTIFY_RESP, {
1894                 { GTP_EXT_CAUSE,        MANDATORY },
1895                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1896                 { 0,                    0 }
1897         }
1898 },
1899 {
1900         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
1901                 { GTP_EXT_CAUSE,        MANDATORY },
1902                 { GTP_EXT_USER_ADDR,    MANDATORY },
1903                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1904                 { 0,                    0 }
1905         }
1906 },
1907 {
1908         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
1909                 { GTP_EXT_CAUSE,        MANDATORY },
1910                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1911                 { 0,                    0 }
1912         }
1913 },
1914 {
1915         GTP_MSG_SEND_ROUT_INFO_REQ, {
1916                 { GTP_EXT_IMSI,         MANDATORY },
1917                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1918                 { 0,                    0 }
1919         }
1920 },
1921 {
1922         GTP_MSG_SEND_ROUT_INFO_RESP, {
1923                 { GTP_EXT_CAUSE,        MANDATORY },
1924                 { GTP_EXT_IMSI,         MANDATORY },
1925                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
1926                 { GTP_EXT_MS_REASON,    OPTIONAL },
1927                 { GTP_EXT_GSN_ADDR,     OPTIONAL },
1928                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1929                 { 0,                    0 }
1930         }
1931 },
1932 {
1933         GTP_MSG_FAIL_REP_REQ, {
1934                 { GTP_EXT_IMSI,         MANDATORY },
1935                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1936                 { 0,                    0 }
1937         }
1938 },
1939 {
1940         GTP_MSG_FAIL_REP_RESP, {
1941                 { GTP_EXT_CAUSE,        MANDATORY },
1942                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
1943                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1944                 { 0,                    0 }
1945         }
1946 },
1947 {
1948         GTP_MSG_MS_PRESENT_REQ, {
1949                 { GTP_EXT_IMSI,         MANDATORY },
1950                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1951                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1952                 { 0,                    0 }
1953         }
1954 },
1955 {
1956         GTP_MSG_MS_PRESENT_RESP, {
1957                 { GTP_EXT_CAUSE,        MANDATORY },
1958                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1959                 { 0,                    0 }
1960         }
1961 },
1962 {
1963         GTP_MSG_IDENT_REQ, {
1964                 { GTP_EXT_RAI,          MANDATORY },
1965                 { GTP_EXT_PTMSI,        MANDATORY },
1966                 { GTP_EXT_PTMSI_SIG,    OPTIONAL },
1967                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1968                 { 0,                    0 }
1969         }
1970 },
1971 {
1972         GTP_MSG_IDENT_RESP, {
1973                 { GTP_EXT_CAUSE,        MANDATORY },
1974                 { GTP_EXT_IMSI,         CONDITIONAL },
1975                 { GTP_EXT_AUTH_TRI,     OPTIONAL },
1976                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1977                 { 0,                    0 }
1978         }
1979 },
1980 {
1981         GTP_MSG_SGSN_CNTXT_REQ, {
1982                 { GTP_EXT_IMSI,         CONDITIONAL },
1983                 { GTP_EXT_RAI,          MANDATORY },
1984                 { GTP_EXT_TLLI,         MANDATORY },
1985                 { GTP_EXT_PTMSI_SIG,    OPTIONAL },
1986                 { GTP_EXT_MS_VALID,     OPTIONAL },
1987                 { GTP_EXT_FLOW_SIG,     MANDATORY },
1988                 { 0,                    0 }
1989         }
1990 },
1991 {
1992         GTP_MSG_SGSN_CNTXT_RESP, {
1993                 { GTP_EXT_CAUSE,        MANDATORY },
1994                 { GTP_EXT_IMSI,         CONDITIONAL },
1995                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
1996                 { GTP_EXT_MM_CNTXT,     CONDITIONAL },
1997                 { GTP_EXT_PDP_CNTXT,    CONDITIONAL },
1998                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1999                 { 0,                    0 }
2000         }
2001 },
2002 {
2003         GTP_MSG_SGSN_CNTXT_ACK, {
2004                 { GTP_EXT_CAUSE,        MANDATORY },
2005                 { GTP_EXT_FLOW_II,      CONDITIONAL },
2006                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2007                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2008                 { 0,                    0 }
2009         }
2010 },
2011 {
2012         GTP_MSG_DATA_TRANSF_REQ, {
2013                 { GTP_EXT_TR_COMM,      MANDATORY },
2014                 { GTP_EXT_DATA_REQ,     CONDITIONAL },
2015                 { GTP_EXT_REL_PACK,     CONDITIONAL },
2016                 { GTP_EXT_CAN_PACK,     CONDITIONAL },
2017                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2018                 { 0,                    0 }
2019         }
2020 },
2021 {
2022         GTP_MSG_DATA_TRANSF_RESP, {
2023                 { GTP_EXT_CAUSE,        MANDATORY },
2024                 { GTP_EXT_DATA_RESP,    MANDATORY },
2025                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2026                 { 0,                    0 }
2027         }
2028 },
2029 {
2030         0, {
2031                 { 0,                    0 }
2032         }
2033 }
2034 };
2035
2036 /* -----------------------------
2037  * UMTS messages 
2038  * -----------------------------*/
2039 _gtp_mess_items umts_mess_items[] = {
2040
2041 {
2042         GTP_MSG_ECHO_REQ, {                                     
2043                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2044                 { 0,                    0 }
2045         }
2046 },
2047 {
2048         GTP_MSG_ECHO_RESP, {
2049                 { GTP_EXT_RECOVER,      MANDATORY },
2050                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2051                 { 0,                    0 }
2052         }
2053 },
2054 {
2055         GTP_MSG_VER_NOT_SUPP, {
2056                 { 0,                    0 }
2057         }
2058 },
2059 {
2060         GTP_MSG_NODE_ALIVE_REQ, {
2061                 { GTP_EXT_NODE_ADDR,    MANDATORY },
2062                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2063                 { 0,                    0 }
2064         }
2065 },
2066 {
2067         GTP_MSG_NODE_ALIVE_RESP, {
2068                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2069                 { 0,                    0 }
2070         }
2071 },
2072 {
2073         GTP_MSG_REDIR_REQ, {
2074                 { GTP_EXT_CAUSE,        MANDATORY },
2075                 { GTP_EXT_NODE_ADDR,    OPTIONAL },
2076                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2077                 { 0,                    0 }
2078         }
2079 },
2080 {
2081         GTP_MSG_REDIR_REQ, {
2082                 { 0,                    0 }
2083         }
2084 },
2085 {
2086         GTP_MSG_CREATE_PDP_REQ, {
2087                 { GTP_EXT_IMSI,         CONDITIONAL },
2088                 { GTP_EXT_RECOVER,      OPTIONAL },
2089                 { GTP_EXT_SEL_MODE,     CONDITIONAL },
2090                 { GTP_EXT_TEID,         MANDATORY },
2091                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2092                 { GTP_EXT_NSAPI,        MANDATORY },
2093                 { GTP_EXT_NSAPI,        CONDITIONAL },
2094                 { GTP_EXT_CHRG_CHAR,    OPTIONAL },
2095                 { GTP_EXT_TRACE_REF,    OPTIONAL },
2096                 { GTP_EXT_TRACE_TYPE,   OPTIONAL },
2097                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
2098                 { GTP_EXT_APN,          CONDITIONAL },
2099                 { GTP_EXT_PROTO_CONF,   CONDITIONAL },
2100                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2101                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2102                 { GTP_EXT_MSISDN,       CONDITIONAL },
2103                 { GTP_EXT_QOS_UMTS,     MANDATORY },
2104                 { GTP_EXT_TFT,          CONDITIONAL },
2105                 { GTP_EXT_TRIGGER_ID,   OPTIONAL },
2106                 { GTP_EXT_OMC_ID,       OPTIONAL },
2107                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2108                 { 0,                    0 }
2109         }
2110 },
2111 {
2112         GTP_MSG_CREATE_PDP_RESP, {
2113                 { GTP_EXT_CAUSE,        MANDATORY },
2114                 { GTP_EXT_REORDER,      CONDITIONAL },
2115                 { GTP_EXT_RECOVER,      OPTIONAL },
2116                 { GTP_EXT_TEID,         CONDITIONAL },
2117                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2118                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
2119                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
2120                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
2121                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2122                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2123                 { GTP_EXT_QOS_UMTS,     CONDITIONAL },
2124                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
2125                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2126                 { 0,                    0 }
2127         }
2128 },
2129 {       /* checked, SGSN -> GGSN */
2130         GTP_MSG_UPDATE_PDP_REQ, {
2131                 { GTP_EXT_IMSI,         CONDITIONAL },
2132                 { GTP_EXT_RECOVER,      OPTIONAL },
2133                 { GTP_EXT_TEID,         MANDATORY },
2134                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2135                 { GTP_EXT_NSAPI,        MANDATORY },
2136                 { GTP_EXT_TRACE_REF,    OPTIONAL },
2137                 { GTP_EXT_TRACE_TYPE,   OPTIONAL },
2138                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2139                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2140                 { GTP_EXT_QOS_UMTS,     MANDATORY },
2141                 { GTP_EXT_TFT,          OPTIONAL },
2142                 { GTP_EXT_TRIGGER_ID,   OPTIONAL },
2143                 { GTP_EXT_OMC_ID,       OPTIONAL },
2144                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2145                 { 0,                    0 }
2146         }
2147 },
2148 {       /* checked, GGSN -> SGSN */
2149         GTP_MSG_UPDATE_PDP_RESP, {
2150                 { GTP_EXT_CAUSE,        MANDATORY },
2151                 { GTP_EXT_RECOVER,      OPTIONAL },
2152                 { GTP_EXT_TEID,         CONDITIONAL },
2153                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2154                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
2155                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2156                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2157                 { GTP_EXT_QOS_UMTS,     CONDITIONAL },
2158                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
2159                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2160                 { 0,                    0 }
2161         }
2162 },
2163 {
2164         GTP_MSG_DELETE_PDP_REQ, {
2165                 { GTP_EXT_TEAR_IND,     CONDITIONAL },
2166                 { GTP_EXT_NSAPI,        MANDATORY },
2167                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2168                 { 0,                    0 }
2169         }
2170 },
2171 {
2172         GTP_MSG_DELETE_PDP_RESP, {
2173                 { GTP_EXT_CAUSE,        MANDATORY },
2174                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2175                 { 0,                    0 }
2176         }
2177 },
2178 {
2179         GTP_MSG_ERR_IND, {
2180                 { GTP_EXT_TEID,         MANDATORY },
2181                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2182                 { 0,                    0 }
2183         }
2184 },
2185 {
2186         GTP_MSG_PDU_NOTIFY_REQ, {
2187                 { GTP_EXT_IMSI,         MANDATORY },
2188                 { GTP_EXT_TEID_CP,      MANDATORY },
2189                 { GTP_EXT_USER_ADDR,    MANDATORY },
2190                 { GTP_EXT_APN,          MANDATORY },
2191                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2192                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2193                 { 0,                    0 }
2194         }
2195 },
2196 {
2197         GTP_MSG_PDU_NOTIFY_RESP, {
2198                 { GTP_EXT_CAUSE,        MANDATORY },
2199                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2200                 { 0,                    0 }
2201         }
2202 },
2203 {
2204         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
2205                 { GTP_EXT_CAUSE,        MANDATORY },
2206                 { GTP_EXT_TEID_CP,      MANDATORY },
2207                 { GTP_EXT_USER_ADDR,    MANDATORY },
2208                 { GTP_EXT_APN,          MANDATORY },
2209                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2210                 { 0,                    0 }
2211         }
2212 },
2213 {
2214         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
2215                 { GTP_EXT_CAUSE,        MANDATORY },
2216                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2217                 { 0,                    0 }
2218         }
2219 },
2220 {
2221         GTP_MSG_SUPP_EXT_HDR, {
2222                 { GTP_EXT_HDR_LIST,     MANDATORY },
2223                 { 0,                    0 }
2224         }
2225 },
2226 {
2227         GTP_MSG_SEND_ROUT_INFO_REQ, {
2228                 { GTP_EXT_IMSI,         MANDATORY },
2229                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2230                 { 0,                    0 }
2231         }
2232 },
2233 {
2234         GTP_MSG_SEND_ROUT_INFO_RESP, {
2235                 { GTP_EXT_CAUSE,        MANDATORY },
2236                 { GTP_EXT_IMSI,         MANDATORY },
2237                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
2238                 { GTPv1_EXT_MS_REASON,  OPTIONAL },
2239                 { GTP_EXT_GSN_ADDR,     OPTIONAL },
2240                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2241                 { 0,                    0 }
2242         }
2243 },
2244 {
2245         GTP_MSG_FAIL_REP_REQ, {
2246                 { GTP_EXT_IMSI,         MANDATORY },
2247                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2248                 { 0,                    0 }
2249         }
2250 },
2251 {
2252         GTP_MSG_FAIL_REP_RESP, {
2253                 { GTP_EXT_CAUSE,        MANDATORY },
2254                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
2255                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2256                 { 0,                    0 }
2257         }
2258 },
2259 {
2260         GTP_MSG_MS_PRESENT_REQ, {
2261                 { GTP_EXT_IMSI,         MANDATORY },
2262                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2263                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2264                 { 0,                    0 }
2265         }
2266 },
2267 {
2268         GTP_MSG_MS_PRESENT_RESP, {
2269                 { GTP_EXT_CAUSE,        MANDATORY },
2270                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2271                 { 0,                    0 }
2272         }
2273 },
2274 {
2275         GTP_MSG_IDENT_REQ, {
2276                 { GTP_EXT_RAI,          MANDATORY },
2277                 { GTP_EXT_PTMSI,        MANDATORY },
2278                 { GTP_EXT_PTMSI_SIG,    CONDITIONAL },
2279                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2280                 { 0,                    0 }
2281         }
2282 },
2283 {
2284         GTP_MSG_IDENT_RESP, {
2285                 { GTP_EXT_CAUSE,        MANDATORY },
2286                 { GTP_EXT_IMSI,         CONDITIONAL },
2287                 { GTP_EXT_AUTH_TRI,     CONDITIONAL },
2288                 { GTP_EXT_AUTH_QUI,     CONDITIONAL },
2289                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2290                 { 0,                    0 }
2291         }
2292 },
2293 {
2294         GTP_MSG_SGSN_CNTXT_REQ, {
2295                 { GTP_EXT_IMSI,         CONDITIONAL },
2296                 { GTP_EXT_RAI,          MANDATORY },
2297                 { GTP_EXT_TLLI,         CONDITIONAL },
2298                 { GTP_EXT_PTMSI,        CONDITIONAL },
2299                 { GTP_EXT_PTMSI_SIG,    CONDITIONAL },
2300                 { GTP_EXT_MS_VALID,     OPTIONAL },
2301                 { GTP_EXT_TEID_CP,      MANDATORY },
2302                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2303                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2304                 { 0,                    0 }
2305         }
2306 },
2307 {
2308         GTP_MSG_SGSN_CNTXT_RESP, {
2309                 { GTP_EXT_CAUSE,        MANDATORY },
2310                 { GTP_EXT_IMSI,         CONDITIONAL },
2311                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2312                 { GTP_EXT_RP_SMS,       OPTIONAL },
2313                 { GTP_EXT_RP,           OPTIONAL },
2314                 { GTP_EXT_PKT_FLOW_ID,  OPTIONAL },
2315                 { GTP_EXT_MM_CNTXT,     CONDITIONAL },
2316                 { GTP_EXT_PDP_CNTXT,    CONDITIONAL },
2317                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2318                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2319                 { 0,                    0 }
2320         }
2321 },
2322 {
2323         GTP_MSG_SGSN_CNTXT_ACK, {
2324                 { GTP_EXT_CAUSE,        MANDATORY },
2325                 { GTP_EXT_TEID_II,      CONDITIONAL },
2326                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2327                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2328                 { 0,                    0 }
2329         }
2330 },
2331 {
2332         GTP_MSG_FORW_RELOC_REQ, {
2333                 { GTP_EXT_IMSI,         MANDATORY },
2334                 { GTP_EXT_TEID_CP,      MANDATORY },
2335                 { GTP_EXT_RANAP_CAUSE,  MANDATORY },
2336                 { GTP_EXT_MM_CNTXT,     MANDATORY },
2337                 { GTP_EXT_PDP_CNTXT,    CONDITIONAL },
2338                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2339                 { GTP_EXT_TARGET_ID,    MANDATORY },
2340                 { GTP_EXT_UTRAN_CONT,   MANDATORY },
2341                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2342                 { 0,                    0 }
2343         }
2344 },
2345 {
2346         GTP_MSG_FORW_RELOC_RESP, {
2347                 { GTP_EXT_CAUSE,        MANDATORY },
2348                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2349                 { GTP_EXT_RANAP_CAUSE,  CONDITIONAL },
2350                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2351                 { GTP_EXT_UTRAN_CONT,   OPTIONAL },
2352                 { GTP_EXT_RAB_SETUP,    CONDITIONAL },
2353                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2354                 { 0,                    0 }
2355         }
2356 },
2357 {
2358         GTP_MSG_FORW_RELOC_COMP, {
2359                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2360                 { 0,                    0 }
2361         }
2362 },
2363 {
2364         GTP_MSG_RELOC_CANCEL_REQ, {
2365                 { GTP_EXT_IMSI,         MANDATORY },
2366                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2367                 { 0,                    0 }
2368         }
2369 },
2370 {
2371         GTP_MSG_RELOC_CANCEL_RESP, {
2372                 { GTP_EXT_CAUSE,        MANDATORY },
2373                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2374                 { 0,                    0 }
2375         }
2376 },
2377 {
2378         GTP_MSG_FORW_RELOC_ACK, {
2379                 { GTP_EXT_CAUSE,        MANDATORY },
2380                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2381                 { 0,                    0 }
2382         }
2383 },
2384 {
2385         GTP_MSG_FORW_SRNS_CNTXT, {
2386                 { GTP_EXT_RAB_CNTXT,    MANDATORY },
2387                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2388                 { 0,                    0 }
2389         }
2390 },
2391 {
2392         GTP_MSG_FORW_SRNS_CNTXT_ACK, {
2393                 { GTP_EXT_CAUSE,        MANDATORY },
2394                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2395                 { 0,                    0 }
2396         }
2397 },
2398 {
2399         0, {
2400                 { 0,                    0 }
2401         }
2402 }
2403 };
2404
2405 static int 
2406 check_field_presence(guint8 message, guint8 field, int *position) {
2407         
2408         guint                   i = 0;
2409         _gtp_mess_items         *mess_items;
2410
2411         switch(gtp_version) {
2412                 case 0: 
2413                         mess_items = gprs_mess_items;
2414                         break;
2415                 case 1: 
2416                         mess_items = umts_mess_items;
2417                         break;
2418                 default:
2419                         return -2;
2420         }
2421
2422         while (mess_items[i].code) {
2423                 if (mess_items[i].code == message) {
2424                         
2425                         while (mess_items[i].fields[*position].code) {
2426                                 if (mess_items[i].fields[*position].code == field) {
2427                                         (*position)++;
2428                                         return 0;
2429                                 } else { 
2430                                 if (mess_items[i].fields[*position].presence == MANDATORY) {
2431                                         return mess_items[i].fields[(*position)++].code;
2432                                 } else {
2433                                         (*position)++;
2434                                 }}
2435                         }
2436                         return -1;
2437                 }
2438                 i++;
2439         }       
2440
2441         return -2;
2442 }
2443
2444 /* Decoders of fields in extension headers, each function returns no of bytes from field */
2445
2446 /* GPRS:        9.60 v7.6.0, chapter
2447  * UMTS:        29.060 v4.0, chapter
2448  */
2449 static int
2450 decode_gtp_cause(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2451
2452         guint8  cause;
2453         
2454         cause = tvb_get_guint8(tvb, offset+1);  
2455         
2456         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_cause : hf_gtpv0_cause, tvb, offset, 2, cause);
2457
2458         return 2;
2459 }
2460
2461 /* GPRS:        9.60 v7.6.0, chapter 7.9.2
2462  * UMTS:        29.060 v4.0, chapter 7.7.2
2463  */
2464 static int 
2465 decode_gtp_imsi(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2466                 
2467         guint8  tid_val[8];
2468         gchar   *tid_str;
2469
2470         tvb_memcpy(tvb, tid_val, offset+1, 8);
2471         tid_val[1] = tid_val[1] & 0x0F;
2472         tid_str = id_to_str(tid_val);
2473         
2474         proto_tree_add_string(tree, gtp_version ? hf_gtpv1_imsi : hf_gtpv0_imsi, tvb, offset, 9, tid_str);
2475
2476         return 9;
2477 }
2478
2479 /* GPRS:        9.60 v7.6.0, chapter 7.9.3
2480  * UMTS:        29.060 v4.0, chapter 7.7.3
2481  * TODO: Add details about MCC, MNC, LAC, RAC (show each digit) ?
2482  */
2483 static int
2484 decode_gtp_rai(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2485                 
2486         proto_tree      *ext_tree_rai;
2487         proto_item      *te;
2488         guint8          byte[3];
2489         
2490         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_RAI, gtp_val, "Unknown message")); 
2491         ext_tree_rai = proto_item_add_subtree(te, ett_gtp_rai);
2492         
2493 /*      tvb_memcpy (tvb, (guint8 *)&byte, offset + 1, 3); */
2494         byte[1] = tvb_get_guint8 (tvb, offset + 1);
2495         byte[2] = tvb_get_guint8 (tvb, offset + 2);
2496         byte[3] = tvb_get_guint8 (tvb, offset + 3);
2497         
2498         
2499         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_mcc : hf_gtpv0_rai_mcc, tvb, offset+1, 2, (byte[1] & 0x0F) * 100 + ((byte[1] & 0xF0) >> 4) * 10  + (byte[2] & 0x0F ));
2500         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_mnc : hf_gtpv0_rai_mnc, tvb, offset+2, 2, ((byte[3] & 0xF0) >> 4 ) * 10  + (byte[3] & 0x0F));
2501         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_lac : hf_gtpv0_rai_lac, tvb, offset+4, 2, tvb_get_ntohs (tvb, offset+4));
2502         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_rac : hf_gtpv0_rai_rac, tvb, offset+6, 1, tvb_get_guint8 (tvb, offset+6));
2503
2504         return 7;
2505 }
2506
2507 /* GPRS:        9.60 v7.6.0, chapter 7.9.4, page 39
2508  * UMTS:        29.060 v4.0, chapter 7.7.4, page 47
2509  */
2510 static int
2511 decode_gtp_tlli(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2512                 
2513         guint32 tlli;
2514         
2515         tlli = tvb_get_ntohl(tvb, offset+1);    
2516         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_tlli : hf_gtpv0_tlli, tvb, offset, 5, tlli); 
2517
2518         return 5;
2519 }
2520
2521 /* GPRS:        9.60 v7.6.0, chapter 7.9.5, page 39
2522  * UMTS:        29.060 v4.0, chapter 7.7.5, page 47
2523  */
2524 static int
2525 decode_gtp_ptmsi(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2526                 
2527         guint32 ptmsi;
2528         
2529         ptmsi = tvb_get_ntohl(tvb, offset);     
2530         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ptmsi : hf_gtpv0_ptmsi, tvb, offset, 5, ptmsi);
2531
2532         return 5;
2533 }
2534
2535 /* adjust - how many bytes before offset should be highlighted 
2536  */
2537 static int
2538 decode_qos_gprs(tvbuff_t *tvb, int offset, proto_tree *tree, gchar* qos_str, guint8 adjust) {
2539         
2540         guint8          spare1, delay, reliability, peak, spare2,  precedence, spare3, mean;
2541         proto_tree      *ext_tree_qos;
2542         proto_item      *te;
2543         
2544         spare1 = tvb_get_guint8(tvb, offset) & 0xC0;
2545         delay = tvb_get_guint8(tvb, offset) & 0x38;
2546         reliability = tvb_get_guint8(tvb, offset) & 0x07;
2547         peak = tvb_get_guint8(tvb, offset+1) & 0xF0;
2548         spare2 = tvb_get_guint8(tvb, offset+1) & 0x08;
2549         precedence = tvb_get_guint8(tvb, offset+1) & 0x07;
2550         spare3 = tvb_get_guint8(tvb, offset+2) & 0xE0;
2551         mean = tvb_get_guint8(tvb, offset+2) & 0x1F;
2552         
2553         te = proto_tree_add_text(tree, tvb, offset-adjust, 3+adjust, "%s: delay: %u, reliability: %u, peak: %u, precedence: %u, mean: %u",
2554                                                                         qos_str, delay, reliability, peak, precedence, mean);
2555         ext_tree_qos = proto_item_add_subtree(te, ett_gtp_qos);
2556
2557         if (adjust != 0) {
2558                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare1, tvb, offset, 1, spare1);
2559                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_delay, tvb, offset, 1, delay);
2560                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_reliability, tvb, offset, 1, reliability);
2561                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_peak, tvb, offset+1, 1, peak);
2562                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare2, tvb, offset+1, 1, spare2);
2563                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_precedence, tvb, offset+1, 1, precedence);
2564                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare3, tvb, offset+2, 1, spare3);
2565                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_mean, tvb, offset+2, 1, mean);
2566         }
2567
2568         return 3; 
2569 }
2570
2571 /* GPRS:        9.60 v7.6.0, chapter 7.9.6, page 39
2572  *              4.08
2573  *              3.60
2574  * UMTS:        not present
2575  * TODO:        check if length is included: ETSI 4.08 vs 9.60 
2576  */
2577 static int
2578 decode_gtp_qos_gprs(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2579                 
2580         return (1+decode_qos_gprs(tvb, offset+1, tree, "Quality of Service", 1));
2581         
2582 }
2583
2584 /* GPRS:        9.60 v7.6.0, chapter 7.9.7, page 39
2585  * UMTS:        29.060 v4.0, chapter 7.7.6, page 47
2586  */
2587 static int
2588 decode_gtp_reorder(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2589
2590         guint8  reorder;
2591         
2592         reorder = tvb_get_guint8(tvb, offset+1) & 0x01; 
2593         proto_tree_add_boolean(tree, gtp_version ? hf_gtpv1_reorder : hf_gtpv0_reorder, tvb, offset, 2, reorder); 
2594
2595         return 2;
2596 }
2597
2598 /* GPRS:        9.60 v7.6.0, chapter 7.9.8, page 40
2599  *              4.08 v7.1.2, chapter 10.5.3.1+ 
2600  * UMTS:        29.060 v4.0, chapter 7.7.7
2601  * TODO: Add blurb support by registering items in the protocol registration
2602  */
2603 static int
2604 decode_gtp_auth_tri(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2605
2606         proto_tree      *ext_tree_auth_tri;
2607         proto_item      *te;
2608         guint32         rand[4], sres, kc[2];
2609         
2610         tvb_memcpy(tvb, (guint8 *)&rand, offset+1, 16);
2611         sres = tvb_get_ntohl(tvb, offset+17);
2612         tvb_memcpy(tvb, (guint8 *)&kc, offset+21, 16);
2613         
2614         te = proto_tree_add_text(tree, tvb, offset, 29, val_to_str(GTP_EXT_AUTH_TRI, gtp_val, "Unknown message"));
2615         ext_tree_auth_tri = proto_item_add_subtree(tree, ett_gtp_auth_tri);
2616                                                         
2617         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+1, 16, "RAND: %x%x%x%x", rand[0], rand[1], rand[2], rand[3]);
2618         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+17, 4, "SRES: %x", sres);
2619         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+21, 8, "Kc: %x%x", kc[0], kc[1]);
2620
2621         return 1+16+4+8;
2622 }
2623
2624 /* GPRS:        9.60 v7.6.0, chapter 7.9.9, page 40
2625  *              9.02 v7.7.0, page 1090
2626  * UMTS:        29.060 v4.0, chapter 7.7.8, page 48
2627  *              29.002 v4.2.1, chapter 17.5, page 268
2628  */
2629 static int
2630 decode_gtp_map_cause(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2631                 
2632         guint8  map_cause;
2633         
2634         map_cause = tvb_get_guint8(tvb, offset+1);      
2635         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_map_cause : hf_gtpv0_map_cause, tvb, offset, 2, map_cause);
2636
2637         return 2;
2638 }
2639
2640 /* GPRS:        9.60 v7.6.0, chapter 7.9.10, page 41
2641  * UMTS:        29.060 v4.0, chapter 7.7.9, page 48
2642  */
2643 static int
2644 decode_gtp_ptmsi_sig(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2645                 
2646         guint32 ptmsi_sig;
2647         
2648         ptmsi_sig = tvb_get_ntoh24(tvb, offset+1);      
2649         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ptmsi_sig : hf_gtpv0_ptmsi_sig, tvb, offset, 4, ptmsi_sig);
2650
2651         return 4;
2652 }
2653
2654 /* GPRS:        9.60 v7.6.0, chapter 7.9.11, page 41
2655  * UMTS:        29.060 v4.0, chapter 7.7.10, page 49
2656  */
2657 static int
2658 decode_gtp_ms_valid(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2659                 
2660         guint8  ms_valid;
2661         
2662         ms_valid = tvb_get_guint8(tvb, offset+1) & 0x01;        
2663         proto_tree_add_boolean(tree, gtp_version ? hf_gtpv1_ms_valid : hf_gtpv0_ms_valid, tvb, offset, 2, ms_valid);
2664
2665         return 2;
2666 }
2667
2668 /* GPRS:        9.60 v7.6.0, chapter 7.9.12, page 41
2669  * UMTS:        29.060 v4.0, chapter 7.7.11, page 49
2670  */
2671 static int
2672 decode_gtp_recovery(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2673                 
2674         guint8  recovery;
2675         
2676         recovery = tvb_get_guint8(tvb, offset+1);       
2677         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_recovery : hf_gtpv0_recovery, tvb, offset, 2, recovery);
2678
2679         return 2;
2680 }
2681
2682 /* GPRS:        9.60 v7.6.0, chapter 7.9.13, page 42
2683  * UMTS:        29.060 v4.0, chapter 7.7.12, page 49
2684  */
2685 static int
2686 decode_gtp_sel_mode(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2687                 
2688         guint8  sel_mode;
2689         
2690         sel_mode = tvb_get_guint8(tvb, offset+1) & 0x03;        
2691         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_sel_mode : hf_gtpv0_sel_mode, tvb, offset, 2, sel_mode);
2692
2693         return 2;
2694 }
2695
2696 /* GPRS:        9.60 v7.6.0, chapter 7.9.14, page 42
2697  * UMTS:        29.060 v4.0, chapter 7.7.13, page 50
2698  */
2699 static int
2700 decode_gtp_16(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2701                 
2702         guint16 ext_flow_label; 
2703         guint32 teid_data;
2704
2705         switch (gtp_version) {
2706                 case 0:
2707                         ext_flow_label = tvb_get_ntohs(tvb, offset+1);  
2708                         proto_tree_add_uint(tree, hf_gtpv0_ext_flow_label, tvb, offset, 3, ext_flow_label);
2709                         
2710                         return 3;
2711                 case 1:
2712                         teid_data = tvb_get_ntohl(tvb, offset+1);
2713                         proto_tree_add_uint(tree, hf_gtpv1_teid_data, tvb, offset, 5, teid_data);
2714
2715                         return 5;
2716                 default: 
2717                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label/TEID Data I : GTP version not supported");
2718                         
2719                         return 3;
2720         }
2721 }
2722
2723 /* GPRS:        9.60 v7.6.0, chapter 7.9.15, page 42
2724  * UMTS:        29.060 v4.0, chapter 7.7.14, page 42
2725  */
2726 static int
2727 decode_gtp_17(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2728
2729         guint16         flow_sig;
2730         guint32         teid_cp;
2731
2732         switch (gtp_version) {
2733                 case 0:
2734                         flow_sig = tvb_get_ntohs(tvb, offset+1);        
2735                         proto_tree_add_uint(tree, hf_gtpv0_flow_sig, tvb, offset, 3, flow_sig);
2736                         
2737                         return 3;
2738                 case 1:
2739                         teid_cp = tvb_get_ntohl(tvb, offset+1);
2740                         proto_tree_add_uint(tree, hf_gtpv1_teid_cp, tvb, offset, 5, teid_cp);
2741                         
2742                         return 5;
2743                 default:
2744                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label signalling/TEID control plane : GTP version not supported");
2745                         
2746                         return 3;
2747         }
2748 }
2749
2750 /* GPRS:        9.60 v7.6.0, chapter 7.9.16, page 42
2751  * UMTS:        29.060 v4.0, chapter 7.7.15, page 51
2752  */
2753 static int
2754 decode_gtp_18(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2755
2756         guint16         flow_ii;
2757         guint32         teid_ii;
2758         proto_tree      *ext_tree_flow_ii;
2759         proto_item      *te;
2760
2761         switch (gtp_version) {
2762                 case 0:
2763                         te = proto_tree_add_text(tree, tvb, offset, 4, val_to_str(GTP_EXT_FLOW_II, gtp_val, "Unknown message"));
2764                         ext_tree_flow_ii = proto_item_add_subtree(te, ett_gtp_flow_ii);
2765                         
2766                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv0_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2767                         
2768                         flow_ii = tvb_get_ntohs(tvb, offset+2); 
2769                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv0_flow_ii, tvb, offset+2, 2, flow_ii);
2770                         
2771                         return 4;
2772                 case 1: 
2773                         te = proto_tree_add_text(tree, tvb, offset, 6, val_to_str(GTP_EXT_TEID_II, gtp_val, "Unknown message"));
2774                         ext_tree_flow_ii = proto_item_add_subtree(te, ett_gtp_flow_ii);
2775                         
2776                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv1_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2777
2778                         
2779                         teid_ii = tvb_get_ntohl(tvb, offset+2);
2780                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv1_teid_ii, tvb, offset+2, 4, teid_ii);
2781                         
2782                         return 6;
2783                 default:
2784                         proto_tree_add_text(tree, tvb, offset, 1, "Flow data II/TEID Data II : GTP Version not supported");
2785                         
2786                         return 4;
2787         }
2788 }
2789
2790 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A, page 43
2791  * UMTS:        29.060 v4.0, chapter 7.7.16, page 51
2792  * Check if all ms_reason types are included
2793  */
2794 static int
2795 decode_gtp_19(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2796                 
2797         guint8          field19;        
2798         
2799         field19 = tvb_get_guint8(tvb, offset+1);        
2800         
2801         switch (gtp_version) {
2802                 case 0: 
2803                         proto_tree_add_uint(tree, hf_gtpv0_ms_reason, tvb, offset, 2, field19);
2804                         
2805                         break;
2806                 case 1:
2807                         proto_tree_add_boolean(tree, hf_gtpv1_tear_ind, tvb, offset, 2, field19 & 0x01);
2808                         
2809                         break;
2810                 default:
2811                         proto_tree_add_text(tree, tvb, offset, 1, "Information Element Type = 19 : GTP Version not supported");
2812
2813                         break;
2814         }
2815
2816         return 2;
2817 }
2818
2819 /* GPRS:        not present
2820  * UMTS:        29.060 v4.0, chapter 7.7.17, page 51
2821  */
2822 static int
2823 decode_gtp_nsapi(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2824                 
2825         guint8          nsapi;
2826         
2827         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;   
2828         proto_tree_add_uint(tree, hf_gtpv1_nsapi, tvb, offset, 2, nsapi);
2829
2830         return 2;
2831 }
2832
2833 /* GPRS:        not present
2834  * UMTS:        29.060 v4.0, chapter 7.7.18, page 52
2835  */
2836 static int
2837 decode_gtp_ranap_cause(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2838                 
2839         guint8          ranap;
2840         
2841         ranap = tvb_get_guint8(tvb, offset+1);
2842
2843         if(ranap > 0 && ranap <=64)
2844         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Radio Network Layer Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2845
2846         if(ranap > 64 && ranap <=80)
2847         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Transport Layer Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2848
2849         if(ranap > 80 && ranap <=96)
2850         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (NAS Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2851
2852         if(ranap > 96 && ranap <=112)
2853         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Protocol Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2854
2855         if(ranap > 112 && ranap <=128)
2856         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Miscellaneous Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2857
2858         if(ranap > 128 && ranap <=255)
2859         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Non-standard Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2860
2861         return 2;
2862 }
2863
2864 /* GPRS:        not present
2865  * UMTS:        29.060 v4.0, chapter 7.7.19, page 52
2866  */
2867 static int
2868 decode_gtp_rab_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2869                 
2870         guint8          nsapi, dl_pdcp_seq, ul_pdcp_seq;
2871         guint16         dl_gtpu_seq, ul_gtpu_seq;
2872         proto_tree      *ext_tree_rab_cntxt;
2873         proto_item      *te;
2874         
2875         te = proto_tree_add_text(tree, tvb, offset, 8, val_to_str(GTP_EXT_RAB_CNTXT, gtp_val, "Unknown message"));
2876         ext_tree_rab_cntxt = proto_item_add_subtree(te, ett_gtp_rab_cntxt);
2877         
2878         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;   
2879         dl_gtpu_seq = tvb_get_ntohs(tvb, offset+2);
2880         ul_gtpu_seq = tvb_get_ntohs(tvb, offset+4);
2881         dl_pdcp_seq = tvb_get_guint8(tvb, offset+6);
2882         ul_pdcp_seq = tvb_get_guint8(tvb, offset+7);
2883
2884         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_nsapi, tvb, offset+1, 1, nsapi);
2885         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_gtpu_dn, tvb, offset+2, 2, dl_gtpu_seq);
2886         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_gtpu_up, tvb, offset+4, 2, ul_gtpu_seq);
2887         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_pdu_dn, tvb, offset+6, 1, dl_pdcp_seq);
2888         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_pdu_up, tvb, offset+7, 1, ul_pdcp_seq);
2889
2890         return 8;
2891 }
2892
2893
2894 /* GPRS:        not present
2895  * UMTS:        29.060 v4.0, chapter 7.7.20, page 53
2896  */
2897 static int
2898 decode_gtp_rp_sms(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2899                 
2900         guint8          rp_sms;
2901         
2902         rp_sms = tvb_get_guint8(tvb, offset+1) & 0x07;  
2903         proto_tree_add_uint(tree, hf_gtpv1_rp_sms, tvb, offset, 2, rp_sms);
2904
2905         return 2;
2906 }
2907
2908 /* GPRS:        not present
2909  * UMTS:        29.060 v4.0, chapter 7.7.21, page 53
2910  */
2911 static int
2912 decode_gtp_rp(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2913                 
2914         proto_tree      *ext_tree_rp;
2915         proto_item      *te;
2916         guint8          nsapi, rp, spare;
2917         
2918         nsapi = tvb_get_guint8(tvb, offset+1) & 0xF0;
2919         spare = tvb_get_guint8(tvb, offset+1) & 0x08;
2920         rp = tvb_get_guint8(tvb, offset+1) & 0x07;
2921
2922         te = proto_tree_add_uint_format(tree, hf_gtpv1_rp, tvb, offset, 2, rp, "Radio Priority for NSAPI(%u) : %u", nsapi, rp);
2923         ext_tree_rp = proto_item_add_subtree(tree, ett_gtp_rp);
2924
2925         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp_nsapi, tvb, offset+1, 1, nsapi);
2926         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp_spare, tvb, offset+1, 1, spare);
2927         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp, tvb, offset+1, 1, rp);
2928
2929         return 2;
2930 }
2931
2932 /* GPRS:        not present
2933  * UMTS:        29.060 v4.0, chapter 7.7.22, page 53
2934  */
2935 static int
2936 decode_gtp_pkt_flow_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2937                 
2938         proto_tree      *ext_tree_pkt_flow_id;
2939         proto_item      *te;
2940         guint8          nsapi, pkt_flow_id;
2941         
2942         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
2943         pkt_flow_id = tvb_get_guint8(tvb, offset+2);
2944
2945         te = proto_tree_add_uint_format(tree, hf_gtpv1_pkt_flow_id, tvb, offset, 3, pkt_flow_id, "Packet Flow ID for NSAPI(%u) : %u", nsapi, pkt_flow_id);
2946         ext_tree_pkt_flow_id = proto_item_add_subtree(tree, ett_gtp_pkt_flow_id);
2947
2948         proto_tree_add_uint(ext_tree_pkt_flow_id, hf_gtpv1_nsapi, tvb, offset+1, 1, nsapi);
2949         proto_tree_add_uint_format(ext_tree_pkt_flow_id, hf_gtpv1_pkt_flow_id, tvb, offset+2, 1, pkt_flow_id, "%s : %u", val_to_str(GTP_EXT_PKT_FLOW_ID, gtp_val, "Unknown message"), pkt_flow_id);
2950         
2951         return 3;
2952 }
2953
2954 /* GPRS:        not present
2955  * UMTS:        29.060 v4.0, chapter 7.7.23, page 53
2956  * TODO: Differenciate these uints?
2957  */
2958 static int
2959 decode_gtp_chrg_char(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2960                 
2961         guint16         chrg_char;
2962         proto_item      *te;
2963         proto_tree      *ext_tree_chrg_char;
2964         
2965         chrg_char = tvb_get_ntohs(tvb, offset+1);
2966         
2967         te = proto_tree_add_text(tree, tvb, offset, 3, "%s: %x", val_to_str(GTP_EXT_CHRG_CHAR, gtp_val, "Unknown message"), chrg_char);
2968         ext_tree_chrg_char = proto_item_add_subtree(te, ett_gtp_chrg_char);
2969         
2970         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_s, tvb, offset+1, 2, chrg_char);
2971         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_n, tvb, offset+1, 2, chrg_char);
2972         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_p, tvb, offset+1, 2, chrg_char);
2973         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_f, tvb, offset+1, 2, chrg_char);
2974         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_h, tvb, offset+1, 2, chrg_char);
2975         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_r, tvb, offset+1, 2, chrg_char);
2976         
2977         return 3;
2978 }
2979
2980 /* GPRS:        not present
2981  * UMTS:        29.060 v4.0, chapter 7.7.24, page 
2982  */
2983 static int
2984 decode_gtp_trace_ref(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2985                 
2986         guint16         trace_ref;
2987         
2988         trace_ref = tvb_get_ntohs(tvb, offset+1);
2989         
2990         proto_tree_add_uint(tree, hf_gtpv1_trace_ref, tvb, offset, 3, trace_ref);
2991
2992         return 3;
2993 }
2994
2995 /* GPRS:        not present
2996  * UMTS:        29.060 v4.0, chapter 7.7.25, page 
2997  */
2998 static int
2999 decode_gtp_trace_type(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3000                 
3001         guint16         trace_type;
3002         
3003         trace_type = tvb_get_ntohs(tvb, offset+1);
3004         
3005         proto_tree_add_uint(tree, hf_gtpv1_trace_type, tvb, offset, 3, trace_type);
3006         
3007         return 3;
3008 }
3009
3010 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A
3011  * UMTS:        29.060 v4.0, chapter 7.7.25A, page 
3012  */
3013 static int
3014 decode_gtp_ms_reason(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3015                 
3016         guint8          reason; 
3017         
3018         reason = tvb_get_guint8(tvb, offset+1); 
3019         
3020         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ms_reason : hf_gtpv0_ms_reason, tvb, offset, 2, reason);
3021
3022         return 2;
3023 }
3024
3025
3026 /* GPRS:        12.15
3027  * UMTS:        33.015
3028  */
3029 static int
3030 decode_gtp_tr_comm(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3031                 
3032         guint8  tr_command;     
3033         
3034         tr_command = tvb_get_ntohl(tvb, offset+1);      
3035         
3036         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_tr_comm : hf_gtpv0_tr_comm, tvb, offset, 2, tr_command);
3037
3038         return 2;
3039 }
3040
3041 /* GPRS:        9.60 v7.6.0, chapter 7.9.17, page 43
3042  * UMTS:        29.060 v4.0, chapter 7.7.26, page 55
3043  */
3044 static int
3045 decode_gtp_chrg_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3046                 
3047         guint32 chrg_id;        
3048         
3049         chrg_id = tvb_get_ntohl(tvb, offset+1); 
3050         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_chrg_id : hf_gtpv0_chrg_id, tvb, offset, 5, chrg_id);
3051
3052         return 5;
3053 }
3054
3055 /* GPRS:        9.60 v7.6.0, chapter 7.9.18, page 43
3056  * UMTS:        29.060 v4.0, chapter 7.7.27, page 55
3057  */
3058 static int
3059 decode_gtp_user_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3060                 
3061         guint16         length;
3062         guint8          pdp_typ, pdp_org;       
3063         guint32         addr_ipv4;
3064         struct          e_in6_addr addr_ipv6;
3065         proto_tree      *ext_tree_user;
3066         proto_item      *te;
3067         
3068         
3069         length = tvb_get_ntohs(tvb, offset+1);
3070         pdp_org = tvb_get_guint8(tvb, offset+3) & 0x0F;
3071         pdp_typ = tvb_get_guint8(tvb, offset+4);
3072
3073         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s (%s/%s)",
3074             val_to_str(GTP_EXT_USER_ADDR, gtp_val, "Unknown message"),
3075             val_to_str(pdp_org, pdp_org_type, "Unknown PDP Organization"),
3076             val_to_str(pdp_typ, pdp_type, "Unknown PDP Type"));
3077         ext_tree_user = proto_item_add_subtree(te, ett_gtp_user);
3078         
3079         proto_tree_add_text(ext_tree_user, tvb, offset+1, 2, "Length : %u", length);
3080         proto_tree_add_uint(ext_tree_user, gtp_version ? hf_gtpv1_user_addr_pdp_org : hf_gtpv0_user_addr_pdp_org, tvb, offset+3, 1, pdp_org);
3081         proto_tree_add_uint(ext_tree_user, gtp_version ? hf_gtpv1_user_addr_pdp_type : hf_gtpv0_user_addr_pdp_type, tvb, offset+4, 1, pdp_typ);
3082         
3083         if (length == 2) {
3084                 if (pdp_org == 0 && pdp_typ == 1)
3085                         proto_item_append_text(te, " (Point to Point Protocol)");
3086                 else if (pdp_typ == 2)
3087                         proto_item_append_text(te, " (Octet Stream Protocol)");
3088         } else if (length > 2) {
3089                 switch (pdp_typ) {
3090                         case 0x21:
3091                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+5, sizeof addr_ipv4);
3092                                 proto_tree_add_ipv4(ext_tree_user, gtp_version ? hf_gtpv1_user_ipv4 : hf_gtpv0_user_ipv4, tvb, offset+5, 4, addr_ipv4);
3093                                 proto_item_append_text(te, " : %s", ip_to_str((guint8 *)&addr_ipv4));
3094                                 break;
3095                         case 0x57:
3096                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+5, sizeof addr_ipv6);
3097                                 proto_tree_add_ipv6(ext_tree_user, gtp_version ? hf_gtpv1_user_ipv6 : hf_gtpv0_user_ipv6, tvb, offset+5, 16, (guint8 *)&addr_ipv6);
3098                                 proto_item_append_text(te, " : %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3099                                 break;
3100                 }
3101         } else
3102                 proto_item_append_text(te, " : empty PDP Address");
3103                                 
3104         return 3+length;
3105 }
3106
3107 static int
3108 decode_triplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count) {
3109         
3110         proto_tree      *ext_tree_trip;
3111         proto_item      *te_trip;
3112         guint32         rand[4], sres, kc[2];
3113         guint16         i;
3114         
3115         for (i=0;i<count;i++) {
3116                 
3117                 tvb_memcpy(tvb, (guint8 *)&rand, offset+i*28, 16);
3118                 sres = tvb_get_ntohl(tvb, offset+i*28+16);
3119                 tvb_memcpy(tvb, (guint8 *)&kc, offset+i*28+20, 8);
3120
3121                 te_trip = proto_tree_add_text(tree, tvb, offset+i*28, 28, "Triplet no%x", i);
3122                 ext_tree_trip = proto_item_add_subtree(te_trip, ett_gtp_trip);
3123                                                         
3124                 proto_tree_add_text(ext_tree_trip, tvb, offset+i*28, 16, "RAND: %x%x%x%x", rand[0], rand[1], rand[2], rand[3]);
3125                 proto_tree_add_text(ext_tree_trip, tvb, offset+i*28+16, 4, "SRES: %x", sres);
3126                 proto_tree_add_text(ext_tree_trip, tvb, offset+i*28+20, 8, "Kc: %x%x", kc[0], kc[1]);
3127         }
3128         
3129         return count*28;
3130 }
3131
3132 /* adjust - how many bytes before quintuplet should be highlighted
3133  */
3134 static int
3135 decode_quintuplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count, guint8 adjust) {
3136         
3137         proto_tree      *ext_tree_quint;
3138         proto_item      *te_quint;
3139         guint32         rand[4], q_ck[4], q_ik[4];
3140         guint16         q_len, xres_len, auth_len, q_offset, i;
3141
3142         q_offset = 0;
3143         
3144         for (i=0;i<count;i++) { 
3145         
3146                 offset = offset + q_offset;
3147                 
3148                 q_len = tvb_get_ntohs(tvb, offset);
3149                 
3150                 tvb_memcpy(tvb, (guint8 *)&rand, offset+2, 16);
3151                 xres_len = tvb_get_ntohs(tvb, offset+18);
3152 /*              xres = tvb_get_ptr(tvb, offset+20, xres_len);*/
3153                 tvb_memcpy(tvb, (guint8 *)&q_ck, offset+20+xres_len, 16);
3154                 tvb_memcpy(tvb, (guint8 *)&q_ik, offset+36+xres_len, 16);
3155                 auth_len = tvb_get_ntohs(tvb, offset+52+xres_len);
3156 /*              auth = tvb_get_ptr(tvb, offset+54+xres_len, auth_len);*/
3157
3158                 te_quint = proto_tree_add_text(tree, tvb, offset-adjust, q_len+adjust, "Quintuplet #%x", i);
3159                 ext_tree_quint = proto_item_add_subtree(te_quint, ett_gtp_quint);
3160                                                         
3161                 proto_tree_add_text(ext_tree_quint, tvb, offset, 2, "Length: %x", q_len);
3162                 proto_tree_add_text(ext_tree_quint, tvb, offset+2, 16, "RAND: %x%x%x%x", rand[0], rand[1], rand[2], rand[3]);
3163                 proto_tree_add_text(ext_tree_quint, tvb, offset+18, 2, "XRES length: %x", xres_len);
3164                 proto_tree_add_text(ext_tree_quint, tvb, offset+20, xres_len, "XRES");
3165                 proto_tree_add_text(ext_tree_quint, tvb, offset+20+xres_len, 16, "Quintuplet ciphering key: %x%x%x%x", q_ck[0], q_ck[1], q_ck[2], q_ck[3]);
3166                 proto_tree_add_text(ext_tree_quint, tvb, offset+36+xres_len, 16, "Quintuplet integrity key: %x%x%x%x", q_ik[0], q_ik[1], q_ik[2], q_ik[3]);
3167                 proto_tree_add_text(ext_tree_quint, tvb, offset+52+xres_len, 2, "Authentication length: %x", auth_len);
3168                 proto_tree_add_text(ext_tree_quint, tvb, offset+54+xres_len, auth_len, "AUTH");
3169
3170                 q_offset = q_offset + q_len + 2;
3171         }
3172         
3173         return q_offset;
3174 }
3175
3176 /* GPRS:        9.60 v7.6.0, chapter 7.9.19 page 
3177  * UMTS:        29.060 v4.0, chapter 7.7.28 page 57
3178  * TODO:        - check if for quintuplets first 2 bytes are length, according to AuthQuint
3179  *              - finish displaying last 3 parameters
3180  */
3181 static int
3182 decode_gtp_mm_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3183                 
3184         guint16         length, quint_len, net_cap, con_len;    
3185         guint8          cksn, count, sec_mode, cipher, trans_id, proto_disc, message, drx_split, drx_len, drx_ccch, non_drx_timer;
3186         guint32         kc[4], ik[4];
3187         proto_tree      *ext_tree_mm;
3188         proto_item      *te;
3189         
3190         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_MM_CNTXT, gtp_val, "Unknown message"));
3191         ext_tree_mm = proto_item_add_subtree(te, ett_gtp_mm);
3192         
3193         length = tvb_get_ntohs(tvb, offset+1);
3194         if (length < 1) return 3;
3195         
3196         cksn = tvb_get_guint8(tvb, offset+3) & 0x07;
3197         sec_mode = (tvb_get_guint8(tvb, offset+4) >> 6) & 0x03;
3198         count = (tvb_get_guint8(tvb, offset+4) >> 3) & 0x07;
3199         cipher = tvb_get_guint8(tvb, offset+4) & 0x07;
3200         
3201         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 2, "Length: %x", length);
3202         proto_tree_add_text(ext_tree_mm, tvb, offset+3, 1, "Ciphering Key Sequence Number: %u", cksn);
3203         if (gtp_version != 0) {
3204                 proto_tree_add_text(ext_tree_mm, tvb, offset+3, 1, "Security type: %u", sec_mode);
3205         } else {
3206                 sec_mode = 1;
3207         }
3208         
3209         proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "No of triplets: %u", count);
3210
3211         switch (sec_mode) {
3212                 case 0: 
3213                         if (cipher == 0) {
3214                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3215                         } else {
3216                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3217                         }
3218                         tvb_memcpy(tvb, (guint8 *)&kc, offset+5, 16);
3219                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 16, "Ciphering key CK: %x%x%x%x", kc[0], kc[1], kc[2], kc[3]);
3220                         tvb_memcpy(tvb, (guint8 *)&ik, offset+21, 16);
3221                         proto_tree_add_text(ext_tree_mm, tvb, offset+21, 16, "Integrity key CK: %x%x%x%x", ik[0], ik[1], ik[2], ik[3]);
3222                         quint_len = tvb_get_ntohs(tvb, offset+37);
3223                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: %x", quint_len);
3224
3225                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count, 0) + 39;
3226                         
3227                                         
3228                         break;
3229                 case 1: 
3230                         if (cipher == 0) {
3231                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3232                         } else {
3233                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3234                         }
3235                         tvb_memcpy(tvb, (guint8 *)&kc, offset+5, 8);
3236                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %x%x", kc[0], kc[1]);
3237
3238                         offset = offset + decode_triplet(tvb, offset+13, ext_tree_mm, count) + 13;
3239
3240                         break;
3241                 case 2: 
3242                         tvb_memcpy(tvb, (guint8 *)&kc, offset+5, 16);
3243                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 16, "Ciphering key CK: %x%x%x%x", kc[0], kc[1], kc[2], kc[3]);
3244                         tvb_memcpy(tvb, (guint8 *)&ik, offset+21, 16);
3245                         proto_tree_add_text(ext_tree_mm, tvb, offset+21, 16, "Integrity key CK: %x%x%x%x", ik[0], ik[1], ik[2], ik[3]);
3246                         quint_len = tvb_get_ntohs(tvb, offset+37);
3247                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: %x", quint_len);
3248                         
3249                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count, 0) + 39;
3250                         
3251                         break;
3252                 case 3: 
3253                         if (cipher == 0) {
3254                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3255                         } else {
3256                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3257                         }
3258                         tvb_memcpy(tvb, (guint8 *)&kc, offset+5, 8);
3259                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %x%x", kc[0], kc[1]);
3260                         quint_len = tvb_get_ntohs(tvb, offset+13);
3261                         proto_tree_add_text(ext_tree_mm, tvb, offset+13, 2, "Quintuplets length: %x", quint_len);
3262
3263                         offset = offset + decode_quintuplet(tvb, offset+15, ext_tree_mm, count, 0) + 15;
3264                         
3265                         break;
3266                 default:
3267                         break;
3268         }
3269         
3270         
3271         drx_split = tvb_get_guint8(tvb, offset);
3272         drx_len = (tvb_get_guint8(tvb, offset+1) >> 4) & 0x0F;
3273         drx_ccch = (tvb_get_guint8(tvb, offset+1) >> 3) & 0x01;
3274         non_drx_timer = tvb_get_guint8(tvb, offset+1) & 0x07;
3275
3276         net_cap = tvb_get_ntohs(tvb, offset+2);
3277         con_len = tvb_get_ntohs(tvb, offset+4);
3278         
3279         proto_tree_add_text(ext_tree_mm, tvb, offset, 1, "DRX: split PG cycle code: %u", drx_split);
3280         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: CN specific DRX cycle length coefficient: %u", drx_len);
3281         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: split PG cycle on CCCH supported by MS: %s", yesno[drx_ccch]);
3282         if (non_drx_timer == 0) {
3283                 proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: no non-DRX mode after transfer state");
3284         } else {
3285                 proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: max sec non-DRX mode after transfer state:  2^%u", non_drx_timer-1);
3286         }
3287         
3288         proto_tree_add_text(ext_tree_mm, tvb, offset+2, 2, "MS network capability: %u", net_cap);
3289         proto_tree_add_text(ext_tree_mm, tvb, offset+4, 2, "Container length: %u", con_len);
3290         
3291         if (con_len > 0) {
3292                 trans_id = (tvb_get_guint8(tvb, offset+6) >> 4) & 0x0F;
3293                 proto_disc = tvb_get_guint8(tvb, offset+6) & 0x0F;
3294                 message = tvb_get_guint8(tvb, offset+7);
3295         }
3296
3297         return 3+length;
3298 }
3299
3300  /* WARNING : actually length is coded on 2 octets for QoS profile but on 1 octet for PDP Context!
3301   * so type means length of length :-)
3302  */
3303 static int
3304 decode_qos_umts(tvbuff_t *tvb, int offset, proto_tree *tree, gchar* qos_str, guint8 type) {
3305
3306         guint8          length;
3307         guint8          al_ret_priority;
3308         guint8          delay, reliability, peak, precedence, mean, spare1, spare2, spare3;
3309         guint8          traf_class, del_order, del_err_sdu;
3310         guint8          max_sdu_size, max_ul, max_dl;
3311         guint8          res_ber, sdu_err_ratio;
3312         guint8          trans_delay, traf_handl_prio;
3313         guint8          guar_ul, guar_dl;
3314         proto_tree      *ext_tree_qos;
3315         proto_item      *te;
3316         int             mss, mu, md, gu, gd;
3317
3318         switch (type) {
3319                 case 1:
3320                         length = tvb_get_guint8 (tvb, offset);
3321                         te = proto_tree_add_text (tree, tvb, offset, length + 1, "%s", qos_str);
3322                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3323                         proto_tree_add_text (ext_tree_qos, tvb, offset, 1, "Length: %u", length);
3324                         break;
3325                 case 2:
3326                         length = tvb_get_ntohs (tvb, offset + 1);
3327                         te = proto_tree_add_text(tree, tvb, offset, length + 3, "%s", qos_str);
3328                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3329                         proto_tree_add_text (ext_tree_qos, tvb, offset + 1, 2, "Length: %u", length);
3330                         type++;         /* +1 because of first 0x86 byte for UMTS QoS */
3331                         break;
3332                 default:
3333                         /* XXX - what should we do with the length here? */
3334                         length = 0;
3335                         ext_tree_qos = NULL;
3336                         break;
3337         }
3338         
3339         offset += type;
3340         
3341         al_ret_priority = tvb_get_guint8 (tvb, offset);
3342
3343         spare1 = tvb_get_guint8(tvb, offset+1) & 0xC0;
3344         delay = tvb_get_guint8(tvb, offset+1) & 0x38;
3345         reliability = tvb_get_guint8(tvb, offset+1) & 0x07;
3346         peak = tvb_get_guint8(tvb, offset+2) & 0xF0;
3347         spare2 = tvb_get_guint8(tvb, offset+2) & 0x08;
3348         precedence = tvb_get_guint8(tvb, offset+2) & 0x07;
3349         spare3 = tvb_get_guint8(tvb, offset+3) & 0xE0;
3350         mean = tvb_get_guint8(tvb, offset+3) & 0x1F;
3351
3352         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_al_ret_priority, tvb, offset, 1, al_ret_priority);
3353         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare1, tvb, offset+1, 1, spare1);
3354         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_delay, tvb, offset+1, 1, delay);
3355         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_reliability, tvb, offset+1, 1, reliability);
3356         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_peak, tvb, offset+2, 1, peak);
3357         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare2, tvb, offset+2, 1, spare2);
3358         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_precedence, tvb, offset+2, 1, precedence);
3359         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare3, tvb, offset+3, 1, spare3);
3360         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_mean, tvb, offset+3, 1, mean);
3361
3362         if (length > 4) {
3363                 
3364                 traf_class = tvb_get_guint8(tvb, offset+4) & 0xE0;
3365                 del_order = tvb_get_guint8(tvb, offset+4) & 0x18;
3366                 del_err_sdu = tvb_get_guint8(tvb, offset+4) & 0x07;
3367                 max_sdu_size = tvb_get_guint8(tvb, offset+5);
3368                 max_dl = tvb_get_guint8(tvb, offset+6);
3369                 max_ul = tvb_get_guint8(tvb, offset+7);
3370                 res_ber = tvb_get_guint8(tvb, offset+8) & 0xF0;
3371                 sdu_err_ratio = tvb_get_guint8(tvb, offset+8) & 0x0F;
3372                 trans_delay = tvb_get_guint8(tvb, offset+9) & 0xFC;
3373                 traf_handl_prio = tvb_get_guint8(tvb, offset+9) & 0x03;
3374                 guar_ul = tvb_get_guint8(tvb, offset+10);
3375                 guar_dl = tvb_get_guint8(tvb, offset+11);
3376                 
3377                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_traf_class, tvb, offset+4, 1, traf_class);
3378                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_del_order, tvb, offset+4, 1, del_order);
3379                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_del_err_sdu, tvb, offset+4, 1, del_err_sdu);
3380                 if (max_sdu_size == 0 || max_sdu_size > 150)
3381                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_sdu_size, tvb, offset+5, 1, max_sdu_size);
3382                 if (max_sdu_size > 0 && max_sdu_size <= 150) {
3383                         mss = max_sdu_size*10;
3384                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_sdu_size, tvb, offset+5, 1, mss, "Maximum SDU size : %u octets", mss);
3385                 }
3386
3387                 if(max_ul == 0 || max_ul == 255)
3388                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+6, 1, max_ul);
3389                 if(max_ul > 0 && max_ul <= 63)
3390                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+6, 1, max_ul, "Maximum bit rate for uplink : %u kbps", max_ul);
3391                 if(max_ul > 63 && max_ul <=127) {
3392                         mu = 64 + ( max_ul - 64 ) * 8;
3393                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+6, 1, mu, "Maximum bit rate for uplink : %u kbps", mu);
3394                 }
3395         
3396                 if(max_ul > 127 && max_ul <=254) {
3397                         mu = 576 + ( max_ul - 128 ) * 64;
3398                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+6, 1, mu, "Maximum bit rate for uplink : %u kbps", mu);
3399                 }
3400
3401                 if(max_dl == 0 || max_dl == 255)
3402                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+7, 1, max_dl);
3403                 if(max_dl > 0 && max_dl <= 63)
3404                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+7, 1, max_dl, "Maximum bit rate for downlink : %u kbps", max_dl);
3405                 if(max_dl > 63 && max_dl <=127) {
3406                         md = 64 + ( max_dl - 64 ) * 8;
3407                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+7, 1, md, "Maximum bit rate for downlink : %u kbps", md);
3408                 }
3409                 if(max_dl > 127 && max_dl <=254) {
3410                         md = 576 + ( max_dl - 128 ) * 64;
3411                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+7, 1, md, "Maximum bit rate for downlink : %u kbps", md);
3412                 }
3413
3414                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_res_ber, tvb, offset+8, 1, res_ber);
3415                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_sdu_err_ratio, tvb, offset+8, 1, sdu_err_ratio);
3416                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_trans_delay, tvb, offset+9, 1, trans_delay);
3417                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_traf_handl_prio, tvb, offset+9, 1, traf_handl_prio);
3418
3419                 if(guar_ul == 0 || guar_ul == 255)
3420                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+10, 1, guar_ul);
3421                 if(guar_ul > 0 && guar_ul <= 63)
3422                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+10, 1, guar_ul, "Guaranteed bit rate for uplink : %u kbps", guar_ul);
3423                 if(guar_ul > 63 && guar_ul <=127) {
3424                         gu = 64 + ( guar_ul - 64 ) * 8;
3425                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+10, 1, gu, "Guaranteed bit rate for uplink : %u kbps", gu);
3426                 }
3427                 if(guar_ul > 127 && guar_ul <=254) {
3428                         gu = 576 + ( guar_ul - 128 ) * 64;
3429                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+10, 1, gu, "Guaranteed bit rate for uplink : %u kbps", gu);
3430                 }
3431
3432                 if(guar_dl == 0 || guar_dl == 255)
3433                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+11, 1, guar_dl);
3434                 if(guar_dl > 0 && guar_dl <= 63)
3435                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+11, 1, guar_dl, "Guaranteed bit rate for downlink : %u kbps", guar_dl);
3436                 if(guar_dl > 63 && guar_dl <=127) {
3437                         gd = 64 + ( guar_dl - 64 ) * 8;
3438                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+11, 1, gd, "Guaranteed bit rate for downlink : %u kbps", gd);
3439                 }
3440                 if(guar_dl > 127 && guar_dl <=254) {
3441                         gd = 576 + ( guar_dl - 128 ) * 64;
3442                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+11, 1, gd, "Guaranteed bit rate for downlink : %u kbps", gd);
3443                 }
3444         
3445         }
3446         
3447         return length + type;
3448
3449 }
3450
3451 static void
3452 decode_apn(tvbuff_t *tvb, int offset, guint16 length, proto_tree *tree) {
3453
3454         gchar   *apn = NULL;
3455         guint8  name_len, tmp;
3456
3457         if (length > 0) {
3458                 apn = g_malloc (length + 1);
3459                 name_len = tvb_get_guint8 (tvb, offset);
3460
3461                 if (name_len < 0x20) {
3462                         tvb_memcpy (tvb, apn, offset + 1, length);
3463                         for (;;) {
3464                                 if (name_len >= length - 1) break;
3465                                 tmp = name_len;
3466                                 name_len = name_len + apn[tmp] + 1;
3467                                 apn[tmp] = '.';
3468                         }
3469                 } else {
3470                         tvb_memcpy (tvb, apn, offset, length);
3471                 }
3472                 
3473                 apn[length-1] = '\0';
3474                 proto_tree_add_string(tree, gtp_version ? hf_gtpv1_apn : hf_gtpv0_apn, tvb, offset, length, apn);
3475                 g_free(apn);
3476         }
3477 }
3478
3479 /* GPRS:        9.60 v7.6.0, chapter 7.9.20
3480  * UMTS:        29.060 v4.0, chapter 7.7.29
3481  * TODO:        unify addr functions 
3482  */
3483 static int
3484 decode_gtp_pdp_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3485
3486         guint8          ggsn_addr_len, apn_len, trans_id, vaa, order, nsapi, sapi, pdu_send_no, pdu_rec_no, pdp_cntxt_id,
3487                         pdp_type_org, pdp_type_num, pdp_addr_len;
3488         guint16         length, sn_down, sn_up, up_flow;
3489         guint32         addr_ipv4, up_teid, up_teid_cp;
3490         struct  e_in6_addr addr_ipv6;   
3491         proto_tree      *ext_tree_pdp;
3492         proto_item      *te;
3493         
3494         length = tvb_get_ntohs(tvb, offset+1);
3495         
3496         te = proto_tree_add_text(tree, tvb, offset, length+3, val_to_str(GTP_EXT_PDP_CNTXT, gtp_val, "Unknown message"));
3497         ext_tree_pdp = proto_item_add_subtree(te, ett_gtp_pdp);
3498         
3499         vaa = (tvb_get_guint8(tvb, offset+3) >> 6) & 0x01;
3500         order = (tvb_get_guint8(tvb, offset+3) >> 4) & 0x01;
3501         nsapi =  tvb_get_guint8(tvb, offset+3) & 0x0F;
3502         sapi = tvb_get_guint8(tvb, offset+4) & 0x0F;
3503         
3504         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "VPLMN address allowed: %s", yesno[vaa]);
3505         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "Reordering required: %s", yesno[order]);
3506         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "NSAPI: %u", nsapi);
3507         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "SAPI: %u", sapi);
3508         
3509         switch (gtp_version) {
3510                 case 0: 
3511                         decode_qos_gprs(tvb, offset+5, ext_tree_pdp, "QoS subscribed", 0);
3512                         decode_qos_gprs(tvb, offset+8, ext_tree_pdp, "QoS requested", 0);
3513                         decode_qos_gprs(tvb, offset+11, ext_tree_pdp, "QoS negotiated", 0);
3514                         offset = offset + 14;
3515                         break;
3516                 case 1: 
3517                         offset = offset + 5;
3518                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS subscribed", 1);
3519                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS requested", 1);
3520                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS negotiated", 1);
3521                         break;
3522                 default:
3523                         break;
3524         }
3525         
3526         sn_down = tvb_get_ntohs(tvb, offset);
3527         sn_up = tvb_get_ntohs(tvb, offset+2);
3528         pdu_send_no = tvb_get_guint8(tvb, offset+4);
3529         pdu_rec_no = tvb_get_guint8(tvb, offset+5);
3530         
3531         proto_tree_add_text(ext_tree_pdp, tvb, offset, 2, "Sequence number down: %u", sn_down);
3532         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 2, "Sequence number up: %u", sn_up);
3533         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "Send N-PDU number: %u", pdu_send_no);
3534         proto_tree_add_text(ext_tree_pdp, tvb, offset+5, 1, "Receive N-PDU number: %u", pdu_rec_no);
3535         
3536         switch (gtp_version) {
3537                 case 0:
3538                         up_flow = tvb_get_ntohs(tvb, offset+6);
3539                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 2, "Uplink flow label signalling: %u", up_flow);
3540                         offset = offset + 8;
3541                         break;
3542                 case 1:
3543                         up_teid = tvb_get_ntohl(tvb, offset+6);
3544                         up_teid_cp = tvb_get_ntohl(tvb, offset+10);
3545                         pdp_cntxt_id = tvb_get_guint8(tvb, offset+14);
3546                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 4, "Uplink TEID: %x", up_teid);
3547                         proto_tree_add_text(ext_tree_pdp, tvb, offset+10, 4, "Uplink TEID control plane: %x", up_teid_cp);
3548                         proto_tree_add_text(ext_tree_pdp, tvb, offset+14, 1, "PDP context identifier: %u", pdp_cntxt_id);
3549                         offset = offset + 15;
3550                         break;
3551                 default:
3552                         break;
3553         }
3554
3555         pdp_type_org = tvb_get_guint8(tvb, offset) & 0x0F;
3556         pdp_type_num = tvb_get_guint8(tvb, offset+1);
3557         pdp_addr_len = tvb_get_guint8(tvb, offset+2);
3558         
3559         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "PDP organization: %s", val_to_str(pdp_type_org, pdp_type, "Unknown PDP org"));
3560         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 1, "PDP type: %s", val_to_str(pdp_type_num, pdp_org_type, "Unknown PDP type"));
3561         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 1, "PDP address length: %u", pdp_addr_len);
3562
3563         if (pdp_addr_len > 0) {
3564                 switch (pdp_type_num) {
3565                         case 0x21:
3566                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
3567                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 4, "PDP address: %s", ip_to_str((guint8 *)&addr_ipv4));
3568                                 break;
3569                         case 0x57:
3570                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
3571                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 16, "PDP address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3572                                 break;
3573                         default:
3574                                 break;
3575                 }
3576         }
3577         
3578         offset = offset + 3 + pdp_addr_len;
3579
3580         ggsn_addr_len = tvb_get_guint8(tvb, offset);
3581         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN address length: %u", ggsn_addr_len);
3582         
3583         switch (ggsn_addr_len) {
3584                 case 4: 
3585                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+1, sizeof addr_ipv4);
3586                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN address: %s", ip_to_str((guint8 *)&addr_ipv4));
3587                         break;
3588                 case 16: 
3589                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+1, sizeof addr_ipv6);
3590                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3591                         break;
3592                 default:
3593                         break;
3594         }
3595         
3596         offset = offset + 1 + ggsn_addr_len;
3597         
3598         if (gtp_version == 1) {
3599
3600                 ggsn_addr_len = tvb_get_guint8(tvb, offset);
3601                 proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN 2 address length: %u", ggsn_addr_len);
3602                 
3603                 switch (ggsn_addr_len) {
3604                         case 4: 
3605                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+1, sizeof addr_ipv4);
3606                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN 2 address: %s", ip_to_str((guint8 *)&addr_ipv4));
3607                                 break;
3608                         case 16: 
3609                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+1, sizeof addr_ipv6);
3610                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN 2 address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3611                                 break;
3612                         default:
3613                                 break;
3614                 }
3615                 offset = offset + 1 + ggsn_addr_len;
3616                 
3617         }
3618         
3619         apn_len = tvb_get_guint8(tvb, offset);
3620         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "APN length: %u", apn_len);
3621         decode_apn(tvb, offset+1, apn_len, ext_tree_pdp);
3622
3623         offset = offset + 1 + apn_len;
3624         
3625         trans_id = tvb_get_guint8(tvb, offset);
3626         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "Transaction identifier: %u", trans_id);
3627
3628         return 3+length;
3629 }
3630
3631 /* GPRS:        9.60, v7.6.0, chapter 7.9.21
3632  * UMTS:        29.060, v4.0, chapter 7.7.30
3633  */
3634 static int
3635 decode_gtp_apn(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3636
3637         guint16         length;
3638         proto_tree      *ext_tree_apn;
3639         proto_item      *te;
3640         
3641         length = tvb_get_ntohs(tvb, offset+1);  
3642
3643         te = proto_tree_add_text(tree, tvb, offset, length+3, val_to_str(GTP_EXT_APN, gtp_val, "Unknown field"));
3644         ext_tree_apn = proto_item_add_subtree(te, ett_gtp_apn);
3645         
3646         proto_tree_add_text(ext_tree_apn, tvb, offset+1, 2, "APN length : %u", length);
3647         decode_apn(tvb, offset+3, length, ext_tree_apn);
3648
3649         return 3+length;
3650 }
3651
3652 /* GPRS:        9.60 v7.6.0, chapter 7.9.22
3653  *              4.08 v. 7.1.2, chapter 10.5.6.3 (p.580)
3654  * UMTS:        29.060 v4.0, chapter 7.7.31
3655  *              24.008, v4.2, chapter 10.5.6.3
3656  * TODO:        check if length is 8 or 16 bits
3657  *              - proto_conf in 3G */
3658 int
3659 decode_gtp_proto_conf(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3660
3661         guint16         length, proto_offset;
3662         guint8          *ptr, conf, proto_len, tmp, msg;
3663         tvbuff_t        *next_tvb;
3664         proto_tree      *ext_tree_proto;
3665         proto_item      *te;
3666
3667         length = tvb_get_ntohs(tvb, offset + 1);
3668
3669         te = proto_tree_add_text(tree, tvb, offset, length + 3, val_to_str(GTP_EXT_PROTO_CONF, gtp_val, "Unknown message"));
3670         ext_tree_proto = proto_item_add_subtree(te, ett_gtp_proto);
3671
3672         proto_tree_add_text(ext_tree_proto, tvb, offset + 1, 2, "Length: %u", length);
3673
3674         if (length < 1) return 3;
3675
3676         conf = tvb_get_guint8(tvb, offset + 3) & 0x07;
3677         proto_offset = 1;       /* ... 1st byte is conf */
3678
3679         for (;;) {
3680                 if (proto_offset >= length) break;
3681                 proto_len = tvb_get_guint8(tvb, offset + 6); 
3682                 proto_offset += proto_len + 3; 
3683                         
3684                 if ((proto_len > 0) && ppp_reorder) { 
3685                         
3686                         /* this part changes layout of GTP payload: 
3687                          * it swaps "length field" with "protocol header"  */ 
3688                         
3689                         ptr = (guint8 *)tvb_get_ptr(tvb, offset + 4, 3); 
3690                         
3691                         tmp = ptr[2]; 
3692                         ptr[2] = ptr[1]; 
3693                         ptr[1] = ptr[0]; 
3694                         ptr[0] = tmp; 
3695                                 
3696                         next_tvb = tvb_new_subset(tvb, offset + 5, proto_len + 2, proto_len + 2); 
3697                         call_dissector(ppp_handle, next_tvb, pinfo, ext_tree_proto); 
3698                                 
3699                         if (check_col(pinfo->cinfo, COL_PROTOCOL))
3700                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP"); 
3701                                 
3702                         if (check_col(pinfo->cinfo, COL_INFO)) { 
3703                                         
3704                                 msg = tvb_get_guint8(tvb, 1); 
3705                                                 
3706                                 col_set_str(pinfo->cinfo, COL_INFO, val_to_str(msg, message_type, "Unknown")); 
3707                         } 
3708                 } 
3709         }
3710
3711         return 3 + length;
3712 }
3713
3714 /* GPRS:        9.60 v7.6.0, chapter 7.9.23
3715  * UMTS:        29.060 v4.0, chapter 7.7.32
3716  */
3717 static int
3718 decode_gtp_gsn_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3719         
3720         guint8          addr_type, addr_len;    
3721         guint16         length; 
3722         guint32         addr_ipv4;
3723         struct  e_in6_addr addr_ipv6;
3724         proto_tree      *ext_tree_gsn_addr;
3725         proto_item      *te;
3726         
3727         length = tvb_get_ntohs(tvb, offset+1);
3728         
3729         te = proto_tree_add_text(tree, tvb, offset, 3+length, "GSN address : ");
3730         ext_tree_gsn_addr = proto_item_add_subtree(te, ett_gtp_gsn_addr);
3731         
3732         switch (length) {
3733                 case 4:
3734                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length);
3735                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
3736                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
3737                         proto_tree_add_ipv4(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv4 : hf_gtpv0_gsn_ipv4, tvb, offset+3, 4, addr_ipv4);
3738                         break;
3739                 case 5:
3740                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
3741                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
3742                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_type : hf_gtpv0_gsn_addr_type, tvb, offset+3, 1, addr_type);
3743                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
3744                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_len : hf_gtpv0_gsn_addr_len, tvb, offset+3, 1, addr_len);
3745                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+4, sizeof addr_ipv4);
3746                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
3747                         proto_tree_add_ipv4(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv4 : hf_gtpv0_gsn_ipv4, tvb, offset+4, 4, addr_ipv4);
3748                         break;
3749                 case 16:
3750                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length); 
3751                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
3752                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3753                         proto_tree_add_ipv6(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv6 : hf_gtpv0_gsn_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
3754                         break;
3755                 case 17: 
3756                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
3757                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
3758                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_type : hf_gtpv0_gsn_addr_type, tvb, offset+3, 1, addr_type);
3759                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
3760                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_len : hf_gtpv0_gsn_addr_len, tvb, offset+3, 1, addr_len);
3761                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+4, sizeof addr_ipv6);
3762                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3763                         proto_tree_add_ipv6(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv6 : hf_gtpv0_gsn_ipv6, tvb, offset+4, 16, (guint8*)&addr_ipv6);
3764                         break;
3765                 default:
3766                         proto_item_append_text(te, "unknown type or wrong length");
3767                         break;
3768         }
3769         
3770         return 3+length;
3771 }
3772
3773 /* GPRS:        9.60 v7.6.0, chapter 7.9.24
3774  * UMTS:        29.060 v4.0, chapter 7.7.33
3775  */
3776 static int
3777 decode_gtp_msisdn(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3778                 
3779         const guint8    *msisdn_val;
3780         gchar           *msisdn_str;
3781         guint16         length;
3782         
3783         length = tvb_get_ntohs(tvb, offset+1);
3784         
3785         if (length < 1) return 3;
3786         
3787         msisdn_val = tvb_get_ptr(tvb, offset+3, length);
3788         msisdn_str = msisdn_to_str(msisdn_val, length);
3789         
3790         proto_tree_add_string(tree, gtp_version ? hf_gtpv1_msisdn : hf_gtpv0_msisdn, tvb, offset, 3+length, msisdn_str);
3791         
3792         return 3+length;
3793 }
3794
3795 /* GPRS:        not present
3796  * UMTS:        29.060 v4.0, chapter 7.7.34
3797  *              24.008 v4.2, chapter 10.5.6.5
3798  */
3799 static int
3800 decode_gtp_qos_umts(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3801
3802         return decode_qos_umts(tvb, offset, tree, "Quality of Service", 2);
3803 }
3804
3805 /* GPRS:        not present
3806  * UMTS:        29.060 v4.0, chapter 7.7.35
3807  */
3808 static int
3809 decode_gtp_auth_qui(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3810         
3811         return (1 + decode_quintuplet(tvb, offset+1, tree, 1, 1));
3812
3813 }
3814
3815 /* GPRS:        not present
3816  * UMTS:        29.060 v4.0, chapter 7.7.36
3817  *              24.008 v4.2, chapter 10.5.6.12
3818  */
3819 static int
3820 decode_gtp_tft(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3821
3822         guint16         length, port1, port2, tos;
3823         guint8          tft_code, no_packet_filters, i, pf_id, pf_eval, pf_len, pf_content_id, pf_offset, proto;
3824         guint32         addr_ipv4, ipsec_id, label;
3825         struct  e_in6_addr addr_ipv6;
3826         proto_tree      *ext_tree_tft, *ext_tree_tft_pf;
3827         proto_item      *te, *tee;
3828         
3829         length = tvb_get_ntohs(tvb, offset+1);
3830         
3831         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Traffic flow template");
3832         ext_tree_tft = proto_item_add_subtree(te, ett_gtp_tft);
3833         
3834         tft_code = (tvb_get_guint8(tvb, offset+3) >> 5) & 0x07;
3835         no_packet_filters = tvb_get_guint8(tvb, offset+3) & 0x0F;
3836         
3837         proto_tree_add_text(ext_tree_tft, tvb, offset+1, 2, "TFT length: %u", length);
3838         proto_tree_add_text(ext_tree_tft, tvb, offset+3, 1, "TFT operation code: %u", tft_code);
3839         proto_tree_add_text(ext_tree_tft, tvb, offset+3, 1, "Number of packet filters: %u", no_packet_filters); 
3840
3841         offset = offset + 4;
3842         
3843         for (i=0;i<no_packet_filters;i++) {
3844                 
3845                 pf_id = tvb_get_guint8(tvb, offset);
3846                 
3847                 tee = proto_tree_add_text(ext_tree_tft, tvb, offset, 1, "Packet filter id: %u", pf_id);
3848                 ext_tree_tft_pf = proto_item_add_subtree(tee, ett_gtp_tft_pf);
3849                 
3850                 if (tft_code != 2) {
3851                         
3852                         pf_eval = tvb_get_guint8(tvb, offset+1);
3853                         pf_len = tvb_get_guint8(tvb, offset+2);
3854                         
3855                         proto_tree_add_text(ext_tree_tft_pf, tvb, offset+1, 1, "Evaluation precedence: %u", pf_eval);
3856                         proto_tree_add_text(ext_tree_tft_pf, tvb, offset+2, 1, "Contents length: %u", pf_len);
3857
3858                         offset = offset + 3;
3859                         pf_offset = 0;  
3860                         
3861                         while (pf_offset < pf_len) {    
3862                                 
3863                                 pf_content_id = tvb_get_guint8(tvb, offset + pf_offset);
3864                                 
3865                                 switch (pf_content_id) {
3866                                         /* address IPv4 and mask = 8 bytes*/
3867                                         case 0x10: 
3868                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset, 1, "Address IPv4 and mask (0x10)");
3869                                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset + pf_offset + 1, sizeof addr_ipv4);
3870                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\tAddress: %s", ip_to_str((guint8 *)&addr_ipv4));
3871                                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset + pf_offset + 5, sizeof addr_ipv4);
3872                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 5, 4, "\tNetmask: %s", ip_to_str((guint8 *)&addr_ipv4));
3873                                                 pf_offset = pf_offset + 9;
3874                                                 break;
3875                                         /* address IPv6 and mask = 32 bytes*/
3876                                         case 0x20: 
3877                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Address IPv6 and mask (0x20)");
3878                                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+pf_offset+1, sizeof addr_ipv6);
3879                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+offset+1, 16, "\tAddress: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3880                                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+pf_offset+17, sizeof addr_ipv6);
3881                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+offset+17, 16, "\tNetmask: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3882                                                 pf_offset = pf_offset + 33;
3883                                                 break;
3884                                         /* protocol identifier/next header type = 1 byte*/
3885                                         case 0x30:
3886                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset, 1, "IPv4 protocol identifier/IPv6 next header (0x30)");
3887                                                 proto = tvb_get_guint8(tvb, offset + pf_offset + 1);
3888                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 1, "\t%u", proto);
3889                                                 pf_offset = pf_offset + 2;
3890                                                 break;
3891                                         /* single destination port type = 2 bytes */
3892                                         case 0x40:
3893                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset, 1, "Destination port (0x40)");
3894                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3895                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 2, "\t%u", port1);
3896                                                 pf_offset = pf_offset + 3;
3897                                                 break;
3898                                         /* destination port range type = 4 bytes */
3899                                         case 0x41:
3900                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Destination port range (0x41)");
3901                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3902                                                 port2 = tvb_get_ntohs(tvb, offset + pf_offset + 3);
3903                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\t%u-%u", port1, port2);
3904                                                 pf_offset = pf_offset + 5;
3905                                                 break;
3906                                         /* single source port type = 2 bytes */
3907                                         case 0x50:
3908                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Source port (0x50)");
3909                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3910                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 2, "\t%u", port1);
3911                                                 pf_offset = pf_offset + 3;
3912                                                 break;
3913                                         /* source port range type = 4 bytes */
3914                                         case 0x51:
3915                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Source port range (0x51)");
3916                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3917                                                 port2 = tvb_get_ntohs(tvb, offset + pf_offset + 3);
3918                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\t%u-%u", port1, port2);
3919                                                 pf_offset = pf_offset + 5;
3920                                                 break;
3921                                         /* security parameter index type = 4 bytes */
3922                                         case 0x60:
3923                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Security parameter index (0x60)");
3924                                                 ipsec_id = tvb_get_ntohl(tvb, offset + pf_offset + 1);
3925                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\t%x", ipsec_id);
3926                                                 pf_offset = pf_offset + 5;
3927                                                 break;
3928                                         /* type of service/traffic class type = 2 bytes */
3929                                         case 0x70:
3930                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Type of Service/Traffic Class (0x70)");
3931                                                 tos = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3932                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 2, "\t%u", tos);
3933                                                 pf_offset = pf_offset + 3;
3934                                                 break;
3935                                         /* flow label type = 3 bytes */
3936                                         case 0x80:
3937                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Flow label (0x80)");
3938                                                 label = tvb_get_ntoh24(tvb, offset + pf_offset + 1) & 0x0FFFFF;;
3939                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 3, "\t%x", label);
3940                                                 pf_offset = pf_offset + 4;
3941                                                 break;
3942                                         
3943                                         default: 
3944                                                 break;
3945                                 }
3946                         }
3947                 }       
3948         }
3949         
3950         return 3 + length;
3951 }
3952
3953 /* GPRS:        not present
3954  * UMTS:        29.060 v4.0, chapter 7.7.37
3955  *              25.413 v3.4, chapter ???
3956  */
3957 static int
3958 decode_gtp_target_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3959
3960         guint16         length;
3961
3962         length = tvb_get_ntohs(tvb, offset + 1);
3963
3964         proto_tree_add_text(tree, tvb, offset, 3 + length, "Targer Identification");
3965         
3966         return 3 + length;
3967 }
3968
3969
3970 /* GPRS:        not present
3971  * UMTS:        29.060 v4.0, chapter 7.7.38
3972  */
3973 static int
3974 decode_gtp_utran_cont(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3975
3976         guint16         length;
3977
3978         length = tvb_get_ntohs(tvb, offset + 1);
3979
3980         proto_tree_add_text(tree, tvb, offset, 3 + length, "UTRAN transparent field");
3981
3982         return 3 + length;
3983
3984 }
3985         
3986
3987 /* GPRS:        not present
3988  * UMTS:        29.060 v4.0, chapter 7.7.39
3989  */
3990 static int
3991 decode_gtp_rab_setup(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3992
3993         guint32         teid, addr_ipv4;
3994         guint16         length;
3995         guint8          nsapi;
3996         struct  e_in6_addr addr_ipv6;
3997         proto_tree      *ext_tree_rab_setup;
3998         proto_item      *te;
3999         
4000         length = tvb_get_ntohs(tvb, offset + 1);
4001         nsapi = tvb_get_guint8(tvb, offset + 3) & 0x0F;
4002
4003         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Radio Access Bearer Setup Information");
4004         ext_tree_rab_setup = proto_item_add_subtree(te, ett_gtp_rab_setup);
4005
4006         proto_tree_add_text(ext_tree_rab_setup, tvb, offset+1, 2, "RAB setup length : %u", length);
4007         proto_tree_add_uint(ext_tree_rab_setup, hf_gtpv1_nsapi, tvb, offset+3, 1, nsapi);
4008
4009         if (length > 1) {
4010                 
4011                 teid = tvb_get_ntohl(tvb, offset + 4);
4012
4013                 proto_tree_add_uint(ext_tree_rab_setup, hf_gtpv1_teid_data, tvb, offset+4, 4, teid);
4014         
4015                 switch (length) {
4016                         case 12:
4017                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+8, sizeof addr_ipv4);
4018                                 proto_tree_add_ipv4(ext_tree_rab_setup, hf_gtpv1_rnc_ipv4, tvb, offset+8, 4, addr_ipv4);
4019                                 break;
4020                         case 24: 
4021                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+8, sizeof addr_ipv6);
4022                                 proto_tree_add_ipv6(ext_tree_rab_setup, hf_gtpv1_rnc_ipv6, tvb, offset+8, 16, (guint8 *)&addr_ipv6);
4023                                 break;
4024                         default:
4025                                 break;
4026                 }
4027         }
4028
4029         return 3 + length;
4030 }
4031
4032
4033 /* GPRS:        not present
4034  * UMTS:        29.060 v4.0, chapter 7.7.40
4035  */
4036 static int
4037 decode_gtp_hdr_list(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4038
4039         int             i;
4040         guint8          length, hdr;
4041         proto_tree      *ext_tree_hdr_list;
4042         proto_item      *te;
4043         
4044         length = tvb_get_guint8(tvb, offset + 1);
4045
4046         te = proto_tree_add_text(tree, tvb, offset, 2+length, "%s", val_to_str(GTP_EXT_HDR_LIST, gtp_val, "Unknown"));
4047         ext_tree_hdr_list = proto_item_add_subtree(te, ett_gtp_hdr_list);
4048         
4049         proto_tree_add_text(ext_tree_hdr_list, tvb, offset+1, 1, "Number of Extension Header Types in list (i.e., length) : %u", length);
4050
4051         for(i=0 ; i<length ; i++) {
4052                 hdr = tvb_get_guint8(tvb, offset+2+i);
4053
4054                 proto_tree_add_text(ext_tree_hdr_list, tvb, offset+2+i, 1, "No. %u --> Extension Header Type value : %s (%u)", i+1, val_to_str(hdr, gtp_val, "Unknown Extension Header Type"), hdr);
4055         }
4056
4057         return 2 + length;
4058 }
4059
4060 /* GPRS:        not present
4061  * UMTS:        29.060 v4.0, chapter 7.7.41
4062  * TODO:        find TriggerID description
4063  */
4064 static int
4065 decode_gtp_trigger_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4066
4067         guint16         length;
4068
4069         length = tvb_get_ntohs(tvb, offset + 1);
4070
4071         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_TRIGGER_ID, gtp_val, "Unknown"), length);
4072
4073         return 3 + length;
4074
4075 }
4076
4077 /* GPRS:        not present
4078  * UMTS:        29.060 v4.0, chapter 7.7.42
4079  * TODO:        find OMC-ID description
4080  */
4081 static int
4082 decode_gtp_omc_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4083
4084         guint16         length;
4085
4086         length = tvb_get_ntohs(tvb, offset + 1);
4087
4088         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_OMC_ID, gtp_val, "Unknown"), length);
4089
4090         return 3 + length;
4091
4092 }
4093
4094 /* GPRS:        9.60 v7.6.0, chapter 7.9.25
4095  * UMTS:        29.060 v4.0, chapter 7.7.43
4096  */
4097 static int
4098 decode_gtp_chrg_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4099                 
4100         guint16         length; 
4101         guint32         addr_ipv4;
4102         struct  e_in6_addr addr_ipv6;
4103         proto_tree      *ext_tree_chrg_addr;
4104         proto_item      *te;
4105         
4106         length = tvb_get_ntohs(tvb, offset+1);
4107         
4108         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_CHRG_ADDR, gtp_val, "Unknown"));
4109         ext_tree_chrg_addr = proto_item_add_subtree(te, ett_gtp_chrg_addr);
4110         
4111         proto_tree_add_text(ext_tree_chrg_addr, tvb, offset+1, 2, "%s length : %u", val_to_str(GTP_EXT_CHRG_ADDR, gtp_val, "Unknown"), length);
4112         
4113         switch (length) {
4114                 case 4:
4115                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
4116                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4117                         proto_tree_add_ipv4(ext_tree_chrg_addr, gtp_version ? hf_gtpv1_chrg_ipv4 : hf_gtpv0_chrg_ipv4, tvb, offset+3, 4, addr_ipv4);
4118                         break;
4119                 case 16: 
4120                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
4121                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4122                         proto_tree_add_ipv6(ext_tree_chrg_addr, gtp_version ? hf_gtpv1_chrg_ipv6 : hf_gtpv0_chrg_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
4123                         break;
4124                 default:
4125                         proto_item_append_text(te, "unknown type or wrong length");
4126                         break;
4127         }
4128
4129         return 3 + length;
4130 }
4131
4132 /* GPRS:        12.15
4133  * UMTS:        33.015
4134  */
4135 static int
4136 decode_gtp_rel_pack(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4137         
4138         guint16         length, n, number;
4139         proto_tree      *ext_tree_rel_pack;
4140         proto_item      *te;
4141
4142         length = tvb_get_ntohs(tvb, offset + 1);
4143         
4144         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of released packets IE");
4145         ext_tree_rel_pack = proto_item_add_subtree(te, ett_gtp_rel_pack);
4146         
4147         n = 0;
4148         
4149         while (n < length) {
4150
4151                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4152                 proto_tree_add_text(ext_tree_rel_pack, tvb, offset + 3 + n, 2, "%u", number);
4153                 n = n + 2;
4154
4155         }
4156         
4157         return 3 + length;
4158 }
4159
4160 /* GPRS:        12.15
4161  * UMTS:        33.015
4162  */
4163 static int
4164 decode_gtp_can_pack(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4165         
4166         guint16         length, n, number;
4167         proto_tree      *ext_tree_can_pack;
4168         proto_item      *te;
4169
4170         length = tvb_get_ntohs(tvb, offset + 1);
4171         
4172         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of cancelled  packets IE");
4173         ext_tree_can_pack = proto_item_add_subtree(te, ett_gtp_can_pack);
4174         
4175         n = 0;
4176         
4177         while (n < length) {
4178
4179                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4180                 proto_tree_add_text(ext_tree_can_pack, tvb, offset + 3 + n, 2, "%u", number);
4181                 n = n + 2;
4182
4183         }
4184         
4185         return 3 + length;
4186 }
4187
4188 /* CDRs dissector */
4189 static int
4190 decode_gtp_data_req(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4191         
4192         guint16         length, format_ver, data_len, i, j;
4193         guint8          no, format, rectype;
4194         proto_tree      *ext_tree, *cdr_tree;
4195         proto_item      *te, *ce;
4196
4197         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_DATA_REQ, gtp_val, "Unknown message"));
4198         ext_tree = proto_item_add_subtree(te, ett_gtp_ext);
4199         
4200         length = tvb_get_ntohs(tvb, offset + 1);
4201         no = tvb_get_guint8(tvb, offset + 3);
4202         format = tvb_get_guint8(tvb, offset + 4);
4203         format_ver = tvb_get_ntohs(tvb, offset + 5);
4204         
4205         proto_tree_add_text(ext_tree, tvb, offset+1, 2, "Length: %u", length);
4206         proto_tree_add_text(ext_tree, tvb, offset+3, 1, "Number of data records: %u", no);
4207         proto_tree_add_text(ext_tree, tvb, offset+4, 1, "Data record format: %u", format);
4208         proto_tree_add_text(ext_tree, tvb, offset+5, 2, "Data record format version: %u", format_ver);
4209
4210         data_len = 0;
4211         offset = offset + 7;
4212
4213         if (gtpv0_cdr_as != DONT_DISSECT_CDRS) {
4214         
4215         for (i = 0; i < no; i++) {
4216                 data_len = tvb_get_ntohs(tvb, offset);
4217                 rectype = tvb_get_guint8(tvb, offset+2);
4218                 switch (rectype) {
4219                         case 0x13:              /* GCDR */ 
4220                                 if (tvb_length_remaining(tvb, offset) < 3 + 118) {
4221                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "GCDR fragmented, can't dissect");
4222                                         break;
4223                                 }
4224                                 
4225                                 tvb_memcpy(tvb, gcdr.imsi, offset+3, 8);        
4226                                 tvb_memcpy(tvb, (guint8 *)&gcdr.ggsnaddr, offset+11, sizeof gcdr.ggsnaddr);
4227                                 gcdr.chrgid = tvb_get_ntohl(tvb, offset+15);
4228                                 tvb_memcpy(tvb, (guint8 *)&gcdr.sgsnaddr, offset+19, sizeof gcdr.sgsnaddr);
4229                                 tvb_memcpy(tvb, gcdr.apn, offset+23, 63);
4230                                 gcdr.pdporg = tvb_get_guint8(tvb, offset+86);
4231                                 gcdr.pdptype = tvb_get_guint8(tvb, offset+87);
4232                                 tvb_memcpy(tvb, (guint8 *)&gcdr.pdpaddr, offset+88, sizeof gcdr.pdpaddr);
4233                                 gcdr.addrflag = tvb_get_guint8(tvb, offset+92);
4234                                 gcdr.uplink = tvb_get_ntohl(tvb, offset+96);
4235                                 gcdr.downlink = tvb_get_ntohl(tvb, offset+100);
4236                                 gcdr.timestamp = tvb_get_ntohl(tvb, offset+104);
4237                                 gcdr.opening = tvb_get_ntohl(tvb, offset+108);
4238                                 gcdr.duration = tvb_get_ntohl(tvb, offset+112);
4239                                 gcdr.closecause = tvb_get_guint8(tvb, offset+116);
4240                                 gcdr.seqno = tvb_get_ntohl(tvb, offset+117);
4241                                 
4242                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "GCDR (0x13), sequence number: %u", gcdr.seqno);
4243                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4244                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4245                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4246                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 8, "IMSI: %s", id_to_str(gcdr.imsi));
4247                                 proto_tree_add_text(cdr_tree, tvb, offset+11, 4, "GGSN address: %s", ip_to_str((guint8 *)&gcdr.ggsnaddr));
4248                                 proto_tree_add_text(cdr_tree, tvb, offset+15, 4, "Charging ID: %x", gcdr.chrgid);
4249                                 proto_tree_add_text(cdr_tree, tvb, offset+19, 4, "SGSN address: %s", ip_to_str((guint8 *)&gcdr.sgsnaddr));
4250                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 63, "APN: %s", gcdr.apn);
4251                                 proto_tree_add_text(cdr_tree, tvb, offset+86, 1, "PDP org: %s", val_to_str(gcdr.pdporg, pdp_org_type, "Unknown PDP org"));
4252                                 proto_tree_add_text(cdr_tree, tvb, offset+87, 1, "PDP type: %s", val_to_str(gcdr.pdptype, pdp_type, "Unknown PDP type"));
4253                                 proto_tree_add_text(cdr_tree, tvb, offset+88, 4, "PDP address: %s", ip_to_str((guint8 *)&gcdr.pdpaddr));
4254                                 proto_tree_add_text(cdr_tree, tvb, offset+92, 1, "PDP address type: %u", gcdr.addrflag);
4255                                 decode_qos_gprs(tvb, offset+93, cdr_tree, "QoS", 0);
4256                                 proto_tree_add_text(cdr_tree, tvb, offset+96, 4, "Uplink volume: %u", gcdr.uplink);
4257                                 proto_tree_add_text(cdr_tree, tvb, offset+100, 4, "Downlink volume: %u", gcdr.downlink);
4258                                 proto_tree_add_text(cdr_tree, tvb, offset+104, 4, "Timestamp: %s", time_int_to_str(gcdr.timestamp));
4259                                 proto_tree_add_text(cdr_tree, tvb, offset+108, 4, "Record opening time: %s", time_int_to_str(gcdr.opening));
4260                                 proto_tree_add_text(cdr_tree, tvb, offset+112, 4, "Duration: %s", rel_time_int_to_str(gcdr.duration));
4261                                 proto_tree_add_text(cdr_tree, tvb, offset+116, 1, "Cause for close: %s (%u)", val_to_str(gcdr.closecause, cdr_close_type, "Unknown cause"), gcdr.closecause);
4262                                 proto_tree_add_text(cdr_tree, tvb, offset+117, 4, "Sequence number: %u", gcdr.seqno);
4263                                 
4264                                 if (data_len > 119) {
4265                                         tvb_memcpy (tvb, gcdr.msisdn, offset + 121, 9);
4266                                         proto_tree_add_text(cdr_tree, tvb, offset+121, 9, "MSISDN: %s", msisdn_to_str (gcdr.msisdn, 9));
4267                                 }
4268                                         
4269                                 break;
4270
4271                         case 0x12:              /* SCDR */
4272                                 if (tvb_length_remaining(tvb, offset) < 3 + 277) {
4273                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "SCDR fragmented, can't dissect");
4274                                         break;
4275                                 }
4276                                 
4277                                 scdr.len = tvb_get_letohs(tvb, offset+3);
4278                                 scdr.netini = tvb_get_guint8(tvb, offset+5);
4279                                 scdr.anon = tvb_get_guint8(tvb, offset+6);
4280                                 scdr.imsilen = tvb_get_guint8(tvb, offset+7);
4281                                 tvb_memcpy(tvb, scdr.imsi, offset+8, 8);
4282                                 tvb_memcpy(tvb, scdr.imei, offset+16, 8);
4283                                 scdr.msisdnlen = tvb_get_guint8(tvb, offset+24);
4284                                 tvb_memcpy(tvb, scdr.msisdn, offset+25, 10);
4285                                 tvb_memcpy(tvb, (guint8 *)&scdr.sgsnaddr, offset+35, sizeof scdr.sgsnaddr);
4286                                 tvb_memcpy(tvb, scdr.msclass_notused, offset+39, 12);
4287                                 scdr.msclass_caplen = tvb_get_guint8(tvb, offset+51);
4288                                 scdr.msclass_cap = tvb_get_guint8(tvb, offset+52);
4289                                 scdr.msclass_capomit = tvb_get_ntohs(tvb, offset+53);
4290                                 scdr.lac = tvb_get_ntohs(tvb, offset+55);
4291                                 scdr.rac = tvb_get_guint8(tvb, offset+57);
4292                                 scdr.cid = tvb_get_ntohs(tvb, offset+58);
4293                                 scdr.chrgid = tvb_get_ntohl(tvb, offset+60);
4294                                 tvb_memcpy(tvb, (guint8 *)&scdr.ggsnaddr, offset+64, sizeof scdr.ggsnaddr);
4295                                 tvb_memcpy(tvb, scdr.apn, offset+68, 64);
4296                                 scdr.pdporg = tvb_get_guint8(tvb, offset+132);
4297                                 scdr.pdptype = tvb_get_guint8(tvb, offset+133);
4298                                 tvb_memcpy(tvb, (guint8 *)&scdr.pdpaddr, offset+134, sizeof scdr.pdpaddr);
4299                                 scdr.listind = tvb_get_guint8(tvb, offset+138);
4300                                 for (j=0;j<4;j++) {
4301                                         scdr.change[j].change = tvb_get_guint8(tvb, offset+139+23*j);
4302                                         scdr.change[j].time1 = tvb_get_ntohl(tvb, offset+140+23*j);
4303                                         scdr.change[j].time2 = tvb_get_ntohl(tvb, offset+144+23*j);
4304                                         scdr.change[j].uplink = tvb_get_ntohl(tvb, offset+148+23*j);
4305                                         scdr.change[j].downlink = tvb_get_ntohl(tvb, offset+152+23*j);
4306 /*                                      tvb_memcpy(tvb, scdr.change[j].qos_req, offset+156+23*j, 3);
4307                                         tvb_memcpy(tvb, scdr.change[j].qos_neg, offset+159+23*j, 3);*/
4308                                 }
4309                                 scdr.timestamp = tvb_get_ntohl(tvb, offset+254);
4310                                 scdr.opening = tvb_get_ntohl(tvb, offset+258);
4311                                 scdr.duration = tvb_get_ntohl(tvb, offset+262);
4312                                 scdr.sgsnchange = tvb_get_guint8(tvb, offset+266);
4313                                 scdr.closecause = tvb_get_guint8(tvb, offset+267);
4314                                 scdr.diag1 = tvb_get_guint8(tvb, offset+268);
4315                                 scdr.diag2 = tvb_get_guint8(tvb, offset+269);
4316                                 scdr.diag3 = tvb_get_guint8(tvb, offset+270);
4317                                 scdr.diag4 = tvb_get_guint8(tvb, offset+271);
4318                                 scdr.diag5 = tvb_get_ntohl(tvb, offset+272);
4319                                 scdr.seqno = tvb_get_ntohl(tvb, offset+276);
4320
4321                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "SCDR (type %x), sequence number: %u", rectype, scdr.seqno);
4322                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4323                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4324                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4325                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "CDR length: %u", scdr.len);
4326                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "Network initiated PDP context: %s", yesno[scdr.netini]);
4327                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 1, "Anonymous acces: %s", yesno[scdr.anon]);
4328                                 proto_tree_add_text(cdr_tree, tvb, offset+7, 1, "IMSI length: %u", scdr.imsilen);
4329                                 proto_tree_add_text(cdr_tree, tvb, offset+8, 8, "IMSI: %s", id_to_str(scdr.imsi));
4330                                 proto_tree_add_text(cdr_tree, tvb, offset+16, 8, "IMEI: %s", id_to_str(scdr.imei));
4331                                 proto_tree_add_text(cdr_tree, tvb, offset+24, 1, "MSISDN length: %u", scdr.msisdnlen);
4332                                 proto_tree_add_text(cdr_tree, tvb, offset+25, 10, "MSISDN: %s", msisdn_to_str(scdr.msisdn, 10));
4333                                 proto_tree_add_text(cdr_tree, tvb, offset+35, 4, "SGSN address: %s", ip_to_str((guint8 *)&scdr.sgsnaddr));
4334                                 proto_tree_add_text(cdr_tree, tvb, offset+39, 12, "(not used)");
4335                                 proto_tree_add_text(cdr_tree, tvb, offset+51, 1, "MS network capability length: %u", scdr.msclass_caplen);
4336                                 
4337 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+52, 1, "MS network capability: %u", scdr.msclass_cap);
4338                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4339                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+52, 1, scdr.cap);
4340                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+52, 1, scdr.cap);
4341                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+52, 1, scdr.cap);
4342                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+52, 1, scdr.cap);
4343                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+52, 1, scdr.cap);
4344                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+52, 1, scdr.cap);
4345                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_pad, tvb, offset+52, 1, scdr.cap);
4346 */
4347
4348                                 proto_tree_add_text(cdr_tree, tvb, offset+53, 2, "MS network capability omitted: %u", scdr.msclass_capomit);
4349                                 proto_tree_add_text(cdr_tree, tvb, offset+55, 2, "LAC: %u", scdr.lac);
4350                                 proto_tree_add_text(cdr_tree, tvb, offset+57, 1, "RAC: %u", scdr.rac);
4351                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 2, "Cell ID: %u", scdr.cid);
4352                                 proto_tree_add_text(cdr_tree, tvb, offset+60, 4, "Charging ID: %x", scdr.chrgid);
4353                                 proto_tree_add_text(cdr_tree, tvb, offset+64, 4, "GGSN address: %s", ip_to_str((guint8 *)&scdr.ggsnaddr));
4354                                 proto_tree_add_text(cdr_tree, tvb, offset+68, 64, "APN: %s", scdr.apn);
4355                                 proto_tree_add_text(cdr_tree, tvb, offset+132, 1, "PDP org: %s", val_to_str(scdr.pdporg, pdp_org_type, "Unknown PDP org"));
4356                                 proto_tree_add_text(cdr_tree, tvb, offset+133, 1, "PDP type: %s", val_to_str(scdr.pdptype, pdp_type, "Unknown PDP type"));
4357                                 proto_tree_add_text(cdr_tree, tvb, offset+134, 4, "PDP address: %s", ip_to_str((guint8 *)&scdr.pdpaddr));
4358                                 proto_tree_add_text(cdr_tree, tvb, offset+138, 1, "List of data volume index: %u", scdr.listind);
4359                                 for (j=0;j<4;j++) {
4360                                         proto_tree_add_text(cdr_tree, tvb, offset+139+23*j, 1, "List of data vol change condition: %u", scdr.change[j].change);
4361                                         proto_tree_add_text(cdr_tree, tvb, offset+140+23*j, 4, "Time1: %x", scdr.change[j].time1);
4362                                         proto_tree_add_text(cdr_tree, tvb, offset+144+23*j, 4, "Time2: %x", scdr.change[j].time2);
4363                                         proto_tree_add_text(cdr_tree, tvb, offset+148+23*j, 4, "Uplink: %x", scdr.change[j].uplink);
4364                                         proto_tree_add_text(cdr_tree, tvb, offset+152+23*j, 4, "Downlink: %x", scdr.change[j].downlink);
4365                                         decode_qos_gprs(tvb, offset+156, cdr_tree, "QoS requested", 0);
4366                                         decode_qos_gprs(tvb, offset+159, cdr_tree, "QoS negotiated", 0);
4367                                 }       
4368                                 proto_tree_add_text(cdr_tree, tvb, offset+254, 4, "Timestamp: %s", time_int_to_str(scdr.timestamp));
4369                                 proto_tree_add_text(cdr_tree, tvb, offset+258, 4, "Opening: %s", time_int_to_str(scdr.opening));
4370                                 proto_tree_add_text(cdr_tree, tvb, offset+262, 4, "Duration: %s", rel_time_int_to_str(scdr.duration));
4371                                 proto_tree_add_text(cdr_tree, tvb, offset+266, 1, "SGSN change: %u", scdr.sgsnchange);
4372                                 proto_tree_add_text(cdr_tree, tvb, offset+267, 1, "Cause for close: %s (%u)", val_to_str(scdr.closecause, cdr_close_type, "Unknown cause"), scdr.closecause);
4373                                 proto_tree_add_text(cdr_tree, tvb, offset+268, 1, "Diagnostics 1: %u", scdr.diag1);
4374                                 proto_tree_add_text(cdr_tree, tvb, offset+269, 1, "Diagnostics 2: %u", scdr.diag2);
4375                                 proto_tree_add_text(cdr_tree, tvb, offset+270, 1, "Diagnostics 3: %u", scdr.diag3);
4376                                 proto_tree_add_text(cdr_tree, tvb, offset+271, 1, "Diagnostics 4: %u", scdr.diag4);
4377                                 proto_tree_add_text(cdr_tree, tvb, offset+272, 4, "Diagnostics 5: %u", scdr.diag5);
4378                                 proto_tree_add_text(cdr_tree, tvb, offset+276, 4, "Sequence number: %u", scdr.seqno);
4379                                 break;
4380                         case 0x14:              /* MCDR */
4381                                 if (tvb_length_remaining(tvb, offset) < 3 + 147) {
4382                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "MCDR fragmented, can't dissect");
4383                                         break;
4384                                 }
4385
4386                                 mcdr.len = tvb_get_ntohs(tvb, offset+3);
4387                                 mcdr.imsilen = tvb_get_guint8(tvb, offset+5);
4388                                 tvb_memcpy(tvb, mcdr.imsi, offset+6, 8);
4389                                 tvb_memcpy(tvb, mcdr.imei, offset+14, 8);
4390                                 mcdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4391                                 tvb_memcpy(tvb, mcdr.msisdn, offset+23, 10);
4392                                 tvb_memcpy(tvb, (guint8 *)&mcdr.sgsnaddr, offset+33, sizeof mcdr.sgsnaddr);
4393                                 tvb_memcpy(tvb, mcdr.msclass_notused, offset+37, 12);
4394                                 mcdr.msclass_caplen = tvb_get_guint8(tvb, offset+49);
4395                                 mcdr.msclass_cap = tvb_get_guint8(tvb, offset+50);
4396                                 mcdr.msclass_capomit = tvb_get_ntohs(tvb, offset+51);
4397                                 mcdr.lac = tvb_get_ntohs(tvb, offset+53);
4398                                 mcdr.rac = tvb_get_guint8(tvb, offset+55);
4399                                 mcdr.cid = tvb_get_ntohs(tvb, offset+56);
4400                                 mcdr.change_count = tvb_get_guint8(tvb, offset+58);
4401                                 for (j=0;j<4;j++) {
4402                                         mcdr.change[j].lac = tvb_get_ntohs(tvb, offset+59+13*j);
4403                                         mcdr.change[j].rac = tvb_get_guint8(tvb, offset+61+13*j);
4404                                         mcdr.change[j].cid = tvb_get_ntohs(tvb, offset+62+13*j);
4405                                         tvb_memcpy(tvb, mcdr.change[j].omit, offset+64+13*j, 8);
4406                                 }
4407                                 mcdr.timestamp = tvb_get_ntohl(tvb, offset+124);
4408                                 mcdr.opening = tvb_get_ntohl(tvb, offset+128);
4409                                 mcdr.duration = tvb_get_ntohl(tvb, offset+132);
4410                                 mcdr.sgsnchange = tvb_get_guint8(tvb, offset+136);
4411                                 mcdr.closecause = tvb_get_guint8(tvb, offset+137);
4412                                 mcdr.diag1 = tvb_get_guint8(tvb, offset+138);
4413                                 mcdr.diag2 = tvb_get_guint8(tvb, offset+139);
4414                                 mcdr.diag3 = tvb_get_guint8(tvb, offset+140);
4415                                 mcdr.diag4 = tvb_get_guint8(tvb, offset+141);
4416                                 mcdr.diag5 = tvb_get_ntohl(tvb, offset+142);
4417                                 mcdr.seqno = tvb_get_ntohl(tvb, offset+146);
4418
4419                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "MCDR (0x14), sequence number: %u", mcdr.seqno);
4420                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4421                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4422                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4423                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", mcdr.len);
4424                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", mcdr.imsilen);
4425                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(mcdr.imsi));
4426                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(mcdr.imei));
4427                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", mcdr.msisdnlen);
4428                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(mcdr.msisdn, 10));
4429                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 4, "SGSN address: %s", ip_to_str((guint8 *)&mcdr.sgsnaddr));
4430                                 proto_tree_add_text(cdr_tree, tvb, offset+37, 12, "(not used)");
4431                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 1, "MS network capability length: %u", mcdr.msclass_caplen);
4432                                 
4433 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+50, 1, "MS network capability: %u", mcdr.msclass_cap);
4434                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4435                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+50, 1, mcdr.cap);
4436                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+50, 1, mcdr.cap);
4437                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+50, 1, mcdr.cap);
4438                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+50, 1, mcdr.cap);
4439                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+50, 1, mcdr.cap);
4440                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+50, 1, mcdr.cap);
4441                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_pad, tvb, offset+50, 1, mcdr.cap);
4442 */
4443                                 proto_tree_add_text(cdr_tree, tvb, offset+51, 2, "MS network capability omitted: %u", mcdr.msclass_capomit);
4444                                 proto_tree_add_text(cdr_tree, tvb, offset+53, 2, "LAC: %u", mcdr.lac);
4445                                 proto_tree_add_text(cdr_tree, tvb, offset+55, 1, "RAC: %u", mcdr.rac);
4446                                 proto_tree_add_text(cdr_tree, tvb, offset+56, 2, "Cell ID: %u", mcdr.cid);
4447                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 1, "List of data volume changes: %u", mcdr.change_count);
4448                                 for (j=0;j<4;j++) {
4449                                         proto_tree_add_text(cdr_tree, tvb, offset+59+13*j, 2, "LAC: %u", mcdr.change[j].lac);
4450                                         proto_tree_add_text(cdr_tree, tvb, offset+61+13*j, 1, "RAC: %u", mcdr.change[j].rac);
4451                                         proto_tree_add_text(cdr_tree, tvb, offset+62+13*j, 2, "CID: %u", mcdr.change[j].cid);
4452                                         proto_tree_add_text(cdr_tree, tvb, offset+64+13*j, 8, "(omitted)");
4453                                 }
4454
4455                                 proto_tree_add_text(cdr_tree, tvb, offset+124, 4, "Timestamp: %s", time_int_to_str(mcdr.timestamp));
4456                                 proto_tree_add_text(cdr_tree, tvb, offset+128, 4, "Record opening time: %s", time_int_to_str(mcdr.opening));
4457                                 proto_tree_add_text(cdr_tree, tvb, offset+132, 4, "Duration: %s", rel_time_int_to_str(mcdr.duration));
4458                                 proto_tree_add_text(cdr_tree, tvb, offset+136, 1, "SGSN change: %u", mcdr.sgsnchange);
4459                                 proto_tree_add_text(cdr_tree, tvb, offset+137, 1, "Cause for close: %s (%u)", val_to_str(mcdr.closecause, cdr_close_type, "Unknown cause"), mcdr.closecause);
4460                                 proto_tree_add_text(cdr_tree, tvb, offset+138, 1, "Diagnostics 1: %u", mcdr.diag1);
4461                                 proto_tree_add_text(cdr_tree, tvb, offset+139, 1, "Diagnostics 2: %u", mcdr.diag2);
4462                                 proto_tree_add_text(cdr_tree, tvb, offset+140, 1, "Diagnostics 3: %u", mcdr.diag3);
4463                                 proto_tree_add_text(cdr_tree, tvb, offset+141, 1, "Diagnostics 4: %u", mcdr.diag4);
4464                                 proto_tree_add_text(cdr_tree, tvb, offset+142, 4, "Diagnostics 5: %u", mcdr.diag5);
4465                                 proto_tree_add_text(cdr_tree, tvb, offset+146, 4, "Sequence number: %u", mcdr.seqno);
4466                                 break;
4467
4468                         case 0x15:              /* SOCDR */
4469                                 if (tvb_length_remaining(tvb, offset) < 3 + 80) {
4470                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "SOCDR fragmented, can't dissect");
4471                                         break;
4472                                 }
4473
4474                                 socdr.len = tvb_get_ntohs(tvb, offset+3);
4475                                 socdr.imsilen = tvb_get_guint8(tvb, offset+5);
4476                                 tvb_memcpy(tvb, socdr.imsi, offset+6, 8);
4477                                 tvb_memcpy(tvb, socdr.imei, offset+14, 8);
4478                                 socdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4479                                 tvb_memcpy(tvb, socdr.msisdn, offset+23, 10);
4480                                 tvb_memcpy(tvb, socdr.msclass_notused, offset+33, 12);
4481                                 socdr.msclass_caplen = tvb_get_guint8(tvb, offset+45);
4482                                 socdr.msclass_cap = tvb_get_guint8(tvb, offset+46);
4483                                 socdr.msclass_capomit = tvb_get_ntohs(tvb, offset+47);
4484                                 tvb_memcpy(tvb, socdr.serv_centr, offset+49, 9);
4485                                 tvb_memcpy(tvb, socdr.rec_ent, offset+58, 9);
4486                                 socdr.lac = tvb_get_ntohs(tvb, offset+67);
4487                                 socdr.rac = tvb_get_guint8(tvb, offset+69);
4488                                 socdr.cid = tvb_get_ntohs(tvb, offset+70);
4489                                 socdr.time1 = tvb_get_ntohl(tvb, offset+72);
4490                                 socdr.time2 = tvb_get_ntohl(tvb, offset+76);
4491                                 socdr.messref = tvb_get_guint8(tvb, offset+80);
4492                                 socdr.smsres = tvb_get_ntohs(tvb, offset+81);
4493
4494                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "SOCDR (0x15)");
4495                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4496                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4497                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4498                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", socdr.len);
4499                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", socdr.imsilen);
4500                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(socdr.imsi));
4501                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(socdr.imei));
4502                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", socdr.msisdnlen);
4503                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(socdr.msisdn, 10));
4504                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 12, "(not used)");
4505                                 proto_tree_add_text(cdr_tree, tvb, offset+45, 1, "MS network capability length: %u", socdr.msclass_caplen);
4506                                 
4507 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+46, 1, "MS network capability: %u", socdr.msclass_cap);
4508                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4509                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+46, 1, socdr.cap);
4510                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+46, 1, socdr.cap);
4511                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+46, 1, socdr.cap);
4512                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+46, 1, socdr.cap);
4513                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+46, 1, socdr.cap);
4514                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+46, 1, socdr.cap);
4515 */
4516                                 proto_tree_add_text(cdr_tree, tvb, offset+47, 2, "MS network capability omitted: %u", stcdr.msclass_capomit);
4517                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 9, "SMSC E.164 address: %s", msisdn_to_str(socdr.serv_centr, 9));
4518                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 9, "SGSN E.164 address: %s", msisdn_to_str(socdr.rec_ent, 9));
4519                                 proto_tree_add_text(cdr_tree, tvb, offset+67, 2, "LAC: %u", socdr.lac);
4520                                 proto_tree_add_text(cdr_tree, tvb, offset+69, 1, "RAC: %u", socdr.rac);
4521                                 proto_tree_add_text(cdr_tree, tvb, offset+70, 2, "Cell ID: %u", socdr.cid);
4522                                 proto_tree_add_text(cdr_tree, tvb, offset+72, 4, "Time1: %s", time_int_to_str(socdr.time1));
4523                                 proto_tree_add_text(cdr_tree, tvb, offset+76, 4, "Time2: %s", time_int_to_str(socdr.time2));
4524                                 proto_tree_add_text(cdr_tree, tvb, offset+80, 1, "Message reference: %u", socdr.messref);
4525                                 proto_tree_add_text(cdr_tree, tvb, offset+81, 2, "Delivery result: %u", socdr.smsres);
4526                                 break;
4527
4528                         case 0x16:              /* STCDR */
4529                                 if (tvb_length_remaining(tvb, offset) < 3 + 79) {
4530                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "STCDR fragmented, can't dissect");
4531                                         break;
4532                                 }
4533
4534                                 stcdr.len = tvb_get_ntohs(tvb, offset+3);
4535                                 stcdr.imsilen = tvb_get_guint8(tvb, offset+5);
4536                                 tvb_memcpy(tvb, stcdr.imsi, offset+6, 8);
4537                                 tvb_memcpy(tvb, stcdr.imei, offset+14, 8);
4538                                 stcdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4539                                 tvb_memcpy(tvb, stcdr.msisdn, offset+23, 10);
4540                                 tvb_memcpy(tvb, stcdr.msclass_notused, offset+33, 12);
4541                                 stcdr.msclass_caplen = tvb_get_guint8(tvb, offset+45);
4542                                 stcdr.msclass_cap = tvb_get_guint8(tvb, offset+46);
4543                                 stcdr.msclass_capomit = tvb_get_ntohs(tvb, offset+47);
4544                                 tvb_memcpy(tvb, stcdr.serv_centr, offset+49, 9);
4545                                 tvb_memcpy(tvb, stcdr.rec_ent, offset+58, 9);
4546                                 stcdr.lac = tvb_get_ntohs(tvb, offset+67);
4547                                 stcdr.rac = tvb_get_guint8(tvb, offset+69);
4548                                 stcdr.cid = tvb_get_ntohs(tvb, offset+70);
4549                                 stcdr.time1 = tvb_get_ntohl(tvb, offset+72);
4550                                 stcdr.time2 = tvb_get_ntohl(tvb, offset+76);
4551                                 stcdr.smsres = tvb_get_ntohs(tvb, offset+80);
4552
4553                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "STCDR (0x16)");
4554                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4555                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4556                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4557                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", stcdr.len);
4558                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", stcdr.imsilen);
4559                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(stcdr.imsi));
4560                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(stcdr.imei));
4561                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", stcdr.msisdnlen);
4562                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(stcdr.msisdn, 10));
4563                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 12, "(not used)");
4564                                 proto_tree_add_text(cdr_tree, tvb, offset+45, 1, "MS network capability length: %u", stcdr.msclass_caplen);
4565                                 
4566 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+46, 1, "MS network capability: %u", stcdr.msclass_cap);
4567                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4568                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+46, 1, stcdr.cap);
4569                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+46, 1, stcdr.cap);
4570                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+46, 1, stcdr.cap);
4571                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+46, 1, stcdr.cap);
4572                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+46, 1, stcdr.cap);
4573                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+46, 1, stcdr.cap);
4574 */
4575                                 proto_tree_add_text(cdr_tree, tvb, offset+47, 2, "MS network capability omitted: %u", stcdr.msclass_capomit);
4576                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 9, "SMSC E.164 address: %s", msisdn_to_str(stcdr.serv_centr, 9));
4577                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 9, "SGSN E.164 address: %s", msisdn_to_str(stcdr.rec_ent, 9));
4578                                 proto_tree_add_text(cdr_tree, tvb, offset+67, 2, "LAC: %u", stcdr.lac);
4579                                 proto_tree_add_text(cdr_tree, tvb, offset+69, 1, "RAC: %u", stcdr.rac);
4580                                 proto_tree_add_text(cdr_tree, tvb, offset+70, 2, "Cell ID: %u", stcdr.cid);
4581                                 proto_tree_add_text(cdr_tree, tvb, offset+72, 4, "Time1: %s", time_int_to_str(stcdr.time1));
4582                                 proto_tree_add_text(cdr_tree, tvb, offset+76, 4, "Time2: %s", time_int_to_str(stcdr.time2));
4583                                 proto_tree_add_text(cdr_tree, tvb, offset+80, 2, "Delivery result: %u", stcdr.smsres);
4584                                 break;
4585                 }
4586                 offset = offset + 2 + data_len;
4587         }
4588         }
4589         return 3+length;
4590 }
4591
4592 /* GPRS:        12.15
4593  * UMTS:        33.015
4594  */
4595 static int
4596 decode_gtp_data_resp(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4597         
4598         guint16         length, n, number;
4599         proto_tree      *ext_tree_data_resp;
4600         proto_item      *te;
4601
4602         length = tvb_get_ntohs(tvb, offset + 1);
4603         
4604         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Requests responded");
4605         ext_tree_data_resp = proto_item_add_subtree(te, ett_gtp_data_resp);
4606         
4607         n = 0;
4608         
4609         while (n < length) {
4610
4611                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4612                 proto_tree_add_text(ext_tree_data_resp, tvb, offset + 3 + n, 2, "%u", number);
4613                 n = n + 2;
4614
4615         }
4616
4617         return 3 + length;
4618
4619 }
4620         
4621 /* GPRS:        12.15
4622  * UMTS:        33.015
4623  */
4624 static int
4625 decode_gtp_node_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4626                 
4627         guint16         length; 
4628         guint32         addr_ipv4;
4629         struct  e_in6_addr addr_ipv6;
4630         proto_tree      *ext_tree_node_addr;
4631         proto_item      *te;
4632         
4633         length = tvb_get_ntohs(tvb, offset+1);
4634         
4635         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Node address: ");
4636         ext_tree_node_addr = proto_item_add_subtree(te, ett_gtp_node_addr);
4637         
4638         proto_tree_add_text(ext_tree_node_addr, tvb, offset+1, 2, "Node address length: %u", length);
4639         
4640         switch (length) {
4641                 case 4:
4642                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
4643                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4644                         proto_tree_add_ipv4(ext_tree_node_addr, gtp_version ? hf_gtpv1_node_ipv4 : hf_gtpv0_node_ipv4, tvb, offset+3, 4, addr_ipv4);
4645                         break;
4646                 case 16: 
4647                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
4648                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4649                         proto_tree_add_ipv6(ext_tree_node_addr, gtp_version ? hf_gtpv1_node_ipv6 : hf_gtpv0_node_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
4650                         break;
4651                 default:
4652                         proto_item_append_text(te, "unknown type or wrong length");
4653                         break;
4654         }
4655
4656         return 3 + length;
4657
4658 }
4659
4660 /* GPRS:        9.60 v7.6.0, chapter 7.9.26
4661  * UMTS:        29.060 v4.0, chapter 7.7.44
4662  */
4663 static int
4664 decode_gtp_priv_ext(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {  
4665                 
4666         guint16         length, ext_id; 
4667         gchar           ext_val[64];
4668         proto_tree      *ext_tree_priv_ext;
4669         proto_item      *te;
4670         
4671         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_PRIV_EXT, gtp_val, "Unknown message"));
4672         ext_tree_priv_ext = proto_item_add_subtree(te, ett_gtp_ext);
4673         
4674         length = tvb_get_ntohs(tvb, offset+1);
4675         if (length < 1) return 3+length;
4676         
4677         ext_id = tvb_get_ntohs(tvb, offset+3);  
4678         tvb_memcpy(tvb, ext_val, offset+5, length > 65 ? 63 : length-2);
4679         ext_val[length > 65 ? 64 : length-1] = '\0';
4680         proto_tree_add_uint(ext_tree_priv_ext, gtp_version ? hf_gtpv1_ext_id : hf_gtpv0_ext_id, tvb, offset+3, 2, ext_id);
4681         proto_tree_add_string(ext_tree_priv_ext, gtp_version ? hf_gtpv1_ext_val : hf_gtpv0_ext_val, tvb, offset+5, length-2, ext_val);
4682         
4683         return 3+length;
4684 }
4685
4686 static int
4687 decode_gtp_unknown(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4688
4689         proto_tree_add_text(tree, tvb, offset, 1, "Unknown extension header");
4690
4691         return tvb_length_remaining(tvb, offset);
4692 }
4693
4694 static void
4695 dissect_gtpv0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4696 {
4697         
4698         _gtpv0_hdr      gtpv0_hdr;
4699         proto_item      *ti, *tf;
4700         proto_tree      *gtpv0_tree, *flags_tree;
4701         guint8          ext_hdr_val;
4702         tvbuff_t        *next_tvb;
4703         const guint8    *tid_val;
4704         gchar           *tid_str;
4705         int             offset, length, i, mandatory, checked_field;
4706         
4707         if (check_col(pinfo->cinfo, COL_PROTOCOL))
4708                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP");
4709         if (check_col(pinfo->cinfo, COL_INFO))
4710                 col_clear(pinfo->cinfo, COL_INFO);
4711
4712         tvb_memcpy(tvb, (guint8 *)&gtpv0_hdr, 0, 12); 
4713         tid_val = tvb_get_ptr(tvb, 12, 8);
4714         tid_str = id_to_str(tid_val);
4715         gtp_version = (gtpv0_hdr.flags >> 5) & 0x07;
4716
4717         if (!((gtpv0_hdr.flags >> 4) & 1)) {
4718                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
4719                         col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP-CDR");
4720         } else {
4721                 switch ((gtpv0_hdr.flags >> 5) & 0x07) {
4722                 case 0: if (check_col(pinfo->cinfo, COL_PROTOCOL))
4723                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP");
4724                         break;
4725                 case 1: if (check_col(pinfo->cinfo, COL_PROTOCOL))
4726                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTPv1");
4727                 default: if (check_col(pinfo->cinfo, COL_PROTOCOL))
4728                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTPv?");
4729                         break;
4730                 }
4731         }
4732
4733         if (check_col(pinfo->cinfo, COL_INFO))
4734                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(gtpv0_hdr.message, message_type, "Unknown"));
4735         
4736         if (tree) {
4737                         
4738                 /* dissect GTP header */
4739                 ti = proto_tree_add_item(tree, proto_gtpv0, tvb, 0, -1, FALSE);
4740                 gtpv0_tree = proto_item_add_subtree(ti, ett_gtp);
4741
4742                 tf = proto_tree_add_uint(gtpv0_tree, hf_gtpv0_flags, tvb, 0, 1, gtpv0_hdr.flags);
4743
4744                 flags_tree = proto_item_add_subtree(tf, ett_gtp_flags);
4745                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_ver, tvb, 0, 1, gtpv0_hdr.flags);
4746                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_pt, tvb, 0, 1, gtpv0_hdr.flags);
4747                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_spare, tvb, 0, 1, gtpv0_hdr.flags);
4748                 proto_tree_add_boolean(flags_tree, hf_gtpv0_flags_snn, tvb, 0, 1, gtpv0_hdr.flags);
4749                 
4750                 gtpv0_hdr.length = ntohs(gtpv0_hdr.length);
4751                 gtpv0_hdr.seq_no = ntohs(gtpv0_hdr.seq_no);
4752                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_message_type, tvb, 1, 1, gtpv0_hdr.message);
4753                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_length, tvb, 2, 2, gtpv0_hdr.length);
4754                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_seq_number, tvb, 4, 2, gtpv0_hdr.seq_no);
4755                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_flow_label, tvb, 6, 2, gtpv0_hdr.flow_label);
4756                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_sndcp_number, tvb, 8, 1, gtpv0_hdr.sndcp_no);
4757                 proto_tree_add_string(gtpv0_tree, hf_gtpv0_tid, tvb, 12, 8, tid_str);
4758         
4759                 if (gtpv0_hdr.message != GTP_MSG_TPDU) {
4760                                 
4761                         proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[--- end of GTPv0 header, beginning of extension headers ---]");
4762                                         
4763                         offset = GTPv0_HDR_LENGTH;
4764                         length = tvb_length(tvb);
4765
4766                         mandatory = 0;          /* check order of GTP fields against ETSI */
4767                 
4768                         for (;;) {
4769                                         
4770                                 if (offset >= length) break;
4771                                 ext_hdr_val = tvb_get_guint8(tvb, offset);
4772                                 
4773                                 if (gtpv0_etsi_order) {
4774                                         checked_field = check_field_presence (gtpv0_hdr.message, ext_hdr_val , (int *)&mandatory);
4775                                         switch (checked_field) {
4776                                                 case -2: proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[WARNING] message not found");
4777                                                          break;
4778                                                 case -1: proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[WARNING] field not present");
4779                                                          break;
4780                                                 case 0:  break;
4781                                                 default: proto_tree_add_text(gtpv0_tree, tvb, offset, 1, "[WARNING] wrong next field, should be: %s", val_to_str(checked_field, gtp_val, "Unknown extension field"));
4782                                         }
4783                                 }
4784                                 
4785                                 i = -1;
4786                                 while (gtpopt[++i].optcode) if (gtpopt[i].optcode == ext_hdr_val) break;
4787                                 offset = offset + (*gtpopt[i].decode)(tvb, offset, pinfo, gtpv0_tree);
4788                         }
4789                 }
4790         } 
4791
4792 /* next part dissects sublayers of GTP
4793  * right now it's only IP */
4794         
4795         if ((gtpv0_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
4796                 next_tvb = tvb_new_subset(tvb, 20, -1, -1);
4797                 call_dissector(ip_handle, next_tvb, pinfo, tree);
4798                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
4799                         col_append_str_gtp(pinfo->cinfo, COL_PROTOCOL, "GTP");
4800         }
4801         
4802 }
4803
4804 /* GTP v1 dissector */
4805 static void
4806 dissect_gtpv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
4807         
4808         _gtpv1_hdr      gtpv1_hdr;
4809         proto_item      *ti, *tf;
4810         proto_tree      *gtpv1_tree, *flags_tree;
4811         guint16         seq_no;
4812         guint8          ext_hdr_val, i, hdr_offset = 4, next_hdr, npdu_no, probe;
4813         tvbuff_t        *next_tvb;
4814         int             offset, length, mandatory, checked_field;
4815         
4816         if (check_col(pinfo->cinfo, COL_PROTOCOL))
4817                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP-C");
4818         if (check_col(pinfo->cinfo, COL_INFO))
4819                 col_clear(pinfo->cinfo, COL_INFO);
4820
4821         tvb_memcpy(tvb, (guint8 *)&gtpv1_hdr, 0, 8);
4822         gtp_version = (gtpv1_hdr.flags >> 5) & 0x07;
4823
4824         if (check_col(pinfo->cinfo, COL_INFO))
4825                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(gtpv1_hdr.message, message_type, "Unknown"));
4826
4827         if (tree) {
4828                         
4829                 ti = proto_tree_add_item(tree, proto_gtpv1, tvb, 0, -1, FALSE);
4830                 gtpv1_tree = proto_item_add_subtree(ti, ett_gtp);
4831
4832                 tf = proto_tree_add_uint(gtpv1_tree, hf_gtpv1_flags, tvb, 0, 1, gtpv1_hdr.flags);
4833                 flags_tree = proto_item_add_subtree(tf, ett_gtp_flags);
4834                 
4835                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_ver, tvb, 0, 1, gtpv1_hdr.flags);
4836                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_pt, tvb, 0, 1, gtpv1_hdr.flags);
4837                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_spare, tvb, 0, 1, gtpv1_hdr.flags);
4838                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_e, tvb, 0, 1, gtpv1_hdr.flags);
4839                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_s, tvb, 0, 1, gtpv1_hdr.flags);
4840                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_pn, tvb, 0, 1, gtpv1_hdr.flags);
4841                 
4842                 gtpv1_hdr.length = ntohs(gtpv1_hdr.length);
4843                 gtpv1_hdr.teid = ntohl(gtpv1_hdr.teid);
4844                 
4845                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_message_type, tvb, 1, 1, gtpv1_hdr.message);
4846                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_length, tvb, 2, 2, gtpv1_hdr.length);
4847                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_teid, tvb, 4, 4, gtpv1_hdr.teid);
4848
4849                 if (gtpv1_hdr.flags & 0x07) {
4850                         seq_no = tvb_get_ntohs (tvb, 8);
4851                         proto_tree_add_uint (gtpv1_tree, hf_gtpv1_seq_number, tvb, 8, 2, seq_no);
4852                         npdu_no = tvb_get_guint8 (tvb, 10);
4853                         proto_tree_add_uint (gtpv1_tree, hf_gtpv1_npdu_number, tvb, 10, 1, npdu_no);
4854                         next_hdr = tvb_get_guint8(tvb, 11);
4855                         proto_tree_add_uint(gtpv1_tree, hf_gtpv1_next, tvb, 11, 1, next_hdr);
4856                         hdr_offset = 0;
4857                         
4858                         if (next_hdr) hdr_offset = 1;
4859                         else hdr_offset = 0;
4860                 }
4861         
4862                 if (gtpv1_hdr.message != GTP_MSG_TPDU) {
4863
4864                         proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[--- end of GTP v1 header, beginning of extension headers ---]");
4865                                 
4866                         offset = GTPv1_HDR_LENGTH - hdr_offset;
4867                         length = tvb_length(tvb);
4868                 
4869                         mandatory = 0;          /* check order of GTP fields against ETSI */
4870                 
4871                         for (;;) {
4872                                         
4873                                 if (offset >= length) break;
4874                                 ext_hdr_val = tvb_get_guint8(tvb, offset);
4875                                 
4876                                 if (gtpv1_etsi_order) {
4877                                         checked_field = check_field_presence (gtpv1_hdr.message, ext_hdr_val , (int *)&mandatory);
4878                                         switch (checked_field) {
4879                                                 case -2: proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[WARNING] message not found");
4880                                                          break;
4881                                                 case -1: proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[WARNING] field not present");
4882                                                          break;
4883                                                 case 0:  break;
4884                                                 default: proto_tree_add_text(gtpv1_tree, tvb, offset, 1, "[WARNING] wrong next field, should be: %s", val_to_str(checked_field, gtp_val, "Unknown extension field"));
4885                                         }
4886                                 }
4887                                 
4888                                 i = -1;
4889                                 while (gtpopt[++i].optcode) if (gtpopt[i].optcode == ext_hdr_val) break;
4890                                 offset = offset + (*gtpopt[i].decode)(tvb, offset, pinfo, gtpv1_tree);
4891                         }
4892                 } 
4893         }
4894
4895         if (gtpv1_hdr.message == GTP_MSG_ERR_IND)
4896                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
4897                         col_add_str(pinfo->cinfo, COL_PROTOCOL, "GTP-U");
4898
4899
4900         if ((gtpv1_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
4901         
4902                 if (gtpv1_hdr.flags & 0x07) {   
4903                         if (tvb_get_guint8 (tvb, 11)) hdr_offset = 1;           /* if next_hdr != 0 */
4904                         else hdr_offset = 0;
4905                 }
4906                 
4907                 next_tvb = tvb_new_subset(tvb, GTPv1_HDR_LENGTH - hdr_offset, -1, -1);
4908                 call_dissector(ip_handle, next_tvb, pinfo, tree);
4909                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
4910                         col_append_str_gtp(pinfo->cinfo, COL_PROTOCOL, "GTP-U");
4911         }
4912 }
4913
4914 static const true_false_string yes_no_tfs = { 
4915         "yes" ,
4916         "no"
4917 };
4918
4919 void
4920 proto_register_gtp(void)
4921 {                 
4922
4923         static hf_register_info hf_gtpv0[] = {
4924
4925         { &hf_gtpv0_flags,              { "Flags",              "gtpv0.flags",                  FT_UINT8,       BASE_HEX, NULL, 0, "Ver/PT/Spare/SNN", HFILL }},
4926         { &hf_gtpv0_flags_ver,          { "Version",            "gtpv0.flags.version",          FT_UINT8,       BASE_DEC, VALS(ver_types), GTP_VER_MASK, "GTP Version", HFILL }},
4927         { &hf_gtpv0_flags_pt,           { "Protocol type",      "gtpv0.flags.payload",          FT_UINT8,       BASE_DEC, NULL, GTP_PT_MASK, "Protocol Type (1 = GTP, 0 = GTP' )", HFILL }},
4928         { &hf_gtpv0_flags_spare,                { "Reserved",           "gtpv0.flags.reserved",         FT_UINT8,       BASE_DEC, NULL, GTP_SPARE_MASK, "Reserved (shall be sent as '111' )", HFILL }},
4929         { &hf_gtpv0_flags_snn,          { "Is SNDCP N-PDU included?", "gtpv0.flags.snn",        FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTP_SNN_MASK, "Is SNDCP N-PDU LLC Number included? (1 = yes, 0 = no)", HFILL }},
4930         { &hf_gtpv0_message_type,               { "Message type",       "gtpv0.message",                FT_UINT8,       BASE_HEX, VALS(message_type), 0x0, "GTP Message Type", HFILL }},
4931         { &hf_gtpv0_length,             { "Length",             "gtpv0.length",                 FT_UINT16,      BASE_DEC, NULL, 0, "Length (i.e. number of octets after TID or TEID)", HFILL }},
4932         { &hf_gtpv0_seq_number,         { "Sequence number",    "gtpv0.seq_number",             FT_UINT16,      BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
4933         { &hf_gtpv0_flow_label,         { "Flow label",         "gtpv0.flow_label",             FT_UINT16,      BASE_HEX, NULL, 0, "Flow label", HFILL }},
4934         { &hf_gtpv0_sndcp_number,               { "SNDCP N-PDU LLC Number", "gtpv0.sndcp_number",               FT_UINT8,       BASE_HEX, NULL, 0, "SNDCP N-PDU LLC Number", HFILL }},
4935         { &hf_gtpv0_tid,                        { "TID",                "gtpv0.tid",                    FT_STRING,      BASE_DEC, NULL, 0, "Tunnel Identifier", HFILL }},
4936         { &hf_gtpv0_cause,              { "Cause",              "gtpv0.cause",                  FT_UINT8,       BASE_DEC, VALS(cause_type), 0, "Cause of operation", HFILL }},
4937         { &hf_gtpv0_imsi,                       { "IMSI",               "gtpv0.imsi",                   FT_STRING,      BASE_DEC, NULL, 0, "International Mobile Subscriber Identity number", HFILL }},
4938         { &hf_gtpv0_rai_mcc,            { "MCC",                "gtpv0.mcc",                    FT_UINT16,      BASE_DEC, NULL, 0, "Mobile Country Code", HFILL }},
4939         { &hf_gtpv0_rai_mnc,            { "MNC",                "gtpv0.mnc",                    FT_UINT8,       BASE_DEC, NULL, 0, "Mobile Network Code", HFILL }},
4940         { &hf_gtpv0_rai_rac,            { "RAC",                "gtpv0.rac",                    FT_UINT8,       BASE_DEC, NULL, 0, "Routing Area Code", HFILL }},
4941         { &hf_gtpv0_rai_lac,            { "LAC",                "gtpv0.lac",                    FT_UINT16,      BASE_DEC, NULL, 0, "Location Area Code", HFILL }},
4942         { &hf_gtpv0_tlli,                       { "TLLI",               "gtpv0.tlli",                   FT_UINT32,      BASE_HEX, NULL, 0, "Temporary Logical Link Identity", HFILL }},
4943         { &hf_gtpv0_ptmsi,              { "P-TMSI",             "gtpv0.ptmsi",                  FT_UINT32,      BASE_HEX, NULL, 0, "Packet-Temporary Mobile Subscriber Identity", HFILL }},
4944         { &hf_gtpv0_qos_spare1,         { "Spare",              "gtpv0.qos_spare1",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE1_MASK, "Spare (shall be sent as '00' )", HFILL }},
4945         { &hf_gtpv0_qos_delay,          { "QoS delay",          "gtpv0.qos_delay",              FT_UINT8,       BASE_DEC, VALS(qos_delay_type), GTP_EXT_QOS_DELAY_MASK, "Quality of Service Delay Class", HFILL }},
4946         { &hf_gtpv0_qos_reliability,    { "QoS reliability",    "gtpv0.qos_reliabilty",         FT_UINT8,       BASE_DEC, VALS(qos_reliability_type), GTP_EXT_QOS_RELIABILITY_MASK, "Quality of Service Reliability Class", HFILL }},
4947         { &hf_gtpv0_qos_peak,           { "QoS peak",           "gtpv0.qos_peak",               FT_UINT8,       BASE_DEC, VALS(qos_peak_type), GTP_EXT_QOS_PEAK_MASK, "Quality of Service Peak Throughput", HFILL }},
4948         { &hf_gtpv0_qos_spare2,         { "Spare",              "gtpv0.qos_spare2",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE2_MASK, "Spare (shall be sent as 0)", HFILL }},
4949         { &hf_gtpv0_qos_precedence,     { "QoS precedence",     "gtpv0.qos_precedence",         FT_UINT8,       BASE_DEC, VALS(qos_precedence_type), GTP_EXT_QOS_PRECEDENCE_MASK, "Quality of Service Precedence Class", HFILL }},
4950         { &hf_gtpv0_qos_spare3,         { "Spare",              "gtpv0.qos_spare3",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE3_MASK, "Spare (shall be sent as '000' )", HFILL }},
4951         { &hf_gtpv0_qos_mean,           { "QoS mean",           "gtpv0.qos_mean",               FT_UINT8,       BASE_DEC, VALS(qos_mean_type), GTP_EXT_QOS_MEAN_MASK, "Quality of Service Mean Throughput", HFILL }},
4952         { &hf_gtpv0_reorder,            { "Reordering required","gtpv0.reorder",                FT_BOOLEAN,     BASE_NONE,NULL, 0, "Reordering required", HFILL }},
4953         { &hf_gtpv0_map_cause,          { "MAP cause",          "gtpv0.map_cause",              FT_UINT8,       BASE_DEC, VALS(map_cause_type), 0, "MAP cause", HFILL }},
4954         { &hf_gtpv0_ptmsi_sig,          { "P-TMSI signature",   "gtpv0.ptmsi_sig",              FT_UINT24,      BASE_HEX, NULL, 0, "P-TMSI Signature", HFILL }},
4955         { &hf_gtpv0_ms_valid,           { "MS validated",       "gtpv0.ms_valid",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "MS validated", HFILL }},
4956         { &hf_gtpv0_recovery,           { "Recovery",           "gtpv0.recovery",               FT_UINT8,       BASE_DEC, NULL, 0, "Restart counter", HFILL }},
4957         { &hf_gtpv0_sel_mode,           { "Selection mode",     "gtpv0.sel_mode",               FT_UINT8,       BASE_DEC, VALS(sel_mode_type), 0, "Selection Mode", HFILL }},
4958         { &hf_gtpv0_ext_flow_label,     { "Flow Label Data I",  "gtpv0.ext_flow_label",         FT_UINT16,      BASE_DEC, NULL, 0, "Flow label data", HFILL }},
4959         { &hf_gtpv0_flow_sig,           { "Flow label Signalling",      "gtpv0.flow_sig",       FT_UINT16,      BASE_DEC, NULL, 0, "Flow label signalling", HFILL }},
4960         { &hf_gtpv0_nsapi,              { "NSAPI ",             "gtpv0.nsapi",                  FT_UINT8,       BASE_DEC, NULL, 0, "Network layer Service Access Point Identifier", HFILL }},
4961         { &hf_gtpv0_flow_ii,            { "Flow Label Data II ","gtpv0.flow_ii",                FT_UINT16,      BASE_DEC, NULL, 0, "Downlink flow label data", HFILL }},
4962         { &hf_gtpv0_ms_reason,          { "MS not reachable reason",    "gtpv0.ms_reason",      FT_UINT8,       BASE_DEC, VALS(ms_not_reachable_type), 0, "MS Not Reachable Reason", HFILL }},
4963         { &hf_gtpv0_tr_comm,            { "Packet transfer command",    "gtpv0.tr_comm",        FT_UINT8,       BASE_DEC, VALS(tr_comm_type), 0, "Packat transfer command", HFILL }},
4964         { &hf_gtpv0_chrg_id,            { "Charging ID ",       "gtpv0.chrg_id",                FT_UINT32,      BASE_HEX, NULL, 0, "Charging ID", HFILL }},
4965         { &hf_gtpv0_user_ipv4,          { "End user address IPv4",      "gtpv0.user_ipv4",      FT_IPv4,        BASE_DEC, NULL, 0, "End user address IPv4", HFILL }},
4966         { &hf_gtpv0_user_ipv6,          { "End user address IPv6",      "gtpv0.user_ipv6",      FT_IPv6,        BASE_HEX, NULL, 0, "End user address IPv6", HFILL }},
4967         { &hf_gtpv0_user_addr_pdp_org,  { "PDP type organization",      "gtpv0.user_addr_pdp_org",      FT_UINT8,       BASE_DEC, VALS(pdp_org_type), 0, "PDP type organization", HFILL }},
4968         { &hf_gtpv0_user_addr_pdp_type, { "PDP type number",    "gtpv0.user_addr_pdp_type",     FT_UINT8,       BASE_HEX, VALS(pdp_type), 0, "PDP type", HFILL }},
4969         { &hf_gtpv0_apn,                        { "APN",                "gtpv0.apn",                    FT_STRING,      BASE_DEC, NULL, 0, "Access Point Name", HFILL }},
4970         { &hf_gtpv0_gsn_addr_type,      { "GSN address type",   "gtpv0.gsn_addr_type",          FT_UINT8,       BASE_DEC, VALS(gsn_addr_type), GTP_EXT_GSN_ADDR_TYPE_MASK, "GSN Address Type", HFILL }},
4971         { &hf_gtpv0_gsn_addr_len,               { "GSN address length", "gtpv0.gsn_addr_len",           FT_UINT8,       BASE_DEC, NULL, GTP_EXT_GSN_ADDR_LEN_MASK, "GSN Address Length", HFILL }},
4972         { &hf_gtpv0_gsn_ipv4,           { "GSN address IPv4",   "gtpv0.gsn_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "GSN address IPv4", HFILL }},
4973         { &hf_gtpv0_gsn_ipv6,           { "GSN address IPv6",   "gtpv0.gsn_ipv6",               FT_IPv6,        BASE_DEC, NULL, 0, "GSN address IPv6", HFILL }},
4974         { &hf_gtpv0_msisdn,             { "MSISDN",             "gtpv0.msisdn",                 FT_STRING,      BASE_DEC, NULL, 0, "MS international PSTN/ISDN number", HFILL }},
4975         { &hf_gtpv0_chrg_ipv4,          { "CG address IPv4",    "gtpv0.chrg_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Charging Gateway address IPv4", HFILL }},
4976         { &hf_gtpv0_chrg_ipv6,          { "CG address IPv6",    "gtpv0.chrg_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Charging Gateway address IPv6", HFILL }},
4977         { &hf_gtpv0_node_ipv4,          { "Node address IPv4",  "gtpv0.node_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Recommended node address IPv4", HFILL }},
4978         { &hf_gtpv0_node_ipv6,          { "Node address IPv6",  "gtpv0.node_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Recommended node address IPv6", HFILL }},
4979         { &hf_gtpv0_ext_id,             { "Extension identifier",       "gtpv0.ext_id",         FT_UINT16,      BASE_DEC, NULL, 0, "Extension Identifier", HFILL }},
4980         { &hf_gtpv0_ext_val,            { "Extension value",            "gtpv0.ext_val",        FT_STRING,      BASE_DEC, NULL, 0, "Extension Value", HFILL }},
4981         { &hf_gtpv0_unknown,            { "Unknown data (length)",      "gtpv0.unknown",        FT_UINT16,      BASE_DEC, NULL, 0, "Unknown data", HFILL }},
4982
4983         };
4984
4985         
4986         static hf_register_info hf_gtpv1[] = {
4987
4988         { &hf_gtpv1_flags,              { "Flags",              "gtpv1.flags",                  FT_UINT8,       BASE_HEX, NULL, 0, "Ver/PT/Spare/E/S/PN", HFILL }},
4989         { &hf_gtpv1_flags_ver,          { "Version",            "gtpv1.flags.version",          FT_UINT8,       BASE_DEC, VALS(ver_types), GTP_VER_MASK, "GTP Version", HFILL }},
4990         { &hf_gtpv1_flags_pt,           { "Protocol type",      "gtpv1.flags.payload_type",     FT_UINT8,       BASE_DEC, NULL, GTP_PT_MASK, "Protocol Type (1 = GTP, 0 = GPRS charging protocol : GTP' )", HFILL }},
4991         { &hf_gtpv1_flags_spare,                { "Spare bit",          "gtpv1.flags.spare",            FT_UINT8,       BASE_DEC, NULL, GTPv1_SPARE_MASK, "Spare bit (shall be sent as 0)", HFILL }},
4992         { &hf_gtpv1_flags_e,            { "Is Next Extension Header present?",  "gtpv1.flags.e",                FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTPv1_E_MASK, "Is Next Extension Header present? (1 = yes, 0 = no)", HFILL }},
4993         { &hf_gtpv1_flags_s,            { "Is Sequence Number present?",        "gtpv1.flags.s",                FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTPv1_S_MASK, "Is Sequence Number present? (1 = yes, 0 = no)", HFILL }},
4994         { &hf_gtpv1_flags_pn,           { "Is N-PDU number present?",   "gtpv1.flags.pn",               FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTPv1_PN_MASK, "Is N-PDU number present? (1 = yes, 0 = no)", HFILL }},
4995         { &hf_gtpv1_message_type,               { "Message Type",       "gtpv1.message",                FT_UINT8,       BASE_HEX, VALS(message_type), 0x0, "GTP Message Type", HFILL }},
4996         { &hf_gtpv1_length,             { "Length",             "gtpv1.length",                 FT_UINT16,      BASE_DEC, NULL, 0, "Length (i.e. number of octets after TID or TEID)", HFILL }},
4997         { &hf_gtpv1_seq_number,         { "Sequence Number",    "gtpv1.seq_number",             FT_UINT16,      BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
4998         { &hf_gtpv1_teid,                       { "TEID",               "gtpv1.teid",                   FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier", HFILL }},
4999         { &hf_gtpv1_npdu_number,                { "N-PDU Number",       "gtpv1.npdu_number",            FT_UINT8,       BASE_HEX, NULL, 0, "N-PDU Number", HFILL }},
5000         { &hf_gtpv1_next,                       { "Next extension header type", "gtpv1.next",           FT_UINT8,       BASE_HEX, NULL, 0, "Next Extension Header Type", HFILL }},
5001         { &hf_gtpv1_cause,              { "Cause ",             "gtpv1.cause",                  FT_UINT8,       BASE_DEC, VALS(cause_type), 0, "Cause of operation", HFILL }},
5002         { &hf_gtpv1_imsi,                       { "IMSI",               "gtpv1.imsi",                   FT_STRING,      BASE_DEC, NULL, 0, "International Mobile Subscriber Identity number", HFILL }},
5003         { &hf_gtpv1_rai_mcc,            { "MCC",                "gtpv1.mcc",                    FT_UINT16,      BASE_DEC, NULL, 0, "Mobile Country Code", HFILL }},
5004         { &hf_gtpv1_rai_mnc,            { "MNC",                "gtpv1.mnc",                    FT_UINT8,       BASE_DEC, NULL, 0, "Mobile Network Code", HFILL }},
5005         { &hf_gtpv1_rai_rac,            { "RAC",                "gtpv1.rac",                    FT_UINT8,       BASE_DEC, NULL, 0, "Routing Area Code", HFILL }},
5006         { &hf_gtpv1_rai_lac,            { "LAC",                "gtpv1.lac",                    FT_UINT16,      BASE_DEC, NULL, 0, "Location Area Code", HFILL }},
5007         { &hf_gtpv1_tlli,                       { "TLLI",               "gtpv1.tlli",                   FT_UINT32,      BASE_HEX, NULL, 0, "Temporary Logical Link Identity", HFILL }},
5008         { &hf_gtpv1_ptmsi,              { "P-TMSI",             "gtpv1.ptmsi",                  FT_UINT32,      BASE_HEX, NULL, 0, "Packet-Temporary Mobile Subscriber Identity", HFILL }},
5009         { &hf_gtpv1_qos_spare1,         { "Spare",              "gtpv1.qos_spare1",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE1_MASK, "Spare (shall be sent as '00' )", HFILL }},
5010         { &hf_gtpv1_qos_delay,          { "QoS Delay",          "gtpv1.qos_delay",              FT_UINT8,       BASE_DEC, VALS(qos_delay_type), GTP_EXT_QOS_DELAY_MASK, "Quality of Service Delay Class", HFILL }},
5011         { &hf_gtpv1_qos_reliability,    { "QoS Reliability",    "gtpv1.qos_reliabilty",         FT_UINT8,       BASE_DEC, VALS(qos_reliability_type), GTP_EXT_QOS_RELIABILITY_MASK, "Quality of Service Reliability Class", HFILL }},
5012         { &hf_gtpv1_qos_peak,           { "QoS Peak",           "gtpv1.qos_peak",               FT_UINT8,       BASE_DEC, VALS(qos_peak_type), GTP_EXT_QOS_PEAK_MASK, "Quality of Service Peak Throughput", HFILL }},
5013         { &hf_gtpv1_qos_spare2,         { "Spare",              "gtpv1.qos_spare2",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE2_MASK, "Spare (shall be sent as 0)", HFILL }},
5014         { &hf_gtpv1_qos_precedence,     { "QoS Precedence",     "gtpv1.qos_precedence",         FT_UINT8,       BASE_DEC, VALS(qos_precedence_type), GTP_EXT_QOS_PRECEDENCE_MASK, "Quality of Service Precedence Class", HFILL }},
5015         { &hf_gtpv1_qos_spare3,         { "Spare",              "gtpv1.qos_spare3",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE3_MASK, "Spare (shall be sent as '000' )", HFILL }},
5016         { &hf_gtpv1_qos_mean,           { "QoS Mean",           "gtpv1.qos_mean",               FT_UINT8,       BASE_DEC, VALS(qos_mean_type), GTP_EXT_QOS_MEAN_MASK, "Quality of Service Mean Throughput", HFILL }},
5017         { &hf_gtpv1_reorder,            { "Reordering required","gtpv1.reorder",                FT_BOOLEAN,     BASE_NONE,NULL, 0, "Reordering required", HFILL }},
5018         { &hf_gtpv1_map_cause,          { "MAP cause",          "gtpv1.map_cause",              FT_UINT8,       BASE_DEC, VALS(map_cause_type), 0, "MAP cause", HFILL }},
5019         { &hf_gtpv1_ptmsi_sig,          { "P-TMSI Signature",   "gtpv1.ptmsi_sig",              FT_UINT24,      BASE_HEX, NULL, 0, "P-TMSI Signature", HFILL }},
5020         { &hf_gtpv1_ms_valid,           { "MS validated",       "gtpv1.ms_valid",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "MS validated", HFILL }},
5021         { &hf_gtpv1_recovery,           { "Recovery",           "gtpv1.recovery",               FT_UINT8,       BASE_DEC, NULL, 0, "Restart counter", HFILL }},
5022         { &hf_gtpv1_sel_mode,           { "Selection Mode",     "gtpv1.sel_mode",               FT_UINT8,       BASE_DEC, VALS(sel_mode_type), 0, "Selection Mode", HFILL }},
5023         { &hf_gtpv1_teid_data,          { "TEID Data I",        "gtpv1.teid_data",              FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data I", HFILL }},
5024         { &hf_gtpv1_teid_cp,            { "TEID Control Plane", "gtpv1.teid_cp",                FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Control Plane", HFILL }},
5025         { &hf_gtpv1_nsapi,              { "NSAPI",              "gtpv1.nsapi",                  FT_UINT8,       BASE_DEC, NULL, 0, "Network layer Service Access Point Identifier", HFILL }},
5026         { &hf_gtpv1_teid_ii,            { "TEID Data II",       "gtpv1.teid_ii",                FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data II", HFILL }},
5027         { &hf_gtpv1_tear_ind,           { "Teardown indication","gtpv1.tear_ind",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "Teardown Indication", HFILL }},
5028         { &hf_gtpv1_ranap_cause,                { "RANAP cause",        "gtpv1.ranap_cause",            FT_UINT8,       BASE_DEC, VALS(ranap_cause_type), 0, "RANAP cause", HFILL }},
5029         { &hf_gtpv1_rab_gtpu_dn,                { "Downlink GTP-U seq number",  "gtpv1.rab_gtp_dn",     FT_UINT16,      BASE_DEC, NULL, 0, "Downlink GTP-U sequence number", HFILL }},
5030         { &hf_gtpv1_rab_gtpu_up,                { "Uplink GTP-U seq number",    "gtpv1.rab_gtp_up",     FT_UINT16,      BASE_DEC, NULL, 0, "Uplink GTP-U sequence number", HFILL }},
5031         { &hf_gtpv1_rab_pdu_dn,         { "Downlink next PDCP-PDU seq number",  "gtpv1.rab_pdu_dn",             FT_UINT8,       BASE_DEC, NULL, 0, "Downlink next PDCP-PDU sequence number", HFILL }},
5032         { &hf_gtpv1_rab_pdu_up,         { "Uplink next PDCP-PDU seq number",    "gtpv1.rab_pdu_up",             FT_UINT8,       BASE_DEC, NULL, 0, "Uplink next PDCP-PDU sequence number", HFILL }},
5033         { &hf_gtpv1_rp_sms,             { "Radio Priority SMS", "gtpv1.rp_sms",                 FT_UINT8,       BASE_DEC, NULL, 0, "Radio Priority for MO SMS", HFILL }},
5034         { &hf_gtpv1_rp_nsapi,           { "NSAPI in Radio Priority",    "gtpv1.rp_nsapi",       FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_NSAPI_MASK, "Network layer Service Access Point Identifier in Radio Priority", HFILL }},
5035         { &hf_gtpv1_rp_spare,           { "Reserved",           "gtpv1.rp_spare",               FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_SPARE_MASK, "Spare bit", HFILL }},
5036         { &hf_gtpv1_rp,                 { "Radio Priority",     "gtpv1.rp",                     FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_MASK, "Radio Priority for uplink tx", HFILL }},
5037         { &hf_gtpv1_pkt_flow_id,                { "Packet Flow ID",     "gtpv1.pkt_flow_id",            FT_UINT8,       BASE_DEC, NULL, 0, "Packet Flow ID", HFILL }},
5038         { &hf_gtpv1_chrg_char_s,                { "Spare",              "gtpv1.chrg_char_s",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_S, "Spare", HFILL }},
5039         { &hf_gtpv1_chrg_char_n,                { "Normal charging",    "gtpv1.chrg_char_n",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_N, "Normal charging", HFILL }},
5040         { &hf_gtpv1_chrg_char_p,                { "Prepaid charging",   "gtpv1.chrg_char_p",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_P, "Prepaid charging", HFILL }},
5041         { &hf_gtpv1_chrg_char_f,                { "Flat rate charging", "gtpv1.chrg_char_f",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_F, "Flat rate charging", HFILL }},
5042         { &hf_gtpv1_chrg_char_h,                { "Hot billing charging",       "gtpv1.chrg_char_h",    FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_H, "Hot billing charging", HFILL }},
5043         { &hf_gtpv1_chrg_char_r,                { "Reserved",           "gtpv1.chrg_char_r",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_R, "Reserved", HFILL }},
5044         { &hf_gtpv1_trace_ref,          { "Trace reference",    "gtpv1.trace_ref",              FT_UINT16,      BASE_HEX, NULL, 0, "Trace reference", HFILL }},
5045         { &hf_gtpv1_trace_type,         { "Trace type",         "gtpv1.trace_type",             FT_UINT16,      BASE_HEX, NULL, 0, "Trace type", HFILL }},
5046         { &hf_gtpv1_ms_reason,          { "MS not reachable reason",    "gtpv1.ms_reason",      FT_UINT8,       BASE_DEC, VALS(ms_not_reachable_type), 0, "MS not reachable reason", HFILL }},
5047         { &hf_gtpv1_tr_comm,            { "Packet transfer command",    "gtpv1.tr_comm",        FT_UINT8,       BASE_DEC, VALS(tr_comm_type), 0, "Packat transfer command", HFILL }},
5048         { &hf_gtpv1_chrg_id,            { "Charging ID",        "gtpv1.chrg_id",                FT_UINT32,      BASE_HEX, NULL, 0, "Charging ID", HFILL }},
5049         { &hf_gtpv1_user_ipv4,          { "End user address IPv4",      "gtpv1.user_ipv4",      FT_IPv4,        BASE_DEC, NULL, 0, "End user address IPv4", HFILL }},
5050         { &hf_gtpv1_user_ipv6,          { "End user address IPv6",      "gtpv1.user_ipv6",      FT_IPv6,        BASE_HEX, NULL, 0, "End user address IPv6", HFILL }},
5051         { &hf_gtpv1_user_addr_pdp_org,  { "PDP type organization",      "gtpv1.user_addr_pdp_org",      FT_UINT8,       BASE_DEC, VALS(pdp_org_type), 0, "PDP type organization", HFILL }},
5052         { &hf_gtpv1_user_addr_pdp_type, { "PDP type number",    "gtpv1.user_addr_pdp_type",     FT_UINT8,       BASE_HEX, VALS(pdp_type), 0, "PDP type", HFILL }},
5053         { &hf_gtpv1_apn,                        { "APN",                "gtpv1.apn",                    FT_STRING,      BASE_DEC, NULL, 0, "Access Point Name", HFILL }},
5054         { &hf_gtpv1_gsn_addr_type,      { "GSN Address Type",   "gtpv1.gsn_addr_type",          FT_UINT8,       BASE_DEC, VALS(gsn_addr_type), GTP_EXT_GSN_ADDR_TYPE_MASK, "GSN Address Type", HFILL }},
5055         { &hf_gtpv1_gsn_addr_len,               { "GSN Address Length", "gtpv1.gsn_addr_len",           FT_UINT8,       BASE_DEC, NULL, GTP_EXT_GSN_ADDR_LEN_MASK, "GSN Address Length", HFILL }},
5056         { &hf_gtpv1_gsn_ipv4,           { "GSN address IPv4",   "gtpv1.gsn_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "GSN address IPv4", HFILL }},
5057         { &hf_gtpv1_gsn_ipv6,           { "GSN address IPv6",   "gtpv1.gsn_ipv6",               FT_IPv6,        BASE_DEC, NULL, 0, "GSN address IPv6", HFILL }},
5058         { &hf_gtpv1_msisdn,             { "MSISDN",             "gtpv1.msisdn",                 FT_STRING,      BASE_DEC, NULL, 0, "MS international PSTN/ISDN number", HFILL }},
5059         { &hf_gtpv1_qos_al_ret_priority,        { "Allocation/Retention priority ","gtpv1.qos_al_ret_priority",         FT_UINT8,       BASE_DEC, NULL, 0, "Allocation/Retention Priority", HFILL }},
5060         { &hf_gtpv1_qos_traf_class,     { "Traffic class",      "gtpv1.qos_traf_class",         FT_UINT8,       BASE_DEC, VALS(qos_traf_class), GTP_EXT_QOS_TRAF_CLASS_MASK, "Traffic Class", HFILL }},
5061         { &hf_gtpv1_qos_del_order,      { "Delivery order",     "gtpv1.qos_del_order",          FT_UINT8,       BASE_DEC, VALS(qos_del_order), GTP_EXT_QOS_DEL_ORDER_MASK, "Delivery Order", HFILL }},
5062         { &hf_gtpv1_qos_del_err_sdu,    { "Delivery of erroneous SDU",  "gtpv1.qos_del_err_sdu",        FT_UINT8,       BASE_DEC, VALS(qos_del_err_sdu), GTP_EXT_QOS_DEL_ERR_SDU_MASK, "Delivery of Erroneous SDU", HFILL }},
5063         { &hf_gtpv1_qos_max_sdu_size,   { "Maximum SDU size",   "gtpv1.qos_max_sdu_size",       FT_UINT8,       BASE_DEC, VALS(qos_max_sdu_size), 0, "Maximum SDU size", HFILL }},
5064         { &hf_gtpv1_qos_max_ul,                 { "Maximum bit rate for uplink",        "gtpv1.qos_max_ul",     FT_UINT8,       BASE_DEC, VALS(qos_max_ul), 0, "Maximum bit rate for uplink", HFILL }},
5065         { &hf_gtpv1_qos_max_dl,                 { "Maximum bit rate for downlink",      "gtpv1.qos_max_dl",     FT_UINT8,       BASE_DEC, VALS(qos_max_dl), 0, "Maximum bit rate for downlink", HFILL }},
5066         { &hf_gtpv1_qos_res_ber,                { "Residual BER",       "gtpv1.qos_res_ber",            FT_UINT8,       BASE_DEC, VALS(qos_res_ber), GTP_EXT_QOS_RES_BER_MASK, "Residual Bit Error Rate", HFILL }},
5067         { &hf_gtpv1_qos_sdu_err_ratio,  { "SDU Error ratio",    "gtpv1.qos_sdu_err_ratio",      FT_UINT8,       BASE_DEC, VALS(qos_sdu_err_ratio), GTP_EXT_QOS_SDU_ERR_RATIO_MASK, "SDU Error Ratio", HFILL }},
5068         { &hf_gtpv1_qos_trans_delay,    { "Transfer delay",     "gtpv1.qos_trans_delay",        FT_UINT8,       BASE_DEC, VALS(qos_trans_delay), GTP_EXT_QOS_TRANS_DELAY_MASK, "Transfer Delay", HFILL }},
5069         { &hf_gtpv1_qos_traf_handl_prio,        { "Traffic handling priority",  "gtpv1.qos_traf_handl_prio",    FT_UINT8,       BASE_DEC, VALS(qos_traf_handl_prio), GTP_EXT_QOS_TRAF_HANDL_PRIORITY_MASK, "Traffic Handling Priority", HFILL }},
5070         { &hf_gtpv1_qos_guar_ul,                { "Guaranteed bit rate for uplink",     "gtpv1.qos_guar_ul",    FT_UINT8,       BASE_DEC, VALS(qos_guar_ul), 0, "Guaranteed bit rate for uplink", HFILL }},
5071         { &hf_gtpv1_qos_guar_dl,                { "Guaranteed bit rate for downlink",   "gtpv1.qos_guar_dl",    FT_UINT8,       BASE_DEC, VALS(qos_guar_dl), 0, "Guaranteed bit rate for downlink", HFILL }},
5072         { &hf_gtpv1_rnc_ipv4,           { "RNC address IPv4",   "gtpv1.rnc_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "Radio Network Controller address IPv4", HFILL }},
5073         { &hf_gtpv1_rnc_ipv6,           { "RNC address IPv6",   "gtpv1.rnc_ipv6",               FT_IPv6,        BASE_HEX, NULL, 0, "Radio Network Controller address IPv6", HFILL }},
5074         { &hf_gtpv1_chrg_ipv4,          { "CG address IPv4",    "gtpv1.chrg_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Charging Gateway address IPv4", HFILL }},
5075         { &hf_gtpv1_chrg_ipv6,          { "CG address IPv6",    "gtpv1.chrg_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Charging Gateway address IPv6", HFILL }},
5076         { &hf_gtpv1_node_ipv4,          { "Node address IPv4",  "gtpv1.node_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Recommended node address IPv4", HFILL }},
5077         { &hf_gtpv1_node_ipv6,          { "Node address IPv6",  "gtpv1.node_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Recommended node address IPv6", HFILL }},
5078         { &hf_gtpv1_ext_id,             { "Extensio Identifier","gtpv1.ext_id",                 FT_UINT16,      BASE_DEC, NULL, 0, "Extension Identifier", HFILL }},
5079         { &hf_gtpv1_ext_val,            { "Extension Value",    "gtpv1.ext_val",                FT_STRING,      BASE_DEC, NULL, 0, "Extension Value", HFILL }},
5080         { &hf_gtpv1_unknown,            { "Unknown data (length)",      "gtpv1.unknown",        FT_UINT16,      BASE_DEC, NULL, 0, "Unknown data", HFILL }},
5081
5082         };
5083
5084         static gint *ett_gtp_array[] = {
5085                 &ett_gtp,
5086                 &ett_gtp_flags,
5087                 &ett_gtp_ext,
5088                 &ett_gtp_rai,
5089                 &ett_gtp_qos,
5090                 &ett_gtp_auth_tri,
5091                 &ett_gtp_flow_ii,
5092                 &ett_gtp_rab_cntxt,
5093                 &ett_gtp_rp,
5094                 &ett_gtp_pkt_flow_id,
5095                 &ett_gtp_chrg_char,
5096                 &ett_gtp_user,
5097                 &ett_gtp_mm,
5098                 &ett_gtp_trip,
5099                 &ett_gtp_quint,
5100                 &ett_gtp_pdp,
5101                 &ett_gtp_apn,
5102                 &ett_gtp_proto,
5103                 &ett_gtp_gsn_addr,
5104                 &ett_gtp_tft,
5105                 &ett_gtp_tft_pf,
5106                 &ett_gtp_rab_setup,
5107                 &ett_gtp_hdr_list,
5108                 &ett_gtp_chrg_addr,
5109                 &ett_gtp_node_addr,
5110                 &ett_gtp_rel_pack,
5111                 &ett_gtp_can_pack,
5112                 &ett_gtp_data_resp,
5113                 &ett_gtp_priv_ext,
5114         };
5115
5116         module_t        *gtp_module;
5117         
5118         static enum_val_t gtpv0_cdr_options[] = {
5119                 { "GSM 12.15",  0 },
5120                 { "Nokia CDR",  1 },
5121                 { "None",       2 },
5122                 { NULL,         -1 }
5123         };
5124
5125         proto_gtpv0 = proto_register_protocol("GPRS Tunnelling Protocol v0", "GTPv0", "gtpv0");
5126         proto_register_field_array(proto_gtpv0, hf_gtpv0, array_length(hf_gtpv0));
5127         proto_register_subtree_array(ett_gtp_array, array_length(ett_gtp_array));
5128         
5129         proto_gtpv1 = proto_register_protocol("GPRS Tunnelling Protocol v1", "GTPv1", "gtpv1");
5130         proto_register_field_array(proto_gtpv1, hf_gtpv1, array_length(hf_gtpv1));
5131         proto_register_subtree_array(ett_gtp_array, array_length(ett_gtp_array));
5132         
5133         gtp_module = prefs_register_protocol(proto_gtpv0, proto_reg_handoff_gtp);
5134         
5135         prefs_register_uint_preference(gtp_module, "gtpv0_port", "GTPv0 port ", "GTPv0 port (default 3386)", 10, &g_gtpv0_port);
5136         prefs_register_uint_preference(gtp_module, "gtpv1c_port", "GTPv1 control plane (GTP-C) port ", "GTPv1 control plane port (default 2123)", 10, &g_gtpv1c_port);
5137         prefs_register_uint_preference(gtp_module, "gtpv1u_port", "GTPv1 user plane (GTP-U) port ", "GTPv1 user plane port (default 2152)", 10, &g_gtpv1u_port);
5138         prefs_register_bool_preference(gtp_module, "gtp_dissect_tpdu", "Dissect T-PDU ", "Dissect T-PDU", &gtp_tpdu);
5139         prefs_register_enum_preference(gtp_module, "gtpv0_dissect_cdr_as", "Dissect GTP'v0 CDRs as ", "Dissect GTP'v0 CDRs as", &gtpv0_cdr_as, gtpv0_cdr_options, FALSE);
5140         prefs_register_bool_preference(gtp_module, "gtpv0_check_etsi", "Compare GTPv0 order with ETSI ", "GTPv0 ETSI order", &gtpv0_etsi_order);
5141         prefs_register_bool_preference(gtp_module, "gtpv1_check_etsi", "Compare GTPv1 order with ETSI ", "GTPv1 ETSI order", &gtpv1_etsi_order);
5142         prefs_register_bool_preference(gtp_module, "ppp_reorder", "Reorder & dissect PPP in Protocol conf. options", "PPP reorder & dissect", &ppp_reorder);
5143         
5144         register_dissector("gtpv0", dissect_gtpv0, proto_gtpv0);
5145         register_dissector("gtpv1", dissect_gtpv1, proto_gtpv1);
5146
5147 }
5148
5149 void
5150 proto_reg_handoff_gtp(void)
5151 {
5152         static int Initialized = FALSE;
5153         static dissector_handle_t gtpv0_handle;
5154         static dissector_handle_t gtpv1_handle;
5155         
5156         if (!Initialized) {
5157                 
5158                 gtpv0_handle = find_dissector("gtpv0");
5159
5160                 gtpv1_handle = find_dissector("gtpv1");
5161
5162                 Initialized = TRUE;
5163                 
5164         } else {
5165                 
5166                 dissector_delete("udp.port", gtpv0_port, gtpv0_handle);
5167                 dissector_delete("tcp.port", gtpv0_port, gtpv0_handle);
5168
5169                 dissector_delete("udp.port", gtpv1c_port, gtpv1_handle);
5170                 dissector_delete("tcp.port", gtpv1c_port, gtpv1_handle);
5171                 dissector_delete("udp.port", gtpv1u_port, gtpv1_handle);
5172                 dissector_delete("tcp.port", gtpv1u_port, gtpv1_handle);
5173         }
5174                 
5175         gtpv0_port = g_gtpv0_port;
5176         gtpv1c_port = g_gtpv1c_port;
5177         gtpv1u_port = g_gtpv1u_port;
5178         
5179         /* GTP v0 */
5180         
5181         dissector_add("udp.port", g_gtpv0_port, gtpv0_handle);
5182         dissector_add("tcp.port", g_gtpv0_port, gtpv0_handle);
5183
5184         /* GTP v1 */
5185         
5186         dissector_add("udp.port", g_gtpv1c_port, gtpv1_handle);
5187         dissector_add("tcp.port", g_gtpv1c_port, gtpv1_handle);
5188         dissector_add("udp.port", g_gtpv1u_port, gtpv1_handle);
5189         dissector_add("tcp.port", g_gtpv1u_port, gtpv1_handle);
5190         
5191         ip_handle = find_dissector("ip");
5192         ppp_handle = find_dissector("ppp");
5193 }