Committer:
donatien
Date:
Fri Aug 06 10:42:05 2010 +0000
Revision:
3:e02ec42cf9c8
Parent:
0:0f5a52711275

        

Who changed what in which revision?

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