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
14 #include "epan/packet.h"
15 #include "epan/prefs.h"
16 #include "epan/expert.h"
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
;
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
;
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
;
70 uint32_t type
, length
;
75 col_append_str(pinfo
->cinfo
, COL_PROTOCOL
, "/NOE");
79 col_append_str(pinfo
->cinfo
, COL_PROTOCOL
, "/DL");
82 opcode
= tvb_get_uint8(tvb
, 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
);
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
);
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);
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
);
121 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
132 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
143 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
154 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
165 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
176 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
187 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
198 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
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
);
209 expert_add_info_format(pinfo
, tlv_len_item
, &ei_uasip_tlv_length
, "Invalid length %d", length
);
223 proto_tree_add_item_ret_uint(uasip_tree
, hf_uasip_expseq
, tvb
, offset
, 2, ENC_BIG_ENDIAN
, &ua_tap_info
.expseq
);
229 col_set_str(pinfo
->cinfo
, COL_INFO
, "NACK");
233 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "NACK exp:%d", ua_tap_info
.expseq
);
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
);
245 datalen
= tvb_reported_length_remaining(tvb
, offset
);
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
);
261 col_set_str(pinfo
->cinfo
, COL_INFO
, "DATA - Couldn't resolve direction.");
266 col_set_str(pinfo
->cinfo
, COL_INFO
, "ACK");
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
);
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
);
289 tap_queue_packet(uasip_tap
, pinfo
, &ua_tap_info
);
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
[] = {
323 BASE_DEC
| BASE_EXT_STRING
,
324 &uaudp_opcode_str_ext
,
344 &hf_uasip_window_size
,
352 "UA/SIP Window Size",
383 &hf_uasip_udp_lost_reinit
,
386 "uasip.udp_lost_reinit",
391 "UA/SIP Lost Re-Init",
409 &hf_uasip_qos_ip_tos
,
422 &hf_uasip_qos_8021_vlid
,
425 "uasip.qos_8021_vlid",
430 "UA/SIP QoS 802.1 VLID",
435 &hf_uasip_qos_8021_pri
,
438 "uasip.qos_8021_pri",
443 "UA/SIP QoS 802.1 PRI",
450 "Sequence Number (expected)",
456 "UA/SIP Expected Sequence Number",
463 "Sequence Number (sent)",
469 "UA/SIP Sent Sequence Number",
479 BASE_DEC
|BASE_EXT_STRING
,
480 &uaudp_connect_vals_ext
,
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
);
527 uasip_tap
= register_tap("uasip");
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;
553 report_failure("uasip: Invalid 'Proxy IP Address': \"%s\"", pref_proxy_ipaddr_s
);
559 * Editor modelines - https://www.wireshark.org/tools/modelines.html
564 * indent-tabs-mode: nil
567 * vi: set shiftwidth=4 tabstop=8 expandtab:
568 * :indentSize=4:tabSize=8:noTabs=true: