home *** CD-ROM | disk | FTP | other *** search
- /*
- * MODEM.C
- *
- * (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
- *
- */
-
- #include "includes.h"
- #include "uucp.h"
- #include "log.h"
-
- Prototype void openline (void);
- Prototype int get_baud (void);
- Prototype void modem_init (void);
- Prototype char *dial_nbr (const char *);
- Prototype void reset_modem (void);
-
- /*
- * NOTE: modem stuff pretty much ignored if we are run from
- * a getty.
- */
-
- #define MULTIMODEM /* I have a multi-modem */
-
- void
- openline (void)
- {
- int
- to = 0;
- char
- *ptr;
-
- if (ptr = FindConfig (CTIMEOUT))
- to = atoi (ptr);
-
- signal (SIGINT, sigint);
- IgnoreCD |= 4;
-
- do {
- chkabort ();
- } while (instr ("CONNECT", 7, to));
-
- #ifdef MULTIMODEM
-
- #else
- set_baud (get_baud ());
- #endif
- Delay (120); /* sleep 2.4 seconds */
-
- IgnoreCD &= ~4;
-
- return;
- }
-
- #ifndef MULTIMODEM
-
- int
- get_baud (void)
- {
- /* We've seen the CONNECT message, now we must see what baud rate
- we've connected with */
- /* gather input until \r then see if it's 300, 1200, 2400, etc. */
- /* this is for hayes compatibles */
-
- int
- rate_inx = 0,
- data;
- char
- rate [10];
-
- DEBUG (2,"looking for baud rate\n",0);
-
- while (((data = xgetc (BYTE_TO, 0)) != EOF) && ((char) data != '\r')) {
- if ((char) data == ' ')
- continue;
- rate [rate_inx++] = (char) data;
- }
- DEBUG (2, "found baud rate of %s\n", rate);
-
- if (strncmp (rate, "1200", 4) == 0)
- return 1200;
- if (strncmp (rate, "2400", 4) == 0)
- return 2400;
- if (strncmp (rate, "4800", 4) == 0)
- return 4800;
- if (strncmp (rate, "9600", 4) == 0)
- return 9600;
- if (strncmp (rate, "14400", 5) == 0)
- return 19200; /* no mistake */
- if (strncmp (rate, "19200", 5) == 0)
- return 19200;
-
- if (rate_inx == 0)
- return 300;
-
- return 1200; /* default */
- }
- #endif
-
- void
- modem_init (void)
- {
- reset_modem ();
- return;
- }
-
- /*
- * Simple dialer routine. Needs replacement with a full blown
- * script driven dialer. Next week maybe :-). FIXME.
- *
- * return 0 on success
- */
-
- char *
- dial_nbr (const char *nbr)
- {
- char
- *dial,
- *errmsg = NULL;
- int
- to = 0;
- static char
- buf [64];
-
- if (dial = FindConfig (CTIMEOUT))
- to = atoi (dial);
-
- IgnoreCD |= 4;
-
- /*
- * Clear any queued data
- */
-
- while (xgetc (0, 0) != EOF)
- ;
-
- /*
- * Start dial sequence
- */
-
- twrite ("\rAT\r", 4);
- Delay (50);
-
- if (dial = FindConfig (MODEMINIT))
- xlat_str (dial);
- dial = malloc (strlen (nbr) + 16);
- dial [0] = 0;
- if (strnicmp (nbr, "AT", 2) != 0)
- strcpy (dial, "ATDT");
- strcat (dial, nbr);
- strcat (dial, "\r");
-
- DEBUG (2, "dialing %s\n", dial);
- twrite (dial, strlen (dial));
-
- for (;;) {
- if (inline (to, buf, sizeof (buf)) < 0) {
- errmsg = "Timeout";
- break;
- }
- if (strnicmp (buf, "CONNECT", 7) == 0)
- break;
- if (strnicmp (buf, "NO CARRIER", 10) == 0 ||
- strnicmp (buf, "ERROR", 5) == 0 ||
- strnicmp (buf, "NO DIAL", 7) == 0 ||
- strnicmp (buf, "BUSY", 4) == 0 ||
- strnicmp (buf, "NO ANSWER", 8) == 0) {
- errmsg = buf;
- break;
- }
- }
-
- IgnoreCD &= ~4;
-
- free (dial);
-
- return errmsg;
- }
-
- /*
- * RESET_MODEM()
- *
- * If run from a Getty we do NOT reset the modem, which would
- * disconnect an already connected connection.
- *
- * Note that the delay between CloseSerial() and OpenSerial() only
- * serves to give the Getty, if running, time to lock the port and
- * begin a disconnect sequence.
- */
-
- void
- reset_modem (void)
- {
- if (Getty || Overide) /* called from a getty */
- return;
-
- DEBUG (4, "Beg-Reset\n", 0);
-
- while (xgetc (QUICK_TO, 0) != EOF)
- /* Eat extraneous chars. */
- ;
-
- if (CheckCarrier ()) {
- if (IgnoreDTR) {
- Delay (50 * 2);
- xwrite ("+", 1);
- Delay (10);
- xwrite ("+", 1);
- Delay (10);
- xwrite ("+", 1);
- Delay (50 * 3);
- xwrite ("ATH0\r", 5);
- Delay (50 * 5);
- /* Should we eat "No carrier"? */
- }
- else {
- CloseSerial (0); /* drop dtr */
- Delay (50 * 5); /* delay 5 seconds */
- DEBUG (4, "End-Reset-1\n", 0);
- OpenSerial (0); /* re-open serial */
- }
- }
- else {
- xwrite ("\r", 1); /* hangup the dial? */
- }
- DEBUG (4, "End-Reset-2\n", 0);
-
- return;
- }
-