|
|
1.1 ! root 1: /* ! 2: * dcpunix.c ! 3: * ! 4: * Coherent/Unix/Minix support for dcp ! 5: * Copyright 1989 (c) by Peter S. Housel. ! 6: * Changes Copyright (c) 1989-1991 by Mark Williams Company. ! 7: */ ! 8: ! 9: #include <stdio.h> ! 10: ! 11: #include <signal.h> ! 12: #include "dial.h" ! 13: #include "dcp.h" ! 14: #include "alarm.h" ! 15: ! 16: #if SGTTY ! 17: #include <sgtty.h> ! 18: #elif TERMIO ! 19: #include <termio.h> ! 20: #endif ! 21: ! 22: int swritefd; /* fd for serial write */ ! 23: int sreadfd; /* fd for serial read */ ! 24: ! 25: swrite(data, num) ! 26: char *data; ! 27: int num; ! 28: { ! 29: return( write(swritefd, data, num) ); ! 30: } ! 31: ! 32: #define MINTIMEOUT 2 ! 33: ! 34: int sread(data, num, timeout) ! 35: char *data; ! 36: int num, timeout; ! 37: { ! 38: int ret; ! 39: register char *ptr; ! 40: ! 41: SETALRM( (timeout>MINTIMEOUT) ? timeout: MINTIMEOUT ); ! 42: ret = read(sreadfd, data, num); ! 43: CLRALRM(); ! 44: ! 45: if ( stripflg ) ! 46: for (ptr=data; ptr<data+ret; ptr++) ! 47: *ptr &= 0x7F; ! 48: #if 0 ! 49: printmsg(M_DATA, "sread: {%s}", visbuf(data, num)); ! 50: #endif ! 51: return( (ret>0) ? ret: 0 ); ! 52: } ! 53: ! 54: int sread2(data, num) ! 55: char *data; ! 56: int num; ! 57: { ! 58: int retval = read(sreadfd, data, num); ! 59: register char *ptr; ! 60: ! 61: if ( stripflg ) ! 62: for (ptr=data; ptr<data+retval; ptr++) ! 63: *ptr &= 0x7F; ! 64: #if 0 ! 65: printmsg(M_DATA, "sread2: %d: {%s}", retval, visbuf(data, retval)); ! 66: #endif ! 67: return(retval); ! 68: } ! 69: ! 70: /* ! 71: * Coherent support for setting the line parameters. ! 72: * ! 73: * initline() -- Used for uucico SLAVE mode. ! 74: * Sets the serial file descriptors: sreadfd and swritefd. ! 75: * Returns (1) for success, (0) for failure. ! 76: * ! 77: * fixline() ! 78: * Fixes the line to RAW for uucico MASTER mode. ! 79: */ ! 80: ! 81: int initline() ! 82: { ! 83: #if SGTTY ! 84: struct sgttyb ttyb; ! 85: ! 86: sreadfd = 0; /* standard input */ ! 87: swritefd = 1; /* standard output */ ! 88: ioctl(sreadfd, TIOCHPCL); ! 89: gtty(sreadfd, &ttyb); /* set raw mode */ ! 90: ttyb.sg_flags |= (RAW | CBREAK); ! 91: stripflg = 0; ! 92: ttyb.sg_flags &= ~(XTABS | EVENP | ODDP | CRMOD | ECHO | LCASE); ! 93: stty(sreadfd, &ttyb); ! 94: ! 95: #elif TERMIO ! 96: struct termio tio; ! 97: ! 98: sreadfd = 0; /* standard input */ ! 99: swritefd = 1; /* standard output */ ! 100: ioctl(sreadfd, TCGETA, &tio); ! 101: tio.c_iflag = 0; ! 102: tio.c_oflag = 0; ! 103: tio.c_cflag &= ~(CSIZE|PARENB); ! 104: tio.c_cflag |= (HUPCL|CS8); ! 105: stripflg = 0; ! 106: tio.c_lflag = 0; ! 107: ioctl(sreadfd, TCSETA, &tio); ! 108: #endif ! 109: return(1); ! 110: } ! 111: ! 112: fixline() ! 113: { ! 114: #if SGTTY ! 115: struct sgttyb ttyb; ! 116: ! 117: gtty(sreadfd, &ttyb); ! 118: ttyb.sg_flags |= (RAW | CBREAK); ! 119: stripflg = 0; ! 120: stty(sreadfd, &ttyb); ! 121: ! 122: #elif TERMIO ! 123: struct termio tio; ! 124: ! 125: ioctl(sreadfd, TCGETA, &tio); ! 126: #if 0 ! 127: printmsg(M_LOG, "tio.c_iflag = 0x%04x", tio.c_iflag); ! 128: #endif ! 129: tio.c_iflag = 0; ! 130: stripflg = 0; ! 131: ioctl(sreadfd, TCSETA, &tio); ! 132: #endif ! 133: } ! 134: ! 135: ! 136: /* ! 137: * Coherent support for dialing and connecting with a modem device. ! 138: * Used for uucico MASTER mode. ! 139: * ! 140: * dcpdial(dev, speed, tel) char *dev, *speed, *tel; ! 141: * Initiates the call, utilizing the modemcap dial package, ! 142: * and sets the serial file descriptors: sreadfd and swritefd. ! 143: * Returns (1) for success, and (0) for failure. ! 144: * ! 145: * dcpundial() ! 146: * Closes the serial file descriptors set up with dcpdial(). ! 147: */ ! 148: ! 149: static CALL call; /* dial(3) structure, see "dial.h" */ ! 150: ! 151: int dcpdial(dev, speed, tel) ! 152: char *dev, *speed, *tel; ! 153: { ! 154: char *cp; ! 155: ! 156: call.baud = atoi(speed); ! 157: call.line = dev; ! 158: call.telno = tel; ! 159: ! 160: printmsg(M_CALL, "Trying to connect at speed %d", call.baud); ! 161: if (tel != NULL) ! 162: printmsg(M_CALL, "Calling phone# %s", call.telno); ! 163: if ((sreadfd = swritefd = dial(&call)) < 0) { ! 164: plog(M_CALL, "Dial failed, %s {%d}", _merr_list[-merrno], ! 165: processid); ! 166: while ((cp = index(modembuf, '\r')) != NULL) ! 167: *cp = ' '; ! 168: while ((cp = index(modembuf, '\n')) != NULL) ! 169: *cp = ' '; ! 170: plog(M_CALL, "Modem says %s", modembuf); ! 171: dcpundial(); ! 172: return( 0 ); ! 173: } ! 174: return( 1 ); ! 175: } ! 176: ! 177: /* dcpundial() is called by sysend(), possibly others. ! 178: * Dcpundial calls hangup. Hangup terminates the call and hangs up the ! 179: * modem. Hangup then calls undial() which removes device lock files ! 180: * and re-enables any ports if necessary. Bob H. 11/22/91 ! 181: */ ! 182: ! 183: dcpundial() ! 184: { ! 185: printmsg(M_DEBUG,"dcpundial: about to call hangup()."); ! 186: ! 187: if (role == MASTER) ! 188: hangup(swritefd); ! 189: else { ! 190: #if 0 ! 191: ioctl(swritefd, TIOCHPCL); ! 192: #endif ! 193: /* slave mode */ ! 194: close(swritefd); /* stdout */ ! 195: close(sreadfd); /* stdin */ ! 196: close(2); /* stderr */ ! 197: } ! 198: ! 199: #if 0 ! 200: plog(M_CALL, "dcpundial(%d)", sreadfd); ! 201: if (sreadfd > 2) ! 202: hangup(sreadfd); ! 203: else { ! 204: ioctl(sreadfd, TIOCHPCL); ! 205: close(sreadfd); ! 206: } ! 207: #endif ! 208: } ! 209: ! 210: sendbrk() ! 211: { ! 212: #if SGTTY ! 213: ioctl(swritefd, TIOCSBRK); ! 214: sleep(1); ! 215: ioctl(swritefd, TIOCCBRK); ! 216: #endif ! 217: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.