Linux bluetooth development
 help / color / mirror / Atom feed
From: Andre Guedes <andre.guedes@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Andre Guedes <andre.guedes@openbossa.org>
Subject: [RFC 07/16] Add 'timeout' param to start_scanning callback
Date: Fri, 29 Apr 2011 21:27:23 -0300	[thread overview]
Message-ID: <1304123252-14464-8-git-send-email-andre.guedes@openbossa.org> (raw)
In-Reply-To: <1304123252-14464-1-git-send-email-andre.guedes@openbossa.org>

This patch adds a timeout parameter to start_scanning callback in
btd_adatper. The parameter should be used to stop scanning  after
'timeout' milliseconds.
---
 plugins/hciops.c  |   38 ++++++++++++++++++++++++++++++++++++--
 plugins/mgmtops.c |    2 +-
 src/adapter.c     |    2 +-
 src/adapter.h     |    2 +-
 4 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 81a0f29..61ae404 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -139,6 +139,8 @@ static struct dev_info {
 	GSList *uuids;
 
 	GSList *connections;
+
+	guint stop_scan_id;
 } *devs = NULL;
 
 static inline int get_state(int index)
@@ -2303,6 +2305,9 @@ static void stop_hci_dev(int index)
 	if (dev->watch_id > 0)
 		g_source_remove(dev->watch_id);
 
+	if (dev->stop_scan_id > 0)
+		g_source_remove(dev->stop_scan_id);
+
 	if (dev->io != NULL)
 		g_io_channel_unref(dev->io);
 
@@ -3031,10 +3036,25 @@ static int le_set_scan_enable(int index, uint8_t enable)
 	return 0;
 }
 
-static int hciops_start_scanning(int index)
+static gboolean stop_le_scan_cb(gpointer user_data)
+{
+	struct dev_info *dev = user_data;
+	int err;
+
+	err = le_set_scan_enable(dev->id, 0);
+	if (err < 0)
+		return TRUE;
+
+	dev->stop_scan_id = 0;
+
+	return FALSE;
+}
+
+static int hciops_start_scanning(int index, int timeout)
 {
 	struct dev_info *dev = &devs[index];
 	le_set_scan_parameters_cp cp;
+	int err;
 
 	DBG("hci%d", index);
 
@@ -3051,13 +3071,27 @@ static int hciops_start_scanning(int index)
 				LE_SET_SCAN_PARAMETERS_CP_SIZE, &cp) < 0)
 		return -errno;
 
-	return le_set_scan_enable(index, 1);
+	err = le_set_scan_enable(index, 1);
+	if (err < 0)
+		return err;
+
+	/* Schedule a le scan disable in 'timeout' milliseconds */
+	dev->stop_scan_id = g_timeout_add(timeout, stop_le_scan_cb, dev);
+
+	return 0;
 }
 
 static int hciops_stop_scanning(int index)
 {
+	struct dev_info *dev = &devs[index];
+
 	DBG("hci%d", index);
 
+	if (dev->stop_scan_id > 0) {
+		g_source_remove(dev->stop_scan_id);
+		dev->stop_scan_id = 0;
+	}
+
 	return le_set_scan_enable(index, 0);
 }
 
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index ac180f9..9fa195d 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1632,7 +1632,7 @@ static int mgmt_stop_inquiry(int index)
 	return 0;
 }
 
-static int mgmt_start_scanning(int index)
+static int mgmt_start_scanning(int index, int timeout)
 {
 	DBG("index %d", index);
 	return -ENOSYS;
diff --git a/src/adapter.c b/src/adapter.c
index 1dfa9a6..6c29992 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2807,7 +2807,7 @@ void adapter_set_state(struct btd_adapter *adapter, int state)
 		 */
 		if (adapter->disc_sessions && (type & DISC_INTERLEAVE) &&
 						(previous & STATE_STDINQ)) {
-			adapter_ops->start_scanning(adapter->dev_id);
+			adapter_ops->start_scanning(adapter->dev_id, 0);
 			return;
 		}
 		/* BR/EDR only: inquiry finished */
diff --git a/src/adapter.h b/src/adapter.h
index 1a5c687..bb1abe8 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -191,7 +191,7 @@ struct btd_adapter_ops {
 	int (*stop_discovery) (int index);
 	int (*start_inquiry) (int index, uint8_t length, gboolean periodic);
 	int (*stop_inquiry) (int index);
-	int (*start_scanning) (int index);
+	int (*start_scanning) (int index, int timeout);
 	int (*stop_scanning) (int index);
 
 	int (*resolve_name) (int index, bdaddr_t *bdaddr);
-- 
1.7.1


  parent reply	other threads:[~2011-04-30  0:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-30  0:27 [RFC 00/16] Discovery procedure refactoring Andre Guedes
2011-04-30  0:27 ` [RFC 01/16] Add discovery callbacks to btd_adapter_ops Andre Guedes
2011-04-30  0:27 ` [RFC 02/16] Replace inquiry/scanning calls by discovery calls Andre Guedes
2011-04-30  0:27 ` [RFC 03/16] Add 'discov_state' field to struct dev_info Andre Guedes
2011-04-30  0:27 ` [RFC 04/16] Code cleanup event.c Andre Guedes
2011-04-30  0:27 ` [RFC 05/16] Remove Periodic Inquiry support in hciops Andre Guedes
2011-05-02  7:38   ` Luiz Augusto von Dentz
2011-05-02 22:35     ` Andre Guedes
2011-04-30  0:27 ` [RFC 06/16] Change DiscoverSchedulerInterval default value Andre Guedes
2011-05-02  7:48   ` Luiz Augusto von Dentz
2011-05-02 22:37     ` Andre Guedes
2011-04-30  0:27 ` Andre Guedes [this message]
2011-04-30  0:27 ` [RFC 08/16] Refactoring adapter_set_state() Andre Guedes
2011-04-30  0:27 ` [RFC 09/16] Remove 'suspend' param from stop_discovery() Andre Guedes
2011-05-02  8:42   ` Luiz Augusto von Dentz
2011-05-02 22:38     ` Andre Guedes
2011-04-30  0:27 ` [RFC 10/16] Add extfeatures to struct dev_info Andre Guedes
2011-04-30  0:27 ` [RFC 11/16] Implement start_discovery hciops callback Andre Guedes
2011-04-30  0:27 ` [RFC 12/16] Remove obsolete code Andre Guedes
2011-04-30  0:27 ` [RFC 13/16] Implement stop_discovery hciops callback Andre Guedes
2011-04-30  0:27 ` [RFC 14/16] Implement mgmt start and stop discovery Andre Guedes
2011-04-30  0:27 ` [RFC 15/16] Remove inquiry and scanning callbacks from btd_adapter_ops Andre Guedes
2011-04-30  0:27 ` [RFC 16/16] Remove 'periodic' param from hciops_start_inquiry() Andre Guedes
2011-05-02  8:39 ` [RFC 00/16] Discovery procedure refactoring Luiz Augusto von Dentz
2011-05-02 14:01   ` Anderson Lizardo
2011-05-02 22:32   ` Andre Guedes
2011-05-05  8:26 ` Johan Hedberg
2011-05-10 14:03   ` Andre Guedes

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=1304123252-14464-8-git-send-email-andre.guedes@openbossa.org \
    --to=andre.guedes@openbossa.org \
    --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