Commit 9188e79ec3fd43a0a605274324aecfb731baa88b

Authored by Jiri Kosina
1 parent 6bbe586fd4

HID: add phys and name ioctls to hidraw

The hiddev interface provides ioctl() calls which can be used
to obtain phys and raw name of the underlying device.

Add the corresponding support also into hidraw.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>

Showing 2 changed files with 30 additions and 0 deletions Side-by-side Diff

drivers/hid/hidraw.c
... ... @@ -265,6 +265,34 @@
265 265 break;
266 266 }
267 267 default:
  268 + {
  269 + struct hid_device *hid = dev->hid;
  270 + if (_IOC_TYPE(cmd) != 'H' || _IOC_DIR(cmd) != _IOC_READ)
  271 + return -EINVAL;
  272 +
  273 + if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWNAME(0))) {
  274 + int len;
  275 + if (!hid->name)
  276 + return 0;
  277 + len = strlen(hid->name) + 1;
  278 + if (len > _IOC_SIZE(cmd))
  279 + len = _IOC_SIZE(cmd);
  280 + return copy_to_user(user_arg, hid->name, len) ?
  281 + -EFAULT : len;
  282 + }
  283 +
  284 + if (_IOC_NR(cmd) == _IOC_NR(HIDIOCGRAWPHYS(0))) {
  285 + int len;
  286 + if (!hid->phys)
  287 + return 0;
  288 + len = strlen(hid->phys) + 1;
  289 + if (len > _IOC_SIZE(cmd))
  290 + len = _IOC_SIZE(cmd);
  291 + return copy_to_user(user_arg, hid->phys, len) ?
  292 + -EFAULT : len;
  293 + }
  294 + }
  295 +
268 296 ret = -ENOTTY;
269 297 }
270 298 unlock_kernel();
include/linux/hidraw.h
... ... @@ -33,6 +33,8 @@
33 33 #define HIDIOCGRDESCSIZE _IOR('H', 0x01, int)
34 34 #define HIDIOCGRDESC _IOR('H', 0x02, struct hidraw_report_descriptor)
35 35 #define HIDIOCGRAWINFO _IOR('H', 0x03, struct hidraw_devinfo)
  36 +#define HIDIOCGRAWNAME(len) _IOC(_IOC_READ, 'H', 0x04, len)
  37 +#define HIDIOCGRAWPHYS(len) _IOC(_IOC_READ, 'H', 0x05, len)
36 38  
37 39 #define HIDRAW_FIRST_MINOR 0
38 40 #define HIDRAW_MAX_DEVICES 64