diff options
Diffstat (limited to 'lib/vusb/libs-host/opendevice.h')
-rw-r--r-- | lib/vusb/libs-host/opendevice.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/vusb/libs-host/opendevice.h b/lib/vusb/libs-host/opendevice.h new file mode 100644 index 000000000..c92527634 --- /dev/null +++ b/lib/vusb/libs-host/opendevice.h | |||
@@ -0,0 +1,76 @@ | |||
1 | /* Name: opendevice.h | ||
2 | * Project: V-USB host-side library | ||
3 | * Author: Christian Starkjohann | ||
4 | * Creation Date: 2008-04-10 | ||
5 | * Tabsize: 4 | ||
6 | * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH | ||
7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | General Description: | ||
12 | This module offers additional functionality for host side drivers based on | ||
13 | libusb or libusb-win32. It includes a function to find and open a device | ||
14 | based on numeric IDs and textual description. It also includes a function to | ||
15 | obtain textual descriptions from a device. | ||
16 | |||
17 | To use this functionality, simply copy opendevice.c and opendevice.h into your | ||
18 | project and add them to your Makefile. You may modify and redistribute these | ||
19 | files according to the GNU General Public License (GPL) version 2 or 3. | ||
20 | */ | ||
21 | |||
22 | #ifndef __OPENDEVICE_H_INCLUDED__ | ||
23 | #define __OPENDEVICE_H_INCLUDED__ | ||
24 | |||
25 | #include <usb.h> /* this is libusb, see http://libusb.sourceforge.net/ */ | ||
26 | #include <stdio.h> | ||
27 | |||
28 | int usbGetStringAscii(usb_dev_handle *dev, int index, char *buf, int buflen); | ||
29 | /* This function gets a string descriptor from the device. 'index' is the | ||
30 | * string descriptor index. The string is returned in ISO Latin 1 encoding in | ||
31 | * 'buf' and it is terminated with a 0-character. The buffer size must be | ||
32 | * passed in 'buflen' to prevent buffer overflows. A libusb device handle | ||
33 | * must be given in 'dev'. | ||
34 | * Returns: The length of the string (excluding the terminating 0) or | ||
35 | * a negative number in case of an error. If there was an error, use | ||
36 | * usb_strerror() to obtain the error message. | ||
37 | */ | ||
38 | |||
39 | int usbOpenDevice(usb_dev_handle **device, int vendorID, char *vendorNamePattern, int productID, char *productNamePattern, char *serialNamePattern, FILE *printMatchingDevicesFp, FILE *warningsFp); | ||
40 | /* This function iterates over all devices on all USB busses and searches for | ||
41 | * a device. Matching is done first by means of Vendor- and Product-ID (passed | ||
42 | * in 'vendorID' and 'productID'. An ID of 0 matches any numeric ID (wildcard). | ||
43 | * When a device matches by its IDs, matching by names is performed. Name | ||
44 | * matching can be done on textual vendor name ('vendorNamePattern'), product | ||
45 | * name ('productNamePattern') and serial number ('serialNamePattern'). A | ||
46 | * device matches only if all non-null pattern match. If you don't care about | ||
47 | * a string, pass NULL for the pattern. Patterns are Unix shell style pattern: | ||
48 | * '*' stands for 0 or more characters, '?' for one single character, a list | ||
49 | * of characters in square brackets for a single character from the list | ||
50 | * (dashes are allowed to specify a range) and if the lis of characters begins | ||
51 | * with a caret ('^'), it matches one character which is NOT in the list. | ||
52 | * Other parameters to the function: If 'warningsFp' is not NULL, warning | ||
53 | * messages are printed to this file descriptor with fprintf(). If | ||
54 | * 'printMatchingDevicesFp' is not NULL, no device is opened but matching | ||
55 | * devices are printed to the given file descriptor with fprintf(). | ||
56 | * If a device is opened, the resulting USB handle is stored in '*device'. A | ||
57 | * pointer to a "usb_dev_handle *" type variable must be passed here. | ||
58 | * Returns: 0 on success, an error code (see defines below) on failure. | ||
59 | */ | ||
60 | |||
61 | /* usbOpenDevice() error codes: */ | ||
62 | #define USBOPEN_SUCCESS 0 /* no error */ | ||
63 | #define USBOPEN_ERR_ACCESS 1 /* not enough permissions to open device */ | ||
64 | #define USBOPEN_ERR_IO 2 /* I/O error */ | ||
65 | #define USBOPEN_ERR_NOTFOUND 3 /* device not found */ | ||
66 | |||
67 | |||
68 | /* Obdev's free USB IDs, see USB-IDs-for-free.txt for details */ | ||
69 | |||
70 | #define USB_VID_OBDEV_SHARED 5824 /* obdev's shared vendor ID */ | ||
71 | #define USB_PID_OBDEV_SHARED_CUSTOM 1500 /* shared PID for custom class devices */ | ||
72 | #define USB_PID_OBDEV_SHARED_HID 1503 /* shared PID for HIDs except mice & keyboards */ | ||
73 | #define USB_PID_OBDEV_SHARED_CDCACM 1505 /* shared PID for CDC Modem devices */ | ||
74 | #define USB_PID_OBDEV_SHARED_MIDI 1508 /* shared PID for MIDI class devices */ | ||
75 | |||
76 | #endif /* __OPENDEVICE_H_INCLUDED__ */ | ||