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
00061 #ifndef sanei_usb_h
00062 #define sanei_usb_h
00063
00064 #include "../include/sane/config.h"
00065 #include "../include/sane/sane.h"
00066
00067 #include <stdlib.h>
00068
00069
00070 #ifndef USB_CLASS_PER_INTERFACE
00071
00073
00074 #define USB_CLASS_PER_INTERFACE 0x00
00075 #define USB_CLASS_AUDIO 0x01
00076 #define USB_CLASS_COMM 0x02
00077 #define USB_CLASS_HID 0x03
00078 #define USB_CLASS_PRINTER 0x07
00079 #define USB_CLASS_MASS_STORAGE 0x08
00080 #define USB_CLASS_HUB 0x09
00081 #define USB_CLASS_DATA 0x0a
00082 #define USB_CLASS_VENDOR_SPEC 0xff
00083
00084
00086
00087 #define USB_DT_DEVICE 0x01
00088 #define USB_DT_CONFIG 0x02
00089 #define USB_DT_STRING 0x03
00090 #define USB_DT_INTERFACE 0x04
00091 #define USB_DT_ENDPOINT 0x05
00092 #define USB_DT_HID 0x21
00093 #define USB_DT_REPORT 0x22
00094 #define USB_DT_PHYSICAL 0x23
00095 #define USB_DT_HUB 0x29
00096
00097
00099
00100 #define USB_DT_DEVICE_SIZE 18
00101 #define USB_DT_CONFIG_SIZE 9
00102 #define USB_DT_INTERFACE_SIZE 9
00103 #define USB_DT_ENDPOINT_SIZE 7
00104 #define USB_DT_ENDPOINT_AUDIO_SIZE 9
00105 #define USB_DT_HUB_NONVAR_SIZE 7
00106
00107
00109
00110 #define USB_ENDPOINT_ADDRESS_MASK 0x0f
00111 #define USB_ENDPOINT_DIR_MASK 0x80
00112 #define USB_ENDPOINT_TYPE_MASK 0x03
00113 #define USB_ENDPOINT_TYPE_CONTROL 0
00114 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
00115 #define USB_ENDPOINT_TYPE_BULK 2
00116 #define USB_ENDPOINT_TYPE_INTERRUPT 3
00117
00118
00120
00121 #define USB_REQ_GET_STATUS 0x00
00122 #define USB_REQ_CLEAR_FEATURE 0x01
00123 #define USB_REQ_SET_FEATURE 0x03
00124 #define USB_REQ_SET_ADDRESS 0x05
00125 #define USB_REQ_GET_DESCRIPTOR 0x06
00126 #define USB_REQ_SET_DESCRIPTOR 0x07
00127 #define USB_REQ_GET_CONFIGURATION 0x08
00128 #define USB_REQ_SET_CONFIGURATION 0x09
00129 #define USB_REQ_GET_INTERFACE 0x0A
00130 #define USB_REQ_SET_INTERFACE 0x0B
00131 #define USB_REQ_SYNCH_FRAME 0x0C
00132
00133
00135
00136 #define USB_TYPE_STANDARD (0x00 << 5)
00137 #define USB_TYPE_CLASS (0x01 << 5)
00138 #define USB_TYPE_VENDOR (0x02 << 5)
00139 #define USB_TYPE_RESERVED (0x03 << 5)
00140
00141
00143
00144 #define USB_RECIP_DEVICE 0x00
00145 #define USB_RECIP_INTERFACE 0x01
00146 #define USB_RECIP_ENDPOINT 0x02
00147 #define USB_RECIP_OTHER 0x03
00148
00149
00150 #endif
00151
00152
00154
00155 #define USB_TYPE_MASK (0x03 << 5)
00156 #define USB_RECIP_MASK 0x1f
00157
00158
00160
00161 #define USB_DIR_OUT 0x00
00162 #define USB_DIR_IN 0x80
00163
00164
00166 struct sanei_usb_dev_descriptor
00167 {
00168 SANE_Byte desc_type;
00169 unsigned int bcd_usb;
00170 unsigned int bcd_dev;
00171 SANE_Byte dev_class;
00172 SANE_Byte dev_sub_class;
00173 SANE_Byte dev_protocol;
00174 SANE_Byte max_packet_size;
00175 };
00176
00181 extern void sanei_usb_init (void);
00182
00195 SANE_Status
00196 sanei_usb_get_vendor_product_byname (SANE_String_Const devname,
00197 SANE_Word * vendor, SANE_Word * product);
00198
00213 extern SANE_Status
00214 sanei_usb_get_vendor_product (SANE_Int dn, SANE_Word * vendor,
00215 SANE_Word * product);
00216
00228 extern SANE_Status
00229 sanei_usb_find_devices (SANE_Int vendor, SANE_Int product,
00230 SANE_Status (*attach) (SANE_String_Const devname));
00231
00252 extern SANE_Status sanei_usb_open (SANE_String_Const devname, SANE_Int * dn);
00253
00258 extern void sanei_usb_close (SANE_Int dn);
00259
00264 extern void sanei_usb_set_timeout (SANE_Int timeout);
00265
00268 #define HAVE_SANEI_USB_SET_TIMEOUT
00269
00286 extern SANE_Status
00287 sanei_usb_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size);
00288
00303 extern SANE_Status
00304 sanei_usb_write_bulk (SANE_Int dn, const SANE_Byte * buffer, size_t * size);
00305
00330 extern SANE_Status
00331 sanei_usb_control_msg (SANE_Int dn, SANE_Int rtype, SANE_Int req,
00332 SANE_Int value, SANE_Int index, SANE_Int len,
00333 SANE_Byte * data);
00334
00352 extern SANE_Status
00353 sanei_usb_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size);
00354
00371 extern void
00372 sanei_usb_attach_matching_devices (const char *name,
00373 SANE_Status (*attach) (const char *dev));
00374
00390 extern SANE_Status
00391 sanei_usb_set_configuration (SANE_Int dn, SANE_Int configuration);
00392
00408 extern SANE_Status
00409 sanei_usb_claim_interface (SANE_Int dn, SANE_Int interface_number);
00410
00426 extern SANE_Status
00427 sanei_usb_release_interface (SANE_Int dn, SANE_Int interface_number);
00428
00444 extern SANE_Status
00445 sanei_usb_set_altinterface (SANE_Int dn, SANE_Int alternate);
00446
00463 extern SANE_Status
00464 sanei_usb_get_descriptor( SANE_Int dn, struct sanei_usb_dev_descriptor *desc );
00465
00466
00467 #endif