EthernetNetIf

Dependents:   XBee_WiFi_EA_LPC4088

Committer:
hmike
Date:
Wed Nov 19 12:00:42 2014 +0000
Revision:
0:62580107d20c
EthernetNetIf

Who changed what in which revision?

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