Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 3/3] android/avrcp-lib: Add avrcp_set_passthrough_handlers
From: Luiz Augusto von Dentz @ 2014-02-20 14:40 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1392907255-29758-1-git-send-email-luiz.dentz@gmail.com>

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

This adds avrcp_set_passthrough_handlers which can be used to set
pass-through PDU handlers table and user data.
---
 android/avrcp-lib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 android/avrcp-lib.h |  8 ++++++++
 2 files changed, 52 insertions(+)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index c508516..d46e3d3 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -98,6 +98,10 @@ struct avrcp {
 	const struct avrcp_control_handler *control_handlers;
 	void *control_data;
 	unsigned int control_id;
+
+	const struct avrcp_passthrough_handler *passthrough_handlers;
+	void *passthrough_data;
+	unsigned int passthrough_id;
 };
 
 void avrcp_shutdown(struct avrcp *session)
@@ -106,6 +110,9 @@ void avrcp_shutdown(struct avrcp *session)
 		if (session->control_id > 0)
 			avctp_unregister_pdu_handler(session->conn,
 							session->control_id);
+		if (session->passthrough_id > 0)
+			avctp_unregister_passthrough_handler(session->conn,
+						session->passthrough_id);
 		avctp_shutdown(session->conn);
 	}
 
@@ -168,6 +175,31 @@ reject:
 	return AVRCP_HEADER_LENGTH + 1;
 }
 
+static bool handle_passthrough_pdu(struct avctp *conn, uint8_t op,
+						bool pressed, void *user_data)
+{
+	struct avrcp *session = user_data;
+	const struct avrcp_passthrough_handler *handler;
+
+	if (!session->passthrough_handlers)
+		return false;
+
+	for (handler = session->passthrough_handlers; handler->func;
+								handler++) {
+		if (handler->op == op)
+			break;
+	}
+
+	if (handler->func == NULL)
+		return false;
+
+	/* Do not trigger handler on release */
+	if (!pressed)
+		return true;
+
+	return handler->func(session);
+}
+
 struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version)
 {
 	struct avrcp *session;
@@ -180,6 +212,10 @@ struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version)
 		return NULL;
 	}
 
+	session->passthrough_id = avctp_register_passthrough_handler(
+							session->conn,
+							handle_passthrough_pdu,
+							session);
 	session->control_id = avctp_register_pdu_handler(session->conn,
 							AVC_OP_VENDORDEP,
 							handle_vendordep_pdu,
@@ -202,6 +238,14 @@ void avrcp_set_control_handlers(struct avrcp *session,
 	session->control_data = user_data;
 }
 
+void avrcp_set_passthrough_handlers(struct avrcp *session,
+			const struct avrcp_passthrough_handler *handlers,
+			void *user_data)
+{
+	session->passthrough_handlers = handlers;
+	session->passthrough_data = user_data;
+}
+
 int avrcp_init_uinput(struct avrcp *session, const char *name,
 							const char *address)
 {
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 1a135cc..2337429 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -55,6 +55,11 @@ struct avrcp_control_handler {
 			uint16_t *params_len, uint8_t *params, void *user_data);
 };
 
+struct avrcp_passthrough_handler {
+	uint8_t op;
+	bool (*func) (struct avrcp *session);
+};
+
 typedef void (*avrcp_destroy_cb_t) (void *user_data);
 
 struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version);
@@ -64,5 +69,8 @@ void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
 void avrcp_set_control_handlers(struct avrcp *session,
 				const struct avrcp_control_handler *handlers,
 				void *user_data);
+void avrcp_set_passthrough_handlers(struct avrcp *session,
+			const struct avrcp_passthrough_handler *handlers,
+			void *user_data);
 int avrcp_init_uinput(struct avrcp *session, const char *name,
 							const char *address);
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH v3] Bluetooth: Fix channel check when binding RFCOMM sock
From: Andrzej Kaczmarek @ 2014-02-20 15:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek

When binding RFCOMM socket with non-zero channel we're checking if
there is already any other socket which has the same channel number
assigned and then fail. This check does not consider situation where
we have another socket connected to remote device on given channel
number in which case we still should be able to bind local socket.

This patch changes __rfcomm_get_sock_by_addr() to return only sockets
in either BT_BOUND or BT_LISTEN states, also name is updated to better
describe what this function does now.

Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
---
 net/bluetooth/rfcomm/sock.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 00573fb..c024e71 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -105,13 +105,18 @@ static void rfcomm_sk_state_change(struct rfcomm_dlc *d, int err)
 }
 
 /* ---- Socket functions ---- */
-static struct sock *__rfcomm_get_sock_by_addr(u8 channel, bdaddr_t *src)
+static struct sock *__rfcomm_get_listen_sock_by_addr(u8 channel, bdaddr_t *src)
 {
 	struct sock *sk = NULL;
 
 	sk_for_each(sk, &rfcomm_sk_list.head) {
-		if (rfcomm_pi(sk)->channel == channel &&
-				!bacmp(&rfcomm_pi(sk)->src, src))
+		if (rfcomm_pi(sk)->channel != channel)
+			continue;
+
+		if (bacmp(&rfcomm_pi(sk)->src, src))
+			continue;
+
+		if (sk->sk_state == BT_BOUND || sk->sk_state == BT_LISTEN)
 			break;
 	}
 
@@ -331,6 +336,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;
+	int chan = sa->rc_channel;
 	int err = 0;
 
 	BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr);
