Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 04/10] android/hal-audio: Add support to open output stream
From: Andrzej Kaczmarek @ 2014-01-15  9:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1389779996-9749-1-git-send-email-andrzej.kaczmarek@tieto.com>

This patch adds support to open output stream via Audio IPC.
Since only SBC is supported, we always try to open stream for first
endpoint only which is enough.
---
 android/hal-audio.c | 109 ++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 88 insertions(+), 21 deletions(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 3b4648a..2ced954 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -87,9 +87,23 @@ struct audio_endpoint {
 
 static struct audio_endpoint audio_endpoints[MAX_AUDIO_ENDPOINTS];
 
+enum a2dp_state_t {
+	AUDIO_A2DP_STATE_NONE,
+	AUDIO_A2DP_STATE_STANDBY,
+	AUDIO_A2DP_STATE_SUSPENDED,
+	AUDIO_A2DP_STATE_STARTED
+};
+
+struct a2dp_stream_out {
+	struct audio_stream_out stream;
+
+	struct audio_endpoint *ep;
+	enum a2dp_state_t audio_state;
+};
+
 struct a2dp_audio_dev {
 	struct audio_hw_device dev;
-	struct audio_stream_out *out;
+	struct a2dp_stream_out *out;
 };
 
 static const a2dp_sbc_t codec_sbc_presets[] = {
@@ -354,6 +368,38 @@ static int ipc_close_cmd(uint8_t endpoint_id)
 	return result;
 }
 
+static int ipc_open_stream_cmd(uint8_t endpoint_id,
+					struct audio_preset **caps)
+{
+	char buf[BLUEZ_AUDIO_MTU];
+	struct audio_cmd_open_stream cmd;
+	struct audio_rsp_open_stream *rsp =
+					(struct audio_rsp_open_stream *) &buf;
+	size_t rsp_len = sizeof(buf);
+	int result;
+
+	DBG("");
+
+	if (!caps)
+		return AUDIO_STATUS_FAILED;
+
+	cmd.id = endpoint_id;
+
+	result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_OPEN_STREAM,
+				sizeof(cmd), &cmd, &rsp_len, rsp, NULL);
+
+	if (result == AUDIO_STATUS_SUCCESS) {
+		size_t buf_len = sizeof(struct audio_preset) +
+					rsp->preset[0].len;
+		*caps = malloc(buf_len);
+		memcpy(*caps, &rsp->preset, buf_len);
+	} else {
+		*caps = NULL;
+	}
+
+	return result;
+}
+
 static int register_endpoints(void)
 {
 	struct audio_endpoint *ep = &audio_endpoints[0];
@@ -595,35 +641,56 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
 
 {
 	struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *) dev;
-	struct audio_stream_out *out;
+	struct a2dp_stream_out *out;
+	struct audio_preset *preset;
 
-	out = calloc(1, sizeof(struct audio_stream_out));
+	out = calloc(1, sizeof(struct a2dp_stream_out));
 	if (!out)
 		return -ENOMEM;
 
 	DBG("");
 
-	out->common.get_sample_rate = out_get_sample_rate;
-	out->common.set_sample_rate = out_set_sample_rate;
-	out->common.get_buffer_size = out_get_buffer_size;
-	out->common.get_channels = out_get_channels;
-	out->common.get_format = out_get_format;
-	out->common.set_format = out_set_format;
-	out->common.standby = out_standby;
-	out->common.dump = out_dump;
-	out->common.set_parameters = out_set_parameters;
-	out->common.get_parameters = out_get_parameters;
-	out->common.add_audio_effect = out_add_audio_effect;
-	out->common.remove_audio_effect = out_remove_audio_effect;
-	out->get_latency = out_get_latency;
-	out->set_volume = out_set_volume;
-	out->write = out_write;
-	out->get_render_position = out_get_render_position;
-
-	*stream_out = out;
+	out->stream.common.get_sample_rate = out_get_sample_rate;
+	out->stream.common.set_sample_rate = out_set_sample_rate;
+	out->stream.common.get_buffer_size = out_get_buffer_size;
+	out->stream.common.get_channels = out_get_channels;
+	out->stream.common.get_format = out_get_format;
+	out->stream.common.set_format = out_set_format;
+	out->stream.common.standby = out_standby;
+	out->stream.common.dump = out_dump;
+	out->stream.common.set_parameters = out_set_parameters;
+	out->stream.common.get_parameters = out_get_parameters;
+	out->stream.common.add_audio_effect = out_add_audio_effect;
+	out->stream.common.remove_audio_effect = out_remove_audio_effect;
+	out->stream.get_latency = out_get_latency;
+	out->stream.set_volume = out_set_volume;
+	out->stream.write = out_write;
+	out->stream.get_render_position = out_get_render_position;
+
+	/* TODO: for now we always use endpoint 0 */
+	out->ep = &audio_endpoints[0];
+
+	if (ipc_open_stream_cmd(out->ep->id, &preset) != AUDIO_STATUS_SUCCESS)
+		goto fail;
+
+	if (!preset)
+		goto fail;
+
+	/* TODO: initialize codec using received audio_preset */
+
+	free(preset);
+
+	*stream_out = &out->stream;
 	a2dp_dev->out = out;
 
+	out->audio_state = AUDIO_A2DP_STATE_STANDBY;
+
 	return 0;
+
+fail:
+	free(out);
+	*stream_out = NULL;
+	return -EIO;
 }
 
 static void audio_close_output_stream(struct audio_hw_device *dev,
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 03/10] android/hal-audio: Add support to unregister audio endpoints
From: Andrzej Kaczmarek @ 2014-01-15  9:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1389779996-9749-1-git-send-email-andrzej.kaczmarek@tieto.com>

---
 android/hal-audio.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 84e7348..3b4648a 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -339,6 +339,21 @@ static int ipc_open_cmd(const struct audio_codec *codec)
 	return rsp.id;
 }
 
+static int ipc_close_cmd(uint8_t endpoint_id)
+{
+	struct audio_cmd_close cmd;
+	int result;
+
+	DBG("");
+
+	cmd.id = endpoint_id;
+
+	result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_CLOSE,
+				sizeof(cmd), &cmd, NULL, NULL, NULL);
+
+	return result;
+}
+
 static int register_endpoints(void)
 {
 	struct audio_endpoint *ep = &audio_endpoints[0];
@@ -360,6 +375,20 @@ static int register_endpoints(void)
 	return AUDIO_STATUS_SUCCESS;
 }
 
+static void unregister_endpoints(void)
+{
+	size_t i;
+
+	for (i = 0; i < MAX_AUDIO_ENDPOINTS; i++) {
+		struct audio_endpoint *ep = &audio_endpoints[i];
+
+		if (ep->id) {
+			ipc_close_cmd(ep->id);
+			memset(ep, 0, sizeof(*ep));
+		}
+	}
+}
+
 static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
 								size_t bytes)
 {
@@ -755,6 +784,8 @@ static void *ipc_handler(void *data)
 		if (register_endpoints() != AUDIO_STATUS_SUCCESS) {
 			error("audio: Failed to register endpoints");
 
+			unregister_endpoints();
+
 			shutdown(audio_sk, SHUT_RDWR);
 			continue;
 		}
@@ -778,6 +809,8 @@ static void *ipc_handler(void *data)
 		pthread_mutex_unlock(&close_mutex);
 	}
 
+	unregister_endpoints();
+
 	info("Closing Audio IPC thread");
 	return NULL;
 }
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 02/10] android/hal-audio: Add support to register audio endpoints
From: Andrzej Kaczmarek @ 2014-01-15  9:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1389779996-9749-1-git-send-email-andrzej.kaczmarek@tieto.com>

This patch adds support to register audio enpoints via Audio IPC.
Endpoints are registered based on predefined codecs table and for
each defined codec one endpoint is registered. By default, only
SBC will be supported.
---
 android/hal-audio.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 167 insertions(+)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 354c3cf..84e7348 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -31,6 +31,11 @@
 #include "audio-msg.h"
 #include "hal-log.h"
 #include "hal-msg.h"
+#include "../profiles/audio/a2dp-codecs.h"
+
+static const uint8_t a2dp_src_uuid[] = {
+		0x00, 0x00, 0x11, 0x0a, 0x00, 0x00, 0x10, 0x00,
+		0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb };
 
 static int listen_sk = -1;
 static int audio_sk = -1;
@@ -40,11 +45,118 @@ static pthread_t ipc_th = 0;
 static pthread_mutex_t close_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t sk_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+struct audio_input_config {
+	uint32_t rate;
+	uint32_t channels;
+	audio_format_t format;
+};
+
+static int codec_sbc_get_presets(struct audio_preset *preset, size_t *len);
+
+struct audio_codec {
+	uint8_t type;
+
+	int (*get_presets) (struct audio_preset *preset, size_t *len);
+
+	int (*init) (struct audio_preset *preset, void **codec_data);
+	int (*cleanup) (void *codec_data);
+	int (*get_config) (void *codec_data,
+					struct audio_input_config *config);
+	ssize_t (*write_data) (void *codec_data, const void *buffer,
+				size_t bytes);
+};
+
+static const struct audio_codec audio_codecs[] = {
+	{
+		.type = A2DP_CODEC_SBC,
+
+		.get_presets = codec_sbc_get_presets,
+	}
+};
+
+#define NUM_CODECS (sizeof(audio_codecs) / sizeof(audio_codecs[0]))
+
+#define MAX_AUDIO_ENDPOINTS NUM_CODECS
+
+struct audio_endpoint {
+	uint8_t id;
+	const struct audio_codec *codec;
+	void *codec_data;
+	int fd;
+};
+
+static struct audio_endpoint audio_endpoints[MAX_AUDIO_ENDPOINTS];
+
 struct a2dp_audio_dev {
 	struct audio_hw_device dev;
 	struct audio_stream_out *out;
 };
 
