Return-Path: From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= To: linux-bluetooth@vger.kernel.org Cc: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Subject: [PATCH 08/21] hog: Enable "Report" characteristic notifications Date: Tue, 3 Jul 2012 15:43:00 -0300 Message-Id: <1341340993-7480-9-git-send-email-jprvita@openbossa.org> In-Reply-To: <1341340993-7480-1-git-send-email-jprvita@openbossa.org> References: <1341340993-7480-1-git-send-email-jprvita@openbossa.org> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: --- input/hog_device.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/input/hog_device.c b/input/hog_device.c index fdf76cd..1883728 100644 --- a/input/hog_device.c +++ b/input/hog_device.c @@ -67,10 +67,30 @@ struct hog_device { static GSList *devices = NULL; +static void report_ccc_written_cb(guint8 status, const guint8 *pdu, + guint16 plen, gpointer user_data) +{ + if (status != 0) { + error("Write report characteristic descriptor failed: %s", + att_ecode2str(status)); + return; + } + + DBG("Report characteristic descriptor written: notifications enabled"); +} + +static void write_ccc(uint16_t handle, gpointer user_data) +{ + struct hog_device *hogdev = user_data; + uint8_t value[] = { 0x01, 0x00 }; + + gatt_write_char(hogdev->attrib, handle, value, sizeof(value), + report_ccc_written_cb, hogdev); +} + static void discover_descriptor_cb(guint8 status, const guint8 *pdu, guint16 len, gpointer user_data) { - struct report *report = user_data; struct att_data_list *list; uint8_t format; int i; @@ -89,13 +109,17 @@ static void discover_descriptor_cb(guint8 status, const guint8 *pdu, goto done; for (i = 0; i < list->num; i++) { - uint16_t uuid16; + uint16_t uuid16, handle; uint8_t *value; value = list->data[i]; + handle = att_get_u16(value); uuid16 = att_get_u16(&value[2]); - DBG("%s descriptor: 0x%04x", report->decl->uuid, uuid16); + if (uuid16 != GATT_CLIENT_CHARAC_CFG_UUID) + continue; + + write_ccc(handle, user_data); } done: -- 1.7.10.4