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