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