Skip to contentSkip to conversation

add support to fake HID devices

PATCH In review Aristeu Rozanski 3 participants 3 messages Mar 13, 2008 – Mar 14, 2008 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH v11 1/2 add support to fake HID devices

This patch adds support to fake HID devices. Instead of registering with kernel, the fake HID will be handled in user level and an uinput device will be created in order to get the events into input layer.

---
 input/Makefile.am |    3 +-
 input/device.c    |   58 ++++++++++++++++++++++++++++++++++++----------------
 input/device.h    |   12 ++++++++++
 input/fakehid.c   |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 input/fakehid.h   |   18 ++++++++++++++++
 5 files changed, 132 insertions(+), 19 deletions(-)
input/device.c +40 -18
@@ -52,6 +52,7 @@
 #include "error.h"
 #include "manager.h"
 #include "storage.h"
+#include "fakehid.h"
 
 #define INPUT_DEVICE_INTERFACE	"org.bluez.input.Device"
 
@@ -63,16 +64,6 @@
 
 struct device;
 
-struct fake_input {
-	int		flags;
-	GIOChannel	*io;
-	int		rfcomm; /* RFCOMM socket */
-	int		uinput;	/* uinput socket */
-	uint8_t		ch;	/* RFCOMM channel number */
-	gboolean	(*connect)(struct device *idev);
-	int		(*disconnect)(struct device *idev);
-};
-
 struct device {
 	bdaddr_t		src;
 	bdaddr_t		dst;
@@ -1336,24 +1327,47 @@ int input_device_close_channels(bdaddr_t
 	return 0;
 }
 
+static gboolean fake_hid_connect(struct device *dev)
+{
+	struct fake_hid *fhid = dev->fake->priv;
+
+	return fhid->connect(dev->fake);
+}
+
+static int fake_hid_disconnect(struct device *dev)
+{
+	struct fake_hid *fhid = dev->fake->priv;
+
+	return fhid->disconnect(dev->fake);
+}
+
 int input_device_connadd(bdaddr_t *src, bdaddr_t *dst)
 {
 	struct device *idev;
+	struct fake_hid *fake_hid;
+	struct fake_input *fake = NULL;
 	int err;
 
 	idev = find_device(src, dst);
 	if (!idev)
 		return -ENOENT;
 
-	err = hidp_connadd(src, dst, idev->ctrl_sk, idev->intr_sk, idev->name);
-	if (err < 0) {
-		close(idev->ctrl_sk);
-		close(idev->intr_sk);
-		idev->ctrl_sk = -1;
-		idev->intr_sk = -1;
+	fake_hid = get_fake_hid(idev->vendor, idev->product);
+	if (fake_hid) {
+		fake = g_try_new0(struct fake_input, 1)
+		if (!fake) {
+			err = -ENOMEM;
+			goto error;
+		}
 
-		return err;
-	}
+		fake->connect = fake_hid_connect;
+		fake->disconnect = fake_hid_disconnect;
+		fake->priv = fake_hid;
+		err = fake_hid_connadd(fake, idev->intr_sk, fake_hid);
+	} else
+		err = hidp_connadd(src, dst, idev->ctrl_sk, idev->intr_sk, idev->name);
+	if (err < 0)
+		goto error;
 
 	idev->intr_watch = create_watch(idev->intr_sk, intr_watch_cb, idev);
 	idev->ctrl_watch = create_watch(idev->ctrl_sk, ctrl_watch_cb, idev);
@@ -1363,4 +1377,12 @@ int input_device_connadd(bdaddr_t *src, 
 			"Connected",
 			DBUS_TYPE_INVALID);
 	return 0;
+error:
+	close(idev->ctrl_sk);
+	close(idev->intr_sk);
+	idev->ctrl_sk = -1;
+	idev->intr_sk = -1;
+	if (fake)
+		gfree(fake);
+	return err;
 }
input/fakehid.h new file +18 -0
@@ -0,0 +1,18 @@
+#ifndef FAKEHID_H
+#define FAKEHID_H
+#include <glib.h>
+struct fake_hid;
+struct fake_input;
+
+struct fake_hid {
+	uint16_t vendor;
+	uint16_t product;
+	gboolean (*connect)(struct fake_input *fake_input);
+	int (*disconnect)(struct fake_input *fake_input);
+	gboolean (*event)(GIOChannel *chan, GIOCondition cond, gpointer data);
+	int (*setup_uinput)(struct fake_input *fake, struct fake_hid *fake_hid);
+};
+struct fake_hid *get_fake_hid(uint16_t vendor, uint16_t product);
+int fake_hid_connadd(struct fake_input *fake, int intr_sk,
+		     struct fake_hid *fake_hid);
+#endif	/* FAKEHID_H */
input/fakehid.c new file +60 -0

60 lines not on this page · raw message

input/device.h +12 -0
@@ -24,6 +24,18 @@
 #define L2CAP_PSM_HIDP_CTRL	0x11
 #define L2CAP_PSM_HIDP_INTR	0x13
 
+struct device;
+struct fake_input {
+	int		flags;
+	GIOChannel	*io;
+	int		uinput;	/* uinput socket */
+	int		rfcomm; /* RFCOMM socket */
+	uint8_t		ch;	/* RFCOMM channel number */
+	gboolean 	(*connect) (struct device *dev);
+	int		(*disconnect) (struct device *dev);
+	void		*priv;
+};
+
 int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst,
 			struct hidp_connadd_req *hidp, const char **ppath);
 int fake_input_register(DBusConnection *conn, bdaddr_t *src,
input/Makefile.am +2 -1
@@ -12,7 +12,8 @@ service_PROGRAMS = bluetoothd-service-in
 
 bluetoothd_service_input_SOURCES = main.c \
 	manager.h manager.c \
-	server.h server.c device.h device.c storage.h storage.c
+	server.h server.c device.h device.c storage.h storage.c \
+	fakehid.c fakehid.h
 
 LDADD = $(top_builddir)/common/libhelper.a \
 		@GLIB_LIBS@ @DBUS_LIBS@ @BLUEZ_LIBS@

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#1 lore raw
Quoted 3 lines · Aristeu Rozanski

This patch adds support to fake HID devices. Instead of registering with kernel, the fake HID will be handled in user level and an uinput device will be created in order to get the events into input layer.

<snip>

input/device.c int input_device_close_channels(bdaddr_t · line 1357

Quoted 1 line
input/device.c +1 -0
+		fake = g_try_new0(struct fake_input, 1)

Missing a semi-colon.

input/device.c int input_device_connadd(bdaddr_t *src, · line 1386

Quoted 2 lines
input/device.c +2 -0
+	if (fake)
+		gfree(fake);

g_free, not gfree.

Works fine after those changes.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#2 lore raw

Hi Bastien,

Quoted 11 lines
Quoted 5 lines

This patch adds support to fake HID devices. Instead of registering with
kernel, the fake HID will be handled in user level and an uinput device
will be created in order to get the events into input layer.

<snip>

input/device.c int input_device_close_channels(bdaddr_t · line 1357

Quoted 1 line
input/device.c +1 -0
+		fake = g_try_new0(struct fake_input, 1)

Missing a semi-colon.

Quoted 6 lines

input/device.c int input_device_connadd(bdaddr_t *src, · line 1386

Quoted 2 lines
input/device.c +2 -0
+	if (fake)
+		gfree(fake);

g_free, not gfree.

Works fine after those changes.

fixed everything, but I had to do some manual fixups for coding style and so on. This patch is in. The other one isn't. I need an updated one.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel