-
Notifications
You must be signed in to change notification settings - Fork 616
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
nsyshid: Fix SetProtocol and SetReport for Libusb Backend #1027
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -694,22 +694,58 @@ namespace nsyshid::backend::libusb | |
return false; | ||
} | ||
|
||
// ToDo: implement this | ||
#if 0 | ||
// is this correct? Discarding "ifIndex" seems like a bad idea | ||
int ret = libusb_set_configuration(handleLock->getHandle(), protocol); | ||
if (ret == 0) { | ||
cemuLog_logDebug(LogType::Force, | ||
"nsyshid::DeviceLibusb::setProtocol(): success"); | ||
return true; | ||
struct libusb_config_descriptor* conf = nullptr; | ||
libusb_device* dev = libusb_get_device(handleLock->GetHandle()); | ||
int getConfig = libusb_get_active_config_descriptor(dev, &conf); | ||
if (getConfig == LIBUSB_SUCCESS) | ||
{ | ||
for (uint8 i = 0; i < conf->bNumInterfaces; ++i) | ||
{ | ||
int releaseSuccess = libusb_release_interface(handleLock->GetHandle(), i); | ||
if (releaseSuccess < LIBUSB_SUCCESS) | ||
{ | ||
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetProtocol(): Failed to release interface %i", i); | ||
return false; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetProtocol(): Failed to Get Active Config"); | ||
} | ||
|
||
const int setConfig = libusb_set_configuration(handleLock->GetHandle(), protocol); | ||
if (setConfig == LIBUSB_SUCCESS) | ||
{ | ||
getConfig = libusb_get_active_config_descriptor(dev, &conf); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (in its current form) causes us to lose all references to the struct that struct libusb_config_descriptor *conf = nullptr;
libusb_get_active_config_descriptor(dev, &conf);
libusb_get_active_config_descriptor(dev, &conf);
libusb_free_config_descriptor(conf); |
||
if (getConfig == LIBUSB_SUCCESS) | ||
{ | ||
for (uint8 i = 0; i < conf->bNumInterfaces; ++i) | ||
{ | ||
int detachSuccess = libusb_detach_kernel_driver(handleLock->GetHandle(), i); | ||
if (detachSuccess < LIBUSB_SUCCESS && detachSuccess != LIBUSB_ERROR_NOT_FOUND && | ||
detachSuccess != LIBUSB_ERROR_NOT_SUPPORTED) | ||
{ | ||
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetProtocol(): failed to detach kernel driver"); | ||
return false; | ||
} | ||
int claimInterface = libusb_claim_interface(handleLock->GetHandle(), i); | ||
if (claimInterface < LIBUSB_SUCCESS) | ||
{ | ||
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetProtocol(): failed to claim interface"); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
libusb_free_config_descriptor(conf); | ||
} | ||
else | ||
{ | ||
cemuLog_logDebug(LogType::Force, "nsyshid::DeviceLibusb::SetProtocol(): Failed to set config %i", protocol); | ||
return false; | ||
} | ||
cemuLog_logDebug(LogType::Force, | ||
"nsyshid::DeviceLibusb::setProtocol(): failed with error code: {}", | ||
ret); | ||
return false; | ||
#endif | ||
|
||
// pretend that everything is fine | ||
return true; | ||
} | ||
|
||
|
@@ -723,18 +759,20 @@ namespace nsyshid::backend::libusb | |
return false; | ||
} | ||
|
||
// ToDo: implement this | ||
#if 0 | ||
// not sure if libusb_control_transfer() is the right candidate for this | ||
int ret = libusb_control_transfer(handleLock->getHandle(), | ||
bmRequestType, | ||
bRequest, | ||
wValue, | ||
wIndex, | ||
reportData, | ||
length, | ||
timeout); | ||
#endif | ||
int ret = libusb_control_transfer(handleLock->GetHandle(), | ||
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT, | ||
LIBUSB_REQUEST_SET_CONFIGURATION, | ||
512 /* This may be skylander specific, but other games don't use this method anyway */, | ||
0, | ||
originalData, | ||
originalLength, | ||
0); | ||
|
||
if (ret != originalLength) | ||
{ | ||
cemuLog_log(LogType::Force, "nsyshid::DeviceLibusb::SetReport(): Control Transfer Failed: {}", libusb_error_name(ret)); | ||
return false; | ||
} | ||
|
||
// pretend that everything is fine | ||
return true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning here is problematic: We still need to tell libusb to free the struct that
conf
points to!Since you are only using
conf->bNumInterfaces
from that struct, how about callinglibusb_get_active_config_descriptor()
, making a copy ofconf->bNumInterfaces
and then immediately callinglibusb_free_config_descriptor()
?