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