1/* 2 Snapscan 1212U modifications for the Snapscan SANE backend 3 4 Copyright (C) 2000 Henrik Johansson 5 6 Henrik Johansson (henrikjo@post.urfors.se) 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as 10 published by the Free Software Foundation; either version 2 of the 11 License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <https://www.gnu.org/licenses/>. 20 21 As a special exception, the authors of SANE give permission for 22 additional uses of the libraries contained in this release of SANE. 23 24 The exception is that, if you link a SANE library with other files 25 to produce an executable, this does not by itself cause the 26 resulting executable to be covered by the GNU General Public 27 License. Your use of that executable is in no way restricted on 28 account of linking the SANE library code into it. 29 30 This exception does not, however, invalidate any other reasons why 31 the executable file might be covered by the GNU General Public 32 License. 33 34 If you submit changes to SANE to the maintainers to be included in 35 a subsequent release, you agree by submitting the changes that 36 those changes may be distributed with this exception intact. 37 38 If you write modifications of your own for SANE, it is your choice 39 whether to permit this exception to apply to your modifications. 40 If you do not wish that, delete this exception notice. 41 42 This file implements USB equivalents to the SCSI routines used by the Snapscan 43 backend. 44*/ 45 46/* 47 SnapScan backend scan data sources 48*/ 49 50#ifndef snapscan_usb_h 51#define snapscan_usb_h 52 53typedef SANE_Status (*sense_handler_type)(int fd, u_char *sense_buffer, void *arg); 54 55static SANE_Status snapscani_usb_cmd(int fd, const void *src, size_t src_size, 56 void *dst, size_t * dst_size); 57static SANE_Status snapscani_usb_open(const char *dev, int *fdp, 58 sense_handler_type, void*); 59static void snapscani_usb_close(int fd); 60 61/* 62 * USB status codes 63 */ 64#define GOOD 0x00 65#define CHECK_CONDITION 0x01 66#define CONDITION_GOOD 0x02 67#define BUSY 0x04 68#define INTERMEDIATE_GOOD 0x08 69#define INTERMEDIATE_C_GOOD 0x0a 70#define RESERVATION_CONFLICT 0x0c 71#define COMMAND_TERMINATED 0x11 72#define QUEUE_FULL 0x14 73 74#define STATUS_MASK 0x3e 75 76/* 77 * USB transaction status 78 */ 79#define TRANSACTION_COMPLETED 0xfb /* Scanner considers the transaction done */ 80#define TRANSACTION_READ 0xf9 /* Scanner has data to deliver */ 81#define TRANSACTION_WRITE 0xf8 /* Scanner is expecting more data */ 82 83/* 84 * Busy queue data structure and prototypes 85 */ 86struct usb_busy_queue { 87 int fd; 88 void *src; 89 size_t src_size; 90 struct usb_busy_queue *next; 91}; 92 93static struct usb_busy_queue *bqhead,*bqtail; 94static int enqueue_bq(int fd,const void *src, size_t src_size); 95static void dequeue_bq(void); 96static int is_queueable(const char *src); 97 98static SANE_Status atomic_usb_cmd(int fd, const void *src, size_t src_size, 99 void *dst, size_t * dst_size); 100static SANE_Status usb_cmd(int fd, const void *src, size_t src_size, 101 void *dst, size_t * dst_size); 102 103#endif 104 105/* 106 * Revision 1.6 2003/07/26 17:16:55 oliverschwartz 107 * Changed licence to GPL + SANE exception for snapscan-usb.[ch] 108 * 109 * Revision 1.5 2002/04/10 21:45:53 oliverschwartz 110 * Removed illegal character / removed declaration of bqelements 111 * 112 * Revision 1.10 2001/12/09 23:06:45 oliverschwartz 113 * - use sense handler for USB if scanner reports CHECK_CONDITION 114 * 115 * Revision 1.9 2001/11/16 20:23:16 oliverschwartz 116 * Merge with sane-1.0.6 117 * - Check USB vendor IDs to avoid hanging scanners 118 * - fix bug in dither matrix computation 119 * 120 * Revision 1.8 2001/09/18 15:01:07 oliverschwartz 121 * - Read scanner id string again after firmware upload 122 * to identify correct model 123 * - Make firmware upload work for AGFA scanners 124 * - Change copyright notice 125 * 126 * */ 127