Committer:
zoot661
Date:
Tue May 29 09:49:18 2012 +0000
Revision:
0:f993b6d8b1d8

        

Who changed what in which revision?

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