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