libosmousb 1.13.1.1-afb4 Osmocom USB library

libusb.h
Go to the documentation of this file.
1#pragma once
2/* libusb utilities
3 *
4 * (C) 2010-2019 by Harald Welte <hwelte@hmw-consulting.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <libusb.h>
18
19#define USB_MAX_PATH_LEN 20
20
21 struct dev_id {
22 uint16_t vendor_id;
23 uint16_t product_id;
24};
25
26/* structure describing a single matching interface found */
27 struct usb_interface_match {
28 /* libusb device E*/
29 libusb_device *usb_dev;
30 /* Vendor ID of the device running matching interface */
31 uint16_t vendor;
32 /* Product ID of the device running matching interface */
33 uint16_t product;
34 /* USB Bus Address */
35 uint8_t addr;
36 /* physical path */
37 char path[USB_MAX_PATH_LEN];
38 /* configuration of matching interface */
39 uint8_t configuration;
40 /* interface number of matching interface */
41 uint8_t interface;
42 /* altsetting of matching interface */
43 uint8_t altsetting;
44 /* bInterfaceClass of matching interface */
45 uint8_t class;
46 /* bInterfaceSubClass of matching interface */
47 uint8_t sub_class;
48 /* bInterfaceProtocol of matching interface */
49 uint8_t protocol;
50 /* index of string descriptor of matching interface */
51 uint8_t string_idx;
52};
53
55 struct osmo_usb_matchspec {
57 struct {
58 int vendor_id;
59 int product_id;
60 char *path;
61 } dev;
62
64 int config_id;
67 struct {
68 /* typically those three are set to application defaults */
69 int class;
70 int subclass;
71 int proto;
73 /* typically those two are -1; but user can override them */
74 int num;
75 int altsetting;
76 } intf;
77};
78
79
80 char *osmo_libusb_dev_get_path_buf(char *buf, size_t bufsize, libusb_device *dev);
81 char *osmo_libusb_dev_get_path_c(void *ctx, libusb_device *dev);
82
83libusb_device **osmo_libusb_find_matching_usb_devs(void *ctx, struct libusb_context *luctx,
84 const struct dev_id *dev_ids);
85
86libusb_device *osmo_libusb_find_matching_dev_path(struct libusb_context *luctx,
87 const struct dev_id *dev_ids,
88 const char *path);
89
90libusb_device *osmo_libusb_find_matching_dev_serial(struct libusb_context *luctx,
91 const struct dev_id *dev_ids,
92 const char *serial);
93
94 int osmo_libusb_dev_find_matching_interfaces(libusb_device *dev, int class, int sub_class,
95 int protocol, struct usb_interface_match *out,
96 unsigned int out_len);
97
98 int osmo_libusb_find_matching_interfaces(libusb_context *luctx, const struct dev_id *dev_ids,
99 int class, int sub_class, int protocol,
100 struct usb_interface_match *out, unsigned int out_len);
101
102libusb_device_handle *osmo_libusb_open_claim_interface(void *ctx, libusb_context *luctx,
103 const struct usb_interface_match *ifm);
104
105 void osmo_libusb_match_init(struct osmo_usb_matchspec *cfg, int if_class, int if_subclass, int if_proto);
106
107libusb_device_handle *osmo_libusb_find_open_claim(const struct osmo_usb_matchspec *cfg,
108 const struct dev_id *default_dev_ids);
109
110 int osmo_libusb_get_ep_addrs(libusb_device_handle *devh, unsigned int if_num,
111 uint8_t *out, uint8_t *in, uint8_t *irq);
112
113
114 int osmo_libusb_init(libusb_context **luctx);
115 void osmo_libusb_exit(libusb_context *luctx);
libusb.h
osmo_libusb_open_claim_interface
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
Definition: osmo_libusb.c:517
osmo_libusb_find_open_claim
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.
Definition: osmo_libusb.c:622
osmo_libusb_get_ep_addrs
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.
Definition: osmo_libusb.c:693
osmo_libusb_match_init
void osmo_libusb_match_init(struct osmo_usb_matchspec *cfg, int if_class, int if_subclass, int if_proto)
Definition: osmo_libusb.c:590
osmo_libusb_dev_get_path_c
char * osmo_libusb_dev_get_path_c(void *ctx, libusb_device *dev)
obtain the string representation of the USB device path of given device.
Definition: osmo_libusb.c:142
osmo_libusb_find_matching_dev_path
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.
Definition: osmo_libusb.c:227
osmo_libusb_exit
void osmo_libusb_exit(libusb_context *luctx)
Definition: osmo_libusb.c:772
osmo_libusb_init
int osmo_libusb_init(libusb_context **luctx)
Definition: osmo_libusb.c:736
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.
Definition: osmo_libusb.c:173
osmo_libusb_find_matching_dev_serial
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.
Definition: osmo_libusb.c:293
osmo_libusb_dev_get_path_buf
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.
Definition: osmo_libusb.c:117
osmo_libusb_find_matching_interfaces
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.
Definition: osmo_libusb.c:457
USB_MAX_PATH_LEN
#define USB_MAX_PATH_LEN
Definition: libusb.h:19
osmo_libusb_dev_find_matching_interfaces
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.
Definition: osmo_libusb.c:382
dev_id
Definition: libusb.h:21
dev_id::product_id
uint16_t product_id
Definition: libusb.h:23
dev_id::vendor_id
uint16_t vendor_id
Definition: libusb.h:22
osmo_usb_matchspec
Description of the USB device+interface we're looking for.
Definition: libusb.h:55
osmo_usb_matchspec::path
char * path
used for disambiguation when multiple matches; can be NULL
Definition: libusb.h:60
osmo_usb_matchspec::altsetting
int altsetting
Definition: libusb.h:75
osmo_usb_matchspec::intf
struct osmo_usb_matchspec::@1 intf
specify the USB interface
osmo_usb_matchspec::dev
struct osmo_usb_matchspec::@0 dev
specify the USB device
osmo_usb_matchspec::vendor_id
int vendor_id
typically -1 for compile time defaults
Definition: libusb.h:58
osmo_usb_matchspec::config_id
int config_id
specify the USB configuration
Definition: libusb.h:64
osmo_usb_matchspec::num
int num
Definition: libusb.h:74
osmo_usb_matchspec::product_id
int product_id
typically -1 for compile time defaults
Definition: libusb.h:59
osmo_usb_matchspec::subclass
int subclass
-1 or a user-specified subclass
Definition: libusb.h:70
osmo_usb_matchspec::proto
int proto
-1 or a user-specified protocol
Definition: libusb.h:71
usb_interface_match
Definition: libusb.h:27
usb_interface_match::product
uint16_t product
Definition: libusb.h:33
usb_interface_match::altsetting
uint8_t altsetting
Definition: libusb.h:43
usb_interface_match::sub_class
uint8_t sub_class
Definition: libusb.h:47
usb_interface_match::vendor
uint16_t vendor
Definition: libusb.h:31
usb_interface_match::protocol
uint8_t protocol
Definition: libusb.h:49
usb_interface_match::path
char path[USB_MAX_PATH_LEN]
Definition: libusb.h:37
usb_interface_match::usb_dev
libusb_device * usb_dev
Definition: libusb.h:29
usb_interface_match::interface
uint8_t interface
Definition: libusb.h:41
usb_interface_match::addr
uint8_t addr
Definition: libusb.h:35
usb_interface_match::configuration
uint8_t configuration
Definition: libusb.h:39
usb_interface_match::string_idx
uint8_t string_idx
Definition: libusb.h:51