[PATCH 19/21] hog: Add HID Information Characteristic read

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Claudio Takahasi <claudio.takahasi@xxxxxxxxxxxxx>

This patch adds the characteristic value read for HID Information
Characteristic. It's information contains HID Device's HID Attributes.
---
 input/hog_device.c |   38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/input/hog_device.c b/input/hog_device.c
index 00127c3..778a367 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
 
 struct hog_device {
 	char			*path;
@@ -73,6 +75,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 {
@@ -296,10 +301,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 != 4) {
+		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;
 
@@ -311,6 +343,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;
@@ -334,6 +367,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);
 	}
 }
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux