xref: /titanic_52/usr/src/cmd/cmd-inet/usr.bin/pppd/fsm.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifndef __FSM_H__
39*7c478bd9Sstevel@tonic-gate #define __FSM_H__
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
42*7c478bd9Sstevel@tonic-gate extern "C" {
43*7c478bd9Sstevel@tonic-gate #endif
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * Packet header = Code, id, length.
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate #define HEADERLEN	4
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  *  Control Protocol (LCP, IPCP, etc.) message code numbers.
52*7c478bd9Sstevel@tonic-gate  *  (More in lcp.h and net/ppp-comp.h.)
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate #define CODE_CONFREQ		1	/* Configuration Request */
55*7c478bd9Sstevel@tonic-gate #define CODE_CONFACK		2	/* Configuration Ack */
56*7c478bd9Sstevel@tonic-gate #define CODE_CONFNAK		3	/* Configuration Nak */
57*7c478bd9Sstevel@tonic-gate #define CODE_CONFREJ		4	/* Configuration Reject */
58*7c478bd9Sstevel@tonic-gate #define CODE_TERMREQ		5	/* Termination Request */
59*7c478bd9Sstevel@tonic-gate #define CODE_TERMACK		6	/* Termination Ack */
60*7c478bd9Sstevel@tonic-gate #define CODE_CODEREJ		7	/* Code Reject */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate  * Each FSM is described by an fsm structure and fsm callbacks.
65*7c478bd9Sstevel@tonic-gate  */
66*7c478bd9Sstevel@tonic-gate typedef struct fsm {
67*7c478bd9Sstevel@tonic-gate     int unit;			/* Interface unit number */
68*7c478bd9Sstevel@tonic-gate     int protocol;		/* Data Link Layer Protocol field value */
69*7c478bd9Sstevel@tonic-gate     int state;			/* State */
70*7c478bd9Sstevel@tonic-gate     int flags;			/* Contains option bits */
71*7c478bd9Sstevel@tonic-gate     u_char id;			/* Current id */
72*7c478bd9Sstevel@tonic-gate     u_char reqid;		/* Current request id */
73*7c478bd9Sstevel@tonic-gate     u_char seen_ack;		/* Have received valid Ack/Nak/Rej to Req */
74*7c478bd9Sstevel@tonic-gate     int timeouttime;		/* Timeout time in milliseconds */
75*7c478bd9Sstevel@tonic-gate     int maxconfreqtransmits;	/* Maximum Configure-Request transmissions */
76*7c478bd9Sstevel@tonic-gate     int retransmits;		/* Number of retransmissions left */
77*7c478bd9Sstevel@tonic-gate     int maxtermtransmits;	/* Maximum Terminate-Request transmissions */
78*7c478bd9Sstevel@tonic-gate     int nakloops;		/* Number of nak loops since last ack */
79*7c478bd9Sstevel@tonic-gate     int maxnakloops;		/* Maximum number of nak loops tolerated */
80*7c478bd9Sstevel@tonic-gate     struct fsm_callbacks *callbacks;	/* Callback routines */
81*7c478bd9Sstevel@tonic-gate     char *term_reason;		/* Reason for closing protocol */
82*7c478bd9Sstevel@tonic-gate     int term_reason_len;	/* Length of term_reason */
83*7c478bd9Sstevel@tonic-gate     u_int32_t codemask[8];	/* Codes rejected by peer */
84*7c478bd9Sstevel@tonic-gate } fsm;
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate /*
87*7c478bd9Sstevel@tonic-gate  *	Function	RFC 1661
88*7c478bd9Sstevel@tonic-gate  *	-----		------------------------------
89*7c478bd9Sstevel@tonic-gate  *	ackci		RCA
90*7c478bd9Sstevel@tonic-gate  *	nakci		RCN
91*7c478bd9Sstevel@tonic-gate  *	rejci		RCN
92*7c478bd9Sstevel@tonic-gate  *	reqci		RCR+ or RCR- (by return value)
93*7c478bd9Sstevel@tonic-gate  *	up		tlu (this-layer-up)
94*7c478bd9Sstevel@tonic-gate  *	down		tld (this-layer-down)
95*7c478bd9Sstevel@tonic-gate  *	starting	tls (this-layer-starting)
96*7c478bd9Sstevel@tonic-gate  *	finished	tlf (this-layer-finished)
97*7c478bd9Sstevel@tonic-gate  *	codereject	RXJ+ or RXJ- (by return value)
98*7c478bd9Sstevel@tonic-gate  *
99*7c478bd9Sstevel@tonic-gate  * Note that this-layer-down means "stop transmitting."
100*7c478bd9Sstevel@tonic-gate  * This-layer-finished means "stop everything."
101*7c478bd9Sstevel@tonic-gate  */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate typedef struct fsm_callbacks {
104*7c478bd9Sstevel@tonic-gate     void (*resetci)		/* Reset our Configuration Information */
105*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
106*7c478bd9Sstevel@tonic-gate     int  (*cilen)		/* Length of our Configuration Information */
107*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
108*7c478bd9Sstevel@tonic-gate     void (*addci)		/* Add our Configuration Information */
109*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int *));
110*7c478bd9Sstevel@tonic-gate     int  (*ackci)		/* ACK our Configuration Information */
111*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int));
112*7c478bd9Sstevel@tonic-gate     int  (*nakci)		/* NAK our Configuration Information */
113*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int));
114*7c478bd9Sstevel@tonic-gate     int  (*rejci)		/* Reject our Configuration Information */
115*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int));
116*7c478bd9Sstevel@tonic-gate     int  (*reqci)		/* Request peer's Configuration Information */
117*7c478bd9Sstevel@tonic-gate 		__P((fsm *, u_char *, int *, int));
118*7c478bd9Sstevel@tonic-gate     void (*up)			/* Called when fsm reaches OPENED state */
119*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
120*7c478bd9Sstevel@tonic-gate     void (*down)		/* Called when fsm leaves OPENED state */
121*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
122*7c478bd9Sstevel@tonic-gate     void (*starting)		/* Called when we want the lower layer */
123*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
124*7c478bd9Sstevel@tonic-gate     void (*finished)		/* Called when we don't want the lower layer */
125*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
126*7c478bd9Sstevel@tonic-gate     void (*retransmit)		/* Retransmission is necessary */
127*7c478bd9Sstevel@tonic-gate 		__P((fsm *));
128*7c478bd9Sstevel@tonic-gate     int  (*extcode)		/* Called when unknown code received */
129*7c478bd9Sstevel@tonic-gate 		__P((fsm *, int, int, u_char *, int));
130*7c478bd9Sstevel@tonic-gate     char *proto_name;		/* String name for protocol (for messages) */
131*7c478bd9Sstevel@tonic-gate     int (*codereject)		/* Called when Code-Reject received */
132*7c478bd9Sstevel@tonic-gate 		__P((fsm *p, int code, int id, u_char *inp, int len));
133*7c478bd9Sstevel@tonic-gate } fsm_callbacks;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate /*
137*7c478bd9Sstevel@tonic-gate  * RFC 1661 NCP states.
138*7c478bd9Sstevel@tonic-gate  */
139*7c478bd9Sstevel@tonic-gate #define INITIAL		0	/* Down, hasn't been opened */
140*7c478bd9Sstevel@tonic-gate #define STARTING	1	/* Down, been opened */
141*7c478bd9Sstevel@tonic-gate #define CLOSED		2	/* Up, hasn't been opened */
142*7c478bd9Sstevel@tonic-gate #define STOPPED		3	/* Open, waiting for down event */
143*7c478bd9Sstevel@tonic-gate #define CLOSING		4	/* Terminating the connection, not open */
144*7c478bd9Sstevel@tonic-gate #define STOPPING	5	/* Terminating, but open */
145*7c478bd9Sstevel@tonic-gate #define REQSENT		6	/* We've sent a Config Request */
146*7c478bd9Sstevel@tonic-gate #define ACKRCVD		7	/* We've received a Config Ack */
147*7c478bd9Sstevel@tonic-gate #define ACKSENT		8	/* We've sent a Config Ack */
148*7c478bd9Sstevel@tonic-gate #define OPENED		9	/* Connection available */
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate #define FSM__STATES \
151*7c478bd9Sstevel@tonic-gate 	"Initial", "Starting", "Closed", "Stopped", "Closing", "Stopping", \
152*7c478bd9Sstevel@tonic-gate 	"ReqSent", "AckRcvd", "AckSent", "Opened"
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate /*
155*7c478bd9Sstevel@tonic-gate  * Flags - indicate options controlling FSM operation
156*7c478bd9Sstevel@tonic-gate  */
157*7c478bd9Sstevel@tonic-gate #define OPT_PASSIVE	1	/* Don't die if we don't get a response */
158*7c478bd9Sstevel@tonic-gate #define OPT_RESTART	2	/* Treat 2nd OPEN as DOWN, UP */
159*7c478bd9Sstevel@tonic-gate #define OPT_SILENT	4	/* Wait for peer to speak first */
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate /*
163*7c478bd9Sstevel@tonic-gate  * Timeouts.
164*7c478bd9Sstevel@tonic-gate  */
165*7c478bd9Sstevel@tonic-gate #define DEFTIMEOUT	3	/* Timeout time in seconds */
166*7c478bd9Sstevel@tonic-gate #define DEFMAXTERMREQS	2	/* Maximum Terminate-Request transmissions */
167*7c478bd9Sstevel@tonic-gate #define DEFMAXCONFREQS	10	/* Maximum Configure-Request transmissions */
168*7c478bd9Sstevel@tonic-gate #define DEFMAXNAKLOOPS	5	/* Maximum number of nak loops */
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate /*
172*7c478bd9Sstevel@tonic-gate  * Prototypes
173*7c478bd9Sstevel@tonic-gate  */
174*7c478bd9Sstevel@tonic-gate void fsm_init __P((fsm *));
175*7c478bd9Sstevel@tonic-gate void fsm_lowerup __P((fsm *));
176*7c478bd9Sstevel@tonic-gate void fsm_lowerdown __P((fsm *));
177*7c478bd9Sstevel@tonic-gate void fsm_open __P((fsm *));
178*7c478bd9Sstevel@tonic-gate void fsm_close __P((fsm *, char *));
179*7c478bd9Sstevel@tonic-gate void fsm_input __P((fsm *, u_char *, int));
180*7c478bd9Sstevel@tonic-gate void fsm_protreject __P((fsm *));
181*7c478bd9Sstevel@tonic-gate void fsm_sdata __P((fsm *, int, int, u_char *, int));
182*7c478bd9Sstevel@tonic-gate void fsm_setpeermru __P((int, int));
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate const char *fsm_state __P((int statenum));
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
187*7c478bd9Sstevel@tonic-gate }
188*7c478bd9Sstevel@tonic-gate #endif
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate #endif /* __FSM_H__ */
191