Brandon Fictorie / Mbed 2 deprecated BF_Websocket

Dependencies:   mbed

Committer:
bfictorie
Date:
Sun Mar 25 17:26:30 2012 +0000
Revision:
0:8cdad1c73e8e

        

Who changed what in which revision?

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