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
817777Sralph #ifndef lint
9*62384Sbostic static char sccsid[] = "@(#)nov.c 8.1 (Berkeley) 06/06/93";
1048651Sbostic #endif /* not lint */
1117777Sralph
1246875Sbostic #include "condevs.h"
1317777Sralph
1417777Sralph /***
1517777Sralph * novopn(telno, flds, dev) connect to novation Smart-Cat
1617777Sralph * (similar to hayes smartmodem)
1717777Sralph * char *flds[], *dev[];
1817777Sralph *
1917777Sralph * return codes:
2017777Sralph * >0 - file number - ok
2117777Sralph * CF_DIAL,CF_DEVICE - failed
2217777Sralph */
2317777Sralph
novopn(telno,flds,dev)2417777Sralph novopn(telno, flds, dev)
2517777Sralph char *telno;
2617777Sralph char *flds[];
2717777Sralph struct Devices *dev;
2817777Sralph {
2917777Sralph int dh = -1;
3017777Sralph extern errno;
3117777Sralph char dcname[20];
3217777Sralph int pulse = 0;
3317777Sralph
3417777Sralph sprintf(dcname, "/dev/%s", dev->D_line);
3517777Sralph DEBUG(4, "dc - %s\n", dcname);
3617777Sralph if (strcmp(dev->D_calldev, "pulse") == 0)
3717777Sralph pulse = 1;
3817777Sralph if (setjmp(Sjbuf)) {
3917777Sralph DEBUG(1, "timeout novation open %s\n", dcname);
4017777Sralph logent("novation open", "TIMEOUT");
4117777Sralph if (dh >= 0)
4217777Sralph close(dh);
4317777Sralph delock(dev->D_line);
4417777Sralph return CF_DIAL;
4517777Sralph }
4617777Sralph signal(SIGALRM, alarmtr);
4717777Sralph getnextfd();
4817777Sralph alarm(10);
4917777Sralph dh = open(dcname, 2); /* read/write */
5017777Sralph alarm(0);
5117777Sralph
5217777Sralph /* modem is open */
5317777Sralph next_fd = -1;
5417777Sralph if (dh >= 0) {
5517777Sralph fixline(dh, dev->D_speed);
5617777Sralph /* set guard time small so line is in transparant mode */
5717777Sralph slowrite(dh, "\rATS12=1\r");
5817777Sralph if (expect("OK", dh) != 0) {
5917777Sralph logent("NOV no line", _FAILED);
6017777Sralph strcpy(devSel, dev->D_line);
6117777Sralph novcls(dh);
6217777Sralph return CF_DIAL;
6317777Sralph }
6417777Sralph
6517777Sralph if (pulse)
6617777Sralph slowrite(dh, "ATDP");
6717777Sralph else
6817777Sralph slowrite(dh, "ATDT");
6917777Sralph slowrite(dh, telno);
7017777Sralph slowrite(dh, "\r");
7117777Sralph
7217777Sralph if (expect("CONNECT", dh) != 0) {
7317777Sralph logent("NOV no carrier", _FAILED);
7417777Sralph strcpy(devSel, dev->D_line);
7517777Sralph novcls(dh);
7617777Sralph return CF_DIAL;
7717777Sralph }
7817777Sralph
7917777Sralph }
8017777Sralph if (dh < 0) {
8117777Sralph DEBUG(4, "novation failed\n", CNULL);
8217777Sralph delock(dev->D_line);
8317777Sralph }
8417777Sralph DEBUG(4, "novation ok\n", CNULL);
8517777Sralph return dh;
8617777Sralph }
8717777Sralph
novcls(fd)8817777Sralph novcls(fd)
8917777Sralph int fd;
9017777Sralph {
9117777Sralph char dcname[20];
9217777Sralph struct sgttyb hup, sav;
9317777Sralph
9417777Sralph if (fd > 0) {
9517777Sralph sprintf(dcname, "/dev/%s", devSel);
9617777Sralph DEBUG(4, "Hanging up fd = %d\n", fd);
9717777Sralph /*
9817777Sralph * code to drop DTR -- change to 0 baud then back to default.
9917777Sralph */
10017777Sralph gtty(fd, &hup);
10117777Sralph gtty(fd, &sav);
10217777Sralph hup.sg_ispeed = B0;
10317777Sralph hup.sg_ospeed = B0;
10417777Sralph stty(fd, &hup);
10517777Sralph sleep(2);
10617777Sralph stty(fd, &sav);
10717777Sralph /*
10817777Sralph * now raise DTR -- close the device & open it again.
10917777Sralph */
11017777Sralph sleep(2);
11117777Sralph close(fd);
11217777Sralph sleep(2);
11317777Sralph fd = open(dcname, 2);
11417777Sralph /*
11517777Sralph * Since we have a getty sleeping on this line, when it wakes up it sends
11617777Sralph * all kinds of garbage to the modem. Unfortunatly, the modem likes to
11717777Sralph * execute the previous command when it sees the garbage. The previous
11817777Sralph * command was to dial the phone, so let's make the last command reset
11917777Sralph * the modem.
12017777Sralph */
12117777Sralph sleep(2);
12217777Sralph slowrite(fd, "\rATZ\r");
12317777Sralph close(fd);
12417777Sralph delock(devSel);
12517777Sralph }
12617777Sralph }
127