[PATCH 7/7] Code cleanup in set_mode.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alok Barsode <alok.barsode@xxxxxxxxxx>

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

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux