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