public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: alokbarsode@gmail.com
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, Alok Barsode <alok.barsode@azingo.com>
Subject: [PATCH 2/7] Adding set_powered method to hciops plugin.
Date: Tue, 12 May 2009 17:56:51 +0530	[thread overview]
Message-ID: <1242131216-4081-2-git-send-email-alok.barsode@azingo.com> (raw)
In-Reply-To: <1242131216-4081-1-git-send-email-alok.barsode@azingo.com>

From: Alok Barsode <alok.barsode@azingo.com>

---
 plugins/hciops.c |   20 ++++++++++++++++++++
 src/adapter.c    |   12 ++----------
 src/adapter.h    |    1 +
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 2e91129..c0368d0 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -462,11 +462,31 @@ done:
 	return err;
 }
 
+static int hciops_powered(int index, gboolean powered)
+{
+	int dd;
+
+	if (powered)
+		return hciops_start(index);
+
+	dd = hci_open_dev(index);
+	if (dd < 0)
+		return -EIO;
+
+	hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
+					1, SCAN_DISABLED);
+
+	hci_close_dev(dd);
+
+	return hciops_stop(index);
+}
+
 static struct btd_adapter_ops hci_ops = {
 	.setup = hciops_setup,
 	.cleanup = hciops_cleanup,
 	.start = hciops_start,
 	.stop = hciops_stop,
+	.set_powered = hciops_powered,
 };
 
 static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index 2efdbc8..caf82b1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -406,21 +406,13 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 	scan_enable = mode2scan(new_mode);
 
 	if (!adapter->up && scan_enable != SCAN_DISABLED) {
-		err = adapter_ops->start(adapter->dev_id);
+		err = adapter_ops->set_powered(adapter->dev_id, TRUE);
 		if (err < 0)
 			return err;
 	}
 
-	dd = hci_open_dev(adapter->dev_id);
-	if (dd < 0)
-		return -EIO;
-
 	if (adapter->up && scan_enable == SCAN_DISABLED) {
-		hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
-					1, &scan_enable);
-		hci_close_dev(dd);
-
-		err = adapter_ops->stop(adapter->dev_id);
+		err = adapter_ops->set_powered(adapter->dev_id, FALSE);
 		if (err < 0)
 			return err;
 
diff --git a/src/adapter.h b/src/adapter.h
index 97e9888..5c292fb 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -152,6 +152,7 @@ struct btd_adapter_ops {
 	void (*cleanup) (void);
 	int (*start) (int index);
 	int (*stop) (int index);
+	int (*set_powered) (int index, gboolean powered);
 };
 
 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
-- 
1.5.6.3

  reply	other threads:[~2009-05-12 12:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-12 12:26 [PATCH 1/7] Using hci_send_cmd instead of hci_send_req to set scan mode alokbarsode
2009-05-12 12:26 ` alokbarsode [this message]
2009-05-12 12:26   ` [PATCH 3/7] Adding set_connectable method to hciops plugin alokbarsode
2009-05-12 12:26     ` [PATCH 4/7] Adding set_discoverable method to hciops alokbarsode
2009-05-12 12:26       ` [PATCH 5/7] Modifying load_connections method alokbarsode
2009-05-12 12:26         ` [PATCH 6/7] Adding set_limited_discoverable method to hciops plugin alokbarsode
2009-05-12 12:26           ` [PATCH 7/7] Code cleanup in set_mode alokbarsode
2009-05-15 18:22   ` [PATCH 2/7] Adding set_powered method to hciops plugin Johan Hedberg
2009-05-16 22:54     ` Johan Hedberg
2009-05-17  7:27       ` alok barsode
2009-05-17 18:42         ` Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2009-05-18  9:49 [PATCH 1/7] Using hci_send_cmd instead of hci_send_req to set scan mode alokbarsode
2009-05-18  9:49 ` [PATCH 2/7] Adding set_powered method to hciops plugin alokbarsode

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=1242131216-4081-2-git-send-email-alok.barsode@azingo.com \
    --to=alokbarsode@gmail.com \
    --cc=alok.barsode@azingo.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.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