aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-03-22 20:39:12 -0300
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-20 18:32:37 -0300
commit29fa677f9810ab18c569b30252fcacf5f41f3ed9 (patch)
tree9e2e9c85101316337ba444320532c33445a3712d
parenta6d92dcdb4feea953aeea5dec7f63a317b820193 (diff)
downloadbluez-29fa677f9810ab18c569b30252fcacf5f41f3ed9.tar.gz
bluez-29fa677f9810ab18c569b30252fcacf5f41f3ed9.tar.xz
bluez-29fa677f9810ab18c569b30252fcacf5f41f3ed9.zip
hog: Discover all characteristics declaration
HID service supports multiple report characteristic. Each report characteristic has a reference descriptor containing ID and type.
-rw-r--r--input/hog_device.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/input/hog_device.c b/input/hog_device.c
index 6ce05a9b..791550a7 100644
--- a/input/hog_device.c
+++ b/input/hog_device.c
@@ -47,21 +47,65 @@
#include "attio.h"
#include "gatt.h"
+#define HOG_REPORT_UUID 0x2A4D
+
+struct report {
+ struct gatt_char *decl;
+};
+
struct hog_device {
char *path;
struct btd_device *device;
GAttrib *attrib;
guint attioid;
struct gatt_primary *hog_primary;
+ GSList *reports;
};
static GSList *devices = NULL;
+static void char_discovered_cb(GSList *chars, guint8 status, gpointer user_data)
+{
+ struct hog_device *hogdev = user_data;
+ bt_uuid_t report_uuid;
+ struct report *report;
+ GSList *l;
+
+ if (status != 0) {
+ const char *str = att_ecode2str(status);
+ DBG("Discover all characteristics failed: %s", str);
+ return;
+ }
+
+ bt_uuid16_create(&report_uuid, HOG_REPORT_UUID);
+
+ for (l = chars; l; l = g_slist_next(l)) {
+ struct gatt_char *chr = l->data;
+ bt_uuid_t uuid;
+
+ DBG("0x%04x UUID: %s properties: %02x",
+ chr->handle, chr->uuid, chr->properties);
+
+ bt_string_to_uuid(&uuid, chr->uuid);
+
+ if (bt_uuid_cmp(&uuid, &report_uuid) != 0)
+ continue;
+
+ report = g_new0(struct report, 1);
+ report->decl = g_memdup(chr, sizeof(*chr));
+ hogdev->reports = g_slist_append(hogdev->reports, report);
+ }
+}
+
static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
{
struct hog_device *hogdev = user_data;
+ struct gatt_primary *prim = hogdev->hog_primary;
hogdev->attrib = g_attrib_ref(attrib);
+
+ gatt_discover_char(hogdev->attrib, prim->range.start, prim->range.end,
+ NULL, char_discovered_cb, hogdev);
}
static void attio_disconnected_cb(gpointer user_data)
@@ -148,9 +192,17 @@ int hog_device_register(struct btd_device *device, const char *path)
return 0;
}
+static void report_free(void *data)
+{
+ struct report *report = data;
+ g_free(report->decl);
+ g_free(report);
+}
+
static void hog_device_free(struct hog_device *hogdev)
{
btd_device_unref(hogdev->device);
+ g_slist_free_full(hogdev->reports, report_free);
g_free(hogdev->path);
g_free(hogdev->hog_primary);
g_free(hogdev);