@@ -352,12 +358,12 @@ 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)) {
+	if (chan && __rfcomm_get_listen_sock_by_addr(chan, &sa->rc_bdaddr)) {
 		err = -EADDRINUSE;
 	} else {
 		/* Save source address */
 		bacpy(&rfcomm_pi(sk)->src, &sa->rc_bdaddr);
-		rfcomm_pi(sk)->channel = sa->rc_channel;
+		rfcomm_pi(sk)->channel = chan;
 		sk->sk_state = BT_BOUND;
 	}
 
@@ -439,7 +445,7 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
 		write_lock(&rfcomm_sk_list.lock);
 
 		for (channel = 1; channel < 31; channel++)
-			if (!__rfcomm_get_sock_by_addr(channel, src)) {
+			if (!__rfcomm_get_listen_sock_by_addr(channel, src)) {
 				rfcomm_pi(sk)->channel = channel;
 				err = 0;
 				break;
-- 
1.8.5.4


^ permalink raw reply related

* Re: [PATCH v3] Bluetooth: Fix channel check when binding RFCOMM sock
From: Marcel Holtmann @ 2014-02-20 19:37 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: bluez mailin list (linux-bluetooth@vger.kernel.org)
In-Reply-To: <1392910921-19348-1-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

> When binding RFCOMM socket with non-zero channel we're checking if
> there is already any other socket which has the same channel number
> assigned and then fail. This check does not consider situation where
> we have another socket connected to remote device on given channel
> number in which case we still should be able to bind local socket.
> 
> This patch changes __rfcomm_get_sock_by_addr() to return only sockets
> in either BT_BOUND or BT_LISTEN states, also name is updated to better
> describe what this function does now.
> 
> Signed-off-by: Andrzej Kaczmarek <andrzej.kaczmarek@tieto.com>
> ---
> net/bluetooth/rfcomm/sock.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply

* [PATCH] Bluetooth: Provide option for changing LE advertising channel map
From: Marcel Holtmann @ 2014-02-20 19:55 UTC (permalink / raw)
  To: linux-bluetooth

For testing purposes it is useful to provide an option to change the
advertising channel map. So add a debugfs option to allow this.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_core.c         | 31 +++++++++++++++++++++++++++++++
 net/bluetooth/mgmt.c             |  2 +-
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 3a8e22e9b25d..c0fcc041fbb5 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -178,6 +178,7 @@ struct hci_dev {
 	__u16		page_scan_interval;
 	__u16		page_scan_window;
 	__u8		page_scan_type;
+	__u8		le_adv_channel_map;
 	__u16		le_scan_interval;
 	__u16		le_scan_window;
 	__u16		le_conn_min_interval;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 877330b4876f..67192867c998 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -757,6 +757,34 @@ static int conn_max_interval_get(void *data, u64 *val)
 DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get,
 			conn_max_interval_set, "%llu\n");
 
+static int adv_channel_map_set(void *data, u64 val)
+{
+	struct hci_dev *hdev = data;
+
+	if (val < 0x01 || val > 0x07)
+		return -EINVAL;
+
+	hci_dev_lock(hdev);
+	hdev->le_adv_channel_map = val;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+static int adv_channel_map_get(void *data, u64 *val)
+{
+	struct hci_dev *hdev = data;
+
+	hci_dev_lock(hdev);
+	*val = hdev->le_adv_channel_map;
+	hci_dev_unlock(hdev);
+
+	return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get,
+			adv_channel_map_set, "%llu\n");
+
 static ssize_t lowpan_read(struct file *file, char __user *user_buf,
 			   size_t count, loff_t *ppos)
 {
@@ -1605,6 +1633,8 @@ static int __hci_init(struct hci_dev *hdev)
 				    hdev, &conn_min_interval_fops);
 		debugfs_create_file("conn_max_interval", 0644, hdev->debugfs,
 				    hdev, &conn_max_interval_fops);
+		debugfs_create_file("adv_channel_map", 0644, hdev->debugfs,
+				    hdev, &adv_channel_map_fops);
 		debugfs_create_file("6lowpan", 0644, hdev->debugfs, hdev,
 				    &lowpan_debugfs_fops);
 	}
@@ -3264,6 +3294,7 @@ struct hci_dev *hci_alloc_dev(void)
 	hdev->sniff_max_interval = 800;
 	hdev->sniff_min_interval = 80;
 
+	hdev->le_adv_channel_map = 0x07;
 	hdev->le_scan_interval = 0x0060;
 	hdev->le_scan_window = 0x0030;
 	hdev->le_conn_min_interval = 0x0028;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 5f5e388716ec..12fa6399c796 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1374,7 +1374,7 @@ static void enable_advertising(struct hci_request *req)
 	cp.max_interval = __constant_cpu_to_le16(0x0800);
 	cp.type = get_adv_type(hdev);
 	cp.own_address_type = hdev->own_addr_type;
-	cp.channel_map = 0x07;
+	cp.channel_map = hdev->le_adv_channel_map;
 
 	hci_req_add(req, HCI_OP_LE_SET_ADV_PARAM, sizeof(cp), &cp);
 
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH] Bluetooth: Increase minor version of core module
From: Marcel Holtmann @ 2014-02-20 20:44 UTC (permalink / raw)
  To: linux-bluetooth

With the addition of Resolvable Private Address (RPA) resolution
support for Bluetooth Low Energy connections, it makes sense to
increase the minor version of the Bluetooth core module.

The module version is not used anywhere, but it gives a nice extra
hint for debugging purposes.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 net/bluetooth/af_bluetooth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 0c5866bb49b6..2021c481cdb6 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -31,7 +31,7 @@
 #include <net/bluetooth/bluetooth.h>
 #include <linux/proc_fs.h>
 
-#define VERSION "2.18"
+#define VERSION "2.19"
 
 /* Bluetooth sockets */
 #define BT_MAX_PROTO	8
-- 
1.8.5.3


^ permalink raw reply related

* Re: [PATCH] Bluetooth: Provide option for changing LE advertising channel map
From: Johan Hedberg @ 2014-02-21  4:22 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1392926156-4599-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Thu, Feb 20, 2014, Marcel Holtmann wrote:
> For testing purposes it is useful to provide an option to change the
> advertising channel map. So add a debugfs option to allow this.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  include/net/bluetooth/hci_core.h |  1 +
>  net/bluetooth/hci_core.c         | 31 +++++++++++++++++++++++++++++++
>  net/bluetooth/mgmt.c             |  2 +-
>  3 files changed, 33 insertions(+), 1 deletion(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH] Bluetooth: Increase minor version of core module
From: Johan Hedberg @ 2014-02-21  4:23 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <1392929060-4999-1-git-send-email-marcel@holtmann.org>

Hi Marcel,

On Thu, Feb 20, 2014, Marcel Holtmann wrote:
> With the addition of Resolvable Private Address (RPA) resolution
> support for Bluetooth Low Energy connections, it makes sense to
> increase the minor version of the Bluetooth core module.
> 
> The module version is not used anywhere, but it gives a nice extra
> hint for debugging purposes.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  net/bluetooth/af_bluetooth.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied to bluetooth-next. Thanks.

Johan

^ permalink raw reply

* [PATCH] unit/avrcp: First unit test for AVRCP profile
From: Andrei Emeltchenko @ 2014-02-21  7:02 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

The tests verifies connection establishment for control.
---
 Makefile.am       |   9 ++
 unit/test-avrcp.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 274 insertions(+)
 create mode 100644 unit/test-avrcp.c

diff --git a/Makefile.am b/Makefile.am
index 11f2aa1..5fe58eb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -282,6 +282,15 @@ unit_test_avctp_SOURCES = unit/test-avctp.c \
 				android/avctp.c android/avctp.h
 unit_test_avctp_LDADD = @GLIB_LIBS@
 
+unit_tests += unit/test-avrcp
+
+unit_test_avrcp_SOURCES = unit/test-avrcp.c \
+				src/shared/util.h src/shared/util.c \
+				src/log.h src/log.c \
+				android/avctp.c android/avctp.h \
+				android/avrcp-lib.c android/avrcp-lib.h
+unit_test_avrcp_LDADD = @GLIB_LIBS@ lib/libbluetooth-internal.la
+
 unit_tests += unit/test-gdbus-client
 
 unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
new file mode 100644
index 0000000..336b741
--- /dev/null
+++ b/unit/test-avrcp.c
@@ -0,0 +1,265 @@
+/*
+ *
+ *  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 <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+
+#include <glib.h>
+
+#include "src/shared/util.h"
+#include "src/log.h"
+#include "lib/bluetooth.h"
+
+#include "android/avctp.h"
+#include "android/avrcp-lib.h"
+
+struct test_pdu {
+	bool valid;
+	bool fragmented;
+	const uint8_t *data;
+	size_t size;
+};
+
+struct test_data {
+	char *test_name;
+	struct test_pdu *pdu_list;
+};
+
+struct context {
+	GMainLoop *main_loop;
+	struct avrcp *session;
+	guint source;
+	guint process;
+	int fd;
+	unsigned int pdu_offset;
+	const struct test_data *data;
+};
+
+#define data(args...) ((const unsigned char[]) { args })
+
+#define raw_pdu(args...)					\
+	{							\
+		.valid = true,					\
+		.data = data(args),				\
+		.size = sizeof(data(args)),			\
+	}
+
+#define frg_pdu(args...)					\
+	{							\
+		.valid = true,					\
+		.fragmented = true,				\
+		.data = data(args),				\
+		.size = sizeof(data(args)),			\
+	}
+
+#define define_test(name, function, args...)				\
+	do {								\
+		const struct test_pdu pdus[] = {			\
+			args, { }					\
+		};							\
+		static struct test_data data;				\
+		data.test_name = g_strdup(name);			\
+		data.pdu_list = g_malloc(sizeof(pdus));			\
+		memcpy(data.pdu_list, pdus, sizeof(pdus));		\
+		g_test_add_data_func(name, &data, function);		\
+	} while (0)
+
+static void test_debug(const char *str, void *user_data)
+{
+	const char *prefix = user_data;
+
+	g_print("%s%s\n", prefix, str);
+}
+
+static void test_free(gconstpointer user_data)
+{
+	const struct test_data *data = user_data;
+
+	g_free(data->test_name);
+	g_free(data->pdu_list);
+}
+
+static gboolean context_quit(gpointer user_data)
+{
+	struct context *context = user_data;
+
+	if (context->process > 0)
+		g_source_remove(context->process);
+
+	g_main_loop_quit(context->main_loop);
+
+	return FALSE;
+}
+
+static gboolean send_pdu(gpointer user_data)
+{
+	struct context *context = user_data;
+	const struct test_pdu *pdu;
+	ssize_t len;
+
+	pdu = &context->data->pdu_list[context->pdu_offset++];
+
+	len = write(context->fd, pdu->data, pdu->size);
+
+	if (g_test_verbose())
+		util_hexdump('<', pdu->data, len, test_debug, "AVCTP: ");
+
+	g_assert_cmpint(len, ==, pdu->size);
+
+	if (pdu->fragmented)
+		return send_pdu(user_data);
+
+	context->process = 0;
+	return FALSE;
+}
+
+static void context_process(struct context *context)
+{
+	if (!context->data->pdu_list[context->pdu_offset].valid) {
+		context_quit(context);
+		return;
+	}
+
+	context->process = g_idle_add(send_pdu, context);
+}
+
+static gboolean test_handler(GIOChannel *channel, GIOCondition cond,
+							gpointer user_data)
+{
+	struct context *context = user_data;
+	const struct test_pdu *pdu;
+	unsigned char buf[512];
+	ssize_t len;
+	int fd;
+
+	pdu = &context->data->pdu_list[context->pdu_offset++];
+
+	if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+		context->source = 0;
+		g_print("%s: cond %x\n", __func__, cond);
+		return FALSE;
+	}
+
+	fd = g_io_channel_unix_get_fd(channel);
+
+	len = read(fd, buf, sizeof(buf));
+
+	g_assert(len > 0);
+
+	if (g_test_verbose())
+		util_hexdump('>', buf, len, test_debug, "AVCTP: ");
+
+	g_assert_cmpint(len, ==, pdu->size);
+
+	g_assert(memcmp(buf, pdu->data, pdu->size) == 0);
+
+	if (!pdu->fragmented)
+		context_process(context);
+
+	return TRUE;
+}
+
+static struct context *create_context(uint16_t version, gconstpointer data)
+{
+	struct context *context = g_new0(struct context, 1);
+	GIOChannel *channel;
+	int err, sv[2];
+
+	context->main_loop = g_main_loop_new(NULL, FALSE);
+	g_assert(context->main_loop);
+
+	err = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv);
+	g_assert(err == 0);
+
+	context->session = avrcp_new(sv[0], 672, 672, version);
+	g_assert(context->session != NULL);
+
+	channel = g_io_channel_unix_new(sv[1]);
+
+	g_io_channel_set_close_on_unref(channel, TRUE);
+	g_io_channel_set_encoding(channel, NULL, NULL);
+	g_io_channel_set_buffered(channel, FALSE);
+
+	context->source = g_io_add_watch(channel,
+				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+				test_handler, context);
+	g_assert(context->source > 0);
+
+	g_io_channel_unref(channel);
+
+	context->fd = sv[1];
+	context->data = data;
+
+	return context;
+}
+
+static void destroy_context(struct context *context)
+{
+	if (context->source > 0)
+		g_source_remove(context->source);
+
+	avrcp_shutdown(context->session);
+
+	g_main_loop_unref(context->main_loop);
+
+	test_free(context->data);
+	g_free(context);
+}
+
+static void test_dummy(gconstpointer data)
+{
+	struct context *context =  create_context(0x0100, data);
+
+	destroy_context(context);
+}
+
+int main(int argc, char *argv[])
+{
+	g_test_init(&argc, &argv, NULL);
+
+	if (g_test_verbose())
+		__btd_log_init("*", 0);
+
+	/* Connection Establishment for Control tests */
+
+	/*
+	 * Tests are checking connection establishement and release
+	 * for control channel. Since we are connected through socketpair
+	 * the tests are dummy
+	 */
+	define_test("/TP/CEC/BV-01-I", test_dummy, raw_pdu(0x00));
+	define_test("/TP/CEC/BV-02-I", test_dummy, raw_pdu(0x00));
+	define_test("/TP/CRC/BV-01-I", test_dummy, raw_pdu(0x00));
+	define_test("/TP/CRC/BV-02-I", test_dummy, raw_pdu(0x00));
+
+	return g_test_run();
+}
-- 
1.8.3.2


^ permalink raw reply related

* Re: [PATCH] android/pixit: correct PIXIT value
From: Szymon Janc @ 2014-02-21 10:44 UTC (permalink / raw)
  To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1392818658-18623-1-git-send-email-sebastian.chlad@tieto.com>

Hi Sebastian,

On Wednesday 19 of February 2014 15:04:18 Sebastian Chlad wrote:
> It is important for NAP role to set proper PTS btaddr in PIXIT
> ---
>  android/pixit-pan.txt | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/android/pixit-pan.txt b/android/pixit-pan.txt
> index 6544a9c..21434fb 100644
> --- a/android/pixit-pan.txt
> +++ b/android/pixit-pan.txt
> @@ -3,7 +3,7 @@ PAN PIXIT for the PTS tool.
>  PTS version: 5.0
>  
>  * - different than PTS defaults
> -& - should be set to IUT Bluetooth address
> +& - should be set to IUT or PTS Bluetooth address respectively
>  
>  		Required PIXIT settings
>  -------------------------------------------------------------------------------
> @@ -22,7 +22,7 @@ TSPX_iut_ip_address					192.168.167.152
>  TSPX_iut_port_number					4242
>  TSPX_PTS_ip_address					192.168.168.100
>  TSPX_PTS_port_number					4242
> -TSPX_bd_addr_PTS					000000000000
> +TSPX_bd_addr_PTS					112233445566 (*&)
>  TSPX_checksum						E851
>  TSPX_secure_simple_pairing_pass_key_confirmation	False
>  TSPX_iut_friendly_bt_name				gprs-pc
> 

Pushed, thanks.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply

* Re: [PATCH] android/pts: PTS test results for PAN
From: Szymon Janc @ 2014-02-21 10:44 UTC (permalink / raw)
  To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1392819038-19608-1-git-send-email-sebastian.chlad@tieto.com>

Hi Sebastian,

On Wednesday 19 of February 2014 15:10:38 Sebastian Chlad wrote:
> This adds initial PTS test results for PAN profile.
> ---
>  android/pts-pan.txt | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 70 insertions(+)
>  create mode 100644 android/pts-pan.txt
> 
> diff --git a/android/pts-pan.txt b/android/pts-pan.txt
> new file mode 100644
> index 0000000..8e8ae41
> --- /dev/null
> +++ b/android/pts-pan.txt
> @@ -0,0 +1,70 @@
> +PTS test results for PAN
> +
> +PTS version: 5.0
> +Tested: 19.02.2014
> +Android version: 4.4.2
> +
> +Results:
> +PASS	test passed
> +FAIL	test failed
> +INC	test is inconclusive
> +N/A	test is disabled due to PICS setup
> +
> +-------------------------------------------------------------------------------
> +Test Name				Result	Notes
> +-------------------------------------------------------------------------------
> +TC_BNEP_GN_BROADCAST_0_BV_03_C		N/A
> +TC_GN_Ipv4_Autonet_BV_01_I		N/A
> +TC_GN_Ipv6_Autonet_BV_02_I		N/A
> +TC_GN_IP_DHCP_BV_03_I			N/A
> +TC_GN_IP_LLMNR_BV_01_I			N/A
> +TC_GN_IP_LLMNR_BV_02_I			N/A
> +TC_GN_IP_DNS_BV_01_I			N/A
> +TC_GN_IP_APP_BV_01_I			N/A
> +TC_GN_IP_APP_BV_02_I			N/A
> +TC_GN_IP_APP_BV_03_I			N/A
> +TC_GN_IP_APP_BV_04_I			N/A
> +TC_GN_IP_APP_BV_05_I			N/A
> +TC_SDP_GN_BV_02_C			N/A
> +TC_MISC_GN_UUID_BV_01_C			N/A
> +TC_MISC_GN_UUID_BV_02_C			N/A
> +TC_BNEP_NAP_BROADCAST_0_BV_01_C		N/A
> +TC_BNEP_NAP_BROADCAST_0_BV_02_C		N/A
> +TC_BNEP_NAP_FORWARD_UNICAST_BV_05_C	N/A
> +TC_BNEP_NAP_FORWARD_UNICAST_BV_06_C	N/A
> +TC_BNEP_NAP_MULTICAST_0_BV_03_C		N/A
> +TC_BNEP_NAP_MULTICAST_0_BV_04_C		N/A
> +TC_BNEP_BRIDGE_RX_BV_02_I		INC
> +TC_BNEP_BRIDGE_TX_BV_01_I		PASS
> +TC_NAP_Ipv4_Autonet_BV_01_I		N/A
> +TC_NAP_Ipv6_Autonet_BV_02_I		N/A
> +TC_NAP_IP_DHCP_BV_03_I			N/A
> +TC_NAP_IP_LLMNR_BV_01_I			INC
> +TC_NAP_IP_LLMNR_BV_02_I			N/A
> +TC_NAP_IP_DNS_BV_01_I			N/A
> +TC_NAP_IP_APP_BV_01_I			N/A
> +TC_NAP_IP_APP_BV_02_I			N/A
> +TC_NAP_IP_APP_BV_03_I			N/A
> +TC_NAP_IP_APP_BV_04_I			N/A
> +TC_NAP_IP_APP_BV_05_I			PASS
> +TC_SDP_NAP_BV_01_C			PASS
> +TC_MISC_NAP_UUID_BV_01_C		PASS
> +TC_MISC_NAP_UUID_BV_02_C		PASS
> +TC_BNEP_PANU_BROADCAST_0_BV_04_C	N/A
> +TC_PANU_Ipv4_Autonet_BV_01_I		INC
> +TC_PANU_Ipv6_Autonet_BV_02_I		N/A
> +TC_PANU_IP_LLMNR_BV_01_I		INC
> +TC_PANU_IP_LLMNR_BV_02_I		N/A
> +TC_PANU_IP_DHCP_BV_03_I			PASS
> +TC_PANU_IP_DNS_BV_01_I			N/A
> +TC_PANU_IP_APP_BV_01_I			N/A
> +TC_PANU_IP_APP_BV_02_I			N/A
> +TC_PANU_IP_APP_BV_03_I			INC
> +TC_PANU_IP_APP_BV_04_I			INC
> +TC_PANU_IP_APP_BV_05_I			PASS
> +TC_SDP_PANU_BV_01_C			N/A
> +TC_MISC_PANU_UUID_BV_01_C		N/A
> +TC_MISC_PANU_UUID_BV_02_C		N/A
> +TC_MISC_ROLE_BV_01_C			N/A
> +TC_MISC_ROLE_BV_BV_02_C			N/A
> +-------------------------------------------------------------------------------
> 

Pushed, thanks.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply

* Re: [PATCH 1/2] android/hal-bluetooth: Use fixed size buffers for commands
From: Szymon Janc @ 2014-02-21 10:44 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1392842978-29373-1-git-send-email-szymon.janc@gmail.com>

On Wednesday 19 of February 2014 21:49:37 Szymon Janc wrote:
> This make code follow same conventions for all commands.
> ---
>  android/hal-bluetooth.c | 44 +++++++++++++++++++++++++++-----------------
>  1 file changed, 27 insertions(+), 17 deletions(-)
> 
> diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> index 65432a8..a01229a 100644
> --- a/android/hal-bluetooth.c
> +++ b/android/hal-bluetooth.c
> @@ -525,8 +525,9 @@ static int get_adapter_property(bt_property_type_t type)
>  
>  static int set_adapter_property(const bt_property_t *property)
>  {
> -	char buf[sizeof(struct hal_cmd_set_adapter_prop) + property->len];
> +	char buf[BLUEZ_HAL_MTU];
>  	struct hal_cmd_set_adapter_prop *cmd = (void *) buf;
> +	size_t len;
>  
>  	DBG("prop: %s", btproperty2str(property));
>  
> @@ -535,8 +536,10 @@ static int set_adapter_property(const bt_property_t *property)
>  
>  	adapter_prop_from_hal(property, &cmd->type, &cmd->len, cmd->val);
>  
> +	len = sizeof(*cmd) + cmd->len;
> +
>  	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP,
> -				sizeof(*cmd) + cmd->len, cmd, 0, NULL, NULL);
> +						len, cmd, 0, NULL, NULL);
>  }
>  
>  static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
> @@ -579,8 +582,9 @@ static int get_remote_device_property(bt_bdaddr_t *remote_addr,
>  static int set_remote_device_property(bt_bdaddr_t *remote_addr,
>  						const bt_property_t *property)
>  {
> -	struct hal_cmd_set_remote_device_prop *cmd;
> -	uint8_t buf[sizeof(*cmd) + property->len];
> +	char buf[BLUEZ_HAL_MTU];
> +	struct hal_cmd_set_remote_device_prop *cmd = (void *) buf;
> +	size_t len;
>  
>  	DBG("bdaddr: %s prop: %s", bdaddr2str(remote_addr),
>  				bt_property_type_t2str(property->type));
> @@ -588,8 +592,6 @@ static int set_remote_device_property(bt_bdaddr_t *remote_addr,
>  	if (!interface_ready())
>  		return BT_STATUS_NOT_READY;
>  
> -	cmd = (void *) buf;
> -
>  	memcpy(cmd->bdaddr, remote_addr, sizeof(cmd->bdaddr));
>  
>  	/* type match IPC type */
> @@ -597,9 +599,11 @@ static int set_remote_device_property(bt_bdaddr_t *remote_addr,
>  	cmd->len = property->len;
>  	memcpy(cmd->val, property->val, property->len);
>  
> +	len = sizeof(*cmd) + cmd->len;
> +
>  	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH,
>  					HAL_OP_SET_REMOTE_DEVICE_PROP,
> -					sizeof(buf), cmd, 0, NULL, NULL);
> +					len, cmd, 0, NULL, NULL);
>  }
>  
>  static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
> @@ -786,40 +790,46 @@ static int dut_mode_configure(uint8_t enable)
>  					sizeof(cmd), &cmd, 0, NULL, NULL);
>  }
>  
> -static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t len)
> +static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
>  {
> -	uint8_t cmd_buf[sizeof(struct hal_cmd_dut_mode_send) + len];
> +	char cmd_buf[BLUEZ_HAL_MTU];
>  	struct hal_cmd_dut_mode_send *cmd = (void *) cmd_buf;
> +	size_t len;
>  
> -	DBG("opcode %u len %u", opcode, len);
> +	DBG("opcode %u len %u", opcode, buf_len);
>  
>  	if (!interface_ready())
>  		return BT_STATUS_NOT_READY;
>  
>  	cmd->opcode = opcode;
> -	cmd->len = len;
> +	cmd->len = buf_len;
>  	memcpy(cmd->data, buf, cmd->len);
>  
> +	len = sizeof(*cmd) + cmd->len;
> +
>  	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_DUT_MODE_SEND,
> -					sizeof(cmd_buf), cmd, 0, NULL, NULL);
> +						len, cmd, 0, NULL, NULL);
>  }
>  
> -static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
> +static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
>  {
> -	uint8_t cmd_buf[sizeof(struct hal_cmd_le_test_mode) + len];
> +	char cmd_buf[BLUEZ_HAL_MTU];
>  	struct hal_cmd_le_test_mode *cmd = (void *) cmd_buf;
> +	size_t len;
>  
> -	DBG("opcode %u len %u", opcode, len);
> +	DBG("opcode %u len %u", opcode, buf_len);
>  
>  	if (!interface_ready())
>  		return BT_STATUS_NOT_READY;
>  
>  	cmd->opcode = opcode;
> -	cmd->len = len;
> +	cmd->len = buf_len;
>  	memcpy(cmd->data, buf, cmd->len);
>  
> +	len = sizeof(*cmd) + cmd->len;
> +
>  	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_LE_TEST_MODE,
> -					sizeof(cmd_buf), cmd, 0, NULL, NULL);
> +						len, cmd, 0, NULL, NULL);
>  }
>  
>  static int config_hci_snoop_log(uint8_t enable)
> 

