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