2014-11-17 14:06:55

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 1/4] android/hal-ipc-api: Update HidHost with Android 5 API

---
android/hal-ipc-api.txt | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 67a6205..a5ec44b 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -671,6 +671,13 @@ Notifications:
0x0c = Authentication failed
0x0d = HDL

+ Opcode 0x87 - Handshake notification
+
+ Notification parameters: Remote address (6 octets)
+ Status (1 octet)
+
+ Valid status values: Same as in Virtual Unplug notification
+

Bluetooth PAN HAL (ID 4)
========================
--
1.9.1



2014-11-19 19:37:19

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 3/4] android/hid: Support handshake message

Hi Jakub,

On Monday 17 of November 2014 15:06:57 Jakub Tyszkowski wrote:
> ---
> android/hidhost.c | 25 ++++++++++++++++++++++++-
> 1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/android/hidhost.c b/android/hidhost.c
> index 657fa8f..ba44af0 100644
> --- a/android/hidhost.c
> +++ b/android/hidhost.c
> @@ -80,6 +80,9 @@
> /* HID Virtual Cable Unplug */
> #define HID_VIRTUAL_CABLE_UNPLUG 0x05
>
> +/* HID Max. Handshake status code */
> +#define HID_HANDSHAKE_ERROR 0x05

This should be specified in IPC document and headers (this is enum).

> +
> #define HOG_UUID "00001812-0000-1000-8000-00805f9b34fb"
>
> static bdaddr_t adapter_addr;
> @@ -391,6 +394,24 @@ send:
> g_free(ev);
> }
>
> +static void bt_hid_notify_handshake(struct hid_device *dev, uint8_t *buf,
> + int len)
> +{
> + struct hal_ev_hidhost_handshake ev;
> + int ev_len;
> +
> + ev_len = sizeof(ev);

ev_len is not needed, just pass sizeof() directly.

> + bdaddr2android(&dev->dst, ev.bdaddr);
> +
> + /* crop result code to HAL range */
> + ev.status = buf[0];
> + if (ev.status > HID_HANDSHAKE_ERROR)
> + ev.status = HID_HANDSHAKE_ERROR;
> +
> + ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST,
> + HAL_EV_HIDHOST_HANDSHAKE, ev_len, &ev);
> +}
> +
> static void bt_hid_notify_virtual_unplug(struct hid_device *dev,
> uint8_t *buf, int len)
> {
> @@ -441,7 +462,9 @@ static gboolean ctrl_io_watch_cb(GIOChannel *chan,
> gpointer data) break;
> }
>
> - if (buf[0] == (HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG))
> + if (buf[0] < HID_MSG_CONTROL)
> + bt_hid_notify_handshake(dev, buf, bread);
> + else if (buf[0] == (HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG))
> bt_hid_notify_virtual_unplug(dev, buf, bread);

This looks strange, is this value or bitmask?

>
> /* reset msg type request */

--
BR
Szymon Janc

2014-11-17 14:06:56

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 2/4] android/hal: Update HidHost HAL for Android 5

---
android/hal-hidhost.c | 11 +++++++++++
android/hal-msg.h | 6 ++++++
2 files changed, 17 insertions(+)

diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 58b0218..3cfc6b6 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -102,6 +102,16 @@ static void handle_virtual_unplug(void *buf, uint16_t len, int fd)
ev->status);
}

+static void handle_handshake(void *buf, uint16_t len, int fd)
+{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ struct hal_ev_hidhost_handshake *ev = buf;
+
+ if (cbacks->handshake_cb)
+ cbacks->handshake_cb((bt_bdaddr_t *) ev->bdaddr, ev->status);
+#endif
+}
+
/*
* handlers will be called from notification thread context,
* index in table equals to 'opcode - HAL_MINIMUM_EVENT'
@@ -120,6 +130,7 @@ static const struct hal_ipc_handler ev_handlers[] = {
/* HAL_EV_HIDHOST_VIRTUAL_UNPLUG */
{ handle_virtual_unplug, false,
sizeof(struct hal_ev_hidhost_virtual_unplug) },
+ { handle_handshake, false, sizeof(struct hal_ev_hidhost_handshake) },
};

