From fd16f2cc64554bc4e9b9b04c5267c71223a04cff Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Wed, 17 Oct 2012 09:51:33 +0200 Subject: [PATCH] heartrate: Always write measurement CCC on discovery Measurement CCC is written during discovery only in case watcher is registered and notifications shall be enabled. However, it may happen that (e.g. during reconnection scenario) notifications are already enabled on remote but watcher is no longer registered and we will be receiving unwanted notifications. This patch makes sure measurement CCC is written to proper value every time it's discovered during connection. --- profiles/heartrate/heartrate.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c index 9a929607f..f0eb7a4ef 100644 --- a/profiles/heartrate/heartrate.c +++ b/profiles/heartrate/heartrate.c @@ -412,28 +412,30 @@ static void discover_ccc_cb(guint8 status, const guint8 *pdu, for (i = 0; i < list->num; i++) { uint8_t *value; uint16_t handle, uuid; + char *msg; + uint8_t attr_val[2]; value = list->data[i]; handle = att_get_u16(value); uuid = att_get_u16(value + 2); - if (uuid == GATT_CLIENT_CHARAC_CFG_UUID) { - char *msg; - uint8_t value[2]; + if (uuid != GATT_CLIENT_CHARAC_CFG_UUID) + continue; - hr->measurement_ccc_handle = handle; + hr->measurement_ccc_handle = handle; - if (g_slist_length(hr->hradapter->watchers) == 0) - break; - - att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value); + if (g_slist_length(hr->hradapter->watchers) == 0) { + att_put_u16(0x0000, attr_val); + msg = g_strdup("Disable measurement"); + } else { + att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, attr_val); msg = g_strdup("Enable measurement"); + } - gatt_write_char(hr->attrib, handle, value, - sizeof(value), char_write_cb, msg); + gatt_write_char(hr->attrib, handle, attr_val, + sizeof(attr_val), char_write_cb, msg); - break; - } + break; } done: -- 2.47.3