usb

package module
v0.0.0-...-3badf09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2018 License: LGPL-2.1 Imports: 6 Imported by: 0

README

go-usb

An in-progress port of libusb to Go

Current state

OS-Agnostic code is converted and needs to be passed over for compile errors:

Syntax:

  • backend.go
  • core.go
  • descriptor.go
  • hotplug.go
  • io.go
  • io_unix.go
  • io_windows.go
  • libusb.go
  • libusbi.go
  • list.go
  • strerror.go
  • sync.go

Semantic:

  • backend.go
  • core.go
  • descriptor.go
  • hotplug.go
  • io.go
  • io_unix.go
  • io_windows.go
  • libusb.go
  • libusbi.go
  • list.go
  • strerror.go
  • sync.go

OS-Specific code is in the process of conversion

All of the small OS-specific files have been converted, the smallest remaining file at over 600 LOC.

Before I start converting the larger files I want to look into whether the poll semantics that libusb uses are even a thing we need to care about, or if they can be replicated with channels. All references to poll in the libusb docs suggest that they are "fake" and just used for signalling, which sounds a heck of a lot like a chan struct{}.

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	/** In the context of a \ref libusb_device_descriptor "device descriptor",
	 * this bDeviceClass value indicates that each interface specifies its
	 * own class information and all interfaces operate independently.
	 */
	LIBUSB_CLASS_PER_INTERFACE libusb_class_code = 0

	/** Audio class */
	LIBUSB_CLASS_AUDIO libusb_class_code = 1

	/** Communications class */
	LIBUSB_CLASS_COMM libusb_class_code = 2

	/** Human Interface Device class */
	LIBUSB_CLASS_HID libusb_class_code = 3

	/** Physical */
	LIBUSB_CLASS_PHYSICAL libusb_class_code = 5

	/** Printer class */
	LIBUSB_CLASS_PRINTER libusb_class_code = 7

	/** Image class */
	LIBUSB_CLASS_IMAGE libusb_class_code = 6

	/** Mass storage class */
	LIBUSB_CLASS_MASS_STORAGE libusb_class_code = 8

	/** Hub class */
	LIBUSB_CLASS_HUB libusb_class_code = 9

	/** Data class */
	LIBUSB_CLASS_DATA libusb_class_code = 10

	/** Smart Card */
	LIBUSB_CLASS_SMART_CARD libusb_class_code = 0x0b

	/** Content Security */
	LIBUSB_CLASS_CONTENT_SECURITY libusb_class_code = 0x0d

	/** Video */
	LIBUSB_CLASS_VIDEO libusb_class_code = 0x0e

	/** Personal Healthcare */
	LIBUSB_CLASS_PERSONAL_HEALTHCARE libusb_class_code = 0x0f

	/** Diagnostic Device */
	LIBUSB_CLASS_DIAGNOSTIC_DEVICE libusb_class_code = 0xdc

	/** Wireless class */
	LIBUSB_CLASS_WIRELESS libusb_class_code = 0xe0

	/** Application class */
	LIBUSB_CLASS_APPLICATION libusb_class_code = 0xfe

	/** Class is vendor-specific */
	LIBUSB_CLASS_VENDOR_SPEC libusb_class_code = 0xff
)
View Source
const (
	/** Device descriptor. See libusb_device_descriptor. */
	LIBUSB_DT_DEVICE libusb_descriptor_type = 0x01

	/** Configuration descriptor. See libusb_config_descriptor. */
	LIBUSB_DT_CONFIG libusb_descriptor_type = 0x02

	/** String descriptor */
	LIBUSB_DT_STRING libusb_descriptor_type = 0x03

	/** Interface descriptor. See libusb_interface_descriptor. */
	LIBUSB_DT_INTERFACE libusb_descriptor_type = 0x04

	/** Endpoint descriptor. See libusb_endpoint_descriptor. */
	LIBUSB_DT_ENDPOINT libusb_descriptor_type = 0x05

	/** BOS descriptor */
	LIBUSB_DT_BOS libusb_descriptor_type = 0x0f

	/** Device Capability descriptor */
	LIBUSB_DT_DEVICE_CAPABILITY libusb_descriptor_type = 0x10

	/** HID descriptor */
	LIBUSB_DT_HID libusb_descriptor_type = 0x21

	/** HID report descriptor */
	LIBUSB_DT_REPORT libusb_descriptor_type = 0x22

	/** Physical descriptor */
	LIBUSB_DT_PHYSICAL libusb_descriptor_type = 0x23

	/** Hub descriptor */
	LIBUSB_DT_HUB libusb_descriptor_type = 0x29

	/** SuperSpeed Hub descriptor */
	LIBUSB_DT_SUPERSPEED_HUB libusb_descriptor_type = 0x2a

	/** SuperSpeed Endpoint Companion descriptor */
	LIBUSB_DT_SS_ENDPOINT_COMPANION libusb_descriptor_type = 0x30
)
View Source
const (
	/** In: device-to-host */
	LIBUSB_ENDPOINT_IN libusb_endpoint_direction = 0x80

	/** Out: host-to-device */
	LIBUSB_ENDPOINT_OUT libusb_endpoint_direction = 0x00
)
View Source
const (
	/** Control endpoint */
	LIBUSB_TRANSFER_TYPE_CONTROL libusb_transfer_type = iota

	/** Isochronous endpoint */
	LIBUSB_TRANSFER_TYPE_ISOCHRONOUS libusb_transfer_type = iota

	/** Bulk endpoint */
	LIBUSB_TRANSFER_TYPE_BULK libusb_transfer_type = iota

	/** Interrupt endpoint */
	LIBUSB_TRANSFER_TYPE_INTERRUPT libusb_transfer_type = iota

	/** Stream endpoint */
	LIBUSB_TRANSFER_TYPE_BULK_STREAM libusb_transfer_type = iota
)
View Source
const (
	/** Request status of the specific recipient */
	LIBUSB_REQUEST_GET_STATUS libusb_standard_request = 0x00

	/** Clear or disable a specific feature */
	LIBUSB_REQUEST_CLEAR_FEATURE libusb_standard_request = 0x01

	/** Set or enable a specific feature */
	LIBUSB_REQUEST_SET_FEATURE libusb_standard_request = 0x03

	/** Set device address for all future accesses */
	LIBUSB_REQUEST_SET_ADDRESS libusb_standard_request = 0x05

	/** Get the specified descriptor */
	LIBUSB_REQUEST_GET_DESCRIPTOR libusb_standard_request = 0x06

	/** Used to update existing descriptors or add new descriptors */
	LIBUSB_REQUEST_SET_DESCRIPTOR libusb_standard_request = 0x07

	/** Get the current device configuration value */
	LIBUSB_REQUEST_GET_CONFIGURATION libusb_standard_request = 0x08

	/** Set device configuration */
	LIBUSB_REQUEST_SET_CONFIGURATION libusb_standard_request = 0x09

	/** Return the selected alternate setting for the specified interface */
	LIBUSB_REQUEST_GET_INTERFACE libusb_standard_request = 0x0A

	/** Select an alternate interface for the specified interface */
	LIBUSB_REQUEST_SET_INTERFACE libusb_standard_request = 0x0B

	/** Set then report an endpoint's synchronization frame */
	LIBUSB_REQUEST_SYNCH_FRAME libusb_standard_request = 0x0C

	/** Sets both the U1 and U2 Exit Latency */
	LIBUSB_REQUEST_SET_SEL libusb_standard_request = 0x30

	/** Delay from the time a host transmits a packet to the time it is
	 * received by the device. */
	LIBUSB_SET_ISOCH_DELAY libusb_standard_request = 0x31
)
View Source
const (
	/** Standard */
	LIBUSB_REQUEST_TYPE_STANDARD libusb_request_type = (0x00 << 5)

	/** Class */
	LIBUSB_REQUEST_TYPE_CLASS libusb_request_type = (0x01 << 5)

	/** Vendor */
	LIBUSB_REQUEST_TYPE_VENDOR libusb_request_type = (0x02 << 5)

	/** Reserved */
	LIBUSB_REQUEST_TYPE_RESERVED libusb_request_type = (0x03 << 5)
)
View Source
const (
	/** Device */
	LIBUSB_RECIPIENT_DEVICE libusb_request_recipient = iota

	/** Interface */
	LIBUSB_RECIPIENT_INTERFACE libusb_request_recipient = iota

	/** Endpoint */
	LIBUSB_RECIPIENT_ENDPOINT libusb_request_recipient = iota

	/** Other */
	LIBUSB_RECIPIENT_OTHER libusb_request_recipient = iota
)
View Source
const (
	/** No synchronization */
	LIBUSB_ISO_SYNC_TYPE_NONE libusb_iso_sync_type = iota

	/** Asynchronous */
	LIBUSB_ISO_SYNC_TYPE_ASYNC libusb_iso_sync_type = iota

	/** Adaptive */
	LIBUSB_ISO_SYNC_TYPE_ADAPTIVE libusb_iso_sync_type = iota

	/** Synchronous */
	LIBUSB_ISO_SYNC_TYPE_SYNC libusb_iso_sync_type = iota
)
View Source
const (
	/** Data endpoint */
	LIBUSB_ISO_USAGE_TYPE_DATA libusb_iso_usage_type = iota

	/** Feedback endpoint */
	LIBUSB_ISO_USAGE_TYPE_FEEDBACK libusb_iso_usage_type = iota

	/** Implicit feedback Data endpoint */
	LIBUSB_ISO_USAGE_TYPE_IMPLICIT libusb_iso_usage_type = iota
)
View Source
const (
	/** The OS doesn't report or know the device speed. */
	LIBUSB_SPEED_UNKNOWN libusb_speed = iota

	/** The device is operating at low speed (1.5MBit/s). */
	LIBUSB_SPEED_LOW libusb_speed = iota

	/** The device is operating at full speed (12MBit/s). */
	LIBUSB_SPEED_FULL libusb_speed = iota

	/** The device is operating at high speed (480MBit/s). */
	LIBUSB_SPEED_HIGH libusb_speed = iota

	/** The device is operating at super speed (5000MBit/s). */
	LIBUSB_SPEED_SUPER libusb_speed = iota
)
View Source
const (
	/** Low speed operation supported (1.5MBit/s). */
	LIBUSB_LOW_SPEED_OPERATION libusb_supported_speed = 1

	/** Full speed operation supported (12MBit/s). */
	LIBUSB_FULL_SPEED_OPERATION libusb_supported_speed = 2

	/** High speed operation supported (480MBit/s). */
	LIBUSB_HIGH_SPEED_OPERATION libusb_supported_speed = 4

	/** Superspeed operation supported (5000MBit/s). */
	LIBUSB_SUPER_SPEED_OPERATION libusb_supported_speed = 8
)
View Source
const (
	/** Wireless USB device capability */
	LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY libusb_bos_type = 1

	/** USB 2.0 extensions */
	LIBUSB_BT_USB_2_0_EXTENSION libusb_bos_type = 2

	/** SuperSpeed USB device capability */
	LIBUSB_BT_SS_USB_DEVICE_CAPABILITY libusb_bos_type = 3

	/** Container ID type */
	LIBUSB_BT_CONTAINER_ID libusb_bos_type = 4
)
View Source
const (
	/** Success (no error) */
	LIBUSB_SUCCESS libusb_error = 0

	/** Input/output error */
	LIBUSB_ERROR_IO libusb_error = -1

	/** Invalid parameter */
	LIBUSB_ERROR_INVALID_PARAM libusb_error = -2

	/** Access denied (insufficient permissions) */
	LIBUSB_ERROR_ACCESS libusb_error = -3

	/** No such device (it may have been disconnected) */
	LIBUSB_ERROR_NO_DEVICE libusb_error = -4

	/** Entity not found */
	LIBUSB_ERROR_NOT_FOUND libusb_error = -5

	/** Resource busy */
	LIBUSB_ERROR_BUSY libusb_error = -6

	/** Operation timed out */
	LIBUSB_ERROR_TIMEOUT libusb_error = -7

	/** Overflow */
	LIBUSB_ERROR_OVERFLOW libusb_error = -8

	/** Pipe error */
	LIBUSB_ERROR_PIPE libusb_error = -9

	/** System call interrupted (perhaps due to signal) */
	LIBUSB_ERROR_INTERRUPTED libusb_error = -10

	/** Insufficient memory */
	LIBUSB_ERROR_NO_MEM libusb_error = -11

	/** Operation not supported or unimplemented on this platform */
	LIBUSB_ERROR_NOT_SUPPORTED libusb_error = -12

	/** Other error */
	LIBUSB_ERROR_OTHER libusb_error = -99
)
View Source
const (
	/** Transfer completed without error. Note that this does not indicate
	 * that the entire amount of requested data was transferred. */
	LIBUSB_TRANSFER_COMPLETED libusb_transfer_status = iota

	/** Transfer failed */
	LIBUSB_TRANSFER_ERROR libusb_transfer_status = iota

	/** Transfer timed out */
	LIBUSB_TRANSFER_TIMED_OUT libusb_transfer_status = iota

	/** Transfer was cancelled */
	LIBUSB_TRANSFER_CANCELLED libusb_transfer_status = iota

	/** For bulk/interrupt endpoints: halt condition detected (endpoint
	 * stalled). For control endpoints: control request not supported. */
	LIBUSB_TRANSFER_STALL libusb_transfer_status = iota

	/** Device was disconnected */
	LIBUSB_TRANSFER_NO_DEVICE libusb_transfer_status = iota

	/** Device sent more data than requested */
	LIBUSB_TRANSFER_OVERFLOW libusb_transfer_status = iota
)
View Source
const (
	/** Report short frames as errors */
	LIBUSB_TRANSFER_SHORT_NOT_OK libusb_transfer_flags = 1 << 0

	/** Automatically free() transfer buffer during libusb_free_transfer().
	 * Note that buffers allocated with libusb_dev_mem_alloc() should not
	 * be attempted freed in this way, since free() is not an appropriate
	 * way to release such memory. */
	LIBUSB_TRANSFER_FREE_BUFFER libusb_transfer_flags = 1 << 1

	/** Automatically call libusb_free_transfer() after callback returns.
	 * If this flag is set, it is illegal to call libusb_free_transfer()
	 * from your transfer callback, as this will result in a double-free
	 * when this flag is acted upon. */
	LIBUSB_TRANSFER_FREE_TRANSFER libusb_transfer_flags = 1 << 2

	/** Terminate transfers that are a multiple of the endpoint's
	 * wMaxPacketSize with an extra zero length packet. This is useful
	 * when a device protocol mandates that each logical request is
	 * terminated by an incomplete packet (i.e. the logical requests are
	 * not separated by other means).
	 *
	 * This flag only affects host-to-device transfers to bulk and interrupt
	 * endpoints. In other situations, it is ignored.
	 *
	 * This flag only affects transfers with a length that is a multiple of
	 * the endpoint's wMaxPacketSize. On transfers of other lengths, this
	 * flag has no effect. Therefore, if you are working with a device that
	 * needs a ZLP whenever the end of the logical request falls on a packet
	 * boundary, then it is sensible to set this flag on <em>every</em>
	 * transfer (you do not have to worry about only setting it on transfers
	 * that end on the boundary).
	 *
	 * This flag is currently only supported on Linux.
	 * On other systems, libusb_submit_transfer() will return
	 * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
	 *
	 * Available since libusb-1.0.9.
	 */
	LIBUSB_TRANSFER_ADD_ZERO_PACKET libusb_transfer_flags = 1 << 3
)
View Source
const (
	/** The libusb_has_capability() API is available. */
	LIBUSB_CAP_HAS_CAPABILITY libusb_capability = 0x0000
	/** Hotplug support is available on this platform. */
	LIBUSB_CAP_HAS_HOTPLUG libusb_capability = 0x0001
	/** The library can access HID devices without requiring user intervention.
	 * Note that before being able to actually access an HID device, you may
	 * still have to call additional libusb functions such as
	 * \ref libusb_detach_kernel_driver(). */
	LIBUSB_CAP_HAS_HID_ACCESS libusb_capability = 0x0100
	/** The library supports detaching of the default USB driver, using
	 * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel */
	LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER libusb_capability = 0x0101
)
View Source
const (
	LIBUSB_LOG_LEVEL_NONE    libusb_log_level = iota
	LIBUSB_LOG_LEVEL_ERROR   libusb_log_level = iota
	LIBUSB_LOG_LEVEL_WARNING libusb_log_level = iota
	LIBUSB_LOG_LEVEL_INFO    libusb_log_level = iota
	LIBUSB_LOG_LEVEL_DEBUG   libusb_log_level = iota
)
View Source
const (
	LIBUSB_HOTPLUG_NO_FLAGS libusb_hotplug_flag = 0

	/** Arm the callback and fire it for all matching currently attached devices. */
	LIBUSB_HOTPLUG_ENUMERATE libusb_hotplug_flag = 1 << 0
)
View Source
const (
	/** A device has been plugged in and is ready to use */
	LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED libusb_hotplug_event = 0x01

	/** A device has left and is no longer available.
	 * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device.
	 * It is safe to call libusb_get_device_descriptor on a device that has left */
	LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT libusb_hotplug_event = 0x02
)
View Source
const (
	LIBUSB_TRANSFER_TYPE_MASK  = 0x03 /* in bmAttributes */
	LIBUSB_ISO_USAGE_TYPE_MASK = 0x30
	LIBUSB_ISO_SYNC_TYPE_MASK  = 0x0C
)
View Source
const (
	USB_MAXENDPOINTS  = 32
	USB_MAXINTERFACES = 32
	USB_MAXCONFIG     = 8

	/* Backend specific capabilities */
	USBI_CAP_HAS_HID_ACCESS                = 0x00010000
	USBI_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x00020000

	/* Maximum number of bytes in a log line */
	USBI_MAX_LOG_LEN = 1024
)
View Source
const (
	/* The list of pollfds has been modified */
	USBI_EVENT_POLLFDS_MODIFIED usbi_event_flags = 1 << 0

	/* The user has interrupted the event handler */
	USBI_EVENT_USER_INTERRUPT usbi_event_flags = 1 << 1
)
View Source
const (
	USBI_CLOCK_MONOTONIC usbi_clock = iota
	USBI_CLOCK_REALTIME  usbi_clock = iota
)
View Source
const (
	/* Transfer successfully submitted by backend */
	USBI_TRANSFER_IN_FLIGHT usbi_transfer_state_flags = 1 << 0

	/* Cancellation was requested via libusb_cancel_transfer() */
	USBI_TRANSFER_CANCELLING usbi_transfer_state_flags = 1 << 1

	/* Operation on the transfer failed because the device disappeared */
	USBI_TRANSFER_DEVICE_DISAPPEARED usbi_transfer_state_flags = 1 << 2
)
View Source
const (
	/* Set by backend submit_transfer() if the OS handles timeout */
	USBI_TRANSFER_OS_HANDLES_TIMEOUT usbi_transfer_timeout_flags = 1 << 0

	/* The transfer timeout has been handled */
	USBI_TRANSFER_TIMEOUT_HANDLED usbi_transfer_timeout_flags = 1 << 1

	/* The transfer timeout was successfully processed */
	USBI_TRANSFER_TIMED_OUT usbi_transfer_timeout_flags = 1 << 2
)
View Source
const CONFIG_DESC_LENGTH = 9
View Source
const DESC_HEADER_LENGTH = 2
View Source
const DEVICE_DESC_LENGTH = 18
View Source
const ENDPOINT_AUDIO_DESC_LENGTH = 9
View Source
const ENDPOINT_DESC_LENGTH = 7
View Source
const INTERFACE_DESC_LENGTH = 9
View Source
const LIBUSB_API_VERSION = 0x01000105

* \def LIBUSB_API_VERSION

  • \ingroup libusb_misc
  • libusb's API version. *
  • Since version 1.0.13, to help with feature detection, libusb defines
  • a LIBUSB_API_VERSION macro that gets increased every time there is a
  • significant change to the API, such as the introduction of a new call,
  • the definition of a new macro/enum member, or any other element that
  • libusb applications may want to detect at compilation time. *
  • The macro is typically used in an application as follows:
  • \code
  • #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01001234)
  • // Use one of the newer features from the libusb API
  • #endif
  • \endcode *
  • Internally, LIBUSB_API_VERSION is defined as follows:
  • (libusb major << 24) | (libusb minor << 16) | (16 bit incremental)
View Source
const LIBUSB_BM_LPM_SUPPORT libusb_usb_2_0_extension_attributes = 2

* Supports Link Power Management (LPM)

View Source
const LIBUSB_BM_LTM_SUPPORT libusb_ss_usb_device_capability_attributes = 2

* Supports Latency Tolerance Messages (LTM)

View Source
const LIBUSB_BT_CONTAINER_ID_SIZE = 20
View Source
const LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE = 10
View Source
const LIBUSB_BT_USB_2_0_EXTENSION_SIZE = 7

BOS descriptor sizes

View Source
const LIBUSB_CONTROL_SETUP_SIZE = 8 // manually calculated in port

