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

Improve libusb error logging #10729

Merged
merged 6 commits into from Jun 17, 2022

Conversation

Pokechu22
Copy link
Contributor

This PR adds logging when libusb functions fail, using LibusbUtils::ErrorWrap from #10604.

I haven't tested this much beyond confirming that it builds. But hopefully adding additional error logging makes debugging easier.

@@ -49,22 +49,22 @@ class Context::Impl

libusb_context* GetContext() { return m_context; }

bool GetDeviceList(GetDeviceListCallback callback)
int GetDeviceList(GetDeviceListCallback callback)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something or can this function be const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I make the function const I get compile errors when trying to lock on m_device_list_mutex.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah true. Thoughts on making that mutable? I usually make my mutexes mutable in favor of const functions but I see why people would shy away from that...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could go either way, but it shouldn't be too hard to change. I don't think const has any benefits here, but there isn't really a downside to it either.

INFO_LOG_FMT(IOS_WIIMOTE, "Sent a reset command to adapter");
const int ret =
libusb_control_transfer(m_handle, REQUEST_TYPE, 0, 0, 0, packet, sizeof(packet), TIMEOUT);
if (ret < 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (ret < LIBUSB_SUCCESS) ?

Copy link
Contributor

@iwubcode iwubcode Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with the others in this commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that here, ret indicates the number of bytes transferred if it's nonnegative, but it's probably best to change it to LIBUSB_SUCCESS anyways (the < versus != still applies for that difference).

I can also change a few < 0 comparisons to < LIBUSB_SUCCESS in GCAdapter.cpp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I probably could go either way on that too. This works though.

Copy link
Contributor

@iwubcode iwubcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untested. Code LGTM

@AdmiralCurtiss AdmiralCurtiss merged commit 23ed611 into dolphin-emu:master Jun 17, 2022
10 checks passed
@AdmiralCurtiss
Copy link
Contributor

Apparently this breaks some combinations of Wiimotes on Linux...? https://forums.dolphin-emu.org/Thread-unable-to-pair-remotes-hci-command-timeout

libusb_get_string_descriptor_ascii(m_handle, device_descriptor.iManufacturer, manufacturer,
sizeof(manufacturer));
libusb_get_string_descriptor_ascii(m_handle, device_descriptor.iProduct, product,
sizeof(product));
libusb_get_string_descriptor_ascii(m_handle, device_descriptor.iSerialNumber, serial_number,
sizeof(serial_number));
const int manufacturer_ret = libusb_get_string_descriptor_ascii(
m_handle, device_descriptor.iManufacturer, manufacturer, sizeof(manufacturer));
const int product_ret = libusb_get_string_descriptor_ascii(
m_handle, device_descriptor.iProduct, product, sizeof(product));
const int serial_ret = libusb_get_string_descriptor_ascii(
m_handle, device_descriptor.iSerialNumber, serial_number, sizeof(serial_number));
if (manufacturer_ret < LIBUSB_SUCCESS || product_ret < LIBUSB_SUCCESS ||
serial_ret < LIBUSB_SUCCESS)
{
ERROR_LOG_FMT(IOS_WIIMOTE,
"Failed to get descriptor for device {:04x}:{:04x} (rev {:x}): {}/{}/{}",
device_descriptor.idVendor, device_descriptor.idProduct,
device_descriptor.bcdDevice, LibusbUtils::ErrorWrap(manufacturer_ret),
LibusbUtils::ErrorWrap(product_ret), LibusbUtils::ErrorWrap(serial_ret));
return true;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new error seems to be this:

 56:49:662 Core/IOS/USB/Bluetooth/BTReal.cpp:116 E[IOS_WIIMOTE]: Failed to get descriptor for device 057e:0305 (rev 100): Other error (13: **UNKNOWN**)/Other error (8: **UNKNOWN**)/Invalid parameter (-2: LIBUSB_ERROR_INVALID_PARAM)

i.e. libusb_get_string_descriptor_ascii is returning an error code, and now we're treating that as a problem while before we were fine with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants