393 Commits

Author SHA1 Message Date
Sebastian Zagrodzki
e840be9d06 Do not assume interface numbers follow the slice indices. (#134)
Do not assume interface numbers follow the slice indices.

This is a continuation of
9ad54830f4
which tried to solve the problem of non-contiguous interface indices;
this commit modifies another code path that had the same assumption.
2024-09-13 20:43:01 +02:00
Kuba Raczkowski
606016adee Android support via fileDescriptor (#130)
Adds a new way to initialize the context, `ContextOptions`, and a new way to open devices, `OpenDeviceWithFileDescriptor`.

Combined they can be used to support Android devices, where device enumeration is not supported (can be now disabled through `ContextOptions`) and where USB devices can be opened in the Android SDK and passed over to gousb through a file descriptor.

Co-authored-by: Juan <994594+juaoose@users.noreply.github.com>
Co-authored-by: Kuba Raczkowski <kuba.raczkowski@spectricity.com>
2024-09-08 21:40:30 +02:00
Sebastian Zagrodzki
8c7a7eb841 Upgrade build/test environment
Upgrading Linux build env to Ubuntu 24.04, Go 1.23
2024-09-08 18:32:06 +02:00
Jamil Djadala
2f9ed92cb8 suppress 'interrupted [code -10]' log message. resolve #87 (#121) v1.1.3 2024-02-24 22:08:57 +01:00
Sebastian Zagrodzki
5514912016 Go 1.22 (#122)
Update Go & Ubuntu versions in GitHub CI workflows. Pass files through a new version of gofmt. Allow running CI workflow manually.
2024-02-24 21:48:06 +01:00
Sebastian Zagrodzki
844d4b8a71 Add a retract version for v2.1.0+incompatible. (#109)
This will avoid listing this version in "go list -m -versions", which
is used by GitHub's dependabot. The "go list" is expected to list
versions oldest to newest, but it doesn't exclude the "+incompatible"
versions and treats v2.1.0 as the newest. We don't want that, 1.1 is the
latest at the moment.
v1.1.2
2022-03-29 23:13:07 +02:00
Will McEnaney
6ad122da6a Add Path to DeviceDesc (#101)
Populates information about device port path in the device descriptor.
2021-11-10 16:04:13 +01:00
Sebastian Zagrodzki
1f6abc1f14 Run gofmt on all files, complain about the diff. (#106) 2021-11-03 22:39:59 +01:00
Sebastian Zagrodzki
bdb184b25c Make golint fail on errors. (#105)
* make lint fail on errors
* fix lint errors
2021-11-02 12:52:11 +01:00
Sebastian Zagrodzki
d3bdbe53c8 Migrate from Travis/Appveyor combo to GitHub actions (#104)
* Add a github actions workflow config (linux + windows build)
* Remove Travis config, migrated to Github Actions
* Remove AppVeyor configs, migrated to Github Actions
2021-11-02 09:18:09 +01:00
danielpaulus
0ce3a07f8e Dereference device with a defer call to prevent memory leaks (#98)
We should always dereference devices. c.libusb.open is keeping its own internal reference so there is no risk of breaking anything.
2021-11-01 21:40:49 +01:00
Sebastian Zagrodzki
0eba1b1264 Checks for closed/uninitialized context and devices. (#93) 2021-01-15 17:25:29 +01:00
Sebastian Zagrodzki
c9efe54672 Switch to Bionic image for Travis. Use Go 1.10 and upwards.
Go 1.9 is well over 3yo.
2021-01-07 19:57:37 +01:00
Sebastian Zagrodzki
dd9486a141 Update AppVeyor image version (#90)
configure VS2019 image explicitly
2021-01-07 19:42:57 +01:00
Sebastian Zagrodzki
cb06b9fb0d Add a go.mod for v1.1.0. This will make the Go proxy (#86)
prefer v1.* (with a valid go.mod file) over the v2.1.0+incompatible version
(which doesn't have a go.mod file).
v1.1.1
2020-11-09 10:57:35 +01:00
Sebastian Zagrodzki
76f12f69ac Refresh pacman in the appveyor build (#84)
...for updated Go package versions. Go 1.12 is gone from the MSYS2 repos.
2020-11-09 10:07:43 +01:00
Sebastian Zagrodzki
0995919da4 Since go 1.15 new() on CGo structs is no longer supported: (#85)
./fakelibusb_test.go:101:87: libusbContext can't be allocated in Go; it is incomplete (or unallocatable)
./fakelibusb_test.go:131:10: libusbDevHandle can't be allocated in Go; it is incomplete (or unallocatable)

Use CGo malloc to obtain unique pointers.
2020-11-09 09:50:43 +01:00
Sebastian Zagrodzki
e4c3f66a15 Document the recommendations/restrictions around the buffer size (#81)
* Document the recommendations/restrictions around the buffer size
v2.1.0 v1.1.0
2020-04-29 21:51:05 +02:00
Sebastian Zagrodzki
9ad54830f4 Support malformed interface descriptors (#79)
* Add an invalid interface descriptor to one of the test devices.
* Add a test for getting that interface description.
* Handle the malformed interface/alternate setting descriptors, where
interface/alt numbers don't follow the spec (not 0-based, not contiguous
etc.)

Addresses issue #65.
2020-04-28 11:32:10 +02:00
Sebastian Zagrodzki
18f4c1d8a7 Don't skip empty transfers. In isochronous transfers, make sure (#72)
Don't skip empty transfers.
Update the fake libusb to honor the endpoint max packet sizes.
Update tests that were taking advantage of the fact that libusb
allowed unlimited amount of data in any transfer packet.
2019-08-12 21:38:32 +02:00
Steve Manuel
2dc560e6be readme: fix markdown link (#67) 2019-05-25 11:27:38 +02:00
Mauricio Galindo
64d8208677 Fix typo (#64) 2019-04-11 01:18:22 +06:00
Joël Stemmer
d0c05ab7f7 Fix linux-usb.org URL's (#62)
These were accidentally modified when the package was renamed to gousb
in commit 5200a36.
2019-01-25 16:00:36 +01:00
Biling Uliar
04360a5457 Update usb.go (#60)
Possible typo fix
2018-12-22 22:43:27 +01:00
Jo Haugum
a50ac957b1 Updated dead link (#59) 2018-11-06 18:00:28 +01:00
Sebastian Zagrodzki
0f73bf7aea Replace libusb class ID definitions with a manually curated list based directly off usb.org list. (#58) 2018-11-05 17:35:27 +01:00
Sebastian Zagrodzki
da849d96b5 Add context-aware read/write (#57)
Adds ReadContext/WriteContext methods to endpoints and to streams. Update rawread example tool to use ReadContext for implementation of "timeout" flag.
2018-11-05 15:33:31 +01:00
Cyrille Hemidy
593cfb67e9 fix mispell (#54)
* fix mispell

* update golint path in travis

* Golint requires Go 1.9 or later

* install golint only if go >=1.9

* exclude go 1.7 and go 1.8 for golint

* add build on go 1.10.x
2018-10-25 07:55:16 +10:00
Sebastian Zagrodzki
15d2fa288b Add more device classes, based on libusb.h enumeration. (#51) 2018-10-05 13:53:10 +02:00
Sebastian Zagrodzki
92967a7d10 Use gousb_set_debug instead of libusb_set_debug in one more place. (#44)
* One more place that should call gousb_set_debug instead of
libusb_set_debug.

* Better comment to explain what sort of benchmarking this is needed for.
2018-06-16 20:22:24 +02:00
Sebastian Zagrodzki
c6e780971f Support libusb_set_option in additon to libusb_set_debug. (#39)
* Support libusb_set_option in additon to libusb_set_debug.
The latter is deprecated in libusb 1.0.22 and later.

* Move the "debug level constants" todo to the right place. Add a comment
about libusb 1.0.22 exported API version.
2018-05-23 16:07:03 +02:00
Sebastian Zagrodzki
21b0ed46ae Set alternate setting for the interface only if required. (#38)
Spec says devices must support "set interface" if they have more than
one alternate setting.
2018-05-23 10:08:10 +02:00
Sebastian Zagrodzki
815369492f Add AppVeyor badge. (#41) 2018-05-23 10:06:27 +02:00
Sebastian Zagrodzki
5115a55a03 Redefine constants around control request types. (#34) 2018-04-05 13:23:20 +02:00
Sebastian Zagrodzki
d0366361a2 Add missing arguments to Interface() error on failed descriptor
retrieval.
2017-11-12 03:32:09 +01:00
Sebastian Zagrodzki
b893afb018 Add missing endpoint argument to Fatalf. 2017-11-12 03:29:28 +01:00
Davor Kapsa
e9aec43516 travis: update go versions (#24) 2017-11-12 03:22:54 +01:00
Sebastian Zagrodzki
85520e6880 Add missing argument to Fatalf. 2017-11-12 03:21:28 +01:00
zagrodzki
5c10dc8f4e Write stream implementation (#19)
Defines a WriteStream structure for buffering writes, similar to the existing ReadStream. WriteStreams can be created on OutEndpoints by using ep.NewStream().
2017-09-08 13:41:25 +02:00
CriJonsi
01840c1d23 Add the number of the USB port in the DeviceDesc structure (#18) 2017-09-07 17:27:58 +02:00
zagrodzki
c113a5e0de Parallelize tests (#17)
* Store a reference to libusb implementation in the context, transfers
and some more places. Remove the global libusb variable.

* Parallelize tests.

* Fix the link in README.
2017-09-04 16:55:47 +02:00
zagrodzki
f9aba6fab5 Config and interface description (#16)
* Add APIs for config and interface descriptors. Split out the common
parts of selecting a config descriptor from device desc and
selecting a setting descriptor from a config desc.

* Parallelize the few tests that actually can be parallelized safely.
Add comments where they can't. Note to self: it would be beneficial
to restructure the fakelibusb to index all properties of the lib
with the used context. That way a libusb implementation wouldn't need
to be referred via a shared variable.
2017-09-04 14:17:34 +02:00
zagrodzki
cf19eb7001 Fix a race condition in reuse of the same malloc result (#15)
In free(), remove Go references to the C memory before the C memory
itself is released. That ensures that a concurrent alloc()
will not try to insert the same pointer into the map that was not
yet removed.
2017-09-04 12:52:42 +02:00
Deomid Ryabkov
757722bf8e Add Device.Manufacturer(), .Product() and .SerialNumber() (#14) 2017-09-04 00:42:55 +02:00
zagrodzki
1aaa100bdb Allocate libusb buffers in C (#11)
* add alloc/free_transfer_and_buffer. Manages the buffer memory on the C
side.

* switch libusb.go to use the new alloc/free_transfer_and_buffer. Add
a new buffer() call to get access to the allocated buffer as a Go slice.

* Fake USB transfer uses the new alloc/free/buffer interface.

* Switch to the new libusb.alloc signature, where libusb owns the buffer.

* newUSBTransfer now allocates a separate buffer, do a copy on
endpoint.transfer.

* newUSBTransfer will now allocate it's own buffer.

* Enable autodetach in rawread.
2017-08-29 12:11:04 +02:00
Nico MT
bc91dd3f2c Extend the autodetach behavior
Detach interfaces before trying to change the config, as libusb doesn't handle that automatically.
2017-07-21 21:15:49 +02:00
Veniamin Albaev
9829f2fcba Fixed libusb: warning [libusb_exit] some libusb_devices were leaked (#7) 2017-07-20 14:09:58 +02:00
Filzmaier Josef
9fc0278283 Don't reset the configuration if desired config is already active (#6)
Fixes issue #5
2017-06-29 14:31:12 +02:00
Tamási Benjamin
aa64bae804 Appveyor support (#2) 2017-06-20 16:03:55 +02:00
zagrodzki
00e8f24bda Merge pull request #1 from google/same-endpoint-in-out
Allow the same endpoint number to be reused for IN and OUT endpoints separately
2017-06-14 11:15:38 +02:00