1 /* packet-aastra-aasp.c
2 * Routines for AASP (Aastra Signalling Protocol) packet dissection.
3 * Copyright 2011, Marek Tews <marek.tews@gmail.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
12 /*
13 * AASP over SIP
14 * Content-Type: message/x-aasp-signalling
15 */
16
17 #include "config.h"
18
19 #include <epan/packet.h>
20
21 /* commands id */
22 #define BEGIN_BLOCK_DATA 0x80
23 #define WINDOW 0x81
24 #define TITLE 0x83
25 #define ROW 0x84
26 #define MENU_ITEM 0x85
27 #define CONTEXT_INFO 0x86
28 #define BUTTON_PRESSED 0x87
29 #define COLUMN 0x88
30 #define SET_TEXT 0x89
31 #define DATE_TIME_INFO 0xA4
32 #define INCOMING_CALLER 0xA5
33 #define DO_COMMAND 0xA9
34 #define PUSH_BTN_C 0xC8
35 #define PUSH_BTN_TASK 0xC9
36 #define PUSH_BTN_PLUS 0xCA
37 #define PUSH_BTN_MINUS 0xCB
38 #define PUSH_BTN_MIC 0xCC
39 #define PUSH_BTN_SPK 0xCD
40 #define PUSH_BTN_TBOOK 0xCE
41 #define PUSH_BTN_DBL_ARROW 0xCF
42 #define PUSH_BTN_ON_HOOK 0xD0
43 #define PUSH_BTN_OFF_HOOK 0xD1
44 #define PUSH_BTN_UP 0xD2
45 #define PUSH_BTN_DOWN 0xD3
46 #define PUSH_BTN_LEFT 0xD4
47 #define PUSH_BTN_RIGHT 0xD5
48 #define END_BLOCK_DATA 0xFE
49
50
51 /* Forward declarations */
52 void proto_register_aasp(void);
53 void proto_reg_handoff_aasp(void);
54
55 /* Initialize the protocol and registered fields */
56 static gint proto_aasp = -1;
57
58 static gint hf_a_data = -1;
59 static gint hf_a_cmd = -1;
60 static gint hf_a_id = -1;
61 static gint hf_a_length = -1;
62 static gint hf_a_text = -1;
63 static gint hf_a_line = -1;
64 static gint hf_a_cdpn = -1;
65 static gint hf_a_button_id = -1;
66
67 static gint hf_a_attr = -1;
68
69 static gint hf_a_item = -1;
70 static gint hf_a_hour = -1;
71 static gint hf_a_minute = -1;
72 static gint hf_a_day = -1;
73 static gint hf_a_month = -1;
74 static gint hf_a_weekofyear = -1;
75 static gint hf_a_weekday = -1;
76 static gint hf_a_month_name = -1;
77 static gint hf_a_weekofyear_prefix = -1;
78
79 /* Initialize the subtree pointers */
80 static gint ett_aasp = -1;
81 static gint ett_a_cmd = -1;
82 static gint ett_a_item = -1;
83
84 /* Preferences */
85
86 /**
87 * Commands
88 */
89 static const value_string szCmdID[] =
90 {
91 { BEGIN_BLOCK_DATA, "Begin Block Data" },
92 { WINDOW, "Window" },
93 { TITLE, "Title" },
94 { ROW, "Row" },
95 { MENU_ITEM, "Menu Item" },
96 { CONTEXT_INFO, "Context Info" },
97 { BUTTON_PRESSED, "Button Pressed" },
98 { COLUMN, "Column" },
99 { SET_TEXT, "Set Text" },
100 { DATE_TIME_INFO, "Date Time Info" },
101 { INCOMING_CALLER, "Incoming Caller" },
102 { DO_COMMAND, "Do Command" },
103 { PUSH_BTN_C, "Push Button 'C'" },
104 { PUSH_BTN_TASK, "Push Button 'Task'" },
105 { PUSH_BTN_PLUS, "Push Button '+'" },
106 { PUSH_BTN_MINUS, "Push Button '-'" },
107 { PUSH_BTN_MIC, "Push Button 'Microphone'" },
108 { PUSH_BTN_SPK, "Push Button 'Speaker'" },
109 { PUSH_BTN_TBOOK, "Push Button 'Telephone Book'" },
110 { PUSH_BTN_DBL_ARROW, "Push Button 'Double-Arrow'" },
111 { PUSH_BTN_ON_HOOK, "Red Button 'On Hook'" },
112 { PUSH_BTN_OFF_HOOK, "Green Button 'Off Hook'" },
113 { PUSH_BTN_UP, "Push Button 'Up'" },
114 { PUSH_BTN_DOWN, "Push Button 'Down'" },
115 { PUSH_BTN_LEFT, "Push Button 'Left'" },
116 { PUSH_BTN_RIGHT, "Push Button 'Right'" },
117 { END_BLOCK_DATA, "End Block Data" },
118 { 0, NULL }
119 };
120
121 /**
122 * Dissect single command
123 */
124 static void
dissect_a_binary_command(tvbuff_t * tvb,packet_info * pinfo _U_,proto_tree * tree)125 dissect_a_binary_command(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
126 {
127 proto_item *ti;
128 proto_tree *subtree;
129 const guint8* pstr;
130 guint i, len;
131
132 /* create command subtree */
133 ti = proto_tree_add_item(tree, hf_a_cmd, tvb, 0, -1, ENC_NA);
134 subtree = proto_item_add_subtree(ti, ett_a_cmd);
135 proto_item_append_text(ti, ", %s", val_to_str(tvb_get_guint8(tvb, 0), szCmdID, "Unk %d"));
136
137 /* command id */
138 proto_tree_add_item(subtree, hf_a_id, tvb, 0, 1, ENC_BIG_ENDIAN);
139
140 /* attributes */
141 switch(tvb_get_guint8(tvb, 0))
142 {
143 default:
144 {
145 if(tvb_reported_length(tvb) > 1)
146 proto_tree_add_item(subtree, hf_a_data, tvb, 1, -1, ENC_NA);
147 break;
148 }
149 case CONTEXT_INFO:
150 {
151 for(i = 1; i<tvb_reported_length(tvb); )
152 {
153 switch(tvb_get_guint8(tvb, i))
154 {
155 default: i = tvb_reported_length(tvb); continue;
156
157 case 1:
158 case 3:
159 case 7:
160 {
161 ti = proto_tree_add_item(subtree, hf_a_attr, tvb, i, 2, ENC_NA);
162 proto_item_append_text(ti, " %d", tvb_get_guint8(tvb, i));
163 i+=2; break;
164 }
165
166 case 0:
167 case 4:
168 {
169 ti = proto_tree_add_item(subtree, hf_a_attr, tvb, i, 3, ENC_NA);
170 proto_item_append_text(ti, " %d", tvb_get_guint8(tvb, i));
171 i+=3; break;
172 }
173
174 case 2:
175 {
176 ti = proto_tree_add_item(subtree, hf_a_attr, tvb, i, 5, ENC_NA);
177 proto_item_append_text(ti, " %d", tvb_get_guint8(tvb, i));
178 i+=5; break;
179 }
180 }
181 }
182 break;
183 }
184 case BUTTON_PRESSED:
185 {
186 guint8 c = tvb_get_guint8(tvb, 5);
187 proto_item_append_text(ti, ": %d '%c'", c, c);
188
189 proto_tree_add_item(subtree, hf_a_data, tvb, 1, 4, ENC_NA);
190 ti = proto_tree_add_item(subtree, hf_a_button_id, tvb, 5, 1, ENC_BIG_ENDIAN);
191 if(ti)
192 proto_item_append_text(ti, " '%c'", c);
193 break;
194 }
195 case SET_TEXT:
196 {
197 if(tvb_reported_length(tvb) > 3)
198 {
199 proto_tree_add_item(subtree, hf_a_data, tvb, 1, 3, ENC_NA);
200 proto_tree_add_item(subtree, hf_a_length, tvb, 4, 1, ENC_BIG_ENDIAN);
201 proto_tree_add_item(subtree, hf_a_text, tvb, 5, -1, ENC_ASCII|ENC_NA);
202
203 pstr = tvb_get_string_enc(pinfo->pool, tvb, 5, tvb_get_guint8(tvb, 4), ENC_ASCII|ENC_NA);
204 if(pstr)
205 {
206 proto_item_append_text(ti, ": '%s'", pstr);
207 }
208 }
209 else
210 {
211 proto_tree_add_item(subtree, hf_a_data, tvb, 1, -1, ENC_NA);
212 }
213 break;
214 }
215 case DATE_TIME_INFO:
216 {
217 proto_tree *infotree;
218
219 for(i=1; i<tvb_reported_length(tvb); )
220 {
221 switch(tvb_get_guint8(tvb, i))
222 {
223 default: i++; break;
224 case 1:
225 {
226 len = 2;
227 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
228 infotree = proto_item_add_subtree(ti, ett_a_item);
229 proto_tree_add_item(infotree, hf_a_day, tvb, i+1, 1, ENC_BIG_ENDIAN);
230 proto_item_append_text(ti, ", Day: '%d'", tvb_get_guint8(tvb, i+1));
231 i += len;
232 break;
233 }
234 case 2:
235 {
236 len = 2;
237 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
238 infotree = proto_item_add_subtree(ti, ett_a_item);
239 proto_tree_add_item(infotree, hf_a_month, tvb, i+1, 1, ENC_BIG_ENDIAN);
240 proto_item_append_text(ti, ", Month: '%d'", tvb_get_guint8(tvb, i+1));
241 i += len;
242 break;
243 }
244 case 3:
245 {
246 len = 2;
247 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
248 infotree = proto_item_add_subtree(ti, ett_a_item);
249 proto_tree_add_item(infotree, hf_a_weekofyear, tvb, i+1, 1, ENC_BIG_ENDIAN);
250 proto_item_append_text(ti, ", Week of the year: '%d'", tvb_get_guint8(tvb, i+1));
251 i += len;
252 break;
253 }
254 case 4:
255 {
256 len = tvb_get_guint8(tvb, i+1);
257 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
258 infotree = proto_item_add_subtree(ti, ett_a_item);
259 proto_tree_add_item(infotree, hf_a_data, tvb, i+2, len, ENC_NA);
260 i += len +2;
261 break;
262 }
263 case 5:
264 {
265 len = tvb_get_guint8(tvb, i+1);
266 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
267 infotree = proto_item_add_subtree(ti, ett_a_item);
268 proto_tree_add_item_ret_string(infotree, hf_a_weekday, tvb, i+2, len, ENC_ASCII|ENC_NA, pinfo->pool, &pstr);
269 if(pstr)
270 proto_item_append_text(ti, ", Weekday: '%s'", pstr);
271
272 i += len +2;
273 break;
274 }
275 case 6:
276 {
277 len = tvb_get_guint8(tvb, i+1);
278 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
279 infotree = proto_item_add_subtree(ti, ett_a_item);
280 proto_tree_add_item_ret_string(infotree, hf_a_month_name, tvb, i+2, len, ENC_ASCII|ENC_NA, pinfo->pool, &pstr);
281 if(pstr)
282 proto_item_append_text(ti, ", Month name: '%s'", pstr);
283 i += len +2;
284 break;
285 }
286 case 7:
287 {
288 len = tvb_get_guint8(tvb, i+1);
289 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
290 infotree = proto_item_add_subtree(ti, ett_a_item);
291 proto_tree_add_item_ret_string(infotree, hf_a_weekofyear_prefix, tvb, i+2, len, ENC_ASCII|ENC_NA, pinfo->pool, &pstr);
292 if(pstr)
293 proto_item_append_text(ti, ", Week of the year prefix: '%s'", pstr);
294 i += len +2;
295 break;
296 }
297 case 8:
298 {
299 len = 2;
300 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
301 infotree = proto_item_add_subtree(ti, ett_a_item);
302 proto_tree_add_item(infotree, hf_a_hour, tvb, i+1, 1, ENC_BIG_ENDIAN);
303 proto_item_append_text(ti, ", Hour: '%d'", tvb_get_guint8(tvb, i+1));
304 i += len;
305 break;
306 }
307 case 9:
308 {
309 len = 2;
310 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
311 infotree = proto_item_add_subtree(ti, ett_a_item);
312 proto_tree_add_item(infotree, hf_a_minute, tvb, i+1, 1, ENC_BIG_ENDIAN);
313 proto_item_append_text(ti, ", Minute: '%d'", tvb_get_guint8(tvb, i+1));
314 i += len;
315 break;
316 }
317 case 10:
318 {
319 len = 2;
320 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
321 infotree = proto_item_add_subtree(ti, ett_a_item);
322 proto_tree_add_item(infotree, hf_a_data, tvb, i+1, 1, ENC_NA);
323 i += len;
324 break;
325 }
326 }
327 }
328 break;
329 }
330 case DO_COMMAND:
331 {
332 if(tvb_reported_length(tvb) > 1)
333 {
334 proto_tree_add_item(subtree, hf_a_line, tvb, 1, 1, ENC_BIG_ENDIAN);
335 proto_tree_add_item(subtree, hf_a_length, tvb, 2, 1, ENC_BIG_ENDIAN);
336 proto_tree_add_item(subtree, hf_a_cdpn, tvb, 3, -1, ENC_ASCII|ENC_NA);
337
338 pstr = tvb_get_string_enc(pinfo->pool, tvb, 3, tvb_get_guint8(tvb, 2), ENC_ASCII|ENC_NA);
339 if(pstr)
340 proto_item_append_text(ti, ": '%s'", pstr);
341 }
342 else
343 proto_item_append_text(ti, ": ???");
344 break;
345 }
346 }
347 }
348
349 /**
350 * Searching for the next command when the variable or unknown length.
351 */
searchNext(tvbuff_t * tvb,guint begin,guint end)352 static guint searchNext(tvbuff_t *tvb, guint begin, guint end)
353 {
354 for(; begin < end; begin++)
355 {
356 if(tvb_get_guint8(tvb, begin) & 0x80)
357 return begin;
358 }
359 return end;
360 }
361
362 /**
363 * AASP-over-SIP
364 */
365 static int
dissect_aasp(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)366 dissect_aasp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
367 {
368 /* Set up structures needed to add the protocol subtree and manage it */
369 proto_item *ti; proto_tree *aasp_tree; guint n;
370
371 /* Check that there's enough data */
372 n = tvb_reported_length(tvb);
373 if(n < 3) return 0;
374
375 col_clear(pinfo->cinfo, COL_INFO);
376 col_append_str(pinfo->cinfo, COL_PROTOCOL, "/AASP");
377
378 if(tree)
379 {
380 guint i, prev;
381
382 /* create display subtree for the protocol */
383 ti = proto_tree_add_item(tree, proto_aasp, tvb, 0, -1, ENC_NA);
384 aasp_tree = proto_item_add_subtree(ti, ett_aasp);
385
386 /* separation of command; jump "a=" */
387 if(tvb_memeql(tvb, 0, (const guint8*)"a=", 2) == 0)
388 {
389 prev = 2;
390 for(i=2; i<n;)
391 {
392 switch(tvb_get_guint8(tvb, i))
393 {
394 #if 0
395 case CONTEXT_INFO:
396 {
397 /* 86:02:00:02:00:23:04:00 */
398 /* 86:02:00:12:00:23:04:00 */
399 /* 86:02:00:3a:02:77 */
400 /* 86:02:00:45:02:77 */
401 /* 86:02:00:62:02:77 */
402 /* 86:02:00:61:02:77 */
403 /* 86:02:00:1e:02:77 */
404 /* 86:02:00:00:12:77 */
405 /* 86:02:00:07:12:77 */
406 /* 86:02:00:00:00:01:03:02 */
407 /* 86:02:00:00:01:03:02 */
408 switch(tvb_get_guint8(tvb, i+2))
409 {
410 case 0x00: i += 11; break;
411 case 0x02: i += 8; break;
412 }
413 break;
414 }
415 #endif
416 default:
417 i = searchNext(tvb, i+1, n);
418 break;
419 }
420 dissect_a_binary_command(tvb_new_subset_length(tvb, prev, i-prev), pinfo, aasp_tree);
421 prev = i;
422 }
423 }
424 else
425 {
426 proto_tree_add_item(aasp_tree, hf_a_text, tvb, 0, -1, ENC_ASCII|ENC_NA);
427 }
428 }
429
430 /* Return the amount of data this dissector was able to dissect */
431 return n;
432 }
433
434 /* Register the protocol with Wireshark */
435 void
proto_register_aasp(void)436 proto_register_aasp(void)
437 {
438 /*module_t *aasp_module;*/
439
440 /* Setup list of header fields See Section 1.6.1 for details*/
441 static hf_register_info hf[] = {
442 { &hf_a_data,
443 { "Data", "aasp.bin.data", FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
444 { &hf_a_cmd,
445 { "Bin Cmd", "aasp.a", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
446 { &hf_a_id,
447 { "ID", "aasp.a.id", FT_UINT8, BASE_DEC, VALS(szCmdID), 0, NULL, HFILL }},
448 { &hf_a_length,
449 { "Length", "aasp.bin.length", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
450 { &hf_a_text,
451 { "Text", "aasp.bin.text", FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }},
452 { &hf_a_line,
453 { "Line", "aasp.bin.line", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
454 { &hf_a_cdpn,
455 { "CDPN", "aasp.bin.cdpn", FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }},
456 { &hf_a_button_id,
457 { "Button ID", "aasp.bin.btnid", FT_UINT8, BASE_HEX_DEC, NULL, 0, NULL, HFILL }},
458
459 { &hf_a_attr,
460 { "Attribute", "aasp.a.attr", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
461
462 { &hf_a_item,
463 { "Info item", "aasp.bin.infoitem", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
464 { &hf_a_hour,
465 { "Hour", "aasp.bin.hour", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
466 { &hf_a_minute,
467 { "Minute", "aasp.bin.minute", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
468 { &hf_a_day,
469 { "Day", "aasp.bin.day", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
470 { &hf_a_month,
471 { "Month", "aasp.bin.month", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
472 { &hf_a_weekofyear,
473 { "Week of the year", "aasp.bin.weekofyear", FT_UINT8, BASE_DEC, NULL, 0,
474 "Week number in the year", HFILL }},
475 { &hf_a_weekday,
476 { "Weekday", "aasp.bin.weekday", FT_STRING, BASE_NONE, NULL, 0,
477 "Short weekday name in the PBX current language", HFILL }},
478 { &hf_a_month_name,
479 { "Month name", "aasp.bin.monthname", FT_STRING, BASE_NONE, NULL, 0,
480 "Short month name in the PBX current language", HFILL }},
481 { &hf_a_weekofyear_prefix,
482 { "Week of the year prefix", "aasp.bin.weekofyearprefix", FT_STRING, BASE_NONE, NULL, 0,
483 "Precedes the number on the screen which is the week number in year", HFILL }},
484 };
485
486 /* Setup protocol subtree array */
487 static gint *ett[] = {
488 &ett_aasp,
489 &ett_a_cmd,
490 &ett_a_item,
491 };
492
493 /* Register the protocol name and description */
494 proto_aasp = proto_register_protocol("Aastra Signalling Protocol", "AASP", "aasp");
495
496 /* Required function calls to register the header fields and subtrees used */
497 proto_register_field_array(proto_aasp, hf, array_length(hf));
498 proto_register_subtree_array(ett, array_length(ett));
499
500 /* Register our configuration options */
501 /* aasp_module = prefs_register_protocol(proto_aasp, proto_reg_handoff_aasp); */
502 }
503
504 /* */
505 void
proto_reg_handoff_aasp(void)506 proto_reg_handoff_aasp(void)
507 {
508 dissector_handle_t aasp_handle;
509 aasp_handle = create_dissector_handle(dissect_aasp, proto_aasp);
510 dissector_add_string("media_type", "message/x-aasp-signalling", aasp_handle);
511 }
512
513 /*
514 * Editor modelines - https://www.wireshark.org/tools/modelines.html
515 *
516 * Local variables:
517 * c-basic-offset: 4
518 * tab-width: 8
519 * indent-tabs-mode: nil
520 * End:
521 *
522 * vi: set shiftwidth=4 tabstop=8 expandtab:
523 * :indentSize=4:tabSize=8:noTabs=true:
524 */
525