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
00043
00063 #ifndef sanei_usb_h
00064 #define sanei_usb_h
00065
00066 #include "../include/sane/config.h"
00067 #include "../include/sane/sane.h"
00068
00069 #include <stdlib.h>
00070
00071
00072 #ifndef USB_CLASS_PER_INTERFACE
00073
00075
00076 #define USB_CLASS_PER_INTERFACE 0x00
00077 #define USB_CLASS_AUDIO 0x01
00078 #define USB_CLASS_COMM 0x02
00079 #define USB_CLASS_HID 0x03
00080 #define USB_CLASS_PRINTER 0x07
00081 #define USB_CLASS_MASS_STORAGE 0x08
00082 #define USB_CLASS_HUB 0x09
00083 #define USB_CLASS_DATA 0x0a
00084 #define USB_CLASS_VENDOR_SPEC 0xff
00085
00086
00088
00089 #define USB_DT_DEVICE 0x01
00090 #define USB_DT_CONFIG 0x02
00091 #define USB_DT_STRING 0x03
00092 #define USB_DT_INTERFACE 0x04
00093 #define USB_DT_ENDPOINT 0x05
00094 #define USB_DT_HID 0x21
00095 #define USB_DT_REPORT 0x22
00096 #define USB_DT_PHYSICAL 0x23
00097 #define USB_DT_HUB 0x29
00098
00099
00101
00102 #define USB_DT_DEVICE_SIZE 18
00103 #define USB_DT_CONFIG_SIZE 9
00104 #define USB_DT_INTERFACE_SIZE 9
00105 #define USB_DT_ENDPOINT_SIZE 7
00106 #define USB_DT_ENDPOINT_AUDIO_SIZE 9
00107 #define USB_DT_HUB_NONVAR_SIZE 7
00108
00109
00111
00112 #define USB_ENDPOINT_ADDRESS_MASK 0x0f
00113 #define USB_ENDPOINT_DIR_MASK 0x80
00114 #define USB_ENDPOINT_TYPE_MASK 0x03
00115 #define USB_ENDPOINT_TYPE_CONTROL 0
00116 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
00117 #define USB_ENDPOINT_TYPE_BULK 2
00118 #define USB_ENDPOINT_TYPE_INTERRUPT 3
00119
00120
00122
00123 #define USB_REQ_GET_STATUS 0x00
00124 #define USB_REQ_CLEAR_FEATURE 0x01
00125 #define USB_REQ_SET_FEATURE 0x03
00126 #define USB_REQ_SET_ADDRESS 0x05
00127 #define USB_REQ_GET_DESCRIPTOR 0x06
00128 #define USB_REQ_SET_DESCRIPTOR 0x07
00129 #define USB_REQ_GET_CONFIGURATION 0x08
00130 #define USB_REQ_SET_CONFIGURATION 0x09
00131 #define USB_REQ_GET_INTERFACE 0x0A
00132 #define USB_REQ_SET_INTERFACE 0x0B
00133 #define USB_REQ_SYNCH_FRAME 0x0C
00134
00135
00137
00138 #define USB_TYPE_STANDARD (0x00 << 5)
00139 #define USB_TYPE_CLASS (0x01 << 5)
00140 #define USB_TYPE_VENDOR (0x02 << 5)
00141 #define USB_TYPE_RESERVED (0x03 << 5)
00142
00143
00145
00146 #define USB_RECIP_DEVICE 0x00
00147 #define USB_RECIP_INTERFACE 0x01
00148 #define USB_RECIP_ENDPOINT 0x02
00149 #define USB_RECIP_OTHER 0x03
00150
00151
00152 #endif
00153
00154
00156
00157 #define USB_TYPE_MASK (0x03 << 5)
00158 #define USB_RECIP_MASK 0x1f
00159
00160
00162
00163 #define USB_DIR_OUT 0x00
00164 #define USB_DIR_IN 0x80
00165
00166
00168 struct sanei_usb_dev_descriptor
00169 {
00170 SANE_Byte desc_type;
00171 unsigned int bcd_usb;
00172 unsigned int bcd_dev;
00173 SANE_Byte dev_class;
00174 SANE_Byte dev_sub_class;
00175 SANE_Byte dev_protocol;
00176 SANE_Byte max_packet_size;
00177 };
00178
00183 extern void sanei_usb_init (void);
00184
00197 SANE_Status
00198 sanei_usb_get_vendor_product_byname (SANE_String_Const devname,
00199 SANE_Word * vendor, SANE_Word * product);
00200
00215 extern SANE_Status
00216 sanei_usb_get_vendor_product (SANE_Int dn, SANE_Word * vendor,
00217 SANE_Word * product);
00218
00230 extern SANE_Status
00231 sanei_usb_find_devices (SANE_Int vendor, SANE_Int product,
00232 SANE_Status (*attach) (SANE_String_Const devname));
00233
00254 extern SANE_Status sanei_usb_open (SANE_String_Const devname, SANE_Int * dn);
00255
00268 extern void sanei_usb_set_endpoint (SANE_Int dn, SANE_Int ep_type, SANE_Int ep);
00269
00281 extern SANE_Int sanei_usb_get_endpoint (SANE_Int dn, SANE_Int ep_type);
00282
00287 extern void sanei_usb_close (SANE_Int dn);
00288
00293 extern void sanei_usb_set_timeout (SANE_Int timeout);
00294
00297 #define HAVE_SANEI_USB_SET_TIMEOUT
00298
00303 extern SANE_Status sanei_usb_clear_halt (SANE_Int dn);
00304
00307 #define HAVE_SANEI_USB_CLEAR_HALT
00308
00313 extern SANE_Status sanei_usb_reset (SANE_Int dn);
00314
00331 extern SANE_Status
00332 sanei_usb_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size);
00333
00348 extern SANE_Status
00349 sanei_usb_write_bulk (SANE_Int dn, const SANE_Byte * buffer, size_t * size);
00350
00375 extern SANE_Status
00376 sanei_usb_control_msg (SANE_Int dn, SANE_Int rtype, SANE_Int req,
00377 SANE_Int value, SANE_Int index, SANE_Int len,
00378 SANE_Byte * data);
00379
00397 extern SANE_Status
00398 sanei_usb_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size);
00399
00416 extern void
00417 sanei_usb_attach_matching_devices (const char *name,
00418 SANE_Status (*attach) (const char *dev));
00419
00435 extern SANE_Status
00436 sanei_usb_set_configuration (SANE_Int dn, SANE_Int configuration);
00437
00453 extern SANE_Status
00454 sanei_usb_claim_interface (SANE_Int dn, SANE_Int interface_number);
00455
00471 extern SANE_Status
00472 sanei_usb_release_interface (SANE_Int dn, SANE_Int interface_number);
00473
00489 extern SANE_Status
00490 sanei_usb_set_altinterface (SANE_Int dn, SANE_Int alternate);
00491
00508 extern SANE_Status
00509 sanei_usb_get_descriptor( SANE_Int dn, struct sanei_usb_dev_descriptor *desc );
00510
00511
00512 #endif