linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: uinput - Add UI_SET_UNIQ ioctl handler
@ 2019-11-27 18:51 Abhishek Pandit-Subedi
  2019-12-01 14:53 ` Pali Rohár
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Abhishek Pandit-Subedi @ 2019-11-27 18:51 UTC (permalink / raw)
  To: linux-input
  Cc: Pali Rohár, linux-bluetooth, Luiz Augusto von Dentz,
	Abhishek Pandit-Subedi, Enric Balletbo i Serra, linux-kernel,
	Thomas Gleixner, Logan Gunthorpe, Dmitry Torokhov,
	Andrey Smirnov, Kirill Smelkov

Support setting the uniq attribute of the input device. The uniq
attribute is used as a unique identifier for the connected device.

For example, uinput devices created by BlueZ will store the address of
the connected device as the uniq property.

Signed-off-by: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
---
Hi input maintainers,

I added this change to allow BlueZ to display the peer device address in
udev. BlueZ has been setting ATTR{name} to the peer address since it
isn't possible to set the uniq attribute currently.

I've tested this on a Chromebook running kernel v4.19 with this patch.

$ uname -r
4.19.85

$ dmesg | grep "input:" | tail -1
[   69.604752] input: BeatsStudio Wireless as /devices/virtual/input/input17

$ udevadm info -a -p /sys/devices/virtual/input/input17

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/virtual/input/input17':
    KERNEL=="input17"
    SUBSYSTEM=="input"
    DRIVER==""
    ATTR{inhibited}=="0"
    ATTR{name}=="BeatsStudio Wireless"
    ATTR{phys}=="00:00:00:6e:d0:74"
    ATTR{properties}=="0"
    ATTR{uniq}=="00:00:00:cc:1c:f3"

(I zeroed out part of the addresses above. The phys attribute
corresponds to the address of the Bluetooth controller on the Chromebook
and the uniq is the address of the headphones)


 drivers/input/misc/uinput.c | 21 ++++++++++++++++++++-
 include/uapi/linux/uinput.h |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 84051f20b18a..68319bda41b8 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -280,7 +280,7 @@ static int uinput_dev_flush(struct input_dev *dev, struct file *file)
 
 static void uinput_destroy_device(struct uinput_device *udev)
 {
-	const char *name, *phys;
+	const char *name, *phys, *uniq;
 	struct input_dev *dev = udev->dev;
 	enum uinput_state old_state = udev->state;
 
@@ -289,6 +289,7 @@ static void uinput_destroy_device(struct uinput_device *udev)
 	if (dev) {
 		name = dev->name;
 		phys = dev->phys;
+		uniq = dev->uniq;
 		if (old_state == UIST_CREATED) {
 			uinput_flush_requests(udev);
 			input_unregister_device(dev);
@@ -297,6 +298,7 @@ static void uinput_destroy_device(struct uinput_device *udev)
 		}
 		kfree(name);
 		kfree(phys);
+		kfree(uniq);
 		udev->dev = NULL;
 	}
 }
@@ -840,6 +842,7 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
 	struct uinput_ff_erase  ff_erase;
 	struct uinput_request   *req;
 	char			*phys;
+	char			*uniq;
 	const char		*name;
 	unsigned int		size;
 
@@ -931,6 +934,22 @@ static long uinput_ioctl_handler(struct file *file, unsigned int cmd,
 		udev->dev->phys = phys;
 		goto out;
 
+	case UI_SET_UNIQ:
+		if (udev->state == UIST_CREATED) {
+			retval = -EINVAL;
+			goto out;
+		}
+
+		uniq = strndup_user(p, 1024);
+		if (IS_ERR(uniq)) {
+			retval = PTR_ERR(uniq);
+			goto out;
+		}
+
+		kfree(udev->dev->uniq);
+		udev->dev->uniq = uniq;
+		goto out;
+
 	case UI_BEGIN_FF_UPLOAD:
 		retval = uinput_ff_upload_from_user(p, &ff_up);
 		if (retval)
diff --git a/include/uapi/linux/uinput.h b/include/uapi/linux/uinput.h
index c9e677e3af1d..d5b7767c1b02 100644
--- a/include/uapi/linux/uinput.h
+++ b/include/uapi/linux/uinput.h
@@ -145,6 +145,7 @@ struct uinput_abs_setup {
 #define UI_SET_PHYS		_IOW(UINPUT_IOCTL_BASE, 108, char*)
 #define UI_SET_SWBIT		_IOW(UINPUT_IOCTL_BASE, 109, int)
 #define UI_SET_PROPBIT		_IOW(UINPUT_IOCTL_BASE, 110, int)
+#define UI_SET_UNIQ		_IOW(UINPUT_IOCTL_BASE, 111, char*)
 
 #define UI_BEGIN_FF_UPLOAD	_IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
 #define UI_END_FF_UPLOAD	_IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
-- 
2.24.0.432.g9d3f5f5b63-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2024-02-06 17:44 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-27 18:51 [PATCH] Input: uinput - Add UI_SET_UNIQ ioctl handler Abhishek Pandit-Subedi
2019-12-01 14:53 ` Pali Rohár
2019-12-02  1:23   ` Dmitry Torokhov
2019-12-02  8:47     ` Pali Rohár
2019-12-02 17:54       ` Dmitry Torokhov
2019-12-02 18:53         ` Pali Rohár
2019-12-02 19:36           ` Dmitry Torokhov
2019-12-02 22:54             ` Abhishek Pandit-Subedi
2019-12-02 23:09             ` Pali Rohár
2019-12-03 17:38               ` Pali Rohár
2019-12-03 19:11                 ` Dmitry Torokhov
2019-12-04 12:02                   ` Luiz Augusto von Dentz
2019-12-04 21:59                   ` Abhishek Pandit-Subedi
2019-12-05 10:52                   ` Pali Rohár
2019-12-05 20:03                     ` Abhishek Pandit-Subedi
2019-12-06  9:11                       ` Pali Rohár
2019-12-06 17:40                         ` Dmitry Torokhov
2019-12-16 21:57                           ` Abhishek Pandit-Subedi
2019-12-18 11:02                           ` Pali Rohár
2019-12-18 11:26                             ` Pali Rohár
2020-03-22 15:47                               ` Pali Rohár
2022-06-13 21:36                                 ` Luiz Augusto von Dentz
2024-02-06 17:17                                   ` Chris Morgan
2024-02-06 17:44                                     ` Pali Rohár
2019-12-04  1:49 ` Marcel Holtmann
2022-06-29  9:31 ` macmpi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).