* [PATCH BlueZ 2/3] android/hal-hidhost: Add implementation of .connection_state_cb
2013-10-31 12:19 [PATCH BlueZ 1/3] android/hid: Add handling of incoming connections Luiz Augusto von Dentz
@ 2013-10-31 12:19 ` Luiz Augusto von Dentz
2013-10-31 12:19 ` [PATCH BlueZ 3/3] android/hid: Add handling of HAL_EV_HID_CONN_STATE Luiz Augusto von Dentz
2013-10-31 13:00 ` [PATCH BlueZ 1/3] android/hid: Add handling of incoming connections Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2013-10-31 12:19 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
android/hal-hidhost.c | 25 +++++++++++++++++++++++++
android/hal-ipc-api.txt | 1 +
android/hal-ipc.c | 3 +++
android/hal-msg.h | 14 ++++++++++++++
android/hal.h | 1 +
5 files changed, 44 insertions(+)
diff --git a/android/hal-hidhost.c b/android/hal-hidhost.c
index 032e961..9354b95 100644
--- a/android/hal-hidhost.c
+++ b/android/hal-hidhost.c
@@ -31,6 +31,31 @@ static bool interface_ready(void)
return bt_hh_cbacks != NULL;
}
+static void handle_conn_state(void *buf)
+{
+ struct hal_ev_hid_conn_state *ev = buf;
+
+ if (bt_hh_cbacks->connection_state_cb)
+ bt_hh_cbacks->connection_state_cb((bt_bdaddr_t *) (ev->bdaddr),
+ ev->state);
+}
+
+/* will be called from notification thread context */
+void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len)
+{
+ if (!interface_ready())
+ return;
+
+ switch (opcode) {
+ case HAL_EV_HID_CONN_STATE:
+ handle_conn_state(buf);
+ break;
+ default:
+ DBG("Unhandled callback opcode=0x%x", opcode);
+ break;
+ }
+}
+
static bt_status_t hh_connect(bt_bdaddr_t *bd_addr)
{
struct hal_cmd_hid_connect cmd;
diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index a5d1980..6b11684 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -574,6 +574,7 @@ Notifications:
Opcode 0x81 - Connection State notification
Notification parameters: Remote address (6 octets)
+ Connection State (1 octets)
Valid connection states: 0x00 = Connected
0x01 = Connecting
diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index f68e789..14be69b 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -49,6 +49,9 @@ static void notification_dispatch(struct hal_hdr *msg, int fd)
case HAL_SERVICE_ID_BLUETOOTH:
bt_notify_adapter(msg->opcode, msg->payload, msg->len);
break;
+ case HAL_SERVICE_ID_HIDHOST:
+ bt_notify_hh(msg->opcode, msg->payload, msg->len);
+ break;
case HAL_SERVICE_ID_A2DP:
bt_notify_av(msg->opcode, msg->payload, msg->len);
break;
diff --git a/android/hal-msg.h b/android/hal-msg.h
index dfe73cc..b792411 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -423,6 +423,20 @@ struct hal_ev_le_test_mode {
uint16_t num_packets;
} __attribute__((packed));
+#define HAL_HID_STATE_CONNECTED 0x00
+#define HAL_HID_STATE_CONNECTING 0x01
+#define HAL_HID_STATE_DISCONNECTED 0x02
+#define HAL_HID_STATE_DISCONNECTING 0x03
+#define HAL_HID_STATE_NO_HID 0x07
+#define HAL_HID_STATE_FAILED 0x08
+#define HAL_HID_STATE_UNKNOWN 0x09
+
+#define HAL_EV_HID_CONN_STATE 0x81
+struct hal_ev_hid_conn_state {
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
#define HAL_EV_AV_CONNECTION_STATE 0x81
struct hal_ev_av_connection_state {
uint8_t state;
diff --git a/android/hal.h b/android/hal.h
index a377649..5d6a93e 100644
--- a/android/hal.h
+++ b/android/hal.h
@@ -29,4 +29,5 @@ btav_interface_t *bt_get_av_interface(void);
void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len);
void bt_thread_associate(void);
void bt_thread_disassociate(void);
+void bt_notify_hh(uint16_t opcode, void *buf, uint16_t len);
void bt_notify_av(uint16_t opcode, void *buf, uint16_t len);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH BlueZ 3/3] android/hid: Add handling of HAL_EV_HID_CONN_STATE
2013-10-31 12:19 [PATCH BlueZ 1/3] android/hid: Add handling of incoming connections Luiz Augusto von Dentz
2013-10-31 12:19 ` [PATCH BlueZ 2/3] android/hal-hidhost: Add implementation of .connection_state_cb Luiz Augusto von Dentz
@ 2013-10-31 12:19 ` Luiz Augusto von Dentz
2013-10-31 13:00 ` [PATCH BlueZ 1/3] android/hid: Add handling of incoming connections Johan Hedberg
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2013-10-31 12:19 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This patches generate proper events when the connection state changes:
>hidhost connect
BlueZ D: android/hal-hidhost.c:hh_connect()
connection_state_cb: bd_addr= connection_state=BTHH_CONN_STATE_CONNECTING
if_hh->connect: BT_STATUS_SUCCESS
connection_state_cb: bd_addr= connection_state=BTHH_CONN_STATE_CONNECTED
>hidhost disconnect
BlueZ D: android/hal-hidhost.c:hh_disconnect()
connection_state_cb: bd_addr= connection_state=BTHH_CONN_STATE_DISCONNECTING
if_hh->disconnect: BT_STATUS_SUCCESS
connection_state_cb: bd_addr= connection_state=BTHH_CONN_STATE_DISCONNECTED
---
android/hid.c | 46 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/android/hid.c b/android/hid.c
index 92efd72..5caa25b 100644
--- a/android/hid.c
+++ b/android/hid.c
@@ -51,6 +51,7 @@ static GSList *devices = NULL;
struct hid_device {
bdaddr_t dst;
+ uint8_t state;
GIOChannel *ctrl_io;
GIOChannel *intr_io;
guint ctrl_watch;
@@ -104,18 +105,34 @@ static gboolean intr_io_watch_cb(GIOChannel *chan, gpointer data)
return TRUE;
}
+static void bt_hid_set_state(struct hid_device *hdev, uint8_t state)
+{
+ struct hal_ev_hid_conn_state ev;
+ char address[18];
+
+ if (hdev->state == state)
+ return;
+
+ hdev->state = state;
+
+ ba2str(&hdev->dst, address);
+ DBG("device %s state %u", address, state);
+
+ bdaddr2android(&hdev->dst, ev.bdaddr);
+ ev.state = state;
+
+ ipc_send(notification_io, HAL_SERVICE_ID_HIDHOST,
+ HAL_EV_HID_CONN_STATE, sizeof(ev), &ev, -1);
+}
+
static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
struct hid_device *hdev = data;
- char address[18];
if (cond & G_IO_IN)
return intr_io_watch_cb(chan, data);
- ba2str(&hdev->dst, address);
- DBG("Device %s disconnected", address);
-
/* Checking for ctrl_watch avoids a double g_io_channel_shutdown since
* it's likely that ctrl_watch_cb has been queued for dispatching in
* this mainloop iteration */
@@ -143,7 +160,7 @@ static gboolean ctrl_watch_cb(GIOChannel *chan, GIOCondition cond,
char address[18];
ba2str(&hdev->dst, address);
- DBG("Device %s disconnected", address);
+ bt_hid_set_state(hdev, HAL_HID_STATE_DISCONNECTED);
/* Checking for intr_watch avoids a double g_io_channel_shutdown since
* it's likely that intr_watch_cb has been queued for dispatching in
@@ -175,6 +192,8 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
intr_watch_cb, hdev);
+ bt_hid_set_state(hdev, HAL_HID_STATE_CONNECTED);
+
return;
failed:
@@ -203,6 +222,7 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
DBG("");
if (conn_err) {
+ bt_hid_set_state(hdev, HAL_HID_STATE_DISCONNECTED);
error("%s", conn_err->message);
goto failed;
}
@@ -270,6 +290,7 @@ static uint8_t bt_hid_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
}
devices = g_slist_append(devices, hdev);
+ bt_hid_set_state(hdev, HAL_HID_STATE_CONNECTING);
return HAL_STATUS_SUCCESS;
}
@@ -277,6 +298,7 @@ static uint8_t bt_hid_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
static uint8_t bt_hid_disconnect(struct hal_cmd_hid_disconnect *cmd,
uint16_t len)
{
+ struct hid_device *hdev;
GSList *l;
bdaddr_t dst;
@@ -291,7 +313,16 @@ static uint8_t bt_hid_disconnect(struct hal_cmd_hid_disconnect *cmd,
if (!l)
return HAL_STATUS_FAILED;
- hid_device_free(l->data);
+ hdev = l->data;
+
+ /* Wait either channels to HUP */
+ if (hdev->intr_io)
+ g_io_channel_shutdown(hdev->intr_io, TRUE, NULL);
+
+ if (hdev->ctrl_io)
+ g_io_channel_shutdown(hdev->ctrl_io, TRUE, NULL);
+
+ bt_hid_set_state(hdev, HAL_HID_STATE_DISCONNECTING);
return HAL_STATUS_SUCCESS;
}
@@ -357,7 +388,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
hdev->ctrl_watch = g_io_add_watch(hdev->ctrl_io,
G_IO_HUP | G_IO_ERR | G_IO_NVAL,
ctrl_watch_cb, hdev);
-
+ bt_hid_set_state(hdev, HAL_HID_STATE_CONNECTING);
break;
case L2CAP_PSM_HIDP_INTR:
@@ -370,6 +401,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
hdev->intr_watch = g_io_add_watch(hdev->intr_io,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
intr_watch_cb, hdev);
+ bt_hid_set_state(hdev, HAL_HID_STATE_CONNECTED);
break;
}
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread