]> git.sur5r.net Git - freertos/blob - Demo/Common/ethernet/lwIP/netif/ppp/fsm.h
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@82 1d2547de-c912-0410-9cb9...
[freertos] / Demo / Common / ethernet / lwIP / netif / ppp / fsm.h
1 /*****************************************************************************\r
2 * fsm.h - Network Control Protocol Finite State Machine header file.\r
3 *\r
4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.\r
5 * Copyright (c) 1997 Global Election Systems Inc.\r
6 *\r
7 * The authors hereby grant permission to use, copy, modify, distribute,\r
8 * and license this software and its documentation for any purpose, provided\r
9 * that existing copyright notices are retained in all copies and that this\r
10 * notice and the following disclaimer are included verbatim in any \r
11 * distributions. No written agreement, license, or royalty fee is required\r
12 * for any of the authorized uses.\r
13 *\r
14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR\r
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
24 *\r
25 ******************************************************************************\r
26 * REVISION HISTORY\r
27 *\r
28 * 03-01-01 Marc Boucher <marc@mbsi.ca>\r
29 *   Ported to lwIP.\r
30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.\r
31 *       Original based on BSD code.\r
32 *****************************************************************************/\r
33 /*\r
34  * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.\r
35  *\r
36  * Copyright (c) 1989 Carnegie Mellon University.\r
37  * All rights reserved.\r
38  *\r
39  * Redistribution and use in source and binary forms are permitted\r
40  * provided that the above copyright notice and this paragraph are\r
41  * duplicated in all such forms and that any documentation,\r
42  * advertising materials, and other materials related to such\r
43  * distribution and use acknowledge that the software was developed\r
44  * by Carnegie Mellon University.  The name of the\r
45  * University may not be used to endorse or promote products derived\r
46  * from this software without specific prior written permission.\r
47  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR\r
48  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED\r
49  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\r
50  *\r
51  * $Id: fsm.h,v 1.1 2003/05/27 14:37:56 jani Exp $\r
52  */\r
53 \r
54 #ifndef FSM_H\r
55 #define FSM_H\r
56 \r
57 \r
58 /*****************************************************************************\r
59 ************************* PUBLIC DEFINITIONS *********************************\r
60 *****************************************************************************/\r
61 /*\r
62  * LCP Packet header = Code, id, length.\r
63  */\r
64 #define HEADERLEN       (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))\r
65 \r
66 \r
67 /*\r
68  *  CP (LCP, IPCP, etc.) codes.\r
69  */\r
70 #define CONFREQ         1               /* Configuration Request */\r
71 #define CONFACK         2               /* Configuration Ack */\r
72 #define CONFNAK         3               /* Configuration Nak */\r
73 #define CONFREJ         4               /* Configuration Reject */\r
74 #define TERMREQ         5               /* Termination Request */\r
75 #define TERMACK         6               /* Termination Ack */\r
76 #define CODEREJ         7               /* Code Reject */\r
77 \r
78 /*\r
79  * Link states.\r
80  */\r
81 #define INITIAL         0               /* Down, hasn't been opened */\r
82 #define STARTING        1               /* Down, been opened */\r
83 #define CLOSED          2               /* Up, hasn't been opened */\r
84 #define STOPPED         3               /* Open, waiting for down event */\r
85 #define CLOSING         4               /* Terminating the connection, not open */\r
86 #define STOPPING        5               /* Terminating, but open */\r
87 #define REQSENT         6               /* We've sent a Config Request */\r
88 #define ACKRCVD         7               /* We've received a Config Ack */\r
89 #define ACKSENT         8               /* We've sent a Config Ack */\r
90 #define OPENED          9               /* Connection available */\r
91 \r
92 \r
93 /*\r
94  * Flags - indicate options controlling FSM operation\r
95  */\r
96 #define OPT_PASSIVE     1               /* Don't die if we don't get a response */\r
97 #define OPT_RESTART     2               /* Treat 2nd OPEN as DOWN, UP */\r
98 #define OPT_SILENT      4               /* Wait for peer to speak first */\r
99 \r
100 \r
101 /*****************************************************************************\r
102 ************************* PUBLIC DATA TYPES **********************************\r
103 *****************************************************************************/\r
104 /*\r
105  * Each FSM is described by an fsm structure and fsm callbacks.\r
106  */\r
107 typedef struct fsm {\r
108     int unit;                           /* Interface unit number */\r
109     u_short protocol;           /* Data Link Layer Protocol field value */\r
110     int state;                          /* State */\r
111     int flags;                          /* Contains option bits */\r
112     u_char id;                          /* Current id */\r
113     u_char reqid;                       /* Current request id */\r
114     u_char seen_ack;            /* Have received valid Ack/Nak/Rej to Req */\r
115     int timeouttime;            /* Timeout time in milliseconds */\r
116     int maxconfreqtransmits;/* Maximum Configure-Request transmissions */\r
117     int retransmits;            /* Number of retransmissions left */\r
118     int maxtermtransmits;       /* Maximum Terminate-Request transmissions */\r
119     int nakloops;                       /* Number of nak loops since last ack */\r
120     int maxnakloops;            /* Maximum number of nak loops tolerated */\r
121     struct fsm_callbacks* callbacks;/* Callback routines */\r
122     char* term_reason;          /* Reason for closing protocol */\r
123     int term_reason_len;        /* Length of term_reason */\r
124 } fsm;\r
125 \r
126 \r
127 typedef struct fsm_callbacks {\r
128     void (*resetci)                     /* Reset our Configuration Information */\r
129                 (fsm*);\r
130     int  (*cilen)                       /* Length of our Configuration Information */\r
131                 (fsm*);\r
132     void (*addci)                       /* Add our Configuration Information */\r
133                 (fsm*, u_char*, int*);\r
134     int  (*ackci)                       /* ACK our Configuration Information */\r
135                 (fsm*, u_char*, int);\r
136     int  (*nakci)                       /* NAK our Configuration Information */\r
137                 (fsm*, u_char*, int);\r
138     int  (*rejci)                       /* Reject our Configuration Information */\r
139                 (fsm*, u_char*, int);\r
140     int  (*reqci)                       /* Request peer's Configuration Information */\r
141                 (fsm*, u_char*, int*, int);\r
142     void (*up)                          /* Called when fsm reaches OPENED state */\r
143                 (fsm*);\r
144     void (*down)                        /* Called when fsm leaves OPENED state */\r
145                 (fsm*);\r
146     void (*starting)            /* Called when we want the lower layer */\r
147                 (fsm*);\r
148     void (*finished)            /* Called when we don't want the lower layer */\r
149                 (fsm*);\r
150     void (*protreject)          /* Called when Protocol-Reject received */\r
151                 (int);\r
152     void (*retransmit)          /* Retransmission is necessary */\r
153                 (fsm*);\r
154     int  (*extcode)                     /* Called when unknown code received */\r
155                 (fsm*, int, u_char, u_char*, int);\r
156     char *proto_name;           /* String name for protocol (for messages) */\r
157 } fsm_callbacks;\r
158 \r
159 \r
160 /*****************************************************************************\r
161 *********************** PUBLIC DATA STRUCTURES *******************************\r
162 *****************************************************************************/\r
163 /*\r
164  * Variables\r
165  */\r
166 extern int peer_mru[];          /* currently negotiated peer MRU (per unit) */\r
167 \r
168 \r
169 /*****************************************************************************\r
170 ************************** PUBLIC FUNCTIONS **********************************\r
171 *****************************************************************************/\r
172 \r
173 /*\r
174  * Prototypes\r
175  */\r
176 void fsm_init (fsm*);\r
177 void fsm_lowerup (fsm*);\r
178 void fsm_lowerdown (fsm*);\r
179 void fsm_open (fsm*);\r
180 void fsm_close (fsm*, char*);\r
181 void fsm_input (fsm*, u_char*, int);\r
182 void fsm_protreject (fsm*);\r
183 void fsm_sdata (fsm*, u_char, u_char, u_char*, int);\r
184 \r
185 \r
186 #endif /* FSM_H */\r
187 \r