EthernetNetIf Compatibility.

Dependents:   XBeeWiFi_SPI_example

Fork of NetServicesSource by Donatien Garnier

Committer:
donatien
Date:
Fri Jul 09 14:46:47 2010 +0000
Revision:
4:fd826cad83c0
Parent:
0:632c9925f013

        

Who changed what in which revision?

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