LIBUSB20(3)
π libusb20(3) β USB access library π
okay bestie, welcome to the libusb20(3) page from the Library Functions Manual π
this is the USB access library, and itβs giving βlet me talk to USB directlyβ energy. No cap, itβs a whole collection of functions for accessing and controlling USB through the USB file system interface. β¨
Quick vibe check: thelibusb20interfaces are specific to the FreeBSD usb stack and are not available on other operating systems. So if youβre making a portable app, portable applications should consider usinglibusb(3). π«Ά
πΈ NAME πΈ
libusb20 β USB access library
π§ LIBRARY π§
USB access library (libusb -lusb)
β¨ SYNOPSIS β¨
okay so hereβs the exact synopsis, bestie β every prototype, no edits, no βfixingβ the typo energy π
#include <libusb20.h>
int
libusb20_tr_close(struct libusb20_transfer *xfer);
int
libusb20_tr_open(struct libusb20_transfer *xfer, uint32_t max_buf_size,
uint32_t max_frame_count, uint8_t ep_no);
libusb20_tr_open_stream(struct libusb20_transfer *xfer,
uint32_t max_buf_size, uint32_t max_frame_count, uint8_t ep_no,
uint16_t stream_id);
struct libusb20_transfer*
libusb20_tr_get_pointer(struct libusb20_device *pdev,
uint16_t tr_index);
uint16_t
libusb20_tr_get_time_complete(struct libusb20_transfer *xfer);
uint32_t
libusb20_tr_get_actual_frames(struct libusb20_transfer *xfer);
uint32_t
libusb20_tr_get_actual_length(struct libusb20_transfer *xfer);
uint32_t
libusb20_tr_get_max_frames(struct libusb20_transfer *xfer);
uint32_t
libusb20_tr_get_max_packet_length(struct libusb20_transfer *xfer);
uint32_t
libusb20_tr_get_max_total_length(struct libusb20_transfer *xfer);
uint8_t
libusb20_tr_get_status(struct libusb20_transfer *xfer);
uint8_t
libusb20_tr_pending(struct libusb20_transfer *xfer);
void
libusb20_tr_callback_wrapper(struct libusb20_transfer *xfer);
void
libusb20_tr_clear_stall_sync(struct libusb20_transfer *xfer);
void
libusb20_tr_drain(struct libusb20_transfer *xfer);
void
libusb20_tr_set_buffer(struct libusb20_transfer *xfer, void *buffer,
uint16_t fr_index);
void
libusb20_tr_set_callback(struct libusb20_transfer *xfer,
libusb20_tr_callback_t *cb);
void
libusb20_tr_set_flags(struct libusb20_transfer *xfer, uint8_t flags);
uint32_t
libusb20_tr_get_length(struct libusb20_transfer *xfer,
uint16_t fr_index);
void
libusb20_tr_set_length(struct libusb20_transfer *xfer, uint32_t length,
uint16_t fr_index);
void
libusb20_tr_set_priv_sc0(struct libusb20_transfer *xfer, void *sc0);
void
libusb20_tr_set_priv_sc1(struct libusb20_transfer *xfer, void *sc1);
void
libusb20_tr_set_timeout(struct libusb20_transfer *xfer,
uint32_t timeout);
void
libusb20_tr_set_total_frames(struct libusb20_transfer *xfer,
uint32_t nframes);
void
libusb20_tr_setup_bulk(struct libusb20_transfer *xfer, void *pbuf,
uint32_t length, uint32_t timeout);
void
libusb20_tr_setup_control(struct libusb20_transfer *xfer, void *psetup,
void *pbuf, uint32_t timeout);
void
libusb20_tr_setup_intr(struct libusb20_transfer *xfer, void *pbuf,
uint32_t length, uint32_t timeout);
void
libusb20_tr_setup_isoc(struct libusb20_transfer *xfer, void *pbuf,
uint32_t length, uint61_t fr_index);
uint8_t
libusb20_tr_bulk_intr_sync(struct libusb20_transfer *xfer, void *pbuf,
uint32_t length, uint32_t *pactlen, uint32_t timeout);
void
libusb20_tr_start(struct libusb20_transfer *xfer);
void
libusb20_tr_stop(struct libusb20_transfer *xfer);
void
libusb20_tr_submit(struct libusb20_transfer *xfer);
void *
libusb20_tr_get_priv_sc0(struct libusb20_transfer *xfer);
void *
libusb20_tr_get_priv_sc1(struct libusb20_transfer *xfer);
const char *
libusb20_dev_get_backend_name(struct libusb20_device *);
int
libusb20_dev_get_port_path(struct libusb20_device *pdev, uint8_t *buf,
uint8_t bufsize);
int
libusb20_dev_get_info(struct libusb20_device *pdev,
struct usb_device_info *pinfo);
int
libusb20_dev_get_iface_desc(struct libusb20_device *pdev,
uint8_t iface_index, char *buf, uint8_t len);
const char *
libusb20_dev_get_desc(struct libusb20_device *pdev);
int
libusb20_dev_get_stats(struct libusb20_device *pdev,
struct libusb20_device_stats *pstats);
int
libusb20_dev_close(struct libusb20_device *pdev);
int
libusb20_dev_detach_kernel_driver(struct libusb20_device *pdev,
uint8_t iface_index);
int
libusb20_dev_set_config_index(struct libusb20_device *pdev,
uint8_t configIndex);
int
libusb20_dev_get_debug(struct libusb20_device *pdev);
int
libusb20_dev_get_fd(struct libusb20_device *pdev);
int
libusb20_dev_kernel_driver_active(struct libusb20_device *pdev,
uint8_t iface_index);
int
libusb20_dev_open(struct libusb20_device *pdev, uint16_t transfer_max);
int
libusb20_dev_process(struct libusb20_device *pdev);
int
libusb20_dev_request_sync(struct libusb20_device *pdev,
struct LIBUSB20_CONTROL_SETUP_DECODED *setup, void *data,
uint16_t *pactlen, uint32_t timeout, uint8_t flags);
int
libusb20_dev_req_string_sync(struct libusb20_device *pdev,
uint8_t index, uint16_t langid, void *ptr, uint16_t len);
int
libusb20_dev_req_string_simple_sync(struct libusb20_device *pdev,
uint8_t index, void *ptr, uint16_t len);
int
libusb20_dev_reset(struct libusb20_device *pdev);
int
libusb20_dev_check_connected(struct libusb20_device *pdev);
int
libusb20_dev_set_power_mode(struct libusb20_device *pdev,
uint8_t power_mode);
uint8_t
libusb20_dev_get_power_mode(struct libusb20_device *pdev);
uint16_t
libusb20_dev_get_power_usage(struct libusb20_device *pdev);
int
libusb20_dev_set_alt_index(struct libusb20_device *pdev,
uint8_t iface_index, uint8_t alt_index);
struct LIBUSB20_DEVICE_DESC_DECODED *
libusb20_dev_get_device_desc(struct libusb20_device *pdev);
struct libusb20_config *
libusb20_dev_alloc_config(struct libusb20_device *pdev,
uint8_t config_index);
struct libusb20_device *
libusb20_dev_alloc(void);
uint8_t
libusb20_dev_get_address(struct libusb20_device *pdev);
uint8_t
libusb20_dev_get_parent_address(struct libusb20_device *pdev);
uint8_t
libusb20_dev_get_parent_port(struct libusb20_device *pdev);
uint8_t
libusb20_dev_get_bus_number(struct libusb20_device *pdev);
uint8_t
libusb20_dev_get_mode(struct libusb20_device *pdev);
uint8_t
libusb20_dev_get_speed(struct libusb20_device *pdev);
uint8_t
libusb20_dev_get_config_index(struct libusb20_device *pdev);
void
libusb20_dev_free(struct libusb20_device *pdev);
void
libusb20_dev_set_debug(struct libusb20_device *pdev, int debug);
void
libusb20_dev_wait_process(struct libusb20_device *pdev, int timeout);
int
libusb20_be_get_template(struct libusb20_backend *pbe, int *ptemp);
int
libusb20_be_set_template(struct libusb20_backend *pbe, int temp);
int
libusb20_be_get_dev_quirk(struct libusb20_backend *pber, uint16_t index,
struct libusb20_quirk *pq);
int
libusb20_be_get_quirk_name(struct libusb20_backend *pbe, uint16_t index,
struct libusb20_quirk *pq);
int
libusb20_be_add_dev_quirk(struct libusb20_backend *pbe,
struct libusb20_quirk *pq);
int
libusb20_be_remove_dev_quirk(struct libusb20_backend *pbe,
struct libusb20_quirk *pq);
struct libusb20_backend *
libusb20_be_alloc_default(void);
struct libusb20_backend *
libusb20_be_alloc_freebsd(void);
struct libusb20_backend *
libusb20_be_alloc_linux(void);
struct libusb20_device *
libusb20_be_device_foreach(struct libusb20_backend *pbe,
struct libusb20_device *pdev);
void
libusb20_be_dequeue_device(struct libusb20_backend *pbe,
struct libusb20_device *pdev);
void
libusb20_be_enqueue_device(struct libusb20_backend *pbe,
struct libusb20_device *pdev);
void
libusb20_be_free(struct libusb20_backend *pbe);
uint8_t
libusb20_me_get_1(const struct libusb20_me_struct *me, uint16_t off);
uint16_t
libusb20_me_get_2(const struct libusb20_me_struct *me, uint16_t off);
uint16_t
libusb20_me_encode(void *pdata, uint16_t len, const void *pdecoded);
uint16_t
libusb20_me_decode(const void *pdata, uint16_t len, void *pdecoded);
const uint8_t *
libusb20_desc_foreach(const struct libusb20_me_struct *me,
const uint8_t *pdesc);
const char *
libusb20_strerror(int code);
const char *
libusb20_error_name(int code);
π DESCRIPTION π
The libusb20 library implements functions so you can easily access and control USB through the USB file system interface. Thatβs the whole point: itβs the FreeBSD USB stackβs own little playground, and the libusb20 interfaces are specific to the FreeBSD usb stack. They are not available on other operating systems, periodt. Portable applications should consider using libusb(3) instead. π
π USB TRANSFER OPERATIONS π
okay so this is the transfer toolbox, bestie β every little function here has a job, and weβre going through them in order. no skips, no βoops I forgot one.β periodt. π
libusb20_tr_close()β releases all the kernel resources tied to a USB xfer. It returns zero on success, and non-zero return values indicate aLIBUSB20_ERRORvalue. Bye-bye resources, slay. π§libusb20_tr_open()β allocates kernel buffer resources according tomax_buf_sizeandmax_frame_countassociated with a USBpxfer, and binds the transfer to the specifiedep_no.max_buf_sizeis the minimum buffer size that the data transport layer has to support. Ifmax_buf_sizeis zero, thelibusb20library will usewMaxPacketSizeto compute the buffer size β which can be useful for isochronous transfers. The actual buffer size can be greater thanmax_buf_size, and itβs returned bylibusb20_tr_get_max_total_length(). Ifmax_frame_countis OR'ed withLIBUSB20_MAX_FRAME_PRE_SCALE, the remaining part of the argument gets converted from milliseconds into the actual number of frames, rounded up, when this function returns. That flag is only valid for ISOCHRONOUS transfers and has no effect for other transfer types. The actual number of frames setup is found by callinglibusb20_tr_get_max_frames(). This function returns zero on success; non-zero return values indicate aLIBUSB20_ERRORvalue. β¨libusb20_tr_open_stream()β identical tolibusb20_tr_open()except that a stream ID can be specified for BULK endpoints having such a feature.libusb20_tr_open()can be used to open stream ID zero. cute, consistent, we love. πlibusb20_tr_get_pointer()β returns a pointer to the allocated USB transfer according to thepdevandtr_indexarguments. This function returnsNULLin case of failure. no cap, thatNULLmatters. πlibusb20_tr_get_time_complete()β returns the completion time of a USB transfer in millisecond units. This one is most useful for isochronous USB transfers when doing echo cancelling. time math bestie, iconic. β±οΈlibusb20_tr_get_actual_frames()β returns the actual number of USB frames after a USB transfer completed. A value of zero means that no data was transferred. zero frames, zero data, thatβs the whole vibe check. π«Άlibusb20_tr_get_actual_length()β returns the sum of the actual length for all transferred USB frames for the given USB transfer. adding it all up, main character behavior. βlibusb20_tr_get_max_frames()β returns the maximum number of USB frames that were allocated when a USB transfer was setup for the given USB transfer. the ceiling, the limit, the max frame count. πΈlibusb20_tr_get_max_packet_length()β returns the maximum packet length in bytes associated with the given USB transfer. You can use this packet length to round up buffer sizes so that short USB packets are avoided for proxy buffers. tiny packets? not on our watch. π¦libusb20_tr_get_max_total_length()β returns the maximum value for the data length sum of all USB frames associated with a USB transfer. In the case of control transfers, the value returned does not include the length of theSETUPpacket, 8 bytes, which is part of frame zero. The returned value of this function is always aligned to the maximum packet size,wMaxPacketSize, of the endpoint which the USB transfer is bound to. precise alignment, we love to see it. π₯libusb20_tr_get_status()β returns the status of a USB transfer. Status values are defined by a set ofLIBUSB20_TRANSFER_XXXenums. status check: acquired. πlibusb20_tr_pending()β returns non-zero if the given USB transfer is pending for completion. Else this function returns zero. pending or not pending, that is the question. πlibusb20_tr_callback_wrapper()β this is an internal function used to wrap asynchronous USB callbacks. internal business, bestie, donβt touch unless youβre supposed to. π§libusb20_tr_clear_stall_sync()β this is an internal function used to synchronously clear the stall on the given USB transfer. Please see the USB specification for more information on stall clearing. If the given USB transfer is pending when this function is called, the USB transfer will complete with an error after this function has been called. so yes, that pending detail is important β no cap. β οΈlibusb20_tr_drain()β stops the given USB transfer and will not return until the USB transfer has been stopped in hardware. itβs giving βwe wait until itβs actually done.β πlibusb20_tr_set_buffer()β sets the buffer pointer for the given USB transfer andfr_index. Typically the frame index is zero. set that pointer, bestie. π―libusb20_tr_set_callback()β sets the USB callback for asynchronous USB transfers. The callback type is defined bylibusb20_tr_callback_t. callback secured. πlibusb20_tr_set_flags()β sets various USB flags for the given USB transfer. Here are the flag girlies:LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OKβ report a short frame as error.LIBUSB20_TRANSFER_MULTI_SHORT_NOT_OKβ multiple short frames are not allowed.LIBUSB20_TRANSFER_FORCE_SHORTβ all transmitted frames are short terminated.LIBUSB20_TRANSFER_DO_CLEAR_STALLβ will do a clear-stall before starting the transfer.
libusb20_tr_get_length()β returns the length of the given USB frame by index. After a USB transfer is complete, the USB frame length will get updated to the actual transferred length. length update, noted. πlibusb20_tr_set_length()β sets the length of the given USB frame by index. set it, bestie. βοΈlibusb20_tr_set_priv_sc0()β sets private driver pointer number zero. pointer zero, handled. π«‘libusb20_tr_set_priv_sc1()β sets private driver pointer number one. and pointer one too. πlibusb20_tr_set_timeout()β sets the timeout for the given USB transfer. A timeout value of zero means no timeout. The timeout is given in milliseconds. zero = no timeout, milliseconds = the unit. got it. β³libusb20_tr_set_total_frames()β sets the total number of frames that should be executed when the USB transfer is submitted. The total number of USB frames must be less than the maximum number of USB frames associated with the given USB transfer. less than, not equal β keep that in mind. π¨libusb20_tr_setup_bulk()β a helper function for setting up a single frame USB BULK transfer. helper icon behavior. π οΈlibusb20_tr_setup_control()β a helper function for setting up a single or dual frame USB CONTROL transfer depending on the control transfer length. one frame or two, depending on length. ποΈlibusb20_tr_setup_intr()β a helper function for setting up a single frame USB INTERRUPT transfer. single frame, interrupt business. β‘libusb20_tr_setup_isoc()β a helper function for setting up a multi frame USB ISOCHRONOUS transfer. multi frame, isoc setup, slay. πlibusb20_tr_bulk_intr_sync()β performs a synchronous BULK or INTERRUPT transfer having length given by thelengthargument and buffer pointer given by thepbufargument on the USB transfer given by thexferargument. If thepactlenargument is non-NULL, the actual transfer length will be stored at the given pointer destination. If thetimeoutargument is non-zero, the transfer will timeout after the given value in milliseconds. This function does not change the transfer flags, like short packet not ok. It returns zero on success; else aLIBUSB20_TRANSFER_XXXvalue is returned. big sync energy, no flag meddling. π₯libusb20_tr_start()β will get the USB transfer started, if not already started. This function will not get the transfer queued in hardware. This function is non-blocking. start it, but donβt expect hardware queueing. πlibusb20_tr_stop()β will get the USB transfer stopped, if not already stopped. This function is non-blocking, which means that the actual stop can happen after this function returns. stop is requested, not necessarily finished β important. πlibusb20_tr_submit()β will get the USB transfer queued in hardware. now thatβs the hardware queue. π¬libusb20_tr_get_priv_sc0()β returns private driver pointer number zero associated with a USB transfer. pointer zero, returned. πlibusb20_tr_get_priv_sc1()β returns private driver pointer number one associated with a USB transfer. and pointer one, returned. π
β¨ USB DEVICE OPERATIONS β¨
Okay bestie, this is the big one β all the device-level calls. Buckle up, there's like forty of them and they're all gonna be fine π
libusb20_dev_get_backend_name()β hands you a zero terminated string that describes the backend in use. That's it, that's the whole job πΈlibusb20_dev_get_port_path()β pulls out the list of USB port numbers that the datastream for a given USB device follows. The first port number is the Root HUB port number, then the children port numbers follow after it. The Root HUB device itself has a port path length of zero. Valid port numbers start at one and range until and including 255. Typically there should not be more than 16 levels, because of electrical and protocol limitations (nature said no π§). This function returns the number of actual port levels on success, else aLIBUSB20_ERRORvalue is returned β and those are always negative. If the actual number of port levels is greater than the maximum specified, aLIBUSB20_ERRORvalue is returned.libusb20_dev_get_info()β retrieves the BSD specificusb_device_infostructure into the memory location given by pinfo. The USB device given by pdev must be opened before this function will succeed β no opening, no info, that's the rule π. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_get_iface_desc()β retrieves the kernel interface description for the given iface_index. The format of the USB interface description is:"drivername<unit>: <description>". The description string is always zero terminated. A zero length string is written in case no driver is attached to the given interface. The USB device given by pdev must be opened before this function will succeed. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_get_desc()β returns a zero terminated string describing the given USB device. The format of the string is:"drivername<unit>: <description>"β same glow-up as above, iconic πlibusb20_dev_get_stats()β retrieves the device statistics into the structure pointed to by the pstats argument. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_close()β closes the given USB device. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_detach_kernel_driver()β will try to detach the kernel driver for the USB interface given by iface_index. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_set_config_index()β will try to set the configuration index on a USB device. The first configuration index is zero. The un-configure index is255β yes, 255, that's the "we're so done here" index π. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_get_debug()β returns the debug level of a USB device. Lowkey the nosiest little function, love her.libusb20_dev_get_fd()β returns the file descriptor of the given USB device. A negative value is returned when no file descriptor is present. The file descriptor can be used for polling purposes β iykyk πlibusb20_dev_kernel_driver_active()β returns zero if a kernel driver is active on the given USB interface. Else aLIBUSB20_ERRORvalue is returned.libusb20_dev_open()β opens a USB device so that setting up USB transfers becomes possible. The number of USB transfers can be zero, which means only control transfers are allowed. Returns zero on success, else aLIBUSB20_ERRORvalue is returned. A return value ofLIBUSB20_ERROR_BUSYmeans that the device is already opened β somebody got here first, awkward πlibusb20_dev_process()β call this to sync kernel USB transfers with userland USB transfers. Returns zero on success, else aLIBUSB20_ERRORvalue is returned, typically indicating that the given USB device has been detached. So if you get an error here, check if your device literally left the chat πlibusb20_dev_request_sync()β performs a synchronous control request on the given USB device. Before this call will succeed the USB device must be opened. Here's the tea on the args:- setup is a pointer to a decoded and host endian
SETUPpacket. - data is a pointer to a data transfer buffer associated with the control transaction. This argument can be
NULL. - pactlen is a pointer to a variable that will hold the actual transfer length after the control transaction is complete.
- timeout is the transaction timeout given in milliseconds. A timeout of zero means no timeout β³.
- flags is used to specify transaction flags, for example
LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK.
- setup is a pointer to a decoded and host endian
Returns zero on success, else a LIBUSB20_ERROR value is returned.
libusb20_dev_req_string_sync()β will synchronously request a USB string by language ID and string index into the given buffer, limited by a maximum length. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_req_string_simple_sync()β will synchronously request a USB string using the default language ID and convert the string into ASCII before storing it into the given buffer, limited by a maximum length which includes the terminating zero (don't forget that extra byte, bestie π). Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_reset()β will try to BUS reset the given USB device and restore the last set USB configuration. A little "have you tried turning it off and on again" but make it USB. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_check_connected()β checks if an opened USB device is still connected. Returns zero if the device is still connected, else aLIBUSB20_ERRORvalue is returned. The vibe check function, literally π«Άlibusb20_dev_set_power_mode()β sets the power mode of the USB device. Valid power modes:LIBUSB20_POWER_OFFLIBUSB20_POWER_ONLIBUSB20_POWER_SAVELIBUSB20_POWER_SUSPENDLIBUSB20_POWER_RESUME
Returns zero on success, else a LIBUSB20_ERROR value is returned.
libusb20_dev_get_power_mode()β returns the currently selected power mode for the given USB device.libusb20_dev_get_power_usage()β returns the reported power usage in milliamps for the given USB device. A power usage of zero typically means that the device is self powered β independent queen behavior πβ‘libusb20_dev_set_alt_index()β will try to set the given alternate index for the given USB interface index. Returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_dev_get_device_desc()β returns a pointer to the decoded and host endian version of the device descriptor. The USB device need not be opened when calling this function β rare no-open-needed moment, we stan β¨libusb20_dev_alloc_config()β will read out and decode the USB config descriptor for the given USB device and config index. Returns a pointer to the decoded configuration, which must eventually be passed tofree().NULLis returned in case of failure. So like, remember to free it or you're leaking, no cap πlibusb20_dev_alloc()β an internal function to allocate a new USB device. Not for you, babe, that's housekeeping πΈlibusb20_dev_get_address()β returns the internal and not necessarily the real hardware address of the given USB device. Valid addresses start at one.libusb20_dev_get_parent_address()β returns the internal and not necessarily the real hardware address of the given parent USB HUB device. This value is zero for the root HUB, which usually has a device address equal to one. Valid addresses start at one β careful, internal β hardware, that's the whole point π§libusb20_dev_get_parent_port()β returns the port number on the parent USB HUB device. This value is zero for the root HUB, which usually has a device address equal to one. Valid port numbers start at one.libusb20_dev_get_bus_number()β returns the internal bus number which the given USB device belongs to. Valid bus numbers start at zero. Zero, not one β one is for addresses, zero is for buses, don't mix them up πlibusb20_dev_get_mode()β returns the current operation mode of the USB entity. Valid return values are:LIBUSB20_MODE_HOSTLIBUSB20_MODE_DEVICE
libusb20_dev_get_speed()β returns the current speed of the given USB device:LIBUSB20_SPEED_UNKNOWNLIBUSB20_SPEED_LOWLIBUSB20_SPEED_FULLLIBUSB20_SPEED_HIGHLIBUSB20_SPEED_VARIABLELIBUSB20_SPEED_SUPERLIBUSB20_SPEED_SUPER_PLUS
libusb20_dev_get_config_index()β returns the currently selected config index for the given USB device.libusb20_dev_free()β will free the given USB device and all associated USB transfers. Everything goes, clean slate, we love a tidy exit πlibusb20_dev_set_debug()β will set the debug level for the given USB device.libusb20_dev_wait_process()β will wait until a pending USB transfer has completed on the given USB device. A timeout value can be specified, which is passed on to thepoll(2)function.
πΈ USB BACKEND OPERATIONS πΈ
okay bestie, this is the backend section and it's giving βunder the hood but make it iconic.β Backends let you scan for USB devices that are currently present, and there are also quirk functions for when a device needs a little extra handling. Let's go π
libusb20_be_get_template()β returns the currently selected global USB device side mode template into the integer pointerptemp. This function returns zero on success, else aLIBUSB20_ERRORvalue is returned.libusb20_be_set_template()β sets the global USB device side mode template totemp. The new template is not activated until after the next USB enumeration. The template number decides how the USB device will present itself to the USB Host, like Mass Storage Device or USB Ethernet Device. Also see theusb2_template(4)module. This function returns zero on success, else aLIBUSB20_ERRORvalue is returned. β¨libusb20_be_get_dev_quirk()β returns the device quirk according toindexinto thelibusb20_quirkstructure pointed to bypq. This function returns zero on success, else aLIBUSB20_ERRORvalue is returned. If the given quirk does not exist,LIBUSB20_ERROR_NOT_FOUNDis returned.libusb20_be_get_quirk_name()β returns the quirk name according toindexinto thelibusb20_quirkstructure pointed to bypq. This function returns zero on success, else aLIBUSB20_ERRORvalue is returned. If the given quirk does not exist,LIBUSB20_ERROR_NOT_FOUNDis returned.libusb20_be_add_dev_quirk()β adds thelibusb20_quirkstructure pointed to by thepqargument into the device quirk list. This function returns zero on success, else aLIBUSB20_ERRORvalue is returned. If the given quirk cannot be added,LIBUSB20_ERROR_NO_MEMis returned.libusb20_be_remove_dev_quirk()β removes the quirk matching thelibusb20_quirkstructure pointed to by thepqargument from the device quirk list. This function returns zero on success, else aLIBUSB20_ERRORvalue is returned. If the given quirk does not exist,LIBUSB20_ERROR_NOT_FOUNDis returned.libusb20_be_alloc_default(),libusb20_be_alloc_freebsd(),libusb20_be_alloc_linux()β these functions are used to allocate a specific USB backend or the operating system default USB backend. Allocating a backend is a way to scan for currently present USB devices. π¦libusb20_be_device_foreach()β used to iterate USB devices present in a USB backend. The starting value ofpdevisNULL. This function returns the next USB device in the list. IfNULLis returned, the end of the USB device list has been reached.libusb20_be_dequeue_device()β dequeues the given USB device pointer from the backend USB device list. Dequeued USB devices will not be freed when the backend is freed. Important bestie! π«Άlibusb20_be_enqueue_device()β enqueues the given USB device pointer in the backend USB device list. Enqueued USB devices will get freed when the backend is freed.libusb20_be_free()β frees the given backend and all USB devices in its device list.
π USB DESCRIPTOR PARSING π
this is the encode/decode zone, and it's honestly so satisfying when it works. β¨
libusb20_me_get_1(pie, offset)β returns a byte at the given byte offset of a message entity. This function is safe against invalid offsets.libusb20_me_get_2(pie, offset)β returns a little endian 16-bit value at the given byte offset of a message entity. This function is safe against invalid offsets.libusb20_me_encode(pbuf, len, pdecoded)β encodes a so-called*DECODEDstructure into binary format. The total encoded length that will fit in the given buffer is returned. If the buffer pointer isNULL, no data will be written to the buffer location.libusb20_me_decode(pbuf, len, pdecoded)β decodes a binary structure into a so-called*DECODEDstructure. The total decoded length is returned. The buffer pointer cannot beNULL. π¨
π USB DEBUGGING π
when things go sideways, these two are your emotional support functions. no cap. π«Ά
const char * libusb20_strerror(int code)β get the ASCII representation of the error given by thecodeargument. This function does not returnNULL.const char * libusb20_error_name(int code)β get the ASCII representation of the error enum given by thecodeargument. This function does not returnNULL.
π FILES π
/dev/usbβ that's the path, bestie. π
π SEE ALSO π
go read these too, iykyk:
π§ HISTORY π§
Some parts of the libusb20 API derives from the libusb project at sourceforge. π¦
okay that's the whole vibe! this page's source is Debian, dated December 27, 2019, and its page/version is LIBUSB20(3) β mwah! ππβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2008-2019 Hans Petter Selasky
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms