Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 5/5] Document new "hex-encoded pins" feature
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
In-Reply-To: <1304623040-30461-1-git-send-email-dh.herrmann@googlemail.com>

---
 doc/agent-api.txt |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/doc/agent-api.txt b/doc/agent-api.txt
index d8d35c0..0c84e1c 100644
--- a/doc/agent-api.txt
+++ b/doc/agent-api.txt
@@ -26,7 +26,13 @@ Methods		void Release()
 			needs to get the passkey for an authentication.
 
 			The return value should be a string of 1-16 characters
-			length. The string can be alphanumeric.
+			length. Longer strings are truncated to 16 characters.
+			The string can be alphanumeric.
+
+			Strings starting with '$' are parsed as hex-encoded
+			pins. That is, each two following hex characters form
+			a single byte of the resulting pin. The parser is
+			case-insensitive.
 
 			Possible errors: org.bluez.Error.Rejected
 			                 org.bluez.Error.Canceled
-- 
1.7.5


^ permalink raw reply related

* [PATCH 4/5] Remove 16 byte limit for PIN codes returned by agents
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
In-Reply-To: <1304623040-30461-1-git-send-email-dh.herrmann@googlemail.com>

Agents can now return PIN codes longer than 16 characters. The
pin parser automatically truncates all PINs to 16 characters, but
allows hexadecimal PINs to be longer than 16 characters because
each two hexdecimal encoded bytes are parsed into one output byte.
---
 src/agent.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/agent.c b/src/agent.c
index f87f253..40495bf 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -403,7 +403,7 @@ static void pincode_reply(DBusPendingCall *call, void *user_data)
 	len = strlen(pin);
 
 	dbus_error_init(&err);
-	if (len > 16 || len < 1) {
+	if (len < 1) {
 		error("Invalid PIN length (%zu) from agent", len);
 		dbus_set_error_const(&err, "org.bluez.Error.InvalidArgs",
 					"Invalid passkey length");
-- 
1.7.5


^ permalink raw reply related

* [PATCH 3/5] Parse pin codes starting with '$' as hexadecimal encoded strings
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
In-Reply-To: <1304623040-30461-1-git-send-email-dh.herrmann@googlemail.com>

If a pin code is retrieved from an agent and the first character is
a dollar sign '$', then the pin is decoded as following:
 - The first character (dollar sign) is stripped from the pin
 - The rest is parsed as hexadecimal numbers, where each two characters
   will be converted into a one byte integer. If an odd number of
   characters follows, then the last character is stripped. Empty
   pins are valid. Parser is case insensitive.
Pins not starting with '$' are parsed as usual.

For instance:
 pin: $0A3e005067
is decoded into a 5 byte pin:
 decoded: 0x0a 0x3e 0x00 0x50 0x67
---
 src/event.c |   45 +++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/event.c b/src/event.c
index c238392..b0318de 100644
--- a/src/event.c
+++ b/src/event.c
@@ -101,12 +101,53 @@ static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
  *
  *****************************************************************/
 
+static uint8_t hex2dec(uint8_t c)
+{
+	if (c >= '0' && c <= '9')
+		return  c - '0';
+	else if (c >= 'A' && c <= 'F')
+		return c - 'A' + 10;
+	else if (c >= 'a' && c <= 'f')
+		return c - 'a' + 10;
+	else
+		return 0;
+}
+
+static size_t decode_hex(const char *pin, char *out)
+{
+	size_t i;
+
+	for (i = 0; i < 16 && pin[i * 2] && pin[i * 2 + 1]; i++)
+		out[i] = hex2dec(pin[i * 2]) * 16 + hex2dec(pin[i * 2 + 1]);
+
+	return i;
+}
+
+static size_t decode_pin(const char *pin, char *out)
+{
+	size_t len;
+
+	if (!pin)
+		return 0;
+
+	if (pin[0] == '$') {
+		len = decode_hex(&pin[1], out);
+	} else {
+		len = strnlen(pin, 16);
+		memcpy(out, pin, len);
+	}
+
+	return len;
+}
+
 static void pincode_cb(struct agent *agent, DBusError *derr,
 				const char *pincode, struct btd_device *device)
 {
 	struct btd_adapter *adapter = device_get_adapter(device);
 	bdaddr_t dba;
 	int err;
+	size_t len;
+	char rawpin[16];
 
 	device_get_address(device, &dba);
 
@@ -117,8 +158,8 @@ static void pincode_cb(struct agent *agent, DBusError *derr,
 		return;
 	}
 
-	err = btd_adapter_pincode_reply(adapter, &dba, pincode,
-						pincode ? strlen(pincode) : 0);
+	len = decode_pin(pincode, rawpin);
+	err = btd_adapter_pincode_reply(adapter, &dba, rawpin, len);
 	if (err < 0)
 		goto fail;
 
-- 
1.7.5


^ permalink raw reply related

* [PATCH 2/5] Make adapter API accept binary pincodes
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann
In-Reply-To: <1304623040-30461-1-git-send-email-dh.herrmann@googlemail.com>

Add pin-length argument to adapter API to allow passing binary pins
containing \0 characters to the hci handler.
---
 src/adapter.c |    4 ++--
 src/adapter.h |    2 +-
 src/event.c   |    7 ++++---
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index b7016c4..67644b8 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3543,10 +3543,10 @@ int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr)
 }
 
 int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-							const char *pin)
+					const char *pin, size_t pin_len)
 {
 	return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin,
-							pin ? strlen(pin) : 0);
+								pin_len);
 }
 
 int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/adapter.h b/src/adapter.h
index e08068c..322a33b 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -254,7 +254,7 @@ int btd_adapter_disconnect_device(struct btd_adapter *adapter,
 int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 
 int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-							const char *pin);
+					const char *pin, size_t pin_len);
 int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 							gboolean success);
 int btd_adapter_passkey_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/event.c b/src/event.c
index d5bf967..c238392 100644
--- a/src/event.c
+++ b/src/event.c
@@ -111,13 +111,14 @@ static void pincode_cb(struct agent *agent, DBusError *derr,
 	device_get_address(device, &dba);
 
 	if (derr) {
-		err = btd_adapter_pincode_reply(adapter, &dba, NULL);
+		err = btd_adapter_pincode_reply(adapter, &dba, NULL, 0);
 		if (err < 0)
 			goto fail;
 		return;
 	}
 
-	err = btd_adapter_pincode_reply(adapter, &dba, pincode);
+	err = btd_adapter_pincode_reply(adapter, &dba, pincode,
+						pincode ? strlen(pincode) : 0);
 	if (err < 0)
 		goto fail;
 
@@ -140,7 +141,7 @@ int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba)
 	memset(pin, 0, sizeof(pin));
 	pinlen = read_pin_code(sba, dba, pin);
 	if (pinlen > 0) {
-		btd_adapter_pincode_reply(adapter, dba, pin);
+		btd_adapter_pincode_reply(adapter, dba, pin, pinlen);
 		return 0;
 	}
 
-- 
1.7.5


^ permalink raw reply related

* [PATCH 1/5] Add length argument to hci pincode reply
From: David Herrmann @ 2011-05-05 19:17 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: johan.hedberg, hadess, padovan, David Herrmann

This adds a new "length" argument to the hci pincode reply to allow
sending binary pins including \0 characters.
---
 plugins/hciops.c  |   10 +++++-----
 plugins/mgmtops.c |    9 ++++-----
 src/adapter.c     |    3 ++-
 src/adapter.h     |    3 ++-
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 2c49e35..b125699 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -3415,7 +3415,8 @@ static int hciops_remove_bonding(int index, bdaddr_t *bdaddr)
 	return 0;
 }
 
-static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
+static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin,
+								size_t pin_len)
 {
 	struct dev_info *dev = &devs[index];
 	char addr[18];
@@ -3426,14 +3427,13 @@ static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
 
 	if (pin) {
 		pin_code_reply_cp pr;
-		size_t len = strlen(pin);
 
-		dev->pin_length = len;
+		dev->pin_length = pin_len;
 
 		memset(&pr, 0, sizeof(pr));
 		bacpy(&pr.bdaddr, bdaddr);
-		memcpy(pr.pin_code, pin, len);
-		pr.pin_len = len;
+		memcpy(pr.pin_code, pin, pin_len);
+		pr.pin_len = pin_len;
 		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
 						OCF_PIN_CODE_REPLY,
 						PIN_CODE_REPLY_CP_SIZE, &pr);
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 9e1cfac..ce0ec2d 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -494,7 +494,8 @@ static void mgmt_connect_failed(int sk, uint16_t index, void *buf, size_t len)
 	btd_event_bonding_complete(&info->bdaddr, &ev->bdaddr, ev->status);
 }
 
-static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
+static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin,
+								size_t pin_len)
 {
 	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_pin_code_reply)];
 	struct mgmt_hdr *hdr = (void *) buf;
@@ -502,7 +503,7 @@ static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
 	char addr[18];
 
 	ba2str(bdaddr, addr);
-	DBG("index %d addr %s pin %s", index, addr, pin ? pin : "<none>");
+	DBG("index %d addr %s pinlen %lu", index, addr, pin_len);
 
 	memset(buf, 0, sizeof(buf));
 
@@ -519,9 +520,7 @@ static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
 		buf_len = sizeof(*hdr) + sizeof(*cp);
 	} else {
 		struct mgmt_cp_pin_code_reply *cp;
-		size_t pin_len;
 
-		pin_len = strlen(pin);
 		if (pin_len > 16)
 			return -EINVAL;
 
@@ -569,7 +568,7 @@ static void mgmt_pin_code_request(int sk, uint16_t index, void *buf, size_t len)
 	err = btd_event_request_pin(&info->bdaddr, &ev->bdaddr);
 	if (err < 0) {
 		error("btd_event_request_pin: %s", strerror(-err));
-		mgmt_pincode_reply(index, &ev->bdaddr, NULL);
+		mgmt_pincode_reply(index, &ev->bdaddr, NULL, 0);
 	}
 }
 
diff --git a/src/adapter.c b/src/adapter.c
index f068335..b7016c4 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3545,7 +3545,8 @@ int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr)
 int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 							const char *pin)
 {
-	return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin);
+	return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin,
+							pin ? strlen(pin) : 0);
 }
 
 int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/adapter.h b/src/adapter.h
index 9406b9b..e08068c 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -201,7 +201,8 @@ struct btd_adapter_ops {
 	int (*read_local_features) (int index, uint8_t *features);
 	int (*disconnect) (int index, bdaddr_t *bdaddr);
 	int (*remove_bonding) (int index, bdaddr_t *bdaddr);
-	int (*pincode_reply) (int index, bdaddr_t *bdaddr, const char *pin);
+	int (*pincode_reply) (int index, bdaddr_t *bdaddr, const char *pin,
+							size_t pin_len);
 	int (*confirm_reply) (int index, bdaddr_t *bdaddr, gboolean success);
 	int (*passkey_reply) (int index, bdaddr_t *bdaddr, uint32_t passkey);
 	int (*enable_le) (int index);
-- 
1.7.5


^ permalink raw reply related

* Re: [PATCH] Fix btio.c compilation warning
From: Johan Hedberg @ 2011-05-05 19:14 UTC (permalink / raw)
  To: anderson.briglia; +Cc: linux-bluetooth
In-Reply-To: <4dc2f2a9.f0c7ec0a.7feb.654f@mx.google.com>

Hi,

On Thu, May 05, 2011, anderson.briglia@openbossa.org wrote:
> This patch fixes a compilation warning regarding btio/btio.c. Actually
> this warning seems a false positive by Ubuntu Natty GCC version. A new
> bug on Ubuntu bug system was opened but if you do not want to wait until
> it is analyzed, just apply this minor fix.
> 
> btio/btio.c: In function 'bt_io_get':
> btio/btio.c:803:11: warning: 'flushable' may be used uninitialized in
> this function
> ---
>  btio/btio.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] bluetooth: Fix for security block issue.
From: Gustavo F. Padovan @ 2011-05-05 19:09 UTC (permalink / raw)
  To: Lukasz.Rymanowski
  Cc: mika.linnanoja, linux-bluetooth, ville.tervo, antti.julku, marcel,
	linus.walleij, par-gunnar.p.hjalmdahl
In-Reply-To: <7D7F2FD3846CF6429ACEBDFB5A2DD86F07F33ED77A@EXMB01.eu.tieto.com>

Hi Lukasz,

* Lukasz.Rymanowski@tieto.com <Lukasz.Rymanowski@tieto.com> [2011-05-04 10:53:17 +0300]:

> On Thu, Apr 28, 2011 at 12:39:37PM +0300, Antti Julku wrote:
> > It's easy to reproduce at least with these dongles:
> > 
> > Alink BLUEUSB21 (BCM)
> > Belkin BT2.1 F8T017 (BCM)
> > DeLock 2.1 (CSR)
> > PTS 2.1 (CSR)
> > 
> > So most of our BT 2.1 dongles seem to be buggy. It would be nice to 
> > have a workaround since it happens with so many dongles.
> 
> If there is so many buggy devices I think Gustavo and Marcel could consider to take this patch.

The patch is too hackish, I don't wanna have such workaround in the tree.
It is a good idea check the USB stack for possible causes for this bug.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* Re: [PATCH] Re: Work-around for broken MS device
From: Johan Hedberg @ 2011-05-05 19:02 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: Marcel Holtmann, BlueZ development
In-Reply-To: <1304620681.16101.15.camel@novo.hadess.net>

Hi Bastien,

On Thu, May 05, 2011, Bastien Nocera wrote:
> > Patch to do that attached.
> 
> And one that compiles (sigh).

> From 2b4524b060d980a7899c03359cd4943c9ad9cfe4 Mon Sep 17 00:00:00 2001
> From: Bastien Nocera <hadess@hadess.net>
> Date: Mon, 8 Nov 2010 16:43:42 +0000
> Subject: [PATCH] Handle non-UTF-8 device names
> 
> http://thread.gmane.org/gmane.linux.bluez.kernel/1687
> https://bugzilla.redhat.com/show_bug.cgi?id=450081
> ---
>  src/event.c |   19 ++++++++++++-------
>  1 files changed, 12 insertions(+), 7 deletions(-)

Pushed upstream. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] bluetooth: Fix for security block issue.
From: Gustavo F. Padovan @ 2011-05-05 19:02 UTC (permalink / raw)
  To: Mika Linnanoja
  Cc: linux-bluetooth, ext Ville Tervo, Antti Julku,
	ext Marcel Holtmann, Lukasz Rymanowski, linus.walleij,
	par-gunnar.p.hjalmdahl
In-Reply-To: <4DBA6D97.7050207@nokia.com>

Hi Mika,

* Mika Linnanoja <mika.linnanoja@nokia.com> [2011-04-29 10:49:43 +0300]:

> On 04/28/2011 12:51 PM, ext Ville Tervo wrote:
> > Could the actual reason be some change in usb stack? Could it have lower
> > priority for event pipe than for data pipe? In that case event for security
> > change might arrive to bt stack too late.
> >
> > At lest I haven't seen this kind of behaviour with serial attached chips. So I
> > think this is something USB specific.
> 
> Happens on Ubuntu 11.04 (released yesterday; bluez 4.91 & kernel 2.6.38-8) as 
> well, tested with White PTS 2.1 dongle (CSR chip) on laptop x61s. Sending 
> party (OPP with obex-client in a loop) was a phone.

Is this an regression? Or did it never happen before?

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* Re: [PATCH] Remove btio.c compilation warning
From: Bastien Nocera @ 2011-05-05 19:01 UTC (permalink / raw)
  To: Vinicius Costa Gomes
  Cc: Luiz Augusto von Dentz, Elvis Pfützenreuter,
	Anderson Briglia, linux-bluetooth
In-Reply-To: <20110505140531.GA27568@piper>

On Thu, 2011-05-05 at 11:05 -0300, Vinicius Costa Gomes wrote:
> Hi Luiz,
> 
> On 11:05 Thu 05 May, Luiz Augusto von Dentz wrote:
> 
> [snip]
> 
> > 
> > I don't see why it would be ubuntu specific, this seems to be some
> > kind of regression/'feature' with gcc 4.5.
> 
> Yeah, I really believe this is the case. I have gcc 4.5.2 here, that
> would be the version as in Natty, and I don't encounter that problem.
> 
> The only difference that I could find is that Ubuntu ships gcc with
> a .diff.gz of 1.3MB ;-)
> 
> But back to the topic at hand, I agree that the patch should be applied,
> Ubuntu is used by many developers and BlueZ should be kept clean of 
> warnings.

It's also a bug in the GCC 4.6 shipped by Fedora 15, fwiw.

Cheers


^ permalink raw reply

* [PATCH] Fix btio.c compilation warning
From: anderson.briglia @ 2011-05-05 18:55 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Briglia

From: Anderson Briglia <anderson.briglia@openbossa.org>

This patch fixes a compilation warning regarding btio/btio.c. Actually
this warning seems a false positive by Ubuntu Natty GCC version. A new
bug on Ubuntu bug system was opened but if you do not want to wait until
it is analyzed, just apply this minor fix.

btio/btio.c: In function 'bt_io_get':
btio/btio.c:803:11: warning: 'flushable' may be used uninitialized in
this function
---
 btio/btio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/btio/btio.c b/btio/btio.c
index 6d71b90..a3cf38a 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -800,7 +800,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 	uint8_t dev_class[3];
 	uint16_t handle;
 	socklen_t len;
-	gboolean flushable;
+	gboolean flushable = FALSE;
 
 	len = sizeof(l2o);
 	memset(&l2o, 0, len);
-- 
1.7.4.1


^ permalink raw reply related

* Re: [PATCH] Remove btio.c compilation warning
From: Anderson Briglia @ 2011-05-05 18:51 UTC (permalink / raw)
  To: Luiz Augusto von Dentz
  Cc: Vinicius Costa Gomes, Elvis Pfützenreuter, linux-bluetooth
In-Reply-To: <BANLkTinUocgdf3YFTEvzTo6ij7E_oAGvKQ@mail.gmail.com>

Hi all,

On Thu, May 5, 2011 at 10:30 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Vinicius,
>
> On Thu, May 5, 2011 at 5:05 PM, Vinicius Costa Gomes
> <vinicius.gomes@openbossa.org> wrote:
>> Hi Luiz,
>>
>> On 11:05 Thu 05 May, Luiz Augusto von Dentz wrote:
>>
>> [snip]
>>
>>>
>>> I don't see why it would be ubuntu specific, this seems to be some
>>> kind of regression/'feature' with gcc 4.5.
>>
>> Yeah, I really believe this is the case. I have gcc 4.5.2 here, that
>> would be the version as in Natty, and I don't encounter that problem.
>
> So it seems to be Ubuntu specific in some way, very annoying way.
>
>> The only difference that I could find is that Ubuntu ships gcc with
>> a .diff.gz of 1.3MB ;-)
>>
>> But back to the topic at hand, I agree that the patch should be applied,
>> Ubuntu is used by many developers and BlueZ should be kept clean of
>> warnings.
>
> Well if we don't get anywhere with the bug Elvis sent than that is the
> only think we can do, or maybe there is some new gcc flag that can
> prevent such behavior.

I'll resend the patch and you decide if it is worth to be applied or not.

Regards,

Briglia

>
>
> --
> Luiz Augusto von Dentz
> Computer Engineer
>



-- 
INdT - Instituto Nokia de tecnologia
+55 2126 1122
http://techblog.briglia.net

^ permalink raw reply

* Warning fixes for GCC 4.6
From: Bastien Nocera @ 2011-05-05 18:43 UTC (permalink / raw)
  To: BlueZ development

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

So that bluez compiles with -Werror.

Cheers

[-- Attachment #2: 0002-Fix-set-but-not-unused-variable-GCC-4.6-warnings.patch --]
[-- Type: text/x-patch, Size: 17758 bytes --]

>From 588f7efc01dde6eb81104a9edf6bde3a9afb770f Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 5 May 2011 19:41:38 +0100
Subject: [PATCH 2/2] Fix "set but not unused variable" GCC 4.6 warnings

---
 attrib/gatt.c         |    9 ++++-----
 audio/a2dp.c          |    5 ++---
 audio/manager.c       |    3 +--
 audio/pcm_bluetooth.c |    4 ++--
 btio/btio.c           |    5 +++++
 compat/fakehid.c      |    6 ++++--
 cups/hcrp.c           |   12 ++++++++++++
 gdbus/object.c        |    3 +--
 input/device.c        |    2 +-
 input/server.c        |    3 ++-
 lib/sdp.c             |    2 +-
 network/common.c      |    2 +-
 plugins/hciops.c      |    4 +---
 plugins/mgmtops.c     |    4 +---
 sbc/sbcinfo.c         |    2 +-
 src/adapter.c         |    6 ------
 src/sdp-xml.c         |    4 ----
 src/sdpd-request.c    |    2 +-
 src/textfile.c        |    8 ++++++++
 test/hciemu.c         |    6 ++++++
 test/hstest.c         |    7 ++++++-
 test/rctest.c         |    2 --
 test/scotest.c        |    2 --
 test/test-textfile.c  |    2 ++
 tools/hciattach.c     |    6 +++---
 tools/hcitool.c       |    2 --
 26 files changed, 65 insertions(+), 48 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 360218b..61c9ed1 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -71,13 +71,12 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
 {
 	bt_uuid_t prim;
 	guint16 plen;
-	uint8_t op;
 
 	bt_uuid16_create(&prim, GATT_PRIM_SVC_UUID);
 
 	if (uuid == NULL) {
-		/* Discover all primary services */
-		op = ATT_OP_READ_BY_GROUP_REQ;
+		/* Discover all primary services
+		   op = ATT_OP_READ_BY_GROUP_REQ; */
 		plen = enc_read_by_grp_req(start, end, &prim, pdu, len);
 	} else {
 		uint16_t u16;
@@ -85,8 +84,8 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
 		const void *value;
 		int vlen;
 
-		/* Discover primary service by service UUID */
-		op = ATT_OP_FIND_BY_TYPE_REQ;
+		/* Discover primary service by service UUID
+		   op = ATT_OP_FIND_BY_TYPE_REQ; */
 
 		if (uuid->type == BT_UUID16) {
 			u16 = htobs(uuid->value.u16);
diff --git a/audio/a2dp.c b/audio/a2dp.c
index 9cd7207..2333dee 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -2038,7 +2038,6 @@ unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
 	struct avdtp_media_codec_capability *codec_cap = NULL;
 	int posix_err;
 	bdaddr_t src;
-	uint8_t remote_type;
 
 	avdtp_get_peers(session, &src, NULL);
 	server = find_server(servers, &src);
@@ -2085,9 +2084,9 @@ unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
 	case AVDTP_STATE_IDLE:
 		if (sep->type == AVDTP_SEP_TYPE_SOURCE) {
 			l = server->sources;
-			remote_type = AVDTP_SEP_TYPE_SINK;
+			/* remote_type = AVDTP_SEP_TYPE_SINK; */
 		} else {
-			remote_type = AVDTP_SEP_TYPE_SOURCE;
+			/* remote_type = AVDTP_SEP_TYPE_SOURCE; */
 			l = server->sinks;
 		}
 
diff --git a/audio/manager.c b/audio/manager.c
index 7e206be..ec667d5 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -562,7 +562,6 @@ static void hf_io_cb(GIOChannel *chan, gpointer data)
 	GError *err = NULL;
 	uint8_t ch;
 	const char *server_uuid, *remote_uuid;
-	uint16_t svclass;
 	struct audio_device *device;
 	int perr;
 
@@ -580,7 +579,7 @@ static void hf_io_cb(GIOChannel *chan, gpointer data)
 
 	server_uuid = HFP_AG_UUID;
 	remote_uuid = HFP_HS_UUID;
-	svclass = HANDSFREE_AGW_SVCLASS_ID;
+	/* svclass = HANDSFREE_AGW_SVCLASS_ID; */
 
 	device = manager_get_device(&src, &dst, TRUE);
 	if (!device)
diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c
index 799f17f..2d9f178 100644
--- a/audio/pcm_bluetooth.c
+++ b/audio/pcm_bluetooth.c
@@ -820,7 +820,7 @@ static int bluetooth_playback_poll_revents(snd_pcm_ioplug_t *io,
 					unsigned short *revents)
 {
 	static char buf[1];
-	int ret;
+	int ret = 0;
 
 	DBG("");
 
@@ -838,7 +838,7 @@ static int bluetooth_playback_poll_revents(snd_pcm_ioplug_t *io,
 
 	*revents = (pfds[0].revents & POLLIN) ? POLLOUT : 0;
 
-	return 0;
+	return ret;
 }
 
 
diff --git a/btio/btio.c b/btio/btio.c
index 6d71b90..6bfa619 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -884,6 +884,7 @@ static gboolean l2cap_get(int sock, GError **err, BtIOOption opt1,
 			*(va_arg(args, uint8_t *)) = l2o.mode;
 			break;
 		case BT_IO_OPT_FLUSHABLE:
+			flushable = TRUE;
 			if (l2cap_get_flushable(sock, &flushable) < 0) {
 				ERROR_FAILED(err, "get_flushable", errno);
 				return FALSE;
@@ -1135,6 +1136,10 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data,
 	if (!(pfd.revents & POLLOUT)) {
 		int ret;
 		ret = read(sock, &c, 1);
+		if (ret == -1) {
+			ERROR_FAILED(err, "read", errno);
+			return FALSE;
+		}
 	}
 
 	accept_add(io, connect, user_data, destroy);
diff --git a/compat/fakehid.c b/compat/fakehid.c
index b996d10..0974d0a 100644
--- a/compat/fakehid.c
+++ b/compat/fakehid.c
@@ -60,13 +60,13 @@ static void sig_term(int sig)
 	__io_canceled = 1;
 }
 
-static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
+static int send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 {
 	struct uinput_event event;
 	int len;
 
 	if (fd <= fileno(stderr))
-		return;
+		return -1;
 
 	memset(&event, 0, sizeof(event));
 	event.type = type;
@@ -74,6 +74,8 @@ static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 	event.value = value;
 
 	len = write(fd, &event, sizeof(event));
+
+	return len;
 }
 
 static int uinput_create(char *name, int keyboard, int mouse)
diff --git a/cups/hcrp.c b/cups/hcrp.c
index 7aafcdc..e2e8ce3 100644
--- a/cups/hcrp.c
+++ b/cups/hcrp.c
@@ -94,8 +94,12 @@ static int hcrp_credit_grant(int sk, uint16_t tid, uint32_t credit)
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	memcpy(buf + HCRP_PDU_HDR_SIZE, &cp, HCRP_CREDIT_GRANT_CP_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE + HCRP_CREDIT_GRANT_CP_SIZE);
+	if (len == -1)
+		return -1;
 
 	len = read(sk, buf, sizeof(buf));
+	if (len == -1)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_GRANT_RP_SIZE);
 
@@ -119,8 +123,12 @@ static int hcrp_credit_request(int sk, uint16_t tid, uint32_t *credit)
 	hdr.plen = htons(0);
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
+	if (len == -1)
+		return -1;
 
 	len = read(sk, buf, sizeof(buf));
+	if (len == -1)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_CREDIT_REQUEST_RP_SIZE);
 
@@ -147,8 +155,12 @@ static int hcrp_get_lpt_status(int sk, uint16_t tid, uint8_t *lpt_status)
 	hdr.plen = htons(0);
 	memcpy(buf, &hdr, HCRP_PDU_HDR_SIZE);
 	len = write(sk, buf, HCRP_PDU_HDR_SIZE);
+	if (len == -1)
+		return -1;
 
 	len = read(sk, buf, sizeof(buf));
+	if (len == -1)
+		return -1;
 	memcpy(&hdr, buf, HCRP_PDU_HDR_SIZE);
 	memcpy(&rp, buf + HCRP_PDU_HDR_SIZE, HCRP_GET_LPT_STATUS_RP_SIZE);
 
diff --git a/gdbus/object.c b/gdbus/object.c
index eaa2e1a..d17a101 100644
--- a/gdbus/object.c
+++ b/gdbus/object.c
@@ -255,14 +255,13 @@ void g_dbus_pending_success(DBusConnection *connection,
 
         for (list = pending_security; list; list = list->next) {
 		struct security_data *secdata = list->data;
-		DBusHandlerResult result;
 
 		if (secdata->pending != pending)
 			continue;
 
 		pending_security = g_slist_remove(pending_security, secdata);
 
-		result = process_message(connection, secdata->message,
+		process_message(connection, secdata->message,
 				secdata->method, secdata->iface_user_data);
 
 		dbus_message_unref(secdata->message);
diff --git a/input/device.c b/input/device.c
index 554f5ac..550e1c7 100644
--- a/input/device.c
+++ b/input/device.c
@@ -250,7 +250,7 @@ static int decode_key(const char *str)
 static void send_event(int fd, uint16_t type, uint16_t code, int32_t value)
 {
 	struct uinput_event event;
-	int err;
+	int __attribute__((__unused__)) err;
 
 	memset(&event, 0, sizeof(event));
 	event.type	= type;
diff --git a/input/server.c b/input/server.c
index d98018b..15bf5b3 100644
--- a/input/server.c
+++ b/input/server.c
@@ -91,7 +91,8 @@ static void connect_event_cb(GIOChannel *chan, GError *err, gpointer data)
 	/* Send unplug virtual cable to unknown devices */
 	if (ret == -ENOENT && psm == L2CAP_PSM_HIDP_CTRL) {
 		unsigned char unplug = 0x15;
-		int err, sk = g_io_channel_unix_get_fd(chan);
+		int __attribute__((__unused__)) err;
+		int sk = g_io_channel_unix_get_fd(chan);
 		err = write(sk, &unplug, sizeof(unplug));
 	}
 
diff --git a/lib/sdp.c b/lib/sdp.c
index d24d1e2..d852587 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -3319,7 +3319,7 @@ int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search,
 	uint32_t reqsize = 0, _reqsize;
 	uint32_t rspsize = 0, rsplen;
 	int seqlen = 0;
-	int total_rec_count, rec_count;
+	int __attribute__((__unused__)) total_rec_count, rec_count;
 	unsigned scanned, pdata_len;
 	uint8_t *pdata, *_pdata;
 	uint8_t *reqbuf, *rspbuf;
diff --git a/network/common.c b/network/common.c
index ef72679..38d2c49 100644
--- a/network/common.c
+++ b/network/common.c
@@ -215,7 +215,7 @@ int bnep_if_up(const char *devname)
 int bnep_if_down(const char *devname)
 {
 	struct ifreq ifr;
-	int sk, err;
+	int sk, __attribute__((__unused__)) err;
 
 	sk = socket(AF_INET, SOCK_DGRAM, 0);
 
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 2c49e35..49dd48d 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2754,7 +2754,7 @@ static void init_conn_list(int index)
 	struct dev_info *dev = &devs[index];
 	struct hci_conn_list_req *cl;
 	struct hci_conn_info *ci;
-	int err, i;
+	int i;
 
 	DBG("hci%d", index);
 
@@ -2780,8 +2780,6 @@ static void init_conn_list(int index)
 		conn->handle = ci->handle;
 	}
 
-	err = 0;
-
 failed:
 	g_free(cl);
 }
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 9e1cfac..b831044 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -207,7 +207,7 @@ static int mgmt_update_powered(int index, uint8_t powered)
 {
 	struct controller_info *info;
 	struct btd_adapter *adapter;
-	gboolean pairable, discoverable;
+	gboolean pairable;
 	uint8_t on_mode;
 
 	if (index > max_index) {
@@ -238,8 +238,6 @@ static int mgmt_update_powered(int index, uint8_t powered)
 
 	btd_adapter_get_mode(adapter, NULL, &on_mode, &pairable);
 
-	discoverable = (on_mode == MODE_DISCOVERABLE);
-
 	if (on_mode == MODE_DISCOVERABLE && !info->discoverable)
 		mgmt_set_discoverable(index, TRUE);
 	else if (on_mode == MODE_CONNECTABLE && !info->connectable)
diff --git a/sbc/sbcinfo.c b/sbc/sbcinfo.c
index 6d92679..63f05aa 100644
--- a/sbc/sbcinfo.c
+++ b/sbc/sbcinfo.c
@@ -281,7 +281,7 @@ static int analyze_file(char *filename)
 	printf("Subbands\t\t%d\n", subbands);
 	printf("Block length\t\t%d\n", blocks);
 	printf("Sampling frequency\t%s\n", freq2str(freq));
-	printf("Channel mode\t\t%s\n", mode2str(hdr.channel_mode));
+	printf("Channel mode\t\t%s\n", mode2str(mode));
 	printf("Allocation method\t%s\n", method ? "SNR" : "Loudness");
 	printf("Bitpool\t\t\t%d", bitpool[0]);
 	for (n = 1; n < SIZE; n++)
diff --git a/src/adapter.c b/src/adapter.c
index f068335..76fc01b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -476,13 +476,10 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode,
 {
 	int err;
 	const char *modestr;
-	gboolean discoverable;
 
 	if (adapter->pending_mode != NULL)
 		return -EALREADY;
 
-	discoverable = new_mode == MODE_DISCOVERABLE;
-
 	if (!adapter->up && new_mode != MODE_OFF) {
 		err = adapter_ops->set_powered(adapter->dev_id, TRUE);
 		if (err < 0)
@@ -3405,7 +3402,6 @@ gboolean adapter_powering_down(struct btd_adapter *adapter)
 int btd_adapter_restore_powered(struct btd_adapter *adapter)
 {
 	char mode[14], address[18];
-	gboolean discoverable;
 
 	if (!adapter_ops)
 		return -EINVAL;
@@ -3421,8 +3417,6 @@ int btd_adapter_restore_powered(struct btd_adapter *adapter)
 						g_str_equal(mode, "off"))
 		return 0;
 
-	discoverable = get_mode(&adapter->bdaddr, mode) == MODE_DISCOVERABLE;
-
 	return adapter_ops->set_powered(adapter->dev_id, TRUE);
 }
 
diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index 3aa9df0..62226cc 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -47,7 +47,6 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
 	int i, hex;
 	char buf[STRBUFSIZE];
 	char indent[MAXINDENT];
-	char next_indent[MAXINDENT];
 
 	if (!value)
 		return;
@@ -57,12 +56,9 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
 
 	for (i = 0; i < indent_level; i++) {
 		indent[i] = '\t';
-		next_indent[i] = '\t';
 	}
 
 	indent[i] = '\0';
-	next_indent[i] = '\t';
-	next_indent[i + 1] = '\0';
 
 	buf[STRBUFSIZE - 1] = '\0';
 
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 1722f78..287acc2 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -962,7 +962,7 @@ static void process_request(sdp_req_t *req)
 	sdp_pdu_hdr_t *rsphdr;
 	sdp_buf_t rsp;
 	uint8_t *buf = malloc(USHRT_MAX);
-	int sent = 0;
+	int __attribute__((__unused__)) sent = 0;
 	int status = SDP_INVALID_SYNTAX;
 
 	memset(buf, 0, USHRT_MAX);
diff --git a/src/textfile.c b/src/textfile.c
index d115ff6..2645f9a 100644
--- a/src/textfile.c
+++ b/src/textfile.c
@@ -204,6 +204,10 @@ static int write_key(const char *pathname, const char *key, const char *value, i
 	if (!size) {
 		if (value) {
 			pos = lseek(fd, size, SEEK_SET);
+			if (pos == (off_t) -1) {
+				err = errno;
+				goto unlock;
+			}
 			err = write_key_value(fd, key, value);
 		}
 		goto unlock;
@@ -222,6 +226,10 @@ static int write_key(const char *pathname, const char *key, const char *value, i
 		if (value) {
 			munmap(map, size);
 			pos = lseek(fd, size, SEEK_SET);
+			if (pos == (off_t) -1) {
+				err = errno;
+				goto unlock;
+			}
 			err = write_key_value(fd, key, value);
 		}
 		goto unlock;
diff --git a/test/hciemu.c b/test/hciemu.c
index 66f99a9..3048285 100644
--- a/test/hciemu.c
+++ b/test/hciemu.c
@@ -222,7 +222,11 @@ static int write_snoop(int fd, int type, int incoming, unsigned char *buf, int l
 		pkt.flags |= ntohl(0x02);
 
 	err = write(fd, &pkt, BTSNOOP_PKT_SIZE);
+	if (err == -1)
+		return -1;
 	err = write(fd, buf, size);
+	if (err == -1)
+		return -1;
 
 	return 0;
 }
@@ -899,6 +903,8 @@ static gboolean io_acl_data(GIOChannel *chan, GIOCondition cond, gpointer data)
 	write_snoop(vdev.dd, HCI_ACLDATA_PKT, 1, buf, len);
 
 	err = write(vdev.fd, buf, len);
+	if (err == -1)
+		return FALSE;
 
 	return TRUE;
 }
diff --git a/test/hstest.c b/test/hstest.c
index 08f2257..63c402b 100644
--- a/test/hstest.c
+++ b/test/hstest.c
@@ -244,8 +244,13 @@ int main(int argc, char *argv[])
 
 	fprintf(stderr, "SCO audio channel connected (handle %d, mtu %d)\n", sco_handle, sco_mtu);
 
-	if (mode == RECORD)
+	if (mode == RECORD) {
 		err = write(rd, "RING\r\n", 6);
+		if (err == -1) {
+			perror("Can't write \"RING\"");
+			return -1;
+		}
+	}
 
 	maxfd = (rd > sd) ? rd : sd;
 
diff --git a/test/rctest.c b/test/rctest.c
index b3804f5..9754f52 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -417,13 +417,11 @@ static void recv_mode(int sk)
 	struct timeval tv_beg, tv_end, tv_diff;
 	char ts[30];
 	long total;
-	uint32_t seq;
 
 	syslog(LOG_INFO, "Receiving ...");
 
 	memset(ts, 0, sizeof(ts));
 
-	seq = 0;
 	while (1) {
 		gettimeofday(&tv_beg,NULL);
 		total = 0;
diff --git a/test/scotest.c b/test/scotest.c
index 50b622a..17bd8a6 100644
--- a/test/scotest.c
+++ b/test/scotest.c
@@ -216,11 +216,9 @@ static void recv_mode(int sk)
 {
 	struct timeval tv_beg,tv_end,tv_diff;
 	long total;
-	uint32_t seq;
 
 	syslog(LOG_INFO, "Receiving ...");
 
-	seq = 0;
 	while (1) {
 		gettimeofday(&tv_beg, NULL);
 		total = 0;
diff --git a/test/test-textfile.c b/test/test-textfile.c
index 970e9e7..7adc3da 100644
--- a/test/test-textfile.c
+++ b/test/test-textfile.c
@@ -51,6 +51,8 @@ int main(int argc, char *argv[])
 
 	fd = creat(filename, 0644);
 	err = ftruncate(fd, 0);
+	if (err == -1)
+		fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
 
 	memset(value, 0, sizeof(value));
 	for (i = 0; i < (size / sizeof(value)); i++)
diff --git a/tools/hciattach.c b/tools/hciattach.c
index e4d5aa1..bc56f31 100644
--- a/tools/hciattach.c
+++ b/tools/hciattach.c
@@ -351,7 +351,7 @@ static int bcsp_max_retries = 10;
 static void bcsp_tshy_sig_alarm(int sig)
 {
 	unsigned char bcsp_sync_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xda,0xdc,0xed,0xed,0xc0};
-	int len;
+	int __attribute__((__unused__)) len;
 	static int retries = 0;
 
 	if (retries < bcsp_max_retries) {
@@ -369,7 +369,7 @@ static void bcsp_tshy_sig_alarm(int sig)
 static void bcsp_tconf_sig_alarm(int sig)
 {
 	unsigned char bcsp_conf_pkt[10] = {0xc0,0x00,0x41,0x00,0xbe,0xad,0xef,0xac,0xed,0xc0};
-	int len;
+	int __attribute__((__unused__)) len;
 	static int retries = 0;
 
 	if (retries < bcsp_max_retries){
@@ -394,7 +394,7 @@ static int bcsp(int fd, struct uart_t *u, struct termios *ti)
 		bcspconf[4]     = {0xad,0xef,0xac,0xed},
 		bcspconfresp[4] = {0xde,0xad,0xd0,0xd0};
 	struct sigaction sa;
-	int len;
+	int __attribute__((__unused__)) len;
 
 	if (set_speed(fd, ti, u->speed) < 0) {
 		perror("Can't set default baud rate");
diff --git a/tools/hcitool.c b/tools/hcitool.c
index a117449..ece187c 100644
--- a/tools/hcitool.c
+++ b/tools/hcitool.c
@@ -2351,7 +2351,6 @@ static int print_advertising_devices(int dd, uint8_t filter_type)
 	unsigned char buf[HCI_MAX_EVENT_SIZE], *ptr;
 	struct hci_filter nf, of;
 	socklen_t olen;
-	hci_event_hdr *hdr;
 	int num, len;
 
 	olen = sizeof(of);
@@ -2382,7 +2381,6 @@ static int print_advertising_devices(int dd, uint8_t filter_type)
 			goto done;
 		}
 
-		hdr = (void *) (buf + 1);
 		ptr = buf + (1 + HCI_EVENT_HDR_SIZE);
 		len -= (1 + HCI_EVENT_HDR_SIZE);
 
-- 
1.7.5


[-- Attachment #3: 0001-Remove-obsolete-Sixaxis-enablement-in-hidd.patch --]
[-- Type: text/x-patch, Size: 1180 bytes --]

>From de72d9561310b996fb643d84e678e8cb59fedbfc Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 5 May 2011 19:41:07 +0100
Subject: [PATCH 1/2] Remove obsolete Sixaxis enablement in hidd

Seeing as this is now handled in the kernel.
---
 compat/hidd.c |   13 -------------
 1 files changed, 0 insertions(+), 13 deletions(-)

diff --git a/compat/hidd.c b/compat/hidd.c
index 88944cf..d83d41f 100644
--- a/compat/hidd.c
+++ b/compat/hidd.c
@@ -237,16 +237,6 @@ static int request_encryption(bdaddr_t *src, bdaddr_t *dst)
 	return err;
 }
 
-static void enable_sixaxis(int csk)
-{
-	const unsigned char buf[] = {
-		0x53 /*HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE*/,
-		0xf4,  0x42, 0x03, 0x00, 0x00 };
-	int err;
-
-	err = write(csk, buf, sizeof(buf));
-}
-
 static int create_device(int ctl, int csk, int isk, uint8_t subclass, int nosdp, int nocheck, int bootonly, int encrypt, int timeout)
 {
 	struct hidp_connadd_req req;
@@ -335,9 +325,6 @@ create:
 		req.flags |= (1 << HIDP_BOOT_PROTOCOL_MODE);
 	}
 
-	if (req.vendor == 0x054c && req.product == 0x0268)
-		enable_sixaxis(csk);
-
 	err = ioctl(ctl, HIDPCONNADD, &req);
 
 error:
-- 
1.7.5


^ permalink raw reply related

* Re: [PATCH] Re: Work-around for broken MS device
From: Bastien Nocera @ 2011-05-05 18:37 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ development
In-Reply-To: <1304618532.16101.14.camel@novo.hadess.net>

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

On Thu, 2011-05-05 at 19:02 +0100, Bastien Nocera wrote:
> On Mon, 2009-03-23 at 16:45 +0100, Marcel Holtmann wrote:
> > Hi Bastien,
> > 
> > >>>> As seen in https://bugzilla.redhat.com/show_bug.cgi?id=450081
> > >>>> The Microsoft Wireless Notebook Presenter Mouse 8000 has its name  
> > >>>> in
> > >>>> ISO-8859-1 instead of UTF-8, as required by the BT spec.
> > >>>>
> > >>>> I've implemented a small work-around. This isn't very invasive,  
> > >>>> IMO, as
> > >>>> we already do UTF-8 checks.
> > >>>>
> > >>>> In my tests, this makes the mouse show up as:
> > >>>> Microsoft® Wireless Notebook Presenter Mouse 8000
> > >>>
> > >>> Attached is patch in the proper format.
> > >>
> > >> I see the need for this one, but just a failing UTF-8 check to  
> > >> assume we
> > >> are using ISO-8859-1 is not good enough. Since the mouse has a DID
> > >> record, can we tie this together with the VID and PID?
> > >
> > > In those kind of cases, we can only guess what the encoding would  
> > > be, we
> > > can't detect those encodings reliably. Given that we fallback to the  
> > > old
> > > behaviour when the device, and that ISO-8859-X corresponds 1-1 with
> > > UTF-8 for the ASCII characters, I don't think it's such a stretch to
> > > think that American companies (who'd be using ISO-8859-1) would be the
> > > worst offenders for this sort of mistake.
> > >
> > > I don't think special casing only this device would be a good idea.  
> > > As I
> > > mentioned, I reproduced the bug by making my computer, running BlueZ,
> > > adopt that name.
> > 
> > can we just fallback to ASCII only? Looks better to me than assuming  
> > Latin-1. We replace invalid characters with spaces in that case.
> 
> Patch to do that attached.

And one that compiles (sigh).

[-- Attachment #2: 0001-Handle-non-UTF-8-device-names.patch --]
[-- Type: text/x-patch, Size: 1389 bytes --]

>From 2b4524b060d980a7899c03359cd4943c9ad9cfe4 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Mon, 8 Nov 2010 16:43:42 +0000
Subject: [PATCH] Handle non-UTF-8 device names

http://thread.gmane.org/gmane.linux.bluez.kernel/1687
https://bugzilla.redhat.com/show_bug.cgi?id=450081
---
 src/event.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/event.c b/src/event.c
index d5bf967..6805c0b 100644
--- a/src/event.c
+++ b/src/event.c
@@ -28,6 +28,7 @@
 
 #define _GNU_SOURCE
 #include <stdio.h>
+#include <ctype.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -562,13 +563,17 @@ void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
 	struct remote_dev_info match, *dev_info;
 
 	if (status == 0) {
-		char *end;
-
-		/* It's ok to cast end between const and non-const since
-		 * we know it points to inside of name which is non-const */
-		if (!g_utf8_validate(name, -1, (const char **) &end))
-			*end = '\0';
-
+		if (!g_utf8_validate(name, -1, NULL)) {
+			guint i;
+
+			/* Assume ASCII, and replace all non-ASCII with spaces */
+			for (i = 0; name[i] != '\0'; i++) {
+				if (!isascii (name[i]))
+					name[i] = ' ';
+			}
+			/* Remove leading and trailing whitespace characters */
+			g_strstrip (name);
+		}
 		write_device_name(local, peer, name);
 	}
 
-- 
1.7.5


^ permalink raw reply related

* Re: [PATCH] Re: Work-around for broken MS device
From: Bastien Nocera @ 2011-05-05 18:02 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ development
In-Reply-To: <7B1632C9-FE1A-43EA-A0B6-F26A46F9929F@holtmann.org>

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

On Mon, 2009-03-23 at 16:45 +0100, Marcel Holtmann wrote:
> Hi Bastien,
> 
> >>>> As seen in https://bugzilla.redhat.com/show_bug.cgi?id=450081
> >>>> The Microsoft Wireless Notebook Presenter Mouse 8000 has its name  
> >>>> in
> >>>> ISO-8859-1 instead of UTF-8, as required by the BT spec.
> >>>>
> >>>> I've implemented a small work-around. This isn't very invasive,  
> >>>> IMO, as
> >>>> we already do UTF-8 checks.
> >>>>
> >>>> In my tests, this makes the mouse show up as:
> >>>> Microsoft® Wireless Notebook Presenter Mouse 8000
> >>>
> >>> Attached is patch in the proper format.
> >>
> >> I see the need for this one, but just a failing UTF-8 check to  
> >> assume we
> >> are using ISO-8859-1 is not good enough. Since the mouse has a DID
> >> record, can we tie this together with the VID and PID?
> >
> > In those kind of cases, we can only guess what the encoding would  
> > be, we
> > can't detect those encodings reliably. Given that we fallback to the  
> > old
> > behaviour when the device, and that ISO-8859-X corresponds 1-1 with
> > UTF-8 for the ASCII characters, I don't think it's such a stretch to
> > think that American companies (who'd be using ISO-8859-1) would be the
> > worst offenders for this sort of mistake.
> >
> > I don't think special casing only this device would be a good idea.  
> > As I
> > mentioned, I reproduced the bug by making my computer, running BlueZ,
> > adopt that name.
> 
> can we just fallback to ASCII only? Looks better to me than assuming  
> Latin-1. We replace invalid characters with spaces in that case.

Patch to do that attached.

Cheers

[-- Attachment #2: 0001-Handle-non-UTF-8-device-names.patch --]
[-- Type: text/x-patch, Size: 1227 bytes --]

>From 02180fd9a53d3e544a218b3040ce63dcb58b4560 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Mon, 8 Nov 2010 16:43:42 +0000
Subject: [PATCH] Handle non-UTF-8 device names

http://thread.gmane.org/gmane.linux.bluez.kernel/1687
https://bugzilla.redhat.com/show_bug.cgi?id=450081
---
 src/event.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/event.c b/src/event.c
index d5bf967..0a2fb0c 100644
--- a/src/event.c
+++ b/src/event.c
@@ -562,13 +562,15 @@ void btd_event_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
 	struct remote_dev_info match, *dev_info;
 
 	if (status == 0) {
-		char *end;
-
-		/* It's ok to cast end between const and non-const since
-		 * we know it points to inside of name which is non-const */
-		if (!g_utf8_validate(name, -1, (const char **) &end))
-			*end = '\0';
-
+		if (!g_utf8_validate(name, -1, NULL)) {
+			/* Assume ASCII, and replace all non-ASCII with spaces */
+			for (i = 0; name[i] != '\0'; i++) {
+				if (!isascii (name[i]))
+					name[i] = ' ';
+			}
+			/* Remove leading and trailing whitespace characters */
+			g_strstrip (name);
+		}
 		write_device_name(local, peer, name);
 	}
 
-- 
1.7.5


^ permalink raw reply related

* Re: [PATCH 2/4] Make adapter API accept binary pincodes
From: Gustavo F. Padovan @ 2011-05-05 17:38 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, johan.hedberg, hadess, dforsi
In-Reply-To: <1302455477-27664-3-git-send-email-dh.herrmann@googlemail.com>

* David Herrmann <dh.herrmann@googlemail.com> [2011-04-10 19:11:15 +0200]:

> Add pin-length argument to adapter API to allow passing binary pins
> containing \0 characters to the hci handler.
> ---
>  src/adapter.c |    4 ++--
>  src/adapter.h |    2 +-
>  src/event.c   |    6 +++---
>  3 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/adapter.c b/src/adapter.c
> index 83f3217..14516ac 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -3701,9 +3701,9 @@ int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr)
>  }
>  
>  int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
> -							const char *pin)
> +							const char *pin, size_t pinlen)

Over column 80 here.

>  {
> -	return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin, pin ? strlen(pin) : 0);
> +	return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin, pinlen);
>  }
>  
>  int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
> diff --git a/src/adapter.h b/src/adapter.h
> index fd2fc12..b507506 100644
> --- a/src/adapter.h
> +++ b/src/adapter.h
> @@ -273,7 +273,7 @@ int btd_adapter_disconnect_device(struct btd_adapter *adapter,
>  int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr);
>  
>  int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
> -							const char *pin);
> +							const char *pin, size_t pinlen);

and here.

>  int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
>  							gboolean success);
>  int btd_adapter_passkey_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
> diff --git a/src/event.c b/src/event.c
> index 4ca1be5..248fb78 100644
> --- a/src/event.c
> +++ b/src/event.c
> @@ -111,13 +111,13 @@ static void pincode_cb(struct agent *agent, DBusError *derr,
>  	device_get_address(device, &dba);
>  
>  	if (derr) {
> -		err = btd_adapter_pincode_reply(adapter, &dba, NULL);
> +		err = btd_adapter_pincode_reply(adapter, &dba, NULL, 0);
>  		if (err < 0)
>  			goto fail;
>  		return;
>  	}
>  
> -	err = btd_adapter_pincode_reply(adapter, &dba, pincode);
> +	err = btd_adapter_pincode_reply(adapter, &dba, pincode, pincode ? strlen(pincode) : 0);

and here.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* Re: [PATCH v2 00/13] Discovery Cleanup - Step 1
From: Claudio Takahasi @ 2011-05-05 17:34 UTC (permalink / raw)
  To: Claudio Takahasi, linux-bluetooth; +Cc: Marcel Holtmann
In-Reply-To: <20110505083417.GB24639@jh-x301>

Hi Johan,

On Thu, May 5, 2011 at 5:34 AM, Johan Hedberg <johan.hedberg@gmail.com> wro=
te:
> Hi Claudio,
>
> On Tue, May 03, 2011, Claudio Takahasi wrote:
>> This patch series is the first step to cleanup the device discovery
>> procedure. The main changes are:
>> =C2=A0 - Unify advertising reports and inquiry results: mgmt sends
>> =C2=A0 =C2=A0 one device found event
>> =C2=A0 - Logic improvement/cleanup: device found
>> =C2=A0 - Move EIR functions to a new file
>> =C2=A0 - Add BDADDR type constants: necessary L2CAP connections and bond=
ing
>>
>>
>>
>> Bruna Moreira (3):
>> =C2=A0 Remove btd_event_advertising_report
>> =C2=A0 Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH
>> =C2=A0 Drop variable EIR length
>>
>> Claudio Takahasi (10):
>> =C2=A0 Move EIR related functions to a new file
>> =C2=A0 Add Bluetooth address type definition
>> =C2=A0 Initial device found cleanup
>> =C2=A0 Move legacy verification to a new function
>> =C2=A0 Cleanup read name and alias from storage
>> =C2=A0 Don't resolve name if the name is in the storage
>> =C2=A0 Unify inquiry results and advertises
>> =C2=A0 Fix memory leak of EIR data
>> =C2=A0 Change the order to write/read the remote's name
>> =C2=A0 Cleanup inserting new device found entry
>>
>> =C2=A0Makefile.am =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A02 +-
>> =C2=A0lib/bluetooth.h =C2=A0 | =C2=A0 =C2=A04 +
>> =C2=A0plugins/hciops.c =C2=A0| =C2=A0202 +++++--------------------------=
--
>> =C2=A0plugins/mgmtops.c | =C2=A0 =C2=A03 +-
>> =C2=A0src/adapter.c =C2=A0 =C2=A0 | =C2=A0182 +++++++++++++++++++-------=
----
>> =C2=A0src/adapter.h =C2=A0 =C2=A0 | =C2=A0 =C2=A09 +-
>> =C2=A0src/eir.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0328 ++++++++++++++++=
+++++++++++++++++++++++++++++++++++++
>> =C2=A0src/eir.h =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 41 +++++++
>> =C2=A0src/event.c =C2=A0 =C2=A0 =C2=A0 | =C2=A0224 +--------------------=
---------------
>> =C2=A0src/event.h =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A05 +-
>> =C2=A0src/sdpd.h =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 14 ---
>> =C2=A011 files changed, 530 insertions(+), 484 deletions(-)
>> =C2=A0create mode 100644 src/eir.c
>> =C2=A0create mode 100644 src/eir.h
>
> These patches don't seem to apply any more after I applied Andr=C3=A9s
> patches. (also, I can't really try applying anything else except 1/13
> since 2/13 is already the address type patch which is still being
> discussed).
>
> Johan
>

I am aware of this conflict. Patches are already rebased, but I will
wait Marcel's blessing(for the address type) before to send again the
patch series.

BR,
Claudio.

^ permalink raw reply

* Re: [PATCH 1/4] Add length argument to hci pincode reply
From: Gustavo F. Padovan @ 2011-05-05 17:34 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, johan.hedberg, hadess, dforsi
In-Reply-To: <1302455477-27664-2-git-send-email-dh.herrmann@googlemail.com>

* David Herrmann <dh.herrmann@googlemail.com> [2011-04-10 19:11:14 +0200]:

> This adds a new "length" argument to the hci pincode reply to allow
> sending binary pins including \0 characters.
> ---
>  plugins/hciops.c  |    9 ++++-----
>  plugins/mgmtops.c |   14 ++++++--------
>  src/adapter.c     |    2 +-
>  src/adapter.h     |    2 +-
>  4 files changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/plugins/hciops.c b/plugins/hciops.c
> index 93f6f21..afac330 100644
> --- a/plugins/hciops.c
> +++ b/plugins/hciops.c
> @@ -3296,7 +3296,7 @@ static int hciops_remove_bonding(int index, bdaddr_t *bdaddr)
>  	return 0;
>  }
>  
> -static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
> +static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin, size_t pinlen)
>  {
>  	struct dev_info *dev = &devs[index];
>  	char addr[18];
> @@ -3307,14 +3307,13 @@ static int hciops_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
>  
>  	if (pin) {
>  		pin_code_reply_cp pr;
> -		size_t len = strlen(pin);
>  
> -		dev->pin_length = len;
> +		dev->pin_length = pinlen;
>  
>  		memset(&pr, 0, sizeof(pr));
>  		bacpy(&pr.bdaddr, bdaddr);
> -		memcpy(pr.pin_code, pin, len);
> -		pr.pin_len = len;
> +		memcpy(pr.pin_code, pin, pinlen);
> +		pr.pin_len = pinlen;
>  		err = hci_send_cmd(dev->sk, OGF_LINK_CTL,
>  						OCF_PIN_CODE_REPLY,
>  						PIN_CODE_REPLY_CP_SIZE, &pr);
> diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
> index 042afc5..d03a29d 100644
> --- a/plugins/mgmtops.c
> +++ b/plugins/mgmtops.c
> @@ -493,7 +493,7 @@ static void mgmt_connect_failed(int sk, uint16_t index, void *buf, size_t len)
>  	btd_event_bonding_complete(&info->bdaddr, &ev->bdaddr, ev->status);
>  }
>  
> -static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
> +static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin, size_t pinlen)

This is over 80 characters. And call pinlen, pin_len instead to keep the same
name and have a small diff here.

>  {
>  	char buf[MGMT_HDR_SIZE + sizeof(struct mgmt_cp_pin_code_reply)];
>  	struct mgmt_hdr *hdr = (void *) buf;
> @@ -501,7 +501,7 @@ static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
>  	char addr[18];
>  
>  	ba2str(bdaddr, addr);
> -	DBG("index %d addr %s pin %s", index, addr, pin ? pin : "<none>");
> +	DBG("index %d addr %s pinlen %lu", index, addr, pinlen);
>  
>  	memset(buf, 0, sizeof(buf));
>  
> @@ -518,10 +518,8 @@ static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
>  		buf_len = sizeof(*hdr) + sizeof(*cp);
>  	} else {
>  		struct mgmt_cp_pin_code_reply *cp;
> -		size_t pin_len;
>  
> -		pin_len = strlen(pin);
> -		if (pin_len > 16)
> +		if (pinlen > 16)
>  			return -EINVAL;
>  
>  		hdr->opcode = htobs(MGMT_OP_PIN_CODE_REPLY);
> @@ -530,8 +528,8 @@ static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin)
>  
>  		cp = (void *) &buf[sizeof(*hdr)];
>  		bacpy(&cp->bdaddr, bdaddr);
> -		cp->pin_len = pin_len;
> -		memcpy(cp->pin_code, pin, pin_len);
> +		cp->pin_len = pinlen;
> +		memcpy(cp->pin_code, pin, pinlen);
>  
>  		buf_len = sizeof(*hdr) + sizeof(*cp);
>  	}
> @@ -568,7 +566,7 @@ static void mgmt_pin_code_request(int sk, uint16_t index, void *buf, size_t len)
>  	err = btd_event_request_pin(&info->bdaddr, &ev->bdaddr);
>  	if (err < 0) {
>  		error("btd_event_request_pin: %s", strerror(-err));
> -		mgmt_pincode_reply(index, &ev->bdaddr, NULL);
> +		mgmt_pincode_reply(index, &ev->bdaddr, NULL, 0);
>  	}
>  }
>  
> diff --git a/src/adapter.c b/src/adapter.c
> index c400bfd..83f3217 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -3703,7 +3703,7 @@ int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr)
>  int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
>  							const char *pin)
>  {
> -	return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin);
> +	return adapter_ops->pincode_reply(adapter->dev_id, bdaddr, pin, pin ? strlen(pin) : 0);

Over 80 here as well.

>  }
>  
>  int btd_adapter_confirm_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
> diff --git a/src/adapter.h b/src/adapter.h
> index 308af75..fd2fc12 100644
> --- a/src/adapter.h
> +++ b/src/adapter.h
> @@ -221,7 +221,7 @@ struct btd_adapter_ops {
>  	int (*read_local_features) (int index, uint8_t *features);
>  	int (*disconnect) (int index, bdaddr_t *bdaddr);
>  	int (*remove_bonding) (int index, bdaddr_t *bdaddr);
> -	int (*pincode_reply) (int index, bdaddr_t *bdaddr, const char *pin);
> +	int (*pincode_reply) (int index, bdaddr_t *bdaddr, const char *pin, size_t pinlen);

same here.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* Re: [PATCH] Bluetooth: Allow unsegmented SDU retries on sock_queue_rcv_skb failure.
From: Gustavo F. Padovan @ 2011-05-05 16:30 UTC (permalink / raw)
  To: Ruiyi Zhang; +Cc: linux-bluetooth
In-Reply-To: <1303990781-15538-1-git-send-email-Ruiyi.zhang@atheros.com>

Hi Ruiyi,

* Ruiyi Zhang <Ruiyi.zhang@atheros.com> [2011-04-28 19:39:41 +0800]:

>  In L2CAP_SDU_UNSEGMENTED case, if sock_queue_rcv_skb returns error,
>  l2cap_ertm_reassembly_sdu should not return 0 so as to insert the
>  skb into BUSY_QUEUE for later retries.
> 
> 
> Signed-off-by: Ruiyi Zhang <Ruiyi.zhang@atheros.com>
> ---
>  net/bluetooth/l2cap_core.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
> 
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index ca27f3a..3b2f140 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -2784,8 +2784,7 @@ static int l2cap_ertm_reassembly_sdu(struct sock *sk, struct sk_buff *skb, u16 c
>  			goto drop;
>  
>  		err = sock_queue_rcv_skb(sk, skb);
> -		if (!err)
> -			return err;
> +		return err;
>  
>  		break;

I prefer simply
		return sock_queue_rcv_skb();

and remove the break inclusive.

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply

* Re: [PATCH] bluetooth: fix shutdown on SCO sockets
From: Luiz Augusto von Dentz @ 2011-05-05 14:50 UTC (permalink / raw)
  To: Luiz Augusto von Dentz, linux-bluetooth
In-Reply-To: <20110418175619.GB2472@joana>

Hi Gustavo,

On Mon, Apr 18, 2011 at 8:56 PM, Gustavo F. Padovan
<padovan@profusion.mobi> wrote:
> * Luiz Augusto von Dentz <luiz.dentz@gmail.com> [2011-04-17 20:26:53 +0300]:
>
>> Hi Gustavo,
>>
>> On Fri, Apr 15, 2011 at 9:58 PM, Gustavo F. Padovan
>> <padovan@profusion.mobi> wrote:
>> > Hi Luiz,
>> >
>> > * Luiz Augusto von Dentz <luiz.dentz@gmail.com> [2011-04-08 17:10:41 +0300]:
>> >
>> >> From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
>> >>
>> >> shutdown should wait for SCO link to be properly disconnected before
>> >> detroying the socket, otherwise an application using the socket may
>> >> assume link is properly disconnected before it really happens which
>> >> can be a problem when e.g synchronizing profile switch.
>> >>
>> >> Signed-off-by: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
>> >
>> > I applied it, but in bluetooth-next. Let's see its behaviour there and if no
>> > problems show up we can move it to bluetooth-2.6
>>
>> I tested this against Nokia BH-504 and Sony Ericsson W600, both have
>> problem when switching from hfp to a2dp where the avdtp start is sent
>> before SCO is fully disconnected, this patch fixes with those
>> headsets.
>
> Ok, I also pushed it to bluetooth-2.6.


Apparently this cause a regression, since we set conn to NULL but an
application may not wait for shutdown to complete and call
close/release which will cause sco_chan_del to be called which destroy
the socket without resetting conn->sk to NULL so on disconn_cfm it
will access invalid memory.

To fix this what about the following:

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 94954c7..cb4fb78 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -373,7 +373,7 @@ static void __sco_sock_close(struct sock *sk)
                        sk->sk_state = BT_DISCONN;
                        sco_sock_set_timer(sk, SCO_DISCONN_TIMEOUT);
                        hci_conn_put(sco_pi(sk)->conn->hcon);
-                       sco_pi(sk)->conn = NULL;
+                       sco_pi(sk)->conn->hcon = NULL;
                } else
                        sco_chan_del(sk, ECONNRESET);
                break;
@@ -828,7 +828,9 @@ static void sco_chan_del(struct sock *sk, int err)
                conn->sk = NULL;
                sco_pi(sk)->conn = NULL;
                sco_conn_unlock(conn);
-               hci_conn_put(conn->hcon);
+
+               if (conn->hcon)
+                       hci_conn_put(conn->hcon);
        }

        sk->sk_state = BT_CLOSED;

I tested it with code waiting for shutdown to complete, watch for
POLL_ERR, and without waiting and it seems to work fine, finally.

-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply related

* Re: [PATCH] Remove btio.c compilation warning
From: Luiz Augusto von Dentz @ 2011-05-05 14:30 UTC (permalink / raw)
  To: Vinicius Costa Gomes
  Cc: Elvis Pfützenreuter, Anderson Briglia, linux-bluetooth
In-Reply-To: <20110505140531.GA27568@piper>

Hi Vinicius,

On Thu, May 5, 2011 at 5:05 PM, Vinicius Costa Gomes
<vinicius.gomes@openbossa.org> wrote:
> Hi Luiz,
>
> On 11:05 Thu 05 May, Luiz Augusto von Dentz wrote:
>
> [snip]
>
>>
>> I don't see why it would be ubuntu specific, this seems to be some
>> kind of regression/'feature' with gcc 4.5.
>
> Yeah, I really believe this is the case. I have gcc 4.5.2 here, that
> would be the version as in Natty, and I don't encounter that problem.

So it seems to be Ubuntu specific in some way, very annoying way.

> The only difference that I could find is that Ubuntu ships gcc with
> a .diff.gz of 1.3MB ;-)
>
> But back to the topic at hand, I agree that the patch should be applied,
> Ubuntu is used by many developers and BlueZ should be kept clean of
> warnings.

Well if we don't get anywhere with the bug Elvis sent than that is the
only think we can do, or maybe there is some new gcc flag that can
prevent such behavior.


-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply

* [PATCH v1] Bluetooth: Double check sec req for pre 2.1 device
From: Waldemar Rymarkiewicz @ 2011-05-05 14:16 UTC (permalink / raw)
  To: padovan, linux-bluetooth; +Cc: Waldemar Rymarkiewicz
In-Reply-To: <1304604978-17895-1-git-send-email-waldemar.rymarkiewicz@tieto.com>

In case of pre v2.1 devices authentication request will return
success immediately if the link key already exists without any
authentication process.

That means, it's not possible to re-authenticate the link if you
already have combination key and for instance want to re-authenticate
to get the high security (use 16 digit pin).

Therefore, it's necessary to check security requirements on auth
complete event to prevent not enough secure connection.

Signed-off-by: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>
---
 include/net/bluetooth/hci_core.h |    4 +++-
 net/bluetooth/hci_conn.c         |   17 +++++++++++++++++
 net/bluetooth/rfcomm/core.c      |    2 +-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 14cc324..1b35c27 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -420,8 +420,10 @@ int hci_conn_del(struct hci_conn *conn);
 void hci_conn_hash_flush(struct hci_dev *hdev);
 void hci_conn_check_pending(struct hci_dev *hdev);
 
-struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type);
+struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
+					__u8 sec_level, __u8 auth_type);
 int hci_conn_check_link_mode(struct hci_conn *conn);
+int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
 int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
 int hci_conn_change_link_key(struct hci_conn *conn);
 int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 7f5ad8a..3163330 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -623,6 +623,23 @@ encrypt:
 }
 EXPORT_SYMBOL(hci_conn_security);
 
+/* Check secure link requirement */
+int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level)
+{
+	BT_DBG("conn %p", conn);
+
+	if (sec_level != BT_SECURITY_HIGH)
+		return 1; /* Accept if non-secure is required */
+
+	if (conn->key_type == HCI_LK_AUTH_COMBINATION ||
+			(conn->key_type == HCI_LK_COMBINATION &&
+			conn->pin_length == 16))
+		return 1;
+
+	return 0; /* Reject not secure link */
+}
+EXPORT_SYMBOL(hci_conn_check_secure);
+
 /* Change link key */
 int hci_conn_change_link_key(struct hci_conn *conn)
 {
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 121a5c1..5759bb7 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -2096,7 +2096,7 @@ static void rfcomm_security_cfm(struct hci_conn *conn, u8 status, u8 encrypt)
 		if (!test_and_clear_bit(RFCOMM_AUTH_PENDING, &d->flags))
 			continue;
 
-		if (!status)
+		if (!status && hci_conn_check_secure(conn, d->sec_level))
 			set_bit(RFCOMM_AUTH_ACCEPT, &d->flags);
 		else
 			set_bit(RFCOMM_AUTH_REJECT, &d->flags);
-- 
1.7.1


^ permalink raw reply related

* [PATCH v1] Bluetooth: Double check sec req for pre 2.1 device
From: Waldemar Rymarkiewicz @ 2011-05-05 14:16 UTC (permalink / raw)
  To: padovan, linux-bluetooth; +Cc: Waldemar Rymarkiewicz

I've changed the function name since hci_conn_check_secure seems more
adequare then hci_conn_accept_secure.

/Waldek

Waldemar Rymarkiewicz (1):
  Bluetooth: Double check sec req for pre 2.1 device

 include/net/bluetooth/hci_core.h |    4 +++-
 net/bluetooth/hci_conn.c         |   17 +++++++++++++++++
 net/bluetooth/rfcomm/core.c      |    2 +-
 3 files changed, 21 insertions(+), 2 deletions(-)


^ permalink raw reply

* Re: BT 3.0 HS Support in BlueZ
From: Luiz Augusto von Dentz @ 2011-05-05 14:13 UTC (permalink / raw)
  To: Arun Kumar SINGH
  Cc: Gustavo F. Padovan, Anurag Gupta, linux-bluetooth@vger.kernel.org
In-Reply-To: <AFCDDB4A3EA003429EEF1E7B211FDBBA3395937A4C@EXDCVYMBSTM005.EQ1STM.local>

Hi,

On Thu, May 5, 2011 at 10:26 AM, Arun Kumar SINGH
<arunkr.singh@stericsson.com> wrote:
> Hi Gustavo,
>
>>> Does anybody know if
>>bluetooth 3.0 HS spec is
>>supported in BlueZ?
>>> Is AMP supported in BlueZ?
>>
>>There is two different
>>implementations, one by
>>Atheros and another by QuIC.
>>Both never reach upstream,
>>if you look to the list logs
>>you will find them.
>
>
> Any hopes of getting this unified version upstream anytime in near future? I guess this has been on the cards for some time now given that merge process started last august.
>
> I am trying to understand the options other folks may have, who may be interested in having 3.0 support in Bluez. Rewriting entire 3.0 support from scratch may be one thing that should be avoided as long as current upstreaming activity doesn't end up in a dead trail.  Which I assume, it hadn't.

Well I would like to test something with obexd/obex-client to see how
we could indicate that high speed is necessary, so it would be very
welcoming if somebody step up and try to make a plan to integrate this
work upstream, otherwise we gonna have to either start from scratch or
pick one that seems to fit best in upstream.


-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply

* Re: [PATCH] Remove btio.c compilation warning
From: Vinicius Costa Gomes @ 2011-05-05 14:05 UTC (permalink / raw)
  To: Luiz Augusto von Dentz
  Cc: Elvis Pfützenreuter, Anderson Briglia, linux-bluetooth
In-Reply-To: <BANLkTikLnb229tLvdeeWMnfqkqdSAva1bQ@mail.gmail.com>

Hi Luiz,

On 11:05 Thu 05 May, Luiz Augusto von Dentz wrote:

[snip]

> 
> I don't see why it would be ubuntu specific, this seems to be some
> kind of regression/'feature' with gcc 4.5.

Yeah, I really believe this is the case. I have gcc 4.5.2 here, that
would be the version as in Natty, and I don't encounter that problem.

The only difference that I could find is that Ubuntu ships gcc with
a .diff.gz of 1.3MB ;-)

But back to the topic at hand, I agree that the patch should be applied,
Ubuntu is used by many developers and BlueZ should be kept clean of 
warnings.

> 
> -- 
> Luiz Augusto von Dentz
> Computer Engineer
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers,
-- 
Vinicius

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox