public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Louis JANG <louis@mizi.com>
To: bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] forcing SCO connection patch
Date: Mon, 17 Dec 2007 21:39:59 +0900	[thread overview]
Message-ID: <47666E1F.2000902@mizi.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]

Hello everybody,

I attached two patches. the first one(bluez-kernel-forcesco.patch) is to
force using HCI_OP_ADD_SCO instead of HCI_OP_SETUP_SYNC_CONN, and the
second one is to handle SCO connection complete event but its request
was ESCO.

1.
I'm developing bluetooth functions in my linux phone project, and I'm
using bluez for my job. I've tested lots of headsets, and found that I
coudn't connect SCO channel with HCI_OP_SETUP_SYNC_CONN in some old
headsets. I could connect SCO channel with HCI_OP_ADD_SCO in this case.
however, there is no api to force using SCO instead of ESCO in bluez. so
I added SCO_FORCESCO to handle this old headsets

2.
When I tried to connect SCO channel with
HCI_OP_SETUP_SYNC_CONN(LINK_TYPE_ESCO), some bluetooth headsets responds
with LINK_TYPE_SCO because it did not support ESCO. But bluez couldn't
handle this situation, and patch_hci_event.c is for this.


BRs
Louis JANG


[-- Attachment #2: bluez-kernel-forcesco.patch --]
[-- Type: text/x-patch, Size: 2106 bytes --]

--- net/bluetooth/sco.c.orig	2007-12-17 18:03:14.000000000 +0900
+++ net/bluetooth/sco.c	2007-12-17 18:18:53.000000000 +0900
@@ -200,7 +200,11 @@
 
 	err = -ENOMEM;
 
-	type = lmp_esco_capable(hdev) ? ESCO_LINK : SCO_LINK;
+	if (sco_pi(sk)->force_sco) {
+	    type = SCO_LINK;
+	} else {
+	    type = lmp_esco_capable(hdev) ? ESCO_LINK : SCO_LINK;
+	}
 
 	hcon = hci_connect(hdev, type, dst);
 	if (!hcon)
@@ -660,12 +664,23 @@
 {
 	struct sock *sk = sock->sk;
 	int err = 0;
+	int len;
+	unsigned int force_sco;
 
 	BT_DBG("sk %p", sk);
 
 	lock_sock(sk);
 
 	switch (optname) {
+	case SCO_FORCESCO:
+		len = sizeof(unsigned int);
+		if (copy_from_user((char *)&force_sco, optval, len)) {
+		    err = -EFAULT;
+		    break;
+		}
+		sco_pi(sk)->force_sco = (force_sco != 0);
+		break;
+
 	default:
 		err = -ENOPROTOOPT;
 		break;
@@ -681,6 +696,7 @@
 	struct sco_options opts;
 	struct sco_conninfo cinfo;
 	int len, err = 0; 
+	unsigned int force_sco;
 
 	BT_DBG("sk %p", sk);
 
@@ -721,6 +737,14 @@
 
 		break;
 
+	case SCO_FORCESCO:
+		force_sco = sco_pi(sock)->force_sco;
+		len = sizeof(unsigned int);
+		if (copy_to_user(optval, (char *)&force_sco, len))
+			err = -EFAULT;
+
+		break;
+		
 	default:
 		err = -ENOPROTOOPT;
 		break;
--- net/bluetooth/hci_conn.c.orig	2007-11-29 15:53:15.000000000 +0900
+++ net/bluetooth/hci_conn.c	2007-12-17 18:03:28.000000000 +0900
@@ -355,7 +355,8 @@
 
 		if (acl->state == BT_CONNECTED && 
 				(sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
-			if (lmp_esco_capable(hdev))
+			//if (lmp_esco_capable(hdev))
+			if (type == ESCO_LINK)
 				hci_setup_sync(sco, acl->handle);
 			else
 				hci_add_sco(sco, acl->handle);
--- include/net/bluetooth/sco.h.orig	2007-12-17 18:02:54.000000000 +0900
+++ include/net/bluetooth/sco.h	2007-12-17 18:04:17.000000000 +0900
@@ -51,6 +51,8 @@
 	__u8  dev_class[3];
 };
 
+#define SCO_FORCESCO	0x03
+
 /* ---- SCO connections ---- */
 struct sco_conn {
 	struct hci_conn	*hcon;
@@ -74,6 +76,7 @@
 	struct bt_sock	bt;
 	__u32		flags;
 	struct sco_conn	*conn;
+	unsigned int    force_sco :1;
 };
 
 #endif /* __SCO_H */

[-- Attachment #3: patch_hci_event.c --]
[-- Type: text/x-csrc, Size: 647 bytes --]

--- ../../../kernel-2.6-bluez-patch-2.6.23-mh1/net/bluetooth/hci_event.c	2007-11-21 14:15:41.000000000 +0900
+++ hci_event.c	2007-12-05 14:39:52.000000000 +0900
@@ -1316,8 +1316,16 @@
 	hci_dev_lock(hdev);
 
 	conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
-	if (!conn)
-		goto unlock;
+	if (!conn) {
+	    if (ev->link_type != ACL_LINK) {
+		int t = (ev->link_type == ESCO_LINK) ? SCO_LINK : ESCO_LINK;
+		conn = hci_conn_hash_lookup_ba(hdev, t, &ev->bdaddr);
+		if (conn) 
+		    conn->type = ev->link_type;
+	    }
+	    if (!conn) 
+	    	goto unlock;
+	}
 
 	if (!ev->status) {
 		conn->handle = __le16_to_cpu(ev->handle);

[-- Attachment #4: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #5: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

             reply	other threads:[~2007-12-17 12:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-17 12:39 Louis JANG [this message]
2008-02-25  6:43 ` [Bluez-devel] forcing SCO connection patch Brad Midgley
2008-02-25  6:56   ` Brad Midgley
2008-02-26 19:19   ` Guillaume Bedot
2008-02-26 19:28     ` Marcel Holtmann
2008-02-26 21:05       ` Guillaume Bedot
     [not found] ` <a8e1da0802242330l765b8b1ava62b857baf8a5568@mail.gmail.com>
     [not found]   ` <47C28A33.4070102@mizi.com>
     [not found]     ` <a8e1da0802250155u1b7af481va203849f68d9106b@mail.gmail.com>
     [not found]       ` <47C2A7FA.2060902@mizi.com>
     [not found]         ` <70692DDF-93B7-447E-ABEE-3CDBD94F15F1@holtmann.org>
     [not found]           ` <47C38D40.3040809@mizi.com>
     [not found]             ` <B96BD3FE-F490-4AD5-9315-ECD42CE9C728@holtmann.org>
     [not found]               ` <47C4C3D4.8010902@mizi.com>
     [not found]                 ` <2A7EF87C-1340-45D7-B457-F81799674B1E@holtmann.org>
     [not found]                   ` <47C555E5.2000903@mizi.com>
2008-02-27 13:04                     ` Guillaume Bedot
     [not found]                     ` <5D9353FF-6A69-4039-9033-C0EBD1CDA756@holtmann.org>
     [not found]                       ` <47C62147.90007@mizi.com>
2008-02-28 10:57                         ` Guillaume Bedot

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=47666E1F.2000902@mizi.com \
    --to=louis@mizi.com \
    --cc=bluez-devel@lists.sourceforge.net \
    /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