2013-10-30 10:00:26

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH v2 0/6] Initial HAL support for device discovery

v2 Changes:
* fixed coding style issues pointed by jhe and niko1
* extracted property repacking code for reuse

Jakub Tyszkowski (6):
android/hal: Add support for start/cancel device discovery commands
android/hal: Add support for handling discovery state change event
android/hal: Extract bt property repacking code for further reuse
android/hal: Add device found event handler
android/hal: Add device state changed event handler
android: Add missing discovery state definitions to IPC header

android/hal-bluetooth.c | 92 +++++++++++++++++++++++++++++++++++++++----------
android/hal-msg.h | 3 ++
2 files changed, 76 insertions(+), 19 deletions(-)

--
1.8.4.1



2013-10-30 10:13:22

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v2 0/6] Initial HAL support for device discovery

Hi Jakub,

On Wed, Oct 30, 2013, Jakub Tyszkowski wrote:
> v2 Changes:
> * fixed coding style issues pointed by jhe and niko1
> * extracted property repacking code for reuse
>
> Jakub Tyszkowski (6):
> android/hal: Add support for start/cancel device discovery commands
> android/hal: Add support for handling discovery state change event
> android/hal: Extract bt property repacking code for further reuse
> android/hal: Add device found event handler
> android/hal: Add device state changed event handler
> android: Add missing discovery state definitions to IPC header
>
> android/hal-bluetooth.c | 92 +++++++++++++++++++++++++++++++++++++++----------
> android/hal-msg.h | 3 ++
> 2 files changed, 76 insertions(+), 19 deletions(-)

All patches have been applied. Thanks.

Johan

2013-10-30 10:00:32

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH v2 6/6] android: Add missing discovery state definitions to IPC header

---
android/hal-msg.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 80b47d6..d2a0e2a 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -348,6 +348,9 @@ struct hal_ev_device_found {
struct hal_property props[0];
} __attribute__((packed));

+#define HAL_DISCOVERY_STATE_STOPPED 0x00
+#define HAL_DISCOVERY_STATE_STARTED 0x01
+
#define HAL_EV_DISCOVERY_STATE_CHANGED 0x85
struct hal_ev_discovery_state_changed {
uint8_t state;
--
1.8.4.1


2013-10-30 10:00:31

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH v2 5/6] android/hal: Add device state changed event handler

This is used to report property change of already reported remote
device.

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

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 3f9df96..2237063 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -145,6 +145,21 @@ static void handle_device_found(void *buf, uint16_t len)
bt_hal_cbacks->device_found_cb(ev->num_props, props);
}

+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];
+
+ if (!bt_hal_cbacks->remote_device_properties_cb)
+ return;
+
+ repack_properties(props, ev->props, ev->num_props, buf + len);
+
+ bt_hal_cbacks->remote_device_properties_cb(ev->status,
+ (bt_bdaddr_t *)ev->bdaddr,
+ ev->num_props, props);
+}
+
/* will be called from notification thread context */
void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
{
@@ -164,6 +179,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_DEVICE_FOUND:
handle_device_found(buf, len);
break;
+ case HAL_EV_REMOTE_DEVICE_PROPS:
+ handle_device_state_changed(buf, len);
+ break;
case HAL_EV_BOND_STATE_CHANGED:
handle_bond_state_change(buf);
break;
--
1.8.4.1


2013-10-30 10:00:29

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH v2 3/6] android/hal: Extract bt property repacking code for further reuse

This extracted part of code can be reused for repacking remote device
properties.

---
android/hal-bluetooth.c | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 18a5e1c..06d85e3 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -37,33 +37,38 @@ static void handle_adapter_state_changed(void *buf)
bt_hal_cbacks->adapter_state_changed_cb(ev->state);
}

