📄 modem.c
字号:
panic();
} /* if */
/*--------------------------------------------------------------------*/
/* Set the modem speed */
/*--------------------------------------------------------------------*/
if ( xspeed == 0)
speed = inspeed;
else
speed = xspeed;
/*--------------------------------------------------------------------*/
/* Open the communications port */
/*--------------------------------------------------------------------*/
norecovery = FALSE; // Shutdown gracefully as needed
if (activeopenline(M_device, speed, bmodemflag[MODEM_DIRECT] ))
panic();
/*--------------------------------------------------------------------*/
/* Initialize stats */
/*--------------------------------------------------------------------*/
memset( &remote_stats, 0, sizeof remote_stats);
/* Clear remote stats for login */
time(&remote_stats.ltime); /* Remember time of last attempt conn */
remote_stats.calls ++ ;
if (bmodemflag[MODEM_CD])
CD(); /* Set the carrier detect flags */
return CONN_HOTLOGIN;
} /* callhot */
/*--------------------------------------------------------------------*/
/* c a l l i n */
/* */
/* Answer the modem in passive mode */
/*--------------------------------------------------------------------*/
CONN_STATE callin( const time_t exit_time )
{
char c; /* A character for input buffer */
int offset; /* Time to wait for telephone */
time_t left;
/*--------------------------------------------------------------------*/
/* Determine how long we can wait for the telephone, up to */
/* SHRT_MAX seconds. Aside from Turbo C limits, this insures we */
/* kick the modem once in a while. */
/*--------------------------------------------------------------------*/
left = exit_time - time(NULL);
if ( left < 0 ) /* Any time left? */
return CONN_EXIT; /* No --> shutdown */
if ( left > SHRT_MAX)
offset = SHRT_MAX;
else
offset = (int) left;
/*--------------------------------------------------------------------*/
/* Open the serial port */
/*--------------------------------------------------------------------*/
if (E_inmodem == NULL)
{
printmsg(0,"callin: No modem name supplied for incoming calls!");
panic();
} /* if */
/*--------------------------------------------------------------------*/
/* Open the communications port */
/*--------------------------------------------------------------------*/
norecovery = FALSE; // Shutdown gracefully as needed
/*--------------------------------------------------------------------*/
/* Flush the input buffer of any characters */
/*--------------------------------------------------------------------*/
if ( IsNetwork() )
{
if (passiveopenline(M_device, inspeed, bmodemflag[MODEM_DIRECT]))
panic();
}
else {
if (((ring == NULL) || (inspeed == 0)))
{
printmsg(0,"callin: Missing inspeed and/or ring values in modem "
"configuration file.");
panic();
} /* if */
if (passiveopenline(M_device, inspeed, bmodemflag[MODEM_DIRECT]))
panic();
while (sread(&c ,1,0)); /* Discard trailing trash from modem
connect message */
/*--------------------------------------------------------------------*/
/* Initialize the modem */
/*--------------------------------------------------------------------*/
if (!sendlist( initialize, modemTimeout, modemTimeout, NULL))
{
printmsg(0,"callin: Modem failed to initialize");
shutDown();
panic();
}
} /* else */
/*--------------------------------------------------------------------*/
/* Wait for the telephone to ring */
/*--------------------------------------------------------------------*/
printmsg(1,"Monitoring port %s device %s"
" for %d minutes until %s",
M_device, E_inmodem , (int) (offset / 60),
(left > hhmm2sec(10000)) ?
"user hits Ctrl-Break" :
dater( exit_time , NULL));
interactive_processing = FALSE;
if (IsNetwork())
{ /* Network connect is different */
if (!WaitForNetConnect(offset))
{
interactive_processing = TRUE;
shutDown();
if ( suspend_processing ) // Give up modem for another process?
{
return CONN_WAIT;
}
return CONN_INITIALIZE;
}
interactive_processing = TRUE;
printmsg(14, "callin: Modem reports connected");
}
else {
if (!sendlist( ring,modemTimeout, offset, noconnect))
{ /* Did it ring? */
interactive_processing = TRUE;
raised = 0;
shutDown();
if ( suspend_processing ) // Give up modem for another process?
return CONN_WAIT;
else
return CONN_INITIALIZE; /* No --> Return to caller */
}
interactive_processing = TRUE;
setPrty(M_priority, M_prioritydelta );
// Into warp drive for actual transfers
if(!sendlist(answer, modemTimeout,answerTimeout, noconnect))
{ /* Pick up the telephone */
printmsg(1,"callin: Modem failed to connect to incoming call");
shutDown();
return CONN_INITIALIZE;
}
printmsg(14, "callin: Modem reports connected");
autobaud(inspeed); /* autobaud the modem */
/*--------------------------------------------------------------------*/
/* Flush the input buffer of any other input characters */
/*--------------------------------------------------------------------*/
while (sread(&c ,1,0)); /* Discard trailing trash from modem
connect message */
} /* else */
memset( &remote_stats, 0, sizeof remote_stats);
/* Clear remote stats for login */
time(&remote_stats.ltime); /* Remember time of last attempt conn */
remote_stats.calls ++ ;
return CONN_LOGIN;
} /* callin */
/*--------------------------------------------------------------------*/
/* g e t m o d e m */
/* */
/* Read a modem configuration file */
/*--------------------------------------------------------------------*/
boolean getmodem( const char *brand)
{
char filename[FILENAME_MAX];
static char *modem = NULL;
FILE *fp;
CONFIGTABLE *tptr;
size_t subscript;
boolean success;
/*--------------------------------------------------------------------*/
/* Validate the modem name */
/* Added check for validity of modem ptr -- makes NT happier - dmw */
/*--------------------------------------------------------------------*/
if ((modem != NULL) && equal(modem, brand)) /* Already initialized?*/
return TRUE; /* Yes --> Don't process it again */
/*--------------------------------------------------------------------*/
/* Initialize the table */
/*--------------------------------------------------------------------*/
for (tptr = modemtable; tptr->sym != nil(char); tptr++)
if (tptr->bits & (B_TOKEN | B_STRING | B_LIST | B_CLIST))
*(tptr->loc) = nil(char);
for (subscript = 0; subscript < MODEM_LAST; subscript++)
bmodemflag[subscript] = FALSE;
M_charDelay = 00; /* Default is no delay between chars */
dialTimeout = 40; /* Default is 40 seconds to dial phone */
gPacketSize = SMALL_PACKET;
vPacketSize = MAXPACK;
GPacketSize = MAXPACK;
gWindowSize = 0;
vWindowSize = 0;
GWindowSize = 0;
M_fPacketSize = MAXPACK;
M_fPacketTimeout = 20;
M_gPacketTimeout = 10;
M_tPacketTimeout = 60;
modemTimeout = 3; /* Default is 3 seconds for modem cmds */
scriptTimeout = 30; /* Default is 30 seconds for script data*/
answerTimeout = 30; /* Default is 30 seconds to answer phone*/
M_xfer_bufsize = BUFSIZ; /* Buffering used for file transfers */
M_MaxErr= 10; /* Allowed errors per single packet */
M_suite = NULL; // Use default suite for communications
M_startupTimeout = 40; // 40 seconds per message to exchange protocols
M_priority = 999;
M_prioritydelta = 999;
/*--------------------------------------------------------------------*/
/* Open the modem configuration file */
/*--------------------------------------------------------------------*/
if (equaln(brand,"COM",3))
{
printmsg(0,"Modem type %s is invalid; Snuffles suspects "
"your %s file is obsolete.", brand, E_systems);
panic();
}
sprintf(filename,"%s/%s.MDM",E_confdir, brand);
if ((fp = FOPEN(filename, "r",TEXT_MODE)) == nil(FILE))
{
printmsg(0,"getmodem: Unable to locate configuration for %s",
brand);
printerr( filename );
return FALSE;
}
/*--------------------------------------------------------------------*/
/* We got the file open, now process it */
/*--------------------------------------------------------------------*/
printmsg(3,"getmodem: loading modem configuration file %s", filename);
success = getconfig(fp, MODEM_CONFIG, B_UUCICO, modemtable, modemFlags);
fclose(fp);
if (!success)
return FALSE;
/*--------------------------------------------------------------------*/
/* Verify all required modem parameters were supplied */
/*--------------------------------------------------------------------*/
success = TRUE;
for (tptr = modemtable; tptr->sym != nil(char); tptr++) {
if ((tptr->bits & (B_REQUIRED | B_FOUND)) == B_REQUIRED)
{
printmsg(0, "getmodem: configuration parameter \"%s\" must be set.",
tptr->sym);
success = FALSE;
} /* if */
} /* for */
if ( ! success ) // Missing any required inputs?
return success; // Yes --> Return failure to caller
/*--------------------------------------------------------------------*/
/* The strings are valid, try to initialize the pointers to */
/* the processing routines. */
/*--------------------------------------------------------------------*/
if ( ! chooseCommunications( M_suite ))
return FALSE;
/*--------------------------------------------------------------------*/
/* We have success, save modem name for next time to speed */
/* initialize. */
/*--------------------------------------------------------------------*/
modem = newstr(brand); /* Yes --> Remember it for next time */
return TRUE;
} /* getmodem */
/*--------------------------------------------------------------------*/
/* d i a l */
/* */
/* Generic modem dialer; only major limitation is that autoabaud */
/* strings are not configurable */
/*--------------------------------------------------------------------*/
static boolean dial(char *number, const BPS speed)
{
char buf[81];
/*--------------------------------------------------------------------*/
/* Open the serial port */
/*--------------------------------------------------------------------*/
norecovery = FALSE; // Shutdown gracefully as needed
/*--------------------------------------------------------------------*/
/* Flush the input buffer of any characters */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -