1141cc406Sopenharmony_ci/* SANE - Scanner Access Now Easy.
2141cc406Sopenharmony_ci
3141cc406Sopenharmony_ci   Copyright (C) 2008 by Louis Lagendijk
4141cc406Sopenharmony_ci   based on sane_usb.h:
5141cc406Sopenharmony_ci   Copyright (C) 2003, 2005 Rene Rebe (sanei_read_int,sanei_set_timeout)
6141cc406Sopenharmony_ci   Copyright (C) 2001, 2002 Henning Meier-Geinitz
7141cc406Sopenharmony_ci
8141cc406Sopenharmony_ci   This file is part of the SANE package.
9141cc406Sopenharmony_ci
10141cc406Sopenharmony_ci   SANE is free software; you can redistribute it and/or modify it
11141cc406Sopenharmony_ci   under the terms of the GNU General Public License as published by
12141cc406Sopenharmony_ci   the Free Software Foundation; either version 2 of the License, or
13141cc406Sopenharmony_ci   (at your option) any later version.
14141cc406Sopenharmony_ci
15141cc406Sopenharmony_ci   SANE is distributed in the hope that it will be useful, but WITHOUT
16141cc406Sopenharmony_ci   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17141cc406Sopenharmony_ci   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
18141cc406Sopenharmony_ci   License for more details.
19141cc406Sopenharmony_ci
20141cc406Sopenharmony_ci   You should have received a copy of the GNU General Public License
21141cc406Sopenharmony_ci   along with sane; see the file COPYING.
22141cc406Sopenharmony_ci   If not, see <https://www.gnu.org/licenses/>.
23141cc406Sopenharmony_ci
24141cc406Sopenharmony_ci   As a special exception, the authors of SANE give permission for
25141cc406Sopenharmony_ci   additional uses of the libraries contained in this release of SANE.
26141cc406Sopenharmony_ci
27141cc406Sopenharmony_ci   The exception is that, if you link a SANE library with other files
28141cc406Sopenharmony_ci   to produce an executable, this does not by itself cause the
29141cc406Sopenharmony_ci   resulting executable to be covered by the GNU General Public
30141cc406Sopenharmony_ci   License.  Your use of that executable is in no way restricted on
31141cc406Sopenharmony_ci   account of linking the SANE library code into it.
32141cc406Sopenharmony_ci
33141cc406Sopenharmony_ci   This exception does not, however, invalidate any other reasons why
34141cc406Sopenharmony_ci   the executable file might be covered by the GNU General Public
35141cc406Sopenharmony_ci   License.
36141cc406Sopenharmony_ci
37141cc406Sopenharmony_ci   If you submit changes to SANE to the maintainers to be included in
38141cc406Sopenharmony_ci   a subsequent release, you agree by submitting the changes that
39141cc406Sopenharmony_ci   those changes may be distributed with this exception intact.
40141cc406Sopenharmony_ci
41141cc406Sopenharmony_ci   If you write modifications of your own for SANE, it is your choice
42141cc406Sopenharmony_ci   whether to permit this exception to apply to your modifications.
43141cc406Sopenharmony_ci   If you do not wish that, delete this exception notice.
44141cc406Sopenharmony_ci*/
45141cc406Sopenharmony_ci/** @file sanei_bjnp.h
46141cc406Sopenharmony_ci * This file provides a generic BJNP interface.
47141cc406Sopenharmony_ci */
48141cc406Sopenharmony_ci
49141cc406Sopenharmony_ci#ifndef sanei_bjnp_h
50141cc406Sopenharmony_ci#define sanei_bjnp_h
51141cc406Sopenharmony_ci
52141cc406Sopenharmony_ci#include "../include/sane/config.h"
53141cc406Sopenharmony_ci#include "../include/sane/sane.h"
54141cc406Sopenharmony_ci#include "pixma.h"
55141cc406Sopenharmony_ci
56141cc406Sopenharmony_ci#ifdef HAVE_STDLIB_H
57141cc406Sopenharmony_ci#include <stdlib.h>		/* for size_t */
58141cc406Sopenharmony_ci#endif
59141cc406Sopenharmony_ci
60141cc406Sopenharmony_ci/** Initialize sanei_bjnp.
61141cc406Sopenharmony_ci *
62141cc406Sopenharmony_ci * Call this before any other sanei_bjnp function.
63141cc406Sopenharmony_ci */
64141cc406Sopenharmony_ciextern void sanei_bjnp_init (void);
65141cc406Sopenharmony_ci
66141cc406Sopenharmony_ci/** Find scanners responding to a BJNP broadcast.
67141cc406Sopenharmony_ci *
68141cc406Sopenharmony_ci * The function sanei_bjnp_attach is called for every device which has
69141cc406Sopenharmony_ci * been found.
70141cc406Sopenharmony_ci * Serial is the address of the scanner in human readable form of max
71141cc406Sopenharmony_ci * SERIAL_MAX characters
72141cc406Sopenharmony_ci * @param conf_devices list of pre-configures device URI's to attach
73141cc406Sopenharmony_ci * @param attach attach function
74141cc406Sopenharmony_ci * @param pixma_devices device informatio needed by attach function
75141cc406Sopenharmony_ci *
76141cc406Sopenharmony_ci * @return SANE_STATUS_GOOD - on success (even if no scanner was found)
77141cc406Sopenharmony_ci */
78141cc406Sopenharmony_ci
79141cc406Sopenharmony_ci#define SERIAL_MAX 16
80141cc406Sopenharmony_ci
81141cc406Sopenharmony_ciextern SANE_Status
82141cc406Sopenharmony_cisanei_bjnp_find_devices (const char **conf_devices,
83141cc406Sopenharmony_ci                         SANE_Status (*attach_bjnp)
84141cc406Sopenharmony_ci			     (SANE_String_Const devname,
85141cc406Sopenharmony_ci                               SANE_String_Const serial,
86141cc406Sopenharmony_ci			       const struct pixma_config_t *cfg),
87141cc406Sopenharmony_ci                         const struct pixma_config_t *const pixma_devices[]);
88141cc406Sopenharmony_ci
89141cc406Sopenharmony_ci/** Open a BJNP device.
90141cc406Sopenharmony_ci *
91141cc406Sopenharmony_ci * The device is opened by its name devname and the device number is
92141cc406Sopenharmony_ci * returned in dn on success.
93141cc406Sopenharmony_ci *
94141cc406Sopenharmony_ci * Device names consist of an URI
95141cc406Sopenharmony_ci * Where:
96141cc406Sopenharmony_ci * method = bjnp
97141cc406Sopenharmony_ci * hostname = resolvable name or IP-address
98141cc406Sopenharmony_ci * port = 8612 for a bjnp scanner, 8610 for a mfnp device
99141cc406Sopenharmony_ci * An example could look like this: bjnp://host.domain:8612
100141cc406Sopenharmony_ci *
101141cc406Sopenharmony_ci * @param devname name of the device to open
102141cc406Sopenharmony_ci * @param dn device number
103141cc406Sopenharmony_ci *
104141cc406Sopenharmony_ci * @return
105141cc406Sopenharmony_ci * - SANE_STATUS_GOOD - on success
106141cc406Sopenharmony_ci * - SANE_STATUS_ACCESS_DENIED - if the file couldn't be accessed due to
107141cc406Sopenharmony_ci *   permissions
108141cc406Sopenharmony_ci * - SANE_STATUS_INVAL - on every other error
109141cc406Sopenharmony_ci */
110141cc406Sopenharmony_ciextern SANE_Status sanei_bjnp_open (SANE_String_Const devname, SANE_Int * dn);
111141cc406Sopenharmony_ci
112141cc406Sopenharmony_ci/** Close a BJNP device.
113141cc406Sopenharmony_ci *
114141cc406Sopenharmony_ci * @param dn device number
115141cc406Sopenharmony_ci */
116141cc406Sopenharmony_ci
117141cc406Sopenharmony_ciextern void sanei_bjnp_close (SANE_Int dn);
118141cc406Sopenharmony_ci
119141cc406Sopenharmony_ci/** Activate a BJNP device connection
120141cc406Sopenharmony_ci *
121141cc406Sopenharmony_ci *  @param dn device number
122141cc406Sopenharmony_ci */
123141cc406Sopenharmony_ci
124141cc406Sopenharmony_ciextern SANE_Status sanei_bjnp_activate (SANE_Int dn);
125141cc406Sopenharmony_ci
126141cc406Sopenharmony_ci/** De-activate a BJNP device connection
127141cc406Sopenharmony_ci *
128141cc406Sopenharmony_ci * @param dn device number
129141cc406Sopenharmony_ci */
130141cc406Sopenharmony_ci
131141cc406Sopenharmony_ciextern SANE_Status sanei_bjnp_deactivate (SANE_Int dn);
132141cc406Sopenharmony_ci
133141cc406Sopenharmony_ci/** Set the libbjnp timeout for bulk and interrupt reads.
134141cc406Sopenharmony_ci *
135141cc406Sopenharmony_ci * @param devno device number
136141cc406Sopenharmony_ci * @param timeout the new timeout in ms
137141cc406Sopenharmony_ci */
138141cc406Sopenharmony_ciextern void sanei_bjnp_set_timeout (SANE_Int devno, SANE_Int timeout);
139141cc406Sopenharmony_ci
140141cc406Sopenharmony_ci/** Check if sanei_bjnp_set_timeout() is available.
141141cc406Sopenharmony_ci */
142141cc406Sopenharmony_ci#define HAVE_SANEI_BJNP_SET_TIMEOUT
143141cc406Sopenharmony_ci
144141cc406Sopenharmony_ci/** Initiate a bulk transfer read.
145141cc406Sopenharmony_ci *
146141cc406Sopenharmony_ci * Read up to size bytes from the device to buffer. After the read, size
147141cc406Sopenharmony_ci * contains the number of bytes actually read.
148141cc406Sopenharmony_ci *
149141cc406Sopenharmony_ci * @param dn device number
150141cc406Sopenharmony_ci * @param buffer buffer to store read data in
151141cc406Sopenharmony_ci * @param size size of the data
152141cc406Sopenharmony_ci *
153141cc406Sopenharmony_ci * @return
154141cc406Sopenharmony_ci * - SANE_STATUS_GOOD - on success
155141cc406Sopenharmony_ci * - SANE_STATUS_EOF - if zero bytes have been read
156141cc406Sopenharmony_ci * - SANE_STATUS_IO_ERROR - if an error occurred during the read
157141cc406Sopenharmony_ci * - SANE_STATUS_INVAL - on every other error
158141cc406Sopenharmony_ci *
159141cc406Sopenharmony_ci */
160141cc406Sopenharmony_ciextern SANE_Status
161141cc406Sopenharmony_cisanei_bjnp_read_bulk (SANE_Int dn, SANE_Byte * buffer, size_t * size);
162141cc406Sopenharmony_ci
163141cc406Sopenharmony_ci/** Initiate a bulk transfer write.
164141cc406Sopenharmony_ci *
165141cc406Sopenharmony_ci * Write up to size bytes from buffer to the device. After the write size
166141cc406Sopenharmony_ci * contains the number of bytes actually written.
167141cc406Sopenharmony_ci *
168141cc406Sopenharmony_ci * @param dn device number
169141cc406Sopenharmony_ci * @param buffer buffer to write to device
170141cc406Sopenharmony_ci * @param size size of the data
171141cc406Sopenharmony_ci *
172141cc406Sopenharmony_ci * @return
173141cc406Sopenharmony_ci * - SANE_STATUS_GOOD - on success
174141cc406Sopenharmony_ci * - SANE_STATUS_IO_ERROR - if an error occurred during the write
175141cc406Sopenharmony_ci * - SANE_STATUS_INVAL - on every other error
176141cc406Sopenharmony_ci */
177141cc406Sopenharmony_ciextern SANE_Status
178141cc406Sopenharmony_cisanei_bjnp_write_bulk (SANE_Int dn, const SANE_Byte * buffer, size_t * size);
179141cc406Sopenharmony_ci
180141cc406Sopenharmony_ci/** Initiate a interrupt transfer read.
181141cc406Sopenharmony_ci *
182141cc406Sopenharmony_ci * Read up to size bytes from the interrupt endpoint from the device to
183141cc406Sopenharmony_ci * buffer. After the read, size contains the number of bytes actually read.
184141cc406Sopenharmony_ci *
185141cc406Sopenharmony_ci * @param dn device number
186141cc406Sopenharmony_ci * @param buffer buffer to store read data in
187141cc406Sopenharmony_ci * @param size size of the data
188141cc406Sopenharmony_ci *
189141cc406Sopenharmony_ci * @return
190141cc406Sopenharmony_ci * - SANE_STATUS_GOOD - on success
191141cc406Sopenharmony_ci * - SANE_STATUS_EOF - if zero bytes have been read
192141cc406Sopenharmony_ci * - SANE_STATUS_IO_ERROR - if an error occurred during the read
193141cc406Sopenharmony_ci * - SANE_STATUS_INVAL - on every other error
194141cc406Sopenharmony_ci *
195141cc406Sopenharmony_ci */
196141cc406Sopenharmony_ci
197141cc406Sopenharmony_ciextern SANE_Status
198141cc406Sopenharmony_cisanei_bjnp_read_int (SANE_Int dn, SANE_Byte * buffer, size_t * size);
199141cc406Sopenharmony_ci
200141cc406Sopenharmony_ci/*------------------------------------------------------*/
201141cc406Sopenharmony_ci#endif /* sanei_bjnp_h */
202