Example self-announcing webserver which controls a servo through a smallHTML userinterface.

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:56:01 2010 +0000
Revision:
0:a259777c45a3

        

Who changed what in which revision?

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