Demo Application for the Celeritous Breakout Board

Dependencies:   mbed

Committer:
celeritous
Date:
Fri May 18 03:55:10 2012 +0000
Revision:
0:1a3da73fe36a
Celeritous_BreakoutBoardDemo

Who changed what in which revision?

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