00001 #ifndef __USB_H__
00002 #define __USB_H__
00003
00004 #include <stdlib.h>
00005
00006
00007
00008
00009 #ifdef interface
00010 #undef interface
00011 #endif
00012
00013
00014
00015
00016 #define LIBUSB_PATH_MAX 512
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #define USB_CLASS_PER_INTERFACE 0
00030 #define USB_CLASS_AUDIO 1
00031 #define USB_CLASS_COMM 2
00032 #define USB_CLASS_HID 3
00033 #define USB_CLASS_PRINTER 7
00034 #define USB_CLASS_MASS_STORAGE 8
00035 #define USB_CLASS_HUB 9
00036 #define USB_CLASS_DATA 10
00037 #define USB_CLASS_VENDOR_SPEC 0xff
00038
00039
00040
00041
00042 #define USB_DT_DEVICE 0x01
00043 #define USB_DT_CONFIG 0x02
00044 #define USB_DT_STRING 0x03
00045 #define USB_DT_INTERFACE 0x04
00046 #define USB_DT_ENDPOINT 0x05
00047
00048 #define USB_DT_HID 0x21
00049 #define USB_DT_REPORT 0x22
00050 #define USB_DT_PHYSICAL 0x23
00051 #define USB_DT_HUB 0x29
00052
00053
00054
00055
00056 #define USB_DT_DEVICE_SIZE 18
00057 #define USB_DT_CONFIG_SIZE 9
00058 #define USB_DT_INTERFACE_SIZE 9
00059 #define USB_DT_ENDPOINT_SIZE 7
00060 #define USB_DT_ENDPOINT_AUDIO_SIZE 9
00061 #define USB_DT_HUB_NONVAR_SIZE 7
00062
00063
00064
00065
00066 #include <pshpack1.h>
00067
00068
00069
00070 struct usb_descriptor_header {
00071 unsigned char bLength;
00072 unsigned char bDescriptorType;
00073 };
00074
00075
00076 struct usb_string_descriptor {
00077 unsigned char bLength;
00078 unsigned char bDescriptorType;
00079 unsigned short wData[1];
00080 };
00081
00082
00083 struct usb_hid_descriptor {
00084 unsigned char bLength;
00085 unsigned char bDescriptorType;
00086 unsigned short bcdHID;
00087 unsigned char bCountryCode;
00088 unsigned char bNumDescriptors;
00089 };
00090
00091
00092 #define USB_MAXENDPOINTS 32
00093 struct usb_endpoint_descriptor {
00094 unsigned char bLength;
00095 unsigned char bDescriptorType;
00096 unsigned char bEndpointAddress;
00097 unsigned char bmAttributes;
00098 unsigned short wMaxPacketSize;
00099 unsigned char bInterval;
00100 unsigned char bRefresh;
00101 unsigned char bSynchAddress;
00102
00103 unsigned char *extra;
00104 int extralen;
00105 };
00106
00107 #define USB_ENDPOINT_ADDRESS_MASK 0x0f
00108 #define USB_ENDPOINT_DIR_MASK 0x80
00109
00110 #define USB_ENDPOINT_TYPE_MASK 0x03
00111 #define USB_ENDPOINT_TYPE_CONTROL 0
00112 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
00113 #define USB_ENDPOINT_TYPE_BULK 2
00114 #define USB_ENDPOINT_TYPE_INTERRUPT 3
00115
00116
00117 #define USB_MAXINTERFACES 32
00118 struct usb_interface_descriptor {
00119 unsigned char bLength;
00120 unsigned char bDescriptorType;
00121 unsigned char bInterfaceNumber;
00122 unsigned char bAlternateSetting;
00123 unsigned char bNumEndpoints;
00124 unsigned char bInterfaceClass;
00125 unsigned char bInterfaceSubClass;
00126 unsigned char bInterfaceProtocol;
00127 unsigned char iInterface;
00128
00129 struct usb_endpoint_descriptor *endpoint;
00130
00131 unsigned char *extra;
00132 int extralen;
00133 };
00134
00135 #define USB_MAXALTSETTING 128
00136 struct usb_interface {
00137 struct usb_interface_descriptor *altsetting;
00138
00139 int num_altsetting;
00140 };
00141
00142
00143 #define USB_MAXCONFIG 8
00144 struct usb_config_descriptor {
00145 unsigned char bLength;
00146 unsigned char bDescriptorType;
00147 unsigned short wTotalLength;
00148 unsigned char bNumInterfaces;
00149 unsigned char bConfigurationValue;
00150 unsigned char iConfiguration;
00151 unsigned char bmAttributes;
00152 unsigned char MaxPower;
00153
00154 struct usb_interface *interface;
00155
00156 unsigned char *extra;
00157 int extralen;
00158 };
00159
00160
00161 struct usb_device_descriptor {
00162 unsigned char bLength;
00163 unsigned char bDescriptorType;
00164 unsigned short bcdUSB;
00165 unsigned char bDeviceClass;
00166 unsigned char bDeviceSubClass;
00167 unsigned char bDeviceProtocol;
00168 unsigned char bMaxPacketSize0;
00169 unsigned short idVendor;
00170 unsigned short idProduct;
00171 unsigned short bcdDevice;
00172 unsigned char iManufacturer;
00173 unsigned char iProduct;
00174 unsigned char iSerialNumber;
00175 unsigned char bNumConfigurations;
00176 };
00177
00178 struct usb_ctrl_setup {
00179 unsigned char bRequestType;
00180 unsigned char bRequest;
00181 unsigned short wValue;
00182 unsigned short wIndex;
00183 unsigned short wLength;
00184 };
00185
00186
00187
00188
00189 #define USB_REQ_GET_STATUS 0x00
00190 #define USB_REQ_CLEAR_FEATURE 0x01
00191
00192 #define USB_REQ_SET_FEATURE 0x03
00193
00194 #define USB_REQ_SET_ADDRESS 0x05
00195 #define USB_REQ_GET_DESCRIPTOR 0x06
00196 #define USB_REQ_SET_DESCRIPTOR 0x07
00197 #define USB_REQ_GET_CONFIGURATION 0x08
00198 #define USB_REQ_SET_CONFIGURATION 0x09
00199 #define USB_REQ_GET_INTERFACE 0x0A
00200 #define USB_REQ_SET_INTERFACE 0x0B
00201 #define USB_REQ_SYNCH_FRAME 0x0C
00202
00203 #define USB_TYPE_STANDARD (0x00 << 5)
00204 #define USB_TYPE_CLASS (0x01 << 5)
00205 #define USB_TYPE_VENDOR (0x02 << 5)
00206 #define USB_TYPE_RESERVED (0x03 << 5)
00207
00208 #define USB_RECIP_DEVICE 0x00
00209 #define USB_RECIP_INTERFACE 0x01
00210 #define USB_RECIP_ENDPOINT 0x02
00211 #define USB_RECIP_OTHER 0x03
00212
00213
00214
00215
00216
00217 #define USB_ENDPOINT_IN 0x80
00218 #define USB_ENDPOINT_OUT 0x00
00219
00220
00221 #define USB_ERROR_BEGIN 500000
00222
00223
00224
00225
00226
00227 #define USB_LE16_TO_CPU(x)
00228
00229
00230 struct usb_device;
00231 struct usb_bus;
00232
00233 struct usb_device {
00234 struct usb_device *next, *prev;
00235
00236 char filename[LIBUSB_PATH_MAX];
00237
00238 struct usb_bus *bus;
00239
00240 struct usb_device_descriptor descriptor;
00241 struct usb_config_descriptor *config;
00242
00243 void *dev;
00244 };
00245
00246 struct usb_bus {
00247 struct usb_bus *next, *prev;
00248
00249 char dirname[LIBUSB_PATH_MAX];
00250
00251 struct usb_device *devices;
00252 unsigned long location;
00253 };
00254
00255
00256 struct usb_version {
00257 struct {
00258 int major;
00259 int minor;
00260 int micro;
00261 int nano;
00262 } dll;
00263 struct {
00264 int major;
00265 int minor;
00266 int micro;
00267 int nano;
00268 } driver;
00269 };
00270
00271
00272 struct usb_dev_handle;
00273 typedef struct usb_dev_handle usb_dev_handle;
00274
00275
00276 extern struct usb_bus *usb_busses;
00277
00278
00279 #include <poppack.h>
00280
00281
00282 #ifdef __cplusplus
00283 extern "C" {
00284 #endif
00285
00286
00287
00288
00289 usb_dev_handle *usb_open(struct usb_device *dev);
00290 int usb_close(usb_dev_handle *dev);
00291 int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
00292 size_t buflen);
00293 int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
00294 size_t buflen);
00295
00296
00297 int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
00298 unsigned char type, unsigned char index,
00299 void *buf, int size);
00300 int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
00301 unsigned char index, void *buf, int size);
00302
00303
00304 int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
00305 int timeout);
00306 int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
00307 int timeout);
00308 int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
00309 int timeout);
00310 int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
00311 int timeout);
00312 int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
00313 int value, int index, char *bytes, int size,
00314 int timeout);
00315 int usb_set_configuration(usb_dev_handle *dev, int configuration);
00316 int usb_claim_interface(usb_dev_handle *dev, int interface);
00317 int usb_release_interface(usb_dev_handle *dev, int interface);
00318 int usb_set_altinterface(usb_dev_handle *dev, int alternate);
00319 int usb_resetep(usb_dev_handle *dev, unsigned int ep);
00320 int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
00321 int usb_reset(usb_dev_handle *dev);
00322
00323 char *usb_strerror(void);
00324
00325 void usb_init(void);
00326 void usb_set_debug(int level);
00327 int usb_find_busses(void);
00328 int usb_find_devices(void);
00329 struct usb_device *usb_device(usb_dev_handle *dev);
00330 struct usb_bus *usb_get_busses(void);
00331
00332
00333 struct usb_version *usb_get_version(void);
00334
00335
00336 #ifdef __cplusplus
00337 }
00338 #endif
00339
00340 #endif
00341