Commit a9010063 authored by Michal Labedzki's avatar Michal Labedzki
Browse files

Bluetooth: Add ability to add custom UUID description

Some vendors use UUID128 as own services/attributes.
Sometimes they use UUID16 for it too. Support both cases.

Change-Id: I001692b94fcc2f86eafa81012790e9134b0f2a36
Reviewed-on: https://code.wireshark.org/review/11976

Reviewed-by: default avatarMichal Labedzki <michal.labedzki@tieto.com>
parent c4424644
......@@ -73,7 +73,6 @@ libwireshark.so.0 libwireshark0 #MINVER#
ber_decode_as_foreach@Base 1.9.1
ber_set_filename@Base 1.9.1
bluetooth_company_id_vals_ext@Base 1.99.6
bluetooth_uuid_custom@Base 1.99.2
bluetooth_uuid_vals@Base 1.99.2
bluetooth_uuid_vals_ext@Base 1.99.2
bssgp_cause_vals_ext@Base 1.9.1
......@@ -939,6 +938,8 @@ libwireshark.so.0 libwireshark0 #MINVER#
print_stream_ps_stdio_new@Base 1.12.0~rc1
print_stream_text_new@Base 1.12.0~rc1
print_stream_text_stdio_new@Base 1.12.0~rc1
print_uuid@Base 2.0.0
print_numeric_uuid@Base 2.0.0
process_reassembled_data@Base 1.9.1
process_stat_cmd_arg@Base 1.9.1
proto_all_finfos@Base 1.9.1
......
......@@ -60,6 +60,8 @@ static wmem_tree_t *localhost_name = NULL;
static wmem_tree_t *localhost_bdaddr = NULL;
static wmem_tree_t *hci_vendors = NULL;
wmem_tree_t *bluetooth_uuids = NULL;
static int bluetooth_tap = -1;
int bluetooth_device_tap = -1;
int bluetooth_hci_summary_tap = -1;
......@@ -579,20 +581,6 @@ const value_string bluetooth_uuid_vals[] = {
};
value_string_ext bluetooth_uuid_vals_ext = VALUE_STRING_EXT_INIT(bluetooth_uuid_vals);
const bluetooth_uuid_custom_t bluetooth_uuid_custom[] = {
{ {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x02}, 16, "SyncML Server" },
{ {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x02}, 16, "SyncML Client" },
{ {0x6E, 0x40, 0x00, 0x01, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E}, 16, "Nordic UART Service" },
{ {0x6E, 0x40, 0x00, 0x02, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E}, 16, "Nordic UART Tx" },
{ {0x6E, 0x40, 0x00, 0x03, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E}, 16, "Nordic UART Rx" },
{ {0x00, 0x00, 0x15, 0x30, 0x12, 0x12, 0xEF, 0xDE, 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23}, 16, "Nordic DFU Service" },
{ {0x00, 0x00, 0x15, 0x31, 0x12, 0x12, 0xEF, 0xDE, 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23}, 16, "Nordic DFU Control Point" },
{ {0x00, 0x00, 0x15, 0x32, 0x12, 0x12, 0xEF, 0xDE, 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23}, 16, "Nordic DFU Packet" },
{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, NULL},
};
/* Taken from https://www.bluetooth.org/technical/assignednumbers/identifiers.htm */
static const value_string bluetooth_company_id_vals[] = {
{0x0000, "Ericsson Technology Licensing"},
......@@ -1318,33 +1306,26 @@ print_numeric_uuid(bluetooth_uuid_t *uuid)
gchar *
print_uuid(bluetooth_uuid_t *uuid)
{
if (uuid->bt_uuid) {
return wmem_strdup(wmem_packet_scope(), val_to_str_ext_const(uuid->bt_uuid, &bluetooth_uuid_vals_ext, "Unknown"));
} else {
guint i_uuid;
gchar *description;
gchar *description;
i_uuid = 0;
while (bluetooth_uuid_custom[i_uuid].name) {
if (bluetooth_uuid_custom[i_uuid].size != uuid->size) {
i_uuid += 1;
continue;
}
if (uuid->bt_uuid) {
gchar *name;
if (memcmp(uuid->data, bluetooth_uuid_custom[i_uuid].uuid, uuid->size) == 0) {
return wmem_strdup(wmem_packet_scope(), bluetooth_uuid_custom[i_uuid].name);
}
name = wmem_strdup(wmem_packet_scope(), val_to_str_ext_const(uuid->bt_uuid, &bluetooth_uuid_vals_ext, "Unknown"));
i_uuid += 1;
}
if (strcmp(name , "Unknown"))
return name;
}
description = print_numeric_uuid(uuid);
description = print_numeric_uuid(uuid);
if (description) {
description = (gchar *) wmem_tree_lookup_string(bluetooth_uuids, description, 0);
if (description)
return description;
else
return (gchar *) "Unknown";
}
return (gchar *) "Unknown";
}
static bluetooth_data_t *
......@@ -1621,6 +1602,7 @@ proto_register_bluetooth(void)
hci_vendors = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
hci_vendor_table = register_dissector_table("bluetooth.vendor", "HCI Vendor", FT_UINT16, BASE_HEX, DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE);
bluetooth_uuids = wmem_tree_new(wmem_epan_scope());
bluetooth_tap = register_tap("bluetooth");
bluetooth_device_tap = register_tap("bluetooth.device");
......@@ -1666,6 +1648,10 @@ proto_reg_handoff_bluetooth(void)
dissector_add_uint("usb.protocol", 0xE00104, bluetooth_usb_handle);
dissector_add_for_decode_as("usb.device", bluetooth_usb_handle);
wmem_tree_insert_string(bluetooth_uuids, "00000001-0000-1000-8000-0002EE000002", (gchar *) "SyncML Server", 0);
wmem_tree_insert_string(bluetooth_uuids, "00000002-0000-1000-8000-0002EE000002", (gchar *) "SyncML Client", 0);
/* TODO: Add UUID128 verion of UUID16; UUID32? UUID16? */
}
/*
......
......@@ -190,12 +190,6 @@ typedef struct _uuid_t {
guint8 data[16];
} bluetooth_uuid_t;
typedef struct _bluetooth_uuid_custom {
const guint8 uuid[16];
const guint8 size;
const gchar *name;
} bluetooth_uuid_custom_t;
enum bluetooth_device_type {
BLUETOOTH_DEVICE_BD_ADDR,
BLUETOOTH_DEVICE_NAME,
......@@ -261,10 +255,11 @@ extern int bluetooth_device_tap;
extern int bluetooth_hci_summary_tap;
WS_DLL_PUBLIC const value_string bluetooth_uuid_vals[];
WS_DLL_PUBLIC const bluetooth_uuid_custom_t bluetooth_uuid_custom[];
extern dissector_table_t bluetooth_uuid_table;
WS_DLL_PUBLIC wmem_tree_t *bluetooth_uuids;
WS_DLL_PUBLIC value_string_ext bluetooth_uuid_vals_ext;
WS_DLL_PUBLIC value_string_ext bluetooth_company_id_vals_ext;
extern guint32 max_disconnect_in_frame;
......@@ -274,8 +269,8 @@ extern gint dissect_bd_addr(gint hf_bd_addr, packet_info *pinfo, proto_tree *tre
guint32 interface_id, guint32 adapter_id, guint8 *bdaddr);
extern bluetooth_uuid_t get_uuid(tvbuff_t *tvb, gint offset, gint size);
extern gchar *print_uuid(bluetooth_uuid_t *uuid);
extern gchar *print_numeric_uuid(bluetooth_uuid_t *uuid);
WS_DLL_PUBLIC gchar *print_uuid(bluetooth_uuid_t *uuid);
WS_DLL_PUBLIC gchar *print_numeric_uuid(bluetooth_uuid_t *uuid);
extern void save_local_device_name_from_eir_ad(tvbuff_t *tvb, gint offset,
packet_info *pinfo, guint8 size, bluetooth_data_t *bluetooth_data);
......
......@@ -10799,8 +10799,10 @@ proto_reg_handoff_btgatt(void)
int (*dissect_func)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data);
} uuid_dissectors[] = {
{ "6e400001-b5a3-f393-e0a9-e50e24dcca9e", "Bluetooth GATT Nordic UART Service", "Nordic UART Service", "btgatt.nordic.uart", NULL},
{ "6e400002-b5a3-f393-e0a9-e50e24dcca9e", "Bluetooth GATT Nordic UART Tx", "Nordic UART Tx", "btgatt.nordic.uart_tx", dissect_btgatt_nordic_uart_tx},
{ "6e400003-b5a3-f393-e0a9-e50e24dcca9e", "Bluetooth GATT Nordic UART Rx", "Nordic UART Rx", "btgatt.nordic.uart_rx", dissect_btgatt_nordic_uart_rx},
{ "00001530-1212-efde-1523-785feabcd123", "Bluetooth GATT Nordic DFU Service", "Nordic DFU Service", "btgatt.nordic.dfu", NULL},
{ "00001531-1212-efde-1523-785feabcd123", "Bluetooth GATT Nordic DFU Control Point", "Nordic DFU Control Point", "btgatt.nordic.dfu.control_point", dissect_btgatt_nordic_dfu_control_point},
{ "00001532-1212-efde-1523-785feabcd123", "Bluetooth GATT Nordic DFU Packet", "Nordic DFU Packet", "btgatt.nordic.dfu.packet", dissect_btgatt_nordic_dfu_packet},
......@@ -10813,6 +10815,8 @@ proto_reg_handoff_btgatt(void)
dissector_handle_t handle_tmp;
gint proto_tmp;
wmem_tree_insert_string(bluetooth_uuids, uuid_dissectors[i_array].uuid, (gchar *) uuid_dissectors[i_array].short_name, 0);
if (!uuid_dissectors[i_array].dissect_func) {
i_array += 1;
continue;
......
......@@ -4889,7 +4889,6 @@ dissect_eir_ad_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bluetoo
guint8 type;
guint8 data_size;
gint64 end_offset;
guint i_uuid;
gboolean has_bd_addr = FALSE;
guint8 bd_addr[6];
guint8 *name = NULL;
......@@ -4945,22 +4944,12 @@ dissect_eir_ad_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bluetoo
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_uuid_32, tvb, offset, 4, ENC_BIG_ENDIAN);
proto_item_append_text(sub_item, " (%s)", val_to_str_ext_const(tvb_get_ntohs(tvb, offset + 2), &bluetooth_uuid_vals_ext, "Unknown"));
} else {
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 4, ENC_NA);
i_uuid = 0;
while (bluetooth_uuid_custom[i_uuid].name) {
if (bluetooth_uuid_custom[i_uuid].size != 4) {
i_uuid += 1;
continue;
}
bluetooth_uuid_t uuid;
if (tvb_memeql(tvb, offset, bluetooth_uuid_custom[i_uuid].uuid, 4) == 0) {
proto_item_append_text(sub_item, " (%s)", bluetooth_uuid_custom[i_uuid].name);
break;
}
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 4, ENC_NA);
uuid = get_uuid(tvb, offset, 4);
i_uuid += 1;
}
proto_item_append_text(sub_item, " (%s)", print_uuid(&uuid));
}
offset += 4;
......@@ -4978,22 +4967,12 @@ dissect_eir_ad_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bluetoo
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_uuid_128, tvb, offset, 16, ENC_NA);
proto_item_append_text(sub_item, " (%s)", val_to_str_ext_const(tvb_get_ntohs(tvb, offset + 2), &bluetooth_uuid_vals_ext, "Unknown"));
} else {
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 16, ENC_NA);
bluetooth_uuid_t uuid;
i_uuid = 0;
while (bluetooth_uuid_custom[i_uuid].name) {
if (bluetooth_uuid_custom[i_uuid].size != 16) {
i_uuid += 1;
continue;
}
if (tvb_memeql(tvb, offset, bluetooth_uuid_custom[i_uuid].uuid, 16) == 0) {
proto_item_append_text(sub_item, " (%s)", bluetooth_uuid_custom[i_uuid].name);
break;
}
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 16, ENC_NA);
uuid = get_uuid(tvb, offset, 16);
i_uuid += 1;
}
proto_item_append_text(sub_item, " (%s)", print_uuid(&uuid));
}
offset += 16;
......@@ -5120,22 +5099,12 @@ dissect_eir_ad_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bluetoo
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_uuid_32, tvb, offset, 4, ENC_BIG_ENDIAN);
proto_item_append_text(sub_item, " (%s)", val_to_str_ext_const(tvb_get_ntohs(tvb, offset + 2), &bluetooth_uuid_vals_ext, "Unknown"));
} else {
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 4, ENC_NA);
bluetooth_uuid_t uuid;
i_uuid = 0;
while (bluetooth_uuid_custom[i_uuid].name) {
if (bluetooth_uuid_custom[i_uuid].size != 4) {
i_uuid += 1;
continue;
}
if (tvb_memeql(tvb, offset, bluetooth_uuid_custom[i_uuid].uuid, 4) == 0) {
proto_item_append_text(sub_item, " (%s)", bluetooth_uuid_custom[i_uuid].name);
break;
}
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 4, ENC_NA);
uuid = get_uuid(tvb, offset, 4);
i_uuid += 1;
}
proto_item_append_text(sub_item, " (%s)", print_uuid(&uuid));
}
offset += 4;
......@@ -5151,22 +5120,12 @@ dissect_eir_ad_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bluetoo
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_uuid_128, tvb, offset, 16, ENC_NA);
proto_item_append_text(sub_item, " (%s)", val_to_str_ext_const(tvb_get_ntohs(tvb, offset + 2), &bluetooth_uuid_vals_ext, "Unknown"));
} else {
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 16, ENC_NA);
bluetooth_uuid_t uuid;
i_uuid = 0;
while (bluetooth_uuid_custom[i_uuid].name) {
if (bluetooth_uuid_custom[i_uuid].size != 16) {
i_uuid += 1;
continue;
}
if (tvb_memeql(tvb, offset, bluetooth_uuid_custom[i_uuid].uuid, 16) == 0) {
proto_item_append_text(sub_item, " (%s)", bluetooth_uuid_custom[i_uuid].name);
break;
}
sub_item = proto_tree_add_item(entry_tree, hf_btcommon_eir_ad_custom_uuid, tvb, offset, 16, ENC_NA);
uuid = get_uuid(tvb, offset, 16);
i_uuid += 1;
}
proto_item_append_text(sub_item, " (%s)", print_uuid(&uuid));
}
offset += 16;
......
......@@ -1367,23 +1367,12 @@ dissect_uuid(proto_tree *tree, tvbuff_t *tvb, gint offset, gint size, bluetooth_
uuid->bt_uuid = tvb_get_ntohs(tvb, offset + 2);
proto_item_append_text(item, " (%s)", val_to_str_ext_const(uuid->bt_uuid, &bluetooth_uuid_vals_ext, "Unknown"));
} else {
guint i_uuid;
item = proto_tree_add_item(tree, hf_data_element_value_uuid, tvb, offset, size, ENC_NA);
i_uuid = 0;
while (bluetooth_uuid_custom[i_uuid].name) {
if (bluetooth_uuid_custom[i_uuid].size != size) {
i_uuid += 1;
continue;
}
bluetooth_uuid_t x_uuid;
if (tvb_memeql(tvb, offset, bluetooth_uuid_custom[i_uuid].uuid, 4) == 0) {
proto_item_append_text(item, " (%s)", bluetooth_uuid_custom[i_uuid].name);
break;
}
item = proto_tree_add_item(tree, hf_data_element_value_uuid, tvb, offset, size, ENC_NA);
x_uuid = get_uuid(tvb, offset, size);
i_uuid += 1;
}
proto_item_append_text(item, " (%s)", print_uuid(&x_uuid));
uuid->bt_uuid = 0;
}
......
......@@ -40,61 +40,6 @@ static const int column_number_handle = 0;
static const int column_number_uuid = 1;
static const int column_number_uuid_name = 2;
static gchar *
bt_print_numeric_uuid(bluetooth_uuid_t *uuid)
{
if (!(uuid && uuid->size > 0))
return NULL;
if (uuid->size != 16) {
return bytes_to_str(wmem_packet_scope(), uuid->data, uuid->size);
} else {
gchar *text;
text = (gchar *) wmem_alloc(wmem_packet_scope(), 38);
bytes_to_hexstr(&text[0], uuid->data, 4);
text[8] = '-';
bytes_to_hexstr(&text[9], uuid->data + 4, 2);
text[13] = '-';
bytes_to_hexstr(&text[14], uuid->data + 4 + 2 * 1, 2);
text[18] = '-';
bytes_to_hexstr(&text[19], uuid->data + 4 + 2 * 2, 2);
text[23] = '-';
bytes_to_hexstr(&text[24], uuid->data + 4 + 2 * 3, 6);
text[36] = '\0';
return text;
}
return NULL;
}
static const gchar *
bt_print_uuid(bluetooth_uuid_t *uuid)
{
if (uuid->bt_uuid) {
return val_to_str_ext_const(uuid->bt_uuid, &bluetooth_uuid_vals_ext, "<Unknown>");
} else {
guint i_uuid;
i_uuid = 0;
while (bluetooth_uuid_custom[i_uuid].name) {
if (bluetooth_uuid_custom[i_uuid].size != uuid->size) {
i_uuid += 1;
continue;
}
if (memcmp(uuid->data, bluetooth_uuid_custom[i_uuid].uuid, uuid->size) == 0) {
return wmem_strdup(wmem_packet_scope(), bluetooth_uuid_custom[i_uuid].name);
}
i_uuid += 1;
}
return "<Unknown>";
}
}
static gboolean
btatt_handle_tap_packet(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *edt, const void* data)
{
......@@ -271,8 +216,8 @@ gboolean BluetoothAttServerAttributesDialog::tapPacket(void *tapinfo_ptr, packet
}
handle.sprintf("0x%04x", tap_handles->handle);
uuid = QString(bt_print_numeric_uuid(&tap_handles->uuid));
uuid_name = QString(bt_print_uuid(&tap_handles->uuid));
uuid = QString(print_numeric_uuid(&tap_handles->uuid));
uuid_name = QString(print_uuid(&tap_handles->uuid));
if (dialog->ui->removeDuplicatesCheckBox->checkState() == Qt::Checked) {
QTreeWidgetItemIterator i_item(dialog->ui->tableTreeWidget);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment