1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 by Sun Microsystems, Inc.
5*7c478bd9Sstevel@tonic-gate  * All rights reserved.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software and its
8*7c478bd9Sstevel@tonic-gate  * documentation is hereby granted, provided that the above copyright
9*7c478bd9Sstevel@tonic-gate  * notice appears in all copies.
10*7c478bd9Sstevel@tonic-gate  *
11*7c478bd9Sstevel@tonic-gate  * SUN MAKES NO REPRESENTATION OR WARRANTIES ABOUT THE SUITABILITY OF
12*7c478bd9Sstevel@tonic-gate  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13*7c478bd9Sstevel@tonic-gate  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14*7c478bd9Sstevel@tonic-gate  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT.  SUN SHALL NOT BE LIABLE FOR
15*7c478bd9Sstevel@tonic-gate  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
16*7c478bd9Sstevel@tonic-gate  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
17*7c478bd9Sstevel@tonic-gate  *
18*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1989 Carnegie Mellon University.
19*7c478bd9Sstevel@tonic-gate  * All rights reserved.
20*7c478bd9Sstevel@tonic-gate  *
21*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
22*7c478bd9Sstevel@tonic-gate  * provided that the above copyright notice and this paragraph are
23*7c478bd9Sstevel@tonic-gate  * duplicated in all such forms and that any documentation,
24*7c478bd9Sstevel@tonic-gate  * advertising materials, and other materials related to such
25*7c478bd9Sstevel@tonic-gate  * distribution and use acknowledge that the software was developed
26*7c478bd9Sstevel@tonic-gate  * by Carnegie Mellon University.  The name of the
27*7c478bd9Sstevel@tonic-gate  * University may not be used to endorse or promote products derived
28*7c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
29*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
30*7c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
31*7c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * $Id: fsm.h,v 1.8 1999/11/15 01:51:50 paulus Exp $
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #ifndef __FSM_H__
37*7c478bd9Sstevel@tonic-gate #define __FSM_H__
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
40*7c478bd9Sstevel@tonic-gate extern "C" {
41*7c478bd9Sstevel@tonic-gate #endif
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * Packet header = Code, id, length.
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate #define HEADERLEN	4
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  *  Control Protocol (LCP, IPCP, etc.) message code numbers.
50*7c478bd9Sstevel@tonic-gate  *  (More in lcp.h and net/ppp-comp.h.)
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate #define CODE_CONFREQ		1	/* Configuration Request */
53*7c478bd9Sstevel@tonic-gate #define CODE_CONFACK		2	/* Configuration Ack */
54*7c478bd9Sstevel@tonic-gate #define CODE_CONFNAK		3	/* Configuration Nak */
55*7c478bd9Sstevel@tonic-gate #define CODE_CONFREJ		4	/* Configuration Reject */
56*7c478bd9Sstevel@tonic-gate #define CODE_TERMREQ		5	/* Termination Request */
57*7c478bd9Sstevel@tonic-gate #define CODE_TERMACK		6	/* Termination Ack */
58*7c478bd9Sstevel@tonic-gate #define CODE_CODEREJ		7	/* Code Reject */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate  * Each FSM is described by an fsm structure and fsm callbacks.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate typedef struct fsm {
65*7c478bd9Sstevel@tonic-gate     int unit;			/* Interface unit number */
66*7c478bd9Sstevel@tonic-gate     int protocol;		/* Data Link Layer Protocol field value */
67*7c478bd9Sstevel@tonic-gate     int state;			/* State */
68*7c478bd9Sstevel@tonic-gate     int flags;			/* Contains option bits */
69*7c478bd9Sstevel@tonic-gate     u_char id;			/* Current id */
70*7c478bd9Sstevel@tonic-gate     u_char reqid;		/* Current request id */
71*7c478bd9Sstevel@tonic-gate     u_char seen_ack;		/* Have received valid Ack/Nak/Rej to Req */
72*7c478bd9Sstevel@tonic-gate     int timeouttime;		/* Timeout time in milliseconds */
73*7c478bd9Sstevel@tonic-gate     int maxconfreqtransmits;	/* Maximum Configure-Request transmissions */
74*7c478bd9Sstevel@tonic-gate     int retransmits;		/* Number of retransmissions left */
75*7c478bd9Sstevel@tonic-gate     int maxtermtransmits;	/* Maximum Terminate-Request transmissions */
76*7c478bd9Sstevel@tonic-gate     int nakloops;		/* Number of nak loops since last ack */
77*7c478bd9Sstevel@tonic-gate     int maxnakloops;		/* Maximum number of nak loops tolerated */
78*7c478bd9Sstevel@tonic-gate     struct fsm_callbacks *callbacks;	/* Callback routines */
79*7c478bd9Sstevel@tonic-gate     char *term_reason;		/* Reason for closing protocol */
80*7c478bd9Sstevel@tonic-gate     int term_reason_len;	/* Length of term_reason */
81*7c478bd9Sstevel@tonic-gate     u_int32_t codemask[8];	/* Codes rejected by peer */
82*7c478bd9Sstevel@tonic-gate } fsm;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate /*
85*7c478bd9Sstevel@tonic-gate  *	Function	RFC 1661
86*7c478bd9Sstevel@tonic-gate  *	-----		------------------------------
87*7c478bd9Sstevel@tonic-gate  *	ackci		RCA
88*7c478bd9Sstevel@tonic-gate  *	nakci		RCN
89*7c478bd9Sstevel@tonic-gate  *	rejci		RCN
90*7c478bd9Sstevel@tonic-gate  *	reqci		RCR+ or RCR- (by return value)
91*7c478bd9Sstevel@tonic-gate  *	up		tlu (this-layer-up)
92*7c478bd9Sstevel@tonic-gate  *	down		tld (this-layer-down)
93*7c478bd9Sstevel@tonic-gate  *	starting	tls (this-layer-starting)
94*7c478bd9Sstevel@tonic-gate  *	finished	tlf (this-layer-finished)
95*7c478bd9Sstevel@tonic-gate  *	codereject	RXJ+ or RXJ- (by return value)
96*7c478bd9Sstevel@tonic-gate  *
97*7c478bd9Sstevel@tonic-gate  * Note that this-layer-down means "stop transmitting."
98*7c478bd9Sstevel@tonic-gate  * This-layer-finished means "stop everything."
99*7c478bd9Sstevel@tonic-gate  */
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate typedef struct fsm_callbacks {
102*7c478bd9Sstevel@tonic-gate     void (*resetci)		/* Reset our Configuration Information */
103*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
104*7c478bd9Sstevel@tonic-gate     int  (*cilen)		/* Length of our Configuration Information */
105*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
106*7c478bd9Sstevel@tonic-gate     void (*addci)		/* Add our Configuration Information */
107*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int *));
108*7c478bd9Sstevel@tonic-gate     int  (*ackci)		/* ACK our Configuration Information */
109*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int));
110*7c478bd9Sstevel@tonic-gate     int  (*nakci)		/* NAK our Configuration Information */
111*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int));
112*7c478bd9Sstevel@tonic-gate     int  (*rejci)		/* Reject our Configuration Information */
113*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int));
114*7c478bd9Sstevel@tonic-gate     int  (*reqci)		/* Request peer's Configuration Information */
115*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int *, int));
116*7c478bd9Sstevel@tonic-gate     void (*up)			/* Called when fsm reaches OPENED state */
117*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
118*7c478bd9Sstevel@tonic-gate     void (*down)		/* Called when fsm leaves OPENED state */
119*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
120*7c478bd9Sstevel@tonic-gate     void (*starting)		/* Called when we want the lower layer */
121*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
122*7c478bd9Sstevel@tonic-gate     void (*finished)		/* Called when we don't want the lower layer */
123*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
124*7c478bd9Sstevel@tonic-gate     void (*retransmit)		/* Retransmission is necessary */
125*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
126*7c478bd9Sstevel@tonic-gate     int  (*extcode)		/* Called when unknown code received */
127*7c478bd9Sstevel@tonic-gate 		__P((fsm *, int, int, u_char *, int));
128*7c478bd9Sstevel@tonic-gate     char *proto_name;		/* String name for protocol (for messages) */
129*7c478bd9Sstevel@tonic-gate     int (*codereject)		/* Called when Code-Reject received */
130*7c478bd9Sstevel@tonic-gate 		__P((fsm *p, int code, int id, u_char *inp, int len));
131*7c478bd9Sstevel@tonic-gate } fsm_callbacks;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate /*
135*7c478bd9Sstevel@tonic-gate  * RFC 1661 NCP states.
136*7c478bd9Sstevel@tonic-gate  */
137*7c478bd9Sstevel@tonic-gate #define INITIAL		0	/* Down, hasn't been opened */
138*7c478bd9Sstevel@tonic-gate #define STARTING	1	/* Down, been opened */
139*7c478bd9Sstevel@tonic-gate #define CLOSED		2	/* Up, hasn't been opened */
140*7c478bd9Sstevel@tonic-gate #define STOPPED		3	/* Open, waiting for down event */
141*7c478bd9Sstevel@tonic-gate #define CLOSING		4	/* Terminating the connection, not open */
142*7c478bd9Sstevel@tonic-gate #define STOPPING	5	/* Terminating, but open */
143*7c478bd9Sstevel@tonic-gate #define REQSENT		6	/* We've sent a Config Request */
144*7c478bd9Sstevel@tonic-gate #define ACKRCVD		7	/* We've received a Config Ack */
145*7c478bd9Sstevel@tonic-gate #define ACKSENT		8	/* We've sent a Config Ack */
146*7c478bd9Sstevel@tonic-gate #define OPENED		9	/* Connection available */
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate #define FSM__STATES \
149*7c478bd9Sstevel@tonic-gate 	"Initial", "Starting", "Closed", "Stopped", "Closing", "Stopping", \
150*7c478bd9Sstevel@tonic-gate 	"ReqSent", "AckRcvd", "AckSent", "Opened"
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate /*
153*7c478bd9Sstevel@tonic-gate  * Flags - indicate options controlling FSM operation
154*7c478bd9Sstevel@tonic-gate  */
155*7c478bd9Sstevel@tonic-gate #define OPT_PASSIVE	1	/* Don't die if we don't get a response */
156*7c478bd9Sstevel@tonic-gate #define OPT_RESTART	2	/* Treat 2nd OPEN as DOWN, UP */
157*7c478bd9Sstevel@tonic-gate #define OPT_SILENT	4	/* Wait for peer to speak first */
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  * Timeouts.
162*7c478bd9Sstevel@tonic-gate  */
163*7c478bd9Sstevel@tonic-gate #define DEFTIMEOUT	3	/* Timeout time in seconds */
164*7c478bd9Sstevel@tonic-gate #define DEFMAXTERMREQS	2	/* Maximum Terminate-Request transmissions */
165*7c478bd9Sstevel@tonic-gate #define DEFMAXCONFREQS	10	/* Maximum Configure-Request transmissions */
166*7c478bd9Sstevel@tonic-gate #define DEFMAXNAKLOOPS	5	/* Maximum number of nak loops */
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate /*
170*7c478bd9Sstevel@tonic-gate  * Prototypes
171*7c478bd9Sstevel@tonic-gate  */
172*7c478bd9Sstevel@tonic-gate void fsm_init __P((fsm *));
173*7c478bd9Sstevel@tonic-gate void fsm_lowerup __P((fsm *));
174*7c478bd9Sstevel@tonic-gate void fsm_lowerdown __P((fsm *));
175*7c478bd9Sstevel@tonic-gate void fsm_open __P((fsm *));
176*7c478bd9Sstevel@tonic-gate void fsm_close __P((fsm *, char *));
177*7c478bd9Sstevel@tonic-gate void fsm_input __P((fsm *, u_char *, int));
178*7c478bd9Sstevel@tonic-gate void fsm_protreject __P((fsm *));
179*7c478bd9Sstevel@tonic-gate void fsm_sdata __P((fsm *, int, int, u_char *, int));
180*7c478bd9Sstevel@tonic-gate void fsm_setpeermru __P((int, int));
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate const char *fsm_state __P((int statenum));
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
185*7c478bd9Sstevel@tonic-gate }
186*7c478bd9Sstevel@tonic-gate #endif
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate #endif /* __FSM_H__ */
189