Michael Fischler / Mbed 2 deprecated Contest_Winner

Dependencies:   mbed

Committer:
mafischl
Date:
Thu Oct 13 17:02:29 2011 +0000
Revision:
0:d9266031f832

        

Who changed what in which revision?

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