148651Sbostic /*-
2*62384Sbostic * Copyright (c) 1985, 1993
3*62384Sbostic * The Regents of the University of California. All rights reserved.
448651Sbostic *
548651Sbostic * %sccs.include.proprietary.c%
648651Sbostic */
748651Sbostic
817786Sralph #ifndef lint
9*62384Sbostic static char sccsid[] = "@(#)vent.c 8.1 (Berkeley) 06/06/93";
1048651Sbostic #endif /* not lint */
1117786Sralph
1246875Sbostic #include "condevs.h"
1317786Sralph
ventopn(telno,flds,dev)1417786Sralph ventopn(telno, flds, dev)
1517786Sralph char *flds[], *telno;
1617786Sralph struct Devices *dev;
1717786Sralph {
1817786Sralph int dh;
1917786Sralph int i, ok = -1;
2017786Sralph char dcname[20];
2117786Sralph
2217786Sralph sprintf(dcname, "/dev/%s", dev->D_line);
2317786Sralph if (setjmp(Sjbuf)) {
2417786Sralph DEBUG(1, "timeout ventel open\n", "");
2517786Sralph logent("ventel open", "TIMEOUT");
2617786Sralph if (dh >= 0)
2717786Sralph close(dh);
2817786Sralph delock(dev->D_line);
2917786Sralph return CF_NODEV;
3017786Sralph }
3117786Sralph signal(SIGALRM, alarmtr);
3217786Sralph getnextfd();
3317786Sralph alarm(10);
3417786Sralph dh = open(dcname, 2);
3517786Sralph next_fd = -1;
3625158Sbloom alarm(0);
3717786Sralph if (dh < 0) {
3817786Sralph DEBUG(4,"%s\n", errno == 4 ? "no carrier" : "can't open modem");
3917786Sralph delock(dev->D_line);
4017786Sralph return errno == 4 ? CF_DIAL : CF_NODEV;
4117786Sralph }
4217786Sralph
4317786Sralph /* modem is open */
4417786Sralph fixline(dh, dev->D_speed);
4517786Sralph
4617786Sralph /* translate - to % and = to & for VenTel */
4717786Sralph DEBUG(4, "calling %s -> ", telno);
4817786Sralph for (i = 0; i < strlen(telno); ++i) {
4917786Sralph switch(telno[i]) {
5017786Sralph case '-': /* delay */
5117786Sralph telno[i] = '%';
5217786Sralph break;
5317786Sralph case '=': /* await dial tone */
5417786Sralph telno[i] = '&';
5517786Sralph break;
5617786Sralph case '<':
5717786Sralph telno[i] = '%';
5817786Sralph break;
5917786Sralph }
6017786Sralph }
6117786Sralph DEBUG(4, "%s\n", telno);
6217786Sralph sleep(1);
6317786Sralph for(i = 0; i < 5; ++i) { /* make up to 5 tries */
6417786Sralph slowrite(dh, "\r\r");/* awake, thou lowly VenTel! */
6517786Sralph
6617786Sralph DEBUG(4, "wanted %s ", "$");
6717786Sralph ok = expect("$", dh);
6817786Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
6917786Sralph if (ok != 0)
7017786Sralph continue;
7117786Sralph slowrite(dh, "K"); /* "K" (enter number) command */
7217786Sralph DEBUG(4, "wanted %s ", "DIAL: ");
7317786Sralph ok = expect("DIAL: ", dh);
7417786Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
7517786Sralph if (ok == 0)
7617786Sralph break;
7717786Sralph }
7817786Sralph
7917786Sralph if (ok == 0) {
8017786Sralph slowrite(dh, telno); /* send telno, send \r */
8117786Sralph slowrite(dh, "\r");
8217786Sralph DEBUG(4, "wanted %s ", "ONLINE");
8317786Sralph ok = expect("ONLINE!", dh);
8417786Sralph DEBUG(4, "got %s\n", ok ? "?" : "that");
8517786Sralph }
8617786Sralph if (ok != 0) {
8717786Sralph if (dh > 2)
8817786Sralph close(dh);
8917786Sralph DEBUG(4, "venDial failed\n", "");
9017786Sralph return CF_DIAL;
9117786Sralph }
9217786Sralph else
9317786Sralph DEBUG(4, "venDial ok\n", "");
9417786Sralph return dh;
9517786Sralph }
9617786Sralph
ventcls(fd)9717786Sralph ventcls(fd)
9817786Sralph int fd;
9917786Sralph {
10017786Sralph if (fd > 0) {
10117786Sralph close(fd);
10217786Sralph sleep(5);
10317786Sralph delock(devSel);
10417786Sralph }
10517786Sralph }
106