Both patches are now upstream.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply

* Re: [PATCH 1/2] android: Add resolve_name parameter to confirm_device_name
From: Szymon Janc @ 2014-02-21 11:02 UTC (permalink / raw)
  To: Lukasz Rymanowski; +Cc: linux-bluetooth
In-Reply-To: <1392654390-19913-1-git-send-email-lukasz.rymanowski@tieto.com>

Hi Łukasz,

On Monday 17 of February 2014 17:26:29 Lukasz Rymanowski wrote:
> ---
>  android/bluetooth.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 525fd27..1827834 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -1012,7 +1012,8 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length,
>  			HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp);
>  }
>  
> -static void confirm_device_name(const bdaddr_t *addr, uint8_t addr_type)
> +static void confirm_device_name(const bdaddr_t *addr, uint8_t addr_type,
> +							bool resolve_name)
>  {
>  	struct mgmt_cp_confirm_name cp;
>  
> @@ -1020,6 +1021,9 @@ static void confirm_device_name(const bdaddr_t *addr, uint8_t addr_type)
>  	bacpy(&cp.addr.bdaddr, addr);
>  	cp.addr.type = addr_type;
>  
> +	if (!resolve_name)
> +		cp.name_known = 1;
> +
>  	if (mgmt_reply(mgmt_if, MGMT_OP_CONFIRM_NAME, adapter.index,
>  				sizeof(cp), &cp, NULL, NULL, NULL) == 0)
>  		error("Failed to send confirm name request");
> @@ -1179,10 +1183,12 @@ static void update_found_device(const bdaddr_t *bdaddr, uint8_t bdaddr_type,
>  
>  	if (confirm) {
>  		char addr[18];
> +		bool resolve_name = true;
>  
>  		ba2str(bdaddr, addr);
> -		info("Device %s needs name confirmation.", addr);
> -		confirm_device_name(bdaddr, bdaddr_type);
> +		info("Device %s needs name confirmation (resolve_name=%d)",
> +							addr, resolve_name);
> +		confirm_device_name(bdaddr, bdaddr_type, resolve_name);
>  	}
>  }
>  

Both patches applied, thanks.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply

* [PATCH] android/avrcp: Use NULL for zero pointers
From: Andrei Emeltchenko @ 2014-02-21 11:27 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 android/avrcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/avrcp.c b/android/avrcp.c
index 8ac9e2f..acffd56 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -222,7 +222,7 @@ static sdp_record_t *avrcp_record(void)
 	features = sdp_data_alloc(SDP_UINT16, &feat);
 	sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
 
-	sdp_set_info_attr(record, "AVRCP TG", 0, 0);
+	sdp_set_info_attr(record, "AVRCP TG", NULL, NULL);
 
 	sdp_data_free(psm);
 	sdp_data_free(version);
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH 1/2] android/tester: Fix tester setup result set
From: Grzegorz Kolodziejczyk @ 2014-02-21 11:33 UTC (permalink / raw)
  To: linux-bluetooth

