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