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

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

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