xref: /titanic_44/usr/src/lib/libnsl/dial/interface.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*	interface( label )
34*7c478bd9Sstevel@tonic-gate 	provide alternate definitions for the I/O functions through global
35*7c478bd9Sstevel@tonic-gate 	interfaces.
36*7c478bd9Sstevel@tonic-gate */
37*7c478bd9Sstevel@tonic-gate #include	"uucp.h"
38*7c478bd9Sstevel@tonic-gate #include <rpc/trace.h>
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #ifdef TLI
42*7c478bd9Sstevel@tonic-gate #include	<tiuser.h>
43*7c478bd9Sstevel@tonic-gate char *t_alloc();
44*7c478bd9Sstevel@tonic-gate int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis();
45*7c478bd9Sstevel@tonic-gate int t_getinfo(), t_getstate(), t_look(), t_rcv(), t_snd(), t_sync(), t_unbind();
46*7c478bd9Sstevel@tonic-gate #endif /*  TLI  */
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT
49*7c478bd9Sstevel@tonic-gate #include	"dk.h"
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate static int	dksetup();
52*7c478bd9Sstevel@tonic-gate static int	dkteardown();
53*7c478bd9Sstevel@tonic-gate #endif	/* DATAKIT */
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate EXTERN void	sethup();
56*7c478bd9Sstevel@tonic-gate EXTERN int	restline();
57*7c478bd9Sstevel@tonic-gate extern ssize_t	read(), write();
58*7c478bd9Sstevel@tonic-gate static int	usetup(), uteardown();
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate GLOBAL ssize_t	(*Read)() = read,
61*7c478bd9Sstevel@tonic-gate 	(*Write)() = write;
62*7c478bd9Sstevel@tonic-gate GLOBAL int	(*Ioctl)(int,int,...) = ioctl,
63*7c478bd9Sstevel@tonic-gate 	(*Setup)() = usetup,
64*7c478bd9Sstevel@tonic-gate 	(*Teardown)() = uteardown;
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate #ifdef TLI
67*7c478bd9Sstevel@tonic-gate EXTERN void tfaillog(int fd, const char *s);
68*7c478bd9Sstevel@tonic-gate EXTERN void show_tlook();
69*7c478bd9Sstevel@tonic-gate static ssize_t	tread(), twrite();	/* TLI i/o */
70*7c478bd9Sstevel@tonic-gate static int		tioctl(int, int, ...),
71*7c478bd9Sstevel@tonic-gate 		tsetup(),		/* TLI setup without streams module */
72*7c478bd9Sstevel@tonic-gate 		tssetup(),		/* TLI setup with streams module */
73*7c478bd9Sstevel@tonic-gate 		tteardown();		/* TLI teardown, works with either setup
74*7c478bd9Sstevel@tonic-gate 					*/
75*7c478bd9Sstevel@tonic-gate #endif /*  TLI  */
76*7c478bd9Sstevel@tonic-gate /*	The IN_label in Interface[] imply different caller routines:
77*7c478bd9Sstevel@tonic-gate 	e.g. tlicall().
78*7c478bd9Sstevel@tonic-gate 	If so, the names here and the names in callers.c must match.
79*7c478bd9Sstevel@tonic-gate */
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate static
82*7c478bd9Sstevel@tonic-gate   struct Interface {
83*7c478bd9Sstevel@tonic-gate 	const	char	*IN_label;		/* interface name */
84*7c478bd9Sstevel@tonic-gate 	ssize_t	(*IN_read)();		/* read function */
85*7c478bd9Sstevel@tonic-gate 	ssize_t	(*IN_write)();		/* write function */
86*7c478bd9Sstevel@tonic-gate 	int	(*IN_ioctl)(int,int,...);
87*7c478bd9Sstevel@tonic-gate 	int	(*IN_setup)();		/* setup function, called before first
88*7c478bd9Sstevel@tonic-gate 					i/o operation */
89*7c478bd9Sstevel@tonic-gate 	int	(*IN_teardown)();	/* teardown function, called after last
90*7c478bd9Sstevel@tonic-gate 					i/o operation */
91*7c478bd9Sstevel@tonic-gate } Interface[] = {
92*7c478bd9Sstevel@tonic-gate 			/* vanilla UNIX */
93*7c478bd9Sstevel@tonic-gate 		{ "UNIX", read, write, ioctl, usetup, uteardown },
94*7c478bd9Sstevel@tonic-gate #ifdef SYTEK
95*7c478bd9Sstevel@tonic-gate 			/* Sytek network */
96*7c478bd9Sstevel@tonic-gate 		{ "Sytek", read, write, ioctl, usetup, uteardown },
97*7c478bd9Sstevel@tonic-gate #endif /* Sytek network */
98*7c478bd9Sstevel@tonic-gate #ifdef DIAL801
99*7c478bd9Sstevel@tonic-gate 			/* 801 auto dialers */
100*7c478bd9Sstevel@tonic-gate 		{ "801", read, write, ioctl, usetup, uteardown },
101*7c478bd9Sstevel@tonic-gate #endif /* DIAL801 */
102*7c478bd9Sstevel@tonic-gate #ifdef DIAL801
103*7c478bd9Sstevel@tonic-gate 			/* 212 auto dialers */
104*7c478bd9Sstevel@tonic-gate 		{ "212", read, write, ioctl, usetup, uteardown },
105*7c478bd9Sstevel@tonic-gate #endif /* DIAL801 */
106*7c478bd9Sstevel@tonic-gate #ifdef TLI
107*7c478bd9Sstevel@tonic-gate 			/* AT&T Transport Interface Library WITHOUT streams */
108*7c478bd9Sstevel@tonic-gate 		{ "TLI", tread, twrite, tioctl, tsetup, tteardown },
109*7c478bd9Sstevel@tonic-gate #ifdef TLIS
110*7c478bd9Sstevel@tonic-gate 			/* AT&T Transport Interface Library WITH streams */
111*7c478bd9Sstevel@tonic-gate 		{ "TLIS", read, write, tioctl, tssetup, uteardown },
112*7c478bd9Sstevel@tonic-gate #endif /*  TLIS  */
113*7c478bd9Sstevel@tonic-gate #endif /*  TLI  */
114*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT
115*7c478bd9Sstevel@tonic-gate 		{ "DK", read, write, ioctl, dksetup, dkteardown },
116*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
117*7c478bd9Sstevel@tonic-gate #ifdef UNET  /* this should work for 4.2BSD and 3com */
118*7c478bd9Sstevel@tonic-gate 		{ "TCP", read, write, ioctl, usetup, uteardown },
119*7c478bd9Sstevel@tonic-gate #endif
120*7c478bd9Sstevel@tonic-gate #ifdef UNET
121*7c478bd9Sstevel@tonic-gate 		{ "Unetserver", read, write, ioctl, usetup, uteardown },
122*7c478bd9Sstevel@tonic-gate #endif
123*7c478bd9Sstevel@tonic-gate 		{ 0, 0, 0, 0, 0, 0 }
124*7c478bd9Sstevel@tonic-gate 	};
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate GLOBAL int
128*7c478bd9Sstevel@tonic-gate interface(label)
129*7c478bd9Sstevel@tonic-gate char	*label;
130*7c478bd9Sstevel@tonic-gate {
131*7c478bd9Sstevel@tonic-gate 	register int	i;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 	trace1(TR_interface, 0);
134*7c478bd9Sstevel@tonic-gate 	for (i = 0;  Interface[i].IN_label;  ++i) {
135*7c478bd9Sstevel@tonic-gate 		if (!strcmp(Interface[i].IN_label, label)) {
136*7c478bd9Sstevel@tonic-gate 			Read = Interface[i].IN_read;
137*7c478bd9Sstevel@tonic-gate 			Write = Interface[i].IN_write;
138*7c478bd9Sstevel@tonic-gate 			Ioctl = Interface[i].IN_ioctl;
139*7c478bd9Sstevel@tonic-gate 			Setup = Interface[i].IN_setup;
140*7c478bd9Sstevel@tonic-gate 			Teardown = Interface[i].IN_teardown;
141*7c478bd9Sstevel@tonic-gate 			DEBUG(5, "set interface %s\n", label);
142*7c478bd9Sstevel@tonic-gate 			trace1(TR_interface, 1);
143*7c478bd9Sstevel@tonic-gate 			return (0);
144*7c478bd9Sstevel@tonic-gate 		}
145*7c478bd9Sstevel@tonic-gate 	}
146*7c478bd9Sstevel@tonic-gate 	trace1(TR_interface, 1);
147*7c478bd9Sstevel@tonic-gate 	return (FAIL);
148*7c478bd9Sstevel@tonic-gate }
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate /*
151*7c478bd9Sstevel@tonic-gate  *	usetup - vanilla unix setup routine
152*7c478bd9Sstevel@tonic-gate  */
153*7c478bd9Sstevel@tonic-gate static int
154*7c478bd9Sstevel@tonic-gate usetup(int role, int *fdreadp, int *fdwritep)
155*7c478bd9Sstevel@tonic-gate {
156*7c478bd9Sstevel@tonic-gate 	trace1(TR_usetup, 0);
157*7c478bd9Sstevel@tonic-gate 	if (role == SLAVE) {
158*7c478bd9Sstevel@tonic-gate 		*fdreadp = 0;
159*7c478bd9Sstevel@tonic-gate 		*fdwritep = 1;
160*7c478bd9Sstevel@tonic-gate 		/* 2 has been re-opened to RMTDEBUG in main() */
161*7c478bd9Sstevel@tonic-gate 	}
162*7c478bd9Sstevel@tonic-gate 	trace1(TR_usetup, 1);
163*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
164*7c478bd9Sstevel@tonic-gate }
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate /*
167*7c478bd9Sstevel@tonic-gate  *	uteardown - vanilla unix teardown routine
168*7c478bd9Sstevel@tonic-gate  */
169*7c478bd9Sstevel@tonic-gate static int
170*7c478bd9Sstevel@tonic-gate uteardown(int role, int fdread, int fdwrite)
171*7c478bd9Sstevel@tonic-gate {
172*7c478bd9Sstevel@tonic-gate 	int ret;
173*7c478bd9Sstevel@tonic-gate 	char *ttyn;
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	trace1(TR_uteardown, 0);
176*7c478bd9Sstevel@tonic-gate 	if (role == SLAVE) {
177*7c478bd9Sstevel@tonic-gate 		ret = restline();
178*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "ret restline - %d\n", ret);
179*7c478bd9Sstevel@tonic-gate 		sethup(0);
180*7c478bd9Sstevel@tonic-gate 	}
181*7c478bd9Sstevel@tonic-gate 	if (fdread != -1) {
182*7c478bd9Sstevel@tonic-gate 		ttyn = ttyname(fdread);
183*7c478bd9Sstevel@tonic-gate 		if (ttyn != NULL)
184*7c478bd9Sstevel@tonic-gate 			chmod(ttyn, Dev_mode);	/* can fail, but who cares? */
185*7c478bd9Sstevel@tonic-gate 		(void) close(fdread);
186*7c478bd9Sstevel@tonic-gate 		(void) close(fdwrite);
187*7c478bd9Sstevel@tonic-gate 	}
188*7c478bd9Sstevel@tonic-gate 	trace1(TR_uteardown, 1);
189*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
190*7c478bd9Sstevel@tonic-gate }
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate #ifdef DATAKIT
193*7c478bd9Sstevel@tonic-gate /*
194*7c478bd9Sstevel@tonic-gate  *	dksetup - DATAKIT setup routine
195*7c478bd9Sstevel@tonic-gate  *
196*7c478bd9Sstevel@tonic-gate  * Put line in block mode.
197*7c478bd9Sstevel@tonic-gate  */
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate static int
200*7c478bd9Sstevel@tonic-gate dksetup (role, fdreadp, fdwritep)
201*7c478bd9Sstevel@tonic-gate int	role;
202*7c478bd9Sstevel@tonic-gate int *	fdreadp;
203*7c478bd9Sstevel@tonic-gate int *	fdwritep;
204*7c478bd9Sstevel@tonic-gate {
205*7c478bd9Sstevel@tonic-gate 	static short dkrmode[3] = { DKR_BLOCK | DKR_TIME, 0, 0 };
206*7c478bd9Sstevel@tonic-gate 	int	ret;
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	trace2(TR_dksetup, 0, role);
209*7c478bd9Sstevel@tonic-gate 	(void) usetup(role, fdreadp, fdwritep);
210*7c478bd9Sstevel@tonic-gate 	if ((ret = (*Ioctl)(*fdreadp, DIOCRMODE, dkrmode)) < 0) {
211*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "dksetup: failed to set block mode. ret=%d,\n", ret);
212*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "read fd=%d, ", *fdreadp);
213*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "errno=%d\n", errno);
214*7c478bd9Sstevel@tonic-gate 		trace1(TR_dksetup, 1);
215*7c478bd9Sstevel@tonic-gate 		return (FAIL);
216*7c478bd9Sstevel@tonic-gate 	}
217*7c478bd9Sstevel@tonic-gate 	trace1(TR_dksetup, 1);
218*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
219*7c478bd9Sstevel@tonic-gate }
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate /*
222*7c478bd9Sstevel@tonic-gate  *	dkteardown  -  DATAKIT teardown routine
223*7c478bd9Sstevel@tonic-gate  */
224*7c478bd9Sstevel@tonic-gate static int
225*7c478bd9Sstevel@tonic-gate dkteardown(role, fdread, fdwrite)
226*7c478bd9Sstevel@tonic-gate int	role, fdread, fdwrite;
227*7c478bd9Sstevel@tonic-gate {
228*7c478bd9Sstevel@tonic-gate 	char	*ttyn;
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	trace4(TR_dkteardown, 0, role, fdread, fdwrite);
231*7c478bd9Sstevel@tonic-gate 	if (role == MASTER) {
232*7c478bd9Sstevel@tonic-gate 		ttyn = ttyname(fdread);
233*7c478bd9Sstevel@tonic-gate 		if (ttyn != NULL)
234*7c478bd9Sstevel@tonic-gate 			chmod(ttyn, Dev_mode);	/* can fail, but who cares? */
235*7c478bd9Sstevel@tonic-gate 	}
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 	/*	must flush fd's for datakit	*/
238*7c478bd9Sstevel@tonic-gate 	/*	else close can hang		*/
239*7c478bd9Sstevel@tonic-gate 	if (ioctl(fdread, DIOCFLUSH, NULL) != 0)
240*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "dkteardown: DIOCFLUSH of input fd %d failed", fdread);
241*7c478bd9Sstevel@tonic-gate 	if (ioctl(fdwrite, DIOCFLUSH, NULL) != 0)
242*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "dkteardown: DIOCFLUSH of output fd %d failed", fdwrite);
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 	(void) close(fdread);
245*7c478bd9Sstevel@tonic-gate 	(void) close(fdwrite);
246*7c478bd9Sstevel@tonic-gate 	trace1(TR_dkteardown, 1);
247*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
248*7c478bd9Sstevel@tonic-gate }
249*7c478bd9Sstevel@tonic-gate #endif /* DATAKIT */
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate #ifdef TLI
253*7c478bd9Sstevel@tonic-gate /*
254*7c478bd9Sstevel@tonic-gate  *	tread - tli read routine
255*7c478bd9Sstevel@tonic-gate  */
256*7c478bd9Sstevel@tonic-gate static ssize_t
257*7c478bd9Sstevel@tonic-gate tread(fd, buf, nbytes)
258*7c478bd9Sstevel@tonic-gate int		fd;
259*7c478bd9Sstevel@tonic-gate char		*buf;
260*7c478bd9Sstevel@tonic-gate unsigned	nbytes;
261*7c478bd9Sstevel@tonic-gate {
262*7c478bd9Sstevel@tonic-gate 	int		rcvflags;
263*7c478bd9Sstevel@tonic-gate 	int		dummy;
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 	trace2(TR_tread, 0, fd);
266*7c478bd9Sstevel@tonic-gate 	dummy = t_rcv(fd, buf, nbytes, &rcvflags);
267*7c478bd9Sstevel@tonic-gate 	trace1(TR_tread, 1);
268*7c478bd9Sstevel@tonic-gate 	return ((ssize_t)dummy);
269*7c478bd9Sstevel@tonic-gate }
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate /*
272*7c478bd9Sstevel@tonic-gate  *	twrite - tli write routine
273*7c478bd9Sstevel@tonic-gate  */
274*7c478bd9Sstevel@tonic-gate #define	N_CHECK	100
275*7c478bd9Sstevel@tonic-gate static ssize_t
276*7c478bd9Sstevel@tonic-gate twrite(fd, buf, nbytes)
277*7c478bd9Sstevel@tonic-gate int		fd;
278*7c478bd9Sstevel@tonic-gate char		*buf;
279*7c478bd9Sstevel@tonic-gate unsigned	nbytes;
280*7c478bd9Sstevel@tonic-gate {
281*7c478bd9Sstevel@tonic-gate 	register int		i, ret;
282*7c478bd9Sstevel@tonic-gate 	static int		n_writ, got_info;
283*7c478bd9Sstevel@tonic-gate 	static struct t_info	info;
284*7c478bd9Sstevel@tonic-gate 	int                     dummy;
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 	trace3(TR_twrite, 0, fd, nbytes);
287*7c478bd9Sstevel@tonic-gate 	if (got_info == 0) {
288*7c478bd9Sstevel@tonic-gate 		if (t_getinfo(fd, &info) != 0) {
289*7c478bd9Sstevel@tonic-gate 			tfaillog(fd, "twrite: t_getinfo\n");
290*7c478bd9Sstevel@tonic-gate 			trace1(TR_twrite, 1);
291*7c478bd9Sstevel@tonic-gate 			return (FAIL);
292*7c478bd9Sstevel@tonic-gate 		}
293*7c478bd9Sstevel@tonic-gate 		got_info = 1;
294*7c478bd9Sstevel@tonic-gate 	}
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	/* on every N_CHECKth call, check that are still in DATAXFER state */
297*7c478bd9Sstevel@tonic-gate 	if (++n_writ == N_CHECK) {
298*7c478bd9Sstevel@tonic-gate 		n_writ = 0;
299*7c478bd9Sstevel@tonic-gate 		if (t_getstate(fd) != T_DATAXFER) {
300*7c478bd9Sstevel@tonic-gate 			trace1(TR_twrite, 1);
301*7c478bd9Sstevel@tonic-gate 			return (FAIL);
302*7c478bd9Sstevel@tonic-gate 		}
303*7c478bd9Sstevel@tonic-gate 	}
304*7c478bd9Sstevel@tonic-gate 
305*7c478bd9Sstevel@tonic-gate 	if (info.tsdu <= 0 || nbytes <= info.tsdu) {
306*7c478bd9Sstevel@tonic-gate 		dummy = t_snd(fd, buf, nbytes, NULL);
307*7c478bd9Sstevel@tonic-gate 		trace1(TR_twrite, 1);
308*7c478bd9Sstevel@tonic-gate 		return ((ssize_t)dummy);
309*7c478bd9Sstevel@tonic-gate 	}
310*7c478bd9Sstevel@tonic-gate 	/* if get here, then there is a limit on transmit size	*/
311*7c478bd9Sstevel@tonic-gate 	/* (info.tsdu > 0) and buf exceeds it			*/
312*7c478bd9Sstevel@tonic-gate 	i = ret = 0;
313*7c478bd9Sstevel@tonic-gate 	while (nbytes >= info.tsdu) {
314*7c478bd9Sstevel@tonic-gate 		if ((ret = t_snd(fd,  &buf[i], info.tsdu, NULL)) != info.tsdu) {
315*7c478bd9Sstevel@tonic-gate 			trace1(TR_twrite, 1);
316*7c478bd9Sstevel@tonic-gate 			return ((ssize_t)(ret >= 0 ? (i + ret) : ret));
317*7c478bd9Sstevel@tonic-gate 		}
318*7c478bd9Sstevel@tonic-gate 		i += info.tsdu;
319*7c478bd9Sstevel@tonic-gate 		nbytes -= info.tsdu;
320*7c478bd9Sstevel@tonic-gate 	}
321*7c478bd9Sstevel@tonic-gate 	if (nbytes != 0) {
322*7c478bd9Sstevel@tonic-gate 		if ((ret = t_snd(fd,  &buf[i], nbytes, NULL)) != nbytes) {
323*7c478bd9Sstevel@tonic-gate 			trace1(TR_twrite, 1);
324*7c478bd9Sstevel@tonic-gate 			return ((ssize_t)(ret >= 0 ? (i + ret) : ret));
325*7c478bd9Sstevel@tonic-gate 		}
326*7c478bd9Sstevel@tonic-gate 		i += nbytes;
327*7c478bd9Sstevel@tonic-gate 	}
328*7c478bd9Sstevel@tonic-gate 	trace1(TR_twrite, 1);
329*7c478bd9Sstevel@tonic-gate 	return ((ssize_t)i);
330*7c478bd9Sstevel@tonic-gate }
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate /*
333*7c478bd9Sstevel@tonic-gate  *	tioctl - stub for tli ioctl routine
334*7c478bd9Sstevel@tonic-gate  */
335*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
336*7c478bd9Sstevel@tonic-gate static int
337*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
338*7c478bd9Sstevel@tonic-gate tioctl(int fd, int request, ...)
339*7c478bd9Sstevel@tonic-gate #else
340*7c478bd9Sstevel@tonic-gate tioctl(fd, request, arg)
341*7c478bd9Sstevel@tonic-gate int	fd, request;
342*7c478bd9Sstevel@tonic-gate #endif
343*7c478bd9Sstevel@tonic-gate {
344*7c478bd9Sstevel@tonic-gate 	trace1(TR_tioctl, 0);
345*7c478bd9Sstevel@tonic-gate 	trace1(TR_tioctl, 1);
346*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
347*7c478bd9Sstevel@tonic-gate }
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate /*
350*7c478bd9Sstevel@tonic-gate  *	tsetup - tli setup routine
351*7c478bd9Sstevel@tonic-gate  *	note blatant assumption that *fdreadp == *fdwritep == 0
352*7c478bd9Sstevel@tonic-gate  */
353*7c478bd9Sstevel@tonic-gate static int
354*7c478bd9Sstevel@tonic-gate tsetup(int role, int *fdreadp, int *fdwritep)
355*7c478bd9Sstevel@tonic-gate {
356*7c478bd9Sstevel@tonic-gate 	trace1(TR_tsetup, 0);
357*7c478bd9Sstevel@tonic-gate 	if (role == SLAVE) {
358*7c478bd9Sstevel@tonic-gate 		*fdreadp = 0;
359*7c478bd9Sstevel@tonic-gate 		*fdwritep = 1;
360*7c478bd9Sstevel@tonic-gate 		/* 2 has been re-opened to RMTDEBUG in main() */
361*7c478bd9Sstevel@tonic-gate 		errno = t_errno = 0;
362*7c478bd9Sstevel@tonic-gate 		if (t_sync(*fdreadp) == -1 || t_sync(*fdwritep) == -1) {
363*7c478bd9Sstevel@tonic-gate 			tfaillog(*fdreadp, "tsetup: t_sync\n");
364*7c478bd9Sstevel@tonic-gate 			trace1(TR_tsetup, 1);
365*7c478bd9Sstevel@tonic-gate 			return (FAIL);
366*7c478bd9Sstevel@tonic-gate 		}
367*7c478bd9Sstevel@tonic-gate 	}
368*7c478bd9Sstevel@tonic-gate 	trace1(TR_tsetup, 1);
369*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
370*7c478bd9Sstevel@tonic-gate }
371*7c478bd9Sstevel@tonic-gate 
372*7c478bd9Sstevel@tonic-gate /*
373*7c478bd9Sstevel@tonic-gate  *	tteardown - tli shutdown routine
374*7c478bd9Sstevel@tonic-gate  */
375*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
376*7c478bd9Sstevel@tonic-gate static int
377*7c478bd9Sstevel@tonic-gate tteardown(int role, int fdread, int fdwrite)
378*7c478bd9Sstevel@tonic-gate {
379*7c478bd9Sstevel@tonic-gate 	trace1(TR_tteardown, 0);
380*7c478bd9Sstevel@tonic-gate 	(void) t_unbind(fdread);
381*7c478bd9Sstevel@tonic-gate 	(void) t_close(fdread);
382*7c478bd9Sstevel@tonic-gate 	trace1(TR_tteardown, 1);
383*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
384*7c478bd9Sstevel@tonic-gate }
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate #ifdef TLIS
387*7c478bd9Sstevel@tonic-gate /*
388*7c478bd9Sstevel@tonic-gate  *	tssetup - tli, with streams module, setup routine
389*7c478bd9Sstevel@tonic-gate  *	note blatant assumption that *fdreadp == *fdwritep
390*7c478bd9Sstevel@tonic-gate  */
391*7c478bd9Sstevel@tonic-gate static int
392*7c478bd9Sstevel@tonic-gate tssetup(role, fdreadp, fdwritep)
393*7c478bd9Sstevel@tonic-gate int	role;
394*7c478bd9Sstevel@tonic-gate int	*fdreadp;
395*7c478bd9Sstevel@tonic-gate int	*fdwritep;
396*7c478bd9Sstevel@tonic-gate {
397*7c478bd9Sstevel@tonic-gate 	trace2(TR_tssetup, 0, role);
398*7c478bd9Sstevel@tonic-gate 	if (role == SLAVE) {
399*7c478bd9Sstevel@tonic-gate 		*fdreadp = 0;
400*7c478bd9Sstevel@tonic-gate 		*fdwritep = 1;
401*7c478bd9Sstevel@tonic-gate 		/* 2 has been re-opened to RMTDEBUG in main() */
402*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "tssetup: SLAVE mode: leaving ok\n%s", "");
403*7c478bd9Sstevel@tonic-gate 		trace1(TR_tssetup, 1);
404*7c478bd9Sstevel@tonic-gate 		return (SUCCESS);
405*7c478bd9Sstevel@tonic-gate 	}
406*7c478bd9Sstevel@tonic-gate 
407*7c478bd9Sstevel@tonic-gate 	DEBUG(4, "tssetup: MASTER mode: leaving ok\n%s", "");
408*7c478bd9Sstevel@tonic-gate 	trace1(TR_tssetup, 1);
409*7c478bd9Sstevel@tonic-gate 	return (SUCCESS);
410*7c478bd9Sstevel@tonic-gate }
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate /*
413*7c478bd9Sstevel@tonic-gate  *	Report why a TLI call failed.
414*7c478bd9Sstevel@tonic-gate  */
415*7c478bd9Sstevel@tonic-gate GLOBAL void
416*7c478bd9Sstevel@tonic-gate tfaillog(fd, s)
417*7c478bd9Sstevel@tonic-gate int	fd;
418*7c478bd9Sstevel@tonic-gate const char	*s;
419*7c478bd9Sstevel@tonic-gate {
420*7c478bd9Sstevel@tonic-gate 	char	fmt[ BUFSIZ ];
421*7c478bd9Sstevel@tonic-gate 
422*7c478bd9Sstevel@tonic-gate 	trace2(TR_tfaillog, 0, fd);
423*7c478bd9Sstevel@tonic-gate 	if (0 < t_errno && t_errno < t_nerr) {
424*7c478bd9Sstevel@tonic-gate 		sprintf(fmt, "%s: %%s\n", s);
425*7c478bd9Sstevel@tonic-gate 		DEBUG(5, fmt, t_errlist[t_errno]);
426*7c478bd9Sstevel@tonic-gate 		logent(s, t_errlist[t_errno]);
427*7c478bd9Sstevel@tonic-gate 		if (t_errno == TSYSERR) {
428*7c478bd9Sstevel@tonic-gate 			strcpy(fmt, "tlicall: system error: %s\n");
429*7c478bd9Sstevel@tonic-gate 			DEBUG(5, fmt, strerror(errno));
430*7c478bd9Sstevel@tonic-gate 		} else if (t_errno == TLOOK) {
431*7c478bd9Sstevel@tonic-gate 			show_tlook(fd);
432*7c478bd9Sstevel@tonic-gate 		}
433*7c478bd9Sstevel@tonic-gate 	} else {
434*7c478bd9Sstevel@tonic-gate 		sprintf(fmt, "unknown tli error %d", t_errno);
435*7c478bd9Sstevel@tonic-gate 		logent(s, fmt);
436*7c478bd9Sstevel@tonic-gate 		sprintf(fmt, "%s: unknown tli error %d", s, t_errno);
437*7c478bd9Sstevel@tonic-gate 		DEBUG(5, fmt, 0);
438*7c478bd9Sstevel@tonic-gate 		sprintf(fmt, "%s: %%s\n", s);
439*7c478bd9Sstevel@tonic-gate 		DEBUG(5, fmt, strerror(errno));
440*7c478bd9Sstevel@tonic-gate 	}
441*7c478bd9Sstevel@tonic-gate 	trace1(TR_tfaillog, 1);
442*7c478bd9Sstevel@tonic-gate 	return;
443*7c478bd9Sstevel@tonic-gate }
444*7c478bd9Sstevel@tonic-gate 
445*7c478bd9Sstevel@tonic-gate GLOBAL void
446*7c478bd9Sstevel@tonic-gate show_tlook(fd)
447*7c478bd9Sstevel@tonic-gate int fd;
448*7c478bd9Sstevel@tonic-gate {
449*7c478bd9Sstevel@tonic-gate 	register int reason;
450*7c478bd9Sstevel@tonic-gate 	register const char *msg;
451*7c478bd9Sstevel@tonic-gate 
452*7c478bd9Sstevel@tonic-gate /*
453*7c478bd9Sstevel@tonic-gate  * Find out the current state of the interface.
454*7c478bd9Sstevel@tonic-gate  */
455*7c478bd9Sstevel@tonic-gate 	trace2(TR_show_tlook, 0, fd);
456*7c478bd9Sstevel@tonic-gate 	errno = t_errno = 0;
457*7c478bd9Sstevel@tonic-gate 	switch(reason = t_getstate(fd)) {
458*7c478bd9Sstevel@tonic-gate 	case T_UNBND:		msg = (const char *)"T_UNBIND";	break;
459*7c478bd9Sstevel@tonic-gate 	case T_IDLE:		msg = (const char *)"T_IDLE";	break;
460*7c478bd9Sstevel@tonic-gate 	case T_OUTCON:		msg = (const char *)"T_OUTCON";	break;
461*7c478bd9Sstevel@tonic-gate 	case T_INCON:		msg = (const char *)"T_INCON";	break;
462*7c478bd9Sstevel@tonic-gate 	case T_DATAXFER:	msg = (const char *)"T_DATAXFER"; break;
463*7c478bd9Sstevel@tonic-gate 	case T_OUTREL:		msg = (const char *)"T_OUTREL";	break;
464*7c478bd9Sstevel@tonic-gate 	case T_INREL:		msg = (const char *)"T_INREL";	break;
465*7c478bd9Sstevel@tonic-gate 	default:		msg = NULL;		break;
466*7c478bd9Sstevel@tonic-gate 	}
467*7c478bd9Sstevel@tonic-gate 	if (msg == NULL) {
468*7c478bd9Sstevel@tonic-gate 		trace1(TR_show_tlook, 1);
469*7c478bd9Sstevel@tonic-gate 		return;
470*7c478bd9Sstevel@tonic-gate 	}
471*7c478bd9Sstevel@tonic-gate 	DEBUG(5, "state is %s", msg);
472*7c478bd9Sstevel@tonic-gate 	switch(reason = t_look(fd)) {
473*7c478bd9Sstevel@tonic-gate 	case -1:		msg = (const char *)""; break;
474*7c478bd9Sstevel@tonic-gate 	case 0:			msg = (const char *)"NO ERROR"; break;
475*7c478bd9Sstevel@tonic-gate 	case T_LISTEN:		msg = (const char *)"T_LISTEN"; break;
476*7c478bd9Sstevel@tonic-gate 	case T_CONNECT:		msg = (const char *)"T_CONNECT"; break;
477*7c478bd9Sstevel@tonic-gate 	case T_DATA:		msg = (const char *)"T_DATA";	 break;
478*7c478bd9Sstevel@tonic-gate 	case T_EXDATA:		msg = (const char *)"T_EXDATA"; break;
479*7c478bd9Sstevel@tonic-gate 	case T_DISCONNECT:	msg = (const char *)"T_DISCONNECT"; break;
480*7c478bd9Sstevel@tonic-gate 	case T_ORDREL:		msg = (const char *)"T_ORDREL"; break;
481*7c478bd9Sstevel@tonic-gate 	case T_ERROR:		msg = (const char *)"T_ERROR"; break;
482*7c478bd9Sstevel@tonic-gate 	case T_UDERR:		msg = (const char *)"T_UDERR"; break;
483*7c478bd9Sstevel@tonic-gate 	default:		msg = (const char *)"UNKNOWN ERROR"; break;
484*7c478bd9Sstevel@tonic-gate 	}
485*7c478bd9Sstevel@tonic-gate 	DEBUG(4, " reason is %s\n", msg);
486*7c478bd9Sstevel@tonic-gate 
487*7c478bd9Sstevel@tonic-gate 	if (reason == T_DISCONNECT)
488*7c478bd9Sstevel@tonic-gate 	{
489*7c478bd9Sstevel@tonic-gate 		struct t_discon	*dropped;
490*7c478bd9Sstevel@tonic-gate 		if (((dropped =
491*7c478bd9Sstevel@tonic-gate 			(struct t_discon *)t_alloc(fd, T_DIS, T_ALL)) == 0)
492*7c478bd9Sstevel@tonic-gate 		||  (t_rcvdis(fd, dropped) == -1)) {
493*7c478bd9Sstevel@tonic-gate 			if (dropped)
494*7c478bd9Sstevel@tonic-gate 				t_free((char *)dropped, T_DIS);
495*7c478bd9Sstevel@tonic-gate 			trace1(TR_show_tlook, 1);
496*7c478bd9Sstevel@tonic-gate 			return;
497*7c478bd9Sstevel@tonic-gate 		}
498*7c478bd9Sstevel@tonic-gate 		DEBUG(5, "disconnect reason #%d\n", dropped->reason);
499*7c478bd9Sstevel@tonic-gate 		t_free((char *)dropped, T_DIS);
500*7c478bd9Sstevel@tonic-gate 	}
501*7c478bd9Sstevel@tonic-gate 	trace1(TR_show_tlook, 1);
502*7c478bd9Sstevel@tonic-gate 	return;
503*7c478bd9Sstevel@tonic-gate }
504*7c478bd9Sstevel@tonic-gate 
505*7c478bd9Sstevel@tonic-gate #endif /*  TLIS  */
506*7c478bd9Sstevel@tonic-gate 
507*7c478bd9Sstevel@tonic-gate #endif /*  TLI  */
508