* [PATCH 5/7] android: Remove not needed bt_adapter_get_address function
From: Szymon Janc @ 2013-11-12 0:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384215857-19679-1-git-send-email-szymon.janc@tieto.com>
All services receive adapter address on init so there is no need for
this function. Removing it will also help keeping services not depend
on adapter service.
---
android/adapter.c | 5 -----
android/adapter.h | 2 --
2 files changed, 7 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index f337b5e..e083131 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1968,11 +1968,6 @@ error:
ipc_send_rsp(sk, HAL_SERVICE_ID_BLUETOOTH, status);
}
-const bdaddr_t *bt_adapter_get_address(void)
-{
- return &adapter_bdaddr;
-}
-
bool bt_adapter_register(int sk)
{
DBG("");
diff --git a/android/adapter.h b/android/adapter.h
index 96136bb..94c97ac 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -31,7 +31,5 @@ void bt_adapter_cleanup(void);
void bt_adapter_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
-const bdaddr_t *bt_adapter_get_address(void);
-
bool bt_adapter_register(int sk);
void bt_adapter_unregister(void);
--
1.8.4.2
^ permalink raw reply related
* [PATCH 7/7] android: Rename bluetooth service functions to match service name
From: Szymon Janc @ 2013-11-12 0:24 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384215857-19679-1-git-send-email-szymon.janc@tieto.com>
Make public functions match service name.
---
android/bluetooth.c | 16 ++++++++--------
android/bluetooth.h | 16 ++++++++--------
android/main.c | 13 +++++++------
3 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index b3a6e20..9545ec4 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -61,7 +61,7 @@ static GSList *browse_reqs;
static uint16_t option_index = MGMT_INDEX_NONE;
static uint16_t adapter_index = MGMT_INDEX_NONE;
static struct mgmt *mgmt_if = NULL;
-static bt_adapter_ready adapter_ready = NULL;
+static bt_bluetooth_ready adapter_ready = NULL;
static bdaddr_t adapter_bdaddr;
static uint32_t adapter_dev_class = 0;
static char *adapter_name = NULL;
@@ -1272,7 +1272,7 @@ failed:
adapter_ready(-EIO, NULL);
}
-bool bt_adapter_start(int index, bt_adapter_ready cb)
+bool bt_bluetooth_start(int index, bt_bluetooth_ready cb)
{
DBG("index %d", index);
@@ -1303,7 +1303,7 @@ bool bt_adapter_start(int index, bt_adapter_ready cb)
static void shutdown_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
- bt_adapter_stopped cb = user_data;
+ bt_bluetooth_stopped cb = user_data;
if (status != MGMT_STATUS_SUCCESS)
error("Clean controller shutdown failed");
@@ -1311,7 +1311,7 @@ static void shutdown_complete(uint8_t status, uint16_t length,
cb();
}
-bool bt_adapter_stop(bt_adapter_stopped cb)
+bool bt_bluetooth_stop(bt_bluetooth_stopped cb)
{
struct mgmt_mode cp;
@@ -1327,7 +1327,7 @@ bool bt_adapter_stop(bt_adapter_stopped cb)
NULL) > 0;
}
-void bt_adapter_cleanup(void)
+void bt_bluetooth_cleanup(void)
{
g_free(adapter_name);
adapter_name = NULL;
@@ -1849,7 +1849,7 @@ static uint8_t get_remote_services(void *buf, uint16_t len)
return browse_remote_sdp(&addr);
}
-void bt_adapter_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
+void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
{
uint8_t status = HAL_STATUS_FAILED;
@@ -1968,7 +1968,7 @@ error:
ipc_send_rsp(sk, HAL_SERVICE_ID_BLUETOOTH, status);
}
-bool bt_adapter_register(int sk)
+bool bt_bluetooth_register(int sk)
{
DBG("");
@@ -1977,7 +1977,7 @@ bool bt_adapter_register(int sk)
return true;
}
-void bt_adapter_unregister(void)
+void bt_bluetooth_unregister(void)
{
DBG("");
diff --git a/android/bluetooth.h b/android/bluetooth.h
index 94c97ac..88ec326 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
@@ -21,15 +21,15 @@
*
*/
-typedef void (*bt_adapter_ready)(int err, const bdaddr_t *addr);
-bool bt_adapter_start(int index, bt_adapter_ready cb);
+typedef void (*bt_bluetooth_ready)(int err, const bdaddr_t *addr);
+bool bt_bluetooth_start(int index, bt_bluetooth_ready cb);
-typedef void (*bt_adapter_stopped)(void);
-bool bt_adapter_stop(bt_adapter_stopped cb);
+typedef void (*bt_bluetooth_stopped)(void);
+bool bt_bluetooth_stop(bt_bluetooth_stopped cb);
-void bt_adapter_cleanup(void);
+void bt_bluetooth_cleanup(void);
-void bt_adapter_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
+void bt_bluetooth_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
-bool bt_adapter_register(int sk);
-void bt_adapter_unregister(void);
+bool bt_bluetooth_register(int sk);
+void bt_bluetooth_unregister(void);
diff --git a/android/main.c b/android/main.c
index e4c93ec..cbbfc06 100644
--- a/android/main.c
+++ b/android/main.c
@@ -84,7 +84,7 @@ static void service_register(void *buf, uint16_t len)
switch (m->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
- if (!bt_adapter_register(sk))
+ if (!bt_bluetooth_register(sk))
goto failed;
break;
@@ -134,7 +134,7 @@ static void service_unregister(void *buf, uint16_t len)
switch (m->service_id) {
case HAL_SERVICE_ID_BLUETOOTH:
- bt_adapter_unregister();
+ bt_bluetooth_unregister();
break;
case HAL_SERVICE_ID_SOCK:
bt_socket_unregister();
@@ -203,7 +203,7 @@ static void stop_bluetooth(void)
__stop = true;
- if (!bt_adapter_stop(bluetooth_stopped)) {
+ if (!bt_bluetooth_stop(bluetooth_stopped)) {
g_main_loop_quit(event_loop);
return;
}
@@ -251,7 +251,8 @@ static gboolean cmd_watch_cb(GIOChannel *io, GIOCondition cond,
handle_service_core(msg->opcode, msg->payload, msg->len);
break;
case HAL_SERVICE_ID_BLUETOOTH:
- bt_adapter_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
+ bt_bluetooth_handle_cmd(fd, msg->opcode, msg->payload,
+ msg->len);
break;
case HAL_SERVICE_ID_HIDHOST:
bt_hid_handle_cmd(fd, msg->opcode, msg->payload, msg->len);
@@ -560,7 +561,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (!bt_adapter_start(option_index, adapter_ready))
+ if (!bt_bluetooth_start(option_index, adapter_ready))
return EXIT_FAILURE;
/* Use params: mtu = 0, flags = 0 */
@@ -574,7 +575,7 @@ int main(int argc, char *argv[])
cleanup_hal_connection();
stop_sdp_server();
- bt_adapter_cleanup();
+ bt_bluetooth_cleanup();
g_main_loop_unref(event_loop);
info("Exit");
--
1.8.4.2
^ permalink raw reply related
* Re: Problems with too many connections
From: Markus Roppelt @ 2013-11-12 8:29 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <A43EED3E-8B1F-4C4C-B7A9-26065DE55928@holtmann.org>
2013/9/27 Marcel Holtmann <marcel@holtmann.org>
>
> Hi Markus,
>
> > I want to write an application which repeats the following procedure
> > for several (100+) bluetooth (low energy) devices:
> >
> > 1. connect
> > 2. read register values
> > 3. disconnect
> >
> > Therefore I modified the source code from /attrib/interactive.c. For
> > testing purposes I am only looping over one device. See attached
> > source code.
> >
> > The code works fine. It connects, reads the values and disconnects.
> > However, after 1020 repetitions, the following error occurs:
> > (process:10205): GLib-WARNING **: poll(2) failed due to: Invalid argument.
> >
> > I think the problem has to do with some sockets / file descriptors not
> > being closed properly.
> >
> > Can someone help me to get this fixed?
>
> have you considered trying to write this from scratch and not basing this off existing code.
>
> And yes, this will be most likely an issues with GSource handling of the attribute IO channel, but since you hacked the code is extremely hard to debug. It was never designed for what you are doing.
>
> Regards
>
> Marcel
>
I found a solution myself. I quote from:
https://github.com/webOS-ports/nyx-modules/commit/bbcbbd64000ba76f39215e43a5179408ff96e097
"When a watch is added to the
glib mainloop it references internally a file descriptor to pass it
later to the poll
function (see poll(2)). Every watch gets an id which should be used by
the user to refer
to the watch whenever needed. When the io channel is destroyed the
watch should be remove
from the mainloop as well. If this isn't done probably by the user it
will cause the
internal list of fds which are passed to the poll function to exceed
the maximum of 256.
This finally results in poll returning EINVAL as error code."
With the additions from there my code runs without problems.
Greetings
Markus
^ permalink raw reply
* Re: [RFCv1 4/9] android/hal-sock: Initial listen handle
From: Marcin Kraglak @ 2013-11-12 8:45 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1384178627-25991-5-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi Andrei,
On 11 November 2013 15:03, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Handle HAL socket listen call. Create RFCOMM socket and wait for events.
> ---
> android/socket.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 92 insertions(+), 2 deletions(-)
>
> diff --git a/android/socket.c b/android/socket.c
> index c283c5f..80cb39e 100644
> --- a/android/socket.c
> +++ b/android/socket.c
> @@ -27,22 +27,112 @@
>
> #include <glib.h>
> #include <stdbool.h>
> +#include <errno.h>
>
> #include "lib/bluetooth.h"
> +#include "btio/btio.h"
> #include "log.h"
> #include "hal-msg.h"
> #include "hal-ipc.h"
> #include "ipc.h"
> +#include "adapter.h"
> #include "socket.h"
>
> +/* Simple list of RFCOMM server sockets */
> +GList *rfcomm_srv_list = NULL;
> +/* Simple list of RFCOMM accepted sockets */
> +GList *rfcomm_accepted_list = NULL;
>
> -static int handle_listen(void *buf)
> +struct rfcomm_slot {
> + int fd;
> + int hal_fd;
> + int real_sock;
> + uint32_t channel;
> +};
> +
> +static struct rfcomm_slot *create_rfslot(int sock)
> {
> - DBG("Not implemented");
> + int fds[2] = {-1, -1};
> + struct rfcomm_slot *rfslot;
> +
> + if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) < 0) {
> + error("socketpair(): %s", strerror(errno));
> + return NULL;
> + }
> +
> + rfslot = g_malloc0(sizeof(*rfslot));
> + rfslot->fd = fds[0];
> + rfslot->hal_fd = fds[1];
> + rfslot->real_sock = sock;
> +
> + return rfslot;
> +}
> +
> +static const uint8_t UUID_PBAP[] = {
> + 0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00,
> + 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
> +};
> +#define RFCOMM_CHAN_PBAP 19
> +
> +static const uint8_t UUID_OPP[] = {
> + 0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
> + 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
> +};
> +#define RFCOMM_CHAN_OPP 12
> +
> +static int get_rfcomm_chan(const uint8_t *uuid)
> +{
> + if (!memcmp(UUID_PBAP, uuid, sizeof(UUID_PBAP)))
> + return RFCOMM_CHAN_PBAP;
> +
> + if (!memcmp(UUID_OPP, uuid, sizeof(UUID_OPP)))
> + return RFCOMM_CHAN_OPP;
>
> return -1;
> }
>
> +static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
> +{
> +}
> +
> +static int handle_listen(void *buf)
> +{
> + struct hal_cmd_sock_listen *cmd = buf;
> + const bdaddr_t *src = bt_adapter_get_address();
> + struct rfcomm_slot *rfslot;
> + GIOChannel *io;
> + GError *err = NULL;
> + int ch;
> +
> + DBG("");
> +
> + ch = get_rfcomm_chan(cmd->uuid);
> + if (ch < 0)
> + return -1;
> +
> + DBG("rfcomm channel %u", ch);
> +
> + rfslot = create_rfslot(-1);
> +
> + io = bt_io_listen(connect_cb, NULL, rfslot, NULL, &err,
> + BT_IO_OPT_SOURCE_BDADDR, src,
> + BT_IO_OPT_CHANNEL, ch,
> + BT_IO_OPT_INVALID);
> + if (!io) {
> + error("Failed listen: %s", err->message);
shouldn't we free rfslot in case of error?
> + g_error_free(err);
> + return -1;
> + }
> +
> + rfslot->real_sock = g_io_channel_unix_get_fd(io);
> + rfcomm_srv_list = g_list_append(rfcomm_srv_list, rfslot);
> +
> + DBG("real_sock %d fd %d hal_fd %d",
> + rfslot->real_sock, rfslot->fd, rfslot->hal_fd);
> +
> + return rfslot->hal_fd;
> +}
> +
> static int handle_connect(void *buf)
> {
> DBG("Not implemented");
> --
> 1.7.10.4
>
> --
> 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
Best regards
Marcin
^ permalink raw reply
* Re: [PATCH] obex: Use user's cache dir as a default root
From: Luiz Augusto von Dentz @ 2013-11-12 8:58 UTC (permalink / raw)
To: Bastien Nocera; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1384093460.4593.8.camel@nuvo>
Hi Bastien,
On Sun, Nov 10, 2013 at 4:24 PM, Bastien Nocera <hadess@hadess.net> wrote:
>
> It's per-user, so we won't try to overwrite somebody else's
> files in /tmp when that happens. It's also (unless we have a
> particularly bizarre setup) on the same partition as the destination
> folder which means we can atomically move the file to the destination
> with a unique filename.
> ---
> obexd/src/main.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/obexd/src/main.c b/obexd/src/main.c
> index 61a06b2..2f7d723 100644
> --- a/obexd/src/main.c
> +++ b/obexd/src/main.c
> @@ -50,8 +50,6 @@
> #include "obexd.h"
> #include "server.h"
>
> -#define DEFAULT_ROOT_PATH "/tmp"
> -
> #define DEFAULT_CAP_FILE CONFIGDIR "/capability.xml"
>
> static GMainLoop *main_loop = NULL;
> @@ -285,8 +283,10 @@ int main(int argc, char *argv[])
> exit(EXIT_FAILURE);
> }
>
> - if (option_root == NULL)
> - option_root = g_strdup(DEFAULT_ROOT_PATH);
> + if (option_root == NULL) {
> + option_root = g_build_filename(g_get_user_cache_dir(), "obexd", NULL);
> + g_mkdir_with_parents(option_root, 0700);
> + }
>
> if (option_root[0] != '/') {
> char *old_root = option_root, *home = getenv("HOME");
> --
> 1.8.4.2
Pushed, thanks.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH 2/3] android/hidhost: Remove deprecated idle opcode from ipc document
From: Ravi Kumar Veeramally @ 2013-11-12 9:29 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth@vger.kernel.org development
In-Reply-To: <0C266DD4-7034-4D43-ADEB-E05BE0E54B32@holtmann.org>
Hi Marcel,
On 11/12/2013 01:05 AM, Marcel Holtmann wrote:
> Hi Ravi,
>
>> Idle time is deprecated in HID 1_1. So remove it from ipc document
>> and update GET_REPORT and VIRTUAL_UNPLUG opcode values.
>> ---
>> android/hal-ipc-api.txt | 10 ++--------
>> android/hal-msg.h | 4 ++--
>> 2 files changed, 4 insertions(+), 10 deletions(-)
>>
>> diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
>> index 91ea280..57f4c13 100644
>> --- a/android/hal-ipc-api.txt
>> +++ b/android/hal-ipc-api.txt
>> @@ -614,20 +614,14 @@ Notifications:
>> 0x01 = Boot
>> 0xff = Unsupported
>>
>> - Opcode 0x84 - Idle Time notification
>> -
>> - Notification parameters: Remote address (6 octets)
>> - Status (1 octet)
>> - Idle time (2 octets)
> so what does HID_1.1 actually mean? I still see this notification in bt_hh.h.
>
> Regards
>
> Marcel
>
In HID_SPEC_V11 (3.1) Get Idle and Set Idle are deprecated. And even in
bt_hh.h
get_idle and set_idle interfaces are not available. Bluedroid had
implementation
of those two in bluedroid/btif/src/btif_hh.c but in interface struct
those are commented out.
I didn't find the call back call there. That's why I updated ipc-doc.
Please let me know if I miss anything.
Thanks,
Ravi.
^ permalink raw reply
* [PATCH] android/hidhost: Fix uhid create failure case
From: Ravi kumar Veeramally @ 2013-11-12 9:47 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
If uhid open or create fails then notify state and free the device.
Otherwise it replies bogus success return value on connect request.
---
android/hidhost.c | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index 683938f..491eacd 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -514,6 +514,7 @@ static int uhid_create(struct hid_device *dev)
error("Failed to create uHID device: %s", strerror(errno));
close(dev->uhid_fd);
dev->uhid_fd = -1;
+ bt_hid_notify_state(dev, HAL_HIDHOST_STATE_NO_HID);
return -errno;
}
@@ -534,8 +535,10 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
DBG("");
- if (conn_err)
+ if (conn_err) {
+ error("%s", conn_err->message);
goto failed;
+ }
if (uhid_create(dev) < 0)
goto failed;
@@ -549,19 +552,7 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
return;
failed:
- /* So we guarantee the interrupt channel is closed before the
- * control channel (if we only do unref GLib will close it only
- * after returning control to the mainloop */
- if (!conn_err)
- g_io_channel_shutdown(dev->intr_io, FALSE, NULL);
-
- g_io_channel_unref(dev->intr_io);
- dev->intr_io = NULL;
-
- if (dev->ctrl_io) {
- g_io_channel_unref(dev->ctrl_io);
- dev->ctrl_io = NULL;
- }
+ hid_device_free(dev);
}
static void control_connect_cb(GIOChannel *chan, GError *conn_err,
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH 1/3] android/hidhost: Handle uhid output and feature events
From: Ravi Kumar Veeramally @ 2013-11-12 10:11 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1384172130-29837-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi,
This patch is buggy. Conversion needs to be done like set_report and
send_data methods. I will send _v2 of this particular patch.
Sorry for inconvenience.
Thanks,
Ravi.
On 11/11/2013 02:15 PM, Ravi kumar Veeramally wrote:
> Data read on uhid events output and feature has to be send through
> SET_REPORT request to HID device.
> ---
> android/hidhost.c | 37 ++++++++++++++++++++++++++++++++++++-
> 1 file changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/android/hidhost.c b/android/hidhost.c
> index 683938f..816fe3e 100644
> --- a/android/hidhost.c
> +++ b/android/hidhost.c
> @@ -155,7 +155,42 @@ static void hid_device_free(struct hid_device *dev)
>
> static void handle_uhid_event(struct hid_device *dev, struct uhid_event *ev)
> {
> - DBG("UHID_OUTPUT UHID_FEATURE unsupported");
> + int fd;
> + uint8_t *req = NULL;
> + uint8_t req_size = 0;
> +
> + if (!(dev->ctrl_io))
> + return;
> +
> + switch (ev->type) {
> + case UHID_OUTPUT:
> + req_size = 1 + ev->u.output.size;
> + req = g_try_malloc0(req_size);
> + if (!req)
> + return;
> +
> + req[0] = HID_MSG_SET_REPORT | HID_DATA_TYPE_OUTPUT;
> + memcpy(req + 1, ev->u.output.data, ev->u.output.size);
> + break;
> +
> + case UHID_FEATURE:
> + req_size = sizeof(struct uhid_feature_req);
> + req = g_try_malloc0(req_size);
> + if (!req)
> + return;
> +
> + req[0] = HID_MSG_SET_REPORT | HID_DATA_TYPE_FEATURE;
> + memcpy(req + 1, (ev + sizeof(ev->type)), req_size - 1);
> + break;
> + }
> +
> + fd = g_io_channel_unix_get_fd(dev->ctrl_io);
> +
> + if (write(fd, req, req_size) < 0)
> + error("error writing hid_set_report: %s (%d)",
> + strerror(errno), errno);
> +
> + g_free(req);
> }
>
> static gboolean uhid_event_cb(GIOChannel *io, GIOCondition cond,
^ permalink raw reply
* [PATCH v2 0/5] Add support for registering local SDP records
From: Szymon Janc @ 2013-11-12 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
V2:
- don't use bt_uuid_t
- few bugfixes
V1 cover:
This adds support for manipulating local SDP database with
bt_adapter_add_record and bt_adapter_remove_record functions. Those should
be called when HAL service is registered or unregistered.
This also adds DeviceID record as at least 1 local UUID is needed by Android to
properly handle remote device profiles.
Last but not least: With this serie it is possible to connect HID device from
Android UI (Settings application). \O/
--
BR
Szymon Janc
Marcin Kraglak (3):
android: Add and remove sdp records and uuids
android: Clear adapter uuids during initialization
android: Add support for getting UUIDs property
Szymon Janc (2):
android: Remove not needed include
android: Register DeviceID record when adapter is initialized
android/adapter.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++----
android/adapter.h | 3 +
2 files changed, 178 insertions(+), 13 deletions(-)
--
1.8.4.2
^ permalink raw reply
* [PATCH v2 1/5] android: Add and remove sdp records and uuids
From: Szymon Janc @ 2013-11-12 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1384257985-26319-1-git-send-email-szymon.janc@tieto.com>
From: Marcin Kraglak <marcin.kraglak@tieto.com>
This is api for adding and removing sdp records and uuids
via mgmt interface. Local profiles have to store handle to
own records to remove them in cleanup. Additionally list of
uuids is created in bt_adapter struct.
---
android/adapter.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
android/adapter.h | 3 ++
2 files changed, 101 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index 65b3170..b053043 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -40,6 +40,7 @@
#include "lib/sdp_lib.h"
#include "lib/uuid.h"
#include "src/sdp-client.h"
+#include "src/sdpd.h"
#include "log.h"
#include "hal-msg.h"
#include "ipc.h"
@@ -74,6 +75,7 @@ struct bt_adapter {
bool discovering;
uint32_t discoverable_timeout;
+ GSList *uuids;
};
struct browse_req {
@@ -986,6 +988,102 @@ static void load_link_keys(GSList *keys)
}
}
+/* output uint128 is in host order */
+static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128)
+{
+ uuid_t uuid16, uuid128;
+
+ sdp_uuid16_create(&uuid16, uuid);
+ sdp_uuid16_to_uuid128(&uuid128, &uuid16);
+
+ ntoh128(&uuid128.value.uuid128, u128);
+}
+
+static void remove_uuid_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ if (status != MGMT_STATUS_SUCCESS) {
+ error("Failed to remove UUID: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+}
+
+static void remove_uuid(uint128_t *uuid)
+{
+ struct mgmt_cp_remove_uuid cp;
+
+ htob128(uuid, (uint128_t *) cp.uuid);
+
+ mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_UUID,
+ adapter->index, sizeof(cp), &cp,
+ remove_uuid_complete, NULL, NULL);
+}
+
+static void add_uuid_complete(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ if (status != MGMT_STATUS_SUCCESS) {
+ error("Failed to add UUID: %s (0x%02x)",
+ mgmt_errstr(status), status);
+ return;
+ }
+
+ mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+}
+
+static void add_uuid(uint8_t svc_hint, uint128_t *uuid)
+{
+ struct mgmt_cp_add_uuid cp;
+
+ htob128(uuid, (uint128_t *) cp.uuid);
+ cp.svc_hint = svc_hint;
+
+ mgmt_send(adapter->mgmt, MGMT_OP_ADD_UUID,
+ adapter->index, sizeof(cp), &cp,
+ add_uuid_complete, NULL, NULL);
+}
+
+int bt_adapter_add_record(uint16_t uuid, sdp_record_t *rec, uint8_t svc_hint)
+{
+ uint128_t uint128;
+
+ if (g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid))) {
+ DBG("UUID 0x%x already added", uuid);
+ return -1;
+ }
+
+ adapter->uuids = g_slist_prepend(adapter->uuids,
+ GUINT_TO_POINTER(uuid));
+
+ uuid16_to_uint128(uuid, &uint128);
+
+ add_uuid(svc_hint, &uint128);
+
+ return add_record_to_server(&adapter->bdaddr, rec);
+}
+
+void bt_adapter_remove_record(uint16_t uuid, int handle)
+{
+ GSList *uuid_found;
+
+ uuid_found = g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid));
+ if (uuid_found) {
+ uint128_t uint128;
+
+ uuid16_to_uint128(uuid, &uint128);
+
+ remove_uuid(&uint128);
+
+ adapter->uuids = g_slist_remove(adapter->uuids,
+ uuid_found->data);
+ }
+
+ remove_record_from_server(handle);
+}
+
static void set_mode_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
diff --git a/android/adapter.h b/android/adapter.h
index c62b859..4c3100f 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -32,3 +32,6 @@ const bdaddr_t *bt_adapter_get_address(void);
bool bt_adapter_register(int sk);
void bt_adapter_unregister(void);
+
+int bt_adapter_add_record(uint16_t uuid, sdp_record_t *rec, uint8_t svc_hint);
+void bt_adapter_remove_record(uint16_t uuid, int handle);
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 2/5] android: Remove not needed include
From: Szymon Janc @ 2013-11-12 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384257985-26319-1-git-send-email-szymon.janc@tieto.com>
bt_uuid_t is not used so lib/uuid.h doesn't need to be included.
---
android/adapter.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/android/adapter.c b/android/adapter.c
index b053043..bda8e20 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -38,7 +38,6 @@
#include "src/eir.h"
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
-#include "lib/uuid.h"
#include "src/sdp-client.h"
#include "src/sdpd.h"
#include "log.h"
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 3/5] android: Clear adapter uuids during initialization
From: Szymon Janc @ 2013-11-12 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1384257985-26319-1-git-send-email-szymon.janc@tieto.com>
From: Marcin Kraglak <marcin.kraglak@tieto.com>
Clear adapter uuids during init. We have to do it before
other profiles will be able to register sdp records and add
their uuids.
---
android/adapter.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index bda8e20..d5b1806 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -1193,6 +1193,17 @@ static uint8_t set_discoverable_timeout(uint8_t *timeout)
return HAL_STATUS_SUCCESS;
}
+
+static void clear_uuids(void)
+{
+ struct mgmt_cp_remove_uuid cp;
+
+ memset(&cp, 0, sizeof(cp));
+
+ mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_UUID, adapter->index,
+ sizeof(cp), &cp, NULL, NULL, NULL);
+}
+
static void read_info_complete(uint8_t status, uint16_t length, const void *param,
void *user_data)
{
@@ -1233,6 +1244,8 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
/* TODO: Register all event notification handlers */
register_mgmt_handlers();
+ clear_uuids();
+
load_link_keys(NULL);
set_io_capability();
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 4/5] android: Add support for getting UUIDs property
From: Szymon Janc @ 2013-11-12 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Marcin Kraglak
In-Reply-To: <1384257985-26319-1-git-send-email-szymon.janc@tieto.com>
From: Marcin Kraglak <marcin.kraglak@tieto.com>
This method will call adapter_properties_cb with uuids of
adapter. Method is called also when uuid is added or removed.
---
android/adapter.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 47 insertions(+), 8 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index d5b1806..fd40bad 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -998,6 +998,45 @@ static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128)
ntoh128(&uuid128.value.uuid128, u128);
}
+static bool get_uuids(void)
+{
+ struct hal_ev_adapter_props_changed *ev;
+ GSList *list = adapter->uuids;
+ unsigned int uuid_count = g_slist_length(list);
+ int len = uuid_count * sizeof(uint128_t);
+ uint8_t buf[BASELEN_PROP_CHANGED + len];
+ uint8_t *p;
+ int i;
+
+ memset(buf, 0, sizeof(buf));
+ ev = (void *) buf;
+
+ ev->num_props = 1;
+ ev->status = HAL_STATUS_SUCCESS;
+
+ ev->props[0].type = HAL_PROP_ADAPTER_UUIDS;
+ ev->props[0].len = len;
+ p = ev->props->val;
+
+ for (; list; list = g_slist_next(list)) {
+ uint16_t uuid = GPOINTER_TO_UINT(list->data);
+ uint128_t uint128;
+
+ uuid16_to_uint128(uuid, &uint128);
+
+ /* Android expects swapped bytes in uuid */
+ for (i = 0; i < 16; i++)
+ p[15 - i] = uint128.data[i];
+
+ p += sizeof(uint128_t);
+ }
+
+ ipc_send(notification_sk, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1);
+
+ return true;
+}
+
static void remove_uuid_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
@@ -1008,6 +1047,10 @@ static void remove_uuid_complete(uint8_t status, uint16_t length,
}
mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+
+ /* send notification only if bluetooth service is registered */
+ if (notification_sk >= 0)
+ get_uuids();
}
static void remove_uuid(uint128_t *uuid)
@@ -1031,6 +1074,10 @@ static void add_uuid_complete(uint8_t status, uint16_t length,
}
mgmt_dev_class_changed_event(adapter->index, length, param, NULL);
+
+ /* send notification only if bluetooth service is registered */
+ if (notification_sk >= 0)
+ get_uuids();
}
static void add_uuid(uint8_t svc_hint, uint128_t *uuid)
@@ -1331,14 +1378,6 @@ static bool get_name(void)
return true;
}
-static bool get_uuids(void)
-{
- DBG("Not implemented");
-
- /* TODO: Add implementation */
-
- return false;
-}
static bool get_class(void)
{
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 5/5] android: Register DeviceID record when adapter is initialized
From: Szymon Janc @ 2013-11-12 12:06 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1384257985-26319-1-git-send-email-szymon.janc@tieto.com>
Register DeviceID SDP record and update local UUIDs after DeviceID
information is passed to kernel.
---
android/adapter.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index fd40bad..1ddd1f4 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -46,6 +46,10 @@
#include "utils.h"
#include "adapter.h"
+#define DEVICE_ID_SOURCE 0x0002 /* USB */
+#define DEVICE_ID_VENDOR 0x1d6b /* Linux Foundation */
+#define DEVICE_ID_PRODUCT 0x0247 /* BlueZ for Android */
+
/* Default to DisplayYesNo */
#define DEFAULT_IO_CAPABILITY 0x01
/* Default discoverable timeout 120sec as in Android */
@@ -1182,20 +1186,29 @@ static void set_device_id(void)
{
struct mgmt_cp_set_device_id cp;
uint8_t major, minor;
+ uint16_t version;
if (sscanf(VERSION, "%hhu.%hhu", &major, &minor) != 2)
return;
+ version = major << 8 | minor;
+
memset(&cp, 0, sizeof(cp));
- cp.source = htobs(0x0002); /* USB */
- cp.vendor = htobs(0x1d6b); /* Linux Foundation */
- cp.product = htobs(0x0247); /* BlueZ for Android */
- cp.version = htobs(major << 8 | minor);
+ cp.source = htobs(DEVICE_ID_SOURCE);
+ cp.vendor = htobs(DEVICE_ID_VENDOR);
+ cp.product = htobs(DEVICE_ID_PRODUCT);
+ cp.version = htobs(version);
if (mgmt_send(adapter->mgmt, MGMT_OP_SET_DEVICE_ID,
adapter->index, sizeof(cp), &cp,
NULL, NULL, NULL) == 0)
error("Failed to set device id");
+
+ register_device_id(DEVICE_ID_SOURCE, DEVICE_ID_VENDOR,
+ DEVICE_ID_PRODUCT, version);
+
+ bt_adapter_add_record(PNP_INFO_PROFILE_ID, sdp_record_find(0x10000),
+ 0x00);
}
static void set_adapter_name_complete(uint8_t status, uint16_t length,
--
1.8.4.2
^ permalink raw reply related
* [PATCH v2 0/3] Fixes for incoming connection and bonding
From: Lukasz Rymanowski @ 2013-11-12 12:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
V2:
Bonding state added.
V1:
With those patches it is possible to bond from remote device and in addition
you will see the name of remote device on Android pairing request pop up.
Lukasz Rymanowski (3):
android: Update bond state on incoming bonding
android: Update HAL with device info on incoming connection
android: Change TODO with explaining comment
android/adapter.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 56 insertions(+), 9 deletions(-)
--
1.8.4
^ permalink raw reply
* [PATCH v2 1/3] android: Update bond state on incoming bonding
From: Lukasz Rymanowski @ 2013-11-12 12:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
In-Reply-To: <1384260700-16621-1-git-send-email-lukasz.rymanowski@tieto.com>
Before sending any ssp request or pin code request up to HAL library we
need to send bond state change with bonding state. Otherwise incoming
bonding is impossible.
Add bonding tracking to adapter.
---
android/adapter.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index 65b3170..f92301e 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -74,6 +74,8 @@ struct bt_adapter {
bool discovering;
uint32_t discoverable_timeout;
+
+ bool bonding;
};
struct browse_req {
@@ -486,6 +488,7 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
send_bond_state_change(&addr->bdaddr, HAL_STATUS_SUCCESS,
HAL_BOND_STATE_BONDED);
+ adapter->bonding = false;
browse_remote_sdp(&addr->bdaddr);
}
@@ -501,6 +504,13 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
return;
}
+ if (!adapter->bonding) {
+ adapter->bonding = true;
+ /* Update bonding state */
+ send_bond_state_change(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_BONDING);
+ }
+
ba2str(&ev->addr.bdaddr, dst);
DBG("%s type %u secure %u", dst, ev->addr.type, ev->secure);
@@ -542,6 +552,13 @@ static void user_confirm_request_callback(uint16_t index, uint16_t length,
ba2str(&ev->addr.bdaddr, dst);
DBG("%s confirm_hint %u", dst, ev->confirm_hint);
+ if (!adapter->bonding) {
+ adapter->bonding = true;
+ /* Update bonding state */
+ send_bond_state_change(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_BONDING);
+ }
+
if (ev->confirm_hint)
send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_CONSENT, 0);
else
@@ -563,6 +580,13 @@ static void user_passkey_request_callback(uint16_t index, uint16_t length,
ba2str(&ev->addr.bdaddr, dst);
DBG("%s", dst);
+ if (!adapter->bonding) {
+ adapter->bonding = true;
+ /* Update bonding state */
+ send_bond_state_change(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_BONDING);
+ }
+
send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_ENTRY, 0);
}
@@ -581,9 +605,17 @@ static void user_passkey_notify_callback(uint16_t index, uint16_t length,
DBG("%s entered %u", dst, ev->entered);
/* HAL seems to not support entered characters */
- if (!ev->entered)
- send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_NOTIF,
- ev->passkey);
+ if (ev->entered)
+ return;
+
+ if (!adapter->bonding) {
+ adapter->bonding=true;
+ /* Update bonding state */
+ send_bond_state_change(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_BOND_STATE_BONDING);
+ }
+
+ send_ssp_request(&ev->addr.bdaddr, HAL_SSP_VARIANT_NOTIF, ev->passkey);
}
static void mgmt_discovering_event(uint16_t index, uint16_t length,
@@ -1166,6 +1198,7 @@ void bt_adapter_init(uint16_t index, struct mgmt *mgmt, bt_adapter_ready cb)
adapter->ready = cb;
/* TODO: Read it from some storage */
adapter->discoverable_timeout = DEFAULT_DISCOVERABLE_TIMEOUT;
+ adapter->bonding = false;
if (mgmt_send(mgmt, MGMT_OP_READ_INFO, index, 0, NULL,
read_info_complete, NULL, NULL) > 0)
@@ -1486,6 +1519,7 @@ static void pair_device_complete(uint8_t status, uint16_t length,
if (status == MGMT_STATUS_SUCCESS)
return;
+ adapter->bonding = false;
send_bond_state_change(&rp->addr.bdaddr, status_mgmt2hal(status),
HAL_BOND_STATE_NONE);
}
@@ -1504,6 +1538,7 @@ static bool create_bond(void *buf, uint16_t len)
NULL) == 0)
return false;
+ adapter->bonding = true;
send_bond_state_change(&cp.addr.bdaddr, HAL_STATUS_SUCCESS,
HAL_BOND_STATE_BONDING);
@@ -1514,13 +1549,18 @@ static bool cancel_bond(void *buf, uint16_t len)
{
struct hal_cmd_cancel_bond *cmd = buf;
struct mgmt_addr_info cp;
+ bool result;
cp.type = BDADDR_BREDR;
android2bdaddr(cmd->bdaddr, &cp.bdaddr);
- return mgmt_reply(adapter->mgmt, MGMT_OP_CANCEL_PAIR_DEVICE,
+ result = mgmt_reply(adapter->mgmt, MGMT_OP_CANCEL_PAIR_DEVICE,
adapter->index, sizeof(cp), &cp, NULL, NULL,
NULL) > 0;
+ if (result)
+ adapter->bonding = false;
+
+ return result;
}
static void unpair_device_complete(uint8_t status, uint16_t length,
@@ -1737,7 +1777,7 @@ void bt_adapter_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
break;
case HAL_OP_CREATE_BOND:
- if (!create_bond(buf, len))
+ if (adapter->bonding || !create_bond(buf, len))
goto error;
break;
--
1.8.4
^ permalink raw reply related
* [PATCH v2 2/3] android: Update HAL with device info on incoming connection
From: Lukasz Rymanowski @ 2013-11-12 12:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
In-Reply-To: <1384260700-16621-1-git-send-email-lukasz.rymanowski@tieto.com>
Make sure Android have information about connecting remote device. This
is needed for example to show device name on incoming bonding request.
---
android/adapter.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index f92301e..a59ab4e 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -857,9 +857,8 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,
return;
}
- /* TODO: Update device */
-
- /* TODO: Check Set bonding state */
+ update_found_device(&ev->addr.bdaddr, ev->addr.type, 0, false,
+ &ev->eir[0], btohs(ev->eir_len));
hal_ev.status = HAL_STATUS_SUCCESS;
hal_ev.state = HAL_ACL_STATE_CONNECTED;
--
1.8.4
^ permalink raw reply related
* [PATCH v2 3/3] android: Change TODO with explaining comment
From: Lukasz Rymanowski @ 2013-11-12 12:51 UTC (permalink / raw)
To: linux-bluetooth; +Cc: johan.hedberg, szymon.janc, Lukasz Rymanowski
In-Reply-To: <1384260700-16621-1-git-send-email-lukasz.rymanowski@tieto.com>
---
android/adapter.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/android/adapter.c b/android/adapter.c
index a59ab4e..ac1ebc2 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -515,7 +515,10 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
DBG("%s type %u secure %u", dst, ev->addr.type, ev->secure);
- /* TODO name and CoD of remote devices should probably be cached */
+ /* It is ok to have empty name and CoD of remote devices here since
+ * those information has been already provided on device_connected event
+ * or during device scaning. Android will use that instead.
+ */
memset(&hal_ev, 0, sizeof(hal_ev));
bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
@@ -528,7 +531,10 @@ static void send_ssp_request(const bdaddr_t *addr, uint8_t variant,
{
struct hal_ev_ssp_request ev;
- /* TODO name and CoD of remote devices should probably be cached */
+ /* It is ok to have empty name and CoD of remote devices here since
+ * those information has been already provided on device_connected event
+ * or during device scaning. Android will use that instead.
+ */
memset(&ev, 0, sizeof(ev));
bdaddr2android(addr, ev.bdaddr);
ev.pairing_variant = variant;
--
1.8.4
^ permalink raw reply related
* Re: [PATCH v2 1/3] android: Update bond state on incoming bonding
From: Johan Hedberg @ 2013-11-12 13:02 UTC (permalink / raw)
To: Lukasz Rymanowski; +Cc: linux-bluetooth, szymon.janc
In-Reply-To: <1384260700-16621-2-git-send-email-lukasz.rymanowski@tieto.com>
Hi Lukasz,
On Tue, Nov 12, 2013, Lukasz Rymanowski wrote:
> Before sending any ssp request or pin code request up to HAL library we
> need to send bond state change with bonding state. Otherwise incoming
> bonding is impossible.
> Add bonding tracking to adapter.
> ---
> android/adapter.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 45 insertions(+), 5 deletions(-)
>
> diff --git a/android/adapter.c b/android/adapter.c
> index 65b3170..f92301e 100644
> --- a/android/adapter.c
> +++ b/android/adapter.c
> @@ -74,6 +74,8 @@ struct bt_adapter {
>
> bool discovering;
> uint32_t discoverable_timeout;
> +
> + bool bonding;
> };
>
> struct browse_req {
> @@ -486,6 +488,7 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
> send_bond_state_change(&addr->bdaddr, HAL_STATUS_SUCCESS,
> HAL_BOND_STATE_BONDED);
>
> + adapter->bonding = false;
> browse_remote_sdp(&addr->bdaddr);
> }
>
> @@ -501,6 +504,13 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
> return;
> }
>
> + if (!adapter->bonding) {
> + adapter->bonding = true;
> + /* Update bonding state */
> + send_bond_state_change(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
> + HAL_BOND_STATE_BONDING);
> + }
Is there something explicitly blocking multiple parallel bonding
attempts (to different remote devices) in Android? If not this should
really be a list or hash-table with entries identifiable using the
remote bdaddr. In fact since we need this anyway for our LE address type
cache I don't see why it would hurt to have the infrastructure ready for
it now.
Johan
^ permalink raw reply
* [PATCH] android/hidhost: Fix error handling issue incase of G_IO_HUP
From: Ravi kumar Veeramally @ 2013-11-12 13:05 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ravi kumar Veeramally
Incase of G_IO_HUP on GIOCondtion when hid device disconnected,
GIOCondition is combination of G_IO_IN and G_IO_HUP. Current code
tries to read as soon as it finds G_IO_IN in condition.
Apparently there is no data to read and loop continues.
---
android/hidhost.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/android/hidhost.c b/android/hidhost.c
index 491eacd..cba80a6 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -282,26 +282,27 @@ static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond,
{
struct hid_device *dev = data;
+ if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
+ goto error;
+
if (cond & G_IO_IN)
return intr_io_watch_cb(chan, data);
+error:
+ bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTED);
+
/* Checking for ctrl_watch avoids a double g_io_channel_shutdown since
* it's likely that ctrl_watch_cb has been queued for dispatching in
* this mainloop iteration */
if ((cond & (G_IO_HUP | G_IO_ERR)) && dev->ctrl_watch)
g_io_channel_shutdown(chan, TRUE, NULL);
- dev->intr_watch = 0;
-
- if (dev->intr_io) {
- g_io_channel_unref(dev->intr_io);
- dev->intr_io = NULL;
- }
-
/* Close control channel */
if (dev->ctrl_io && !(cond & G_IO_NVAL))
g_io_channel_shutdown(dev->ctrl_io, TRUE, NULL);
+ hid_device_free(dev);
+
return FALSE;
}
@@ -442,12 +443,14 @@ static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
struct hid_device *dev = data;
- char address[18];
+
+ if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
+ goto error;
if (cond & G_IO_IN)
return ctrl_io_watch_cb(chan, data);
- ba2str(&dev->dst, address);
+error:
bt_hid_notify_state(dev, HAL_HIDHOST_STATE_DISCONNECTED);
/* Checking for intr_watch avoids a double g_io_channel_shutdown since
--
1.8.3.2
^ permalink raw reply related
* Re: [PATCH v2 3/3] android: Change TODO with explaining comment
From: Johan Hedberg @ 2013-11-12 13:09 UTC (permalink / raw)
To: Lukasz Rymanowski; +Cc: linux-bluetooth, szymon.janc
In-Reply-To: <1384260700-16621-4-git-send-email-lukasz.rymanowski@tieto.com>
Hi Lukasz,
On Tue, Nov 12, 2013, Lukasz Rymanowski wrote:
> ---
> android/adapter.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/android/adapter.c b/android/adapter.c
> index a59ab4e..ac1ebc2 100644
> --- a/android/adapter.c
> +++ b/android/adapter.c
> @@ -515,7 +515,10 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
>
> DBG("%s type %u secure %u", dst, ev->addr.type, ev->secure);
>
> - /* TODO name and CoD of remote devices should probably be cached */
> + /* It is ok to have empty name and CoD of remote devices here since
> + * those information has been already provided on device_connected event
> + * or during device scaning. Android will use that instead.
> + */
> memset(&hal_ev, 0, sizeof(hal_ev));
> bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
Have you considered security mode 3 devices? There you will get a pin
code request before you get a device_connected. You can even try this
yourself by doing "hciconfig hci0 auth" before attempting to pair. That
said, I'm not sure if there is anything we can do better regarding such
devices, but at least we should keep this use case in mind.
Johan
^ permalink raw reply
* Re: [PATCH v2 1/5] android: Add and remove sdp records and uuids
From: Johan Hedberg @ 2013-11-12 13:24 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth, Marcin Kraglak
In-Reply-To: <1384257985-26319-2-git-send-email-szymon.janc@tieto.com>
Hi,
On Tue, Nov 12, 2013, Szymon Janc wrote:
> +static void add_uuid(uint8_t svc_hint, uint128_t *uuid)
> +{
> + struct mgmt_cp_add_uuid cp;
> +
> + htob128(uuid, (uint128_t *) cp.uuid);
> + cp.svc_hint = svc_hint;
> +
> + mgmt_send(adapter->mgmt, MGMT_OP_ADD_UUID,
> + adapter->index, sizeof(cp), &cp,
> + add_uuid_complete, NULL, NULL);
> +}
> +
> +int bt_adapter_add_record(uint16_t uuid, sdp_record_t *rec, uint8_t svc_hint)
Is it really so that we can't infer the UUID by looking inside
sdp_record_t? (e.g. just use rec->svclass).
> +{
> + uint128_t uint128;
> +
> + if (g_slist_find(adapter->uuids, GUINT_TO_POINTER(uuid))) {
> + DBG("UUID 0x%x already added", uuid);
> + return -1;
> + }
Shouldn't this be return -EALREADY?
> + adapter->uuids = g_slist_prepend(adapter->uuids,
> + GUINT_TO_POINTER(uuid));
> +
> + uuid16_to_uint128(uuid, &uint128);
> +
> + add_uuid(svc_hint, &uint128);
If we only support adding UUID-16, then how about just providing
uint16_t to add/remove_uuid and do the conversion inside these
functions?
> +void bt_adapter_remove_record(uint16_t uuid, int handle)
The type that sdp_record_t uses for the handle is uint32_t so the
parameter here should reflect that.
Johan
^ permalink raw reply
* [PATCH BlueZ] core: Do not attempt to connect if adapter is not powered
From: Luiz Augusto von Dentz @ 2013-11-12 13:26 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If the adapter is not yet powered do not attempt to connect, the same
applies if the error -EHOSTUNREACH is returned by the kernel.
---
src/device.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/device.c b/src/device.c
index 60efd62..e58c16c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1156,7 +1156,7 @@ static void device_profile_connected(struct btd_device *dev,
if (dev->pending == NULL)
return;
- if (!dev->connected && err == -EHOSTDOWN)
+ if (!dev->connected && (err == -EHOSTDOWN || err == -EHOSTUNREACH))
goto done;
pending = dev->pending->data;
@@ -1322,6 +1322,9 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,
if (dev->pending || dev->connect || dev->browse)
return btd_error_in_progress(msg);
+ if (!btd_adapter_get_powered(dev->adapter))
+ return btd_error_not_ready(msg);
+
device_set_temporary(dev, FALSE);
if (!dev->svc_resolved)
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH v2 2/3] android: Update HAL with device info on incoming connection
From: Johan Hedberg @ 2013-11-12 13:27 UTC (permalink / raw)
To: Lukasz Rymanowski; +Cc: linux-bluetooth, szymon.janc
In-Reply-To: <1384260700-16621-3-git-send-email-lukasz.rymanowski@tieto.com>
Hi Lukasz,
On Tue, Nov 12, 2013, Lukasz Rymanowski wrote:
> Make sure Android have information about connecting remote device. This
> is needed for example to show device name on incoming bonding request.
> ---
> android/adapter.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/android/adapter.c b/android/adapter.c
> index f92301e..a59ab4e 100644
> --- a/android/adapter.c
> +++ b/android/adapter.c
> @@ -857,9 +857,8 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,
> return;
> }
>
> - /* TODO: Update device */
> -
> - /* TODO: Check Set bonding state */
> + update_found_device(&ev->addr.bdaddr, ev->addr.type, 0, false,
> + &ev->eir[0], btohs(ev->eir_len));
>
> hal_ev.status = HAL_STATUS_SUCCESS;
> hal_ev.state = HAL_ACL_STATE_CONNECTED;
This patch has been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH] android/hidhost: Fix uhid create failure case
From: Johan Hedberg @ 2013-11-12 13:28 UTC (permalink / raw)
To: Ravi kumar Veeramally; +Cc: linux-bluetooth
In-Reply-To: <1384249639-10915-1-git-send-email-ravikumar.veeramally@linux.intel.com>
Hi Ravi,
On Tue, Nov 12, 2013, Ravi kumar Veeramally wrote:
> If uhid open or create fails then notify state and free the device.
> Otherwise it replies bogus success return value on connect request.
> ---
> android/hidhost.c | 19 +++++--------------
> 1 file changed, 5 insertions(+), 14 deletions(-)
Applied. Thanks.
Johan
^ 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