Embedded C project:18/12/2014

Dependencies:   DS1307 TextLCD mbed

Committer:
ninoderkinderen
Date:
Thu Dec 18 09:35:49 2014 +0000
Revision:
0:8d87bc453349
Programma embedded C

Who changed what in which revision?

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