All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] Using hci_send_cmd instead of hci_send_req to set scan mode.
@ 2009-05-12 12:26 alokbarsode
  2009-05-12 12:26 ` [PATCH 2/7] Adding set_powered method to hciops plugin alokbarsode
  0 siblings, 1 reply; 12+ messages in thread
From: alokbarsode @ 2009-05-12 12:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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

---
 src/adapter.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index a54078c..2efdbc8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -416,14 +416,8 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 		return -EIO;
 
 	if (adapter->up && scan_enable == SCAN_DISABLED) {
-		struct hci_request rq = {
-			.ogf = OGF_HOST_CTL,
-			.ocf = OCF_WRITE_SCAN_ENABLE,
-			.cparam = &scan_enable,
-			.clen = sizeof(scan_enable),
-		};
-
-		hci_send_req(dd, &rq, HCI_REQ_TIMEOUT);
+		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);
-- 
1.5.6.3


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/7] Adding set_powered method to hciops plugin.
  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
  2009-05-12 12:26   ` [PATCH 3/7] Adding set_connectable " alokbarsode
  2009-05-15 18:22   ` [PATCH 2/7] Adding set_powered method to hciops plugin Johan Hedberg
  0 siblings, 2 replies; 12+ messages in thread
From: alokbarsode @ 2009-05-12 12:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/7] Adding set_connectable method to hciops plugin.
  2009-05-12 12:26 ` [PATCH 2/7] Adding set_powered method to hciops plugin alokbarsode
@ 2009-05-12 12:26   ` alokbarsode
  2009-05-12 12:26     ` [PATCH 4/7] Adding set_discoverable method to hciops alokbarsode
  2009-05-15 18:22   ` [PATCH 2/7] Adding set_powered method to hciops plugin Johan Hedberg
  1 sibling, 1 reply; 12+ messages in thread
From: alokbarsode @ 2009-05-12 12:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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

---
 plugins/hciops.c |   18 ++++++++++++++++++
 src/adapter.c    |   45 ++++++++++++++++++++++-----------------------
 src/adapter.h    |    1 +
 3 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index c0368d0..9fdb20d 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -481,12 +481,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 caf82b1..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,20 +433,24 @@ 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);
 		else if (adapter->mode == MODE_LIMITED)
 			set_limited_discoverable(dd, adapter->dev.class,
 									FALSE);
+		hci_close_dev(dd);
 	}
 done:
 	modestr = mode2str(new_mode);
 
 	write_device_mode(&adapter->bdaddr, modestr);
 
-	hci_close_dev(dd);
-
 	adapter->mode = new_mode;
 
 	return 0;
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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/7] Adding set_discoverable method to hciops.
  2009-05-12 12:26   ` [PATCH 3/7] Adding set_connectable " alokbarsode
@ 2009-05-12 12:26     ` alokbarsode
  2009-05-12 12:26       ` [PATCH 5/7] Modifying load_connections method alokbarsode
  0 siblings, 1 reply; 12+ messages in thread
From: alokbarsode @ 2009-05-12 12:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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

---
 plugins/hciops.c |   18 ++++++++++++++++++
 src/adapter.c    |   46 +++++++++++++++++++---------------------------
 src/adapter.h    |    1 +
 3 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 9fdb20d..40de042 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -498,6 +498,23 @@ static int hciops_connectable(int index)
 	return 0;
 }
 
+static int hciops_discoverable(int index)
+{
+	int dd;
+	uint8_t mode = (SCAN_PAGE | SCAN_INQUIRY);
+
+	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,
@@ -505,6 +522,7 @@ static struct btd_adapter_ops hci_ops = {
 	.stop = hciops_stop,
 	.set_powered = hciops_powered,
 	.set_connectable = hciops_connectable,
+	.set_discoverable = hciops_discoverable,
 };
 
 static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index 121694d..cd18412 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -409,24 +409,13 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 	}
 
 	if (current_scan != scan_enable) {
-		if (scan_enable == SCAN_PAGE) {
+		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) {
-				hci_close_dev(dd);
-				return err;
-			}
-
-			hci_close_dev(dd);
-		}
+		else
+			err = adapter_ops->set_discoverable(adapter->dev_id);
+
+		if (err < 0)
+			return err;
 	} else if ((scan_enable & SCAN_INQUIRY) &&
 						(new_mode != adapter->mode)) {
 		adapter_remove_discov_timeout(adapter);
@@ -2001,7 +1990,7 @@ static int adapter_up(struct btd_adapter *adapter)
 	char mode[14], srcaddr[18];
 	uint8_t scan_mode;
 	gboolean powered, dev_down = FALSE;
-	int dd;
+	int dd, err;
 
 	ba2str(&adapter->bdaddr, srcaddr);
 
@@ -2054,19 +2043,22 @@ static int adapter_up(struct btd_adapter *adapter)
 	}
 
 proceed:
-	dd = hci_open_dev(adapter->dev_id);
-
-	if (dd < 0)
-		return -EIO;
+	if (scan_mode == SCAN_PAGE)
+		err = adapter_ops->set_connectable(adapter->dev_id);
+	else
+		err = adapter_ops->set_discoverable(adapter->dev_id);
 
-	if (dev_down == FALSE)
-		hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
-				1, &scan_mode);
+	if (err < 0)
+		return err;
 
 	if (adapter->initialized == FALSE) {
 		load_drivers(adapter);
 		load_devices(adapter);
 
+		dd = hci_open_dev(adapter->dev_id);
+		if (dd < 0)
+			return -EIO;
+
 		/* retrieve the active connections: address the scenario where
 		 * the are active connections before the daemon've started */
 		load_connections(adapter, dd);
@@ -2074,6 +2066,8 @@ proceed:
 		adapter->initialized = TRUE;
 
 		manager_add_adapter(adapter->path);
+
+		hci_close_dev(dd);
 	}
 
 	if (adapter->svc_cache)
@@ -2088,8 +2082,6 @@ proceed:
 					ADAPTER_INTERFACE, "Powered",
 					DBUS_TYPE_BOOLEAN, &powered);
 
-	hci_close_dev(dd);
-
 	return 0;
 }
 
diff --git a/src/adapter.h b/src/adapter.h
index 0bfad8a..bfd2826 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -154,6 +154,7 @@ struct btd_adapter_ops {
 	int (*stop) (int index);
 	int (*set_powered) (int index, gboolean powered);
 	int (*set_connectable) (int index);
+	int (*set_discoverable) (int index);
 };
 
 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
-- 
1.5.6.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/7] Modifying load_connections method.
  2009-05-12 12:26     ` [PATCH 4/7] Adding set_discoverable method to hciops alokbarsode
@ 2009-05-12 12:26       ` alokbarsode
  2009-05-12 12:26         ` [PATCH 6/7] Adding set_limited_discoverable method to hciops plugin alokbarsode
  0 siblings, 1 reply; 12+ messages in thread
From: alokbarsode @ 2009-05-12 12:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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

---
 src/adapter.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index cd18412..73e6d80 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1935,11 +1935,15 @@ static void load_drivers(struct btd_adapter *adapter)
 	}
 }
 
-static void load_connections(struct btd_adapter *adapter, int dd)
+static void load_connections(struct btd_adapter *adapter)
 {
 	struct hci_conn_list_req *cl = NULL;
 	struct hci_conn_info *ci;
-	int i;
+	int i, dd;
+
+	dd = hci_open_dev(adapter->dev_id);
+	if (dd < 0)
+		return;
 
 	cl = g_malloc0(10 * sizeof(*ci) + sizeof(*cl));
 
@@ -1949,6 +1953,7 @@ static void load_connections(struct btd_adapter *adapter, int dd)
 
 	if (ioctl(dd, HCIGETCONNLIST, cl) != 0) {
 		g_free(cl);
+		hci_close_dev(dd);
 		return;
 	}
 
@@ -1963,6 +1968,7 @@ static void load_connections(struct btd_adapter *adapter, int dd)
 	}
 
 	g_free(cl);
+	hci_close_dev(dd);
 }
 
 static int get_discoverable_timeout(const char *src)
@@ -1990,7 +1996,7 @@ static int adapter_up(struct btd_adapter *adapter)
 	char mode[14], srcaddr[18];
 	uint8_t scan_mode;
 	gboolean powered, dev_down = FALSE;
-	int dd, err;
+	int err;
 
 	ba2str(&adapter->bdaddr, srcaddr);
 
@@ -2055,19 +2061,14 @@ proceed:
 		load_drivers(adapter);
 		load_devices(adapter);
 
-		dd = hci_open_dev(adapter->dev_id);
-		if (dd < 0)
-			return -EIO;
-
 		/* retrieve the active connections: address the scenario where
 		 * the are active connections before the daemon've started */
-		load_connections(adapter, dd);
+		load_connections(adapter);
 
 		adapter->initialized = TRUE;
 
 		manager_add_adapter(adapter->path);
 
-		hci_close_dev(dd);
 	}
 
 	if (adapter->svc_cache)
-- 
1.5.6.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/7] Adding set_limited_discoverable method to hciops plugin.
  2009-05-12 12:26       ` [PATCH 5/7] Modifying load_connections method alokbarsode
