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