Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-uasip.c
blob72e19d609b2ab82afb9dfee1c7d951816765ab60
1 /* packet-uasip.c
2 * Routines for UA/UDP (Universal Alcatel over UDP) and NOE/SIP packet dissection.
3 * Copyright 2012, Alcatel-Lucent Enterprise <lars.ruoff@alcatel-lucent.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
12 #include "config.h"
14 #include "epan/packet.h"
15 #include "epan/prefs.h"
16 #include "epan/expert.h"
17 #if 0
18 #include <epan/tap.h>
19 #endif
20 #include <epan/addr_resolv.h>
21 #include <wsutil/report_message.h>
23 #include "packet-uaudp.h"
25 void proto_register_uasip(void);
26 void proto_reg_handoff_uasip(void);
28 static tap_struct_uaudp ua_tap_info;
29 #if 0
30 static int uasip_tap;
31 #endif
33 static int proto_uasip;
34 static int hf_uasip_opcode;
35 static int hf_uasip_version;
36 static int hf_uasip_window_size;
37 static int hf_uasip_mtu;
38 static int hf_uasip_udp_lost;
39 static int hf_uasip_udp_lost_reinit;
40 static int hf_uasip_keepalive;
41 static int hf_uasip_qos_ip_tos;
42 static int hf_uasip_qos_8021_vlid;
43 static int hf_uasip_qos_8021_pri;
44 static int hf_uasip_expseq;
45 static int hf_uasip_sntseq;
46 static int hf_uasip_type;
47 static int hf_uasip_length;
49 static int ett_uasip;
50 static int ett_uasip_tlv;
52 static expert_field ei_uasip_tlv_length;
54 static uint8_t proxy_ipaddr[4];
55 static const char *pref_proxy_ipaddr_s;
57 static bool use_proxy_ipaddr;
58 static bool noesip_enabled;
60 static dissector_handle_t uasip_handle;
62 static dissector_handle_t ua_sys_to_term_handle;
63 static dissector_handle_t ua_term_to_sys_handle;
65 static void _dissect_uasip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, e_ua_direction direction)
67 proto_item *uasip_item, *tlv_item, *tlv_len_item;
68 proto_tree *uasip_tree, *connect_tree;
69 uint8_t opcode;
70 uint32_t type, length;
71 int offset = 0;
73 if (noesip_enabled)
75 col_append_str(pinfo->cinfo, COL_PROTOCOL, "/NOE");
77 else
79 col_append_str(pinfo->cinfo, COL_PROTOCOL, "/DL");
82 opcode = tvb_get_uint8(tvb, offset);
83 offset++;
85 ua_tap_info.opcode = opcode;
86 ua_tap_info.expseq = 0;
87 ua_tap_info.sntseq = 0;
89 col_add_str(pinfo->cinfo, COL_INFO, val_to_str_ext(opcode, &uaudp_opcode_str_ext, "unknown (0x%02x)"));
91 uasip_item = proto_tree_add_protocol_format(tree, proto_uasip, tvb, 0, 5,
92 "SIP/NOE Protocol, %s",
93 val_to_str_ext(opcode, &uaudp_opcode_str_ext, "unknown (0x%02x)"));
94 uasip_tree = proto_item_add_subtree(uasip_item, ett_uasip);
95 proto_tree_add_uint(uasip_tree, hf_uasip_opcode, tvb, 0, 1, opcode);
97 switch(opcode)
99 case UAUDP_CONNECT:
101 while(tvb_reported_length_remaining(tvb, offset) > 0)
103 type = tvb_get_uint8(tvb, offset+0);
104 connect_tree = proto_tree_add_subtree(uasip_tree, tvb, offset, 0, ett_uasip_tlv, &tlv_item,
105 val_to_str_ext(type, &uaudp_connect_vals_ext, "Unknown %d"));
106 proto_tree_add_uint(connect_tree, hf_uasip_type, tvb, offset, 1, type);
107 offset++;
108 tlv_len_item = proto_tree_add_item_ret_uint(connect_tree, hf_uasip_length, tvb, offset, 1, ENC_NA, &length);
109 proto_item_set_len(tlv_item, length+2);
110 offset++;
112 switch(type)
114 case UAUDP_CONNECT_VERSION:
115 if ((length >= 1) && (length <= 4))
117 proto_tree_add_item(connect_tree, hf_uasip_version, tvb, offset, length, ENC_BIG_ENDIAN);
119 else
121 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
123 break;
125 case UAUDP_CONNECT_WINDOW_SIZE:
126 if ((length >= 1) && (length <= 4))
128 proto_tree_add_item(connect_tree, hf_uasip_window_size, tvb, offset, length, ENC_BIG_ENDIAN);
130 else
132 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
134 break;
136 case UAUDP_CONNECT_MTU:
137 if ((length >= 1) && (length <= 4))
139 proto_tree_add_item(connect_tree, hf_uasip_mtu, tvb, offset, length, ENC_BIG_ENDIAN);
141 else
143 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
145 break;
147 case UAUDP_CONNECT_UDP_LOST:
148 if ((length >= 1) && (length <= 4))
150 proto_tree_add_item(connect_tree, hf_uasip_udp_lost, tvb, offset, length, ENC_BIG_ENDIAN);
152 else
154 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
156 break;
158 case UAUDP_CONNECT_UDP_LOST_REINIT:
159 if ((length >= 1) && (length <= 4))
161 proto_tree_add_item(connect_tree, hf_uasip_udp_lost_reinit, tvb, offset, length, ENC_BIG_ENDIAN);
163 else
165 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
167 break;
169 case UAUDP_CONNECT_KEEPALIVE:
170 if ((length >= 1) && (length <= 4))
172 proto_tree_add_item(connect_tree, hf_uasip_keepalive, tvb, offset, length, ENC_BIG_ENDIAN);
174 else
176 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
178 break;
180 case UAUDP_CONNECT_QOS_IP_TOS:
181 if ((length >= 1) && (length <= 4))
183 proto_tree_add_item(connect_tree, hf_uasip_qos_ip_tos, tvb, offset, length, ENC_BIG_ENDIAN);
185 else
187 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
189 break;
191 case UAUDP_CONNECT_QOS_8021_VLID:
192 if ((length >= 1) && (length <= 4))
194 proto_tree_add_item(connect_tree, hf_uasip_qos_8021_vlid, tvb, offset, length, ENC_BIG_ENDIAN);
196 else
198 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
200 break;
202 case UAUDP_CONNECT_QOS_8021_PRI:
203 if ((length >= 1) && (length <= 4))
205 proto_tree_add_item(connect_tree, hf_uasip_qos_8021_pri, tvb, offset, length, ENC_BIG_ENDIAN);
207 else
209 expert_add_info_format(pinfo, tlv_len_item, &ei_uasip_tlv_length, "Invalid length %d", length);
211 break;
213 default:
214 break;
216 offset += length;
219 break;
221 case UAUDP_NACK:
223 proto_tree_add_item_ret_uint(uasip_tree, hf_uasip_expseq, tvb, offset, 2, ENC_BIG_ENDIAN, &ua_tap_info.expseq);
225 /*offset += 2;*/
227 if (noesip_enabled)
229 col_set_str(pinfo->cinfo, COL_INFO, "NACK");
231 else
233 col_add_fstr(pinfo->cinfo, COL_INFO, "NACK exp:%d", ua_tap_info.expseq);
236 break;
238 case UAUDP_DATA:
240 int datalen;
242 proto_tree_add_item_ret_uint(uasip_tree, hf_uasip_expseq, tvb, offset+0, 2, ENC_BIG_ENDIAN, &ua_tap_info.expseq);
243 proto_tree_add_item_ret_uint(uasip_tree, hf_uasip_sntseq, tvb, offset+2, 2, ENC_BIG_ENDIAN, &ua_tap_info.sntseq);
244 offset += 4;
245 datalen = tvb_reported_length_remaining(tvb, offset);
247 if (noesip_enabled)
249 if (datalen > 0)
251 if (direction == SYS_TO_TERM)
253 call_dissector(ua_sys_to_term_handle, tvb_new_subset_length(tvb, offset, datalen), pinfo, tree);
255 else if (direction == TERM_TO_SYS)
257 call_dissector(ua_term_to_sys_handle, tvb_new_subset_length(tvb, offset, datalen), pinfo, tree);
259 else
261 col_set_str(pinfo->cinfo, COL_INFO, "DATA - Couldn't resolve direction.");
264 else
266 col_set_str(pinfo->cinfo, COL_INFO, "ACK");
269 else
271 if (datalen > 0)
273 col_add_fstr(pinfo->cinfo, COL_INFO, "DATA exp:%d", ua_tap_info.expseq);
274 col_append_fstr(pinfo->cinfo, COL_INFO, " snt:%d", ua_tap_info.sntseq);
276 else
278 col_add_fstr(pinfo->cinfo, COL_INFO, "ACK exp:%d", ua_tap_info.expseq);
279 col_append_fstr(pinfo->cinfo, COL_INFO, " snt:%d", ua_tap_info.sntseq);
283 break;
285 default:
286 break;
288 #if 0
289 tap_queue_packet(uasip_tap, pinfo, &ua_tap_info);
290 #endif
293 static int dissect_uasip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
295 if (use_proxy_ipaddr)
297 if (memcmp((pinfo->src).data, proxy_ipaddr, sizeof(proxy_ipaddr)) == 0)
299 _dissect_uasip(tvb, pinfo, tree, SYS_TO_TERM);
300 return tvb_captured_length(tvb);
302 else if (memcmp((pinfo->dst).data, proxy_ipaddr, sizeof(proxy_ipaddr)) == 0)
304 _dissect_uasip(tvb, pinfo, tree, TERM_TO_SYS);
305 return tvb_captured_length(tvb);
308 _dissect_uasip(tvb, pinfo, tree, DIR_UNKNOWN);
309 return tvb_captured_length(tvb);
312 void proto_register_uasip(void)
314 module_t *uasip_module;
316 static hf_register_info hf_uasip[] = {
318 &hf_uasip_opcode,
320 "Opcode",
321 "uasip.opcode",
322 FT_UINT8,
323 BASE_DEC | BASE_EXT_STRING,
324 &uaudp_opcode_str_ext,
325 0x0,
326 "UA/SIP Opcode",
327 HFILL
331 &hf_uasip_version,
333 "Version",
334 "uasip.version",
335 FT_UINT8,
336 BASE_DEC,
337 NULL,
338 0x0,
339 "UA/SIP Version",
340 HFILL
344 &hf_uasip_window_size,
346 "Window Size",
347 "uasip.window_size",
348 FT_UINT8,
349 BASE_DEC,
350 NULL,
351 0x0,
352 "UA/SIP Window Size",
353 HFILL
357 &hf_uasip_mtu,
359 "MTU",
360 "uasip.mtu",
361 FT_UINT8,
362 BASE_DEC,
363 NULL,
364 0x0,
365 "UA/SIP MTU",
366 HFILL
370 &hf_uasip_udp_lost,
372 "UDP Lost",
373 "uasip.udp_lost",
374 FT_UINT8,
375 BASE_DEC,
376 NULL,
377 0x0,
378 "UA/SIP Lost",
379 HFILL
383 &hf_uasip_udp_lost_reinit,
385 "UDP lost reinit",
386 "uasip.udp_lost_reinit",
387 FT_UINT8,
388 BASE_DEC,
389 NULL,
390 0x0,
391 "UA/SIP Lost Re-Init",
392 HFILL
396 &hf_uasip_keepalive,
398 "Keepalive",
399 "uasip.keepalive",
400 FT_UINT8,
401 BASE_DEC,
402 NULL,
403 0x0,
404 "UA/SIP Keepalive",
405 HFILL
409 &hf_uasip_qos_ip_tos,
411 "QoS IP TOS",
412 "uasip.qos_ip_tos",
413 FT_UINT8,
414 BASE_DEC,
415 NULL,
416 0x0,
417 "UA/SIP QoS IP TOS",
418 HFILL
422 &hf_uasip_qos_8021_vlid,
424 "QoS 802.1 VLID",
425 "uasip.qos_8021_vlid",
426 FT_UINT8,
427 BASE_DEC,
428 NULL,
429 0x0,
430 "UA/SIP QoS 802.1 VLID",
431 HFILL
435 &hf_uasip_qos_8021_pri,
437 "QoS 802.1 PRI",
438 "uasip.qos_8021_pri",
439 FT_UINT8,
440 BASE_DEC,
441 NULL,
442 0x0,
443 "UA/SIP QoS 802.1 PRI",
444 HFILL
448 &hf_uasip_expseq,
450 "Sequence Number (expected)",
451 "uasip.expseq",
452 FT_UINT16,
453 BASE_DEC,
454 NULL,
455 0x0,
456 "UA/SIP Expected Sequence Number",
457 HFILL
461 &hf_uasip_sntseq,
463 "Sequence Number (sent)",
464 "uasip.sntseq",
465 FT_UINT16,
466 BASE_DEC,
467 NULL,
468 0x0,
469 "UA/SIP Sent Sequence Number",
470 HFILL
474 &hf_uasip_type,
476 "Type",
477 "uasip.type",
478 FT_UINT8,
479 BASE_DEC|BASE_EXT_STRING,
480 &uaudp_connect_vals_ext,
481 0x0,
482 NULL,
483 HFILL
487 &hf_uasip_length,
489 "Length",
490 "uasip.length",
491 FT_UINT8,
492 BASE_DEC,
493 NULL,
494 0x0,
495 NULL,
496 HFILL
501 static int *ett[] =
503 &ett_uasip,
504 &ett_uasip_tlv,
507 static ei_register_info ei[] = {
508 { &ei_uasip_tlv_length, { "uasip.tlv_length_invalid", PI_PROTOCOL, PI_WARN, "Invalid length", EXPFILL }},
510 expert_module_t* expert_uasip;
512 proto_uasip = proto_register_protocol("UA/SIP Protocol", "UASIP", "uasip");
513 uasip_handle = register_dissector("uasip", dissect_uasip, proto_uasip);
515 proto_register_field_array(proto_uasip, hf_uasip, array_length(hf_uasip));
516 proto_register_subtree_array(ett, array_length(ett));
517 expert_uasip = expert_register_protocol(proto_uasip);
518 expert_register_field_array(expert_uasip, ei, array_length(ei));
520 uasip_module = prefs_register_protocol(proto_uasip, proto_reg_handoff_uasip);
521 prefs_register_obsolete_preference(uasip_module, "application_octet_stream");
522 prefs_register_bool_preference(uasip_module, "noesip", "Try to decode SIP NOE", "NOE SIP Protocol", &noesip_enabled);
523 prefs_register_string_preference(uasip_module, "proxy_ipaddr", "Proxy IP Address",
524 "IPv4 address of the proxy (Invalid values will be ignored)",
525 &pref_proxy_ipaddr_s);
526 #if 0
527 uasip_tap = register_tap("uasip");
528 #endif
531 void proto_reg_handoff_uasip(void)
533 static bool prefs_initialized = false;
535 if (!prefs_initialized)
537 ua_sys_to_term_handle = find_dissector_add_dependency("ua_sys_to_term", proto_uasip);
538 ua_term_to_sys_handle = find_dissector_add_dependency("ua_term_to_sys", proto_uasip);
540 /* Enable decoding "Internet media type" as UASIP */
541 dissector_add_for_decode_as("media_type", uasip_handle);
543 prefs_initialized = true;
546 use_proxy_ipaddr = false;
547 memset(proxy_ipaddr, 0, sizeof(proxy_ipaddr));
549 if (strcmp(pref_proxy_ipaddr_s, "") != 0) {
550 if (str_to_ip(pref_proxy_ipaddr_s, proxy_ipaddr)) {
551 use_proxy_ipaddr = true;
552 } else {
553 report_failure("uasip: Invalid 'Proxy IP Address': \"%s\"", pref_proxy_ipaddr_s);
559 * Editor modelines - https://www.wireshark.org/tools/modelines.html
561 * Local variables:
562 * c-basic-offset: 4
563 * tab-width: 8
564 * indent-tabs-mode: nil
565 * End:
567 * vi: set shiftwidth=4 tabstop=8 expandtab:
568 * :indentSize=4:tabSize=8:noTabs=true: