OSDN Git Service

HID: hidraw: add support uniq ioctl
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 4 Dec 2019 03:41:09 +0000 (04:41 +0100)
committerJiri Kosina <jkosina@suse.cz>
Wed, 11 Dec 2019 14:31:52 +0000 (15:31 +0100)
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>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hidraw.c
include/uapi/linux/hidraw.h

index c3fc0ce..5dfe802 100644 (file)
@@ -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;
index 98e2c49..4913539 100644 (file)
@@ -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