xref: /openbsd/usr.sbin/pppd/fsm.h (revision 07ea8d15)
1 /*	$OpenBSD: fsm.h,v 1.2 1996/03/25 15:55:39 niklas Exp $	*/
2 
3 /*
4  * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
5  *
6  * Copyright (c) 1989 Carnegie Mellon University.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms are permitted
10  * provided that the above copyright notice and this paragraph are
11  * duplicated in all such forms and that any documentation,
12  * advertising materials, and other materials related to such
13  * distribution and use acknowledge that the software was developed
14  * by Carnegie Mellon University.  The name of the
15  * University may not be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20  */
21 
22 /*
23  * Packet header = Code, id, length.
24  */
25 #define HEADERLEN	(sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
26 
27 
28 /*
29  *  CP (LCP, IPCP, etc.) codes.
30  */
31 #define CONFREQ		1	/* Configuration Request */
32 #define CONFACK		2	/* Configuration Ack */
33 #define CONFNAK		3	/* Configuration Nak */
34 #define CONFREJ		4	/* Configuration Reject */
35 #define TERMREQ		5	/* Termination Request */
36 #define TERMACK		6	/* Termination Ack */
37 #define CODEREJ		7	/* Code Reject */
38 
39 
40 /*
41  * Each FSM is described by a fsm_callbacks and a fsm structure.
42  */
43 typedef struct fsm_callbacks {
44     void (*resetci)();		/* Reset our Configuration Information */
45     int  (*cilen)();		/* Length of our Configuration Information */
46     void (*addci)();		/* Add our Configuration Information */
47     int  (*ackci)();		/* ACK our Configuration Information */
48     int  (*nakci)();		/* NAK our Configuration Information */
49     int  (*rejci)();		/* Reject our Configuration Information */
50     int  (*reqci)();		/* Request peer's Configuration Information */
51     void (*up)();		/* Called when fsm reaches OPENED state */
52     void (*down)();		/* Called when fsm leaves OPENED state */
53     void (*starting)();		/* Called when we want the lower layer */
54     void (*finished)();		/* Called when we don't want the lower layer */
55     void (*protreject)();	/* Called when Protocol-Reject received */
56     void (*retransmit)();	/* Retransmission is necessary */
57     int  (*extcode)();		/* Called when unknown code received */
58     char *proto_name;		/* String name for protocol (for messages) */
59 } fsm_callbacks;
60 
61 
62 typedef struct fsm {
63     int unit;			/* Interface unit number */
64     int protocol;		/* Data Link Layer Protocol field value */
65     int state;			/* State */
66     int flags;			/* Contains option bits */
67     u_char id;			/* Current id */
68     u_char reqid;		/* Current request id */
69     u_char seen_ack;		/* Have received valid Ack/Nak/Rej to Req */
70     int timeouttime;		/* Timeout time in milliseconds */
71     int maxconfreqtransmits;	/* Maximum Configure-Request transmissions */
72     int retransmits;		/* Number of retransmissions left */
73     int maxtermtransmits;	/* Maximum Terminate-Request transmissions */
74     int nakloops;		/* Number of nak loops since last ack */
75     int maxnakloops;		/* Maximum number of nak loops tolerated */
76     fsm_callbacks *callbacks;	/* Callback routines */
77     char *term_reason;		/* Reason for closing protocol */
78     int term_reason_len;	/* Length of term_reason */
79 } fsm;
80 
81 
82 /*
83  * Link states.
84  */
85 #define INITIAL		0	/* Down, hasn't been opened */
86 #define STARTING	1	/* Down, been opened */
87 #define CLOSED		2	/* Up, hasn't been opened */
88 #define STOPPED		3	/* Open, waiting for down event */
89 #define CLOSING		4	/* Terminating the connection, not open */
90 #define STOPPING	5	/* Terminating, but open */
91 #define REQSENT		6	/* We've sent a Config Request */
92 #define ACKRCVD		7	/* We've received a Config Ack */
93 #define ACKSENT		8	/* We've sent a Config Ack */
94 #define OPENED		9	/* Connection available */
95 
96 
97 /*
98  * Flags - indicate options controlling FSM operation
99  */
100 #define OPT_PASSIVE	1	/* Don't die if we don't get a response */
101 #define OPT_RESTART	2	/* Treat 2nd OPEN as DOWN, UP */
102 #define OPT_SILENT	4	/* Wait for peer to speak first */
103 
104 
105 /*
106  * Timeouts.
107  */
108 #define DEFTIMEOUT	3	/* Timeout time in seconds */
109 #define DEFMAXTERMREQS	2	/* Maximum Terminate-Request transmissions */
110 #define DEFMAXCONFREQS	10	/* Maximum Configure-Request transmissions */
111 #define DEFMAXNAKLOOPS	5	/* Maximum number of nak loops */
112 
113 
114 /*
115  * Prototypes
116  */
117 void fsm_init __P((fsm *));
118 void fsm_lowerup __P((fsm *));
119 void fsm_lowerdown __P((fsm *));
120 void fsm_open __P((fsm *));
121 void fsm_close __P((fsm *, char *));
122 void fsm_input __P((fsm *, u_char *, int));
123 void fsm_protreject __P((fsm *));
124 void fsm_sdata __P((fsm *, int, int, u_char *, int));
125 
126 
127 /*
128  * Variables
129  */
130 extern int peer_mru[];		/* currently negotiated peer MRU (per unit) */
131