Tester setup result is set to pass after set to fail because of missing
function return. This adds return from function after setting of setup
result to fail.
---
 android/android-tester.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 9605c4d..618efde 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -2024,6 +2024,7 @@ static void setup_base(const void *test_data)
 	if (status != BT_STATUS_SUCCESS) {
 		data->if_bluetooth = NULL;
 		tester_setup_failed();
+		return;
 	}
 
 	tester_setup_complete();
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 2/2] android/tester: Fix Discovery Stop - Success test case
From: Grzegorz Kolodziejczyk @ 2014-02-21 11:33 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1392982394-22845-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

This removes start discovery returned status check what derives double
check of expected status. Returned status should be only checked for cancel
discovery.
---
 android/android-tester.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 618efde..baa0115 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -2405,15 +2405,13 @@ static bool pre_inq_compl_hook(const void *dummy, uint16_t len, void *user_data)
 static void test_discovery_stop_success(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
-	bt_status_t status;
 
 	init_test_conditions(data);
 
 	hciemu_add_hook(data->hciemu, HCIEMU_HOOK_PRE_EVT, BT_HCI_CMD_INQUIRY,
 					pre_inq_compl_hook, data);
 
-	status = data->if_bluetooth->start_discovery();
-	check_expected_status(status);
+	data->if_bluetooth->start_discovery();
 }
 
 static void test_discovery_start_done(const void *test_data)
