aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2012-04-30 21:33:30 -0300
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-21 18:00:18 -0300
commita4e905acf96120a04a7f1eac3f453b45fea6e319 (patch)
tree9251737ce2a1f1738da25370639be9fd9b968d20
parentf7f467e2bb3be971a0d93b29d64951a943a72dfc (diff)
downloadbluez-a4e905acf96120a04a7f1eac3f453b45fea6e319.tar.gz
bluez-a4e905acf96120a04a7f1eac3f453b45fea6e319.tar.xz
bluez-a4e905acf96120a04a7f1eac3f453b45fea6e319.zip
hog: Add HID Information Characteristic read
This patch adds the characteristic value read for HID Information Characteristic. It's information contains HID Device's HID Attributes.
-rw-r--r--input/hog_device.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/input/hog_device.c b/input/hog_device.c
index 3876d98c..24728065 100644
--- a/input/hog_device.c
+++ b/input/hog_device.c
@@ -51,6 +51,7 @@
#include "attio.h"
#include "gatt.h"
+#define HOG_INFO_UUID 0x2A4A
#define HOG_REPORT_MAP_UUID 0x2A4B
#define HOG_REPORT_UUID 0x2A4D
@@ -61,6 +62,7 @@
#define UHID_DEVICE_FILE "/dev/uhid"
#define HOG_REPORT_MAP_MAX_SIZE 512
+#define HID_INFO_SIZE 4
#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
@@ -77,6 +79,9 @@ struct hog_device {
int uhid_fd;
gboolean prepend_id;
guint uhid_watch_id;
+ uint16_t bcdhid;
+ uint8_t bcountrycode;
+ uint8_t flags;
};
struct report {
@@ -300,10 +305,37 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
error("Failed to create uHID device: %s", strerror(errno));
}
+static void info_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
+ gpointer user_data)
+{
+ struct hog_device *hogdev = user_data;
+ uint8_t value[HID_INFO_SIZE];
+ ssize_t vlen;
+
+ if (status != 0) {
+ error("HID Information read failed: %s",
+ att_ecode2str(status));
+ return;
+ }
+
+ vlen = dec_read_resp(pdu, plen, value, sizeof(value));
+ if (vlen != 5) {
+ error("ATT protocol error");
+ return;
+ }
+
+ hogdev->bcdhid = att_get_u16(&value[0]);
+ hogdev->bcountrycode = value[2];
+ hogdev->flags = value[3];
+
+ DBG("bcdHID: 0x%04X bCountryCode: 0x%02X Flags: 0x%02X",
+ hogdev->bcdhid, hogdev->bcountrycode, hogdev->flags);
+}
+
static void char_discovered_cb(GSList *chars, guint8 status, gpointer user_data)
{
struct hog_device *hogdev = user_data;
- bt_uuid_t report_uuid, report_map_uuid;
+ bt_uuid_t report_uuid, report_map_uuid, info_uuid;
struct report *report;
GSList *l;
@@ -315,6 +347,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);
+ bt_uuid16_create(&info_uuid, HOG_INFO_UUID);
for (l = chars; l; l = g_slist_next(l)) {
struct gatt_char *chr, *next;
@@ -338,6 +371,9 @@ static void char_discovered_cb(GSList *chars, guint8 status, gpointer user_data)
} else if (bt_uuid_cmp(&uuid, &report_map_uuid) == 0)
gatt_read_char(hogdev->attrib, chr->value_handle, 0,
report_map_read_cb, hogdev);
+ else if (bt_uuid_cmp(&uuid, &info_uuid) == 0)
+ gatt_read_char(hogdev->attrib, chr->value_handle, 0,
+ info_read_cb, hogdev);
}
}