xref: /onnv-gate/usr/src/cmd/bnu/interface.c (revision 634:263e46dc023d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*634Sdp  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate /*	interface( label )
330Sstevel@tonic-gate 	provide alternate definitions for the I/O functions through global
340Sstevel@tonic-gate 	interfaces.
350Sstevel@tonic-gate */
360Sstevel@tonic-gate #include	"uucp.h"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef TLI
390Sstevel@tonic-gate #include	<tiuser.h>
400Sstevel@tonic-gate char *t_alloc();
410Sstevel@tonic-gate int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis();
420Sstevel@tonic-gate int t_getinfo(), t_getstate(), t_look(), t_rcv(), t_snd(), t_sync(), t_unbind();
430Sstevel@tonic-gate #endif /*  TLI  */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #ifdef DATAKIT
460Sstevel@tonic-gate #include	"dk.h"
470Sstevel@tonic-gate 
480Sstevel@tonic-gate static int	dksetup();
490Sstevel@tonic-gate static int	dkteardown();
500Sstevel@tonic-gate #endif	/* DATAKIT */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate EXTERN void	sethup();
530Sstevel@tonic-gate EXTERN int	restline();
540Sstevel@tonic-gate #if defined(__STDC__)
550Sstevel@tonic-gate extern int	ioctl(int, int, ...);
560Sstevel@tonic-gate #else
570Sstevel@tonic-gate extern int	ioctl();
580Sstevel@tonic-gate #endif
590Sstevel@tonic-gate static int	usetup(), uteardown();
600Sstevel@tonic-gate 
610Sstevel@tonic-gate GLOBAL ssize_t	(*Read)() = read,
620Sstevel@tonic-gate 	(*Write)() = write;
630Sstevel@tonic-gate #if defined(__STDC__)
640Sstevel@tonic-gate GLOBAL int	(*Ioctl)(int,int,...) = ioctl,
650Sstevel@tonic-gate #else
660Sstevel@tonic-gate GLOBAL int	(*Ioctl)() = ioctl,
670Sstevel@tonic-gate #endif
680Sstevel@tonic-gate 	(*Setup)() = usetup,
690Sstevel@tonic-gate 	(*Teardown)() = uteardown;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate #ifdef TLI
720Sstevel@tonic-gate EXTERN void tfaillog(), show_tlook();
730Sstevel@tonic-gate static ssize_t	tread(), twrite();	/* TLI i/o */
740Sstevel@tonic-gate #ifdef __STDC__
750Sstevel@tonic-gate static int	tioctl(int, int, ...),
760Sstevel@tonic-gate #else
770Sstevel@tonic-gate static int	tioctl(),		/* TLI i/o control */
780Sstevel@tonic-gate #endif
790Sstevel@tonic-gate 		tsetup(),		/* TLI setup without streams module */
800Sstevel@tonic-gate 		tssetup(),		/* TLI setup with streams module */
810Sstevel@tonic-gate 		tteardown();		/* TLI teardown, works with either setup
820Sstevel@tonic-gate 					*/
830Sstevel@tonic-gate #endif /*  TLI  */
840Sstevel@tonic-gate /*	The IN_label in Interface[] imply different caller routines:
850Sstevel@tonic-gate 	e.g. tlicall().
860Sstevel@tonic-gate 	If so, the names here and the names in callers.c must match.
870Sstevel@tonic-gate */
880Sstevel@tonic-gate 
890Sstevel@tonic-gate static
900Sstevel@tonic-gate   struct Interface {
910Sstevel@tonic-gate 	char	*IN_label;		/* interface name */
920Sstevel@tonic-gate 	ssize_t	(*IN_read)();		/* read function */
930Sstevel@tonic-gate 	ssize_t	(*IN_write)();		/* write function */
940Sstevel@tonic-gate #ifdef __STDC__
950Sstevel@tonic-gate 	int	(*IN_ioctl)(int,int,...);
960Sstevel@tonic-gate #else
970Sstevel@tonic-gate 	int	(*IN_ioctl)();		/* ioctl function */
980Sstevel@tonic-gate #endif
990Sstevel@tonic-gate 	int	(*IN_setup)();		/* setup function, called before first
1000Sstevel@tonic-gate 					i/o operation */
1010Sstevel@tonic-gate 	int	(*IN_teardown)();	/* teardown function, called after last
1020Sstevel@tonic-gate 					i/o operation */
1030Sstevel@tonic-gate } Interface[] = {
1040Sstevel@tonic-gate 			/* vanilla UNIX */
1050Sstevel@tonic-gate 		{ "UNIX", read, write, ioctl, usetup, uteardown },
1060Sstevel@tonic-gate #ifdef TCP
1070Sstevel@tonic-gate 			/* TCP over sockets or UNET */
1080Sstevel@tonic-gate 		{ "TCP", read, write, ioctl, usetup, uteardown },
1090Sstevel@tonic-gate #endif /* TCP */
1100Sstevel@tonic-gate #ifdef SYTEK
1110Sstevel@tonic-gate 			/* Sytek network */
1120Sstevel@tonic-gate 		{ "Sytek", read, write, ioctl, usetup, uteardown },
1130Sstevel@tonic-gate #endif /* Sytek network */
1140Sstevel@tonic-gate #ifdef DIAL801
1150Sstevel@tonic-gate 			/* 801 auto dialers */
1160Sstevel@tonic-gate 		{ "801", read, write, ioctl, usetup, uteardown },
1170Sstevel@tonic-gate #endif /* DIAL801 */
1180Sstevel@tonic-gate #ifdef DIAL801
1190Sstevel@tonic-gate 			/* 212 auto dialers */
1200Sstevel@tonic-gate 		{ "212", read, write, ioctl, usetup, uteardown },
1210Sstevel@tonic-gate #endif /* DIAL801 */
1220Sstevel@tonic-gate #ifdef TLI
1230Sstevel@tonic-gate 			/* AT&T Transport Interface Library WITHOUT streams */
1240Sstevel@tonic-gate 		{ "TLI", tread, twrite, tioctl, tsetup, tteardown },
1250Sstevel@tonic-gate #ifdef TLIS
1260Sstevel@tonic-gate 			/* AT&T Transport Interface Library WITH streams */
1270Sstevel@tonic-gate 		{ "TLIS", read, write, tioctl, tssetup, uteardown },
1280Sstevel@tonic-gate #endif /*  TLIS  */
1290Sstevel@tonic-gate #endif /*  TLI  */
1300Sstevel@tonic-gate #ifdef DATAKIT
1310Sstevel@tonic-gate 		{ "DK", read, write, ioctl, dksetup, dkteardown },
1320Sstevel@tonic-gate #endif /* DATAKIT */
1330Sstevel@tonic-gate #ifdef UNET
1340Sstevel@tonic-gate 		{ "Unetserver", read, write, ioctl, usetup, uteardown },
1350Sstevel@tonic-gate #endif
1360Sstevel@tonic-gate 		{ 0, 0, 0, 0, 0, 0 }
1370Sstevel@tonic-gate 	};
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate GLOBAL int
interface(label)1410Sstevel@tonic-gate interface(label)
1420Sstevel@tonic-gate char	*label;
1430Sstevel@tonic-gate {
1440Sstevel@tonic-gate 	register int	i;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	for ( i = 0;  Interface[i].IN_label;  ++i ) {
1470Sstevel@tonic-gate 		if( !strcmp( Interface[i].IN_label, label ) ) {
1480Sstevel@tonic-gate 			Read = Interface[i].IN_read;
1490Sstevel@tonic-gate 			Write = Interface[i].IN_write;
1500Sstevel@tonic-gate 			Ioctl = Interface[i].IN_ioctl;
1510Sstevel@tonic-gate 			Setup = Interface[i].IN_setup;
1520Sstevel@tonic-gate 			Teardown = Interface[i].IN_teardown;
1530Sstevel@tonic-gate 			DEBUG(5, "set interface %s\n", label);
1540Sstevel@tonic-gate 			return( 0 );
1550Sstevel@tonic-gate 		}
1560Sstevel@tonic-gate 	}
1570Sstevel@tonic-gate 	return( FAIL );
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate /*
1610Sstevel@tonic-gate  *	usetup - vanilla unix setup routine
1620Sstevel@tonic-gate  */
1630Sstevel@tonic-gate static int
usetup(role,fdreadp,fdwritep)1640Sstevel@tonic-gate usetup( role, fdreadp, fdwritep )
1650Sstevel@tonic-gate int	*fdreadp, *fdwritep;
1660Sstevel@tonic-gate {
1670Sstevel@tonic-gate 	if ( role == SLAVE )
1680Sstevel@tonic-gate 	{
1690Sstevel@tonic-gate 		*fdreadp = 0;
1700Sstevel@tonic-gate 		*fdwritep = 1;
1710Sstevel@tonic-gate 		/* 2 has been re-opened to RMTDEBUG in main() */
1720Sstevel@tonic-gate 	}
1730Sstevel@tonic-gate 	return(SUCCESS);
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate /*
1770Sstevel@tonic-gate  *	uteardown - vanilla unix teardown routine
1780Sstevel@tonic-gate  */
1790Sstevel@tonic-gate static int
uteardown(role,fdread,fdwrite)1800Sstevel@tonic-gate uteardown( role, fdread, fdwrite )
1810Sstevel@tonic-gate {
1820Sstevel@tonic-gate 	int ret;
1830Sstevel@tonic-gate 	char *ttyn;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	if (role == SLAVE) {
1860Sstevel@tonic-gate 		ret = restline();
1870Sstevel@tonic-gate 		DEBUG(4, "ret restline - %d\n", ret);
1880Sstevel@tonic-gate 		if (fdread != -1)
1890Sstevel@tonic-gate 			sethup(fdread);
1900Sstevel@tonic-gate 	}
1910Sstevel@tonic-gate 	if (fdread != -1) {
1920Sstevel@tonic-gate 		ttyn = ttyname(fdread);
1930Sstevel@tonic-gate 		if (ttyn != NULL && Dev_mode != 0)
1940Sstevel@tonic-gate 			chmod(ttyn, Dev_mode);	/* can fail, but who cares? */
1950Sstevel@tonic-gate 		(void) close(fdread);
1960Sstevel@tonic-gate 		(void) close(fdwrite);
1970Sstevel@tonic-gate 	}
1980Sstevel@tonic-gate 	return(SUCCESS);
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate #ifdef DATAKIT
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate  *	dksetup - DATAKIT setup routine
2040Sstevel@tonic-gate  *
2050Sstevel@tonic-gate  * Put line in block mode.
2060Sstevel@tonic-gate  */
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate static int
dksetup(role,fdreadp,fdwritep)2090Sstevel@tonic-gate dksetup (role, fdreadp, fdwritep)
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate int	role;
2120Sstevel@tonic-gate int *	fdreadp;
2130Sstevel@tonic-gate int *	fdwritep;
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate {
2160Sstevel@tonic-gate 	static short dkrmode[3] = { DKR_BLOCK | DKR_TIME, 0, 0 };
2170Sstevel@tonic-gate 	int	ret;
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 	(void) usetup(role, fdreadp, fdwritep);
2200Sstevel@tonic-gate 	if((ret = (*Ioctl)(*fdreadp, DIOCRMODE, dkrmode)) < 0) {
2210Sstevel@tonic-gate 		DEBUG(4, "dksetup: failed to set block mode. ret=%d,\n", ret);
2220Sstevel@tonic-gate 		DEBUG(4, "read fd=%d, ", *fdreadp);
2230Sstevel@tonic-gate 		DEBUG(4, "errno=%d\n", errno);
2240Sstevel@tonic-gate 		return(FAIL);
2250Sstevel@tonic-gate 	}
2260Sstevel@tonic-gate 	return(SUCCESS);
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate /*
2300Sstevel@tonic-gate  *	dkteardown  -  DATAKIT teardown routine
2310Sstevel@tonic-gate  */
2320Sstevel@tonic-gate static int
dkteardown(role,fdread,fdwrite)2330Sstevel@tonic-gate dkteardown( role, fdread, fdwrite )
2340Sstevel@tonic-gate int	role, fdread, fdwrite;
2350Sstevel@tonic-gate {
2360Sstevel@tonic-gate 	char	*ttyn;
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate 	if ( role == MASTER ) {
2390Sstevel@tonic-gate 		ttyn = ttyname(fdread);
2400Sstevel@tonic-gate 		if ( ttyn != NULL && Dev_mode != 0 )
2410Sstevel@tonic-gate 			chmod(ttyn, Dev_mode);	/* can fail, but who cares? */
2420Sstevel@tonic-gate 	}
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	/*	must flush fd's for datakit	*/
2450Sstevel@tonic-gate 	/*	else close can hang		*/
2460Sstevel@tonic-gate 	if ( ioctl(fdread, DIOCFLUSH, NULL) != 0 )
2470Sstevel@tonic-gate 		DEBUG(4, "dkteardown: DIOCFLUSH of input fd %d failed", fdread);
2480Sstevel@tonic-gate 	if ( ioctl(fdwrite, DIOCFLUSH, NULL) != 0 )
2490Sstevel@tonic-gate 		DEBUG(4, "dkteardown: DIOCFLUSH of output fd %d failed", fdwrite);
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	(void)close(fdread);
2520Sstevel@tonic-gate 	(void)close(fdwrite);
2530Sstevel@tonic-gate 	return(SUCCESS);
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate #endif /* DATAKIT */
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate #ifdef TLI
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate  *	tread - tli read routine
2610Sstevel@tonic-gate  */
2620Sstevel@tonic-gate static ssize_t
tread(fd,buf,nbytes)2630Sstevel@tonic-gate tread(fd, buf, nbytes)
2640Sstevel@tonic-gate int		fd;
2650Sstevel@tonic-gate char		*buf;
2660Sstevel@tonic-gate unsigned	nbytes;
2670Sstevel@tonic-gate {
2680Sstevel@tonic-gate 	int		rcvflags;
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	return((ssize_t)t_rcv(fd, buf, nbytes, &rcvflags));
2710Sstevel@tonic-gate }
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate /*
2740Sstevel@tonic-gate  *	twrite - tli write routine
2750Sstevel@tonic-gate  */
2760Sstevel@tonic-gate #define	N_CHECK	100
2770Sstevel@tonic-gate static ssize_t
twrite(fd,buf,nbytes)2780Sstevel@tonic-gate twrite(fd, buf, nbytes)
2790Sstevel@tonic-gate int		fd;
2800Sstevel@tonic-gate char		*buf;
2810Sstevel@tonic-gate unsigned	nbytes;
2820Sstevel@tonic-gate {
2830Sstevel@tonic-gate 	register int		i, ret;
2840Sstevel@tonic-gate 	static int		n_writ, got_info;
2850Sstevel@tonic-gate 	static struct t_info	info;
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	if ( got_info == 0 ) {
2880Sstevel@tonic-gate 		if ( t_getinfo(fd, &info) != 0 ) {
2890Sstevel@tonic-gate 			tfaillog(fd, "twrite: t_getinfo\n");
2900Sstevel@tonic-gate 			return(FAIL);
2910Sstevel@tonic-gate 		}
2920Sstevel@tonic-gate 		got_info = 1;
2930Sstevel@tonic-gate 	}
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	/* on every N_CHECKth call, check that are still in DATAXFER state */
2960Sstevel@tonic-gate 	if ( ++n_writ == N_CHECK ) {
2970Sstevel@tonic-gate 		n_writ = 0;
2980Sstevel@tonic-gate 		if ( t_getstate(fd) != T_DATAXFER )
2990Sstevel@tonic-gate 			return(FAIL);
3000Sstevel@tonic-gate 	}
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	if ( info.tsdu <= 0 || nbytes <= info.tsdu )
3030Sstevel@tonic-gate 		return(t_snd(fd, buf, nbytes, NULL));
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	/* if get here, then there is a limit on transmit size	*/
3060Sstevel@tonic-gate 	/* (info.tsdu > 0) and buf exceeds it			*/
3070Sstevel@tonic-gate 	i = ret = 0;
3080Sstevel@tonic-gate 	while ( nbytes >= info.tsdu ) {
3090Sstevel@tonic-gate 		if ( (ret = t_snd(fd,  &buf[i], info.tsdu, NULL)) != info.tsdu )
3100Sstevel@tonic-gate 			return( ( ret >= 0 ? (i + ret) : ret ) );
3110Sstevel@tonic-gate 		i += info.tsdu;
3120Sstevel@tonic-gate 		nbytes -= info.tsdu;
3130Sstevel@tonic-gate 	}
3140Sstevel@tonic-gate 	if ( nbytes != 0 ) {
3150Sstevel@tonic-gate 		if ( (ret = t_snd(fd,  &buf[i], nbytes, NULL)) != nbytes )
3160Sstevel@tonic-gate 			return( (ssize_t)( ret >= 0 ? (i + ret) : ret ) );
3170Sstevel@tonic-gate 		i += nbytes;
3180Sstevel@tonic-gate 	}
3190Sstevel@tonic-gate 	return((ssize_t)i);
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate /*
3240Sstevel@tonic-gate  *	tioctl - stub for tli ioctl routine
3250Sstevel@tonic-gate  */
3260Sstevel@tonic-gate /*ARGSUSED*/
3270Sstevel@tonic-gate static int
3280Sstevel@tonic-gate #ifdef __STDC__
tioctl(int fd,int request,...)3290Sstevel@tonic-gate tioctl(int fd, int request, ...)
3300Sstevel@tonic-gate #else
3310Sstevel@tonic-gate tioctl(fd, request, arg)
3320Sstevel@tonic-gate int	fd, request;
3330Sstevel@tonic-gate #endif
3340Sstevel@tonic-gate {
3350Sstevel@tonic-gate 	return(SUCCESS);
3360Sstevel@tonic-gate }
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate /*
3390Sstevel@tonic-gate  *	tsetup - tli setup routine
3400Sstevel@tonic-gate  *	note blatant assumption that *fdreadp == *fdwritep == 0
3410Sstevel@tonic-gate  */
3420Sstevel@tonic-gate static int
tsetup(role,fdreadp,fdwritep)3430Sstevel@tonic-gate tsetup( role, fdreadp, fdwritep )
3440Sstevel@tonic-gate int	*fdreadp, *fdwritep;
3450Sstevel@tonic-gate {
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	if ( role == SLAVE ) {
3480Sstevel@tonic-gate 		*fdreadp = 0;
3490Sstevel@tonic-gate 		*fdwritep = 1;
3500Sstevel@tonic-gate 		/* 2 has been re-opened to RMTDEBUG in main() */
3510Sstevel@tonic-gate 		errno = t_errno = 0;
3520Sstevel@tonic-gate 		if ( t_sync(*fdreadp) == -1 || t_sync(*fdwritep) == -1 ) {
3530Sstevel@tonic-gate 			tfaillog(*fdreadp, "tsetup: t_sync\n");
3540Sstevel@tonic-gate 			return(FAIL);
3550Sstevel@tonic-gate 		}
3560Sstevel@tonic-gate 	}
3570Sstevel@tonic-gate 	return(SUCCESS);
3580Sstevel@tonic-gate }
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate /*
3610Sstevel@tonic-gate  *	tteardown - tli shutdown routine
3620Sstevel@tonic-gate  */
3630Sstevel@tonic-gate /*ARGSUSED*/
3640Sstevel@tonic-gate static int
tteardown(role,fdread,fdwrite)3650Sstevel@tonic-gate tteardown( role, fdread, fdwrite )
3660Sstevel@tonic-gate {
3670Sstevel@tonic-gate 	(void)t_unbind(fdread);
3680Sstevel@tonic-gate 	(void)t_close(fdread);
3690Sstevel@tonic-gate 	return(SUCCESS);
3700Sstevel@tonic-gate }
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate #ifdef TLIS
3730Sstevel@tonic-gate /*
3740Sstevel@tonic-gate  *	tssetup - tli, with streams module, setup routine
3750Sstevel@tonic-gate  *	note blatant assumption that *fdreadp == *fdwritep
3760Sstevel@tonic-gate  */
3770Sstevel@tonic-gate static int
tssetup(role,fdreadp,fdwritep)3780Sstevel@tonic-gate tssetup( role, fdreadp, fdwritep )
3790Sstevel@tonic-gate int	role;
3800Sstevel@tonic-gate int	*fdreadp;
3810Sstevel@tonic-gate int	*fdwritep;
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate 	if ( role == SLAVE ) {
3840Sstevel@tonic-gate 		*fdreadp = 0;
3850Sstevel@tonic-gate 		*fdwritep = 1;
3860Sstevel@tonic-gate 		/* 2 has been re-opened to RMTDEBUG in main() */
3870Sstevel@tonic-gate 		DEBUG(5, "tssetup: SLAVE mode: leaving ok\n%s", "");
3880Sstevel@tonic-gate 		return(SUCCESS);
3890Sstevel@tonic-gate 	}
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 	DEBUG(4, "tssetup: MASTER mode: leaving ok\n%s", "");
3920Sstevel@tonic-gate 	return(SUCCESS);
3930Sstevel@tonic-gate }
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate /*
3960Sstevel@tonic-gate  *	Report why a TLI call failed.
3970Sstevel@tonic-gate  */
3980Sstevel@tonic-gate GLOBAL void
tfaillog(fd,s)3990Sstevel@tonic-gate tfaillog(fd, s)
4000Sstevel@tonic-gate int	fd;
4010Sstevel@tonic-gate char	*s;
4020Sstevel@tonic-gate {
4030Sstevel@tonic-gate 	char	fmt[ BUFSIZ ];
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 	if (0 < t_errno && t_errno < t_nerr) {
4060Sstevel@tonic-gate 		sprintf( fmt, "%s: %%s\n", s );
4070Sstevel@tonic-gate 		DEBUG(5, fmt, t_errlist[t_errno]);
4080Sstevel@tonic-gate 		logent(s, t_errlist[t_errno]);
4090Sstevel@tonic-gate 		if ( t_errno == TSYSERR ) {
4100Sstevel@tonic-gate 			strcpy(fmt, "tlicall: system error: %s\n");
411*634Sdp 			DEBUG(5, fmt, strerror(errno));
4120Sstevel@tonic-gate 		} else if ( t_errno == TLOOK ) {
4130Sstevel@tonic-gate 			show_tlook(fd);
4140Sstevel@tonic-gate 		}
4150Sstevel@tonic-gate 	} else {
4160Sstevel@tonic-gate 		sprintf(fmt, "unknown tli error %d", t_errno);
4170Sstevel@tonic-gate 		logent(s, fmt);
4180Sstevel@tonic-gate 		sprintf(fmt, "%s: unknown tli error %d", s, t_errno);
4190Sstevel@tonic-gate 		DEBUG(5, fmt, 0);
4200Sstevel@tonic-gate 		sprintf(fmt, "%s: %%s\n", s);
421*634Sdp 		DEBUG(5, fmt, strerror(errno));
4220Sstevel@tonic-gate 	}
4230Sstevel@tonic-gate 	return;
4240Sstevel@tonic-gate }
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate GLOBAL void
show_tlook(fd)4270Sstevel@tonic-gate show_tlook(fd)
4280Sstevel@tonic-gate int fd;
4290Sstevel@tonic-gate {
4300Sstevel@tonic-gate 	register int reason;
4310Sstevel@tonic-gate 	register char *msg;
4320Sstevel@tonic-gate 	extern int	t_errno;
4330Sstevel@tonic-gate /*
4340Sstevel@tonic-gate  * Find out the current state of the interface.
4350Sstevel@tonic-gate  */
4360Sstevel@tonic-gate 	errno = t_errno = 0;
4370Sstevel@tonic-gate 	switch( reason = t_getstate(fd) ) {
4380Sstevel@tonic-gate 	case T_UNBND:		msg = "T_UNBIND";	break;
4390Sstevel@tonic-gate 	case T_IDLE:		msg = "T_IDLE";		break;
4400Sstevel@tonic-gate 	case T_OUTCON:		msg = "T_OUTCON";	break;
4410Sstevel@tonic-gate 	case T_INCON:		msg = "T_INCON";	break;
4420Sstevel@tonic-gate 	case T_DATAXFER:	msg = "T_DATAXFER";	break;
4430Sstevel@tonic-gate 	case T_OUTREL:		msg = "T_OUTREL";	break;
4440Sstevel@tonic-gate 	case T_INREL:		msg = "T_INREL";	break;
4450Sstevel@tonic-gate 	default:		msg = NULL;		break;
4460Sstevel@tonic-gate 	}
4470Sstevel@tonic-gate 	if( msg == NULL )
4480Sstevel@tonic-gate 		return;
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 	DEBUG(5, "state is %s", msg);
4510Sstevel@tonic-gate 	switch( reason = t_look(fd) ) {
4520Sstevel@tonic-gate 	case -1:		msg = ""; break;
4530Sstevel@tonic-gate 	case 0:			msg = "NO ERROR"; break;
4540Sstevel@tonic-gate 	case T_LISTEN:		msg = "T_LISTEN"; break;
4550Sstevel@tonic-gate 	case T_CONNECT:		msg = "T_CONNECT"; break;
4560Sstevel@tonic-gate 	case T_DATA:		msg = "T_DATA";	 break;
4570Sstevel@tonic-gate 	case T_EXDATA:		msg = "T_EXDATA"; break;
4580Sstevel@tonic-gate 	case T_DISCONNECT:	msg = "T_DISCONNECT"; break;
4590Sstevel@tonic-gate 	case T_ORDREL:		msg = "T_ORDREL"; break;
4600Sstevel@tonic-gate 	case T_ERROR:		msg = "T_ERROR"; break;
4610Sstevel@tonic-gate 	case T_UDERR:		msg = "T_UDERR"; break;
4620Sstevel@tonic-gate 	default:		msg = "UNKNOWN ERROR"; break;
4630Sstevel@tonic-gate 	}
4640Sstevel@tonic-gate 	DEBUG(4, " reason is %s\n", msg);
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	if ( reason == T_DISCONNECT )
4670Sstevel@tonic-gate 	{
4680Sstevel@tonic-gate 		struct t_discon	*dropped;
4690Sstevel@tonic-gate 		if ( ((dropped =
4700Sstevel@tonic-gate 			(struct t_discon *)t_alloc(fd, T_DIS, T_ALL)) == 0)
4710Sstevel@tonic-gate 		||  (t_rcvdis(fd, dropped) == -1 )) {
4720Sstevel@tonic-gate 			if (dropped)
4730Sstevel@tonic-gate 				t_free((char *)dropped, T_DIS);
4740Sstevel@tonic-gate 			return;
4750Sstevel@tonic-gate 		}
4760Sstevel@tonic-gate 		DEBUG(5, "disconnect reason #%d\n", dropped->reason);
4770Sstevel@tonic-gate 		t_free((char *)dropped, T_DIS);
4780Sstevel@tonic-gate 	}
4790Sstevel@tonic-gate 	return;
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate #endif /*  TLIS  */
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate #endif /*  TLI  */
485