linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] android/gatt: Fix handling advertising state
@ 2014-05-14 11:26 Lukasz Rymanowski
  2014-05-14 13:19 ` Szymon Janc
  2014-05-14 15:12 ` Marcel Holtmann
  0 siblings, 2 replies; 6+ messages in thread
From: Lukasz Rymanowski @ 2014-05-14 11:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: szymon.janc, Lukasz Rymanowski

This patch fixes enabling advertising.
It was not possible to enable it if we had server registered
which is on listen_apps list but does not trigger advertising.

This patch introduces static counter to track number of clients
requested advertising.
---
 android/gatt.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 157ebe6..ad89233 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -167,6 +167,7 @@ struct app_connection {
 static struct ipc *hal_ipc = NULL;
 static bdaddr_t adapter_addr;
 static bool scanning = false;
+static unsigned int advertising_cnt = 0;
 
 static struct queue *gatt_apps = NULL;
 static struct queue *gatt_devices = NULL;
@@ -1374,6 +1375,10 @@ static void set_advertising_cb(uint8_t status, void *user_data)
 
 	send_client_listen_notify(l->client_id, status);
 
+	/* In case of success update advertising state*/
+	if (!status)
+		advertising_cnt = l->start ? 1 : 0;
+
 	/*
 	 * Let's remove client from the list in two cases
 	 * 1. Start failed
@@ -1418,7 +1423,8 @@ static void handle_client_listen(const void *buf, uint16_t len)
 		}
 
 		/* If listen is already on just return success*/
-		if (queue_length(listen_apps) > 1) {
+		if (advertising_cnt > 0) {
+			advertising_cnt++;
 			status = HAL_STATUS_SUCCESS;
 			goto reply;
 		}
@@ -1435,7 +1441,8 @@ static void handle_client_listen(const void *buf, uint16_t len)
 		 * In case there is more listening clients don't stop
 		 * advertising
 		 */
-		if (queue_length(listen_apps) > 1) {
+		if (advertising_cnt > 1) {
+			advertising_cnt--;
 			queue_remove(listen_apps,
 						INT_TO_PTR(cmd->client_if));
 			status = HAL_STATUS_SUCCESS;
-- 
1.8.4


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

end of thread, other threads:[~2014-05-14 17:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-14 11:26 [PATCH] android/gatt: Fix handling advertising state Lukasz Rymanowski
2014-05-14 13:19 ` Szymon Janc
2014-05-14 15:12 ` Marcel Holtmann
2014-05-14 16:02   ` Lukasz Rymanowski
2014-05-14 16:10     ` Marcel Holtmann
2014-05-14 17:54       ` Lukasz Rymanowski

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).