+static const a2dp_sbc_t codec_sbc_presets[] = {
+	{
+		.frequency = SBC_SAMPLING_FREQ_44100 | SBC_SAMPLING_FREQ_48000,
+		.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,
+		.allocation_method = SBC_ALLOCATION_SNR |
+					SBC_ALLOCATION_LOUDNESS,
+		.block_length = SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 |
+				SBC_BLOCK_LENGTH_12 | SBC_BLOCK_LENGTH_16,
+		.min_bitpool = MIN_BITPOOL,
+		.max_bitpool = MAX_BITPOOL
+	},
+	{
+		.frequency = SBC_SAMPLING_FREQ_44100,
+		.channel_mode = SBC_CHANNEL_MODE_STEREO,
+		.subbands = SBC_SUBBANDS_8,
+		.allocation_method = SBC_ALLOCATION_LOUDNESS,
+		.block_length = SBC_BLOCK_LENGTH_16,
+		.min_bitpool = MIN_BITPOOL,
+		.max_bitpool = MAX_BITPOOL
+	},
+	{
+		.frequency = SBC_SAMPLING_FREQ_48000,
+		.channel_mode = SBC_CHANNEL_MODE_STEREO,
+		.subbands = SBC_SUBBANDS_8,
+		.allocation_method = SBC_ALLOCATION_LOUDNESS,
+		.block_length = SBC_BLOCK_LENGTH_16,
+		.min_bitpool = MIN_BITPOOL,
+		.max_bitpool = MAX_BITPOOL
+	},
+};
+
+static int codec_sbc_get_presets(struct audio_preset *preset, size_t *len)
+{
+	int i;
+	int count;
+	size_t new_len = 0;
+	uint8_t *ptr = (uint8_t *) preset;
+	size_t preset_size = sizeof(*preset) + sizeof(a2dp_sbc_t);
+
+	DBG("");
+
+	count = sizeof(codec_sbc_presets) / sizeof(codec_sbc_presets[0]);
+
+	for (i = 0; i < count; i++) {
+		preset = (struct audio_preset *) ptr;
+
+		if (new_len + preset_size > *len)
+			break;
+
+		preset->len = sizeof(a2dp_sbc_t);
+		memcpy(preset->data, &codec_sbc_presets[i], preset->len);
+
+		new_len += preset_size;
+		ptr += preset_size;
+	}
+
+	*len = new_len;
+
+	return i;
+}
+
 static void audio_ipc_cleanup(void)
 {
 	if (audio_sk >= 0) {
@@ -200,6 +312,54 @@ failed:
 	return AUDIO_STATUS_FAILED;
 }
 
+static int ipc_open_cmd(const struct audio_codec *codec)
+{
+	uint8_t buf[BLUEZ_AUDIO_MTU];
+	struct audio_cmd_open *cmd = (struct audio_cmd_open *) buf;
+	struct audio_rsp_open rsp;
+	size_t cmd_len = sizeof(buf) - sizeof(*cmd);
+	size_t rsp_len = sizeof(rsp);
+	int result;
+
+	DBG("");
+
+	memcpy(cmd->uuid, a2dp_src_uuid, sizeof(a2dp_src_uuid));
+
+	cmd->codec = codec->type;
+	cmd->presets = codec->get_presets(cmd->preset, &cmd_len);
+
+	cmd_len += sizeof(*cmd);
+
+	result = audio_ipc_cmd(AUDIO_SERVICE_ID, AUDIO_OP_OPEN, cmd_len, cmd,
+				&rsp_len, &rsp, NULL);
+
+	if (result != AUDIO_STATUS_SUCCESS)
+		return 0;
+
+	return rsp.id;
+}
+
+static int register_endpoints(void)
+{
+	struct audio_endpoint *ep = &audio_endpoints[0];
+	size_t i;
+
+	for (i = 0; i < NUM_CODECS; i++) {
+		const struct audio_codec *codec = &audio_codecs[i];
+
+		ep->id = ipc_open_cmd(codec);
+
+		if (!ep->id)
+			return AUDIO_STATUS_FAILED;
+
+		ep->codec = codec;
+		ep->codec_data = NULL;
+		ep->fd = -1;
+	}
+
+	return AUDIO_STATUS_SUCCESS;
+}
+
 static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
 								size_t bytes)
 {
@@ -592,6 +752,13 @@ static void *ipc_handler(void *data)
 
 		DBG("Audio IPC: Connected");
 
+		if (register_endpoints() != AUDIO_STATUS_SUCCESS) {
+			error("audio: Failed to register endpoints");
+
+			shutdown(audio_sk, SHUT_RDWR);
+			continue;
+		}
+
 		memset(&pfd, 0, sizeof(pfd));
 		pfd.fd = audio_sk;
 		pfd.events = POLLHUP | POLLERR | POLLNVAL;
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 01/10] android/hal-audio: Add audio_ipc_cmd
From: Andrzej Kaczmarek @ 2014-01-15  9:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lukasz Rymanowski
In-Reply-To: <1389779996-9749-1-git-send-email-andrzej.kaczmarek@tieto.com>

From: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>

Add function to handle send/receive on audio_sk.
---
 android/Makefile.am |   1 +
 android/hal-audio.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+)

diff --git a/android/Makefile.am b/android/Makefile.am
index 7806f79..e09f967 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -120,6 +120,7 @@ android_android_tester_LDFLAGS = -pthread -ldl
 plugin_LTLIBRARIES += android/audio.a2dp.default.la
 
 android_audio_a2dp_default_la_SOURCES = android/audio-msg.h \
+					android/hal-msg.h \
 					android/hal-audio.c \
 					android/hardware/audio.h \
 					android/hardware/audio_effect.h \
diff --git a/android/hal-audio.c b/android/hal-audio.c
index c51b065..354c3cf 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -30,6 +30,7 @@
 
 #include "audio-msg.h"
 #include "hal-log.h"
+#include "hal-msg.h"
 
 static int listen_sk = -1;
 static int audio_sk = -1;
@@ -37,6 +38,7 @@ static bool close_thread = false;
 
 static pthread_t ipc_th = 0;
 static pthread_mutex_t close_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t sk_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 struct a2dp_audio_dev {
 	struct audio_hw_device dev;
@@ -51,6 +53,153 @@ static void audio_ipc_cleanup(void)
 	}
 }
 
