2 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
4 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that the above copyright notice and this paragraph are
8 * duplicated in all such forms and that any documentation,
9 * advertising materials, and other materials related to such
10 * distribution and use acknowledge that the software was developed
11 * by the Internet Initiative Japan. The name of the
12 * IIJ may not be used to endorse or promote products derived
13 * from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
44 #define MODE_ACK 4 /* pseudo mode for ccp negotiations */
46 #define OPEN_PASSIVE -1
48 #define FSM_REQ_TIMER 1
49 #define FSM_TRM_TIMER 2
54 u_int timeout; /* FSM retry frequency */
55 u_int maxreq; /* Max Config REQ retries */
56 u_int maxtrm; /* Max Term REQ retries */
60 u_char ack[100], *ackend;
61 u_char nak[100], *nakend;
62 u_char rej[100], *rejend;
65 struct fsm_callbacks {
66 int (*LayerUp) (struct fsm *); /* Layer is now up (tlu) */
67 void (*LayerDown) (struct fsm *); /* About to come down (tld) */
68 void (*LayerStart) (struct fsm *); /* Layer about to start up (tls) */
69 void (*LayerFinish) (struct fsm *); /* Layer now down (tlf) */
70 void (*InitRestartCounter) (struct fsm *, int); /* Set fsm timer load */
71 void (*SendConfigReq) (struct fsm *); /* Send REQ please */
72 void (*SentTerminateReq) (struct fsm *); /* Term REQ just sent */
73 void (*SendTerminateAck) (struct fsm *, u_char); /* Send Term ACK please */
74 void (*DecodeConfig) (struct fsm *, u_char *, int, int, struct fsm_decode *);
75 /* Deal with incoming data */
76 void (*RecvResetReq) (struct fsm *fp); /* Reset output */
77 void (*RecvResetAck) (struct fsm *fp, u_char); /* Reset input */
81 void (*LayerStart) (void *, struct fsm *); /* tls */
82 void (*LayerUp) (void *, struct fsm *); /* tlu */
83 void (*LayerDown) (void *, struct fsm *); /* tld */
84 void (*LayerFinish) (void *, struct fsm *); /* tlf */
92 const char *name; /* Name of protocol */
93 u_short proto; /* Protocol number */
96 int open_mode; /* Delay before config REQ (-1 forever) */
97 int state; /* State of the machine */
98 u_char reqid; /* Next request id */
99 int restart; /* Restart counter value */
102 int reqs; /* Max config REQs before a close() */
103 int naks; /* Max config NAKs before a close() */
104 int rejs; /* Max config REJs before a close() */
107 struct pppTimer FsmTimer; /* Restart Timer */
108 struct pppTimer OpenTimer; /* Delay before opening */
111 * This timer times the ST_STOPPED state out after the given value
112 * (specified via "set stopped ..."). Although this isn't specified in the
113 * rfc, the rfc *does* say that "the application may use higher level
114 * timers to avoid deadlock". The StoppedTimer takes effect when the other
115 * side ABENDs rather than going into ST_ACKSENT (and sending the ACK),
116 * causing ppp to time out and drop into ST_STOPPED. At this point,
117 * nothing will change this state :-(
119 struct pppTimer StoppedTimer;
122 /* The link layer active with this FSM (may be our bundle below) */
125 /* Our high-level link */
126 struct bundle *bundle;
128 const struct fsm_parent *parent;
129 const struct fsm_callbacks *fn;
133 u_char code; /* Request code */
134 u_char id; /* Identification */
135 u_short length; /* Length of packet */
138 #define CODE_CONFIGREQ 1
139 #define CODE_CONFIGACK 2
140 #define CODE_CONFIGNAK 3
141 #define CODE_CONFIGREJ 4
142 #define CODE_TERMREQ 5
143 #define CODE_TERMACK 6
144 #define CODE_CODEREJ 7
145 #define CODE_PROTOREJ 8
146 #define CODE_ECHOREQ 9 /* Used in LCP */
147 #define CODE_ECHOREP 10 /* Used in LCP */
148 #define CODE_DISCREQ 11
149 #define CODE_IDENT 12 /* Used in LCP Extension */
150 #define CODE_TIMEREM 13 /* Used in LCP Extension */
151 #define CODE_RESETREQ 14 /* Used in CCP */
152 #define CODE_RESETACK 15 /* Used in CCP */
154 /* Minimum config req size. This struct is *only* used for it's size */
160 extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int,
161 struct bundle *, struct link *, const struct fsm_parent *,
162 struct fsm_callbacks *, const char *[3]);
163 extern void fsm_Output(struct fsm *, u_int, u_int, u_char *, int, int);
164 extern void fsm_Open(struct fsm *);
165 extern void fsm_Up(struct fsm *);
166 extern void fsm_Down(struct fsm *);
167 extern void fsm_Input(struct fsm *, struct mbuf *);
168 extern void fsm_Close(struct fsm *);
169 extern void fsm_NullRecvResetReq(struct fsm *);
170 extern void fsm_NullRecvResetAck(struct fsm *, u_char);
171 extern void fsm_Reopen(struct fsm *);
172 extern void fsm2initial(struct fsm *);
173 extern const char *State2Nam(u_int);