xref: /freebsd/usr.sbin/ppp/fsm.h (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
1 /*
2  *	    Written by Toshiharu OHNO (tony-o@iij.ad.jp)
3  *
4  *   Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that the above copyright notice and this paragraph are
8  * duplicated in all such forms and that any documentation,
9  * advertising materials, and other materials related to such
10  * distribution and use acknowledge that the software was developed
11  * by the Internet Initiative Japan.  The name of the
12  * IIJ may not be used to endorse or promote products derived
13  * from this software without specific prior written permission.
14  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  *
18  * $Id:$
19  *
20  *	TODO:
21  */
22 #ifndef _FSM_H_
23 #define	_FSM_H_
24 
25 #include "defs.h"
26 #include <netinet/in.h>
27 #include "timeout.h"
28 
29 /*
30  *  State of machine
31  */
32 #define	ST_INITIAL	0
33 #define	ST_STARTING	1
34 #define	ST_CLOSED	2
35 #define	ST_STOPPED	3
36 #define	ST_CLOSING	4
37 #define	ST_STOPPING	5
38 #define	ST_REQSENT	6
39 #define	ST_ACKRCVD	7
40 #define	ST_ACKSENT	8
41 #define	ST_OPENED	9
42 
43 #define	ST_MAX		10
44 #define	ST_UNDEF	-1
45 
46 #define	MODE_REQ	0
47 #define	MODE_NAK	1
48 #define	MODE_REJ	2
49 
50 #define	OPEN_ACTIVE	0
51 #define	OPEN_PASSIVE	1
52 
53 struct fsm {
54   char	  *name;		/* Name of protocol */
55   u_short proto;		/* Protocol number */
56   u_short max_code;
57   int	  open_mode;
58   int	  state;		/* State of the machine */
59   int	  reqid;		/* Next request id */
60   int	  restart;		/* Restart counter value */
61   int	  maxconfig;
62 
63   int     reqcode;		/* Request code sent */
64   struct pppTimer FsmTimer;	/* Restart Timer */
65 
66   void	  (*LayerUp)();
67   void	  (*LayerDown)();
68   void	  (*LayerStart)();
69   void	  (*LayerFinish)();
70   void	  (*InitRestartCounter)();
71   void	  (*SendConfigReq)();
72   void	  (*SendTerminateReq)();
73   void	  (*SendTerminateAck)();
74   void	  (*DecodeConfig)();
75 };
76 
77 struct fsmheader {
78   u_char  code;		/* Request code */
79   u_char  id;		/* Identification */
80   u_short length;	/* Length of packet */
81 };
82 
83 #define	CODE_CONFIGREQ	1
84 #define	CODE_CONFIGACK	2
85 #define	CODE_CONFIGNAK	3
86 #define	CODE_CONFIGREJ	4
87 #define	CODE_TERMREQ	5
88 #define	CODE_TERMACK	6
89 #define	CODE_CODEREJ	7
90 #define	CODE_PROTOREJ	8
91 #define	CODE_ECHOREQ	9		/* Used in LCP */
92 #define	CODE_ECHOREP	10		/* Used in LCP */
93 #define	CODE_DISCREQ	11
94 #define	CODE_IDENT	12		/* Used in LCP Extension */
95 #define	CODE_TIMEREM	13		/* Used in LCP Extension */
96 #define	CODE_RESETREQ	14		/* Used in CCP */
97 #define	CODE_RESETACK	15		/* Used in CCP */
98 
99 struct fsmcodedesc {
100   void (*action)();
101   char *name;
102 };
103 
104 struct fsmconfig {
105   u_char type;
106   u_char length;
107 };
108 
109 u_char AckBuff[200];
110 u_char NakBuff[200];
111 u_char RejBuff[100];
112 u_char ReqBuff[200];
113 
114 u_char *ackp, *nakp, *rejp;
115 
116 extern char *StateNames[];
117 extern void FsmInit(struct fsm *);
118 extern void NewState(struct fsm *, int);
119 extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int);
120 extern void FsmOpen(struct fsm *);
121 extern void FsmUp(struct fsm *);
122 extern void FsmDown(struct fsm *);
123 extern void FsmInput(struct fsm *, struct mbuf *);
124 
125 extern void FsmRecvConfigReq(struct fsm *, struct fsmheader *, struct mbuf *);
126 extern void FsmRecvConfigAck(struct fsm *, struct fsmheader *, struct mbuf *);
127 extern void FsmRecvConfigNak(struct fsm *, struct fsmheader *, struct mbuf *);
128 extern void FsmRecvTermReq(struct fsm *, struct fsmheader *, struct mbuf *);
129 extern void FsmRecvTermAck(struct fsm *, struct fsmheader *, struct mbuf *);
130 extern void FsmClose(struct fsm *fp);
131 
132 extern struct fsm LcpFsm, IpcpFsm, CcpFsm;
133 
134 #endif	/* _FSM_H_ */
135