17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*09b0d01cSGary Mills * Copyright 2014 Gary Mills 24ace1a5f1Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 297c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 307c478bd9Sstevel@tonic-gate 31*09b0d01cSGary Mills /* 32*09b0d01cSGary Mills * interface(label) 33*09b0d01cSGary Mills * provide alternate definitions for the I/O functions through global 34*09b0d01cSGary Mills * interfaces. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate #include "uucp.h" 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef TLI 397c478bd9Sstevel@tonic-gate #include <tiuser.h> 407c478bd9Sstevel@tonic-gate char *t_alloc(); 417c478bd9Sstevel@tonic-gate int t_bind(), t_close(), t_connect(), t_free(), t_look(), t_open(), t_rcvdis(); 427c478bd9Sstevel@tonic-gate int t_getinfo(), t_getstate(), t_look(), t_rcv(), t_snd(), t_sync(), t_unbind(); 437c478bd9Sstevel@tonic-gate #endif /* TLI */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifdef DATAKIT 467c478bd9Sstevel@tonic-gate #include "dk.h" 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate static int dksetup(); 497c478bd9Sstevel@tonic-gate static int dkteardown(); 507c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate EXTERN void sethup(); 537c478bd9Sstevel@tonic-gate EXTERN int restline(); 547c478bd9Sstevel@tonic-gate #if defined(__STDC__) 557c478bd9Sstevel@tonic-gate extern int ioctl(int, int, ...); 567c478bd9Sstevel@tonic-gate #else 577c478bd9Sstevel@tonic-gate extern int ioctl(); 587c478bd9Sstevel@tonic-gate #endif 597c478bd9Sstevel@tonic-gate static int usetup(), uteardown(); 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate GLOBAL ssize_t (*Read)() = read, 627c478bd9Sstevel@tonic-gate (*Write)() = write; 637c478bd9Sstevel@tonic-gate #if defined(__STDC__) 647c478bd9Sstevel@tonic-gate GLOBAL int (*Ioctl)(int, int, ...) = ioctl, 657c478bd9Sstevel@tonic-gate #else 667c478bd9Sstevel@tonic-gate GLOBAL int (*Ioctl)() = ioctl, 677c478bd9Sstevel@tonic-gate #endif 687c478bd9Sstevel@tonic-gate (*Setup)() = usetup, 697c478bd9Sstevel@tonic-gate (*Teardown)() = uteardown; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate #ifdef TLI 727c478bd9Sstevel@tonic-gate EXTERN void tfaillog(), show_tlook(); 737c478bd9Sstevel@tonic-gate static ssize_t tread(), twrite(); /* TLI i/o */ 747c478bd9Sstevel@tonic-gate #ifdef __STDC__ 757c478bd9Sstevel@tonic-gate static int tioctl(int, int, ...), 767c478bd9Sstevel@tonic-gate #else 777c478bd9Sstevel@tonic-gate static int tioctl(), /* TLI i/o control */ 787c478bd9Sstevel@tonic-gate #endif 797c478bd9Sstevel@tonic-gate tsetup(), /* TLI setup without streams module */ 807c478bd9Sstevel@tonic-gate tssetup(), /* TLI setup with streams module */ 81*09b0d01cSGary Mills tteardown(); /* TLI teardown, works with either setup */ 827c478bd9Sstevel@tonic-gate #endif /* TLI */ 83*09b0d01cSGary Mills /* 84*09b0d01cSGary Mills * The IN_label in Interface[] imply different caller routines: 85*09b0d01cSGary Mills * e.g. tlicall(). 86*09b0d01cSGary Mills * If so, the names here and the names in callers.c must match. 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate static 907c478bd9Sstevel@tonic-gate struct Interface { 917c478bd9Sstevel@tonic-gate char *IN_label; /* interface name */ 927c478bd9Sstevel@tonic-gate ssize_t (*IN_read)(); /* read function */ 937c478bd9Sstevel@tonic-gate ssize_t (*IN_write)(); /* write function */ 947c478bd9Sstevel@tonic-gate #ifdef __STDC__ 957c478bd9Sstevel@tonic-gate int (*IN_ioctl)(int, int, ...); 967c478bd9Sstevel@tonic-gate #else 977c478bd9Sstevel@tonic-gate int (*IN_ioctl)(); /* ioctl function */ 987c478bd9Sstevel@tonic-gate #endif 99*09b0d01cSGary Mills int (*IN_setup)(); /* setup function, called before */ 100*09b0d01cSGary Mills /* first i/o operation */ 101*09b0d01cSGary Mills int (*IN_teardown)(); /* teardown function, called after */ 102*09b0d01cSGary Mills /* last i/o operation */ 1037c478bd9Sstevel@tonic-gate } Interface[] = { 1047c478bd9Sstevel@tonic-gate /* vanilla UNIX */ 1057c478bd9Sstevel@tonic-gate { "UNIX", read, write, ioctl, usetup, uteardown }, 1067c478bd9Sstevel@tonic-gate #ifdef TCP 1077c478bd9Sstevel@tonic-gate /* TCP over sockets or UNET */ 1087c478bd9Sstevel@tonic-gate { "TCP", read, write, ioctl, usetup, uteardown }, 1097c478bd9Sstevel@tonic-gate #endif /* TCP */ 1107c478bd9Sstevel@tonic-gate #ifdef SYTEK 1117c478bd9Sstevel@tonic-gate /* Sytek network */ 1127c478bd9Sstevel@tonic-gate { "Sytek", read, write, ioctl, usetup, uteardown }, 1137c478bd9Sstevel@tonic-gate #endif /* Sytek network */ 1147c478bd9Sstevel@tonic-gate #ifdef DIAL801 1157c478bd9Sstevel@tonic-gate /* 801 auto dialers */ 1167c478bd9Sstevel@tonic-gate { "801", read, write, ioctl, usetup, uteardown }, 1177c478bd9Sstevel@tonic-gate #endif /* DIAL801 */ 1187c478bd9Sstevel@tonic-gate #ifdef DIAL801 1197c478bd9Sstevel@tonic-gate /* 212 auto dialers */ 1207c478bd9Sstevel@tonic-gate { "212", read, write, ioctl, usetup, uteardown }, 1217c478bd9Sstevel@tonic-gate #endif /* DIAL801 */ 1227c478bd9Sstevel@tonic-gate #ifdef TLI 1237c478bd9Sstevel@tonic-gate /* AT&T Transport Interface Library WITHOUT streams */ 1247c478bd9Sstevel@tonic-gate { "TLI", tread, twrite, tioctl, tsetup, tteardown }, 1257c478bd9Sstevel@tonic-gate #ifdef TLIS 1267c478bd9Sstevel@tonic-gate /* AT&T Transport Interface Library WITH streams */ 1277c478bd9Sstevel@tonic-gate { "TLIS", read, write, tioctl, tssetup, uteardown }, 1287c478bd9Sstevel@tonic-gate #endif /* TLIS */ 1297c478bd9Sstevel@tonic-gate #endif /* TLI */ 1307c478bd9Sstevel@tonic-gate #ifdef DATAKIT 1317c478bd9Sstevel@tonic-gate { "DK", read, write, ioctl, dksetup, dkteardown }, 1327c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 1337c478bd9Sstevel@tonic-gate #ifdef UNET 1347c478bd9Sstevel@tonic-gate { "Unetserver", read, write, ioctl, usetup, uteardown }, 1357c478bd9Sstevel@tonic-gate #endif 1367c478bd9Sstevel@tonic-gate { 0, 0, 0, 0, 0, 0 } 1377c478bd9Sstevel@tonic-gate }; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate GLOBAL int 1417c478bd9Sstevel@tonic-gate interface(label) 1427c478bd9Sstevel@tonic-gate char *label; 1437c478bd9Sstevel@tonic-gate { 1447c478bd9Sstevel@tonic-gate register int i; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate for (i = 0; Interface[i].IN_label; ++i) { 147*09b0d01cSGary Mills if (0 == strcmp(Interface[i].IN_label, label)) { 1487c478bd9Sstevel@tonic-gate Read = Interface[i].IN_read; 1497c478bd9Sstevel@tonic-gate Write = Interface[i].IN_write; 1507c478bd9Sstevel@tonic-gate Ioctl = Interface[i].IN_ioctl; 1517c478bd9Sstevel@tonic-gate Setup = Interface[i].IN_setup; 1527c478bd9Sstevel@tonic-gate Teardown = Interface[i].IN_teardown; 1537c478bd9Sstevel@tonic-gate DEBUG(5, "set interface %s\n", label); 1547c478bd9Sstevel@tonic-gate return (0); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate return (FAIL); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate /* 1617c478bd9Sstevel@tonic-gate * usetup - vanilla unix setup routine 1627c478bd9Sstevel@tonic-gate */ 1637c478bd9Sstevel@tonic-gate static int 1647c478bd9Sstevel@tonic-gate usetup(role, fdreadp, fdwritep) 1657c478bd9Sstevel@tonic-gate int *fdreadp, *fdwritep; 1667c478bd9Sstevel@tonic-gate { 1677c478bd9Sstevel@tonic-gate if (role == SLAVE) 1687c478bd9Sstevel@tonic-gate { 1697c478bd9Sstevel@tonic-gate *fdreadp = 0; 1707c478bd9Sstevel@tonic-gate *fdwritep = 1; 1717c478bd9Sstevel@tonic-gate /* 2 has been re-opened to RMTDEBUG in main() */ 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate return (SUCCESS); 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* 1777c478bd9Sstevel@tonic-gate * uteardown - vanilla unix teardown routine 1787c478bd9Sstevel@tonic-gate */ 1797c478bd9Sstevel@tonic-gate static int 1807c478bd9Sstevel@tonic-gate uteardown(role, fdread, fdwrite) 1817c478bd9Sstevel@tonic-gate { 1827c478bd9Sstevel@tonic-gate int ret; 1837c478bd9Sstevel@tonic-gate char *ttyn; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if (role == SLAVE) { 1867c478bd9Sstevel@tonic-gate ret = restline(); 1877c478bd9Sstevel@tonic-gate DEBUG(4, "ret restline - %d\n", ret); 1887c478bd9Sstevel@tonic-gate if (fdread != -1) 1897c478bd9Sstevel@tonic-gate sethup(fdread); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate if (fdread != -1) { 1927c478bd9Sstevel@tonic-gate ttyn = ttyname(fdread); 1937c478bd9Sstevel@tonic-gate if (ttyn != NULL && Dev_mode != 0) 1947c478bd9Sstevel@tonic-gate chmod(ttyn, Dev_mode); /* can fail, but who cares? */ 1957c478bd9Sstevel@tonic-gate (void) close(fdread); 1967c478bd9Sstevel@tonic-gate (void) close(fdwrite); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate return (SUCCESS); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #ifdef DATAKIT 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * dksetup - DATAKIT setup routine 2047c478bd9Sstevel@tonic-gate * 2057c478bd9Sstevel@tonic-gate * Put line in block mode. 2067c478bd9Sstevel@tonic-gate */ 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate static int 2097c478bd9Sstevel@tonic-gate dksetup(role, fdreadp, fdwritep) 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate int role; 2127c478bd9Sstevel@tonic-gate int *fdreadp; 2137c478bd9Sstevel@tonic-gate int *fdwritep; 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate { 2167c478bd9Sstevel@tonic-gate static short dkrmode[3] = { DKR_BLOCK | DKR_TIME, 0, 0 }; 2177c478bd9Sstevel@tonic-gate int ret; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate (void) usetup(role, fdreadp, fdwritep); 2207c478bd9Sstevel@tonic-gate if ((ret = (*Ioctl)(*fdreadp, DIOCRMODE, dkrmode)) < 0) { 2217c478bd9Sstevel@tonic-gate DEBUG(4, "dksetup: failed to set block mode. ret=%d,\n", ret); 2227c478bd9Sstevel@tonic-gate DEBUG(4, "read fd=%d, ", *fdreadp); 2237c478bd9Sstevel@tonic-gate DEBUG(4, "errno=%d\n", errno); 2247c478bd9Sstevel@tonic-gate return (FAIL); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate return (SUCCESS); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * dkteardown - DATAKIT teardown routine 2317c478bd9Sstevel@tonic-gate */ 2327c478bd9Sstevel@tonic-gate static int 2337c478bd9Sstevel@tonic-gate dkteardown(role, fdread, fdwrite) 2347c478bd9Sstevel@tonic-gate int role, fdread, fdwrite; 2357c478bd9Sstevel@tonic-gate { 2367c478bd9Sstevel@tonic-gate char *ttyn; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate if (role == MASTER) { 2397c478bd9Sstevel@tonic-gate ttyn = ttyname(fdread); 2407c478bd9Sstevel@tonic-gate if (ttyn != NULL && Dev_mode != 0) 2417c478bd9Sstevel@tonic-gate chmod(ttyn, Dev_mode); /* can fail, but who cares? */ 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate /* must flush fd's for datakit */ 2457c478bd9Sstevel@tonic-gate /* else close can hang */ 2467c478bd9Sstevel@tonic-gate if (ioctl(fdread, DIOCFLUSH, NULL) != 0) 247*09b0d01cSGary Mills DEBUG(4, "dkteardown: DIOCFLUSH of input fd %d failed", 248*09b0d01cSGary Mills fdread); 2497c478bd9Sstevel@tonic-gate if (ioctl(fdwrite, DIOCFLUSH, NULL) != 0) 250*09b0d01cSGary Mills DEBUG(4, "dkteardown: DIOCFLUSH of output fd %d failed", 251*09b0d01cSGary Mills fdwrite); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate (void) close(fdread); 2547c478bd9Sstevel@tonic-gate (void) close(fdwrite); 2557c478bd9Sstevel@tonic-gate return (SUCCESS); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate #endif /* DATAKIT */ 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate #ifdef TLI 2617c478bd9Sstevel@tonic-gate /* 2627c478bd9Sstevel@tonic-gate * tread - tli read routine 2637c478bd9Sstevel@tonic-gate */ 2647c478bd9Sstevel@tonic-gate static ssize_t 2657c478bd9Sstevel@tonic-gate tread(fd, buf, nbytes) 2667c478bd9Sstevel@tonic-gate int fd; 2677c478bd9Sstevel@tonic-gate char *buf; 2687c478bd9Sstevel@tonic-gate unsigned nbytes; 2697c478bd9Sstevel@tonic-gate { 2707c478bd9Sstevel@tonic-gate int rcvflags; 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate return ((ssize_t)t_rcv(fd, buf, nbytes, &rcvflags)); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * twrite - tli write routine 2777c478bd9Sstevel@tonic-gate */ 2787c478bd9Sstevel@tonic-gate #define N_CHECK 100 2797c478bd9Sstevel@tonic-gate static ssize_t 2807c478bd9Sstevel@tonic-gate twrite(fd, buf, nbytes) 2817c478bd9Sstevel@tonic-gate int fd; 2827c478bd9Sstevel@tonic-gate char *buf; 2837c478bd9Sstevel@tonic-gate unsigned nbytes; 2847c478bd9Sstevel@tonic-gate { 2857c478bd9Sstevel@tonic-gate register int i, ret; 2867c478bd9Sstevel@tonic-gate static int n_writ, got_info; 2877c478bd9Sstevel@tonic-gate static struct t_info info; 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if (got_info == 0) { 2907c478bd9Sstevel@tonic-gate if (t_getinfo(fd, &info) != 0) { 2917c478bd9Sstevel@tonic-gate tfaillog(fd, "twrite: t_getinfo\n"); 2927c478bd9Sstevel@tonic-gate return (FAIL); 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate got_info = 1; 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate /* on every N_CHECKth call, check that are still in DATAXFER state */ 2987c478bd9Sstevel@tonic-gate if (++n_writ == N_CHECK) { 2997c478bd9Sstevel@tonic-gate n_writ = 0; 3007c478bd9Sstevel@tonic-gate if (t_getstate(fd) != T_DATAXFER) 3017c478bd9Sstevel@tonic-gate return (FAIL); 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate if (info.tsdu <= 0 || nbytes <= info.tsdu) 3057c478bd9Sstevel@tonic-gate return (t_snd(fd, buf, nbytes, NULL)); 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate /* if get here, then there is a limit on transmit size */ 3087c478bd9Sstevel@tonic-gate /* (info.tsdu > 0) and buf exceeds it */ 3097c478bd9Sstevel@tonic-gate i = ret = 0; 3107c478bd9Sstevel@tonic-gate while (nbytes >= info.tsdu) { 3117c478bd9Sstevel@tonic-gate if ((ret = t_snd(fd, &buf[i], info.tsdu, NULL)) != info.tsdu) 3127c478bd9Sstevel@tonic-gate return ((ret >= 0 ? (i + ret) : ret)); 3137c478bd9Sstevel@tonic-gate i += info.tsdu; 3147c478bd9Sstevel@tonic-gate nbytes -= info.tsdu; 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate if (nbytes != 0) { 3177c478bd9Sstevel@tonic-gate if ((ret = t_snd(fd, &buf[i], nbytes, NULL)) != nbytes) 3187c478bd9Sstevel@tonic-gate return ((ssize_t)(ret >= 0 ? (i + ret) : ret)); 3197c478bd9Sstevel@tonic-gate i += nbytes; 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate return ((ssize_t)i); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate * tioctl - stub for tli ioctl routine 3277c478bd9Sstevel@tonic-gate */ 3287c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3297c478bd9Sstevel@tonic-gate static int 3307c478bd9Sstevel@tonic-gate #ifdef __STDC__ 3317c478bd9Sstevel@tonic-gate tioctl(int fd, int request, ...) 3327c478bd9Sstevel@tonic-gate #else 3337c478bd9Sstevel@tonic-gate tioctl(fd, request, arg) 3347c478bd9Sstevel@tonic-gate int fd, request; 3357c478bd9Sstevel@tonic-gate #endif 3367c478bd9Sstevel@tonic-gate { 3377c478bd9Sstevel@tonic-gate return (SUCCESS); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate /* 3417c478bd9Sstevel@tonic-gate * tsetup - tli setup routine 3427c478bd9Sstevel@tonic-gate * note blatant assumption that *fdreadp == *fdwritep == 0 3437c478bd9Sstevel@tonic-gate */ 3447c478bd9Sstevel@tonic-gate static int 3457c478bd9Sstevel@tonic-gate tsetup(role, fdreadp, fdwritep) 3467c478bd9Sstevel@tonic-gate int *fdreadp, *fdwritep; 3477c478bd9Sstevel@tonic-gate { 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate if (role == SLAVE) { 3507c478bd9Sstevel@tonic-gate *fdreadp = 0; 3517c478bd9Sstevel@tonic-gate *fdwritep = 1; 3527c478bd9Sstevel@tonic-gate /* 2 has been re-opened to RMTDEBUG in main() */ 3537c478bd9Sstevel@tonic-gate errno = t_errno = 0; 3547c478bd9Sstevel@tonic-gate if (t_sync(*fdreadp) == -1 || t_sync(*fdwritep) == -1) { 3557c478bd9Sstevel@tonic-gate tfaillog(*fdreadp, "tsetup: t_sync\n"); 3567c478bd9Sstevel@tonic-gate return (FAIL); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate } 3597c478bd9Sstevel@tonic-gate return (SUCCESS); 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate /* 3637c478bd9Sstevel@tonic-gate * tteardown - tli shutdown routine 3647c478bd9Sstevel@tonic-gate */ 3657c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3667c478bd9Sstevel@tonic-gate static int 3677c478bd9Sstevel@tonic-gate tteardown(role, fdread, fdwrite) 3687c478bd9Sstevel@tonic-gate { 3697c478bd9Sstevel@tonic-gate (void) t_unbind(fdread); 3707c478bd9Sstevel@tonic-gate (void) t_close(fdread); 3717c478bd9Sstevel@tonic-gate return (SUCCESS); 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate #ifdef TLIS 3757c478bd9Sstevel@tonic-gate /* 3767c478bd9Sstevel@tonic-gate * tssetup - tli, with streams module, setup routine 3777c478bd9Sstevel@tonic-gate * note blatant assumption that *fdreadp == *fdwritep 3787c478bd9Sstevel@tonic-gate */ 3797c478bd9Sstevel@tonic-gate static int 3807c478bd9Sstevel@tonic-gate tssetup(role, fdreadp, fdwritep) 3817c478bd9Sstevel@tonic-gate int role; 3827c478bd9Sstevel@tonic-gate int *fdreadp; 3837c478bd9Sstevel@tonic-gate int *fdwritep; 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate if (role == SLAVE) { 3867c478bd9Sstevel@tonic-gate *fdreadp = 0; 3877c478bd9Sstevel@tonic-gate *fdwritep = 1; 3887c478bd9Sstevel@tonic-gate /* 2 has been re-opened to RMTDEBUG in main() */ 3897c478bd9Sstevel@tonic-gate DEBUG(5, "tssetup: SLAVE mode: leaving ok\n%s", ""); 3907c478bd9Sstevel@tonic-gate return (SUCCESS); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate DEBUG(4, "tssetup: MASTER mode: leaving ok\n%s", ""); 3947c478bd9Sstevel@tonic-gate return (SUCCESS); 3957c478bd9Sstevel@tonic-gate } 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate /* 3987c478bd9Sstevel@tonic-gate * Report why a TLI call failed. 3997c478bd9Sstevel@tonic-gate */ 4007c478bd9Sstevel@tonic-gate GLOBAL void 4017c478bd9Sstevel@tonic-gate tfaillog(fd, s) 4027c478bd9Sstevel@tonic-gate int fd; 4037c478bd9Sstevel@tonic-gate char *s; 4047c478bd9Sstevel@tonic-gate { 4057c478bd9Sstevel@tonic-gate char fmt[ BUFSIZ ]; 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate if (0 < t_errno && t_errno < t_nerr) { 4087c478bd9Sstevel@tonic-gate sprintf(fmt, "%s: %%s\n", s); 4097c478bd9Sstevel@tonic-gate DEBUG(5, fmt, t_errlist[t_errno]); 4107c478bd9Sstevel@tonic-gate logent(s, t_errlist[t_errno]); 4117c478bd9Sstevel@tonic-gate if (t_errno == TSYSERR) { 4127c478bd9Sstevel@tonic-gate strcpy(fmt, "tlicall: system error: %s\n"); 413ace1a5f1Sdp DEBUG(5, fmt, strerror(errno)); 4147c478bd9Sstevel@tonic-gate } else if (t_errno == TLOOK) { 4157c478bd9Sstevel@tonic-gate show_tlook(fd); 4167c478bd9Sstevel@tonic-gate } 4177c478bd9Sstevel@tonic-gate } else { 4187c478bd9Sstevel@tonic-gate sprintf(fmt, "unknown tli error %d", t_errno); 4197c478bd9Sstevel@tonic-gate logent(s, fmt); 4207c478bd9Sstevel@tonic-gate sprintf(fmt, "%s: unknown tli error %d", s, t_errno); 4217c478bd9Sstevel@tonic-gate DEBUG(5, fmt, 0); 4227c478bd9Sstevel@tonic-gate sprintf(fmt, "%s: %%s\n", s); 423ace1a5f1Sdp DEBUG(5, fmt, strerror(errno)); 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate } 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate GLOBAL void 4287c478bd9Sstevel@tonic-gate show_tlook(fd) 4297c478bd9Sstevel@tonic-gate int fd; 4307c478bd9Sstevel@tonic-gate { 4317c478bd9Sstevel@tonic-gate register int reason; 4327c478bd9Sstevel@tonic-gate register char *msg; 4337c478bd9Sstevel@tonic-gate extern int t_errno; 4347c478bd9Sstevel@tonic-gate /* 4357c478bd9Sstevel@tonic-gate * Find out the current state of the interface. 4367c478bd9Sstevel@tonic-gate */ 4377c478bd9Sstevel@tonic-gate errno = t_errno = 0; 4387c478bd9Sstevel@tonic-gate switch (reason = t_getstate(fd)) { 4397c478bd9Sstevel@tonic-gate case T_UNBND: msg = "T_UNBIND"; break; 4407c478bd9Sstevel@tonic-gate case T_IDLE: msg = "T_IDLE"; break; 4417c478bd9Sstevel@tonic-gate case T_OUTCON: msg = "T_OUTCON"; break; 4427c478bd9Sstevel@tonic-gate case T_INCON: msg = "T_INCON"; break; 4437c478bd9Sstevel@tonic-gate case T_DATAXFER: msg = "T_DATAXFER"; break; 4447c478bd9Sstevel@tonic-gate case T_OUTREL: msg = "T_OUTREL"; break; 4457c478bd9Sstevel@tonic-gate case T_INREL: msg = "T_INREL"; break; 4467c478bd9Sstevel@tonic-gate default: msg = NULL; break; 4477c478bd9Sstevel@tonic-gate } 4487c478bd9Sstevel@tonic-gate if (msg == NULL) 4497c478bd9Sstevel@tonic-gate return; 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate DEBUG(5, "state is %s", msg); 4527c478bd9Sstevel@tonic-gate switch (reason = t_look(fd)) { 4537c478bd9Sstevel@tonic-gate case -1: msg = ""; break; 4547c478bd9Sstevel@tonic-gate case 0: msg = "NO ERROR"; break; 4557c478bd9Sstevel@tonic-gate case T_LISTEN: msg = "T_LISTEN"; break; 4567c478bd9Sstevel@tonic-gate case T_CONNECT: msg = "T_CONNECT"; break; 4577c478bd9Sstevel@tonic-gate case T_DATA: msg = "T_DATA"; break; 4587c478bd9Sstevel@tonic-gate case T_EXDATA: msg = "T_EXDATA"; break; 4597c478bd9Sstevel@tonic-gate case T_DISCONNECT: msg = "T_DISCONNECT"; break; 4607c478bd9Sstevel@tonic-gate case T_ORDREL: msg = "T_ORDREL"; break; 4617c478bd9Sstevel@tonic-gate case T_UDERR: msg = "T_UDERR"; break; 4627c478bd9Sstevel@tonic-gate default: msg = "UNKNOWN ERROR"; break; 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate DEBUG(4, " reason is %s\n", msg); 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate if (reason == T_DISCONNECT) 4677c478bd9Sstevel@tonic-gate { 4687c478bd9Sstevel@tonic-gate struct t_discon *dropped; 4697c478bd9Sstevel@tonic-gate if (((dropped = 470*09b0d01cSGary Mills (struct t_discon *)t_alloc(fd, T_DIS, T_ALL)) == 0) || 471*09b0d01cSGary Mills (t_rcvdis(fd, dropped) == -1)) { 4727c478bd9Sstevel@tonic-gate if (dropped) 4737c478bd9Sstevel@tonic-gate t_free((char *)dropped, T_DIS); 4747c478bd9Sstevel@tonic-gate return; 4757c478bd9Sstevel@tonic-gate } 4767c478bd9Sstevel@tonic-gate DEBUG(5, "disconnect reason #%d\n", dropped->reason); 4777c478bd9Sstevel@tonic-gate t_free((char *)dropped, T_DIS); 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate } 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate #endif /* TLIS */ 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate #endif /* TLI */ 484