blob: 382c86e1953fd1d5e70208a0208c2b17284e97e7 [file] [log] [blame]
Harald Welteda432cd2019-12-15 19:13:26 +01001#pragma once
Harald Welted462e3f2019-12-15 20:04:51 +01002/* 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 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
Harald Welteda432cd2019-12-15 19:13:26 +010020
21#include <libusb.h>
22
Harald Welted462e3f2019-12-15 20:04:51 +010023#define USB_MAX_PATH_LEN 20
24
25struct dev_id {
26 uint16_t vendor_id;
27 uint16_t product_id;
28};
29
30/* structure describing a single matching interface found */
31struct usb_interface_match {
32 /* libusb device E*/
33 libusb_device *usb_dev;
34 /* Vendor ID of the device running matching interface */
35 uint16_t vendor;
36 /* Product ID of the device running matching interface */
37 uint16_t product;
38 /* USB Bus Address */
39 uint8_t addr;
40 /* physical path */
41 char path[USB_MAX_PATH_LEN];
42 /* configuration of matching interface */
43 uint8_t configuration;
44 /* interface number of matching interface */
45 uint8_t interface;
46 /* altsetting of matching interface */
47 uint8_t altsetting;
48 /* bInterfaceClass of matching interface */
49 uint8_t class;
50 /* bInterfaceSubClass of matching interface */
51 uint8_t sub_class;
52 /* bInterfaceProtocol of matching interface */
53 uint8_t protocol;
54 /* index of string descriptor of matching interface */
55 uint8_t string_idx;
56};
57
58
59char *osmo_libusb_dev_get_path_buf(char *buf, size_t bufsize, libusb_device *dev);
60char *osmo_libusb_dev_get_path_c(void *ctx, libusb_device *dev);
61
62libusb_device **osmo_libusb_find_matching_usb_devs(void *ctx, struct libusb_context *luctx,
63 const struct dev_id *dev_ids);
64
65int osmo_libusb_dev_find_matching_interfaces(libusb_device *dev, int class, int sub_class,
66 int protocol, struct usb_interface_match *out,
67 unsigned int out_len);
68
69int osmo_libusb_find_matching_interfaces(libusb_context *luctx, const struct dev_id *dev_ids,
70 int class, int sub_class, int protocol,
71 struct usb_interface_match *out, unsigned int out_len);
72
73libusb_device_handle *osmo_libusb_open_claim_interface(void *ctx, libusb_context *luctx,
74 const struct usb_interface_match *ifm);
75
76int osmo_libusb_get_ep_addrs(libusb_device_handle *devh, unsigned int if_num,
77 uint8_t *out, uint8_t *in, uint8_t *irq);
78
79
Harald Welteda432cd2019-12-15 19:13:26 +010080int osmo_libusb_init(libusb_context **luctx);
81void osmo_libusb_exit(libusb_context *luctx);