Skip to contentSkip to conversation

HID: hidraw: add support uniq ioctl

PATCH Applied Marcel Holtmann 2 participants 2 messages Dec 4, 2019 – Dec 11, 2019 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: hidraw: add support uniq ioctl

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.

---
 drivers/hid/hidraw.c        | 9 +++++++++
 include/uapi/linux/hidraw.h | 1 +
 2 files changed, 10 insertions(+)
drivers/hid/hidraw.c +9 -0
index bbc6ec1aa5cb..039304069fd0 100644
@@ -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;
include/uapi/linux/hidraw.h +1 -0
index 98e2c493de85..4913539e5bcc 100644
@@ -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
Signature · 1 line
2.23.0
maintainer Applied
#1 lore raw
Quoted 17 lines · Marcel Holtmann

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.

---
 drivers/hid/hidraw.c        | 9 +++++++++
 include/uapi/linux/hidraw.h | 1 +
 2 files changed, 10 insertions(+)
drivers/hid/hidraw.c +0 -0
index bbc6ec1aa5cb..039304069fd0 100644
@@ -450,6 +450,15 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
 						-EFAULT : len;
 					break;

drivers/hid/hidraw.c static long hidraw_ioctl(struct file *file, unsigned int cmd, · line 461

Quoted 10 lines
drivers/hid/hidraw.c +9 -0
 				}
+
+				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,

Signature · 2 lines
Jiri Kosina
SUSE Labs