Forked from the DieterGraef Library

Fork of F7_Ethernet by Dieter Graef

Committer:
DieterGraef
Date:
Sun Jun 19 16:23:40 2016 +0000
Revision:
0:d26c1b55cfca
Ethernet Library for Nucleo stm32f746ZG and Disco stm32f746NG  works under arm and gcc environment

Who changed what in which revision?

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