2014-11-20 11:18:48

by Jakub Tyszkowski

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

---
android/hal-ipc-api.txt | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 67a6205..efcd3cf 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -599,6 +599,23 @@ Commands and responses:

Notifications:

+ Status is common for many notifications and has fixed value range:
+
+ Status values: 0x00 = Ok
+ 0x01 = Handshake - Device not ready
+ 0x02 = Handshake - Invalid report ID
+ 0x03 = Handshake - Transaction not SPT
+ 0x04 = Handshake - Invalid parameter
+ 0x05 = Handshake - Generic error
+ 0x06 = General error
+ 0x07 = SDP error
+ 0x08 = Set protocol error
+ 0x09 = Device database full
+ 0x0a = Device type not supported
+ 0x0b = No resources
+ 0x0c = Authentication failed
+ 0x0d = HDL
+
Opcode 0x81 - Connection State notification

Notification parameters: Remote address (6 octets)
@@ -656,20 +673,13 @@ Notifications:
Notification parameters: Remote address (6 octets)
Status (1 octet)

- Valid status values: 0x00 = Ok
- 0x01 = Handshake - Device not ready
- 0x02 = Handshake - Invalid report ID
- 0x03 = Handshake - Transaction not SPT
- 0x04 = Handshake - Invalid parameter
- 0x05 = Handshake - Generic error
- 0x06 = General error
- 0x07 = SDP error
- 0x08 = Set protocol error
- 0x09 = Device database full
- 0x0a = Device type not supported
- 0x0b = No resources
- 0x0c = Authentication failed
- 0x0d = HDL
+ Opcode 0x87 - Handshake notification
+
+ Notification parameters: Remote address (6 octets)
+ Status (1 octet)
+
+ Only status values from 0x00 to 0x05 are valid as handshake
+ status.


Bluetooth PAN HAL (ID 4)
--
1.9.1



2014-11-20 15:23:30

by Szymon Janc

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

Hi Jakub,

On Thursday 20 of November 2014 12:18:48 Jakub Tyszkowski wrote:
> ---
> android/hal-ipc-api.txt | 38 ++++++++++++++++++++++++--------------
> 1 file changed, 24 insertions(+), 14 deletions(-)
>
> diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
> index 67a6205..efcd3cf 100644
> --- a/android/hal-ipc-api.txt
> +++ b/android/hal-ipc-api.txt
> @@ -599,6 +599,23 @@ Commands and responses:
>
> Notifications:
>
> + Status is common for many notifications and has fixed value range:
> +
> + Status values: 0x00 = Ok
> + 0x01 = Handshake - Device not ready
> + 0x02 = Handshake - Invalid report ID
> + 0x03 = Handshake - Transaction not SPT
> + 0x04 = Handshake - Invalid parameter
> + 0x05 = Handshake - Generic error
> + 0x06 = General error
> + 0x07 = SDP error
> + 0x08 = Set protocol error
> + 0x09 = Device database full
> + 0x0a = Device type not supported
> + 0x0b = No resources
> + 0x0c = Authentication failed
> + 0x0d = HDL
> +
> Opcode 0x81 - Connection State notification
>
> Notification parameters: Remote address (6 octets)
> @@ -656,20 +673,13 @@ Notifications:
> Notification parameters: Remote address (6 octets)
> Status (1 octet)
>
> - Valid status values: 0x00 = Ok
> - 0x01 = Handshake - Device not ready
> - 0x02 = Handshake - Invalid report ID
> - 0x03 = Handshake - Transaction not SPT
> - 0x04 = Handshake - Invalid parameter
> - 0x05 = Handshake - Generic error
> - 0x06 = General error
> - 0x07 = SDP error
> - 0x08 = Set protocol error
> - 0x09 = Device database full
> - 0x0a = Device type not supported
> - 0x0b = No resources
> - 0x0c = Authentication failed
> - 0x0d = HDL
> + Opcode 0x87 - Handshake notification
> +
> + Notification parameters: Remote address (6 octets)
> + Status (1 octet)
> +
> + Only status values from 0x00 to 0x05 are valid as handshake
> + status.
>
>
> Bluetooth PAN HAL (ID 4)

All patches applied, thanks.

--
Best regards,
Szymon Janc

2014-11-20 11:18:51

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCHv2 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


2014-11-20 11:18:50

by Jakub Tyszkowski

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

---
android/hidhost.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/android/hidhost.c b/android/hidhost.c
index 657fa8f..75e895b 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -58,6 +58,7 @@
#define L2CAP_PSM_HIDP_INTR 0x13

/* HID message types */
+#define HID_MSG_HANDSHAKE 0x00
#define HID_MSG_CONTROL 0x10
#define HID_MSG_GET_REPORT 0x40
#define HID_MSG_SET_REPORT 0x50
@@ -65,6 +66,8 @@
#define HID_MSG_SET_PROTOCOL 0x70
#define HID_MSG_DATA 0xa0

+#define HID_MSG_TYPE_MASK 0xf0
+
/* HID data types */
#define HID_DATA_TYPE_INPUT 0x01
#define HID_DATA_TYPE_OUTPUT 0x02
@@ -391,6 +394,22 @@ 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;
+
+ bdaddr2android(&dev->dst, ev.bdaddr);
+
+ /* crop result code to handshake status range from HAL */
+ ev.status = buf[0];
+ if (ev.status > HAL_HIDHOST_HS_ERROR)
+ ev.status = HAL_HIDHOST_HS_ERROR;
+
+ ipc_send_notif(hal_ipc, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HIDHOST_HANDSHAKE, sizeof(ev), &ev);
+}
+
static void bt_hid_notify_virtual_unplug(struct hid_device *dev,
uint8_t *buf, int len)
{
@@ -441,8 +460,17 @@ static gboolean ctrl_io_watch_cb(GIOChannel *chan, gpointer data)
break;
}

- if (buf[0] == (HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG))
- bt_hid_notify_virtual_unplug(dev, buf, bread);
+ switch (buf[0] & HID_MSG_TYPE_MASK) {
+ case HID_MSG_HANDSHAKE:
+ bt_hid_notify_handshake(dev, buf, bread);
+ break;
+ case HID_MSG_CONTROL:
+ if ((buf[0] & !HID_MSG_TYPE_MASK) == HID_VIRTUAL_CABLE_UNPLUG)
+ bt_hid_notify_virtual_unplug(dev, buf, bread);
+ break;
+ default:
+ break;
+ }

/* reset msg type request */
dev->last_hid_msg = 0;
--
1.9.1


2014-11-20 11:18:49

by Jakub Tyszkowski

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

---
android/hal-hidhost.c | 11 +++++++++++
android/hal-msg.h | 24 ++++++++++++++++++++++--
2 files changed, 33 insertions(+), 2 deletions(-)

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 c575938..ca512d4 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -1353,8 +1353,22 @@ struct hal_ev_hidhost_conn_state {
uint8_t state;
} __attribute__((packed));

-#define HAL_HIDHOST_STATUS_OK 0x00
-#define HAL_HIDHOST_GENERAL_ERROR 0x06
+#define HAL_HIDHOST_STATUS_OK 0x00
+
+#define HAL_HIDHOST_HS_NOT_READY 0x01
+#define HAL_HIDHOST_HS_INVALID_RAPORT_ID 0x02
+#define HAL_HIDHOST_HS_TRANS_NOT_SUPPORTED 0x03
+#define HAL_HIDHOST_HS_INVALID_PARAM 0x04
+#define HAL_HIDHOST_HS_ERROR 0x05
+
+#define HAL_HIDHOST_GENERAL_ERROR 0x06
+#define HAL_HIDHOST_SDP_ERROR 0x07
+#define HAL_HIDHOST_PROTOCOL_ERROR 0x08
+#define HAL_HIDHOST_DB_ERROR 0x09
+#define HAL_HIDHOST_TOD_UNSUPPORTED_ERROR 0x0a
+#define HAL_HIDHOST_NO_RESOURCES_ERROR 0x0b
+#define HAL_HIDHOST_AUTH_FAILED_ERROR 0x0c
+#define HAL_HIDHOST_HDL_ERROR 0x0d

#define HAL_EV_HIDHOST_INFO 0x82
struct hal_ev_hidhost_info {
@@ -1398,6 +1412,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