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