68a706168f585b7ac0f75ba04146fd5278595eb2
[dragonfly.git] / usr.bin / tip / libacu / unidialer.c
1 /*
2  * Copyright (c) 1986, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * @(#)unidialer.c      8.1 (Berkeley) 6/6/93
34  * $FreeBSD: src/usr.bin/tip/libacu/unidialer.c,v 1.7 1999/08/28 01:06:30 peter Exp $
35  * $DragonFly: src/usr.bin/tip/libacu/unidialer.c,v 1.4 2005/05/07 23:20:43 corecode Exp $
36  */
37
38 /*
39  * Generalized routines for calling up on a Hayes AT command set based modem.
40  * Control variables are pulled out of a modem caps-style database to
41  * configure the driver for a particular modem.
42  */
43 #include "tipconf.h"
44 #include "tip.h"
45 #include "pathnames.h"
46
47 #include <sys/times.h>
48 #include <assert.h>
49 #include <err.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52
53 #include "acucommon.h"
54 #include "tod.h"
55
56 /* #define DEBUG */
57 #define MAXRETRY        5
58
59 typedef enum
60 {
61         mpt_notype, mpt_string, mpt_number, mpt_boolean
62 } modem_parm_type_t;
63
64 typedef struct {
65         modem_parm_type_t modem_parm_type;
66         const char *name;
67         union {
68                 char **string;
69                 unsigned int *number;
70         } value;
71         union {
72                 char *string;
73                 unsigned int number;
74         } default_value;
75 } modem_parm_t;
76
77 /*
78         Configuration
79 */
80 static char modem_name [80];
81 static char *dial_command;
82 static char *hangup_command;
83 static char *echo_off_command;
84 static char *reset_command;
85 static char *init_string;
86 static char *escape_sequence;
87 static int hw_flow_control;
88 static int lock_baud;
89 static unsigned int intercharacter_delay;
90 static unsigned int intercommand_delay;
91 static unsigned int escape_guard_time;
92 static unsigned int reset_delay;
93
94 static int unidialer_dialer (register char *num, char *acu);
95 static void unidialer_disconnect ();
96 static void unidialer_abort ();
97 static int unidialer_connect(void);
98 static int unidialer_swallow(char *);
99
100 static acu_t unidialer =
101 {
102         modem_name,
103         unidialer_dialer,
104         unidialer_disconnect,
105         unidialer_abort
106 };
107
108 /*
109         Table of parameters kept in modem database
110 */
111 modem_parm_t modem_parms [] = {
112         { mpt_string, "dial_command", &dial_command, "ATDT%s\r" },
113         { mpt_string, "hangup_command", &hangup_command, "ATH\r", },
114         { mpt_string, "echo_off_command", &echo_off_command, "ATE0\r" },
115         { mpt_string, "reset_command", &reset_command, "ATZ\r" },
116         { mpt_string, "init_string", &init_string, "AT&F\r", },
117         { mpt_string, "escape_sequence", &escape_sequence, "+++" },
118         { mpt_boolean, "hw_flow_control", (char **)&hw_flow_control, NULL },
119         { mpt_boolean, "lock_baud", (char **)&lock_baud, NULL },
120         { mpt_number, "intercharacter_delay", (char **)&intercharacter_delay, (char *)50 },
121         { mpt_number, "intercommand_delay", (char **)&intercommand_delay, (char *)300 },
122         { mpt_number, "escape_guard_time", (char **)&escape_guard_time, (char *)300 },
123         { mpt_number, "reset_delay", (char **)&reset_delay, (char *)3000 },
124         { mpt_notype, NULL, NULL, NULL }
125 };
126
127 /*
128         Forward declarations
129 */
130 static void unidialer_verbose_read ();
131 static void unidialer_modem_cmd (int fd, CONST char *cmd);
132 static void unidialer_write (int fd, CONST char *cp, int n);
133 static void unidialer_write_str (int fd, CONST char *cp);
134 static void unidialer_disconnect ();
135 static void sigALRM ();
136 static int unidialersync ();
137 static int unidialer_swallow (register char *match);
138
139 /*
140         Global vars
141 */
142 static int timeout = 0;
143 static int connected = 0;
144 static jmp_buf timeoutbuf, intbuf;
145
146 #define cgetflag(f)     (cgetcap(bp, f, ':') != NULL)
147
148 #ifdef DEBUG
149
150 #define print_str(x) printf (#x " = %s\n", x)
151 #define print_num(x) printf (#x " = %d\n", x)
152
153 void dumpmodemparms (char *modem)
154 {
155                 printf ("modem parms for %s\n", modem);
156                 print_str (dial_command);
157                 print_str (hangup_command);
158                 print_str (echo_off_command);
159                 print_str (reset_command);
160                 print_str (init_string);
161                 print_str (escape_sequence);
162                 print_num (lock_baud);
163                 print_num (intercharacter_delay);
164                 print_num (intercommand_delay);
165                 print_num (escape_guard_time);
166                 print_num (reset_delay);
167                 printf ("\n");
168 }
169 #endif
170
171 static int getmodemparms (const char *modem)
172 {
173         char *bp, *db_array [3], *modempath;
174         int ndx, stat;
175         modem_parm_t *mpp;
176
177         modempath = getenv ("MODEMS");
178
179         ndx = 0;
180
181         if (modempath != NULL)
182                 db_array [ndx++] = modempath;
183
184         db_array [ndx++] = _PATH_MODEMS;
185         db_array [ndx] = NULL;
186
187         if ((stat = cgetent (&bp, db_array, (char *)modem)) < 0) {
188                 switch (stat) {
189                 case -1:
190                         warnx ("unknown modem %s", modem);
191                         break;
192                 case -2:
193                         warnx ("can't open modem description file");
194                         break;
195                 case -3:
196                         warnx ("possible reference loop in modem description file");
197                         break;
198                 }
199                 return 0;
200         }
201         for (mpp = modem_parms; mpp->name; mpp++)
202         {
203                 switch (mpp->modem_parm_type)
204                 {
205                         case mpt_string:
206                                 if (cgetstr (bp, (char *)mpp->name, mpp->value.string) == -1)
207                                         *mpp->value.string = mpp->default_value.string;
208                                 break;
209
210                         case mpt_number:
211                         {
212                                 long l;
213                                 if (cgetnum (bp, (char *)mpp->name, &l) == -1)
214                                         *mpp->value.number = mpp->default_value.number;
215                                 else
216                                         *mpp->value.number = (unsigned int)l;
217                         }
218                                 break;
219
220                         case mpt_boolean:
221                                 *mpp->value.number = cgetflag ((char *)mpp->name);
222                                 break;
223                 }
224         }
225         strncpy (modem_name, modem, sizeof (modem_name) - 1);
226         modem_name [sizeof (modem_name) - 1] = '\0';
227         return 1;
228 }
229
230 /*
231 */
232 acu_t* unidialer_getmodem (const char *modem_name)
233 {
234         acu_t* rc = NULL;
235         if (getmodemparms (modem_name))
236                 rc = &unidialer;
237         return rc;
238 }
239
240 static int unidialer_modem_ready ()
241 {
242 #ifdef TIOCMGET
243         int state;
244         ioctl (FD, TIOCMGET, &state);
245         return (state & TIOCM_DSR) ? 1 : 0;
246 #else
247         return (1);
248 #endif
249 }
250
251 static int unidialer_waitfor_modem_ready (int ms)
252 {
253 #ifdef TIOCMGET
254         int count;
255         for (count = 0; count < ms; count += 100)
256         {
257                 if (unidialer_modem_ready ())
258                 {
259 #ifdef DEBUG
260                         printf ("unidialer_waitfor_modem_ready: modem ready.\n");
261 #endif
262                         break;
263                 }
264                 acu_nap (100);
265         }
266         return (count < ms);
267 #else
268         acu_nap (250);
269         return (1);
270 #endif
271 }
272
273 int unidialer_tty_clocal (int flag)
274 {
275 #if HAVE_TERMIOS
276         struct termios t;
277         tcgetattr (FD, &t);
278         if (flag)
279                 t.c_cflag |= CLOCAL;
280         else
281                 t.c_cflag &= ~CLOCAL;
282         tcsetattr (FD, TCSANOW, &t);
283 #elif defined(TIOCMSET)
284         int state;
285         /*
286                 Don't have CLOCAL so raise CD in software to
287                 get the same effect.
288         */
289         ioctl (FD, TIOCMGET, &state);
290         if (flag)
291                 state |= TIOCM_CD;
292         else
293                 state &= ~TIOCM_CD;
294         ioctl (FD, TIOCMSET, &state);
295 #endif
296 }
297
298 int unidialer_get_modem_response (char *buf, int bufsz, int response_timeout)
299 {
300         sig_t f;
301         char c, *p = buf, *lid = buf + bufsz - 1;
302         int state;
303
304         assert (bufsz > 0);
305
306         f = signal (SIGALRM, sigALRM);
307
308         timeout = 0;
309
310         if (setjmp (timeoutbuf)) {
311                 signal (SIGALRM, f);
312                 *p = '\0';
313 #ifdef DEBUG
314                 printf ("get_response: timeout buf=%s, state=%d\n", buf, state);
315 #endif
316                 return (0);
317         }
318
319         ualarm (response_timeout * 1000, 0);
320
321         state = 0;
322
323         while (1)
324         {
325                 switch (state)
326                 {
327                         case 0:
328                                 if (read (FD, &c, 1) == 1)
329                                 {
330                                         if (c == '\r')
331                                         {
332                                                 ++state;
333                                         }
334                                         else
335                                         {
336 #ifdef DEBUG
337                                                 printf ("get_response: unexpected char %s.\n", ctrl (c));
338 #endif
339                                         }
340                                 }
341                                 break;
342
343                         case 1:
344                                 if (read (FD, &c, 1) == 1)
345                                 {
346                                         if (c == '\n')
347                                         {
348 #ifdef DEBUG
349                                                 printf ("get_response: <CRLF> encountered.\n", buf);
350 #endif
351                                                 ++state;
352                                         }
353                                         else
354                                         {
355                                                         state = 0;
356 #ifdef DEBUG
357                                                         printf ("get_response: unexpected char %s.\n", ctrl (c));
358 #endif
359                                         }
360                                 }
361                                 break;
362
363                         case 2:
364                                 if (read (FD, &c, 1) == 1)
365                                 {
366                                         if (c == '\r')
367                                                 ++state;
368                                         else if (c >= ' ' && p < lid)
369                                                 *p++ = c;
370                                 }
371                                 break;
372
373                         case 3:
374                                 if (read (FD, &c, 1) == 1)
375                                 {
376                                         if (c == '\n')
377                                         {
378                                                 signal (SIGALRM, f);
379                                                 /* ualarm (0, 0); */
380                                                 alarm (0);
381                                                 *p = '\0';
382 #ifdef DEBUG
383                                                 printf ("get_response: %s\n", buf);
384 #endif
385                                                 return (1);
386                                         }
387                                         else
388                                         {
389                                                 state = 0;
390                                                 p = buf;
391                                         }
392                                 }
393                                 break;
394                 }
395         }
396 }
397
398 int unidialer_get_okay (int ms)
399 {
400         int okay;
401         char buf [BUFSIZ];
402         okay = unidialer_get_modem_response (buf, sizeof (buf), ms) &&
403                 strcmp (buf, "OK") == 0;
404         return okay;
405 }
406
407 static int unidialer_dialer (register char *num, char *acu)
408 {
409         register char *cp;
410         char dial_string [80];
411 #if ACULOG
412         char line [80];
413 #endif
414
415         #ifdef DEBUG
416         dumpmodemparms (modem_name);
417         #endif
418
419         if (lock_baud) {
420                 int i;
421                 if ((i = speed(number(value(BAUDRATE)))) == 0)
422                         return 0;
423                 ttysetup (i);
424         }
425
426         if (boolean(value(VERBOSE)))
427                 printf("Using \"%s\"\n", acu);
428
429         acu_hupcl ();
430
431         /*
432          * Get in synch.
433          */
434         if (!unidialersync()) {
435 badsynch:
436                 printf("tip: can't synchronize with %s\n", modem_name);
437 #if ACULOG
438                 logent(value(HOST), num, modem_name, "can't synch up");
439 #endif
440                 return (0);
441         }
442
443         unidialer_modem_cmd (FD, echo_off_command);     /* turn off echoing */
444
445         sleep(1);
446
447 #ifdef DEBUG
448         if (boolean(value(VERBOSE)))
449                 unidialer_verbose_read();
450 #endif
451
452         acu_flush (); /* flush any clutter */
453
454         unidialer_modem_cmd (FD, init_string);
455
456         if (!unidialer_get_okay (reset_delay))
457                 goto badsynch;
458
459         fflush (stdout);
460
461         for (cp = num; *cp; cp++)
462                 if (*cp == '=')
463                         *cp = ',';
464
465         (void) sprintf (dial_string, dial_command, num);
466
467         unidialer_modem_cmd (FD, dial_string);
468
469         connected = unidialer_connect ();
470
471         if (connected && hw_flow_control) {
472                 acu_hw_flow_control (hw_flow_control);
473         }
474
475 #if ACULOG
476         if (timeout) {
477                 sprintf(line, "%d second dial timeout",
478                         number(value(DIALTIMEOUT)));
479                 logent(value(HOST), num, modem_name, line);
480         }
481 #endif
482
483         if (timeout)
484                 unidialer_disconnect ();
485
486         return (connected);
487 }
488
489 static void unidialer_disconnect ()
490 {
491         int okay, retries;
492
493         acu_flush (); /* flush any clutter */
494
495         unidialer_tty_clocal (TRUE);
496
497         /* first hang up the modem*/
498         ioctl (FD, TIOCCDTR, 0);
499         acu_nap (250);
500         ioctl (FD, TIOCSDTR, 0);
501
502         /*
503          * If AT&D2, then dropping DTR *should* just hangup the modem. But
504          * some modems reset anyway; also, the modem may be programmed to reset
505          * anyway with AT&D3. Play it safe and wait for the full reset time before
506          * proceeding.
507          */
508         acu_nap (reset_delay);
509
510         if (!unidialer_waitfor_modem_ready (reset_delay))
511         {
512 #ifdef DEBUG
513                         printf ("unidialer_disconnect: warning CTS low.\r\n");
514 #endif
515         }
516
517         /*
518          * If not strapped for DTR control, try to get command mode.
519          */
520         for (retries = okay = 0; retries < MAXRETRY && !okay; retries++)
521         {
522                 int timeout_value;
523                 /* flush any clutter */
524                 if (!acu_flush ())
525                 {
526 #ifdef DEBUG
527                         printf ("unidialer_disconnect: warning flush failed.\r\n");
528 #endif
529                 }
530                 timeout_value = escape_guard_time;
531                 timeout_value += (timeout_value * retries / MAXRETRY);
532                 acu_nap (timeout_value);
533                 acu_flush (); /* flush any clutter */
534                 unidialer_modem_cmd (FD, escape_sequence);
535                 acu_nap (timeout_value);
536                 unidialer_modem_cmd (FD, hangup_command);
537                 okay = unidialer_get_okay (reset_delay);
538         }
539         if (!okay)
540         {
541                 #if ACULOG
542                 logent(value(HOST), "", modem_name, "can't hang up modem");
543                 #endif
544                 if (boolean(value(VERBOSE)))
545                         printf("hang up failed\n");
546         }
547         (void) acu_flush ();
548         close (FD);
549 }
550
551 static void unidialer_abort ()
552 {
553         unidialer_write_str (FD, "\r"); /* send anything to abort the call */
554         unidialer_disconnect ();
555 }
556
557 static void sigALRM ()
558 {
559         (void) printf("\07timeout waiting for reply\n");
560         timeout = 1;
561         longjmp(timeoutbuf, 1);
562 }
563
564 static int unidialer_swallow (register char *match)
565 {
566         sig_t f;
567         char c;
568
569         f = signal(SIGALRM, sigALRM);
570
571         timeout = 0;
572
573         if (setjmp(timeoutbuf)) {
574                 signal(SIGALRM, f);
575                 return (0);
576         }
577
578         alarm(number(value(DIALTIMEOUT)));
579
580         do {
581                 if (*match =='\0') {
582                         signal(SIGALRM, f);
583                         alarm (0);
584                         return (1);
585                 }
586                 do {
587                         read (FD, &c, 1);
588                 } while (c == '\0');
589                 c &= 0177;
590 #ifdef DEBUG
591                 if (boolean(value(VERBOSE)))
592                 {
593                         /* putchar(c); */
594                         printf (ctrl (c));
595                 }
596 #endif
597         } while (c == *match++);
598         signal(SIGALRM, SIG_DFL);
599         alarm(0);
600 #ifdef DEBUG
601         if (boolean(value(VERBOSE)))
602                 fflush (stdout);
603 #endif
604         return (0);
605 }
606
607 static struct baud_msg {
608         char *msg;
609         int baud;
610 } baud_msg[] = {
611         "",             B300,
612         " 1200",        B1200,
613         " 2400",        B2400,
614         " 9600",        B9600,
615         " 9600/ARQ",    B9600,
616         0,              0,
617 };
618
619 static int unidialer_connect ()
620 {
621         char c;
622         int nc, nl, n;
623         char dialer_buf[64];
624         struct baud_msg *bm;
625         sig_t f;
626
627         if (unidialer_swallow("\r\n") == 0)
628                 return (0);
629         f = signal(SIGALRM, sigALRM);
630 again:
631         nc = 0; nl = sizeof(dialer_buf)-1;
632         bzero(dialer_buf, sizeof(dialer_buf));
633         timeout = 0;
634         for (nc = 0, nl = sizeof(dialer_buf)-1 ; nl > 0 ; nc++, nl--) {
635                 if (setjmp(timeoutbuf))
636                         break;
637                 alarm(number(value(DIALTIMEOUT)));
638                 n = read(FD, &c, 1);
639                 alarm(0);
640                 if (n <= 0)
641                         break;
642                 c &= 0x7f;
643                 if (c == '\r') {
644                         if (unidialer_swallow("\n") == 0)
645                                 break;
646                         if (!dialer_buf[0])
647                                 goto again;
648                         if (strcmp(dialer_buf, "RINGING") == 0 &&
649                             boolean(value(VERBOSE))) {
650 #ifdef DEBUG
651                                 printf("%s\r\n", dialer_buf);
652 #endif
653                                 goto again;
654                         }
655                         if (strncmp(dialer_buf, "CONNECT",
656                                     sizeof("CONNECT")-1) != 0)
657                                 break;
658                         if (lock_baud) {
659                                 signal(SIGALRM, f);
660 #ifdef DEBUG
661                                 if (boolean(value(VERBOSE)))
662                                         printf("%s\r\n", dialer_buf);
663 #endif
664                                 return (1);
665                         }
666                         for (bm = baud_msg ; bm->msg ; bm++)
667                                 if (strcmp(bm->msg, dialer_buf+sizeof("CONNECT")-1) == 0) {
668                                         if (!acu_setspeed (bm->baud))
669                                                 goto error;
670                                         signal(SIGALRM, f);
671 #ifdef DEBUG
672                                         if (boolean(value(VERBOSE)))
673                                                 printf("%s\r\n", dialer_buf);
674 #endif
675                                         return (1);
676                                 }
677                         break;
678                 }
679                 dialer_buf[nc] = c;
680         }
681 error1:
682         printf("%s\r\n", dialer_buf);
683 error:
684         signal(SIGALRM, f);
685         return (0);
686 }
687
688 /*
689  * This convoluted piece of code attempts to get
690  * the unidialer in sync.
691  */
692 static int unidialersync ()
693 {
694         int already = 0;
695         int len;
696         char buf[40];
697
698         while (already++ < MAXRETRY) {
699                 acu_nap (intercommand_delay);
700                 acu_flush (); /* flush any clutter */
701                 unidialer_write_str (FD, reset_command); /* reset modem */
702                 bzero(buf, sizeof(buf));
703                 acu_nap (reset_delay);
704                 ioctl (FD, FIONREAD, &len);
705                 if (len) {
706                         len = read(FD, buf, sizeof(buf));
707 #ifdef DEBUG
708                         buf [len] = '\0';
709                         printf("unidialersync (%s): (\"%s\")\n\r", modem_name, buf);
710 #endif
711                         if (index(buf, '0') ||
712                            (index(buf, 'O') && index(buf, 'K')))
713                                 return(1);
714                 }
715                 /*
716                  * If not strapped for DTR control,
717                  * try to get command mode.
718                  */
719                 acu_nap (escape_guard_time);
720                 unidialer_write_str (FD, escape_sequence);
721                 acu_nap (escape_guard_time);
722                 unidialer_write_str (FD, hangup_command);
723                 /*
724                  * Toggle DTR to force anyone off that might have left
725                  * the modem connected.
726                  */
727                 acu_nap (escape_guard_time);
728                 ioctl (FD, TIOCCDTR, 0);
729                 acu_nap (1000);
730                 ioctl (FD, TIOCSDTR, 0);
731         }
732         acu_nap (intercommand_delay);
733         unidialer_write_str (FD, reset_command);
734         return (0);
735 }
736
737 /*
738         Send commands to modem; impose delay between commands.
739 */
740 static void unidialer_modem_cmd (int fd, const char *cmd)
741 {
742         static struct timeval oldt = { 0, 0 };
743         struct timeval newt;
744         tod_gettime (&newt);
745         if (tod_lt (&newt, &oldt))
746         {
747                 unsigned int naptime;
748                 tod_subfrom (&oldt, newt);
749                 naptime = oldt.tv_sec * 1000 + oldt.tv_usec / 1000;
750                 if (naptime > intercommand_delay)
751                 {
752 #ifdef DEBUG
753                 printf ("unidialer_modem_cmd: suspicious naptime (%u ms)\r\n", naptime);
754 #endif
755                         naptime = intercommand_delay;
756                 }
757 #ifdef DEBUG
758                 printf ("unidialer_modem_cmd: delaying %u ms\r\n", naptime);
759 #endif
760                 acu_nap (naptime);
761         }
762         unidialer_write_str (fd, cmd);
763         tod_gettime (&oldt);
764         newt.tv_sec = 0;
765         newt.tv_usec = intercommand_delay;
766         tod_addto (&oldt, &newt);
767 }
768
769 static void unidialer_write_str (int fd, const char *cp)
770 {
771 #ifdef DEBUG
772         printf ("unidialer (%s): sending %s\n", modem_name, cp);
773 #endif
774         unidialer_write (fd, cp, strlen (cp));
775 }
776
777 static void unidialer_write (int fd, const char *cp, int n)
778 {
779         acu_nap (intercharacter_delay);
780         for ( ; n-- ; cp++) {
781                 write (fd, cp, 1);
782                 acu_nap (intercharacter_delay);
783         }
784 }
785
786 #ifdef DEBUG
787 static void unidialer_verbose_read()
788 {
789         int n = 0;
790         char buf[BUFSIZ];
791
792         if (ioctl(FD, FIONREAD, &n) < 0)
793                 return;
794         if (n <= 0)
795                 return;
796         if (read(FD, buf, n) != n)
797                 return;
798         write(1, buf, n);
799 }
800 #endif
801
802 /* end of unidialer.c */