Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

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