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