Skip to contentSkip to conversation

android/hog: Cache report value

PATCH Applied Luiz Augusto von Dentz 1 participant 3 messages Jul 29, 2014 – Jul 31, 2014 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 android/hog: Cache report value

From: Luiz Augusto von Dentz <[email protected]>

Report value will be used for implementing support for UHID_FEATURE event.

---
 android/hog.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
android/hog.c +14 -1
index ef5690c..85a6982 100644
@@ -105,6 +105,8 @@ struct report {
 	uint16_t		ccc_handle;
 	guint			notifyid;
 	struct gatt_char	*decl;
+	uint16_t		len;
+	uint8_t			*value;
 };
 
 static void report_value_cb(const guint8 *pdu, guint16 len, gpointer user_data)
@@ -290,8 +292,18 @@ static void discover_report(GAttrib *attrib, uint16_t start, uint16_t end,
 static void report_read_cb(guint8 status, const guint8 *pdu, guint16 len,
 							gpointer user_data)
 {
-	if (status != 0)
+	struct report *report = user_data;
+
+	if (status != 0) {
 		error("Error reading Report value: %s", att_ecode2str(status));
+		return;
+	}
+
+	if (report->value)
+		g_free(report->value);
+
+	report->value = g_memdup(pdu, len);
+	report->len = len;
 }
 
 static struct report *report_new(struct bt_hog *hog, struct gatt_char *chr)
@@ -690,6 +702,7 @@ static void report_free(void *data)
 {
 	struct report *report = data;
 
+	g_free(report->value);
 	g_free(report->decl);
 	g_free(report);
 }
Signature · 1 line
1.9.3
author maintainer
#1 lore raw

PATCH 2/2 android/hog: Add support for UHID_FEATURE event

From: Luiz Augusto von Dentz <[email protected]>

---
 android/hog.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
android/hog.c +37 -0
index 85a6982..09a16d5 100644
@@ -439,6 +439,42 @@ static void forward_report(struct uhid_event *ev, void *user_data)
 						data, size, NULL, NULL);
 }
 
+static void get_report(struct uhid_event *ev, void *user_data)
+{
+	struct bt_hog *hog = user_data;
+	struct report *report;
+	GSList *l;
+	struct uhid_event rsp;
+	int err;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.type = UHID_FEATURE_ANSWER;
+	rsp.u.feature_answer.id = ev->u.feature.id;
+
+	l = g_slist_find_custom(hog->reports,
+				GUINT_TO_POINTER(ev->u.feature.rtype),
+				report_type_cmp);
+	if (!l) {
+		rsp.u.feature_answer.err = ENOTSUP;
+		goto done;
+	}
+
+	report = l->data;
+
+	if (!report->value) {
+		rsp.u.feature_answer.err = EIO;
+		goto done;
+	}
+
+	rsp.u.feature_answer.size = report->len;
+	memcpy(rsp.u.feature_answer.data, report->value, report->len);
+
+done:
+	err = bt_uhid_send(hog->uhid, &rsp);
+	if (err < 0)
+		error("bt_uhid_send: %s", strerror(-err));
+}
+
 static bool get_descriptor_item_info(uint8_t *buf, ssize_t blen, ssize_t *len,
 								bool *is_long)
 {
@@ -576,6 +612,7 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
 	}
 
 	bt_uhid_register(hog->uhid, UHID_OUTPUT, forward_report, hog);
+	bt_uhid_register(hog->uhid, UHID_FEATURE, get_report, hog);
 }
 
 static void info_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
Signature · 1 line
1.9.3
author maintainer Applied
#2 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 50 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Report value will be used for implementing support for UHID_FEATURE event.

---
 android/hog.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
android/hog.c +14 -2
index ef5690c..85a6982 100644
@@ -105,6 +105,8 @@ struct report {
        uint16_t                ccc_handle;
        guint                   notifyid;
        struct gatt_char        *decl;
+       uint16_t                len;
+       uint8_t                 *value;
 };
 
 static void report_value_cb(const guint8 *pdu, guint16 len, gpointer user_data)
@@ -290,8 +292,18 @@ static void discover_report(GAttrib *attrib, uint16_t start, uint16_t end,
 static void report_read_cb(guint8 status, const guint8 *pdu, guint16 len,
                                                        gpointer user_data)
 {
-       if (status != 0)
+       struct report *report = user_data;
+
+       if (status != 0) {
                error("Error reading Report value: %s", att_ecode2str(status));
+               return;
+       }
+
+       if (report->value)
+               g_free(report->value);
+
+       report->value = g_memdup(pdu, len);
+       report->len = len;
 }
 
 static struct report *report_new(struct bt_hog *hog, struct gatt_char *chr)
@@ -690,6 +702,7 @@ static void report_free(void *data)
 {
        struct report *report = data;
 
+       g_free(report->value);
        g_free(report->decl);
        g_free(report);
 }
--
Quoted 1 line

1.9.3

Applied.

Signature · 1 line
Luiz Augusto von Dentz