[gnome-bluetooth] lib: Add helper to deduce type from appearance
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth] lib: Add helper to deduce type from appearance
- Date: Fri, 3 Nov 2017 17:02:17 +0000 (UTC)
commit 6721b84257ce2782b161286b45fb80a50f8e0c98
Author: Bastien Nocera <hadess hadess net>
Date: Fri Nov 3 16:45:12 2017 +0100
lib: Add helper to deduce type from appearance
Bluetooth LE devices use the Appearance GAP attribute, instead of a
device class. Add support for it so that Bluetooth LE devices are
properly typed and with the correct icons.
lib/bluetooth-utils.c | 44 +++++++++++++++++++++++++++++++++++++++++++
lib/bluetooth-utils.h | 1 +
lib/gnome-bluetooth.symbols | 1 +
3 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/lib/bluetooth-utils.c b/lib/bluetooth-utils.c
index fa7f41a..62bd53c 100644
--- a/lib/bluetooth-utils.c
+++ b/lib/bluetooth-utils.c
@@ -236,6 +236,50 @@ bluetooth_class_to_type (guint32 class)
return 0;
}
+/**
+ * bluetooth_appearance_to_type:
+ * @appearance: a Bluetooth device appearance
+ *
+ * Returns the type of device corresponding to the given @appearance value,
+ * as usually found in the GAP service.
+ *
+ * Return value: a #BluetoothType.
+ **/
+BluetoothType
+bluetooth_appearance_to_type (guint16 appearance)
+{
+ switch ((appearance & 0xffc0) >> 6) {
+ case 0x01:
+ return BLUETOOTH_TYPE_PHONE;
+ case 0x02:
+ return BLUETOOTH_TYPE_COMPUTER;
+ case 0x05:
+ return BLUETOOTH_TYPE_DISPLAY;
+ case 0x0a:
+ return BLUETOOTH_TYPE_OTHER_AUDIO;
+ case 0x0b:
+ return BLUETOOTH_TYPE_SCANNER;
+ case 0x0f: /* HID Generic */
+ switch (appearance & 0x3f) {
+ case 0x01:
+ return BLUETOOTH_TYPE_KEYBOARD;
+ case 0x02:
+ return BLUETOOTH_TYPE_MOUSE;
+ case 0x03:
+ case 0x04:
+ return BLUETOOTH_TYPE_JOYPAD;
+ case 0x05:
+ return BLUETOOTH_TYPE_TABLET;
+ case 0x08:
+ return BLUETOOTH_TYPE_SCANNER;
+ }
+ break;
+ }
+
+ return 0;
+
+}
+
static const char *
uuid16_custom_to_string (guint uuid16, const char *uuid)
{
diff --git a/lib/bluetooth-utils.h b/lib/bluetooth-utils.h
index f78b950..a5108dd 100644
--- a/lib/bluetooth-utils.h
+++ b/lib/bluetooth-utils.h
@@ -61,6 +61,7 @@ G_BEGIN_DECLS
#define BLUETOOTH_UUID_VDP_SOURCE 0x1303
BluetoothType bluetooth_class_to_type (guint32 class);
+BluetoothType bluetooth_appearance_to_type (guint16 appearance);
const gchar *bluetooth_type_to_string (guint type);
const gchar *bluetooth_type_to_filter_string (guint type);
gboolean bluetooth_verify_address (const char *bdaddr);
diff --git a/lib/gnome-bluetooth.symbols b/lib/gnome-bluetooth.symbols
index 21f99e2..9866ce1 100644
--- a/lib/gnome-bluetooth.symbols
+++ b/lib/gnome-bluetooth.symbols
@@ -29,6 +29,7 @@ bluetooth_client_connect_service
bluetooth_client_connect_service_finish
bluetooth_client_set_trusted
bluetooth_client_get_device
+bluetooth_appearance_to_type
bluetooth_class_to_type
bluetooth_type_to_string
bluetooth_type_to_filter_string
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]