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

Replace libusb 0.1 usage with libusb 1.0 #396

Merged
merged 20 commits into from
Nov 14, 2019
Merged

Conversation

tsteven4
Copy link
Collaborator

Replace our modified libusb 0.1.12 with libusb 1.0.22 on macos. On macos we statically link to our inclcuded libusb.
Use libusb 1.0 instead of libusb 0.1 on linux. On linux we dynamically link to a distribution provided libusb, or optionally build without libusb support.

This fixes #381
This resolves #25 as requested (albeit 3.5 years later)

TODO:
flow with configure
flow with cmake
test on macos
test on linux
are include paths consistent for libusb.h?
better way to find endpoint addresses than search all interfaces,
altsettings and endpoints?
This has mac/libusb/config.h that was generated on 10.14.6 by configure.
It is not clear a fixed config.h will be viable.
configure builds on macos don't work yet, but qmake or cmake does.
configure is linking via a static lib we create.
this removes the conflict between the gpsbabel configure created
config.h and the libusb config.h.

use the libusb-1.0 supplied hardcoded config.h from for Xcode.

qmake/cmake are still linking the individual libusb objects.
this was the traditional behavior.

add -lobjc on mac for libusb.  while this doesn't seem
necessary it is what libusb does.
Now that we have the dependencies correct we generate
and find the included library with the standard name.
libusb_exit should be called IFF libusb_init succeded.

atexit should only be called once to register gusb_atexit_teardown,
its effects are cumulative and irreversible.
delete obsolete comment in README.

don't log each file the macos linker loads with -t.
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@GPSBabel GPSBabel deleted a comment Aug 28, 2019
@tsteven4
Copy link
Collaborator Author

I believe this is a fair translation, but it may not be correct:
https://github.com/gpsbabel/gpsbabel/blob/3b656719d096660d16c099cca24b954711f82dd8/jeeps/gpslibusb.cc#L360
bMaxPacketSize is "Maximum Packet Size for Zero Endpoint. Valid Sizes are 8, 16, 32, 64"
What we may want is wMaxPacketSize for the bulk out endpoint "Maximum Packet Size this endpoint is capable of sending or receiving".

The value is used in gusb_cmd_send. It seems to pertain to the garmin spec:

The host always transmits to the device over the Bulk OUT pipe.

Output buffer receives 4-byte USB packet size. Client is responsible for sending a zero length transfer if the amount of
data sent to the device is an integral multiple of the USB packet size.

@GPSBabel GPSBabel deleted a comment Oct 2, 2019
@tsteven4
Copy link
Collaborator Author

tsteven4 commented Oct 6, 2019

Regarding the concern about bMaxPacketSize0 vs. wMaxPacketSize, on the etrex vista cx it is irrelevant because they are all equal on this device. From a modified testlibusb.c (verbose=1, and printf(..., desc.bMaxPacketSize0)) we can see that bMaxPacketSize0 and wMaxPacketSize for all endpoints have a value of 64. Of course, we don't know if this is true in general.

Dev (bus 2, device 4): 091E - 0003
BMaxPacketSize0 64
Configuration:
wTotalLength: 39
bNumInterfaces: 1
bConfigurationValue: 1
iConfiguration: 0
bmAttributes: 80h
MaxPower: 150
Interface:
bInterfaceNumber: 0
bAlternateSetting: 0
bNumEndpoints: 3
bInterfaceClass: 255
bInterfaceSubClass: 255
bInterfaceProtocol: 255
iInterface: 0
Endpoint:
bEndpointAddress: 81h
bmAttributes: 02h
wMaxPacketSize: 64
bInterval: 0
bRefresh: 0
bSynchAddress: 0
Endpoint:
bEndpointAddress: 82h
bmAttributes: 03h
wMaxPacketSize: 64
bInterval: 1
bRefresh: 0
bSynchAddress: 0
Endpoint:
bEndpointAddress: 03h
bmAttributes: 02h
wMaxPacketSize: 64
bInterval: 0
bRefresh: 0
bSynchAddress: 0

@robertlipe
Copy link
Collaborator

robertlipe commented Oct 7, 2019 via email

@tsteven4
Copy link
Collaborator Author

tsteven4 commented Oct 7, 2019

Do the edge 305 and 60CS work with 1.6.0 (libusb 0.1), or do they fail like 80015bc?

@tsteven4
Copy link
Collaborator Author

tsteven4 commented Oct 7, 2019

60CS still fails in the same way. Edge 305 still fails.

To debug set environmental variable LIBUSB_DEBUG to a value >= 2. Look for a message "transfer error:"
If that doesn't help use LIBUSB_DEBUG=4 and look for a message "interpreting short transfer as error".

  • Log message levels.
    • LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default)
    • LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr
    • LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
    • LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stderr
    • LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stderr

@GPSBabel GPSBabel deleted a comment Oct 7, 2019
@GPSBabel GPSBabel deleted a comment Oct 8, 2019
@tsteven4
Copy link
Collaborator Author

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 1
           

See the complete overview on Codacy

@GPSBabel GPSBabel deleted a comment Nov 14, 2019
@tsteven4 tsteven4 merged commit 8ab5555 into master Nov 14, 2019
@tsteven4 tsteven4 deleted the libusb1_conversion branch November 14, 2019 17:31
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

Successfully merging this pull request may close these issues.

Garmin eTrex Vista HCX not detected on USB on Macos libusb-1.0 support
2 participants