2011-04-19 15:23:51 +00:00
|
|
|
/* packet-bt-utp.c
|
|
|
|
* Routines for BT-UTP dissection
|
|
|
|
* Copyright 2011, Xiao Xiangquan <xiaoxiangquan@gmail.com>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1999 Gerald Combs
|
|
|
|
*
|
2018-02-12 11:23:27 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2011-04-19 15:23:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2011-11-15 21:07:37 +00:00
|
|
|
|
2011-04-19 15:23:51 +00:00
|
|
|
#include <epan/packet.h>
|
2011-11-15 21:07:37 +00:00
|
|
|
#include <epan/conversation.h>
|
2012-12-16 00:28:38 +00:00
|
|
|
#include <epan/prefs.h>
|
2011-04-19 15:23:51 +00:00
|
|
|
|
2013-12-14 12:45:57 +00:00
|
|
|
void proto_register_bt_utp(void);
|
|
|
|
void proto_reg_handoff_bt_utp(void);
|
|
|
|
|
2011-04-20 20:32:26 +00:00
|
|
|
enum {
|
|
|
|
ST_DATA = 0,
|
|
|
|
ST_FIN = 1,
|
|
|
|
ST_STATE = 2,
|
|
|
|
ST_RESET = 3,
|
|
|
|
ST_SYN = 4,
|
2011-11-01 01:23:10 +00:00
|
|
|
ST_NUM_STATES
|
2011-04-20 20:32:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* V0 hdr: "flags"; V1 hdr: "type" */
|
2011-04-19 15:23:51 +00:00
|
|
|
static const value_string bt_utp_type_vals[] = {
|
2011-04-20 20:32:26 +00:00
|
|
|
{ ST_DATA, "Data" },
|
|
|
|
{ ST_FIN, "Fin" },
|
|
|
|
{ ST_STATE, "State" },
|
|
|
|
{ ST_RESET, "Reset" },
|
|
|
|
{ ST_SYN, "Syn" },
|
2011-04-19 15:23:51 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2011-04-20 20:32:26 +00:00
|
|
|
enum {
|
|
|
|
EXT_NO_EXTENSION = 0,
|
|
|
|
EXT_SELECTION_ACKS = 1,
|
|
|
|
EXT_EXTENSION_BITS = 2,
|
2011-11-01 01:23:10 +00:00
|
|
|
EXT_NUM_EXT
|
2011-04-20 20:32:26 +00:00
|
|
|
};
|
2011-04-19 15:23:51 +00:00
|
|
|
|
|
|
|
static const value_string bt_utp_extension_type_vals[] = {
|
2011-04-20 20:32:26 +00:00
|
|
|
{ EXT_NO_EXTENSION, "No Extension" },
|
2012-12-04 17:47:07 +00:00
|
|
|
{ EXT_SELECTION_ACKS, "Selective ACKs" },
|
2011-04-19 15:23:51 +00:00
|
|
|
{ EXT_EXTENSION_BITS, "Extension bits" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int proto_bt_utp = -1;
|
|
|
|
|
2012-12-04 17:47:07 +00:00
|
|
|
/* --- "Original" uTP Header ("version 0" ?) --------------
|
2011-04-20 20:32:26 +00:00
|
|
|
|
|
|
|
See utp.cpp source code @ https://github.com/bittorrent/libutp
|
|
|
|
|
|
|
|
-- Fixed Header --
|
2012-12-04 17:47:07 +00:00
|
|
|
0 4 8 16 24 32
|
2011-04-20 20:32:26 +00:00
|
|
|
+-------+-------+---------------+---------------+---------------+
|
|
|
|
| connection_id |
|
|
|
|
+-------+-------+---------------+---------------+---------------+
|
|
|
|
| timestamp_seconds |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| timestamp_microseconds |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| timestamp_difference_microseconds |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| wnd_size | ext | flags | seq_nr [ho] |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| seq_nr [lo] | ack_nr |
|
|
|
|
+---------------+---------------+---------------+
|
|
|
|
|
|
|
|
-- Extension Field(s) --
|
|
|
|
0 8 16
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| extension | len | bitmask
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
|
|
|
|
|
+---------------+---------------+....
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* --- Version 1 Header ----------------
|
|
|
|
|
|
|
|
Specifications: BEP-0029
|
2011-04-19 15:23:51 +00:00
|
|
|
http://www.bittorrent.org/beps/bep_0029.html
|
|
|
|
|
2011-04-20 20:32:26 +00:00
|
|
|
-- Fixed Header --
|
2011-04-19 15:23:51 +00:00
|
|
|
Fields Types
|
|
|
|
0 4 8 16 24 32
|
|
|
|
+-------+-------+---------------+---------------+---------------+
|
2012-12-04 17:47:07 +00:00
|
|
|
| type | ver | extension | connection_id |
|
2011-04-19 15:23:51 +00:00
|
|
|
+-------+-------+---------------+---------------+---------------+
|
|
|
|
| timestamp_microseconds |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| timestamp_difference_microseconds |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| wnd_size |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| seq_nr | ack_nr |
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
|
2011-04-20 20:32:26 +00:00
|
|
|
-- Extension Field(s) --
|
2011-04-19 15:23:51 +00:00
|
|
|
0 8 16
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
| extension | len | bitmask
|
|
|
|
+---------------+---------------+---------------+---------------+
|
|
|
|
|
|
|
|
|
+---------------+---------------+....
|
|
|
|
*/
|
2011-04-20 20:32:26 +00:00
|
|
|
|
2012-12-04 17:47:07 +00:00
|
|
|
#define V0_FIXED_HDR_SIZE 23
|
2011-04-20 20:32:26 +00:00
|
|
|
#define V1_FIXED_HDR_SIZE 20
|
|
|
|
|
2011-10-28 14:49:31 +00:00
|
|
|
static dissector_handle_t bt_utp_handle;
|
|
|
|
|
2011-04-19 15:23:51 +00:00
|
|
|
static int hf_bt_utp_ver = -1;
|
|
|
|
static int hf_bt_utp_type = -1;
|
2011-04-20 20:32:26 +00:00
|
|
|
static int hf_bt_utp_flags = -1;
|
2011-04-19 15:23:51 +00:00
|
|
|
static int hf_bt_utp_extension = -1;
|
|
|
|
static int hf_bt_utp_next_extension_type = -1;
|
|
|
|
static int hf_bt_utp_extension_len = -1;
|
|
|
|
static int hf_bt_utp_extension_bitmask = -1;
|
|
|
|
static int hf_bt_utp_extension_unknown = -1;
|
2011-04-20 20:32:26 +00:00
|
|
|
static int hf_bt_utp_connection_id_v0 = -1;
|
|
|
|
static int hf_bt_utp_connection_id_v1 = -1;
|
|
|
|
static int hf_bt_utp_timestamp_sec = -1;
|
|
|
|
static int hf_bt_utp_timestamp_us = -1;
|
|
|
|
static int hf_bt_utp_timestamp_diff_us = -1;
|
|
|
|
static int hf_bt_utp_wnd_size_v0 = -1;
|
|
|
|
static int hf_bt_utp_wnd_size_v1 = -1;
|
2011-04-19 15:23:51 +00:00
|
|
|
static int hf_bt_utp_seq_nr = -1;
|
|
|
|
static int hf_bt_utp_ack_nr = -1;
|
2012-12-04 17:47:07 +00:00
|
|
|
static int hf_bt_utp_data = -1;
|
2011-04-19 15:23:51 +00:00
|
|
|
|
|
|
|
static gint ett_bt_utp = -1;
|
|
|
|
static gint ett_bt_utp_extension = -1;
|
|
|
|
|
2012-12-04 17:47:07 +00:00
|
|
|
static gint
|
|
|
|
get_utp_version(tvbuff_t *tvb) {
|
|
|
|
guint8 v0_flags, v0_ext;
|
|
|
|
guint8 v1_ver_type, v1_ext;
|
2011-04-20 20:32:26 +00:00
|
|
|
guint len;
|
|
|
|
|
2012-12-04 17:47:07 +00:00
|
|
|
/* Simple heuristics inspired by code from utp.cpp */
|
|
|
|
|
2015-06-22 21:40:23 +00:00
|
|
|
len = tvb_captured_length(tvb);
|
2012-12-16 00:28:38 +00:00
|
|
|
|
2013-02-20 02:15:20 +00:00
|
|
|
/* Version 1? */
|
|
|
|
if (len < V1_FIXED_HDR_SIZE) {
|
2012-12-16 00:28:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-04-20 20:32:26 +00:00
|
|
|
v1_ver_type = tvb_get_guint8(tvb, 0);
|
2013-02-20 02:15:20 +00:00
|
|
|
v1_ext = tvb_get_guint8(tvb, 1);
|
|
|
|
if (((v1_ver_type & 0x0f) == 1) && ((v1_ver_type>>4) < ST_NUM_STATES) &&
|
|
|
|
(v1_ext < EXT_NUM_EXT)) {
|
2013-02-04 02:44:04 +00:00
|
|
|
return 1;
|
2012-12-04 17:47:07 +00:00
|
|
|
}
|
2013-02-20 02:15:20 +00:00
|
|
|
|
|
|
|
/* Version 0? */
|
|
|
|
if (len < V0_FIXED_HDR_SIZE) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
v0_flags = tvb_get_guint8(tvb, 18);
|
|
|
|
v0_ext = tvb_get_guint8(tvb, 17);
|
|
|
|
if ((v0_flags < ST_NUM_STATES) || (v0_ext < EXT_NUM_EXT)) {
|
2013-02-04 02:44:04 +00:00
|
|
|
return 0;
|
2011-04-20 20:32:26 +00:00
|
|
|
}
|
2013-02-20 02:15:20 +00:00
|
|
|
|
|
|
|
return -1;
|
2011-04-20 20:32:26 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 15:23:51 +00:00
|
|
|
static int
|
2011-04-22 13:16:45 +00:00
|
|
|
dissect_utp_header_v0(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint8 *extension_type)
|
2011-04-19 15:23:51 +00:00
|
|
|
{
|
2011-04-22 13:16:45 +00:00
|
|
|
/* "Original" (V0) */
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_connection_id_v0, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 4;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_timestamp_sec, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 4;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_timestamp_us, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 4;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_timestamp_diff_us, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 4;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_wnd_size_v0, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 1;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_next_extension_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
|
|
|
|
*extension_type = tvb_get_guint8(tvb, offset);
|
|
|
|
offset += 1;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, " Type: %s", val_to_str(tvb_get_guint8(tvb, offset), bt_utp_type_vals, "Unknown %d"));
|
|
|
|
offset += 1;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_seq_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 2;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_ack_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 2;
|
2011-04-20 20:32:26 +00:00
|
|
|
|
2011-04-22 13:16:45 +00:00
|
|
|
return offset;
|
|
|
|
}
|
2011-04-20 20:32:26 +00:00
|
|
|
|
2011-04-22 13:16:45 +00:00
|
|
|
static int
|
|
|
|
dissect_utp_header_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, guint8 *extension_type)
|
|
|
|
{
|
|
|
|
/* V1 */
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_ver, tvb, offset, 1, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(tree, hf_bt_utp_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, " Type: %s", val_to_str((tvb_get_guint8(tvb, offset) >> 4), bt_utp_type_vals, "Unknown %d"));
|
|
|
|
offset += 1;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_next_extension_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
*extension_type = tvb_get_guint8(tvb, offset);
|
|
|
|
offset += 1;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_connection_id_v1, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 2;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_timestamp_us, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 4;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_timestamp_diff_us, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 4;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_wnd_size_v1, tvb, offset, 4, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 4;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_seq_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 2;
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(tree, hf_bt_utp_ack_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
offset += 2;
|
2011-04-19 15:23:51 +00:00
|
|
|
|
2011-04-22 13:16:45 +00:00
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dissect_utp_extension(tvbuff_t *tvb, packet_info _U_*pinfo, proto_tree *tree, int offset, guint8 *extension_type)
|
|
|
|
{
|
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *ext_tree;
|
|
|
|
guint8 extension_length;
|
2011-04-19 15:23:51 +00:00
|
|
|
/* display the extension tree */
|
2011-04-20 17:25:07 +00:00
|
|
|
|
2012-12-04 17:47:07 +00:00
|
|
|
while(*extension_type != EXT_NO_EXTENSION && offset < (int)tvb_reported_length(tvb))
|
2011-04-19 15:23:51 +00:00
|
|
|
{
|
2011-04-22 13:16:45 +00:00
|
|
|
switch(*extension_type){
|
2011-04-19 15:23:51 +00:00
|
|
|
case EXT_SELECTION_ACKS: /* 1 */
|
|
|
|
{
|
2011-10-04 22:44:31 +00:00
|
|
|
ti = proto_tree_add_item(tree, hf_bt_utp_extension, tvb, offset, -1, ENC_NA);
|
2011-04-19 15:23:51 +00:00
|
|
|
ext_tree = proto_item_add_subtree(ti, ett_bt_utp_extension);
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_next_extension_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
*extension_type = tvb_get_guint8(tvb, offset);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += 1;
|
2011-04-19 16:37:39 +00:00
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_extension_len, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-19 15:23:51 +00:00
|
|
|
extension_length = tvb_get_guint8(tvb, offset);
|
2012-12-04 17:47:07 +00:00
|
|
|
proto_item_append_text(ti, " Selection ACKs, Len=%d", extension_length);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += 1;
|
2011-04-19 16:37:39 +00:00
|
|
|
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_extension_bitmask, tvb, offset, extension_length, ENC_NA);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += extension_length;
|
|
|
|
proto_item_set_len(ti, 1 + 1 + extension_length);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-20 17:25:07 +00:00
|
|
|
case EXT_EXTENSION_BITS: /* 2 */
|
2011-04-19 15:23:51 +00:00
|
|
|
{
|
2011-10-04 22:44:31 +00:00
|
|
|
ti = proto_tree_add_item(tree, hf_bt_utp_extension, tvb, offset, -1, ENC_NA);
|
2011-04-19 15:23:51 +00:00
|
|
|
ext_tree = proto_item_add_subtree(ti, ett_bt_utp_extension);
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_next_extension_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
*extension_type = tvb_get_guint8(tvb, offset);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += 1;
|
2011-04-19 16:37:39 +00:00
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_extension_len, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-19 16:37:39 +00:00
|
|
|
extension_length = tvb_get_guint8(tvb, offset);
|
2011-04-19 15:23:51 +00:00
|
|
|
proto_item_append_text(ti, " Extension Bits, Len=%d", extension_length);
|
|
|
|
offset += 1;
|
2011-04-19 16:37:39 +00:00
|
|
|
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_extension_bitmask, tvb, offset, extension_length, ENC_NA);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += extension_length;
|
|
|
|
proto_item_set_len(ti, 1 + 1 + extension_length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-10-04 22:44:31 +00:00
|
|
|
ti = proto_tree_add_item(tree, hf_bt_utp_extension, tvb, offset, -1, ENC_NA);
|
2011-04-19 15:23:51 +00:00
|
|
|
ext_tree = proto_item_add_subtree(ti, ett_bt_utp_extension);
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_next_extension_type, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-22 13:16:45 +00:00
|
|
|
*extension_type = tvb_get_guint8(tvb, offset);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += 1;
|
2011-04-19 16:37:39 +00:00
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_extension_len, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2011-04-19 15:23:51 +00:00
|
|
|
extension_length = tvb_get_guint8(tvb, offset);
|
2011-04-19 16:37:39 +00:00
|
|
|
proto_item_append_text(ti, " Unknown, Len=%d", extension_length);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += 1;
|
|
|
|
|
2011-10-04 22:44:31 +00:00
|
|
|
proto_tree_add_item(ext_tree, hf_bt_utp_extension_unknown, tvb, offset, extension_length, ENC_NA);
|
2011-04-19 15:23:51 +00:00
|
|
|
offset += extension_length;
|
|
|
|
proto_item_set_len(ti, 1 + 1 + extension_length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-09-10 21:40:21 +00:00
|
|
|
dissect_bt_utp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
|
2011-04-19 15:23:51 +00:00
|
|
|
{
|
2012-12-04 17:47:07 +00:00
|
|
|
gint version;
|
|
|
|
version = get_utp_version(tvb);
|
2011-04-20 17:25:07 +00:00
|
|
|
|
2012-02-05 13:51:50 +00:00
|
|
|
/* try dissecting */
|
2012-12-16 00:28:38 +00:00
|
|
|
if (version >= 0)
|
2011-04-19 15:23:51 +00:00
|
|
|
{
|
2012-12-04 17:47:07 +00:00
|
|
|
conversation_t *conversation;
|
2012-12-04 19:52:01 +00:00
|
|
|
guint len_tvb;
|
2012-02-05 13:51:50 +00:00
|
|
|
proto_tree *sub_tree = NULL;
|
2012-12-04 17:47:07 +00:00
|
|
|
proto_item *ti;
|
|
|
|
gint offset = 0;
|
2012-02-05 13:51:50 +00:00
|
|
|
guint8 extension_type;
|
|
|
|
|
|
|
|
conversation = find_or_create_conversation(pinfo);
|
|
|
|
conversation_set_dissector(conversation, bt_utp_handle);
|
|
|
|
|
|
|
|
/* set the protocol column */
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "BT-uTP");
|
|
|
|
/* set the info column */
|
|
|
|
col_set_str( pinfo->cinfo, COL_INFO, "uTorrent Transport Protocol" );
|
|
|
|
|
2012-12-04 19:52:01 +00:00
|
|
|
len_tvb = tvb_reported_length(tvb);
|
2012-12-04 17:47:07 +00:00
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_bt_utp, tvb, 0, -1,
|
|
|
|
"uTorrent Transport Protocol V%d (%d bytes)",
|
2012-12-04 19:52:01 +00:00
|
|
|
version, len_tvb);
|
2012-12-04 17:47:07 +00:00
|
|
|
sub_tree = proto_item_add_subtree(ti, ett_bt_utp);
|
2011-04-20 17:25:07 +00:00
|
|
|
|
2012-02-05 13:51:50 +00:00
|
|
|
/* Determine header version */
|
2011-04-22 13:16:45 +00:00
|
|
|
|
2012-12-04 17:47:07 +00:00
|
|
|
if (version == 0) {
|
|
|
|
offset = dissect_utp_header_v0(tvb, pinfo, sub_tree, offset, &extension_type);
|
2012-02-05 13:51:50 +00:00
|
|
|
} else {
|
2012-12-04 17:47:07 +00:00
|
|
|
offset = dissect_utp_header_v1(tvb, pinfo, sub_tree, offset, &extension_type);
|
2012-02-05 13:51:50 +00:00
|
|
|
}
|
2011-10-28 14:49:31 +00:00
|
|
|
|
2012-12-04 17:47:07 +00:00
|
|
|
offset = dissect_utp_extension(tvb, pinfo, sub_tree, offset, &extension_type);
|
2011-10-28 14:49:31 +00:00
|
|
|
|
2015-06-22 21:40:23 +00:00
|
|
|
len_tvb = tvb_captured_length_remaining(tvb, offset);
|
2012-12-04 19:52:01 +00:00
|
|
|
if(len_tvb > 0)
|
|
|
|
proto_tree_add_item(sub_tree, hf_bt_utp_data, tvb, offset, len_tvb, ENC_NA);
|
2012-12-04 17:47:07 +00:00
|
|
|
|
2012-12-04 19:52:01 +00:00
|
|
|
return offset+len_tvb;
|
2012-02-05 13:51:50 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2011-10-28 14:49:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-19 15:23:51 +00:00
|
|
|
void
|
|
|
|
proto_register_bt_utp(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_bt_utp_ver,
|
|
|
|
{ "Version", "bt-utp.ver",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0F,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2011-04-20 20:32:26 +00:00
|
|
|
{ &hf_bt_utp_flags,
|
|
|
|
{ "Flags", "bt-utp.flags",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(bt_utp_type_vals), 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2011-04-19 15:23:51 +00:00
|
|
|
{ &hf_bt_utp_type,
|
|
|
|
{ "Type", "bt-utp.type",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(bt_utp_type_vals), 0xF0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_extension,
|
|
|
|
{ "Extension", "bt-utp.extension",
|
|
|
|
FT_NONE, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_next_extension_type,
|
|
|
|
{ "Next Extension Type", "bt-utp.next_extension_type",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(bt_utp_extension_type_vals), 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_extension_len,
|
|
|
|
{ "Extension Length", "bt-utp.extension_len",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_extension_bitmask,
|
|
|
|
{ "Extension Bitmask", "bt-utp.extension_bitmask",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_extension_unknown,
|
|
|
|
{ "Extension Unknown", "bt-utp.extension_unknown",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2011-04-20 20:32:26 +00:00
|
|
|
{ &hf_bt_utp_connection_id_v0,
|
|
|
|
{ "Connection ID", "bt-utp.connection_id",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_connection_id_v1,
|
2011-04-19 15:23:51 +00:00
|
|
|
{ "Connection ID", "bt-utp.connection_id",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2011-04-20 20:32:26 +00:00
|
|
|
{ &hf_bt_utp_timestamp_sec,
|
|
|
|
{ "Timestamp seconds", "bt-utp.timestamp_sec",
|
2011-04-19 15:23:51 +00:00
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2011-04-20 20:32:26 +00:00
|
|
|
{ &hf_bt_utp_timestamp_us,
|
|
|
|
{ "Timestamp Microseconds", "bt-utp.timestamp_us",
|
2011-04-19 15:23:51 +00:00
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2011-04-20 20:32:26 +00:00
|
|
|
{ &hf_bt_utp_timestamp_diff_us,
|
|
|
|
{ "Timestamp Difference Microseconds", "bt-utp.timestamp_diff_us",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_wnd_size_v0,
|
|
|
|
{ "Windows Size", "bt-utp.wnd_size",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_wnd_size_v1,
|
2011-04-19 15:23:51 +00:00
|
|
|
{ "Windows Size", "bt-utp.wnd_size",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_seq_nr,
|
2012-12-04 17:47:07 +00:00
|
|
|
{ "Sequence number", "bt-utp.seq_nr",
|
2011-04-19 15:23:51 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
|
|
|
{ &hf_bt_utp_ack_nr,
|
2012-12-04 17:47:07 +00:00
|
|
|
{ "ACK number", "bt-utp.ack_nr",
|
2011-04-19 15:23:51 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2012-12-04 17:47:07 +00:00
|
|
|
{ &hf_bt_utp_data,
|
|
|
|
{ "Data", "bt-utp.data",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
|
|
|
NULL, HFILL }
|
|
|
|
},
|
2011-04-19 15:23:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup protocol subtree array */
|
|
|
|
static gint *ett[] = { &ett_bt_utp, &ett_bt_utp_extension };
|
|
|
|
|
2012-12-16 00:28:38 +00:00
|
|
|
module_t *bt_utp_module;
|
|
|
|
|
2011-04-19 15:23:51 +00:00
|
|
|
/* Register protocol */
|
2016-10-05 20:33:54 +00:00
|
|
|
proto_bt_utp = proto_register_protocol ("uTorrent Transport Protocol", "BT-uTP", "bt-utp");
|
2011-04-19 15:23:51 +00:00
|
|
|
|
2016-10-05 20:33:54 +00:00
|
|
|
bt_utp_module = prefs_register_protocol(proto_bt_utp, NULL);
|
2015-07-13 00:40:31 +00:00
|
|
|
prefs_register_obsolete_preference(bt_utp_module, "enable");
|
2012-12-16 00:28:38 +00:00
|
|
|
|
2011-04-19 15:23:51 +00:00
|
|
|
proto_register_field_array(proto_bt_utp, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_bt_utp(void)
|
|
|
|
{
|
2016-10-05 20:33:54 +00:00
|
|
|
/* disabled by default since heuristic is weak */
|
|
|
|
heur_dissector_add("udp", dissect_bt_utp, "BitTorrent UTP over UDP", "bt_utp_udp", proto_bt_utp, HEURISTIC_DISABLE);
|
2012-12-16 00:28:38 +00:00
|
|
|
|
2016-10-05 20:33:54 +00:00
|
|
|
bt_utp_handle = create_dissector_handle(dissect_bt_utp, proto_bt_utp);
|
|
|
|
dissector_add_for_decode_as_with_preference("udp.port", bt_utp_handle);
|
2011-04-19 15:23:51 +00:00
|
|
|
}
|
2012-12-16 00:28:38 +00:00
|
|
|
|
2011-04-19 15:23:51 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
2011-09-21 17:49:11 +00:00
|
|
|
* ex: set shiftwidth=2 tabstop=8 expandtab:
|
2011-04-19 15:23:51 +00:00
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|
2011-04-19 16:37:39 +00:00
|
|
|
|