2013-11-01 13:41:38

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 1/8] android/haltest: Fix print device name

From: Andrei Emeltchenko <[email protected]>

---
android/client/textconv.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/android/client/textconv.c b/android/client/textconv.c
index effd1b3..8e6bdb9 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -258,8 +258,7 @@ char *btproperty2str(const bt_property_t *property)
switch (property->type) {
case BT_PROPERTY_BDNAME:
case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
- sprintf(p, "%*s", property->len,
- ((bt_bdname_t *) property->val)->name);
+ sprintf(p, "%s", ((bt_bdname_t *) property->val)->name);
break;

case BT_PROPERTY_BDADDR:
--
1.7.10.4



2013-11-01 14:40:29

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv1 8/8] android/daemon: Refactor sending acl state

Hi Andrei,

On Fri, Nov 01, 2013, Andrei Emeltchenko wrote:
> Sending ACL state change might be refactored.
> ---
> android/adapter.c | 32 ++++++++++++++++++--------------
> 1 file changed, 18 insertions(+), 14 deletions(-)

Patches 2-7 have been applied. 1/8 didn't apply and this last one is
quite unnecessary since there will never be more than two users and
you're actually adding more lines than you're removing.

Johan

2013-11-01 13:41:41

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 4/8] android/hal: Handle acl_state_changed event

From: Andrei Emeltchenko <[email protected]>

---
android/hal-bluetooth.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index a0ee844..91c5f97 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -254,6 +254,18 @@ static void handle_device_state_changed(void *buf, uint16_t len)
device_hal_props_cleanup(props, ev->num_props);
}

+static void handle_acl_state_changed(void *buf)
+{
+ struct hal_ev_acl_state_changed *ev = buf;
+ bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
+
+ DBG("state %u", ev->state);
+
+ if (bt_hal_cbacks->acl_state_changed_cb)
+ bt_hal_cbacks->acl_state_changed_cb(ev->status, addr,
+ ev->state);
+}
+
/* will be called from notification thread context */
void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
{
@@ -287,6 +299,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_SSP_REQUEST:
handle_ssp_request(buf);
break;
+ case HAL_EV_ACL_STATE_CHANGED:
+ handle_acl_state_changed(buf);
+ break;
default:
DBG("Unhandled callback opcode=0x%x", opcode);
break;
--
1.7.10.4


2013-11-01 13:41:42

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 5/8] android/daemon: Add debug handlers for unhandled mgmt event

From: Andrei Emeltchenko <[email protected]>

Add debug prints to some mgmt events.
---
android/adapter.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 5a5fa2e..299a025 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -651,6 +651,24 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,
HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev, -1);
}

+static void mgmt_connect_failed_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("");
+}
+
+static void mgmt_auth_failed_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("");
+}
+
+static void mgmt_device_unpaired_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ DBG("");
+}
+
static void register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -691,6 +709,15 @@ static void register_mgmt_handlers(void)

mgmt_register(adapter->mgmt, MGMT_EV_DEVICE_CONNECTED, adapter->index,
mgmt_device_connected_event, NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_CONNECT_FAILED, adapter->index,
+ mgmt_connect_failed_event, NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_AUTH_FAILED, adapter->index,
+ mgmt_auth_failed_event, NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_DEVICE_UNPAIRED, adapter->index,
+ mgmt_device_unpaired_event, NULL, NULL);
}

static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.7.10.4


2013-11-01 13:41:40

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 3/8] android/daemon: Implement mgmt device connected event

From: Andrei Emeltchenko <[email protected]>

Send HAL_EV_ACL_STATE_CHANGED event to HAL through IPC.
---
android/adapter.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 5ce0797..5a5fa2e 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -628,6 +628,29 @@ static void mgmt_device_found_event(uint16_t index, uint16_t length,
confirm_name, eir, eir_len);
}

