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