+static int audio_ipc_cmd(uint8_t service_id, uint8_t opcode, uint16_t len,
+			void *param, size_t *rsp_len, void *rsp, int *fd)
+{
+	ssize_t ret;
+	struct msghdr msg;
+	struct iovec iv[2];
+	struct hal_hdr cmd;
+	char cmsgbuf[CMSG_SPACE(sizeof(int))];
+	struct hal_status s;
+	size_t s_len = sizeof(s);
+
+	if (audio_sk < 0) {
+		error("audio: Invalid cmd socket passed to audio_ipc_cmd");
+		goto failed;
+	}
+
+	if (!rsp || !rsp_len) {
+		memset(&s, 0, s_len);
+		rsp_len = &s_len;
+		rsp = &s;
+	}
+
+	memset(&msg, 0, sizeof(msg));
+	memset(&cmd, 0, sizeof(cmd));
+
+	cmd.service_id = service_id;
+	cmd.opcode = opcode;
+	cmd.len = len;
+
+	iv[0].iov_base = &cmd;
+	iv[0].iov_len = sizeof(cmd);
+
+	iv[1].iov_base = param;
+	iv[1].iov_len = len;
+
+	msg.msg_iov = iv;
+	msg.msg_iovlen = 2;
+
+	pthread_mutex_lock(&sk_mutex);
+
+	ret = sendmsg(audio_sk, &msg, 0);
+	if (ret < 0) {
+		error("audio: Sending command failed:%s", strerror(errno));
+		pthread_mutex_unlock(&sk_mutex);
+		goto failed;
+	}
+
+	/* socket was shutdown */
+	if (ret == 0) {
+		error("audio: Command socket closed");
+		goto failed;
+	}
+
+	memset(&msg, 0, sizeof(msg));
+	memset(&cmd, 0, sizeof(cmd));
+
+	iv[0].iov_base = &cmd;
+	iv[0].iov_len = sizeof(cmd);
+
+	iv[1].iov_base = rsp;
+	iv[1].iov_len = *rsp_len;
+
+	msg.msg_iov = iv;
+	msg.msg_iovlen = 2;
+
+	if (fd) {
+		memset(cmsgbuf, 0, sizeof(cmsgbuf));
+		msg.msg_control = cmsgbuf;
+		msg.msg_controllen = sizeof(cmsgbuf);
+	}
+
+	ret = recvmsg(audio_sk, &msg, 0);
+	if (ret < 0) {
+		error("audio: Receiving command response failed:%s",
+							strerror(errno));
+		pthread_mutex_unlock(&sk_mutex);
+		goto failed;
+	}
+
+	pthread_mutex_unlock(&sk_mutex);
+
+	if (ret < (ssize_t) sizeof(cmd)) {
+		error("audio: Too small response received(%zd bytes)", ret);
+		goto failed;
+	}
+
+	if (cmd.service_id != service_id) {
+		error("audio: Invalid service id (%u vs %u)", cmd.service_id,
+								service_id);
+		goto failed;
+	}
+
+	if (ret != (ssize_t) (sizeof(cmd) + cmd.len)) {
+		error("audio: Malformed response received(%zd bytes)", ret);
+		goto failed;
+	}
+
+	if (cmd.opcode != opcode && cmd.opcode != AUDIO_OP_STATUS) {
+		error("audio: Invalid opcode received (%u vs %u)",
+						cmd.opcode, opcode);
+		goto failed;
+	}
+
+	if (cmd.opcode == AUDIO_OP_STATUS) {
+		struct hal_status *s = rsp;
+
+		if (sizeof(*s) != cmd.len) {
+			error("audio: Invalid status length");
+			goto failed;
+		}
+
+		if (s->code == AUDIO_STATUS_SUCCESS) {
+			error("audio: Invalid success status response");
+			goto failed;
+		}
+
+		return s->code;
+	}
+
+	/* Receive auxiliary data in msg */
+	if (fd) {
+		struct cmsghdr *cmsg;
+
+		*fd = -1;
+
+		for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
+					cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+			if (cmsg->cmsg_level == SOL_SOCKET
+					&& cmsg->cmsg_type == SCM_RIGHTS) {
+				memcpy(fd, CMSG_DATA(cmsg), sizeof(int));
+				break;
+			}
+		}
+	}
+
+	if (rsp_len)
+		*rsp_len = cmd.len;
+
+	return AUDIO_STATUS_SUCCESS;
+
+failed:
+	/* Some serious issue happen on IPC - recover */
+	shutdown(audio_sk, SHUT_RDWR);
+	audio_sk = -1;
+	return AUDIO_STATUS_FAILED;
+}
+
 static ssize_t out_write(struct audio_stream_out *stream, const void *buffer,
 								size_t bytes)
 {
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 00/10] android: Audio HAL implementation
From: Andrzej Kaczmarek @ 2014-01-15  9:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek

Hi,

Here are patches which implement Audio HAL. Complete IPC signalling is
implemented with stubs to add SBC codec in next step.

Note that in order to make these patches work correctly BlueZ needs to
notify A2DP connected state after streaming channel is connected - at
the moment it does so just after singalling is connected which will
result in an error when Audio HAL tries to open stream.


Andrzej Kaczmarek (9):
  android/hal-audio: Add support to register audio endpoints
  android/hal-audio: Add support to unregister audio endpoints
  android/hal-audio: Add support to open output stream
  android/hal-audio: Add support to close output stream
  android/hal-audio: Add support to resume output stream
  android/hal-audio: Add support to suspend output stream
  android/hal-audio: Handle audio preset from stream
  android/hal-audio: Fix module loading
  android/hal-audio: Fix AudioFlinger crash

Lukasz Rymanowski (1):
  android/hal-audio: Add audio_ipc_cmd

 android/Makefile.am |   1 +
 android/hal-audio.c | 699 +++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 667 insertions(+), 33 deletions(-)

-- 
1.8.5.2


^ permalink raw reply

* Re: [PATCH 1/2] android/a2dp: Fix IPC response length calculation
From: Luiz Augusto von Dentz @ 2014-01-15  9:38 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1389716179-21874-1-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Tue, Jan 14, 2014 at 6:16 PM, Andrzej Kaczmarek
<andrzej.kaczmarek@tieto.com> wrote:
> struct audio_rsp_open_stream has only zero-length array member thus its
> size equals to 0. We need to explicitly specify size of array element
> type here.
> ---
>  android/a2dp.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/android/a2dp.c b/android/a2dp.c
> index 9f3164a..145cd67 100644
> --- a/android/a2dp.c
> +++ b/android/a2dp.c
> @@ -1088,8 +1088,8 @@ static void bt_stream_open(const void *buf, uint16_t len)
>                 return;
>         }
>
> -       len = sizeof(*rsp) + setup->preset->len;
> -       rsp = g_malloc0(sizeof(*rsp) + setup->preset->len);
> +       len = sizeof(struct audio_preset) + setup->preset->len;
> +       rsp = g_malloc0(len);
>         rsp->preset->len = setup->preset->len;
>         memcpy(rsp->preset->data, setup->preset->data, setup->preset->len);
>
> --
> 1.8.5.2

Pushed, thanks.

-- 
Luiz Augusto von Dentz

^ permalink raw reply

* [PATCH] android/pics: Add PICS and PIXIT for AVCTP
From: Jakub Tyszkowski @ 2014-01-15  9:31 UTC (permalink / raw)
  To: linux-bluetooth

Add PICS/PIXIT for AVCTP, targeting Android 4.4.
---
 android/Makefile.am     |  1 +
 android/pics-avctp.txt  | 75 +++++++++++++++++++++++++++++++++++++++++++++++++
 android/pixit-avctp.txt | 39 +++++++++++++++++++++++++
 3 files changed, 115 insertions(+)
 create mode 100644 android/pics-avctp.txt
 create mode 100644 android/pixit-avctp.txt

diff --git a/android/Makefile.am b/android/Makefile.am
index 7806f79..cd4a526 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -147,4 +147,5 @@ EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
 		android/pics-l2cap.txt android/pixit-l2cap.txt \
 		android/pics-avrcp.txt android/pixit-avrcp.txt \
 		android/pics-a2dp.txt android/pixit-a2dp.txt \
+		android/pics-avctp.txt android/pixit-avctp.txt \
 		android/pts-l2cap.txt
diff --git a/android/pics-avctp.txt b/android/pics-avctp.txt
new file mode 100644
index 0000000..939ffdb
--- /dev/null
+++ b/android/pics-avctp.txt
@@ -0,0 +1,75 @@
+AVCTP PICS for the PTS tool.
+
+PTS version: 5.0
+
+* - different than PTS defaults
+# - not yet implemented/supported
+
+M - mandatory if such role selected
+O - optional
+
+		Protocol Version
+-------------------------------------------------------------------------------
+Parameter Name	Selected	Description
+-------------------------------------------------------------------------------
+TSPC_AVCTP_0_1	False		AVCTP 1.0 (C.1)
+TSPC_AVCTP_0_2	True (*)	AVCTP 1.2 (C.1)
+TSPC_AVCTP_0_3	False		AVCTP 1.3 (C.1)
+TSPC_AVCTP_0_4	False		AVCTP 1.4 (C.1)
+-------------------------------------------------------------------------------
+C.1: Mandatory to support only one Protocol Version.
+-------------------------------------------------------------------------------
+
+
+		Roles
+-------------------------------------------------------------------------------
+Parameter Name	Selected	Description
+-------------------------------------------------------------------------------
+TSPC_AVCTP_1_1	False		Controller (C.1)
+TSPC_AVCTP_1_2	True (*)	Target (C.1)
+-------------------------------------------------------------------------------
+C.1: Mandatory to support at least one of the defined roles.
+-------------------------------------------------------------------------------
+
+
+		Controller Features
+-------------------------------------------------------------------------------
+Parameter Name	Selected	Description
+-------------------------------------------------------------------------------
+TSPC_AVCTP_2_1	False		Message fragmentation (O)
+TSPC_AVCTP_2_2	False (*)	Transaction label management (M)
+TSPC_AVCTP_2_3	False (*)	Packet type field management (M)
+TSPC_AVCTP_2_4	False (*)	Message type field management (M)
+TSPC_AVCTP_2_5	False (*)	PID field management (M)
+TSPC_AVCTP_2_6	False (*)	IPID field mangement (M)
+TSPC_AVCTP_2_7	False (*)	Message information management (M)
+TSPC_AVCTP_2_8	False		Event registration for message reception (O)
+TSPC_AVCTP_2_9	False		Event registration for connection request (O)
+TSPC_AVCTP_2_10	False		Event registration for disconnection (O)
+TSPC_AVCTP_2_11	False		Connect request (O)
+TSPC_AVCTP_2_12	False		Disconnect request (O)
+TSPC_AVCTP_2_13	False		Send message (O)
+TSPC_AVCTP_2_14	False		Support for multiple AVCTP channel establishment
+					(O)
+-------------------------------------------------------------------------------
+
+
+		Target Features
+-------------------------------------------------------------------------------
+Parameter Name	Selected	Description
+-------------------------------------------------------------------------------
+TSPC_AVCTP_3_1	True (*)	Message fragmentation (O)
+TSPC_AVCTP_3_2	True		Transaction label management (M)
+TSPC_AVCTP_3_3	True		Packet type field management (M)
+TSPC_AVCTP_3_4	True		Message type field management (M)
+TSPC_AVCTP_3_5	True		PID field management (M)
+TSPC_AVCTP_3_6	True		IPID field management (M)
+TSPC_AVCTP_3_7	True		Message information management (M)
+TSPC_AVCTP_3_8	True (*)	Event registration for message reception (O)
+TSPC_AVCTP_3_9	True (*)	Event registration for connection request (O)
+TSPC_AVCTP_3_10	True (*)	Event registration for disconnection request (O)
+TSPC_AVCTP_3_11	True (*)	Connect request (O)
+TSPC_AVCTP_3_12	True (*)	Disconnect request (O)
+TSPC_AVCTP_3_13	True (*)	Send message (O)
+TSPC_AVCTP_ALL	False		Enables all test cases when set to TRUE
+-------------------------------------------------------------------------------
diff --git a/android/pixit-avctp.txt b/android/pixit-avctp.txt
new file mode 100644
index 0000000..c5782fd
--- /dev/null
+++ b/android/pixit-avctp.txt
@@ -0,0 +1,39 @@
+AVCTP PIXIT for the PTS tool.
+
+PTS version: 5.0
+
+* - different than PTS defaults
+& - should be set to IUT Bluetooth address
+# - should be set to PTS's bin/audio folder
+
+		Required PIXIT settings
+-------------------------------------------------------------------------------
+Parameter Name			Value
+-------------------------------------------------------------------------------
+TSPX_avctp_psm			0017
+TSPX_avctp_profile_id		110E
+TSPX_connect_avdtp		TRUE
+TSPX_avctp_tester_command_data
+TSPX_avctp_tester_response_data
+TSPX_avctp_iut_command_data
+TSPX_avctp_iut_response_data
+TSPX_bd_addr_iut		08606E414394 (&)
+TSPX_pin_code			0000
+TSPX_delete_link_key		FALSE
+TSPX_security_enabled		FALSE
+TSPX_class_of_device		20050C
+TSPX_player_feature_bitmask	0000000000000007FFF00070000000000
+TSPX_avrcp_version
+TSPX_establish_avdtp_stream	TRUE
+TSPX_tester_av_role
+TSPX_time_guard			300000
+TSPX_avrcp_only			FALSE
+TSPX_use_implicit_send		TRUE
+TSPX_media_directory		C:\Program Files\Bluetooth SIG\Bluetooth PTS\
+					bin\audio (#)
+TSPX_no_confirmations		FALSE
+TSPX_auth_password		0000
+TSPX_auth_user_id		PTS
+TSPX_rfcomm_channel		8
+TSPX_l2cap_psm			1011
+-------------------------------------------------------------------------------
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH] Bluetooth: Queue incoming ACL data until BT_CONNECTED state is reached
From: johan.hedberg @ 2014-01-15  9:30 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds a queue for incoming L2CAP data that's received before
l2cap_connect_cfm is called and processes the data once
l2cap_connect_cfm is called. This way we ensure that we have e.g. all
remote features before processing L2CAP signaling data (which is very
important for making the correct security decisions).

The processing of the pending rx data needs to be done through
queue_work since unlike l2cap_recv_acldata, l2cap_connect_cfm is called
with the hci_dev lock held which could cause potential deadlocks.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
This patch is e.g. needed for the "L2CAP BR/EDR Server - Security Block"
l2cap-tester test case to pass reliably.

 include/net/bluetooth/l2cap.h |  3 +++
 net/bluetooth/l2cap_core.c    | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index dbc4a89984ca..40e15cd948c1 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -623,6 +623,9 @@ struct l2cap_conn {
 	__u32			rx_len;
 	__u8			tx_ident;
 
+	struct sk_buff_head	pending_rx;
+	struct work_struct	pending_rx_work;
+
 	__u8			disc_reason;
 
 	struct delayed_work	security_timer;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index b0ad2c752d73..f2ee479a87a7 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -63,6 +63,8 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err);
 static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
 		     struct sk_buff_head *skbs, u8 event);
 
+static void process_pending_rx(struct work_struct *work);
+
 static inline __u8 bdaddr_type(struct hci_conn *hcon, __u8 type)
 {
 	if (hcon->type == LE_LINK) {
@@ -1546,6 +1548,8 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
 	}
 
 	mutex_unlock(&conn->chan_lock);
+
+	queue_work(hcon->hdev->workqueue, &conn->pending_rx_work);
 }
 
 /* Notify sockets that we cannot guaranty reliability anymore */
@@ -1671,6 +1675,9 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
 
 	kfree_skb(conn->rx_skb);
 
+	skb_queue_purge(&conn->pending_rx);
+	flush_work(&conn->pending_rx_work);
+
 	l2cap_unregister_all_users(conn);
 
 	mutex_lock(&conn->chan_lock);
@@ -1773,6 +1780,9 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
 	else
 		INIT_DELAYED_WORK(&conn->info_timer, l2cap_info_timeout);
 
+	skb_queue_head_init(&conn->pending_rx);
+	INIT_WORK(&conn->pending_rx_work, process_pending_rx);
+
 	conn->disc_reason = HCI_ERROR_REMOTE_USER_TERM;
 
 	return conn;
@@ -7084,9 +7094,16 @@ drop:
 static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
 {
 	struct l2cap_hdr *lh = (void *) skb->data;
+	struct hci_conn *hcon = conn->hcon;
 	u16 cid, len;
 	__le16 psm;
 
+	if (hcon->state != BT_CONNECTED) {
+		BT_DBG("queueing pending rx skb");
+		skb_queue_tail(&conn->pending_rx, skb);
+		return;
+	}
+
 	skb_pull(skb, L2CAP_HDR_SIZE);
 	cid = __le16_to_cpu(lh->cid);
 	len = __le16_to_cpu(lh->len);
@@ -7132,6 +7149,22 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
 	}
 }
 
+static void process_pending_rx(struct work_struct *work)
+{
+	struct l2cap_conn *conn = container_of(work, struct l2cap_conn,
+					       pending_rx_work);
+
+	BT_DBG("");
+
+	while (!skb_queue_empty(&conn->pending_rx)) {
+		struct sk_buff *skb;
+
+		skb = skb_dequeue(&conn->pending_rx);
+
+		l2cap_recv_frame(conn, skb);
+	}
+}
+
 /* ---- L2CAP interface with lower layer (HCI) ---- */
 
 int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr)
-- 
1.8.4.2


^ permalink raw reply related

* Re: [RFC 1/4] android: Add sample init.bluetooth.rc file
From: Marcel Holtmann @ 2014-01-14 21:20 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1389713283-13038-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

> This file is intended to be included from device init.rc.
> ---
> android/Android.mk        | 16 +++++++++++++++-
> android/Makefile.am       |  1 +
> android/init.bluetooth.rc | 27 +++++++++++++++++++++++++++
> 3 files changed, 43 insertions(+), 1 deletion(-)
> create mode 100644 android/init.bluetooth.rc
> 
> diff --git a/android/Android.mk b/android/Android.mk
> index ae52ab4..f13e703 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -109,7 +109,7 @@ LOCAL_MODULE := bluetooth.default
> LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
> LOCAL_MODULE_TAGS := optional
> LOCAL_MODULE_CLASS := SHARED_LIBRARIES
> -LOCAL_REQUIRED_MODULES := bluetoothd bluetoothd-snoop
> +LOCAL_REQUIRED_MODULES := bluetoothd bluetoothd-snoop init.bluetooth.rc
> 
> include $(BUILD_SHARED_LIBRARY)
> 
> @@ -263,3 +263,17 @@ LOCAL_MODULE_TAGS := optional
> LOCAL_MODULE := bluetoothd-snoop
> 
> include $(BUILD_EXECUTABLE)
> +
> +#
> +# init.bleutooth.rc
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_MODULE := init.bluetooth.rc
> +LOCAL_MODULE_CLASS := ETC
> +LOCAL_SRC_FILES := $(LOCAL_MODULE)
> +LOCAL_MODULE_TAGS := optional
> +LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
> +
> +include $(BUILD_PREBUILT)
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 7806f79..b205019 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -134,6 +134,7 @@ android_audio_a2dp_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \
> endif
> 
> EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
> +		android/init.bluetooth.rc \
> 		android/pics-gap.txt android/pics-hid.txt \
> 		android/pics-pan.txt android/pics-did.txt \
> 		android/pics-opp.txt android/pics-pbap.txt \
> diff --git a/android/init.bluetooth.rc b/android/init.bluetooth.rc
> new file mode 100644
> index 0000000..e2be9e8
> --- /dev/null
> +++ b/android/init.bluetooth.rc
> @@ -0,0 +1,27 @@
> +chown bluetooth bluetooth /data/misc/bluetooth
> +
> +chown bluetooth bluetooth /dev/uhid
> +
> +on property:bluetooth.start=bluetoothd
> +    start bluetoothd
> +
> +on property:bluetooth.stop=bluetoothd
> +    stop bluetoothd
> +
> +on property:bluetooth.start=bluetoothd-snoop
> +    start bluetoothd-snoop
> +
> +on property:bluetooth.stop=bluetoothd-snoop
> +    stop bluetoothd-snoop

