1 /* packet-gprscdr-template.c
2  * Copyright 2011 , Anders Broman <anders.broman [AT] ericsson.com>
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  * References: 3GPP TS 32.298 V16.7.0
10  */
11 
12 #include "config.h"
13 
14 #include <epan/packet.h>
15 #include <epan/expert.h>
16 #include <epan/asn1.h>
17 
18 #include "packet-ber.h"
19 #include "packet-gsm_map.h"
20 #include "packet-gsm_a_common.h"
21 #include "packet-e212.h"
22 #include "packet-gprscdr.h"
23 #include "packet-gtp.h"
24 #include "packet-gtpv2.h"
25 
26 #define PNAME  "GPRS CDR"
27 #define PSNAME "GPRSCDR"
28 #define PFNAME "gprscdr"
29 
30 void proto_register_gprscdr(void);
31 
32 /* Define the GPRS CDR proto */
33 static int proto_gprscdr = -1;
34 
35 #include "packet-gprscdr-hf.c"
36 
37 static int ett_gprscdr = -1;
38 static int ett_gprscdr_timestamp = -1;
39 static int ett_gprscdr_plmn_id = -1;
40 static int ett_gprscdr_pdp_pdn_type = -1;
41 static int ett_gprscdr_eps_qos_arp = -1;
42 static int ett_gprscdr_managementextension_information = -1;
43 static int ett_gprscdr_userlocationinformation = -1;
44 #include "packet-gprscdr-ett.c"
45 
46 static expert_field ei_gprscdr_not_dissected = EI_INIT;
47 static expert_field ei_gprscdr_choice_not_found = EI_INIT;
48 
49 /* Global variables */
50 static const char *obj_id = NULL;
51 
52 static const value_string gprscdr_daylight_saving_time_vals[] = {
53     {0, "No adjustment"},
54     {1, "+1 hour adjustment for Daylight Saving Time"},
55     {2, "+2 hours adjustment for Daylight Saving Time"},
56     {3, "Reserved"},
57     {0, NULL}
58 };
59 
60 /* 3GPP-RAT-Type
61 *  3GPP TS 29.061
62 */
63 static const value_string gprscdr_rat_type_vals[] = {
64     {0, "Reserved"},
65     {1, "UTRAN"},
66     {2, "GERAN"},
67     {3, "WLAN"},
68     {4, "GAN"},
69     {5, "HSPA Evolution"},
70     {6, "EUTRAN"},
71     {7, "Virtual"},
72     {8, "EUTRAN-NB-IoT"},
73     {9, "LTE-M"},
74     {10, "NR"},
75     /* 11-100 Spare for future use TS 29.061 */
76     {101, "IEEE 802.16e"},
77     {102, "3GPP2 eHRPD"},
78     {103, "3GPP2 HRPD"},
79     /* 104-255 Spare for future use TS 29.061 */
80     {0, NULL}
81 };
82 
83 static int
dissect_gprscdr_uli(tvbuff_t * tvb _U_,asn1_ctx_t * actx _U_,proto_tree * tree _U_,int type)84 dissect_gprscdr_uli(tvbuff_t *tvb _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int type) {
85   proto_tree *ext_tree_uli;
86   guint       length;
87 
88   length = tvb_reported_length(tvb);
89   ext_tree_uli = proto_tree_add_subtree(tree, tvb, 0, length, ett_gprscdr_userlocationinformation, NULL, "UserLocationInformation");
90 
91   switch (type) {
92   case 1:
93       /* For GGSN/EGGSN-CDR,
94        * this octet string is a 1:1 copy of the contents (i.e. starting with octet 4) of the
95        * User Location Information (ULI) information element specified in 29.060, ch7.7.51.
96        */
97       dissect_gtp_uli(tvb, 0, actx->pinfo, ext_tree_uli, NULL);
98       break;
99   case 2:
100       /* For SGW/PGW-CDR,
101        * this octet string is a 1:1 copy of the contents (i.e. starting with octet 5) of the
102        * User Location Information (ULI) information element specified in 29.274, ch8.21.
103        */
104       dissect_gtpv2_uli(tvb, actx->pinfo, ext_tree_uli, NULL, length, 0, 0, NULL);
105       break;
106   default:
107       proto_tree_add_expert(ext_tree_uli, actx->pinfo, &ei_gprscdr_not_dissected, tvb, 0, length);
108       break;
109   }
110 
111   return length;
112 }
113 
114 #include "packet-gprscdr-fn.c"
115 
116 
117 
118 /* Register all the bits needed with the filtering engine */
119 void
proto_register_gprscdr(void)120 proto_register_gprscdr(void)
121 {
122   /* List of fields */
123   static hf_register_info hf[] = {
124 #include "packet-gprscdr-hfarr.c"
125   };
126 
127   /* List of subtrees */
128   static gint *ett[] = {
129     &ett_gprscdr,
130     &ett_gprscdr_timestamp,
131     &ett_gprscdr_plmn_id,
132     &ett_gprscdr_pdp_pdn_type,
133     &ett_gprscdr_eps_qos_arp,
134     &ett_gprscdr_managementextension_information,
135     &ett_gprscdr_userlocationinformation,
136 #include "packet-gprscdr-ettarr.c"
137         };
138 
139   static ei_register_info ei[] = {
140     { &ei_gprscdr_not_dissected, { "gprscdr.not_dissected", PI_UNDECODED, PI_WARN, "Not dissected", EXPFILL }},
141     { &ei_gprscdr_choice_not_found, { "gprscdr.error.choice_not_found", PI_MALFORMED, PI_WARN, "GPRS CDR Error: This choice field(Record type) was not found", EXPFILL }},
142   };
143 
144   expert_module_t* expert_gprscdr;
145 
146   proto_gprscdr = proto_register_protocol(PNAME, PSNAME, PFNAME);
147 
148   proto_register_field_array(proto_gprscdr, hf, array_length(hf));
149   proto_register_subtree_array(ett, array_length(ett));
150   expert_gprscdr = expert_register_protocol(proto_gprscdr);
151   expert_register_field_array(expert_gprscdr, ei, array_length(ei));
152 }
153 
154 /* The registration hand-off routine */
155 
156 /*
157  * Editor modelines
158  *
159  * Local Variables:
160  * c-basic-offset: 2
161  * tab-width: 8
162  * indent-tabs-mode: nil
163  * End:
164  *
165  * ex: set shiftwidth=2 tabstop=8 expandtab:
166  * :indentSize=2:tabSize=8:noTabs=true:
167  */
168