Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

HID: Add HID Report Descriptor to sysfs

Add a new binary sysfs entry called report_descriptor which contains
the HID report descriptor.

Signed-off-by: Alan Ott <alan@signal11.us>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>

authored by

Alan Ott and committed by
Jiri Kosina
6d3bfb74 8ef39531

+43
+10
Documentation/ABI/testing/sysfs-driver-hid
··· 1 + What: For USB devices : /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/report_descriptor 2 + For BT devices : /sys/class/bluetooth/hci<addr>/<hid-bus>:<vendor-id>:<product-id>.<num>/report_descriptor 3 + Symlink : /sys/class/hidraw/hidraw<num>/device/report_descriptor 4 + Date: Jan 2011 5 + KernelVersion: 2.0.39 6 + Contact: Alan Ott <alan@signal11.us> 7 + Description: When read, this file returns the device's raw binary HID 8 + report descriptor. 9 + This file cannot be written. 10 + Users: HIDAPI library (http://www.signal11.us/oss/hidapi)
+33
drivers/hid/hid-core.c
··· 1159 1159 return !!hid_match_id(hdev, hid_hiddev_list); 1160 1160 } 1161 1161 1162 + 1163 + static ssize_t 1164 + read_report_descriptor(struct file *filp, struct kobject *kobj, 1165 + struct bin_attribute *attr, 1166 + char *buf, loff_t off, size_t count) 1167 + { 1168 + struct device *dev = container_of(kobj, struct device, kobj); 1169 + struct hid_device *hdev = container_of(dev, struct hid_device, dev); 1170 + 1171 + if (off >= hdev->rsize) 1172 + return 0; 1173 + 1174 + if (off + count > hdev->rsize) 1175 + count = hdev->rsize - off; 1176 + 1177 + memcpy(buf, hdev->rdesc + off, count); 1178 + 1179 + return count; 1180 + } 1181 + 1182 + static struct bin_attribute dev_bin_attr_report_desc = { 1183 + .attr = { .name = "report_descriptor", .mode = 0444 }, 1184 + .read = read_report_descriptor, 1185 + .size = HID_MAX_DESCRIPTOR_SIZE, 1186 + }; 1187 + 1162 1188 int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 1163 1189 { 1164 1190 static const char *types[] = { "Device", "Pointer", "Mouse", "Device", ··· 1195 1169 char buf[64]; 1196 1170 unsigned int i; 1197 1171 int len; 1172 + int ret; 1198 1173 1199 1174 if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE) 1200 1175 connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV); ··· 1257 1230 bus = "<UNKNOWN>"; 1258 1231 } 1259 1232 1233 + ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 1234 + if (ret) 1235 + hid_warn(hdev, 1236 + "can't create sysfs report descriptor attribute err: %d\n", ret); 1237 + 1260 1238 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", 1261 1239 buf, bus, hdev->version >> 8, hdev->version & 0xff, 1262 1240 type, hdev->name, hdev->phys); ··· 1272 1240 1273 1241 void hid_disconnect(struct hid_device *hdev) 1274 1242 { 1243 + device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 1275 1244 if (hdev->claimed & HID_CLAIMED_INPUT) 1276 1245 hidinput_disconnect(hdev); 1277 1246 if (hdev->claimed & HID_CLAIMED_HIDDEV)