Show Boolean flags as Booleans.
[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.10 2001/09/27 10:01:07 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 "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 } gcdr;
1459
1460 typedef struct change_ {
1461         guint8          change;
1462         guint32         time1;
1463         guint32         time2;
1464         guint32         uplink;
1465         guint32         downlink;
1466         guint8          qos_req[3];
1467         guint8          qos_neg[3];
1468 } change_t;
1469
1470 struct _scdr {                                  /* SCDR 277B */
1471         guint16         len;
1472         guint8          netini;
1473         guint8          anon;
1474         guint8          imsilen;
1475         guint8          imsi[8];
1476         guint8          imei[8];
1477         guint8          msisdnlen;
1478         guint8          msisdn[10];
1479         guint32         sgsnaddr;
1480         guint8          msclass_notused[12];
1481         guint8          msclass_caplen;
1482         guint8          msclass_cap;
1483         guint16         msclass_capomit;
1484         guint16         lac;
1485         guint8          rac;
1486         guint16         cid;
1487         guint32         chrgid;
1488         guint32         ggsnaddr;
1489         gchar           apn[64];
1490         guint8          pdporg;
1491         guint8          pdptype;
1492         guint32         pdpaddr;
1493         guint8          listind;
1494         change_t        change[5];
1495         guint32         timestamp;
1496         guint32         opening;
1497         guint32         duration;
1498         guint8          sgsnchange;
1499         guint8          closecause;
1500         guint8          diag1;
1501         guint8          diag2;
1502         guint8          diag3;
1503         guint8          diag4;
1504         guint32         diag5;
1505         guint32         seqno;
1506 } scdr;
1507
1508 typedef struct mmchange_ {
1509         guint16         lac;
1510         guint8          rac;
1511         guint16         cid;
1512         guint8          omit[8];
1513 } mmchange_t;
1514
1515 struct _mcdr {                                  /* MCDR 147B */
1516         guint16         len;
1517         guint8          imsilen;
1518         guint8          imsi[8];
1519         guint8          imei[8];
1520         guint8          msisdnlen;
1521         guint8          msisdn[10];
1522         guint32         sgsnaddr;
1523         guint8          msclass_notused[12];
1524         guint8          msclass_caplen;
1525         guint8          msclass_cap;
1526         guint16         msclass_capomit;
1527         guint16         lac;
1528         guint8          rac;
1529         guint16         cid;
1530         guint8          change_count;
1531         mmchange_t      change[5];
1532         guint32         timestamp;
1533         guint32         opening;
1534 /*      guint8          opening[8]; */
1535         guint32         duration;
1536         guint8          sgsnchange;
1537         guint8          closecause;
1538         guint8          diag1;
1539         guint8          diag2;
1540         guint8          diag3;
1541         guint8          diag4;
1542         guint32         diag5;
1543         guint32         seqno;
1544 } mcdr;
1545
1546 struct _socdr {                                         /* SOCDR 80B */
1547         guint16         len;
1548         guint8          imsilen;
1549         guint8          imsi[8];
1550         guint8          imei[8];
1551         guint8          msisdnlen;
1552         guint8          msisdn[10];
1553         guint8          msclass_notused[12];
1554         guint8          msclass_caplen;
1555         guint8          msclass_cap;
1556         guint16         msclass_capomit;
1557         guint8          serv_centr[9];
1558         guint8          rec_ent[9];
1559         guint16         lac;
1560         guint8          rac;
1561         guint16         cid;
1562         guint32         time1;
1563         guint32         time2;
1564         guint8          messref;
1565         guint16         smsres;
1566 } socdr;
1567
1568
1569 struct _stcdr {                                         /* STCDR 79B */
1570         guint16         len;
1571         guint8          imsilen;
1572         guint8          imsi[8];
1573         guint8          imei[8];
1574         guint8          msisdnlen;
1575         guint8          msisdn[10];
1576         guint8          msclass_notused[12];
1577         guint8          msclass_caplen;
1578         guint8          msclass_cap;
1579         guint16         msclass_capomit;
1580         guint8          serv_centr[9];
1581         guint8          rec_ent[9];
1582         guint16         lac;
1583         guint8          rac;
1584         guint16         cid;
1585         guint32         time1;
1586         guint32         time2;
1587         guint16         smsres;
1588 } stcdr;
1589         
1590         guint8          gtp_version = 0;
1591         char            *yesno[] = { "False", "True" };
1592         
1593 static void
1594 col_append_str_gtp(frame_data *fd, gint el, gchar *proto_name) {
1595         
1596         int     i;
1597         int     max_len;
1598         gchar   _tmp[COL_MAX_LEN];
1599
1600         max_len = COL_MAX_LEN;
1601
1602         for (i = 0; i < fd->cinfo->num_cols; i++) {
1603                 if (fd->cinfo->fmt_matx[i][el]) {
1604                         if (fd->cinfo->col_data[i] != fd->cinfo->col_buf[i]) {
1605                                 
1606                                 strncpy(fd->cinfo->col_buf[i], fd->cinfo->col_data[i], max_len);
1607                                 fd->cinfo->col_buf[i][max_len - 1] = '\0';
1608                         }
1609         
1610                         _tmp[0] = '\0';
1611                         strcat(_tmp, proto_name);
1612                         strcat(_tmp, " <");
1613                         strcat(_tmp, fd->cinfo->col_buf[i]);
1614                         strcat(_tmp, ">");
1615                         fd->cinfo->col_buf[i][0] = '\0';
1616                         strcat(fd->cinfo->col_buf[i], _tmp);
1617                         fd->cinfo->col_data[i] = fd->cinfo->col_buf[i];
1618                 }
1619         }
1620 }
1621
1622 static gchar *
1623 id_to_str(const guint8 *ad) {
1624                 
1625         static gchar    *str[17];
1626         gchar           *p;
1627         guint8          bits8to5, bits4to1, i;
1628         static const    gchar hex_digits[10] = "0123456789";
1629
1630         p = (gchar *)&str[17];
1631         *--p = '\0';
1632         i = 7;
1633         for (;;) {
1634                 bits8to5 = (ad[i] >> 4) & 0x0F;
1635                 bits4to1 = ad[i] & 0x0F;
1636                 if (bits8to5 < 0xA) *--p = hex_digits[bits8to5]; 
1637                 if (bits4to1 < 0xA) *--p = hex_digits[bits4to1];
1638                 if (i == 0) break;
1639                 i--;
1640         }
1641         return p;
1642 }
1643
1644 static gchar *
1645 msisdn_to_str(const guint8 *ad, int len) {
1646                 
1647         static gchar    *str[17];
1648         gchar           *p;
1649         guint8          bits8to5, bits4to1, i;
1650         static const    gchar hex_digits[16] = "0123456789      ";
1651
1652         p = (gchar *)&str[0];
1653         *p = '+';
1654         i = 1;
1655         for (;;) {
1656                 bits8to5 = (ad[i] >> 4) & 0x0F;
1657                 bits4to1 = ad[i] & 0x0F;
1658                 if (bits4to1 < 0xA) *++p = hex_digits[bits4to1];
1659                 if (bits8to5 < 0xA) *++p = hex_digits[bits8to5];
1660                 if (i == len-1) break;
1661                 i++;
1662         }
1663         *++p = '\0';
1664         return (gchar *)&str[0];
1665 }
1666
1667 gchar *
1668 time_int_to_str (guint32 time)
1669 {
1670         guint   hours, mins, secs, month, days;
1671         guint   mths_n[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
1672         guint   mths_s[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
1673         static gchar    *cur, *p, str[3][2+1+2+1+2+1+4+1+2+1+2+2];
1674         
1675         if (cur == &str[0][0]) { 
1676                 cur = &str[1][0]; 
1677         } else if (cur == &str[1][0]) { 
1678                 cur = &str[2][0]; 
1679         } else { 
1680                 cur = &str[0][0]; 
1681         }
1682         
1683         if (time == 0) { 
1684                 sprintf (cur, "00:00:00 1970-01-01"); 
1685                 return cur; 
1686         }
1687         
1688         secs = time % 60; 
1689         time /= 60; 
1690         mins = time % 60; 
1691         time /= 60; 
1692         hours = time % 24; 
1693         time /= 24; 
1694         days = time % 366; 
1695         time /= 366; 
1696         days += time - (time + 2) / 4; 
1697         
1698         if ((time + 2) % 4) { 
1699                 for (month=0; month<12; month++) if (days > mths_n[month]) days -= mths_n[month]; 
1700                         else break; 
1701         } else { 
1702                 for (month=0; month<12; month++) 
1703                         if (days > mths_s[month]) days -= mths_s[month]; 
1704                         else break; 
1705         } 
1706                         
1707         month++; 
1708         days++; 
1709         time += 1970; 
1710         p = cur; 
1711         sprintf (p, "%02d:%02d:%02d %u-%02d-%02d", hours, mins, secs, time, month, days); 
1712         
1713         return  cur;
1714 }
1715
1716 /* Next definitions and function check_field_presence checks if given field 
1717  * in GTP packet is compliant with ETSI 
1718  */
1719 typedef struct _header {
1720         guint8          code;
1721         guint8          presence;
1722 } ext_header;
1723
1724 typedef struct _message {
1725         guint8          code;
1726         ext_header      fields[32];
1727 } _gtp_mess_items;
1728
1729 /* ---------------------
1730  * GPRS messages 
1731  * ---------------------*/
1732 _gtp_mess_items gprs_mess_items[] = {
1733
1734 {
1735         GTP_MSG_ECHO_REQ, {                                     
1736                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1737                 { 0,                    0 }
1738         }
1739 },
1740 {
1741         GTP_MSG_ECHO_RESP, {
1742                 { GTP_EXT_RECOVER,      MANDATORY },
1743                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1744                 { 0,                    0 }
1745         }
1746 },
1747 {
1748         GTP_MSG_VER_NOT_SUPP, {
1749                 { 0,                    0 }
1750         }
1751 },
1752 {
1753         GTP_MSG_NODE_ALIVE_REQ, {
1754                 { GTP_EXT_NODE_ADDR,    MANDATORY },
1755                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1756                 { 0,                    0 }
1757         }
1758 },
1759 {
1760         GTP_MSG_NODE_ALIVE_RESP, {
1761                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1762                 { 0,                    0 }
1763         }
1764 },
1765 {
1766         GTP_MSG_REDIR_REQ, {
1767                 { GTP_EXT_CAUSE,        MANDATORY },
1768                 { GTP_EXT_NODE_ADDR,    OPTIONAL },
1769                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1770                 { 0,                    0 }
1771         }
1772 },
1773 {
1774         GTP_MSG_REDIR_RESP, {
1775                 { GTP_EXT_CAUSE,        MANDATORY },
1776                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1777                 { 0,                    0 }
1778         }
1779 },
1780
1781         GTP_MSG_CREATE_PDP_REQ, {
1782                 { GTP_EXT_QOS_GPRS,     MANDATORY },
1783                 { GTP_EXT_RECOVER,      OPTIONAL },
1784                 { GTP_EXT_SEL_MODE,     MANDATORY },
1785                 { GTP_EXT_FLOW_LABEL,   MANDATORY },
1786                 { GTP_EXT_FLOW_SIG,     MANDATORY },
1787                 { GTP_EXT_MSISDN,       MANDATORY },
1788                 { GTP_EXT_USER_ADDR,    MANDATORY },
1789                 { GTP_EXT_APN,          MANDATORY },
1790                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1791                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1792                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1793                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1794                 { 0,                    0 }
1795         }
1796 },
1797
1798         GTP_MSG_CREATE_PDP_RESP, {
1799                 { GTP_EXT_CAUSE,        MANDATORY },
1800                 { GTP_EXT_QOS_GPRS,     CONDITIONAL },
1801                 { GTP_EXT_REORDER,      CONDITIONAL },
1802                 { GTP_EXT_RECOVER,      OPTIONAL },
1803                 { GTP_EXT_FLOW_LABEL,   CONDITIONAL },
1804                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
1805                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
1806                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
1807                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1808                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1809                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1810                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
1811                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1812                 { 0,                    0 }
1813         }
1814 },
1815 {       
1816         GTP_MSG_UPDATE_PDP_REQ, {
1817                 { GTP_EXT_QOS_GPRS,     MANDATORY },
1818                 { GTP_EXT_RECOVER,      OPTIONAL },
1819                 { GTP_EXT_FLOW_LABEL,   MANDATORY },
1820                 { GTP_EXT_FLOW_SIG,     MANDATORY },
1821                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1822                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1823                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1824                 { 0,                    0 },
1825         }
1826 },
1827 {
1828         GTP_MSG_UPDATE_PDP_RESP, {
1829                 { GTP_EXT_CAUSE,        MANDATORY },
1830                 { GTP_EXT_QOS_GPRS,     CONDITIONAL },
1831                 { GTP_EXT_RECOVER,      OPTIONAL },
1832                 { GTP_EXT_FLOW_LABEL,   CONDITIONAL },
1833                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
1834                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
1835                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1836                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1837                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
1838                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1839                 { 0,                    0 }
1840         }
1841 },
1842 {
1843         GTP_MSG_DELETE_PDP_REQ, {
1844                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1845                 { 0,                    0 }
1846         }
1847 },
1848 {
1849         GTP_MSG_DELETE_PDP_RESP, {
1850                 { GTP_EXT_CAUSE,        MANDATORY },
1851                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1852                 { 0,                    0 },
1853         }
1854 },
1855 {
1856         GTP_MSG_CREATE_AA_PDP_REQ, {
1857                 { GTP_EXT_QOS_GPRS,     MANDATORY },
1858                 { GTP_EXT_RECOVER,      OPTIONAL },
1859                 { GTP_EXT_SEL_MODE,     MANDATORY },
1860                 { GTP_EXT_FLOW_LABEL,   MANDATORY },
1861                 { GTP_EXT_FLOW_SIG,     MANDATORY },
1862                 { GTP_EXT_USER_ADDR,    MANDATORY },
1863                 { GTP_EXT_APN,          MANDATORY },
1864                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1865                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1866                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1867                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1868                 { 0,                    0 }
1869         }
1870 },
1871 {
1872         GTP_MSG_CREATE_AA_PDP_RESP, {                                   
1873                 { GTP_EXT_CAUSE,        MANDATORY },
1874                 { GTP_EXT_QOS_GPRS,     CONDITIONAL },
1875                 { GTP_EXT_REORDER,      CONDITIONAL },
1876                 { GTP_EXT_RECOVER,      OPTIONAL },
1877                 { GTP_EXT_FLOW_LABEL,   CONDITIONAL },
1878                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
1879                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
1880                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
1881                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
1882                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1883                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
1884                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
1885                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1886                 { 0,                    0 }
1887         }
1888 },
1889 {
1890         GTP_MSG_DELETE_AA_PDP_REQ, {
1891                 { GTP_EXT_CAUSE,        MANDATORY },
1892                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1893                 { 0,                    0 }
1894         }
1895 },
1896 {
1897         GTP_MSG_DELETE_AA_PDP_RESP, {
1898                 { GTP_EXT_CAUSE,        MANDATORY },
1899                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1900                 { 0,                    0 }
1901         }
1902 },
1903 {
1904         GTP_MSG_ERR_IND, {
1905                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1906                 { 0,                    0 }
1907         }
1908 },
1909 {
1910         GTP_MSG_PDU_NOTIFY_REQ, {
1911                 { GTP_EXT_USER_ADDR,    MANDATORY },
1912                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1913                 { 0,                    0 }
1914         }
1915 },
1916 {       
1917         GTP_MSG_PDU_NOTIFY_RESP, {
1918                 { GTP_EXT_CAUSE,        MANDATORY },
1919                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1920                 { 0,                    0 }
1921         }
1922 },
1923 {
1924         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
1925                 { GTP_EXT_CAUSE,        MANDATORY },
1926                 { GTP_EXT_USER_ADDR,    MANDATORY },
1927                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1928                 { 0,                    0 }
1929         }
1930 },
1931 {
1932         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
1933                 { GTP_EXT_CAUSE,        MANDATORY },
1934                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1935                 { 0,                    0 }
1936         }
1937 },
1938 {
1939         GTP_MSG_SEND_ROUT_INFO_REQ, {
1940                 { GTP_EXT_IMSI,         MANDATORY },
1941                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1942                 { 0,                    0 }
1943         }
1944 },
1945 {
1946         GTP_MSG_SEND_ROUT_INFO_RESP, {
1947                 { GTP_EXT_CAUSE,        MANDATORY },
1948                 { GTP_EXT_IMSI,         MANDATORY },
1949                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
1950                 { GTP_EXT_MS_REASON,    OPTIONAL },
1951                 { GTP_EXT_GSN_ADDR,     OPTIONAL },
1952                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1953                 { 0,                    0 }
1954         }
1955 },
1956 {
1957         GTP_MSG_FAIL_REP_REQ, {
1958                 { GTP_EXT_IMSI,         MANDATORY },
1959                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1960                 { 0,                    0 }
1961         }
1962 },
1963 {
1964         GTP_MSG_FAIL_REP_RESP, {
1965                 { GTP_EXT_CAUSE,        MANDATORY },
1966                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
1967                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1968                 { 0,                    0 }
1969         }
1970 },
1971 {
1972         GTP_MSG_MS_PRESENT_REQ, {
1973                 { GTP_EXT_IMSI,         MANDATORY },
1974                 { GTP_EXT_GSN_ADDR,     MANDATORY },
1975                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1976                 { 0,                    0 }
1977         }
1978 },
1979 {
1980         GTP_MSG_MS_PRESENT_RESP, {
1981                 { GTP_EXT_CAUSE,        MANDATORY },
1982                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1983                 { 0,                    0 }
1984         }
1985 },
1986 {
1987         GTP_MSG_IDENT_REQ, {
1988                 { GTP_EXT_RAI,          MANDATORY },
1989                 { GTP_EXT_PTMSI,        MANDATORY },
1990                 { GTP_EXT_PTMSI_SIG,    OPTIONAL },
1991                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
1992                 { 0,                    0 }
1993         }
1994 },
1995 {
1996         GTP_MSG_IDENT_RESP, {
1997                 { GTP_EXT_CAUSE,        MANDATORY },
1998                 { GTP_EXT_IMSI,         CONDITIONAL },
1999                 { GTP_EXT_AUTH_TRI,     OPTIONAL },
2000                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2001                 { 0,                    0 }
2002         }
2003 },
2004 {
2005         GTP_MSG_SGSN_CNTXT_REQ, {
2006                 { GTP_EXT_IMSI,         CONDITIONAL },
2007                 { GTP_EXT_RAI,          MANDATORY },
2008                 { GTP_EXT_TLLI,         MANDATORY },
2009                 { GTP_EXT_PTMSI_SIG,    OPTIONAL },
2010                 { GTP_EXT_MS_VALID,     OPTIONAL },
2011                 { GTP_EXT_FLOW_SIG,     MANDATORY },
2012                 { 0,                    0 }
2013         }
2014 },
2015 {
2016         GTP_MSG_SGSN_CNTXT_RESP, {
2017                 { GTP_EXT_CAUSE,        MANDATORY },
2018                 { GTP_EXT_IMSI,         CONDITIONAL },
2019                 { GTP_EXT_FLOW_SIG,     CONDITIONAL },
2020                 { GTP_EXT_MM_CNTXT,     CONDITIONAL },
2021                 { GTP_EXT_PDP_CNTXT,    CONDITIONAL },
2022                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2023                 { 0,                    0 }
2024         }
2025 },
2026 {
2027         GTP_MSG_SGSN_CNTXT_ACK, {
2028                 { GTP_EXT_CAUSE,        MANDATORY },
2029                 { GTP_EXT_FLOW_II,      CONDITIONAL },
2030                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2031                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2032                 { 0,                    0 }
2033         }
2034 },
2035 {
2036         GTP_MSG_DATA_TRANSF_REQ, {
2037                 { GTP_EXT_TR_COMM,      MANDATORY },
2038                 { GTP_EXT_DATA_REQ,     CONDITIONAL },
2039                 { GTP_EXT_REL_PACK,     CONDITIONAL },
2040                 { GTP_EXT_CAN_PACK,     CONDITIONAL },
2041                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2042                 { 0,                    0 }
2043         }
2044 },
2045 {
2046         GTP_MSG_DATA_TRANSF_RESP, {
2047                 { GTP_EXT_CAUSE,        MANDATORY },
2048                 { GTP_EXT_DATA_RESP,    MANDATORY },
2049                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2050                 { 0,                    0 }
2051         }
2052 },
2053 {
2054         0, {
2055                 { 0,                    0 }
2056         }
2057 }
2058 };
2059
2060 /* -----------------------------
2061  * UMTS messages 
2062  * -----------------------------*/
2063 _gtp_mess_items umts_mess_items[] = {
2064
2065 {
2066         GTP_MSG_ECHO_REQ, {                                     
2067                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2068                 { 0,                    0 }
2069         }
2070 },
2071 {
2072         GTP_MSG_ECHO_RESP, {
2073                 { GTP_EXT_RECOVER,      MANDATORY },
2074                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2075                 { 0,                    0 }
2076         }
2077 },
2078 {
2079         GTP_MSG_VER_NOT_SUPP, {
2080                 { 0,                    0 }
2081         }
2082 },
2083 {
2084         GTP_MSG_NODE_ALIVE_REQ, {
2085                 { GTP_EXT_NODE_ADDR,    MANDATORY },
2086                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2087                 { 0,                    0 }
2088         }
2089 },
2090 {
2091         GTP_MSG_NODE_ALIVE_RESP, {
2092                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2093                 { 0,                    0 }
2094         }
2095 },
2096 {
2097         GTP_MSG_REDIR_REQ, {
2098                 { GTP_EXT_CAUSE,        MANDATORY },
2099                 { GTP_EXT_NODE_ADDR,    OPTIONAL },
2100                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2101                 { 0,                    0 }
2102         }
2103 },
2104 {
2105         GTP_MSG_REDIR_REQ, {
2106                 { 0,                    0 }
2107         }
2108 },
2109 {
2110         GTP_MSG_CREATE_PDP_REQ, {
2111                 { GTP_EXT_IMSI,         CONDITIONAL },
2112                 { GTP_EXT_RECOVER,      OPTIONAL },
2113                 { GTP_EXT_SEL_MODE,     CONDITIONAL },
2114                 { GTP_EXT_TEID,         MANDATORY },
2115                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2116                 { GTP_EXT_NSAPI,        MANDATORY },
2117                 { GTP_EXT_NSAPI,        CONDITIONAL },
2118                 { GTP_EXT_CHRG_CHAR,    OPTIONAL },
2119                 { GTP_EXT_TRACE_REF,    OPTIONAL },
2120                 { GTP_EXT_TRACE_TYPE,   OPTIONAL },
2121                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
2122                 { GTP_EXT_APN,          CONDITIONAL },
2123                 { GTP_EXT_PROTO_CONF,   CONDITIONAL },
2124                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2125                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2126                 { GTP_EXT_MSISDN,       CONDITIONAL },
2127                 { GTP_EXT_QOS_UMTS,     MANDATORY },
2128                 { GTP_EXT_TFT,          CONDITIONAL },
2129                 { GTP_EXT_TRIGGER_ID,   OPTIONAL },
2130                 { GTP_EXT_OMC_ID,       OPTIONAL },
2131                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2132                 { 0,                    0 }
2133         }
2134 },
2135 {
2136         GTP_MSG_CREATE_PDP_RESP, {
2137                 { GTP_EXT_CAUSE,        MANDATORY },
2138                 { GTP_EXT_REORDER,      CONDITIONAL },
2139                 { GTP_EXT_RECOVER,      OPTIONAL },
2140                 { GTP_EXT_TEID,         CONDITIONAL },
2141                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2142                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
2143                 { GTP_EXT_USER_ADDR,    CONDITIONAL },
2144                 { GTP_EXT_PROTO_CONF,   OPTIONAL },
2145                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2146                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2147                 { GTP_EXT_QOS_UMTS,     CONDITIONAL },
2148                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
2149                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2150                 { 0,                    0 }
2151         }
2152 },
2153 {       /* checked, SGSN -> GGSN */
2154         GTP_MSG_UPDATE_PDP_REQ, {
2155                 { GTP_EXT_IMSI,         CONDITIONAL },
2156                 { GTP_EXT_RECOVER,      OPTIONAL },
2157                 { GTP_EXT_TEID,         MANDATORY },
2158                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2159                 { GTP_EXT_NSAPI,        MANDATORY },
2160                 { GTP_EXT_TRACE_REF,    OPTIONAL },
2161                 { GTP_EXT_TRACE_TYPE,   OPTIONAL },
2162                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2163                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2164                 { GTP_EXT_QOS_UMTS,     MANDATORY },
2165                 { GTP_EXT_TFT,          OPTIONAL },
2166                 { GTP_EXT_TRIGGER_ID,   OPTIONAL },
2167                 { GTP_EXT_OMC_ID,       OPTIONAL },
2168                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2169                 { 0,                    0 }
2170         }
2171 },
2172 {       /* checked, GGSN -> SGSN */
2173         GTP_MSG_UPDATE_PDP_RESP, {
2174                 { GTP_EXT_CAUSE,        MANDATORY },
2175                 { GTP_EXT_RECOVER,      OPTIONAL },
2176                 { GTP_EXT_TEID,         CONDITIONAL },
2177                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2178                 { GTP_EXT_CHRG_ID,      CONDITIONAL },
2179                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2180                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2181                 { GTP_EXT_QOS_UMTS,     CONDITIONAL },
2182                 { GTP_EXT_CHRG_ADDR,    OPTIONAL },
2183                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2184                 { 0,                    0 }
2185         }
2186 },
2187 {
2188         GTP_MSG_DELETE_PDP_REQ, {
2189                 { GTP_EXT_TEAR_IND,     CONDITIONAL },
2190                 { GTP_EXT_NSAPI,        MANDATORY },
2191                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2192                 { 0,                    0 }
2193         }
2194 },
2195 {
2196         GTP_MSG_DELETE_PDP_RESP, {
2197                 { GTP_EXT_CAUSE,        MANDATORY },
2198                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2199                 { 0,                    0 }
2200         }
2201 },
2202 {
2203         GTP_MSG_ERR_IND, {
2204                 { GTP_EXT_TEID,         MANDATORY },
2205                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2206                 { 0,                    0 }
2207         }
2208 },
2209 {
2210         GTP_MSG_PDU_NOTIFY_REQ, {
2211                 { GTP_EXT_IMSI,         MANDATORY },
2212                 { GTP_EXT_TEID_CP,      MANDATORY },
2213                 { GTP_EXT_USER_ADDR,    MANDATORY },
2214                 { GTP_EXT_APN,          MANDATORY },
2215                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2216                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2217                 { 0,                    0 }
2218         }
2219 },
2220 {
2221         GTP_MSG_PDU_NOTIFY_RESP, {
2222                 { GTP_EXT_CAUSE,        MANDATORY },
2223                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2224                 { 0,                    0 }
2225         }
2226 },
2227 {
2228         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
2229                 { GTP_EXT_CAUSE,        MANDATORY },
2230                 { GTP_EXT_TEID_CP,      MANDATORY },
2231                 { GTP_EXT_USER_ADDR,    MANDATORY },
2232                 { GTP_EXT_APN,          MANDATORY },
2233                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2234                 { 0,                    0 }
2235         }
2236 },
2237 {
2238         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
2239                 { GTP_EXT_CAUSE,        MANDATORY },
2240                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2241                 { 0,                    0 }
2242         }
2243 },
2244 {
2245         GTP_MSG_SUPP_EXT_HDR, {
2246                 { GTP_EXT_HDR_LIST,     MANDATORY },
2247                 { 0,                    0 }
2248         }
2249 },
2250 {
2251         GTP_MSG_SEND_ROUT_INFO_REQ, {
2252                 { GTP_EXT_IMSI,         MANDATORY },
2253                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2254                 { 0,                    0 }
2255         }
2256 },
2257 {
2258         GTP_MSG_SEND_ROUT_INFO_RESP, {
2259                 { GTP_EXT_CAUSE,        MANDATORY },
2260                 { GTP_EXT_IMSI,         MANDATORY },
2261                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
2262                 { GTPv1_EXT_MS_REASON,  OPTIONAL },
2263                 { GTP_EXT_GSN_ADDR,     OPTIONAL },
2264                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2265                 { 0,                    0 }
2266         }
2267 },
2268 {
2269         GTP_MSG_FAIL_REP_REQ, {
2270                 { GTP_EXT_IMSI,         MANDATORY },
2271                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2272                 { 0,                    0 }
2273         }
2274 },
2275 {
2276         GTP_MSG_FAIL_REP_RESP, {
2277                 { GTP_EXT_CAUSE,        MANDATORY },
2278                 { GTP_EXT_MAP_CAUSE,    OPTIONAL },
2279                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2280                 { 0,                    0 }
2281         }
2282 },
2283 {
2284         GTP_MSG_MS_PRESENT_REQ, {
2285                 { GTP_EXT_IMSI,         MANDATORY },
2286                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2287                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2288                 { 0,                    0 }
2289         }
2290 },
2291 {
2292         GTP_MSG_MS_PRESENT_RESP, {
2293                 { GTP_EXT_CAUSE,        MANDATORY },
2294                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2295                 { 0,                    0 }
2296         }
2297 },
2298 {
2299         GTP_MSG_IDENT_REQ, {
2300                 { GTP_EXT_RAI,          MANDATORY },
2301                 { GTP_EXT_PTMSI,        MANDATORY },
2302                 { GTP_EXT_PTMSI_SIG,    CONDITIONAL },
2303                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2304                 { 0,                    0 }
2305         }
2306 },
2307 {
2308         GTP_MSG_IDENT_RESP, {
2309                 { GTP_EXT_CAUSE,        MANDATORY },
2310                 { GTP_EXT_IMSI,         CONDITIONAL },
2311                 { GTP_EXT_AUTH_TRI,     CONDITIONAL },
2312                 { GTP_EXT_AUTH_QUI,     CONDITIONAL },
2313                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2314                 { 0,                    0 }
2315         }
2316 },
2317 {
2318         GTP_MSG_SGSN_CNTXT_REQ, {
2319                 { GTP_EXT_IMSI,         CONDITIONAL },
2320                 { GTP_EXT_RAI,          MANDATORY },
2321                 { GTP_EXT_TLLI,         CONDITIONAL },
2322                 { GTP_EXT_PTMSI,        CONDITIONAL },
2323                 { GTP_EXT_PTMSI_SIG,    CONDITIONAL },
2324                 { GTP_EXT_MS_VALID,     OPTIONAL },
2325                 { GTP_EXT_TEID_CP,      MANDATORY },
2326                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2327                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2328                 { 0,                    0 }
2329         }
2330 },
2331 {
2332         GTP_MSG_SGSN_CNTXT_RESP, {
2333                 { GTP_EXT_CAUSE,        MANDATORY },
2334                 { GTP_EXT_IMSI,         CONDITIONAL },
2335                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2336                 { GTP_EXT_RP_SMS,       OPTIONAL },
2337                 { GTP_EXT_RP,           OPTIONAL },
2338                 { GTP_EXT_PKT_FLOW_ID,  OPTIONAL },
2339                 { GTP_EXT_MM_CNTXT,     CONDITIONAL },
2340                 { GTP_EXT_PDP_CNTXT,    CONDITIONAL },
2341                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2342                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2343                 { 0,                    0 }
2344         }
2345 },
2346 {
2347         GTP_MSG_SGSN_CNTXT_ACK, {
2348                 { GTP_EXT_CAUSE,        MANDATORY },
2349                 { GTP_EXT_TEID_II,      CONDITIONAL },
2350                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2351                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2352                 { 0,                    0 }
2353         }
2354 },
2355 {
2356         GTP_MSG_FORW_RELOC_REQ, {
2357                 { GTP_EXT_IMSI,         MANDATORY },
2358                 { GTP_EXT_TEID_CP,      MANDATORY },
2359                 { GTP_EXT_RANAP_CAUSE,  MANDATORY },
2360                 { GTP_EXT_MM_CNTXT,     MANDATORY },
2361                 { GTP_EXT_PDP_CNTXT,    CONDITIONAL },
2362                 { GTP_EXT_GSN_ADDR,     MANDATORY },
2363                 { GTP_EXT_TARGET_ID,    MANDATORY },
2364                 { GTP_EXT_UTRAN_CONT,   MANDATORY },
2365                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2366                 { 0,                    0 }
2367         }
2368 },
2369 {
2370         GTP_MSG_FORW_RELOC_RESP, {
2371                 { GTP_EXT_CAUSE,        MANDATORY },
2372                 { GTP_EXT_TEID_CP,      CONDITIONAL },
2373                 { GTP_EXT_RANAP_CAUSE,  CONDITIONAL },
2374                 { GTP_EXT_GSN_ADDR,     CONDITIONAL },
2375                 { GTP_EXT_UTRAN_CONT,   OPTIONAL },
2376                 { GTP_EXT_RAB_SETUP,    CONDITIONAL },
2377                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2378                 { 0,                    0 }
2379         }
2380 },
2381 {
2382         GTP_MSG_FORW_RELOC_COMP, {
2383                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2384                 { 0,                    0 }
2385         }
2386 },
2387 {
2388         GTP_MSG_RELOC_CANCEL_REQ, {
2389                 { GTP_EXT_IMSI,         MANDATORY },
2390                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2391                 { 0,                    0 }
2392         }
2393 },
2394 {
2395         GTP_MSG_RELOC_CANCEL_RESP, {
2396                 { GTP_EXT_CAUSE,        MANDATORY },
2397                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2398                 { 0,                    0 }
2399         }
2400 },
2401 {
2402         GTP_MSG_FORW_RELOC_ACK, {
2403                 { GTP_EXT_CAUSE,        MANDATORY },
2404                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2405                 { 0,                    0 }
2406         }
2407 },
2408 {
2409         GTP_MSG_FORW_SRNS_CNTXT, {
2410                 { GTP_EXT_RAB_CNTXT,    MANDATORY },
2411                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2412                 { 0,                    0 }
2413         }
2414 },
2415 {
2416         GTP_MSG_FORW_SRNS_CNTXT_ACK, {
2417                 { GTP_EXT_CAUSE,        MANDATORY },
2418                 { GTP_EXT_PRIV_EXT,     OPTIONAL },
2419                 { 0,                    0 }
2420         }
2421 },
2422 {
2423         0, {
2424                 { 0,                    0 }
2425         }
2426 }
2427 };
2428
2429 static int 
2430 check_field_presence(guint8 message, guint8 field, int *position) {
2431         
2432         guint                   i = 0;
2433         _gtp_mess_items         *mess_items;
2434
2435         switch(gtp_version) {
2436                 case 0: 
2437                         mess_items = gprs_mess_items;
2438                         break;
2439                 case 1: 
2440                         mess_items = umts_mess_items;
2441                         break;
2442                 default:
2443                         return -2;
2444         }
2445
2446         while (mess_items[i].code) {
2447                 if (mess_items[i].code == message) {
2448                         
2449                         while (mess_items[i].fields[*position].code) {
2450                                 if (mess_items[i].fields[*position].code == field) {
2451                                         (*position)++;
2452                                         return 0;
2453                                 } else { 
2454                                 if (mess_items[i].fields[*position].presence == MANDATORY) {
2455                                         return mess_items[i].fields[(*position)++].code;
2456                                 } else {
2457                                         (*position)++;
2458                                 }}
2459                         }
2460                         return -1;
2461                 }
2462                 i++;
2463         }       
2464
2465         return -2;
2466 }
2467
2468 /* Decoders of fields in extension headers, each function returns no of bytes from field */
2469
2470 /* GPRS:        9.60 v7.6.0, chapter
2471  * UMTS:        29.060 v4.0, chapter
2472  */
2473 static int
2474 decode_gtp_cause(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2475
2476         guint8  cause;
2477         
2478         cause = tvb_get_guint8(tvb, offset+1);  
2479         
2480         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_cause : hf_gtpv0_cause, tvb, offset, 2, cause);
2481
2482         return 2;
2483 }
2484
2485 /* GPRS:        9.60 v7.6.0, chapter 7.9.2
2486  * UMTS:        29.060 v4.0, chapter 7.7.2
2487  */
2488 static int 
2489 decode_gtp_imsi(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2490                 
2491         guint8  tid_val[8];
2492         gchar   *tid_str;
2493
2494         tvb_memcpy(tvb, tid_val, offset+1, 8);
2495         tid_val[1] = tid_val[1] & 0x0F;
2496         tid_str = id_to_str(tid_val);
2497         
2498         proto_tree_add_string(tree, gtp_version ? hf_gtpv1_imsi : hf_gtpv0_imsi, tvb, offset, 9, tid_str);
2499
2500         return 9;
2501 }
2502
2503 /* GPRS:        9.60 v7.6.0, chapter 7.9.3
2504  * UMTS:        29.060 v4.0, chapter 7.7.3
2505  * TODO: Add details about MCC, MNC, LAC, RAC (show each digit) ?
2506  */
2507 static int
2508 decode_gtp_rai(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2509                 
2510         proto_tree      *ext_tree_rai;
2511         proto_item      *te;
2512         
2513         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_RAI, gtp_val, "Unknown message")); 
2514         ext_tree_rai = proto_item_add_subtree(te, ett_gtp_rai);
2515         
2516         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_mcc : hf_gtpv0_rai_mcc, tvb, offset+1, 2, tvb_get_letohs(tvb, offset+1) & 0xFF0F);
2517         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_mnc : hf_gtpv0_rai_mnc, tvb, offset+2, 2, tvb_get_ntohs(tvb, offset+3) & 0xF0FF);
2518         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_lac : hf_gtpv0_rai_lac, tvb, offset+4, 2, tvb_get_letohs(tvb, offset+4));
2519         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));
2520
2521         return 7;
2522 }
2523
2524 /* GPRS:        9.60 v7.6.0, chapter 7.9.4, page 39
2525  * UMTS:        29.060 v4.0, chapter 7.7.4, page 47
2526  */
2527 static int
2528 decode_gtp_tlli(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2529                 
2530         guint32 tlli;
2531         
2532         tlli = tvb_get_ntohl(tvb, offset+1);    
2533         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_tlli : hf_gtpv0_tlli, tvb, offset, 5, tlli); 
2534
2535         return 5;
2536 }
2537
2538 /* GPRS:        9.60 v7.6.0, chapter 7.9.5, page 39
2539  * UMTS:        29.060 v4.0, chapter 7.7.5, page 47
2540  */
2541 static int
2542 decode_gtp_ptmsi(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2543                 
2544         guint32 ptmsi;
2545         
2546         ptmsi = tvb_get_ntohl(tvb, offset);     
2547         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ptmsi : hf_gtpv0_ptmsi, tvb, offset, 5, ptmsi);
2548
2549         return 5;
2550 }
2551
2552 /* adjust - how many bytes before offset should be highlighted 
2553  */
2554 static int
2555 decode_qos_gprs(tvbuff_t *tvb, int offset, proto_tree *tree, gchar* qos_str, guint8 adjust) {
2556         
2557         guint8          spare1, delay, reliability, peak, spare2,  precedence, spare3, mean;
2558         proto_tree      *ext_tree_qos;
2559         proto_item      *te;
2560         
2561         spare1 = tvb_get_guint8(tvb, offset) & 0xC0;
2562         delay = tvb_get_guint8(tvb, offset) & 0x38;
2563         reliability = tvb_get_guint8(tvb, offset) & 0x07;
2564         peak = tvb_get_guint8(tvb, offset+1) & 0xF0;
2565         spare2 = tvb_get_guint8(tvb, offset+1) & 0x08;
2566         precedence = tvb_get_guint8(tvb, offset+1) & 0x07;
2567         spare3 = tvb_get_guint8(tvb, offset+2) & 0xE0;
2568         mean = tvb_get_guint8(tvb, offset+2) & 0x1F;
2569         
2570         te = proto_tree_add_text(tree, tvb, offset-adjust, 3+adjust, "%s: delay: %u, reliability: %u, peak: %u, precedence: %u, mean: %u",
2571                                                                         qos_str, delay, reliability, peak, precedence, mean);
2572         ext_tree_qos = proto_item_add_subtree(te, ett_gtp_qos);
2573
2574         if (adjust != 0) {
2575                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare1, tvb, offset, 1, spare1);
2576                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_delay, tvb, offset, 1, delay);
2577                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_reliability, tvb, offset, 1, reliability);
2578                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_peak, tvb, offset+1, 1, peak);
2579                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare2, tvb, offset+1, 1, spare2);
2580                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_precedence, tvb, offset+1, 1, precedence);
2581                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare3, tvb, offset+2, 1, spare3);
2582                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_mean, tvb, offset+2, 1, mean);
2583         }
2584
2585         return 3; 
2586 }
2587
2588 /* GPRS:        9.60 v7.6.0, chapter 7.9.6, page 39
2589  *              4.08
2590  *              3.60
2591  * UMTS:        not present
2592  * TODO:        check if length is included: ETSI 4.08 vs 9.60 
2593  */
2594 static int
2595 decode_gtp_qos_gprs(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2596                 
2597         return (1+decode_qos_gprs(tvb, offset+1, tree, "Quality of Service", 1));
2598         
2599 }
2600
2601 /* GPRS:        9.60 v7.6.0, chapter 7.9.7, page 39
2602  * UMTS:        29.060 v4.0, chapter 7.7.6, page 47
2603  */
2604 static int
2605 decode_gtp_reorder(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2606
2607         guint8  reorder;
2608         
2609         reorder = tvb_get_guint8(tvb, offset+1) & 0x01; 
2610         proto_tree_add_boolean(tree, gtp_version ? hf_gtpv1_reorder : hf_gtpv0_reorder, tvb, offset, 2, reorder); 
2611
2612         return 2;
2613 }
2614
2615 /* GPRS:        9.60 v7.6.0, chapter 7.9.8, page 40
2616  *              4.08 v7.1.2, chapter 10.5.3.1+ 
2617  * UMTS:        29.060 v4.0, chapter 7.7.7
2618  * TODO: Add blurb support by registering items in the protocol registration
2619  */
2620 static int
2621 decode_gtp_auth_tri(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2622
2623         proto_tree      *ext_tree_auth_tri;
2624         proto_item      *te;
2625         guint32         rand[4], sres, kc[2];
2626         
2627         tvb_memcpy(tvb, (guint8 *)&rand, offset+1, 16);
2628         sres = tvb_get_ntohl(tvb, offset+17);
2629         tvb_memcpy(tvb, (guint8 *)&kc, offset+21, 16);
2630         
2631         te = proto_tree_add_text(tree, tvb, offset, 29, val_to_str(GTP_EXT_AUTH_TRI, gtp_val, "Unknown message"));
2632         ext_tree_auth_tri = proto_item_add_subtree(tree, ett_gtp_auth_tri);
2633                                                         
2634         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]);
2635         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+17, 4, "SRES: %x", sres);
2636         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+21, 8, "Kc: %x%x", kc[0], kc[1]);
2637
2638         return 1+16+4+8;
2639 }
2640
2641 /* GPRS:        9.60 v7.6.0, chapter 7.9.9, page 40
2642  *              9.02 v7.7.0, page 1090
2643  * UMTS:        29.060 v4.0, chapter 7.7.8, page 48
2644  *              29.002 v4.2.1, chapter 17.5, page 268
2645  */
2646 static int
2647 decode_gtp_map_cause(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2648                 
2649         guint8  map_cause;
2650         
2651         map_cause = tvb_get_guint8(tvb, offset+1);      
2652         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_map_cause : hf_gtpv0_map_cause, tvb, offset, 2, map_cause);
2653
2654         return 2;
2655 }
2656
2657 /* GPRS:        9.60 v7.6.0, chapter 7.9.10, page 41
2658  * UMTS:        29.060 v4.0, chapter 7.7.9, page 48
2659  */
2660 static int
2661 decode_gtp_ptmsi_sig(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2662                 
2663         guint32 ptmsi_sig;
2664         
2665         ptmsi_sig = tvb_get_ntoh24(tvb, offset+1);      
2666         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ptmsi_sig : hf_gtpv0_ptmsi_sig, tvb, offset, 4, ptmsi_sig);
2667
2668         return 4;
2669 }
2670
2671 /* GPRS:        9.60 v7.6.0, chapter 7.9.11, page 41
2672  * UMTS:        29.060 v4.0, chapter 7.7.10, page 49
2673  */
2674 static int
2675 decode_gtp_ms_valid(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2676                 
2677         guint8  ms_valid;
2678         
2679         ms_valid = tvb_get_guint8(tvb, offset+1) & 0x01;        
2680         proto_tree_add_boolean(tree, gtp_version ? hf_gtpv1_ms_valid : hf_gtpv0_ms_valid, tvb, offset, 2, ms_valid);
2681
2682         return 2;
2683 }
2684
2685 /* GPRS:        9.60 v7.6.0, chapter 7.9.12, page 41
2686  * UMTS:        29.060 v4.0, chapter 7.7.11, page 49
2687  */
2688 static int
2689 decode_gtp_recovery(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2690                 
2691         guint8  recovery;
2692         
2693         recovery = tvb_get_guint8(tvb, offset+1);       
2694         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_recovery : hf_gtpv0_recovery, tvb, offset, 2, recovery);
2695
2696         return 2;
2697 }
2698
2699 /* GPRS:        9.60 v7.6.0, chapter 7.9.13, page 42
2700  * UMTS:        29.060 v4.0, chapter 7.7.12, page 49
2701  */
2702 static int
2703 decode_gtp_sel_mode(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2704                 
2705         guint8  sel_mode;
2706         
2707         sel_mode = tvb_get_guint8(tvb, offset+1) & 0x03;        
2708         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_sel_mode : hf_gtpv0_sel_mode, tvb, offset, 2, sel_mode);
2709
2710         return 2;
2711 }
2712
2713 /* GPRS:        9.60 v7.6.0, chapter 7.9.14, page 42
2714  * UMTS:        29.060 v4.0, chapter 7.7.13, page 50
2715  */
2716 static int
2717 decode_gtp_16(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2718                 
2719         guint16 ext_flow_label; 
2720         guint32 teid_data;
2721
2722         switch (gtp_version) {
2723                 case 0:
2724                         ext_flow_label = tvb_get_ntohs(tvb, offset+1);  
2725                         proto_tree_add_uint(tree, hf_gtpv0_ext_flow_label, tvb, offset, 3, ext_flow_label);
2726                         
2727                         return 3;
2728                 case 1:
2729                         teid_data = tvb_get_ntohl(tvb, offset+1);
2730                         proto_tree_add_uint(tree, hf_gtpv1_teid_data, tvb, offset, 5, teid_data);
2731
2732                         return 5;
2733                 default: 
2734                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label/TEID Data I : GTP version not supported");
2735                         
2736                         return 3;
2737         }
2738 }
2739
2740 /* GPRS:        9.60 v7.6.0, chapter 7.9.15, page 42
2741  * UMTS:        29.060 v4.0, chapter 7.7.14, page 42
2742  */
2743 static int
2744 decode_gtp_17(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2745
2746         guint16         flow_sig;
2747         guint32         teid_cp;
2748
2749         switch (gtp_version) {
2750                 case 0:
2751                         flow_sig = tvb_get_ntohs(tvb, offset+1);        
2752                         proto_tree_add_uint(tree, hf_gtpv0_flow_sig, tvb, offset, 3, flow_sig);
2753                         
2754                         return 3;
2755                 case 1:
2756                         teid_cp = tvb_get_ntohl(tvb, offset+1);
2757                         proto_tree_add_uint(tree, hf_gtpv1_teid_cp, tvb, offset, 5, teid_cp);
2758                         
2759                         return 5;
2760                 default:
2761                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label signalling/TEID control plane : GTP version not supported");
2762                         
2763                         return 3;
2764         }
2765 }
2766
2767 /* GPRS:        9.60 v7.6.0, chapter 7.9.16, page 42
2768  * UMTS:        29.060 v4.0, chapter 7.7.15, page 51
2769  */
2770 static int
2771 decode_gtp_18(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2772
2773         guint16         flow_ii;
2774         guint32         teid_ii;
2775         proto_tree      *ext_tree_flow_ii;
2776         proto_item      *te;
2777
2778         switch (gtp_version) {
2779                 case 0:
2780                         te = proto_tree_add_text(tree, tvb, offset, 4, val_to_str(GTP_EXT_FLOW_II, gtp_val, "Unknown message"));
2781                         ext_tree_flow_ii = proto_item_add_subtree(te, ett_gtp_flow_ii);
2782                         
2783                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv0_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2784                         
2785                         flow_ii = tvb_get_ntohs(tvb, offset+2); 
2786                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv0_flow_ii, tvb, offset+2, 2, flow_ii);
2787                         
2788                         return 4;
2789                 case 1: 
2790                         te = proto_tree_add_text(tree, tvb, offset, 6, val_to_str(GTP_EXT_TEID_II, gtp_val, "Unknown message"));
2791                         ext_tree_flow_ii = proto_item_add_subtree(te, ett_gtp_flow_ii);
2792                         
2793                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv1_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2794
2795                         
2796                         teid_ii = tvb_get_ntohl(tvb, offset+2);
2797                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv1_teid_ii, tvb, offset+2, 4, teid_ii);
2798                         
2799                         return 6;
2800                 default:
2801                         proto_tree_add_text(tree, tvb, offset, 1, "Flow data II/TEID Data II : GTP Version not supported");
2802                         
2803                         return 4;
2804         }
2805 }
2806
2807 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A, page 43
2808  * UMTS:        29.060 v4.0, chapter 7.7.16, page 51
2809  * Check if all ms_reason types are included
2810  */
2811 static int
2812 decode_gtp_19(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2813                 
2814         guint8          field19;        
2815         
2816         field19 = tvb_get_guint8(tvb, offset+1);        
2817         
2818         switch (gtp_version) {
2819                 case 0: 
2820                         proto_tree_add_uint(tree, hf_gtpv0_ms_reason, tvb, offset, 2, field19);
2821                         
2822                         break;
2823                 case 1:
2824                         proto_tree_add_boolean(tree, hf_gtpv1_tear_ind, tvb, offset, 2, field19 & 0x01);
2825                         
2826                         break;
2827                 default:
2828                         proto_tree_add_text(tree, tvb, offset, 1, "Information Element Type = 19 : GTP Version not supported");
2829
2830                         break;
2831         }
2832
2833         return 2;
2834 }
2835
2836 /* GPRS:        not present
2837  * UMTS:        29.060 v4.0, chapter 7.7.17, page 51
2838  */
2839 static int
2840 decode_gtp_nsapi(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2841                 
2842         guint8          nsapi;
2843         
2844         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;   
2845         proto_tree_add_uint(tree, hf_gtpv1_nsapi, tvb, offset, 2, nsapi);
2846
2847         return 2;
2848 }
2849
2850 /* GPRS:        not present
2851  * UMTS:        29.060 v4.0, chapter 7.7.18, page 52
2852  */
2853 static int
2854 decode_gtp_ranap_cause(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2855                 
2856         guint8          ranap;
2857         
2858         ranap = tvb_get_guint8(tvb, offset+1);
2859
2860         if(ranap > 0 && ranap <=64)
2861         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);
2862
2863         if(ranap > 64 && ranap <=80)
2864         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);
2865
2866         if(ranap > 80 && ranap <=96)
2867         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);
2868
2869         if(ranap > 96 && ranap <=112)
2870         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);
2871
2872         if(ranap > 112 && ranap <=128)
2873         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);
2874
2875         if(ranap > 128 && ranap <=255)
2876         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);
2877
2878         return 2;
2879 }
2880
2881 /* GPRS:        not present
2882  * UMTS:        29.060 v4.0, chapter 7.7.19, page 52
2883  */
2884 static int
2885 decode_gtp_rab_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2886                 
2887         guint8          nsapi, dl_pdcp_seq, ul_pdcp_seq;
2888         guint16         dl_gtpu_seq, ul_gtpu_seq;
2889         proto_tree      *ext_tree_rab_cntxt;
2890         proto_item      *te;
2891         
2892         te = proto_tree_add_text(tree, tvb, offset, 8, val_to_str(GTP_EXT_RAB_CNTXT, gtp_val, "Unknown message"));
2893         ext_tree_rab_cntxt = proto_item_add_subtree(te, ett_gtp_rab_cntxt);
2894         
2895         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;   
2896         dl_gtpu_seq = tvb_get_ntohs(tvb, offset+2);
2897         ul_gtpu_seq = tvb_get_ntohs(tvb, offset+4);
2898         dl_pdcp_seq = tvb_get_guint8(tvb, offset+6);
2899         ul_pdcp_seq = tvb_get_guint8(tvb, offset+7);
2900
2901         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_nsapi, tvb, offset+1, 1, nsapi);
2902         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_gtpu_dn, tvb, offset+2, 2, dl_gtpu_seq);
2903         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_gtpu_up, tvb, offset+4, 2, ul_gtpu_seq);
2904         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_pdu_dn, tvb, offset+6, 1, dl_pdcp_seq);
2905         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_pdu_up, tvb, offset+7, 1, ul_pdcp_seq);
2906
2907         return 8;
2908 }
2909
2910
2911 /* GPRS:        not present
2912  * UMTS:        29.060 v4.0, chapter 7.7.20, page 53
2913  */
2914 static int
2915 decode_gtp_rp_sms(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2916                 
2917         guint8          rp_sms;
2918         
2919         rp_sms = tvb_get_guint8(tvb, offset+1) & 0x07;  
2920         proto_tree_add_uint(tree, hf_gtpv1_rp_sms, tvb, offset, 2, rp_sms);
2921
2922         return 2;
2923 }
2924
2925 /* GPRS:        not present
2926  * UMTS:        29.060 v4.0, chapter 7.7.21, page 53
2927  */
2928 static int
2929 decode_gtp_rp(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2930                 
2931         proto_tree      *ext_tree_rp;
2932         proto_item      *te;
2933         guint8          nsapi, rp, spare;
2934         
2935         nsapi = tvb_get_guint8(tvb, offset+1) & 0xF0;
2936         spare = tvb_get_guint8(tvb, offset+1) & 0x08;
2937         rp = tvb_get_guint8(tvb, offset+1) & 0x07;
2938
2939         te = proto_tree_add_uint_format(tree, hf_gtpv1_rp, tvb, offset, 2, rp, "Radio Priority for NSAPI(%u) : %u", nsapi, rp);
2940         ext_tree_rp = proto_item_add_subtree(tree, ett_gtp_rp);
2941
2942         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp_nsapi, tvb, offset+1, 1, nsapi);
2943         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp_spare, tvb, offset+1, 1, spare);
2944         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp, tvb, offset+1, 1, rp);
2945
2946         return 2;
2947 }
2948
2949 /* GPRS:        not present
2950  * UMTS:        29.060 v4.0, chapter 7.7.22, page 53
2951  */
2952 static int
2953 decode_gtp_pkt_flow_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2954                 
2955         proto_tree      *ext_tree_pkt_flow_id;
2956         proto_item      *te;
2957         guint8          nsapi, pkt_flow_id;
2958         
2959         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
2960         pkt_flow_id = tvb_get_guint8(tvb, offset+2);
2961
2962         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);
2963         ext_tree_pkt_flow_id = proto_item_add_subtree(tree, ett_gtp_pkt_flow_id);
2964
2965         proto_tree_add_uint(ext_tree_pkt_flow_id, hf_gtpv1_nsapi, tvb, offset+1, 1, nsapi);
2966         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);
2967         
2968         return 3;
2969 }
2970
2971 /* GPRS:        not present
2972  * UMTS:        29.060 v4.0, chapter 7.7.23, page 53
2973  * TODO: Differenciate these uints?
2974  */
2975 static int
2976 decode_gtp_chrg_char(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
2977                 
2978         guint16         chrg_char;
2979         proto_item      *te;
2980         proto_tree      *ext_tree_chrg_char;
2981         
2982         chrg_char = tvb_get_ntohs(tvb, offset+1);
2983         
2984         te = proto_tree_add_text(tree, tvb, offset, 3, "%s: %x", val_to_str(GTP_EXT_CHRG_CHAR, gtp_val, "Unknown message"), chrg_char);
2985         ext_tree_chrg_char = proto_item_add_subtree(te, ett_gtp_chrg_char);
2986         
2987         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_s, tvb, offset+1, 2, chrg_char);
2988         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_n, tvb, offset+1, 2, chrg_char);
2989         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_p, tvb, offset+1, 2, chrg_char);
2990         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_f, tvb, offset+1, 2, chrg_char);
2991         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_h, tvb, offset+1, 2, chrg_char);
2992         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_r, tvb, offset+1, 2, chrg_char);
2993         
2994         return 3;
2995 }
2996
2997 /* GPRS:        not present
2998  * UMTS:        29.060 v4.0, chapter 7.7.24, page 
2999  */
3000 static int
3001 decode_gtp_trace_ref(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3002                 
3003         guint16         trace_ref;
3004         
3005         trace_ref = tvb_get_ntohs(tvb, offset+1);
3006         
3007         proto_tree_add_uint(tree, hf_gtpv1_trace_ref, tvb, offset, 3, trace_ref);
3008
3009         return 3;
3010 }
3011
3012 /* GPRS:        not present
3013  * UMTS:        29.060 v4.0, chapter 7.7.25, page 
3014  */
3015 static int
3016 decode_gtp_trace_type(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3017                 
3018         guint16         trace_type;
3019         
3020         trace_type = tvb_get_ntohs(tvb, offset+1);
3021         
3022         proto_tree_add_uint(tree, hf_gtpv1_trace_type, tvb, offset, 3, trace_type);
3023         
3024         return 3;
3025 }
3026
3027 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A
3028  * UMTS:        29.060 v4.0, chapter 7.7.25A, page 
3029  */
3030 static int
3031 decode_gtp_ms_reason(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3032                 
3033         guint8          reason; 
3034         
3035         reason = tvb_get_guint8(tvb, offset+1); 
3036         
3037         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ms_reason : hf_gtpv0_ms_reason, tvb, offset, 2, reason);
3038
3039         return 2;
3040 }
3041
3042
3043 /* GPRS:        12.15
3044  * UMTS:        33.015
3045  */
3046 static int
3047 decode_gtp_tr_comm(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3048                 
3049         guint8  tr_command;     
3050         
3051         tr_command = tvb_get_ntohl(tvb, offset+1);      
3052         
3053         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_tr_comm : hf_gtpv0_tr_comm, tvb, offset, 2, tr_command);
3054
3055         return 2;
3056 }
3057
3058 /* GPRS:        9.60 v7.6.0, chapter 7.9.17, page 43
3059  * UMTS:        29.060 v4.0, chapter 7.7.26, page 55
3060  */
3061 static int
3062 decode_gtp_chrg_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3063                 
3064         guint32 chrg_id;        
3065         
3066         chrg_id = tvb_get_ntohl(tvb, offset+1); 
3067         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_chrg_id : hf_gtpv0_chrg_id, tvb, offset, 5, chrg_id);
3068
3069         return 5;
3070 }
3071
3072 /* GPRS:        9.60 v7.6.0, chapter 7.9.18, page 43
3073  * UMTS:        29.060 v4.0, chapter 7.7.27, page 55
3074  */
3075 static int
3076 decode_gtp_user_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3077                 
3078         guint16         length;
3079         guint8          pdp_typ, pdp_org;       
3080         guint32         addr_ipv4;
3081         struct          e_in6_addr addr_ipv6;
3082         proto_tree      *ext_tree_user;
3083         proto_item      *te;
3084         
3085         
3086         length = tvb_get_ntohs(tvb, offset+1);
3087         pdp_org = tvb_get_guint8(tvb, offset+3) & 0x0F;
3088         pdp_typ = tvb_get_guint8(tvb, offset+4);
3089
3090         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s (%s/%s)",
3091             val_to_str(GTP_EXT_USER_ADDR, gtp_val, "Unknown message"),
3092             val_to_str(pdp_org, pdp_org_type, "Unknown PDP Organization"),
3093             val_to_str(pdp_typ, pdp_type, "Unknown PDP Type"));
3094         ext_tree_user = proto_item_add_subtree(te, ett_gtp_user);
3095         
3096         proto_tree_add_text(ext_tree_user, tvb, offset+1, 2, "Length : %u", length);
3097         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);
3098         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);
3099         
3100         if (length == 2) {
3101                 if (pdp_org == 0 && pdp_typ == 1)
3102                         proto_item_append_text(te, " (Point to Point Protocol)");
3103                 else if (pdp_typ == 2)
3104                         proto_item_append_text(te, " (Octet Stream Protocol)");
3105         } else if (length > 2) {
3106                 switch (pdp_typ) {
3107                         case 0x21:
3108                                 addr_ipv4 = tvb_get_letohl(tvb, offset+5);
3109                                 proto_tree_add_ipv4(ext_tree_user, gtp_version ? hf_gtpv1_user_ipv4 : hf_gtpv0_user_ipv4, tvb, offset+5, 4, addr_ipv4);  
3110                                 proto_item_append_text(te, " : %s", ip_to_str((guint8 *)&addr_ipv4));
3111                                 break;
3112                         case 0x57:
3113                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+5, sizeof addr_ipv6);
3114                                 proto_tree_add_ipv6(ext_tree_user, gtp_version ? hf_gtpv1_user_ipv6 : hf_gtpv0_user_ipv6, tvb, offset+5, 16, (guint8 *)&addr_ipv6);
3115                                 proto_item_append_text(te, " : %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3116                                 break;
3117                 }
3118         } else
3119                 proto_item_append_text(te, " : empty PDP Address");
3120                                 
3121         return 3+length;
3122 }
3123
3124 static int
3125 decode_triplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count) {
3126         
3127         proto_tree      *ext_tree_trip;
3128         proto_item      *te_trip;
3129         guint32         rand[4], sres, kc[2];
3130         guint16         i;
3131         
3132         for (i=0;i<count;i++) {
3133                 
3134                 tvb_memcpy(tvb, (guint8 *)&rand, offset+i*28, 16);
3135                 sres = tvb_get_ntohl(tvb, offset+i*28+16);
3136                 tvb_memcpy(tvb, (guint8 *)&kc, offset+i*28+20, 8);
3137
3138                 te_trip = proto_tree_add_text(tree, tvb, offset+i*28, 28, "Triplet no%x", i);
3139                 ext_tree_trip = proto_item_add_subtree(te_trip, ett_gtp_trip);
3140                                                         
3141                 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]);
3142                 proto_tree_add_text(ext_tree_trip, tvb, offset+i*28+16, 4, "SRES: %x", sres);
3143                 proto_tree_add_text(ext_tree_trip, tvb, offset+i*28+20, 8, "Kc: %x%x", kc[0], kc[1]);
3144         }
3145         
3146         return count*28;
3147 }
3148
3149 /* adjust - how many bytes before quintuplet should be highlighted
3150  */
3151 static int
3152 decode_quintuplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count, guint8 adjust) {
3153         
3154         proto_tree      *ext_tree_quint;
3155         proto_item      *te_quint;
3156         guint32         rand[4], q_ck[4], q_ik[4];
3157         guint16         q_len, xres_len, auth_len, q_offset, i;
3158
3159         q_offset = 0;
3160         
3161         for (i=0;i<count;i++) { 
3162         
3163                 offset = offset + q_offset;
3164                 
3165                 q_len = tvb_get_ntohs(tvb, offset);
3166                 
3167                 tvb_memcpy(tvb, (guint8 *)&rand, offset+2, 16);
3168                 xres_len = tvb_get_ntohs(tvb, offset+18);
3169 /*              xres = tvb_get_ptr(tvb, offset+20, xres_len);*/
3170                 tvb_memcpy(tvb, (guint8 *)&q_ck, offset+20+xres_len, 16);
3171                 tvb_memcpy(tvb, (guint8 *)&q_ik, offset+36+xres_len, 16);
3172                 auth_len = tvb_get_ntohs(tvb, offset+52+xres_len);
3173 /*              auth = tvb_get_ptr(tvb, offset+54+xres_len, auth_len);*/
3174
3175                 te_quint = proto_tree_add_text(tree, tvb, offset-adjust, q_len+adjust, "Quintuplet #%x", i);
3176                 ext_tree_quint = proto_item_add_subtree(te_quint, ett_gtp_quint);
3177                                                         
3178                 proto_tree_add_text(ext_tree_quint, tvb, offset, 2, "Length: %x", q_len);
3179                 proto_tree_add_text(ext_tree_quint, tvb, offset+2, 16, "RAND: %x%x%x%x", rand[0], rand[1], rand[2], rand[3]);
3180                 proto_tree_add_text(ext_tree_quint, tvb, offset+18, 2, "XRES length: %x", xres_len);
3181                 proto_tree_add_text(ext_tree_quint, tvb, offset+20, xres_len, "XRES");
3182                 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]);
3183                 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]);
3184                 proto_tree_add_text(ext_tree_quint, tvb, offset+52+xres_len, 2, "Authentication length: %x", auth_len);
3185                 proto_tree_add_text(ext_tree_quint, tvb, offset+54+xres_len, auth_len, "AUTH");
3186
3187                 q_offset = q_offset + q_len + 2;
3188         }
3189         
3190         return q_offset;
3191 }
3192
3193 /* GPRS:        9.60 v7.6.0, chapter 7.9.19 page 
3194  * UMTS:        29.060 v4.0, chapter 7.7.28 page 57
3195  * TODO:        - check if for quintuplets first 2 bytes are length, according to AuthQuint
3196  *              - finish displaying last 3 parameters
3197  */
3198 static int
3199 decode_gtp_mm_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3200                 
3201         guint16         length, quint_len, net_cap, con_len;    
3202         guint8          cksn, count, sec_mode, cipher, trans_id, proto_disc, message, drx_split, drx_len, drx_ccch, non_drx_timer;
3203         guint32         kc[4], ik[4];
3204         proto_tree      *ext_tree_mm;
3205         proto_item      *te;
3206         
3207         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_MM_CNTXT, gtp_val, "Unknown message"));
3208         ext_tree_mm = proto_item_add_subtree(te, ett_gtp_mm);
3209         
3210         length = tvb_get_ntohs(tvb, offset+1);
3211         if (length < 1) return 3;
3212         
3213         cksn = tvb_get_guint8(tvb, offset+3) & 0x07;
3214         sec_mode = (tvb_get_guint8(tvb, offset+4) >> 6) & 0x03;
3215         count = (tvb_get_guint8(tvb, offset+4) >> 3) & 0x07;
3216         cipher = tvb_get_guint8(tvb, offset+4) & 0x07;
3217         
3218         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 2, "Length: %x", length);
3219         proto_tree_add_text(ext_tree_mm, tvb, offset+3, 1, "Ciphering Key Sequence Number: %u", cksn);
3220         if (gtp_version != 0) {
3221                 proto_tree_add_text(ext_tree_mm, tvb, offset+3, 1, "Security type: %u", sec_mode);
3222         } else {
3223                 sec_mode = 1;
3224         }
3225         
3226         proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "No of triplets: %u", count);
3227
3228         switch (sec_mode) {
3229                 case 0: 
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, 16);
3236                         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]);
3237                         tvb_memcpy(tvb, (guint8 *)&ik, offset+21, 16);
3238                         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]);
3239                         quint_len = tvb_get_ntohs(tvb, offset+37);
3240                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: %x", quint_len);
3241
3242                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count, 0) + 39;
3243                         
3244                                         
3245                         break;
3246                 case 1: 
3247                         if (cipher == 0) {
3248                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3249                         } else {
3250                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3251                         }
3252                         tvb_memcpy(tvb, (guint8 *)&kc, offset+5, 8);
3253                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %x%x", kc[0], kc[1]);
3254
3255                         offset = offset + decode_triplet(tvb, offset+13, ext_tree_mm, count) + 13;
3256
3257                         break;
3258                 case 2: 
3259                         tvb_memcpy(tvb, (guint8 *)&kc, offset+5, 16);
3260                         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]);
3261                         tvb_memcpy(tvb, (guint8 *)&ik, offset+21, 16);
3262                         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]);
3263                         quint_len = tvb_get_ntohs(tvb, offset+37);
3264                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: %x", quint_len);
3265                         
3266                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count, 0) + 39;
3267                         
3268                         break;
3269                 case 3: 
3270                         if (cipher == 0) {
3271                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3272                         } else {
3273                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3274                         }
3275                         tvb_memcpy(tvb, (guint8 *)&kc, offset+5, 8);
3276                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %x%x", kc[0], kc[1]);
3277                         quint_len = tvb_get_ntohs(tvb, offset+13);
3278                         proto_tree_add_text(ext_tree_mm, tvb, offset+13, 2, "Quintuplets length: %x", quint_len);
3279
3280                         offset = offset + decode_quintuplet(tvb, offset+15, ext_tree_mm, count, 0) + 15;
3281                         
3282                         break;
3283                 default:
3284                         break;
3285         }
3286         
3287         
3288         drx_split = tvb_get_guint8(tvb, offset);
3289         drx_len = (tvb_get_guint8(tvb, offset+1) >> 4) & 0x0F;
3290         drx_ccch = (tvb_get_guint8(tvb, offset+1) >> 3) & 0x01;
3291         non_drx_timer = tvb_get_guint8(tvb, offset+1) & 0x07;
3292
3293         net_cap = tvb_get_ntohs(tvb, offset+2);
3294         con_len = tvb_get_ntohs(tvb, offset+4);
3295         
3296         proto_tree_add_text(ext_tree_mm, tvb, offset, 1, "DRX: split PG cycle code: %u", drx_split);
3297         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: CN specific DRX cycle length coefficient: %u", drx_len);
3298         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: split PG cycle on CCCH supported by MS: %s", yesno[drx_ccch]);
3299         if (non_drx_timer == 0) {
3300                 proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: no non-DRX mode after transfer state");
3301         } else {
3302                 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);
3303         }
3304         
3305         proto_tree_add_text(ext_tree_mm, tvb, offset+2, 2, "MS network capability: %u", net_cap);
3306         proto_tree_add_text(ext_tree_mm, tvb, offset+4, 2, "Container length: %u", con_len);
3307         
3308         if (con_len > 0) {
3309                 trans_id = (tvb_get_guint8(tvb, offset+6) >> 4) & 0x0F;
3310                 proto_disc = tvb_get_guint8(tvb, offset+6) & 0x0F;
3311                 message = tvb_get_guint8(tvb, offset+7);
3312         }
3313
3314         return 3+length;
3315 }
3316
3317 /* adjust - how many bytes before offset sould be highligthed
3318  * WARNING : actually length is coded on 2 octets for QoS profile but on 1 octet for PDP Context!
3319  */
3320 static int
3321 decode_qos_umts(tvbuff_t *tvb, int offset, proto_tree *tree, gchar* qos_str, guint8 adjust) {
3322
3323         guint8          length;
3324         guint8          al_ret_priority;
3325         guint8          delay, reliability, peak, precedence, mean, spare1, spare2, spare3;
3326         guint8          traf_class, del_order, del_err_sdu;
3327         guint8          max_sdu_size, max_ul, max_dl;
3328         guint8          res_ber, sdu_err_ratio;
3329         guint8          trans_delay, traf_handl_prio;
3330         guint8          guar_ul, guar_dl;
3331         proto_tree      *ext_tree_qos;
3332         proto_item      *te;
3333         int             mss, mu, md, gu, gd;
3334
3335         length = tvb_get_guint8(tvb, offset-1);
3336         al_ret_priority = tvb_get_guint8(tvb, offset);
3337
3338         spare1 = tvb_get_guint8(tvb, offset+1) & 0xC0;
3339         delay = tvb_get_guint8(tvb, offset+1) & 0x38;
3340         reliability = tvb_get_guint8(tvb, offset+1) & 0x07;
3341         peak = tvb_get_guint8(tvb, offset+2) & 0xF0;
3342         spare2 = tvb_get_guint8(tvb, offset+2) & 0x08;
3343         precedence = tvb_get_guint8(tvb, offset+2) & 0x07;
3344         spare3 = tvb_get_guint8(tvb, offset+3) & 0xE0;
3345         mean = tvb_get_guint8(tvb, offset+3) & 0x1F;
3346         traf_class = tvb_get_guint8(tvb, offset+4) & 0xE0;
3347         del_order = tvb_get_guint8(tvb, offset+4) & 0x18;
3348         del_err_sdu = tvb_get_guint8(tvb, offset+4) & 0x07;
3349         max_sdu_size = tvb_get_guint8(tvb, offset+5);
3350         max_dl = tvb_get_guint8(tvb, offset+6);
3351         max_ul = tvb_get_guint8(tvb, offset+7);
3352         res_ber = tvb_get_guint8(tvb, offset+8) & 0xF0;
3353         sdu_err_ratio = tvb_get_guint8(tvb, offset+8) & 0x0F;
3354         trans_delay = tvb_get_guint8(tvb, offset+9) & 0xFC;
3355         traf_handl_prio = tvb_get_guint8(tvb, offset+9) & 0x03;
3356         guar_ul = tvb_get_guint8(tvb, offset+10);
3357         guar_dl = tvb_get_guint8(tvb, offset+11);
3358         
3359         te = proto_tree_add_text(tree, tvb, offset-adjust, length+adjust, "%s : length (%u)", qos_str, length);
3360         ext_tree_qos = proto_item_add_subtree(te, ett_gtp_qos);
3361         
3362         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_al_ret_priority, tvb, offset, 1, al_ret_priority);
3363         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare1, tvb, offset+1, 1, spare1);
3364         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_delay, tvb, offset+1, 1, delay);
3365         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_reliability, tvb, offset+1, 1, reliability);
3366         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_peak, tvb, offset+2, 1, peak);
3367         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare2, tvb, offset+2, 1, spare2);
3368         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_precedence, tvb, offset+2, 1, precedence);
3369         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare3, tvb, offset+3, 1, spare3);
3370         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_mean, tvb, offset+3, 1, mean);
3371         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_traf_class, tvb, offset+4, 1, traf_class);
3372         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_del_order, tvb, offset+4, 1, del_order);
3373         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_del_err_sdu, tvb, offset+4, 1, del_err_sdu);
3374         
3375         if (max_sdu_size == 0 || max_sdu_size > 150)
3376                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_sdu_size, tvb, offset+5, 1, max_sdu_size);
3377         if (max_sdu_size > 0 && max_sdu_size <= 150) {
3378                 mss = max_sdu_size*10;
3379                 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);
3380         }
3381
3382         if(max_ul == 0 || max_ul == 255)
3383                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+6, 1, max_ul);
3384         if(max_ul > 0 && max_ul <= 63)
3385                 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);
3386         if(max_ul > 63 && max_ul <=127) {
3387                 mu = 64 + ( max_ul - 64 ) * 8;
3388                 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);
3389         }
3390
3391         if(max_ul > 127 && max_ul <=254) {
3392                 mu = 576 + ( max_ul - 128 ) * 64;
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_dl == 0 || max_dl == 255)
3397                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+7, 1, max_dl);
3398         if(max_dl > 0 && max_dl <= 63)
3399                 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);
3400         if(max_dl > 63 && max_dl <=127) {
3401                 md = 64 + ( max_dl - 64 ) * 8;
3402                 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);
3403         }
3404         if(max_dl > 127 && max_dl <=254) {
3405                 md = 576 + ( max_dl - 128 ) * 64;
3406                 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);
3407         }
3408
3409         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_res_ber, tvb, offset+8, 1, res_ber);
3410         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_sdu_err_ratio, tvb, offset+8, 1, sdu_err_ratio);
3411         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_trans_delay, tvb, offset+9, 1, trans_delay);
3412
3413
3414         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_traf_handl_prio, tvb, offset+9, 1, traf_handl_prio);
3415
3416         if(guar_ul == 0 || guar_ul == 255)
3417                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+10, 1, guar_ul);
3418         if(guar_ul > 0 && guar_ul <= 63)
3419                 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);
3420         if(guar_ul > 63 && guar_ul <=127) {
3421                 gu = 64 + ( guar_ul - 64 ) * 8;
3422                 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);
3423         }
3424         if(guar_ul > 127 && guar_ul <=254) {
3425                 gu = 576 + ( guar_ul - 128 ) * 64;
3426                 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);
3427         }
3428
3429         if(guar_dl == 0 || guar_dl == 255)
3430                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+11, 1, guar_dl);
3431         if(guar_dl > 0 && guar_dl <= 63)
3432                 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);
3433         if(guar_dl > 63 && guar_dl <=127) {
3434                 gd = 64 + ( guar_dl - 64 ) * 8;
3435                 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);
3436         }
3437         if(guar_dl > 127 && guar_dl <=254) {
3438                 gd = 576 + ( guar_dl - 128 ) * 64;
3439                 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);
3440         }
3441         
3442         return length + adjust;
3443
3444 }
3445
3446 static void
3447 decode_apn(tvbuff_t *tvb, int offset, guint16 length, proto_tree *tree) {
3448
3449         gchar   *apn = NULL;
3450         guint8  name_len, tmp;
3451
3452         if (length > 0) {
3453                 apn = g_malloc(length);
3454                 tvb_memcpy(tvb, apn, offset+1, length);
3455                 name_len = tvb_get_guint8(tvb, offset);
3456                 
3457                 for (;;) {
3458                         if (name_len >= length-1) break;
3459                         tmp = name_len;
3460                         name_len = name_len + apn[tmp] + 1;
3461                         apn[tmp] = '.';
3462                 }
3463                 apn[length-1] = '\0';
3464                 proto_tree_add_string(tree, gtp_version ? hf_gtpv1_apn : hf_gtpv0_apn, tvb, offset, length, apn);
3465                 g_free(apn);
3466         }
3467 }
3468
3469 /* GPRS:        9.60 v7.6.0, chapter 7.9.20
3470  * UMTS:        29.060 v4.0, chapter 7.7.29
3471  * TODO:        unify addr functions 
3472  */
3473 static int
3474 decode_gtp_pdp_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3475
3476         guint8          ggsn_addr_len, apn_len, trans_id, vaa, order, nsapi, sapi, pdu_send_no, pdu_rec_no, pdp_cntxt_id,
3477                         pdp_type_org, pdp_type_num, pdp_addr_len;
3478         guint16         length, l_offset, sn_down, sn_up, up_flow;
3479         guint32         addr_ipv4, up_teid, up_teid_cp;
3480         struct  e_in6_addr addr_ipv6;   
3481         proto_tree      *ext_tree_pdp;
3482         proto_item      *te;
3483         
3484         length = tvb_get_ntohs(tvb, offset+1);
3485         
3486         te = proto_tree_add_text(tree, tvb, offset, length+3, val_to_str(GTP_EXT_PDP_CNTXT, gtp_val, "Unknown message"));
3487         ext_tree_pdp = proto_item_add_subtree(te, ett_gtp_pdp);
3488         
3489         vaa = (tvb_get_guint8(tvb, offset+3) >> 6) & 0x01;
3490         order = (tvb_get_guint8(tvb, offset+3) >> 4) & 0x01;
3491         nsapi =  tvb_get_guint8(tvb, offset+3) & 0x0F;
3492         sapi = tvb_get_guint8(tvb, offset+4) & 0x0F;
3493         
3494         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "VPLMN address allowed: %s", yesno[vaa]);
3495         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "Reordering required: %s", yesno[order]);
3496         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "NSAPI: %u", nsapi);
3497         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "SAPI: %u", sapi);
3498         
3499         switch (gtp_version) {
3500                 case 0: 
3501                         decode_qos_gprs(tvb, offset+5, ext_tree_pdp, "QoS subscribed", 0);
3502                         decode_qos_gprs(tvb, offset+8, ext_tree_pdp, "QoS requested", 0);
3503                         decode_qos_gprs(tvb, offset+11, ext_tree_pdp, "QoS negotiated", 0);
3504                         offset = offset + 13;
3505                         break;
3506                 case 1: 
3507                         offset = offset + 5;
3508                         offset = offset + decode_qos_umts(tvb, offset+1, ext_tree_pdp, "QoS subscribed", 1);
3509                         offset = offset + decode_qos_umts(tvb, offset+1, ext_tree_pdp, "QoS requested", 1);
3510                         offset = offset + decode_qos_umts(tvb, offset+1, ext_tree_pdp, "QoS negotiated", 1);
3511                         break;
3512                 default:
3513                         break;
3514         }
3515         
3516         sn_down = tvb_get_ntohs(tvb, offset);
3517         sn_up = tvb_get_ntohs(tvb, offset+2);
3518         pdu_send_no = tvb_get_guint8(tvb, offset+4);
3519         pdu_rec_no = tvb_get_guint8(tvb, offset+5);
3520         
3521         proto_tree_add_text(ext_tree_pdp, tvb, offset, 2, "Sequence number down: %u", sn_down);
3522         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 2, "Sequence number up: %u", sn_up);
3523         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "Send N-PDU number: %u", pdu_send_no);
3524         proto_tree_add_text(ext_tree_pdp, tvb, offset+5, 1, "Receive N-PDU number: %u", pdu_rec_no);
3525         
3526         switch (gtp_version) {
3527                 case 0:
3528                         up_flow = tvb_get_ntohs(tvb, offset+6);
3529                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 2, "Uplink flow label signalling: %u", up_flow);
3530                         offset = offset + 8;
3531                         break;
3532                 case 1:
3533                         up_teid = tvb_get_ntohl(tvb, offset+6);
3534                         up_teid_cp = tvb_get_ntohl(tvb, offset+10);
3535                         pdp_cntxt_id = tvb_get_guint8(tvb, offset+14);
3536                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 4, "Uplink TEID: %x", up_teid);
3537                         proto_tree_add_text(ext_tree_pdp, tvb, offset+10, 4, "Uplink TEID control plane: %x", up_teid_cp);
3538                         proto_tree_add_text(ext_tree_pdp, tvb, offset+14, 1, "PDP context identifier: %u", pdp_cntxt_id);
3539                         offset = offset + 15;
3540                         break;
3541                 default:
3542                         break;
3543         }
3544
3545         pdp_type_org = tvb_get_guint8(tvb, offset) & 0x0F;
3546         pdp_type_num = tvb_get_guint8(tvb, offset+1);
3547         pdp_addr_len = tvb_get_guint8(tvb, offset+2);
3548         
3549         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "PDP type: %s", val_to_str(pdp_type_org, pdp_type, "Unknown PDP type"));
3550         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 1, "PDP organization: %s", val_to_str(pdp_type_num, pdp_org_type, "Unknown PDP org"));
3551         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 1, "PDP address length: %u", pdp_addr_len);
3552
3553         if (pdp_addr_len > 0) {
3554                 switch (pdp_type_num) {
3555                         case 0x21:
3556                                 addr_ipv4 = tvb_get_letohl(tvb, offset+3);
3557                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 4, "PDP address: %s", ip_to_str((guint8 *)&addr_ipv4));
3558                                 break;
3559                         case 0x57:
3560                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
3561                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 16, "PDP address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3562                                 break;
3563                         default:
3564                                 break;
3565                 }
3566         }
3567         
3568         offset = offset + 3 + pdp_addr_len;
3569
3570         ggsn_addr_len = tvb_get_guint8(tvb, offset);
3571         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN 1 address length: %u", ggsn_addr_len);
3572         
3573         switch (ggsn_addr_len) {
3574                 case 4: 
3575                         addr_ipv4 = tvb_get_letohl(tvb, offset+1);
3576                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN 1 address: %s", ip_to_str((guint8 *)&addr_ipv4));
3577                         break;
3578                 case 16: 
3579                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+1, sizeof addr_ipv6);
3580                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN 1 address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3581                         break;
3582                 default:
3583                         break;
3584         }
3585         
3586         offset = offset + 1 + ggsn_addr_len;
3587         
3588         ggsn_addr_len = tvb_get_guint8(tvb, offset);
3589         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN 2 address length: %u", ggsn_addr_len);
3590         
3591         switch (ggsn_addr_len) {
3592                 case 4: 
3593                         addr_ipv4 = tvb_get_letohl(tvb, offset+1);
3594                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN 2 address: %s", ip_to_str((guint8 *)&addr_ipv4));
3595                         break;
3596                 case 16: 
3597                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+1, sizeof addr_ipv6);
3598                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN 2 address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3599                         break;
3600                 default:
3601                         break;
3602         }
3603         
3604         offset = offset + 1 + ggsn_addr_len;
3605         
3606         apn_len = tvb_get_guint8(tvb, offset);
3607         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "APN length: %u", apn_len);
3608         decode_apn(tvb, offset+1, apn_len, ext_tree_pdp);
3609
3610         offset = offset + 1 + apn_len;
3611         
3612         trans_id = tvb_get_guint8(tvb, offset);
3613         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "Transaction identifier: %u", trans_id);
3614
3615         return 3+length;
3616 }
3617
3618 /* GPRS:        9.60, v7.6.0, chapter 7.9.21
3619  * UMTS:        29.060, v4.0, chapter 7.7.30
3620  */
3621 static int
3622 decode_gtp_apn(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3623
3624         guint16         length, name_len, tmp;  
3625         gchar           *apn;
3626         proto_tree      *ext_tree_apn;
3627         proto_item      *te;
3628         
3629         length = tvb_get_ntohs(tvb, offset+1);  
3630
3631         te = proto_tree_add_text(tree, tvb, offset, length+3, val_to_str(GTP_EXT_APN, gtp_val, "Unknown field"));
3632         ext_tree_apn = proto_item_add_subtree(te, ett_gtp_apn);
3633         
3634         proto_tree_add_text(ext_tree_apn, tvb, offset+1, 2, "APN length : %u", length);
3635         decode_apn(tvb, offset+3, length, ext_tree_apn);
3636
3637         return 3+length;
3638 }
3639
3640 /* GPRS:        9.60 v7.6.0, chapter 7.9.22
3641  *              4.08 v. 7.1.2, chapter 10.5.6.3 (p.580)
3642  * UMTS:        29.060 v4.0, chapter 7.7.31
3643  *              24.008, v4.2, chapter 10.5.6.3
3644  * TODO:        check if length is 8 or 16 bits
3645  *              - proto_conf in 3G */
3646 int
3647 decode_gtp_proto_conf(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3648
3649         guint16         length, proto_offset;
3650         guint8          *ptr, conf, proto_len, tmp, msg;
3651         tvbuff_t        *next_tvb;
3652         proto_tree      *ext_tree_proto;
3653         proto_item      *te;
3654         packet_info     save_pi;
3655
3656         length = tvb_get_ntohs(tvb, offset + 1);
3657
3658         te = proto_tree_add_text(tree, tvb, offset, length + 3, val_to_str(GTP_EXT_PROTO_CONF, gtp_val, "Unknown message"));
3659         ext_tree_proto = proto_item_add_subtree(te, ett_gtp_proto);
3660
3661         proto_tree_add_text(ext_tree_proto, tvb, offset + 1, 2, "Length: %u", length);
3662
3663         if (length < 1) return 3;
3664
3665         conf = tvb_get_guint8(tvb, offset + 3) & 0x07;
3666         proto_offset = 1;       /* ... 1st byte is conf */
3667
3668         for (;;) {
3669                 if (proto_offset >= length) break;
3670                 proto_len = tvb_get_guint8(tvb, offset + 6); 
3671                 proto_offset += proto_len + 3; 
3672                         
3673                 if ((proto_len > 0) && ppp_reorder) { 
3674                         
3675                         /* this part changes layout of GTP payload: 
3676                          * it swaps "length field" with "protocol header"  */ 
3677                         
3678                         ptr = (guint8 *)tvb_get_ptr(tvb, offset + 4, 3); 
3679                         
3680                         tmp = ptr[2]; 
3681                         ptr[2] = ptr[1]; 
3682                         ptr[1] = ptr[0]; 
3683                         ptr[0] = tmp; 
3684                                 
3685                         next_tvb = tvb_new_subset(tvb, offset + 5, proto_len + 2, proto_len + 2); 
3686
3687                         /* Save the current value of "pi", and adjust
3688                            certain fields to reflect the new top-level
3689                            tvbuff. */
3690                         save_pi = pi;
3691                         pi.compat_top_tvb = next_tvb;
3692                         pi.len = tvb_reported_length(next_tvb);
3693                         pi.captured_len = tvb_length(next_tvb);
3694
3695                         call_dissector(ppp_handle, next_tvb, pinfo, ext_tree_proto); 
3696
3697                         pi = save_pi;
3698                                 
3699                         if (check_col(pinfo->fd, COL_PROTOCOL)) col_set_str(pinfo->fd, COL_PROTOCOL, "GTP"); 
3700                                 
3701                         if (check_col(pinfo->fd, COL_INFO)) { 
3702                                         
3703                                 msg = tvb_get_guint8(tvb, 1); 
3704                                                 
3705                                 col_set_str(pinfo->fd, COL_INFO, val_to_str(msg, message_type, "Unknown")); 
3706                         } 
3707                 } 
3708         }
3709
3710         return 3 + length;
3711 }
3712
3713 /* GPRS:        9.60 v7.6.0, chapter 7.9.23
3714  * UMTS:        29.060 v4.0, chapter 7.7.32
3715  */
3716 static int
3717 decode_gtp_gsn_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3718         
3719         guint8          addr_type, addr_len;    
3720         guint16         length; 
3721         guint32         addr_ipv4;
3722         struct  e_in6_addr addr_ipv6;
3723         proto_tree      *ext_tree_gsn_addr;
3724         proto_item      *te;
3725         
3726         length = tvb_get_ntohs(tvb, offset+1);
3727         
3728         te = proto_tree_add_text(tree, tvb, offset, 3+length, "GSN address : ");
3729         ext_tree_gsn_addr = proto_item_add_subtree(te, ett_gtp_gsn_addr);
3730         
3731         switch (length) {
3732                 case 4:
3733                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length);
3734                         addr_ipv4 = tvb_get_letohl(tvb, offset+3);
3735                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
3736                         proto_tree_add_ipv4(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv4 : hf_gtpv0_gsn_ipv4, tvb, offset+3, 4, addr_ipv4);
3737                         break;
3738                 case 5:
3739                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
3740                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
3741                         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);
3742                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
3743                         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);
3744                         addr_ipv4 = tvb_get_letohl(tvb, offset+4);
3745                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
3746                         proto_tree_add_ipv4(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv4 : hf_gtpv0_gsn_ipv4, tvb, offset+4, 4, addr_ipv4);
3747                         break;
3748                 case 16:
3749                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length); 
3750                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
3751                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3752                         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);
3753                         break;
3754                 case 17: 
3755                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
3756                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
3757                         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);
3758                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
3759                         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);
3760                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+4, sizeof addr_ipv6);
3761                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3762                         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);
3763                         break;
3764                 default:
3765                         proto_item_append_text(te, "unknown type or wrong length");
3766                         break;
3767         }
3768         
3769         return 3+length;
3770 }
3771
3772 /* GPRS:        9.60 v7.6.0, chapter 7.9.24
3773  * UMTS:        29.060 v4.0, chapter 7.7.33
3774  */
3775 static int
3776 decode_gtp_msisdn(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3777                 
3778         const guint8    *msisdn_val;
3779         gchar           *msisdn_str;
3780         guint16         length;
3781         
3782         length = tvb_get_ntohs(tvb, offset+1);
3783         
3784         if (length < 1) return 3;
3785         
3786         msisdn_val = tvb_get_ptr(tvb, offset+3, length);
3787         msisdn_str = msisdn_to_str(msisdn_val, length);
3788         
3789         proto_tree_add_string(tree, gtp_version ? hf_gtpv1_msisdn : hf_gtpv0_msisdn, tvb, offset, 3+length, msisdn_str);
3790         
3791         return 3+length;
3792 }
3793
3794 /* GPRS:        not present
3795  * UMTS:        29.060 v4.0, chapter 7.7.34
3796  *              24.008 v4.2, chapter 10.5.6.5
3797  */
3798 static int
3799 decode_gtp_qos_umts(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3800
3801         return decode_qos_umts(tvb, offset+3, tree, "Quality of Service", 3);
3802 }
3803
3804 /* GPRS:        not present
3805  * UMTS:        29.060 v4.0, chapter 7.7.35
3806  */
3807 static int
3808 decode_gtp_auth_qui(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3809         
3810         return (1 + decode_quintuplet(tvb, offset+1, tree, 1, 1));
3811
3812 }
3813
3814 /* GPRS:        not present
3815  * UMTS:        29.060 v4.0, chapter 7.7.36
3816  *              24.008 v4.2, chapter 10.5.6.12
3817  */
3818 static int
3819 decode_gtp_tft(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3820
3821         guint16         length, port1, port2, tos;
3822         guint8          tft_code, no_packet_filters, i, pf_id, pf_eval, pf_len, pf_content_id, pf_offset, proto;
3823         guint32         addr_ipv4, ipsec_id, label;
3824         struct  e_in6_addr addr_ipv6;
3825         proto_tree      *ext_tree_tft, *ext_tree_tft_pf;
3826         proto_item      *te, *tee;
3827         
3828         length = tvb_get_ntohs(tvb, offset+1);
3829         
3830         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Traffic flow template");
3831         ext_tree_tft = proto_item_add_subtree(te, ett_gtp_tft);
3832         
3833         tft_code = (tvb_get_guint8(tvb, offset+3) >> 5) & 0x07;
3834         no_packet_filters = tvb_get_guint8(tvb, offset+3) & 0x0F;
3835         
3836         proto_tree_add_text(ext_tree_tft, tvb, offset+1, 2, "TFT length: %u", length);
3837         proto_tree_add_text(ext_tree_tft, tvb, offset+3, 1, "TFT operation code: %u", tft_code);
3838         proto_tree_add_text(ext_tree_tft, tvb, offset+3, 1, "Number of packet filters: %u", no_packet_filters); 
3839
3840         offset = offset + 4;
3841         
3842         for (i=0;i<no_packet_filters;i++) {
3843                 
3844                 pf_id = tvb_get_guint8(tvb, offset);
3845                 
3846                 tee = proto_tree_add_text(ext_tree_tft, tvb, offset, 1, "Packet filter id: %u", pf_id);
3847                 ext_tree_tft_pf = proto_item_add_subtree(tee, ett_gtp_tft_pf);
3848                 
3849                 if (tft_code != 2) {
3850                         
3851                         pf_eval = tvb_get_guint8(tvb, offset+1);
3852                         pf_len = tvb_get_guint8(tvb, offset+2);
3853                         
3854                         proto_tree_add_text(ext_tree_tft_pf, tvb, offset+1, 1, "Evaluation precedence: %u", pf_eval);
3855                         proto_tree_add_text(ext_tree_tft_pf, tvb, offset+2, 1, "Contents length: %u", pf_len);
3856
3857                         offset = offset + 3;
3858                         pf_offset = 0;  
3859                         
3860                         while (pf_offset < pf_len) {    
3861                                 
3862                                 pf_content_id = tvb_get_guint8(tvb, offset + pf_offset);
3863                                 
3864                                 switch (pf_content_id) {
3865                                         /* address IPv4 and mask = 8 bytes*/
3866                                         case 0x10: 
3867                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset, 1, "Address IPv4 and mask (0x10)");
3868                                                 addr_ipv4 = tvb_get_letohl(tvb, offset + pf_offset + 1);
3869                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\tAddress: %s", ip_to_str((guint8 *)&addr_ipv4));
3870                                                 addr_ipv4 = tvb_get_letohl(tvb, offset + pf_offset + 5); 
3871                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 5, 4, "\tNetmask: %s", ip_to_str((guint8 *)&addr_ipv4));
3872                                                 pf_offset = pf_offset + 9;
3873                                                 break;
3874                                         /* address IPv6 and mask = 32 bytes*/
3875                                         case 0x20: 
3876                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Address IPv6 and mask (0x20)");
3877                                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+pf_offset+1, sizeof addr_ipv6);
3878                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+offset+1, 16, "\tAddress: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3879                                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+pf_offset+17, sizeof addr_ipv6);
3880                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+offset+17, 16, "\tNetmask: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3881                                                 pf_offset = pf_offset + 33;
3882                                                 break;
3883                                         /* protocol identifier/next header type = 1 byte*/
3884                                         case 0x30:
3885                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset, 1, "IPv4 protocol identifier/IPv6 next header (0x30)");
3886                                                 proto = tvb_get_guint8(tvb, offset + pf_offset + 1);
3887                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 1, "\t%u", proto);
3888                                                 pf_offset = pf_offset + 2;
3889                                                 break;
3890                                         /* single destination port type = 2 bytes */
3891                                         case 0x40:
3892                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset, 1, "Destination port (0x40)");
3893                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3894                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 2, "\t%u", port1);
3895                                                 pf_offset = pf_offset + 3;
3896                                                 break;
3897                                         /* destination port range type = 4 bytes */
3898                                         case 0x41:
3899                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Destination port range (0x41)");
3900                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3901                                                 port2 = tvb_get_ntohs(tvb, offset + pf_offset + 3);
3902                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\t%u-%u", port1, port2);
3903                                                 pf_offset = pf_offset + 5;
3904                                                 break;
3905                                         /* single source port type = 2 bytes */
3906                                         case 0x50:
3907                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Source port (0x50)");
3908                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3909                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 2, "\t%u", port1);
3910                                                 pf_offset = pf_offset + 3;
3911                                                 break;
3912                                         /* source port range type = 4 bytes */
3913                                         case 0x51:
3914                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Source port range (0x51)");
3915                                                 port1 = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3916                                                 port2 = tvb_get_ntohs(tvb, offset + pf_offset + 3);
3917                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\t%u-%u", port1, port2);
3918                                                 pf_offset = pf_offset + 5;
3919                                                 break;
3920                                         /* security parameter index type = 4 bytes */
3921                                         case 0x60:
3922                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Security parameter index (0x60)");
3923                                                 ipsec_id = tvb_get_ntohl(tvb, offset + pf_offset + 1);
3924                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 4, "\t%x", ipsec_id);
3925                                                 pf_offset = pf_offset + 5;
3926                                                 break;
3927                                         /* type of service/traffic class type = 2 bytes */
3928                                         case 0x70:
3929                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Type of Service/Traffic Class (0x70)");
3930                                                 tos = tvb_get_ntohs(tvb, offset + pf_offset + 1);
3931                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 2, "\t%u", tos);
3932                                                 pf_offset = pf_offset + 3;
3933                                                 break;
3934                                         /* flow label type = 3 bytes */
3935                                         case 0x80:
3936                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset+pf_offset, 1, "Flow label (0x80)");
3937                                                 label = tvb_get_ntoh24(tvb, offset + pf_offset + 1) & 0x0FFFFF;;
3938                                                 proto_tree_add_text(ext_tree_tft_pf, tvb, offset + pf_offset + 1, 3, "\t%x", label);
3939                                                 pf_offset = pf_offset + 4;
3940                                                 break;
3941                                         
3942                                         default: 
3943                                                 break;
3944                                 }
3945                         }
3946                 }       
3947         }
3948         
3949         return 3 + length;
3950 }
3951
3952 /* GPRS:        not present
3953  * UMTS:        29.060 v4.0, chapter 7.7.37
3954  *              25.413 v3.4, chapter ???
3955  */
3956 static int
3957 decode_gtp_target_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3958
3959         guint16         length;
3960
3961         length = tvb_get_ntohs(tvb, offset + 1);
3962
3963         proto_tree_add_text(tree, tvb, offset, 3 + length, "Targer Identification");
3964         
3965         return 3 + length;
3966 }
3967
3968
3969 /* GPRS:        not present
3970  * UMTS:        29.060 v4.0, chapter 7.7.38
3971  */
3972 static int
3973 decode_gtp_utran_cont(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3974
3975         guint16         length;
3976
3977         length = tvb_get_ntohs(tvb, offset + 1);
3978
3979         proto_tree_add_text(tree, tvb, offset, 3 + length, "UTRAN transparent field");
3980
3981         return 3 + length;
3982
3983 }
3984         
3985
3986 /* GPRS:        not present
3987  * UMTS:        29.060 v4.0, chapter 7.7.39
3988  */
3989 static int
3990 decode_gtp_rab_setup(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3991
3992         guint32         teid, addr_ipv4;
3993         guint16         length;
3994         guint8          nsapi;
3995         struct  e_in6_addr addr_ipv6;
3996         proto_tree      *ext_tree_rab_setup;
3997         proto_item      *te;
3998         
3999         length = tvb_get_ntohs(tvb, offset + 1);
4000         nsapi = tvb_get_guint8(tvb, offset + 3) & 0x0F;
4001
4002         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Radio Access Bearer Setup Information");
4003         ext_tree_rab_setup = proto_item_add_subtree(te, ett_gtp_rab_setup);
4004
4005         proto_tree_add_text(ext_tree_rab_setup, tvb, offset+1, 2, "RAB setup length : %u", length);
4006         proto_tree_add_uint(ext_tree_rab_setup, hf_gtpv1_nsapi, tvb, offset+3, 1, nsapi);
4007
4008         if (length > 1) {
4009                 
4010                 teid = tvb_get_ntohl(tvb, offset + 4);
4011
4012                 proto_tree_add_uint(ext_tree_rab_setup, hf_gtpv1_teid_data, tvb, offset+4, 4, teid);
4013         
4014                 switch (length) {
4015                         case 12:
4016                                 addr_ipv4 = tvb_get_letohl(tvb, offset + 8);
4017                                 proto_tree_add_ipv4(ext_tree_rab_setup, hf_gtpv1_rnc_ipv4, tvb, offset+8, 4, addr_ipv4);
4018                                 break;
4019                         case 24: 
4020                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+8, sizeof addr_ipv6);
4021                                 proto_tree_add_ipv6(ext_tree_rab_setup, hf_gtpv1_rnc_ipv6, tvb, offset+8, 16, (guint8 *)&addr_ipv6);
4022                                 break;
4023                         default:
4024                                 break;
4025                 }
4026         }
4027
4028         return 3 + length;
4029 }
4030
4031
4032 /* GPRS:        not present
4033  * UMTS:        29.060 v4.0, chapter 7.7.40
4034  */
4035 static int
4036 decode_gtp_hdr_list(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4037
4038         int             i;
4039         guint8          length, hdr;
4040         proto_tree      *ext_tree_hdr_list;
4041         proto_item      *te;
4042         
4043         length = tvb_get_guint8(tvb, offset + 1);
4044
4045         te = proto_tree_add_text(tree, tvb, offset, 2+length, "%s", val_to_str(GTP_EXT_HDR_LIST, gtp_val, "Unknown"));
4046         ext_tree_hdr_list = proto_item_add_subtree(te, ett_gtp_hdr_list);
4047         
4048         proto_tree_add_text(ext_tree_hdr_list, tvb, offset+1, 1, "Number of Extension Header Types in list (i.e., length) : %u", length);
4049
4050         for(i=0 ; i<length ; i++) {
4051                 hdr = tvb_get_guint8(tvb, offset+2+i);
4052
4053                 proto_tree_add_text(ext_tree_hdr_list, tvb, offset+2+i, 1, "N°%u --> Extension Header Type value : %s (%u)", i+1, val_to_str(hdr, gtp_val, "Unknown Extension Header Type"), hdr);
4054         }
4055
4056         return 2 + length;
4057 }
4058
4059 /* GPRS:        not present
4060  * UMTS:        29.060 v4.0, chapter 7.7.41
4061  * TODO:        find TriggerID description
4062  */
4063 static int
4064 decode_gtp_trigger_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4065
4066         guint16         length;
4067
4068         length = tvb_get_ntohs(tvb, offset + 1);
4069
4070         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_TRIGGER_ID, gtp_val, "Unknown"), length);
4071
4072         return 3 + length;
4073
4074 }
4075
4076 /* GPRS:        not present
4077  * UMTS:        29.060 v4.0, chapter 7.7.42
4078  * TODO:        find OMC-ID description
4079  */
4080 static int
4081 decode_gtp_omc_id(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4082
4083         guint16         length;
4084
4085         length = tvb_get_ntohs(tvb, offset + 1);
4086
4087         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_OMC_ID, gtp_val, "Unknown"), length);
4088
4089         return 3 + length;
4090
4091 }
4092
4093 /* GPRS:        9.60 v7.6.0, chapter 7.9.25
4094  * UMTS:        29.060 v4.0, chapter 7.7.43
4095  */
4096 static int
4097 decode_gtp_chrg_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4098                 
4099         guint16         length; 
4100         guint32         addr_ipv4;
4101         struct  e_in6_addr addr_ipv6;
4102         proto_tree      *ext_tree_chrg_addr;
4103         proto_item      *te;
4104         
4105         length = tvb_get_ntohs(tvb, offset+1);
4106         
4107         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_CHRG_ADDR, gtp_val, "Unknown"));
4108         ext_tree_chrg_addr = proto_item_add_subtree(te, ett_gtp_chrg_addr);
4109         
4110         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);
4111         
4112         switch (length) {
4113                 case 4:
4114                         addr_ipv4 = tvb_get_letohl(tvb, offset+3);
4115                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4116                         proto_tree_add_ipv4(ext_tree_chrg_addr, gtp_version ? hf_gtpv1_chrg_ipv4 : hf_gtpv0_chrg_ipv4, tvb, offset+3, 4, addr_ipv4);
4117                         break;
4118                 case 16: 
4119                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
4120                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4121                         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);
4122                         break;
4123                 default:
4124                         proto_item_append_text(te, "unknown type or wrong length");
4125                         break;
4126         }
4127
4128         return 3 + length;
4129 }
4130
4131 /* GPRS:        12.15
4132  * UMTS:        33.015
4133  */
4134 static int
4135 decode_gtp_rel_pack(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4136         
4137         guint16         length, n, number;
4138         proto_tree      *ext_tree_rel_pack;
4139         proto_item      *te;
4140
4141         length = tvb_get_ntohs(tvb, offset + 1);
4142         
4143         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of released packets IE");
4144         ext_tree_rel_pack = proto_item_add_subtree(te, ett_gtp_rel_pack);
4145         
4146         n = 0;
4147         
4148         while (n < length) {
4149
4150                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4151                 proto_tree_add_text(ext_tree_rel_pack, tvb, offset + 3 + n, 2, "%u", number);
4152                 n = n + 2;
4153
4154         }
4155         
4156         return 3 + length;
4157 }
4158
4159 /* GPRS:        12.15
4160  * UMTS:        33.015
4161  */
4162 static int
4163 decode_gtp_can_pack(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4164         
4165         guint16         length, n, number;
4166         proto_tree      *ext_tree_can_pack;
4167         proto_item      *te;
4168
4169         length = tvb_get_ntohs(tvb, offset + 1);
4170         
4171         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of cancelled  packets IE");
4172         ext_tree_can_pack = proto_item_add_subtree(te, ett_gtp_can_pack);
4173         
4174         n = 0;
4175         
4176         while (n < length) {
4177
4178                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4179                 proto_tree_add_text(ext_tree_can_pack, tvb, offset + 3 + n, 2, "%u", number);
4180                 n = n + 2;
4181
4182         }
4183         
4184         return 3 + length;
4185 }
4186
4187 /* CDRs dissector */
4188 static int
4189 decode_gtp_data_req(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4190         
4191         guint16         length, format_ver, data_len, i, j;
4192         guint8          no, format, rectype;
4193         proto_tree      *ext_tree, *cdr_tree;
4194         proto_item      *te, *ce;
4195
4196         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_DATA_REQ, gtp_val, "Unknown message"));
4197         ext_tree = proto_item_add_subtree(te, ett_gtp_ext);
4198         
4199         length = tvb_get_ntohs(tvb, offset + 1);
4200         no = tvb_get_guint8(tvb, offset + 3);
4201         format = tvb_get_guint8(tvb, offset + 4);
4202         format_ver = tvb_get_ntohs(tvb, offset + 5);
4203         
4204         proto_tree_add_text(ext_tree, tvb, offset+1, 2, "Length: %u", length);
4205         proto_tree_add_text(ext_tree, tvb, offset+3, 1, "Number of data records: %u", no);
4206         proto_tree_add_text(ext_tree, tvb, offset+4, 1, "Data record format: %u", format);
4207         proto_tree_add_text(ext_tree, tvb, offset+5, 2, "Data record format version: %u", format_ver);
4208
4209         data_len = 0;
4210         offset = offset + 7;
4211
4212         if (gtpv0_cdr_as != DONT_DISSECT_CDRS) {
4213         
4214         for (i = 0; i < no; i++) {
4215                 data_len = tvb_get_ntohs(tvb, offset);
4216                 rectype = tvb_get_guint8(tvb, offset+2);
4217                 switch (rectype) {
4218                         case 0x13:              /* GCDR */ 
4219                                 if (tvb_length_remaining(tvb, offset) < 3 + 118) {
4220                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "GCDR fragmented, can't dissect");
4221                                         break;
4222                                 }
4223                                 
4224                                 tvb_memcpy(tvb, gcdr.imsi, offset+3, 8);        
4225                                 gcdr.ggsnaddr = tvb_get_letohl(tvb, offset+11);
4226                                 gcdr.chrgid = tvb_get_ntohl(tvb, offset+15);
4227                                 gcdr.sgsnaddr = tvb_get_letohl(tvb, offset+19);
4228                                 tvb_memcpy(tvb, gcdr.apn, offset+23, 63);
4229                                 gcdr.pdporg = tvb_get_guint8(tvb, offset+86);
4230                                 gcdr.pdptype = tvb_get_guint8(tvb, offset+87);
4231                                 gcdr.pdpaddr = tvb_get_letohl(tvb, offset+88);
4232                                 gcdr.addrflag = tvb_get_guint8(tvb, offset+92);
4233                                 gcdr.uplink = tvb_get_ntohl(tvb, offset+96);
4234                                 gcdr.downlink = tvb_get_ntohl(tvb, offset+100);
4235                                 gcdr.timestamp = tvb_get_ntohl(tvb, offset+104);
4236                                 gcdr.opening = tvb_get_ntohl(tvb, offset+108);
4237                                 gcdr.duration = tvb_get_ntohl(tvb, offset+112);
4238                                 gcdr.closecause = tvb_get_guint8(tvb, offset+116);
4239                                 gcdr.seqno = tvb_get_ntohl(tvb, offset+117);
4240                                 
4241                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "GCDR (0x13), sequence number: %u", gcdr.seqno);
4242                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4243                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4244                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4245                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 8, "IMSI: %s", id_to_str(gcdr.imsi));
4246                                 proto_tree_add_text(cdr_tree, tvb, offset+11, 4, "GGSN address: %s", ip_to_str((guint8 *)&gcdr.ggsnaddr));
4247                                 proto_tree_add_text(cdr_tree, tvb, offset+15, 4, "Charging ID: %x", gcdr.chrgid);
4248                                 proto_tree_add_text(cdr_tree, tvb, offset+19, 4, "SGSN address: %s", ip_to_str((guint8 *)&gcdr.sgsnaddr));
4249                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 63, "APN: %s", gcdr.apn);
4250                                 proto_tree_add_text(cdr_tree, tvb, offset+86, 1, "PDP org: %s", val_to_str(gcdr.pdporg, pdp_org_type, "Unknown PDP org"));
4251                                 proto_tree_add_text(cdr_tree, tvb, offset+87, 1, "PDP type: %s", val_to_str(gcdr.pdptype, pdp_type, "Unknown PDP type"));
4252                                 proto_tree_add_text(cdr_tree, tvb, offset+88, 4, "PDP address: %s", ip_to_str((guint8 *)&gcdr.pdpaddr));
4253                                 proto_tree_add_text(cdr_tree, tvb, offset+92, 1, "PDP address type: %u", gcdr.addrflag);
4254                                 decode_qos_gprs(tvb, offset+93, cdr_tree, "QoS", 0);
4255                                 proto_tree_add_text(cdr_tree, tvb, offset+96, 4, "Uplink volume: %u", gcdr.uplink);
4256                                 proto_tree_add_text(cdr_tree, tvb, offset+100, 4, "Downlink volume: %u", gcdr.downlink);
4257                                 proto_tree_add_text(cdr_tree, tvb, offset+104, 4, "Timestamp: %s", time_int_to_str(gcdr.timestamp));
4258                                 proto_tree_add_text(cdr_tree, tvb, offset+108, 4, "Record opening time: %s", time_int_to_str(gcdr.opening));
4259                                 proto_tree_add_text(cdr_tree, tvb, offset+112, 4, "Duration: %s", time_int_to_str(gcdr.duration));
4260                                 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);
4261                                 proto_tree_add_text(cdr_tree, tvb, offset+117, 4, "Sequence number: %u", gcdr.seqno);
4262                                 
4263                                 if (data_len > 119) {
4264                                         proto_tree_add_text(cdr_tree, tvb, offset+121, 8, "MSISDN: ");
4265                                 }
4266                                         
4267                                 break;
4268
4269                         case 0x12:              /* SCDR */
4270                                 if (tvb_length_remaining(tvb, offset) < 3 + 277) {
4271                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "SCDR fragmented, can't dissect");
4272                                         break;
4273                                 }
4274                                 
4275                                 scdr.len = tvb_get_letohs(tvb, offset+3);
4276                                 scdr.netini = tvb_get_guint8(tvb, offset+5);
4277                                 scdr.anon = tvb_get_guint8(tvb, offset+6);
4278                                 scdr.imsilen = tvb_get_guint8(tvb, offset+7);
4279                                 tvb_memcpy(tvb, scdr.imsi, offset+8, 8);
4280                                 tvb_memcpy(tvb, scdr.imei, offset+16, 8);
4281                                 scdr.msisdnlen = tvb_get_guint8(tvb, offset+24);
4282                                 tvb_memcpy(tvb, scdr.msisdn, offset+25, 10);
4283                                 scdr.sgsnaddr = tvb_get_letohl(tvb, offset+35);
4284                                 tvb_memcpy(tvb, scdr.msclass_notused, offset+39, 12);
4285                                 scdr.msclass_caplen = tvb_get_guint8(tvb, offset+51);
4286                                 scdr.msclass_cap = tvb_get_guint8(tvb, offset+52);
4287                                 scdr.msclass_capomit = tvb_get_ntohs(tvb, offset+53);
4288                                 scdr.lac = tvb_get_ntohs(tvb, offset+55);
4289                                 scdr.rac = tvb_get_guint8(tvb, offset+57);
4290                                 scdr.cid = tvb_get_ntohs(tvb, offset+58);
4291                                 scdr.chrgid = tvb_get_ntohl(tvb, offset+60);
4292                                 scdr.ggsnaddr = tvb_get_letohl(tvb, offset+64);
4293                                 tvb_memcpy(tvb, scdr.apn, offset+68, 64);
4294                                 scdr.pdporg = tvb_get_guint8(tvb, offset+132);
4295                                 scdr.pdptype = tvb_get_guint8(tvb, offset+133);
4296                                 scdr.pdpaddr = tvb_get_letohl(tvb, offset+134);
4297                                 scdr.listind = tvb_get_guint8(tvb, offset+138);
4298                                 for (j=0;j<4;j++) {
4299                                         scdr.change[j].change = tvb_get_guint8(tvb, offset+139+23*j);
4300                                         scdr.change[j].time1 = tvb_get_ntohl(tvb, offset+140+23*j);
4301                                         scdr.change[j].time2 = tvb_get_ntohl(tvb, offset+144+23*j);
4302                                         scdr.change[j].uplink = tvb_get_ntohl(tvb, offset+148+23*j);
4303                                         scdr.change[j].downlink = tvb_get_ntohl(tvb, offset+152+23*j);
4304 /*                                      tvb_memcpy(tvb, scdr.change[j].qos_req, offset+156+23*j, 3);
4305                                         tvb_memcpy(tvb, scdr.change[j].qos_neg, offset+159+23*j, 3);*/
4306                                 }
4307                                 scdr.timestamp = tvb_get_ntohl(tvb, offset+254);
4308                                 scdr.opening = tvb_get_ntohl(tvb, offset+258);
4309                                 scdr.duration = tvb_get_ntohl(tvb, offset+262);
4310                                 scdr.sgsnchange = tvb_get_guint8(tvb, offset+266);
4311                                 scdr.closecause = tvb_get_guint8(tvb, offset+267);
4312                                 scdr.diag1 = tvb_get_guint8(tvb, offset+268);
4313                                 scdr.diag2 = tvb_get_guint8(tvb, offset+269);
4314                                 scdr.diag3 = tvb_get_guint8(tvb, offset+270);
4315                                 scdr.diag4 = tvb_get_guint8(tvb, offset+271);
4316                                 scdr.diag5 = tvb_get_ntohl(tvb, offset+272);
4317                                 scdr.seqno = tvb_get_ntohl(tvb, offset+276);
4318
4319                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "SCDR (type %x), sequence number: %u", rectype, scdr.seqno);
4320                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4321                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4322                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4323                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "CDR length: %u", scdr.len);
4324                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "Network initiated PDP context: %s", yesno[scdr.netini]);
4325                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 1, "Anonymous acces: %s", yesno[scdr.anon]);
4326                                 proto_tree_add_text(cdr_tree, tvb, offset+7, 1, "IMSI length: %u", scdr.imsilen);
4327                                 proto_tree_add_text(cdr_tree, tvb, offset+8, 8, "IMSI: %s", id_to_str(scdr.imsi));
4328                                 proto_tree_add_text(cdr_tree, tvb, offset+16, 8, "IMEI: %s", id_to_str(scdr.imei));
4329                                 proto_tree_add_text(cdr_tree, tvb, offset+24, 1, "MSISDN length: %u", scdr.msisdnlen);
4330                                 proto_tree_add_text(cdr_tree, tvb, offset+25, 10, "MSISDN: %s", msisdn_to_str(scdr.msisdn, 10));
4331                                 proto_tree_add_text(cdr_tree, tvb, offset+35, 4, "SGSN address: %s", ip_to_str((guint8 *)&scdr.sgsnaddr));
4332                                 proto_tree_add_text(cdr_tree, tvb, offset+39, 12, "(not used)");
4333                                 proto_tree_add_text(cdr_tree, tvb, offset+51, 1, "MS network capability length: %u", scdr.msclass_caplen);
4334                                 
4335 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+52, 1, "MS network capability: %u", scdr.msclass_cap);
4336                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4337                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+52, 1, scdr.cap);
4338                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+52, 1, scdr.cap);
4339                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+52, 1, scdr.cap);
4340                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+52, 1, scdr.cap);
4341                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+52, 1, scdr.cap);
4342                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+52, 1, scdr.cap);
4343                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_pad, tvb, offset+52, 1, scdr.cap);
4344 */
4345
4346                                 proto_tree_add_text(cdr_tree, tvb, offset+53, 2, "MS network capability omitted: %u", scdr.msclass_capomit);
4347                                 proto_tree_add_text(cdr_tree, tvb, offset+55, 2, "LAC: %u", scdr.lac);
4348                                 proto_tree_add_text(cdr_tree, tvb, offset+57, 1, "RAC: %u", scdr.rac);
4349                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 2, "Cell ID: %u", scdr.cid);
4350                                 proto_tree_add_text(cdr_tree, tvb, offset+60, 4, "Charging ID: %x", scdr.chrgid);
4351                                 proto_tree_add_text(cdr_tree, tvb, offset+64, 4, "GGSN address: %s", ip_to_str((guint8 *)&scdr.ggsnaddr));
4352                                 proto_tree_add_text(cdr_tree, tvb, offset+68, 64, "APN: %s", scdr.apn);
4353                                 proto_tree_add_text(cdr_tree, tvb, offset+132, 1, "PDP org: %s", val_to_str(scdr.pdporg, pdp_org_type, "Unknown PDP org"));
4354                                 proto_tree_add_text(cdr_tree, tvb, offset+133, 1, "PDP type: %s", val_to_str(scdr.pdptype, pdp_type, "Unknown PDP type"));
4355                                 proto_tree_add_text(cdr_tree, tvb, offset+134, 4, "PDP address: %s", ip_to_str((guint8 *)&scdr.pdpaddr));
4356                                 proto_tree_add_text(cdr_tree, tvb, offset+138, 1, "List of data volume index: %u", scdr.listind);
4357                                 for (j=0;j<4;j++) {
4358                                         proto_tree_add_text(cdr_tree, tvb, offset+139+23*j, 1, "List of data vol change condition: %u", scdr.change[j].change);
4359                                         proto_tree_add_text(cdr_tree, tvb, offset+140+23*j, 4, "Time1: %x", scdr.change[j].time1);
4360                                         proto_tree_add_text(cdr_tree, tvb, offset+144+23*j, 4, "Time2: %x", scdr.change[j].time2);
4361                                         proto_tree_add_text(cdr_tree, tvb, offset+148+23*j, 4, "Uplink: %x", scdr.change[j].uplink);
4362                                         proto_tree_add_text(cdr_tree, tvb, offset+152+23*j, 4, "Downlink: %x", scdr.change[j].downlink);
4363                                         decode_qos_gprs(tvb, offset+156, cdr_tree, "QoS requested", 0);
4364                                         decode_qos_gprs(tvb, offset+159, cdr_tree, "QoS negotiated", 0);
4365                                 }       
4366                                 proto_tree_add_text(cdr_tree, tvb, offset+254, 4, "Timestamp: %s", time_int_to_str(scdr.timestamp));
4367                                 proto_tree_add_text(cdr_tree, tvb, offset+258, 4, "Opening: %s", time_int_to_str(scdr.opening));
4368                                 proto_tree_add_text(cdr_tree, tvb, offset+262, 4, "Duration: %s", time_int_to_str(scdr.duration));
4369                                 proto_tree_add_text(cdr_tree, tvb, offset+266, 1, "SGSN change: %u", scdr.sgsnchange);
4370                                 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);
4371                                 proto_tree_add_text(cdr_tree, tvb, offset+268, 1, "Diagnostics 1: %u", scdr.diag1);
4372                                 proto_tree_add_text(cdr_tree, tvb, offset+269, 1, "Diagnostics 2: %u", scdr.diag2);
4373                                 proto_tree_add_text(cdr_tree, tvb, offset+270, 1, "Diagnostics 3: %u", scdr.diag3);
4374                                 proto_tree_add_text(cdr_tree, tvb, offset+271, 1, "Diagnostics 4: %u", scdr.diag4);
4375                                 proto_tree_add_text(cdr_tree, tvb, offset+272, 4, "Diagnostics 5: %u", scdr.diag5);
4376                                 proto_tree_add_text(cdr_tree, tvb, offset+276, 4, "Sequence number: %u", scdr.seqno);
4377                                 break;
4378                         case 0x14:              /* MCDR */
4379                                 if (tvb_length_remaining(tvb, offset) < 3 + 147) {
4380                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "MCDR fragmented, can't dissect");
4381                                         break;
4382                                 }
4383
4384                                 mcdr.len = tvb_get_ntohs(tvb, offset+3);
4385                                 mcdr.imsilen = tvb_get_guint8(tvb, offset+5);
4386                                 tvb_memcpy(tvb, mcdr.imsi, offset+6, 8);
4387                                 tvb_memcpy(tvb, mcdr.imei, offset+14, 8);
4388                                 mcdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4389                                 tvb_memcpy(tvb, mcdr.msisdn, offset+23, 10);
4390                                 mcdr.sgsnaddr = tvb_get_letohl(tvb, offset+33);
4391                                 tvb_memcpy(tvb, mcdr.msclass_notused, offset+37, 12);
4392                                 mcdr.msclass_caplen = tvb_get_guint8(tvb, offset+49);
4393                                 mcdr.msclass_cap = tvb_get_guint8(tvb, offset+50);
4394                                 mcdr.msclass_capomit = tvb_get_ntohs(tvb, offset+51);
4395                                 mcdr.lac = tvb_get_ntohs(tvb, offset+53);
4396                                 mcdr.rac = tvb_get_guint8(tvb, offset+55);
4397                                 mcdr.cid = tvb_get_ntohs(tvb, offset+56);
4398                                 mcdr.change_count = tvb_get_guint8(tvb, offset+58);
4399                                 for (j=0;j<4;j++) {
4400                                         mcdr.change[j].lac = tvb_get_ntohs(tvb, offset+59+13*j);
4401                                         mcdr.change[j].rac = tvb_get_guint8(tvb, offset+61+13*j);
4402                                         mcdr.change[j].cid = tvb_get_ntohs(tvb, offset+62+13*j);
4403                                         tvb_memcpy(tvb, mcdr.change[j].omit, offset+64+13*j, 8);
4404                                 }
4405                                 mcdr.timestamp = tvb_get_ntohl(tvb, offset+124);
4406                                 mcdr.opening = tvb_get_ntohl(tvb, offset+128);
4407                                 mcdr.duration = tvb_get_ntohl(tvb, offset+132);
4408                                 mcdr.sgsnchange = tvb_get_guint8(tvb, offset+136);
4409                                 mcdr.closecause = tvb_get_guint8(tvb, offset+137);
4410                                 mcdr.diag1 = tvb_get_guint8(tvb, offset+138);
4411                                 mcdr.diag2 = tvb_get_guint8(tvb, offset+139);
4412                                 mcdr.diag3 = tvb_get_guint8(tvb, offset+140);
4413                                 mcdr.diag4 = tvb_get_guint8(tvb, offset+141);
4414                                 mcdr.diag5 = tvb_get_ntohl(tvb, offset+142);
4415                                 mcdr.seqno = tvb_get_ntohl(tvb, offset+146);
4416
4417                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "MCDR (0x14), sequence number: %u", mcdr.seqno);
4418                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4419                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4420                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4421                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", mcdr.len);
4422                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", mcdr.imsilen);
4423                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(mcdr.imsi));
4424                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(mcdr.imei));
4425                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", mcdr.msisdnlen);
4426                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(mcdr.msisdn, 10));
4427                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 4, "SGSN address: %s", ip_to_str((guint8 *)&mcdr.sgsnaddr));
4428                                 proto_tree_add_text(cdr_tree, tvb, offset+37, 12, "(not used)");
4429                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 1, "MS network capability length: %u", mcdr.msclass_caplen);
4430                                 
4431 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+50, 1, "MS network capability: %u", mcdr.msclass_cap);
4432                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4433                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+50, 1, mcdr.cap);
4434                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+50, 1, mcdr.cap);
4435                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+50, 1, mcdr.cap);
4436                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+50, 1, mcdr.cap);
4437                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+50, 1, mcdr.cap);
4438                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+50, 1, mcdr.cap);
4439                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_pad, tvb, offset+50, 1, mcdr.cap);
4440 */
4441                                 proto_tree_add_text(cdr_tree, tvb, offset+51, 2, "MS network capability omitted: %u", mcdr.msclass_capomit);
4442                                 proto_tree_add_text(cdr_tree, tvb, offset+53, 2, "LAC: %u", mcdr.lac);
4443                                 proto_tree_add_text(cdr_tree, tvb, offset+55, 1, "RAC: %u", mcdr.rac);
4444                                 proto_tree_add_text(cdr_tree, tvb, offset+56, 2, "Cell ID: %u", mcdr.cid);
4445                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 1, "List of data volume changes: %u", mcdr.change_count);
4446                                 for (j=0;j<4;j++) {
4447                                         proto_tree_add_text(cdr_tree, tvb, offset+59+13*j, 2, "LAC: %u", mcdr.change[j].lac);
4448                                         proto_tree_add_text(cdr_tree, tvb, offset+61+13*j, 1, "RAC: %u", mcdr.change[j].rac);
4449                                         proto_tree_add_text(cdr_tree, tvb, offset+62+13*j, 2, "CID: %u", mcdr.change[j].cid);
4450                                         proto_tree_add_text(cdr_tree, tvb, offset+64+13*j, 8, "(omitted)");
4451                                 }
4452
4453                                 proto_tree_add_text(cdr_tree, tvb, offset+124, 4, "Timestamp: %s", time_int_to_str(mcdr.timestamp));
4454                                 proto_tree_add_text(cdr_tree, tvb, offset+128, 4, "Record opening time: %s", time_int_to_str(mcdr.opening));
4455                                 proto_tree_add_text(cdr_tree, tvb, offset+132, 4, "Duration: %s", time_int_to_str(mcdr.duration));
4456                                 proto_tree_add_text(cdr_tree, tvb, offset+136, 1, "SGSN change: %u", mcdr.sgsnchange);
4457                                 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);
4458                                 proto_tree_add_text(cdr_tree, tvb, offset+138, 1, "Diagnostics 1: %u", mcdr.diag1);
4459                                 proto_tree_add_text(cdr_tree, tvb, offset+139, 1, "Diagnostics 2: %u", mcdr.diag2);
4460                                 proto_tree_add_text(cdr_tree, tvb, offset+140, 1, "Diagnostics 3: %u", mcdr.diag3);
4461                                 proto_tree_add_text(cdr_tree, tvb, offset+141, 1, "Diagnostics 4: %u", mcdr.diag4);
4462                                 proto_tree_add_text(cdr_tree, tvb, offset+142, 4, "Diagnostics 5: %u", mcdr.diag5);
4463                                 proto_tree_add_text(cdr_tree, tvb, offset+146, 4, "Sequence number: %u", mcdr.seqno);
4464                                 break;
4465
4466                         case 0x15:              /* SOCDR */
4467                                 if (tvb_length_remaining(tvb, offset) < 3 + 80) {
4468                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "SOCDR fragmented, can't dissect");
4469                                         break;
4470                                 }
4471
4472                                 socdr.len = tvb_get_ntohs(tvb, offset+3);
4473                                 socdr.imsilen = tvb_get_guint8(tvb, offset+5);
4474                                 tvb_memcpy(tvb, socdr.imsi, offset+6, 8);
4475                                 tvb_memcpy(tvb, socdr.imei, offset+14, 8);
4476                                 socdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4477                                 tvb_memcpy(tvb, socdr.msisdn, offset+23, 10);
4478                                 tvb_memcpy(tvb, socdr.msclass_notused, offset+33, 12);
4479                                 socdr.msclass_caplen = tvb_get_guint8(tvb, offset+45);
4480                                 socdr.msclass_cap = tvb_get_guint8(tvb, offset+46);
4481                                 socdr.msclass_capomit = tvb_get_ntohs(tvb, offset+47);
4482                                 tvb_memcpy(tvb, socdr.serv_centr, offset+49, 9);
4483                                 tvb_memcpy(tvb, socdr.rec_ent, offset+58, 9);
4484                                 socdr.lac = tvb_get_ntohs(tvb, offset+67);
4485                                 socdr.rac = tvb_get_guint8(tvb, offset+69);
4486                                 socdr.cid = tvb_get_ntohs(tvb, offset+70);
4487                                 socdr.time1 = tvb_get_ntohl(tvb, offset+72);
4488                                 socdr.time2 = tvb_get_ntohl(tvb, offset+76);
4489                                 socdr.messref = tvb_get_guint8(tvb, offset+80);
4490                                 socdr.smsres = tvb_get_ntohs(tvb, offset+81);
4491
4492                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "SOCDR (0x15)");
4493                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4494                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4495                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4496                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", socdr.len);
4497                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", socdr.imsilen);
4498                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(socdr.imsi));
4499                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(socdr.imei));
4500                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", socdr.msisdnlen);
4501                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(socdr.msisdn, 10));
4502                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 12, "(not used)");
4503                                 proto_tree_add_text(cdr_tree, tvb, offset+45, 1, "MS network capability length: %u", socdr.msclass_caplen);
4504                                 
4505 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+46, 1, "MS network capability: %u", socdr.msclass_cap);
4506                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4507                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+46, 1, socdr.cap);
4508                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+46, 1, socdr.cap);
4509                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+46, 1, socdr.cap);
4510                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+46, 1, socdr.cap);
4511                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+46, 1, socdr.cap);
4512                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+46, 1, socdr.cap);
4513 */
4514                                 proto_tree_add_text(cdr_tree, tvb, offset+47, 2, "MS network capability omitted: %u", stcdr.msclass_capomit);
4515                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 9, "SMSC E.164 address: %s", msisdn_to_str(socdr.serv_centr, 9));
4516                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 9, "SGSN E.164 address: %s", msisdn_to_str(socdr.rec_ent, 9));
4517                                 proto_tree_add_text(cdr_tree, tvb, offset+67, 2, "LAC: %u", socdr.lac);
4518                                 proto_tree_add_text(cdr_tree, tvb, offset+69, 1, "RAC: %u", socdr.rac);
4519                                 proto_tree_add_text(cdr_tree, tvb, offset+70, 2, "Cell ID: %u", socdr.cid);
4520                                 proto_tree_add_text(cdr_tree, tvb, offset+72, 4, "Time1: %s", time_int_to_str(socdr.time1));
4521                                 proto_tree_add_text(cdr_tree, tvb, offset+76, 4, "Time2: %s", time_int_to_str(socdr.time2));
4522                                 proto_tree_add_text(cdr_tree, tvb, offset+80, 1, "Message reference: %u", socdr.messref);
4523                                 proto_tree_add_text(cdr_tree, tvb, offset+81, 2, "Delivery result: %u", socdr.smsres);
4524                                 break;
4525
4526                         case 0x16:              /* STCDR */
4527                                 if (tvb_length_remaining(tvb, offset) < 3 + 79) {
4528                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "STCDR fragmented, can't dissect");
4529                                         break;
4530                                 }
4531
4532                                 stcdr.len = tvb_get_ntohs(tvb, offset+3);
4533                                 stcdr.imsilen = tvb_get_guint8(tvb, offset+5);
4534                                 tvb_memcpy(tvb, stcdr.imsi, offset+6, 8);
4535                                 tvb_memcpy(tvb, stcdr.imei, offset+14, 8);
4536                                 stcdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4537                                 tvb_memcpy(tvb, stcdr.msisdn, offset+23, 10);
4538                                 tvb_memcpy(tvb, stcdr.msclass_notused, offset+33, 12);
4539                                 stcdr.msclass_caplen = tvb_get_guint8(tvb, offset+45);
4540                                 stcdr.msclass_cap = tvb_get_guint8(tvb, offset+46);
4541                                 stcdr.msclass_capomit = tvb_get_ntohs(tvb, offset+47);
4542                                 tvb_memcpy(tvb, stcdr.serv_centr, offset+49, 9);
4543                                 tvb_memcpy(tvb, stcdr.rec_ent, offset+58, 9);
4544                                 stcdr.lac = tvb_get_ntohs(tvb, offset+67);
4545                                 stcdr.rac = tvb_get_guint8(tvb, offset+69);
4546                                 stcdr.cid = tvb_get_ntohs(tvb, offset+70);
4547                                 stcdr.time1 = tvb_get_ntohl(tvb, offset+72);
4548                                 stcdr.time2 = tvb_get_ntohl(tvb, offset+76);
4549                                 stcdr.smsres = tvb_get_ntohs(tvb, offset+80);
4550
4551                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "STCDR (0x16)");
4552                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4553                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4554                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4555                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", stcdr.len);
4556                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", stcdr.imsilen);
4557                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(stcdr.imsi));
4558                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(stcdr.imei));
4559                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", stcdr.msisdnlen);
4560                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(stcdr.msisdn, 10));
4561                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 12, "(not used)");
4562                                 proto_tree_add_text(cdr_tree, tvb, offset+45, 1, "MS network capability length: %u", stcdr.msclass_caplen);
4563                                 
4564 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+46, 1, "MS network capability: %u", stcdr.msclass_cap);
4565                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4566                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+46, 1, stcdr.cap);
4567                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+46, 1, stcdr.cap);
4568                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+46, 1, stcdr.cap);
4569                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+46, 1, stcdr.cap);
4570                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+46, 1, stcdr.cap);
4571                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+46, 1, stcdr.cap);
4572 */
4573                                 proto_tree_add_text(cdr_tree, tvb, offset+47, 2, "MS network capability omitted: %u", stcdr.msclass_capomit);
4574                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 9, "SMSC E.164 address: %s", msisdn_to_str(stcdr.serv_centr, 9));
4575                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 9, "SGSN E.164 address: %s", msisdn_to_str(stcdr.rec_ent, 9));
4576                                 proto_tree_add_text(cdr_tree, tvb, offset+67, 2, "LAC: %u", stcdr.lac);
4577                                 proto_tree_add_text(cdr_tree, tvb, offset+69, 1, "RAC: %u", stcdr.rac);
4578                                 proto_tree_add_text(cdr_tree, tvb, offset+70, 2, "Cell ID: %u", stcdr.cid);
4579                                 proto_tree_add_text(cdr_tree, tvb, offset+72, 4, "Time1: %s", time_int_to_str(stcdr.time1));
4580                                 proto_tree_add_text(cdr_tree, tvb, offset+76, 4, "Time2: %s", time_int_to_str(stcdr.time2));
4581                                 proto_tree_add_text(cdr_tree, tvb, offset+80, 2, "Delivery result: %u", stcdr.smsres);
4582                                 break;
4583                 }
4584                 offset = offset + 2 + data_len;
4585         }
4586         }
4587         return 3+length;
4588 }
4589
4590 /* GPRS:        12.15
4591  * UMTS:        33.015
4592  */
4593 static int
4594 decode_gtp_data_resp(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4595         
4596         guint16         length, n, number;
4597         proto_tree      *ext_tree_data_resp;
4598         proto_item      *te;
4599
4600         length = tvb_get_ntohs(tvb, offset + 1);
4601         
4602         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Requests responded");
4603         ext_tree_data_resp = proto_item_add_subtree(te, ett_gtp_data_resp);
4604         
4605         n = 0;
4606         
4607         while (n < length) {
4608
4609                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4610                 proto_tree_add_text(ext_tree_data_resp, tvb, offset + 3 + n, 2, "%u", number);
4611                 n = n + 2;
4612
4613         }
4614
4615         return 3 + length;
4616
4617 }
4618         
4619 /* GPRS:        12.15
4620  * UMTS:        33.015
4621  */
4622 static int
4623 decode_gtp_node_addr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4624                 
4625         guint16         length; 
4626         guint32         addr_ipv4;
4627         struct  e_in6_addr addr_ipv6;
4628         proto_tree      *ext_tree_node_addr;
4629         proto_item      *te;
4630         
4631         length = tvb_get_ntohs(tvb, offset+1);
4632         
4633         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Node address: ");
4634         ext_tree_node_addr = proto_item_add_subtree(te, ett_gtp_node_addr);
4635         
4636         proto_tree_add_text(ext_tree_node_addr, tvb, offset+1, 2, "Node address length: %u", length);
4637         
4638         switch (length) {
4639                 case 4:
4640                         addr_ipv4 = tvb_get_letohl(tvb, offset+3);
4641                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4642                         proto_tree_add_ipv4(ext_tree_node_addr, gtp_version ? hf_gtpv1_node_ipv4 : hf_gtpv0_node_ipv4, tvb, offset+3, 4, addr_ipv4);
4643                         break;
4644                 case 16: 
4645                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
4646                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4647                         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);
4648                         break;
4649                 default:
4650                         proto_item_append_text(te, "unknown type or wrong length");
4651                         break;
4652         }
4653
4654         return 3 + length;
4655
4656 }
4657
4658 /* GPRS:        9.60 v7.6.0, chapter 7.9.26
4659  * UMTS:        29.060 v4.0, chapter 7.7.44
4660  */
4661 static int
4662 decode_gtp_priv_ext(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {  
4663                 
4664         guint16         length, ext_id; 
4665         gchar           ext_val[64];
4666         proto_tree      *ext_tree_priv_ext;
4667         proto_item      *te;
4668         
4669         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_PRIV_EXT, gtp_val, "Unknown message"));
4670         ext_tree_priv_ext = proto_item_add_subtree(te, ett_gtp_ext);
4671         
4672         length = tvb_get_ntohs(tvb, offset+1);
4673         if (length < 1) return 3+length;
4674         
4675         ext_id = tvb_get_ntohs(tvb, offset+3);  
4676         tvb_memcpy(tvb, ext_val, offset+5, length > 65 ? 63 : length-2);
4677         ext_val[length > 65 ? 64 : length-1] = '\0';
4678         proto_tree_add_uint(ext_tree_priv_ext, gtp_version ? hf_gtpv1_ext_id : hf_gtpv0_ext_id, tvb, offset+3, 2, ext_id);
4679         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);
4680         
4681         return 3+length;
4682 }
4683
4684 static int
4685 decode_gtp_unknown(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
4686
4687         proto_tree_add_text(tree, tvb, offset, 1, "Unknown extension header");
4688
4689         return tvb_length_remaining(tvb, offset);
4690 }
4691
4692 static void
4693 dissect_gtpv0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4694 {
4695         
4696         _gtpv0_hdr      gtpv0_hdr;
4697         proto_item      *ti, *tf;
4698         proto_tree      *gtpv0_tree, *flags_tree;
4699         guint8          ext_hdr_val;
4700         tvbuff_t        *next_tvb;
4701         const guint8    *tid_val;
4702         gchar           *tid_str;
4703         int             offset, length, i, mandatory, checked_field;
4704         
4705         if (check_col(pinfo->fd, COL_PROTOCOL)) col_set_str(pinfo->fd, COL_PROTOCOL, "GTP");
4706         if (check_col(pinfo->fd, COL_INFO)) col_clear(pinfo->fd, COL_INFO);
4707
4708         tvb_memcpy(tvb, (guint8 *)&gtpv0_hdr, 0, 12); 
4709         tid_val = tvb_get_ptr(tvb, 12, 8);
4710         tid_str = id_to_str(tid_val);
4711         gtp_version = (gtpv0_hdr.flags >> 5) & 0x07;
4712
4713         if (!((gtpv0_hdr.flags >> 4) & 1)) {
4714                 if (check_col(pinfo->fd, COL_PROTOCOL))
4715                         col_set_str(pinfo->fd, COL_PROTOCOL, "GTP-CDR");
4716         } else {
4717                 switch ((gtpv0_hdr.flags >> 5) & 0x07) {
4718                 case 0: if (check_col(pinfo->fd, COL_PROTOCOL))
4719                                 col_set_str(pinfo->fd, COL_PROTOCOL, "GTP");
4720                         break;
4721                 case 1: if (check_col(pinfo->fd, COL_PROTOCOL))
4722                                 col_set_str(pinfo->fd, COL_PROTOCOL, "GTPv1");
4723                 default: if (check_col(pinfo->fd, COL_PROTOCOL))
4724                                 col_set_str(pinfo->fd, COL_PROTOCOL, "GTPv?");
4725                         break;
4726                 }
4727         }
4728
4729         if (check_col(pinfo->fd, COL_INFO)) col_add_str(pinfo->fd, COL_INFO, val_to_str(gtpv0_hdr.message, message_type, "Unknown"));
4730         
4731         if (tree) {
4732                         
4733                 /* dissect GTP header */
4734                 ti = proto_tree_add_item(tree, proto_gtpv0, tvb, 0, tvb_length(tvb), FALSE);
4735                 gtpv0_tree = proto_item_add_subtree(ti, ett_gtp);
4736
4737                 tf = proto_tree_add_uint(gtpv0_tree, hf_gtpv0_flags, tvb, 0, 1, gtpv0_hdr.flags);
4738
4739                 flags_tree = proto_item_add_subtree(tf, ett_gtp_flags);
4740                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_ver, tvb, 0, 1, gtpv0_hdr.flags);
4741                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_pt, tvb, 0, 1, gtpv0_hdr.flags);
4742                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_spare, tvb, 0, 1, gtpv0_hdr.flags);
4743                 proto_tree_add_boolean(flags_tree, hf_gtpv0_flags_snn, tvb, 0, 1, gtpv0_hdr.flags);
4744                 
4745                 gtpv0_hdr.length = ntohs(gtpv0_hdr.length);
4746                 gtpv0_hdr.seq_no = ntohs(gtpv0_hdr.seq_no);
4747                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_message_type, tvb, 1, 1, gtpv0_hdr.message);
4748                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_length, tvb, 2, 2, gtpv0_hdr.length);
4749                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_seq_number, tvb, 4, 2, gtpv0_hdr.seq_no);
4750                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_flow_label, tvb, 6, 2, gtpv0_hdr.flow_label);
4751                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_sndcp_number, tvb, 8, 1, gtpv0_hdr.sndcp_no);
4752                 proto_tree_add_string(gtpv0_tree, hf_gtpv0_tid, tvb, 12, 8, tid_str);
4753         
4754                 if (gtpv0_hdr.message != GTP_MSG_TPDU) {
4755                                 
4756                         proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[--- end of GTPv0 header, beginning of extension headers ---]");
4757                                         
4758                         offset = GTPv0_HDR_LENGTH;
4759                         length = tvb_length(tvb);
4760
4761                         mandatory = 0;          /* check order of GTP fields against ETSI */
4762                 
4763                         for (;;) {
4764                                         
4765                                 if (offset >= length) break;
4766                                 ext_hdr_val = tvb_get_guint8(tvb, offset);
4767                                 
4768                                 if (gtpv0_etsi_order) {
4769                                         checked_field = check_field_presence (gtpv0_hdr.message, ext_hdr_val , (int *)&mandatory);
4770                                         switch (checked_field) {
4771                                                 case -2: proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[WARNING] message not found");
4772                                                          break;
4773                                                 case -1: proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[WARNING] field not present");
4774                                                          break;
4775                                                 case 0:  break;
4776                                                 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"));
4777                                         }
4778                                 }
4779                                 
4780                                 i = -1;
4781                                 while (gtpopt[++i].optcode) if (gtpopt[i].optcode == ext_hdr_val) break;
4782                                 offset = offset + (*gtpopt[i].decode)(tvb, offset, pinfo, gtpv0_tree);
4783                         }
4784                 }
4785         } 
4786
4787 /* next part dissects sublayers of GTP
4788  * right now it's only IP */
4789         
4790         if ((gtpv0_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
4791                 next_tvb = tvb_new_subset(tvb, 20, -1, -1);
4792                 call_dissector(ip_handle, next_tvb, pinfo, tree);
4793                 if (check_col(pinfo->fd, COL_PROTOCOL)) col_append_str_gtp(pinfo->fd, COL_PROTOCOL, "GTP");
4794         }
4795         
4796 }
4797
4798 /* GTP v1 dissector */
4799 static void
4800 dissect_gtpv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
4801         
4802         _gtpv1_hdr      gtpv1_hdr;
4803         proto_item      *ti, *tf;
4804         proto_tree      *gtpv1_tree, *flags_tree;
4805         guint16         seq_no;
4806         guint8          ext_hdr_val, i, hdr_offset = 4, next_hdr, npdu_no, probe;
4807         tvbuff_t        *next_tvb;
4808         int             offset, length, mandatory, checked_field;
4809         
4810         if (check_col(pinfo->fd, COL_PROTOCOL)) col_set_str(pinfo->fd, COL_PROTOCOL, "GTP-C");
4811         if (check_col(pinfo->fd, COL_INFO)) col_clear(pinfo->fd, COL_INFO);
4812
4813         tvb_memcpy(tvb, (guint8 *)&gtpv1_hdr, 0, 8);
4814         gtp_version = (gtpv1_hdr.flags >> 5) & 0x07;
4815
4816         if (check_col(pinfo->fd, COL_INFO)) col_add_str(pinfo->fd, COL_INFO, val_to_str(gtpv1_hdr.message, message_type, "Unknown"));
4817
4818         if (tree) {
4819                         
4820                 ti = proto_tree_add_item(tree, proto_gtpv1, tvb, 0, tvb_length(tvb), FALSE);
4821                 gtpv1_tree = proto_item_add_subtree(ti, ett_gtp);
4822
4823                 tf = proto_tree_add_uint(gtpv1_tree, hf_gtpv1_flags, tvb, 0, 1, gtpv1_hdr.flags);
4824                 flags_tree = proto_item_add_subtree(tf, ett_gtp_flags);
4825                 
4826                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_ver, tvb, 0, 1, gtpv1_hdr.flags);
4827                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_pt, tvb, 0, 1, gtpv1_hdr.flags);
4828                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_spare, tvb, 0, 1, gtpv1_hdr.flags);
4829                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_e, tvb, 0, 1, gtpv1_hdr.flags);
4830                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_s, tvb, 0, 1, gtpv1_hdr.flags);
4831                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_pn, tvb, 0, 1, gtpv1_hdr.flags);
4832                 
4833                 gtpv1_hdr.length = ntohs(gtpv1_hdr.length);
4834                 gtpv1_hdr.teid = ntohl(gtpv1_hdr.teid);
4835                 
4836                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_message_type, tvb, 1, 1, gtpv1_hdr.message);
4837                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_length, tvb, 2, 2, gtpv1_hdr.length);
4838                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_teid, tvb, 4, 4, gtpv1_hdr.teid);
4839
4840                 hdr_offset = 0;
4841
4842                 if (gtpv1_hdr.flags & 0x02) {
4843                         seq_no = tvb_get_ntohs(tvb, 8);
4844                         proto_tree_add_uint(gtpv1_tree, hf_gtpv1_seq_number, tvb, 8, 2, seq_no);
4845                 } else {
4846                         hdr_offset = hdr_offset + 2;
4847                 }
4848                 
4849                 if ((gtpv1_hdr.flags & 0x01 ) || (gtpv1_hdr.message != 0xFF)) {
4850                         npdu_no = tvb_get_guint8(tvb, 10 - hdr_offset);
4851                         proto_tree_add_uint(gtpv1_tree, hf_gtpv1_npdu_number, tvb, 10 - hdr_offset, 1, npdu_no);
4852                 } else {
4853                         hdr_offset = hdr_offset + 1;
4854                 }
4855
4856                 if ((gtpv1_hdr.flags & 0x04) || (gtpv1_hdr.message != 0xFF)) { 
4857                         next_hdr = tvb_get_guint8(tvb, 11 - hdr_offset);
4858                         proto_tree_add_uint(gtpv1_tree, hf_gtpv1_next, tvb, 11 - hdr_offset, 1, next_hdr);
4859                 } else {
4860                         hdr_offset = hdr_offset + 1;
4861                 }
4862
4863                 if (gtpv1_hdr.message != GTP_MSG_TPDU) {
4864
4865                         proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[--- end of GTP v1 header, beginning of extension headers ---]");
4866                                 
4867                         offset = GTPv1_HDR_LENGTH - hdr_offset;
4868                         length = tvb_length(tvb);
4869                 
4870                         mandatory = 0;          /* check order of GTP fields against ETSI */
4871                 
4872                         for (;;) {
4873                                         
4874                                 if (offset >= length) break;
4875                                 ext_hdr_val = tvb_get_guint8(tvb, offset);
4876                                 
4877                                 if (gtpv1_etsi_order) {
4878                                         checked_field = check_field_presence (gtpv1_hdr.message, ext_hdr_val , (int *)&mandatory);
4879                                         switch (checked_field) {
4880                                                 case -2: proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[WARNING] message not found");
4881                                                          break;
4882                                                 case -1: proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[WARNING] field not present");
4883                                                          break;
4884                                                 case 0:  break;
4885                                                 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"));
4886                                         }
4887                                 }
4888                                 
4889                                 i = -1;
4890                                 while (gtpopt[++i].optcode) if (gtpopt[i].optcode == ext_hdr_val) break;
4891                                 offset = offset + (*gtpopt[i].decode)(tvb, offset, pinfo, gtpv1_tree);
4892                         }
4893                 } 
4894         }
4895
4896         if (gtpv1_hdr.message == GTP_MSG_ERR_IND)
4897                 if (check_col(pinfo->fd, COL_PROTOCOL)) col_add_str(pinfo->fd, COL_PROTOCOL, "GTP-U");
4898
4899
4900         if ((gtpv1_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
4901         
4902                 hdr_offset =  (gtpv1_hdr.flags & 0x02) ? 0 : 2;
4903
4904                 /* some stupid checking, because some vendors do not respect
4905                  * ETSI recommendation */
4906                 
4907                 probe = tvb_get_guint8(tvb, 10 - hdr_offset);
4908                 if (probe == 0) {
4909                         probe = tvb_get_guint8(tvb, 11 - hdr_offset);
4910                         if (probe != 0) hdr_offset++;
4911                 } else {
4912                         hdr_offset = hdr_offset + 2;
4913                 }
4914                 
4915                 next_tvb = tvb_new_subset(tvb, GTPv1_HDR_LENGTH - hdr_offset, -1, -1);
4916                 call_dissector(ip_handle, next_tvb, pinfo, tree);
4917                 if (check_col(pinfo->fd, COL_PROTOCOL)) col_append_str_gtp(pinfo->fd, COL_PROTOCOL, "GTP-U");
4918         }
4919 }
4920
4921 static const true_false_string yes_no_tfs = { 
4922         "yes" ,
4923         "no"
4924 };
4925
4926 void
4927 proto_register_gtp(void)
4928 {                 
4929
4930         static hf_register_info hf_gtpv0[] = {
4931
4932         { &hf_gtpv0_flags,              { "Flags",              "gtpv0.flags",                  FT_UINT8,       BASE_HEX, NULL, 0, "Ver/PT/Spare/SNN", HFILL }},
4933         { &hf_gtpv0_flags_ver,          { "Version",            "gtpv0.flags.version",          FT_UINT8,       BASE_DEC, VALS(ver_types), GTP_VER_MASK, "GTP Version", HFILL }},
4934         { &hf_gtpv0_flags_pt,           { "Protocol type",      "gtpv0.flags.payload",          FT_UINT8,       BASE_DEC, NULL, GTP_PT_MASK, "Protocol Type (1 = GTP, 0 = GTP' )", HFILL }},
4935         { &hf_gtpv0_flags_spare,                { "Reserved",           "gtpv0.flags.reserved",         FT_UINT8,       BASE_DEC, NULL, GTP_SPARE_MASK, "Reserved (shall be sent as '111' )", HFILL }},
4936         { &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 }},
4937         { &hf_gtpv0_message_type,               { "Message type",       "gtpv0.message",                FT_UINT8,       BASE_HEX, VALS(message_type), 0x0, "GTP Message Type", HFILL }},
4938         { &hf_gtpv0_length,             { "Length",             "gtpv0.length",                 FT_UINT16,      BASE_DEC, NULL, 0, "Length (i.e. number of octets after TID or TEID)", HFILL }},
4939         { &hf_gtpv0_seq_number,         { "Sequence number",    "gtpv0.seq_number",             FT_UINT16,      BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
4940         { &hf_gtpv0_flow_label,         { "Flow label",         "gtpv0.flow_label",             FT_UINT16,      BASE_HEX, NULL, 0, "Flow label", HFILL }},
4941         { &hf_gtpv0_sndcp_number,               { "SNDCP N-PDU LLC Number", "gtpv0.sndcp_number",               FT_UINT8,       BASE_HEX, NULL, 0, "SNDCP N-PDU LLC Number", HFILL }},
4942         { &hf_gtpv0_tid,                        { "TID",                "gtpv0.tid",                    FT_STRING,      BASE_DEC, NULL, 0, "Tunnel Identifier", HFILL }},
4943         { &hf_gtpv0_cause,              { "Cause",              "gtpv0.cause",                  FT_UINT8,       BASE_DEC, VALS(cause_type), 0, "Cause of operation", HFILL }},
4944         { &hf_gtpv0_imsi,                       { "IMSI",               "gtpv0.imsi",                   FT_STRING,      BASE_DEC, NULL, 0, "International Mobile Subscriber Identity number", HFILL }},
4945         { &hf_gtpv0_rai_mcc,            { "MCC",                "gtpv0.mcc",                    FT_UINT16,      BASE_DEC, NULL, 0, "Mobile Country Code", HFILL }},
4946         { &hf_gtpv0_rai_mnc,            { "MNC",                "gtpv0.mnc",                    FT_UINT8,       BASE_DEC, NULL, 0, "Mobile Network Code", HFILL }},
4947         { &hf_gtpv0_rai_rac,            { "RAC",                "gtpv0.rac",                    FT_UINT8,       BASE_DEC, NULL, 0, "Routing Area Code", HFILL }},
4948         { &hf_gtpv0_rai_lac,            { "LAC",                "gtpv0.lac",                    FT_UINT16,      BASE_DEC, NULL, 0, "Location Area Code", HFILL }},
4949         { &hf_gtpv0_tlli,                       { "TLLI",               "gtpv0.tlli",                   FT_UINT32,      BASE_HEX, NULL, 0, "Temporary Logical Link Identity", HFILL }},
4950         { &hf_gtpv0_ptmsi,              { "P-TMSI",             "gtpv0.ptmsi",                  FT_UINT32,      BASE_HEX, NULL, 0, "Packet-Temporary Mobile Subscriber Identity", HFILL }},
4951         { &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 }},
4952         { &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 }},
4953         { &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 }},
4954         { &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 }},
4955         { &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 }},
4956         { &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 }},
4957         { &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 }},
4958         { &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 }},
4959         { &hf_gtpv0_reorder,            { "Reordering required","gtpv0.reorder",                FT_BOOLEAN,     BASE_NONE,NULL, 0, "Reordering required", HFILL }},
4960         { &hf_gtpv0_map_cause,          { "MAP cause",          "gtpv0.map_cause",              FT_UINT8,       BASE_DEC, VALS(map_cause_type), 0, "MAP cause", HFILL }},
4961         { &hf_gtpv0_ptmsi_sig,          { "P-TMSI signature",   "gtpv0.ptmsi_sig",              FT_UINT24,      BASE_HEX, NULL, 0, "P-TMSI Signature", HFILL }},
4962         { &hf_gtpv0_ms_valid,           { "MS validated",       "gtpv0.ms_valid",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "MS validated", HFILL }},
4963         { &hf_gtpv0_recovery,           { "Recovery",           "gtpv0.recovery",               FT_UINT8,       BASE_DEC, NULL, 0, "Restart counter", HFILL }},
4964         { &hf_gtpv0_sel_mode,           { "Selection mode",     "gtpv0.sel_mode",               FT_UINT8,       BASE_DEC, VALS(sel_mode_type), 0, "Selection Mode", HFILL }},
4965         { &hf_gtpv0_ext_flow_label,     { "Flow Label Data I",  "gtpv0.ext_flow_label",         FT_UINT16,      BASE_DEC, NULL, 0, "Flow label data", HFILL }},
4966         { &hf_gtpv0_flow_sig,           { "Flow label Signalling",      "gtpv0.flow_sig",       FT_UINT16,      BASE_DEC, NULL, 0, "Flow label signalling", HFILL }},
4967         { &hf_gtpv0_nsapi,              { "NSAPI ",             "gtpv0.nsapi",                  FT_UINT8,       BASE_DEC, NULL, 0, "Network layer Service Access Point Identifier", HFILL }},
4968         { &hf_gtpv0_flow_ii,            { "Flow Label Data II ","gtpv0.flow_ii",                FT_UINT16,      BASE_DEC, NULL, 0, "Downlink flow label data", HFILL }},
4969         { &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 }},
4970         { &hf_gtpv0_tr_comm,            { "Packet transfer command",    "gtpv0.tr_comm",        FT_UINT8,       BASE_DEC, VALS(tr_comm_type), 0, "Packat transfer command", HFILL }},
4971         { &hf_gtpv0_chrg_id,            { "Charging ID ",       "gtpv0.chrg_id",                FT_UINT32,      BASE_HEX, NULL, 0, "Charging ID", HFILL }},
4972         { &hf_gtpv0_user_ipv4,          { "End user address IPv4",      "gtpv0.user_ipv4",      FT_IPv4,        BASE_DEC, NULL, 0, "End user address IPv4", HFILL }},
4973         { &hf_gtpv0_user_ipv6,          { "End user address IPv6",      "gtpv0.user_ipv6",      FT_IPv6,        BASE_HEX, NULL, 0, "End user address IPv6", HFILL }},
4974         { &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 }},
4975         { &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 }},
4976         { &hf_gtpv0_apn,                        { "APN",                "gtpv0.apn",                    FT_STRING,      BASE_DEC, NULL, 0, "Access Point Name", HFILL }},
4977         { &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 }},
4978         { &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 }},
4979         { &hf_gtpv0_gsn_ipv4,           { "GSN address IPv4",   "gtpv0.gsn_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "GSN address IPv4", HFILL }},
4980         { &hf_gtpv0_gsn_ipv6,           { "GSN address IPv6",   "gtpv0.gsn_ipv6",               FT_IPv6,        BASE_DEC, NULL, 0, "GSN address IPv6", HFILL }},
4981         { &hf_gtpv0_msisdn,             { "MSISDN",             "gtpv0.msisdn",                 FT_STRING,      BASE_DEC, NULL, 0, "MS international PSTN/ISDN number", HFILL }},
4982         { &hf_gtpv0_chrg_ipv4,          { "CG address IPv4",    "gtpv0.chrg_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Charging Gateway address IPv4", HFILL }},
4983         { &hf_gtpv0_chrg_ipv6,          { "CG address IPv6",    "gtpv0.chrg_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Charging Gateway address IPv6", HFILL }},
4984         { &hf_gtpv0_node_ipv4,          { "Node address IPv4",  "gtpv0.node_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Recommended node address IPv4", HFILL }},
4985         { &hf_gtpv0_node_ipv6,          { "Node address IPv6",  "gtpv0.node_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Recommended node address IPv6", HFILL }},
4986         { &hf_gtpv0_ext_id,             { "Extension identifier",       "gtpv0.ext_id",         FT_UINT16,      BASE_DEC, NULL, 0, "Extension Identifier", HFILL }},
4987         { &hf_gtpv0_ext_val,            { "Extension value",            "gtpv0.ext_val",        FT_STRING,      BASE_DEC, NULL, 0, "Extension Value", HFILL }},
4988         { &hf_gtpv0_unknown,            { "Unknown data (length)",      "gtpv0.unknown",        FT_UINT16,      BASE_DEC, NULL, 0, "Unknown data", HFILL }},
4989
4990         };
4991
4992         
4993         static hf_register_info hf_gtpv1[] = {
4994
4995         { &hf_gtpv1_flags,              { "Flags",              "gtpv1.flags",                  FT_UINT8,       BASE_HEX, NULL, 0, "Ver/PT/Spare/E/S/PN", HFILL }},
4996         { &hf_gtpv1_flags_ver,          { "Version",            "gtpv1.flags.version",          FT_UINT8,       BASE_DEC, VALS(ver_types), GTP_VER_MASK, "GTP Version", HFILL }},
4997         { &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 }},
4998         { &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 }},
4999         { &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 }},
5000         { &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 }},
5001         { &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 }},
5002         { &hf_gtpv1_message_type,               { "Message Type",       "gtpv1.message",                FT_UINT8,       BASE_HEX, VALS(message_type), 0x0, "GTP Message Type", HFILL }},
5003         { &hf_gtpv1_length,             { "Length",             "gtpv1.length",                 FT_UINT16,      BASE_DEC, NULL, 0, "Length (i.e. number of octets after TID or TEID)", HFILL }},
5004         { &hf_gtpv1_seq_number,         { "Sequence Number",    "gtpv1.seq_number",             FT_UINT16,      BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
5005         { &hf_gtpv1_teid,                       { "TEID",               "gtpv1.teid",                   FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier", HFILL }},
5006         { &hf_gtpv1_npdu_number,                { "N-PDU Number",       "gtpv1.npdu_number",            FT_UINT8,       BASE_HEX, NULL, 0, "N-PDU Number", HFILL }},
5007         { &hf_gtpv1_next,                       { "Next extension header type", "gtpv1.next",           FT_UINT8,       BASE_HEX, NULL, 0, "Next Extension Header Type", HFILL }},
5008         { &hf_gtpv1_cause,              { "Cause ",             "gtpv1.cause",                  FT_UINT8,       BASE_DEC, VALS(cause_type), 0, "Cause of operation", HFILL }},
5009         { &hf_gtpv1_imsi,                       { "IMSI",               "gtpv1.imsi",                   FT_STRING,      BASE_DEC, NULL, 0, "International Mobile Subscriber Identity number", HFILL }},
5010         { &hf_gtpv1_rai_mcc,            { "MCC",                "gtpv1.mcc",                    FT_UINT16,      BASE_DEC, NULL, 0, "Mobile Country Code", HFILL }},
5011         { &hf_gtpv1_rai_mnc,            { "MNC",                "gtpv1.mnc",                    FT_UINT8,       BASE_DEC, NULL, 0, "Mobile Network Code", HFILL }},
5012         { &hf_gtpv1_rai_rac,            { "RAC",                "gtpv1.rac",                    FT_UINT8,       BASE_DEC, NULL, 0, "Routing Area Code", HFILL }},
5013         { &hf_gtpv1_rai_lac,            { "LAC",                "gtpv1.lac",                    FT_UINT16,      BASE_DEC, NULL, 0, "Location Area Code", HFILL }},
5014         { &hf_gtpv1_tlli,                       { "TLLI",               "gtpv1.tlli",                   FT_UINT32,      BASE_HEX, NULL, 0, "Temporary Logical Link Identity", HFILL }},
5015         { &hf_gtpv1_ptmsi,              { "P-TMSI",             "gtpv1.ptmsi",                  FT_UINT32,      BASE_HEX, NULL, 0, "Packet-Temporary Mobile Subscriber Identity", HFILL }},
5016         { &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 }},
5017         { &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 }},
5018         { &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 }},
5019         { &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 }},
5020         { &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 }},
5021         { &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 }},
5022         { &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 }},
5023         { &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 }},
5024         { &hf_gtpv1_reorder,            { "Reordering required","gtpv1.reorder",                FT_BOOLEAN,     BASE_NONE,NULL, 0, "Reordering required", HFILL }},
5025         { &hf_gtpv1_map_cause,          { "MAP cause",          "gtpv1.map_cause",              FT_UINT8,       BASE_DEC, VALS(map_cause_type), 0, "MAP cause", HFILL }},
5026         { &hf_gtpv1_ptmsi_sig,          { "P-TMSI Signature",   "gtpv1.ptmsi_sig",              FT_UINT24,      BASE_HEX, NULL, 0, "P-TMSI Signature", HFILL }},
5027         { &hf_gtpv1_ms_valid,           { "MS validated",       "gtpv1.ms_valid",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "MS validated", HFILL }},
5028         { &hf_gtpv1_recovery,           { "Recovery",           "gtpv1.recovery",               FT_UINT8,       BASE_DEC, NULL, 0, "Restart counter", HFILL }},
5029         { &hf_gtpv1_sel_mode,           { "Selection Mode",     "gtpv1.sel_mode",               FT_UINT8,       BASE_DEC, VALS(sel_mode_type), 0, "Selection Mode", HFILL }},
5030         { &hf_gtpv1_teid_data,          { "TEID Data I",        "gtpv1.teid_data",              FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data I", HFILL }},
5031         { &hf_gtpv1_teid_cp,            { "TEID Control Plane", "gtpv1.teid_cp",                FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Control Plane", HFILL }},
5032         { &hf_gtpv1_nsapi,              { "NSAPI",              "gtpv1.nsapi",                  FT_UINT8,       BASE_DEC, NULL, 0, "Network layer Service Access Point Identifier", HFILL }},
5033         { &hf_gtpv1_teid_ii,            { "TEID Data II",       "gtpv1.teid_ii",                FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data II", HFILL }},
5034         { &hf_gtpv1_tear_ind,           { "Teardown indication","gtpv1.tear_ind",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "Teardown Indication", HFILL }},
5035         { &hf_gtpv1_ranap_cause,                { "RANAP cause",        "gtpv1.ranap_cause",            FT_UINT8,       BASE_DEC, VALS(ranap_cause_type), 0, "RANAP cause", HFILL }},
5036         { &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 }},
5037         { &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 }},
5038         { &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 }},
5039         { &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 }},
5040         { &hf_gtpv1_rp_sms,             { "Radio Priority SMS", "gtpv1.rp_sms",                 FT_UINT8,       BASE_DEC, NULL, 0, "Radio Priority for MO SMS", HFILL }},
5041         { &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 }},
5042         { &hf_gtpv1_rp_spare,           { "Reserved",           "gtpv1.rp_spare",               FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_SPARE_MASK, "Spare bit", HFILL }},
5043         { &hf_gtpv1_rp,                 { "Radio Priority",     "gtpv1.rp",                     FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_MASK, "Radio Priority for uplink tx", HFILL }},
5044         { &hf_gtpv1_pkt_flow_id,                { "Packet Flow ID",     "gtpv1.pkt_flow_id",            FT_UINT8,       BASE_DEC, NULL, 0, "Packet Flow ID", HFILL }},
5045         { &hf_gtpv1_chrg_char_s,                { "Spare",              "gtpv1.chrg_char_s",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_S, "Spare", HFILL }},
5046         { &hf_gtpv1_chrg_char_n,                { "Normal charging",    "gtpv1.chrg_char_n",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_N, "Normal charging", HFILL }},
5047         { &hf_gtpv1_chrg_char_p,                { "Prepaid charging",   "gtpv1.chrg_char_p",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_P, "Prepaid charging", HFILL }},
5048         { &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 }},
5049         { &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 }},
5050         { &hf_gtpv1_chrg_char_r,                { "Reserved",           "gtpv1.chrg_char_r",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_R, "Reserved", HFILL }},
5051         { &hf_gtpv1_trace_ref,          { "Trace reference",    "gtpv1.trace_ref",              FT_UINT16,      BASE_HEX, NULL, 0, "Trace reference", HFILL }},
5052         { &hf_gtpv1_trace_type,         { "Trace type",         "gtpv1.trace_type",             FT_UINT16,      BASE_HEX, NULL, 0, "Trace type", HFILL }},
5053         { &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 }},
5054         { &hf_gtpv1_tr_comm,            { "Packet transfer command",    "gtpv1.tr_comm",        FT_UINT8,       BASE_DEC, VALS(tr_comm_type), 0, "Packat transfer command", HFILL }},
5055         { &hf_gtpv1_chrg_id,            { "Charging ID",        "gtpv1.chrg_id",                FT_UINT32,      BASE_HEX, NULL, 0, "Charging ID", HFILL }},
5056         { &hf_gtpv1_user_ipv4,          { "End user address IPv4",      "gtpv1.user_ipv4",      FT_IPv4,        BASE_DEC, NULL, 0, "End user address IPv4", HFILL }},
5057         { &hf_gtpv1_user_ipv6,          { "End user address IPv6",      "gtpv1.user_ipv6",      FT_IPv6,        BASE_HEX, NULL, 0, "End user address IPv6", HFILL }},
5058         { &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 }},
5059         { &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 }},
5060         { &hf_gtpv1_apn,                        { "APN",                "gtpv1.apn",                    FT_STRING,      BASE_DEC, NULL, 0, "Access Point Name", HFILL }},
5061         { &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 }},
5062         { &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 }},
5063         { &hf_gtpv1_gsn_ipv4,           { "GSN address IPv4",   "gtpv1.gsn_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "GSN address IPv4", HFILL }},
5064         { &hf_gtpv1_gsn_ipv6,           { "GSN address IPv6",   "gtpv1.gsn_ipv6",               FT_IPv6,        BASE_DEC, NULL, 0, "GSN address IPv6", HFILL }},
5065         { &hf_gtpv1_msisdn,             { "MSISDN",             "gtpv1.msisdn",                 FT_STRING,      BASE_DEC, NULL, 0, "MS international PSTN/ISDN number", HFILL }},
5066         { &hf_gtpv1_qos_al_ret_priority,        { "Allocation/Retention priority ","gtpv1.qos_al_ret_priority",         FT_UINT8,       BASE_DEC, NULL, 0, "Allocation/Retention Priority", HFILL }},
5067         { &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 }},
5068         { &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 }},
5069         { &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 }},
5070         { &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 }},
5071         { &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 }},
5072         { &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 }},
5073         { &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 }},
5074         { &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 }},
5075         { &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 }},
5076         { &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 }},
5077         { &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 }},
5078         { &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 }},
5079         { &hf_gtpv1_rnc_ipv4,           { "RNC address IPv4",   "gtpv1.rnc_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "Radio Network Controller address IPv4", HFILL }},
5080         { &hf_gtpv1_rnc_ipv6,           { "RNC address IPv6",   "gtpv1.rnc_ipv6",               FT_IPv6,        BASE_HEX, NULL, 0, "Radio Network Controller address IPv6", HFILL }},
5081         { &hf_gtpv1_chrg_ipv4,          { "CG address IPv4",    "gtpv1.chrg_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Charging Gateway address IPv4", HFILL }},
5082         { &hf_gtpv1_chrg_ipv6,          { "CG address IPv6",    "gtpv1.chrg_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Charging Gateway address IPv6", HFILL }},
5083         { &hf_gtpv1_node_ipv4,          { "Node address IPv4",  "gtpv1.node_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Recommended node address IPv4", HFILL }},
5084         { &hf_gtpv1_node_ipv6,          { "Node address IPv6",  "gtpv1.node_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Recommended node address IPv6", HFILL }},
5085         { &hf_gtpv1_ext_id,             { "Extensio Identifier","gtpv1.ext_id",                 FT_UINT16,      BASE_DEC, NULL, 0, "Extension Identifier", HFILL }},
5086         { &hf_gtpv1_ext_val,            { "Extension Value",    "gtpv1.ext_val",                FT_STRING,      BASE_DEC, NULL, 0, "Extension Value", HFILL }},
5087         { &hf_gtpv1_unknown,            { "Unknown data (length)",      "gtpv1.unknown",        FT_UINT16,      BASE_DEC, NULL, 0, "Unknown data", HFILL }},
5088
5089         };
5090
5091         static gint *ett_gtp_array[] = {
5092                 &ett_gtp,
5093                 &ett_gtp_flags,
5094                 &ett_gtp_ext,
5095                 &ett_gtp_rai,
5096                 &ett_gtp_qos,
5097                 &ett_gtp_auth_tri,
5098                 &ett_gtp_flow_ii,
5099                 &ett_gtp_rab_cntxt,
5100                 &ett_gtp_rp,
5101                 &ett_gtp_pkt_flow_id,
5102                 &ett_gtp_chrg_char,
5103                 &ett_gtp_user,
5104                 &ett_gtp_mm,
5105                 &ett_gtp_trip,
5106                 &ett_gtp_quint,
5107                 &ett_gtp_pdp,
5108                 &ett_gtp_apn,
5109                 &ett_gtp_proto,
5110                 &ett_gtp_gsn_addr,
5111                 &ett_gtp_tft,
5112                 &ett_gtp_tft_pf,
5113                 &ett_gtp_rab_setup,
5114                 &ett_gtp_hdr_list,
5115                 &ett_gtp_chrg_addr,
5116                 &ett_gtp_node_addr,
5117                 &ett_gtp_rel_pack,
5118                 &ett_gtp_can_pack,
5119                 &ett_gtp_data_resp,
5120                 &ett_gtp_priv_ext,
5121         };
5122
5123         module_t        *gtp_module;
5124         
5125         static enum_val_t gtpv0_cdr_options[] = {
5126                 { "GSM 12.15",  0 },
5127                 { "Nokia CDR",  1 },
5128                 { "None",       2 },
5129                 { NULL,         -1 }
5130         };
5131
5132         proto_gtpv0 = proto_register_protocol("GPRS Tunnelling Protocol v0", "GTPv0", "gtpv0");
5133         proto_register_field_array(proto_gtpv0, hf_gtpv0, array_length(hf_gtpv0));
5134         proto_register_subtree_array(ett_gtp_array, array_length(ett_gtp_array));
5135         
5136         proto_gtpv1 = proto_register_protocol("GPRS Tunnelling Protocol v1", "GTPv1", "gtpv1");
5137         proto_register_field_array(proto_gtpv1, hf_gtpv1, array_length(hf_gtpv1));
5138         proto_register_subtree_array(ett_gtp_array, array_length(ett_gtp_array));
5139         
5140         gtp_module = prefs_register_protocol(proto_gtpv0, proto_reg_handoff_gtp);
5141         
5142         prefs_register_uint_preference(gtp_module, "gtpv0_port", "GTPv0 port ", "GTPv0 port (default 3386)", 10, &g_gtpv0_port);
5143         prefs_register_uint_preference(gtp_module, "gtpv1c_port", "GTPv1 control plane (GTP-C) port ", "GTPv1 control plane port (default 2123)", 10, &g_gtpv1c_port);
5144         prefs_register_uint_preference(gtp_module, "gtpv1u_port", "GTPv1 user plane (GTP-U) port ", "GTPv1 user plane port (default 2152)", 10, &g_gtpv1u_port);
5145         prefs_register_bool_preference(gtp_module, "gtp_dissect_tpdu", "Dissect T-PDU ", "Dissect T-PDU", &gtp_tpdu);
5146         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);
5147         prefs_register_bool_preference(gtp_module, "gtpv0_check_etsi", "Compare GTPv0 order with ETSI ", "GTPv0 ETSI order", &gtpv0_etsi_order);
5148         prefs_register_bool_preference(gtp_module, "gtpv1_check_etsi", "Compare GTPv1 order with ETSI ", "GTPv1 ETSI order", &gtpv1_etsi_order);
5149         prefs_register_bool_preference(gtp_module, "ppp_reorder", "Reorder & dissect PPP in Protocol conf. options", "PPP reorder & dissect", &ppp_reorder);
5150         
5151         register_dissector("gtpv0", dissect_gtpv0, proto_gtpv0);
5152         register_dissector("gtpv1", dissect_gtpv1, proto_gtpv1);
5153
5154 }
5155
5156 void
5157 proto_reg_handoff_gtp(void)
5158 {
5159         static int Initialized = FALSE;
5160         
5161         if (Initialized) {
5162                 
5163                 dissector_delete("udp.port", gtpv0_port, dissect_gtpv0);
5164                 dissector_delete("tcp.port", gtpv0_port, dissect_gtpv0);
5165                 
5166                 dissector_delete("udp.port", gtpv1c_port, dissect_gtpv1);
5167                 dissector_delete("tcp.port", gtpv1c_port, dissect_gtpv1);
5168                 dissector_delete("udp.port", gtpv1u_port, dissect_gtpv1);
5169                 dissector_delete("tcp.port", gtpv1u_port, dissect_gtpv1);
5170                 
5171         } else {
5172                 
5173                 Initialized = TRUE;
5174         }
5175                 
5176         gtpv0_port = g_gtpv0_port;
5177         gtpv1c_port = g_gtpv1c_port;
5178         gtpv1u_port = g_gtpv1u_port;
5179         
5180         /* GTP v0 */
5181         
5182         dissector_add("udp.port", g_gtpv0_port, dissect_gtpv0, proto_gtpv0);
5183         dissector_add("tcp.port", g_gtpv0_port, dissect_gtpv0, proto_gtpv0);
5184
5185         /* GTP v1 */
5186         
5187         dissector_add("udp.port", g_gtpv1c_port, dissect_gtpv1, proto_gtpv1);
5188         dissector_add("tcp.port", g_gtpv1c_port, dissect_gtpv1, proto_gtpv1);
5189         dissector_add("udp.port", g_gtpv1u_port, dissect_gtpv1, proto_gtpv1);
5190         dissector_add("tcp.port", g_gtpv1u_port, dissect_gtpv1, proto_gtpv1);
5191         
5192         ip_handle = find_dissector("ip");
5193         ppp_handle = find_dissector("ppp");
5194 }