+static void mgmt_device_connected_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_ev_device_connected *ev = param;
+ struct hal_ev_acl_state_changed hal_ev;
+
+ if (length < sizeof(*ev)) {
+ error("Too short device connected event (%u bytes)", length);
+ return;
+ }
+
+ /* TODO: Update device */
+
+ /* TODO: Check Set bonding state */
+
+ hal_ev.status = HAL_STATUS_SUCCESS;
+ hal_ev.state = HAL_ACL_STATE_CONNECTED;
+ bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev, -1);
+}
+
static void register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -665,6 +688,9 @@ static void register_mgmt_handlers(void)
mgmt_register(adapter->mgmt, MGMT_EV_DEVICE_FOUND,
adapter->index, mgmt_device_found_event,
NULL, NULL);
+
+ mgmt_register(adapter->mgmt, MGMT_EV_DEVICE_CONNECTED, adapter->index,
+ mgmt_device_connected_event, NULL, NULL);
}

static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.7.10.4


2013-11-01 13:41:39

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 2/8] android/ipc: Update HAL IPC header

From: Andrei Emeltchenko <[email protected]>

Add ACL states to the header.
---
android/hal-msg.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 8a344d8..1d256f2 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -405,6 +405,9 @@ struct hal_ev_bond_state_changed {
uint8_t state;
} __attribute__((packed));

+#define HAL_ACL_STATE_CONNECTED 0x00
+#define HAL_ACL_STATE_DISCONNECTED 0x01
+
#define HAL_EV_ACL_STATE_CHANGED 0x89
struct hal_ev_acl_state_changed {
uint8_t status;
--
1.7.10.4


2013-11-01 13:41:43

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 6/8] android/hal: Add debug prints for every HAL callback

From: Andrei Emeltchenko <[email protected]>

This allows us to trace callbacks to Java.
---
android/hal-bluetooth.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 91c5f97..7334d24 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -153,6 +153,8 @@ static void handle_adapter_props_changed(void *buf, uint16_t len)
struct hal_ev_adapter_props_changed *ev = buf;
bt_property_t props[ev->num_props];

+ DBG("");
+
if (!bt_hal_cbacks->adapter_properties_cb)
return;

@@ -168,6 +170,8 @@ static void handle_bond_state_change(void *buf)
struct hal_ev_bond_state_changed *ev = buf;
bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;

+ DBG("state %u", ev->state);
+
if (bt_hal_cbacks->bond_state_changed_cb)
bt_hal_cbacks->bond_state_changed_cb(ev->status, addr,
ev->state);
@@ -180,6 +184,8 @@ static void handle_pin_request(void *buf)
bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
bt_bdname_t *name = (bt_bdname_t *) ev->name;

+ DBG("");
+
if (bt_hal_cbacks->pin_request_cb)
bt_hal_cbacks->pin_request_cb(addr, name, ev->class_of_dev);
}
@@ -191,6 +197,8 @@ static void handle_ssp_request(void *buf)
bt_bdaddr_t *addr = (bt_bdaddr_t *) ev->bdaddr;
bt_bdname_t *name = (bt_bdname_t *) ev->name;

+ DBG("");
+
if (bt_hal_cbacks->ssp_request_cb)
bt_hal_cbacks->ssp_request_cb(addr, name, ev->class_of_dev,
ev->pairing_variant,
@@ -218,6 +226,8 @@ static void handle_discovery_state_changed(void *buf)
{
struct hal_ev_discovery_state_changed *ev = buf;

+ DBG("");
+
if (bt_hal_cbacks->discovery_state_changed_cb)
bt_hal_cbacks->discovery_state_changed_cb(ev->state);
}
@@ -227,6 +237,8 @@ static void handle_device_found(void *buf, uint16_t len)
struct hal_ev_device_found *ev = buf;
bt_property_t props[ev->num_props];

+ DBG("");
+
if (!bt_hal_cbacks->device_found_cb)
return;

@@ -242,6 +254,8 @@ static void handle_device_state_changed(void *buf, uint16_t len)
struct hal_ev_remote_device_props *ev = buf;
bt_property_t props[ev->num_props];

+ DBG("");
+
if (!bt_hal_cbacks->remote_device_properties_cb)
return;

--
1.7.10.4


2013-11-01 13:41:44

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 7/8] android/daemon: Add handler for device disconnected