@ 2009-05-12 12:26         ` alokbarsode
  2009-05-12 12:26           ` [PATCH 7/7] Code cleanup in set_mode alokbarsode
  0 siblings, 1 reply; 12+ messages in thread
From: alokbarsode @ 2009-05-12 12:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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

---
 plugins/hciops.c |   46 ++++++++++++++++++++++++++++++++++++
 src/adapter.c    |   69 +++++++----------------------------------------------
 src/adapter.h    |    2 +
 3 files changed, 57 insertions(+), 60 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 40de042..aabfe86 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -515,6 +515,51 @@ static int hciops_discoverable(int index)
 	return 0;
 }
 
+static int hciops_set_limited_discoverable(int index, const uint8_t *cls,
+							gboolean limited)
+{
+	int dd, err = 0;
+	uint32_t dev_class;
+	int num = (limited ? 2 : 1);
+	uint8_t lap[] = { 0x33, 0x8b, 0x9e, 0x00, 0x8b, 0x9e };
+	/*
+	 * 1: giac
+	 * 2: giac + liac
+	 */
+	dd = hci_open_dev(index);
+	if (dd < 0)
+		return -EIO;
+
+	if (hci_write_current_iac_lap(dd, num, lap, HCI_REQ_TIMEOUT) < 0) {
+		err = -errno;
+		error("Can't write current IAC LAP: %s(%d)",
+						strerror(errno), errno);
+		goto done;
+	}
+
+	if (limited) {
+		if (cls[1] & 0x20)
+			goto done; /* Already limited */
+
+		dev_class = (cls[2] << 16) | ((cls[1] | 0x20) << 8) | cls[0];
+	} else {
+		if (!(cls[1] & 0x20))
+			goto done; /* Already clear */
+
+		dev_class = (cls[2] << 16) | ((cls[1] & 0xdf) << 8) | cls[0];
+	}
+
+	if (hci_write_class_of_dev(dd, dev_class, HCI_REQ_TIMEOUT) < 0) {
+		err = -errno;
+		error("Can't write class of device: %s (%d)",
+						strerror(errno), errno);
+		goto done;
+	}
+done:
+	hci_close_dev(dd);
+	return err;
+}
+
 static struct btd_adapter_ops hci_ops = {
 	.setup = hciops_setup,
 	.cleanup = hciops_cleanup,
@@ -523,6 +568,7 @@ static struct btd_adapter_ops hci_ops = {
 	.set_powered = hciops_powered,
 	.set_connectable = hciops_connectable,
 	.set_discoverable = hciops_discoverable,
+	.set_limited_discoverable = hciops_set_limited_discoverable,
 };
 
 static int hciops_init(void)
diff --git a/src/adapter.c b/src/adapter.c
index 73e6d80..87ecaff 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -252,45 +252,6 @@ int pending_remote_name_cancel(struct btd_adapter *adapter)
 	return err;
 }
 
