fsm.h revision 30715
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.10 1997/08/25 00:29:12 brian Exp $
19 *
20 *	TODO:
21 */
22
23/*
24 *  State of machine
25 */
26#define	ST_INITIAL	0
27#define	ST_STARTING	1
28#define	ST_CLOSED	2
29#define	ST_STOPPED	3
30#define	ST_CLOSING	4
31#define	ST_STOPPING	5
32#define	ST_REQSENT	6
33#define	ST_ACKRCVD	7
34#define	ST_ACKSENT	8
35#define	ST_OPENED	9
36
37#define	ST_MAX		10
38#define	ST_UNDEF	-1
39
40#define	MODE_REQ	0
41#define	MODE_NAK	1
42#define	MODE_REJ	2
43#define	MODE_NOP	3
44
45#define	OPEN_ACTIVE	0
46#define	OPEN_PASSIVE	1
47
48struct fsm {
49  char *name;			/* Name of protocol */
50  u_short proto;		/* Protocol number */
51  u_short max_code;
52  int open_mode;
53  int state;			/* State of the machine */
54  int reqid;			/* Next request id */
55  int restart;			/* Restart counter value */
56  int maxconfig;
57
58  int reqcode;			/* Request code sent */
59  struct pppTimer FsmTimer;	/* Restart Timer */
60
61  /*
62   * This timer times the ST_STOPPED state out after the given value
63   * (specified via "set stopped ...").  Although this isn't specified in the
64   * rfc, the rfc *does* say that "the application may use higher level
65   * timers to avoid deadlock". The StoppedTimer takes effect when the other
66   * side ABENDs rather than going into ST_ACKSENT (and sending the ACK),
67   * causing ppp to time out and drop into ST_STOPPED.  At this point,
68   * nothing will change this state :-(
69   */
70  struct pppTimer StoppedTimer;
71  int LogLevel;
72
73  void (*LayerUp) (struct fsm *);
74  void (*LayerDown) (struct fsm *);
75  void (*LayerStart) (struct fsm *);
76  void (*LayerFinish) (struct fsm *);
77  void (*InitRestartCounter) (struct fsm *);
78  void (*SendConfigReq) (struct fsm *);
79  void (*SendTerminateReq) (struct fsm *);
80  void (*SendTerminateAck) (struct fsm *);
81  void (*DecodeConfig) (u_char *, int, int);
82};
83
84struct fsmheader {
85  u_char code;			/* Request code */
86  u_char id;			/* Identification */
87  u_short length;		/* Length of packet */
88};
89
90#define	CODE_CONFIGREQ	1
91#define	CODE_CONFIGACK	2
92#define	CODE_CONFIGNAK	3
93#define	CODE_CONFIGREJ	4
94#define	CODE_TERMREQ	5
95#define	CODE_TERMACK	6
96#define	CODE_CODEREJ	7
97#define	CODE_PROTOREJ	8
98#define	CODE_ECHOREQ	9	/* Used in LCP */
99#define	CODE_ECHOREP	10	/* Used in LCP */
100#define	CODE_DISCREQ	11
101#define	CODE_IDENT	12	/* Used in LCP Extension */
102#define	CODE_TIMEREM	13	/* Used in LCP Extension */
103#define	CODE_RESETREQ	14	/* Used in CCP */
104#define	CODE_RESETACK	15	/* Used in CCP */
105
106struct fsmcodedesc {
107  void (*action) (struct fsm *, struct fsmheader *, struct mbuf *);
108  char *name;
109};
110
111struct fsmconfig {
112  u_char type;
113  u_char length;
114};
115
116extern u_char AckBuff[200];
117extern u_char NakBuff[200];
118extern u_char RejBuff[100];
119extern u_char ReqBuff[200];
120extern u_char *ackp;
121extern u_char *nakp;
122extern u_char *rejp;
123
124extern char const *StateNames[];
125
126extern void FsmInit(struct fsm *);
127extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int);
128extern void FsmOpen(struct fsm *);
129extern void FsmUp(struct fsm *);
130extern void FsmDown(struct fsm *);
131extern void FsmInput(struct fsm *, struct mbuf *);
132extern void FsmClose(struct fsm *);
133