Web server based weather station using Sparkfun Weather Meters.

Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Committer:
AdamGreen
Date:
Sat Feb 25 03:28:05 2012 +0000
Revision:
1:c7958aa34fa1
Parent:
0:616601bde9fb
Use published libraries where possible.

Who changed what in which revision?

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