Linux bluetooth development
 help / color / mirror / Atom feed
From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: "Elvis Pfützenreuter" <epx@signove.com>
Subject: [PATCHv2 5/5] Implement ATT handle indication
Date: Tue, 22 Feb 2011 18:01:31 -0300	[thread overview]
Message-ID: <1298408491-11154-5-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1298323843-31106-1-git-send-email-anderson.lizardo@openbossa.org>

From: Elvis Pfützenreuter <epx@signove.com>

---
 src/attrib-server.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 8fcfa89..dc4d864 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -61,6 +61,8 @@ struct gatt_channel {
 	guint mtu;
 	guint id;
 	gboolean encrypted;
+	guint outstanding_indications;
+	time_t oldest_indication;
 };
 
 struct group_elem {
@@ -888,6 +890,10 @@ static void channel_handler(const uint8_t *ipdu, uint16_t len,
 		length = find_by_type(start, end, &uuid, value, vlen,
 							opdu, channel->mtu);
 		break;
+	case ATT_OP_HANDLE_CNF:
+		if (channel->outstanding_indications)
+			channel->outstanding_indications -= 1;
+		return;
 	case ATT_OP_READ_MULTI_REQ:
 	case ATT_OP_PREP_WRITE_REQ:
 	case ATT_OP_EXEC_WRITE_REQ:
@@ -967,8 +973,11 @@ static void confirm_event(GIOChannel *io, void *user_data)
 static void attrib_notify_clients(struct attribute *attr)
 {
 	guint handle = attr->handle;
+	time_t now;
 	GSList *l;
 
+	time(&now);
+
 	for (l = clients; l; l = l->next) {
 		struct gatt_channel *channel = l->data;
 
@@ -985,6 +994,37 @@ static void attrib_notify_clients(struct attribute *attr)
 			g_attrib_send(channel->attrib, 0, pdu[0], pdu, len,
 							NULL, NULL, NULL);
 		}
+
+		/* The outstanding_indications variable counts how many
+		 * unconfirmed indications have been sent. The oldest_indication
+		 * variable gives a small time frame to accomodate
+		 * almost-concomitant indications, sending both without forcing
+		 * a serialization.
+		 *
+		 * Indications are withheld once oldest_indication is older than
+		 * at least 1 second and there are pending confirmations. */
+
+		if (channel->outstanding_indications &&
+				(now - channel->oldest_indication) > 1)
+			continue;
+
+		/* Indication */
+		if (g_slist_find_custom(channel->indicate,
+				GUINT_TO_POINTER(handle), handle_cmp) != NULL) {
+			uint8_t pdu[ATT_MAX_MTU];
+			uint16_t len;
+
+			len = enc_indication(attr, pdu, channel->mtu);
+			if (len == 0)
+				continue;
+
+			g_attrib_send(channel->attrib, 0, pdu[0], pdu, len,
+							NULL, NULL, NULL);
+
+			channel->outstanding_indications += 1;
+			if (channel->outstanding_indications == 1)
+				channel->oldest_indication = now;
+		}
 	}
 }
 
-- 
1.7.0.4


      parent reply	other threads:[~2011-02-22 21:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21 21:30 [PATCH 1/5] Add read/write callbacks to attribute server Anderson Lizardo
2011-02-21 21:30 ` [PATCH 2/5] Initial Client Characteristic Configuration implementation Anderson Lizardo
2011-02-21 21:30 ` [PATCH 3/5] Check permissions before setting client configs Anderson Lizardo
2011-02-21 21:30 ` [PATCH 4/5] Implement server-side ATT handle notification Anderson Lizardo
2011-02-21 21:30 ` [PATCH 5/5] Implement ATT handle indication Anderson Lizardo
2011-02-22 21:01 ` [PATCHv2 1/5] Add read/write callbacks to attribute server Anderson Lizardo
2011-02-23  3:21   ` Johan Hedberg
2011-02-23 14:28     ` Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 " Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 2/5] Initial Client Characteristic Configuration implementation Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 3/5] Check properties before setting client configs Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 4/5] Implement server-side ATT handle notification Anderson Lizardo
2011-02-23 15:14   ` [PATCH v3 5/5] Implement ATT handle indication Anderson Lizardo
2011-02-24 19:10     ` Johan Hedberg
2011-02-22 21:01 ` [PATCHv2 2/5] Initial Client Characteristic Configuration implementation Anderson Lizardo
2011-02-23  3:26   ` Johan Hedberg
2011-02-23 14:29     ` Anderson Lizardo
2011-03-07 20:52     ` Peter Dons Tychsen
2011-02-22 21:01 ` [PATCHv2 3/5] Check permissions before setting client configs Anderson Lizardo
2011-02-22 21:01 ` [PATCHv2 4/5] Implement server-side ATT handle notification Anderson Lizardo
2011-02-22 21:01 ` Anderson Lizardo [this message]

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=1298408491-11154-5-git-send-email-anderson.lizardo@openbossa.org \
    --to=anderson.lizardo@openbossa.org \
    --cc=epx@signove.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