-- 
1.8.5.2


^ permalink raw reply related

* Re: [PATCH 1/2] android/tester: Fix tester setup result set
From: Szymon Janc @ 2014-02-21 11:54 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth
In-Reply-To: <1392982394-22845-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

Hi Grzegorz,

On Friday 21 of February 2014 12:33:13 Grzegorz Kolodziejczyk wrote:
> Tester setup result is set to pass after set to fail because of missing
> function return. This adds return from function after setting of setup
> result to fail.
> ---
>  android/android-tester.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/android/android-tester.c b/android/android-tester.c
> index 9605c4d..618efde 100644
> --- a/android/android-tester.c
> +++ b/android/android-tester.c
> @@ -2024,6 +2024,7 @@ static void setup_base(const void *test_data)
>  	if (status != BT_STATUS_SUCCESS) {
>  		data->if_bluetooth = NULL;
>  		tester_setup_failed();
> +		return;
>  	}
>  
>  	tester_setup_complete();
> 

Both patches applied, thanks.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply

* Re: [PATCH v3] android/hal-audio: Add simple downmix to mono
From: Szymon Janc @ 2014-02-21 12:03 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1391521125-2465-1-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Tuesday 04 of February 2014 14:38:45 Andrzej Kaczmarek wrote:
> This patch adds simple downmix support from stereo to mono in order to
> support mono channel mode as it's mandatory for SBC codec. It uses
> simple (L+R)/2 calculation which should be good enough.
> ---
>  android/hal-audio.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 49 insertions(+), 5 deletions(-)
> 
> diff --git a/android/hal-audio.c b/android/hal-audio.c
> index efdf823..f90265b 100644
> --- a/android/hal-audio.c
> +++ b/android/hal-audio.c
> @@ -36,9 +36,12 @@
>  #include "hal-log.h"
>  #include "hal-msg.h"
>  #include "../profiles/audio/a2dp-codecs.h"
> +#include "../src/shared/util.h"
>  
>  #define FIXED_A2DP_PLAYBACK_LATENCY_MS 25
>  
> +#define FIXED_BUFFER_SIZE (20 * 512)
> +
>  #define MAX_FRAMES_IN_PAYLOAD 15
>  
>  static const uint8_t a2dp_src_uuid[] = {
> @@ -220,6 +223,8 @@ struct a2dp_stream_out {
>  	struct audio_endpoint *ep;
>  	enum a2dp_state_t audio_state;
>  	struct audio_input_config cfg;
> +
> +	uint8_t *downmix_buf;
>  };
>  
>  struct a2dp_audio_dev {
> @@ -230,7 +235,8 @@ struct a2dp_audio_dev {
>  static const a2dp_sbc_t sbc_presets[] = {
>  	{
>  		.frequency = SBC_SAMPLING_FREQ_44100 | SBC_SAMPLING_FREQ_48000,
> -		.channel_mode = SBC_CHANNEL_MODE_DUAL_CHANNEL |
> +		.channel_mode = SBC_CHANNEL_MODE_MONO |
> +				SBC_CHANNEL_MODE_DUAL_CHANNEL |
>  				SBC_CHANNEL_MODE_STEREO |
>  				SBC_CHANNEL_MODE_JOINT_STEREO,
>  		.subbands = SBC_SUBBANDS_4 | SBC_SUBBANDS_8,
> @@ -826,6 +832,21 @@ static void unregister_endpoints(void)
>  	}
>  }
>  
> +static void downmix_to_mono(struct a2dp_stream_out *out, const uint8_t *buffer,
> +								size_t bytes)
> +{
> +	const int16_t *input = (const void *) buffer;
> +	int16_t *output = (void *) out->downmix_buf;
> +	size_t i;
> +
> +	for (i = 0; i < bytes / 2; i++) {
> +		int16_t l = le16_to_cpu(get_unaligned(&input[i * 2]));
> +		int16_t r = le16_to_cpu(get_unaligned(&input[i * 2 + 1]));
> +
> +		put_unaligned(cpu_to_le16((l + r) / 2), &output[i]);
> +	}
> +}
> +
>  static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
>  								size_t bytes)
>  {
> @@ -853,6 +874,18 @@ static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
>  		return -1;
>  	}
>  
> +	if (out->cfg.channels == AUDIO_CHANNEL_OUT_MONO) {
> +		if (!out->downmix_buf) {
> +			error("audio: downmix buffer not initialized");
> +			return -1;
> +		}
> +
> +		downmix_to_mono(out, buffer, bytes);
> +
> +		return out->ep->codec->write_data(out->ep->codec_data,
> +				out->downmix_buf, bytes / 2, out->ep->fd) * 2;
> +	}
> +
>  	return out->ep->codec->write_data(out->ep->codec_data, buffer,
>  							bytes, out->ep->fd);
>  }
> @@ -890,16 +923,18 @@ static size_t out_get_buffer_size(const struct audio_stream *stream)
>  	 * use magic value here and out_write code takes care of splitting
>  	 * input buffer into multiple media packets.
>  	 */
> -	return 20 * 512;
> +	return FIXED_BUFFER_SIZE;
>  }
>  
>  static uint32_t out_get_channels(const struct audio_stream *stream)
>  {
> -	struct a2dp_stream_out *out = (struct a2dp_stream_out *) stream;
> -
>  	DBG("");
>  
> -	return out->cfg.channels;
> +	/* AudioFlinger can only provide stereo stream, so we return it here and
> +	 * later we'll downmix this to mono in case codec requires it
> +	 */
> +
> +	return AUDIO_CHANNEL_OUT_STEREO;
>  }
>  
>  static audio_format_t out_get_format(const struct audio_stream *stream)
> @@ -1212,6 +1247,12 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
>  
>  	free(preset);
>  
> +	if (out->cfg.channels == AUDIO_CHANNEL_OUT_MONO) {
> +		out->downmix_buf = malloc(FIXED_BUFFER_SIZE / 2);
> +		if (!out->downmix_buf)
> +			goto fail;
> +	}
> +
>  	*stream_out = &out->stream;
>  	a2dp_dev->out = out;
>  
> @@ -1230,6 +1271,7 @@ static void audio_close_output_stream(struct audio_hw_device *dev,
>  					struct audio_stream_out *stream)
>  {
>  	struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *) dev;
> +	struct a2dp_stream_out *out = (struct a2dp_stream_out *) stream;
>  	struct audio_endpoint *ep = a2dp_dev->out->ep;
>  
>  	DBG("");
> @@ -1243,6 +1285,8 @@ static void audio_close_output_stream(struct audio_hw_device *dev,
>  	ep->codec->cleanup(ep->codec_data);
>  	ep->codec_data = NULL;
>  
> +	free(out->downmix_buf);
> +
>  	free(stream);
>  	a2dp_dev->out = NULL;
>  }
> 

