2 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4 * Internet Initiative Japan, Inc (IIJ)
7 * Redistribution and use in source and binary forms, with or without
8 * 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.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 #define MODE_ACK 4 /* pseudo mode for ccp negotiations */
54 #define OPEN_PASSIVE -1
56 #define FSM_REQ_TIMER 1
57 #define FSM_TRM_TIMER 2
62 u_int timeout; /* FSM retry frequency */
63 u_int maxreq; /* Max Config REQ retries */
64 u_int maxtrm; /* Max Term REQ retries */
68 u_char ack[100], *ackend;
69 u_char nak[100], *nakend;
70 u_char rej[100], *rejend;
73 struct fsm_callbacks {
74 int (*LayerUp) (struct fsm *); /* Layer is now up (tlu) */
75 void (*LayerDown) (struct fsm *); /* About to come down (tld) */
76 void (*LayerStart) (struct fsm *); /* Layer about to start up (tls) */
77 void (*LayerFinish) (struct fsm *); /* Layer now down (tlf) */
78 void (*InitRestartCounter) (struct fsm *, int); /* Set fsm timer load */
79 void (*SendConfigReq) (struct fsm *); /* Send REQ please */
80 void (*SentTerminateReq) (struct fsm *); /* Term REQ just sent */
81 void (*SendTerminateAck) (struct fsm *, u_char); /* Send Term ACK please */
82 void (*DecodeConfig) (struct fsm *, u_char *, int, int, struct fsm_decode *);
83 /* Deal with incoming data */
84 int (*RecvResetReq) (struct fsm *fp); /* Reset output */
85 void (*RecvResetAck) (struct fsm *fp, u_char); /* Reset input */
89 void (*LayerStart) (void *, struct fsm *); /* tls */
90 void (*LayerUp) (void *, struct fsm *); /* tlu */
91 void (*LayerDown) (void *, struct fsm *); /* tld */
92 void (*LayerFinish) (void *, struct fsm *); /* tlf */
100 const char *name; /* Name of protocol */
101 u_short proto; /* Protocol number */
104 int open_mode; /* Delay before config REQ (-1 forever) */
105 int state; /* State of the machine */
106 u_char reqid; /* Next request id */
107 int restart; /* Restart counter value */
110 int reqs; /* Max config REQs before a close() */
111 int naks; /* Max config NAKs before a close() */
112 int rejs; /* Max config REJs before a close() */
115 struct pppTimer FsmTimer; /* Restart Timer */
116 struct pppTimer OpenTimer; /* Delay before opening */
119 * This timer times the ST_STOPPED state out after the given value
120 * (specified via "set stopped ..."). Although this isn't specified in the
121 * rfc, the rfc *does* say that "the application may use higher level
122 * timers to avoid deadlock". The StoppedTimer takes effect when the other
123 * side ABENDs rather than going into ST_ACKSENT (and sending the ACK),
124 * causing ppp to time out and drop into ST_STOPPED. At this point,
125 * nothing will change this state :-(
127 struct pppTimer StoppedTimer;
130 /* The link layer active with this FSM (may be our bundle below) */
133 /* Our high-level link */
134 struct bundle *bundle;
136 const struct fsm_parent *parent;
137 const struct fsm_callbacks *fn;
141 u_char code; /* Request code */
142 u_char id; /* Identification */
143 u_short length; /* Length of packet */
146 #define CODE_CONFIGREQ 1
147 #define CODE_CONFIGACK 2
148 #define CODE_CONFIGNAK 3
149 #define CODE_CONFIGREJ 4
150 #define CODE_TERMREQ 5
151 #define CODE_TERMACK 6
152 #define CODE_CODEREJ 7
153 #define CODE_PROTOREJ 8
154 #define CODE_ECHOREQ 9 /* Used in LCP */
155 #define CODE_ECHOREP 10 /* Used in LCP */
156 #define CODE_DISCREQ 11
157 #define CODE_IDENT 12 /* Used in LCP Extension */
158 #define CODE_TIMEREM 13 /* Used in LCP Extension */
159 #define CODE_RESETREQ 14 /* Used in CCP */
160 #define CODE_RESETACK 15 /* Used in CCP */
162 /* Minimum config req size. This struct is *only* used for it's size */
168 extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int,
169 struct bundle *, struct link *, const struct fsm_parent *,
170 struct fsm_callbacks *, const char * const [3]);
171 extern void fsm_Output(struct fsm *, u_int, u_int, u_char *, int, int);
172 extern void fsm_Open(struct fsm *);
173 extern void fsm_Up(struct fsm *);
174 extern void fsm_Down(struct fsm *);
175 extern void fsm_Input(struct fsm *, struct mbuf *);
176 extern void fsm_Close(struct fsm *);
177 extern int fsm_NullRecvResetReq(struct fsm *);
178 extern void fsm_NullRecvResetAck(struct fsm *, u_char);
179 extern void fsm_Reopen(struct fsm *);
180 extern void fsm2initial(struct fsm *);
181 extern const char *State2Nam(u_int);