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