diff --git a/epan/dissectors/packet-bluetooth.c b/epan/dissectors/packet-bluetooth.c index bff8e8d73b..fd25b5c13d 100644 --- a/epan/dissectors/packet-bluetooth.c +++ b/epan/dissectors/packet-bluetooth.c @@ -1251,10 +1251,30 @@ get_uuid(tvbuff_t *tvb, gint offset, gint size) } uuid.size = size; - tvb_memcpy(tvb, uuid.data, offset, size); + if (size == 2) { + uuid.data[0] = tvb_get_guint8(tvb, offset + 1); + uuid.data[1] = tvb_get_guint8(tvb, offset); + } else if (size == 16) { + uuid.data[0] = tvb_get_guint8(tvb, offset + 15); + uuid.data[1] = tvb_get_guint8(tvb, offset + 14); + uuid.data[2] = tvb_get_guint8(tvb, offset + 13); + uuid.data[3] = tvb_get_guint8(tvb, offset + 12); + uuid.data[4] = tvb_get_guint8(tvb, offset + 11); + uuid.data[5] = tvb_get_guint8(tvb, offset + 10); + uuid.data[6] = tvb_get_guint8(tvb, offset + 9); + uuid.data[7] = tvb_get_guint8(tvb, offset + 8); + uuid.data[8] = tvb_get_guint8(tvb, offset + 7); + uuid.data[9] = tvb_get_guint8(tvb, offset + 6); + uuid.data[10] = tvb_get_guint8(tvb, offset + 5); + uuid.data[11] = tvb_get_guint8(tvb, offset + 4); + uuid.data[12] = tvb_get_guint8(tvb, offset + 3); + uuid.data[13] = tvb_get_guint8(tvb, offset + 2); + uuid.data[14] = tvb_get_guint8(tvb, offset + 1); + uuid.data[15] = tvb_get_guint8(tvb, offset); + } if (size == 2) { - uuid.bt_uuid = uuid.data[0] | uuid.data[1] << 8; + uuid.bt_uuid = uuid.data[1] | uuid.data[0] << 8; } else { if (uuid.data[0] == 0x00 && uuid.data[1] == 0x00 && uuid.data[4] == 0x00 && uuid.data[5] == 0x00 && uuid.data[6] == 0x10 && @@ -1267,6 +1287,35 @@ get_uuid(tvbuff_t *tvb, gint offset, gint size) return uuid; } +gchar * +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; +} + gchar * print_uuid(bluetooth_uuid_t *uuid) { @@ -1289,20 +1338,10 @@ print_uuid(bluetooth_uuid_t *uuid) i_uuid += 1; } - return bytes_to_str(wmem_packet_scope(), uuid->data, uuid->size); + return print_numeric_uuid(uuid); } } -gchar * -print_numeric_uuid(bluetooth_uuid_t *uuid) -{ - if (uuid && uuid->size > 0) - return bytes_to_str(wmem_packet_scope(), uuid->data, uuid->size); - - return NULL; -} - - static bluetooth_data_t * dissect_bluetooth_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { diff --git a/epan/dissectors/packet-btatt.c b/epan/dissectors/packet-btatt.c index f107178388..c2b81bdebd 100644 --- a/epan/dissectors/packet-btatt.c +++ b/epan/dissectors/packet-btatt.c @@ -5773,8 +5773,8 @@ dissect_btgatt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) if (strlen(pinfo->current_proto) > 7) { uuid.size = 2; uuid.bt_uuid = (guint16) g_ascii_strtoull(pinfo->current_proto + strlen(pinfo->current_proto) - 7, NULL, 16); - uuid.data[0] = uuid.bt_uuid & 0xFF; - uuid.data[1] = (uuid.bt_uuid >> 8) & 0xFF; + uuid.data[1] = uuid.bt_uuid & 0xFF; + uuid.data[0] = (uuid.bt_uuid >> 8) & 0xFF; } else { uuid.size = 2; uuid.bt_uuid = 0; diff --git a/epan/to_str.h b/epan/to_str.h index 5582f16bd7..b89c9059f4 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -164,6 +164,9 @@ WS_DLL_PUBLIC char *bytes_to_str(wmem_allocator_t *scope, const guint8 *bd, int */ WS_DLL_PUBLIC const gchar *bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct); +WS_DLL_PUBLIC char * +bytes_to_hexstr(char *out, const guint8 *ad, guint32 len); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ui/qt/bluetooth_att_server_attributes_dialog.cpp b/ui/qt/bluetooth_att_server_attributes_dialog.cpp index 78312b5ef2..efe0af981b 100644 --- a/ui/qt/bluetooth_att_server_attributes_dialog.cpp +++ b/ui/qt/bluetooth_att_server_attributes_dialog.cpp @@ -40,12 +40,40 @@ 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"); + return val_to_str_ext_const(uuid->bt_uuid, &bluetooth_uuid_vals_ext, ""); } else { guint i_uuid; @@ -63,21 +91,10 @@ bt_print_uuid(bluetooth_uuid_t *uuid) i_uuid += 1; } - return bytes_to_str(wmem_packet_scope(), uuid->data, uuid->size); + return ""; } } - -static gchar * -bt_print_numeric_uuid(bluetooth_uuid_t *uuid) -{ - if (uuid && uuid->size > 0) - return bytes_to_str(wmem_packet_scope(), uuid->data, uuid->size); - - return NULL; -} - - static gboolean btatt_handle_tap_packet(void *tapinfo_ptr, packet_info *pinfo, epan_dissect_t *edt, const void* data) { @@ -254,7 +271,7 @@ gboolean BluetoothAttServerAttributesDialog::tapPacket(void *tapinfo_ptr, packet } handle.sprintf("0x%04x", tap_handles->handle); - uuid.sprintf("0x%s", bt_print_numeric_uuid(&tap_handles->uuid)); + uuid = QString(bt_print_numeric_uuid(&tap_handles->uuid)); uuid_name = QString(bt_print_uuid(&tap_handles->uuid)); if (dialog->ui->removeDuplicatesCheckBox->checkState() == Qt::Checked) {