Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

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