Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

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