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 4ddd68b..df56452 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -620,6 +620,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 %s (%u bytes)", __func__, 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,
@@ -657,6 +680,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
Hi Andrei,
On Fri, Nov 01, 2013, Andrei Emeltchenko wrote:
> Send HAL_EV_ACL_STATE_CHANGED event to HAL through IPC.
> ---
> android/adapter.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
This doesn't compile:
CC android/adapter.o
android/adapter.c: In function ‘mgmt_device_connected_event’:
android/adapter.c:641:17: error: ‘HAL_ACL_STATE_CONNECTED’ undeclared (first use in this function)
hal_ev.state = HAL_ACL_STATE_CONNECTED;
^
android/adapter.c:641:17: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [android/adapter.o] Error 1
> + if (length < sizeof(*ev)) {
> + error("Too short %s (%u bytes)", __func__, length);
> + return;
> + }
This looks a bit weird. The function is not too short but the message
is, not to mention that having to use __func__ for error logs is a bit
counterintuitive. Just put "device connected event" into the string.
Same goes for your device disconnected event patch.
Johan
From: Andrei Emeltchenko <[email protected]>
Send event to callback thread which shall call acl state change callback.
---
android/adapter.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index bc4492b..39389ee 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -643,6 +643,29 @@ 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 %s (%u bytes)", __func__, length);
+ return;
+ }
+
+ /* TODO: Update device */
+
+ /* TODO: Check Set bonding state */
+
+ 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)
{
@@ -696,6 +719,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
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
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
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
From: Andrei Emeltchenko <[email protected]>
Add debug prints in a case connection is failing
---
android/adapter.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/android/adapter.c b/android/adapter.c
index df56452..bc4492b 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -643,6 +643,18 @@ 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 register_mgmt_handlers(void)
{
mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
@@ -683,6 +695,12 @@ 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);
}
static void load_link_keys_complete(uint8_t status, uint16_t length,
--
1.7.10.4