xref: /freebsd/usr.sbin/ppp/fsm.h (revision ef5d438ed4bc17ad7ece3e40fe4d1f9baf3aadf7)
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: fsm.h,v 1.4 1995/02/27 03:17:58 amurai Exp $
19  *
20  *	TODO:
21  */
22 
23 #ifndef _FSM_H_
24 #define	_FSM_H_
25 
26 #include "defs.h"
27 #include <netinet/in.h>
28 #include "timeout.h"
29 #include "cdefs.h"
30 
31 /*
32  *  State of machine
33  */
34 #define	ST_INITIAL	0
35 #define	ST_STARTING	1
36 #define	ST_CLOSED	2
37 #define	ST_STOPPED	3
38 #define	ST_CLOSING	4
39 #define	ST_STOPPING	5
40 #define	ST_REQSENT	6
41 #define	ST_ACKRCVD	7
42 #define	ST_ACKSENT	8
43 #define	ST_OPENED	9
44 
45 #define	ST_MAX		10
46 #define	ST_UNDEF	-1
47 
48 #define	MODE_REQ	0
49 #define	MODE_NAK	1
50 #define	MODE_REJ	2
51 #define	MODE_NOP	3
52 
53 #define	OPEN_ACTIVE	0
54 #define	OPEN_PASSIVE	1
55 
56 struct fsm {
57   char	  *name;		/* Name of protocol */
58   u_short proto;		/* Protocol number */
59   u_short max_code;
60   int	  open_mode;
61   int	  state;		/* State of the machine */
62   int	  reqid;		/* Next request id */
63   int	  restart;		/* Restart counter value */
64   int	  maxconfig;
65 
66   int     reqcode;		/* Request code sent */
67   struct pppTimer FsmTimer;	/* Restart Timer */
68 
69   void	  (*LayerUp) __P((struct fsm *));
70   void	  (*LayerDown) __P((struct fsm *));
71   void	  (*LayerStart) __P((struct fsm *));
72   void	  (*LayerFinish) __P((struct fsm *));
73   void	  (*InitRestartCounter) __P((struct fsm *));
74   void	  (*SendConfigReq) __P((struct fsm *));
75   void	  (*SendTerminateReq) __P((struct fsm *));
76   void	  (*SendTerminateAck) __P((struct fsm *));
77   void	  (*DecodeConfig) __P((u_char *, int, int));
78 };
79 
80 struct fsmheader {
81   u_char  code;		/* Request code */
82   u_char  id;		/* Identification */
83   u_short length;	/* Length of packet */
84 };
85 
86 #define	CODE_CONFIGREQ	1
87 #define	CODE_CONFIGACK	2
88 #define	CODE_CONFIGNAK	3
89 #define	CODE_CONFIGREJ	4
90 #define	CODE_TERMREQ	5
91 #define	CODE_TERMACK	6
92 #define	CODE_CODEREJ	7
93 #define	CODE_PROTOREJ	8
94 #define	CODE_ECHOREQ	9		/* Used in LCP */
95 #define	CODE_ECHOREP	10		/* Used in LCP */
96 #define	CODE_DISCREQ	11
97 #define	CODE_IDENT	12		/* Used in LCP Extension */
98 #define	CODE_TIMEREM	13		/* Used in LCP Extension */
99 #define	CODE_RESETREQ	14		/* Used in CCP */
100 #define	CODE_RESETACK	15		/* Used in CCP */
101 
102 struct fsmcodedesc {
103   void (*action) __P((struct fsm *, struct fsmheader *, struct mbuf *));
104   char *name;
105 };
106 
107 struct fsmconfig {
108   u_char type;
109   u_char length;
110 };
111 
112 u_char AckBuff[200];
113 u_char NakBuff[200];
114 u_char RejBuff[100];
115 u_char ReqBuff[200];
116 
117 u_char *ackp, *nakp, *rejp;
118 
119 extern char const *StateNames[];
120 extern void FsmInit __P((struct fsm *));
121 extern void NewState __P((struct fsm *, int));
122 extern void FsmOutput __P((struct fsm *, u_int, u_int, u_char *, int));
123 extern void FsmOpen __P((struct fsm *));
124 extern void FsmUp __P((struct fsm *));
125 extern void FsmDown __P((struct fsm *));
126 extern void FsmInput __P((struct fsm *, struct mbuf *));
127 
128 extern void FsmRecvConfigReq __P((struct fsm *, struct fsmheader *, struct mbuf *));
129 extern void FsmRecvConfigAck __P((struct fsm *, struct fsmheader *, struct mbuf *));
130 extern void FsmRecvConfigNak __P((struct fsm *, struct fsmheader *, struct mbuf *));
131 extern void FsmRecvTermReq __P((struct fsm *, struct fsmheader *, struct mbuf *));
132 extern void FsmRecvTermAck __P((struct fsm *, struct fsmheader *, struct mbuf *));
133 extern void FsmClose __P((struct fsm *fp));
134 
135 extern struct fsm LcpFsm, IpcpFsm, CcpFsm;
136 
137 #endif	/* _FSM_H_ */
138