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

Any plan for supporting libusb_init_context()? #207

Open
zephyr-fun opened this issue May 31, 2024 · 6 comments
Open

Any plan for supporting libusb_init_context()? #207

zephyr-fun opened this issue May 31, 2024 · 6 comments
Assignees

Comments

@zephyr-fun
Copy link

Thanks for your brilliant work! It really paves the way between rust and USB devices.

TL:DR: is there any plan to support calling libusb_set_option() before libusb_init(), which is super useful in access-limited situations?

For now, the crate works fine in most situations, however, when it comes to circumstances where access to USB devices is limited, there seems to be no way to call libusb_set_option() with opt equals to LIBUSB_OPTION_NO_DEVICE_DISCOVERY before libusb_init(), which helps the caller to skip scanning devices when calling libsub_init().
Also, the libusb_init() API has already been marked as deprecated , it would be a better choice to turn to libusb_init_context().

Looking forward to your replies!

You may find the following links helpful:
https://libusb.sourceforge.io/api-1.0/group__libusb__lib.html#ga7deaef521cfb1a5b3f8d6c01be11a795
https://libusb.sourceforge.io/api-1.0/group__libusb__lib.html#ga07d4ec54cf575d672ba94c72b3c0de7c

@a1ien
Copy link
Owner

a1ien commented Jul 1, 2024

Sorry for the delay in my response. Yes, I can try to add this feature. However, it might be a bit tricky. We also need to verify that we are linking to the new libusb version (>= 1.0.27); otherwise, we will encounter a linking error.

@a1ien a1ien self-assigned this Jul 1, 2024
@dgramop
Copy link
Contributor

dgramop commented Jul 24, 2024

See: #209 :)

@a1ien
Copy link
Owner

a1ien commented Jul 24, 2024

Actually for android you can use old approache

libusb1_sys::libusb_set_option(
        std::ptr::null_mut(),
        LIBUSB_OPTION_NO_DEVICE_DISCOVERY
    )

or rusb::disable_device_discovery

But I will try to upgrade rusb to allow the new approach.

@dgramop
Copy link
Contributor

dgramop commented Jul 25, 2024

the old libusb_set_option way would trigger segmentation faults on Android, but libusb_init_context with the same option would not. I think it has to do with how set_option is implemented and some faulty assumption about memory allocation or struct padding that doesn't hold up in my environment

@a1ien
Copy link
Owner

a1ien commented Jul 25, 2024

The old libusb_set_option should still work. You must call it before any operation context initialization.

And you need to

You can take a look here #19 (comment)
Also in edit section

Edit: I just had to do let _ = rusb::disable_device_discovery(); and everything works great!

@dgramop
Copy link
Contributor

dgramop commented Jul 25, 2024

it seems i was doing this incorrectly. i had mis-re-typed the original sample code in the android directory when writing the C++ sanity-check proof-of-concept code on android (which also segfaulted till i switched to the new API). that behavior is a little unintuitive, i'm glad they deprecated that API haha. closer reading may have saved me.

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

No branches or pull requests

3 participants