00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00062 #ifndef sanei_usb_h
00063 #define sanei_usb_h
00064
00065 #include "../include/sane/config.h"
00066 #include "../include/sane/sane.h"
00067
00068 #include <stdlib.h>
00069
00070
00071 #ifndef USB_CLASS_PER_INTERFACE
00072
00074
00075 #define USB_CLASS_PER_INTERFACE 0x00
00076 #define USB_CLASS_AUDIO 0x01
00077 #define USB_CLASS_COMM 0x02
00078 #define USB_CLASS_HID 0x03
00079 #define USB_CLASS_PRINTER 0x07
00080 #define USB_CLASS_MASS_STORAGE 0x08
00081 #define USB_CLASS_HUB 0x09
00082 #define USB_CLASS_DATA 0x0a
00083 #define USB_CLASS_VENDOR_SPEC 0xff
00084
00085
00087
00088 #define USB_DT_DEVICE 0x01
00089 #define USB_DT_CONFIG 0x02
00090 #define USB_DT_STRING 0x03
00091 #define USB_DT_INTERFACE 0x04
00092 #define USB_DT_ENDPOINT 0x05
00093 #define USB_DT_HID 0x21
00094 #define USB_DT_REPORT 0x22
00095 #define USB_DT_PHYSICAL 0x23
00096 #define USB_DT_HUB 0x29
00097
00098
00100
00101 #define USB_DT_DEVICE_SIZE 18
00102 #define USB_DT_CONFIG_SIZE 9
00103 #define USB_DT_INTERFACE_SIZE 9
00104 #define USB_DT_ENDPOINT_SIZE 7
00105 #define USB_DT_ENDPOINT_AUDIO_SIZE 9
00106 #define USB_DT_HUB_NONVAR_SIZE 7
00107
00108
00110
00111 #define USB_ENDPOINT_ADDRESS_MASK 0x0f
00112 #define USB_ENDPOINT_DIR_MASK 0x80
00113 #define USB_ENDPOINT_TYPE_MASK 0x03
00114 #define USB_ENDPOINT_TYPE_CONTROL 0
00115 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
00116 #define USB_ENDPOINT_TYPE_BULK 2
00117 #define USB_ENDPOINT_TYPE_INTERRUPT 3
00118
00119
00121
00122 #define USB_REQ_GET_STATUS 0x00
00123 #define USB_REQ_CLEAR_FEATURE 0x01
00124 #define USB_REQ_SET_FEATURE 0x03
00125 #define USB_REQ_SET_ADDRESS 0x05
00126 #define USB_REQ_GET_DESCRIPTOR 0x06
00127 #define USB_REQ_SET_DESCRIPTOR 0x07
00128 #define USB_REQ_GET_CONFIGURATION 0x08
00129 #define USB_REQ_SET_CONFIGURATION 0x09
00130 #define USB_REQ_GET_INTERFACE 0x0A
00131 #define USB_REQ_SET_INTERFACE 0x0B
00132 #define USB_REQ_SYNCH_FRAME 0x0C
00133
00134
00136
00137 #define USB_TYPE_STANDARD (0x00 << 5)
00138 #define USB_TYPE_CLASS (0x01 << 5)
00139 #define USB_TYPE_VENDOR (0x02 << 5)
00140 #define USB_TYPE_RESERVED (0x03 << 5)
00141
00142
00144
00145 #define USB_RECIP_DEVICE 0x00
00146 #define USB_RECIP_INTERFACE 0x01
00147 #define USB_RECIP_ENDPOINT 0x02
00148 #define USB_RECIP_OTHER 0x03
00149
00150
00151 #endif
00152
00153
00155
00156 #define USB_TYPE_MASK (0x03 << 5)
00157 #define USB_RECIP_MASK 0x1f
00158
00159
00161
00162 #define USB_DIR_OUT 0x00
00163 #define USB_DIR_IN 0x80
00164
00165
00167 struct sanei_usb_dev_descriptor
00168 {
00169 SANE_Byte desc_type;
00170 unsigned int bcd_usb;
00171 unsigned int bcd_dev;
00172 SANE_Byte dev_class;
00173 SANE_Byte dev_sub_class;
00174 SANE_Byte dev_protocol;
00175 SANE_Byte max_packet_size;
00176 };
00177
00182 extern void sanei_usb_init (void);
00183
00196 SANE_Status
00197 sanei_usb_get_vendor_product_byname (SANE_String_Const devname,
00198 SANE_Word * vendor, SANE_Word * product);
00199
00214 extern SANE_Status
00215 sanei_usb_get_vendor_product (SANE_Int dn, SANE_Word * vendor,
00216 SANE_Word * product);
00217
00229 extern SANE_Status
00230 sanei_usb_find_devices (SANE_Int vendor, SANE_Int product,
00231 SANE_Status (*attach) (SANE_String_Const devname));
00232
00253 extern SANE_Status sanei_usb_open (SANE_String_Const devname, SANE_Int * dn);
00254
00259 extern void sanei_usb_close (SANE_Int dn);
00260
00265 extern void sanei_usb_set_timeout (SANE_Int timeout);
00266
00269 #define HAVE_SANEI_USB_SET_TIMEOUT
00270
00275 extern SANE_Status sanei_usb_clear_halt (SANE_Int dn);
00276
00279 #define HAVE_SANEI_USB_CLEAR_HALT
00280
00297 extern SANE_Status
00298 sanei_usb_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size);
00299
00314 extern SANE_Status
00315 sanei_usb_write_bulk (SANE_Int dn, const SANE_Byte * buffer, size_t * size);
00316
00341 extern SANE_Status
00342 sanei_usb_control_msg (SANE_Int dn, SANE_Int rtype, SANE_Int req,
00343 SANE_Int value, SANE_Int index, SANE_Int len,
00344 SANE_Byte * data);
00345
00363 extern SANE_Status
00364 sanei_usb_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size);
00365
00382 extern void
00383 sanei_usb_attach_matching_devices (const char *name,
00384 SANE_Status (*attach) (const char *dev));
00385
00401 extern SANE_Status
00402 sanei_usb_set_configuration (SANE_Int dn, SANE_Int configuration);
00403
00419 extern SANE_Status
00420 sanei_usb_claim_interface (SANE_Int dn, SANE_Int interface_number);
00421
00437 extern SANE_Status
00438 sanei_usb_release_interface (SANE_Int dn, SANE_Int interface_number);
00439
00455 extern SANE_Status
00456 sanei_usb_set_altinterface (SANE_Int dn, SANE_Int alternate);
00457
00474 extern SANE_Status
00475 sanei_usb_get_descriptor( SANE_Int dn, struct sanei_usb_dev_descriptor *desc );
00476
00477
00478 #endif