Kévin Redon | 26a6609 | 2018-10-10 00:30:23 +0200 | [diff] [blame] | 1 | /* libisb utilities |
| 2 | * |
| 3 | * (C) 2010-2016 by Harald Welte <hwelte@hmw-consulting.de> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #pragma once |
| 20 | |
| 21 | #include <libusb.h> |
| 22 | |
| 23 | #define USB_MAX_PATH_LEN 20 |
| 24 | |
| 25 | struct dev_id { |
| 26 | uint16_t vendor_id; |
| 27 | uint16_t product_id; |
| 28 | }; |
| 29 | |
| 30 | /* Find any USB devices in the system matching the given Vendor and |
| 31 | * Product ID */ |
| 32 | libusb_device **find_matching_usb_devs(const struct dev_id *dev_ids); |
| 33 | |
| 34 | /* structure describing a single matching interface found */ |
| 35 | struct usb_interface_match { |
| 36 | /* libusb device E*/ |
| 37 | libusb_device *usb_dev; |
| 38 | /* Vendor ID of the device running matching interface */ |
| 39 | uint16_t vendor; |
| 40 | /* Product ID of the device running matching interface */ |
| 41 | uint16_t product; |
| 42 | /* USB Bus Address */ |
| 43 | uint8_t addr; |
| 44 | /* physical path */ |
| 45 | char path[USB_MAX_PATH_LEN]; |
| 46 | /* configuration of matching interface */ |
| 47 | uint8_t configuration; |
| 48 | /* interface number of matching interface */ |
| 49 | uint8_t interface; |
| 50 | /* altsetting of matching interface */ |
| 51 | uint8_t altsetting; |
| 52 | /* bInterfaceClass of matching interface */ |
| 53 | uint8_t class; |
| 54 | /* bInterfaceSubClass of matching interface */ |
| 55 | uint8_t sub_class; |
| 56 | /* bInterfaceProtocol of matching interface */ |
| 57 | uint8_t protocol; |
| 58 | /* index of string descriptor of matching interface */ |
| 59 | uint8_t string_idx; |
| 60 | }; |
| 61 | |
| 62 | int dev_find_matching_interfaces(libusb_device *dev, int class, int sub_class, int protocol, |
| 63 | struct usb_interface_match *out, unsigned int out_len); |
| 64 | |
| 65 | int usb_match_interfaces(libusb_context *ctx, const struct dev_id *dev_ids, |
| 66 | int class, int sub_class, int protocol, |
| 67 | struct usb_interface_match *out, unsigned int out_len); |
| 68 | |
| 69 | libusb_device_handle *usb_open_claim_interface(libusb_context *ctx, |
| 70 | const struct usb_interface_match *ifm); |