-static int set_limited_discoverable(int dd, const uint8_t *cls,
-							gboolean limited)
-{
-	uint32_t dev_class;
-	int num = (limited ? 2 : 1);
-	uint8_t lap[] = { 0x33, 0x8b, 0x9e, 0x00, 0x8b, 0x9e };
-	/*
-	 * 1: giac
-	 * 2: giac + liac
-	 */
-	if (hci_write_current_iac_lap(dd, num, lap, HCI_REQ_TIMEOUT) < 0) {
-		int err = -errno;
-		error("Can't write current IAC LAP: %s(%d)",
-						strerror(errno), errno);
-		return err;
-	}
-
-	if (limited) {
-		if (cls[1] & 0x20)
-			return 0; /* Already limited */
-
-		dev_class = (cls[2] << 16) | ((cls[1] | 0x20) << 8) | cls[0];
-	} else {
-		if (!(cls[1] & 0x20))
-			return 0; /* Already clear */
-
-		dev_class = (cls[2] << 16) | ((cls[1] & 0xdf) << 8) | cls[0];
-	}
-
-	if (hci_write_class_of_dev(dd, dev_class, HCI_REQ_TIMEOUT) < 0) {
-		int err = -errno;
-		error("Can't write class of device: %s (%d)",
-						strerror(errno), errno);
-		return err;
-	}
-
-	return 0;
-}
-
 static const char *mode2str(uint8_t mode)
 {
 	switch(mode) {
@@ -387,7 +348,7 @@ 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, dd;
+	int err;
 	const char *modestr;
 
 	scan_enable = mode2scan(new_mode);
@@ -423,17 +384,12 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 			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);
+			adapter_ops->set_limited_discoverable(adapter->dev_id,
+							adapter->dev.class, TRUE);
 		else if (adapter->mode == MODE_LIMITED)
-			set_limited_discoverable(dd, adapter->dev.class,
-									FALSE);
-		hci_close_dev(dd);
+			adapter_ops->set_limited_discoverable(adapter->dev_id,
+							adapter->dev.class, FALSE);
 	}
 done:
 	modestr = mode2str(new_mode);
@@ -2724,7 +2680,6 @@ void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode)
 	const gchar *path = adapter_get_path(adapter);
 	gboolean discoverable, pairable;
 	uint8_t real_class[3];
-	int dd;
 
 	if (adapter->scan_mode == scan_mode)
 		return;
@@ -2769,23 +2724,17 @@ void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode)
 					ADAPTER_INTERFACE, "Pairable",
 					DBUS_TYPE_BOOLEAN, &pairable);
 
-	dd = hci_open_dev(adapter->dev_id);
-	if (dd < 0) {
-		error("HCI device open failed: hci%d", adapter->dev_id);
-		goto done;
-	}
-
 	memcpy(real_class, adapter->dev.class, 3);
 	if (adapter->svc_cache)
 		real_class[2] = adapter->svc_cache;
 
 	if (discoverable && adapter->pairable)
-		set_limited_discoverable(dd, real_class, TRUE);
+		adapter_ops->set_limited_discoverable(adapter->dev_id,
+							real_class, TRUE);
 	else if (!discoverable)
-		set_limited_discoverable(dd, real_class, FALSE);
+		adapter_ops->set_limited_discoverable(adapter->dev_id,
+							real_class, FALSE);
 
-	hci_close_dev(dd);
-done:
 	emit_property_changed(connection, path,
 				ADAPTER_INTERFACE, "Discoverable",
 				DBUS_TYPE_BOOLEAN, &discoverable);
diff --git a/src/adapter.h b/src/adapter.h
index bfd2826..a94edc6 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -155,6 +155,8 @@ struct btd_adapter_ops {
 	int (*set_powered) (int index, gboolean powered);
 	int (*set_connectable) (int index);
 	int (*set_discoverable) (int index);
+	int (*set_limited_discoverable) (int index, const uint8_t *cls,
+						gboolean limited);
 };
 
 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
-- 
1.5.6.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/7] Code cleanup in set_mode.
  2009-05-12 12:26         ` [PATCH 6/7] Adding set_limited_discoverable method to hciops plugin alokbarsode
@ 2009-05-12 12:26           ` alokbarsode
  0 siblings, 0 replies; 12+ messages in thread
From: alokbarsode @ 2009-05-12 12:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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 87ecaff..c1a81b4 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

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/7] Adding set_powered method to hciops plugin.
  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-15 18:22   ` Johan Hedberg
  2009-05-16 22:54     ` Johan Hedberg
  1 sibling, 1 reply; 12+ messages in thread
From: Johan Hedberg @ 2009-05-15 18:22 UTC (permalink / raw)
  To: alokbarsode; +Cc: linux-bluetooth, marcel, Alok Barsode

Hi Alok,

I'm going through your patches now and I found at least one issue:

> +	hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
> +					1, SCAN_DISABLED);

This looks wrong. The last parameter should a pointer and not an integer.

