2 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
4 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name "Carnegie Mellon University" must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission. For permission or any legal
21 * details, please contact
22 * Office of Technology Transfer
23 * Carnegie Mellon University
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
29 * 4. Redistributions of any form whatsoever must retain the following
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42 * $Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp $
45 #include "netif/ppp/ppp_opts.h"
46 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
54 * Packet header = Code, id, length.
60 * CP (LCP, IPCP, etc.) codes.
62 #define CONFREQ 1 /* Configuration Request */
63 #define CONFACK 2 /* Configuration Ack */
64 #define CONFNAK 3 /* Configuration Nak */
65 #define CONFREJ 4 /* Configuration Reject */
66 #define TERMREQ 5 /* Termination Request */
67 #define TERMACK 6 /* Termination Ack */
68 #define CODEREJ 7 /* Code Reject */
72 * Each FSM is described by an fsm structure and fsm callbacks.
75 ppp_pcb
*pcb
; /* PPP Interface */
76 const struct fsm_callbacks
*callbacks
; /* Callback routines */
77 const char *term_reason
; /* Reason for closing protocol */
78 u8_t seen_ack
; /* Have received valid Ack/Nak/Rej to Req */
79 /* -- This is our only flag, we might use u_int :1 if we have more flags */
80 u16_t protocol
; /* Data Link Layer Protocol field value */
81 u8_t state
; /* State */
82 u8_t flags
; /* Contains option bits */
83 u8_t id
; /* Current id */
84 u8_t reqid
; /* Current request id */
85 u8_t retransmits
; /* Number of retransmissions left */
86 u8_t nakloops
; /* Number of nak loops since last ack */
87 u8_t rnakloops
; /* Number of naks received */
88 u8_t maxnakloops
; /* Maximum number of nak loops tolerated
89 (necessary because IPCP require a custom large max nak loops value) */
90 u8_t term_reason_len
; /* Length of term_reason */
94 typedef struct fsm_callbacks
{
95 void (*resetci
) /* Reset our Configuration Information */
97 int (*cilen
) /* Length of our Configuration Information */
99 void (*addci
) /* Add our Configuration Information */
100 (fsm
*, u_char
*, int *);
101 int (*ackci
) /* ACK our Configuration Information */
102 (fsm
*, u_char
*, int);
103 int (*nakci
) /* NAK our Configuration Information */
104 (fsm
*, u_char
*, int, int);
105 int (*rejci
) /* Reject our Configuration Information */
106 (fsm
*, u_char
*, int);
107 int (*reqci
) /* Request peer's Configuration Information */
108 (fsm
*, u_char
*, int *, int);
109 void (*up
) /* Called when fsm reaches PPP_FSM_OPENED state */
111 void (*down
) /* Called when fsm leaves PPP_FSM_OPENED state */
113 void (*starting
) /* Called when we want the lower layer */
115 void (*finished
) /* Called when we don't want the lower layer */
117 void (*protreject
) /* Called when Protocol-Reject received */
119 void (*retransmit
) /* Retransmission is necessary */
121 int (*extcode
) /* Called when unknown code received */
122 (fsm
*, int, int, u_char
*, int);
123 const char *proto_name
; /* String name for protocol (for messages) */
130 #define PPP_FSM_INITIAL 0 /* Down, hasn't been opened */
131 #define PPP_FSM_STARTING 1 /* Down, been opened */
132 #define PPP_FSM_CLOSED 2 /* Up, hasn't been opened */
133 #define PPP_FSM_STOPPED 3 /* Open, waiting for down event */
134 #define PPP_FSM_CLOSING 4 /* Terminating the connection, not open */
135 #define PPP_FSM_STOPPING 5 /* Terminating, but open */
136 #define PPP_FSM_REQSENT 6 /* We've sent a Config Request */
137 #define PPP_FSM_ACKRCVD 7 /* We've received a Config Ack */
138 #define PPP_FSM_ACKSENT 8 /* We've sent a Config Ack */
139 #define PPP_FSM_OPENED 9 /* Connection available */
143 * Flags - indicate options controlling FSM operation
145 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
146 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
147 #define OPT_SILENT 4 /* Wait for peer to speak first */
153 #if 0 /* moved to ppp_opts.h */
154 #define DEFTIMEOUT 3 /* Timeout time in seconds */
155 #define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */
156 #define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */
157 #define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */
158 #endif /* moved to ppp_opts.h */
164 void fsm_init(fsm
*f
);
165 void fsm_lowerup(fsm
*f
);
166 void fsm_lowerdown(fsm
*f
);
167 void fsm_open(fsm
*f
);
168 void fsm_close(fsm
*f
, const char *reason
);
169 void fsm_input(fsm
*f
, u_char
*inpacket
, int l
);
170 void fsm_protreject(fsm
*f
);
171 void fsm_sdata(fsm
*f
, u_char code
, u_char id
, const u_char
*data
, int datalen
);
175 #endif /* PPP_SUPPORT */