sanei_usb.h

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

Generated on Sat Jul 26 05:45:27 2008 for SANEI by  doxygen 1.5.1