Johan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/7] Adding set_powered method to hciops plugin.
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Johan Hedberg @ 2009-05-16 22:54 UTC (permalink / raw)
  To: alokbarsode, linux-bluetooth, marcel, Alok Barsode

Hi Alok,

On Fri, May 15, 2009, Johan Hedberg wrote:
> I'm going through your patches now and I found at least one issue:
> 
> > +	hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
> > +					1, SCAN_DISABLED);
> 
> This looks wrong. The last parameter should a pointer and not an integer.

There's another issue with this patch as well:
adapter.c: In function ‘set_mode’:
adapter.c:403: error: ‘dd’ may be used uninitialized in this function

I'd have fixed both issues for you (since they are rather trivial) but
then your third patch doesn't apply cleanly anymore. So please fix these
issues, check that no patch causes any compilation warning or error, and
resend them. Thanks.

Johan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/7] Adding set_powered method to hciops plugin.
  2009-05-16 22:54     ` Johan Hedberg
@ 2009-05-17  7:27       ` alok barsode
  2009-05-17 18:42         ` Johan Hedberg
  0 siblings, 1 reply; 12+ messages in thread
From: alok barsode @ 2009-05-17  7:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel

Hi Johan,

On Sun, May 17, 2009 at 4:24 AM, Johan Hedberg <johan.hedberg@gmail.com> wr=
ote:
> Hi Alok,
>
> On Fri, May 15, 2009, Johan Hedberg wrote:
>> I'm going through your patches now and I found at least one issue:
>>
>> > + =A0 hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_SCAN_ENABLE,
>> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
1, SCAN_DISABLED);
>>
>> This looks wrong. The last parameter should a pointer and not an integer=
.
>
hmmm right, I show assign 'SCAN_DISABLE' to a variable and send its
address to hci_send_cmd.

> There's another issue with this patch as well:
> adapter.c: In function =91set_mode=92:
> adapter.c:403: error: =91dd=92 may be used uninitialized in this function
>
> I'd have fixed both issues for you (since they are rather trivial) but
> then your third patch doesn't apply cleanly anymore. So please fix these
> issues, check that no patch causes any compilation warning or error, and
> resend them. Thanks.
>
The 3rd patch has dependencies on the 1st patch (using hci_send_cmd
for hci_send_req) .
did u get time to test that patch?

Thanks for fixing patch2.

do you want me to rework all the patches so as to remove dependency on patc=
h1?
(which would basically mean removing that patch).

Cheers,
Alok

> Johan
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/7] Adding set_powered method to hciops plugin.
  2009-05-17  7:27       ` alok barsode
@ 2009-05-17 18:42         ` Johan Hedberg
  0 siblings, 0 replies; 12+ messages in thread
From: Johan Hedberg @ 2009-05-17 18:42 UTC (permalink / raw)
  To: alok barsode; +Cc: linux-bluetooth, marcel

Hi Alok,

On Sun, May 17, 2009, alok barsode wrote:
> The 3rd patch has dependencies on the 1st patch (using hci_send_cmd
> for hci_send_req) .
> did u get time to test that patch?

No. I stopped processing the patches after I hit the issues with the
second one.

> do you want me to rework all the patches so as to remove dependency on patch1?
> (which would basically mean removing that patch).

Resend a fixed second patch and any other patches that need updating due
to the fixes (afaik it only affects the third patch).

Johan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/7] Using hci_send_cmd instead of hci_send_req to set scan mode.
@ 2009-05-18  9:49 alokbarsode
  0 siblings, 0 replies; 12+ messages in thread
From: alokbarsode @ 2009-05-18  9:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Alok Barsode

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

---
 src/adapter.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index a54078c..2efdbc8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -416,14 +416,8 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
 		return -EIO;
 
 	if (adapter->up && scan_enable == SCAN_DISABLED) {
-		struct hci_request rq = {
-			.ogf = OGF_HOST_CTL,
-			.ocf = OCF_WRITE_SCAN_ENABLE,
-			.cparam = &scan_enable,
-			.clen = sizeof(scan_enable),
-		};
-
-		hci_send_req(dd, &rq, HCI_REQ_TIMEOUT);
+		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);
-- 
1.5.6.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-05-18  9:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
2009-05-18  9:49 [PATCH 1/7] Using hci_send_cmd instead of hci_send_req to set scan mode alokbarsode

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.