-static void handle_adapter_props_changed(void *buf, uint16_t len)
+static void repack_properties(bt_property_t *send_props,
+ struct hal_property *hal_prop,
+ uint8_t num_props,
+ void *buff_end)
{
- struct hal_ev_adapter_props_changed *ev = buf;
- bt_property_t props[ev->num_props];
- struct hal_property *hal_prop;
- void *p;
- int i;
+ void *p = hal_prop;
+ uint8_t i;

- if (!bt_hal_cbacks->adapter_properties_cb)
- return;
-
- hal_prop = ev->props;
- p = ev->props;
-
- for (i = 0; i < ev->num_props; i++) {
- if (p + sizeof(*hal_prop) + hal_prop->len > buf + len) {
+ for (i = 0; i < num_props; i++) {
+ if (p + sizeof(*hal_prop) + hal_prop->len > buff_end) {
error("invalid adapter properties event, aborting");
exit(EXIT_FAILURE);
}

- props[i].type = hal_prop->type;
- props[i].len = hal_prop->len;
- props[i].val = hal_prop->val;
+ send_props[i].type = hal_prop->type;
+ send_props[i].len = hal_prop->len;
+ send_props[i].val = hal_prop->val;

p += sizeof(*hal_prop) + hal_prop->len;
hal_prop = p;
}
+}
+
+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];
+
+ if (!bt_hal_cbacks->adapter_properties_cb)
+ return;
+
+ repack_properties(props, ev->props, ev->num_props, buf + len);

bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
}
--
1.8.4.1


2013-10-30 10:00:30

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH v2 4/6] android/hal: Add device found event handler

This is called when new remote device is found.

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

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 06d85e3..3f9df96 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -132,6 +132,19 @@ static void handle_discovery_state_changed(void *buf)
bt_hal_cbacks->discovery_state_changed_cb(ev->state);
}

+static void handle_device_found(void *buf, uint16_t len)
+{
+ struct hal_ev_device_found *ev = buf;
+ bt_property_t props[ev->num_props];
+
+ if (!bt_hal_cbacks->device_found_cb)
+ return;
+
+ repack_properties(props, ev->props, ev->num_props, buf + len);
+
+ bt_hal_cbacks->device_found_cb(ev->num_props, props);
+}
+
/* will be called from notification thread context */
void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
{
@@ -148,6 +161,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_DISCOVERY_STATE_CHANGED:
handle_discovery_state_changed(buf);
break;
+ case HAL_EV_DEVICE_FOUND:
+ handle_device_found(buf, len);
+ break;
case HAL_EV_BOND_STATE_CHANGED:
handle_bond_state_change(buf);
break;
--
1.8.4.1


2013-10-30 10:00:28

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH v2 2/6] android/hal: Add support for handling discovery state change event

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

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 9d1c3f7..18a5e1c 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -119,6 +119,14 @@ static bool interface_ready(void)
return bt_hal_cbacks != NULL;
}

+static void handle_discovery_state_changed(void *buf)
+{
+ struct hal_ev_discovery_state_changed *ev = buf;
+
+ if (bt_hal_cbacks->discovery_state_changed_cb)
+ bt_hal_cbacks->discovery_state_changed_cb(ev->state);
+}
+
/* will be called from notification thread context */
void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
{
@@ -132,6 +140,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
case HAL_EV_ADAPTER_PROPS_CHANGED:
handle_adapter_props_changed(buf, len);
break;
+ case HAL_EV_DISCOVERY_STATE_CHANGED:
+ handle_discovery_state_changed(buf);
+ break;
case HAL_EV_BOND_STATE_CHANGED:
handle_bond_state_change(buf);
break;
--
1.8.4.1


2013-10-30 10:00:27

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH v2 1/6] android/hal: Add support for start/cancel device discovery commands

---
android/hal-bluetooth.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index ffaf8da..9d1c3f7 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -353,7 +353,9 @@ static int start_discovery(void)
if (!interface_ready())
return BT_STATUS_NOT_READY;

- return BT_STATUS_UNSUPPORTED;
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_START_DISCOVERY, 0, NULL, 0,
+ NULL, NULL);
}

static int cancel_discovery(void)
@@ -363,7 +365,9 @@ static int cancel_discovery(void)
if (!interface_ready())
return BT_STATUS_NOT_READY;

- return BT_STATUS_UNSUPPORTED;
+ return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH,
+ HAL_OP_CANCEL_DISCOVERY, 0, NULL, 0,
+ NULL, NULL);
}

static int create_bond(const bt_bdaddr_t *bd_addr)
--
1.8.4.1