Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hid_get_device_info #432

Merged
merged 28 commits into from
Aug 13, 2022
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4155be7
feat: Add hid_get_device_info
Julusian Jun 20, 2022
1818b59
chore: formatting
Julusian Jun 20, 2022
19e03fb
Apply suggestions from code review
Julusian Jun 23, 2022
5497de1
Update hidapi/hidapi.h
Julusian Jun 23, 2022
f88c36c
fix: segfaults
Julusian Jun 23, 2022
575b133
fix: windows hopefully
Julusian Jun 23, 2022
372c89b
fix: code review suggestions
Julusian Jul 17, 2022
c42b4b8
fix: lazy load hid_get_device_info result on some platforms
Julusian Jul 26, 2022
3d992cd
Update libusb/hid.c
Youw Aug 1, 2022
8d2954c
Update libusb/hid.c
Youw Aug 1, 2022
29f3826
Update libusb/hid.c
Youw Aug 1, 2022
5c75cd0
Update hidapi/hidapi.h
Youw Aug 1, 2022
938b912
Apply suggestions from code review
Julusian Aug 1, 2022
1832674
code review comments
Julusian Aug 1, 2022
fdddfc6
refactor libusb fill_device_info_for_device into create_device_info_f…
Julusian Aug 1, 2022
cd7349e
review comments
Julusian Aug 1, 2022
e6241f9
Explicit documentation NOTE
Youw Aug 6, 2022
79a77a7
libusb: lazy initialisation for get_device_info
Youw Aug 6, 2022
acd4788
fix invasive detach build
Youw Aug 6, 2022
e48a449
fix usage_page/usage fill
Youw Aug 7, 2022
4471fce
compilation fix
Youw Aug 7, 2022
e22cc65
typo
Youw Aug 7, 2022
d5bfa6e
use MAX_REPORT_DESCRIPTOR_SIZE constant
Youw Aug 7, 2022
5bb05a9
correct woding
Youw Aug 7, 2022
c7a8a71
check for handle
Youw Aug 7, 2022
8d11ec5
code style
Youw Aug 7, 2022
0296250
hidtest: print all of hid_get_device_info
Youw Aug 7, 2022
4779d63
refactor hidraw create_device_info_for_hid_device
Youw Aug 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: formatting
  • Loading branch information
Julusian committed Jun 23, 2022
commit 1818b598c8d720d1cabd44e51a4f2ba9214b999c
114 changes: 57 additions & 57 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,65 +575,65 @@ static void fill_device_info_for_device(libusb_device_handle *handle, struct hid
cur_dev->product_string =
get_usb_string(handle, desc->iProduct);

#ifdef INVASIVE_GET_USAGE
{
/*
This section is removed because it is too
invasive on the system. Getting a Usage Page
and Usage requires parsing the HID Report
descriptor. Getting a HID Report descriptor
involves claiming the interface. Claiming the
interface involves detaching the kernel driver.
Detaching the kernel driver is hard on the system
because it will unclaim interfaces (if another
app has them claimed) and the re-attachment of
the driver will sometimes change /dev entry names.
It is for these reasons that this section is
#if 0. For composite devices, use the interface
field in the hid_device_info struct to distinguish
between interfaces. */
unsigned char data[256];
#ifdef DETACH_KERNEL_DRIVER
int detached = 0;
/* Usage Page and Usage */
res = libusb_kernel_driver_active(handle, interface_num);
if (res == 1) {
res = libusb_detach_kernel_driver(handle, interface_num);
if (res < 0)
LOG("Couldn't detach kernel driver, even though a kernel driver was attached.\n");
else
detached = 1;
}
#ifdef INVASIVE_GET_USAGE
{
/*
This section is removed because it is too
invasive on the system. Getting a Usage Page
and Usage requires parsing the HID Report
descriptor. Getting a HID Report descriptor
involves claiming the interface. Claiming the
interface involves detaching the kernel driver.
Detaching the kernel driver is hard on the system
because it will unclaim interfaces (if another
app has them claimed) and the re-attachment of
the driver will sometimes change /dev entry names.
It is for these reasons that this section is
#if 0. For composite devices, use the interface
field in the hid_device_info struct to distinguish
between interfaces. */
unsigned char data[256];
#ifdef DETACH_KERNEL_DRIVER
int detached = 0;
/* Usage Page and Usage */
res = libusb_kernel_driver_active(handle, interface_num);
if (res == 1) {
res = libusb_detach_kernel_driver(handle, interface_num);
if (res < 0)
LOG("Couldn't detach kernel driver, even though a kernel driver was attached.\n");
else
detached = 1;
}
#endif
res = libusb_claim_interface(handle, interface_num);
if (res >= 0) {
/* Get the HID Report Descriptor. */
res = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_RECIPIENT_INTERFACE, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8)|interface_num, 0, data, sizeof(data), 5000);
if (res >= 0) {
unsigned short page=0, usage=0;
/* Parse the usage and usage page
out of the report descriptor. */
get_usage(data, res, &page, &usage);
cur_dev->usage_page = page;
cur_dev->usage = usage;
}
else
LOG("libusb_control_transfer() for getting the HID report failed with %d\n", res);

/* Release the interface */
res = libusb_release_interface(handle, interface_num);
if (res < 0)
LOG("Can't release the interface.\n");
}
else
LOG("Can't claim interface %d\n", res);
res = libusb_claim_interface(handle, interface_num);
if (res >= 0) {
/* Get the HID Report Descriptor. */
res = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_RECIPIENT_INTERFACE, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8)|interface_num, 0, data, sizeof(data), 5000);
if (res >= 0) {
unsigned short page=0, usage=0;
/* Parse the usage and usage page
out of the report descriptor. */
Youw marked this conversation as resolved.
Show resolved Hide resolved
get_usage(data, res, &page, &usage);
cur_dev->usage_page = page;
cur_dev->usage = usage;
}
else
LOG("libusb_control_transfer() for getting the HID report failed with %d\n", res);

/* Release the interface */
res = libusb_release_interface(handle, interface_num);
if (res < 0)
LOG("Can't release the interface.\n");
}
else
LOG("Can't claim interface %d\n", res);
#ifdef DETACH_KERNEL_DRIVER
/* Re-attach kernel driver if necessary. */
if (detached) {
res = libusb_attach_kernel_driver(handle, interface_num);
if (res < 0)
LOG("Couldn't re-attach kernel driver.\n");
}
/* Re-attach kernel driver if necessary. */
if (detached) {
res = libusb_attach_kernel_driver(handle, interface_num);
if (res < 0)
LOG("Couldn't re-attach kernel driver.\n");
}
#endif
}
#endif /* INVASIVE_GET_USAGE */
Expand Down