This patch has been applied, thanks.

-- 
Best regards, 
Szymon Janc

^ permalink raw reply

* Re: [PATCH BlueZ 1/3] lib/sdp: Add missing Service Class ID for GAP
From: Luiz Augusto von Dentz @ 2014-02-21 12:33 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: BlueZ development
In-Reply-To: <CAJdJm_MNNC9iTjibrm7ajmoeqmoCMwfC2oq1DtErA=RX70Ey_w@mail.gmail.com>

Hi Anderson,

On Mon, Feb 17, 2014 at 1:55 PM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> Hi,
>
> On Fri, Feb 7, 2014 at 4:14 PM, Anderson Lizardo
> <anderson.lizardo@openbossa.org> wrote:
>> Also reorder last ID so the list remains ordered.
>> ---
>>  lib/sdp.c |    3 ++-
>>  lib/sdp.h |    7 ++++---
>>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> ping.

Pushed, thanks.

-- 
Luiz Augusto von Dentz

^ permalink raw reply

* [PATCH] android/pts: PTS test results for A2DP
From: Sebastian Chlad @ 2014-02-21 12:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Sebastian Chlad

---
 android/pts-a2dp.txt | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/android/pts-a2dp.txt b/android/pts-a2dp.txt
index 301b1e7..c407130 100644
--- a/android/pts-a2dp.txt
+++ b/android/pts-a2dp.txt
@@ -1,7 +1,7 @@
 PTS test results for A2DP
 
 PTS version: 5.0
