]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - include/usb.h
Attempt at getting the windows client to at least compile without bombing out with...
[proxmark3-svn] / include / usb.h
diff --git a/include/usb.h b/include/usb.h
new file mode 100644 (file)
index 0000000..04f5afa
--- /dev/null
@@ -0,0 +1,374 @@
+#ifndef __USB_H__\r
+#define __USB_H__\r
+\r
+#include <stdlib.h>\r
+\r
+/* \r
+ * 'interface' is defined somewhere in the Windows header files. This macro \r
+ * is deleted here to avoid conflicts and compile errors.\r
+ */\r
+\r
+#ifdef interface\r
+#undef interface\r
+#endif\r
+\r
+/*\r
+ * PATH_MAX from limits.h can't be used on Windows if the dll and\r
+ * import libraries are build/used by different compilers \r
+ */\r
+\r
+#define LIBUSB_PATH_MAX 512\r
+\r
+\r
+/*\r
+ * USB spec information\r
+ *\r
+ * This is all stuff grabbed from various USB specs and is pretty much\r
+ * not subject to change\r
+ */\r
+\r
+/*\r
+ * Device and/or Interface Class codes\r
+ */\r
+#define USB_CLASS_PER_INTERFACE                0       /* for DeviceClass */\r
+#define USB_CLASS_AUDIO                              1\r
+#define USB_CLASS_COMM                       2\r
+#define USB_CLASS_HID                          3\r
+#define USB_CLASS_PRINTER                    7\r
+#define USB_CLASS_MASS_STORAGE         8\r
+#define USB_CLASS_HUB                          9\r
+#define USB_CLASS_DATA                       10\r
+#define USB_CLASS_VENDOR_SPEC            0xff\r
+\r
+/*\r
+ * Descriptor types\r
+ */\r
+#define USB_DT_DEVICE                  0x01\r
+#define USB_DT_CONFIG                  0x02\r
+#define USB_DT_STRING                  0x03\r
+#define USB_DT_INTERFACE       0x04\r
+#define USB_DT_ENDPOINT                0x05\r
+\r
+#define USB_DT_HID                     0x21\r
+#define USB_DT_REPORT          0x22\r
+#define USB_DT_PHYSICAL        0x23\r
+#define USB_DT_HUB                     0x29\r
+\r
+/*\r
+ * Descriptor sizes per descriptor type\r
+ */\r
+#define USB_DT_DEVICE_SIZE             18\r
+#define USB_DT_CONFIG_SIZE             9\r
+#define USB_DT_INTERFACE_SIZE          9\r
+#define USB_DT_ENDPOINT_SIZE           7\r
+#define USB_DT_ENDPOINT_AUDIO_SIZE     9       /* Audio extension */\r
+#define USB_DT_HUB_NONVAR_SIZE         7\r
+\r
+\r
+/* ensure byte-packed structures */\r
+#include <pshpack1.h> \r
+\r
+\r
+/* All standard descriptors have these 2 fields in common */\r
+struct usb_descriptor_header {\r
+  unsigned char  bLength;\r
+  unsigned char  bDescriptorType;\r
+};\r
+\r
+/* String descriptor */\r
+struct usb_string_descriptor {\r
+  unsigned char  bLength;\r
+  unsigned char  bDescriptorType;\r
+  unsigned short wData[1];\r
+};\r
+\r
+/* HID descriptor */\r
+struct usb_hid_descriptor {\r
+  unsigned char  bLength;\r
+  unsigned char  bDescriptorType;\r
+  unsigned short bcdHID;\r
+  unsigned char  bCountryCode;\r
+  unsigned char  bNumDescriptors;\r
+};\r
+\r
+/* Endpoint descriptor */\r
+#define USB_MAXENDPOINTS       32\r
+struct usb_endpoint_descriptor {\r
+  unsigned char  bLength;\r
+  unsigned char  bDescriptorType;\r
+  unsigned char  bEndpointAddress;\r
+  unsigned char  bmAttributes;\r
+  unsigned short wMaxPacketSize;\r
+  unsigned char  bInterval;\r
+  unsigned char  bRefresh;\r
+  unsigned char  bSynchAddress;\r
+\r
+  unsigned char *extra;        /* Extra descriptors */\r
+  int extralen;\r
+};\r
+\r
+#define USB_ENDPOINT_ADDRESS_MASK      0x0f    /* in bEndpointAddress */\r
+#define USB_ENDPOINT_DIR_MASK            0x80\r
+\r
+#define USB_ENDPOINT_TYPE_MASK         0x03    /* in bmAttributes */\r
+#define USB_ENDPOINT_TYPE_CONTROL          0\r
+#define USB_ENDPOINT_TYPE_ISOCHRONOUS  1\r
+#define USB_ENDPOINT_TYPE_BULK             2\r
+#define USB_ENDPOINT_TYPE_INTERRUPT      3\r
+\r
+/* Interface descriptor */\r
+#define USB_MAXINTERFACES      32\r
+struct usb_interface_descriptor {\r
+  unsigned char  bLength;\r
+  unsigned char  bDescriptorType;\r
+  unsigned char  bInterfaceNumber;\r
+  unsigned char  bAlternateSetting;\r
+  unsigned char  bNumEndpoints;\r
+  unsigned char  bInterfaceClass;\r
+  unsigned char  bInterfaceSubClass;\r
+  unsigned char  bInterfaceProtocol;\r
+  unsigned char  iInterface;\r
+\r
+  struct usb_endpoint_descriptor *endpoint;\r
+\r
+  unsigned char *extra;        /* Extra descriptors */\r
+  int extralen;\r
+};\r
+\r
+#define USB_MAXALTSETTING      128     /* Hard limit */\r
+\r
+struct usb_interface {\r
+  struct usb_interface_descriptor *altsetting;\r
+\r
+  int num_altsetting;\r
+};\r
+\r
+/* Configuration descriptor information.. */\r
+#define USB_MAXCONFIG          8\r
+struct usb_config_descriptor {\r
+  unsigned char  bLength;\r
+  unsigned char  bDescriptorType;\r
+  unsigned short wTotalLength;\r
+  unsigned char  bNumInterfaces;\r
+  unsigned char  bConfigurationValue;\r
+  unsigned char  iConfiguration;\r
+  unsigned char  bmAttributes;\r
+  unsigned char  MaxPower;\r
+\r
+  struct usb_interface *interface;\r
+\r
+  unsigned char *extra;        /* Extra descriptors */\r
+  int extralen;\r
+};\r
+\r
+/* Device descriptor */\r
+struct usb_device_descriptor {\r
+  unsigned char  bLength;\r
+  unsigned char  bDescriptorType;\r
+  unsigned short bcdUSB;\r
+  unsigned char  bDeviceClass;\r
+  unsigned char  bDeviceSubClass;\r
+  unsigned char  bDeviceProtocol;\r
+  unsigned char  bMaxPacketSize0;\r
+  unsigned short idVendor;\r
+  unsigned short idProduct;\r
+  unsigned short bcdDevice;\r
+  unsigned char  iManufacturer;\r
+  unsigned char  iProduct;\r
+  unsigned char  iSerialNumber;\r
+  unsigned char  bNumConfigurations;\r
+};\r
+\r
+struct usb_ctrl_setup {\r
+  unsigned char  bRequestType;\r
+  unsigned char  bRequest;\r
+  unsigned short wValue;\r
+  unsigned short wIndex;\r
+  unsigned short wLength;\r
+};\r
+\r
+/*\r
+ * Standard requests\r
+ */\r
+#define USB_REQ_GET_STATUS                 0x00\r
+#define USB_REQ_CLEAR_FEATURE      0x01\r
+/* 0x02 is reserved */\r
+#define USB_REQ_SET_FEATURE                0x03\r
+/* 0x04 is reserved */\r
+#define USB_REQ_SET_ADDRESS                0x05\r
+#define USB_REQ_GET_DESCRIPTOR         0x06\r
+#define USB_REQ_SET_DESCRIPTOR         0x07\r
+#define USB_REQ_GET_CONFIGURATION      0x08\r
+#define USB_REQ_SET_CONFIGURATION      0x09\r
+#define USB_REQ_GET_INTERFACE            0x0A\r
+#define USB_REQ_SET_INTERFACE            0x0B\r
+#define USB_REQ_SYNCH_FRAME                0x0C\r
+\r
+#define USB_TYPE_STANDARD              (0x00 << 5)\r
+#define USB_TYPE_CLASS                 (0x01 << 5)\r
+#define USB_TYPE_VENDOR                        (0x02 << 5)\r
+#define USB_TYPE_RESERVED              (0x03 << 5)\r
+\r
+#define USB_RECIP_DEVICE               0x00\r
+#define USB_RECIP_INTERFACE    0x01\r
+#define USB_RECIP_ENDPOINT     0x02\r
+#define USB_RECIP_OTHER                        0x03\r
+\r
+/*\r
+ * Various libusb API related stuff\r
+ */\r
+\r
+#define USB_ENDPOINT_IN                        0x80\r
+#define USB_ENDPOINT_OUT               0x00\r
+\r
+/* Error codes */\r
+#define USB_ERROR_BEGIN                        500000\r
+\r
+/*\r
+ * This is supposed to look weird. This file is generated from autoconf\r
+ * and I didn't want to make this too complicated.\r
+ */\r
+#define USB_LE16_TO_CPU(x)\r
+\r
+/* Data types */\r
+/* struct usb_device; */\r
+/* struct usb_bus; */\r
+\r
+struct usb_device {\r
+  struct usb_device *next, *prev;\r
+\r
+  char filename[LIBUSB_PATH_MAX];\r
+\r
+  struct usb_bus *bus;\r
+\r
+  struct usb_device_descriptor descriptor;\r
+  struct usb_config_descriptor *config;\r
+\r
+  void *dev;           /* Darwin support */\r
+\r
+  unsigned char devnum;\r
+\r
+  unsigned char num_children;\r
+  struct usb_device **children;\r
+};\r
+\r
+struct usb_bus {\r
+  struct usb_bus *next, *prev;\r
+\r
+  char dirname[LIBUSB_PATH_MAX];\r
+\r
+  struct usb_device *devices;\r
+  unsigned long location;\r
+\r
+  struct usb_device *root_dev;\r
+};\r
+\r
+/* Version information, Windows specific */\r
+struct usb_version {\r
+  struct {\r
+    int major;\r
+    int minor;\r
+    int micro;\r
+    int nano;\r
+  } dll;\r
+  struct {\r
+    int major;\r
+    int minor;\r
+    int micro;\r
+    int nano;\r
+  } driver;\r
+};\r
+\r
+\r
+struct usb_dev_handle;\r
+typedef struct usb_dev_handle usb_dev_handle;\r
+\r
+/* Variables */\r
+extern struct usb_bus *usb_busses;\r
+\r
+\r
+#include <poppack.h>\r
+\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+  /* Function prototypes */\r
+\r
+  /* usb.c */\r
+  usb_dev_handle *usb_open(struct usb_device *dev);\r
+  int usb_close(usb_dev_handle *dev);\r
+  int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,\r
+                     size_t buflen);\r
+  int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,\r
+                            size_t buflen);\r
+\r
+  /* descriptors.c */\r
+  int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,\r
+                                     unsigned char type, unsigned char index,\r
+                                     void *buf, int size);\r
+  int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,\r
+                         unsigned char index, void *buf, int size);\r
+\r
+  /* <arch>.c */\r
+  int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,\r
+                     int timeout);\r
+  int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,\r
+                    int timeout);\r
+  int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,\r
+                          int timeout);\r
+  int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,\r
+                         int timeout);\r
+  int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,\r
+                      int value, int index, char *bytes, int size, \r
+                      int timeout);\r
+  int usb_set_configuration(usb_dev_handle *dev, int configuration);\r
+  int usb_claim_interface(usb_dev_handle *dev, int interface);\r
+  int usb_release_interface(usb_dev_handle *dev, int interface);\r
+  int usb_set_altinterface(usb_dev_handle *dev, int alternate);\r
+  int usb_resetep(usb_dev_handle *dev, unsigned int ep);\r
+  int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);\r
+  int usb_reset(usb_dev_handle *dev);\r
+\r
+  char *usb_strerror(void);\r
+\r
+  void usb_init(void);\r
+  void usb_set_debug(int level);\r
+  int usb_find_busses(void);\r
+  int usb_find_devices(void);\r
+  struct usb_device *usb_device(usb_dev_handle *dev);\r
+  struct usb_bus *usb_get_busses(void);\r
+\r
+\r
+  /* Windows specific functions */\r
+\r
+  #define LIBUSB_HAS_INSTALL_SERVICE_NP 1\r
+  int usb_install_service_np(void);\r
+\r
+  #define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1\r
+  int usb_uninstall_service_np(void);\r
+\r
+  #define LIBUSB_HAS_INSTALL_DRIVER_NP 1\r
+  int usb_install_driver_np(const char *inf_file);\r
+  \r
+  const struct usb_version *usb_get_version(void);\r
+\r
+  int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,\r
+                                  unsigned char ep, int pktsize);\r
+  int usb_bulk_setup_async(usb_dev_handle *dev, void **context,\r
+                           unsigned char ep);\r
+  int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,\r
+                                unsigned char ep);\r
+\r
+  int usb_submit_async(void *context, char *bytes, int size);\r
+  int usb_reap_async(void *context, int timeout);\r
+  int usb_free_async(void **context);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* __USB_H__ */\r
+\r
Impressum, Datenschutz