Add datalink state DATALINK_READY to indicate when the datalink

is available, but LCP hasn't yet been started.  We get to this
state in ``term'' mode.
Remove PacketMode().  LCP startup and shutdown is now controlled
by the datalink.
Add ``show links'' command.
Make ``close'' capable of running with and without a context.
Make ``down'' require a context.
Make ``set parity'' and ``set rtscts'' use the correct context.
This commit is contained in:
Brian Somers 1998-02-17 19:28:35 +00:00
parent 1b35f8f703
commit c7cc50305f
8 changed files with 181 additions and 95 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.11 1998/02/17 01:05:33 brian Exp $
* $Id: bundle.c,v 1.1.2.12 1998/02/17 19:27:45 brian Exp $
*/
#include <sys/param.h>
@ -699,11 +699,14 @@ bundle_FillQueues(struct bundle *bundle)
int
bundle_ShowLinks(struct cmdargs const *arg)
{
struct datalink *dl;
if (arg->cx)
datalink_Show(arg->cx);
else {
struct datalink *dl;
prompt_Printf(&prompt, "The following links are defined:\n");
for (dl = arg->bundle->links; dl; dl = dl->next)
prompt_Printf(&prompt, "\t%s\n", dl->name);
for (dl = arg->bundle->links; dl; dl = dl->next)
datalink_Show(dl);
}
return 0;
}

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.22 1998/02/17 19:27:51 brian Exp $
* $Id: command.c,v 1.131.2.23 1998/02/17 19:28:09 brian Exp $
*
*/
#include <sys/param.h>
@ -346,7 +346,7 @@ static struct cmdtab const Commands[] = {
"Allow ppp access", "allow users|modes ...."},
{"bg", "!bg", BgShellCommand, LOCAL_AUTH,
"Run a background command", "[!]bg command"},
{"close", NULL, CloseCommand, LOCAL_AUTH,
{"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
"Close connection", "close"},
{"delete", NULL, DeleteCommand, LOCAL_AUTH,
"delete route", "delete dest", NULL},
@ -386,7 +386,7 @@ static struct cmdtab const Commands[] = {
"Quit PPP program", "quit|bye [all]"},
{"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
"Display this message", "help|? [command]", Commands},
{NULL, "down", DownCommand, LOCAL_AUTH,
{NULL, "down", DownCommand, LOCAL_AUTH | LOCAL_CX,
"Generate down event", "down"},
{NULL, NULL, NULL},
};
@ -829,14 +829,14 @@ QuitCommand(struct cmdargs const *arg)
static int
CloseCommand(struct cmdargs const *arg)
{
bundle_Close(LcpInfo.fsm.bundle, NULL, 1);
bundle_Close(LcpInfo.fsm.bundle, arg->cx ? arg->cx->name : NULL, 1);
return 0;
}
static int
DownCommand(struct cmdargs const *arg)
{
link_Close(&arg->bundle->links->physical->link, arg->bundle, 0, 1);
link_Close(&arg->cx->physical->link, arg->bundle, 0, 1);
return 0;
}
@ -852,7 +852,7 @@ SetModemSpeed(struct cmdargs const *arg)
return -1;
}
if (strcasecmp(*arg->argv, "sync") == 0) {
Physical_SetSync(arg->bundle->links->physical);
Physical_SetSync(arg->cx->physical);
return 0;
}
end = NULL;
@ -861,7 +861,7 @@ SetModemSpeed(struct cmdargs const *arg)
LogPrintf(LogWARN, "SetModemSpeed: Bad argument \"%s\"", *arg->argv);
return -1;
}
if (Physical_SetSpeed(arg->bundle->links->physical, speed))
if (Physical_SetSpeed(arg->cx->physical, speed))
return 0;
LogPrintf(LogWARN, "%s: Invalid speed\n", *arg->argv);
} else
@ -1041,7 +1041,7 @@ SetServer(struct cmdargs const *arg)
static int
SetModemParity(struct cmdargs const *arg)
{
return arg->argc > 0 ? modem_SetParity(arg->bundle->links->physical, *arg->argv) : -1;
return arg->argc > 0 ? modem_SetParity(arg->cx->physical, *arg->argv) : -1;
}
static int

View file

@ -23,13 +23,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.6 1998/02/17 01:05:38 brian Exp $
* $Id: datalink.c,v 1.1.2.7 1998/02/17 19:27:55 brian Exp $
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <alias.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
@ -57,6 +58,9 @@
#include "modem.h"
#include "iplist.h"
#include "ipcp.h"
#include "prompt.h"
static const char *datalink_State(struct datalink *);
static void
datalink_OpenTimeout(void *v)
@ -131,11 +135,23 @@ datalink_LoginDone(struct datalink *dl)
} 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);
if (dl->script.packetmode) {
int openmode;
openmode = dl->state == DATALINK_READY ? 0 : VarOpenMode;
LogPrintf(LogPHASE, "%s: Entering OPEN state\n", dl->name);
dl->state = DATALINK_OPEN;
LcpInit(dl->bundle, dl->physical);
CcpInit(dl->bundle, &dl->physical->link);
FsmUp(&LcpInfo.fsm);
LcpOpen(openmode);
} else {
LogPrintf(LogPHASE, "%s: Entering READY state\n", dl->name);
dl->state = DATALINK_READY;
}
}
}
@ -223,6 +239,8 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e,
break;
}
break;
case DATALINK_READY:
case DATALINK_OPEN:
result = descriptor_UpdateSet(&dl->physical->desc, r, w, e, n);
break;
@ -237,11 +255,15 @@ datalink_IsSet(struct descriptor *d, fd_set *fdset)
switch (dl->state) {
case DATALINK_CLOSED:
case DATALINK_OPENING:
break;
case DATALINK_HANGUP:
case DATALINK_DIAL:
case DATALINK_LOGIN:
return descriptor_IsSet(&dl->chat.desc, fdset);
case DATALINK_READY:
case DATALINK_OPEN:
return descriptor_IsSet(&dl->physical->desc, fdset);
}
@ -255,12 +277,16 @@ datalink_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
switch (dl->state) {
case DATALINK_CLOSED:
case DATALINK_OPENING:
break;
case DATALINK_HANGUP:
case DATALINK_DIAL:
case DATALINK_LOGIN:
descriptor_Read(&dl->chat.desc, bundle, fdset);
break;
case DATALINK_READY:
case DATALINK_OPEN:
descriptor_Read(&dl->physical->desc, bundle, fdset);
break;
@ -274,12 +300,16 @@ datalink_Write(struct descriptor *d, const fd_set *fdset)
switch (dl->state) {
case DATALINK_CLOSED:
case DATALINK_OPENING:
break;
case DATALINK_HANGUP:
case DATALINK_DIAL:
case DATALINK_LOGIN:
descriptor_Write(&dl->chat.desc, fdset);
break;
case DATALINK_READY:
case DATALINK_OPEN:
descriptor_Write(&dl->physical->desc, fdset);
break;
@ -307,6 +337,8 @@ datalink_Create(const char *name, struct bundle *bundle)
*dl->script.dial = '\0';
*dl->script.login = '\0';
*dl->script.hangup = '\0';
dl->script.run = 1;
dl->script.packetmode = 1;
dl->bundle = bundle;
dl->next = NULL;
@ -334,7 +366,7 @@ datalink_Create(const char *name, struct bundle *bundle)
LcpInit(dl->bundle, dl->physical);
CcpInit(dl->bundle, &dl->physical->link);
LogPrintf(LogPHASE, "%s: Entering CLOSED state\n", dl->name);
LogPrintf(LogPHASE, "%s: Created in CLOSED state\n", dl->name);
return dl;
}
@ -345,7 +377,8 @@ datalink_Destroy(struct datalink *dl)
struct datalink *result;
if (dl->state != DATALINK_CLOSED)
LogPrintf(LogERROR, "Oops, destroying a datalink in state %d\n", dl->state);
LogPrintf(LogERROR, "Oops, destroying a datalink in state %s\n",
datalink_State(dl));
result = dl->next;
chat_Destroy(&dl->chat);
@ -359,41 +392,36 @@ datalink_Destroy(struct datalink *dl)
void
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;
switch (dl->state) {
case 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;
break;
case DATALINK_OPENING:
if (!dl->script.run && runscripts)
dl->script.run = 1;
/* fall through */
case DATALINK_DIAL:
case DATALINK_LOGIN:
case DATALINK_READY:
if (!dl->script.packetmode && packetmode) {
dl->script.packetmode = 1;
if (dl->state == DATALINK_READY)
datalink_LoginDone(dl);
}
break;
}
}
void
datalink_Close(struct datalink *dl, int stay)
static void
datalink_ComeDown(struct datalink *dl, int stay)
{
/* Please close */
FsmClose(&CcpInfo.fsm);
FsmClose(&LcpInfo.fsm);
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
}
}
void
datalink_Down(struct datalink *dl, int stay)
{
/* Carrier is lost */
LogPrintf(LogPHASE, "datalink_Down: %sstay down\n", stay ? "" : "don't ");
FsmDown(&CcpInfo.fsm);
FsmClose(&CcpInfo.fsm);
FsmDown(&LcpInfo.fsm);
if (stay)
FsmClose(&LcpInfo.fsm);
else
FsmOpen(&CcpInfo.fsm);
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
@ -410,8 +438,64 @@ datalink_Down(struct datalink *dl, int stay)
}
}
void
datalink_Close(struct datalink *dl, int stay)
{
/* Please close */
if (dl->state == DATALINK_OPEN) {
FsmClose(&CcpInfo.fsm);
FsmClose(&LcpInfo.fsm);
if (stay) {
dl->dial_tries = -1;
dl->reconnect_tries = 0;
}
} else
datalink_ComeDown(dl, stay);
}
void
datalink_Down(struct datalink *dl, int stay)
{
/* Carrier is lost */
if (dl->state == DATALINK_OPEN) {
FsmDown(&CcpInfo.fsm);
FsmClose(&CcpInfo.fsm);
FsmDown(&LcpInfo.fsm);
if (stay)
FsmClose(&LcpInfo.fsm);
else
FsmOpen(&CcpInfo.fsm);
}
datalink_ComeDown(dl, stay);
}
void
datalink_StayDown(struct datalink *dl)
{
dl->reconnect_tries = 0;
}
void
datalink_Show(struct datalink *dl)
{
prompt_Printf(&prompt, "Link %s: State %s\n", dl->name, datalink_State(dl));
}
static char *states[] = {
"CLOSED",
"OPENING",
"HANGUP",
"DIAL",
"LOGIN",
"READY",
"OPEN"
};
static const char *
datalink_State(struct datalink *dl)
{
if (dl->state < 0 || dl->state >= sizeof states / sizeof states[0])
return "unknown";
return states[dl->state];
}

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.4 1998/02/16 19:11:01 brian Exp $
* $Id: datalink.h,v 1.1.2.5 1998/02/17 01:05:38 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -31,7 +31,8 @@
#define DATALINK_HANGUP (2)
#define DATALINK_DIAL (3)
#define DATALINK_LOGIN (4)
#define DATALINK_OPEN (5)
#define DATALINK_READY (5)
#define DATALINK_OPEN (6)
struct datalink {
struct descriptor desc; /* We play either a physical or a chat */
@ -79,3 +80,4 @@ 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 *);
extern void datalink_Show(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.23 1998/02/16 19:09:55 brian Exp $
* $Id: main.c,v 1.121.2.24 1998/02/17 01:05:43 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -497,23 +497,6 @@ main(int argc, char **argv)
return EX_NORMAL;
}
/*
* Turn into packet mode, where we speak PPP.
*/
void
PacketMode(struct bundle *bundle, int delay)
{
/* XXX which one ? */
LcpInit(bundle, bundle2physical(bundle, NULL));
CcpInit(bundle, bundle2link(bundle, NULL));
FsmUp(&LcpInfo.fsm);
LcpOpen(delay);
prompt_TtyCommandMode(&prompt);
prompt_Printf(&prompt, "Packet mode.\n");
}
static void
DoLoop(struct bundle *bundle)
{

View file

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.h,v 1.9.2.5 1998/02/13 05:10:18 brian Exp $
* $Id: main.h,v 1.9.2.6 1998/02/16 00:00:36 brian Exp $
*
*/
@ -26,6 +26,5 @@ extern int CleaningUp;
extern void Cleanup(int);
extern void AbortProgram(int);
extern void TtyTermMode(void);
extern void PacketMode(struct bundle *, int);
extern void TtyOldMode(void);
extern void TtyCommandMode(struct bundle *, int);

View file

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.77.2.18 1998/02/17 01:05:18 brian Exp $
* $Id: modem.c,v 1.77.2.19 1998/02/17 19:27:57 brian Exp $
*
* TODO:
*/
@ -265,12 +265,19 @@ modem_Timeout(void *data)
* In dedicated mode, start packet mode immediate after we detected
* carrier.
*/
#if 0
/*
* Dedicated links should never have datalink::script.run set, and should
* always have datalink::script.packetmode set - therefore we're going to
* go into packet mode immediately.
*/
#ifdef notyet
if (to->modem->is_dedicated)
PacketMode(to->bundle, VarOpenMode);
#else
if (mode & MODE_DEDICATED)
PacketMode(to->bundle, VarOpenMode);
#endif
#endif
} else {
LogPrintf(LogDEBUG, "modem_Timeout: online -> offline\n");
@ -998,7 +1005,7 @@ modem_DescriptorRead(struct descriptor *d, struct bundle *bundle,
Physical_Write(p, rbuff, cp - rbuff);
Physical_Write(p, "\r\n", 2);
}
PacketMode(bundle, 0);
datalink_Up(bundle2datalink(bundle, p->link.name), 0, 1);
} else
prompt_Printf(&prompt, "%.*s", n, rbuff);
}

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.5 1998/02/17 19:28:00 brian Exp $
* $Id: prompt.c,v 1.1.2.6 1998/02/17 19:28:12 brian Exp $
*/
#include <sys/param.h>
@ -118,18 +118,6 @@ prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
static int ttystate;
char linebuff[LINE_LEN];
if (p->TermMode != NULL) {
if (p->TermMode->state == DATALINK_CLOSED) {
prompt_Printf(p, "Exiting terminal mode.\n");
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;
prompt_Display(&prompt, bundle);
}
if (p->TermMode->state != DATALINK_OPEN)
return;
}
LogPrintf(LogDEBUG, "descriptor2prompt; %p -> %p\n", d, p);
LogPrintf(LogDEBUG, "termode = %p, p->fd_in = %d, mode = %d\n",
p->TermMode, p->fd_in, mode);
@ -152,6 +140,29 @@ prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
return;
}
switch (p->TermMode->state) {
case DATALINK_CLOSED:
prompt_Printf(p, "Link lost, terminal mode.\n");
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;
prompt_Display(&prompt, bundle);
return;
case DATALINK_READY:
break;
case DATALINK_OPEN:
prompt_Printf(p, "\nPacket mode detected.\n");
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;
/* We'll get a prompt because of our status change */
/* Fall through */
default:
/* Wait 'till we're in a state we care about */
return;
}
/*
* We are in terminal mode, decode special sequences
*/
@ -173,13 +184,10 @@ prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
prompt_ShowHelp(p);
break;
case 'p':
/*
* XXX: Should check carrier.
*/
if (LcpInfo.fsm.state <= ST_CLOSED)
PacketMode(bundle, 0);
break;
datalink_Up(p->TermMode, 0, 1);
prompt_Printf(p, "\nPacket mode.\n");
prompt_TtyCommandMode(&prompt);
break;
case '.':
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;