Dependencies:   mbed

Committer:
robertcook
Date:
Wed Jun 13 18:39:46 2012 +0000
Revision:
0:32a0996dff0f

        

Who changed what in which revision?

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