aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-03-23 10:49:28 -0300
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-20 18:32:48 -0300
commit3674422aa5d2fbb5358bb13a44cfc1403dbdbaed (patch)
treec3970f5d9d4472b8b1cb67124de34620bd719685
parentcc7e1f9adc6bb699b9648bcff5eef093aaa0311d (diff)
downloadbluez-3674422aa5d2fbb5358bb13a44cfc1403dbdbaed.tar.gz
bluez-3674422aa5d2fbb5358bb13a44cfc1403dbdbaed.tar.xz
bluez-3674422aa5d2fbb5358bb13a44cfc1403dbdbaed.zip
hog: Discover the "Report Map" characteristic
This characteristic contains the HID descriptor.
-rw-r--r--input/hog_device.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/input/hog_device.c b/input/hog_device.c
index cac66e25..574e6f39 100644
--- a/input/hog_device.c
+++ b/input/hog_device.c
@@ -47,8 +47,11 @@
#include "attio.h"
#include "gatt.h"
+#define HOG_REPORT_MAP_UUID 0x2A4B
#define HOG_REPORT_UUID 0x2A4D
+#define HOG_REPORT_MAP_MAX_SIZE 512
+
struct report {
struct gatt_char *decl;
};
@@ -113,10 +116,37 @@ static void discover_descriptor(GAttrib *attrib, struct gatt_char *chr,
gatt_find_info(attrib, start, end, discover_descriptor_cb, user_data);
}
+static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
+ gpointer user_data)
+{
+ uint8_t value[HOG_REPORT_MAP_MAX_SIZE];
+ ssize_t vlen;
+ int i;
+
+ if (status != 0) {
+ error("Report Map read failed: %s", att_ecode2str(status));
+ return;
+ }
+
+ vlen = dec_read_resp(pdu, plen, value, sizeof(value));
+ if (vlen < 0) {
+ error("ATT protocol error");
+ return;
+ }
+
+ DBG("Report MAP:");
+ for (i = 0; i < vlen; i += 2) {
+ if (i + 1 == vlen)
+ DBG("\t %02x", value[i]);
+ else
+ DBG("\t %02x %02x", value[i], value[i + 1]);
+ }
+}
+
static void char_discovered_cb(GSList *chars, guint8 status, gpointer user_data)
{
struct hog_device *hogdev = user_data;
- bt_uuid_t report_uuid;
+ bt_uuid_t report_uuid, report_map_uuid;
struct report *report;
GSList *l;
@@ -127,6 +157,7 @@ static void char_discovered_cb(GSList *chars, guint8 status, gpointer user_data)
}
bt_uuid16_create(&report_uuid, HOG_REPORT_UUID);
+ bt_uuid16_create(&report_map_uuid, HOG_REPORT_MAP_UUID);
for (l = chars; l; l = g_slist_next(l)) {
struct gatt_char *chr, *next;
@@ -140,14 +171,15 @@ static void char_discovered_cb(GSList *chars, guint8 status, gpointer user_data)
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);
-
- discover_descriptor(hogdev->attrib, chr, next, hogdev);
+ if (bt_uuid_cmp(&uuid, &report_uuid) == 0) {
+ report = g_new0(struct report, 1);
+ report->decl = g_memdup(chr, sizeof(*chr));
+ hogdev->reports = g_slist_append(hogdev->reports,
+ report);
+ discover_descriptor(hogdev->attrib, chr, next, hogdev);
+ } else if (bt_uuid_cmp(&uuid, &report_map_uuid) == 0)
+ gatt_read_char(hogdev->attrib, chr->value_handle, 0,
+ report_map_read_cb, hogdev);
}
}