fdsf

Dependents:   sisk_proj_stat MQTT Hello_FXOS8700Q WireFSHandControl ... more

Committer:
grzemich
Date:
Wed Dec 07 23:47:50 2016 +0000
Revision:
0:d7bd7384a37c
dgd

Who changed what in which revision?

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