linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Pelly <npelly@google.com>
To: Linux Bluetooth <linux-bluetooth@vger.kernel.org>
Subject: Userspace patches for eSCO/SCO packet selection
Date: Thu, 18 Feb 2010 16:10:18 -0800	[thread overview]
Message-ID: <35c90d961002181610kb72d0b7hd37c595929a9d7be@mail.gmail.com> (raw)

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

For hcidump:

0001-Print-pkt_type-when-decoding-Setup-Synchronous-Conne.patch
0002-Print-pkt_type-on-HCI-Accept-Synchrnous-Connection-R.patch

For bluez userspace:
0001-Update-userspace-headers-for-SCO-eSCO-packet-selecti.patch
0002-Add-option-to-change-sco-packet-type-in-scotest.patch

Nick

[-- Attachment #2: 0001-Print-pkt_type-when-decoding-Setup-Synchronous-Conne.patch --]
[-- Type: application/octet-stream, Size: 896 bytes --]

From 0e2012c382c085cb4df31b47681bd2ddb3e4b1ef Mon Sep 17 00:00:00 2001
From: Nick Pelly <npelly@google.com>
Date: Tue, 9 Feb 2010 17:05:02 -0800
Subject: [PATCH 1/2] Print pkt_type when decoding Setup Synchronous Connection command.

---
 parser/hci.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/parser/hci.c b/parser/hci.c
index c0ca27e..958cd38 100644
--- a/parser/hci.c
+++ b/parser/hci.c
@@ -917,8 +917,9 @@ static inline void setup_sync_conn_dump(int level, struct frame *frm)
 	setup_sync_conn_cp *cp = frm->ptr;
 
 	p_indent(level, frm);
-	printf("handle %d voice setting 0x%4.4x\n", btohs(cp->handle),
-						btohs(cp->voice_setting));
+	printf("handle %d voice setting 0x%4.4x pkt_type 0x%4.4x\n",
+		btohs(cp->handle), btohs(cp->voice_setting),
+		btohs(cp->pkt_type));
 }
 
 static inline void hold_mode_dump(int level, struct frame *frm)
-- 
1.6.5.3


[-- Attachment #3: 0002-Print-pkt_type-on-HCI-Accept-Synchrnous-Connection-R.patch --]
[-- Type: application/octet-stream, Size: 1419 bytes --]

From 55f43e604797356468733a7a333bc835e9ab2332 Mon Sep 17 00:00:00 2001
From: Nick Pelly <npelly@google.com>
Date: Thu, 11 Feb 2010 15:26:27 -0800
Subject: [PATCH 2/2] Print pkt_type on HCI Accept Synchrnous Connection Request Command.

---
 parser/hci.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/parser/hci.c b/parser/hci.c
index 958cd38..ee4fdb0 100644
--- a/parser/hci.c
+++ b/parser/hci.c
@@ -922,6 +922,17 @@ static inline void setup_sync_conn_dump(int level, struct frame *frm)
 		btohs(cp->pkt_type));
 }
 
+static inline void accept_sync_conn_req_dump(int level, struct frame *frm)
+{
+	accept_sync_conn_req_cp *cp = frm->ptr;
+	char addr[18];
+
+	p_indent(level, frm);
+	p_ba2str(&cp->bdaddr, addr);
+	printf("bdaddr %s voice_setting 0x%4.4x pkt_type 0x%4.4x\n",
+		addr, btohs(cp->voice_setting), btohs(cp->pkt_type));
+}
+
 static inline void hold_mode_dump(int level, struct frame *frm)
 {
 	hold_mode_cp *cp = frm->ptr;
@@ -1385,9 +1396,11 @@ static inline void command_dump(int level, struct frame *frm)
 			return;
 		case OCF_CREATE_CONN_CANCEL:
 		case OCF_REMOTE_NAME_REQ_CANCEL:
-		case OCF_ACCEPT_SYNC_CONN_REQ:
 			bdaddr_command_dump(level + 1, frm);
 			return;
+		case OCF_ACCEPT_SYNC_CONN_REQ:
+			accept_sync_conn_req_dump(level + 1, frm);
+			return;
 		case OCF_ADD_SCO:
 		case OCF_SET_CONN_PTYPE:
 			add_sco_dump(level + 1, frm);
-- 
1.6.5.3


[-- Attachment #4: 0001-Update-userspace-headers-for-SCO-eSCO-packet-selecti.patch --]
[-- Type: application/octet-stream, Size: 3689 bytes --]

From 4c246b19b8e6227f897e892faa1abd8af7c619eb Mon Sep 17 00:00:00 2001
From: Nick Pelly <npelly@google.com>
Date: Thu, 18 Feb 2010 15:59:16 -0800
Subject: [PATCH 1/2] Update userspace headers for SCO/eSCO packet selection in struct sockaddr_sco.

uint16_t sco_pkt_type is introduced to struct sockaddr_sco. It allows bitwise
selection of SCO/eSCO packet types. Currently those bits are:

0x0001 HV1 may be used.
0x0002 HV2 may be used.
0x0004 HV3 may be used.
0x0008 EV3 may be used.
0x0010 EV4 may be used.
0x0020 EV5 may be used.
0x0040 2-EV3 may be used.
0x0080 3-EV3 may be used.
0x0100 2-EV5 may be used.
0x0200 3-EV5 may be used.

This is similar to the Packet Type parameter in the HCI Setup Synchronous
Connection Command, except that we are not reversing the logic on the EDR bits.
This makes the use of sco_pkt_tpye forward portable for the use case of
white-listing packet types, which we expect will be the primary use case.

If sco_pkt_type is zero, or userspace uses the old struct sockaddr_sco,
then the default behavior is to allow all packet types.

Packet type selection is just a request made to the Bluetooth chipset, and
it is up to the link manager on the chipset to negiotiate and decide on the
actual packet types used. Furthermore, when a SCO/eSCO connection is eventually
made there is no way for the host stack to determine which packet type was used
(however it is possible to get the link type of SCO or eSCO).

sco_pkt_type is ignored for incoming SCO connections. It is possible
to add this in the future as a parameter to the Accept Synchronous Connection
Command, however its a little trickier because the kernel does not
currently preserve sockaddr_sco data between userspace calls to accept().

The most common use for sco_pkt_type will be to white-list only SCO packets,
which can be done with the hci.h constant SCO_ESCO_MASK.

This patch is motivated by broken Bluetooth carkits such as the Motorola
HF850 (it claims to support eSCO, but will actually reject eSCO connections
after 5 seconds) and the 2007/2008 Infiniti G35/37 (fails to route audio
if a 2-EV5 packet type is negiotiated). With this patch userspace can maintain
a list of compatible packet types to workaround remote devices such as these.

---
 include/bluetooth/hci.h |   17 +++++++++++++++++
 include/bluetooth/sco.h |    2 ++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/include/bluetooth/hci.h b/include/bluetooth/hci.h
index dcd32e7..aaee296 100644
--- a/include/bluetooth/hci.h
+++ b/include/bluetooth/hci.h
@@ -133,6 +133,23 @@ enum {
 #define SCO_PTYPE_MASK	(HCI_HV1 | HCI_HV2 | HCI_HV3)
 #define ACL_PTYPE_MASK	(HCI_DM1 | HCI_DH1 | HCI_DM3 | HCI_DH3 | HCI_DM5 | HCI_DH5)
 
+/* eSCO packet types */
+#define ESCO_HV1	0x0001
+#define ESCO_HV2	0x0002
+#define ESCO_HV3	0x0004
+#define ESCO_EV3	0x0008
+#define ESCO_EV4	0x0010
+#define ESCO_EV5	0x0020
+#define ESCO_2EV3	0x0040
+#define ESCO_3EV3	0x0080
+#define ESCO_2EV5	0x0100
+#define ESCO_3EV5	0x0200
+
+#define SCO_ESCO_MASK	(ESCO_HV1 | ESCO_HV2 | ESCO_HV3)
+#define EDR_ESCO_MASK	(ESCO_2EV3 | ESCO_3EV3 | ESCO_2EV5 | ESCO_3EV5)
+#define ALL_ESCO_MASK	(SCO_ESCO_MASK | ESCO_EV3 | ESCO_EV4 | ESCO_EV5 | \
+			EDR_ESCO_MASK)
+
 /* HCI Error codes */
 #define HCI_UNKNOWN_COMMAND			0x01
 #define HCI_NO_CONNECTION			0x02
diff --git a/include/bluetooth/sco.h b/include/bluetooth/sco.h
index 43b6069..ff71829 100644
--- a/include/bluetooth/sco.h
+++ b/include/bluetooth/sco.h
@@ -41,6 +41,8 @@ extern "C" {
 struct sockaddr_sco {
 	sa_family_t	sco_family;
 	bdaddr_t	sco_bdaddr;
+	/* for use with eSCO masks such as SCO_ESCO_MASK */
+	uint16_t	sco_pkt_type;
 };
 
 /* set/get sockopt defines */
-- 
1.6.5.3


[-- Attachment #5: 0002-Add-option-to-change-sco-packet-type-in-scotest.patch --]
[-- Type: application/octet-stream, Size: 2059 bytes --]

From 833b10b88c0e8aa7acd98133f8f7ccac64cafd3a Mon Sep 17 00:00:00 2001
From: Nick Pelly <npelly@google.com>
Date: Thu, 18 Feb 2010 16:04:42 -0800
Subject: [PATCH 2/2] Add option to change sco packet type in scotest.

---
 test/scotest.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/test/scotest.c b/test/scotest.c
index 80081c6..d72c610 100644
--- a/test/scotest.c
+++ b/test/scotest.c
@@ -55,6 +55,9 @@ static unsigned char *buf;
 /* Default data size */
 static long data_size = 672;
 
+/* Default packet type */
+static uint16_t pkt_type = 0;
+
 static bdaddr_t bdaddr;
 
 static float tv2fl(struct timeval tv)
@@ -91,6 +94,7 @@ static int do_connect(char *svr)
 	/* Connect to remote device */
 	memset(&addr, 0, sizeof(addr));
 	addr.sco_family = AF_BLUETOOTH;
+	addr.sco_pkt_type = pkt_type;
 	str2ba(svr, &addr.sco_bdaddr);
 
 	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
@@ -139,6 +143,7 @@ static void do_listen(void (*handler)(int sk))
 	/* Bind to local address */
 	memset(&addr, 0, sizeof(addr));
 	addr.sco_family = AF_BLUETOOTH;
+	addr.sco_pkt_type = pkt_type;
 	bacpy(&addr.sco_bdaddr, &bdaddr);
 
 	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
@@ -329,7 +334,7 @@ static void usage(void)
 {
 	printf("scotest - SCO testing\n"
 		"Usage:\n");
-	printf("\tscotest <mode> [-b bytes] [bd_addr]\n");
+	printf("\tscotest <mode> [-b bytes] [-p pkt_type] [bd_addr]\n");
 	printf("Modes:\n"
 		"\t-d dump (server)\n"
 		"\t-c reconnect (client)\n"
@@ -344,7 +349,7 @@ int main(int argc ,char *argv[])
 	struct sigaction sa;
 	int opt, sk, mode = RECV;
 
-	while ((opt=getopt(argc,argv,"rdscmnb:")) != EOF) {
+	while ((opt=getopt(argc,argv,"rdscmnb:p:")) != EOF) {
 		switch(opt) {
 		case 'r':
 			mode = RECV;
@@ -374,6 +379,13 @@ int main(int argc ,char *argv[])
 			data_size = atoi(optarg);
 			break;
 
+		case 'p':
+			if (sscanf(optarg, "0x%4hx", &pkt_type) != 1) {
+				usage();
+				exit(1);
+			}
+			break;
+
 		default:
 			usage();
 			exit(1);
-- 
1.6.5.3


                 reply	other threads:[~2010-02-19  0:10 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=35c90d961002181610kb72d0b7hd37c595929a9d7be@mail.gmail.com \
    --to=npelly@google.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;
as well as URLs for NNTP newsgroup(s).