HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

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