Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested

Fork of F7_Ethernet by Dieter Graef

Committer:
TudaPellini
Date:
Sun Aug 20 22:09:22 2017 +0000
Revision:
4:c63cab7b2bda
Parent:
0:d26c1b55cfca
Minor adjustments;

Who changed what in which revision?

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