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