17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*24da5b34Srie * Common Development and Distribution License (the "License").
6*24da5b34Srie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*24da5b34Srie * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include "uucp.h"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #if defined(BSD4_2) || defined(ATTSVR4)
367c478bd9Sstevel@tonic-gate #include <netdb.h>
377c478bd9Sstevel@tonic-gate #include <netinet/in.h>
387c478bd9Sstevel@tonic-gate #include <sys/socket.h>
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate #ifdef UNET
417c478bd9Sstevel@tonic-gate #include "UNET/unetio.h"
427c478bd9Sstevel@tonic-gate #include "UNET/tcp.h"
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate
45*24da5b34Srie #include <libgen.h>
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate EXTERN void alarmtr();
487c478bd9Sstevel@tonic-gate EXTERN jmp_buf Sjbuf;
49*24da5b34Srie EXTERN char *fdig();
507c478bd9Sstevel@tonic-gate EXTERN int interface();
517c478bd9Sstevel@tonic-gate EXTERN int fd_mklock(), fd_cklock(), chat(), getdialline();
527c478bd9Sstevel@tonic-gate EXTERN void fixline(), fd_rmlock();
537c478bd9Sstevel@tonic-gate static void translate();
547c478bd9Sstevel@tonic-gate static int gdial();
557c478bd9Sstevel@tonic-gate EXTERN int Modemctrl;
567c478bd9Sstevel@tonic-gate EXTERN unsigned connecttime;
577c478bd9Sstevel@tonic-gate EXTERN int (*Setup)();
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate * to add a new caller:
617c478bd9Sstevel@tonic-gate * declare the function that knows how to call on the device,
627c478bd9Sstevel@tonic-gate * add a line to the callers table giving the name of the device
637c478bd9Sstevel@tonic-gate * (from Devices file) and the name of the function
647c478bd9Sstevel@tonic-gate * add the function to the end of this file
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #ifdef DIAL801
687c478bd9Sstevel@tonic-gate EXTERN int dial801();
697c478bd9Sstevel@tonic-gate EXTERN int open801();
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate #ifdef DATAKIT
737c478bd9Sstevel@tonic-gate EXTERN int dkcall();
747c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate #ifdef V8
777c478bd9Sstevel@tonic-gate int Dialout();
787c478bd9Sstevel@tonic-gate #endif
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate #ifdef TCP
817c478bd9Sstevel@tonic-gate int unetcall();
827c478bd9Sstevel@tonic-gate int tcpcall();
837c478bd9Sstevel@tonic-gate #endif /* TCP */
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate #ifdef SYTEK
867c478bd9Sstevel@tonic-gate int sytcall();
877c478bd9Sstevel@tonic-gate #endif /* SYTEK */
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate #ifdef TLI
907c478bd9Sstevel@tonic-gate EXTERN int tlicall();
917c478bd9Sstevel@tonic-gate #endif /* TLI */
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate static struct caller Caller[] = {
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate #ifdef DIAL801
967c478bd9Sstevel@tonic-gate {"801", dial801},
977c478bd9Sstevel@tonic-gate {"212", dial801},
987c478bd9Sstevel@tonic-gate #endif /* DIAL801 */
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate #ifdef V8
1017c478bd9Sstevel@tonic-gate {"Dialout", Dialout}, /* ditto but using dialout(III) */
1027c478bd9Sstevel@tonic-gate #endif
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate #ifdef TCP
1057c478bd9Sstevel@tonic-gate #if defined(BSD4_2) || defined(ATTSVR4)
1067c478bd9Sstevel@tonic-gate {"TCP", tcpcall}, /* 4.2BSD sockets */
1077c478bd9Sstevel@tonic-gate #else /* !BSD4_2 */
1087c478bd9Sstevel@tonic-gate #ifdef UNET
1097c478bd9Sstevel@tonic-gate {"TCP", unetcall}, /* 3com implementation of tcp */
1107c478bd9Sstevel@tonic-gate {"Unetserver", unetcall},
1117c478bd9Sstevel@tonic-gate #endif /* UNET */
1127c478bd9Sstevel@tonic-gate #endif /* BSD4_2 || ATTSVR4 */
1137c478bd9Sstevel@tonic-gate #endif /* TCP */
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate #ifdef DATAKIT
1167c478bd9Sstevel@tonic-gate {"DK", dkcall}, /* standard AT&T DATAKIT VCS caller */
1177c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate #ifdef SYTEK
1207c478bd9Sstevel@tonic-gate {"Sytek", sytcall}, /* untested but should work */
1217c478bd9Sstevel@tonic-gate #endif /* SYTEK */
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate #ifdef TLI
1247c478bd9Sstevel@tonic-gate {"TLI", tlicall}, /* AT&T Transport Layer Interface */
1257c478bd9Sstevel@tonic-gate #ifdef TLIS
1267c478bd9Sstevel@tonic-gate {"TLIS", tlicall}, /* AT&T Transport Layer Interface */
1277c478bd9Sstevel@tonic-gate #endif /* TLIS */
1287c478bd9Sstevel@tonic-gate #endif /* TLI */
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate {NULL, NULL} /* this line must be last */
1317c478bd9Sstevel@tonic-gate };
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate * exphone - expand phone number for given prefix and number
1357c478bd9Sstevel@tonic-gate *
1367c478bd9Sstevel@tonic-gate * return code - none
1377c478bd9Sstevel@tonic-gate */
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate static void
exphone(in,out)1407c478bd9Sstevel@tonic-gate exphone(in, out)
1417c478bd9Sstevel@tonic-gate char *in, *out;
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate FILE *fn;
1447c478bd9Sstevel@tonic-gate char pre[MAXPH], npart[MAXPH], tpre[MAXPH], p[MAXPH];
1457c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
1467c478bd9Sstevel@tonic-gate char *s1;
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate if (!isalpha(*in)) {
1497c478bd9Sstevel@tonic-gate (void) strcpy(out, in);
1507c478bd9Sstevel@tonic-gate return;
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate s1=pre;
1547c478bd9Sstevel@tonic-gate while (isalpha(*in))
1557c478bd9Sstevel@tonic-gate *s1++ = *in++;
1567c478bd9Sstevel@tonic-gate *s1 = NULLCHAR;
1577c478bd9Sstevel@tonic-gate s1 = npart;
1587c478bd9Sstevel@tonic-gate while (*in != NULLCHAR)
1597c478bd9Sstevel@tonic-gate *s1++ = *in++;
1607c478bd9Sstevel@tonic-gate *s1 = NULLCHAR;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR;
1637c478bd9Sstevel@tonic-gate fn = fopen(DIALCODES, "r");
1647c478bd9Sstevel@tonic-gate if (fn != NULL) {
1657c478bd9Sstevel@tonic-gate while (fgets(buf, BUFSIZ, fn)) {
1667c478bd9Sstevel@tonic-gate if ( sscanf(buf, "%s%s", p, tpre) < 1)
1677c478bd9Sstevel@tonic-gate continue;
1687c478bd9Sstevel@tonic-gate if (EQUALS(p, pre))
1697c478bd9Sstevel@tonic-gate break;
1707c478bd9Sstevel@tonic-gate tpre[0] = NULLCHAR;
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate fclose(fn);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate (void) strcpy(out, tpre);
1767c478bd9Sstevel@tonic-gate (void) strcat(out, npart);
1777c478bd9Sstevel@tonic-gate return;
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate /*
1817c478bd9Sstevel@tonic-gate * repphone - Replace \D and \T sequences in arg with phone
1827c478bd9Sstevel@tonic-gate * expanding and translating as appropriate.
1837c478bd9Sstevel@tonic-gate */
1847c478bd9Sstevel@tonic-gate static char *
repphone(arg,phone,trstr)1857c478bd9Sstevel@tonic-gate repphone(arg, phone, trstr)
186462be471Sceastha char *arg, *phone, *trstr;
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate static char pbuf[2*(MAXPH+2)];
189462be471Sceastha char *fp, *tp;
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate for (tp=pbuf; *arg; arg++) {
1927c478bd9Sstevel@tonic-gate if (*arg != '\\') {
1937c478bd9Sstevel@tonic-gate *tp++ = *arg;
1947c478bd9Sstevel@tonic-gate continue;
1957c478bd9Sstevel@tonic-gate } else {
1967c478bd9Sstevel@tonic-gate switch (*(arg+1)) {
1977c478bd9Sstevel@tonic-gate case 'T':
1987c478bd9Sstevel@tonic-gate exphone(phone, tp);
1997c478bd9Sstevel@tonic-gate translate(trstr, tp);
2007c478bd9Sstevel@tonic-gate for(; *tp; tp++)
2017c478bd9Sstevel@tonic-gate ;
2027c478bd9Sstevel@tonic-gate arg++;
2037c478bd9Sstevel@tonic-gate break;
2047c478bd9Sstevel@tonic-gate case 'D':
2057c478bd9Sstevel@tonic-gate for(fp=phone; *tp = *fp++; tp++)
2067c478bd9Sstevel@tonic-gate ;
2077c478bd9Sstevel@tonic-gate arg++;
2087c478bd9Sstevel@tonic-gate break;
2097c478bd9Sstevel@tonic-gate default:
2107c478bd9Sstevel@tonic-gate *tp++ = *arg;
2117c478bd9Sstevel@tonic-gate break;
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate *tp = '\0';
2167c478bd9Sstevel@tonic-gate return(pbuf);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate static u_int saved_mode;
2207c478bd9Sstevel@tonic-gate static char saved_dcname[20];
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate * processdev - Process a line from the Devices file
2247c478bd9Sstevel@tonic-gate *
2257c478bd9Sstevel@tonic-gate * return codes:
2267c478bd9Sstevel@tonic-gate * file descriptor - succeeded
2277c478bd9Sstevel@tonic-gate * FAIL - failed
2287c478bd9Sstevel@tonic-gate */
2297c478bd9Sstevel@tonic-gate GLOBAL int
processdev(flds,dev)2307c478bd9Sstevel@tonic-gate processdev(flds, dev)
231462be471Sceastha char *flds[], *dev[];
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate int dcf = -1;
234462be471Sceastha struct caller *ca;
2357c478bd9Sstevel@tonic-gate char *args[D_MAX+1], dcname[20];
236462be471Sceastha char **sdev;
2377c478bd9Sstevel@tonic-gate EXTERN int pop_push();
2387c478bd9Sstevel@tonic-gate EXTERN void setdevcfg();
239462be471Sceastha int nullfd;
2407c478bd9Sstevel@tonic-gate char *phonecl; /* clear phone string */
2417c478bd9Sstevel@tonic-gate char phoneex[2*(MAXPH+2)]; /* expanded phone string */
2427c478bd9Sstevel@tonic-gate EXTERN void ttygenbrk();
2437c478bd9Sstevel@tonic-gate struct termio tty_orig;
2447c478bd9Sstevel@tonic-gate int ret_orig = -1;
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate sdev = dev;
2477c478bd9Sstevel@tonic-gate /* set up default "break" routine */
2487c478bd9Sstevel@tonic-gate genbrk = ttygenbrk;
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate /* initialize Devconfig info */
2517c478bd9Sstevel@tonic-gate DEBUG(5, "processdev: calling setdevcfg(%s, ", Progname);
2527c478bd9Sstevel@tonic-gate DEBUG(5, "%s)\n", flds[F_TYPE]);
2537c478bd9Sstevel@tonic-gate setdevcfg(Progname, flds[F_TYPE]);
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate for (ca = Caller; ca->CA_type != NULL; ca++) {
2567c478bd9Sstevel@tonic-gate /* This will find built-in caller functions */
2577c478bd9Sstevel@tonic-gate if (EQUALS(ca->CA_type, dev[D_CALLER])) {
2587c478bd9Sstevel@tonic-gate DEBUG(5, "Internal caller type %s\n", dev[D_CALLER]);
2597c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) {
2607c478bd9Sstevel@tonic-gate /* if NULL - assume translate */
2617c478bd9Sstevel@tonic-gate dev[D_ARG+1] = NULL; /* needed for for loop later to mark the end */
2627c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\T";
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate dev[D_ARG] = repphone(dev[D_ARG], flds[F_PHONE], "");
2657c478bd9Sstevel@tonic-gate if ((dcf = (*(ca->CA_caller))(flds, dev)) < 0)
2667c478bd9Sstevel@tonic-gate return(dcf) ;
2677c478bd9Sstevel@tonic-gate if ( interface( ca->CA_type ) ) {
2687c478bd9Sstevel@tonic-gate DEBUG(5, "interface(%s) failed", ca->CA_type);
2697c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED;
2707c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */
2717c478bd9Sstevel@tonic-gate (void)interface("UNIX");
2727c478bd9Sstevel@tonic-gate return(FAIL);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate dev += 2; /* Skip to next CALLER and ARG */
2757c478bd9Sstevel@tonic-gate break;
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate if (dcf == -1) {
2797c478bd9Sstevel@tonic-gate /* Here if not a built-in caller function */
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate /* We do locking (file and advisory) after open */
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate /*
2847c478bd9Sstevel@tonic-gate * Open the line
2857c478bd9Sstevel@tonic-gate */
2867c478bd9Sstevel@tonic-gate if ( *dev[D_LINE] != '/' ) {
2877c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
2887c478bd9Sstevel@tonic-gate } else {
2897c478bd9Sstevel@tonic-gate (void) strcpy(dcname, dev[D_LINE] );
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate /* take care of the possible partial open fd */
2927c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY));
2937c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
2947c478bd9Sstevel@tonic-gate (void) close(nullfd);
2957c478bd9Sstevel@tonic-gate DEBUG(1, "generic open timeout\n%s", "");
2967c478bd9Sstevel@tonic-gate logent("generic open", "TIMEOUT");
2977c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE;
2987c478bd9Sstevel@tonic-gate goto bad;
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
3017c478bd9Sstevel@tonic-gate (void) alarm(10);
3027c478bd9Sstevel@tonic-gate if ( Modemctrl ) {
3037c478bd9Sstevel@tonic-gate DEBUG(7, "opening with O_NDELAY set\n%s", "");
3047c478bd9Sstevel@tonic-gate dcf = open(dcname, (O_RDWR | O_NDELAY) );
3057c478bd9Sstevel@tonic-gate saved_mode = O_RDWR | O_NDELAY;
3067c478bd9Sstevel@tonic-gate } else {
3077c478bd9Sstevel@tonic-gate dcf = open(dcname, O_RDWR );
3087c478bd9Sstevel@tonic-gate saved_mode = O_RDWR;
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate strcpy(saved_dcname, dcname);
3117c478bd9Sstevel@tonic-gate (void) alarm(0);
3127c478bd9Sstevel@tonic-gate if (dcf < 0) {
3137c478bd9Sstevel@tonic-gate DEBUG(1, "generic open failed, errno = %d\n", errno);
3147c478bd9Sstevel@tonic-gate (void) close(nullfd);
3157c478bd9Sstevel@tonic-gate logent("generic open", "FAILED");
3167c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE;
3177c478bd9Sstevel@tonic-gate goto bad;
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate /* check locks BEFORE modifying the stream */
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate if ( fd_mklock(dcf) != SUCCESS ) {
3237c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname);
3247c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE;
3257c478bd9Sstevel@tonic-gate goto bad;
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate if ( Modemctrl ) {
3297c478bd9Sstevel@tonic-gate DEBUG(7, "clear O_NDELAY\n%s", "");
3307c478bd9Sstevel@tonic-gate if ( fcntl(dcf, F_SETFL,
3317c478bd9Sstevel@tonic-gate (fcntl(dcf, F_GETFL, 0) & ~O_NDELAY)) < 0 ) {
3327c478bd9Sstevel@tonic-gate DEBUG( 7, "clear O_NDELAY failed, errno %d\n", errno);
3337c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED;
3347c478bd9Sstevel@tonic-gate goto bad;
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate if ( (*Setup)( MASTER, &dcf, &dcf ) ) {
3407c478bd9Sstevel@tonic-gate /* any device|system lock files we should remove? */
3417c478bd9Sstevel@tonic-gate DEBUG(5, "MASTER Setup failed%s", "");
3427c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED;
3437c478bd9Sstevel@tonic-gate goto bad;
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /* configure any requested streams modules */
3477c478bd9Sstevel@tonic-gate if ( !pop_push(dcf) ) {
3487c478bd9Sstevel@tonic-gate DEBUG(5, "STREAMS module configuration failed%s\n","");
3497c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED;
3507c478bd9Sstevel@tonic-gate goto bad;
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate /* save initial state of line in case script fails */
3547c478bd9Sstevel@tonic-gate ret_orig = ioctl(dcf, TCGETA, &tty_orig);
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate /* use sdev[] since dev[] is incremented for internal callers */
3577c478bd9Sstevel@tonic-gate fixline(dcf, atoi(fdig(sdev[D_CLASS])), D_DIRECT);
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate * Now loop through the remaining callers and chat
3617c478bd9Sstevel@tonic-gate * according to scripts in dialers file.
3627c478bd9Sstevel@tonic-gate */
3637c478bd9Sstevel@tonic-gate for (; dev[D_CALLER] != NULL; dev += 2) {
364462be471Sceastha int w;
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate * Scan Dialers file to find an entry
3677c478bd9Sstevel@tonic-gate */
3687c478bd9Sstevel@tonic-gate if ((w = gdial(dev[D_CALLER], args, D_MAX)) < 1) {
3697c478bd9Sstevel@tonic-gate logent("generic call to gdial", "FAILED");
3707c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE;
3717c478bd9Sstevel@tonic-gate goto bad;
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate if (w <= 2) /* do nothing - no chat */
3747c478bd9Sstevel@tonic-gate break;
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate * Translate the phone number
3777c478bd9Sstevel@tonic-gate */
3787c478bd9Sstevel@tonic-gate if (dev[D_ARG] == NULL) {
3797c478bd9Sstevel@tonic-gate /* if NULL - assume no translation */
3807c478bd9Sstevel@tonic-gate dev[D_ARG+1] = NULL; /* needed for for loop to mark the end */
3817c478bd9Sstevel@tonic-gate dev[D_ARG] = "\\D";
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate phonecl = repphone(dev[D_ARG], flds[F_PHONE], args[1]);
3857c478bd9Sstevel@tonic-gate exphone(phonecl, phoneex);
3867c478bd9Sstevel@tonic-gate translate(args[1], phoneex);
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate * Chat
3897c478bd9Sstevel@tonic-gate */
3907c478bd9Sstevel@tonic-gate if (chat(w-2, &args[2], dcf, phonecl, phoneex) != SUCCESS) {
3917c478bd9Sstevel@tonic-gate CDEBUG(5, "\nCHAT gdial(%s) FAILED\n", dev[D_CALLER]);
3927c478bd9Sstevel@tonic-gate Uerror = SS_CHAT_FAILED;
3937c478bd9Sstevel@tonic-gate goto bad;
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate /*
3977c478bd9Sstevel@tonic-gate * Success at last!
3987c478bd9Sstevel@tonic-gate */
3997c478bd9Sstevel@tonic-gate strcpy(Dc, sdev[D_LINE]);
4007c478bd9Sstevel@tonic-gate return(dcf);
4017c478bd9Sstevel@tonic-gate bad:
4027c478bd9Sstevel@tonic-gate if ( dcf >= 0 ) {
4037c478bd9Sstevel@tonic-gate /* reset line settings if we got them in the beginning */
4047c478bd9Sstevel@tonic-gate if ( ret_orig == 0 )
4057c478bd9Sstevel@tonic-gate (void) ioctl(dcf, TCSETAW, &tty_orig);
4067c478bd9Sstevel@tonic-gate fd_rmlock(dcf);
4077c478bd9Sstevel@tonic-gate (void)close(dcf);
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate /* restore vanilla unix interface */
4107c478bd9Sstevel@tonic-gate (void)interface("UNIX");
4117c478bd9Sstevel@tonic-gate return(FAIL);
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate /*
4157c478bd9Sstevel@tonic-gate * clear_hup() clear the hangup state of the given device
4167c478bd9Sstevel@tonic-gate */
4177c478bd9Sstevel@tonic-gate GLOBAL int
clear_hup(dcf)4187c478bd9Sstevel@tonic-gate clear_hup(dcf)
4197c478bd9Sstevel@tonic-gate int dcf;
4207c478bd9Sstevel@tonic-gate {
4217c478bd9Sstevel@tonic-gate int ndcf;
4227c478bd9Sstevel@tonic-gate if ((ndcf = open(saved_dcname, saved_mode)) < 0) {
4237c478bd9Sstevel@tonic-gate return (FAIL);
4247c478bd9Sstevel@tonic-gate }
4257c478bd9Sstevel@tonic-gate if (ndcf != dcf) {
4267c478bd9Sstevel@tonic-gate close(ndcf);
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate return (SUCCESS);
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate * translate the pairs of characters present in the first
4347c478bd9Sstevel@tonic-gate * string whenever the first of the pair appears in the second
4357c478bd9Sstevel@tonic-gate * string.
4367c478bd9Sstevel@tonic-gate */
4377c478bd9Sstevel@tonic-gate static void
translate(ttab,str)4387c478bd9Sstevel@tonic-gate translate(ttab, str)
439462be471Sceastha char *ttab, *str;
4407c478bd9Sstevel@tonic-gate {
441462be471Sceastha char *s;
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate for(;*ttab && *(ttab+1); ttab += 2)
4447c478bd9Sstevel@tonic-gate for(s=str;*s;s++)
4457c478bd9Sstevel@tonic-gate if(*ttab == *s)
4467c478bd9Sstevel@tonic-gate *s = *(ttab+1);
4477c478bd9Sstevel@tonic-gate return;
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate #define MAXLINE 512
4517c478bd9Sstevel@tonic-gate /*
4527c478bd9Sstevel@tonic-gate * Get the information about the dialer.
4537c478bd9Sstevel@tonic-gate * gdial(type, arps, narps)
4547c478bd9Sstevel@tonic-gate * type -> type of dialer (e.g., penril)
4557c478bd9Sstevel@tonic-gate * arps -> array of pointers returned by gdial
4567c478bd9Sstevel@tonic-gate * narps -> number of elements in array returned by gdial
4577c478bd9Sstevel@tonic-gate * Return value:
4587c478bd9Sstevel@tonic-gate * -1 -> Can't open DIALERFILE
4597c478bd9Sstevel@tonic-gate * 0 -> requested type not found
4607c478bd9Sstevel@tonic-gate * >0 -> success - number of fields filled in
4617c478bd9Sstevel@tonic-gate */
4627c478bd9Sstevel@tonic-gate static int
gdial(type,arps,narps)4637c478bd9Sstevel@tonic-gate gdial(type, arps, narps)
464462be471Sceastha char *type, *arps[];
465462be471Sceastha int narps;
4667c478bd9Sstevel@tonic-gate {
4677c478bd9Sstevel@tonic-gate static char info[MAXLINE];
468462be471Sceastha int na;
4697c478bd9Sstevel@tonic-gate EXTERN void dialreset();
4707c478bd9Sstevel@tonic-gate EXTERN char * currdial();
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate DEBUG(2, "gdial(%s) called\n", type);
4737c478bd9Sstevel@tonic-gate while (getdialline(info, sizeof(info))) {
4747c478bd9Sstevel@tonic-gate if ((info[0] == '#') || (info[0] == ' ') ||
4757c478bd9Sstevel@tonic-gate (info[0] == '\t') || (info[0] == '\n'))
4767c478bd9Sstevel@tonic-gate continue;
4777c478bd9Sstevel@tonic-gate if ((na = getargs(info, arps, narps)) == 0)
4787c478bd9Sstevel@tonic-gate continue;
4797c478bd9Sstevel@tonic-gate if (EQUALS(arps[0], type)) {
4807c478bd9Sstevel@tonic-gate DEBUG(5, "Trying caller script '%s'", type);
4817c478bd9Sstevel@tonic-gate DEBUG(5, " from '%s'.\n", currdial());
4827c478bd9Sstevel@tonic-gate dialreset();
4837c478bd9Sstevel@tonic-gate bsfix(arps);
4847c478bd9Sstevel@tonic-gate return(na);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate DEBUG(1, "%s not found in Dialers file\n", type);
4887c478bd9Sstevel@tonic-gate dialreset();
4897c478bd9Sstevel@tonic-gate return(0);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate #ifdef DATAKIT
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate /*
4967c478bd9Sstevel@tonic-gate * dkcall(flds, dev) make a DATAKIT VCS connection
4977c478bd9Sstevel@tonic-gate * DATAKIT VCS is a trademark of AT&T
4987c478bd9Sstevel@tonic-gate *
4997c478bd9Sstevel@tonic-gate * return codes:
5007c478bd9Sstevel@tonic-gate * >0 - file number - ok
5017c478bd9Sstevel@tonic-gate * FAIL - failed
5027c478bd9Sstevel@tonic-gate */
5037c478bd9Sstevel@tonic-gate
5047c478bd9Sstevel@tonic-gate #include "dk.h"
5057c478bd9Sstevel@tonic-gate EXTERN int dkdial();
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5087c478bd9Sstevel@tonic-gate GLOBAL int
dkcall(flds,dev)5097c478bd9Sstevel@tonic-gate dkcall(flds, dev)
5107c478bd9Sstevel@tonic-gate char *flds[], *dev[];
5117c478bd9Sstevel@tonic-gate {
512462be471Sceastha int fd;
5137c478bd9Sstevel@tonic-gate #ifdef V8
5147c478bd9Sstevel@tonic-gate extern int cdkp_ld;
5157c478bd9Sstevel@tonic-gate #endif
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate char dialstring[64];
5187c478bd9Sstevel@tonic-gate EXTERN void dkbreak();
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate strcpy(dialstring, dev[D_ARG]);
5217c478bd9Sstevel@tonic-gate DEBUG(4, "dkcall(%s)\n", dialstring);
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate #ifdef V8
5257c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
5267c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
5277c478bd9Sstevel@tonic-gate return(FAIL);
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
5317c478bd9Sstevel@tonic-gate (void) alarm(connecttime);
5327c478bd9Sstevel@tonic-gate DEBUG(4, "tdkdial(%s", flds[F_PHONE]);
5337c478bd9Sstevel@tonic-gate DEBUG(4, ", %d)\n", atoi(dev[D_CLASS]));
5347c478bd9Sstevel@tonic-gate if ((fd = tdkdial(flds[F_PHONE], atoi(dev[D_CLASS]))) >= 0)
5357c478bd9Sstevel@tonic-gate if (dkproto(fd, cdkp_ld) < 0)
5367c478bd9Sstevel@tonic-gate {
5377c478bd9Sstevel@tonic-gate close(fd);
5387c478bd9Sstevel@tonic-gate fd = -1;
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate (void) alarm(0);
5417c478bd9Sstevel@tonic-gate #else
5427c478bd9Sstevel@tonic-gate fd = dkdial(dialstring);
5437c478bd9Sstevel@tonic-gate #endif
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "DK");
5467c478bd9Sstevel@tonic-gate if (fd < 0) {
5477c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
5487c478bd9Sstevel@tonic-gate return(FAIL);
5497c478bd9Sstevel@tonic-gate }
5507c478bd9Sstevel@tonic-gate else {
5517c478bd9Sstevel@tonic-gate genbrk = dkbreak;
5527c478bd9Sstevel@tonic-gate return(fd);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate }
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
5577c478bd9Sstevel@tonic-gate
5587c478bd9Sstevel@tonic-gate #ifdef TCP
5597c478bd9Sstevel@tonic-gate
5607c478bd9Sstevel@tonic-gate /*
5617c478bd9Sstevel@tonic-gate * tcpcall(flds, dev) make ethernet/socket connection
5627c478bd9Sstevel@tonic-gate *
5637c478bd9Sstevel@tonic-gate * return codes:
5647c478bd9Sstevel@tonic-gate * >0 - file number - ok
5657c478bd9Sstevel@tonic-gate * FAIL - failed
5667c478bd9Sstevel@tonic-gate */
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate #if !(defined(BSD4_2) || defined(ATTSVR4))
5697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5707c478bd9Sstevel@tonic-gate GLOBAL int
tcpcall(flds,dev)5717c478bd9Sstevel@tonic-gate tcpcall(flds, dev)
5727c478bd9Sstevel@tonic-gate char *flds[], *dev[];
5737c478bd9Sstevel@tonic-gate {
5747c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
5757c478bd9Sstevel@tonic-gate return(FAIL);
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate #else /* BSD4_2 */
5787c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5797c478bd9Sstevel@tonic-gate GLOBAL int
tcpcall(flds,dev)5807c478bd9Sstevel@tonic-gate tcpcall(flds, dev)
5817c478bd9Sstevel@tonic-gate char *flds[], *dev[];
5827c478bd9Sstevel@tonic-gate {
5837c478bd9Sstevel@tonic-gate int ret;
5847c478bd9Sstevel@tonic-gate short port;
5857c478bd9Sstevel@tonic-gate struct servent *sp;
5867c478bd9Sstevel@tonic-gate struct hostent *hp;
5877c478bd9Sstevel@tonic-gate struct sockaddr_in sin;
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate if (EQUALS(flds[F_CLASS], "-")) {
5907c478bd9Sstevel@tonic-gate /*
5917c478bd9Sstevel@tonic-gate * Use standard UUCP port number.
5927c478bd9Sstevel@tonic-gate */
5937c478bd9Sstevel@tonic-gate sp = getservbyname("uucp", "tcp");
5947c478bd9Sstevel@tonic-gate endservent();
5957c478bd9Sstevel@tonic-gate ASSERT(sp != NULL, "No uucp service number", 0, 0);
5967c478bd9Sstevel@tonic-gate port = sp->s_port;
5977c478bd9Sstevel@tonic-gate } else {
5987c478bd9Sstevel@tonic-gate /*
5997c478bd9Sstevel@tonic-gate * Systems file specifies a port number.
6007c478bd9Sstevel@tonic-gate */
6017c478bd9Sstevel@tonic-gate sp = getservbyname(flds[F_CLASS], "tcp");
6027c478bd9Sstevel@tonic-gate endservent();
6037c478bd9Sstevel@tonic-gate if (sp == NULL) {
6047c478bd9Sstevel@tonic-gate port = htons(atoi(flds[F_CLASS]));
6057c478bd9Sstevel@tonic-gate if (port == 0) {
6067c478bd9Sstevel@tonic-gate logent("tcpopen", "unknown port number");
6077c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
6087c478bd9Sstevel@tonic-gate return(FAIL);
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate } else
6117c478bd9Sstevel@tonic-gate port = sp->s_port;
6127c478bd9Sstevel@tonic-gate }
6137c478bd9Sstevel@tonic-gate if (EQUALS(flds[F_PHONE], "-")) {
6147c478bd9Sstevel@tonic-gate /*
6157c478bd9Sstevel@tonic-gate * Use UUCP name as host name.
6167c478bd9Sstevel@tonic-gate */
6177c478bd9Sstevel@tonic-gate hp = gethostbyname(flds[F_NAME]);
6187c478bd9Sstevel@tonic-gate } else {
6197c478bd9Sstevel@tonic-gate /*
6207c478bd9Sstevel@tonic-gate * Systems file specifies a host name different from the UUCP
6217c478bd9Sstevel@tonic-gate * host name.
6227c478bd9Sstevel@tonic-gate */
6237c478bd9Sstevel@tonic-gate hp = gethostbyname(flds[F_PHONE]);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate endhostent();
6267c478bd9Sstevel@tonic-gate if (hp == NULL) {
6277c478bd9Sstevel@tonic-gate logent("tcpopen", "no such host");
6287c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
6297c478bd9Sstevel@tonic-gate return(FAIL);
6307c478bd9Sstevel@tonic-gate }
6317c478bd9Sstevel@tonic-gate DEBUG(4, "tcpdial host %s, ", hp->h_name);
6327c478bd9Sstevel@tonic-gate DEBUG(4, "port %d\n", ntohs(port));
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate ret = socket(AF_INET, SOCK_STREAM, 0);
6357c478bd9Sstevel@tonic-gate if (ret < 0) {
636ace1a5f1Sdp DEBUG(5, "no socket: %s\n", strerror(errno));
637ace1a5f1Sdp logent("no socket", strerror(errno));
6387c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
6397c478bd9Sstevel@tonic-gate return(FAIL);
6407c478bd9Sstevel@tonic-gate }
6417c478bd9Sstevel@tonic-gate sin.sin_family = hp->h_addrtype;
6427c478bd9Sstevel@tonic-gate #ifdef BSD4_2
6437c478bd9Sstevel@tonic-gate bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
6447c478bd9Sstevel@tonic-gate #else
6457c478bd9Sstevel@tonic-gate memcpy((caddr_t)&sin.sin_addr, hp->h_addr, hp->h_length);
6467c478bd9Sstevel@tonic-gate #endif
6477c478bd9Sstevel@tonic-gate sin.sin_port = port;
6487c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
6497c478bd9Sstevel@tonic-gate DEBUG(4, "timeout tcpopen\n%s", "");
6507c478bd9Sstevel@tonic-gate logent("tcpopen", "TIMEOUT");
6517c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
6527c478bd9Sstevel@tonic-gate return(FAIL);
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
6557c478bd9Sstevel@tonic-gate (void) alarm(connecttime);
6567c478bd9Sstevel@tonic-gate DEBUG(7, "family: %d\n", sin.sin_family);
6577c478bd9Sstevel@tonic-gate DEBUG(7, "port: %d\n", sin.sin_port);
6587c478bd9Sstevel@tonic-gate DEBUG(7, "addr: %08x\n",*((int *) &sin.sin_addr));
6597c478bd9Sstevel@tonic-gate if (connect(ret, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
6607c478bd9Sstevel@tonic-gate (void) alarm(0);
6617c478bd9Sstevel@tonic-gate (void) close(ret);
662ace1a5f1Sdp DEBUG(5, "connect failed: %s\n", strerror(errno));
663ace1a5f1Sdp logent("connect failed", strerror(errno));
6647c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
6657c478bd9Sstevel@tonic-gate return(FAIL);
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate (void) signal(SIGPIPE, SIG_IGN); /* watch out for broken ipc link...*/
6687c478bd9Sstevel@tonic-gate (void) alarm(0);
6697c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "IPC");
6707c478bd9Sstevel@tonic-gate return(ret);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate #endif /* BSD4_2 */
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate /*
6767c478bd9Sstevel@tonic-gate * unetcall(flds, dev) make ethernet connection
6777c478bd9Sstevel@tonic-gate *
6787c478bd9Sstevel@tonic-gate * return codes:
6797c478bd9Sstevel@tonic-gate * >0 - file number - ok
6807c478bd9Sstevel@tonic-gate * FAIL - failed
6817c478bd9Sstevel@tonic-gate */
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate #ifndef UNET
6847c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6857c478bd9Sstevel@tonic-gate GLOBAL int
unetcall(flds,dev)6867c478bd9Sstevel@tonic-gate unetcall(flds, dev)
6877c478bd9Sstevel@tonic-gate char *flds[], *dev[];
6887c478bd9Sstevel@tonic-gate {
6897c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
6907c478bd9Sstevel@tonic-gate return(FAIL);
6917c478bd9Sstevel@tonic-gate }
6927c478bd9Sstevel@tonic-gate #else /* UNET */
6937c478bd9Sstevel@tonic-gate GLOBAL int
unetcall(flds,dev)6947c478bd9Sstevel@tonic-gate unetcall(flds, dev)
6957c478bd9Sstevel@tonic-gate char *flds[], *dev[];
6967c478bd9Sstevel@tonic-gate {
6977c478bd9Sstevel@tonic-gate int ret;
6987c478bd9Sstevel@tonic-gate int port;
6997c478bd9Sstevel@tonic-gate
7007c478bd9Sstevel@tonic-gate port = atoi(dev[D_ARG]);
7017c478bd9Sstevel@tonic-gate DEBUG(4, "unetdial host %s, ", flds[F_PHONE]);
7027c478bd9Sstevel@tonic-gate DEBUG(4, "port %d\n", port);
7037c478bd9Sstevel@tonic-gate (void) alarm(connecttime);
7047c478bd9Sstevel@tonic-gate ret = tcpopen(flds[F_PHONE], port, 0, TO_ACTIVE, "rw");
7057c478bd9Sstevel@tonic-gate (void) alarm(0);
7067c478bd9Sstevel@tonic-gate endhnent();
7077c478bd9Sstevel@tonic-gate if (ret < 0) {
7087c478bd9Sstevel@tonic-gate DEBUG(5, "tcpopen failed: errno %d\n", errno);
7097c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
7107c478bd9Sstevel@tonic-gate return(FAIL);
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "UNET");
7137c478bd9Sstevel@tonic-gate return(ret);
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate #endif /* UNET */
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate #endif /* TCP */
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate #ifdef SYTEK
7207c478bd9Sstevel@tonic-gate
7217c478bd9Sstevel@tonic-gate /*
7227c478bd9Sstevel@tonic-gate * sytcall(flds, dev) make a sytek connection
7237c478bd9Sstevel@tonic-gate *
7247c478bd9Sstevel@tonic-gate * return codes:
7257c478bd9Sstevel@tonic-gate * >0 - file number - ok
7267c478bd9Sstevel@tonic-gate * FAIL - failed
7277c478bd9Sstevel@tonic-gate */
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7307c478bd9Sstevel@tonic-gate GLOBAL int
sytcall(flds,dev)7317c478bd9Sstevel@tonic-gate sytcall(flds, dev)
7327c478bd9Sstevel@tonic-gate char *flds[], *dev[];
7337c478bd9Sstevel@tonic-gate {
7347c478bd9Sstevel@tonic-gate int dcr, dcr2, nullfd, ret;
7357c478bd9Sstevel@tonic-gate char dcname[20], command[BUFSIZ];
7367c478bd9Sstevel@tonic-gate
7377c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
7387c478bd9Sstevel@tonic-gate DEBUG(4, "dc - %s, ", dcname);
7397c478bd9Sstevel@tonic-gate dcr = open(dcname, O_WRONLY|O_NDELAY);
7407c478bd9Sstevel@tonic-gate if (dcr < 0) {
7417c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
7427c478bd9Sstevel@tonic-gate DEBUG(4, "OPEN FAILED %s\n", dcname);
7437c478bd9Sstevel@tonic-gate return(FAIL);
7447c478bd9Sstevel@tonic-gate }
7457c478bd9Sstevel@tonic-gate if ( fd_mklock(dcr) != SUCCESS ) {
7467c478bd9Sstevel@tonic-gate (void)close(dcr);
7477c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname);
7487c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE;
7497c478bd9Sstevel@tonic-gate return(FAIL);
7507c478bd9Sstevel@tonic-gate }
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate sytfixline(dcr, atoi(fdig(dev[D_CLASS])), D_DIRECT);
7537c478bd9Sstevel@tonic-gate (void) sleep(2);
7547c478bd9Sstevel@tonic-gate DEBUG(4, "Calling Sytek unit %s\n", dev[D_ARG]);
7557c478bd9Sstevel@tonic-gate (void) sprintf(command,"\r\rcall %s\r", dev[D_ARG]);
7567c478bd9Sstevel@tonic-gate ret = (*Write)(dcr, command, strlen(command));
7577c478bd9Sstevel@tonic-gate (void) sleep(1);
7587c478bd9Sstevel@tonic-gate DEBUG(4, "COM1 return = %d\n", ret);
7597c478bd9Sstevel@tonic-gate sytfix2line(dcr);
7607c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY));
7617c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
7627c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
7637c478bd9Sstevel@tonic-gate DEBUG(4, "timeout sytek open\n%s", "");
7647c478bd9Sstevel@tonic-gate (void) close(nullfd);
7657c478bd9Sstevel@tonic-gate (void) close(dcr2);
7667c478bd9Sstevel@tonic-gate fd_rmlock(dcr);
7677c478bd9Sstevel@tonic-gate (void) close(dcr);
7687c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
7697c478bd9Sstevel@tonic-gate return(FAIL);
7707c478bd9Sstevel@tonic-gate }
7717c478bd9Sstevel@tonic-gate (void) alarm(10);
7727c478bd9Sstevel@tonic-gate dcr2 = open(dcname,O_RDWR);
7737c478bd9Sstevel@tonic-gate (void) alarm(0);
7747c478bd9Sstevel@tonic-gate fd_rmlock(dcr);
7757c478bd9Sstevel@tonic-gate (void) close(dcr);
7767c478bd9Sstevel@tonic-gate if (dcr2 < 0) {
7777c478bd9Sstevel@tonic-gate DEBUG(4, "OPEN 2 FAILED %s\n", dcname);
7787c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
7797c478bd9Sstevel@tonic-gate (void) close(nullfd); /* kernel might think dc2 is open */
7807c478bd9Sstevel@tonic-gate return(FAIL);
7817c478bd9Sstevel@tonic-gate }
7827c478bd9Sstevel@tonic-gate if ( fd_mklock(dcr2) != SUCCESS ) {
7837c478bd9Sstevel@tonic-gate (void)close(dcr2);
7847c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname);
7857c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE;
7867c478bd9Sstevel@tonic-gate return(FAIL);
7877c478bd9Sstevel@tonic-gate return(dcr2);
7887c478bd9Sstevel@tonic-gate }
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate #endif /* SYTEK */
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate #ifdef DIAL801
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate /*
7957c478bd9Sstevel@tonic-gate * dial801(flds, dev) dial remote machine on 801/801
7967c478bd9Sstevel@tonic-gate * char *flds[], *dev[];
7977c478bd9Sstevel@tonic-gate *
7987c478bd9Sstevel@tonic-gate * return codes:
7997c478bd9Sstevel@tonic-gate * file descriptor - succeeded
8007c478bd9Sstevel@tonic-gate * FAIL - failed
8017c478bd9Sstevel@tonic-gate *
8027c478bd9Sstevel@tonic-gate * unfortunately, open801() is different for usg and non-usg
8037c478bd9Sstevel@tonic-gate */
8047c478bd9Sstevel@tonic-gate
8057c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8067c478bd9Sstevel@tonic-gate GLOBAL int
8077c478bd9Sstevel@tonic-gate dial801(flds, dev)
8087c478bd9Sstevel@tonic-gate char *flds[], *dev[];
8097c478bd9Sstevel@tonic-gate {
8107c478bd9Sstevel@tonic-gate char dcname[20], dnname[20], phone[MAXPH+2];
8117c478bd9Sstevel@tonic-gate int dcf = -1, speed;
8127c478bd9Sstevel@tonic-gate
8137c478bd9Sstevel@tonic-gate (void) sprintf(dnname, "/dev/%s", dev[D_CALLDEV]);
8147c478bd9Sstevel@tonic-gate (void) sprintf(phone, "%s%s", dev[D_ARG] , ACULAST);
8157c478bd9Sstevel@tonic-gate (void) sprintf(dcname, "/dev/%s", dev[D_LINE]);
8167c478bd9Sstevel@tonic-gate CDEBUG(1, "Use Port %s, ", dcname);
8177c478bd9Sstevel@tonic-gate DEBUG(4, "acu - %s, ", dnname);
8187c478bd9Sstevel@tonic-gate VERBOSE("Trying modem - %s, ", dcname); /* for cu */
8197c478bd9Sstevel@tonic-gate VERBOSE("acu - %s, ", dnname); /* for cu */
8207c478bd9Sstevel@tonic-gate if(getuid()==0 || GRPCHK(getgid())) {
8217c478bd9Sstevel@tonic-gate CDEBUG(1, "Phone Number %s\n", phone);
8227c478bd9Sstevel@tonic-gate /* In cu, only give out the phone number to trusted people. */
8237c478bd9Sstevel@tonic-gate VERBOSE("calling %s: ", phone); /* for cu */
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate speed = atoi(fdig(dev[D_CLASS]));
8267c478bd9Sstevel@tonic-gate dcf = open801(dcname, dnname, phone, speed);
8277c478bd9Sstevel@tonic-gate if (dcf >= 0) {
8287c478bd9Sstevel@tonic-gate if ( fd_mklock(dcf) != SUCCESS ) {
8297c478bd9Sstevel@tonic-gate (void) close(dcf);
8307c478bd9Sstevel@tonic-gate DEBUG(5, "fd_mklock line %s failed\n", dev[D_LINE]);
8317c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE;
8327c478bd9Sstevel@tonic-gate return(FAIL);
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate fixline(dcf, speed, D_ACU);
8357c478bd9Sstevel@tonic-gate (void) strcpy(Dc, dev[D_LINE]); /* for later unlock() */
8367c478bd9Sstevel@tonic-gate VERBOSE("SUCCEEDED\n%s", "");
8377c478bd9Sstevel@tonic-gate } else {
8387c478bd9Sstevel@tonic-gate VERBOSE("FAILED\n%s", "");
8397c478bd9Sstevel@tonic-gate }
8407c478bd9Sstevel@tonic-gate return(dcf);
8417c478bd9Sstevel@tonic-gate }
8427c478bd9Sstevel@tonic-gate
8437c478bd9Sstevel@tonic-gate
8447c478bd9Sstevel@tonic-gate #ifndef ATTSV
8457c478bd9Sstevel@tonic-gate /*ARGSUSED*/
8467c478bd9Sstevel@tonic-gate GLOBAL int
8477c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed)
8487c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone;
8497c478bd9Sstevel@tonic-gate {
8507c478bd9Sstevel@tonic-gate int nw, lt, dcf = -1, nullfd, dnf = -1;
8517c478bd9Sstevel@tonic-gate pid_t w_ret, pid = -1;
8527c478bd9Sstevel@tonic-gate unsigned timelim;
8537c478bd9Sstevel@tonic-gate
8547c478bd9Sstevel@tonic-gate if ((dnf = open(dnname, O_WRONLY)) < 0) {
8557c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dnname);
8567c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE;
8577c478bd9Sstevel@tonic-gate return(FAIL);
8587c478bd9Sstevel@tonic-gate }
8597c478bd9Sstevel@tonic-gate DEBUG(5, "%s is open\n", dnname);
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/dev/null", O_RDONLY));/* partial open hack */
8627c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
8637c478bd9Sstevel@tonic-gate DEBUG(4, "timeout modem open\n%s", "");
8647c478bd9Sstevel@tonic-gate (void) close(nullfd);
8657c478bd9Sstevel@tonic-gate (void) close(dcf);
8667c478bd9Sstevel@tonic-gate (void) close(dnf);
8677c478bd9Sstevel@tonic-gate logent("801 open", "TIMEOUT");
8687c478bd9Sstevel@tonic-gate if (pid > 0) {
8697c478bd9Sstevel@tonic-gate kill(pid, 9);
8707c478bd9Sstevel@tonic-gate wait((int *) 0);
8717c478bd9Sstevel@tonic-gate }
8727c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
8737c478bd9Sstevel@tonic-gate return(FAIL);
8747c478bd9Sstevel@tonic-gate }
8757c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
8767c478bd9Sstevel@tonic-gate timelim = 5 * strlen(phone);
8777c478bd9Sstevel@tonic-gate (void) alarm(timelim < connecttime ? connecttime : timelim);
8787c478bd9Sstevel@tonic-gate if ((pid = fork()) == 0) {
8797c478bd9Sstevel@tonic-gate sleep(2);
8807c478bd9Sstevel@tonic-gate nw = (*Write)(dnf, phone, lt = strlen(phone));
8817c478bd9Sstevel@tonic-gate if (nw != lt) {
8827c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write error %d\n", errno);
8837c478bd9Sstevel@tonic-gate logent("ACU write", "FAILED");
8847c478bd9Sstevel@tonic-gate exit(1);
8857c478bd9Sstevel@tonic-gate }
8867c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write ok\n%s", "");
8877c478bd9Sstevel@tonic-gate exit(0);
8887c478bd9Sstevel@tonic-gate }
8897c478bd9Sstevel@tonic-gate /* open line - will return on carrier */
8907c478bd9Sstevel@tonic-gate dcf = open(dcname, O_RDWR);
8917c478bd9Sstevel@tonic-gate
8927c478bd9Sstevel@tonic-gate DEBUG(4, "dcf is %d\n", dcf);
8937c478bd9Sstevel@tonic-gate if (dcf < 0) { /* handle like a timeout */
8947c478bd9Sstevel@tonic-gate (void) alarm(0);
8957c478bd9Sstevel@tonic-gate longjmp(Sjbuf, 1);
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate
8987c478bd9Sstevel@tonic-gate /* modem is open */
8997c478bd9Sstevel@tonic-gate while ((w_ret = wait(<)) != pid)
9007c478bd9Sstevel@tonic-gate if (w_ret == -1 && errno != EINTR) {
9017c478bd9Sstevel@tonic-gate DEBUG(4, "Wait failed errno=%d\n", errno);
9027c478bd9Sstevel@tonic-gate (void) close(dcf);
9037c478bd9Sstevel@tonic-gate (void) close(dnf);
9047c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
9057c478bd9Sstevel@tonic-gate return(FAIL);
9067c478bd9Sstevel@tonic-gate }
9077c478bd9Sstevel@tonic-gate (void) alarm(0);
9087c478bd9Sstevel@tonic-gate
9097c478bd9Sstevel@tonic-gate (void) close(dnf); /* no reason to keep the 801 open */
9107c478bd9Sstevel@tonic-gate if (lt != 0) {
9117c478bd9Sstevel@tonic-gate DEBUG(4, "Fork Stat %o\n", lt);
9127c478bd9Sstevel@tonic-gate (void) close(dcf);
9137c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
9147c478bd9Sstevel@tonic-gate return(FAIL);
9157c478bd9Sstevel@tonic-gate }
9167c478bd9Sstevel@tonic-gate return(dcf);
9177c478bd9Sstevel@tonic-gate }
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate #else /* ATTSV */
9207c478bd9Sstevel@tonic-gate
9217c478bd9Sstevel@tonic-gate GLOBAL int
9227c478bd9Sstevel@tonic-gate open801(dcname, dnname, phone, speed)
9237c478bd9Sstevel@tonic-gate char *dcname, *dnname, *phone;
9247c478bd9Sstevel@tonic-gate {
9257c478bd9Sstevel@tonic-gate int nw, lt, dcf = -1, nullfd, dnf = -1, ret;
9267c478bd9Sstevel@tonic-gate unsigned timelim;
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); /* partial open hack */
9297c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
9307c478bd9Sstevel@tonic-gate DEBUG(4, "DN write %s\n", "timeout");
9317c478bd9Sstevel@tonic-gate (void) close(dnf);
9327c478bd9Sstevel@tonic-gate (void) close(dcf);
9337c478bd9Sstevel@tonic-gate (void) close(nullfd);
9347c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
9357c478bd9Sstevel@tonic-gate return(FAIL);
9367c478bd9Sstevel@tonic-gate }
9377c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
9387c478bd9Sstevel@tonic-gate timelim = 5 * strlen(phone);
9397c478bd9Sstevel@tonic-gate (void) alarm(timelim < connecttime ? connecttime : timelim);
9407c478bd9Sstevel@tonic-gate
9417c478bd9Sstevel@tonic-gate if ((dnf = open(dnname, O_WRONLY)) < 0 ) {
9427c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dnname);
9437c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE;
9447c478bd9Sstevel@tonic-gate return(FAIL);
9457c478bd9Sstevel@tonic-gate }
9467c478bd9Sstevel@tonic-gate DEBUG(5, "%s is open\n", dnname);
9477c478bd9Sstevel@tonic-gate if ( fd_mklock(dnf) != SUCCESS ) {
9487c478bd9Sstevel@tonic-gate (void)close(dnf);
9497c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dnname);
9507c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE;
9517c478bd9Sstevel@tonic-gate }
9527c478bd9Sstevel@tonic-gate if ( (dcf = open(dcname, O_RDWR | O_NDELAY)) < 0 ) {
9537c478bd9Sstevel@tonic-gate DEBUG(5, "can't open %s\n", dcname);
9547c478bd9Sstevel@tonic-gate Uerror = SS_CANT_ACCESS_DEVICE;
9557c478bd9Sstevel@tonic-gate return(FAIL);
9567c478bd9Sstevel@tonic-gate }
9577c478bd9Sstevel@tonic-gate if ( fd_mklock(dcf) != SUCCESS ) {
9587c478bd9Sstevel@tonic-gate (void)close(dcf);
9597c478bd9Sstevel@tonic-gate DEBUG(1, "failed to lock device %s\n", dcname);
9607c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE;
9617c478bd9Sstevel@tonic-gate return(FAIL);
9627c478bd9Sstevel@tonic-gate }
9637c478bd9Sstevel@tonic-gate
9647c478bd9Sstevel@tonic-gate DEBUG(4, "dcf is %d\n", dcf);
9657c478bd9Sstevel@tonic-gate fixline(dcf, speed, D_ACU);
9667c478bd9Sstevel@tonic-gate nw = (*Write)(dnf, phone, lt = strlen(phone));
9677c478bd9Sstevel@tonic-gate if (nw != lt) {
9687c478bd9Sstevel@tonic-gate (void) alarm(0);
9697c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write error %d\n", errno);
9707c478bd9Sstevel@tonic-gate (void) close(dnf);
9717c478bd9Sstevel@tonic-gate (void) close(dcf);
9727c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
9737c478bd9Sstevel@tonic-gate return(FAIL);
9747c478bd9Sstevel@tonic-gate } else
9757c478bd9Sstevel@tonic-gate DEBUG(4, "ACU write ok\n%s", "");
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate (void) close(dnf);
9787c478bd9Sstevel@tonic-gate (void) close(nullfd = open("/", O_RDONLY)); /* partial open hack */
9797c478bd9Sstevel@tonic-gate ret = open(dcname, O_RDWR); /* wait for carrier */
9807c478bd9Sstevel@tonic-gate (void) alarm(0);
9817c478bd9Sstevel@tonic-gate (void) close(ret); /* close 2nd modem open() */
9827c478bd9Sstevel@tonic-gate if (ret < 0) { /* open() interrupted by alarm */
9837c478bd9Sstevel@tonic-gate DEBUG(4, "Line open %s\n", "failed");
9847c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
9857c478bd9Sstevel@tonic-gate (void) close(nullfd); /* close partially opened modem */
9867c478bd9Sstevel@tonic-gate return(FAIL);
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate (void) fcntl(dcf,F_SETFL, fcntl(dcf, F_GETFL, 0) & ~O_NDELAY);
9897c478bd9Sstevel@tonic-gate return(dcf);
9907c478bd9Sstevel@tonic-gate }
9917c478bd9Sstevel@tonic-gate #endif /* ATTSV */
9927c478bd9Sstevel@tonic-gate
9937c478bd9Sstevel@tonic-gate #endif /* DIAL801 */
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate #ifdef V8
9967c478bd9Sstevel@tonic-gate GLOBAL int
9977c478bd9Sstevel@tonic-gate Dialout(flds)
9987c478bd9Sstevel@tonic-gate char *flds[];
9997c478bd9Sstevel@tonic-gate {
10007c478bd9Sstevel@tonic-gate int fd;
10017c478bd9Sstevel@tonic-gate char phone[MAXPH+2];
10027c478bd9Sstevel@tonic-gate
10037c478bd9Sstevel@tonic-gate exphone(flds[F_PHONE], phone);
10047c478bd9Sstevel@tonic-gate
10057c478bd9Sstevel@tonic-gate DEBUG(4, "call dialout(%s", phone);
10067c478bd9Sstevel@tonic-gate DEBUG(4, ", %s)\n", dev[D_CLASS]);
10077c478bd9Sstevel@tonic-gate fd = dialout(phone, dev[D_CLASS]);
10087c478bd9Sstevel@tonic-gate if (fd == -1)
10097c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
10107c478bd9Sstevel@tonic-gate if (fd == -3)
10117c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
10127c478bd9Sstevel@tonic-gate if (fd == -9)
10137c478bd9Sstevel@tonic-gate Uerror = SS_DEVICE_FAILED;
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate (void) strcpy(Dc, "Dialout");
10167c478bd9Sstevel@tonic-gate
10177c478bd9Sstevel@tonic-gate return(fd);
10187c478bd9Sstevel@tonic-gate }
10197c478bd9Sstevel@tonic-gate #endif /* V8 */
10207c478bd9Sstevel@tonic-gate
10217c478bd9Sstevel@tonic-gate #ifdef TLI
10227c478bd9Sstevel@tonic-gate /*
10237c478bd9Sstevel@tonic-gate *
10247c478bd9Sstevel@tonic-gate * AT&T Transport Layer Interface
10257c478bd9Sstevel@tonic-gate *
10267c478bd9Sstevel@tonic-gate * expected in Devices
10277c478bd9Sstevel@tonic-gate * TLI line1 - - TLI
10287c478bd9Sstevel@tonic-gate * or
10297c478bd9Sstevel@tonic-gate * TLIS line1 - - TLIS
10307c478bd9Sstevel@tonic-gate *
10317c478bd9Sstevel@tonic-gate */
10327c478bd9Sstevel@tonic-gate
10337c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
10347c478bd9Sstevel@tonic-gate
10357c478bd9Sstevel@tonic-gate EXTERN void tfaillog();
10367c478bd9Sstevel@tonic-gate
10377c478bd9Sstevel@tonic-gate char *t_alloc();
10387c478bd9Sstevel@tonic-gate int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis();
10397c478bd9Sstevel@tonic-gate
10407c478bd9Sstevel@tonic-gate #define CONNECT_ATTEMPTS 3
10417c478bd9Sstevel@tonic-gate #define TFREE(p, type) if ((p)) t_free((char *)(p), (type))
10427c478bd9Sstevel@tonic-gate
10437c478bd9Sstevel@tonic-gate /*
10447c478bd9Sstevel@tonic-gate * returns fd to remote uucp daemon
10457c478bd9Sstevel@tonic-gate */
10467c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10477c478bd9Sstevel@tonic-gate GLOBAL int
10487c478bd9Sstevel@tonic-gate tlicall(flds, dev)
10497c478bd9Sstevel@tonic-gate char *flds[];
10507c478bd9Sstevel@tonic-gate char *dev[];
10517c478bd9Sstevel@tonic-gate {
10527c478bd9Sstevel@tonic-gate char addrbuf[ BUFSIZ ];
10537c478bd9Sstevel@tonic-gate char devname[MAXNAMESIZE];
10547c478bd9Sstevel@tonic-gate int fd;
1055462be471Sceastha int i, j;
10567c478bd9Sstevel@tonic-gate struct t_bind *bind_ret = 0;
10577c478bd9Sstevel@tonic-gate struct t_info tinfo;
10587c478bd9Sstevel@tonic-gate struct t_call *sndcall = 0, *rcvcall = 0;
10597c478bd9Sstevel@tonic-gate extern int t_errno;
10607c478bd9Sstevel@tonic-gate
10617c478bd9Sstevel@tonic-gate EXTERN struct netbuf *stoa();
10627c478bd9Sstevel@tonic-gate
10637c478bd9Sstevel@tonic-gate if ( dev[D_LINE][0] != '/' ) {
10647c478bd9Sstevel@tonic-gate /* dev holds device name relative to /dev */
10657c478bd9Sstevel@tonic-gate sprintf(devname, "/dev/%s", dev[D_LINE]);
10667c478bd9Sstevel@tonic-gate } else {
10677c478bd9Sstevel@tonic-gate /* dev holds full path name of device */
10687c478bd9Sstevel@tonic-gate strcpy(devname, dev[D_LINE]);
10697c478bd9Sstevel@tonic-gate }
10707c478bd9Sstevel@tonic-gate /* gimme local transport endpoint */
10717c478bd9Sstevel@tonic-gate errno = t_errno = 0;
10727c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
10737c478bd9Sstevel@tonic-gate DEBUG(1, "t_open timeout\n%s", "");
10747c478bd9Sstevel@tonic-gate logent("t_open", "TIMEOUT");
10757c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
10767c478bd9Sstevel@tonic-gate return(FAIL);
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
10797c478bd9Sstevel@tonic-gate (void) alarm(5);
10807c478bd9Sstevel@tonic-gate fd = t_open(devname, O_RDWR, &tinfo);
10817c478bd9Sstevel@tonic-gate (void) alarm(0);
10827c478bd9Sstevel@tonic-gate if (fd < 0) {
10837c478bd9Sstevel@tonic-gate tfaillog(fd, "t_open" );
10847c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
10857c478bd9Sstevel@tonic-gate return(FAIL);
10867c478bd9Sstevel@tonic-gate }
10877c478bd9Sstevel@tonic-gate if ( fd_mklock(fd) != SUCCESS ) {
10887c478bd9Sstevel@tonic-gate (void)t_close(fd);
10897c478bd9Sstevel@tonic-gate DEBUG(1, "tlicall: failed to lock device %s\n", devname);
10907c478bd9Sstevel@tonic-gate Uerror = SS_LOCKED_DEVICE;
10917c478bd9Sstevel@tonic-gate return(FAIL);
10927c478bd9Sstevel@tonic-gate }
10937c478bd9Sstevel@tonic-gate
10947c478bd9Sstevel@tonic-gate /* allocate tli structures */
10957c478bd9Sstevel@tonic-gate errno = t_errno = 0;
10967c478bd9Sstevel@tonic-gate if ( (bind_ret = (struct t_bind *)t_alloc(fd, T_BIND, T_ALL)) ==
10977c478bd9Sstevel@tonic-gate (struct t_bind *)NULL
10987c478bd9Sstevel@tonic-gate || (sndcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) ==
10997c478bd9Sstevel@tonic-gate (struct t_call *)NULL
11007c478bd9Sstevel@tonic-gate || (rcvcall = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) ==
11017c478bd9Sstevel@tonic-gate (struct t_call *)NULL ) {
11027c478bd9Sstevel@tonic-gate tfaillog(fd, "t_alloc" );
11037c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11047c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL);
11057c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
11067c478bd9Sstevel@tonic-gate return(FAIL);
11077c478bd9Sstevel@tonic-gate }
11087c478bd9Sstevel@tonic-gate
11097c478bd9Sstevel@tonic-gate /* bind */
11107c478bd9Sstevel@tonic-gate errno = t_errno = 0;
11117c478bd9Sstevel@tonic-gate if (t_bind(fd, (struct t_bind *) 0, bind_ret ) < 0) {
11127c478bd9Sstevel@tonic-gate tfaillog(fd, "t_bind" );
11137c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11147c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL);
11157c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
11167c478bd9Sstevel@tonic-gate fd_rmlock(fd);
11177c478bd9Sstevel@tonic-gate (void) t_close(fd);
11187c478bd9Sstevel@tonic-gate return(FAIL);
11197c478bd9Sstevel@tonic-gate }
11207c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: bound to %s\n", bind_ret->addr.buf);
11217c478bd9Sstevel@tonic-gate
11227c478bd9Sstevel@tonic-gate /*
11237c478bd9Sstevel@tonic-gate * Prepare to connect.
11247c478bd9Sstevel@tonic-gate *
11257c478bd9Sstevel@tonic-gate * If address begins with "\x", "\X", "\o", or "\O",
11267c478bd9Sstevel@tonic-gate * assume is hexadecimal or octal address and use stoa()
11277c478bd9Sstevel@tonic-gate * to convert it.
11287c478bd9Sstevel@tonic-gate *
11297c478bd9Sstevel@tonic-gate * Else is usual uucico address -- only \N's left to process.
11307c478bd9Sstevel@tonic-gate * Walk thru connection address, changing \N's to NULLCHARs.
11317c478bd9Sstevel@tonic-gate * Note: If a NULLCHAR must be part of the connection address,
11327c478bd9Sstevel@tonic-gate * it must be overtly included in the address. One recommended
11337c478bd9Sstevel@tonic-gate * way is to do it in the Devices file, thusly:
11347c478bd9Sstevel@tonic-gate * Netname /dev/netport - - TLI \D\000
11357c478bd9Sstevel@tonic-gate * bsfix() turns \000 into \N and then the loop below makes it a
11367c478bd9Sstevel@tonic-gate * real, included-in-the-length null-byte.
11377c478bd9Sstevel@tonic-gate *
11387c478bd9Sstevel@tonic-gate * The DEBUG must print the strecpy'd address (so that
11397c478bd9Sstevel@tonic-gate * non-printables will have been replaced with C escapes).
11407c478bd9Sstevel@tonic-gate */
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate DEBUG(5, "t_connect to addr \"%s\"\n",
11437c478bd9Sstevel@tonic-gate strecpy( addrbuf, dev[D_ARG], "\\" ) );
11447c478bd9Sstevel@tonic-gate
11457c478bd9Sstevel@tonic-gate if ( dev[D_ARG][0] == '\\' &&
11467c478bd9Sstevel@tonic-gate ( dev[D_ARG][1] == 'x' || dev[D_ARG][1] == 'X'
11477c478bd9Sstevel@tonic-gate || dev[D_ARG][1] == 'o' || dev[D_ARG][1] == 'O' ) ) {
11487c478bd9Sstevel@tonic-gate if ( stoa(dev[D_ARG], &(sndcall->addr)) == (struct netbuf *)NULL ) {
11497c478bd9Sstevel@tonic-gate DEBUG(5, "tlicall: stoa failed\n%s", "");
11507c478bd9Sstevel@tonic-gate logent("tlicall", "string-to-address failed");
11517c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11527c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL);
11537c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
11547c478bd9Sstevel@tonic-gate fd_rmlock(fd);
11557c478bd9Sstevel@tonic-gate (void) t_close(fd);
11567c478bd9Sstevel@tonic-gate return(FAIL);
11577c478bd9Sstevel@tonic-gate }
11587c478bd9Sstevel@tonic-gate } else {
11597c478bd9Sstevel@tonic-gate for( i = j = 0; i < BUFSIZ && dev[D_ARG][i] != NULLCHAR;
11607c478bd9Sstevel@tonic-gate ++i, ++j ) {
11617c478bd9Sstevel@tonic-gate if( dev[D_ARG][i] == '\\' && dev[D_ARG][i+1] == 'N' ) {
11627c478bd9Sstevel@tonic-gate addrbuf[j] = NULLCHAR;
11637c478bd9Sstevel@tonic-gate ++i;
11647c478bd9Sstevel@tonic-gate }
11657c478bd9Sstevel@tonic-gate else {
11667c478bd9Sstevel@tonic-gate addrbuf[j] = dev[D_ARG][i];
11677c478bd9Sstevel@tonic-gate }
11687c478bd9Sstevel@tonic-gate }
11697c478bd9Sstevel@tonic-gate sndcall->addr.buf = addrbuf;
11707c478bd9Sstevel@tonic-gate sndcall->addr.len = j;
11717c478bd9Sstevel@tonic-gate }
11727c478bd9Sstevel@tonic-gate
11737c478bd9Sstevel@tonic-gate if (setjmp(Sjbuf)) {
11747c478bd9Sstevel@tonic-gate DEBUG(4, "timeout tlicall\n%s", "");
11757c478bd9Sstevel@tonic-gate logent("tlicall", "TIMEOUT");
11767c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11777c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL);
11787c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE;
11797c478bd9Sstevel@tonic-gate fd_rmlock(fd);
11807c478bd9Sstevel@tonic-gate (void) t_close(fd);
11817c478bd9Sstevel@tonic-gate return(FAIL);
11827c478bd9Sstevel@tonic-gate }
11837c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr);
11847c478bd9Sstevel@tonic-gate (void) alarm(connecttime);
11857c478bd9Sstevel@tonic-gate
11867c478bd9Sstevel@tonic-gate /* connect to the service -- some listeners can't handle */
11877c478bd9Sstevel@tonic-gate /* multiple connect requests, so try it a few times */
11887c478bd9Sstevel@tonic-gate errno = t_errno = 0;
11897c478bd9Sstevel@tonic-gate for ( i = 0; i < CONNECT_ATTEMPTS; ++i ) {
11907c478bd9Sstevel@tonic-gate if (t_connect(fd, sndcall, rcvcall) == 0)
11917c478bd9Sstevel@tonic-gate break;
11927c478bd9Sstevel@tonic-gate if ( (t_errno == TLOOK) && (t_look(fd) == T_DISCONNECT)) {
11937c478bd9Sstevel@tonic-gate t_rcvdis(fd,NULL);
11947c478bd9Sstevel@tonic-gate (void) alarm(0);
11957c478bd9Sstevel@tonic-gate } else {
11967c478bd9Sstevel@tonic-gate (void) alarm(0);
11977c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect");
11987c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
11997c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL);
12007c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
12017c478bd9Sstevel@tonic-gate fd_rmlock(fd);
12027c478bd9Sstevel@tonic-gate (void) t_close(fd);
12037c478bd9Sstevel@tonic-gate return(FAIL);
12047c478bd9Sstevel@tonic-gate }
12057c478bd9Sstevel@tonic-gate }
12067c478bd9Sstevel@tonic-gate (void) alarm(0);
12077c478bd9Sstevel@tonic-gate TFREE(bind_ret, T_BIND);TFREE(sndcall, T_CALL);
12087c478bd9Sstevel@tonic-gate TFREE(rcvcall, T_CALL);
12097c478bd9Sstevel@tonic-gate if ( i == CONNECT_ATTEMPTS ) {
12107c478bd9Sstevel@tonic-gate tfaillog(fd, "t_connect");
12117c478bd9Sstevel@tonic-gate Uerror = SS_DIAL_FAILED;
12127c478bd9Sstevel@tonic-gate fd_rmlock(fd);
12137c478bd9Sstevel@tonic-gate (void) t_close(fd);
12147c478bd9Sstevel@tonic-gate return(FAIL);
12157c478bd9Sstevel@tonic-gate }
12167c478bd9Sstevel@tonic-gate errno = t_errno = 0;
12177c478bd9Sstevel@tonic-gate (void) strcpy(Dc, dev[D_CALLER]);
12187c478bd9Sstevel@tonic-gate return(fd);
12197c478bd9Sstevel@tonic-gate }
12207c478bd9Sstevel@tonic-gate #endif /* TLI */
1221