Skip to contentSkip to conversation

Initial HID connect disconnect methods

PATCH In review Ravi kumar Veeramally 2 participants 5 messages Oct 28, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Initial HID connect disconnect methods

Patchset adds hid connect and disconnect mechanisms at L2CAP level. It opens the control channel and interrupt channel and listens on io events. UHID, hid server and reconnect related features not yet done.

Ravi kumar Veeramally (2):
android: Add initial HID connect implementation
android: Add initial HID disconnect implementation.

 Makefile.android   |    3 +-
 android/Android.mk |    1 +
 android/hid.c      |  260 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 263 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/2 android: Add initial HID connect implementation

Implemented basic HID connect method. Host connects to bt device at L2CAP level.

---
 Makefile.android   |    3 +-
 android/Android.mk |    1 +
 android/hid.c      |  237 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 240 insertions(+), 1 deletion(-)
Makefile.android +2 -1
index 2b57daa..22002be 100644
@@ -12,7 +12,8 @@ android_bluetoothd_SOURCES =	android/main.c \
 				android/adapter.h android/adapter.c \
 				android/hid.h android/hid.c \
 				android/ipc.h android/ipc.c \
-				android/socket.h android/socket.c
+				android/socket.h android/socket.c \
+				btio/btio.h btio/btio.c
 
 android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
 
android/Android.mk +1 -0
index 22208e0..28ec465 100644
@@ -28,6 +28,7 @@ LOCAL_SRC_FILES := \
 	../lib/sdp.c \
 	../lib/bluetooth.c \
 	../lib/hci.c \
+	../btio/btio.c
 
 LOCAL_C_INCLUDES := \
 	$(call include-path-for, glib) \
android/hid.c +237 -0

259 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH 1/2] android: Add initial HID connect implementation

Hi Ravi,

Quoted 64 lines · Ravi kumar Veeramally

Implemented basic HID connect method. Host connects to bt device at L2CAP level.

---
 Makefile.android   |    3 +-
 android/Android.mk |    1 +
 android/hid.c      |  237 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 240 insertions(+), 1 deletion(-)
Makefile.android +2 -1
index 2b57daa..22002be 100644
@@ -12,7 +12,8 @@ android_bluetoothd_SOURCES =  android/main.c \
                                android/adapter.h android/adapter.c \
                                android/hid.h android/hid.c \
                                android/ipc.h android/ipc.c \
-                               android/socket.h android/socket.c
+                               android/socket.h android/socket.c \
+                               btio/btio.h btio/btio.c
 
 android_bluetoothd_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
 
android/Android.mk +1 -0
index 22208e0..28ec465 100644
@@ -28,6 +28,7 @@ LOCAL_SRC_FILES := \
        ../lib/sdp.c \
        ../lib/bluetooth.c \
        ../lib/hci.c \
+       ../btio/btio.c
 
 LOCAL_C_INCLUDES := \
        $(call include-path-for, glib) \
android/hid.c +12 -0
index f2da0d3..b7bdc07 100644
@@ -23,16 +23,252 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 #include <glib.h>
 
+#include "btio/btio.h"
 #include "lib/bluetooth.h"
+#include "src/shared/mgmt.h"
+
 #include "log.h"
 #include "hal-msg.h"
 #include "ipc.h"
 #include "hid.h"
+#include "adapter.h"
+#include "utils.h"
+
+#define L2CAP_PSM_HIDP_CTRL    0x11
+#define L2CAP_PSM_HIDP_INTR    0x13
+#define MAX_READ_BUFFER                4096
 
 static GIOChannel *notification_io = NULL;

android/hid.c line 57

Quoted 10 lines
android/hid.c +10 -0
+static GSList *devices = NULL;
+
+struct input_device {
+       bdaddr_t        src;
+       bdaddr_t        dst;
+       GIOChannel      *ctrl_io;
+       GIOChannel      *intr_io;
+       guint           ctrl_watch;
+       guint           intr_watch;
+};

You probably don't need the address of the adapter as there could be only one in android you can always query its value via bt_adapter_get_address.

Quoted 5 lines
android/hid.c +5 -0
+static uint8_t dev_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
+{
+       struct input_device *idev;
+       char addr[18];
+       GError *err = NULL;

android/hid.c line 251

Quoted 10 lines
android/hid.c +10 -0
+
+       DBG("");
+
+       if (len < sizeof(*cmd))
+               return HAL_STATUS_INVALID;
+
+       idev = g_new0(struct input_device, 1);
+       bacpy(&idev->src, bt_adapter_get_address());
+       android2bdaddr((bdaddr_t *)&cmd->bdaddr, &idev->dst);
+       ba2str(&idev->dst, addr);

Might be worth checking if there a connection ongoing before you create a new data, I would also avoid having the same struct names from our input plugin, just use something else like hid_data.

Quoted 24 lines
android/hid.c +20 -0
+
+       DBG("connecting to %s", addr);
+
+       idev->ctrl_io = bt_io_connect(control_connect_cb, idev, NULL, &err,
+                                       BT_IO_OPT_SOURCE_BDADDR, &idev->src,
+                                       BT_IO_OPT_DEST_BDADDR, &idev->dst,
+                                       BT_IO_OPT_PSM, L2CAP_PSM_HIDP_CTRL,
+                                       BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
+                                       BT_IO_OPT_INVALID);
+       if (err) {
+               error("%s", err->message);
+               g_error_free(err);
+               input_device_free(idev);
+               return HAL_STATUS_FAILED;
+       }
+
+       devices = g_slist_append(devices, idev);
+
+       return HAL_STATUS_SUCCESS;
+}
 
 void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
 {

android/hid.c void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len) · line 279

Quoted 4 lines
android/hid.c +1 -0
@@ -40,6 +276,7 @@ void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
 
        switch (opcode) {
        case HAL_OP_HID_CONNECT:
+               status = dev_connect((struct hal_cmd_hid_connect *) buf, len);

Call it hid_connect or bt_hid_connect.

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw

PATCH 2/2 android: Add initial HID disconnect implementation.

In reply to Ravi kumar Veeramally

Implemented basic HID disconnect method. Host disconnects with bt device at L2CAP level.

---
 android/hid.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
android/hid.c +23 -0
index b7bdc07..3e7ac0d 100644
@@ -270,6 +270,27 @@ static uint8_t dev_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
 	return HAL_STATUS_SUCCESS;
 }
 
+static uint8_t dev_disconnect(struct hal_cmd_hid_disconnect *cmd, uint16_t len)
+{
+	GSList *l;
+	bdaddr_t dst;
+
+	DBG("");
+
+	if (len < sizeof(*cmd))
+		return HAL_STATUS_INVALID;
+
+	android2bdaddr((bdaddr_t *)&cmd->bdaddr, &dst);
+
+	l = g_slist_find_custom(devices, &dst, device_cmp);
+	if (!l)
+		return HAL_STATUS_FAILED;
+
+	input_device_free(l->data);
+
+	return HAL_STATUS_SUCCESS;
+}
+
 void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
 {
 	uint8_t status = HAL_STATUS_FAILED;
@@ -279,6 +300,8 @@ void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
 		status = dev_connect((struct hal_cmd_hid_connect *) buf, len);
 		break;
 	case HAL_OP_HID_DISCONNECT:
+		status = dev_disconnect((struct hal_cmd_hid_disconnect *) buf,
+									len);
 		break;
 	default:
 		DBG("Unhandled command, opcode 0x%x", opcode);
Signature · 1 line
1.7.9.5
#4 lore raw

Re: [PATCH 2/2] android: Add initial HID disconnect implementation.

Hi Ravi,

Quoted 39 lines · Ravi kumar Veeramally

Implemented basic HID disconnect method. Host disconnects with bt device at L2CAP level.

---
 android/hid.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
android/hid.c +21 -0
index b7bdc07..3e7ac0d 100644
@@ -270,6 +270,27 @@ static uint8_t dev_connect(struct hal_cmd_hid_connect *cmd, uint16_t len)
        return HAL_STATUS_SUCCESS;
 }
 
+static uint8_t dev_disconnect(struct hal_cmd_hid_disconnect *cmd, uint16_t len)
+{
+       GSList *l;
+       bdaddr_t dst;
+
+       DBG("");
+
+       if (len < sizeof(*cmd))
+               return HAL_STATUS_INVALID;
+
+       android2bdaddr((bdaddr_t *)&cmd->bdaddr, &dst);
+
+       l = g_slist_find_custom(devices, &dst, device_cmp);
+       if (!l)
+               return HAL_STATUS_FAILED;
+
+       input_device_free(l->data);
+
+       return HAL_STATUS_SUCCESS;
+}
+
 void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
 {
        uint8_t status = HAL_STATUS_FAILED;

android/hid.c void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len) · line 304

Quoted 5 lines
android/hid.c +2 -0
@@ -279,6 +300,8 @@ void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
                status = dev_connect((struct hal_cmd_hid_connect *) buf, len);
                break;
        case HAL_OP_HID_DISCONNECT:
+               status = dev_disconnect((struct hal_cmd_hid_disconnect *) buf,
+                                                                       len);

Look at the other files, we are not doing the casts upfront but in the function itself.

Signature · 1 line
Luiz Augusto von Dentz