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 7/7] Code cleanup in set_mode.
Date: Mon, 18 May 2009 17:07:49 +0530	[thread overview]
Message-ID: <1242646669-2831-1-git-send-email-alok.barsode@azingo.com> (raw)

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

---
 src/adapter.c |   45 ++++++++++++++-------------------------------
 1 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index ebbd02e..7795e8d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -328,38 +328,18 @@ static void adapter_set_discov_timeout(struct btd_adapter *adapter,
 							adapter);
 }
 
-static uint8_t mode2scan(uint8_t mode)
-{
-	switch (mode) {
-	case MODE_OFF:
-		return SCAN_DISABLED;
-	case MODE_CONNECTABLE:
-		return SCAN_PAGE;
-	case MODE_DISCOVERABLE:
-	case MODE_LIMITED:
-		return (SCAN_PAGE | SCAN_INQUIRY);
-	default:
-		error("Invalid mode given to mode2scan: %u", mode);
-		return SCAN_PAGE;
-	}
-}
-
 static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 {
-	uint8_t scan_enable;
-	uint8_t current_scan = adapter->scan_mode;
 	int err;
 	const char *modestr;
 
-	scan_enable = mode2scan(new_mode);
-
-	if (!adapter->up && scan_enable != SCAN_DISABLED) {
+	if (!adapter->up && new_mode != MODE_OFF) {
 		err = adapter_ops->set_powered(adapter->dev_id, TRUE);
 		if (err < 0)
 			return err;
 	}
 
-	if (adapter->up && scan_enable == SCAN_DISABLED) {
+	if (adapter->up && new_mode == MODE_OFF) {
 		err = adapter_ops->set_powered(adapter->dev_id, FALSE);
 		if (err < 0)
 			return err;
@@ -369,17 +349,20 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 		goto done;
 	}
 
-	if (current_scan != scan_enable) {
-		if (scan_enable == SCAN_PAGE)
-			err = adapter_ops->set_connectable(adapter->dev_id);
-		else
-			err = adapter_ops->set_discoverable(adapter->dev_id);
+	if (new_mode == adapter->mode)
+		return 0;
 
-		if (err < 0)
-			return err;
-	} else if ((scan_enable & SCAN_INQUIRY) &&
-						(new_mode != adapter->mode)) {
+	if (new_mode == MODE_CONNECTABLE)
+		err = adapter_ops->set_connectable(adapter->dev_id);
+	else
+		err = adapter_ops->set_discoverable(adapter->dev_id);
+
+	if (err < 0)
+		return err;
+
+	if (new_mode > MODE_CONNECTABLE) {
 		adapter_remove_discov_timeout(adapter);
+
 		if (adapter->discov_timeout)
 			adapter_set_discov_timeout(adapter,
 						adapter->discov_timeout);
-- 
1.5.6.3

             reply	other threads:[~2009-05-18 11:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 11:37 alokbarsode [this message]
2009-05-18 20:45 ` [PATCH 7/7] Code cleanup in set_mode 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
2009-05-18  9:49   ` [PATCH 3/7] Adding set_connectable " alokbarsode
2009-05-18  9:49     ` [PATCH 4/7] Adding set_discoverable method to hciops alokbarsode
2009-05-18  9:49       ` [PATCH 5/7] Modifying load_connections method alokbarsode
2009-05-18  9:49         ` [PATCH 6/7] Adding set_limited_discoverable method to hciops plugin alokbarsode
2009-05-18  9:49           ` [PATCH 7/7] Code cleanup in set_mode alokbarsode
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 ` [PATCH 2/7] Adding set_powered method to hciops plugin alokbarsode
2009-05-12 12:26   ` [PATCH 3/7] Adding set_connectable " 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

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=1242646669-2831-1-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