xref: /freebsd/usr.sbin/ppp/fsm.h (revision 3b0f8d2ed641ceeded11c0d3f253b0cacbf00880)
11ae349f5Scvs2svn /*
21ae349f5Scvs2svn  *	    Written by Toshiharu OHNO (tony-o@iij.ad.jp)
31ae349f5Scvs2svn  *
41ae349f5Scvs2svn  *   Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
51ae349f5Scvs2svn  *
61ae349f5Scvs2svn  * Redistribution and use in source and binary forms are permitted
71ae349f5Scvs2svn  * provided that the above copyright notice and this paragraph are
81ae349f5Scvs2svn  * duplicated in all such forms and that any documentation,
91ae349f5Scvs2svn  * advertising materials, and other materials related to such
101ae349f5Scvs2svn  * distribution and use acknowledge that the software was developed
111ae349f5Scvs2svn  * by the Internet Initiative Japan.  The name of the
121ae349f5Scvs2svn  * IIJ may not be used to endorse or promote products derived
131ae349f5Scvs2svn  * from this software without specific prior written permission.
141ae349f5Scvs2svn  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
151ae349f5Scvs2svn  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
161ae349f5Scvs2svn  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
171ae349f5Scvs2svn  *
183b0f8d2eSBrian Somers  * $Id: fsm.h,v 1.16.2.12 1998/03/24 18:46:59 brian Exp $
191ae349f5Scvs2svn  *
201ae349f5Scvs2svn  *	TODO:
211ae349f5Scvs2svn  */
221ae349f5Scvs2svn 
231ae349f5Scvs2svn /*
241ae349f5Scvs2svn  *  State of machine
251ae349f5Scvs2svn  */
261ae349f5Scvs2svn #define	ST_INITIAL	0
271ae349f5Scvs2svn #define	ST_STARTING	1
281ae349f5Scvs2svn #define	ST_CLOSED	2
291ae349f5Scvs2svn #define	ST_STOPPED	3
301ae349f5Scvs2svn #define	ST_CLOSING	4
311ae349f5Scvs2svn #define	ST_STOPPING	5
321ae349f5Scvs2svn #define	ST_REQSENT	6
331ae349f5Scvs2svn #define	ST_ACKRCVD	7
341ae349f5Scvs2svn #define	ST_ACKSENT	8
351ae349f5Scvs2svn #define	ST_OPENED	9
361ae349f5Scvs2svn 
371ae349f5Scvs2svn #define	ST_MAX		10
381ae349f5Scvs2svn #define	ST_UNDEF	-1
391ae349f5Scvs2svn 
401ae349f5Scvs2svn #define	MODE_REQ	0
411ae349f5Scvs2svn #define	MODE_NAK	1
421ae349f5Scvs2svn #define	MODE_REJ	2
431ae349f5Scvs2svn #define	MODE_NOP	3
441ae349f5Scvs2svn #define	MODE_ACK	4	/* pseudo mode for ccp negotiations */
451ae349f5Scvs2svn 
461ae349f5Scvs2svn #define	OPEN_PASSIVE	-1
471ae349f5Scvs2svn 
4883d1af55SBrian Somers struct fsm;
4983d1af55SBrian Somers 
5030c2f2ffSBrian Somers struct fsm_decode {
5130c2f2ffSBrian Somers   u_char ack[100], *ackend;
5230c2f2ffSBrian Somers   u_char nak[100], *nakend;
5330c2f2ffSBrian Somers   u_char rej[100], *rejend;
5430c2f2ffSBrian Somers };
5530c2f2ffSBrian Somers 
566d666775SBrian Somers struct fsm_callbacks {
5783d1af55SBrian Somers   void (*LayerUp) (struct fsm *);            /* Layer is now up (tlu) */
5883d1af55SBrian Somers   void (*LayerDown) (struct fsm *);          /* About to come down (tld) */
5983d1af55SBrian Somers   void (*LayerStart) (struct fsm *);         /* Layer about to start up (tls) */
6083d1af55SBrian Somers   void (*LayerFinish) (struct fsm *);        /* Layer now down (tlf) */
6183d1af55SBrian Somers   void (*InitRestartCounter) (struct fsm *); /* Set fsm timer load */
6283d1af55SBrian Somers   void (*SendConfigReq) (struct fsm *);      /* Send REQ please */
632267893fSBrian Somers   void (*SentTerminateReq) (struct fsm *);   /* Term REQ just sent */
642267893fSBrian Somers   void (*SendTerminateAck) (struct fsm *, u_char); /* Send Term ACK please */
6530c2f2ffSBrian Somers   void (*DecodeConfig) (struct fsm *, u_char *, int, int, struct fsm_decode *);
66503a7782SBrian Somers                                              /* Deal with incoming data */
67503a7782SBrian Somers   void (*RecvResetReq) (struct fsm *fp);         /* Reset output */
68503a7782SBrian Somers   void (*RecvResetAck) (struct fsm *fp, u_char); /* Reset input */
6983d1af55SBrian Somers };
7083d1af55SBrian Somers 
716d666775SBrian Somers struct fsm_parent {
726d666775SBrian Somers   void (*LayerStart) (void *, struct fsm *);         /* tls */
736d666775SBrian Somers   void (*LayerUp) (void *, struct fsm *);            /* tlu */
746d666775SBrian Somers   void (*LayerDown) (void *, struct fsm *);          /* tld */
756d666775SBrian Somers   void (*LayerFinish) (void *, struct fsm *);        /* tlf */
766d666775SBrian Somers   void *object;
776d666775SBrian Somers };
786d666775SBrian Somers 
791ae349f5Scvs2svn struct fsm {
801ae349f5Scvs2svn   const char *name;		/* Name of protocol */
811ae349f5Scvs2svn   u_short proto;		/* Protocol number */
823b0f8d2eSBrian Somers   u_short min_code;
831ae349f5Scvs2svn   u_short max_code;
847308ec68SBrian Somers   int open_mode;		/* Delay before config REQ (-1 forever) */
851ae349f5Scvs2svn   int state;			/* State of the machine */
861ae349f5Scvs2svn   u_char reqid;			/* Next request id */
871ae349f5Scvs2svn   int restart;			/* Restart counter value */
883b0f8d2eSBrian Somers   int maxconfig;		/* Max config REQ before a close() */
891ae349f5Scvs2svn 
901ae349f5Scvs2svn   struct pppTimer FsmTimer;	/* Restart Timer */
911ae349f5Scvs2svn   struct pppTimer OpenTimer;	/* Delay before opening */
921ae349f5Scvs2svn 
931ae349f5Scvs2svn   /*
941ae349f5Scvs2svn    * This timer times the ST_STOPPED state out after the given value
951ae349f5Scvs2svn    * (specified via "set stopped ...").  Although this isn't specified in the
961ae349f5Scvs2svn    * rfc, the rfc *does* say that "the application may use higher level
971ae349f5Scvs2svn    * timers to avoid deadlock". The StoppedTimer takes effect when the other
981ae349f5Scvs2svn    * side ABENDs rather than going into ST_ACKSENT (and sending the ACK),
991ae349f5Scvs2svn    * causing ppp to time out and drop into ST_STOPPED.  At this point,
1001ae349f5Scvs2svn    * nothing will change this state :-(
1011ae349f5Scvs2svn    */
1021ae349f5Scvs2svn   struct pppTimer StoppedTimer;
1031ae349f5Scvs2svn   int LogLevel;
1041ae349f5Scvs2svn 
1057a6f8720SBrian Somers   /* The link layer active with this FSM (may be our bundle below) */
1068c07a7b2SBrian Somers   struct link *link;
10763b73463SBrian Somers 
1087a6f8720SBrian Somers   /* Our high-level link */
1097a6f8720SBrian Somers   struct bundle *bundle;
1107a6f8720SBrian Somers 
1116d666775SBrian Somers   const struct fsm_parent *parent;
11283d1af55SBrian Somers   const struct fsm_callbacks *fn;
1131ae349f5Scvs2svn };
1141ae349f5Scvs2svn 
1151ae349f5Scvs2svn struct fsmheader {
1161ae349f5Scvs2svn   u_char code;			/* Request code */
1171ae349f5Scvs2svn   u_char id;			/* Identification */
1181ae349f5Scvs2svn   u_short length;		/* Length of packet */
1191ae349f5Scvs2svn };
1201ae349f5Scvs2svn 
1211ae349f5Scvs2svn #define	CODE_CONFIGREQ	1
1221ae349f5Scvs2svn #define	CODE_CONFIGACK	2
1231ae349f5Scvs2svn #define	CODE_CONFIGNAK	3
1241ae349f5Scvs2svn #define	CODE_CONFIGREJ	4
1251ae349f5Scvs2svn #define	CODE_TERMREQ	5
1261ae349f5Scvs2svn #define	CODE_TERMACK	6
1271ae349f5Scvs2svn #define	CODE_CODEREJ	7
1281ae349f5Scvs2svn #define	CODE_PROTOREJ	8
1291ae349f5Scvs2svn #define	CODE_ECHOREQ	9	/* Used in LCP */
1301ae349f5Scvs2svn #define	CODE_ECHOREP	10	/* Used in LCP */
1311ae349f5Scvs2svn #define	CODE_DISCREQ	11
1321ae349f5Scvs2svn #define	CODE_IDENT	12	/* Used in LCP Extension */
1331ae349f5Scvs2svn #define	CODE_TIMEREM	13	/* Used in LCP Extension */
1341ae349f5Scvs2svn #define	CODE_RESETREQ	14	/* Used in CCP */
1351ae349f5Scvs2svn #define	CODE_RESETACK	15	/* Used in CCP */
1361ae349f5Scvs2svn 
1377308ec68SBrian Somers /* Minimum config req size.  This struct is *only* used for it's size */
1381ae349f5Scvs2svn struct fsmconfig {
1391ae349f5Scvs2svn   u_char type;
1401ae349f5Scvs2svn   u_char length;
1411ae349f5Scvs2svn };
1421ae349f5Scvs2svn 
1433b0f8d2eSBrian Somers extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int, int,
1446d666775SBrian Somers                      struct bundle *, struct link *, const  struct fsm_parent *,
1453b0f8d2eSBrian Somers                      struct fsm_callbacks *, const char *[3]);
1461ae349f5Scvs2svn extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int);
1471ae349f5Scvs2svn extern void FsmOpen(struct fsm *);
1481ae349f5Scvs2svn extern void FsmUp(struct fsm *);
1491ae349f5Scvs2svn extern void FsmDown(struct fsm *);
1501ae349f5Scvs2svn extern void FsmInput(struct fsm *, struct mbuf *);
1511ae349f5Scvs2svn extern void FsmClose(struct fsm *);
152503a7782SBrian Somers extern void NullRecvResetReq(struct fsm *fp);
153503a7782SBrian Somers extern void NullRecvResetAck(struct fsm *fp, u_char);
1541e991daaSBrian Somers extern const char *State2Nam(u_int);
155