UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / win32 / libusb-winusb-bridge.h
blob210ae2902c5086bd5b2d5b9bdb090f5424da9687
1 /*
2 * libusb-winusb-bridge.h
4 * Simple backend for libusb using MS WinUsb. Only the basic functions
5 * necessary for apcupsd are implemented, although the others could be added
6 * fairly easily.
7 */
9 /*
10 * Copyright (C) 2010 Adam Kropelin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General
14 * Public License as published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public
22 * License along with this program; if not, write to the Free
23 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 * MA 02111-1307, USA.
27 #ifndef __LIBUSB_WINUSB_BRIDGE_H
28 #define __LIBUSB_WINUSB_BRIDGE_H
30 #include "winusb.h"
31 #include <limits.h>
33 // Make old libusb constants from WinUSB constants
34 #define USB_ENDPOINT_IN USB_ENDPOINT_DIRECTION_MASK
35 #define USB_ENDPOINT_OUT 0
36 #define USB_RECIP_INTERFACE (BMREQUEST_TO_INTERFACE << 0)
37 #define USB_TYPE_CLASS (BMREQUEST_CLASS << 5)
38 #define USB_REQ_GET_DESCRIPTOR USB_REQUEST_GET_DESCRIPTOR
39 #define USB_DT_REPORT 0x22
40 #define USB_REQ_GET_REPORT 0x01
41 #define USB_REQ_SET_REPORT 0x09
43 // usb device descriptor
44 struct usb_device_descriptor
46 UCHAR bLength;
47 UCHAR bDescriptorType;
48 USHORT bcdUSB;
49 UCHAR bDeviceClass;
50 UCHAR bDeviceSubClass;
51 UCHAR bDeviceProtocol;
52 UCHAR bMaxPacketSize0;
53 USHORT idVendor;
54 USHORT idProduct;
55 USHORT bcdDevice;
56 UCHAR iManufacturer;
57 UCHAR iProduct;
58 UCHAR iSerialNumber;
59 UCHAR bNumConfigurations;
62 // libusb structures, abbreviated
63 struct usb_bus;
64 struct usb_device
66 struct usb_device *next, *prev;
67 char filename[PATH_MAX + 1];
68 struct usb_bus *bus;
69 struct usb_device_descriptor descriptor;
72 struct usb_bus
74 struct usb_bus *next, *prev;
75 char dirname[PATH_MAX + 1];
76 struct usb_device *devices;
79 struct usb_dev_handle;
80 typedef struct usb_dev_handle usb_dev_handle;
82 // libusb function prototypes (just the ones we support)
83 usb_dev_handle *usb_open(struct usb_device *dev);
84 int usb_close(usb_dev_handle *dev);
85 int usb_get_string_simple(
86 usb_dev_handle *dev, int index, char *buf, size_t buflen);
87 int usb_interrupt_read(
88 usb_dev_handle *dev, int ep, char *bytes, int size, int timeout);
89 int usb_control_msg(
90 usb_dev_handle *dev, int requesttype, int request, int value,
91 int index, char *bytes, int size, int timeout);
92 int usb_set_configuration(usb_dev_handle *dev, int configuration);
93 int usb_claim_interface(usb_dev_handle *dev, int iface);
94 int usb_reset(usb_dev_handle *dev);
95 char *usb_strerror(void);
96 void usb_init(void);
97 void usb_set_debug(int level);
98 int usb_find_busses(void);
99 int usb_find_devices(void);
100 struct usb_bus *usb_get_busses(void);
102 #endif // __LIBUSB_WINUSB_BRIDGE_H