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