* [PATCH BlueZ 04/10] android/A2DP: Add initial code to handle audio IPC commands
From: Luiz Augusto von Dentz @ 2013-12-31 11:29 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1388489402-8919-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds initial code to handle audio IPC commands.
---
android/a2dp.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/android/a2dp.c b/android/a2dp.c
index 581d094..7550644 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -352,6 +352,9 @@ static sdp_record_t *a2dp_record(void)
return record;
}
+static const struct ipc_handler audio_handlers[] = {
+};
+
bool bt_a2dp_register(const bdaddr_t *addr)
{
GError *err = NULL;
@@ -359,6 +362,8 @@ bool bt_a2dp_register(const bdaddr_t *addr)
DBG("");
+ audio_ipc_init();
+
bacpy(&adapter_addr, addr);
server = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
@@ -388,6 +393,9 @@ bool bt_a2dp_register(const bdaddr_t *addr)
ipc_register(HAL_SERVICE_ID_A2DP, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
+ audio_ipc_register(AUDIO_SERVICE_ID_CORE, audio_handlers,
+ G_N_ELEMENTS(audio_handlers));
+
return true;
fail:
@@ -411,8 +419,9 @@ void bt_a2dp_unregister(void)
g_slist_foreach(devices, a2dp_device_disconnected, NULL);
devices = NULL;
-
ipc_unregister(HAL_SERVICE_ID_A2DP);
+ audio_ipc_unregister(AUDIO_SERVICE_ID_CORE);
+
bt_adapter_remove_record(record_id);
record_id = 0;
@@ -421,4 +430,6 @@ void bt_a2dp_unregister(void)
g_io_channel_unref(server);
server = NULL;
}
+
+ audio_ipc_cleanup();
}
--
1.8.4.2
^ permalink raw reply related
* [PATCH BlueZ 03/10] android/ipc: Add audio_ipc_send_rsp and audio_ipc_send_rsp_full
From: Luiz Augusto von Dentz @ 2013-12-31 11:29 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1388489402-8919-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
These functions can be used to respond to commands recieved over audio
IPC.
---
android/ipc.c | 24 ++++++++++++++++++++++++
android/ipc.h | 4 ++++
2 files changed, 28 insertions(+)
diff --git a/android/ipc.c b/android/ipc.c
index 751284f..d6cb126 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -381,6 +381,30 @@ void audio_ipc_cleanup(void)
}
}
+void audio_ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status)
+{
+ struct hal_status s;
+ int sk;
+
+ sk = g_io_channel_unix_get_fd(audio_io);
+
+ if (status == HAL_STATUS_SUCCESS) {
+ ipc_send(sk, service_id, opcode, 0, NULL, -1);
+ return;
+ }
+
+ s.code = status;
+
+ ipc_send(sk, service_id, HAL_OP_STATUS, sizeof(s), &s, -1);
+}
+
+void audio_ipc_send_rsp_full(uint8_t service_id, uint8_t opcode, uint16_t len,
+ void *param, int fd)
+{
+ ipc_send(g_io_channel_unix_get_fd(audio_io), service_id, opcode, len,
+ param, fd);
+}
+
void audio_ipc_register(uint8_t service, const struct ipc_handler *handlers,
uint8_t size)
{
diff --git a/android/ipc.h b/android/ipc.h
index 44d5a5d..f224367 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -41,6 +41,10 @@ void ipc_unregister(uint8_t service);
void audio_ipc_init(void);
void audio_ipc_cleanup(void);
+void audio_ipc_send_rsp(uint8_t service_id, uint8_t opcode, uint8_t status);
+void audio_ipc_send_rsp_full(uint8_t service_id, uint8_t opcode, uint16_t len,
+ void *param, int fd);
+
void audio_ipc_register(uint8_t service, const struct ipc_handler *handlers,
uint8_t size);
void audio_ipc_unregister(uint8_t service);
--
1.8.4.2
^ permalink raw reply related
* [PATCH BlueZ 02/10] android/ipc: Add audio_ipc_register and audio_ipc_unregister
From: Luiz Augusto von Dentz @ 2013-12-31 11:29 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1388489402-8919-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
These function can be used to register command handlers for audio IPC.
---
android/hal-msg.h | 4 ++++
android/ipc.c | 14 ++++++++++++++
android/ipc.h | 4 ++++
3 files changed, 22 insertions(+)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index b14eced..267f9b2 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -48,6 +48,10 @@ struct hal_hdr {
#define HAL_SERVICE_ID_MAX HAL_SERVICE_ID_GATT
+#define AUDIO_SERVICE_ID_CORE 0
+
+#define AUDIO_SERVICE_ID_MAX AUDIO_SERVICE_ID_CORE
+
/* Core Service */
#define HAL_STATUS_SUCCESS 0x00
diff --git a/android/ipc.c b/android/ipc.c
index d062d95..751284f 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -46,6 +46,7 @@ struct service_handler {
};
static struct service_handler services[HAL_SERVICE_ID_MAX + 1];
+static struct service_handler audio_services[AUDIO_SERVICE_ID_MAX + 1];
static GIOChannel *cmd_io = NULL;
static GIOChannel *notif_io = NULL;
@@ -379,3 +380,16 @@ void audio_ipc_cleanup(void)
audio_io = NULL;
}
}
+
+void audio_ipc_register(uint8_t service, const struct ipc_handler *handlers,
+ uint8_t size)
+{
+ audio_services[service].handler = handlers;
+ audio_services[service].size = size;
+}
+
+void audio_ipc_unregister(uint8_t service)
+{
+ audio_services[service].handler = NULL;
+ audio_services[service].size = 0;
+}
diff --git a/android/ipc.h b/android/ipc.h
index 8e92811..44d5a5d 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -40,3 +40,7 @@ void ipc_unregister(uint8_t service);
void audio_ipc_init(void);
void audio_ipc_cleanup(void);
+
+void audio_ipc_register(uint8_t service, const struct ipc_handler *handlers,
+ uint8_t size);
+void audio_ipc_unregister(uint8_t service);
--
1.8.4.2
^ permalink raw reply related
* [PATCH BlueZ 01/10] android/ipc: Add initial code for audio IPC
From: Luiz Augusto von Dentz @ 2013-12-31 11:29 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This add initial code for listen and accept connections on the abstract
socket defined for the audio IPC.
---
android/hal-msg.h | 1 +
android/ipc.c | 65 +++++++++++++++++++++++++++++++++++++++++++++----------
android/ipc.h | 3 +++
3 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index c351501..b14eced 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -24,6 +24,7 @@
#define BLUEZ_HAL_MTU 1024
static const char BLUEZ_HAL_SK_PATH[] = "\0bluez_hal_socket";
+static const char BLUEZ_AUDIO_SK_PATH[] = "\0bluez_audio_socket";
struct hal_hdr {
uint8_t service_id;
diff --git a/android/ipc.c b/android/ipc.c
index 9e8ccc3..d062d95 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -49,8 +49,10 @@ static struct service_handler services[HAL_SERVICE_ID_MAX + 1];
static GIOChannel *cmd_io = NULL;
static GIOChannel *notif_io = NULL;
+static GIOChannel *audio_io = NULL;
-static void ipc_handle_msg(const void *buf, ssize_t len)
+static void ipc_handle_msg(struct service_handler *handlers, const void *buf,
+ ssize_t len)
{
const struct hal_hdr *msg = buf;
const struct ipc_handler *handler;
@@ -76,7 +78,7 @@ static void ipc_handle_msg(const void *buf, ssize_t len)
}
/* if service is registered */
- if (!services[msg->service_id].handler) {
+ if (!handlers[msg->service_id].handler) {
error("IPC: unregistered service (0x%x), terminating",
msg->service_id);
raise(SIGTERM);
@@ -85,7 +87,7 @@ static void ipc_handle_msg(const void *buf, ssize_t len)
/* if opcode is valid */
if (msg->opcode == HAL_OP_STATUS ||
- msg->opcode > services[msg->service_id].size) {
+ msg->opcode > handlers[msg->service_id].size) {
error("IPC: invalid opcode 0x%x for service 0x%x, terminating",
msg->opcode, msg->service_id);
raise(SIGTERM);
@@ -93,7 +95,7 @@ static void ipc_handle_msg(const void *buf, ssize_t len)
}
/* opcode is table offset + 1 */
- handler = &services[msg->service_id].handler[msg->opcode - 1];
+ handler = &handlers[msg->service_id].handler[msg->opcode - 1];
/* if payload size is valid */
if ((handler->var_len && handler->data_len > msg->len) ||
@@ -110,6 +112,7 @@ static void ipc_handle_msg(const void *buf, ssize_t len)
static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
+ struct service_handler *handlers = user_data;
char buf[BLUEZ_HAL_MTU];
ssize_t ret;
int fd;
@@ -128,7 +131,7 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
goto fail;
}
- ipc_handle_msg(buf, ret);
+ ipc_handle_msg(handlers, buf, ret);
return TRUE;
fail:
@@ -145,7 +148,8 @@ static gboolean notif_watch_cb(GIOChannel *io, GIOCondition cond,
return FALSE;
}
-static GIOChannel *connect_hal(GIOFunc connect_cb)
+static GIOChannel *connect_hal(const char *path, size_t size,
+ GIOFunc connect_cb)
{
struct sockaddr_un addr;
GIOCondition cond;
@@ -167,11 +171,11 @@ static GIOChannel *connect_hal(GIOFunc connect_cb)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- memcpy(addr.sun_path, BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH));
+ memcpy(addr.sun_path, path, size);
if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- error("IPC: failed to connect HAL socket: %d (%s)", errno,
- strerror(errno));
+ error("IPC: failed to connect HAL socket %s: %d (%s)", &path[1],
+ errno, strerror(errno));
g_io_channel_unref(io);
return NULL;
}
@@ -200,7 +204,7 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- g_io_add_watch(cmd_io, cond, cmd_watch_cb, NULL);
+ g_io_add_watch(cmd_io, cond, cmd_watch_cb, services);
info("IPC: successfully connected");
@@ -218,7 +222,8 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
return FALSE;
}
- notif_io = connect_hal(notif_connect_cb);
+ notif_io = connect_hal(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+ notif_connect_cb);
if (!notif_io)
raise(SIGTERM);
@@ -227,7 +232,8 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
void ipc_init(void)
{
- cmd_io = connect_hal(cmd_connect_cb);
+ cmd_io = connect_hal(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH),
+ cmd_connect_cb);
if (!cmd_io)
raise(SIGTERM);
}
@@ -338,3 +344,38 @@ void ipc_unregister(uint8_t service)
services[service].handler = NULL;
services[service].size = 0;
}
+
+static gboolean audio_connect_cb(GIOChannel *io, GIOCondition cond,
+ gpointer user_data)
+{
+ DBG("");
+
+ if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
+ error("Audio IPC: socket connect failed");
+ audio_ipc_cleanup();
+ return FALSE;
+ }
+
+ cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
+
+ g_io_add_watch(audio_io, cond, cmd_watch_cb, NULL);
+
+ info("Audio IPC: successfully connected");
+
+ return FALSE;
+}
+
+void audio_ipc_init(void)
+{
+ audio_io = connect_hal(BLUEZ_AUDIO_SK_PATH, sizeof(BLUEZ_AUDIO_SK_PATH),
+ audio_connect_cb);
+}
+
+void audio_ipc_cleanup(void)
+{
+ if (audio_io) {
+ g_io_channel_shutdown(audio_io, TRUE, NULL);
+ g_io_channel_unref(audio_io);
+ audio_io = NULL;
+ }
+}
diff --git a/android/ipc.h b/android/ipc.h
index 6cd102b..8e92811 100644
--- a/android/ipc.h
+++ b/android/ipc.h
@@ -37,3 +37,6 @@ void ipc_send_notif(uint8_t service_id, uint8_t opcode, uint16_t len,
void ipc_register(uint8_t service, const struct ipc_handler *handlers,
uint8_t size);
void ipc_unregister(uint8_t service);
+
+void audio_ipc_init(void);
+void audio_ipc_cleanup(void);
--
1.8.4.2
^ permalink raw reply related
* [PATCH_v2] android/pan: Add pan sdp record for NAP role
From: Ravi kumar Veeramally @ 2013-12-31 9:59 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
---
android/pan.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/android/pan.c b/android/pan.c
index 689c7ef..a4d8977 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -44,9 +44,12 @@
#include "utils.h"
#include "bluetooth.h"
+#define SVC_HINT_NETWORKING 0x02
+
static bdaddr_t adapter_addr;
GSList *devices = NULL;
uint8_t local_role = HAL_PAN_ROLE_NONE;
+static uint32_t record_id = 0;
struct pan_device {
char iface[16];
@@ -335,20 +338,110 @@ static const struct ipc_handler cmd_handlers[] = {
{ bt_pan_disconnect, false, sizeof(struct hal_cmd_pan_disconnect) },
};
+static sdp_record_t *pan_record(void)
+{
+ sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto;
+ uuid_t root_uuid, pan, l2cap, bnep;
+ sdp_profile_desc_t profile[1];
+ sdp_list_t *proto[2];
+ sdp_data_t *v, *p;
+ uint16_t psm = BNEP_PSM, version = 0x0100;
+ uint16_t security = 0x0001, type = 0xfffe;
+ uint32_t rate = 0;
+ const char *desc = "Network service", *name = "bnep";
+ sdp_record_t *record;
+ uint16_t ptype[] = { 0x0800, /* IPv4 */ 0x0806, /* ARP */ };
+ sdp_data_t *head, *pseq, *data;
+
+ record = sdp_record_alloc();
+ if (!record)
+ return NULL;
+
+ record->attrlist = NULL;
+ record->pattern = NULL;
+
+ sdp_uuid16_create(&pan, NAP_SVCLASS_ID);
+ svclass = sdp_list_append(NULL, &pan);
+ sdp_set_service_classes(record, svclass);
+
+ sdp_uuid16_create(&profile[0].uuid, NAP_PROFILE_ID);
+ profile[0].version = 0x0100;
+ pfseq = sdp_list_append(NULL, &profile[0]);
+ sdp_set_profile_descs(record, pfseq);
+ sdp_set_info_attr(record, name, NULL, desc);
+ sdp_attr_add_new(record, SDP_ATTR_NET_ACCESS_TYPE, SDP_UINT16, &type);
+ sdp_attr_add_new(record, SDP_ATTR_MAX_NET_ACCESSRATE,
+ SDP_UINT32, &rate);
+
+ sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
+ root = sdp_list_append(NULL, &root_uuid);
+ sdp_set_browse_groups(record, root);
+
+ sdp_uuid16_create(&l2cap, L2CAP_UUID);
+ proto[0] = sdp_list_append(NULL, &l2cap);
+ p = sdp_data_alloc(SDP_UINT16, &psm);
+ proto[0] = sdp_list_append(proto[0], p);
+ apseq = sdp_list_append(NULL, proto[0]);
+
+ sdp_uuid16_create(&bnep, BNEP_UUID);
+ proto[1] = sdp_list_append(NULL, &bnep);
+ v = sdp_data_alloc(SDP_UINT16, &version);
+ proto[1] = sdp_list_append(proto[1], v);
+
+ head = sdp_data_alloc(SDP_UINT16, &ptype[0]);
+ data = sdp_data_alloc(SDP_UINT16, &ptype[1]);
+ sdp_seq_append(head, data);
+
+ pseq = sdp_data_alloc(SDP_SEQ16, head);
+ proto[1] = sdp_list_append(proto[1], pseq);
+ apseq = sdp_list_append(apseq, proto[1]);
+ aproto = sdp_list_append(NULL, apseq);
+ sdp_set_access_protos(record, aproto);
+ sdp_add_lang_attr(record);
+ sdp_attr_add_new(record, SDP_ATTR_SECURITY_DESC, SDP_UINT16, &security);
+
+ sdp_data_free(p);
+ sdp_data_free(v);
+ sdp_list_free(apseq, NULL);
+ sdp_list_free(root, NULL);
+ sdp_list_free(aproto, NULL);
+ sdp_list_free(proto[0], NULL);
+ sdp_list_free(proto[1], NULL);
+ sdp_list_free(svclass, NULL);
+ sdp_list_free(pfseq, NULL);
+
+ return record;
+}
+
bool bt_pan_register(const bdaddr_t *addr)
{
+ sdp_record_t *rec;
int err;
DBG("");
bacpy(&adapter_addr, addr);
+ rec = pan_record();
+ if (!rec) {
+ error("Failed to allocate PAN record");
+ return false;
+ }
+
+ if (bt_adapter_add_record(rec, SVC_HINT_NETWORKING) < 0) {
+ error("Failed to register PAN record");
+ sdp_record_free(rec);
+ return false;
+ }
+
err = bnep_init();
if (err) {
error("bnep init failed");
+ sdp_record_free(rec);
return false;
}
+ record_id = rec->handle;
ipc_register(HAL_SERVICE_ID_PAN, cmd_handlers,
G_N_ELEMENTS(cmd_handlers));
@@ -362,4 +455,6 @@ void bt_pan_unregister(void)
bnep_cleanup();
ipc_unregister(HAL_SERVICE_ID_PAN);
+ bt_adapter_remove_record(record_id);
+ record_id = 0;
}
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH 1/4] android/hidhost: Move get_protocol parameter check to daemon
From: Johan Hedberg @ 2013-12-31 9:35 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1388444180-13683-1-git-send-email-szymon.janc@gmail.com>
Hi Szymon,
On Mon, Dec 30, 2013, Szymon Janc wrote:
> HAL library is to be as simple as possible and parameters values should
> be verified by daemon for robustness anyway. Move this check to daemon.
> ---
> android/hal-hidhost.c | 12 ++----------
> android/hidhost.c | 9 +++++++++
> 2 files changed, 11 insertions(+), 10 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply
* Re: [RFC 6/6] android/audio: Add listener thread on the Audio HAL socket
From: Luiz Augusto von Dentz @ 2013-12-31 9:08 UTC (permalink / raw)
To: Lukasz Rymanowski
Cc: Lukasz Rymanowski, linux-bluetooth@vger.kernel.org, Johan Hedberg
In-Reply-To: <CAN_7+YZs8y-+xcYtJu39MToF5oMu9XGvFfCGCGgacA4doOVM2g@mail.gmail.com>
Hi Lukazs,
On Mon, Dec 30, 2013 at 10:57 PM, Lukasz Rymanowski
<lukasz.rymanowski@gmail.com> wrote:
> Hi Luiz,
>
> On Mon, Dec 30, 2013 at 2:07 PM, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
>> Hi Lukasz,
>>
>> On Mon, Dec 30, 2013 at 1:40 PM, Lukasz Rymanowski
>> <lukasz.rymanowski@tieto.com> wrote:
>>> Hi Luiz,
>>>
>>> On 30 December 2013 12:31, Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote:
>>>> Hi Lukasz,
>>>>
>>>> On Mon, Dec 30, 2013 at 12:17 PM, Lukasz Rymanowski
>>>> <lukasz.rymanowski@tieto.com> wrote:
>>>>> This patch add thread which is reponsible for listen on audio HAL
>>>>> socket, register a2dp endpoint(s) and maintain socket.
>>>>> When bluetooth daemon goes down, HAL audio plugin starts to listen on Audio HAL
>>>>> socket again.
>>>>>
>>>>> ---
>>>>> android/Makefile.am | 2 +
>>>>> android/hal-audio.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>>> android/hal-audio.h | 18 +++++++
>>>>> 3 files changed, 165 insertions(+)
>>>>> create mode 100644 android/hal-audio.h
>>>>>
>>>>> diff --git a/android/Makefile.am b/android/Makefile.am
>>>>> index eaf39bd..bd90c13 100644
>>>>> --- a/android/Makefile.am
>>>>> +++ b/android/Makefile.am
>>>>> @@ -112,6 +112,8 @@ android_libaudio_internal_la_SOURCES = android/hal-audio.c \
>>>>>
>>>>> android_libaudio_internal_la_CFLAGS = -I$(srcdir)/android
>>>>>
>>>>> +android_libaudio_internal_la_LDFLAGS = -pthread
>>>>> +
>>>>> endif
>>>>>
>>>>> EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
>>>>> diff --git a/android/hal-audio.c b/android/hal-audio.c
>>>>> index 011a699..0e3bc70 100644
>>>>> --- a/android/hal-audio.c
>>>>> +++ b/android/hal-audio.c
>>>>> @@ -16,18 +16,30 @@
>>>>> */
>>>>>
>>>>> #include <errno.h>
>>>>> +#include <pthread.h>
>>>>> +#include <poll.h>
>>>>> #include <stdio.h>
>>>>> #include <stdlib.h>
>>>>> #include <string.h>
>>>>> +#include <sys/socket.h>
>>>>> +#include <sys/un.h>
>>>>> +#include <unistd.h>
>>>>>
>>>>> #include <hardware/audio.h>
>>>>> #include <hardware/hardware.h>
>>>>>
>>>>> +#include "hal-audio.h"
>>>>> #include "hal-log.h"
>>>>>
>>>>> struct a2dp_audio_dev {
>>>>> struct audio_hw_device dev;
>>>>> struct a2dp_stream_out *stream_out;
>>>>> +
>>>>> + pthread_t bt_watcher;
>>>>> + pthread_mutex_t hal_sk_mutex;
>>>>> + pthread_cond_t bt_watcher_cond;
>>>>> +
>>>>> + int hal_sk;
>>>>> };
>>>>>
>>>>> struct a2dp_stream_out {
>>>>> @@ -384,15 +396,135 @@ static int audio_dump(const audio_hw_device_t *device, int fd)
>>>>>
>>>>> static int audio_close(hw_device_t *device)
>>>>> {
>>>>> + struct audio_hw_device *dev = (struct audio_hw_device *)device;
>>>>> + struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *)dev;
>>>>> +
>>
>> Hmm, Im afraid these are not the same pointers as you do *device =
>> &a2dp_dev->dev.common; so this will probably cause invalid accesses.
>>
> Actually this is same pointer and even I could do here direct cast
> from hw_device_t to a2dp_audio_dev with some comment why I can do it.
> Is that fine?
> Also in audio_open(), to make code less confusing, will do *device =
> (hw_device_t *)a2dp_dev
> Is that fine for you? Not sure how discussion ends or IRC about that
> as I had to go.
It seems the biggest problem with this type of usage of casts is
binary compatibility, but this is a general problem in Android we
can't do anything about and for BlueZ it shouldn't matter that much
since the code should always be available it is just a matter of
recompiling.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH v2] Bluetooth: Add hci_h4p driver
From: Sebastian Reichel @ 2013-12-30 23:42 UTC (permalink / raw)
To: Pali Rohár, Marcel Holtmann,
Ивайло Димитров,
Gustavo F. Padovan, Johan Hedberg, Pavel Machek, linux-kernel,
linux-bluetooth@vger.kernel.org development
In-Reply-To: <20131230145250.GA16904@earth.universe>
[-- Attachment #1: Type: text/plain, Size: 617 bytes --]
Hi again,
On Mon, Dec 30, 2013 at 03:52:51PM +0100, Sebastian Reichel wrote:
> On Mon, Dec 30, 2013 at 03:31:25PM +0100, Pali Rohár wrote:
> > [...] I think that correct commit message is not needed now.
> Wolfram Sang gave a talk about that at 30C3 yesterday. Official
> recordings of his talk are not yet ready, but the live stream
> has been recorded and uploaded to youtube: [...]
The official recording is now available from here:
http://media.ccc.de/browse/congress/2013/30C3_-_5446_-_en_-_saal_g_-_201312282200_-_the_good_the_bad_and_the_ugly_-_linux_kernel_patches_-_wsa.html
-- Sebastian
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply
* [PATCH 4/4] android/hidhost: Move set_report parameter check to daemon
From: Szymon Janc @ 2013-12-30 22:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388444180-13683-1-git-send-email-szymon.janc@gmail.com>
HAL library is to be as simple as possible and parameters values should
be verified by daemon for robustness anyway. Move this check to daemon.
---
android/hal-hidhost.c | 15 ++-------------
android/hidhost.c | 10 ++++++++++
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 371250a..fd3ad2d 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -294,19 +294,8 @@ static bt_status_t set_report(bt_bdaddr_t *bd_addr,
cmd->len = strlen(report);
memcpy(cmd->data, report, cmd->len);
- switch (report_type) {
- case BTHH_INPUT_REPORT:
- cmd->type = HAL_HIDHOST_INPUT_REPORT;
- break;
- case BTHH_OUTPUT_REPORT:
- cmd->type = HAL_HIDHOST_OUTPUT_REPORT;
- break;
- case BTHH_FEATURE_REPORT:
- cmd->type = HAL_HIDHOST_FEATURE_REPORT;
- break;
- default:
- return BT_STATUS_PARM_INVALID;
- }
+ /* type match IPC type */
+ cmd->type = report_type;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
sizeof(*cmd) + cmd->len, buf, 0, NULL, NULL);
diff --git a/android/hidhost.c b/android/hidhost.c
index 1cf85b1..aed9899 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -1064,6 +1064,16 @@ static void bt_hid_set_report(const void *buf, uint16_t len)
return;
}
+ switch (cmd->type) {
+ case HAL_HIDHOST_INPUT_REPORT:
+ case HAL_HIDHOST_OUTPUT_REPORT:
+ case HAL_HIDHOST_FEATURE_REPORT:
+ break;
+ default:
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
+
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
--
1.8.5.2
^ permalink raw reply related
* [PATCH 3/4] android/hidhost: Move get_report parameter check to daemon
From: Szymon Janc @ 2013-12-30 22:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388444180-13683-1-git-send-email-szymon.janc@gmail.com>
HAL library is to be as simple as possible and parameters values should
be verified by daemon for robustness anyway. Move this check to daemon.
---
android/hal-hidhost.c | 15 ++-------------
android/hidhost.c | 10 ++++++++++
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index b331145..371250a 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -268,19 +268,8 @@ static bt_status_t get_report(bt_bdaddr_t *bd_addr,
cmd.id = report_id;
cmd.buf_size = buffer_size;
- switch (report_type) {
- case BTHH_INPUT_REPORT:
- cmd.type = HAL_HIDHOST_INPUT_REPORT;
- break;
- case BTHH_OUTPUT_REPORT:
- cmd.type = HAL_HIDHOST_OUTPUT_REPORT;
- break;
- case BTHH_FEATURE_REPORT:
- cmd.type = HAL_HIDHOST_FEATURE_REPORT;
- break;
- default:
- return BT_STATUS_PARM_INVALID;
- }
+ /* type match IPC type */
+ cmd.type = report_type;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_REPORT,
sizeof(cmd), &cmd, 0, NULL, NULL);
diff --git a/android/hidhost.c b/android/hidhost.c
index 76e65b8..1cf85b1 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -991,6 +991,16 @@ static void bt_hid_get_report(const void *buf, uint16_t len)
DBG("");
+ switch (cmd->type) {
+ case HAL_HIDHOST_INPUT_REPORT:
+ case HAL_HIDHOST_OUTPUT_REPORT:
+ case HAL_HIDHOST_FEATURE_REPORT:
+ break;
+ default:
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
+
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
--
1.8.5.2
^ permalink raw reply related
* [PATCH 2/4] android/hidhost: Move set_protocol parameter check to daemon
From: Szymon Janc @ 2013-12-30 22:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388444180-13683-1-git-send-email-szymon.janc@gmail.com>
HAL library is to be as simple as possible and parameters values should
be verified by daemon for robustness anyway. Move this check to daemon.
---
android/hal-hidhost.c | 12 ++----------
android/hidhost.c | 9 +++++++++
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 5d05f9b..b331145 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -241,16 +241,8 @@ static bt_status_t set_protocol(bt_bdaddr_t *bd_addr,
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
- switch (protocol_mode) {
- case BTHH_REPORT_MODE:
- cmd.mode = HAL_HIDHOST_REPORT_PROTOCOL;
- break;
- case BTHH_BOOT_MODE:
- cmd.mode = HAL_HIDHOST_BOOT_PROTOCOL;
- break;
- default:
- return BT_STATUS_PARM_INVALID;
- }
+ /* type match IPC type */
+ cmd.mode = protocol_mode;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
HAL_OP_HIDHOST_SET_PROTOCOL,
diff --git a/android/hidhost.c b/android/hidhost.c
index 4635e53..76e65b8 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -935,6 +935,15 @@ static void bt_hid_set_protocol(const void *buf, uint16_t len)
DBG("");
+ switch (cmd->mode) {
+ case HAL_HIDHOST_REPORT_PROTOCOL:
+ case HAL_HIDHOST_BOOT_PROTOCOL:
+ break;
+ default:
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
+
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
--
1.8.5.2
^ permalink raw reply related
* [PATCH 1/4] android/hidhost: Move get_protocol parameter check to daemon
From: Szymon Janc @ 2013-12-30 22:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
HAL library is to be as simple as possible and parameters values should
be verified by daemon for robustness anyway. Move this check to daemon.
---
android/hal-hidhost.c | 12 ++----------
android/hidhost.c | 9 +++++++++
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 6a6b682..5d05f9b 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -218,16 +218,8 @@ static bt_status_t get_protocol(bt_bdaddr_t *bd_addr,
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
- switch (protocol_mode) {
- case BTHH_REPORT_MODE:
- cmd.mode = HAL_HIDHOST_REPORT_PROTOCOL;
- break;
- case BTHH_BOOT_MODE:
- cmd.mode = HAL_HIDHOST_BOOT_PROTOCOL;
- break;
- default:
- return BT_STATUS_PARM_INVALID;
- }
+ /* type match IPC type */
+ cmd.mode = protocol_mode;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
HAL_OP_HIDHOST_GET_PROTOCOL,
diff --git a/android/hidhost.c b/android/hidhost.c
index 0e0391a..4635e53 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -880,6 +880,15 @@ static void bt_hid_get_protocol(const void *buf, uint16_t len)
DBG("");
+ switch (cmd->mode) {
+ case HAL_HIDHOST_REPORT_PROTOCOL:
+ case HAL_HIDHOST_BOOT_PROTOCOL:
+ break;
+ default:
+ status = HAL_STATUS_INVALID;
+ goto failed;
+ }
+
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
--
1.8.5.2
^ permalink raw reply related
* Re: [PATCH v2] Bluetooth: Add hci_h4p driver
From: Pavel Machek @ 2013-12-30 22:48 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Pali Rohár,
Ивайло Димитров,
Gustavo F. Padovan, Johan Hedberg, linux-kernel,
linux-bluetooth@vger.kernel.org development, Ville Tervo,
Sebastian Reichel
In-Reply-To: <C8D1F470-7964-4EAC-82E0-D53CF54DE086@holtmann.org>
Hi!
> > +#define NBT_DBG(fmt, arg...) \
> > + pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_FW(fmt, arg...) \
> > + pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_POWER(fmt, arg...) \
> > + pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_TRANSFER(fmt, arg...) \
> > + pr_debug("%s: " fmt "" , __func__ , ## arg)
> > +
> > +#define NBT_DBG_TRANSFER_NF(fmt, arg...) \
> > + pr_debug(fmt "" , ## arg)
> > +
> > +#define NBT_DBG_DMA(fmt, arg...) \
> > + pr_debug("%s: " fmt "" , __func__ , ## arg)
>
>
> I rather not introduce another ton of new debug helpers. Either use the BT_ ones or just spell this out if you need something that is not common.
>
It looks like idea here is that separate macros may be defined out
separately.
That debugging level should not be neccessary these days, so:
Regards,
Pavel
commit 1978475804807d6e17015c8aa53ad5606a82a71c
Author: Pavel <pavel@ucw.cz>
Date: Mon Dec 30 23:47:00 2013 +0100
Remove custom debugging helpers.
Signed-off-by: Pavel Machek <pavel@ucw.cz>
diff --git a/drivers/bluetooth/hci_h4p.h b/drivers/bluetooth/hci_h4p.h
index d1d313b..a2174ea 100644
--- a/drivers/bluetooth/hci_h4p.h
+++ b/drivers/bluetooth/hci_h4p.h
@@ -1,10 +1,8 @@
/*
- * This file is part of hci_h4p bluetooth driver
+ * This file is part of Nokia H4P bluetooth driver
*
* Copyright (C) 2005-2008 Nokia Corporation.
*
- * Contact: Ville Tervo <ville.tervo@nokia.com>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
@@ -48,24 +46,6 @@
#define UART_OMAP_SYSC_NO_IDLE (1 << UART_OMAP_SYSC_IDLEMODE)
#define UART_OMAP_SYSC_SMART_IDLE (2 << UART_OMAP_SYSC_IDLEMODE)
-#define NBT_DBG(fmt, arg...) \
- pr_debug("%s: " fmt "" , __func__ , ## arg)
-
-#define NBT_DBG_FW(fmt, arg...) \
- pr_debug("%s: " fmt "" , __func__ , ## arg)
-
-#define NBT_DBG_POWER(fmt, arg...) \
- pr_debug("%s: " fmt "" , __func__ , ## arg)
-
-#define NBT_DBG_TRANSFER(fmt, arg...) \
- pr_debug("%s: " fmt "" , __func__ , ## arg)
-
-#define NBT_DBG_TRANSFER_NF(fmt, arg...) \
- pr_debug(fmt "" , ## arg)
-
-#define NBT_DBG_DMA(fmt, arg...) \
- pr_debug("%s: " fmt "" , __func__ , ## arg)
-
#define H4P_TRANSFER_MODE 1
#define H4P_SCHED_TRANSFER_MODE 2
#define H4P_ACTIVE_MODE 3
diff --git a/drivers/bluetooth/nokia_core.c b/drivers/bluetooth/nokia_core.c
index 6dbd3b7..85dd106 100644
--- a/drivers/bluetooth/nokia_core.c
+++ b/drivers/bluetooth/nokia_core.c
@@ -54,7 +54,7 @@ static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
spin_lock_irqsave(&info->clocks_lock, flags);
if (enable && !*clock) {
- NBT_DBG_POWER("Enabling %p\n", clock);
+ BT_DBG("Enabling %p\n", clock);
clk_prepare_enable(info->uart_fclk);
clk_prepare_enable(info->uart_iclk);
if (atomic_read(&info->clk_users) == 0)
@@ -63,7 +63,7 @@ static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
}
if (!enable && *clock) {
- NBT_DBG_POWER("Disabling %p\n", clock);
+ BT_DBG("Disabling %p\n", clock);
if (atomic_dec_and_test(&info->clk_users))
hci_h4p_store_regs(info);
clk_disable_unprepare(info->uart_fclk);
@@ -114,7 +114,7 @@ static inline void h4p_schedule_pm(struct hci_h4p_info *info)
static void hci_h4p_disable_tx(struct hci_h4p_info *info)
{
- NBT_DBG_POWER("\n");
+ BT_DBG("\n");
if (!info->pm_enabled)
return;
@@ -130,7 +130,7 @@ static void hci_h4p_disable_tx(struct hci_h4p_info *info)
void hci_h4p_enable_tx(struct hci_h4p_info *info)
{
unsigned long flags;
- NBT_DBG_POWER("\n");
+ BT_DBG("\n");
if (!info->pm_enabled)
return;
@@ -197,7 +197,7 @@ int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
unsigned long flags;
int len;
- NBT_DBG("Sending alive packet\n");
+ BT_DBG("Sending alive packet\n");
len = H4_TYPE_SIZE + sizeof(*hdr) + sizeof(*pkt);
skb = bt_skb_alloc(len, GFP_KERNEL);
@@ -217,7 +217,7 @@ int hci_h4p_send_alive_packet(struct hci_h4p_info *info)
UART_IER_THRI);
spin_unlock_irqrestore(&info->lock, flags);
- NBT_DBG("Alive packet sent\n");
+ BT_DBG("Alive packet sent\n");
return 0;
}
@@ -228,7 +228,7 @@ static void hci_h4p_alive_packet(struct hci_h4p_info *info,
struct hci_h4p_alive_hdr *hdr;
struct hci_h4p_alive_pkt *pkt;
- NBT_DBG("Received alive packet\n");
+ BT_DBG("Received alive packet\n");
hdr = (struct hci_h4p_alive_hdr *)skb->data;
if (hdr->dlen != sizeof(*pkt)) {
dev_err(info->dev, "Corrupted alive message\n");
@@ -256,7 +256,7 @@ static int hci_h4p_send_negotiation(struct hci_h4p_info *info)
int err, len;
u16 sysclk;
- NBT_DBG("Sending negotiation..\n");
+ BT_DBG("Sending negotiation..\n");
switch (info->bt_sysclk) {
case 1:
@@ -326,7 +326,7 @@ static int hci_h4p_send_negotiation(struct hci_h4p_info *info)
if (info->init_error < 0)
return info->init_error;
- NBT_DBG("Negotiation succesful\n");
+ BT_DBG("Negotiation succesful\n");
return 0;
}
@@ -448,14 +448,14 @@ static inline void hci_h4p_recv_frame(struct hci_h4p_info *info,
}
if (!test_bit(HCI_UP, &info->hdev->flags)) {
- NBT_DBG("fw_event\n");
+ BT_DBG("fw_event\n");
hci_h4p_parse_fw_event(info, skb);
return;
}
}
hci_recv_frame(skb);
- NBT_DBG("Frame sent to upper layer\n");
+ BT_DBG("Frame sent to upper layer\n");
}
static inline void hci_h4p_handle_byte(struct hci_h4p_info *info, u8 byte)
@@ -514,8 +514,8 @@ static void hci_h4p_rx_tasklet(unsigned long data)
u8 byte;
struct hci_h4p_info *info = (struct hci_h4p_info *)data;
- NBT_DBG("tasklet woke up\n");
- NBT_DBG_TRANSFER("rx_tasklet woke up\ndata ");
+ BT_DBG("tasklet woke up\n");
+ BT_DBG("rx_tasklet woke up\ndata ");
while (hci_h4p_inb(info, UART_LSR) & UART_LSR_DR) {
byte = hci_h4p_inb(info, UART_RX);
@@ -535,7 +535,7 @@ static void hci_h4p_rx_tasklet(unsigned long data)
info->rx_skb->dev = (void *)info->hdev;
}
info->hdev->stat.byte_rx++;
- NBT_DBG_TRANSFER_NF("0x%.2x ", byte);
+ pr_debug("0x%.2x ", byte);
hci_h4p_handle_byte(info, byte);
}
@@ -551,8 +551,8 @@ static void hci_h4p_rx_tasklet(unsigned long data)
}
finish_rx:
- NBT_DBG_TRANSFER_NF("\n");
- NBT_DBG("rx_ended\n");
+ pr_debug("\n");
+ BT_DBG("rx_ended\n");
}
static void hci_h4p_tx_tasklet(unsigned long data)
@@ -561,8 +561,8 @@ static void hci_h4p_tx_tasklet(unsigned long data)
struct sk_buff *skb;
struct hci_h4p_info *info = (struct hci_h4p_info *)data;
- NBT_DBG("tasklet woke up\n");
- NBT_DBG_TRANSFER("tx_tasklet woke up\n data ");
+ BT_DBG("tasklet woke up\n");
+ BT_DBG("tx_tasklet woke up\n data ");
if (info->autorts != info->rx_enabled) {
if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
@@ -587,7 +587,7 @@ static void hci_h4p_tx_tasklet(unsigned long data)
skb = skb_dequeue(&info->txq);
if (!skb) {
/* No data in buffer */
- NBT_DBG("skb ready\n");
+ BT_DBG("skb ready\n");
if (hci_h4p_inb(info, UART_LSR) & UART_LSR_TEMT) {
hci_h4p_outb(info, UART_IER,
hci_h4p_inb(info, UART_IER) &
@@ -605,13 +605,13 @@ static void hci_h4p_tx_tasklet(unsigned long data)
/* Copy data to tx fifo */
while (!(hci_h4p_inb(info, UART_OMAP_SSR) & UART_OMAP_SSR_TXFULL) &&
(sent < skb->len)) {
- NBT_DBG_TRANSFER_NF("0x%.2x ", skb->data[sent]);
+ pr_debug("0x%.2x ", skb->data[sent]);
hci_h4p_outb(info, UART_TX, skb->data[sent]);
sent++;
}
info->hdev->stat.byte_tx += sent;
- NBT_DBG_TRANSFER_NF("\n");
+ pr_debug("\n");
if (skb->len == sent) {
kfree_skb(skb);
} else {
@@ -642,7 +642,7 @@ static irqreturn_t hci_h4p_interrupt(int irq, void *data)
if (iir & UART_IIR_NO_INT)
return IRQ_HANDLED;
- NBT_DBG("In interrupt handler iir 0x%.2x\n", iir);
+ BT_DBG("In interrupt handler iir 0x%.2x\n", iir);
iir &= UART_IIR_ID;
@@ -688,7 +688,7 @@ static irqreturn_t hci_h4p_wakeup_interrupt(int irq, void *dev_inst)
return IRQ_HANDLED;
}
- NBT_DBG_POWER("gpio interrupt %d\n", should_wakeup);
+ BT_DBG("gpio interrupt %d\n", should_wakeup);
/* Check if wee have missed some interrupts */
if (info->rx_enabled == should_wakeup)
@@ -970,7 +970,7 @@ again:
info->alive_cmd_skb = NULL;
set_bit(HCI_RUNNING, &hdev->flags);
- NBT_DBG("hci up and running\n");
+ BT_DBG("hci up and running\n");
return 0;
err_clean:
@@ -1030,7 +1030,7 @@ static int hci_h4p_hci_send_frame(struct sk_buff *skb)
return -ENODEV;
}
- NBT_DBG("dev %p, skb %p\n", hdev, skb);
+ BT_DBG("dev %p, skb %p\n", hdev, skb);
info = hci_get_drvdata(hdev);
@@ -1188,10 +1188,10 @@ static int hci_h4p_probe(struct platform_device *pdev)
info->reset_gpio_shared = bt_plat_data->reset_gpio_shared;
info->bt_sysclk = bt_plat_data->bt_sysclk;
- NBT_DBG("RESET gpio: %d\n", info->reset_gpio);
- NBT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
- NBT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
- NBT_DBG("sysclk: %d\n", info->bt_sysclk);
+ BT_DBG("RESET gpio: %d\n", info->reset_gpio);
+ BT_DBG("BTWU gpio: %d\n", info->bt_wakeup_gpio);
+ BT_DBG("HOSTWU gpio: %d\n", info->host_wakeup_gpio);
+ BT_DBG("sysclk: %d\n", info->bt_sysclk);
init_completion(&info->test_completion);
complete_all(&info->test_completion);
diff --git a/drivers/bluetooth/nokia_fw-bcm.c b/drivers/bluetooth/nokia_fw-bcm.c
index 9c01a6a..0cf8535 100644
--- a/drivers/bluetooth/nokia_fw-bcm.c
+++ b/drivers/bluetooth/nokia_fw-bcm.c
@@ -73,7 +73,7 @@ void hci_h4p_bcm_parse_fw_event(struct hci_h4p_info *info, struct sk_buff *skb)
}
if (fw_skb->data[1] == 0x01 && fw_skb->data[2] == 0xfc && fw_skb->len >= 10) {
- NBT_DBG_FW("Setting bluetooth address\n");
+ BT_DBG("Setting bluetooth address\n");
err = hci_h4p_bcm_set_bdaddr(info, fw_skb);
if (err < 0) {
kfree_skb(fw_skb);
@@ -99,7 +99,7 @@ int hci_h4p_bcm_send_fw(struct hci_h4p_info *info,
info->fw_error = 0;
- NBT_DBG_FW("Sending firmware\n");
+ BT_DBG("Sending firmware\n");
time = jiffies;
@@ -108,7 +108,7 @@ int hci_h4p_bcm_send_fw(struct hci_h4p_info *info,
if (!skb)
return -ENODATA;
- NBT_DBG_FW("Sending commands\n");
+ BT_DBG("Sending commands\n");
/*
* Disable smart-idle as UART TX interrupts
@@ -135,7 +135,7 @@ int hci_h4p_bcm_send_fw(struct hci_h4p_info *info,
return -EPROTO;
}
- NBT_DBG_FW("Firmware sent in %d msecs\n",
+ BT_DBG("Firmware sent in %d msecs\n",
jiffies_to_msecs(jiffies-time));
hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
diff --git a/drivers/bluetooth/nokia_fw-csr.c b/drivers/bluetooth/nokia_fw-csr.c
index 23c5fc5..886b721 100644
--- a/drivers/bluetooth/nokia_fw-csr.c
+++ b/drivers/bluetooth/nokia_fw-csr.c
@@ -53,7 +53,7 @@ int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
info->fw_error = 0;
- NBT_DBG_FW("Sending firmware\n");
+ BT_DBG("Sending firmware\n");
skb = skb_dequeue(fw_queue);
if (!skb)
@@ -90,7 +90,7 @@ int hci_h4p_bc4_send_fw(struct hci_h4p_info *info,
}
for (count = 1; ; count++) {
- NBT_DBG_FW("Sending firmware command %d\n", count);
+ BT_DBG("Sending firmware command %d\n", count);
init_completion(&info->fw_completion);
skb_queue_tail(&info->txq, skb);
spin_lock_irqsave(&info->lock, flags);
diff --git a/drivers/bluetooth/nokia_fw-ti1273.c b/drivers/bluetooth/nokia_fw-ti1273.c
index 2825504..fd82494 100644
--- a/drivers/bluetooth/nokia_fw-ti1273.c
+++ b/drivers/bluetooth/nokia_fw-ti1273.c
@@ -63,7 +63,7 @@ int hci_h4p_ti1273_send_fw(struct hci_h4p_info *info,
info->fw_error = 0;
- NBT_DBG_FW("Sending firmware\n");
+ BT_DBG("Sending firmware\n");
time = jiffies;
@@ -72,7 +72,7 @@ int hci_h4p_ti1273_send_fw(struct hci_h4p_info *info,
if (!skb)
return -ENODATA;
- NBT_DBG_FW("Sending commands\n");
+ BT_DBG("Sending commands\n");
/* Check if this is bd_address packet */
init_completion(&info->fw_completion);
hci_h4p_smart_idle(info, 0);
@@ -93,7 +93,7 @@ int hci_h4p_ti1273_send_fw(struct hci_h4p_info *info,
return -EPROTO;
}
- NBT_DBG_FW("Firmware sent in %d msecs\n",
+ BT_DBG("Firmware sent in %d msecs\n",
jiffies_to_msecs(jiffies-time));
hci_h4p_set_auto_ctsrts(info, 0, UART_EFR_RTS);
diff --git a/drivers/bluetooth/nokia_fw.c b/drivers/bluetooth/nokia_fw.c
index b3d39f9..f69efd8 100644
--- a/drivers/bluetooth/nokia_fw.c
+++ b/drivers/bluetooth/nokia_fw.c
@@ -38,7 +38,7 @@ static int hci_h4p_open_firmware(struct hci_h4p_info *info,
int err;
fw_pos = 0;
- NBT_DBG_FW("Opening firmware man_id 0x%.2x ver_id 0x%.2x\n",
+ BT_DBG("Opening firmware man_id 0x%.2x ver_id 0x%.2x\n",
info->man_id, info->ver_id);
switch (info->man_id) {
case H4P_ID_TI1271:
diff --git a/drivers/bluetooth/nokia_uart.c b/drivers/bluetooth/nokia_uart.c
index fd94a98..c19b8d2 100644
--- a/drivers/bluetooth/nokia_uart.c
+++ b/drivers/bluetooth/nokia_uart.c
@@ -100,7 +100,7 @@ void hci_h4p_change_speed(struct hci_h4p_info *info, unsigned long speed)
unsigned int divisor;
u8 lcr, mdr1;
- NBT_DBG("Setting speed %lu\n", speed);
+ BT_DBG("Setting speed %lu\n", speed);
if (speed >= 460800) {
divisor = UART_CLOCK / 13 / speed;
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply related
* [PATCH 7/7] android/build: Fix building HAL library on Linux
From: Szymon Janc @ 2013-12-30 22:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388443421-6295-1-git-send-email-szymon.janc@gmail.com>
PLATFORM_SDK_VERSION was not passed while building HAL library on Linux
host resulting in 4.3+ features not being build.
---
android/Makefile.am | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/Makefile.am b/android/Makefile.am
index 36210b9..7d9b580 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -59,7 +59,8 @@ android_libhal_internal_la_SOURCES = android/hal.h android/hal-bluetooth.c \
android/hal-log.h \
android/hal-ipc.h android/hal-ipc.c
-android_libhal_internal_la_CPPFLAGS = -I$(srcdir)/android
+android_libhal_internal_la_CPPFLAGS = -I$(srcdir)/android \
+ -DPLATFORM_SDK_VERSION=19
noinst_PROGRAMS += android/haltest
--
1.8.5.2
^ permalink raw reply related
* [PATCH 6/7] android/haltest: Implement missing functions from bluetooth HAL
From: Szymon Janc @ 2013-12-30 22:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388443421-6295-1-git-send-email-szymon.janc@gmail.com>
Implement functions added in Android 4.3+ to Bluetooth HAL.
---
android/client/if-bt.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index 0cd43db..10b79f1 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -797,6 +797,36 @@ static void dut_mode_configure_p(int argc, const char **argv)
EXEC(if_bluetooth->dut_mode_configure, mode);
}
+static void dut_mode_send_p(int argc, const char **argv)
+{
+ haltest_error("not implemented\n");
+}
+
+#if PLATFORM_SDK_VERSION > 17
+static void le_test_mode_p(int argc, const char **argv)
+{
+ haltest_error("not implemented\n");
+}
+#endif
+
+#if PLATFORM_SDK_VERSION > 18
+static void config_hci_snoop_log_p(int argc, const char **argv)
+{
+ uint8_t mode;
+
+ RETURN_IF_NULL(if_bluetooth);
+
+ if (argc <= 2) {
+ haltest_error("No mode specified\n");
+ return;
+ }
+
+ mode = strtol(argv[2], NULL, 0);
+
+ EXEC(if_bluetooth->config_hci_snoop_log, mode);
+}
+#endif
+
static struct method methods[] = {
STD_METHOD(init),
STD_METHOD(cleanup),
@@ -820,6 +850,13 @@ static struct method methods[] = {
STD_METHODCH(ssp_reply, "<address> <ssp_veriant> 1|0 [<passkey>]"),
STD_METHODCH(get_profile_interface, "<profile id>"),
STD_METHODH(dut_mode_configure, "<dut mode>"),
+ STD_METHOD(dut_mode_send),
+#if PLATFORM_SDK_VERSION > 17
+ STD_METHOD(le_test_mode),
+#endif
+#if PLATFORM_SDK_VERSION > 18
+ STD_METHODH(config_hci_snoop_log, "<mode>"),
+#endif
END_METHOD
};
--
1.8.5.2
^ permalink raw reply related
* [PATCH 5/7] android/haltest: Improve EXEC macro robustness
From: Szymon Janc @ 2013-12-30 22:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388443421-6295-1-git-send-email-szymon.janc@gmail.com>
Print info about method being NULL instead of crashing.
---
android/client/if-main.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/android/client/if-main.h b/android/client/if-main.h
index a83f48b..4a5d4cc 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -147,8 +147,12 @@ const struct method *get_interface_method(const char *iname,
/* Helper macro for executing function on interface and printing BT_STATUS */
#define EXEC(f, ...) \
{ \
- int err = f(__VA_ARGS__); \
- haltest_info("%s: %s\n", #f, bt_status_t2str(err)); \
+ if (f) { \
+ int err = f(__VA_ARGS__); \
+ haltest_info("%s: %s\n", #f, bt_status_t2str(err)); \
+ } else { \
+ haltest_info("%s is NULL\n", #f); \
+ } \
}
/* Helper macro for executing void function on interface */
--
1.8.5.2
^ permalink raw reply related
* [PATCH 4/7] android/hal-bluetooth: Add debug print to config_hci_snoop_log
From: Szymon Janc @ 2013-12-30 22:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388443421-6295-1-git-send-email-szymon.janc@gmail.com>
Improves debugs and make it consistent with other methods.
---
android/hal-bluetooth.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index a95c4ea..7accdcc 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -829,6 +829,8 @@ static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
#if PLATFORM_SDK_VERSION > 18
static int config_hci_snoop_log(uint8_t enable)
{
+ DBG("enable %u", enable);
+
if (enable && property_set("ctl.start", SNOOP_SERVICE_NAME) < 0) {
error("Failed to start service %s", SNOOP_SERVICE_NAME);
return BT_STATUS_FAIL;
--
1.8.5.2
^ permalink raw reply related
* [PATCH 3/7] android: Add support for bluetoothd-snoop service in system-emulator
From: Szymon Janc @ 2013-12-30 22:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388443421-6295-1-git-send-email-szymon.janc@gmail.com>
This allows to test bluetoothd-snoop service on Linux host.
---
android/system-emulator.c | 61 +++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 56 insertions(+), 5 deletions(-)
diff --git a/android/system-emulator.c b/android/system-emulator.c
index 611e46e..2dc9ad8 100644
--- a/android/system-emulator.c
+++ b/android/system-emulator.c
@@ -45,6 +45,7 @@
static char exec_dir[PATH_MAX + 1];
static pid_t daemon_pid = -1;
+static pid_t snoop_pid = -1;
static void ctl_start(void)
{
@@ -81,6 +82,47 @@ static void ctl_start(void)
daemon_pid = pid;
}
+static void snoop_start(void)
+{
+ char prg_name[PATH_MAX + 1];
+ char *prg_argv[3];
+ char *prg_envp[1];
+ pid_t pid;
+
+ snprintf(prg_name, sizeof(prg_name), "%s/%s", exec_dir,
+ "bluetoothd-snoop");
+
+ prg_argv[0] = prg_name;
+ prg_argv[1] = "/tmp/btsnoop_hci.log";
+ prg_argv[2] = NULL;
+
+ prg_envp[0] = NULL;
+
+ printf("Starting %s\n", prg_name);
+
+ pid = fork();
+ if (pid < 0) {
+ perror("Failed to fork new process");
+ return;
+ }
+
+ if (pid == 0) {
+ execve(prg_argv[0], prg_argv, prg_envp);
+ exit(0);
+ }
+
+ printf("New process %d created\n", pid);
+
+ snoop_pid = pid;
+}
+
+static void snoop_stop(void)
+{
+ printf("Stoping %s/%s\n", exec_dir, "bluetoothd-snoop");
+
+ kill(snoop_pid, SIGTERM);
+}
+
static void system_socket_callback(int fd, uint32_t events, void *user_data)
{
char buf[4096];
@@ -97,13 +139,20 @@ static void system_socket_callback(int fd, uint32_t events, void *user_data)
printf("Received %s\n", buf);
- if (strcmp(buf, "ctl.start=bluetoothd"))
- return;
+ if (!strcmp(buf, "ctl.start=bluetoothd")) {
+ if (daemon_pid > 0)
+ return;
- if (daemon_pid > 0)
- return;
+ ctl_start();
+ } else if (!strcmp(buf, "ctl.start=bluetoothd-snoop")) {
+ if (snoop_pid > 0)
+ return;
- ctl_start();
+ snoop_start();
+ } else if (!strcmp(buf, "ctl.stop=bluetoothd-snoop")) {
+ if (snoop_pid > 0)
+ snoop_stop();
+ }
}
static void signal_callback(int signum, void *user_data)
@@ -127,6 +176,8 @@ static void signal_callback(int signum, void *user_data)
if (pid == daemon_pid)
daemon_pid = -1;
+ else if (pid == snoop_pid)
+ snoop_pid = -1;
}
break;
}
--
1.8.5.2
^ permalink raw reply related
* [PATCH 2/7] android/hal-bluetooth: Update snoop service name
From: Szymon Janc @ 2013-12-30 22:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1388443421-6295-1-git-send-email-szymon.janc@gmail.com>
Match service name with android snoop binary name. It is more common
to use '-' instead of '_' in the code for binaries name.
---
android/hal-bluetooth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 9f9814a..a95c4ea 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -28,7 +28,7 @@
#include "hal-ipc.h"
#include "hal-utils.h"
-#define SNOOP_SERVICE_NAME "bluetoothd_snoop"
+#define SNOOP_SERVICE_NAME "bluetoothd-snoop"
static const bt_callbacks_t *bt_hal_cbacks = NULL;
--
1.8.5.2
^ permalink raw reply related
* [PATCH 1/7] android: Add HCI snooping tool
From: Szymon Janc @ 2013-12-30 22:43 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This tool is intended to be run as Android service. It supports
writing HCI snoop data in old btsnoop format only. By default traffic
is stored in /sdcard/btsnoop_hci.log file (can be overridded with
option - mainly for testing on Linux host). Only index 0 is sniffed.
---
.gitignore | 1 +
android/Android.mk | 23 +++++
android/Makefile.am | 6 ++
android/bluetoothd-snoop.c | 219 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 249 insertions(+)
create mode 100644 android/bluetoothd-snoop.c
diff --git a/.gitignore b/.gitignore
index b97546e..1447c90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -109,3 +109,4 @@ android/system-emulator
android/bluetoothd
android/haltest
android/android-tester
+android/bluetoothd-snoop
diff --git a/android/Android.mk b/android/Android.mk
index 7e29899..1720823 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -253,3 +253,26 @@ LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := l2test
include $(BUILD_EXECUTABLE)
+
+#
+# bluetoothd-snoop
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ bluetoothd-snoop.c \
+ ../monitor/mainloop.c \
+ ../src/shared/btsnoop.c \
+
+LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)/.. \
+ $(LOCAL_PATH)/../lib \
+
+LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS)
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := bluetoothd-snoop
+
+include $(BUILD_EXECUTABLE)
diff --git a/android/Makefile.am b/android/Makefile.am
index dec81ce..36210b9 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -4,6 +4,12 @@ noinst_PROGRAMS += android/system-emulator
android_system_emulator_SOURCES = android/system-emulator.c \
monitor/mainloop.h monitor/mainloop.c
+noinst_PROGRAMS += android/bluetoothd-snoop
+
+android_bluetoothd_snoop_SOURCES = android/bluetoothd-snoop.c \
+ monitor/mainloop.h monitor/mainloop.c \
+ src/shared/btsnoop.h src/shared/btsnoop.c
+
noinst_PROGRAMS += android/bluetoothd
android_bluetoothd_SOURCES = android/main.c \
diff --git a/android/bluetoothd-snoop.c b/android/bluetoothd-snoop.c
new file mode 100644
index 0000000..02f44e9
--- /dev/null
+++ b/android/bluetoothd-snoop.c
@@ -0,0 +1,219 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2013 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 <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "lib/bluetooth.h"
+#include "lib/hci.h"
+#include "lib/mgmt.h"
+
+#include "monitor/mainloop.h"
+#include "src/shared/btsnoop.h"
+
+#define DEAULT_SNOOP_FILE "/sdcard/btsnoop_hci.log"
+
+#define MAX_PACKET_SIZE (1486 + 4)
+
+static struct btsnoop *snoop = NULL;
+static uint8_t monitor_buf[MAX_PACKET_SIZE];
+static int monitor_fd = -1;
+
+static void signal_callback(int signum, void *user_data)
+{
+ switch (signum) {
+ case SIGINT:
+ case SIGTERM:
+ mainloop_quit();
+ break;
+ }
+}
+
+static uint32_t get_flags_from_opcode(uint16_t opcode)
+{
+ switch (opcode) {
+ case BTSNOOP_OPCODE_NEW_INDEX:
+ case BTSNOOP_OPCODE_DEL_INDEX:
+ break;
+ case BTSNOOP_OPCODE_COMMAND_PKT:
+ return 0x02;
+ case BTSNOOP_OPCODE_EVENT_PKT:
+ return 0x03;
+ case BTSNOOP_OPCODE_ACL_TX_PKT:
+ return 0x00;
+ case BTSNOOP_OPCODE_ACL_RX_PKT:
+ return 0x01;
+ case BTSNOOP_OPCODE_SCO_TX_PKT:
+ case BTSNOOP_OPCODE_SCO_RX_PKT:
+ break;
+ }
+
+ return 0xff;
+}
+
+static void data_callback(int fd, uint32_t events, void *user_data)
+{
+ unsigned char control[32];
+ struct mgmt_hdr hdr;
+ struct msghdr msg;
+ struct iovec iov[2];
+
+ if (events & (EPOLLERR | EPOLLHUP)) {
+ mainloop_remove_fd(monitor_fd);
+ return;
+ }
+
+ iov[0].iov_base = &hdr;
+ iov[0].iov_len = MGMT_HDR_SIZE;
+ iov[1].iov_base = monitor_buf;
+ iov[1].iov_len = sizeof(monitor_buf);
+
+ memset(&msg, 0, sizeof(msg));
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 2;
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
+
+ while (true) {
+ struct cmsghdr *cmsg;
+ struct timeval *tv = NULL;
+ struct timeval ctv;
+ uint16_t opcode, index, pktlen;
+ uint32_t flags;
+ ssize_t len;
+
+ len = recvmsg(monitor_fd, &msg, MSG_DONTWAIT);
+ if (len < 0)
+ break;
+
+ if (len < MGMT_HDR_SIZE)
+ break;
+
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ if (cmsg->cmsg_level != SOL_SOCKET)
+ continue;
+
+ if (cmsg->cmsg_type == SCM_TIMESTAMP) {
+ memcpy(&ctv, CMSG_DATA(cmsg), sizeof(ctv));
+ tv = &ctv;
+ }
+ }
+
+ opcode = btohs(hdr.opcode);
+ index = btohs(hdr.index);
+ pktlen = btohs(hdr.len);
+
+ if (index)
+ continue;
+
+ flags = get_flags_from_opcode(opcode);
+ if (flags != 0xff)
+ btsnoop_write(snoop, tv, flags, monitor_buf, pktlen);
+ }
+}
+
+static int open_monitor(const char *path)
+{
+ struct sockaddr_hci addr;
+ int opt = 1;
+
+ snoop = btsnoop_create(path, BTSNOOP_TYPE_HCI);
+ if (!snoop)
+ return -1;
+
+ monitor_fd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
+ if (monitor_fd < 0)
+ goto failed;
+
+ memset(&addr, 0, sizeof(addr));
+ addr.hci_family = AF_BLUETOOTH;
+ addr.hci_dev = HCI_DEV_NONE;
+ addr.hci_channel = HCI_CHANNEL_MONITOR;
+
+ if (bind(monitor_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
+ goto failed_close;
+
+ if (setsockopt(monitor_fd, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))
+ < 0)
+ goto failed_close;
+
+ mainloop_add_fd(monitor_fd, EPOLLIN, data_callback, NULL, NULL);
+
+ return 0;
+
+failed_close:
+ close(monitor_fd);
+ monitor_fd = -1;
+
+failed:
+ btsnoop_unref(snoop);
+ snoop = NULL;
+
+ return -1;
+}
+
+static void close_monitor(void)
+{
+ btsnoop_unref(snoop);
+ snoop = NULL;
+
+ close(monitor_fd);
+ monitor_fd = -1;
+}
+
+int main(int argc, char *argv[])
+{
+ const char *path;
+ sigset_t mask;
+
+ if (argc > 1)
+ path = argv[1];
+ else
+ path = DEAULT_SNOOP_FILE;
+
+ mainloop_init();
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGINT);
+ sigaddset(&mask, SIGTERM);
+
+ mainloop_set_signal(&mask, signal_callback, NULL, NULL);
+
+ if (open_monitor(path) < 0) {
+ printf("Failed to start bluetoothd_snoop\n");
+ return EXIT_FAILURE;
+ }
+
+ mainloop_run();
+
+ close_monitor();
+
+ return EXIT_SUCCESS;
+}
--
1.8.5.2
^ permalink raw reply related
* Re: [PATCH v2] Bluetooth: Add hci_h4p driver
From: Pavel Machek @ 2013-12-30 22:28 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Pali Rohár,
Ивайло Димитров,
Gustavo F. Padovan, Johan Hedberg, linux-kernel,
linux-bluetooth@vger.kernel.org development, Ville Tervo,
Sebastian Reichel
In-Reply-To: <C8D1F470-7964-4EAC-82E0-D53CF54DE086@holtmann.org>
Hi!
> > +++ b/drivers/bluetooth/hci_h4p/core.c
> > @@ -0,0 +1,1357 @@
> > +/*
> > + * This file is part of hci_h4p bluetooth driver
> > + *
> > + * Copyright (C) 2005-2008 Nokia Corporation.
> > + *
> > + * Contact: Ville Tervo <ville.tervo@nokia.com>
>
> I think you can just remove the contact names since I think nobody of the original authors is still working at Nokia and I bet this emails addresses just do not work anymore.
>
What about this?
commit 3f18ca6cd02a13baf4be9beb89b1470ad1ce008c
Author: Pavel <pavel@ucw.cz>
Date: Mon Dec 30 23:27:21 2013 +0100
Update comments, remove no longer relevant contacts.
Signed-off-by: Pavel Machek <pavel@ucw.cz>
diff --git a/drivers/bluetooth/nokia_core.c b/drivers/bluetooth/nokia_core.c
index a91bd7b..6dbd3b7 100644
--- a/drivers/bluetooth/nokia_core.c
+++ b/drivers/bluetooth/nokia_core.c
@@ -1,10 +1,8 @@
/*
- * This file is part of hci_h4p bluetooth driver
+ * This file is part of Nokia H4P bluetooth driver
*
* Copyright (C) 2005-2008 Nokia Corporation.
*
- * Contact: Ville Tervo <ville.tervo@nokia.com>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
@@ -19,6 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
+ * Thanks to all the Nokia people that helped with this driver,
+ * including Ville Tervo and Roger Quadros.
*/
#include <linux/module.h>
diff --git a/drivers/bluetooth/nokia_fw-bcm.c b/drivers/bluetooth/nokia_fw-bcm.c
index 390d021..9c01a6a 100644
--- a/drivers/bluetooth/nokia_fw-bcm.c
+++ b/drivers/bluetooth/nokia_fw-bcm.c
@@ -1,10 +1,8 @@
/*
- * This file is part of hci_h4p bluetooth driver
+ * This file is part of Nokia H4P bluetooth driver
*
* Copyright (C) 2005-2008 Nokia Corporation.
*
- * Contact: Ville Tervo <ville.tervo@nokia.com>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
diff --git a/drivers/bluetooth/nokia_fw-csr.c b/drivers/bluetooth/nokia_fw-csr.c
index af880d9..23c5fc5 100644
--- a/drivers/bluetooth/nokia_fw-csr.c
+++ b/drivers/bluetooth/nokia_fw-csr.c
@@ -1,10 +1,8 @@
/*
- * This file is part of hci_h4p bluetooth driver
+ * This file is part of Nokia H4P bluetooth driver
*
* Copyright (C) 2005-2008 Nokia Corporation.
*
- * Contact: Ville Tervo <ville.tervo@nokia.com>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
diff --git a/drivers/bluetooth/nokia_fw-ti1273.c b/drivers/bluetooth/nokia_fw-ti1273.c
index 32e5fa0..2825504 100644
--- a/drivers/bluetooth/nokia_fw-ti1273.c
+++ b/drivers/bluetooth/nokia_fw-ti1273.c
@@ -1,10 +1,8 @@
/*
- * This file is part of hci_h4p bluetooth driver
+ * This file is part of Nokia H4P bluetooth driver
*
* Copyright (C) 2009 Nokia Corporation.
*
- * Contact: Ville Tervo <ville.tervo@nokia.com>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
diff --git a/drivers/bluetooth/nokia_uart.c b/drivers/bluetooth/nokia_uart.c
index 8e0a93c..fd94a98 100644
--- a/drivers/bluetooth/nokia_uart.c
+++ b/drivers/bluetooth/nokia_uart.c
@@ -1,10 +1,8 @@
/*
- * This file is part of hci_h4p bluetooth driver
+ * This file is part of Nokia H4P bluetooth driver
*
* Copyright (C) 2005, 2006 Nokia Corporation.
*
- * Contact: Ville Tervo <ville.tervo@nokia.com>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
diff --git a/include/linux/bluetooth/hci_h4p.h b/include/linux/bluetooth/hci_h4p.h
index daf83fc..30d169d 100644
--- a/include/linux/bluetooth/hci_h4p.h
+++ b/include/linux/bluetooth/hci_h4p.h
@@ -1,10 +1,8 @@
/*
- * This file is part of hci_h4p bluetooth driver
+ * This file is part of Nokia H4P bluetooth driver
*
* Copyright (C) 2010 Nokia Corporation.
*
- * Contact: Roger Quadros <roger.quadros@nokia.com>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply related
* [PATCH] wilink: mention name of module in help text
From: Pavel Machek @ 2013-12-30 22:19 UTC (permalink / raw)
To: Marcel Holtmann, trivial
Cc: Pali Rohár,
Ивайло Димитров,
Gustavo F. Padovan, Johan Hedberg, linux-kernel,
linux-bluetooth@vger.kernel.org development, Ville Tervo,
Sebastian Reichel
In-Reply-To: <C8D1F470-7964-4EAC-82E0-D53CF54DE086@holtmann.org>
Mention module name in Kconfig.
Signed-off-by: Pavel Machek <pavel@ucw.cz>
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 9d46f23..a53e8c7 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -241,7 +241,7 @@ config BT_WILINK
core driver to communicate with the BT core of the combo chip.
Say Y here to compile support for Texas Instrument's WiLink7 driver
- into the kernel or say M to compile it as module.
+ into the kernel or say M to compile it as module (btwilink).
config BT_NOKIA_H4P
tristate "HCI driver with H4 Nokia extensions"
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply related
* Re: [PATCH v2] Bluetooth: Add hci_h4p driver
From: Pavel Machek @ 2013-12-30 22:18 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Pali Rohár,
Ивайло Димитров,
Gustavo F. Padovan, Johan Hedberg, linux-kernel,
linux-bluetooth@vger.kernel.org development, Ville Tervo,
Sebastian Reichel
In-Reply-To: <C8D1F470-7964-4EAC-82E0-D53CF54DE086@holtmann.org>
Hi!
> > +config BT_HCIH4P
> > + tristate "HCI driver with H4 Nokia extensions"
> > + depends on BT && ARCH_OMAP
>
> Since then we moved away from doing hci_* prefix of drivers since that is misleading. See btusb.ko, btmrvl_sdio.ko etc.
>
> So this might be better named BT_NOK_H4P or BT_NOKIA_H4P and the module named btnok_h4p.ko or btnokia_h4p.ko.
>
Pali, please apply :-).
Pavel
commit b724166911dcdae2c43170ce4040427c00e834e3
Author: Pavel <pavel@ucw.cz>
Date: Mon Dec 30 23:16:25 2013 +0100
Rename nokia h4p driver object to btnokia_h4p.ko.
Signed-off-by: Pavel Machek <pavel@ucw.cz>
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 9d46f23..a53e8c7 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -251,5 +251,5 @@ config BT_NOKIA_H4P
support for H4+ Bluetooth chip with vendor-specific H4 extensions.
Say Y here to compile support for h4 extended devices into the kernel
- or say M to compile it as module (hci_h4p).
+ or say M to compile it as module (btnokia_h4p).
endmenu
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index c286dbe..a5ed271 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -31,7 +31,7 @@ hci_uart-$(CONFIG_BT_HCIUART_ATH3K) += hci_ath.o
hci_uart-$(CONFIG_BT_HCIUART_3WIRE) += hci_h5.o
hci_uart-objs := $(hci_uart-y)
-obj-$(CONFIG_BT_NOKIA_H4P) += hci_h4p.o
-hci_h4p-objs := nokia_core.o nokia_fw.o nokia_uart.o nokia_fw-csr.o \
+obj-$(CONFIG_BT_NOKIA_H4P) += btnokia_h4p.o
+btnokia_h4p-objs := nokia_core.o nokia_fw.o nokia_uart.o nokia_fw-csr.o \
nokia_fw-bcm.o nokia_fw-ti1273.o
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply related
* PATCH hid2hci for CSR 8510 A10
From: Gordon @ 2013-12-30 21:59 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 551 bytes --]
Hi,
ich had a problem with the Sitecom CNT-524 as described by someone else
here:
http://blog.ruecker.fi/2013/10/06/adventures-in-bluetooth-4-0-part-i/
so i tried to fix that by introducing --mode csr2 for hid2hci
I neither know how to switch back to hid nor how to detect the EALREADY
state, otherwise the patch is very small.
I works on my machine in ubuntu 13.04 with bluez 4.101-0ubuntu8b1 and
said sitecom usb dongle. the patch is against bluez commit
fd00064e0bb2c81e53e9d0b7d22ce919b41dbe60
Could someone please review.
Cheers,
Gordon
[-- Attachment #2: bluez_hid2hci.patch --]
[-- Type: text/x-patch, Size: 2471 bytes --]
diff --git a/tools/hid2hci.1 b/tools/hid2hci.1
index 8c5d520..c6876a3 100644
--- a/tools/hid2hci.1
+++ b/tools/hid2hci.1
@@ -32,7 +32,7 @@ mode and back.
.B --mode= [hid, hci]
Sets the mode to switch the device into
.TP
-.B --method= [csr, logitech-hid, dell]
+.B --method= [csr, csr2, logitech-hid, dell]
Which vendor method to use for switching the device.
.TP
.B --devpath=
diff --git a/tools/hid2hci.c b/tools/hid2hci.c
index 95b4abf..514accc 100644
--- a/tools/hid2hci.c
+++ b/tools/hid2hci.c
@@ -118,6 +118,41 @@ static int usb_switch_csr(int fd, enum mode mode)
return err;
}
+static int usb_switch_csr2(int fd, enum mode mode)
+{
+ int err = 0;
+ struct usbfs_disconnect disconnect;
+ char report[] = { 0x1 , 0x5 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 };
+ switch (mode) {
+ case HCI:
+ //send report as is
+ disconnect.interface = 0;
+ disconnect.flags = USBFS_DISCONNECT_EXCEPT_DRIVER;
+ strcpy(disconnect.driver, "usbfs");
+
+ if (ioctl(fd, USBFS_IOCTL_DISCONNECT, &disconnect) < 0) {
+ fprintf(stderr, "Can't claim interface: %s (%d)\n",
+ strerror(errno), errno);
+ return -1;
+ }
+
+ err = control_message(fd, USB_ENDPOINT_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+ USB_REQ_SET_CONFIGURATION, //Set_Report Request
+ 0x01 | (0x03 << 8), //report id: 0x01, report type: feature (0x03)
+ 0, //interface
+ report, sizeof(report), 5000);
+ //unable to detect EALREADY
+ break;
+ case HID:
+ // currently unknown what to do here
+ fprintf(stderr, "csr2: Switching to hid mode is not implemented\n");
+ return -1;
+ break;
+ }
+
+ return err;
+}
+
static int hid_logitech_send_report(int fd, const char *buf, size_t size)
{
struct hiddev_report_info rinfo;
@@ -257,7 +292,7 @@ static void usage(const char *error)
printf("Usage: hid2hci [options]\n"
" --mode= mode to switch to [hid|hci] (default hci)\n"
" --devpath= sys device path\n"
- " --method= method to use to switch [csr|logitech-hid|dell]\n"
+ " --method= method to use to switch [csr|csr2|logitech-hid|dell]\n"
" --help\n\n");
}
@@ -310,6 +345,9 @@ int main(int argc, char *argv[])
if (!strcmp(optarg, "csr")) {
method = METHOD_CSR;
usb_switch = usb_switch_csr;
+ } else if (!strcmp(optarg, "csr2")) {
+ method = METHOD_CSR;
+ usb_switch = usb_switch_csr2;
} else if (!strcmp(optarg, "logitech-hid")) {
method = METHOD_LOGITECH_HID;
} else if (!strcmp(optarg, "dell")) {
^ permalink raw reply related
* Re: [RFC 6/6] android/audio: Add listener thread on the Audio HAL socket
From: Lukasz Rymanowski @ 2013-12-30 20:57 UTC (permalink / raw)
To: Luiz Augusto von Dentz
Cc: Lukasz Rymanowski, linux-bluetooth@vger.kernel.org, Johan Hedberg
In-Reply-To: <CABBYNZK-c_AD2ZkxGs0XE4SkNwGnVxNByv-c-erV9DFJ9mry_w@mail.gmail.com>
Hi Luiz,
On Mon, Dec 30, 2013 at 2:07 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Lukasz,
>
> On Mon, Dec 30, 2013 at 1:40 PM, Lukasz Rymanowski
> <lukasz.rymanowski@tieto.com> wrote:
>> Hi Luiz,
>>
>> On 30 December 2013 12:31, Luiz Augusto von Dentz <luiz.dentz@gmail.com> wrote:
>>> Hi Lukasz,
>>>
>>> On Mon, Dec 30, 2013 at 12:17 PM, Lukasz Rymanowski
>>> <lukasz.rymanowski@tieto.com> wrote:
>>>> This patch add thread which is reponsible for listen on audio HAL
>>>> socket, register a2dp endpoint(s) and maintain socket.
>>>> When bluetooth daemon goes down, HAL audio plugin starts to listen on Audio HAL
>>>> socket again.
>>>>
>>>> ---
>>>> android/Makefile.am | 2 +
>>>> android/hal-audio.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>> android/hal-audio.h | 18 +++++++
>>>> 3 files changed, 165 insertions(+)
>>>> create mode 100644 android/hal-audio.h
>>>>
>>>> diff --git a/android/Makefile.am b/android/Makefile.am
>>>> index eaf39bd..bd90c13 100644
>>>> --- a/android/Makefile.am
>>>> +++ b/android/Makefile.am
>>>> @@ -112,6 +112,8 @@ android_libaudio_internal_la_SOURCES = android/hal-audio.c \
>>>>
>>>> android_libaudio_internal_la_CFLAGS = -I$(srcdir)/android
>>>>
>>>> +android_libaudio_internal_la_LDFLAGS = -pthread
>>>> +
>>>> endif
>>>>
>>>> EXTRA_DIST += android/Android.mk android/hal-ipc-api.txt android/README \
>>>> diff --git a/android/hal-audio.c b/android/hal-audio.c
>>>> index 011a699..0e3bc70 100644
>>>> --- a/android/hal-audio.c
>>>> +++ b/android/hal-audio.c
>>>> @@ -16,18 +16,30 @@
>>>> */
>>>>
>>>> #include <errno.h>
>>>> +#include <pthread.h>
>>>> +#include <poll.h>
>>>> #include <stdio.h>
>>>> #include <stdlib.h>
>>>> #include <string.h>
>>>> +#include <sys/socket.h>
>>>> +#include <sys/un.h>
>>>> +#include <unistd.h>
>>>>
>>>> #include <hardware/audio.h>
>>>> #include <hardware/hardware.h>
>>>>
>>>> +#include "hal-audio.h"
>>>> #include "hal-log.h"
>>>>
>>>> struct a2dp_audio_dev {
>>>> struct audio_hw_device dev;
>>>> struct a2dp_stream_out *stream_out;
>>>> +
>>>> + pthread_t bt_watcher;
>>>> + pthread_mutex_t hal_sk_mutex;
>>>> + pthread_cond_t bt_watcher_cond;
>>>> +
>>>> + int hal_sk;
>>>> };
>>>>
>>>> struct a2dp_stream_out {
>>>> @@ -384,15 +396,135 @@ static int audio_dump(const audio_hw_device_t *device, int fd)
>>>>
>>>> static int audio_close(hw_device_t *device)
>>>> {
>>>> + struct audio_hw_device *dev = (struct audio_hw_device *)device;
>>>> + struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *)dev;
>>>> +
>
> Hmm, Im afraid these are not the same pointers as you do *device =
> &a2dp_dev->dev.common; so this will probably cause invalid accesses.
>
Actually this is same pointer and even I could do here direct cast
from hw_device_t to a2dp_audio_dev with some comment why I can do it.
Is that fine?
Also in audio_open(), to make code less confusing, will do *device =
(hw_device_t *)a2dp_dev
Is that fine for you? Not sure how discussion ends or IRC about that
as I had to go.
>>>> DBG("");
>>>> +
>>>> + if (a2dp_dev) {
>>>> + /* TODO: We could try to unregister Endpoint here */
>>>> + shutdown(a2dp_dev->hal_sk, 2);
>>>> +
>>>> + pthread_mutex_lock(&a2dp_dev->hal_sk_mutex);
>>>> + pthread_cond_signal(&a2dp_dev->bt_watcher_cond);
>>>> + pthread_mutex_unlock(&a2dp_dev->hal_sk_mutex);
>>>> +
>>>> + (void) pthread_join(a2dp_dev->bt_watcher, NULL);
>>>> + free(a2dp_dev);
>>>> + }
>>>> +
>>>> free(device);
>>>> return 0;
>>>> }
>>>>
>>>> +static int wait_for_client(void)
>>>> +{
>>>> + struct sockaddr_un addr;
>>>> + int err;
>>>> + int sk;
>>>> + int new_sk;
>>>> +
>>>> + DBG("");
>>>> +
>>>> + sk = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
>>>> + if (sk < 0) {
>>>> + err = errno;
>>>> + error("Failed to create socket: %d (%s)", err, strerror(err));
>>>> + return -1;
>>>> + }
>>>> +
>>>> + memset(&addr, 0, sizeof(addr));
>>>> + addr.sun_family = AF_UNIX;
>>>> +
>>>> + memcpy(addr.sun_path, BLUEZ_AUDIO_HAL_SK_PATH,
>>>> + sizeof(BLUEZ_AUDIO_HAL_SK_PATH));
>>>> +
>>>> + if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
>>>> + err = errno;
>>>> + error("Failed to bind socket: %d (%s)", err, strerror(err));
>>>> + goto error;
>>>> + }
>>>> +
>>>> + if (listen(sk, 1) < 0) {
>>>> + err = errno;
>>>> + error("Failed to bind socket: %d (%s)", err, strerror(err));
>>>> + goto error;
>>>> + }
>>>> +
>>>> + new_sk = accept(sk, NULL, NULL);
>>>> + if (new_sk < 0) {
>>>> + err = errno;
>>>> + error("Failed to accept socket: %d (%s)", err, strerror(err));
>>>> + goto error;
>>>> + }
>>>> +
>>>> + close(sk);
>>>> + return new_sk;
>>>> +
>>>> +error:
>>>> + close(sk);
>>>> + return -1;
>>>> +}
>>>> +
>>>> +static void *bluetoothd_watcher(void *data)
>>>> +{
>>>> + int err;
>>>> + struct a2dp_audio_dev *a2dp_dev = (struct a2dp_audio_dev *)data;
>>>> + struct pollfd pfd;
>>>> + struct timeval now;
>>>> + struct timespec timeout;
>>>> +
>>>> + DBG("");
>>>> +
>>>> + while (1) {
>>>> + a2dp_dev->hal_sk = wait_for_client();
>>>> + if (a2dp_dev->hal_sk < 0) {
>>>> + error("Failed to create listening socket");
>>>> + continue;
>>>> + }
>>>> +
>>>> + DBG("Audio IPC: Connected");
>>>> +
>>>> + /* TODO: Register ENDPOINT here */
>>>> +
>>>> + memset(&pfd, 0, sizeof(pfd));
>>>> + pfd.fd = a2dp_dev->hal_sk;
>>>> + pfd.events = POLLHUP | POLLERR | POLLNVAL;
>>>> +
>>>> + pthread_mutex_lock(&a2dp_dev->hal_sk_mutex);
>>>> +
>>>> + /* Check if socket is still alive */
>>>> + err = poll(&pfd, 1, -1);
>>>> + if (pfd.revents & (POLLHUP | POLLERR | POLLNVAL)) {
>>>> + info("Audio HAL: Socket closed");
>>>> + a2dp_dev->hal_sk = -1;
>>>> + }
>>>> +
>>>> + /* Maybe audio system is closing and audio_close() has been called? */
>>>> + gettimeofday(&now, NULL);
>>>> + timeout.tv_sec = now.tv_sec;
>>>> + timeout.tv_nsec = now.tv_usec * 1000;
>>>> + timeout.tv_sec += 1;
>>>> +
>>>> + err = pthread_cond_timedwait(&a2dp_dev->bt_watcher_cond,
>>>> + &a2dp_dev->hal_sk_mutex, &timeout);
>>>> +
>>>> + pthread_mutex_unlock(&a2dp_dev->hal_sk_mutex);
>>>> + if (err != ETIMEDOUT)
>>>> + /* Seems that device has been closed */
>>>> + break;
>>>> + }
>>>> +
>>>> + info("Closing bluetooth_watcher thread");
>>>> + pthread_exit(NULL);
>>>> + return NULL;
>>>> +}
>>>> +
>>>> static int audio_open(const hw_module_t *module, const char *name,
>>>> hw_device_t **device)
>>>> {
>>>> struct a2dp_audio_dev *a2dp_dev;
>>>> + int err;
>>>>
>>>> DBG("");
>>>>
>>>> @@ -427,6 +559,19 @@ static int audio_open(const hw_module_t *module, const char *name,
>>>>
>>>> *device = &a2dp_dev->dev.common;
>>>>
>>>> + a2dp_dev->hal_sk = -1;
>>>> +
>>>> + pthread_mutex_init(&a2dp_dev->hal_sk_mutex, NULL);
>>>> + pthread_cond_init(&a2dp_dev->bt_watcher_cond, NULL);
>>>> +
>>>> + err = pthread_create(&a2dp_dev->bt_watcher, NULL, bluetoothd_watcher, a2dp_dev);
>>>> + if (err < 0) {
>>>> + a2dp_dev->bt_watcher = 0;
>>>> + error("Failed to start bluetoothd watcher thread: %d (%s)", -err,
>>>> + strerror(-err));
>>>> + return (-err);
>>>> + }
>>>> +
>>>> return 0;
>>>> }
>>>>
>>>> diff --git a/android/hal-audio.h b/android/hal-audio.h
>>>> new file mode 100644
>>>> index 0000000..93e49f6
>>>> --- /dev/null
>>>> +++ b/android/hal-audio.h
>>>> @@ -0,0 +1,18 @@
>>>> +/*
>>>> + *
>>>> + * Copyright (C) 2013 Intel Corporation
>>>> + *
>>>> + * Licensed under the Apache License, Version 2.0 (the "License");
>>>> + * you may not use this file except in compliance with the License.
>>>> + * You may obtain a copy of the License at
>>>> + *
>>>> + * http://www.apache.org/licenses/LICENSE-2.0
>>>> + *
>>>> + * Unless required by applicable law or agreed to in writing, software
>>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>>> + * See the License for the specific language governing permissions and
>>>> + * limitations under the License.
>>>> + *
>>>> + */
>>>> +static const char BLUEZ_AUDIO_HAL_SK_PATH[] = "\0bluez_audio_socket";
>>>> --
>>>> 1.8.4
>>>
>>> Ive started working on the daemon side and should be able to post some
>>> patches today, Im not really sure we are going to need a thread for
>>> command handling since all the commands will be sent by the plugin
>>> side so they can be synchronous, the only problem would be if the
>>> plugin cannot really block even for a short period.
>>>
>>
>> This Thread is only going to be used for accept, endpoint register and
>> then listening for socket close (so we can start listen for connection
>> from new bluetoothd).
>>
>> Commands and response will be handled in main thread (ex.
>> audio_open(), out_write()) and we can block there for a while - no
>> problem with that
>
> Well it seems the init/listen stage needs to be non-blocking so we
> don't interrupt the audio init procedure which may block bluetooth HAL
> to initialized, the endpoint then should be registered whenever
> bluetoothd connects.
>
>
\Łukasz
> --
> Luiz Augusto von Dentz
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox