diff mbox

[1/1] hid: Add HID Report Descriptor to sysfs.

Message ID 1295590785-7101-2-git-send-email-alan@signal11.us (mailing list archive)
State New, archived
Delegated to: Jiri Kosina
Headers show

Commit Message

Alan Ott Jan. 21, 2011, 6:19 a.m. UTC
None
diff mbox

Patch

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index d678cf3..0ff1ba2 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1159,6 +1159,28 @@  static bool hid_hiddev(struct hid_device *hdev)
 	return !!hid_match_id(hdev, hid_hiddev_list);
 }
 
+
+static ssize_t show_report_descriptor(struct device *dev,
+				      struct device_attribute *attr,
+				      char *buf)
+{
+	int i, cur = 0;
+	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
+
+	for (i = 0; i < hdev->rsize; i++) {
+		if (cur + 4 >= PAGE_SIZE)
+			break;
+		sprintf(buf + cur, "%02hhx ", hdev->rdesc[i]);
+		cur += 3;
+	}
+	/* Replace the last space with a newline. */
+	buf[cur-1] = '\n';
+	buf[PAGE_SIZE-1] = '\0';
+	return cur + 1;
+}
+
+static DEVICE_ATTR(report_descriptor, S_IRUGO, show_report_descriptor, NULL);
+
 int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
 {
 	static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
@@ -1169,6 +1191,7 @@  int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
 	char buf[64];
 	unsigned int i;
 	int len;
+	int ret;
 
 	if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
 		connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
@@ -1230,6 +1253,11 @@  int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
 		bus = "<UNKNOWN>";
 	}
 
+	ret = device_create_file(&hdev->dev, &dev_attr_report_descriptor);
+	if (ret)
+		hid_warn(hdev,
+			 "can't create sysfs report descriptor attribute err: %d\n", ret);
+
 	hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
 		 buf, bus, hdev->version >> 8, hdev->version & 0xff,
 		 type, hdev->name, hdev->phys);