Library for Bert van Dam's book "ARM MICROCONTROLLERS" For all chapters with internet.

Dependencies:   mbed

Committer:
ICTFBI
Date:
Fri Oct 16 14:28:26 2015 +0000
Revision:
0:4edb816d21e1
Pre-update 16-10-15

Who changed what in which revision?

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