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 6/7] Adding set_limited_discoverable method to hciops plugin.
Date: Mon, 18 May 2009 15:19:12 +0530	[thread overview]
Message-ID: <1242640153-23420-6-git-send-email-alok.barsode@azingo.com> (raw)
In-Reply-To: <1242640153-23420-5-git-send-email-alok.barsode@azingo.com>

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 184ed9c..8f9ee06 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -516,6 +516,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,
@@ -524,6 +569,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

  reply	other threads:[~2009-05-18  9:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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         ` alokbarsode [this message]
2009-05-18  9:49           ` [PATCH 7/7] Code cleanup in set_mode alokbarsode
  -- strict thread matches above, loose matches on Subject: below --
2009-05-18 11:37 [PATCH 6/7] Adding set_limited_discoverable method to hciops plugin 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

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=1242640153-23420-6-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