Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-xcsl.c
blob0704110752ae014550d2385323da3657f45b3a3c
1 /* packet-xcsl.c
3 * Routines for the Xcsl dissection (Call Specification Language)
5 * Copyright 2008, Dick Gooris (gooris@alcatel-lucent.com)
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <stdlib.h>
17 #include <epan/packet.h>
19 #include <wsutil/strtoi.h>
21 /* string array size */
22 #define MAXLEN 4096
24 void proto_register_xcsl(void);
25 void proto_reg_handoff_xcsl(void);
27 static int proto_xcsl;
29 static int hf_xcsl_command;
30 static int hf_xcsl_information;
31 static int hf_xcsl_parameter;
32 static int hf_xcsl_protocol_version;
33 static int hf_xcsl_result;
34 static int hf_xcsl_transaction_id;
36 /* Initialize the subtree pointers */
37 static int ett_xcsl;
39 /* Xcsl result codes */
40 #define XCSL_SUCCESS 0
41 #define XCSL_UNKNOWN 1
42 #define XCSL_USRUNKN 2
43 #define XCSL_ERROR 3
44 #define XCSL_BUSY 4
45 #define XCSL_UNDEFINED 5
46 #define XCSL_MORE 6
47 #define XCSL_MAINT 7
48 #define XCSL_PROTSEQERR 8
49 #define XCSL_NONE 9
51 /* Result code meanings. */
52 static const value_string xcsl_action_vals[] = {
53 { XCSL_SUCCESS, "Success" },
54 { XCSL_UNKNOWN, "Unknown" },
55 { XCSL_USRUNKN, "User unknown" },
56 { XCSL_ERROR, "Error" },
57 { XCSL_BUSY, "Busy" },
58 { XCSL_UNDEFINED, "Undefined" },
59 { XCSL_MORE, "More" },
60 { XCSL_MAINT, "Maintenance" },
61 { XCSL_PROTSEQERR, "Protocol Sequence Error" },
62 { 0, NULL }
65 /* patterns used for tvb_ws_mempbrk_pattern_uint8 */
66 static ws_mempbrk_pattern pbrk_param_end;
68 /* Dissector for xcsl */
69 static void dissect_xcsl_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
71 unsigned offset = 0;
72 int length_remaining;
73 uint8_t idx;
74 bool request;
75 uint8_t par;
76 uint8_t *str;
77 uint8_t result;
78 const char *code;
79 unsigned len;
80 int next_offset;
81 proto_tree *xcsl_tree = NULL;
83 /* color support */
84 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Xcsl");
85 col_clear(pinfo->cinfo, COL_INFO);
87 /* Create display tree for the xcsl protocol */
88 if (tree) {
89 proto_item *xcsl_item;
90 xcsl_item = proto_tree_add_item(tree, proto_xcsl, tvb, offset, -1, ENC_NA);
91 xcsl_tree = proto_item_add_subtree(xcsl_item, ett_xcsl);
94 /* reset idx */
95 idx = 0;
97 /* reset the parameter count */
98 par = 0;
100 /* switch whether it concerns a command or an answer */
101 request = false;
103 while ((length_remaining = tvb_reported_length_remaining(tvb, offset)) > 0) {
105 /* get next item */
106 next_offset = tvb_ws_mempbrk_pattern_uint8(tvb, offset, length_remaining, &pbrk_param_end, NULL);
107 if (next_offset == -1) {
108 len = length_remaining;
109 next_offset = offset + len;
110 } else {
111 len = next_offset - offset;
114 /* do not add to the tree when the string is of zero length */
115 if ( len == 0 ) {
116 offset = next_offset + 1;
117 continue;
120 str = tvb_get_string_enc(pinfo->pool, tvb, offset, len, ENC_ASCII);
122 /* Xcsl (Call Specification Language) protocol in brief :
124 * Request :
126 * <xcsl-version>;<transaction-id>;<command>;[parameter1;parameter2;parameter3;....]
128 * Reply :
130 * <xcsl-version>;transaction-id;<result>;[answer data;answer data];...
132 * If result is one or more digits, this is determined as a Reply.
134 * Example :
136 * --> xcsl-1.0;1000;offhook;+31356871234
137 * <-- xcsl-1.0;1000;0 <- success
139 * --> xcsl-1.0;1001;dial;+31356871234;+31356875678
140 * <-- xcsl-1.0;1001;0 <- success
143 * index : 0 1 2 3 4
145 * Index 2 represents the return code (see the xcsl_action_vals[] definitions)
149 /* One by one go through each item ';' separated */
150 switch (idx) {
152 /* This is the protocol item */
153 case 0:
154 proto_tree_add_item(xcsl_tree, hf_xcsl_protocol_version, tvb, offset, len, ENC_ASCII);
155 break;
157 /* This should be the transaction ID, if non-digit, it is treated as info */
158 case 1:
159 if ( g_ascii_isdigit(str[0]) ) {
160 proto_tree_add_item(xcsl_tree, hf_xcsl_transaction_id, tvb, offset, len, ENC_ASCII);
161 } else {
162 proto_tree_add_item(xcsl_tree, hf_xcsl_information, tvb, offset, len, ENC_ASCII);
164 col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",str);
165 break;
167 /* Starting with non-digit -> Command, if it starts with a digit -> reply */
168 case 2:
169 if ( g_ascii_isdigit(str[0]) ) {
170 proto_item *xcsl_item;
172 request = false;
173 result = XCSL_UNDEFINED;
174 ws_strtou8(str, NULL, &result);
175 if ( result >= XCSL_NONE ) {
176 result = XCSL_UNDEFINED;
178 code = val_to_str(result, xcsl_action_vals, "Unknown: %d");
180 /* Print result code and description */
181 xcsl_item = proto_tree_add_item(xcsl_tree, hf_xcsl_result, tvb, offset, len, ENC_ASCII);
182 proto_item_append_text(xcsl_item, " (%s)", code);
184 if (result != 0)
185 col_append_fstr(pinfo->cinfo, COL_INFO, "[%s] ", code);
187 } else {
189 request = true;
190 proto_tree_add_item(xcsl_tree, hf_xcsl_command, tvb, offset, len, ENC_ASCII);
192 col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", str);
195 break;
197 /* This is a command parameter */
198 default:
199 proto_tree_add_item(xcsl_tree, hf_xcsl_parameter, tvb, offset, len, ENC_ASCII);
201 if ( request == true ) {
202 col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
203 } else {
204 if (par == 0) {
205 col_append_fstr(pinfo->cinfo, COL_INFO, "reply: %s ",str);
206 } else {
207 col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
211 /* increment the parameter count */
212 par++;
214 break;
217 offset = next_offset + 1;
218 idx++;
223 return;
227 /* This function determines whether the first 4 octets equals to xcsl and the fifth is an ; or - */
228 static bool dissect_xcsl_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
230 uint8_t *protocol;
232 if (tvb_captured_length (tvb) >= 5) {
233 protocol = tvb_get_string_enc(pinfo->pool, tvb, 0, 5, ENC_ASCII);
235 if (strncmp(protocol,"xcsl",4) == 0 && (protocol[4] == ';' || protocol[4] == '-')) {
237 /* Disssect it as being an xcsl message */
238 dissect_xcsl_tcp(tvb, pinfo, tree);
240 return true;
244 return false;
248 /* register the various xcsl protocol filters */
249 void proto_register_xcsl(void) {
250 static hf_register_info hf[] = {
251 { &hf_xcsl_protocol_version,
252 { "Protocol Version", "xcsl.protocol_version",
253 FT_STRING, BASE_NONE, NULL, 0x0,
254 NULL, HFILL }
256 { &hf_xcsl_transaction_id,
257 { "Transaction ID", "xcsl.transaction_id",
258 FT_STRING, BASE_NONE, NULL, 0x0,
259 NULL, HFILL }
261 { &hf_xcsl_command,
262 { "Command", "xcsl.command",
263 FT_STRING, BASE_NONE, NULL, 0x0,
264 NULL, HFILL }
266 { &hf_xcsl_result,
267 { "Result", "xcsl.result",
268 FT_STRING, BASE_NONE, NULL, 0x0,
269 NULL, HFILL }
271 { &hf_xcsl_information,
272 { "Information", "xcsl.information",
273 FT_STRING, BASE_NONE, NULL, 0x0,
274 NULL, HFILL }
276 { &hf_xcsl_parameter,
277 { "Parameter", "xcsl.parameter",
278 FT_STRING, BASE_NONE, NULL, 0x0,
279 NULL, HFILL }
283 /* Setup protocol subtree array */
284 static int *ett[] = {
285 &ett_xcsl
288 /* Register the protocol name and description */
289 proto_xcsl = proto_register_protocol("Call Specification Language (Xcsl)", "XCSL", "xcsl");
290 proto_register_field_array(proto_xcsl, hf, array_length(hf));
291 proto_register_subtree_array(ett, array_length(ett));
293 /* compile patterns */
294 ws_mempbrk_compile(&pbrk_param_end, ";\r\n");
297 /* In case it concerns TCP, try to match on the xcsl header */
298 void proto_reg_handoff_xcsl(void) {
299 heur_dissector_add("tcp", dissect_xcsl_tcp_heur, "XCSL over TCP", "xcsl_tcp", proto_xcsl, HEURISTIC_ENABLE);
303 * Editor modelines - https://www.wireshark.org/tools/modelines.html
305 * Local variables:
306 * c-basic-offset: 4
307 * tab-width: 8
308 * indent-tabs-mode: nil
309 * End:
311 * vi: set shiftwidth=4 tabstop=8 expandtab:
312 * :indentSize=4:tabSize=8:noTabs=true: