public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: alokbarsode@gmail.com
To: linux-bluetooth@vger.kernel.org
Cc: Alok Barsode <alok.barsode@azingo.com>
Subject: [PATCH] Fix Class of Device initialization.
Date: Wed,  5 Aug 2009 21:05:03 +0530	[thread overview]
Message-ID: <1249486503-18208-1-git-send-email-alok.barsode@azingo.com> (raw)

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

---
 plugins/hciops.c |   19 -------------------
 src/adapter.c    |   21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 2b43737..6f96dda 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -103,25 +103,6 @@ static void configure_device(int index)
 		return;
 	}
 
-	/* Set device class */
-	if ((main_opts.flags & (1 << HCID_SET_CLASS))) {
-		write_class_of_dev_cp cp;
-		uint8_t cls[3];
-
-		if (read_local_class(&di.bdaddr, cls) < 0) {
-			uint32_t class = htobl(main_opts.class);
-			memcpy(cp.dev_class, &class, 3);
-		} else {
-			if (!(main_opts.scan & SCAN_INQUIRY))
-				cls[1] &= 0xdf; /* Clear discoverable bit */
-			cls[2] = get_service_classes(&di.bdaddr);
-			memcpy(cp.dev_class, cls, 3);
-		}
-
-		hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_CLASS_OF_DEV,
-					WRITE_CLASS_OF_DEV_CP_SIZE, &cp);
-	}
-
 	/* Set page timeout */
 	if ((main_opts.flags & (1 << HCID_SET_PAGETO))) {
 		write_page_timeout_cp cp;
diff --git a/src/adapter.c b/src/adapter.c
index bf69fcc..873b1bd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1756,6 +1756,8 @@ static int adapter_setup(struct btd_adapter *adapter, const char *mode)
 	uint8_t inqmode;
 	int err , dd;
 	char name[MAX_NAME_LENGTH + 1];
+	uint8_t cls[3];
+	uint32_t class;
 
 	dd = hci_open_dev(adapter->dev_id);
 	if (dd < 0) {
@@ -1815,9 +1817,28 @@ static int adapter_setup(struct btd_adapter *adapter, const char *mode)
 							adapter->dev_id);
 
 	adapter_ops->set_name(adapter->dev_id, name);
+
 	if (g_str_equal(mode, "off"))
 		strncpy((char *) adapter->dev.name, name, MAX_NAME_LENGTH);
 
+	/* Set device class */
+	if (read_local_class(&adapter->bdaddr, cls) < 0) {
+		class = htobl(main_opts.class);
+		memcpy(cls, &class, 3);
+	}
+
+	cls[2] = adapter->svc_cache;
+
+	class = (cls[2] << 16 | cls[1] << 8 | cls[0]);
+
+	if (hci_write_class_of_dev(dd, class, HCI_REQ_TIMEOUT) < 0) {
+		err = -errno;
+		error("Can't write class of device: %s (%d)",
+						strerror(errno), errno);
+		hci_close_dev(dd);
+		return err;
+	}
+
 done:
 	hci_close_dev(dd);
 	return 0;
-- 
1.5.6.3


                 reply	other threads:[~2009-08-05 15:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1249486503-18208-1-git-send-email-alok.barsode@azingo.com \
    --to=alokbarsode@gmail.com \
    --cc=alok.barsode@azingo.com \
    --cc=linux-bluetooth@vger.kernel.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