1 /* 2 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. 3 * 4 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 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 16 * distribution. 17 * 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 24 * 5000 Forbes Avenue 25 * Pittsburgh, PA 15213-3890 26 * (412) 268-4387, fax: (412) 268-7395 27 * tech-transfer@andrew.cmu.edu 28 * 29 * 4. Redistributions of any form whatsoever must retain the following 30 * acknowledgment: 31 * "This product includes software developed by Computing Services 32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 33 * 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. 41 * 42 * $Id: fsm.h,v 1.10 2004/11/13 02:28:15 paulus Exp $ 43 */ 44 45 #include "netif/ppp/ppp_opts.h" 46 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 47 48 #ifndef FSM_H 49 #define FSM_H 50 51 #include "ppp.h" 52 53 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 57 /* 58 * Packet header = Code, id, length. 59 */ 60 #define HEADERLEN 4 61 62 63 /* 64 * CP (LCP, IPCP, etc.) codes. 65 */ 66 #define CONFREQ 1 /* Configuration Request */ 67 #define CONFACK 2 /* Configuration Ack */ 68 #define CONFNAK 3 /* Configuration Nak */ 69 #define CONFREJ 4 /* Configuration Reject */ 70 #define TERMREQ 5 /* Termination Request */ 71 #define TERMACK 6 /* Termination Ack */ 72 #define CODEREJ 7 /* Code Reject */ 73 74 75 /* 76 * Each FSM is described by an fsm structure and fsm callbacks. 77 */ 78 typedef struct fsm { 79 ppp_pcb *pcb; /* PPP Interface */ 80 const struct fsm_callbacks *callbacks; /* Callback routines */ 81 const char *term_reason; /* Reason for closing protocol */ 82 u8_t seen_ack; /* Have received valid Ack/Nak/Rej to Req */ 83 /* -- This is our only flag, we might use u_int :1 if we have more flags */ 84 u16_t protocol; /* Data Link Layer Protocol field value */ 85 u8_t state; /* State */ 86 u8_t flags; /* Contains option bits */ 87 u8_t id; /* Current id */ 88 u8_t reqid; /* Current request id */ 89 u8_t retransmits; /* Number of retransmissions left */ 90 u8_t nakloops; /* Number of nak loops since last ack */ 91 u8_t rnakloops; /* Number of naks received */ 92 u8_t maxnakloops; /* Maximum number of nak loops tolerated 93 (necessary because IPCP require a custom large max nak loops value) */ 94 u8_t term_reason_len; /* Length of term_reason */ 95 } fsm; 96 97 98 typedef struct fsm_callbacks { 99 void (*resetci) /* Reset our Configuration Information */ 100 (fsm *); 101 int (*cilen) /* Length of our Configuration Information */ 102 (fsm *); 103 void (*addci) /* Add our Configuration Information */ 104 (fsm *, u_char *, int *); 105 int (*ackci) /* ACK our Configuration Information */ 106 (fsm *, u_char *, int); 107 int (*nakci) /* NAK our Configuration Information */ 108 (fsm *, u_char *, int, int); 109 int (*rejci) /* Reject our Configuration Information */ 110 (fsm *, u_char *, int); 111 int (*reqci) /* Request peer's Configuration Information */ 112 (fsm *, u_char *, int *, int); 113 void (*up) /* Called when fsm reaches PPP_FSM_OPENED state */ 114 (fsm *); 115 void (*down) /* Called when fsm leaves PPP_FSM_OPENED state */ 116 (fsm *); 117 void (*starting) /* Called when we want the lower layer */ 118 (fsm *); 119 void (*finished) /* Called when we don't want the lower layer */ 120 (fsm *); 121 void (*protreject) /* Called when Protocol-Reject received */ 122 (int); 123 void (*retransmit) /* Retransmission is necessary */ 124 (fsm *); 125 int (*extcode) /* Called when unknown code received */ 126 (fsm *, int, int, u_char *, int); 127 const char *proto_name; /* String name for protocol (for messages) */ 128 } fsm_callbacks; 129 130 131 /* 132 * Link states. 133 */ 134 #define PPP_FSM_INITIAL 0 /* Down, hasn't been opened */ 135 #define PPP_FSM_STARTING 1 /* Down, been opened */ 136 #define PPP_FSM_CLOSED 2 /* Up, hasn't been opened */ 137 #define PPP_FSM_STOPPED 3 /* Open, waiting for down event */ 138 #define PPP_FSM_CLOSING 4 /* Terminating the connection, not open */ 139 #define PPP_FSM_STOPPING 5 /* Terminating, but open */ 140 #define PPP_FSM_REQSENT 6 /* We've sent a Config Request */ 141 #define PPP_FSM_ACKRCVD 7 /* We've received a Config Ack */ 142 #define PPP_FSM_ACKSENT 8 /* We've sent a Config Ack */ 143 #define PPP_FSM_OPENED 9 /* Connection available */ 144 145 146 /* 147 * Flags - indicate options controlling FSM operation 148 */ 149 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */ 150 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ 151 #define OPT_SILENT 4 /* Wait for peer to speak first */ 152 153 154 /* 155 * Timeouts. 156 */ 157 #if 0 /* moved to ppp_opts.h */ 158 #define DEFTIMEOUT 3 /* Timeout time in seconds */ 159 #define DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ 160 #define DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ 161 #define DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ 162 #endif /* moved to ppp_opts.h */ 163 164 165 /* 166 * Prototypes 167 */ 168 void fsm_init(fsm *f); 169 void fsm_lowerup(fsm *f); 170 void fsm_lowerdown(fsm *f); 171 void fsm_open(fsm *f); 172 void fsm_close(fsm *f, const char *reason); 173 void fsm_input(fsm *f, u_char *inpacket, int l); 174 void fsm_protreject(fsm *f); 175 void fsm_sdata(fsm *f, u_char code, u_char id, const u_char *data, int datalen); 176 177 #ifdef __cplusplus 178 } 179 #endif 180 181 #endif /* FSM_H */ 182 #endif /* PPP_SUPPORT */ 183