Annotation of embedaddon/mpd/src/fsm.h, revision 1.1.1.1
1.1 misho 1:
2: /*
3: * fsm.h
4: *
5: * Written by Toshiharu OHNO <tony-o@iij.ad.jp>
6: * Copyright (c) 1993, Internet Initiative Japan, Inc. All rights reserved.
7: * See ``COPYRIGHT.iij''
8: *
9: * Rewritten by Archie Cobbs <archie@freebsd.org>
10: * Copyright (c) 1995-1999 Whistle Communications, Inc. All rights reserved.
11: * See ``COPYRIGHT.whistle''
12: */
13:
14: #ifndef _FSM_H_
15: #define _FSM_H_
16:
17: #include <netinet/in.h>
18: #include "mbuf.h"
19: #include "timer.h"
20: #include <netgraph/ng_ppp.h>
21:
22: /*
23: * DEFINITIONS
24: */
25:
26: /* States: don't change these! */
27: enum fsm_state {
28: ST_INITIAL = 0,
29: ST_STARTING,
30: ST_CLOSED,
31: ST_STOPPED,
32: ST_CLOSING,
33: ST_STOPPING,
34: ST_REQSENT,
35: ST_ACKRCVD,
36: ST_ACKSENT,
37: ST_OPENED
38: };
39:
40: #define OPEN_STATE(s) ((s) > ST_CLOSING || ((s) & 1))
41:
42: #define MODE_REQ 0
43: #define MODE_NAK 1
44: #define MODE_REJ 2
45: #define MODE_NOP 3
46:
47: /* Codes */
48: #define CODE_VENDOR 0
49: #define CODE_CONFIGREQ 1
50: #define CODE_CONFIGACK 2
51: #define CODE_CONFIGNAK 3
52: #define CODE_CONFIGREJ 4
53: #define CODE_TERMREQ 5
54: #define CODE_TERMACK 6
55: #define CODE_CODEREJ 7
56: #define CODE_PROTOREJ 8
57: #define CODE_ECHOREQ 9
58: #define CODE_ECHOREP 10
59: #define CODE_DISCREQ 11
60: #define CODE_IDENT 12
61: #define CODE_TIMEREM 13
62: #define CODE_RESETREQ 14
63: #define CODE_RESETACK 15
64:
65: /* All the various ways that the FSM can fail */
66: /* XXX This should be extended to contain more descriptive information
67: XXX about the cause of the failure, like what the rejected protocol
68: XXX or option was, etc. */
69: enum fsmfail {
70: FAIL_NEGOT_FAILURE, /* option negotiation failed */
71: FAIL_RECD_BADMAGIC, /* rec'd bad magic number */
72: FAIL_RECD_CODEREJ, /* rec'd fatal code reject */
73: FAIL_RECD_PROTREJ, /* rec'd fatal protocol reject */
74: FAIL_WAS_PROTREJ, /* protocol was rejected */
75: FAIL_ECHO_TIMEOUT, /* peer not responding to echo requests */
76: FAIL_CANT_ENCRYPT /* failed to negotiate required encryption */
77: };
78:
79: /* FSM descriptor */
80: struct fsm;
81: typedef struct fsm *Fsm;
82: struct fsmoption;
83: typedef struct fsmoption *FsmOption;
84: struct fsmoptinfo;
85: typedef const struct fsmoptinfo *FsmOptInfo;
86:
87: struct fsmconf {
88: short maxconfig; /* "Max-Configure" initial value */
89: short maxterminate; /* "Max-Terminate" initial value */
90: short maxfailure; /* "Max-Failure" initial value */
91: short echo_int; /* LCP echo interval (zero disables) */
92: short echo_max; /* LCP max quiet timeout */
93: u_char check_magic; /* Validate any magic numbers seen */
94: u_char passive; /* Passive option (see rfc 1661) */
95: };
96: typedef struct fsmconf *FsmConf;
97:
98: struct fsmtype {
99: const char *name; /* Name of protocol */
100: uint16_t proto; /* Protocol number */
101: uint16_t known_codes; /* Accepted FSM codes */
102: u_char link_layer; /* Link level FSM */
103: int log, log2; /* Log levels for FSM events */
104:
105: void (*NewState)(Fsm f, enum fsm_state old, enum fsm_state new);
106: void (*LayerUp)(Fsm f);
107: void (*LayerDown)(Fsm f);
108: void (*LayerStart)(Fsm f);
109: void (*LayerFinish)(Fsm f);
110: u_char * (*BuildConfigReq)(Fsm f, u_char *cp);
111: void (*DecodeConfig)(Fsm f, FsmOption a, int num, int mode);
112: void (*Configure)(Fsm f);
113: void (*UnConfigure)(Fsm f);
114: void (*SendTerminateReq)(Fsm f);
115: void (*SendTerminateAck)(Fsm f);
116: int (*RecvCodeRej)(Fsm f, int code, Mbuf bp);
117: int (*RecvProtoRej)(Fsm f, int proto, Mbuf bp);
118: void (*Failure)(Fsm f, enum fsmfail reason);
119: void (*RecvResetReq)(Fsm f, int id, Mbuf bp);
120: void (*RecvResetAck)(Fsm f, int id, Mbuf bp);
121: void (*RecvIdent)(Fsm f, Mbuf bp);
122: void (*RecvDiscReq)(Fsm f, Mbuf bp);
123: void (*RecvTimeRemain)(Fsm f, Mbuf bp);
124: void (*RecvVendor)(Fsm f, Mbuf bp);
125: };
126: typedef const struct fsmtype *FsmType;
127:
128: struct fsm {
129: FsmType type; /* FSM constant stuff */
130: void *arg; /* Context (Link or Bund) */
131: int log; /* Current log level */
132: int log2; /* Current log2 level */
133: struct fsmconf conf; /* FSM parameters */
134: enum fsm_state state; /* State of the machine */
135: u_char reqid; /* Next request id */
136: u_char rejid; /* Next reject id */
137: u_char echoid; /* Next echo request id */
138: short restart; /* Restart counter value */
139: short failure; /* How many failures left */
140: short config; /* How many configs left */
141: short quietCount; /* How long peer has been silent */
142: struct pppTimer timer; /* Restart Timer */
143: struct pppTimer echoTimer; /* Keep-alive timer */
144: struct ng_ppp_link_stat
145: idleStats; /* Stats for echo timeout */
146: };
147:
148: /* Packet header */
149: struct fsmheader {
150: u_char code; /* Request code */
151: u_char id; /* Identification */
152: u_short length; /* Length of packet */
153: };
154: typedef struct fsmheader *FsmHeader;
155:
156: /* One config option */
157: struct fsmoption {
158: u_char type;
159: u_char len;
160: u_char *data;
161: };
162:
163: /* Fsm option descriptor */
164: struct fsmoptinfo {
165: const char *name;
166: u_char type;
167: u_char minLen;
168: u_char maxLen;
169: u_char supported;
170: };
171:
172: /*
173: * VARIABLES
174: */
175:
176: extern u_int gAckSize, gNakSize, gRejSize;
177:
178: /*
179: * FUNCTIONS
180: */
181:
182: extern void FsmInit(Fsm f, FsmType t, void *arg);
183: extern void FsmInst(Fsm fp, Fsm fpt, void *arg);
184: extern void FsmOpen(Fsm f);
185: extern void FsmClose(Fsm f);
186: extern void FsmUp(Fsm f);
187: extern void FsmDown(Fsm f);
188: extern void FsmInput(Fsm f, Mbuf bp);
189: extern void FsmOutput(Fsm, u_int, u_int, u_char *, int);
190: extern void FsmOutputMbuf(Fsm, u_int, u_int, Mbuf);
191: extern void FsmSendEchoReq(Fsm fp, Mbuf payload);
192: extern void FsmSendIdent(Fsm fp, const char *ident);
193: extern void FsmSendTimeRemaining(Fsm fp, u_int seconds);
194: extern u_char *FsmConfValue(u_char *cp, int ty,
195: int len, const void *data);
196: extern void FsmFailure(Fsm fp, enum fsmfail reason);
197: extern const char *FsmFailureStr(enum fsmfail reason);
198:
199: extern void FsmAck(Fsm fp, const struct fsmoption *opt);
200: extern void FsmNak(Fsm fp, const struct fsmoption *opt);
201: extern void FsmRej(Fsm fp, const struct fsmoption *opt);
202:
203: extern FsmOptInfo FsmFindOptInfo(FsmOptInfo list, u_char type);
204: extern const char *FsmStateName(enum fsm_state state);
205: extern const char *FsmCodeName(int code);
206:
207: #define Pref(fp) ( (fp)->type->link_layer ? ((Link)((fp)->arg))->name : ((Bund)((fp)->arg))->name )
208: #define Fsm(fp) ( (fp)->type->name )
209:
210: #endif /* _FSM_H_ */
211:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>