-Tested: 28.01.2014
+Tested: 21.02.2014
 Android version: 4.4.2
 
 Results:
@@ -14,7 +14,7 @@ N/A	test is disabled due to PICS setup
 -------------------------------------------------------------------------------
 Test Name		Result	Notes
 -------------------------------------------------------------------------------
-TC_SRC_CC_BV_09_I	INC
+TC_SRC_CC_BV_09_I	PASS	Start streaming
 TC_SRC_CC_BV_10_I	N/A
 TC_SRC_REL_BV_01_I	PASS	Connect to PTS from IUT. When requested
 				disconnect from IUT
@@ -22,11 +22,11 @@ TC_SRC_REL_BV_02_I	PASS
 TC_SRC_SET_BV_01_I	PASS	Connect to PTS (open a2dp)
 TC_SRC_SET_BV_02_I	PASS
 TC_SRC_SET_BV_03_I	PASS	Start streaming
-TC_SRC_SET_BV_04_I	INC	Start streaming
-TC_SRC_SET_BV_05_I	INC	IUT must be moved out of range
-TC_SRC_SET_BV_06_I	INC	IUT must be moved out of range
+TC_SRC_SET_BV_04_I	PASS	Start streaming
+TC_SRC_SET_BV_05_I	PASS	IUT must be moved out of range
+TC_SRC_SET_BV_06_I	PASS	IUT must be moved out of range
 TC_SRC_SUS_BV_01_I	PASS	Stop streaming
-TC_SRC_SUS_BV_02_I	INC
+TC_SRC_SUS_BV_02_I	PASS
 TC_SRC_SDP_BV_01_I	PASS
 TC_SRC_AS_BV_01_I	PASS	Requires checking if the output on the IUT is
 				correct
-- 
1.8.5.3


^ permalink raw reply related

* [PATCH 00/13] Make android-tester callbacks thread safe
From: Jakub Tyszkowski @ 2014-02-21 12:57 UTC (permalink / raw)
  To: linux-bluetooth


This patch set makes all callbacks executions in HAL's notification thread being
transfered to tester's context. As test-specific callbacks are called by generic
callbacks, making the later executed in tester's main loop makes all custom
callbacks (and newly added) automatically executed in the right contex.

This is basically RFCv2 resend as PATCH with two follow-up patches.

Changes in relation to RFCv2:
  * [PATCH 12/13]: Changed daemon termination checks to non-blocking
  * [PATCH 13/13]: Added guard to execute all scheduled callbacks in current
    test's context

Best regards,

Jakub Tyszkowski (13):
  android/tester: Execute device found cbacks in main loop
  android/tester: Execute discovery state cbacks in main loop
  android/tester: Execute device properties cbacks in main loop
  android/tester: Execute adapter props cbacks in main loop
  android/tester: Execute adapter state changed cbacks in main loop
  android/tester: Execute socket cbacks in main loop
  android/tester: Execute hh connection state cbacks in main loop
  android/tester: Execute hh info cbacks in main loop
  android/tester: Execute hh protocol mode cbacks in main loop
  android/tester: Execute hh report cbacks in main loop
  android/tester: Execute hh virtual unplug cbacks in main loop
  android/tester: Non-blocking check for daemon termination
  android/tester: Add guard for late callback calls

 android/android-tester.c | 375 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 326 insertions(+), 49 deletions(-)

--
1.8.5.2


^ permalink raw reply

* [PATCH 01/13] android/tester: Execute device found cbacks in main loop
From: Jakub Tyszkowski @ 2014-02-21 12:57 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1392987473-19994-1-git-send-email-jakub.tyszkowski@tieto.com>

Execute generic device_found_cb in tester's main loop.
---
 android/android-tester.c | 60 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 5 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index baa0115..d609323 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -117,6 +117,16 @@ struct test_data {
 	uint16_t intr_cid;
 };
 
+struct bt_cb_data {
+	bt_state_t state;
+	bt_status_t status;
+
+	bt_bdaddr_t bdaddr;
+
+	int num;
+	bt_property_t *props;
+};
+
 static char exec_dir[PATH_MAX + 1];
 
 static void mgmt_debug(const char *str, void *user_data)
@@ -695,6 +705,31 @@ static void discovery_state_changed_cb(bt_discovery_state_t state)
 	}
 }
 
+static bt_property_t *copy_properties(int num_properties,
+						bt_property_t *properties)
+{
+	int i;
+	bt_property_t *props = g_new0(bt_property_t, num_properties);
+
+	for (i = 0; i < num_properties; i++) {
+		props[i].type = properties[i].type;
+		props[i].len = properties[i].len;
+		props[i].val = g_memdup(properties[i].val, properties[i].len);
+	}
+
+	return props;
+}
+
+static void free_properties(int num_properties, bt_property_t *properties)
+{
+	int i;
+
+	for (i = 0; i < num_properties; i++)
+		g_free(properties[i].val);
+
+	g_free(properties);
+}
+
 static void discovery_device_found_cb(int num_properties,
 						bt_property_t *properties)
 {
@@ -832,15 +867,30 @@ static void remote_setprop_fail_device_found_cb(int num_properties,
 	check_expected_status(status);
 }
 
-static void device_found_cb(int num_properties, bt_property_t *properties)
+static gboolean device_found(gpointer user_data)
 {
 	struct test_data *data = tester_get_data();
 	const struct generic_data *test = data->test_data;
+	struct bt_cb_data *cb_data = user_data;
 
-	if (data->test_init_done && test->expected_hal_cb.device_found_cb) {
-		test->expected_hal_cb.device_found_cb(num_properties,
-								properties);
-	}
+	if (data->test_init_done && test->expected_hal_cb.device_found_cb)
+		test->expected_hal_cb.device_found_cb(cb_data->num,
+								cb_data->props);
+
+	free_properties(cb_data->num, cb_data->props);
+	g_free(cb_data);
+
+	return FALSE;
+}
+
+static void device_found_cb(int num_properties, bt_property_t *properties)
+{
+	struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
+
+	cb_data->num = num_properties;
+	cb_data->props = copy_properties(num_properties, properties);
+
+	g_idle_add(device_found, cb_data);
 }
 
 static void check_count_properties_cb(bt_status_t status, int num_properties,
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 02/13] android/tester: Execute discovery state cbacks in main loop
From: Jakub Tyszkowski @ 2014-02-21 12:57 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1392987473-19994-1-git-send-email-jakub.tyszkowski@tieto.com>

Execute generic discovery_state_changed_cb in tester's main loop.
---
 android/android-tester.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index d609323..0976081 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -695,14 +695,27 @@ static void remote_setprop_disc_state_changed_cb(bt_discovery_state_t state)
 	}
 }
 
