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