-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
os/darwin: switch from using ResetDevice to USBDeviceReEnumerate
In newer versions of macOS the ResetDevice function does nothing. For these systems we have to use USBDeviceReEnumerate. This should also work for older versions os MacOS X. Fixes #455 Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
- Loading branch information
Showing
2 changed files
with
5 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
#define LIBUSB_NANO 11314 | ||
#define LIBUSB_NANO 11315 |
c14ab5f
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.
I was using libusb with BTStack, and I noticed that the use of "USBDeviceReEnumerate" seems to violate it's expectation of what "reset device" does. They typically open and then reset the device, which I assume works on other platforms (I'm going to try NetBSD and Linux, but haven't yet). But on Mac OS X, the "reset device" call (which now calls "USBDeviceReEnumerate" seems to always result in the IO kit device being invalidated (and according to Apple's docs, that's to be expected). The calls to load the descriptor ignore the return value, but for me, that value is always an error that indicates the device has been closed (again, consistent with Apple's docs).
I tried to modify the call a little bit to close and re-open the device, but that didn't work -- the close "worked" (internally, it cleaned up the libusb data structures, although it got an error back from the OS that the device was not open). But the second "open" failed, and it appeared to fail because the old device information was incorrect. I'm guessing that when it was virtually detached and re-attached (as re-enumerate claims to do), it ended up with some different parameters that libusb needs to process, and since I'm inside a call to "reset device", it hasn't had a chance to do that yet. I didn't try to track it down further yet.
c14ab5f
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.
Yeah. BTStack developer's must have not read the documentation for libusb_reset_device:
So, they MUST close and re-open the device. From what I can tell they should still be able to use the libusb_device. Let me read through the documentation. If the libusb_device must remain valid then I can update the backend to re-use the libusb_device after reset/re-enumeration.
c14ab5f
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.
Hmm, or maybe I am reading that wrong. Maybe the handle should also remain valid. That would require me to update reset to wait until the handle is valid again. Not a big deal but need to make sure the API is followed.
c14ab5f
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.
Hmm, definitely need to return
LIBUSB_ERROR_NOT_FOUND
at a minimum. Because it is essentially a re-plug now.c14ab5f
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.
Ok, it is already returning the correct value in the backend. Is BTStack getting
LIBUSB_ERROR_NOT_FOUND
?