Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] input: Fix closing sockets when ioctl_connadd() fails
From: Anderson Lizardo @ 2013-01-03  2:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

Instead of calling close() directly, properly shutdown the channel and
set GIOChannel pointers to NULL.

Also remove dead code and do a small refactoring around the code.

Fixes this error detected when HIDP support is disabled on kernel and we
attempt to connect to a BT keyboard:

bluetoothd[5168]: profiles/input/device.c:encrypt_notify()
bluetoothd[5168]: ioctl_connadd(): Protocol not supported(93)
bluetoothd[5168]: profiles/input/device.c:ctrl_watch_cb() Device
CA:FE:CA:FE:CA:FE disconnected

(bluetoothd:5168): GLib-WARNING **: Invalid file descriptor.

bluetoothd[5168]: profiles/input/device.c:intr_watch_cb() Device
CA:FE:CA:FE:CA:FE disconnected

(bluetoothd:5168): GLib-WARNING **: Invalid file descriptor.
---

Let me know if you want me to split the refactoring part in a separate patch.

 profiles/input/device.c |   62 ++++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 33 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 9cea028..2cb44cf 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -136,8 +136,10 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
 
 	idev->intr_watch = 0;
 
-	g_io_channel_unref(idev->intr_io);
-	idev->intr_io = NULL;
+	if (idev->intr_io) {
+		g_io_channel_unref(idev->intr_io);
+		idev->intr_io = NULL;
+	}
 
 	/* Close control channel */
 	if (idev->ctrl_io && !(cond & G_IO_NVAL))
@@ -163,8 +165,10 @@ static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
 
 	idev->ctrl_watch = 0;
 
-	g_io_channel_unref(idev->ctrl_io);
-	idev->ctrl_io = NULL;
+	if (idev->ctrl_io) {
+		g_io_channel_unref(idev->ctrl_io);
+		idev->ctrl_io = NULL;
+	}
 
 	/* Close interrupt channel */
 	if (idev->intr_io && !(cond & G_IO_NVAL))
@@ -271,43 +275,35 @@ static int ioctl_connadd(struct hidp_connadd_req *req)
 	return err;
 }
 
-static void encrypt_completed(uint8_t status, gpointer user_data)
-{
-	struct hidp_connadd_req *req = user_data;
-	int err;
-
-	if (status) {
-		error("Encryption failed: %s(0x%x)",
-				strerror(bt_error(status)), status);
-		goto failed;
-	}
-
-	err = ioctl_connadd(req);
-	if (err == 0)
-		goto cleanup;
-
-	error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
-failed:
-	close(req->intr_sock);
-	close(req->ctrl_sock);
-
-cleanup:
-	free(req->rd_data);
-
-	g_free(req);
-}
-
 static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition,
 								gpointer data)
 {
 	struct input_device *idev = data;
-	struct hidp_connadd_req *req = idev->req;
+	int err;
 
-	DBG(" ");
+	DBG("");
 
-	encrypt_completed(0, req);
+	err = ioctl_connadd(idev->req);
+	if (err < 0) {
+		error("ioctl_connadd(): %s (%d)", strerror(-err), -err);
+
+		if (idev->ctrl_io) {
+			g_io_channel_shutdown(idev->ctrl_io, FALSE, NULL);
+			g_io_channel_unref(idev->ctrl_io);
+			idev->ctrl_io = NULL;
+		}
+
+		if (idev->intr_io) {
+			g_io_channel_shutdown(idev->intr_io, FALSE, NULL);
+			g_io_channel_unref(idev->intr_io);
+			idev->intr_io = NULL;
+		}
+	}
 
 	idev->sec_watch = 0;
+
+	g_free(idev->req->rd_data);
+	g_free(idev->req);
 	idev->req = NULL;
 
 	return FALSE;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 1/2] Bluetooth: Add support for Foxconn / Hon Hai [0489:e04e]
From: AceLan Kao @ 2013-01-03  4:24 UTC (permalink / raw)
  To: linux-bluetooth, Gustavo F. Padovan, Marcel Holtmann,
	Johan Hedberg

Add support for the AR9462 chip

T:  Bus=01 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#=  5 Spd=12  MxCh= 0
D:  Ver= 1.10 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=0489 ProdID=e04e Rev=00.02
C:  #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
I:  If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
---
 drivers/bluetooth/ath3k.c |    2 ++
 drivers/bluetooth/btusb.c |    1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 3418bf9..0649513 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -82,6 +82,7 @@ static struct usb_device_id ath3k_table[] = {
 	{ USB_DEVICE(0x0930, 0x0219) },
 	{ USB_DEVICE(0x0489, 0xe057) },
 	{ USB_DEVICE(0x13d3, 0x3393) },
+	{ USB_DEVICE(0x0489, 0xe04e) },
 
 	/* Atheros AR5BBU12 with sflash firmware */
 	{ USB_DEVICE(0x0489, 0xE02C) },
@@ -110,6 +111,7 @@ static struct usb_device_id ath3k_blist_tbl[] = {
 	{ USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
+	{ USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
 
 	/* Atheros AR5BBU22 with sflash firmware */
 	{ USB_DEVICE(0x0489, 0xE03C), .driver_info = BTUSB_ATH3012 },
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index acd5be4..ba617d6 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -140,6 +140,7 @@ static struct usb_device_id blacklist_table[] = {
 	{ USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
+	{ USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
 
 	/* Atheros AR5BBU12 with sflash firmware */
 	{ USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
-- 
1.7.10.4

^ permalink raw reply related

* [PATCH 2/2] Bluetooth: Add support for Foxconn / Hon Hai [0489:e056]
From: AceLan Kao @ 2013-01-03  4:25 UTC (permalink / raw)
  To: linux-bluetooth, Gustavo F. Padovan, Marcel Holtmann,
	Johan Hedberg
In-Reply-To: <1357187100-9658-1-git-send-email-acelan.kao@canonical.com>

Add support for the AR9462 chip

T: Bus=01 Lev=02 Prnt=02 Port=05 Cnt=01 Dev#= 4 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs= 1
P: Vendor=0489 ProdID=e056 Rev=00.01
C: #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
I: If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb

Signed-off-by: AceLan Kao <acelan.kao@canonical.com>
---
 drivers/bluetooth/ath3k.c |    2 ++
 drivers/bluetooth/btusb.c |    1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index 0649513..0bb42e6 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -83,6 +83,7 @@ static struct usb_device_id ath3k_table[] = {
 	{ USB_DEVICE(0x0489, 0xe057) },
 	{ USB_DEVICE(0x13d3, 0x3393) },
 	{ USB_DEVICE(0x0489, 0xe04e) },
+	{ USB_DEVICE(0x0489, 0xe056) },
 
 	/* Atheros AR5BBU12 with sflash firmware */
 	{ USB_DEVICE(0x0489, 0xE02C) },
@@ -112,6 +113,7 @@ static struct usb_device_id ath3k_blist_tbl[] = {
 	{ USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
+	{ USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
 
 	/* Atheros AR5BBU22 with sflash firmware */
 	{ USB_DEVICE(0x0489, 0xE03C), .driver_info = BTUSB_ATH3012 },
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index ba617d6..170d20d 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -141,6 +141,7 @@ static struct usb_device_id blacklist_table[] = {
 	{ USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
 	{ USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
+	{ USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
 
 	/* Atheros AR5BBU12 with sflash firmware */
 	{ USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
-- 
1.7.10.4

^ permalink raw reply related

* Re: [PATCH BlueZ] input: Fix closing sockets when ioctl_connadd() fails
From: Johan Hedberg @ 2013-01-03  8:32 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: linux-bluetooth
In-Reply-To: <1357178905-22533-1-git-send-email-anderson.lizardo@openbossa.org>

Hi Lizardo,

On Wed, Jan 02, 2013, Anderson Lizardo wrote:
> Instead of calling close() directly, properly shutdown the channel and
> set GIOChannel pointers to NULL.
> 
> Also remove dead code and do a small refactoring around the code.
> 
> Fixes this error detected when HIDP support is disabled on kernel and we
> attempt to connect to a BT keyboard:
> 
> bluetoothd[5168]: profiles/input/device.c:encrypt_notify()
> bluetoothd[5168]: ioctl_connadd(): Protocol not supported(93)
> bluetoothd[5168]: profiles/input/device.c:ctrl_watch_cb() Device
> CA:FE:CA:FE:CA:FE disconnected
> 
> (bluetoothd:5168): GLib-WARNING **: Invalid file descriptor.
> 
> bluetoothd[5168]: profiles/input/device.c:intr_watch_cb() Device
> CA:FE:CA:FE:CA:FE disconnected
> 
> (bluetoothd:5168): GLib-WARNING **: Invalid file descriptor.
> ---
> 
> Let me know if you want me to split the refactoring part in a separate patch.
> 
>  profiles/input/device.c |   62 ++++++++++++++++++++++-------------------------
>  1 file changed, 29 insertions(+), 33 deletions(-)

Looks good, but please split this into two patches.

Johan

^ permalink raw reply

* Re: [PATCH 1/1] adapter, AVCTP: Replaced calls to g_queue_free_full function
From: Luiz Augusto von Dentz @ 2013-01-03 10:27 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: Vinicius Gomes, Giovanni Gherdovich, Anderson Lizardo,
	linux-bluetooth@vger.kernel.org
In-Reply-To: <1357170124.19248.98.camel@aeonflux>

Hi Marcel,

On Thu, Jan 3, 2013 at 1:42 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Luiz,
>
>> >> In that case I would just revert back this patch, but the
>> >> documentation actually say g_slist_free_full is available since 2.28
>> >> http://developer.gnome.org/glib/2.28/glib-Singly-Linked-Lists.html#g-slist-free-full
>> >> so I wonder what is going on.
>> >>
>> >
>> > The problem now is g_queue_free_full() not the g_slist_free_full().
>>
>> Right, but it is quite the same situation and I don't get why we don't
>> just update, by the time distros start to package BlueZ 5 glib 2.32
>> wont be a problem, in fact it should not be a problem right now as it
>> is about a year old release:
>
> because every new GLib release drags in more dependencies. It is a bit
> out of control. So requiring the 2.32 comes at a cost that I am not
> willing to pay right now. We already have seen this with ConnMan where I
> accidentally used a newer GLib function that was not present in a 2.28
> and before. It is pretty hard for embedded system to do these kind of
> upgrades when their dependencies and thus footprint and memory
> consumption increases for just a simple convenience function.

It seems the mandatory glib dependencies are restricted to libffi,
pkg-config and Python:
http://www.linuxfromscratch.org/blfs/view/svn/general/glib2.html

Anyway regardless if we do update or not, I don't see why
g_queue_free_full is different than g_slist_free_full, so instead of
converting everything to g_queue_foreach + g_queue_free why we don't
bring back glib-compat and do this in one place as we did for
g_slist_free_full?

--
Luiz Augusto von Dentz

^ permalink raw reply

* [PATCH 1/2] Bluetooth: Move hci_outgoing_auth_needed() to hci_conn.c
From: Jaganath Kanakkassery @ 2013-01-03 13:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery

This is done so that other files can use this function

Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
---
 include/net/bluetooth/hci_core.h |    1 +
 net/bluetooth/hci_conn.c         |   17 +++++++++++++++++
 net/bluetooth/hci_event.c        |   18 ------------------
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 014a2ea..2e1897c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -706,6 +706,7 @@ int hci_get_dev_info(void __user *arg);
 int hci_get_conn_list(void __user *arg);
 int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
 int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
+int hci_outgoing_auth_needed(struct hci_dev *hdev, struct hci_conn *conn);
 int hci_inquiry(void __user *arg);
 
 struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 25bfce0..7fbabae 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1027,3 +1027,20 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
 
 	return hchan;
 }
+
+int hci_outgoing_auth_needed(struct hci_dev *hdev, struct hci_conn *conn)
+{
+	if (conn->state != BT_CONFIG || !conn->out)
+		return 0;
+
+	if (conn->pending_sec_level == BT_SECURITY_SDP)
+		return 0;
+
+	/* Only request authentication for SSP connections or non-SSP
+	 * devices with sec_level HIGH or if MITM protection is requested */
+	if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) &&
+	    conn->pending_sec_level != BT_SECURITY_HIGH)
+		return 0;
+
+	return 1;
+}
\ No newline at end of file
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 705078a..720d5ec 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1509,24 +1509,6 @@ static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
 	hci_dev_unlock(hdev);
 }
 
-static int hci_outgoing_auth_needed(struct hci_dev *hdev,
-				    struct hci_conn *conn)
-{
-	if (conn->state != BT_CONFIG || !conn->out)
-		return 0;
-
-	if (conn->pending_sec_level == BT_SECURITY_SDP)
-		return 0;
-
-	/* Only request authentication for SSP connections or non-SSP
-	 * devices with sec_level HIGH or if MITM protection is requested */
-	if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) &&
-	    conn->pending_sec_level != BT_SECURITY_HIGH)
-		return 0;
-
-	return 1;
-}
-
 static int hci_resolve_name(struct hci_dev *hdev,
 				   struct inquiry_entry *e)
 {
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 2/2] Bluetooth: Fix authentication if acl data comes before remote feature evt
From: Jaganath Kanakkassery @ 2013-01-03 13:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery
In-Reply-To: <1357218329-21399-1-git-send-email-jaganath.k@samsung.com>

If remote device sends l2cap info request before read_remote_ext_feature
completes then mgmt_connected will be sent in hci_acldata_packet() and
remote name request wont be sent and eventually authentication wont happen

Hcidump log of the issue

< HCI Command: Create Connection (0x01|0x0005) plen 13
    bdaddr BC:85:1F:74:7F:29 ptype 0xcc18 rswitch 0x01 clkoffset 0x4bf7 (valid)
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5
> HCI Event: Command Status (0x0f) plen 4
    Create Connection (0x01|0x0005) status 0x00 ncmd 1
> HCI Event: Connect Complete (0x03) plen 11
    status 0x00 handle 12 bdaddr BC:85:1F:74:7F:29 type ACL encrypt 0x00
< HCI Command: Read Remote Supported Features (0x01|0x001b) plen 2
    handle 12
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
    status 0x00 handle 12
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> HCI Event: Max Slots Change (0x1b) plen 3
    handle 12 slots 5
< HCI Command: Read Remote Extended Features (0x01|0x001c) plen 3
    handle 12 page 1
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> ACL data: handle 12 flags 0x02 dlen 10
    L2CAP(s): Info req: type 2
< ACL data: handle 12 flags 0x00 dlen 16
    L2CAP(s): Info rsp: type 2 result 0
      Extended feature mask 0x00b8
        Enhanced Retransmission mode
        Streaming mode
        FCS Option
        Fixed Channels
> HCI Event: Read Remote Extended Features (0x23) plen 13
    status 0x00 handle 12 page 1 max 1
    Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> ACL data: handle 12 flags 0x02 dlen 10
    L2CAP(s): Info req: type 3
< ACL data: handle 12 flags 0x00 dlen 20
    L2CAP(s): Info rsp: type 3 result 0
      Fixed channel list 0x00000002
        L2CAP Signalling Channel
> HCI Event: Number of Completed Packets (0x13) plen 5
    handle 12 packets 2

Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
---
 net/bluetooth/hci_core.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 596660d..c14def9 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2812,6 +2812,7 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
 
 		hci_dev_lock(hdev);
 		if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
+		    !hci_outgoing_auth_needed(hdev, conn) &&
 		    !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
 			mgmt_device_connected(hdev, &conn->dst, conn->type,
 					      conn->dst_type, 0, NULL, 0,
-- 
1.7.9.5


^ permalink raw reply related

* Re: [PATCH 1/2] Bluetooth: Move hci_outgoing_auth_needed() to hci_conn.c
From: Johan Hedberg @ 2013-01-03 13:51 UTC (permalink / raw)
  To: Jaganath Kanakkassery; +Cc: linux-bluetooth
In-Reply-To: <1357218329-21399-1-git-send-email-jaganath.k@samsung.com>

Hi Jaganath,

On Thu, Jan 03, 2013, Jaganath Kanakkassery wrote:
> This is done so that other files can use this function
> 
> Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
> ---
>  include/net/bluetooth/hci_core.h |    1 +
>  net/bluetooth/hci_conn.c         |   17 +++++++++++++++++
>  net/bluetooth/hci_event.c        |   18 ------------------
>  3 files changed, 18 insertions(+), 18 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 014a2ea..2e1897c 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -706,6 +706,7 @@ int hci_get_dev_info(void __user *arg);
>  int hci_get_conn_list(void __user *arg);
>  int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
>  int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
> +int hci_outgoing_auth_needed(struct hci_dev *hdev, struct hci_conn *conn);
>  int hci_inquiry(void __user *arg);
>  
>  struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
> diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
> index 25bfce0..7fbabae 100644
> --- a/net/bluetooth/hci_conn.c
> +++ b/net/bluetooth/hci_conn.c
> @@ -1027,3 +1027,20 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
>  
>  	return hchan;
>  }
> +
> +int hci_outgoing_auth_needed(struct hci_dev *hdev, struct hci_conn *conn)
> +{
> +	if (conn->state != BT_CONFIG || !conn->out)
> +		return 0;
> +
> +	if (conn->pending_sec_level == BT_SECURITY_SDP)
> +		return 0;
> +
> +	/* Only request authentication for SSP connections or non-SSP
> +	 * devices with sec_level HIGH or if MITM protection is requested */
> +	if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) &&
> +	    conn->pending_sec_level != BT_SECURITY_HIGH)
> +		return 0;
> +
> +	return 1;
> +}

Since you're moving this to hci_conn.c I'd prefix the function with
hci_conn_*. You should also remove the hdev parameter since it's not
used in the function (I believe the only reason it was there was for
consistency in hci_core.c).

Johan

^ permalink raw reply

* Re: [PATCH 2/2] Bluetooth: Fix authentication if acl data comes before remote feature evt
From: Johan Hedberg @ 2013-01-03 14:00 UTC (permalink / raw)
  To: Jaganath Kanakkassery; +Cc: linux-bluetooth
In-Reply-To: <1357218329-21399-2-git-send-email-jaganath.k@samsung.com>

Hi Jaganath,

On Thu, Jan 03, 2013, Jaganath Kanakkassery wrote:
> If remote device sends l2cap info request before read_remote_ext_feature
> completes then mgmt_connected will be sent in hci_acldata_packet() and
> remote name request wont be sent and eventually authentication wont happen
> 
> Hcidump log of the issue
> 
> < HCI Command: Create Connection (0x01|0x0005) plen 13
>     bdaddr BC:85:1F:74:7F:29 ptype 0xcc18 rswitch 0x01 clkoffset 0x4bf7 (valid)
>     Packet type: DM1 DM3 DM5 DH1 DH3 DH5
> > HCI Event: Command Status (0x0f) plen 4
>     Create Connection (0x01|0x0005) status 0x00 ncmd 1
> > HCI Event: Connect Complete (0x03) plen 11
>     status 0x00 handle 12 bdaddr BC:85:1F:74:7F:29 type ACL encrypt 0x00
> < HCI Command: Read Remote Supported Features (0x01|0x001b) plen 2
>     handle 12
> > HCI Event: Command Status (0x0f) plen 4
>     Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> > HCI Event: Read Remote Supported Features (0x0b) plen 11
>     status 0x00 handle 12
>     Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> > HCI Event: Max Slots Change (0x1b) plen 3
>     handle 12 slots 5
> < HCI Command: Read Remote Extended Features (0x01|0x001c) plen 3
>     handle 12 page 1
> > HCI Event: Command Status (0x0f) plen 4
>     Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> > ACL data: handle 12 flags 0x02 dlen 10
>     L2CAP(s): Info req: type 2
> < ACL data: handle 12 flags 0x00 dlen 16
>     L2CAP(s): Info rsp: type 2 result 0
>       Extended feature mask 0x00b8
>         Enhanced Retransmission mode
>         Streaming mode
>         FCS Option
>         Fixed Channels
> > HCI Event: Read Remote Extended Features (0x23) plen 13
>     status 0x00 handle 12 page 1 max 1
>     Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> > ACL data: handle 12 flags 0x02 dlen 10
>     L2CAP(s): Info req: type 3
> < ACL data: handle 12 flags 0x00 dlen 20
>     L2CAP(s): Info rsp: type 3 result 0
>       Fixed channel list 0x00000002
>         L2CAP Signalling Channel
> > HCI Event: Number of Completed Packets (0x13) plen 5
>     handle 12 packets 2
> 
> Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
> ---
>  net/bluetooth/hci_core.c |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 596660d..c14def9 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -2812,6 +2812,7 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
>  
>  		hci_dev_lock(hdev);
>  		if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
> +		    !hci_outgoing_auth_needed(hdev, conn) &&
>  		    !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
>  			mgmt_device_connected(hdev, &conn->dst, conn->type,
>  					      conn->dst_type, 0, NULL, 0,

I'm not completely sure if this is the right way or even the right place
to fix the issue. The reason why this if-clause is here is so that we
don't get a too late mgmt_connected event in case the remote device is
fast in sending an L2CAP Connect Request. Maybe if-clause needs to be
made L2CAP Connect request specific (and moved to an L2CAP specific
location) or then something added to the code path taken for the info
request?

Johan

^ permalink raw reply

* Re: [PATCH BlueZ] input: Fix closing sockets when ioctl_connadd() fails
From: Anderson Lizardo @ 2013-01-03 14:09 UTC (permalink / raw)
  To: Anderson Lizardo, linux-bluetooth
In-Reply-To: <20130103083207.GA11193@x220>

Hi Johan,

On Thu, Jan 3, 2013 at 4:32 AM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> Looks good, but please split this into two patches.

Just sent the split patches, although a little more than two because I
could not find a saner way to split them.

Best Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply

* [PATCH v2 BlueZ 1/6] input: Remove dead code from encrypt_completed()
From: Anderson Lizardo @ 2013-01-03 14:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

"status" is always zero, so this code will never be reached.
---
 profiles/input/device.c |    7 -------
 1 file changed, 7 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 9cea028..7655534 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -276,18 +276,11 @@ static void encrypt_completed(uint8_t status, gpointer user_data)
 	struct hidp_connadd_req *req = user_data;
 	int err;
 
-	if (status) {
-		error("Encryption failed: %s(0x%x)",
-				strerror(bt_error(status)), status);
-		goto failed;
-	}
-
 	err = ioctl_connadd(req);
 	if (err == 0)
 		goto cleanup;
 
 	error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
-failed:
 	close(req->intr_sock);
 	close(req->ctrl_sock);
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 BlueZ 2/6] input: Use g_free() where appropriate
From: Anderson Lizardo @ 2013-01-03 14:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1357222503-31554-1-git-send-email-anderson.lizardo@openbossa.org>

req->rd_data was allocated with g_try_malloc0(), therefore it should be
freed with g_free().
---
 profiles/input/device.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 7655534..ca1ce8b 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -285,7 +285,7 @@ static void encrypt_completed(uint8_t status, gpointer user_data)
 	close(req->ctrl_sock);
 
 cleanup:
-	free(req->rd_data);
+	g_free(req->rd_data);
 
 	g_free(req);
 }
@@ -376,7 +376,7 @@ static int hidp_add_connection(struct input_device *idev)
 	err = ioctl_connadd(req);
 
 cleanup:
-	free(req->rd_data);
+	g_free(req->rd_data);
 	g_free(req);
 
 	return err;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 BlueZ 3/6] input: Remove unnecessary goto label
From: Anderson Lizardo @ 2013-01-03 14:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1357222503-31554-1-git-send-email-anderson.lizardo@openbossa.org>

Instead, use "if (err < 0)" for error handling.
---
 profiles/input/device.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index ca1ce8b..fc7f8f7 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -277,16 +277,13 @@ static void encrypt_completed(uint8_t status, gpointer user_data)
 	int err;
 
 	err = ioctl_connadd(req);
-	if (err == 0)
-		goto cleanup;
-
-	error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
-	close(req->intr_sock);
-	close(req->ctrl_sock);
+	if (err < 0) {
+		error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
+		close(req->intr_sock);
+		close(req->ctrl_sock);
+	}
 
-cleanup:
 	g_free(req->rd_data);
-
 	g_free(req);
 }
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 BlueZ 4/6] input: Remove unnecessary encrypt_completed() function
From: Anderson Lizardo @ 2013-01-03 14:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1357222503-31554-1-git-send-email-anderson.lizardo@openbossa.org>

Its code is used only once, and can be made much simpler if moved to
encrypt_notify().
---
 profiles/input/device.c |   28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index fc7f8f7..e69d647 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -271,33 +271,25 @@ static int ioctl_connadd(struct hidp_connadd_req *req)
 	return err;
 }
 
-static void encrypt_completed(uint8_t status, gpointer user_data)
-{
-	struct hidp_connadd_req *req = user_data;
-	int err;
-
-	err = ioctl_connadd(req);
-	if (err < 0) {
-		error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
-		close(req->intr_sock);
-		close(req->ctrl_sock);
-	}
-
-	g_free(req->rd_data);
-	g_free(req);
-}
-
 static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition,
 								gpointer data)
 {
 	struct input_device *idev = data;
-	struct hidp_connadd_req *req = idev->req;
+	int err;
 
 	DBG(" ");
 
-	encrypt_completed(0, req);
+	err = ioctl_connadd(idev->req);
+	if (err < 0) {
+		error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
+		close(idev->req->intr_sock);
+		close(idev->req->ctrl_sock);
+	}
 
 	idev->sec_watch = 0;
+
+	g_free(idev->req->rd_data);
+	g_free(idev->req);
 	idev->req = NULL;
 
 	return FALSE;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 BlueZ 5/6] input: Minor whitespace fixes
From: Anderson Lizardo @ 2013-01-03 14:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1357222503-31554-1-git-send-email-anderson.lizardo@openbossa.org>

---
 profiles/input/device.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index e69d647..3d5ee20 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -277,11 +277,11 @@ static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition,
 	struct input_device *idev = data;
 	int err;
 
-	DBG(" ");
+	DBG("");
 
 	err = ioctl_connadd(idev->req);
 	if (err < 0) {
-		error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
+		error("ioctl_connadd(): %s (%d)", strerror(-err), -err);
 		close(idev->req->intr_sock);
 		close(idev->req->ctrl_sock);
 	}
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v2 BlueZ 6/6] input: Fix closing sockets when ioctl_connadd() fails
From: Anderson Lizardo @ 2013-01-03 14:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo
In-Reply-To: <1357222503-31554-1-git-send-email-anderson.lizardo@openbossa.org>

Instead of calling close() directly, properly shutdown the channel and
set GIOChannel pointers to NULL.

Fixes this error detected when HIDP support is disabled on kernel and we
attempt to connect to a BT keyboard:

bluetoothd[5168]: profiles/input/device.c:encrypt_notify()
bluetoothd[5168]: ioctl_connadd(): Protocol not supported(93)
bluetoothd[5168]: profiles/input/device.c:ctrl_watch_cb() Device
CA:FE:CA:FE:CA:FE disconnected

(bluetoothd:5168): GLib-WARNING **: Invalid file descriptor.

bluetoothd[5168]: profiles/input/device.c:intr_watch_cb() Device
CA:FE:CA:FE:CA:FE disconnected

(bluetoothd:5168): GLib-WARNING **: Invalid file descriptor.
---
 profiles/input/device.c |   26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 3d5ee20..9ab7509 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -136,8 +136,10 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
 
 	idev->intr_watch = 0;
 
-	g_io_channel_unref(idev->intr_io);
-	idev->intr_io = NULL;
+	if (idev->intr_io) {
+		g_io_channel_unref(idev->intr_io);
+		idev->intr_io = NULL;
+	}
 
 	/* Close control channel */
 	if (idev->ctrl_io && !(cond & G_IO_NVAL))
@@ -163,8 +165,10 @@ static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data
 
 	idev->ctrl_watch = 0;
 
-	g_io_channel_unref(idev->ctrl_io);
-	idev->ctrl_io = NULL;
+	if (idev->ctrl_io) {
+		g_io_channel_unref(idev->ctrl_io);
+		idev->ctrl_io = NULL;
+	}
 
 	/* Close interrupt channel */
 	if (idev->intr_io && !(cond & G_IO_NVAL))
@@ -282,8 +286,18 @@ static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition,
 	err = ioctl_connadd(idev->req);
 	if (err < 0) {
 		error("ioctl_connadd(): %s (%d)", strerror(-err), -err);
-		close(idev->req->intr_sock);
-		close(idev->req->ctrl_sock);
+
+		if (idev->ctrl_io) {
+			g_io_channel_shutdown(idev->ctrl_io, FALSE, NULL);
+			g_io_channel_unref(idev->ctrl_io);
+			idev->ctrl_io = NULL;
+		}
+
+		if (idev->intr_io) {
+			g_io_channel_shutdown(idev->intr_io, FALSE, NULL);
+			g_io_channel_unref(idev->intr_io);
+			idev->intr_io = NULL;
+		}
 	}
 
 	idev->sec_watch = 0;
-- 
1.7.9.5


^ permalink raw reply related

* Re: [PATCH 00/12] Add LE broadcaster and observer functionality
From: Aloisio Almeida @ 2013-01-03 15:02 UTC (permalink / raw)
  To: Jefferson Delfes; +Cc: linux-bluetooth
In-Reply-To: <1355511098-10190-1-git-send-email-jefferson.delfes@openbossa.org>

bump

On Fri, Dec 14, 2012 at 3:51 PM, Jefferson Delfes
<jefferson.delfes@openbossa.org> wrote:
> This patch series adds broadcaster and observer functionality.
>
> For the userspace, we are updating our branch and we will send it in s few
> days.
>
> Aloisio Almeida Jr (10):
>   Bluetooth: Set advertising parameters on LE setup
>   Bluetooth: Add set controller data MGMT command
>   Bluetooth: Add set broadcaster MGMT command
>   Bluetooth: Advertise controller data in broadcaster mode
>   Bluetooth: Stop to acquire hdev lock inside hci_update_ad
>   Bluetooth: Enable on-the-fly update of broadcast data
>   Bluetooth: Enable support for broadcaster mode when powered off.
>   Bluetooth: Refactor le scan helpers to enable observer support
>   Bluetooth: Add set observer MGMT command
>   Bluetooth: Enable support for observer mode when powered off.
>
> Jefferson Delfes (2):
>   Bluetooth: Add HCI command to set advertising parameters
>   Bluetooth: Add unset controller data MGMT command
>
>  include/net/bluetooth/hci.h      |  19 +++
>  include/net/bluetooth/hci_core.h |  42 ++++-
>  include/net/bluetooth/mgmt.h     |  21 +++
>  net/bluetooth/hci_core.c         | 183 ++++++++++++++++-----
>  net/bluetooth/hci_event.c        | 121 +++++++++-----
>  net/bluetooth/mgmt.c             | 335 +++++++++++++++++++++++++++++++++++++--
>  6 files changed, 628 insertions(+), 93 deletions(-)
>
> --
> 1.8.0.2
>
> --
> 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

^ permalink raw reply

* Re: [PATCH v2 BlueZ 1/6] input: Remove dead code from encrypt_completed()
From: Johan Hedberg @ 2013-01-03 16:12 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: linux-bluetooth
In-Reply-To: <1357222503-31554-1-git-send-email-anderson.lizardo@openbossa.org>

Hi Lizardo,

On Thu, Jan 03, 2013, Anderson Lizardo wrote:
> "status" is always zero, so this code will never be reached.
> ---
>  profiles/input/device.c |    7 -------
>  1 file changed, 7 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH] attrib-server: Fix invalid device access
From: Paulo Borges @ 2013-01-03 18:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Paulo Borges

When the device is not found, the channel attach must fail.
---
 src/attrib-server.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 15622e4..4a25743 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1131,10 +1131,17 @@ guint attrib_channel_attach(GAttrib *attrib)
 	ba2str(&channel->dst, addr);
 
 	device = adapter_find_device(server->adapter, addr);
-	if (device == NULL || device_is_bonded(device) == FALSE) {
+	if (device == NULL) {
+		error("Device not found");
+		g_free(channel);
+
+		return 0;
+	}
+
+	if (device_is_bonded(device) == FALSE) {
 		char *filename;
 
-		filename = btd_device_get_storage_path(channel->device, "ccc");
+		filename = btd_device_get_storage_path(device, "ccc");
 		unlink(filename);
 		g_free(filename);
 	}
-- 
1.7.9.5


^ permalink raw reply related

* Re: [RFC 3/3] Bluetooth:  Provide mgmt API for reading list of supported codecs
From: Gustavo Padovan @ 2013-01-03 19:09 UTC (permalink / raw)
  To: Michael Knudsen; +Cc: linux-bluetooth, Michael Knudsen
In-Reply-To: <1353585909-28400-4-git-send-email-m.knudsen@samsung.com>

Hi Michael,

* Michael Knudsen <michaelknudsendk@gmail.com> [2012-11-22 13:05:08 +0100]:

> Provide an API for allowing user space to read the list of codecs
> supported by a given controller.  For now, hardwire PCM support,
> but construct initial list of supported codecs by inspecting the
> relevant bits of the local supported features bit mask.  Later,
> devices that support the appropriate HCI command will read out the
> actual list during controller initialisation.
> ---
>  include/net/bluetooth/hci_core.h |    2 ++
>  include/net/bluetooth/mgmt.h     |    7 +++++++
>  net/bluetooth/hci_core.c         |    3 +++
>  net/bluetooth/hci_event.c        |   21 +++++++++++++++++++++
>  net/bluetooth/mgmt.c             |   36 ++++++++++++++++++++++++++++++++++++
>  5 files changed, 69 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index ef5b85d..79fe128 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -153,6 +153,8 @@ struct hci_dev {
>  	__u8		features[8];
>  	__u8		host_features[8];
>  	__u8		commands[64];
> +	__u8		codecs;
> +	__u8		codec[255];
>  	__u8		hci_ver;
>  	__u16		hci_rev;
>  	__u8		lmp_ver;
> diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
> index 22980a7..523dc58 100644
> --- a/include/net/bluetooth/mgmt.h
> +++ b/include/net/bluetooth/mgmt.h
> @@ -350,6 +350,13 @@ struct mgmt_cp_set_device_id {
>  } __packed;
>  #define MGMT_SET_DEVICE_ID_SIZE		8
>  
> +#define MGMT_OP_READ_CODECS		0x0029
> +#define MGMT_READ_CODECS_SIZE		0
> +struct mgmt_rp_read_codecs {
> +	__u8	count;
> +	__u8	codec[0];
> +} __packed;
> +

We think it is better to read the list of codecs from the SCO socket, we need
to allow both oFono and PulseAudio to read them without the need of talking to
BlueZ. Also, bluetoothd has nothing intersting to do with this information.

	Gustavo

^ permalink raw reply

* Re: [PATCH 1/2] core: Replace calls to g_queue_free_full function
From: Giovanni Gherdovich @ 2013-01-03 19:36 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz, Vinicius Costa Gomes,
	Anderson Lizardo
  Cc: linux-bluetooth
In-Reply-To: <1357164488.19248.92.camel@aeonflux>

Hi Marcel, Luiz, Vinicius, Anderson,

2013/1/2 Marcel Holtmann <marcel@holtmann.org>:
> [...]
>
> I would have done this:
>
>         static void free_service_auth(gpointer data, gpointer user_data)
>         {
>                 struct service_auth *auth = data;
>
>                 g_free(auth);
>         }


> change pending_destroy() to this:
>
>         static void pending_destroy(gpointer data, gpointer user_data)
>         {
>                 ...
>         }
>
> And then fix the callers to add an extra NULL.

I am about to send the modified patch.

I also had to revert another GLib function, g_slist_free_full,
to g_slist_foreach + g_slist_free, since having changed the signature
of pending_destroy, i didn't suit any more the second argument of
g_slist_free_full.
I hope that's not a big deal.


2013/1/2 Luiz Augusto von Dentz <luiz.dentz@gmail.com>:
> [...]
>
> There is something off here, in the past we did have an implementation
> of g_slist_free_full to overcome this dependency problem but it was
> removed in this commit:
>
> commit 84156dadb25ec0973752d34d84fc9ffb3c720988
> Author: Marcel Holtmann <marcel@holtmann.org>
> Date:   Mon Apr 16 18:22:24 2012 +0200
>
>     build: Remove glib-compat.h support
>

yes, here a link to the gitweb
http://git.kernel.org/?p=bluetooth/bluez.git;a=commitdiff;h=84156dadb25ec0973752d34d84fc9ffb3c720988;hp=1a79248e6be548696715f3bb2ddcf01630cf2c69

2013/1/2 Luiz Augusto von Dentz <luiz.dentz@gmail.com>:
> Hi Vinicius,
>
> On Wed, Jan 2, 2013 at 10:23 PM, Vinicius Gomes
>> [...]
>> The problem now is g_queue_free_full() not the g_slist_free_full().
>
> Right, but it is quite the same situation  [...]

It is exactly the same situation.
In the commit where the GLib team added g_queue_free_full,
they mentioned that they wanted to align the API for GQueue
to what they had for GSList and GList.

2013/1/3 Luiz Augusto von Dentz <luiz.dentz@gmail.com>:
> [...]
>
> Anyway regardless if we do update or not, I don't see why
> g_queue_free_full is different than g_slist_free_full, so instead of
> converting everything to g_queue_foreach + g_queue_free why we don't
> bring back glib-compat and do this in one place as we did for
> g_slist_free_full?

If you bring back that code, you bring back the evil cast of

void (*) (void *)

to

void (*) (void *, void *)

which I am trying to avoid.

Regards,
Giovanni

^ permalink raw reply

* [PATCH 1/2] core: Replace calls to g_queue_free_full function
From: Giovanni Gherdovich @ 2013-01-03 19:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Giovanni Gherdovich

The function g_queue_free_full is available only from GLib 2.32.
If BlueZ has to build against GLib 2.28, as stated in the configure.ac,
this patch replaces the calls to g_queue_free_full in the "core" BlueZ module
with its body, taken from the sources of GLib 2.32.
---
 src/adapter.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index e71cea8..ca94fa9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1688,6 +1688,13 @@ int btd_adapter_stop(struct btd_adapter *adapter)
 	return 0;
 }
 
+static void free_service_auth(gpointer data, gpointer user_data)
+{
+	struct service_auth *auth = data;
+
+	g_free(auth);
+}
+
 static void adapter_free(gpointer user_data)
 {
 	struct btd_adapter *adapter = user_data;
@@ -1697,7 +1704,8 @@ static void adapter_free(gpointer user_data)
 	if (adapter->auth_idle_id)
 		g_source_remove(adapter->auth_idle_id);
 
-	g_queue_free_full(adapter->auths, g_free);
+	g_queue_foreach(adapter->auths, free_service_auth, NULL);
+	g_queue_free(adapter->auths);
 
 	sdp_list_free(adapter->services, NULL);
 
-- 
1.7.4.1


^ permalink raw reply related

* [PATCH 2/2] AVCTP: Replace calls to g_queue_free_full function
From: Giovanni Gherdovich @ 2013-01-03 19:37 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Giovanni Gherdovich

The function g_queue_free_full is available only from GLib 2.32.
If BlueZ has to build against GLib 2.28, as stated in the configure.ac,
this patch replaces the calls to g_queue_free_full in the AVTCP module
with its body, taken from the sources of GLib 2.32.
---
 profiles/audio/avctp.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index 013c587..b26abe5 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -370,7 +370,7 @@ static struct avctp_pdu_handler *find_handler(GSList *list, uint8_t opcode)
 	return NULL;
 }
 
-static void pending_destroy(void *data)
+static void pending_destroy(gpointer data, gpointer user_data)
 {
 	struct avctp_pending_req *req = data;
 
@@ -395,8 +395,10 @@ static void avctp_channel_destroy(struct avctp_channel *chan)
 		g_source_remove(chan->process_id);
 
 	g_free(chan->buffer);
-	g_queue_free_full(chan->queue, pending_destroy);
-	g_slist_free_full(chan->processed, pending_destroy);
+	g_queue_foreach(chan->queue, pending_destroy, NULL);
+	g_queue_free(chan->queue);
+	g_slist_foreach(chan->processed, pending_destroy, NULL);
+	g_slist_free(chan->processed);
 	g_slist_free_full(chan->handlers, g_free);
 	g_free(chan);
 }
@@ -540,7 +542,7 @@ static gboolean req_timeout(gpointer user_data)
 
 	p->timeout = 0;
 
-	pending_destroy(p);
+	pending_destroy(p, NULL);
 	chan->p = NULL;
 
 	if (chan->process_id == 0)
@@ -574,7 +576,7 @@ static gboolean process_queue(void *user_data)
 		if (p->process(p->data) == 0)
 			break;
 
-		pending_destroy(p);
+		pending_destroy(p, NULL);
 	}
 
 	if (p == NULL)
@@ -626,7 +628,7 @@ static void control_response(struct avctp_channel *control,
 			return;
 
 		control->processed = g_slist_remove(control->processed, p);
-		pending_destroy(p);
+		pending_destroy(p, NULL);
 
 		return;
 	}
-- 
1.7.4.1


^ permalink raw reply related

* Re: [PATCH v2 2/2] Bluetooth: Fix stop discovery while in STARTING state
From: Gustavo Padovan @ 2013-01-03 19:38 UTC (permalink / raw)
  To: Jaganath Kanakkassery; +Cc: linux-bluetooth
In-Reply-To: <1356094225-12706-3-git-send-email-jaganath.k@samsung.com>

Hi Jaganath,

* Jaganath Kanakkassery <jaganath.k@samsung.com> [2012-12-21 18:20:25 +0530]:

> If stop_discovery() is called when discovery state is STARTING, it
> will be failed currently. This patch fixes this.
> 
> Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
> ---
>  include/net/bluetooth/hci_core.h |    2 ++
>  net/bluetooth/hci_event.c        |   14 ++++++++++++--
>  net/bluetooth/mgmt.c             |   31 ++++++++++++++++++++++++++++++-
>  3 files changed, 44 insertions(+), 3 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index 119fcb6..c2886b7 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -64,6 +64,7 @@ struct discovery_state {
>  		DISCOVERY_RESOLVING,
>  		DISCOVERY_STOPPING,
>  	} state;
> +	u8  discovering;
>  	struct list_head	all;	/* All devices found during inquiry */
>  	struct list_head	unknown;	/* Name state not known */
>  	struct list_head	resolve;	/* Name needs to be resolved */
> @@ -1066,6 +1067,7 @@ int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
>  int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
>  		     u8 addr_type, s8 rssi, u8 *name, u8 name_len);
>  int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
> +int mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status);
>  int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
>  int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
>  int mgmt_interleaved_discovery(struct hci_dev *hdev);
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index e248e7c..b486458 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -1092,7 +1092,12 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
>  		set_bit(HCI_LE_SCAN, &hdev->dev_flags);
>  
>  		hci_dev_lock(hdev);
> -		hci_discovery_set_state(hdev, DISCOVERY_FINDING);
> +		if (hdev->discovery.state == DISCOVERY_STOPPING) {
> +			hci_cancel_le_scan(hdev);
> +			mgmt_start_discovery_complete(hdev, 0);

Reply to mgmt with an error here might be better.

> +		} else {
> +			hci_discovery_set_state(hdev, DISCOVERY_FINDING);
> +		}
>  		hci_dev_unlock(hdev);
>  		break;
>  
> @@ -1189,7 +1194,12 @@ static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
>  	set_bit(HCI_INQUIRY, &hdev->flags);
>  
>  	hci_dev_lock(hdev);
> -	hci_discovery_set_state(hdev, DISCOVERY_FINDING);
> +	if (hdev->discovery.state == DISCOVERY_STOPPING) {
> +		hci_cancel_inquiry(hdev);
> +		mgmt_start_discovery_complete(hdev, 0);
> +	} else {
> +		hci_discovery_set_state(hdev, DISCOVERY_FINDING);
> +	}
>  	hci_dev_unlock(hdev);
>  }
>  
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index d6c0d78..ba4171f 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -2385,7 +2385,8 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
>  
>  	hci_dev_lock(hdev);
>  
> -	if (!hci_discovery_active(hdev)) {
> +	if (hdev->discovery.state != DISCOVERY_STARTING &&
> +	    !hci_discovery_active(hdev)) {
>  		err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY,
>  				   MGMT_STATUS_REJECTED, &mgmt_cp->type,
>  				   sizeof(mgmt_cp->type));
> @@ -2433,6 +2434,10 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
>  
>  		break;
>  
> +	case DISCOVERY_STARTING:
> +		err = 0;
> +		break;
> +
>  	default:
>  		BT_DBG("unknown discovery state %u", hdev->discovery.state);
>  		err = -EFAULT;
> @@ -3624,6 +3629,25 @@ int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status)
>  	return err;
>  }
>  
> +int mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status)
> +{
> +	struct pending_cmd *cmd;
> +	u8 type;
> +	int err;
> +
> +	cmd = mgmt_pending_find(MGMT_OP_START_DISCOVERY, hdev);
> +	if (!cmd)
> +		return -ENOENT;
> +
> +	type = hdev->discovery.type;
> +
> +	err = cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status),
> +			   &type, sizeof(type));
> +	mgmt_pending_remove(cmd);
> +
> +	return err;
> +}

This is exactly the same thing as mgmt_start_discovery_failed(), just rename it
to _complete() as you did with mgmt_stop_discovery_failed(). Do it as a
separate patch.

	Gustavo

^ permalink raw reply

* [PATCH BlueZ 1/8] media-api: Add playback control methods to MediaPlayer1
From: Luiz Augusto von Dentz @ 2013-01-03 19:46 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds methods such as Play, Pause directly in MediaPlayer1, in
addition to that Track is now turn into a property to take advantage of
ObjectManager and document the interface as experimental.
---
 doc/media-api.txt | 99 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 57 insertions(+), 42 deletions(-)

diff --git a/doc/media-api.txt b/doc/media-api.txt
index e2a72dc..eb1f74f 100644
--- a/doc/media-api.txt
+++ b/doc/media-api.txt
@@ -129,7 +129,7 @@ Media Control hierarchy
 =======================
 
 Service		org.bluez
-Interface	org.bluez.MediaControl1
+Interface	org.bluez.MediaControl1 [Deprecated]
 Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
 
 Methods		void Play()
@@ -178,65 +178,47 @@ Properties
 MediaPlayer1 hierarchy
 ======================
 
-Service		unique name (Target role)
-Interface	org.bluez.MediaPlayer1
-Object path	freely definable
-
 Service		org.bluez (Controller role)
-Interface	org.bluez.MediaPlayer1
+Interface	org.bluez.MediaPlayer1 [Experimental]
 Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX
 
-Methods		dict GetTrack()
-
-			Returns known metadata of the current track.
-
-			See TrackChanged for possible values.
-
-		void Release()
-
-			This method gets called when the service daemon
-			unregisters the player which can then perform
-			cleanup tasks. There is no need to unregister the
-			player, because when this method gets called it has
-			already been unregistered.
+Methods		void Play()
 
-Signals		TrackChanged(dict metadata)
+			Resume playback.
 
-			This signal indicates that current track has changed.
-			All available metadata for the new track shall be set
-			at once in the metadata argument. Metadata cannot be
-			updated in parts, otherwise it will be interpreted as
-			multiple track changes.
+		void Pause()
 
-			Possible values:
+			Pause playback.
 
-				string Title:
+		void Stop()
 
-					Track title name
+			Stop playback.
 
-				string Artist:
+		void Next()
 
-					Track artist name
+			Next item.
 
-				string Album:
+		void Previous()
 
-					Track album name
+			Previous item.
 
-				string Genre:
+		void VolumeUp()
 
-					Track genre name
+			Adjust remote volume one step up
 
-				uint32 NumberOfTracks:
+		void VolumeDown()
 
-					Number of tracks in total
+			Adjust remote volume one step down
 
-				uint32 Number:
+		void FastForward()
 
-					Track number
+			Fast forward playback, this action is only stopped
+			when another method in this interface is called.
 
-				uint32 Duration:
+		void Rewind()
 
-					Track duration in milliseconds
+			Rewind playback, this action is only stopped
+			when another method in this interface is called.
 
 Properties	string Equalizer [readwrite]
 
@@ -258,8 +240,8 @@ Properties	string Equalizer [readwrite]
 		string Status [readonly]
 
 			Possible status: "playing", "stopped", "paused",
-					"forward-seek", "reverse-seek" or
-					"error"
+					"forward-seek", "reverse-seek"
+					or "error"
 
 		uint32 Position [readonly]
 
@@ -272,6 +254,39 @@ Properties	string Equalizer [readwrite]
 			possible to signal its end by setting position to the
 			maximum uint32 value.
 
+		dict Track [readonly]
+
+			Track metadata.
+
+			Possible values:
+
+				string Title:
+
+					Track title name
+
+				string Artist:
+
+					Track artist name
+
+				string Album:
+
+					Track album name
+
+				string Genre:
+
+					Track genre name
+
+				uint32 NumberOfTracks:
+
+					Number of tracks in total
+
+				uint32 Number:
+
+					Track number
+
+				uint32 Duration:
+
+					Track duration in milliseconds
 
 MediaEndpoint1 hierarchy
 ========================
-- 
1.8.0.1


^ permalink raw reply related


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