Version of http://mbed.org/cookbook/NetServicesTribute with setting set the same for LPC2368

Dependents:   UDPSocketExample 24LCxx_I2CApp WeatherPlatform_pachube HvZServerLib ... more

Committer:
simon
Date:
Tue Nov 23 14:15:36 2010 +0000
Revision:
0:350011bf8be7
Experimental version for testing UDP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:350011bf8be7 1 /*****************************************************************************
simon 0:350011bf8be7 2 * lcp.c - Network Link Control Protocol program file.
simon 0:350011bf8be7 3 *
simon 0:350011bf8be7 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
simon 0:350011bf8be7 5 * portions Copyright (c) 1997 by Global Election Systems Inc.
simon 0:350011bf8be7 6 *
simon 0:350011bf8be7 7 * The authors hereby grant permission to use, copy, modify, distribute,
simon 0:350011bf8be7 8 * and license this software and its documentation for any purpose, provided
simon 0:350011bf8be7 9 * that existing copyright notices are retained in all copies and that this
simon 0:350011bf8be7 10 * notice and the following disclaimer are included verbatim in any
simon 0:350011bf8be7 11 * distributions. No written agreement, license, or royalty fee is required
simon 0:350011bf8be7 12 * for any of the authorized uses.
simon 0:350011bf8be7 13 *
simon 0:350011bf8be7 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
simon 0:350011bf8be7 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
simon 0:350011bf8be7 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
simon 0:350011bf8be7 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
simon 0:350011bf8be7 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
simon 0:350011bf8be7 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
simon 0:350011bf8be7 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
simon 0:350011bf8be7 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
simon 0:350011bf8be7 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
simon 0:350011bf8be7 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
simon 0:350011bf8be7 24 *
simon 0:350011bf8be7 25 ******************************************************************************
simon 0:350011bf8be7 26 * REVISION HISTORY
simon 0:350011bf8be7 27 *
simon 0:350011bf8be7 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
simon 0:350011bf8be7 29 * Ported to lwIP.
simon 0:350011bf8be7 30 * 97-12-01 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
simon 0:350011bf8be7 31 * Original.
simon 0:350011bf8be7 32 *****************************************************************************/
simon 0:350011bf8be7 33
simon 0:350011bf8be7 34 /*
simon 0:350011bf8be7 35 * lcp.c - PPP Link Control Protocol.
simon 0:350011bf8be7 36 *
simon 0:350011bf8be7 37 * Copyright (c) 1989 Carnegie Mellon University.
simon 0:350011bf8be7 38 * All rights reserved.
simon 0:350011bf8be7 39 *
simon 0:350011bf8be7 40 * Redistribution and use in source and binary forms are permitted
simon 0:350011bf8be7 41 * provided that the above copyright notice and this paragraph are
simon 0:350011bf8be7 42 * duplicated in all such forms and that any documentation,
simon 0:350011bf8be7 43 * advertising materials, and other materials related to such
simon 0:350011bf8be7 44 * distribution and use acknowledge that the software was developed
simon 0:350011bf8be7 45 * by Carnegie Mellon University. The name of the
simon 0:350011bf8be7 46 * University may not be used to endorse or promote products derived
simon 0:350011bf8be7 47 * from this software without specific prior written permission.
simon 0:350011bf8be7 48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
simon 0:350011bf8be7 49 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
simon 0:350011bf8be7 50 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
simon 0:350011bf8be7 51 */
simon 0:350011bf8be7 52
simon 0:350011bf8be7 53
simon 0:350011bf8be7 54 #include "lwip/opt.h"
simon 0:350011bf8be7 55
simon 0:350011bf8be7 56 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
simon 0:350011bf8be7 57
simon 0:350011bf8be7 58 #include "ppp.h"
simon 0:350011bf8be7 59 #include "pppdebug.h"
simon 0:350011bf8be7 60
simon 0:350011bf8be7 61 #include "fsm.h"
simon 0:350011bf8be7 62 #include "chap.h"
simon 0:350011bf8be7 63 #include "magic.h"
simon 0:350011bf8be7 64 #include "auth.h"
simon 0:350011bf8be7 65 #include "lcp.h"
simon 0:350011bf8be7 66
simon 0:350011bf8be7 67 #include <string.h>
simon 0:350011bf8be7 68
simon 0:350011bf8be7 69 #if PPPOE_SUPPORT
simon 0:350011bf8be7 70 #include "netif/ppp_oe.h"
simon 0:350011bf8be7 71 #else
simon 0:350011bf8be7 72 #define PPPOE_MAXMTU PPP_MAXMRU
simon 0:350011bf8be7 73 #endif
simon 0:350011bf8be7 74
simon 0:350011bf8be7 75 #if 0 /* UNUSED */
simon 0:350011bf8be7 76 /*
simon 0:350011bf8be7 77 * LCP-related command-line options.
simon 0:350011bf8be7 78 */
simon 0:350011bf8be7 79 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
simon 0:350011bf8be7 80 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
simon 0:350011bf8be7 81 bool lax_recv = 0; /* accept control chars in asyncmap */
simon 0:350011bf8be7 82
simon 0:350011bf8be7 83 static int setescape (char **);
simon 0:350011bf8be7 84
simon 0:350011bf8be7 85 static option_t lcp_option_list[] = {
simon 0:350011bf8be7 86 /* LCP options */
simon 0:350011bf8be7 87 /* list stripped for simplicity */
simon 0:350011bf8be7 88 {NULL}
simon 0:350011bf8be7 89 };
simon 0:350011bf8be7 90 #endif /* UNUSED */
simon 0:350011bf8be7 91
simon 0:350011bf8be7 92 /* options */
simon 0:350011bf8be7 93 LinkPhase lcp_phase[NUM_PPP]; /* Phase of link session (RFC 1661) */
simon 0:350011bf8be7 94 static u_int lcp_echo_interval = LCP_ECHOINTERVAL; /* Interval between LCP echo-requests */
simon 0:350011bf8be7 95 static u_int lcp_echo_fails = LCP_MAXECHOFAILS; /* Tolerance to unanswered echo-requests */
simon 0:350011bf8be7 96
simon 0:350011bf8be7 97 /* global vars */
simon 0:350011bf8be7 98 static fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
simon 0:350011bf8be7 99 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
simon 0:350011bf8be7 100 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
simon 0:350011bf8be7 101 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
simon 0:350011bf8be7 102 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
simon 0:350011bf8be7 103 ext_accm xmit_accm[NUM_PPP]; /* extended transmit ACCM */
simon 0:350011bf8be7 104
simon 0:350011bf8be7 105 static u32_t lcp_echos_pending = 0; /* Number of outstanding echo msgs */
simon 0:350011bf8be7 106 static u32_t lcp_echo_number = 0; /* ID number of next echo frame */
simon 0:350011bf8be7 107 static u32_t lcp_echo_timer_running = 0; /* TRUE if a timer is running */
simon 0:350011bf8be7 108
simon 0:350011bf8be7 109 /* @todo: do we really need such a large buffer? The typical 1500 bytes seem too much. */
simon 0:350011bf8be7 110 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
simon 0:350011bf8be7 111
simon 0:350011bf8be7 112 /*
simon 0:350011bf8be7 113 * Callbacks for fsm code. (CI = Configuration Information)
simon 0:350011bf8be7 114 */
simon 0:350011bf8be7 115 static void lcp_resetci (fsm*); /* Reset our CI */
simon 0:350011bf8be7 116 static int lcp_cilen (fsm*); /* Return length of our CI */
simon 0:350011bf8be7 117 static void lcp_addci (fsm*, u_char*, int*); /* Add our CI to pkt */
simon 0:350011bf8be7 118 static int lcp_ackci (fsm*, u_char*, int); /* Peer ack'd our CI */
simon 0:350011bf8be7 119 static int lcp_nakci (fsm*, u_char*, int); /* Peer nak'd our CI */
simon 0:350011bf8be7 120 static int lcp_rejci (fsm*, u_char*, int); /* Peer rej'd our CI */
simon 0:350011bf8be7 121 static int lcp_reqci (fsm*, u_char*, int*, int); /* Rcv peer CI */
simon 0:350011bf8be7 122 static void lcp_up (fsm*); /* We're UP */
simon 0:350011bf8be7 123 static void lcp_down (fsm*); /* We're DOWN */
simon 0:350011bf8be7 124 static void lcp_starting (fsm*); /* We need lower layer up */
simon 0:350011bf8be7 125 static void lcp_finished (fsm*); /* We need lower layer down */
simon 0:350011bf8be7 126 static int lcp_extcode (fsm*, int, u_char, u_char*, int);
simon 0:350011bf8be7 127 static void lcp_rprotrej (fsm*, u_char*, int);
simon 0:350011bf8be7 128
simon 0:350011bf8be7 129 /*
simon 0:350011bf8be7 130 * routines to send LCP echos to peer
simon 0:350011bf8be7 131 */
simon 0:350011bf8be7 132
simon 0:350011bf8be7 133 static void lcp_echo_lowerup (int);
simon 0:350011bf8be7 134 static void lcp_echo_lowerdown (int);
simon 0:350011bf8be7 135 static void LcpEchoTimeout (void*);
simon 0:350011bf8be7 136 static void lcp_received_echo_reply (fsm*, int, u_char*, int);
simon 0:350011bf8be7 137 static void LcpSendEchoRequest (fsm*);
simon 0:350011bf8be7 138 static void LcpLinkFailure (fsm*);
simon 0:350011bf8be7 139 static void LcpEchoCheck (fsm*);
simon 0:350011bf8be7 140
simon 0:350011bf8be7 141 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
simon 0:350011bf8be7 142 lcp_resetci, /* Reset our Configuration Information */
simon 0:350011bf8be7 143 lcp_cilen, /* Length of our Configuration Information */
simon 0:350011bf8be7 144 lcp_addci, /* Add our Configuration Information */
simon 0:350011bf8be7 145 lcp_ackci, /* ACK our Configuration Information */
simon 0:350011bf8be7 146 lcp_nakci, /* NAK our Configuration Information */
simon 0:350011bf8be7 147 lcp_rejci, /* Reject our Configuration Information */
simon 0:350011bf8be7 148 lcp_reqci, /* Request peer's Configuration Information */
simon 0:350011bf8be7 149 lcp_up, /* Called when fsm reaches LS_OPENED state */
simon 0:350011bf8be7 150 lcp_down, /* Called when fsm leaves LS_OPENED state */
simon 0:350011bf8be7 151 lcp_starting, /* Called when we want the lower layer up */
simon 0:350011bf8be7 152 lcp_finished, /* Called when we want the lower layer down */
simon 0:350011bf8be7 153 NULL, /* Called when Protocol-Reject received */
simon 0:350011bf8be7 154 NULL, /* Retransmission is necessary */
simon 0:350011bf8be7 155 lcp_extcode, /* Called to handle LCP-specific codes */
simon 0:350011bf8be7 156 "LCP" /* String name of protocol */
simon 0:350011bf8be7 157 };
simon 0:350011bf8be7 158
simon 0:350011bf8be7 159 /*
simon 0:350011bf8be7 160 * Protocol entry points.
simon 0:350011bf8be7 161 * Some of these are called directly.
simon 0:350011bf8be7 162 */
simon 0:350011bf8be7 163
simon 0:350011bf8be7 164 static void lcp_input (int, u_char *, int);
simon 0:350011bf8be7 165 static void lcp_protrej (int);
simon 0:350011bf8be7 166
simon 0:350011bf8be7 167 struct protent lcp_protent = {
simon 0:350011bf8be7 168 PPP_LCP,
simon 0:350011bf8be7 169 lcp_init,
simon 0:350011bf8be7 170 lcp_input,
simon 0:350011bf8be7 171 lcp_protrej,
simon 0:350011bf8be7 172 lcp_lowerup,
simon 0:350011bf8be7 173 lcp_lowerdown,
simon 0:350011bf8be7 174 lcp_open,
simon 0:350011bf8be7 175 lcp_close,
simon 0:350011bf8be7 176 #if PPP_ADDITIONAL_CALLBACKS
simon 0:350011bf8be7 177 lcp_printpkt,
simon 0:350011bf8be7 178 NULL,
simon 0:350011bf8be7 179 #endif /* PPP_ADDITIONAL_CALLBACKS */
simon 0:350011bf8be7 180 1,
simon 0:350011bf8be7 181 "LCP",
simon 0:350011bf8be7 182 #if PPP_ADDITIONAL_CALLBACKS
simon 0:350011bf8be7 183 NULL,
simon 0:350011bf8be7 184 NULL,
simon 0:350011bf8be7 185 NULL
simon 0:350011bf8be7 186 #endif /* PPP_ADDITIONAL_CALLBACKS */
simon 0:350011bf8be7 187 };
simon 0:350011bf8be7 188
simon 0:350011bf8be7 189 int lcp_loopbackfail = DEFLOOPBACKFAIL;
simon 0:350011bf8be7 190
simon 0:350011bf8be7 191 /*
simon 0:350011bf8be7 192 * Length of each type of configuration option (in octets)
simon 0:350011bf8be7 193 */
simon 0:350011bf8be7 194 #define CILEN_VOID 2
simon 0:350011bf8be7 195 #define CILEN_CHAR 3
simon 0:350011bf8be7 196 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
simon 0:350011bf8be7 197 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
simon 0:350011bf8be7 198 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
simon 0:350011bf8be7 199 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
simon 0:350011bf8be7 200 #define CILEN_CBCP 3
simon 0:350011bf8be7 201
simon 0:350011bf8be7 202 #define CODENAME(x) ((x) == CONFACK ? "ACK" : (x) == CONFNAK ? "NAK" : "REJ")
simon 0:350011bf8be7 203
simon 0:350011bf8be7 204 #if 0 /* UNUSED */
simon 0:350011bf8be7 205 /*
simon 0:350011bf8be7 206 * setescape - add chars to the set we escape on transmission.
simon 0:350011bf8be7 207 */
simon 0:350011bf8be7 208 static int
simon 0:350011bf8be7 209 setescape(argv)
simon 0:350011bf8be7 210 char **argv;
simon 0:350011bf8be7 211 {
simon 0:350011bf8be7 212 int n, ret;
simon 0:350011bf8be7 213 char *p, *endp;
simon 0:350011bf8be7 214
simon 0:350011bf8be7 215 p = *argv;
simon 0:350011bf8be7 216 ret = 1;
simon 0:350011bf8be7 217 while (*p) {
simon 0:350011bf8be7 218 n = strtol(p, &endp, 16);
simon 0:350011bf8be7 219 if (p == endp) {
simon 0:350011bf8be7 220 option_error("escape parameter contains invalid hex number '%s'", p);
simon 0:350011bf8be7 221 return 0;
simon 0:350011bf8be7 222 }
simon 0:350011bf8be7 223 p = endp;
simon 0:350011bf8be7 224 if (n < 0 || n == 0x5E || n > 0xFF) {
simon 0:350011bf8be7 225 option_error("can't escape character 0x%x", n);
simon 0:350011bf8be7 226 ret = 0;
simon 0:350011bf8be7 227 } else
simon 0:350011bf8be7 228 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
simon 0:350011bf8be7 229 while (*p == ',' || *p == ' ')
simon 0:350011bf8be7 230 ++p;
simon 0:350011bf8be7 231 }
simon 0:350011bf8be7 232 return ret;
simon 0:350011bf8be7 233 }
simon 0:350011bf8be7 234 #endif /* UNUSED */
simon 0:350011bf8be7 235
simon 0:350011bf8be7 236 /*
simon 0:350011bf8be7 237 * lcp_init - Initialize LCP.
simon 0:350011bf8be7 238 */
simon 0:350011bf8be7 239 void
simon 0:350011bf8be7 240 lcp_init(int unit)
simon 0:350011bf8be7 241 {
simon 0:350011bf8be7 242 fsm *f = &lcp_fsm[unit];
simon 0:350011bf8be7 243 lcp_options *wo = &lcp_wantoptions[unit];
simon 0:350011bf8be7 244 lcp_options *ao = &lcp_allowoptions[unit];
simon 0:350011bf8be7 245
simon 0:350011bf8be7 246 f->unit = unit;
simon 0:350011bf8be7 247 f->protocol = PPP_LCP;
simon 0:350011bf8be7 248 f->callbacks = &lcp_callbacks;
simon 0:350011bf8be7 249
simon 0:350011bf8be7 250 fsm_init(f);
simon 0:350011bf8be7 251
simon 0:350011bf8be7 252 wo->passive = 0;
simon 0:350011bf8be7 253 wo->silent = 0;
simon 0:350011bf8be7 254 wo->restart = 0; /* Set to 1 in kernels or multi-line implementations */
simon 0:350011bf8be7 255 wo->neg_mru = 1;
simon 0:350011bf8be7 256 wo->mru = PPP_DEFMRU;
simon 0:350011bf8be7 257 wo->neg_asyncmap = 1;
simon 0:350011bf8be7 258 wo->asyncmap = 0x00000000l; /* Assume don't need to escape any ctl chars. */
simon 0:350011bf8be7 259 wo->neg_chap = 0; /* Set to 1 on server */
simon 0:350011bf8be7 260 wo->neg_upap = 0; /* Set to 1 on server */
simon 0:350011bf8be7 261 wo->chap_mdtype = CHAP_DIGEST_MD5;
simon 0:350011bf8be7 262 wo->neg_magicnumber = 1;
simon 0:350011bf8be7 263 wo->neg_pcompression = 1;
simon 0:350011bf8be7 264 wo->neg_accompression = 1;
simon 0:350011bf8be7 265 wo->neg_lqr = 0; /* no LQR implementation yet */
simon 0:350011bf8be7 266 wo->neg_cbcp = 0;
simon 0:350011bf8be7 267
simon 0:350011bf8be7 268 ao->neg_mru = 1;
simon 0:350011bf8be7 269 ao->mru = PPP_MAXMRU;
simon 0:350011bf8be7 270 ao->neg_asyncmap = 1;
simon 0:350011bf8be7 271 ao->asyncmap = 0x00000000l; /* Assume don't need to escape any ctl chars. */
simon 0:350011bf8be7 272 ao->neg_chap = (CHAP_SUPPORT != 0);
simon 0:350011bf8be7 273 ao->chap_mdtype = CHAP_DIGEST_MD5;
simon 0:350011bf8be7 274 ao->neg_upap = (PAP_SUPPORT != 0);
simon 0:350011bf8be7 275 ao->neg_magicnumber = 1;
simon 0:350011bf8be7 276 ao->neg_pcompression = 1;
simon 0:350011bf8be7 277 ao->neg_accompression = 1;
simon 0:350011bf8be7 278 ao->neg_lqr = 0; /* no LQR implementation yet */
simon 0:350011bf8be7 279 ao->neg_cbcp = (CBCP_SUPPORT != 0);
simon 0:350011bf8be7 280
simon 0:350011bf8be7 281 /*
simon 0:350011bf8be7 282 * Set transmit escape for the flag and escape characters plus anything
simon 0:350011bf8be7 283 * set for the allowable options.
simon 0:350011bf8be7 284 */
simon 0:350011bf8be7 285 memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
simon 0:350011bf8be7 286 xmit_accm[unit][15] = 0x60;
simon 0:350011bf8be7 287 xmit_accm[unit][0] = (u_char)((ao->asyncmap & 0xFF));
simon 0:350011bf8be7 288 xmit_accm[unit][1] = (u_char)((ao->asyncmap >> 8) & 0xFF);
simon 0:350011bf8be7 289 xmit_accm[unit][2] = (u_char)((ao->asyncmap >> 16) & 0xFF);
simon 0:350011bf8be7 290 xmit_accm[unit][3] = (u_char)((ao->asyncmap >> 24) & 0xFF);
simon 0:350011bf8be7 291 LCPDEBUG(LOG_INFO, ("lcp_init: xmit_accm=%X %X %X %X\n",
simon 0:350011bf8be7 292 xmit_accm[unit][0],
simon 0:350011bf8be7 293 xmit_accm[unit][1],
simon 0:350011bf8be7 294 xmit_accm[unit][2],
simon 0:350011bf8be7 295 xmit_accm[unit][3]));
simon 0:350011bf8be7 296
simon 0:350011bf8be7 297 lcp_phase[unit] = PHASE_INITIALIZE;
simon 0:350011bf8be7 298 }
simon 0:350011bf8be7 299
simon 0:350011bf8be7 300
simon 0:350011bf8be7 301 /*
simon 0:350011bf8be7 302 * lcp_open - LCP is allowed to come up.
simon 0:350011bf8be7 303 */
simon 0:350011bf8be7 304 void
simon 0:350011bf8be7 305 lcp_open(int unit)
simon 0:350011bf8be7 306 {
simon 0:350011bf8be7 307 fsm *f = &lcp_fsm[unit];
simon 0:350011bf8be7 308 lcp_options *wo = &lcp_wantoptions[unit];
simon 0:350011bf8be7 309
simon 0:350011bf8be7 310 f->flags = 0;
simon 0:350011bf8be7 311 if (wo->passive) {
simon 0:350011bf8be7 312 f->flags |= OPT_PASSIVE;
simon 0:350011bf8be7 313 }
simon 0:350011bf8be7 314 if (wo->silent) {
simon 0:350011bf8be7 315 f->flags |= OPT_SILENT;
simon 0:350011bf8be7 316 }
simon 0:350011bf8be7 317 fsm_open(f);
simon 0:350011bf8be7 318
simon 0:350011bf8be7 319 lcp_phase[unit] = PHASE_ESTABLISH;
simon 0:350011bf8be7 320 }
simon 0:350011bf8be7 321
simon 0:350011bf8be7 322
simon 0:350011bf8be7 323 /*
simon 0:350011bf8be7 324 * lcp_close - Take LCP down.
simon 0:350011bf8be7 325 */
simon 0:350011bf8be7 326 void
simon 0:350011bf8be7 327 lcp_close(int unit, char *reason)
simon 0:350011bf8be7 328 {
simon 0:350011bf8be7 329 fsm *f = &lcp_fsm[unit];
simon 0:350011bf8be7 330
simon 0:350011bf8be7 331 if (lcp_phase[unit] != PHASE_DEAD) {
simon 0:350011bf8be7 332 lcp_phase[unit] = PHASE_TERMINATE;
simon 0:350011bf8be7 333 }
simon 0:350011bf8be7 334 if (f->state == LS_STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
simon 0:350011bf8be7 335 /*
simon 0:350011bf8be7 336 * This action is not strictly according to the FSM in RFC1548,
simon 0:350011bf8be7 337 * but it does mean that the program terminates if you do an
simon 0:350011bf8be7 338 * lcp_close() in passive/silent mode when a connection hasn't
simon 0:350011bf8be7 339 * been established.
simon 0:350011bf8be7 340 */
simon 0:350011bf8be7 341 f->state = LS_CLOSED;
simon 0:350011bf8be7 342 lcp_finished(f);
simon 0:350011bf8be7 343 } else {
simon 0:350011bf8be7 344 fsm_close(f, reason);
simon 0:350011bf8be7 345 }
simon 0:350011bf8be7 346 }
simon 0:350011bf8be7 347
simon 0:350011bf8be7 348
simon 0:350011bf8be7 349 /*
simon 0:350011bf8be7 350 * lcp_lowerup - The lower layer is up.
simon 0:350011bf8be7 351 */
simon 0:350011bf8be7 352 void
simon 0:350011bf8be7 353 lcp_lowerup(int unit)
simon 0:350011bf8be7 354 {
simon 0:350011bf8be7 355 lcp_options *wo = &lcp_wantoptions[unit];
simon 0:350011bf8be7 356
simon 0:350011bf8be7 357 /*
simon 0:350011bf8be7 358 * Don't use A/C or protocol compression on transmission,
simon 0:350011bf8be7 359 * but accept A/C and protocol compressed packets
simon 0:350011bf8be7 360 * if we are going to ask for A/C and protocol compression.
simon 0:350011bf8be7 361 */
simon 0:350011bf8be7 362 ppp_set_xaccm(unit, &xmit_accm[unit]);
simon 0:350011bf8be7 363 ppp_send_config(unit, PPP_MRU, 0xffffffffl, 0, 0);
simon 0:350011bf8be7 364 ppp_recv_config(unit, PPP_MRU, 0x00000000l,
simon 0:350011bf8be7 365 wo->neg_pcompression, wo->neg_accompression);
simon 0:350011bf8be7 366 peer_mru[unit] = PPP_MRU;
simon 0:350011bf8be7 367 lcp_allowoptions[unit].asyncmap = (u_long)xmit_accm[unit][0]
simon 0:350011bf8be7 368 | ((u_long)xmit_accm[unit][1] << 8)
simon 0:350011bf8be7 369 | ((u_long)xmit_accm[unit][2] << 16)
simon 0:350011bf8be7 370 | ((u_long)xmit_accm[unit][3] << 24);
simon 0:350011bf8be7 371 LCPDEBUG(LOG_INFO, ("lcp_lowerup: asyncmap=%X %X %X %X\n",
simon 0:350011bf8be7 372 xmit_accm[unit][3],
simon 0:350011bf8be7 373 xmit_accm[unit][2],
simon 0:350011bf8be7 374 xmit_accm[unit][1],
simon 0:350011bf8be7 375 xmit_accm[unit][0]));
simon 0:350011bf8be7 376
simon 0:350011bf8be7 377 fsm_lowerup(&lcp_fsm[unit]);
simon 0:350011bf8be7 378 }
simon 0:350011bf8be7 379
simon 0:350011bf8be7 380
simon 0:350011bf8be7 381 /*
simon 0:350011bf8be7 382 * lcp_lowerdown - The lower layer is down.
simon 0:350011bf8be7 383 */
simon 0:350011bf8be7 384 void
simon 0:350011bf8be7 385 lcp_lowerdown(int unit)
simon 0:350011bf8be7 386 {
simon 0:350011bf8be7 387 fsm_lowerdown(&lcp_fsm[unit]);
simon 0:350011bf8be7 388 }
simon 0:350011bf8be7 389
simon 0:350011bf8be7 390
simon 0:350011bf8be7 391 /*
simon 0:350011bf8be7 392 * lcp_input - Input LCP packet.
simon 0:350011bf8be7 393 */
simon 0:350011bf8be7 394 static void
simon 0:350011bf8be7 395 lcp_input(int unit, u_char *p, int len)
simon 0:350011bf8be7 396 {
simon 0:350011bf8be7 397 fsm *f = &lcp_fsm[unit];
simon 0:350011bf8be7 398
simon 0:350011bf8be7 399 fsm_input(f, p, len);
simon 0:350011bf8be7 400 }
simon 0:350011bf8be7 401
simon 0:350011bf8be7 402
simon 0:350011bf8be7 403 /*
simon 0:350011bf8be7 404 * lcp_extcode - Handle a LCP-specific code.
simon 0:350011bf8be7 405 */
simon 0:350011bf8be7 406 static int
simon 0:350011bf8be7 407 lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len)
simon 0:350011bf8be7 408 {
simon 0:350011bf8be7 409 u_char *magp;
simon 0:350011bf8be7 410
simon 0:350011bf8be7 411 switch( code ){
simon 0:350011bf8be7 412 case PROTREJ:
simon 0:350011bf8be7 413 lcp_rprotrej(f, inp, len);
simon 0:350011bf8be7 414 break;
simon 0:350011bf8be7 415
simon 0:350011bf8be7 416 case ECHOREQ:
simon 0:350011bf8be7 417 if (f->state != LS_OPENED) {
simon 0:350011bf8be7 418 break;
simon 0:350011bf8be7 419 }
simon 0:350011bf8be7 420 LCPDEBUG(LOG_INFO, ("lcp: Echo-Request, Rcvd id %d\n", id));
simon 0:350011bf8be7 421 magp = inp;
simon 0:350011bf8be7 422 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
simon 0:350011bf8be7 423 fsm_sdata(f, ECHOREP, id, inp, len);
simon 0:350011bf8be7 424 break;
simon 0:350011bf8be7 425
simon 0:350011bf8be7 426 case ECHOREP:
simon 0:350011bf8be7 427 lcp_received_echo_reply(f, id, inp, len);
simon 0:350011bf8be7 428 break;
simon 0:350011bf8be7 429
simon 0:350011bf8be7 430 case DISCREQ:
simon 0:350011bf8be7 431 break;
simon 0:350011bf8be7 432
simon 0:350011bf8be7 433 default:
simon 0:350011bf8be7 434 return 0;
simon 0:350011bf8be7 435 }
simon 0:350011bf8be7 436 return 1;
simon 0:350011bf8be7 437 }
simon 0:350011bf8be7 438
simon 0:350011bf8be7 439
simon 0:350011bf8be7 440 /*
simon 0:350011bf8be7 441 * lcp_rprotrej - Receive an Protocol-Reject.
simon 0:350011bf8be7 442 *
simon 0:350011bf8be7 443 * Figure out which protocol is rejected and inform it.
simon 0:350011bf8be7 444 */
simon 0:350011bf8be7 445 static void
simon 0:350011bf8be7 446 lcp_rprotrej(fsm *f, u_char *inp, int len)
simon 0:350011bf8be7 447 {
simon 0:350011bf8be7 448 int i;
simon 0:350011bf8be7 449 struct protent *protp;
simon 0:350011bf8be7 450 u_short prot;
simon 0:350011bf8be7 451
simon 0:350011bf8be7 452 if (len < (int)sizeof (u_short)) {
simon 0:350011bf8be7 453 LCPDEBUG(LOG_INFO, ("lcp_rprotrej: Rcvd short Protocol-Reject packet!\n"));
simon 0:350011bf8be7 454 return;
simon 0:350011bf8be7 455 }
simon 0:350011bf8be7 456
simon 0:350011bf8be7 457 GETSHORT(prot, inp);
simon 0:350011bf8be7 458
simon 0:350011bf8be7 459 LCPDEBUG(LOG_INFO, ("lcp_rprotrej: Rcvd Protocol-Reject packet for %x!\n", prot));
simon 0:350011bf8be7 460
simon 0:350011bf8be7 461 /*
simon 0:350011bf8be7 462 * Protocol-Reject packets received in any state other than the LCP
simon 0:350011bf8be7 463 * LS_OPENED state SHOULD be silently discarded.
simon 0:350011bf8be7 464 */
simon 0:350011bf8be7 465 if( f->state != LS_OPENED ) {
simon 0:350011bf8be7 466 LCPDEBUG(LOG_INFO, ("Protocol-Reject discarded: LCP in state %d\n", f->state));
simon 0:350011bf8be7 467 return;
simon 0:350011bf8be7 468 }
simon 0:350011bf8be7 469
simon 0:350011bf8be7 470 /*
simon 0:350011bf8be7 471 * Upcall the proper Protocol-Reject routine.
simon 0:350011bf8be7 472 */
simon 0:350011bf8be7 473 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
simon 0:350011bf8be7 474 if (protp->protocol == prot && protp->enabled_flag) {
simon 0:350011bf8be7 475 (*protp->protrej)(f->unit);
simon 0:350011bf8be7 476 return;
simon 0:350011bf8be7 477 }
simon 0:350011bf8be7 478 }
simon 0:350011bf8be7 479
simon 0:350011bf8be7 480 LCPDEBUG(LOG_WARNING, ("Protocol-Reject for unsupported protocol 0x%x\n", prot));
simon 0:350011bf8be7 481 }
simon 0:350011bf8be7 482
simon 0:350011bf8be7 483
simon 0:350011bf8be7 484 /*
simon 0:350011bf8be7 485 * lcp_protrej - A Protocol-Reject was received.
simon 0:350011bf8be7 486 */
simon 0:350011bf8be7 487 static void
simon 0:350011bf8be7 488 lcp_protrej(int unit)
simon 0:350011bf8be7 489 {
simon 0:350011bf8be7 490 LWIP_UNUSED_ARG(unit);
simon 0:350011bf8be7 491 /*
simon 0:350011bf8be7 492 * Can't reject LCP!
simon 0:350011bf8be7 493 */
simon 0:350011bf8be7 494 LCPDEBUG(LOG_WARNING, ("lcp_protrej: Received Protocol-Reject for LCP!\n"));
simon 0:350011bf8be7 495 fsm_protreject(&lcp_fsm[unit]);
simon 0:350011bf8be7 496 }
simon 0:350011bf8be7 497
simon 0:350011bf8be7 498
simon 0:350011bf8be7 499 /*
simon 0:350011bf8be7 500 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
simon 0:350011bf8be7 501 */
simon 0:350011bf8be7 502 void
simon 0:350011bf8be7 503 lcp_sprotrej(int unit, u_char *p, int len)
simon 0:350011bf8be7 504 {
simon 0:350011bf8be7 505 /*
simon 0:350011bf8be7 506 * Send back the protocol and the information field of the
simon 0:350011bf8be7 507 * rejected packet. We only get here if LCP is in the LS_OPENED state.
simon 0:350011bf8be7 508 */
simon 0:350011bf8be7 509
simon 0:350011bf8be7 510 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id, p, len);
simon 0:350011bf8be7 511 }
simon 0:350011bf8be7 512
simon 0:350011bf8be7 513
simon 0:350011bf8be7 514 /*
simon 0:350011bf8be7 515 * lcp_resetci - Reset our CI.
simon 0:350011bf8be7 516 */
simon 0:350011bf8be7 517 static void
simon 0:350011bf8be7 518 lcp_resetci(fsm *f)
simon 0:350011bf8be7 519 {
simon 0:350011bf8be7 520 lcp_wantoptions[f->unit].magicnumber = magic();
simon 0:350011bf8be7 521 lcp_wantoptions[f->unit].numloops = 0;
simon 0:350011bf8be7 522 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
simon 0:350011bf8be7 523 peer_mru[f->unit] = PPP_MRU;
simon 0:350011bf8be7 524 auth_reset(f->unit);
simon 0:350011bf8be7 525 }
simon 0:350011bf8be7 526
simon 0:350011bf8be7 527
simon 0:350011bf8be7 528 /*
simon 0:350011bf8be7 529 * lcp_cilen - Return length of our CI.
simon 0:350011bf8be7 530 */
simon 0:350011bf8be7 531 static int
simon 0:350011bf8be7 532 lcp_cilen(fsm *f)
simon 0:350011bf8be7 533 {
simon 0:350011bf8be7 534 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 535
simon 0:350011bf8be7 536 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
simon 0:350011bf8be7 537 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
simon 0:350011bf8be7 538 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
simon 0:350011bf8be7 539 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
simon 0:350011bf8be7 540 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
simon 0:350011bf8be7 541 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
simon 0:350011bf8be7 542 /*
simon 0:350011bf8be7 543 * NB: we only ask for one of CHAP and UPAP, even if we will
simon 0:350011bf8be7 544 * accept either.
simon 0:350011bf8be7 545 */
simon 0:350011bf8be7 546 return (LENCISHORT(go->neg_mru && go->mru != PPP_DEFMRU) +
simon 0:350011bf8be7 547 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl) +
simon 0:350011bf8be7 548 LENCICHAP(go->neg_chap) +
simon 0:350011bf8be7 549 LENCISHORT(!go->neg_chap && go->neg_upap) +
simon 0:350011bf8be7 550 LENCILQR(go->neg_lqr) +
simon 0:350011bf8be7 551 LENCICBCP(go->neg_cbcp) +
simon 0:350011bf8be7 552 LENCILONG(go->neg_magicnumber) +
simon 0:350011bf8be7 553 LENCIVOID(go->neg_pcompression) +
simon 0:350011bf8be7 554 LENCIVOID(go->neg_accompression));
simon 0:350011bf8be7 555 }
simon 0:350011bf8be7 556
simon 0:350011bf8be7 557
simon 0:350011bf8be7 558 /*
simon 0:350011bf8be7 559 * lcp_addci - Add our desired CIs to a packet.
simon 0:350011bf8be7 560 */
simon 0:350011bf8be7 561 static void
simon 0:350011bf8be7 562 lcp_addci(fsm *f, u_char *ucp, int *lenp)
simon 0:350011bf8be7 563 {
simon 0:350011bf8be7 564 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 565 u_char *start_ucp = ucp;
simon 0:350011bf8be7 566
simon 0:350011bf8be7 567 #define ADDCIVOID(opt, neg) \
simon 0:350011bf8be7 568 if (neg) { \
simon 0:350011bf8be7 569 LCPDEBUG(LOG_INFO, ("lcp_addci: opt=%d\n", opt)); \
simon 0:350011bf8be7 570 PUTCHAR(opt, ucp); \
simon 0:350011bf8be7 571 PUTCHAR(CILEN_VOID, ucp); \
simon 0:350011bf8be7 572 }
simon 0:350011bf8be7 573 #define ADDCISHORT(opt, neg, val) \
simon 0:350011bf8be7 574 if (neg) { \
simon 0:350011bf8be7 575 LCPDEBUG(LOG_INFO, ("lcp_addci: INT opt=%d %X\n", opt, val)); \
simon 0:350011bf8be7 576 PUTCHAR(opt, ucp); \
simon 0:350011bf8be7 577 PUTCHAR(CILEN_SHORT, ucp); \
simon 0:350011bf8be7 578 PUTSHORT(val, ucp); \
simon 0:350011bf8be7 579 }
simon 0:350011bf8be7 580 #define ADDCICHAP(opt, neg, val, digest) \
simon 0:350011bf8be7 581 if (neg) { \
simon 0:350011bf8be7 582 LCPDEBUG(LOG_INFO, ("lcp_addci: CHAP opt=%d %X\n", opt, val)); \
simon 0:350011bf8be7 583 PUTCHAR(opt, ucp); \
simon 0:350011bf8be7 584 PUTCHAR(CILEN_CHAP, ucp); \
simon 0:350011bf8be7 585 PUTSHORT(val, ucp); \
simon 0:350011bf8be7 586 PUTCHAR(digest, ucp); \
simon 0:350011bf8be7 587 }
simon 0:350011bf8be7 588 #define ADDCILONG(opt, neg, val) \
simon 0:350011bf8be7 589 if (neg) { \
simon 0:350011bf8be7 590 LCPDEBUG(LOG_INFO, ("lcp_addci: L opt=%d %lX\n", opt, val)); \
simon 0:350011bf8be7 591 PUTCHAR(opt, ucp); \
simon 0:350011bf8be7 592 PUTCHAR(CILEN_LONG, ucp); \
simon 0:350011bf8be7 593 PUTLONG(val, ucp); \
simon 0:350011bf8be7 594 }
simon 0:350011bf8be7 595 #define ADDCILQR(opt, neg, val) \
simon 0:350011bf8be7 596 if (neg) { \
simon 0:350011bf8be7 597 LCPDEBUG(LOG_INFO, ("lcp_addci: LQR opt=%d %lX\n", opt, val)); \
simon 0:350011bf8be7 598 PUTCHAR(opt, ucp); \
simon 0:350011bf8be7 599 PUTCHAR(CILEN_LQR, ucp); \
simon 0:350011bf8be7 600 PUTSHORT(PPP_LQR, ucp); \
simon 0:350011bf8be7 601 PUTLONG(val, ucp); \
simon 0:350011bf8be7 602 }
simon 0:350011bf8be7 603 #define ADDCICHAR(opt, neg, val) \
simon 0:350011bf8be7 604 if (neg) { \
simon 0:350011bf8be7 605 LCPDEBUG(LOG_INFO, ("lcp_addci: CHAR opt=%d %X '%z'\n", opt, val, val)); \
simon 0:350011bf8be7 606 PUTCHAR(opt, ucp); \
simon 0:350011bf8be7 607 PUTCHAR(CILEN_CHAR, ucp); \
simon 0:350011bf8be7 608 PUTCHAR(val, ucp); \
simon 0:350011bf8be7 609 }
simon 0:350011bf8be7 610
simon 0:350011bf8be7 611 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
simon 0:350011bf8be7 612 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
simon 0:350011bf8be7 613 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
simon 0:350011bf8be7 614 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
simon 0:350011bf8be7 615 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
simon 0:350011bf8be7 616 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
simon 0:350011bf8be7 617 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
simon 0:350011bf8be7 618 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
simon 0:350011bf8be7 619 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
simon 0:350011bf8be7 620
simon 0:350011bf8be7 621 if (ucp - start_ucp != *lenp) {
simon 0:350011bf8be7 622 /* this should never happen, because peer_mtu should be 1500 */
simon 0:350011bf8be7 623 LCPDEBUG(LOG_ERR, ("Bug in lcp_addci: wrong length\n"));
simon 0:350011bf8be7 624 }
simon 0:350011bf8be7 625 }
simon 0:350011bf8be7 626
simon 0:350011bf8be7 627
simon 0:350011bf8be7 628 /*
simon 0:350011bf8be7 629 * lcp_ackci - Ack our CIs.
simon 0:350011bf8be7 630 * This should not modify any state if the Ack is bad.
simon 0:350011bf8be7 631 *
simon 0:350011bf8be7 632 * Returns:
simon 0:350011bf8be7 633 * 0 - Ack was bad.
simon 0:350011bf8be7 634 * 1 - Ack was good.
simon 0:350011bf8be7 635 */
simon 0:350011bf8be7 636 static int
simon 0:350011bf8be7 637 lcp_ackci(fsm *f, u_char *p, int len)
simon 0:350011bf8be7 638 {
simon 0:350011bf8be7 639 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 640 u_char cilen, citype, cichar;
simon 0:350011bf8be7 641 u_short cishort;
simon 0:350011bf8be7 642 u32_t cilong;
simon 0:350011bf8be7 643
simon 0:350011bf8be7 644 /*
simon 0:350011bf8be7 645 * CIs must be in exactly the same order that we sent.
simon 0:350011bf8be7 646 * Check packet length and CI length at each step.
simon 0:350011bf8be7 647 * If we find any deviations, then this packet is bad.
simon 0:350011bf8be7 648 */
simon 0:350011bf8be7 649 #define ACKCIVOID(opt, neg) \
simon 0:350011bf8be7 650 if (neg) { \
simon 0:350011bf8be7 651 if ((len -= CILEN_VOID) < 0) \
simon 0:350011bf8be7 652 goto bad; \
simon 0:350011bf8be7 653 GETCHAR(citype, p); \
simon 0:350011bf8be7 654 GETCHAR(cilen, p); \
simon 0:350011bf8be7 655 if (cilen != CILEN_VOID || citype != opt) \
simon 0:350011bf8be7 656 goto bad; \
simon 0:350011bf8be7 657 }
simon 0:350011bf8be7 658 #define ACKCISHORT(opt, neg, val) \
simon 0:350011bf8be7 659 if (neg) { \
simon 0:350011bf8be7 660 if ((len -= CILEN_SHORT) < 0) \
simon 0:350011bf8be7 661 goto bad; \
simon 0:350011bf8be7 662 GETCHAR(citype, p); \
simon 0:350011bf8be7 663 GETCHAR(cilen, p); \
simon 0:350011bf8be7 664 if (cilen != CILEN_SHORT || citype != opt) \
simon 0:350011bf8be7 665 goto bad; \
simon 0:350011bf8be7 666 GETSHORT(cishort, p); \
simon 0:350011bf8be7 667 if (cishort != val) \
simon 0:350011bf8be7 668 goto bad; \
simon 0:350011bf8be7 669 }
simon 0:350011bf8be7 670 #define ACKCICHAR(opt, neg, val) \
simon 0:350011bf8be7 671 if (neg) { \
simon 0:350011bf8be7 672 if ((len -= CILEN_CHAR) < 0) \
simon 0:350011bf8be7 673 goto bad; \
simon 0:350011bf8be7 674 GETCHAR(citype, p); \
simon 0:350011bf8be7 675 GETCHAR(cilen, p); \
simon 0:350011bf8be7 676 if (cilen != CILEN_CHAR || citype != opt) \
simon 0:350011bf8be7 677 goto bad; \
simon 0:350011bf8be7 678 GETCHAR(cichar, p); \
simon 0:350011bf8be7 679 if (cichar != val) \
simon 0:350011bf8be7 680 goto bad; \
simon 0:350011bf8be7 681 }
simon 0:350011bf8be7 682 #define ACKCICHAP(opt, neg, val, digest) \
simon 0:350011bf8be7 683 if (neg) { \
simon 0:350011bf8be7 684 if ((len -= CILEN_CHAP) < 0) \
simon 0:350011bf8be7 685 goto bad; \
simon 0:350011bf8be7 686 GETCHAR(citype, p); \
simon 0:350011bf8be7 687 GETCHAR(cilen, p); \
simon 0:350011bf8be7 688 if (cilen != CILEN_CHAP || citype != opt) \
simon 0:350011bf8be7 689 goto bad; \
simon 0:350011bf8be7 690 GETSHORT(cishort, p); \
simon 0:350011bf8be7 691 if (cishort != val) \
simon 0:350011bf8be7 692 goto bad; \
simon 0:350011bf8be7 693 GETCHAR(cichar, p); \
simon 0:350011bf8be7 694 if (cichar != digest) \
simon 0:350011bf8be7 695 goto bad; \
simon 0:350011bf8be7 696 }
simon 0:350011bf8be7 697 #define ACKCILONG(opt, neg, val) \
simon 0:350011bf8be7 698 if (neg) { \
simon 0:350011bf8be7 699 if ((len -= CILEN_LONG) < 0) \
simon 0:350011bf8be7 700 goto bad; \
simon 0:350011bf8be7 701 GETCHAR(citype, p); \
simon 0:350011bf8be7 702 GETCHAR(cilen, p); \
simon 0:350011bf8be7 703 if (cilen != CILEN_LONG || citype != opt) \
simon 0:350011bf8be7 704 goto bad; \
simon 0:350011bf8be7 705 GETLONG(cilong, p); \
simon 0:350011bf8be7 706 if (cilong != val) \
simon 0:350011bf8be7 707 goto bad; \
simon 0:350011bf8be7 708 }
simon 0:350011bf8be7 709 #define ACKCILQR(opt, neg, val) \
simon 0:350011bf8be7 710 if (neg) { \
simon 0:350011bf8be7 711 if ((len -= CILEN_LQR) < 0) \
simon 0:350011bf8be7 712 goto bad; \
simon 0:350011bf8be7 713 GETCHAR(citype, p); \
simon 0:350011bf8be7 714 GETCHAR(cilen, p); \
simon 0:350011bf8be7 715 if (cilen != CILEN_LQR || citype != opt) \
simon 0:350011bf8be7 716 goto bad; \
simon 0:350011bf8be7 717 GETSHORT(cishort, p); \
simon 0:350011bf8be7 718 if (cishort != PPP_LQR) \
simon 0:350011bf8be7 719 goto bad; \
simon 0:350011bf8be7 720 GETLONG(cilong, p); \
simon 0:350011bf8be7 721 if (cilong != val) \
simon 0:350011bf8be7 722 goto bad; \
simon 0:350011bf8be7 723 }
simon 0:350011bf8be7 724
simon 0:350011bf8be7 725 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
simon 0:350011bf8be7 726 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
simon 0:350011bf8be7 727 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
simon 0:350011bf8be7 728 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
simon 0:350011bf8be7 729 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
simon 0:350011bf8be7 730 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
simon 0:350011bf8be7 731 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
simon 0:350011bf8be7 732 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
simon 0:350011bf8be7 733 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
simon 0:350011bf8be7 734
simon 0:350011bf8be7 735 /*
simon 0:350011bf8be7 736 * If there are any remaining CIs, then this packet is bad.
simon 0:350011bf8be7 737 */
simon 0:350011bf8be7 738 if (len != 0) {
simon 0:350011bf8be7 739 goto bad;
simon 0:350011bf8be7 740 }
simon 0:350011bf8be7 741 LCPDEBUG(LOG_INFO, ("lcp_acki: Ack\n"));
simon 0:350011bf8be7 742 return (1);
simon 0:350011bf8be7 743 bad:
simon 0:350011bf8be7 744 LCPDEBUG(LOG_WARNING, ("lcp_acki: received bad Ack!\n"));
simon 0:350011bf8be7 745 return (0);
simon 0:350011bf8be7 746 }
simon 0:350011bf8be7 747
simon 0:350011bf8be7 748
simon 0:350011bf8be7 749 /*
simon 0:350011bf8be7 750 * lcp_nakci - Peer has sent a NAK for some of our CIs.
simon 0:350011bf8be7 751 * This should not modify any state if the Nak is bad
simon 0:350011bf8be7 752 * or if LCP is in the LS_OPENED state.
simon 0:350011bf8be7 753 *
simon 0:350011bf8be7 754 * Returns:
simon 0:350011bf8be7 755 * 0 - Nak was bad.
simon 0:350011bf8be7 756 * 1 - Nak was good.
simon 0:350011bf8be7 757 */
simon 0:350011bf8be7 758 static int
simon 0:350011bf8be7 759 lcp_nakci(fsm *f, u_char *p, int len)
simon 0:350011bf8be7 760 {
simon 0:350011bf8be7 761 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 762 lcp_options *wo = &lcp_wantoptions[f->unit];
simon 0:350011bf8be7 763 u_char citype, cichar, *next;
simon 0:350011bf8be7 764 u_short cishort;
simon 0:350011bf8be7 765 u32_t cilong;
simon 0:350011bf8be7 766 lcp_options no; /* options we've seen Naks for */
simon 0:350011bf8be7 767 lcp_options try; /* options to request next time */
simon 0:350011bf8be7 768 int looped_back = 0;
simon 0:350011bf8be7 769 int cilen;
simon 0:350011bf8be7 770
simon 0:350011bf8be7 771 BZERO(&no, sizeof(no));
simon 0:350011bf8be7 772 try = *go;
simon 0:350011bf8be7 773
simon 0:350011bf8be7 774 /*
simon 0:350011bf8be7 775 * Any Nak'd CIs must be in exactly the same order that we sent.
simon 0:350011bf8be7 776 * Check packet length and CI length at each step.
simon 0:350011bf8be7 777 * If we find any deviations, then this packet is bad.
simon 0:350011bf8be7 778 */
simon 0:350011bf8be7 779 #define NAKCIVOID(opt, neg, code) \
simon 0:350011bf8be7 780 if (go->neg && \
simon 0:350011bf8be7 781 len >= CILEN_VOID && \
simon 0:350011bf8be7 782 p[1] == CILEN_VOID && \
simon 0:350011bf8be7 783 p[0] == opt) { \
simon 0:350011bf8be7 784 len -= CILEN_VOID; \
simon 0:350011bf8be7 785 INCPTR(CILEN_VOID, p); \
simon 0:350011bf8be7 786 no.neg = 1; \
simon 0:350011bf8be7 787 code \
simon 0:350011bf8be7 788 }
simon 0:350011bf8be7 789 #define NAKCICHAP(opt, neg, code) \
simon 0:350011bf8be7 790 if (go->neg && \
simon 0:350011bf8be7 791 len >= CILEN_CHAP && \
simon 0:350011bf8be7 792 p[1] == CILEN_CHAP && \
simon 0:350011bf8be7 793 p[0] == opt) { \
simon 0:350011bf8be7 794 len -= CILEN_CHAP; \
simon 0:350011bf8be7 795 INCPTR(2, p); \
simon 0:350011bf8be7 796 GETSHORT(cishort, p); \
simon 0:350011bf8be7 797 GETCHAR(cichar, p); \
simon 0:350011bf8be7 798 no.neg = 1; \
simon 0:350011bf8be7 799 code \
simon 0:350011bf8be7 800 }
simon 0:350011bf8be7 801 #define NAKCICHAR(opt, neg, code) \
simon 0:350011bf8be7 802 if (go->neg && \
simon 0:350011bf8be7 803 len >= CILEN_CHAR && \
simon 0:350011bf8be7 804 p[1] == CILEN_CHAR && \
simon 0:350011bf8be7 805 p[0] == opt) { \
simon 0:350011bf8be7 806 len -= CILEN_CHAR; \
simon 0:350011bf8be7 807 INCPTR(2, p); \
simon 0:350011bf8be7 808 GETCHAR(cichar, p); \
simon 0:350011bf8be7 809 no.neg = 1; \
simon 0:350011bf8be7 810 code \
simon 0:350011bf8be7 811 }
simon 0:350011bf8be7 812 #define NAKCISHORT(opt, neg, code) \
simon 0:350011bf8be7 813 if (go->neg && \
simon 0:350011bf8be7 814 len >= CILEN_SHORT && \
simon 0:350011bf8be7 815 p[1] == CILEN_SHORT && \
simon 0:350011bf8be7 816 p[0] == opt) { \
simon 0:350011bf8be7 817 len -= CILEN_SHORT; \
simon 0:350011bf8be7 818 INCPTR(2, p); \
simon 0:350011bf8be7 819 GETSHORT(cishort, p); \
simon 0:350011bf8be7 820 no.neg = 1; \
simon 0:350011bf8be7 821 code \
simon 0:350011bf8be7 822 }
simon 0:350011bf8be7 823 #define NAKCILONG(opt, neg, code) \
simon 0:350011bf8be7 824 if (go->neg && \
simon 0:350011bf8be7 825 len >= CILEN_LONG && \
simon 0:350011bf8be7 826 p[1] == CILEN_LONG && \
simon 0:350011bf8be7 827 p[0] == opt) { \
simon 0:350011bf8be7 828 len -= CILEN_LONG; \
simon 0:350011bf8be7 829 INCPTR(2, p); \
simon 0:350011bf8be7 830 GETLONG(cilong, p); \
simon 0:350011bf8be7 831 no.neg = 1; \
simon 0:350011bf8be7 832 code \
simon 0:350011bf8be7 833 }
simon 0:350011bf8be7 834 #define NAKCILQR(opt, neg, code) \
simon 0:350011bf8be7 835 if (go->neg && \
simon 0:350011bf8be7 836 len >= CILEN_LQR && \
simon 0:350011bf8be7 837 p[1] == CILEN_LQR && \
simon 0:350011bf8be7 838 p[0] == opt) { \
simon 0:350011bf8be7 839 len -= CILEN_LQR; \
simon 0:350011bf8be7 840 INCPTR(2, p); \
simon 0:350011bf8be7 841 GETSHORT(cishort, p); \
simon 0:350011bf8be7 842 GETLONG(cilong, p); \
simon 0:350011bf8be7 843 no.neg = 1; \
simon 0:350011bf8be7 844 code \
simon 0:350011bf8be7 845 }
simon 0:350011bf8be7 846
simon 0:350011bf8be7 847 /*
simon 0:350011bf8be7 848 * We don't care if they want to send us smaller packets than
simon 0:350011bf8be7 849 * we want. Therefore, accept any MRU less than what we asked for,
simon 0:350011bf8be7 850 * but then ignore the new value when setting the MRU in the kernel.
simon 0:350011bf8be7 851 * If they send us a bigger MRU than what we asked, accept it, up to
simon 0:350011bf8be7 852 * the limit of the default MRU we'd get if we didn't negotiate.
simon 0:350011bf8be7 853 */
simon 0:350011bf8be7 854 if (go->neg_mru && go->mru != PPP_DEFMRU) {
simon 0:350011bf8be7 855 NAKCISHORT(CI_MRU, neg_mru,
simon 0:350011bf8be7 856 if (cishort <= wo->mru || cishort < PPP_DEFMRU) {
simon 0:350011bf8be7 857 try.mru = cishort;
simon 0:350011bf8be7 858 }
simon 0:350011bf8be7 859 );
simon 0:350011bf8be7 860 }
simon 0:350011bf8be7 861
simon 0:350011bf8be7 862 /*
simon 0:350011bf8be7 863 * Add any characters they want to our (receive-side) asyncmap.
simon 0:350011bf8be7 864 */
simon 0:350011bf8be7 865 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl) {
simon 0:350011bf8be7 866 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
simon 0:350011bf8be7 867 try.asyncmap = go->asyncmap | cilong;
simon 0:350011bf8be7 868 );
simon 0:350011bf8be7 869 }
simon 0:350011bf8be7 870
simon 0:350011bf8be7 871 /*
simon 0:350011bf8be7 872 * If they've nak'd our authentication-protocol, check whether
simon 0:350011bf8be7 873 * they are proposing a different protocol, or a different
simon 0:350011bf8be7 874 * hash algorithm for CHAP.
simon 0:350011bf8be7 875 */
simon 0:350011bf8be7 876 if ((go->neg_chap || go->neg_upap)
simon 0:350011bf8be7 877 && len >= CILEN_SHORT
simon 0:350011bf8be7 878 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
simon 0:350011bf8be7 879 cilen = p[1];
simon 0:350011bf8be7 880 len -= cilen;
simon 0:350011bf8be7 881 no.neg_chap = go->neg_chap;
simon 0:350011bf8be7 882 no.neg_upap = go->neg_upap;
simon 0:350011bf8be7 883 INCPTR(2, p);
simon 0:350011bf8be7 884 GETSHORT(cishort, p);
simon 0:350011bf8be7 885 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
simon 0:350011bf8be7 886 /*
simon 0:350011bf8be7 887 * If we were asking for CHAP, they obviously don't want to do it.
simon 0:350011bf8be7 888 * If we weren't asking for CHAP, then we were asking for PAP,
simon 0:350011bf8be7 889 * in which case this Nak is bad.
simon 0:350011bf8be7 890 */
simon 0:350011bf8be7 891 if (!go->neg_chap) {
simon 0:350011bf8be7 892 goto bad;
simon 0:350011bf8be7 893 }
simon 0:350011bf8be7 894 try.neg_chap = 0;
simon 0:350011bf8be7 895
simon 0:350011bf8be7 896 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
simon 0:350011bf8be7 897 GETCHAR(cichar, p);
simon 0:350011bf8be7 898 if (go->neg_chap) {
simon 0:350011bf8be7 899 /*
simon 0:350011bf8be7 900 * We were asking for CHAP/MD5; they must want a different
simon 0:350011bf8be7 901 * algorithm. If they can't do MD5, we'll have to stop
simon 0:350011bf8be7 902 * asking for CHAP.
simon 0:350011bf8be7 903 */
simon 0:350011bf8be7 904 if (cichar != go->chap_mdtype) {
simon 0:350011bf8be7 905 try.neg_chap = 0;
simon 0:350011bf8be7 906 }
simon 0:350011bf8be7 907 } else {
simon 0:350011bf8be7 908 /*
simon 0:350011bf8be7 909 * Stop asking for PAP if we were asking for it.
simon 0:350011bf8be7 910 */
simon 0:350011bf8be7 911 try.neg_upap = 0;
simon 0:350011bf8be7 912 }
simon 0:350011bf8be7 913
simon 0:350011bf8be7 914 } else {
simon 0:350011bf8be7 915 /*
simon 0:350011bf8be7 916 * We don't recognize what they're suggesting.
simon 0:350011bf8be7 917 * Stop asking for what we were asking for.
simon 0:350011bf8be7 918 */
simon 0:350011bf8be7 919 if (go->neg_chap) {
simon 0:350011bf8be7 920 try.neg_chap = 0;
simon 0:350011bf8be7 921 } else {
simon 0:350011bf8be7 922 try.neg_upap = 0;
simon 0:350011bf8be7 923 }
simon 0:350011bf8be7 924 p += cilen - CILEN_SHORT;
simon 0:350011bf8be7 925 }
simon 0:350011bf8be7 926 }
simon 0:350011bf8be7 927
simon 0:350011bf8be7 928 /*
simon 0:350011bf8be7 929 * If they can't cope with our link quality protocol, we'll have
simon 0:350011bf8be7 930 * to stop asking for LQR. We haven't got any other protocol.
simon 0:350011bf8be7 931 * If they Nak the reporting period, take their value XXX ?
simon 0:350011bf8be7 932 */
simon 0:350011bf8be7 933 NAKCILQR(CI_QUALITY, neg_lqr,
simon 0:350011bf8be7 934 if (cishort != PPP_LQR) {
simon 0:350011bf8be7 935 try.neg_lqr = 0;
simon 0:350011bf8be7 936 } else {
simon 0:350011bf8be7 937 try.lqr_period = cilong;
simon 0:350011bf8be7 938 }
simon 0:350011bf8be7 939 );
simon 0:350011bf8be7 940
simon 0:350011bf8be7 941 /*
simon 0:350011bf8be7 942 * Only implementing CBCP...not the rest of the callback options
simon 0:350011bf8be7 943 */
simon 0:350011bf8be7 944 NAKCICHAR(CI_CALLBACK, neg_cbcp,
simon 0:350011bf8be7 945 try.neg_cbcp = 0;
simon 0:350011bf8be7 946 );
simon 0:350011bf8be7 947
simon 0:350011bf8be7 948 /*
simon 0:350011bf8be7 949 * Check for a looped-back line.
simon 0:350011bf8be7 950 */
simon 0:350011bf8be7 951 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
simon 0:350011bf8be7 952 try.magicnumber = magic();
simon 0:350011bf8be7 953 looped_back = 1;
simon 0:350011bf8be7 954 );
simon 0:350011bf8be7 955
simon 0:350011bf8be7 956 /*
simon 0:350011bf8be7 957 * Peer shouldn't send Nak for protocol compression or
simon 0:350011bf8be7 958 * address/control compression requests; they should send
simon 0:350011bf8be7 959 * a Reject instead. If they send a Nak, treat it as a Reject.
simon 0:350011bf8be7 960 */
simon 0:350011bf8be7 961 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
simon 0:350011bf8be7 962 try.neg_pcompression = 0;
simon 0:350011bf8be7 963 );
simon 0:350011bf8be7 964 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
simon 0:350011bf8be7 965 try.neg_accompression = 0;
simon 0:350011bf8be7 966 );
simon 0:350011bf8be7 967
simon 0:350011bf8be7 968 /*
simon 0:350011bf8be7 969 * There may be remaining CIs, if the peer is requesting negotiation
simon 0:350011bf8be7 970 * on an option that we didn't include in our request packet.
simon 0:350011bf8be7 971 * If we see an option that we requested, or one we've already seen
simon 0:350011bf8be7 972 * in this packet, then this packet is bad.
simon 0:350011bf8be7 973 * If we wanted to respond by starting to negotiate on the requested
simon 0:350011bf8be7 974 * option(s), we could, but we don't, because except for the
simon 0:350011bf8be7 975 * authentication type and quality protocol, if we are not negotiating
simon 0:350011bf8be7 976 * an option, it is because we were told not to.
simon 0:350011bf8be7 977 * For the authentication type, the Nak from the peer means
simon 0:350011bf8be7 978 * `let me authenticate myself with you' which is a bit pointless.
simon 0:350011bf8be7 979 * For the quality protocol, the Nak means `ask me to send you quality
simon 0:350011bf8be7 980 * reports', but if we didn't ask for them, we don't want them.
simon 0:350011bf8be7 981 * An option we don't recognize represents the peer asking to
simon 0:350011bf8be7 982 * negotiate some option we don't support, so ignore it.
simon 0:350011bf8be7 983 */
simon 0:350011bf8be7 984 while (len > CILEN_VOID) {
simon 0:350011bf8be7 985 GETCHAR(citype, p);
simon 0:350011bf8be7 986 GETCHAR(cilen, p);
simon 0:350011bf8be7 987 if (cilen < CILEN_VOID || (len -= cilen) < 0) {
simon 0:350011bf8be7 988 goto bad;
simon 0:350011bf8be7 989 }
simon 0:350011bf8be7 990 next = p + cilen - 2;
simon 0:350011bf8be7 991
simon 0:350011bf8be7 992 switch (citype) {
simon 0:350011bf8be7 993 case CI_MRU:
simon 0:350011bf8be7 994 if ((go->neg_mru && go->mru != PPP_DEFMRU)
simon 0:350011bf8be7 995 || no.neg_mru || cilen != CILEN_SHORT) {
simon 0:350011bf8be7 996 goto bad;
simon 0:350011bf8be7 997 }
simon 0:350011bf8be7 998 GETSHORT(cishort, p);
simon 0:350011bf8be7 999 if (cishort < PPP_DEFMRU) {
simon 0:350011bf8be7 1000 try.mru = cishort;
simon 0:350011bf8be7 1001 }
simon 0:350011bf8be7 1002 break;
simon 0:350011bf8be7 1003 case CI_ASYNCMAP:
simon 0:350011bf8be7 1004 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl)
simon 0:350011bf8be7 1005 || no.neg_asyncmap || cilen != CILEN_LONG) {
simon 0:350011bf8be7 1006 goto bad;
simon 0:350011bf8be7 1007 }
simon 0:350011bf8be7 1008 break;
simon 0:350011bf8be7 1009 case CI_AUTHTYPE:
simon 0:350011bf8be7 1010 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap) {
simon 0:350011bf8be7 1011 goto bad;
simon 0:350011bf8be7 1012 }
simon 0:350011bf8be7 1013 break;
simon 0:350011bf8be7 1014 case CI_MAGICNUMBER:
simon 0:350011bf8be7 1015 if (go->neg_magicnumber || no.neg_magicnumber ||
simon 0:350011bf8be7 1016 cilen != CILEN_LONG) {
simon 0:350011bf8be7 1017 goto bad;
simon 0:350011bf8be7 1018 }
simon 0:350011bf8be7 1019 break;
simon 0:350011bf8be7 1020 case CI_PCOMPRESSION:
simon 0:350011bf8be7 1021 if (go->neg_pcompression || no.neg_pcompression
simon 0:350011bf8be7 1022 || cilen != CILEN_VOID) {
simon 0:350011bf8be7 1023 goto bad;
simon 0:350011bf8be7 1024 }
simon 0:350011bf8be7 1025 break;
simon 0:350011bf8be7 1026 case CI_ACCOMPRESSION:
simon 0:350011bf8be7 1027 if (go->neg_accompression || no.neg_accompression
simon 0:350011bf8be7 1028 || cilen != CILEN_VOID) {
simon 0:350011bf8be7 1029 goto bad;
simon 0:350011bf8be7 1030 }
simon 0:350011bf8be7 1031 break;
simon 0:350011bf8be7 1032 case CI_QUALITY:
simon 0:350011bf8be7 1033 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR) {
simon 0:350011bf8be7 1034 goto bad;
simon 0:350011bf8be7 1035 }
simon 0:350011bf8be7 1036 break;
simon 0:350011bf8be7 1037 }
simon 0:350011bf8be7 1038 p = next;
simon 0:350011bf8be7 1039 }
simon 0:350011bf8be7 1040
simon 0:350011bf8be7 1041 /* If there is still anything left, this packet is bad. */
simon 0:350011bf8be7 1042 if (len != 0) {
simon 0:350011bf8be7 1043 goto bad;
simon 0:350011bf8be7 1044 }
simon 0:350011bf8be7 1045
simon 0:350011bf8be7 1046 /*
simon 0:350011bf8be7 1047 * OK, the Nak is good. Now we can update state.
simon 0:350011bf8be7 1048 */
simon 0:350011bf8be7 1049 if (f->state != LS_OPENED) {
simon 0:350011bf8be7 1050 if (looped_back) {
simon 0:350011bf8be7 1051 if (++try.numloops >= lcp_loopbackfail) {
simon 0:350011bf8be7 1052 LCPDEBUG(LOG_NOTICE, ("Serial line is looped back.\n"));
simon 0:350011bf8be7 1053 lcp_close(f->unit, "Loopback detected");
simon 0:350011bf8be7 1054 }
simon 0:350011bf8be7 1055 } else {
simon 0:350011bf8be7 1056 try.numloops = 0;
simon 0:350011bf8be7 1057 }
simon 0:350011bf8be7 1058 *go = try;
simon 0:350011bf8be7 1059 }
simon 0:350011bf8be7 1060
simon 0:350011bf8be7 1061 return 1;
simon 0:350011bf8be7 1062
simon 0:350011bf8be7 1063 bad:
simon 0:350011bf8be7 1064 LCPDEBUG(LOG_WARNING, ("lcp_nakci: received bad Nak!\n"));
simon 0:350011bf8be7 1065 return 0;
simon 0:350011bf8be7 1066 }
simon 0:350011bf8be7 1067
simon 0:350011bf8be7 1068
simon 0:350011bf8be7 1069 /*
simon 0:350011bf8be7 1070 * lcp_rejci - Peer has Rejected some of our CIs.
simon 0:350011bf8be7 1071 * This should not modify any state if the Reject is bad
simon 0:350011bf8be7 1072 * or if LCP is in the LS_OPENED state.
simon 0:350011bf8be7 1073 *
simon 0:350011bf8be7 1074 * Returns:
simon 0:350011bf8be7 1075 * 0 - Reject was bad.
simon 0:350011bf8be7 1076 * 1 - Reject was good.
simon 0:350011bf8be7 1077 */
simon 0:350011bf8be7 1078 static int
simon 0:350011bf8be7 1079 lcp_rejci(fsm *f, u_char *p, int len)
simon 0:350011bf8be7 1080 {
simon 0:350011bf8be7 1081 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 1082 u_char cichar;
simon 0:350011bf8be7 1083 u_short cishort;
simon 0:350011bf8be7 1084 u32_t cilong;
simon 0:350011bf8be7 1085 lcp_options try; /* options to request next time */
simon 0:350011bf8be7 1086
simon 0:350011bf8be7 1087 try = *go;
simon 0:350011bf8be7 1088
simon 0:350011bf8be7 1089 /*
simon 0:350011bf8be7 1090 * Any Rejected CIs must be in exactly the same order that we sent.
simon 0:350011bf8be7 1091 * Check packet length and CI length at each step.
simon 0:350011bf8be7 1092 * If we find any deviations, then this packet is bad.
simon 0:350011bf8be7 1093 */
simon 0:350011bf8be7 1094 #define REJCIVOID(opt, neg) \
simon 0:350011bf8be7 1095 if (go->neg && \
simon 0:350011bf8be7 1096 len >= CILEN_VOID && \
simon 0:350011bf8be7 1097 p[1] == CILEN_VOID && \
simon 0:350011bf8be7 1098 p[0] == opt) { \
simon 0:350011bf8be7 1099 len -= CILEN_VOID; \
simon 0:350011bf8be7 1100 INCPTR(CILEN_VOID, p); \
simon 0:350011bf8be7 1101 try.neg = 0; \
simon 0:350011bf8be7 1102 LCPDEBUG(LOG_INFO, ("lcp_rejci: void opt %d rejected\n", opt)); \
simon 0:350011bf8be7 1103 }
simon 0:350011bf8be7 1104 #define REJCISHORT(opt, neg, val) \
simon 0:350011bf8be7 1105 if (go->neg && \
simon 0:350011bf8be7 1106 len >= CILEN_SHORT && \
simon 0:350011bf8be7 1107 p[1] == CILEN_SHORT && \
simon 0:350011bf8be7 1108 p[0] == opt) { \
simon 0:350011bf8be7 1109 len -= CILEN_SHORT; \
simon 0:350011bf8be7 1110 INCPTR(2, p); \
simon 0:350011bf8be7 1111 GETSHORT(cishort, p); \
simon 0:350011bf8be7 1112 /* Check rejected value. */ \
simon 0:350011bf8be7 1113 if (cishort != val) { \
simon 0:350011bf8be7 1114 goto bad; \
simon 0:350011bf8be7 1115 } \
simon 0:350011bf8be7 1116 try.neg = 0; \
simon 0:350011bf8be7 1117 LCPDEBUG(LOG_INFO, ("lcp_rejci: short opt %d rejected\n", opt)); \
simon 0:350011bf8be7 1118 }
simon 0:350011bf8be7 1119 #define REJCICHAP(opt, neg, val, digest) \
simon 0:350011bf8be7 1120 if (go->neg && \
simon 0:350011bf8be7 1121 len >= CILEN_CHAP && \
simon 0:350011bf8be7 1122 p[1] == CILEN_CHAP && \
simon 0:350011bf8be7 1123 p[0] == opt) { \
simon 0:350011bf8be7 1124 len -= CILEN_CHAP; \
simon 0:350011bf8be7 1125 INCPTR(2, p); \
simon 0:350011bf8be7 1126 GETSHORT(cishort, p); \
simon 0:350011bf8be7 1127 GETCHAR(cichar, p); \
simon 0:350011bf8be7 1128 /* Check rejected value. */ \
simon 0:350011bf8be7 1129 if (cishort != val || cichar != digest) { \
simon 0:350011bf8be7 1130 goto bad; \
simon 0:350011bf8be7 1131 } \
simon 0:350011bf8be7 1132 try.neg = 0; \
simon 0:350011bf8be7 1133 try.neg_upap = 0; \
simon 0:350011bf8be7 1134 LCPDEBUG(LOG_INFO, ("lcp_rejci: chap opt %d rejected\n", opt)); \
simon 0:350011bf8be7 1135 }
simon 0:350011bf8be7 1136 #define REJCILONG(opt, neg, val) \
simon 0:350011bf8be7 1137 if (go->neg && \
simon 0:350011bf8be7 1138 len >= CILEN_LONG && \
simon 0:350011bf8be7 1139 p[1] == CILEN_LONG && \
simon 0:350011bf8be7 1140 p[0] == opt) { \
simon 0:350011bf8be7 1141 len -= CILEN_LONG; \
simon 0:350011bf8be7 1142 INCPTR(2, p); \
simon 0:350011bf8be7 1143 GETLONG(cilong, p); \
simon 0:350011bf8be7 1144 /* Check rejected value. */ \
simon 0:350011bf8be7 1145 if (cilong != val) { \
simon 0:350011bf8be7 1146 goto bad; \
simon 0:350011bf8be7 1147 } \
simon 0:350011bf8be7 1148 try.neg = 0; \
simon 0:350011bf8be7 1149 LCPDEBUG(LOG_INFO, ("lcp_rejci: long opt %d rejected\n", opt)); \
simon 0:350011bf8be7 1150 }
simon 0:350011bf8be7 1151 #define REJCILQR(opt, neg, val) \
simon 0:350011bf8be7 1152 if (go->neg && \
simon 0:350011bf8be7 1153 len >= CILEN_LQR && \
simon 0:350011bf8be7 1154 p[1] == CILEN_LQR && \
simon 0:350011bf8be7 1155 p[0] == opt) { \
simon 0:350011bf8be7 1156 len -= CILEN_LQR; \
simon 0:350011bf8be7 1157 INCPTR(2, p); \
simon 0:350011bf8be7 1158 GETSHORT(cishort, p); \
simon 0:350011bf8be7 1159 GETLONG(cilong, p); \
simon 0:350011bf8be7 1160 /* Check rejected value. */ \
simon 0:350011bf8be7 1161 if (cishort != PPP_LQR || cilong != val) { \
simon 0:350011bf8be7 1162 goto bad; \
simon 0:350011bf8be7 1163 } \
simon 0:350011bf8be7 1164 try.neg = 0; \
simon 0:350011bf8be7 1165 LCPDEBUG(LOG_INFO, ("lcp_rejci: LQR opt %d rejected\n", opt)); \
simon 0:350011bf8be7 1166 }
simon 0:350011bf8be7 1167 #define REJCICBCP(opt, neg, val) \
simon 0:350011bf8be7 1168 if (go->neg && \
simon 0:350011bf8be7 1169 len >= CILEN_CBCP && \
simon 0:350011bf8be7 1170 p[1] == CILEN_CBCP && \
simon 0:350011bf8be7 1171 p[0] == opt) { \
simon 0:350011bf8be7 1172 len -= CILEN_CBCP; \
simon 0:350011bf8be7 1173 INCPTR(2, p); \
simon 0:350011bf8be7 1174 GETCHAR(cichar, p); \
simon 0:350011bf8be7 1175 /* Check rejected value. */ \
simon 0:350011bf8be7 1176 if (cichar != val) { \
simon 0:350011bf8be7 1177 goto bad; \
simon 0:350011bf8be7 1178 } \
simon 0:350011bf8be7 1179 try.neg = 0; \
simon 0:350011bf8be7 1180 LCPDEBUG(LOG_INFO, ("lcp_rejci: Callback opt %d rejected\n", opt)); \
simon 0:350011bf8be7 1181 }
simon 0:350011bf8be7 1182
simon 0:350011bf8be7 1183 REJCISHORT(CI_MRU, neg_mru, go->mru);
simon 0:350011bf8be7 1184 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
simon 0:350011bf8be7 1185 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
simon 0:350011bf8be7 1186 if (!go->neg_chap) {
simon 0:350011bf8be7 1187 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
simon 0:350011bf8be7 1188 }
simon 0:350011bf8be7 1189 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
simon 0:350011bf8be7 1190 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
simon 0:350011bf8be7 1191 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
simon 0:350011bf8be7 1192 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
simon 0:350011bf8be7 1193 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
simon 0:350011bf8be7 1194
simon 0:350011bf8be7 1195 /*
simon 0:350011bf8be7 1196 * If there are any remaining CIs, then this packet is bad.
simon 0:350011bf8be7 1197 */
simon 0:350011bf8be7 1198 if (len != 0) {
simon 0:350011bf8be7 1199 goto bad;
simon 0:350011bf8be7 1200 }
simon 0:350011bf8be7 1201 /*
simon 0:350011bf8be7 1202 * Now we can update state.
simon 0:350011bf8be7 1203 */
simon 0:350011bf8be7 1204 if (f->state != LS_OPENED) {
simon 0:350011bf8be7 1205 *go = try;
simon 0:350011bf8be7 1206 }
simon 0:350011bf8be7 1207 return 1;
simon 0:350011bf8be7 1208
simon 0:350011bf8be7 1209 bad:
simon 0:350011bf8be7 1210 LCPDEBUG(LOG_WARNING, ("lcp_rejci: received bad Reject!\n"));
simon 0:350011bf8be7 1211 return 0;
simon 0:350011bf8be7 1212 }
simon 0:350011bf8be7 1213
simon 0:350011bf8be7 1214
simon 0:350011bf8be7 1215 /*
simon 0:350011bf8be7 1216 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
simon 0:350011bf8be7 1217 *
simon 0:350011bf8be7 1218 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
simon 0:350011bf8be7 1219 * appropriately. If reject_if_disagree is non-zero, doesn't return
simon 0:350011bf8be7 1220 * CONFNAK; returns CONFREJ if it can't return CONFACK.
simon 0:350011bf8be7 1221 */
simon 0:350011bf8be7 1222 static int
simon 0:350011bf8be7 1223 lcp_reqci(fsm *f,
simon 0:350011bf8be7 1224 u_char *inp, /* Requested CIs */
simon 0:350011bf8be7 1225 int *lenp, /* Length of requested CIs */
simon 0:350011bf8be7 1226 int reject_if_disagree)
simon 0:350011bf8be7 1227 {
simon 0:350011bf8be7 1228 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 1229 lcp_options *ho = &lcp_hisoptions[f->unit];
simon 0:350011bf8be7 1230 lcp_options *ao = &lcp_allowoptions[f->unit];
simon 0:350011bf8be7 1231 u_char *cip, *next; /* Pointer to current and next CIs */
simon 0:350011bf8be7 1232 int cilen, citype; /* Parsed len, type */
simon 0:350011bf8be7 1233 u_char cichar; /* Parsed char value */
simon 0:350011bf8be7 1234 u_short cishort; /* Parsed short value */
simon 0:350011bf8be7 1235 u32_t cilong; /* Parse long value */
simon 0:350011bf8be7 1236 int rc = CONFACK; /* Final packet return code */
simon 0:350011bf8be7 1237 int orc; /* Individual option return code */
simon 0:350011bf8be7 1238 u_char *p; /* Pointer to next char to parse */
simon 0:350011bf8be7 1239 u_char *rejp; /* Pointer to next char in reject frame */
simon 0:350011bf8be7 1240 u_char *nakp; /* Pointer to next char in Nak frame */
simon 0:350011bf8be7 1241 int l = *lenp; /* Length left */
simon 0:350011bf8be7 1242 #if TRACELCP > 0
simon 0:350011bf8be7 1243 char traceBuf[80];
simon 0:350011bf8be7 1244 size_t traceNdx = 0;
simon 0:350011bf8be7 1245 #endif
simon 0:350011bf8be7 1246
simon 0:350011bf8be7 1247 /*
simon 0:350011bf8be7 1248 * Reset all his options.
simon 0:350011bf8be7 1249 */
simon 0:350011bf8be7 1250 BZERO(ho, sizeof(*ho));
simon 0:350011bf8be7 1251
simon 0:350011bf8be7 1252 /*
simon 0:350011bf8be7 1253 * Process all his options.
simon 0:350011bf8be7 1254 */
simon 0:350011bf8be7 1255 next = inp;
simon 0:350011bf8be7 1256 nakp = nak_buffer;
simon 0:350011bf8be7 1257 rejp = inp;
simon 0:350011bf8be7 1258 while (l) {
simon 0:350011bf8be7 1259 orc = CONFACK; /* Assume success */
simon 0:350011bf8be7 1260 cip = p = next; /* Remember begining of CI */
simon 0:350011bf8be7 1261 if (l < 2 || /* Not enough data for CI header or */
simon 0:350011bf8be7 1262 p[1] < 2 || /* CI length too small or */
simon 0:350011bf8be7 1263 p[1] > l) { /* CI length too big? */
simon 0:350011bf8be7 1264 LCPDEBUG(LOG_WARNING, ("lcp_reqci: bad CI length!\n"));
simon 0:350011bf8be7 1265 orc = CONFREJ; /* Reject bad CI */
simon 0:350011bf8be7 1266 cilen = l; /* Reject till end of packet */
simon 0:350011bf8be7 1267 l = 0; /* Don't loop again */
simon 0:350011bf8be7 1268 citype = 0;
simon 0:350011bf8be7 1269 goto endswitch;
simon 0:350011bf8be7 1270 }
simon 0:350011bf8be7 1271 GETCHAR(citype, p); /* Parse CI type */
simon 0:350011bf8be7 1272 GETCHAR(cilen, p); /* Parse CI length */
simon 0:350011bf8be7 1273 l -= cilen; /* Adjust remaining length */
simon 0:350011bf8be7 1274 next += cilen; /* Step to next CI */
simon 0:350011bf8be7 1275
simon 0:350011bf8be7 1276 switch (citype) { /* Check CI type */
simon 0:350011bf8be7 1277 case CI_MRU:
simon 0:350011bf8be7 1278 if (!ao->neg_mru) { /* Allow option? */
simon 0:350011bf8be7 1279 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject MRU - not allowed\n"));
simon 0:350011bf8be7 1280 orc = CONFREJ; /* Reject CI */
simon 0:350011bf8be7 1281 break;
simon 0:350011bf8be7 1282 } else if (cilen != CILEN_SHORT) { /* Check CI length */
simon 0:350011bf8be7 1283 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject MRU - bad length\n"));
simon 0:350011bf8be7 1284 orc = CONFREJ; /* Reject CI */
simon 0:350011bf8be7 1285 break;
simon 0:350011bf8be7 1286 }
simon 0:350011bf8be7 1287 GETSHORT(cishort, p); /* Parse MRU */
simon 0:350011bf8be7 1288
simon 0:350011bf8be7 1289 /*
simon 0:350011bf8be7 1290 * He must be able to receive at least our minimum.
simon 0:350011bf8be7 1291 * No need to check a maximum. If he sends a large number,
simon 0:350011bf8be7 1292 * we'll just ignore it.
simon 0:350011bf8be7 1293 */
simon 0:350011bf8be7 1294 if (cishort < PPP_MINMRU) {
simon 0:350011bf8be7 1295 LCPDEBUG(LOG_INFO, ("lcp_reqci: Nak - MRU too small\n"));
simon 0:350011bf8be7 1296 orc = CONFNAK; /* Nak CI */
simon 0:350011bf8be7 1297 PUTCHAR(CI_MRU, nakp);
simon 0:350011bf8be7 1298 PUTCHAR(CILEN_SHORT, nakp);
simon 0:350011bf8be7 1299 PUTSHORT(PPP_MINMRU, nakp); /* Give him a hint */
simon 0:350011bf8be7 1300 break;
simon 0:350011bf8be7 1301 }
simon 0:350011bf8be7 1302 ho->neg_mru = 1; /* Remember he sent MRU */
simon 0:350011bf8be7 1303 ho->mru = cishort; /* And remember value */
simon 0:350011bf8be7 1304 #if TRACELCP > 0
simon 0:350011bf8be7 1305 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " MRU %d", cishort);
simon 0:350011bf8be7 1306 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1307 #endif
simon 0:350011bf8be7 1308 break;
simon 0:350011bf8be7 1309
simon 0:350011bf8be7 1310 case CI_ASYNCMAP:
simon 0:350011bf8be7 1311 if (!ao->neg_asyncmap) {
simon 0:350011bf8be7 1312 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject ASYNCMAP not allowed\n"));
simon 0:350011bf8be7 1313 orc = CONFREJ;
simon 0:350011bf8be7 1314 break;
simon 0:350011bf8be7 1315 } else if (cilen != CILEN_LONG) {
simon 0:350011bf8be7 1316 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject ASYNCMAP bad length\n"));
simon 0:350011bf8be7 1317 orc = CONFREJ;
simon 0:350011bf8be7 1318 break;
simon 0:350011bf8be7 1319 }
simon 0:350011bf8be7 1320 GETLONG(cilong, p);
simon 0:350011bf8be7 1321
simon 0:350011bf8be7 1322 /*
simon 0:350011bf8be7 1323 * Asyncmap must have set at least the bits
simon 0:350011bf8be7 1324 * which are set in lcp_allowoptions[unit].asyncmap.
simon 0:350011bf8be7 1325 */
simon 0:350011bf8be7 1326 if ((ao->asyncmap & ~cilong) != 0) {
simon 0:350011bf8be7 1327 LCPDEBUG(LOG_INFO, ("lcp_reqci: Nak ASYNCMAP %lX missing %lX\n",
simon 0:350011bf8be7 1328 cilong, ao->asyncmap));
simon 0:350011bf8be7 1329 orc = CONFNAK;
simon 0:350011bf8be7 1330 PUTCHAR(CI_ASYNCMAP, nakp);
simon 0:350011bf8be7 1331 PUTCHAR(CILEN_LONG, nakp);
simon 0:350011bf8be7 1332 PUTLONG(ao->asyncmap | cilong, nakp);
simon 0:350011bf8be7 1333 break;
simon 0:350011bf8be7 1334 }
simon 0:350011bf8be7 1335 ho->neg_asyncmap = 1;
simon 0:350011bf8be7 1336 ho->asyncmap = cilong;
simon 0:350011bf8be7 1337 #if TRACELCP > 0
simon 0:350011bf8be7 1338 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " ASYNCMAP=%lX", cilong);
simon 0:350011bf8be7 1339 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1340 #endif
simon 0:350011bf8be7 1341 break;
simon 0:350011bf8be7 1342
simon 0:350011bf8be7 1343 case CI_AUTHTYPE:
simon 0:350011bf8be7 1344 if (cilen < CILEN_SHORT) {
simon 0:350011bf8be7 1345 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject AUTHTYPE missing arg\n"));
simon 0:350011bf8be7 1346 orc = CONFREJ;
simon 0:350011bf8be7 1347 break;
simon 0:350011bf8be7 1348 } else if (!(ao->neg_upap || ao->neg_chap)) {
simon 0:350011bf8be7 1349 /*
simon 0:350011bf8be7 1350 * Reject the option if we're not willing to authenticate.
simon 0:350011bf8be7 1351 */
simon 0:350011bf8be7 1352 LCPDEBUG(LOG_INFO, ("lcp_reqci: Reject AUTHTYPE not allowed\n"));
simon 0:350011bf8be7 1353 orc = CONFREJ;
simon 0:350011bf8be7 1354 break;
simon 0:350011bf8be7 1355 }
simon 0:350011bf8be7 1356 GETSHORT(cishort, p);
simon 0:350011bf8be7 1357
simon 0:350011bf8be7 1358 /*
simon 0:350011bf8be7 1359 * Authtype must be UPAP or CHAP.
simon 0:350011bf8be7 1360 *
simon 0:350011bf8be7 1361 * Note: if both ao->neg_upap and ao->neg_chap are set,
simon 0:350011bf8be7 1362 * and the peer sends a Configure-Request with two
simon 0:350011bf8be7 1363 * authenticate-protocol requests, one for CHAP and one
simon 0:350011bf8be7 1364 * for UPAP, then we will reject the second request.
simon 0:350011bf8be7 1365 * Whether we end up doing CHAP or UPAP depends then on
simon 0:350011bf8be7 1366 * the ordering of the CIs in the peer's Configure-Request.
simon 0:350011bf8be7 1367 */
simon 0:350011bf8be7 1368
simon 0:350011bf8be7 1369 if (cishort == PPP_PAP) {
simon 0:350011bf8be7 1370 if (ho->neg_chap) { /* we've already accepted CHAP */
simon 0:350011bf8be7 1371 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE PAP already accepted\n"));
simon 0:350011bf8be7 1372 orc = CONFREJ;
simon 0:350011bf8be7 1373 break;
simon 0:350011bf8be7 1374 } else if (cilen != CILEN_SHORT) {
simon 0:350011bf8be7 1375 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE PAP bad len\n"));
simon 0:350011bf8be7 1376 orc = CONFREJ;
simon 0:350011bf8be7 1377 break;
simon 0:350011bf8be7 1378 }
simon 0:350011bf8be7 1379 if (!ao->neg_upap) { /* we don't want to do PAP */
simon 0:350011bf8be7 1380 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE PAP not allowed\n"));
simon 0:350011bf8be7 1381 orc = CONFNAK; /* NAK it and suggest CHAP */
simon 0:350011bf8be7 1382 PUTCHAR(CI_AUTHTYPE, nakp);
simon 0:350011bf8be7 1383 PUTCHAR(CILEN_CHAP, nakp);
simon 0:350011bf8be7 1384 PUTSHORT(PPP_CHAP, nakp);
simon 0:350011bf8be7 1385 PUTCHAR(ao->chap_mdtype, nakp);
simon 0:350011bf8be7 1386 break;
simon 0:350011bf8be7 1387 }
simon 0:350011bf8be7 1388 ho->neg_upap = 1;
simon 0:350011bf8be7 1389 #if TRACELCP > 0
simon 0:350011bf8be7 1390 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " PAP (%X)", cishort);
simon 0:350011bf8be7 1391 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1392 #endif
simon 0:350011bf8be7 1393 break;
simon 0:350011bf8be7 1394 }
simon 0:350011bf8be7 1395 if (cishort == PPP_CHAP) {
simon 0:350011bf8be7 1396 if (ho->neg_upap) { /* we've already accepted PAP */
simon 0:350011bf8be7 1397 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE CHAP accepted PAP\n"));
simon 0:350011bf8be7 1398 orc = CONFREJ;
simon 0:350011bf8be7 1399 break;
simon 0:350011bf8be7 1400 } else if (cilen != CILEN_CHAP) {
simon 0:350011bf8be7 1401 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Reject AUTHTYPE CHAP bad len\n"));
simon 0:350011bf8be7 1402 orc = CONFREJ;
simon 0:350011bf8be7 1403 break;
simon 0:350011bf8be7 1404 }
simon 0:350011bf8be7 1405 if (!ao->neg_chap) { /* we don't want to do CHAP */
simon 0:350011bf8be7 1406 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE CHAP not allowed\n"));
simon 0:350011bf8be7 1407 orc = CONFNAK; /* NAK it and suggest PAP */
simon 0:350011bf8be7 1408 PUTCHAR(CI_AUTHTYPE, nakp);
simon 0:350011bf8be7 1409 PUTCHAR(CILEN_SHORT, nakp);
simon 0:350011bf8be7 1410 PUTSHORT(PPP_PAP, nakp);
simon 0:350011bf8be7 1411 break;
simon 0:350011bf8be7 1412 }
simon 0:350011bf8be7 1413 GETCHAR(cichar, p); /* get digest type*/
simon 0:350011bf8be7 1414 if (cichar != CHAP_DIGEST_MD5
simon 0:350011bf8be7 1415 #if MSCHAP_SUPPORT
simon 0:350011bf8be7 1416 && cichar != CHAP_MICROSOFT
simon 0:350011bf8be7 1417 #endif
simon 0:350011bf8be7 1418 ) {
simon 0:350011bf8be7 1419 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE CHAP digest=%d\n", (int)cichar));
simon 0:350011bf8be7 1420 orc = CONFNAK;
simon 0:350011bf8be7 1421 PUTCHAR(CI_AUTHTYPE, nakp);
simon 0:350011bf8be7 1422 PUTCHAR(CILEN_CHAP, nakp);
simon 0:350011bf8be7 1423 PUTSHORT(PPP_CHAP, nakp);
simon 0:350011bf8be7 1424 PUTCHAR(ao->chap_mdtype, nakp);
simon 0:350011bf8be7 1425 break;
simon 0:350011bf8be7 1426 }
simon 0:350011bf8be7 1427 #if TRACELCP > 0
simon 0:350011bf8be7 1428 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CHAP %X,%d", cishort, (int)cichar);
simon 0:350011bf8be7 1429 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1430 #endif
simon 0:350011bf8be7 1431 ho->chap_mdtype = cichar; /* save md type */
simon 0:350011bf8be7 1432 ho->neg_chap = 1;
simon 0:350011bf8be7 1433 break;
simon 0:350011bf8be7 1434 }
simon 0:350011bf8be7 1435
simon 0:350011bf8be7 1436 /*
simon 0:350011bf8be7 1437 * We don't recognize the protocol they're asking for.
simon 0:350011bf8be7 1438 * Nak it with something we're willing to do.
simon 0:350011bf8be7 1439 * (At this point we know ao->neg_upap || ao->neg_chap.)
simon 0:350011bf8be7 1440 */
simon 0:350011bf8be7 1441 orc = CONFNAK;
simon 0:350011bf8be7 1442 PUTCHAR(CI_AUTHTYPE, nakp);
simon 0:350011bf8be7 1443 if (ao->neg_chap) {
simon 0:350011bf8be7 1444 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE %d req CHAP\n", cishort));
simon 0:350011bf8be7 1445 PUTCHAR(CILEN_CHAP, nakp);
simon 0:350011bf8be7 1446 PUTSHORT(PPP_CHAP, nakp);
simon 0:350011bf8be7 1447 PUTCHAR(ao->chap_mdtype, nakp);
simon 0:350011bf8be7 1448 } else {
simon 0:350011bf8be7 1449 LCPDEBUG(LOG_WARNING, ("lcp_reqci: Nak AUTHTYPE %d req PAP\n", cishort));
simon 0:350011bf8be7 1450 PUTCHAR(CILEN_SHORT, nakp);
simon 0:350011bf8be7 1451 PUTSHORT(PPP_PAP, nakp);
simon 0:350011bf8be7 1452 }
simon 0:350011bf8be7 1453 break;
simon 0:350011bf8be7 1454
simon 0:350011bf8be7 1455 case CI_QUALITY:
simon 0:350011bf8be7 1456 GETSHORT(cishort, p);
simon 0:350011bf8be7 1457 GETLONG(cilong, p);
simon 0:350011bf8be7 1458 #if TRACELCP > 0
simon 0:350011bf8be7 1459 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " QUALITY (%x %x)", cishort, (unsigned int) cilong);
simon 0:350011bf8be7 1460 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1461 #endif
simon 0:350011bf8be7 1462
simon 0:350011bf8be7 1463 if (!ao->neg_lqr ||
simon 0:350011bf8be7 1464 cilen != CILEN_LQR) {
simon 0:350011bf8be7 1465 orc = CONFREJ;
simon 0:350011bf8be7 1466 break;
simon 0:350011bf8be7 1467 }
simon 0:350011bf8be7 1468
simon 0:350011bf8be7 1469 /*
simon 0:350011bf8be7 1470 * Check the protocol and the reporting period.
simon 0:350011bf8be7 1471 * XXX When should we Nak this, and what with?
simon 0:350011bf8be7 1472 */
simon 0:350011bf8be7 1473 if (cishort != PPP_LQR) {
simon 0:350011bf8be7 1474 orc = CONFNAK;
simon 0:350011bf8be7 1475 PUTCHAR(CI_QUALITY, nakp);
simon 0:350011bf8be7 1476 PUTCHAR(CILEN_LQR, nakp);
simon 0:350011bf8be7 1477 PUTSHORT(PPP_LQR, nakp);
simon 0:350011bf8be7 1478 PUTLONG(ao->lqr_period, nakp);
simon 0:350011bf8be7 1479 break;
simon 0:350011bf8be7 1480 }
simon 0:350011bf8be7 1481 break;
simon 0:350011bf8be7 1482
simon 0:350011bf8be7 1483 case CI_MAGICNUMBER:
simon 0:350011bf8be7 1484 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
simon 0:350011bf8be7 1485 cilen != CILEN_LONG) {
simon 0:350011bf8be7 1486 orc = CONFREJ;
simon 0:350011bf8be7 1487 break;
simon 0:350011bf8be7 1488 }
simon 0:350011bf8be7 1489 GETLONG(cilong, p);
simon 0:350011bf8be7 1490 #if TRACELCP > 0
simon 0:350011bf8be7 1491 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " MAGICNUMBER (%lX)", cilong);
simon 0:350011bf8be7 1492 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1493 #endif
simon 0:350011bf8be7 1494
simon 0:350011bf8be7 1495 /*
simon 0:350011bf8be7 1496 * He must have a different magic number.
simon 0:350011bf8be7 1497 */
simon 0:350011bf8be7 1498 if (go->neg_magicnumber &&
simon 0:350011bf8be7 1499 cilong == go->magicnumber) {
simon 0:350011bf8be7 1500 cilong = magic(); /* Don't put magic() inside macro! */
simon 0:350011bf8be7 1501 orc = CONFNAK;
simon 0:350011bf8be7 1502 PUTCHAR(CI_MAGICNUMBER, nakp);
simon 0:350011bf8be7 1503 PUTCHAR(CILEN_LONG, nakp);
simon 0:350011bf8be7 1504 PUTLONG(cilong, nakp);
simon 0:350011bf8be7 1505 break;
simon 0:350011bf8be7 1506 }
simon 0:350011bf8be7 1507 ho->neg_magicnumber = 1;
simon 0:350011bf8be7 1508 ho->magicnumber = cilong;
simon 0:350011bf8be7 1509 break;
simon 0:350011bf8be7 1510
simon 0:350011bf8be7 1511
simon 0:350011bf8be7 1512 case CI_PCOMPRESSION:
simon 0:350011bf8be7 1513 #if TRACELCP > 0
simon 0:350011bf8be7 1514 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " PCOMPRESSION");
simon 0:350011bf8be7 1515 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1516 #endif
simon 0:350011bf8be7 1517 if (!ao->neg_pcompression ||
simon 0:350011bf8be7 1518 cilen != CILEN_VOID) {
simon 0:350011bf8be7 1519 orc = CONFREJ;
simon 0:350011bf8be7 1520 break;
simon 0:350011bf8be7 1521 }
simon 0:350011bf8be7 1522 ho->neg_pcompression = 1;
simon 0:350011bf8be7 1523 break;
simon 0:350011bf8be7 1524
simon 0:350011bf8be7 1525 case CI_ACCOMPRESSION:
simon 0:350011bf8be7 1526 #if TRACELCP > 0
simon 0:350011bf8be7 1527 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " ACCOMPRESSION");
simon 0:350011bf8be7 1528 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1529 #endif
simon 0:350011bf8be7 1530 if (!ao->neg_accompression ||
simon 0:350011bf8be7 1531 cilen != CILEN_VOID) {
simon 0:350011bf8be7 1532 orc = CONFREJ;
simon 0:350011bf8be7 1533 break;
simon 0:350011bf8be7 1534 }
simon 0:350011bf8be7 1535 ho->neg_accompression = 1;
simon 0:350011bf8be7 1536 break;
simon 0:350011bf8be7 1537
simon 0:350011bf8be7 1538 case CI_MRRU:
simon 0:350011bf8be7 1539 #if TRACELCP > 0
simon 0:350011bf8be7 1540 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_MRRU");
simon 0:350011bf8be7 1541 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1542 #endif
simon 0:350011bf8be7 1543 orc = CONFREJ;
simon 0:350011bf8be7 1544 break;
simon 0:350011bf8be7 1545
simon 0:350011bf8be7 1546 case CI_SSNHF:
simon 0:350011bf8be7 1547 #if TRACELCP > 0
simon 0:350011bf8be7 1548 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_SSNHF");
simon 0:350011bf8be7 1549 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1550 #endif
simon 0:350011bf8be7 1551 orc = CONFREJ;
simon 0:350011bf8be7 1552 break;
simon 0:350011bf8be7 1553
simon 0:350011bf8be7 1554 case CI_EPDISC:
simon 0:350011bf8be7 1555 #if TRACELCP > 0
simon 0:350011bf8be7 1556 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_EPDISC");
simon 0:350011bf8be7 1557 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1558 #endif
simon 0:350011bf8be7 1559 orc = CONFREJ;
simon 0:350011bf8be7 1560 break;
simon 0:350011bf8be7 1561
simon 0:350011bf8be7 1562 default:
simon 0:350011bf8be7 1563 #if TRACELCP
simon 0:350011bf8be7 1564 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " unknown %d", citype);
simon 0:350011bf8be7 1565 traceNdx = strlen(traceBuf);
simon 0:350011bf8be7 1566 #endif
simon 0:350011bf8be7 1567 orc = CONFREJ;
simon 0:350011bf8be7 1568 break;
simon 0:350011bf8be7 1569 }
simon 0:350011bf8be7 1570
simon 0:350011bf8be7 1571 endswitch:
simon 0:350011bf8be7 1572 #if TRACELCP
simon 0:350011bf8be7 1573 if (traceNdx >= 80 - 32) {
simon 0:350011bf8be7 1574 LCPDEBUG(LOG_INFO, ("lcp_reqci: rcvd%s\n", traceBuf));
simon 0:350011bf8be7 1575 traceNdx = 0;
simon 0:350011bf8be7 1576 }
simon 0:350011bf8be7 1577 #endif
simon 0:350011bf8be7 1578 if (orc == CONFACK && /* Good CI */
simon 0:350011bf8be7 1579 rc != CONFACK) { /* but prior CI wasnt? */
simon 0:350011bf8be7 1580 continue; /* Don't send this one */
simon 0:350011bf8be7 1581 }
simon 0:350011bf8be7 1582
simon 0:350011bf8be7 1583 if (orc == CONFNAK) { /* Nak this CI? */
simon 0:350011bf8be7 1584 if (reject_if_disagree /* Getting fed up with sending NAKs? */
simon 0:350011bf8be7 1585 && citype != CI_MAGICNUMBER) {
simon 0:350011bf8be7 1586 orc = CONFREJ; /* Get tough if so */
simon 0:350011bf8be7 1587 } else {
simon 0:350011bf8be7 1588 if (rc == CONFREJ) { /* Rejecting prior CI? */
simon 0:350011bf8be7 1589 continue; /* Don't send this one */
simon 0:350011bf8be7 1590 }
simon 0:350011bf8be7 1591 rc = CONFNAK;
simon 0:350011bf8be7 1592 }
simon 0:350011bf8be7 1593 }
simon 0:350011bf8be7 1594 if (orc == CONFREJ) { /* Reject this CI */
simon 0:350011bf8be7 1595 rc = CONFREJ;
simon 0:350011bf8be7 1596 if (cip != rejp) { /* Need to move rejected CI? */
simon 0:350011bf8be7 1597 BCOPY(cip, rejp, cilen); /* Move it */
simon 0:350011bf8be7 1598 }
simon 0:350011bf8be7 1599 INCPTR(cilen, rejp); /* Update output pointer */
simon 0:350011bf8be7 1600 }
simon 0:350011bf8be7 1601 }
simon 0:350011bf8be7 1602
simon 0:350011bf8be7 1603 /*
simon 0:350011bf8be7 1604 * If we wanted to send additional NAKs (for unsent CIs), the
simon 0:350011bf8be7 1605 * code would go here. The extra NAKs would go at *nakp.
simon 0:350011bf8be7 1606 * At present there are no cases where we want to ask the
simon 0:350011bf8be7 1607 * peer to negotiate an option.
simon 0:350011bf8be7 1608 */
simon 0:350011bf8be7 1609
simon 0:350011bf8be7 1610 switch (rc) {
simon 0:350011bf8be7 1611 case CONFACK:
simon 0:350011bf8be7 1612 *lenp = (int)(next - inp);
simon 0:350011bf8be7 1613 break;
simon 0:350011bf8be7 1614 case CONFNAK:
simon 0:350011bf8be7 1615 /*
simon 0:350011bf8be7 1616 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
simon 0:350011bf8be7 1617 */
simon 0:350011bf8be7 1618 *lenp = (int)(nakp - nak_buffer);
simon 0:350011bf8be7 1619 BCOPY(nak_buffer, inp, *lenp);
simon 0:350011bf8be7 1620 break;
simon 0:350011bf8be7 1621 case CONFREJ:
simon 0:350011bf8be7 1622 *lenp = (int)(rejp - inp);
simon 0:350011bf8be7 1623 break;
simon 0:350011bf8be7 1624 }
simon 0:350011bf8be7 1625
simon 0:350011bf8be7 1626 #if TRACELCP > 0
simon 0:350011bf8be7 1627 if (traceNdx > 0) {
simon 0:350011bf8be7 1628 LCPDEBUG(LOG_INFO, ("lcp_reqci: %s\n", traceBuf));
simon 0:350011bf8be7 1629 }
simon 0:350011bf8be7 1630 #endif
simon 0:350011bf8be7 1631 LCPDEBUG(LOG_INFO, ("lcp_reqci: returning CONF%s.\n", CODENAME(rc)));
simon 0:350011bf8be7 1632 return (rc); /* Return final code */
simon 0:350011bf8be7 1633 }
simon 0:350011bf8be7 1634
simon 0:350011bf8be7 1635
simon 0:350011bf8be7 1636 /*
simon 0:350011bf8be7 1637 * lcp_up - LCP has come UP.
simon 0:350011bf8be7 1638 */
simon 0:350011bf8be7 1639 static void
simon 0:350011bf8be7 1640 lcp_up(fsm *f)
simon 0:350011bf8be7 1641 {
simon 0:350011bf8be7 1642 lcp_options *wo = &lcp_wantoptions[f->unit];
simon 0:350011bf8be7 1643 lcp_options *ho = &lcp_hisoptions[f->unit];
simon 0:350011bf8be7 1644 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 1645 lcp_options *ao = &lcp_allowoptions[f->unit];
simon 0:350011bf8be7 1646
simon 0:350011bf8be7 1647 if (!go->neg_magicnumber) {
simon 0:350011bf8be7 1648 go->magicnumber = 0;
simon 0:350011bf8be7 1649 }
simon 0:350011bf8be7 1650 if (!ho->neg_magicnumber) {
simon 0:350011bf8be7 1651 ho->magicnumber = 0;
simon 0:350011bf8be7 1652 }
simon 0:350011bf8be7 1653
simon 0:350011bf8be7 1654 /*
simon 0:350011bf8be7 1655 * Set our MTU to the smaller of the MTU we wanted and
simon 0:350011bf8be7 1656 * the MRU our peer wanted. If we negotiated an MRU,
simon 0:350011bf8be7 1657 * set our MRU to the larger of value we wanted and
simon 0:350011bf8be7 1658 * the value we got in the negotiation.
simon 0:350011bf8be7 1659 */
simon 0:350011bf8be7 1660 ppp_send_config(f->unit, LWIP_MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
simon 0:350011bf8be7 1661 (ho->neg_asyncmap? ho->asyncmap: 0xffffffffl),
simon 0:350011bf8be7 1662 ho->neg_pcompression, ho->neg_accompression);
simon 0:350011bf8be7 1663 /*
simon 0:350011bf8be7 1664 * If the asyncmap hasn't been negotiated, we really should
simon 0:350011bf8be7 1665 * set the receive asyncmap to ffffffff, but we set it to 0
simon 0:350011bf8be7 1666 * for backwards contemptibility.
simon 0:350011bf8be7 1667 */
simon 0:350011bf8be7 1668 ppp_recv_config(f->unit, (go->neg_mru? LWIP_MAX(wo->mru, go->mru): PPP_MRU),
simon 0:350011bf8be7 1669 (go->neg_asyncmap? go->asyncmap: 0x00000000),
simon 0:350011bf8be7 1670 go->neg_pcompression, go->neg_accompression);
simon 0:350011bf8be7 1671
simon 0:350011bf8be7 1672 if (ho->neg_mru) {
simon 0:350011bf8be7 1673 peer_mru[f->unit] = ho->mru;
simon 0:350011bf8be7 1674 }
simon 0:350011bf8be7 1675
simon 0:350011bf8be7 1676 lcp_echo_lowerup(f->unit); /* Enable echo messages */
simon 0:350011bf8be7 1677
simon 0:350011bf8be7 1678 link_established(f->unit); /* The link is up; authenticate now */
simon 0:350011bf8be7 1679 }
simon 0:350011bf8be7 1680
simon 0:350011bf8be7 1681
simon 0:350011bf8be7 1682 /*
simon 0:350011bf8be7 1683 * lcp_down - LCP has gone DOWN.
simon 0:350011bf8be7 1684 *
simon 0:350011bf8be7 1685 * Alert other protocols.
simon 0:350011bf8be7 1686 */
simon 0:350011bf8be7 1687 static void
simon 0:350011bf8be7 1688 lcp_down(fsm *f)
simon 0:350011bf8be7 1689 {
simon 0:350011bf8be7 1690 lcp_options *go = &lcp_gotoptions[f->unit];
simon 0:350011bf8be7 1691
simon 0:350011bf8be7 1692 lcp_echo_lowerdown(f->unit);
simon 0:350011bf8be7 1693
simon 0:350011bf8be7 1694 link_down(f->unit);
simon 0:350011bf8be7 1695
simon 0:350011bf8be7 1696 ppp_send_config(f->unit, PPP_MRU, 0xffffffffl, 0, 0);
simon 0:350011bf8be7 1697 ppp_recv_config(f->unit, PPP_MRU,
simon 0:350011bf8be7 1698 (go->neg_asyncmap? go->asyncmap: 0x00000000),
simon 0:350011bf8be7 1699 go->neg_pcompression, go->neg_accompression);
simon 0:350011bf8be7 1700 peer_mru[f->unit] = PPP_MRU;
simon 0:350011bf8be7 1701 }
simon 0:350011bf8be7 1702
simon 0:350011bf8be7 1703
simon 0:350011bf8be7 1704 /*
simon 0:350011bf8be7 1705 * lcp_starting - LCP needs the lower layer up.
simon 0:350011bf8be7 1706 */
simon 0:350011bf8be7 1707 static void
simon 0:350011bf8be7 1708 lcp_starting(fsm *f)
simon 0:350011bf8be7 1709 {
simon 0:350011bf8be7 1710 link_required(f->unit); /* lwip: currently does nothing */
simon 0:350011bf8be7 1711 }
simon 0:350011bf8be7 1712
simon 0:350011bf8be7 1713
simon 0:350011bf8be7 1714 /*
simon 0:350011bf8be7 1715 * lcp_finished - LCP has finished with the lower layer.
simon 0:350011bf8be7 1716 */
simon 0:350011bf8be7 1717 static void
simon 0:350011bf8be7 1718 lcp_finished(fsm *f)
simon 0:350011bf8be7 1719 {
simon 0:350011bf8be7 1720 link_terminated(f->unit); /* we are finished with the link */
simon 0:350011bf8be7 1721 }
simon 0:350011bf8be7 1722
simon 0:350011bf8be7 1723
simon 0:350011bf8be7 1724 #if PPP_ADDITIONAL_CALLBACKS
simon 0:350011bf8be7 1725 /*
simon 0:350011bf8be7 1726 * print_string - print a readable representation of a string using
simon 0:350011bf8be7 1727 * printer.
simon 0:350011bf8be7 1728 */
simon 0:350011bf8be7 1729 static void
simon 0:350011bf8be7 1730 print_string( char *p, int len, void (*printer) (void *, char *, ...), void *arg)
simon 0:350011bf8be7 1731 {
simon 0:350011bf8be7 1732 int c;
simon 0:350011bf8be7 1733
simon 0:350011bf8be7 1734 printer(arg, "\"");
simon 0:350011bf8be7 1735 for (; len > 0; --len) {
simon 0:350011bf8be7 1736 c = *p++;
simon 0:350011bf8be7 1737 if (' ' <= c && c <= '~') {
simon 0:350011bf8be7 1738 if (c == '\\' || c == '"') {
simon 0:350011bf8be7 1739 printer(arg, "\\");
simon 0:350011bf8be7 1740 }
simon 0:350011bf8be7 1741 printer(arg, "%c", c);
simon 0:350011bf8be7 1742 } else {
simon 0:350011bf8be7 1743 switch (c) {
simon 0:350011bf8be7 1744 case '\n':
simon 0:350011bf8be7 1745 printer(arg, "\\n");
simon 0:350011bf8be7 1746 break;
simon 0:350011bf8be7 1747 case '\r':
simon 0:350011bf8be7 1748 printer(arg, "\\r");
simon 0:350011bf8be7 1749 break;
simon 0:350011bf8be7 1750 case '\t':
simon 0:350011bf8be7 1751 printer(arg, "\\t");
simon 0:350011bf8be7 1752 break;
simon 0:350011bf8be7 1753 default:
simon 0:350011bf8be7 1754 printer(arg, "\\%.3o", c);
simon 0:350011bf8be7 1755 }
simon 0:350011bf8be7 1756 }
simon 0:350011bf8be7 1757 }
simon 0:350011bf8be7 1758 printer(arg, "\"");
simon 0:350011bf8be7 1759 }
simon 0:350011bf8be7 1760
simon 0:350011bf8be7 1761
simon 0:350011bf8be7 1762 /*
simon 0:350011bf8be7 1763 * lcp_printpkt - print the contents of an LCP packet.
simon 0:350011bf8be7 1764 */
simon 0:350011bf8be7 1765 static char *lcp_codenames[] = {
simon 0:350011bf8be7 1766 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
simon 0:350011bf8be7 1767 "TermReq", "TermAck", "CodeRej", "ProtRej",
simon 0:350011bf8be7 1768 "EchoReq", "EchoRep", "DiscReq"
simon 0:350011bf8be7 1769 };
simon 0:350011bf8be7 1770
simon 0:350011bf8be7 1771 static int
simon 0:350011bf8be7 1772 lcp_printpkt( u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
simon 0:350011bf8be7 1773 {
simon 0:350011bf8be7 1774 int code, id, len, olen;
simon 0:350011bf8be7 1775 u_char *pstart, *optend;
simon 0:350011bf8be7 1776 u_short cishort;
simon 0:350011bf8be7 1777 u32_t cilong;
simon 0:350011bf8be7 1778
simon 0:350011bf8be7 1779 if (plen < HEADERLEN) {
simon 0:350011bf8be7 1780 return 0;
simon 0:350011bf8be7 1781 }
simon 0:350011bf8be7 1782 pstart = p;
simon 0:350011bf8be7 1783 GETCHAR(code, p);
simon 0:350011bf8be7 1784 GETCHAR(id, p);
simon 0:350011bf8be7 1785 GETSHORT(len, p);
simon 0:350011bf8be7 1786 if (len < HEADERLEN || len > plen) {
simon 0:350011bf8be7 1787 return 0;
simon 0:350011bf8be7 1788 }
simon 0:350011bf8be7 1789
simon 0:350011bf8be7 1790 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *)) {
simon 0:350011bf8be7 1791 printer(arg, " %s", lcp_codenames[code-1]);
simon 0:350011bf8be7 1792 } else {
simon 0:350011bf8be7 1793 printer(arg, " code=0x%x", code);
simon 0:350011bf8be7 1794 }
simon 0:350011bf8be7 1795 printer(arg, " id=0x%x", id);
simon 0:350011bf8be7 1796 len -= HEADERLEN;
simon 0:350011bf8be7 1797 switch (code) {
simon 0:350011bf8be7 1798 case CONFREQ:
simon 0:350011bf8be7 1799 case CONFACK:
simon 0:350011bf8be7 1800 case CONFNAK:
simon 0:350011bf8be7 1801 case CONFREJ:
simon 0:350011bf8be7 1802 /* print option list */
simon 0:350011bf8be7 1803 while (len >= 2) {
simon 0:350011bf8be7 1804 GETCHAR(code, p);
simon 0:350011bf8be7 1805 GETCHAR(olen, p);
simon 0:350011bf8be7 1806 p -= 2;
simon 0:350011bf8be7 1807 if (olen < 2 || olen > len) {
simon 0:350011bf8be7 1808 break;
simon 0:350011bf8be7 1809 }
simon 0:350011bf8be7 1810 printer(arg, " <");
simon 0:350011bf8be7 1811 len -= olen;
simon 0:350011bf8be7 1812 optend = p + olen;
simon 0:350011bf8be7 1813 switch (code) {
simon 0:350011bf8be7 1814 case CI_MRU:
simon 0:350011bf8be7 1815 if (olen == CILEN_SHORT) {
simon 0:350011bf8be7 1816 p += 2;
simon 0:350011bf8be7 1817 GETSHORT(cishort, p);
simon 0:350011bf8be7 1818 printer(arg, "mru %d", cishort);
simon 0:350011bf8be7 1819 }
simon 0:350011bf8be7 1820 break;
simon 0:350011bf8be7 1821 case CI_ASYNCMAP:
simon 0:350011bf8be7 1822 if (olen == CILEN_LONG) {
simon 0:350011bf8be7 1823 p += 2;
simon 0:350011bf8be7 1824 GETLONG(cilong, p);
simon 0:350011bf8be7 1825 printer(arg, "asyncmap 0x%lx", cilong);
simon 0:350011bf8be7 1826 }
simon 0:350011bf8be7 1827 break;
simon 0:350011bf8be7 1828 case CI_AUTHTYPE:
simon 0:350011bf8be7 1829 if (olen >= CILEN_SHORT) {
simon 0:350011bf8be7 1830 p += 2;
simon 0:350011bf8be7 1831 printer(arg, "auth ");
simon 0:350011bf8be7 1832 GETSHORT(cishort, p);
simon 0:350011bf8be7 1833 switch (cishort) {
simon 0:350011bf8be7 1834 case PPP_PAP:
simon 0:350011bf8be7 1835 printer(arg, "pap");
simon 0:350011bf8be7 1836 break;
simon 0:350011bf8be7 1837 case PPP_CHAP:
simon 0:350011bf8be7 1838 printer(arg, "chap");
simon 0:350011bf8be7 1839 break;
simon 0:350011bf8be7 1840 default:
simon 0:350011bf8be7 1841 printer(arg, "0x%x", cishort);
simon 0:350011bf8be7 1842 }
simon 0:350011bf8be7 1843 }
simon 0:350011bf8be7 1844 break;
simon 0:350011bf8be7 1845 case CI_QUALITY:
simon 0:350011bf8be7 1846 if (olen >= CILEN_SHORT) {
simon 0:350011bf8be7 1847 p += 2;
simon 0:350011bf8be7 1848 printer(arg, "quality ");
simon 0:350011bf8be7 1849 GETSHORT(cishort, p);
simon 0:350011bf8be7 1850 switch (cishort) {
simon 0:350011bf8be7 1851 case PPP_LQR:
simon 0:350011bf8be7 1852 printer(arg, "lqr");
simon 0:350011bf8be7 1853 break;
simon 0:350011bf8be7 1854 default:
simon 0:350011bf8be7 1855 printer(arg, "0x%x", cishort);
simon 0:350011bf8be7 1856 }
simon 0:350011bf8be7 1857 }
simon 0:350011bf8be7 1858 break;
simon 0:350011bf8be7 1859 case CI_CALLBACK:
simon 0:350011bf8be7 1860 if (olen >= CILEN_CHAR) {
simon 0:350011bf8be7 1861 p += 2;
simon 0:350011bf8be7 1862 printer(arg, "callback ");
simon 0:350011bf8be7 1863 GETSHORT(cishort, p);
simon 0:350011bf8be7 1864 switch (cishort) {
simon 0:350011bf8be7 1865 case CBCP_OPT:
simon 0:350011bf8be7 1866 printer(arg, "CBCP");
simon 0:350011bf8be7 1867 break;
simon 0:350011bf8be7 1868 default:
simon 0:350011bf8be7 1869 printer(arg, "0x%x", cishort);
simon 0:350011bf8be7 1870 }
simon 0:350011bf8be7 1871 }
simon 0:350011bf8be7 1872 break;
simon 0:350011bf8be7 1873 case CI_MAGICNUMBER:
simon 0:350011bf8be7 1874 if (olen == CILEN_LONG) {
simon 0:350011bf8be7 1875 p += 2;
simon 0:350011bf8be7 1876 GETLONG(cilong, p);
simon 0:350011bf8be7 1877 printer(arg, "magic 0x%x", cilong);
simon 0:350011bf8be7 1878 }
simon 0:350011bf8be7 1879 break;
simon 0:350011bf8be7 1880 case CI_PCOMPRESSION:
simon 0:350011bf8be7 1881 if (olen == CILEN_VOID) {
simon 0:350011bf8be7 1882 p += 2;
simon 0:350011bf8be7 1883 printer(arg, "pcomp");
simon 0:350011bf8be7 1884 }
simon 0:350011bf8be7 1885 break;
simon 0:350011bf8be7 1886 case CI_ACCOMPRESSION:
simon 0:350011bf8be7 1887 if (olen == CILEN_VOID) {
simon 0:350011bf8be7 1888 p += 2;
simon 0:350011bf8be7 1889 printer(arg, "accomp");
simon 0:350011bf8be7 1890 }
simon 0:350011bf8be7 1891 break;
simon 0:350011bf8be7 1892 }
simon 0:350011bf8be7 1893 while (p < optend) {
simon 0:350011bf8be7 1894 GETCHAR(code, p);
simon 0:350011bf8be7 1895 printer(arg, " %.2x", code);
simon 0:350011bf8be7 1896 }
simon 0:350011bf8be7 1897 printer(arg, ">");
simon 0:350011bf8be7 1898 }
simon 0:350011bf8be7 1899 break;
simon 0:350011bf8be7 1900
simon 0:350011bf8be7 1901 case TERMACK:
simon 0:350011bf8be7 1902 case TERMREQ:
simon 0:350011bf8be7 1903 if (len > 0 && *p >= ' ' && *p < 0x7f) {
simon 0:350011bf8be7 1904 printer(arg, " ");
simon 0:350011bf8be7 1905 print_string((char*)p, len, printer, arg);
simon 0:350011bf8be7 1906 p += len;
simon 0:350011bf8be7 1907 len = 0;
simon 0:350011bf8be7 1908 }
simon 0:350011bf8be7 1909 break;
simon 0:350011bf8be7 1910
simon 0:350011bf8be7 1911 case ECHOREQ:
simon 0:350011bf8be7 1912 case ECHOREP:
simon 0:350011bf8be7 1913 case DISCREQ:
simon 0:350011bf8be7 1914 if (len >= 4) {
simon 0:350011bf8be7 1915 GETLONG(cilong, p);
simon 0:350011bf8be7 1916 printer(arg, " magic=0x%x", cilong);
simon 0:350011bf8be7 1917 p += 4;
simon 0:350011bf8be7 1918 len -= 4;
simon 0:350011bf8be7 1919 }
simon 0:350011bf8be7 1920 break;
simon 0:350011bf8be7 1921 }
simon 0:350011bf8be7 1922
simon 0:350011bf8be7 1923 /* print the rest of the bytes in the packet */
simon 0:350011bf8be7 1924 for (; len > 0; --len) {
simon 0:350011bf8be7 1925 GETCHAR(code, p);
simon 0:350011bf8be7 1926 printer(arg, " %.2x", code);
simon 0:350011bf8be7 1927 }
simon 0:350011bf8be7 1928
simon 0:350011bf8be7 1929 return (int)(p - pstart);
simon 0:350011bf8be7 1930 }
simon 0:350011bf8be7 1931 #endif /* PPP_ADDITIONAL_CALLBACKS */
simon 0:350011bf8be7 1932
simon 0:350011bf8be7 1933 /*
simon 0:350011bf8be7 1934 * Time to shut down the link because there is nothing out there.
simon 0:350011bf8be7 1935 */
simon 0:350011bf8be7 1936 static void
simon 0:350011bf8be7 1937 LcpLinkFailure (fsm *f)
simon 0:350011bf8be7 1938 {
simon 0:350011bf8be7 1939 if (f->state == LS_OPENED) {
simon 0:350011bf8be7 1940 LCPDEBUG(LOG_INFO, ("No response to %d echo-requests\n", lcp_echos_pending));
simon 0:350011bf8be7 1941 LCPDEBUG(LOG_NOTICE, ("Serial link appears to be disconnected.\n"));
simon 0:350011bf8be7 1942 lcp_close(f->unit, "Peer not responding");
simon 0:350011bf8be7 1943 }
simon 0:350011bf8be7 1944 }
simon 0:350011bf8be7 1945
simon 0:350011bf8be7 1946 /*
simon 0:350011bf8be7 1947 * Timer expired for the LCP echo requests from this process.
simon 0:350011bf8be7 1948 */
simon 0:350011bf8be7 1949 static void
simon 0:350011bf8be7 1950 LcpEchoCheck (fsm *f)
simon 0:350011bf8be7 1951 {
simon 0:350011bf8be7 1952 LcpSendEchoRequest (f);
simon 0:350011bf8be7 1953
simon 0:350011bf8be7 1954 /*
simon 0:350011bf8be7 1955 * Start the timer for the next interval.
simon 0:350011bf8be7 1956 */
simon 0:350011bf8be7 1957 LWIP_ASSERT("lcp_echo_timer_running == 0", lcp_echo_timer_running == 0);
simon 0:350011bf8be7 1958
simon 0:350011bf8be7 1959 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
simon 0:350011bf8be7 1960 lcp_echo_timer_running = 1;
simon 0:350011bf8be7 1961 }
simon 0:350011bf8be7 1962
simon 0:350011bf8be7 1963 /*
simon 0:350011bf8be7 1964 * LcpEchoTimeout - Timer expired on the LCP echo
simon 0:350011bf8be7 1965 */
simon 0:350011bf8be7 1966 static void
simon 0:350011bf8be7 1967 LcpEchoTimeout (void *arg)
simon 0:350011bf8be7 1968 {
simon 0:350011bf8be7 1969 if (lcp_echo_timer_running != 0) {
simon 0:350011bf8be7 1970 lcp_echo_timer_running = 0;
simon 0:350011bf8be7 1971 LcpEchoCheck ((fsm *) arg);
simon 0:350011bf8be7 1972 }
simon 0:350011bf8be7 1973 }
simon 0:350011bf8be7 1974
simon 0:350011bf8be7 1975 /*
simon 0:350011bf8be7 1976 * LcpEchoReply - LCP has received a reply to the echo
simon 0:350011bf8be7 1977 */
simon 0:350011bf8be7 1978 static void
simon 0:350011bf8be7 1979 lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
simon 0:350011bf8be7 1980 {
simon 0:350011bf8be7 1981 u32_t magic;
simon 0:350011bf8be7 1982
simon 0:350011bf8be7 1983 LWIP_UNUSED_ARG(id);
simon 0:350011bf8be7 1984
simon 0:350011bf8be7 1985 /* Check the magic number - don't count replies from ourselves. */
simon 0:350011bf8be7 1986 if (len < 4) {
simon 0:350011bf8be7 1987 LCPDEBUG(LOG_WARNING, ("lcp: received short Echo-Reply, length %d\n", len));
simon 0:350011bf8be7 1988 return;
simon 0:350011bf8be7 1989 }
simon 0:350011bf8be7 1990 GETLONG(magic, inp);
simon 0:350011bf8be7 1991 if (lcp_gotoptions[f->unit].neg_magicnumber && magic == lcp_gotoptions[f->unit].magicnumber) {
simon 0:350011bf8be7 1992 LCPDEBUG(LOG_WARNING, ("appear to have received our own echo-reply!\n"));
simon 0:350011bf8be7 1993 return;
simon 0:350011bf8be7 1994 }
simon 0:350011bf8be7 1995
simon 0:350011bf8be7 1996 /* Reset the number of outstanding echo frames */
simon 0:350011bf8be7 1997 lcp_echos_pending = 0;
simon 0:350011bf8be7 1998 }
simon 0:350011bf8be7 1999
simon 0:350011bf8be7 2000 /*
simon 0:350011bf8be7 2001 * LcpSendEchoRequest - Send an echo request frame to the peer
simon 0:350011bf8be7 2002 */
simon 0:350011bf8be7 2003 static void
simon 0:350011bf8be7 2004 LcpSendEchoRequest (fsm *f)
simon 0:350011bf8be7 2005 {
simon 0:350011bf8be7 2006 u32_t lcp_magic;
simon 0:350011bf8be7 2007 u_char pkt[4], *pktp;
simon 0:350011bf8be7 2008
simon 0:350011bf8be7 2009 /*
simon 0:350011bf8be7 2010 * Detect the failure of the peer at this point.
simon 0:350011bf8be7 2011 */
simon 0:350011bf8be7 2012 if (lcp_echo_fails != 0) {
simon 0:350011bf8be7 2013 if (lcp_echos_pending >= lcp_echo_fails) {
simon 0:350011bf8be7 2014 LcpLinkFailure(f);
simon 0:350011bf8be7 2015 lcp_echos_pending = 0;
simon 0:350011bf8be7 2016 }
simon 0:350011bf8be7 2017 }
simon 0:350011bf8be7 2018
simon 0:350011bf8be7 2019 /*
simon 0:350011bf8be7 2020 * Make and send the echo request frame.
simon 0:350011bf8be7 2021 */
simon 0:350011bf8be7 2022 if (f->state == LS_OPENED) {
simon 0:350011bf8be7 2023 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
simon 0:350011bf8be7 2024 pktp = pkt;
simon 0:350011bf8be7 2025 PUTLONG(lcp_magic, pktp);
simon 0:350011bf8be7 2026 fsm_sdata(f, ECHOREQ, (u_char)(lcp_echo_number++ & 0xFF), pkt, (int)(pktp - pkt));
simon 0:350011bf8be7 2027 ++lcp_echos_pending;
simon 0:350011bf8be7 2028 }
simon 0:350011bf8be7 2029 }
simon 0:350011bf8be7 2030
simon 0:350011bf8be7 2031 /*
simon 0:350011bf8be7 2032 * lcp_echo_lowerup - Start the timer for the LCP frame
simon 0:350011bf8be7 2033 */
simon 0:350011bf8be7 2034
simon 0:350011bf8be7 2035 static void
simon 0:350011bf8be7 2036 lcp_echo_lowerup (int unit)
simon 0:350011bf8be7 2037 {
simon 0:350011bf8be7 2038 fsm *f = &lcp_fsm[unit];
simon 0:350011bf8be7 2039
simon 0:350011bf8be7 2040 /* Clear the parameters for generating echo frames */
simon 0:350011bf8be7 2041 lcp_echos_pending = 0;
simon 0:350011bf8be7 2042 lcp_echo_number = 0;
simon 0:350011bf8be7 2043 lcp_echo_timer_running = 0;
simon 0:350011bf8be7 2044
simon 0:350011bf8be7 2045 /* If a timeout interval is specified then start the timer */
simon 0:350011bf8be7 2046 if (lcp_echo_interval != 0) {
simon 0:350011bf8be7 2047 LcpEchoCheck (f);
simon 0:350011bf8be7 2048 }
simon 0:350011bf8be7 2049 }
simon 0:350011bf8be7 2050
simon 0:350011bf8be7 2051 /*
simon 0:350011bf8be7 2052 * lcp_echo_lowerdown - Stop the timer for the LCP frame
simon 0:350011bf8be7 2053 */
simon 0:350011bf8be7 2054
simon 0:350011bf8be7 2055 static void
simon 0:350011bf8be7 2056 lcp_echo_lowerdown (int unit)
simon 0:350011bf8be7 2057 {
simon 0:350011bf8be7 2058 fsm *f = &lcp_fsm[unit];
simon 0:350011bf8be7 2059
simon 0:350011bf8be7 2060 if (lcp_echo_timer_running != 0) {
simon 0:350011bf8be7 2061 UNTIMEOUT (LcpEchoTimeout, f);
simon 0:350011bf8be7 2062 lcp_echo_timer_running = 0;
simon 0:350011bf8be7 2063 }
simon 0:350011bf8be7 2064 }
simon 0:350011bf8be7 2065
simon 0:350011bf8be7 2066 #endif /* PPP_SUPPORT */