Sort out (fix) the `term' command.

datalink_Up() can now be told to skip the dial/login/hangup
scripts and can be told whether to enter packet mode when
entering the DATALINK_OPENED state.
This commit is contained in:
Brian Somers 1998-02-17 01:05:47 +00:00
parent eaf65a3609
commit c5a5a6ca93
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33449
6 changed files with 93 additions and 48 deletions

View file

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.9 1998/02/15 23:59:39 brian Exp $
* $Id: bundle.c,v 1.1.2.10 1998/02/16 19:09:37 brian Exp $
*/
#include <sys/param.h>
@ -554,10 +554,15 @@ bundle_LinkClosed(struct bundle *bundle, struct datalink *dl)
if (!(mode & MODE_AUTO))
bundle_DownInterface(bundle);
if (mode & MODE_DDIAL)
datalink_Up(dl);
datalink_Up(dl, 1, 1);
else
bundle_NewPhase(bundle, NULL, PHASE_DEAD);
if (mode & MODE_INTER)
prompt_Display(&prompt, bundle);
}
void
@ -616,10 +621,12 @@ bundle_Open(struct bundle *bundle, const char *name)
* Please open the given datalink, or all if name == NULL
*/
struct datalink *dl;
int runscripts;
runscripts = (mode & (MODE_DIRECT|MODE_DEDICATED)) ? 0 : 1;
for (dl = bundle->links; dl; dl = dl->next)
if (name == NULL || !strcasecmp(dl->name, name)) {
datalink_Up(dl);
datalink_Up(dl, runscripts, 1);
if (name != NULL)
break;
}

View file

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.19 1998/02/16 19:10:30 brian Exp $
* $Id: command.c,v 1.131.2.20 1998/02/16 19:10:57 brian Exp $
*
*/
#include <sys/param.h>
@ -779,17 +779,18 @@ ShowCommand(struct cmdargs const *arg)
static int
TerminalCommand(struct cmdargs const *arg)
{
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
if (LcpInfo.fsm.state > ST_CLOSED) {
prompt_Printf(&prompt, "LCP state is [%s]\n",
StateNames[LcpInfo.fsm.state]);
return 1;
}
if (!IsInteractive(1))
return (1);
if (modem_Open(bundle2physical(arg->bundle, NULL), arg->bundle) < 0) {
prompt_Printf(&prompt, "Failed to open modem.\n");
return (1);
}
datalink_Up(dl, 0, 0);
prompt_Printf(&prompt, "Entering terminal mode.\n");
prompt_Printf(&prompt, "Type `~?' for help.\n");
prompt_TtyTermMode(&prompt);

View file

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.4 1998/02/16 19:10:35 brian Exp $
* $Id: datalink.c,v 1.1.2.5 1998/02/16 19:10:59 brian Exp $
*/
#include <sys/param.h>
@ -98,8 +98,8 @@ datalink_HangupDone(struct datalink *dl)
dl->state = DATALINK_CLOSED;
dl->dial_tries = -1;
dl->reconnect_tries = 0;
datalink_StartDialTimer(dl, dl->dial_timeout);
bundle_LinkClosed(dl->bundle, dl);
datalink_StartDialTimer(dl, dl->dial_timeout);
} else {
LogPrintf(LogPHASE, "%s: Entering OPENING state\n", dl->name);
dl->state = DATALINK_OPENING;
@ -117,6 +117,28 @@ datalink_HangupDone(struct datalink *dl)
}
}
static void
datalink_LoginDone(struct datalink *dl)
{
dl->dial_tries = 0;
if (modem_Raw(dl->physical, dl->bundle) < 0) {
LogPrintf(LogWARN, "datalink_LoginDone: Not connected.\n");
if (dl->script.run) {
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
modem_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->script.hangup, 1);
} else
datalink_HangupDone(dl);
} else {
LogPrintf(LogPHASE, "%s: Entering OPEN state\n", dl->name);
dl->state = DATALINK_OPEN;
dl->dial_tries = -1;
if (dl->script.packetmode)
PacketMode(dl->bundle, VarOpenMode);
}
}
static int
datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
int *n)
@ -134,12 +156,15 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
if (--dl->dial_tries < 0)
dl->dial_tries = 0;
if (modem_Open(dl->physical, dl->bundle) >= 0) {
LogPrintf(LogPHASE, "%s: Entering DIAL state\n", dl->name);
dl->state = DATALINK_DIAL;
chat_Init(&dl->chat, dl->physical, dl->script.dial, 1);
if (!(mode & MODE_DDIAL) && dl->max_dial)
LogPrintf(LogCHAT, "%s: Dial attempt %u of %d\n",
dl->name, dl->max_dial - dl->dial_tries, dl->max_dial);
if (dl->script.run) {
LogPrintf(LogPHASE, "%s: Entering DIAL state\n", dl->name);
dl->state = DATALINK_DIAL;
chat_Init(&dl->chat, dl->physical, dl->script.dial, 1);
if (!(mode & MODE_DDIAL) && dl->max_dial)
LogPrintf(LogCHAT, "%s: Dial attempt %u of %d\n",
dl->name, dl->max_dial - dl->dial_tries, dl->max_dial);
} else
datalink_LoginDone(dl);
} else {
if (!(mode & MODE_DDIAL) && dl->max_dial)
LogPrintf(LogCHAT, "Failed to open modem (attempt %u of %d)\n",
@ -153,8 +178,8 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
dl->reconnect_tries = 0;
dl->dial_tries = -1;
bundle_LinkClosed(dl->bundle, dl);
} else
datalink_StartDialTimer(dl, dl->dial_timeout);
}
datalink_StartDialTimer(dl, dl->dial_timeout);
}
}
break;
@ -176,19 +201,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
chat_Init(&dl->chat, dl->physical, dl->script.login, 0);
break;
case DATALINK_LOGIN:
dl->dial_tries = 0;
if (modem_Raw(dl->physical, dl->bundle) < 0) {
LogPrintf(LogWARN, "PacketMode: Not connected.\n");
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
modem_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->script.hangup, 1);
} else {
LogPrintf(LogPHASE, "%s: Entering OPEN state\n", dl->name);
dl->state = DATALINK_OPEN;
dl->dial_tries = -1;
PacketMode(dl->bundle, VarOpenMode);
}
datalink_LoginDone(dl);
break;
}
break;
@ -315,6 +328,7 @@ datalink_Create(const char *name, struct bundle *bundle)
free(dl);
return NULL;
}
chat_Init(&dl->chat, dl->physical, NULL, 1);
IpcpDefAddress();
LcpInit(dl->bundle, dl->physical);
@ -343,13 +357,15 @@ datalink_Destroy(struct datalink *dl)
}
void
datalink_Up(struct datalink *dl)
datalink_Up(struct datalink *dl, int runscripts, int packetmode)
{
if (dl->state == DATALINK_CLOSED) {
LogPrintf(LogPHASE, "%s: Entering OPENING state\n", dl->name);
dl->state = DATALINK_OPENING;
dl->reconnect_tries = dl->max_reconnect;
dl->dial_tries = dl->max_dial;
dl->script.run = runscripts;
dl->script.packetmode = packetmode;
}
}
@ -378,17 +394,20 @@ datalink_Down(struct datalink *dl, int stay)
else
FsmOpen(&CcpInfo.fsm);
if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) {
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
modem_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->script.hangup, 1);
}
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
}
if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) {
modem_Offline(dl->physical);
if (dl->script.run) {
LogPrintf(LogPHASE, "%s: Entering HANGUP state\n", dl->name);
dl->state = DATALINK_HANGUP;
chat_Init(&dl->chat, dl->physical, dl->script.hangup, 1);
} else
datalink_HangupDone(dl);
}
}
void

