Being able to allocate bulk-streams is not really useful if the user cannot specify the stream ids when submitting transfers.
Note that the actual stream id gets added to our private itransfer struct, and a setter + getter is added to get to it. Unfortunately this is the only way to add support for stream ids without breaking ABI. So this is another item to fix when we do break ABI in libusb-2.0. Most users will likely use the new libusb_fill_bulk_stream_transfer() though, and will never know the difference. Signed-off-by: Hans de Goede <hdego...@redhat.com> --- libusb/io.c | 37 +++++++++++++++++++++++++++++++++++++ libusb/libusb.h | 33 ++++++++++++++++++++++++++++++++- libusb/libusbi.h | 1 + libusb/os/linux_usbfs.c | 1 + libusb/os/linux_usbfs.h | 5 ++++- libusb/version_nano.h | 2 +- 6 files changed, 76 insertions(+), 3 deletions(-) diff --git a/libusb/io.c b/libusb/io.c index 4f22963..c909380 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1510,6 +1510,43 @@ int API_EXPORTED libusb_cancel_transfer(struct libusb_transfer *transfer) return r; } +/** \ingroup asyncio + * Set a transfers bulk stream id. Note users are advised to use + * libusb_fill_bulk_stream_transfer() instead of calling this function + * directly. + * + * Since version 1.0.18, \ref LIBUSBX_API_VERSION >= 0x01000103 + * + * \param transfer the transfer to set the stream id for + * \param stream_id the stream id to set + * \see libusb_alloc_streams() + */ +void API_EXPORTED libusb_transfer_set_stream_id( + struct libusb_transfer *transfer, int stream_id) +{ + struct usbi_transfer *itransfer = + LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer); + + itransfer->stream_id = stream_id; +} + +/** \ingroup asyncio + * Get a transfers bulk stream id. + * + * Since version 1.0.18, \ref LIBUSBX_API_VERSION >= 0x01000103 + * + * \param transfer the transfer to get the stream id for + * \returns the stream id for the transfer + */ +int API_EXPORTED libusb_transfer_get_stream_id( + struct libusb_transfer *transfer) +{ + struct usbi_transfer *itransfer = + LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer); + + return itransfer->stream_id; +} + /* Handle completion of a transfer (completion might be an error condition). * This will invoke the user-supplied callback function, which may end up * freeing the transfer. Therefore you cannot use the transfer structure diff --git a/libusb/libusb.h b/libusb/libusb.h index d3c8afd..b9bcb99 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -144,7 +144,7 @@ typedef unsigned __int32 uint32_t; * Internally, LIBUSBX_API_VERSION is defined as follows: * (libusbx major << 24) | (libusbx minor << 16) | (16 bit incremental) */ -#define LIBUSBX_API_VERSION 0x01000102 +#define LIBUSBX_API_VERSION 0x01000103 #ifdef __cplusplus extern "C" { @@ -1475,6 +1475,10 @@ struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets); int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer); int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer); void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer); +void LIBUSB_CALL libusb_transfer_set_stream_id( + struct libusb_transfer *transfer, int stream_id); +int LIBUSB_CALL libusb_transfer_get_stream_id( + struct libusb_transfer *transfer); /** \ingroup asyncio * Helper function to populate the required \ref libusb_transfer fields @@ -1552,6 +1556,33 @@ static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer, /** \ingroup asyncio * Helper function to populate the required \ref libusb_transfer fields + * for a bulk transfer using bulk streams. + * + * Since version 1.0.18, \ref LIBUSBX_API_VERSION >= 0x01000103 + * + * \param transfer the transfer to populate + * \param dev_handle handle of the device that will handle the transfer + * \param endpoint address of the endpoint where this transfer will be sent + * \param stream_id bulk stream id for this transfer + * \param buffer data buffer + * \param length length of data buffer + * \param callback callback function to be invoked on transfer completion + * \param user_data user data to pass to callback function + * \param timeout timeout for the transfer in milliseconds + */ +static inline void libusb_fill_bulk_stream_transfer( + struct libusb_transfer *transfer, libusb_device_handle *dev_handle, + unsigned char endpoint, int stream_id, + unsigned char *buffer, int length, libusb_transfer_cb_fn callback, + void *user_data, unsigned int timeout) +{ + libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, + length, callback, user_data, timeout); + libusb_transfer_set_stream_id(transfer, stream_id); +} + +/** \ingroup asyncio + * Helper function to populate the required \ref libusb_transfer fields * for an interrupt transfer. * * \param transfer the transfer to populate diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 762e644..2236e02 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -357,6 +357,7 @@ struct usbi_transfer { struct list_head list; struct timeval timeout; int transferred; + int stream_id; uint8_t flags; /* this lock is held during libusb_submit_transfer() and diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 8783a46..dc41dc7 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -1824,6 +1824,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer, urb->usercontext = itransfer; urb->type = urb_type; urb->endpoint = transfer->endpoint; + urb->stream_id = itransfer->stream_id; urb->buffer = transfer->buffer + (i * bulk_buffer_len); /* don't set the short not ok flag for the last URB */ if (use_bulk_continuation && !is_out && (i < num_urbs - 1)) diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h index 113d23f..72be3a7 100644 --- a/libusb/os/linux_usbfs.h +++ b/libusb/os/linux_usbfs.h @@ -94,7 +94,10 @@ struct usbfs_urb { int buffer_length; int actual_length; int start_frame; - int number_of_packets; + union { + int number_of_packets; /* Only used for isoc urbs */ + int stream_id; /* Only used with bulk streams */ + }; int error_count; unsigned int signr; void *usercontext; diff --git a/libusb/version_nano.h b/libusb/version_nano.h index da8a87c..85260ed 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 10835 +#define LIBUSB_NANO 10836 -- 1.8.3.1 ------------------------------------------------------------------------------ How ServiceNow helps IT people transform IT departments: 1. Consolidate legacy IT systems to a single system of record for IT 2. Standardize and globalize service processes across IT 3. Implement zero-touch automation to replace manual, redundant tasks http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk _______________________________________________ libusbx-devel mailing list libusbx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusbx-devel