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