change the signature that asn2wrs generates for functions to marm all parameters...
[obnox/wireshark/wip.git] / epan / dissectors / 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  * Updates and corrections:
8  * Copyright 2006, Anders Broman <anders.broman@ericsson.com>
9  *
10  * $Id$
11  *
12  * Wireshark - Network traffic analyzer
13  * By Gerald Combs <gerald@wireshark.org>
14  * Copyright 1998 Gerald Combs
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29  * Ref: 3GPP TS 29.060 version 6.8.0 Release 6
30  */
31
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include <glib.h>
41
42 #include <epan/packet.h>
43 #include <epan/prefs.h>
44 #include <epan/sminmpec.h>
45 #include "packet-ipv6.h"
46 #include "packet-ppp.h"
47 #include "packet-radius.h"
48 #include "packet-bssap.h"
49 #include "packet-gsm_a.h"
50 #include "packet-gsm_map.h"
51 #include "packet-per.h"
52 #include "packet-ranap.h"
53 #include "packet-bssgp.h"
54
55 static dissector_table_t ppp_subdissector_table;
56
57 #define GTPv0_PORT 3386
58 #define GTPv1C_PORT 2123                        /* 3G Control PDU */
59 #define GTPv1U_PORT 2152                        /* 3G T-PDU */
60
61 #define GTPv0_HDR_LENGTH 20
62 #define GTPv1_HDR_LENGTH 12
63 #define GTP_PRIME_HDR_LENGTH 6
64
65 /* to check compliance with ETSI  */
66 #define GTP_MANDATORY   1
67 #define GTP_OPTIONAL    2
68 #define GTP_CONDITIONAL 4
69
70 static guint g_gtpv0_port       = GTPv0_PORT;
71 static guint g_gtpv1c_port      = GTPv1C_PORT;
72 static guint g_gtpv1u_port      = GTPv1U_PORT;
73
74 void proto_reg_handoff_gtp(void);
75
76 static int proto_gtp            = -1;
77
78 static int hf_gtp_apn                           = -1;
79 static int hf_gtp_cause                         = -1;
80 static int hf_gtp_chrg_char                     = -1;
81 static int hf_gtp_chrg_char_s           = -1;
82 static int hf_gtp_chrg_char_n           = -1;
83 static int hf_gtp_chrg_char_p           = -1;
84 static int hf_gtp_chrg_char_f           = -1;
85 static int hf_gtp_chrg_char_h           = -1;
86 static int hf_gtp_chrg_char_r           = -1;
87 static int hf_gtp_chrg_id                       = -1;
88 static int hf_gtp_chrg_ipv4                     = -1;
89 static int hf_gtp_chrg_ipv6                     = -1;
90 static int hf_gtp_ext_flow_label        = -1;
91 static int hf_gtp_ext_id                        = -1;
92 static int hf_gtp_ext_val                       = -1;
93 static int hf_gtp_flags                         = -1;
94 static int hf_gtp_flags_ver                     = -1;
95 static int hf_gtp_flags_pt                      = -1;
96 static int hf_gtp_flags_spare1          = -1;
97 static int hf_gtp_flags_snn                     = -1;
98 static int hf_gtp_flags_spare2          = -1;
99 static int hf_gtp_flags_e                       = -1;
100 static int hf_gtp_flags_s                       = -1;
101 static int hf_gtp_flags_pn                      = -1;
102 static int hf_gtp_flow_ii                       = -1;
103 static int hf_gtp_flow_label            = -1;
104 static int hf_gtp_flow_sig                      = -1;
105 static int hf_gtp_gsn_addr_len          = -1;
106 static int hf_gtp_gsn_addr_type         = -1;
107 static int hf_gtp_gsn_ipv4                      = -1;
108 static int hf_gtp_gsn_ipv6                      = -1;
109 static int hf_gtp_imsi                          = -1;
110 static int hf_gtp_length                        = -1;
111 static int hf_gtp_map_cause                     = -1;
112 static int hf_gtp_message_type          = -1;
113 static int hf_gtp_ms_reason                     = -1;
114 static int hf_gtp_ms_valid                      = -1;
115 static int hf_gtp_msisdn                        = -1;
116 static int hf_gtp_next                          = -1;
117 static int hf_gtp_npdu_number           = -1;
118 static int hf_gtp_node_ipv4                     = -1;
119 static int hf_gtp_node_ipv6                     = -1;
120 static int hf_gtp_nsapi                         = -1;
121 static int hf_gtp_ptmsi                         = -1;
122 static int hf_gtp_ptmsi_sig                     = -1;
123 static int hf_gtp_qos_version           = -1;
124 static int hf_gtp_qos_spare1            = -1;
125 static int hf_gtp_qos_delay                     = -1;
126 static int hf_gtp_qos_mean                      = -1;
127 static int hf_gtp_qos_peak                      = -1;
128 static int hf_gtp_qos_spare2            = -1;
129 static int hf_gtp_qos_precedence        = -1;
130 static int hf_gtp_qos_spare3            = -1;
131 static int hf_gtp_qos_reliability       = -1;
132 static int hf_gtp_qos_al_ret_priority   = -1;
133 static int hf_gtp_qos_traf_class        = -1;
134 static int hf_gtp_qos_del_order         = -1;
135 static int hf_gtp_qos_del_err_sdu       = -1;
136 static int hf_gtp_qos_max_sdu_size      = -1;
137 static int hf_gtp_qos_max_ul            = -1;
138 static int hf_gtp_qos_max_dl            = -1;
139 static int hf_gtp_qos_res_ber           = -1;
140 static int hf_gtp_qos_sdu_err_ratio     = -1;
141 static int hf_gtp_qos_trans_delay       = -1;
142 static int hf_gtp_qos_traf_handl_prio   = -1;
143 static int hf_gtp_qos_guar_ul           = -1;
144 static int hf_gtp_qos_guar_dl           = -1;
145 static int hf_gtp_pkt_flow_id           = -1;
146 static int hf_gtp_rab_gtpu_dn           = -1;
147 static int hf_gtp_rab_gtpu_up           = -1;
148 static int hf_gtp_rab_pdu_dn            = -1;
149 static int hf_gtp_rab_pdu_up            = -1;
150 static int hf_gtp_rai_mcc                       = -1;
151 static int hf_gtp_rai_mnc                       = -1;
152 static int hf_gtp_rai_rac                       = -1;
153 static int hf_gtp_rai_lac                       = -1;
154 static int hf_gtp_ranap_cause           = -1;
155 static int hf_gtp_recovery                      = -1;
156 static int hf_gtp_reorder                       = -1;
157 static int hf_gtp_rnc_ipv4                      = -1;
158 static int hf_gtp_rnc_ipv6                      = -1;
159 static int hf_gtp_rp                            = -1;
160 static int hf_gtp_rp_nsapi                      = -1;
161 static int hf_gtp_rp_sms                        = -1;
162 static int hf_gtp_rp_spare                      = -1;
163 static int hf_gtp_sel_mode                      = -1;
164 static int hf_gtp_seq_number            = -1;
165 static int hf_gtp_sndcp_number          = -1;
166 static int hf_gtp_tear_ind                      = -1;
167 static int hf_gtp_teid                          = -1;
168 static int hf_gtp_teid_cp                       = -1;
169 static int hf_gtp_teid_data                     = -1;
170 static int hf_gtp_teid_ii                       = -1;
171 static int hf_gtp_tft_code                      = -1;
172 static int hf_gtp_tft_spare                     = -1;
173 static int hf_gtp_tft_number            = -1;
174 static int hf_gtp_tft_eval                      = -1;
175 static int hf_gtp_tid                           = -1;
176 static int hf_gtp_tlli                          = -1;
177 static int hf_gtp_tr_comm                       = -1;
178 static int hf_gtp_trace_ref                     = -1;
179 static int hf_gtp_trace_type            = -1;
180 static int hf_gtp_unknown                       = -1;
181 static int hf_gtp_user_addr_pdp_org     = -1;
182 static int hf_gtp_user_addr_pdp_type    = -1;
183 static int hf_gtp_user_ipv4                     = -1;
184 static int hf_gtp_user_ipv6                     = -1;
185 static int hf_gtp_security_mode         = -1;
186 static int hf_gtp_no_of_vectors         = -1;
187 static int hf_gtp_cipher_algorithm      = -1;
188 static int hf_gtp_cksn_ksi                      = -1;
189 static int hf_gtp_cksn                          = -1;
190 static int hf_gtp_ksi                           = -1;
191 static int hf_gtp_ext_length            = -1;
192 static int hf_gtp_ext_apn_res           = -1;
193 static int hf_gtp_ext_rat_type          = -1;
194 static int hf_gtp_ext_geo_loc_type      = -1;
195 static int hf_gtp_ext_sac                       = -1;
196 static int hf_gtp_ext_imeisv            = -1;
197 static int hf_gtp_targetid                      = -1;
198 static int hf_gtp_bssgp_cause           = -1;
199
200
201 /* Initialize the subtree pointers */
202 static gint ett_gtp                                     = -1;
203 static gint ett_gtp_flags                       = -1;
204 static gint ett_gtp_ext                         = -1;
205 static gint ett_gtp_rai                         = -1;
206 static gint ett_gtp_qos                         = -1;
207 static gint ett_gtp_auth_tri            = -1;
208 static gint ett_gtp_flow_ii                     = -1;
209 static gint ett_gtp_rab_cntxt           = -1;
210 static gint ett_gtp_rp                          = -1;
211 static gint ett_gtp_pkt_flow_id         = -1;
212 static gint ett_gtp_chrg_char           = -1;
213 static gint ett_gtp_user                        = -1;
214 static gint ett_gtp_mm                          = -1;
215 static gint ett_gtp_trip                        = -1;
216 static gint ett_gtp_quint                       = -1;
217 static gint ett_gtp_pdp                         = -1;
218 static gint ett_gtp_apn                         = -1;
219 static gint ett_gtp_proto                       = -1;
220 static gint ett_gtp_gsn_addr            = -1;
221 static gint ett_gtp_tft                         = -1;
222 static gint ett_gtp_tft_pf                      = -1;
223 static gint ett_gtp_tft_flags           = -1;
224 static gint ett_gtp_rab_setup           = -1;
225 static gint ett_gtp_hdr_list            = -1;
226 static gint ett_gtp_chrg_addr           = -1;
227 static gint ett_gtp_node_addr           = -1;
228 static gint ett_gtp_rel_pack            = -1;
229 static gint ett_gtp_can_pack            = -1;
230 static gint ett_gtp_data_resp           = -1;
231 static gint ett_gtp_priv_ext            = -1;
232 static gint ett_gtp_net_cap                     = -1;
233 static gint ett_gtp_ext_tree_apn_res    = -1;
234 static gint ett_gtp_ext_rat_type                = -1;
235 static gint ett_gtp_ext_imeisv                  = -1;
236 static gint ett_gtp_ext_ran_tr_cont                     = -1;
237 static gint ett_gtp_ext_pdp_cont_prio           = -1;
238 static gint ett_gtp_ext_ssgn_no                         = -1;
239 static gint ett_gtp_ext_rab_setup_inf           = -1;
240 static gint ett_gtp_ext_common_flgs                     = -1;
241 static gint ett_gtp_ext_usr_loc_inf                     = -1;
242 static gint ett_gtp_ext_ms_time_zone            = -1;
243 static gint ett_gtp_ext_camel_chg_inf_con       = -1;
244 static gint ett_GTP_EXT_MBMS_UE_CTX                     = -1;
245 static gint ett_gtp_ext_tmgi                            = -1;
246 static gint ett_gtp_ext_rim_ra                          = -1;
247 static gint ett_gtp_ext_mbms_prot_conf_opt      = -1;
248 static gint ett_gtp_ext_mbms_sa                         = -1;
249 static gint ett_gtp_ext_bms_ses_dur                     = -1;
250 static gint ett_gtp_ext_src_rnc_pdp_ctx_inf     = -1;
251 static gint ett_gtp_ext_add_trs_inf                     = -1;
252 static gint ett_gtp_ext_hop_count                       = -1;
253 static gint ett_gtp_ext_sel_plmn_id             = -1;
254 static gint ett_gtp_ext_mbms_ses_id             = -1;
255 static gint ett_gtp_ext_mbms_2g_3g_ind          = -1;
256 static gint ett_gtp_ext_enh_nsapi                       = -1;
257 static gint ett_gtp_ext_ad_mbms_trs_inf         = -1;
258 static gint ett_gtp_ext_mbms_ses_id_rep_no      = -1;
259 static gint ett_gtp_ext_mbms_time_to_data_tr    = -1;
260 static gint ett_gtp_ext_ps_ho_req_ctx           = -1;
261 static gint ett_gtp_ext_bss_cont                        = -1;
262 static gint ett_gtp_ext_cell_id                         = -1;
263 static gint ett_gtp_ext_pdu_no                          = -1;
264 static gint ett_gtp_ext_bssgp_cause             = -1;
265 static gint ett_gtp_ext_ra_prio_lcs             = -1;
266 static gint ett_gtp_target_id                           = -1;
267 static gint ett_gtp_utran_cont                          = -1;
268         
269 static gboolean gtp_tpdu                        = TRUE;
270 static gboolean gtp_over_tcp            = TRUE;
271 static gboolean gtp_etsi_order          = FALSE;
272 static guint    gtpv0_port              = 0;
273 static guint    gtpv1c_port             = 0;
274 static guint    gtpv1u_port             = 0;
275
276 /* Definition of flags masks */
277 #define GTP_VER_MASK 0xE0
278
279 static const value_string ver_types[] = {
280         { 0, "GTP release 97/98 version" },
281         { 1, "GTP release 99 version" },
282         { 2, "None" },
283         { 3, "None" },
284         { 4, "None" },
285         { 5, "None" },
286         { 6, "None" },
287         { 7, "None" },
288         { 0, NULL }
289 };
290 static const value_string pt_types[] = {
291         { 0, "GTP'" },
292         { 1, "GTP" },
293         { 0, NULL }
294 };
295
296 #define GTP_PT_MASK                     0x10
297 #define GTP_SPARE1_MASK         0x0E
298 #define GTP_SPARE2_MASK         0x08
299 #define GTP_E_MASK                      0x04
300 #define GTP_S_MASK                      0x02
301 #define GTP_SNN_MASK            0x01
302 #define GTP_PN_MASK                     0x01
303
304 /* Definition of 3G charging characteristics masks */
305 #define GTP_MASK_CHRG_CHAR_S    0xF000
306 #define GTP_MASK_CHRG_CHAR_N    0x0800
307 #define GTP_MASK_CHRG_CHAR_P    0x0400
308 #define GTP_MASK_CHRG_CHAR_F    0x0200
309 #define GTP_MASK_CHRG_CHAR_H    0x0100
310 #define GTP_MASK_CHRG_CHAR_R    0x00FF
311
312 /* Traffic Flow Templates  mask */
313 #define GTPv1_TFT_CODE_MASK     0xE0
314 #define GTPv1_TFT_SPARE_MASK    0x10
315 #define GTPv1_TFT_NUMBER_MASK   0x0F
316
317 /* Definition of GSN Address masks */
318 #define GTP_EXT_GSN_ADDR_TYPE_MASK              0xC0
319 #define GTP_EXT_GSN_ADDR_LEN_MASK               0x3F
320
321 /* Definition of QoS masks */
322 #define GTP_EXT_QOS_SPARE1_MASK                                 0xC0
323 #define GTP_EXT_QOS_DELAY_MASK                                  0x38
324 #define GTP_EXT_QOS_RELIABILITY_MASK                    0x07
325 #define GTP_EXT_QOS_PEAK_MASK                                   0xF0
326 #define GTP_EXT_QOS_SPARE2_MASK                                 0x08
327 #define GTP_EXT_QOS_PRECEDENCE_MASK                             0x07
328 #define GTP_EXT_QOS_SPARE3_MASK                                 0xE0
329 #define GTP_EXT_QOS_MEAN_MASK                                   0x1F
330 #define GTP_EXT_QOS_TRAF_CLASS_MASK                             0xE0
331 #define GTP_EXT_QOS_DEL_ORDER_MASK                              0x18
332 #define GTP_EXT_QOS_DEL_ERR_SDU_MASK                    0x07
333 #define GTP_EXT_QOS_RES_BER_MASK                                0xF0
334 #define GTP_EXT_QOS_SDU_ERR_RATIO_MASK                  0x0F
335 #define GTP_EXT_QOS_TRANS_DELAY_MASK                    0xFC
336 #define GTP_EXT_QOS_TRAF_HANDL_PRIORITY_MASK    0x03
337
338 /* Definition of Radio Priority's masks */
339 #define GTPv1_EXT_RP_NSAPI_MASK                 0xF0
340 #define GTPv1_EXT_RP_SPARE_MASK                 0x08
341 #define GTPv1_EXT_RP_MASK                               0x07
342
343 /* definitions of GTP messages */
344 #define GTP_MSG_UNKNOWN                         0x00
345 #define GTP_MSG_ECHO_REQ                        0x01
346 #define GTP_MSG_ECHO_RESP                       0x02
347 #define GTP_MSG_VER_NOT_SUPP            0x03
348 #define GTP_MSG_NODE_ALIVE_REQ          0x04
349 #define GTP_MSG_NODE_ALIVE_RESP         0x05
350 #define GTP_MSG_REDIR_REQ                       0x06
351 #define GTP_MSG_REDIR_RESP                      0x07
352 #define GTP_MSG_CREATE_PDP_REQ          0x10
353 #define GTP_MSG_CREATE_PDP_RESP         0x11
354 #define GTP_MSG_UPDATE_PDP_REQ          0x12
355 #define GTP_MSG_UPDATE_PDP_RESP         0x13
356 #define GTP_MSG_DELETE_PDP_REQ          0x14
357 #define GTP_MSG_DELETE_PDP_RESP         0x15
358 #define GTP_MSG_CREATE_AA_PDP_REQ       0x16    /* 2G */
359 #define GTP_MSG_CREATE_AA_PDP_RESP      0x17    /* 2G */
360 #define GTP_MSG_DELETE_AA_PDP_REQ       0x18    /* 2G */
361 #define GTP_MSG_DELETE_AA_PDP_RESP      0x19    /* 2G */
362 #define GTP_MSG_ERR_IND                         0x1A
363 #define GTP_MSG_PDU_NOTIFY_REQ          0x1B
364 #define GTP_MSG_PDU_NOTIFY_RESP         0x1C
365 #define GTP_MSG_PDU_NOTIFY_REJ_REQ      0x1D
366 #define GTP_MSG_PDU_NOTIFY_REJ_RESP     0x1E
367 #define GTP_MSG_SUPP_EXT_HDR            0x1F
368 #define GTP_MSG_SEND_ROUT_INFO_REQ      0x20
369 #define GTP_MSG_SEND_ROUT_INFO_RESP     0x21
370 #define GTP_MSG_FAIL_REP_REQ            0x22
371 #define GTP_MSG_FAIL_REP_RESP           0x23
372 #define GTP_MSG_MS_PRESENT_REQ          0x24
373 #define GTP_MSG_MS_PRESENT_RESP         0x25
374 #define GTP_MSG_IDENT_REQ                       0x30
375 #define GTP_MSG_IDENT_RESP                      0x31
376 #define GTP_MSG_SGSN_CNTXT_REQ          0x32
377 #define GTP_MSG_SGSN_CNTXT_RESP         0x33
378 #define GTP_MSG_SGSN_CNTXT_ACK          0x34
379 #define GTP_MSG_FORW_RELOC_REQ          0x35
380 #define GTP_MSG_FORW_RELOC_RESP         0x36
381 #define GTP_MSG_FORW_RELOC_COMP         0x37
382 #define GTP_MSG_RELOC_CANCEL_REQ        0x38
383 #define GTP_MSG_RELOC_CANCEL_RESP       0x39
384 #define GTP_MSG_FORW_SRNS_CNTXT         0x3A
385 #define GTP_MSG_FORW_RELOC_ACK          0x3B
386 #define GTP_MSG_FORW_SRNS_CNTXT_ACK     0x3C
387
388 #define GTP_MSG_RAN_INFO_RELAY          70
389 #define GTP_MBMS_NOTIFY_REQ                     96
390 #define GTP_MBMS_NOTIFY_RES                     97
391 #define GTP_MBMS_NOTIFY_REJ_REQ         98
392 #define GTP_MBMS_NOTIFY_REJ_RES         99
393 #define GTP_CREATE_MBMS_CNTXT_REQ       100
394 #define GTP_CREATE_MBMS_CNTXT_RES       101
395 #define GTP_UPD_MBMS_CNTXT_REQ          102
396 #define GTP_UPD_MBMS_CNTXT_RES          103
397 #define GTP_DEL_MBMS_CNTXT_REQ          104
398 #define GTP_DEL_MBMS_CNTXT_RES          105
399 #define GTP_MBMS_REG_REQ                        112
400 #define GTP_MBMS_REG_RES                        113
401 #define GTP_MBMS_DE_REG_REQ                     114
402 #define GTP_MBMS_DE_REG_RES                     115
403 #define GTP_MBMS_SES_START_REQ          116
404 #define GTP_MBMS_SES_START_RES          117
405 #define GTP_MBMS_SES_STOP_REQ           118
406 #define GTP_MBMS_SES_STOP_RES           119
407 #define GTP_MSG_DATA_TRANSF_REQ         0xF0
408 #define GTP_MSG_DATA_TRANSF_RESP        0xF1
409 #define GTP_MSG_TPDU                            0xFF
410
411 static const value_string message_type[] = {
412         { GTP_MSG_UNKNOWN,                              "For future use" },
413         { GTP_MSG_ECHO_REQ,                             "Echo request" },
414         { GTP_MSG_ECHO_RESP,                    "Echo response" },
415         { GTP_MSG_VER_NOT_SUPP,                 "Version not supported" },
416         { GTP_MSG_NODE_ALIVE_REQ,               "Node alive request" },
417         { GTP_MSG_NODE_ALIVE_RESP,              "Node alive response" },
418         { GTP_MSG_REDIR_REQ,                    "Redirection request" },
419         { GTP_MSG_REDIR_RESP,                   "Redirection response" },
420         { GTP_MSG_CREATE_PDP_REQ,               "Create PDP context request" },
421         { GTP_MSG_CREATE_PDP_RESP,              "Create PDP context response" },
422         { GTP_MSG_UPDATE_PDP_REQ,               "Update PDP context request" },
423         { GTP_MSG_UPDATE_PDP_RESP,              "Update PDP context response" },
424         { GTP_MSG_DELETE_PDP_REQ,               "Delete PDP context request" },
425         { GTP_MSG_DELETE_PDP_RESP,              "Delete PDP context response" },
426         { GTP_MSG_CREATE_AA_PDP_REQ,    "Create AA PDP Context Request" },
427         { GTP_MSG_CREATE_AA_PDP_RESP,   "Create AA PDP Context Response" },
428         { GTP_MSG_DELETE_AA_PDP_REQ,    "Delete AA PDP Context Request" },
429         { GTP_MSG_DELETE_AA_PDP_RESP,   "Delete AA PDP Context Response" },
430         { GTP_MSG_ERR_IND,                              "Error indication" },
431         { GTP_MSG_PDU_NOTIFY_REQ,               "PDU notification request" },
432         { GTP_MSG_PDU_NOTIFY_RESP,              "PDU notification response" },
433         { GTP_MSG_PDU_NOTIFY_REJ_REQ,   "PDU notification reject request" },
434         { GTP_MSG_PDU_NOTIFY_REJ_RESP,  "PDU notification reject response" },
435         { GTP_MSG_SUPP_EXT_HDR,                 "Supported extension header notification" },
436         { GTP_MSG_SEND_ROUT_INFO_REQ,   "Send routing information for GPRS request" },
437         { GTP_MSG_SEND_ROUT_INFO_RESP,  "Send routing information for GPRS response" },
438         { GTP_MSG_FAIL_REP_REQ,                 "Failure report request" },
439         { GTP_MSG_FAIL_REP_RESP,                "Failure report response" },
440         { GTP_MSG_MS_PRESENT_REQ,               "Note MS GPRS present request" },
441         { GTP_MSG_MS_PRESENT_RESP,              "Note MS GPRS present response" },
442         { GTP_MSG_IDENT_REQ,                    "Identification request" },
443         { GTP_MSG_IDENT_RESP,                   "Identification response" },
444         { GTP_MSG_SGSN_CNTXT_REQ,               "SGSN context request" },
445         { GTP_MSG_SGSN_CNTXT_RESP,              "SGSN context response" },
446         { GTP_MSG_SGSN_CNTXT_ACK,               "SGSN context acknowledgement" },
447         { GTP_MSG_FORW_RELOC_REQ,               "Forward relocation request" },
448         { GTP_MSG_FORW_RELOC_RESP,              "Forward relocation response" },
449         { GTP_MSG_FORW_RELOC_COMP,              "Forward relocation complete" },
450         { GTP_MSG_RELOC_CANCEL_REQ,             "Relocation cancel request" },
451         { GTP_MSG_RELOC_CANCEL_RESP,    "Relocation cancel response" },
452         { GTP_MSG_FORW_SRNS_CNTXT,              "Forward SRNS context" },
453         { GTP_MSG_FORW_RELOC_ACK,               "Forward relocation complete acknowledge" },
454         { GTP_MSG_FORW_SRNS_CNTXT_ACK,  "Forward SRNS context acknowledge" },
455         { GTP_MSG_RAN_INFO_RELAY,               "RAN Information Relay" },
456         { GTP_MBMS_NOTIFY_REQ,                  "MBMS Notification Request" },
457         { GTP_MBMS_NOTIFY_RES,                  "MBMS Notification Response" },
458         { GTP_MBMS_NOTIFY_REJ_REQ,              "MBMS Notification Reject Request" },
459         { GTP_MBMS_NOTIFY_REJ_RES,              "MBMS Notification Reject Response" },
460         { GTP_CREATE_MBMS_CNTXT_REQ,    "Create MBMS Context Request" },
461         { GTP_CREATE_MBMS_CNTXT_RES,    "Create MBMS Context Response" },
462         { GTP_UPD_MBMS_CNTXT_REQ,               "Update MBMS Context Request" },
463         { GTP_UPD_MBMS_CNTXT_RES,               "Update MBMS Context Response" },
464         { GTP_DEL_MBMS_CNTXT_REQ,               "Delete MBMS Context Request" },
465         { GTP_DEL_MBMS_CNTXT_RES,               "Delete MBMS Context Response" },
466         { GTP_MBMS_REG_REQ,                             "MBMS Registration Request" },
467         { GTP_MBMS_REG_RES,                             "MBMS Registration Response" },
468         { GTP_MBMS_DE_REG_REQ,                  "MBMS De-Registration Request" },
469         { GTP_MBMS_DE_REG_RES,                  "MBMS De-Registration Response" },
470         { GTP_MBMS_SES_START_REQ,               "MBMS Session Start Request" },
471         { GTP_MBMS_SES_START_RES,               "MBMS Session Start Response" },
472         { GTP_MBMS_SES_STOP_REQ,                "MBMS Session Stop Request" },
473         { GTP_MBMS_SES_STOP_RES,                "MBMS Session Stop Response" },
474         { GTP_MSG_DATA_TRANSF_REQ,              "Data record transfer request" },
475         { GTP_MSG_DATA_TRANSF_RESP,             "Data record transfer response" },
476         { GTP_MSG_TPDU,                                 "T-PDU" },
477         { 0, NULL }
478 };
479
480 /* definitions of fields in extension header */
481 #define GTP_EXT_CAUSE           0x01
482 #define GTP_EXT_IMSI            0x02
483 #define GTP_EXT_RAI                     0x03
484 #define GTP_EXT_TLLI            0x04
485 #define GTP_EXT_PTMSI           0x05
486 #define GTP_EXT_QOS_GPRS        0x06
487 #define GTP_EXT_REORDER         0x08
488 #define GTP_EXT_AUTH_TRI        0x09
489 #define GTP_EXT_MAP_CAUSE       0x0B
490 #define GTP_EXT_PTMSI_SIG       0x0C
491 #define GTP_EXT_MS_VALID        0x0D
492 #define GTP_EXT_RECOVER         0x0E
493 #define GTP_EXT_SEL_MODE        0x0F
494
495 #define GTP_EXT_16                      0x10
496 #define GTP_EXT_FLOW_LABEL      0x10
497 #define GTP_EXT_TEID            0x10    /* 0xFF10 3G */
498
499 #define GTP_EXT_17                      0x11
500 #define GTP_EXT_FLOW_SIG        0x11
501 #define GTP_EXT_TEID_CP         0x11    /* 0xFF11 3G */
502
503 #define GTP_EXT_18                      0x12
504 #define GTP_EXT_FLOW_II         0x12
505 #define GTP_EXT_TEID_II         0x12    /* 0xFF12 3G*/
506
507 #define GTP_EXT_19                      0x13
508 #define GTP_EXT_MS_REASON       0x13    /* same as 0x1D GTPv1_EXT_MS_REASON */
509 #define GTP_EXT_TEAR_IND        0x13    /* 0xFF13 3G*/
510
511 #define GTP_EXT_NSAPI           0x14    /* 3G */
512 #define GTP_EXT_RANAP_CAUSE     0x15    /* 3G */
513 #define GTP_EXT_RAB_CNTXT       0x16    /* 3G */
514 #define GTP_EXT_RP_SMS          0x17    /* 3G */
515 #define GTP_EXT_RP                      0x18    /* 3G */
516 #define GTP_EXT_PKT_FLOW_ID     0x19    /* 3G */
517 #define GTP_EXT_CHRG_CHAR       0x1A    /* 3G */
518 #define GTP_EXT_TRACE_REF       0x1B    /* 3G */
519 #define GTP_EXT_TRACE_TYPE      0x1C    /* 3G */
520 #define GTPv1_EXT_MS_REASON     0x1D    /* 3G */
521 #define GTP_EXT_TR_COMM         0x7E    /* charging */
522 #define GTP_EXT_CHRG_ID         0x7F
523 #define GTP_EXT_USER_ADDR       0x80
524 #define GTP_EXT_MM_CNTXT        0x81
525 #define GTP_EXT_PDP_CNTXT       0x82
526 #define GTP_EXT_APN                     0x83
527 #define GTP_EXT_PROTO_CONF      0x84
528 #define GTP_EXT_GSN_ADDR        0x85
529 #define GTP_EXT_MSISDN          0x86
530 #define GTP_EXT_QOS_UMTS        0x87    /* 3G */
531 #define GTP_EXT_AUTH_QUI        0x88    /* 3G */
532 #define GTP_EXT_TFT                     0x89    /* 3G */
533 #define GTP_EXT_TARGET_ID       0x8A    /* 3G */
534 #define GTP_EXT_UTRAN_CONT      0x8B    /* 3G */
535 #define GTP_EXT_RAB_SETUP       0x8C    /* 3G */
536 #define GTP_EXT_HDR_LIST        0x8D    /* 3G */
537 #define GTP_EXT_TRIGGER_ID      0x8E                    /* 3G   142 7.7.41 */
538 #define GTP_EXT_OMC_ID          0x8F                    /* 3G   143 TLV OMC Identity 7.7.42 */
539 #define GTP_EXT_RAN_TR_CONT                     0x90    /* 3G   144 TLV RAN Transparent Container 7.7.43 */
540 #define GTP_EXT_PDP_CONT_PRIO           0x91    /* 3G   145 TLV PDP Context Prioritization 7.7.45 */
541 #define GTP_EXT_ADD_RAB_SETUP_INF       0x92    /* 3G   146 TLV Additional RAB Setup Information 7.7.45A */
542 #define GTP_EXT_SSGN_NO                         0x93    /* 3G   147 TLV SGSN Number 7.7.47 */
543 #define GTP_EXT_COMMON_FLGS                     0x94    /* 3G   148 TLV Common Flags 7.7.48 */
544 #define GTP_EXT_APN_RES                         0x95    /* 3G   149 */
545 #define GTP_EXT_RA_PRIO_LCS                     0x96    /* 3G   150 TLV Radio Priority LCS 7.7.25B */
546 #define GTP_EXT_RAT_TYPE                        0x97    /* 3G   151 TLV RAT Type 7.7.50 */
547 #define GTP_EXT_USR_LOC_INF                     0x98    /* 3G   152 TLV User Location Information 7.7.51 */
548 #define GTP_EXT_MS_TIME_ZONE            0x99    /* 3G   153 TLV MS Time Zone 7.7.52 */
549
550 #define GTP_EXT_IMEISV                          0x9A    /* 3G */
551 #define GTP_EXT_CAMEL_CHG_INF_CON       0x9B    /* 3G   155 TLV CAMEL Charging Information Container 7.7.54 */
552 #define GTP_EXT_MBMS_UE_CTX                     0x9C    /* 3G   156 TLV MBMS UE Context 7.7.55 */
553 #define GTP_EXT_TMGI                            0x9D    /* 3G   157 TLV Temporary Mobile Group Identity (TMGI) 7.7.56 */
554 #define GTP_EXT_RIM_RA                          0x9E    /* 3G   158 TLV RIM Routing Address 7.7.57 */
555 #define GTP_EXT_MBMS_PROT_CONF_OPT      0x9F    /* 3G   159 TLV MBMS Protocol Configuration Options 7.7.58 */
556 #define GTP_EXT_MBMS_SA                         0xA0    /* 3G   160 TLV MBMS Service Area 7.7.60 */
557 #define GTP_EXT_SRC_RNC_PDP_CTX_INF 0xA1        /* 3G   161 TLV Source RNC PDCP context info 7.7.61 */
558 #define GTP_EXT_ADD_TRS_INF                     0xA2    /* 3G   162 TLV Additional Trace Info 7.7.62 */
559 #define GTP_EXT_HOP_COUNT                       0xA3    /* 3G   163 TLV Hop Counter 7.7.63 */
560 #define GTP_EXT_SEL_PLMN_ID                     0xA4    /* 3G   164 TLV Selected PLMN ID 7.7.64 */
561 #define GTP_EXT_MBMS_SES_ID                     0xA5    /* 3G   165 TLV MBMS Session Identifier 7.7.65 */
562 #define GTP_EXT_MBMS_2G_3G_IND          0xA6    /* 3G   166 TLV MBMS 2G/3G Indicator 7.7.66 */
563 #define GTP_EXT_ENH_NSAPI                       0xA7    /* 3G   167 TLV Enhanced NSAPI 7.7.67 */
564 #define GTP_EXT_MBMS_SES_DUR            0xA8    /* 3G   168 TLV MBMS Session Duration 7.7.59 */
565 #define GTP_EXT_ADD_MBMS_TRS_INF        0xA9    /* 3G   169 TLV Additional MBMS Trace Info 7.7.68 */
566 #define GTP_EXT_MBMS_SES_ID_REP_NO      0xAA    /* 3G   170 TLV MBMS Session Identity Repetition Number 7.7.69 */
567 #define GTP_EXT_MBMS_TIME_TO_DATA_TR 0xAB       /* 3G   171 TLV MBMS Time To Data Transfer 7.7.70 */
568 #define GTP_EXT_PS_HO_REQ_CTX           0xAC    /* 3G   172 TLV PS Handover Request Context 7.7.71 */
569 #define GTP_EXT_BSS_CONT                        0xAD    /* 3G   173 TLV BSS Container 7.7.72 */
570 #define GTP_EXT_CELL_ID                         0xAE    /* 3G   174 TLV Cell Identification 7.7.73 */
571 #define GTP_EXT_PDU_NO                          0xAF    /* 3G   175 TLV PDU Numbers 7.7.74 */
572 #define GTP_EXT_BSSGP_CAUSE                     0xA0    /* 3G   176 TLV BSSGP Cause 7.7.75 */
573
574 #define GTP_EXT_C1                      0xC1
575 #define GTP_EXT_C2                      0xC2
576 #define GTP_EXT_REL_PACK        0xF9    /* charging */
577 #define GTP_EXT_CAN_PACK        0xFA    /* charging */
578 #define GTP_EXT_CHRG_ADDR       0xFB
579 #define GTP_EXT_DATA_REQ        0xFC    /* charging */
580 #define GTP_EXT_DATA_RESP       0xFD    /* charging */
581 #define GTP_EXT_NODE_ADDR       0xFE    /* charging */
582 #define GTP_EXT_PRIV_EXT        0xFF
583
584 static const value_string gtp_val[] = {
585         { GTP_EXT_CAUSE,                "Cause of operation" },
586         { GTP_EXT_IMSI,                 "IMSI" },
587         { GTP_EXT_RAI,                  "Routing Area Identity" },
588         { GTP_EXT_TLLI,                 "Temporary Logical Link Identity" },
589         { GTP_EXT_PTMSI,                "Packet TMSI" },
590         { GTP_EXT_QOS_GPRS,             "Quality of Service" },
591         { GTP_EXT_REORDER,              "Reorder required" },
592         { GTP_EXT_AUTH_TRI,             "Authentication triplets" },
593         { GTP_EXT_MAP_CAUSE,    "MAP cause" },
594         { GTP_EXT_PTMSI_SIG,    "P-TMSI signature" },
595         { GTP_EXT_MS_VALID,             "MS validated" },
596         { GTP_EXT_RECOVER,              "Recovery" },
597         { GTP_EXT_SEL_MODE,             "Selection mode" },
598
599         { GTP_EXT_16,                   "Flow label data I" },
600         { GTP_EXT_FLOW_LABEL,   "Flow label data I" },
601         { GTP_EXT_TEID,                 "Tunnel Endpoint Identifier Data I" },                  /* 3G */
602
603         { GTP_EXT_17,                   "Flow label signalling" },
604         { GTP_EXT_FLOW_SIG,             "Flow label signalling" },
605         { GTP_EXT_TEID_CP,              "Tunnel Endpoint Identifier Data Control Plane" },      /* 3G */
606
607         { GTP_EXT_18,                   "Flow label data II" },
608         { GTP_EXT_FLOW_II,              "Flow label data II" },
609         { GTP_EXT_TEID_II,              "Tunnel Endpoint Identifier Data II" },                 /* 3G */
610
611         { GTP_EXT_19,                   "MS not reachable reason" },
612         { GTP_EXT_MS_REASON,    "MS not reachable reason" },
613         { GTP_EXT_TEAR_IND,             "Teardown ID" },                                                                /* 3G */
614         
615         { GTP_EXT_NSAPI,                "NSAPI" },                                                                              /* 3G */
616         { GTP_EXT_RANAP_CAUSE,  "RANAP cause" },                                                                /* 3G */
617         { GTP_EXT_RAB_CNTXT,    "RAB context" },                                                                /* 3G */
618         { GTP_EXT_RP_SMS,               "Radio Priority for MO SMS" },                                  /* 3G */
619         { GTP_EXT_RP,                   "Radio Priority" },                                                             /* 3G */
620         { GTP_EXT_PKT_FLOW_ID,  "Packet Flow ID" },                                                             /* 3G */
621         { GTP_EXT_CHRG_CHAR,    "Charging characteristics" },                                   /* 3G */
622         { GTP_EXT_TRACE_REF,    "Trace references" },                                                   /* 3G */
623         { GTP_EXT_TRACE_TYPE,   "Trace type" },                                                                 /* 3G */
624         { GTPv1_EXT_MS_REASON,  "MS not reachable reason" },                                    /* 3G */
625         { GTP_EXT_TR_COMM,              "Packet transfer command" },                                    /* charging */
626         { GTP_EXT_CHRG_ID,              "Charging ID" },
627         { GTP_EXT_USER_ADDR,    "End user address" },
628         { GTP_EXT_MM_CNTXT,             "MM context" },
629         { GTP_EXT_PDP_CNTXT,    "PDP context" },
630         { GTP_EXT_APN,                  "Access Point Name" },
631         { GTP_EXT_PROTO_CONF,   "Protocol configuration options" },
632         { GTP_EXT_GSN_ADDR,             "GSN address" },
633         { GTP_EXT_MSISDN,               "MS international PSTN/ISDN number" },
634         { GTP_EXT_QOS_UMTS,             "Quality of service (UMTS)" },                                  /* 3G */
635         { GTP_EXT_AUTH_QUI,             "Authentication quintuplets" },                                 /* 3G */
636         { GTP_EXT_TFT,                  "Traffic Flow Template (TFT)" },                                /* 3G */
637         { GTP_EXT_TARGET_ID,    "Target (RNC) identification" },                                /* 3G */
638         { GTP_EXT_UTRAN_CONT,   "UTRAN transparent field" },                                    /* 3G */
639         { GTP_EXT_RAB_SETUP,    "RAB setup information" },                                              /* 3G */
640         { GTP_EXT_HDR_LIST,             "Extension Header Types List" },                                /* 3G */
641         { GTP_EXT_TRIGGER_ID,   "Trigger Id" },                                                                 /* 3G */
642         { GTP_EXT_OMC_ID,               "OMC Identity" },                                                               /* 3G */
643
644         { GTP_EXT_RAN_TR_CONT,                  "RAN Transparent Container" },                                  /* 7.7.43 */
645         { GTP_EXT_PDP_CONT_PRIO,                "PDP Context Prioritization" },                                 /* 7.7.45 */
646         { GTP_EXT_ADD_RAB_SETUP_INF,    "Additional RAB Setup Information" },                   /* 7.7.45A */
647         { GTP_EXT_SSGN_NO,                              "SGSN Number" },                                                                /* 7.7.47 */
648         { GTP_EXT_COMMON_FLGS,                  "Common Flags" },                                                               /* 7.7.48 */
649         { GTP_EXT_APN_RES,                              "APN Restriction" },                                                    /* 3G */
650         { GTP_EXT_RA_PRIO_LCS,                  "Radio Priority LCS" },                                                 /* 7.7.25B */
651         { GTP_EXT_RAT_TYPE,                             "RAT Type" },                                                                   /* 3G */
652         { GTP_EXT_USR_LOC_INF,                  "User Location Information" },                                  /* 7.7.51 */
653         { GTP_EXT_MS_TIME_ZONE,                 "MS Time Zone" },                                                               /* 7.7.52 */
654
655         { GTP_EXT_IMEISV,                               "IMEI(SV)" },                                                                   /* 3G */
656         { GTP_EXT_CAMEL_CHG_INF_CON,    "CAMEL Charging Information Container" },               /* 7.7.54 */
657         { GTP_EXT_MBMS_UE_CTX,                  "MBMS UE Context" },                                                    /* 7.7.55 */
658         { GTP_EXT_TMGI,                                 "Temporary Mobile Group Identity (TMGI)" },             /* 7.7.56 */
659         { GTP_EXT_RIM_RA,                               "RIM Routing Address" },                                                /* 7.7.57 */
660         { GTP_EXT_MBMS_PROT_CONF_OPT,   "MBMS Protocol Configuration Options" },                /* 7.7.58 */
661         { GTP_EXT_MBMS_SA,                              "MBMS Service Area" },                                                  /* 7.7.60 */
662         { GTP_EXT_SRC_RNC_PDP_CTX_INF,  "Source RNC PDCP context info" },                               /* 7.7.61 */
663         { GTP_EXT_ADD_TRS_INF,                  "Additional Trace Info" },                                              /* 7.7.62 */
664         { GTP_EXT_HOP_COUNT,                            "Hop Counter" },                                                        /* 7.7.63 */
665         { GTP_EXT_SEL_PLMN_ID,                  "Selected PLMN ID" },                                                   /* 7.7.64 */
666         { GTP_EXT_MBMS_SES_ID,                  "MBMS Session Identifier" },                                    /* 7.7.65 */
667         { GTP_EXT_MBMS_2G_3G_IND,               "MBMS 2G/3G Indicator" },                                               /* 7.7.66 */
668         { GTP_EXT_ENH_NSAPI,                    "Enhanced NSAPI" },                                                             /* 7.7.67 */
669         { GTP_EXT_MBMS_SES_DUR,                 "MBMS Session Duration" },                                              /* 7.7.59 */
670         { GTP_EXT_ADD_MBMS_TRS_INF,             "Additional MBMS Trace Info" },                                 /* 7.7.68 */
671         { GTP_EXT_MBMS_SES_ID_REP_NO,   "MBMS Session Identity Repetition Number" },    /* 7.7.69 */
672         { GTP_EXT_MBMS_TIME_TO_DATA_TR, "MBMS Time To Data Transfer" },                                 /* 7.7.70 */
673         { GTP_EXT_PS_HO_REQ_CTX,                "PS Handover Request Context" },                                /* 7.7.71 */
674         { GTP_EXT_BSS_CONT,                             "BSS Container" },                                                              /* 7.7.72 */
675         { GTP_EXT_CELL_ID,                              "Cell Identification" },                                                /* 7.7.73 */
676         { GTP_EXT_PDU_NO,                               "PDU Numbers" },                                                                /* 7.7.74 */
677         { GTP_EXT_BSSGP_CAUSE,                  "BSSGP Cause" },                                                                /* 7.7.75 */
678         { GTP_EXT_REL_PACK,                             "Sequence numbers of released packets IE" },    /* charging */
679         { GTP_EXT_CAN_PACK,                             "Sequence numbers of canceled packets IE" },    /* charging */
680         { GTP_EXT_CHRG_ADDR,                    "Charging Gateway address" },   
681         { GTP_EXT_DATA_REQ,                             "Data record packet" },                                                 /* charging */
682         { GTP_EXT_DATA_RESP,                    "Requests responded" },                                                 /* charging */
683         { GTP_EXT_NODE_ADDR,                    "Address of recommended node" },                                /* charging */
684         { GTP_EXT_PRIV_EXT,                     "Private Extension" },
685         { 0, NULL }
686 };
687 /* It seems like some IE's are renamed in gtpv1 at least reading 
688  * 3GPP TS 29.060 version 6.11.0 Release 6
689  */ 
690 static const value_string gtpv1_val[] = {
691         { GTP_EXT_CAUSE,                "Cause of operation" },
692         { GTP_EXT_IMSI,                 "IMSI" },
693         { GTP_EXT_RAI,                  "Routing Area Identity" },
694         { GTP_EXT_TLLI,                 "Temporary Logical Link Identity" },
695         { GTP_EXT_PTMSI,                "Packet TMSI" },
696         { GTP_EXT_QOS_GPRS,             "Quality of Service" },
697         { GTP_EXT_REORDER,              "Reorder required" },
698         { GTP_EXT_AUTH_TRI,             "Authentication triplets" },
699         { GTP_EXT_MAP_CAUSE,    "MAP cause" },
700         { GTP_EXT_PTMSI_SIG,    "P-TMSI signature" },
701         { GTP_EXT_MS_VALID,             "MS validated" },
702         { GTP_EXT_RECOVER,              "Recovery" },
703         { GTP_EXT_SEL_MODE,             "Selection mode" },
704
705         { GTP_EXT_TEID,                 "Tunnel Endpoint Identifier Data I" },                  /* 3G */
706
707         { GTP_EXT_TEID_CP,              "Tunnel Endpoint Identifier Data Control Plane" },      /* 3G */
708
709         { GTP_EXT_TEID_II,              "Tunnel Endpoint Identifier Data II" },                 /* 3G */
710
711         { GTP_EXT_TEAR_IND,             "Teardown ID" },                                                                /* 3G */
712         
713         { GTP_EXT_NSAPI,                "NSAPI" },                                                                              /* 3G */
714         { GTP_EXT_RANAP_CAUSE,  "RANAP cause" },                                                                /* 3G */
715         { GTP_EXT_RAB_CNTXT,    "RAB context" },                                                                /* 3G */
716         { GTP_EXT_RP_SMS,               "Radio Priority for MO SMS" },                                  /* 3G */
717         { GTP_EXT_RP,                   "Radio Priority" },                                                             /* 3G */
718         { GTP_EXT_PKT_FLOW_ID,  "Packet Flow ID" },                                                             /* 3G */
719         { GTP_EXT_CHRG_CHAR,    "Charging characteristics" },                                   /* 3G */
720         { GTP_EXT_TRACE_REF,    "Trace references" },                                                   /* 3G */
721         { GTP_EXT_TRACE_TYPE,   "Trace type" },                                                                 /* 3G */
722         { GTPv1_EXT_MS_REASON,  "MS not reachable reason" },                                    /* 3G */
723         { GTP_EXT_TR_COMM,              "Packet transfer command" },                                    /* charging */
724         { GTP_EXT_CHRG_ID,              "Charging ID" },
725         { GTP_EXT_USER_ADDR,    "End user address" },
726         { GTP_EXT_MM_CNTXT,             "MM context" },
727         { GTP_EXT_PDP_CNTXT,    "PDP context" },
728         { GTP_EXT_APN,                  "Access Point Name" },
729         { GTP_EXT_PROTO_CONF,   "Protocol configuration options" },
730         { GTP_EXT_GSN_ADDR,             "GSN address" },
731         { GTP_EXT_MSISDN,               "MS international PSTN/ISDN number" },
732         { GTP_EXT_QOS_UMTS,             "Quality of service (UMTS)" },                                  /* 3G */
733         { GTP_EXT_AUTH_QUI,             "Authentication quintuplets" },                                 /* 3G */
734         { GTP_EXT_TFT,                  "Traffic Flow Template (TFT)" },                                /* 3G */
735         { GTP_EXT_TARGET_ID,    "Target (RNC) identification" },                                /* 3G */
736         { GTP_EXT_UTRAN_CONT,   "UTRAN transparent field" },                                    /* 3G */
737         { GTP_EXT_RAB_SETUP,    "RAB setup information" },                                              /* 3G */
738         { GTP_EXT_HDR_LIST,             "Extension Header Types List" },                                /* 3G */
739         { GTP_EXT_TRIGGER_ID,   "Trigger Id" },                                                                 /* 3G */
740         { GTP_EXT_OMC_ID,               "OMC Identity" },                                                               /* 3G */
741
742         { GTP_EXT_RAN_TR_CONT,                  "RAN Transparent Container" },                                  /* 7.7.43 */
743         { GTP_EXT_PDP_CONT_PRIO,                "PDP Context Prioritization" },                                 /* 7.7.45 */
744         { GTP_EXT_ADD_RAB_SETUP_INF,    "Additional RAB Setup Information" },                   /* 7.7.45A */
745         { GTP_EXT_SSGN_NO,                              "SGSN Number" },                                                                /* 7.7.47 */
746         { GTP_EXT_COMMON_FLGS,                  "Common Flags" },                                                               /* 7.7.48 */
747         { GTP_EXT_APN_RES,                              "APN Restriction" },                                                    /* 3G */
748         { GTP_EXT_RA_PRIO_LCS,                  "Radio Priority LCS" },                                                 /* 7.7.25B */
749         { GTP_EXT_RAT_TYPE,                             "RAT Type" },                                                                   /* 3G */
750         { GTP_EXT_USR_LOC_INF,                  "User Location Information" },                                  /* 7.7.51 */
751         { GTP_EXT_MS_TIME_ZONE,                 "MS Time Zone" },                                                               /* 7.7.52 */
752
753         { GTP_EXT_IMEISV,                               "IMEI(SV)" },                                                                   /* 3G */
754         { GTP_EXT_CAMEL_CHG_INF_CON,    "CAMEL Charging Information Container" },               /* 7.7.54 */
755         { GTP_EXT_MBMS_UE_CTX,                  "MBMS UE Context" },                                                    /* 7.7.55 */
756         { GTP_EXT_TMGI,                                 "Temporary Mobile Group Identity (TMGI)" },             /* 7.7.56 */
757         { GTP_EXT_RIM_RA,                               "RIM Routing Address" },                                                /* 7.7.57 */
758         { GTP_EXT_MBMS_PROT_CONF_OPT,   "MBMS Protocol Configuration Options" },                /* 7.7.58 */
759         { GTP_EXT_MBMS_SA,                              "MBMS Service Area" },                                                  /* 7.7.60 */
760         { GTP_EXT_SRC_RNC_PDP_CTX_INF,  "Source RNC PDCP context info" },                               /* 7.7.61 */
761         { GTP_EXT_ADD_TRS_INF,                  "Additional Trace Info" },                                              /* 7.7.62 */
762         { GTP_EXT_HOP_COUNT,                            "Hop Counter" },                                                        /* 7.7.63 */
763         { GTP_EXT_SEL_PLMN_ID,                  "Selected PLMN ID" },                                                   /* 7.7.64 */
764         { GTP_EXT_MBMS_SES_ID,                  "MBMS Session Identifier" },                                    /* 7.7.65 */
765         { GTP_EXT_MBMS_2G_3G_IND,               "MBMS 2G/3G Indicator" },                                               /* 7.7.66 */
766         { GTP_EXT_ENH_NSAPI,                    "Enhanced NSAPI" },                                                             /* 7.7.67 */
767         { GTP_EXT_MBMS_SES_DUR,                 "MBMS Session Duration" },                                              /* 7.7.59 */
768         { GTP_EXT_ADD_MBMS_TRS_INF,             "Additional MBMS Trace Info" },                                 /* 7.7.68 */
769         { GTP_EXT_MBMS_SES_ID_REP_NO,   "MBMS Session Identity Repetition Number" },    /* 7.7.69 */
770         { GTP_EXT_MBMS_TIME_TO_DATA_TR, "MBMS Time To Data Transfer" },                                 /* 7.7.70 */
771         { GTP_EXT_PS_HO_REQ_CTX,                "PS Handover Request Context" },                                /* 7.7.71 */
772         { GTP_EXT_BSS_CONT,                             "BSS Container" },                                                              /* 7.7.72 */
773         { GTP_EXT_CELL_ID,                              "Cell Identification" },                                                /* 7.7.73 */
774         { GTP_EXT_PDU_NO,                               "PDU Numbers" },                                                                /* 7.7.74 */
775         { GTP_EXT_BSSGP_CAUSE,                  "BSSGP Cause" },                                                                /* 7.7.75 */
776         { GTP_EXT_REL_PACK,                             "Sequence numbers of released packets IE" },    /* charging */
777         { GTP_EXT_CAN_PACK,                             "Sequence numbers of canceled packets IE" },    /* charging */
778         { GTP_EXT_CHRG_ADDR,                    "Charging Gateway address" },   
779         { GTP_EXT_DATA_REQ,                             "Data record packet" },                                                 /* charging */
780         { GTP_EXT_DATA_RESP,                    "Requests responded" },                                                 /* charging */
781         { GTP_EXT_NODE_ADDR,                    "Address of recommended node" },                                /* charging */
782         { GTP_EXT_PRIV_EXT,                     "Private Extension" },
783         { 0, NULL }
784 };
785 /* GPRS:        9.60 v7.6.0, page 37
786  * UMTS:        29.060 v4.0, page 45
787  */
788 static const value_string cause_type[] = {
789         { 0,    "Request IMSI" },
790         { 1,    "Request IMEI" },
791         { 2,    "Request IMSI and IMEI" },
792         { 3,    "No identity needed" },
793         { 4,    "MS refuses" },
794         { 5,    "MS is not GPRS responding" },
795         { 59,   "System failure" },     /* charging */
796         { 60,   "The transmit buffers are becoming full" },     /* charging */
797         { 61,   "The receive buffers are becoming full" },      /* charging */
798         { 62,   "Another node is about to go down" },   /* charging */
799         { 63,   "This node is about to go down" },      /* charging */
800         { 128,  "Request accepted" },
801         { 192,  "Non-existent" },
802         { 193,  "Invalid message format" },
803         { 194,  "IMSI not known" },
804         { 195,  "MS is GPRS detached" },
805         { 196,  "MS is not GPRS responding" },
806         { 197,  "MS refuses" },
807         { 198,  "Version not supported" },
808         { 199,  "No resource available" },
809         { 200,  "Service not supported" },
810         { 201,  "Mandatory IE incorrect" },
811         { 202,  "Mandatory IE missing" },
812         { 203,  "Optional IE incorrect" },
813         { 204,  "System failure" },
814         { 205,  "Roaming restriction" },
815         { 206,  "P-TMSI signature mismatch" },
816         { 207,  "GPRS connection suspended" },
817         { 208,  "Authentication failure" },
818         { 209,  "User authentication failed" },
819         { 210,  "Context not found" },
820         { 211,  "All PDP dynamic addresses are occupied" },
821         { 212,  "No memory is available" },
822         { 213,  "Relocation failure" },
823         { 214,  "Unknown mandatory extension header" },
824         { 215,  "Semantic error in the TFT operation" },
825         { 216,  "Syntactic error in the TFT operation" },
826         { 217,  "Semantic errors in packet filter(s)" },
827         { 218,  "Syntactic errors in packet filter(s)" },
828         { 219,  "Missing or unknown APN" },
829         { 220,  "Unknown PDP address or PDP type" },
830         { 221,  "PDP context without TFT already activated" },
831         { 222,  "APN access denied - no subscription" },
832         { 223,  "APN Restriction type incompatibility with currently active PDP Contexts" },
833         { 224,  "MS MBMS Capabilities Insufficient" },
834         { 252,  "Request related to possibly duplicated packets already fulfilled" },   /* charging */
835         { 253,  "Request already fulfilled" },  /* charging */
836         { 254,  "Sequence numbers of released/cancelled packets IE incorrect" },        /* charging */
837         { 255,  "Request not fulfilled" },      /* charging */
838         { 0, NULL }
839 };
840
841 /* GPRS:        9.02 v7.7.0
842  * UMTS:        29.002 v4.2.1, chapter 17.5, page 268
843  * Imported gsm_map_GSMMAPLocalErrorcode_vals from gsm_map from gsm_map
844  */
845
846 static const value_string gsn_addr_type[] = {
847         { 0x00, "IPv4" },
848         { 0x01, "IPv6" },
849         { 0,    NULL },
850 };
851
852 static const value_string pdp_type[] = {
853         { 0x00, "X.25" },
854         { 0x01, "PPP" },
855         { 0x02, "OSP:IHOSS" },
856         { 0x21, "IPv4" },
857         { 0x57, "IPv6" },
858         { 0, NULL }
859 };
860
861 static const value_string pdp_org_type[] = {
862         { 0, "ETSI" },
863         { 1, "IETF" },
864         { 0, NULL }
865 };
866
867 static const value_string qos_delay_type[] = {
868         { 0x00, "Subscribed delay class (in MS to network direction)" },
869         { 0x01, "Delay class 1" },
870         { 0x02, "Delay class 2" },
871         { 0x03, "Delay class 3" },
872         { 0x04, "Delay class 4 (best effort)" },
873         { 0x07, "Reserved" },
874         { 0, NULL }
875 };
876
877 static const value_string qos_reliability_type[] = {
878         { 0x00, "Subscribed reliability class (in MS to network direction)" },
879         { 0x01, "Ack GTP/LLC/RLC, Protected data" },
880         { 0x02, "Unack GTP, Ack LLC/RLC, Protected data" },
881         { 0x03, "Unack GTP/LLC, Ack RLC, Protected data" },
882         { 0x04, "Unack GTP/LLC/RLC, Protected data" },
883         { 0x05, "Unack GTP/LLC/RLC, Unprotected data" },
884         { 0x07, "Reserved" },
885         { 0, NULL }
886 };
887
888 static const value_string qos_peak_type[] = {
889         { 0x00, "Subscribed peak throughput (in MS to network direction)" },
890         { 0x01, "Up to 1 000 oct/s" },
891         { 0x02, "Up to 2 000 oct/s" },
892         { 0x03, "Up to 4 000 oct/s" },
893         { 0x04, "Up to 8 000 oct/s" },
894         { 0x05, "Up to 16 000 oct/s" },
895         { 0x06, "Up to 32 000 oct/s" },
896         { 0x07, "Up to 64 000 oct/s" },
897         { 0x08, "Up to 128 000 oct/s" },
898         { 0x09, "Up to 256 000 oct/s" },
899 /* QoS Peak throughput classes from 0x0A to 0x0F (from 10 to 15) are subscribed */
900         { 0x0A, "Reserved" },
901         { 0x0B, "Reserved" },
902         { 0x0C, "Reserved" },
903         { 0x0D, "Reserved" },
904         { 0x0E, "Reserved" },
905         { 0x0F, "Reserved" },
906         { 0, NULL }
907 };
908
909 static const value_string qos_precedence_type[] = {
910         { 0x00, "Subscribed precedence (in MS to network direction)" },
911         { 0x01, "High priority" },
912         { 0x02, "Normal priority" },
913         { 0x03, "Low priority" },
914         { 0x07, "Reserved" },
915         { 0, NULL }
916 };
917
918 static const value_string qos_mean_type[] = {
919         { 0x00, "Subscribed mean throughput (in MS to network direction)" },
920         { 0x01, "100 oct/h" },          /* Class 2 */
921         { 0x02, "200 oct/h" },          /* Class 3 */
922         { 0x03, "500 oct/h" },          /* Class 4 */
923         { 0x04, "1 000 oct/h" },        /* Class 5 */
924         { 0x05, "2 000 oct/h" },        /* Class 6 */
925         { 0x06, "5 000 oct/h" },        /* Class 7 */
926         { 0x07, "10 000 oct/h" },       /* Class 8 */
927         { 0x08, "20 000 oct/h" },       /* Class 9 */
928         { 0x09, "50 000 oct/h" },       /* Class 10 */
929         { 0x0A, "100 000 oct/h" },      /* Class 11 */
930         { 0x0B, "200 000 oct/h" },      /* Class 12 */
931         { 0x0C, "500 000 oct/h" },      /* Class 13 */
932         { 0x0D, "1 000 000 oct/h" },    /* Class 14 */
933         { 0x0E, "2 000 000 oct/h" },    /* Class 15 */
934         { 0x0F, "5 000 000 oct/h" },    /* Class 16 */
935         { 0x10, "10 000 000 oct/h" },   /* Class 17 */
936         { 0x11, "20 000 000 oct/h" },   /* Class 18 */
937         { 0x12, "50 000 000 oct/h" },   /* Class 19 */
938 /* QoS Mean throughput classes from 0x13 to 0x1E (from 19 to 30) are subscribed */
939         { 0x13, "Reserved" },
940         { 0x14, "Reserved" },
941         { 0x15, "Reserved" },
942         { 0x16, "Reserved" },
943         { 0x17, "Reserved" },
944         { 0x18, "Reserved" },
945         { 0x19, "Reserved" },
946         { 0x1A, "Reserved" },
947         { 0x1B, "Reserved" },
948         { 0x1C, "Reserved" },
949         { 0x1D, "Reserved" },
950         { 0x1E, "Reserved" },
951         { 0x1F, "Best effort" },        /* Class 1 */
952         { 0, NULL }
953 };
954
955 static const value_string qos_del_err_sdu[] = {
956         { 0x00, "Subscribed delivery of erroneous SDUs (in MS to network direction)" },
957         { 0x01, "No detect ('-')" },
958         { 0x02, "Erroneous SDUs are delivered ('yes')" },
959         { 0x03, "Erroneous SDUs are not delivered ('no')" },
960         { 0x07, "Reserved" },           /* All other values are reserved */
961         { 0, NULL }
962 };
963
964 static const value_string qos_del_order[] = {
965         { 0x00, "Subscribed delivery order (in MS to network direction)" },
966         { 0x01, "With delivery order ('yes')" },
967         { 0x02, "Without delivery order ('no')" },
968         { 0x03, "Reserved" },           /* All other values are reserved */
969         { 0, NULL }
970 };
971
972 static const value_string qos_traf_class[] = {
973         { 0x00, "Subscribed traffic class (in MS to network direction)" },
974         { 0x01, "Conversational class" },
975         { 0x02, "Streaming class" },
976         { 0x03, "Interactive class" },
977         { 0x04, "Background class" },
978         { 0x07, "Reserved" },           /* All other values are reserved */
979         { 0, NULL }
980 };
981
982 static const value_string qos_max_sdu_size[] = {
983         { 0x00, "Subscribed maximum SDU size (in MS to network direction" },
984         /* For values from 0x01 to 0x96 (from 1 to 150), use a granularity of 10 octets */
985         { 0x97, "1502 octets" },
986         { 0x98, "1510 octets" },
987         { 0x99, "1520 octets" },
988         { 0, NULL }                                     /* All other values are reserved */
989 };
990
991 static const value_string qos_max_ul[] = {
992         { 0x00, "Subscribed maximum 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_max_dl[] = {
1001         { 0x00, "Subscribed maximum 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 qos_res_ber[] = {
1010         { 0x00, "Subscribed residual BER (in MS to network direction)" },
1011         { 0x01, "1/20 = 5x10^-2" },
1012         { 0x02, "1/100 = 1x10^-2" },
1013         { 0x03, "1/200 = 5x10^-3" },
1014         { 0x04, "1/250 = 4x10^-3" },
1015         { 0x05, "1/1 000 = 1x10^-3" },
1016         { 0x06, "1/10 000 = 1x10^-4" },
1017         { 0x07, "1/100 000 = 1x10^-5" },
1018         { 0x08, "1/1 000 000 = 1x10^-6" },
1019         { 0x09, "3/50 000 000 = 6x10^-8" },
1020         { 0x0F, "Reserved" },           /* All other values are reserved */
1021         { 0, NULL }
1022 };
1023
1024 static const value_string qos_sdu_err_ratio[] = {
1025         { 0x00, "Subscribed SDU error ratio (in MS to network direction)" },
1026         { 0x01, "1/100 = 1x10^-2" },
1027         { 0x02, "7/1000 = 7x10^-3" },
1028         { 0x03, "1/1 000 = 1x10^-3" },
1029         { 0x04, "1/10 000 = 1x10^-4" },
1030         { 0x05, "1/100 000 = 1x10^-5" },
1031         { 0x06, "1/1 000 000 = 1x10^-6" },
1032         { 0x07, "1/10 = 1x10^-1" },
1033         { 0x0F, "Reserved" },           /* All other values are reserved */
1034         { 0, NULL }
1035 };
1036
1037 static const value_string qos_traf_handl_prio[] = {
1038         { 0x00, "Subscribed traffic handling priority (in MS to network direction)" },
1039         { 0x01, "Priority level 1" },
1040         { 0x02, "Priority level 2" },
1041         { 0x03, "Priority level 3" },
1042         { 0, NULL }
1043 };
1044
1045 static const value_string qos_trans_delay[] = {
1046         { 0x00, "Subscribed Transfer Delay (in MS to network direction)" },
1047         { 0x01, "10 ms" },      /* Using a granularity of 10 ms */
1048         { 0x02, "20 ms" },
1049         { 0x03, "30 ms" },
1050         { 0x04, "40 ms" },
1051         { 0x05, "50 ms" },
1052         { 0x06, "60 ms" },
1053         { 0x07, "70 ms" },
1054         { 0x08, "80 ms" },
1055         { 0x09, "90 ms" },
1056         { 0x0A, "100 ms" },
1057         { 0x0B, "110 ms" },
1058         { 0x0C, "120 ms" },
1059         { 0x0D, "130 ms" },
1060         { 0x0E, "140 ms" },
1061         { 0x0F, "150 ms" },
1062         { 0x10, "200 ms" },     /* (For values from 0x10 to 0x1F, value = 200 ms + (value - 0x10) * 50 ms */
1063         { 0x11, "250 ms" },
1064         { 0x12, "300 ms" },
1065         { 0x13, "350 ms" },
1066         { 0x14, "400 ms" },
1067         { 0x15, "450 ms" },
1068         { 0x16, "500 ms" },
1069         { 0x17, "550 ms" },
1070         { 0x18, "600 ms" },
1071         { 0x19, "650 ms" },
1072         { 0x1A, "700 ms" },
1073         { 0x1B, "750 ms" },
1074         { 0x1C, "800 ms" },
1075         { 0x1D, "850 ms" },
1076         { 0x1E, "900 ms" },
1077         { 0x1F, "950 ms" },
1078         { 0x20, "1000 ms" },    /* For values from 0x20 to 0x3E, value = 1000 ms + (value - 0x20) * 100 ms */
1079         { 0x21, "1100 ms" },
1080         { 0x22, "1200 ms" },
1081         { 0x23, "1300 ms" },
1082         { 0x24, "1400 ms" },
1083         { 0x25, "1500 ms" },
1084         { 0x26, "1600 ms" },
1085         { 0x27, "1700 ms" },
1086         { 0x28, "1800 ms" },
1087         { 0x29, "1900 ms" },
1088         { 0x2A, "2000 ms" },
1089         { 0x2B, "2100 ms" },
1090         { 0x2C, "2200 ms" },
1091         { 0x2D, "2300 ms" },
1092         { 0x2E, "2400 ms" },
1093         { 0x2F, "2500 ms" },
1094         { 0x30, "2600 ms" },
1095         { 0x31, "2700 ms" },
1096         { 0x32, "2800 ms" },
1097         { 0x33, "2900 ms" },
1098         { 0x34, "3000 ms" },
1099         { 0x35, "3100 ms" },
1100         { 0x36, "3200 ms" },
1101         { 0x37, "3300 ms" },
1102         { 0x38, "3400 ms" },
1103         { 0x39, "3500 ms" },
1104         { 0x3A, "3600 ms" },
1105         { 0x3B, "3700 ms" },
1106         { 0x3C, "3800 ms" },
1107         { 0x3D, "3900 ms" },
1108         { 0x3E, "4000 ms" },
1109         { 0x3F, "Reserved"},
1110         { 0, NULL }
1111 };
1112
1113 static const value_string qos_guar_ul[] = {
1114         { 0x00, "Subscribed guaranteed bit rate for uplink (in MS to network direction)" },
1115         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
1116         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
1117         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
1118         { 0xFF, "0 kbps" },
1119         { 0, NULL }
1120 };
1121
1122 static const value_string qos_guar_dl[] = {
1123         { 0x00, "Subscribed guaranteed bit rate for downlink (in MS to network direction)" },
1124         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
1125         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
1126         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
1127         { 0xFF, "0 kbps" },
1128         { 0, NULL }
1129 };
1130
1131 static const value_string sel_mode_type[] = {
1132         { 0,    "MS or network provided APN, subscribed verified" },
1133         { 1,    "MS provided APN, subscription not verified" },
1134         { 2,    "Network provided APN, subscription not verified" },
1135         { 3,    "For future use (Network provided APN, subscription not verified" },/* Shall not be sent. If received, shall be sent as value 2 */
1136         { 0,    NULL }
1137 };
1138
1139 static const value_string tr_comm_type[] = {
1140         { 1,    "Send data record packet" },
1141         { 2,    "Send possibly duplicated data record packet" },
1142         { 3,    "Cancel data record packet" },
1143         { 4,    "Release data record packet"},
1144         { 0,    NULL }
1145 };
1146
1147 /* TODO: CHeck if all ms_reasons are included */
1148 static const value_string ms_not_reachable_type[] = {
1149         { 0,    "No paging response via the MSC" },
1150         { 1,    "IMSI detached" },
1151         { 2,    "Roaming restriction" },
1152         { 3,    "Deregistered in the HLR for non GPRS" },
1153         { 4,    "MS purge for non GPRS" },
1154         { 5,    "No paging response via the SGSN" },
1155         { 6,    "GPRS detached" },
1156         { 7,    "Deregistered in the HLR for non GPRS" },
1157         { 8,    "MS purged for GPRS" },
1158         { 9,    "Unidentified subscriber via the MSC" },
1159         { 10,   "Unidentified subscriber via the SGSN" },
1160         { 0,    NULL }
1161 };
1162
1163 /* UMTS:        25.413 v3.4.0, chapter 9.2.1.4, page 80
1164  */
1165 static const value_string ranap_cause_type[] = {
1166 /* Radio Network Layer Cause (1-->64) */
1167         { 1, "RAB preempted" },
1168         { 2, "Trelocoverall Expiry" },
1169         { 3, "Trelocprep Expiry" },
1170         { 4, "Treloccomplete Expiry" },
1171         { 5, "Tqueing Expiry" },
1172         { 6, "Relocation Triggered" },
1173         { 7, "TRELOCalloc Expiry" },
1174         { 8, "Unable to Estabish During Relocation" },
1175         { 9, "Unknown Target RNC" },
1176         { 10, "Relocation Cancelled" },
1177         { 11, "Successful Relocation" },
1178         { 12, "Requested Ciphering and/or Integrity Protection Algorithms not Supported" },
1179         { 13, "Change of Ciphering and/or Integrity Protection is not supported" },
1180         { 14, "Failure in the Radio Interface Procedure" },
1181         { 15, "Release due to UTRAN Generated Reason" },
1182         { 16, "User Inactivity" },
1183         { 17, "Time Critical Relocation" },
1184         { 18, "Requested Traffic Class not Available" },
1185         { 19, "Invalid RAB Parameters Value" },
1186         { 20, "Requested Maximum Bit Rate not Available" },
1187         { 21, "Requested Guaranteed Bit Rate not Available" },
1188         { 22, "Requested Transfer Delay not Achievable" },
1189         { 23, "Invalid RAB Parameters Combination" },
1190         { 24, "Condition Violation for SDU Parameters" },
1191         { 25, "Condition Violation for Traffic Handling Priority" },
1192         { 26, "Condition Violation for Guaranteed Bit Rate" },
1193         { 27, "User Plane Versions not Supported" },
1194         { 28, "Iu UP Failure" },
1195         { 29, "Relocation Failure in Target CN/RNC or Target System" },
1196         { 30, "Invalid RAB ID" },
1197         { 31, "No Remaining RAB" },
1198         { 32, "Interaction with other procedure" },
1199         { 33, "Requested Maximum Bit Rate for DL not Available" },
1200         { 34, "Requested Maximum Bit Rate for UL not Available" },
1201         { 35, "Requested Guaranteed Bit Rate for DL not Available" },
1202         { 36, "Requested Guaranteed Bit Rate for UL not Available" },
1203         { 37, "Repeated Integrity Checking Failure" },
1204         { 38, "Requested Report Type not supported" },
1205         { 39, "Request superseded" },
1206         { 40, "Release due to UE generated signalling connection release" },
1207         { 41, "Resource Optimisation Relocation" },
1208         { 42, "Requested Information Not Available" },
1209         { 43, "Relocation desirable for radio reasons" },
1210         { 44, "Relocation not supported in Target RNC or Target System" },
1211         { 45, "Directed Retry" },
1212         { 46, "Radio Connection With UE Lost" },
1213         {  47, "rNC-unable-to-establish-all-RFCs" },
1214         {  48, "deciphering-keys-not-available" },
1215         {  49, "dedicated-assistance-data-not-available" },
1216         {  50, "relocation-target-not-allowed" },
1217         {  51, "location-reporting-congestion" },
1218         {  52, "reduce-load-in-serving-cell" },
1219         {  53, "no-radio-resources-available-in-target-cell" },
1220         {  54, "gERAN-Iumode-failure" },
1221         {  55, "access-restricted-due-to-shared-networks" },
1222         {  56, "incoming-relocation-not-supported-due-to-PUESBINE-feature" },
1223         {  57, "traffic-load-in-the-target-cell-higher-than-in-the-source-cell" },
1224         {  58, "mBMS-no-multicast-service-for-this-UE" },
1225         {  59, "mBMS-unknown-UE-ID" },
1226         {  60, "successful-MBMS-session-start-no-data-bearer-necessary" },
1227         {  61, "mBMS-superseded-due-to-NNSF" },
1228         {  62, "mBMS-UE-linking-already-done" },
1229         {  63, "mBMS-UE-de-linking-failure-no-existing-UE-linking" },
1230         {  64, "tMGI-unknown" },
1231 /* Transport Layer Cause (65-->80) */
1232         { 65, "Signalling Transport Resource Failure" },
1233         { 66, "Iu Transport Connection Failed to Establish" },
1234 /* NAS Cause (81-->96) */
1235         { 81, "User Restriction Start Indication" },
1236         { 82, "User Restriction End Indication" },
1237         { 83, "Normal Release" },
1238 /* Protocol Cause (97-->112) */
1239         { 97, "Transfer Syntax Error" },
1240         { 98, "Semantic Error" },
1241         { 99, "Message not compatible with receiver state" },
1242         { 100, "Abstract Syntax Error (Reject)" },
1243         { 101, "Abstract Syntax Error (Ignore and Notify)" },
1244         { 102, "Abstract Syntax Error (Falsely Constructed Message" },
1245 /* Miscellaneous Cause (113-->128) */
1246         { 113, "O & M Intervention" },
1247         { 114, "No Resource Available" },
1248         { 115, "Unspecified Failure" },
1249         { 116, "Network Opimisation" },
1250 /* Non-standard Cause (129-->255) */
1251
1252 /* ranap_CauseRadioNetworkExtension ??
1253         { 257, "iP-multicast-address-and-APN-not-valid" },
1254         { 258, "mBMS-de-registration-rejected-due-to-implicit-registration" },
1255         { 259, "mBMS-request-superseded" },
1256         { 260, "mBMS-de-registration-during-session-not-allowed" },
1257         { 261, "mBMS-no-data-bearer-necessary" },
1258   */
1259
1260         { 0, NULL }
1261 };
1262
1263 static const value_string mm_sec_modep[] = {
1264         { 0,    "Used cipher value, UMTS keys and Quintuplets" },
1265         { 1,    "GSM key and triplets" },
1266         { 2,    "UMTS key and quintuplets" },
1267         { 3,    "GSM key and quintuplets" },
1268         { 0,    NULL }
1269 };
1270
1271 static const value_string gtp_cipher_algorithm[] = {
1272         { 0, "No ciphering" },
1273         { 1, "GEA/1" },
1274         { 2, "GEA/2" },
1275         { 3, "GEA/3" },
1276         { 4, "GEA/4" },
1277         { 5, "GEA/5" },
1278         { 6, "GEA/6" },
1279         { 7, "GEA/7" },
1280         { 0, NULL }
1281 };
1282
1283 static const value_string gtp_ext_rat_type_vals[] = {
1284         { 0,    "Reserved" },
1285         { 1,    "UTRAN" },
1286         { 2,    "GERAN" },
1287         { 3,    "WLAN" },
1288         { 0,    NULL }
1289 };
1290
1291
1292
1293 #define MM_PROTO_GROUP_CALL_CONTROL     0x00
1294 #define MM_PROTO_BROADCAST_CALL_CONTROL 0x01
1295 #define MM_PROTO_PDSS1                  0x02
1296 #define MM_PROTO_CALL_CONTROL           0x03
1297 #define MM_PROTO_PDSS2                  0x04
1298 #define MM_PROTO_MM_NON_GPRS            0x05
1299 #define MM_PROTO_RR_MGMT                0x06
1300 #define MM_PROTO_MM_GPRS                0x08
1301 #define MM_PROTO_SMS                    0x09
1302 #define MM_PROTO_SESSION_MGMT           0x0A
1303 #define MM_PROTO_NON_CALL_RELATED       0x0B
1304
1305 static const value_string tft_code_type[] = {
1306         { 0, "Spare" },
1307         { 1, "Create new TFT" },
1308         { 2, "Delete existing TFT" },
1309         { 3, "Add packet filters to existing TFT" },
1310         { 4, "Replace packet filters in existing TFT" },
1311         { 5, "Delete packet filters from existing TFT" },
1312         { 6, "Reserved" },
1313         { 7, "Reserved" },
1314         { 0, NULL }
1315 };
1316
1317
1318 static dissector_handle_t ip_handle;
1319 static dissector_handle_t ipv6_handle;
1320 static dissector_handle_t ppp_handle;
1321 static dissector_handle_t data_handle;
1322 static dissector_handle_t gtpcdr_handle;
1323 static dissector_table_t bssap_pdu_type_table=NULL;
1324
1325 static int decode_gtp_cause             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1326 static int decode_gtp_imsi              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1327 static int decode_gtp_rai               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1328 static int decode_gtp_tlli              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1329 static int decode_gtp_ptmsi             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1330 static int decode_gtp_qos_gprs          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1331 static int decode_gtp_reorder           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1332 static int decode_gtp_auth_tri          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1333 static int decode_gtp_map_cause         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1334 static int decode_gtp_ptmsi_sig         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1335 static int decode_gtp_ms_valid          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1336 static int decode_gtp_recovery          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1337 static int decode_gtp_sel_mode          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1338 static int decode_gtp_16                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1339 static int decode_gtp_17                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1340 static int decode_gtp_18                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1341 static int decode_gtp_19                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1342 static int decode_gtp_nsapi             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1343 static int decode_gtp_ranap_cause       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1344 static int decode_gtp_rab_cntxt         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1345 static int decode_gtp_rp_sms            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1346 static int decode_gtp_rp                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1347 static int decode_gtp_pkt_flow_id       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1348 static int decode_gtp_chrg_char         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1349 static int decode_gtp_trace_ref         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1350 static int decode_gtp_trace_type        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1351 static int decode_gtp_ms_reason         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1352 static int decode_gtp_tr_comm           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1353 static int decode_gtp_chrg_id           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1354 static int decode_gtp_user_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1355 static int decode_gtp_mm_cntxt          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1356 static int decode_gtp_pdp_cntxt         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1357 static int decode_gtp_apn               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1358 static int decode_gtp_gsn_addr          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1359 static int decode_gtp_proto_conf        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1360 static int decode_gtp_msisdn            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1361 static int decode_gtp_qos_umts          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1362 static int decode_gtp_auth_qui          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1363 static int decode_gtp_tft               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1364 static int decode_gtp_target_id         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1365 static int decode_gtp_utran_cont        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1366 static int decode_gtp_rab_setup         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1367 static int decode_gtp_hdr_list          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1368 static int decode_gtp_trigger_id        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1369 static int decode_gtp_omc_id            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1370
1371 static int decode_gtp_ran_tr_cont       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1372 static int decode_gtp_pdp_cont_prio     (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1373 static int decode_gtp_add_rab_setup_inf (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1374 static int decode_gtp_ssgn_no                   (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1375 static int decode_gtp_common_flgs               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1376 static int decode_gtp_apn_res                   (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1377 static int decode_gtp_ra_prio_lcs               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1378 static int decode_gtp_rat_type                  (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1379 static int decode_gtp_usr_loc_inf               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1380 static int decode_gtp_ms_time_zone              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1381 static int decode_gtp_imeisv                    (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1382 static int decode_gtp_camel_chg_inf_con (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1383 static int decode_gtp_mbms_ue_ctx               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1384 static int decode_gtp_tmgi                              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1385 static int decode_gtp_rim_ra                    (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1386 static int decode_gtp_mbms_prot_conf_opt        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1387 static int decode_gtp_mbms_sa                           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1388 static int decode_gtp_src_rnc_pdp_ctx_inf       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1389 static int decode_gtp_add_trs_inf                       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1390 static int decode_gtp_hop_count                 (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1391 static int decode_gtp_sel_plmn_id               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1392 static int decode_gtp_mbms_ses_id               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1393 static int decode_gtp_mbms_2g_3g_ind    (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1394 static int decode_gtp_enh_nsapi                 (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1395 static int decode_gtp_mbms_ses_dur              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1396 static int decode_gtp_add_mbms_trs_inf  (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1397 static int decode_gtp_mbms_ses_id_rep_no(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1398 static int decode_gtp_mbms_time_to_data_tr(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1399 static int decode_gtp_ps_ho_req_ctx     (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1400 static int decode_gtp_bss_cont          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1401 static int decode_gtp_cell_id           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1402 static int decode_gtp_pdu_no            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1403 static int decode_gtp_bssgp_cause       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1404
1405 static int decode_gtp_chrg_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1406 static int decode_gtp_rel_pack          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1407 static int decode_gtp_can_pack          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1408 static int decode_gtp_data_req          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1409 static int decode_gtp_data_resp         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1410 static int decode_gtp_node_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1411 static int decode_gtp_priv_ext          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1412 static int decode_gtp_unknown           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1413
1414 typedef struct _gtp_opt {
1415         int   optcode;
1416         int  (*decode)(tvbuff_t  *, int, packet_info *, proto_tree *);
1417 } gtp_opt_t;
1418
1419 static const gtp_opt_t gtpopt[] = {
1420         { GTP_EXT_CAUSE,                                decode_gtp_cause },
1421         { GTP_EXT_IMSI,                                 decode_gtp_imsi },
1422         { GTP_EXT_RAI,                                  decode_gtp_rai },
1423         { GTP_EXT_TLLI,                                 decode_gtp_tlli },
1424         { GTP_EXT_PTMSI,                                decode_gtp_ptmsi },
1425         { GTP_EXT_QOS_GPRS,                             decode_gtp_qos_gprs },
1426         { GTP_EXT_REORDER,                              decode_gtp_reorder },
1427         { GTP_EXT_AUTH_TRI,                             decode_gtp_auth_tri },
1428         { GTP_EXT_MAP_CAUSE,                    decode_gtp_map_cause },
1429         { GTP_EXT_PTMSI_SIG,                    decode_gtp_ptmsi_sig },
1430         { GTP_EXT_MS_VALID,                             decode_gtp_ms_valid },
1431         { GTP_EXT_RECOVER,                              decode_gtp_recovery },
1432         { GTP_EXT_SEL_MODE,                             decode_gtp_sel_mode },
1433         { GTP_EXT_16,                                   decode_gtp_16 },
1434         { GTP_EXT_17,                                   decode_gtp_17 },
1435         { GTP_EXT_18,                                   decode_gtp_18 },
1436         { GTP_EXT_19,                                   decode_gtp_19 },
1437         { GTP_EXT_NSAPI,                                decode_gtp_nsapi },
1438         { GTP_EXT_RANAP_CAUSE,                  decode_gtp_ranap_cause },
1439         { GTP_EXT_RAB_CNTXT,                    decode_gtp_rab_cntxt },
1440         { GTP_EXT_RP_SMS,                               decode_gtp_rp_sms },
1441         { GTP_EXT_RP,                                   decode_gtp_rp },
1442         { GTP_EXT_PKT_FLOW_ID,                  decode_gtp_pkt_flow_id },
1443         { GTP_EXT_CHRG_CHAR,                    decode_gtp_chrg_char },
1444         { GTP_EXT_TRACE_REF,                    decode_gtp_trace_ref },
1445         { GTP_EXT_TRACE_TYPE,                   decode_gtp_trace_type },
1446         { GTPv1_EXT_MS_REASON,                  decode_gtp_ms_reason },
1447         { GTP_EXT_TR_COMM,                              decode_gtp_tr_comm },
1448         { GTP_EXT_CHRG_ID,                              decode_gtp_chrg_id },
1449         { GTP_EXT_USER_ADDR,                    decode_gtp_user_addr },
1450         { GTP_EXT_MM_CNTXT,                             decode_gtp_mm_cntxt },
1451         { GTP_EXT_PDP_CNTXT,                    decode_gtp_pdp_cntxt },
1452         { GTP_EXT_APN,                                  decode_gtp_apn },
1453         { GTP_EXT_PROTO_CONF,                   decode_gtp_proto_conf },
1454         { GTP_EXT_GSN_ADDR,                             decode_gtp_gsn_addr },
1455         { GTP_EXT_MSISDN,                               decode_gtp_msisdn },
1456         { GTP_EXT_QOS_UMTS,                             decode_gtp_qos_umts },                          /* 3G */
1457         { GTP_EXT_AUTH_QUI,                             decode_gtp_auth_qui },                          /* 3G */
1458         { GTP_EXT_TFT,                                  decode_gtp_tft },                                       /* 3G */
1459         { GTP_EXT_TARGET_ID,                    decode_gtp_target_id },                         /* 3G */
1460         { GTP_EXT_UTRAN_CONT,                   decode_gtp_utran_cont },                        /* 3G */
1461         { GTP_EXT_RAB_SETUP,                    decode_gtp_rab_setup },                         /* 3G */
1462         { GTP_EXT_HDR_LIST,                             decode_gtp_hdr_list },                          /* 3G */
1463         { GTP_EXT_TRIGGER_ID,                   decode_gtp_trigger_id },                        /* 3G */
1464         { GTP_EXT_OMC_ID,                               decode_gtp_omc_id },                            /* 3G */
1465         /* TS 29 060 V6.11.0 */
1466         { GTP_EXT_RAN_TR_CONT,                  decode_gtp_ran_tr_cont },                               /* 7.7.43 */
1467         { GTP_EXT_PDP_CONT_PRIO,                decode_gtp_pdp_cont_prio },                             /* 7.7.45 */
1468         { GTP_EXT_ADD_RAB_SETUP_INF,    decode_gtp_add_rab_setup_inf },                 /* 7.7.45A */
1469         { GTP_EXT_SSGN_NO,                              decode_gtp_ssgn_no },                                   /* 7.7.47 */
1470         { GTP_EXT_COMMON_FLGS,                  decode_gtp_common_flgs },                               /* 7.7.48 */
1471         { GTP_EXT_APN_RES,                              decode_gtp_apn_res },                                   /* 3G */
1472         { GTP_EXT_RA_PRIO_LCS,                  decode_gtp_ra_prio_lcs },                               /* 7.7.25B */
1473         { GTP_EXT_RAT_TYPE,                             decode_gtp_rat_type },                                  /* 3G */
1474         { GTP_EXT_USR_LOC_INF,                  decode_gtp_usr_loc_inf},                                /* 7.7.51 */
1475         { GTP_EXT_MS_TIME_ZONE,                 decode_gtp_ms_time_zone},                               /* 7.7.52 */
1476         { GTP_EXT_IMEISV,                               decode_gtp_imeisv },                                    /* 3G 7.7.53*/
1477         { GTP_EXT_CAMEL_CHG_INF_CON,    decode_gtp_camel_chg_inf_con },                 /* 7.7.54 */
1478         { GTP_EXT_MBMS_UE_CTX,                  decode_gtp_mbms_ue_ctx },                               /* 7.7.55 */
1479         { GTP_EXT_TMGI,                                 decode_gtp_tmgi },                                              /* 7.7.56 */
1480         { GTP_EXT_RIM_RA,                               decode_gtp_rim_ra },                                    /* 7.7.57 */
1481         { GTP_EXT_MBMS_PROT_CONF_OPT,   decode_gtp_mbms_prot_conf_opt },                /* 7.7.58 */
1482         { GTP_EXT_MBMS_SA,                              decode_gtp_mbms_sa },                                   /* 7.7.60 */
1483         { GTP_EXT_SRC_RNC_PDP_CTX_INF,  decode_gtp_src_rnc_pdp_ctx_inf },               /* 7.7.61 */
1484         { GTP_EXT_ADD_TRS_INF,                  decode_gtp_add_trs_inf },                               /* 7.7.62 */
1485         { GTP_EXT_HOP_COUNT,                    decode_gtp_hop_count },                                 /* 7.7.63 */
1486         { GTP_EXT_SEL_PLMN_ID,                  decode_gtp_sel_plmn_id },                               /* 7.7.64 */
1487         { GTP_EXT_MBMS_SES_ID,                  decode_gtp_mbms_ses_id },                               /* 7.7.65 */
1488         { GTP_EXT_MBMS_2G_3G_IND,               decode_gtp_mbms_2g_3g_ind },                    /* 7.7.66 */
1489         { GTP_EXT_ENH_NSAPI,                    decode_gtp_enh_nsapi },                                 /* 7.7.67 */
1490         { GTP_EXT_MBMS_SES_DUR,                 decode_gtp_mbms_ses_dur },                              /* 7.7.59 */
1491         { GTP_EXT_ADD_MBMS_TRS_INF,             decode_gtp_add_mbms_trs_inf },                  /* 7.7.68 */
1492         { GTP_EXT_MBMS_SES_ID_REP_NO,   decode_gtp_mbms_ses_id_rep_no },                /* 7.7.69 */
1493         { GTP_EXT_MBMS_TIME_TO_DATA_TR, decode_gtp_mbms_time_to_data_tr },              /* 7.7.70 */
1494         { GTP_EXT_PS_HO_REQ_CTX,                decode_gtp_ps_ho_req_ctx },                             /* 7.7.71 */
1495         { GTP_EXT_BSS_CONT,                             decode_gtp_bss_cont },                                  /* 7.7.72 */
1496         { GTP_EXT_CELL_ID,                              decode_gtp_cell_id },                                   /* 7.7.73 */
1497         { GTP_EXT_PDU_NO,                               decode_gtp_pdu_no },                                    /* 7.7.74 */
1498         { GTP_EXT_BSSGP_CAUSE,                  decode_gtp_bssgp_cause },                               /* 7.7.75 */
1499
1500         { GTP_EXT_REL_PACK,             decode_gtp_rel_pack },                          /* charging */
1501         { GTP_EXT_CAN_PACK,             decode_gtp_can_pack },                          /* charging */
1502         { GTP_EXT_CHRG_ADDR,    decode_gtp_chrg_addr },
1503         { GTP_EXT_DATA_REQ,             decode_gtp_data_req },                          /* charging */
1504         { GTP_EXT_DATA_RESP,    decode_gtp_data_resp },                         /* charging */
1505         { GTP_EXT_NODE_ADDR,    decode_gtp_node_addr },
1506         { GTP_EXT_PRIV_EXT,             decode_gtp_priv_ext },
1507         { 0,                    decode_gtp_unknown }
1508 };
1509
1510 struct _gtp_hdr {
1511         guint8          flags;
1512         guint8          message;
1513         guint16         length;
1514 };
1515
1516 static  guint8          gtp_version = 0;
1517 static  const char      *yesno[] = { "no", "yes" };
1518
1519 static void
1520 col_append_str_gtp(column_info *cinfo, gint el, const gchar *proto_name) {
1521
1522         int     i;
1523         int     max_len;
1524         gchar   _tmp[COL_MAX_LEN];
1525
1526         max_len = COL_MAX_LEN;
1527
1528         for (i = 0; i < cinfo->num_cols; i++) {
1529                 if (cinfo->fmt_matx[i][el]) {
1530                         if (cinfo->col_data[i] != cinfo->col_buf[i]) {
1531
1532                                 strncpy(cinfo->col_buf[i], cinfo->col_data[i], max_len);
1533                                 cinfo->col_buf[i][max_len - 1] = '\0';
1534                         }
1535
1536                         _tmp[0] = '\0';
1537                         strcat(_tmp, proto_name);
1538                         strcat(_tmp, " <");
1539                         strcat(_tmp, cinfo->col_buf[i]);
1540                         strcat(_tmp, ">");
1541                         cinfo->col_buf[i][0] = '\0';
1542                         strcat(cinfo->col_buf[i], _tmp);
1543                         cinfo->col_data[i] = cinfo->col_buf[i];
1544                 }
1545         }
1546 }
1547
1548 static gchar *
1549 id_to_str(const guint8 *ad) {
1550
1551         static gchar    str[17] = "                ";
1552         guint8          bits8to5, bits4to1;
1553         int             i, j = 0;
1554         static const    gchar hex_digits[10] = "0123456789";
1555
1556         for (i = 0; i < 8; i++) {
1557                 bits8to5 = (ad[i] >> 4) & 0x0F;
1558                 bits4to1 = ad[i] & 0x0F;
1559                 if (bits4to1 < 0xA)
1560                         str[j++] = hex_digits[bits4to1];
1561                 if (bits8to5 < 0xA)
1562                         str[j++] = hex_digits[bits8to5];
1563         }
1564         str[j] = '\0';
1565         return str;
1566 }
1567
1568 static gchar *
1569 imsi_to_str(const guint8 *ad) {
1570
1571         static gchar    str[17] = "                ";
1572         int             i, j = 0;
1573
1574         for (i = 0; i < 8; i++) {
1575                 if ((ad[i] & 0x0F) <= 9) str[j++] = (ad[i] & 0x0F) + 0x30;
1576                 if (((ad[i] >> 4) & 0x0F) <= 9) str[j++] = ((ad[i] >> 4) & 0x0F) + 0x30;
1577         }
1578         str[j] = '\0';
1579
1580         return str;
1581 }
1582
1583 static gchar *
1584 msisdn_to_str(const guint8 *ad, int len) {
1585
1586         static gchar    str[18] = "+                ";
1587         guint8          bits8to5, bits4to1;
1588         int             i, j = 1;
1589         static const    gchar hex_digits[10] = "0123456789";
1590
1591         for (i = 1; i < len && i < 9; i++) {
1592                 bits8to5 = (ad[i] >> 4) & 0x0F;
1593                 bits4to1 = ad[i] & 0x0F;
1594                 if (bits4to1 < 0xA)
1595                         str[j++] = hex_digits[bits4to1];
1596                 if (bits8to5 < 0xA)
1597                         str[j++] = hex_digits[bits8to5];
1598         }
1599         str[j] = '\0';
1600
1601         return str;
1602 }
1603
1604 /* Next definitions and function check_field_presence checks if given field
1605  * in GTP packet is compliant with ETSI
1606  */
1607 typedef struct _header {
1608         guint8          code;
1609         guint8          presence;
1610 } ext_header;
1611
1612 typedef struct _message {
1613         guint8          code;
1614         ext_header      fields[32];
1615 } _gtp_mess_items;
1616
1617 /* ---------------------
1618  * GPRS messages
1619  * ---------------------*/
1620 static _gtp_mess_items gprs_mess_items[] = {
1621
1622 {
1623         GTP_MSG_ECHO_REQ, {
1624                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1625                 { 0,                    0 }
1626         }
1627 },
1628 {
1629         GTP_MSG_ECHO_RESP, {
1630                 { GTP_EXT_RECOVER,      GTP_MANDATORY },
1631                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1632                 { 0,                    0 }
1633         }
1634 },
1635 {
1636         GTP_MSG_VER_NOT_SUPP, {
1637                 { 0,                    0 }
1638         }
1639 },
1640 {
1641         GTP_MSG_NODE_ALIVE_REQ, {
1642                 { GTP_EXT_NODE_ADDR,    GTP_MANDATORY },
1643                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1644                 { 0,                    0 }
1645         }
1646 },
1647 {
1648         GTP_MSG_NODE_ALIVE_RESP, {
1649                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1650                 { 0,                    0 }
1651         }
1652 },
1653 {
1654         GTP_MSG_REDIR_REQ, {
1655                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1656                 { GTP_EXT_NODE_ADDR,    GTP_OPTIONAL },
1657                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1658                 { 0,                    0 }
1659         }
1660 },
1661 {
1662         GTP_MSG_REDIR_RESP, {
1663                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1664                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1665                 { 0,                    0 }
1666         }
1667 },
1668 {
1669         GTP_MSG_CREATE_PDP_REQ, {
1670                 { GTP_EXT_QOS_GPRS,     GTP_MANDATORY },
1671                 { GTP_EXT_RECOVER,              GTP_OPTIONAL },
1672                 { GTP_EXT_SEL_MODE,     GTP_MANDATORY },
1673                 { GTP_EXT_FLOW_LABEL,   GTP_MANDATORY },
1674                 { GTP_EXT_FLOW_SIG,             GTP_MANDATORY },
1675                 { GTP_EXT_MSISDN,               GTP_MANDATORY },
1676                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1677                 { GTP_EXT_APN,                  GTP_MANDATORY },
1678                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1679                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
1680                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
1681                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
1682                 { 0,                    0 }
1683         }
1684 },
1685 {
1686         GTP_MSG_CREATE_PDP_RESP, {
1687                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1688                 { GTP_EXT_QOS_GPRS,     GTP_CONDITIONAL },
1689                 { GTP_EXT_REORDER,      GTP_CONDITIONAL },
1690                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1691                 { GTP_EXT_FLOW_LABEL,   GTP_CONDITIONAL },
1692                 { GTP_EXT_FLOW_SIG,     GTP_CONDITIONAL },
1693                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
1694                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
1695                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1696                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1697                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1698                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
1699                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1700                 { 0,                    0 }
1701         }
1702 },
1703 {
1704         GTP_MSG_UPDATE_PDP_REQ, {
1705                 { GTP_EXT_QOS_GPRS,     GTP_MANDATORY },
1706                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1707                 { GTP_EXT_FLOW_LABEL,   GTP_MANDATORY },
1708                 { GTP_EXT_FLOW_SIG,     GTP_MANDATORY },
1709                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1710                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1711                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1712                 { 0,                    0 },
1713         }
1714 },
1715 {
1716         GTP_MSG_UPDATE_PDP_RESP, {
1717                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1718                 { GTP_EXT_QOS_GPRS,     GTP_CONDITIONAL },
1719                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1720                 { GTP_EXT_FLOW_LABEL,   GTP_CONDITIONAL },
1721                 { GTP_EXT_FLOW_SIG,     GTP_CONDITIONAL },
1722                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
1723                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1724                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1725                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
1726                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1727                 { 0,                    0 }
1728         }
1729 },
1730 {
1731         GTP_MSG_DELETE_PDP_REQ, {
1732                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1733                 { 0,                    0 }
1734         }
1735 },
1736 {
1737         GTP_MSG_DELETE_PDP_RESP, {
1738                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1739                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1740                 { 0,                    0 },
1741         }
1742 },
1743 {
1744         GTP_MSG_CREATE_AA_PDP_REQ, {
1745                 { GTP_EXT_QOS_GPRS,     GTP_MANDATORY },
1746                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1747                 { GTP_EXT_SEL_MODE,     GTP_MANDATORY },
1748                 { GTP_EXT_FLOW_LABEL,   GTP_MANDATORY },
1749                 { GTP_EXT_FLOW_SIG,     GTP_MANDATORY },
1750                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1751                 { GTP_EXT_APN,          GTP_MANDATORY },
1752                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1753                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1754                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1755                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1756                 { 0,                    0 }
1757         }
1758 },
1759 {
1760         GTP_MSG_CREATE_AA_PDP_RESP, {
1761                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1762                 { GTP_EXT_QOS_GPRS,     GTP_CONDITIONAL },
1763                 { GTP_EXT_REORDER,      GTP_CONDITIONAL },
1764                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1765                 { GTP_EXT_FLOW_LABEL,   GTP_CONDITIONAL },
1766                 { GTP_EXT_FLOW_SIG,     GTP_CONDITIONAL },
1767                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
1768                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
1769                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1770                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1771                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1772                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
1773                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1774                 { 0,                    0 }
1775         }
1776 },
1777 {
1778         GTP_MSG_DELETE_AA_PDP_REQ, {
1779                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1780                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1781                 { 0,                    0 }
1782         }
1783 },
1784 {
1785         GTP_MSG_DELETE_AA_PDP_RESP, {
1786                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1787                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1788                 { 0,                    0 }
1789         }
1790 },
1791 {
1792         GTP_MSG_ERR_IND, {
1793                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1794                 { 0,                    0 }
1795         }
1796 },
1797 {
1798         GTP_MSG_PDU_NOTIFY_REQ, {
1799                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1800                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1801                 { 0,                    0 }
1802         }
1803 },
1804 {
1805         GTP_MSG_PDU_NOTIFY_RESP, {
1806                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1807                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1808                 { 0,                    0 }
1809         }
1810 },
1811 {
1812         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
1813                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1814                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1815                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1816                 { 0,                    0 }
1817         }
1818 },
1819 {
1820         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
1821                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1822                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1823                 { 0,                    0 }
1824         }
1825 },
1826 {
1827         GTP_MSG_SEND_ROUT_INFO_REQ, {
1828                 { GTP_EXT_IMSI,         GTP_MANDATORY },
1829                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1830                 { 0,                    0 }
1831         }
1832 },
1833 {
1834         GTP_MSG_SEND_ROUT_INFO_RESP, {
1835                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
1836                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
1837                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
1838                 { GTP_EXT_MS_REASON,    GTP_OPTIONAL },
1839                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },
1840                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
1841                 { 0,                    0 }
1842         }
1843 },
1844 {
1845         GTP_MSG_FAIL_REP_REQ, {
1846                 { GTP_EXT_IMSI,         GTP_MANDATORY },
1847                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1848                 { 0,                    0 }
1849         }
1850 },
1851 {
1852         GTP_MSG_FAIL_REP_RESP, {
1853                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1854                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
1855                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1856                 { 0,                    0 }
1857         }
1858 },
1859 {
1860         GTP_MSG_MS_PRESENT_REQ, {
1861                 { GTP_EXT_IMSI,         GTP_MANDATORY },
1862                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1863                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1864                 { 0,                    0 }
1865         }
1866 },
1867 {
1868         GTP_MSG_MS_PRESENT_RESP, {
1869                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1870                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1871                 { 0,                    0 }
1872         }
1873 },
1874 {
1875         GTP_MSG_IDENT_REQ, {
1876                 { GTP_EXT_RAI,                  GTP_MANDATORY },
1877                 { GTP_EXT_PTMSI,                GTP_MANDATORY },
1878                 { GTP_EXT_PTMSI_SIG,    GTP_OPTIONAL },
1879                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
1880                 { 0,                    0 }
1881         }
1882 },
1883 {
1884         GTP_MSG_IDENT_RESP, {
1885                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
1886                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
1887                 { GTP_EXT_AUTH_TRI,             GTP_OPTIONAL },
1888                 { GTP_EXT_AUTH_QUI,             GTP_OPTIONAL },
1889                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
1890                 { 0,                    0 }
1891         }
1892 },
1893 {
1894         GTP_MSG_SGSN_CNTXT_REQ, {
1895                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
1896                 { GTP_EXT_RAI,                  GTP_MANDATORY },
1897                 { GTP_EXT_TLLI,                 GTP_MANDATORY },
1898                 { GTP_EXT_PTMSI_SIG,    GTP_OPTIONAL },
1899                 { GTP_EXT_MS_VALID,             GTP_OPTIONAL },
1900                 { GTP_EXT_FLOW_SIG,     GTP_MANDATORY },
1901                 { 0,                    0 }
1902         }
1903 },
1904 {
1905         GTP_MSG_SGSN_CNTXT_RESP, {
1906                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
1907                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
1908                 { GTP_EXT_FLOW_SIG,             GTP_CONDITIONAL },
1909                 { GTP_EXT_MM_CNTXT,             GTP_CONDITIONAL },
1910                 { GTP_EXT_PDP_CNTXT,    GTP_CONDITIONAL },
1911                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
1912                 { 0,                    0 }
1913         }
1914 },
1915 {
1916         GTP_MSG_SGSN_CNTXT_ACK, {
1917                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1918                 { GTP_EXT_FLOW_II,      GTP_CONDITIONAL },
1919                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1920                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1921                 { 0,                    0 }
1922         }
1923 },
1924 {
1925         GTP_MSG_DATA_TRANSF_REQ, {
1926                 { GTP_EXT_TR_COMM,      GTP_MANDATORY },
1927                 { GTP_EXT_DATA_REQ,     GTP_CONDITIONAL },
1928                 { GTP_EXT_REL_PACK,     GTP_CONDITIONAL },
1929                 { GTP_EXT_CAN_PACK,     GTP_CONDITIONAL },
1930                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1931                 { 0,                    0 }
1932         }
1933 },
1934 {
1935         GTP_MSG_DATA_TRANSF_RESP, {
1936                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1937                 { GTP_EXT_DATA_RESP,    GTP_MANDATORY },
1938                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1939                 { 0,                    0 }
1940         }
1941 },
1942 {
1943         0, {
1944                 { 0,                    0 }
1945         }
1946 }
1947 };
1948
1949 /* -----------------------------
1950  * UMTS messages
1951  * -----------------------------*/
1952 static _gtp_mess_items umts_mess_items[] = {
1953         /* 7.2 Path Management Messages */
1954 {
1955         GTP_MSG_ECHO_REQ, {
1956                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1957                 { 0,                    0 }
1958         }
1959 },
1960 {
1961         GTP_MSG_ECHO_RESP, {
1962                 { GTP_EXT_RECOVER,      GTP_MANDATORY },
1963                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1964                 { 0,                    0 }
1965         }
1966 },
1967 {
1968         GTP_MSG_VER_NOT_SUPP, {
1969                 { 0,                    0 }
1970         }
1971 },
1972 {
1973         GTP_MSG_SUPP_EXT_HDR, {
1974                 { GTP_EXT_HDR_LIST,     GTP_MANDATORY },
1975                 { 0,                    0 }
1976         }
1977 },
1978         /* ??? */
1979 {
1980         GTP_MSG_NODE_ALIVE_REQ, {
1981                 { GTP_EXT_NODE_ADDR,    GTP_MANDATORY },
1982                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1983                 { 0,                    0 }
1984         }
1985 },
1986 {
1987         GTP_MSG_NODE_ALIVE_RESP, {
1988                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1989                 { 0,                    0 }
1990         }
1991 },
1992 {
1993         GTP_MSG_REDIR_REQ, {
1994                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1995                 { GTP_EXT_NODE_ADDR,    GTP_OPTIONAL },
1996                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1997                 { 0,                    0 }
1998         }
1999 },
2000 {
2001         GTP_MSG_REDIR_REQ, {
2002                 { 0,                    0 }
2003         }
2004 },
2005         /* 7.3 Tunnel Management Messages */
2006 {
2007         GTP_MSG_CREATE_PDP_REQ, {
2008                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
2009                         /* RAI is in TS 29.060 V6.11.0 */
2010                 { GTP_EXT_RAI,                  GTP_OPTIONAL },         /* Routeing Area Identity (RAI) Optional 7.7.3 */
2011                 { GTP_EXT_RECOVER,              GTP_OPTIONAL },
2012                 { GTP_EXT_SEL_MODE,     GTP_CONDITIONAL },
2013                 { GTP_EXT_TEID,                 GTP_MANDATORY },
2014                 { GTP_EXT_TEID_CP,              GTP_CONDITIONAL },
2015                 { GTP_EXT_NSAPI,                GTP_MANDATORY },
2016                 { GTP_EXT_NSAPI,                GTP_CONDITIONAL },
2017                 { GTP_EXT_CHRG_CHAR,    GTP_OPTIONAL },
2018                 { GTP_EXT_TRACE_REF,    GTP_OPTIONAL },
2019                 { GTP_EXT_TRACE_TYPE,   GTP_OPTIONAL },
2020                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
2021                 { GTP_EXT_APN,                  GTP_CONDITIONAL },
2022                 { GTP_EXT_PROTO_CONF,   GTP_CONDITIONAL },
2023                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
2024                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
2025                 { GTP_EXT_MSISDN,               GTP_CONDITIONAL },
2026                 { GTP_EXT_QOS_UMTS,             GTP_MANDATORY },
2027                 { GTP_EXT_TFT,                  GTP_CONDITIONAL },
2028                 { GTP_EXT_TRIGGER_ID,   GTP_OPTIONAL },
2029                 { GTP_EXT_OMC_ID,               GTP_OPTIONAL },
2030                 /* TS 29.060 V6.11.0 */
2031                 { GTP_EXT_APN_RES,              GTP_OPTIONAL },
2032                 { GTP_EXT_RAT_TYPE,             GTP_OPTIONAL },
2033                 { GTP_EXT_USR_LOC_INF,  GTP_OPTIONAL },
2034                 { GTP_EXT_MS_TIME_ZONE, GTP_OPTIONAL },
2035                 { GTP_EXT_IMEISV,               GTP_OPTIONAL },
2036                 { GTP_EXT_CAMEL_CHG_INF_CON, GTP_OPTIONAL },
2037                 { GTP_EXT_ADD_TRS_INF,  GTP_OPTIONAL },
2038                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2039                 { 0,                    0 }
2040         }
2041 },
2042 {
2043         GTP_MSG_CREATE_PDP_RESP, {
2044                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2045                 { GTP_EXT_REORDER,              GTP_CONDITIONAL },
2046                 { GTP_EXT_RECOVER,              GTP_OPTIONAL },
2047                 { GTP_EXT_TEID,                 GTP_CONDITIONAL },
2048                 { GTP_EXT_TEID_CP,              GTP_CONDITIONAL },
2049                 { GTP_EXT_CHRG_ID,              GTP_CONDITIONAL },
2050                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
2051                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
2052                 { GTP_EXT_GSN_ADDR,             GTP_CONDITIONAL },
2053                 { GTP_EXT_GSN_ADDR,             GTP_CONDITIONAL },
2054                 { GTP_EXT_QOS_UMTS,             GTP_CONDITIONAL },
2055                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
2056                 /* TS 29.060 V6.11.0 */
2057                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },         /* Alternative Charging Gateway Address Optional 7.7.44 */
2058                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL }, 
2059                 { GTP_EXT_COMMON_FLGS,  GTP_OPTIONAL },         /* Common Flags Optional 7.7.48 */
2060                 { GTP_EXT_APN_RES,              GTP_OPTIONAL },         /* APN Restriction Optional 7.7.49 */
2061                 { 0,                    0 }
2062         }
2063 },
2064 {       /* checked, SGSN -> GGSN */
2065         GTP_MSG_UPDATE_PDP_REQ, {
2066                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
2067                 { GTP_EXT_RAI,                  GTP_OPTIONAL },         /* Routeing Area Identity (RAI) Optional 7.7.3 */
2068                 { GTP_EXT_RECOVER,              GTP_OPTIONAL },
2069                 { GTP_EXT_TEID,                 GTP_MANDATORY },
2070                 { GTP_EXT_TEID_CP,              GTP_CONDITIONAL },
2071                 { GTP_EXT_NSAPI,                GTP_MANDATORY },
2072                 { GTP_EXT_TRACE_REF,    GTP_OPTIONAL },
2073                 { GTP_EXT_TRACE_TYPE,   GTP_OPTIONAL },
2074                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },         /* Protocol Configuration Options Optional 7.7.31 */
2075                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },        /* SGSN Address for Control Plane Mandatory GSN Address 7.7.32 */
2076                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },        /* SGSN Address for User Traffic Mandatory GSN Address 7.7.32 */
2077                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },         /* Alternative SGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2078                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },         /* Alternative SGSN Address for User Traffic Conditional GSN Address 7.7.32 */
2079                 { GTP_EXT_QOS_UMTS,             GTP_MANDATORY },
2080                 { GTP_EXT_TFT,                  GTP_OPTIONAL },
2081                 { GTP_EXT_TRIGGER_ID,   GTP_OPTIONAL },
2082                 { GTP_EXT_OMC_ID,               GTP_OPTIONAL },
2083                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2084                 { GTP_EXT_RAT_TYPE,             GTP_OPTIONAL },         /* RAT Type Optional 7.7.50 */
2085                 { GTP_EXT_USR_LOC_INF,  GTP_OPTIONAL },         /* User Location Information Optional 7.7.51 */
2086                 { GTP_EXT_MS_TIME_ZONE, GTP_OPTIONAL },         /* MS Time Zone Optional 7.7.52 */
2087                 { GTP_EXT_ADD_TRS_INF,  GTP_OPTIONAL },         /* Additonal Trace Info Optional 7.7.62 */
2088                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2089                 { 0,                    0 }
2090         }
2091 },
2092 {       /* checked, GGSN -> SGSN */
2093         GTP_MSG_UPDATE_PDP_RESP, {
2094                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2095                 { GTP_EXT_RECOVER,              GTP_OPTIONAL },
2096                 { GTP_EXT_TEID,                 GTP_CONDITIONAL },
2097                 { GTP_EXT_TEID_CP,              GTP_CONDITIONAL },
2098                 { GTP_EXT_CHRG_ID,              GTP_CONDITIONAL },
2099                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },         /* Protocol Configuration Options Optional 7.7.31 */
2100                 { GTP_EXT_GSN_ADDR,             GTP_CONDITIONAL },
2101                 { GTP_EXT_GSN_ADDR,             GTP_CONDITIONAL },
2102                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },         /* Alternative SGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2103                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },         /* Alternative SGSN Address for User Traffic Conditional GSN Address 7.7.32 */
2104                 { GTP_EXT_QOS_UMTS,             GTP_CONDITIONAL },
2105                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
2106                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },         /* Alternative Charging Gateway Address Optional 7.7.44 */
2107                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2108                 { GTP_EXT_COMMON_FLGS,  GTP_OPTIONAL },         /* Common Flags Optional 7.7.48 */
2109                 { GTP_EXT_APN_RES,              GTP_OPTIONAL },         /* APN Restriction Optional 7.7.49 */
2110                 { 0,                    0 }
2111         }
2112 },
2113 {
2114         GTP_MSG_DELETE_PDP_REQ, {
2115                 { GTP_EXT_TEAR_IND,             GTP_CONDITIONAL },
2116                 { GTP_EXT_NSAPI,                GTP_MANDATORY },
2117                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },         /* Protocol Configuration Options Optional 7.7.31 */
2118                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2119                 { 0,                    0 }
2120         }
2121 },
2122 {
2123         GTP_MSG_DELETE_PDP_RESP, {
2124                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2125                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },         /* Protocol Configuration Options Optional 7.7.31 */
2126                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2127                 { 0,                    0 }
2128         }
2129 },
2130 {
2131         GTP_MSG_ERR_IND, {
2132                 { GTP_EXT_TEID,                 GTP_MANDATORY },
2133                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },        /* GSN Address Mandatory 7.7.32 */
2134                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2135                 { 0,                    0 }
2136         }
2137 },
2138 {
2139         GTP_MSG_PDU_NOTIFY_REQ, {
2140                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
2141                 { GTP_EXT_TEID_CP,              GTP_MANDATORY },
2142                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
2143                 { GTP_EXT_APN,                  GTP_MANDATORY },
2144                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },         /* Protocol Configuration Options Optional 7.7.31 */
2145                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
2146                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2147                 { 0,                    0 }
2148         }
2149 },
2150 {
2151         GTP_MSG_PDU_NOTIFY_RESP, {
2152                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2153                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2154                 { 0,                    0 }
2155         }
2156 },
2157 {
2158         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
2159                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2160                 { GTP_EXT_TEID_CP,              GTP_MANDATORY },
2161                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
2162                 { GTP_EXT_APN,                  GTP_MANDATORY },
2163                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },         /* Protocol Configuration Options Optional 7.7.31 */
2164                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2165                 { 0,                    0 }
2166         }
2167 },
2168 {
2169         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
2170                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2171                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2172                 { 0,                    0 }
2173         }
2174 },
2175         /* 7.4 Location Management Messages */
2176 {
2177         GTP_MSG_SEND_ROUT_INFO_REQ, {
2178                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
2179                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2180                 { 0,                    0 }
2181         }
2182 },
2183 {
2184         GTP_MSG_SEND_ROUT_INFO_RESP, {
2185                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2186                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
2187                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
2188                 { GTPv1_EXT_MS_REASON,  GTP_OPTIONAL },
2189                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },
2190                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2191                 { 0,                    0 }
2192         }
2193 },
2194 {
2195         GTP_MSG_FAIL_REP_REQ, {
2196                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
2197                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2198                 { 0,                    0 }
2199         }
2200 },
2201 {
2202         GTP_MSG_FAIL_REP_RESP, {
2203                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2204                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
2205                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2206                 { 0,                    0 }
2207         }
2208 },
2209 {
2210         GTP_MSG_MS_PRESENT_REQ, {
2211                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
2212                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
2213                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2214                 { 0,                    0 }
2215         }
2216 },
2217 {
2218         GTP_MSG_MS_PRESENT_RESP, {
2219                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2220                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2221                 { 0,                    0 }
2222         }
2223 },
2224         /* 7.5 Mobility Management Messages */
2225 {
2226         GTP_MSG_IDENT_REQ, {
2227                 { GTP_EXT_RAI,                  GTP_MANDATORY },
2228                 { GTP_EXT_PTMSI,                GTP_MANDATORY },
2229                 { GTP_EXT_PTMSI_SIG,    GTP_CONDITIONAL },
2230                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },         /* SGSN Address for Control Plane Optional 7.7.32 */
2231                 { GTP_EXT_HOP_COUNT,    GTP_OPTIONAL },         /* Hop Counter Optional 7.7.63 */
2232                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2233                 { 0,                    0 }
2234         }
2235 },
2236 {
2237         GTP_MSG_IDENT_RESP, {
2238                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2239                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
2240                 { GTP_EXT_AUTH_TRI,             GTP_CONDITIONAL },
2241                 { GTP_EXT_AUTH_QUI,             GTP_CONDITIONAL },
2242                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2243                 { 0,                    0 }
2244         }
2245 },
2246 {
2247         GTP_MSG_SGSN_CNTXT_REQ, {
2248                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
2249                 { GTP_EXT_RAI,                  GTP_MANDATORY },
2250                 { GTP_EXT_TLLI,                 GTP_CONDITIONAL },
2251                 { GTP_EXT_PTMSI,                GTP_CONDITIONAL },
2252                 { GTP_EXT_PTMSI_SIG,    GTP_CONDITIONAL },
2253                 { GTP_EXT_MS_VALID,             GTP_OPTIONAL },
2254                 { GTP_EXT_TEID_CP,              GTP_MANDATORY },
2255                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
2256                 { GTP_EXT_GSN_ADDR,             GTP_OPTIONAL },         /* Alternative SGSN Address for Control Plane Optional 7.7.32 */
2257                 { GTP_EXT_SSGN_NO,              GTP_OPTIONAL },         /* SGSN Number Optional 7.7.47 */
2258                 { GTP_EXT_HOP_COUNT,    GTP_OPTIONAL },         /* Hop Counter Optional 7.7.63 */
2259                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2260                 { 0,                    0 }
2261         }
2262 },
2263 {
2264         GTP_MSG_SGSN_CNTXT_RESP, {
2265                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2266                 { GTP_EXT_IMSI,                 GTP_CONDITIONAL },
2267                 { GTP_EXT_TEID_CP,              GTP_CONDITIONAL },
2268                 { GTP_EXT_RAB_CNTXT,    GTP_CONDITIONAL },      /* RAB Context Conditional 7.7.19 */
2269                 { GTP_EXT_RP_SMS,               GTP_OPTIONAL },
2270                 { GTP_EXT_RP,                   GTP_OPTIONAL },
2271                 { GTP_EXT_PKT_FLOW_ID,  GTP_OPTIONAL },
2272                 { GTP_EXT_CHRG_CHAR,    GTP_OPTIONAL },         /* CharingCharacteristics Optional 7.7.23 */
2273                 { GTP_EXT_RA_PRIO_LCS,  GTP_OPTIONAL },         /* Radio Priority LCS Optional 7.7.25B */
2274                 { GTP_EXT_MM_CNTXT,             GTP_CONDITIONAL },
2275                 { GTP_EXT_PDP_CNTXT,    GTP_CONDITIONAL },
2276                 { GTP_EXT_GSN_ADDR,             GTP_CONDITIONAL },
2277                 { GTP_EXT_PDP_CONT_PRIO,GTP_OPTIONAL },         /* PDP Context Prioritization Optional 7.7.45 */
2278                 { GTP_EXT_MBMS_UE_CTX,  GTP_OPTIONAL },         /* MBMS UE Context Optional 7.7.55 */
2279                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2280                 { 0,                    0 }
2281         }
2282 },
2283 {
2284         GTP_MSG_SGSN_CNTXT_ACK, {
2285                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2286                 { GTP_EXT_TEID_II,              GTP_CONDITIONAL },
2287                 { GTP_EXT_GSN_ADDR,             GTP_CONDITIONAL },
2288                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2289                 { 0,                    0 }
2290         }
2291 },
2292 {
2293         GTP_MSG_FORW_RELOC_REQ, {
2294                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
2295                 { GTP_EXT_TEID_CP,              GTP_MANDATORY },
2296                 { GTP_EXT_RANAP_CAUSE,  GTP_MANDATORY },
2297                 { GTP_EXT_CHRG_CHAR,    GTP_OPTIONAL },         /* CharingCharacteristics Optional 7.7.23 */
2298                 { GTP_EXT_MM_CNTXT,             GTP_MANDATORY },
2299                 { GTP_EXT_PDP_CNTXT,    GTP_CONDITIONAL },
2300                 { GTP_EXT_GSN_ADDR,             GTP_MANDATORY },
2301                 { GTP_EXT_TARGET_ID,    GTP_MANDATORY },
2302                 { GTP_EXT_UTRAN_CONT,   GTP_MANDATORY },
2303                 { GTP_EXT_PDP_CONT_PRIO,GTP_OPTIONAL },         /* PDP Context Prioritization Optional 7.7.45 */
2304                 { GTP_EXT_MBMS_UE_CTX,  GTP_OPTIONAL },         /* MBMS UE Context Optional 7.7.55 */
2305                 { GTP_EXT_SEL_PLMN_ID,  GTP_OPTIONAL },         /* Selected PLMN ID Optional 7.7.64 */
2306                 { GTP_EXT_PS_HO_REQ_CTX,GTP_OPTIONAL },         /* PS Handover Request Context Optional 7.7.71 */
2307                 { GTP_EXT_BSS_CONT,             GTP_OPTIONAL },         /* BSS Container Optional 7.7.72 */
2308                 { GTP_EXT_CELL_ID,              GTP_OPTIONAL },         /* Cell Identification Optional 7.7.73 */
2309                 { GTP_EXT_BSSGP_CAUSE,  GTP_OPTIONAL },         /* BSSGP Cause Optional 7.7.75 */
2310                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2311                 { GTP_EXT_SSGN_NO,              GTP_OPTIONAL },
2312                 { 0,                    0 }
2313         }
2314 },
2315 {
2316         GTP_MSG_FORW_RELOC_RESP, {
2317                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2318                 { GTP_EXT_TEID_CP,              GTP_CONDITIONAL },
2319                 { GTP_EXT_TEID_II,              GTP_CONDITIONAL },      /* Tunnel Endpoint Identifier Data II Optional 7.7.15 */
2320                 { GTP_EXT_RANAP_CAUSE,  GTP_CONDITIONAL },
2321                 { GTP_EXT_GSN_ADDR,             GTP_CONDITIONAL },
2322                 { GTP_EXT_UTRAN_CONT,   GTP_OPTIONAL },
2323                 { GTP_EXT_RAB_SETUP,    GTP_CONDITIONAL },
2324                 { GTP_EXT_ADD_RAB_SETUP_INF,    GTP_CONDITIONAL },      /* Additional RAB Setup Information Conditional 7.7.45A */
2325                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2326                 { 0,                    0 }
2327         }
2328 },
2329 {
2330         GTP_MSG_FORW_RELOC_COMP, {
2331                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2332                 { 0,                    0 }
2333         }
2334 },
2335 {
2336         GTP_MSG_RELOC_CANCEL_REQ, {
2337                 { GTP_EXT_IMSI,                 GTP_MANDATORY },
2338                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2339                 { 0,                    0 }
2340         }
2341 },
2342 {
2343         GTP_MSG_RELOC_CANCEL_RESP, {
2344                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2345                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2346                 { 0,                    0 }
2347         }
2348 },
2349 {
2350         GTP_MSG_FORW_RELOC_ACK, {
2351                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2352                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2353                 { 0,                    0 }
2354         }
2355 },
2356 {
2357         GTP_MSG_FORW_SRNS_CNTXT_ACK, {
2358                 { GTP_EXT_CAUSE,                GTP_MANDATORY },
2359                 { GTP_EXT_PRIV_EXT,             GTP_OPTIONAL },
2360                 { 0,                    0 }
2361         }
2362 },
2363 {
2364         GTP_MSG_FORW_SRNS_CNTXT, {
2365                 { GTP_EXT_RAB_CNTXT,                    GTP_MANDATORY },
2366                 { GTP_EXT_SRC_RNC_PDP_CTX_INF,  GTP_OPTIONAL },         /* Source RNC PDCP context info Optional 7.7.61 */
2367                 { GTP_EXT_PDU_NO,                               GTP_OPTIONAL },         /* PDU Numbers Optional 7.7.74 */
2368                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2369                 { 0,                    0 }
2370         }
2371 },
2372
2373 /*      7.5.14 RAN Information Management Messages */
2374 {
2375                 GTP_MSG_RAN_INFO_RELAY, {
2376                 { GTP_EXT_RAN_TR_CONT,                  GTP_MANDATORY },        /* RAN Transparent Container Mandatory 7.7.43 */
2377                 { GTP_EXT_RIM_RA,                               GTP_OPTIONAL },         /* RIM Routing Address Optional 7.7.57 */
2378                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2379                 { 0,                    0 }
2380         }
2381 },
2382 /* 7.5A MBMS Messages 
2383  * 7.5A.1 UE Specific MBMS Messages
2384  */
2385 {
2386                 GTP_MBMS_NOTIFY_REQ, {
2387                 { GTP_EXT_IMSI,                                 GTP_MANDATORY },        /* IMSI Mandatory 7.7.2 */
2388                 { GTP_EXT_TEID_CP,                              GTP_MANDATORY },        /* Tunnel Endpoint Identifier Control Plane Mandatory 7.7.14 */
2389                 { GTP_EXT_NSAPI,                                GTP_MANDATORY },        /* NSAPI Mandatory 7.7.17 */
2390                 { GTP_EXT_USER_ADDR,                    GTP_MANDATORY },        /* End User Address Mandatory 7.7.27 */
2391                 { GTP_EXT_APN,                                  GTP_MANDATORY },        /* Access Point Name Mandatory 7.7.30 */
2392                 { GTP_EXT_GSN_ADDR,                             GTP_MANDATORY },        /* GGSN Address for Control Plane Mandatory 7.7.32 */
2393                 { GTP_EXT_MBMS_PROT_CONF_OPT,   GTP_OPTIONAL },         /* MBMS Protocol Configuration Options Optional 7.7.58 */
2394                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2395                 { 0,                    0 }
2396         }
2397 },
2398 {
2399                 GTP_MBMS_NOTIFY_RES, {
2400                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2401                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2402                 { 0,                    0 }
2403         }
2404 },
2405 {
2406                 GTP_MBMS_NOTIFY_REJ_REQ, {
2407                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2408                 { GTP_EXT_TEID_CP,                              GTP_MANDATORY },        /* Tunnel Endpoint Identifier Control Plane Mandatory 7.7.14 */
2409                 { GTP_EXT_NSAPI,                                GTP_MANDATORY },        /* NSAPI Mandatory 7.7.17 */
2410                 { GTP_EXT_USER_ADDR,                    GTP_MANDATORY },        /* End User Address Mandatory 7.7.27 */
2411                 { GTP_EXT_APN,                                  GTP_MANDATORY },        /* Access Point Name Mandatory 7.7.30 */
2412                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2413                 { 0,                    0 }
2414         }
2415 },
2416 {
2417                 GTP_MBMS_NOTIFY_REJ_RES, {
2418                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2419                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2420                 { 0,                    0 }
2421         }
2422 },
2423 {
2424                 GTP_CREATE_MBMS_CNTXT_REQ, {
2425                 { GTP_EXT_IMSI,                                 GTP_CONDITIONAL },      /* IMSI Conditional 7.7.2 */
2426                 { GTP_EXT_RAI,                                  GTP_MANDATORY },        /* Routeing Area Identity (RAI) Mandatory 7.7.3 */
2427                 { GTP_EXT_RECOVER,                              GTP_OPTIONAL },         /* Recovery Optional 7.7.11 */
2428                 { GTP_EXT_SEL_MODE,                             GTP_CONDITIONAL },      /* Selection mode Conditional 7.7.12 */
2429                 { GTP_EXT_TEID_CP,                              GTP_CONDITIONAL },      /* Tunnel Endpoint Identifier Control Plane Conditional 7.7.14 */
2430                 { GTP_EXT_TRACE_REF,                    GTP_OPTIONAL },         /* Trace Reference Optional 7.7.24 */
2431                 { GTP_EXT_TRACE_TYPE,                   GTP_OPTIONAL },         /* Trace Type Optional 7.7.25 */
2432                 { GTP_EXT_USER_ADDR,                    GTP_MANDATORY },        /* End User Address Mandatory 7.7.27 */
2433                 { GTP_EXT_APN,                                  GTP_MANDATORY },        /* Access Point Name Mandatory 7.7.30 */
2434                 { GTP_EXT_GSN_ADDR,                             GTP_MANDATORY },        /* SGSN Address for signalling Mandatory GSN Address 7.7.32 */
2435                 { GTP_EXT_MSISDN,                               GTP_CONDITIONAL },      /* MSISDN Conditional 7.7.33 */
2436                 { GTP_EXT_TRIGGER_ID,                   GTP_OPTIONAL },         /* Trigger Id Optional 7.7.41 */
2437                 { GTP_EXT_OMC_ID,                               GTP_OPTIONAL },         /* OMC Identity Optional 7.7.42 */
2438                 { GTP_EXT_RAT_TYPE,                             GTP_OPTIONAL },         /* RAT Type Optional 7.7.50 */
2439                 { GTP_EXT_USR_LOC_INF,                  GTP_OPTIONAL },         /* User Location Information Optional 7.7.51 */
2440                 { GTP_EXT_MS_TIME_ZONE,                 GTP_OPTIONAL },         /* MS Time Zone Optional 7.7.52 */
2441                 { GTP_EXT_IMEISV,                               GTP_OPTIONAL },         /* IMEI(SV) Optional 7.7.53 */
2442                 { GTP_EXT_MBMS_PROT_CONF_OPT,   GTP_OPTIONAL },         /* MBMS Protocol Configuration Options Optional 7.7.58 */
2443                 { GTP_EXT_ADD_TRS_INF,                  GTP_OPTIONAL },         /* Additonal Trace Info Optional 7.7.62 */
2444                 { GTP_EXT_ENH_NSAPI,                    GTP_MANDATORY },        /* Enhanced NSAPI Mandatory 7.7.67 */
2445                 { GTP_EXT_ADD_MBMS_TRS_INF,             GTP_OPTIONAL },         /* Additional MBMS Trace Info Optional 7.7.68 */
2446                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2447                 { 0,                    0 }
2448         }
2449 },
2450 {
2451                 GTP_CREATE_MBMS_CNTXT_RES, {
2452                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2453                 { GTP_EXT_RECOVER,                              GTP_OPTIONAL },         /* Recovery Optional 7.7.11 */
2454                 { GTP_EXT_TEID_CP,                              GTP_CONDITIONAL },      /* Tunnel Endpoint Identifier Control Plane Conditional 7.7.14 */
2455                 { GTP_EXT_CHRG_ID,                              GTP_CONDITIONAL },      /* Charging ID Conditional 7.7.26 */
2456                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* GGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2457                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* Alternative GGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2458                 { GTP_EXT_CHRG_ADDR,                    GTP_OPTIONAL },         /* Charging Gateway Address Optional 7.7.44 */
2459                 { GTP_EXT_CHRG_ADDR,                    GTP_OPTIONAL },         /* Alternative Charging Gateway Address Optional 7.7.44 */
2460                 { GTP_EXT_MBMS_PROT_CONF_OPT,   GTP_OPTIONAL },         /* MBMS Protocol Configuration Options Optional 7.7.58 */
2461                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2462                 { 0,                    0 }
2463         }
2464 },
2465 {
2466                 GTP_UPD_MBMS_CNTXT_REQ, {
2467                 { GTP_EXT_IMSI,                         GTP_CONDITIONAL },              /* IMSI Conditional 7.7.2 */
2468                 { GTP_EXT_RAI,                                  GTP_MANDATORY },        /* Routeing Area Identity (RAI) Mandatory 7.7.3 */
2469                 { GTP_EXT_RECOVER,                              GTP_OPTIONAL },         /* Recovery Optional 7.7.11 */
2470                 { GTP_EXT_TEID_CP,                              GTP_CONDITIONAL },      /* Tunnel Endpoint Identifier Control Plane Conditional 7.7.14 */
2471                 { GTP_EXT_TRACE_REF,                    GTP_OPTIONAL },         /* Trace Reference Optional 7.7.24 */
2472                 { GTP_EXT_TRACE_TYPE,                   GTP_OPTIONAL },         /* Trace Type Optional 7.7.25 */
2473                 { GTP_EXT_GSN_ADDR,                             GTP_MANDATORY },        /* SGSN Address for Control Plane Mandatory GSN Address 7.7.32 */
2474                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* Alternative SGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2475                 { GTP_EXT_TRIGGER_ID,                   GTP_OPTIONAL },         /* Trigger Id Optional 7.7.41 */
2476                 { GTP_EXT_OMC_ID,                               GTP_OPTIONAL },         /* OMC Identity Optional 7.7.42 */
2477                 { GTP_EXT_RAT_TYPE,                             GTP_OPTIONAL },         /* RAT Type Optional 7.7.50 */
2478                 { GTP_EXT_USR_LOC_INF,                  GTP_OPTIONAL },         /* User Location Information Optional 7.7.51 */
2479                 { GTP_EXT_MS_TIME_ZONE,                 GTP_OPTIONAL },         /* MS Time Zone Optional 7.7.52 */
2480                 { GTP_EXT_ADD_TRS_INF,                  GTP_OPTIONAL },         /* Additional Trace Info Optional 7.7.62 */
2481                 { GTP_EXT_ENH_NSAPI,                    GTP_MANDATORY },        /* Enhanced NSAPI Mandatory 7.7.67 */
2482                 { GTP_EXT_ADD_MBMS_TRS_INF,             GTP_OPTIONAL },         /* Additional MBMS Trace Info Optional 7.7.68 */
2483                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2484                 { 0,                    0 }
2485         }
2486 },
2487 {
2488                 GTP_UPD_MBMS_CNTXT_RES, {
2489                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2490                 { GTP_EXT_RECOVER,                              GTP_OPTIONAL },         /* Recovery Optional 7.7.11 */
2491                 { GTP_EXT_TEID_CP,                              GTP_MANDATORY },        /* Tunnel Endpoint Identifier Control Plane Conditional 7.7.14 */
2492                 { GTP_EXT_CHRG_ID,                              GTP_CONDITIONAL },      /* Charging ID Conditional 7.7.26 */
2493                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* GGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2494                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* Alternative GGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2495                 { GTP_EXT_CHRG_ADDR,                    GTP_OPTIONAL },         /* Charging Gateway Address Optional 7.7.44 */
2496                 { GTP_EXT_CHRG_ADDR,                    GTP_OPTIONAL },         /* Alternative Charging Gateway Address Optional 7.7.44 */
2497                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2498                 { 0,                    0 }
2499         }
2500 },
2501 {
2502                 GTP_DEL_MBMS_CNTXT_REQ, {
2503                 { GTP_EXT_IMSI,                                 GTP_CONDITIONAL },      /* IMSI Conditional 7.7.2 */
2504                 { GTP_EXT_TEID_CP,                              GTP_MANDATORY },        /* Tunnel Endpoint Identifier Control Plane Conditional 7.7.14 */
2505                 { GTP_EXT_USER_ADDR,                    GTP_CONDITIONAL },      /* End User Address Conditional 7.7.27 */
2506                 { GTP_EXT_APN,                                  GTP_CONDITIONAL },      /* Access Point Name Conditional 7.7.30 */
2507                 { GTP_EXT_MBMS_PROT_CONF_OPT,   GTP_OPTIONAL },         /* MBMS Protocol Configuration Options Optional 7.7.58 */
2508                 { GTP_EXT_ENH_NSAPI,                    GTP_MANDATORY },        /* Enhanced NSAPI Conditional 7.7.67 */
2509                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2510                 { 0,                    0 }
2511         }
2512 },
2513 {
2514                 GTP_DEL_MBMS_CNTXT_RES, {
2515                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2516                 { GTP_EXT_MBMS_PROT_CONF_OPT,   GTP_OPTIONAL },         /* MBMS Protocol Configuration Options Optional 7.7.58 */
2517                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },
2518                 { 0,                    0 }
2519         }
2520 },
2521 {
2522                 GTP_MBMS_REG_REQ, {
2523                 { GTP_EXT_USER_ADDR,                    GTP_MANDATORY },        /* End User Address Mandatory 7.7.27 */
2524                 { GTP_EXT_APN,                                  GTP_MANDATORY },        /* Access Point Name Mandatory 7.7.30 */
2525                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2526                 { 0,                    0 }
2527         }
2528 },
2529 {
2530                 GTP_MBMS_REG_RES, {
2531                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2532                 { GTP_EXT_TMGI,                                 GTP_MANDATORY },        /* Temporary Mobile Group Identity (TMGI) Conditional 7.7.56 */
2533                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2534                 { 0,                    0 }
2535         }
2536 },
2537 {
2538                 GTP_MBMS_DE_REG_REQ, {
2539                 { GTP_EXT_USER_ADDR,                    GTP_MANDATORY },        /* End User Address Mandatory 7.7.27 */
2540                 { GTP_EXT_APN,                                  GTP_MANDATORY },        /* Access Point Name Mandatory 7.7.30 */
2541                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2542                 { 0,                    0 }
2543         }
2544 },
2545 {
2546                 GTP_MBMS_DE_REG_RES, {
2547                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2548                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2549                 { 0,                    0 }
2550         }
2551 },
2552 {
2553                 GTP_MBMS_SES_START_REQ, {
2554                 { GTP_EXT_RECOVER,                              GTP_OPTIONAL },         /* Recovery Optional 7.7.11 */
2555                 { GTP_EXT_TEID_CP,                              GTP_CONDITIONAL },      /* Tunnel Endpoint Identifier Control Plane Conditional 7.7.14 */
2556                 { GTP_EXT_USER_ADDR,                    GTP_MANDATORY },        /* End User Address Mandatory 7.7.27 */
2557                 { GTP_EXT_APN,                                  GTP_MANDATORY },        /* Access Point Name Mandatory 7.7.30 */
2558                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* GGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2559                 { GTP_EXT_QOS_UMTS,                             GTP_MANDATORY },        /* Quality of Service Profile Mandatory 7.7.34 */
2560                 { GTP_EXT_COMMON_FLGS,                  GTP_OPTIONAL },         /* Common Flags Mandatory 7.7.48 */
2561                 { GTP_EXT_TMGI,                                 GTP_MANDATORY },        /* Temporary Mobile Group Identity (TMGI) Mandatory 7.7.56 */
2562                 { GTP_EXT_MBMS_SES_DUR,                 GTP_MANDATORY },        /* MBMS Session Duration Mandatory 7.7.59 */
2563                 { GTP_EXT_MBMS_SA,                              GTP_MANDATORY },        /* MBMS Service Area Mandatory 7.7.60 */
2564                 { GTP_EXT_MBMS_SES_ID,                  GTP_OPTIONAL },         /* MBMS Session Identifier Optional 7.7.65 */
2565                 { GTP_EXT_MBMS_2G_3G_IND,               GTP_MANDATORY },        /* MBMS 2G/3G Indicator Mandatory 7.7.66 */
2566                 { GTP_EXT_MBMS_SES_ID_REP_NO,   GTP_OPTIONAL },         /* MBMS Session Identity Repetition Number Optional 7.7.69 */
2567                 { GTP_EXT_MBMS_TIME_TO_DATA_TR, GTP_MANDATORY },        /* MBMS Time To Data Transfer Mandatory 7.7.70 */
2568                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2569                 { 0,                    0 }
2570         }
2571 },
2572 {
2573                 GTP_MBMS_SES_START_RES, {
2574                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2575                 { GTP_EXT_RECOVER,                              GTP_OPTIONAL },         /* Recovery Optional 7.7.11 */
2576                 { GTP_EXT_TEID,                                 GTP_CONDITIONAL },      /* Tunnel Endpoint Identifier Data I Conditional 7.7.13 */
2577                 { GTP_EXT_TEID_CP,                              GTP_CONDITIONAL },      /* Tunnel Endpoint Identifier Control Plane Conditional 7.7.14 */
2578                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* SGSN Address for Control Plane Conditional GSN Address 7.7.32 */
2579                 { GTP_EXT_GSN_ADDR,                             GTP_CONDITIONAL },      /* SGSN Address for user traffic Conditional GSN Address 7.7.32 */
2580                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2581                 { 0,                    0 }
2582         }
2583 },
2584 {
2585                 GTP_MBMS_SES_STOP_REQ, {
2586                 { GTP_EXT_USER_ADDR,                    GTP_MANDATORY },        /* End User Address Mandatory 7.7.27 */
2587                 { GTP_EXT_APN,                                  GTP_MANDATORY },        /* Access Point Name Mandatory 7.7.30 */
2588                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2589                 { 0,                    0 }
2590         }
2591 },
2592 {
2593                 GTP_MBMS_SES_STOP_RES, {
2594                 { GTP_EXT_CAUSE,                                GTP_MANDATORY },        /* Cause Mandatory 7.7.1 */
2595                 { GTP_EXT_PRIV_EXT,                             GTP_OPTIONAL },         /* Private Extension Optional 7.7.46 */
2596                 { 0,                    0 }
2597         }
2598 },
2599 {
2600         0, {
2601                 { 0,                    0 }
2602         }
2603 }
2604 };
2605
2606 static int
2607 check_field_presence(guint8 message, guint8 field, int *position) {
2608
2609         guint                   i = 0;
2610         _gtp_mess_items         *mess_items;
2611
2612         switch(gtp_version) {
2613                 case 0:
2614                         mess_items = gprs_mess_items;
2615                         break;
2616                 case 1:
2617                         mess_items = umts_mess_items;
2618                         break;
2619                 default:
2620                         return -2;
2621         }
2622
2623         while (mess_items[i].code) {
2624                 if (mess_items[i].code == message) {
2625
2626                         while (mess_items[i].fields[*position].code) {
2627                                 if (mess_items[i].fields[*position].code == field) {
2628                                         (*position)++;
2629                                         return 0;
2630                                 } else {
2631                                 if (mess_items[i].fields[*position].presence == GTP_MANDATORY) {
2632                                         return mess_items[i].fields[(*position)++].code;
2633                                 } else {
2634                                         (*position)++;
2635                                 }}
2636                         }
2637                         return -1;
2638                 }
2639                 i++;
2640         }
2641
2642         return -2;
2643 }
2644
2645 /* Decoders of fields in extension headers, each function returns no of bytes from field */
2646
2647 /* GPRS:        9.60 v7.6.0, chapter
2648  * UMTS:        29.060 v4.0, chapter
2649  */
2650 static int
2651 decode_gtp_cause(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2652
2653         guint8  cause;
2654
2655         cause = tvb_get_guint8(tvb, offset+1);
2656
2657         proto_tree_add_uint(tree, hf_gtp_cause, tvb, offset, 2, cause);
2658
2659         return 2;
2660 }
2661
2662 /* GPRS:        9.60 v7.6.0, chapter 7.9.2
2663  * UMTS:        29.060 v4.0, chapter 7.7.2
2664  */
2665 static int
2666 decode_gtp_imsi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2667
2668         guint8  imsi_val[8];
2669         gchar   *imsi_str;
2670
2671         tvb_memcpy(tvb, imsi_val, offset+1, 8);
2672         imsi_str = imsi_to_str (imsi_val);
2673
2674         proto_tree_add_string (tree, hf_gtp_imsi, tvb, offset, 9, imsi_str);
2675
2676         return 9;
2677 }
2678
2679 /* GPRS:        9.60 v7.6.0, chapter 7.9.3
2680  * UMTS:        29.060 v4.0, chapter 7.7.3
2681  */
2682 static int
2683 decode_gtp_rai(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2684
2685         proto_tree      *ext_tree_rai;
2686         proto_item      *te;
2687         guint8          byte[3];
2688         guint16         mnc, mcc;
2689
2690         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_RAI, gtp_val, "Unknown message"));
2691         ext_tree_rai = proto_item_add_subtree(te, ett_gtp_rai);
2692
2693         byte[0] = tvb_get_guint8 (tvb, offset + 1);
2694         byte[1] = tvb_get_guint8 (tvb, offset + 2);
2695         byte[2] = tvb_get_guint8 (tvb, offset + 3);
2696         mcc = (byte[0] & 0x0F) * 100 + ((byte[0] & 0xF0) >> 4) * 10  + (byte[1] & 0x0F );
2697         if ((byte[1] & 0xF0) == 0xF0)
2698                 mnc = (byte[2] & 0x0F) * 10  + ((byte[2] & 0xF0) >> 4);
2699         else
2700                 mnc = (byte[2] & 0x0F) * 100 + ((byte[2] & 0xF0) >> 4 ) * 10  + ((byte[1] & 0xF0) >> 4);
2701
2702         proto_tree_add_uint(ext_tree_rai, hf_gtp_rai_mcc, tvb, offset+1, 2, mcc);
2703         proto_tree_add_uint(ext_tree_rai, hf_gtp_rai_mnc, tvb, offset+2, 2, mnc);
2704         proto_tree_add_uint(ext_tree_rai, hf_gtp_rai_lac, tvb, offset+4, 2, tvb_get_ntohs (tvb, offset+4));
2705         proto_tree_add_uint(ext_tree_rai, hf_gtp_rai_rac, tvb, offset+6, 1, tvb_get_guint8 (tvb, offset+6));
2706
2707         return 7;
2708 }
2709
2710 /* GPRS:        9.60 v7.6.0, chapter 7.9.4, page 39
2711  * UMTS:        29.060 v4.0, chapter 7.7.4, page 47
2712  */
2713 static int
2714 decode_gtp_tlli(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2715
2716         guint32 tlli;
2717
2718         tlli = tvb_get_ntohl(tvb, offset+1);
2719         proto_tree_add_uint(tree, hf_gtp_tlli, tvb, offset, 5, tlli);
2720
2721         return 5;
2722 }
2723
2724 /* GPRS:        9.60 v7.6.0, chapter 7.9.5, page 39
2725  * UMTS:        29.060 v4.0, chapter 7.7.5, page 47
2726  */
2727 static int
2728 decode_gtp_ptmsi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2729
2730         guint32 ptmsi;
2731
2732         ptmsi = tvb_get_ntohl (tvb, offset+1);
2733         proto_tree_add_uint (tree, hf_gtp_ptmsi, tvb, offset, 5, ptmsi);
2734
2735         return 5;
2736 }
2737
2738 /* adjust - how many bytes before offset should be highlighted
2739  */
2740 static int
2741 decode_qos_gprs(tvbuff_t *tvb, int offset, proto_tree *tree, const gchar* qos_str, guint8 adjust) {
2742
2743         guint8          spare1, delay, reliability, peak, spare2,  precedence, spare3, mean;
2744         proto_tree      *ext_tree_qos;
2745         proto_item      *te;
2746
2747         spare1 = tvb_get_guint8(tvb, offset) & 0xC0;
2748         delay = tvb_get_guint8(tvb, offset) & 0x38;
2749         reliability = tvb_get_guint8(tvb, offset) & 0x07;
2750         peak = tvb_get_guint8(tvb, offset+1) & 0xF0;
2751         spare2 = tvb_get_guint8(tvb, offset+1) & 0x08;
2752         precedence = tvb_get_guint8(tvb, offset+1) & 0x07;
2753         spare3 = tvb_get_guint8(tvb, offset+2) & 0xE0;
2754         mean = tvb_get_guint8(tvb, offset+2) & 0x1F;
2755
2756         te = proto_tree_add_text(tree, tvb, offset-adjust, 3+adjust, "%s: delay: %u, reliability: %u, peak: %u, precedence: %u, mean: %u",
2757                                                                         qos_str, (delay >> 3) & 0x07, reliability, (peak >> 4) & 0x0F, precedence, mean);
2758         ext_tree_qos = proto_item_add_subtree(te, ett_gtp_qos);
2759
2760         if (adjust != 0) {
2761                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_spare1, tvb, offset, 1, spare1);
2762                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_delay, tvb, offset, 1, delay);
2763                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_reliability, tvb, offset, 1, reliability);
2764                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_peak, tvb, offset+1, 1, peak);
2765                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_spare2, tvb, offset+1, 1, spare2);
2766                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_precedence, tvb, offset+1, 1, precedence);
2767                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_spare3, tvb, offset+2, 1, spare3);
2768                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_mean, tvb, offset+2, 1, mean);
2769         }
2770
2771         return 3;
2772 }
2773
2774 /* GPRS:        9.60 v7.6.0, chapter 7.9.6, page 39
2775  *              4.08
2776  *              3.60
2777  * UMTS:        not present
2778  * TODO:        check if length is included: ETSI 4.08 vs 9.60
2779  */
2780 static int
2781 decode_gtp_qos_gprs(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2782
2783         return (1+decode_qos_gprs(tvb, offset+1, tree, "Quality of Service", 1));
2784
2785 }
2786
2787 /* GPRS:        9.60 v7.6.0, chapter 7.9.7, page 39
2788  * UMTS:        29.060 v4.0, chapter 7.7.6, page 47
2789  */
2790 static int
2791 decode_gtp_reorder(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2792
2793         guint8  reorder;
2794
2795         reorder = tvb_get_guint8(tvb, offset+1) & 0x01;
2796         proto_tree_add_boolean(tree, hf_gtp_reorder, tvb, offset, 2, reorder);
2797
2798         return 2;
2799 }
2800
2801 /* GPRS:        9.60 v7.6.0, chapter 7.9.8, page 40
2802  *              4.08 v7.1.2, chapter 10.5.3.1+
2803  * UMTS:        29.060 v4.0, chapter 7.7.7
2804  * TODO: Add blurb support by registering items in the protocol registration
2805  */
2806 static int
2807 decode_gtp_auth_tri(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2808
2809         proto_tree      *ext_tree_auth_tri;
2810         proto_item      *te;
2811
2812         te = proto_tree_add_text(tree, tvb, offset, 29, val_to_str(GTP_EXT_AUTH_TRI, gtp_val, "Unknown message"));
2813         ext_tree_auth_tri = proto_item_add_subtree(tree, ett_gtp_auth_tri);
2814
2815         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+1, 16, "RAND: %s", tvb_bytes_to_str(tvb, offset+1, 16));
2816         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+17, 4, "SRES: %s", tvb_bytes_to_str(tvb, offset+17, 4));
2817         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+21, 8, "Kc: %s", tvb_bytes_to_str(tvb, offset+21, 8));
2818
2819         return 1+16+4+8;
2820 }
2821
2822 /* GPRS:        9.60 v7.6.0, chapter 7.9.9, page 40
2823  *              9.02 v7.7.0, page 1090
2824  * UMTS:        29.060 v4.0, chapter 7.7.8, page 48
2825  *              29.002 v4.2.1, chapter 17.5, page 268
2826  */
2827 static int
2828 decode_gtp_map_cause(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2829
2830         guint8  map_cause;
2831
2832         map_cause = tvb_get_guint8(tvb, offset+1);
2833         proto_tree_add_uint (tree, hf_gtp_map_cause, tvb, offset, 2, map_cause);
2834
2835         return 2;
2836 }
2837
2838 /* GPRS:        9.60 v7.6.0, chapter 7.9.10, page 41
2839  * UMTS:        29.060 v4.0, chapter 7.7.9, page 48
2840  */
2841 static int
2842 decode_gtp_ptmsi_sig(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2843
2844         guint32 ptmsi_sig;
2845
2846         ptmsi_sig = tvb_get_ntoh24(tvb, offset+1);
2847         proto_tree_add_uint(tree, hf_gtp_ptmsi_sig, tvb, offset, 4, ptmsi_sig);
2848
2849         return 4;
2850 }
2851
2852 /* GPRS:        9.60 v7.6.0, chapter 7.9.11, page 41
2853  * UMTS:        29.060 v4.0, chapter 7.7.10, page 49
2854  */
2855 static int
2856 decode_gtp_ms_valid(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2857
2858         guint8  ms_valid;
2859
2860         ms_valid = tvb_get_guint8(tvb, offset+1) & 0x01;
2861         proto_tree_add_boolean (tree, hf_gtp_ms_valid, tvb, offset, 2, ms_valid);
2862
2863         return 2;
2864 }
2865
2866 /* GPRS:        9.60 v7.6.0, chapter 7.9.12, page 41
2867  * UMTS:        29.060 v4.0, chapter 7.7.11, page 49
2868  */
2869 static int
2870 decode_gtp_recovery(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2871
2872         guint8  recovery;
2873
2874         recovery = tvb_get_guint8(tvb, offset+1);
2875         proto_tree_add_uint (tree, hf_gtp_recovery, tvb, offset, 2, recovery);
2876
2877         return 2;
2878 }
2879
2880 /* GPRS:        9.60 v7.6.0, chapter 7.9.13, page 42
2881  * UMTS:        29.060 v4.0, chapter 7.7.12, page 49
2882  */
2883 static int
2884 decode_gtp_sel_mode(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2885
2886         guint8  sel_mode;
2887
2888         sel_mode = tvb_get_guint8(tvb, offset+1) & 0x03;
2889         proto_tree_add_uint(tree, hf_gtp_sel_mode, tvb, offset, 2, sel_mode);
2890
2891         return 2;
2892 }
2893
2894 /* GPRS:        9.60 v7.6.0, chapter 7.9.14, page 42
2895  * UMTS:        29.060 v4.0, chapter 7.7.13, page 50
2896  */
2897 static int
2898 decode_gtp_16(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2899
2900         guint16 ext_flow_label;
2901         guint32 teid_data;
2902
2903         switch (gtp_version) {
2904                 case 0:
2905                         ext_flow_label = tvb_get_ntohs(tvb, offset+1);
2906                         proto_tree_add_uint(tree, hf_gtp_ext_flow_label, tvb, offset, 3, ext_flow_label);
2907
2908                         return 3;
2909                 case 1:
2910                         teid_data = tvb_get_ntohl(tvb, offset+1);
2911                         proto_tree_add_uint(tree, hf_gtp_teid_data, tvb, offset, 5, teid_data);
2912
2913                         return 5;
2914                 default:
2915                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label/TEID Data I : GTP version not supported");
2916
2917                         return 3;
2918         }
2919 }
2920
2921 /* GPRS:        9.60 v7.6.0, chapter 7.9.15, page 42
2922  * UMTS:        29.060 v4.0, chapter 7.7.14, page 42
2923  */
2924 static int
2925 decode_gtp_17(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2926
2927         guint16         flow_sig;
2928         guint32         teid_cp;
2929
2930         switch (gtp_version) {
2931                 case 0:
2932                         flow_sig = tvb_get_ntohs(tvb, offset+1);
2933                         proto_tree_add_uint (tree, hf_gtp_flow_sig, tvb, offset, 3, flow_sig);
2934                         return 3;
2935                 case 1:
2936                         teid_cp = tvb_get_ntohl(tvb, offset+1);
2937                         proto_tree_add_uint (tree, hf_gtp_teid_cp, tvb, offset, 5, teid_cp);
2938                         return 5;
2939                 default:
2940                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label signalling/TEID control plane : GTP version not supported");
2941                         return 3;
2942         }
2943 }
2944
2945 /* GPRS:        9.60 v7.6.0, chapter 7.9.16, page 42
2946  * UMTS:        29.060 v4.0, chapter 7.7.15, page 51
2947  */
2948 static int
2949 decode_gtp_18(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2950
2951         guint16         flow_ii;
2952         guint32         teid_ii;
2953         proto_tree      *ext_tree_flow_ii;
2954         proto_item      *te;
2955
2956         switch (gtp_version) {
2957                 case 0:
2958                         te = proto_tree_add_text(tree, tvb, offset, 4, val_to_str(GTP_EXT_FLOW_II, gtp_val, "Unknown message"));
2959                         ext_tree_flow_ii = proto_item_add_subtree (te, ett_gtp_flow_ii);
2960
2961                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtp_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2962
2963                         flow_ii = tvb_get_ntohs(tvb, offset+2);
2964                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtp_flow_ii, tvb, offset+2, 2, flow_ii);
2965
2966                         return 4;
2967                 case 1:
2968                         te = proto_tree_add_text (tree, tvb, offset, 6, val_to_str(GTP_EXT_TEID_II, gtpv1_val, "Unknown message"));
2969                         ext_tree_flow_ii = proto_item_add_subtree(te, ett_gtp_flow_ii);
2970
2971                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtp_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2972
2973
2974                         teid_ii = tvb_get_ntohl(tvb, offset+2);
2975                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtp_teid_ii, tvb, offset+2, 4, teid_ii);
2976
2977                         return 6;
2978                 default:
2979                         proto_tree_add_text(tree, tvb, offset, 1, "Flow data II/TEID Data II : GTP Version not supported");
2980
2981                         return 4;
2982         }
2983 }
2984
2985 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A, page 43
2986  * UMTS:        29.060 v4.0, chapter 7.7.16, page 51
2987  * Check if all ms_reason types are included
2988  */
2989 static int
2990 decode_gtp_19(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2991
2992         guint8          field19;
2993
2994         field19 = tvb_get_guint8(tvb, offset+1);
2995
2996         switch (gtp_version) {
2997                 case 0:
2998                         proto_tree_add_uint(tree, hf_gtp_ms_reason, tvb, offset, 2, field19);
2999                         break;
3000                 case 1:
3001                         proto_tree_add_boolean(tree, hf_gtp_tear_ind, tvb, offset, 2, field19 & 0x01);
3002                         break;
3003                 default:
3004                         proto_tree_add_text(tree, tvb, offset, 1, "Information Element Type = 19 : GTP Version not supported");
3005                         break;
3006         }
3007
3008         return 2;
3009 }
3010
3011 /* GPRS:        not present
3012  * UMTS:        29.060 v4.0, chapter 7.7.17, page 51
3013  */
3014 static int
3015 decode_gtp_nsapi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3016
3017         guint8          nsapi;
3018
3019         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
3020         proto_tree_add_uint(tree, hf_gtp_nsapi, tvb, offset, 2, nsapi);
3021
3022         return 2;
3023 }
3024
3025 /* GPRS:        not present
3026  * UMTS:        29.060 v4.0, chapter 7.7.18, page 52
3027  */
3028 static int
3029 decode_gtp_ranap_cause(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3030
3031         guint8          ranap;
3032
3033         ranap = tvb_get_guint8(tvb, offset+1);
3034
3035         if(ranap > 0 && ranap <=64)
3036                 proto_tree_add_uint_format(tree, hf_gtp_ranap_cause, tvb, offset, 2,
3037                         ranap, "%s (Radio Network Layer Cause) : %s (%u)",
3038                         val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"),
3039                         val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
3040
3041         if(ranap > 64 && ranap <=80)
3042                 proto_tree_add_uint_format(tree, hf_gtp_ranap_cause, tvb, offset, 2,
3043                         ranap, "%s (Transport Layer Cause) : %s (%u)",
3044                         val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"),
3045                         val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
3046
3047         if(ranap > 80 && ranap <=96)
3048                 proto_tree_add_uint_format(tree, hf_gtp_ranap_cause, tvb, offset, 2,
3049                         ranap, "%s (NAS Cause) : %s (%u)",
3050                         val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"),
3051                         val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
3052
3053         if(ranap > 96 && ranap <=112)
3054                 proto_tree_add_uint_format(tree, hf_gtp_ranap_cause, tvb, offset, 2, ranap,
3055                         "%s (Protocol Cause) : %s (%u)",
3056                         val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"),
3057                         val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
3058
3059         if(ranap > 112 && ranap <=128)
3060                 proto_tree_add_uint_format(tree, hf_gtp_ranap_cause, tvb, offset, 2, ranap,
3061                         "%s (Miscellaneous Cause) : %s (%u)",
3062                         val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"),
3063                         val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
3064
3065         if(ranap > 128 /* && ranap <=255 */)
3066                 proto_tree_add_uint_format(tree, hf_gtp_ranap_cause, tvb, offset, 2, ranap,
3067                         "%s (Non-standard Cause) : %s (%u)",
3068                         val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"),
3069                         val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
3070
3071         return 2;
3072 }
3073
3074 /* GPRS:        not present
3075  * UMTS:        29.060 v4.0, chapter 7.7.19, page 52
3076  */
3077 static int
3078 decode_gtp_rab_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3079
3080         guint8          nsapi;
3081         proto_tree      *ext_tree_rab_cntxt;
3082         proto_item      *te;
3083
3084         te = proto_tree_add_text(tree, tvb, offset, 10, val_to_str(GTP_EXT_RAB_CNTXT, gtp_val, "Unknown message"));
3085         ext_tree_rab_cntxt = proto_item_add_subtree(te, ett_gtp_rab_cntxt);
3086
3087         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
3088
3089         proto_tree_add_uint (ext_tree_rab_cntxt, hf_gtp_nsapi, tvb, offset+1, 1, nsapi);
3090         proto_tree_add_item(ext_tree_rab_cntxt, hf_gtp_rab_gtpu_dn, tvb, offset+2, 2, FALSE);
3091         proto_tree_add_item(ext_tree_rab_cntxt, hf_gtp_rab_gtpu_up, tvb, offset+4, 2, FALSE);
3092         proto_tree_add_item(ext_tree_rab_cntxt, hf_gtp_rab_pdu_dn, tvb, offset+6, 2, FALSE);
3093         proto_tree_add_item(ext_tree_rab_cntxt, hf_gtp_rab_pdu_up, tvb, offset+8, 2, FALSE);
3094
3095         return 10;
3096 }
3097
3098
3099 /* GPRS:        not present
3100  * UMTS:        29.060 v4.0, chapter 7.7.20, page 53
3101  */
3102 static int
3103 decode_gtp_rp_sms(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3104
3105         guint8          rp_sms;
3106
3107         rp_sms = tvb_get_guint8(tvb, offset+1) & 0x07;
3108         proto_tree_add_uint(tree, hf_gtp_rp_sms, tvb, offset, 2, rp_sms);
3109
3110         return 2;
3111 }
3112
3113 /* GPRS:        not present
3114  * UMTS:        29.060 v4.0, chapter 7.7.21, page 53
3115  */
3116 static int
3117 decode_gtp_rp(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3118
3119         proto_tree      *ext_tree_rp;
3120         proto_item      *te;
3121         guint8          nsapi, rp, spare;
3122
3123         nsapi = tvb_get_guint8(tvb, offset+1) & 0xF0;
3124         spare = tvb_get_guint8(tvb, offset+1) & 0x08;
3125         rp = tvb_get_guint8(tvb, offset+1) & 0x07;
3126
3127         te = proto_tree_add_uint_format(tree, hf_gtp_rp, tvb, offset, 2, rp, "Radio Priority for NSAPI(%u) : %u", nsapi, rp);
3128         ext_tree_rp = proto_item_add_subtree(tree, ett_gtp_rp);
3129
3130         proto_tree_add_uint(ext_tree_rp, hf_gtp_rp_nsapi, tvb, offset+1, 1, nsapi);
3131         proto_tree_add_uint(ext_tree_rp, hf_gtp_rp_spare, tvb, offset+1, 1, spare);
3132         proto_tree_add_uint(ext_tree_rp, hf_gtp_rp, tvb, offset+1, 1, rp);
3133
3134         return 2;
3135 }
3136
3137 /* GPRS:        not present
3138  * UMTS:        29.060 v4.0, chapter 7.7.22, page 53
3139  */
3140 static int
3141 decode_gtp_pkt_flow_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3142
3143         proto_tree      *ext_tree_pkt_flow_id;
3144         proto_item      *te;
3145         guint8          nsapi, pkt_flow_id;
3146
3147         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
3148         pkt_flow_id = tvb_get_guint8(tvb, offset+2);
3149
3150         te = proto_tree_add_uint_format (tree, hf_gtp_pkt_flow_id, tvb, offset,
3151                 3, pkt_flow_id, "Packet Flow ID for NSAPI(%u) : %u", nsapi,
3152                 pkt_flow_id);
3153         ext_tree_pkt_flow_id = proto_item_add_subtree(tree, ett_gtp_pkt_flow_id);
3154
3155         proto_tree_add_uint(ext_tree_pkt_flow_id, hf_gtp_nsapi, tvb, offset+1, 1, nsapi);
3156         proto_tree_add_uint_format(ext_tree_pkt_flow_id, hf_gtp_pkt_flow_id, tvb,
3157                 offset+2, 1, pkt_flow_id, "%s : %u",
3158                 val_to_str(GTP_EXT_PKT_FLOW_ID, gtp_val, "Unknown message"),
3159                 pkt_flow_id);
3160
3161         return 3;
3162 }
3163
3164 /* GPRS:        not present
3165  * UMTS:        29.060 v4.0, chapter 7.7.23, page 53
3166  * TODO: Differenciate these uints?
3167  */
3168 static int
3169 decode_gtp_chrg_char(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3170
3171         guint16         chrg_char;
3172         proto_item      *te;
3173         proto_tree      *ext_tree_chrg_char;
3174
3175         chrg_char = tvb_get_ntohs(tvb, offset+1);
3176
3177         te = proto_tree_add_uint (tree, hf_gtp_chrg_char, tvb, offset, 3, chrg_char);
3178         /*"%s: %x", val_to_str (GTP_EXT_CHRG_CHAR, gtp_val, "Unknown message"), chrg_char);*/
3179         ext_tree_chrg_char = proto_item_add_subtree(te, ett_gtp_chrg_char);
3180
3181         proto_tree_add_uint (ext_tree_chrg_char, hf_gtp_chrg_char_s, tvb, offset+1, 2, chrg_char);
3182         proto_tree_add_uint (ext_tree_chrg_char, hf_gtp_chrg_char_n, tvb, offset+1, 2, chrg_char);
3183         proto_tree_add_uint (ext_tree_chrg_char, hf_gtp_chrg_char_p, tvb, offset+1, 2, chrg_char);
3184         proto_tree_add_uint (ext_tree_chrg_char, hf_gtp_chrg_char_f, tvb, offset+1, 2, chrg_char);
3185         proto_tree_add_uint (ext_tree_chrg_char, hf_gtp_chrg_char_h, tvb, offset+1, 2, chrg_char);
3186         proto_tree_add_uint (ext_tree_chrg_char, hf_gtp_chrg_char_r, tvb, offset+1, 2, chrg_char);
3187
3188         return 3;
3189 }
3190
3191 /* GPRS:        not present
3192  * UMTS:        29.060 v4.0, chapter 7.7.24, page
3193  */
3194 static int
3195 decode_gtp_trace_ref(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3196
3197         guint16         trace_ref;
3198
3199         trace_ref = tvb_get_ntohs(tvb, offset+1);
3200
3201         proto_tree_add_uint (tree, hf_gtp_trace_ref, tvb, offset, 3, trace_ref);
3202
3203         return 3;
3204 }
3205
3206 /* GPRS:        not present
3207  * UMTS:        29.060 v4.0, chapter 7.7.25, page
3208  */
3209 static int
3210 decode_gtp_trace_type(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3211
3212         guint16         trace_type;
3213
3214         trace_type = tvb_get_ntohs(tvb, offset+1);
3215
3216         proto_tree_add_uint (tree, hf_gtp_trace_type, tvb, offset, 3, trace_type);
3217
3218         return 3;
3219 }
3220
3221 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A
3222  * UMTS:        29.060 v4.0, chapter 7.7.25A, page
3223  */
3224 static int
3225 decode_gtp_ms_reason(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3226
3227         guint8          reason;
3228
3229         reason = tvb_get_guint8(tvb, offset+1);
3230
3231         proto_tree_add_uint (tree, hf_gtp_ms_reason, tvb, offset, 2, reason);
3232
3233         return 2;
3234 }
3235
3236 /* GPRS:        ?
3237  * UMTS:        29.060 v6.11.0, chapter 7.7.25B
3238  * Radio Priority LCS
3239  */
3240  static int
3241 decode_gtp_ra_prio_lcs(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3242
3243         guint16         length;
3244         proto_tree      *ext_tree;
3245         proto_item      *te;
3246
3247         length = tvb_get_ntohs(tvb, offset+1);
3248         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_RA_PRIO_LCS, gtp_val, "Unknown"));
3249         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_ra_prio_lcs);
3250         
3251         offset++;
3252         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
3253         offset = offset +2;
3254         /* TODO add decoding of data */
3255         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
3256
3257         return 3 + length;
3258
3259   }
3260
3261 /* GPRS:        12.15 v7.6.0, chapter 7.3.3, page 45
3262  * UMTS:        33.015
3263  */
3264 static int
3265 decode_gtp_tr_comm(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3266
3267         guint8  tr_command;
3268
3269         tr_command = tvb_get_guint8(tvb, offset+1);
3270
3271         proto_tree_add_uint (tree, hf_gtp_tr_comm, tvb, offset, 2, tr_command);
3272
3273         return 2;
3274 }
3275
3276 /* GPRS:        9.60 v7.6.0, chapter 7.9.17, page 43
3277  * UMTS:        29.060 v4.0, chapter 7.7.26, page 55
3278  */
3279 static int
3280 decode_gtp_chrg_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3281
3282         guint32 chrg_id;
3283
3284         chrg_id = tvb_get_ntohl(tvb, offset+1);
3285         proto_tree_add_uint (tree, hf_gtp_chrg_id, tvb, offset, 5, chrg_id);
3286
3287         return 5;
3288 }
3289
3290 /* GPRS:        9.60 v7.6.0, chapter 7.9.18, page 43
3291  * UMTS:        29.060 v4.0, chapter 7.7.27, page 55
3292  */
3293 static int
3294 decode_gtp_user_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3295
3296         guint16         length;
3297         guint8          pdp_typ, pdp_org;
3298         guint32         addr_ipv4;
3299         struct          e_in6_addr addr_ipv6;
3300         proto_tree      *ext_tree_user;
3301         proto_item      *te;
3302
3303
3304         length = tvb_get_ntohs(tvb, offset+1);
3305         pdp_org = tvb_get_guint8(tvb, offset+3) & 0x0F;
3306         pdp_typ = tvb_get_guint8(tvb, offset+4);
3307
3308         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s (%s/%s)",
3309             val_to_str(GTP_EXT_USER_ADDR, gtp_val, "Unknown message"),
3310             val_to_str(pdp_org, pdp_org_type, "Unknown PDP Organization"),
3311             val_to_str(pdp_typ, pdp_type, "Unknown PDP Type"));
3312         ext_tree_user = proto_item_add_subtree(te, ett_gtp_user);
3313
3314         proto_tree_add_text(ext_tree_user, tvb, offset+1, 2, "Length : %u", length);
3315         proto_tree_add_uint(ext_tree_user, hf_gtp_user_addr_pdp_org, tvb, offset+3, 1, pdp_org);
3316         proto_tree_add_uint(ext_tree_user, hf_gtp_user_addr_pdp_type, tvb, offset+4, 1, pdp_typ);
3317
3318         if (length == 2) {
3319                 if (pdp_org == 0 && pdp_typ == 1)
3320                         proto_item_append_text(te, " (Point to Point Protocol)");
3321                 else if (pdp_typ == 2)
3322                         proto_item_append_text(te, " (Octet Stream Protocol)");
3323         } else if (length > 2) {
3324                 switch (pdp_typ) {
3325                         case 0x21:
3326                                 addr_ipv4 = tvb_get_ipv4(tvb, offset+5);
3327                                 proto_tree_add_ipv4(ext_tree_user, hf_gtp_user_ipv4, tvb, offset+5, 4, addr_ipv4);
3328                                 proto_item_append_text(te, " : %s", ip_to_str((guint8 *)&addr_ipv4));
3329                                 break;
3330                         case 0x57:
3331                                 tvb_get_ipv6(tvb, offset+5, &addr_ipv6);
3332                                 proto_tree_add_ipv6 (ext_tree_user, hf_gtp_user_ipv6, tvb, offset+5, 16, (guint8 *)&addr_ipv6);
3333                                 proto_item_append_text(te, " : %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3334                                 break;
3335                 }
3336         } else
3337                 proto_item_append_text(te, " : empty PDP Address");
3338
3339         return 3+length;
3340 }
3341
3342 static int
3343 decode_triplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count) {
3344
3345         proto_tree      *ext_tree_trip;
3346         proto_item      *te_trip;
3347         guint16         i;
3348
3349         for (i=0;i<count;i++) {
3350                 te_trip = proto_tree_add_text(tree, tvb, offset+i*28, 28, "Triplet no%x", i);
3351                 ext_tree_trip = proto_item_add_subtree(te_trip, ett_gtp_trip);
3352
3353                 proto_tree_add_text(ext_tree_trip, tvb, offset+i*28, 16, "RAND: %s", tvb_bytes_to_str(tvb, offset+i*28, 16));
3354                 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));
3355                 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));
3356         }
3357
3358         return count*28;
3359 }
3360
3361 /* adjust - how many bytes before quintuplet should be highlighted
3362  */
3363 static int
3364 decode_quintuplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count) {
3365
3366         proto_tree      *ext_tree_quint;
3367         proto_item      *te_quint;
3368         guint16         q_offset, i;
3369         guint8          xres_len, auth_len;
3370
3371         q_offset = 0;
3372
3373         for (i=0;i<count;i++) {
3374
3375                 te_quint = proto_tree_add_text(tree, tvb, offset, -1, "Quintuplet #%x", i+1);
3376                 ext_tree_quint = proto_item_add_subtree(te_quint, ett_gtp_quint);
3377
3378
3379                 proto_tree_add_text(ext_tree_quint, tvb, offset + q_offset, 16, "RAND: %s", tvb_bytes_to_str(tvb, offset, 16));
3380                 q_offset = q_offset + 16;
3381                 xres_len = tvb_get_guint8(tvb, offset+q_offset);
3382                 proto_tree_add_text(ext_tree_quint, tvb, offset + q_offset, 1, "XRES length: %u", xres_len);
3383                 q_offset++;
3384                 proto_tree_add_text(ext_tree_quint, tvb, offset + q_offset, xres_len, "XRES: %s", tvb_bytes_to_str(tvb, offset + q_offset, xres_len));
3385                 q_offset = q_offset + xres_len;
3386                 proto_tree_add_text(ext_tree_quint, tvb ,offset + q_offset, 16, "Quintuplet Ciphering Key: %s", tvb_bytes_to_str(tvb, offset + q_offset, 16));
3387                 q_offset = q_offset + 16;
3388                 proto_tree_add_text(ext_tree_quint, tvb, offset + q_offset, 16, "Quintuplet Integrity Key: %s", tvb_bytes_to_str(tvb, offset + q_offset, 16));
3389                 q_offset = q_offset +16;
3390                 auth_len = tvb_get_guint8(tvb, offset + q_offset);
3391                 proto_tree_add_text(ext_tree_quint, tvb, offset + q_offset, 1, "Authentication length: %u", auth_len);
3392                 q_offset++;
3393                 proto_tree_add_text(ext_tree_quint, tvb, offset + q_offset, auth_len, "AUTH: %s", tvb_bytes_to_str(tvb, offset + q_offset, auth_len));
3394
3395                 q_offset = q_offset+auth_len;
3396                 proto_item_set_end(te_quint, tvb, offset+q_offset);
3397
3398         }
3399
3400         return q_offset;
3401 }
3402
3403 /* GPRS:        9.60 v7.6.0, chapter 7.9.19 page
3404  * UMTS:        29.060 v4.0, chapter 7.7.28 page 57
3405  * TODO:        - check if for quintuplets first 2 bytes are length, according to AuthQuint
3406  *              - finish displaying last 3 parameters
3407  */
3408 static int
3409 decode_gtp_mm_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3410
3411         guint16         length, quint_len, con_len;
3412         guint8          cksn, count, sec_mode, len;
3413         proto_tree      *ext_tree_mm;
3414         proto_item      *te;
3415     proto_item  *tf = NULL;
3416     proto_tree  *tf_tree = NULL;
3417         tvbuff_t        *l3_tvb;
3418
3419
3420         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_MM_CNTXT, gtp_val, "Unknown message"));
3421         ext_tree_mm = proto_item_add_subtree(te, ett_gtp_mm);
3422
3423         /* Octet 2 - 3 */
3424         length = tvb_get_ntohs(tvb, offset+1);
3425         if (length < 1) return 3;
3426
3427         /* Octet 4 */
3428         cksn = tvb_get_guint8(tvb, offset+3) & 0x07;
3429         /* Octet 5 */
3430         sec_mode = (tvb_get_guint8(tvb, offset+4) >> 6) & 0x03;
3431         count = (tvb_get_guint8(tvb, offset+4) >> 3) & 0x07;
3432
3433         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 2, "Length: %x", length);
3434         if (gtp_version == 0)
3435                 sec_mode = 1;
3436
3437
3438         switch (sec_mode) {
3439                 case 0:                         /* Used cipher value, UMTS keys and Quintuplets */
3440                         proto_tree_add_item(ext_tree_mm, hf_gtp_cksn_ksi, tvb, offset+3, 1, FALSE);
3441                         proto_tree_add_item(ext_tree_mm, hf_gtp_security_mode, tvb, offset+4, 1, FALSE);
3442                         proto_tree_add_item(ext_tree_mm, hf_gtp_no_of_vectors, tvb, offset+4, 1, FALSE);
3443                         proto_tree_add_item(ext_tree_mm, hf_gtp_cipher_algorithm, tvb, offset+4, 1, FALSE);
3444                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 16, "Ciphering key CK: %s", tvb_bytes_to_str(tvb, offset+5, 16));
3445                         proto_tree_add_text(ext_tree_mm, tvb, offset+21, 16, "Integrity key IK: %s", tvb_bytes_to_str(tvb, offset+21, 16));
3446                         quint_len = tvb_get_ntohs(tvb, offset+37);
3447                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: 0x%x (%u)", quint_len, quint_len);
3448
3449                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count) + 39;
3450
3451
3452                         break;
3453                 case 1:                         /* GSM key and triplets */
3454                         proto_tree_add_item(ext_tree_mm, hf_gtp_cksn, tvb, offset+3, 1, FALSE);
3455                         if (gtp_version != 0)
3456                                 proto_tree_add_item(ext_tree_mm, hf_gtp_security_mode, tvb, offset+4, 1, FALSE);
3457
3458                         proto_tree_add_item(ext_tree_mm, hf_gtp_no_of_vectors, tvb, offset+4, 1, FALSE);
3459                         proto_tree_add_item(ext_tree_mm, hf_gtp_cipher_algorithm, tvb, offset+4, 1, FALSE);
3460                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %s", tvb_bytes_to_str(tvb, offset+5, 8));
3461
3462                         offset = offset + decode_triplet(tvb, offset+13, ext_tree_mm, count) + 13;
3463
3464                         break;
3465                 case 2:                         /* UMTS key and quintuplets */
3466                         proto_tree_add_item(ext_tree_mm, hf_gtp_ksi, tvb, offset+3, 1, FALSE);
3467                         proto_tree_add_item(ext_tree_mm, hf_gtp_security_mode, tvb, offset+4, 1, FALSE);
3468                         proto_tree_add_item(ext_tree_mm, hf_gtp_no_of_vectors, tvb, offset+4, 1, FALSE);
3469                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 16, "Ciphering key CK: %s", tvb_bytes_to_str(tvb, offset+5, 16));
3470                         proto_tree_add_text(ext_tree_mm, tvb, offset+21, 16, "Integrity key IK: %s", tvb_bytes_to_str(tvb, offset+21, 16));
3471                         quint_len = tvb_get_ntohs(tvb, offset+37);
3472                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: 0x%x (%u)", quint_len, quint_len);
3473
3474                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count) + 39;
3475
3476                         break;
3477                 case 3:                         /* GSM key and quintuplets */
3478                         proto_tree_add_item(ext_tree_mm, hf_gtp_cksn, tvb, offset+3, 1, FALSE);
3479                         proto_tree_add_item(ext_tree_mm, hf_gtp_security_mode, tvb, offset+4, 1, FALSE);
3480                         proto_tree_add_item(ext_tree_mm, hf_gtp_no_of_vectors, tvb, offset+4, 1, FALSE);
3481                         proto_tree_add_item(ext_tree_mm, hf_gtp_cipher_algorithm, tvb, offset+4, 1, FALSE);
3482                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %s", tvb_bytes_to_str(tvb, offset+5, 8));
3483                         quint_len = tvb_get_ntohs(tvb, offset+13);
3484                         proto_tree_add_text(ext_tree_mm, tvb, offset+13, 2, "Quintuplets length: 0x%x (%u)", quint_len, quint_len);
3485
3486                         offset = offset + decode_quintuplet(tvb, offset+15, ext_tree_mm, count) + 15;
3487
3488                         break;
3489                 default:
3490                         break;
3491         }
3492
3493 /*
3494  * 3GPP TS 24.008 10.5.5.6 ( see packet-gsm_a.c )
3495  */
3496         de_gmm_drx_param(tvb, ext_tree_mm, offset, 2, NULL, 0);
3497         offset = offset +2;
3498
3499         len     = tvb_get_guint8(tvb, offset);
3500     tf = proto_tree_add_text(ext_tree_mm,
3501         tvb, offset, len+1,
3502         "MS Network Capability");
3503
3504     tf_tree = proto_item_add_subtree(tf, ett_gtp_net_cap);
3505
3506         proto_tree_add_text(tf_tree, tvb, offset, 1, "Length of MS network capability contents: %u", len);
3507
3508         offset++;
3509 /*
3510  * GPP TS 24.008 10.5.5.12 ( see packet-gsm_a.c )
3511  */
3512         de_gmm_ms_net_cap(tvb, tf_tree, offset, len, NULL, 0);
3513         offset = offset +len;
3514
3515 /* Container contains one or several optional information elements as described in the clause 'Overview',
3516  * from the clause 'General message format and information elements coding' in 3GPP TS 24.008.
3517  * The IMEISV shall, if available, be included in the Container.
3518  */
3519
3520         con_len = tvb_get_ntohs(tvb, offset);
3521         proto_tree_add_text(ext_tree_mm, tvb, offset, 2, "Container length: %u", con_len);
3522         offset = offset + 2;
3523
3524         if (con_len > 0) {
3525
3526                 l3_tvb = tvb_new_subset(tvb, offset,con_len, con_len );
3527                 if  (!dissector_try_port(bssap_pdu_type_table,BSSAP_PDU_TYPE_DTAP, l3_tvb, pinfo, ext_tree_mm))
3528                                 call_dissector(data_handle, l3_tvb, pinfo, ext_tree_mm);
3529         }
3530
3531         return 3+length;
3532 }
3533
3534 /* Function to extract the value of an hexadecimal octet. Only the lower
3535  * nybble will be non-zero in the output.
3536  * */
3537 static guint8 hex2dec (guint8 x)
3538 {
3539         if ((x >= 'a') && (x <= 'f'))
3540                 x = x - 'a' + 10;
3541         else if ((x >= 'A') && (x <= 'F'))
3542                 x = x - 'A' + 10;
3543         else if ((x >= '0') && (x <= '9'))
3544                 x = x - '0';
3545         else
3546                 x = 0;
3547         return x;
3548 }
3549
3550 /* Wrapper function to add UTF-8 decoding for QoS attributes in
3551  * RADIUS messages.
3552  * */
3553 static guint8 wrapped_tvb_get_guint8( tvbuff_t *tvb, int offset, int type)
3554 {
3555         if (type == 2)
3556                 return (hex2dec(tvb_get_guint8(tvb, offset)) << 4
3557                                         | hex2dec(tvb_get_guint8(tvb, offset + 1)));
3558         else
3559                 return tvb_get_guint8(tvb, offset);
3560 }
3561
3562  /* WARNING : actually length is coded on 2 octets for QoS profile but on 1 octet for PDP Context!
3563   * so type means length of length :-)
3564   *
3565   * WARNING :) type does not mean length of length any more... see below for
3566   * type = 3!
3567  */
3568 static int
3569 decode_qos_umts(tvbuff_t *tvb, int offset, proto_tree *tree, const gchar* qos_str, guint8 type) {
3570
3571         guint           length;
3572         guint8          al_ret_priority;
3573         guint8          delay, reliability, peak, precedence, mean, spare1, spare2, spare3;
3574         guint8          traf_class, del_order, del_err_sdu;
3575         guint8          max_sdu_size, max_ul, max_dl;
3576         guint8          res_ber, sdu_err_ratio;
3577         guint8          trans_delay, traf_handl_prio;
3578         guint8          guar_ul, guar_dl;
3579         proto_tree      *ext_tree_qos;
3580         proto_item      *te;
3581         int             mss, mu, md, gu, gd;
3582
3583         /* Will keep if the input is UTF-8 encoded (as in RADIUS messages).
3584          * If 1, input is *not* UTF-8 encoded (i.e. each input octet corresponds
3585          * to one byte to be dissected).
3586          * If 2, input is UTF-8 encoded (i.e. each *couple* of input octets
3587          * corresponds to one byte to be dissected)
3588          * */
3589         guint8      utf8_type = 1;
3590
3591         /* In RADIUS messages the QoS has a version field of two octets prepended.
3592          * As of 29.061 v.3.a.0, there is an hyphen between "Release Indicator" and
3593          * <release specific QoS IE UTF-8 encoding>. Even if it sounds rather
3594          * inconsistent and unuseful, I will check hyphen presence here and
3595          * will signal its presence.
3596          * */
3597         guint8      hyphen;
3598
3599         /* Will keep the value that will be returned
3600          * */
3601         int             retval = 0;
3602
3603         switch (type) {
3604                 case 1:
3605                         length = tvb_get_guint8 (tvb, offset);
3606                         te = proto_tree_add_text (tree, tvb, offset, length + 1, "%s", qos_str);
3607                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3608                         proto_tree_add_text (ext_tree_qos, tvb, offset, 1, "Length: %u", length);
3609                         offset++;
3610                         retval = length + 1;
3611                         break;
3612                 case 2:
3613                         length = tvb_get_ntohs (tvb, offset + 1);
3614                         te = proto_tree_add_text(tree, tvb, offset, length + 3, "%s", qos_str);
3615                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3616                         proto_tree_add_text (ext_tree_qos, tvb, offset + 1, 2, "Length: %u", length);
3617                         offset += 3;            /* +1 because of first 0x86 byte for UMTS QoS */
3618                         retval = length + 3;
3619                         break;
3620                 case 3:
3621                         /* For QoS inside RADIUS Client messages from GGSN */
3622                         utf8_type = 2;
3623
3624                         /* The field in the RADIUS message is the length of the tvb we were given */
3625                         length = tvb_length(tvb);
3626                         te = proto_tree_add_text (tree, tvb, offset, length, "%s", qos_str);
3627
3628                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3629
3630                         proto_tree_add_item (ext_tree_qos, hf_gtp_qos_version, tvb, offset, 2, FALSE);
3631
3632                         /* Hyphen handling */
3633                         hyphen = tvb_get_guint8(tvb, offset + 2);
3634                         if (hyphen == ((guint8) '-'))
3635                         {
3636                                 /* Hyphen is present, put in protocol tree */
3637                                 proto_tree_add_text (ext_tree_qos, tvb, offset + 2, 1, "Hyphen separator: -");
3638                                 offset++; /* "Get rid" of hyphen */
3639                         }
3640
3641                         /* Now, we modify offset here and in order to use type later
3642                          * effectively.*/
3643                         offset++;
3644
3645                         length -= offset;
3646                         length /=2;
3647
3648                         retval = length + 2;      /* Actually, will be ignored. */
3649                         break;
3650                 default:
3651                         /* XXX - what should we do with the length here? */
3652                         length = 0;
3653                         retval = 0;
3654                         ext_tree_qos = NULL;
3655                         break;
3656         }
3657
3658         /* In RADIUS messages there is no allocation-retention priority
3659          * so I don't need to wrap the following call to tvb_get_guint8
3660          * */
3661         al_ret_priority = tvb_get_guint8 (tvb, offset);
3662
3663         /* All calls are wrapped to take into account the possibility that the
3664          * input is UTF-8 encoded. If utf8_type is equal to 1, the final value
3665          * of the offset will be the same as in the previous version of this
3666          * dissector, and the wrapped function will serve as a dumb wrapper;
3667          * otherwise, if utf_8_type is 2, the offset is correctly shifted by
3668          * two bytes for needed shift, and the wrapped function will unencode
3669          * two values from the input.
3670          * */
3671         spare1 = wrapped_tvb_get_guint8(tvb, offset+(1 - 1) * utf8_type + 1, utf8_type) & 0xC0;
3672         delay = wrapped_tvb_get_guint8(tvb, offset+(1 - 1) * utf8_type + 1, utf8_type) & 0x38;
3673         reliability = wrapped_tvb_get_guint8(tvb, offset+(1 - 1) * utf8_type + 1, utf8_type) & 0x07;
3674         peak = wrapped_tvb_get_guint8(tvb, offset+(2 - 1) * utf8_type + 1, utf8_type) & 0xF0;
3675         spare2 = wrapped_tvb_get_guint8(tvb, offset+(2 - 1) * utf8_type + 1, utf8_type) & 0x08;
3676         precedence = wrapped_tvb_get_guint8(tvb, offset+(2 - 1) * utf8_type + 1, utf8_type) & 0x07;
3677         spare3 = wrapped_tvb_get_guint8(tvb, offset+(3 - 1) * utf8_type + 1, utf8_type) & 0xE0;
3678         mean = wrapped_tvb_get_guint8(tvb, offset+(3 - 1) * utf8_type + 1, utf8_type) & 0x1F;
3679
3680         /* In RADIUS messages there is no allocation-retention priority */
3681         if (type != 3)
3682                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_al_ret_priority, tvb, offset, 1, al_ret_priority);
3683
3684         /* All additions must take care of the fact that QoS fields in RADIUS
3685          * messages are UTF-8 encoded, so we have to use the same trick as above.
3686          * */
3687         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_spare1, tvb, offset+(1 - 1) * utf8_type + 1, utf8_type, spare1);
3688         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_delay, tvb, offset+(1 - 1) * utf8_type + 1, utf8_type, delay);
3689         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_reliability, tvb, offset+(1 - 1) * utf8_type + 1, utf8_type, reliability);
3690         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_peak, tvb, offset+(2 - 1) * utf8_type + 1, utf8_type, peak);
3691         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_spare2, tvb, offset+(2 - 1) * utf8_type + 1, utf8_type, spare2);
3692         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_precedence, tvb, offset+(2 - 1) * utf8_type + 1, utf8_type, precedence);
3693         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_spare3, tvb, offset+(3 - 1) * utf8_type + 1, utf8_type, spare3);
3694         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_mean, tvb, offset+(3 - 1) * utf8_type + 1, utf8_type, mean);
3695
3696         if (length > 4) {
3697
3698                 /* See above for the need of wrapping
3699                  * */
3700                 traf_class = wrapped_tvb_get_guint8(tvb, offset+(4 - 1) * utf8_type + 1, utf8_type) & 0xE0;
3701                 del_order = wrapped_tvb_get_guint8(tvb, offset+(4 - 1) * utf8_type + 1, utf8_type) & 0x18;
3702                 del_err_sdu = wrapped_tvb_get_guint8(tvb, offset+(4 - 1) * utf8_type + 1, utf8_type) & 0x07;
3703                 max_sdu_size = wrapped_tvb_get_guint8(tvb, offset+(5 - 1) * utf8_type + 1, utf8_type);
3704                 max_ul = wrapped_tvb_get_guint8(tvb, offset+(6 - 1) * utf8_type + 1, utf8_type);
3705                 max_dl = wrapped_tvb_get_guint8(tvb, offset+(7 - 1) * utf8_type + 1, utf8_type);
3706                 res_ber = wrapped_tvb_get_guint8(tvb, offset+(8 - 1) * utf8_type + 1, utf8_type) & 0xF0;
3707                 sdu_err_ratio = wrapped_tvb_get_guint8(tvb, offset+(8 - 1) * utf8_type + 1, utf8_type) & 0x0F;
3708                 trans_delay = wrapped_tvb_get_guint8(tvb, offset+(9 - 1) * utf8_type + 1, utf8_type) & 0xFC;
3709                 traf_handl_prio = wrapped_tvb_get_guint8(tvb, offset+(9 - 1) * utf8_type + 1, utf8_type) & 0x03;
3710                 guar_ul = wrapped_tvb_get_guint8(tvb, offset+(10 - 1) * utf8_type + 1, utf8_type);
3711                 guar_dl = wrapped_tvb_get_guint8(tvb, offset+(11 - 1) * utf8_type + 1, utf8_type);
3712
3713                 /* See above comments for the changes
3714                  * */
3715                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_traf_class, tvb, offset+(4 - 1) * utf8_type + 1, utf8_type, traf_class);
3716                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_del_order, tvb, offset+(4 - 1) * utf8_type + 1, utf8_type, del_order);
3717                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_del_err_sdu, tvb, offset+(4 - 1) * utf8_type + 1, utf8_type, del_err_sdu);
3718                 if (max_sdu_size == 0 || max_sdu_size > 150)
3719                         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_max_sdu_size, tvb, offset+(5 - 1) * utf8_type + 1, utf8_type, max_sdu_size);
3720                 if (max_sdu_size > 0 && max_sdu_size <= 150) {
3721                         mss = max_sdu_size*10;
3722                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_max_sdu_size, tvb, offset+(5 - 1) * utf8_type + 1, utf8_type, mss, "Maximum SDU size : %u octets", mss);
3723                 }
3724
3725                 if(max_ul == 0 || max_ul == 255)
3726                         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, max_ul);
3727                 if(max_ul > 0 && max_ul <= 63)
3728                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, max_ul, "Maximum bit rate for uplink : %u kbps", max_ul);
3729                 if(max_ul > 63 && max_ul <=127) {
3730                         mu = 64 + ( max_ul - 64 ) * 8;
3731                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, mu, "Maximum bit rate for uplink : %u kbps", mu);
3732                 }
3733
3734                 if(max_ul > 127 && max_ul <=254) {
3735                         mu = 576 + ( max_ul - 128 ) * 64;
3736                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, mu, "Maximum bit rate for uplink : %u kbps", mu);
3737                 }
3738
3739                 if(max_dl == 0 || max_dl == 255)
3740                         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, max_dl);
3741                 if(max_dl > 0 && max_dl <= 63)
3742                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, max_dl, "Maximum bit rate for downlink : %u kbps", max_dl);
3743                 if(max_dl > 63 && max_dl <=127) {
3744                         md = 64 + ( max_dl - 64 ) * 8;
3745                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, md, "Maximum bit rate for downlink : %u kbps", md);
3746                 }
3747                 if(max_dl > 127 && max_dl <=254) {
3748                         md = 576 + ( max_dl - 128 ) * 64;
3749                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, md, "Maximum bit rate for downlink : %u kbps", md);
3750                 }
3751
3752                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_res_ber, tvb, offset+(8 - 1) * utf8_type + 1, utf8_type, res_ber);
3753                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_sdu_err_ratio, tvb, offset+(8 - 1) * utf8_type + 1, utf8_type, sdu_err_ratio);
3754                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_trans_delay, tvb, offset+(9 - 1) * utf8_type + 1, utf8_type, trans_delay);
3755                 proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_traf_handl_prio, tvb, offset+(9 - 1) * utf8_type + 1, utf8_type, traf_handl_prio);
3756
3757                 if(guar_ul == 0 || guar_ul == 255)
3758                         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, guar_ul);
3759                 if(guar_ul > 0 && guar_ul <= 63)
3760                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, guar_ul, "Guaranteed bit rate for uplink : %u kbps", guar_ul);
3761                 if(guar_ul > 63 && guar_ul <=127) {
3762                         gu = 64 + ( guar_ul - 64 ) * 8;
3763                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, gu, "Guaranteed bit rate for uplink : %u kbps", gu);
3764                 }
3765                 if(guar_ul > 127 && guar_ul <=254) {
3766                         gu = 576 + ( guar_ul - 128 ) * 64;
3767                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, gu, "Guaranteed bit rate for uplink : %u kbps", gu);
3768                 }
3769
3770                 if(guar_dl == 0 || guar_dl == 255)
3771                         proto_tree_add_uint(ext_tree_qos, hf_gtp_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, guar_dl);
3772                 if(guar_dl > 0 && guar_dl <= 63)
3773                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, guar_dl, "Guaranteed bit rate for downlink : %u kbps", guar_dl);
3774                 if(guar_dl > 63 && guar_dl <=127) {
3775                         gd = 64 + ( guar_dl - 64 ) * 8;
3776                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, gd, "Guaranteed bit rate for downlink : %u kbps", gd);
3777                 }
3778                 if(guar_dl > 127 && guar_dl <=254) {
3779                         gd = 576 + ( guar_dl - 128 ) * 64;
3780                         proto_tree_add_uint_format(ext_tree_qos, hf_gtp_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, gd, "Guaranteed bit rate for downlink : %u kbps", gd);
3781                 }
3782
3783         }
3784
3785         return retval;
3786 }
3787
3788 static const gchar* dissect_radius_qos_umts(proto_tree *tree, tvbuff_t *tvb) {
3789         decode_qos_umts(tvb, 0, tree, "UMTS GTP QoS Profile", 3);
3790         return tvb_get_ephemeral_string(tvb,0,tvb_length(tvb));
3791 }
3792
3793 static void
3794 decode_apn(tvbuff_t *tvb, int offset, guint16 length, proto_tree *tree) {
3795
3796         guint8  *apn = NULL;
3797         int     name_len, tmp;
3798
3799         if (length > 0) {
3800                 name_len = tvb_get_guint8 (tvb, offset);
3801
3802                 if (name_len < 0x20) {
3803                         apn = tvb_get_ephemeral_string(tvb, offset + 1, length - 1);
3804                         for (;;) {
3805                                 if (name_len >= length - 1) break;
3806                                 tmp = name_len;
3807                                 name_len = name_len + apn[tmp] + 1;
3808                                 apn[tmp] = '.';
3809                         }
3810                 } else
3811                         apn = tvb_get_ephemeral_string(tvb, offset, length);
3812
3813                 proto_tree_add_string (tree, hf_gtp_apn, tvb, offset, length, apn);
3814         }
3815 }
3816
3817 /* GPRS:        9.60 v7.6.0, chapter 7.9.20
3818  * UMTS:        29.060 v4.0, chapter 7.7.29
3819  * TODO:        unify addr functions
3820  */
3821 static int
3822 decode_gtp_pdp_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3823
3824         guint8          ggsn_addr_len, apn_len, trans_id, vaa, order, nsapi, sapi, pdu_send_no, pdu_rec_no, pdp_cntxt_id,
3825                         pdp_type_org, pdp_type_num, pdp_addr_len;
3826         guint16         length, sn_down, sn_up, up_flow;
3827         guint32         addr_ipv4, up_teid, up_teid_cp;
3828         struct  e_in6_addr addr_ipv6;
3829         proto_tree      *ext_tree_pdp;
3830         proto_item      *te;
3831
3832         length = tvb_get_ntohs(tvb, offset+1);
3833
3834         te = proto_tree_add_text(tree, tvb, offset, length+3, val_to_str(GTP_EXT_PDP_CNTXT, gtp_val, "Unknown message"));
3835         ext_tree_pdp = proto_item_add_subtree(te, ett_gtp_pdp);
3836
3837         vaa = (tvb_get_guint8(tvb, offset+3) >> 6) & 0x01;
3838         order = (tvb_get_guint8(tvb, offset+3) >> 4) & 0x01;
3839         nsapi =  tvb_get_guint8(tvb, offset+3) & 0x0F;
3840         sapi = tvb_get_guint8(tvb, offset+4) & 0x0F;
3841
3842         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "VPLMN address allowed: %s", yesno[vaa]);
3843         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "Reordering required: %s", yesno[order]);
3844         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "NSAPI: %u", nsapi);
3845         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "SAPI: %u", sapi);
3846
3847         switch (gtp_version) {
3848                 case 0:
3849                         decode_qos_gprs(tvb, offset+5, ext_tree_pdp, "QoS subscribed", 0);
3850                         decode_qos_gprs(tvb, offset+8, ext_tree_pdp, "QoS requested", 0);
3851                         decode_qos_gprs(tvb, offset+11, ext_tree_pdp, "QoS negotiated", 0);
3852                         offset = offset + 14;
3853                         break;
3854                 case 1:
3855                         offset = offset + 5;
3856                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS subscribed", 1);
3857                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS requested", 1);
3858                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS negotiated", 1);
3859                         break;
3860                 default:
3861                         break;
3862         }
3863
3864         sn_down = tvb_get_ntohs(tvb, offset);
3865         sn_up = tvb_get_ntohs(tvb, offset+2);
3866         pdu_send_no = tvb_get_guint8(tvb, offset+4);
3867         pdu_rec_no = tvb_get_guint8(tvb, offset+5);
3868
3869         proto_tree_add_text(ext_tree_pdp, tvb, offset, 2, "Sequence number down: %u", sn_down);
3870         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 2, "Sequence number up: %u", sn_up);
3871         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "Send N-PDU number: %u", pdu_send_no);
3872         proto_tree_add_text(ext_tree_pdp, tvb, offset+5, 1, "Receive N-PDU number: %u", pdu_rec_no);
3873
3874         switch (gtp_version) {
3875                 case 0:
3876                         up_flow = tvb_get_ntohs(tvb, offset+6);
3877                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 2, "Uplink flow label signalling: %u", up_flow);
3878                         offset = offset + 8;
3879                         break;
3880                 case 1:
3881                         up_teid = tvb_get_ntohl(tvb, offset+6);
3882                         up_teid_cp = tvb_get_ntohl(tvb, offset+10);
3883                         pdp_cntxt_id = tvb_get_guint8(tvb, offset+14);
3884                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 4, "Uplink TEID: %x", up_teid);
3885                         proto_tree_add_text(ext_tree_pdp, tvb, offset+10, 4, "Uplink TEID control plane: %x", up_teid_cp);
3886                         proto_tree_add_text(ext_tree_pdp, tvb, offset+14, 1, "PDP context identifier: %u", pdp_cntxt_id);
3887                         offset = offset + 15;
3888                         break;
3889                 default:
3890                         break;
3891         }
3892
3893         pdp_type_org = tvb_get_guint8(tvb, offset) & 0x0F;
3894         pdp_type_num = tvb_get_guint8(tvb, offset+1);
3895         pdp_addr_len = tvb_get_guint8(tvb, offset+2);
3896
3897         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "PDP organization: %s", val_to_str(pdp_type_org, pdp_type, "Unknown PDP org"));
3898         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 1, "PDP type: %s", val_to_str(pdp_type_num, pdp_type, "Unknown PDP type"));
3899         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 1, "PDP address length: %u", pdp_addr_len);
3900
3901         if (pdp_addr_len > 0) {
3902                 switch (pdp_type_num) {
3903                         case 0x21:
3904                                 addr_ipv4 = tvb_get_ipv4(tvb, offset+3);
3905                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 4, "PDP address: %s", ip_to_str((guint8 *)&addr_ipv4));
3906                                 break;
3907                         case 0x57:
3908                                 tvb_get_ipv6(tvb, offset+3, &addr_ipv6);
3909                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 16, "PDP address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3910                                 break;
3911                         default:
3912                                 break;
3913                 }
3914         }
3915
3916         offset = offset + 3 + pdp_addr_len;
3917
3918         ggsn_addr_len = tvb_get_guint8(tvb, offset);
3919         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN address length: %u", ggsn_addr_len);
3920
3921         switch (ggsn_addr_len) {
3922                 case 4:
3923                         addr_ipv4 = tvb_get_ipv4(tvb, offset+1);
3924                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN address: %s", ip_to_str((guint8 *)&addr_ipv4));
3925                         break;
3926                 case 16:
3927                         tvb_get_ipv6(tvb, offset+1, &addr_ipv6);
3928                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3929                         break;
3930                 default:
3931                         break;
3932         }
3933
3934         offset = offset + 1 + ggsn_addr_len;
3935
3936         if (gtp_version == 1) {
3937
3938                 ggsn_addr_len = tvb_get_guint8(tvb, offset);
3939                 proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN 2 address length: %u", ggsn_addr_len);
3940
3941                 switch (ggsn_addr_len) {
3942                         case 4:
3943                                 addr_ipv4 = tvb_get_ipv4(tvb, offset+1);
3944                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN 2 address: %s", ip_to_str((guint8 *)&addr_ipv4));
3945                                 break;
3946                         case 16:
3947                                 tvb_get_ipv6(tvb, offset+1, &addr_ipv6);
3948                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN 2 address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3949                                 break;
3950                         default:
3951                                 break;
3952                 }
3953                 offset = offset + 1 + ggsn_addr_len;
3954
3955         }
3956
3957         apn_len = tvb_get_guint8(tvb, offset);
3958         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "APN length: %u", apn_len);
3959         decode_apn(tvb, offset+1, apn_len, ext_tree_pdp);
3960
3961         offset = offset + 1 + apn_len;
3962
3963         trans_id = tvb_get_guint8(tvb, offset);
3964         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "Transaction identifier: %u", trans_id);
3965
3966         return 3+length;
3967 }
3968
3969 /* GPRS:        9.60, v7.6.0, chapter 7.9.21
3970  * UMTS:        29.060, v4.0, chapter 7.7.30
3971  */
3972 static int
3973 decode_gtp_apn(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3974
3975         guint16         length;
3976         proto_tree      *ext_tree_apn;
3977         proto_item      *te;
3978
3979         length = tvb_get_ntohs(tvb, offset+1);
3980
3981         te = proto_tree_add_text (tree, tvb, offset, length+3, val_to_str(GTP_EXT_APN, gtp_val, "Unknown field"));
3982         ext_tree_apn = proto_item_add_subtree(te, ett_gtp_apn);
3983
3984         proto_tree_add_text (ext_tree_apn, tvb, offset+1, 2, "APN length : %u", length);
3985         decode_apn (tvb, offset+3, length, ext_tree_apn);
3986
3987         return 3+length;
3988 }
3989
3990 /* GPRS:        9.60 v7.6.0, chapter 7.9.22
3991  *              4.08 v. 7.1.2, chapter 10.5.6.3 (p.580)
3992  * UMTS:        29.060 v4.0, chapter 7.7.31
3993  *              24.008, v4.2, chapter 10.5.6.3
3994  */
3995 int
3996 decode_gtp_proto_conf(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3997
3998         guint16         length, proto_offset;
3999         guint16         proto_id;
4000         guint8          conf, proto_len, cnt = 1;
4001         tvbuff_t        *next_tvb;
4002         proto_tree      *ext_tree_proto;
4003         proto_item      *te;
4004         gboolean        save_writable;
4005
4006         length = tvb_get_ntohs(tvb, offset + 1);
4007
4008         te = proto_tree_add_text(tree, tvb, offset, length + 3, val_to_str(GTP_EXT_PROTO_CONF, gtp_val, "Unknown message"));
4009         ext_tree_proto = proto_item_add_subtree(te, ett_gtp_proto);
4010
4011         proto_tree_add_text(ext_tree_proto, tvb, offset + 1, 2, "Length: %u", length);
4012
4013         if (length < 1) return 3;
4014
4015         conf = tvb_get_guint8 (tvb, offset + 3) & 0x07;
4016         proto_tree_add_text (ext_tree_proto, tvb, offset + 3, 1, "Configuration protocol (00000xxx): %u", conf);
4017
4018         proto_offset = 1;       /* ... 1st byte is conf */
4019         offset += 4;
4020
4021         for (;;) {
4022                 if (proto_offset >= length) break;
4023                 proto_id = tvb_get_ntohs (tvb, offset);
4024                 proto_len = tvb_get_guint8 (tvb, offset + 2);
4025                 proto_offset += proto_len + 3;          /* 3 = proto id + length byte */
4026
4027                 if (proto_len > 0) {
4028
4029                         proto_tree_add_text (ext_tree_proto, tvb, offset, 2, "Protocol %u ID: %s (0x%04x)",
4030                             cnt, val_to_str(proto_id, ppp_vals, "Unknown"),
4031                             proto_id);
4032                         proto_tree_add_text (ext_tree_proto, tvb, offset+2, 1, "Protocol %u length: %u", cnt, proto_len);
4033
4034                         /*
4035                          * Don't allow the dissector for the configuration
4036                          * protocol in question to update the columns - this
4037                          * is GTP, not PPP.
4038                          */
4039                         save_writable = col_get_writable(pinfo->cinfo);
4040                         col_set_writable(pinfo->cinfo, FALSE);
4041
4042                         /*
4043                          * XXX - should we have our own dissector table,
4044                          * solely for configuration protocols, so that bogus
4045                          * values don't cause us to dissect the protocol
4046                          * data as, for example, IP?
4047                          */
4048                         next_tvb = tvb_new_subset (tvb, offset + 3, proto_len, proto_len);
4049                         if (!dissector_try_port(ppp_subdissector_table,
4050                             proto_id, next_tvb, pinfo, ext_tree_proto)) {
4051                                 call_dissector(data_handle, next_tvb, pinfo,
4052                                     ext_tree_proto);
4053                         }
4054
4055                         col_set_writable(pinfo->cinfo, save_writable);
4056                 }
4057
4058                 offset += proto_len + 3;
4059                 cnt++;
4060         }
4061
4062         return 3 + length;
4063 }
4064
4065 /* GPRS:        9.60 v7.6.0, chapter 7.9.23
4066  * UMTS:        29.060 v4.0, chapter 7.7.32
4067  */
4068 static int
4069 decode_gtp_gsn_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4070
4071         guint8          addr_type, addr_len;
4072         guint16         length;
4073         guint32         addr_ipv4;
4074         struct  e_in6_addr addr_ipv6;
4075         proto_tree      *ext_tree_gsn_addr;
4076         proto_item      *te;
4077
4078         length = tvb_get_ntohs(tvb, offset+1);
4079
4080         te = proto_tree_add_text(tree, tvb, offset, 3+length, "GSN address : ");
4081         ext_tree_gsn_addr = proto_item_add_subtree(te, ett_gtp_gsn_addr);
4082
4083         switch (length) {
4084                 case 4:
4085                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length);
4086                         addr_ipv4 = tvb_get_ipv4(tvb, offset+3);
4087                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4088                         proto_tree_add_ipv4(ext_tree_gsn_addr, hf_gtp_gsn_ipv4, tvb, offset+3, 4, addr_ipv4);
4089                         break;
4090                 case 5:
4091                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
4092                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
4093                         proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_type, tvb, offset+3, 1, addr_type);
4094                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
4095                         proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_len, tvb, offset+3, 1, addr_len);
4096                         addr_ipv4 = tvb_get_ipv4(tvb, offset+4);
4097                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4098                         proto_tree_add_ipv4(ext_tree_gsn_addr, hf_gtp_gsn_ipv4, tvb, offset+4, 4, addr_ipv4);
4099                         break;
4100                 case 16:
4101                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length);
4102                         tvb_get_ipv6(tvb, offset+3, &addr_ipv6);
4103                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4104                         proto_tree_add_ipv6(ext_tree_gsn_addr, hf_gtp_gsn_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
4105                         break;
4106                 case 17:
4107                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
4108                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
4109                         proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_type, tvb, offset+3, 1, addr_type);
4110                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
4111                         proto_tree_add_uint(ext_tree_gsn_addr, hf_gtp_gsn_addr_len, tvb, offset+3, 1, addr_len);
4112                         tvb_get_ipv6(tvb, offset+4, &addr_ipv6);
4113                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4114                         proto_tree_add_ipv6(ext_tree_gsn_addr, hf_gtp_gsn_ipv6, tvb, offset+4, 16, (guint8*)&addr_ipv6);
4115                         break;
4116                 default:
4117                         proto_item_append_text(te, "unknown type or wrong length");
4118                         break;
4119         }
4120
4121         return 3+length;
4122 }
4123
4124 /* GPRS:        9.60 v7.6.0, chapter 7.9.24
4125  * UMTS:        29.060 v4.0, chapter 7.7.33
4126  */
4127 static int
4128 decode_gtp_msisdn(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4129
4130         const guint8    *msisdn_val;
4131         gchar           *msisdn_str;
4132         guint16         length;
4133
4134         length = tvb_get_ntohs(tvb, offset+1);
4135
4136         if (length < 1) return 3;
4137
4138         msisdn_val = tvb_get_ptr(tvb, offset+3, length);
4139         msisdn_str = msisdn_to_str(msisdn_val, length);
4140
4141         proto_tree_add_string(tree, hf_gtp_msisdn, tvb, offset, 3+length, msisdn_str);
4142
4143         return 3+length;
4144 }
4145
4146 /* GPRS:        not present
4147  * UMTS:        29.060 v4.0, chapter 7.7.34
4148  *              24.008 v4.2, chapter 10.5.6.5
4149  */
4150 static int
4151 decode_gtp_qos_umts(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4152
4153         return decode_qos_umts(tvb, offset, tree, "Quality of Service", 2);
4154 }
4155
4156 /* GPRS:        not present
4157  * UMTS:        29.060 v4.0, chapter 7.7.35
4158  */
4159 static int
4160 decode_gtp_auth_qui(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4161
4162         proto_tree      *ext_tree;
4163         proto_item      *te_quint;
4164         guint16         length;
4165         guint8      xres_len, auth_len;
4166
4167
4168         length = tvb_get_ntohs(tvb, offset + 1);
4169
4170         te_quint = proto_tree_add_text(tree, tvb, offset, length+1, "Quintuplet");
4171         ext_tree = proto_item_add_subtree(te_quint, ett_gtp_quint);
4172         offset++;
4173
4174         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4175         offset = offset +2;
4176
4177         proto_tree_add_text(ext_tree, tvb, offset, 16, "RAND: %s", tvb_bytes_to_str(tvb, offset, 16));
4178         offset = offset + 16;
4179         xres_len = tvb_get_guint8(tvb, offset);
4180         proto_tree_add_text(ext_tree, tvb, offset, 1, "XRES length: %u", xres_len);
4181         offset++;
4182         proto_tree_add_text(ext_tree, tvb, offset , xres_len, "XRES: %s", tvb_bytes_to_str(tvb, offset, xres_len));
4183         offset = offset + xres_len;
4184         proto_tree_add_text(ext_tree, tvb ,offset, 16, "Quintuplet Ciphering Key: %s", tvb_bytes_to_str(tvb, offset, 16));
4185         offset =  offset + 16;
4186         proto_tree_add_text(ext_tree, tvb, offset, 16, "Quintuplet Integrity Key: %s", tvb_bytes_to_str(tvb, offset, 16));
4187         offset = offset +16;
4188         auth_len = tvb_get_guint8(tvb, offset);
4189         proto_tree_add_text(ext_tree, tvb, offset, 1, "Authentication length: %u", auth_len);
4190         offset++;
4191         proto_tree_add_text(ext_tree, tvb, offset , auth_len, "AUTH: %s", tvb_bytes_to_str(tvb, offset, auth_len));
4192
4193         offset = offset+auth_len;
4194
4195         return (3 + length);
4196
4197 }
4198
4199 /* GPRS:        not present
4200  * UMTS:        29.060 v4.0, chapter 7.7.36
4201  *              24.008 v4.2, chapter 10.5.6.12
4202  */
4203 static int
4204 decode_gtp_tft(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4205
4206         guint16         length, port1, port2, tos;
4207         guint8          tft_flags, tft_code, no_packet_filters, i, pf_id, pf_eval, pf_len, pf_content_id, proto, spare;
4208         guint           pf_offset;
4209         guint32         mask_ipv4, addr_ipv4, ipsec_id, label;
4210         struct  e_in6_addr addr_ipv6, mask_ipv6;
4211         proto_tree      *ext_tree_tft, *ext_tree_tft_pf, *ext_tree_tft_flags;
4212         proto_item      *te, *tee, *tef;
4213
4214         length = tvb_get_ntohs(tvb, offset+1);
4215
4216         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Traffic flow template");
4217         ext_tree_tft = proto_item_add_subtree(te, ett_gtp_tft);
4218
4219         tft_flags = tvb_get_guint8(tvb, offset+3);
4220         tft_code = (tft_flags >> 5) & 0x07;
4221         spare = (tft_flags >> 4) & 0x01;
4222         no_packet_filters = tft_flags & 0x0F;
4223
4224         proto_tree_add_text(ext_tree_tft, tvb, offset+1, 2, "TFT length: %u", length);
4225
4226         tef = proto_tree_add_text (ext_tree_tft, tvb, offset + 3, 1, "TFT flags");
4227         ext_tree_tft_flags = proto_item_add_subtree (tef, ett_gtp_tft_flags);
4228         proto_tree_add_uint (ext_tree_tft_flags, hf_gtp_tft_code, tvb, offset + 3, 1, tft_flags);
4229         proto_tree_add_uint (ext_tree_tft_flags, hf_gtp_tft_spare, tvb, offset + 3, 1, tft_flags);
4230         proto_tree_add_uint (ext_tree_tft_flags, hf_gtp_tft_number, tvb, offset + 3, 1, tft_flags);
4231
4232         offset = offset + 4;
4233
4234         for (i=0;i<no_packet_filters;i++) {
4235
4236                 pf_id = tvb_get_guint8(tvb, offset);
4237
4238                 tee = proto_tree_add_text (ext_tree_tft, tvb, offset, 1, "Packet filter id: %u", pf_id);
4239                 ext_tree_tft_pf = proto_item_add_subtree (tee, ett_gtp_tft_pf);
4240                 offset++;
4241
4242                 if (tft_code != 2) {
4243
4244                         pf_eval = tvb_get_guint8(tvb, offset);
4245                         pf_len = tvb_get_guint8(tvb, offset + 1);
4246
4247                         proto_tree_add_uint (ext_tree_tft_pf, hf_gtp_tft_eval, tvb, offset, 1, pf_eval);
4248                         proto_tree_add_text (ext_tree_tft_pf, tvb, offset+1, 1, "Content length: %u", pf_len);
4249
4250                         offset = offset + 2;
4251                         pf_offset = 0;
4252
4253                         while (pf_offset < pf_len) {
4254
4255                                 pf_content_id = tvb_get_guint8 (tvb, offset + pf_offset);
4256
4257                                 switch (pf_content_id) {
4258                                         /* address IPv4 and mask = 8 bytes*/
4259                                         case 0x10:
4260                                                 addr_ipv4 = tvb_get_ipv4 (tvb, offset + pf_offset + 1);
4261                                                 mask_ipv4 = tvb_get_ipv4 (tvb, offset + pf_offset + 5);
4262                                                 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));
4263                                                 pf_offset = pf_offset + 9;
4264                                                 break;
4265                                         /* address IPv6 and mask = 32 bytes*/
4266                                         case 0x20:
4267                                                 tvb_get_ipv6 (tvb, offset+pf_offset+1, &addr_ipv6);
4268                                                 tvb_get_ipv6 (tvb, offset+pf_offset+17, &mask_ipv6);
4269                                                 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));
4270                                                 pf_offset = pf_offset + 33;
4271                                                 break;
4272                                         /* protocol identifier/next header type = 1 byte*/
4273                                         case 0x30:
4274                                                 proto = tvb_get_guint8 (tvb, offset + pf_offset + 1);
4275                                                 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);
4276                                                 pf_offset = pf_offset + 2;
4277                                                 break;
4278                                         /* single destination port type = 2 bytes */
4279                                         case 0x40:
4280                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4281                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 3, "ID 0x40: destination port: %u", port1);
4282                                                 pf_offset = pf_offset + 3;
4283                                                 break;
4284                                         /* destination port range type = 4 bytes */
4285                                         case 0x41:
4286                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4287                                                 port2 = tvb_get_ntohs (tvb, offset + pf_offset + 3);
4288                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 5, "ID 0x41: destination port range: %u - %u", port1, port2);
4289                                                 pf_offset = pf_offset + 5;
4290                                                 break;
4291                                         /* single source port type = 2 bytes */
4292                                         case 0x50:
4293                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4294                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 3, "ID 0x50: source port: %u", port1);
4295                                                 pf_offset = pf_offset + 3;
4296                                                 break;
4297                                         /* source port range type = 4 bytes */
4298                                         case 0x51:
4299                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4300                                                 port2 = tvb_get_ntohs (tvb, offset + pf_offset + 3);
4301                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 5, "ID 0x51: source port range: %u - %u", port1, port2);
4302                                                 pf_offset = pf_offset + 5;
4303                                                 break;
4304                                         /* security parameter index type = 4 bytes */
4305                                         case 0x60:
4306                                                 ipsec_id = tvb_get_ntohl (tvb, offset + pf_offset + 1);
4307                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 5, "ID 0x60: security parameter index: %x", ipsec_id);
4308                                                 pf_offset = pf_offset + 5;
4309                                                 break;
4310                                         /* type of service/traffic class type = 2 bytes */
4311                                         case 0x70:
4312                                                 tos = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4313                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 2, "ID 0x70: Type of Service/Traffic Class: %u (%x)", tos, tos);
4314                                                 pf_offset = pf_offset + 3;
4315                                                 break;
4316                                         /* flow label type = 3 bytes */
4317                                         case 0x80:
4318                                                 label = tvb_get_ntoh24(tvb, offset + pf_offset + 1) & 0x0FFFFF;
4319                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 4, "ID 0x80: Flow Label: %u (%x)", label, label);
4320                                                 pf_offset = pf_offset + 4;
4321                                                 break;
4322
4323                                         default:
4324                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 1, "Unknown value: %x ", pf_content_id);
4325                                                 pf_offset++; /* to avoid infinite loop */
4326                                                 break;
4327                                 }
4328                         }
4329
4330                         offset = offset + pf_offset;
4331                 }
4332         }
4333
4334         return 3 + length;
4335 }
4336
4337 /* GPRS:        not present
4338  * UMTS:        29.060 v4.0, chapter 7.7.37
4339  * Type = 138 (Decimal)
4340  *              25.413(RANAP) TargetID 
4341  */
4342 static int
4343 decode_gtp_target_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4344
4345         guint16         length;
4346         proto_item      *target_id_item;
4347         proto_tree      *ext_tree;
4348         tvbuff_t        *next_tvb;
4349         asn1_ctx_t asn1_ctx;
4350         asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
4351         
4352         length = tvb_get_ntohs(tvb, offset + 1);
4353
4354         target_id_item = proto_tree_add_text (tree, tvb, offset, 3 + length, "Target Identification");
4355         ext_tree = proto_item_add_subtree (target_id_item, ett_gtp_target_id);
4356         offset = offset +1;
4357         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4358         offset = offset +2;
4359         next_tvb = tvb_new_subset (tvb, offset, length, length);
4360         dissect_ranap_TargetID(next_tvb, 0, &asn1_ctx, ext_tree, hf_gtp_targetid);
4361
4362         return 3 + length;
4363 }
4364
4365
4366 /* GPRS:        not present
4367  * UMTS:        29.060 v4.0, chapter 7.7.38
4368  */
4369 static int
4370 decode_gtp_utran_cont(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4371
4372         guint16         length;
4373         proto_item      *utran_cont_item;
4374         proto_tree      *ext_tree;
4375         tvbuff_t        *next_tvb;
4376
4377         length = tvb_get_ntohs(tvb, offset + 1);
4378
4379         utran_cont_item = proto_tree_add_text(tree, tvb, offset, 3 + length, "UTRAN transparent field");
4380         ext_tree = proto_item_add_subtree (utran_cont_item, ett_gtp_utran_cont);
4381         offset = offset +1;
4382         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4383         offset = offset +2;
4384         next_tvb = tvb_new_subset (tvb, offset, length, length);
4385
4386         return 3 + length;
4387
4388 }
4389
4390
4391 /* GPRS:        not present
4392  * UMTS:        29.060 v4.0, chapter 7.7.39
4393  */
4394 static int
4395 decode_gtp_rab_setup(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4396
4397         guint32         teid, addr_ipv4;
4398         guint16         length;
4399         guint8          nsapi;
4400         struct  e_in6_addr addr_ipv6;
4401         proto_tree      *ext_tree_rab_setup;
4402         proto_item      *te;
4403
4404         length = tvb_get_ntohs(tvb, offset + 1);
4405         nsapi = tvb_get_guint8(tvb, offset + 3) & 0x0F;
4406
4407         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Radio Access Bearer Setup Information");
4408         ext_tree_rab_setup = proto_item_add_subtree(te, ett_gtp_rab_setup);
4409
4410         proto_tree_add_text(ext_tree_rab_setup, tvb, offset+1, 2, "RAB setup length : %u", length);
4411         proto_tree_add_uint(ext_tree_rab_setup, hf_gtp_nsapi, tvb, offset+3, 1, nsapi);
4412
4413         if (length > 1) {
4414
4415                 teid = tvb_get_ntohl(tvb, offset + 4);
4416
4417                 proto_tree_add_uint(ext_tree_rab_setup, hf_gtp_teid_data, tvb, offset+4, 4, teid);
4418
4419                 switch (length) {
4420                         case 12:
4421                                 addr_ipv4 = tvb_get_ipv4(tvb, offset+8);
4422                                 proto_tree_add_ipv4(ext_tree_rab_setup, hf_gtp_rnc_ipv4, tvb, offset+8, 4, addr_ipv4);
4423                                 break;
4424                         case 24:
4425                                 tvb_get_ipv6(tvb, offset+8, &addr_ipv6);
4426                                 proto_tree_add_ipv6(ext_tree_rab_setup, hf_gtp_rnc_ipv6, tvb, offset+8, 16, (guint8 *)&addr_ipv6);
4427                                 break;
4428                         default:
4429                                 break;
4430                 }
4431         }
4432
4433         return 3 + length;
4434 }
4435
4436
4437 /* GPRS:        not present
4438  * UMTS:        29.060 v4.0, chapter 7.7.40
4439  */
4440 static int
4441 decode_gtp_hdr_list(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4442
4443         int             i;
4444         guint8          length, hdr;
4445         proto_tree      *ext_tree_hdr_list;
4446         proto_item      *te;
4447
4448         length = tvb_get_guint8(tvb, offset + 1);
4449
4450         te = proto_tree_add_text(tree, tvb, offset, 2+length, "%s", val_to_str(GTP_EXT_HDR_LIST, gtp_val, "Unknown"));
4451         ext_tree_hdr_list = proto_item_add_subtree(te, ett_gtp_hdr_list);
4452
4453         proto_tree_add_text(ext_tree_hdr_list, tvb, offset+1, 1, "Number of Extension Header Types in list (i.e., length) : %u", length);
4454
4455         for(i=0 ; i<length ; i++) {
4456                 hdr = tvb_get_guint8(tvb, offset+2+i);
4457
4458                 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);
4459         }
4460
4461         return 2 + length;
4462 }
4463
4464 /* GPRS:        not present
4465  * UMTS:        29.060 v4.0, chapter 7.7.41
4466  * TODO:        find TriggerID description
4467  */
4468 static int
4469 decode_gtp_trigger_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4470
4471         guint16         length;
4472
4473         length = tvb_get_ntohs(tvb, offset + 1);
4474
4475         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_TRIGGER_ID, gtp_val, "Unknown"), length);
4476
4477         return 3 + length;
4478
4479 }
4480
4481 /* GPRS:        not present
4482  * UMTS:        29.060 v4.0, chapter 7.7.42
4483  * TODO:        find OMC-ID description
4484  */
4485 static int
4486 decode_gtp_omc_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4487
4488         guint16         length;
4489
4490         length = tvb_get_ntohs(tvb, offset + 1);
4491
4492         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_OMC_ID, gtp_val, "Unknown"), length);
4493
4494         return 3 + length;
4495
4496 }
4497
4498 /* GPRS:        9.60 v7.6.0, chapter 7.9.25
4499  * UMTS:        29.060 v6.11.0, chapter 7.7.44 Charging Gateway Address
4500  */
4501 static int
4502 decode_gtp_chrg_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4503
4504         guint16         length;
4505         guint32         addr_ipv4;
4506         struct  e_in6_addr addr_ipv6;
4507         proto_tree      *ext_tree_chrg_addr;
4508         proto_item      *te;
4509
4510         length = tvb_get_ntohs(tvb, offset+1);
4511
4512         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_CHRG_ADDR, gtp_val, "Unknown"));
4513         ext_tree_chrg_addr = proto_item_add_subtree(te, ett_gtp_chrg_addr);
4514
4515         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);
4516
4517         switch (length) {
4518                 case 4:
4519                         addr_ipv4 = tvb_get_ipv4(tvb, offset+3);
4520                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4521                         proto_tree_add_ipv4 (ext_tree_chrg_addr, hf_gtp_chrg_ipv4, tvb, offset+3, 4, addr_ipv4);
4522                         break;
4523                 case 16:
4524                         tvb_get_ipv6(tvb, offset+3, &addr_ipv6);
4525                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4526                         proto_tree_add_ipv6 (ext_tree_chrg_addr, hf_gtp_chrg_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
4527                         break;
4528                 default:
4529                         proto_item_append_text(te, "unknown type or wrong length");
4530                         break;
4531         }
4532
4533         return 3 + length;
4534 }
4535
4536 /* GPRS:        ?
4537  * UMTS:        29.060 v6.11.0, chapter 7.7.44 RAN Transparent Container
4538  */
4539  static int
4540  decode_gtp_ran_tr_cont(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4541
4542         guint16         length;
4543         proto_tree      *ext_tree;
4544         proto_item      *te;
4545
4546         length = tvb_get_ntohs(tvb, offset+1);
4547         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_RAN_TR_CONT, gtp_val, "Unknown"));
4548         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_ran_tr_cont);
4549         
4550         offset++;
4551         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4552         offset = offset +2;
4553         /* TODO add decoding of data */
4554         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4555
4556         return 3 + length;
4557
4558   }
4559  
4560 /* GPRS:        ?
4561  * UMTS:        29.060 v6.11.0, chapter 7.7.45 PDP Context Prioritization
4562  */
4563  static int
4564  decode_gtp_pdp_cont_prio(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4565
4566         guint16         length;
4567         proto_tree      *ext_tree;
4568         proto_item      *te;
4569
4570         length = tvb_get_ntohs(tvb, offset+1);
4571         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_PDP_CONT_PRIO, gtp_val, "Unknown"));
4572         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_pdp_cont_prio);
4573         
4574         offset++;
4575         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4576         offset = offset +2;
4577         /* TODO add decoding of data */
4578         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4579
4580         return 3 + length;
4581
4582   }
4583 /* GPRS:        ?
4584  * UMTS:        29.060 v6.11.0, chapter 7.7.45A Additional RAB Setup Information
4585  */
4586 static int
4587 decode_gtp_add_rab_setup_inf(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4588
4589         guint16         length;
4590         proto_tree      *ext_tree;
4591         proto_item      *te;
4592
4593         length = tvb_get_ntohs(tvb, offset+1);
4594         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_ADD_RAB_SETUP_INF, gtp_val, "Unknown"));
4595         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_rab_setup_inf);
4596         
4597         offset++;
4598         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4599         offset = offset +2;
4600         /* TODO add decoding of data */
4601         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4602
4603         return 3 + length;
4604
4605   }
4606  
4607
4608  /* GPRS:       ?
4609  * UMTS:        29.060 v6.11.0, chapter 7.7.47 SGSN Number
4610  */
4611  static int
4612  decode_gtp_ssgn_no(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4613
4614         guint16         length;
4615         proto_tree      *ext_tree;
4616         proto_item      *te;
4617
4618         length = tvb_get_ntohs(tvb, offset+1);
4619         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_SSGN_NO, gtp_val, "Unknown"));
4620         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_ssgn_no);
4621         
4622         offset++;
4623         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4624         offset = offset +2;
4625         /* TODO add decoding of data */
4626         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4627
4628         return 3 + length;
4629
4630   }
4631
4632 /* GPRS:        ?
4633  * UMTS:        29.060 v6.11.0, chapter 7.7.48 Common Flags
4634  */
4635  static int
4636  decode_gtp_common_flgs(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4637
4638         guint16         length;
4639         proto_tree      *ext_tree;
4640         proto_item      *te;
4641
4642         length = tvb_get_ntohs(tvb, offset+1);
4643         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_COMMON_FLGS, gtp_val, "Unknown"));
4644         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_common_flgs);
4645         
4646         offset++;
4647         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4648         offset = offset +2;
4649         /* TODO add decoding of data */
4650         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4651
4652         return 3 + length;
4653
4654   }
4655
4656 /* GPRS:        ?
4657  * UMTS:        29.060 v6.11.0, chapter 7.7.49
4658  */
4659 static int
4660 decode_gtp_apn_res(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4661
4662         guint16         length;
4663         proto_tree      *ext_tree_apn_res;
4664         proto_item      *te;
4665
4666         length = tvb_get_ntohs(tvb, offset+1);
4667         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_APN_RES, gtp_val, "Unknown"));
4668         ext_tree_apn_res = proto_item_add_subtree(te, ett_gtp_ext_tree_apn_res);
4669         
4670         offset++;
4671         proto_tree_add_item(ext_tree_apn_res, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4672         offset = offset +2;
4673
4674         /* Restriction Type value */
4675         proto_tree_add_item(ext_tree_apn_res, hf_gtp_ext_apn_res, tvb, offset, length, FALSE);
4676         return 3 + length;
4677 }
4678
4679 /* GPRS:        ?
4680  * UMTS:        29.060 v6.11.0, chapter 7.7.50
4681  * RAT Type
4682  * Type = 151 (Decimal)
4683  */
4684 static int
4685 decode_gtp_rat_type(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4686
4687         guint16         length;
4688         proto_tree      *ext_tree_rat_type;
4689         proto_item      *te;
4690
4691         length = tvb_get_ntohs(tvb, offset+1);
4692         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_RAT_TYPE, gtp_val, "Unknown"));
4693         ext_tree_rat_type = proto_item_add_subtree(te, ett_gtp_ext_rat_type);
4694         
4695         offset++;
4696         proto_tree_add_item(ext_tree_rat_type, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4697         offset = offset +2;
4698
4699         /* RAT Type value */
4700         proto_tree_add_item(ext_tree_rat_type, hf_gtp_ext_rat_type, tvb, offset, length, FALSE);
4701         
4702         return 3 + length;
4703 }
4704 /* GPRS:        ?
4705  * UMTS:        29.060 v6.11.0, chapter 7.7.51 
4706  * User Location Information
4707  * Type = 152 (Decimal)
4708  */
4709 static int
4710 decode_gtp_usr_loc_inf(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4711
4712         guint16         length;
4713         proto_tree      *ext_tree;
4714         proto_item      *te;
4715         guint8          geo_loc_type;
4716
4717         length = tvb_get_ntohs(tvb, offset+1);
4718         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_USR_LOC_INF, gtp_val, "Unknown"));
4719         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_usr_loc_inf);
4720         
4721         offset++;
4722         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4723         offset = offset +2;
4724         /* TODO add decoding of data */
4725         /* Geographic Location Type */
4726         proto_tree_add_item(ext_tree, hf_gtp_ext_geo_loc_type, tvb, offset, 1, FALSE);
4727         geo_loc_type = tvb_get_guint8(tvb,offset);
4728         offset++;
4729         
4730         if (geo_loc_type == 0)
4731                 /* Use gsm_a's function to dissect Geographic Location by faking disc ( last 0) */
4732                 be_cell_id_aux(tvb, ext_tree, offset, length-1, NULL, 0, 0);
4733         if (geo_loc_type == 1){
4734                 /* Use gsm_a's function to dissect Geographic Location by faking disc ( last 4) */
4735                 be_cell_id_aux(tvb, ext_tree, offset, length-1, NULL, 0, 4);
4736                 offset = offset + 5;
4737                 proto_tree_add_item(ext_tree, hf_gtp_ext_sac, tvb, offset, 2, FALSE);
4738         }
4739
4740         return 3 + length;
4741
4742  }
4743
4744 /* GPRS:        ?
4745  * UMTS:        29.060 v6.11.0, chapter 7.7.52 
4746  * MS Time Zone
4747  * Type = 153 (Decimal)
4748  */
4749 static int
4750 decode_gtp_ms_time_zone(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4751
4752         guint16         length;
4753         proto_tree      *ext_tree;
4754         proto_item      *te;
4755         /*guint8                data;*/
4756         /*char          sign;*/
4757
4758         length = tvb_get_ntohs(tvb, offset+1);
4759         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_MS_TIME_ZONE, gtp_val, "Unknown"));
4760         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_ms_time_zone);
4761         
4762         offset++;
4763         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4764         offset = offset +2;
4765
4766         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4767         /* 3GPP TS 23.040 version 6.6.0 Release 6 
4768          * 9.2.3.11 TP-Service-Centre-Time-Stamp (TP-SCTS)
4769          * :
4770          * The Time Zone indicates the difference, expressed in quarters of an hour, 
4771          * between the local time and GMT. In the first of the two semi-octets, 
4772          * the first bit (bit 3 of the seventh octet of the TP-Service-Centre-Time-Stamp field)
4773          * represents the algebraic sign of this difference (0: positive, 1: negative).
4774          */
4775         /*
4776     data = tvb_get_guint8(tvb, offset);
4777     sign = (data & 0x08)?'-':'+';
4778     data = (data >> 4) + (data & 0x07) * 10;
4779
4780     proto_tree_add_text(tree, tvb, offset, 1,"Timezone: GMT %c %d hours %d minutes",
4781                 sign, data / 4, data % 4 * 15);
4782
4783         */
4784         return 3 + length;
4785
4786  }
4787 /* GPRS:        ?
4788  * UMTS:        29.060 v6.11.0, chapter 7.7.53
4789  * International Mobile Equipment Identity (and Software Version) (IMEI(SV))
4790  * Type = 154 (Decimal)
4791  */
4792 static int
4793 decode_gtp_imeisv(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4794
4795         guint16         length;
4796         proto_tree      *ext_imeisv;
4797         proto_item      *te;
4798
4799         length = tvb_get_ntohs(tvb, offset+1);
4800         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_IMEISV, gtp_val, "Unknown"));
4801         ext_imeisv = proto_item_add_subtree(te, ett_gtp_ext_imeisv);
4802         
4803         offset++;
4804         proto_tree_add_item(ext_imeisv, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4805         offset = offset +2;
4806
4807         /* IMEI(SV) */
4808         proto_tree_add_item(ext_imeisv, hf_gtp_ext_imeisv, tvb, offset, length, FALSE);
4809         
4810         return 3 + length;
4811 }
4812 /* GPRS:        ?
4813  * UMTS:        29.060 v6.11.0, chapter 7.7.54 
4814  * CAMEL Charging Information Container
4815  * Type = 155 (Decimal)
4816  */
4817 static int
4818 decode_gtp_camel_chg_inf_con(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4819
4820         guint16         length;
4821         proto_tree      *ext_tree;
4822         proto_item      *te;
4823
4824         length = tvb_get_ntohs(tvb, offset+1);
4825         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_CAMEL_CHG_INF_CON, gtp_val, "Unknown"));
4826         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_camel_chg_inf_con);
4827         
4828         offset++;
4829         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4830         offset = offset +2;
4831         /* TODO add decoding of data */
4832         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4833
4834         return 3 + length;
4835
4836  }
4837 /* GPRS:        ?
4838  * UMTS:        29.060 v6.11.0, chapter 7.7.55 
4839  * MBMS UE Context
4840  */
4841 static int
4842 decode_gtp_mbms_ue_ctx(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4843
4844         guint16         length;
4845         proto_tree      *ext_tree;
4846         proto_item      *te;
4847
4848         length = tvb_get_ntohs(tvb, offset+1);
4849         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_UE_CTX, gtp_val, "Unknown"));
4850         ext_tree = proto_item_add_subtree(te, ett_GTP_EXT_MBMS_UE_CTX);
4851         
4852         offset++;
4853         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4854         offset = offset +2;
4855         /* TODO add decoding of data */
4856         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4857
4858         return 3 + length;
4859
4860  }
4861
4862 /* GPRS:        ?
4863  * UMTS:        29.060 v6.11.0, chapter 7.7.56
4864  * Temporary Mobile Group Identity (TMGI)
4865  */
4866 static int
4867 decode_gtp_tmgi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4868
4869         guint16         length;
4870         proto_tree      *ext_tree;
4871         proto_item      *te;
4872
4873         length = tvb_get_ntohs(tvb, offset+1);
4874         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_TMGI, gtp_val, "Unknown"));
4875         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_tmgi);
4876         
4877         offset++;
4878         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4879         offset = offset +2;
4880
4881         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4882
4883         return 3 + length;
4884
4885  }
4886
4887 /* GPRS:        ?
4888  * UMTS:        29.060 v6.11.0, chapter 7.7.57
4889  * RIM Routing Address
4890  */
4891 static int
4892 decode_gtp_rim_ra(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4893
4894         guint16         length;
4895         proto_tree      *ext_tree;
4896         proto_item      *te;
4897
4898         length = tvb_get_ntohs(tvb, offset+1);
4899         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_RIM_RA, gtp_val, "Unknown"));
4900         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_rim_ra);
4901         
4902         offset++;
4903         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4904         offset = offset +2;
4905         /* TODO add decoding of data */
4906         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4907         /*  
4908          * Octets 4-n are coded according to 3GPP TS 48.018 [20] 11.3.77 RIM Routing Information IE octets 4-n.
4909          */
4910
4911         return 3 + length;
4912
4913  }
4914
4915 /* GPRS:        ?
4916  * UMTS:        29.060 v6.11.0, chapter 7.7.58
4917  * MBMS Protocol Configuration Options
4918  */
4919 static int
4920 decode_gtp_mbms_prot_conf_opt(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4921
4922         guint16         length;
4923         proto_tree      *ext_tree;
4924         proto_item      *te;
4925
4926         length = tvb_get_ntohs(tvb, offset+1);
4927         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_PROT_CONF_OPT, gtp_val, "Unknown"));
4928         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_mbms_prot_conf_opt);
4929         
4930         offset++;
4931         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4932         offset = offset +2;
4933         /* TODO add decoding of data */
4934         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4935
4936         return 3 + length;
4937
4938  }
4939 /* GPRS:        ?
4940  * UMTS:        29.060 v6.11.0, chapter 7.7.59
4941  * MBMS Session Duration
4942  */
4943 static int
4944 decode_gtp_mbms_ses_dur(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4945
4946         guint16         length;
4947         proto_tree      *ext_tree;
4948         proto_item      *te;
4949
4950         length = tvb_get_ntohs(tvb, offset+1);
4951         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_SES_DUR, gtp_val, "Unknown"));
4952         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_bms_ses_dur);
4953         
4954         offset++;
4955         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4956         offset = offset +2;
4957         /* TODO add decoding of data */
4958         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4959
4960         return 3 + length;
4961
4962  }
4963
4964 /* GPRS:        ?
4965  * UMTS:        29.060 v6.11.0, chapter 7.7.60
4966  * MBMS Service Area
4967  */
4968 static int
4969 decode_gtp_mbms_sa(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4970
4971         guint16         length;
4972         proto_tree      *ext_tree;
4973         proto_item      *te;
4974
4975         length = tvb_get_ntohs(tvb, offset+1);
4976         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_SA, gtp_val, "Unknown"));
4977         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_mbms_sa);
4978         
4979         offset++;
4980         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
4981         offset = offset +2;
4982         /* TODO add decoding of data */
4983         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
4984
4985         return 3 + length;
4986
4987  }
4988
4989 /* GPRS:        ?
4990  * UMTS:        29.060 v6.11.0, chapter 7.7.61
4991  * Source RNC PDCP context info
4992  */
4993 static int
4994 decode_gtp_src_rnc_pdp_ctx_inf(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4995
4996         guint16         length;
4997         proto_tree      *ext_tree;
4998         proto_item      *te;
4999
5000         length = tvb_get_ntohs(tvb, offset+1);
5001         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_SRC_RNC_PDP_CTX_INF, gtp_val, "Unknown"));
5002         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_src_rnc_pdp_ctx_inf);
5003         
5004         offset++;
5005         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5006         offset = offset +2;
5007         /* TODO add decoding of data */
5008         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5009
5010         return 3 + length;
5011
5012  }
5013
5014 /* GPRS:        ?
5015  * UMTS:        29.060 v6.11.0, chapter 7.7.62 
5016  * Additional Trace Info
5017  */
5018 static int
5019 decode_gtp_add_trs_inf(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5020
5021         guint16         length;
5022         proto_tree      *ext_tree;
5023         proto_item      *te;
5024
5025         length = tvb_get_ntohs(tvb, offset+1);
5026         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_ADD_TRS_INF, gtp_val, "Unknown"));
5027         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_add_trs_inf);
5028         
5029         offset++;
5030         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5031         offset = offset +2;
5032         /* TODO add decoding of data */
5033         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5034
5035         return 3 + length;
5036
5037  }
5038
5039 /* GPRS:        ?
5040  * UMTS:        29.060 v6.11.0, chapter 7.7.63 
5041  * Hop Counter
5042  */
5043 static int
5044 decode_gtp_hop_count(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5045
5046         guint16         length;
5047         proto_tree      *ext_tree;
5048         proto_item      *te;
5049
5050         length = tvb_get_ntohs(tvb, offset+1);
5051         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_HOP_COUNT, gtp_val, "Unknown"));
5052         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_hop_count);
5053         
5054         offset++;
5055         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5056         offset = offset +2;
5057         /* TODO add decoding of data */
5058         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5059
5060         return 3 + length;
5061
5062  }
5063
5064 /* GPRS:        ?
5065  * UMTS:        29.060 v6.11.0, chapter 7.7.64 
5066  * Selected PLMN ID
5067  */
5068 static int
5069 decode_gtp_sel_plmn_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5070
5071         guint16         length;
5072         proto_tree      *ext_tree;
5073         proto_item      *te;
5074
5075         length = tvb_get_ntohs(tvb, offset+1);
5076         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_SEL_PLMN_ID, gtp_val, "Unknown"));
5077         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_sel_plmn_id);
5078         
5079         offset++;
5080         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5081         offset = offset +2;
5082         /* TODO add decoding of data */
5083         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5084
5085         return 3 + length;
5086
5087  }
5088
5089 /* GPRS:        ?
5090  * UMTS:        29.060 v6.11.0, chapter 7.7.65
5091  * MBMS Session Identifier
5092  */
5093 static int
5094 decode_gtp_mbms_ses_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5095
5096         guint16         length;
5097         proto_tree      *ext_tree;
5098         proto_item      *te;
5099
5100         length = tvb_get_ntohs(tvb, offset+1);
5101         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_SES_ID, gtp_val, "Unknown"));
5102         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_mbms_ses_id);
5103         
5104         offset++;
5105         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5106         offset = offset +2;
5107         /* TODO add decoding of data */
5108         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5109
5110         return 3 + length;
5111
5112  }
5113
5114 /* GPRS:        ?
5115  * UMTS:        29.060 v6.11.0, chapter 7.7.66
5116  * MBMS 2G/3G Indicator
5117  */
5118 static int
5119 decode_gtp_mbms_2g_3g_ind(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5120
5121         guint16         length;
5122         proto_tree      *ext_tree;
5123         proto_item      *te;
5124
5125         length = tvb_get_ntohs(tvb, offset+1);
5126         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_2G_3G_IND, gtp_val, "Unknown"));
5127         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_mbms_2g_3g_ind);
5128         
5129         offset++;
5130         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5131         offset = offset +2;
5132         /* TODO add decoding of data */
5133         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5134
5135         return 3 + length;
5136
5137  }
5138
5139 /* GPRS:        ?
5140  * UMTS:        29.060 v6.11.0, chapter 7.7.67
5141  * Enhanced NSAPI
5142  */
5143 static int
5144 decode_gtp_enh_nsapi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5145
5146         guint16         length;
5147         proto_tree      *ext_tree;
5148         proto_item      *te;
5149
5150         length = tvb_get_ntohs(tvb, offset+1);
5151         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_ENH_NSAPI, gtp_val, "Unknown"));
5152         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_enh_nsapi);
5153         
5154         offset++;
5155         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5156         offset = offset +2;
5157         /* TODO add decoding of data */
5158         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5159
5160         return 3 + length;
5161
5162  }
5163
5164 /* GPRS:        ?
5165  * UMTS:        29.060 v6.11.0, chapter 7.7.68
5166  * Additional MBMS Trace Info
5167  */
5168 static int
5169 decode_gtp_add_mbms_trs_inf(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5170
5171         guint16         length;
5172         proto_tree      *ext_tree;
5173         proto_item      *te;
5174
5175         length = tvb_get_ntohs(tvb, offset+1);
5176         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_ADD_MBMS_TRS_INF, gtp_val, "Unknown"));
5177         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_ad_mbms_trs_inf);
5178         
5179         offset++;
5180         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5181         offset = offset +2;
5182         /* TODO add decoding of data */
5183         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5184
5185         return 3 + length;
5186
5187  }
5188
5189 /* GPRS:        ?
5190  * UMTS:        29.060 v6.11.0, chapter 7.7.69
5191  * MBMS Session Identity Repetition Number
5192  */
5193 static int
5194 decode_gtp_mbms_ses_id_rep_no(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5195
5196         guint16         length;
5197         proto_tree      *ext_tree;
5198         proto_item      *te;
5199
5200         length = tvb_get_ntohs(tvb, offset+1);
5201         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_SES_ID_REP_NO, gtp_val, "Unknown"));
5202         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_mbms_ses_id_rep_no);
5203         
5204         offset++;
5205         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5206         offset = offset +2;
5207         /* TODO add decoding of data */
5208         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5209
5210         return 3 + length;
5211
5212  }
5213
5214 /* GPRS:        ?
5215  * UMTS:        29.060 v6.11.0, chapter 7.7.70
5216  * MBMS Time To Data Transfer
5217  */
5218 static int
5219 decode_gtp_mbms_time_to_data_tr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5220
5221         guint16         length;
5222         proto_tree      *ext_tree;
5223         proto_item      *te;
5224
5225         length = tvb_get_ntohs(tvb, offset+1);
5226         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_MBMS_TIME_TO_DATA_TR, gtp_val, "Unknown"));
5227         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_mbms_time_to_data_tr);
5228         
5229         offset++;
5230         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5231         offset = offset +2;
5232         /* TODO add decoding of data */
5233         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5234
5235         return 3 + length;
5236
5237  }
5238
5239 /* GPRS:        ?
5240  * UMTS:        29.060 v6.11.0, chapter 7.7.71
5241  * PS Handover Request Context
5242  */
5243 static int
5244 decode_gtp_ps_ho_req_ctx(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5245
5246         guint16         length;
5247         proto_tree      *ext_tree;
5248         proto_item      *te;
5249
5250         length = tvb_get_ntohs(tvb, offset+1);
5251         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_PS_HO_REQ_CTX, gtp_val, "Unknown"));
5252         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_ps_ho_req_ctx);
5253         
5254         offset++;
5255         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5256         offset = offset +2;
5257         /* TODO add decoding of data */
5258         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5259
5260         return 3 + length;
5261
5262  }
5263
5264 /* GPRS:        ?
5265  * UMTS:        29.060 v6.11.0, chapter 7.7.72
5266  * BSS Container
5267  */
5268 static int
5269 decode_gtp_bss_cont(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5270
5271         guint16         length;
5272         proto_tree      *ext_tree;
5273         proto_item      *te;
5274
5275         length = tvb_get_ntohs(tvb, offset+1);
5276         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_BSS_CONT, gtp_val, "Unknown"));
5277         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_bss_cont);
5278         
5279         offset++;
5280         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5281         offset = offset +2;
5282         /* TODO add decoding of data */
5283         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5284         /*
5285          * The content of this container is defined in 3GPP TS 48.018
5286          */
5287
5288         return 3 + length;
5289
5290  }
5291
5292 /* GPRS:        ?
5293  * UMTS:        29.060 v6.11.0, chapter 7.7.73
5294  * Cell Identification
5295  */
5296 static int
5297 decode_gtp_cell_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5298
5299         guint16         length;
5300         proto_tree      *ext_tree;
5301         proto_item      *te;
5302
5303         length = tvb_get_ntohs(tvb, offset+1);
5304         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_CELL_ID, gtp_val, "Unknown"));
5305         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_cell_id);
5306         
5307         offset++;
5308         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5309         offset = offset +2;
5310         /* TODO add decoding of data */
5311         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5312         /*
5313          * for PS handover from A/Gb mode, the identification of a target cell (Cell ID 1) and the identification of the
5314          * source cell (Cell ID 2) as defined in 3GPP TS 48.018 [20].
5315          *
5316          * for PS handover from Iu mode, the identification of a target cell (Cell ID 1)) and the identification of the
5317          * source RNC (RNC-ID) as defined in 3GPP TS 48.018
5318          */
5319
5320         return 3 + length;
5321
5322  }
5323
5324 /* GPRS:        ?
5325  * UMTS:        29.060 v6.11.0, chapter 7.7.74
5326  * PDU Numbers
5327  */
5328 static int
5329 decode_gtp_pdu_no(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5330
5331         guint16         length;
5332         proto_tree      *ext_tree;
5333         proto_item      *te;
5334
5335         length = tvb_get_ntohs(tvb, offset+1);
5336         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_PDU_NO, gtp_val, "Unknown"));
5337         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_pdu_no);
5338         
5339         offset++;
5340         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5341         offset = offset +2;
5342         /* TODO add decoding of data */
5343         proto_tree_add_text(ext_tree, tvb, offset, length, "Data not decoded yet");
5344
5345         return 3 + length;
5346
5347  }
5348
5349 /* GPRS:        ?
5350  * UMTS:        29.060 v6.11.0, chapter 7.7.75
5351  * BSSGP Cause
5352  */
5353 static int
5354 decode_gtp_bssgp_cause(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5355
5356         guint16         length;
5357         proto_tree      *ext_tree;
5358         proto_item      *te;
5359
5360         length = tvb_get_ntohs(tvb, offset+1);
5361         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s", val_to_str(GTP_EXT_BSSGP_CAUSE, gtp_val, "Unknown"));
5362         ext_tree = proto_item_add_subtree(te, ett_gtp_ext_bssgp_cause);
5363         
5364         offset++;
5365         proto_tree_add_item(ext_tree, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5366         offset = offset +2;
5367         
5368         /*      
5369          * The BSSGP Cause information element contains the cause as defined in 3GPP TS 48.018
5370          */
5371         proto_tree_add_item(ext_tree, hf_gtp_bssgp_cause, tvb, offset, 2, FALSE);
5372
5373         return 3 + length;
5374
5375  }
5376
5377 /* GPRS:        12.15
5378  * UMTS:        33.015
5379  */
5380 static int
5381 decode_gtp_rel_pack(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5382
5383         guint16         length, n, number;
5384         proto_tree      *ext_tree_rel_pack;
5385         proto_item      *te;
5386
5387         length = tvb_get_ntohs(tvb, offset + 1);
5388
5389         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of released packets IE");
5390         ext_tree_rel_pack = proto_item_add_subtree(te, ett_gtp_rel_pack);
5391
5392         n = 0;
5393
5394         while (n < length) {
5395
5396                 number = tvb_get_ntohs(tvb, offset + 3 + n);
5397                 proto_tree_add_text(ext_tree_rel_pack, tvb, offset + 3 + n, 2, "%u", number);
5398                 n = n + 2;
5399
5400         }
5401
5402         return 3 + length;
5403 }
5404
5405 /* GPRS:        12.15
5406  * UMTS:        33.015
5407  */
5408 static int
5409 decode_gtp_can_pack(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5410
5411         guint16         length, n, number;
5412         proto_tree      *ext_tree_can_pack;
5413         proto_item      *te;
5414
5415         length = tvb_get_ntohs(tvb, offset + 1);
5416
5417         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of cancelled  packets IE");
5418         ext_tree_can_pack = proto_item_add_subtree(te, ett_gtp_can_pack);
5419
5420         n = 0;
5421
5422         while (n < length) {
5423
5424                 number = tvb_get_ntohs(tvb, offset + 3 + n);
5425                 proto_tree_add_text(ext_tree_can_pack, tvb, offset + 3 + n, 2, "%u", number);
5426                 n = n + 2;
5427         }
5428
5429         return 3 + length;
5430 }
5431
5432 /* CDRs dissector */
5433 static int
5434 decode_gtp_data_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5435
5436         guint16         length, format_ver;
5437         guint8          no, format;
5438         proto_tree      *ext_tree;
5439         proto_item      *te;
5440         tvbuff_t        *next_tvb;
5441
5442         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_DATA_REQ, gtp_val, "Unknown message"));
5443         ext_tree = proto_item_add_subtree(te, ett_gtp_ext);
5444
5445         length = tvb_get_ntohs(tvb, offset + 1);
5446         no = tvb_get_guint8(tvb, offset + 3);
5447         format = tvb_get_guint8(tvb, offset + 4);
5448         format_ver = tvb_get_ntohs(tvb, offset + 5);
5449
5450         proto_tree_add_text(ext_tree, tvb, offset+1, 2, "Length: %u", length);
5451         proto_tree_add_text(ext_tree, tvb, offset+3, 1, "Number of data records: %u", no);
5452         proto_tree_add_text(ext_tree, tvb, offset+4, 1, "Data record format: %u", format);
5453         proto_tree_add_text(ext_tree, tvb, offset+5, 2, "Data record format version: %u", format_ver);
5454
5455         if (gtpcdr_handle) {
5456                 next_tvb = tvb_new_subset (tvb, offset, -1, -1);
5457                 call_dissector (gtpcdr_handle, next_tvb, pinfo, tree);
5458         }
5459         else
5460                 proto_tree_add_text (tree, tvb, offset, 0, "Data");
5461
5462         return 3+length;
5463 }
5464
5465 /* GPRS:        12.15
5466  * UMTS:        33.015
5467  */
5468 static int
5469 decode_gtp_data_resp(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5470
5471         guint16         length, n, number;
5472         proto_tree      *ext_tree_data_resp;
5473         proto_item      *te;
5474
5475         length = tvb_get_ntohs(tvb, offset + 1);
5476
5477         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Requests responded");
5478         ext_tree_data_resp = proto_item_add_subtree(te, ett_gtp_data_resp);
5479
5480         n = 0;
5481
5482         while (n < length) {
5483
5484                 number = tvb_get_ntohs(tvb, offset + 3 + n);
5485                 proto_tree_add_text(ext_tree_data_resp, tvb, offset + 3 + n, 2, "%u", number);
5486                 n = n + 2;
5487
5488         }
5489
5490         return 3 + length;
5491
5492 }
5493
5494 /* GPRS:        12.15
5495  * UMTS:        33.015
5496  */
5497 static int
5498 decode_gtp_node_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5499
5500         guint16         length;
5501         guint32         addr_ipv4;
5502         struct  e_in6_addr addr_ipv6;
5503         proto_tree      *ext_tree_node_addr;
5504         proto_item      *te;
5505
5506         length = tvb_get_ntohs(tvb, offset+1);
5507
5508         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Node address: ");
5509         ext_tree_node_addr = proto_item_add_subtree(te, ett_gtp_node_addr);
5510
5511         proto_tree_add_text (ext_tree_node_addr, tvb, offset+1, 2, "Node address length: %u", length);
5512
5513         switch (length) {
5514                 case 4:
5515                         addr_ipv4 = tvb_get_ipv4(tvb, offset+3);
5516                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
5517                         proto_tree_add_ipv4 (ext_tree_node_addr, hf_gtp_node_ipv4, tvb, offset+3, 4, addr_ipv4);
5518                         break;
5519                 case 16:
5520                         tvb_get_ipv6(tvb, offset+3, &addr_ipv6);
5521                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
5522                         proto_tree_add_ipv6 (ext_tree_node_addr, hf_gtp_node_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
5523                         break;
5524                 default:
5525                         proto_item_append_text(te, "unknown type or wrong length");
5526                         break;
5527         }
5528
5529         return 3 + length;
5530
5531 }
5532
5533 /* GPRS:        9.60 v7.6.0, chapter 7.9.26
5534  * UMTS:        29.060 v4.0, chapter 7.7.46 Private Extension
5535  * 
5536  */
5537
5538 static int
5539 decode_gtp_priv_ext(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5540
5541         guint16         length, ext_id;
5542         proto_tree      *ext_tree_priv_ext;
5543         proto_item      *te;
5544
5545         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_PRIV_EXT, gtp_val, "Unknown message"));
5546         ext_tree_priv_ext = proto_item_add_subtree(te, ett_gtp_ext);
5547
5548         offset++;
5549         length = tvb_get_ntohs(tvb, offset);
5550         proto_tree_add_item(ext_tree_priv_ext, hf_gtp_ext_length, tvb, offset, 2, FALSE);
5551         offset = offset+2;
5552         if (length >= 2) {
5553                 ext_id = tvb_get_ntohs(tvb, offset);
5554                 proto_tree_add_uint(ext_tree_priv_ext, hf_gtp_ext_id, tvb, offset, 2, ext_id);
5555                 offset = offset+2;
5556
5557                 /*
5558                  * XXX - is this always a text string?  Or should it be
5559                  * displayed as hex data?
5560                  */
5561                 if (length > 2)
5562                         proto_tree_add_item(ext_tree_priv_ext, hf_gtp_ext_val, tvb, offset, length-2, FALSE);
5563         }
5564
5565         return 3+length;
5566 }
5567
5568 static int
5569 decode_gtp_unknown(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
5570
5571         proto_tree_add_text(tree, tvb, offset, 1, "Unknown extension header");
5572
5573         return tvb_length_remaining(tvb, offset);
5574 }
5575
5576 static void
5577 dissect_gtp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
5578 {
5579         struct _gtp_hdr gtp_hdr;
5580         proto_tree      *gtp_tree, *flags_tree;
5581         proto_item      *ti, *tf;
5582         int             i, offset, length, gtp_prime, checked_field, mandatory;
5583         int             seq_no, flow_label;
5584         guint8          pdu_no, next_hdr = 0, ext_hdr_val;
5585         const guint8    *tid_val;
5586         gchar           *tid_str;
5587         guint32         teid;
5588         tvbuff_t        *next_tvb;
5589         guint8          sub_proto, acfield_len = 0, control_field;
5590
5591         if (check_col(pinfo->cinfo, COL_PROTOCOL))
5592                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP");
5593         if (check_col(pinfo->cinfo, COL_INFO))
5594                 col_clear(pinfo->cinfo, COL_INFO);
5595
5596         tvb_memcpy(tvb, (guint8 *)&gtp_hdr, 0, 4);
5597
5598         if (!(gtp_hdr.flags & 0x10))
5599                 gtp_prime = 1;
5600         else
5601                 gtp_prime = 0;
5602
5603         switch ((gtp_hdr.flags >> 5) & 0x07) {
5604                 case 0:
5605                         gtp_version = 0;
5606                         break;
5607                 case 1:
5608                         gtp_version = 1;
5609                         break;
5610                 default:
5611                         gtp_version = 1;
5612                         break;
5613         }
5614
5615         if (check_col(pinfo->cinfo, COL_INFO))
5616                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(gtp_hdr.message, message_type, "Unknown"));
5617
5618         if (tree) {
5619                 ti = proto_tree_add_item (tree, proto_gtp, tvb, 0, -1, FALSE);
5620                 gtp_tree = proto_item_add_subtree(ti, ett_gtp);
5621
5622                 tf = proto_tree_add_uint (gtp_tree, hf_gtp_flags, tvb, 0, 1, gtp_hdr.flags);
5623                 flags_tree = proto_item_add_subtree (tf, ett_gtp_flags);
5624
5625                 proto_tree_add_uint (flags_tree, hf_gtp_flags_ver, tvb, 0, 1, gtp_hdr.flags);
5626                 proto_tree_add_uint (flags_tree, hf_gtp_flags_pt, tvb, 0, 1, gtp_hdr.flags);
5627
5628                 switch (gtp_version) {
5629                         case 0:
5630                                 proto_tree_add_uint (flags_tree, hf_gtp_flags_spare1, tvb, 0, 1, gtp_hdr.flags);
5631                                 proto_tree_add_boolean (flags_tree, hf_gtp_flags_snn, tvb, 0, 1, gtp_hdr.flags);
5632                                 break;
5633                         case 1:
5634                                 proto_tree_add_uint (flags_tree, hf_gtp_flags_spare2, tvb, 0, 1, gtp_hdr.flags);
5635                                 proto_tree_add_boolean (flags_tree, hf_gtp_flags_e, tvb, 0, 1, gtp_hdr.flags);
5636                                 proto_tree_add_boolean (flags_tree, hf_gtp_flags_s, tvb, 0, 1, gtp_hdr.flags);
5637                                 proto_tree_add_boolean (flags_tree, hf_gtp_flags_pn, tvb, 0, 1, gtp_hdr.flags);
5638                                 break;
5639                         default:
5640                                 break;
5641                 }
5642
5643                 proto_tree_add_uint (gtp_tree, hf_gtp_message_type, tvb, 1, 1, gtp_hdr.message);
5644
5645                 gtp_hdr.length = g_ntohs (gtp_hdr.length);
5646                 proto_tree_add_uint (gtp_tree, hf_gtp_length, tvb, 2, 2, gtp_hdr.length);
5647
5648                 offset = 4;
5649
5650                 if (gtp_prime) {
5651                         seq_no = tvb_get_ntohs (tvb, offset);
5652                         proto_tree_add_uint (gtp_tree, hf_gtp_seq_number, tvb, offset, 2, seq_no);
5653                         offset += 2;
5654                 } else
5655                 switch (gtp_version) {
5656                         case 0:
5657                                 seq_no = tvb_get_ntohs (tvb, offset);
5658                                 proto_tree_add_uint (gtp_tree, hf_gtp_seq_number, tvb, offset, 2, seq_no);
5659                                 offset += 2;
5660
5661                                 flow_label = tvb_get_ntohs (tvb, offset);
5662                                 proto_tree_add_uint (gtp_tree, hf_gtp_flow_label, tvb, offset, 2, flow_label);
5663                                 offset += 2;
5664
5665                                 pdu_no = tvb_get_guint8 (tvb, offset);
5666                                 proto_tree_add_uint (gtp_tree, hf_gtp_sndcp_number, tvb, offset, 1, pdu_no);
5667                                 offset += 4;
5668
5669                                 tid_val = tvb_get_ptr(tvb, offset, 8);
5670                                 tid_str = id_to_str (tid_val);
5671                                 proto_tree_add_string (gtp_tree, hf_gtp_tid, tvb, offset, 8, tid_str);
5672                                 offset += 8;
5673                                 break;
5674                         case 1:
5675                                 teid = tvb_get_ntohl (tvb, offset);
5676                                 proto_tree_add_uint (gtp_tree, hf_gtp_teid, tvb, offset, 4, teid);
5677                                 offset += 4;
5678
5679                                 if (gtp_hdr.flags & 0x07) {
5680                                         seq_no = tvb_get_ntohs (tvb, offset);
5681                                         proto_tree_add_uint (gtp_tree, hf_gtp_seq_number, tvb, offset, 2, seq_no);
5682                                         offset += 2;
5683
5684                                         pdu_no = tvb_get_guint8 (tvb, offset);
5685                                         proto_tree_add_uint (gtp_tree, hf_gtp_npdu_number, tvb, offset, 1, pdu_no);
5686                                         offset++;
5687
5688                                         next_hdr = tvb_get_guint8 (tvb, offset);
5689                                         proto_tree_add_uint (gtp_tree, hf_gtp_next, tvb, offset, 1, next_hdr);
5690                                         if (!next_hdr)
5691                                                 offset++;
5692                                 }
5693                                 break;
5694                         default:
5695                                 break;
5696                 }
5697
5698
5699                 if (gtp_hdr.message != GTP_MSG_TPDU) {
5700                         proto_tree_add_text(gtp_tree, tvb, 0, 0, "[--- end of GTP header, beginning of extension headers ---]");
5701                         length = tvb_length (tvb);
5702                         mandatory = 0;          /* check order of GTP fields against ETSI */
5703                         for (;;) {
5704                                 if (offset >= length)
5705                                         break;
5706                                 if (next_hdr) {
5707                                         ext_hdr_val = next_hdr;
5708                                         next_hdr = 0;
5709                                 }
5710                                 else
5711                                         ext_hdr_val = tvb_get_guint8 (tvb, offset);
5712                                 if (gtp_etsi_order) {
5713                                         checked_field = check_field_presence (gtp_hdr.message, ext_hdr_val , (int *)&mandatory);
5714                                         switch (checked_field) {
5715                                                 case -2: proto_tree_add_text (gtp_tree, tvb, 0, 0, "[WARNING] message not found");
5716                                                          break;
5717                                                 case -1: proto_tree_add_text (gtp_tree, tvb, 0, 0, "[WARNING] field not present");
5718                                                          break;
5719                                                 case 0:  break;
5720                                                 default: proto_tree_add_text (gtp_tree, tvb, offset, 1, "[WARNING] wrong next field, should be: %s", val_to_str(checked_field, gtp_val, "Unknown extension field"));
5721                                                          break;
5722                                         }
5723                                 }
5724
5725                                 i = -1;
5726                                 while (gtpopt[++i].optcode)
5727                                         if (gtpopt[i].optcode == ext_hdr_val)
5728                                                 break;
5729                                 offset = offset + (*gtpopt[i].decode)(tvb, offset, pinfo, gtp_tree);
5730                         }
5731                 }
5732         }
5733
5734         if ((gtp_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
5735
5736                 if (gtp_prime)
5737                         offset = 6;
5738                 else
5739                 if (gtp_version == 1) {
5740                         if (gtp_hdr.flags & 0x07)  {
5741                                 offset = 11;
5742                                 if (tvb_get_guint8 (tvb, offset) == 0)
5743                                         offset++;
5744                         }
5745                         else
5746                                 offset = 8;
5747                 }
5748                 else
5749                         offset = 20;
5750
5751                 sub_proto = tvb_get_guint8 (tvb, offset);
5752
5753                 if ((sub_proto >= 0x45) &&  (sub_proto <= 0x4e)) {
5754                         /* this is most likely an IPv4 packet
5755                          * we can exclude 0x40 - 0x44 because the minimum header size is 20 octets
5756                          * 0x4f is excluded because PPP protocol type "IPv6 header compression"
5757                          * with protocol field compression is more likely than a plain IPv4 packet with 60 octet header size */
5758
5759                         next_tvb = tvb_new_subset (tvb, offset, -1, -1);
5760                         call_dissector(ip_handle, next_tvb, pinfo, tree);
5761
5762                 } else
5763                 if ((sub_proto & 0xf0) == 0x60){
5764                         /* this is most likely an IPv6 packet */
5765                         next_tvb = tvb_new_subset (tvb, offset, -1, -1);
5766                         call_dissector (ipv6_handle, next_tvb, pinfo, tree);
5767                 } else {
5768                         /* this seems to be a PPP packet */
5769
5770                         if (sub_proto == 0xff) {
5771                                 /* this might be an address field, even it shouldn't be here */
5772                                 control_field = tvb_get_guint8 (tvb, offset + 1);
5773                                 if (control_field == 0x03)
5774                                         /* now we are pretty sure that address and control field are mistakenly inserted -> ignore it for PPP dissection */
5775                                         acfield_len = 2;
5776                         }
5777
5778                         next_tvb = tvb_new_subset (tvb, offset + acfield_len, -1, -1);
5779                         call_dissector (ppp_handle, next_tvb, pinfo, tree);
5780                 }
5781
5782                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
5783                         col_append_str_gtp(pinfo->cinfo, COL_PROTOCOL, "GTP");
5784         }
5785 }
5786
5787 static const true_false_string yes_no_tfs = {
5788         "yes" ,
5789         "no"
5790 };
5791
5792 void
5793 proto_register_gtp(void)
5794 {
5795         static hf_register_info hf_gtp[] = {
5796                 { &hf_gtp_apn, { "APN", "gtp.apn", FT_STRING, BASE_DEC, NULL, 0, "Access Point Name", HFILL }},
5797                 { &hf_gtp_cause, { "Cause ", "gtp.cause", FT_UINT8, BASE_DEC, VALS(cause_type), 0, "Cause of operation", HFILL }},
5798                 { &hf_gtp_chrg_char, { "Charging characteristics", "gtp.chrg_char", FT_UINT16, BASE_DEC, NULL, 0, "Charging characteristics", HFILL }},
5799                 { &hf_gtp_chrg_char_s, { "Spare", "gtp.chrg_char_s", FT_UINT16,         BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_S, "Spare", HFILL }},
5800                 { &hf_gtp_chrg_char_n, { "Normal charging", "gtp.chrg_char_n", FT_UINT16, BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_N, "Normal charging", HFILL }},
5801                 { &hf_gtp_chrg_char_p, { "Prepaid charging", "gtp.chrg_char_p", FT_UINT16, BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_P, "Prepaid charging", HFILL }},
5802                 { &hf_gtp_chrg_char_f, { "Flat rate charging", "gtp.chrg_char_f", FT_UINT16, BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_F, "Flat rate charging", HFILL }},
5803                 { &hf_gtp_chrg_char_h, { "Hot billing charging", "gtp.chrg_char_h", FT_UINT16, BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_H, "Hot billing charging", HFILL }},
5804                 { &hf_gtp_chrg_char_r, { "Reserved", "gtp.chrg_char_r", FT_UINT16, BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_R, "Reserved", HFILL }},
5805                 { &hf_gtp_chrg_id, { "Charging ID", "gtp.chrg_id", FT_UINT32, BASE_HEX, NULL, 0, "Charging ID", HFILL }},
5806                 { &hf_gtp_chrg_ipv4, { "CG address IPv4", "gtp.chrg_ipv4", FT_IPv4, BASE_DEC, NULL, 0, "Charging Gateway address IPv4", HFILL }},
5807                 { &hf_gtp_chrg_ipv6, { "CG address IPv6", "gtp.chrg_ipv6", FT_IPv6, BASE_HEX, NULL, 0, "Charging Gateway address IPv6", HFILL }},
5808                 { &hf_gtp_ext_flow_label, { "Flow Label Data I", "gtp.ext_flow_label", FT_UINT16, BASE_HEX, NULL, 0, "Flow label data", HFILL }},
5809                 { &hf_gtp_ext_id, { "Extension identifier", "gtp.ext_id", FT_UINT16, BASE_DEC, VALS(sminmpec_values), 0, "Extension Identifier", HFILL }},
5810                 { &hf_gtp_ext_val, { "Extension value", "gtp.ext_val", FT_BYTES, BASE_HEX, NULL, 0, "Extension Value", HFILL }},
5811                 { &hf_gtp_flags, { "Flags", "gtp.flags", FT_UINT8, BASE_HEX, NULL, 0, "Ver/PT/Spare...", HFILL }},
5812                 { &hf_gtp_flags_ver,
5813                         { "Version", "gtp.flags.version",
5814                         FT_UINT8, BASE_DEC, VALS(ver_types), GTP_VER_MASK,
5815                         "GTP Version", HFILL }
5816                 },
5817                 { &hf_gtp_flags_pt,
5818                         { "Protocol type",      "gtp.flags.payload",
5819                         FT_UINT8, BASE_DEC, VALS(pt_types), GTP_PT_MASK,
5820                         "Protocol Type", HFILL }
5821                 },
5822                 { &hf_gtp_flags_spare1,
5823                         { "Reserved", "gtp.flags.reserved",
5824                         FT_UINT8, BASE_DEC, NULL, GTP_SPARE1_MASK,
5825                         "Reserved (shall be sent as '111' )", HFILL }
5826                 },
5827                 { &hf_gtp_flags_snn, { "Is SNDCP N-PDU included?", "gtp.flags.snn", FT_BOOLEAN, 8, TFS(&yes_no_tfs), GTP_SNN_MASK, "Is SNDCP N-PDU LLC Number included? (1 = yes, 0 = no)", HFILL }},
5828                 { &hf_gtp_flags_spare2, { "Reserved", "gtp.flags.reserved", FT_UINT8, BASE_DEC, NULL, GTP_SPARE2_MASK, "Reserved (shall be sent as '1' )", HFILL }},
5829                 { &hf_gtp_flags_e, { "Is Next Extension Header present?", "gtp.flags.e", FT_BOOLEAN, 8, TFS(&yes_no_tfs), GTP_E_MASK, "Is Next Extension Header present? (1 = yes, 0 = no)", HFILL }},
5830                 { &hf_gtp_flags_s, { "Is Sequence Number present?", "gtp.flags.s", FT_BOOLEAN, 8, TFS(&yes_no_tfs), GTP_S_MASK, "Is Sequence Number present? (1 = yes, 0 = no)", HFILL }},
5831                 { &hf_gtp_flags_pn, { "Is N-PDU number present?", "gtp.flags.pn", FT_BOOLEAN, 8, TFS(&yes_no_tfs), GTP_PN_MASK, "Is N-PDU number present? (1 = yes, 0 = no)", HFILL }},
5832                 { &hf_gtp_flow_ii, { "Flow Label Data II ", "gtp.flow_ii", FT_UINT16, BASE_DEC, NULL, 0, "Downlink flow label data", HFILL }},
5833                 { &hf_gtp_flow_label, { "Flow label", "gtp.flow_label", FT_UINT16, BASE_HEX, NULL, 0, "Flow label", HFILL }},
5834                 { &hf_gtp_flow_sig, { "Flow label Signalling", "gtp.flow_sig", FT_UINT16, BASE_HEX, NULL, 0, "Flow label signalling", HFILL }},
5835                 { &hf_gtp_gsn_addr_len, { "GSN Address Length", "gtp.gsn_addr_len", FT_UINT8, BASE_DEC, NULL, GTP_EXT_GSN_ADDR_LEN_MASK, "GSN Address Length", HFILL }},
5836                 { &hf_gtp_gsn_addr_type, { "GSN Address Type", "gtp.gsn_addr_type", FT_UINT8, BASE_DEC, VALS(gsn_addr_type), GTP_EXT_GSN_ADDR_TYPE_MASK, "GSN Address Type", HFILL }},
5837                 { &hf_gtp_gsn_ipv4, { "GSN address IPv4", "gtp.gsn_ipv4", FT_IPv4, BASE_DEC, NULL, 0, "GSN address IPv4", HFILL }},
5838                 { &hf_gtp_gsn_ipv6, { "GSN address IPv6", "gtp.gsn_ipv6", FT_IPv6, BASE_DEC, NULL, 0, "GSN address IPv6", HFILL }},
5839                 { &hf_gtp_imsi, { "IMSI", "gtp.imsi", FT_STRING, BASE_DEC, NULL, 0, "International Mobile Subscriber Identity number", HFILL }},
5840                 { &hf_gtp_length, { "Length", "gtp.length", FT_UINT16, BASE_DEC, NULL, 0, "Length (i.e. number of octets after TID or TEID)", HFILL }},
5841                 { &hf_gtp_map_cause, { "MAP cause", "gtp.map_cause", FT_UINT8, BASE_DEC, VALS(gsm_map_GSMMAPLocalErrorcode_vals), 0, "MAP cause", HFILL }},
5842                 { &hf_gtp_message_type, { "Message Type", "gtp.message", FT_UINT8, BASE_HEX, VALS(message_type), 0x0, "GTP Message Type", HFILL }},
5843                 { &hf_gtp_ms_reason, { "MS not reachable reason", "gtp.ms_reason", FT_UINT8, BASE_DEC, VALS(ms_not_reachable_type), 0, "MS Not Reachable Reason", HFILL }},
5844                 { &hf_gtp_ms_valid, { "MS validated", "gtp.ms_valid", FT_BOOLEAN, BASE_NONE,NULL, 0, "MS validated", HFILL }},
5845                 { &hf_gtp_msisdn, { "MSISDN", "gtp.msisdn", FT_STRING, BASE_DEC, NULL, 0, "MS international PSTN/ISDN number", HFILL }},
5846                 { &hf_gtp_next, { "Next extension header type", "gtp.next", FT_UINT8, BASE_HEX, NULL, 0, "Next Extension Header Type", HFILL }},
5847                 { &hf_gtp_node_ipv4, { "Node address IPv4", "gtp.node_ipv4", FT_IPv4, BASE_DEC, NULL, 0, "Recommended node address IPv4", HFILL }},
5848                 { &hf_gtp_node_ipv6, { "Node address IPv6", "gtp.node_ipv6", FT_IPv6, BASE_HEX, NULL, 0, "Recommended node address IPv6", HFILL }},
5849                 { &hf_gtp_npdu_number, { "N-PDU Number", "gtp.npdu_number", FT_UINT8, BASE_HEX, NULL, 0, "N-PDU Number", HFILL }},
5850                 { &hf_gtp_nsapi, { "NSAPI", "gtp.nsapi", FT_UINT8, BASE_DEC, NULL, 0, "Network layer Service Access Point Identifier", HFILL }},
5851                 { &hf_gtp_qos_version, { "Version", "gtp.qos_version", FT_STRING, BASE_DEC, NULL, 0, "Version of the QoS Profile", HFILL }},
5852                 { &hf_gtp_qos_spare1, { "Spare", "gtp.qos_spare1", FT_UINT8, BASE_DEC, NULL, GTP_EXT_QOS_SPARE1_MASK, "Spare (shall be sent as '00' )", HFILL }},
5853                 { &hf_gtp_qos_delay, { "QoS delay", "gtp.qos_delay", FT_UINT8, BASE_DEC, VALS(qos_delay_type), GTP_EXT_QOS_DELAY_MASK, "Quality of Service Delay Class", HFILL }},
5854                 { &hf_gtp_qos_reliability, { "QoS reliability", "gtp.qos_reliabilty", FT_UINT8, BASE_DEC, VALS(qos_reliability_type), GTP_EXT_QOS_RELIABILITY_MASK, "Quality of Service Reliability Class", HFILL }},
5855                 { &hf_gtp_qos_peak, { "QoS peak", "gtp.qos_peak", FT_UINT8, BASE_DEC, VALS(qos_peak_type), GTP_EXT_QOS_PEAK_MASK, "Quality of Service Peak Throughput", HFILL }},
5856                 { &hf_gtp_qos_spare2, { "Spare", "gtp.qos_spare2",FT_UINT8, BASE_DEC, NULL, GTP_EXT_QOS_SPARE2_MASK, "Spare (shall be sent as 0)", HFILL }},
5857                 { &hf_gtp_qos_precedence, { "QoS precedence", "gtp.qos_precedence", FT_UINT8, BASE_DEC, VALS(qos_precedence_type), GTP_EXT_QOS_PRECEDENCE_MASK, "Quality of Service Precedence Class", HFILL }},
5858                 { &hf_gtp_qos_spare3, { "Spare", "gtp.qos_spare3", FT_UINT8, BASE_DEC, NULL, GTP_EXT_QOS_SPARE3_MASK, "Spare (shall be sent as '000' )", HFILL }},
5859                 { &hf_gtp_qos_mean, { "QoS mean", "gtp.qos_mean", FT_UINT8, BASE_DEC, VALS(qos_mean_type), GTP_EXT_QOS_MEAN_MASK, "Quality of Service Mean Throughput", HFILL }},
5860                 { &hf_gtp_qos_al_ret_priority, { "Allocation/Retention priority ","gtp.qos_al_ret_priority", FT_UINT8, BASE_DEC, NULL, 0, "Allocation/Retention Priority", HFILL }},
5861                 { &hf_gtp_qos_traf_class, { "Traffic class", "gtp.qos_traf_class", FT_UINT8, BASE_DEC, VALS(qos_traf_class), GTP_EXT_QOS_TRAF_CLASS_MASK, "Traffic Class", HFILL }},
5862                 { &hf_gtp_qos_del_order, { "Delivery order", "gtp.qos_del_order", FT_UINT8, BASE_DEC, VALS(qos_del_order), GTP_EXT_QOS_DEL_ORDER_MASK, "Delivery Order", HFILL }},
5863                 { &hf_gtp_qos_del_err_sdu, { "Delivery of erroneous SDU", "gtp.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 }},
5864                 { &hf_gtp_qos_max_sdu_size, { "Maximum SDU size", "gtp.qos_max_sdu_size", FT_UINT8, BASE_DEC, VALS(qos_max_sdu_size), 0, "Maximum SDU size", HFILL }},
5865                 { &hf_gtp_qos_max_ul, { "Maximum bit rate for uplink",  "gtp.qos_max_ul", FT_UINT8, BASE_DEC, VALS(qos_max_ul), 0, "Maximum bit rate for uplink", HFILL }},
5866                 { &hf_gtp_qos_max_dl, { "Maximum bit rate for downlink", "gtp.qos_max_dl", FT_UINT8, BASE_DEC, VALS(qos_max_dl), 0, "Maximum bit rate for downlink", HFILL }},
5867                 { &hf_gtp_qos_res_ber, { "Residual BER", "gtp.qos_res_ber", FT_UINT8, BASE_DEC, VALS(qos_res_ber), GTP_EXT_QOS_RES_BER_MASK, "Residual Bit Error Rate", HFILL }},
5868                 { &hf_gtp_qos_sdu_err_ratio, { "SDU Error ratio", "gtp.qos_sdu_err_ratio", FT_UINT8, BASE_DEC, VALS(qos_sdu_err_ratio), GTP_EXT_QOS_SDU_ERR_RATIO_MASK, "SDU Error Ratio", HFILL }},
5869                 { &hf_gtp_qos_trans_delay, { "Transfer delay",  "gtp.qos_trans_delay", FT_UINT8, BASE_DEC, VALS(qos_trans_delay), GTP_EXT_QOS_TRANS_DELAY_MASK, "Transfer Delay", HFILL }},
5870                 { &hf_gtp_qos_traf_handl_prio, { "Traffic handling priority", "gtp.qos_traf_handl_prio", FT_UINT8, BASE_DEC, VALS(qos_traf_handl_prio), GTP_EXT_QOS_TRAF_HANDL_PRIORITY_MASK, "Traffic Handling Priority", HFILL }},
5871                 { &hf_gtp_qos_guar_ul, { "Guaranteed bit rate for uplink", "gtp.qos_guar_ul", FT_UINT8, BASE_DEC, VALS(qos_guar_ul), 0, "Guaranteed bit rate for uplink", HFILL }},
5872                 { &hf_gtp_qos_guar_dl, { "Guaranteed bit rate for downlink", "gtp.qos_guar_dl", FT_UINT8, BASE_DEC, VALS(qos_guar_dl), 0, "Guaranteed bit rate for downlink", HFILL }},
5873                 { &hf_gtp_pkt_flow_id, { "Packet Flow ID", "gtp.pkt_flow_id", FT_UINT8, BASE_DEC, NULL, 0, "Packet Flow ID", HFILL }},
5874                 { &hf_gtp_ptmsi, { "P-TMSI", "gtp.ptmsi", FT_UINT32, BASE_HEX, NULL, 0, "Packet-Temporary Mobile Subscriber Identity", HFILL }},
5875                 { &hf_gtp_ptmsi_sig, { "P-TMSI Signature", "gtp.ptmsi_sig", FT_UINT24, BASE_HEX, NULL, 0, "P-TMSI Signature", HFILL }},
5876                 { &hf_gtp_rab_gtpu_dn, { "Downlink GTP-U seq number", "gtp.rab_gtp_dn", FT_UINT16, BASE_DEC, NULL, 0, "Downlink GTP-U sequence number", HFILL }},
5877                 { &hf_gtp_rab_gtpu_up, { "Uplink GTP-U seq number", "gtp.rab_gtp_up", FT_UINT16, BASE_DEC, NULL, 0, "Uplink GTP-U sequence number", HFILL }},
5878                 { &hf_gtp_rab_pdu_dn, { "Downlink next PDCP-PDU seq number", "gtp.rab_pdu_dn", FT_UINT16, BASE_DEC, NULL, 0, "Downlink next PDCP-PDU sequence number", HFILL }},
5879                 { &hf_gtp_rab_pdu_up, { "Uplink next PDCP-PDU seq number", "gtp.rab_pdu_up", FT_UINT16, BASE_DEC, NULL, 0, "Uplink next PDCP-PDU sequence number", HFILL }},
5880                 { &hf_gtp_rai_mcc, { "MCC", "gtp.mcc", FT_UINT16, BASE_DEC, NULL, 0, "Mobile Country Code", HFILL }},
5881                 { &hf_gtp_rai_mnc, { "MNC", "gtp.mnc", FT_UINT8, BASE_DEC, NULL, 0, "Mobile Network Code", HFILL }},
5882                 { &hf_gtp_rai_rac, { "RAC", "gtp.rac", FT_UINT8, BASE_DEC, NULL, 0, "Routing Area Code", HFILL }},
5883                 { &hf_gtp_rai_lac, { "LAC", "gtp.lac", FT_UINT16, BASE_DEC, NULL, 0, "Location Area Code", HFILL }},
5884                 { &hf_gtp_ranap_cause, { "RANAP cause", "gtp.ranap_cause", FT_UINT8, BASE_DEC, VALS(ranap_cause_type), 0, "RANAP cause", HFILL }},
5885                 { &hf_gtp_recovery, { "Recovery", "gtp.recovery", FT_UINT8, BASE_DEC, NULL, 0, "Restart counter", HFILL }},
5886                 { &hf_gtp_reorder, { "Reordering required","gtp.reorder", FT_BOOLEAN, BASE_NONE,NULL, 0, "Reordering required", HFILL }},
5887                 { &hf_gtp_rnc_ipv4, { "RNC address IPv4", "gtp.rnc_ipv4", FT_IPv4, BASE_DEC, NULL, 0, "Radio Network Controller address IPv4", HFILL }},
5888                 { &hf_gtp_rnc_ipv6, { "RNC address IPv6", "gtp.rnc_ipv6", FT_IPv6, BASE_HEX, NULL, 0, "Radio Network Controller address IPv6", HFILL }},
5889                 { &hf_gtp_rp, { "Radio Priority", "gtp.rp", FT_UINT8, BASE_DEC, NULL, GTPv1_EXT_RP_MASK, "Radio Priority for uplink tx", HFILL }},
5890                 { &hf_gtp_rp_nsapi, { "NSAPI in Radio Priority", "gtp.rp_nsapi", FT_UINT8, BASE_DEC, NULL, GTPv1_EXT_RP_NSAPI_MASK, "Network layer Service Access Point Identifier in Radio Priority", HFILL }},
5891                 { &hf_gtp_rp_sms, { "Radio Priority SMS", "gtp.rp_sms", FT_UINT8, BASE_DEC, NULL, 0, "Radio Priority for MO SMS", HFILL }},
5892                 { &hf_gtp_rp_spare, { "Reserved", "gtp.rp_spare", FT_UINT8, BASE_DEC, NULL, GTPv1_EXT_RP_SPARE_MASK, "Spare bit", HFILL }},
5893                 { &hf_gtp_sel_mode, { "Selection mode", "gtp.sel_mode", FT_UINT8, BASE_DEC, VALS(sel_mode_type), 0, "Selection Mode", HFILL }},
5894                 { &hf_gtp_seq_number, { "Sequence number", "gtp.seq_number", FT_UINT16, BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
5895                 { &hf_gtp_sndcp_number, { "SNDCP N-PDU LLC Number", "gtp.sndcp_number", FT_UINT8, BASE_HEX, NULL, 0, "SNDCP N-PDU LLC Number", HFILL }},
5896                 { &hf_gtp_tear_ind, { "Teardown Indicator", "gtp.tear_ind", FT_BOOLEAN, BASE_NONE,NULL, 0, "Teardown Indicator", HFILL }},
5897                 { &hf_gtp_teid, { "TEID", "gtp.teid", FT_UINT32, BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier", HFILL }},
5898                 { &hf_gtp_teid_cp, { "TEID Control Plane", "gtp.teid_cp", FT_UINT32, BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Control Plane", HFILL }},
5899                 { &hf_gtp_teid_data, { "TEID Data I", "gtp.teid_data", FT_UINT32, BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data I", HFILL }},
5900                 { &hf_gtp_teid_ii, { "TEID Data II", "gtp.teid_ii", FT_UINT32, BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data II", HFILL }},
5901                 { &hf_gtp_tft_code, { "TFT operation code", "gtp.tft_code", FT_UINT8, BASE_DEC, VALS (tft_code_type), GTPv1_TFT_CODE_MASK, "TFT operation code", HFILL }},
5902                 { &hf_gtp_tft_spare, { "TFT spare bit", "gtp.tft_spare", FT_UINT8, BASE_DEC, NULL, GTPv1_TFT_SPARE_MASK, "TFT spare bit", HFILL }},
5903                 { &hf_gtp_tft_number, { "Number of packet filters", "gtp.tft_number", FT_UINT8, BASE_DEC, NULL, GTPv1_TFT_NUMBER_MASK, "Number of packet filters", HFILL }},
5904                 { &hf_gtp_tft_eval, { "Evaluation precedence", "gtp.tft_eval", FT_UINT8, BASE_DEC, NULL, 0, "Evaluation precedence", HFILL }},
5905                 { &hf_gtp_tid, { "TID", "gtp.tid", FT_STRING, BASE_DEC, NULL, 0, "Tunnel Identifier", HFILL }},
5906                 { &hf_gtp_tlli, { "TLLI", "gtp.tlli", FT_UINT32, BASE_HEX, NULL, 0, "Temporary Logical Link Identity", HFILL }},
5907                 { &hf_gtp_tr_comm, { "Packet transfer command", "gtp.tr_comm", FT_UINT8, BASE_DEC, VALS (tr_comm_type), 0, "Packat transfer command", HFILL }},
5908                 { &hf_gtp_trace_ref, { "Trace reference", "gtp.trace_ref", FT_UINT16, BASE_HEX, NULL, 0, "Trace reference", HFILL }},
5909                 { &hf_gtp_trace_type, { "Trace type", "gtp.trace_type", FT_UINT16, BASE_HEX, NULL, 0, "Trace type", HFILL }},
5910                 { &hf_gtp_unknown, { "Unknown data (length)",   "gtp.unknown", FT_UINT16, BASE_DEC, NULL, 0, "Unknown data", HFILL }},
5911                 { &hf_gtp_user_addr_pdp_org, { "PDP type organization", "gtp.user_addr_pdp_org", FT_UINT8, BASE_DEC, VALS(pdp_org_type), 0, "PDP type organization", HFILL }},
5912                 { &hf_gtp_user_addr_pdp_type, { "PDP type number", "gtp.user_addr_pdp_type", FT_UINT8, BASE_HEX, VALS (pdp_type), 0, "PDP type", HFILL }},
5913                 { &hf_gtp_user_ipv4, { "End user address IPv4", "gtp.user_ipv4", FT_IPv4, BASE_DEC, NULL, 0, "End user address IPv4", HFILL }},
5914                 { &hf_gtp_user_ipv6, { "End user address IPv6", "gtp.user_ipv6", FT_IPv6, BASE_HEX, NULL, 0, "End user address IPv6", HFILL }},
5915                 { &hf_gtp_security_mode,
5916                         { "Security Mode", "gtp.security_mode",
5917                         FT_UINT8, BASE_DEC, VALS(mm_sec_modep), 0xc0,
5918                         "Security Mode", HFILL }
5919                 },
5920                 { &hf_gtp_no_of_vectors,
5921                         { "No of Vectors", "gtp.no_of_vectors",
5922                         FT_UINT8, BASE_DEC, NULL, 0x38,
5923                         "No of Vectors", HFILL }
5924                 },
5925                 { &hf_gtp_cipher_algorithm,
5926                         { "Cipher Algorithm", "gtp.no_of_vectors",
5927                         FT_UINT8, BASE_DEC, VALS(gtp_cipher_algorithm), 0x07,
5928                         "Cipher Algorithm", HFILL }
5929                 },
5930                 { &hf_gtp_cksn_ksi,
5931                         { "Ciphering Key Sequence Number (CKSN)/Key Set Identifier (KSI)", "gtp.cksn_ksi",
5932                         FT_UINT8, BASE_DEC, NULL, 0x07,
5933                         "CKSN/KSI", HFILL }
5934                 },
5935                 { &hf_gtp_cksn,
5936                         { "Ciphering Key Sequence Number (CKSN)", "gtp.cksn_ksi",
5937                         FT_UINT8, BASE_DEC, NULL, 0x07,
5938                         "CKSN", HFILL }
5939                 },
5940                 { &hf_gtp_ksi,
5941                         { "Key Set Identifier (KSI)", "gtp.cksn_ksi",
5942                         FT_UINT8, BASE_DEC, NULL, 0x07,
5943                         "KSI", HFILL }
5944                 },
5945                 { &hf_gtp_ext_length,
5946                         { "Length", "gtp.ext_length",
5947                         FT_UINT16, BASE_DEC, NULL, 0x0,
5948                         "IE Length", HFILL }
5949                 },
5950                 { &hf_gtp_ext_apn_res,
5951                         { "Restriction Type", "gtp.ext_apn_res",
5952                         FT_UINT8, BASE_DEC, NULL, 0x0,
5953                         "Restriction Type", HFILL }
5954                 },
5955                 { &hf_gtp_ext_rat_type,
5956                         { "RAT Type", "gtp.ext_rat_type",
5957                         FT_UINT8, BASE_DEC, VALS(gtp_ext_rat_type_vals), 0x0,
5958                         "RAT Type", HFILL }
5959                 },
5960                 { &hf_gtp_ext_geo_loc_type,
5961                         { "Geographic Location Type", "gtp.ext_geo_loc_type",
5962                         FT_UINT8, BASE_DEC, NULL, 0x0,
5963                         "Geographic Location Type", HFILL }
5964                 },
5965                 { &hf_gtp_ext_sac,
5966                         { "SAC", "gtp.ext_sac",
5967                         FT_UINT16, BASE_HEX, NULL, 0x0,
5968                         "SAC", HFILL }
5969                 },
5970                 { &hf_gtp_ext_imeisv,
5971                         { "IMEI(SV)", "gtp.ext_imeisv",
5972                         FT_BYTES, BASE_NONE, NULL, 0x0,
5973                         "IMEI(SV)", HFILL }
5974                 },
5975                 { &hf_gtp_targetid,
5976                         { "TargetID", "gtp.targetid",
5977                         FT_UINT32, BASE_DEC, VALS(ranap_TargetID_vals), 0,
5978                         "TargetID", HFILL }},
5979                 { &hf_gtp_bssgp_cause,
5980                         { "BSSGP Cause", "gtp.bssgp_cause",
5981                         FT_UINT8, BASE_DEC, VALS(tab_cause), 0,
5982                         "BSSGP Cause", HFILL }},
5983
5984         };
5985
5986         static gint *ett_gtp_array[] = {
5987                 &ett_gtp,
5988                 &ett_gtp_flags,
5989                 &ett_gtp_ext,
5990                 &ett_gtp_rai,
5991                 &ett_gtp_qos,
5992                 &ett_gtp_auth_tri,
5993                 &ett_gtp_flow_ii,
5994                 &ett_gtp_rab_cntxt,
5995                 &ett_gtp_rp,
5996                 &ett_gtp_pkt_flow_id,
5997                 &ett_gtp_chrg_char,
5998                 &ett_gtp_user,
5999                 &ett_gtp_mm,
6000                 &ett_gtp_trip,
6001                 &ett_gtp_quint,
6002                 &ett_gtp_pdp,
6003                 &ett_gtp_apn,
6004                 &ett_gtp_proto,
6005                 &ett_gtp_gsn_addr,
6006                 &ett_gtp_tft,
6007                 &ett_gtp_tft_pf,
6008                 &ett_gtp_tft_flags,
6009                 &ett_gtp_rab_setup,
6010                 &ett_gtp_hdr_list,
6011                 &ett_gtp_chrg_addr,
6012                 &ett_gtp_node_addr,
6013                 &ett_gtp_rel_pack,
6014                 &ett_gtp_can_pack,
6015                 &ett_gtp_data_resp,
6016                 &ett_gtp_priv_ext,
6017                 &ett_gtp_net_cap,
6018                 &ett_gtp_ext_tree_apn_res,
6019                 &ett_gtp_ext_rat_type,
6020                 &ett_gtp_ext_imeisv,
6021                 &ett_gtp_ext_ran_tr_cont,
6022                 &ett_gtp_ext_pdp_cont_prio,
6023                 &ett_gtp_ext_ssgn_no,
6024                 &ett_gtp_ext_rab_setup_inf,
6025                 &ett_gtp_ext_common_flgs,
6026                 &ett_gtp_ext_usr_loc_inf,
6027                 &ett_gtp_ext_ms_time_zone,
6028                 &ett_gtp_ext_camel_chg_inf_con,
6029                 &ett_GTP_EXT_MBMS_UE_CTX,
6030                 &ett_gtp_ext_tmgi,
6031                 &ett_gtp_ext_rim_ra,
6032                 &ett_gtp_ext_mbms_prot_conf_opt,
6033                 &ett_gtp_ext_mbms_sa,
6034                 &ett_gtp_ext_bms_ses_dur,
6035                 &ett_gtp_ext_src_rnc_pdp_ctx_inf,
6036                 &ett_gtp_ext_add_trs_inf,
6037                 &ett_gtp_ext_hop_count,
6038                 &ett_gtp_ext_sel_plmn_id,
6039                 &ett_gtp_ext_mbms_ses_id,
6040                 &ett_gtp_ext_mbms_2g_3g_ind,
6041                 &ett_gtp_ext_enh_nsapi,
6042                 &ett_gtp_ext_ad_mbms_trs_inf,
6043                 &ett_gtp_ext_mbms_ses_id_rep_no,
6044                 &ett_gtp_ext_mbms_time_to_data_tr,
6045                 &ett_gtp_ext_ps_ho_req_ctx,
6046                 &ett_gtp_ext_bss_cont,
6047                 &ett_gtp_ext_cell_id,
6048                 &ett_gtp_ext_pdu_no,
6049                 &ett_gtp_ext_bssgp_cause,
6050                 &ett_gtp_ext_ra_prio_lcs,
6051                 &ett_gtp_target_id,
6052                 &ett_gtp_utran_cont,
6053         };
6054
6055         module_t        *gtp_module;
6056
6057         proto_gtp = proto_register_protocol ("GPRS Tunneling Protocol", "GTP", "gtp");
6058         proto_register_field_array (proto_gtp, hf_gtp, array_length (hf_gtp));
6059         proto_register_subtree_array (ett_gtp_array, array_length (ett_gtp_array));
6060
6061         gtp_module = prefs_register_protocol(proto_gtp, proto_reg_handoff_gtp);
6062
6063         prefs_register_uint_preference(gtp_module, "v0_port", "GTPv0 port", "GTPv0 port (default 3386)", 10, &g_gtpv0_port);
6064         prefs_register_uint_preference(gtp_module, "v1c_port", "GTPv1 control plane (GTP-C) port", "GTPv1 control plane port (default 2123)", 10, &g_gtpv1c_port);
6065         prefs_register_uint_preference(gtp_module, "v1u_port", "GTPv1 user plane (GTP-U) port", "GTPv1 user plane port (default 2152)", 10, &g_gtpv1u_port);
6066         prefs_register_bool_preference(gtp_module, "dissect_tpdu", "Dissect T-PDU", "Dissect T-PDU", &gtp_tpdu);
6067
6068         prefs_register_obsolete_preference (gtp_module, "v0_dissect_cdr_as");
6069         prefs_register_obsolete_preference (gtp_module, "v0_check_etsi");
6070         prefs_register_obsolete_preference (gtp_module, "v1_check_etsi");
6071         prefs_register_bool_preference (gtp_module, "check_etsi", "Compare GTP order with ETSI", "GTP ETSI order", &gtp_etsi_order);
6072         prefs_register_obsolete_preference(gtp_module, "ppp_reorder");
6073
6074         /* This preference can be used to disable the dissection of GTP over TCP. Most of the Wireless operators uses GTP over UDP.
6075                  * The preference is set to TRUE by default forbackward compatibility
6076                  */
6077         prefs_register_bool_preference(gtp_module, "dissect_gtp_over_tcp", "Dissect GTP over TCP", "Dissect GTP over TCP", &gtp_over_tcp);
6078
6079         register_dissector("gtp", dissect_gtp, proto_gtp);
6080 }
6081
6082 void
6083 proto_reg_handoff_gtp(void)
6084 {
6085         static int Initialized = FALSE;
6086         static dissector_handle_t gtp_handle;
6087
6088
6089         if (!Initialized) {
6090                 gtp_handle = find_dissector("gtp");
6091                 ppp_subdissector_table = find_dissector_table("ppp.protocol");
6092
6093                 radius_register_avp_dissector(VENDOR_THE3GPP,5,dissect_radius_qos_umts);
6094
6095                 Initialized = TRUE;
6096         } else {
6097                 dissector_delete ("udp.port", gtpv0_port, gtp_handle);
6098                 dissector_delete ("udp.port", gtpv1c_port, gtp_handle);
6099                 dissector_delete ("udp.port", gtpv1u_port, gtp_handle);
6100
6101                 if ( !gtp_over_tcp ) {
6102                         dissector_delete ("tcp.port", gtpv0_port, gtp_handle);
6103                         dissector_delete ("tcp.port", gtpv1c_port, gtp_handle);
6104                         dissector_delete ("tcp.port", gtpv1u_port, gtp_handle);
6105                 }
6106
6107         }
6108
6109         gtpv0_port = g_gtpv0_port;
6110         gtpv1c_port = g_gtpv1c_port;
6111         gtpv1u_port = g_gtpv1u_port;
6112
6113         dissector_add ("udp.port", g_gtpv0_port, gtp_handle);
6114         dissector_add ("udp.port", g_gtpv1c_port, gtp_handle);
6115         dissector_add ("udp.port", g_gtpv1u_port, gtp_handle);
6116
6117
6118         if ( gtp_over_tcp ) {
6119                 dissector_add ("tcp.port", g_gtpv0_port, gtp_handle);
6120                 dissector_add ("tcp.port", g_gtpv1c_port, gtp_handle);
6121                 dissector_add ("tcp.port", g_gtpv1u_port, gtp_handle);
6122         }
6123
6124         ip_handle = find_dissector("ip");
6125         ipv6_handle = find_dissector("ipv6");
6126         ppp_handle = find_dissector("ppp");
6127         data_handle = find_dissector("data");
6128         gtpcdr_handle = find_dissector("gtpcdr");
6129         bssap_pdu_type_table = find_dissector_table("bssap.pdu_type");
6130
6131 }