• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* sane - Scanner Access Now Easy.
2  * Copyright (C) 2003-2005 Gerhard Jaeger <gerhard@gjaeger.de>
3  * based on work done by Jochen Eisinger <jochen.eisinger@gmx.net>
4  * also parts from libieee1284 by Tim Waugh <tim@cyberelk.net>
5  * This file is part of the SANE package.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * As a special exception, the authors of SANE give permission for
21  * additional uses of the libraries contained in this release of SANE.
22  *
23  * The exception is that, if you link a SANE library with other files
24  * to produce an executable, this does not by itself cause the
25  * resulting executable to be covered by the GNU General Public
26  * License.  Your use of that executable is in no way restricted on
27  * account of linking the SANE library code into it.
28  *
29  * This exception does not, however, invalidate any other reasons why
30  * the executable file might be covered by the GNU General Public
31  * License.
32  *
33  * If you submit changes to SANE to the maintainers to be included in
34  * a subsequent release, you agree by submitting the changes that
35  * those changes may be distributed with this exception intact.
36  *
37  * If you write modifications of your own for SANE, it is your choice
38  * whether to permit this exception to apply to your modifications.
39  * If you do not wish that, delete this exception notice.
40  *
41  * This file implements an interface for accessing the parallelport
42  */
43 
44 /* debug levels:
45  * 0 - nothing
46  * 1 - errors
47  * 2 - warnings
48  * 3 - things nice to know
49  * 4 - code flow
50  * 5 - detailed flow
51  * 6 - everything
52  *
53  * These debug levels can be set using the environment variable
54  * SANE_DEBUG_SANEI_PP
55  */
56 
57 #include "../include/sane/config.h"
58 
59 #define BACKEND_NAME sanei_pp
60 
61 #define _TEST_LOOPS 1000
62 #define _MAX_PORTS    20
63 
64 #ifndef _VAR_NOT_USED
65 # define _VAR_NOT_USED(x)	((x)=(x))
66 #endif
67 
68 /* uncomment this to have some parameter checks on in/out functions,
69  * note: that this will slow down the calls
70  */
71 #if 0
72 # define _PARANOIA
73 #endif
74 
75 #ifdef HAVE_UNISTD_H
76 # include <unistd.h>
77 #endif
78 #ifdef HAVE_SYS_TIME_H
79 # include <sys/time.h>
80 #endif
81 #ifdef HAVE_LIMITS_H
82 # include <limits.h>
83 #else
84 # ifndef ULONG_MAX
85 #  define ULONG_MAX 4294967295UL
86 # endif
87 #endif
88 #if defined (ENABLE_PARPORT_DIRECTIO)
89 # undef HAVE_LIBIEEE1284
90 # include "../include/sane/sanei_directio.h"
91 #elif defined(HAVE_LIBIEEE1284)
92 # include <ieee1284.h>
93 #else
94 # pragma message "No I/O support for this architecture!"
95 # define IO_SUPPORT_MISSING
96 #endif
97 
98 #include "../include/sane/sane.h"
99 #include "../include/sane/sanei.h"
100 #include "../include/sane/sanei_debug.h"
101 #include "../include/sane/sanei_pp.h"
102 
103 #include <errno.h>
104 #include <stdio.h>
105 #include <stdlib.h>
106 #if defined(HAVE_STRING_H)
107 # include <string.h>
108 #elif defined(HAVE_STRINGS_H)
109 # include <strings.h>
110 #endif
111 #if defined(HAVE_SYS_TYPES_H)
112 # include <sys/types.h>
113 #endif
114 
115 /** our global init flag... */
116 static int           first_time = SANE_TRUE;
117 static unsigned long pp_thresh  = 0;
118 
119 #if (defined (HAVE_IOPERM) || defined (HAVE_LIBIEEE1284)) && !defined (IO_SUPPORT_MISSING)
120 
121 typedef struct {
122 
123 #ifndef HAVE_LIBIEEE1284
124 	const char name[6];
125 	u_long     base;        /**< i/o base address                */
126 	u_char     ctrl;        /**< for restoring CTRL register     */
127 	u_char     ecp_ctrl;    /**< for restoring ECP-CTRL register */
128 #endif
129 
130 	u_int in_use;           /**< port in use?      */
131 	u_int claimed;          /**< port claimed?     */
132 
133 	int caps;               /**< port capabilities */
134 
135 } PortRec, *Port;
136 
137 #if defined (HAVE_LIBIEEE1284)
138 
139 static struct parport_list  pplist;
140 static PortRec              port[_MAX_PORTS];
141 
142 #else
143 
144 /** redefine the CAPability flags */
145 enum ieee1284_capabilities
146 {
147 	CAP1284_RAW    = (1<<0),
148 	CAP1284_NIBBLE = (1<<1), /* SPP mode             */
149 	CAP1284_BYTE   = (1<<2), /* PS/2 bidirectional   */
150 	CAP1284_COMPAT = (1<<3),
151 	CAP1284_BECP   = (1<<4),
152 	CAP1284_ECP    = (1<<5), /* ECP                  */
153 	CAP1284_ECPRLE = (1<<6), /* ECP with RLE support */
154 	CAP1284_ECPSWE = (1<<7),
155 	CAP1284_EPP    = (1<<8), /* EPP hardware support */
156 	CAP1284_EPPSL  = (1<<9), /* EPP 1.7              */
157 	CAP1284_EPPSWE = (1<<10) /* EPP software support */
158 };
159 
160 static PortRec port[] = {
161 	{ "0x378", 0x378, 0, 0, SANE_FALSE, SANE_FALSE, 0 },
162 	{ "0x278", 0x278, 0, 0, SANE_FALSE, SANE_FALSE, 0 },
163 	{ "0x3BC", 0x3BC, 0, 0, SANE_FALSE, SANE_FALSE, 0 }
164 };
165 
166 #endif
167 
168 /** depending on the interface we use, define the port macros
169  */
170 #if defined(HAVE_LIBIEEE1284)
171 
172 #define inb_data(fd) ieee1284_read_data(pplist.portv[fd]);
173 #define inb_stat(fd) (ieee1284_read_status(pplist.portv[fd]) ^ S1284_INVERTED)
174 #define inb_ctrl(fd) (ieee1284_read_control(pplist.portv[fd]) ^ C1284_INVERTED)
175 
inb_eppdata(int fd)176 static inline u_char inb_eppdata(int fd)
177 {
178 	u_char val;
179 	ieee1284_epp_read_data(pplist.portv[fd], 0, (char *)&val, 1);
180 	return val;
181 }
182 
outb_eppdata(int fd,u_char val)183 static inline void outb_eppdata(int fd, u_char val)
184 {
185 	ieee1284_epp_write_data(pplist.portv[fd], 0, (const char *)&val, 1);
186 }
187 
188 #define outb_data(fd,val) ieee1284_write_data(pplist.portv[fd], val)
189 #define outb_ctrl(fd,val) ieee1284_write_control(pplist.portv[fd], \
190                                                    (val) ^ C1284_INVERTED)
outb_addr(int fd,u_char val)191 static inline void outb_addr(int fd, u_char val)
192 {
193 	ieee1284_epp_write_addr (pplist.portv[fd], 0, (char *)&val, 1);
194 }
195 
196 #else
197 
198 #define inb_data(fd)    sanei_inb(port[fd].base)
199 #define inb_stat(fd)    sanei_inb(port[fd].base + 1)
200 #define inb_ctrl(fd)    sanei_inb(port[fd].base + 2)
201 #define inb_eppdata(fd) sanei_inb(port[fd].base + 4)
202 
203 #define outb_data(fd,val)    sanei_outb(port[fd].base, val)
204 #define outb_stat(fd,val)    sanei_outb(port[fd].base + 1, val)
205 #define outb_ctrl(fd,val)    sanei_outb(port[fd].base + 2, val)
206 #define outb_addr(fd,val)    sanei_outb(port[fd].base + 3, val)
207 #define outb_eppdata(fd,val) sanei_outb(port[fd].base + 4, val)
208 
209 #ifdef HAVE_IOPL
210 # define _SET_IOPL()        iopl(3)
211 #else
212 # define _SET_IOPL()
213 #endif
214 #define inbyte400(fd)      sanei_inb(port[fd].base + 0x400)
215 #define inbyte402(fd)      sanei_inb(port[fd].base + 0x402)
216 #define outbyte400(fd,val) sanei_outb(port[fd].base + 0x400, val)
217 #define outbyte402(fd,val) sanei_outb(port[fd].base + 0x402, val)
218 #endif
219 
220 /* should also be in unistd.h */
221 extern int setuid (uid_t);
222 
223 #if defined (HAVE_LIBIEEE1284)
224 
pp_libieee1284_errorstr(int error)225 static const char *pp_libieee1284_errorstr( int error )
226 {
227 	switch (error) {
228 
229 		case E1284_OK:
230 			return "Everything went fine";
231 
232 		case E1284_NOTIMPL:
233 			return "Not implemented in libieee1284";
234 
235 		case E1284_NOTAVAIL:
236 			return "Not available on this system";
237 
238 		case E1284_TIMEDOUT:
239 			return "Operation timed out";
240 
241 		case E1284_REJECTED:
242 			return "IEEE 1284 negotiation rejected";
243 
244 		case E1284_NEGFAILED:
245 			return "Negotiation went wrong";
246 
247 		case E1284_NOMEM:
248 			return "No memory left";
249 
250 		case E1284_INIT:
251 			return "Error initializing port";
252 
253 		case E1284_SYS:
254 			return "Error interfacing system";
255 
256 		case E1284_NOID:
257 			return "No IEEE 1284 ID available";
258 
259 		case E1284_INVALIDPORT:
260 			return "Invalid port";
261 
262 		default:
263 			return "Unknown error";
264 	}
265 }
266 #endif
267 
268 /** show the caps
269  */
270 static int
pp_showcaps(int caps)271 pp_showcaps( int caps )
272 {
273 	int  mode = 0;
274 	char ct[1024];
275 
276     ct[0] = '\0';
277 
278 	if( caps & CAP1284_NIBBLE ) {
279 		strcat( ct, "SPP " );
280 		mode |= SANEI_PP_MODE_SPP;
281 	}
282 
283 	if( caps & CAP1284_BYTE ) {
284 		strcat( ct, "PS/2 " );
285 		mode |= SANEI_PP_MODE_BIDI;
286 	}
287 
288 	if( caps &  CAP1284_EPP ) {
289 		strcat( ct, "EPP " );
290 		mode |= SANEI_PP_MODE_EPP;
291 	}
292 
293 	if( caps &  CAP1284_EPPSWE ) {
294 		strcat( ct, "EPPSWE " );
295 		mode |= SANEI_PP_MODE_EPP;
296 	}
297 
298 	if( caps &  CAP1284_ECP ) {
299 		strcat( ct, "ECP " );
300 		mode |= SANEI_PP_MODE_ECP;
301 	}
302 
303 	if( caps &  CAP1284_ECPRLE ) {
304 		strcat( ct, "ECPRLE " );
305 		mode |= SANEI_PP_MODE_ECP;
306 	}
307 
308 	DBG( 4, "Supported Modes: %s\n", ct );
309 	return mode;
310 }
311 
312 #ifndef HAVE_LIBIEEE1284
313 
314 /** probe the parallel port
315  */
316 static int
pp_probe(int fd)317 pp_probe( int fd )
318 {
319 #ifdef HAVE_IOPL
320 	SANE_Byte c;
321 	int       i, j;
322 #endif
323 	SANE_Byte a, b;
324 	int       retv = 0;
325 
326 	DBG( 4, "pp_probe: port 0x%04lx\n", port[fd].base );
327 
328 	/* SPP check */
329 	outbyte402( fd, 0x0c );
330 	outb_ctrl ( fd, 0x0c );
331 	outb_data ( fd, 0x55 );
332 	a = inb_data( fd );
333 	if( a != 0x55 ) {
334 	    DBG( 4, "pp_probe: nothing supported :-(\n" );
335 		return retv;
336 	}
337 
338 	DBG( 4, "pp_probe: SPP port present\n" );
339 	retv += CAP1284_NIBBLE;
340 
341 	/* check for ECP */
342 #ifdef HAVE_IOPL
343 
344 	/* clear at most 1k of data from FIFO */
345 	for( i = 1024; i > 0; i-- ) {
346 		a = inbyte402( fd );
347 		if ((a & 0x03) == 0x03)
348 			goto no_ecp;
349 		if (a & 0x01)
350 		    break;
351 		inbyte400( fd ); /* Remove byte from FIFO */
352 	}
353 
354 	if (i <= 0)
355 		goto no_ecp;
356 
357 	b = a ^ 3;
358 	outbyte402( fd, b );
359 	c = inbyte402( fd );
360 
361 	if (a == c) {
362 		outbyte402( fd, 0xc0 ); /* FIFO test */
363 		j = 0;
364 		while (!(inbyte402( fd ) & 0x01) && (j < 1024)) {
365 	    	inbyte402( fd );
366 	    	j++;
367 		}
368 		if (j >= 1024)
369 		    goto no_ecp;
370 		i = 0;
371 		j = 0;
372 		while (!(inbyte402( fd ) & 0x02) && (j < 1024)) {
373 		    outbyte400( fd, 0x00 );
374 	    	i++;
375 		    j++;
376 		}
377 		if (j >= 1024)
378 		    goto no_ecp;
379 		j = 0;
380 		while (!(inbyte402( fd ) & 0x01) && (j < 1024)) {
381 	    	inbyte400( fd );
382 		    j++;
383 		}
384 		if (j >= 1024)
385 		    goto no_ecp;
386 
387     	DBG( 4, "pp_probe: ECP with a %i byte FIFO present\n", i );
388 		retv += CAP1284_ECP;
389     }
390 
391 no_ecp:
392 #endif
393 	/* check for PS/2 compatible port */
394 	if( retv & CAP1284_ECP ) {
395 		outbyte402( fd, 0x20 );
396 	}
397 
398 	outb_data( fd, 0x55 );
399 	outb_ctrl( fd, 0x0c );
400 	a = inb_data( fd );
401 	outb_data( fd, 0x55 );
402 	outb_ctrl( fd, 0x2c );
403 	b = inb_data( fd );
404 	if( a != b ) {
405     	DBG( 4, "pp_probe: PS/2 bidirectional port present\n");
406 		retv += CAP1284_BYTE;
407     }
408 
409     /* check for EPP support */
410 	if( port[fd].base & 0x007 ) {
411 	    DBG( 4, "pp_probe: EPP not supported at this address\n" );
412 		return retv;
413     }
414 #ifdef HAVE_IOPL
415     if( retv & CAP1284_ECP ) {
416 		for( i = 0x00; i < 0x80; i += 0x20 ) {
417 	    	outbyte402( fd, i );
418 
419 		    a = inb_stat( fd );
420 		    outb_stat( fd, a );
421 		    outb_stat( fd, (a & 0xfe));
422 		    a = inb_stat( fd );
423 	    	if (!(a & 0x01)) {
424 			    DBG( 2, "pp_probe: "
425 			            "Failed Intel bug check. (Phony EPP in ECP)\n" );
426 				return retv;
427 		    }
428 		}
429 	    DBG( 4, "pp_probe: Passed Intel bug check.\n" );
430 		outbyte402( fd, 0x80 );
431     }
432 #endif
433 
434 	a = inb_stat( fd );
435 	outb_stat( fd, a );
436 	outb_stat( fd, (a & 0xfe));
437 	a = inb_stat( fd );
438 
439 	if (a & 0x01) {
440 		outbyte402( fd, 0x0c );
441 		outb_ctrl ( fd, 0x0c );
442 		return retv;
443 	}
444 
445 	outb_ctrl( fd, 0x04 );
446 	inb_eppdata ( fd );
447 	a = inb_stat( fd );
448 	outb_stat( fd, a );
449 	outb_stat( fd, (a & 0xfe));
450 
451 	if( a & 0x01 ) {
452 	    DBG( 4, "pp_probe: EPP 1.9 with hardware direction protocol\n");
453 		retv += CAP1284_EPP;
454     } else {
455 		/* The EPP timeout bit was not set, this could either be:
456 		 * EPP 1.7
457 		 * EPP 1.9 with software direction
458 		 */
459 		outb_ctrl( fd, 0x24 );
460 		inb_eppdata ( fd );
461 		a = inb_stat( fd );
462 		outb_stat( fd, a );
463 		outb_stat( fd, (a & 0xfe));
464 		if( a & 0x01 ) {
465 			DBG( 4, "pp_probe: EPP 1.9 with software direction protocol\n" );
466 		    retv += CAP1284_EPPSWE;
467 		} else {
468 			DBG( 4, "pp_probe: EPP 1.7\n" );
469 			retv += CAP1284_EPPSL;
470 		}
471 	}
472 
473 	outbyte402( fd, 0x0c );
474 	outb_ctrl ( fd, 0x0c );
475     return retv;
476 }
477 
478 /**
479  */
pp_set_scpmode(int fd)480 static int pp_set_scpmode( int fd )
481 {
482 	SANE_Byte tmp;
483 	DBG( 4, "pp_set_scpmode\n" );
484 
485 #ifdef HAVE_IOPL
486 	tmp  = inbyte402( fd );
487 	tmp &= 0x1f;
488 	outbyte402( fd, tmp );
489 #endif
490 	tmp  = inb_ctrl( fd );
491 	tmp &= 0x0f;
492 	outb_ctrl ( fd, tmp );
493 
494 	return SANE_STATUS_GOOD;
495 }
496 
pp_set_bidimode(int fd)497 static int pp_set_bidimode( int fd )
498 {
499 	SANE_Byte tmp;
500 	DBG( 4, "pp_set_bidimode\n" );
501 #ifdef HAVE_IOPL
502 	tmp = inbyte402( fd );
503 	tmp = (tmp & 0x1f) | 0x20;
504 	outbyte402( fd, tmp );
505 #endif
506 	tmp = inb_ctrl( fd );
507 	tmp = (tmp & 0x0f) | 0x20;
508 	outb_ctrl ( fd, tmp );
509 
510 	return SANE_STATUS_GOOD;
511 }
512 
pp_set_eppmode(int fd)513 static int pp_set_eppmode( int fd )
514 {
515 	SANE_Byte tmp;
516 	DBG( 4, "pp_set_eppmode\n" );
517 #ifdef HAVE_IOPL
518 	tmp = inbyte402( fd );
519 	tmp = (tmp & 0x1f) | 0x80;
520 	outbyte402( fd, tmp );
521 #endif
522 	tmp = inb_ctrl( fd );
523 	tmp = (tmp & 0xf0) | 0x40;
524 	outb_ctrl ( fd, tmp );
525 
526 	return SANE_STATUS_GOOD;
527 }
528 
pp_set_ecpmode(int fd)529 static int pp_set_ecpmode( int fd )
530 {
531 #ifdef HAVE_IOPL
532 	SANE_Byte tmp;
533 #endif
534 
535 	DBG( 4, "pp_set_ecpmode\n" );
536 #ifdef HAVE_IOPL
537 	tmp = inbyte402( fd );
538 	tmp = (tmp & 0x1f) | 0x60;
539 	outbyte402( fd, tmp );
540 	return SANE_STATUS_GOOD;
541 #endif
542 	return SANE_STATUS_UNSUPPORTED;
543 }
544 
545 /** set the parallel port mode
546  */
547 static int
pp_setmode(int fd,int mode)548 pp_setmode( int fd, int mode )
549 {
550 	int ret;
551 
552 	if( 0 == (mode & port[fd].caps)) {
553 		DBG( 2, "pp_setmode: mode not supported %d\n", mode );
554 		return SANE_STATUS_UNSUPPORTED;
555 	}
556 
557 	switch( mode ) {
558 		case SANEI_PP_MODE_SPP:  ret = pp_set_scpmode( fd );  break;
559 		case SANEI_PP_MODE_BIDI: ret = pp_set_bidimode( fd ); break;
560 		case SANEI_PP_MODE_EPP:  ret = pp_set_eppmode( fd );  break;
561 		case SANEI_PP_MODE_ECP:  ret = pp_set_ecpmode( fd );  break;
562 
563 		default:
564 			DBG( 2, "pp_setmode: invalid mode %d\n", mode );
565 			return SANE_STATUS_INVAL;
566 	}
567 
568 	return ret;
569 }
570 
571 #endif
572 
573 static unsigned long
pp_time_diff(struct timeval * start,struct timeval * end)574 pp_time_diff( struct timeval *start, struct timeval *end )
575 {
576 	double s, e, r;
577 
578 	s = (double)start->tv_sec * 1000000.0 + (double)start->tv_usec;
579 	e = (double)end->tv_sec   * 1000000.0 + (double)end->tv_usec;
580 
581 	if( e > s )
582 		r = (e - s);
583 	else
584 		r = (s - e);
585 
586 	if( r <= (double)ULONG_MAX )
587 		return (unsigned long)r;
588 
589 	return 0;
590 }
591 
592 /**
593  */
594 static unsigned long
pp_calculate_thresh(void)595 pp_calculate_thresh( void )
596 {
597 	unsigned long  i, r, ret;
598 	struct timeval start, end, deadline;
599 
600 	gettimeofday( &start, NULL);
601 
602 	for( i = _TEST_LOOPS; i; i-- ) {
603 
604 		gettimeofday( &deadline, NULL );
605 		deadline.tv_usec += 10;
606 		deadline.tv_sec  += deadline.tv_usec / 1000000;
607 		deadline.tv_usec %= 1000000;
608 	}
609 
610 	gettimeofday( &end, NULL);
611 
612 	r   = pp_time_diff( &start, &end );
613 	ret = r/_TEST_LOOPS;
614 	return ret;
615 }
616 
617 /**
618  */
619 static void
pp_calibrate_delay(void)620 pp_calibrate_delay( void )
621 {
622 	unsigned long  r, i;
623 	struct timeval start, end;
624 
625     for( i = 0; i < 5; i++ ) {
626 
627 		pp_thresh = pp_calculate_thresh();
628 		gettimeofday( &start, NULL);
629 
630 		for( i = _TEST_LOOPS; i; i-- ) {
631 			sanei_pp_udelay( 1 );
632 		}
633 		gettimeofday( &end, NULL);
634 
635 		r = pp_time_diff( &start, &end );
636 
637 		DBG( 4, "pp_calibrate_delay: Delay expected: "
638 				"%u, real %lu, pp_thresh=%lu\n", _TEST_LOOPS, r, pp_thresh );
639 
640 		if( r >= _TEST_LOOPS ) {
641 			return;
642 		}
643 	}
644 
645 	DBG( 4, "pp_calibrate_delay: pp_thresh set to 0\n" );
646 	pp_thresh = 0;
647 }
648 
649 static SANE_Status
pp_init(void)650 pp_init( void )
651 {
652 #if defined (HAVE_LIBIEEE1284)
653 	int result, i;
654 #endif
655 
656 	if( first_time == SANE_FALSE ) {
657 		DBG( 5, "pp_init: already initialized\n" );
658 		return SANE_STATUS_GOOD;
659     }
660 
661 	DBG( 5, "pp_init: called for the first time\n");
662 	first_time = SANE_FALSE;
663 
664 #if defined (HAVE_LIBIEEE1284)
665 
666 	DBG( 4, "pp_init: initializing libieee1284\n");
667 	result = ieee1284_find_ports( &pplist, 0 );
668 
669 	if (result) {
670 		DBG (1, "pp_init: initializing IEEE 1284 failed (%s)\n",
671 				 pp_libieee1284_errorstr( result ));
672 		first_time = SANE_TRUE;
673 		return SANE_STATUS_INVAL;
674 	}
675 
676 	DBG( 3, "pp_init: %d ports reported by IEEE 1284 library\n", pplist.portc);
677 
678 	for( i = 0; i < pplist.portc; i++ )
679 		DBG( 6, "pp_init: port %d is `%s`\n", i, pplist.portv[i]->name);
680 
681 	/* we support only up to _MAX_PORTS... */
682 	if( pplist.portc > _MAX_PORTS ) {
683 		DBG (1, "pp_init: Lib IEEE 1284 reports too much ports: %d\n",
684 		        pplist.portc );
685 
686 		ieee1284_free_ports( &pplist );
687 		first_time = SANE_TRUE;
688 		return SANE_STATUS_UNSUPPORTED;
689 	}
690 	memset( port, 0, sizeof(port));
691 
692 #else
693 
694 	DBG( 4, "pp_init: trying to setuid root\n");
695 	if( 0 > setuid( 0 )) {
696 
697 		DBG( 1, "pp_init: setuid failed: errno = %d\n", errno );
698 		DBG( 5, "pp_init: returning SANE_STATUS_INVAL\n" );
699 
700 		first_time = SANE_TRUE;
701 		return SANE_STATUS_INVAL;
702 	}
703 
704 	DBG( 3, "pp_init: the application is now root\n" );
705 
706 #endif
707 
708 	DBG( 5, "pp_init: initialized successfully\n" );
709 	return SANE_STATUS_GOOD;
710 }
711 
712 static int
pp_open(const char * dev,SANE_Status * status)713 pp_open( const char *dev, SANE_Status * status )
714 {
715 	int i;
716 #if !defined (HAVE_LIBIEEE1284)
717 	u_long base;
718 #else
719 	int result;
720 #endif
721 
722 	DBG( 4, "pp_open: trying to attach dev `%s`\n", dev );
723 
724 #if !defined (HAVE_LIBIEEE1284)
725 {
726 	char *end;
727 
728 	DBG( 5, "pp_open: reading port number\n" );
729 
730 	base = strtol( dev, &end, 0 );
731 	if ((end == dev) || (*end != '\0')) {
732 
733 		DBG( 1, "pp_open: `%s` is not a valid port number\n", dev);
734 		DBG( 6, "pp_open: the part I did not understand was ...`%s`\n", end);
735 		*status = SANE_STATUS_INVAL;
736 		return -1;
737 	}
738 }
739 
740 	DBG( 6, "pp_open: read port number 0x%03lx\n", base );
741 	if( base == 0 ) {
742 
743 		DBG( 1, "pp_open: 0x%03lx is not a valid base address\n", base );
744 		*status = SANE_STATUS_INVAL;
745 		return -1;
746 	}
747 #endif
748 
749 	DBG( 5, "pp_open: looking up port in list\n" );
750 
751 #if defined (HAVE_LIBIEEE1284)
752 	for( i = 0; i < pplist.portc; i++ ) {
753 		DBG( 5, "pp_open: checking >%s<\n", pplist.portv[i]->name );
754 		if( !strcmp(pplist.portv[i]->name, dev))
755 			break;
756 	}
757 
758 	if( pplist.portc <= i ) {
759 		DBG( 1, "pp_open: `%s` is not a valid device name\n", dev );
760 		*status = SANE_STATUS_INVAL;
761 		return -1;
762 	}
763 
764 #else
765 
766 	for( i = 0; i < NELEMS(port); i++ ) {
767 		if( port[i].base == base )
768 			break;
769 	}
770 
771 	if (NELEMS (port) <= i) {
772 
773 		DBG( 1, "pp_open: 0x%03lx is not a valid base address\n", base );
774 		*status = SANE_STATUS_INVAL;
775 		return -1;
776 	}
777 
778 #endif
779 
780 	DBG( 6, "pp_open: port is in list at port[%d]\n", i);
781 
782 	if( port[i].in_use == SANE_TRUE) {
783 
784 #if defined (HAVE_LIBIEEE1284)
785 		DBG( 1, "pp_open: device `%s` is already in use\n", dev );
786 #else
787 		DBG( 1, "pp_open: port 0x%03lx is already in use\n", base );
788 #endif
789 		*status = SANE_STATUS_DEVICE_BUSY;
790 		return -1;
791 	}
792 
793 	port[i].in_use  = SANE_TRUE;
794 	port[i].claimed = SANE_FALSE;
795 
796 #if defined (HAVE_LIBIEEE1284)
797 
798 	DBG( 5, "pp_open: opening device\n" );
799 	result = ieee1284_open( pplist.portv[i], 0, &port[i].caps );
800 	if (result) {
801 		DBG( 1, "pp_open: could not open device `%s` (%s)\n",
802 				dev, pp_libieee1284_errorstr (result));
803 		port[i].in_use = SANE_FALSE;
804 		*status = SANE_STATUS_ACCESS_DENIED;
805 		return -1;
806 	}
807 
808 #else
809 
810 	DBG( 5, "pp_open: getting io permissions\n" );
811 
812 	/* TODO: insert FreeBSD compatible code here */
813 
814 	if( sanei_ioperm( port[i].base, 5, 1 )) {
815 		DBG( 1, "pp_open: cannot get io privilege for port 0x%03lx\n",
816 				port[i].base);
817 
818 		port[i].in_use = SANE_FALSE;
819 		*status = SANE_STATUS_IO_ERROR;
820 		return -1;
821 	}
822 
823 	/* save the CTRL register settings */
824 #ifdef HAVE_IOPL
825 	_SET_IOPL();
826 	port[i].ecp_ctrl = inbyte402(i);
827 	port[i].ctrl     = inb_ctrl(i);
828 #endif
829 
830 	/* check the capabilities of this port */
831 	port[i].caps = pp_probe( i );
832 #endif
833 
834 	port[i].caps = pp_showcaps( port[i].caps );
835 	DBG( 3, "pp_open: device `%s` opened...\n", dev );
836 	*status = SANE_STATUS_GOOD;
837 	return i;
838 }
839 
840 static int
pp_close(int fd,SANE_Status * status)841 pp_close( int fd, SANE_Status *status )
842 {
843 #if defined(HAVE_LIBIEEE1284)
844 	int result;
845 #endif
846 	DBG( 4, "pp_close: fd=%d\n", fd );
847 
848 #if defined(HAVE_LIBIEEE1284)
849 	DBG( 6, "pp_close: this is port '%s'\n", pplist.portv[fd]->name );
850 #else
851 	DBG( 6, "pp_close: this is port 0x%03lx\n", port[fd].base );
852 	DBG( 6, "pp_close: restoring the CTRL registers\n" );
853 	outb_ctrl( fd, port[fd].ctrl );
854 #ifdef HAVE_IOPL
855 	outbyte402( fd, port[fd].ecp_ctrl );
856 #endif
857 #endif
858 
859 	if( port[fd].claimed == SANE_TRUE ) {
860 		sanei_pp_release( fd );
861 	}
862 
863 	DBG( 5, "pp_close: trying to free io port\n" );
864 #if defined(HAVE_LIBIEEE1284)
865 	if((result = ieee1284_close(pplist.portv[fd])) < 0) {
866 #else
867 	if( sanei_ioperm( port[fd].base, 5, 0 )) {
868 #endif
869 #if defined(HAVE_LIBIEEE1284)
870 		DBG( 1, "pp_close: can't free port '%s' (%s)\n",
871 				pplist.portv[fd]->name, pp_libieee1284_errorstr(result));
872 #else
873 		DBG( 1, "pp_close: can't free port 0x%03lx\n", port[fd].base );
874 #endif
875 		*status = SANE_STATUS_IO_ERROR;
876 		return -1;
877 	}
878 
879 	DBG( 5, "pp_close: marking port as unused\n" );
880 	port[fd].in_use = SANE_FALSE;
881 
882 	*status = SANE_STATUS_GOOD;
883 	return 0;
884 }
885 
886 /** exported functions **/
887 
888 SANE_Status
889 sanei_pp_init( void )
890 {
891 	SANE_Status result;
892 
893 	DBG_INIT();
894 
895 	result = pp_init();
896 	if( result != SANE_STATUS_GOOD ) {
897 		return result;
898 	}
899 
900 	pp_calibrate_delay();
901 	return SANE_STATUS_GOOD;
902 }
903 
904 SANE_Status
905 sanei_pp_open( const char *dev, int *fd )
906 {
907 	SANE_Status status;
908 
909 	DBG( 4, "sanei_pp_open: called for device '%s'\n", dev);
910 
911 	*fd = pp_open( dev, &status );
912 	if( *fd  == -1 ) {
913 		DBG( 5, "sanei_pp_open: connection failed\n" );
914 		return status;
915 	}
916 
917 	DBG( 6, "sanei_pp_open: connected to device using fd %u\n", *fd );
918 
919 	return SANE_STATUS_GOOD;
920 }
921 
922 void
923 sanei_pp_close( int fd )
924 {
925 	SANE_Status status;
926 
927 	DBG( 4, "sanei_pp_close: fd = %d\n", fd );
928 
929 #if defined(HAVE_LIBIEEE1284)
930 	if((fd < 0) || (fd >= pplist.portc)) {
931 #else
932 	if((fd < 0) || (fd >= NELEMS (port))) {
933 #endif
934 		DBG( 2, "sanei_pp_close: fd %d is invalid\n", fd );
935 		return;
936 	}
937 
938 	if( port[fd].in_use == SANE_FALSE ) {
939 
940 		DBG( 2, "sanei_pp_close: port is not in use\n" );
941 #if defined(HAVE_LIBIEEE1284)
942 		DBG( 6, "sanei_pp_close: port is '%s'\n", pplist.portv[fd]->name );
943 #else
944 		DBG( 6, "sanei_pp_close: port is 0x%03lx\n", port[fd].base );
945 #endif
946       return;
947     }
948 
949 	DBG( 5, "sanei_pp_close: freeing resources\n" );
950 	if( pp_close (fd, &status) == -1 ) {
951 		DBG( 5, "sanei_pp_close: failed\n" );
952 		return;
953 	}
954 	DBG( 5, "sanei_pp_close: finished\n" );
955 }
956 
957 SANE_Status
958 sanei_pp_claim( int fd )
959 {
960 #if defined (HAVE_LIBIEEE1284)
961 	int result;
962 #endif
963 	DBG( 4, "sanei_pp_claim: fd = %d\n", fd );
964 
965 #if defined (HAVE_LIBIEEE1284)
966 	if((fd < 0) || (fd >= pplist.portc)) {
967 		DBG( 2, "sanei_pp_claim: fd %d is invalid\n", fd );
968 		return SANE_STATUS_INVAL;
969 	}
970 
971 	result = ieee1284_claim (pplist.portv[fd]);
972 	if (result) {
973 		DBG (1, "sanei_pp_claim: failed (%s)\n",
974 				pp_libieee1284_errorstr(result));
975 		return -1;
976 	}
977 #endif
978 
979 	port[fd].claimed = SANE_TRUE;
980 
981 	return SANE_STATUS_GOOD;
982 }
983 
984 SANE_Status
985 sanei_pp_release( int fd )
986 {
987 	DBG( 4, "sanei_pp_release: fd = %d\n", fd );
988 
989 #if defined(HAVE_LIBIEEE1284)
990 	if((fd < 0) || (fd >= pplist.portc)) {
991 		DBG( 2, "sanei_pp_release: fd %d is invalid\n", fd );
992 		return SANE_STATUS_INVAL;
993 	}
994 
995 	ieee1284_release( pplist.portv[fd] );
996 #endif
997 	port[fd].claimed = SANE_FALSE;
998 
999 	return SANE_STATUS_GOOD;
1000 }
1001 
1002 SANE_Status
1003 sanei_pp_outb_data( int fd, SANE_Byte val )
1004 {
1005 #ifdef _PARANOIA
1006 	DBG( 4, "sanei_pp_outb_data: called for fd %d\n", fd );
1007 
1008 #if defined(HAVE_LIBIEEE1284)
1009 	if ((fd < 0) || (fd >= pplist.portc)) {
1010 #else
1011 	if ((fd < 0) || (fd >= NELEMS (port))) {
1012 #endif
1013 		DBG( 2, "sanei_pp_outb_data: invalid fd %d\n", fd );
1014 		return SANE_STATUS_INVAL;
1015     }
1016 #endif
1017 	outb_data( fd, val );
1018 	return SANE_STATUS_GOOD;
1019 }
1020 
1021 SANE_Status
1022 sanei_pp_outb_ctrl( int fd, SANE_Byte val )
1023 {
1024 #ifdef _PARANOIA
1025 	DBG( 4, "sanei_pp_outb_ctrl: called for fd %d\n", fd );
1026 
1027 #if defined(HAVE_LIBIEEE1284)
1028 	if ((fd < 0) || (fd >= pplist.portc)) {
1029 #else
1030 	if ((fd < 0) || (fd >= NELEMS (port))) {
1031 #endif
1032 		DBG( 2, "sanei_pp_outb_ctrl: invalid fd %d\n", fd );
1033 		return SANE_STATUS_INVAL;
1034     }
1035 #endif
1036 	outb_ctrl( fd, val );
1037 	return SANE_STATUS_GOOD;
1038 }
1039 
1040 SANE_Status
1041 sanei_pp_outb_addr( int fd, SANE_Byte val )
1042 {
1043 #ifdef _PARANOIA
1044 	DBG( 4, "sanei_pp_outb_addr: called for fd %d\n", fd );
1045 
1046 #if defined(HAVE_LIBIEEE1284)
1047 	if ((fd < 0) || (fd >= pplist.portc)) {
1048 #else
1049 	if ((fd < 0) || (fd >= NELEMS (port))) {
1050 #endif
1051 		DBG( 2, "sanei_pp_outb_addr: invalid fd %d\n", fd );
1052 		return SANE_STATUS_INVAL;
1053     }
1054 #endif
1055     outb_addr( fd, val );
1056 	return SANE_STATUS_GOOD;
1057 }
1058 
1059 SANE_Status
1060 sanei_pp_outb_epp( int fd, SANE_Byte val )
1061 {
1062 #ifdef _PARANOIA
1063 	DBG( 4, "sanei_pp_outb_epp: called for fd %d\n", fd );
1064 
1065 #if defined(HAVE_LIBIEEE1284)
1066 	if ((fd < 0) || (fd >= pplist.portc)) {
1067 #else
1068 	if ((fd < 0) || (fd >= NELEMS (port))) {
1069 #endif
1070 		DBG( 2, "sanei_pp_outb_epp: invalid fd %d\n", fd );
1071 		return SANE_STATUS_INVAL;
1072     }
1073 #endif
1074     outb_eppdata( fd, val );
1075 	return SANE_STATUS_GOOD;
1076 }
1077 
1078 SANE_Byte
1079 sanei_pp_inb_data( int fd )
1080 {
1081 #ifdef _PARANOIA
1082 	DBG( 4, "sanei_pp_inb_data: called for fd %d\n", fd );
1083 
1084 #if defined(HAVE_LIBIEEE1284)
1085 	if ((fd < 0) || (fd >= pplist.portc)) {
1086 #else
1087 	if ((fd < 0) || (fd >= NELEMS (port))) {
1088 #endif
1089 		DBG( 2, "sanei_pp_inb_data: invalid fd %d\n", fd );
1090 		return SANE_STATUS_INVAL;
1091     }
1092 #endif
1093 	return inb_data( fd );
1094 }
1095 
1096 SANE_Byte
1097 sanei_pp_inb_stat( int fd )
1098 {
1099 #ifdef _PARANOIA
1100 	DBG( 4, "sanei_pp_inb_stat: called for fd %d\n", fd );
1101 
1102 #if defined(HAVE_LIBIEEE1284)
1103 	if ((fd < 0) || (fd >= pplist.portc)) {
1104 #else
1105 	if ((fd < 0) || (fd >= NELEMS (port))) {
1106 #endif
1107 		DBG( 2, "sanei_pp_outb_stat: invalid fd %d\n", fd );
1108 		return SANE_STATUS_INVAL;
1109     }
1110 #endif
1111 	return inb_stat( fd );
1112 }
1113 
1114 SANE_Byte
1115 sanei_pp_inb_ctrl( int fd )
1116 {
1117 #ifdef _PARANOIA
1118 	DBG( 4, "sanei_pp_inb_ctrl: called for fd %d\n", fd );
1119 #if defined(HAVE_LIBIEEE1284)
1120 	if ((fd < 0) || (fd >= pplist.portc)) {
1121 #else
1122 	if ((fd < 0) || (fd >= NELEMS (port))) {
1123 #endif
1124 		DBG( 2, "sanei_pp_inb_ctrl: invalid fd %d\n", fd );
1125 		return SANE_STATUS_INVAL;
1126     }
1127 #endif
1128 	return inb_ctrl( fd );
1129 }
1130 
1131 SANE_Byte
1132 sanei_pp_inb_epp( int fd )
1133 {
1134 #ifdef _PARANOIA
1135 	DBG( 4, "sanei_pp_inb_epp: called for fd %d\n", fd );
1136 
1137 #if defined(HAVE_LIBIEEE1284)
1138 	if ((fd < 0) || (fd >= pplist.portc)) {
1139 #else
1140 	if ((fd < 0) || (fd >= NELEMS (port))) {
1141 #endif
1142 		DBG( 2, "sanei_pp_inb_epp: invalid fd %d\n", fd );
1143 		return SANE_STATUS_INVAL;
1144 	}
1145 #endif
1146 	return inb_eppdata( fd );
1147 }
1148 
1149 SANE_Status
1150 sanei_pp_getmodes( int fd, int *mode )
1151 {
1152 #if defined(HAVE_LIBIEEE1284)
1153 	if ((fd < 0) || (fd >= pplist.portc)) {
1154 #else
1155 	if ((fd < 0) || (fd >= NELEMS (port))) {
1156 #endif
1157 		DBG( 2, "sanei_pp_getmodes: invalid fd %d\n", fd );
1158 		return SANE_STATUS_INVAL;
1159 	}
1160 
1161 	if( mode )
1162 		*mode = port[fd].caps;
1163 
1164 	return SANE_STATUS_GOOD;
1165 }
1166 
1167 SANE_Status
1168 sanei_pp_setmode( int fd, int mode )
1169 {
1170 #if defined(HAVE_LIBIEEE1284)
1171 	int result;
1172 
1173 	if ((fd < 0) || (fd >= pplist.portc)) {
1174 #else
1175 	if ((fd < 0) || (fd >= NELEMS (port))) {
1176 #endif
1177 		DBG( 2, "sanei_pp_setmode: invalid fd %d\n", fd );
1178 		return SANE_STATUS_INVAL;
1179 	}
1180 
1181 	if((mode !=	SANEI_PP_MODE_SPP) && (mode !=	SANEI_PP_MODE_BIDI) &&
1182 	   (mode !=	SANEI_PP_MODE_EPP) && (mode !=	SANEI_PP_MODE_ECP)) {
1183 		DBG( 2, "sanei_pp_setmode: invalid mode %d\n", mode );
1184 		return SANE_STATUS_INVAL;
1185 	}
1186 
1187 #if defined(HAVE_LIBIEEE1284)
1188 	switch( mode ) {
1189 		case SANEI_PP_MODE_SPP:  mode = M1284_NIBBLE; break;
1190 		case SANEI_PP_MODE_BIDI: mode = M1284_BYTE;   break;
1191 		case SANEI_PP_MODE_EPP:  mode = M1284_EPP;    break;
1192 		case SANEI_PP_MODE_ECP:  mode = M1284_ECP;    break;
1193 
1194 		default:
1195 			DBG( 2, "sanei_pp_setmode: invalid mode %d\n", mode );
1196 			return SANE_STATUS_INVAL;
1197 	}
1198 
1199 	result = ieee1284_negotiate( pplist.portv[fd], mode );
1200 
1201 	/* negotiation might fails, but the port-mode should be set... */
1202 	if((E1284_OK != result) && (E1284_NEGFAILED != result)) {
1203 		DBG( 2, "sanei_pp_setmode failed: %s\n",
1204 		        pp_libieee1284_errorstr( result ));
1205 		return SANE_STATUS_INVAL;
1206 	}
1207 
1208 	return SANE_STATUS_GOOD;
1209 #else
1210     return pp_setmode( fd, mode );
1211 #endif
1212 }
1213 
1214 void
1215 sanei_pp_udelay( unsigned long usec )
1216 {
1217 	struct timeval now, deadline;
1218 
1219 	if( usec == 0 )
1220 		return;
1221 
1222 	gettimeofday( &deadline, NULL );
1223 	deadline.tv_usec += usec;
1224 	deadline.tv_sec  += deadline.tv_usec / 1000000;
1225 	deadline.tv_usec %= 1000000;
1226 
1227 	if( usec < pp_thresh )
1228 		return;
1229 
1230 	do {
1231 		gettimeofday( &now, NULL );
1232 	} while ((now.tv_sec < deadline.tv_sec) ||
1233 		(now.tv_sec == deadline.tv_sec && now.tv_usec < deadline.tv_usec));
1234 }
1235 
1236 SANE_Status
1237 sanei_pp_set_datadir( int fd, int rev )
1238 {
1239 #if defined(HAVE_LIBIEEE1284)
1240 	if ((fd < 0) || (fd >= pplist.portc)) {
1241 #else
1242 	SANE_Byte tmp;
1243 
1244 	if ((fd < 0) || (fd >= NELEMS (port))) {
1245 #endif
1246 		DBG( 2, "sanei_pp_setdir: invalid fd %d\n", fd );
1247 		return SANE_STATUS_INVAL;
1248     }
1249 
1250 #if defined(HAVE_LIBIEEE1284)
1251 	ieee1284_data_dir( pplist.portv[fd], rev );
1252 #else
1253 	tmp = inb_ctrl( fd );
1254 	if( SANEI_PP_DATAIN == rev )
1255 		tmp |= SANEI_PP_CTRL_DIRECTION;
1256 	else
1257 		tmp &= ~SANEI_PP_CTRL_DIRECTION;
1258 	outb_ctrl( fd, tmp );
1259 #endif
1260 
1261     return SANE_STATUS_GOOD;
1262 }
1263 
1264 SANE_Bool
1265 sanei_pp_uses_directio( void )
1266 {
1267 #if defined(HAVE_LIBIEEE1284)
1268 	return SANE_FALSE;
1269 #else
1270 	return SANE_TRUE;
1271 #endif
1272 }
1273 
1274 #else /* !HAVE_IOPERM */
1275 
1276 SANE_Status
1277 sanei_pp_init( void )
1278 {
1279 	DBG_INIT();
1280 	_VAR_NOT_USED( first_time );
1281 	return SANE_STATUS_GOOD;
1282 }
1283 
1284 SANE_Status
1285 sanei_pp_open( const char *dev, int *fd )
1286 {
1287 	if (fd)
1288 		*fd = -1;
1289 
1290 	DBG( 4, "sanei_pp_open: called for device `%s`\n", dev );
1291 	DBG( 3, "sanei_pp_open: support not compiled\n" );
1292 	DBG( 6, "sanei_pp_open: basically, this backend does only compile\n" );
1293 	DBG( 6, "sanei_pp_open: on x86 architectures. Furthermore it\n" );
1294 	DBG( 6, "sanei_pp_open: needs ioperm() and sanei_inb()/sanei_outb() calls.\n" );
1295 	DBG( 6, "sanei_pp_open: alternatively it makes use of libieee1284\n" );
1296 	DBG( 6, "sanei_pp_open: (which isn't present either)\n");
1297 	return SANE_STATUS_INVAL;
1298 }
1299 
1300 void
1301 sanei_pp_close( int fd )
1302 {
1303 	DBG( 4, "sanei_pp_close: called for fd %d\n", fd );
1304 	DBG( 2, "sanei_pp_close: fd %d is invalid\n", fd );
1305 	return;
1306 }
1307 
1308 SANE_Status
1309 sanei_pp_claim( int fd )
1310 {
1311 	DBG( 4, "sanei_pp_claim: called for fd %d\n", fd );
1312 	DBG( 2, "sanei_pp_claim: fd %d is invalid\n", fd );
1313 	return SANE_STATUS_INVAL;
1314 }
1315 
1316 SANE_Status
1317 sanei_pp_release( int fd )
1318 {
1319 	DBG( 4, "sanei_pp_release: called for fd %d\n", fd );
1320 	DBG( 2, "sanei_pp_release: fd %d is invalid\n", fd );
1321 	return SANE_STATUS_INVAL;
1322 }
1323 
1324 SANE_Status
1325 sanei_pp_outb_data( int fd, SANE_Byte val )
1326 {
1327 	_VAR_NOT_USED( val );
1328 	DBG( 4, "sanei_pp_outb_data: called for fd %d\n", fd );
1329 	DBG( 2, "sanei_pp_outb_data: fd %d is invalid\n", fd );
1330 	return SANE_STATUS_INVAL;
1331 }
1332 
1333 SANE_Status
1334 sanei_pp_outb_ctrl( int fd, SANE_Byte val )
1335 {
1336 	_VAR_NOT_USED( val );
1337 	DBG( 4, "sanei_pp_outb_ctrl: called for fd %d\n", fd );
1338 	DBG( 2, "sanei_pp_outb_ctrl: fd %d is invalid\n", fd );
1339 	return SANE_STATUS_INVAL;
1340 }
1341 
1342 SANE_Status
1343 sanei_pp_outb_addr( int fd, SANE_Byte val )
1344 {
1345 	_VAR_NOT_USED( val );
1346 	DBG( 4, "sanei_pp_outb_addr: called for fd %d\n", fd );
1347 	DBG( 2, "sanei_pp_outb_addr: fd %d is invalid\n", fd );
1348 	return SANE_STATUS_INVAL;
1349 }
1350 
1351 SANE_Byte
1352 sanei_pp_inb_data( int fd )
1353 {
1354 	DBG( 4, "sanei_pp_inb_data: called for fd %d\n", fd );
1355 	DBG( 2, "sanei_pp_inb_data: fd %d is invalid\n", fd );
1356 	return SANE_STATUS_INVAL;
1357 }
1358 
1359 SANE_Byte sanei_pp_inb_stat( int fd )
1360 {
1361 	DBG( 4, "sanei_pp_inb_stat: called for fd %d\n", fd );
1362 	DBG( 2, "sanei_pp_inb_stat: fd %d is invalid\n", fd );
1363 	return SANE_STATUS_INVAL;
1364 }
1365 
1366 SANE_Byte sanei_pp_inb_ctrl( int fd )
1367 {
1368 	DBG( 4, "sanei_pp_inb_ctrl: called for fd %d\n", fd );
1369 	DBG( 2, "sanei_pp_inb_ctrl: fd %d is invalid\n", fd );
1370 	return SANE_STATUS_INVAL;
1371 }
1372 
1373 SANE_Byte sanei_pp_inb_epp ( int fd )
1374 {
1375 	DBG( 4, "sanei_pp_inb_epp: called for fd %d\n", fd );
1376 	DBG( 2, "sanei_pp_inb_epp: fd %d is invalid\n", fd );
1377 	return SANE_STATUS_INVAL;
1378 }
1379 
1380 SANE_Status
1381 sanei_pp_getmodes( int fd, int *mode )
1382 {
1383 	_VAR_NOT_USED( mode );
1384 	DBG( 4, "sanei_pp_getmodes: called for fd %d\n", fd );
1385 	DBG( 1, "sanei_pp_getmodes: fd %d is invalid\n", fd );
1386 	return SANE_STATUS_INVAL;
1387 }
1388 
1389 SANE_Status
1390 sanei_pp_setmode( int fd, int mode )
1391 {
1392 	_VAR_NOT_USED( mode );
1393 	DBG( 4, "sanei_pp_setmode: called for fd %d\n", fd );
1394 	DBG( 1, "sanei_pp_setmode: fd %d is invalid\n", fd );
1395 	return SANE_STATUS_INVAL;
1396 }
1397 
1398 void
1399 sanei_pp_udelay( unsigned long usec )
1400 {
1401 	_VAR_NOT_USED( usec );
1402 	_VAR_NOT_USED( pp_thresh );
1403 	DBG( 2, "sanei_pp_udelay: not supported\n" );
1404 }
1405 
1406 SANE_Status
1407 sanei_pp_set_datadir( int fd, int rev )
1408 {
1409 	_VAR_NOT_USED( rev );
1410 	DBG( 4, "sanei_pp_setdir: called for fd %d\n", fd );
1411 	DBG( 1, "sanei_pp_setdir: fd %d is invalid\n", fd );
1412 	return SANE_STATUS_INVAL;
1413 }
1414 
1415 SANE_Bool
1416 sanei_pp_uses_directio( void )
1417 {
1418 	DBG( 1, "sanei_pp_uses_directio: not supported\n" );
1419 	return SANE_FALSE;
1420 }
1421 
1422 #endif /* !HAVE_IOPERM */
1423