2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
5 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
6 * Internet Initiative Japan, Inc (IIJ)
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 #define MODE_ACK 4 /* pseudo mode for ccp negotiations */
56 #define OPEN_PASSIVE -1
58 #define FSM_REQ_TIMER 1
59 #define FSM_TRM_TIMER 2
61 #define FSM_OPTLEN 100
66 u_int timeout; /* FSM retry frequency */
67 u_int maxreq; /* Max Config REQ retries */
68 u_int maxtrm; /* Max Term REQ retries */
72 u_char ack[FSM_OPTLEN], *ackend;
73 u_char nak[FSM_OPTLEN], *nakend;
74 u_char rej[FSM_OPTLEN], *rejend;
77 struct fsm_callbacks {
78 int (*LayerUp)(struct fsm *); /* Layer is now up (tlu) */
79 void (*LayerDown)(struct fsm *); /* About to come down (tld) */
80 void (*LayerStart)(struct fsm *); /* Layer about to start (tls) */
81 void (*LayerFinish)(struct fsm *); /* Layer now down (tlf) */
82 void (*InitRestartCounter)(struct fsm *, int);/* Set fsm timer load */
83 void (*SendConfigReq)(struct fsm *); /* Send REQ please */
84 void (*SentTerminateReq)(struct fsm *); /* Term REQ just sent */
85 void (*SendTerminateAck)(struct fsm *, u_char); /* Send Term ACK please */
86 void (*DecodeConfig)(struct fsm *, u_char *, u_char *, int,
87 struct fsm_decode *); /* Deal with incoming data */
88 int (*RecvResetReq)(struct fsm *fp); /* Reset output */
89 void (*RecvResetAck)(struct fsm *fp, u_char); /* Reset input */
93 void (*LayerStart) (void *, struct fsm *); /* tls */
94 void (*LayerUp) (void *, struct fsm *); /* tlu */
95 void (*LayerDown) (void *, struct fsm *); /* tld */
96 void (*LayerFinish) (void *, struct fsm *); /* tlf */
104 const char *name; /* Name of protocol */
105 u_short proto; /* Protocol number */
108 int open_mode; /* Delay before config REQ (-1 forever) */
109 unsigned state; /* State of the machine */
110 u_char reqid; /* Next request id */
111 int restart; /* Restart counter value */
114 int reqs; /* Max config REQs before a close() */
115 int naks; /* Max config NAKs before a close() */
116 int rejs; /* Max config REJs before a close() */
119 struct pppTimer FsmTimer; /* Restart Timer */
120 struct pppTimer OpenTimer; /* Delay before opening */
123 * This timer times the ST_STOPPED state out after the given value
124 * (specified via "set stopped ..."). Although this isn't specified in the
125 * rfc, the rfc *does* say that "the application may use higher level
126 * timers to avoid deadlock". The StoppedTimer takes effect when the other
127 * side ABENDs rather than going into ST_ACKSENT (and sending the ACK),
128 * causing ppp to time out and drop into ST_STOPPED. At this point,
129 * nothing will change this state :-(
131 struct pppTimer StoppedTimer;
134 /* The link layer active with this FSM (may be our bundle below) */
137 /* Our high-level link */
138 struct bundle *bundle;
140 const struct fsm_parent *parent;
141 const struct fsm_callbacks *fn;
145 u_char code; /* Request code */
146 u_char id; /* Identification */
147 u_short length; /* Length of packet */
150 #define CODE_CONFIGREQ 1
151 #define CODE_CONFIGACK 2
152 #define CODE_CONFIGNAK 3
153 #define CODE_CONFIGREJ 4
154 #define CODE_TERMREQ 5
155 #define CODE_TERMACK 6
156 #define CODE_CODEREJ 7
157 #define CODE_PROTOREJ 8
158 #define CODE_ECHOREQ 9 /* Used in LCP */
159 #define CODE_ECHOREP 10 /* Used in LCP */
160 #define CODE_DISCREQ 11
161 #define CODE_IDENT 12 /* Used in LCP Extension */
162 #define CODE_TIMEREM 13 /* Used in LCP Extension */
163 #define CODE_RESETREQ 14 /* Used in CCP */
164 #define CODE_RESETACK 15 /* Used in CCP */
171 #define MAX_FSM_OPT_LEN 52
173 struct fsm_opt_hdr hdr;
174 u_char data[MAX_FSM_OPT_LEN-2];
177 #define INC_FSM_OPT(ty, length, o) \
179 (o)->hdr.id = (ty); \
180 (o)->hdr.len = (length); \
181 (o) = (struct fsm_opt *)((u_char *)(o) + (length)); \
185 extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int,
186 struct bundle *, struct link *, const struct fsm_parent *,
187 struct fsm_callbacks *, const char * const [3]);
188 extern void fsm_Output(struct fsm *, u_int, u_int, u_char *, unsigned, int);
189 extern void fsm_Open(struct fsm *);
190 extern void fsm_Up(struct fsm *);
191 extern void fsm_Down(struct fsm *);
192 extern void fsm_Input(struct fsm *, struct mbuf *);
193 extern void fsm_Close(struct fsm *);
194 extern int fsm_NullRecvResetReq(struct fsm *);
195 extern void fsm_NullRecvResetAck(struct fsm *, u_char);
196 extern void fsm_Reopen(struct fsm *);
197 extern void fsm2initial(struct fsm *);
198 extern const char *State2Nam(u_int);
199 extern struct fsm_opt *fsm_readopt(u_char **);
200 extern void fsm_rej(struct fsm_decode *, const struct fsm_opt *);
201 extern void fsm_ack(struct fsm_decode *, const struct fsm_opt *);
202 extern void fsm_nak(struct fsm_decode *, const struct fsm_opt *);
203 extern void fsm_opt_normalise(struct fsm_decode *);