Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / asn1 / q932 / packet-q932-template.c
blob54e1f0d9eaf19bfbb1f75fe67e514c70436d5447
1 /* packet-q932.c
2 * Routines for Q.932 packet dissection
3 * 2007 Tomas Kukosa
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/expert.h>
16 #include <epan/strutil.h>
17 #include <epan/asn1.h>
18 #include <epan/prefs.h>
19 #include <wsutil/array.h>
21 #include "packet-ber.h"
22 #include "packet-q932.h"
24 #define PNAME "Q.932"
25 #define PSNAME "Q932"
26 #define PFNAME "q932"
28 void proto_register_q932(void);
30 /* Initialize the protocol and registered fields */
31 static int proto_q932;
32 static int hf_q932_ie_type;
33 static int hf_q932_ie_len;
34 static int hf_q932_ie_data;
35 static int hf_q932_pp;
36 static int hf_q932_nd;
37 #include "packet-q932-hf.c"
39 /* Initialize the subtree pointers */
40 static int ett_q932;
41 static int ett_q932_ie;
42 #include "packet-q932-ett.c"
44 static expert_field ei_q932_dse_not_supported;
45 static expert_field ei_q932_acse_not_supported;
46 static expert_field ei_q932_unknown_component;
47 static expert_field ei_q932_asn1_encoded;
50 /* Preferences */
52 /* ROSE context */
53 static rose_ctx_t q932_rose_ctx;
55 dissector_table_t qsig_arg_local_dissector_table;
56 dissector_table_t qsig_res_local_dissector_table;
57 dissector_table_t qsig_err_local_dissector_table;
59 dissector_table_t etsi_arg_local_dissector_table;
60 dissector_table_t etsi_res_local_dissector_table;
61 dissector_table_t etsi_err_local_dissector_table;
63 #define FACILITY_QSIG 0
64 #define FACILITY_ETSI 1
65 static int g_facility_encoding = FACILITY_QSIG;
67 void proto_reg_handoff_q932(void);
69 static dissector_handle_t q932_ie_handle;
71 /* Subdissectors */
72 static dissector_handle_t q932_ros_handle;
74 #define Q932_IE_EXTENDED_FACILITY 0x0D
75 #define Q932_IE_FACILITY 0x1C
76 #define Q932_IE_NOTIFICATION_INDICATOR 0x27
77 #define Q932_IE_INFORMATION_REQUEST 0x32
78 #define Q932_IE_FEATURE_ACTIVATION 0x38
79 #define Q932_IE_FEATURE_INDICATION 0x39
80 #define Q932_IE_SERVICE_PROFILE_ID 0x3A
81 #define Q932_IE_ENDPOINT_IDENTIFIER 0x3B
82 static const value_string q932_str_ie_type[] = {
83 { Q932_IE_EXTENDED_FACILITY , "Extended facility" },
84 { Q932_IE_FACILITY , "Facility" },
85 { Q932_IE_NOTIFICATION_INDICATOR, "Notification indicator" },
86 { Q932_IE_INFORMATION_REQUEST, "Information request" },
87 { Q932_IE_FEATURE_ACTIVATION , "Feature activation" },
88 { Q932_IE_FEATURE_INDICATION , "Feature indication" },
89 { Q932_IE_SERVICE_PROFILE_ID , "Service profile identification" },
90 { Q932_IE_ENDPOINT_IDENTIFIER, "Endpoint identifier" },
91 { 0, NULL}
94 static const value_string str_pp[] = {
95 { 0x11 , "Remote Operations Protocol" },
96 { 0x12 , "CMIP Protocol" },
97 { 0x13 , "ACSE Protocol" },
98 { 0x1F , "Networking extensions" },
99 { 0, NULL}
102 static const value_string str_nd[] = {
103 { 0x00 , "User suspended" },
104 { 0x01 , "User resume" },
105 { 0x02 , "Bearer service change" },
106 { 0x04 , "Call completion delay" },
107 { 0x03 , "Discriminator for extension to ASN.1 encoded component" },
108 { 0x40 , "Discriminator for extension to ASN.1 encoded component for ISO" },
109 { 0x42 , "Conference established" },
110 { 0x43 , "Conference disconnected" },
111 { 0x44 , "Other party added" },
112 { 0x45 , "Isolated" },
113 { 0x46 , "Reattached" },
114 { 0x47 , "Other party isolated" },
115 { 0x48 , "Other party reattached" },
116 { 0x49 , "Other party split" },
117 { 0x4A , "Other party disconnected" },
118 { 0x4B , "Conference floating" },
119 { 0x4C , "Conference disconnected, pre-emption" },
120 { 0x4F , "Conference floating, served user pre-empted" },
121 { 0x60 , "Call is a waiting call" },
122 { 0x68 , "Diversion activated" },
123 { 0x69 , "call transferred, alerting" },
124 { 0x6A , "call transferred, answered" },
125 { 0x6E , "reverse charging (whole call)" },
126 { 0x6F , "reverse charging (for the rest of the call)" },
127 { 0x74 , "service profile update" },
128 { 0x79 , "Remote hold" },
129 { 0x7A , "Remote retrieval" },
130 { 0x7B , "Call is diverting" },
131 { 0, NULL}
134 #include "packet-q932-fn.c"
136 /*--- dissect_q932_facility_ie -------------------------------------------------------*/
137 static void
138 dissect_q932_facility_ie(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int length) {
139 int8_t appclass;
140 bool pc;
141 int32_t tag;
142 uint32_t len;
143 int hoffset, eoffset;
144 int ie_end;
145 tvbuff_t *next_tvb;
147 ie_end = offset + length;
148 proto_tree_add_item(tree, hf_q932_pp, tvb, offset, 1, ENC_BIG_ENDIAN);
149 offset++;
150 while (offset < ie_end) {
151 hoffset = offset;
152 offset = get_ber_identifier(tvb, offset, &appclass, &pc, &tag);
153 offset = get_ber_length(tvb, offset, &len, NULL);
154 eoffset = offset + len;
155 next_tvb = tvb_new_subset_length(tvb, hoffset, eoffset - hoffset);
156 switch (appclass) {
157 case BER_CLASS_CON:
158 switch (tag) {
159 case 10 : /* Network Facility Extension */
160 dissect_NetworkFacilityExtension_PDU(next_tvb, pinfo, tree, NULL);
161 break;
162 case 18 : /* Network Protocol Profile */
163 dissect_NetworkProtocolProfile_PDU(next_tvb, pinfo, tree, NULL);
164 break;
165 case 11 : /* Interpretation Component */
166 dissect_InterpretationComponent_PDU(next_tvb, pinfo, tree, NULL);
167 break;
168 /* ROSE APDU */
169 case 1 : /* invoke */
170 case 2 : /* returnResult */
171 case 3 : /* returnError */
172 case 4 : /* reject */
173 q932_rose_ctx.apdu_depth = 1;
174 call_dissector_with_data(q932_ros_handle, next_tvb, pinfo, tree, &q932_rose_ctx);
175 break;
176 /* DSE APDU */
177 case 12 : /* begin */
178 case 14 : /* end */
179 case 15 : /* continue */
180 case 17 : /* abort */
181 offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
182 offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
183 proto_tree_add_expert(tree, pinfo, &ei_q932_dse_not_supported, tvb, offset, len);
184 break;
185 default:
186 offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
187 offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
188 proto_tree_add_expert(tree, pinfo, &ei_q932_unknown_component, tvb, offset, len);
190 break;
191 case BER_CLASS_APP:
192 switch (tag) {
193 /* ACSE APDU */
194 case 0 : /* aarq */
195 case 1 : /* aare */
196 case 2 : /* rlrq */
197 case 3 : /* rlre */
198 case 4 : /* abrt */
199 offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
200 offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
201 proto_tree_add_expert(tree, pinfo, &ei_q932_acse_not_supported, tvb, offset, len);
202 break;
203 default:
204 offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
205 offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
206 proto_tree_add_expert(tree, pinfo, &ei_q932_unknown_component, tvb, offset, len);
208 break;
209 default:
210 offset = dissect_ber_identifier(pinfo, tree, tvb, hoffset, NULL, NULL, NULL);
211 offset = dissect_ber_length(pinfo, tree, tvb, offset, NULL, NULL);
212 proto_tree_add_expert(tree, pinfo, &ei_q932_unknown_component, tvb, offset, len);
214 offset = eoffset;
218 /*--- dissect_q932_ni_ie -------------------------------------------------------*/
219 static void
220 dissect_q932_ni_ie(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int length) {
221 int remain = length;
222 uint8_t octet = 0;
223 uint32_t value = 0;
224 proto_item* ti;
226 while ((remain > 0) && !(octet & 0x80)) {
227 octet = tvb_get_uint8(tvb, offset++);
228 remain--;
229 value <<= 7;
230 value |= octet & 0x7F;
232 ti = proto_tree_add_uint(tree, hf_q932_nd, tvb, offset - (length - remain), length - remain, value);
234 if (remain > 0) {
235 expert_add_info(pinfo, ti, &ei_q932_asn1_encoded);
239 /*--- dissect_q932_ie -------------------------------------------------------*/
240 static int
241 dissect_q932_ie(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
242 int offset;
243 proto_item *ti;
244 proto_tree *ie_tree;
245 uint8_t ie_type, ie_len;
247 offset = 0;
249 ti = proto_tree_add_item(tree, proto_q932, tvb, offset, -1, ENC_NA);
250 proto_item_set_hidden(ti);
252 ie_type = tvb_get_uint8(tvb, offset);
253 ie_len = tvb_get_uint8(tvb, offset + 1);
255 ie_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_q932_ie, NULL,
256 val_to_str(ie_type, VALS(q932_str_ie_type), "unknown (0x%02X)"));
258 proto_tree_add_item(ie_tree, hf_q932_ie_type, tvb, offset, 1, ENC_BIG_ENDIAN);
259 proto_tree_add_item(ie_tree, hf_q932_ie_len, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
260 offset += 2;
261 if (tvb_reported_length_remaining(tvb, offset) <= 0)
262 return offset;
263 switch (ie_type) {
264 case Q932_IE_FACILITY :
265 dissect_q932_facility_ie(tvb, offset, pinfo, ie_tree, ie_len);
266 break;
267 case Q932_IE_NOTIFICATION_INDICATOR :
268 dissect_q932_ni_ie(tvb, offset, pinfo, ie_tree, ie_len);
269 break;
270 default:
271 if (ie_len > 0) {
272 proto_tree_add_item(ie_tree, hf_q932_ie_data, tvb, offset, ie_len, ENC_NA);
275 return tvb_captured_length(tvb);
278 /*--- dissect_q932_apdu -----------------------------------------------------*/
279 static int
280 dissect_q932_apdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
281 return call_dissector(q932_ros_handle, tvb, pinfo, tree);
284 /*--- proto_register_q932 ---------------------------------------------------*/
285 void proto_register_q932(void) {
287 /* List of fields */
288 static hf_register_info hf[] = {
289 { &hf_q932_ie_type, { "Type", "q932.ie.type",
290 FT_UINT8, BASE_HEX, VALS(q932_str_ie_type), 0x0,
291 "Information Element Type", HFILL }},
292 { &hf_q932_ie_len, { "Length", "q932.ie.len",
293 FT_UINT8, BASE_DEC, NULL, 0x0,
294 "Information Element Length", HFILL }},
295 { &hf_q932_ie_data, { "Data", "q932.ie.data",
296 FT_BYTES, BASE_NONE, NULL, 0x0,
297 NULL, HFILL }},
298 { &hf_q932_pp, { "Protocol profile", "q932.pp",
299 FT_UINT8, BASE_HEX, VALS(str_pp), 0x1F,
300 NULL, HFILL }},
301 { &hf_q932_nd, { "Notification description", "q932.nd",
302 FT_UINT8, BASE_HEX, VALS(str_nd), 0x0,
303 NULL, HFILL }},
304 #include "packet-q932-hfarr.c"
307 /* List of subtrees */
308 static int *ett[] = {
309 &ett_q932,
310 &ett_q932_ie,
311 #include "packet-q932-ettarr.c"
314 static ei_register_info ei[] = {
315 { &ei_q932_dse_not_supported, { "q932.dse_not_supported", PI_UNDECODED, PI_WARN, "DSE APDU (not supported)", EXPFILL }},
316 { &ei_q932_acse_not_supported, { "q932.acse_not_supported", PI_UNDECODED, PI_WARN, "ACSE APDU (not supported)", EXPFILL }},
317 { &ei_q932_unknown_component, { "q932.unknown_component", PI_UNDECODED, PI_WARN, "Unknown Component", EXPFILL }},
318 { &ei_q932_asn1_encoded, { "q932.asn1_encoded", PI_UNDECODED, PI_WARN, "ASN.1 Encoded Data Structure(NOT IMPLEMENTED)", EXPFILL }},
321 module_t *q932_module;
322 expert_module_t* expert_q932;
324 static const enum_val_t facility_encoding[] = {
325 {"QSIG", "Dissect facility as QSIG", FACILITY_QSIG},
326 {"ETSI", "Dissect facility as ETSI", FACILITY_ETSI},
327 {NULL, NULL, -1}
330 /* Register protocol and dissector */
331 proto_q932 = proto_register_protocol(PNAME, PSNAME, PFNAME);
332 register_dissector("q932.apdu", dissect_q932_apdu, proto_q932);
333 q932_ie_handle = register_dissector("q932.ie", dissect_q932_ie, proto_q932);
335 /* Register fields and subtrees */
336 proto_register_field_array(proto_q932, hf, array_length(hf));
337 proto_register_subtree_array(ett, array_length(ett));
338 expert_q932 = expert_register_protocol(proto_q932);
339 expert_register_field_array(expert_q932, ei, array_length(ei));
341 rose_ctx_init(&q932_rose_ctx);
343 /* Register dissector tables */
344 q932_rose_ctx.arg_global_dissector_table = register_dissector_table("q932.ros.global.arg", "Q.932 Operation Argument (global opcode)", proto_q932, FT_STRING, STRING_CASE_SENSITIVE);
345 q932_rose_ctx.res_global_dissector_table = register_dissector_table("q932.ros.global.res", "Q.932 Operation Result (global opcode)", proto_q932, FT_STRING, STRING_CASE_SENSITIVE);
346 q932_rose_ctx.err_global_dissector_table = register_dissector_table("q932.ros.global.err", "Q.932 Error (global opcode)", proto_q932, FT_STRING, STRING_CASE_SENSITIVE);
348 qsig_arg_local_dissector_table = register_dissector_table("q932.ros.local.arg", "Q.932 Operation Argument (local opcode)", proto_q932, FT_UINT32, BASE_HEX);
349 qsig_res_local_dissector_table = register_dissector_table("q932.ros.local.res", "Q.932 Operation Result (local opcode)", proto_q932, FT_UINT32, BASE_HEX);
350 qsig_err_local_dissector_table = register_dissector_table("q932.ros.local.err", "Q.932 Error (local opcode)", proto_q932, FT_UINT32, BASE_HEX);
352 etsi_arg_local_dissector_table = register_dissector_table("q932.ros.etsi.local.arg", "Q.932 ETSI Operation Argument (local opcode)", proto_q932, FT_UINT32, BASE_HEX);
353 etsi_res_local_dissector_table = register_dissector_table("q932.ros.etsi.local.res", "Q.932 ETSI Operation Result (local opcode)", proto_q932, FT_UINT32, BASE_HEX);
354 etsi_err_local_dissector_table = register_dissector_table("q932.ros.etsi.local.err", "Q.932 ETSI Error (local opcode)", proto_q932, FT_UINT32, BASE_HEX);
356 q932_module = prefs_register_protocol(proto_q932, proto_reg_handoff_q932);
358 prefs_register_enum_preference(q932_module, "facility_encoding",
359 "Type of Facility encoding",
360 "Type of Facility encoding",
361 &g_facility_encoding, facility_encoding, false);
364 /*--- proto_reg_handoff_q932 ------------------------------------------------*/
365 void proto_reg_handoff_q932(void) {
366 static bool q931_prefs_initialized = false;
368 if (!q931_prefs_initialized) {
369 /* Facility */
370 dissector_add_uint("q931.ie", (0x00 << 8) | Q932_IE_FACILITY, q932_ie_handle);
371 /* Notification indicator */
372 dissector_add_uint("q931.ie", (0x00 << 8) | Q932_IE_NOTIFICATION_INDICATOR, q932_ie_handle);
373 q932_ros_handle = find_dissector_add_dependency("q932.ros", proto_q932);
375 q931_prefs_initialized = true;
378 if(g_facility_encoding == FACILITY_QSIG){
379 q932_rose_ctx.arg_local_dissector_table = qsig_arg_local_dissector_table;
380 q932_rose_ctx.res_local_dissector_table = qsig_res_local_dissector_table;
381 q932_rose_ctx.err_local_dissector_table = qsig_err_local_dissector_table;
382 }else{
383 q932_rose_ctx.arg_local_dissector_table = etsi_arg_local_dissector_table;
384 q932_rose_ctx.res_local_dissector_table = etsi_res_local_dissector_table;
385 q932_rose_ctx.err_local_dissector_table = etsi_err_local_dissector_table;
390 /*---------------------------------------------------------------------------*/