xref: /netbsd-src/external/bsd/ppp/dist/pppd/fsm.h (revision f12839c5f795a8def46f685de6698463dbd213a9)
1 /*	$NetBSD: fsm.h,v 1.6 2025/01/08 19:59:39 christos Exp $	*/
2 
3 /*
4  * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
5  *
6  * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. The name "Carnegie Mellon University" must not be used to
21  *    endorse or promote products derived from this software without
22  *    prior written permission. For permission or any legal
23  *    details, please contact
24  *      Office of Technology Transfer
25  *      Carnegie Mellon University
26  *      5000 Forbes Avenue
27  *      Pittsburgh, PA  15213-3890
28  *      (412) 268-4387, fax: (412) 268-7395
29  *      tech-transfer@andrew.cmu.edu
30  *
31  * 4. Redistributions of any form whatsoever must retain the following
32  *    acknowledgment:
33  *    "This product includes software developed by Computing Services
34  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
35  *
36  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
37  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
39  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
41  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
42  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43  */
44 #ifndef PPP_FSM_H
45 #define PPP_FSM_H
46 
47 #include "pppdconf.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * Packet header = Code, id, length.
55  */
56 #define HEADERLEN	4
57 
58 /*
59  *  CP (LCP, IPCP, etc.) codes.
60  */
61 #define CONFREQ		1	/* Configuration Request */
62 #define CONFACK		2	/* Configuration Ack */
63 #define CONFNAK		3	/* Configuration Nak */
64 #define CONFREJ		4	/* Configuration Reject */
65 #define TERMREQ		5	/* Termination Request */
66 #define TERMACK		6	/* Termination Ack */
67 #define CODEREJ		7	/* Code Reject */
68 
69 
70 /*
71  * Each FSM is described by an fsm structure and fsm callbacks.
72  */
73 typedef struct fsm {
74     int unit;			/* Interface unit number */
75     int protocol;		/* Data Link Layer Protocol field value */
76     int state;			/* State */
77     int flags;			/* Contains option bits */
78     unsigned char id;			/* Current id */
79     unsigned char reqid;		/* Current request id */
80     unsigned char seen_ack;		/* Have received valid Ack/Nak/Rej to Req */
81     int timeouttime;		/* Timeout time in milliseconds */
82     int maxconfreqtransmits;	/* Maximum Configure-Request transmissions */
83     int retransmits;		/* Number of retransmissions left */
84     int maxtermtransmits;	/* Maximum Terminate-Request transmissions */
85     int nakloops;		/* Number of nak loops since last ack */
86     int rnakloops;		/* Number of naks received */
87     int maxnakloops;		/* Maximum number of nak loops tolerated */
88     struct fsm_callbacks *callbacks;	/* Callback routines */
89     char *term_reason;		/* Reason for closing protocol */
90     int term_reason_len;	/* Length of term_reason */
91 } fsm;
92 
93 
94 typedef struct fsm_callbacks {
95     void (*resetci)(fsm *);	/* Reset our Configuration Information */
96     int  (*cilen)(fsm *);	/* Length of our Configuration Information */
97     void (*addci) 		/* Add our Configuration Information */
98 		(fsm *, unsigned char *, int *);
99     int  (*ackci)		/* ACK our Configuration Information */
100 		(fsm *, unsigned char *, int);
101     int  (*nakci)		/* NAK our Configuration Information */
102 		(fsm *, unsigned char *, int, int);
103     int  (*rejci)		/* Reject our Configuration Information */
104 		(fsm *, unsigned char *, int);
105     int  (*reqci)		/* Request peer's Configuration Information */
106 		(fsm *, unsigned char *, int *, int);
107     void (*up)(fsm *);		/* Called when fsm reaches OPENED state */
108     void (*down)(fsm *);	/* Called when fsm leaves OPENED state */
109     void (*starting)(fsm *);	/* Called when we want the lower layer */
110     void (*finished)(fsm *);	/* Called when we don't want the lower layer */
111     void (*protreject)(int);	/* Called when Protocol-Reject received */
112     void (*retransmit)(fsm *);	/* Retransmission is necessary */
113     int  (*extcode)		/* Called when unknown code received */
114 		(fsm *, int, int, unsigned char *, int);
115     char *proto_name;		/* String name for protocol (for messages) */
116 } fsm_callbacks;
117 
118 
119 /*
120  * Link states.
121  */
122 #define INITIAL		0	/* Down, hasn't been opened */
123 #define STARTING	1	/* Down, been opened */
124 #define CLOSED		2	/* Up, hasn't been opened */
125 #define STOPPED		3	/* Open, waiting for down event */
126 #define CLOSING		4	/* Terminating the connection, not open */
127 #define STOPPING	5	/* Terminating, but open */
128 #define REQSENT		6	/* We've sent a Config Request */
129 #define ACKRCVD		7	/* We've received a Config Ack */
130 #define ACKSENT		8	/* We've sent a Config Ack */
131 #define OPENED		9	/* Connection available */
132 
133 
134 /*
135  * Flags - indicate options controlling FSM operation
136  */
137 #define OPT_PASSIVE	1	/* Don't die if we don't get a response */
138 #define OPT_RESTART	2	/* Treat 2nd OPEN as DOWN, UP */
139 #define OPT_SILENT	4	/* Wait for peer to speak first */
140 
141 
142 /*
143  * Timeouts.
144  */
145 #define DEFTIMEOUT	3	/* Timeout time in seconds */
146 #define DEFMAXTERMREQS	2	/* Maximum Terminate-Request transmissions */
147 #define DEFMAXCONFREQS	10	/* Maximum Configure-Request transmissions */
148 #define DEFMAXNAKLOOPS	5	/* Maximum number of nak loops */
149 
150 
151 /*
152  * Prototypes
153  */
154 void fsm_init (fsm *);
155 void fsm_lowerup (fsm *);
156 void fsm_lowerdown (fsm *);
157 void fsm_open (fsm *);
158 void fsm_close (fsm *, char *);
159 void fsm_input (fsm *, unsigned char *, int);
160 void fsm_protreject (fsm *);
161 void fsm_sdata (fsm *, int, int, unsigned char *, int);
162 
163 
164 /*
165  * Variables
166  */
167 extern int peer_mru[];		/* currently negotiated peer MRU (per unit) */
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif // PPP_FSM_H
174