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