Annotation of embedaddon/libpdel/ppp/ppp_fsm.h, revision 1.1.1.1
1.1 misho 1:
2: /*
3: * Copyright (c) 2001-2002 Packet Design, LLC.
4: * All rights reserved.
5: *
6: * Subject to the following obligations and disclaimer of warranty,
7: * use and redistribution of this software, in source or object code
8: * forms, with or without modifications are expressly permitted by
9: * Packet Design; provided, however, that:
10: *
11: * (i) Any and all reproductions of the source or object code
12: * must include the copyright notice above and the following
13: * disclaimer of warranties; and
14: * (ii) No rights are granted, in any manner or form, to use
15: * Packet Design trademarks, including the mark "PACKET DESIGN"
16: * on advertising, endorsements, or otherwise except as such
17: * appears in the above copyright notice or in the software.
18: *
19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
36: * THE POSSIBILITY OF SUCH DAMAGE.
37: *
38: * Author: Archie Cobbs <archie@freebsd.org>
39: */
40:
41: #ifndef _PDEL_PPP_PPP_FSM_H_
42: #define _PDEL_PPP_PPP_FSM_H_
43:
44: #ifndef _PDEL_PPP_PRIVATE_H_
45: #error "This header is only for use by the ppp library."
46: #endif
47:
48: struct ppp_fsm;
49: struct ppp_fsm_instance;
50: struct ppp_fsm_options;
51: struct ppp_fsm_optdesc;
52:
53: /*
54: * FSM states
55: */
56: enum ppp_fsm_state {
57: FSM_STATE_INITIAL =0,
58: FSM_STATE_STARTING =1,
59: FSM_STATE_CLOSED =2,
60: FSM_STATE_STOPPED =3,
61: FSM_STATE_CLOSING =4,
62: FSM_STATE_STOPPING =5,
63: FSM_STATE_REQSENT =6,
64: FSM_STATE_ACKRCVD =7,
65: FSM_STATE_ACKSENT =8,
66: FSM_STATE_OPENED =9
67: };
68: #define FSM_STATE_MAX 10
69:
70: /*
71: * FSM codes
72: */
73: enum ppp_fsm_code {
74: FSM_CODE_VENDOR =0,
75: FSM_CODE_CONFIGREQ =1,
76: FSM_CODE_CONFIGACK =2,
77: FSM_CODE_CONFIGNAK =3,
78: FSM_CODE_CONFIGREJ =4,
79: FSM_CODE_TERMREQ =5,
80: FSM_CODE_TERMACK =6,
81: FSM_CODE_CODEREJ =7,
82: FSM_CODE_PROTOREJ =8,
83: FSM_CODE_ECHOREQ =9,
84: FSM_CODE_ECHOREP =10,
85: FSM_CODE_DISCREQ =11,
86: FSM_CODE_IDENT =12,
87: FSM_CODE_TIMEREM =13,
88: FSM_CODE_RESETREQ =14,
89: FSM_CODE_RESETACK =15
90: };
91: #define FSM_CODE_MAX 16
92:
93: /*
94: * FSM packet format
95: */
96: struct ppp_fsm_pkt {
97: u_char code; /* fsm code */
98: u_char id; /* packet id */
99: u_int16_t length; /* length (network order) */
100: u_char data[0]; /* packet data */
101: };
102:
103: /*
104: * Input to an FSM
105: */
106: enum ppp_fsm_input {
107: FSM_INPUT_OPEN = 1, /* request to open */
108: FSM_INPUT_CLOSE, /* request to close */
109: FSM_INPUT_UP, /* lower layer went up */
110: FSM_INPUT_DOWN_FATAL, /* lower layer went down, fatal */
111: FSM_INPUT_DOWN_NONFATAL, /* lower layer went down, not fatal */
112: FSM_INPUT_DATA, /* packet recieved */
113: FSM_INPUT_XMIT_PROTOREJ, /* send a protocol-reject to peer */
114: FSM_INPUT_RECD_PROTOREJ, /* indicate rec'd fatal proto-rej */
115: };
116:
117: /*
118: * Output from an FSM
119: */
120: enum ppp_fsmoutput {
121: FSM_OUTPUT_OPEN = 1, /* request opening lower layer */
122: FSM_OUTPUT_CLOSE, /* request closing lower layer */
123: FSM_OUTPUT_UP, /* fsm has reached the open state */
124: FSM_OUTPUT_DOWN, /* fsm has left the open state */
125: FSM_OUTPUT_DATA, /* packet to be sent */
126: FSM_OUTPUT_PROTOREJ, /* rec'd non-fatal protocol reject */
127: FSM_OUTPUT_DEAD, /* fsm has finished or failed */
128: };
129:
130: /* Reasons associated with a FSM_OUTPUT_DOWN or FSM_OUTPUT_DEAD output */
131: enum ppp_fsm_reason {
132: FSM_REASON_CLOSE = 1, /* rec'd FSM_INPUT_CLOSE */
133: FSM_REASON_DOWN_FATAL, /* rec'd FSM_INPUT_DOWN_FATAL */
134: FSM_REASON_DOWN_NONFATAL, /* rec'd FSM_INPUT_DOWN_NONFATAL */
135: FSM_REASON_CONF, /* rec'd Conf-Req, etc. (DOWN only) */
136: FSM_REASON_TERM, /* rec'd terminate request */
137: FSM_REASON_CODEREJ, /* rec'd fatal code reject */
138: FSM_REASON_PROTOREJ, /* rec'd fatal protocol reject */
139: FSM_REASON_NEGOT, /* negotiation failed/didn't converge */
140: FSM_REASON_BADMAGIC, /* bad magic number received */
141: FSM_REASON_LOOPBACK, /* looped back connection detected */
142: FSM_REASON_TIMEOUT, /* peer not responding to echo */
143: FSM_REASON_SYSERR, /* internal system error */
144: };
145:
146: /* FSM output structure */
147: struct ppp_fsm_output {
148: enum ppp_fsmoutput type; /* type of output */
149: union {
150: struct { /* if FSM_OUTPUT_DATA */
151: u_char *data;
152: u_int length;
153: } data;
154: u_int16_t proto; /* if FSM_OUTPUT_PROTOREJ */
155: struct { /* if FSM_OUTPUT_DOWN, DEAD */
156: enum ppp_fsm_reason reason; /* reason for DOWN or DEAD */
157: union {
158: int error; /* FSM_REASON_SYSERR */
159: u_char code; /* FSM_REASON_CODEREJ/CONF */
160: u_int16_t proto; /* FSM_REASON_PROTOREJ */
161: } u;
162: } down;
163: } u; /* type specific contents */
164: };
165:
166: /*
167: * FSM type function types
168: */
169: typedef void ppp_fsm_type_destroy_t(struct ppp_fsm_instance *fsm);
170: typedef int ppp_fsm_type_build_conf_req_t(struct ppp_fsm_instance *fsm,
171: struct ppp_fsm_options *opts);
172: typedef int ppp_fsm_type_recv_conf_req_t(struct ppp_fsm_instance *fsm,
173: struct ppp_fsm_options *req,
174: struct ppp_fsm_options *nak,
175: struct ppp_fsm_options *rej);
176: typedef int ppp_fsm_type_recv_conf_rej_t(struct ppp_fsm_instance *fsm,
177: struct ppp_fsm_options *rej);
178: typedef int ppp_fsm_type_recv_conf_nak_t(struct ppp_fsm_instance *fsm,
179: struct ppp_fsm_options *nak);
180: typedef u_int32_t ppp_fsm_type_get_magic_t(struct ppp_fsm_instance *fsm,
181: int dir);
182: typedef void ppp_fsm_type_recv_reset_req_t(struct ppp_fsm_instance *fsm,
183: const u_char *data, u_int len);
184: typedef void ppp_fsm_type_recv_reset_ack_t(struct ppp_fsm_instance *fsm,
185: const u_char *data, u_int len);
186: typedef void ppp_fsm_type_recv_vendor_t(struct ppp_fsm_instance *fsm,
187: const u_char *data, u_int len);
188:
189: /*
190: * FSM type
191: *
192: * Information describing one type of FSM (e.g., LCP, IPCP)
193: */
194: struct ppp_fsm_type {
195:
196: /* Basic stuff */
197: const char *name; /* name of protocol */
198: u_int16_t proto; /* fsm protocol number */
199: u_int32_t sup_codes; /* supported fsm codes */
200: u_int32_t req_codes; /* required fsm codes */
201:
202: /* FSM configuration options */
203: const struct ppp_fsm_optdesc *options; /* option descriptors */
204: const struct ppp_fsm_options *defaults; /* default options */
205:
206: /* Required callbacks */
207: ppp_fsm_type_destroy_t *destroy;
208: ppp_fsm_type_build_conf_req_t *build_conf_req;
209: ppp_fsm_type_recv_conf_req_t *recv_conf_req;
210: ppp_fsm_type_recv_conf_rej_t *recv_conf_rej;
211: ppp_fsm_type_recv_conf_nak_t *recv_conf_nak;
212:
213: /* Magic numbers */
214: ppp_fsm_type_get_magic_t *get_magic;
215:
216: /* Optional callbacks */
217: ppp_fsm_type_recv_reset_req_t *recv_reset_req;
218: ppp_fsm_type_recv_reset_ack_t *recv_reset_ack;
219: ppp_fsm_type_recv_vendor_t *recv_vendor;
220: };
221:
222: /*
223: * One instance of an FSM
224: */
225: struct ppp_fsm_instance {
226: const struct ppp_fsm_type *type; /* which type of fsm */
227: struct ppp_fsm *fsm; /* back-pointer to fsm */
228: void *arg; /* per-instance info */
229: };
230:
231: __BEGIN_DECLS
232:
233: /* Functions */
234: extern struct ppp_fsm *ppp_fsm_create(struct pevent_ctx *ctx,
235: pthread_mutex_t *mutex, struct ppp_fsm_instance *inst,
236: struct ppp_log *log);
237: extern void ppp_fsm_destroy(struct ppp_fsm **fsmp);
238:
239: extern struct mesg_port *ppp_fsm_get_outport(struct ppp_fsm *fsm);
240:
241: extern void ppp_fsm_input(struct ppp_fsm *fsm,
242: enum ppp_fsm_input input, ...);
243: extern void ppp_fsm_free_output(struct ppp_fsm_output *output);
244: extern enum ppp_fsm_state ppp_fsm_get_state(struct ppp_fsm *fsm);
245: extern time_t ppp_fsm_last_heard(struct ppp_fsm *fsm);
246: extern struct ppp_fsm_instance *ppp_fsm_get_instance(struct ppp_fsm *fsm);
247: extern void ppp_fsm_send_reset_req(struct ppp_fsm *fsm,
248: const void *data, size_t dlen);
249: extern void ppp_fsm_send_reset_ack(struct ppp_fsm *fsm,
250: const void *data, size_t dlen);
251:
252: extern const char *ppp_fsm_output_str(struct ppp_fsm_output *output);
253: extern const char *ppp_fsm_reason_str(struct ppp_fsm_output *output);
254:
255: __END_DECLS
256:
257: #endif /* _PDEL_PPP_PPP_FSM_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>