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