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 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate /* This is a new line.c, which consists of line.c and culine.c 29*7c478bd9Sstevel@tonic-gate * merged together. 30*7c478bd9Sstevel@tonic-gate */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include "uucp.h" 33*7c478bd9Sstevel@tonic-gate #include <rpc/trace.h> 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate static const struct sg_spds { 36*7c478bd9Sstevel@tonic-gate int sp_val, 37*7c478bd9Sstevel@tonic-gate sp_name; 38*7c478bd9Sstevel@tonic-gate } spds[] = { 39*7c478bd9Sstevel@tonic-gate { 50, B50}, 40*7c478bd9Sstevel@tonic-gate { 75, B75}, 41*7c478bd9Sstevel@tonic-gate { 110, B110}, 42*7c478bd9Sstevel@tonic-gate { 134, B134}, 43*7c478bd9Sstevel@tonic-gate { 150, B150}, 44*7c478bd9Sstevel@tonic-gate { 200, B200}, 45*7c478bd9Sstevel@tonic-gate { 300, B300}, 46*7c478bd9Sstevel@tonic-gate { 600, B600}, 47*7c478bd9Sstevel@tonic-gate {1200, B1200}, 48*7c478bd9Sstevel@tonic-gate {1800, B1800}, 49*7c478bd9Sstevel@tonic-gate {2400, B2400}, 50*7c478bd9Sstevel@tonic-gate {4800, B4800}, 51*7c478bd9Sstevel@tonic-gate {9600, B9600}, 52*7c478bd9Sstevel@tonic-gate #ifdef EXTA 53*7c478bd9Sstevel@tonic-gate {19200, EXTA}, 54*7c478bd9Sstevel@tonic-gate #endif 55*7c478bd9Sstevel@tonic-gate #ifdef B19200 56*7c478bd9Sstevel@tonic-gate {19200, B19200}, 57*7c478bd9Sstevel@tonic-gate #endif 58*7c478bd9Sstevel@tonic-gate #ifdef B38400 59*7c478bd9Sstevel@tonic-gate {38400, B38400}, 60*7c478bd9Sstevel@tonic-gate #endif 61*7c478bd9Sstevel@tonic-gate {57600, B57600}, 62*7c478bd9Sstevel@tonic-gate {76800, B76800}, 63*7c478bd9Sstevel@tonic-gate {115200, B115200}, 64*7c478bd9Sstevel@tonic-gate {153600, B153600}, 65*7c478bd9Sstevel@tonic-gate {230400, B230400}, 66*7c478bd9Sstevel@tonic-gate {307200, B307200}, 67*7c478bd9Sstevel@tonic-gate {460800, B460800}, 68*7c478bd9Sstevel@tonic-gate {0, 0} 69*7c478bd9Sstevel@tonic-gate }; 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate #define PACKSIZE 64 72*7c478bd9Sstevel@tonic-gate #define HEADERSIZE 6 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate GLOBAL int 75*7c478bd9Sstevel@tonic-gate packsize = PACKSIZE, 76*7c478bd9Sstevel@tonic-gate xpacksize = PACKSIZE; 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate #define SNDFILE 'S' 79*7c478bd9Sstevel@tonic-gate #define RCVFILE 'R' 80*7c478bd9Sstevel@tonic-gate #define RESET 'X' 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate GLOBAL int donap; /* for speedup hook in pk1.c */ 83*7c478bd9Sstevel@tonic-gate static int Saved_line; /* was savline() successful? */ 84*7c478bd9Sstevel@tonic-gate static int Saved_termios; /* was termios saved? */ 85*7c478bd9Sstevel@tonic-gate GLOBAL int 86*7c478bd9Sstevel@tonic-gate Oddflag, /* Default is no parity */ 87*7c478bd9Sstevel@tonic-gate Evenflag, /* Default is no parity */ 88*7c478bd9Sstevel@tonic-gate Duplex = 1, /* Default is full duplex */ 89*7c478bd9Sstevel@tonic-gate Terminal, /* Default is no terminal */ 90*7c478bd9Sstevel@tonic-gate term_8bit = -1, /* Default to terminal setting or 8 bit */ 91*7c478bd9Sstevel@tonic-gate line_8bit = -1; /* Default is same as terminal */ 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate static const char P_PARITY[] = "Parity option error\r\n"; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate #ifdef ATTSV 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate static struct termio Savettyb; 98*7c478bd9Sstevel@tonic-gate static struct termios Savettybs; 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * set speed/echo/mode... 101*7c478bd9Sstevel@tonic-gate * tty -> terminal name 102*7c478bd9Sstevel@tonic-gate * spwant -> speed 103*7c478bd9Sstevel@tonic-gate * type -> type 104*7c478bd9Sstevel@tonic-gate * 105*7c478bd9Sstevel@tonic-gate * if spwant == 0, speed is untouched 106*7c478bd9Sstevel@tonic-gate * type is unused, but needed for compatibility 107*7c478bd9Sstevel@tonic-gate * 108*7c478bd9Sstevel@tonic-gate * return: 109*7c478bd9Sstevel@tonic-gate * none 110*7c478bd9Sstevel@tonic-gate */ 111*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 112*7c478bd9Sstevel@tonic-gate GLOBAL void 113*7c478bd9Sstevel@tonic-gate fixline(tty, spwant, type) 114*7c478bd9Sstevel@tonic-gate int tty, spwant, type; 115*7c478bd9Sstevel@tonic-gate { 116*7c478bd9Sstevel@tonic-gate register const struct sg_spds *ps; 117*7c478bd9Sstevel@tonic-gate struct termio ttbuf; 118*7c478bd9Sstevel@tonic-gate struct termios ttbufs; 119*7c478bd9Sstevel@tonic-gate int speed = -1; 120*7c478bd9Sstevel@tonic-gate int i, istermios, ospeed; 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate trace4(TR_fixline, 0, tty, spwant, type); 123*7c478bd9Sstevel@tonic-gate DEBUG(6, "fixline(%d, ", tty); 124*7c478bd9Sstevel@tonic-gate DEBUG(6, "%d)\n", spwant); 125*7c478bd9Sstevel@tonic-gate if ((istermios = (*Ioctl)(tty, TCGETS, &ttbufs)) < 0) { 126*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(tty, TCGETA, &ttbuf) != 0) { 127*7c478bd9Sstevel@tonic-gate trace1(TR_fixline, 1); 128*7c478bd9Sstevel@tonic-gate return; 129*7c478bd9Sstevel@tonic-gate } else { 130*7c478bd9Sstevel@tonic-gate ttbufs.c_lflag = ttbuf.c_lflag; 131*7c478bd9Sstevel@tonic-gate ttbufs.c_oflag = ttbuf.c_oflag; 132*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag = ttbuf.c_iflag; 133*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag = ttbuf.c_cflag; 134*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 135*7c478bd9Sstevel@tonic-gate ttbufs.c_cc[i] = ttbuf.c_cc[i]; 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate } 138*7c478bd9Sstevel@tonic-gate if (spwant > 0) { 139*7c478bd9Sstevel@tonic-gate for (ps = spds; ps->sp_val; ps++) 140*7c478bd9Sstevel@tonic-gate if (ps->sp_val == spwant) { 141*7c478bd9Sstevel@tonic-gate speed = ps->sp_name; 142*7c478bd9Sstevel@tonic-gate break; 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate if (speed < 0) { 145*7c478bd9Sstevel@tonic-gate /*EMPTY*/ 146*7c478bd9Sstevel@tonic-gate DEBUG(5, "speed (%d) not supported\n", spwant); 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate ASSERT(speed >= 0, "BAD SPEED", "", spwant); 149*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag &= 0xffff0000; 150*7c478bd9Sstevel@tonic-gate cfsetospeed(&ttbufs, speed); 151*7c478bd9Sstevel@tonic-gate } else { /* determine the current speed setting */ 152*7c478bd9Sstevel@tonic-gate ospeed = cfgetospeed(&ttbufs); 153*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag &= 0xffff0000; 154*7c478bd9Sstevel@tonic-gate cfsetospeed(&ttbufs, ospeed); 155*7c478bd9Sstevel@tonic-gate for (ps = spds; ps->sp_val; ps++) 156*7c478bd9Sstevel@tonic-gate if (ps->sp_name == ospeed) { 157*7c478bd9Sstevel@tonic-gate spwant = ps->sp_val; 158*7c478bd9Sstevel@tonic-gate break; 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate } 161*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag &= 0xffff0000; 162*7c478bd9Sstevel@tonic-gate ttbufs.c_oflag &= 0xffff0000; 163*7c478bd9Sstevel@tonic-gate ttbufs.c_lflag &= 0xffff0000; 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate #ifdef NO_MODEM_CTRL 166*7c478bd9Sstevel@tonic-gate /* CLOCAL may cause problems on pdp11s with DHs */ 167*7c478bd9Sstevel@tonic-gate if (type == D_DIRECT) { 168*7c478bd9Sstevel@tonic-gate DEBUG(4, "fixline - direct\n%s", ""); 169*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= CLOCAL; 170*7c478bd9Sstevel@tonic-gate } else 171*7c478bd9Sstevel@tonic-gate #endif /* NO_MODEM_CTRL */ 172*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag &= ~CLOCAL; 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate if (EQUALS(Progname, "cu")) { 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate /* set attributes associated with -h, -t, -e, and -o options */ 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag = (IGNPAR | IGNBRK | IXON | IXOFF); 179*7c478bd9Sstevel@tonic-gate if (line_8bit) { 180*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= CS8; 181*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag &= ~ISTRIP; 182*7c478bd9Sstevel@tonic-gate } else { 183*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= CS7; 184*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag |= ISTRIP; 185*7c478bd9Sstevel@tonic-gate } 186*7c478bd9Sstevel@tonic-gate 187*7c478bd9Sstevel@tonic-gate ttbufs.c_cc[VEOF] = '\1'; 188*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= (CREAD | (speed ? HUPCL : 0)); 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate if (Evenflag) { /*even parity -e */ 191*7c478bd9Sstevel@tonic-gate if (ttbufs.c_cflag & PARENB) { 192*7c478bd9Sstevel@tonic-gate VERBOSE(P_PARITY, 0); 193*7c478bd9Sstevel@tonic-gate trace1(TR_fixline, 1); 194*7c478bd9Sstevel@tonic-gate exit (1); 195*7c478bd9Sstevel@tonic-gate } else 196*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= PARENB; 197*7c478bd9Sstevel@tonic-gate } else if (Oddflag) { /*odd parity -o */ 198*7c478bd9Sstevel@tonic-gate if (ttbufs.c_cflag & PARENB) { 199*7c478bd9Sstevel@tonic-gate VERBOSE(P_PARITY, 0); 200*7c478bd9Sstevel@tonic-gate trace1(TR_fixline, 1); 201*7c478bd9Sstevel@tonic-gate exit (1); 202*7c478bd9Sstevel@tonic-gate } else { 203*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= PARODD; 204*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= PARENB; 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate if (!Duplex) /*half duplex -h */ 209*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag &= ~(IXON | IXOFF); 210*7c478bd9Sstevel@tonic-gate if (Terminal) /* -t */ 211*7c478bd9Sstevel@tonic-gate ttbufs.c_oflag |= (OPOST | ONLCR); 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate } else { /* non-cu */ 214*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= (CS8 | CREAD | (speed ? HUPCL : 0)); 215*7c478bd9Sstevel@tonic-gate ttbufs.c_cc[VMIN] = HEADERSIZE; 216*7c478bd9Sstevel@tonic-gate ttbufs.c_cc[VTIME] = 1; 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate donap = (spwant > 0 && spwant < 4800); 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate if (istermios < 0) { 222*7c478bd9Sstevel@tonic-gate ttbuf.c_lflag = ttbufs.c_lflag; 223*7c478bd9Sstevel@tonic-gate ttbuf.c_oflag = ttbufs.c_oflag; 224*7c478bd9Sstevel@tonic-gate ttbuf.c_iflag = ttbufs.c_iflag; 225*7c478bd9Sstevel@tonic-gate ttbuf.c_cflag = ttbufs.c_cflag; 226*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 227*7c478bd9Sstevel@tonic-gate ttbuf.c_cc[i] = ttbufs.c_cc[i]; 228*7c478bd9Sstevel@tonic-gate ASSERT((*Ioctl)(tty, TCSETAW, &ttbuf) >= 0, 229*7c478bd9Sstevel@tonic-gate "RETURN FROM fixline ioctl", "", errno); 230*7c478bd9Sstevel@tonic-gate } else { 231*7c478bd9Sstevel@tonic-gate ASSERT((*Ioctl)(tty, TCSETSW, &ttbufs) >= 0, 232*7c478bd9Sstevel@tonic-gate "RETURN FROM fixline ioctl", "", errno); 233*7c478bd9Sstevel@tonic-gate } 234*7c478bd9Sstevel@tonic-gate trace1(TR_fixline, 1); 235*7c478bd9Sstevel@tonic-gate return; 236*7c478bd9Sstevel@tonic-gate } 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate GLOBAL void 239*7c478bd9Sstevel@tonic-gate sethup(dcf) 240*7c478bd9Sstevel@tonic-gate int dcf; 241*7c478bd9Sstevel@tonic-gate { 242*7c478bd9Sstevel@tonic-gate struct termio ttbuf; 243*7c478bd9Sstevel@tonic-gate 244*7c478bd9Sstevel@tonic-gate trace2(TR_sethup, 0, dcf); 245*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(dcf, TCGETA, &ttbuf) != 0) { 246*7c478bd9Sstevel@tonic-gate trace1(TR_sethup, 1); 247*7c478bd9Sstevel@tonic-gate return; 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate if (!(ttbuf.c_cflag & HUPCL)) { 250*7c478bd9Sstevel@tonic-gate ttbuf.c_cflag |= HUPCL; 251*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(dcf, TCSETAW, &ttbuf); 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate trace1(TR_sethup, 1); 254*7c478bd9Sstevel@tonic-gate return; 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate GLOBAL void 258*7c478bd9Sstevel@tonic-gate ttygenbrk(fn) 259*7c478bd9Sstevel@tonic-gate register int fn; 260*7c478bd9Sstevel@tonic-gate { 261*7c478bd9Sstevel@tonic-gate trace2(TR_ttygenbrk, 0, fn); 262*7c478bd9Sstevel@tonic-gate if (isatty(fn)) 263*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(fn, TCSBRK, 0); 264*7c478bd9Sstevel@tonic-gate trace1(TR_ttygenbrk, 1); 265*7c478bd9Sstevel@tonic-gate return; 266*7c478bd9Sstevel@tonic-gate } 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate #ifndef DIAL 270*7c478bd9Sstevel@tonic-gate /* 271*7c478bd9Sstevel@tonic-gate * optimize line setting for sending or receiving files 272*7c478bd9Sstevel@tonic-gate * return: 273*7c478bd9Sstevel@tonic-gate * none 274*7c478bd9Sstevel@tonic-gate */ 275*7c478bd9Sstevel@tonic-gate GLOBAL void 276*7c478bd9Sstevel@tonic-gate setline(type) 277*7c478bd9Sstevel@tonic-gate register char type; 278*7c478bd9Sstevel@tonic-gate { 279*7c478bd9Sstevel@tonic-gate static struct termio tbuf; 280*7c478bd9Sstevel@tonic-gate static struct termios tbufs; 281*7c478bd9Sstevel@tonic-gate int i, vtime, istermios, ospeed; 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate trace1(TR_setline, 0); 284*7c478bd9Sstevel@tonic-gate DEBUG(2, "setline - %c\n", type); 285*7c478bd9Sstevel@tonic-gate if ((istermios = (*Ioctl)(Ifn, TCGETS, &tbufs)) < 0) { 286*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(Ifn, TCGETA, &tbuf) != 0) { 287*7c478bd9Sstevel@tonic-gate trace1(TR_setline, 1); 288*7c478bd9Sstevel@tonic-gate return; 289*7c478bd9Sstevel@tonic-gate } else { 290*7c478bd9Sstevel@tonic-gate tbufs.c_lflag = tbuf.c_lflag; 291*7c478bd9Sstevel@tonic-gate tbufs.c_oflag = tbuf.c_oflag; 292*7c478bd9Sstevel@tonic-gate tbufs.c_iflag = tbuf.c_iflag; 293*7c478bd9Sstevel@tonic-gate tbufs.c_cflag = tbuf.c_cflag; 294*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 295*7c478bd9Sstevel@tonic-gate tbufs.c_cc[i] = tbuf.c_cc[i]; 296*7c478bd9Sstevel@tonic-gate } 297*7c478bd9Sstevel@tonic-gate } 298*7c478bd9Sstevel@tonic-gate switch (type) { 299*7c478bd9Sstevel@tonic-gate case RCVFILE: 300*7c478bd9Sstevel@tonic-gate ospeed = cfgetospeed(&tbufs); 301*7c478bd9Sstevel@tonic-gate switch (ospeed) { 302*7c478bd9Sstevel@tonic-gate case B9600: 303*7c478bd9Sstevel@tonic-gate vtime = 1; 304*7c478bd9Sstevel@tonic-gate break; 305*7c478bd9Sstevel@tonic-gate case B4800: 306*7c478bd9Sstevel@tonic-gate vtime = 4; 307*7c478bd9Sstevel@tonic-gate break; 308*7c478bd9Sstevel@tonic-gate default: 309*7c478bd9Sstevel@tonic-gate vtime = 8; 310*7c478bd9Sstevel@tonic-gate break; 311*7c478bd9Sstevel@tonic-gate } 312*7c478bd9Sstevel@tonic-gate if (tbufs.c_cc[VMIN] != packsize || 313*7c478bd9Sstevel@tonic-gate tbufs.c_cc[VTIME] != vtime) { 314*7c478bd9Sstevel@tonic-gate tbufs.c_cc[VMIN] = packsize; 315*7c478bd9Sstevel@tonic-gate tbufs.c_cc[VTIME] = vtime; 316*7c478bd9Sstevel@tonic-gate if (istermios < 0) { 317*7c478bd9Sstevel@tonic-gate tbuf.c_lflag = tbufs.c_lflag; 318*7c478bd9Sstevel@tonic-gate tbuf.c_oflag = tbufs.c_oflag; 319*7c478bd9Sstevel@tonic-gate tbuf.c_iflag = tbufs.c_iflag; 320*7c478bd9Sstevel@tonic-gate tbuf.c_cflag = tbufs.c_cflag; 321*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 322*7c478bd9Sstevel@tonic-gate tbuf.c_cc[i] = tbufs.c_cc[i]; 323*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(Ifn, TCSETAW, &tbuf) != 0) 324*7c478bd9Sstevel@tonic-gate DEBUG(4, "setline Ioctl failed errno=%d\n", errno); 325*7c478bd9Sstevel@tonic-gate } else { 326*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(Ifn, TCSETSW, &tbufs) != 0) 327*7c478bd9Sstevel@tonic-gate DEBUG(4, "setline Ioctl failed errno=%d\n", errno); 328*7c478bd9Sstevel@tonic-gate } 329*7c478bd9Sstevel@tonic-gate } 330*7c478bd9Sstevel@tonic-gate break; 331*7c478bd9Sstevel@tonic-gate 332*7c478bd9Sstevel@tonic-gate case SNDFILE: 333*7c478bd9Sstevel@tonic-gate case RESET: 334*7c478bd9Sstevel@tonic-gate if (tbufs.c_cc[VMIN] != HEADERSIZE) { 335*7c478bd9Sstevel@tonic-gate tbufs.c_cc[VMIN] = HEADERSIZE; 336*7c478bd9Sstevel@tonic-gate if (istermios < 0) { 337*7c478bd9Sstevel@tonic-gate tbuf.c_lflag = tbufs.c_lflag; 338*7c478bd9Sstevel@tonic-gate tbuf.c_oflag = tbufs.c_oflag; 339*7c478bd9Sstevel@tonic-gate tbuf.c_iflag = tbufs.c_iflag; 340*7c478bd9Sstevel@tonic-gate tbuf.c_cflag = tbufs.c_cflag; 341*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 342*7c478bd9Sstevel@tonic-gate tbuf.c_cc[i] = tbufs.c_cc[i]; 343*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(Ifn, TCSETAW, &tbuf) != 0) 344*7c478bd9Sstevel@tonic-gate DEBUG(4, "setline Ioctl failed errno=%d\n", errno); 345*7c478bd9Sstevel@tonic-gate } else { 346*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(Ifn, TCSETSW, &tbufs) != 0) 347*7c478bd9Sstevel@tonic-gate DEBUG(4, "setline Ioctl failed errno=%d\n", errno); 348*7c478bd9Sstevel@tonic-gate } 349*7c478bd9Sstevel@tonic-gate } 350*7c478bd9Sstevel@tonic-gate break; 351*7c478bd9Sstevel@tonic-gate } 352*7c478bd9Sstevel@tonic-gate trace1(TR_setline, 1); 353*7c478bd9Sstevel@tonic-gate return; 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate #endif 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate GLOBAL int 358*7c478bd9Sstevel@tonic-gate savline() 359*7c478bd9Sstevel@tonic-gate { 360*7c478bd9Sstevel@tonic-gate trace1(TR_savline, 0); 361*7c478bd9Sstevel@tonic-gate if ((Saved_termios = (*Ioctl)(0, TCGETS, &Savettybs)) < 0) { 362*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(0, TCGETA, &Savettyb) != 0) { 363*7c478bd9Sstevel@tonic-gate Saved_line = FALSE; 364*7c478bd9Sstevel@tonic-gate } else { 365*7c478bd9Sstevel@tonic-gate Saved_line = TRUE; 366*7c478bd9Sstevel@tonic-gate Savettyb.c_cflag = (Savettyb.c_cflag & ~CS8) | CS7; 367*7c478bd9Sstevel@tonic-gate Savettyb.c_oflag |= OPOST; 368*7c478bd9Sstevel@tonic-gate Savettyb.c_lflag |= (ISIG|ICANON|ECHO); 369*7c478bd9Sstevel@tonic-gate } 370*7c478bd9Sstevel@tonic-gate } else { 371*7c478bd9Sstevel@tonic-gate Saved_line = TRUE; 372*7c478bd9Sstevel@tonic-gate Savettybs.c_cflag = (Savettybs.c_cflag & ~CS8) | CS7; 373*7c478bd9Sstevel@tonic-gate Savettybs.c_oflag |= OPOST; 374*7c478bd9Sstevel@tonic-gate Savettybs.c_lflag |= (ISIG|ICANON|ECHO); 375*7c478bd9Sstevel@tonic-gate } 376*7c478bd9Sstevel@tonic-gate trace1(TR_savline, 1); 377*7c478bd9Sstevel@tonic-gate return (0); 378*7c478bd9Sstevel@tonic-gate } 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate #ifdef SYTEK 381*7c478bd9Sstevel@tonic-gate 382*7c478bd9Sstevel@tonic-gate /* 383*7c478bd9Sstevel@tonic-gate * sytfixline(tty, spwant) set speed/echo/mode... 384*7c478bd9Sstevel@tonic-gate * int tty, spwant; 385*7c478bd9Sstevel@tonic-gate * 386*7c478bd9Sstevel@tonic-gate * return codes: none 387*7c478bd9Sstevel@tonic-gate */ 388*7c478bd9Sstevel@tonic-gate 389*7c478bd9Sstevel@tonic-gate GLOBAL void 390*7c478bd9Sstevel@tonic-gate sytfixline(tty, spwant) 391*7c478bd9Sstevel@tonic-gate int tty, spwant; 392*7c478bd9Sstevel@tonic-gate { 393*7c478bd9Sstevel@tonic-gate struct termio ttbuf; 394*7c478bd9Sstevel@tonic-gate struct termios ttbufs; 395*7c478bd9Sstevel@tonic-gate const struct sg_spds *ps; 396*7c478bd9Sstevel@tonic-gate int speed = -1; 397*7c478bd9Sstevel@tonic-gate int i, ret, istermios; 398*7c478bd9Sstevel@tonic-gate 399*7c478bd9Sstevel@tonic-gate trace3(TR_sytfixline, 0, tty, spwant); 400*7c478bd9Sstevel@tonic-gate if ((istermios = (*Ioctl)(tty, TCGETS, &ttbufs)) < 0) { 401*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(tty, TCGETA, &ttbuf) != 0) { 402*7c478bd9Sstevel@tonic-gate trace1(TR_sytfixline, 1); 403*7c478bd9Sstevel@tonic-gate return; 404*7c478bd9Sstevel@tonic-gate } else { 405*7c478bd9Sstevel@tonic-gate ttbufs.c_lflag = ttbuf.c_lflag; 406*7c478bd9Sstevel@tonic-gate ttbufs.c_oflag = ttbuf.c_oflag; 407*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag = ttbuf.c_iflag; 408*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag = ttbuf.c_cflag; 409*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 410*7c478bd9Sstevel@tonic-gate ttbufs.c_cc[i] = ttbuf.c_cc[i]; 411*7c478bd9Sstevel@tonic-gate } 412*7c478bd9Sstevel@tonic-gate } 413*7c478bd9Sstevel@tonic-gate for (ps = spds; ps->sp_val >= 0; ps++) 414*7c478bd9Sstevel@tonic-gate if (ps->sp_val == spwant) 415*7c478bd9Sstevel@tonic-gate speed = ps->sp_name; 416*7c478bd9Sstevel@tonic-gate DEBUG(4, "sytfixline - speed= %d\n", speed); 417*7c478bd9Sstevel@tonic-gate ASSERT(speed >= 0, "BAD SPEED", "", spwant); 418*7c478bd9Sstevel@tonic-gate ttbufs.c_iflag &= 0xffff0000; 419*7c478bd9Sstevel@tonic-gate ttbufs.c_oflag &= 0xffff0000; 420*7c478bd9Sstevel@tonic-gate ttbufs.c_lflag &= 0xffff0000; 421*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag &= 0xffff0000; 422*7c478bd9Sstevel@tonic-gate cfsetospeed(&ttbufs, speed); 423*7c478bd9Sstevel@tonic-gate ttbufs.c_cflag |= (CS8|CLOCAL); 424*7c478bd9Sstevel@tonic-gate ttbufs.c_cc[VMIN] = 6; 425*7c478bd9Sstevel@tonic-gate ttbufs.c_cc[VTIME] = 1; 426*7c478bd9Sstevel@tonic-gate if (istermios < 0) { 427*7c478bd9Sstevel@tonic-gate ttbuf.c_lflag = ttbufs.c_lflag; 428*7c478bd9Sstevel@tonic-gate ttbuf.c_oflag = ttbufs.c_oflag; 429*7c478bd9Sstevel@tonic-gate ttbuf.c_iflag = ttbufs.c_iflag; 430*7c478bd9Sstevel@tonic-gate ttbuf.c_cflag = ttbufs.c_cflag; 431*7c478bd9Sstevel@tonic-gate for(i = 0; i < NCC; i++) 432*7c478bd9Sstevel@tonic-gate ttbuf.c_cc[i] = ttbufs.c_cc[i]; 433*7c478bd9Sstevel@tonic-gate ret = (*Ioctl)(tty, TCSETAW, &ttbuf); 434*7c478bd9Sstevel@tonic-gate } else 435*7c478bd9Sstevel@tonic-gate ret = (*Ioctl)(tty, TCSETSW, &ttbufs); 436*7c478bd9Sstevel@tonic-gate 437*7c478bd9Sstevel@tonic-gate ASSERT(ret >= 0, "RETURN FROM sytfixline", "", ret); 438*7c478bd9Sstevel@tonic-gate trace1(TR_sytfixline, 1); 439*7c478bd9Sstevel@tonic-gate return; 440*7c478bd9Sstevel@tonic-gate } 441*7c478bd9Sstevel@tonic-gate 442*7c478bd9Sstevel@tonic-gate GLOBAL void 443*7c478bd9Sstevel@tonic-gate sytfix2line(tty) 444*7c478bd9Sstevel@tonic-gate int tty; 445*7c478bd9Sstevel@tonic-gate { 446*7c478bd9Sstevel@tonic-gate struct termio ttbuf; 447*7c478bd9Sstevel@tonic-gate int ret; 448*7c478bd9Sstevel@tonic-gate 449*7c478bd9Sstevel@tonic-gate trace2(TR_sytfix2line, 0, tty); 450*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(tty, TCGETA, &ttbuf) != 0) { 451*7c478bd9Sstevel@tonic-gate trace1(TR_sytfix2line, 1); 452*7c478bd9Sstevel@tonic-gate return; 453*7c478bd9Sstevel@tonic-gate } 454*7c478bd9Sstevel@tonic-gate ttbuf.c_cflag &= ~CLOCAL; 455*7c478bd9Sstevel@tonic-gate ttbuf.c_cflag |= CREAD|HUPCL; 456*7c478bd9Sstevel@tonic-gate ret = (*Ioctl)(tty, TCSETAW, &ttbuf); 457*7c478bd9Sstevel@tonic-gate ASSERT(ret >= 0, "RETURN FROM sytfix2line", "", ret); 458*7c478bd9Sstevel@tonic-gate trace1(TR_sytfix2line, 1); 459*7c478bd9Sstevel@tonic-gate return; 460*7c478bd9Sstevel@tonic-gate } 461*7c478bd9Sstevel@tonic-gate 462*7c478bd9Sstevel@tonic-gate #endif /* SYTEK */ 463*7c478bd9Sstevel@tonic-gate 464*7c478bd9Sstevel@tonic-gate GLOBAL int 465*7c478bd9Sstevel@tonic-gate restline() 466*7c478bd9Sstevel@tonic-gate { 467*7c478bd9Sstevel@tonic-gate trace1(TR_restline, 0); 468*7c478bd9Sstevel@tonic-gate if (Saved_line == TRUE) { 469*7c478bd9Sstevel@tonic-gate trace1(TR_restline, 1); 470*7c478bd9Sstevel@tonic-gate if (Saved_termios < 0) 471*7c478bd9Sstevel@tonic-gate return ((*Ioctl)(0, TCSETAW, &Savettyb)); 472*7c478bd9Sstevel@tonic-gate else 473*7c478bd9Sstevel@tonic-gate return ((*Ioctl)(0, TCSETSW, &Savettybs)); 474*7c478bd9Sstevel@tonic-gate } 475*7c478bd9Sstevel@tonic-gate trace1(TR_restline, 1); 476*7c478bd9Sstevel@tonic-gate return (0); 477*7c478bd9Sstevel@tonic-gate } 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate #else /* !ATTSV */ 480*7c478bd9Sstevel@tonic-gate 481*7c478bd9Sstevel@tonic-gate static struct sgttyb Savettyb; 482*7c478bd9Sstevel@tonic-gate 483*7c478bd9Sstevel@tonic-gate /* 484*7c478bd9Sstevel@tonic-gate * fixline(tty, spwant, type) set speed/echo/mode... 485*7c478bd9Sstevel@tonic-gate * int tty, spwant; 486*7c478bd9Sstevel@tonic-gate * 487*7c478bd9Sstevel@tonic-gate * if spwant == 0, speed is untouched 488*7c478bd9Sstevel@tonic-gate * type is unused, but needed for compatibility 489*7c478bd9Sstevel@tonic-gate * 490*7c478bd9Sstevel@tonic-gate * return codes: none 491*7c478bd9Sstevel@tonic-gate */ 492*7c478bd9Sstevel@tonic-gate 493*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 494*7c478bd9Sstevel@tonic-gate GLOBAL void 495*7c478bd9Sstevel@tonic-gate fixline(tty, spwant, type) 496*7c478bd9Sstevel@tonic-gate int tty, spwant, type; 497*7c478bd9Sstevel@tonic-gate { 498*7c478bd9Sstevel@tonic-gate struct sgttyb ttbuf; 499*7c478bd9Sstevel@tonic-gate struct sg_spds *ps; 500*7c478bd9Sstevel@tonic-gate int speed = -1; 501*7c478bd9Sstevel@tonic-gate 502*7c478bd9Sstevel@tonic-gate trace4(TR_fixline, 0, tty, spwant, type); 503*7c478bd9Sstevel@tonic-gate DEBUG(6, "fixline(%d, ", tty); 504*7c478bd9Sstevel@tonic-gate DEBUG(6, "%d)\n", spwant); 505*7c478bd9Sstevel@tonic-gate 506*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(tty, TIOCGETP, &ttbuf) != 0) { 507*7c478bd9Sstevel@tonic-gate trace1(TR_fixline, 1); 508*7c478bd9Sstevel@tonic-gate return; 509*7c478bd9Sstevel@tonic-gate } 510*7c478bd9Sstevel@tonic-gate if (spwant > 0) { 511*7c478bd9Sstevel@tonic-gate for (ps = spds; ps->sp_val; ps++) 512*7c478bd9Sstevel@tonic-gate if (ps->sp_val == spwant) { 513*7c478bd9Sstevel@tonic-gate speed = ps->sp_name; 514*7c478bd9Sstevel@tonic-gate break; 515*7c478bd9Sstevel@tonic-gate } 516*7c478bd9Sstevel@tonic-gate ASSERT(speed >= 0, "BAD SPEED", "", spwant); 517*7c478bd9Sstevel@tonic-gate ttbuf.sg_ispeed = ttbuf.sg_ospeed = speed; 518*7c478bd9Sstevel@tonic-gate } else { 519*7c478bd9Sstevel@tonic-gate for (ps = spds; ps->sp_val; ps++) 520*7c478bd9Sstevel@tonic-gate if (ps->sp_name == ttbuf.sg_ispeed) { 521*7c478bd9Sstevel@tonic-gate spwant = ps->sp_val; 522*7c478bd9Sstevel@tonic-gate break; 523*7c478bd9Sstevel@tonic-gate } 524*7c478bd9Sstevel@tonic-gate ASSERT(spwant >= 0, "BAD SPEED", "", ttbuf.sg_ispeed); 525*7c478bd9Sstevel@tonic-gate } 526*7c478bd9Sstevel@tonic-gate ttbuf.sg_flags = (ANYP | RAW); 527*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(tty, TIOCSETP, &ttbuf); 528*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(tty, TIOCHPCL, STBNULL); 529*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(tty, TIOCEXCL, STBNULL); 530*7c478bd9Sstevel@tonic-gate donap = (spwant > 0 && spwant < 4800); 531*7c478bd9Sstevel@tonic-gate trace1(TR_fixline, 1); 532*7c478bd9Sstevel@tonic-gate return; 533*7c478bd9Sstevel@tonic-gate } 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate GLOBAL void 536*7c478bd9Sstevel@tonic-gate sethup(dcf) 537*7c478bd9Sstevel@tonic-gate int dcf; 538*7c478bd9Sstevel@tonic-gate { 539*7c478bd9Sstevel@tonic-gate trace2(TR_sethup, 0, dcf); 540*7c478bd9Sstevel@tonic-gate if (isatty(dcf)) 541*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(dcf, TIOCHPCL, STBNULL); 542*7c478bd9Sstevel@tonic-gate trace1(TR_sethup, 1); 543*7c478bd9Sstevel@tonic-gate return; 544*7c478bd9Sstevel@tonic-gate } 545*7c478bd9Sstevel@tonic-gate 546*7c478bd9Sstevel@tonic-gate /* 547*7c478bd9Sstevel@tonic-gate * genbrk send a break 548*7c478bd9Sstevel@tonic-gate * 549*7c478bd9Sstevel@tonic-gate * return codes; none 550*7c478bd9Sstevel@tonic-gate */ 551*7c478bd9Sstevel@tonic-gate 552*7c478bd9Sstevel@tonic-gate GLOBAL void 553*7c478bd9Sstevel@tonic-gate ttygenbrk(fn) 554*7c478bd9Sstevel@tonic-gate { 555*7c478bd9Sstevel@tonic-gate trace1(TR_ttygenbrk, 0); 556*7c478bd9Sstevel@tonic-gate if (isatty(fn)) { 557*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(fn, TIOCSBRK, 0); 558*7c478bd9Sstevel@tonic-gate #ifndef V8 559*7c478bd9Sstevel@tonic-gate nap(HZ/10); /* 0.1 second break */ 560*7c478bd9Sstevel@tonic-gate (void) (*Ioctl)(fn, TIOCCBRK, 0); 561*7c478bd9Sstevel@tonic-gate #endif 562*7c478bd9Sstevel@tonic-gate } 563*7c478bd9Sstevel@tonic-gate trace1(TR_ttygenbrk, 1); 564*7c478bd9Sstevel@tonic-gate return; 565*7c478bd9Sstevel@tonic-gate } 566*7c478bd9Sstevel@tonic-gate 567*7c478bd9Sstevel@tonic-gate #ifndef DIAL 568*7c478bd9Sstevel@tonic-gate /* 569*7c478bd9Sstevel@tonic-gate * V7 and RT aren't smart enough for this -- linebaudrate is the best 570*7c478bd9Sstevel@tonic-gate * they can do. 571*7c478bd9Sstevel@tonic-gate */ 572*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 573*7c478bd9Sstevel@tonic-gate GLOBAL void 574*7c478bd9Sstevel@tonic-gate setline(dummy) 575*7c478bd9Sstevel@tonic-gate { 576*7c478bd9Sstevel@tonic-gate trace1(TR_setline, 0); 577*7c478bd9Sstevel@tonic-gate trace1(TR_setline, 1); 578*7c478bd9Sstevel@tonic-gate } 579*7c478bd9Sstevel@tonic-gate #endif 580*7c478bd9Sstevel@tonic-gate 581*7c478bd9Sstevel@tonic-gate GLOBAL int 582*7c478bd9Sstevel@tonic-gate savline() 583*7c478bd9Sstevel@tonic-gate { 584*7c478bd9Sstevel@tonic-gate trace1(TR_savline, 0); 585*7c478bd9Sstevel@tonic-gate if ((*Ioctl)(0, TIOCGETP, &Savettyb) != 0) { 586*7c478bd9Sstevel@tonic-gate Saved_line = FALSE; 587*7c478bd9Sstevel@tonic-gate else { 588*7c478bd9Sstevel@tonic-gate Saved_line = TRUE; 589*7c478bd9Sstevel@tonic-gate Savettyb.sg_flags |= ECHO; 590*7c478bd9Sstevel@tonic-gate Savettyb.sg_flags &= ~RAW; 591*7c478bd9Sstevel@tonic-gate } 592*7c478bd9Sstevel@tonic-gate trace1(TR_savline, 1); 593*7c478bd9Sstevel@tonic-gate return (0); 594*7c478bd9Sstevel@tonic-gate } 595*7c478bd9Sstevel@tonic-gate 596*7c478bd9Sstevel@tonic-gate GLOBAL int 597*7c478bd9Sstevel@tonic-gate restline() 598*7c478bd9Sstevel@tonic-gate { 599*7c478bd9Sstevel@tonic-gate trace1(TR_restline, 0); 600*7c478bd9Sstevel@tonic-gate if (Saved_line == TRUE) { 601*7c478bd9Sstevel@tonic-gate trace1(TR_restline, 1); 602*7c478bd9Sstevel@tonic-gate return ((*Ioctl)(0, TIOCSETP, &Savettyb)); 603*7c478bd9Sstevel@tonic-gate } 604*7c478bd9Sstevel@tonic-gate trace1(TR_restline, 1); 605*7c478bd9Sstevel@tonic-gate return (0); 606*7c478bd9Sstevel@tonic-gate } 607*7c478bd9Sstevel@tonic-gate #endif 608