static bt_status_t hidhost_connect(bt_bdaddr_t *bd_addr)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 773af5b..35fb78a 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -1263,6 +1263,12 @@ struct hal_ev_hidhost_virtual_unplug {
uint8_t status;
} __attribute__((packed));

+#define HAL_EV_HIDHOST_HANDSHAKE 0x87
+struct hal_ev_hidhost_handshake {
+ uint8_t bdaddr[6];
+ uint8_t status;
+} __attribute__((packed));
+
#define HAL_EV_PAN_CTRL_STATE 0x81
struct hal_ev_pan_ctrl_state {
uint8_t state;
--
1.9.1


2014-11-17 14:06:57

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 3/4] android/hid: Support handshake message

---
android/hidhost.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/android/hidhost.c b/android/hidhost.c
index 657fa8f..ba44af0 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -80,6 +80,9 @@
/* HID Virtual Cable Unplug */
#define HID_VIRTUAL_CABLE_UNPLUG 0x05

+/* HID Max. Handshake status code */
+#define HID_HANDSHAKE_ERROR 0x05
+
#define HOG_UUID "00001812-0000-1000-8000-00805f9b34fb"

static bdaddr_t adapter_addr;
@@ -391,6 +394,24 @@ send:
g_free(ev);
}

+static void bt_hid_notify_handshake(struct hid_device *dev, uint8_t *buf,
+ int len)
+{
+ struct hal_ev_hidhost_handshake ev;
+ int ev_len;
+
+ ev_len = sizeof(ev);
+ bdaddr2android(&dev->dst, ev.bdaddr);
+
+ /* crop result code to HAL range */
+ ev.status = buf[0];
+ if (ev.status > HID_HANDSHAKE_ERROR)
+ ev.status = HID_HANDSHAKE_ERROR;
+
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HIDHOST_HANDSHAKE, ev_len, &ev);
+}
+
static void bt_hid_notify_virtual_unplug(struct hid_device *dev,
uint8_t *buf, int len)
{
@@ -441,7 +462,9 @@ static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
break;
}

- if (buf[0] == (HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG))
+ if (buf[0] < HID_MSG_CONTROL)
+ bt_hid_notify_handshake(dev, buf, bread);
+ else if (buf[0] == (HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG))
bt_hid_notify_virtual_unplug(dev, buf, bread);

/* reset msg type request */
--
1.9.1


2014-11-17 14:06:58

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 4/4] android/client: Add handshake callback

---
android/client/if-hh.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/android/client/if-hh.c b/android/client/if-hh.c
index b2bf8ca..25519e5 100644
--- a/android/client/if-hh.c
+++ b/android/client/if-hh.c
@@ -100,6 +100,18 @@ static void virtual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status)
bthh_status_t2str(hh_status));
}

+/* Callback for Android 5.0 handshake api. */
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+static void handshake_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status)
+{
+ char addr[MAX_ADDR_STR_LEN];
+
+ haltest_info("%s: bd_addr=%s hh_status=%s\n", __func__,
+ bt_bdaddr_t2str(bd_addr, addr),
+ bthh_status_t2str(hh_status));
+}
+#endif
+
/*
* Callback for get hid info
* hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id,
@@ -163,7 +175,10 @@ static bthh_callbacks_t bthh_callbacks = {
.protocol_mode_cb = protocol_mode_cb,
.idle_time_cb = idle_time_cb,
.get_report_cb = get_report_cb,
- .virtual_unplug_cb = virtual_unplug_cb
+ .virtual_unplug_cb = virtual_unplug_cb,
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+ .handshake_cb = handshake_cb
+#endif
};

/* init */
--
1.9.1