2 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
4 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name "Carnegie Mellon University" must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission. For permission or any legal
21 * details, please contact
22 * Office of Technology Transfer
23 * Carnegie Mellon University
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
29 * 4. Redistributions of any form whatsoever must retain the following
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42 * $Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp $
50 * Packet header = Code, id, length.
56 * CP (LCP, IPCP, etc.) codes.
58 #define CONFREQ 1 /* Configuration Request */
59 #define CONFACK 2 /* Configuration Ack */
60 #define CONFNAK 3 /* Configuration Nak */
61 #define CONFREJ 4 /* Configuration Reject */
62 #define TERMREQ 5 /* Termination Request */
63 #define TERMACK 6 /* Termination Ack */
64 #define CODEREJ 7 /* Code Reject */
68 * Each FSM is described by an fsm structure and fsm callbacks.
71 int unit; /* Interface unit number */
72 int protocol; /* Data Link Layer Protocol field value */
73 int state; /* State */
74 int flags; /* Contains option bits */
75 u_char id; /* Current id */
76 u_char reqid; /* Current request id */
77 u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
78 int timeouttime; /* Timeout time in milliseconds */
79 int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
80 int retransmits; /* Number of retransmissions left */
81 int maxtermtransmits; /* Maximum Terminate-Request transmissions */
82 int nakloops; /* Number of nak loops since last ack */
83 int rnakloops; /* Number of naks received */
84 int maxnakloops; /* Maximum number of nak loops tolerated */
85 struct fsm_callbacks *callbacks; /* Callback routines */
86 char *term_reason; /* Reason for closing protocol */
87 int term_reason_len; /* Length of term_reason */
91 typedef struct fsm_callbacks {
92 void (*resetci)(fsm *); /* Reset our Configuration Information */
93 int (*cilen)(fsm *); /* Length of our Configuration Information */
94 void (*addci) /* Add our Configuration Information */
95 (fsm *, u_char *, int *);
96 int (*ackci) /* ACK our Configuration Information */
97 (fsm *, u_char *, int);
98 int (*nakci) /* NAK our Configuration Information */
99 (fsm *, u_char *, int, int);
100 int (*rejci) /* Reject our Configuration Information */
101 (fsm *, u_char *, int);
102 int (*reqci) /* Request peer's Configuration Information */
103 (fsm *, u_char *, int *, int);
104 void (*up)(fsm *); /* Called when fsm reaches OPENED state */
105 void (*down)(fsm *); /* Called when fsm leaves OPENED state */
106 void (*starting)(fsm *); /* Called when we want the lower layer */
107 void (*finished)(fsm *); /* Called when we don't want the lower layer */
108 void (*protreject)(int); /* Called when Protocol-Reject received */
109 void (*retransmit)(fsm *); /* Retransmission is necessary */
110 int (*extcode) /* Called when unknown code received */
111 (fsm *, int, int, u_char *, int);
112 char *proto_name; /* String name for protocol (for messages) */
119 #define INITIAL 0 /* Down, hasn't been opened */
120 #define STARTING 1 /* Down, been opened */
121 #define CLOSED 2 /* Up, hasn't been opened */
122 #define STOPPED 3 /* Open, waiting for down event */
123 #define CLOSING 4 /* Terminating the connection, not open */
124 #define STOPPING 5 /* Terminating, but open */
125 #define REQSENT 6 /* We've sent a Config Request */
126 #define ACKRCVD 7 /* We've received a Config Ack */
127 #define ACKSENT 8 /* We've sent a Config Ack */
128 #define OPENED 9 /* Connection available */
132 * Flags - indicate options controlling FSM operation
134 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
135 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
136 #define OPT_SILENT 4 /* Wait for peer to speak first */
142 #define DEFTIMEOUT 3 /* Timeout time in seconds */
143 #define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
144 #define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
145 #define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
151 void fsm_init (fsm *);
152 void fsm_lowerup (fsm *);
153 void fsm_lowerdown (fsm *);
154 void fsm_open (fsm *);
155 void fsm_close (fsm *, char *);
156 void fsm_input (fsm *, u_char *, int);
157 void fsm_protreject (fsm *);
158 void fsm_sdata (fsm *, int, int, u_char *, int);
164 extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */