1 /* packet-ain-template.c
2 * Routines for AIN
3 * Copyright 2018, Anders Broman <anders.broman@ericsson.com>
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 *
11 * Ref
12 * GR-1299-CORE
13 */
14 
15 #include "config.h"
16 
17 #include <epan/packet.h>
18 #include <epan/oids.h>
19 #include <epan/asn1.h>
20 #include <epan/expert.h>
21 
22 #include "packet-ber.h"
23 #include "packet-ansi_tcap.h"
24 
25 #if defined(__GNUC__)
26 /*
27  * This is meant to handle dissect_ain_ROS' defined but not used.
28  *
29  * DIAG_OFF doesn't work with llvm-gcc, for some unknown reason, so
30  * we just use the pragma directly.
31  */
32 #pragma GCC diagnostic ignored "-Wunused-function"
33 #endif
34 
35 #define PNAME  "Advanced Intelligent Network"
36 #define PSNAME "AIN"
37 #define PFNAME "ain"
38 
39 void proto_register_ain(void);
40 void proto_reg_handoff_ain(void);
41 
42 
43 /* Initialize the protocol and registered fields */
44 static int proto_ain = -1;
45 
46 static dissector_handle_t   ain_handle;
47 
48 /* include constants */
49 #include "packet-ain-val.h"
50 
51 static int hf_ain_ext_type_oid = -1;
52 static int hf_ain_odd_even_indicator = -1;
53 static int hf_ain_nature_of_address = -1;
54 static int hf_ain_numbering_plan = -1;
55 static int hf_ain_bcd_digits = -1;
56 static int hf_ain_carrier_selection = -1;
57 static int hf_ain_nature_of_carrier = -1;
58 static int hf_ain_nr_digits = -1;
59 static int hf_ain_carrier_bcd_digits = -1;
60 static int hf_ain_amaslpid = -1;
61 
62 #include "packet-ain-hf.c"
63 
64 /* Initialize the subtree pointers */
65 static int ett_ain = -1;
66 static int ett_ain_digits = -1;
67 static int ett_ain_carrierformat = -1;
68 static int ett_ain_amaslpid = -1;
69 
70 #include "packet-ain-ett.c"
71 
72 static expert_field ei_ain_unknown_invokeData = EI_INIT;
73 static expert_field ei_ain_unknown_returnResultData = EI_INIT;
74 static expert_field ei_ain_unknown_returnErrorData = EI_INIT;
75 
76 /* Global variables */
77 static guint32 opcode = 0;
78 static guint32 errorCode = 0;
79 //static const char *obj_id = NULL;
80 
81 static int ain_opcode_type;
82 #define AIN_OPCODE_INVOKE        1
83 #define AIN_OPCODE_RETURN_RESULT 2
84 #define AIN_OPCODE_RETURN_ERROR  3
85 #define AIN_OPCODE_REJECT        4
86 
87 /* Forvard declarations */
88 static int dissect_invokeData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_);
89 static int dissect_returnResultData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_);
90 static int dissect_returnErrorData(proto_tree *tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx);
91 
92 static const value_string ain_np_vals[] = {
93     {   0, "Unknown or not applicable"},
94     {   1, "ISDN Numbering Plan (ITU Rec. E.164)"},
95     {   2, "Telephony Numbering (ITU-T Rec. E.164,E.163)"},
96     {   3, "Data Numbering (ITU-T Rec. X.121)"},
97     {   4, "Telex Numbering (ITU-T Rec. F.69)"},
98     {   5, "Maritime Mobile Numbering"},
99     {   6, "Land Mobile Numbering (ITU-T Rec. E.212)"},
100     {   7, "Private Numbering Plan"},
101     {   0, NULL }
102 };
103 
104 static const value_string ain_carrier_selection_vals[] = {
105     {   0, "No indication"},
106     {   1, "Selected carrier identification code presubscribed and not input by calling party"},
107     {   2, "Selected carrier identification code presubscribed and input by calling party"},
108     {   3, "Selected carrier identification code presubscribed, no indication of whether input by calling party"},
109     {   4, "Selected carrier identification code not presubscribed and input by calling party"},
110     {   0, NULL }
111 };
112 
113 static const value_string ain_nature_of_carrier_vals[] = {
114     {   0, "No NOC Provided"},
115     {   1, "local"},
116     {   2, "intraLATA toll"},
117     {   3, "interLATA"},
118     {   4, "local, intraLATA toll and interLATA"},
119     {   5, "local and intraLATA toll"},
120     {   6, "intraLATA toll and interLATA"},
121     {   0, NULL }
122 };
123 
124 #include "packet-ain-table.c"
125 
126 #include "packet-ain-fn.c"
127 
128 #include "packet-ain-table2.c"
129 
130 
131 static int
dissect_ain(tvbuff_t * tvb,packet_info * pinfo,proto_tree * parent_tree,void * data _U_)132 dissect_ain(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data _U_)
133 {
134     proto_item *ain_item;
135     proto_tree *ain_tree = NULL;
136     struct ansi_tcap_private_t *p_private_tcap = (struct ansi_tcap_private_t *)data;
137     asn1_ctx_t asn1_ctx;
138     asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
139 
140     /* The TCAP dissector should have provided data but didn't so reject it. */
141     if (data == NULL)
142         return 0;
143     /*
144     * Make entry in the Protocol column on summary display
145     */
146     col_set_str(pinfo->cinfo, COL_PROTOCOL, "AIN");
147 
148     /*
149     * create the AIN protocol tree
150     */
151     ain_item = proto_tree_add_item(parent_tree, proto_ain, tvb, 0, -1, ENC_NA);
152     ain_tree = proto_item_add_subtree(ain_item, ett_ain);
153 
154     switch (p_private_tcap->d.pdu) {
155         /*
156         1 : invoke,
157         2 : returnResult,
158         3 : returnError,
159         4 : reject
160         */
161     case 1:
162         opcode = p_private_tcap->d.OperationCode_private;
163         /*ansi_map_is_invoke = TRUE;*/
164         col_add_fstr(pinfo->cinfo, COL_INFO, "%s Invoke ", val_to_str(opcode, ain_opr_code_strings, "Unknown AIN PDU (%u)"));
165         proto_item_append_text(p_private_tcap->d.OperationCode_item, " %s", val_to_str(opcode, ain_opr_code_strings, "Unknown AIN PDU (%u)"));
166         dissect_invokeData(ain_tree, tvb, 0, &asn1_ctx);
167         /*update_saved_invokedata(pinfo, p_private_tcap);*/
168         break;
169     //case 2:
170     //    opcode = find_saved_invokedata(&asn1_ctx, p_private_tcap);
171     //    col_add_fstr(pinfo->cinfo, COL_INFO, "%s ReturnResult ", val_to_str_ext(opcode, &ansi_map_opr_code_strings_ext, "Unknown ANSI-MAP PDU (%u)"));
172     //    proto_item_append_text(p_private_tcap->d.OperationCode_item, " %s", val_to_str_ext(opcode, &ansi_map_opr_code_strings_ext, "Unknown ANSI-MAP PDU (%u)"));
173     //    dissect_returnData(ain_tree, tvb, 0, &asn1_ctx);
174     //    break;
175     case 3:
176         col_add_fstr(pinfo->cinfo, COL_INFO, "%s ReturnError ", val_to_str(opcode, ain_opr_code_strings, "Unknown AIN PDU (%u)"));
177         break;
178     case 4:
179         col_add_fstr(pinfo->cinfo, COL_INFO, "%s Reject ", val_to_str(opcode, ain_opr_code_strings, "Unknown AIN PDU (%u)"));
180         break;
181     default:
182         /* Must be Invoke ReturnResult ReturnError or Reject */
183         DISSECTOR_ASSERT_NOT_REACHED();
184         break;
185     }
186 
187     return tvb_captured_length(tvb);
188 }
189 
proto_reg_handoff_ain(void)190 void proto_reg_handoff_ain(void) {
191 
192     /*static gboolean ain_prefs_initialized = FALSE;*/
193     /*static range_t *ssn_range;*/
194 
195 }
196 
197 
proto_register_ain(void)198 void proto_register_ain(void) {
199     /* List of fields */
200 
201     static hf_register_info hf[] = {
202 
203 
204     { &hf_ain_ext_type_oid,
205     { "AssignmentAuthority", "ain.ext_type_oid",
206     FT_STRING, BASE_NONE, NULL, 0,
207     "Type of ExtensionParameter", HFILL } },
208     { &hf_ain_odd_even_indicator,
209     { "Odd/even indicator",  "ain.odd_even_indicator",
210     FT_BOOLEAN, 8, TFS(&tfs_odd_even), 0x80,
211     NULL, HFILL } },
212     { &hf_ain_nature_of_address,
213     { "Nature of address",  "ain.nature_of_address",
214     FT_UINT8, BASE_DEC, NULL, 0x7f,
215     NULL, HFILL } },
216     { &hf_ain_numbering_plan,
217     { "Numbering plan",  "ain.numbering_plan",
218     FT_UINT8, BASE_DEC, VALS(ain_np_vals), 0x70,
219     NULL, HFILL } },
220     { &hf_ain_bcd_digits,
221     { "BCD digits", "ain.bcd_digits",
222     FT_STRING, BASE_NONE, NULL, 0,
223     NULL, HFILL } },
224     { &hf_ain_carrier_selection,
225     { "Carrier Selection",  "ain.carrier_selection",
226     FT_UINT8, BASE_DEC, VALS(ain_carrier_selection_vals), 0x0,
227     NULL, HFILL } },
228     { &hf_ain_nature_of_carrier,
229     { "Nature of Carrier",  "ain.nature_of_carrier",
230     FT_UINT8, BASE_DEC, VALS(ain_nature_of_carrier_vals), 0xf0,
231     NULL, HFILL } },
232     { &hf_ain_nr_digits,
233     { "Number of Digits",  "ain.nature_of_carrier",
234     FT_UINT8, BASE_DEC, NULL, 0x0f,
235     NULL, HFILL } },
236     { &hf_ain_carrier_bcd_digits,
237     { "Carrier digits", "ain.carrier_bcd_digits",
238     FT_STRING, BASE_NONE, NULL, 0,
239     NULL, HFILL } },
240     { &hf_ain_amaslpid,
241     { "AMAslpID", "ain.amaslpid",
242     FT_STRING, BASE_NONE, NULL, 0,
243     NULL, HFILL } },
244 
245 #include "packet-ain-hfarr.c"
246     };
247 
248     /* List of subtrees */
249     static gint *ett[] = {
250         &ett_ain,
251         &ett_ain_digits,
252         &ett_ain_carrierformat,
253         &ett_ain_amaslpid,
254 #include "packet-ain-ettarr.c"
255     };
256 
257     static ei_register_info ei[] = {
258         { &ei_ain_unknown_invokeData,{ "ain.unknown.invokeData", PI_MALFORMED, PI_WARN, "Unknown invokeData", EXPFILL } },
259         { &ei_ain_unknown_returnResultData,{ "ain.unknown.returnResultData", PI_MALFORMED, PI_WARN, "Unknown returnResultData", EXPFILL } },
260         { &ei_ain_unknown_returnErrorData,{ "ain.unknown.returnErrorData", PI_MALFORMED, PI_WARN, "Unknown returnResultData", EXPFILL } },
261     };
262 
263     expert_module_t* expert_ain;
264 
265     /* Register protocol */
266     proto_ain = proto_register_protocol(PNAME, PSNAME, PFNAME);
267     ain_handle = register_dissector("ain", dissect_ain, proto_ain);
268     /* Register fields and subtrees */
269     proto_register_field_array(proto_ain, hf, array_length(hf));
270     proto_register_subtree_array(ett, array_length(ett));
271     expert_ain = expert_register_protocol(proto_ain);
272     expert_register_field_array(expert_ain, ei, array_length(ei));
273 
274 }
275 
276 /*
277 * Editor modelines
278 *
279 * Local Variables:
280 * c-basic-offset: 2
281 * tab-width: 8
282 * indent-tabs-mode: nil
283 * End:
284 *
285 * ex: set shiftwidth=2 tabstop=8 expandtab:
286 * :indentSize=2:tabSize=8:noTabs=true:
287 */
288 
289 
290 
291 
292