[PATCH 3/7] Adding set_connectable method to hciops plugin.

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

 



From: Alok Barsode <alok.barsode@xxxxxxxxxx>

---
 plugins/hciops.c |   18 ++++++++++++++++++
 src/adapter.c    |   42 +++++++++++++++++++++---------------------
 src/adapter.h    |    1 +
 3 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 1e54c09..15084e4 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -482,12 +482,30 @@ static int hciops_powered(int index, gboolean powered)
 	return hciops_stop(index);
 }
 
+static int hciops_connectable(int index)
+{
+	int dd;
+	uint8_t mode = SCAN_PAGE;
+
+	dd = hci_open_dev(index);
+	if (dd < 0)
+		return -EIO;
+
+	hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
+					1, &mode);
+
+	hci_close_dev(dd);
+
+	return 0;
+}
+
 static struct btd_adapter_ops hci_ops = {
 	.setup = hciops_setup,
 	.cleanup = hciops_cleanup,
 	.start = hciops_start,
 	.stop = hciops_stop,
 	.set_powered = hciops_powered,
+	.set_connectable = hciops_connectable,
 };
 
 static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index 5b3b0aa..121694d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -343,23 +343,10 @@ static void adapter_remove_discov_timeout(struct btd_adapter *adapter)
 static gboolean discov_timeout_handler(gpointer user_data)
 {
 	struct btd_adapter *adapter = user_data;
-	int dd;
-	uint8_t scan_enable;
-	uint16_t dev_id = adapter->dev_id;
 
 	adapter->discov_timeout_id = 0;
 
-	dd = hci_open_dev(dev_id);
-	if (dd < 0) {
-		error("HCI device open failed: hci%d", dev_id);
-		return FALSE;
-	}
-
-	scan_enable = adapter->scan_mode & ~SCAN_INQUIRY;
-
-	hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
-					1, &scan_enable);
-	hci_close_dev(dd);
+	adapter_ops->set_connectable(adapter->dev_id);
 
 	return FALSE;
 }
@@ -421,16 +408,24 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 		goto done;
 	}
 
-	dd = hci_open_dev(adapter->dev_id);
-	if (dd < 0)
-		return -EIO;
-
 	if (current_scan != scan_enable) {
-		err = hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
+		if (scan_enable == SCAN_PAGE) {
+			err = adapter_ops->set_connectable(adapter->dev_id);
+			if (err < 0)
+				return err;
+		} else {
+			dd = hci_open_dev(adapter->dev_id);
+			if (dd < 0)
+				return -EIO;
+
+			err = hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
 					1, &scan_enable);
-		if (err < 0) {
+			if (err < 0) {
+				hci_close_dev(dd);
+				return err;
+			}
+
 			hci_close_dev(dd);
-			return err;
 		}
 	} else if ((scan_enable & SCAN_INQUIRY) &&
 						(new_mode != adapter->mode)) {
@@ -438,6 +433,11 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 		if (adapter->discov_timeout)
 			adapter_set_discov_timeout(adapter,
 						adapter->discov_timeout);
+
+		dd = hci_open_dev(adapter->dev_id);
+		if (dd < 0)
+			return -EIO;
+
 		if (new_mode == MODE_LIMITED)
 			set_limited_discoverable(dd, adapter->dev.class,
 									TRUE);
diff --git a/src/adapter.h b/src/adapter.h
index 5c292fb..0bfad8a 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -153,6 +153,7 @@ struct btd_adapter_ops {
 	int (*start) (int index);
 	int (*stop) (int index);
 	int (*set_powered) (int index, gboolean powered);
+	int (*set_connectable) (int index);
 };
 
 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
-- 
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