117787Sralph #ifndef lint 2*33590Srick static char sccsid[] = "@(#)vmacs.c 4.5 (Berkeley) 02/24/88"; 317787Sralph #endif 417787Sralph 517787Sralph #include "../condevs.h" 6*33590Srick 717787Sralph /* 817787Sralph * 917787Sralph * A typical 300 baud L-devices entry is 1017787Sralph * ACU /dev/tty10 /dev/tty11,48,1200 300 vmacs 1117787Sralph * where tty10 is the communication line (D_Line), 1217787Sralph * tty11 is the dialer line (D_calldev), 1317787Sralph * the '4' is the dialer address + modem type (viz. dialer 0, Bell 103), 1417787Sralph * and the '8' is the communication port 1517787Sralph * (Note: Based on RVMACS version for 820 dialer. This version 1617787Sralph * developed by Doug Kingston @ BRL, 13 December 83.) 1717787Sralph */ 1817787Sralph 1917787Sralph #define SOH 01 /* Abort */ 2017787Sralph #define STX 02 /* Access Adaptor */ 2117787Sralph #define ETX 03 /* Transfer to Dialer */ 2217787Sralph #define SI 017 /* Buffer Empty (end of phone number) */ 2317787Sralph 2417787Sralph vmacsopn(ph, flds, dev) 2517787Sralph char *ph, *flds[]; 2617787Sralph struct Devices *dev; 2717787Sralph { 2817787Sralph register int va, i, child; 2917787Sralph register char *p; 3017787Sralph char c, acu[20], com[20]; 3117787Sralph char modem, dialer; 3217787Sralph int dialspeed; 3317787Sralph char c_STX = STX; 3417787Sralph char c_ETX = ETX; 3517787Sralph char c_SI = SI; 3617787Sralph char c_SOH = SOH; 3717787Sralph 3817787Sralph /* create child to open comm line */ 3917787Sralph child = -1; 4017787Sralph sprintf(com, "/dev/%s", dev->D_line); 4117787Sralph if ((child = fork()) == 0) { 4217787Sralph signal(SIGINT, SIG_DFL); 4317787Sralph open(com, 0); 4417787Sralph DEBUG(5, "%s Opened.", com); 4517787Sralph sleep(5); 4617787Sralph exit(1); 4717787Sralph } 4817787Sralph 4917787Sralph if ((p = index(dev->D_calldev, ',')) == NULL) { 5017787Sralph DEBUG(2, "No dialer/modem specification\n", 0); 5117787Sralph goto failret; 5217787Sralph } 5317787Sralph *p++ = '\0'; 5417787Sralph if (*p < '0' || *p > '7') { 5517787Sralph logent(p, "Bad dialer address/modem type"); 5617787Sralph goto failret; 5717787Sralph } 5817787Sralph dialer = *p++; 5917787Sralph if (*p < '0' || *p > '>') { 6017787Sralph logent(p, "Bad modem address"); 6117787Sralph goto failret; 6217787Sralph } 6317787Sralph modem = *p++; 6417787Sralph if (*p++ == ',') 6517787Sralph dialspeed = atoi (p); 6617787Sralph else 6717787Sralph dialspeed = dev->D_speed; 6817787Sralph if (setjmp(Sjbuf)) { 6917787Sralph logent("vmacsopn", "TIMEOUT"); 7017787Sralph i = CF_DIAL; 7117787Sralph goto ret; 7217787Sralph } 7317787Sralph DEBUG(4, "STARTING CALL\n", 0); 7417787Sralph sprintf(acu, "/dev/%s", dev->D_calldev); 7517787Sralph getnextfd(); 7617787Sralph signal(SIGALRM, alarmtr); 7723705Sbloom alarm(60); 7817787Sralph if ((va = open(acu, 2)) < 0) { 7917787Sralph logent(acu, "CAN'T OPEN"); 8017787Sralph i = CF_NODEV; 8117787Sralph goto ret; 8217787Sralph } 8317787Sralph DEBUG(5, "ACU %s opened.\n", acu); 8425157Sbloom next_fd = -1; 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 */ 9923705Sbloom for (p=ph; *p; p++) { 10023705Sbloom if (*p == '=' || (*p >= '0' && *p <= '9')) 10123705Sbloom write(va, p, 1); 10223705Sbloom } 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': 11623705Sbloom 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); 15323705Sbloom 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 } 167