http://mbed.org/users/okini3939/notebook/logger/

Dependencies:   mbed

Committer:
okini3939
Date:
Sat Apr 16 15:15:48 2011 +0000
Revision:
0:a3c892f39cc1

        

Who changed what in which revision?

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