Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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