-static void discovery_state_changed_cb(bt_discovery_state_t state)
+static gboolean discovery_state_changed(gpointer user_data)
 {
 	struct test_data *data = tester_get_data();
 	const struct generic_data *test = data->test_data;
+	struct bt_cb_data *cb_data = user_data;
 
-	if (test && test->expected_hal_cb.discovery_state_changed_cb) {
-		test->expected_hal_cb.discovery_state_changed_cb(state);
-	}
+	if (test && test->expected_hal_cb.discovery_state_changed_cb)
+		test->expected_hal_cb.discovery_state_changed_cb(
+								cb_data->state);
+
+	g_free(cb_data);
+
+	return FALSE;
+}
+
+static void discovery_state_changed_cb(bt_discovery_state_t state)
+{
+	struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
+
+	cb_data->state = state;
+	g_idle_add(discovery_state_changed, cb_data);
 }
 
 static bt_property_t *copy_properties(int num_properties,
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 03/13] android/tester: Execute device properties cbacks in main loop
From: Jakub Tyszkowski @ 2014-02-21 12:57 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1392987473-19994-1-git-send-email-jakub.tyszkowski@tieto.com>

Execute generic remote_device_properties_cb in tester's main loop.
---
 android/android-tester.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 0976081..35e375a 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -963,18 +963,36 @@ static void remote_setprop_device_properties_cb(bt_status_t status,
 	}
 }
 
-static void remote_device_properties_cb(bt_status_t status,
-				bt_bdaddr_t *bd_addr, int num_properties,
-				bt_property_t *properties)
+static gboolean remote_device_properties(gpointer user_data)
 {
 	struct test_data *data = tester_get_data();
 	const struct generic_data *test = data->test_data;
+	struct bt_cb_data *cb_data = user_data;
 
 	if (data->test_init_done &&
-			test->expected_hal_cb.remote_device_properties_cb) {
-		test->expected_hal_cb.remote_device_properties_cb(status,
-					bd_addr, num_properties, properties);
-	}
+			test->expected_hal_cb.remote_device_properties_cb)
+		test->expected_hal_cb.remote_device_properties_cb(
+					cb_data->status, &cb_data->bdaddr,
+					cb_data->num, cb_data->props);
+
+	free_properties(cb_data->num, cb_data->props);
+	g_free(cb_data);
+
+	return FALSE;
+}
+
+static void remote_device_properties_cb(bt_status_t status,
+				bt_bdaddr_t *bd_addr, int num_properties,
+				bt_property_t *properties)
+{
+	struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
+
+	cb_data->status = status;
+	cb_data->bdaddr = *bd_addr;
+	cb_data->num = num_properties;
+	cb_data->props = copy_properties(num_properties, properties);
+
+	g_idle_add(remote_device_properties, cb_data);
 }
 
 static bt_bdaddr_t enable_done_bdaddr_val = { {0x00} };
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 04/13]  android/tester: Execute adapter props cbacks in main loop
From: Jakub Tyszkowski @ 2014-02-21 12:57 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1392987473-19994-1-git-send-email-jakub.tyszkowski@tieto.com>

Execute generic adapter_properties_cb in tester's main loop.
---
 android/android-tester.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 35e375a..3c4bf6c 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -915,19 +915,32 @@ static void check_count_properties_cb(bt_status_t status, int num_properties,
 		check_expected_property(properties[i]);
 }
 
+static gboolean adapter_properties(gpointer user_data)
+{
+	struct test_data *data = tester_get_data();
+	const struct generic_data *test = data->test_data;
+	struct bt_cb_data *cb_data = user_data;
+
+	if (data->test_init_done && test->expected_hal_cb.adapter_properties_cb)
+		test->expected_hal_cb.adapter_properties_cb(cb_data->status,
+						cb_data->num, cb_data->props);
+
+	free_properties(cb_data->num, cb_data->props);
+	g_free(cb_data);
+
+	return FALSE;
+}
 
 static void adapter_properties_cb(bt_status_t status, int num_properties,
 						bt_property_t *properties)
 {
-	struct test_data *data = tester_get_data();
-	const struct generic_data *test = data->test_data;
+	struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
 
-	if (data->test_init_done &&
-				test->expected_hal_cb.adapter_properties_cb) {
-		test->expected_hal_cb.adapter_properties_cb(
-							status, num_properties,
-							properties);
-	}
+	cb_data->status = status;
+	cb_data->num = num_properties;
+	cb_data->props = copy_properties(num_properties, properties);
+
+	g_idle_add(adapter_properties, cb_data);
 }
 
 static void remote_test_device_properties_cb(bt_status_t status,
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 05/13] android/tester: Execute adapter state changed cbacks in main loop
From: Jakub Tyszkowski @ 2014-02-21 12:57 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1392987473-19994-1-git-send-email-jakub.tyszkowski@tieto.com>

Execute generic adapter_state_changed_cb in tester's main loop.
---
 android/android-tester.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 3c4bf6c..a941e9f 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -599,19 +599,33 @@ static void disable_success_cb(bt_state_t state)
 	}
 }
 
-static void adapter_state_changed_cb(bt_state_t state)
+static gboolean adapter_state_changed(gpointer user_data)
 {
 	struct test_data *data = tester_get_data();
 	const struct generic_data *test = data->test_data;
+	struct bt_cb_data *cb_data = user_data;
 
 	if (data->test_init_done &&
 			test->expected_hal_cb.adapter_state_changed_cb) {
-		test->expected_hal_cb.adapter_state_changed_cb(state);
-		return;
+		test->expected_hal_cb.adapter_state_changed_cb(cb_data->state);
+		goto cleanup;
 	}
 
-	if (!data->test_init_done && state == BT_STATE_ON)
+	if (!data->test_init_done && cb_data->state == BT_STATE_ON)
 		setup_powered_emulated_remote();
+
+cleanup:
+	g_free(cb_data);
+	return FALSE;
+}
+
+static void adapter_state_changed_cb(bt_state_t state)
+{
+	struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1);
+
+	cb_data->state = state;
+
+	g_idle_add(adapter_state_changed, cb_data);
 }
 
 static void discovery_start_success_cb(bt_discovery_state_t state)
-- 
1.8.5.2


^ 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