Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:850eacf3e945 1 /*****************************************************************************
RodColeman 0:850eacf3e945 2 * fsm.c - Network Control Protocol Finite State Machine program file.
RodColeman 0:850eacf3e945 3 *
RodColeman 0:850eacf3e945 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
RodColeman 0:850eacf3e945 5 * portions Copyright (c) 1997 by Global Election Systems Inc.
RodColeman 0:850eacf3e945 6 *
RodColeman 0:850eacf3e945 7 * The authors hereby grant permission to use, copy, modify, distribute,
RodColeman 0:850eacf3e945 8 * and license this software and its documentation for any purpose, provided
RodColeman 0:850eacf3e945 9 * that existing copyright notices are retained in all copies and that this
RodColeman 0:850eacf3e945 10 * notice and the following disclaimer are included verbatim in any
RodColeman 0:850eacf3e945 11 * distributions. No written agreement, license, or royalty fee is required
RodColeman 0:850eacf3e945 12 * for any of the authorized uses.
RodColeman 0:850eacf3e945 13 *
RodColeman 0:850eacf3e945 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
RodColeman 0:850eacf3e945 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
RodColeman 0:850eacf3e945 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
RodColeman 0:850eacf3e945 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
RodColeman 0:850eacf3e945 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
RodColeman 0:850eacf3e945 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
RodColeman 0:850eacf3e945 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
RodColeman 0:850eacf3e945 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
RodColeman 0:850eacf3e945 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
RodColeman 0:850eacf3e945 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RodColeman 0:850eacf3e945 24 *
RodColeman 0:850eacf3e945 25 ******************************************************************************
RodColeman 0:850eacf3e945 26 * REVISION HISTORY
RodColeman 0:850eacf3e945 27 *
RodColeman 0:850eacf3e945 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
RodColeman 0:850eacf3e945 29 * Ported to lwIP.
RodColeman 0:850eacf3e945 30 * 97-12-01 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
RodColeman 0:850eacf3e945 31 * Original based on BSD fsm.c.
RodColeman 0:850eacf3e945 32 *****************************************************************************/
RodColeman 0:850eacf3e945 33 /*
RodColeman 0:850eacf3e945 34 * fsm.c - {Link, IP} Control Protocol Finite State Machine.
RodColeman 0:850eacf3e945 35 *
RodColeman 0:850eacf3e945 36 * Copyright (c) 1989 Carnegie Mellon University.
RodColeman 0:850eacf3e945 37 * All rights reserved.
RodColeman 0:850eacf3e945 38 *
RodColeman 0:850eacf3e945 39 * Redistribution and use in source and binary forms are permitted
RodColeman 0:850eacf3e945 40 * provided that the above copyright notice and this paragraph are
RodColeman 0:850eacf3e945 41 * duplicated in all such forms and that any documentation,
RodColeman 0:850eacf3e945 42 * advertising materials, and other materials related to such
RodColeman 0:850eacf3e945 43 * distribution and use acknowledge that the software was developed
RodColeman 0:850eacf3e945 44 * by Carnegie Mellon University. The name of the
RodColeman 0:850eacf3e945 45 * University may not be used to endorse or promote products derived
RodColeman 0:850eacf3e945 46 * from this software without specific prior written permission.
RodColeman 0:850eacf3e945 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
RodColeman 0:850eacf3e945 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
RodColeman 0:850eacf3e945 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
RodColeman 0:850eacf3e945 50 */
RodColeman 0:850eacf3e945 51
RodColeman 0:850eacf3e945 52 /*
RodColeman 0:850eacf3e945 53 * TODO:
RodColeman 0:850eacf3e945 54 * Randomize fsm id on link/init.
RodColeman 0:850eacf3e945 55 * Deal with variable outgoing MTU.
RodColeman 0:850eacf3e945 56 */
RodColeman 0:850eacf3e945 57
RodColeman 0:850eacf3e945 58 #include "lwip/opt.h"
RodColeman 0:850eacf3e945 59
RodColeman 0:850eacf3e945 60 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
RodColeman 0:850eacf3e945 61
RodColeman 0:850eacf3e945 62 #include "ppp.h"
RodColeman 0:850eacf3e945 63 #include "pppdebug.h"
RodColeman 0:850eacf3e945 64
RodColeman 0:850eacf3e945 65 #include "fsm.h"
RodColeman 0:850eacf3e945 66
RodColeman 0:850eacf3e945 67 #include <string.h>
RodColeman 0:850eacf3e945 68
RodColeman 0:850eacf3e945 69 #if PPP_DEBUG
RodColeman 0:850eacf3e945 70 static const char *ppperr_strerr[] = {
RodColeman 0:850eacf3e945 71 "LS_INITIAL", /* LS_INITIAL 0 */
RodColeman 0:850eacf3e945 72 "LS_STARTING", /* LS_STARTING 1 */
RodColeman 0:850eacf3e945 73 "LS_CLOSED", /* LS_CLOSED 2 */
RodColeman 0:850eacf3e945 74 "LS_STOPPED", /* LS_STOPPED 3 */
RodColeman 0:850eacf3e945 75 "LS_CLOSING", /* LS_CLOSING 4 */
RodColeman 0:850eacf3e945 76 "LS_STOPPING", /* LS_STOPPING 5 */
RodColeman 0:850eacf3e945 77 "LS_REQSENT", /* LS_REQSENT 6 */
RodColeman 0:850eacf3e945 78 "LS_ACKRCVD", /* LS_ACKRCVD 7 */
RodColeman 0:850eacf3e945 79 "LS_ACKSENT", /* LS_ACKSENT 8 */
RodColeman 0:850eacf3e945 80 "LS_OPENED" /* LS_OPENED 9 */
RodColeman 0:850eacf3e945 81 };
RodColeman 0:850eacf3e945 82 #endif /* PPP_DEBUG */
RodColeman 0:850eacf3e945 83
RodColeman 0:850eacf3e945 84 static void fsm_timeout (void *);
RodColeman 0:850eacf3e945 85 static void fsm_rconfreq (fsm *, u_char, u_char *, int);
RodColeman 0:850eacf3e945 86 static void fsm_rconfack (fsm *, int, u_char *, int);
RodColeman 0:850eacf3e945 87 static void fsm_rconfnakrej (fsm *, int, int, u_char *, int);
RodColeman 0:850eacf3e945 88 static void fsm_rtermreq (fsm *, int, u_char *, int);
RodColeman 0:850eacf3e945 89 static void fsm_rtermack (fsm *);
RodColeman 0:850eacf3e945 90 static void fsm_rcoderej (fsm *, u_char *, int);
RodColeman 0:850eacf3e945 91 static void fsm_sconfreq (fsm *, int);
RodColeman 0:850eacf3e945 92
RodColeman 0:850eacf3e945 93 #define PROTO_NAME(f) ((f)->callbacks->proto_name)
RodColeman 0:850eacf3e945 94
RodColeman 0:850eacf3e945 95 int peer_mru[NUM_PPP];
RodColeman 0:850eacf3e945 96
RodColeman 0:850eacf3e945 97
RodColeman 0:850eacf3e945 98 /*
RodColeman 0:850eacf3e945 99 * fsm_init - Initialize fsm.
RodColeman 0:850eacf3e945 100 *
RodColeman 0:850eacf3e945 101 * Initialize fsm state.
RodColeman 0:850eacf3e945 102 */
RodColeman 0:850eacf3e945 103 void
RodColeman 0:850eacf3e945 104 fsm_init(fsm *f)
RodColeman 0:850eacf3e945 105 {
RodColeman 0:850eacf3e945 106 f->state = LS_INITIAL;
RodColeman 0:850eacf3e945 107 f->flags = 0;
RodColeman 0:850eacf3e945 108 f->id = 0; /* XXX Start with random id? */
RodColeman 0:850eacf3e945 109 f->timeouttime = FSM_DEFTIMEOUT;
RodColeman 0:850eacf3e945 110 f->maxconfreqtransmits = FSM_DEFMAXCONFREQS;
RodColeman 0:850eacf3e945 111 f->maxtermtransmits = FSM_DEFMAXTERMREQS;
RodColeman 0:850eacf3e945 112 f->maxnakloops = FSM_DEFMAXNAKLOOPS;
RodColeman 0:850eacf3e945 113 f->term_reason_len = 0;
RodColeman 0:850eacf3e945 114 }
RodColeman 0:850eacf3e945 115
RodColeman 0:850eacf3e945 116
RodColeman 0:850eacf3e945 117 /*
RodColeman 0:850eacf3e945 118 * fsm_lowerup - The lower layer is up.
RodColeman 0:850eacf3e945 119 */
RodColeman 0:850eacf3e945 120 void
RodColeman 0:850eacf3e945 121 fsm_lowerup(fsm *f)
RodColeman 0:850eacf3e945 122 {
RodColeman 0:850eacf3e945 123 int oldState = f->state;
RodColeman 0:850eacf3e945 124
RodColeman 0:850eacf3e945 125 LWIP_UNUSED_ARG(oldState);
RodColeman 0:850eacf3e945 126
RodColeman 0:850eacf3e945 127 switch( f->state ) {
RodColeman 0:850eacf3e945 128 case LS_INITIAL:
RodColeman 0:850eacf3e945 129 f->state = LS_CLOSED;
RodColeman 0:850eacf3e945 130 break;
RodColeman 0:850eacf3e945 131
RodColeman 0:850eacf3e945 132 case LS_STARTING:
RodColeman 0:850eacf3e945 133 if( f->flags & OPT_SILENT ) {
RodColeman 0:850eacf3e945 134 f->state = LS_STOPPED;
RodColeman 0:850eacf3e945 135 } else {
RodColeman 0:850eacf3e945 136 /* Send an initial configure-request */
RodColeman 0:850eacf3e945 137 fsm_sconfreq(f, 0);
RodColeman 0:850eacf3e945 138 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 139 }
RodColeman 0:850eacf3e945 140 break;
RodColeman 0:850eacf3e945 141
RodColeman 0:850eacf3e945 142 default:
RodColeman 0:850eacf3e945 143 FSMDEBUG(LOG_INFO, ("%s: Up event in state %d (%s)!\n",
RodColeman 0:850eacf3e945 144 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 145 }
RodColeman 0:850eacf3e945 146
RodColeman 0:850eacf3e945 147 FSMDEBUG(LOG_INFO, ("%s: lowerup state %d (%s) -> %d (%s)\n",
RodColeman 0:850eacf3e945 148 PROTO_NAME(f), oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 149 }
RodColeman 0:850eacf3e945 150
RodColeman 0:850eacf3e945 151
RodColeman 0:850eacf3e945 152 /*
RodColeman 0:850eacf3e945 153 * fsm_lowerdown - The lower layer is down.
RodColeman 0:850eacf3e945 154 *
RodColeman 0:850eacf3e945 155 * Cancel all timeouts and inform upper layers.
RodColeman 0:850eacf3e945 156 */
RodColeman 0:850eacf3e945 157 void
RodColeman 0:850eacf3e945 158 fsm_lowerdown(fsm *f)
RodColeman 0:850eacf3e945 159 {
RodColeman 0:850eacf3e945 160 int oldState = f->state;
RodColeman 0:850eacf3e945 161
RodColeman 0:850eacf3e945 162 LWIP_UNUSED_ARG(oldState);
RodColeman 0:850eacf3e945 163
RodColeman 0:850eacf3e945 164 switch( f->state ) {
RodColeman 0:850eacf3e945 165 case LS_CLOSED:
RodColeman 0:850eacf3e945 166 f->state = LS_INITIAL;
RodColeman 0:850eacf3e945 167 break;
RodColeman 0:850eacf3e945 168
RodColeman 0:850eacf3e945 169 case LS_STOPPED:
RodColeman 0:850eacf3e945 170 f->state = LS_STARTING;
RodColeman 0:850eacf3e945 171 if( f->callbacks->starting ) {
RodColeman 0:850eacf3e945 172 (*f->callbacks->starting)(f);
RodColeman 0:850eacf3e945 173 }
RodColeman 0:850eacf3e945 174 break;
RodColeman 0:850eacf3e945 175
RodColeman 0:850eacf3e945 176 case LS_CLOSING:
RodColeman 0:850eacf3e945 177 f->state = LS_INITIAL;
RodColeman 0:850eacf3e945 178 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 179 break;
RodColeman 0:850eacf3e945 180
RodColeman 0:850eacf3e945 181 case LS_STOPPING:
RodColeman 0:850eacf3e945 182 case LS_REQSENT:
RodColeman 0:850eacf3e945 183 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 184 case LS_ACKSENT:
RodColeman 0:850eacf3e945 185 f->state = LS_STARTING;
RodColeman 0:850eacf3e945 186 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 187 break;
RodColeman 0:850eacf3e945 188
RodColeman 0:850eacf3e945 189 case LS_OPENED:
RodColeman 0:850eacf3e945 190 if( f->callbacks->down ) {
RodColeman 0:850eacf3e945 191 (*f->callbacks->down)(f);
RodColeman 0:850eacf3e945 192 }
RodColeman 0:850eacf3e945 193 f->state = LS_STARTING;
RodColeman 0:850eacf3e945 194 break;
RodColeman 0:850eacf3e945 195
RodColeman 0:850eacf3e945 196 default:
RodColeman 0:850eacf3e945 197 FSMDEBUG(LOG_INFO, ("%s: Down event in state %d (%s)!\n",
RodColeman 0:850eacf3e945 198 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 199 }
RodColeman 0:850eacf3e945 200
RodColeman 0:850eacf3e945 201 FSMDEBUG(LOG_INFO, ("%s: lowerdown state %d (%s) -> %d (%s)\n",
RodColeman 0:850eacf3e945 202 PROTO_NAME(f), oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 203 }
RodColeman 0:850eacf3e945 204
RodColeman 0:850eacf3e945 205
RodColeman 0:850eacf3e945 206 /*
RodColeman 0:850eacf3e945 207 * fsm_open - Link is allowed to come up.
RodColeman 0:850eacf3e945 208 */
RodColeman 0:850eacf3e945 209 void
RodColeman 0:850eacf3e945 210 fsm_open(fsm *f)
RodColeman 0:850eacf3e945 211 {
RodColeman 0:850eacf3e945 212 int oldState = f->state;
RodColeman 0:850eacf3e945 213
RodColeman 0:850eacf3e945 214 LWIP_UNUSED_ARG(oldState);
RodColeman 0:850eacf3e945 215
RodColeman 0:850eacf3e945 216 switch( f->state ) {
RodColeman 0:850eacf3e945 217 case LS_INITIAL:
RodColeman 0:850eacf3e945 218 f->state = LS_STARTING;
RodColeman 0:850eacf3e945 219 if( f->callbacks->starting ) {
RodColeman 0:850eacf3e945 220 (*f->callbacks->starting)(f);
RodColeman 0:850eacf3e945 221 }
RodColeman 0:850eacf3e945 222 break;
RodColeman 0:850eacf3e945 223
RodColeman 0:850eacf3e945 224 case LS_CLOSED:
RodColeman 0:850eacf3e945 225 if( f->flags & OPT_SILENT ) {
RodColeman 0:850eacf3e945 226 f->state = LS_STOPPED;
RodColeman 0:850eacf3e945 227 } else {
RodColeman 0:850eacf3e945 228 /* Send an initial configure-request */
RodColeman 0:850eacf3e945 229 fsm_sconfreq(f, 0);
RodColeman 0:850eacf3e945 230 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 231 }
RodColeman 0:850eacf3e945 232 break;
RodColeman 0:850eacf3e945 233
RodColeman 0:850eacf3e945 234 case LS_CLOSING:
RodColeman 0:850eacf3e945 235 f->state = LS_STOPPING;
RodColeman 0:850eacf3e945 236 /* fall through */
RodColeman 0:850eacf3e945 237 case LS_STOPPED:
RodColeman 0:850eacf3e945 238 case LS_OPENED:
RodColeman 0:850eacf3e945 239 if( f->flags & OPT_RESTART ) {
RodColeman 0:850eacf3e945 240 fsm_lowerdown(f);
RodColeman 0:850eacf3e945 241 fsm_lowerup(f);
RodColeman 0:850eacf3e945 242 }
RodColeman 0:850eacf3e945 243 break;
RodColeman 0:850eacf3e945 244 }
RodColeman 0:850eacf3e945 245
RodColeman 0:850eacf3e945 246 FSMDEBUG(LOG_INFO, ("%s: open state %d (%s) -> %d (%s)\n",
RodColeman 0:850eacf3e945 247 PROTO_NAME(f), oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 248 }
RodColeman 0:850eacf3e945 249
RodColeman 0:850eacf3e945 250 #if 0 /* backport pppd 2.4.4b1; */
RodColeman 0:850eacf3e945 251 /*
RodColeman 0:850eacf3e945 252 * terminate_layer - Start process of shutting down the FSM
RodColeman 0:850eacf3e945 253 *
RodColeman 0:850eacf3e945 254 * Cancel any timeout running, notify upper layers we're done, and
RodColeman 0:850eacf3e945 255 * send a terminate-request message as configured.
RodColeman 0:850eacf3e945 256 */
RodColeman 0:850eacf3e945 257 static void
RodColeman 0:850eacf3e945 258 terminate_layer(fsm *f, int nextstate)
RodColeman 0:850eacf3e945 259 {
RodColeman 0:850eacf3e945 260 /* @todo */
RodColeman 0:850eacf3e945 261 }
RodColeman 0:850eacf3e945 262 #endif
RodColeman 0:850eacf3e945 263
RodColeman 0:850eacf3e945 264 /*
RodColeman 0:850eacf3e945 265 * fsm_close - Start closing connection.
RodColeman 0:850eacf3e945 266 *
RodColeman 0:850eacf3e945 267 * Cancel timeouts and either initiate close or possibly go directly to
RodColeman 0:850eacf3e945 268 * the LS_CLOSED state.
RodColeman 0:850eacf3e945 269 */
RodColeman 0:850eacf3e945 270 void
RodColeman 0:850eacf3e945 271 fsm_close(fsm *f, char *reason)
RodColeman 0:850eacf3e945 272 {
RodColeman 0:850eacf3e945 273 int oldState = f->state;
RodColeman 0:850eacf3e945 274
RodColeman 0:850eacf3e945 275 LWIP_UNUSED_ARG(oldState);
RodColeman 0:850eacf3e945 276
RodColeman 0:850eacf3e945 277 f->term_reason = reason;
RodColeman 0:850eacf3e945 278 f->term_reason_len = (reason == NULL ? 0 : (int)strlen(reason));
RodColeman 0:850eacf3e945 279 switch( f->state ) {
RodColeman 0:850eacf3e945 280 case LS_STARTING:
RodColeman 0:850eacf3e945 281 f->state = LS_INITIAL;
RodColeman 0:850eacf3e945 282 break;
RodColeman 0:850eacf3e945 283 case LS_STOPPED:
RodColeman 0:850eacf3e945 284 f->state = LS_CLOSED;
RodColeman 0:850eacf3e945 285 break;
RodColeman 0:850eacf3e945 286 case LS_STOPPING:
RodColeman 0:850eacf3e945 287 f->state = LS_CLOSING;
RodColeman 0:850eacf3e945 288 break;
RodColeman 0:850eacf3e945 289
RodColeman 0:850eacf3e945 290 case LS_REQSENT:
RodColeman 0:850eacf3e945 291 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 292 case LS_ACKSENT:
RodColeman 0:850eacf3e945 293 case LS_OPENED:
RodColeman 0:850eacf3e945 294 if( f->state != LS_OPENED ) {
RodColeman 0:850eacf3e945 295 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 296 } else if( f->callbacks->down ) {
RodColeman 0:850eacf3e945 297 (*f->callbacks->down)(f); /* Inform upper layers we're down */
RodColeman 0:850eacf3e945 298 }
RodColeman 0:850eacf3e945 299 /* Init restart counter, send Terminate-Request */
RodColeman 0:850eacf3e945 300 f->retransmits = f->maxtermtransmits;
RodColeman 0:850eacf3e945 301 fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
RodColeman 0:850eacf3e945 302 (u_char *) f->term_reason, f->term_reason_len);
RodColeman 0:850eacf3e945 303 TIMEOUT(fsm_timeout, f, f->timeouttime);
RodColeman 0:850eacf3e945 304 --f->retransmits;
RodColeman 0:850eacf3e945 305
RodColeman 0:850eacf3e945 306 f->state = LS_CLOSING;
RodColeman 0:850eacf3e945 307 break;
RodColeman 0:850eacf3e945 308 }
RodColeman 0:850eacf3e945 309
RodColeman 0:850eacf3e945 310 FSMDEBUG(LOG_INFO, ("%s: close reason=%s state %d (%s) -> %d (%s)\n",
RodColeman 0:850eacf3e945 311 PROTO_NAME(f), reason, oldState, ppperr_strerr[oldState], f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 312 }
RodColeman 0:850eacf3e945 313
RodColeman 0:850eacf3e945 314
RodColeman 0:850eacf3e945 315 /*
RodColeman 0:850eacf3e945 316 * fsm_timeout - Timeout expired.
RodColeman 0:850eacf3e945 317 */
RodColeman 0:850eacf3e945 318 static void
RodColeman 0:850eacf3e945 319 fsm_timeout(void *arg)
RodColeman 0:850eacf3e945 320 {
RodColeman 0:850eacf3e945 321 fsm *f = (fsm *) arg;
RodColeman 0:850eacf3e945 322
RodColeman 0:850eacf3e945 323 switch (f->state) {
RodColeman 0:850eacf3e945 324 case LS_CLOSING:
RodColeman 0:850eacf3e945 325 case LS_STOPPING:
RodColeman 0:850eacf3e945 326 if( f->retransmits <= 0 ) {
RodColeman 0:850eacf3e945 327 FSMDEBUG(LOG_WARNING, ("%s: timeout sending Terminate-Request state=%d (%s)\n",
RodColeman 0:850eacf3e945 328 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 329 /*
RodColeman 0:850eacf3e945 330 * We've waited for an ack long enough. Peer probably heard us.
RodColeman 0:850eacf3e945 331 */
RodColeman 0:850eacf3e945 332 f->state = (f->state == LS_CLOSING)? LS_CLOSED: LS_STOPPED;
RodColeman 0:850eacf3e945 333 if( f->callbacks->finished ) {
RodColeman 0:850eacf3e945 334 (*f->callbacks->finished)(f);
RodColeman 0:850eacf3e945 335 }
RodColeman 0:850eacf3e945 336 } else {
RodColeman 0:850eacf3e945 337 FSMDEBUG(LOG_WARNING, ("%s: timeout resending Terminate-Requests state=%d (%s)\n",
RodColeman 0:850eacf3e945 338 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 339 /* Send Terminate-Request */
RodColeman 0:850eacf3e945 340 fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
RodColeman 0:850eacf3e945 341 (u_char *) f->term_reason, f->term_reason_len);
RodColeman 0:850eacf3e945 342 TIMEOUT(fsm_timeout, f, f->timeouttime);
RodColeman 0:850eacf3e945 343 --f->retransmits;
RodColeman 0:850eacf3e945 344 }
RodColeman 0:850eacf3e945 345 break;
RodColeman 0:850eacf3e945 346
RodColeman 0:850eacf3e945 347 case LS_REQSENT:
RodColeman 0:850eacf3e945 348 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 349 case LS_ACKSENT:
RodColeman 0:850eacf3e945 350 if (f->retransmits <= 0) {
RodColeman 0:850eacf3e945 351 FSMDEBUG(LOG_WARNING, ("%s: timeout sending Config-Requests state=%d (%s)\n",
RodColeman 0:850eacf3e945 352 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 353 f->state = LS_STOPPED;
RodColeman 0:850eacf3e945 354 if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished ) {
RodColeman 0:850eacf3e945 355 (*f->callbacks->finished)(f);
RodColeman 0:850eacf3e945 356 }
RodColeman 0:850eacf3e945 357 } else {
RodColeman 0:850eacf3e945 358 FSMDEBUG(LOG_WARNING, ("%s: timeout resending Config-Request state=%d (%s)\n",
RodColeman 0:850eacf3e945 359 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 360 /* Retransmit the configure-request */
RodColeman 0:850eacf3e945 361 if (f->callbacks->retransmit) {
RodColeman 0:850eacf3e945 362 (*f->callbacks->retransmit)(f);
RodColeman 0:850eacf3e945 363 }
RodColeman 0:850eacf3e945 364 fsm_sconfreq(f, 1); /* Re-send Configure-Request */
RodColeman 0:850eacf3e945 365 if( f->state == LS_ACKRCVD ) {
RodColeman 0:850eacf3e945 366 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 367 }
RodColeman 0:850eacf3e945 368 }
RodColeman 0:850eacf3e945 369 break;
RodColeman 0:850eacf3e945 370
RodColeman 0:850eacf3e945 371 default:
RodColeman 0:850eacf3e945 372 FSMDEBUG(LOG_INFO, ("%s: UNHANDLED timeout event in state %d (%s)!\n",
RodColeman 0:850eacf3e945 373 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 374 }
RodColeman 0:850eacf3e945 375 }
RodColeman 0:850eacf3e945 376
RodColeman 0:850eacf3e945 377
RodColeman 0:850eacf3e945 378 /*
RodColeman 0:850eacf3e945 379 * fsm_input - Input packet.
RodColeman 0:850eacf3e945 380 */
RodColeman 0:850eacf3e945 381 void
RodColeman 0:850eacf3e945 382 fsm_input(fsm *f, u_char *inpacket, int l)
RodColeman 0:850eacf3e945 383 {
RodColeman 0:850eacf3e945 384 u_char *inp = inpacket;
RodColeman 0:850eacf3e945 385 u_char code, id;
RodColeman 0:850eacf3e945 386 int len;
RodColeman 0:850eacf3e945 387
RodColeman 0:850eacf3e945 388 /*
RodColeman 0:850eacf3e945 389 * Parse header (code, id and length).
RodColeman 0:850eacf3e945 390 * If packet too short, drop it.
RodColeman 0:850eacf3e945 391 */
RodColeman 0:850eacf3e945 392 if (l < HEADERLEN) {
RodColeman 0:850eacf3e945 393 FSMDEBUG(LOG_WARNING, ("fsm_input(%x): Rcvd short header.\n",
RodColeman 0:850eacf3e945 394 f->protocol));
RodColeman 0:850eacf3e945 395 return;
RodColeman 0:850eacf3e945 396 }
RodColeman 0:850eacf3e945 397 GETCHAR(code, inp);
RodColeman 0:850eacf3e945 398 GETCHAR(id, inp);
RodColeman 0:850eacf3e945 399 GETSHORT(len, inp);
RodColeman 0:850eacf3e945 400 if (len < HEADERLEN) {
RodColeman 0:850eacf3e945 401 FSMDEBUG(LOG_INFO, ("fsm_input(%x): Rcvd illegal length.\n",
RodColeman 0:850eacf3e945 402 f->protocol));
RodColeman 0:850eacf3e945 403 return;
RodColeman 0:850eacf3e945 404 }
RodColeman 0:850eacf3e945 405 if (len > l) {
RodColeman 0:850eacf3e945 406 FSMDEBUG(LOG_INFO, ("fsm_input(%x): Rcvd short packet.\n",
RodColeman 0:850eacf3e945 407 f->protocol));
RodColeman 0:850eacf3e945 408 return;
RodColeman 0:850eacf3e945 409 }
RodColeman 0:850eacf3e945 410 len -= HEADERLEN; /* subtract header length */
RodColeman 0:850eacf3e945 411
RodColeman 0:850eacf3e945 412 if( f->state == LS_INITIAL || f->state == LS_STARTING ) {
RodColeman 0:850eacf3e945 413 FSMDEBUG(LOG_INFO, ("fsm_input(%x): Rcvd packet in state %d (%s).\n",
RodColeman 0:850eacf3e945 414 f->protocol, f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 415 return;
RodColeman 0:850eacf3e945 416 }
RodColeman 0:850eacf3e945 417 FSMDEBUG(LOG_INFO, ("fsm_input(%s):%d,%d,%d\n", PROTO_NAME(f), code, id, l));
RodColeman 0:850eacf3e945 418 /*
RodColeman 0:850eacf3e945 419 * Action depends on code.
RodColeman 0:850eacf3e945 420 */
RodColeman 0:850eacf3e945 421 switch (code) {
RodColeman 0:850eacf3e945 422 case CONFREQ:
RodColeman 0:850eacf3e945 423 fsm_rconfreq(f, id, inp, len);
RodColeman 0:850eacf3e945 424 break;
RodColeman 0:850eacf3e945 425
RodColeman 0:850eacf3e945 426 case CONFACK:
RodColeman 0:850eacf3e945 427 fsm_rconfack(f, id, inp, len);
RodColeman 0:850eacf3e945 428 break;
RodColeman 0:850eacf3e945 429
RodColeman 0:850eacf3e945 430 case CONFNAK:
RodColeman 0:850eacf3e945 431 case CONFREJ:
RodColeman 0:850eacf3e945 432 fsm_rconfnakrej(f, code, id, inp, len);
RodColeman 0:850eacf3e945 433 break;
RodColeman 0:850eacf3e945 434
RodColeman 0:850eacf3e945 435 case TERMREQ:
RodColeman 0:850eacf3e945 436 fsm_rtermreq(f, id, inp, len);
RodColeman 0:850eacf3e945 437 break;
RodColeman 0:850eacf3e945 438
RodColeman 0:850eacf3e945 439 case TERMACK:
RodColeman 0:850eacf3e945 440 fsm_rtermack(f);
RodColeman 0:850eacf3e945 441 break;
RodColeman 0:850eacf3e945 442
RodColeman 0:850eacf3e945 443 case CODEREJ:
RodColeman 0:850eacf3e945 444 fsm_rcoderej(f, inp, len);
RodColeman 0:850eacf3e945 445 break;
RodColeman 0:850eacf3e945 446
RodColeman 0:850eacf3e945 447 default:
RodColeman 0:850eacf3e945 448 FSMDEBUG(LOG_INFO, ("fsm_input(%s): default: \n", PROTO_NAME(f)));
RodColeman 0:850eacf3e945 449 if( !f->callbacks->extcode ||
RodColeman 0:850eacf3e945 450 !(*f->callbacks->extcode)(f, code, id, inp, len) ) {
RodColeman 0:850eacf3e945 451 fsm_sdata(f, CODEREJ, ++f->id, inpacket, len + HEADERLEN);
RodColeman 0:850eacf3e945 452 }
RodColeman 0:850eacf3e945 453 break;
RodColeman 0:850eacf3e945 454 }
RodColeman 0:850eacf3e945 455 }
RodColeman 0:850eacf3e945 456
RodColeman 0:850eacf3e945 457
RodColeman 0:850eacf3e945 458 /*
RodColeman 0:850eacf3e945 459 * fsm_rconfreq - Receive Configure-Request.
RodColeman 0:850eacf3e945 460 */
RodColeman 0:850eacf3e945 461 static void
RodColeman 0:850eacf3e945 462 fsm_rconfreq(fsm *f, u_char id, u_char *inp, int len)
RodColeman 0:850eacf3e945 463 {
RodColeman 0:850eacf3e945 464 int code, reject_if_disagree;
RodColeman 0:850eacf3e945 465
RodColeman 0:850eacf3e945 466 FSMDEBUG(LOG_INFO, ("fsm_rconfreq(%s): Rcvd id %d state=%d (%s)\n",
RodColeman 0:850eacf3e945 467 PROTO_NAME(f), id, f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 468 switch( f->state ) {
RodColeman 0:850eacf3e945 469 case LS_CLOSED:
RodColeman 0:850eacf3e945 470 /* Go away, we're closed */
RodColeman 0:850eacf3e945 471 fsm_sdata(f, TERMACK, id, NULL, 0);
RodColeman 0:850eacf3e945 472 return;
RodColeman 0:850eacf3e945 473 case LS_CLOSING:
RodColeman 0:850eacf3e945 474 case LS_STOPPING:
RodColeman 0:850eacf3e945 475 return;
RodColeman 0:850eacf3e945 476
RodColeman 0:850eacf3e945 477 case LS_OPENED:
RodColeman 0:850eacf3e945 478 /* Go down and restart negotiation */
RodColeman 0:850eacf3e945 479 if( f->callbacks->down ) {
RodColeman 0:850eacf3e945 480 (*f->callbacks->down)(f); /* Inform upper layers */
RodColeman 0:850eacf3e945 481 }
RodColeman 0:850eacf3e945 482 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
RodColeman 0:850eacf3e945 483 break;
RodColeman 0:850eacf3e945 484
RodColeman 0:850eacf3e945 485 case LS_STOPPED:
RodColeman 0:850eacf3e945 486 /* Negotiation started by our peer */
RodColeman 0:850eacf3e945 487 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
RodColeman 0:850eacf3e945 488 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 489 break;
RodColeman 0:850eacf3e945 490 }
RodColeman 0:850eacf3e945 491
RodColeman 0:850eacf3e945 492 /*
RodColeman 0:850eacf3e945 493 * Pass the requested configuration options
RodColeman 0:850eacf3e945 494 * to protocol-specific code for checking.
RodColeman 0:850eacf3e945 495 */
RodColeman 0:850eacf3e945 496 if (f->callbacks->reqci) { /* Check CI */
RodColeman 0:850eacf3e945 497 reject_if_disagree = (f->nakloops >= f->maxnakloops);
RodColeman 0:850eacf3e945 498 code = (*f->callbacks->reqci)(f, inp, &len, reject_if_disagree);
RodColeman 0:850eacf3e945 499 } else if (len) {
RodColeman 0:850eacf3e945 500 code = CONFREJ; /* Reject all CI */
RodColeman 0:850eacf3e945 501 } else {
RodColeman 0:850eacf3e945 502 code = CONFACK;
RodColeman 0:850eacf3e945 503 }
RodColeman 0:850eacf3e945 504
RodColeman 0:850eacf3e945 505 /* send the Ack, Nak or Rej to the peer */
RodColeman 0:850eacf3e945 506 fsm_sdata(f, (u_char)code, id, inp, len);
RodColeman 0:850eacf3e945 507
RodColeman 0:850eacf3e945 508 if (code == CONFACK) {
RodColeman 0:850eacf3e945 509 if (f->state == LS_ACKRCVD) {
RodColeman 0:850eacf3e945 510 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 511 f->state = LS_OPENED;
RodColeman 0:850eacf3e945 512 if (f->callbacks->up) {
RodColeman 0:850eacf3e945 513 (*f->callbacks->up)(f); /* Inform upper layers */
RodColeman 0:850eacf3e945 514 }
RodColeman 0:850eacf3e945 515 } else {
RodColeman 0:850eacf3e945 516 f->state = LS_ACKSENT;
RodColeman 0:850eacf3e945 517 }
RodColeman 0:850eacf3e945 518 f->nakloops = 0;
RodColeman 0:850eacf3e945 519 } else {
RodColeman 0:850eacf3e945 520 /* we sent CONFACK or CONFREJ */
RodColeman 0:850eacf3e945 521 if (f->state != LS_ACKRCVD) {
RodColeman 0:850eacf3e945 522 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 523 }
RodColeman 0:850eacf3e945 524 if( code == CONFNAK ) {
RodColeman 0:850eacf3e945 525 ++f->nakloops;
RodColeman 0:850eacf3e945 526 }
RodColeman 0:850eacf3e945 527 }
RodColeman 0:850eacf3e945 528 }
RodColeman 0:850eacf3e945 529
RodColeman 0:850eacf3e945 530
RodColeman 0:850eacf3e945 531 /*
RodColeman 0:850eacf3e945 532 * fsm_rconfack - Receive Configure-Ack.
RodColeman 0:850eacf3e945 533 */
RodColeman 0:850eacf3e945 534 static void
RodColeman 0:850eacf3e945 535 fsm_rconfack(fsm *f, int id, u_char *inp, int len)
RodColeman 0:850eacf3e945 536 {
RodColeman 0:850eacf3e945 537 FSMDEBUG(LOG_INFO, ("fsm_rconfack(%s): Rcvd id %d state=%d (%s)\n",
RodColeman 0:850eacf3e945 538 PROTO_NAME(f), id, f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 539
RodColeman 0:850eacf3e945 540 if (id != f->reqid || f->seen_ack) { /* Expected id? */
RodColeman 0:850eacf3e945 541 return; /* Nope, toss... */
RodColeman 0:850eacf3e945 542 }
RodColeman 0:850eacf3e945 543 if( !(f->callbacks->ackci? (*f->callbacks->ackci)(f, inp, len): (len == 0)) ) {
RodColeman 0:850eacf3e945 544 /* Ack is bad - ignore it */
RodColeman 0:850eacf3e945 545 FSMDEBUG(LOG_INFO, ("%s: received bad Ack (length %d)\n",
RodColeman 0:850eacf3e945 546 PROTO_NAME(f), len));
RodColeman 0:850eacf3e945 547 return;
RodColeman 0:850eacf3e945 548 }
RodColeman 0:850eacf3e945 549 f->seen_ack = 1;
RodColeman 0:850eacf3e945 550
RodColeman 0:850eacf3e945 551 switch (f->state) {
RodColeman 0:850eacf3e945 552 case LS_CLOSED:
RodColeman 0:850eacf3e945 553 case LS_STOPPED:
RodColeman 0:850eacf3e945 554 fsm_sdata(f, TERMACK, (u_char)id, NULL, 0);
RodColeman 0:850eacf3e945 555 break;
RodColeman 0:850eacf3e945 556
RodColeman 0:850eacf3e945 557 case LS_REQSENT:
RodColeman 0:850eacf3e945 558 f->state = LS_ACKRCVD;
RodColeman 0:850eacf3e945 559 f->retransmits = f->maxconfreqtransmits;
RodColeman 0:850eacf3e945 560 break;
RodColeman 0:850eacf3e945 561
RodColeman 0:850eacf3e945 562 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 563 /* Huh? an extra valid Ack? oh well... */
RodColeman 0:850eacf3e945 564 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 565 fsm_sconfreq(f, 0);
RodColeman 0:850eacf3e945 566 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 567 break;
RodColeman 0:850eacf3e945 568
RodColeman 0:850eacf3e945 569 case LS_ACKSENT:
RodColeman 0:850eacf3e945 570 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 571 f->state = LS_OPENED;
RodColeman 0:850eacf3e945 572 f->retransmits = f->maxconfreqtransmits;
RodColeman 0:850eacf3e945 573 if (f->callbacks->up) {
RodColeman 0:850eacf3e945 574 (*f->callbacks->up)(f); /* Inform upper layers */
RodColeman 0:850eacf3e945 575 }
RodColeman 0:850eacf3e945 576 break;
RodColeman 0:850eacf3e945 577
RodColeman 0:850eacf3e945 578 case LS_OPENED:
RodColeman 0:850eacf3e945 579 /* Go down and restart negotiation */
RodColeman 0:850eacf3e945 580 if (f->callbacks->down) {
RodColeman 0:850eacf3e945 581 (*f->callbacks->down)(f); /* Inform upper layers */
RodColeman 0:850eacf3e945 582 }
RodColeman 0:850eacf3e945 583 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
RodColeman 0:850eacf3e945 584 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 585 break;
RodColeman 0:850eacf3e945 586 }
RodColeman 0:850eacf3e945 587 }
RodColeman 0:850eacf3e945 588
RodColeman 0:850eacf3e945 589
RodColeman 0:850eacf3e945 590 /*
RodColeman 0:850eacf3e945 591 * fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
RodColeman 0:850eacf3e945 592 */
RodColeman 0:850eacf3e945 593 static void
RodColeman 0:850eacf3e945 594 fsm_rconfnakrej(fsm *f, int code, int id, u_char *inp, int len)
RodColeman 0:850eacf3e945 595 {
RodColeman 0:850eacf3e945 596 int (*proc) (fsm *, u_char *, int);
RodColeman 0:850eacf3e945 597 int ret;
RodColeman 0:850eacf3e945 598
RodColeman 0:850eacf3e945 599 FSMDEBUG(LOG_INFO, ("fsm_rconfnakrej(%s): Rcvd id %d state=%d (%s)\n",
RodColeman 0:850eacf3e945 600 PROTO_NAME(f), id, f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 601
RodColeman 0:850eacf3e945 602 if (id != f->reqid || f->seen_ack) { /* Expected id? */
RodColeman 0:850eacf3e945 603 return; /* Nope, toss... */
RodColeman 0:850eacf3e945 604 }
RodColeman 0:850eacf3e945 605 proc = (code == CONFNAK)? f->callbacks->nakci: f->callbacks->rejci;
RodColeman 0:850eacf3e945 606 if (!proc || !((ret = proc(f, inp, len)))) {
RodColeman 0:850eacf3e945 607 /* Nak/reject is bad - ignore it */
RodColeman 0:850eacf3e945 608 FSMDEBUG(LOG_INFO, ("%s: received bad %s (length %d)\n",
RodColeman 0:850eacf3e945 609 PROTO_NAME(f), (code==CONFNAK? "Nak": "reject"), len));
RodColeman 0:850eacf3e945 610 return;
RodColeman 0:850eacf3e945 611 }
RodColeman 0:850eacf3e945 612 f->seen_ack = 1;
RodColeman 0:850eacf3e945 613
RodColeman 0:850eacf3e945 614 switch (f->state) {
RodColeman 0:850eacf3e945 615 case LS_CLOSED:
RodColeman 0:850eacf3e945 616 case LS_STOPPED:
RodColeman 0:850eacf3e945 617 fsm_sdata(f, TERMACK, (u_char)id, NULL, 0);
RodColeman 0:850eacf3e945 618 break;
RodColeman 0:850eacf3e945 619
RodColeman 0:850eacf3e945 620 case LS_REQSENT:
RodColeman 0:850eacf3e945 621 case LS_ACKSENT:
RodColeman 0:850eacf3e945 622 /* They didn't agree to what we wanted - try another request */
RodColeman 0:850eacf3e945 623 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 624 if (ret < 0) {
RodColeman 0:850eacf3e945 625 f->state = LS_STOPPED; /* kludge for stopping CCP */
RodColeman 0:850eacf3e945 626 } else {
RodColeman 0:850eacf3e945 627 fsm_sconfreq(f, 0); /* Send Configure-Request */
RodColeman 0:850eacf3e945 628 }
RodColeman 0:850eacf3e945 629 break;
RodColeman 0:850eacf3e945 630
RodColeman 0:850eacf3e945 631 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 632 /* Got a Nak/reject when we had already had an Ack?? oh well... */
RodColeman 0:850eacf3e945 633 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 634 fsm_sconfreq(f, 0);
RodColeman 0:850eacf3e945 635 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 636 break;
RodColeman 0:850eacf3e945 637
RodColeman 0:850eacf3e945 638 case LS_OPENED:
RodColeman 0:850eacf3e945 639 /* Go down and restart negotiation */
RodColeman 0:850eacf3e945 640 if (f->callbacks->down) {
RodColeman 0:850eacf3e945 641 (*f->callbacks->down)(f); /* Inform upper layers */
RodColeman 0:850eacf3e945 642 }
RodColeman 0:850eacf3e945 643 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
RodColeman 0:850eacf3e945 644 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 645 break;
RodColeman 0:850eacf3e945 646 }
RodColeman 0:850eacf3e945 647 }
RodColeman 0:850eacf3e945 648
RodColeman 0:850eacf3e945 649
RodColeman 0:850eacf3e945 650 /*
RodColeman 0:850eacf3e945 651 * fsm_rtermreq - Receive Terminate-Req.
RodColeman 0:850eacf3e945 652 */
RodColeman 0:850eacf3e945 653 static void
RodColeman 0:850eacf3e945 654 fsm_rtermreq(fsm *f, int id, u_char *p, int len)
RodColeman 0:850eacf3e945 655 {
RodColeman 0:850eacf3e945 656 LWIP_UNUSED_ARG(p);
RodColeman 0:850eacf3e945 657
RodColeman 0:850eacf3e945 658 FSMDEBUG(LOG_INFO, ("fsm_rtermreq(%s): Rcvd id %d state=%d (%s)\n",
RodColeman 0:850eacf3e945 659 PROTO_NAME(f), id, f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 660
RodColeman 0:850eacf3e945 661 switch (f->state) {
RodColeman 0:850eacf3e945 662 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 663 case LS_ACKSENT:
RodColeman 0:850eacf3e945 664 f->state = LS_REQSENT; /* Start over but keep trying */
RodColeman 0:850eacf3e945 665 break;
RodColeman 0:850eacf3e945 666
RodColeman 0:850eacf3e945 667 case LS_OPENED:
RodColeman 0:850eacf3e945 668 if (len > 0) {
RodColeman 0:850eacf3e945 669 FSMDEBUG(LOG_INFO, ("%s terminated by peer (%p)\n", PROTO_NAME(f), p));
RodColeman 0:850eacf3e945 670 } else {
RodColeman 0:850eacf3e945 671 FSMDEBUG(LOG_INFO, ("%s terminated by peer\n", PROTO_NAME(f)));
RodColeman 0:850eacf3e945 672 }
RodColeman 0:850eacf3e945 673 if (f->callbacks->down) {
RodColeman 0:850eacf3e945 674 (*f->callbacks->down)(f); /* Inform upper layers */
RodColeman 0:850eacf3e945 675 }
RodColeman 0:850eacf3e945 676 f->retransmits = 0;
RodColeman 0:850eacf3e945 677 f->state = LS_STOPPING;
RodColeman 0:850eacf3e945 678 TIMEOUT(fsm_timeout, f, f->timeouttime);
RodColeman 0:850eacf3e945 679 break;
RodColeman 0:850eacf3e945 680 }
RodColeman 0:850eacf3e945 681
RodColeman 0:850eacf3e945 682 fsm_sdata(f, TERMACK, (u_char)id, NULL, 0);
RodColeman 0:850eacf3e945 683 }
RodColeman 0:850eacf3e945 684
RodColeman 0:850eacf3e945 685
RodColeman 0:850eacf3e945 686 /*
RodColeman 0:850eacf3e945 687 * fsm_rtermack - Receive Terminate-Ack.
RodColeman 0:850eacf3e945 688 */
RodColeman 0:850eacf3e945 689 static void
RodColeman 0:850eacf3e945 690 fsm_rtermack(fsm *f)
RodColeman 0:850eacf3e945 691 {
RodColeman 0:850eacf3e945 692 FSMDEBUG(LOG_INFO, ("fsm_rtermack(%s): state=%d (%s)\n",
RodColeman 0:850eacf3e945 693 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 694
RodColeman 0:850eacf3e945 695 switch (f->state) {
RodColeman 0:850eacf3e945 696 case LS_CLOSING:
RodColeman 0:850eacf3e945 697 UNTIMEOUT(fsm_timeout, f);
RodColeman 0:850eacf3e945 698 f->state = LS_CLOSED;
RodColeman 0:850eacf3e945 699 if( f->callbacks->finished ) {
RodColeman 0:850eacf3e945 700 (*f->callbacks->finished)(f);
RodColeman 0:850eacf3e945 701 }
RodColeman 0:850eacf3e945 702 break;
RodColeman 0:850eacf3e945 703
RodColeman 0:850eacf3e945 704 case LS_STOPPING:
RodColeman 0:850eacf3e945 705 UNTIMEOUT(fsm_timeout, f);
RodColeman 0:850eacf3e945 706 f->state = LS_STOPPED;
RodColeman 0:850eacf3e945 707 if( f->callbacks->finished ) {
RodColeman 0:850eacf3e945 708 (*f->callbacks->finished)(f);
RodColeman 0:850eacf3e945 709 }
RodColeman 0:850eacf3e945 710 break;
RodColeman 0:850eacf3e945 711
RodColeman 0:850eacf3e945 712 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 713 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 714 break;
RodColeman 0:850eacf3e945 715
RodColeman 0:850eacf3e945 716 case LS_OPENED:
RodColeman 0:850eacf3e945 717 if (f->callbacks->down) {
RodColeman 0:850eacf3e945 718 (*f->callbacks->down)(f); /* Inform upper layers */
RodColeman 0:850eacf3e945 719 }
RodColeman 0:850eacf3e945 720 fsm_sconfreq(f, 0);
RodColeman 0:850eacf3e945 721 break;
RodColeman 0:850eacf3e945 722 default:
RodColeman 0:850eacf3e945 723 FSMDEBUG(LOG_INFO, ("fsm_rtermack(%s): UNHANDLED state=%d (%s)!!!\n",
RodColeman 0:850eacf3e945 724 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 725 }
RodColeman 0:850eacf3e945 726 }
RodColeman 0:850eacf3e945 727
RodColeman 0:850eacf3e945 728
RodColeman 0:850eacf3e945 729 /*
RodColeman 0:850eacf3e945 730 * fsm_rcoderej - Receive an Code-Reject.
RodColeman 0:850eacf3e945 731 */
RodColeman 0:850eacf3e945 732 static void
RodColeman 0:850eacf3e945 733 fsm_rcoderej(fsm *f, u_char *inp, int len)
RodColeman 0:850eacf3e945 734 {
RodColeman 0:850eacf3e945 735 u_char code, id;
RodColeman 0:850eacf3e945 736
RodColeman 0:850eacf3e945 737 FSMDEBUG(LOG_INFO, ("fsm_rcoderej(%s): state=%d (%s)\n",
RodColeman 0:850eacf3e945 738 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 739
RodColeman 0:850eacf3e945 740 if (len < HEADERLEN) {
RodColeman 0:850eacf3e945 741 FSMDEBUG(LOG_INFO, ("fsm_rcoderej: Rcvd short Code-Reject packet!\n"));
RodColeman 0:850eacf3e945 742 return;
RodColeman 0:850eacf3e945 743 }
RodColeman 0:850eacf3e945 744 GETCHAR(code, inp);
RodColeman 0:850eacf3e945 745 GETCHAR(id, inp);
RodColeman 0:850eacf3e945 746 FSMDEBUG(LOG_WARNING, ("%s: Rcvd Code-Reject for code %d, id %d\n",
RodColeman 0:850eacf3e945 747 PROTO_NAME(f), code, id));
RodColeman 0:850eacf3e945 748
RodColeman 0:850eacf3e945 749 if( f->state == LS_ACKRCVD ) {
RodColeman 0:850eacf3e945 750 f->state = LS_REQSENT;
RodColeman 0:850eacf3e945 751 }
RodColeman 0:850eacf3e945 752 }
RodColeman 0:850eacf3e945 753
RodColeman 0:850eacf3e945 754
RodColeman 0:850eacf3e945 755 /*
RodColeman 0:850eacf3e945 756 * fsm_protreject - Peer doesn't speak this protocol.
RodColeman 0:850eacf3e945 757 *
RodColeman 0:850eacf3e945 758 * Treat this as a catastrophic error (RXJ-).
RodColeman 0:850eacf3e945 759 */
RodColeman 0:850eacf3e945 760 void
RodColeman 0:850eacf3e945 761 fsm_protreject(fsm *f)
RodColeman 0:850eacf3e945 762 {
RodColeman 0:850eacf3e945 763 switch( f->state ) {
RodColeman 0:850eacf3e945 764 case LS_CLOSING:
RodColeman 0:850eacf3e945 765 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 766 /* fall through */
RodColeman 0:850eacf3e945 767 case LS_CLOSED:
RodColeman 0:850eacf3e945 768 f->state = LS_CLOSED;
RodColeman 0:850eacf3e945 769 if( f->callbacks->finished ) {
RodColeman 0:850eacf3e945 770 (*f->callbacks->finished)(f);
RodColeman 0:850eacf3e945 771 }
RodColeman 0:850eacf3e945 772 break;
RodColeman 0:850eacf3e945 773
RodColeman 0:850eacf3e945 774 case LS_STOPPING:
RodColeman 0:850eacf3e945 775 case LS_REQSENT:
RodColeman 0:850eacf3e945 776 case LS_ACKRCVD:
RodColeman 0:850eacf3e945 777 case LS_ACKSENT:
RodColeman 0:850eacf3e945 778 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
RodColeman 0:850eacf3e945 779 /* fall through */
RodColeman 0:850eacf3e945 780 case LS_STOPPED:
RodColeman 0:850eacf3e945 781 f->state = LS_STOPPED;
RodColeman 0:850eacf3e945 782 if( f->callbacks->finished ) {
RodColeman 0:850eacf3e945 783 (*f->callbacks->finished)(f);
RodColeman 0:850eacf3e945 784 }
RodColeman 0:850eacf3e945 785 break;
RodColeman 0:850eacf3e945 786
RodColeman 0:850eacf3e945 787 case LS_OPENED:
RodColeman 0:850eacf3e945 788 if( f->callbacks->down ) {
RodColeman 0:850eacf3e945 789 (*f->callbacks->down)(f);
RodColeman 0:850eacf3e945 790 }
RodColeman 0:850eacf3e945 791 /* Init restart counter, send Terminate-Request */
RodColeman 0:850eacf3e945 792 f->retransmits = f->maxtermtransmits;
RodColeman 0:850eacf3e945 793 fsm_sdata(f, TERMREQ, f->reqid = ++f->id,
RodColeman 0:850eacf3e945 794 (u_char *) f->term_reason, f->term_reason_len);
RodColeman 0:850eacf3e945 795 TIMEOUT(fsm_timeout, f, f->timeouttime);
RodColeman 0:850eacf3e945 796 --f->retransmits;
RodColeman 0:850eacf3e945 797
RodColeman 0:850eacf3e945 798 f->state = LS_STOPPING;
RodColeman 0:850eacf3e945 799 break;
RodColeman 0:850eacf3e945 800
RodColeman 0:850eacf3e945 801 default:
RodColeman 0:850eacf3e945 802 FSMDEBUG(LOG_INFO, ("%s: Protocol-reject event in state %d (%s)!\n",
RodColeman 0:850eacf3e945 803 PROTO_NAME(f), f->state, ppperr_strerr[f->state]));
RodColeman 0:850eacf3e945 804 }
RodColeman 0:850eacf3e945 805 }
RodColeman 0:850eacf3e945 806
RodColeman 0:850eacf3e945 807
RodColeman 0:850eacf3e945 808 /*
RodColeman 0:850eacf3e945 809 * fsm_sconfreq - Send a Configure-Request.
RodColeman 0:850eacf3e945 810 */
RodColeman 0:850eacf3e945 811 static void
RodColeman 0:850eacf3e945 812 fsm_sconfreq(fsm *f, int retransmit)
RodColeman 0:850eacf3e945 813 {
RodColeman 0:850eacf3e945 814 u_char *outp;
RodColeman 0:850eacf3e945 815 int cilen;
RodColeman 0:850eacf3e945 816
RodColeman 0:850eacf3e945 817 if( f->state != LS_REQSENT && f->state != LS_ACKRCVD && f->state != LS_ACKSENT ) {
RodColeman 0:850eacf3e945 818 /* Not currently negotiating - reset options */
RodColeman 0:850eacf3e945 819 if( f->callbacks->resetci ) {
RodColeman 0:850eacf3e945 820 (*f->callbacks->resetci)(f);
RodColeman 0:850eacf3e945 821 }
RodColeman 0:850eacf3e945 822 f->nakloops = 0;
RodColeman 0:850eacf3e945 823 }
RodColeman 0:850eacf3e945 824
RodColeman 0:850eacf3e945 825 if( !retransmit ) {
RodColeman 0:850eacf3e945 826 /* New request - reset retransmission counter, use new ID */
RodColeman 0:850eacf3e945 827 f->retransmits = f->maxconfreqtransmits;
RodColeman 0:850eacf3e945 828 f->reqid = ++f->id;
RodColeman 0:850eacf3e945 829 }
RodColeman 0:850eacf3e945 830
RodColeman 0:850eacf3e945 831 f->seen_ack = 0;
RodColeman 0:850eacf3e945 832
RodColeman 0:850eacf3e945 833 /*
RodColeman 0:850eacf3e945 834 * Make up the request packet
RodColeman 0:850eacf3e945 835 */
RodColeman 0:850eacf3e945 836 outp = outpacket_buf[f->unit] + PPP_HDRLEN + HEADERLEN;
RodColeman 0:850eacf3e945 837 if( f->callbacks->cilen && f->callbacks->addci ) {
RodColeman 0:850eacf3e945 838 cilen = (*f->callbacks->cilen)(f);
RodColeman 0:850eacf3e945 839 if( cilen > peer_mru[f->unit] - (int)HEADERLEN ) {
RodColeman 0:850eacf3e945 840 cilen = peer_mru[f->unit] - HEADERLEN;
RodColeman 0:850eacf3e945 841 }
RodColeman 0:850eacf3e945 842 if (f->callbacks->addci) {
RodColeman 0:850eacf3e945 843 (*f->callbacks->addci)(f, outp, &cilen);
RodColeman 0:850eacf3e945 844 }
RodColeman 0:850eacf3e945 845 } else {
RodColeman 0:850eacf3e945 846 cilen = 0;
RodColeman 0:850eacf3e945 847 }
RodColeman 0:850eacf3e945 848
RodColeman 0:850eacf3e945 849 /* send the request to our peer */
RodColeman 0:850eacf3e945 850 fsm_sdata(f, CONFREQ, f->reqid, outp, cilen);
RodColeman 0:850eacf3e945 851
RodColeman 0:850eacf3e945 852 /* start the retransmit timer */
RodColeman 0:850eacf3e945 853 --f->retransmits;
RodColeman 0:850eacf3e945 854 TIMEOUT(fsm_timeout, f, f->timeouttime);
RodColeman 0:850eacf3e945 855
RodColeman 0:850eacf3e945 856 FSMDEBUG(LOG_INFO, ("%s: sending Configure-Request, id %d\n",
RodColeman 0:850eacf3e945 857 PROTO_NAME(f), f->reqid));
RodColeman 0:850eacf3e945 858 }
RodColeman 0:850eacf3e945 859
RodColeman 0:850eacf3e945 860
RodColeman 0:850eacf3e945 861 /*
RodColeman 0:850eacf3e945 862 * fsm_sdata - Send some data.
RodColeman 0:850eacf3e945 863 *
RodColeman 0:850eacf3e945 864 * Used for all packets sent to our peer by this module.
RodColeman 0:850eacf3e945 865 */
RodColeman 0:850eacf3e945 866 void
RodColeman 0:850eacf3e945 867 fsm_sdata( fsm *f, u_char code, u_char id, u_char *data, int datalen)
RodColeman 0:850eacf3e945 868 {
RodColeman 0:850eacf3e945 869 u_char *outp;
RodColeman 0:850eacf3e945 870 int outlen;
RodColeman 0:850eacf3e945 871
RodColeman 0:850eacf3e945 872 /* Adjust length to be smaller than MTU */
RodColeman 0:850eacf3e945 873 outp = outpacket_buf[f->unit];
RodColeman 0:850eacf3e945 874 if (datalen > peer_mru[f->unit] - (int)HEADERLEN) {
RodColeman 0:850eacf3e945 875 datalen = peer_mru[f->unit] - HEADERLEN;
RodColeman 0:850eacf3e945 876 }
RodColeman 0:850eacf3e945 877 if (datalen && data != outp + PPP_HDRLEN + HEADERLEN) {
RodColeman 0:850eacf3e945 878 BCOPY(data, outp + PPP_HDRLEN + HEADERLEN, datalen);
RodColeman 0:850eacf3e945 879 }
RodColeman 0:850eacf3e945 880 outlen = datalen + HEADERLEN;
RodColeman 0:850eacf3e945 881 MAKEHEADER(outp, f->protocol);
RodColeman 0:850eacf3e945 882 PUTCHAR(code, outp);
RodColeman 0:850eacf3e945 883 PUTCHAR(id, outp);
RodColeman 0:850eacf3e945 884 PUTSHORT(outlen, outp);
RodColeman 0:850eacf3e945 885 pppWrite(f->unit, outpacket_buf[f->unit], outlen + PPP_HDRLEN);
RodColeman 0:850eacf3e945 886 FSMDEBUG(LOG_INFO, ("fsm_sdata(%s): Sent code %d,%d,%d.\n",
RodColeman 0:850eacf3e945 887 PROTO_NAME(f), code, id, outlen));
RodColeman 0:850eacf3e945 888 }
RodColeman 0:850eacf3e945 889
RodColeman 0:850eacf3e945 890 #endif /* PPP_SUPPORT */