diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2013-12-23 16:55:11 -0800 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2013-12-23 16:55:11 -0800 |
commit | 177eb4837ce0d2815cbda527e7c3081559b30dd9 (patch) | |
tree | d5761d45dde33add2eba8d32d507682628e62789 /monitor | |
parent | 670de1db48960dc4c497da6964072884b868b16a (diff) | |
download | bluez-177eb4837ce0d2815cbda527e7c3081559b30dd9.tar.gz |
monitor: Decode vendor and product information from Device ID
Diffstat (limited to 'monitor')
-rw-r--r-- | monitor/hwdb.c | 84 | ||||
-rw-r--r-- | monitor/hwdb.h | 27 | ||||
-rw-r--r-- | monitor/packet.c | 37 |
3 files changed, 141 insertions, 7 deletions
diff --git a/monitor/hwdb.c b/monitor/hwdb.c new file mode 100644 index 000000000..c79e55499 --- /dev/null +++ b/monitor/hwdb.c @@ -0,0 +1,84 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2011-2012 Intel Corporation + * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org> + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> + +#include "hwdb.h" + +#ifdef HAVE_UDEV_HWDB_NEW +#include <libudev.h> + +bool hwdb_get_vendor_model(const char *modalias, char **vendor, char **model) +{ + struct udev *udev; + struct udev_hwdb *hwdb; + struct udev_list_entry *head, *entry; + bool result; + + udev = udev_new(); + if (!udev) + return false; + + hwdb = udev_hwdb_new(udev); + if (!hwdb) { + result = false; + goto done; + } + + *vendor = NULL; + *model = NULL; + + head = udev_hwdb_get_properties_list_entry(hwdb, modalias, 0); + + udev_list_entry_foreach(entry, head) { + const char *name = udev_list_entry_get_name(entry); + + if (!name) + continue; + + if (!*vendor && !strcmp(name, "ID_VENDOR_FROM_DATABASE")) + *vendor = strdup(udev_list_entry_get_value(entry)); + else if (!*model && !strcmp(name, "ID_MODEL_FROM_DATABASE")) + *model = strdup(udev_list_entry_get_value(entry)); + } + + hwdb = udev_hwdb_unref(hwdb); + + result = true; + +done: + udev = udev_unref(udev); + + return result; +} +#else +bool hwdb_get_vendor_model(const char *modalias, char **vendor, char **model) +{ + return false; +} +#endif diff --git a/monitor/hwdb.h b/monitor/hwdb.h new file mode 100644 index 000000000..8cf6571ed --- /dev/null +++ b/monitor/hwdb.h @@ -0,0 +1,27 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2011-2012 Intel Corporation + * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org> + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <stdbool.h> + +bool hwdb_get_vendor_model(const char *modalias, char **vendor, char **model); diff --git a/monitor/packet.c b/monitor/packet.c index 3614a4d14..2e56f8382 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -44,6 +44,7 @@ #include "display.h" #include "bt.h" #include "ll.h" +#include "hwdb.h" #include "uuid.h" #include "l2cap.h" #include "control.h" @@ -2445,41 +2446,63 @@ static void print_manufacturer_data(const void *data, uint8_t data_len) static void print_device_id(const void *data, uint8_t data_len) { - uint16_t source, version; + uint16_t source, vendor, product, version; + char modalias[26], *vendor_str, *product_str; const char *str; if (data_len < 8) return; source = bt_get_le16(data); + vendor = bt_get_le16(data + 2); + product = bt_get_le16(data + 4); + version = bt_get_le16(data + 6); switch (source) { case 0x0001: str = "Bluetooth SIG assigned"; + sprintf(modalias, "bluetooth:v%04Xp%04Xd%04X", + vendor, product, version); break; case 0x0002: str = "USB Implementer's Forum assigned"; + sprintf(modalias, "usb:v%04Xp%04Xd%04X", + vendor, product, version); break; default: str = "Reserved"; + modalias[0] = '\0'; break; } print_field("Device ID: %s (0x%4.4x)", str, source); - if (source == 0x0001) - packet_print_company(" Vendor", bt_get_le16(data + 2)); - else - print_field(" Vendor: 0x%4.4x", bt_get_le16(data + 2)); + if (!hwdb_get_vendor_model(modalias, &vendor_str, &product_str)) { + vendor_str = NULL; + product_str = NULL; + } - print_field(" Product: 0x%4.4x", bt_get_le16(data + 4)); + if (source != 0x0001) { + if (vendor_str) + print_field(" Vendor: %s (0x%4.4x)", + vendor_str, vendor); + else + print_field(" Vendor: 0x%4.4x", vendor); + } else + packet_print_company(" Vendor", vendor); - version = bt_get_le16(data + 6); + if (product_str) + print_field(" Product: %s (0x%4.4x)", product_str, product); + else + print_field(" Product: 0x%4.4x", product); print_field(" Version: %u.%u.%u (0x%4.4x)", (version & 0xff00) >> 8, (version & 0x00f0) >> 4, (version & 0x000f), version); + + free(vendor_str); + free(product_str); } static void print_uuid16_list(const char *label, const void *data, |