home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
newc_dev
/
uucicosd.lha
/
modem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-02
|
5KB
|
262 lines
/*
* MODEM.C
*
* (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
*
* $Header: Beta:src/uucp/src/uucico/RCS/modem.c,v 1.1 90/02/02 11:56:00 dillon Exp Locker: dillon $
*/
#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 */
extern int Getty;
extern int IgnoreCD;
void
openline()
{
int to = 0;
{
char *ptr;
if (ptr = FindConfig(CTIMEOUT))
to = atoi(ptr);
}
signal(SIGINT,sigint);
IgnoreCD |= 4;
start_again:
chkabort();
if (instr("CONNECT", 7, to))
goto start_again;
#ifdef MULTIMODEM
#else
set_baud(get_baud());
#endif
Delay(120); /* sleep 2 seconds */
IgnoreCD &= ~4;
}
#ifndef MULTIMODEM
int
get_baud()
{
/* 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, or 2400 */
/* this is for hayes compatibles */
int data;
char rate[10];
int rate_inx = 0;
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 (rate_inx == 0) return 300;
return 1200; /* default */
}
#endif
void
modem_init()
{
reset_modem();
}
/*
* Simple dialer routine. Needs replacement with a full blown
* script driven dialer. Next week maybe :-). FIXME.
*
* return 0 on success
*/
char *
dial_nbr(nbr)
const char *nbr;
{
char *dial;
char *errmsg = NULL;
int i;
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()
{
if (Getty) /* 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*2);
} else {
CloseSerial(0); /* drop dtr */
Delay(50*3); /* delay 3 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);
}
#ifdef NOTDEF
if (GettyCmd(DeviceName, DeviceUnit, '0', NULL) == 0)
return;
/*
* Getty doesn't exist, we have to reset the modem ourselves!
*/
IgnoreCD |= 4;
#ifdef MULTIMODEM
set_baud(19200);
if (CheckCarrier()) {
Delay(60);
twrite("+++", 3);
Delay(120);
}
twrite("ATZ\r", 4);
instr("OK\r\n", 4, 3);
twrite("ATH0\r", 5);
instr("OK\r\n", 4, 3);
twrite("ATZ\r", 4);
instr("OK\r\n", 4, 3);
/*amiga_closeopen();*/
sprintf(init, "%s\r", "ATM0S0=2X4$BA0");
if (debug > 0)
init[3] = '1';
twrite(init, strlen(init));
instr("OK\r\n", 4, 3);
#else
twrite("+++", 3);
Delay(60);
twrite("ATH0\r", 5);
Delay(120);
twrite("ATZ\r", 4);
Delay(60);
twrite("ATZ\r", 4);
Delay(60);
sprintf(init, "%s\r", "ATS2");
twrite(init, strlen(init));
Delay(60);
#endif
IgnoreCD &= ~4;
}
#endif