Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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