testing of combination of LCS and LAN

Dependencies:   mbed

Committer:
damir
Date:
Wed Jan 14 13:29:55 2015 +0000
Revision:
0:a7a6a692162f
Test of LAN

Who changed what in which revision?

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