I think this is actually racy. The ctl.start and ctl.stop sound like they have special handling inside Android init. If you accidentally set bluetooth.start , then bad things happen.

So I would propose doing bluetooth.daemon=on/off and bluetooth.snoop=on/off

We just have to make sure that when bluetoothd or bluetoothd-snoop die unexpectedly that these properties get set back to off.

> +
> +service bluetoothd /system/bin/logwrapper /system/bin/bluetoothd
> +    class main
> +    group bluetooth net_admin
> +    disabled
> +    oneshot
> +
> +service bluetoothd-snoop /system/bin/bluetoothd-snoop
> +    class main
> +    group bluetooth net_admin
> +    disabled
> +    oneshot

Does net_admin include CAP_NET_RAW actually or are we using some sort of patched module for this?

Regards

Marcel


^ permalink raw reply

* Re: [RFC 1/4] android: Add sample init.bluetooth.rc file
From: Andrzej Kaczmarek @ 2014-01-14 21:17 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1389713283-13038-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On 14 January 2014 16:28, Szymon Janc <szymon.janc@tieto.com> wrote:
> This file is intended to be included from device init.rc.
> ---
>  android/Android.mk        | 16 +++++++++++++++-
>  android/Makefile.am       |  1 +
>  android/init.bluetooth.rc | 27 +++++++++++++++++++++++++++
>  3 files changed, 43 insertions(+), 1 deletion(-)
>  create mode 100644 android/init.bluetooth.rc
>
> diff --git a/android/Android.mk b/android/Android.mk
> index ae52ab4..f13e703 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -109,7 +109,7 @@ LOCAL_MODULE := bluetooth.default
>  LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
>  LOCAL_MODULE_TAGS := optional
>  LOCAL_MODULE_CLASS := SHARED_LIBRARIES
> -LOCAL_REQUIRED_MODULES := bluetoothd bluetoothd-snoop
> +LOCAL_REQUIRED_MODULES := bluetoothd bluetoothd-snoop init.bluetooth.rc
>
>  include $(BUILD_SHARED_LIBRARY)
>
> @@ -263,3 +263,17 @@ LOCAL_MODULE_TAGS := optional
>  LOCAL_MODULE := bluetoothd-snoop
>
>  include $(BUILD_EXECUTABLE)
> +
> +#
> +# init.bleutooth.rc
> +#
> +
> +include $(CLEAR_VARS)
> +
> +LOCAL_MODULE := init.bluetooth.rc
> +LOCAL_MODULE_CLASS := ETC
> +LOCAL_SRC_FILES := $(LOCAL_MODULE)
> +LOCAL_MODULE_TAGS := optional
> +LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
> +
> +include $(BUILD_PREBUILT)
> diff --git a/android/Makefile.am b/android/Makefile.am
> index 7806f79..b205019 100644
> --- a/android/Makefile.am
> +++ b/android/Makefile.am
> @@ -134,6 +134,7 @@ android_audio_a2dp_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \
>  endif
>
>  EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
> +               android/init.bluetooth.rc \
>                 android/pics-gap.txt android/pics-hid.txt \
>                 android/pics-pan.txt android/pics-did.txt \
>                 android/pics-opp.txt android/pics-pbap.txt \
> diff --git a/android/init.bluetooth.rc b/android/init.bluetooth.rc
> new file mode 100644
> index 0000000..e2be9e8
> --- /dev/null
> +++ b/android/init.bluetooth.rc
> @@ -0,0 +1,27 @@
> +chown bluetooth bluetooth /data/misc/bluetooth
> +
> +chown bluetooth bluetooth /dev/uhid

There should be some action trigger at the beginning, e.g. 'on boot'
should be fine.


BR,
Andrzej

^ permalink raw reply

* Re: [PATCH v2 01/15] android/tester: Fix for asynchronous test case condition check
From: Szymon Janc @ 2014-01-14 18:43 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth
In-Reply-To: <1389707686-30766-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

Hi Grzegorz,

On Tuesday 14 January 2014 14:54:32 Grzegorz Kolodziejczyk wrote:
> This patch fixes checking the state of test case. Due to asynchronous of
> callbacks during state check of every single condition, state can be
> checked double time by callback condition check with pass status already
> set in meantime. Now state is kept as one decremented int.
> To pass it must be equal zero and cannot be checked set again.
> 
> Change-Id: I595c9f9606f1da41218a85c62c07881bd7bd8ee8
> ---
>  android/android-tester.c | 44 ++++++++++++++++++++------------------------
>  1 file changed, 20 insertions(+), 24 deletions(-)

All patches in this set are now upstream, thanks.

(I fixed Change-Id in 1/15 myself but please pay attention on this in future 
patches)

-- 
Szymon K. Janc
szymon.janc@gmail.com

^ permalink raw reply

* Re: [RFC 1/5] android/bluetooth: Split devices list to devices and bonded_devices
From: Szymon Janc @ 2014-01-14 18:03 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: Szymon Janc, linux-bluetooth@vger.kernel.org
In-Reply-To: <CABBYNZLsSJsxLmSB=F1GYLmNyWhzRwjT33qH4p-ELwLy=AftLQ@mail.gmail.com>

Hi Luiz,

On Tuesday 14 January 2014 17:42:02 Luiz Augusto von Dentz wrote:
> Hi Szymon,
> 
> On Tue, Jan 14, 2014 at 1:11 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> > From: Szymon Janc <szymon.janc@gmail.com>
> > 
> > Bonded devices are permament until unbondedn. Non-bonded devices will
> > be held in (size limited) cache based on timestamp property so split
> > list to ease separation.
> > ---
> > 
> >  android/bluetooth.c | 47 +++++++++++++++++++++++++++++++++++------------
> >  1 file changed, 35 insertions(+), 12 deletions(-)
> > 
> > diff --git a/android/bluetooth.c b/android/bluetooth.c
> > index 735b03e..78e98c1 100644
> > --- a/android/bluetooth.c
> > +++ b/android/bluetooth.c
> > @@ -133,6 +133,8 @@ static const uint16_t uuid_list[] = {
> > 
> >  };
> >  
> >  static struct mgmt *mgmt_if = NULL;
> > 
> > +
> > +static GSList *bonded_devices = NULL;
> > 
> >  static GSList *devices = NULL;
> >  
> >  /* This list contains addresses which are asked for records */
> > 
> > @@ -284,6 +286,10 @@ static struct device *find_device(const bdaddr_t
> > *bdaddr)> 
> >  {
> >  
> >         GSList *l;
> > 
> > +       l = g_slist_find_custom(bonded_devices, bdaddr, device_match);
> > +       if (l)
> > +               return l->data;
> > +
> > 
> >         l = g_slist_find_custom(devices, bdaddr, device_match);
> >         if (l)
> >         
> >                 return l->data;
> > 
> > @@ -560,12 +566,30 @@ static void set_device_bond_state(const bdaddr_t
> > *addr, uint8_t status,> 
> >         if (!dev)
> >         
> >                 return;
> > 
> > -       if (dev->bond_state != state) {
> > -               dev->bond_state = state;
> > -               send_bond_state_change(&dev->bdaddr, status, state);
> > +       if (dev->bond_state == state)
> > +               return;
> > 
> > -               store_device_info(dev);
> > +       switch (state) {
> > +       case HAL_BOND_STATE_NONE:
> > +               if (dev->bond_state == HAL_BOND_STATE_BONDED) {
> > +                       bonded_devices = g_slist_remove(bonded_devices,
> > dev); +                       devices = g_slist_prepend(devices, dev);
> > +               }
> > +               break;
> > +       case HAL_BOND_STATE_BONDED:
> > +               devices = g_slist_remove(devices, dev);
> > +               bonded_devices = g_slist_prepend(bonded_devices, dev);
> > +               break;
> > +       case HAL_BOND_STATE_BONDING:
> > +       default:
> > +               break;
> > 
> >         }
> > 
> > +
> > +       dev->bond_state = state;
> > +
> > +       store_device_info(dev);
> > +
> > +       send_bond_state_change(&dev->bdaddr, status, state);
> > 
> >  }
> >  
> >  static  void send_device_property(const bdaddr_t *bdaddr, uint8_t type,
> > 
> > @@ -2134,18 +2158,15 @@ static uint8_t get_adapter_scan_mode(void)
> > 
> >  static uint8_t get_adapter_bonded_devices(void)
> >  {
> > 
> > -       uint8_t buf[sizeof(bdaddr_t) * g_slist_length(devices)];
> > +       uint8_t buf[sizeof(bdaddr_t) * g_slist_length(bonded_devices)];
> > 
> >         int i = 0;
> >         GSList *l;
> >         
> >         DBG("");
> > 
> > -       for (l = devices; l; l = g_slist_next(l)) {
> > +       for (l = bonded_devices; l; l = g_slist_next(l)) {
> > 
> >                 struct device *dev = l->data;
> > 
> > -               if (dev->bond_state != HAL_BOND_STATE_BONDED)
> > -                       continue;
> > -
> > 
> >                 bdaddr2android(&dev->bdaddr, buf + (i *
> >                 sizeof(bdaddr_t)));
> >                 i++;
> >         
> >         }
> > 
> > @@ -2697,11 +2718,10 @@ static void send_bonded_devices_props(void)
> > 
> >  {
> >  
> >         GSList *l;
> > 
> > -       for (l = devices; l; l = g_slist_next(l)) {
> > +       for (l = bonded_devices; l; l = g_slist_next(l)) {
> > 
> >                 struct device *dev = l->data;
> > 
> > -               if (dev->bond_state == HAL_BOND_STATE_BONDED)
> > -                       get_remote_device_props(dev);
> > +               get_remote_device_props(dev);
> > 
> >         }
> >  
> >  }
> > 
> > @@ -3099,6 +3119,9 @@ void bt_bluetooth_unregister(void)
> > 
> >  {
> >  
> >         DBG("");
> > 
> > +       g_slist_free_full(bonded_devices, (GDestroyNotify) free_device);
> > +       bonded_devices = NULL;
> > +
> > 
> >         g_slist_free_full(devices, (GDestroyNotify) free_device);
> 
> You can make free_device to take a void pointer so you don't have to
> cast in such cases.

Yes, that could be done, since this function is already present I'll change 
that in separate patch.

-- 
Szymon K. Janc
szymon.janc@gmail.com

^ permalink raw reply

* Re: [RFC 4/5] android/bluetooth: Add support for caching remote device info
From: Szymon Janc @ 2014-01-14 17:55 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: Szymon Janc, linux-bluetooth@vger.kernel.org
In-Reply-To: <CABBYNZJRVE50AVx0Tm+y_MMuO94U4wEARetXyhRf8UckJCwJcw@mail.gmail.com>

Hi Luiz,

On Tuesday 14 January 2014 17:49:54 Luiz Augusto von Dentz wrote:
> Hi Szymon,
> 
> On Tue, Jan 14, 2014 at 1:11 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> > Cache is limited to DEVICES_CACHE_MAX. Devices are sorted with
> > timestamp so if cache is full olderst device is removed.
> > ---
> > 
> >  android/bluetooth.c | 69
> >  ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 55
> >  insertions(+), 14 deletions(-)
> > 
> > diff --git a/android/bluetooth.c b/android/bluetooth.c
> > index 8c91d87..df442a3 100644
> > --- a/android/bluetooth.c
> > +++ b/android/bluetooth.c
> > @@ -70,6 +70,8 @@
> > 
> >  /* Default discoverable timeout 120sec as in Android */
> >  #define DEFAULT_DISCOVERABLE_TIMEOUT 120
> > 
> > +#define DEVICES_CACHE_MAX 100
> 
> Is this being limited because Android UI cannot handle more than that?
> Or perhaps because our IPC/MTU cannot carry more than that? If the
> latter I believe we can actually calculate the maximun e.g. MTU / pdu
> size.

This is not related to Android UI nor MTU. This is just to limit max resources 
usage. Value is totally arbitrary. If device is not in cache some HAL 
functions might fail (notably set/get device property).

-- 
Szymon K. Janc
szymon.janc@gmail.com

^ permalink raw reply

* [PATCH 2/2] android/a2dp: Fix freeing preset on SEP close
From: Andrzej Kaczmarek @ 2014-01-14 16:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1389716179-21874-1-git-send-email-andrzej.kaczmarek@tieto.com>

In case SEP was opened from local side, corresponding a2dp_setup
structure has just reference to a2dp_preset which is stored on presets
list. As a result, when closing SEP such preset will be freed leaving
dangling pointer on presets list.

This patch duplicates a2dp_preset in such case so it can be freed
safely.
---
 android/a2dp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/android/a2dp.c b/android/a2dp.c
index 145cd67..63629a0 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -266,6 +266,7 @@ static int select_configuration(struct a2dp_device *dev,
 				struct avdtp_remote_sep *rsep)
 {
 	struct a2dp_preset *preset;
+	struct a2dp_preset *preset_dup;
 	struct avdtp_stream *stream;
 	struct avdtp_service_capability *service;
 	struct avdtp_media_codec_capability *codec;
@@ -298,7 +299,11 @@ static int select_configuration(struct a2dp_device *dev,
 		return err;
 	}
 
-	setup_add(dev, endpoint, preset, stream);
+	preset_dup = g_new0(struct a2dp_preset, 1);
+	preset_dup->len = preset->len;
+	preset_dup->data = g_memdup(preset->data, preset->len);
+
+	setup_add(dev, endpoint, preset_dup, stream);
 
 	return 0;
 }
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH 1/2] android/a2dp: Fix IPC response length calculation
From: Andrzej Kaczmarek @ 2014-01-14 16:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek

struct audio_rsp_open_stream has only zero-length array member thus its
size equals to 0. We need to explicitly specify size of array element
type here.
---
 android/a2dp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/android/a2dp.c b/android/a2dp.c
index 9f3164a..145cd67 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -1088,8 +1088,8 @@ static void bt_stream_open(const void *buf, uint16_t len)
 		return;
 	}
 
-	len = sizeof(*rsp) + setup->preset->len;
-	rsp = g_malloc0(sizeof(*rsp) + setup->preset->len);
+	len = sizeof(struct audio_preset) + setup->preset->len;
+	rsp = g_malloc0(len);
 	rsp->preset->len = setup->preset->len;
 	memcpy(rsp->preset->data, setup->preset->data, setup->preset->len);
 
-- 
1.8.5.2


^ permalink raw reply related

* Re: [RFC 4/5] android/bluetooth: Add support for caching remote device info
From: Luiz Augusto von Dentz @ 2014-01-14 15:49 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1389697905-18532-5-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Tue, Jan 14, 2014 at 1:11 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> Cache is limited to DEVICES_CACHE_MAX. Devices are sorted with
> timestamp so if cache is full olderst device is removed.
> ---
>  android/bluetooth.c | 69 ++++++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 55 insertions(+), 14 deletions(-)
>
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 8c91d87..df442a3 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -70,6 +70,8 @@
>  /* Default discoverable timeout 120sec as in Android */
>  #define DEFAULT_DISCOVERABLE_TIMEOUT 120
>
> +#define DEVICES_CACHE_MAX 100

Is this being limited because Android UI cannot handle more than that?
Or perhaps because our IPC/MTU cannot carry more than that? If the
latter I believe we can actually calculate the maximun e.g. MTU / pdu
size.

^ permalink raw reply

* Re: [RFC 1/5] android/bluetooth: Split devices list to devices and bonded_devices
From: Luiz Augusto von Dentz @ 2014-01-14 15:42 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org, Szymon Janc
In-Reply-To: <1389697905-18532-2-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Tue, Jan 14, 2014 at 1:11 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> From: Szymon Janc <szymon.janc@gmail.com>
>
> Bonded devices are permament until unbondedn. Non-bonded devices will
> be held in (size limited) cache based on timestamp property so split
> list to ease separation.
> ---
>  android/bluetooth.c | 47 +++++++++++++++++++++++++++++++++++------------
>  1 file changed, 35 insertions(+), 12 deletions(-)
>
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index 735b03e..78e98c1 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -133,6 +133,8 @@ static const uint16_t uuid_list[] = {
>  };
>
>  static struct mgmt *mgmt_if = NULL;
> +
> +static GSList *bonded_devices = NULL;
>  static GSList *devices = NULL;
>
>  /* This list contains addresses which are asked for records */
> @@ -284,6 +286,10 @@ static struct device *find_device(const bdaddr_t *bdaddr)
>  {
>         GSList *l;
>
> +       l = g_slist_find_custom(bonded_devices, bdaddr, device_match);
> +       if (l)
> +               return l->data;
> +
>         l = g_slist_find_custom(devices, bdaddr, device_match);
>         if (l)
>                 return l->data;
> @@ -560,12 +566,30 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status,
>         if (!dev)
>                 return;
>
> -       if (dev->bond_state != state) {
> -               dev->bond_state = state;
> -               send_bond_state_change(&dev->bdaddr, status, state);
> +       if (dev->bond_state == state)
> +               return;
>
> -               store_device_info(dev);
> +       switch (state) {
> +       case HAL_BOND_STATE_NONE:
> +               if (dev->bond_state == HAL_BOND_STATE_BONDED) {
> +                       bonded_devices = g_slist_remove(bonded_devices, dev);
> +                       devices = g_slist_prepend(devices, dev);
> +               }
> +               break;
> +       case HAL_BOND_STATE_BONDED:
> +               devices = g_slist_remove(devices, dev);
> +               bonded_devices = g_slist_prepend(bonded_devices, dev);
> +               break;
> +       case HAL_BOND_STATE_BONDING:
> +       default:
> +               break;
>         }
> +
> +       dev->bond_state = state;
> +
> +       store_device_info(dev);
> +
> +       send_bond_state_change(&dev->bdaddr, status, state);
>  }
>
>  static  void send_device_property(const bdaddr_t *bdaddr, uint8_t type,
> @@ -2134,18 +2158,15 @@ static uint8_t get_adapter_scan_mode(void)
>
>  static uint8_t get_adapter_bonded_devices(void)
>  {
> -       uint8_t buf[sizeof(bdaddr_t) * g_slist_length(devices)];
> +       uint8_t buf[sizeof(bdaddr_t) * g_slist_length(bonded_devices)];
>         int i = 0;
>         GSList *l;
>
>         DBG("");
>
> -       for (l = devices; l; l = g_slist_next(l)) {
> +       for (l = bonded_devices; l; l = g_slist_next(l)) {
>                 struct device *dev = l->data;
>
> -               if (dev->bond_state != HAL_BOND_STATE_BONDED)
> -                       continue;
> -
>                 bdaddr2android(&dev->bdaddr, buf + (i * sizeof(bdaddr_t)));
>                 i++;
>         }
> @@ -2697,11 +2718,10 @@ static void send_bonded_devices_props(void)
>  {
>         GSList *l;
>
> -       for (l = devices; l; l = g_slist_next(l)) {
> +       for (l = bonded_devices; l; l = g_slist_next(l)) {
>                 struct device *dev = l->data;
>
> -               if (dev->bond_state == HAL_BOND_STATE_BONDED)
> -                       get_remote_device_props(dev);
> +               get_remote_device_props(dev);
>         }
>  }
>
> @@ -3099,6 +3119,9 @@ void bt_bluetooth_unregister(void)
>  {
>         DBG("");
>
> +       g_slist_free_full(bonded_devices, (GDestroyNotify) free_device);
> +       bonded_devices = NULL;
> +
>         g_slist_free_full(devices, (GDestroyNotify) free_device);

You can make free_device to take a void pointer so you don't have to
cast in such cases.



-- 
Luiz Augusto von Dentz

^ permalink raw reply

* [RFC 4/4] android: Update README with init.rc updates
From: Szymon Janc @ 2014-01-14 15:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1389713283-13038-1-git-send-email-szymon.janc@tieto.com>

---
 android/README | 32 +++++++-------------------------
 1 file changed, 7 insertions(+), 25 deletions(-)

diff --git a/android/README b/android/README
index 717ffa2..24ed703 100644
--- a/android/README
+++ b/android/README
@@ -36,31 +36,13 @@ Runtime requirements
 ====================
 
 BlueZ HAL library requires 'bluetoothd' and 'bluetoothd-snoop' services to be
-available on Android system. This can be done by defining following services in
-init.rc file of targeted board:
-
-service bluetoothd /system/bin/logwrapper /system/bin/bluetoothd
-  class main
-  group bluetooth net_admin
-  disabled
-  oneshot
-
-service bluetoothd-snoop /system/bin/bluetoothd-snoop
-  class main
-  group bluetooth net_admin
-  disabled
-  oneshot
-
-It is required that bluetooth user could start and stop bluetoothd and
-bluetoothd-snoop services by setting 'ctl.start' or 'ctl.stop' property. This
-can be achieved by whitelisting bluetooth user and bluetoothd and
-bluetoothd-snoop services in init source code.
-
-Required Android init system modifications can be found at
-https://code.google.com/p/aosp-bluez.platform-system-core/
-
-Some configuration changes like setting permissions, starting hciattach
-services etc. are device specific. For convenience examples are provided at:
+available on Android system. Some permissions settings are also required.
+
+This can be done by importing init.bluetooth.rc file in init.rc file of targeted
+board:
+import init.bluetooth.rc
+
+For convenience examples are provided at:
 https://code.google.com/p/aosp-bluez.device-lge-mako/    (Nexus 4)
 https://code.google.com/p/aosp-bluez.device-asus-flo/    (Nexus 7 2013)
 
-- 
1.8.3.2


^ permalink raw reply related

* [RFC 3/4] android/system-emulator: Update property used for start/stop services
From: Szymon Janc @ 2014-01-14 15:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1389713283-13038-1-git-send-email-szymon.janc@tieto.com>

---
 android/system-emulator.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/android/system-emulator.c b/android/system-emulator.c
index f1c6622..0966a02 100644
--- a/android/system-emulator.c
+++ b/android/system-emulator.c
@@ -139,17 +139,17 @@ static void system_socket_callback(int fd, uint32_t events, void *user_data)
 
 	printf("Received %s\n", buf);
 
-	if (!strcmp(buf, "ctl.start=bluetoothd")) {
+	if (!strcmp(buf, "bluetooth.start=bluetoothd")) {
 		if (daemon_pid > 0)
 			return;
 
 		ctl_start();
-	} else if (!strcmp(buf, "ctl.start=bluetoothd-snoop")) {
+	} else if (!strcmp(buf, "bluetooth.start=bluetoothd-snoop")) {
 		if (snoop_pid > 0)
 			return;
 
 		snoop_start();
-	} else if (!strcmp(buf, "ctl.stop=bluetoothd-snoop")) {
+	} else if (!strcmp(buf, "bluetooth.stop=bluetoothd-snoop")) {
 		if (snoop_pid > 0)
 			snoop_stop();
 	}
-- 
1.8.3.2


^ permalink raw reply related

* [RFC 2/4] android/hal: Update property used for start/stop services
From: Szymon Janc @ 2014-01-14 15:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1389713283-13038-1-git-send-email-szymon.janc@tieto.com>

---
 android/hal-bluetooth.c | 4 ++--
 android/hal-ipc.c       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index be45836..76560da 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -822,12 +822,12 @@ static int config_hci_snoop_log(uint8_t enable)
 {
 	DBG("enable %u", enable);
 
-	if (enable && property_set("ctl.start", SNOOP_SERVICE_NAME) < 0) {
+	if (enable && property_set("bluetooth.start", SNOOP_SERVICE_NAME) < 0) {
 		error("Failed to start service %s", SNOOP_SERVICE_NAME);
 		return BT_STATUS_FAIL;
 	}
 
-	if (!enable && property_set("ctl.stop", SNOOP_SERVICE_NAME) < 0) {
+	if (!enable && property_set("bluetooth.stop", SNOOP_SERVICE_NAME) < 0) {
 		error("Failed to stop service %s", SNOOP_SERVICE_NAME);
 		return BT_STATUS_FAIL;
 	}
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 97f1bcd..56165df 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -259,7 +259,7 @@ bool hal_ipc_init(void)
 	}
 
 	/* Start Android Bluetooth daemon service */
-	if (property_set("ctl.start", SERVICE_NAME) < 0) {
+	if (property_set("bluetooth.start", SERVICE_NAME) < 0) {
 		error("Failed to start service %s", SERVICE_NAME);
 		close(sk);
 		return false;
-- 
1.8.3.2


^ permalink raw reply related

* [RFC 1/4] android: Add sample init.bluetooth.rc file
From: Szymon Janc @ 2014-01-14 15:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This file is intended to be included from device init.rc.
---
 android/Android.mk        | 16 +++++++++++++++-
 android/Makefile.am       |  1 +
 android/init.bluetooth.rc | 27 +++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 android/init.bluetooth.rc

diff --git a/android/Android.mk b/android/Android.mk
index ae52ab4..f13e703 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -109,7 +109,7 @@ LOCAL_MODULE := bluetooth.default
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
-LOCAL_REQUIRED_MODULES := bluetoothd bluetoothd-snoop
+LOCAL_REQUIRED_MODULES := bluetoothd bluetoothd-snoop init.bluetooth.rc
 
 include $(BUILD_SHARED_LIBRARY)
 
@@ -263,3 +263,17 @@ LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := bluetoothd-snoop
 
 include $(BUILD_EXECUTABLE)
+
+#
+# init.bleutooth.rc
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := init.bluetooth.rc
+LOCAL_MODULE_CLASS := ETC
+LOCAL_SRC_FILES := $(LOCAL_MODULE)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
+
+include $(BUILD_PREBUILT)
diff --git a/android/Makefile.am b/android/Makefile.am
index 7806f79..b205019 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -134,6 +134,7 @@ android_audio_a2dp_default_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \
 endif
 
 EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
+		android/init.bluetooth.rc \
 		android/pics-gap.txt android/pics-hid.txt \
 		android/pics-pan.txt android/pics-did.txt \
 		android/pics-opp.txt android/pics-pbap.txt \
diff --git a/android/init.bluetooth.rc b/android/init.bluetooth.rc
new file mode 100644
index 0000000..e2be9e8
--- /dev/null
+++ b/android/init.bluetooth.rc
@@ -0,0 +1,27 @@
+chown bluetooth bluetooth /data/misc/bluetooth
+
+chown bluetooth bluetooth /dev/uhid
+
+on property:bluetooth.start=bluetoothd
+    start bluetoothd
+
+on property:bluetooth.stop=bluetoothd
+    stop bluetoothd
+
+on property:bluetooth.start=bluetoothd-snoop
+    start bluetoothd-snoop
+
+on property:bluetooth.stop=bluetoothd-snoop
+    stop bluetoothd-snoop
+
+service bluetoothd /system/bin/logwrapper /system/bin/bluetoothd
+    class main
+    group bluetooth net_admin
+    disabled
+    oneshot
+
+service bluetoothd-snoop /system/bin/bluetoothd-snoop
+    class main
+    group bluetooth net_admin
+    disabled
+    oneshot
-- 
1.8.3.2


^ permalink raw reply related

* [PATCH v2 15/15] android/tester: Add get device FRIENDLY_NAME prop fail test case
From: Grzegorz Kolodziejczyk @ 2014-01-14 13:54 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1389707686-30766-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

This adds device FRIENDLY NAME property fail test case.
---
 android/android-tester.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 94b00dd..7640eea 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -1568,6 +1568,25 @@ static const struct generic_data bt_dev_getprop_verinfo_fail_test = {
 	.expected_adapter_status = BT_STATUS_FAIL,
 };
 
+static struct priority_property remote_getprop_fname_props[] = {
+	{
+	.prop.type = BT_PROPERTY_REMOTE_VERSION_INFO,
+	.prop.val = NULL,
+	.prop.len = 0,
+	},
+};
+
+static const struct generic_data bt_dev_getprop_fname_fail_test = {
+	.expected_hal_cb.discovery_state_changed_cb =
+					remote_discovery_state_changed_cb,
+	.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
+	.expected_hal_cb.remote_device_properties_cb =
+					remote_test_device_properties_cb,
+	.expected_cb_count = 3,
+	.expected_properties = remote_getprop_fname_props,
+	.expected_adapter_status = BT_STATUS_FAIL,
+};
+
 static bt_callbacks_t bt_callbacks = {
 	.size = sizeof(bt_callbacks),
 	.adapter_state_changed_cb = adapter_state_changed_cb,
@@ -2198,6 +2217,15 @@ static void test_dev_getprop_verinfo_fail(const void *test_data)
 	data->if_bluetooth->start_discovery();
 }
 
+static void test_dev_getprop_fname_fail(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	init_test_conditions(data);
+
+	data->if_bluetooth->start_discovery();
+}
+
 /* Test Socket HAL */
 
 static void adapter_socket_state_changed_cb(bt_state_t state)
@@ -2864,6 +2892,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_dev_getprop_verinfo_fail, teardown);
 
+	test_bredrle("Bluetooth Device Get FRIENDLY_NAME - Fail",
+					&bt_dev_getprop_fname_fail_test,
+					setup_enabled_adapter,
+					test_dev_getprop_fname_fail, teardown);
+
 	test_bredrle("Socket Init", NULL, setup_socket_interface,
 						test_dummy, teardown);
 
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH v2 14/15] android/tester: Add get device VERINFO property fail test case
From: Grzegorz Kolodziejczyk @ 2014-01-14 13:54 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1389707686-30766-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

This adds device VERSION INFO property fail test case.
---
 android/android-tester.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 89566d4..94b00dd 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -1549,6 +1549,25 @@ static const struct generic_data bt_dev_getprop_disctimeout_fail_test = {
 	.expected_adapter_status = BT_STATUS_FAIL,
 };
 
+static struct priority_property remote_getprop_verinfo_props[] = {
+	{
+	.prop.type = BT_PROPERTY_REMOTE_VERSION_INFO,
+	.prop.val = NULL,
+	.prop.len = 0,
+	},
+};
+
+static const struct generic_data bt_dev_getprop_verinfo_fail_test = {
+	.expected_hal_cb.discovery_state_changed_cb =
+					remote_discovery_state_changed_cb,
+	.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
+	.expected_hal_cb.remote_device_properties_cb =
+					remote_test_device_properties_cb,
+	.expected_cb_count = 3,
+	.expected_properties = remote_getprop_verinfo_props,
+	.expected_adapter_status = BT_STATUS_FAIL,
+};
+
 static bt_callbacks_t bt_callbacks = {
 	.size = sizeof(bt_callbacks),
 	.adapter_state_changed_cb = adapter_state_changed_cb,
@@ -2170,6 +2189,15 @@ static void test_dev_getprop_disctimeout_fail(const void *test_data)
 	data->if_bluetooth->start_discovery();
 }
 
+static void test_dev_getprop_verinfo_fail(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	init_test_conditions(data);
+
+	data->if_bluetooth->start_discovery();
+}
+
 /* Test Socket HAL */
 
 static void adapter_socket_state_changed_cb(bt_state_t state)
@@ -2831,6 +2859,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_dev_getprop_disctimeout_fail, teardown);
 
+	test_bredrle("Bluetooth Device Get VERSION_INFO - Fail",
+				&bt_dev_getprop_verinfo_fail_test,
+				setup_enabled_adapter,
+				test_dev_getprop_verinfo_fail, teardown);
+
 	test_bredrle("Socket Init", NULL, setup_socket_interface,
 						test_dummy, teardown);
 
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH v2 13/15] android/tester: Add get device DISCTIMEOUT prop fail test case
From: Grzegorz Kolodziejczyk @ 2014-01-14 13:54 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1389707686-30766-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

This adds device DISCOVERY TIMEOUT property fail test case.
---
 android/android-tester.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 2192cc4..89566d4 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -1528,6 +1528,27 @@ static const struct generic_data bt_dev_getprop_bondeddev_fail_test = {
 	.expected_adapter_status = BT_STATUS_FAIL,
 };
 
+static uint32_t remote_getprop_disctimeout_val = 120;
+
+static struct priority_property remote_getprop_disctimeout_props[] = {
+	{
+	.prop.type = BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
+	.prop.val = &remote_getprop_disctimeout_val,
+	.prop.len = sizeof(remote_getprop_disctimeout_val),
+	},
+};
+
+static const struct generic_data bt_dev_getprop_disctimeout_fail_test = {
+	.expected_hal_cb.discovery_state_changed_cb =
+					remote_discovery_state_changed_cb,
+	.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
+	.expected_hal_cb.remote_device_properties_cb =
+					remote_test_device_properties_cb,
+	.expected_cb_count = 3,
+	.expected_properties = remote_getprop_disctimeout_props,
+	.expected_adapter_status = BT_STATUS_FAIL,
+};
+
 static bt_callbacks_t bt_callbacks = {
 	.size = sizeof(bt_callbacks),
 	.adapter_state_changed_cb = adapter_state_changed_cb,
@@ -2140,6 +2161,15 @@ static void test_dev_getprop_bondeddev_fail(const void *test_data)
 	data->if_bluetooth->start_discovery();
 }
 
+static void test_dev_getprop_disctimeout_fail(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	init_test_conditions(data);
+
+	data->if_bluetooth->start_discovery();
+}
+
 /* Test Socket HAL */
 
 static void adapter_socket_state_changed_cb(bt_state_t state)
@@ -2796,6 +2826,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_dev_getprop_bondeddev_fail, teardown);
 
+	test_bredrle("Bluetooth Device Get DISCOVERY_TIMEOUT - Fail",
+				&bt_dev_getprop_disctimeout_fail_test,
+				setup_enabled_adapter,
+				test_dev_getprop_disctimeout_fail, teardown);
+
 	test_bredrle("Socket Init", NULL, setup_socket_interface,
 						test_dummy, teardown);
 
-- 
1.8.5.2


^ permalink raw reply related

* [PATCH v2 12/15] android/tester: Add get device BONDED_DEV property fail test case
From: Grzegorz Kolodziejczyk @ 2014-01-14 13:54 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1389707686-30766-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>

This adds device BONDED DEVICES property fail test case.
---
 android/android-tester.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index a9f57e5..2192cc4 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -1509,6 +1509,25 @@ static const struct generic_data bt_dev_getprop_scanmode_fail_test = {
 	.expected_adapter_status = BT_STATUS_FAIL,
 };
 
+static struct priority_property remote_getprop_bondeddev_props[] = {
+	{
+	.prop.type = BT_PROPERTY_ADAPTER_BONDED_DEVICES,
+	.prop.val = NULL,
+	.prop.len = 0,
+	},
+};
+
+static const struct generic_data bt_dev_getprop_bondeddev_fail_test = {
+	.expected_hal_cb.discovery_state_changed_cb =
+					remote_discovery_state_changed_cb,
+	.expected_hal_cb.device_found_cb = remote_get_property_device_found_cb,
+	.expected_hal_cb.remote_device_properties_cb =
+					remote_test_device_properties_cb,
+	.expected_cb_count = 3,
+	.expected_properties = remote_getprop_bondeddev_props,
+	.expected_adapter_status = BT_STATUS_FAIL,
+};
+
 static bt_callbacks_t bt_callbacks = {
 	.size = sizeof(bt_callbacks),
 	.adapter_state_changed_cb = adapter_state_changed_cb,
@@ -2112,6 +2131,15 @@ static void test_dev_getprop_scanmode_fail(const void *test_data)
 	data->if_bluetooth->start_discovery();
 }
 
+static void test_dev_getprop_bondeddev_fail(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	init_test_conditions(data);
+
+	data->if_bluetooth->start_discovery();
+}
+
 /* Test Socket HAL */
 
 static void adapter_socket_state_changed_cb(bt_state_t state)
@@ -2763,6 +2791,11 @@ int main(int argc, char *argv[])
 				setup_enabled_adapter,
 				test_dev_getprop_scanmode_fail, teardown);
 
+	test_bredrle("Bluetooth Device Get BONDED_DEVICES - Fail",
+				&bt_dev_getprop_bondeddev_fail_test,
+				setup_enabled_adapter,
+				test_dev_getprop_bondeddev_fail, teardown);
+
 	test_bredrle("Socket Init", NULL, setup_socket_interface,
 						test_dummy, teardown);
 
-- 
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