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