sanei_usb.h

Go to the documentation of this file.
00001 /* sane - Scanner Access Now Easy.
00002    Copyright (C) 2001, 2002 Henning Meier-Geinitz
00003    Copyright (C) 2003, 2005 Rene Rebe (sanei_read_int,sanei_set_timeout)
00004    Copyright (C) 2008 m. allan noah (sanei_usb_clear_halt)
00005    This file is part of the SANE package.
00006 
00007    SANE is free software; you can redistribute it and/or modify it
00008    under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011 
00012    SANE is distributed in the hope that it will be useful, but WITHOUT
00013    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00014    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
00015    License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with sane; see the file COPYING.  If not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 
00021    As a special exception, the authors of SANE give permission for
00022    additional uses of the libraries contained in this release of SANE.
00023 
00024    The exception is that, if you link a SANE library with other files
00025    to produce an executable, this does not by itself cause the
00026    resulting executable to be covered by the GNU General Public
00027    License.  Your use of that executable is in no way restricted on
00028    account of linking the SANE library code into it.
00029 
00030    This exception does not, however, invalidate any other reasons why
00031    the executable file might be covered by the GNU General Public
00032    License.
00033 
00034    If you submit changes to SANE to the maintainers to be included in
00035    a subsequent release, you agree by submitting the changes that
00036    those changes may be distributed with this exception intact.
00037 
00038    If you write modifications of your own for SANE, it is your choice
00039    whether to permit this exception to apply to your modifications.
00040    If you do not wish that, delete this exception notice.
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> /* for size_t */
00069 
00070 /* USB spec defines */
00071 #ifndef USB_CLASS_PER_INTERFACE
00072 /* Also defined in libusb */
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 /* not USB_CLASS_PER_INTERFACE */
00152 
00153 /* Not defined in libsub */
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 /* sanei_usb_h */

Generated on Wed Nov 5 02:30:50 2008 for SANEI by  doxygen 1.5.1