hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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