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
818563Sralph #ifndef lint
9*62384Sbostic static char sccsid[] = "@(#)df12.c 8.1 (Berkeley) 06/06/93";
1048651Sbostic #endif /* not lint */
1118563Sralph
1246875Sbostic #include "condevs.h"
1318563Sralph
1418563Sralph /*
1518563Sralph * df12popn(telno, flds, dev) connect to df12 modem (pulse call)
1618563Sralph * df12topn(telno, flds, dev) connect to df12 modem (tone call)
1718563Sralph * char *flds[], *dev[];
1818563Sralph *
1918563Sralph * return codes:
2018563Sralph * >0 - file number - ok
2118563Sralph * CF_DIAL,CF_NODEV - failed
2218563Sralph */
2318563Sralph
df12popn(telno,flds,dev)2418563Sralph df12popn (telno, flds, dev)
2518563Sralph char *telno,
2618563Sralph *flds[];
2718563Sralph struct Devices *dev;
2818563Sralph {
2918563Sralph return df12opn (telno, flds, dev, 0);
3018563Sralph }
3118563Sralph
df12topn(telno,flds,dev)3218563Sralph df12topn (telno, flds, dev)
3318563Sralph char *telno,
3418563Sralph *flds[];
3518563Sralph struct Devices *dev;
3618563Sralph {
3718563Sralph return df12opn (telno, flds, dev, 1);
3818563Sralph }
3918563Sralph
4018563Sralph /* ARGSUSED */
df12opn(telno,flds,dev,toneflag)4118563Sralph df12opn (telno, flds, dev, toneflag)
4218563Sralph char *telno;
4318563Sralph char *flds[];
4418563Sralph struct Devices *dev;
4518563Sralph int toneflag;
4618563Sralph {
4718563Sralph int phindex, dh = -1;
4818563Sralph extern errno;
4918563Sralph char dcname[20], newphone[64];
5018563Sralph
5118563Sralph sprintf (dcname, "/dev/%s", dev -> D_line);
5218563Sralph DEBUG (4, "dc - %s\n", dcname);
5318563Sralph if (setjmp (Sjbuf))
5418563Sralph {
5518563Sralph logent (dcname, "TIMEOUT");
5618563Sralph if (dh >= 0)
5718563Sralph close (dh);
5818563Sralph return CF_DIAL;
5918563Sralph }
6018563Sralph signal (SIGALRM, alarmtr);
6118563Sralph getnextfd ();
6218563Sralph alarm (10);
6318563Sralph dh = open (dcname, 2);/* read/write */
6418563Sralph alarm (0);
6518563Sralph
6618563Sralph /* modem is open */
6718563Sralph
6818563Sralph /* First, adjust our phone number string. These modems don't
6918563Sralph * like any characters but digits and "=" signs (for delay)
7018563Sralph */
7118563Sralph for (phindex = 0; *telno; telno++)
7218563Sralph {
7318563Sralph if (*telno == '=' || (*telno >= '0' && *telno <= '9'))
7418563Sralph newphone[phindex++] = *telno;
7518563Sralph if (phindex == 64)
7618563Sralph {
7718563Sralph logent (dcname, "Phone number too long");
7818563Sralph close (dh);
7918563Sralph return CF_DIAL;
8018563Sralph }
8118563Sralph }
8218563Sralph newphone[phindex] = '\0';
8318563Sralph next_fd = -1;
8418563Sralph if (dh >= 0)
8518563Sralph {
8618563Sralph fixline (dh, dev -> D_speed);
8718563Sralph if (dochat (dev, flds, dh))
8818563Sralph {
8918563Sralph logent (dcname, "CHAT FAILED");
9018563Sralph close (dh);
9118563Sralph return CF_DIAL;
9218563Sralph }
9318563Sralph slowrite (dh, "\02");
9418563Sralph if (expect ("Ready\r\n", dh) != 0)
9518563Sralph {
9618563Sralph DEBUG (4, "Didn't get 'Ready' response.\n", NULL);
9718563Sralph logent (dcname, "Modem not responding");
9818563Sralph close (dh);
9918563Sralph return CF_DIAL;
10018563Sralph }
10118563Sralph DEBUG (4, "Got 'Ready' response\n", NULL);
10218563Sralph DEBUG (7, "Writing control select flag %c\n", toneflag ? 'T' : 'P');
10318563Sralph slowrite (dh, toneflag ? "T" : "P");
10418563Sralph DEBUG (4, "Writing telephone number %s\n", newphone);
10518563Sralph slowrite (dh, newphone);
10618563Sralph DEBUG (7, "Telephone number written\n", NULL);
10718563Sralph slowrite (dh, "#");
10818563Sralph DEBUG (7, "Writing # sign\n", NULL);
10918563Sralph
11018563Sralph if (expect ("Attached\r\n", dh) != 0)
11118563Sralph {
11218563Sralph logent (dcname, "No carrier");
11318563Sralph strcpy (devSel, dev -> D_line);
11418563Sralph df12cls (dh);
11518563Sralph return CF_DIAL;
11618563Sralph }
11718563Sralph
11818563Sralph }
11918563Sralph if (dh < 0)
12018563Sralph {
12118563Sralph logent (dcname, "CAN'T OPEN");
12218563Sralph return CF_NODEV;
12318563Sralph }
12418563Sralph else
12518563Sralph {
12618563Sralph DEBUG (4, "df12 ok\n", CNULL);
12718563Sralph return dh;
12818563Sralph }
12918563Sralph }
13018563Sralph
df12cls(fd)13118563Sralph df12cls (fd)
13218563Sralph int fd;
13318563Sralph {
13418563Sralph char dcname[20];
13518563Sralph struct sgttyb hup,
13618563Sralph sav;
13718563Sralph
13818563Sralph if (fd > 0)
13918563Sralph {
14018563Sralph sprintf (dcname, "/dev/%s", devSel);
14118563Sralph DEBUG (4, "Hanging up fd = %d\n", fd);
14218563Sralph /*
14318563Sralph * code to drop DTR -- change to 0 baud then back to default.
14418563Sralph */
14518563Sralph gtty (fd, &hup);
14618563Sralph gtty (fd, &sav);
14718563Sralph hup.sg_ispeed = B0;
14818563Sralph hup.sg_ospeed = B0;
14918563Sralph stty (fd, &hup);
15018563Sralph sleep (2);
15118563Sralph stty (fd, &sav);
15218563Sralph /*
15318563Sralph * now raise DTR -- close the device & open it again.
15418563Sralph */
15518563Sralph sleep (2);
15618563Sralph close (fd);
15718563Sralph sleep (2);
15818563Sralph delock (devSel);
15918563Sralph }
16018563Sralph }
161