linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: hidraw: add support uniq ioctl
@ 2019-12-04  3:41 Marcel Holtmann
  2019-12-11 14:33 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Marcel Holtmann @ 2019-12-04  3:41 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires; +Cc: abhishekpandit, linux-input, linux-kernel

Add support for reading out the uniq information from the underlying HID
device. This might be the iSerialNumber in case of USB or the BD_ADDR in
case of Bluetooth.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 drivers/hid/hidraw.c        | 9 +++++++++
 include/uapi/linux/hidraw.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index bbc6ec1aa5cb..039304069fd0 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -450,6 +450,15 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
 						-EFAULT : len;
 					break;
 				}
+
+				if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWUNIQ(0))) {
+					int len = strlen(hid->uniq) + 1;
+					if (len > _IOC_SIZE(cmd))
+						len = _IOC_SIZE(cmd);
+					ret = copy_to_user(user_arg, hid->uniq, len) ?
+						-EFAULT : len;
+					break;
+				}
 			}
 
 		ret = -ENOTTY;
diff --git a/include/uapi/linux/hidraw.h b/include/uapi/linux/hidraw.h
index 98e2c493de85..4913539e5bcc 100644
--- a/include/uapi/linux/hidraw.h
+++ b/include/uapi/linux/hidraw.h
@@ -39,6 +39,7 @@ struct hidraw_devinfo {
 /* The first byte of SFEATURE and GFEATURE is the report number */
 #define HIDIOCSFEATURE(len)    _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len)
 #define HIDIOCGFEATURE(len)    _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)
+#define HIDIOCGRAWUNIQ(len)     _IOC(_IOC_READ, 'H', 0x08, len)
 
 #define HIDRAW_FIRST_MINOR 0
 #define HIDRAW_MAX_DEVICES 64
-- 
2.23.0


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

* Re: [PATCH] HID: hidraw: add support uniq ioctl
  2019-12-04  3:41 [PATCH] HID: hidraw: add support uniq ioctl Marcel Holtmann
@ 2019-12-11 14:33 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2019-12-11 14:33 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: Benjamin Tissoires, abhishekpandit, linux-input, linux-kernel

On Wed, 4 Dec 2019, Marcel Holtmann wrote:

> Add support for reading out the uniq information from the underlying HID
> device. This might be the iSerialNumber in case of USB or the BD_ADDR in
> case of Bluetooth.
> 
> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
>  drivers/hid/hidraw.c        | 9 +++++++++
>  include/uapi/linux/hidraw.h | 1 +
>  2 files changed, 10 insertions(+)
> 
> diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
> index bbc6ec1aa5cb..039304069fd0 100644
> --- a/drivers/hid/hidraw.c
> +++ b/drivers/hid/hidraw.c
> @@ -450,6 +450,15 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
>  						-EFAULT : len;
>  					break;
>  				}
> +
> +				if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWUNIQ(0))) {
> +					int len = strlen(hid->uniq) + 1;
> +					if (len > _IOC_SIZE(cmd))
> +						len = _IOC_SIZE(cmd);
> +					ret = copy_to_user(user_arg, hid->uniq, len) ?
> +						-EFAULT : len;
> +					break;
> +				}

Queued for 5.6. Thanks,

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2019-12-11 14:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04  3:41 [PATCH] HID: hidraw: add support uniq ioctl Marcel Holtmann
2019-12-11 14:33 ` Jiri Kosina

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).