117787Sralph #ifndef lint 2*23705Sbloom static char sccsid[] = "@(#)vmacs.c 4.2 (Berkeley) 06/23/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); 78*23705Sbloom 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); 8517787Sralph fixline(va, dialspeed); 8617787Sralph 8717787Sralph write(va, &c_SOH, 1); /* abort, reset the dialer */ 8817787Sralph do { 8917787Sralph if (read (va, &c, 1) != 1) { 9017787Sralph logent ("MACS initialization", _FAILED); 9117787Sralph goto failret; 9217787Sralph } 9317787Sralph } while ((c&0177) != 'B'); 9417787Sralph DEBUG(5, "ACU initialized\n", 0); 9517787Sralph 9617787Sralph write(va, &c_STX, 1); /* start text, access adaptor */ 9717787Sralph write(va, &dialer, 1); /* send dialer address digit */ 9817787Sralph write(va, &modem, 1); /* send modem address digit */ 99*23705Sbloom for (p=ph; *p; p++) { 100*23705Sbloom if (*p == '=' || (*p >= '0' && *p <= '9')) 101*23705Sbloom write(va, p, 1); 102*23705Sbloom } 10317787Sralph write(va, &c_SI, 1); /* send buffer empty */ 10417787Sralph write(va, &c_ETX, 1); /* end of text, initiate call */ 10517787Sralph 10617787Sralph if (read(va, &c, 1) != 1) { 10717787Sralph logent("ACU READ", _FAILED); 10817787Sralph goto failret; 10917787Sralph } 11017787Sralph switch(c) { 11117787Sralph case 'A': 11217787Sralph /* Fine! */ 11317787Sralph DEBUG(5, "Call connected\n", 0); 11417787Sralph break; 11517787Sralph case 'B': 116*23705Sbloom DEBUG(2, "Dialer Timeout or Abort\n", 0); 11717787Sralph goto failret; 11817787Sralph case 'D': 11917787Sralph DEBUG(2, "Dialer format error\n", 0); 12017787Sralph goto failret; 12117787Sralph case 'E': 12217787Sralph DEBUG(2, "Dialer parity error\n", 0); 12317787Sralph goto failret; 12417787Sralph case 'F': 12517787Sralph DEBUG(2, "Phone number too long\n", 0); 12617787Sralph goto failret; 12717787Sralph case 'G': 12817787Sralph DEBUG(2, "Busy signal\n", 0); 12917787Sralph goto failret; 13017787Sralph default: 13117787Sralph DEBUG(2, "Unknown MACS return code '%c'\n", i); 13217787Sralph goto failret; 13317787Sralph } 13417787Sralph /* 13517787Sralph * open line - will return on carrier 13617787Sralph */ 13717787Sralph if ((i = open(com, 2)) < 0) { 13817787Sralph if (errno == EIO) 13917787Sralph logent("carrier", "LOST"); 14017787Sralph else 14117787Sralph logent("dialup open", _FAILED); 14217787Sralph goto failret; 14317787Sralph } 14417787Sralph fixline(i, dev->D_speed); 14517787Sralph goto ret; 14617787Sralph failret: 14717787Sralph i = CF_DIAL; 14817787Sralph ret: 14917787Sralph alarm(0); 15017787Sralph if (child > 1) 15117787Sralph kill(child, SIGKILL); 15217787Sralph close(va); 153*23705Sbloom sleep(2); 15417787Sralph return i; 15517787Sralph } 15617787Sralph 15717787Sralph vmacscls(fd) 15817787Sralph register int fd; 15917787Sralph { 16017787Sralph char c_SOH = SOH; 16117787Sralph 16217787Sralph DEBUG(2, "MACS close %d\n", fd); 16317787Sralph write(fd, &c_SOH, 1); 16417787Sralph /* ioctl(fd, TIOCCDTR, NULL);*/ 16517787Sralph close(fd); 16617787Sralph } 16717787Sralph #endif VMACS 168