117787Sralph #ifndef lint 2*25157Sbloom static char sccsid[] = "@(#)vmacs.c 4.3 (Berkeley) 10/10/85"; 317787Sralph #endif 417787Sralph 517787Sralph #include "../condevs.h" 617787Sralph #ifdef VMACS 717787Sralph /* 817787Sralph * Racal-Vadic 'RV811' MACS system with 831 adaptor. 917787Sralph * 1017787Sralph * A typical 300 baud L-devices entry is 1117787Sralph * ACU /dev/tty10 /dev/tty11,48,1200 300 vmacs 1217787Sralph * where tty10 is the communication line (D_Line), 1317787Sralph * tty11 is the dialer line (D_calldev), 1417787Sralph * the '4' is the dialer address + modem type (viz. dialer 0, Bell 103), 1517787Sralph * and the '8' is the communication port 1617787Sralph * (Note: Based on RVMACS version for 820 dialer. This version 1717787Sralph * developed by Doug Kingston @ BRL, 13 December 83.) 1817787Sralph */ 1917787Sralph 2017787Sralph #define SOH 01 /* Abort */ 2117787Sralph #define STX 02 /* Access Adaptor */ 2217787Sralph #define ETX 03 /* Transfer to Dialer */ 2317787Sralph #define SI 017 /* Buffer Empty (end of phone number) */ 2417787Sralph 2517787Sralph vmacsopn(ph, flds, dev) 2617787Sralph char *ph, *flds[]; 2717787Sralph struct Devices *dev; 2817787Sralph { 2917787Sralph register int va, i, child; 3017787Sralph register char *p; 3117787Sralph char c, acu[20], com[20]; 3217787Sralph char modem, dialer; 3317787Sralph int dialspeed; 3417787Sralph char c_STX = STX; 3517787Sralph char c_ETX = ETX; 3617787Sralph char c_SI = SI; 3717787Sralph char c_SOH = SOH; 3817787Sralph 3917787Sralph /* create child to open comm line */ 4017787Sralph child = -1; 4117787Sralph sprintf(com, "/dev/%s", dev->D_line); 4217787Sralph if ((child = fork()) == 0) { 4317787Sralph signal(SIGINT, SIG_DFL); 4417787Sralph open(com, 0); 4517787Sralph DEBUG(5, "%s Opened.", com); 4617787Sralph sleep(5); 4717787Sralph exit(1); 4817787Sralph } 4917787Sralph 5017787Sralph if ((p = index(dev->D_calldev, ',')) == NULL) { 5117787Sralph DEBUG(2, "No dialer/modem specification\n", 0); 5217787Sralph goto failret; 5317787Sralph } 5417787Sralph *p++ = '\0'; 5517787Sralph if (*p < '0' || *p > '7') { 5617787Sralph logent(p, "Bad dialer address/modem type"); 5717787Sralph goto failret; 5817787Sralph } 5917787Sralph dialer = *p++; 6017787Sralph if (*p < '0' || *p > '>') { 6117787Sralph logent(p, "Bad modem address"); 6217787Sralph goto failret; 6317787Sralph } 6417787Sralph modem = *p++; 6517787Sralph if (*p++ == ',') 6617787Sralph dialspeed = atoi (p); 6717787Sralph else 6817787Sralph dialspeed = dev->D_speed; 6917787Sralph if (setjmp(Sjbuf)) { 7017787Sralph logent("vmacsopn", "TIMEOUT"); 7117787Sralph i = CF_DIAL; 7217787Sralph goto ret; 7317787Sralph } 7417787Sralph DEBUG(4, "STARTING CALL\n", 0); 7517787Sralph sprintf(acu, "/dev/%s", dev->D_calldev); 7617787Sralph getnextfd(); 7717787Sralph signal(SIGALRM, alarmtr); 7823705Sbloom alarm(60); 7917787Sralph if ((va = open(acu, 2)) < 0) { 8017787Sralph logent(acu, "CAN'T OPEN"); 8117787Sralph i = CF_NODEV; 8217787Sralph goto ret; 8317787Sralph } 8417787Sralph DEBUG(5, "ACU %s opened.\n", acu); 85*25157Sbloom next_fd = -1; 8617787Sralph fixline(va, dialspeed); 8717787Sralph 8817787Sralph write(va, &c_SOH, 1); /* abort, reset the dialer */ 8917787Sralph do { 9017787Sralph if (read (va, &c, 1) != 1) { 9117787Sralph logent ("MACS initialization", _FAILED); 9217787Sralph goto failret; 9317787Sralph } 9417787Sralph } while ((c&0177) != 'B'); 9517787Sralph DEBUG(5, "ACU initialized\n", 0); 9617787Sralph 9717787Sralph write(va, &c_STX, 1); /* start text, access adaptor */ 9817787Sralph write(va, &dialer, 1); /* send dialer address digit */ 9917787Sralph write(va, &modem, 1); /* send modem address digit */ 10023705Sbloom for (p=ph; *p; p++) { 10123705Sbloom if (*p == '=' || (*p >= '0' && *p <= '9')) 10223705Sbloom write(va, p, 1); 10323705Sbloom } 10417787Sralph write(va, &c_SI, 1); /* send buffer empty */ 10517787Sralph write(va, &c_ETX, 1); /* end of text, initiate call */ 10617787Sralph 10717787Sralph if (read(va, &c, 1) != 1) { 10817787Sralph logent("ACU READ", _FAILED); 10917787Sralph goto failret; 11017787Sralph } 11117787Sralph switch(c) { 11217787Sralph case 'A': 11317787Sralph /* Fine! */ 11417787Sralph DEBUG(5, "Call connected\n", 0); 11517787Sralph break; 11617787Sralph case 'B': 11723705Sbloom DEBUG(2, "Dialer Timeout or Abort\n", 0); 11817787Sralph goto failret; 11917787Sralph case 'D': 12017787Sralph DEBUG(2, "Dialer format error\n", 0); 12117787Sralph goto failret; 12217787Sralph case 'E': 12317787Sralph DEBUG(2, "Dialer parity error\n", 0); 12417787Sralph goto failret; 12517787Sralph case 'F': 12617787Sralph DEBUG(2, "Phone number too long\n", 0); 12717787Sralph goto failret; 12817787Sralph case 'G': 12917787Sralph DEBUG(2, "Busy signal\n", 0); 13017787Sralph goto failret; 13117787Sralph default: 13217787Sralph DEBUG(2, "Unknown MACS return code '%c'\n", i); 13317787Sralph goto failret; 13417787Sralph } 13517787Sralph /* 13617787Sralph * open line - will return on carrier 13717787Sralph */ 13817787Sralph if ((i = open(com, 2)) < 0) { 13917787Sralph if (errno == EIO) 14017787Sralph logent("carrier", "LOST"); 14117787Sralph else 14217787Sralph logent("dialup open", _FAILED); 14317787Sralph goto failret; 14417787Sralph } 14517787Sralph fixline(i, dev->D_speed); 14617787Sralph goto ret; 14717787Sralph failret: 14817787Sralph i = CF_DIAL; 14917787Sralph ret: 15017787Sralph alarm(0); 15117787Sralph if (child > 1) 15217787Sralph kill(child, SIGKILL); 15317787Sralph close(va); 15423705Sbloom sleep(2); 15517787Sralph return i; 15617787Sralph } 15717787Sralph 15817787Sralph vmacscls(fd) 15917787Sralph register int fd; 16017787Sralph { 16117787Sralph char c_SOH = SOH; 16217787Sralph 16317787Sralph DEBUG(2, "MACS close %d\n", fd); 16417787Sralph write(fd, &c_SOH, 1); 16517787Sralph /* ioctl(fd, TIOCCDTR, NULL);*/ 16617787Sralph close(fd); 16717787Sralph } 16817787Sralph #endif VMACS 169