public final class LibUsb extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BM_LPM_SUPPORT
Supports Link Power Management (LPM).
|
static byte |
BM_LTM_SUPPORT
Supports Latency Tolerance Messages (LTM).
|
static byte |
BT_CONTAINER_ID
Container ID type.
|
static byte |
BT_CONTAINER_ID_SIZE
Size of a BOS descriptor.
|
static byte |
BT_SS_USB_DEVICE_CAPABILITY
SuperSpeed USB device capability.
|
static byte |
BT_SS_USB_DEVICE_CAPABILITY_SIZE
Size of a BOS descriptor.
|
static byte |
BT_USB_2_0_EXTENSION
USB 2.0 extensions.
|
static byte |
BT_USB_2_0_EXTENSION_SIZE
Size of a BOS descriptor.
|
static byte |
BT_WIRELESS_USB_DEVICE_CAPABILITY
Wireless USB device capability.
|
static int |
CAP_HAS_CAPABILITY
The
hasCapability(int) API is available. |
static int |
CAP_HAS_HID_ACCESS
The library can access HID devices without requiring user intervention.
|
static int |
CAP_HAS_HOTPLUG
Hotplug support is available on this platform.
|
static int |
CAP_SUPPORTS_DETACH_KERNEL_DRIVER
The library supports detaching of the default USB driver, using
detachKernelDriver(DeviceHandle, int) , if one is set by the OS
kernel. |
static byte |
CLASS_APPLICATION
Application class.
|
static byte |
CLASS_AUDIO
Audio class.
|
static byte |
CLASS_COMM
Communications class.
|
static byte |
CLASS_CONTENT_SECURITY
Content Security.
|
static byte |
CLASS_DATA
Data class.
|
static byte |
CLASS_DIAGNOSTIC_DEVICE
Diagnostic Device.
|
static byte |
CLASS_HID
Human Interface Device class.
|
static byte |
CLASS_HUB
Hub class.
|
static byte |
CLASS_IMAGE
Image class.
|
static byte |
CLASS_MASS_STORAGE
Mass storage class.
|
static byte |
CLASS_PER_INTERFACE
In the context of a device descriptor, this bDeviceClass value indicates
that each interface specifies its own class information and all
interfaces operate independently.
|
static byte |
CLASS_PERSONAL_HEALTHCARE
Personal Healthcare.
|
static byte |
CLASS_PHYSICAL
Physical.
|
static byte |
CLASS_PRINTER
Printer class.
|
static byte |
CLASS_PTP
Image class.
|
static byte |
CLASS_SMART_CARD
Smart Card.
|
static byte |
CLASS_VENDOR_SPEC
Class is vendor-specific.
|
static byte |
CLASS_VIDEO
Video.
|
static byte |
CLASS_WIRELESS
Wireless class.
|
static short |
CONTROL_SETUP_SIZE
The size of a control setup packet.
|
static byte |
DT_BOS
BOS descriptor.
|
static byte |
DT_BOS_MAX_SIZE
We unwrap the BOS => define its maximum size.
|
static byte |
DT_BOS_SIZE
Size of a BOS descriptor.
|
static byte |
DT_CONFIG
Configuration descriptor.
|
static byte |
DT_CONFIG_SIZE
Size of a config descriptor.
|
static byte |
DT_DEVICE
Device descriptor.
|
static byte |
DT_DEVICE_CAPABILITY
Device Capability descriptor.
|
static byte |
DT_DEVICE_CAPABILITY_SIZE
Size of a device capability descriptor.
|
static byte |
DT_DEVICE_SIZE
Size of a device descriptor.
|
static byte |
DT_ENDPOINT
Endpoint descriptor.
|
static byte |
DT_ENDPOINT_AUDIO_SIZE
Size of an endpoint descriptor with audio extension.
|
static byte |
DT_ENDPOINT_SIZE
Size of an endpoint descriptor.
|
static byte |
DT_HID
HID descriptor.
|
static byte |
DT_HUB
Hub descriptor.
|
static byte |
DT_HUB_NONVAR_SIZE
Size of a hub descriptor.
|
static byte |
DT_INTERFACE
Interface descriptor.
|
static byte |
DT_INTERFACE_SIZE
Size of an interface descriptor.
|
static byte |
DT_PHYSICAL
Physical descriptor.
|
static byte |
DT_REPORT
HID report descriptor.
|
static byte |
DT_SS_ENDPOINT_COMPANION
SuperSpeed Endpoint Companion descriptor.
|
static byte |
DT_SS_ENDPOINT_COMPANION_SIZE
Size of a SuperSpeed endpoint companion descriptor.
|
static byte |
DT_STRING
String descriptor.
|
static byte |
DT_SUPERSPEED_HUB
SuperSpeed Hub descriptor.
|
static byte |
ENDPOINT_ADDRESS_MASK
Endpoint address mask.
|
static byte |
ENDPOINT_DIR_MASK
Endpoint direction mask.
|
static byte |
ENDPOINT_IN
In: device-to-host.
|
static byte |
ENDPOINT_OUT
Out: host-to-device.
|
static int |
ERROR_ACCESS
Access denied (insufficient permissions).
|
static int |
ERROR_BUSY
Resource busy.
|
static int |
ERROR_COUNT
Total number of error codes.
|
static int |
ERROR_INTERRUPTED
System call interrupted (perhaps due to signal).
|
static int |
ERROR_INVALID_PARAM
Invalid parameter.
|
static int |
ERROR_IO
Input/output error.
|
static int |
ERROR_NO_DEVICE
No such device (it may have been disconnected).
|
static int |
ERROR_NO_MEM
Insufficient memory.
|
static int |
ERROR_NOT_FOUND
Entity not found.
|
static int |
ERROR_NOT_SUPPORTED
Operation not supported or unimplemented on this platform.
|
static int |
ERROR_OTHER
Other error.
|
static int |
ERROR_OVERFLOW
Overflow.
|
static int |
ERROR_PIPE
Pipe error.
|
static int |
ERROR_TIMEOUT
Operation timed out.
|
static short |
FULL_SPEED_OPERATION
Full speed operation supported (12MBit/s).
|
static short |
HIGH_SPEED_OPERATION
High speed operation supported (480MBit/s).
|
static int |
HOTPLUG_ENUMERATE
Arm the callback and fire it for all matching currently attached devices.
|
static int |
HOTPLUG_EVENT_DEVICE_ARRIVED
A device has been plugged in and is ready to use.
|
static int |
HOTPLUG_EVENT_DEVICE_LEFT
A device has left and is no longer available.
|
static int |
HOTPLUG_MATCH_ANY
Match any vendorId or productId or deviceClass.
|
static int |
HOTPLUG_NO_FLAGS
Default value when not using any flags.
|
static byte |
ISO_SYNC_TYPE_ADAPTIVE
Adaptive.
|
static byte |
ISO_SYNC_TYPE_ASYNC
Asynchronous.
|
static byte |
ISO_SYNC_TYPE_MASK
The mask used to filter out sync types from attributes.
|
static byte |
ISO_SYNC_TYPE_NONE
No synchronization.
|
static byte |
ISO_SYNC_TYPE_SYNC
Synchronous.
|
static byte |
ISO_USAGE_TYPE_DATA
Data endpoint.
|
static byte |
ISO_USAGE_TYPE_FEEDBACK
Feedback endpoint.
|
static byte |
ISO_USAGE_TYPE_IMPLICIT
Implicit feedback Data endpoint.
|
static byte |
ISO_USAGE_TYPE_MASK
The mask used to filter out usage types from attributes.
|
static int |
LOG_LEVEL_DEBUG
Debug and informational messages are printed to stdout, warnings and
errors to stderr.
|
static int |
LOG_LEVEL_ERROR
Error messages are printed to stderr.
|
static int |
LOG_LEVEL_INFO
Informational messages are printed to stdout, warning and error messages
are printed to stderr.
|
static int |
LOG_LEVEL_NONE
No messages ever printed by the library (default).
|
static int |
LOG_LEVEL_WARNING
Warning and error messages are printed to stderr.
|
static short |
LOW_SPEED_OPERATION
Low speed operation supported (1.5MBit/s).
|
static int |
OPTION_LOG_LEVEL
Set the log message verbosity.
|
static int |
OPTION_USE_USBDK
Use the UsbDk backend for a specific context, if available.
|
static byte |
RECIPIENT_DEVICE
Device.
|
static byte |
RECIPIENT_ENDPOINT
Endpoint.
|
static byte |
RECIPIENT_INTERFACE
Interface.
|
static byte |
RECIPIENT_OTHER
Other.
|
static byte |
REQUEST_CLEAR_FEATURE
Clear or disable a specific feature.
|
static byte |
REQUEST_GET_CONFIGURATION
Get the current device configuration value.
|
static byte |
REQUEST_GET_DESCRIPTOR
Set device address for all future accesses.
|
static byte |
REQUEST_GET_INTERFACE
Return the selected alternate setting for the specified interface.
|
static byte |
REQUEST_GET_STATUS
Request status of the specific recipient.
|
static byte |
REQUEST_SET_ADDRESS
Set device address for all future accesses.
|
static byte |
REQUEST_SET_CONFIGURATION
Get the current device configuration value.
|
static byte |
REQUEST_SET_DESCRIPTOR
Set device address for all future accesses.
|
static byte |
REQUEST_SET_FEATURE
Set or enable a specific feature.
|
static byte |
REQUEST_SET_INTERFACE
Select an alternate interface for the specified interface.
|
static byte |
REQUEST_SET_SEL
Sets both the U1 and U2 Exit Latency.
|
static byte |
REQUEST_SYNCH_FRAME
Set then report an endpoint's synchronization frame.
|
static byte |
REQUEST_TYPE_CLASS
Class.
|
static byte |
REQUEST_TYPE_RESERVED
Reserved.
|
static byte |
REQUEST_TYPE_STANDARD
Standard.
|
static byte |
REQUEST_TYPE_VENDOR
Vendor.
|
static byte |
SET_ISOCH_DELAY
Delay from the time a host transmits a packet to the time it is received
by the device.
|
static int |
SPEED_FULL
The device is operating at full speed (12MBit/s).
|
static int |
SPEED_HIGH
The device is operating at high speed (480MBit/s).
|
static int |
SPEED_LOW
The device is operating at low speed (1.5MBit/s).
|
static int |
SPEED_SUPER
The device is operating at super speed (5000MBit/s).
|
static int |
SPEED_SUPER_PLUS
The device is operating at super speed plus (10000MBit/s).
|
static int |
SPEED_UNKNOWN
The OS doesn't report or know the device speed.
|
static int |
SUCCESS
Success (no error).
|
static short |
SUPER_SPEED_OPERATION
Superspeed operation supported (5000MBit/s).
|
static byte |
TRANSFER_ADD_ZERO_PACKET
Terminate transfers that are a multiple of the endpoint's wMaxPacketSize
with an extra zero length packet.
|
static int |
TRANSFER_CANCELLED
Transfer was cancelled.
|
static int |
TRANSFER_COMPLETED
Transfer completed without error.
|
static int |
TRANSFER_ERROR
Transfer failed.
|
static byte |
TRANSFER_FREE_BUFFER
Automatically free transfer buffer during
freeTransfer(Transfer)
Please note that this flag (which is originally 2) is effectively a no-op
(set to zero) here in the Java wrapper, since the ByteBuffer that acts as
a buffer for transfers is allocated by the JVM and is subject to garbage
collection like any other object at some point. |
static byte |
TRANSFER_FREE_TRANSFER
Automatically call
freeTransfer(Transfer) after callback
returns. |
static int |
TRANSFER_NO_DEVICE
Device was disconnected.
|
static int |
TRANSFER_OVERFLOW
Device sent more data than requested.
|
static byte |
TRANSFER_SHORT_NOT_OK
Report short frames as errors.
|
static int |
TRANSFER_STALL
For bulk/interrupt endpoints: halt condition detected (endpoint stalled).
|
static int |
TRANSFER_TIMED_OUT
Transfer timed out.
|
static byte |
TRANSFER_TYPE_BULK
Bulk endpoint.
|
static byte |
TRANSFER_TYPE_BULK_STREAM
Stream endpoint.
|
static byte |
TRANSFER_TYPE_CONTROL
Control endpoint.
|
static byte |
TRANSFER_TYPE_INTERRUPT
Interrupt endpoint.
|
static byte |
TRANSFER_TYPE_ISOCHRONOUS
Isochronous endpoint.
|
static byte |
TRANSFER_TYPE_MASK
Transfer type mask.
|
Modifier and Type | Method and Description |
---|---|
static int |
allocStreams(DeviceHandle handle,
int numStreams,
byte[] endpoints)
Allocate up to numStreams USB bulk streams on the specified endpoints.
|
static Transfer |
allocTransfer()
Allocate a libusb transfer without support for isochronous transfers.
|
static Transfer |
allocTransfer(int isoPackets)
Allocate a libusb transfer with a specified number of isochronous packet
descriptors.
|
static int |
attachKernelDriver(DeviceHandle handle,
int interfaceNumber)
Re-attach an interface's kernel driver, which was previously detached
using
detachKernelDriver(DeviceHandle, int) . |
static int |
bulkTransfer(DeviceHandle handle,
byte endpoint,
ByteBuffer data,
IntBuffer transferred,
long timeout)
Perform a USB bulk transfer.
|
static int |
cancelTransfer(Transfer transfer)
Asynchronously cancel a previously submitted transfer.
|
static int |
claimInterface(DeviceHandle handle,
int iface)
Claim an interface on a given device handle.
|
static int |
clearHalt(DeviceHandle handle,
byte endpoint)
Clear the halt/stall condition for an endpoint.
|
static void |
close(DeviceHandle handle)
Close a device handle.
|
static int |
controlTransfer(DeviceHandle handle,
byte bmRequestType,
byte bRequest,
short wValue,
short wIndex,
ByteBuffer data,
long timeout)
Perform a USB control transfer.
|
static ByteBuffer |
controlTransferGetData(Transfer transfer)
Get the data section of a control transfer.
|
static ControlSetup |
controlTransferGetSetup(Transfer transfer)
Get the control setup packet of a control transfer.
|
static short |
cpuToLe16(short x)
Convert a 16-bit value from host-endian to little-endian format.
|
static int |
detachKernelDriver(DeviceHandle handle,
int interfaceNumber)
Detach a kernel driver from an interface.
|
static ByteBuffer |
devMemAlloc(DeviceHandle handle,
int length)
Attempts to allocate a block of persistent DMA memory suitable for transfers against the given device.
|
static int |
devMemFree(DeviceHandle handle,
ByteBuffer buffer,
int size)
Free device memory allocated with
devMemAlloc(DeviceHandle, int) . |
static String |
errorName(int errorCode)
Returns a string with the ASCII name of a libusb error or transfer status
code.
|
static int |
eventHandlerActive(Context context)
Determine if an active thread is handling events (i.e.
|
static int |
eventHandlingOk(Context context)
Determine if it is still OK for this thread to be doing event handling.
|
static void |
exit(Context context)
Deinitialize libusb.
|
static void |
fillBulkStreamTransfer(Transfer transfer,
DeviceHandle handle,
byte endpoint,
int streamId,
ByteBuffer buffer,
TransferCallback callback,
Object userData,
long timeout)
Helper function to populate the required
Transfer fields
for a bulk transfer using bulk streams. |
static void |
fillBulkTransfer(Transfer transfer,
DeviceHandle handle,
byte endpoint,
ByteBuffer buffer,
TransferCallback callback,
Object userData,
long timeout)
Helper function to populate the required
Transfer fields for a
bulk transfer. |
static void |
fillControlSetup(ByteBuffer buffer,
byte bmRequestType,
byte bRequest,
short wValue,
short wIndex,
short wLength)
Helper function to populate the setup packet (first 8 bytes of the data
buffer) for a control transfer.
|
static void |
fillControlTransfer(Transfer transfer,
DeviceHandle handle,
ByteBuffer buffer,
TransferCallback callback,
Object userData,
long timeout)
Helper function to populate the required
Transfer fields for a
control transfer. |
static void |
fillInterruptTransfer(Transfer transfer,
DeviceHandle handle,
byte endpoint,
ByteBuffer buffer,
TransferCallback callback,
Object userData,
long timeout)
Helper function to populate the required
Transfer fields for an
interrupt transfer. |
static void |
fillIsoTransfer(Transfer transfer,
DeviceHandle handle,
byte endpoint,
ByteBuffer buffer,
int numIsoPackets,
TransferCallback callback,
Object userData,
long timeout)
Helper function to populate the required
Transfer fields for an
isochronous transfer. |
static void |
freeBosDescriptor(BosDescriptor descriptor)
Free a BOS descriptor obtained from
getBosDescriptor(DeviceHandle, BosDescriptor) . |
static void |
freeConfigDescriptor(ConfigDescriptor descriptor)
Free a configuration descriptor obtained from
getConfigDescriptor(Device, byte, ConfigDescriptor) or
getActiveConfigDescriptor(Device, ConfigDescriptor) . |
static void |
freeContainerIdDescriptor(ContainerIdDescriptor containerIdDescriptor)
Free a Container ID descriptor obtained from
getContainerIdDescriptor(Context, BosDevCapabilityDescriptor,
ContainerIdDescriptor) . |
static void |
freeDeviceList(DeviceList list,
boolean unrefDevices)
Frees a list of devices previously discovered using
getDeviceList(Context, DeviceList) . |
static void |
freePollfds(Pollfds pollfds)
Free a list of
Pollfd structures. |
static void |
freeSsEndpointCompanionDescriptor(SsEndpointCompanionDescriptor companionDescriptor)
Free a superspeed endpoint companion descriptor obtained from
getSsEndpointCompanionDescriptor(Context, EndpointDescriptor,
SsEndpointCompanionDescriptor) . |
static void |
freeSsUsbDeviceCapabilityDescriptor(SsUsbDeviceCapabilityDescriptor ssUsbDeviceCapabilityDescriptor)
Free a SuperSpeed USB Device Capability descriptor obtained from
getSsUsbDeviceCapabilityDescriptor(Context,
BosDevCapabilityDescriptor, SsUsbDeviceCapabilityDescriptor) . |
static int |
freeStreams(DeviceHandle handle,
byte[] endpoints)
Free USB bulk streams allocated with LibUsb.allocStreams().
|
static void |
freeTransfer(Transfer transfer)
Free a transfer structure.
|
static void |
freeUsb20ExtensionDescriptor(Usb20ExtensionDescriptor extensionDescriptor)
Free a USB 2.0 Extension descriptor obtained from
getUsb20ExtensionDescriptor(Context, BosDevCapabilityDescriptor,
Usb20ExtensionDescriptor) . |
static int |
getActiveConfigDescriptor(Device device,
ConfigDescriptor descriptor)
Get the USB configuration descriptor for the currently active
configuration.
|
static int |
getApiVersion()
Returns the API version of the underlying libusb library.
|
static int |
getBosDescriptor(DeviceHandle handle,
BosDescriptor descriptor)
Get a Binary Object Store (BOS) descriptor.
|
static int |
getBusNumber(Device device)
Get the number of the bus that a device is connected to.
|
static int |
getConfigDescriptor(Device device,
byte index,
ConfigDescriptor descriptor)
Get a USB configuration descriptor based on its index.
|
static int |
getConfigDescriptorByValue(Device device,
byte value,
ConfigDescriptor descriptor)
Get a USB configuration descriptor with a specific bConfigurationValue.
|
static int |
getConfiguration(DeviceHandle handle,
IntBuffer config)
Determine the bConfigurationValue of the currently active configuration.
|
static int |
getContainerIdDescriptor(Context context,
BosDevCapabilityDescriptor devCapDescriptor,
ContainerIdDescriptor containerIdDescriptor)
Get a Container ID descriptor.
|
static int |
getDescriptor(DeviceHandle handle,
byte type,
byte index,
ByteBuffer data)
Retrieve a descriptor from the default control pipe.
|
static Device |
getDevice(DeviceHandle handle)
Get the underlying device for a handle.
|
static int |
getDeviceAddress(Device device)
Get the address of the device on the bus it is connected to.
|
static int |
getDeviceDescriptor(Device device,
DeviceDescriptor descriptor)
Get the USB device descriptor for a given device.
|
static int |
getDeviceList(Context context,
DeviceList list)
Returns a list of USB devices currently attached to the system.
|
static int |
getDeviceSpeed(Device device)
Get the negotiated connection speed for a device.
|
static ByteBuffer |
getIsoPacketBuffer(Transfer transfer,
int packet)
Convenience function to locate the position of an isochronous packet
within the buffer of an isochronous transfer.
|
static ByteBuffer |
getIsoPacketBufferSimple(Transfer transfer,
int packet)
Convenience function to locate the position of an isochronous packet
within the buffer of an isochronous transfer, for transfers where each
packet is of identical size.
|
static int |
getMaxIsoPacketSize(Device device,
byte endpoint)
Calculate the maximum packet size which a specific endpoint is capable
sending or receiving in the duration of 1 microframe.
|
static int |
getMaxPacketSize(Device device,
byte endpoint)
Convenience function to retrieve the wMaxPacketSize value for a
particular endpoint in the active device configuration.
|
static int |
getNextTimeout(Context context,
LongBuffer timeout)
Determine the next internal timeout that libusb needs to handle.
|
static Device |
getParent(Device device)
Get the the parent from the specified device [EXPERIMENTAL].
|
static Pollfds |
getPollfds(Context context)
Retrieve a list of file descriptors that should be polled by your main loop as libusb event sources.
|
static int |
getPortNumber(Device device)
Get the number of the port that a device is connected to.
|
static int |
getPortNumbers(Device device,
ByteBuffer path)
Get the list of all port numbers from root for the specified device.
|
static int |
getPortPath(Context context,
Device device,
ByteBuffer path)
Deprecated.
Please use
getPortNumbers(Device, ByteBuffer)
instead. |
static int |
getSsEndpointCompanionDescriptor(Context context,
EndpointDescriptor endpointDescriptor,
SsEndpointCompanionDescriptor companionDescriptor)
Get an endpoints superspeed endpoint companion descriptor (if any).
|
static int |
getSsUsbDeviceCapabilityDescriptor(Context context,
BosDevCapabilityDescriptor devCapDescriptor,
SsUsbDeviceCapabilityDescriptor ssUsbDeviceCapabilityDescriptor)
Get a SuperSpeed USB Device Capability descriptor.
|
static String |
getStringDescriptor(DeviceHandle handle,
byte index)
A simple wrapper around
getStringDescriptorAscii(DeviceHandle, byte, StringBuffer) . |
static int |
getStringDescriptor(DeviceHandle handle,
byte index,
short langId,
ByteBuffer data)
Retrieve a descriptor from a device.
|
static int |
getStringDescriptorAscii(DeviceHandle handle,
byte index,
StringBuffer string)
Retrieve a string descriptor in C style ASCII.
|
static int |
getUsb20ExtensionDescriptor(Context context,
BosDevCapabilityDescriptor devCapDescriptor,
Usb20ExtensionDescriptor extensionDescriptor)
Get an USB 2.0 Extension descriptor.
|
static Version |
getVersion()
Returns the version of the libusb runtime.
|
static int |
handleEvents(Context context)
Handle any pending events in blocking mode.
|
static int |
handleEventsCompleted(Context context,
IntBuffer completed)
Handle any pending events in blocking mode.
|
static int |
handleEventsLocked(Context context,
long timeout)
Handle any pending events by polling file descriptors, without checking
if any other threads are already doing so.
|
static int |
handleEventsTimeout(Context context,
long timeout)
Handle any pending events.
|
static int |
handleEventsTimeoutCompleted(Context context,
long timeout,
IntBuffer completed)
Handle any pending events.
|
static boolean |
hasCapability(int capability)
Check at runtime if the loaded library has a given capability.
|
static void |
hotplugDeregisterCallback(Context context,
HotplugCallbackHandle callbackHandle)
Deregisters a hotplug callback.
|
static int |
hotplugRegisterCallback(Context context,
int events,
int flags,
int vendorId,
int productId,
int deviceClass,
HotplugCallback callback,
Object userData,
HotplugCallbackHandle callbackHandle)
Register a hotplug callback function.
|
static int |
init(Context context)
Initialize libusb.
|
static void |
interruptEventHandler(Context context)
Interrupt any active thread that is handling events.
|
static int |
interruptTransfer(DeviceHandle handle,
byte endpoint,
ByteBuffer data,
IntBuffer transferred,
long timeout)
Perform a USB interrupt transfer.
|
static int |
kernelDriverActive(DeviceHandle handle,
int interfaceNumber)
Determine if a kernel driver is active on an interface.
|
static short |
le16ToCpu(short x)
Convert a 16-bit value from little-endian to host-endian format.
|
static void |
lockEvents(Context context)
Acquire the event handling lock, blocking until successful acquisition if
it is contended.
|
static void |
lockEventWaiters(Context context)
Acquire the event waiters lock.
|
static int |
open(Device device,
DeviceHandle handle)
Open a device and obtain a device handle.
|
static DeviceHandle |
openDeviceWithVidPid(Context context,
short vendorId,
short productId)
Convenience function for finding a device with a particular
idVendor/idProduct combination.
|
static int |
pollfdsHandleTimeouts(Context context)
Determines whether your application must apply special timing
considerations when monitoring libusb's file descriptors.
|
static Device |
refDevice(Device device)
Increment the reference count of a device.
|
static int |
releaseInterface(DeviceHandle handle,
int iface)
Release an interface previously claimed with
claimInterface(DeviceHandle, int) . |
static int |
resetDevice(DeviceHandle handle)
Perform a USB port reset to reinitialize a device.
|
static int |
setAutoDetachKernelDriver(DeviceHandle handle,
boolean enable)
Enable/disable libusb's automatic kernel driver detachment.
|
static int |
setConfiguration(DeviceHandle handle,
int config)
Set the active configuration for a device.
|
static void |
setDebug(Context context,
int level)
Deprecated.
Use
setOption(Context, int, int) instead using the OPTION_LOG_LEVEL option. |
static int |
setInterfaceAltSetting(DeviceHandle handle,
int interfaceNumber,
int alternateSetting)
Activate an alternate setting for an interface.
|
static void |
setIsoPacketLengths(Transfer transfer,
int length)
Convenience function to set the length of all packets in an isochronous
transfer, based on the
Transfer.numIsoPackets() field. |
static int |
setLocale(String locale)
Set the language, and only the language, not the encoding! used for
translatable libusb messages.
|
static int |
setOption(Context context,
int option)
Set an option in the library.
|
static int |
setOption(Context context,
int option,
int value)
Set an option in the library.
|
static void |
setPollfdNotifiers(Context context,
PollfdListener listener,
Object userData)
Register notification functions for file descriptor additions/removals.
|
static String |
strError(int errcode)
Returns a string with a short description of the given error code, this
description is intended for displaying to the end user and will be in the
language set by
setLocale(String) . |
static int |
submitTransfer(Transfer transfer)
Submit a transfer.
|
static int |
tryLockEvents(Context context)
Attempt to acquire the event handling lock.
|
static void |
unlockEvents(Context context)
Release the lock previously acquired with
tryLockEvents(Context)
or lockEvents(Context) . |
static void |
unlockEventWaiters(Context context)
Release the event waiters lock.
|
static void |
unrefDevice(Device device)
Decrement the reference count of a device.
|
static int |
waitForEvent(Context context,
long timeout)
Wait for another thread to signal completion of an event.
|
public static final int LOG_LEVEL_NONE
public static final int LOG_LEVEL_ERROR
public static final int LOG_LEVEL_WARNING
public static final int LOG_LEVEL_INFO
public static final int LOG_LEVEL_DEBUG
public static final int OPTION_LOG_LEVEL
LOG_LEVEL_NONE
, which means no messages are ever
printed. If you choose to increase the message verbosity level, ensure
that your application does not close the stderr file descriptor.
You are advised to use level LOG_LEVEL_WARNING
. libusb is conservative
with its message logging and most of the time, will only log messages that
explain error conditions and other oddities. This will help you debug
your software.
If the LIBUSB_DEBUG environment variable was set when libusb was
initialized, this function does nothing: the message verbosity is fixed
to the value in the environment variable.
If libusb was compiled without any message logging, this function does
nothing: you'll never get any messages.
If libusb was compiled with verbose debug message logging, this function
does nothing: you'll always get messages from all levels.public static final int OPTION_USE_USBDK
init(Context)
, otherwise
unspecified behavior may occur.
Only valid on Windows.public static final int SUCCESS
public static final int ERROR_IO
public static final int ERROR_INVALID_PARAM
public static final int ERROR_ACCESS
public static final int ERROR_NO_DEVICE
public static final int ERROR_NOT_FOUND
public static final int ERROR_BUSY
public static final int ERROR_TIMEOUT
public static final int ERROR_OVERFLOW
public static final int ERROR_PIPE
public static final int ERROR_INTERRUPTED
public static final int ERROR_NO_MEM
public static final int ERROR_NOT_SUPPORTED
public static final int ERROR_OTHER
public static final int ERROR_COUNT
public static final int SPEED_UNKNOWN
public static final int SPEED_LOW
public static final int SPEED_FULL
public static final int SPEED_HIGH
public static final int SPEED_SUPER
public static final int SPEED_SUPER_PLUS
public static final short LOW_SPEED_OPERATION
public static final short FULL_SPEED_OPERATION
public static final short HIGH_SPEED_OPERATION
public static final short SUPER_SPEED_OPERATION
public static final int BM_LPM_SUPPORT
public static final byte BM_LTM_SUPPORT
public static final byte BT_WIRELESS_USB_DEVICE_CAPABILITY
public static final byte BT_USB_2_0_EXTENSION
public static final byte BT_SS_USB_DEVICE_CAPABILITY
public static final byte BT_CONTAINER_ID
public static final byte REQUEST_GET_STATUS
public static final byte REQUEST_CLEAR_FEATURE
public static final byte REQUEST_SET_FEATURE
public static final byte REQUEST_SET_ADDRESS
public static final byte REQUEST_GET_DESCRIPTOR
public static final byte REQUEST_SET_DESCRIPTOR
public static final byte REQUEST_GET_CONFIGURATION
public static final byte REQUEST_SET_CONFIGURATION
public static final byte REQUEST_GET_INTERFACE
public static final byte REQUEST_SET_INTERFACE
public static final byte REQUEST_SYNCH_FRAME
public static final byte REQUEST_SET_SEL
public static final byte SET_ISOCH_DELAY
public static final byte REQUEST_TYPE_STANDARD
public static final byte REQUEST_TYPE_CLASS
public static final byte REQUEST_TYPE_VENDOR
public static final byte REQUEST_TYPE_RESERVED
public static final byte RECIPIENT_DEVICE
public static final byte RECIPIENT_INTERFACE
public static final byte RECIPIENT_ENDPOINT
public static final byte RECIPIENT_OTHER
public static final int CAP_HAS_CAPABILITY
hasCapability(int)
API is available.public static final int CAP_HAS_HOTPLUG
public static final int CAP_HAS_HID_ACCESS
detachKernelDriver(DeviceHandle, int)
.public static final int CAP_SUPPORTS_DETACH_KERNEL_DRIVER
detachKernelDriver(DeviceHandle, int)
, if one is set by the OS
kernel.public static final short CONTROL_SETUP_SIZE
public static final byte CLASS_PER_INTERFACE
public static final byte CLASS_AUDIO
public static final byte CLASS_COMM
public static final byte CLASS_HID
public static final byte CLASS_PHYSICAL
public static final byte CLASS_PTP
public static final byte CLASS_IMAGE
public static final byte CLASS_PRINTER
public static final byte CLASS_MASS_STORAGE
public static final byte CLASS_HUB
public static final byte CLASS_DATA
public static final byte CLASS_SMART_CARD
public static final byte CLASS_CONTENT_SECURITY
public static final byte CLASS_VIDEO
public static final byte CLASS_PERSONAL_HEALTHCARE
public static final byte CLASS_DIAGNOSTIC_DEVICE
public static final byte CLASS_WIRELESS
public static final byte CLASS_APPLICATION
public static final byte CLASS_VENDOR_SPEC
public static final byte DT_DEVICE
DeviceDescriptor
,
Constant Field Valuespublic static final byte DT_CONFIG
ConfigDescriptor
,
Constant Field Valuespublic static final byte DT_STRING
public static final byte DT_INTERFACE
InterfaceDescriptor
,
Constant Field Valuespublic static final byte DT_ENDPOINT
EndpointDescriptor
,
Constant Field Valuespublic static final byte DT_BOS
BosDescriptor
,
Constant Field Valuespublic static final byte DT_DEVICE_CAPABILITY
BosDevCapabilityDescriptor
,
Constant Field Valuespublic static final byte DT_HID
public static final byte DT_REPORT
public static final byte DT_PHYSICAL
public static final byte DT_HUB
public static final byte DT_SUPERSPEED_HUB
public static final byte DT_SS_ENDPOINT_COMPANION
public static final byte DT_DEVICE_SIZE
public static final byte DT_CONFIG_SIZE
public static final byte DT_INTERFACE_SIZE
public static final byte DT_ENDPOINT_SIZE
public static final byte DT_ENDPOINT_AUDIO_SIZE
public static final byte DT_HUB_NONVAR_SIZE
public static final byte DT_SS_ENDPOINT_COMPANION_SIZE
public static final byte DT_BOS_SIZE
public static final byte DT_DEVICE_CAPABILITY_SIZE
public static final byte BT_USB_2_0_EXTENSION_SIZE
public static final byte BT_SS_USB_DEVICE_CAPABILITY_SIZE
public static final byte BT_CONTAINER_ID_SIZE
public static final byte DT_BOS_MAX_SIZE
public static final byte ENDPOINT_IN
public static final byte ENDPOINT_OUT
public static final byte ENDPOINT_ADDRESS_MASK
public static final byte ENDPOINT_DIR_MASK
public static final byte TRANSFER_TYPE_MASK
public static final byte TRANSFER_TYPE_CONTROL
public static final byte TRANSFER_TYPE_ISOCHRONOUS
public static final byte TRANSFER_TYPE_BULK
public static final byte TRANSFER_TYPE_INTERRUPT
public static final byte TRANSFER_TYPE_BULK_STREAM
public static final byte ISO_SYNC_TYPE_MASK
public static final byte ISO_SYNC_TYPE_NONE
public static final byte ISO_SYNC_TYPE_ASYNC
public static final byte ISO_SYNC_TYPE_ADAPTIVE
public static final byte ISO_SYNC_TYPE_SYNC
public static final byte ISO_USAGE_TYPE_MASK
public static final byte ISO_USAGE_TYPE_DATA
public static final byte ISO_USAGE_TYPE_FEEDBACK
public static final byte ISO_USAGE_TYPE_IMPLICIT
public static final byte TRANSFER_SHORT_NOT_OK
public static final byte TRANSFER_FREE_BUFFER
freeTransfer(Transfer)
Please note that this flag (which is originally 2) is effectively a no-op
(set to zero) here in the Java wrapper, since the ByteBuffer that acts as
a buffer for transfers is allocated by the JVM and is subject to garbage
collection like any other object at some point. Nulling the reference is
the only needed action to take, and it is already done by the
TRANSFER_FREE_TRANSFER flag.public static final byte TRANSFER_FREE_TRANSFER
freeTransfer(Transfer)
after callback
returns.
If this flag is set, it is illegal to call
freeTransfer(Transfer)
from your transfer callback, as this will
result in a double-free when this flag is acted upon.public static final byte TRANSFER_ADD_ZERO_PACKET
ERROR_NOT_SUPPORTED
for
every transfer where this flag is set.public static final int TRANSFER_COMPLETED
public static final int TRANSFER_ERROR
public static final int TRANSFER_TIMED_OUT
public static final int TRANSFER_CANCELLED
public static final int TRANSFER_STALL
public static final int TRANSFER_NO_DEVICE
public static final int TRANSFER_OVERFLOW
public static final int HOTPLUG_NO_FLAGS
public static final int HOTPLUG_ENUMERATE
public static final int HOTPLUG_EVENT_DEVICE_ARRIVED
public static final int HOTPLUG_EVENT_DEVICE_LEFT
close(DeviceHandle)
on
any handle associated with a disconnected device.
It is safe to call getDeviceDescriptor(Device, DeviceDescriptor)
on a device that has left.public static final int HOTPLUG_MATCH_ANY
public static int getApiVersion()
public static int init(Context context)
Context
, a default
context will be created. If there was already a default context, it will
be reused (and nothing will be initialized/reinitialized).context
- Optional output location for context pointer. Null to use
default context. Only valid on return code 0.public static void exit(Context context)
context
- The Context
to deinitialize, or NULL for the default
context.public static void setDebug(Context context, int level)
setOption(Context, int, int)
instead using the OPTION_LOG_LEVEL
option.LOG_LEVEL_NONE
, which means no messages are
ever printed. If you choose to increase the message verbosity level,
ensure that your application does not close the stdout/stderr file
descriptors.
You are advised to use level LOG_LEVEL_WARNING
. libusb is
conservative with its message logging and most of the time, will only log
messages that explain error conditions and other oddities. This will help
you debug your software.
If the LOG_LEVEL_DEBUG
environment variable was set when libusb
was initialized, this function does nothing: the message verbosity is
fixed to the value in the environment variable.
If libusb was compiled without any message logging, this function does
nothing: you'll never get any messages.
If libusb was compiled with verbose debug message logging, this function
does nothing: you'll always get messages from all levels.context
- The Context
to operate on, or NULL for the default
context.level
- The log level to set.public static int setOption(Context context, int option)
context
- The Context
on which to operate.option
- Which option to set.SUCCESS
on success, ERROR_INVALID_PARAM
if the option or arguments are invalid,
ERROR_NOT_SUPPORTED
if the option is valid but not supported on this platform.public static int setOption(Context context, int option, int value)
context
- The Context
on which to operate.option
- Which option to set.value
- Required argument for the specified option.SUCCESS
on success, ERROR_INVALID_PARAM
if the option or arguments are invalid,
ERROR_NOT_SUPPORTED
if the option is valid but not supported on this platform.public static Version getVersion()
public static int getDeviceList(Context context, DeviceList list)
freeDeviceList(DeviceList, boolean)
. Note that
freeDeviceList(DeviceList, boolean)
can unref all the devices
for you. Be careful not to unreference a device you are about to open
until after you have opened it.context
- The context to operate on, or NULL for the default context.list
- Output location for a list of devices. Must be later freed
with freeDeviceList(DeviceList, boolean)
.public static void freeDeviceList(DeviceList list, boolean unrefDevices)
getDeviceList(Context, DeviceList)
.
If the unref_devices parameter is set, the reference count of each device
in the list is decremented by 1.list
- The list to free.unrefDevices
- Whether to unref the devices in the list.public static int getBusNumber(Device device)
device
- A device.public static int getPortNumber(Device device)
device
- A devicepublic static int getPortNumbers(Device device, ByteBuffer path)
device
- A device.path
- The array that should contain the port numbers. As per the USB
3.0 specs, the current maximum limit for the depth is 7.ERROR_OVERFLOW
if the
array is too small@Deprecated public static int getPortPath(Context context, Device device, ByteBuffer path)
getPortNumbers(Device, ByteBuffer)
instead.context
- The context.device
- A device.path
- The array that should contain the port numbers. As per the USB
3.0 specs, the current maximum limit for the depth is 7.ERROR_OVERFLOW
if the
array is too smallpublic static Device getParent(Device device)
unrefDevice(Device)
directly on the returned Device.device
- A devicegetDeviceList(Context, DeviceList)
before calling this
function and make sure that you only access the parent before
issuing freeDeviceList(DeviceList, boolean)
. The reason
is that libusb currently does not maintain a permanent list of
device instances, and therefore can only guarantee that parents
are fully instantiated within a
getDeviceList(Context, DeviceList)
-
freeDeviceList(DeviceList, boolean)
block.public static int getDeviceAddress(Device device)
device
- A device.public static int getDeviceSpeed(Device device)
device
- A device.SPEED_UNKNOWN
means that the OS
doesn't know or doesn't support returning the negotiated speed.public static int getMaxPacketSize(Device device, byte endpoint)
getMaxIsoPacketSize(Device, byte)
instead.device
- A device.endpoint
- Address of the endpoint in question.ERROR_NOT_FOUND
if the endpoint
does not exist ERROR_OTHER
on other failurepublic static int getMaxIsoPacketSize(Device device, byte endpoint)
setIsoPacketLengths(Transfer, int)
in order to set the length
field of every isochronous packet in a transfer.device
- A device.endpoint
- Address of the endpoint in question.ERROR_NOT_FOUND
if the endpoint does not exist
ERROR_OTHER
on other failure.public static Device refDevice(Device device)
device
- The device to reference.public static void unrefDevice(Device device)
device
- the device to unreference.public static int open(Device device, DeviceHandle handle)
getDevice(DeviceHandle)
. This reference
is removed during close(DeviceHandle)
.
This is a non-blocking function; no requests are sent over the bus.device
- The device to open.handle
- Output location for the returned device handle pointer. Only
populated when the return code is 0.ERROR_NO_MEM
on memory allocation failure,
ERROR_ACCESS
if the user has insufficient permissions,
ERROR_NO_DEVICE
if the device has been disconnected,
another error on other failurepublic static DeviceHandle openDeviceWithVidPid(Context context, short vendorId, short productId)
getDeviceList(Context, DeviceList)
and worrying about
traversing/freeing the list.
This function has limitations and is hence not intended for use in real
applications: if multiple devices have the same IDs it will only give you
the first one, etc.context
- The context to operate on, or NULL for the default context.vendorId
- The idVendor value to search for.productId
- The idProduct value to search for.public static void close(DeviceHandle handle)
open(Device, DeviceHandle)
on the given device.
This is a non-blocking function; no requests are sent over the bus.handle
- The handle to close.public static Device getDevice(DeviceHandle handle)
unrefDevice(Device)
directly on the returned Device.handle
- a device handle.public static int getConfiguration(DeviceHandle handle, IntBuffer config)
handle
- a device handle.config
- output location for the bConfigurationValue of the active
configuration (only valid for return code 0)ERROR_NO_DEVICE
if the device has been
disconnected another error code on other failurepublic static int setConfiguration(DeviceHandle handle, int config)
releaseInterface(DeviceHandle, int)
first. You cannot
change/reset configuration if other applications or drivers have claimed
interfaces.
A configuration value of -1 will put the device in unconfigured state.
The USB specifications state that a configuration value of 0 does this,
however buggy devices exist which actually have a configuration 0.
You should always use this function rather than formulating your own
SET_CONFIGURATION control request. This is because the underlying
operating system needs to know when such changes happen.
This is a blocking function.handle
- a device handle.config
- the bConfigurationValue of the configuration you wish to
activate, or -1 if you wish to put the device in unconfigured
stateERROR_NOT_FOUND
if the requested
configuration does not exist, ERROR_BUSY
if interfaces
are currently claimed, ERROR_NO_DEVICE
if the device has
been disconnected, another error code on other failurepublic static int claimInterface(DeviceHandle handle, int iface)
handle
- A device handle.iface
- The bInterfaceNumber of the interface you wish to claim.ERROR_NOT_FOUND
if the requested interface
does not exist, ERROR_BUSY
if another program or driver
has claimed the interface, ERROR_NO_DEVICE
if the device
has been disconnected, another error code on other failurepublic static int releaseInterface(DeviceHandle handle, int iface)
claimInterface(DeviceHandle, int)
.
You should release all claimed interfaces before closing a device handle.
This is a blocking function. A SET_INTERFACE control request will be sent
to the device, resetting interface state to the first alternate setting.handle
- a device handle.iface
- The bInterfaceNumber of the previously-claimed interfaceERROR_NOT_FOUND
if the interface was not
claimed, ERROR_NO_DEVICE
if the device has been
disconnected, another ERROR code on other failurepublic static int setInterfaceAltSetting(DeviceHandle handle, int interfaceNumber, int alternateSetting)
claimInterface(DeviceHandle, int)
.
You should always use this function rather than formulating your own
SET_INTERFACE control request. This is because the underlying operating
system needs to know when such changes happen.
This is a blocking function.handle
- A device handle.interfaceNumber
- The bInterfaceNumber of the previously-claimed interfacealternateSetting
- The bAlternateSetting of the alternate setting to activateERROR_NOT_FOUND
if the interface was not
claimed, or the requested alternate setting does not exist
ERROR_NO_DEVICE
if the device has been disconnected,
another ERROR code on other failurepublic static int clearHalt(DeviceHandle handle, byte endpoint)
handle
- A device handle.endpoint
- The endpoint to clear halt statusERROR_NOT_FOUND
if the endpoint does not
exist, ERROR_NO_DEVICE
if the device has been
disconnected, another ERROR code on other failure.public static int resetDevice(DeviceHandle handle)
ERROR_NOT_FOUND
indicates when this is the case.
This is a blocking function which usually incurs a noticeable delay.handle
- a handle of the device to resetERROR_NOT_FOUND
if re-enumeration is
required, or if the device has been disconnected another ERROR
code on other failurepublic static int allocStreams(DeviceHandle handle, int numStreams, byte[] endpoints)
handle
- a device handlenumStreams
- number of streams to try to allocateendpoints
- array of endpoints to allocate streams onpublic static int freeStreams(DeviceHandle handle, byte[] endpoints)
handle
- a device handleendpoints
- array of endpoints to allocate streams onpublic static ByteBuffer devMemAlloc(DeviceHandle handle, int length)
Transfer
against this device. Using this memory instead of regular memory means that the host controller can use DMA
directly into the buffer to increase performance, and also that transfers can no longer fail due to kernel
memory fragmentation.
Note that this means you should not modify this memory (or even data on the same cache lines) when a transfer
is in progress, although it is legal to have several transfers going on within the same memory block.
Will return NULL on failure. Many systems do not support such zerocopy and will always return NULL. Memory
allocated with this function must be freed with devMemFree(DeviceHandle, ByteBuffer, int)
.
Specifically, this means that the flag TRANSFER_FREE_BUFFER
cannot be used to free memory
allocated with this function.handle
- A device handle.length
- Size of desired data buffer.public static int devMemFree(DeviceHandle handle, ByteBuffer buffer, int size)
devMemAlloc(DeviceHandle, int)
.handle
- A device handle.buffer
- The previously allocated memory.size
- The size of the previously allocated memory.SUCCESS
, or a LIBUSB_ERROR code on failure.public static int kernelDriverActive(DeviceHandle handle, int interfaceNumber)
handle
- A device handle.interfaceNumber
- The interface to check.ERROR_NO_DEVICE
if the device has been disconnected,
ERROR_NOT_SUPPORTED
on platforms where the functionality
is not available, another ERROR code on other failuredetachKernelDriver(DeviceHandle, int)
public static int detachKernelDriver(DeviceHandle handle, int interfaceNumber)
ERROR_NOT_FOUND
.handle
- a device handleinterfaceNumber
- the interface to detach the driver fromERROR_NOT_FOUND
if no kernel driver was
active, ERROR_INVALID_PARAM
if the interface does not
exist, ERROR_NO_DEVICE
if the device has been
disconnected, ERROR_NOT_SUPPORTED
on platforms where the
functionality is not available, another ERROR code on other
failurekernelDriverActive(DeviceHandle, int)
public static int attachKernelDriver(DeviceHandle handle, int interfaceNumber)
detachKernelDriver(DeviceHandle, int)
.
This call is only effective on Linux and returns
ERROR_NOT_SUPPORTED
on all other platforms.
This functionality is not available on Darwin or Windows.handle
- A device handleinterfaceNumber
- the interface to attach the driver fromERROR_NOT_FOUND
if no kernel driver was
active, ERROR_INVALID_PARAM
if the interface does not
exist, ERROR_NO_DEVICE
if the device has been
disconnected, ERROR_NOT_SUPPORTED
on platforms where the
functionality is not available, ERROR_BUSY
if the driver
cannot be attached because the interface is claimed by a program
or driver, anotherERROR code on other failurekernelDriverActive(DeviceHandle, int)
public static int setAutoDetachKernelDriver(DeviceHandle handle, boolean enable)
CAP_SUPPORTS_DETACH_KERNEL_DRIVER
this function will return ERROR_NOT_SUPPORTED
, and libusb will
continue as if this function was never called.handle
- A device handle.enable
- Whether to enable or disable auto kernel driver detachmentSUCCESS
on success, ERROR_NOT_SUPPORTED
on
platforms where the functionality is not available.public static boolean hasCapability(int capability)
capability
- The capability to check for.public static String errorName(int errorCode)
errorCode
- The libusb error or libusb transfer status code to return the
name of.public static int setLocale(String locale)
setLocale(String)
is not called, all messages will be in
English.
The following functions return translatable strings: libusb_strerror().
Note that the libusb log messages controlled through
setDebug(Context, int)
are not translated, they are always in
English.locale
- locale-string in the form of lang[_country_region][.codeset]
or lang[-region], where lang is a 2 letter ISO 639-1 code.SUCCESS
on success, ERROR_INVALID_PARAM
if the
locale doesn't meet the requirements, ERROR_NOT_FOUND
if
the requested language is not supported, a error code on other
errors.public static String strError(int errcode)
setLocale(String)
.
The messages always start with a capital letter and end without any dot.errcode
- The error code whose description is desired.public static short le16ToCpu(short x)
x
- The little-endian value to convertpublic static short cpuToLe16(short x)
x
- The host-endian value to convertpublic static int getDeviceDescriptor(Device device, DeviceDescriptor descriptor)
device
- the devicedescriptor
- output location for the descriptor datapublic static int getStringDescriptorAscii(DeviceHandle handle, byte index, StringBuffer string)
handle
- A device handle.index
- The index of the descriptor to retrieve.string
- Output buffer for ASCII string descriptor.public static String getStringDescriptor(DeviceHandle handle, byte index)
getStringDescriptorAscii(DeviceHandle, byte, StringBuffer)
.
It simply returns the string (maximum length of 127) if possible. If not
possible (NULL handle or 0-index specified or error occurred) then null is
returned.
This method is not part of libusb.handle
- The device handle.index
- The string descriptor index.public static int getActiveConfigDescriptor(Device device, ConfigDescriptor descriptor)
device
- A device.descriptor
- Output location for the USB configuration descriptor. Only
valid if 0 was returned. Must be freed with
freeConfigDescriptor(ConfigDescriptor)
after use.ERROR_NOT_FOUND
if the device is in
unconfigured state another ERROR code on errorgetConfigDescriptor(Device, byte, ConfigDescriptor)
public static int getConfigDescriptor(Device device, byte index, ConfigDescriptor descriptor)
device
- A device.index
- The index of the configuration you wish to retrievedescriptor
- Output location for the USB configuration descriptor. Only
valid if 0 was returned. Must be freed with
freeConfigDescriptor(ConfigDescriptor)
after use.ERROR_NOT_FOUND
if the configuration does
not exist another ERROR code on error.getActiveConfigDescriptor(Device, ConfigDescriptor)
,
getConfigDescriptorByValue(Device, byte, ConfigDescriptor)
public static int getConfigDescriptorByValue(Device device, byte value, ConfigDescriptor descriptor)
device
- A device.value
- The bConfigurationValue of the configuration you wish to
retrieve.descriptor
- Output location for the USB configuration descriptor. Only
valid if 0 was returned. Must be freed with
freeConfigDescriptor(ConfigDescriptor)
after use.ERROR_NOT_FOUND
if the configuration does
not exist another ERROR code on error See also:getActiveConfigDescriptor(Device, ConfigDescriptor)
,
getConfigDescriptor(Device, byte, ConfigDescriptor)
public static void freeConfigDescriptor(ConfigDescriptor descriptor)
getConfigDescriptor(Device, byte, ConfigDescriptor)
or
getActiveConfigDescriptor(Device, ConfigDescriptor)
.
It is safe to call this function with a NULL config parameter, in which
case the function simply returns.descriptor
- The configuration descriptor to freepublic static int getSsEndpointCompanionDescriptor(Context context, EndpointDescriptor endpointDescriptor, SsEndpointCompanionDescriptor companionDescriptor)
context
- The context to operate on, or NULL for the default context.endpointDescriptor
- Endpoint descriptor from which to get the superspeed endpoint
companion descriptor.companionDescriptor
- Output location for the superspeed endpoint companion
descriptor. Only valid if 0 was returned. Must be freed with
(SsEndpointCompanionDescriptor)
after use.SUCCESS
on success, ERROR_NOT_FOUND
if the
descriptor does not exist, another error code on errorpublic static void freeSsEndpointCompanionDescriptor(SsEndpointCompanionDescriptor companionDescriptor)
getSsEndpointCompanionDescriptor(Context, EndpointDescriptor,
SsEndpointCompanionDescriptor)
.
It is safe to call this function with a NULL parameter, in which case the
function simply returns.companionDescriptor
- The superspeed endpoint companion descriptor to freepublic static int getBosDescriptor(DeviceHandle handle, BosDescriptor descriptor)
handle
- The handle of an open libusb device.descriptor
- Output location for the BOS descriptor. Only valid if 0 was
returned. Must be freed with
freeBosDescriptor(BosDescriptor)
after use.SUCCESS
on success, ERROR_NOT_FOUND
if the
device doesn't have a BOS descriptor, another error code on errorpublic static void freeBosDescriptor(BosDescriptor descriptor)
getBosDescriptor(DeviceHandle, BosDescriptor)
.
It is safe to call this function with a NULL parameter, in which case the
function simply returns.descriptor
- The BOS descriptor to free.public static int getUsb20ExtensionDescriptor(Context context, BosDevCapabilityDescriptor devCapDescriptor, Usb20ExtensionDescriptor extensionDescriptor)
context
- The context to operate on, or NULL for the default context.devCapDescriptor
- Device Capability descriptor with a bDevCapabilityType of
BT_USB_2_0_EXTENSION
.extensionDescriptor
- Output location for the USB 2.0 Extension descriptor. Only
valid if 0 was returned. Must be freed with
freeUsb20ExtensionDescriptor(
Usb20ExtensionDescriptor)
after use.public static void freeUsb20ExtensionDescriptor(Usb20ExtensionDescriptor extensionDescriptor)
getUsb20ExtensionDescriptor(Context, BosDevCapabilityDescriptor,
Usb20ExtensionDescriptor)
.
It is safe to call this function with a NULL parameter, in which case
the function simply returns.extensionDescriptor
- The USB 2.0 Extension descriptor to free.public static int getSsUsbDeviceCapabilityDescriptor(Context context, BosDevCapabilityDescriptor devCapDescriptor, SsUsbDeviceCapabilityDescriptor ssUsbDeviceCapabilityDescriptor)
context
- The context to operate on, or NULL for the default context.devCapDescriptor
- Device Capability descriptor with a bDevCapabilityType of
BT_SS_USB_DEVICE_CAPABILITY
.ssUsbDeviceCapabilityDescriptor
- Output location for the SuperSpeed USB Device Capability
descriptor. Only valid if SUCCESS
was returned.
Must be freed with
freeSsUsbDeviceCapabilityDescriptor(
SsUsbDeviceCapabilityDescriptor)
after use.SUCCESS
on success, an error code on error.public static void freeSsUsbDeviceCapabilityDescriptor(SsUsbDeviceCapabilityDescriptor ssUsbDeviceCapabilityDescriptor)
getSsUsbDeviceCapabilityDescriptor(Context,
BosDevCapabilityDescriptor, SsUsbDeviceCapabilityDescriptor)
.
It is safe to call this function with a NULL parameter,
in which case the function simply returns.ssUsbDeviceCapabilityDescriptor
- The descriptor to free.public static int getContainerIdDescriptor(Context context, BosDevCapabilityDescriptor devCapDescriptor, ContainerIdDescriptor containerIdDescriptor)
context
- The context to operate on, or NULL for the default context.devCapDescriptor
- Device Capability descriptor with a bDevCapabilityType of
BT_CONTAINER_ID
.containerIdDescriptor
- Output location for the Container ID descriptor. Only valid if
SUCCESS
was returned. Must be freed with
freeContainerIdDescriptor(ContainerIdDescriptor)
after use.SUCCESS
on success or an error code on errorpublic static void freeContainerIdDescriptor(ContainerIdDescriptor containerIdDescriptor)
getContainerIdDescriptor(Context, BosDevCapabilityDescriptor,
ContainerIdDescriptor)
.
It is safe to call this function with a NULL parameter, in which case
the function simply returns.containerIdDescriptor
- The descriptor to free.public static int getDescriptor(DeviceHandle handle, byte type, byte index, ByteBuffer data)
handle
- A device handle.type
- The descriptor type, see DT_* constants.index
- The index of the descriptor to retrieve.data
- Output buffer for descriptorpublic static int getStringDescriptor(DeviceHandle handle, byte index, short langId, ByteBuffer data)
handle
- A device handle.index
- The index of the descriptor to retrieve.langId
- The language ID for the string descriptor.data
- Output buffer for descriptor.getStringDescriptorAscii(DeviceHandle, byte, StringBuffer)
public static int controlTransfer(DeviceHandle handle, byte bmRequestType, byte bRequest, short wValue, short wIndex, ByteBuffer data, long timeout)
handle
- A handle for the device to communicate with.bmRequestType
- The request type field for the setup packet.bRequest
- The request field for the setup packet.wValue
- The value field for the setup packet.wIndex
- The index field for the setup packet.data
- A suitably-sized data buffer for either input or output
(depending on direction bits within bmRequestType).timeout
- Timeout (in milliseconds) that this function should wait before
giving up due to no response being received. For an unlimited
timeout, use value 0.ERROR_TIMEOUT
if the transfer timed out,
ERROR_PIPE
if the control request was not supported by the device,
ERROR_NO_DEVICE
if the device has been disconnected,
ERROR_BUSY
if called from event handling context,
ERROR_INVALID_PARAM
if the transfer size is larger than the operating system and/or
hardware can support.
Another ERROR code on other failurespublic static int bulkTransfer(DeviceHandle handle, byte endpoint, ByteBuffer data, IntBuffer transferred, long timeout)
handle
- A handle for the device to communicate with.endpoint
- The address of a valid endpoint to communicate with.data
- A suitably-sized data buffer for either input or output
(depending on endpoint).transferred
- Output location for the number of bytes actually transferred.timeout
- timeout (in milliseconds) that this function should wait before
giving up due to no response being received. For an unlimited
timeout, use value 0.ERROR_TIMEOUT
if the transfer timed out (and populates transferred),
ERROR_PIPE
if the endpoint halted,
ERROR_OVERFLOW
if the device offered more data, see
Packets and overflows, ERROR_NO_DEVICE
if the device has
been disconnected, another ERROR code on other failures.public static int interruptTransfer(DeviceHandle handle, byte endpoint, ByteBuffer data, IntBuffer transferred, long timeout)
handle
- A handle for the device to communicate with.endpoint
- The address of a valid endpoint to communicate with.data
- A suitably-sized data buffer for either input or output
(depending on endpoint).transferred
- Output location for the number of bytes actually transferred.timeout
- Timeout (in milliseconds) that this function should wait before
giving up due to no response being received. For an unlimited
timeout, use value 0.ERROR_TIMEOUT
if the transfer timed out, ERROR_PIPE
if the endpoint
halted, ERROR_OVERFLOW
if the device offered more data,
see Packets and overflows, ERROR_NO_DEVICE
if the device
has been disconnected, another ERROR code on other errorpublic static int tryLockEvents(Context context)
handleEvents(Context)
) then you do not need to be concerned with
this locking.
While holding this lock, you are trusted to actually be handling events.
If you are no longer handling events, you must call
unlockEvents(Context)
as soon as possible.context
- The context to operate on, or NULL for the default context.public static void lockEvents(Context context)
handleEvents(Context)
) then you do not need to be concerned with
this locking.
While holding this lock, you are trusted to actually be handling events.
If you are no longer handling events, you must call
unlockEvents(Context)
as soon as possible.context
- The context to operate on, or NULL for the default context.public static void unlockEvents(Context context)
tryLockEvents(Context)
or lockEvents(Context)
.
Releasing this lock will wake up any threads blocked on
waitForEvent(Context, long)
.context
- The context to operate on, or NULL for the default contextpublic static int eventHandlingOk(Context context)
context
- The context to operate on, or NULL for the default context.public static int eventHandlerActive(Context context)
context
- The context to operate on, or NULL for the default context.public static void interruptEventHandler(Context context)
exit(Context)
.context
- The context to operate on, or NULL for the default context.public static void lockEventWaiters(Context context)
handleEvents(Context)
is not allowed.
You then obtain this lock, re-check that another thread is still handling
events, then call waitForEvent(Context, long)
.
You only need to use this lock if you are developing an application which
calls poll() or select() on libusb's file descriptors directly, and may
potentially be handling events from 2 threads simultaneously. If you
stick to libusb's event handling loop functions (e.g.
handleEvents(Context)
) then you do not need to be concerned with
this locking.context
- The context to operate on, or NULL for the default context.public static void unlockEventWaiters(Context context)
context
- The context to operate on, or NULL for the default context.public static int waitForEvent(Context context, long timeout)
lockEventWaiters(Context)
.
This function will block until any of the following conditions are met:
The timeout expires A transfer completes A thread releases the event
handling lock through unlockEvents(Context)
Condition 1 is
obvious. Condition 2 unblocks your thread after the callback for the
transfer has completed. Condition 3 is important because it means that
the thread that was previously handling events is no longer doing so, so
if any events are to complete, another thread needs to step up and start
event handling.
This function releases the event waiters lock before putting your thread
to sleep, and reacquires the lock as it is being woken up.context
- The context to operate on, or NULL for the default context.timeout
- Maximum timeout for this blocking function. A 0 value
indicates unlimited timeout.public static int handleEventsTimeoutCompleted(Context context, long timeout, IntBuffer completed)
BufferUtils.allocateIntBuffer()
context
- the context to operate on, or NULL for the default contexttimeout
- the maximum time to block waiting for events, or 0 for
non-blocking mode.completed
- Buffer for completion integer to check, or NULL.public static int handleEventsTimeout(Context context, long timeout)
handleEventsTimeoutCompleted(Context, long, IntBuffer)
, but
without the completed parameter, calling this function is equivalent to
calling handleEventsTimeoutCompleted(Context, long, IntBuffer)
with a NULL completed parameter.
This function is kept primarily for backwards compatibility. All new code
should call handleEventsCompleted(Context, IntBuffer)
or
handleEventsTimeoutCompleted(Context, long, IntBuffer)
to avoid
race conditions.context
- The context to operate on, or NULL for the default contexttimeout
- The maximum time (In microseconds) to block waiting for
events, or an all zero timeval struct for non-blocking modepublic static int handleEvents(Context context)
handleEventsTimeoutCompleted(Context, long, IntBuffer)
instead.
This function is kept primarily for backwards compatibility. All new code
should call handleEventsCompleted(Context, IntBuffer)
or
handleEventsTimeoutCompleted(Context, long, IntBuffer)
to avoid
race conditions.context
- The context to operate on, or NULL for the default context.public static int handleEventsCompleted(Context context, IntBuffer completed)
handleEvents(Context)
, with the addition of a completed
parameter to allow for race free waiting for the completion of a specific
transfer.
See handleEventsTimeoutCompleted(Context, long, IntBuffer)
for
details on the completed parameter.context
- The context to operate on, or NULL for the default context.completed
- Buffer for completion integer to check, or NULL.public static int handleEventsLocked(Context context, long timeout)
lockEvents(Context)
.
This function is designed to be called under the situation where you have
taken the event lock and are calling poll()/select() directly on libusb's
file descriptors (as opposed to using handleEvents(Context)
or
similar). You detect events on libusb's descriptors, so you then call
this function with a zero timeout value (while still holding the event
lock).context
- The context to operate on, or NULL for the default context.timeout
- The maximum time (In microseconds) to block waiting for
events, or zero for non-blocking modepublic static int pollfdsHandleTimeouts(Context context)
getNextTimeout(Context, LongBuffer)
to learn about when the next
timeout occurs, and to adjust your poll()/select() timeout accordingly so
that you can make a call into the library at that time.
Some platforms supported by libusb do not come with this baggage - any
events relevant to timing will be represented by activity on the file
descriptor set, and getNextTimeout(Context, LongBuffer)
will
always return 0. This function allows you to detect whether you are
running on such a platform.context
- The context to operate on, or NULL for the default contextgetNextTimeout(Context, LongBuffer)
, or 1 if all timeout
events are handled internally or through regular activity on the
file descriptors.public static int getNextTimeout(Context context, LongBuffer timeout)
handleEvents(Context)
or a variant
directly.
You should call this function in your main loop in order to determine how
long to wait for select() or poll() to return results. libusb needs to
be called into at this timeout, so you should use it as an upper bound on
your select() or poll() call.
When the timeout has expired, call into
handleEventsTimeout(Context, long)
(perhaps in non-blocking
mode) so that libusb can handle the timeout.
This function may return 1 (success) and an all-zero timeval. If this is
the case, it indicates that libusb has a timeout that has already
expired so you should call handleEventsTimeout(Context, long)
or
similar immediately. A return code of 0 indicates that there are no
pending timeouts.
On some platforms, this function will always returns 0 (no pending
timeouts). See Notes on time-based events.context
- The context to operate on, or NULL for the default contexttimeout
- Output location for a relative time against the current clock
in which libusb must be called into in order to process
timeout eventsERROR_OTHER
failurepublic static void setPollfdNotifiers(Context context, PollfdListener listener, Object userData)
init(Context)
time).
Additionally, note that the removal notifier may be called during
exit(Context)
(e.g. when it is closing file descriptors that
were opened and added to the poll set at init(Context)
time). If
you don't want this, remove the notifiers immediately before calling
exit(Context)
.context
- The context to operate on, or NULL for the default context.listener
- The listener for addition and removal notifications.userData
- User data to be passed back to callbacks (useful for passing
context information).public static Pollfds getPollfds(Context context)
freePollfds(Pollfds)
when done. The actual list contents must not be
touched.
As file descriptors are a Unix-specific concept, this function is not available on Windows and will always
return NULL.context
- The context to operate on, or NULL for the default context.public static void freePollfds(Pollfds pollfds)
Pollfd
structures.
This should be called for all pollfd lists allocated with getPollfds(Context)
.
It is legal to call this function with a NULL pollfd list. In this case, the function will simply return safely.public static Transfer allocTransfer()
freeTransfer(Transfer)
.public static Transfer allocTransfer(int isoPackets)
freeTransfer(Transfer)
.
Transfers intended for non-isochronous endpoints (e.g. control, bulk,
interrupt) should specify an iso_packets count of zero.
For transfers intended for isochronous endpoints, specify an appropriate
number of packet descriptors to be allocated as part of the transfer. The
returned transfer is not specially initialized for isochronous I/O; you
are still required to call the Transfer.setNumIsoPackets(int)
a
Transfer.setType(byte)
methods accordingly.
It is safe to allocate a transfer with some isochronous packets and then
use it on a non-isochronous endpoint. If you do this, ensure that at time
of submission, numIsoPackets is 0 and that type is set appropriately.isoPackets
- Number of isochronous packet descriptors to allocate.public static void freeTransfer(Transfer transfer)
allocTransfer(int)
.
Please refer to TRANSFER_FREE_BUFFER
for an explanation
of how buffers are freed.
It is legal to call this function with a NULL transfer. In this case, the
function will simply return safely.
It is not legal to free an active transfer (one which has been submitted
and has not yet completed).transfer
- The transfer to freepublic static int submitTransfer(Transfer transfer)
transfer
- The transfer to submitERROR_NO_DEVICE
if the device has
been
disconnected, ERROR_BUSY
if the transfer has
already been
submitted. ERROR_NOT_SUPPORTED
if the transfer
flags are
not supported by the operating system. Another LIBUSB_ERROR code
on failure.public static int cancelTransfer(Transfer transfer)
TRANSFER_CANCELLED
.transfer
- The transfer to cancelERROR_NOT_FOUND
if the transfer is
already complete or cancelled. Another LIBUSB_ERROR code on
failure.public static ByteBuffer controlTransferGetData(Transfer transfer)
Transfer.buffer()
.transfer
- A transfer.public static ControlSetup controlTransferGetSetup(Transfer transfer)
Transfer.buffer()
.transfer
- A transfer.public static void fillControlSetup(ByteBuffer buffer, byte bmRequestType, byte bRequest, short wValue, short wIndex, short wLength)
buffer
- Buffer to output the setup packet into.bmRequestType
- See ControlSetup.bmRequestType()
.bRequest
- See ControlSetup.bRequest()
.wValue
- See ControlSetup.wValue()
.wIndex
- See ControlSetup.wIndex()
.wLength
- See ControlSetup.wLength()
.public static void fillControlTransfer(Transfer transfer, DeviceHandle handle, ByteBuffer buffer, TransferCallback callback, Object userData, long timeout)
Transfer
fields for a
control transfer.
If you pass a transfer buffer to this function, the first 8 bytes will be
interpreted as a control setup packet, and the wLength field will be used
to automatically populate the length field of the transfer. Therefore the
recommended approach is:
1. Allocate a suitably sized data buffer (including space for control
setup).
2. Call
fillControlSetup(ByteBuffer, byte, byte, short, short, short)
.
3. If this is a host-to-device transfer with a data stage, put the data
in place after the setup packet.
4. Call this function.
5. Call submitTransfer(Transfer)
.
It is also legal to pass a NULL buffer to this function, in which case
this function will not attempt to populate the length field. Remember
that you must then populate the buffer and length fields later.transfer
- The transfer to populate.handle
- Handle of the device that will handle the transfer.buffer
- Data buffer. If provided, this function will interpret the
first 8 bytes as a setup packet and infer the transfer length
from that.callback
- callback function to be invoked on transfer completion.userData
- User data to pass to callback function.timeout
- Timeout for the transfer in milliseconds.public static void fillBulkTransfer(Transfer transfer, DeviceHandle handle, byte endpoint, ByteBuffer buffer, TransferCallback callback, Object userData, long timeout)
Transfer
fields for a
bulk transfer.transfer
- The transfer to populate.handle
- Handle of the device that will handle the transfer.endpoint
- Address of the endpoint where this transfer will be sent.buffer
- Data buffer.callback
- Callback function to be invoked on transfer completion.userData
- User data to pass to callback function.timeout
- Timeout for the transfer in milliseconds.public static void fillBulkStreamTransfer(Transfer transfer, DeviceHandle handle, byte endpoint, int streamId, ByteBuffer buffer, TransferCallback callback, Object userData, long timeout)
Transfer
fields
for a bulk transfer using bulk streams.transfer
- The transfer to populate.handle
- Handle of the device that will handle the transfer.endpoint
- Address of the endpoint where this transfer will be sent.streamId
- Bulk stream id for this transfer.buffer
- Data buffer.callback
- Callback function to be invoked on transfer completion.userData
- User data to pass to callback function.timeout
- Timeout for the transfer in milliseconds.public static void fillInterruptTransfer(Transfer transfer, DeviceHandle handle, byte endpoint, ByteBuffer buffer, TransferCallback callback, Object userData, long timeout)
Transfer
fields for an
interrupt transfer.transfer
- The transfer to populate.handle
- Handle of the device that will handle the transfer.endpoint
- Address of the endpoint where this transfer will be sent.buffer
- Data buffer.callback
- Callback function to be invoked on transfer completion.userData
- User data to pass to callback function.timeout
- Timeout for the transfer in milliseconds.public static void fillIsoTransfer(Transfer transfer, DeviceHandle handle, byte endpoint, ByteBuffer buffer, int numIsoPackets, TransferCallback callback, Object userData, long timeout)
Transfer
fields for an
isochronous transfer.transfer
- The transfer to populate.handle
- Handle of the device that will handle the transfer.endpoint
- Address of the endpoint where this transfer will be sent.buffer
- Data buffer.numIsoPackets
- The number of isochronous packets.callback
- Callback function to be invoked on transfer completion.userData
- User data to pass to callback function.timeout
- Timeout for the transfer in milliseconds.public static void setIsoPacketLengths(Transfer transfer, int length)
Transfer.numIsoPackets()
field.transfer
- A transfer.length
- The length to set in each isochronous packet descriptor.getMaxPacketSize(Device, byte)
public static ByteBuffer getIsoPacketBuffer(Transfer transfer, int packet)
getIsoPacketBufferSimple(Transfer, int)
instead.transfer
- A transfer.packet
- The packet to return the address of.getIsoPacketBufferSimple(Transfer, int)
public static ByteBuffer getIsoPacketBufferSimple(Transfer transfer, int packet)
transfer
- A transfer.packet
- The packet to return the address of.getIsoPacketBuffer(Transfer, int)
public static int hotplugRegisterCallback(Context context, int events, int flags, int vendorId, int productId, int deviceClass, HotplugCallback callback, Object userData, HotplugCallbackHandle callbackHandle)
Context
. The callback will fire
when a matching event occurs on a matching device. The callback is
armed until either it is deregistered with
hotplugDeregisterCallback(Context, HotplugCallbackHandle)
or the
supplied callback returns 1 to indicate it is finished processing
events.context
- Context to register this callback with.events
- Bitwise or of events that will trigger this callback.flags
- Hotplug callback flags.vendorId
- The vendor id to match or HOTPLUG_MATCH_ANY
.productId
- The product id to match or HOTPLUG_MATCH_ANY
.deviceClass
- The device class to match or HOTPLUG_MATCH_ANY
.callback
- The function to be invoked on a matching event/deviceuserData
- User data to pass to the callback function.callbackHandle
- Hotplug callback handle of the allocated callback. Only needed
if you later want to deregister this callback, can be NULL.SUCCESS
on success, some ERROR code on failure.public static void hotplugDeregisterCallback(Context context, HotplugCallbackHandle callbackHandle)
Context
. This function is safe to
call from within a hotplug callback.context
- context this callback is registered withcallbackHandle
- the handle of the callback to deregisterCopyright © 2011–2018 usb4java Team. All rights reserved.