We unwrap the BOS => define its max size

View Source
const LIBUSB_DT_BOS_SIZE = 5
View Source
const LIBUSB_DT_CONFIG_SIZE = 9
View Source
const LIBUSB_DT_DEVICE_CAPABILITY_SIZE = 3
View Source
const LIBUSB_DT_DEVICE_SIZE = 18

Descriptor sizes per descriptor type

View Source
const LIBUSB_DT_ENDPOINT_AUDIO_SIZE = 9 /* Audio extension */
View Source
const LIBUSB_DT_ENDPOINT_SIZE = 7
View Source
const LIBUSB_DT_HUB_NONVAR_SIZE = 7
View Source
const LIBUSB_DT_INTERFACE_SIZE = 9
View Source
const LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE = 6
View Source
const LIBUSB_ENDPOINT_ADDRESS_MASK = 0x0f /* in bEndpointAddress */
View Source
const LIBUSB_ENDPOINT_DIR_MASK = 0x80
View Source
const LIBUSB_ERROR_COUNT = 14

Total number of error codes in enum libusb_error

View Source
const LIBUSB_HOTPLUG_MATCH_ANY = -1

* \ingroup libusb_hotplug

  • Wildcard matching for hotplug events

Variables

This section is empty.

Functions

func BosDescriptorFromBytes

func BosDescriptorFromBytes(bytes []uint8) (*libusb_bos_descriptor, error)

BosDescriptorFromBytes does not populate the dev_capability field

func IS_EPIN

func IS_EPIN(ep uint8) bool

func IS_XFERIN

func IS_XFERIN(xfer *libusb_transfer) bool

func SsUsbDeviceCapabilityDescriptorFromBytes

func SsUsbDeviceCapabilityDescriptorFromBytes(bytes []uint8) (*libusb_ss_usb_device_capability_descriptor, error)

func USBI_GET_CONTEXT

func USBI_GET_CONTEXT(ctx *libusb_context) *libusb_context

func Usb20ExtensionDescriptorFromBytes

func Usb20ExtensionDescriptorFromBytes(bytes []uint8) (*libusb_usb_2_0_extension_descriptor, error)

Types

type LinkedList

type LinkedList struct {
	// contains filtered or unexported fields
}

type Locale

type Locale string
const (
	ENGLISH Locale = "en"
	DUTCH   Locale = "nl"
	FRENCH  Locale = "fr"
	RUSSIAN Locale = "ru"
)

type POLL_NFDS_TYPE

type POLL_NFDS_TYPE uint32

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL