libosmousb 1.9.3
Osmocom USB library
|
#include <libusb.h>
Go to the source code of this file.
Data Structures | |
struct | dev_id |
struct | usb_interface_match |
struct | osmo_usb_matchspec |
Description of the USB device+interface we're looking for. More... | |
Macros | |
#define | USB_MAX_PATH_LEN 20 |
Functions | |
char * | osmo_libusb_dev_get_path_buf (char *buf, size_t bufsize, libusb_device *dev) |
obtain the string representation of the USB device path of given device. More... | |
char * | osmo_libusb_dev_get_path_c (void *ctx, libusb_device *dev) |
obtain the string representation of the USB device path of given device. More... | |
libusb_device ** | osmo_libusb_find_matching_usb_devs (void *ctx, struct libusb_context *luctx, const struct dev_id *dev_ids) |
Find USB devices matching the specified list of USB VendorID/ProductIDs. More... | |
libusb_device * | osmo_libusb_find_matching_dev_path (struct libusb_context *luctx, const struct dev_id *dev_ids, const char *path) |
Find a USB device of matching VendorID/ProductID at given path. More... | |
libusb_device * | osmo_libusb_find_matching_dev_serial (struct libusb_context *luctx, const struct dev_id *dev_ids, const char *serial) |
Find a USB device of matching VendorID/ProductID and given iSerial string. More... | |
int | osmo_libusb_dev_find_matching_interfaces (libusb_device *dev, int class, int sub_class, int protocol, struct usb_interface_match *out, unsigned int out_len) |
find a matching interface among all interfaces of the given USB device. More... | |
int | osmo_libusb_find_matching_interfaces (libusb_context *luctx, const struct dev_id *dev_ids, int class, int sub_class, int protocol, struct usb_interface_match *out, unsigned int out_len) |
find matching interfaces among a list devices of specified VendorId/ProductID tuples. More... | |
libusb_device_handle * | osmo_libusb_open_claim_interface (void *ctx, libusb_context *luctx, const struct usb_interface_match *ifm) |
open matching USB device and claim interface More... | |
void | osmo_libusb_match_init (struct osmo_usb_matchspec *cfg, int if_class, int if_subclass, int if_proto) |
libusb_device_handle * | osmo_libusb_find_open_claim (const struct osmo_usb_matchspec *cfg, const struct dev_id *default_dev_ids) |
high-level all-in-one function for USB device, config + interface matching + opening. More... | |
int | osmo_libusb_get_ep_addrs (libusb_device_handle *devh, unsigned int if_num, uint8_t *out, uint8_t *in, uint8_t *irq) |
obtain the endpoint addresses for a given USB interface. More... | |
int | osmo_libusb_init (libusb_context **luctx) |
void | osmo_libusb_exit (libusb_context *luctx) |
#define USB_MAX_PATH_LEN 20 |
int osmo_libusb_dev_find_matching_interfaces | ( | libusb_device * | dev, |
int | class, | ||
int | sub_class, | ||
int | protocol, | ||
struct usb_interface_match * | out, | ||
unsigned int | out_len | ||
) |
find a matching interface among all interfaces of the given USB device.
[in] | dev | USB device in which we shall search |
[in] | class | USB Interface Class to look for |
[in] | sub_class | USB Interface Subclass to look for |
[in] | protocol | USB Interface Protocol to look for |
[out] | out | User-allocated array for storing matches |
[in] | out_len | Length of out array |
References usb_interface_match::addr, usb_interface_match::altsetting, usb_interface_match::class, usb_interface_match::configuration, usb_interface_match::interface, osmo_libusb_dev_get_path_buf(), usb_interface_match::path, usb_interface_match::product, usb_interface_match::protocol, usb_interface_match::string_idx, usb_interface_match::sub_class, usb_interface_match::usb_dev, USB_MAX_PATH_LEN, and usb_interface_match::vendor.
Referenced by osmo_libusb_find_matching_interfaces(), and osmo_libusb_find_open_claim().
char * osmo_libusb_dev_get_path_buf | ( | char * | buf, |
size_t | bufsize, | ||
libusb_device * | dev | ||
) |
obtain the string representation of the USB device path of given device.
[out] | buf | Output string buffer |
[in] | bufsize | Size of output string buffer in bytes |
[in] | dev | USB device whose bus path we want to obtain |
Referenced by osmo_libusb_dev_find_matching_interfaces(), osmo_libusb_dev_get_path_c(), osmo_libusb_find_matching_dev_path(), and osmo_libusb_open_claim_interface().
char * osmo_libusb_dev_get_path_c | ( | void * | ctx, |
libusb_device * | dev | ||
) |
obtain the string representation of the USB device path of given device.
[in] | talloc | context from which to dynamically allocate output string buffer |
[in] | dev | USB device whose bus path we want to obtain |
References osmo_libusb_dev_get_path_buf(), and USB_MAX_PATH_LEN.
void osmo_libusb_exit | ( | libusb_context * | luctx | ) |
libusb_device * osmo_libusb_find_matching_dev_path | ( | struct libusb_context * | luctx, |
const struct dev_id * | dev_ids, | ||
const char * | path | ||
) |
Find a USB device of matching VendorID/ProductID at given path.
[in] | luctx | libusb context on which to operate |
[in] | dev_ids | zer-oterminated array of VendorId/ProductId tuples |
[in] | path | string representation of USB path |
References DLUSB, match_dev_ids(), and osmo_libusb_dev_get_path_buf().
Referenced by osmo_libusb_find_open_claim().
libusb_device * osmo_libusb_find_matching_dev_serial | ( | struct libusb_context * | luctx, |
const struct dev_id * | dev_ids, | ||
const char * | serial | ||
) |
Find a USB device of matching VendorID/ProductID and given iSerial string.
[in] | luctx | libusb context on which to operate |
[in] | dev_ids | zer-oterminated array of VendorId/ProductId tuples |
[in] | serial | string representation of serial number |
References DLUSB, and match_dev_ids().
int osmo_libusb_find_matching_interfaces | ( | libusb_context * | luctx, |
const struct dev_id * | dev_ids, | ||
int | class, | ||
int | sub_class, | ||
int | protocol, | ||
struct usb_interface_match * | out, | ||
unsigned int | out_len | ||
) |
find matching interfaces among a list devices of specified VendorId/ProductID tuples.
[in] | luctx | libusb context on which to operate |
[in] | dev_ids | zero-terminated array of VendorId/ProductId tuples |
[in] | class | USB Interface Class to look for |
[in] | sub_class | USB Interface Subclass to look for |
[in] | protocol | USB Interface Protocol to look for |
[out] | out | User-allocated array for storing matches |
[in] | out_len | Length of out array |
References osmo_libusb_dev_find_matching_interfaces(), and osmo_libusb_find_matching_usb_devs().
libusb_device ** osmo_libusb_find_matching_usb_devs | ( | void * | ctx, |
struct libusb_context * | luctx, | ||
const struct dev_id * | dev_ids | ||
) |
Find USB devices matching the specified list of USB VendorID/ProductIDs.
[in] | ctx | talloc context from which to allocate output data |
[in] | luctx | libusb context on which to operate |
[in] | dev_ids | zero-terminated array of VendorId/ProductId tuples |
References match_dev_ids().
Referenced by osmo_libusb_find_matching_interfaces(), and osmo_libusb_open_claim_interface().
libusb_device_handle * osmo_libusb_find_open_claim | ( | const struct osmo_usb_matchspec * | cfg, |
const struct dev_id * | default_dev_ids | ||
) |
high-level all-in-one function for USB device, config + interface matching + opening.
This function offers the highest level of API among all libosmousb helper functions. It is intended as a one-stop shop for everything related to grabbing an interface.
1) looks for a device matching either the VID/PID from 'cfg' or 'default_dev_ids', if more than one is found, the user is expected to fill in cfg->dev.path to disambiguate. 2) find any interfaces on the device that match the specification in 'cfg'. The match could be done based on any of (class, subclass, proto, interface number). If there are multiple matches, the caller must disambiguate by specifying the interface number. 3) open the USB device; set the configuration (if needed); claim the interface and set the altsetting
[in] | cfg | user-supplied match configuration (from command line or config file) |
[in] | default_dev_ids | Default list of supported VendorId/ProductIds |
References osmo_usb_matchspec::class, osmo_usb_matchspec::dev, DLUSB, osmo_usb_matchspec::intf, osmo_usb_matchspec::num, osmo_libusb_dev_find_matching_interfaces(), osmo_libusb_find_matching_dev_path(), osmo_libusb_open_claim_interface(), osmo_usb_matchspec::path, osmo_usb_matchspec::product_id, osmo_usb_matchspec::proto, osmo_usb_matchspec::subclass, and osmo_usb_matchspec::vendor_id.
int osmo_libusb_get_ep_addrs | ( | libusb_device_handle * | devh, |
unsigned int | if_num, | ||
uint8_t * | out, | ||
uint8_t * | in, | ||
uint8_t * | irq | ||
) |
obtain the endpoint addresses for a given USB interface.
[in] | devh | USB device handle on which to operate |
[in] | if_num | USB Interface number on which to operate |
[out] | out | user-provided storage for OUT endpoint number |
[out] | in | user-provided storage for IN endpoint number |
[out] | irq | user-provided storage for IRQ endpoint number |
int osmo_libusb_init | ( | libusb_context ** | luctx | ) |
References DLUSB, osmo_usb_added_cb(), and osmo_usb_removed_cb().
void osmo_libusb_match_init | ( | struct osmo_usb_matchspec * | cfg, |
int | if_class, | ||
int | if_subclass, | ||
int | if_proto | ||
) |
References osmo_usb_matchspec::altsetting, osmo_usb_matchspec::class, osmo_usb_matchspec::config_id, osmo_usb_matchspec::dev, osmo_usb_matchspec::intf, osmo_usb_matchspec::num, osmo_usb_matchspec::path, osmo_usb_matchspec::product_id, osmo_usb_matchspec::proto, osmo_usb_matchspec::subclass, and osmo_usb_matchspec::vendor_id.
libusb_device_handle * osmo_libusb_open_claim_interface | ( | void * | ctx, |
libusb_context * | luctx, | ||
const struct usb_interface_match * | ifm | ||
) |
open matching USB device and claim interface
[in] | ctx | talloc context to use for related allocations |
[in] | luctx | libusb context on which to operate |
[in] | ifm | interface match describing interface to claim |
References usb_interface_match::addr, usb_interface_match::altsetting, usb_interface_match::configuration, usb_interface_match::interface, osmo_libusb_dev_get_path_buf(), osmo_libusb_find_matching_usb_devs(), usb_interface_match::path, usb_interface_match::product, USB_MAX_PATH_LEN, and usb_interface_match::vendor.
Referenced by osmo_libusb_find_open_claim().