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