Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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