54fdf313d60cb80167278a7f77317a58ff54a2bd
[obnox/wireshark/wip.git] / epan / dissectors / packet-gtpv2.c
1 /* packet-gtpv2.c
2  *
3  * Routines for GTPv2 dissection
4  * Copyright 2009, Anders Broman <anders.broman [at] ericcsson.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25  * Ref: 3GPP TS 29.274 version 8.1.1 Release 8 ETSI TS 129 274 V8.1.1 (2009-04)
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/asn1.h>
40
41 #include "packet-gsm_a_common.h"
42 #include "packet-gsm_map.h"
43 #include "packet-e212.h"
44
45 /*GTPv2 Message->GTP Header(SB)*/
46 static int proto_gtpv2 = -1;
47 static int hf_gtpv2_flags = -1;
48 static int hf_gtpv2_version = -1;
49 static int hf_gtpv2_t = -1;
50 static int hf_gtpv2_message_type = -1;
51 static int hf_gtpv2_msg_length = -1;
52 static int hf_gtpv2_teid = -1;
53 static int hf_gtpv2_seq = -1;
54 static int hf_gtpv2_spare = -1;
55
56
57 static int hf_gtpv2_ie = -1;
58 static int hf_gtpv2_ie_len = -1;
59 static int hf_gtpv2_cr = -1;
60 static int hf_gtpv2_instance = -1;
61 static int hf_gtpv2_cause = -1;
62 static int hf_gtpv2_cause_cs= -1;
63 static int hf_gtpv2_rec = -1;
64 static int hf_gtpv2_apn = -1;
65 static int hf_gtpv2_ebi = -1;
66 static int hf_gtpv2_daf = -1;
67 static int hf_gtpv2_dtf = -1;
68 static int hf_gtpv2_hi = -1;
69 static int hf_gtpv2_dfi = -1;
70 static int hf_gtpv2_oi = -1;
71 static int hf_gtpv2_isrsi = -1;
72 static int hf_gtpv2_israi = -1;
73 static int hf_gtpv2_sgwci = -1;
74 static int hf_gtpv2_pt = -1;
75 static int hf_gtpv2_tdi = -1;
76 static int hf_gtpv2_si = -1;
77 static int hf_gtpv2_msv = -1;
78 static int hf_gtpv2_pdn_type = -1;
79 static int hf_gtpv2_pdn_ipv4 = -1;
80 static int hf_gtpv2_pdn_ipv6_len = -1;
81 static int hf_gtpv2_pdn_ipv6 = -1;
82
83
84 static int hf_gtpv2_rat_type = -1;
85 static int hf_gtpv2_uli_ecgi_flg = -1;
86 static int hf_gtpv2_uli_tai_flg = -1;
87 static int hf_gtpv2_uli_rai_flg = -1;
88 static int hf_gtpv2_uli_sai_flg = -1;
89 static int hf_gtpv2_uli_cgi_flg = -1;
90 static int hf_gtpv2_cng_rep_act = -1;
91
92 static gint ett_gtpv2 = -1;
93 static gint ett_gtpv2_flags = -1;
94 static gint ett_gtpv2_ie = -1;
95
96
97 static int hf_gtpv2_selec_mode= -1;
98
99 static int hf_gtpv2_f_teid_v4= -1;
100 static int hf_gtpv2_f_teid_v6= -1;
101 static int hf_gtpv2_f_teid_interface_type= -1;
102 static int hf_gtpv2_f_teid_gre_key= -1;
103 static int hf_gtpv2_f_teid_ipv4= -1;
104 static int hf_gtpv2_f_teid_ipv6= -1;
105 static int hf_gtpv2_imsi= -1;
106
107 static int hf_gtpv2_ambr_up= -1;
108 static int hf_gtpv2_ambr_down= -1;
109 static int hf_gtpv2_ip_address_ipv4= -1;
110 static int hf_gtpv2_ip_address_ipv6= -1;
111 static int hf_gtpv2_mei= -1;
112
113 static int hf_gtpv2_bearer_qos_pvi= -1;
114 static int hf_gtpv2_bearer_qos_pl= -1;
115 static int hf_gtpv2_bearer_qos_pci= -1;
116 static int hf_gtpv2_bearer_qos_label_qci= -1;
117 static int hf_gtpv2_bearer_qos_mbr_up= -1;
118 static int hf_gtpv2_bearer_qos_mbr_down= -1;
119 static int hf_gtpv2_bearer_qos_gbr_up= -1;
120 static int hf_gtpv2_bearer_qos_gbr_down= -1;
121 static int hf_gtpv2_flow_qos_label_qci= -1;
122 static int hf_gtpv2_flow_qos_mbr_up= -1;
123 static int hf_gtpv2_flow_qos_mbr_down= -1;
124 static int hf_gtpv2_flow_qos_gbr_up= -1;
125 static int hf_gtpv2_flow_qos_gbr_down= -1;
126
127 static int hf_gtpv2_delay_value= -1;
128 static int hf_gtpv2_charging_id= -1;
129 static int hf_gtpv2_charging_characteristic= -1;
130 static int hf_gtpv2_bearer_flag= -1;
131 static int hf_gtpv2_ue_time_zone= -1;
132 static int hf_gtpv2_ue_time_zone_dst= -1;
133
134 static int hf_gtpv2_node_type= -1;
135
136 static int hf_gtpv2_b_tft_opcode= -1;
137 static int hf_gtpv2_b_tft_ebit= -1;
138 static int hf_gtpv2_b_tft_number= -1;
139 static int hf_gtpv2_b_tft_pf_id= -1;
140 static int hf_gtpv2_b_tft_pf_direction= -1;
141 static int hf_gtpv2_b_tft_pf_eval= -1;
142 static int hf_gtpv2_b_tft_pf_length= -1;
143 static int hf_gtpv2_b_tft_pf_comp_type= -1;
144 static int hf_gtpv2_b_tft_pf_ipv4= -1;
145 static int hf_gtpv2_b_tft_pf_ipv4_mask= -1;
146 static int hf_gtpv2_b_tft_pf_ipv6= -1;
147 static int hf_gtpv2_b_tft_pf_ipv6_mask= -1;
148 static int hf_gtpv2_b_tft_pf_prot_id= -1;
149 static int hf_gtpv2_b_tft_pf_single_local= -1;
150 static int hf_gtpv2_b_tft_pf_local_port_low= -1;
151 static int hf_gtpv2_b_tft_pf_local_port_high= -1;
152 static int hf_gtpv2_b_tft_pf_single_remote= -1;
153 static int hf_gtpv2_b_tft_pf_remote_port_low= -1;
154 static int hf_gtpv2_b_tft_pf_remote_port_high= -1;
155 static int hf_gtpv2_b_tft_pf_security= -1;
156 static int hf_gtpv2_b_tft_pf_service_type= -1;
157 static int hf_gtpv2_b_tft_pf_service_type_mask= -1;
158 static int hf_gtpv2_b_tft_pf_flow_label= -1;
159 static int hf_gtpv2_apn_rest= -1;
160 static int hf_gtpv2_pti= -1;
161 static int hf_gtpv2_uli_cgi_lac= -1;
162 static int hf_gtpv2_uli_cgi_ci= -1;
163 static int hf_gtpv2_uli_sai_lac= -1;
164 static int hf_gtpv2_uli_sai_sac= -1;
165 static int hf_gtpv2_uli_rai_lac= -1;
166 static int hf_gtpv2_uli_rai_rac= -1;
167 static int hf_gtpv2_uli_tai_tac= -1;
168 static int hf_gtpv2_uli_ecgi_eci= -1;
169 static int hf_gtpv2_bearer_control_mode= -1;
170
171 /*Message Types for GTPv2 (Refer Pg19 29.274) (SB)*/
172 static const value_string gtpv2_message_type_vals[] = {
173         {0, "Reserved"},
174         {1, "Echo Request"},
175         {2, "Echo Response"},
176         {3, "Version Not Supported Indication"},
177         /* 4-24 Reserved for S101 interface TS 29.276 */
178         /* 25-31 Reserved for Sv interface TS 29.280 */
179         /* SGSN/MME to PGW (S4/S11, S5/S8) */
180         {32, "Create Session Request"},
181         {33, "Create Session Response"},
182         {34, "Modify Bearer Request"},
183         {35, "Modify Bearer Response"},
184         {36, "Delete Session Request"},
185         {37, "Delete Session Response"},
186         /* SGSN to PGW (S4, S5/S8) */
187         {38, "Change Notification Request"},
188         {39, "Change Notification Response"},
189         /* 40-63 For future use */
190         /* Messages without explicit response */
191         {64, "Modify Bearer Command"},                                                  /* (MME/SGSN to PGW -S11/S4, S5/S8) */
192         {65, "Modify Bearer Failure Indication"},                               /*(PGW to MME/SGSN -S5/S8, S11/S4) */
193         {66, "Delete Bearer Command"},                                                  /* (MME to PGW -S11, S5/S8) */
194         {67, "Delete Bearer Failure Indication"},                               /* (PGW to MME -S5/S8, S11) */
195         {68, "Bearer Resource Command"},                                                /* (MME/SGSN to PGW -S11/S4, S5/S8) */
196         {69, "Bearer Resource Failure Indication"},                             /* (PGW to MME/SGSN -S5/S8, S11/S4) */
197         {70, "Downlink Data Notification Failure Indication"},  /*(SGSN/MME to SGW -S4/S11) */
198         {71, "Trace Session Activation"},
199         {72, "Trace Session Deactivation"},
200         {73, "Stop Paging Indication"},
201         /* 74-94 For future use */ 
202         /* PDN-GW to SGSN/MME (S5/S8, S4/S11) */
203         {95, "Create Bearer Request"},
204         {96, "Create Bearer Response"},
205         {97, "Update Bearer Request"},
206         {98, "Update Bearer Response"},
207         {99, "Delete Bearer Request"},
208         {100, "Delete Bearer Response"},
209         /* PGW to MME, MME to PGW, SGW to PGW, SGW to MME (S5/S8, S11) */
210         {101, "Delete PDN Connection Set Request"},
211         {102, "Delete PDN Connection Set Response"},
212         /* 103-127 For future use */
213         /* MME to MME, SGSN to MME, MME to SGSN, SGSN to SGSN (S3/10/S16) */
214         {128, "Identification Request"},
215         {129, "Identification Response"},
216         {130, "Context Request"},
217         {131, "Context Response"},
218         {132, "Context Acknowledge"},
219         {133, "Forward Relocation Request"},
220         {134, "Forward Relocation Response"},
221         {135, "Forward Relocation Complete Notification"},
222         {136, "Forward Relocation Complete Acknowledge"},
223         {137, "Forward Access Context Notification"},
224         {138, "Forward Access Context Acknowledge"},
225         {139, "Relocation Cancel Request"},
226         {140, "Relocation Cancel Response"},
227         {141, "Configuration Transfer Tunnel"},
228         /* 142-148 For future use */
229         /* SGSN to MME, MME to SGSN (S3)*/
230         {149, "Detach Notification"},
231         {150, "Detach Acknowledge"},
232         {151, "CS Paging Indication"},
233         {152, "RAN Information Relay"},
234         /* 153-159 For future use */
235         /* MME to SGW (S11) */
236         {160, "Create Forwarding Tunnel Request"},
237         {161, "Create Forwarding Tunnel Response"},
238         {162, "Suspend Notification"},
239         {163, "Suspend Acknowledge"},
240         {164, "Resume Notification"},
241         {165, "Resume Acknowledge"},
242         {166, "Create Indirect Data Forwarding Tunnel Request"},
243         {167, "Create Indirect Data Forwarding Tunnel Response"},
244         {168, "Delete Indirect Data Forwarding Tunnel Request"},
245         {169, "Delete Indirect Data Forwarding Tunnel Response"},
246         {170, "Release Access Bearers Request"},
247         {171, "Release Access Bearers Response"},
248         /* 172-175 For future use */
249         /* SGW to SGSN/MME (S4/S11) */
250         {176, "Downlink Data Notification "},
251         {177, "Downlink Data Notification Acknowledgement"},
252         /* SGW to SGSN (S4) */
253         {178, "Update Bearer Complete "},
254         /* 179-191 For future use */
255         /* Other */
256         /* 192-244 For future use */
257         /* 245-255 Reserved for GTP-U TS 29.281 [13] */
258     {0, NULL}
259 };
260
261 #define GTPV2_IE_RESERVED               0
262 #define GTPV2_IE_IMSI                   1
263 #define GTPV2_IE_CAUSE                  2
264 #define GTPV2_REC_REST_CNT              3
265 #define GTPV2_APN                               71
266 #define GTPV2_AMBR              72 
267 #define GTPV2_EBI                               73
268 #define GTPV2_IP_ADDRESS                74 
269 #define GTPV2_MEI                               75 
270 #define GTPV2_IE_MSISDN                 76
271 #define GTPV2_INDICATION                77
272 #define GTPV2_PCO                               78
273 #define GTPV2_PAA                               79
274 #define GTPV2_BEARER_QOS                80
275 #define GTPV2_FLOW_QOS                  81
276 #define GTPV2_IE_RAT_TYPE               82
277 #define GTPV2_IE_SERV_NET               83
278 #define GTPV2_BEARER_TFT                84
279 #define GTPV2_TAD                               85
280 #define GTPV2_ULI                               86
281 #define GTPV2_F_TEID                    87
282 #define GTPV2_G_CN_ID                   89
283 #define GTPV2_DELAY_VALUE               92
284 #define GTPV2_BEARER_CTX                93
285 #define GTPV2_CHARGING_ID       94
286 #define GTPV2_CHARGING_CHARACTERISTIC       95
287 #define GTPV2_BEARER_FLAG       97
288 #define GTPV2_PDN_TYPE          99
289 #define GTPV2_PTI                               100
290 #define GTPV2_UE_TIME_ZONE              114
291 #define GTPV2_APN_RESTRICTION   127
292 #define GTPV2_SELEC_MODE        128 
293 #define GTPV2_BEARER_CONTROL_MODE       130
294 #define GTPV2_CNG_REP_ACT               131
295 #define GTPV2_NODE_TYPE                 135 
296
297 #define SPARE                                                           0X0
298 #define CREATE_NEW_TFT                                          0X20
299 #define DELETE_TFT                                                      0X40
300 #define ADD_PACKET_FILTERS_TFT                          0X60
301 #define REPLACE_PACKET_FILTERS_TFT                      0X80
302 #define DELETE_PACKET_FILTERS_TFT                       0XA0
303 #define NO_TFT_OPERATION                                        0XC0
304 #define RESERVED                                                        0XE0
305
306
307 /* Table 8.1-1: Information Element types for GTPv2 */
308 static const value_string gtpv2_element_type_vals[] = {
309         {0, "Reserved"},
310         {1, "International Mobile Subscriber Identity (IMSI)"},                                         /* Variable Length / 8.3 */
311         {2, "Cause"},                                                                                                                           /* Variable Length / 8.4 */
312         {3, "Recovery (Restart Counter)"},                                                                                      /* Variable Length / 8.5 */
313         /* 4-50 Reserved for S101 interface Extendable / See 3GPP TS 29.276 [14] */
314         /* 51-70 Reserved for Sv interface Extendable / See 3GPP TS 29.280 [15] */
315         {71, "Access Point Name (APN)"},                                                                                        /* Variable Length / 8.6 */
316         {72, "Aggregate Maximum Bit Rate (AMBR)"},                                                                      /* Fixed Length / 8.7 */
317         {73, "EPS Bearer ID (EBI)"},                                                                                            /* Extendable / 8.8 */
318         {74, "IP Address"},                                                                                                                     /* Extendable / 8.9 */
319         {75, "Mobile Equipment Identity (MEI)"},                                                                        /* Variable Length / 8.10 */
320         {76, "MSISDN"},                                                                                                                         /* Variable Length / 8.11 */
321         {77, "Indication"},                                                                                                                     /* Extendable / 8.12 */
322         {78, "Protocol Configuration Options (PCO)"},                                                           /* Variable Length / 8.13 */
323         {79, "PDN Address Allocation (PAA)"},                                                                           /* Variable Length / 8.14 */
324         {80, "Bearer Level Quality of Service (Bearer QoS)"},                                           /* Variable Length / 8.15 */
325         {81, "Flow Quality of Service (Flow QoS)"},                                                                     /* Extendable / 8.16 */
326         {82, "RAT Type"},                                                                                                                       /* Extendable / 8.17 */
327         {83, "Serving Network"},                                                                                                        /* Extendable / 8.18 */
328         {84, "EPS Bearer Level Traffic Flow Template (Bearer TFT)"},                            /* Variable Length / 8.19 */
329         {85, "Traffic Aggregation Description (TAD)"},                                                          /* Variable Length / 8.20 */
330         {86, "User Location Info (ULI)"},                                                                                       /* Variable Length / 8.21 */
331         {87, "Fully Qualified Tunnel Endpoint Identifier (F-TEID)"},                            /* Extendable / 8.22 */
332         {88, "TMSI"},                                                                                                                           /* Variable Length / 8.23 */
333         {89, "Global CN-Id"},                                                                                                           /* Variable Length / 8.24 */
334         {90, "S103 PDN Data Forwarding Info (S103PDF)"},                                                        /* Variable Length / 8.25 */
335         {91, "S1-U Data Forwarding Info (S1UDF)"},                                                                      /* Variable Length/ 8.26 */
336         {92, "Delay Value"},                                                                                                            /* Extendable / 8.27 */
337         {93, "Bearer Context"},                                                                                                         /* Extendable / 8.28 */
338         {94, "Charging ID"},                                                                                                            /* Extendable / 8.29 */
339         {95, "Charging Characteristics"},                                                                                       /* Extendable / 8.30 */
340         {96, "Trace Information"},                                                                                                      /* Extendable / 8.31 */
341         {97, "Bearer Flags"},                                                                                                           /* Extendable / 8.32 */
342         {98, "Paging Cause"},                                                                                                           /* Variable Length / 8.33 */
343         {99, "PDN Type"},                                                                                                                       /* Extendable / 8.34 */
344         {100, "Procedure Transaction ID"},                                                                                      /* Extendable / 8.35 */
345         {101, "DRX Parameter"},                                                                                                         /* Variable Length/ 8.36 */
346         {102, "UE Network Capability"},                                                                                         /* Variable Length / 8.37 */
347         {103, "MM Context (GSM Key and Triplets)"},                                                                     /* Variable Length / 8.38 */
348         {104, "MM Context (UMTS Key, Used Cipher and Quintuplets)"},                            /* Variable Length / 8.38 */
349         {105, "MM Context (GSM Key, Used Cipher and Quintuplets)"},                                     /* Variable Length / 8.38 */
350         {106, "MM Context (UMTS Key and Quintuplets)"},                                                         /* Variable Length / 8.38 */
351         {107, "MM Context (EPS Security Context, Quadruplets and Quintuplets)"},        /* Variable Length / 8.38 */
352         {108, "MM Context (UMTS Key, Quadruplets and Quintuplets)"},                            /* Variable Length / 8.38 */
353         {109, "PDN Connection"},                                                                                                        /* Extendable / 8.39 */
354         {110, "PDU Numbers"},                                                                                                           /* Extendable / 8.40 */
355         {111, "P-TMSI"},                                                                                                                        /* Variable Length / 8.41 */
356         {112, "P-TMSI Signature"},                                                                                                      /* Variable Length / 8.42 */
357         {113, "Hop Counter"},                                                                                                           /* Extendable / 8.43 */
358         {114, "UE Time Zone"},                                                                                                          /* Variable Length / 8.44 */
359         {115, "Trace Reference"},                                                                                                       /* Fixed Length / 8.45 */
360         {116, "Complete Request Message"},                                                                                      /* Variable Length / 8.46 */
361         {117, "GUTI"},                                                                                                                          /* Variable Length / 8.47 */
362         {118, "F-Container"},                                                                                                           /* Variable Length / 8.48 */
363         {119, "F-Cause"},                                                                                                                       /* Variable Length / 8.49 */
364         {120, "Selected PLMN ID"},                                                                                                      /* Variable Length / 8.50 */
365         {121, "Target Identification"},                                                                                         /* Variable Length / 8.51 */
366         {122, "NSAPI"},                                                                                                                         /* Extendable / 8.52 */
367         {123, "Packet Flow ID"},                                                                                                        /* Variable Length / 8.53 */
368         {124, "RAB Context"},                                                                                                           /* Fixed Length / 8.54 */
369         {125, "Source RNC PDCP Context Info"},                                                                          /* Variable Length / 8.55 */
370         {126, "UDP Source Port Number"},                                                                                        /* Extendable / 8.56 */
371         {127, "APN Restriction"},                                                                                                       /* Extendable / 8.57 */
372         {128, "Selection Mode"},                                                                                                        /* Extendable / 8.58 */
373         {129, "Source Identification"},                                                                                         /* Variable Length / 8.50 */
374         {130, "Bearer Control Mode"},                                                                                           /* Extendable / 8.60 */
375         {131, "Change Reporting Action"},                                                                                       /* Variable Length / 8.61 */
376         {132, "Fully Qualified PDN Connection Set Identifier (FQ-CSID)"},                       /* Variable Length / 8.62 */
377         {133, "Channel needed"},                                                                                                        /* Extendable / 8.63 */
378         {134, "eMLPP Priority"},                                                                                                        /* Extendable / 8.64 */
379         {135, "Node Type"},                                                                                                                     /* Extendable / 8.65 */
380         {136, "Fully Qualified Domain Name (FQDN)"},                                                            /* Variable Length / 8.66 */
381         {137, "Transaction Identifier (TI)"},                                                                           /* Variable Length / 8.68 */
382         /* 138-254 "Spare."},   */                                                                                                      /* For future use. FFS */
383         {255, "Private"},                                                                                                                       /* Extension Extendable / 8.71 */
384     {0, NULL}
385 };
386
387 /* Code to dissect IE's */
388
389 static void
390 dissect_gtpv2_unknown(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
391 {
392
393         proto_tree_add_text(tree, tvb, 0, length, "IE data not dissected yet"); 
394 }
395
396 /* 
397  * 8.3 International Mobile Subscriber Identity (IMSI)
398  *
399  * IMSI is defined in 3GPP TS 23.003
400  * Editor's note: IMSI coding will be defined in 3GPP TS 24.301
401  * Editor's note: In the first release of GTPv2 spec (TS 29.274v8.0.0) n = 8. 
402  * That is, the overall length of the IE is 11 octets.
403  */
404
405
406 static gchar *imsi_to_str(const guint8 * ad)
407 {
408     static gchar str[17] = "                ";
409     int i, j = 0;
410
411     for (i = 0; i < 8; i++)
412     {
413         if (((ad[i] >> 4) & 0x0F) <= 9)
414                 str[j++] = ((ad[i] >> 4) & 0x0F) + 0x30;
415         if ((ad[i] & 0x0F) <= 9)
416                 str[j++] = (ad[i] & 0x0F) + 0x30; /* Adding 0x30(48 decimal) makes it a printable digit (Eg. Ascii value 0f 9 is 57 (9+48))*/
417
418     }
419     str[j] = '\0';
420
421     return str;
422 }
423
424 static void
425 dissect_gtpv2_imsi(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
426 {
427     int offset= 0;
428         guint8 imsi_val[8];
429         gchar *imsi_str;
430
431         tvb_memcpy(tvb, imsi_val, offset , 8);
432         imsi_str = imsi_to_str(imsi_val);
433
434         proto_tree_add_string(tree, hf_gtpv2_imsi, tvb, offset, length, imsi_str);
435 }
436
437 /* Table 8.4-1: Cause values */
438 static const value_string gtpv2_cause_vals[] = {
439         {0, "Reserved"},
440         /* Request */
441         {1, "Paging Cause"},
442         {2, "Local Detach"},
443         {3, "Complete Detach"},
444         {4, "RAT changed from 3GPP to Non-3GPP"},
445         {5, "ISR is activated"},
446         /* 6-15 Spare. This value range is reserved for Cause values in a request message */
447         /* Acceptance Response */
448         {16, "Request accepted"},
449         {17, "Request accepted partially"},
450         {18, "New PDN type due to network preference"},
451         {19, "New PDN type due to single address bearer only"},
452         /* 20-63 Spare. This value range is reserved for Cause values in acceptance response message */
453         /* Rejection Response */
454         {64, "Context Not Found"},
455         {65, "Invalid Message Format"},
456         {66, "Version not supported by next peer"},
457         {67, "Invalid length"},
458         {68, "Service not supported"},
459         {69, "Mandatory IE incorrect"},
460         {70, "Mandatory IE missing"},
461         {71, "Optional IE incorrect"},
462         {72, "System failure"},
463         {73, "No resources available"},
464         {74, "Semantic error in the TFT operation"},
465         {75, "Syntactic error in the TFT operation"},
466         {76, "Semantic errors in packet filter(s)"},
467         {77, "Syntactic errors in packet filter(s)"},
468         {78, "Missing or unknown APN"},
469         {79, "Unexpected repeated IE"},
470         {80, "GRE key not found"},
471         {81, "Reallocation failure"},
472         {82, "Denied in RAT"},
473         {83, "Preferred PDN type not supported"},
474         {84, "All dynamic addresses are occupied"},
475         {85, "UE context without TFT already activated"},
476         {86, "Protocol type not supported"},
477         {87, "UE not responding"},
478         {88, "UE refuses"},
479         {89, "Service denied"},
480         {90, "Unable to page UE"},
481         {91, "No memory available"},
482         {92, "User authentication failed"},
483         {93, "APN access denied - no subscription"},
484         {94, "Request rejected"},
485         {95, "P-TMSI Signature mismatch"},
486         {96, "IMSI not known"},
487         {97, "Semantic error in the TAD operation"},
488         {98, "Syntactic error in the TAD operation"},
489         {99, "Reserved Message Value Received"},
490         {100, "PGW not responding"},
491         {101, "Collision with network initiated request"},
492         {102, "Unable to page UE due to Suspension"},
493         {103, "Conditional IE missing"},
494         {104, "APN Restriction type Incompatible with currently active PDN connection"},
495         /* 105-219 Spare. This value range is reserved for Cause values in rejection response message */
496         /* 220-255 Reserved for 3GPP Specific PMIPv6 Error Codes as defined in 3GPP TS 29.275 [26] */
497     {0, NULL}
498 };
499
500 /*
501  * 8.4 Cause
502  */
503
504 static void
505 dissect_gtpv2_cause(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
506 {
507         int offset = 0;
508         /* Cause value octet 5 */
509         proto_tree_add_item(tree, hf_gtpv2_cause, tvb, offset, 1, FALSE);
510         offset++;
511         proto_tree_add_item(tree, hf_gtpv2_cause_cs, tvb, offset, 1, FALSE);
512 }
513
514 /*
515  * 8.5 Recovery (Restart Counter)
516  */
517 static void
518 dissect_gtpv2_recovery(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
519 {
520         int offset = 0;
521         proto_tree_add_item(tree, hf_gtpv2_rec, tvb, offset, 1, FALSE);
522 }
523
524 /*
525  * 8.6 Access Point Name (APN)
526  */
527 static void
528 dissect_gtpv2_apn(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
529 {
530         int offset = 0;
531     guint8 *apn = NULL;
532     int name_len, tmp;
533
534     if (length > 0) {
535                 name_len = tvb_get_guint8(tvb, offset);
536
537                 if (name_len < 0x20) {
538                         apn = tvb_get_ephemeral_string(tvb, offset + 1, length - 1);
539                         for (;;) {
540                                 if (name_len >= length - 1)
541                                 break;
542                                 tmp = name_len;
543                                 name_len = name_len + apn[tmp] + 1;
544                                 apn[tmp] = '.';
545                         }
546                 } else{
547                         apn = tvb_get_ephemeral_string(tvb, offset, length);
548                 }
549                 proto_tree_add_string(tree, hf_gtpv2_apn, tvb, offset, length, apn);
550     }
551
552 }
553
554 /*
555  * 8.7 Aggregate Maximum Bit Rate (AMBR) */
556
557 static void
558 dissect_gtpv2_ambr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
559 {
560         int offset = 0;
561         proto_tree_add_item(tree, hf_gtpv2_ambr_up, tvb, offset, 4, FALSE);
562         offset= offset + 4;
563         proto_tree_add_item(tree, hf_gtpv2_ambr_down, tvb, offset, 4, FALSE);
564 }
565
566 /* 
567  * 8.8 EPS Bearer ID (EBI)
568  */
569 static void
570 dissect_gtpv2_ebi(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
571 {
572
573         int offset = 0;
574         /* Spare (all bits set to 0) B8 - B5*/
575         /* EPS Bearer ID (EBI) B4 - B1 */
576         proto_tree_add_item(tree, hf_gtpv2_ebi, tvb, offset, 1, FALSE);
577
578 }
579 /* 8.9 IP Address  */
580 static void
581 dissect_gtpv2_ip_address(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
582 {
583         int offset = 0;
584         if (length==4)
585         {
586                 proto_tree_add_item(tree, hf_gtpv2_ip_address_ipv4, tvb, offset, length, FALSE);
587     }
588         else if (length==16)
589         {
590                 proto_tree_add_item(tree, hf_gtpv2_ip_address_ipv6, tvb, offset, length, FALSE);
591         }
592 }
593 /* 8.10 Mobile Equipment Identity (MEI)*/
594 static gchar *mei_to_str(const guint8 * ad)
595 {
596     static gchar str[17] = "                ";
597     int i, j = 0;
598     for (i = 0; i < 8; i++)
599     {
600         if (((ad[i] >> 4) & 0x0F) <= 9)
601                 str[j++] = ((ad[i] >> 4) & 0x0F) + 0x30;
602         if ((ad[i] & 0x0F) <= 9)
603                 str[j++] = (ad[i] & 0x0F) + 0x30; /* Adding 0x30(48 decimal) makes it a printable digit (Eg. Ascii value 0f 9 is 57 (9+48))*/
604     }
605     str[j] = '\0';
606     return str;
607 }
608
609 static void
610 dissect_gtpv2_mei(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
611 {
612         int offset= 0;
613         guint8 mei_val[8];
614         gchar *mei_str;
615         tvb_memcpy(tvb, mei_val, offset , 8);
616         mei_str = mei_to_str(mei_val);
617         proto_tree_add_string(tree, hf_gtpv2_mei, tvb, offset, length, mei_str);
618 }
619
620 /*
621  * 8.11 MSISDN
622  *
623  * MSISDN is defined in 3GPP TS 23.003
624  * Editor's note: MSISDN coding will be defined in TS 24.301.
625  */
626 static void
627 dissect_gtpv2_msisdn(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
628 {
629         dissect_gsm_map_msisdn(tvb, pinfo, tree); 
630 }
631
632 /*
633  * 8.12 Indication
634  */
635 static void
636 dissect_gtpv2_ind(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
637 {
638         int offset = 0;
639         proto_tree_add_item(tree, hf_gtpv2_daf,                 tvb, offset, 1, FALSE);
640         proto_tree_add_item(tree, hf_gtpv2_dtf,                 tvb, offset, 1, FALSE);
641         proto_tree_add_item(tree, hf_gtpv2_hi,                  tvb, offset, 1, FALSE);
642         proto_tree_add_item(tree, hf_gtpv2_dfi,                 tvb, offset, 1, FALSE);
643         proto_tree_add_item(tree, hf_gtpv2_oi,                  tvb, offset, 1, FALSE);
644         proto_tree_add_item(tree, hf_gtpv2_isrsi,               tvb, offset, 1, FALSE);
645         proto_tree_add_item(tree, hf_gtpv2_israi,               tvb, offset, 1, FALSE);
646         proto_tree_add_item(tree, hf_gtpv2_sgwci,               tvb, offset, 1, FALSE);
647         if(length==1)
648         {
649                 proto_tree_add_text(tree, tvb, 0, length, "Older version?, should be 2 octets in 8.0.0");
650                 return;
651         }
652         offset++;
653         proto_tree_add_item(tree, hf_gtpv2_pt,                  tvb, offset, 1, FALSE);
654         proto_tree_add_item(tree, hf_gtpv2_tdi,                 tvb, offset, 1, FALSE);
655         proto_tree_add_item(tree, hf_gtpv2_si,                  tvb, offset, 1, FALSE);
656         proto_tree_add_item(tree, hf_gtpv2_msv,                 tvb, offset, 1, FALSE);
657 }
658
659 /*
660  * 8.13 Protocol Configuration Options (PCO)
661  * Editor's note: PCO will be defined in 3GPP TS 23.003 and its coding in TS 24.301
662  * Dissected in packey-gsm_a_gm.c
663  */
664 static void
665 dissect_gtpv2_pco(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
666 {
667         de_sm_pco(tvb, tree, 0, length, NULL, 0);
668 }
669
670 /*
671  * 8.14 PDN Address Allocation (PAA)
672  */
673
674 static const value_string gtpv2_pdn_type_vals[] = {
675     {1, "IPv4"},
676     {2, "IPv6"},
677         {3, "IPv4/IPv6"},
678     {0, NULL}
679 };
680
681 static void
682 dissect_gtpv2_paa(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
683 {
684         int offset = 0;
685         guint8 pdn_type;
686         pdn_type  = tvb_get_guint8(tvb, offset);
687     proto_tree_add_item(tree, hf_gtpv2_pdn_type, tvb, offset, 1, FALSE);
688         offset++;
689         switch(pdn_type)
690         {
691                 case 1:
692                         /* IPv4 */
693                         proto_tree_add_item(tree, hf_gtpv2_pdn_ipv4, tvb, offset, 4, FALSE);
694                         offset+=4;
695                         break;
696                 case 2:
697                         /* IPv6*/
698                         proto_tree_add_item(tree, hf_gtpv2_pdn_ipv6_len, tvb, offset, 1, FALSE);
699                         offset++;
700                         proto_tree_add_item(tree, hf_gtpv2_pdn_ipv6, tvb, offset, 16, FALSE);
701                         offset+=16;
702                         break;
703                 case 3:
704                         /* IPv4/IPv6 */
705                         proto_tree_add_item(tree, hf_gtpv2_pdn_ipv6_len, tvb, offset, 1, FALSE);
706                         offset++;
707                         proto_tree_add_item(tree, hf_gtpv2_pdn_ipv6, tvb, offset, 16, FALSE);
708                         offset+=16;
709                         proto_tree_add_item(tree, hf_gtpv2_pdn_ipv4, tvb, offset, 4, FALSE);
710                         offset+=4;
711                         break;
712                 default:
713                         break;
714         }
715 }
716 /*
717  * 8.15 Bearer Quality of Service (Bearer QoS)
718  */
719
720 static void
721 dissect_gtpv2_bearer_qos(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
722 {
723         int offset = 0;
724         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_pvi, tvb, offset, 1, FALSE);
725         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_pl, tvb, offset, 1, FALSE);
726         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_pci, tvb, offset, 1, FALSE);
727         offset++;
728         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_label_qci, tvb, offset, 1, FALSE);
729         offset++;
730         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_mbr_up, tvb, offset, 5, FALSE);
731         offset= offset+5;
732         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_mbr_down, tvb, offset, 5, FALSE);
733         offset= offset+5;
734         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_gbr_up, tvb, offset, 5, FALSE);
735         offset= offset+5;
736         proto_tree_add_item(tree, hf_gtpv2_bearer_qos_gbr_down, tvb, offset, 5, FALSE);
737         offset= offset+5;
738 }
739
740 /*
741  * 8.16 Flow Quality of Service (Flow QoS)
742  */
743
744 static void
745 dissect_gtpv2_flow_qos(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
746 {
747         int offset = 0;
748         proto_tree_add_item(tree, hf_gtpv2_flow_qos_label_qci, tvb, offset, 1, FALSE);
749         offset++;
750         proto_tree_add_item(tree, hf_gtpv2_flow_qos_mbr_up, tvb, offset, 5, FALSE);
751         offset= offset+5;
752         proto_tree_add_item(tree, hf_gtpv2_flow_qos_mbr_down, tvb, offset, 5, FALSE);
753         offset= offset+5;
754         proto_tree_add_item(tree, hf_gtpv2_flow_qos_gbr_up, tvb, offset, 5, FALSE);
755         offset= offset+5;
756         proto_tree_add_item(tree, hf_gtpv2_flow_qos_gbr_down, tvb, offset, 5, FALSE);
757         offset= offset+5;
758 }
759
760 /*
761  * 8.17 RAT Type
762  */
763 static const value_string gtpv2_rat_type_vals[] = {
764         {0, "Reserved"},
765         {1, "UTRAN"},
766         {2, "GERAN"},
767         {3, "WLAN"},
768         {4, "GAN"},
769         {5, "HSPA Evolution"},
770         {6, "EUTRAN"},
771         {0, NULL}
772 };
773
774 static void
775 dissect_gtpv2_rat_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
776 {
777         proto_tree_add_item(tree, hf_gtpv2_rat_type, tvb, 0, 1, FALSE);
778 }
779
780 /*
781  * 8.18 Serving Network
782  */
783 static void
784 dissect_gtpv2_serv_net(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
785 {
786         dissect_e212_mcc_mnc(tvb, tree, 0); 
787 }
788
789 /*
790  * 8.19 EPS Bearer Level Traffic Flow Template (Bearer TFT) */
791
792 static const value_string gtpv2_opcode_vals[] = {
793         {0, "Spare"},
794         {1, "Create New TFT"},
795         {2, "Delete Existing TFT"},
796         {3, "Add Packet filters to existing TFT"},
797         {4, "Replace Packet filters in existing TFT"},
798         {5, "Delete Packet filters from existing TFT"},
799         {6, "No TFT Operation"},
800         {7, "Reserved"},
801         {0, NULL}
802 };
803 static const value_string gtpv2_comp_type_vals[] = {
804         {16, "IPV4 remote address type"},
805         {32, "IPV6 remote address type"},
806         {48, "Protocol Identifier"},
807         {64, "Single local port type"},
808         {65, "Local port range type"},
809         {80, "Single remote port type"},
810         {81, "Remote port range type"},
811         {96, "Security Parameter Index type"},
812         {112, "Type of Service/Traffic class type"},
813         {128, "Flow Label type"},
814         {0, NULL}
815 };
816 static const value_string gtpv2_direction_vals[] = {
817         {0, "Pre Rel-7 TFT filter"},
818         {1, "Downlink only"},
819         {2, "uplink only"},
820         {3, "bidirectional"},
821         {0, NULL}
822 };
823
824 static void
825 dissect_gtpv2_bearer_tft(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
826 {
827         int offset= 0,i=0,newoffset2;
828         guint8 number, opcode, ebit, comptype, length1;
829         proto_tree *ie_tree;
830         proto_item *ti;
831         number = tvb_get_guint8(tvb,offset)& 0x0f;
832         opcode = tvb_get_guint8(tvb,offset)& 0xe0;
833         ebit = tvb_get_guint8(tvb,offset)& 0x10;
834         proto_tree_add_item(tree, hf_gtpv2_b_tft_opcode, tvb, offset, 1, FALSE);
835         proto_tree_add_item(tree, hf_gtpv2_b_tft_number, tvb, offset, 1, FALSE);
836         proto_tree_add_item(tree, hf_gtpv2_b_tft_ebit, tvb, offset, 1, FALSE);
837         offset++;
838         switch(opcode)
839                 {
840                         case SPARE:
841                                 /* Spare */
842                                 break;
843                         case CREATE_NEW_TFT:
844                                 /* Create New TFT */
845                         case ADD_PACKET_FILTERS_TFT:
846                                 /* Add packet filters to existing TFT */
847                         case REPLACE_PACKET_FILTERS_TFT:
848                                 /*Replace Packet filters in existing TFT */
849                                 while (i<number)
850                                 {
851                                         i++;newoffset2=0;
852                                         length1 =tvb_get_guint8(tvb,offset+2);
853                                         ti = proto_tree_add_text(tree, tvb, offset, 3+length1, "Packet Filter %d",i);
854                                         ie_tree = proto_item_add_subtree(ti, ett_gtpv2_ie);
855                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_id, tvb, offset, 1, FALSE);
856                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_direction, tvb, offset, 1, FALSE);
857                                         offset++;
858                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_eval, tvb, offset, 1, FALSE);
859                                         offset++;
860                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_length, tvb, offset, 1, FALSE);
861                                         offset++;
862
863                                         while (newoffset2<length1)
864                                         {
865                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_comp_type, tvb, offset, 1, FALSE);
866                                         comptype = tvb_get_guint8(tvb,offset);
867                                         offset++;
868                                         newoffset2++;
869                                                 if (comptype==16)
870                                                 {
871                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4, tvb, offset, 4, FALSE);
872                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4_mask, tvb, offset, 4, FALSE);
873                                                         offset+=8;
874                                                         newoffset2+=8;
875                                                 }
876                                                 if (comptype==32)
877                                                 {
878                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6, tvb, offset, 16, FALSE);
879                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6_mask, tvb, offset, 16, FALSE);
880                                                         offset+=32;
881                                                         newoffset2+=32;
882                                                 }
883                                                 if (comptype==48)
884                                                 {
885                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_prot_id, tvb, offset, 1, FALSE);
886                                                         offset+=1;
887                                                         newoffset2+=1;
888                                                 }
889                                                 if (comptype==64)
890                                                 {
891                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_local, tvb, offset, 2, FALSE);
892                                                         offset+=2;
893                                                         newoffset2+=2;
894                                                 }
895                                                 if (comptype==65)
896                                                 {
897                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_low, tvb, offset, 2, FALSE);
898                                                         offset+=2;
899                                                         newoffset2+=2;
900                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_high, tvb, offset, 2, FALSE);
901                                                         offset+=2;
902                                                         newoffset2+=2;
903                                                 }
904                                                 if (comptype==80)
905                                                 {
906                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_remote, tvb, offset, 2, FALSE);
907                                                         offset+=2;
908                                                         newoffset2+=2;
909                                                 }
910                                                 if (comptype==81)
911                                                 {
912                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_low, tvb, offset, 2, FALSE);
913                                                         offset+=2;
914                                                         newoffset2+=2;
915                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_high, tvb, offset, 2, FALSE);
916                                                         offset+=2;
917                                                         newoffset2+=2;
918                                                 }
919                                                 if (comptype==96)
920                                                 {
921                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_security, tvb, offset, 4, FALSE);
922                                                         offset+=4;
923                                                         newoffset2+=4;
924                                                 }
925                                                 if (comptype==112)
926                                                 {
927                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type, tvb, offset, 1, FALSE);
928                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type_mask, tvb, offset, 1, FALSE);
929                                                         offset+=2;
930                                                         newoffset2+=2;
931                                                 }
932                                                 if (comptype==128)
933                                                 {
934                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_flow_label, tvb, offset, 3, FALSE);
935                                                         offset+=3;
936                                                         newoffset2+=3;
937                                                 }
938                                   }
939                                 }
940
941                                 break;
942                         case DELETE_TFT:
943                                 /* Delete Existing TFT */
944                                 break;
945
946                         case DELETE_PACKET_FILTERS_TFT:
947                                 /* Delete Packet filters from existing TFT */
948                                 while (i<number)
949                                 {
950                                         i++;
951                                         ti = proto_tree_add_text(tree, tvb, offset, 1, "Packet Filter %d",i);
952                                         ie_tree = proto_item_add_subtree(ti, ett_gtpv2_ie);
953                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_id, tvb, offset, 1, FALSE);
954                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_direction, tvb, offset, 1, FALSE);
955                                         offset++;
956                                 }
957                                 break;
958                         case NO_TFT_OPERATION:
959                                 /* No TFT operation */
960                                 break;
961                         case RESERVED:
962                                 /* Reserved */
963                                 break;
964                         default:
965                                 break;
966                 }
967
968 }
969  /* 8.20 Traffic Aggregate Description (TAD) 
970  */
971 static void
972 dissect_gtpv2_tad(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
973 {
974         int offset= 0,i=0,newoffset2;
975         guint8 number, opcode, ebit, comptype, length1;
976         proto_tree *ie_tree;
977         proto_item *ti;
978         number = tvb_get_guint8(tvb,offset)& 0x0f;
979         opcode = tvb_get_guint8(tvb,offset)& 0xe0;
980         ebit = tvb_get_guint8(tvb,offset)& 0x10;
981         proto_tree_add_item(tree, hf_gtpv2_b_tft_opcode, tvb, offset, 1, FALSE);
982         proto_tree_add_item(tree, hf_gtpv2_b_tft_number, tvb, offset, 1, FALSE);
983         proto_tree_add_item(tree, hf_gtpv2_b_tft_ebit, tvb, offset, 1, FALSE);
984         offset++;
985         switch(opcode)
986                 {
987                         case SPARE:
988                                 /* Spare */
989                                 break;
990                         case CREATE_NEW_TFT:
991                                 /* Create New TFT */
992                         case REPLACE_PACKET_FILTERS_TFT:
993                                 /*Replace Packet filters in existing TFT */
994                                 while (i<number)
995                                 {
996                                         i++;newoffset2=0;
997                                         length1 =tvb_get_guint8(tvb,offset+2);
998                                         ti = proto_tree_add_text(tree, tvb, offset, 3+length1, "Packet Filter %d",i);
999                                         ie_tree = proto_item_add_subtree(ti, ett_gtpv2_ie);
1000                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_id, tvb, offset, 1, FALSE);
1001                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_direction, tvb, offset, 1, FALSE);
1002                                         offset++;
1003                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_eval, tvb, offset, 1, FALSE);
1004                                         offset++;
1005                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_length, tvb, offset, 1, FALSE);
1006                                         offset++;
1007
1008                                         while (newoffset2<length1)
1009                                         {
1010                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_comp_type, tvb, offset, 1, FALSE);
1011                                                 comptype = tvb_get_guint8(tvb,offset);
1012                                                 offset++;
1013                                                 newoffset2++;
1014                                                 if (comptype==16)
1015                                                 {
1016                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4, tvb, offset, 4, FALSE);
1017                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4_mask, tvb, offset, 4, FALSE);
1018                                                         offset+=8;
1019                                                         newoffset2+=8;
1020                                                 }
1021                                                 if (comptype==32)
1022                                                 {
1023                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6, tvb, offset, 16, FALSE);
1024                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6_mask, tvb, offset, 16, FALSE);
1025                                                         offset+=32;
1026                                                         newoffset2+=32;
1027                                                 }
1028                                                 if (comptype==48)
1029                                                 {
1030                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_prot_id, tvb, offset, 1, FALSE);
1031                                                         offset+=1;
1032                                                         newoffset2+=1;
1033                                                 }
1034                                                 if (comptype==64)
1035                                                 {
1036                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_local, tvb, offset, 2, FALSE);
1037                                                         offset+=2;
1038                                                         newoffset2+=2;
1039                                                 }
1040                                                 if (comptype==65)
1041                                                 {
1042                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_low, tvb, offset, 2, FALSE);
1043                                                         offset+=2;
1044                                                         newoffset2+=2;
1045                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_high, tvb, offset, 2, FALSE);
1046                                                         offset+=2;
1047                                                         newoffset2+=2;
1048                                                 }
1049                                                 if (comptype==80)
1050                                                 {
1051                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_remote, tvb, offset, 2, FALSE);
1052                                                         offset+=2;
1053                                                         newoffset2+=2;
1054                                                 }
1055                                                 if (comptype==81)
1056                                                 {
1057                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_low, tvb, offset, 2, FALSE);
1058                                                         offset+=2;
1059                                                         newoffset2+=2;
1060                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_high, tvb, offset, 2, FALSE);
1061                                                         offset+=2;
1062                                                         newoffset2+=2;
1063                                                 }
1064                                                 if (comptype==96)
1065                                                 {
1066                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_security, tvb, offset, 4, FALSE);
1067                                                         offset+=4;
1068                                                         newoffset2+=4;
1069                                                 }
1070                                                 if (comptype==112)
1071                                                 {
1072                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type, tvb, offset, 1, FALSE);
1073                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type_mask, tvb, offset, 1, FALSE);
1074                                                         offset+=2;
1075                                                         newoffset2+=2;
1076                                                 }
1077                                                 if (comptype==128)
1078                                                 {
1079                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_flow_label, tvb, offset, 3, FALSE);
1080                                                         offset+=3;
1081                                                         newoffset2+=3;
1082                                                 }
1083                                   }
1084                                 }
1085
1086                                 break;
1087                         case ADD_PACKET_FILTERS_TFT:
1088                                 /* Add packet filters to existing TFT */
1089                                 while (i<number)
1090                                 {
1091                                         i++;newoffset2=0;
1092                                         length1 =tvb_get_guint8(tvb,offset+1);
1093                                         ti = proto_tree_add_text(tree, tvb, offset, 2+length1, "Packet Filter %d",i);
1094                                         ie_tree = proto_item_add_subtree(ti, ett_gtpv2_ie);
1095                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_eval, tvb, offset, 1, FALSE);
1096                                         offset++;
1097                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_length, tvb, offset, 1, FALSE);
1098                                         offset++;
1099
1100                                         while (newoffset2<length1)
1101                                         {
1102                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_comp_type, tvb, offset, 1, FALSE);
1103                                                 comptype = tvb_get_guint8(tvb,offset);
1104                                                 offset++;
1105                                                 newoffset2++;
1106                                                 if (comptype==16)
1107                                                 {
1108                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4, tvb, offset, 4, FALSE);
1109                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4_mask, tvb, offset, 4, FALSE);
1110                                                         offset+=8;
1111                                                         newoffset2+=8;
1112                                                 }
1113                                                 if (comptype==32)
1114                                                 {
1115                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6, tvb, offset, 16, FALSE);
1116                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6_mask, tvb, offset, 16, FALSE);
1117                                                         offset+=32;
1118                                                         newoffset2+=32;
1119                                                 }
1120                                                 if (comptype==48)
1121                                                 {
1122                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_prot_id, tvb, offset, 1, FALSE);
1123                                                         offset+=1;
1124                                                         newoffset2+=1;
1125                                                 }
1126                                                 if (comptype==64)
1127                                                 {
1128                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_local, tvb, offset, 2, FALSE);
1129                                                         offset+=2;
1130                                                         newoffset2+=2;
1131                                                 }
1132                                                 if (comptype==65)
1133                                                 {
1134                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_low, tvb, offset, 2, FALSE);
1135                                                         offset+=2;
1136                                                         newoffset2+=2;
1137                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_high, tvb, offset, 2, FALSE);
1138                                                         offset+=2;
1139                                                         newoffset2+=2;
1140                                                 }
1141                                                 if (comptype==80)
1142                                                 {
1143                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_remote, tvb, offset, 2, FALSE);
1144                                                         offset+=2;
1145                                                         newoffset2+=2;
1146                                                 }
1147                                                 if (comptype==81)
1148                                                 {
1149                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_low, tvb, offset, 2, FALSE);
1150                                                         offset+=2;
1151                                                         newoffset2+=2;
1152                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_high, tvb, offset, 2, FALSE);
1153                                                         offset+=2;
1154                                                         newoffset2+=2;
1155                                                 }
1156                                                 if (comptype==96)
1157                                                 {
1158                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_security, tvb, offset, 4, FALSE);
1159                                                         offset+=4;
1160                                                         newoffset2+=4;
1161                                                 }
1162                                                 if (comptype==112)
1163                                                 {
1164                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type, tvb, offset, 1, FALSE);
1165                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type_mask, tvb, offset, 1, FALSE);
1166                                                         offset+=2;
1167                                                         newoffset2+=2;
1168                                                 }
1169                                                 if (comptype==128)
1170                                                 {
1171                                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_flow_label, tvb, offset, 3, FALSE);
1172                                                         offset+=3;
1173                                                         newoffset2+=3;
1174                                                 }
1175                                   }
1176                                 }
1177
1178                                 break;
1179                         case DELETE_TFT:
1180                                 /* Delete Existing TFT */
1181                                 break;
1182
1183                         case DELETE_PACKET_FILTERS_TFT:
1184                                 /* Delete Packet filters from existing TFT */
1185                                 while (i<number)
1186                                 {
1187                                         i++;
1188                                         ti = proto_tree_add_text(tree, tvb, offset, 1, "Packet Filter %d",i);
1189                                         ie_tree = proto_item_add_subtree(ti, ett_gtpv2_ie);
1190                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_id, tvb, offset, 1, FALSE);
1191                                         proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_direction, tvb, offset, 1, FALSE);
1192                                         offset++;
1193                                 }
1194                                 break;
1195                         case NO_TFT_OPERATION:
1196                                 /* No TFT operation */
1197                                 break;
1198                         case RESERVED:
1199                                 /* Reserved */
1200                                 break;
1201                         default:
1202                                 break;
1203                 }
1204
1205 }
1206 /*
1207  * 8.21 User Location Info (ULI)
1208  *
1209  * The flags ECGI, TAI, RAI, SAI and CGI in octed 5 indicate if the corresponding
1210  * fields are present in the IE or not. If one of these flags is set to "0", 
1211  * the corresponding field is not present at all. The respective identities are defined in 3GPP
1212  * TS 23.003 [2].
1213  * Editor's Note: The definition of ECGI is missing in 3GPP TS 23.003 v8.1.0. 
1214  * It can be found in 3GPP TS 36.413 v8.3.0, but it is expected that it will be moved
1215  * to 23.003 in a future version.
1216  */
1217
1218 static void
1219 dissect_gtpv2_uli(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1220 {
1221         int offset = 0;
1222         guint flags;
1223         flags = tvb_get_guint8(tvb,offset)&0x1f;
1224         /* ECGI B5 */
1225         proto_tree_add_item(tree, hf_gtpv2_uli_ecgi_flg, tvb, offset, 1, FALSE);
1226         /* TAI B4  */
1227         proto_tree_add_item(tree, hf_gtpv2_uli_tai_flg, tvb, offset, 1, FALSE);
1228         /* RAI B3  */
1229         proto_tree_add_item(tree, hf_gtpv2_uli_rai_flg, tvb, offset, 1, FALSE);
1230         /* SAI B2  */
1231         proto_tree_add_item(tree, hf_gtpv2_uli_sai_flg, tvb, offset, 1, FALSE);
1232         /* CGI B1  */
1233         proto_tree_add_item(tree, hf_gtpv2_uli_cgi_flg, tvb, offset, 1, FALSE);
1234         offset++;
1235
1236         /* 8.22.1 CGI field  */
1237         if (flags&0x01)
1238         {
1239                 dissect_e212_mcc_mnc(tvb, tree, 0);
1240                 offset+=3;
1241                 proto_tree_add_item(tree, hf_gtpv2_uli_cgi_lac, tvb, offset, 2, FALSE);
1242                 proto_tree_add_item(tree, hf_gtpv2_uli_cgi_ci, tvb, offset, 2, FALSE);
1243                 offset+=4;
1244                 if(offset==length)
1245                         return;
1246         }
1247
1248         /* 8.22.2 SAI field  */
1249         if (flags&0x02)
1250         {
1251                 dissect_e212_mcc_mnc(tvb, tree, 0);
1252                 offset+=3;
1253                 proto_tree_add_item(tree, hf_gtpv2_uli_sai_lac, tvb, offset, 2, FALSE);
1254                 proto_tree_add_item(tree, hf_gtpv2_uli_sai_sac, tvb, offset, 2, FALSE);
1255                 offset+=4;
1256                 if(offset==length)
1257                         return;
1258         }
1259         /* 8.22.3 RAI field  */
1260         if (flags&0x04)
1261         {
1262                 dissect_e212_mcc_mnc(tvb, tree, 0);
1263                 offset+=3;
1264                 proto_tree_add_item(tree, hf_gtpv2_uli_rai_lac, tvb, offset, 2, FALSE);
1265                 proto_tree_add_item(tree, hf_gtpv2_uli_rai_rac, tvb, offset, 2, FALSE);
1266                 offset+=4;
1267                 if(offset==length)
1268                         return;
1269         }
1270         /* 8.22.4 TAI field  */
1271         if (flags&0x08)
1272         {
1273                 dissect_e212_mcc_mnc(tvb, tree, 0);
1274                 offset+=3;
1275                 proto_tree_add_item(tree, hf_gtpv2_uli_tai_tac, tvb, offset, 2, FALSE);
1276                 offset+=2;
1277                 if(offset==length)
1278                         return;
1279         }
1280         /* 8.22.5 ECGI field */
1281         if (flags&0x10)
1282         {
1283                 /* The bits 8 through 5, of octet e+3 (Fig 8.21.5-1 in TS 29.274 V8.2.0) are spare
1284                 and hence they would not make any difference to the hex string following it, thus we directly read 4 bytes from tvb */
1285
1286                 proto_tree_add_item(tree, hf_gtpv2_uli_ecgi_eci, tvb, offset, 4, FALSE);
1287                 offset+=4;
1288
1289         }
1290 }
1291
1292 /*
1293  * 8.22 Fully Qualified TEID (F-TEID) 
1294  */
1295 static const value_string gtpv2_f_teid_interface_type_vals[] = {
1296         {0, "S1-U eNodeB GTP-U interface"},
1297         {1, "S1-U SGW GTP-U interface"},
1298         {2, "S12 RNC GTP-U interface"},
1299         {3, "S12 SGW GTP-U interface"},
1300         {4, "S5/S8 SGW GTP-U interface"},
1301         {5, "S5/S8 PGW GTP-U interface"},
1302         {6, "S5/S8 SGW GTP-C interface"},
1303         {7, "S5/S8 PGW GTP-C interface"},
1304         {8, "S5/S8 SGW PMIPv6 interface (the 32 bit GRE key is encoded in 32 bit TEID field "
1305                 "and since alternate CoA is not used the control plane and user plane addresses are the same for PMIPv6)"},
1306         {9, "S5/S8 PGW PMIPv6 interface (the 32 bit GRE key is encoded in 32 bit TEID field "
1307                 "and the control plane and user plane addresses are the same for PMIPv6)"},
1308         {10, "S11 MME GTP-C interface"},
1309         {11, "S11/S4 SGW GTP-C interface"},
1310         {12, "S10 MME GTP-C interface"},
1311         {13, "S3 MME GTP-C interface"},
1312         {14, "S3 SGSN GTP-C interface"},
1313         {15, "S4 SGSN GTP-U interface"},
1314         {16, "S4 SGW GTP-U interface"},
1315         {17, "S4 SGSN GTP-C interface"},
1316         {18, "S16 SGSN GTP-C interface"},
1317         {19, "eNodeB GTP-U interface for DL data forwarding"},
1318         {20, "eNodeB GTP-U interface for UL data forwarding"},
1319         {21, "RNC GTP-U interface for data forwarding"},
1320         {22, "SGSN GTP-U interface for data forwarding"},
1321         {23, "SGW GTP-U interface for data forwarding"},
1322         {0, NULL}
1323 };
1324 static void
1325 dissect_gtpv2_f_teid(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1326 {
1327         int offset = 0;
1328         guint8 v4, v6;
1329         v4 = tvb_get_guint8(tvb,offset)& 0x80;
1330         v6 = tvb_get_guint8(tvb,offset)& 0x40;
1331         proto_tree_add_item(tree, hf_gtpv2_f_teid_v4, tvb, offset, 1, FALSE);
1332         proto_tree_add_item(tree, hf_gtpv2_f_teid_v6, tvb, offset, 1, FALSE);
1333         proto_tree_add_item(tree, hf_gtpv2_f_teid_interface_type, tvb, offset, 1, FALSE);
1334
1335         offset++;
1336         proto_tree_add_item(tree, hf_gtpv2_f_teid_gre_key, tvb, offset, 4, FALSE);
1337
1338         offset= offset+4;
1339         if (v4)
1340         {
1341                 proto_tree_add_item(tree, hf_gtpv2_f_teid_ipv4, tvb, offset, 4, FALSE);
1342                 offset= offset+4;
1343         }
1344         if (v6)
1345         {
1346                 proto_tree_add_item(tree, hf_gtpv2_f_teid_ipv6, tvb, offset, 16, FALSE);
1347                 offset= offset+16;
1348         }
1349 }
1350 /*
1351  * 8.23 TMSI 
1352  */
1353 /*
1354  * 8.24 Global CN-Id
1355  */
1356
1357 static void
1358 dissect_gtpv2_g_cn_id(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1359 {
1360         proto_tree_add_text(tree, tvb, 0, length, "IE data not dissected yet"); 
1361 }
1362 /*
1363  * 8.25 S103 PDN Data Forwarding Info (S103PDF)
1364  * 8.26 S1-U Data Forwarding (S1UDF) */
1365  
1366 /*8.27 Delay Value
1367  */
1368
1369 static void
1370 dissect_gtpv2_delay_value(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1371 {
1372
1373         int offset = 0;
1374
1375         proto_tree_add_item(tree, hf_gtpv2_delay_value, tvb, offset, 1, FALSE);
1376
1377
1378 }
1379 /*8.28 Bearer Context (grouped IE) */
1380
1381 static void
1382 dissect_gtpv2_bearer_ctx(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1383 {
1384         int offset= 0,i=0;
1385         int newoffset, newoffset1, newoffset2, newoffset3;
1386         guint8 number, opcode, ebit, comptype, length1;
1387         guint8 type, instances;
1388         proto_tree *ie_tree;
1389         proto_item *ti;
1390         guint8 v4, v6;
1391         guint16 lengths;
1392         while (offset<length)
1393                 {
1394                         type = tvb_get_guint8(tvb,offset);
1395                         lengths = tvb_get_ntohs(tvb, offset+1);
1396                         ti = proto_tree_add_text(tree, tvb, offset, 4 + lengths, "%s : ", val_to_str(type, gtpv2_element_type_vals, "Unknown"));
1397                         ie_tree = proto_item_add_subtree(ti, ett_gtpv2_ie);
1398                         /* Octet 1 */
1399                         proto_tree_add_item(ie_tree, hf_gtpv2_ie, tvb, offset, 1, FALSE);
1400                         offset++;
1401
1402                         /*Octet 2 - 3 */
1403                         proto_tree_add_item(ie_tree, hf_gtpv2_ie_len, tvb, offset, 2, FALSE);
1404                         offset+=2;
1405                         /* CR Spare Instance Octet 4*/
1406                         proto_tree_add_item(ie_tree, hf_gtpv2_cr, tvb, offset, 1, FALSE);
1407
1408                         instances = tvb_get_guint8(tvb,offset)& 0x0f;
1409                         proto_tree_add_item(ie_tree, hf_gtpv2_instance, tvb, offset, 1, FALSE);
1410                         offset++;
1411                         switch(type)
1412                         {
1413                                 case 73:
1414                                         /* EPS Bearer ID */
1415                                         proto_tree_add_item(ie_tree, hf_gtpv2_ebi, tvb, offset, 1, FALSE);
1416                                         offset+=lengths;
1417                                         break;
1418                                 case 2:
1419                                         /* Cause */
1420                                         proto_tree_add_item(ie_tree, hf_gtpv2_cause, tvb, offset, 1, FALSE);
1421                                         proto_tree_add_item(ie_tree, hf_gtpv2_cause_cs, tvb, offset+1, 1, FALSE);
1422                                         offset+=lengths;
1423                                         break;
1424                                 case 80:
1425                                         /* Bearer Qos */
1426                                                 newoffset3= offset;
1427                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_pvi, tvb, newoffset3, 1, FALSE);
1428                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_pl, tvb, newoffset3, 1, FALSE);
1429                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_pci, tvb, newoffset3, 1, FALSE);
1430
1431                                                 newoffset3++;
1432                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_label_qci, tvb, newoffset3, 1, FALSE);
1433
1434                                                 newoffset3++;
1435                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_mbr_up, tvb, newoffset3, 5, FALSE);
1436
1437                                                 newoffset3= newoffset3+5;
1438                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_mbr_down, tvb, newoffset3, 5, FALSE);
1439
1440                                                 newoffset3= newoffset3+5;
1441                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_gbr_up, tvb, newoffset3, 5, FALSE);
1442
1443                                                 newoffset3= newoffset3+5;
1444                                                 proto_tree_add_item(ie_tree, hf_gtpv2_bearer_qos_gbr_down, tvb, newoffset3, 5, FALSE);
1445
1446                                                 newoffset3= newoffset3+5;
1447                                                 offset+=lengths;
1448                                                 break;
1449                                 case 84:
1450                                         /* TFT */
1451                                                 newoffset1=offset;
1452                                                 number = tvb_get_guint8(tvb,newoffset1)& 0x0f;
1453                                                 opcode = tvb_get_guint8(tvb,newoffset1)& 0xe0;
1454                                                 ebit = tvb_get_guint8(tvb,newoffset1)& 0x10;
1455                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_opcode, tvb, newoffset1, 1, FALSE);
1456                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_number, tvb, newoffset1, 1, FALSE);
1457                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_ebit, tvb, newoffset1, 1, FALSE);
1458                                                 newoffset1++;
1459                                                 switch(opcode)
1460                                                         {
1461                                                                 case SPARE:
1462                                                                         /* Spare */
1463                                                                         break;
1464                                                                 case CREATE_NEW_TFT:
1465                                                                         /* Create New TFT */
1466                                                                 case ADD_PACKET_FILTERS_TFT:
1467                                                                         /* Add packet filters to existing TFT */
1468                                                                 case REPLACE_PACKET_FILTERS_TFT:
1469                                                                         /*Replace Packet filters in existing TFT */
1470                                                                         while (i<number)
1471                                                                         {
1472                                                                                 i++;newoffset2=0;
1473                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_id, tvb, newoffset1, 1, FALSE);
1474                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_direction, tvb, newoffset1, 1, FALSE);
1475                                                                                 newoffset1++;
1476                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_eval, tvb, newoffset1, 1, FALSE);
1477                                                                                 newoffset1++;
1478                                                                                 length1 =tvb_get_guint8(tvb,newoffset1);
1479                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_length, tvb, newoffset1, 1, FALSE);
1480                                                                                 newoffset1++;
1481
1482                                                                                 while (newoffset2<length1)
1483                                                                                 {
1484                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_comp_type, tvb, newoffset1, 1, FALSE);
1485                                                                                 comptype = tvb_get_guint8(tvb,newoffset1);
1486                                                                                 newoffset1++;
1487                                                                                 newoffset2++;
1488                                                                                         if (comptype==16)
1489                                                                                         {
1490                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4, tvb, newoffset1, 4, FALSE);
1491                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv4_mask, tvb, newoffset1, 4, FALSE);
1492                                                                                                 newoffset1+=8;
1493                                                                                                 newoffset2+=8;
1494                                                                                         }
1495                                                                                         if (comptype==32)
1496                                                                                         {
1497                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6, tvb, newoffset1, 16, FALSE);
1498                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_ipv6_mask, tvb, newoffset1, 16, FALSE);
1499                                                                                                 newoffset1+=32;
1500                                                                                                 newoffset2+=32;
1501                                                                                         }
1502                                                                                         if (comptype==48)
1503                                                                                         {
1504                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_prot_id, tvb, newoffset1, 1, FALSE);
1505                                                                                                 newoffset1+=1;
1506                                                                                                 newoffset2+=1;
1507                                                                                         }
1508                                                                                         if (comptype==64)
1509                                                                                         {
1510                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_local, tvb, newoffset1, 2, FALSE);
1511                                                                                                 newoffset1+=2;
1512                                                                                                 newoffset2+=2;
1513                                                                                         }
1514                                                                                         if (comptype==65)
1515                                                                                         {
1516                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_low, tvb, newoffset1, 2, FALSE);
1517                                                                                                 newoffset1+=2;
1518                                                                                                 newoffset2+=2;
1519                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_local_port_high, tvb, newoffset1, 2, FALSE);
1520                                                                                                 newoffset1+=2;
1521                                                                                                 newoffset2+=2;
1522                                                                                         }
1523                                                                                         if (comptype==80)
1524                                                                                         {
1525                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_single_remote, tvb, newoffset1, 2, FALSE);
1526                                                                                                 newoffset1+=2;
1527                                                                                                 newoffset2+=2;
1528                                                                                         }
1529                                                                                         if (comptype==81)
1530                                                                                         {
1531                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_low, tvb, newoffset1, 2, FALSE);
1532                                                                                                 newoffset1+=2;
1533                                                                                                 newoffset2+=2;
1534                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_remote_port_high, tvb, newoffset1, 2, FALSE);
1535                                                                                                 newoffset1+=2;
1536                                                                                                 newoffset2+=2;
1537                                                                                         }
1538                                                                                         if (comptype==96)
1539                                                                                         {
1540                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_security, tvb, newoffset1, 4, FALSE);
1541                                                                                                 newoffset1+=4;
1542                                                                                                 newoffset2+=4;
1543                                                                                         }
1544                                                                                         if (comptype==112)
1545                                                                                         {
1546                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type, tvb, newoffset1, 1, FALSE);
1547                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_service_type_mask, tvb, newoffset1, 1, FALSE);
1548                                                                                                 newoffset1+=2;
1549                                                                                                 newoffset2+=2;
1550                                                                                         }
1551                                                                                         if (comptype==128)
1552                                                                                         {
1553                                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_flow_label, tvb, offset, 3, FALSE);
1554                                                                                                 newoffset1+=3;
1555                                                                                                 newoffset2+=3;
1556                                                                                         }
1557                                                                           }
1558                                                                         }
1559
1560                                                                         break;
1561                                                                 case DELETE_TFT:
1562                                                                         /* Delete Existing TFT */
1563                                                                         break;
1564
1565                                                                 case DELETE_PACKET_FILTERS_TFT:
1566                                                                         /* Delete Packet filters from existing TFT */
1567                                                                         while (i<number)
1568                                                                                 {
1569                                                                                 i++;
1570                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_id, tvb, newoffset1, 1, FALSE);
1571                                                                                 proto_tree_add_item(ie_tree, hf_gtpv2_b_tft_pf_direction, tvb, newoffset1, 1, FALSE);
1572                                                                                 newoffset1++;
1573                                                                                 }
1574                                                                         break;
1575                                                                 case NO_TFT_OPERATION:
1576                                                                         /* No TFT operation */
1577                                                                         break;
1578                                                                 case RESERVED:
1579                                                                         /* Reserved */
1580                                                                         break;
1581                                                                 default:
1582                                                                         break;
1583                                                         }
1584                                         offset+=lengths;
1585                                         break;
1586
1587                                 case 87:
1588                                         /* F-TEID*/
1589                                         newoffset=offset;
1590                                         v4 = tvb_get_guint8(tvb,newoffset)& 0x80;
1591                                         v6 = tvb_get_guint8(tvb,newoffset)& 0x40;
1592
1593                                         proto_tree_add_item(ie_tree, hf_gtpv2_f_teid_v4, tvb, newoffset, 1, FALSE);
1594                                         proto_tree_add_item(ie_tree, hf_gtpv2_f_teid_v6, tvb, newoffset, 1, FALSE);
1595                                         proto_tree_add_item(ie_tree, hf_gtpv2_f_teid_interface_type, tvb, newoffset, 1, FALSE);
1596                                         newoffset++;
1597                                         proto_tree_add_item(ie_tree, hf_gtpv2_f_teid_gre_key, tvb, newoffset, 4, FALSE);
1598                                         newoffset= newoffset+4;
1599                                         if (v4)
1600                                         {
1601                                                 proto_tree_add_item(ie_tree, hf_gtpv2_f_teid_ipv4, tvb, newoffset, 4, FALSE);
1602                                                 newoffset= newoffset+4;
1603                                         }
1604                                         if (v6)
1605                                         {
1606                                                 proto_tree_add_item(ie_tree, hf_gtpv2_f_teid_ipv6, tvb, newoffset, 16, FALSE);
1607                                                 newoffset= newoffset+16;
1608                                         }
1609                                         offset+=lengths;
1610                                         break;
1611                                 case 94:
1612                                         /* Charging Id */
1613                                         proto_tree_add_item(ie_tree, hf_gtpv2_charging_id, tvb, offset, length, FALSE);
1614                                         offset+=lengths;
1615                                         break;
1616                                 case 97:
1617                                         /* Bearer flags */
1618                                         proto_tree_add_item(ie_tree, hf_gtpv2_bearer_flag, tvb, offset, length, FALSE);
1619                                         offset+=lengths;
1620                                         break;
1621                                 case 122:
1622                                         /* NSAPI */
1623                                         proto_tree_add_text(ie_tree, tvb, 0, lengths, "IE data not dissected yet");
1624                                         offset+=lengths;
1625                                         break;
1626                                 case 137:
1627                                         /* Transaction Identifier */
1628                                         proto_tree_add_text(ie_tree, tvb, 0, lengths, "IE data not dissected yet");
1629                                         offset+=lengths;
1630                                         break;
1631                                 default:
1632                                         break;
1633                         }
1634
1635                 }
1636
1637 }
1638 /* 8.29 Charging ID */
1639 static void
1640 dissect_gtpv2_charging_id(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1641 {
1642
1643         int offset = 0;
1644
1645         proto_tree_add_item(tree, hf_gtpv2_charging_id, tvb, offset, length, FALSE);
1646
1647
1648 }
1649
1650
1651  /* 8.30 Charging Characteristics  */
1652
1653 static void
1654 dissect_gtpv2_charging_characteristic(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1655 {
1656
1657         int offset = 0;
1658
1659         proto_tree_add_item(tree, hf_gtpv2_charging_characteristic, tvb, offset, length, FALSE);
1660
1661
1662 }
1663 /* 8.30 Bearer Flag  */
1664 static void
1665 dissect_gtpv2_bearer_flag(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1666 {
1667
1668         int offset = 0;
1669
1670         proto_tree_add_item(tree, hf_gtpv2_bearer_flag, tvb, offset, length, FALSE);
1671
1672
1673 }
1674 /* 8.34 PDN Type  */
1675 static void
1676 dissect_gtpv2_pdn_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1677 {
1678
1679         int offset = 0;
1680
1681         proto_tree_add_item(tree, hf_gtpv2_pdn_type, tvb, offset, length, FALSE);
1682
1683
1684 }
1685
1686 /* 8.31 Trace Information
1687  * 8.33 Paging Cause 
1688   */
1689
1690 /* 8.35 Procedure Transaction ID (PTI) */
1691 static void
1692 dissect_gtpv2_pti(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1693 {
1694         proto_tree_add_item(tree, hf_gtpv2_pti, tvb, 0, 1, FALSE);
1695 }
1696 /*
1697  * 8.36 DRX Parameter 
1698  * 8.37 UE Network Capability
1699  * 8.38 MM Context 
1700  * 8.39 PDN Connection (grouped IE)
1701  * 8.40 PDU Numbers 
1702  * 8.41 Packet TMSI (P-TMSI)
1703  * 8.42 P-TMSI Signature
1704  * 8.43 Hop Counter
1705  */
1706
1707 /* 8.44 UE Time Zone */
1708
1709 static const value_string gtpv2_ue_time_zone_dst_vals[] = {
1710     {0, "No Adjustments for Daylight Saving Time"},
1711     {1, "+1 Hour Adjustments for Daylight Saving Time"},
1712         {2, "+2 Hour Adjustments for Daylight Saving Time"},
1713     {3, "Spare"},
1714     {0, NULL}
1715 };
1716 static void
1717 dissect_gtpv2_ue_time_zone(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1718 {
1719
1720         int offset = 0;
1721         proto_tree_add_item(tree, hf_gtpv2_ue_time_zone, tvb, offset, 1, FALSE);
1722
1723         offset= offset+ 1;
1724         proto_tree_add_item(tree, hf_gtpv2_ue_time_zone_dst, tvb, offset, 1, FALSE);
1725
1726
1727 }
1728 /* 8.45 Trace Reference
1729  * 8.56 Complete Request Message
1730  * 8.47 GUTI
1731  * 8.48 Fully Qualified Container (F-Container)
1732  * 8.49 Fully Qualified Cause (F-Cause)
1733  * 8.50 Selected PLMN ID
1734  * 8.51 Target Identification
1735  * 8.52 NSAPI
1736  * 8.53 Packet Flow ID
1737  * 8.54 RAB Context
1738  * 8.55 Source RNC PDCP context info
1739  * 8.56 UDP Source Port Number
1740  */
1741
1742 /*8.57 APN Restriction */
1743 static void
1744 dissect_gtpv2_apn_rest(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1745 {
1746         proto_tree_add_item(tree, hf_gtpv2_apn_rest, tvb, 0, 1, FALSE);
1747 }
1748
1749 /* 8.58 Selection Mode */
1750 static const value_string gtpv2_selec_mode_vals[] = {
1751     {0, "MS or network provided APN, subscribed verified"},
1752     {1, "MS provided APN, subscription not verified"},
1753         {2, "Network provided APN, subscription not verified"},
1754     {3, "Network provided APN, subscription not verified (Basically for Future use"},
1755     {0, NULL}
1756 };
1757
1758 static void
1759 dissect_gtpv2_selec_mode(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1760 {
1761         int offset=0;
1762
1763         proto_tree_add_item(tree, hf_gtpv2_selec_mode, tvb, offset, 1, FALSE);
1764 }
1765
1766
1767  /* 8.59 Source Identification */
1768
1769  /* 8.60 Bearer Control Mode */
1770  static const value_string gtpv2_bearer_control_mode_vals[] = {
1771     {0, "Selected Bearer Control Mode-'MS_only'"},
1772     {1, "Selected Bearer Control Mode-'Network_only'"},
1773         {2, "Selected Bearer Control Mode-'MS/NW'"},
1774     {0, NULL}
1775 };
1776
1777 static void
1778 dissect_gtpv2_bearer_control_mode(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1779 {
1780         proto_tree_add_item(tree, hf_gtpv2_bearer_control_mode, tvb, 0, 1, FALSE);
1781 }
1782 /*
1783  * 8.61 Change Reporting Action
1784  */
1785 static const value_string gtpv2_cng_rep_act_vals[] = {
1786         {0, "Stop Reporting"},
1787         {1, "Start Reporting CGI/SAI"},
1788         {2, "Start Reporting RAI"},
1789         {0, NULL}
1790 };
1791
1792 static void
1793 dissect_cng_rep_act(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1794 {
1795
1796         proto_tree_add_item(tree, hf_gtpv2_cng_rep_act, tvb, 0, 1, FALSE); 
1797 }
1798 /*
1799  * 8.62 Fully qualified PDN Connection Set Identifier (FQ-CSID)
1800  * 8.63 Channel needed
1801  * 8.64 eMLPP Priority
1802  */
1803
1804 /*8.65 Node Type */
1805 static const value_string gtpv2_node_type_vals[] = {
1806         {0, "MME"},
1807         {1, "SGSN"},
1808         {0, NULL}
1809 };
1810
1811 static void
1812 dissect_node_type(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item _U_, guint16 length _U_, guint8 instance _U_)
1813 {
1814
1815         proto_tree_add_item(tree, hf_gtpv2_node_type, tvb, 0, 1, FALSE);
1816 }
1817
1818  /* 8.66 Fully Qualified Domain Name (FQDN)
1819  * 8.67 Private Extension
1820  */
1821 typedef struct _gtpv2_ie {
1822     int ie_type;
1823     void (*decode) (tvbuff_t *, packet_info *, proto_tree *, proto_item *, guint16, guint8);
1824 } gtpv2_ie_t;
1825
1826 static const gtpv2_ie_t gtpv2_ies[] = {
1827     {GTPV2_IE_IMSI, dissect_gtpv2_imsi},
1828         {GTPV2_IE_CAUSE, dissect_gtpv2_cause},                          /* 2, Cause (without embedded offending IE) 8.4 */
1829         {GTPV2_REC_REST_CNT, dissect_gtpv2_recovery},           /* 3, Recovery (Restart Counter) 8.5 */
1830                                                                                                                 /* 4-50 Reserved for S101 interface Extendable / See 3GPP TS 29.276 [14] */
1831                                                                                                                 /* 51-70 Reserved for Sv interface Extendable / See 3GPP TS 29.280 [15] */
1832         {GTPV2_APN, dissect_gtpv2_apn},                                         /* 71, Access Point Name (APN) 8.6 */
1833         {GTPV2_AMBR, dissect_gtpv2_ambr},                                       /* 72, Aggregate Maximum Bit Rate (AMBR) */
1834         {GTPV2_EBI, dissect_gtpv2_ebi},                                         /* 73, EPS Bearer ID (EBI)  8.8 */
1835         {GTPV2_IP_ADDRESS, dissect_gtpv2_ip_address},           /* 74, IP Address */
1836         {GTPV2_MEI, dissect_gtpv2_mei},                                 /* 74, Mobile Equipment Identity */
1837         {GTPV2_IE_MSISDN, dissect_gtpv2_msisdn},                        /* 76, MSISDN 8.11 */
1838         {GTPV2_INDICATION, dissect_gtpv2_ind},                          /* 77 Indication 8.12 */
1839         {GTPV2_PCO, dissect_gtpv2_pco},                                         /* 78 Protocol Configuration Options (PCO) 8.13 */
1840         {GTPV2_PAA, dissect_gtpv2_paa},                                         /* 79 PDN Address Allocation (PAA) 8.14 */
1841         {GTPV2_BEARER_QOS,dissect_gtpv2_bearer_qos},            /* 80 Bearer Level Quality of Service (Bearer QoS) 8.15 */
1842         {GTPV2_FLOW_QOS, dissect_gtpv2_flow_qos},                       /* 81 Flow Quality of Service (Flow QoS) 8.16 */
1843         {GTPV2_IE_RAT_TYPE, dissect_gtpv2_rat_type},            /* 82, RAT Type  8.17 */
1844         {GTPV2_IE_SERV_NET, dissect_gtpv2_serv_net},            /* 83, Serving Network 8.18 */
1845         {GTPV2_BEARER_TFT, dissect_gtpv2_bearer_tft},           /* 84, Bearer TFT 8.19 */
1846         {GTPV2_TAD, dissect_gtpv2_tad},                                         /* 85, Traffic Aggregate Description 8.20 */
1847         {GTPV2_ULI, dissect_gtpv2_uli},                                         /* 86, User Location Info (ULI) 8.22 */
1848         {GTPV2_F_TEID, dissect_gtpv2_f_teid},                           /* 87, Fully Qualified Tunnel Endpoint Identifier (F-TEID) 8.23 */
1849         {GTPV2_G_CN_ID, dissect_gtpv2_g_cn_id},                         /* 89, Global CN-Id 8.25 */
1850         {GTPV2_DELAY_VALUE, dissect_gtpv2_delay_value},         /* 92, Delay Value 8.29 */
1851         {GTPV2_BEARER_CTX,dissect_gtpv2_bearer_ctx},            /* 93, Bearer Context  8.31 */
1852         {GTPV2_CHARGING_ID, dissect_gtpv2_charging_id},     /* 94, Charging Id */
1853         {GTPV2_CHARGING_CHARACTERISTIC,                                         /* 95 Charging Characteristic */
1854          dissect_gtpv2_charging_characteristic},
1855         {GTPV2_BEARER_FLAG, dissect_gtpv2_bearer_flag},     /* 97, Bearer Flag */
1856         {GTPV2_PDN_TYPE, dissect_gtpv2_pdn_type},                       /* 99, PDN Type */
1857         {GTPV2_PTI, dissect_gtpv2_pti},                                         /* 100 Procedure Transaction Id */
1858         {GTPV2_UE_TIME_ZONE, dissect_gtpv2_ue_time_zone},   /* 114, UE Time Zone */
1859         {GTPV2_APN_RESTRICTION,                                                         /* 127, APN Restriction */
1860         dissect_gtpv2_apn_rest},
1861         {GTPV2_SELEC_MODE,dissect_gtpv2_selec_mode},            /* 128 Selection Mode */
1862         {GTPV2_BEARER_CONTROL_MODE,
1863         dissect_gtpv2_bearer_control_mode},                                     /* 130 Bearer Control Mode*/
1864         {GTPV2_CNG_REP_ACT ,dissect_cng_rep_act},                       /* 131 Change Reporting Action 8.61 */
1865         {GTPV2_NODE_TYPE ,dissect_node_type},                           /* 135 Node Type 8.65 */
1866                                                                                                                 /* 137-254 Spare. For future use. FFS */
1867
1868     {0, dissect_gtpv2_unknown}
1869 };
1870
1871
1872
1873 static void
1874 dissect_gtpv2_ie_common(tvbuff_t * tvb, packet_info * pinfo _U_, proto_tree * tree, gint offset)
1875 {
1876         proto_tree *ie_tree;
1877         proto_item *ti;
1878         tvbuff_t *ie_tvb;
1879         guint8 type, instance;
1880         guint16 length;
1881         int i;
1882         /*
1883          * Octets       8       7       6       5               4       3       2       1
1884          *      1               Type
1885          *      2-3             Length = n
1886          *      4               CR                      Spare   Instance
1887          * 5-(n+4)      IE specific data
1888          */
1889         while(offset < (gint)tvb_reported_length(tvb)){
1890                 /* Get the type and length */
1891                 type = tvb_get_guint8(tvb,offset);
1892                 length = tvb_get_ntohs(tvb, offset+1);
1893                 ti = proto_tree_add_text(tree, tvb, offset, 4 + length, "%s : ", val_to_str(type, gtpv2_element_type_vals, "Unknown")); 
1894                 ie_tree = proto_item_add_subtree(ti, ett_gtpv2_ie);
1895                 /* Octet 1 */
1896                 proto_tree_add_item(ie_tree, hf_gtpv2_ie, tvb, offset, 1, FALSE);
1897                 offset++;
1898                 
1899                 /*Octet 2 - 3 */
1900                 proto_tree_add_item(ie_tree, hf_gtpv2_ie_len, tvb, offset, 2, FALSE);
1901                 offset+=2;
1902                 /* CR Spare Instance Octet 4*/
1903                 proto_tree_add_item(ie_tree, hf_gtpv2_cr, tvb, offset, 1, FALSE);
1904
1905                 instance = tvb_get_guint8(tvb,offset)& 0x0f;
1906                 proto_tree_add_item(ie_tree, hf_gtpv2_instance, tvb, offset, 1, FALSE);
1907                 offset++;
1908                 
1909                 /* TODO: call IE dissector here */
1910                 if(type==GTPV2_IE_RESERVED){
1911                         /* Treat IE type zero specal as type zero is used to end the loop in the else branch */
1912                         proto_tree_add_text(ie_tree, tvb, offset, length, "IE type Zero is Reserved and should not be used");
1913                 }else{
1914                         i = -1;
1915                         /* Loop over the IE dissector list to se if we find an entry, the last entry will have ie_type=0 braking the loop */
1916                         while (gtpv2_ies[++i].ie_type){
1917                                 if (gtpv2_ies[i].ie_type == type)
1918                                         break;
1919                         }
1920                         /* Just give the IE dissector the IE */
1921                         ie_tvb = tvb_new_subset(tvb, offset, length, length);
1922                         (*gtpv2_ies[i].decode) (ie_tvb, pinfo , ie_tree, ti, length, instance);
1923                 }
1924
1925                 offset = offset + length;
1926         }
1927 }
1928
1929 static void
1930 dissect_gtpv2(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
1931 {
1932     proto_tree *gtpv2_tree, *flags_tree;
1933     proto_item *ti, *tf;
1934         guint8 message_type, t_flag;
1935         int offset = 0;
1936
1937
1938         /* Currently we get called from the GTP dissector no need to check the version */
1939     col_set_str(pinfo->cinfo, COL_PROTOCOL, "GTPv2");
1940     if (check_col(pinfo->cinfo, COL_INFO))
1941                 col_clear(pinfo->cinfo, COL_INFO);
1942
1943         /* message type is in octet 2 */
1944         message_type = tvb_get_guint8(tvb,1);
1945     if (check_col(pinfo->cinfo, COL_INFO))
1946                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(message_type, gtpv2_message_type_vals, "Unknown"));
1947
1948
1949         proto_tree_add_item(tree, proto_gtpv2, tvb, offset, -1, FALSE);
1950
1951     if (tree) {
1952                 ti = proto_tree_add_text(tree, tvb, offset, -1, "%s", val_to_str(message_type, gtpv2_message_type_vals, "Unknown"));
1953                 gtpv2_tree = proto_item_add_subtree(ti, ett_gtpv2);
1954         
1955                 /* Control Plane GTP uses a variable length header. Control Plane GTP header 
1956                  * length shall be a multiple of 4 octets.
1957                  * Figure 5.1-1 illustrates the format of the GTPv2-C Header.
1958                  * Bits           8  7  6       5               4       3               2               1
1959                  * Octets       1 Version       Spare   T       Spare   Spare   Spare
1960                  *                      2 Message Type
1961                  *                      3 Message Length (1st Octet)
1962                  *                      4 Message Length (2nd Octet)
1963                  *      m-k(m+3)        If T flag is set to 1, then TEID shall be placed into octets 5-8.
1964                  *                              Otherwise, TEID field is not present at all.
1965                  *      n-(n+1)   Sequence Number
1966                  * (n+2)-(n+3) Spare
1967                  * Figure 5.1-1: General format of GTPv2 Header for Control Plane
1968                  */
1969                 tf = proto_tree_add_item(gtpv2_tree, hf_gtpv2_flags, tvb, offset, 1, FALSE);
1970                 flags_tree = proto_item_add_subtree(tf, ett_gtpv2_flags);
1971
1972                 /* Octet 1 */
1973                 t_flag = (tvb_get_guint8(tvb,offset) & 0x08)>>3;
1974                 proto_tree_add_item(flags_tree, hf_gtpv2_version, tvb, offset, 1, FALSE);
1975                 proto_tree_add_item(flags_tree, hf_gtpv2_t, tvb, offset, 1, FALSE);
1976                 offset++;
1977
1978                 /* Octet 2 */
1979                 proto_tree_add_item(gtpv2_tree, hf_gtpv2_message_type, tvb, offset, 1, FALSE);
1980                 offset++;
1981                 /* Octet 3 - 4 */
1982                 proto_tree_add_item(gtpv2_tree, hf_gtpv2_msg_length, tvb, offset, 2, FALSE);
1983                 offset+=2;
1984
1985                 if(t_flag){
1986                         /* Tunnel Endpoint Identifier 4 octets */
1987                         proto_tree_add_item(gtpv2_tree, hf_gtpv2_teid, tvb, offset, 4, FALSE);
1988                         offset+=4;
1989                 }
1990                 /* Sequence Number 2 octets */
1991                 proto_tree_add_item(gtpv2_tree, hf_gtpv2_seq, tvb, offset, 2, FALSE);
1992                 offset+=2;
1993
1994                 /* Spare 2 octets */
1995                 proto_tree_add_item(gtpv2_tree, hf_gtpv2_spare, tvb, offset, 2, FALSE);
1996                 offset+=2;
1997
1998                 dissect_gtpv2_ie_common(tvb, pinfo, gtpv2_tree, offset);
1999         }
2000
2001
2002 }
2003 void proto_register_gtpv2(void)
2004 {
2005     static hf_register_info hf_gtpv2[] = {
2006                 {&hf_gtpv2_flags,
2007                 {"Flags", "gtpv2.flags",
2008                 FT_UINT8, BASE_DEC, NULL, 0x0,
2009                 NULL, HFILL}
2010                 },
2011                 {&hf_gtpv2_version,
2012                 {"Version", "gtpv2.version",
2013                 FT_UINT8, BASE_DEC, NULL, 0xe0,
2014                 NULL, HFILL}
2015                 },
2016                 { &hf_gtpv2_t,
2017                 {"T", "gtpv2.t",
2018                 FT_UINT8, BASE_DEC, NULL, 0x08,
2019                 "If TEID field is present or not", HFILL}
2020                 },
2021                 { &hf_gtpv2_message_type,
2022                 {"Message Type", "gtpv2.message_type",
2023                 FT_UINT8, BASE_DEC, VALS(gtpv2_message_type_vals), 0x0,
2024                 NULL, HFILL}
2025                 },
2026                 { &hf_gtpv2_msg_length,
2027                 {"Message Length", "gtpv2.msg_lengt",
2028                 FT_UINT16, BASE_DEC, NULL, 0x0,
2029                 NULL, HFILL}
2030                 },
2031                 { &hf_gtpv2_teid,
2032                 {"Tunnel Endpoint Identifier", "gtpv2.teid",
2033                 FT_UINT32, BASE_DEC, NULL, 0x0,
2034                 "TEID", HFILL}
2035                 },
2036                 { &hf_gtpv2_seq,
2037                 {"Sequence Number", "gtpv2.seq",
2038                 FT_UINT32, BASE_DEC, NULL, 0x0,
2039                 "SEQ", HFILL}
2040                 },
2041                 { &hf_gtpv2_spare,
2042                 {"Spare", "gtpv2.spare",
2043                 FT_UINT16, BASE_DEC, NULL, 0x0,
2044                 NULL, HFILL}
2045                 },
2046                 { &hf_gtpv2_ie,
2047                 {"IE Type", "gtpv2.ie_type",
2048                 FT_UINT8, BASE_DEC, VALS(gtpv2_element_type_vals), 0x0,
2049                 NULL, HFILL}
2050                 },
2051                 { &hf_gtpv2_ie_len,
2052                 {"IE Length", "gtpv2.ie_len",
2053                 FT_UINT16, BASE_DEC, NULL, 0x0,
2054                 "length of the information element excluding the first four octets", HFILL}
2055                 },
2056                 { &hf_gtpv2_cr,
2057                 {"CR flag", "gtpv2.cr",
2058                 FT_UINT8, BASE_DEC, NULL, 0xe0,
2059                 NULL, HFILL}
2060                 },
2061                 { &hf_gtpv2_instance,
2062                 {"Instance", "gtpv2.instance",
2063                 FT_UINT8, BASE_DEC, NULL, 0x0f,
2064                 NULL, HFILL}
2065                 },
2066                 {&hf_gtpv2_imsi,
2067                 {"IMSI(International Mobile Subscriber Identity number)", "gtpv2.imsi",
2068                 FT_STRING, BASE_NONE, NULL, 0,
2069                 NULL, HFILL}
2070                 },
2071                 { &hf_gtpv2_cause,
2072                 {"Cause", "gtpv2.cause",
2073                 FT_UINT8, BASE_DEC, VALS(gtpv2_cause_vals), 0x0,
2074                 NULL, HFILL}
2075                 },
2076                 {&hf_gtpv2_cause_cs,
2077                 {"Cause Source (CS: True-Error originated by remote node, False-Error originated by Node sending the Message)","gtpv2.cs",
2078                 FT_BOOLEAN, 8, NULL, 0x01,
2079                 NULL, HFILL}
2080                 },
2081                 { &hf_gtpv2_rec,
2082                 {"Restart Counter", "gtpv2.rec",
2083                 FT_UINT8, BASE_DEC, NULL, 0x0,
2084                 NULL, HFILL}
2085                 },
2086                 {&hf_gtpv2_apn,
2087                 {"APN (Access Point Name)", "gtp.apn",
2088                 FT_STRING, BASE_NONE, NULL, 0x0,
2089                 NULL, HFILL}
2090                 },
2091                 {&hf_gtpv2_ambr_up,
2092                 {"AMBR Uplink (Aggregate Maximum Bit Rate for Uplink)", "gtpv2.ambr_up",
2093                 FT_UINT32, BASE_DEC, NULL, 0x0,
2094                 NULL, HFILL}
2095                 },
2096                 {&hf_gtpv2_ambr_down,
2097                 {"AMBR Downlink(Aggregate Maximum Bit Rate for Downlink)", "gtpv2.ambr_down",
2098                 FT_UINT32, BASE_DEC, NULL, 0x0,
2099                 NULL, HFILL}
2100                 },
2101                 {&hf_gtpv2_ebi,
2102                 {"EPS Bearer ID (EBI)", "gtpv2.ebi",
2103                 FT_UINT8, BASE_DEC, NULL, 0x0f,
2104                 NULL, HFILL}
2105                 },
2106                 { &hf_gtpv2_ip_address_ipv4,
2107                 {"IP address IPv4", "gtpv2.ip_address_ipv4",
2108                 FT_IPv4, BASE_NONE, NULL, 0x0,
2109                 NULL, HFILL}
2110                 },
2111                 { &hf_gtpv2_ip_address_ipv6,
2112                 {"IP address IPv6", "gtpv2.ip_address_ipv6",
2113                 FT_IPv6, BASE_NONE, NULL, 0x0,
2114                 NULL, HFILL}
2115                 },
2116                 {&hf_gtpv2_mei,
2117                 {"MEI(Mobile Equipment Identity)", "gtpv2.mei",
2118                 FT_STRING, BASE_NONE, NULL, 0,
2119                 NULL, HFILL}
2120                 },
2121
2122                 {&hf_gtpv2_daf, 
2123                 {"DAF (Dual Address Bearer Flag)", "gtpv2.daf", 
2124                 FT_BOOLEAN, 8, NULL, 0x80, "DAF", HFILL}
2125                 },
2126                 {&hf_gtpv2_dtf,
2127                 {"DTF (Direct Tunnel Flag)","gtpv2.dtf",
2128                 FT_BOOLEAN, 8, NULL, 0x40, "DTF", HFILL}
2129                 },
2130                 {&hf_gtpv2_hi,
2131                 {"HI (Handover Indication)", "gtpv2.hi",
2132                 FT_BOOLEAN, 8, NULL, 0x20, "HI", HFILL}
2133                 },
2134                 {&hf_gtpv2_dfi,
2135                 {"DFI (Direct Forwarding Indication)", "gtpv2.dfi",
2136                 FT_BOOLEAN, 8, NULL, 0x10, "DFI", HFILL}
2137                 },
2138                 {&hf_gtpv2_oi,
2139                 {"OI (Operation Indication)","gtp.oi",
2140                 FT_BOOLEAN, 8, NULL, 0x08, "OI", HFILL}
2141                 },
2142                 {&hf_gtpv2_isrsi,
2143                 {"ISRSI (Idle mode Signalling Reduction Supported Indication)", "gtpv2.isrsi",
2144                 FT_BOOLEAN, 8, NULL, 0x04, "ISRSI", HFILL}
2145                 },
2146                 {&hf_gtpv2_israi,
2147                 {"ISRAI (Idle mode Signalling Reduction Activation Indication)",        "gtpv2.israi",
2148                 FT_BOOLEAN, 8, NULL, 0x02, "ISRAI", HFILL}
2149                 },
2150                 {&hf_gtpv2_sgwci,
2151                 {"SGWCI (SGW Change Indication)", "gtpv2.sgwci", 
2152                 FT_BOOLEAN, 8, NULL, 0x01, "SGWCI", HFILL}
2153                 },
2154                 {&hf_gtpv2_pt,
2155                 {"PT (Protocol Type)", "gtpv2.pt", 
2156                 FT_BOOLEAN, 8, NULL, 0x08, "PT", HFILL}
2157                 },
2158                 {&hf_gtpv2_tdi,
2159                 {"TDI (Teardown Indication)", "gtpv2.tdi", 
2160                 FT_BOOLEAN, 8, NULL, 0x04, "TDI", HFILL}
2161                 },
2162                 {&hf_gtpv2_si,
2163                 {"SI (Scope Indication)", "gtpv2.si", 
2164                 FT_BOOLEAN, 8, NULL, 0x02, "SI", HFILL}
2165                 },
2166                 {&hf_gtpv2_msv,
2167                 {"MSV (MS Validated)", "gtpv2.msv", 
2168                 FT_BOOLEAN, 8, NULL, 0x01, "MSV", HFILL}
2169                 },
2170                 { &hf_gtpv2_pdn_type,
2171                 {"PDN Type", "gtpv2.pdn_type",
2172                 FT_UINT8, BASE_DEC, VALS(gtpv2_pdn_type_vals), 0x07,
2173                 NULL, HFILL}
2174                 },
2175                 { &hf_gtpv2_pdn_ipv4,
2176                 {"PDN IPv4", "gtpv2.pdn_ipv4",
2177                 FT_IPv4, BASE_NONE, NULL, 0x0,
2178                 NULL, HFILL}
2179                 },
2180                 { &hf_gtpv2_pdn_ipv6_len,
2181                 {"IPv6 Prefix Length", "gtpv2.pdn_ipv6_len",
2182                 FT_UINT8, BASE_DEC, NULL, 0x0,
2183                 NULL, HFILL}
2184                 },
2185                 { &hf_gtpv2_pdn_ipv6,
2186                 {"PDN IPv6", "gtpv2.pdn_ipv6",
2187                 FT_IPv6, BASE_NONE, NULL, 0x0,
2188                 NULL, HFILL}
2189                 },
2190                 {&hf_gtpv2_bearer_qos_pvi,
2191                 {"PVI (Pre-emption Vulnerability)", "gtpv2.bearer_qos_pvi",
2192                 FT_BOOLEAN, 8, NULL, 0x01,
2193                 NULL, HFILL}
2194                 },
2195                 {&hf_gtpv2_bearer_qos_pl,
2196                 {"PL (Priority Level)", "gtpv2.bearer_qos_pl",
2197                 FT_UINT8, BASE_DEC, NULL, 0x3c,
2198                 NULL, HFILL}
2199                 },
2200                 {&hf_gtpv2_bearer_qos_pci,
2201                 {"PCI (Pre-emption Capability)", "gtpv2.bearer_qos_pci",
2202                 FT_BOOLEAN, 8, NULL, 0x40,
2203                 NULL, HFILL}
2204                 },
2205                 {&hf_gtpv2_bearer_qos_label_qci,
2206                 {"Label (QCI)", "gtpv2.bearer_qos_label_qci",
2207                 FT_UINT8, BASE_DEC, NULL, 0x0,
2208                 NULL, HFILL}
2209                 },
2210                 {&hf_gtpv2_bearer_qos_mbr_up,
2211                 {"Maximum Bit Rate For Uplink", "gtpv2.bearer_qos_mbr_up",
2212                 FT_UINT64, BASE_DEC, NULL, 0x0,
2213                 NULL, HFILL}
2214                 },
2215                 {&hf_gtpv2_bearer_qos_mbr_down,
2216                 {"Maximum Bit Rate For Downlink", "gtpv2.bearer_qos_mbr_down",
2217                 FT_UINT64, BASE_DEC, NULL, 0x0,
2218                 NULL, HFILL}
2219                 },
2220                 {&hf_gtpv2_bearer_qos_gbr_up,
2221                 {"Guaranteed Bit Rate For Uplink", "gtpv2.bearer_qos_gbr_up",
2222                 FT_UINT64, BASE_DEC, NULL, 0x0,
2223                 NULL, HFILL}
2224                 },
2225                 {&hf_gtpv2_bearer_qos_gbr_down,
2226                 {"Guaranteed Bit Rate For Downlink", "gtpv2.bearer_qos_gbr_down",
2227                 FT_UINT64, BASE_DEC, NULL, 0x0,
2228                 NULL, HFILL}
2229                 },
2230                 {&hf_gtpv2_flow_qos_label_qci,
2231                 {"Label (QCI)", "gtpv2.flow_qos_label_qci",
2232                 FT_UINT8, BASE_DEC, NULL, 0x0,
2233                 NULL, HFILL}
2234                 },
2235                 {&hf_gtpv2_flow_qos_mbr_up,
2236                 {"Maximum Bit Rate For Uplink", "gtpv2.flow_qos_mbr_up",
2237                 FT_UINT64, BASE_DEC, NULL, 0x0,
2238                 NULL, HFILL}
2239                 },
2240                 {&hf_gtpv2_flow_qos_mbr_down,
2241                 {"Maximum Bit Rate For Downlink", "gtpv2.flow_qos_mbr_down",
2242                 FT_UINT64, BASE_DEC, NULL, 0x0,
2243                 NULL, HFILL}
2244                 },
2245                 {&hf_gtpv2_flow_qos_gbr_up,
2246                 {"Guaranteed Bit Rate For Uplink", "gtpv2.flow_qos_gbr_up",
2247                 FT_UINT64, BASE_DEC, NULL, 0x0,
2248                 NULL, HFILL}
2249                 },
2250                 {&hf_gtpv2_flow_qos_gbr_down,
2251                 {"Guaranteed Bit Rate For Downlink", "gtpv2.flow_qos_gbr_down",
2252                 FT_UINT64, BASE_DEC, NULL, 0x0,
2253                 NULL, HFILL}
2254                 },
2255                 { &hf_gtpv2_rat_type,
2256                 {"RAT Type", "gtpv2.rat_type",
2257                 FT_UINT8, BASE_DEC, VALS(gtpv2_rat_type_vals), 0x0,
2258                 NULL, HFILL}
2259                 },
2260                 {&hf_gtpv2_b_tft_opcode,
2261                 {"Operation Code", "gtpv2.b_tft_opcode",
2262                 FT_UINT8, BASE_DEC, VALS(gtpv2_opcode_vals), 0xe0,
2263                 NULL , HFILL}
2264                 },
2265                 {&hf_gtpv2_b_tft_ebit,
2266                 {"Ebit", "gtpv2.b_tft_ebit",
2267                 FT_BOOLEAN, 8, NULL, 0x10,
2268                 NULL , HFILL}
2269                 },
2270                 {&hf_gtpv2_b_tft_number,
2271                 {"Number of Packet Filters", "gtpv2.b_tft_number",
2272                 FT_UINT8, BASE_DEC, NULL, 0x0f,
2273                 NULL , HFILL}
2274                 },
2275                 {&hf_gtpv2_b_tft_pf_id,
2276                 {"Packet Filter Identifier", "gtpv2.b_tft_pf_id",
2277                 FT_UINT8, BASE_DEC, NULL, 0x0f,
2278                 NULL , HFILL}
2279                 },
2280                 {&hf_gtpv2_b_tft_pf_direction,
2281                 {"Direction", "gtpv2.b_tft_pf_direction",
2282                 FT_UINT8, BASE_DEC, VALS(gtpv2_direction_vals), 0x30,
2283                 NULL , HFILL}
2284                 },
2285                 {&hf_gtpv2_b_tft_pf_eval,
2286                 {"Evaluation Precedence", "gtpv2.b_tft_pf_eval",
2287                 FT_UINT8, BASE_DEC, NULL, 0x0,
2288                 NULL , HFILL}
2289                 },
2290                 {&hf_gtpv2_b_tft_pf_length,
2291                 {"Length of Packet Filter", "gtpv2.b_tft_pf_length",
2292                 FT_UINT8, BASE_DEC, NULL, 0x0,
2293                 NULL , HFILL}
2294                 },
2295                 {&hf_gtpv2_b_tft_pf_comp_type,
2296                 {"Component Type", "gtpv2.b_tft_pf_comp_type",
2297                 FT_UINT8, BASE_DEC, VALS(gtpv2_comp_type_vals), 0x0,
2298                 NULL , HFILL}
2299                 },
2300                 { &hf_gtpv2_b_tft_pf_ipv4,
2301                 {"IPv4 address", "gtpv2.b_tft_pf_ipv4",
2302                 FT_IPv4, BASE_NONE, NULL, 0x0,
2303                 NULL, HFILL}
2304                 },
2305                 { &hf_gtpv2_b_tft_pf_ipv6,
2306                 {"IPv6 address", "gtpv2.b_tft_pf_ipv6",
2307                 FT_IPv6, BASE_NONE, NULL, 0x0,
2308                 NULL, HFILL}
2309                 },
2310                 {&hf_gtpv2_b_tft_pf_ipv4_mask,
2311                 {"IPV4 address mask field", "gtpv2.b_tft_pf_ipv4_mask",
2312                 FT_UINT32, BASE_DEC, NULL, 0x0,
2313                 NULL , HFILL}
2314                 },
2315                 {&hf_gtpv2_b_tft_pf_ipv6_mask,
2316                 {"IPV6 address mask field", "gtpv2.b_tft_pf_ipv6_mask",
2317                 FT_UINT32, BASE_DEC, NULL, 0x0,
2318                 NULL , HFILL}
2319                 },
2320                 {&hf_gtpv2_b_tft_pf_prot_id,
2321                 {"Protocol Identifier/Next Header type", "gtpv2.b_tft_pf_prot_id",
2322                 FT_UINT8, BASE_DEC, NULL, 0x0,
2323                 NULL , HFILL}
2324                 },
2325                 {&hf_gtpv2_b_tft_pf_single_local,
2326                 {"Single Local port type", "gtpv2.b_tft_pf_single_local",
2327                 FT_UINT16, BASE_DEC, NULL, 0x0,
2328                 NULL , HFILL}
2329                 },
2330                 {&hf_gtpv2_b_tft_pf_local_port_low,
2331                 {"Local port range low limit", "gtpv2.b_tft_pf_local_port_low",
2332                 FT_UINT16, BASE_DEC, NULL, 0x0,
2333                 NULL , HFILL}
2334                 },
2335                 {&hf_gtpv2_b_tft_pf_local_port_high,
2336                 {"Local port range high limit", "gtpv2.b_tft_pf_local_port_high",
2337                 FT_UINT16, BASE_DEC, NULL, 0x0,
2338                 NULL , HFILL}
2339                 },
2340                 {&hf_gtpv2_b_tft_pf_single_remote,
2341                 {"Single remote port type", "gtpv2.b_tft_pf_single_remote",
2342                 FT_UINT16, BASE_DEC, NULL, 0x0,
2343                 NULL , HFILL}
2344                 },
2345                 {&hf_gtpv2_b_tft_pf_remote_port_low,
2346                 {"Remote port range low limit", "gtpv2.b_tft_pf_remote_port_low",
2347                 FT_UINT16, BASE_DEC, NULL, 0x0,
2348                 NULL , HFILL}
2349                 },
2350                 {&hf_gtpv2_b_tft_pf_remote_port_high,
2351                 {"Remote port range high limit", "gtpv2.b_tft_pf_remote_port_high",
2352                 FT_UINT16, BASE_DEC, NULL, 0x0,
2353                 NULL , HFILL}
2354                 },
2355                 {&hf_gtpv2_b_tft_pf_security,
2356                 {"Security Parameter Index", "gtpv2.b_tft_pf_security",
2357                 FT_UINT8, BASE_DEC, NULL, 0x0,
2358                 NULL , HFILL}
2359                 },
2360                 {&hf_gtpv2_b_tft_pf_service_type,
2361                 {"Type of Service/Traffic Class type", "gtpv2.b_tft_pf_service_type",
2362                 FT_UINT8, BASE_DEC, NULL, 0x0,
2363                 NULL , HFILL}
2364                 },
2365                 {&hf_gtpv2_b_tft_pf_service_type_mask,
2366                 {"Type of Service/Traffic Class mask", "gtpv2.b_tft_pf_service_type_mask",
2367                 FT_UINT8, BASE_DEC, NULL, 0x0,
2368                 NULL , HFILL}
2369                 },
2370                 {&hf_gtpv2_b_tft_pf_flow_label,
2371                 {"Flow Label Type", "gtpv2.b_tft_pf_flow_label",
2372                 FT_UINT32, BASE_DEC, NULL, 0,
2373                 NULL, HFILL}
2374                 },
2375                 { &hf_gtpv2_uli_ecgi_flg,
2376                 {"ECGI Present Flag)", "gtpv2.uli_ecgi_flg",    
2377                 FT_BOOLEAN, 8, NULL, 0x10, 
2378                 NULL, HFILL}
2379                 },
2380                 { &hf_gtpv2_uli_tai_flg,
2381                 {"TAI Present Flag)", "gtpv2.uli_tai_flg",      
2382                 FT_BOOLEAN, 8, NULL, 0x08, 
2383                 NULL, HFILL}
2384                 },
2385                 { &hf_gtpv2_uli_rai_flg,
2386                 {"RAI Present Flag)", "gtpv2.uli_rai_flg",      
2387                 FT_BOOLEAN, 8, NULL, 0x04, 
2388                 NULL, HFILL}
2389                 },
2390                 { &hf_gtpv2_uli_sai_flg,
2391                 {"SAI Present Flag)", "gtpv2.uli_sai_flg",      
2392                 FT_BOOLEAN, 8, NULL, 0x02, 
2393                 NULL, HFILL}
2394                 },
2395                 { &hf_gtpv2_uli_cgi_flg,
2396                 {"CGI Present Flag)", "gtpv2.uli_cgi_flg",      
2397                 FT_BOOLEAN, 8, NULL, 0x01, 
2398                 NULL, HFILL}
2399                 },
2400                 { &hf_gtpv2_uli_cgi_lac,
2401                 {"Location Area Code", "gtpv2.uli_cgi_lac",
2402                 FT_UINT16, BASE_DEC, NULL, 0x0,
2403                 NULL, HFILL}
2404                 },
2405                 { &hf_gtpv2_uli_cgi_ci,
2406                 {"Cell Identity", "gtpv2.uli_cgi_ci",
2407                 FT_UINT16, BASE_DEC, NULL, 0x0,
2408                 NULL, HFILL}
2409                 },
2410                 { &hf_gtpv2_uli_sai_lac,
2411                 {"Location Area Code", "gtpv2.uli_sai_lac",
2412                 FT_UINT16, BASE_DEC, NULL, 0x0,
2413                 NULL, HFILL}
2414                 },
2415                 { &hf_gtpv2_uli_sai_sac,
2416                 {"Service Area Code", "gtpv2.uli_sai_sac",
2417                 FT_UINT16, BASE_DEC, NULL, 0x0,
2418                 NULL, HFILL}
2419                 },
2420                 { &hf_gtpv2_uli_rai_lac,
2421                 {"Location Area Code", "gtpv2.uli_rai_lac",
2422                 FT_UINT16, BASE_DEC, NULL, 0x0,
2423                 NULL, HFILL}
2424                 },
2425                 { &hf_gtpv2_uli_rai_rac,
2426                 {"Routing Area Code", "gtpv2.uli_rai_rac",
2427                 FT_UINT16, BASE_DEC, NULL, 0x0,
2428                 NULL, HFILL}
2429                 },
2430                 { &hf_gtpv2_uli_tai_tac,
2431                 {"Tracking Area Code", "gtpv2.uli_tai_tac",
2432                 FT_UINT16, BASE_DEC, NULL, 0x0,
2433                 NULL, HFILL}
2434                 },
2435                 {&hf_gtpv2_uli_ecgi_eci,
2436                 {"ECI (E-UTRAN Cell Identifier)", "gtpv2.uli_ecgi_eci",
2437                 FT_DOUBLE, BASE_DEC, NULL, 0,
2438                 NULL, HFILL}
2439                 },
2440                 {&hf_gtpv2_f_teid_v4,
2441                 {"V4 (True-IPV4 address field Exists,False-Doesn't Exist in F-TEID)", "gtpv2.f_teid_v4",
2442                 FT_BOOLEAN, 8, NULL, 0x80,
2443                 NULL, HFILL}
2444                 },
2445                 {&hf_gtpv2_f_teid_v6,
2446                 {"V6 (True-IPV6 address field Exists,False-Doesn't Exist in F-TEID)", "gtpv2.f_teid_v6",
2447                 FT_BOOLEAN, 8, NULL, 0x40,
2448                 NULL, HFILL}
2449                 },
2450                 {&hf_gtpv2_f_teid_interface_type,
2451                 {"Interface Type", "gtpv2.f_teid_interface_type",
2452                 FT_UINT8, BASE_DEC, VALS(gtpv2_f_teid_interface_type_vals), 0x1f,
2453                 NULL , HFILL}
2454                 },
2455                 {&hf_gtpv2_f_teid_gre_key,
2456                 {"TEID/GRE Key", "gtpv2.f_teid_gre_key",
2457                 FT_UINT32, BASE_DEC, NULL, 0x0,
2458                 NULL , HFILL}
2459                 },
2460                 { &hf_gtpv2_f_teid_ipv4,
2461                 {"F-TEID IPv4", "gtpv2.f_teid_ipv4",
2462                 FT_IPv4, BASE_NONE, NULL, 0x0,
2463                 NULL, HFILL}
2464                 },
2465                 { &hf_gtpv2_f_teid_ipv6,
2466                 {"F-TEID IPv6", "gtpv2.f_teid_ipv6",
2467                 FT_IPv6, BASE_NONE, NULL, 0x0,
2468                 NULL, HFILL}
2469                 },
2470                 {&hf_gtpv2_delay_value,
2471                 {"Delay Value (In integer multiples of 50 milliseconds or zero)", "gtpv2.delay_value",
2472                 FT_UINT8, BASE_DEC, NULL, 0x0,
2473                 NULL, HFILL}
2474                 },
2475                 {&hf_gtpv2_charging_id,
2476                 {"Charging id", "gtpv2.charging_id",
2477                 FT_UINT32, BASE_DEC, NULL, 0x0,
2478                 NULL, HFILL}
2479                 },
2480                 {&hf_gtpv2_charging_characteristic,
2481                 {"Charging Characteristic", "gtpv2.charging_characteristic",
2482                 FT_UINT16, BASE_DEC, NULL, 0x0,
2483                 NULL, HFILL}
2484                 },
2485                 {&hf_gtpv2_bearer_flag,
2486                 {"Bearer Flags(PPC(Prohibit Payload Compression) True-SGSN attempts to compress the payload, False-SGSN doesn't attempt to compress the payload)",
2487                 "gtpv2.bearer_flag",
2488                 FT_BOOLEAN, 8, NULL, 0x01,
2489                 NULL, HFILL}
2490                 },
2491                 {&hf_gtpv2_pti,
2492                 {"Procedure Transaction Id", "gtpv2.pti",
2493                 FT_UINT8, BASE_DEC, NULL, 0x0,
2494                 NULL, HFILL}
2495                 },
2496                 {&hf_gtpv2_ue_time_zone,
2497                 {"Time Zone","gtpv2.ue_time_zone",
2498                 FT_UINT8, BASE_DEC, NULL,0x0,
2499                 NULL, HFILL}
2500                 },
2501                 {&hf_gtpv2_ue_time_zone_dst,
2502                 {"Daylight Saving Time","gtpv2.ue_time_zone_dst",
2503                 FT_UINT8, BASE_DEC, VALS(gtpv2_ue_time_zone_dst_vals),0x03,
2504                 NULL, HFILL}
2505                 },
2506                 {&hf_gtpv2_apn_rest,
2507                 {"APN Restriction", "gtpv2.apn_rest",
2508                 FT_UINT8, BASE_DEC, NULL, 0x0,
2509                 NULL, HFILL}
2510                 },
2511                 {&hf_gtpv2_selec_mode,
2512                 {"Selection Mode","gtpv2.selec_mode",
2513                 FT_UINT8, BASE_DEC, VALS(gtpv2_selec_mode_vals),0x03,
2514                 NULL, HFILL}
2515                 },
2516                 {&hf_gtpv2_bearer_control_mode,
2517                 {"Bearer Control Mode","gtpv2.bearer_control_mode",
2518                 FT_UINT8, BASE_DEC, VALS(gtpv2_bearer_control_mode_vals),0x0,
2519                 NULL, HFILL}
2520                 },
2521                 { &hf_gtpv2_cng_rep_act,
2522                 {"Change Reporting Action", "gtpv2.cng_rep_act",
2523                 FT_UINT8, BASE_DEC, VALS(gtpv2_cng_rep_act_vals), 0x0,
2524                 NULL, HFILL}
2525                 },
2526                 { &hf_gtpv2_node_type,
2527                 {"Node Type", "gtpv2.node_type",
2528                 FT_UINT8, BASE_DEC, VALS(gtpv2_node_type_vals), 0x0,
2529                 NULL, HFILL}
2530                 },
2531
2532          };
2533
2534     static gint *ett_gtpv2_array[] = {
2535                 &ett_gtpv2,
2536                 &ett_gtpv2_flags,
2537                 &ett_gtpv2_ie,
2538     };
2539
2540         proto_gtpv2 = proto_register_protocol("GPRS Tunneling Protocol V2", "GTPv2", "gtpv2");
2541     proto_register_field_array(proto_gtpv2, hf_gtpv2, array_length(hf_gtpv2));
2542     proto_register_subtree_array(ett_gtpv2_array, array_length(ett_gtpv2_array));
2543
2544         register_dissector("gtpv2", dissect_gtpv2, proto_gtpv2);
2545 }
2546
2547 /* The registration hand-off routine */
2548 void
2549 proto_reg_handoff_gtpv2(void)
2550 {
2551
2552   
2553 }