From: Andrei Emeltchenko <[email protected]>

Send event to callback thread which shall call acl state change callback.
---
android/adapter.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 299a025..1109443 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -651,6 +651,25 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,
HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev, -1);
}

+static void mgmt_device_disconnected_event(uint16_t index, uint16_t length,
+ const void *param, void *user_data)
+{
+ const struct mgmt_ev_device_disconnected *ev = param;
+ struct hal_ev_acl_state_changed hal_ev;
+
+ if (length < sizeof(*ev)) {
+ error("Too short device disconnected event (%u bytes)", length);
+ return;
+ }
+
+ hal_ev.status = HAL_STATUS_SUCCESS;
+ hal_ev.state = HAL_ACL_STATE_DISCONNECTED;
+ bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev, -1);
+}
+
static void mgmt_connect_failed_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
@@ -710,6 +729,10 @@ static void register_mgmt_handlers(void)
mgmt_register(adapter->mgmt, MGMT_EV_DEVICE_CONNECTED, adapter->index,
mgmt_device_connected_event, NULL, NULL);

+ mgmt_register(adapter->mgmt, MGMT_EV_DEVICE_DISCONNECTED,
+ adapter->index, mgmt_device_disconnected_event,
+ NULL, NULL);
+
mgmt_register(adapter->mgmt, MGMT_EV_CONNECT_FAILED, adapter->index,
mgmt_connect_failed_event, NULL, NULL);

--
1.7.10.4


2013-11-01 13:41:45

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv1 8/8] android/daemon: Refactor sending acl state

From: Andrei Emeltchenko <[email protected]>

Sending ACL state change might be refactored.
---
android/adapter.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 1109443..d5b32c3 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -628,11 +628,24 @@ static void mgmt_device_found_event(uint16_t index, uint16_t length,
confirm_name, eir, eir_len);
}

+static void send_acl_state_change(const bdaddr_t *addr, uint8_t status,
+ uint8_t state)
+{
+ struct hal_ev_acl_state_changed hal_ev;
+
+ hal_ev.status = status;
+ hal_ev.state = state;
+ bdaddr2android(addr, hal_ev.bdaddr);
+
+ ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+ HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev, -1);
+
+}
+
static void mgmt_device_connected_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
const struct mgmt_ev_device_connected *ev = param;
- struct hal_ev_acl_state_changed hal_ev;

if (length < sizeof(*ev)) {
error("Too short device connected event (%u bytes)", length);
@@ -643,31 +656,22 @@ static void mgmt_device_connected_event(uint16_t index, uint16_t length,

/* TODO: Check Set bonding state */

- hal_ev.status = HAL_STATUS_SUCCESS;
- hal_ev.state = HAL_ACL_STATE_CONNECTED;
- bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
-
- ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
- HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev, -1);
+ send_acl_state_change(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_ACL_STATE_CONNECTED);
}

static void mgmt_device_disconnected_event(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
const struct mgmt_ev_device_disconnected *ev = param;
- struct hal_ev_acl_state_changed hal_ev;

if (length < sizeof(*ev)) {
error("Too short device disconnected event (%u bytes)", length);
return;
}

- hal_ev.status = HAL_STATUS_SUCCESS;
- hal_ev.state = HAL_ACL_STATE_DISCONNECTED;
- bdaddr2android(&ev->addr.bdaddr, hal_ev.bdaddr);
-
- ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
- HAL_EV_ACL_STATE_CHANGED, sizeof(hal_ev), &hal_ev, -1);
+ send_acl_state_change(&ev->addr.bdaddr, HAL_STATUS_SUCCESS,
+ HAL_ACL_STATE_DISCONNECTED);
}

static void mgmt_connect_failed_event(uint16_t index, uint16_t length,
--
1.7.10.4