MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / get_hid_report_descriptor

Function get_hid_report_descriptor

lib/hidapi/linux/hid.c:356–382  ·  view source on GitHub ↗

* Retrieves the hidraw report descriptor from a file. * When using this form, /device/report_descriptor, elevated priviledges are not required. */

Source from the content-addressed store, hash-verified

354 * When using this form, <sysfs_path>/device/report_descriptor, elevated priviledges are not required.
355 */
356static 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 */
385static int get_hid_report_descriptor_from_sysfs(const char *sysfs_path, struct hidraw_report_descriptor *rpt_desc)

Callers 1

Calls 4

openFunction · 0.85
strerrorFunction · 0.85
readFunction · 0.85

Tested by

no test coverage detected