This library is stripped down version of NetServices library. HTTP server and client function is NOT supported.

Dependents:   imu-daq-eth

Committer:
idinor
Date:
Wed Jul 20 11:45:39 2011 +0000
Revision:
0:dcf3c92487ca

        

Who changed what in which revision?

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