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
17 #include <epan/packet.h>
19 #include <wsutil/strtoi.h>
21 /* string array size */
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 */
39 /* Xcsl result codes */
40 #define XCSL_SUCCESS 0
41 #define XCSL_UNKNOWN 1
42 #define XCSL_USRUNKN 2
45 #define XCSL_UNDEFINED 5
48 #define XCSL_PROTSEQERR 8
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" },
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
) {
81 proto_tree
*xcsl_tree
= NULL
;
84 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "Xcsl");
85 col_clear(pinfo
->cinfo
, COL_INFO
);
87 /* Create display tree for the xcsl protocol */
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
);
97 /* reset the parameter count */
100 /* switch whether it concerns a command or an answer */
103 while ((length_remaining
= tvb_reported_length_remaining(tvb
, offset
)) > 0) {
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
;
111 len
= next_offset
- offset
;
114 /* do not add to the tree when the string is of zero length */
116 offset
= next_offset
+ 1;
120 str
= tvb_get_string_enc(pinfo
->pool
, tvb
, offset
, len
, ENC_ASCII
);
122 /* Xcsl (Call Specification Language) protocol in brief :
126 * <xcsl-version>;<transaction-id>;<command>;[parameter1;parameter2;parameter3;....]
130 * <xcsl-version>;transaction-id;<result>;[answer data;answer data];...
132 * If result is one or more digits, this is determined as a Reply.
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
145 * Index 2 represents the return code (see the xcsl_action_vals[] definitions)
149 /* One by one go through each item ';' separated */
152 /* This is the protocol item */
154 proto_tree_add_item(xcsl_tree
, hf_xcsl_protocol_version
, tvb
, offset
, len
, ENC_ASCII
);
157 /* This should be the transaction ID, if non-digit, it is treated as info */
159 if ( g_ascii_isdigit(str
[0]) ) {
160 proto_tree_add_item(xcsl_tree
, hf_xcsl_transaction_id
, tvb
, offset
, len
, ENC_ASCII
);
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
);
167 /* Starting with non-digit -> Command, if it starts with a digit -> reply */
169 if ( g_ascii_isdigit(str
[0]) ) {
170 proto_item
*xcsl_item
;
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
);
185 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "[%s] ", code
);
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
);
197 /* This is a command parameter */
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
);
205 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "reply: %s ",str
);
207 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ": %s ",str
);
211 /* increment the parameter count */
217 offset
= next_offset
+ 1;
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_
) {
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
);
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,
256 { &hf_xcsl_transaction_id
,
257 { "Transaction ID", "xcsl.transaction_id",
258 FT_STRING
, BASE_NONE
, NULL
, 0x0,
262 { "Command", "xcsl.command",
263 FT_STRING
, BASE_NONE
, NULL
, 0x0,
267 { "Result", "xcsl.result",
268 FT_STRING
, BASE_NONE
, NULL
, 0x0,
271 { &hf_xcsl_information
,
272 { "Information", "xcsl.information",
273 FT_STRING
, BASE_NONE
, NULL
, 0x0,
276 { &hf_xcsl_parameter
,
277 { "Parameter", "xcsl.parameter",
278 FT_STRING
, BASE_NONE
, NULL
, 0x0,
283 /* Setup protocol subtree array */
284 static int *ett
[] = {
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
308 * indent-tabs-mode: nil
311 * vi: set shiftwidth=4 tabstop=8 expandtab:
312 * :indentSize=4:tabSize=8:noTabs=true: