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