1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
25 *
26 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 *
32 * 1. Redistributions of source code must retain the above copyright
33 *    notice, this list of conditions and the following disclaimer.
34 *
35 * 2. Redistributions in binary form must reproduce the above copyright
36 *    notice, this list of conditions and the following disclaimer in
37 *    the documentation and/or other materials provided with the
38 *    distribution.
39 *
40 * 3. The name "Carnegie Mellon University" must not be used to
41 *    endorse or promote products derived from this software without
42 *    prior written permission. For permission or any legal
43 *    details, please contact
44 *      Office of Technology Transfer
45 *      Carnegie Mellon University
46 *      5000 Forbes Avenue
47 *      Pittsburgh, PA  15213-3890
48 *      (412) 268-4387, fax: (412) 268-7395
49 *      tech-transfer@andrew.cmu.edu
50 *
51 * 4. Redistributions of any form whatsoever must retain the following
52 *    acknowledgment:
53 *    "This product includes software developed by Computing Services
54 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
55 *
56 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
57 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
58 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
59 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
60 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
61 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
62 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
63 *
64 * $Id: fsm.h,v 1.6 2004/11/19 17:52:19 lindak Exp $
65 */
66
67#ifndef __FSM_H__
68#define __FSM_H__
69
70/*
71 * Packet header = Code, id, length.
72 */
73#define HEADERLEN	4
74
75
76/*
77 *  CP (LCP, IPCP, etc.) codes.
78 */
79#define CONFREQ		1	/* Configuration Request */
80#define CONFACK		2	/* Configuration Ack */
81#define CONFNAK		3	/* Configuration Nak */
82#define CONFREJ		4	/* Configuration Reject */
83#define TERMREQ		5	/* Termination Request */
84#define TERMACK		6	/* Termination Ack */
85#define CODEREJ		7	/* Code Reject */
86
87
88/*
89 * Each FSM is described by an fsm structure and fsm callbacks.
90 */
91typedef struct fsm {
92    int unit;			/* Interface unit number */
93    int protocol;		/* Data Link Layer Protocol field value */
94    int state;			/* State */
95    int flags;			/* Contains option bits */
96    u_char id;			/* Current id */
97    u_char reqid;		/* Current request id */
98    u_char seen_ack;		/* Have received valid Ack/Nak/Rej to Req */
99    int timeouttime;		/* Timeout time in milliseconds */
100    int maxconfreqtransmits;	/* Maximum Configure-Request transmissions */
101    int retransmits;		/* Number of retransmissions left */
102    int maxtermtransmits;	/* Maximum Terminate-Request transmissions */
103    int nakloops;		/* Number of nak loops since last ack */
104    int maxnakloops;		/* Maximum number of nak loops tolerated */
105#ifdef __APPLE__
106    int reqloops;		/* Number of req loops since beginning of (re)negotiation */
107    int maxreqloops;		/* Maximum number of req loops for convergence */
108    u_char recvreqid;		/* last received request id that moved us to opened state */
109    u_short recvreqhash;			/* hash of the options that moved us to opened state */
110#endif
111    struct fsm_callbacks *callbacks;	/* Callback routines */
112    char *term_reason;		/* Reason for closing protocol */
113    int term_reason_len;	/* Length of term_reason */
114} fsm;
115
116
117typedef struct fsm_callbacks {
118    void (*resetci)		/* Reset our Configuration Information */
119		__P((fsm *));
120    int  (*cilen)		/* Length of our Configuration Information */
121		__P((fsm *));
122    void (*addci) 		/* Add our Configuration Information */
123		__P((fsm *, u_char *, int *));
124    int  (*ackci)		/* ACK our Configuration Information */
125		__P((fsm *, u_char *, int));
126    int  (*nakci)		/* NAK our Configuration Information */
127		__P((fsm *, u_char *, int));
128    int  (*rejci)		/* Reject our Configuration Information */
129		__P((fsm *, u_char *, int));
130    int  (*reqci)		/* Request peer's Configuration Information */
131		__P((fsm *, u_char *, int *, int));
132    void (*up)			/* Called when fsm reaches OPENED state */
133		__P((fsm *));
134    void (*down)		/* Called when fsm leaves OPENED state */
135		__P((fsm *));
136    void (*starting)		/* Called when we want the lower layer */
137		__P((fsm *));
138    void (*finished)		/* Called when we don't want the lower layer */
139		__P((fsm *));
140    void (*protreject)		/* Called when Protocol-Reject received */
141		__P((int));
142    void (*retransmit)		/* Retransmission is necessary */
143		__P((fsm *));
144    int  (*extcode)		/* Called when unknown code received */
145		__P((fsm *, int, int, u_char *, int));
146    char *proto_name;		/* String name for protocol (for messages) */
147} fsm_callbacks;
148
149
150/*
151 * Link states.
152 */
153#define INITIAL		0	/* Down, hasn't been opened */
154#define STARTING	1	/* Down, been opened */
155#define CLOSED		2	/* Up, hasn't been opened */
156#define STOPPED		3	/* Open, waiting for down event */
157#define CLOSING		4	/* Terminating the connection, not open */
158#define STOPPING	5	/* Terminating, but open */
159#define REQSENT		6	/* We've sent a Config Request */
160#define ACKRCVD		7	/* We've received a Config Ack */
161#define ACKSENT		8	/* We've sent a Config Ack */
162#define OPENED		9	/* Connection available */
163
164
165/*
166 * Flags - indicate options controlling FSM operation
167 */
168#define OPT_PASSIVE	1	/* Don't die if we don't get a response */
169#define OPT_RESTART	2	/* Treat 2nd OPEN as DOWN, UP */
170#define OPT_SILENT	4	/* Wait for peer to speak first */
171
172
173/*
174 * Timeouts.
175 */
176#define DEFTIMEOUT	3	/* Timeout time in seconds */
177#define DEFMAXTERMREQS	2	/* Maximum Terminate-Request transmissions */
178#define DEFMAXCONFREQS	10	/* Maximum Configure-Request transmissions */
179#define DEFMAXNAKLOOPS	5	/* Maximum number of nak loops */
180#ifdef __APPLE__
181#define DEFMAXREQLOOPS	255 /* Maximum number of req loops for convergence */
182#endif
183
184/*
185 * Prototypes
186 */
187void fsm_init __P((fsm *));
188void fsm_lowerup __P((fsm *));
189void fsm_lowerdown __P((fsm *));
190void fsm_open __P((fsm *));
191void fsm_close __P((fsm *, char *));
192void fsm_input __P((fsm *, u_char *, int));
193void fsm_protreject __P((fsm *));
194void fsm_sdata __P((fsm *, int, int, u_char *, int));
195
196
197/*
198 * Variables
199 */
200extern int peer_mru[];		/* currently negotiated peer MRU (per unit) */
201
202#endif /* __FSM_H__ */
203