From Flavio Poletti: handle the hyphen in QoS inside RADIUS client
[obnox/wireshark/wip.git] / packet-gtp.c
1 /* packet-gtp.c
2  *
3  * Routines for GTP dissection
4  * Copyright 2001, Michal Melerowicz <michal.melerowicz@nokia.com>
5  *                 Nicolas Balkota <balkota@mac.com>
6  *
7  * $Id: packet-gtp.c,v 1.50 2003/01/02 20:33:45 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include <glib.h>
37
38 #include <epan/packet.h>
39 #include "packet-gtp.h"
40 #include "packet-ipv6.h"
41 #include "packet-ppp.h"
42 #include "prefs.h"
43
44 /*
45  * All data related to GTP v0 (GPRS) uses "gtpv0" or "GTPv0",
46  * all data related to GTP v1 (UMTS) uses "gtpv1" or "GTPv1",
47  * if there is any gtp alone statement it means that this data is common
48  * for both: GPRS and UMTS
49  */
50
51 #define GTPv0_PORT 3386
52 #define GTPv1C_PORT 2123                        /* 3G Control PDU */
53 #define GTPv1U_PORT 2152                        /* 3G T-PDU */
54
55 #define GTPv0_HDR_LENGTH 20
56 #define GTPv1_HDR_LENGTH 12
57 #define GTP_PRIME_HDR_LENGTH 6
58
59 /* for function checking compliance with ETSI  */
60 #define GTP_MANDATORY   1
61 #define GTP_OPTIONAL    2
62 #define GTP_CONDITIONAL 4
63
64 static int g_gtpv0_port                 = GTPv0_PORT;
65 static int g_gtpv1c_port                = GTPv1C_PORT;
66 static int g_gtpv1u_port                = GTPv1U_PORT;
67
68 void proto_reg_handoff_gtp(void);
69
70 static int proto_gtp                    = -1;
71 static int proto_gtpv0                  = -1;
72 static int proto_gtpv1                  = -1;
73
74 static int hf_gtpv0_flags                       = -1;
75 static int hf_gtpv0_flags_ver           = -1;
76 static int hf_gtpv0_flags_pt            = -1;
77 static int hf_gtpv0_flags_spare         = -1;
78 #ifdef GTP_UNUSED_HANDLES
79 static int hf_gtpv0_flags_e             = -1;
80 static int hf_gtpv0_flags_s             = -1;
81 static int hf_gtpv0_flags_pn            = -1;
82 #endif
83 static int hf_gtpv0_flags_snn           = -1;
84 static int hf_gtpv0_message_type                = -1;
85 static int hf_gtpv0_length              = -1;
86 static int hf_gtpv0_seq_number          = -1;
87 static int hf_gtpv0_flow_label          = -1;
88 static int hf_gtpv0_sndcp_number                = -1;
89 #ifdef GTP_UNUSED_HANDLES
90 static int hf_gtpv0_npdu_number         = -1;
91 #endif
92 static int hf_gtpv0_tid                 = -1;
93 #ifdef GTP_UNUSED_HANDLES
94 static int hf_gtpv0_teid                        = -1;
95 static int hf_gtpv0_next                        = -1;
96 #endif
97 static int hf_gtpv0_cause                       = -1;
98 static int hf_gtpv0_imsi                        = -1;
99 static int hf_gtpv0_rai_mcc             = -1;
100 static int hf_gtpv0_rai_mnc             = -1;
101 static int hf_gtpv0_rai_rac             = -1;
102 static int hf_gtpv0_rai_lac             = -1;
103 static int hf_gtpv0_tlli                        = -1;
104 static int hf_gtpv0_ptmsi                       = -1;
105 static int hf_gtpv0_qos_spare1          = -1;
106 static int hf_gtpv0_qos_delay           = -1;
107 static int hf_gtpv0_qos_mean            = -1;
108 static int hf_gtpv0_qos_peak            = -1;
109 static int hf_gtpv0_qos_spare2          = -1;
110 static int hf_gtpv0_qos_precedence      = -1;
111 static int hf_gtpv0_qos_spare3          = -1;
112 static int hf_gtpv0_qos_reliability     = -1;
113 static int hf_gtpv0_reorder             = -1;
114 static int hf_gtpv0_map_cause           = -1;
115 static int hf_gtpv0_ptmsi_sig           = -1;
116 static int hf_gtpv0_ms_valid            = -1;
117 static int hf_gtpv0_recovery            = -1;
118 static int hf_gtpv0_sel_mode            = -1;
119 static int hf_gtpv0_ext_flow_label      = -1;
120 #ifdef GTP_UNUSED_HANDLES
121 static int hf_gtpv0_teid_data           = -1;   /* 3G */
122 #endif
123 static int hf_gtpv0_flow_sig            = -1;
124 #ifdef GTP_UNUSED_HANDLES
125 static int hf_gtpv0_teid_cp             = -1;   /* 3G */
126 #endif
127 static int hf_gtpv0_nsapi                       = -1;
128 static int hf_gtpv0_flow_ii             = -1;
129 #ifdef GTP_UNUSED_HANDLES
130 static int hf_gtpv0_teid_ii             = -1;   /* 3G */
131 #endif
132 static int hf_gtpv0_ms_reason           = -1;
133 #ifdef GTP_UNUSED_HANDLES
134 static int hf_gtpv0_tear_ind            = -1;   /* 3G */
135 static int hf_gtpv0_ranap_cause         = -1;   /* 3G */
136 static int hf_gtpv0_rab_gtpu_dn         = -1;   /* 3G */
137 static int hf_gtpv0_rab_gtpu_up         = -1;   /* 3G */
138 static int hf_gtpv0_rab_pdu_dn          = -1;   /* 3G */
139 static int hf_gtpv0_rab_pdu_up          = -1;   /* 3G */
140 static int hf_gtpv0_rp_sms              = -1;   /* 3G */
141 static int hf_gtpv0_rp_spare            = -1;   /* 3G */
142 static int hf_gtpv0_rp_nsapi            = -1;   /* 3G */
143 static int hf_gtpv0_rp                  = -1;   /* 3G */
144 static int hf_gtpv0_pkt_flow_id         = -1;   /* 3G */
145 static int hf_gtpv0_chrg_char_s         = -1;   /* 3G */
146 static int hf_gtpv0_chrg_char_n         = -1;   /* 3G */
147 static int hf_gtpv0_chrg_char_p         = -1;   /* 3G */
148 static int hf_gtpv0_chrg_char_f         = -1;   /* 3G */
149 static int hf_gtpv0_chrg_char_h         = -1;   /* 3G */
150 static int hf_gtpv0_chrg_char_r         = -1;   /* 3G */
151 static int hf_gtpv0_trace_ref           = -1;   /* 3G */
152 static int hf_gtpv0_trace_type          = -1;   /* 3G */
153 #endif
154 static int hf_gtpv0_tr_comm             = -1;   /* charging */
155 static int hf_gtpv0_chrg_id             = -1;
156 static int hf_gtpv0_user_ipv4           = -1;
157 static int hf_gtpv0_user_ipv6           = -1;
158 static int hf_gtpv0_user_addr_pdp_org   = -1;
159 static int hf_gtpv0_user_addr_pdp_type  = -1;
160 static int hf_gtpv0_apn                 = -1;
161 static int hf_gtpv0_gsn_ipv4            = -1;
162 static int hf_gtpv0_gsn_ipv6            = -1;
163 static int hf_gtpv0_gsn_addr_type               = -1;
164 static int hf_gtpv0_gsn_addr_len                = -1;
165 static int hf_gtpv0_msisdn              = -1;
166 #ifdef GTP_UNUSED_HANDLES
167 static int hf_gtpv0_qos_al_ret_priority = -1;
168 static int hf_gtpv0_qos_traf_class      = -1;
169 static int hf_gtpv0_qos_del_order               = -1;
170 static int hf_gtpv0_qos_del_err_sdu     = -1;
171 static int hf_gtpv0_qos_max_sdu_size    = -1;
172 static int hf_gtpv0_qos_max_ul          = -1;
173 static int hf_gtpv0_qos_max_dl          = -1;
174 static int hf_gtpv0_qos_res_ber         = -1;
175 static int hf_gtpv0_qos_sdu_err_ratio   = -1;
176 static int hf_gtpv0_qos_trans_delay     = -1;
177 static int hf_gtpv0_qos_traf_handl_prio = -1;
178 static int hf_gtpv0_qos_guar_ul         = -1;
179 static int hf_gtpv0_qos_guar_dl         = -1;
180 static int hf_gtpv0_rnc_ipv4            = -1;
181 static int hf_gtpv0_rnc_ipv6            = -1;
182 #endif
183 static int hf_gtpv0_chrg_ipv4           = -1;
184 static int hf_gtpv0_chrg_ipv6           = -1;
185 static int hf_gtpv0_node_ipv4           = -1;
186 static int hf_gtpv0_node_ipv6           = -1;
187 static int hf_gtpv0_ext_id              = -1;
188 static int hf_gtpv0_ext_val             = -1;
189 static int hf_gtpv0_unknown             = -1;
190
191 static int hf_gtpv1_flags                       = -1;
192 static int hf_gtpv1_flags_ver           = -1;
193 static int hf_gtpv1_flags_pt            = -1;
194 static int hf_gtpv1_flags_spare         = -1;
195 static int hf_gtpv1_flags_e             = -1;
196 static int hf_gtpv1_flags_s             = -1;
197 static int hf_gtpv1_flags_pn            = -1;
198 #ifdef GTP_UNUSED_HANDLES
199 static int hf_gtpv1_flags_snn           = -1;
200 #endif
201 static int hf_gtpv1_message_type                = -1;
202 static int hf_gtpv1_length              = -1;
203 static int hf_gtpv1_seq_number          = -1;
204 #ifdef GTP_UNUSED_HANDLES
205 static int hf_gtpv1_flow_label          = -1;
206 static int hf_gtpv1_sndcp_number                = -1;
207 #endif
208 static int hf_gtpv1_npdu_number         = -1;
209 #ifdef GTP_UNUSED_HANDLES
210 static int hf_gtpv1_tid                 = -1;
211 #endif
212 static int hf_gtpv1_teid                        = -1;
213 static int hf_gtpv1_next                        = -1;
214 static int hf_gtpv1_cause                       = -1;
215 static int hf_gtpv1_imsi                        = -1;
216 static int hf_gtpv1_rai_mcc             = -1;
217 static int hf_gtpv1_rai_mnc             = -1;
218 static int hf_gtpv1_rai_rac             = -1;
219 static int hf_gtpv1_rai_lac             = -1;
220 static int hf_gtpv1_tlli                        = -1;
221 static int hf_gtpv1_ptmsi                       = -1;
222 static int hf_gtpv1_qos_spare1          = -1;
223 static int hf_gtpv1_qos_delay           = -1;
224 static int hf_gtpv1_qos_mean            = -1;
225 static int hf_gtpv1_qos_peak            = -1;
226 static int hf_gtpv1_qos_spare2          = -1;
227 static int hf_gtpv1_qos_precedence      = -1;
228 static int hf_gtpv1_qos_spare3          = -1;
229 static int hf_gtpv1_qos_reliability     = -1;
230 static int hf_gtpv1_reorder             = -1;
231 static int hf_gtpv1_map_cause           = -1;
232 static int hf_gtpv1_ptmsi_sig           = -1;
233 static int hf_gtpv1_ms_valid            = -1;
234 static int hf_gtpv1_recovery            = -1;
235 static int hf_gtpv1_sel_mode            = -1;
236 #ifdef GTP_UNUSED_HANDLES
237 static int hf_gtpv1_ext_flow_label      = -1;
238 #endif
239 static int hf_gtpv1_teid_data           = -1;   /* 3G */
240 #ifdef GTP_UNUSED_HANDLES
241 static int hf_gtpv1_flow_sig            = -1;
242 #endif
243 static int hf_gtpv1_teid_cp             = -1;   /* 3G */
244 static int hf_gtpv1_nsapi                       = -1;
245 #ifdef GTP_UNUSED_HANDLES
246 static int hf_gtpv1_flow_ii             = -1;
247 #endif
248 static int hf_gtpv1_teid_ii             = -1;   /* 3G */
249 static int hf_gtpv1_ms_reason           = -1;
250 static int hf_gtpv1_tear_ind            = -1;   /* 3G */
251 static int hf_gtpv1_ranap_cause         = -1;   /* 3G */
252 static int hf_gtpv1_rab_gtpu_dn         = -1;   /* 3G */
253 static int hf_gtpv1_rab_gtpu_up         = -1;   /* 3G */
254 static int hf_gtpv1_rab_pdu_dn          = -1;   /* 3G */
255 static int hf_gtpv1_rab_pdu_up          = -1;   /* 3G */
256 static int hf_gtpv1_rp_sms              = -1;   /* 3G */
257 static int hf_gtpv1_rp_spare            = -1;   /* 3G */
258 static int hf_gtpv1_rp_nsapi            = -1;   /* 3G */
259 static int hf_gtpv1_rp                  = -1;   /* 3G */
260 static int hf_gtpv1_pkt_flow_id         = -1;   /* 3G */
261 static int hf_gtpv1_chrg_char_s         = -1;   /* 3G */
262 static int hf_gtpv1_chrg_char_n         = -1;   /* 3G */
263 static int hf_gtpv1_chrg_char_p         = -1;   /* 3G */
264 static int hf_gtpv1_chrg_char_f         = -1;   /* 3G */
265 static int hf_gtpv1_chrg_char_h         = -1;   /* 3G */
266 static int hf_gtpv1_chrg_char_r         = -1;   /* 3G */
267 static int hf_gtpv1_trace_ref           = -1;   /* 3G */
268 static int hf_gtpv1_trace_type          = -1;   /* 3G */
269 static int hf_gtpv1_tr_comm             = -1;   /* charging */
270 static int hf_gtpv1_chrg_id             = -1;
271 static int hf_gtpv1_user_ipv4           = -1;
272 static int hf_gtpv1_user_ipv6           = -1;
273 static int hf_gtpv1_user_addr_pdp_org   = -1;
274 static int hf_gtpv1_user_addr_pdp_type  = -1;
275 static int hf_gtpv1_apn                 = -1;
276 static int hf_gtpv1_gsn_ipv4            = -1;
277 static int hf_gtpv1_gsn_ipv6            = -1;
278 static int hf_gtpv1_gsn_addr_type               = -1;
279 static int hf_gtpv1_gsn_addr_len                = -1;
280 static int hf_gtpv1_msisdn              = -1;
281 static int hf_gtpv1_qos_al_ret_priority = -1;
282 static int hf_gtpv1_qos_traf_class      = -1;
283 static int hf_gtpv1_qos_del_order               = -1;
284 static int hf_gtpv1_qos_del_err_sdu     = -1;
285 static int hf_gtpv1_qos_max_sdu_size    = -1;
286 static int hf_gtpv1_qos_max_ul          = -1;
287 static int hf_gtpv1_qos_max_dl          = -1;
288 static int hf_gtpv1_qos_res_ber         = -1;
289 static int hf_gtpv1_qos_sdu_err_ratio   = -1;
290 static int hf_gtpv1_qos_trans_delay     = -1;
291 static int hf_gtpv1_qos_traf_handl_prio = -1;
292 static int hf_gtpv1_qos_guar_ul         = -1;
293 static int hf_gtpv1_qos_guar_dl         = -1;
294 static int hf_gtpv1_tft_code            = -1;
295 static int hf_gtpv1_tft_spare           = -1;
296 static int hf_gtpv1_tft_number          = -1;
297 static int hf_gtpv1_tft_eval            = -1;
298 static int hf_gtpv1_rnc_ipv4            = -1;
299 static int hf_gtpv1_rnc_ipv6            = -1;
300 static int hf_gtpv1_chrg_ipv4           = -1;
301 static int hf_gtpv1_chrg_ipv6           = -1;
302 static int hf_gtpv1_node_ipv4           = -1;
303 static int hf_gtpv1_node_ipv6           = -1;
304 static int hf_gtpv1_ext_id              = -1;
305 static int hf_gtpv1_ext_val             = -1;
306 static int hf_gtpv1_unknown             = -1;
307
308 /* Initialize the subtree pointers */
309 static gint ett_gtp                     = -1;
310 static gint ett_gtp_flags               = -1;
311 static gint ett_gtp_ext                 = -1;
312 static gint ett_gtp_rai                 = -1;
313 static gint ett_gtp_qos                 = -1;
314 static gint ett_gtp_auth_tri            = -1;
315 static gint ett_gtp_flow_ii             = -1;
316 static gint ett_gtp_rab_cntxt           = -1;
317 static gint ett_gtp_rp                  = -1;
318 static gint ett_gtp_pkt_flow_id         = -1;
319 static gint ett_gtp_chrg_char           = -1;
320 static gint ett_gtp_user                = -1;
321 static gint ett_gtp_mm                  = -1;
322 static gint ett_gtp_trip                = -1;
323 static gint ett_gtp_quint               = -1;
324 static gint ett_gtp_pdp                 = -1;
325 static gint ett_gtp_apn                 = -1;
326 static gint ett_gtp_proto               = -1;
327 static gint ett_gtp_gsn_addr            = -1;
328 static gint ett_gtp_tft                 = -1;
329 static gint ett_gtp_tft_pf              = -1;
330 static gint ett_gtp_tft_flags           = -1;
331 static gint ett_gtp_rab_setup           = -1;
332 static gint ett_gtp_hdr_list            = -1;
333 static gint ett_gtp_chrg_addr           = -1;
334 static gint ett_gtp_node_addr           = -1;
335 static gint ett_gtp_rel_pack            = -1;
336 static gint ett_gtp_can_pack            = -1;
337 static gint ett_gtp_data_resp           = -1;
338 static gint ett_gtp_priv_ext            = -1;
339
340 /* Definition of user preferences panel fields */
341 #define DONT_DISSECT_CDRS       2
342
343 static gboolean gtp_tpdu                = TRUE;
344 static gint     gtpv0_cdr_as            = DONT_DISSECT_CDRS;                    /* 2 = do not dissect */
345 static gboolean gtpv0_etsi_order        = FALSE;
346 static gboolean gtpv1_etsi_order        = FALSE;
347 static int      gtpv0_port              = 0;
348 static int      gtpv1c_port             = 0;
349 static int      gtpv1u_port             = 0;
350
351 /* Definition of flags masks */
352 #define GTP_VER_MASK 0xE0
353
354 static const value_string ver_types[] = {
355         { 0, "GTP release 97/98 version" },
356         { 1, "GTP release 99 version" },
357         { 2, "None" },
358         { 3, "None" },
359         { 4, "None" },
360         { 5, "None" },
361         { 6, "None" },
362         { 7, "None" },
363         { 0, NULL }
364 };
365
366 #define GTP_PT_MASK             0x10
367 #define GTP_SPARE_MASK          0x0E
368 #define GTPv1_SPARE_MASK                0x08
369 #define GTPv1_E_MASK            0x04
370 #define GTPv1_S_MASK            0x02
371 #define GTP_SNN_MASK            0x01
372 #define GTPv1_PN_MASK           0x01
373
374 /* Definition of 3G charging characteristics masks */
375 #define GTP_MASK_CHRG_CHAR_S    0xF000
376 #define GTP_MASK_CHRG_CHAR_N    0x0800
377 #define GTP_MASK_CHRG_CHAR_P    0x0400
378 #define GTP_MASK_CHRG_CHAR_F    0x0200
379 #define GTP_MASK_CHRG_CHAR_H    0x0100
380 #define GTP_MASK_CHRG_CHAR_R    0x00FF
381
382 /* Traffic Flow Templates  mask */
383 #define GTPv1_TFT_CODE_MASK     0xE0
384 #define GTPv1_TFT_SPARE_MASK    0x10
385 #define GTPv1_TFT_NUMBER_MASK   0x0F
386
387 /* Definition of GSN Address masks */
388 #define GTP_EXT_GSN_ADDR_TYPE_MASK              0xC0
389 #define GTP_EXT_GSN_ADDR_LEN_MASK               0x3F
390
391 /* Definition of QoS masks */
392 #define GTP_EXT_QOS_SPARE1_MASK                 0xC0
393 #define GTP_EXT_QOS_DELAY_MASK                  0x38
394 #define GTP_EXT_QOS_RELIABILITY_MASK            0x07
395 #define GTP_EXT_QOS_PEAK_MASK                   0xF0
396 #define GTP_EXT_QOS_SPARE2_MASK                 0x08
397 #define GTP_EXT_QOS_PRECEDENCE_MASK             0x07
398 #define GTP_EXT_QOS_SPARE3_MASK                 0xE0
399 #define GTP_EXT_QOS_MEAN_MASK                   0x1F
400 #define GTP_EXT_QOS_TRAF_CLASS_MASK             0xE0
401 #define GTP_EXT_QOS_DEL_ORDER_MASK              0x18
402 #define GTP_EXT_QOS_DEL_ERR_SDU_MASK            0x07
403 #define GTP_EXT_QOS_RES_BER_MASK                0xF0
404 #define GTP_EXT_QOS_SDU_ERR_RATIO_MASK          0x0F
405 #define GTP_EXT_QOS_TRANS_DELAY_MASK            0xFC
406 #define GTP_EXT_QOS_TRAF_HANDL_PRIORITY_MASK    0x03
407
408 /* Definition of Radio Priority's masks */
409 #define GTPv1_EXT_RP_NSAPI_MASK                 0xF0
410 #define GTPv1_EXT_RP_SPARE_MASK                 0x08
411 #define GTPv1_EXT_RP_MASK                       0x07
412
413 /* definitions of GTP messages */
414 #define GTP_MSG_UNKNOWN                 0x00
415 #define GTP_MSG_ECHO_REQ                0x01
416 #define GTP_MSG_ECHO_RESP               0x02
417 #define GTP_MSG_VER_NOT_SUPP            0x03
418 #define GTP_MSG_NODE_ALIVE_REQ          0x04
419 #define GTP_MSG_NODE_ALIVE_RESP         0x05
420 #define GTP_MSG_REDIR_REQ               0x06
421 #define GTP_MSG_REDIR_RESP              0x07
422 #define GTP_MSG_CREATE_PDP_REQ          0x10
423 #define GTP_MSG_CREATE_PDP_RESP         0x11
424 #define GTP_MSG_UPDATE_PDP_REQ          0x12
425 #define GTP_MSG_UPDATE_PDP_RESP         0x13
426 #define GTP_MSG_DELETE_PDP_REQ          0x14
427 #define GTP_MSG_DELETE_PDP_RESP         0x15
428 #define GTP_MSG_CREATE_AA_PDP_REQ       0x16    /* 2G */
429 #define GTP_MSG_CREATE_AA_PDP_RESP      0x17    /* 2G */
430 #define GTP_MSG_DELETE_AA_PDP_REQ       0x18    /* 2G */
431 #define GTP_MSG_DELETE_AA_PDP_RESP      0x19    /* 2G */
432 #define GTP_MSG_ERR_IND                 0x1A
433 #define GTP_MSG_PDU_NOTIFY_REQ          0x1B
434 #define GTP_MSG_PDU_NOTIFY_RESP         0x1C
435 #define GTP_MSG_PDU_NOTIFY_REJ_REQ      0x1D
436 #define GTP_MSG_PDU_NOTIFY_REJ_RESP     0x1E
437 #define GTP_MSG_SUPP_EXT_HDR            0x1F
438 #define GTP_MSG_SEND_ROUT_INFO_REQ      0x20
439 #define GTP_MSG_SEND_ROUT_INFO_RESP     0x21
440 #define GTP_MSG_FAIL_REP_REQ            0x22
441 #define GTP_MSG_FAIL_REP_RESP           0x23
442 #define GTP_MSG_MS_PRESENT_REQ          0x24
443 #define GTP_MSG_MS_PRESENT_RESP         0x25
444 #define GTP_MSG_IDENT_REQ               0x30
445 #define GTP_MSG_IDENT_RESP              0x31
446 #define GTP_MSG_SGSN_CNTXT_REQ          0x32
447 #define GTP_MSG_SGSN_CNTXT_RESP         0x33
448 #define GTP_MSG_SGSN_CNTXT_ACK          0x34
449 #define GTP_MSG_FORW_RELOC_REQ          0x35
450 #define GTP_MSG_FORW_RELOC_RESP         0x36
451 #define GTP_MSG_FORW_RELOC_COMP         0x37
452 #define GTP_MSG_RELOC_CANCEL_REQ        0x38
453 #define GTP_MSG_RELOC_CANCEL_RESP       0x39
454 #define GTP_MSG_FORW_SRNS_CNTXT         0x3A
455 #define GTP_MSG_FORW_RELOC_ACK          0x3B
456 #define GTP_MSG_FORW_SRNS_CNTXT_ACK     0x3C
457 #define GTP_MSG_DATA_TRANSF_REQ         0xF0
458 #define GTP_MSG_DATA_TRANSF_RESP        0xF1
459 #define GTP_MSG_TPDU                    0xFF
460
461 static const value_string message_type[] = {
462         { GTP_MSG_UNKNOWN,              "For future use" },
463         { GTP_MSG_ECHO_REQ,             "Echo request" },
464         { GTP_MSG_ECHO_RESP,            "Echo response" },
465         { GTP_MSG_VER_NOT_SUPP,         "Version not supported" },
466         { GTP_MSG_NODE_ALIVE_REQ,       "Node alive request" },
467         { GTP_MSG_NODE_ALIVE_RESP,      "Node alive response" },
468         { GTP_MSG_REDIR_REQ,            "Redirection request" },
469         { GTP_MSG_REDIR_RESP,           "Redirection response" },
470         { GTP_MSG_CREATE_PDP_REQ,       "Create PDP context request" },
471         { GTP_MSG_CREATE_PDP_RESP,      "Create PDP context response" },
472         { GTP_MSG_UPDATE_PDP_REQ,       "Update PDP context request" },
473         { GTP_MSG_UPDATE_PDP_RESP,      "Update PDP context response" },
474         { GTP_MSG_DELETE_PDP_REQ,       "Delete PDP context request" },
475         { GTP_MSG_DELETE_PDP_RESP,      "Delete PDP context response" },
476         { GTP_MSG_CREATE_AA_PDP_REQ,    "Create AA PDP Context Request" },
477         { GTP_MSG_CREATE_AA_PDP_RESP,   "Create AA PDP Context Response" },
478         { GTP_MSG_DELETE_AA_PDP_REQ,    "Delete AA PDP Context Request" },
479         { GTP_MSG_DELETE_AA_PDP_RESP,   "Delete AA PDP Context Response" },
480         { GTP_MSG_ERR_IND,              "Error indication" },
481         { GTP_MSG_PDU_NOTIFY_REQ,       "PDU notification request" },
482         { GTP_MSG_PDU_NOTIFY_RESP,      "PDU notification response" },
483         { GTP_MSG_PDU_NOTIFY_REJ_REQ,   "PDU notification reject request" },
484         { GTP_MSG_PDU_NOTIFY_REJ_RESP,  "PDU notification reject response" },
485         { GTP_MSG_SUPP_EXT_HDR,         "Supported extension header notification" },
486         { GTP_MSG_SEND_ROUT_INFO_REQ,   "Send routing information for GPRS request" },
487         { GTP_MSG_SEND_ROUT_INFO_RESP,  "Send routing information for GPRS response" },
488         { GTP_MSG_FAIL_REP_REQ,         "Failure report request" },
489         { GTP_MSG_FAIL_REP_RESP,        "Failure report response" },
490         { GTP_MSG_MS_PRESENT_REQ,       "Note MS GPRS present request" },
491         { GTP_MSG_MS_PRESENT_RESP,      "Note MS GPRS present response" },
492         { GTP_MSG_IDENT_REQ,            "Identification request" },
493         { GTP_MSG_IDENT_RESP,           "Identification response" },
494         { GTP_MSG_SGSN_CNTXT_REQ,       "SGSN context request" },
495         { GTP_MSG_SGSN_CNTXT_RESP,      "SGSN context response" },
496         { GTP_MSG_SGSN_CNTXT_ACK,       "SGSN context acknowledgement" },
497         { GTP_MSG_FORW_RELOC_REQ,       "Forward relocation request" },
498         { GTP_MSG_FORW_RELOC_RESP,      "Forward relocation response" },
499         { GTP_MSG_FORW_RELOC_COMP,      "Forward relocation complete" },
500         { GTP_MSG_RELOC_CANCEL_REQ,     "Relocation cancel request" },
501         { GTP_MSG_RELOC_CANCEL_RESP,    "Relocation cancel response" },
502         { GTP_MSG_FORW_SRNS_CNTXT,      "Forward SRNS context" },
503         { GTP_MSG_FORW_RELOC_ACK,       "Forward relocation complete acknowledge" },
504         { GTP_MSG_FORW_SRNS_CNTXT_ACK,  "Forward SRNS context acknowledge" },
505         { GTP_MSG_DATA_TRANSF_REQ,      "Data record transfer request" },
506         { GTP_MSG_DATA_TRANSF_RESP,     "Data record transfer response" },
507         { GTP_MSG_TPDU,                 "T-PDU" },
508         { 0, NULL }
509 };
510
511 /* definitions of fields in extension header */
512 #define GTP_EXT_CAUSE           0x01
513 #define GTP_EXT_IMSI            0x02
514 #define GTP_EXT_RAI             0x03
515 #define GTP_EXT_TLLI            0x04
516 #define GTP_EXT_PTMSI           0x05
517 #define GTP_EXT_QOS_GPRS        0x06
518 #define GTP_EXT_REORDER         0x08
519 #define GTP_EXT_AUTH_TRI        0x09
520 #define GTP_EXT_MAP_CAUSE       0x0B
521 #define GTP_EXT_PTMSI_SIG       0x0C
522 #define GTP_EXT_MS_VALID        0x0D
523 #define GTP_EXT_RECOVER         0x0E
524 #define GTP_EXT_SEL_MODE        0x0F
525
526 #define GTP_EXT_16              0x10
527 #define GTP_EXT_FLOW_LABEL      0x10
528 #define GTP_EXT_TEID            0x10    /* 0xFF10 3G */
529
530 #define GTP_EXT_17              0x11
531 #define GTP_EXT_FLOW_SIG        0x11
532 #define GTP_EXT_TEID_CP         0x11    /* 0xFF11 3G */
533
534 #define GTP_EXT_18              0x12
535 #define GTP_EXT_FLOW_II         0x12
536 #define GTP_EXT_TEID_II         0x12    /* 0xFF12 3G*/
537
538 #define GTP_EXT_19              0x13
539 #define GTP_EXT_MS_REASON       0x13    /* same as 0x1D GTPv1_EXT_MS_REASON */
540 #define GTP_EXT_TEAR_IND        0x13    /* 0xFF13 3G*/
541
542 #define GTP_EXT_NSAPI           0x14    /* 3G */
543 #define GTP_EXT_RANAP_CAUSE     0x15    /* 3G */
544 #define GTP_EXT_RAB_CNTXT       0x16    /* 3G */
545 #define GTP_EXT_RP_SMS          0x17    /* 3G */
546 #define GTP_EXT_RP              0x18    /* 3G */
547 #define GTP_EXT_PKT_FLOW_ID     0x19    /* 3G */
548 #define GTP_EXT_CHRG_CHAR       0x1A    /* 3G */
549 #define GTP_EXT_TRACE_REF       0x1B    /* 3G */
550 #define GTP_EXT_TRACE_TYPE      0x1C    /* 3G */
551 #define GTPv1_EXT_MS_REASON     0x1D    /* 3G */
552 #define GTP_EXT_TR_COMM         0x7E    /* charging */
553 #define GTP_EXT_CHRG_ID         0x7F
554 #define GTP_EXT_USER_ADDR       0x80
555 #define GTP_EXT_MM_CNTXT        0x81
556 #define GTP_EXT_PDP_CNTXT       0x82
557 #define GTP_EXT_APN             0x83
558 #define GTP_EXT_PROTO_CONF      0x84
559 #define GTP_EXT_GSN_ADDR        0x85
560 #define GTP_EXT_MSISDN          0x86
561 #define GTP_EXT_QOS_UMTS        0x87    /* 3G */
562 #define GTP_EXT_AUTH_QUI        0x88    /* 3G */
563 #define GTP_EXT_TFT             0x89    /* 3G */
564 #define GTP_EXT_TARGET_ID       0x8A    /* 3G */
565 #define GTP_EXT_UTRAN_CONT      0x8B    /* 3G */
566 #define GTP_EXT_RAB_SETUP       0x8C    /* 3G */
567 #define GTP_EXT_HDR_LIST        0x8D    /* 3G */
568 #define GTP_EXT_TRIGGER_ID      0x8E    /* 3G */
569 #define GTP_EXT_OMC_ID          0x8F    /* 3G */
570 #define GTP_EXT_REL_PACK        0xF9    /* charging */
571 #define GTP_EXT_CAN_PACK        0xFA    /* charging */
572 #define GTP_EXT_CHRG_ADDR       0xFB
573 #define GTP_EXT_DATA_REQ        0xFC    /* charging */
574 #define GTP_EXT_DATA_RESP       0xFD    /* charging */
575 #define GTP_EXT_NODE_ADDR       0xFE    /* charging */
576 #define GTP_EXT_PRIV_EXT        0xFF
577
578 static const value_string gtp_val[] = {
579         { GTP_EXT_CAUSE,        "Cause of operation" },
580         { GTP_EXT_IMSI,         "IMSI" },
581         { GTP_EXT_RAI,          "Routing Area Identity" },
582         { GTP_EXT_TLLI,         "Temporary Logical Link Identity" },
583         { GTP_EXT_PTMSI,        "Packet TMSI" },
584         { GTP_EXT_QOS_GPRS,     "Quality of Service" },
585         { GTP_EXT_REORDER,      "Reorder required" },
586         { GTP_EXT_AUTH_TRI,     "Authentication triplets" },
587         { GTP_EXT_MAP_CAUSE,    "MAP cause" },
588         { GTP_EXT_PTMSI_SIG,    "P-TMSI signature" },
589         { GTP_EXT_MS_VALID,     "MS validated" },
590         { GTP_EXT_RECOVER,      "Recovery" },
591         { GTP_EXT_SEL_MODE,     "Selection mode" },
592
593         { GTP_EXT_16,           "Flow label data I" },
594         { GTP_EXT_FLOW_LABEL,   "Flow label data I" },
595         { GTP_EXT_TEID,         "Tunnel Endpoint Identifier Data I" },          /* 3G */
596
597         { GTP_EXT_17,           "Flow label signalling" },
598         { GTP_EXT_FLOW_SIG,     "Flow label signalling" },
599         { GTP_EXT_TEID_CP,      "Tunnel Endpoint Identifier Data Control Plane" },      /* 3G */
600
601         { GTP_EXT_18,           "Flow label data II" },
602         { GTP_EXT_FLOW_II,      "Flow label data II" },
603         { GTP_EXT_TEID_II,      "Tunnel Endpoint Identifier Data II" },         /* 3G */
604
605         { GTP_EXT_19,           "MS not reachable reason" },
606         { GTP_EXT_MS_REASON,    "MS not reachable reason" },
607         { GTP_EXT_TEAR_IND,     "Teardown ID" },                                        /* 3G */
608
609         { GTP_EXT_NSAPI,        "NSAPI" },                                              /* 3G */
610         { GTP_EXT_RANAP_CAUSE,  "RANAP cause" },                                        /* 3G */
611         { GTP_EXT_RAB_CNTXT,    "RAB context" },                                        /* 3G */
612         { GTP_EXT_RP_SMS,       "Radio Priority for MO SMS" },                  /* 3G */
613         { GTP_EXT_RP,           "Radio Priority" },                                     /* 3G */
614         { GTP_EXT_PKT_FLOW_ID,  "Packet Flow ID" },                                     /* 3G */
615         { GTP_EXT_CHRG_CHAR,    "Charging characteristics" },                           /* 3G */
616         { GTP_EXT_TRACE_REF,    "Trace references" },                                   /* 3G */
617         { GTP_EXT_TRACE_TYPE,   "Trace type" },                                 /* 3G */
618         { GTPv1_EXT_MS_REASON,  "MS not reachable reason" },                            /* 3G */
619         { GTP_EXT_TR_COMM,      "Packet transfer command" },                            /* charging */
620         { GTP_EXT_CHRG_ID,      "Charging ID" },
621         { GTP_EXT_USER_ADDR,    "End user address" },
622         { GTP_EXT_MM_CNTXT,     "MM context" },
623         { GTP_EXT_PDP_CNTXT,    "PDP context" },
624         { GTP_EXT_APN,          "Access Point Name" },
625         { GTP_EXT_PROTO_CONF,   "Protocol configuration options" },
626         { GTP_EXT_GSN_ADDR,     "GSN address" },
627         { GTP_EXT_MSISDN,       "MS international PSTN/ISDN number" },
628         { GTP_EXT_QOS_UMTS,     "Quality of service (UMTS)" },                  /* 3G */
629         { GTP_EXT_AUTH_QUI,     "Authentication quintuplets" },                 /* 3G */
630         { GTP_EXT_TFT,          "Traffic Flow Template (TFT)" },                        /* 3G */
631         { GTP_EXT_TARGET_ID,    "Target (RNC) identification" },                        /* 3G */
632         { GTP_EXT_UTRAN_CONT,   "UTRAN transparent field" },                            /* 3G */
633         { GTP_EXT_RAB_SETUP,    "RAB setup information" },                              /* 3G */
634         { GTP_EXT_HDR_LIST,     "Extension Header Types List" },                        /* 3G */
635         { GTP_EXT_TRIGGER_ID,   "Trigger Id" },                                 /* 3G */
636         { GTP_EXT_OMC_ID,       "OMC Identity" },                                       /* 3G */
637         { GTP_EXT_REL_PACK,     "Sequence numbers of released packets IE" },            /* charging */
638         { GTP_EXT_CAN_PACK,     "Sequence numbers of canceled packets IE" },            /* charging */
639         { GTP_EXT_CHRG_ADDR,    "Charging Gateway address" },
640         { GTP_EXT_DATA_REQ,     "Data record packet" },                         /* charging */
641         { GTP_EXT_DATA_RESP,    "Requests responded" },                         /* charging */
642         { GTP_EXT_NODE_ADDR,    "Address of recommended node" },                        /* charging */
643         { GTP_EXT_PRIV_EXT,     "Private Extension" },
644         { 0, NULL }
645 };
646
647 /* GPRS:        9.60 v7.6.0, page 37
648  * UMTS:        29.060 v4.0, page 45
649  */
650 static const value_string cause_type[] = {
651         { 0,    "Request IMSI" },
652         { 1,    "Request IMEI" },
653         { 2,    "Request IMSI and IMEI" },
654         { 3,    "No identity needed" },
655         { 4,    "MS refuses" },
656         { 5,    "MS is not GPRS responding" },
657         { 59,   "System failure" },     /* charging */
658         { 60,   "The transmit buffers are becoming full" },     /* charging */
659         { 61,   "The receive buffers are becoming full" },      /* charging */
660         { 62,   "Another node is about to go down" },   /* charging */
661         { 63,   "This node is about to go down" },      /* charging */
662         { 128,  "Request accepted" },
663         { 192,  "Non-existent" },
664         { 193,  "Invalid message format" },
665         { 194,  "IMSI not known" },
666         { 195,  "MS is GPRS detached" },
667         { 196,  "MS is not GPRS responding" },
668         { 197,  "MS refuses" },
669         { 198,  "Version not supported" },
670         { 199,  "No resource available" },
671         { 200,  "Service not supported" },
672         { 201,  "Mandatory IE incorrect" },
673         { 202,  "Mandatory IE missing" },
674         { 203,  "Optional IE incorrect" },
675         { 204,  "System failure" },
676         { 205,  "Roaming restriction" },
677         { 206,  "P-TMSI signature mismatch" },
678         { 207,  "GPRS connection suspended" },
679         { 208,  "Authentication failure" },
680         { 209,  "User authentication failed" },
681         { 210,  "Context not found" },
682         { 211,  "All PDP dynamic addresses are occupied" },
683         { 212,  "No memory is available" },
684         { 213,  "Relocation failure" },
685         { 214,  "Unknown mandatory extension header" },
686         { 215,  "Semantic error in the TFT operation" },
687         { 216,  "Syntactic error in the TFT operation" },
688         { 217,  "Semantic errors in packet filter(s)" },
689         { 218,  "Syntactic errors in packet filter(s)" },
690         { 219,  "Missing or unknown APN" },
691         { 220,  "Unknown PDP address or PDP type" },
692         { 252,  "Request related to possibly duplicated packets already fulfilled" },   /* charging */
693         { 253,  "Request already fulfilled" },  /* charging */
694         { 254,  "Sequence numbers of released/cancelled packets IE incorrect" },        /* charging */
695         { 255,  "Request not fulfilled" },      /* charging */
696         { 0, NULL }
697 };
698
699 /* GPRS:        9.02 v7.7.0
700  * UMTS:        29.002 v4.2.1, chapter 17.5, page 268
701  * TODO: Check if all map_cause values are included
702  */
703 static const value_string map_cause_type[] = {
704         { 1, "Unknown subscriber" },
705         { 8, "Roaming not allowed" },
706         { 10, "Bearer service not provisioned" },
707         { 11, "Teleservice not provisioned" },
708         { 13, "Call barred" },
709         { 21, "Facility not supported" },
710         { 23, "Update GPRS location" },
711         { 24, "Send routing info for GPRS" },
712         { 26, "Note MS present for GPRS" },
713         { 27, "Absent subscriber" },
714         { 34, "System failure" },
715         { 35, "Data missing" },
716         { 36, "Unexpected data value" },
717         { 44, "Number chenged" },
718         { 45, "Busy subscriber" },
719         { 46, "No subscriber reply" },
720         { 48, "Facility not allowed" },
721         { 0, NULL }
722 };
723
724 static const value_string gsn_addr_type[] = {
725         { 0x00, "IPv4" },
726         { 0x01, "IPv6" },
727         { 0,    NULL },
728 };
729
730 static const value_string pdp_type[] = {
731         { 0x00, "X.25" },
732         { 0x01, "PPP" },
733         { 0x02, "OSP:IHOSS" },
734         { 0x21, "IPv4" },
735         { 0x57, "IPv6" },
736         { 0, NULL }
737 };
738
739 static const value_string pdp_org_type[] = {
740         { 0, "ETSI" },
741         { 1, "IETF" },
742         { 0, NULL }
743 };
744
745 static const value_string qos_delay_type[] = {
746         { 0x00, "Subsribed delay class (in MS to network direction)" },
747         { 0x01, "Delay class 1" },
748         { 0x02, "Delay class 2" },
749         { 0x03, "Delay class 3" },
750         { 0x04, "Delay class 4 (best effort)" },
751         { 0x07, "Reserved" },
752         { 0, NULL }
753 };
754
755 static const value_string qos_reliability_type[] = {
756         { 0x00, "Subscribed reliability class (in MS to network direction)" },
757         { 0x01, "Ack GTP/LLC/RLC, Protected data" },
758         { 0x02, "Unack GTP, Ack LLC/RLC, Protected data" },
759         { 0x03, "Unack GTP/LLC, Ack RLC, Protected data" },
760         { 0x04, "Unack GTP/LLC/RLC, Protected data" },
761         { 0x05, "Unack GTP/LLC/RLC, Unprotected data" },
762         { 0x07, "Reserved" },
763         { 0, NULL }
764 };
765
766 static const value_string qos_peak_type[] = {
767         { 0x00, "Subscribed peak throughput (in MS to network direction)" },
768         { 0x01, "Up to 1 000 oct/s" },
769         { 0x02, "Up to 2 000 oct/s" },
770         { 0x03, "Up to 4 000 oct/s" },
771         { 0x04, "Up to 8 000 oct/s" },
772         { 0x05, "Up to 16 000 oct/s" },
773         { 0x06, "Up to 32 000 oct/s" },
774         { 0x07, "Up to 64 000 oct/s" },
775         { 0x08, "Up to 128 000 oct/s" },
776         { 0x09, "Up to 256 000 oct/s" },
777 /* QoS Peak throughput classes from 0x0A to 0x0F (from 10 to 15) are subscribed */
778         { 0x0A, "Reserved" },
779         { 0x0B, "Reserved" },
780         { 0x0C, "Reserved" },
781         { 0x0D, "Reserved" },
782         { 0x0E, "Reserved" },
783         { 0x0F, "Reserved" },
784         { 0, NULL }
785 };
786
787 static const value_string qos_precedence_type[] = {
788         { 0x00, "Subscribed precedence (in MS to network direction)" },
789         { 0x01, "High priority" },
790         { 0x02, "Normal priority" },
791         { 0x03, "Low priority" },
792         { 0x07, "Reserved" },
793         { 0, NULL }
794 };
795
796 static const value_string qos_mean_type[] = {
797         { 0x00, "Subscribed mean throughput (in MS to network direction)" },
798         { 0x01, "100 oct/h" },          /* Class 2 */
799         { 0x02, "200 oct/h" },          /* Class 3 */
800         { 0x03, "500 oct/h" },          /* Class 4 */
801         { 0x04, "1 000 oct/h" },        /* Class 5 */
802         { 0x05, "2 000 oct/h" },        /* Class 6 */
803         { 0x06, "5 000 oct/h" },        /* Class 7 */
804         { 0x07, "10 000 oct/h" },       /* Class 8 */
805         { 0x08, "20 000 oct/h" },       /* Class 9 */
806         { 0x09, "50 000 oct/h" },       /* Class 10 */
807         { 0x0A, "100 000 oct/h" },      /* Class 11 */
808         { 0x0B, "200 000 oct/h" },      /* Class 12 */
809         { 0x0C, "500 000 oct/h" },      /* Class 13 */
810         { 0x0D, "1 000 000 oct/h" },    /* Class 14 */
811         { 0x0E, "2 000 000 oct/h" },    /* Class 15 */
812         { 0x0F, "5 000 000 oct/h" },    /* Class 16 */
813         { 0x10, "10 000 000 oct/h" },   /* Class 17 */
814         { 0x11, "20 000 000 oct/h" },   /* Class 18 */
815         { 0x12, "50 000 000 oct/h" },   /* Class 19 */
816 /* QoS Mean throughput classes from 0x13 to 0x1E (from 19 to 30) are subscribed */
817         { 0x13, "Reserved" },
818         { 0x14, "Reserved" },
819         { 0x15, "Reserved" },
820         { 0x16, "Reserved" },
821         { 0x17, "Reserved" },
822         { 0x18, "Reserved" },
823         { 0x19, "Reserved" },
824         { 0x1A, "Reserved" },
825         { 0x1B, "Reserved" },
826         { 0x1C, "Reserved" },
827         { 0x1D, "Reserved" },
828         { 0x1E, "Reserved" },
829         { 0x1F, "Best effort" },        /* Class 1 */
830         { 0, NULL }
831 };
832
833 static const value_string qos_del_err_sdu[] = {
834         { 0x00, "Subscribed delivery of erroneous SDUs (in MS to network direction)" },
835         { 0x01, "No detect ('-')" },
836         { 0x02, "Erroneous SDUs are delivered ('yes')" },
837         { 0x03, "Erroneous SDUs are not delivered ('no')" },
838         { 0x07, "Reserved" },           /* All other values are reserved */
839         { 0, NULL }
840 };
841
842 static const value_string qos_del_order[] = {
843         { 0x00, "Subscribed delivery order (in MS to network direction)" },
844         { 0x01, "With delivery order ('yes')" },
845         { 0x02, "Without delivery order ('no')" },
846         { 0x03, "Reserved" },           /* All other values are reserved */
847         { 0, NULL }
848 };
849
850 static const value_string qos_traf_class[] = {
851         { 0x00, "Subscribed traffic class (in MS to network direction)" },
852         { 0x01, "Conversational class" },
853         { 0x02, "Streaming class" },
854         { 0x03, "Interactive class" },
855         { 0x04, "Background class" },
856         { 0x07, "Reserved" },           /* All other values are reserved */
857         { 0, NULL }
858 };
859
860 static const value_string qos_max_sdu_size[] = {
861         { 0x00, "Subscribed maximum SDU size (in MS to network direction" },
862         /* For values from 0x01 to 0x96 (from 1 to 150), use a granularity of 10 octets */
863         { 0x97, "1502 octets" },
864         { 0x98, "1510 octets" },
865         { 0x99, "1520 octets" },
866         { 0, NULL }                                     /* All other values are reserved */
867 };
868
869 static const value_string qos_max_ul[] = {
870         { 0x00, "Subscribed maximum bit rate for uplink (in MS to network direction)" },
871         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
872         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
873         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
874         { 0xFF, "0 kbps" },
875         { 0, NULL }
876 };
877
878 static const value_string qos_max_dl[] = {
879         { 0x00, "Subscribed maximum bit rate for downlink (in MS to network direction)" },
880         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
881         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
882         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
883         { 0xFF, "0 kbps" },
884         { 0, NULL }
885 };
886
887 static const value_string qos_res_ber[] = {
888         { 0x00, "Subscribed residual BER (in MS to network direction)" },
889         { 0x01, "1/20 = 5x10^-2" },
890         { 0x02, "1/100 = 1x10^-2" },
891         { 0x03, "1/200 = 5x10^-3" },
892         { 0x04, "1/250 = 4x10^-3" },
893         { 0x05, "1/1 000 = 1x10^-3" },
894         { 0x06, "1/10 000 = 1x10^-4" },
895         { 0x07, "1/100 000 = 1x10^-5" },
896         { 0x08, "1/1 000 000 = 1x10^-6" },
897         { 0x09, "3/50 000 000 = 6x10^-8" },
898         { 0x0F, "Reserved" },           /* All other values are reserved */
899         { 0, NULL }
900 };
901
902 static const value_string qos_sdu_err_ratio[] = {
903         { 0x00, "Subscribed SDU error ratio (in MS to network direction)" },
904         { 0x01, "1/100 = 1x10^-2" },
905         { 0x02, "7/1000 = 7x10^-3" },
906         { 0x03, "1/1 000 = 1x10^-3" },
907         { 0x04, "1/10 000 = 1x10^-4" },
908         { 0x05, "1/100 000 = 1x10^-5" },
909         { 0x06, "1/1 000 000 = 1x10^-6" },
910         { 0x07, "1/10 = 1x10^-1" },
911         { 0x0F, "Reserved" },           /* All other values are reserved */
912         { 0, NULL }
913 };
914
915 static const value_string qos_traf_handl_prio[] = {
916         { 0x00, "Subscribed traffic handling priority (in MS to network direction)" },
917         { 0x01, "Priority level 1" },
918         { 0x02, "Priority level 2" },
919         { 0x03, "Priority level 3" },
920         { 0, NULL }
921 };
922
923 static const value_string qos_trans_delay[] = {
924         { 0x00, "Subscribed Transfer Delay (in MS to network direction)" },
925         { 0x01, "10 ms" },      /* Using a granularity of 10 ms */
926         { 0x02, "20 ms" },
927         { 0x03, "30 ms" },
928         { 0x04, "40 ms" },
929         { 0x05, "50 ms" },
930         { 0x06, "60 ms" },
931         { 0x07, "70 ms" },
932         { 0x08, "80 ms" },
933         { 0x09, "90 ms" },
934         { 0x0A, "100 ms" },
935         { 0x0B, "110 ms" },
936         { 0x0C, "120 ms" },
937         { 0x0D, "130 ms" },
938         { 0x0E, "140 ms" },
939         { 0x0F, "150 ms" },
940         { 0x10, "200 ms" },     /* (For values from 0x10 to 0x1F, value = 200 ms + (value - 0x10) * 50 ms */
941         { 0x11, "250 ms" },
942         { 0x12, "300 ms" },
943         { 0x13, "350 ms" },
944         { 0x14, "400 ms" },
945         { 0x15, "450 ms" },
946         { 0x16, "500 ms" },
947         { 0x17, "550 ms" },
948         { 0x18, "600 ms" },
949         { 0x19, "650 ms" },
950         { 0x1A, "700 ms" },
951         { 0x1B, "750 ms" },
952         { 0x1C, "800 ms" },
953         { 0x1D, "850 ms" },
954         { 0x1E, "900 ms" },
955         { 0x1F, "950 ms" },
956         { 0x20, "1000 ms" },    /* For values from 0x20 to 0x3E, value = 1000 ms + (value - 0x20) * 100 ms */
957         { 0x21, "1100 ms" },
958         { 0x22, "1200 ms" },
959         { 0x23, "1300 ms" },
960         { 0x24, "1400 ms" },
961         { 0x25, "1500 ms" },
962         { 0x26, "1600 ms" },
963         { 0x27, "1700 ms" },
964         { 0x28, "1800 ms" },
965         { 0x29, "1900 ms" },
966         { 0x2A, "2000 ms" },
967         { 0x2B, "2100 ms" },
968         { 0x2C, "2200 ms" },
969         { 0x2D, "2300 ms" },
970         { 0x2E, "2400 ms" },
971         { 0x2F, "2500 ms" },
972         { 0x30, "2600 ms" },
973         { 0x31, "2700 ms" },
974         { 0x32, "2800 ms" },
975         { 0x33, "2900 ms" },
976         { 0x34, "3000 ms" },
977         { 0x35, "3100 ms" },
978         { 0x36, "3200 ms" },
979         { 0x37, "3300 ms" },
980         { 0x38, "3400 ms" },
981         { 0x39, "3500 ms" },
982         { 0x3A, "3600 ms" },
983         { 0x3B, "3700 ms" },
984         { 0x3C, "3800 ms" },
985         { 0x3D, "3900 ms" },
986         { 0x3E, "4000 ms" },
987         { 0x3F, "Reserved"},
988         { 0, NULL }
989 };
990
991 static const value_string qos_guar_ul[] = {
992         { 0x00, "Subscribed guaranteed bit rate for uplink (in MS to network direction)" },
993         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
994         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
995         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
996         { 0xFF, "0 kbps" },
997         { 0, NULL }
998 };
999
1000 static const value_string qos_guar_dl[] = {
1001         { 0x00, "Subscribed guaranteed bit rate for downlink (in MS to network direction)" },
1002         /* For values from 0x01 to 0x3F (from 1 to 63), use a granularity of 1 kbps */
1003         /* For values from 0x40 to 0x7F, value = 64 kbps + (value - 0x40) * 8 kbps */
1004         /* For values from 0x80 to 0xFE, value = 576 kbps + (value - 0x80) * 64 kbps */
1005         { 0xFF, "0 kbps" },
1006         { 0, NULL }
1007 };
1008
1009 static const value_string sel_mode_type[] = {
1010         { 0,    "MS or network provided APN, subscribed verified" },
1011         { 1,    "MS provided APN, subscription not verified" },
1012         { 2,    "Network provided APN, subscription not verified" },
1013         { 3,    "For future use (Network provided APN, subscription not verified" },/* Shall not be sent. If received, shall be sent as value 2 */
1014         { 0,    NULL }
1015 };
1016
1017 static const value_string tr_comm_type[] = {
1018         { 1,    "Send data record packet" },
1019         { 2,    "Send possibly duplicated data record packet" },
1020         { 3,    "Cancel data record packet" },
1021         { 4,    "Release data record packet"},
1022         { 0,    NULL }
1023 };
1024
1025 /* TODO: CHeck if all ms_reasons are included */
1026 static const value_string ms_not_reachable_type[] = {
1027         { 0,    "No paging response via the MSC" },
1028         { 1,    "IMSI detached" },
1029         { 2,    "Roaming restriction" },
1030         { 3,    "Deregistered in the HLR for non GPRS" },
1031         { 4,    "MS purge for non GPRS" },
1032         { 5,    "No paging response via the SGSN" },
1033         { 6,    "GPRS detached" },
1034         { 7,    "Deregistered in the HLR for non GPRS" },
1035         { 8,    "MS purged for GPRS" },
1036         { 9,    "Unidentified subscriber via the MSC" },
1037         { 10,   "Unidentified subscriber via the SGSN" },
1038         { 0,    NULL }
1039 };
1040
1041 /* UMTS:        25.413 v3.4.0, chapter 9.2.1.4, page 80
1042  */
1043 static const value_string ranap_cause_type[] = {
1044 /* Radio Network Layer Cause (1-->64) */
1045         { 1, "RAB preempted" },
1046         { 2, "Trelocoverall Expiry" },
1047         { 3, "Trelocprep Expiry" },
1048         { 4, "Treloccomplete Expiry" },
1049         { 5, "Tqueing Expiry" },
1050         { 6, "Relocation Triggered" },
1051         { 7, "TRELOCalloc Expiry" },
1052         { 8, "Unable to Estabish During Relocation" },
1053         { 9, "Unknown Target RNC" },
1054         { 10, "Relocation Cancelled" },
1055         { 11, "Successful Relocation" },
1056         { 12, "Requested Ciphering and/or Integrity Protection Algorithms not Supported" },
1057         { 13, "Change of Ciphering and/or Integrity Protection is not supported" },
1058         { 14, "Failure in the Radio Interface Procedure" },
1059         { 15, "Release due to UTRAN Generated Reason" },
1060         { 16, "User Inactivity" },
1061         { 17, "Time Critical Relocation" },
1062         { 18, "Requested Traffic Class not Available" },
1063         { 19, "Invalid RAB Parameters Value" },
1064         { 20, "Requested Maximum Bit Rate not Available" },
1065         { 21, "Requested Guaranteed Bit Rate not Available" },
1066         { 22, "Requested Transfer Delay not Achievable" },
1067         { 23, "Invalid RAB Parameters Combination" },
1068         { 24, "Condition Violation for SDU Parameters" },
1069         { 25, "Condition Violation for Traffic Handling Priority" },
1070         { 26, "Condition Violation for Guaranteed Bit Rate" },
1071         { 27, "User Plane Versions not Supported" },
1072         { 28, "Iu UP Failure" },
1073         { 29, "Relocation Failure in Target CN/RNC or Target System" },
1074         { 30, "Invalid RAB ID" },
1075         { 31, "No Remaining RAB" },
1076         { 32, "Interaction with other procedure" },
1077         { 33, "Requested Maximum Bit Rate for DL not Available" },
1078         { 34, "Requested Maximum Bit Rate for UL not Available" },
1079         { 35, "Requested Guaranteed Bit Rate for DL not Available" },
1080         { 36, "Requested Guaranteed Bit Rate for UL not Available" },
1081         { 37, "Repeated Integrity Checking Failure" },
1082         { 38, "Requested Report Type not supported" },
1083         { 39, "Request superseded" },
1084         { 40, "Release due to UE generated signalling connection release" },
1085         { 41, "Resource Optimisation Relocation" },
1086         { 42, "Requested Information Not Available" },
1087         { 43, "Relocation desirable for radio reasons" },
1088         { 44, "Relocation not supported in Target RNC or Target System" },
1089         { 45, "Directed Retry" },
1090         { 46, "Radio Connection With UE Lost" },
1091 /* Transport Layer Cause (65-->80) */
1092         { 65, "Signalling Transport Resource Failure" },
1093         { 66, "Iu Transport Connection Failed to Establish" },
1094 /* NAS Cause (81-->96) */
1095         { 81, "User Restriction Start Indication" },
1096         { 82, "User Restriction End Indication" },
1097         { 83, "Normal Release" },
1098 /* Protocol Cause (97-->112) */
1099         { 97, "Transfer Syntax Error" },
1100         { 98, "Semantic Error" },
1101         { 99, "Message not compatible with receiver state" },
1102         { 100, "Abstract Syntax Error (Reject)" },
1103         { 101, "Abstract Syntax Error (Ignore and Notify)" },
1104         { 102, "Abstract Syntax Error (Falsely Constructed Message" },
1105 /* Miscellaneous Cause (113-->128) */
1106         { 113, "O & M Intervention" },
1107         { 114, "No Resource Available" },
1108         { 115, "Unspecified Failure" },
1109         { 116, "Network Opimisation" },
1110 /* Non-standard Cause (129-->255) */
1111         { 0, NULL }
1112 };
1113
1114 static const value_string mm_sec_modep[] = {
1115         { 0,    "Used cipher value, UMTS keys and Quintuplets" },
1116         { 1,    "GSM key and triplets" },
1117         { 2,    "UMTS key and quintuplets" },
1118         { 3,    "GSM key and quintuplets" },
1119         { 0,    NULL }
1120 };
1121
1122 static const value_string mm_proto_disc[] = {
1123         { 0x00, "Group call control" },
1124         { 0x01, "Broadcast call control" },
1125         { 0x02, "PDSS1" },
1126         { 0x03, "Call control; call related SS messages" },
1127         { 0x04, "PDSS2" },
1128         { 0x05, "Mobility Management messages for non-GPRS services" },
1129         { 0x06, "Radio Resource management messages" },
1130         { 0x08, "Mobility Management messages for GPRS services" },
1131         { 0x09, "SMS" },
1132         { 0x0A, "Session Management messages" },
1133         { 0x0B, "Non-call related SS messages" },
1134         { 0, NULL }
1135 };
1136
1137 static const value_string mm_rr_mess[] = {
1138         { 0x3C, "RR initialization request" },
1139         { 0x3B, "Additional assignment" },
1140         { 0x3F, "Immediate assignment" },
1141         { 0x39, "Immediate assignment extended" },
1142         { 0x3A, "Immediate assignment reject" },
1143
1144         { 0x35, "Ciphering mode command" },
1145         { 0x32, "Ciphering mode complete" },
1146
1147         { 0x30, "Configuration change command" },
1148         { 0x31, "Configuration change ack" },
1149         { 0x33, "Configuration change reject" },
1150
1151         { 0x2E, "Assignment command" },
1152         { 0x29, "Assignment complete" },
1153         { 0x2F, "Assigment failure" },
1154         { 0x2B, "Handover command" },
1155         { 0x2C, "Handover complete" },
1156         { 0x28, "Handover failure" },
1157         { 0x2D, "Physical information" },
1158
1159         { 0x08, "RR-cell change order" },
1160         { 0x23, "PDCH assignment command" },
1161
1162         { 0x0D, "Channel release" },
1163         { 0x0A, "Partial release" },
1164         { 0x0F, "PArtial release complete" },
1165
1166         { 0x21, "Paging request type 1" },
1167         { 0x22, "Paging request type 2" },
1168         { 0x24, "Paging request type 3" },
1169         { 0x27, "Paging response" },
1170         { 0x20, "Notification/NCH" },
1171         { 0x25, "Notification/FACCH" },
1172         { 0x26, "Reserved" },
1173         { 0x0B, "Reserved" },
1174
1175         { 0x18, "System information type 8" },
1176         { 0x19, "System information type 1" },
1177         { 0x1A, "System information type 2" },
1178         { 0x1B, "System information type 3" },
1179         { 0x1C, "System information type 4" },
1180         { 0x1D, "System information type 5" },
1181         { 0x1E, "System information type 6" },
1182         { 0x1F, "System information type 7" },
1183
1184         { 0x02, "System information type 2bis" },
1185         { 0x03, "System information type 2ter" },
1186         { 0x05, "System information type 5bis" },
1187         { 0x06, "System information type 5ter" },
1188         { 0x04, "System information 9" },
1189         { 0x00, "System information 13" },
1190         { 0x01, "System information 14" },
1191
1192         { 0x3D, "System information type 16" },
1193         { 0x3E, "System information type 17" },
1194
1195         { 0x10, "Channel mode modify" },
1196         { 0x12, "RR status" },
1197         { 0x17, "Channel mode modify ack" },
1198         { 0x14, "Frequency redefinition" },
1199         { 0x15, "Measurement report" },
1200         { 0x16, "Classmark change" },
1201         { 0x13, "Classmark enquiry" },
1202         { 0x36, "Extended measurement report" },
1203         { 0x37, "Extended measurement order" },
1204         { 0x34, "GPRS suspension request" },
1205
1206         { 0x09, "VGCS uplink grant" },
1207         { 0x0E, "Uplink release" },
1208         { 0x0C, "Uplink free" },
1209         { 0x2A, "Uplink busy" },
1210         { 0x11, "Talker indication" },
1211
1212         { 0, NULL }
1213 };
1214
1215 static const value_string mm_mm_mess[] = {
1216         { 0x01, "IMSI DETACH INDICATION" },
1217         { 0x02, "LOCATION UPDATING ACCEPT" },
1218         { 0x04, "LOCATION UPDATING REJECT" },
1219         { 0x08, "LOCATION UPDATING REQUEST" },
1220         { 0x11, "AUTHENTICATION REJECT" },
1221         { 0x12, "AUTHENTICATION REQUEST" },
1222         { 0x14, "AUTHENTICATION RESPONSE" },
1223         { 0x18, "IDENTITY REQUEST" },
1224         { 0x19, "IDENTITY RESPONSE" },
1225         { 0x1A, "TMSI REALLOCATION COMMAND" },
1226         { 0x1B, "TMSI REALLOCATION COMPLETE" },
1227         { 0x21, "CM SERVICE ACCEPT" },
1228         { 0x22, "CM SERVICE REJECT" },
1229         { 0x23, "CM SERVICE ABORT" },
1230         { 0x24, "CM SERVICE REQUEST" },
1231         { 0x25, "CM SERVICE PROMPT" },
1232         { 0x26, "NOTIFICATION RESPONSE" },
1233         { 0x28, "CM RE-ESTABLISHMENT REQUEST" },
1234         { 0x29, "ABORT" },
1235         { 0x30, "MM NULL" },
1236         { 0x31, "MM STATUS" },
1237         { 0x32, "MM INFORMATION" },
1238         { 0, NULL }
1239 };
1240
1241 static const value_string mm_cc_mess[] = {
1242         { 0x00, "escape to nationally specific" },
1243 /*{ 0 x 0 0, "- - - Call establishment messages:" },*/
1244         { 0x01, "ALERTING" },
1245         { 0x08, "CALL CONFIRMED" },
1246         { 0x02, "CALL PROCEEDING" },
1247         { 0x07, "CONNECT" },
1248         { 0x0F, "CONNECT ACKNOWLEDGE" },
1249         { 0x0E, "EMERGENCY SETUP" },
1250         { 0x03, "PROGRESS" },
1251         { 0x04, "CC-ESTABLISHMENT" },
1252         { 0x06, "CC-ESTABLISHMENT CONFIRMED" },
1253         { 0x0B, "RECALL" },
1254         { 0x09, "START CC" },
1255         { 0x05, "SETUP" },
1256 /*{ 0 x 0 1, "- - - Call information phase messages:" },*/
1257         { 0x17, "MODIFY" },
1258         { 0x1F, "MODIFY COMPLETE" },
1259         { 0x13, "MODIFY REJECT" },
1260         { 0x10, "USER INFORMATION" },
1261         { 0x18, "HOLD" },
1262         { 0x19, "HOLD ACKNOWLEDGE" },
1263         { 0x1A, "HOLD REJECT" },
1264         { 0x1C, "RETRIEVE" },
1265         { 0x1D, "RETRIEVE ACKNOWLEDGE" },
1266         { 0x1E, "RETRIEVE REJECT" },
1267 /*{ 0 x 1 0, "- - - Call clearing messages:" },*/
1268         { 0x25, "DISCONNECT" },
1269         { 0x2D, "RELEASE" },
1270         { 0x2A, "RELEASE COMPLETE" },
1271 /*{ 0 x 1 1, "- - - Miscellaneous messages:" },*/
1272         { 0x39, "CONGESTION CONTROL" },
1273         { 0x3E, "NOTIFY" },
1274         { 0x3D, "STATUS" },
1275         { 0x34, "STATUS ENQUIRY" },
1276         { 0x35, "START DTMF" },
1277         { 0x31, "STOP DTMF" },
1278         { 0x32, "STOP DTMF ACKNOWLEDGE" },
1279         { 0x36, "START DTMF ACKNOWLEDGE" },
1280         { 0x37, "START DTMF REJECT" },
1281         { 0x3A, "FACILITY" },
1282         { 0, NULL }
1283 };
1284
1285 static const value_string mm_gprs_mess[] = {
1286         { 0x01, "Attach request" },
1287         { 0x02, "Attach accept" },
1288         { 0x03, "Attach complete" },
1289         { 0x04, "Attach reject" },
1290         { 0x05, "Detach request" },
1291         { 0x06, "Detach accept" },
1292         { 0x08, "Routing area update request" },
1293         { 0x09, "Routing area update accept" },
1294         { 0x0A, "Routing area update complete" },
1295         { 0x0B, "Routing area update reject" },
1296         { 0x10, "P-TMSI reallocation command" },
1297         { 0x11, "P-TMSI reallocation complete" },
1298         { 0x12, "Authentication and ciphering req" },
1299         { 0x13, "Authentication and ciphering resp" },
1300         { 0x14, "Authentication and ciphering rej" },
1301         { 0x15, "Identity request" },
1302         { 0x16, "Identity response" },
1303         { 0x20, "GMM status" },
1304         { 0x21, "GMM information" },
1305         { 0, NULL }
1306 };
1307
1308 static const value_string tft_code_type[] = {
1309         { 0, "Spare" },
1310         { 1, "Create new TFT" },
1311         { 2, "Delete existing TFT" },
1312         { 3, "Add packet filters to existing TFT" },
1313         { 4, "Replace packet filters in existing TFT" },
1314         { 5, "Delete packet filters from existing TFT" },
1315         { 6, "Reserved" },
1316         { 7, "Reserved" },
1317         { 0, NULL }
1318 };
1319
1320 static const value_string cdr_close_type[] = {
1321         { 0, "PDP release" },
1322         { 1, "Volume limit" },
1323         { 2, "Time limit" },
1324         { 3, "SGSN change" },
1325         { 4, "Max changes" },
1326         { 6, "Management" },
1327         { 7, "Abnormal" },
1328         { 0, NULL }
1329 };
1330
1331 static dissector_handle_t ip_handle;
1332 static dissector_handle_t ipv6_handle;
1333 static dissector_handle_t ppp_handle;
1334 static dissector_handle_t data_handle;
1335
1336 static int decode_gtp_cause             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1337 static int decode_gtp_imsi              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1338 static int decode_gtp_rai               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1339 static int decode_gtp_tlli              (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1340 static int decode_gtp_ptmsi             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1341 static int decode_gtp_qos_gprs          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1342 static int decode_gtp_reorder           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1343 static int decode_gtp_auth_tri          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1344 static int decode_gtp_map_cause         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1345 static int decode_gtp_ptmsi_sig         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1346 static int decode_gtp_ms_valid          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1347 static int decode_gtp_recovery          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1348 static int decode_gtp_sel_mode          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1349 static int decode_gtp_16                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1350 static int decode_gtp_17                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1351 static int decode_gtp_18                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1352 static int decode_gtp_19                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1353 static int decode_gtp_nsapi             (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1354 static int decode_gtp_ranap_cause       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1355 static int decode_gtp_rab_cntxt         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1356 static int decode_gtp_rp_sms            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1357 static int decode_gtp_rp                (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1358 static int decode_gtp_pkt_flow_id       (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1359 static int decode_gtp_chrg_char         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1360 static int decode_gtp_trace_ref         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1361 static int decode_gtp_trace_type        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1362 static int decode_gtp_ms_reason         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1363 static int decode_gtp_tr_comm           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1364 static int decode_gtp_chrg_id           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1365 static int decode_gtp_user_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1366 static int decode_gtp_mm_cntxt          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1367 static int decode_gtp_pdp_cntxt         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1368 static int decode_gtp_apn               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1369 static int decode_gtp_gsn_addr          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1370 static int decode_gtp_proto_conf        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1371 static int decode_gtp_msisdn            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1372 static int decode_gtp_qos_umts          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1373 static int decode_gtp_auth_qui          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1374 static int decode_gtp_tft               (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1375 static int decode_gtp_target_id         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1376 static int decode_gtp_utran_cont        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1377 static int decode_gtp_rab_setup         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1378 static int decode_gtp_hdr_list          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1379 static int decode_gtp_trigger_id        (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1380 static int decode_gtp_omc_id            (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1381 static int decode_gtp_chrg_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1382 static int decode_gtp_rel_pack          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1383 static int decode_gtp_can_pack          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1384 static int decode_gtp_data_req          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1385 static int decode_gtp_data_resp         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1386 static int decode_gtp_node_addr         (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1387 static int decode_gtp_priv_ext          (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1388 static int decode_gtp_unknown           (tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
1389
1390 typedef struct _gtp_opt {
1391         int   optcode;
1392 /*      char  *name; */
1393         int  (*decode)(tvbuff_t  *, int, packet_info *, proto_tree *);
1394 } gtp_opt_t;
1395
1396 static const gtp_opt_t gtpopt[] = {
1397         { GTP_EXT_CAUSE,        decode_gtp_cause },
1398         { GTP_EXT_IMSI,         decode_gtp_imsi },
1399         { GTP_EXT_RAI,          decode_gtp_rai },
1400         { GTP_EXT_TLLI,         decode_gtp_tlli },
1401         { GTP_EXT_PTMSI,        decode_gtp_ptmsi },
1402         { GTP_EXT_QOS_GPRS,     decode_gtp_qos_gprs },
1403         { GTP_EXT_REORDER,      decode_gtp_reorder },
1404         { GTP_EXT_AUTH_TRI,     decode_gtp_auth_tri },
1405         { GTP_EXT_MAP_CAUSE,    decode_gtp_map_cause },
1406         { GTP_EXT_PTMSI_SIG,    decode_gtp_ptmsi_sig },
1407         { GTP_EXT_MS_VALID,     decode_gtp_ms_valid },
1408         { GTP_EXT_RECOVER,      decode_gtp_recovery },
1409         { GTP_EXT_SEL_MODE,     decode_gtp_sel_mode },
1410         { GTP_EXT_16,           decode_gtp_16 },
1411         { GTP_EXT_17,           decode_gtp_17 },
1412         { GTP_EXT_18,           decode_gtp_18 },
1413         { GTP_EXT_19,           decode_gtp_19 },
1414         { GTP_EXT_NSAPI,        decode_gtp_nsapi },
1415         { GTP_EXT_RANAP_CAUSE,  decode_gtp_ranap_cause },
1416         { GTP_EXT_RAB_CNTXT,    decode_gtp_rab_cntxt },
1417         { GTP_EXT_RP_SMS,       decode_gtp_rp_sms },
1418         { GTP_EXT_RP,           decode_gtp_rp },
1419         { GTP_EXT_PKT_FLOW_ID,  decode_gtp_pkt_flow_id },
1420         { GTP_EXT_CHRG_CHAR,    decode_gtp_chrg_char },
1421         { GTP_EXT_TRACE_REF,    decode_gtp_trace_ref },
1422         { GTP_EXT_TRACE_TYPE,   decode_gtp_trace_type },
1423         { GTPv1_EXT_MS_REASON,  decode_gtp_ms_reason },
1424         { GTP_EXT_TR_COMM,      decode_gtp_tr_comm },
1425         { GTP_EXT_CHRG_ID,      decode_gtp_chrg_id },
1426         { GTP_EXT_USER_ADDR,    decode_gtp_user_addr },
1427         { GTP_EXT_MM_CNTXT,     decode_gtp_mm_cntxt },
1428         { GTP_EXT_PDP_CNTXT,    decode_gtp_pdp_cntxt },
1429         { GTP_EXT_APN,          decode_gtp_apn },
1430         { GTP_EXT_PROTO_CONF,   decode_gtp_proto_conf },
1431         { GTP_EXT_GSN_ADDR,     decode_gtp_gsn_addr },
1432         { GTP_EXT_MSISDN,       decode_gtp_msisdn },
1433         { GTP_EXT_QOS_UMTS,     decode_gtp_qos_umts },                          /* 3G */
1434         { GTP_EXT_AUTH_QUI,     decode_gtp_auth_qui },                          /* 3G */
1435         { GTP_EXT_TFT,          decode_gtp_tft },                               /* 3G */
1436         { GTP_EXT_TARGET_ID,    decode_gtp_target_id },                 /* 3G */
1437         { GTP_EXT_UTRAN_CONT,   decode_gtp_utran_cont },                        /* 3G */
1438         { GTP_EXT_RAB_SETUP,    decode_gtp_rab_setup },                 /* 3G */
1439         { GTP_EXT_HDR_LIST,     decode_gtp_hdr_list },                          /* 3G */
1440         { GTP_EXT_TRIGGER_ID,   decode_gtp_trigger_id },                        /* 3G */
1441         { GTP_EXT_OMC_ID,       decode_gtp_omc_id },                            /* 3G */
1442         { GTP_EXT_REL_PACK,     decode_gtp_rel_pack },                          /* charging */
1443         { GTP_EXT_CAN_PACK,     decode_gtp_can_pack },                  /* charging */
1444         { GTP_EXT_CHRG_ADDR,    decode_gtp_chrg_addr },
1445         { GTP_EXT_DATA_REQ,     decode_gtp_data_req },                          /* charging */
1446         { GTP_EXT_DATA_RESP,    decode_gtp_data_resp },                 /* charging */
1447         { GTP_EXT_NODE_ADDR,    decode_gtp_node_addr },
1448         { GTP_EXT_PRIV_EXT,     decode_gtp_priv_ext },
1449         { 0,                    decode_gtp_unknown }
1450 };
1451
1452 typedef struct {
1453         guint8          flags;
1454         guint8          message;
1455         guint16         length;
1456         guint16         seq_no;
1457         guint16         flow_label;
1458         guint8          sndcp_no;
1459         guint8          spare[3];
1460         guint8          tid[8];
1461 } _gtpv0_hdr;
1462
1463 typedef struct {
1464         guint8          flags;
1465         guint8          message;
1466         guint16         length;
1467         guint32         teid;
1468 } _gtpv1_hdr;
1469
1470 static struct gcdr_ {                           /* GCDR 118B */
1471         guint8          imsi[8];
1472         guint32         ggsnaddr;
1473         guint32         chrgid;
1474         guint32         sgsnaddr;
1475         gchar           apn[63];
1476         guint8          pdporg;
1477         guint8          pdptype;
1478         guint32         pdpaddr;
1479         guint8          addrflag;
1480         guint8          qos[3];
1481         guint32         uplink;
1482         guint32         downlink;
1483         guint32         timestamp;
1484         guint32         opening;
1485         guint32         duration;
1486         guint8          closecause;
1487         guint32         seqno;
1488         guint8          msisdn[9];
1489 } gcdr;
1490
1491 typedef struct change_ {
1492         guint8          change;
1493         guint32         time1;
1494         guint32         time2;
1495         guint32         uplink;
1496         guint32         downlink;
1497         guint8          qos_req[3];
1498         guint8          qos_neg[3];
1499 } change_t;
1500
1501 static struct _scdr {                           /* SCDR 277B */
1502         guint16         len;
1503         guint8          netini;
1504         guint8          anon;
1505         guint8          imsilen;
1506         guint8          imsi[8];
1507         guint8          imei[8];
1508         guint8          msisdnlen;
1509         guint8          msisdn[10];
1510         guint32         sgsnaddr;
1511         guint8          msclass_notused[12];
1512         guint8          msclass_caplen;
1513         guint8          msclass_cap;
1514         guint16         msclass_capomit;
1515         guint16         lac;
1516         guint8          rac;
1517         guint16         cid;
1518         guint32         chrgid;
1519         guint32         ggsnaddr;
1520         gchar           apn[64];
1521         guint8          pdporg;
1522         guint8          pdptype;
1523         guint32         pdpaddr;
1524         guint8          listind;
1525         change_t        change[5];
1526         guint32         timestamp;
1527         guint32         opening;
1528         guint32         duration;
1529         guint8          sgsnchange;
1530         guint8          closecause;
1531         guint8          diag1;
1532         guint8          diag2;
1533         guint8          diag3;
1534         guint8          diag4;
1535         guint32         diag5;
1536         guint32         seqno;
1537 } scdr;
1538
1539 typedef struct mmchange_ {
1540         guint16         lac;
1541         guint8          rac;
1542         guint16         cid;
1543         guint8          omit[8];
1544 } mmchange_t;
1545
1546 static struct _mcdr {                           /* MCDR 147B */
1547         guint16         len;
1548         guint8          imsilen;
1549         guint8          imsi[8];
1550         guint8          imei[8];
1551         guint8          msisdnlen;
1552         guint8          msisdn[10];
1553         guint32         sgsnaddr;
1554         guint8          msclass_notused[12];
1555         guint8          msclass_caplen;
1556         guint8          msclass_cap;
1557         guint16         msclass_capomit;
1558         guint16         lac;
1559         guint8          rac;
1560         guint16         cid;
1561         guint8          change_count;
1562         mmchange_t      change[5];
1563         guint32         timestamp;
1564         guint32         opening;
1565 /*      guint8          opening[8]; */
1566         guint32         duration;
1567         guint8          sgsnchange;
1568         guint8          closecause;
1569         guint8          diag1;
1570         guint8          diag2;
1571         guint8          diag3;
1572         guint8          diag4;
1573         guint32         diag5;
1574         guint32         seqno;
1575 } mcdr;
1576
1577 static struct _socdr {                                  /* SOCDR 80B */
1578         guint16         len;
1579         guint8          imsilen;
1580         guint8          imsi[8];
1581         guint8          imei[8];
1582         guint8          msisdnlen;
1583         guint8          msisdn[10];
1584         guint8          msclass_notused[12];
1585         guint8          msclass_caplen;
1586         guint8          msclass_cap;
1587         guint16         msclass_capomit;
1588         guint8          serv_centr[9];
1589         guint8          rec_ent[9];
1590         guint16         lac;
1591         guint8          rac;
1592         guint16         cid;
1593         guint32         time1;
1594         guint32         time2;
1595         guint8          messref;
1596         guint16         smsres;
1597 } socdr;
1598
1599
1600 static struct _stcdr {                                  /* STCDR 79B */
1601         guint16         len;
1602         guint8          imsilen;
1603         guint8          imsi[8];
1604         guint8          imei[8];
1605         guint8          msisdnlen;
1606         guint8          msisdn[10];
1607         guint8          msclass_notused[12];
1608         guint8          msclass_caplen;
1609         guint8          msclass_cap;
1610         guint16         msclass_capomit;
1611         guint8          serv_centr[9];
1612         guint8          rec_ent[9];
1613         guint16         lac;
1614         guint8          rac;
1615         guint16         cid;
1616         guint32         time1;
1617         guint32         time2;
1618         guint16         smsres;
1619 } stcdr;
1620
1621 static  guint8          gtp_version = 0;
1622 static  char            *yesno[] = { "False", "True" };
1623
1624 static void
1625 col_append_str_gtp(column_info *cinfo, gint el, gchar *proto_name) {
1626
1627         int     i;
1628         int     max_len;
1629         gchar   _tmp[COL_MAX_LEN];
1630
1631         max_len = COL_MAX_LEN;
1632
1633         for (i = 0; i < cinfo->num_cols; i++) {
1634                 if (cinfo->fmt_matx[i][el]) {
1635                         if (cinfo->col_data[i] != cinfo->col_buf[i]) {
1636
1637                                 strncpy(cinfo->col_buf[i], cinfo->col_data[i], max_len);
1638                                 cinfo->col_buf[i][max_len - 1] = '\0';
1639                         }
1640
1641                         _tmp[0] = '\0';
1642                         strcat(_tmp, proto_name);
1643                         strcat(_tmp, " <");
1644                         strcat(_tmp, cinfo->col_buf[i]);
1645                         strcat(_tmp, ">");
1646                         cinfo->col_buf[i][0] = '\0';
1647                         strcat(cinfo->col_buf[i], _tmp);
1648                         cinfo->col_data[i] = cinfo->col_buf[i];
1649                 }
1650         }
1651 }
1652
1653 static gchar *
1654 id_to_str(const guint8 *ad) {
1655
1656         static gchar    *str[17];
1657         gchar           *p;
1658         guint8          bits8to5, bits4to1, i;
1659         static const    gchar hex_digits[10] = "0123456789";
1660
1661         p = (gchar *)&str[17];
1662         *--p = '\0';
1663         i = 7;
1664         for (;;) {
1665                 bits8to5 = (ad[i] >> 4) & 0x0F;
1666                 bits4to1 = ad[i] & 0x0F;
1667                 if (bits8to5 < 0xA) *--p = hex_digits[bits8to5];
1668                 if (bits4to1 < 0xA) *--p = hex_digits[bits4to1];
1669                 if (i == 0) break;
1670                 i--;
1671         }
1672         return p;
1673 }
1674
1675 static gchar *
1676 imsi_to_str(const guint8 *ad) {
1677
1678         static gchar    *str[16];
1679         gchar           *p;
1680         guint8          i, j = 0;
1681         
1682         p = (gchar *)&str[0];
1683         for (i=0;i<8;i++) {
1684                 if ((ad[i] & 0x0F) <= 9) p[j++] = (ad[i] & 0x0F) + 0x30;
1685                 if (((ad[i] >> 4) & 0x0F) <= 9) p[j++] = ((ad[i] >> 4) & 0x0F) + 0x30;
1686         }
1687         p[j] = 0;
1688         
1689         return p;
1690 }
1691
1692 static gchar *
1693 msisdn_to_str(const guint8 *ad, int len) {
1694
1695         static gchar    *str[17];
1696         gchar           *p;
1697         guint8          bits8to5, bits4to1, i;
1698         static const    gchar hex_digits[16] = "0123456789      ";
1699
1700         p = (gchar *)&str[0];
1701         *p = '+';
1702         i = 1;
1703         for (;;) {
1704                 bits8to5 = (ad[i] >> 4) & 0x0F;
1705                 bits4to1 = ad[i] & 0x0F;
1706                 if (bits4to1 < 0xA) *++p = hex_digits[bits4to1];
1707                 if (bits8to5 < 0xA) *++p = hex_digits[bits8to5];
1708                 if (i == len-1) break;
1709                 i++;
1710         }
1711         *++p = '\0';
1712         return (gchar *)&str[0];
1713 }
1714
1715 static gchar *
1716 time_int_to_str (guint32 time)
1717 {
1718
1719         nstime_t        nstime;
1720
1721         nstime.secs = time;
1722         nstime.nsecs = 0;
1723
1724         return abs_time_to_str (&nstime);
1725 }
1726
1727 static gchar *
1728 rel_time_int_to_str (guint32 time)
1729 {
1730
1731         nstime_t        nstime;
1732
1733         nstime.secs = time;
1734         nstime.nsecs = 0;
1735
1736         return rel_time_to_str (&nstime);
1737 }
1738
1739 /* Next definitions and function check_field_presence checks if given field
1740  * in GTP packet is compliant with ETSI
1741  */
1742 typedef struct _header {
1743         guint8          code;
1744         guint8          presence;
1745 } ext_header;
1746
1747 typedef struct _message {
1748         guint8          code;
1749         ext_header      fields[32];
1750 } _gtp_mess_items;
1751
1752 /* ---------------------
1753  * GPRS messages
1754  * ---------------------*/
1755 static _gtp_mess_items gprs_mess_items[] = {
1756
1757 {
1758         GTP_MSG_ECHO_REQ, {
1759                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1760                 { 0,                    0 }
1761         }
1762 },
1763 {
1764         GTP_MSG_ECHO_RESP, {
1765                 { GTP_EXT_RECOVER,      GTP_MANDATORY },
1766                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1767                 { 0,                    0 }
1768         }
1769 },
1770 {
1771         GTP_MSG_VER_NOT_SUPP, {
1772                 { 0,                    0 }
1773         }
1774 },
1775 {
1776         GTP_MSG_NODE_ALIVE_REQ, {
1777                 { GTP_EXT_NODE_ADDR,    GTP_MANDATORY },
1778                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1779                 { 0,                    0 }
1780         }
1781 },
1782 {
1783         GTP_MSG_NODE_ALIVE_RESP, {
1784                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1785                 { 0,                    0 }
1786         }
1787 },
1788 {
1789         GTP_MSG_REDIR_REQ, {
1790                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1791                 { GTP_EXT_NODE_ADDR,    GTP_OPTIONAL },
1792                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1793                 { 0,                    0 }
1794         }
1795 },
1796 {
1797         GTP_MSG_REDIR_RESP, {
1798                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1799                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1800                 { 0,                    0 }
1801         }
1802 },
1803 {
1804         GTP_MSG_CREATE_PDP_REQ, {
1805                 { GTP_EXT_QOS_GPRS,     GTP_MANDATORY },
1806                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1807                 { GTP_EXT_SEL_MODE,     GTP_MANDATORY },
1808                 { GTP_EXT_FLOW_LABEL,   GTP_MANDATORY },
1809                 { GTP_EXT_FLOW_SIG,     GTP_MANDATORY },
1810                 { GTP_EXT_MSISDN,       GTP_MANDATORY },
1811                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1812                 { GTP_EXT_APN,          GTP_MANDATORY },
1813                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1814                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1815                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1816                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1817                 { 0,                    0 }
1818         }
1819 },
1820 {
1821         GTP_MSG_CREATE_PDP_RESP, {
1822                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1823                 { GTP_EXT_QOS_GPRS,     GTP_CONDITIONAL },
1824                 { GTP_EXT_REORDER,      GTP_CONDITIONAL },
1825                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1826                 { GTP_EXT_FLOW_LABEL,   GTP_CONDITIONAL },
1827                 { GTP_EXT_FLOW_SIG,     GTP_CONDITIONAL },
1828                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
1829                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
1830                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1831                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1832                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1833                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
1834                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1835                 { 0,                    0 }
1836         }
1837 },
1838 {
1839         GTP_MSG_UPDATE_PDP_REQ, {
1840                 { GTP_EXT_QOS_GPRS,     GTP_MANDATORY },
1841                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1842                 { GTP_EXT_FLOW_LABEL,   GTP_MANDATORY },
1843                 { GTP_EXT_FLOW_SIG,     GTP_MANDATORY },
1844                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1845                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1846                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1847                 { 0,                    0 },
1848         }
1849 },
1850 {
1851         GTP_MSG_UPDATE_PDP_RESP, {
1852                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1853                 { GTP_EXT_QOS_GPRS,     GTP_CONDITIONAL },
1854                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1855                 { GTP_EXT_FLOW_LABEL,   GTP_CONDITIONAL },
1856                 { GTP_EXT_FLOW_SIG,     GTP_CONDITIONAL },
1857                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
1858                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1859                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1860                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
1861                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1862                 { 0,                    0 }
1863         }
1864 },
1865 {
1866         GTP_MSG_DELETE_PDP_REQ, {
1867                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1868                 { 0,                    0 }
1869         }
1870 },
1871 {
1872         GTP_MSG_DELETE_PDP_RESP, {
1873                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1874                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1875                 { 0,                    0 },
1876         }
1877 },
1878 {
1879         GTP_MSG_CREATE_AA_PDP_REQ, {
1880                 { GTP_EXT_QOS_GPRS,     GTP_MANDATORY },
1881                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1882                 { GTP_EXT_SEL_MODE,     GTP_MANDATORY },
1883                 { GTP_EXT_FLOW_LABEL,   GTP_MANDATORY },
1884                 { GTP_EXT_FLOW_SIG,     GTP_MANDATORY },
1885                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1886                 { GTP_EXT_APN,          GTP_MANDATORY },
1887                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1888                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1889                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1890                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1891                 { 0,                    0 }
1892         }
1893 },
1894 {
1895         GTP_MSG_CREATE_AA_PDP_RESP, {
1896                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1897                 { GTP_EXT_QOS_GPRS,     GTP_CONDITIONAL },
1898                 { GTP_EXT_REORDER,      GTP_CONDITIONAL },
1899                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
1900                 { GTP_EXT_FLOW_LABEL,   GTP_CONDITIONAL },
1901                 { GTP_EXT_FLOW_SIG,     GTP_CONDITIONAL },
1902                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
1903                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
1904                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
1905                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1906                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
1907                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
1908                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1909                 { 0,                    0 }
1910         }
1911 },
1912 {
1913         GTP_MSG_DELETE_AA_PDP_REQ, {
1914                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1915                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1916                 { 0,                    0 }
1917         }
1918 },
1919 {
1920         GTP_MSG_DELETE_AA_PDP_RESP, {
1921                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1922                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1923                 { 0,                    0 }
1924         }
1925 },
1926 {
1927         GTP_MSG_ERR_IND, {
1928                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1929                 { 0,                    0 }
1930         }
1931 },
1932 {
1933         GTP_MSG_PDU_NOTIFY_REQ, {
1934                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1935                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1936                 { 0,                    0 }
1937         }
1938 },
1939 {
1940         GTP_MSG_PDU_NOTIFY_RESP, {
1941                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1942                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1943                 { 0,                    0 }
1944         }
1945 },
1946 {
1947         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
1948                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1949                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
1950                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1951                 { 0,                    0 }
1952         }
1953 },
1954 {
1955         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
1956                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1957                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1958                 { 0,                    0 }
1959         }
1960 },
1961 {
1962         GTP_MSG_SEND_ROUT_INFO_REQ, {
1963                 { GTP_EXT_IMSI,         GTP_MANDATORY },
1964                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1965                 { 0,                    0 }
1966         }
1967 },
1968 {
1969         GTP_MSG_SEND_ROUT_INFO_RESP, {
1970                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1971                 { GTP_EXT_IMSI,         GTP_MANDATORY },
1972                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
1973                 { GTP_EXT_MS_REASON,    GTP_OPTIONAL },
1974                 { GTP_EXT_GSN_ADDR,     GTP_OPTIONAL },
1975                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1976                 { 0,                    0 }
1977         }
1978 },
1979 {
1980         GTP_MSG_FAIL_REP_REQ, {
1981                 { GTP_EXT_IMSI,         GTP_MANDATORY },
1982                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1983                 { 0,                    0 }
1984         }
1985 },
1986 {
1987         GTP_MSG_FAIL_REP_RESP, {
1988                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
1989                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
1990                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1991                 { 0,                    0 }
1992         }
1993 },
1994 {
1995         GTP_MSG_MS_PRESENT_REQ, {
1996                 { GTP_EXT_IMSI,         GTP_MANDATORY },
1997                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
1998                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
1999                 { 0,                    0 }
2000         }
2001 },
2002 {
2003         GTP_MSG_MS_PRESENT_RESP, {
2004                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2005                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2006                 { 0,                    0 }
2007         }
2008 },
2009 {
2010         GTP_MSG_IDENT_REQ, {
2011                 { GTP_EXT_RAI,          GTP_MANDATORY },
2012                 { GTP_EXT_PTMSI,        GTP_MANDATORY },
2013                 { GTP_EXT_PTMSI_SIG,    GTP_OPTIONAL },
2014                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2015                 { 0,                    0 }
2016         }
2017 },
2018 {
2019         GTP_MSG_IDENT_RESP, {
2020                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2021                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2022                 { GTP_EXT_AUTH_TRI,     GTP_OPTIONAL },
2023                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2024                 { 0,                    0 }
2025         }
2026 },
2027 {
2028         GTP_MSG_SGSN_CNTXT_REQ, {
2029                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2030                 { GTP_EXT_RAI,          GTP_MANDATORY },
2031                 { GTP_EXT_TLLI,         GTP_MANDATORY },
2032                 { GTP_EXT_PTMSI_SIG,    GTP_OPTIONAL },
2033                 { GTP_EXT_MS_VALID,     GTP_OPTIONAL },
2034                 { GTP_EXT_FLOW_SIG,     GTP_MANDATORY },
2035                 { 0,                    0 }
2036         }
2037 },
2038 {
2039         GTP_MSG_SGSN_CNTXT_RESP, {
2040                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2041                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2042                 { GTP_EXT_FLOW_SIG,     GTP_CONDITIONAL },
2043                 { GTP_EXT_MM_CNTXT,     GTP_CONDITIONAL },
2044                 { GTP_EXT_PDP_CNTXT,    GTP_CONDITIONAL },
2045                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2046                 { 0,                    0 }
2047         }
2048 },
2049 {
2050         GTP_MSG_SGSN_CNTXT_ACK, {
2051                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2052                 { GTP_EXT_FLOW_II,      GTP_CONDITIONAL },
2053                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2054                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2055                 { 0,                    0 }
2056         }
2057 },
2058 {
2059         GTP_MSG_DATA_TRANSF_REQ, {
2060                 { GTP_EXT_TR_COMM,      GTP_MANDATORY },
2061                 { GTP_EXT_DATA_REQ,     GTP_CONDITIONAL },
2062                 { GTP_EXT_REL_PACK,     GTP_CONDITIONAL },
2063                 { GTP_EXT_CAN_PACK,     GTP_CONDITIONAL },
2064                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2065                 { 0,                    0 }
2066         }
2067 },
2068 {
2069         GTP_MSG_DATA_TRANSF_RESP, {
2070                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2071                 { GTP_EXT_DATA_RESP,    GTP_MANDATORY },
2072                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2073                 { 0,                    0 }
2074         }
2075 },
2076 {
2077         0, {
2078                 { 0,                    0 }
2079         }
2080 }
2081 };
2082
2083 /* -----------------------------
2084  * UMTS messages
2085  * -----------------------------*/
2086 static _gtp_mess_items umts_mess_items[] = {
2087
2088 {
2089         GTP_MSG_ECHO_REQ, {
2090                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2091                 { 0,                    0 }
2092         }
2093 },
2094 {
2095         GTP_MSG_ECHO_RESP, {
2096                 { GTP_EXT_RECOVER,      GTP_MANDATORY },
2097                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2098                 { 0,                    0 }
2099         }
2100 },
2101 {
2102         GTP_MSG_VER_NOT_SUPP, {
2103                 { 0,                    0 }
2104         }
2105 },
2106 {
2107         GTP_MSG_NODE_ALIVE_REQ, {
2108                 { GTP_EXT_NODE_ADDR,    GTP_MANDATORY },
2109                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2110                 { 0,                    0 }
2111         }
2112 },
2113 {
2114         GTP_MSG_NODE_ALIVE_RESP, {
2115                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2116                 { 0,                    0 }
2117         }
2118 },
2119 {
2120         GTP_MSG_REDIR_REQ, {
2121                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2122                 { GTP_EXT_NODE_ADDR,    GTP_OPTIONAL },
2123                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2124                 { 0,                    0 }
2125         }
2126 },
2127 {
2128         GTP_MSG_REDIR_REQ, {
2129                 { 0,                    0 }
2130         }
2131 },
2132 {
2133         GTP_MSG_CREATE_PDP_REQ, {
2134                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2135                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
2136                 { GTP_EXT_SEL_MODE,     GTP_CONDITIONAL },
2137                 { GTP_EXT_TEID,         GTP_MANDATORY },
2138                 { GTP_EXT_TEID_CP,      GTP_CONDITIONAL },
2139                 { GTP_EXT_NSAPI,        GTP_MANDATORY },
2140                 { GTP_EXT_NSAPI,        GTP_CONDITIONAL },
2141                 { GTP_EXT_CHRG_CHAR,    GTP_OPTIONAL },
2142                 { GTP_EXT_TRACE_REF,    GTP_OPTIONAL },
2143                 { GTP_EXT_TRACE_TYPE,   GTP_OPTIONAL },
2144                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
2145                 { GTP_EXT_APN,          GTP_CONDITIONAL },
2146                 { GTP_EXT_PROTO_CONF,   GTP_CONDITIONAL },
2147                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2148                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2149                 { GTP_EXT_MSISDN,       GTP_CONDITIONAL },
2150                 { GTP_EXT_QOS_UMTS,     GTP_MANDATORY },
2151                 { GTP_EXT_TFT,          GTP_CONDITIONAL },
2152                 { GTP_EXT_TRIGGER_ID,   GTP_OPTIONAL },
2153                 { GTP_EXT_OMC_ID,       GTP_OPTIONAL },
2154                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2155                 { 0,                    0 }
2156         }
2157 },
2158 {
2159         GTP_MSG_CREATE_PDP_RESP, {
2160                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2161                 { GTP_EXT_REORDER,      GTP_CONDITIONAL },
2162                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
2163                 { GTP_EXT_TEID,         GTP_CONDITIONAL },
2164                 { GTP_EXT_TEID_CP,      GTP_CONDITIONAL },
2165                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
2166                 { GTP_EXT_USER_ADDR,    GTP_CONDITIONAL },
2167                 { GTP_EXT_PROTO_CONF,   GTP_OPTIONAL },
2168                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2169                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2170                 { GTP_EXT_QOS_UMTS,     GTP_CONDITIONAL },
2171                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
2172                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2173                 { 0,                    0 }
2174         }
2175 },
2176 {       /* checked, SGSN -> GGSN */
2177         GTP_MSG_UPDATE_PDP_REQ, {
2178                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2179                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
2180                 { GTP_EXT_TEID,         GTP_MANDATORY },
2181                 { GTP_EXT_TEID_CP,      GTP_CONDITIONAL },
2182                 { GTP_EXT_NSAPI,        GTP_MANDATORY },
2183                 { GTP_EXT_TRACE_REF,    GTP_OPTIONAL },
2184                 { GTP_EXT_TRACE_TYPE,   GTP_OPTIONAL },
2185                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2186                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2187                 { GTP_EXT_QOS_UMTS,     GTP_MANDATORY },
2188                 { GTP_EXT_TFT,          GTP_OPTIONAL },
2189                 { GTP_EXT_TRIGGER_ID,   GTP_OPTIONAL },
2190                 { GTP_EXT_OMC_ID,       GTP_OPTIONAL },
2191                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2192                 { 0,                    0 }
2193         }
2194 },
2195 {       /* checked, GGSN -> SGSN */
2196         GTP_MSG_UPDATE_PDP_RESP, {
2197                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2198                 { GTP_EXT_RECOVER,      GTP_OPTIONAL },
2199                 { GTP_EXT_TEID,         GTP_CONDITIONAL },
2200                 { GTP_EXT_TEID_CP,      GTP_CONDITIONAL },
2201                 { GTP_EXT_CHRG_ID,      GTP_CONDITIONAL },
2202                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2203                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2204                 { GTP_EXT_QOS_UMTS,     GTP_CONDITIONAL },
2205                 { GTP_EXT_CHRG_ADDR,    GTP_OPTIONAL },
2206                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2207                 { 0,                    0 }
2208         }
2209 },
2210 {
2211         GTP_MSG_DELETE_PDP_REQ, {
2212                 { GTP_EXT_TEAR_IND,     GTP_CONDITIONAL },
2213                 { GTP_EXT_NSAPI,        GTP_MANDATORY },
2214                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2215                 { 0,                    0 }
2216         }
2217 },
2218 {
2219         GTP_MSG_DELETE_PDP_RESP, {
2220                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2221                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2222                 { 0,                    0 }
2223         }
2224 },
2225 {
2226         GTP_MSG_ERR_IND, {
2227                 { GTP_EXT_TEID,         GTP_MANDATORY },
2228                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2229                 { 0,                    0 }
2230         }
2231 },
2232 {
2233         GTP_MSG_PDU_NOTIFY_REQ, {
2234                 { GTP_EXT_IMSI,         GTP_MANDATORY },
2235                 { GTP_EXT_TEID_CP,      GTP_MANDATORY },
2236                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
2237                 { GTP_EXT_APN,          GTP_MANDATORY },
2238                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2239                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2240                 { 0,                    0 }
2241         }
2242 },
2243 {
2244         GTP_MSG_PDU_NOTIFY_RESP, {
2245                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2246                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2247                 { 0,                    0 }
2248         }
2249 },
2250 {
2251         GTP_MSG_PDU_NOTIFY_REJ_REQ, {
2252                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2253                 { GTP_EXT_TEID_CP,      GTP_MANDATORY },
2254                 { GTP_EXT_USER_ADDR,    GTP_MANDATORY },
2255                 { GTP_EXT_APN,          GTP_MANDATORY },
2256                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2257                 { 0,                    0 }
2258         }
2259 },
2260 {
2261         GTP_MSG_PDU_NOTIFY_REJ_RESP, {
2262                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2263                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2264                 { 0,                    0 }
2265         }
2266 },
2267 {
2268         GTP_MSG_SUPP_EXT_HDR, {
2269                 { GTP_EXT_HDR_LIST,     GTP_MANDATORY },
2270                 { 0,                    0 }
2271         }
2272 },
2273 {
2274         GTP_MSG_SEND_ROUT_INFO_REQ, {
2275                 { GTP_EXT_IMSI,         GTP_MANDATORY },
2276                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2277                 { 0,                    0 }
2278         }
2279 },
2280 {
2281         GTP_MSG_SEND_ROUT_INFO_RESP, {
2282                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2283                 { GTP_EXT_IMSI,         GTP_MANDATORY },
2284                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
2285                 { GTPv1_EXT_MS_REASON,  GTP_OPTIONAL },
2286                 { GTP_EXT_GSN_ADDR,     GTP_OPTIONAL },
2287                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2288                 { 0,                    0 }
2289         }
2290 },
2291 {
2292         GTP_MSG_FAIL_REP_REQ, {
2293                 { GTP_EXT_IMSI,         GTP_MANDATORY },
2294                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2295                 { 0,                    0 }
2296         }
2297 },
2298 {
2299         GTP_MSG_FAIL_REP_RESP, {
2300                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2301                 { GTP_EXT_MAP_CAUSE,    GTP_OPTIONAL },
2302                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2303                 { 0,                    0 }
2304         }
2305 },
2306 {
2307         GTP_MSG_MS_PRESENT_REQ, {
2308                 { GTP_EXT_IMSI,         GTP_MANDATORY },
2309                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2310                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2311                 { 0,                    0 }
2312         }
2313 },
2314 {
2315         GTP_MSG_MS_PRESENT_RESP, {
2316                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2317                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2318                 { 0,                    0 }
2319         }
2320 },
2321 {
2322         GTP_MSG_IDENT_REQ, {
2323                 { GTP_EXT_RAI,          GTP_MANDATORY },
2324                 { GTP_EXT_PTMSI,        GTP_MANDATORY },
2325                 { GTP_EXT_PTMSI_SIG,    GTP_CONDITIONAL },
2326                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2327                 { 0,                    0 }
2328         }
2329 },
2330 {
2331         GTP_MSG_IDENT_RESP, {
2332                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2333                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2334                 { GTP_EXT_AUTH_TRI,     GTP_CONDITIONAL },
2335                 { GTP_EXT_AUTH_QUI,     GTP_CONDITIONAL },
2336                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2337                 { 0,                    0 }
2338         }
2339 },
2340 {
2341         GTP_MSG_SGSN_CNTXT_REQ, {
2342                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2343                 { GTP_EXT_RAI,          GTP_MANDATORY },
2344                 { GTP_EXT_TLLI,         GTP_CONDITIONAL },
2345                 { GTP_EXT_PTMSI,        GTP_CONDITIONAL },
2346                 { GTP_EXT_PTMSI_SIG,    GTP_CONDITIONAL },
2347                 { GTP_EXT_MS_VALID,     GTP_OPTIONAL },
2348                 { GTP_EXT_TEID_CP,      GTP_MANDATORY },
2349                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2350                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2351                 { 0,                    0 }
2352         }
2353 },
2354 {
2355         GTP_MSG_SGSN_CNTXT_RESP, {
2356                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2357                 { GTP_EXT_IMSI,         GTP_CONDITIONAL },
2358                 { GTP_EXT_TEID_CP,      GTP_CONDITIONAL },
2359                 { GTP_EXT_RP_SMS,       GTP_OPTIONAL },
2360                 { GTP_EXT_RP,           GTP_OPTIONAL },
2361                 { GTP_EXT_PKT_FLOW_ID,  GTP_OPTIONAL },
2362                 { GTP_EXT_MM_CNTXT,     GTP_CONDITIONAL },
2363                 { GTP_EXT_PDP_CNTXT,    GTP_CONDITIONAL },
2364                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2365                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2366                 { 0,                    0 }
2367         }
2368 },
2369 {
2370         GTP_MSG_SGSN_CNTXT_ACK, {
2371                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2372                 { GTP_EXT_TEID_II,      GTP_CONDITIONAL },
2373                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2374                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2375                 { 0,                    0 }
2376         }
2377 },
2378 {
2379         GTP_MSG_FORW_RELOC_REQ, {
2380                 { GTP_EXT_IMSI,         GTP_MANDATORY },
2381                 { GTP_EXT_TEID_CP,      GTP_MANDATORY },
2382                 { GTP_EXT_RANAP_CAUSE,  GTP_MANDATORY },
2383                 { GTP_EXT_MM_CNTXT,     GTP_MANDATORY },
2384                 { GTP_EXT_PDP_CNTXT,    GTP_CONDITIONAL },
2385                 { GTP_EXT_GSN_ADDR,     GTP_MANDATORY },
2386                 { GTP_EXT_TARGET_ID,    GTP_MANDATORY },
2387                 { GTP_EXT_UTRAN_CONT,   GTP_MANDATORY },
2388                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2389                 { 0,                    0 }
2390         }
2391 },
2392 {
2393         GTP_MSG_FORW_RELOC_RESP, {
2394                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2395                 { GTP_EXT_TEID_CP,      GTP_CONDITIONAL },
2396                 { GTP_EXT_RANAP_CAUSE,  GTP_CONDITIONAL },
2397                 { GTP_EXT_GSN_ADDR,     GTP_CONDITIONAL },
2398                 { GTP_EXT_UTRAN_CONT,   GTP_OPTIONAL },
2399                 { GTP_EXT_RAB_SETUP,    GTP_CONDITIONAL },
2400                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2401                 { 0,                    0 }
2402         }
2403 },
2404 {
2405         GTP_MSG_FORW_RELOC_COMP, {
2406                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2407                 { 0,                    0 }
2408         }
2409 },
2410 {
2411         GTP_MSG_RELOC_CANCEL_REQ, {
2412                 { GTP_EXT_IMSI,         GTP_MANDATORY },
2413                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2414                 { 0,                    0 }
2415         }
2416 },
2417 {
2418         GTP_MSG_RELOC_CANCEL_RESP, {
2419                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2420                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2421                 { 0,                    0 }
2422         }
2423 },
2424 {
2425         GTP_MSG_FORW_RELOC_ACK, {
2426                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2427                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2428                 { 0,                    0 }
2429         }
2430 },
2431 {
2432         GTP_MSG_FORW_SRNS_CNTXT, {
2433                 { GTP_EXT_RAB_CNTXT,    GTP_MANDATORY },
2434                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2435                 { 0,                    0 }
2436         }
2437 },
2438 {
2439         GTP_MSG_FORW_SRNS_CNTXT_ACK, {
2440                 { GTP_EXT_CAUSE,        GTP_MANDATORY },
2441                 { GTP_EXT_PRIV_EXT,     GTP_OPTIONAL },
2442                 { 0,                    0 }
2443         }
2444 },
2445 {
2446         0, {
2447                 { 0,                    0 }
2448         }
2449 }
2450 };
2451
2452 static int
2453 check_field_presence(guint8 message, guint8 field, int *position) {
2454
2455         guint                   i = 0;
2456         _gtp_mess_items         *mess_items;
2457
2458         switch(gtp_version) {
2459                 case 0:
2460                         mess_items = gprs_mess_items;
2461                         break;
2462                 case 1:
2463                         mess_items = umts_mess_items;
2464                         break;
2465                 default:
2466                         return -2;
2467         }
2468
2469         while (mess_items[i].code) {
2470                 if (mess_items[i].code == message) {
2471
2472                         while (mess_items[i].fields[*position].code) {
2473                                 if (mess_items[i].fields[*position].code == field) {
2474                                         (*position)++;
2475                                         return 0;
2476                                 } else {
2477                                 if (mess_items[i].fields[*position].presence == GTP_MANDATORY) {
2478                                         return mess_items[i].fields[(*position)++].code;
2479                                 } else {
2480                                         (*position)++;
2481                                 }}
2482                         }
2483                         return -1;
2484                 }
2485                 i++;
2486         }
2487
2488         return -2;
2489 }
2490
2491 /* Decoders of fields in extension headers, each function returns no of bytes from field */
2492
2493 /* GPRS:        9.60 v7.6.0, chapter
2494  * UMTS:        29.060 v4.0, chapter
2495  */
2496 static int
2497 decode_gtp_cause(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2498
2499         guint8  cause;
2500
2501         cause = tvb_get_guint8(tvb, offset+1);
2502
2503         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_cause : hf_gtpv0_cause, tvb, offset, 2, cause);
2504
2505         return 2;
2506 }
2507
2508 /* GPRS:        9.60 v7.6.0, chapter 7.9.2
2509  * UMTS:        29.060 v4.0, chapter 7.7.2
2510  */
2511 static int
2512 decode_gtp_imsi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2513
2514         guint8  imsi_val[8];
2515         gchar   *imsi_str;
2516
2517         tvb_memcpy(tvb, imsi_val, offset+1, 8);
2518         imsi_str = imsi_to_str (imsi_val);
2519
2520         proto_tree_add_string(tree, gtp_version ? hf_gtpv1_imsi : hf_gtpv0_imsi, tvb, offset, 9, imsi_str);
2521
2522         return 9;
2523 }
2524
2525 /* GPRS:        9.60 v7.6.0, chapter 7.9.3
2526  * UMTS:        29.060 v4.0, chapter 7.7.3
2527  * TODO: Add details about MCC, MNC, LAC, RAC (show each digit) ?
2528  */
2529 static int
2530 decode_gtp_rai(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2531
2532         proto_tree      *ext_tree_rai;
2533         proto_item      *te;
2534         guint8          byte[3];
2535
2536         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_RAI, gtp_val, "Unknown message"));
2537         ext_tree_rai = proto_item_add_subtree(te, ett_gtp_rai);
2538
2539 /*      tvb_memcpy (tvb, (guint8 *)&byte, offset + 1, 3); */
2540         byte[1] = tvb_get_guint8 (tvb, offset + 1);
2541         byte[2] = tvb_get_guint8 (tvb, offset + 2);
2542         byte[3] = tvb_get_guint8 (tvb, offset + 3);
2543
2544
2545         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_mcc : hf_gtpv0_rai_mcc, tvb, offset+1, 2, (byte[1] & 0x0F) * 100 + ((byte[1] & 0xF0) >> 4) * 10  + (byte[2] & 0x0F ));
2546         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_mnc : hf_gtpv0_rai_mnc, tvb, offset+2, 2, ((byte[3] & 0xF0) >> 4 ) * 10  + (byte[3] & 0x0F));
2547         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_lac : hf_gtpv0_rai_lac, tvb, offset+4, 2, tvb_get_ntohs (tvb, offset+4));
2548         proto_tree_add_uint(ext_tree_rai, gtp_version ? hf_gtpv1_rai_rac : hf_gtpv0_rai_rac, tvb, offset+6, 1, tvb_get_guint8 (tvb, offset+6));
2549
2550         return 7;
2551 }
2552
2553 /* GPRS:        9.60 v7.6.0, chapter 7.9.4, page 39
2554  * UMTS:        29.060 v4.0, chapter 7.7.4, page 47
2555  */
2556 static int
2557 decode_gtp_tlli(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2558
2559         guint32 tlli;
2560
2561         tlli = tvb_get_ntohl(tvb, offset+1);
2562         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_tlli : hf_gtpv0_tlli, tvb, offset, 5, tlli);
2563
2564         return 5;
2565 }
2566
2567 /* GPRS:        9.60 v7.6.0, chapter 7.9.5, page 39
2568  * UMTS:        29.060 v4.0, chapter 7.7.5, page 47
2569  */
2570 static int
2571 decode_gtp_ptmsi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2572
2573         guint32 ptmsi;
2574
2575         ptmsi = tvb_get_ntohl(tvb, offset);
2576         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ptmsi : hf_gtpv0_ptmsi, tvb, offset, 5, ptmsi);
2577
2578         return 5;
2579 }
2580
2581 /* adjust - how many bytes before offset should be highlighted
2582  */
2583 static int
2584 decode_qos_gprs(tvbuff_t *tvb, int offset, proto_tree *tree, gchar* qos_str, guint8 adjust) {
2585
2586         guint8          spare1, delay, reliability, peak, spare2,  precedence, spare3, mean;
2587         proto_tree      *ext_tree_qos;
2588         proto_item      *te;
2589
2590         spare1 = tvb_get_guint8(tvb, offset) & 0xC0;
2591         delay = tvb_get_guint8(tvb, offset) & 0x38;
2592         reliability = tvb_get_guint8(tvb, offset) & 0x07;
2593         peak = tvb_get_guint8(tvb, offset+1) & 0xF0;
2594         spare2 = tvb_get_guint8(tvb, offset+1) & 0x08;
2595         precedence = tvb_get_guint8(tvb, offset+1) & 0x07;
2596         spare3 = tvb_get_guint8(tvb, offset+2) & 0xE0;
2597         mean = tvb_get_guint8(tvb, offset+2) & 0x1F;
2598
2599         te = proto_tree_add_text(tree, tvb, offset-adjust, 3+adjust, "%s: delay: %u, reliability: %u, peak: %u, precedence: %u, mean: %u",
2600                                                                         qos_str, delay, reliability, peak, precedence, mean);
2601         ext_tree_qos = proto_item_add_subtree(te, ett_gtp_qos);
2602
2603         if (adjust != 0) {
2604                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare1, tvb, offset, 1, spare1);
2605                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_delay, tvb, offset, 1, delay);
2606                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_reliability, tvb, offset, 1, reliability);
2607                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_peak, tvb, offset+1, 1, peak);
2608                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare2, tvb, offset+1, 1, spare2);
2609                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_precedence, tvb, offset+1, 1, precedence);
2610                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_spare3, tvb, offset+2, 1, spare3);
2611                 proto_tree_add_uint(ext_tree_qos, hf_gtpv0_qos_mean, tvb, offset+2, 1, mean);
2612         }
2613
2614         return 3;
2615 }
2616
2617 /* GPRS:        9.60 v7.6.0, chapter 7.9.6, page 39
2618  *              4.08
2619  *              3.60
2620  * UMTS:        not present
2621  * TODO:        check if length is included: ETSI 4.08 vs 9.60
2622  */
2623 static int
2624 decode_gtp_qos_gprs(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2625
2626         return (1+decode_qos_gprs(tvb, offset+1, tree, "Quality of Service", 1));
2627
2628 }
2629
2630 /* GPRS:        9.60 v7.6.0, chapter 7.9.7, page 39
2631  * UMTS:        29.060 v4.0, chapter 7.7.6, page 47
2632  */
2633 static int
2634 decode_gtp_reorder(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2635
2636         guint8  reorder;
2637
2638         reorder = tvb_get_guint8(tvb, offset+1) & 0x01;
2639         proto_tree_add_boolean(tree, gtp_version ? hf_gtpv1_reorder : hf_gtpv0_reorder, tvb, offset, 2, reorder);
2640
2641         return 2;
2642 }
2643
2644 /* GPRS:        9.60 v7.6.0, chapter 7.9.8, page 40
2645  *              4.08 v7.1.2, chapter 10.5.3.1+
2646  * UMTS:        29.060 v4.0, chapter 7.7.7
2647  * TODO: Add blurb support by registering items in the protocol registration
2648  */
2649 static int
2650 decode_gtp_auth_tri(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2651
2652         proto_tree      *ext_tree_auth_tri;
2653         proto_item      *te;
2654
2655         te = proto_tree_add_text(tree, tvb, offset, 29, val_to_str(GTP_EXT_AUTH_TRI, gtp_val, "Unknown message"));
2656         ext_tree_auth_tri = proto_item_add_subtree(tree, ett_gtp_auth_tri);
2657
2658         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+1, 16, "RAND: %s", tvb_bytes_to_str(tvb, offset+1, 16));
2659         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+17, 4, "SRES: %s", tvb_bytes_to_str(tvb, offset+17, 4));
2660         proto_tree_add_text(ext_tree_auth_tri, tvb, offset+21, 8, "Kc: %s", tvb_bytes_to_str(tvb, offset+21, 8));
2661
2662         return 1+16+4+8;
2663 }
2664
2665 /* GPRS:        9.60 v7.6.0, chapter 7.9.9, page 40
2666  *              9.02 v7.7.0, page 1090
2667  * UMTS:        29.060 v4.0, chapter 7.7.8, page 48
2668  *              29.002 v4.2.1, chapter 17.5, page 268
2669  */
2670 static int
2671 decode_gtp_map_cause(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2672
2673         guint8  map_cause;
2674
2675         map_cause = tvb_get_guint8(tvb, offset+1);
2676         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_map_cause : hf_gtpv0_map_cause, tvb, offset, 2, map_cause);
2677
2678         return 2;
2679 }
2680
2681 /* GPRS:        9.60 v7.6.0, chapter 7.9.10, page 41
2682  * UMTS:        29.060 v4.0, chapter 7.7.9, page 48
2683  */
2684 static int
2685 decode_gtp_ptmsi_sig(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2686
2687         guint32 ptmsi_sig;
2688
2689         ptmsi_sig = tvb_get_ntoh24(tvb, offset+1);
2690         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ptmsi_sig : hf_gtpv0_ptmsi_sig, tvb, offset, 4, ptmsi_sig);
2691
2692         return 4;
2693 }
2694
2695 /* GPRS:        9.60 v7.6.0, chapter 7.9.11, page 41
2696  * UMTS:        29.060 v4.0, chapter 7.7.10, page 49
2697  */
2698 static int
2699 decode_gtp_ms_valid(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2700
2701         guint8  ms_valid;
2702
2703         ms_valid = tvb_get_guint8(tvb, offset+1) & 0x01;
2704         proto_tree_add_boolean(tree, gtp_version ? hf_gtpv1_ms_valid : hf_gtpv0_ms_valid, tvb, offset, 2, ms_valid);
2705
2706         return 2;
2707 }
2708
2709 /* GPRS:        9.60 v7.6.0, chapter 7.9.12, page 41
2710  * UMTS:        29.060 v4.0, chapter 7.7.11, page 49
2711  */
2712 static int
2713 decode_gtp_recovery(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2714
2715         guint8  recovery;
2716
2717         recovery = tvb_get_guint8(tvb, offset+1);
2718         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_recovery : hf_gtpv0_recovery, tvb, offset, 2, recovery);
2719
2720         return 2;
2721 }
2722
2723 /* GPRS:        9.60 v7.6.0, chapter 7.9.13, page 42
2724  * UMTS:        29.060 v4.0, chapter 7.7.12, page 49
2725  */
2726 static int
2727 decode_gtp_sel_mode(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2728
2729         guint8  sel_mode;
2730
2731         sel_mode = tvb_get_guint8(tvb, offset+1) & 0x03;
2732         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_sel_mode : hf_gtpv0_sel_mode, tvb, offset, 2, sel_mode);
2733
2734         return 2;
2735 }
2736
2737 /* GPRS:        9.60 v7.6.0, chapter 7.9.14, page 42
2738  * UMTS:        29.060 v4.0, chapter 7.7.13, page 50
2739  */
2740 static int
2741 decode_gtp_16(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2742
2743         guint16 ext_flow_label;
2744         guint32 teid_data;
2745
2746         switch (gtp_version) {
2747                 case 0:
2748                         ext_flow_label = tvb_get_ntohs(tvb, offset+1);
2749                         proto_tree_add_uint(tree, hf_gtpv0_ext_flow_label, tvb, offset, 3, ext_flow_label);
2750
2751                         return 3;
2752                 case 1:
2753                         teid_data = tvb_get_ntohl(tvb, offset+1);
2754                         proto_tree_add_uint(tree, hf_gtpv1_teid_data, tvb, offset, 5, teid_data);
2755
2756                         return 5;
2757                 default:
2758                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label/TEID Data I : GTP version not supported");
2759
2760                         return 3;
2761         }
2762 }
2763
2764 /* GPRS:        9.60 v7.6.0, chapter 7.9.15, page 42
2765  * UMTS:        29.060 v4.0, chapter 7.7.14, page 42
2766  */
2767 static int
2768 decode_gtp_17(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2769
2770         guint16         flow_sig;
2771         guint32         teid_cp;
2772
2773         switch (gtp_version) {
2774                 case 0:
2775                         flow_sig = tvb_get_ntohs(tvb, offset+1);
2776                         proto_tree_add_uint(tree, hf_gtpv0_flow_sig, tvb, offset, 3, flow_sig);
2777
2778                         return 3;
2779                 case 1:
2780                         teid_cp = tvb_get_ntohl(tvb, offset+1);
2781                         proto_tree_add_uint(tree, hf_gtpv1_teid_cp, tvb, offset, 5, teid_cp);
2782
2783                         return 5;
2784                 default:
2785                         proto_tree_add_text(tree, tvb, offset, 1, "Flow label signalling/TEID control plane : GTP version not supported");
2786
2787                         return 3;
2788         }
2789 }
2790
2791 /* GPRS:        9.60 v7.6.0, chapter 7.9.16, page 42
2792  * UMTS:        29.060 v4.0, chapter 7.7.15, page 51
2793  */
2794 static int
2795 decode_gtp_18(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2796
2797         guint16         flow_ii;
2798         guint32         teid_ii;
2799         proto_tree      *ext_tree_flow_ii;
2800         proto_item      *te;
2801
2802         switch (gtp_version) {
2803                 case 0:
2804                         te = proto_tree_add_text(tree, tvb, offset, 4, val_to_str(GTP_EXT_FLOW_II, gtp_val, "Unknown message"));
2805                         ext_tree_flow_ii = proto_item_add_subtree(te, ett_gtp_flow_ii);
2806
2807                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv0_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2808
2809                         flow_ii = tvb_get_ntohs(tvb, offset+2);
2810                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv0_flow_ii, tvb, offset+2, 2, flow_ii);
2811
2812                         return 4;
2813                 case 1:
2814                         te = proto_tree_add_text(tree, tvb, offset, 6, val_to_str(GTP_EXT_TEID_II, gtp_val, "Unknown message"));
2815                         ext_tree_flow_ii = proto_item_add_subtree(te, ett_gtp_flow_ii);
2816
2817                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv1_nsapi, tvb, offset+1, 1, tvb_get_guint8(tvb, offset+1) & 0x0F);
2818
2819
2820                         teid_ii = tvb_get_ntohl(tvb, offset+2);
2821                         proto_tree_add_uint(ext_tree_flow_ii, hf_gtpv1_teid_ii, tvb, offset+2, 4, teid_ii);
2822
2823                         return 6;
2824                 default:
2825                         proto_tree_add_text(tree, tvb, offset, 1, "Flow data II/TEID Data II : GTP Version not supported");
2826
2827                         return 4;
2828         }
2829 }
2830
2831 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A, page 43
2832  * UMTS:        29.060 v4.0, chapter 7.7.16, page 51
2833  * Check if all ms_reason types are included
2834  */
2835 static int
2836 decode_gtp_19(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2837
2838         guint8          field19;
2839
2840         field19 = tvb_get_guint8(tvb, offset+1);
2841
2842         switch (gtp_version) {
2843                 case 0:
2844                         proto_tree_add_uint(tree, hf_gtpv0_ms_reason, tvb, offset, 2, field19);
2845
2846                         break;
2847                 case 1:
2848                         proto_tree_add_boolean(tree, hf_gtpv1_tear_ind, tvb, offset, 2, field19 & 0x01);
2849
2850                         break;
2851                 default:
2852                         proto_tree_add_text(tree, tvb, offset, 1, "Information Element Type = 19 : GTP Version not supported");
2853
2854                         break;
2855         }
2856
2857         return 2;
2858 }
2859
2860 /* GPRS:        not present
2861  * UMTS:        29.060 v4.0, chapter 7.7.17, page 51
2862  */
2863 static int
2864 decode_gtp_nsapi(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2865
2866         guint8          nsapi;
2867
2868         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
2869         proto_tree_add_uint(tree, hf_gtpv1_nsapi, tvb, offset, 2, nsapi);
2870
2871         return 2;
2872 }
2873
2874 /* GPRS:        not present
2875  * UMTS:        29.060 v4.0, chapter 7.7.18, page 52
2876  */
2877 static int
2878 decode_gtp_ranap_cause(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2879
2880         guint8          ranap;
2881
2882         ranap = tvb_get_guint8(tvb, offset+1);
2883
2884         if(ranap > 0 && ranap <=64)
2885         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Radio Network Layer Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2886
2887         if(ranap > 64 && ranap <=80)
2888         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Transport Layer Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2889
2890         if(ranap > 80 && ranap <=96)
2891         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (NAS Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2892
2893         if(ranap > 96 && ranap <=112)
2894         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Protocol Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2895
2896         if(ranap > 112 && ranap <=128)
2897         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Miscellaneous Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2898
2899         if(ranap > 128 && ranap <=255)
2900         proto_tree_add_uint_format(tree, hf_gtpv1_ranap_cause, tvb, offset, 2, ranap, "%s (Non-standard Cause) : %s (%u)", val_to_str(GTP_EXT_RANAP_CAUSE, gtp_val, "Unknown"), val_to_str(ranap, ranap_cause_type, "Unknown RANAP Cause"), ranap);
2901
2902         return 2;
2903 }
2904
2905 /* GPRS:        not present
2906  * UMTS:        29.060 v4.0, chapter 7.7.19, page 52
2907  */
2908 static int
2909 decode_gtp_rab_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2910
2911         guint8          nsapi, dl_pdcp_seq, ul_pdcp_seq;
2912         guint16         dl_gtpu_seq, ul_gtpu_seq;
2913         proto_tree      *ext_tree_rab_cntxt;
2914         proto_item      *te;
2915
2916         te = proto_tree_add_text(tree, tvb, offset, 8, val_to_str(GTP_EXT_RAB_CNTXT, gtp_val, "Unknown message"));
2917         ext_tree_rab_cntxt = proto_item_add_subtree(te, ett_gtp_rab_cntxt);
2918
2919         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
2920         dl_gtpu_seq = tvb_get_ntohs(tvb, offset+2);
2921         ul_gtpu_seq = tvb_get_ntohs(tvb, offset+4);
2922         dl_pdcp_seq = tvb_get_guint8(tvb, offset+6);
2923         ul_pdcp_seq = tvb_get_guint8(tvb, offset+7);
2924
2925         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_nsapi, tvb, offset+1, 1, nsapi);
2926         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_gtpu_dn, tvb, offset+2, 2, dl_gtpu_seq);
2927         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_gtpu_up, tvb, offset+4, 2, ul_gtpu_seq);
2928         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_pdu_dn, tvb, offset+6, 1, dl_pdcp_seq);
2929         proto_tree_add_uint(ext_tree_rab_cntxt, hf_gtpv1_rab_pdu_up, tvb, offset+7, 1, ul_pdcp_seq);
2930
2931         return 8;
2932 }
2933
2934
2935 /* GPRS:        not present
2936  * UMTS:        29.060 v4.0, chapter 7.7.20, page 53
2937  */
2938 static int
2939 decode_gtp_rp_sms(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2940
2941         guint8          rp_sms;
2942
2943         rp_sms = tvb_get_guint8(tvb, offset+1) & 0x07;
2944         proto_tree_add_uint(tree, hf_gtpv1_rp_sms, tvb, offset, 2, rp_sms);
2945
2946         return 2;
2947 }
2948
2949 /* GPRS:        not present
2950  * UMTS:        29.060 v4.0, chapter 7.7.21, page 53
2951  */
2952 static int
2953 decode_gtp_rp(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2954
2955         proto_tree      *ext_tree_rp;
2956         proto_item      *te;
2957         guint8          nsapi, rp, spare;
2958
2959         nsapi = tvb_get_guint8(tvb, offset+1) & 0xF0;
2960         spare = tvb_get_guint8(tvb, offset+1) & 0x08;
2961         rp = tvb_get_guint8(tvb, offset+1) & 0x07;
2962
2963         te = proto_tree_add_uint_format(tree, hf_gtpv1_rp, tvb, offset, 2, rp, "Radio Priority for NSAPI(%u) : %u", nsapi, rp);
2964         ext_tree_rp = proto_item_add_subtree(tree, ett_gtp_rp);
2965
2966         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp_nsapi, tvb, offset+1, 1, nsapi);
2967         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp_spare, tvb, offset+1, 1, spare);
2968         proto_tree_add_uint(ext_tree_rp, hf_gtpv1_rp, tvb, offset+1, 1, rp);
2969
2970         return 2;
2971 }
2972
2973 /* GPRS:        not present
2974  * UMTS:        29.060 v4.0, chapter 7.7.22, page 53
2975  */
2976 static int
2977 decode_gtp_pkt_flow_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
2978
2979         proto_tree      *ext_tree_pkt_flow_id;
2980         proto_item      *te;
2981         guint8          nsapi, pkt_flow_id;
2982
2983         nsapi = tvb_get_guint8(tvb, offset+1) & 0x0F;
2984         pkt_flow_id = tvb_get_guint8(tvb, offset+2);
2985
2986         te = proto_tree_add_uint_format(tree, hf_gtpv1_pkt_flow_id, tvb, offset, 3, pkt_flow_id, "Packet Flow ID for NSAPI(%u) : %u", nsapi, pkt_flow_id);
2987         ext_tree_pkt_flow_id = proto_item_add_subtree(tree, ett_gtp_pkt_flow_id);
2988
2989         proto_tree_add_uint(ext_tree_pkt_flow_id, hf_gtpv1_nsapi, tvb, offset+1, 1, nsapi);
2990         proto_tree_add_uint_format(ext_tree_pkt_flow_id, hf_gtpv1_pkt_flow_id, tvb, offset+2, 1, pkt_flow_id, "%s : %u", val_to_str(GTP_EXT_PKT_FLOW_ID, gtp_val, "Unknown message"), pkt_flow_id);
2991
2992         return 3;
2993 }
2994
2995 /* GPRS:        not present
2996  * UMTS:        29.060 v4.0, chapter 7.7.23, page 53
2997  * TODO: Differenciate these uints?
2998  */
2999 static int
3000 decode_gtp_chrg_char(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3001
3002         guint16         chrg_char;
3003         proto_item      *te;
3004         proto_tree      *ext_tree_chrg_char;
3005
3006         chrg_char = tvb_get_ntohs(tvb, offset+1);
3007
3008         te = proto_tree_add_text(tree, tvb, offset, 3, "%s: %x", val_to_str(GTP_EXT_CHRG_CHAR, gtp_val, "Unknown message"), chrg_char);
3009         ext_tree_chrg_char = proto_item_add_subtree(te, ett_gtp_chrg_char);
3010
3011         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_s, tvb, offset+1, 2, chrg_char);
3012         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_n, tvb, offset+1, 2, chrg_char);
3013         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_p, tvb, offset+1, 2, chrg_char);
3014         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_f, tvb, offset+1, 2, chrg_char);
3015         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_h, tvb, offset+1, 2, chrg_char);
3016         proto_tree_add_uint(ext_tree_chrg_char, hf_gtpv1_chrg_char_r, tvb, offset+1, 2, chrg_char);
3017
3018         return 3;
3019 }
3020
3021 /* GPRS:        not present
3022  * UMTS:        29.060 v4.0, chapter 7.7.24, page
3023  */
3024 static int
3025 decode_gtp_trace_ref(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3026
3027         guint16         trace_ref;
3028
3029         trace_ref = tvb_get_ntohs(tvb, offset+1);
3030
3031         proto_tree_add_uint(tree, hf_gtpv1_trace_ref, tvb, offset, 3, trace_ref);
3032
3033         return 3;
3034 }
3035
3036 /* GPRS:        not present
3037  * UMTS:        29.060 v4.0, chapter 7.7.25, page
3038  */
3039 static int
3040 decode_gtp_trace_type(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3041
3042         guint16         trace_type;
3043
3044         trace_type = tvb_get_ntohs(tvb, offset+1);
3045
3046         proto_tree_add_uint(tree, hf_gtpv1_trace_type, tvb, offset, 3, trace_type);
3047
3048         return 3;
3049 }
3050
3051 /* GPRS:        9.60 v7.6.0, chapter 7.9.16A
3052  * UMTS:        29.060 v4.0, chapter 7.7.25A, page
3053  */
3054 static int
3055 decode_gtp_ms_reason(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3056
3057         guint8          reason;
3058
3059         reason = tvb_get_guint8(tvb, offset+1);
3060
3061         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_ms_reason : hf_gtpv0_ms_reason, tvb, offset, 2, reason);
3062
3063         return 2;
3064 }
3065
3066
3067 /* GPRS:        12.15 v7.6.0, chapter 7.3.3, page 45
3068  * UMTS:        33.015
3069  */
3070 static int
3071 decode_gtp_tr_comm(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3072
3073         guint8  tr_command;
3074
3075         tr_command = tvb_get_guint8(tvb, offset+1);
3076
3077         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_tr_comm : hf_gtpv0_tr_comm, tvb, offset, 2, tr_command);
3078
3079         return 2;
3080 }
3081
3082 /* GPRS:        9.60 v7.6.0, chapter 7.9.17, page 43
3083  * UMTS:        29.060 v4.0, chapter 7.7.26, page 55
3084  */
3085 static int
3086 decode_gtp_chrg_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3087
3088         guint32 chrg_id;
3089
3090         chrg_id = tvb_get_ntohl(tvb, offset+1);
3091         proto_tree_add_uint(tree, gtp_version ? hf_gtpv1_chrg_id : hf_gtpv0_chrg_id, tvb, offset, 5, chrg_id);
3092
3093         return 5;
3094 }
3095
3096 /* GPRS:        9.60 v7.6.0, chapter 7.9.18, page 43
3097  * UMTS:        29.060 v4.0, chapter 7.7.27, page 55
3098  */
3099 static int
3100 decode_gtp_user_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3101
3102         guint16         length;
3103         guint8          pdp_typ, pdp_org;
3104         guint32         addr_ipv4;
3105         struct          e_in6_addr addr_ipv6;
3106         proto_tree      *ext_tree_user;
3107         proto_item      *te;
3108
3109
3110         length = tvb_get_ntohs(tvb, offset+1);
3111         pdp_org = tvb_get_guint8(tvb, offset+3) & 0x0F;
3112         pdp_typ = tvb_get_guint8(tvb, offset+4);
3113
3114         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s (%s/%s)",
3115             val_to_str(GTP_EXT_USER_ADDR, gtp_val, "Unknown message"),
3116             val_to_str(pdp_org, pdp_org_type, "Unknown PDP Organization"),
3117             val_to_str(pdp_typ, pdp_type, "Unknown PDP Type"));
3118         ext_tree_user = proto_item_add_subtree(te, ett_gtp_user);
3119
3120         proto_tree_add_text(ext_tree_user, tvb, offset+1, 2, "Length : %u", length);
3121         proto_tree_add_uint(ext_tree_user, gtp_version ? hf_gtpv1_user_addr_pdp_org : hf_gtpv0_user_addr_pdp_org, tvb, offset+3, 1, pdp_org);
3122         proto_tree_add_uint(ext_tree_user, gtp_version ? hf_gtpv1_user_addr_pdp_type : hf_gtpv0_user_addr_pdp_type, tvb, offset+4, 1, pdp_typ);
3123
3124         if (length == 2) {
3125                 if (pdp_org == 0 && pdp_typ == 1)
3126                         proto_item_append_text(te, " (Point to Point Protocol)");
3127                 else if (pdp_typ == 2)
3128                         proto_item_append_text(te, " (Octet Stream Protocol)");
3129         } else if (length > 2) {
3130                 switch (pdp_typ) {
3131                         case 0x21:
3132                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+5, sizeof addr_ipv4);
3133                                 proto_tree_add_ipv4(ext_tree_user, gtp_version ? hf_gtpv1_user_ipv4 : hf_gtpv0_user_ipv4, tvb, offset+5, 4, addr_ipv4);
3134                                 proto_item_append_text(te, " : %s", ip_to_str((guint8 *)&addr_ipv4));
3135                                 break;
3136                         case 0x57:
3137                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+5, sizeof addr_ipv6);
3138                                 proto_tree_add_ipv6(ext_tree_user, gtp_version ? hf_gtpv1_user_ipv6 : hf_gtpv0_user_ipv6, tvb, offset+5, 16, (guint8 *)&addr_ipv6);
3139                                 proto_item_append_text(te, " : %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3140                                 break;
3141                 }
3142         } else
3143                 proto_item_append_text(te, " : empty PDP Address");
3144
3145         return 3+length;
3146 }
3147
3148 static int
3149 decode_triplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count) {
3150
3151         proto_tree      *ext_tree_trip;
3152         proto_item      *te_trip;
3153         guint16         i;
3154
3155         for (i=0;i<count;i++) {
3156                 te_trip = proto_tree_add_text(tree, tvb, offset+i*28, 28, "Triplet no%x", i);
3157                 ext_tree_trip = proto_item_add_subtree(te_trip, ett_gtp_trip);
3158
3159                 proto_tree_add_text(ext_tree_trip, tvb, offset+i*28, 16, "RAND: %s", tvb_bytes_to_str(tvb, offset+i*28, 16));
3160                 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));
3161                 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));
3162         }
3163
3164         return count*28;
3165 }
3166
3167 /* adjust - how many bytes before quintuplet should be highlighted
3168  */
3169 static int
3170 decode_quintuplet(tvbuff_t *tvb, int offset, proto_tree *tree, guint16 count, guint8 adjust) {
3171
3172         proto_tree      *ext_tree_quint;
3173         proto_item      *te_quint;
3174         guint16         q_len, xres_len, auth_len, q_offset, i;
3175
3176         q_offset = 0;
3177
3178         for (i=0;i<count;i++) {
3179
3180                 offset = offset + q_offset;
3181
3182                 q_len = tvb_get_ntohs(tvb, offset);
3183
3184                 te_quint = proto_tree_add_text(tree, tvb, offset-adjust, q_len+adjust, "Quintuplet #%x", i);
3185                 ext_tree_quint = proto_item_add_subtree(te_quint, ett_gtp_quint);
3186
3187                 proto_tree_add_text(ext_tree_quint, tvb, offset, 2, "Length: %x", q_len);
3188                 proto_tree_add_text(ext_tree_quint, tvb, offset+2, 16, "RAND: %s", tvb_bytes_to_str(tvb, offset+2, 16));
3189                 xres_len = tvb_get_ntohs(tvb, offset+18);
3190                 proto_tree_add_text(ext_tree_quint, tvb, offset+18, 2, "XRES length: %u", xres_len);
3191                 proto_tree_add_text(ext_tree_quint, tvb, offset+20, xres_len, "XRES: %s", tvb_bytes_to_str(tvb, offset+20, xres_len));
3192                 proto_tree_add_text(ext_tree_quint, tvb, offset+20+xres_len, 16, "Quintuplet ciphering key: %s", tvb_bytes_to_str(tvb, offset+20+xres_len, 16));
3193                 proto_tree_add_text(ext_tree_quint, tvb, offset+36+xres_len, 16, "Quintuplet integrity key: %s", tvb_bytes_to_str(tvb, offset+36+xres_len, 16));
3194                 auth_len = tvb_get_ntohs(tvb, offset+52+xres_len);
3195                 proto_tree_add_text(ext_tree_quint, tvb, offset+52+xres_len, 2, "Authentication length: %u", auth_len);
3196                 proto_tree_add_text(ext_tree_quint, tvb, offset+54+xres_len, auth_len, "AUTH: %s", tvb_bytes_to_str(tvb, offset+54+xres_len, auth_len));
3197
3198                 q_offset = q_offset + q_len + 2;
3199         }
3200
3201         return q_offset;
3202 }
3203
3204 /* GPRS:        9.60 v7.6.0, chapter 7.9.19 page
3205  * UMTS:        29.060 v4.0, chapter 7.7.28 page 57
3206  * TODO:        - check if for quintuplets first 2 bytes are length, according to AuthQuint
3207  *              - finish displaying last 3 parameters
3208  */
3209 static int
3210 decode_gtp_mm_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3211
3212         guint16         length, quint_len, net_cap, con_len;
3213         guint8          cksn, count, sec_mode, cipher, trans_id, proto_disc, message, drx_split, drx_len, drx_ccch, non_drx_timer;
3214         proto_tree      *ext_tree_mm;
3215         proto_item      *te;
3216
3217         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_MM_CNTXT, gtp_val, "Unknown message"));
3218         ext_tree_mm = proto_item_add_subtree(te, ett_gtp_mm);
3219
3220         length = tvb_get_ntohs(tvb, offset+1);
3221         if (length < 1) return 3;
3222
3223         cksn = tvb_get_guint8(tvb, offset+3) & 0x07;
3224         sec_mode = (tvb_get_guint8(tvb, offset+4) >> 6) & 0x03;
3225         count = (tvb_get_guint8(tvb, offset+4) >> 3) & 0x07;
3226         cipher = tvb_get_guint8(tvb, offset+4) & 0x07;
3227
3228         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 2, "Length: %x", length);
3229         proto_tree_add_text(ext_tree_mm, tvb, offset+3, 1, "Ciphering Key Sequence Number: %u", cksn);
3230         if (gtp_version != 0) {
3231                 proto_tree_add_text(ext_tree_mm, tvb, offset+3, 1, "Security type: %u", sec_mode);
3232         } else {
3233                 sec_mode = 1;
3234         }
3235
3236         proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "No of triplets: %u", count);
3237
3238         switch (sec_mode) {
3239                 case 0:
3240                         if (cipher == 0) {
3241                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3242                         } else {
3243                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3244                         }
3245                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 16, "Ciphering key CK: %s", tvb_bytes_to_str(tvb, offset+5, 16));
3246                         proto_tree_add_text(ext_tree_mm, tvb, offset+21, 16, "Integrity key CK: %s", tvb_bytes_to_str(tvb, offset+21, 16));
3247                         quint_len = tvb_get_ntohs(tvb, offset+37);
3248                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: %x", quint_len);
3249
3250                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count, 0) + 39;
3251
3252
3253                         break;
3254                 case 1:
3255                         if (cipher == 0) {
3256                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3257                         } else {
3258                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3259                         }
3260                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %s", tvb_bytes_to_str(tvb, offset+5, 8));
3261
3262                         offset = offset + decode_triplet(tvb, offset+13, ext_tree_mm, count) + 13;
3263
3264                         break;
3265                 case 2:
3266                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 16, "Ciphering key CK: %s", tvb_bytes_to_str(tvb, offset+5, 16));
3267                         proto_tree_add_text(ext_tree_mm, tvb, offset+21, 16, "Integrity key CK: %s", tvb_bytes_to_str(tvb, offset+21, 16));
3268                         quint_len = tvb_get_ntohs(tvb, offset+37);
3269                         proto_tree_add_text(ext_tree_mm, tvb, offset+37, 2, "Quintuplets length: %x", quint_len);
3270
3271                         offset = offset + decode_quintuplet(tvb, offset+39, ext_tree_mm, count, 0) + 39;
3272
3273                         break;
3274                 case 3:
3275                         if (cipher == 0) {
3276                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: no ciphering");
3277                         } else {
3278                                 proto_tree_add_text(ext_tree_mm, tvb, offset+4, 1, "Ciphering: GEA/%u", cipher);
3279                         }
3280                         proto_tree_add_text(ext_tree_mm, tvb, offset+5, 8, "Ciphering key Kc: %s", tvb_bytes_to_str(tvb, offset+5, 8));
3281                         quint_len = tvb_get_ntohs(tvb, offset+13);
3282                         proto_tree_add_text(ext_tree_mm, tvb, offset+13, 2, "Quintuplets length: %x", quint_len);
3283
3284                         offset = offset + decode_quintuplet(tvb, offset+15, ext_tree_mm, count, 0) + 15;
3285
3286                         break;
3287                 default:
3288                         break;
3289         }
3290
3291
3292         drx_split = tvb_get_guint8(tvb, offset);
3293         drx_len = (tvb_get_guint8(tvb, offset+1) >> 4) & 0x0F;
3294         drx_ccch = (tvb_get_guint8(tvb, offset+1) >> 3) & 0x01;
3295         non_drx_timer = tvb_get_guint8(tvb, offset+1) & 0x07;
3296
3297         net_cap = tvb_get_ntohs(tvb, offset+2);
3298         con_len = tvb_get_ntohs(tvb, offset+4);
3299
3300         proto_tree_add_text(ext_tree_mm, tvb, offset, 1, "DRX: split PG cycle code: %u", drx_split);
3301         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: CN specific DRX cycle length coefficient: %u", drx_len);
3302         proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: split PG cycle on CCCH supported by MS: %s", yesno[drx_ccch]);
3303         if (non_drx_timer == 0) {
3304                 proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: no non-DRX mode after transfer state");
3305         } else {
3306                 proto_tree_add_text(ext_tree_mm, tvb, offset+1, 1, "DRX: max sec non-DRX mode after transfer state:  2^%u", non_drx_timer-1);
3307         }
3308
3309         proto_tree_add_text(ext_tree_mm, tvb, offset+2, 2, "MS network capability: %u", net_cap);
3310         proto_tree_add_text(ext_tree_mm, tvb, offset+4, 2, "Container length: %u", con_len);
3311
3312         if (con_len > 0) {
3313                 trans_id = (tvb_get_guint8(tvb, offset+6) >> 4) & 0x0F;
3314                 proto_disc = tvb_get_guint8(tvb, offset+6) & 0x0F;
3315                 message = tvb_get_guint8(tvb, offset+7);
3316         }
3317
3318         return 3+length;
3319 }
3320
3321 /* Function to extract the value of an hexadecimal octet. Only the lower
3322  * nybble will be non-zero in the output.
3323  * */
3324 static guint8 hex2dec (guint8 x)
3325 {
3326         if ((x >= 'a') && (x <= 'f'))
3327                 x = x - 'a' + 10;
3328         else if ((x >= 'A') && (x <= 'F'))
3329                 x = x - 'A' + 10;
3330         else if ((x >= '0') && (x <= '9'))
3331                 x = x - '0';
3332         else
3333                 x = 0;
3334         return x;
3335 }
3336
3337 /* Wrapper function to add UTF-8 decoding for QoS attributes in
3338  * RADIUS messages.
3339  * */
3340 static guint8 wrapped_tvb_get_guint8(
3341                                          tvbuff_t *tvb, int offset, int type)
3342 {
3343         if (type == 2)
3344                 return (hex2dec(tvb_get_guint8(tvb, offset)) << 4
3345                                         | hex2dec(tvb_get_guint8(tvb, offset + 1)));
3346         else
3347                 return tvb_get_guint8(tvb, offset);
3348 }
3349
3350  /* WARNING : actually length is coded on 2 octets for QoS profile but on 1 octet for PDP Context!
3351   * so type means length of length :-)
3352   *
3353   * WARNING :) type does not mean length of length any more... see below for
3354   * type = 3!
3355  */
3356 int
3357 decode_qos_umts(tvbuff_t *tvb, int offset, proto_tree *tree, gchar* qos_str, guint8 type) {
3358
3359         guint8          length;
3360         guint8          al_ret_priority;
3361         guint8          delay, reliability, peak, precedence, mean, spare1, spare2, spare3;
3362         guint8          traf_class, del_order, del_err_sdu;
3363         guint8          max_sdu_size, max_ul, max_dl;
3364         guint8          res_ber, sdu_err_ratio;
3365         guint8          trans_delay, traf_handl_prio;
3366         guint8          guar_ul, guar_dl;
3367         proto_tree      *ext_tree_qos;
3368         proto_item      *te;
3369         int             mss, mu, md, gu, gd;
3370
3371         /* Will keep if the input is UTF-8 encoded (as in RADIUS messages).
3372          * If 1, input is *not* UTF-8 encoded (i.e. each input octet corresponds
3373          * to one byte to be dissected).
3374          * If 2, input is UTF-8 encoded (i.e. each *couple* of input octets
3375          * corresponds to one byte to be dissected)
3376          * */
3377         guint8      utf8_type = 1;
3378
3379         /* In RADIUS messages the QoS has a version field of two octets prepended.
3380          * As of 29.061 v.3.a.0, there is an hyphen between "Release Indicator" and
3381          * <release specific QoS IE UTF-8 encoding>. Even if it sounds rather
3382          * inconsistent and unuseful, I will check hyphen presence here and
3383          * will signal its presence.
3384          * */
3385         guint8          version_buffer[2];
3386         guint8      hyphen;
3387
3388         /* Will keep the value that will be returned
3389          * */
3390         int             retval = 0;
3391         
3392         switch (type) {
3393                 case 1:
3394                         length = tvb_get_guint8 (tvb, offset);
3395                         te = proto_tree_add_text (tree, tvb, offset, length + 1, "%s", qos_str);
3396                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3397                         proto_tree_add_text (ext_tree_qos, tvb, offset, 1, "Length: %u", length);
3398                         offset++;
3399                         retval = length + 1;
3400                         break;
3401                 case 2:
3402                         length = tvb_get_ntohs (tvb, offset + 1);
3403                         te = proto_tree_add_text(tree, tvb, offset, length + 3, "%s", qos_str);
3404                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3405                         proto_tree_add_text (ext_tree_qos, tvb, offset + 1, 2, "Length: %u", length);
3406                         offset += 3;            /* +1 because of first 0x86 byte for UMTS QoS */
3407                         retval = length + 3;
3408                         break;
3409                 case 3:
3410                         /* For QoS inside RADIUS Client messages from GGSN */
3411                         utf8_type = 2;
3412
3413                         /* The field in the RADIUS message starts one byte before :) */
3414                         length = tvb_get_guint8 (tvb, offset);
3415                         te = proto_tree_add_text (tree, tvb, offset - 1, length, "%s", qos_str);
3416
3417                         ext_tree_qos = proto_item_add_subtree (te, ett_gtp_qos);
3418                         version_buffer[0] = tvb_get_guint8(tvb, offset + 1);
3419                         version_buffer[1] = tvb_get_guint8(tvb, offset + 2);
3420                         proto_tree_add_text (ext_tree_qos, tvb, offset + 1, 2, "Version: %c%c", version_buffer[0], version_buffer[1]);
3421
3422                         /* Hyphen handling */
3423                         hyphen = tvb_get_guint8(tvb, offset + 3);
3424                         if (hyphen == ((guint8) '-'))
3425                         {
3426                                 /* Hyphen is present, put in protocol tree */
3427                                 proto_tree_add_text (ext_tree_qos, tvb, offset + 3, 1, "Hyphen separator: -");
3428                                 offset++; /* "Get rid" of hyphen */
3429                         }
3430                         
3431                         /* Now, we modify offset here and in order to use type later
3432                          * effectively.*/
3433                         offset += 2;
3434                         retval = length + 3;      /* Actually, will be ignored. */
3435                         break;
3436                 default:
3437                         /* XXX - what should we do with the length here? */
3438                         length = 0;
3439                         retval = 0;
3440                         ext_tree_qos = NULL;
3441                         break;
3442         }
3443
3444         /* In RADIUS messages there is no allocation-retention priority
3445          * so I don't need to wrap the following call to tvb_get_guint8
3446          * */
3447         al_ret_priority = tvb_get_guint8 (tvb, offset);
3448
3449         /* All calls are wrapped to take into account the possibility that the
3450          * input is UTF-8 encoded. If utf8_type is equal to 1, the final value
3451          * of the offset will be the same as in the previous version of this
3452          * dissector, and the wrapped function will serve as a dumb wrapper;
3453          * otherwise, if utf_8_type is 2, the offset is correctly shifted by
3454          * two bytes for needed shift, and the wrapped function will unencode
3455          * two values from the input.
3456          * */
3457         spare1 = wrapped_tvb_get_guint8(tvb, offset+(1 - 1) * utf8_type + 1, utf8_type) & 0xC0;
3458         delay = wrapped_tvb_get_guint8(tvb, offset+(1 - 1) * utf8_type + 1, utf8_type) & 0x38;
3459         reliability = wrapped_tvb_get_guint8(tvb, offset+(1 - 1) * utf8_type + 1, utf8_type) & 0x07;
3460         peak = wrapped_tvb_get_guint8(tvb, offset+(2 - 1) * utf8_type + 1, utf8_type) & 0xF0;
3461         spare2 = wrapped_tvb_get_guint8(tvb, offset+(2 - 1) * utf8_type + 1, utf8_type) & 0x08;
3462         precedence = wrapped_tvb_get_guint8(tvb, offset+(2 - 1) * utf8_type + 1, utf8_type) & 0x07;
3463         spare3 = wrapped_tvb_get_guint8(tvb, offset+(3 - 1) * utf8_type + 1, utf8_type) & 0xE0;
3464         mean = wrapped_tvb_get_guint8(tvb, offset+(3 - 1) * utf8_type + 1, utf8_type) & 0x1F;
3465
3466         /* In RADIUS messages there is no allocation-retention priority */
3467         if (type != 3)
3468                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_al_ret_priority, tvb, offset, 1, al_ret_priority);
3469
3470         /* All additions must take care of the fact that QoS fields in RADIUS
3471          * messages are UTF-8 encoded, so we have to use the same trick as above.
3472          * */
3473         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare1, tvb, offset+(1 - 1) * utf8_type + 1, utf8_type, spare1);
3474         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_delay, tvb, offset+(1 - 1) * utf8_type + 1, utf8_type, delay);
3475         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_reliability, tvb, offset+(1 - 1) * utf8_type + 1, utf8_type, reliability);
3476         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_peak, tvb, offset+(2 - 1) * utf8_type + 1, utf8_type, peak);
3477         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare2, tvb, offset+(2 - 1) * utf8_type + 1, utf8_type, spare2);
3478         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_precedence, tvb, offset+(2 - 1) * utf8_type + 1, utf8_type, precedence);
3479         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_spare3, tvb, offset+(3 - 1) * utf8_type + 1, utf8_type, spare3);
3480         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_mean, tvb, offset+(3 - 1) * utf8_type + 1, utf8_type, mean);
3481
3482         if (length > 4) {
3483
3484                 /* See above for the need of wrapping
3485                  * */
3486                 traf_class = wrapped_tvb_get_guint8(tvb, offset+(4 - 1) * utf8_type + 1, utf8_type) & 0xE0;
3487                 del_order = wrapped_tvb_get_guint8(tvb, offset+(4 - 1) * utf8_type + 1, utf8_type) & 0x18;
3488                 del_err_sdu = wrapped_tvb_get_guint8(tvb, offset+(4 - 1) * utf8_type + 1, utf8_type) & 0x07;
3489                 max_sdu_size = wrapped_tvb_get_guint8(tvb, offset+(5 - 1) * utf8_type + 1, utf8_type);
3490                 max_ul = wrapped_tvb_get_guint8(tvb, offset+(6 - 1) * utf8_type + 1, utf8_type);
3491                 max_dl = wrapped_tvb_get_guint8(tvb, offset+(7 - 1) * utf8_type + 1, utf8_type);
3492                 res_ber = wrapped_tvb_get_guint8(tvb, offset+(8 - 1) * utf8_type + 1, utf8_type) & 0xF0;
3493                 sdu_err_ratio = wrapped_tvb_get_guint8(tvb, offset+(8 - 1) * utf8_type + 1, utf8_type) & 0x0F;
3494                 trans_delay = wrapped_tvb_get_guint8(tvb, offset+(9 - 1) * utf8_type + 1, utf8_type) & 0xFC;
3495                 traf_handl_prio = wrapped_tvb_get_guint8(tvb, offset+(9 - 1) * utf8_type + 1, utf8_type) & 0x03;
3496                 guar_ul = wrapped_tvb_get_guint8(tvb, offset+(10 - 1) * utf8_type + 1, utf8_type);
3497                 guar_dl = wrapped_tvb_get_guint8(tvb, offset+(11 - 1) * utf8_type + 1, utf8_type);
3498
3499                 /* See above comments for the changes
3500                  * */
3501                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_traf_class, tvb, offset+(4 - 1) * utf8_type + 1, utf8_type, traf_class);
3502                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_del_order, tvb, offset+(4 - 1) * utf8_type + 1, utf8_type, del_order);
3503                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_del_err_sdu, tvb, offset+(4 - 1) * utf8_type + 1, utf8_type, del_err_sdu);
3504                 if (max_sdu_size == 0 || max_sdu_size > 150)
3505                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_sdu_size, tvb, offset+(5 - 1) * utf8_type + 1, utf8_type, max_sdu_size);
3506                 if (max_sdu_size > 0 && max_sdu_size <= 150) {
3507                         mss = max_sdu_size*10;
3508                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_sdu_size, tvb, offset+(5 - 1) * utf8_type + 1, utf8_type, mss, "Maximum SDU size : %u octets", mss);
3509                 }
3510
3511                 if(max_ul == 0 || max_ul == 255)
3512                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, max_ul);
3513                 if(max_ul > 0 && max_ul <= 63)
3514                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, max_ul, "Maximum bit rate for uplink : %u kbps", max_ul);
3515                 if(max_ul > 63 && max_ul <=127) {
3516                         mu = 64 + ( max_ul - 64 ) * 8;
3517                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, mu, "Maximum bit rate for uplink : %u kbps", mu);
3518                 }
3519
3520                 if(max_ul > 127 && max_ul <=254) {
3521                         mu = 576 + ( max_ul - 128 ) * 64;
3522                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_ul, tvb, offset+(6 - 1) * utf8_type + 1, utf8_type, mu, "Maximum bit rate for uplink : %u kbps", mu);
3523                 }
3524
3525                 if(max_dl == 0 || max_dl == 255)
3526                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, max_dl);
3527                 if(max_dl > 0 && max_dl <= 63)
3528                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, max_dl, "Maximum bit rate for downlink : %u kbps", max_dl);
3529                 if(max_dl > 63 && max_dl <=127) {
3530                         md = 64 + ( max_dl - 64 ) * 8;
3531                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, md, "Maximum bit rate for downlink : %u kbps", md);
3532                 }
3533                 if(max_dl > 127 && max_dl <=254) {
3534                         md = 576 + ( max_dl - 128 ) * 64;
3535                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_max_dl, tvb, offset+(7 - 1) * utf8_type + 1, utf8_type, md, "Maximum bit rate for downlink : %u kbps", md);
3536                 }
3537
3538                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_res_ber, tvb, offset+(8 - 1) * utf8_type + 1, utf8_type, res_ber);
3539                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_sdu_err_ratio, tvb, offset+(8 - 1) * utf8_type + 1, utf8_type, sdu_err_ratio);
3540                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_trans_delay, tvb, offset+(9 - 1) * utf8_type + 1, utf8_type, trans_delay);
3541                 proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_traf_handl_prio, tvb, offset+(9 - 1) * utf8_type + 1, utf8_type, traf_handl_prio);
3542
3543                 if(guar_ul == 0 || guar_ul == 255)
3544                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, guar_ul);
3545                 if(guar_ul > 0 && guar_ul <= 63)
3546                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, guar_ul, "Guaranteed bit rate for uplink : %u kbps", guar_ul);
3547                 if(guar_ul > 63 && guar_ul <=127) {
3548                         gu = 64 + ( guar_ul - 64 ) * 8;
3549                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, gu, "Guaranteed bit rate for uplink : %u kbps", gu);
3550                 }
3551                 if(guar_ul > 127 && guar_ul <=254) {
3552                         gu = 576 + ( guar_ul - 128 ) * 64;
3553                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_ul, tvb, offset+(10 - 1) * utf8_type + 1, utf8_type, gu, "Guaranteed bit rate for uplink : %u kbps", gu);
3554                 }
3555
3556                 if(guar_dl == 0 || guar_dl == 255)
3557                         proto_tree_add_uint(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, guar_dl);
3558                 if(guar_dl > 0 && guar_dl <= 63)
3559                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, guar_dl, "Guaranteed bit rate for downlink : %u kbps", guar_dl);
3560                 if(guar_dl > 63 && guar_dl <=127) {
3561                         gd = 64 + ( guar_dl - 64 ) * 8;
3562                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, gd, "Guaranteed bit rate for downlink : %u kbps", gd);
3563                 }
3564                 if(guar_dl > 127 && guar_dl <=254) {
3565                         gd = 576 + ( guar_dl - 128 ) * 64;
3566                         proto_tree_add_uint_format(ext_tree_qos, hf_gtpv1_qos_guar_dl, tvb, offset+(11 - 1) * utf8_type + 1, utf8_type, gd, "Guaranteed bit rate for downlink : %u kbps", gd);
3567                 }
3568
3569         }
3570
3571         return retval;
3572 }
3573
3574 static void
3575 decode_apn(tvbuff_t *tvb, int offset, guint16 length, proto_tree *tree) {
3576
3577         gchar   *apn = NULL;
3578         guint8  name_len, tmp;
3579
3580         if (length > 0) {
3581                 apn = g_malloc (length + 1);
3582                 name_len = tvb_get_guint8 (tvb, offset);
3583
3584                 if (name_len < 0x20) {
3585                         tvb_memcpy (tvb, apn, offset + 1, length);
3586                         for (;;) {
3587                                 if (name_len >= length - 1) break;
3588                                 tmp = name_len;
3589                                 name_len = name_len + apn[tmp] + 1;
3590                                 apn[tmp] = '.';
3591                         }
3592                 } else {
3593                         tvb_memcpy (tvb, apn, offset, length);
3594                 }
3595
3596                 apn[length-1] = '\0';
3597                 proto_tree_add_string(tree, gtp_version ? hf_gtpv1_apn : hf_gtpv0_apn, tvb, offset, length, apn);
3598                 g_free(apn);
3599         }
3600 }
3601
3602 /* GPRS:        9.60 v7.6.0, chapter 7.9.20
3603  * UMTS:        29.060 v4.0, chapter 7.7.29
3604  * TODO:        unify addr functions
3605  */
3606 static int
3607 decode_gtp_pdp_cntxt(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3608
3609         guint8          ggsn_addr_len, apn_len, trans_id, vaa, order, nsapi, sapi, pdu_send_no, pdu_rec_no, pdp_cntxt_id,
3610                         pdp_type_org, pdp_type_num, pdp_addr_len;
3611         guint16         length, sn_down, sn_up, up_flow;
3612         guint32         addr_ipv4, up_teid, up_teid_cp;
3613         struct  e_in6_addr addr_ipv6;
3614         proto_tree      *ext_tree_pdp;
3615         proto_item      *te;
3616
3617         length = tvb_get_ntohs(tvb, offset+1);
3618
3619         te = proto_tree_add_text(tree, tvb, offset, length+3, val_to_str(GTP_EXT_PDP_CNTXT, gtp_val, "Unknown message"));
3620         ext_tree_pdp = proto_item_add_subtree(te, ett_gtp_pdp);
3621
3622         vaa = (tvb_get_guint8(tvb, offset+3) >> 6) & 0x01;
3623         order = (tvb_get_guint8(tvb, offset+3) >> 4) & 0x01;
3624         nsapi =  tvb_get_guint8(tvb, offset+3) & 0x0F;
3625         sapi = tvb_get_guint8(tvb, offset+4) & 0x0F;
3626
3627         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "VPLMN address allowed: %s", yesno[vaa]);
3628         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "Reordering required: %s", yesno[order]);
3629         proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 1, "NSAPI: %u", nsapi);
3630         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "SAPI: %u", sapi);
3631
3632         switch (gtp_version) {
3633                 case 0:
3634                         decode_qos_gprs(tvb, offset+5, ext_tree_pdp, "QoS subscribed", 0);
3635                         decode_qos_gprs(tvb, offset+8, ext_tree_pdp, "QoS requested", 0);
3636                         decode_qos_gprs(tvb, offset+11, ext_tree_pdp, "QoS negotiated", 0);
3637                         offset = offset + 14;
3638                         break;
3639                 case 1:
3640                         offset = offset + 5;
3641                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS subscribed", 1);
3642                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS requested", 1);
3643                         offset = offset + decode_qos_umts(tvb, offset, ext_tree_pdp, "QoS negotiated", 1);
3644                         break;
3645                 default:
3646                         break;
3647         }
3648
3649         sn_down = tvb_get_ntohs(tvb, offset);
3650         sn_up = tvb_get_ntohs(tvb, offset+2);
3651         pdu_send_no = tvb_get_guint8(tvb, offset+4);
3652         pdu_rec_no = tvb_get_guint8(tvb, offset+5);
3653
3654         proto_tree_add_text(ext_tree_pdp, tvb, offset, 2, "Sequence number down: %u", sn_down);
3655         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 2, "Sequence number up: %u", sn_up);
3656         proto_tree_add_text(ext_tree_pdp, tvb, offset+4, 1, "Send N-PDU number: %u", pdu_send_no);
3657         proto_tree_add_text(ext_tree_pdp, tvb, offset+5, 1, "Receive N-PDU number: %u", pdu_rec_no);
3658
3659         switch (gtp_version) {
3660                 case 0:
3661                         up_flow = tvb_get_ntohs(tvb, offset+6);
3662                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 2, "Uplink flow label signalling: %u", up_flow);
3663                         offset = offset + 8;
3664                         break;
3665                 case 1:
3666                         up_teid = tvb_get_ntohl(tvb, offset+6);
3667                         up_teid_cp = tvb_get_ntohl(tvb, offset+10);
3668                         pdp_cntxt_id = tvb_get_guint8(tvb, offset+14);
3669                         proto_tree_add_text(ext_tree_pdp, tvb, offset+6, 4, "Uplink TEID: %x", up_teid);
3670                         proto_tree_add_text(ext_tree_pdp, tvb, offset+10, 4, "Uplink TEID control plane: %x", up_teid_cp);
3671                         proto_tree_add_text(ext_tree_pdp, tvb, offset+14, 1, "PDP context identifier: %u", pdp_cntxt_id);
3672                         offset = offset + 15;
3673                         break;
3674                 default:
3675                         break;
3676         }
3677
3678         pdp_type_org = tvb_get_guint8(tvb, offset) & 0x0F;
3679         pdp_type_num = tvb_get_guint8(tvb, offset+1);
3680         pdp_addr_len = tvb_get_guint8(tvb, offset+2);
3681
3682         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "PDP organization: %s", val_to_str(pdp_type_org, pdp_type, "Unknown PDP org"));
3683         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 1, "PDP type: %s", val_to_str(pdp_type_num, pdp_org_type, "Unknown PDP type"));
3684         proto_tree_add_text(ext_tree_pdp, tvb, offset+2, 1, "PDP address length: %u", pdp_addr_len);
3685
3686         if (pdp_addr_len > 0) {
3687                 switch (pdp_type_num) {
3688                         case 0x21:
3689                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
3690                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 4, "PDP address: %s", ip_to_str((guint8 *)&addr_ipv4));
3691                                 break;
3692                         case 0x57:
3693                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
3694                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+3, 16, "PDP address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3695                                 break;
3696                         default:
3697                                 break;
3698                 }
3699         }
3700
3701         offset = offset + 3 + pdp_addr_len;
3702
3703         ggsn_addr_len = tvb_get_guint8(tvb, offset);
3704         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN address length: %u", ggsn_addr_len);
3705
3706         switch (ggsn_addr_len) {
3707                 case 4:
3708                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+1, sizeof addr_ipv4);
3709                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN address: %s", ip_to_str((guint8 *)&addr_ipv4));
3710                         break;
3711                 case 16:
3712                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+1, sizeof addr_ipv6);
3713                         proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3714                         break;
3715                 default:
3716                         break;
3717         }
3718
3719         offset = offset + 1 + ggsn_addr_len;
3720
3721         if (gtp_version == 1) {
3722
3723                 ggsn_addr_len = tvb_get_guint8(tvb, offset);
3724                 proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "GGSN 2 address length: %u", ggsn_addr_len);
3725
3726                 switch (ggsn_addr_len) {
3727                         case 4:
3728                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+1, sizeof addr_ipv4);
3729                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 4, "GGSN 2 address: %s", ip_to_str((guint8 *)&addr_ipv4));
3730                                 break;
3731                         case 16:
3732                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+1, sizeof addr_ipv6);
3733                                 proto_tree_add_text(ext_tree_pdp, tvb, offset+1, 16, "GGSN 2 address: %s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3734                                 break;
3735                         default:
3736                                 break;
3737                 }
3738                 offset = offset + 1 + ggsn_addr_len;
3739
3740         }
3741
3742         apn_len = tvb_get_guint8(tvb, offset);
3743         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "APN length: %u", apn_len);
3744         decode_apn(tvb, offset+1, apn_len, ext_tree_pdp);
3745
3746         offset = offset + 1 + apn_len;
3747
3748         trans_id = tvb_get_guint8(tvb, offset);
3749         proto_tree_add_text(ext_tree_pdp, tvb, offset, 1, "Transaction identifier: %u", trans_id);
3750
3751         return 3+length;
3752 }
3753
3754 /* GPRS:        9.60, v7.6.0, chapter 7.9.21
3755  * UMTS:        29.060, v4.0, chapter 7.7.30
3756  */
3757 static int
3758 decode_gtp_apn(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3759
3760         guint16         length;
3761         proto_tree      *ext_tree_apn;
3762         proto_item      *te;
3763
3764         length = tvb_get_ntohs(tvb, offset+1);
3765
3766         te = proto_tree_add_text(tree, tvb, offset, length+3, val_to_str(GTP_EXT_APN, gtp_val, "Unknown field"));
3767         ext_tree_apn = proto_item_add_subtree(te, ett_gtp_apn);
3768
3769         proto_tree_add_text(ext_tree_apn, tvb, offset+1, 2, "APN length : %u", length);
3770         decode_apn(tvb, offset+3, length, ext_tree_apn);
3771
3772         return 3+length;
3773 }
3774
3775 /* GPRS:        9.60 v7.6.0, chapter 7.9.22
3776  *              4.08 v. 7.1.2, chapter 10.5.6.3 (p.580)
3777  * UMTS:        29.060 v4.0, chapter 7.7.31
3778  *              24.008, v4.2, chapter 10.5.6.3
3779  */
3780 int
3781 decode_gtp_proto_conf(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) {
3782
3783         guint16         length, proto_offset;
3784         guint16         proto_id;
3785         guint8          conf, proto_len, cnt = 1;
3786         tvbuff_t        *next_tvb;
3787         proto_tree      *ext_tree_proto;
3788         proto_item      *te;
3789         gboolean        save_writable;
3790
3791         length = tvb_get_ntohs(tvb, offset + 1);
3792
3793         te = proto_tree_add_text(tree, tvb, offset, length + 3, val_to_str(GTP_EXT_PROTO_CONF, gtp_val, "Unknown message"));
3794         ext_tree_proto = proto_item_add_subtree(te, ett_gtp_proto);
3795
3796         proto_tree_add_text(ext_tree_proto, tvb, offset + 1, 2, "Length: %u", length);
3797
3798         if (length < 1) return 3;
3799
3800         conf = tvb_get_guint8 (tvb, offset + 3) & 0x07;
3801         proto_tree_add_text (ext_tree_proto, tvb, offset + 3, 1, "Configuration protocol (00000xxx): %u", conf);
3802
3803         proto_offset = 1;       /* ... 1st byte is conf */
3804         offset += 4;
3805
3806         for (;;) {
3807                 if (proto_offset >= length) break;
3808                 proto_id = tvb_get_ntohs (tvb, offset);
3809                 proto_len = tvb_get_guint8 (tvb, offset + 2);
3810                 proto_offset += proto_len + 3;          /* 3 = proto id + length byte */
3811
3812                 if (proto_len > 0) {
3813
3814                         proto_tree_add_text (ext_tree_proto, tvb, offset, 2, "Protocol %u ID: %s (0x%04x)",
3815                             cnt, val_to_str(proto_id, ppp_vals, "Unknown"),
3816                             proto_id);
3817                         proto_tree_add_text (ext_tree_proto, tvb, offset+2, 1, "Protocol %u length: %u", cnt, proto_len);
3818
3819                         /*
3820                          * Don't allow the dissector for the configuration
3821                          * protocol in question to update the columns - this
3822                          * is GTP, not PPP.
3823                          */
3824                         save_writable = col_get_writable(pinfo->cinfo);
3825                         col_set_writable(pinfo->cinfo, FALSE);
3826
3827                         /*
3828                          * XXX - should we have our own dissector table,
3829                          * solely for configuration protocols, so that bogus
3830                          * values don't cause us to dissect the protocol
3831                          * data as, for example, IP?
3832                          */
3833                         next_tvb = tvb_new_subset (tvb, offset + 3, proto_len, proto_len);
3834                         if (!dissector_try_port(ppp_subdissector_table,
3835                             proto_id, next_tvb, pinfo, ext_tree_proto)) {
3836                                 call_dissector(data_handle, next_tvb, pinfo,
3837                                     ext_tree_proto);
3838                         }
3839
3840                         col_set_writable(pinfo->cinfo, save_writable);
3841                 }
3842
3843                 offset += proto_len + 3;
3844                 cnt++;
3845         }
3846
3847         return 3 + length;
3848 }
3849
3850 /* GPRS:        9.60 v7.6.0, chapter 7.9.23
3851  * UMTS:        29.060 v4.0, chapter 7.7.32
3852  */
3853 static int
3854 decode_gtp_gsn_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3855
3856         guint8          addr_type, addr_len;
3857         guint16         length;
3858         guint32         addr_ipv4;
3859         struct  e_in6_addr addr_ipv6;
3860         proto_tree      *ext_tree_gsn_addr;
3861         proto_item      *te;
3862
3863         length = tvb_get_ntohs(tvb, offset+1);
3864
3865         te = proto_tree_add_text(tree, tvb, offset, 3+length, "GSN address : ");
3866         ext_tree_gsn_addr = proto_item_add_subtree(te, ett_gtp_gsn_addr);
3867
3868         switch (length) {
3869                 case 4:
3870                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length);
3871                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
3872                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
3873                         proto_tree_add_ipv4(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv4 : hf_gtpv0_gsn_ipv4, tvb, offset+3, 4, addr_ipv4);
3874                         break;
3875                 case 5:
3876                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
3877                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
3878                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_type : hf_gtpv0_gsn_addr_type, tvb, offset+3, 1, addr_type);
3879                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
3880                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_len : hf_gtpv0_gsn_addr_len, tvb, offset+3, 1, addr_len);
3881                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+4, sizeof addr_ipv4);
3882                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
3883                         proto_tree_add_ipv4(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv4 : hf_gtpv0_gsn_ipv4, tvb, offset+4, 4, addr_ipv4);
3884                         break;
3885                 case 16:
3886                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address length : %u", length);
3887                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
3888                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3889                         proto_tree_add_ipv6(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv6 : hf_gtpv0_gsn_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
3890                         break;
3891                 case 17:
3892                         proto_tree_add_text(ext_tree_gsn_addr, tvb, offset+1, 2, "GSN address Information Element length : %u", length);
3893                         addr_type = tvb_get_guint8(tvb, offset+3) & 0xC0;
3894                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_type : hf_gtpv0_gsn_addr_type, tvb, offset+3, 1, addr_type);
3895                         addr_len = tvb_get_guint8(tvb, offset+3) & 0x3F;
3896                         proto_tree_add_uint(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_addr_len : hf_gtpv0_gsn_addr_len, tvb, offset+3, 1, addr_len);
3897                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+4, sizeof addr_ipv6);
3898                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
3899                         proto_tree_add_ipv6(ext_tree_gsn_addr, gtp_version ? hf_gtpv1_gsn_ipv6 : hf_gtpv0_gsn_ipv6, tvb, offset+4, 16, (guint8*)&addr_ipv6);
3900                         break;
3901                 default:
3902                         proto_item_append_text(te, "unknown type or wrong length");
3903                         break;
3904         }
3905
3906         return 3+length;
3907 }
3908
3909 /* GPRS:        9.60 v7.6.0, chapter 7.9.24
3910  * UMTS:        29.060 v4.0, chapter 7.7.33
3911  */
3912 static int
3913 decode_gtp_msisdn(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3914
3915         const guint8    *msisdn_val;
3916         gchar           *msisdn_str;
3917         guint16         length;
3918
3919         length = tvb_get_ntohs(tvb, offset+1);
3920
3921         if (length < 1) return 3;
3922
3923         msisdn_val = tvb_get_ptr(tvb, offset+3, length);
3924         msisdn_str = msisdn_to_str(msisdn_val, length);
3925
3926         proto_tree_add_string(tree, gtp_version ? hf_gtpv1_msisdn : hf_gtpv0_msisdn, tvb, offset, 3+length, msisdn_str);
3927
3928         return 3+length;
3929 }
3930
3931 /* GPRS:        not present
3932  * UMTS:        29.060 v4.0, chapter 7.7.34
3933  *              24.008 v4.2, chapter 10.5.6.5
3934  */
3935 static int
3936 decode_gtp_qos_umts(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3937
3938         return decode_qos_umts(tvb, offset, tree, "Quality of Service", 2);
3939 }
3940
3941 /* GPRS:        not present
3942  * UMTS:        29.060 v4.0, chapter 7.7.35
3943  */
3944 static int
3945 decode_gtp_auth_qui(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3946
3947         return (1 + decode_quintuplet(tvb, offset+1, tree, 1, 1));
3948
3949 }
3950
3951 /* GPRS:        not present
3952  * UMTS:        29.060 v4.0, chapter 7.7.36
3953  *              24.008 v4.2, chapter 10.5.6.12
3954  */
3955 static int
3956 decode_gtp_tft(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
3957
3958         guint16         length, port1, port2, tos;
3959         guint8          tft_flags, tft_code, no_packet_filters, i, pf_id, pf_eval, pf_len, pf_content_id, pf_offset, proto, spare;
3960         guint32         mask_ipv4, addr_ipv4, ipsec_id, label;
3961         struct  e_in6_addr addr_ipv6, mask_ipv6;
3962         proto_tree      *ext_tree_tft, *ext_tree_tft_pf, *ext_tree_tft_flags;
3963         proto_item      *te, *tee, *tef;
3964
3965         length = tvb_get_ntohs(tvb, offset+1);
3966
3967         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Traffic flow template");
3968         ext_tree_tft = proto_item_add_subtree(te, ett_gtp_tft);
3969
3970         tft_flags = tvb_get_guint8(tvb, offset+3);
3971         tft_code = (tft_flags >> 5) & 0x07;
3972         spare = (tft_flags >> 4) & 0x01;
3973         no_packet_filters = tft_flags & 0x0F;
3974
3975         proto_tree_add_text(ext_tree_tft, tvb, offset+1, 2, "TFT length: %u", length);
3976
3977         tef = proto_tree_add_text (ext_tree_tft, tvb, offset + 3, 1, "TFT flags");
3978         ext_tree_tft_flags = proto_item_add_subtree (tef, ett_gtp_tft_flags);
3979         proto_tree_add_uint (ext_tree_tft_flags, hf_gtpv1_tft_code, tvb, offset + 3, 1, tft_flags);
3980         proto_tree_add_uint (ext_tree_tft_flags, hf_gtpv1_tft_spare, tvb, offset + 3, 1, tft_flags);
3981         proto_tree_add_uint (ext_tree_tft_flags, hf_gtpv1_tft_number, tvb, offset + 3, 1, tft_flags);
3982
3983         offset = offset + 4;
3984
3985         for (i=0;i<no_packet_filters;i++) {
3986
3987                 pf_id = tvb_get_guint8(tvb, offset);
3988
3989                 tee = proto_tree_add_text (ext_tree_tft, tvb, offset, 1, "Packet filter id: %u", pf_id);
3990                 ext_tree_tft_pf = proto_item_add_subtree (tee, ett_gtp_tft_pf);
3991                 offset++;
3992
3993                 if (tft_code != 2) {
3994
3995                         pf_eval = tvb_get_guint8(tvb, offset);
3996                         pf_len = tvb_get_guint8(tvb, offset + 1);
3997
3998                         proto_tree_add_uint (ext_tree_tft_pf, hf_gtpv1_tft_eval, tvb, offset, 1, pf_eval);
3999                         proto_tree_add_text (ext_tree_tft_pf, tvb, offset+1, 1, "Content length: %u", pf_len);
4000
4001                         offset = offset + 2;
4002                         pf_offset = 0;
4003
4004                         while (pf_offset < pf_len) {
4005
4006                                 pf_content_id = tvb_get_guint8 (tvb, offset + pf_offset);
4007
4008                                 switch (pf_content_id) {
4009                                         /* address IPv4 and mask = 8 bytes*/
4010                                         case 0x10:
4011                                                 tvb_memcpy (tvb, (guint8 *)&addr_ipv4, offset + pf_offset + 1, sizeof addr_ipv4);
4012                                                 tvb_memcpy (tvb, (guint8 *)&mask_ipv4, offset + pf_offset + 5, sizeof mask_ipv4);
4013                                                 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), ip_to_str ((guint8 *)&mask_ipv4));
4014                                                 pf_offset = pf_offset + 9;
4015                                                 break;
4016                                         /* address IPv6 and mask = 32 bytes*/
4017                                         case 0x20:
4018                                                 tvb_memcpy (tvb, (guint8 *)&addr_ipv6, offset+pf_offset+1, sizeof addr_ipv6);
4019                                                 tvb_memcpy (tvb, (guint8 *)&mask_ipv6, offset+pf_offset+17, sizeof mask_ipv6);
4020                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset+pf_offset, 33, "ID 0x20: IPv6/mask: %s/%s", ip6_to_str ((struct e_in6_addr*)&addr_ipv6), ip6_to_str ((struct e_in6_addr*)&mask_ipv6));
4021                                                 pf_offset = pf_offset + 33;
4022                                                 break;
4023                                         /* protocol identifier/next header type = 1 byte*/
4024                                         case 0x30:
4025                                                 proto = tvb_get_guint8 (tvb, offset + pf_offset + 1);
4026                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 2, "ID 0x30: IPv4 protocol identifier/IPv6 next header: %u (%x)", proto, proto);
4027                                                 pf_offset = pf_offset + 2;
4028                                                 break;
4029                                         /* single destination port type = 2 bytes */
4030                                         case 0x40:
4031                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4032                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 3, "ID 0x40: destination port: %u", port1);
4033                                                 pf_offset = pf_offset + 3;
4034                                                 break;
4035                                         /* destination port range type = 4 bytes */
4036                                         case 0x41:
4037                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4038                                                 port2 = tvb_get_ntohs (tvb, offset + pf_offset + 3);
4039                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 5, "ID 0x41: destination port range: %u - %u", port1, port2);
4040                                                 pf_offset = pf_offset + 5;
4041                                                 break;
4042                                         /* single source port type = 2 bytes */
4043                                         case 0x50:
4044                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4045                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 3, "ID 0x50: source port: %u", port1);
4046                                                 pf_offset = pf_offset + 3;
4047                                                 break;
4048                                         /* source port range type = 4 bytes */
4049                                         case 0x51:
4050                                                 port1 = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4051                                                 port2 = tvb_get_ntohs (tvb, offset + pf_offset + 3);
4052                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 5, "ID 0x51: source port range: %u - %u", port1, port2);
4053                                                 pf_offset = pf_offset + 5;
4054                                                 break;
4055                                         /* security parameter index type = 4 bytes */
4056                                         case 0x60:
4057                                                 ipsec_id = tvb_get_ntohl (tvb, offset + pf_offset + 1);
4058                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 5, "ID 0x60: security parameter index: %x", ipsec_id);
4059                                                 pf_offset = pf_offset + 5;
4060                                                 break;
4061                                         /* type of service/traffic class type = 2 bytes */
4062                                         case 0x70:
4063                                                 tos = tvb_get_ntohs (tvb, offset + pf_offset + 1);
4064                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 2, "ID 0x70: Type of Service/Traffic Class: %u (%x)", tos, tos);
4065                                                 pf_offset = pf_offset + 3;
4066                                                 break;
4067                                         /* flow label type = 3 bytes */
4068                                         case 0x80:
4069                                                 label = tvb_get_ntoh24(tvb, offset + pf_offset + 1) & 0x0FFFFF;;
4070                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 4, "ID 0x80: Flow Label: %u (%x)", label, label);
4071                                                 pf_offset = pf_offset + 4;
4072                                                 break;
4073
4074                                         default:
4075                                                 proto_tree_add_text (ext_tree_tft_pf, tvb, offset + pf_offset, 1, "Unknown value: %x ", pf_content_id);
4076                                                 pf_offset++; /* to avoid infinite loop */
4077                                                 break;
4078                                 }
4079                         }
4080
4081                         offset = offset + pf_offset;
4082                 }
4083         }
4084
4085         return 3 + length;
4086 }
4087
4088 /* GPRS:        not present
4089  * UMTS:        29.060 v4.0, chapter 7.7.37
4090  *              25.413 v3.4, chapter ???
4091  */
4092 static int
4093 decode_gtp_target_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4094
4095         guint16         length;
4096
4097         length = tvb_get_ntohs(tvb, offset + 1);
4098
4099         proto_tree_add_text(tree, tvb, offset, 3 + length, "Targer Identification");
4100
4101         return 3 + length;
4102 }
4103
4104
4105 /* GPRS:        not present
4106  * UMTS:        29.060 v4.0, chapter 7.7.38
4107  */
4108 static int
4109 decode_gtp_utran_cont(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4110
4111         guint16         length;
4112
4113         length = tvb_get_ntohs(tvb, offset + 1);
4114
4115         proto_tree_add_text(tree, tvb, offset, 3 + length, "UTRAN transparent field");
4116
4117         return 3 + length;
4118
4119 }
4120
4121
4122 /* GPRS:        not present
4123  * UMTS:        29.060 v4.0, chapter 7.7.39
4124  */
4125 static int
4126 decode_gtp_rab_setup(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4127
4128         guint32         teid, addr_ipv4;
4129         guint16         length;
4130         guint8          nsapi;
4131         struct  e_in6_addr addr_ipv6;
4132         proto_tree      *ext_tree_rab_setup;
4133         proto_item      *te;
4134
4135         length = tvb_get_ntohs(tvb, offset + 1);
4136         nsapi = tvb_get_guint8(tvb, offset + 3) & 0x0F;
4137
4138         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Radio Access Bearer Setup Information");
4139         ext_tree_rab_setup = proto_item_add_subtree(te, ett_gtp_rab_setup);
4140
4141         proto_tree_add_text(ext_tree_rab_setup, tvb, offset+1, 2, "RAB setup length : %u", length);
4142         proto_tree_add_uint(ext_tree_rab_setup, hf_gtpv1_nsapi, tvb, offset+3, 1, nsapi);
4143
4144         if (length > 1) {
4145
4146                 teid = tvb_get_ntohl(tvb, offset + 4);
4147
4148                 proto_tree_add_uint(ext_tree_rab_setup, hf_gtpv1_teid_data, tvb, offset+4, 4, teid);
4149
4150                 switch (length) {
4151                         case 12:
4152                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+8, sizeof addr_ipv4);
4153                                 proto_tree_add_ipv4(ext_tree_rab_setup, hf_gtpv1_rnc_ipv4, tvb, offset+8, 4, addr_ipv4);
4154                                 break;
4155                         case 24:
4156                                 tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+8, sizeof addr_ipv6);
4157                                 proto_tree_add_ipv6(ext_tree_rab_setup, hf_gtpv1_rnc_ipv6, tvb, offset+8, 16, (guint8 *)&addr_ipv6);
4158                                 break;
4159                         default:
4160                                 break;
4161                 }
4162         }
4163
4164         return 3 + length;
4165 }
4166
4167
4168 /* GPRS:        not present
4169  * UMTS:        29.060 v4.0, chapter 7.7.40
4170  */
4171 static int
4172 decode_gtp_hdr_list(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4173
4174         int             i;
4175         guint8          length, hdr;
4176         proto_tree      *ext_tree_hdr_list;
4177         proto_item      *te;
4178
4179         length = tvb_get_guint8(tvb, offset + 1);
4180
4181         te = proto_tree_add_text(tree, tvb, offset, 2+length, "%s", val_to_str(GTP_EXT_HDR_LIST, gtp_val, "Unknown"));
4182         ext_tree_hdr_list = proto_item_add_subtree(te, ett_gtp_hdr_list);
4183
4184         proto_tree_add_text(ext_tree_hdr_list, tvb, offset+1, 1, "Number of Extension Header Types in list (i.e., length) : %u", length);
4185
4186         for(i=0 ; i<length ; i++) {
4187                 hdr = tvb_get_guint8(tvb, offset+2+i);
4188
4189                 proto_tree_add_text(ext_tree_hdr_list, tvb, offset+2+i, 1, "No. %u --> Extension Header Type value : %s (%u)", i+1, val_to_str(hdr, gtp_val, "Unknown Extension Header Type"), hdr);
4190         }
4191
4192         return 2 + length;
4193 }
4194
4195 /* GPRS:        not present
4196  * UMTS:        29.060 v4.0, chapter 7.7.41
4197  * TODO:        find TriggerID description
4198  */
4199 static int
4200 decode_gtp_trigger_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4201
4202         guint16         length;
4203
4204         length = tvb_get_ntohs(tvb, offset + 1);
4205
4206         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_TRIGGER_ID, gtp_val, "Unknown"), length);
4207
4208         return 3 + length;
4209
4210 }
4211
4212 /* GPRS:        not present
4213  * UMTS:        29.060 v4.0, chapter 7.7.42
4214  * TODO:        find OMC-ID description
4215  */
4216 static int
4217 decode_gtp_omc_id(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4218
4219         guint16         length;
4220
4221         length = tvb_get_ntohs(tvb, offset + 1);
4222
4223         proto_tree_add_text(tree, tvb, offset, 3+length, "%s length : %u", val_to_str(GTP_EXT_OMC_ID, gtp_val, "Unknown"), length);
4224
4225         return 3 + length;
4226
4227 }
4228
4229 /* GPRS:        9.60 v7.6.0, chapter 7.9.25
4230  * UMTS:        29.060 v4.0, chapter 7.7.43
4231  */
4232 static int
4233 decode_gtp_chrg_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4234
4235         guint16         length;
4236         guint32         addr_ipv4;
4237         struct  e_in6_addr addr_ipv6;
4238         proto_tree      *ext_tree_chrg_addr;
4239         proto_item      *te;
4240
4241         length = tvb_get_ntohs(tvb, offset+1);
4242
4243         te = proto_tree_add_text(tree, tvb, offset, 3+length, "%s : ", val_to_str(GTP_EXT_CHRG_ADDR, gtp_val, "Unknown"));
4244         ext_tree_chrg_addr = proto_item_add_subtree(te, ett_gtp_chrg_addr);
4245
4246         proto_tree_add_text(ext_tree_chrg_addr, tvb, offset+1, 2, "%s length : %u", val_to_str(GTP_EXT_CHRG_ADDR, gtp_val, "Unknown"), length);
4247
4248         switch (length) {
4249                 case 4:
4250                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
4251                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4252                         proto_tree_add_ipv4(ext_tree_chrg_addr, gtp_version ? hf_gtpv1_chrg_ipv4 : hf_gtpv0_chrg_ipv4, tvb, offset+3, 4, addr_ipv4);
4253                         break;
4254                 case 16:
4255                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
4256                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4257                         proto_tree_add_ipv6(ext_tree_chrg_addr, gtp_version ? hf_gtpv1_chrg_ipv6 : hf_gtpv0_chrg_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
4258                         break;
4259                 default:
4260                         proto_item_append_text(te, "unknown type or wrong length");
4261                         break;
4262         }
4263
4264         return 3 + length;
4265 }
4266
4267 /* GPRS:        12.15
4268  * UMTS:        33.015
4269  */
4270 static int
4271 decode_gtp_rel_pack(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4272
4273         guint16         length, n, number;
4274         proto_tree      *ext_tree_rel_pack;
4275         proto_item      *te;
4276
4277         length = tvb_get_ntohs(tvb, offset + 1);
4278
4279         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of released packets IE");
4280         ext_tree_rel_pack = proto_item_add_subtree(te, ett_gtp_rel_pack);
4281
4282         n = 0;
4283
4284         while (n < length) {
4285
4286                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4287                 proto_tree_add_text(ext_tree_rel_pack, tvb, offset + 3 + n, 2, "%u", number);
4288                 n = n + 2;
4289
4290         }
4291
4292         return 3 + length;
4293 }
4294
4295 /* GPRS:        12.15
4296  * UMTS:        33.015
4297  */
4298 static int
4299 decode_gtp_can_pack(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4300
4301         guint16         length, n, number;
4302         proto_tree      *ext_tree_can_pack;
4303         proto_item      *te;
4304
4305         length = tvb_get_ntohs(tvb, offset + 1);
4306
4307         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Sequence numbers of cancelled  packets IE");
4308         ext_tree_can_pack = proto_item_add_subtree(te, ett_gtp_can_pack);
4309
4310         n = 0;
4311
4312         while (n < length) {
4313
4314                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4315                 proto_tree_add_text(ext_tree_can_pack, tvb, offset + 3 + n, 2, "%u", number);
4316                 n = n + 2;
4317
4318         }
4319
4320         return 3 + length;
4321 }
4322
4323 /* CDRs dissector */
4324 static int
4325 decode_gtp_data_req(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4326
4327         guint16         length, format_ver, data_len, i, j;
4328         guint8          no, format, rectype;
4329         proto_tree      *ext_tree, *cdr_tree;
4330         proto_item      *te, *ce;
4331
4332         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_DATA_REQ, gtp_val, "Unknown message"));
4333         ext_tree = proto_item_add_subtree(te, ett_gtp_ext);
4334
4335         length = tvb_get_ntohs(tvb, offset + 1);
4336         no = tvb_get_guint8(tvb, offset + 3);
4337         format = tvb_get_guint8(tvb, offset + 4);
4338         format_ver = tvb_get_ntohs(tvb, offset + 5);
4339
4340         proto_tree_add_text(ext_tree, tvb, offset+1, 2, "Length: %u", length);
4341         proto_tree_add_text(ext_tree, tvb, offset+3, 1, "Number of data records: %u", no);
4342         proto_tree_add_text(ext_tree, tvb, offset+4, 1, "Data record format: %u", format);
4343         proto_tree_add_text(ext_tree, tvb, offset+5, 2, "Data record format version: %u", format_ver);
4344
4345         data_len = 0;
4346         offset = offset + 7;
4347
4348         if (gtpv0_cdr_as != DONT_DISSECT_CDRS) {
4349
4350         for (i = 0; i < no; i++) {
4351                 data_len = tvb_get_ntohs(tvb, offset);
4352                 rectype = tvb_get_guint8(tvb, offset+2);
4353                 switch (rectype) {
4354                         case 0x13:              /* GCDR */
4355                                 if (tvb_length_remaining(tvb, offset) < 3 + 118) {
4356                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "GCDR fragmented, can't dissect");
4357                                         break;
4358                                 }
4359
4360                                 tvb_memcpy(tvb, gcdr.imsi, offset+3, 8);
4361                                 tvb_memcpy(tvb, (guint8 *)&gcdr.ggsnaddr, offset+11, sizeof gcdr.ggsnaddr);
4362                                 gcdr.chrgid = tvb_get_ntohl(tvb, offset+15);
4363                                 tvb_memcpy(tvb, (guint8 *)&gcdr.sgsnaddr, offset+19, sizeof gcdr.sgsnaddr);
4364                                 tvb_memcpy(tvb, gcdr.apn, offset+23, 63);
4365                                 gcdr.pdporg = tvb_get_guint8(tvb, offset+86);
4366                                 gcdr.pdptype = tvb_get_guint8(tvb, offset+87);
4367                                 tvb_memcpy(tvb, (guint8 *)&gcdr.pdpaddr, offset+88, sizeof gcdr.pdpaddr);
4368                                 gcdr.addrflag = tvb_get_guint8(tvb, offset+92);
4369                                 gcdr.uplink = tvb_get_ntohl(tvb, offset+96);
4370                                 gcdr.downlink = tvb_get_ntohl(tvb, offset+100);
4371                                 gcdr.timestamp = tvb_get_ntohl(tvb, offset+104);
4372                                 gcdr.opening = tvb_get_ntohl(tvb, offset+108);
4373                                 gcdr.duration = tvb_get_ntohl(tvb, offset+112);
4374                                 gcdr.closecause = tvb_get_guint8(tvb, offset+116);
4375                                 gcdr.seqno = tvb_get_ntohl(tvb, offset+117);
4376
4377                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "GCDR (0x13), sequence number: %u", gcdr.seqno);
4378                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4379                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4380                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4381                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 8, "IMSI: %s", id_to_str(gcdr.imsi));
4382                                 proto_tree_add_text(cdr_tree, tvb, offset+11, 4, "GGSN address: %s", ip_to_str((guint8 *)&gcdr.ggsnaddr));
4383                                 proto_tree_add_text(cdr_tree, tvb, offset+15, 4, "Charging ID: %x", gcdr.chrgid);
4384                                 proto_tree_add_text(cdr_tree, tvb, offset+19, 4, "SGSN address: %s", ip_to_str((guint8 *)&gcdr.sgsnaddr));
4385                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 63, "APN: %s", gcdr.apn);
4386                                 proto_tree_add_text(cdr_tree, tvb, offset+86, 1, "PDP org: %s", val_to_str(gcdr.pdporg, pdp_org_type, "Unknown PDP org"));
4387                                 proto_tree_add_text(cdr_tree, tvb, offset+87, 1, "PDP type: %s", val_to_str(gcdr.pdptype, pdp_type, "Unknown PDP type"));
4388                                 proto_tree_add_text(cdr_tree, tvb, offset+88, 4, "PDP address: %s", ip_to_str((guint8 *)&gcdr.pdpaddr));
4389                                 proto_tree_add_text(cdr_tree, tvb, offset+92, 1, "PDP address type: %u", gcdr.addrflag);
4390                                 decode_qos_gprs(tvb, offset+93, cdr_tree, "QoS", 0);
4391                                 proto_tree_add_text(cdr_tree, tvb, offset+96, 4, "Uplink volume: %u", gcdr.uplink);
4392                                 proto_tree_add_text(cdr_tree, tvb, offset+100, 4, "Downlink volume: %u", gcdr.downlink);
4393                                 proto_tree_add_text(cdr_tree, tvb, offset+104, 4, "Timestamp: %s", time_int_to_str(gcdr.timestamp));
4394                                 proto_tree_add_text(cdr_tree, tvb, offset+108, 4, "Record opening time: %s", time_int_to_str(gcdr.opening));
4395                                 proto_tree_add_text(cdr_tree, tvb, offset+112, 4, "Duration: %s", rel_time_int_to_str(gcdr.duration));
4396                                 proto_tree_add_text(cdr_tree, tvb, offset+116, 1, "Cause for close: %s (%u)", val_to_str(gcdr.closecause, cdr_close_type, "Unknown cause"), gcdr.closecause);
4397                                 proto_tree_add_text(cdr_tree, tvb, offset+117, 4, "Sequence number: %u", gcdr.seqno);
4398
4399                                 if (data_len > 119) {
4400                                         tvb_memcpy (tvb, gcdr.msisdn, offset + 121, 9);
4401                                         proto_tree_add_text(cdr_tree, tvb, offset+121, 9, "MSISDN: %s", msisdn_to_str (gcdr.msisdn, 9));
4402                                 }
4403
4404                                 break;
4405
4406                         case 0x12:              /* SCDR */
4407                                 if (tvb_length_remaining(tvb, offset) < 3 + 277) {
4408                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "SCDR fragmented, can't dissect");
4409                                         break;
4410                                 }
4411
4412                                 scdr.len = tvb_get_letohs(tvb, offset+3);
4413                                 scdr.netini = tvb_get_guint8(tvb, offset+5);
4414                                 scdr.anon = tvb_get_guint8(tvb, offset+6);
4415                                 scdr.imsilen = tvb_get_guint8(tvb, offset+7);
4416                                 tvb_memcpy(tvb, scdr.imsi, offset+8, 8);
4417                                 tvb_memcpy(tvb, scdr.imei, offset+16, 8);
4418                                 scdr.msisdnlen = tvb_get_guint8(tvb, offset+24);
4419                                 tvb_memcpy(tvb, scdr.msisdn, offset+25, 10);
4420                                 tvb_memcpy(tvb, (guint8 *)&scdr.sgsnaddr, offset+35, sizeof scdr.sgsnaddr);
4421                                 tvb_memcpy(tvb, scdr.msclass_notused, offset+39, 12);
4422                                 scdr.msclass_caplen = tvb_get_guint8(tvb, offset+51);
4423                                 scdr.msclass_cap = tvb_get_guint8(tvb, offset+52);
4424                                 scdr.msclass_capomit = tvb_get_ntohs(tvb, offset+53);
4425                                 scdr.lac = tvb_get_ntohs(tvb, offset+55);
4426                                 scdr.rac = tvb_get_guint8(tvb, offset+57);
4427                                 scdr.cid = tvb_get_ntohs(tvb, offset+58);
4428                                 scdr.chrgid = tvb_get_ntohl(tvb, offset+60);
4429                                 tvb_memcpy(tvb, (guint8 *)&scdr.ggsnaddr, offset+64, sizeof scdr.ggsnaddr);
4430                                 tvb_memcpy(tvb, scdr.apn, offset+68, 64);
4431                                 scdr.pdporg = tvb_get_guint8(tvb, offset+132);
4432                                 scdr.pdptype = tvb_get_guint8(tvb, offset+133);
4433                                 tvb_memcpy(tvb, (guint8 *)&scdr.pdpaddr, offset+134, sizeof scdr.pdpaddr);
4434                                 scdr.listind = tvb_get_guint8(tvb, offset+138);
4435                                 for (j=0;j<4;j++) {
4436                                         scdr.change[j].change = tvb_get_guint8(tvb, offset+139+23*j);
4437                                         scdr.change[j].time1 = tvb_get_ntohl(tvb, offset+140+23*j);
4438                                         scdr.change[j].time2 = tvb_get_ntohl(tvb, offset+144+23*j);
4439                                         scdr.change[j].uplink = tvb_get_ntohl(tvb, offset+148+23*j);
4440                                         scdr.change[j].downlink = tvb_get_ntohl(tvb, offset+152+23*j);
4441 /*                                      tvb_memcpy(tvb, scdr.change[j].qos_req, offset+156+23*j, 3);
4442                                         tvb_memcpy(tvb, scdr.change[j].qos_neg, offset+159+23*j, 3);*/
4443                                 }
4444                                 scdr.timestamp = tvb_get_ntohl(tvb, offset+254);
4445                                 scdr.opening = tvb_get_ntohl(tvb, offset+258);
4446                                 scdr.duration = tvb_get_ntohl(tvb, offset+262);
4447                                 scdr.sgsnchange = tvb_get_guint8(tvb, offset+266);
4448                                 scdr.closecause = tvb_get_guint8(tvb, offset+267);
4449                                 scdr.diag1 = tvb_get_guint8(tvb, offset+268);
4450                                 scdr.diag2 = tvb_get_guint8(tvb, offset+269);
4451                                 scdr.diag3 = tvb_get_guint8(tvb, offset+270);
4452                                 scdr.diag4 = tvb_get_guint8(tvb, offset+271);
4453                                 scdr.diag5 = tvb_get_ntohl(tvb, offset+272);
4454                                 scdr.seqno = tvb_get_ntohl(tvb, offset+276);
4455
4456                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "SCDR (type %x), sequence number: %u", rectype, scdr.seqno);
4457                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4458                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4459                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4460                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "CDR length: %u", scdr.len);
4461                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "Network initiated PDP context: %s", yesno[scdr.netini]);
4462                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 1, "Anonymous acces: %s", yesno[scdr.anon]);
4463                                 proto_tree_add_text(cdr_tree, tvb, offset+7, 1, "IMSI length: %u", scdr.imsilen);
4464                                 proto_tree_add_text(cdr_tree, tvb, offset+8, 8, "IMSI: %s", id_to_str(scdr.imsi));
4465                                 proto_tree_add_text(cdr_tree, tvb, offset+16, 8, "IMEI: %s", id_to_str(scdr.imei));
4466                                 proto_tree_add_text(cdr_tree, tvb, offset+24, 1, "MSISDN length: %u", scdr.msisdnlen);
4467                                 proto_tree_add_text(cdr_tree, tvb, offset+25, 10, "MSISDN: %s", msisdn_to_str(scdr.msisdn, 10));
4468                                 proto_tree_add_text(cdr_tree, tvb, offset+35, 4, "SGSN address: %s", ip_to_str((guint8 *)&scdr.sgsnaddr));
4469                                 proto_tree_add_text(cdr_tree, tvb, offset+39, 12, "(not used)");
4470                                 proto_tree_add_text(cdr_tree, tvb, offset+51, 1, "MS network capability length: %u", scdr.msclass_caplen);
4471
4472 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+52, 1, "MS network capability: %u", scdr.msclass_cap);
4473                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4474                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+52, 1, scdr.cap);
4475                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+52, 1, scdr.cap);
4476                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+52, 1, scdr.cap);
4477                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+52, 1, scdr.cap);
4478                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+52, 1, scdr.cap);
4479                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+52, 1, scdr.cap);
4480                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_pad, tvb, offset+52, 1, scdr.cap);
4481 */
4482
4483                                 proto_tree_add_text(cdr_tree, tvb, offset+53, 2, "MS network capability omitted: %u", scdr.msclass_capomit);
4484                                 proto_tree_add_text(cdr_tree, tvb, offset+55, 2, "LAC: %u", scdr.lac);
4485                                 proto_tree_add_text(cdr_tree, tvb, offset+57, 1, "RAC: %u", scdr.rac);
4486                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 2, "Cell ID: %u", scdr.cid);
4487                                 proto_tree_add_text(cdr_tree, tvb, offset+60, 4, "Charging ID: %x", scdr.chrgid);
4488                                 proto_tree_add_text(cdr_tree, tvb, offset+64, 4, "GGSN address: %s", ip_to_str((guint8 *)&scdr.ggsnaddr));
4489                                 proto_tree_add_text(cdr_tree, tvb, offset+68, 64, "APN: %s", scdr.apn);
4490                                 proto_tree_add_text(cdr_tree, tvb, offset+132, 1, "PDP org: %s", val_to_str(scdr.pdporg, pdp_org_type, "Unknown PDP org"));
4491                                 proto_tree_add_text(cdr_tree, tvb, offset+133, 1, "PDP type: %s", val_to_str(scdr.pdptype, pdp_type, "Unknown PDP type"));
4492                                 proto_tree_add_text(cdr_tree, tvb, offset+134, 4, "PDP address: %s", ip_to_str((guint8 *)&scdr.pdpaddr));
4493                                 proto_tree_add_text(cdr_tree, tvb, offset+138, 1, "List of data volume index: %u", scdr.listind);
4494                                 for (j=0;j<4;j++) {
4495                                         proto_tree_add_text(cdr_tree, tvb, offset+139+23*j, 1, "List of data vol change condition: %u", scdr.change[j].change);
4496                                         proto_tree_add_text(cdr_tree, tvb, offset+140+23*j, 4, "Time1: %x", scdr.change[j].time1);
4497                                         proto_tree_add_text(cdr_tree, tvb, offset+144+23*j, 4, "Time2: %x", scdr.change[j].time2);
4498                                         proto_tree_add_text(cdr_tree, tvb, offset+148+23*j, 4, "Uplink: %x", scdr.change[j].uplink);
4499                                         proto_tree_add_text(cdr_tree, tvb, offset+152+23*j, 4, "Downlink: %x", scdr.change[j].downlink);
4500                                         decode_qos_gprs(tvb, offset+156, cdr_tree, "QoS requested", 0);
4501                                         decode_qos_gprs(tvb, offset+159, cdr_tree, "QoS negotiated", 0);
4502                                 }
4503                                 proto_tree_add_text(cdr_tree, tvb, offset+254, 4, "Timestamp: %s", time_int_to_str(scdr.timestamp));
4504                                 proto_tree_add_text(cdr_tree, tvb, offset+258, 4, "Opening: %s", time_int_to_str(scdr.opening));
4505                                 proto_tree_add_text(cdr_tree, tvb, offset+262, 4, "Duration: %s", rel_time_int_to_str(scdr.duration));
4506                                 proto_tree_add_text(cdr_tree, tvb, offset+266, 1, "SGSN change: %u", scdr.sgsnchange);
4507                                 proto_tree_add_text(cdr_tree, tvb, offset+267, 1, "Cause for close: %s (%u)", val_to_str(scdr.closecause, cdr_close_type, "Unknown cause"), scdr.closecause);
4508                                 proto_tree_add_text(cdr_tree, tvb, offset+268, 1, "Diagnostics 1: %u", scdr.diag1);
4509                                 proto_tree_add_text(cdr_tree, tvb, offset+269, 1, "Diagnostics 2: %u", scdr.diag2);
4510                                 proto_tree_add_text(cdr_tree, tvb, offset+270, 1, "Diagnostics 3: %u", scdr.diag3);
4511                                 proto_tree_add_text(cdr_tree, tvb, offset+271, 1, "Diagnostics 4: %u", scdr.diag4);
4512                                 proto_tree_add_text(cdr_tree, tvb, offset+272, 4, "Diagnostics 5: %u", scdr.diag5);
4513                                 proto_tree_add_text(cdr_tree, tvb, offset+276, 4, "Sequence number: %u", scdr.seqno);
4514                                 break;
4515                         case 0x14:              /* MCDR */
4516                                 if (tvb_length_remaining(tvb, offset) < 3 + 147) {
4517                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "MCDR fragmented, can't dissect");
4518                                         break;
4519                                 }
4520
4521                                 mcdr.len = tvb_get_ntohs(tvb, offset+3);
4522                                 mcdr.imsilen = tvb_get_guint8(tvb, offset+5);
4523                                 tvb_memcpy(tvb, mcdr.imsi, offset+6, 8);
4524                                 tvb_memcpy(tvb, mcdr.imei, offset+14, 8);
4525                                 mcdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4526                                 tvb_memcpy(tvb, mcdr.msisdn, offset+23, 10);
4527                                 tvb_memcpy(tvb, (guint8 *)&mcdr.sgsnaddr, offset+33, sizeof mcdr.sgsnaddr);
4528                                 tvb_memcpy(tvb, mcdr.msclass_notused, offset+37, 12);
4529                                 mcdr.msclass_caplen = tvb_get_guint8(tvb, offset+49);
4530                                 mcdr.msclass_cap = tvb_get_guint8(tvb, offset+50);
4531                                 mcdr.msclass_capomit = tvb_get_ntohs(tvb, offset+51);
4532                                 mcdr.lac = tvb_get_ntohs(tvb, offset+53);
4533                                 mcdr.rac = tvb_get_guint8(tvb, offset+55);
4534                                 mcdr.cid = tvb_get_ntohs(tvb, offset+56);
4535                                 mcdr.change_count = tvb_get_guint8(tvb, offset+58);
4536                                 for (j=0;j<4;j++) {
4537                                         mcdr.change[j].lac = tvb_get_ntohs(tvb, offset+59+13*j);
4538                                         mcdr.change[j].rac = tvb_get_guint8(tvb, offset+61+13*j);
4539                                         mcdr.change[j].cid = tvb_get_ntohs(tvb, offset+62+13*j);
4540                                         tvb_memcpy(tvb, mcdr.change[j].omit, offset+64+13*j, 8);
4541                                 }
4542                                 mcdr.timestamp = tvb_get_ntohl(tvb, offset+124);
4543                                 mcdr.opening = tvb_get_ntohl(tvb, offset+128);
4544                                 mcdr.duration = tvb_get_ntohl(tvb, offset+132);
4545                                 mcdr.sgsnchange = tvb_get_guint8(tvb, offset+136);
4546                                 mcdr.closecause = tvb_get_guint8(tvb, offset+137);
4547                                 mcdr.diag1 = tvb_get_guint8(tvb, offset+138);
4548                                 mcdr.diag2 = tvb_get_guint8(tvb, offset+139);
4549                                 mcdr.diag3 = tvb_get_guint8(tvb, offset+140);
4550                                 mcdr.diag4 = tvb_get_guint8(tvb, offset+141);
4551                                 mcdr.diag5 = tvb_get_ntohl(tvb, offset+142);
4552                                 mcdr.seqno = tvb_get_ntohl(tvb, offset+146);
4553
4554                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "MCDR (0x14), sequence number: %u", mcdr.seqno);
4555                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4556                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4557                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4558                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", mcdr.len);
4559                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", mcdr.imsilen);
4560                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(mcdr.imsi));
4561                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(mcdr.imei));
4562                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", mcdr.msisdnlen);
4563                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(mcdr.msisdn, 10));
4564                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 4, "SGSN address: %s", ip_to_str((guint8 *)&mcdr.sgsnaddr));
4565                                 proto_tree_add_text(cdr_tree, tvb, offset+37, 12, "(not used)");
4566                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 1, "MS network capability length: %u", mcdr.msclass_caplen);
4567
4568 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+50, 1, "MS network capability: %u", mcdr.msclass_cap);
4569                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4570                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+50, 1, mcdr.cap);
4571                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+50, 1, mcdr.cap);
4572                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+50, 1, mcdr.cap);
4573                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+50, 1, mcdr.cap);
4574                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+50, 1, mcdr.cap);
4575                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+50, 1, mcdr.cap);
4576                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_pad, tvb, offset+50, 1, mcdr.cap);
4577 */
4578                                 proto_tree_add_text(cdr_tree, tvb, offset+51, 2, "MS network capability omitted: %u", mcdr.msclass_capomit);
4579                                 proto_tree_add_text(cdr_tree, tvb, offset+53, 2, "LAC: %u", mcdr.lac);
4580                                 proto_tree_add_text(cdr_tree, tvb, offset+55, 1, "RAC: %u", mcdr.rac);
4581                                 proto_tree_add_text(cdr_tree, tvb, offset+56, 2, "Cell ID: %u", mcdr.cid);
4582                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 1, "List of data volume changes: %u", mcdr.change_count);
4583                                 for (j=0;j<4;j++) {
4584                                         proto_tree_add_text(cdr_tree, tvb, offset+59+13*j, 2, "LAC: %u", mcdr.change[j].lac);
4585                                         proto_tree_add_text(cdr_tree, tvb, offset+61+13*j, 1, "RAC: %u", mcdr.change[j].rac);
4586                                         proto_tree_add_text(cdr_tree, tvb, offset+62+13*j, 2, "CID: %u", mcdr.change[j].cid);
4587                                         proto_tree_add_text(cdr_tree, tvb, offset+64+13*j, 8, "(omitted)");
4588                                 }
4589
4590                                 proto_tree_add_text(cdr_tree, tvb, offset+124, 4, "Timestamp: %s", time_int_to_str(mcdr.timestamp));
4591                                 proto_tree_add_text(cdr_tree, tvb, offset+128, 4, "Record opening time: %s", time_int_to_str(mcdr.opening));
4592                                 proto_tree_add_text(cdr_tree, tvb, offset+132, 4, "Duration: %s", rel_time_int_to_str(mcdr.duration));
4593                                 proto_tree_add_text(cdr_tree, tvb, offset+136, 1, "SGSN change: %u", mcdr.sgsnchange);
4594                                 proto_tree_add_text(cdr_tree, tvb, offset+137, 1, "Cause for close: %s (%u)", val_to_str(mcdr.closecause, cdr_close_type, "Unknown cause"), mcdr.closecause);
4595                                 proto_tree_add_text(cdr_tree, tvb, offset+138, 1, "Diagnostics 1: %u", mcdr.diag1);
4596                                 proto_tree_add_text(cdr_tree, tvb, offset+139, 1, "Diagnostics 2: %u", mcdr.diag2);
4597                                 proto_tree_add_text(cdr_tree, tvb, offset+140, 1, "Diagnostics 3: %u", mcdr.diag3);
4598                                 proto_tree_add_text(cdr_tree, tvb, offset+141, 1, "Diagnostics 4: %u", mcdr.diag4);
4599                                 proto_tree_add_text(cdr_tree, tvb, offset+142, 4, "Diagnostics 5: %u", mcdr.diag5);
4600                                 proto_tree_add_text(cdr_tree, tvb, offset+146, 4, "Sequence number: %u", mcdr.seqno);
4601                                 break;
4602
4603                         case 0x15:              /* SOCDR */
4604                                 if (tvb_length_remaining(tvb, offset) < 3 + 80) {
4605                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "SOCDR fragmented, can't dissect");
4606                                         break;
4607                                 }
4608
4609                                 socdr.len = tvb_get_ntohs(tvb, offset+3);
4610                                 socdr.imsilen = tvb_get_guint8(tvb, offset+5);
4611                                 tvb_memcpy(tvb, socdr.imsi, offset+6, 8);
4612                                 tvb_memcpy(tvb, socdr.imei, offset+14, 8);
4613                                 socdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4614                                 tvb_memcpy(tvb, socdr.msisdn, offset+23, 10);
4615                                 tvb_memcpy(tvb, socdr.msclass_notused, offset+33, 12);
4616                                 socdr.msclass_caplen = tvb_get_guint8(tvb, offset+45);
4617                                 socdr.msclass_cap = tvb_get_guint8(tvb, offset+46);
4618                                 socdr.msclass_capomit = tvb_get_ntohs(tvb, offset+47);
4619                                 tvb_memcpy(tvb, socdr.serv_centr, offset+49, 9);
4620                                 tvb_memcpy(tvb, socdr.rec_ent, offset+58, 9);
4621                                 socdr.lac = tvb_get_ntohs(tvb, offset+67);
4622                                 socdr.rac = tvb_get_guint8(tvb, offset+69);
4623                                 socdr.cid = tvb_get_ntohs(tvb, offset+70);
4624                                 socdr.time1 = tvb_get_ntohl(tvb, offset+72);
4625                                 socdr.time2 = tvb_get_ntohl(tvb, offset+76);
4626                                 socdr.messref = tvb_get_guint8(tvb, offset+80);
4627                                 socdr.smsres = tvb_get_ntohs(tvb, offset+81);
4628
4629                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "SOCDR (0x15)");
4630                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4631                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4632                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4633                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", socdr.len);
4634                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", socdr.imsilen);
4635                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(socdr.imsi));
4636                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(socdr.imei));
4637                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", socdr.msisdnlen);
4638                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(socdr.msisdn, 10));
4639                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 12, "(not used)");
4640                                 proto_tree_add_text(cdr_tree, tvb, offset+45, 1, "MS network capability length: %u", socdr.msclass_caplen);
4641
4642 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+46, 1, "MS network capability: %u", socdr.msclass_cap);
4643                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4644                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+46, 1, socdr.cap);
4645                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+46, 1, socdr.cap);
4646                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+46, 1, socdr.cap);
4647                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+46, 1, socdr.cap);
4648                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+46, 1, socdr.cap);
4649                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+46, 1, socdr.cap);
4650 */
4651                                 proto_tree_add_text(cdr_tree, tvb, offset+47, 2, "MS network capability omitted: %u", stcdr.msclass_capomit);
4652                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 9, "SMSC E.164 address: %s", msisdn_to_str(socdr.serv_centr, 9));
4653                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 9, "SGSN E.164 address: %s", msisdn_to_str(socdr.rec_ent, 9));
4654                                 proto_tree_add_text(cdr_tree, tvb, offset+67, 2, "LAC: %u", socdr.lac);
4655                                 proto_tree_add_text(cdr_tree, tvb, offset+69, 1, "RAC: %u", socdr.rac);
4656                                 proto_tree_add_text(cdr_tree, tvb, offset+70, 2, "Cell ID: %u", socdr.cid);
4657                                 proto_tree_add_text(cdr_tree, tvb, offset+72, 4, "Time1: %s", time_int_to_str(socdr.time1));
4658                                 proto_tree_add_text(cdr_tree, tvb, offset+76, 4, "Time2: %s", time_int_to_str(socdr.time2));
4659                                 proto_tree_add_text(cdr_tree, tvb, offset+80, 1, "Message reference: %u", socdr.messref);
4660                                 proto_tree_add_text(cdr_tree, tvb, offset+81, 2, "Delivery result: %u", socdr.smsres);
4661                                 break;
4662
4663                         case 0x16:              /* STCDR */
4664                                 if (tvb_length_remaining(tvb, offset) < 3 + 79) {
4665                                         proto_tree_add_text(ext_tree, tvb, offset, tvb_length_remaining(tvb, offset), "STCDR fragmented, can't dissect");
4666                                         break;
4667                                 }
4668
4669                                 stcdr.len = tvb_get_ntohs(tvb, offset+3);
4670                                 stcdr.imsilen = tvb_get_guint8(tvb, offset+5);
4671                                 tvb_memcpy(tvb, stcdr.imsi, offset+6, 8);
4672                                 tvb_memcpy(tvb, stcdr.imei, offset+14, 8);
4673                                 stcdr.msisdnlen = tvb_get_guint8(tvb, offset+22);
4674                                 tvb_memcpy(tvb, stcdr.msisdn, offset+23, 10);
4675                                 tvb_memcpy(tvb, stcdr.msclass_notused, offset+33, 12);
4676                                 stcdr.msclass_caplen = tvb_get_guint8(tvb, offset+45);
4677                                 stcdr.msclass_cap = tvb_get_guint8(tvb, offset+46);
4678                                 stcdr.msclass_capomit = tvb_get_ntohs(tvb, offset+47);
4679                                 tvb_memcpy(tvb, stcdr.serv_centr, offset+49, 9);
4680                                 tvb_memcpy(tvb, stcdr.rec_ent, offset+58, 9);
4681                                 stcdr.lac = tvb_get_ntohs(tvb, offset+67);
4682                                 stcdr.rac = tvb_get_guint8(tvb, offset+69);
4683                                 stcdr.cid = tvb_get_ntohs(tvb, offset+70);
4684                                 stcdr.time1 = tvb_get_ntohl(tvb, offset+72);
4685                                 stcdr.time2 = tvb_get_ntohl(tvb, offset+76);
4686                                 stcdr.smsres = tvb_get_ntohs(tvb, offset+80);
4687
4688                                 ce = proto_tree_add_text(ext_tree, tvb, offset, data_len + 2, "STCDR (0x16)");
4689                                 cdr_tree = proto_item_add_subtree(ce, ett_gtp_ext);
4690                                 proto_tree_add_text(cdr_tree, tvb, offset, 2, "Length: %u", data_len);
4691                                 proto_tree_add_text(cdr_tree, tvb, offset+2, 1, "Type: %u (%x)", rectype, rectype);
4692                                 proto_tree_add_text(cdr_tree, tvb, offset+3, 2, "MCDR length: %u", stcdr.len);
4693                                 proto_tree_add_text(cdr_tree, tvb, offset+5, 1, "IMSI length: %u", stcdr.imsilen);
4694                                 proto_tree_add_text(cdr_tree, tvb, offset+6, 8, "IMSI: %s", id_to_str(stcdr.imsi));
4695                                 proto_tree_add_text(cdr_tree, tvb, offset+14, 8, "IMEI: %s", id_to_str(stcdr.imei));
4696                                 proto_tree_add_text(cdr_tree, tvb, offset+22, 1, "MSISDN length: %u", stcdr.msisdnlen);
4697                                 proto_tree_add_text(cdr_tree, tvb, offset+23, 10, "MSISDN: %s", msisdn_to_str(stcdr.msisdn, 10));
4698                                 proto_tree_add_text(cdr_tree, tvb, offset+33, 12, "(not used)");
4699                                 proto_tree_add_text(cdr_tree, tvb, offset+45, 1, "MS network capability length: %u", stcdr.msclass_caplen);
4700
4701 /*                              cap_id = proto_tree_add_text(cdr_tree, tvb, offset+46, 1, "MS network capability: %u", stcdr.msclass_cap);
4702                                 cap_tree = proto_item_add_subtree(cap_id, ett_chrg_cap);
4703                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_gea, tvb, offset+46, 1, stcdr.cap);
4704                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gsm, tvb, offset+46, 1, stcdr.cap);
4705                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_sm_gprs, tvb, offset+46, 1, stcdr.cap);
4706                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ucs2, tvb, offset+46, 1, stcdr.cap);
4707                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_ss, tvb, offset+46, 1, stcdr.cap);
4708                                 proto_tree_add_uint(cap_tree, hf_gtpv0_chrg_cap_solsa, tvb, offset+46, 1, stcdr.cap);
4709 */
4710                                 proto_tree_add_text(cdr_tree, tvb, offset+47, 2, "MS network capability omitted: %u", stcdr.msclass_capomit);
4711                                 proto_tree_add_text(cdr_tree, tvb, offset+49, 9, "SMSC E.164 address: %s", msisdn_to_str(stcdr.serv_centr, 9));
4712                                 proto_tree_add_text(cdr_tree, tvb, offset+58, 9, "SGSN E.164 address: %s", msisdn_to_str(stcdr.rec_ent, 9));
4713                                 proto_tree_add_text(cdr_tree, tvb, offset+67, 2, "LAC: %u", stcdr.lac);
4714                                 proto_tree_add_text(cdr_tree, tvb, offset+69, 1, "RAC: %u", stcdr.rac);
4715                                 proto_tree_add_text(cdr_tree, tvb, offset+70, 2, "Cell ID: %u", stcdr.cid);
4716                                 proto_tree_add_text(cdr_tree, tvb, offset+72, 4, "Time1: %s", time_int_to_str(stcdr.time1));
4717                                 proto_tree_add_text(cdr_tree, tvb, offset+76, 4, "Time2: %s", time_int_to_str(stcdr.time2));
4718                                 proto_tree_add_text(cdr_tree, tvb, offset+80, 2, "Delivery result: %u", stcdr.smsres);
4719                                 break;
4720                 }
4721                 offset = offset + 2 + data_len;
4722         }
4723         }
4724         return 3+length;
4725 }
4726
4727 /* GPRS:        12.15
4728  * UMTS:        33.015
4729  */
4730 static int
4731 decode_gtp_data_resp(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4732
4733         guint16         length, n, number;
4734         proto_tree      *ext_tree_data_resp;
4735         proto_item      *te;
4736
4737         length = tvb_get_ntohs(tvb, offset + 1);
4738
4739         te = proto_tree_add_text(tree, tvb, offset, 3 + length, "Requests responded");
4740         ext_tree_data_resp = proto_item_add_subtree(te, ett_gtp_data_resp);
4741
4742         n = 0;
4743
4744         while (n < length) {
4745
4746                 number = tvb_get_ntohs(tvb, offset + 3 + n);
4747                 proto_tree_add_text(ext_tree_data_resp, tvb, offset + 3 + n, 2, "%u", number);
4748                 n = n + 2;
4749
4750         }
4751
4752         return 3 + length;
4753
4754 }
4755
4756 /* GPRS:        12.15
4757  * UMTS:        33.015
4758  */
4759 static int
4760 decode_gtp_node_addr(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4761
4762         guint16         length;
4763         guint32         addr_ipv4;
4764         struct  e_in6_addr addr_ipv6;
4765         proto_tree      *ext_tree_node_addr;
4766         proto_item      *te;
4767
4768         length = tvb_get_ntohs(tvb, offset+1);
4769
4770         te = proto_tree_add_text(tree, tvb, offset, 3+length, "Node address: ");
4771         ext_tree_node_addr = proto_item_add_subtree(te, ett_gtp_node_addr);
4772
4773         proto_tree_add_text(ext_tree_node_addr, tvb, offset+1, 2, "Node address length: %u", length);
4774
4775         switch (length) {
4776                 case 4:
4777                         tvb_memcpy(tvb, (guint8 *)&addr_ipv4, offset+3, sizeof addr_ipv4);
4778                         proto_item_append_text(te, "%s", ip_to_str((guint8 *)&addr_ipv4));
4779                         proto_tree_add_ipv4(ext_tree_node_addr, gtp_version ? hf_gtpv1_node_ipv4 : hf_gtpv0_node_ipv4, tvb, offset+3, 4, addr_ipv4);
4780                         break;
4781                 case 16:
4782                         tvb_memcpy(tvb, (guint8 *)&addr_ipv6, offset+3, sizeof addr_ipv6);
4783                         proto_item_append_text(te, "%s", ip6_to_str((struct e_in6_addr*)&addr_ipv6));
4784                         proto_tree_add_ipv6(ext_tree_node_addr, gtp_version ? hf_gtpv1_node_ipv6 : hf_gtpv0_node_ipv6, tvb, offset+3, 16, (guint8*)&addr_ipv6);
4785                         break;
4786                 default:
4787                         proto_item_append_text(te, "unknown type or wrong length");
4788                         break;
4789         }
4790
4791         return 3 + length;
4792
4793 }
4794
4795 /* GPRS:        9.60 v7.6.0, chapter 7.9.26
4796  * UMTS:        29.060 v4.0, chapter 7.7.44
4797  */
4798 static int
4799 decode_gtp_priv_ext(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4800
4801         guint16         length, ext_id;
4802         gchar           ext_val[64];
4803         proto_tree      *ext_tree_priv_ext;
4804         proto_item      *te;
4805
4806         te = proto_tree_add_text(tree, tvb, offset, 1, val_to_str(GTP_EXT_PRIV_EXT, gtp_val, "Unknown message"));
4807         ext_tree_priv_ext = proto_item_add_subtree(te, ett_gtp_ext);
4808
4809         length = tvb_get_ntohs(tvb, offset+1);
4810         if (length < 1) return 3+length;
4811
4812         ext_id = tvb_get_ntohs(tvb, offset+3);
4813         tvb_memcpy(tvb, ext_val, offset+5, length > 65 ? 63 : length-2);
4814         ext_val[length > 65 ? 64 : length-1] = '\0';
4815         proto_tree_add_uint(ext_tree_priv_ext, gtp_version ? hf_gtpv1_ext_id : hf_gtpv0_ext_id, tvb, offset+3, 2, ext_id);
4816         proto_tree_add_string(ext_tree_priv_ext, gtp_version ? hf_gtpv1_ext_val : hf_gtpv0_ext_val, tvb, offset+5, length-2, ext_val);
4817
4818         return 3+length;
4819 }
4820
4821 static int
4822 decode_gtp_unknown(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree) {
4823
4824         proto_tree_add_text(tree, tvb, offset, 1, "Unknown extension header");
4825
4826         return tvb_length_remaining(tvb, offset);
4827 }
4828
4829 static void
4830 dissect_gtpv0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
4831 {
4832
4833         _gtpv0_hdr      gtpv0_hdr;
4834         proto_item      *ti, *tf;
4835         proto_tree      *gtpv0_tree, *flags_tree;
4836         guint8          ext_hdr_val;
4837         tvbuff_t        *next_tvb;
4838         const guint8    *tid_val;
4839         gchar           *tid_str;
4840         int             offset, length, i, mandatory, checked_field, gtp_prime = 0;
4841
4842         if (check_col(pinfo->cinfo, COL_PROTOCOL))
4843                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP");
4844         if (check_col(pinfo->cinfo, COL_INFO))
4845                 col_clear(pinfo->cinfo, COL_INFO);
4846
4847         tvb_memcpy(tvb, (guint8 *)&gtpv0_hdr, 0, 12);
4848         tid_val = tvb_get_ptr(tvb, 12, 8);
4849         tid_str = id_to_str(tid_val);
4850         gtp_version = (gtpv0_hdr.flags >> 5) & 0x07;
4851
4852         if (!((gtpv0_hdr.flags >> 4) & 1)) {
4853                 gtp_prime = 1;
4854                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
4855                         col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP-CDR");
4856         } else {
4857                 switch ((gtpv0_hdr.flags >> 5) & 0x07) {
4858                 case 0: if (check_col(pinfo->cinfo, COL_PROTOCOL))
4859                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP");
4860                         break;
4861                 case 1: if (check_col(pinfo->cinfo, COL_PROTOCOL))
4862                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTPv1");
4863                 default: if (check_col(pinfo->cinfo, COL_PROTOCOL))
4864                                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTPv?");
4865                         break;
4866                 }
4867         }
4868
4869         if (check_col(pinfo->cinfo, COL_INFO))
4870                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(gtpv0_hdr.message, message_type, "Unknown"));
4871
4872         if (tree) {
4873
4874                 /* dissect GTP header */
4875                 ti = proto_tree_add_item(tree, proto_gtpv0, tvb, 0, -1, FALSE);
4876                 gtpv0_tree = proto_item_add_subtree(ti, ett_gtp);
4877
4878                 tf = proto_tree_add_uint(gtpv0_tree, hf_gtpv0_flags, tvb, 0, 1, gtpv0_hdr.flags);
4879
4880                 flags_tree = proto_item_add_subtree(tf, ett_gtp_flags);
4881                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_ver, tvb, 0, 1, gtpv0_hdr.flags);
4882                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_pt, tvb, 0, 1, gtpv0_hdr.flags);
4883                 proto_tree_add_uint(flags_tree, hf_gtpv0_flags_spare, tvb, 0, 1, gtpv0_hdr.flags);
4884                 proto_tree_add_boolean(flags_tree, hf_gtpv0_flags_snn, tvb, 0, 1, gtpv0_hdr.flags);
4885
4886                 gtpv0_hdr.length = g_ntohs(gtpv0_hdr.length);
4887                 gtpv0_hdr.seq_no = g_ntohs(gtpv0_hdr.seq_no);
4888                 gtpv0_hdr.flow_label = g_ntohs(gtpv0_hdr.flow_label);
4889                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_message_type, tvb, 1, 1, gtpv0_hdr.message);
4890                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_length, tvb, 2, 2, gtpv0_hdr.length);
4891                 proto_tree_add_uint(gtpv0_tree, hf_gtpv0_seq_number, tvb, 4, 2, gtpv0_hdr.seq_no);
4892
4893                 /* GTP' has 6 bytes of length */
4894                 if (!gtp_prime) {
4895                         proto_tree_add_uint(gtpv0_tree, hf_gtpv0_flow_label, tvb, 6, 2, gtpv0_hdr.flow_label);
4896                         proto_tree_add_uint(gtpv0_tree, hf_gtpv0_sndcp_number, tvb, 8, 1, gtpv0_hdr.sndcp_no);
4897                         proto_tree_add_string(gtpv0_tree, hf_gtpv0_tid, tvb, 12, 8, tid_str);
4898                 }
4899
4900                 if (gtpv0_hdr.message != GTP_MSG_TPDU) {
4901
4902                         proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[--- end of GTPv0 header, beginning of extension headers ---]");
4903
4904                         offset = gtp_prime ? GTP_PRIME_HDR_LENGTH : GTPv0_HDR_LENGTH;
4905
4906                         length = tvb_length(tvb);
4907
4908                         mandatory = 0;          /* check order of GTP fields against ETSI */
4909
4910                         for (;;) {
4911
4912                                 if (offset >= length) break;
4913                                 ext_hdr_val = tvb_get_guint8(tvb, offset);
4914
4915                                 if (gtpv0_etsi_order) {
4916                                         checked_field = check_field_presence (gtpv0_hdr.message, ext_hdr_val , (int *)&mandatory);
4917                                         switch (checked_field) {
4918                                                 case -2: proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[WARNING] message not found");
4919                                                          break;
4920                                                 case -1: proto_tree_add_text(gtpv0_tree, tvb, 0, 0, "[WARNING] field not present");
4921                                                          break;
4922                                                 case 0:  break;
4923                                                 default: proto_tree_add_text(gtpv0_tree, tvb, offset, 1, "[WARNING] wrong next field, should be: %s", val_to_str(checked_field, gtp_val, "Unknown extension field"));
4924                                         }
4925                                 }
4926
4927                                 i = -1;
4928                                 while (gtpopt[++i].optcode) if (gtpopt[i].optcode == ext_hdr_val) break;
4929                                 offset = offset + (*gtpopt[i].decode)(tvb, offset, pinfo, gtpv0_tree);
4930                         }
4931                 }
4932         }
4933
4934 /* next part dissects sublayers of GTP */
4935
4936         if ((gtpv0_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
4937                 guint8 sub_proto;
4938             
4939                 sub_proto = tvb_get_guint8(tvb,GTPv0_HDR_LENGTH);
4940
4941                 if ((sub_proto >= 0x45) &&  (sub_proto <= 0x4e)) {
4942                     /* this is most likely an IPv4 packet */
4943                     /* we can exclude 0x40 - 0x44 because the minimum header size is 20 octets */
4944                     /* 0x4f is excluded because PPP protocol type "IPv6 header compression" 
4945                        with protocol field compression is more likely than a plain IPv4 packet with 60 octet header size */    
4946                     
4947                     next_tvb = tvb_new_subset(tvb, GTPv0_HDR_LENGTH, -1, -1);
4948                     call_dissector(ip_handle, next_tvb, pinfo, tree);
4949                 } else
4950                 if ((sub_proto & 0xf0) == 0x60) {
4951                     /* this is most likely an IPv6 packet */
4952                     next_tvb = tvb_new_subset(tvb, GTPv0_HDR_LENGTH, -1, -1);
4953                     call_dissector(ipv6_handle, next_tvb, pinfo, tree);
4954                 } else {
4955                     /* this seems to be a PPP packet */
4956                     guint8 acfield_len = 0;
4957
4958                     if (sub_proto == 0xff) {
4959                         /* this might be an address field, even it shouldn't be here */
4960                         guint8 control_field = tvb_get_guint8(tvb,GTPv0_HDR_LENGTH + 1);
4961                         if (control_field == 0x03) {
4962                             /* now we are pretty sure that address and control field are mistakenly inserted -> ignore it for PPP dissection */
4963                             acfield_len = 2;
4964                         }
4965                     }
4966                     next_tvb = tvb_new_subset(tvb, GTPv0_HDR_LENGTH + acfield_len, -1, -1);
4967                     call_dissector(ppp_handle, next_tvb, pinfo, tree);
4968                 }
4969             if (check_col(pinfo->cinfo, COL_PROTOCOL))
4970                     col_append_str_gtp(pinfo->cinfo, COL_PROTOCOL, "GTP");
4971         }
4972 }
4973
4974 /* GTP v1 dissector */
4975 static void
4976 dissect_gtpv1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
4977
4978         _gtpv1_hdr      gtpv1_hdr;
4979         proto_item      *ti, *tf;
4980         proto_tree      *gtpv1_tree, *flags_tree;
4981         guint16         seq_no;
4982         guint8          ext_hdr_val, i, hdr_offset = 4, next_hdr, npdu_no, sub_proto;
4983         tvbuff_t        *next_tvb;
4984         int             offset, length, mandatory, checked_field, gtp_prime = 0;
4985
4986         if (check_col(pinfo->cinfo, COL_PROTOCOL))
4987                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTP-C");
4988         if (check_col(pinfo->cinfo, COL_INFO))
4989                 col_clear(pinfo->cinfo, COL_INFO);
4990
4991         tvb_memcpy(tvb, (guint8 *)&gtpv1_hdr, 0, 8);
4992         gtp_version = (gtpv1_hdr.flags >> 5) & 0x07;
4993
4994         if (check_col(pinfo->cinfo, COL_INFO))
4995                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(gtpv1_hdr.message, message_type, "Unknown"));
4996
4997         if (tree) {
4998
4999                 ti = proto_tree_add_item(tree, proto_gtpv1, tvb, 0, -1, FALSE);
5000                 gtpv1_tree = proto_item_add_subtree(ti, ett_gtp);
5001
5002                 tf = proto_tree_add_uint(gtpv1_tree, hf_gtpv1_flags, tvb, 0, 1, gtpv1_hdr.flags);
5003                 flags_tree = proto_item_add_subtree(tf, ett_gtp_flags);
5004
5005                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_ver, tvb, 0, 1, gtpv1_hdr.flags);
5006                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_pt, tvb, 0, 1, gtpv1_hdr.flags);
5007                 proto_tree_add_uint(flags_tree, hf_gtpv1_flags_spare, tvb, 0, 1, gtpv1_hdr.flags);
5008                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_e, tvb, 0, 1, gtpv1_hdr.flags);
5009                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_s, tvb, 0, 1, gtpv1_hdr.flags);
5010                 proto_tree_add_boolean(flags_tree, hf_gtpv1_flags_pn, tvb, 0, 1, gtpv1_hdr.flags);
5011
5012                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_message_type, tvb, 1, 1, gtpv1_hdr.message);
5013
5014                 gtpv1_hdr.length = g_ntohs(gtpv1_hdr.length);
5015                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_length, tvb, 2, 2, gtpv1_hdr.length);
5016
5017                 gtp_prime = (gtpv1_hdr.flags & 0x01) >> 4;
5018
5019                 /* GTP' has 6 bytes of length */
5020
5021                 if (!gtp_prime) {
5022
5023                         gtpv1_hdr.teid = g_ntohl(gtpv1_hdr.teid);
5024                         proto_tree_add_uint(gtpv1_tree, hf_gtpv1_teid, tvb, 4, 4, gtpv1_hdr.teid);
5025
5026                         if (gtpv1_hdr.flags & 0x07) {
5027                                 seq_no = tvb_get_ntohs (tvb, 8);
5028                                 proto_tree_add_uint (gtpv1_tree, hf_gtpv1_seq_number, tvb, 8, 2, seq_no);
5029                                 npdu_no = tvb_get_guint8 (tvb, 10);
5030                                 proto_tree_add_uint (gtpv1_tree, hf_gtpv1_npdu_number, tvb, 10, 1, npdu_no);
5031                                 next_hdr = tvb_get_guint8(tvb, 11);
5032                                 proto_tree_add_uint(gtpv1_tree, hf_gtpv1_next, tvb, 11, 1, next_hdr);
5033                                 hdr_offset = 0;
5034
5035                                 if (next_hdr) hdr_offset = 1;
5036                                 else hdr_offset = 0;
5037                         }
5038                 }
5039
5040                 if (gtpv1_hdr.message != GTP_MSG_TPDU) {
5041
5042                         proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[--- end of GTP v1 header, beginning of extension headers ---]");
5043
5044                         offset = gtp_prime ? GTP_PRIME_HDR_LENGTH: GTPv1_HDR_LENGTH - hdr_offset;
5045                         length = tvb_length(tvb);
5046
5047                         mandatory = 0;          /* check order of GTP fields against ETSI */
5048
5049                         for (;;) {
5050
5051                                 if (offset >= length) break;
5052                                 ext_hdr_val = tvb_get_guint8(tvb, offset);
5053
5054                                 if (gtpv1_etsi_order) {
5055                                         checked_field = check_field_presence (gtpv1_hdr.message, ext_hdr_val , (int *)&mandatory);
5056                                         switch (checked_field) {
5057                                                 case -2: proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[WARNING] message not found");
5058                                                          break;
5059                                                 case -1: proto_tree_add_text(gtpv1_tree, tvb, 0, 0, "[WARNING] field not present");
5060                                                          break;
5061                                                 case 0:  break;
5062                                                 default: proto_tree_add_text(gtpv1_tree, tvb, offset, 1, "[WARNING] wrong next field, should be: %s", val_to_str(checked_field, gtp_val, "Unknown extension field"));
5063                                         }
5064                                 }
5065
5066                                 i = -1;
5067                                 while (gtpopt[++i].optcode) if (gtpopt[i].optcode == ext_hdr_val) break;
5068                                 offset = offset + (*gtpopt[i].decode)(tvb, offset, pinfo, gtpv1_tree);
5069                         }
5070                 }
5071         }
5072
5073         if (gtpv1_hdr.message == GTP_MSG_ERR_IND)
5074                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
5075                         col_add_str(pinfo->cinfo, COL_PROTOCOL, "GTP-U");
5076
5077
5078         if ((gtpv1_hdr.message == GTP_MSG_TPDU) && gtp_tpdu) {
5079
5080                 if (gtpv1_hdr.flags & 0x07) {
5081                         if (tvb_get_guint8 (tvb, 11))
5082                                 hdr_offset = 1;         /* if next_hdr != 0 */
5083                         else
5084                                 hdr_offset = 0;
5085                 }
5086
5087                 sub_proto = tvb_get_guint8(tvb,GTPv1_HDR_LENGTH - hdr_offset);
5088
5089                 if ((sub_proto >= 0x45) &&  (sub_proto <= 0x4e)) {
5090                     /* this is most likely an IPv4 packet */
5091                     /* we can exclude 0x40 - 0x44 because the minimum header size is 20 octets */
5092                     /* 0x4f is excluded because PPP protocol type "IPv6 header compression" 
5093                        with protocol field compression is more likely than a plain IPv4 packet with 60 octet header size */    
5094                     
5095                     next_tvb = tvb_new_subset(tvb, GTPv1_HDR_LENGTH - hdr_offset, -1, -1);
5096                     call_dissector(ip_handle, next_tvb, pinfo, tree);
5097                 } else
5098                 if ((sub_proto & 0xf0) == 0x60)
5099                 {
5100                     /* this is most likely an IPv6 packet */
5101                     next_tvb = tvb_new_subset(tvb, GTPv1_HDR_LENGTH - hdr_offset, -1, -1);
5102                     call_dissector(ipv6_handle, next_tvb, pinfo, tree);
5103                 } else {
5104                     /* this seems to be a PPP packet */
5105                     guint8 acfield_len = 0;
5106
5107                     if (sub_proto == 0xff) {
5108                         /* this might be an address field, even it shouldn't be here */
5109                         guint8 control_field; 
5110                         control_field = tvb_get_guint8(tvb,GTPv1_HDR_LENGTH - hdr_offset + 1);
5111                         if (control_field == 0x03)
5112                         {
5113                             /* now we are pretty sure that address and control field are mistakenly inserted -> ignore it for PPP dissection */
5114                             acfield_len = 2;
5115                         }
5116                     }
5117                     next_tvb = tvb_new_subset(tvb, GTPv1_HDR_LENGTH - hdr_offset + acfield_len, -1, -1);
5118                     call_dissector(ppp_handle, next_tvb, pinfo, tree);
5119                 }
5120             if (check_col(pinfo->cinfo, COL_PROTOCOL))
5121                     col_append_str_gtp(pinfo->cinfo, COL_PROTOCOL, "GTP-U");
5122         }
5123 }
5124
5125 static const true_false_string yes_no_tfs = {
5126         "yes" ,
5127         "no"
5128 };
5129
5130 void
5131 proto_register_gtp(void)
5132 {
5133
5134         static hf_register_info hf_gtpv0[] = {
5135
5136         { &hf_gtpv0_flags,              { "Flags",              "gtpv0.flags",                  FT_UINT8,       BASE_HEX, NULL, 0, "Ver/PT/Spare/SNN", HFILL }},
5137         { &hf_gtpv0_flags_ver,          { "Version",            "gtpv0.flags.version",          FT_UINT8,       BASE_DEC, VALS(ver_types), GTP_VER_MASK, "GTP Version", HFILL }},
5138         { &hf_gtpv0_flags_pt,           { "Protocol type",      "gtpv0.flags.payload",          FT_UINT8,       BASE_DEC, NULL, GTP_PT_MASK, "Protocol Type (1 = GTP, 0 = GTP' )", HFILL }},
5139         { &hf_gtpv0_flags_spare,                { "Reserved",           "gtpv0.flags.reserved",         FT_UINT8,       BASE_DEC, NULL, GTP_SPARE_MASK, "Reserved (shall be sent as '111' )", HFILL }},
5140         { &hf_gtpv0_flags_snn,          { "Is SNDCP N-PDU included?", "gtpv0.flags.snn",        FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTP_SNN_MASK, "Is SNDCP N-PDU LLC Number included? (1 = yes, 0 = no)", HFILL }},
5141         { &hf_gtpv0_message_type,               { "Message type",       "gtpv0.message",                FT_UINT8,       BASE_HEX, VALS(message_type), 0x0, "GTP Message Type", HFILL }},
5142         { &hf_gtpv0_length,             { "Length",             "gtpv0.length",                 FT_UINT16,      BASE_DEC, NULL, 0, "Length (i.e. number of octets after TID or TEID)", HFILL }},
5143         { &hf_gtpv0_seq_number,         { "Sequence number",    "gtpv0.seq_number",             FT_UINT16,      BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
5144         { &hf_gtpv0_flow_label,         { "Flow label",         "gtpv0.flow_label",             FT_UINT16,      BASE_HEX, NULL, 0, "Flow label", HFILL }},
5145         { &hf_gtpv0_sndcp_number,               { "SNDCP N-PDU LLC Number", "gtpv0.sndcp_number",               FT_UINT8,       BASE_HEX, NULL, 0, "SNDCP N-PDU LLC Number", HFILL }},
5146         { &hf_gtpv0_tid,                        { "TID",                "gtpv0.tid",                    FT_STRING,      BASE_DEC, NULL, 0, "Tunnel Identifier", HFILL }},
5147         { &hf_gtpv0_cause,              { "Cause",              "gtpv0.cause",                  FT_UINT8,       BASE_DEC, VALS(cause_type), 0, "Cause of operation", HFILL }},
5148         { &hf_gtpv0_imsi,                       { "IMSI",               "gtpv0.imsi",                   FT_STRING,      BASE_DEC, NULL, 0, "International Mobile Subscriber Identity number", HFILL }},
5149         { &hf_gtpv0_rai_mcc,            { "MCC",                "gtpv0.mcc",                    FT_UINT16,      BASE_DEC, NULL, 0, "Mobile Country Code", HFILL }},
5150         { &hf_gtpv0_rai_mnc,            { "MNC",                "gtpv0.mnc",                    FT_UINT8,       BASE_DEC, NULL, 0, "Mobile Network Code", HFILL }},
5151         { &hf_gtpv0_rai_rac,            { "RAC",                "gtpv0.rac",                    FT_UINT8,       BASE_DEC, NULL, 0, "Routing Area Code", HFILL }},
5152         { &hf_gtpv0_rai_lac,            { "LAC",                "gtpv0.lac",                    FT_UINT16,      BASE_DEC, NULL, 0, "Location Area Code", HFILL }},
5153         { &hf_gtpv0_tlli,                       { "TLLI",               "gtpv0.tlli",                   FT_UINT32,      BASE_HEX, NULL, 0, "Temporary Logical Link Identity", HFILL }},
5154         { &hf_gtpv0_ptmsi,              { "P-TMSI",             "gtpv0.ptmsi",                  FT_UINT32,      BASE_HEX, NULL, 0, "Packet-Temporary Mobile Subscriber Identity", HFILL }},
5155         { &hf_gtpv0_qos_spare1,         { "Spare",              "gtpv0.qos_spare1",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE1_MASK, "Spare (shall be sent as '00' )", HFILL }},
5156         { &hf_gtpv0_qos_delay,          { "QoS delay",          "gtpv0.qos_delay",              FT_UINT8,       BASE_DEC, VALS(qos_delay_type), GTP_EXT_QOS_DELAY_MASK, "Quality of Service Delay Class", HFILL }},
5157         { &hf_gtpv0_qos_reliability,    { "QoS reliability",    "gtpv0.qos_reliabilty",         FT_UINT8,       BASE_DEC, VALS(qos_reliability_type), GTP_EXT_QOS_RELIABILITY_MASK, "Quality of Service Reliability Class", HFILL }},
5158         { &hf_gtpv0_qos_peak,           { "QoS peak",           "gtpv0.qos_peak",               FT_UINT8,       BASE_DEC, VALS(qos_peak_type), GTP_EXT_QOS_PEAK_MASK, "Quality of Service Peak Throughput", HFILL }},
5159         { &hf_gtpv0_qos_spare2,         { "Spare",              "gtpv0.qos_spare2",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE2_MASK, "Spare (shall be sent as 0)", HFILL }},
5160         { &hf_gtpv0_qos_precedence,     { "QoS precedence",     "gtpv0.qos_precedence",         FT_UINT8,       BASE_DEC, VALS(qos_precedence_type), GTP_EXT_QOS_PRECEDENCE_MASK, "Quality of Service Precedence Class", HFILL }},
5161         { &hf_gtpv0_qos_spare3,         { "Spare",              "gtpv0.qos_spare3",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE3_MASK, "Spare (shall be sent as '000' )", HFILL }},
5162         { &hf_gtpv0_qos_mean,           { "QoS mean",           "gtpv0.qos_mean",               FT_UINT8,       BASE_DEC, VALS(qos_mean_type), GTP_EXT_QOS_MEAN_MASK, "Quality of Service Mean Throughput", HFILL }},
5163         { &hf_gtpv0_reorder,            { "Reordering required","gtpv0.reorder",                FT_BOOLEAN,     BASE_NONE,NULL, 0, "Reordering required", HFILL }},
5164         { &hf_gtpv0_map_cause,          { "MAP cause",          "gtpv0.map_cause",              FT_UINT8,       BASE_DEC, VALS(map_cause_type), 0, "MAP cause", HFILL }},
5165         { &hf_gtpv0_ptmsi_sig,          { "P-TMSI signature",   "gtpv0.ptmsi_sig",              FT_UINT24,      BASE_HEX, NULL, 0, "P-TMSI Signature", HFILL }},
5166         { &hf_gtpv0_ms_valid,           { "MS validated",       "gtpv0.ms_valid",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "MS validated", HFILL }},
5167         { &hf_gtpv0_recovery,           { "Recovery",           "gtpv0.recovery",               FT_UINT8,       BASE_DEC, NULL, 0, "Restart counter", HFILL }},
5168         { &hf_gtpv0_sel_mode,           { "Selection mode",     "gtpv0.sel_mode",               FT_UINT8,       BASE_DEC, VALS(sel_mode_type), 0, "Selection Mode", HFILL }},
5169         { &hf_gtpv0_ext_flow_label,     { "Flow Label Data I",  "gtpv0.ext_flow_label",         FT_UINT16,      BASE_DEC, NULL, 0, "Flow label data", HFILL }},
5170         { &hf_gtpv0_flow_sig,           { "Flow label Signalling",      "gtpv0.flow_sig",       FT_UINT16,      BASE_DEC, NULL, 0, "Flow label signalling", HFILL }},
5171         { &hf_gtpv0_nsapi,              { "NSAPI ",             "gtpv0.nsapi",                  FT_UINT8,       BASE_DEC, NULL, 0, "Network layer Service Access Point Identifier", HFILL }},
5172         { &hf_gtpv0_flow_ii,            { "Flow Label Data II ","gtpv0.flow_ii",                FT_UINT16,      BASE_DEC, NULL, 0, "Downlink flow label data", HFILL }},
5173         { &hf_gtpv0_ms_reason,          { "MS not reachable reason",    "gtpv0.ms_reason",      FT_UINT8,       BASE_DEC, VALS(ms_not_reachable_type), 0, "MS Not Reachable Reason", HFILL }},
5174         { &hf_gtpv0_tr_comm,            { "Packet transfer command",    "gtpv0.tr_comm",        FT_UINT8,       BASE_DEC, VALS(tr_comm_type), 0, "Packat transfer command", HFILL }},
5175         { &hf_gtpv0_chrg_id,            { "Charging ID ",       "gtpv0.chrg_id",                FT_UINT32,      BASE_HEX, NULL, 0, "Charging ID", HFILL }},
5176         { &hf_gtpv0_user_ipv4,          { "End user address IPv4",      "gtpv0.user_ipv4",      FT_IPv4,        BASE_DEC, NULL, 0, "End user address IPv4", HFILL }},
5177         { &hf_gtpv0_user_ipv6,          { "End user address IPv6",      "gtpv0.user_ipv6",      FT_IPv6,        BASE_HEX, NULL, 0, "End user address IPv6", HFILL }},
5178         { &hf_gtpv0_user_addr_pdp_org,  { "PDP type organization",      "gtpv0.user_addr_pdp_org",      FT_UINT8,       BASE_DEC, VALS(pdp_org_type), 0, "PDP type organization", HFILL }},
5179         { &hf_gtpv0_user_addr_pdp_type, { "PDP type number",    "gtpv0.user_addr_pdp_type",     FT_UINT8,       BASE_HEX, VALS(pdp_type), 0, "PDP type", HFILL }},
5180         { &hf_gtpv0_apn,                        { "APN",                "gtpv0.apn",                    FT_STRING,      BASE_DEC, NULL, 0, "Access Point Name", HFILL }},
5181         { &hf_gtpv0_gsn_addr_type,      { "GSN address type",   "gtpv0.gsn_addr_type",          FT_UINT8,       BASE_DEC, VALS(gsn_addr_type), GTP_EXT_GSN_ADDR_TYPE_MASK, "GSN Address Type", HFILL }},
5182         { &hf_gtpv0_gsn_addr_len,               { "GSN address length", "gtpv0.gsn_addr_len",           FT_UINT8,       BASE_DEC, NULL, GTP_EXT_GSN_ADDR_LEN_MASK, "GSN Address Length", HFILL }},
5183         { &hf_gtpv0_gsn_ipv4,           { "GSN address IPv4",   "gtpv0.gsn_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "GSN address IPv4", HFILL }},
5184         { &hf_gtpv0_gsn_ipv6,           { "GSN address IPv6",   "gtpv0.gsn_ipv6",               FT_IPv6,        BASE_DEC, NULL, 0, "GSN address IPv6", HFILL }},
5185         { &hf_gtpv0_msisdn,             { "MSISDN",             "gtpv0.msisdn",                 FT_STRING,      BASE_DEC, NULL, 0, "MS international PSTN/ISDN number", HFILL }},
5186         { &hf_gtpv0_chrg_ipv4,          { "CG address IPv4",    "gtpv0.chrg_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Charging Gateway address IPv4", HFILL }},
5187         { &hf_gtpv0_chrg_ipv6,          { "CG address IPv6",    "gtpv0.chrg_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Charging Gateway address IPv6", HFILL }},
5188         { &hf_gtpv0_node_ipv4,          { "Node address IPv4",  "gtpv0.node_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Recommended node address IPv4", HFILL }},
5189         { &hf_gtpv0_node_ipv6,          { "Node address IPv6",  "gtpv0.node_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Recommended node address IPv6", HFILL }},
5190         { &hf_gtpv0_ext_id,             { "Extension identifier",       "gtpv0.ext_id",         FT_UINT16,      BASE_DEC, NULL, 0, "Extension Identifier", HFILL }},
5191         { &hf_gtpv0_ext_val,            { "Extension value",            "gtpv0.ext_val",        FT_STRING,      BASE_DEC, NULL, 0, "Extension Value", HFILL }},
5192         { &hf_gtpv0_unknown,            { "Unknown data (length)",      "gtpv0.unknown",        FT_UINT16,      BASE_DEC, NULL, 0, "Unknown data", HFILL }},
5193
5194         };
5195
5196
5197         static hf_register_info hf_gtpv1[] = {
5198
5199         { &hf_gtpv1_flags,              { "Flags",              "gtpv1.flags",                  FT_UINT8,       BASE_HEX, NULL, 0, "Ver/PT/Spare/E/S/PN", HFILL }},
5200         { &hf_gtpv1_flags_ver,          { "Version",            "gtpv1.flags.version",          FT_UINT8,       BASE_DEC, VALS(ver_types), GTP_VER_MASK, "GTP Version", HFILL }},
5201         { &hf_gtpv1_flags_pt,           { "Protocol type",      "gtpv1.flags.payload_type",     FT_UINT8,       BASE_DEC, NULL, GTP_PT_MASK, "Protocol Type (1 = GTP, 0 = GPRS charging protocol : GTP' )", HFILL }},
5202         { &hf_gtpv1_flags_spare,                { "Spare bit",          "gtpv1.flags.spare",            FT_UINT8,       BASE_DEC, NULL, GTPv1_SPARE_MASK, "Spare bit (shall be sent as 0)", HFILL }},
5203         { &hf_gtpv1_flags_e,            { "Is Next Extension Header present?",  "gtpv1.flags.e",                FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTPv1_E_MASK, "Is Next Extension Header present? (1 = yes, 0 = no)", HFILL }},
5204         { &hf_gtpv1_flags_s,            { "Is Sequence Number present?",        "gtpv1.flags.s",                FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTPv1_S_MASK, "Is Sequence Number present? (1 = yes, 0 = no)", HFILL }},
5205         { &hf_gtpv1_flags_pn,           { "Is N-PDU number present?",   "gtpv1.flags.pn",               FT_BOOLEAN,     8, TFS(&yes_no_tfs), GTPv1_PN_MASK, "Is N-PDU number present? (1 = yes, 0 = no)", HFILL }},
5206         { &hf_gtpv1_message_type,               { "Message Type",       "gtpv1.message",                FT_UINT8,       BASE_HEX, VALS(message_type), 0x0, "GTP Message Type", HFILL }},
5207         { &hf_gtpv1_length,             { "Length",             "gtpv1.length",                 FT_UINT16,      BASE_DEC, NULL, 0, "Length (i.e. number of octets after TID or TEID)", HFILL }},
5208         { &hf_gtpv1_seq_number,         { "Sequence Number",    "gtpv1.seq_number",             FT_UINT16,      BASE_HEX, NULL, 0, "Sequence Number", HFILL }},
5209         { &hf_gtpv1_teid,                       { "TEID",               "gtpv1.teid",                   FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier", HFILL }},
5210         { &hf_gtpv1_npdu_number,                { "N-PDU Number",       "gtpv1.npdu_number",            FT_UINT8,       BASE_HEX, NULL, 0, "N-PDU Number", HFILL }},
5211         { &hf_gtpv1_next,                       { "Next extension header type", "gtpv1.next",           FT_UINT8,       BASE_HEX, NULL, 0, "Next Extension Header Type", HFILL }},
5212         { &hf_gtpv1_cause,              { "Cause ",             "gtpv1.cause",                  FT_UINT8,       BASE_DEC, VALS(cause_type), 0, "Cause of operation", HFILL }},
5213         { &hf_gtpv1_imsi,                       { "IMSI",               "gtpv1.imsi",                   FT_STRING,      BASE_DEC, NULL, 0, "International Mobile Subscriber Identity number", HFILL }},
5214         { &hf_gtpv1_rai_mcc,            { "MCC",                "gtpv1.mcc",                    FT_UINT16,      BASE_DEC, NULL, 0, "Mobile Country Code", HFILL }},
5215         { &hf_gtpv1_rai_mnc,            { "MNC",                "gtpv1.mnc",                    FT_UINT8,       BASE_DEC, NULL, 0, "Mobile Network Code", HFILL }},
5216         { &hf_gtpv1_rai_rac,            { "RAC",                "gtpv1.rac",                    FT_UINT8,       BASE_DEC, NULL, 0, "Routing Area Code", HFILL }},
5217         { &hf_gtpv1_rai_lac,            { "LAC",                "gtpv1.lac",                    FT_UINT16,      BASE_DEC, NULL, 0, "Location Area Code", HFILL }},
5218         { &hf_gtpv1_tlli,                       { "TLLI",               "gtpv1.tlli",                   FT_UINT32,      BASE_HEX, NULL, 0, "Temporary Logical Link Identity", HFILL }},
5219         { &hf_gtpv1_ptmsi,              { "P-TMSI",             "gtpv1.ptmsi",                  FT_UINT32,      BASE_HEX, NULL, 0, "Packet-Temporary Mobile Subscriber Identity", HFILL }},
5220         { &hf_gtpv1_qos_spare1,         { "Spare",              "gtpv1.qos_spare1",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE1_MASK, "Spare (shall be sent as '00' )", HFILL }},
5221         { &hf_gtpv1_qos_delay,          { "QoS Delay",          "gtpv1.qos_delay",              FT_UINT8,       BASE_DEC, VALS(qos_delay_type), GTP_EXT_QOS_DELAY_MASK, "Quality of Service Delay Class", HFILL }},
5222         { &hf_gtpv1_qos_reliability,    { "QoS Reliability",    "gtpv1.qos_reliabilty",         FT_UINT8,       BASE_DEC, VALS(qos_reliability_type), GTP_EXT_QOS_RELIABILITY_MASK, "Quality of Service Reliability Class", HFILL }},
5223         { &hf_gtpv1_qos_peak,           { "QoS Peak",           "gtpv1.qos_peak",               FT_UINT8,       BASE_DEC, VALS(qos_peak_type), GTP_EXT_QOS_PEAK_MASK, "Quality of Service Peak Throughput", HFILL }},
5224         { &hf_gtpv1_qos_spare2,         { "Spare",              "gtpv1.qos_spare2",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE2_MASK, "Spare (shall be sent as 0)", HFILL }},
5225         { &hf_gtpv1_qos_precedence,     { "QoS Precedence",     "gtpv1.qos_precedence",         FT_UINT8,       BASE_DEC, VALS(qos_precedence_type), GTP_EXT_QOS_PRECEDENCE_MASK, "Quality of Service Precedence Class", HFILL }},
5226         { &hf_gtpv1_qos_spare3,         { "Spare",              "gtpv1.qos_spare3",             FT_UINT8,       BASE_DEC, NULL, GTP_EXT_QOS_SPARE3_MASK, "Spare (shall be sent as '000' )", HFILL }},
5227         { &hf_gtpv1_qos_mean,           { "QoS Mean",           "gtpv1.qos_mean",               FT_UINT8,       BASE_DEC, VALS(qos_mean_type), GTP_EXT_QOS_MEAN_MASK, "Quality of Service Mean Throughput", HFILL }},
5228         { &hf_gtpv1_reorder,            { "Reordering required","gtpv1.reorder",                FT_BOOLEAN,     BASE_NONE,NULL, 0, "Reordering required", HFILL }},
5229         { &hf_gtpv1_map_cause,          { "MAP cause",          "gtpv1.map_cause",              FT_UINT8,       BASE_DEC, VALS(map_cause_type), 0, "MAP cause", HFILL }},
5230         { &hf_gtpv1_ptmsi_sig,          { "P-TMSI Signature",   "gtpv1.ptmsi_sig",              FT_UINT24,      BASE_HEX, NULL, 0, "P-TMSI Signature", HFILL }},
5231         { &hf_gtpv1_ms_valid,           { "MS validated",       "gtpv1.ms_valid",               FT_BOOLEAN,     BASE_NONE,NULL, 0, "MS validated", HFILL }},
5232         { &hf_gtpv1_recovery,           { "Recovery",           "gtpv1.recovery",               FT_UINT8,       BASE_DEC, NULL, 0, "Restart counter", HFILL }},
5233         { &hf_gtpv1_sel_mode,           { "Selection Mode",     "gtpv1.sel_mode",               FT_UINT8,       BASE_DEC, VALS(sel_mode_type), 0, "Selection Mode", HFILL }},
5234         { &hf_gtpv1_teid_data,          { "TEID Data I",        "gtpv1.teid_data",              FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data I", HFILL }},
5235         { &hf_gtpv1_teid_cp,            { "TEID Control Plane", "gtpv1.teid_cp",                FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Control Plane", HFILL }},
5236         { &hf_gtpv1_nsapi,              { "NSAPI",              "gtpv1.nsapi",                  FT_UINT8,       BASE_DEC, NULL, 0, "Network layer Service Access Point Identifier", HFILL }},
5237         { &hf_gtpv1_teid_ii,            { "TEID Data II",       "gtpv1.teid_ii",                FT_UINT32,      BASE_HEX, NULL, 0, "Tunnel Endpoint Identifier Data II", HFILL }},
5238         { &hf_gtpv1_tear_ind,           { "Teardown Indicator","gtpv1.tear_ind",                FT_BOOLEAN,     BASE_NONE,NULL, 0, "Teardown Indicator", HFILL }},
5239         { &hf_gtpv1_ranap_cause,                { "RANAP cause",        "gtpv1.ranap_cause",            FT_UINT8,       BASE_DEC, VALS(ranap_cause_type), 0, "RANAP cause", HFILL }},
5240         { &hf_gtpv1_rab_gtpu_dn,                { "Downlink GTP-U seq number",  "gtpv1.rab_gtp_dn",     FT_UINT16,      BASE_DEC, NULL, 0, "Downlink GTP-U sequence number", HFILL }},
5241         { &hf_gtpv1_rab_gtpu_up,                { "Uplink GTP-U seq number",    "gtpv1.rab_gtp_up",     FT_UINT16,      BASE_DEC, NULL, 0, "Uplink GTP-U sequence number", HFILL }},
5242         { &hf_gtpv1_rab_pdu_dn,         { "Downlink next PDCP-PDU seq number",  "gtpv1.rab_pdu_dn",             FT_UINT8,       BASE_DEC, NULL, 0, "Downlink next PDCP-PDU sequence number", HFILL }},
5243         { &hf_gtpv1_rab_pdu_up,         { "Uplink next PDCP-PDU seq number",    "gtpv1.rab_pdu_up",             FT_UINT8,       BASE_DEC, NULL, 0, "Uplink next PDCP-PDU sequence number", HFILL }},
5244         { &hf_gtpv1_rp_sms,             { "Radio Priority SMS", "gtpv1.rp_sms",                 FT_UINT8,       BASE_DEC, NULL, 0, "Radio Priority for MO SMS", HFILL }},
5245         { &hf_gtpv1_rp_nsapi,           { "NSAPI in Radio Priority",    "gtpv1.rp_nsapi",       FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_NSAPI_MASK, "Network layer Service Access Point Identifier in Radio Priority", HFILL }},
5246         { &hf_gtpv1_rp_spare,           { "Reserved",           "gtpv1.rp_spare",               FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_SPARE_MASK, "Spare bit", HFILL }},
5247         { &hf_gtpv1_rp,                 { "Radio Priority",     "gtpv1.rp",                     FT_UINT8,       BASE_DEC, NULL, GTPv1_EXT_RP_MASK, "Radio Priority for uplink tx", HFILL }},
5248         { &hf_gtpv1_pkt_flow_id,                { "Packet Flow ID",     "gtpv1.pkt_flow_id",            FT_UINT8,       BASE_DEC, NULL, 0, "Packet Flow ID", HFILL }},
5249         { &hf_gtpv1_chrg_char_s,                { "Spare",              "gtpv1.chrg_char_s",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_S, "Spare", HFILL }},
5250         { &hf_gtpv1_chrg_char_n,                { "Normal charging",    "gtpv1.chrg_char_n",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_N, "Normal charging", HFILL }},
5251         { &hf_gtpv1_chrg_char_p,                { "Prepaid charging",   "gtpv1.chrg_char_p",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_P, "Prepaid charging", HFILL }},
5252         { &hf_gtpv1_chrg_char_f,                { "Flat rate charging", "gtpv1.chrg_char_f",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_F, "Flat rate charging", HFILL }},
5253         { &hf_gtpv1_chrg_char_h,                { "Hot billing charging",       "gtpv1.chrg_char_h",    FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_H, "Hot billing charging", HFILL }},
5254         { &hf_gtpv1_chrg_char_r,                { "Reserved",           "gtpv1.chrg_char_r",            FT_UINT8,       BASE_DEC, NULL, GTP_MASK_CHRG_CHAR_R, "Reserved", HFILL }},
5255         { &hf_gtpv1_trace_ref,          { "Trace reference",    "gtpv1.trace_ref",              FT_UINT16,      BASE_HEX, NULL, 0, "Trace reference", HFILL }},
5256         { &hf_gtpv1_trace_type,         { "Trace type",         "gtpv1.trace_type",             FT_UINT16,      BASE_HEX, NULL, 0, "Trace type", HFILL }},
5257         { &hf_gtpv1_ms_reason,          { "MS not reachable reason",    "gtpv1.ms_reason",      FT_UINT8,       BASE_DEC, VALS(ms_not_reachable_type), 0, "MS not reachable reason", HFILL }},
5258         { &hf_gtpv1_tr_comm,            { "Packet transfer command",    "gtpv1.tr_comm",        FT_UINT8,       BASE_DEC, VALS(tr_comm_type), 0, "Packat transfer command", HFILL }},
5259         { &hf_gtpv1_chrg_id,            { "Charging ID",        "gtpv1.chrg_id",                FT_UINT32,      BASE_HEX, NULL, 0, "Charging ID", HFILL }},
5260         { &hf_gtpv1_user_ipv4,          { "End user address IPv4",      "gtpv1.user_ipv4",      FT_IPv4,        BASE_DEC, NULL, 0, "End user address IPv4", HFILL }},
5261         { &hf_gtpv1_user_ipv6,          { "End user address IPv6",      "gtpv1.user_ipv6",      FT_IPv6,        BASE_HEX, NULL, 0, "End user address IPv6", HFILL }},
5262         { &hf_gtpv1_user_addr_pdp_org,  { "PDP type organization",      "gtpv1.user_addr_pdp_org",      FT_UINT8,       BASE_DEC, VALS(pdp_org_type), 0, "PDP type organization", HFILL }},
5263         { &hf_gtpv1_user_addr_pdp_type, { "PDP type number",    "gtpv1.user_addr_pdp_type",     FT_UINT8,       BASE_HEX, VALS(pdp_type), 0, "PDP type", HFILL }},
5264         { &hf_gtpv1_apn,                        { "APN",                "gtpv1.apn",                    FT_STRING,      BASE_DEC, NULL, 0, "Access Point Name", HFILL }},
5265         { &hf_gtpv1_gsn_addr_type,      { "GSN Address Type",   "gtpv1.gsn_addr_type",          FT_UINT8,       BASE_DEC, VALS(gsn_addr_type), GTP_EXT_GSN_ADDR_TYPE_MASK, "GSN Address Type", HFILL }},
5266         { &hf_gtpv1_gsn_addr_len,               { "GSN Address Length", "gtpv1.gsn_addr_len",           FT_UINT8,       BASE_DEC, NULL, GTP_EXT_GSN_ADDR_LEN_MASK, "GSN Address Length", HFILL }},
5267         { &hf_gtpv1_gsn_ipv4,           { "GSN address IPv4",   "gtpv1.gsn_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "GSN address IPv4", HFILL }},
5268         { &hf_gtpv1_gsn_ipv6,           { "GSN address IPv6",   "gtpv1.gsn_ipv6",               FT_IPv6,        BASE_DEC, NULL, 0, "GSN address IPv6", HFILL }},
5269         { &hf_gtpv1_msisdn,             { "MSISDN",             "gtpv1.msisdn",                 FT_STRING,      BASE_DEC, NULL, 0, "MS international PSTN/ISDN number", HFILL }},
5270         { &hf_gtpv1_qos_al_ret_priority,        { "Allocation/Retention priority ","gtpv1.qos_al_ret_priority",         FT_UINT8,       BASE_DEC, NULL, 0, "Allocation/Retention Priority", HFILL }},
5271         { &hf_gtpv1_qos_traf_class,     { "Traffic class",      "gtpv1.qos_traf_class",         FT_UINT8,       BASE_DEC, VALS(qos_traf_class), GTP_EXT_QOS_TRAF_CLASS_MASK, "Traffic Class", HFILL }},
5272         { &hf_gtpv1_qos_del_order,      { "Delivery order",     "gtpv1.qos_del_order",          FT_UINT8,       BASE_DEC, VALS(qos_del_order), GTP_EXT_QOS_DEL_ORDER_MASK, "Delivery Order", HFILL }},
5273         { &hf_gtpv1_qos_del_err_sdu,    { "Delivery of erroneous SDU",  "gtpv1.qos_del_err_sdu",        FT_UINT8,       BASE_DEC, VALS(qos_del_err_sdu), GTP_EXT_QOS_DEL_ERR_SDU_MASK, "Delivery of Erroneous SDU", HFILL }},
5274         { &hf_gtpv1_qos_max_sdu_size,   { "Maximum SDU size",   "gtpv1.qos_max_sdu_size",       FT_UINT8,       BASE_DEC, VALS(qos_max_sdu_size), 0, "Maximum SDU size", HFILL }},
5275         { &hf_gtpv1_qos_max_ul,                 { "Maximum bit rate for uplink",        "gtpv1.qos_max_ul",     FT_UINT8,       BASE_DEC, VALS(qos_max_ul), 0, "Maximum bit rate for uplink", HFILL }},
5276         { &hf_gtpv1_qos_max_dl,                 { "Maximum bit rate for downlink",      "gtpv1.qos_max_dl",     FT_UINT8,       BASE_DEC, VALS(qos_max_dl), 0, "Maximum bit rate for downlink", HFILL }},
5277         { &hf_gtpv1_qos_res_ber,                { "Residual BER",       "gtpv1.qos_res_ber",            FT_UINT8,       BASE_DEC, VALS(qos_res_ber), GTP_EXT_QOS_RES_BER_MASK, "Residual Bit Error Rate", HFILL }},
5278         { &hf_gtpv1_qos_sdu_err_ratio,  { "SDU Error ratio",    "gtpv1.qos_sdu_err_ratio",      FT_UINT8,       BASE_DEC, VALS(qos_sdu_err_ratio), GTP_EXT_QOS_SDU_ERR_RATIO_MASK, "SDU Error Ratio", HFILL }},
5279         { &hf_gtpv1_qos_trans_delay,    { "Transfer delay",     "gtpv1.qos_trans_delay",        FT_UINT8,       BASE_DEC, VALS(qos_trans_delay), GTP_EXT_QOS_TRANS_DELAY_MASK, "Transfer Delay", HFILL }},
5280         { &hf_gtpv1_qos_traf_handl_prio,        { "Traffic handling priority",  "gtpv1.qos_traf_handl_prio",    FT_UINT8,       BASE_DEC, VALS(qos_traf_handl_prio), GTP_EXT_QOS_TRAF_HANDL_PRIORITY_MASK, "Traffic Handling Priority", HFILL }},
5281         { &hf_gtpv1_qos_guar_ul,                { "Guaranteed bit rate for uplink",     "gtpv1.qos_guar_ul",    FT_UINT8,       BASE_DEC, VALS(qos_guar_ul), 0, "Guaranteed bit rate for uplink", HFILL }},
5282         { &hf_gtpv1_qos_guar_dl,                { "Guaranteed bit rate for downlink",   "gtpv1.qos_guar_dl",    FT_UINT8,       BASE_DEC, VALS(qos_guar_dl), 0, "Guaranteed bit rate for downlink", HFILL }},
5283
5284         { &hf_gtpv1_tft_code,           { "TFT operation code", "gtpv1.tft_code",               FT_UINT8,       BASE_DEC, VALS (tft_code_type), GTPv1_TFT_CODE_MASK, "TFT operation code", HFILL }},
5285         { &hf_gtpv1_tft_spare,          { "TFT spare bit",      "gtpv1.tft_spare",              FT_UINT8,       BASE_DEC, NULL, GTPv1_TFT_SPARE_MASK, "TFT spare bit", HFILL }},
5286         { &hf_gtpv1_tft_number,         { "Number of packet filters",   "gtpv1.tft_number",     FT_UINT8,       BASE_DEC, NULL, GTPv1_TFT_NUMBER_MASK, "Number of packet filters", HFILL }},
5287         { &hf_gtpv1_tft_eval,           { "Evaluation precedence",      "gtpv1.tft_eval",       FT_UINT8,       BASE_DEC, NULL, 0, "Evaluation precedence", HFILL }},
5288
5289         { &hf_gtpv1_rnc_ipv4,           { "RNC address IPv4",   "gtpv1.rnc_ipv4",               FT_IPv4,        BASE_DEC, NULL, 0, "Radio Network Controller address IPv4", HFILL }},
5290         { &hf_gtpv1_rnc_ipv6,           { "RNC address IPv6",   "gtpv1.rnc_ipv6",               FT_IPv6,        BASE_HEX, NULL, 0, "Radio Network Controller address IPv6", HFILL }},
5291         { &hf_gtpv1_chrg_ipv4,          { "CG address IPv4",    "gtpv1.chrg_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Charging Gateway address IPv4", HFILL }},
5292         { &hf_gtpv1_chrg_ipv6,          { "CG address IPv6",    "gtpv1.chrg_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Charging Gateway address IPv6", HFILL }},
5293         { &hf_gtpv1_node_ipv4,          { "Node address IPv4",  "gtpv1.node_ipv4",              FT_IPv4,        BASE_DEC, NULL, 0, "Recommended node address IPv4", HFILL }},
5294         { &hf_gtpv1_node_ipv6,          { "Node address IPv6",  "gtpv1.node_ipv6",              FT_IPv6,        BASE_HEX, NULL, 0, "Recommended node address IPv6", HFILL }},
5295         { &hf_gtpv1_ext_id,             { "Extensio Identifier","gtpv1.ext_id",                 FT_UINT16,      BASE_DEC, NULL, 0, "Extension Identifier", HFILL }},
5296         { &hf_gtpv1_ext_val,            { "Extension Value",    "gtpv1.ext_val",                FT_STRING,      BASE_DEC, NULL, 0, "Extension Value", HFILL }},
5297         { &hf_gtpv1_unknown,            { "Unknown data (length)",      "gtpv1.unknown",        FT_UINT16,      BASE_DEC, NULL, 0, "Unknown data", HFILL }},
5298
5299         };
5300
5301         static gint *ett_gtp_array[] = {
5302                 &ett_gtp,
5303                 &ett_gtp_flags,
5304                 &ett_gtp_ext,
5305                 &ett_gtp_rai,
5306                 &ett_gtp_qos,
5307                 &ett_gtp_auth_tri,
5308                 &ett_gtp_flow_ii,
5309                 &ett_gtp_rab_cntxt,
5310                 &ett_gtp_rp,
5311                 &ett_gtp_pkt_flow_id,
5312                 &ett_gtp_chrg_char,
5313                 &ett_gtp_user,
5314                 &ett_gtp_mm,
5315                 &ett_gtp_trip,
5316                 &ett_gtp_quint,
5317                 &ett_gtp_pdp,
5318                 &ett_gtp_apn,
5319                 &ett_gtp_proto,
5320                 &ett_gtp_gsn_addr,
5321                 &ett_gtp_tft,
5322                 &ett_gtp_tft_pf,
5323                 &ett_gtp_tft_flags,
5324                 &ett_gtp_rab_setup,
5325                 &ett_gtp_hdr_list,
5326                 &ett_gtp_chrg_addr,
5327                 &ett_gtp_node_addr,
5328                 &ett_gtp_rel_pack,
5329                 &ett_gtp_can_pack,
5330                 &ett_gtp_data_resp,
5331                 &ett_gtp_priv_ext,
5332         };
5333
5334         module_t        *gtp_module;
5335
5336         static enum_val_t gtpv0_cdr_options[] = {
5337                 { "GSM 12.15 (not implemented yet)",    0 },
5338                 { "Nokia CDR",  1 },
5339                 { "None",       2 },
5340                 { NULL,         -1 }
5341         };
5342
5343         /* proto_gtp defined only for preference tab */
5344         proto_gtp = proto_register_protocol ("GPRS Tunneling Protocol", "GTP", "gtp");
5345
5346         proto_gtpv0 = proto_register_protocol ("GPRS Tunnelling Protocol v0", "GTPv0", "gtpv0");
5347         proto_register_field_array(proto_gtpv0, hf_gtpv0, array_length(hf_gtpv0));
5348         proto_register_subtree_array(ett_gtp_array, array_length(ett_gtp_array));
5349
5350         proto_gtpv1 = proto_register_protocol("GPRS Tunnelling Protocol v1", "GTPv1", "gtpv1");
5351         proto_register_field_array(proto_gtpv1, hf_gtpv1, array_length(hf_gtpv1));
5352         proto_register_subtree_array(ett_gtp_array, array_length(ett_gtp_array));
5353
5354         gtp_module = prefs_register_protocol(proto_gtp, proto_reg_handoff_gtp);
5355
5356         prefs_register_uint_preference(gtp_module, "gtpv0_port", "GTPv0 port ", "GTPv0 port (default 3386)", 10, &g_gtpv0_port);
5357         prefs_register_uint_preference(gtp_module, "gtpv1c_port", "GTPv1 control plane (GTP-C) port ", "GTPv1 control plane port (default 2123)", 10, &g_gtpv1c_port);
5358         prefs_register_uint_preference(gtp_module, "gtpv1u_port", "GTPv1 user plane (GTP-U) port ", "GTPv1 user plane port (default 2152)", 10, &g_gtpv1u_port);
5359         prefs_register_bool_preference(gtp_module, "gtp_dissect_tpdu", "Dissect T-PDU ", "Dissect T-PDU", &gtp_tpdu);
5360         prefs_register_enum_preference(gtp_module, "gtpv0_dissect_cdr_as", "Dissect GTP'v0 CDRs as ", "Dissect GTP'v0 CDRs as", &gtpv0_cdr_as, gtpv0_cdr_options, FALSE);
5361         prefs_register_bool_preference(gtp_module, "gtpv0_check_etsi", "Compare GTPv0 order with ETSI ", "GTPv0 ETSI order", &gtpv0_etsi_order);
5362         prefs_register_bool_preference(gtp_module, "gtpv1_check_etsi", "Compare GTPv1 order with ETSI ", "GTPv1 ETSI order", &gtpv1_etsi_order);
5363         prefs_register_obsolete_preference(gtp_module, "ppp_reorder");
5364
5365         register_dissector("gtpv0", dissect_gtpv0, proto_gtpv0);
5366         register_dissector("gtpv1", dissect_gtpv1, proto_gtpv1);
5367 }
5368
5369 void
5370 proto_reg_handoff_gtp(void)
5371 {
5372         static int Initialized = FALSE;
5373         static dissector_handle_t gtpv0_handle;
5374         static dissector_handle_t gtpv1_handle;
5375
5376         if (!Initialized) {
5377
5378                 gtpv0_handle = find_dissector("gtpv0");
5379
5380                 gtpv1_handle = find_dissector("gtpv1");
5381
5382                 Initialized = TRUE;
5383
5384         } else {
5385
5386                 dissector_delete("udp.port", gtpv0_port, gtpv0_handle);
5387                 dissector_delete("tcp.port", gtpv0_port, gtpv0_handle);
5388
5389                 dissector_delete("udp.port", gtpv1c_port, gtpv1_handle);
5390                 dissector_delete("tcp.port", gtpv1c_port, gtpv1_handle);
5391                 dissector_delete("udp.port", gtpv1u_port, gtpv1_handle);
5392                 dissector_delete("tcp.port", gtpv1u_port, gtpv1_handle);
5393         }
5394
5395         gtpv0_port = g_gtpv0_port;
5396         gtpv1c_port = g_gtpv1c_port;
5397         gtpv1u_port = g_gtpv1u_port;
5398
5399         /* GTP v0 */
5400
5401         dissector_add("udp.port", g_gtpv0_port, gtpv0_handle);
5402         dissector_add("tcp.port", g_gtpv0_port, gtpv0_handle);
5403
5404         /* GTP v1 */
5405
5406         dissector_add("udp.port", g_gtpv1c_port, gtpv1_handle);
5407         dissector_add("tcp.port", g_gtpv1c_port, gtpv1_handle);
5408         dissector_add("udp.port", g_gtpv1u_port, gtpv1_handle);
5409         dissector_add("tcp.port", g_gtpv1u_port, gtpv1_handle);
5410
5411         ip_handle = find_dissector("ip");
5412         ipv6_handle = find_dissector("ipv6");
5413         ppp_handle = find_dissector("ppp");
5414         data_handle = find_dissector("data");
5415 }