1*17787Sralph #ifndef lint 2*17787Sralph static char sccsid[] = "@(#)vmacs.c 4.1 (Berkeley) 01/22/85"; 3*17787Sralph #endif 4*17787Sralph 5*17787Sralph #include "../condevs.h" 6*17787Sralph #ifdef VMACS 7*17787Sralph /* 8*17787Sralph * Racal-Vadic 'RV811' MACS system with 831 adaptor. 9*17787Sralph * 10*17787Sralph * A typical 300 baud L-devices entry is 11*17787Sralph * ACU /dev/tty10 /dev/tty11,48,1200 300 vmacs 12*17787Sralph * where tty10 is the communication line (D_Line), 13*17787Sralph * tty11 is the dialer line (D_calldev), 14*17787Sralph * the '4' is the dialer address + modem type (viz. dialer 0, Bell 103), 15*17787Sralph * and the '8' is the communication port 16*17787Sralph * (Note: Based on RVMACS version for 820 dialer. This version 17*17787Sralph * developed by Doug Kingston @ BRL, 13 December 83.) 18*17787Sralph */ 19*17787Sralph 20*17787Sralph #define SOH 01 /* Abort */ 21*17787Sralph #define STX 02 /* Access Adaptor */ 22*17787Sralph #define ETX 03 /* Transfer to Dialer */ 23*17787Sralph #define SI 017 /* Buffer Empty (end of phone number) */ 24*17787Sralph 25*17787Sralph vmacsopn(ph, flds, dev) 26*17787Sralph char *ph, *flds[]; 27*17787Sralph struct Devices *dev; 28*17787Sralph { 29*17787Sralph register int va, i, child; 30*17787Sralph register char *p; 31*17787Sralph char c, acu[20], com[20]; 32*17787Sralph char modem, dialer; 33*17787Sralph int dialspeed; 34*17787Sralph char c_STX = STX; 35*17787Sralph char c_ETX = ETX; 36*17787Sralph char c_SI = SI; 37*17787Sralph char c_SOH = SOH; 38*17787Sralph 39*17787Sralph /* create child to open comm line */ 40*17787Sralph child = -1; 41*17787Sralph sprintf(com, "/dev/%s", dev->D_line); 42*17787Sralph if ((child = fork()) == 0) { 43*17787Sralph signal(SIGINT, SIG_DFL); 44*17787Sralph open(com, 0); 45*17787Sralph DEBUG(5, "%s Opened.", com); 46*17787Sralph sleep(5); 47*17787Sralph exit(1); 48*17787Sralph } 49*17787Sralph 50*17787Sralph if ((p = index(dev->D_calldev, ',')) == NULL) { 51*17787Sralph DEBUG(2, "No dialer/modem specification\n", 0); 52*17787Sralph goto failret; 53*17787Sralph } 54*17787Sralph *p++ = '\0'; 55*17787Sralph if (*p < '0' || *p > '7') { 56*17787Sralph logent(p, "Bad dialer address/modem type"); 57*17787Sralph goto failret; 58*17787Sralph } 59*17787Sralph dialer = *p++; 60*17787Sralph if (*p < '0' || *p > '>') { 61*17787Sralph logent(p, "Bad modem address"); 62*17787Sralph goto failret; 63*17787Sralph } 64*17787Sralph modem = *p++; 65*17787Sralph if (*p++ == ',') 66*17787Sralph dialspeed = atoi (p); 67*17787Sralph else 68*17787Sralph dialspeed = dev->D_speed; 69*17787Sralph if (setjmp(Sjbuf)) { 70*17787Sralph logent("vmacsopn", "TIMEOUT"); 71*17787Sralph i = CF_DIAL; 72*17787Sralph goto ret; 73*17787Sralph } 74*17787Sralph DEBUG(4, "STARTING CALL\n", 0); 75*17787Sralph sprintf(acu, "/dev/%s", dev->D_calldev); 76*17787Sralph getnextfd(); 77*17787Sralph signal(SIGALRM, alarmtr); 78*17787Sralph alarm(45); 79*17787Sralph if ((va = open(acu, 2)) < 0) { 80*17787Sralph logent(acu, "CAN'T OPEN"); 81*17787Sralph i = CF_NODEV; 82*17787Sralph goto ret; 83*17787Sralph } 84*17787Sralph DEBUG(5, "ACU %s opened.\n", acu); 85*17787Sralph fixline(va, dialspeed); 86*17787Sralph 87*17787Sralph write(va, &c_SOH, 1); /* abort, reset the dialer */ 88*17787Sralph do { 89*17787Sralph if (read (va, &c, 1) != 1) { 90*17787Sralph logent ("MACS initialization", _FAILED); 91*17787Sralph goto failret; 92*17787Sralph } 93*17787Sralph } while ((c&0177) != 'B'); 94*17787Sralph DEBUG(5, "ACU initialized\n", 0); 95*17787Sralph 96*17787Sralph write(va, &c_STX, 1); /* start text, access adaptor */ 97*17787Sralph write(va, &dialer, 1); /* send dialer address digit */ 98*17787Sralph write(va, &modem, 1); /* send modem address digit */ 99*17787Sralph write(va, ph, strlen(ph)); /* Send Phone Number */ 100*17787Sralph write(va, &c_SI, 1); /* send buffer empty */ 101*17787Sralph write(va, &c_ETX, 1); /* end of text, initiate call */ 102*17787Sralph 103*17787Sralph if (read(va, &c, 1) != 1) { 104*17787Sralph logent("ACU READ", _FAILED); 105*17787Sralph goto failret; 106*17787Sralph } 107*17787Sralph switch(c) { 108*17787Sralph case 'A': 109*17787Sralph /* Fine! */ 110*17787Sralph DEBUG(5, "Call connected\n", 0); 111*17787Sralph break; 112*17787Sralph case 'B': 113*17787Sralph DEBUG(2, "CALL ABORTED\n", 0); 114*17787Sralph goto failret; 115*17787Sralph case 'D': 116*17787Sralph DEBUG(2, "Dialer format error\n", 0); 117*17787Sralph goto failret; 118*17787Sralph case 'E': 119*17787Sralph DEBUG(2, "Dialer parity error\n", 0); 120*17787Sralph goto failret; 121*17787Sralph case 'F': 122*17787Sralph DEBUG(2, "Phone number too long\n", 0); 123*17787Sralph goto failret; 124*17787Sralph case 'G': 125*17787Sralph DEBUG(2, "Busy signal\n", 0); 126*17787Sralph goto failret; 127*17787Sralph default: 128*17787Sralph DEBUG(2, "Unknown MACS return code '%c'\n", i); 129*17787Sralph goto failret; 130*17787Sralph } 131*17787Sralph /* 132*17787Sralph * open line - will return on carrier 133*17787Sralph */ 134*17787Sralph if ((i = open(com, 2)) < 0) { 135*17787Sralph if (errno == EIO) 136*17787Sralph logent("carrier", "LOST"); 137*17787Sralph else 138*17787Sralph logent("dialup open", _FAILED); 139*17787Sralph goto failret; 140*17787Sralph } 141*17787Sralph fixline(i, dev->D_speed); 142*17787Sralph goto ret; 143*17787Sralph failret: 144*17787Sralph i = CF_DIAL; 145*17787Sralph ret: 146*17787Sralph alarm(0); 147*17787Sralph if (child > 1) 148*17787Sralph kill(child, SIGKILL); 149*17787Sralph close(va); 150*17787Sralph return i; 151*17787Sralph } 152*17787Sralph 153*17787Sralph vmacscls(fd) 154*17787Sralph register int fd; 155*17787Sralph { 156*17787Sralph char c_SOH = SOH; 157*17787Sralph 158*17787Sralph DEBUG(2, "MACS close %d\n", fd); 159*17787Sralph write(fd, &c_SOH, 1); 160*17787Sralph /* ioctl(fd, TIOCCDTR, NULL);*/ 161*17787Sralph close(fd); 162*17787Sralph } 163*17787Sralph #endif VMACS 164