summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2008-11-19 08:56:35 +0000
committeralfred <alfred@FreeBSD.org>2008-11-19 08:56:35 +0000
commit881f5acc93790d49318ffde65d52c6f45ca9c1f8 (patch)
tree563c2e235db65a3694986a6531a444241d882b23 /lib
parentf750559c3fe5d18392fa3f5969411eef4c84075c (diff)
downloadFreeBSD-src-881f5acc93790d49318ffde65d52c6f45ca9c1f8.zip
FreeBSD-src-881f5acc93790d49318ffde65d52c6f45ca9c1f8.tar.gz
src/sys/dev/usb2/controller/uss820dci_pccard.c
src/sys/dev/usb2/core/usbdevs src/sys/dev/usb2/include/urio2_ioctl.h src/sys/dev/usb2/storage/ustorage2_fs.h These files are not used any more. src/usr.sbin/Makefile src/etc/mtree/BSD.include.dist src/include/Makefile src/lib/Makefile src/share/man/man7/hier.7 src/share/mk/bsd.libnames.mk src/etc/mtree/BSD.include.dist Make "usbconfig" and "libusb20" a part of the default build. src/sys/dev/usb/rio500_usb.h src/sys/dev/usb2/storage/urio2.c Use common include file. src/sys/dev/usb2/bluetooth/ng_ubt2.c Make USB bluetooth depend on "ng_hci" module. src/sys/dev/usb2/controller/ehci2.c src/sys/dev/usb2/controller/ehci2.h Patches for Marvell EHCI. src/sys/dev/usb2/core/usb2_busdma.c Bugfix for 64-bit platforms. Need to unload the previously loaded DMA map and some cleanup regarding some corner cases. src/sys/dev/usb2/core/usb2_core.h src/sys/dev/usb2/core/usb2_dev.c src/sys/dev/usb2/core/usb2_dev.h Bugfix for libusb filesystem interface. New feature: Add support for filtering device data at the expense of the userland process. Add some more comments. Some minor code styling. Remove unused function, usb2_fifo_get_data_next(). Fix an issue about "fifo_index" being used instead of "ep_index". src/sys/dev/usb2/core/usb2_device.c src/sys/dev/usb2/core/usb2_generic.c Bugfix for Linux USB compat layer. Do not free non-generic FIFOs when doing an alternate setting. Cleanup USB IOCTL and USB reference handling. Fix a corner case where USB-FS was left initialised after setting a new configuration or alternate setting. src/sys/dev/usb2/core/usb2_hub.c Improvement: Check all USB HUB ports by default at least one time. src/sys/dev/usb2/core/usb2_request.c Bugfix: Make sure destination ASCII string is properly zero terminated in all cases. Improvement: Skip invalid characters instead of replacing with a dot. src/sys/dev/usb2/core/usb2_util.c src/sys/dev/usb2/image/uscanner2.c Spelling. src/sys/dev/usb2/include/Makefile Share "usbdevs" with the old USB stack. src/sys/dev/usb2/include/usb2_devid.h src/sys/dev/usb2/include/usb2_devtable.h Regenerate files. Alfred: Please fix the RCS tag at the top. src/sys/dev/usb2/include/usb2_ioctl.h Fix compilation of "kdump". src/sys/dev/usb2/serial/ubsa2.c src/sys/dev/usb2/serial/ugensa2.c Remove device ID's which will end up in a new 3G driver. src/sys/dev/usb2/sound/uaudio2.c Correct a debug printout. src/sys/dev/usb2/storage/umass2.c Sync with old USB stack. src/lib/libusb20/libusb20.3 Add more documentation. src/lib/libusb20/libusb20.c Various bugfixes and improvements. src/usr.sbin/usbconfig/dump.c src/usr.sbin/usbconfig/usbconfig.c New commands for dumping strings and doing custom USB requests from the command line. Remove keyword requirements from generated files: "head/sys/dev/usb2/include/usb2_devid.h" "head/sys/dev/usb2/include/usb2_devtable.h"
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile4
-rw-r--r--lib/libusb20/libusb20.3194
-rw-r--r--lib/libusb20/libusb20.c58
-rw-r--r--lib/libusb20/libusb20.h3
-rw-r--r--lib/libusb20/libusb20_compat01.c69
-rw-r--r--lib/libusb20/libusb20_compat01.h2
-rw-r--r--lib/libusb20/libusb20_desc.c12
-rw-r--r--lib/libusb20/libusb20_desc.h2
-rw-r--r--lib/libusb20/libusb20_ugen20.c201
9 files changed, 317 insertions, 228 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 1b5ba44..a44335c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -38,7 +38,8 @@ SUBDIR= ${_csu} libc libbsm libcom_err libcrypt libelf libkvm msun libmd \
${_libpmc} libproc librt ${_libsdp} ${_libsm} ${_libsmb} \
${_libsmdb} \
${_libsmutil} libstand ${_libtelnet} ${_libthr} libthread_db libufs \
- libugidfw ${_libusbhid} ${_libvgl} libwrap liby libz ${_bind}
+ libugidfw ${_libusbhid} ${_libusb20} ${_libvgl} libwrap liby libz \
+ ${_bind}
.if exists(${.CURDIR}/csu/${MACHINE_ARCH}-elf)
_csu=csu/${MACHINE_ARCH}-elf
@@ -136,6 +137,7 @@ _libtelnet= libtelnet
.if ${MK_USB} != "no"
_libusbhid= libusbhid
+_libusb20= libusb20
.endif
.include <bsd.subdir.mk>
diff --git a/lib/libusb20/libusb20.3 b/lib/libusb20/libusb20.3
index 975bc63..414c81f 100644
--- a/lib/libusb20/libusb20.3
+++ b/lib/libusb20/libusb20.3
@@ -60,9 +60,9 @@ USB through the USB file system interface.
.
.Pp
.
-.Fn libusb20_tr_close
+.Fn libusb20_tr_close pxfer
This function will release all kernel resources associated with an USB
-.Fa xfer .
+.Fa pxfer .
.
This function returns zero upon success.
.
@@ -70,13 +70,13 @@ Non-zero return values indicate a LIBUSB20_ERROR value.
.
.Pp
.
-.Fn libusb20_tr_open
+.Fn libusb20_tr_open pxfer max_buf_size max_frame_count ep_no
This function will allocate kernel resources like
-.Fa MaxBufSize
+.Fa max_buf_size
and
-.Fa MaxFrameCount
+.Fa max_frame_count
associated with an USB
-.Fa xfer
+.Fa pxfer
and bind the transfer to the specified
.Fa ep_no .
.
@@ -86,7 +86,7 @@ Non-zero return values indicate a LIBUSB20_ERROR value.
.
.Pp
.
-.Fn libusb20_tr_get_pointer
+.Fn libusb20_tr_get_pointer pdev tr_index
This function will return a pointer to the allocated USB transfer according to the
.Fa pdev
and
@@ -97,32 +97,32 @@ This function returns NULL in case of failure.
.
.Pp
.
-.Fn libusb20_tr_get_time_complete
+.Fn libusb20_tr_get_time_complete pxfer
This function will return the completion time of an USB transfer in
millisecond units. This function is most useful for isochronous USB
transfers when doing echo cancelling.
.
.Pp
.
-.Fn libusb20_tr_get_actual_frames
+.Fn libusb20_tr_get_actual_frames pxfer
This function will return the actual number of USB frames after an USB
transfer completed. A value of zero means that no data was transferred.
.
.Pp
.
-.Fn libusb20_tr_get_actual_length
+.Fn libusb20_tr_get_actual_length pxfer
This function will return the sum of the actual length for all
transferred USB frames for the given USB transfer.
.
.Pp
.
-.Fn libusb20_tr_get_max_frames
+.Fn libusb20_tr_get_max_frames pxfer
This function will return the maximum number of USB frames that were
allocated when an USB transfer was setup for the given USB transfer.
.
.Pp
.
-.Fn libusb20_tr_get_max_packet_length
+.Fn libusb20_tr_get_max_packet_length pxfer
This function will return the maximum packet length in bytes
associated with the given USB transfer.
.
@@ -132,20 +132,20 @@ packets are avoided for proxy buffers.
.
.Pp
.
-.Fn libusb20_tr_get_max_total_length
+.Fn libusb20_tr_get_max_total_length pxfer
This function will return the maximum value for the length sum of all
USB frames associated with an USB transfer.
.
.Pp
.
-.Fn libusb20_tr_get_status
+.Fn libusb20_tr_get_status pxfer
This function will return the status of an USB transfer.
.
Status values are defined by a set of LIBUSB20_TRANSFER_XXX enums.
.
.Pp
.
-.Fn libusb20_tr_pending
+.Fn libusb20_tr_pending pxfer
This function will return non-zero if the given USB transfer is
pending for completion.
.
@@ -153,12 +153,12 @@ Else this function returns zero.
.
.Pp
.
-.Fn libusb20_tr_callback_wrapper
+.Fn libusb20_tr_callback_wrapper pxfer
This is an internal function used to wrap asynchronous USB callbacks.
.
.Pp
.
-.Fn libusb20_tr_clear_stall_sync
+.Fn libusb20_tr_clear_stall_sync pxfer
This is an internal function used to synchronously clear the stall on
the given USB transfer.
.
@@ -171,13 +171,13 @@ been called.
.
.Pp
.
-.Fn libusb20_tr_drain
+.Fn libusb20_tr_drain pxfer
This function will stop the given USB transfer and will not return
until the USB transfer has been stopped in hardware.
.
.Pp
.
-.Fn libusb20_tr_set_buffer
+.Fn libusb20_tr_set_buffer pxfer pbuf fr_index
This function is used to set the
.Fa buffer
pointer for the given USB transfer and
@@ -188,7 +188,7 @@ Typically the frame index is zero.
.
.Pp
.
-.Fn libusb20_tr_set_callback
+.Fn libusb20_tr_set_callback pxfer pcallback
This function is used to set the USB callback for asynchronous USB
transfers.
.
@@ -196,7 +196,7 @@ The callback type is defined by libusb20_tr_callback_t.
.
.Pp
.
-.Fn libusb20_tr_set_flags
+.Fn libusb20_tr_set_flags pxfer flags
This function is used to set various USB flags for the given USB transfer.
.Bl -tag
.It LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK
@@ -211,22 +211,22 @@ Will do a clear-stall before starting the transfer.
.
.Pp
.
-.Fn libusb20_tr_set_length
+.Fn libusb20_tr_set_length pxfer length fr_index
This function sets the length of a given USB transfer and frame index.
.
.Pp
.
-.Fn libusb20_tr_set_priv_sc0
+.Fn libusb20_tr_set_priv_sc0 pxfer psc0
This function sets private driver pointer number zero.
.
.Pp
.
-.Fn libusb20_tr_set_priv_sc1
+.Fn libusb20_tr_set_priv_sc1 pxfer psc1
This function sets private driver pointer number one.
.
.Pp
.
-.Fn libusb20_tr_set_timeout
+.Fn libusb20_tr_set_timeout pxfer timeout
This function sets the timeout for the given USB transfer.
.
A timeout value of zero means no timeout.
@@ -235,35 +235,35 @@ The timeout is given in milliseconds.
.
.Pp
.
-.Fn libusb20_tr_set_total_frames
+.Fn libusb20_tr_set_total_frames pxfer nframes
This function sets the total number of frames that should be executed when the USB transfer is submitted.
.
The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer.
.
.Pp
.
-.Fn libusb20_tr_setup_bulk
+.Fn libusb20_tr_setup_bulk pxfer pbuf length timeout
This function is a helper function for setting up a single frame USB BULK transfer.
.
.Pp
.
-.Fn libusb20_tr_setup_control
+.Fn libusb20_tr_setup_control pxfer psetup pbuf timeout
This function is a helper function for setting up a single or dual
frame USB CONTROL transfer depending on the control transfer length.
.
.Pp
.
-.Fn libusb20_tr_setup_intr
+.Fn libusb20_tr_setup_intr pxfer pbuf length timeout
This function is a helper function for setting up a single frame USB INTERRUPT transfer.
.
.Pp
.
-.Fn libusb20_tr_setup_isoc
+.Fn libusb20_tr_setup_isoc pxfer pbuf length fr_index
This function is a helper function for setting up a multi frame USB ISOCHRONOUS transfer.
.
.Pp
.
-.Fn libusb20_tr_start
+.Fn libusb20_tr_start pxfer
This function will get the USB transfer started, if not already
started.
.
@@ -273,7 +273,7 @@ This function is non-blocking.
.
.Pp
.
-.Fn libusb20_tr_stop
+.Fn libusb20_tr_stop pxfer
This function will get the USB transfer stopped, if not already stopped.
.
This function is non-blocking, which means that the actual stop can
@@ -281,20 +281,20 @@ happen after the return of this function.
.
.Pp
.
-.Fn libusb20_tr_submit
+.Fn libusb20_tr_submit pxfer
This function will get the USB transfer queued in hardware.
.
.
.Pp
.
-.Fn libusb20_tr_get_priv_sc0
+.Fn libusb20_tr_get_priv_sc0 pxfer
This function returns private driver pointer number zero associated
with an USB transfer.
.
.
.Pp
.
-.Fn libusb20_tr_get_priv_sc1
+.Fn libusb20_tr_get_priv_sc1 pxfer
This function returns private driver pointer number one associated
with an USB transfer.
.
@@ -303,17 +303,17 @@ with an USB transfer.
.
.Pp
.
-.Fn libusb20_dev_get_backend_name
+.Fn libusb20_dev_get_backend_name pdev
This function returns a zero terminated string describing the backend used.
.
.Pp
.
-.Fn libusb20_dev_get_desc
+.Fn libusb20_dev_get_desc pdev
This function returns a zero terminated string describing the given USB device.
.
.Pp
.
-.Fn libusb20_dev_claim_interface
+.Fn libusb20_dev_claim_interface pdev iface_index
This function will try to claim the given USB interface given by
.Fa iface_index .
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -321,7 +321,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_close
+.Fn libusb20_dev_close pdev
This function will close the given USB device.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -329,7 +329,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_detach_kernel_driver
+.Fn libusb20_dev_detach_kernel_driver pdev iface_index
This function will try to detach the kernel driver for the USB interface given by
.Fa iface_index .
.
@@ -338,7 +338,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_set_config_index
+.Fn libusb20_dev_set_config_index pdev config_index
This function will try to set the configuration index on an USB
device.
.
@@ -350,12 +350,12 @@ This function returns zero on success else a LIBUSB20_ERROR value is returned.
.
.Pp
.
-.Fn libusb20_dev_get_debug
+.Fn libusb20_dev_get_debug pdev
This function returns the debug level of an USB device.
.
.Pp
.
-.Fn libusb20_dev_get_fd
+.Fn libusb20_dev_get_fd pdev
This function returns the file descriptor of the given USB device.
.
A negative value is returned when no file descriptor is present.
@@ -364,7 +364,7 @@ The file descriptor can be used for polling purposes.
.
.Pp
.
-.Fn libusb20_dev_kernel_driver_active
+.Fn libusb20_dev_kernel_driver_active pdev iface_index
This function returns a non-zero value if a kernel driver is active on
the given USB interface.
.
@@ -372,7 +372,7 @@ Else zero is returned.
.
.Pp
.
-.Fn libusb20_dev_open
+.Fn libusb20_dev_open pdev transfer_max
This function opens an USB device so that setting up USB transfers
becomes possible.
.
@@ -387,7 +387,7 @@ opened.
.
.Pp
.
-.Fn libusb20_dev_process
+.Fn libusb20_dev_process pdev
This function is called to sync kernel USB transfers with userland USB
transfers.
.
@@ -397,7 +397,7 @@ detached.
.
.Pp
.
-.Fn libusb20_dev_release_interface
+.Fn libusb20_dev_release_interface pdev iface_index
This function will try to release a claimed USB interface for the specified USB device.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -405,7 +405,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_request_sync
+.Fn libusb20_dev_request_sync pdev psetup pdata pactlen timeout flags
This function will perform a synchronous control request on the given
USB device.
.
@@ -428,7 +428,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_req_string_sync
+.Fn libusb20_dev_req_string_sync pdev index lang_id pbuf len
This function will synchronously request an USB string by language ID
and string index into the given buffer limited by a maximum length.
.
@@ -437,7 +437,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_req_string_simple_sync
+.Fn libusb20_dev_req_string_simple_sync pdev index pbuf len
This function will synchronously request an USB string using the
default language ID and convert the string into ASCII before storing
the string into the given buffer limited by a maximum length which
@@ -449,7 +449,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_reset
+.Fn libusb20_dev_reset pdev
This function will try to BUS reset the given USB device and restore
the last set USB configuration.
.
@@ -458,7 +458,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_set_power_mode
+.Fn libusb20_dev_set_power_mode pdev power_mode
This function sets the power mode of the USB device.
.
Valid power modes:
@@ -475,13 +475,13 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_get_power_mode
+.Fn libusb20_dev_get_power_mode pdev
This function returns the currently selected power mode for the given
USB device.
.
.Pp
.
-.Fn libusb20_dev_set_alt_index
+.Fn libusb20_dev_set_alt_index pdev iface_index alt_index
This function will try to set the given alternate index for the given
USB interface index.
.
@@ -490,7 +490,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_set_owner
+.Fn libusb20_dev_set_owner pdev uid gid
This function will set the ownership of the given USB device.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -498,7 +498,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_set_perm
+.Fn libusb20_dev_set_perm pdev mode
This function will set the permissions of the given USB device.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -506,7 +506,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_set_iface_owner
+.Fn libusb20_dev_set_iface_owner pdev iface_index uid gid
This function will set the ownership of the given USB interface.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -514,7 +514,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_set_iface_perm
+.Fn libusb20_dev_set_iface_perm pdev iface_index mode
This function will set the permissions of the given USB interface.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -522,7 +522,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_get_owner
+.Fn libusb20_dev_get_owner pdev puid pgid
This function will retrieve the current USB device ownership.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -530,7 +530,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_get_perm
+.Fn libusb20_dev_get_perm pdev pmode
This function will retrieve the current USB device permissions.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -538,7 +538,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_get_iface_owner
+.Fn libusb20_dev_get_iface_owner pdev iface_index puid pgid
This function will retrieve the current USB interface ownership for
the given USB interface.
.
@@ -547,7 +547,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_get_iface_perm
+.Fn libusb20_dev_get_iface_perm pdev iface_index pmode
This function will retrieve the current USB interface permissions for
the given USB interface.
.
@@ -556,7 +556,7 @@ returned.
.
.Pp
.
-.Fn libusb20_dev_get_device_desc
+.Fn libusb20_dev_get_device_desc pdev
This function returns a pointer to the decoded and host endian version
of the device descriptor.
.
@@ -564,7 +564,7 @@ The USB device need not be opened when calling this function.
.
.Pp
.
-.Fn libusb20_dev_alloc_config
+.Fn libusb20_dev_alloc_config pdev config_index
This function will read out and decode the USB config descriptor for
the given USB device and config index. This function returns a pointer
to the decoded configuration which must eventually be passed to
@@ -572,24 +572,24 @@ free(). NULL is returned in case of failure.
.
.Pp
.
-.Fn libusb20_dev_alloc(void)
+.Fn libusb20_dev_alloc void
This is an internal function to allocate a new USB device.
.
.Pp
.
-.Fn libusb20_dev_get_address
+.Fn libusb20_dev_get_address pdev
This function returns the internal and not necessarily the real
hardware address of the given USB device.
.
.Pp
.
-.Fn libusb20_dev_get_bus_number
+.Fn libusb20_dev_get_bus_number pdev
This function return the internal bus number which the given USB
device belongs to.
.
.Pp
.
-.Fn libusb20_dev_get_mode
+.Fn libusb20_dev_get_mode pdev
This function returns the current operation mode of the USB entity.
.
Valid return values are:
@@ -600,7 +600,7 @@ Valid return values are:
.
.Pp
.
-.Fn libusb20_dev_get_speed
+.Fn libusb20_dev_get_speed pdev
This function returns the current speed of the given USB device.
.
.Bl -tag
@@ -614,24 +614,24 @@ This function returns the current speed of the given USB device.
.
.Pp
.
-.Fn libusb20_dev_get_config_index
+.Fn libusb20_dev_get_config_index pdev
This function returns the currently select config index for the given
USB device.
.
.Pp
.
-.Fn libusb20_dev_free
+.Fn libusb20_dev_free pdev
This function will free the given USB device and all associated USB
transfers.
.
.Pp
.
-.Fn libusb20_dev_set_debug
+.Fn libusb20_dev_set_debug pdev debug_level
This function will set the debug level for the given USB device.
.
.Pp
.
-.Fn libusb20_dev_wait_process
+.Fn libusb20_dev_wait_process pdev timeout
This function will wait until a pending USB transfer has completed on
the given USB device.
.
@@ -641,7 +641,7 @@ function.
.
.Sh USB BUS OPERATIONS
.
-.Fn libusb20_bus_set_owner
+.Fn libusb20_bus_set_owner pbackend bus_index uid gid
This function will set the ownership for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -649,7 +649,7 @@ returned.
.
.Pp
.
-.Fn libusb20_bus_set_perm
+.Fn libusb20_bus_set_perm pbackend bus_index mode
This function will set the permissions for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -657,7 +657,7 @@ returned.
.
.Pp
.
-.Fn libusb20_bus_get_owner
+.Fn libusb20_bus_get_owner pbackend bus_index puid pgid
This function will retrieve the ownership for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -665,7 +665,7 @@ returned.
.
.Pp
.
-.Fn libusb20_bus_get_perm
+.Fn libusb20_bus_get_perm pbackend bus_index pmode
This function will retrieve the permissions for the given USB bus.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -674,7 +674,7 @@ returned.
.
.Sh USB BACKEND OPERATIONS
.
-.Fn libusb20_be_get_dev_quirk
+.Fn libusb20_be_get_dev_quirk pbackend index pquirk
This function will return the device quirk according to
.Fa index
into the libusb20_quirk structure pointed to by
@@ -687,7 +687,7 @@ returned.
.
.Pp
.
-.Fn libusb20_be_get_quirk_name
+.Fn libusb20_be_get_quirk_name pbackend index pquirk
This function will return the quirk name according to
.Fa index
into the libusb20_quirk structure pointed to by
@@ -700,7 +700,7 @@ returned.
.
.Pp
.
-.Fn libusb20_be_add_dev_quirk
+.Fn libusb20_be_add_dev_quirk pbackend pquirk
This function will add the libusb20_quirk structure pointed to by the
.Fa pq
argument into the device quirk list.
@@ -713,7 +713,7 @@ returned.
.
.Pp
.
-.Fn libusb20_be_remove_dev_quirk
+.Fn libusb20_be_remove_dev_quirk pbackend pquirk
This function will remove the quirk matching the libusb20_quirk structure pointed to by the
.Fa pq
argument from the device quirk list.
@@ -726,7 +726,7 @@ returned.
.
.Pp
.
-.Fn libusb20_be_set_owner
+.Fn libusb20_be_set_owner pbackend uid gid
This function will set the ownership for the given backend.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -734,7 +734,7 @@ returned.
.
.Pp
.
-.Fn libusb20_be_set_perm
+.Fn libusb20_be_set_perm pbackend mode
This function will set the permissions for the given backend.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -742,7 +742,7 @@ returned.
.
.Pp
.
-.Fn libusb20_be_get_owner
+.Fn libusb20_be_get_owner pbackend puid pgid
This function will retrieve the ownership of the given backend.
.
This function returns zero on success else a LIBUSB20_ERROR value is
@@ -750,7 +750,7 @@ returned.
.
.Pp
.
-.Fn libusb20_be_get_perm
+.Fn libusb20_be_get_perm pbackend pmode
This function will retrieve the permissions of the given backend.
.
.
@@ -759,20 +759,20 @@ returned.
.
.Pp
.
-.Fn libusb20_be_alloc
+.Fn libusb20_be_alloc pmethods
This is an internal function to allocate a USB backend.
.
.Pp
-.Fn libusb20_be_alloc_default
-.Fn libusb20_be_alloc_freebsd
-.Fn libusb20_be_alloc_linux
+.Fn libusb20_be_alloc_default void
+.Fn libusb20_be_alloc_freebsd void
+.Fn libusb20_be_alloc_linux void
These functions are used to allocate a specific USB backend or the
operating system default USB backend. Allocating a backend is a way to
scan for currently present USB devices.
.
.Pp
.
-.Fn libusb20_be_device_foreach
+.Fn libusb20_be_device_foreach pbackend pdev
This function is used to iterate USB devices present in a USB backend.
.
The starting value of
@@ -785,7 +785,7 @@ If NULL is returned the end of the USB device list has been reached.
.
.Pp
.
-.Fn libusb20_be_dequeue_device
+.Fn libusb20_be_dequeue_device pbackend pdev
This function will dequeue the given USB device pointer from the
backend USB device list.
.
@@ -793,20 +793,20 @@ Dequeued USB devices will not be freed when the backend is freed.
.
.Pp
.
-.Fn libusb20_be_enqueue_device
+.Fn libusb20_be_enqueue_device pbackend pdev
This function will enqueue the given USB device pointer in the backend USB device list.
.
Enqueued USB devices will get freed when the backend is freed.
.
.Pp
.
-.Fn libusb20_be_free
+.Fn libusb20_be_free pbackend
This function will free the given backend and all USB devices in its device list.
.
.
.Sh USB DESCRIPTOR PARSING
.
-.Fn libusb20_me_get_1
+.Fn libusb20_me_get_1 pie offset
This function will return a byte at the given byte offset of a message
entity.
.
@@ -814,7 +814,7 @@ This function is safe against invalid offsets.
.
.Pp
.
-.Fn libusb20_me_get_2
+.Fn libusb20_me_get_2 pie offset
This function will return a little endian 16-bit value at the given byte offset of a message
entity.
.
@@ -822,7 +822,7 @@ This function is safe against invalid offsets.
.
.Pp
.
-.Fn libusb20_me_encode
+.Fn libusb20_me_encode pbuf len pdecoded
This function will encode a so-called *DECODED structure into binary
format.
.
@@ -834,7 +834,7 @@ location.
.
.Pp
.
-.Fn libusb20_me_decode
+.Fn libusb20_me_decode pbuf len pdecoded
This function will decode a binary structure into a so-called *DECODED
structure.
.
diff --git a/lib/libusb20/libusb20.c b/lib/libusb20/libusb20.c
index 432cd99..f9c99cb 100644
--- a/lib/libusb20/libusb20.c
+++ b/lib/libusb20/libusb20.c
@@ -550,6 +550,9 @@ libusb20_dev_open(struct libusb20_device *pdev, uint16_t nTransferMax)
xfer->callback = &dummy_callback;
}
+ /* set "nTransfer" early */
+ pdev->nTransfer = nTransferMax;
+
error = (pdev->beMethods->open_device) (pdev, nTransferMax);
if (error) {
@@ -562,7 +565,6 @@ libusb20_dev_open(struct libusb20_device *pdev, uint16_t nTransferMax)
pdev->nTransfer = 0;
} else {
pdev->is_opened = 1;
- pdev->nTransfer = nTransferMax;
}
return (error);
}
@@ -647,7 +649,7 @@ libusb20_dev_request_sync(struct libusb20_device *pdev,
int
libusb20_dev_req_string_sync(struct libusb20_device *pdev,
- uint8_t index, uint16_t langid, void *ptr, uint16_t len)
+ uint8_t str_index, uint16_t langid, void *ptr, uint16_t len)
{
struct LIBUSB20_CONTROL_SETUP_DECODED req;
int error;
@@ -667,7 +669,7 @@ libusb20_dev_req_string_sync(struct libusb20_device *pdev,
LIBUSB20_RECIPIENT_DEVICE |
LIBUSB20_ENDPOINT_IN;
req.bRequest = LIBUSB20_REQUEST_GET_DESCRIPTOR;
- req.wValue = (LIBUSB20_DT_STRING << 8) | index;
+ req.wValue = (LIBUSB20_DT_STRING << 8) | str_index;
req.wIndex = langid;
req.wLength = 4; /* bytes */
@@ -695,7 +697,7 @@ libusb20_dev_req_string_sync(struct libusb20_device *pdev,
int
libusb20_dev_req_string_simple_sync(struct libusb20_device *pdev,
- uint8_t index, void *ptr, uint16_t len)
+ uint8_t str_index, void *ptr, uint16_t len)
{
char *buf;
int error;
@@ -712,26 +714,23 @@ libusb20_dev_req_string_simple_sync(struct libusb20_device *pdev,
/* too short buffer */
return (LIBUSB20_ERROR_INVALID_PARAM);
}
- /*
- * Make sure that there is sensible contents in the buffer in case
- * of an error:
- */
- *(uint8_t *)ptr = 0;
-
error = libusb20_dev_req_string_sync(pdev,
0, 0, temp, sizeof(temp));
- if (error < 0)
+ if (error < 0) {
+ *(uint8_t *)ptr = 0; /* zero terminate */
return (error);
-
+ }
langid = temp[2] | (temp[3] << 8);
- error = libusb20_dev_req_string_sync(pdev, index,
+ error = libusb20_dev_req_string_sync(pdev, str_index,
langid, temp, sizeof(temp));
- if (error < 0)
+ if (error < 0) {
+ *(uint8_t *)ptr = 0; /* zero terminate */
return (error);
-
+ }
if (temp[0] < 2) {
/* string length is too short */
+ *(uint8_t *)ptr = 0; /* zero terminate */
return (LIBUSB20_ERROR_OTHER);
}
/* reserve one byte for terminating zero */
@@ -762,14 +761,16 @@ libusb20_dev_req_string_simple_sync(struct libusb20_device *pdev,
*buf = c >> 8;
swap = 2;
} else {
- *buf = '.';
+ /* skip invalid character */
+ continue;
}
/*
* Filter by default - we don't allow greater and less than
* signs because they might confuse the dmesg printouts!
*/
if ((*buf == '<') || (*buf == '>') || (!isprint(*buf))) {
- *buf = '.';
+ /* skip invalid character */
+ continue;
}
buf++;
}
@@ -836,7 +837,7 @@ uint8_t
libusb20_dev_get_config_index(struct libusb20_device *pdev)
{
int error;
- uint8_t index;
+ uint8_t cfg_index;
uint8_t do_close;
if (!pdev->is_opened) {
@@ -850,16 +851,16 @@ libusb20_dev_get_config_index(struct libusb20_device *pdev)
do_close = 0;
}
- error = (pdev->methods->get_config_index) (pdev, &index);
+ error = (pdev->methods->get_config_index) (pdev, &cfg_index);
if (error) {
- index = 0 - 1; /* current config index */
+ cfg_index = 0 - 1; /* current config index */
}
if (do_close) {
if (libusb20_dev_close(pdev)) {
/* ignore */
}
}
- return (index);
+ return (cfg_index);
}
uint8_t
@@ -887,7 +888,7 @@ libusb20_dev_process(struct libusb20_device *pdev)
void
libusb20_dev_wait_process(struct libusb20_device *pdev, int timeout)
{
- struct pollfd pfd[2];
+ struct pollfd pfd[1];
if (!pdev->is_opened) {
return;
@@ -895,11 +896,8 @@ libusb20_dev_wait_process(struct libusb20_device *pdev, int timeout)
pfd[0].fd = pdev->file;
pfd[0].events = (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM);
pfd[0].revents = 0;
- pfd[1].fd = 0; /* standard input */
- pfd[1].events = (POLLIN | POLLRDNORM);
- pfd[1].revents = 0;
- if (poll(pfd, 2, timeout)) {
+ if (poll(pfd, 1, timeout)) {
/* ignore any error */
}
return;
@@ -1071,16 +1069,16 @@ libusb20_bus_get_perm(struct libusb20_backend *pbe, uint8_t bus, mode_t *mode)
int
libusb20_be_get_dev_quirk(struct libusb20_backend *pbe,
- uint16_t index, struct libusb20_quirk *pq)
+ uint16_t quirk_index, struct libusb20_quirk *pq)
{
- return ((pbe->methods->root_get_dev_quirk) (pbe, index, pq));
+ return ((pbe->methods->root_get_dev_quirk) (pbe, quirk_index, pq));
}
int
libusb20_be_get_quirk_name(struct libusb20_backend *pbe,
- uint16_t index, struct libusb20_quirk *pq)
+ uint16_t quirk_index, struct libusb20_quirk *pq)
{
- return ((pbe->methods->root_get_quirk_name) (pbe, index, pq));
+ return ((pbe->methods->root_get_quirk_name) (pbe, quirk_index, pq));
}
int
diff --git a/lib/libusb20/libusb20.h b/lib/libusb20/libusb20.h
index 7fb8e68..d696b63 100644
--- a/lib/libusb20/libusb20.h
+++ b/lib/libusb20/libusb20.h
@@ -199,7 +199,7 @@ struct libusb20_quirk {
/* USB transfer operations */
int libusb20_tr_close(struct libusb20_transfer *xfer);
-int libusb20_tr_open(struct libusb20_transfer *xfer, uint32_t pMaxBufSize, uint32_t MaxFrameCount, uint8_t ep_no);
+int libusb20_tr_open(struct libusb20_transfer *xfer, uint32_t max_buf_size, uint32_t max_frame_count, uint8_t ep_no);
struct libusb20_transfer *libusb20_tr_get_pointer(struct libusb20_device *pdev, uint16_t tr_index);
uint16_t libusb20_tr_get_time_complete(struct libusb20_transfer *xfer);
uint32_t libusb20_tr_get_actual_frames(struct libusb20_transfer *xfer);
@@ -297,6 +297,7 @@ struct libusb20_backend *libusb20_be_alloc(const struct libusb20_backend_methods
struct libusb20_backend *libusb20_be_alloc_default(void);
struct libusb20_backend *libusb20_be_alloc_freebsd(void);
struct libusb20_backend *libusb20_be_alloc_linux(void);
+struct libusb20_backend *libusb20_be_alloc_ugen20(void);
struct libusb20_device *libusb20_be_device_foreach(struct libusb20_backend *pbe, struct libusb20_device *pdev);
void libusb20_be_dequeue_device(struct libusb20_backend *pbe, struct libusb20_device *pdev);
void libusb20_be_enqueue_device(struct libusb20_backend *pbe, struct libusb20_device *pdev);
diff --git a/lib/libusb20/libusb20_compat01.c b/lib/libusb20/libusb20_compat01.c
index e9d9ebe..b63c5e9 100644
--- a/lib/libusb20/libusb20_compat01.c
+++ b/lib/libusb20/libusb20_compat01.c
@@ -131,7 +131,7 @@ usb_get_transfer_by_ep_no(usb_dev_handle * dev, uint8_t ep_no)
x = (ep_no & LIBUSB20_ENDPOINT_ADDRESS_MASK) * 2;
if (ep_no & LIBUSB20_ENDPOINT_DIR_MASK) {
- /* this is a IN endpoint */
+ /* this is an IN endpoint */
x |= 1;
}
speed = libusb20_dev_get_speed(pdev);
@@ -194,13 +194,13 @@ usb_close(usb_dev_handle * dev)
}
int
-usb_get_string(usb_dev_handle * dev, int index,
+usb_get_string(usb_dev_handle * dev, int strindex,
int langid, char *buf, size_t buflen)
{
int err;
err = libusb20_dev_req_string_sync((void *)dev,
- index, langid, buf, buflen);
+ strindex, langid, buf, buflen);
if (err)
return (-1);
@@ -209,13 +209,13 @@ usb_get_string(usb_dev_handle * dev, int index,
}
int
-usb_get_string_simple(usb_dev_handle * dev, int index,
+usb_get_string_simple(usb_dev_handle * dev, int strindex,
char *buf, size_t buflen)
{
int err;
err = libusb20_dev_req_string_simple_sync((void *)dev,
- index, buf, buflen);
+ strindex, buf, buflen);
if (err)
return (-1);
@@ -225,23 +225,23 @@ usb_get_string_simple(usb_dev_handle * dev, int index,
int
usb_get_descriptor_by_endpoint(usb_dev_handle * udev, int ep, uint8_t type,
- uint8_t index, void *buf, int size)
+ uint8_t ep_index, void *buf, int size)
{
memset(buf, 0, size);
return (usb_control_msg(udev, ep | USB_ENDPOINT_IN,
- USB_REQ_GET_DESCRIPTOR, (type << 8) + index, 0,
+ USB_REQ_GET_DESCRIPTOR, (type << 8) + ep_index, 0,
buf, size, 1000));
}
int
-usb_get_descriptor(usb_dev_handle * udev, uint8_t type, uint8_t index,
+usb_get_descriptor(usb_dev_handle * udev, uint8_t type, uint8_t desc_index,
void *buf, int size)
{
memset(buf, 0, size);
return (usb_control_msg(udev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
- (type << 8) + index, 0, buf, size, 1000));
+ (type << 8) + desc_index, 0, buf, size, 1000));
}
int
@@ -616,33 +616,37 @@ int
usb_bulk_write(usb_dev_handle * dev, int ep, char *bytes,
int size, int timeout)
{
- return (usb_std_io(dev, ep, bytes, size, timeout, 0));
+ return (usb_std_io(dev, ep & ~USB_ENDPOINT_DIR_MASK,
+ bytes, size, timeout, 0));
}
int
usb_bulk_read(usb_dev_handle * dev, int ep, char *bytes,
int size, int timeout)
{
- return (usb_std_io(dev, ep, bytes, size, timeout, 0));
+ return (usb_std_io(dev, ep | USB_ENDPOINT_DIR_MASK,
+ bytes, size, timeout, 0));
}
int
usb_interrupt_write(usb_dev_handle * dev, int ep, char *bytes,
int size, int timeout)
{
- return (usb_std_io(dev, ep, bytes, size, timeout, 1));
+ return (usb_std_io(dev, ep & ~USB_ENDPOINT_DIR_MASK,
+ bytes, size, timeout, 1));
}
int
usb_interrupt_read(usb_dev_handle * dev, int ep, char *bytes,
int size, int timeout)
{
- return (usb_std_io(dev, ep, bytes, size, timeout, 1));
+ return (usb_std_io(dev, ep | USB_ENDPOINT_DIR_MASK,
+ bytes, size, timeout, 1));
}
int
usb_control_msg(usb_dev_handle * dev, int requesttype, int request,
- int value, int index, char *bytes, int size, int timeout)
+ int value, int wIndex, char *bytes, int size, int timeout)
{
struct LIBUSB20_CONTROL_SETUP_DECODED req;
int err;
@@ -653,7 +657,7 @@ usb_control_msg(usb_dev_handle * dev, int requesttype, int request,
req.bmRequestType = requesttype;
req.bRequest = request;
req.wValue = value;
- req.wIndex = index;
+ req.wIndex = wIndex;
req.wLength = size;
err = libusb20_dev_request_sync((void *)dev, &req, bytes,
@@ -666,11 +670,40 @@ usb_control_msg(usb_dev_handle * dev, int requesttype, int request,
}
int
-usb_set_configuration(usb_dev_handle * dev, int configuration)
+usb_set_configuration(usb_dev_handle * udev, int bConfigurationValue)
{
+ struct usb_device *dev;
int err;
+ uint8_t i;
+
+ /*
+ * Need to translate from "bConfigurationValue" to
+ * configuration index:
+ */
+
+ if (bConfigurationValue == 0) {
+ /* unconfigure */
+ i = 255;
+ } else {
+ /* lookup configuration index */
+ dev = usb_device(udev);
+
+ /* check if the configuration array is not there */
+ if (dev->config == NULL) {
+ return (-1);
+ }
+ for (i = 0;; i++) {
+ if (i == dev->descriptor.bNumConfigurations) {
+ /* "bConfigurationValue" not found */
+ return (-1);
+ }
+ if ((dev->config + i)->bConfigurationValue == bConfigurationValue) {
+ break;
+ }
+ }
+ }
- err = libusb20_dev_set_config_index((void *)dev, configuration);
+ err = libusb20_dev_set_config_index((void *)udev, i);
if (err)
return (-1);
@@ -754,7 +787,7 @@ usb_reset(usb_dev_handle * dev)
return (0);
}
-char *
+const char *
usb_strerror(void)
{
/* TODO */
diff --git a/lib/libusb20/libusb20_compat01.h b/lib/libusb20/libusb20_compat01.h
index 333793d..3963a9f 100644
--- a/lib/libusb20/libusb20_compat01.h
+++ b/lib/libusb20/libusb20_compat01.h
@@ -291,7 +291,7 @@ int usb_set_altinterface(usb_dev_handle * dev, int alternate);
int usb_resetep(usb_dev_handle * dev, unsigned int ep);
int usb_clear_halt(usb_dev_handle * dev, unsigned int ep);
int usb_reset(usb_dev_handle * dev);
-char *usb_strerror(void);
+const char *usb_strerror(void);
void usb_init(void);
void usb_set_debug(int level);
int usb_find_busses(void);
diff --git a/lib/libusb20/libusb20_desc.c b/lib/libusb20/libusb20_desc.c
index fbbd96f..bba4d25 100644
--- a/lib/libusb20/libusb20_desc.c
+++ b/lib/libusb20/libusb20_desc.c
@@ -84,8 +84,8 @@ libusb20_parse_config_desc(const void *config_desc)
/* get "wTotalLength" and setup "pcdesc" */
pcdesc.ptr = LIBUSB20_ADD_BYTES(config_desc, 0);
pcdesc.len =
- ((uint8_t *)config_desc)[2] |
- (((uint8_t *)config_desc)[3] << 8);
+ ((const uint8_t *)config_desc)[2] |
+ (((const uint8_t *)config_desc)[3] << 8);
pcdesc.type = LIBUSB20_ME_IS_RAW;
/* descriptor pre-scan */
@@ -238,7 +238,7 @@ const uint8_t *
libusb20_desc_foreach(const struct libusb20_me_struct *pdesc,
const uint8_t *psubdesc)
{
- void *end;
+ const void *end;
if (pdesc == NULL) {
return (NULL);
@@ -250,8 +250,8 @@ libusb20_desc_foreach(const struct libusb20_me_struct *pdesc,
} else {
psubdesc = LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]);
}
- return (((((void *)psubdesc) >= ((void *)(pdesc->ptr))) &&
- (((void *)psubdesc) < end) &&
+ return (((((const void *)psubdesc) >= ((void *)(pdesc->ptr))) &&
+ (((const void *)psubdesc) < end) &&
(LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]) >= ((void *)(pdesc->ptr))) &&
(LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]) <= end) &&
(psubdesc[0] >= 3)) ? psubdesc : NULL);
@@ -306,7 +306,7 @@ libusb20_me_encode(void *ptr, uint16_t len, const void *pd)
len_old = len;
buf = ptr;
pd_offset = sizeof(void *);
- pf = (*((struct libusb20_me_format **)pd))->format;
+ pf = (*((struct libusb20_me_format *const *)pd))->format;
/* scan */
diff --git a/lib/libusb20/libusb20_desc.h b/lib/libusb20/libusb20_desc.h
index 76bcca8..e5e7c94 100644
--- a/lib/libusb20/libusb20_desc.h
+++ b/lib/libusb20/libusb20_desc.h
@@ -63,7 +63,7 @@ extern "C" {
#define LIBUSB20_MIN(a,b) (((a) < (b)) ? (a) : (b))
#define LIBUSB20_ADD_BYTES(ptr,off) \
- ((void *)(((const uint8_t *)(ptr)) + (off)))
+ ((void *)(((const uint8_t *)(ptr)) + (off) - ((const uint8_t *)0)))
/* basic message elements */
enum {
diff --git a/lib/libusb20/libusb20_ugen20.c b/lib/libusb20/libusb20_ugen20.c
index ffbd861..0ef5562 100644
--- a/lib/libusb20/libusb20_ugen20.c
+++ b/lib/libusb20/libusb20_ugen20.c
@@ -308,11 +308,56 @@ ugen20_init_backend(struct libusb20_backend *pbe)
}
static int
-ugen20_open_device(struct libusb20_device *pdev, uint16_t nMaxTransfer)
+ugen20_tr_renew(struct libusb20_device *pdev)
{
- struct usb2_fs_endpoint *pfse = NULL;
- struct usb2_fs_init fs_init = { /* zero */ };
+ struct usb2_fs_uninit fs_uninit;
+ struct usb2_fs_init fs_init;
+ struct usb2_fs_endpoint *pfse;
+ int error;
uint32_t size;
+ uint16_t nMaxTransfer;
+
+ nMaxTransfer = pdev->nTransfer;
+ error = 0;
+
+ if (nMaxTransfer == 0) {
+ goto done;
+ }
+ size = nMaxTransfer * sizeof(*pfse);
+
+ if (pdev->privBeData != NULL) {
+ memset(&fs_uninit, 0, sizeof(fs_uninit));
+ if (ioctl(pdev->file, USB_FS_UNINIT, &fs_uninit)) {
+ /* ignore any errors of this kind */
+ }
+ } else {
+ pfse = malloc(size);
+ if (pfse == NULL) {
+ error = LIBUSB20_ERROR_NO_MEM;
+ goto done;
+ }
+ pdev->privBeData = pfse;
+ }
+
+ /* reset endpoint data */
+ memset(pdev->privBeData, 0, size);
+
+ memset(&fs_init, 0, sizeof(fs_init));
+
+ fs_init.pEndpoints = pdev->privBeData;
+ fs_init.ep_index_max = nMaxTransfer;
+
+ if (ioctl(pdev->file, USB_FS_INIT, &fs_init)) {
+ error = LIBUSB20_ERROR_OTHER;
+ goto done;
+ }
+done:
+ return (error);
+}
+
+static int
+ugen20_open_device(struct libusb20_device *pdev, uint16_t nMaxTransfer)
+{
uint32_t plugtime;
char buf[64];
int f;
@@ -345,36 +390,27 @@ ugen20_open_device(struct libusb20_device *pdev, uint16_t nMaxTransfer)
error = LIBUSB20_ERROR_NO_DEVICE;
goto done;
}
- if (nMaxTransfer != 0) {
-
- size = nMaxTransfer * sizeof(*pfse);
-
- pfse = malloc(size);
- if (!pfse) {
- error = LIBUSB20_ERROR_NO_MEM;
- goto done;
- }
- memset(pfse, 0, size);
-
- fs_init.pEndpoints = pfse;
- fs_init.ep_index_max = nMaxTransfer;
+ /* need to set this before "tr_renew()" */
+ pdev->file = f;
+ pdev->file_ctrl = g;
- if (ioctl(f, USB_FS_INIT, &fs_init)) {
- error = LIBUSB20_ERROR_OTHER;
- goto done;
- }
+ /* renew all USB transfers */
+ error = ugen20_tr_renew(pdev);
+ if (error) {
+ goto done;
}
/* set methods */
pdev->methods = &libusb20_ugen20_device_methods;
- pdev->privBeData = pfse;
- pdev->file = f;
- pdev->file_ctrl = g;
- error = 0;
+
done:
if (error) {
- if (pfse) {
- free(pfse);
+ if (pdev->privBeData) {
+ /* cleanup after "tr_renew()" */
+ free(pdev->privBeData);
+ pdev->privBeData = NULL;
}
+ pdev->file = -1;
+ pdev->file_ctrl = -1;
close(f);
close(g);
}
@@ -384,10 +420,11 @@ done:
static int
ugen20_close_device(struct libusb20_device *pdev)
{
- struct usb2_fs_uninit fs_uninit = { /* zero */ };
+ struct usb2_fs_uninit fs_uninit;
int error = 0;
if (pdev->privBeData) {
+ memset(&fs_uninit, 0, sizeof(fs_uninit));
if (ioctl(pdev->file, USB_FS_UNINIT, &fs_uninit)) {
error = LIBUSB20_ERROR_OTHER;
}
@@ -410,17 +447,19 @@ ugen20_exit_backend(struct libusb20_backend *pbe)
static int
ugen20_get_config_desc_full(struct libusb20_device *pdev,
- uint8_t **ppbuf, uint16_t *plen, uint8_t index)
+ uint8_t **ppbuf, uint16_t *plen, uint8_t cfg_index)
{
- struct usb2_gen_descriptor gen_desc = { /* zero */ };
+ struct usb2_gen_descriptor gen_desc;
struct usb2_config_descriptor cdesc;
uint8_t *ptr;
uint16_t len;
int error;
+ memset(&gen_desc, 0, sizeof(gen_desc));
+
gen_desc.ugd_data = &cdesc;
gen_desc.ugd_maxlen = sizeof(cdesc);
- gen_desc.ugd_config_index = index;
+ gen_desc.ugd_config_index = cfg_index;
error = ioctl(pdev->file_ctrl, USB_GET_FULL_DESC, &gen_desc);
if (error) {
@@ -466,14 +505,14 @@ ugen20_get_config_index(struct libusb20_device *pdev, uint8_t *pindex)
}
static int
-ugen20_set_config_index(struct libusb20_device *pdev, uint8_t index)
+ugen20_set_config_index(struct libusb20_device *pdev, uint8_t cfg_index)
{
- int temp = index;
+ int temp = cfg_index;
if (ioctl(pdev->file_ctrl, USB_SET_CONFIG, &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
- return (0);
+ return (ugen20_tr_renew(pdev));
}
static int
@@ -502,7 +541,9 @@ static int
ugen20_set_alt_index(struct libusb20_device *pdev,
uint8_t iface_index, uint8_t alt_index)
{
- struct usb2_alt_interface alt_iface = { /* zero */ };
+ struct usb2_alt_interface alt_iface;
+
+ memset(&alt_iface, 0, sizeof(alt_iface));
alt_iface.uai_interface_index = iface_index;
alt_iface.uai_alt_index = alt_index;
@@ -510,7 +551,7 @@ ugen20_set_alt_index(struct libusb20_device *pdev,
if (ioctl(pdev->file_ctrl, USB_SET_ALTINTERFACE, &alt_iface)) {
return (LIBUSB20_ERROR_OTHER);
}
- return (0);
+ return (ugen20_tr_renew(pdev));
}
static int
@@ -521,7 +562,7 @@ ugen20_reset_device(struct libusb20_device *pdev)
if (ioctl(pdev->file_ctrl, USB_DEVICEENUMERATE, &temp)) {
return (LIBUSB20_ERROR_OTHER);
}
- return (0);
+ return (ugen20_tr_renew(pdev));
}
static int
@@ -615,7 +656,9 @@ ugen20_do_request_sync(struct libusb20_device *pdev,
struct LIBUSB20_CONTROL_SETUP_DECODED *setup,
void *data, uint16_t *pactlen, uint32_t timeout, uint8_t flags)
{
- struct usb2_ctl_request req = { /* zero */ };
+ struct usb2_ctl_request req;
+
+ memset(&req, 0, sizeof(req));
req.ucr_data = data;
if (!(flags & LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK)) {
@@ -689,9 +732,11 @@ static int
ugen20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize,
uint32_t MaxFrameCount, uint8_t ep_no)
{
- struct usb2_fs_open temp = { /* zero */ };
+ struct usb2_fs_open temp;
struct usb2_fs_endpoint *fsep;
+ memset(&temp, 0, sizeof(temp));
+
fsep = xfer->pdev->privBeData;
fsep += xfer->trIndex;
@@ -720,7 +765,9 @@ ugen20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize,
static int
ugen20_tr_close(struct libusb20_transfer *xfer)
{
- struct usb2_fs_close temp = { /* zero */ };
+ struct usb2_fs_close temp;
+
+ memset(&temp, 0, sizeof(temp));
temp.ep_index = xfer->trIndex;
@@ -733,7 +780,9 @@ ugen20_tr_close(struct libusb20_transfer *xfer)
static int
ugen20_tr_clear_stall_sync(struct libusb20_transfer *xfer)
{
- struct usb2_fs_clear_stall_sync temp = { /* zero */ };
+ struct usb2_fs_clear_stall_sync temp;
+
+ memset(&temp, 0, sizeof(temp));
/* if the transfer is active, an error will be returned */
@@ -748,9 +797,11 @@ ugen20_tr_clear_stall_sync(struct libusb20_transfer *xfer)
static void
ugen20_tr_submit(struct libusb20_transfer *xfer)
{
- struct usb2_fs_start temp = { /* zero */ };
+ struct usb2_fs_start temp;
struct usb2_fs_endpoint *fsep;
+ memset(&temp, 0, sizeof(temp));
+
fsep = xfer->pdev->privBeData;
fsep += xfer->trIndex;
@@ -781,7 +832,9 @@ ugen20_tr_submit(struct libusb20_transfer *xfer)
static void
ugen20_tr_cancel_async(struct libusb20_transfer *xfer)
{
- struct usb2_fs_stop temp = { /* zero */ };
+ struct usb2_fs_stop temp;
+
+ memset(&temp, 0, sizeof(temp));
temp.ep_index = xfer->trIndex;
@@ -795,21 +848,21 @@ static int
ugen20_be_ioctl(uint32_t cmd, void *data)
{
int f;
- int err;
+ int error;
f = open("/dev/usb", O_RDONLY);
if (f < 0)
return (LIBUSB20_ERROR_OTHER);
- err = ioctl(f, cmd, data);
- if (err == -1) {
+ error = ioctl(f, cmd, data);
+ if (error == -1) {
if (errno == EPERM) {
- err = LIBUSB20_ERROR_ACCESS;
+ error = LIBUSB20_ERROR_ACCESS;
} else {
- err = LIBUSB20_ERROR_OTHER;
+ error = LIBUSB20_ERROR_OTHER;
}
}
close(f);
- return (err);
+ return (error);
}
static int
@@ -817,16 +870,18 @@ ugen20_be_do_perm(uint32_t get_cmd, uint32_t set_cmd, uint8_t bus,
uint8_t dev, uint8_t iface, uid_t *uid,
gid_t *gid, mode_t *mode)
{
- struct usb2_dev_perm perm = { /* zero */ };
- int err;
+ struct usb2_dev_perm perm;
+ int error;
+
+ memset(&perm, 0, sizeof(perm));
perm.bus_index = bus;
perm.dev_index = dev;
perm.iface_index = iface;
- err = ugen20_be_ioctl(get_cmd, &perm);
- if (err)
- return (err);
+ error = ugen20_be_ioctl(get_cmd, &perm);
+ if (error)
+ return (error);
if (set_cmd == 0) {
if (uid)
@@ -934,18 +989,18 @@ ugen20_dev_set_iface_perm(struct libusb20_device *pdev,
static int
ugen20_root_get_dev_quirk(struct libusb20_backend *pbe,
- uint16_t index, struct libusb20_quirk *pq)
+ uint16_t quirk_index, struct libusb20_quirk *pq)
{
struct usb2_gen_quirk q;
- int err;
+ int error;
memset(&q, 0, sizeof(q));
- q.index = index;
+ q.index = quirk_index;
- err = ugen20_be_ioctl(USB_DEV_QUIRK_GET, &q);
+ error = ugen20_be_ioctl(USB_DEV_QUIRK_GET, &q);
- if (err) {
+ if (error) {
if (errno == EINVAL) {
return (LIBUSB20_ERROR_NOT_FOUND);
}
@@ -956,30 +1011,30 @@ ugen20_root_get_dev_quirk(struct libusb20_backend *pbe,
pq->bcdDeviceHigh = q.bcdDeviceHigh;
strlcpy(pq->quirkname, q.quirkname, sizeof(pq->quirkname));
}
- return (err);
+ return (error);
}
static int
-ugen20_root_get_quirk_name(struct libusb20_backend *pbe, uint16_t index,
+ugen20_root_get_quirk_name(struct libusb20_backend *pbe, uint16_t quirk_index,
struct libusb20_quirk *pq)
{
struct usb2_gen_quirk q;
- int err;
+ int error;
memset(&q, 0, sizeof(q));
- q.index = index;
+ q.index = quirk_index;
- err = ugen20_be_ioctl(USB_QUIRK_NAME_GET, &q);
+ error = ugen20_be_ioctl(USB_QUIRK_NAME_GET, &q);
- if (err) {
+ if (error) {
if (errno == EINVAL) {
return (LIBUSB20_ERROR_NOT_FOUND);
}
} else {
strlcpy(pq->quirkname, q.quirkname, sizeof(pq->quirkname));
}
- return (err);
+ return (error);
}
static int
@@ -987,7 +1042,7 @@ ugen20_root_add_dev_quirk(struct libusb20_backend *pbe,
struct libusb20_quirk *pq)
{
struct usb2_gen_quirk q;
- int err;
+ int error;
memset(&q, 0, sizeof(q));
@@ -997,13 +1052,13 @@ ugen20_root_add_dev_quirk(struct libusb20_backend *pbe,
q.bcdDeviceHigh = pq->bcdDeviceHigh;
strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
- err = ugen20_be_ioctl(USB_DEV_QUIRK_ADD, &q);
- if (err) {
+ error = ugen20_be_ioctl(USB_DEV_QUIRK_ADD, &q);
+ if (error) {
if (errno == ENOMEM) {
return (LIBUSB20_ERROR_NO_MEM);
}
}
- return (err);
+ return (error);
}
static int
@@ -1011,7 +1066,7 @@ ugen20_root_remove_dev_quirk(struct libusb20_backend *pbe,
struct libusb20_quirk *pq)
{
struct usb2_gen_quirk q;
- int err;
+ int error;
memset(&q, 0, sizeof(q));
@@ -1021,13 +1076,13 @@ ugen20_root_remove_dev_quirk(struct libusb20_backend *pbe,
q.bcdDeviceHigh = pq->bcdDeviceHigh;
strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
- err = ugen20_be_ioctl(USB_DEV_QUIRK_REMOVE, &q);
- if (err) {
+ error = ugen20_be_ioctl(USB_DEV_QUIRK_REMOVE, &q);
+ if (error) {
if (errno == EINVAL) {
return (LIBUSB20_ERROR_NOT_FOUND);
}
}
- return (err);
+ return (error);
}
static int
OpenPOWER on IntegriCloud