From: Rafal Garbat <rafal.garbat@tieto.com>
To: <linux-bluetooth@vger.kernel.org>
Cc: <rafal.garbat@tieto.com>
Subject: [PATCH 08/13] heartrate: Add notification support
Date: Thu, 9 Aug 2012 09:20:11 +0200 [thread overview]
Message-ID: <1344496816-4641-9-git-send-email-rafal.garbat@tieto.com> (raw)
In-Reply-To: <1344496816-4641-1-git-send-email-rafal.garbat@tieto.com>
Add handling notification event.
---
profiles/heartrate/heartrate.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index 2521b6a..d5b3fb9 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -42,6 +42,8 @@
#define HEART_RATE_INTERFACE "org.bluez.HeartRate"
+#define MIN_NOTIFICATION_LEN 3 /* 1-byte opcode + 2-byte handle */
+
#define SENSOR_LOCATION_SIZE 1
struct heartrate {
@@ -49,6 +51,7 @@ struct heartrate {
DBusConnection *conn; /*DBus conn*/
GAttrib *attrib; /*GATT connection*/
guint attioid; /*ATT watcher id*/
+ guint attionotid; /*ATT notification watcher id*/
struct att_range *svc_range; /*Heart Rate range*/
GSList *chars; /*Characteristics*/
GSList *watchers; /*Watchers*/
@@ -136,8 +139,10 @@ static void heartrate_destroy(gpointer user_data)
if (hr->attioid > 0)
btd_device_remove_attio_callback(hr->dev, hr->attioid);
- if (hr->attrib != NULL)
+ if (hr->attrib != NULL) {
+ g_attrib_unregister(hr->attrib, hr->attionotid);
g_attrib_unref(hr->attrib);
+ }
if (hr->watchers != NULL)
g_slist_free_full(hr->watchers, watcher_remove);
@@ -407,6 +412,14 @@ static void configure_heartrate_cb(GSList *characteristics, guint8 status,
}
}
+static void notify_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
+{
+ if (len < MIN_NOTIFICATION_LEN) {
+ error("Bad pdu received");
+ return;
+ }
+}
+
static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
{
struct heartrate *hr = user_data;
@@ -415,6 +428,9 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
hr->attrib = g_attrib_ref(attrib);
+ hr->attionotid = g_attrib_register(hr->attrib,
+ ATT_OP_HANDLE_NOTIFY, notify_handler, hr , NULL);
+
if (hr->chars == NULL)
gatt_discover_char(hr->attrib, hr->svc_range->start,
hr->svc_range->end, NULL,
@@ -427,6 +443,8 @@ static void attio_disconnected_cb(gpointer user_data)
DBG("GATT Disconnected");
+ g_attrib_unregister(hr->attrib, hr->attionotid);
+ hr->attionotid = 0;
g_attrib_unref(hr->attrib);
hr->attrib = NULL;
}
--
1.7.9.5
next prev parent reply other threads:[~2012-08-09 7:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-09 7:20 [PATCH 00/13] Add Heart Rate Service Rafal Garbat
2012-08-09 7:20 ` [PATCH 01/13] Heart Rate Profile API Rafal Garbat
2012-08-09 7:20 ` [PATCH 02/13] heartrate: Add Heart Rate Service GATT client skeleton Rafal Garbat
2012-08-09 7:20 ` [PATCH 03/13] heartrate: Add conn logic and attio callbacks Rafal Garbat
2012-08-09 7:20 ` [PATCH 04/13] heartrate: Discover Characteristic Descriptors Rafal Garbat
2012-08-09 7:20 ` [PATCH 05/13] heartrate: Process Heart Rate Descriptors Rafal Garbat
2012-08-09 7:20 ` [PATCH 06/13] heartrate: Add DBus connection logic Rafal Garbat
2012-08-09 7:20 ` [PATCH 07/13] heartrate: Process Heart Rate Characteristics Rafal Garbat
2012-08-09 7:20 ` Rafal Garbat [this message]
2012-08-09 7:20 ` [PATCH 09/13] heartrate: Process measurements Rafal Garbat
2012-08-09 7:20 ` [PATCH 10/13] heartrate: Add support for Control Point Reset Rafal Garbat
2012-08-09 7:20 ` [PATCH 11/13] heartrate: Add GetProperties method handle Rafal Garbat
2012-08-09 7:20 ` [PATCH 12/13] heartrate: Add org.bluez.HeartRateWatcher iface to default policy Rafal Garbat
2012-08-09 7:20 ` [PATCH 13/13] heartrate: Add Heart Rate test script Rafal Garbat
2012-08-09 10:18 ` Santiago Carot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1344496816-4641-9-git-send-email-rafal.garbat@tieto.com \
--to=rafal.garbat@tieto.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox