* [PATCH 5/5] emulator/bthost: Check length of received RFCOMM UIH frames
From: Marcin Kraglak @ 2014-02-11 10:51 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1392115862-19752-1-git-send-email-marcin.kraglak@tieto.com>
Add correct calculation of frame length. If frame is too short, ignore it.
---
emulator/bthost.c | 38 ++++++++++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/emulator/bthost.c b/emulator/bthost.c
index ab90f4c..8447817 100644
--- a/emulator/bthost.c
+++ b/emulator/bthost.c
@@ -1760,17 +1760,30 @@ static void rfcomm_mcc_recv(struct bthost *bthost, struct btconn *conn,
struct l2conn *l2conn, const void *data, uint16_t len)
{
const struct rfcomm_mcc *mcc = data;
+ const struct rfcomm_msc *msc;
+ const struct rfcomm_pn *pn;
+
+ if (len < sizeof(*mcc))
+ return;
switch (RFCOMM_GET_MCC_TYPE(mcc->type)) {
case RFCOMM_MSC:
+ if (len - sizeof(*mcc) < sizeof(*msc))
+ break;
+
+ msc = data + sizeof(*mcc);
+
rfcomm_msc_recv(bthost, conn, l2conn,
- RFCOMM_TEST_CR(mcc->type) / 2,
- data + sizeof(*mcc));
+ RFCOMM_TEST_CR(mcc->type) / 2, msc);
break;
case RFCOMM_PN:
+ if (len - sizeof(*mcc) < sizeof(*pn))
+ break;
+
+ pn = data + sizeof(*mcc);
+
rfcomm_pn_recv(bthost, conn, l2conn,
- RFCOMM_TEST_CR(mcc->type) / 2,
- data + sizeof(*mcc));
+ RFCOMM_TEST_CR(mcc->type) / 2, pn);
break;
default:
break;
@@ -1781,18 +1794,27 @@ static void rfcomm_uih_recv(struct bthost *bthost, struct btconn *conn,
struct l2conn *l2conn, const void *data,
uint16_t len)
{
- const struct rfcomm_cmd *hdr = data;
+ const struct rfcomm_hdr *hdr = data;
+ uint16_t hdr_len;
const void *p;
+ if (len < sizeof(*hdr))
+ return;
+
if (RFCOMM_GET_DLCI(hdr->address))
return;
if (RFCOMM_TEST_EA(hdr->length))
- p = data + sizeof(struct rfcomm_hdr);
+ hdr_len = sizeof(*hdr);
else
- p = data + sizeof(struct rfcomm_hdr) + sizeof(uint8_t);
+ hdr_len = sizeof(*hdr) + sizeof(uint8_t);
+
+ if (len - hdr_len < 0)
+ return;
+
+ p = data + hdr_len;
- rfcomm_mcc_recv(bthost, conn, l2conn, p, p - data);
+ rfcomm_mcc_recv(bthost, conn, l2conn, p, len - hdr_len);
}
static void process_rfcomm(struct bthost *bthost, struct btconn *conn,
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH 1/2] unit/avctp: Use pre-defined values instead of magic numbers
From: Andrei Emeltchenko @ 2014-02-11 11:12 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1391614102-21639-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
ping
On Wed, Feb 05, 2014 at 05:28:21PM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ---
> unit/test-avctp.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/unit/test-avctp.c b/unit/test-avctp.c
> index 581f88c..9d94ae0 100644
> --- a/unit/test-avctp.c
> +++ b/unit/test-avctp.c
> @@ -277,8 +277,8 @@ static void test_client(gconstpointer data)
> {
> struct context *context = create_context(0x0100, data);
>
> - avctp_send_vendordep_req(context->session, 0, 0, NULL, 0,
> - handler_response, context);
> + avctp_send_vendordep_req(context->session, AVC_CTYPE_CONTROL, 0, NULL,
> + 0, handler_response, context);
>
> execute_context(context);
> }
> @@ -290,8 +290,8 @@ static void test_server(gconstpointer data)
> if (g_str_equal(context->data->test_name, "/TP/NFR/BV-03-C")) {
> int ret;
>
> - ret = avctp_register_pdu_handler(context->session, 0x00,
> - handler, NULL);
> + ret = avctp_register_pdu_handler(context->session,
> + AVC_OP_VENDORDEP, handler, NULL);
> DBG("ret %d", ret);
> g_assert_cmpint(ret, !=, 0);
> }
> --
> 1.8.3.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 2/3] avrcp: Fix using incorrect buffer for SetVolume
From: Andrei Emeltchenko @ 2014-02-11 11:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <20140204140815.GQ2930@aemeltch-MOBL1>
On Tue, Feb 04, 2014 at 04:08:17PM +0200, Andrei Emeltchenko wrote:
> On Thu, Jan 30, 2014 at 06:12:55PM +0200, Andrei Emeltchenko wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > The command requires one parameter.
>
> ping
ping
>
> > ---
> > profiles/audio/avrcp.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
> > index 2e1a940..128f7d3 100644
> > --- a/profiles/audio/avrcp.c
> > +++ b/profiles/audio/avrcp.c
> > @@ -3706,7 +3706,7 @@ int avrcp_set_volume(struct btd_device *dev, uint8_t volume)
> > {
> > struct avrcp_server *server;
> > struct avrcp *session;
> > - uint8_t buf[AVRCP_HEADER_LENGTH + 2];
> > + uint8_t buf[AVRCP_HEADER_LENGTH + 1];
> > struct avrcp_header *pdu = (void *) buf;
> >
> > server = find_server(servers, device_get_adapter(dev));
> > --
> > 1.8.3.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
> --
> 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
* [PATCH] android/README: Add Valgrind description
From: Andrzej Kaczmarek @ 2014-02-11 11:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Andrzej Kaczmarek
---
android/README | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/android/README b/android/README
index e3c314f..c7145d5 100644
--- a/android/README
+++ b/android/README
@@ -108,6 +108,22 @@ be found at https://backports.wiki.kernel.org. Sample kernels using backports
for running BlueZ on Android are available at
https://code.google.com/p/aosp-bluez.
+Running with Valgrind
+=====================
+
+BlueZ for Android is preconfigured to be easily run under Valgrind memcheck.
+Appropriate configuration and required modules are automatically included when
+building either userdebug or eng variant of Android platform.
+
+Valgrind can be enabled in runtime by setting "persist.sys.bluetooth.valgrind"
+property to either literal "true" or any numeric value >0. For example:
+adb root
+adb shell setprop persist.sys.bluetooth.valgrind true
+
+After changing property value Bluetooth need to be restarted to apply changes
+(this can be done using UI, just disable and enable it again). Property is
+persistent, i.e. there's no need to enable Valgrind again after reboot.
+
=============================
Building and running on Linux
=============================
--
1.8.5.3
^ permalink raw reply related
* [PATCH] Bluetooth: Fix channel check when binding RFCOMM sock
From: Andrzej Kaczmarek @ 2014-02-11 11:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Andrzej Kaczmarek
When binding RFCOMM socket we should only check if there is another
socket bound or listening on the same channel number. In other case,
it won't be possible to bind/listen on a channel in case we have
connection made to remote device on the same channel number.
Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
---
net/bluetooth/rfcomm/sock.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 00573fb..9912e23 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -331,6 +331,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
{
struct sockaddr_rc *sa = (struct sockaddr_rc *) addr;
struct sock *sk = sock->sk;
+ struct sock *sk1;
int err = 0;
BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr);
@@ -352,7 +353,9 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
write_lock(&rfcomm_sk_list.lock);
- if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) {
+ sk1 = __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr);
+ if (sa->rc_channel && sk1 && (sk1->sk_state == BT_BOUND ||
+ sk1->sk_state == BT_LISTEN)) {
err = -EADDRINUSE;
} else {
/* Save source address */
--
1.8.5.3
^ permalink raw reply related
* AW: Bluetooth with full AMP
From: Viswanatham, RaviTeja @ 2014-02-11 12:15 UTC (permalink / raw)
To: Andrei Emeltchenko, Marcel Holtmann
Cc: bluez mailin list (linux-bluetooth@vger.kernel.org)
-----Urspr=FCngliche Nachricht-----
Von: linux-bluetooth-owner@vger.kernel.org [mailto:linux-bluetooth-owner@vg=
er.kernel.org] Im Auftrag von Andrei Emeltchenko
Gesendet: Dienstag, 11. Februar 2014 08:13
An: Marcel Holtmann
Cc: Viswanatham, RaviTeja; bluez mailin list (linux-bluetooth@vger.kernel.o=
rg)
Betreff: Re:=20
Hi All,
On Mon, Feb 10, 2014 at 10:35:24AM -0800, Marcel Holtmann wrote:
> Hi Ravi,
>=20
> > I am working on Ubuntu 12.04 with a Bluetooth 3.0 +HS + wifi combo=20
> > USB dongle.
> >=20
> > I want to reach a data transfer speed of up to 24 Mbit/s.=20
> >=20
> > My Questions: Does Bluez support high speed data transfer rates up=20
> > to
> > 24 Mbit/s (Bluetooth 3.0+HS) ?=20
> >=20
> > If it does, is there any user configuration involved to achieve that?
> > What other requirements need to be met? Does, Bluetooth enables AMP=20
> > function to communicate 802.11n channel to support high speed or it=20
> > has to be configure with any other drivers?
> >=20
> > I am new to Linux a detail explanation would be really appreciated.
> > Thank you in advance for your support.
>=20
> we do support Bluetooth HS operation. However your WiFi device needs=20
> to be exposed as AMP Controller. Most WiFi hardware needs a special=20
> driver to expose itself as AMP Controller. There is no generic driver=20
> for
> mac80211 subsystem in the kernel.
Some devices have AMP Controller implemented in firmware.
I was using Marvell SD8787, probably newer Marvell devices also works.
You may check drivers/bluetooth/btmrvl_main.c to see how HCI dev_type HCI_A=
MP is assigned.
Best regards
Andrei Emeltchenko=20
Hello Andrei Emelchenko,
Thanks for replying me. I would like to know some more information about th=
e Bluetooth dongle. As you said the Marvell SD8787 is kind of a SoC chipset=
. Is there any USB Bluetooth device available in the market which supports=
out of the box. I am running 3.11 kernel and I already build the Marvell =
option inside the kernel.=20
Is there any dongles available in the market which supports full AMP. If no=
t are there any other possibilities to fix the Marvell driver with the exis=
ting dongle. Please any hints as I am working on ARM board I need to fix th=
e USB Bluetooth device which can transfer with high speed.=20
Thanks in advance.=20
Regards,
Raviteja=20
--
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 a=
t http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* Re: Bluetooth with full AMP
From: Andrei Emeltchenko @ 2014-02-11 12:26 UTC (permalink / raw)
To: Viswanatham, RaviTeja
Cc: Marcel Holtmann,
bluez mailin list (linux-bluetooth@vger.kernel.org), bzhao
In-Reply-To: <9BC883E0D59F6B4DBD525D460025714B08AE363D@deessmx03.dees.eberspaecher.com>
Hi Raviteja,
> On Mon, Feb 10, 2014 at 10:35:24AM -0800, Marcel Holtmann wrote:
> > Hi Ravi,
> >
> > > I am working on Ubuntu 12.04 with a Bluetooth 3.0 +HS + wifi combo
> > > USB dongle.
> > >
> > > I want to reach a data transfer speed of up to 24 Mbit/s.
> > >
> > > My Questions: Does Bluez support high speed data transfer rates up
> > > to
> > > 24 Mbit/s (Bluetooth 3.0+HS) ?
> > >
> > > If it does, is there any user configuration involved to achieve that?
> > > What other requirements need to be met? Does, Bluetooth enables AMP
> > > function to communicate 802.11n channel to support high speed or it
> > > has to be configure with any other drivers?
> > >
> > > I am new to Linux a detail explanation would be really appreciated.
> > > Thank you in advance for your support.
> >
> > we do support Bluetooth HS operation. However your WiFi device needs
> > to be exposed as AMP Controller. Most WiFi hardware needs a special
> > driver to expose itself as AMP Controller. There is no generic driver
> > for mac80211 subsystem in the kernel.
>
> Some devices have AMP Controller implemented in firmware. I was using
> Marvell SD8787, probably newer Marvell devices also works.
>
> You may check drivers/bluetooth/btmrvl_main.c to see how HCI dev_type
> HCI_AMP is assigned.
>
> Thanks for replying me. I would like to know some more information about
> the Bluetooth dongle. As you said the Marvell SD8787 is kind of a SoC
> chipset. Is there any USB Bluetooth device available in the market
> which supports out of the box.
The only possibility I know is Marvell development board like:
http://avnetexpress.avnet.com/store/em/EMController/Development-Kits/Marvell/RD-88W-SD-8787-A0/_/R-10001817/A-10001817/An-0?action=part&catalogId=500201&langId=-1&storeId=500201
> I am running 3.11 kernel and I already
> build the Marvell option inside the kernel.
>
> Is there any dongles available in the market which supports full AMP.
At least I couldn't find one. If you find it let us know ;)
> If
> not are there any other possibilities to fix the Marvell driver with the
> existing dongle. Please any hints as I am working on ARM board I need to
> fix the USB Bluetooth device which can transfer with high speed.
>
Try to contact Marvell and ask which one supports FullAMP.
Best regards
Andrei Emeltchenko
^ permalink raw reply
* Re: [PATCH 1/4] android/avrcp: Decouple AVRCP logic from btio
From: Andrei Emeltchenko @ 2014-02-11 13:03 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1391702774-18972-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi All
On Thu, Feb 06, 2014 at 06:06:11PM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> The patch makes AVRCP to be channel-agnostic so that it might be used in
> unit tests. The idea is that all AVRCP logic would come to avrcp-lib and
> channel stuff got to avrcp.
Any comments regarding this patch?
Best regards
Andrei Emeltchenko
> ---
> android/Android.mk | 1 +
> android/Makefile.am | 1 +
> android/avrcp-lib.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> android/avrcp-lib.h | 34 +++++++++++++++++++++++
> android/avrcp.c | 60 ++++++----------------------------------
> 5 files changed, 125 insertions(+), 51 deletions(-)
> create mode 100644 android/avrcp-lib.c
> create mode 100644 android/avrcp-lib.h
>
> diff --git a/android/Android.mk b/android/Android.mk
> index 20105e6..9b10cfe 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -30,6 +30,7 @@ LOCAL_SRC_FILES := \
> bluez/android/avdtp.c \
> bluez/android/a2dp.c \
> bluez/android/avctp.c \
> + bluez/android/avrcp-lib.c \
> bluez/android/avrcp.c \
> bluez/android/pan.c \
> bluez/android/handsfree.c \
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 5baa8db..3032940 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -36,6 +36,7 @@ android_bluetoothd_SOURCES = android/main.c \
> android/avdtp.h android/avdtp.c \
> android/a2dp.h android/a2dp.c \
> android/avctp.h android/avctp.c \
> + android/avrcp-lib.h android/avrcp-lib.c \
> android/avrcp.h android/avrcp.c \
> android/socket.h android/socket.c \
> android/pan.h android/pan.c \
> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
> new file mode 100644
> index 0000000..6dcc8ac
> --- /dev/null
> +++ b/android/avrcp-lib.c
> @@ -0,0 +1,80 @@
> +/*
> + *
> + * BlueZ - Bluetooth protocol stack for Linux
> + *
> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
> + *
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <stdbool.h>
> +#include <glib.h>
> +
> +#include "lib/bluetooth.h"
> +
> +#include "src/log.h"
> +
> +#include "avctp.h"
> +#include "avrcp-lib.h"
> +
> +static GSList *devices = NULL;
> +
> +void avrcp_device_remove(struct avrcp_device *dev)
> +{
> + devices = g_slist_remove(devices, dev);
> + avrcp_device_free(dev);
> +}
> +
> +void avrcp_free_all(void)
> +{
> + g_slist_free_full(devices, avrcp_device_free);
> + devices = NULL;
> +}
> +
> +struct avrcp_device *avrcp_device_new(const bdaddr_t *dst)
> +{
> + struct avrcp_device *dev;
> +
> + dev = g_new0(struct avrcp_device, 1);
> + bacpy(&dev->dst, dst);
> + devices = g_slist_prepend(devices, dev);
> +
> + return dev;
> +}
> +
> +static int device_cmp(gconstpointer s, gconstpointer user_data)
> +{
> + const struct avrcp_device *dev = s;
> + const bdaddr_t *dst = user_data;
> +
> + return bacmp(&dev->dst, dst);
> +}
> +
> +struct avrcp_device *avrcp_find(const bdaddr_t *dst)
> +{
> + GSList *l;
> +
> + l = g_slist_find_custom(devices, dst, device_cmp);
> + if (!l)
> + return NULL;
> +
> + return l->data;
> +}
> diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
> new file mode 100644
> index 0000000..bf6872e
> --- /dev/null
> +++ b/android/avrcp-lib.h
> @@ -0,0 +1,34 @@
> +/*
> + *
> + * BlueZ - Bluetooth protocol stack for Linux
> + *
> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
> + *
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + */
> +
> +struct avrcp_device {
> + bdaddr_t dst;
> + struct avctp *session;
> + GIOChannel *io;
> +};
> +
> +struct avrcp_device *avrcp_device_new(const bdaddr_t *dst);
> +void avrcp_device_free(void *data);
> +void avrcp_device_remove(struct avrcp_device *dev);
> +void avrcp_free_all(void);
> +struct avrcp_device *avrcp_find(const bdaddr_t *dst);
> diff --git a/android/avrcp.c b/android/avrcp.c
> index 7ee5a8a..22f0a04 100644
> --- a/android/avrcp.c
> +++ b/android/avrcp.c
> @@ -38,6 +38,7 @@
> #include "hal-msg.h"
> #include "ipc.h"
> #include "avctp.h"
> +#include "avrcp-lib.h"
>
> #define L2CAP_PSM_AVCTP 0x17
>
> @@ -48,15 +49,8 @@
>
> static bdaddr_t adapter_addr;
> static uint32_t record_id = 0;
> -static GSList *devices = NULL;
> static GIOChannel *server = NULL;
>
> -struct avrcp_device {
> - bdaddr_t dst;
> - struct avctp *session;
> - GIOChannel *io;
> -};
> -
> static const struct ipc_handler cmd_handlers[] = {
> };
>
> @@ -128,7 +122,7 @@ static sdp_record_t *avrcp_record(void)
> return record;
> }
>
> -static void avrcp_device_free(void *data)
> +void avrcp_device_free(void *data)
> {
> struct avrcp_device *dev = data;
>
> @@ -143,31 +137,6 @@ static void avrcp_device_free(void *data)
> g_free(dev);
> }
>
> -static void avrcp_device_remove(struct avrcp_device *dev)
> -{
> - devices = g_slist_remove(devices, dev);
> - avrcp_device_free(dev);
> -}
> -
> -static struct avrcp_device *avrcp_device_new(const bdaddr_t *dst)
> -{
> - struct avrcp_device *dev;
> -
> - dev = g_new0(struct avrcp_device, 1);
> - bacpy(&dev->dst, dst);
> - devices = g_slist_prepend(devices, dev);
> -
> - return dev;
> -}
> -
> -static int device_cmp(gconstpointer s, gconstpointer user_data)
> -{
> - const struct avrcp_device *dev = s;
> - const bdaddr_t *dst = user_data;
> -
> - return bacmp(&dev->dst, dst);
> -}
> -
> static void disconnect_cb(void *data)
> {
> struct avrcp_device *dev = data;
> @@ -186,7 +155,6 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
> char address[18];
> uint16_t imtu, omtu;
> GError *gerr = NULL;
> - GSList *l;
> int fd;
>
> if (err) {
> @@ -209,13 +177,9 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
>
> ba2str(&dst, address);
>
> - l = g_slist_find_custom(devices, &dst, device_cmp);
> - if (l) {
> - dev = l->data;
> - if (dev->session) {
> - error("Unexpected connection");
> - return;
> - }
> + if (avrcp_find(&dst)) {
> + error("Unexpected connection");
> + return;
> } else {
> DBG("Incoming connection from %s", address);
> dev = avrcp_device_new(&dst);
> @@ -293,8 +257,7 @@ void bt_avrcp_unregister(void)
> {
> DBG("");
>
> - g_slist_free_full(devices, avrcp_device_free);
> - devices = NULL;
> + avrcp_free_all();
>
> ipc_unregister(HAL_SERVICE_ID_AVRCP);
>
> @@ -331,12 +294,10 @@ void bt_avrcp_connect(const bdaddr_t *dst)
> {
> struct avrcp_device *dev;
> char addr[18];
> - GSList *l;
>
> DBG("");
>
> - l = g_slist_find_custom(devices, dst, device_cmp);
> - if (l)
> + if (avrcp_find(dst))
> return;
>
> dev = avrcp_device_new(dst);
> @@ -352,16 +313,13 @@ void bt_avrcp_connect(const bdaddr_t *dst)
> void bt_avrcp_disconnect(const bdaddr_t *dst)
> {
> struct avrcp_device *dev;
> - GSList *l;
>
> DBG("");
>
> - l = g_slist_find_custom(devices, dst, device_cmp);
> - if (!l)
> + dev = avrcp_find(dst);
> + if (!dev)
> return;
>
> - dev = l->data;
> -
> if (dev->session) {
> avctp_shutdown(dev->session);
> return;
> --
> 1.8.3.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 v3] android: Add support for Valgrind in debug variants
From: Szymon Janc @ 2014-02-11 13:25 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1391680239-5396-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Thursday 06 of February 2014 10:50:39 Andrzej Kaczmarek wrote:
> This patch allows bluetoothd to be run with Valgrind easily in debug
> variants.
>
> For userdebug and eng variants bluetoothd is renamed to bluetoothd-main
> and bluetoothd acts a wrapper to launch it either with or without
> Valgrind (this is decided by value of persist.sys.bluetooth.valgrind
> property).
> ---
> android/Android.mk | 42 ++++++++++++++++++++++++
> android/bluetoothd-wrapper.c | 76
> ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118
> insertions(+)
> create mode 100644 android/bluetoothd-wrapper.c
>
> diff --git a/android/Android.mk b/android/Android.mk
> index 20105e6..52745fe 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -82,7 +82,15 @@ $(shell mkdir -p $(LOCAL_PATH)/bluez/lib/bluetooth)
> $(foreach file,$(lib_headers), $(shell ln -sf ../$(file)
> $(LOCAL_PATH)/bluez/lib/bluetooth/$(file)))
>
> LOCAL_MODULE_TAGS := optional
> +
> +# for userdebug/eng this module is bluetoothd-main since bluetoothd is used
> as +# wrapper to launch bluetooth with Valgrind
> +ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
> +LOCAL_MODULE := bluetoothd-main
> +LOCAL_STRIP_MODULE := false
> +else
> LOCAL_MODULE := bluetoothd
> +endif
>
> include $(BUILD_EXECUTABLE)
>
> @@ -406,3 +414,37 @@ LOCAL_CFLAGS:= \
> LOCAL_MODULE := libsbc
>
> include $(BUILD_SHARED_LIBRARY)
> +
> +ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
> +
> +#
> +# bluetoothd (debug)
> +# this is just a wrapper used in userdebug/eng to launch bluetoothd-main
> +# with/without Valgrind
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_SRC_FILES := \
> + bluez/android/bluetoothd-wrapper.c
> +
> +LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
> +
> +LOCAL_SHARED_LIBRARIES := \
> + libcutils \
> +
> +LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)
> +LOCAL_MODULE_TAGS := optional
> +LOCAL_MODULE := bluetoothd
> +
> +LOCAL_REQUIRED_MODULES := \
> + bluetoothd-main \
> + valgrind \
> + memcheck-$(TARGET_ARCH)-linux \
> + vgpreload_core-$(TARGET_ARCH)-linux \
> + vgpreload_memcheck-$(TARGET_ARCH)-linux \
> + default.supp
> +
> +include $(BUILD_EXECUTABLE)
> +
> +endif
> \ No newline at end of file
> diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c
> new file mode 100644
> index 0000000..e90277f
> --- /dev/null
> +++ b/android/bluetoothd-wrapper.c
> @@ -0,0 +1,76 @@
> +/*
> + * Copyright (C) 2014 Intel Corporation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and + *
> limitations under the License.
> + *
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +
> +#include <cutils/properties.h>
> +
> +#define PROPERTY_NAME "persist.sys.bluetooth.valgrind"
> +
> +#define VALGRIND_BIN "/system/bin/valgrind"
> +
> +#define BLUETOOTHD_BIN "/system/bin/bluetoothd-main"
> +
> +void run_valgrind(void)
> +{
> + char *prg_argv[4];
> + char *prg_envp[3];
> +
> + prg_argv[0] = VALGRIND_BIN;
> + prg_argv[1] = "--leak-check=full";
> + prg_argv[2] = BLUETOOTHD_BIN;
> + prg_argv[3] = NULL;
> +
> + prg_envp[0] = "G_SLICE=always-malloc";
> + prg_envp[1] = "G_DEBUG=gc-friendly";
> + prg_envp[2] = NULL;
> +
> + execve(prg_argv[0], prg_argv, prg_envp);
> +}
> +
> +void run_bluetoothd(void)
> +{
> + char *prg_argv[2];
> + char *prg_envp[1];
> +
> + prg_argv[0] = BLUETOOTHD_BIN;
> + prg_argv[1] = NULL;
> +
> + prg_envp[0] = NULL;
> +
> + execve(prg_argv[0], prg_argv, prg_envp);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + char value[PROPERTY_VALUE_MAX];
> +
> + if (property_get(PROPERTY_NAME, value, "") > 0 &&
> + (!strcasecmp(value, "true") || atoi(value) > 0))
> + run_valgrind();
> +
> + /* In case we failed to execute Valgrind, try to run bluetoothd
> + * without it
> + */
> +
> + run_bluetoothd();
> +
> + return 0;
> +}
run_valgrind() and run_bluetooth() should be static.
Other than that this looks good to me.
--
BR
Szymon Janc
^ permalink raw reply
* Re: Some patches applied on Fedora that maybe should be considered for being applied upstream
From: Bastien Nocera @ 2014-02-11 13:27 UTC (permalink / raw)
To: Pacho Ramos; +Cc: BlueZ development
In-Reply-To: <1392062509.4911.0.camel@belkin5>
On Mon, 2014-02-10 at 21:01 +0100, Pacho Ramos wrote:
> El lun, 10-02-2014 a las 14:40 +0100, Bastien Nocera escribió:
> > On Sun, 2014-02-09 at 09:53 +0100, Pacho Ramos wrote:
> > > Hello
> > >
> > > I was looking at bluez package and found some patches that maybe could
> > > be upstreamed. Also, I would like to know the reasons for not accepting
> > > them to ensure they are safe to be applied downstream by us too :)
> > >
> > > http://pkgs.fedoraproject.org/cgit/bluez.git/tree/0001-Allow-using-obexd-without-systemd-in-the-user-sessio.patch -> Does this cause any issues with systemd --user setups?
> >
> > Giovanni already posted this patch earlier. There's no distribution
> > using systemd sessions, so this doesn't work yet.
> >
> > > http://pkgs.fedoraproject.org/cgit/bluez.git/tree/0001-obex-Use-GLib-helper-function-to-manipulate-paths.patch
> > > http://pkgs.fedoraproject.org/cgit/bluez.git/tree/0002-autopair-Don-t-handle-the-iCade.patch
> > > http://pkgs.fedoraproject.org/cgit/bluez.git/tree/0004-agent-Assert-possible-infinite-loop.patch
> > > -> Any reason for not applying it upstream too?
> >
> > I've posted those patches to the list as well.
>
> And, do you know why they weren't accepted? (it's for trying to get them
> merged and not needing to carry them forever)
Read the threads for the various patches?
Mailing-lists, awful at tracking patches since forever...
^ permalink raw reply
* AW: Bluetooth with full AMP
From: Viswanatham, RaviTeja @ 2014-02-11 13:38 UTC (permalink / raw)
To: Andrei Emeltchenko
Cc: Marcel Holtmann,
bluez mailin list (linux-bluetooth@vger.kernel.org),
bzhao@marvell.com
In-Reply-To: <20140211122616.GF8980@aemeltch-MOBL1>
-----Urspr=FCngliche Nachricht-----
Von: linux-bluetooth-owner@vger.kernel.org [mailto:linux-bluetooth-owner@vg=
er.kernel.org] Im Auftrag von Andrei Emeltchenko
Gesendet: Dienstag, 11. Februar 2014 13:27
An: Viswanatham, RaviTeja
Cc: Marcel Holtmann; bluez mailin list (linux-bluetooth@vger.kernel.org); b=
zhao@marvell.com
Betreff: Re: Bluetooth with full AMP
Hi Raviteja,
> On Mon, Feb 10, 2014 at 10:35:24AM -0800, Marcel Holtmann wrote:
> > Hi Ravi,
> >=20
> > > I am working on Ubuntu 12.04 with a Bluetooth 3.0 +HS + wifi combo=20
> > > USB dongle.
> > >=20
> > > I want to reach a data transfer speed of up to 24 Mbit/s.=20
> > >=20
> > > My Questions: Does Bluez support high speed data transfer rates up=20
> > > to
> > > 24 Mbit/s (Bluetooth 3.0+HS) ?=20
> > >=20
> > > If it does, is there any user configuration involved to achieve that?
> > > What other requirements need to be met? Does, Bluetooth enables=20
> > > AMP function to communicate 802.11n channel to support high speed=20
> > > or it has to be configure with any other drivers?
> > >=20
> > > I am new to Linux a detail explanation would be really appreciated.
> > > Thank you in advance for your support.
> >=20
> > we do support Bluetooth HS operation. However your WiFi device needs=20
> > to be exposed as AMP Controller. Most WiFi hardware needs a special=20
> > driver to expose itself as AMP Controller. There is no generic=20
> > driver for mac80211 subsystem in the kernel.
>=20
> Some devices have AMP Controller implemented in firmware. I was using=20
> Marvell SD8787, probably newer Marvell devices also works.
>=20
> You may check drivers/bluetooth/btmrvl_main.c to see how HCI dev_type=20
> HCI_AMP is assigned.
>=20
> Thanks for replying me. I would like to know some more information=20
> about the Bluetooth dongle. As you said the Marvell SD8787 is kind of=20
> a SoC chipset. Is there any USB Bluetooth device available in the=20
> market which supports out of the box.
The only possibility I know is Marvell development board like:
http://avnetexpress.avnet.com/store/em/EMController/Development-Kits/Marvel=
l/RD-88W-SD-8787-A0/_/R-10001817/A-10001817/An-0?action=3Dpart&catalogId=3D=
500201&langId=3D-1&storeId=3D500201
> I am running 3.11 kernel and I already build the Marvell option inside=20
> the kernel.
>=20
> Is there any dongles available in the market which supports full AMP.=20
At least I couldn't find one. If you find it let us know ;)
> If
> not are there any other possibilities to fix the Marvell driver with=20
> the existing dongle. Please any hints as I am working on ARM board I=20
> need to fix the USB Bluetooth device which can transfer with high speed.
>=20
Try to contact Marvell and ask which one supports FullAMP.
Thanks for the reply. I will try to find out about the hardware while conta=
cting Marvell. :)
I bought a USB Bluetooth 3.0 HS + wlan combo dongle. The wlan driver is bas=
ed on realtek8192cu in the mailing list they mentioned it is based on soft=
AMP. I found that the realtek they didn't upgrade new driver which support=
s new kernel (3.11 and above). =20
As I understood that Marvell they developed the driver with the FullAMP so =
that the device can run with high speed. In the same way is there any othe=
r possibilities drivers or else patches available. Any suggestion or hint c=
ould be really appreciated.=20
Thanks in advance,
=20
Regards,
Raviteja
^ permalink raw reply
* [PATCH v4] android: Add support for Valgrind in debug variants
From: Andrzej Kaczmarek @ 2014-02-11 14:28 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Andrzej Kaczmarek
This patch allows bluetoothd to be run with Valgrind easily in debug
variants.
For userdebug and eng variants bluetoothd is renamed to bluetoothd-main
and bluetoothd acts a wrapper to launch it either with or without
Valgrind (this is decided by value of persist.sys.bluetooth.valgrind
property).
---
android/Android.mk | 42 ++++++++++++++++++++++++
android/bluetoothd-wrapper.c | 76 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 118 insertions(+)
create mode 100644 android/bluetoothd-wrapper.c
diff --git a/android/Android.mk b/android/Android.mk
index b82ef84..84e96fe 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -91,7 +91,15 @@ $(shell mkdir -p $(LOCAL_PATH)/bluez/lib/bluetooth)
$(foreach file,$(lib_headers), $(shell ln -sf ../$(file) $(LOCAL_PATH)/bluez/lib/bluetooth/$(file)))
LOCAL_MODULE_TAGS := optional
+
+# for userdebug/eng this module is bluetoothd-main since bluetoothd is used as
+# wrapper to launch bluetooth with Valgrind
+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+LOCAL_MODULE := bluetoothd-main
+LOCAL_STRIP_MODULE := false
+else
LOCAL_MODULE := bluetoothd
+endif
include $(BUILD_EXECUTABLE)
@@ -415,3 +423,37 @@ LOCAL_CFLAGS:= \
LOCAL_MODULE := libsbc
include $(BUILD_SHARED_LIBRARY)
+
+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+
+#
+# bluetoothd (debug)
+# this is just a wrapper used in userdebug/eng to launch bluetoothd-main
+# with/without Valgrind
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ bluez/android/bluetoothd-wrapper.c
+
+LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := bluetoothd
+
+LOCAL_REQUIRED_MODULES := \
+ bluetoothd-main \
+ valgrind \
+ memcheck-$(TARGET_ARCH)-linux \
+ vgpreload_core-$(TARGET_ARCH)-linux \
+ vgpreload_memcheck-$(TARGET_ARCH)-linux \
+ default.supp
+
+include $(BUILD_EXECUTABLE)
+
+endif
\ No newline at end of file
diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c
new file mode 100644
index 0000000..122e6b0
--- /dev/null
+++ b/android/bluetoothd-wrapper.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2014 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <cutils/properties.h>
+
+#define PROPERTY_NAME "persist.sys.bluetooth.valgrind"
+
+#define VALGRIND_BIN "/system/bin/valgrind"
+
+#define BLUETOOTHD_BIN "/system/bin/bluetoothd-main"
+
+static void run_valgrind(void)
+{
+ char *prg_argv[4];
+ char *prg_envp[3];
+
+ prg_argv[0] = VALGRIND_BIN;
+ prg_argv[1] = "--leak-check=full";
+ prg_argv[2] = BLUETOOTHD_BIN;
+ prg_argv[3] = NULL;
+
+ prg_envp[0] = "G_SLICE=always-malloc";
+ prg_envp[1] = "G_DEBUG=gc-friendly";
+ prg_envp[2] = NULL;
+
+ execve(prg_argv[0], prg_argv, prg_envp);
+}
+
+static void run_bluetoothd(void)
+{
+ char *prg_argv[2];
+ char *prg_envp[1];
+
+ prg_argv[0] = BLUETOOTHD_BIN;
+ prg_argv[1] = NULL;
+
+ prg_envp[0] = NULL;
+
+ execve(prg_argv[0], prg_argv, prg_envp);
+}
+
+int main(int argc, char *argv[])
+{
+ char value[PROPERTY_VALUE_MAX];
+
+ if (property_get(PROPERTY_NAME, value, "") > 0 &&
+ (!strcasecmp(value, "true") || atoi(value) > 0))
+ run_valgrind();
+
+ /* In case we failed to execute Valgrind, try to run bluetoothd
+ * without it
+ */
+
+ run_bluetoothd();
+
+ return 0;
+}
--
1.8.5.3
^ permalink raw reply related
* Re: [PATCH 1/4] android/avrcp: Decouple AVRCP logic from btio
From: Szymon Janc @ 2014-02-11 14:37 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <20140211130306.GG8980@aemeltch-MOBL1>
Hi Andrei,
On Tuesday 11 of February 2014 15:03:07 Andrei Emeltchenko wrote:
> Hi All
>
> On Thu, Feb 06, 2014 at 06:06:11PM +0200, Andrei Emeltchenko wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > The patch makes AVRCP to be channel-agnostic so that it might be used in
> > unit tests. The idea is that all AVRCP logic would come to avrcp-lib and
> > channel stuff got to avrcp.
>
> Any comments regarding this patch?
Waiting for V2 as discussed offline.
--
BR
Szymon Janc
^ permalink raw reply
* Re: [PATCH] Bluetooth: Fix channel check when binding RFCOMM sock
From: Marcel Holtmann @ 2014-02-11 15:58 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: bluez mailin list (linux-bluetooth@vger.kernel.org)
In-Reply-To: <1392119413-26341-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
> When binding RFCOMM socket we should only check if there is another
> socket bound or listening on the same channel number. In other case,
> it won't be possible to bind/listen on a channel in case we have
> connection made to remote device on the same channel number.
since this has been used for years now, you need to be more specific on when this fails.
> Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
> ---
> net/bluetooth/rfcomm/sock.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
> index 00573fb..9912e23 100644
> --- a/net/bluetooth/rfcomm/sock.c
> +++ b/net/bluetooth/rfcomm/sock.c
> @@ -331,6 +331,7 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
> {
> struct sockaddr_rc *sa = (struct sockaddr_rc *) addr;
> struct sock *sk = sock->sk;
> + struct sock *sk1;
> int err = 0;
>
> BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr);
> @@ -352,7 +353,9 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
>
> write_lock(&rfcomm_sk_list.lock);
>
> - if (sa->rc_channel && __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr)) {
> + sk1 = __rfcomm_get_sock_by_addr(sa->rc_channel, &sa->rc_bdaddr);
> + if (sa->rc_channel && sk1 && (sk1->sk_state == BT_BOUND ||
> + sk1->sk_state == BT_LISTEN)) {
> err = -EADDRINUSE;
can we find a better name than sk1 here.
> } else {
> /* Save source address */
Regards
Marcel
^ permalink raw reply
* Re: [PATCH] btusb.c add IMC Networks id 13d3:3404 (bcm20702A0)
From: Jurgen Kramer @ 2014-02-11 16:00 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: BlueZ development
In-Reply-To: <F0885393-70B7-483B-8F97-C4AB73B451E6@holtmann.org>
Hi Marcel,
On Mon, 2014-02-10 at 10:33 -0800, Marcel Holtmann wrote:
> HI Jurgen,
>
> > Attached patch adds support for IMC Networks (13d3:3404) to BCM20702A0
> > in btusb.c. This device is used on the Asrock Z87E-ITX motherboard.
> > Tested against 3.12.9.
> >
> > diff -uNrp
> > linux-3.12.9-301.jk1.fc20.x86_64.orig/drivers/bluetooth/btusb.c
> > linux-3.12.9-301.jk1.fc20.x86_64.new/drivers/bluetooth/btusb.c
> > --- a/drivers/bluetooth/btusb.c 2014-02-10 11:35:08.976975562 +0100
> > +++ b/drivers/bluetooth/btusb.c 2014-02-10 11:37:03.864921122 +0100
> > @@ -106,6 +106,7 @@ static struct usb_device_id btusb_table[
> > { USB_DEVICE(0x04ca, 0x2003) },
> > { USB_DEVICE(0x0489, 0xe042) },
> > { USB_DEVICE(0x413c, 0x8197) },
> > + { USB_DEVICE(0x13d3, 0x3404) },
> >
> > /* Foxconn - Hon Hai */
> > { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) },
> >
> > Signed-off-by: Jurgen Kramer <gtm.kramer@xs4all.nl>
> >
> > Jurgen
> > <btusb-bcm20702a0-add-imc-networks.patch>
>
> please send patches inline created from git-format-patch and include /sys/kernel/debug/usb/devices details for this device.
OK. I'll resend in a couple of days.
Regards,
Jurgen
^ permalink raw reply
* Re: [RFC 0/2] Add hci_smd driver
From: Lukasz Rymanowski @ 2014-02-11 16:23 UTC (permalink / raw)
To: linux-arm-msm; +Cc: Lukasz Rymanowski, linux-bluetooth@vger.kernel.org
In-Reply-To: <1391772937-12802-1-git-send-email-lukasz.rymanowski@tieto.com>
Hi
On 7 February 2014 12:35, Lukasz Rymanowski <lukasz.rymanowski@tieto.com> wrote:
> Hello,
>
> This is a try (long shoot) to upstream hci shared memory driver (hci_smd)
> which is used on Qualcomm platforms and BT chips.
>
> To make it build with upstream tree I had to introduce some simple SMD API.
> The idea here is that since SMD channel is represented by platform device
> (as it is done in mach-msm),
> then platfrom_data contains smd_data which contains API for that channel.
>
> Writing this SMD API I was inspired with MSM-SMD and since I'm not an expert
> in this area I'm asking for comments here.
>
> Maybe instead of SMD API I made, I should expose functions like smd_open(), smd_write()
> etc. something similar how sdio does, and just deliver to upstream dummy device
> implementing this SMD API?
>
> Other options I was considering is to implement module inside mach-msm which
> would handle registering SMD BT Channels and when it is done, it would register
> new platform device like "smd-bt". Then I could move smd.h to some bluetooth includes
> (althought don't now where at the moment) and hci_smd would register driver for "smd-bt"
> In this case I would also could rid of one static variable I have now in hci_smd
>
> Comments on those options are welcome.
>
> Anyway, Hci_smd is based on one of the older version of this driver found in msm kernel
> branch, so there are no wakelocks as in new version and also workqueues are used
> instead of takslet.
>
> Since SMD expose two channels, one for CMD/EVENT and one for ACL Data I decide to
> do separate worqueues for this. This is to make sure that ACL data never blocks EVENT
> packages
>
Adding linux-arm-msm group for comments on SMD API.
BR
Lukasz
> Lukasz Rymanowski (2):
> Add basic API for shared memory driver
> bluetooth: Add initial support for BT chip over SMD
>
> drivers/bluetooth/Kconfig | 9 +
> drivers/bluetooth/Makefile | 1 +
> drivers/bluetooth/hci_smd.c | 461 ++++++++++++++++++++++++++++++++++++++++++++
> include/linux/smd.h | 68 +++++++
> include/net/bluetooth/hci.h | 1 +
> 5 files changed, 540 insertions(+)
> create mode 100644 drivers/bluetooth/hci_smd.c
> create mode 100644 include/linux/smd.h
>
> --
> 1.8.4
>
^ permalink raw reply
* Re: [RFC 1/2] Add basic API for shared memory driver
From: Lukasz Rymanowski @ 2014-02-11 16:23 UTC (permalink / raw)
To: linux-arm-msm; +Cc: Lukasz Rymanowski, linux-bluetooth@vger.kernel.org
In-Reply-To: <1391772937-12802-2-git-send-email-lukasz.rymanowski@tieto.com>
Hi
On 7 February 2014 12:35, Lukasz Rymanowski <lukasz.rymanowski@tieto.com> wrote:
> This patch adds simple API to shared memory driver based on msm-smd.h
> This is required in order to add support for support Qualcomm BT chips
> via SMD
>
> Signed-off-by: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
> ---
> include/linux/smd.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 69 insertions(+)
> create mode 100644 include/linux/smd.h
>
> diff --git a/include/linux/smd.h b/include/linux/smd.h
> new file mode 100644
> index 0000000..58de0d4
> --- /dev/null
> +++ b/include/linux/smd.h
> @@ -0,0 +1,69 @@
> +/*
> +* smd.h - API for Shared Memory Driver
> +*
> +* Copyright (c) 2014 Intel Corporation
> +*
> +* This program is free software; you can redistribute it and/or modify
> +* it under the terms of the GNU General Public License version 2 as
> +* published by the Free Software Foundation.
> +*/
> +
> +#ifndef _SMD_H_
> +#define _SMD_H_
> +
> +#include <linux/platform_device.h>
> +
> +/**
> +* Events from smd device.
> +*/
> +#define SMD_EVENT_DATA 1
> +#define SMD_EVENT_OPEN 2
> +#define SMD_EVENT_CLOSE 3
> +
> +struct smd_channel;
> +struct smd_notify_data;
> +struct smd_data;
> +
> +/**
> +* struct smd_ops - specific operation for smd channel
> +*
> +* @open: Open SMD channel. It should return zero once device is opened.
> +* On open there is need to pass notification cb which is used
> +* for notifications form SMD device.
> +* @close Close SMD channel
> +* @write: Write data to SMD channel. It should return number of written
> +* bytes or negative value in case of error.
> +* @read: Read data from SMD channel.It should return number of written
> +* bytes or negative value in case of error.
> +*@read_avail: Returns number of bytes ready to be read. This should be called
> +* before read in order to allocate enought skb
> +*
> +*/
> +struct smd_ops {
> + int (*open)(struct smd_data *s,
> + void (*notify)(struct platform_device *pdev,
> + unsigned int event));
> + int (*close)(struct smd_data *s);
> + int (*write)(struct smd_data *s, const void *data, int len);
> + int (*read)(struct smd_data *s, void *buf, int len);
> + int (*read_avail)(struct smd_data *s);
> +};
> +/**
> +* struct smd_data - smd device data for shared memory channel
> +*
> +* @pdev: Platform device for given smd channel.
> +* @ops: SMD specific operations for this smd channel.
> +* @ch: SMD channel which is used by SMD device. Should not be
> +* used by the driver
> +* @notifier: SMD notifier data. Shall not be used by driver.
> +*
> +* smd_data are initialized by the platform and are available for driver
> +* in platform_data.
> +*/
> +struct smd_data {
> + struct platform_device *pdev;
> + struct smd_ops ops;
> + struct smd_channel *ch;
> + struct smd_notify_data *notify_data;
> +};
> +#endif
> --
Adding linux-arm-msm group for comments on SMD API
BR
Lukasz
> 1.8.4
>
^ permalink raw reply
* Re: [RFC 2/2] bluetooth: Add initial support for BT chip over SMD
From: Lukasz Rymanowski @ 2014-02-11 16:24 UTC (permalink / raw)
To: linux-arm-msm; +Cc: Lukasz Rymanowski, linux-bluetooth@vger.kernel.org
In-Reply-To: <1391772937-12802-3-git-send-email-lukasz.rymanowski@tieto.com>
Hi,
On 7 February 2014 12:35, Lukasz Rymanowski <lukasz.rymanowski@tieto.com> wrote:
> This patch adds support for Qualcomm chips which uses msm
> shared memory driver as a transport layer.
>
> This driver based on SMD driver found in msm kernel branch.
>
> Signed-off-by: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
> ---
> drivers/bluetooth/Kconfig | 9 +
> drivers/bluetooth/Makefile | 1 +
> drivers/bluetooth/hci_smd.c | 460 ++++++++++++++++++++++++++++++++++++++++++++
> include/net/bluetooth/hci.h | 1 +
> 4 files changed, 471 insertions(+)
> create mode 100644 drivers/bluetooth/hci_smd.c
>
> diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
> index 11a6104..f8a46c5 100644
> --- a/drivers/bluetooth/Kconfig
> +++ b/drivers/bluetooth/Kconfig
> @@ -242,4 +242,13 @@ config BT_WILINK
>
> Say Y here to compile support for Texas Instrument's WiLink7 driver
> into the kernel or say M to compile it as module.
> +
> +config BT_HCISMD
> + tristate "Qualcomm HCI Shared Memory Driver"
> + help
> + This enables the Bluetooth driver for Qualcomm BT devices uses SMD interface.
> +
> + Say Y here to compile support for Qualcomm over SMD driver into kernel or
> + say M to compile it as module (hci_smd)
> +
> endmenu
> diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
> index 9fe8a87..0666e60 100644
> --- a/drivers/bluetooth/Makefile
> +++ b/drivers/bluetooth/Makefile
> @@ -19,6 +19,7 @@ obj-$(CONFIG_BT_ATH3K) += ath3k.o
> obj-$(CONFIG_BT_MRVL) += btmrvl.o
> obj-$(CONFIG_BT_MRVL_SDIO) += btmrvl_sdio.o
> obj-$(CONFIG_BT_WILINK) += btwilink.o
> +obj-$(CONFIG_BT_HCISMD) += hci_smd.o
>
> btmrvl-y := btmrvl_main.o
> btmrvl-$(CONFIG_DEBUG_FS) += btmrvl_debugfs.o
> diff --git a/drivers/bluetooth/hci_smd.c b/drivers/bluetooth/hci_smd.c
> new file mode 100644
> index 0000000..9eb3675
> --- /dev/null
> +++ b/drivers/bluetooth/hci_smd.c
> @@ -0,0 +1,460 @@
> +
> +/*
> + *
> + * HCI_SMD (HCI Shared Memory Driver) is Qualcomm's Shared memory driver
> + * for the HCI protocol.
> + *
> + * Copyright (C) 2000-2001 Qualcomm Incorporated
> + * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
> + * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org>
> + * Copyright (C) 2011, Code Aurora Forum. All rights reserved.
> + * Copyright (C) 2014, Intel Corporation. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/types.h>
> +#include <linux/errno.h>
> +#include <linux/string.h>
> +#include <linux/skbuff.h>
> +#include <linux/workqueue.h>
> +#include <linux/platform_device.h>
> +#include <linux/completion.h>
> +#include <linux/jiffies.h>
> +#include <linux/spinlock.h>
> +
> +#include <net/bluetooth/bluetooth.h>
> +#include <net/bluetooth/hci_core.h>
> +
> +#include <linux/smd.h>
> +
> +#define VERSION "0.1"
> +
> +#define SMD_CMD_CHANNEL "APPS_RIVA_BT_CMD"
> +#define SMD_ACL_CHANNEL "APPS_RIVA_BT_ACL"
> +
> +#define SMD_APPS_RIVA_BT_CMD_READY 0x01
> +#define SMD_APPS_RIVA_BT_ACL_READY 0x02
> +#define SMD_READY ((SMD_APPS_RIVA_BT_CMD_READY) | (SMD_APPS_RIVA_BT_ACL_READY))
> +
> +struct rx_work {
> + struct work_struct work;
> + struct smd_data *smd;
> + struct hci_dev *hdev;
> + u8 pkt_type;
> +};
> +
> +struct smd_channel_data {
> + struct hci_dev *hdev;
> + struct workqueue_struct *wq;
> + struct smd_data *smd;
> +};
> +
> +struct hci_smd_data {
> + struct hci_dev *hdev;
> +
> + struct smd_channel_data *smd_cmd;
> + struct smd_channel_data *smd_acl;
> + u8 ready_flags;
> + struct completion smd_ready;
> +
> + /* Protects ready_flags */
> + spinlock_t flags_lock;
> +};
> +
> +static struct hci_smd_data hs;
> +
> +static void hci_smd_channel_open(struct smd_channel_data *scd)
> +{
> + const char *name = scd->smd->pdev->name;
> +
> + spin_lock(&hs.flags_lock);
> + if (scd->hdev) {
> + set_bit(HCI_RUNNING, &scd->hdev->flags);
> + spin_unlock(&hs.flags_lock);
> + return;
> + }
> +
> + if (!strncmp(name, SMD_CMD_CHANNEL, sizeof(SMD_CMD_CHANNEL)))
> + hs.ready_flags |= SMD_APPS_RIVA_BT_CMD_READY;
> +
> + if (!strncmp(name, SMD_ACL_CHANNEL, sizeof(SMD_ACL_CHANNEL)))
> + hs.ready_flags |= SMD_APPS_RIVA_BT_ACL_READY;
> +
> + if ((SMD_READY & hs.ready_flags) != SMD_READY) {
> + spin_unlock(&hs.flags_lock);
> + return;
> + }
> +
> + spin_unlock(&hs.flags_lock);
> + complete_all(&hs.smd_ready);
> +}
> +
> +static void hci_smd_channel_close(struct smd_channel_data *scd)
> +{
> + if (!scd->hdev)
> + return;
> +
> + clear_bit(HCI_RUNNING, &scd->hdev->flags);
> +}
> +
> +static int hci_smd_open(struct hci_dev *hdev)
> +{
> + BT_DBG("hdev %s, %p", hdev->name, hdev);
> +
> + set_bit(HCI_RUNNING, &hdev->flags);
> + return 0;
> +}
> +
> +static int hci_smd_close(struct hci_dev *hdev)
> +{
> + BT_DBG("hdev %s %p", hdev->name, hdev);
> +
> + clear_bit(HCI_RUNNING, &hdev->flags);
> + return 0;
> +}
> +
> +static void hci_smd_rx_work(struct work_struct *work)
> +{
> + struct rx_work *wk = container_of(work, struct rx_work, work);
> + u8 type = wk->pkt_type;
> + struct smd_data *smd = wk->smd;
> + struct hci_dev *hdev = wk->hdev;
> + struct sk_buff *skb;
> + int len;
> +
> + BT_DBG("hdev %p, %02x", hdev, type);
> +
> + /*It s save to free work here */
> + kfree(wk);
> +
> + len = smd->ops.read_avail(smd);
> + if (len > HCI_MAX_FRAME_SIZE)
> + return;
> +
> + while (len) {
> + int rc = 0;
> + skb = bt_skb_alloc(len, GFP_KERNEL);
> + if (!skb)
> + return;
> +
> + rc = smd->ops.read(smd, skb_put(skb, len), len);
> + if (rc < len) {
> + kfree_skb(skb);
> + return;
> + }
> +
> + skb->dev = (void *)hdev;
> + bt_cb(skb)->pkt_type = type;
> + skb_orphan(skb);
> +
> + rc = hci_recv_frame(hdev, skb);
> + if (rc < 0) {
> + BT_ERR("Failed to pass skb to Bluetooth module");
> + kfree_skb(skb);
This is wrong. need to remove it.
> + return;
> + }
> +
> + len = smd->ops.read_avail(smd);
> + if (len > HCI_MAX_FRAME_SIZE)
> + return;
> + }
> +}
> +
> +static int hci_smd_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
> +{
> + struct hci_smd_data *hs = hci_get_drvdata(hdev);
> + struct smd_data *smd;
> + int sent;
> +
> + if (!hdev) {
> + BT_ERR("Frame for unknown HCI device (hdev=NULL)");
> + return -ENODEV;
> + }
> +
> + if (!test_bit(HCI_RUNNING, &(hdev->flags)))
> + return -EBUSY;
> +
> + switch (bt_cb(skb)->pkt_type) {
> + case HCI_COMMAND_PKT:
> + smd = hs->smd_cmd->smd;
> + sent = smd->ops.write(smd, skb->data, skb->len);
> + break;
> + case HCI_ACLDATA_PKT:
> + case HCI_SCODATA_PKT:
> + smd = hs->smd_acl->smd;
> + sent = smd->ops.write(smd, skb->data, skb->len);
> + break;
> + default:
> + BT_ERR("Unknown package");
> + kfree_skb(skb);
> + return -EPROTO;
> + }
> +
> + kfree_skb(skb);
> +
> + if (sent < 0) {
> + BT_ERR("Failed to send all data");
> + return -ENOSPC;
> + }
> +
> + return 0;
> +}
> +
> +static struct rx_work *alloc_rx_work(u8 pkt_type, struct smd_data *smd,
> + struct hci_dev *hdev)
> +{
> + struct rx_work *w = kmalloc(sizeof(*w), GFP_ATOMIC);
> +
> + if (!w) {
> + BT_ERR("Could not allocate work");
> + return NULL;
> + }
> +
> + INIT_WORK(&w->work, hci_smd_rx_work);
> + w->pkt_type = pkt_type;
> + w->smd = smd;
> + w->hdev = hdev;
> +
> + return w;
> +}
> +
> +static void hci_smd_notify(struct platform_device *pdev,
> + unsigned int event, u8 pkt_type)
> +{
> + struct smd_channel_data *scd = dev_get_drvdata(&pdev->dev);
> + struct hci_dev *hdev = scd->hdev;
> + struct rx_work *w;
> +
> + if (!scd || !scd->smd) {
> + BT_ERR("SMD channel data not avaiable");
> + return;
> + }
> +
> + switch (event) {
> + case SMD_EVENT_DATA:
> + w = alloc_rx_work(pkt_type, scd->smd, hdev);
> + if (w && hdev)
> + queue_work(scd->wq, &w->work);
> + else
> + BT_ERR("Read failed hdev:%p, work:%p ", hdev, w);
> + break;
> + case SMD_EVENT_OPEN:
> + hci_smd_channel_open(scd);
> + break;
> + case SMD_EVENT_CLOSE:
> + hci_smd_channel_close(scd);
> + break;
> + default:
> + break;
> + }
> +}
> +
> +static void hci_smd_notify_cmd(struct platform_device *pdev,
> + unsigned int event)
> +{
> + hci_smd_notify(pdev, event, HCI_EVENT_PKT);
> +}
> +
> +static void hci_smd_notify_data(struct platform_device *pdev,
> + unsigned int event)
> +{
> + hci_smd_notify(pdev, event, HCI_ACLDATA_PKT);
> +}
> +
> +static int hci_smd_register(void)
> +{
> + struct hci_dev *hdev;
> + int err;
> +
> + BT_DBG("hci_smd_register");
> +
> + /*
> + * Lets use two different worqueues for Event and ACL data so we make
> + * sure that Event will never be blocked by ACL data.
> + */
> + hs.smd_cmd->wq = alloc_workqueue("smd_event", WQ_HIGHPRI |
> + WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
> + if (!hs.smd_cmd->wq) {
> + BT_ERR("Error allocating event workqueue");
> + err = -ENOMEM;
> + goto close_smd;
> + }
> +
> + hs.smd_acl->wq = alloc_workqueue("data_event", WQ_HIGHPRI |
> + WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
> + if (!hs.smd_acl->wq) {
> + BT_ERR("Error allocating data workqueue");
> + destroy_workqueue(hs.smd_cmd->wq);
> + err = -ENOMEM;
> + goto close_smd;
> + }
> +
> + /* Initialize and register HCI device */
> + hdev = hci_alloc_dev();
> + if (!hdev) {
> + BT_ERR("Error allocating HCI dev");
> + err = -ENOMEM;
> + goto cleanup;
> + }
> +
> + hdev->bus = HCI_SMD;
> + hci_set_drvdata(hdev, &hs);
> +
> + hdev->open = hci_smd_open;
> + hdev->close = hci_smd_close;
> + hdev->send = hci_smd_send_frame;
> +
> + hs.smd_cmd->hdev = hdev;
> + hs.smd_acl->hdev = hdev;
> +
> + err = hci_register_dev(hdev);
> + if (!err)
> + return 0;
> +
> + BT_ERR("Can't register HCI device");
> + hci_free_dev(hdev);
> +
> +cleanup:
> + destroy_workqueue(hs.smd_cmd->wq);
> + destroy_workqueue(hs.smd_acl->wq);
> +close_smd:
> + hs.smd_cmd->smd->ops.close(hs.smd_cmd->smd);
> + hs.smd_acl->smd->ops.close(hs.smd_acl->smd);
> +
> + return err;
> +}
> +
> +static int smd_cmd_channel_probe(struct platform_device *pdev)
> +{
> + struct smd_data *smd = dev_get_platdata(&pdev->dev);
> + struct smd_channel_data *scd = kzalloc(sizeof(*scd), GFP_KERNEL);
> + int err;
> +
> + scd->smd = smd;
> + hs.smd_cmd = scd;
> +
> + dev_set_drvdata(&pdev->dev, scd);
> +
> + err = smd->ops.open(smd, hci_smd_notify_cmd);
> + if (err < 0) {
> + BT_ERR("Can not open %s", SMD_CMD_CHANNEL);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static int smd_data_channel_probe(struct platform_device *pdev)
> +{
> + struct smd_data *smd = dev_get_platdata(&pdev->dev);
> + struct smd_channel_data *scd = kzalloc(sizeof(*scd), GFP_KERNEL);
> + int err;
> +
> + scd->smd = smd;
> + hs.smd_acl = scd;
> +
> + dev_set_drvdata(&pdev->dev, scd);
> +
> + err = smd->ops.open(smd, hci_smd_notify_data);
> + if (err < 0) {
> + BT_ERR("Can not open %s", SMD_ACL_CHANNEL);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +
> +static int smd_channel_remove(struct platform_device *pdev)
> +{
> + struct smd_data *smd = dev_get_platdata(&pdev->dev);
> + return smd->ops.close(smd);
> +}
> +
> +static struct platform_driver cmd_drv = {
> + .driver = {
> + .owner = THIS_MODULE,
> + .name = SMD_CMD_CHANNEL,
> + },
> + .probe = smd_cmd_channel_probe,
> + .remove = smd_channel_remove,
> +
> +};
> +
> +static struct platform_driver acl_drv = {
> + .driver = {
> + .owner = THIS_MODULE,
> + .name = SMD_ACL_CHANNEL,
> + },
> + .probe = smd_data_channel_probe,
> + .remove = smd_channel_remove,
> +};
> +
> +static int __init hci_smd_init(void)
> +{
> + int err;
> +
> + BT_INFO("hci smd driver ver %s", VERSION);
> +
> + memset(&hs, 0, sizeof(hs));
> +
> + spin_lock_init(&hs.flags_lock);
> + init_completion(&hs.smd_ready);
> +
> + /*
> + * SMD channels are represented by platform devices. We need them two
> + * for BT operations. Channel for BT CMD/EVENT traffic and BT ACL DATA
> + * traffic.
> + */
> + err = platform_driver_register(&cmd_drv);
> + if (err < 0) {
> + BT_ERR("Failed to register drv: %s err: %d",
> + cmd_drv.driver.name, err);
> + return err;
> + }
> +
> + err = platform_driver_register(&acl_drv);
> + if (err < 0) {
> + BT_ERR("Failed to register drv: %s, err: %d",
> + acl_drv.driver.name, err);
> + platform_driver_unregister(&cmd_drv);
> + return err;
> + }
> +
> + /* Let's wait until SMD channels are ready */
> + err = wait_for_completion_killable_timeout(&hs.smd_ready,
> + msecs_to_jiffies(5000));
> + if (err <= 0)
> + return err;
> +
> + return hci_smd_register();
> +}
> +
> +static void __exit hci_smd_exit(void)
> +{
> + kfree(hs.smd_cmd);
> + kfree(hs.smd_acl);
> +
> + platform_driver_unregister(&cmd_drv);
> + platform_driver_unregister(&acl_drv);
> +}
> +
> +module_init(hci_smd_init);
> +module_exit(hci_smd_exit);
> +
> +MODULE_AUTHOR("Lukasz Rymanowski <lukasz.rymanowski@tieto.com>");
> +MODULE_AUTHOR("Ankur Nandwani <ankurn@codeaurora.org>");
> +MODULE_DESCRIPTION("Bluetooth SMD driver ver " VERSION);
> +MODULE_VERSION(VERSION);
> +MODULE_LICENSE("GPL v2");
> diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
> index 352d3d7..149b06a 100644
> --- a/include/net/bluetooth/hci.h
> +++ b/include/net/bluetooth/hci.h
> @@ -58,6 +58,7 @@
> #define HCI_RS232 4
> #define HCI_PCI 5
> #define HCI_SDIO 6
> +#define HCI_SMD 7
>
> /* HCI controller types */
> #define HCI_BREDR 0x00
> --
Adding linux-arm-msm group for comments on SMD API
BR
Lukasz
> 1.8.4
>
^ permalink raw reply
* Re: [PATCH v4] android: Add support for Valgrind in debug variants
From: Szymon Janc @ 2014-02-11 16:34 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1392128934-11906-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Tuesday 11 of February 2014 15:28:54 Andrzej Kaczmarek wrote:
> This patch allows bluetoothd to be run with Valgrind easily in debug
> variants.
>
> For userdebug and eng variants bluetoothd is renamed to bluetoothd-main
> and bluetoothd acts a wrapper to launch it either with or without
> Valgrind (this is decided by value of persist.sys.bluetooth.valgrind
> property).
> ---
> android/Android.mk | 42 ++++++++++++++++++++++++
> android/bluetoothd-wrapper.c | 76
> ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118
> insertions(+)
> create mode 100644 android/bluetoothd-wrapper.c
>
> diff --git a/android/Android.mk b/android/Android.mk
> index b82ef84..84e96fe 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -91,7 +91,15 @@ $(shell mkdir -p $(LOCAL_PATH)/bluez/lib/bluetooth)
> $(foreach file,$(lib_headers), $(shell ln -sf ../$(file)
> $(LOCAL_PATH)/bluez/lib/bluetooth/$(file)))
>
> LOCAL_MODULE_TAGS := optional
> +
> +# for userdebug/eng this module is bluetoothd-main since bluetoothd is used
> as +# wrapper to launch bluetooth with Valgrind
> +ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
> +LOCAL_MODULE := bluetoothd-main
> +LOCAL_STRIP_MODULE := false
> +else
> LOCAL_MODULE := bluetoothd
> +endif
>
> include $(BUILD_EXECUTABLE)
>
> @@ -415,3 +423,37 @@ LOCAL_CFLAGS:= \
> LOCAL_MODULE := libsbc
>
> include $(BUILD_SHARED_LIBRARY)
> +
> +ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
> +
> +#
> +# bluetoothd (debug)
> +# this is just a wrapper used in userdebug/eng to launch bluetoothd-main
> +# with/without Valgrind
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_SRC_FILES := \
> + bluez/android/bluetoothd-wrapper.c
> +
> +LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
> +
> +LOCAL_SHARED_LIBRARIES := \
> + libcutils \
> +
> +LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)
> +LOCAL_MODULE_TAGS := optional
> +LOCAL_MODULE := bluetoothd
> +
> +LOCAL_REQUIRED_MODULES := \
> + bluetoothd-main \
> + valgrind \
> + memcheck-$(TARGET_ARCH)-linux \
> + vgpreload_core-$(TARGET_ARCH)-linux \
> + vgpreload_memcheck-$(TARGET_ARCH)-linux \
> + default.supp
> +
> +include $(BUILD_EXECUTABLE)
> +
> +endif
> \ No newline at end of file
> diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c
> new file mode 100644
> index 0000000..122e6b0
> --- /dev/null
> +++ b/android/bluetoothd-wrapper.c
> @@ -0,0 +1,76 @@
> +/*
> + * Copyright (C) 2014 Intel Corporation
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and + *
> limitations under the License.
> + *
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +
> +#include <cutils/properties.h>
> +
> +#define PROPERTY_NAME "persist.sys.bluetooth.valgrind"
> +
> +#define VALGRIND_BIN "/system/bin/valgrind"
> +
> +#define BLUETOOTHD_BIN "/system/bin/bluetoothd-main"
> +
> +static void run_valgrind(void)
> +{
> + char *prg_argv[4];
> + char *prg_envp[3];
> +
> + prg_argv[0] = VALGRIND_BIN;
> + prg_argv[1] = "--leak-check=full";
> + prg_argv[2] = BLUETOOTHD_BIN;
> + prg_argv[3] = NULL;
> +
> + prg_envp[0] = "G_SLICE=always-malloc";
> + prg_envp[1] = "G_DEBUG=gc-friendly";
> + prg_envp[2] = NULL;
> +
> + execve(prg_argv[0], prg_argv, prg_envp);
> +}
> +
> +static void run_bluetoothd(void)
> +{
> + char *prg_argv[2];
> + char *prg_envp[1];
> +
> + prg_argv[0] = BLUETOOTHD_BIN;
> + prg_argv[1] = NULL;
> +
> + prg_envp[0] = NULL;
> +
> + execve(prg_argv[0], prg_argv, prg_envp);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + char value[PROPERTY_VALUE_MAX];
> +
> + if (property_get(PROPERTY_NAME, value, "") > 0 &&
> + (!strcasecmp(value, "true") || atoi(value) > 0))
> + run_valgrind();
> +
> + /* In case we failed to execute Valgrind, try to run bluetoothd
> + * without it
> + */
> +
> + run_bluetoothd();
> +
> + return 0;
> +}
Applied, thanks.
--
BR
Szymon Janc
^ permalink raw reply
* Re: [PATCH] android/README: Add Valgrind description
From: Szymon Janc @ 2014-02-11 16:34 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1392119033-23035-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Tuesday 11 of February 2014 12:43:53 Andrzej Kaczmarek wrote:
> ---
> android/README | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/android/README b/android/README
> index e3c314f..c7145d5 100644
> --- a/android/README
> +++ b/android/README
> @@ -108,6 +108,22 @@ be found at https://backports.wiki.kernel.org. Sample
> kernels using backports for running BlueZ on Android are available at
> https://code.google.com/p/aosp-bluez.
>
> +Running with Valgrind
> +=====================
> +
> +BlueZ for Android is preconfigured to be easily run under Valgrind
> memcheck. +Appropriate configuration and required modules are automatically
> included when +building either userdebug or eng variant of Android
> platform.
> +
> +Valgrind can be enabled in runtime by setting
> "persist.sys.bluetooth.valgrind" +property to either literal "true" or any
> numeric value >0. For example: +adb root
> +adb shell setprop persist.sys.bluetooth.valgrind true
> +
> +After changing property value Bluetooth need to be restarted to apply
> changes +(this can be done using UI, just disable and enable it again).
> Property is +persistent, i.e. there's no need to enable Valgrind again
> after reboot. +
> =============================
> Building and running on Linux
> =============================
Pushed, thanks.
--
BR
Szymon Janc
^ permalink raw reply
* [PATCH 1/6] shared: Add support for disonnect handler to GLib based IO handling
From: Szymon Janc @ 2014-02-11 16:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
---
src/shared/io-glib.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index 77ba19e..a4f982d 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
@@ -40,6 +40,10 @@ struct io {
io_callback_func_t write_callback;
io_destroy_func_t write_destroy;
void *write_data;
+ guint disconnect_watch;
+ io_callback_func_t disconnect_callback;
+ io_destroy_func_t disconnect_destroy;
+ void *disconnect_data;
};
static struct io *io_ref(struct io *io)
@@ -258,8 +262,61 @@ done:
return true;
}
+static void disconnect_watch_destroy(gpointer user_data)
+{
+ struct io *io = user_data;
+
+ if (io->disconnect_destroy)
+ io->disconnect_destroy(io->disconnect_data);
+
+ io->disconnect_watch = 0;
+ io->disconnect_callback = NULL;
+ io->disconnect_destroy = NULL;
+ io->disconnect_data = NULL;
+
+ io_unref(io);
+}
+
+static gboolean disconnect_callback(GIOChannel *channel, GIOCondition cond,
+ gpointer user_data)
+{
+ struct io *io = user_data;
+ bool result;
+
+ if (io->disconnect_callback)
+ result = io->disconnect_callback(io, io->disconnect_data);
+ else
+ result = false;
+
+ return result ? TRUE : FALSE;
+}
+
bool io_set_disconnect_handler(struct io *io, io_callback_func_t callback,
void *user_data, io_destroy_func_t destroy)
{
- return false;
+ if (!io)
+ return false;
+
+ if (io->disconnect_watch > 0) {
+ g_source_remove(io->disconnect_watch);
+ io->disconnect_watch = 0;
+ }
+
+ if (!callback)
+ goto done;
+
+ io->disconnect_watch = g_io_add_watch_full(io->channel,
+ G_PRIORITY_DEFAULT,
+ G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ disconnect_callback, io_ref(io),
+ disconnect_watch_destroy);
+ if (io->disconnect_watch == 0)
+ return false;
+
+ io->disconnect_destroy = destroy;
+ io->disconnect_data = user_data;
+done:
+ io->disconnect_callback = callback;
+
+ return true;
}
--
1.8.5.3
^ permalink raw reply related
* [PATCH 2/6] shared: Add support for disonnect handler to mainloop based IO handling
From: Szymon Janc @ 2014-02-11 16:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1392137346-26272-1-git-send-email-szymon.janc@tieto.com>
---
src/shared/io-mainloop.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 47 insertions(+), 1 deletion(-)
diff --git a/src/shared/io-mainloop.c b/src/shared/io-mainloop.c
index 981ab17..14ab128 100644
--- a/src/shared/io-mainloop.c
+++ b/src/shared/io-mainloop.c
@@ -42,6 +42,9 @@ struct io {
io_callback_func_t write_callback;
io_destroy_func_t write_destroy;
void *write_data;
+ io_callback_func_t disconnect_callback;
+ io_destroy_func_t disconnect_destroy;
+ void *disconnect_data;
};
static struct io *io_ref(struct io *io)
@@ -75,6 +78,9 @@ static void io_cleanup(void *user_data)
if (io->read_destroy)
io->read_destroy(io->read_data);
+ if (io->disconnect_destroy)
+ io->disconnect_destroy(io->disconnect_data);
+
if (io->close_on_destroy)
close(io->fd);
@@ -122,6 +128,21 @@ static void io_callback(int fd, uint32_t events, void *user_data)
mainloop_modify_fd(io->fd, io->events);
}
}
+
+ if ((events & EPOLLRDHUP) && io->disconnect_callback) {
+ if (!io->disconnect_callback(io, io->disconnect_data)) {
+ if (io->disconnect_destroy)
+ io->disconnect_destroy(io->disconnect_data);
+
+ io->disconnect_callback = NULL;
+ io->disconnect_destroy = NULL;
+ io->disconnect_data = NULL;
+
+ io->events &= ~EPOLLRDHUP;
+
+ mainloop_modify_fd(io->fd, io->events);
+ }
+ }
}
struct io *io_new(int fd)
@@ -246,5 +267,30 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
bool io_set_disconnect_handler(struct io *io, io_callback_func_t callback,
void *user_data, io_destroy_func_t destroy)
{
- return false;
+ uint32_t events;
+
+ if (!io || io->fd < 0)
+ return false;
+
+ if (io->disconnect_destroy)
+ io->disconnect_destroy(io->disconnect_data);
+
+ if (callback)
+ events = io->events | EPOLLRDHUP;
+ else
+ events = io->events & ~EPOLLRDHUP;
+
+ io->disconnect_callback = callback;
+ io->disconnect_destroy = destroy;
+ io->disconnect_data = user_data;
+
+ if (events == io->events)
+ return true;
+
+ if (mainloop_modify_fd(io->fd, events) < 0)
+ return false;
+
+ io->events = events;
+
+ return true;
}
--
1.8.5.3
^ permalink raw reply related
* [PATCH 3/6] shared: Add support for disconnect handler in HFP
From: Szymon Janc @ 2014-02-11 16:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1392137346-26272-1-git-send-email-szymon.janc@tieto.com>
It is no longer possible to send any data after disconnection.
Extra reference is taken for disconnect watch to allow users to drop
own reference in disconnect callback.
---
src/shared/hfp.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
src/shared/hfp.h | 6 ++++++
2 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 43e88a6..3944e97 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -51,6 +51,9 @@ struct hfp_gw {
hfp_debug_func_t debug_callback;
hfp_destroy_func_t debug_destroy;
void *debug_data;
+ hfp_disconnect_func_t disconnect_callback;
+ hfp_destroy_func_t disconnect_destroy;
+ void *disconnect_data;
};
static void write_watch_destroy(void *user_data)
@@ -227,6 +230,7 @@ void hfp_gw_unref(struct hfp_gw *hfp)
io_set_write_handler(hfp->io, NULL, NULL, NULL);
io_set_read_handler(hfp->io, NULL, NULL, NULL);
+ io_set_disconnect_handler(hfp->io, NULL, NULL, NULL);
io_destroy(hfp->io);
hfp->io = NULL;
@@ -307,7 +311,7 @@ bool hfp_gw_send_result(struct hfp_gw *hfp, enum hfp_result result)
{
const char *str;
- if (!hfp)
+ if (!hfp || !hfp->io)
return false;
switch (result) {
@@ -333,7 +337,7 @@ bool hfp_gw_send_result(struct hfp_gw *hfp, enum hfp_result result)
bool hfp_gw_send_error(struct hfp_gw *hfp, enum hfp_error error)
{
- if (!hfp)
+ if (!hfp || !hfp->io)
return false;
if (ringbuf_printf(hfp->write_buf, "\r\n+CME ERROR: %u\r\n", error) < 0)
@@ -352,7 +356,7 @@ bool hfp_gw_send_info(struct hfp_gw *hfp, const char *format, ...)
char *fmt;
int len;
- if (!hfp || !format)
+ if (!hfp || !hfp->io || !format)
return false;
if (asprintf(&fmt, "\r\n%s\r\n", format) < 0)
@@ -391,3 +395,53 @@ bool hfp_gw_set_command_handler(struct hfp_gw *hfp,
return true;
}
+
+static void disconnect_watch_destroy(void *user_data)
+{
+ struct hfp_gw *hfp = user_data;
+
+ if (hfp->disconnect_destroy)
+ hfp->disconnect_destroy(hfp->disconnect_data);
+
+ hfp_gw_unref(hfp);
+}
+
+static bool io_disconnected(struct io *io, void *user_data)
+{
+ struct hfp_gw *hfp = user_data;
+
+ io_destroy(hfp->io);
+ hfp->io = NULL;
+
+ if (hfp->disconnect_callback)
+ hfp->disconnect_callback(hfp->disconnect_data);
+
+ return false;
+}
+
+bool hfp_gw_set_disconnect_handler(struct hfp_gw *hfp,
+ hfp_disconnect_func_t callback,
+ void *user_data,
+ hfp_destroy_func_t destroy)
+{
+ if (!hfp)
+ return false;
+
+ if (hfp->disconnect_destroy)
+ hfp->disconnect_destroy(hfp->disconnect_data);
+
+ if (!io_set_disconnect_handler(hfp->io, io_disconnected,
+ hfp_gw_ref(hfp),
+ disconnect_watch_destroy)) {
+ hfp->disconnect_callback = NULL;
+ hfp->disconnect_destroy = NULL;
+ hfp->disconnect_data = NULL;
+ return false;
+ }
+
+ hfp->disconnect_callback = callback;
+ hfp->disconnect_destroy = destroy;
+ hfp->disconnect_data = user_data;
+
+ return true;
+}
diff --git a/src/shared/hfp.h b/src/shared/hfp.h
index 2eca6d8..75ec484 100644
--- a/src/shared/hfp.h
+++ b/src/shared/hfp.h
@@ -64,6 +64,7 @@ typedef void (*hfp_destroy_func_t)(void *user_data);
typedef void (*hfp_debug_func_t)(const char *str, void *user_data);
typedef void (*hfp_command_func_t)(const char *command, void *user_data);
+typedef void (*hfp_disconnect_func_t)(void *user_data);
struct hfp_gw;
@@ -86,3 +87,8 @@ bool hfp_gw_send_info(struct hfp_gw *hfp, const char *format, ...)
bool hfp_gw_set_command_handler(struct hfp_gw *hfp,
hfp_command_func_t callback,
void *user_data, hfp_destroy_func_t destroy);
+
+bool hfp_gw_set_disconnect_handler(struct hfp_gw *hfp,
+ hfp_disconnect_func_t callback,
+ void *user_data,
+ hfp_destroy_func_t destroy);
--
1.8.5.3
^ permalink raw reply related
* [PATCH 4/6] shared: Add support for shutdown to IO
From: Szymon Janc @ 2014-02-11 16:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1392137346-26272-1-git-send-email-szymon.janc@tieto.com>
This allows to locally shutdown IO.
---
src/shared/io-glib.c | 9 +++++++++
src/shared/io-mainloop.c | 9 +++++++++
src/shared/io.h | 2 ++
3 files changed, 20 insertions(+)
diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index a4f982d..8290745 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
@@ -320,3 +320,12 @@ done:
return true;
}
+
+bool io_shutdown(struct io *io)
+{
+ if (!io || !io->channel)
+ return false;
+
+ return g_io_channel_shutdown(io->channel, TRUE, NULL)
+ == G_IO_STATUS_NORMAL;
+}
diff --git a/src/shared/io-mainloop.c b/src/shared/io-mainloop.c
index 14ab128..f1e3b3b 100644
--- a/src/shared/io-mainloop.c
+++ b/src/shared/io-mainloop.c
@@ -26,6 +26,7 @@
#endif
#include <unistd.h>
+#include <sys/socket.h>
#include "monitor/mainloop.h"
#include "src/shared/util.h"
@@ -294,3 +295,11 @@ bool io_set_disconnect_handler(struct io *io, io_callback_func_t callback,
return true;
}
+
+bool io_shutdown(struct io *io)
+{
+ if (!io || io->fd < 0)
+ return false;
+
+ return shutdown(io->fd, SHUT_RDWR) == 0;
+}
diff --git a/src/shared/io.h b/src/shared/io.h
index 2c47e39..2106240 100644
--- a/src/shared/io.h
+++ b/src/shared/io.h
@@ -33,6 +33,8 @@ void io_destroy(struct io *io);
int io_get_fd(struct io *io);
bool io_set_close_on_destroy(struct io *io, bool do_close);
+bool io_shutdown(struct io *io);
+
typedef bool (*io_callback_func_t)(struct io *io, void *user_data);
bool io_set_read_handler(struct io *io, io_callback_func_t callback,
--
1.8.5.3
^ permalink raw reply related
* [PATCH 5/6] shared: Add support for local disconnect to HFP
From: Szymon Janc @ 2014-02-11 16:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1392137346-26272-1-git-send-email-szymon.janc@tieto.com>
This allows to locally trigger disconnection.
---
src/shared/hfp.c | 8 ++++++++
src/shared/hfp.h | 2 ++
2 files changed, 10 insertions(+)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 3944e97..2c793f9 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -445,3 +445,11 @@ bool hfp_gw_set_disconnect_handler(struct hfp_gw *hfp,
return true;
}
+
+bool hfp_gw_disconnect(struct hfp_gw *hfp)
+{
+ if (!hfp)
+ return false;
+
+ return io_shutdown(hfp->io);
+}
diff --git a/src/shared/hfp.h b/src/shared/hfp.h
index 75ec484..5a86dfe 100644
--- a/src/shared/hfp.h
+++ b/src/shared/hfp.h
@@ -92,3 +92,5 @@ bool hfp_gw_set_disconnect_handler(struct hfp_gw *hfp,
hfp_disconnect_func_t callback,
void *user_data,
hfp_destroy_func_t destroy);
+
+bool hfp_gw_disconnect(struct hfp_gw *hfp);
--
1.8.5.3
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox