Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Committer:
dcoban
Date:
Tue Apr 03 18:43:13 2012 +0000
Revision:
0:1a61c61d0845

        

Who changed what in which revision?

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