* Retrieves the hidraw report descriptor from a file. * When using this form, /device/report_descriptor, elevated priviledges are not required. */
| 354 | * When using this form, <sysfs_path>/device/report_descriptor, elevated priviledges are not required. |
| 355 | */ |
| 356 | static int get_hid_report_descriptor(const char *rpt_path, struct hidraw_report_descriptor *rpt_desc) |
| 357 | { |
| 358 | int rpt_handle; |
| 359 | ssize_t res; |
| 360 | |
| 361 | rpt_handle = open(rpt_path, O_RDONLY | O_CLOEXEC); |
| 362 | if (rpt_handle < 0) { |
| 363 | register_global_error_format("open failed (%s): %s", rpt_path, strerror(errno)); |
| 364 | return -1; |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * Read in the Report Descriptor |
| 369 | * The sysfs file has a maximum size of 4096 (which is the same as HID_MAX_DESCRIPTOR_SIZE) so we should always |
| 370 | * be ok when reading the descriptor. |
| 371 | * In practice if the HID descriptor is any larger I suspect many other things will break. |
| 372 | */ |
| 373 | memset(rpt_desc, 0x0, sizeof(*rpt_desc)); |
| 374 | res = read(rpt_handle, rpt_desc->value, HID_MAX_DESCRIPTOR_SIZE); |
| 375 | if (res < 0) { |
| 376 | register_global_error_format("read failed (%s): %s", rpt_path, strerror(errno)); |
| 377 | } |
| 378 | rpt_desc->size = (__u32) res; |
| 379 | |
| 380 | close(rpt_handle); |
| 381 | return (int) res; |
| 382 | } |
| 383 | |
| 384 | /* return size of the descriptor, or -1 on failure */ |
| 385 | static int get_hid_report_descriptor_from_sysfs(const char *sysfs_path, struct hidraw_report_descriptor *rpt_desc) |
no test coverage detected