linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables
@ 2014-08-07  9:03 Luiz Augusto von Dentz
  2014-08-07  9:03 ` [PATCH BlueZ 2/2] android/hog: Fix report lookup Luiz Augusto von Dentz
  2014-08-08 11:01 ` [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables Luiz Augusto von Dentz
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2014-08-07  9:03 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 profiles/input/hog.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index 30f9ed1..b9aba65 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -333,33 +333,30 @@ static void forward_report(struct uhid_event *ev, void *user_data)
 	struct report *report, cmp;
 	GSList *l;
 	uint8_t *data;
-	int size, type, id;
+	int size;
 
 	switch (ev->u.output.rtype) {
 	case UHID_FEATURE_REPORT:
-		type = HOG_REPORT_TYPE_FEATURE;
+		cmp.type = HOG_REPORT_TYPE_FEATURE;
 		break;
 	case UHID_OUTPUT_REPORT:
-		type = HOG_REPORT_TYPE_OUTPUT;
+		cmp.type = HOG_REPORT_TYPE_OUTPUT;
 		break;
 	case UHID_INPUT_REPORT:
-		type = HOG_REPORT_TYPE_INPUT;
+		cmp.type = HOG_REPORT_TYPE_INPUT;
 		break;
 	default:
 		return;
 	}
 
-	id = 0;
+	cmp.id = 0;
 	data = ev->u.output.data;
 	size = ev->u.output.size;
 	if (hogdev->has_report_id && size > 0) {
-		id = *data++;
+		cmp.id = *data++;
 		--size;
 	}
 
-	cmp.type = type;
-	cmp.id = id;
-
 	l = g_slist_find_custom(hogdev->reports, &cmp, report_cmp);
 	if (!l)
 		return;
@@ -367,7 +364,7 @@ static void forward_report(struct uhid_event *ev, void *user_data)
 	report = l->data;
 
 	DBG("Sending report type %d ID %d to device 0x%04X handle 0x%X",
-			type, id, hogdev->id, report->decl->value_handle);
+		cmp.type, cmp.id, hogdev->id, report->decl->value_handle);
 
 	if (hogdev->attrib == NULL)
 		return;
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH BlueZ 2/2] android/hog: Fix report lookup
  2014-08-07  9:03 [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables Luiz Augusto von Dentz
@ 2014-08-07  9:03 ` Luiz Augusto von Dentz
  2014-08-08 11:01 ` [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2014-08-07  9:03 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This fixes not utilizing the report id to match the characteristic that
map it.
---
 android/hog.c | 87 ++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 53 insertions(+), 34 deletions(-)

diff --git a/android/hog.c b/android/hog.c
index 09a16d5..51c7c64 100644
--- a/android/hog.c
+++ b/android/hog.c
@@ -382,12 +382,47 @@ static void external_report_reference_cb(guint8 status, const guint8 *pdu,
 					external_service_char_cb, hog);
 }
 
-static int report_type_cmp(gconstpointer a, gconstpointer b)
+
+static int report_cmp(gconstpointer a, gconstpointer b)
+{
+	const struct report *ra = a, *rb = b;
+
+	/* sort by type first.. */
+	if (ra->type != rb->type)
+		return ra->type - rb->type;
+
+	/* skip id check in case of report id 0 */
+	if (!rb->id)
+		return 0;
+
+	/* ..then by id */
+	return ra->id - rb->id;
+}
+
+static struct report *find_report(struct bt_hog *hog, uint8_t type, uint8_t id)
 {
-	const struct report *report = a;
-	uint8_t type = GPOINTER_TO_UINT(b);
+	struct report cmp;
+	GSList *l;
+
+	switch (type) {
+	case UHID_FEATURE_REPORT:
+		cmp.type = HOG_REPORT_TYPE_FEATURE;
+		break;
+	case UHID_OUTPUT_REPORT:
+		cmp.type = HOG_REPORT_TYPE_OUTPUT;
+		break;
+	case UHID_INPUT_REPORT:
+		cmp.type = HOG_REPORT_TYPE_INPUT;
+		break;
+	default:
+		return NULL;
+	}
+
+	cmp.id = hog->has_report_id ? id : 0;
 
-	return report->type - type;
+	l = g_slist_find_custom(hog->reports, &cmp, report_cmp);
+
+	return l ? l->data : NULL;
 }
 
 static void output_written_cb(guint8 status, const guint8 *pdu,
@@ -403,30 +438,22 @@ static void forward_report(struct uhid_event *ev, void *user_data)
 {
 	struct bt_hog *hog = user_data;
 	struct report *report;
-	GSList *l;
 	void *data;
 	int size;
-	guint type;
-
-	if (hog->has_report_id) {
-		data = ev->u.output.data + 1;
-		size = ev->u.output.size - 1;
-	} else {
-		data = ev->u.output.data;
-		size = ev->u.output.size;
-	}
 
-	type = HOG_REPORT_TYPE_OUTPUT;
-
-	l = g_slist_find_custom(hog->reports, GUINT_TO_POINTER(type),
-							report_type_cmp);
-	if (!l)
+	report = find_report(hog, ev->u.output.rtype, ev->u.output.data[0]);
+	if (!report)
 		return;
 
-	report = l->data;
+	data = ev->u.output.data;
+	size = ev->u.output.size;
+	if (hog->has_report_id && size > 0) {
+		data++;
+		--size;
+	}
 
-	DBG("Sending report type %d to handle 0x%X", type,
-						report->decl->value_handle);
+	DBG("Sending report type %d ID %d to handle 0x%X", report->type,
+				report->id, report->decl->value_handle);
 
 	if (hog->attrib == NULL)
 		return;
@@ -443,7 +470,6 @@ 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;
 
@@ -451,16 +477,12 @@ static void get_report(struct uhid_event *ev, void *user_data)
 	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) {
+	report = find_report(hog, ev->u.feature.rtype, ev->u.feature.rnum);
+	if (!report) {
 		rsp.u.feature_answer.err = ENOTSUP;
 		goto done;
 	}
 
-	report = l->data;
-
 	if (!report->value) {
 		rsp.u.feature_answer.err = EIO;
 		goto done;
@@ -1090,13 +1112,10 @@ int bt_hog_send_report(struct bt_hog *hog, void *data, size_t size, int type)
 	if (!hog->attrib)
 		return -ENOTCONN;
 
-	l = g_slist_find_custom(hog->reports, GUINT_TO_POINTER(type),
-							report_type_cmp);
-	if (!l)
+	report = find_report(hog, type, 0);
+	if (!report)
 		return -ENOTSUP;
 
-	report = l->data;
-
 	DBG("hog: Write report, handle 0x%X", report->decl->value_handle);
 
 	if (report->decl->properties & GATT_CHR_PROP_WRITE)
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables
  2014-08-07  9:03 [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables Luiz Augusto von Dentz
  2014-08-07  9:03 ` [PATCH BlueZ 2/2] android/hog: Fix report lookup Luiz Augusto von Dentz
@ 2014-08-08 11:01 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2014-08-08 11:01 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

Hi,

On Thu, Aug 7, 2014 at 12:03 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> ---
>  profiles/input/hog.c | 17 +++++++----------
>  1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/profiles/input/hog.c b/profiles/input/hog.c
> index 30f9ed1..b9aba65 100644
> --- a/profiles/input/hog.c
> +++ b/profiles/input/hog.c
> @@ -333,33 +333,30 @@ static void forward_report(struct uhid_event *ev, void *user_data)
>         struct report *report, cmp;
>         GSList *l;
>         uint8_t *data;
> -       int size, type, id;
> +       int size;
>
>         switch (ev->u.output.rtype) {
>         case UHID_FEATURE_REPORT:
> -               type = HOG_REPORT_TYPE_FEATURE;
> +               cmp.type = HOG_REPORT_TYPE_FEATURE;
>                 break;
>         case UHID_OUTPUT_REPORT:
> -               type = HOG_REPORT_TYPE_OUTPUT;
> +               cmp.type = HOG_REPORT_TYPE_OUTPUT;
>                 break;
>         case UHID_INPUT_REPORT:
> -               type = HOG_REPORT_TYPE_INPUT;
> +               cmp.type = HOG_REPORT_TYPE_INPUT;
>                 break;
>         default:
>                 return;
>         }
>
> -       id = 0;
> +       cmp.id = 0;
>         data = ev->u.output.data;
>         size = ev->u.output.size;
>         if (hogdev->has_report_id && size > 0) {
> -               id = *data++;
> +               cmp.id = *data++;
>                 --size;
>         }
>
> -       cmp.type = type;
> -       cmp.id = id;
> -
>         l = g_slist_find_custom(hogdev->reports, &cmp, report_cmp);
>         if (!l)
>                 return;
> @@ -367,7 +364,7 @@ static void forward_report(struct uhid_event *ev, void *user_data)
>         report = l->data;
>
>         DBG("Sending report type %d ID %d to device 0x%04X handle 0x%X",
> -                       type, id, hogdev->id, report->decl->value_handle);
> +               cmp.type, cmp.id, hogdev->id, report->decl->value_handle);
>
>         if (hogdev->attrib == NULL)
>                 return;
> --
> 1.9.3

Pushed.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-08 11:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-07  9:03 [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables Luiz Augusto von Dentz
2014-08-07  9:03 ` [PATCH BlueZ 2/2] android/hog: Fix report lookup Luiz Augusto von Dentz
2014-08-08 11:01 ` [PATCH BlueZ 1/2] input/hog: Remove unnecessary variables Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).