View file

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.h,v 1.1.2.3 1998/02/16 19:10:36 brian Exp $
* $Id: datalink.h,v 1.1.2.4 1998/02/16 19:11:01 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -43,6 +43,8 @@ struct datalink {
char dial[SCRIPT_LEN]; /* dial */
char login[SCRIPT_LEN]; /* login */
char hangup[SCRIPT_LEN]; /* hangup */
unsigned run : 1; /* run scripts ? */
unsigned packetmode : 1; /* Go into packet mode after login ? */
} script;
struct pppTimer dial_timer; /* For timing between opens & scripts */
@ -64,7 +66,6 @@ struct datalink {
#endif
struct bundle *bundle; /* for the moment */
struct datalink *next; /* Next in the list */
};
@ -74,7 +75,7 @@ struct datalink {
extern struct datalink *datalink_Create(const char *name, struct bundle *);
extern struct datalink *datalink_Destroy(struct datalink *);
extern void datalink_Up(struct datalink *);
extern void datalink_Up(struct datalink *, int, int);
extern void datalink_Close(struct datalink *, int);
extern void datalink_Down(struct datalink *, int);
extern void datalink_StayDown(struct datalink *);

View file

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.22 1998/02/16 00:00:31 brian Exp $
* $Id: main.c,v 1.121.2.23 1998/02/16 19:09:55 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -523,10 +523,7 @@ DoLoop(struct bundle *bundle)
struct tun_data tun;
#define rbuff tun.data
if (mode & (MODE_DIRECT|MODE_DEDICATED))
bundle_Open(bundle, NULL);
if (mode & MODE_BACKGROUND)
if (mode & (MODE_DIRECT|MODE_DEDICATED|MODE_BACKGROUND))
bundle_Open(bundle, NULL);
while (!CleaningUp || bundle_Phase(SignalBundle) != PHASE_DEAD) {

View file

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: prompt.c,v 1.1.2.2 1998/02/13 05:10:23 brian Exp $
* $Id: prompt.c,v 1.1.2.3 1998/02/16 00:00:58 brian Exp $
*/
#include <sys/param.h>
@ -57,6 +57,8 @@
#include "mbuf.h"
#include "link.h"
#include "physical.h"
#include "chat.h"
#include "datalink.h"
static int prompt_nonewline = 1;
@ -111,11 +113,29 @@ static void
prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
{
struct prompt *p = descriptor2prompt(d);
struct physical *physical;
struct datalink *dl;
int n;
char ch;
static int ttystate;
char linebuff[LINE_LEN];
if (p->TermMode) {
physical = bundle2physical(bundle, NULL);
dl = bundle2datalink(bundle, NULL);
if (!link_IsActive(&physical->link)) {
if (dl->state == DATALINK_CLOSED) {
prompt_Printf(p, "Exiting terminal mode.\n");
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;
prompt_Display(&prompt, bundle);
}
/* Otherwise, we're not yet active (still OPENING) */
return;
}
}
LogPrintf(LogDEBUG, "descriptor2prompt; %p -> %p\n", d, p);
LogPrintf(LogDEBUG, "termode = %d, p->fd_in = %d, mode = %d\n",
p->TermMode, p->fd_in, mode);