* Re: [PATCH] android: Use G_N_ELEMENTS macro for table elements calculation
From: Luiz Augusto von Dentz @ 2013-12-03 12:10 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1385997478-18883-1-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Mon, Dec 2, 2013 at 5:17 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> It is more common in codebase to use this macro instead of opencoded
> (sizeof(foo)/sizeof(foo[0])).
> ---
> android/a2dp.c | 2 +-
> android/bluetooth.c | 2 +-
> android/hidhost.c | 2 +-
> android/main.c | 2 +-
> android/pan.c | 2 +-
> android/socket.c | 2 +-
> 6 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/android/a2dp.c b/android/a2dp.c
> index 98c138e..cee4bfa 100644
> --- a/android/a2dp.c
> +++ b/android/a2dp.c
> @@ -377,7 +377,7 @@ bool bt_a2dp_register(const bdaddr_t *addr)
> record_id = rec->handle;
>
> ipc_register(HAL_SERVICE_ID_A2DP, cmd_handlers,
> - sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
> + G_N_ELEMENTS(cmd_handlers));
>
> return true;
> }
> diff --git a/android/bluetooth.c b/android/bluetooth.c
> index a39e7bf..6174b1f 100644
> --- a/android/bluetooth.c
> +++ b/android/bluetooth.c
> @@ -2418,7 +2418,7 @@ void bt_bluetooth_register(void)
> DBG("");
>
> ipc_register(HAL_SERVICE_ID_BLUETOOTH, cmd_handlers,
> - sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
> + G_N_ELEMENTS(cmd_handlers));
> }
>
> void bt_bluetooth_unregister(void)
> diff --git a/android/hidhost.c b/android/hidhost.c
> index 38194d0..8bfdfed 100644
> --- a/android/hidhost.c
> +++ b/android/hidhost.c
> @@ -1279,7 +1279,7 @@ bool bt_hid_register(const bdaddr_t *addr)
> }
>
> ipc_register(HAL_SERVICE_ID_HIDHOST, cmd_handlers,
> - sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
> + G_N_ELEMENTS(cmd_handlers));
>
> return true;
> }
> diff --git a/android/main.c b/android/main.c
> index b9655c5..5210b4b 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -430,7 +430,7 @@ int main(int argc, char *argv[])
> start_sdp_server(0, 0);
>
> ipc_register(HAL_SERVICE_ID_CORE, cmd_handlers,
> - sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
> + G_N_ELEMENTS(cmd_handlers));
>
> DBG("Entering main loop");
>
> diff --git a/android/pan.c b/android/pan.c
> index 3270aa4..fe6ee26 100644
> --- a/android/pan.c
> +++ b/android/pan.c
> @@ -322,7 +322,7 @@ bool bt_pan_register(const bdaddr_t *addr)
> }
>
> ipc_register(HAL_SERVICE_ID_PAN, cmd_handlers,
> - sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
> + G_N_ELEMENTS(cmd_handlers));
>
> return true;
> }
> diff --git a/android/socket.c b/android/socket.c
> index 76b40c8..c9eca44 100644
> --- a/android/socket.c
> +++ b/android/socket.c
> @@ -929,7 +929,7 @@ void bt_socket_register(const bdaddr_t *addr)
>
> bacpy(&adapter_addr, addr);
> ipc_register(HAL_SERVICE_ID_SOCK, cmd_handlers,
> - sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
> + G_N_ELEMENTS(cmd_handlers));
> }
>
> void bt_socket_unregister(void)
> --
> 1.8.3.2
Applied, thanks.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH BlueZ] audio/AVCTP: Fix crash
From: Anderson Lizardo @ 2013-12-03 12:22 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: BlueZ development
In-Reply-To: <CABBYNZJvw0v8-xJkbh5_92EszcUeU23L4FDnEd6BQJ01GD2-aw@mail.gmail.com>
Hi Luiz,
On Tue, Dec 3, 2013 at 7:40 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> Hi Anderson,
>
> On Tue, Dec 3, 2013 at 1:24 PM, Anderson Lizardo
> <anderson.lizardo@openbossa.org> wrote:
>> Hi Luiz,
>>
>> On Tue, Dec 3, 2013 at 5:36 AM, Luiz Augusto von Dentz
>> <luiz.dentz@gmail.com> wrote:
>>> --- a/profiles/audio/avctp.c
>>> +++ b/profiles/audio/avctp.c
>>> @@ -1488,7 +1488,7 @@ static struct avctp_pending_req *pending_create(struct avctp_channel *chan,
>>> tmp = g_slist_copy(chan->processed);
>>>
>>> /* Find first unused transaction id */
>>> - for (l = tmp; l; l = l->next) {
>>> + for (l = tmp; l; l = g_slist_next(l)) {
>>
>> Are you sure this fixes the problem? AFAIK g_list_next() will still
>> access invalid memory unless the "next" pointer is saved *before* the
>> current entry is freed. See e.g. remove_temp_devices() in
>> src/adapter.c.
>
> Yep, I tested and it fixes the problem. The problem is not actually
> removing the item, but reassigning tmp to the head of the list which
> can be NULL so doing l = l->next before deleting the node doesn't help
> in this case. Anyway this is now applied but we will be changing the
> logic how to check the available transaction to use bitmask operations
> so we find the next transaction without looping in a list.
In this case I agree that it is not the same situation as I described.
I was looking only at the patch itself, not the original code :/ In
any case, good to know you are going to simplify it.
BTW, I noticed that the "chan->transaction %= 16;" in that same
function (in two places) is unnecessary, because chan->transaction is
"uint8_t transaction:4" (4-bit bitfield) so the post increment
operation before this statement will always overflow "transaction" and
it will go back to 0 once it reaches 15.
Best Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* [PATCH] android: Fix missing failure check in ipc_init
From: Szymon Janc @ 2013-12-03 12:42 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
If connecting command socket failed daemon should be terminated.
---
android/ipc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/android/ipc.c b/android/ipc.c
index 1d369a8..6f940cd 100644
--- a/android/ipc.c
+++ b/android/ipc.c
@@ -229,6 +229,8 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
void ipc_init(void)
{
cmd_io = connect_hal(cmd_connect_cb);
+ if (!cmd_io)
+ raise(SIGTERM);
}
void ipc_cleanup(void)
--
1.8.3.2
^ permalink raw reply related
* [PATCHv1 0/2] Introduce default adapter property
From: Timo Mueller @ 2013-12-03 15:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Timo Mueller
From: Timo Mueller <timo.mueller@bmw-carit.de>
Hi,
the information about the default adapter is currently not available
through the D-Bus API of BlueZ. But as plugins can use this
information to choose the adapter they act upon it would be helpful
for users to be able to retrieve this information as well.
For example the neard plugin uses this information to decide for which
adapter oob data is generated. Users could use the same information to
power the adapter before actually sending the oob data.
Best regards,
Timo
Timo Mueller (2):
doc: Introduce default adapter property
adapter: Introduce default adapter property
doc/adapter-api.txt | 9 +++++++++
src/adapter.c | 15 +++++++++++++++
2 files changed, 24 insertions(+)
--
1.8.3.1
^ permalink raw reply
* [PATCHv1 1/2] doc: Introduce default adapter property
From: Timo Mueller @ 2013-12-03 15:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Timo Mueller
In-Reply-To: <cover.1386078490.git.timo.mueller@bmw-carit.de>
From: Timo Mueller <timo.mueller@bmw-carit.de>
Some plugins choose a default adapter when no specific adapter has
been selected. This information was not exposed in the adapters D-Bus
properties.
With the new property users can find out which adapter is used if no
adapter has been specified. This allows them to change the properties
of the adapter beforehand, e.g. powering the adapter before oob data
is sent.
---
doc/adapter-api.txt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index 74d235a..9990432 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -153,3 +153,12 @@ Properties string Address [readonly]
Local Device ID information in modalias format
used by the kernel and udev.
+
+ boolean Default [readonly]
+
+ Indicates that the adapter is the default adapter. The
+ default adapter is used when multiple adapters exist and
+ no specific adapter has been selected.
+
+ In case the default adapter is removed, one of the
+ remaining adapters will become the new default adapter.
--
1.8.3.1
^ permalink raw reply related
* [PATCHv1 2/2] adapter: Introduce default adapter property
From: Timo Mueller @ 2013-12-03 15:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Timo Mueller
In-Reply-To: <cover.1386078490.git.timo.mueller@bmw-carit.de>
From: Timo Mueller <timo.mueller@bmw-carit.de>
Some plugins choose a default adapter when no specific adapter has
been selected. This information was not exposed in the adapters D-Bus
properties.
With the new property users can find out which adapter is used if no
adapter has been specified. This allows them to change the properties
of the adapter beforehand, e.g. powering the adapter before oob data
is sent.
---
src/adapter.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index 41f7bd6..46174d6 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2126,6 +2126,17 @@ static gboolean property_get_modalias(const GDBusPropertyTable *property,
return TRUE;
}
+static gboolean property_get_default(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *user_data)
+{
+ struct btd_adapter *adapter = user_data;
+ dbus_bool_t is_default = btd_adapter_is_default(adapter);
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &is_default);
+
+ return TRUE;
+}
+
static int device_path_cmp(gconstpointer a, gconstpointer b)
{
const struct btd_device *device = a;
@@ -2193,6 +2204,7 @@ static const GDBusPropertyTable adapter_properties[] = {
{ "UUIDs", "as", property_get_uuids },
{ "Modalias", "s", property_get_modalias, NULL,
property_exists_modalias },
+ { "Default", "b", property_get_default },
{ }
};
@@ -5673,6 +5685,9 @@ static int adapter_unregister(struct btd_adapter *adapter)
new_default = adapters->data;
new_default->is_default = true;
+
+ g_dbus_emit_property_changed(dbus_conn, new_default->path,
+ ADAPTER_INTERFACE, "Default");
}
adapter_list = g_list_remove(adapter_list, adapter);
--
1.8.3.1
^ permalink raw reply related
* [PATCHv2 0/4] Socket optimization
From: Andrei Emeltchenko @ 2013-12-03 15:51 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
These patches add socket optimization wrt to buffer size.
Andrei Emeltchenko (4):
android/socket: Cleanup sockets on unregister
android/socket Use 64K buffer for socket handling
android/socket: Use heap instead of stack
android/socket: Setup socket buffer sizes
android/socket.c | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
--
1.8.3.2
^ permalink raw reply
* [PATCHv2 1/4] android/socket: Cleanup sockets on unregister
From: Andrei Emeltchenko @ 2013-12-03 15:51 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085873-21715-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This cleans up rfsock structures closing all sockets and making general cleanup
for servers and for connections. This will be called form socket unregister.
---
android/socket.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/android/socket.c b/android/socket.c
index c9eca44..9020874 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -93,8 +93,10 @@ static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
return rfsock;
}
-static void cleanup_rfsock(struct rfcomm_sock *rfsock)
+static void cleanup_rfsock(gpointer data)
{
+ struct rfcomm_sock *rfsock = data;
+
DBG("rfsock: %p fd %d real_sock %d chan %u",
rfsock, rfsock->fd, rfsock->real_sock, rfsock->channel);
@@ -936,5 +938,8 @@ void bt_socket_unregister(void)
{
DBG("");
+ g_list_free_full(connections, cleanup_rfsock);
+ g_list_free_full(servers, cleanup_rfsock);
+
ipc_unregister(HAL_SERVICE_ID_SOCK);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 2/4] android/socket Use 64K buffer for socket handling
From: Andrei Emeltchenko @ 2013-12-03 15:51 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085873-21715-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Make SOCKET_BUFFER define and use 0xFFFE instead of 1K.
The value 0XFFFE is what Android sends in OBEX Connect packet in
Maximum Packet Length field. Though OBEX specify meximum packet
length as 64K - 1 which is 0xFFFF.
---
android/socket.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 9020874..9ff9019 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -52,6 +52,8 @@
#define SVC_HINT_OBEX 0x10
+#define SOCKET_BUFFER 0xFFFE
+
static bdaddr_t adapter_addr;
/* Simple list of RFCOMM server sockets */
@@ -487,7 +489,7 @@ static gboolean sock_stack_event_cb(GIOChannel *io, GIOCondition cond,
gpointer data)
{
struct rfcomm_sock *rfsock = data;
- unsigned char buf[1024];
+ unsigned char buf[SOCKET_BUFFER];
int len, sent;
if (cond & G_IO_HUP) {
@@ -526,7 +528,7 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
gpointer data)
{
struct rfcomm_sock *rfsock = data;
- unsigned char buf[1024];
+ unsigned char buf[SOCKET_BUFFER];
int len, sent;
if (cond & G_IO_HUP) {
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 3/4] android/socket: Use heap instead of stack
From: Andrei Emeltchenko @ 2013-12-03 15:51 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085873-21715-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Keep buffer used in socket copy in heap instead of stack.
---
android/socket.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 9ff9019..6293b59 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -73,6 +73,8 @@ struct rfcomm_sock {
bdaddr_t dst;
uint32_t service_handle;
+ unsigned char *buf;
+
const struct profile_info *profile;
};
@@ -92,6 +94,8 @@ static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
*hal_fd = fds[1];
rfsock->real_sock = sock;
+ rfsock->buf = g_malloc(SOCKET_BUFFER);
+
return rfsock;
}
@@ -123,6 +127,8 @@ static void cleanup_rfsock(gpointer data)
if (rfsock->service_handle)
bt_adapter_remove_record(rfsock->service_handle);
+ g_free(rfsock->buf);
+
g_free(rfsock);
}
@@ -489,7 +495,6 @@ static gboolean sock_stack_event_cb(GIOChannel *io, GIOCondition cond,
gpointer data)
{
struct rfcomm_sock *rfsock = data;
- unsigned char buf[SOCKET_BUFFER];
int len, sent;
if (cond & G_IO_HUP) {
@@ -503,14 +508,14 @@ static gboolean sock_stack_event_cb(GIOChannel *io, GIOCondition cond,
goto fail;
}
- len = read(rfsock->fd, buf, sizeof(buf));
+ len = read(rfsock->fd, rfsock->buf, SOCKET_BUFFER);
if (len <= 0) {
error("read(): %s", strerror(errno));
/* Read again */
return TRUE;
}
- sent = try_write_all(rfsock->real_sock, buf, len);
+ sent = try_write_all(rfsock->real_sock, rfsock->buf, len);
if (sent < 0) {
error("write(): %s", strerror(errno));
goto fail;
@@ -528,7 +533,6 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
gpointer data)
{
struct rfcomm_sock *rfsock = data;
- unsigned char buf[SOCKET_BUFFER];
int len, sent;
if (cond & G_IO_HUP) {
@@ -542,14 +546,14 @@ static gboolean sock_rfcomm_event_cb(GIOChannel *io, GIOCondition cond,
goto fail;
}
- len = read(rfsock->real_sock, buf, sizeof(buf));
+ len = read(rfsock->real_sock, rfsock->buf, SOCKET_BUFFER);
if (len <= 0) {
error("read(): %s", strerror(errno));
/* Read again */
return TRUE;
}
- sent = try_write_all(rfsock->fd, buf, len);
+ sent = try_write_all(rfsock->fd, rfsock->buf, len);
if (sent < 0) {
error("write(): %s", strerror(errno));
goto fail;
--
1.8.3.2
^ permalink raw reply related
* [PATCHv2 4/4] android/socket: Setup socket buffer sizes
From: Andrei Emeltchenko @ 2013-12-03 15:51 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085873-21715-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Set socket buffer sizes for socketpair's end and real RFCOMM socket
equal to SOCKET_BUFFER.
---
android/socket.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/android/socket.c b/android/socket.c
index 6293b59..3898767 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -82,6 +82,9 @@ static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
{
int fds[2] = {-1, -1};
struct rfcomm_sock *rfsock;
+ socklen_t len = sizeof(int);
+ int size = SOCKET_BUFFER;
+ int i;
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) < 0) {
error("socketpair(): %s", strerror(errno));
@@ -94,6 +97,15 @@ static struct rfcomm_sock *create_rfsock(int sock, int *hal_fd)
*hal_fd = fds[1];
rfsock->real_sock = sock;
+ for (i = 0; i < 2; i++) {
+ if (setsockopt(fds[i], SOL_SOCKET, SO_SNDBUF, &size, len) < 0)
+ warn("setsockopt() SO_SNDBUF fd: %d %s", fds[i],
+ strerror(errno));
+ if (setsockopt(fds[i], SOL_SOCKET, SO_RCVBUF, &size, len) < 0)
+ warn("setsockopt() SO_RCVBUF fd: %d %s", fds[i],
+ strerror(errno));
+ }
+
rfsock->buf = g_malloc(SOCKET_BUFFER);
return rfsock;
--
1.8.3.2
^ permalink raw reply related
* [PATCH 1/6] android/a2dp: Fix possible NULL dereference
From: Andrei Emeltchenko @ 2013-12-03 15:53 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Since a2dp_record may return NULL, check return value. This
silences static analysers tools.
---
android/a2dp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/android/a2dp.c b/android/a2dp.c
index cee4bfa..36a0714 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -366,9 +366,10 @@ bool bt_a2dp_register(const bdaddr_t *addr)
}
rec = a2dp_record();
- if (bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) {
+ if (!rec || bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) {
error("Failed to register on A2DP record");
- sdp_record_free(rec);
+ if (rec)
+ sdp_record_free(rec);
g_io_channel_shutdown(server, TRUE, NULL);
g_io_channel_unref(server);
server = NULL;
--
1.8.3.2
^ permalink raw reply related
* [PATCH 2/6] android/pan: Remove unneeded NULL assignment
From: Andrei Emeltchenko @ 2013-12-03 15:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085993-22055-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/pan.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/android/pan.c b/android/pan.c
index fe6ee26..87fa4e8 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -81,7 +81,6 @@ static void pan_device_free(struct pan_device *dev)
devices = g_slist_remove(devices, dev);
g_free(dev);
- dev = NULL;
}
static void bt_pan_notify_conn_state(struct pan_device *dev, uint8_t state)
--
1.8.3.2
^ permalink raw reply related
* [PATCH 3/6] android/pan: Fix no return on error path
From: Andrei Emeltchenko @ 2013-12-03 15:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085993-22055-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This fixes possible crash in case connect fails.
---
android/pan.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/android/pan.c b/android/pan.c
index 87fa4e8..7e9b3c3 100644
--- a/android/pan.c
+++ b/android/pan.c
@@ -172,6 +172,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer data)
error("%s", err->message);
bt_pan_notify_conn_state(dev, HAL_PAN_STATE_DISCONNECTED);
pan_device_free(dev);
+ return;
}
src = (local_role == HAL_PAN_ROLE_NAP) ? BNEP_SVC_NAP : BNEP_SVC_PANU;
--
1.8.3.2
^ permalink raw reply related
* [PATCH 4/6] android/doc: Add socket-api.txt document
From: Andrei Emeltchenko @ 2013-12-03 15:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085993-22055-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Document describes how socket HAL is working.
---
android/socket-api.txt | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 android/socket-api.txt
diff --git a/android/socket-api.txt b/android/socket-api.txt
new file mode 100644
index 0000000..9f622f9
--- /dev/null
+++ b/android/socket-api.txt
@@ -0,0 +1,61 @@
+Android Socket protocol for Bluetooth
+=====================================
+
+Since Android switched from BlueZ (where sockets where nicely implemented) to
+Bluedroid user space stack there is a need to emulate bluetooth sockets.
+
+Android Bluetooth Socket Hardware Abstraction Layer (HAL) bt_sock.h has
+only 2 functions:
+
+static btsock_interface_t sock_if = {
+ sizeof(sock_if),
+ sock_listen,
+ sock_connect
+};
+
+with following parameters:
+
+sock_listen(btsock_type_t type, const char *service_name,
+ const uint8_t *uuid, int chan, int *sock_fd, int flags)
+sock_connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
+ const uint8_t *uuid, int chan, int *sock_fd, int flags)
+
+socket type RFCOMM is only supported at the moment. uuid and channel used
+to decide where to connect.
+
+sockfd is used to return socket fd to Android framework. It is used to inform
+framework when remote device is connected.
+
+listen()
+========
+
+Listens on RFCOMM socket, socket channel is either found based on uuid or
+channel parameter used directly. Returns sock_fd to Android framework.
+
+Through this sock_fd channel number as (int) needs to be written right after
+listen() succeeds.
+
+When remote device is connected to this socket we shall send accept signal
+through sock_fd
+
+connect()
+=========
+
+Connects to remote device specified in bd_addr parameter. Socket channel is
+found by SDP search of remote device by supplied uuid. Returns sock_fd to
+Android framework.
+
+Through this sock_fd channel number as (int) needs to be written right after
+connects() succeeds.
+
+When remote device is connected to this socket we shall send connect signal
+through sock_fd
+
+The format of connect/accept signal is shown below:
+
+struct hal_sock_connect_signal {
+ short size;
+ uint8_t bdaddr[6];
+ int channel;
+ int status;
+} __attribute__((packed));
--
1.8.3.2
^ permalink raw reply related
* [PATCH 5/6] sdp: Remove dead code
From: Andrei Emeltchenko @ 2013-12-03 15:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085993-22055-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
sdp_next_handle always returns value >= 0x10000.
---
src/sdpd-service.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index 38bf808..448c76b 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -424,10 +424,6 @@ int service_register_req(sdp_req_t *req, sdp_buf_t *rsp)
if (rec->handle == 0xffffffff) {
rec->handle = sdp_next_handle();
- if (rec->handle < 0x10000) {
- sdp_record_free(rec);
- goto invalid;
- }
} else {
if (sdp_record_find(rec->handle)) {
/* extract_pdu_server will add the record handle
--
1.8.3.2
^ permalink raw reply related
* [PATCH 6/6] avdtp: Remove unneeded local variable
From: Andrei Emeltchenko @ 2013-12-03 15:53 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386085993-22055-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
profiles/audio/avdtp.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index f866b39..e12ad9d 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -773,10 +773,9 @@ static int get_send_buffer_size(int sk)
socklen_t optlen = sizeof(size);
if (getsockopt(sk, SOL_SOCKET, SO_SNDBUF, &size, &optlen) < 0) {
- int err = -errno;
- error("getsockopt(SO_SNDBUF) failed: %s (%d)", strerror(-err),
- -err);
- return err;
+ error("getsockopt(SO_SNDBUF) failed: %s (%d)", strerror(errno),
+ errno);
+ return -errno;
}
/*
@@ -792,10 +791,9 @@ static int set_send_buffer_size(int sk, int size)
socklen_t optlen = sizeof(size);
if (setsockopt(sk, SOL_SOCKET, SO_SNDBUF, &size, optlen) < 0) {
- int err = -errno;
- error("setsockopt(SO_SNDBUF) failed: %s (%d)", strerror(-err),
- -err);
- return err;
+ error("setsockopt(SO_SNDBUF) failed: %s (%d)", strerror(errno),
+ errno);
+ return -errno;
}
return 0;
--
1.8.3.2
^ permalink raw reply related
* [PATCH] obex: Fix checking incorrect error code
From: Andrei Emeltchenko @ 2013-12-03 16:04 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
chdir return -1 if error and 0 in success. Checking for > 0 is pointless.
---
tools/obex-server-tool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/obex-server-tool.c b/tools/obex-server-tool.c
index e37c56f..86c2271 100644
--- a/tools/obex-server-tool.c
+++ b/tools/obex-server-tool.c
@@ -427,7 +427,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (option_root && chdir(option_root) > 0) {
+ if (option_root && chdir(option_root) < 0) {
perror("chdir:");
exit(EXIT_FAILURE);
}
--
1.8.3.2
^ permalink raw reply related
* Re: Missing BT_POWER option for l2cap sockets in bluetooth.h?
From: Mathieu Laurendeau @ 2013-12-03 17:46 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <20131203092228.GA9498@x220.p-661hnu-f1>
On Tue, Dec 03, 2013, Johan Hedberg wrote:
> What are you planning to use this for?
I'm working on a software [1] that can make a PC take the identity of a
Sixaxis and control a PS3 over bluetooth. It worked fine until kernel
3.1 from which there was a connection issue (a variable latency of at
least 4s). I tried tweaking the flush timeout, but it was not
concluding. Lately I took a look at the kernel source code and saw the
BT_POWER option was introduced in kernel 3.1. I turned it off and the
latency disappeared.
Thanks for the patch,
Mathieu
[1] https://github.com/matlo/GIMX
^ permalink raw reply
* Re: [PATCH 1/6] android/a2dp: Fix possible NULL dereference
From: Luiz Augusto von Dentz @ 2013-12-03 19:53 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1386085993-22055-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On Tue, Dec 3, 2013 at 5:53 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Since a2dp_record may return NULL, check return value. This
> silences static analysers tools.
> ---
> android/a2dp.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/android/a2dp.c b/android/a2dp.c
> index cee4bfa..36a0714 100644
> --- a/android/a2dp.c
> +++ b/android/a2dp.c
> @@ -366,9 +366,10 @@ bool bt_a2dp_register(const bdaddr_t *addr)
> }
>
> rec = a2dp_record();
> - if (bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) {
> + if (!rec || bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) {
Usually we check the return individually, that means you do if (rec)
and perhaps handle the error path with goto, but first make sure that
a2dp_record can actually fail otherwise this is pointless.
> error("Failed to register on A2DP record");
> - sdp_record_free(rec);
> + if (rec)
> + sdp_record_free(rec);
> g_io_channel_shutdown(server, TRUE, NULL);
> g_io_channel_unref(server);
> server = NULL;
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Luiz Augusto von Dentz
^ permalink raw reply
* tools: Parsing commands is lenient?
From: Karol Babioch @ 2013-12-03 21:27 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 1548 bytes --]
Hi,
I've stumbled across something, which is probably a feature, but I
couldn't find it documented anywhere, so I'm going to bring it up anyway.
The parsing of the "command" field for (at least) the tools "hcitool"
and "sdptool" is quite inaccurate. For example when I want to scan for
Bluetooth devices, I would use something like:
[johnpatcher@vpcs ~]$ hcitool scan
Scanning ...
This works great, but so does the following, too:
[johnpatcher@vpcs ~]$ hcitool scan123
Scanning ...
So, it seems that basically you can append whatever you want to a
command, as long as the command itself is valid.
First of all, I'm not sure whether it is actually a good idea to be
lenient when it comes down to parsing a command. I guess most of you are
around *nix systems even longer than me, but at least I'm used to some
sort of an error message as soon as I goof up a command on the console.
At least, theoretically speaking, one could come up with some scenarios,
where this could go terribly wrong when some commands are added and/or
changed.
Secondly, I think that this sort of behavior should actually be
documented when this is and/or was an explicit consideration, for
instance within the man page(s) of the appropriate tools.
Maybe I'm making too much of a fuss about this, but at least I was
*really* surprised by this. I just want to make sure that this isn't
something that was overlooked and/or introduced by a stupid
carelessness, but rather was a conscious decision.
Best regards,
Karol Babioch
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply
* Re: have to re-pair mouse every few hours (update: mouse needs periodic authorization?)
From: Brian J. Murrell @ 2013-12-03 21:43 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385843856.12122.5.camel@pc.interlinx.bc.ca>
[-- Attachment #1: Type: text/plain, Size: 1944 bytes --]
On Sat, 2013-11-30 at 15:37 -0500, Brian J. Murrell wrote:
> Hi,
>
> I'm using a Microsoft Sculpt Touch Mouse on a Fedora 19 machine
> (kernel-3.11.9-200.fc19.x86_64 and bluez-4.101-9.fc19.x86_64) with a:
>
> Bus 002 Device 019: ID 0a5c:2148 Broadcom Corp. BCM92046DG-CL1ROM Bluetooth 2.1 Adapter
>
> bluetooth adapter. This exact same configuration worked for months just
> fine with a Logitech bluetooth mouse. But sadly that mouse was crap
> (second one to fail within the warranty period of one of them) so
> replaced it with this MS one.
>
> The problem with this MS mouse is that it just goes AWOL and needs to be
> delete and re-paired with the machine every few hours. Typically it's
> after I have gotten up from the computer and have come back to it. But
> I have also had it just happen while using it.
>
> When this happens, the messages log reports messages such as:
>
> Nov 30 12:42:03 pc kernel: [2500032.028982] Bluetooth: Unexpected continuation frame (len 0)
> Nov 30 12:42:03 pc kernel: [2500032.115027] Bluetooth: Unexpected continuation frame (len 0)
>
> Any ideas what the problem might be here?
So an interesting development in this is that after a reboot, I am now
starting to see notification bubbles pop up when the mouse goes AWOL
that say:
Authorization request from 'Microsoft Sculpt Touch Mouse' with a "Check
authorization" button it. When I click that I get a dialog popping up
that says:
Grant access to '<uuid>'
Device 'Microsoft Sculpt Touch Mouse' (<MAC address>) wants access to
the service '<uuid>'.
With both a Reject and a Grant button as well as an "Always grant
access" checkbox.
Clicking Grant restores the functionality of the mouse and clearly I
could click the Always grant access checkbox to have this automatic.
I just wonder what this functionality is. I never had it with my
previous Logitech bluetooth mouse.
Cheers,
b.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply
* cross compiling bluez 4.101
From: Daniel Schultze @ 2013-12-03 22:38 UTC (permalink / raw)
To: linux-bluetooth
Hello Developers,
I'm having a bit of trouble cross compiling bluez 4.101 with an older
kernel 2.6.31. I'm using:
me@buildmachine:~/tmp/bluez-4.101$ arm-none-linux-gnueabi-gcc --version
arm-none-linux-gnueabi-gcc (GCC) 4.1.2
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I'll admit its a bit old but, its what I have to work with. In
addition I have built glibc 2.10.1, glib 2.28.8, and dbus 1.4.26
successfully to fulfill bluez's prerequisites.
This is error I'm getting:
CCLD src/bluetoothd
attrib/bluetoothd-gatt.o: In function `read_long_destroy':
gatt.c:(.text+0xfec): undefined reference to `__sync_fetch_and_sub_4'
attrib/bluetoothd-gatt.o: In function `read_blob_helper':
gatt.c:(.text+0x121c): undefined reference to `__sync_fetch_and_add_4'
attrib/bluetoothd-gatt.o: In function `read_char_helper':
gatt.c:(.text+0x13e8): undefined reference to `__sync_fetch_and_add_4'
attrib/bluetoothd-gatt.o: In function `gatt_read_char':
gatt.c:(.text+0x15d8): undefined reference to `__sync_fetch_and_add_4'
attrib/bluetoothd-gattrib.o: In function `g_attrib_ref':
gattrib.c:(.text+0x1fc): undefined reference to `__sync_fetch_and_add_4'
attrib/bluetoothd-gattrib.o: In function `g_attrib_unref':
gattrib.c:(.text+0x528): undefined reference to `__sync_fetch_and_sub_4'
collect2: ld returned 1 exit status
make[1]: *** [src/bluetoothd] Error 1
make: *** [all] Error 2
and I have configured using this line (for building outside of ltib):
./configure CFLAGS="--sysroot=/home/me/ltib_me/rootfs -march=armv5te"
--prefix=/usr --build=$MACHTYPE --host=arm-none-linux-gnueabi
--disable-alsa --disable-audio --enable-gatt --disable-pcmcia
--disable-gstreamer
and the build machine is:
me@buildmachine:~/tmp/bluez-4.101$ echo $MACHTYPE
i686-pc-linux-gnu
me@buildmachine:~/tmp/bluez-4.101$ uname -a
Linux buildmachine 3.0.0-12-generic-pae #20-Ubuntu SMP Fri Oct 7
16:37:17 UTC 2011 i686 i686 i386 GNU/Linux
me@buildmachine:~/tmp/bluez-4.101$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 11.10
Release: 11.10
Codename: oneiric
Any help on resolving this error would be appreciated.
^ permalink raw reply
* Re: have to re-pair mouse every few hours (update: mouse needs periodic authorization?)
From: Bastien Nocera @ 2013-12-03 23:12 UTC (permalink / raw)
To: Brian J. Murrell; +Cc: linux-bluetooth
In-Reply-To: <1386107032.8730.22.camel@pc.interlinx.bc.ca>
On Tue, 2013-12-03 at 16:43 -0500, Brian J. Murrell wrote:
> On Sat, 2013-11-30 at 15:37 -0500, Brian J. Murrell wrote:
> > Hi,
> >
> > I'm using a Microsoft Sculpt Touch Mouse on a Fedora 19 machine
> > (kernel-3.11.9-200.fc19.x86_64 and bluez-4.101-9.fc19.x86_64) with a:
> >
> > Bus 002 Device 019: ID 0a5c:2148 Broadcom Corp. BCM92046DG-CL1ROM Bluetooth 2.1 Adapter
> >
> > bluetooth adapter. This exact same configuration worked for months just
> > fine with a Logitech bluetooth mouse. But sadly that mouse was crap
> > (second one to fail within the warranty period of one of them) so
> > replaced it with this MS one.
> >
> > The problem with this MS mouse is that it just goes AWOL and needs to be
> > delete and re-paired with the machine every few hours. Typically it's
> > after I have gotten up from the computer and have come back to it. But
> > I have also had it just happen while using it.
> >
> > When this happens, the messages log reports messages such as:
> >
> > Nov 30 12:42:03 pc kernel: [2500032.028982] Bluetooth: Unexpected continuation frame (len 0)
> > Nov 30 12:42:03 pc kernel: [2500032.115027] Bluetooth: Unexpected continuation frame (len 0)
> >
> > Any ideas what the problem might be here?
>
> So an interesting development in this is that after a reboot, I am now
> starting to see notification bubbles pop up when the mouse goes AWOL
> that say:
>
> Authorization request from 'Microsoft Sculpt Touch Mouse' with a "Check
> authorization" button it. When I click that I get a dialog popping up
> that says:
>
> Grant access to '<uuid>'
>
> Device 'Microsoft Sculpt Touch Mouse' (<MAC address>) wants access to
> the service '<uuid>'.
>
> With both a Reject and a Grant button as well as an "Always grant
> access" checkbox.
>
> Clicking Grant restores the functionality of the mouse and clearly I
> could click the Always grant access checkbox to have this automatic.
Just how did you pair your mouse?
^ permalink raw reply
* Re: have to re-pair mouse every few hours (update: mouse needs periodic authorization?)
From: Brian J. Murrell @ 2013-12-04 0:06 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1386112361.5405.37.camel@nuvo>
[-- Attachment #1: Type: text/plain, Size: 163 bytes --]
On Wed, 2013-12-04 at 00:12 +0100, Bastien Nocera wrote:
>
> Just how did you pair your mouse?
With mate[gnome]-bluetooth-properties.
Cheers,
b.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ 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