epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-aastra-aasp.c
blob7bfdea14168dc5535693df22aa8773af10563206
1 /* packet-aastra-aasp.c
2 * Routines for AASP (Aastra Signalling Protocol) packet dissection.
3 * Copyright 2011, Marek Tews <marek.tews@gmail.com>
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
13 * AASP over SIP
14 * Content-Type: message/x-aasp-signalling
17 #include "config.h"
19 #include <epan/packet.h>
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
51 /* Forward declarations */
52 void proto_register_aasp(void);
53 void proto_reg_handoff_aasp(void);
55 static dissector_handle_t aasp_handle;
57 /* Initialize the protocol and registered fields */
58 static int proto_aasp;
60 static int hf_a_data;
61 static int hf_a_cmd;
62 static int hf_a_id;
63 static int hf_a_length;
64 static int hf_a_text;
65 static int hf_a_line;
66 static int hf_a_cdpn;
67 static int hf_a_button_id;
69 static int hf_a_attr;
71 static int hf_a_item;
72 static int hf_a_hour;
73 static int hf_a_minute;
74 static int hf_a_day;
75 static int hf_a_month;
76 static int hf_a_weekofyear;
77 static int hf_a_weekday;
78 static int hf_a_month_name;
79 static int hf_a_weekofyear_prefix;
81 /* Initialize the subtree pointers */
82 static int ett_aasp;
83 static int ett_a_cmd;
84 static int ett_a_item;
86 /* Preferences */
88 /**
89 * Commands
91 static const value_string szCmdID[] =
93 { BEGIN_BLOCK_DATA, "Begin Block Data" },
94 { WINDOW, "Window" },
95 { TITLE, "Title" },
96 { ROW, "Row" },
97 { MENU_ITEM, "Menu Item" },
98 { CONTEXT_INFO, "Context Info" },
99 { BUTTON_PRESSED, "Button Pressed" },
100 { COLUMN, "Column" },
101 { SET_TEXT, "Set Text" },
102 { DATE_TIME_INFO, "Date Time Info" },
103 { INCOMING_CALLER, "Incoming Caller" },
104 { DO_COMMAND, "Do Command" },
105 { PUSH_BTN_C, "Push Button 'C'" },
106 { PUSH_BTN_TASK, "Push Button 'Task'" },
107 { PUSH_BTN_PLUS, "Push Button '+'" },
108 { PUSH_BTN_MINUS, "Push Button '-'" },
109 { PUSH_BTN_MIC, "Push Button 'Microphone'" },
110 { PUSH_BTN_SPK, "Push Button 'Speaker'" },
111 { PUSH_BTN_TBOOK, "Push Button 'Telephone Book'" },
112 { PUSH_BTN_DBL_ARROW, "Push Button 'Double-Arrow'" },
113 { PUSH_BTN_ON_HOOK, "Red Button 'On Hook'" },
114 { PUSH_BTN_OFF_HOOK, "Green Button 'Off Hook'" },
115 { PUSH_BTN_UP, "Push Button 'Up'" },
116 { PUSH_BTN_DOWN, "Push Button 'Down'" },
117 { PUSH_BTN_LEFT, "Push Button 'Left'" },
118 { PUSH_BTN_RIGHT, "Push Button 'Right'" },
119 { END_BLOCK_DATA, "End Block Data" },
120 { 0, NULL }
124 * Dissect single command
126 static void
127 dissect_a_binary_command(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
129 proto_item *ti;
130 proto_tree *subtree;
131 const uint8_t* pstr;
132 unsigned i, len;
134 /* create command subtree */
135 ti = proto_tree_add_item(tree, hf_a_cmd, tvb, 0, -1, ENC_NA);
136 subtree = proto_item_add_subtree(ti, ett_a_cmd);
137 proto_item_append_text(ti, ", %s", val_to_str(tvb_get_uint8(tvb, 0), szCmdID, "Unk %d"));
139 /* command id */
140 proto_tree_add_item(subtree, hf_a_id, tvb, 0, 1, ENC_BIG_ENDIAN);
142 /* attributes */
143 switch(tvb_get_uint8(tvb, 0))
145 default:
147 if(tvb_reported_length(tvb) > 1)
148 proto_tree_add_item(subtree, hf_a_data, tvb, 1, -1, ENC_NA);
149 break;
151 case CONTEXT_INFO:
153 for(i = 1; i<tvb_reported_length(tvb); )
155 switch(tvb_get_uint8(tvb, i))
157 default: i = tvb_reported_length(tvb); continue;
159 case 1:
160 case 3:
161 case 7:
163 ti = proto_tree_add_item(subtree, hf_a_attr, tvb, i, 2, ENC_NA);
164 proto_item_append_text(ti, " %d", tvb_get_uint8(tvb, i));
165 i+=2; break;
168 case 0:
169 case 4:
171 ti = proto_tree_add_item(subtree, hf_a_attr, tvb, i, 3, ENC_NA);
172 proto_item_append_text(ti, " %d", tvb_get_uint8(tvb, i));
173 i+=3; break;
176 case 2:
178 ti = proto_tree_add_item(subtree, hf_a_attr, tvb, i, 5, ENC_NA);
179 proto_item_append_text(ti, " %d", tvb_get_uint8(tvb, i));
180 i+=5; break;
184 break;
186 case BUTTON_PRESSED:
188 uint8_t c = tvb_get_uint8(tvb, 5);
189 proto_item_append_text(ti, ": %d '%c'", c, c);
191 proto_tree_add_item(subtree, hf_a_data, tvb, 1, 4, ENC_NA);
192 ti = proto_tree_add_item(subtree, hf_a_button_id, tvb, 5, 1, ENC_BIG_ENDIAN);
193 if(ti)
194 proto_item_append_text(ti, " '%c'", c);
195 break;
197 case SET_TEXT:
199 if(tvb_reported_length(tvb) > 3)
201 proto_tree_add_item(subtree, hf_a_data, tvb, 1, 3, ENC_NA);
202 proto_tree_add_item(subtree, hf_a_length, tvb, 4, 1, ENC_BIG_ENDIAN);
203 proto_tree_add_item(subtree, hf_a_text, tvb, 5, -1, ENC_ASCII);
205 pstr = tvb_get_string_enc(pinfo->pool, tvb, 5, tvb_get_uint8(tvb, 4), ENC_ASCII|ENC_NA);
206 if(pstr)
208 proto_item_append_text(ti, ": '%s'", pstr);
211 else
213 proto_tree_add_item(subtree, hf_a_data, tvb, 1, -1, ENC_NA);
215 break;
217 case DATE_TIME_INFO:
219 proto_tree *infotree;
221 for(i=1; i<tvb_reported_length(tvb); )
223 switch(tvb_get_uint8(tvb, i))
225 default: i++; break;
226 case 1:
228 len = 2;
229 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
230 infotree = proto_item_add_subtree(ti, ett_a_item);
231 proto_tree_add_item(infotree, hf_a_day, tvb, i+1, 1, ENC_BIG_ENDIAN);
232 proto_item_append_text(ti, ", Day: '%d'", tvb_get_uint8(tvb, i+1));
233 i += len;
234 break;
236 case 2:
238 len = 2;
239 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
240 infotree = proto_item_add_subtree(ti, ett_a_item);
241 proto_tree_add_item(infotree, hf_a_month, tvb, i+1, 1, ENC_BIG_ENDIAN);
242 proto_item_append_text(ti, ", Month: '%d'", tvb_get_uint8(tvb, i+1));
243 i += len;
244 break;
246 case 3:
248 len = 2;
249 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
250 infotree = proto_item_add_subtree(ti, ett_a_item);
251 proto_tree_add_item(infotree, hf_a_weekofyear, tvb, i+1, 1, ENC_BIG_ENDIAN);
252 proto_item_append_text(ti, ", Week of the year: '%d'", tvb_get_uint8(tvb, i+1));
253 i += len;
254 break;
256 case 4:
258 len = tvb_get_uint8(tvb, i+1);
259 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
260 infotree = proto_item_add_subtree(ti, ett_a_item);
261 proto_tree_add_item(infotree, hf_a_data, tvb, i+2, len, ENC_NA);
262 i += len +2;
263 break;
265 case 5:
267 len = tvb_get_uint8(tvb, i+1);
268 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
269 infotree = proto_item_add_subtree(ti, ett_a_item);
270 proto_tree_add_item_ret_string(infotree, hf_a_weekday, tvb, i+2, len, ENC_ASCII|ENC_NA, pinfo->pool, &pstr);
271 if(pstr)
272 proto_item_append_text(ti, ", Weekday: '%s'", pstr);
274 i += len +2;
275 break;
277 case 6:
279 len = tvb_get_uint8(tvb, i+1);
280 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
281 infotree = proto_item_add_subtree(ti, ett_a_item);
282 proto_tree_add_item_ret_string(infotree, hf_a_month_name, tvb, i+2, len, ENC_ASCII|ENC_NA, pinfo->pool, &pstr);
283 if(pstr)
284 proto_item_append_text(ti, ", Month name: '%s'", pstr);
285 i += len +2;
286 break;
288 case 7:
290 len = tvb_get_uint8(tvb, i+1);
291 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len+2, ENC_NA);
292 infotree = proto_item_add_subtree(ti, ett_a_item);
293 proto_tree_add_item_ret_string(infotree, hf_a_weekofyear_prefix, tvb, i+2, len, ENC_ASCII|ENC_NA, pinfo->pool, &pstr);
294 if(pstr)
295 proto_item_append_text(ti, ", Week of the year prefix: '%s'", pstr);
296 i += len +2;
297 break;
299 case 8:
301 len = 2;
302 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
303 infotree = proto_item_add_subtree(ti, ett_a_item);
304 proto_tree_add_item(infotree, hf_a_hour, tvb, i+1, 1, ENC_BIG_ENDIAN);
305 proto_item_append_text(ti, ", Hour: '%d'", tvb_get_uint8(tvb, i+1));
306 i += len;
307 break;
309 case 9:
311 len = 2;
312 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
313 infotree = proto_item_add_subtree(ti, ett_a_item);
314 proto_tree_add_item(infotree, hf_a_minute, tvb, i+1, 1, ENC_BIG_ENDIAN);
315 proto_item_append_text(ti, ", Minute: '%d'", tvb_get_uint8(tvb, i+1));
316 i += len;
317 break;
319 case 10:
321 len = 2;
322 ti = proto_tree_add_item(subtree, hf_a_item, tvb, i, len, ENC_NA);
323 infotree = proto_item_add_subtree(ti, ett_a_item);
324 proto_tree_add_item(infotree, hf_a_data, tvb, i+1, 1, ENC_NA);
325 i += len;
326 break;
330 break;
332 case DO_COMMAND:
334 if(tvb_reported_length(tvb) > 1)
336 proto_tree_add_item(subtree, hf_a_line, tvb, 1, 1, ENC_BIG_ENDIAN);
337 proto_tree_add_item(subtree, hf_a_length, tvb, 2, 1, ENC_BIG_ENDIAN);
338 proto_tree_add_item(subtree, hf_a_cdpn, tvb, 3, -1, ENC_ASCII);
340 pstr = tvb_get_string_enc(pinfo->pool, tvb, 3, tvb_get_uint8(tvb, 2), ENC_ASCII|ENC_NA);
341 if(pstr)
342 proto_item_append_text(ti, ": '%s'", pstr);
344 else
345 proto_item_append_text(ti, ": ???");
346 break;
352 * Searching for the next command when the variable or unknown length.
354 static unsigned searchNext(tvbuff_t *tvb, unsigned begin, unsigned end)
356 for(; begin < end; begin++)
358 if(tvb_get_uint8(tvb, begin) & 0x80)
359 return begin;
361 return end;
365 * AASP-over-SIP
367 static int
368 dissect_aasp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
370 /* Set up structures needed to add the protocol subtree and manage it */
371 proto_item *ti; proto_tree *aasp_tree; unsigned n;
373 /* Check that there's enough data */
374 n = tvb_reported_length(tvb);
375 if(n < 3) return 0;
377 col_clear(pinfo->cinfo, COL_INFO);
378 col_append_str(pinfo->cinfo, COL_PROTOCOL, "/AASP");
380 if(tree)
382 unsigned i, prev;
384 /* create display subtree for the protocol */
385 ti = proto_tree_add_item(tree, proto_aasp, tvb, 0, -1, ENC_NA);
386 aasp_tree = proto_item_add_subtree(ti, ett_aasp);
388 /* separation of command; jump "a=" */
389 if(tvb_memeql(tvb, 0, (const uint8_t*)"a=", 2) == 0)
391 prev = 2;
392 for(i=2; i<n;)
394 switch(tvb_get_uint8(tvb, i))
396 #if 0
397 case CONTEXT_INFO:
399 /* 86:02:00:02:00:23:04:00 */
400 /* 86:02:00:12:00:23:04:00 */
401 /* 86:02:00:3a:02:77 */
402 /* 86:02:00:45:02:77 */
403 /* 86:02:00:62:02:77 */
404 /* 86:02:00:61:02:77 */
405 /* 86:02:00:1e:02:77 */
406 /* 86:02:00:00:12:77 */
407 /* 86:02:00:07:12:77 */
408 /* 86:02:00:00:00:01:03:02 */
409 /* 86:02:00:00:01:03:02 */
410 switch(tvb_get_uint8(tvb, i+2))
412 case 0x00: i += 11; break;
413 case 0x02: i += 8; break;
415 break;
417 #endif
418 default:
419 i = searchNext(tvb, i+1, n);
420 break;
422 dissect_a_binary_command(tvb_new_subset_length(tvb, prev, i-prev), pinfo, aasp_tree);
423 prev = i;
426 else
428 proto_tree_add_item(aasp_tree, hf_a_text, tvb, 0, -1, ENC_ASCII);
432 /* Return the amount of data this dissector was able to dissect */
433 return n;
436 /* Register the protocol with Wireshark */
437 void
438 proto_register_aasp(void)
440 /*module_t *aasp_module;*/
442 /* Setup list of header fields See Section 1.6.1 for details*/
443 static hf_register_info hf[] = {
444 { &hf_a_data,
445 { "Data", "aasp.bin.data", FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
446 { &hf_a_cmd,
447 { "Bin Cmd", "aasp.a", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
448 { &hf_a_id,
449 { "ID", "aasp.a.id", FT_UINT8, BASE_DEC, VALS(szCmdID), 0, NULL, HFILL }},
450 { &hf_a_length,
451 { "Length", "aasp.bin.length", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
452 { &hf_a_text,
453 { "Text", "aasp.bin.text", FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }},
454 { &hf_a_line,
455 { "Line", "aasp.bin.line", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
456 { &hf_a_cdpn,
457 { "CDPN", "aasp.bin.cdpn", FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL }},
458 { &hf_a_button_id,
459 { "Button ID", "aasp.bin.btnid", FT_UINT8, BASE_HEX_DEC, NULL, 0, NULL, HFILL }},
461 { &hf_a_attr,
462 { "Attribute", "aasp.a.attr", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
464 { &hf_a_item,
465 { "Info item", "aasp.bin.infoitem", FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }},
466 { &hf_a_hour,
467 { "Hour", "aasp.bin.hour", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
468 { &hf_a_minute,
469 { "Minute", "aasp.bin.minute", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
470 { &hf_a_day,
471 { "Day", "aasp.bin.day", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
472 { &hf_a_month,
473 { "Month", "aasp.bin.month", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
474 { &hf_a_weekofyear,
475 { "Week of the year", "aasp.bin.weekofyear", FT_UINT8, BASE_DEC, NULL, 0,
476 "Week number in the year", HFILL }},
477 { &hf_a_weekday,
478 { "Weekday", "aasp.bin.weekday", FT_STRING, BASE_NONE, NULL, 0,
479 "Short weekday name in the PBX current language", HFILL }},
480 { &hf_a_month_name,
481 { "Month name", "aasp.bin.monthname", FT_STRING, BASE_NONE, NULL, 0,
482 "Short month name in the PBX current language", HFILL }},
483 { &hf_a_weekofyear_prefix,
484 { "Week of the year prefix", "aasp.bin.weekofyearprefix", FT_STRING, BASE_NONE, NULL, 0,
485 "Precedes the number on the screen which is the week number in year", HFILL }},
488 /* Setup protocol subtree array */
489 static int *ett[] = {
490 &ett_aasp,
491 &ett_a_cmd,
492 &ett_a_item,
495 /* Register the protocol name and description */
496 proto_aasp = proto_register_protocol("Aastra Signalling Protocol", "AASP", "aasp");
498 /* Required function calls to register the header fields and subtrees used */
499 proto_register_field_array(proto_aasp, hf, array_length(hf));
500 proto_register_subtree_array(ett, array_length(ett));
502 /* Register our configuration options */
503 /* aasp_module = prefs_register_protocol(proto_aasp, proto_reg_handoff_aasp); */
505 aasp_handle = register_dissector("aasp", dissect_aasp, proto_aasp);
508 /* */
509 void
510 proto_reg_handoff_aasp(void)
512 dissector_add_string("media_type", "message/x-aasp-signalling", aasp_handle);
516 * Editor modelines - https://www.wireshark.org/tools/modelines.html
518 * Local variables:
519 * c-basic-offset: 4
520 * tab-width: 8
521 * indent-tabs-mode: nil
522 * End:
524 * vi: set shiftwidth=4 tabstop=8 expandtab:
525 * :indentSize=4:tabSize=8:noTabs=true: