117784Sralph #ifndef lint 2*46875Sbostic static char sccsid[] = "@(#)va820.c 4.5 (Berkeley) 03/02/91"; 317784Sralph #endif 417784Sralph 5*46875Sbostic #include "condevs.h" 617784Sralph 717784Sralph /* 817784Sralph * Racal-Vadic 'RV820' with 831 adaptor. 917784Sralph * BUGS: 1017784Sralph * dialer baud rate is hardcoded 1117784Sralph */ 1217784Sralph #define MAXDIG 30 /* set by switches inside adapter */ 1317784Sralph char c_abort = '\001'; 1417784Sralph char c_start = '\002'; 1517784Sralph char c_empty = '\017'; 1617784Sralph char c_end = '\003'; 1717784Sralph 1817784Sralph va820opn(ph, flds, dev) 1917784Sralph char *ph, *flds[]; 2017784Sralph struct Devices *dev; 2117784Sralph { 2217784Sralph register int va, i, child; 2317784Sralph char c, acu[20], com[20]; 2417784Sralph char vadbuf[MAXDIG+2]; 2517784Sralph int nw, lt; 2617784Sralph unsigned timelim; 2717784Sralph struct sgttyb sg; 2817784Sralph 2917784Sralph child = -1; 3017784Sralph if (strlen(ph) > MAXDIG) { 3117784Sralph DEBUG(4, "BAD PHONE NUMBER %s\n", ph); 3217784Sralph logent("rvadopn", "BAD PHONE NUMBER"); 3317784Sralph i = CF_DIAL; 3417784Sralph goto ret; 3517784Sralph } 3617784Sralph 3717784Sralph if (setjmp(Sjbuf)) { 3817784Sralph logent("rvadopn", "TIMEOUT"); 3917784Sralph i = CF_DIAL; 4017784Sralph goto ret; 4117784Sralph } 4217784Sralph DEBUG(4, "ACU %s\n", dev->D_calldev); 4317784Sralph DEBUG(4, "LINE %s\n", dev->D_line); 4417784Sralph sprintf(acu, "/dev/%s", dev->D_calldev); 4517784Sralph getnextfd(); 4617784Sralph signal(SIGALRM, alarmtr); 4717784Sralph alarm(10); 4825160Sbloom va = open(acu, 2); 4925160Sbloom alarm(0); 5025160Sbloom next_fd = -1; 5125160Sbloom if (va < 0) { 5217784Sralph DEBUG(4, "ACU OPEN FAIL %d\n", errno); 5317784Sralph logent(acu, "CAN'T OPEN"); 5417784Sralph i = CF_NODEV; 5517784Sralph goto ret; 5617784Sralph } 5717784Sralph /* 5817784Sralph * Set speed and modes on dialer and clear any 5917784Sralph * previous requests 6017784Sralph */ 6117784Sralph DEBUG(4, "SETTING UP VA831 (%d)\n", va); 6217784Sralph ioctl(va, TIOCGETP, &sg); 6317784Sralph sg.sg_ispeed = sg.sg_ospeed = B1200; 6417784Sralph sg.sg_flags |= RAW; 6517784Sralph sg.sg_flags &= ~ECHO; 6617784Sralph ioctl(va, TIOCSETP, &sg); 6717784Sralph DEBUG(4, "CLEARING VA831\n", 0); 6817784Sralph if ( write(va, &c_abort, 1) != 1) { 6917784Sralph DEBUG(4,"BAD VA831 WRITE %d\n", errno); 7017784Sralph logent(acu, "CAN'T CLEAR"); 7117784Sralph i = CF_DIAL; 7217784Sralph goto ret; 7317784Sralph } 7417784Sralph sleep(1); /* XXX */ 7517784Sralph read(va, &c, 1); 7617784Sralph if (c != 'B') { 7717784Sralph DEBUG(4,"BAD VA831 RESPONSE %c\n", c); 7817784Sralph logent(acu, "CAN'T CLEAR"); 7917784Sralph i = CF_DIAL; 8017784Sralph goto ret; 8117784Sralph } 8217784Sralph /* 8317784Sralph * Build the dialing sequence for the adapter 8417784Sralph */ 8517784Sralph DEBUG(4, "DIALING %s\n", ph); 8623704Sbloom sprintf(vadbuf, "%c%s<%c%c", c_start, ph, c_empty, c_end); 8717784Sralph timelim = 5 * strlen(ph); 8817784Sralph alarm(timelim < 30 ? 30 : timelim); 8917784Sralph nw = write(va, vadbuf, strlen(vadbuf)); /* Send Phone Number */ 9017784Sralph if (nw != strlen(vadbuf)) { 9117784Sralph DEBUG(4,"BAD VA831 WRITE %d\n", nw); 9217784Sralph logent(acu, "BAD WRITE"); 9317784Sralph goto failret; 9417784Sralph } 9517784Sralph 9617784Sralph sprintf(com, "/dev/%s", dev->D_line); 9717784Sralph 9817784Sralph /* create child to open comm line */ 9917784Sralph if ((child = fork()) == 0) { 10017784Sralph signal(SIGINT, SIG_DFL); 10117784Sralph open(com, 0); 10217784Sralph sleep(5); 10317784Sralph _exit(1); 10417784Sralph } 10517784Sralph 10617784Sralph DEBUG(4, "WAITING FOR ANSWER\n", 0); 10717784Sralph if (read(va, &c, 1) != 1) { 10817784Sralph logent("ACU READ", _FAILED); 10917784Sralph goto failret; 11017784Sralph } 11117784Sralph switch(c) { 11217784Sralph case 'A': 11317784Sralph /* Fine! */ 11417784Sralph break; 11517784Sralph case 'B': 11617784Sralph DEBUG(2, "Line Busy / No Answer\n", 0); 11717784Sralph goto failret; 11817784Sralph case 'D': 11917784Sralph DEBUG(2, "Dialer format error\n", 0); 12017784Sralph goto failret; 12117784Sralph case 'E': 12217784Sralph DEBUG(2, "Dialer parity error\n", 0); 12317784Sralph goto failret; 12417784Sralph case 'F': 12517784Sralph DEBUG(2, "Phone number too long\n", 0); 12617784Sralph goto failret; 12717784Sralph case 'G': 12817784Sralph DEBUG(2, "Modem Busy\n", 0); 12917784Sralph goto failret; 13017784Sralph default: 13117784Sralph DEBUG(2, "Unknown MACS return code '%c'\n", c&0177); 13217784Sralph goto failret; 13317784Sralph } 13417784Sralph /* 13517784Sralph * open line - will return on carrier 13617784Sralph */ 13717784Sralph if ((i = open(com, 2)) < 0) { 13817784Sralph if (errno == EIO) 13917784Sralph logent("carrier", "LOST"); 14017784Sralph else 14117784Sralph logent("dialup open", _FAILED); 14217784Sralph goto failret; 14317784Sralph } 14417784Sralph DEBUG(2, "RVADIC opened %d\n", i); 14517784Sralph fixline(i, dev->D_speed); 14617784Sralph goto ret; 14717784Sralph failret: 14817784Sralph i = CF_DIAL; 14917784Sralph ret: 15017784Sralph alarm(0); 15117784Sralph if (child != -1) 15217784Sralph kill(child, SIGKILL); 15317784Sralph close(va); 15417784Sralph while ((nw = wait(<)) != child && nw != -1) 15517784Sralph ; 15617784Sralph return i; 15717784Sralph } 15817784Sralph 15917784Sralph va820cls(fd) 16017784Sralph register int fd; 16117784Sralph { 16217784Sralph 16317784Sralph DEBUG(2, "RVADIC close %d\n", fd); 16417784Sralph close(fd); 16517784Sralph } 166