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 /*** WARNING - THIS HAS NEVER BEEN FINISHED ***/
DieterGraef 0:d26c1b55cfca 2 /*****************************************************************************
DieterGraef 0:d26c1b55cfca 3 * chap.c - Network Challenge Handshake Authentication Protocol program file.
DieterGraef 0:d26c1b55cfca 4 *
DieterGraef 0:d26c1b55cfca 5 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
DieterGraef 0:d26c1b55cfca 6 * portions Copyright (c) 1997 by Global Election Systems Inc.
DieterGraef 0:d26c1b55cfca 7 *
DieterGraef 0:d26c1b55cfca 8 * The authors hereby grant permission to use, copy, modify, distribute,
DieterGraef 0:d26c1b55cfca 9 * and license this software and its documentation for any purpose, provided
DieterGraef 0:d26c1b55cfca 10 * that existing copyright notices are retained in all copies and that this
DieterGraef 0:d26c1b55cfca 11 * notice and the following disclaimer are included verbatim in any
DieterGraef 0:d26c1b55cfca 12 * distributions. No written agreement, license, or royalty fee is required
DieterGraef 0:d26c1b55cfca 13 * for any of the authorized uses.
DieterGraef 0:d26c1b55cfca 14 *
DieterGraef 0:d26c1b55cfca 15 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
DieterGraef 0:d26c1b55cfca 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
DieterGraef 0:d26c1b55cfca 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
DieterGraef 0:d26c1b55cfca 18 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
DieterGraef 0:d26c1b55cfca 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
DieterGraef 0:d26c1b55cfca 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DieterGraef 0:d26c1b55cfca 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
DieterGraef 0:d26c1b55cfca 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
DieterGraef 0:d26c1b55cfca 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
DieterGraef 0:d26c1b55cfca 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DieterGraef 0:d26c1b55cfca 25 *
DieterGraef 0:d26c1b55cfca 26 ******************************************************************************
DieterGraef 0:d26c1b55cfca 27 * REVISION HISTORY
DieterGraef 0:d26c1b55cfca 28 *
DieterGraef 0:d26c1b55cfca 29 * 03-01-01 Marc Boucher <marc@mbsi.ca>
DieterGraef 0:d26c1b55cfca 30 * Ported to lwIP.
DieterGraef 0:d26c1b55cfca 31 * 97-12-04 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
DieterGraef 0:d26c1b55cfca 32 * Original based on BSD chap.c.
DieterGraef 0:d26c1b55cfca 33 *****************************************************************************/
DieterGraef 0:d26c1b55cfca 34 /*
DieterGraef 0:d26c1b55cfca 35 * chap.c - Challenge Handshake Authentication Protocol.
DieterGraef 0:d26c1b55cfca 36 *
DieterGraef 0:d26c1b55cfca 37 * Copyright (c) 1993 The Australian National 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 the Australian National University. The name of the University
DieterGraef 0:d26c1b55cfca 46 * may not be used to endorse or promote products derived from this
DieterGraef 0:d26c1b55cfca 47 * 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 * Copyright (c) 1991 Gregory M. Christy.
DieterGraef 0:d26c1b55cfca 53 * All rights reserved.
DieterGraef 0:d26c1b55cfca 54 *
DieterGraef 0:d26c1b55cfca 55 * Redistribution and use in source and binary forms are permitted
DieterGraef 0:d26c1b55cfca 56 * provided that the above copyright notice and this paragraph are
DieterGraef 0:d26c1b55cfca 57 * duplicated in all such forms and that any documentation,
DieterGraef 0:d26c1b55cfca 58 * advertising materials, and other materials related to such
DieterGraef 0:d26c1b55cfca 59 * distribution and use acknowledge that the software was developed
DieterGraef 0:d26c1b55cfca 60 * by Gregory M. Christy. The name of the author may not be used to
DieterGraef 0:d26c1b55cfca 61 * endorse or promote products derived from this software without
DieterGraef 0:d26c1b55cfca 62 * specific prior written permission.
DieterGraef 0:d26c1b55cfca 63 *
DieterGraef 0:d26c1b55cfca 64 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
DieterGraef 0:d26c1b55cfca 65 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
DieterGraef 0:d26c1b55cfca 66 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
DieterGraef 0:d26c1b55cfca 67 */
DieterGraef 0:d26c1b55cfca 68
DieterGraef 0:d26c1b55cfca 69 #include "lwip/opt.h"
DieterGraef 0:d26c1b55cfca 70
DieterGraef 0:d26c1b55cfca 71 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
DieterGraef 0:d26c1b55cfca 72
DieterGraef 0:d26c1b55cfca 73 #if CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
DieterGraef 0:d26c1b55cfca 74
DieterGraef 0:d26c1b55cfca 75 #include "ppp_impl.h"
DieterGraef 0:d26c1b55cfca 76 #include "pppdebug.h"
DieterGraef 0:d26c1b55cfca 77
DieterGraef 0:d26c1b55cfca 78 #include "magic.h"
DieterGraef 0:d26c1b55cfca 79 #include "randm.h"
DieterGraef 0:d26c1b55cfca 80 #include "auth.h"
DieterGraef 0:d26c1b55cfca 81 #include "md5.h"
DieterGraef 0:d26c1b55cfca 82 #include "chap.h"
DieterGraef 0:d26c1b55cfca 83 #include "chpms.h"
DieterGraef 0:d26c1b55cfca 84
DieterGraef 0:d26c1b55cfca 85 #include <string.h>
DieterGraef 0:d26c1b55cfca 86
DieterGraef 0:d26c1b55cfca 87 #if 0 /* UNUSED */
DieterGraef 0:d26c1b55cfca 88 /*
DieterGraef 0:d26c1b55cfca 89 * Command-line options.
DieterGraef 0:d26c1b55cfca 90 */
DieterGraef 0:d26c1b55cfca 91 static option_t chap_option_list[] = {
DieterGraef 0:d26c1b55cfca 92 { "chap-restart", o_int, &chap[0].timeouttime,
DieterGraef 0:d26c1b55cfca 93 "Set timeout for CHAP" },
DieterGraef 0:d26c1b55cfca 94 { "chap-max-challenge", o_int, &chap[0].max_transmits,
DieterGraef 0:d26c1b55cfca 95 "Set max #xmits for challenge" },
DieterGraef 0:d26c1b55cfca 96 { "chap-interval", o_int, &chap[0].chal_interval,
DieterGraef 0:d26c1b55cfca 97 "Set interval for rechallenge" },
DieterGraef 0:d26c1b55cfca 98 #ifdef MSLANMAN
DieterGraef 0:d26c1b55cfca 99 { "ms-lanman", o_bool, &ms_lanman,
DieterGraef 0:d26c1b55cfca 100 "Use LanMan passwd when using MS-CHAP", 1 },
DieterGraef 0:d26c1b55cfca 101 #endif
DieterGraef 0:d26c1b55cfca 102 { NULL }
DieterGraef 0:d26c1b55cfca 103 };
DieterGraef 0:d26c1b55cfca 104 #endif /* UNUSED */
DieterGraef 0:d26c1b55cfca 105
DieterGraef 0:d26c1b55cfca 106 /*
DieterGraef 0:d26c1b55cfca 107 * Protocol entry points.
DieterGraef 0:d26c1b55cfca 108 */
DieterGraef 0:d26c1b55cfca 109 static void ChapInit (int);
DieterGraef 0:d26c1b55cfca 110 static void ChapLowerUp (int);
DieterGraef 0:d26c1b55cfca 111 static void ChapLowerDown (int);
DieterGraef 0:d26c1b55cfca 112 static void ChapInput (int, u_char *, int);
DieterGraef 0:d26c1b55cfca 113 static void ChapProtocolReject (int);
DieterGraef 0:d26c1b55cfca 114 #if PPP_ADDITIONAL_CALLBACKS
DieterGraef 0:d26c1b55cfca 115 static int ChapPrintPkt (u_char *, int, void (*) (void *, char *, ...), void *);
DieterGraef 0:d26c1b55cfca 116 #endif
DieterGraef 0:d26c1b55cfca 117
DieterGraef 0:d26c1b55cfca 118 struct protent chap_protent = {
DieterGraef 0:d26c1b55cfca 119 PPP_CHAP,
DieterGraef 0:d26c1b55cfca 120 ChapInit,
DieterGraef 0:d26c1b55cfca 121 ChapInput,
DieterGraef 0:d26c1b55cfca 122 ChapProtocolReject,
DieterGraef 0:d26c1b55cfca 123 ChapLowerUp,
DieterGraef 0:d26c1b55cfca 124 ChapLowerDown,
DieterGraef 0:d26c1b55cfca 125 NULL,
DieterGraef 0:d26c1b55cfca 126 NULL,
DieterGraef 0:d26c1b55cfca 127 #if PPP_ADDITIONAL_CALLBACKS
DieterGraef 0:d26c1b55cfca 128 ChapPrintPkt,
DieterGraef 0:d26c1b55cfca 129 NULL,
DieterGraef 0:d26c1b55cfca 130 #endif /* PPP_ADDITIONAL_CALLBACKS */
DieterGraef 0:d26c1b55cfca 131 1,
DieterGraef 0:d26c1b55cfca 132 "CHAP",
DieterGraef 0:d26c1b55cfca 133 #if PPP_ADDITIONAL_CALLBACKS
DieterGraef 0:d26c1b55cfca 134 NULL,
DieterGraef 0:d26c1b55cfca 135 NULL,
DieterGraef 0:d26c1b55cfca 136 NULL
DieterGraef 0:d26c1b55cfca 137 #endif /* PPP_ADDITIONAL_CALLBACKS */
DieterGraef 0:d26c1b55cfca 138 };
DieterGraef 0:d26c1b55cfca 139
DieterGraef 0:d26c1b55cfca 140 chap_state chap[NUM_PPP]; /* CHAP state; one for each unit */
DieterGraef 0:d26c1b55cfca 141
DieterGraef 0:d26c1b55cfca 142 static void ChapChallengeTimeout (void *);
DieterGraef 0:d26c1b55cfca 143 static void ChapResponseTimeout (void *);
DieterGraef 0:d26c1b55cfca 144 static void ChapReceiveChallenge (chap_state *, u_char *, u_char, int);
DieterGraef 0:d26c1b55cfca 145 static void ChapRechallenge (void *);
DieterGraef 0:d26c1b55cfca 146 static void ChapReceiveResponse (chap_state *, u_char *, int, int);
DieterGraef 0:d26c1b55cfca 147 static void ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int len);
DieterGraef 0:d26c1b55cfca 148 static void ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int len);
DieterGraef 0:d26c1b55cfca 149 static void ChapSendStatus (chap_state *, int);
DieterGraef 0:d26c1b55cfca 150 static void ChapSendChallenge (chap_state *);
DieterGraef 0:d26c1b55cfca 151 static void ChapSendResponse (chap_state *);
DieterGraef 0:d26c1b55cfca 152 static void ChapGenChallenge (chap_state *);
DieterGraef 0:d26c1b55cfca 153
DieterGraef 0:d26c1b55cfca 154 /*
DieterGraef 0:d26c1b55cfca 155 * ChapInit - Initialize a CHAP unit.
DieterGraef 0:d26c1b55cfca 156 */
DieterGraef 0:d26c1b55cfca 157 static void
DieterGraef 0:d26c1b55cfca 158 ChapInit(int unit)
DieterGraef 0:d26c1b55cfca 159 {
DieterGraef 0:d26c1b55cfca 160 chap_state *cstate = &chap[unit];
DieterGraef 0:d26c1b55cfca 161
DieterGraef 0:d26c1b55cfca 162 BZERO(cstate, sizeof(*cstate));
DieterGraef 0:d26c1b55cfca 163 cstate->unit = unit;
DieterGraef 0:d26c1b55cfca 164 cstate->clientstate = CHAPCS_INITIAL;
DieterGraef 0:d26c1b55cfca 165 cstate->serverstate = CHAPSS_INITIAL;
DieterGraef 0:d26c1b55cfca 166 cstate->timeouttime = CHAP_DEFTIMEOUT;
DieterGraef 0:d26c1b55cfca 167 cstate->max_transmits = CHAP_DEFTRANSMITS;
DieterGraef 0:d26c1b55cfca 168 /* random number generator is initialized in magic_init */
DieterGraef 0:d26c1b55cfca 169 }
DieterGraef 0:d26c1b55cfca 170
DieterGraef 0:d26c1b55cfca 171
DieterGraef 0:d26c1b55cfca 172 /*
DieterGraef 0:d26c1b55cfca 173 * ChapAuthWithPeer - Authenticate us with our peer (start client).
DieterGraef 0:d26c1b55cfca 174 *
DieterGraef 0:d26c1b55cfca 175 */
DieterGraef 0:d26c1b55cfca 176 void
DieterGraef 0:d26c1b55cfca 177 ChapAuthWithPeer(int unit, char *our_name, u_char digest)
DieterGraef 0:d26c1b55cfca 178 {
DieterGraef 0:d26c1b55cfca 179 chap_state *cstate = &chap[unit];
DieterGraef 0:d26c1b55cfca 180
DieterGraef 0:d26c1b55cfca 181 cstate->resp_name = our_name;
DieterGraef 0:d26c1b55cfca 182 cstate->resp_type = digest;
DieterGraef 0:d26c1b55cfca 183
DieterGraef 0:d26c1b55cfca 184 if (cstate->clientstate == CHAPCS_INITIAL ||
DieterGraef 0:d26c1b55cfca 185 cstate->clientstate == CHAPCS_PENDING) {
DieterGraef 0:d26c1b55cfca 186 /* lower layer isn't up - wait until later */
DieterGraef 0:d26c1b55cfca 187 cstate->clientstate = CHAPCS_PENDING;
DieterGraef 0:d26c1b55cfca 188 return;
DieterGraef 0:d26c1b55cfca 189 }
DieterGraef 0:d26c1b55cfca 190
DieterGraef 0:d26c1b55cfca 191 /*
DieterGraef 0:d26c1b55cfca 192 * We get here as a result of LCP coming up.
DieterGraef 0:d26c1b55cfca 193 * So even if CHAP was open before, we will
DieterGraef 0:d26c1b55cfca 194 * have to re-authenticate ourselves.
DieterGraef 0:d26c1b55cfca 195 */
DieterGraef 0:d26c1b55cfca 196 cstate->clientstate = CHAPCS_LISTEN;
DieterGraef 0:d26c1b55cfca 197 }
DieterGraef 0:d26c1b55cfca 198
DieterGraef 0:d26c1b55cfca 199
DieterGraef 0:d26c1b55cfca 200 /*
DieterGraef 0:d26c1b55cfca 201 * ChapAuthPeer - Authenticate our peer (start server).
DieterGraef 0:d26c1b55cfca 202 */
DieterGraef 0:d26c1b55cfca 203 void
DieterGraef 0:d26c1b55cfca 204 ChapAuthPeer(int unit, char *our_name, u_char digest)
DieterGraef 0:d26c1b55cfca 205 {
DieterGraef 0:d26c1b55cfca 206 chap_state *cstate = &chap[unit];
DieterGraef 0:d26c1b55cfca 207
DieterGraef 0:d26c1b55cfca 208 cstate->chal_name = our_name;
DieterGraef 0:d26c1b55cfca 209 cstate->chal_type = digest;
DieterGraef 0:d26c1b55cfca 210
DieterGraef 0:d26c1b55cfca 211 if (cstate->serverstate == CHAPSS_INITIAL ||
DieterGraef 0:d26c1b55cfca 212 cstate->serverstate == CHAPSS_PENDING) {
DieterGraef 0:d26c1b55cfca 213 /* lower layer isn't up - wait until later */
DieterGraef 0:d26c1b55cfca 214 cstate->serverstate = CHAPSS_PENDING;
DieterGraef 0:d26c1b55cfca 215 return;
DieterGraef 0:d26c1b55cfca 216 }
DieterGraef 0:d26c1b55cfca 217
DieterGraef 0:d26c1b55cfca 218 ChapGenChallenge(cstate);
DieterGraef 0:d26c1b55cfca 219 ChapSendChallenge(cstate); /* crank it up dude! */
DieterGraef 0:d26c1b55cfca 220 cstate->serverstate = CHAPSS_INITIAL_CHAL;
DieterGraef 0:d26c1b55cfca 221 }
DieterGraef 0:d26c1b55cfca 222
DieterGraef 0:d26c1b55cfca 223
DieterGraef 0:d26c1b55cfca 224 /*
DieterGraef 0:d26c1b55cfca 225 * ChapChallengeTimeout - Timeout expired on sending challenge.
DieterGraef 0:d26c1b55cfca 226 */
DieterGraef 0:d26c1b55cfca 227 static void
DieterGraef 0:d26c1b55cfca 228 ChapChallengeTimeout(void *arg)
DieterGraef 0:d26c1b55cfca 229 {
DieterGraef 0:d26c1b55cfca 230 chap_state *cstate = (chap_state *) arg;
DieterGraef 0:d26c1b55cfca 231
DieterGraef 0:d26c1b55cfca 232 /* if we aren't sending challenges, don't worry. then again we */
DieterGraef 0:d26c1b55cfca 233 /* probably shouldn't be here either */
DieterGraef 0:d26c1b55cfca 234 if (cstate->serverstate != CHAPSS_INITIAL_CHAL &&
DieterGraef 0:d26c1b55cfca 235 cstate->serverstate != CHAPSS_RECHALLENGE) {
DieterGraef 0:d26c1b55cfca 236 return;
DieterGraef 0:d26c1b55cfca 237 }
DieterGraef 0:d26c1b55cfca 238
DieterGraef 0:d26c1b55cfca 239 if (cstate->chal_transmits >= cstate->max_transmits) {
DieterGraef 0:d26c1b55cfca 240 /* give up on peer */
DieterGraef 0:d26c1b55cfca 241 CHAPDEBUG(LOG_ERR, ("Peer failed to respond to CHAP challenge\n"));
DieterGraef 0:d26c1b55cfca 242 cstate->serverstate = CHAPSS_BADAUTH;
DieterGraef 0:d26c1b55cfca 243 auth_peer_fail(cstate->unit, PPP_CHAP);
DieterGraef 0:d26c1b55cfca 244 return;
DieterGraef 0:d26c1b55cfca 245 }
DieterGraef 0:d26c1b55cfca 246
DieterGraef 0:d26c1b55cfca 247 ChapSendChallenge(cstate); /* Re-send challenge */
DieterGraef 0:d26c1b55cfca 248 }
DieterGraef 0:d26c1b55cfca 249
DieterGraef 0:d26c1b55cfca 250
DieterGraef 0:d26c1b55cfca 251 /*
DieterGraef 0:d26c1b55cfca 252 * ChapResponseTimeout - Timeout expired on sending response.
DieterGraef 0:d26c1b55cfca 253 */
DieterGraef 0:d26c1b55cfca 254 static void
DieterGraef 0:d26c1b55cfca 255 ChapResponseTimeout(void *arg)
DieterGraef 0:d26c1b55cfca 256 {
DieterGraef 0:d26c1b55cfca 257 chap_state *cstate = (chap_state *) arg;
DieterGraef 0:d26c1b55cfca 258
DieterGraef 0:d26c1b55cfca 259 /* if we aren't sending a response, don't worry. */
DieterGraef 0:d26c1b55cfca 260 if (cstate->clientstate != CHAPCS_RESPONSE) {
DieterGraef 0:d26c1b55cfca 261 return;
DieterGraef 0:d26c1b55cfca 262 }
DieterGraef 0:d26c1b55cfca 263
DieterGraef 0:d26c1b55cfca 264 ChapSendResponse(cstate); /* re-send response */
DieterGraef 0:d26c1b55cfca 265 }
DieterGraef 0:d26c1b55cfca 266
DieterGraef 0:d26c1b55cfca 267
DieterGraef 0:d26c1b55cfca 268 /*
DieterGraef 0:d26c1b55cfca 269 * ChapRechallenge - Time to challenge the peer again.
DieterGraef 0:d26c1b55cfca 270 */
DieterGraef 0:d26c1b55cfca 271 static void
DieterGraef 0:d26c1b55cfca 272 ChapRechallenge(void *arg)
DieterGraef 0:d26c1b55cfca 273 {
DieterGraef 0:d26c1b55cfca 274 chap_state *cstate = (chap_state *) arg;
DieterGraef 0:d26c1b55cfca 275
DieterGraef 0:d26c1b55cfca 276 /* if we aren't sending a response, don't worry. */
DieterGraef 0:d26c1b55cfca 277 if (cstate->serverstate != CHAPSS_OPEN) {
DieterGraef 0:d26c1b55cfca 278 return;
DieterGraef 0:d26c1b55cfca 279 }
DieterGraef 0:d26c1b55cfca 280
DieterGraef 0:d26c1b55cfca 281 ChapGenChallenge(cstate);
DieterGraef 0:d26c1b55cfca 282 ChapSendChallenge(cstate);
DieterGraef 0:d26c1b55cfca 283 cstate->serverstate = CHAPSS_RECHALLENGE;
DieterGraef 0:d26c1b55cfca 284 }
DieterGraef 0:d26c1b55cfca 285
DieterGraef 0:d26c1b55cfca 286
DieterGraef 0:d26c1b55cfca 287 /*
DieterGraef 0:d26c1b55cfca 288 * ChapLowerUp - The lower layer is up.
DieterGraef 0:d26c1b55cfca 289 *
DieterGraef 0:d26c1b55cfca 290 * Start up if we have pending requests.
DieterGraef 0:d26c1b55cfca 291 */
DieterGraef 0:d26c1b55cfca 292 static void
DieterGraef 0:d26c1b55cfca 293 ChapLowerUp(int unit)
DieterGraef 0:d26c1b55cfca 294 {
DieterGraef 0:d26c1b55cfca 295 chap_state *cstate = &chap[unit];
DieterGraef 0:d26c1b55cfca 296
DieterGraef 0:d26c1b55cfca 297 if (cstate->clientstate == CHAPCS_INITIAL) {
DieterGraef 0:d26c1b55cfca 298 cstate->clientstate = CHAPCS_CLOSED;
DieterGraef 0:d26c1b55cfca 299 } else if (cstate->clientstate == CHAPCS_PENDING) {
DieterGraef 0:d26c1b55cfca 300 cstate->clientstate = CHAPCS_LISTEN;
DieterGraef 0:d26c1b55cfca 301 }
DieterGraef 0:d26c1b55cfca 302
DieterGraef 0:d26c1b55cfca 303 if (cstate->serverstate == CHAPSS_INITIAL) {
DieterGraef 0:d26c1b55cfca 304 cstate->serverstate = CHAPSS_CLOSED;
DieterGraef 0:d26c1b55cfca 305 } else if (cstate->serverstate == CHAPSS_PENDING) {
DieterGraef 0:d26c1b55cfca 306 ChapGenChallenge(cstate);
DieterGraef 0:d26c1b55cfca 307 ChapSendChallenge(cstate);
DieterGraef 0:d26c1b55cfca 308 cstate->serverstate = CHAPSS_INITIAL_CHAL;
DieterGraef 0:d26c1b55cfca 309 }
DieterGraef 0:d26c1b55cfca 310 }
DieterGraef 0:d26c1b55cfca 311
DieterGraef 0:d26c1b55cfca 312
DieterGraef 0:d26c1b55cfca 313 /*
DieterGraef 0:d26c1b55cfca 314 * ChapLowerDown - The lower layer is down.
DieterGraef 0:d26c1b55cfca 315 *
DieterGraef 0:d26c1b55cfca 316 * Cancel all timeouts.
DieterGraef 0:d26c1b55cfca 317 */
DieterGraef 0:d26c1b55cfca 318 static void
DieterGraef 0:d26c1b55cfca 319 ChapLowerDown(int unit)
DieterGraef 0:d26c1b55cfca 320 {
DieterGraef 0:d26c1b55cfca 321 chap_state *cstate = &chap[unit];
DieterGraef 0:d26c1b55cfca 322
DieterGraef 0:d26c1b55cfca 323 /* Timeout(s) pending? Cancel if so. */
DieterGraef 0:d26c1b55cfca 324 if (cstate->serverstate == CHAPSS_INITIAL_CHAL ||
DieterGraef 0:d26c1b55cfca 325 cstate->serverstate == CHAPSS_RECHALLENGE) {
DieterGraef 0:d26c1b55cfca 326 UNTIMEOUT(ChapChallengeTimeout, cstate);
DieterGraef 0:d26c1b55cfca 327 } else if (cstate->serverstate == CHAPSS_OPEN
DieterGraef 0:d26c1b55cfca 328 && cstate->chal_interval != 0) {
DieterGraef 0:d26c1b55cfca 329 UNTIMEOUT(ChapRechallenge, cstate);
DieterGraef 0:d26c1b55cfca 330 }
DieterGraef 0:d26c1b55cfca 331 if (cstate->clientstate == CHAPCS_RESPONSE) {
DieterGraef 0:d26c1b55cfca 332 UNTIMEOUT(ChapResponseTimeout, cstate);
DieterGraef 0:d26c1b55cfca 333 }
DieterGraef 0:d26c1b55cfca 334 cstate->clientstate = CHAPCS_INITIAL;
DieterGraef 0:d26c1b55cfca 335 cstate->serverstate = CHAPSS_INITIAL;
DieterGraef 0:d26c1b55cfca 336 }
DieterGraef 0:d26c1b55cfca 337
DieterGraef 0:d26c1b55cfca 338
DieterGraef 0:d26c1b55cfca 339 /*
DieterGraef 0:d26c1b55cfca 340 * ChapProtocolReject - Peer doesn't grok CHAP.
DieterGraef 0:d26c1b55cfca 341 */
DieterGraef 0:d26c1b55cfca 342 static void
DieterGraef 0:d26c1b55cfca 343 ChapProtocolReject(int unit)
DieterGraef 0:d26c1b55cfca 344 {
DieterGraef 0:d26c1b55cfca 345 chap_state *cstate = &chap[unit];
DieterGraef 0:d26c1b55cfca 346
DieterGraef 0:d26c1b55cfca 347 if (cstate->serverstate != CHAPSS_INITIAL &&
DieterGraef 0:d26c1b55cfca 348 cstate->serverstate != CHAPSS_CLOSED) {
DieterGraef 0:d26c1b55cfca 349 auth_peer_fail(unit, PPP_CHAP);
DieterGraef 0:d26c1b55cfca 350 }
DieterGraef 0:d26c1b55cfca 351 if (cstate->clientstate != CHAPCS_INITIAL &&
DieterGraef 0:d26c1b55cfca 352 cstate->clientstate != CHAPCS_CLOSED) {
DieterGraef 0:d26c1b55cfca 353 auth_withpeer_fail(unit, PPP_CHAP); /* lwip: just sets the PPP error code on this unit to PPPERR_AUTHFAIL */
DieterGraef 0:d26c1b55cfca 354 }
DieterGraef 0:d26c1b55cfca 355 ChapLowerDown(unit); /* shutdown chap */
DieterGraef 0:d26c1b55cfca 356 }
DieterGraef 0:d26c1b55cfca 357
DieterGraef 0:d26c1b55cfca 358
DieterGraef 0:d26c1b55cfca 359 /*
DieterGraef 0:d26c1b55cfca 360 * ChapInput - Input CHAP packet.
DieterGraef 0:d26c1b55cfca 361 */
DieterGraef 0:d26c1b55cfca 362 static void
DieterGraef 0:d26c1b55cfca 363 ChapInput(int unit, u_char *inpacket, int packet_len)
DieterGraef 0:d26c1b55cfca 364 {
DieterGraef 0:d26c1b55cfca 365 chap_state *cstate = &chap[unit];
DieterGraef 0:d26c1b55cfca 366 u_char *inp;
DieterGraef 0:d26c1b55cfca 367 u_char code, id;
DieterGraef 0:d26c1b55cfca 368 int len;
DieterGraef 0:d26c1b55cfca 369
DieterGraef 0:d26c1b55cfca 370 /*
DieterGraef 0:d26c1b55cfca 371 * Parse header (code, id and length).
DieterGraef 0:d26c1b55cfca 372 * If packet too short, drop it.
DieterGraef 0:d26c1b55cfca 373 */
DieterGraef 0:d26c1b55cfca 374 inp = inpacket;
DieterGraef 0:d26c1b55cfca 375 if (packet_len < CHAP_HEADERLEN) {
DieterGraef 0:d26c1b55cfca 376 CHAPDEBUG(LOG_INFO, ("ChapInput: rcvd short header.\n"));
DieterGraef 0:d26c1b55cfca 377 return;
DieterGraef 0:d26c1b55cfca 378 }
DieterGraef 0:d26c1b55cfca 379 GETCHAR(code, inp);
DieterGraef 0:d26c1b55cfca 380 GETCHAR(id, inp);
DieterGraef 0:d26c1b55cfca 381 GETSHORT(len, inp);
DieterGraef 0:d26c1b55cfca 382 if (len < CHAP_HEADERLEN) {
DieterGraef 0:d26c1b55cfca 383 CHAPDEBUG(LOG_INFO, ("ChapInput: rcvd illegal length.\n"));
DieterGraef 0:d26c1b55cfca 384 return;
DieterGraef 0:d26c1b55cfca 385 }
DieterGraef 0:d26c1b55cfca 386 if (len > packet_len) {
DieterGraef 0:d26c1b55cfca 387 CHAPDEBUG(LOG_INFO, ("ChapInput: rcvd short packet.\n"));
DieterGraef 0:d26c1b55cfca 388 return;
DieterGraef 0:d26c1b55cfca 389 }
DieterGraef 0:d26c1b55cfca 390 len -= CHAP_HEADERLEN;
DieterGraef 0:d26c1b55cfca 391
DieterGraef 0:d26c1b55cfca 392 /*
DieterGraef 0:d26c1b55cfca 393 * Action depends on code (as in fact it usually does :-).
DieterGraef 0:d26c1b55cfca 394 */
DieterGraef 0:d26c1b55cfca 395 switch (code) {
DieterGraef 0:d26c1b55cfca 396 case CHAP_CHALLENGE:
DieterGraef 0:d26c1b55cfca 397 ChapReceiveChallenge(cstate, inp, id, len);
DieterGraef 0:d26c1b55cfca 398 break;
DieterGraef 0:d26c1b55cfca 399
DieterGraef 0:d26c1b55cfca 400 case CHAP_RESPONSE:
DieterGraef 0:d26c1b55cfca 401 ChapReceiveResponse(cstate, inp, id, len);
DieterGraef 0:d26c1b55cfca 402 break;
DieterGraef 0:d26c1b55cfca 403
DieterGraef 0:d26c1b55cfca 404 case CHAP_FAILURE:
DieterGraef 0:d26c1b55cfca 405 ChapReceiveFailure(cstate, inp, id, len);
DieterGraef 0:d26c1b55cfca 406 break;
DieterGraef 0:d26c1b55cfca 407
DieterGraef 0:d26c1b55cfca 408 case CHAP_SUCCESS:
DieterGraef 0:d26c1b55cfca 409 ChapReceiveSuccess(cstate, inp, id, len);
DieterGraef 0:d26c1b55cfca 410 break;
DieterGraef 0:d26c1b55cfca 411
DieterGraef 0:d26c1b55cfca 412 default: /* Need code reject? */
DieterGraef 0:d26c1b55cfca 413 CHAPDEBUG(LOG_WARNING, ("Unknown CHAP code (%d) received.\n", code));
DieterGraef 0:d26c1b55cfca 414 break;
DieterGraef 0:d26c1b55cfca 415 }
DieterGraef 0:d26c1b55cfca 416 }
DieterGraef 0:d26c1b55cfca 417
DieterGraef 0:d26c1b55cfca 418
DieterGraef 0:d26c1b55cfca 419 /*
DieterGraef 0:d26c1b55cfca 420 * ChapReceiveChallenge - Receive Challenge and send Response.
DieterGraef 0:d26c1b55cfca 421 */
DieterGraef 0:d26c1b55cfca 422 static void
DieterGraef 0:d26c1b55cfca 423 ChapReceiveChallenge(chap_state *cstate, u_char *inp, u_char id, int len)
DieterGraef 0:d26c1b55cfca 424 {
DieterGraef 0:d26c1b55cfca 425 int rchallenge_len;
DieterGraef 0:d26c1b55cfca 426 u_char *rchallenge;
DieterGraef 0:d26c1b55cfca 427 int secret_len;
DieterGraef 0:d26c1b55cfca 428 char secret[MAXSECRETLEN];
DieterGraef 0:d26c1b55cfca 429 char rhostname[256];
DieterGraef 0:d26c1b55cfca 430 MD5_CTX mdContext;
DieterGraef 0:d26c1b55cfca 431 u_char hash[MD5_SIGNATURE_SIZE];
DieterGraef 0:d26c1b55cfca 432
DieterGraef 0:d26c1b55cfca 433 CHAPDEBUG(LOG_INFO, ("ChapReceiveChallenge: Rcvd id %d.\n", id));
DieterGraef 0:d26c1b55cfca 434 if (cstate->clientstate == CHAPCS_CLOSED ||
DieterGraef 0:d26c1b55cfca 435 cstate->clientstate == CHAPCS_PENDING) {
DieterGraef 0:d26c1b55cfca 436 CHAPDEBUG(LOG_INFO, ("ChapReceiveChallenge: in state %d\n",
DieterGraef 0:d26c1b55cfca 437 cstate->clientstate));
DieterGraef 0:d26c1b55cfca 438 return;
DieterGraef 0:d26c1b55cfca 439 }
DieterGraef 0:d26c1b55cfca 440
DieterGraef 0:d26c1b55cfca 441 if (len < 2) {
DieterGraef 0:d26c1b55cfca 442 CHAPDEBUG(LOG_INFO, ("ChapReceiveChallenge: rcvd short packet.\n"));
DieterGraef 0:d26c1b55cfca 443 return;
DieterGraef 0:d26c1b55cfca 444 }
DieterGraef 0:d26c1b55cfca 445
DieterGraef 0:d26c1b55cfca 446 GETCHAR(rchallenge_len, inp);
DieterGraef 0:d26c1b55cfca 447 len -= sizeof (u_char) + rchallenge_len; /* now name field length */
DieterGraef 0:d26c1b55cfca 448 if (len < 0) {
DieterGraef 0:d26c1b55cfca 449 CHAPDEBUG(LOG_INFO, ("ChapReceiveChallenge: rcvd short packet.\n"));
DieterGraef 0:d26c1b55cfca 450 return;
DieterGraef 0:d26c1b55cfca 451 }
DieterGraef 0:d26c1b55cfca 452 rchallenge = inp;
DieterGraef 0:d26c1b55cfca 453 INCPTR(rchallenge_len, inp);
DieterGraef 0:d26c1b55cfca 454
DieterGraef 0:d26c1b55cfca 455 if (len >= (int)sizeof(rhostname)) {
DieterGraef 0:d26c1b55cfca 456 len = sizeof(rhostname) - 1;
DieterGraef 0:d26c1b55cfca 457 }
DieterGraef 0:d26c1b55cfca 458 BCOPY(inp, rhostname, len);
DieterGraef 0:d26c1b55cfca 459 rhostname[len] = '\000';
DieterGraef 0:d26c1b55cfca 460
DieterGraef 0:d26c1b55cfca 461 CHAPDEBUG(LOG_INFO, ("ChapReceiveChallenge: received name field '%s'\n",
DieterGraef 0:d26c1b55cfca 462 rhostname));
DieterGraef 0:d26c1b55cfca 463
DieterGraef 0:d26c1b55cfca 464 /* Microsoft doesn't send their name back in the PPP packet */
DieterGraef 0:d26c1b55cfca 465 if (ppp_settings.remote_name[0] != 0 && (ppp_settings.explicit_remote || rhostname[0] == 0)) {
DieterGraef 0:d26c1b55cfca 466 strncpy(rhostname, ppp_settings.remote_name, sizeof(rhostname));
DieterGraef 0:d26c1b55cfca 467 rhostname[sizeof(rhostname) - 1] = 0;
DieterGraef 0:d26c1b55cfca 468 CHAPDEBUG(LOG_INFO, ("ChapReceiveChallenge: using '%s' as remote name\n",
DieterGraef 0:d26c1b55cfca 469 rhostname));
DieterGraef 0:d26c1b55cfca 470 }
DieterGraef 0:d26c1b55cfca 471
DieterGraef 0:d26c1b55cfca 472 /* get secret for authenticating ourselves with the specified host */
DieterGraef 0:d26c1b55cfca 473 if (!get_secret(cstate->unit, cstate->resp_name, rhostname,
DieterGraef 0:d26c1b55cfca 474 secret, &secret_len, 0)) {
DieterGraef 0:d26c1b55cfca 475 secret_len = 0; /* assume null secret if can't find one */
DieterGraef 0:d26c1b55cfca 476 CHAPDEBUG(LOG_WARNING, ("No CHAP secret found for authenticating us to %s\n",
DieterGraef 0:d26c1b55cfca 477 rhostname));
DieterGraef 0:d26c1b55cfca 478 }
DieterGraef 0:d26c1b55cfca 479
DieterGraef 0:d26c1b55cfca 480 /* cancel response send timeout if necessary */
DieterGraef 0:d26c1b55cfca 481 if (cstate->clientstate == CHAPCS_RESPONSE) {
DieterGraef 0:d26c1b55cfca 482 UNTIMEOUT(ChapResponseTimeout, cstate);
DieterGraef 0:d26c1b55cfca 483 }
DieterGraef 0:d26c1b55cfca 484
DieterGraef 0:d26c1b55cfca 485 cstate->resp_id = id;
DieterGraef 0:d26c1b55cfca 486 cstate->resp_transmits = 0;
DieterGraef 0:d26c1b55cfca 487
DieterGraef 0:d26c1b55cfca 488 /* generate MD based on negotiated type */
DieterGraef 0:d26c1b55cfca 489 switch (cstate->resp_type) {
DieterGraef 0:d26c1b55cfca 490
DieterGraef 0:d26c1b55cfca 491 case CHAP_DIGEST_MD5:
DieterGraef 0:d26c1b55cfca 492 MD5Init(&mdContext);
DieterGraef 0:d26c1b55cfca 493 MD5Update(&mdContext, &cstate->resp_id, 1);
DieterGraef 0:d26c1b55cfca 494 MD5Update(&mdContext, (u_char*)secret, secret_len);
DieterGraef 0:d26c1b55cfca 495 MD5Update(&mdContext, rchallenge, rchallenge_len);
DieterGraef 0:d26c1b55cfca 496 MD5Final(hash, &mdContext);
DieterGraef 0:d26c1b55cfca 497 BCOPY(hash, cstate->response, MD5_SIGNATURE_SIZE);
DieterGraef 0:d26c1b55cfca 498 cstate->resp_length = MD5_SIGNATURE_SIZE;
DieterGraef 0:d26c1b55cfca 499 break;
DieterGraef 0:d26c1b55cfca 500
DieterGraef 0:d26c1b55cfca 501 #if MSCHAP_SUPPORT
DieterGraef 0:d26c1b55cfca 502 case CHAP_MICROSOFT:
DieterGraef 0:d26c1b55cfca 503 ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len);
DieterGraef 0:d26c1b55cfca 504 break;
DieterGraef 0:d26c1b55cfca 505 #endif
DieterGraef 0:d26c1b55cfca 506
DieterGraef 0:d26c1b55cfca 507 default:
DieterGraef 0:d26c1b55cfca 508 CHAPDEBUG(LOG_INFO, ("unknown digest type %d\n", cstate->resp_type));
DieterGraef 0:d26c1b55cfca 509 return;
DieterGraef 0:d26c1b55cfca 510 }
DieterGraef 0:d26c1b55cfca 511
DieterGraef 0:d26c1b55cfca 512 BZERO(secret, sizeof(secret));
DieterGraef 0:d26c1b55cfca 513 ChapSendResponse(cstate);
DieterGraef 0:d26c1b55cfca 514 }
DieterGraef 0:d26c1b55cfca 515
DieterGraef 0:d26c1b55cfca 516
DieterGraef 0:d26c1b55cfca 517 /*
DieterGraef 0:d26c1b55cfca 518 * ChapReceiveResponse - Receive and process response.
DieterGraef 0:d26c1b55cfca 519 */
DieterGraef 0:d26c1b55cfca 520 static void
DieterGraef 0:d26c1b55cfca 521 ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len)
DieterGraef 0:d26c1b55cfca 522 {
DieterGraef 0:d26c1b55cfca 523 u_char *remmd, remmd_len;
DieterGraef 0:d26c1b55cfca 524 int secret_len, old_state;
DieterGraef 0:d26c1b55cfca 525 int code;
DieterGraef 0:d26c1b55cfca 526 char rhostname[256];
DieterGraef 0:d26c1b55cfca 527 MD5_CTX mdContext;
DieterGraef 0:d26c1b55cfca 528 char secret[MAXSECRETLEN];
DieterGraef 0:d26c1b55cfca 529 u_char hash[MD5_SIGNATURE_SIZE];
DieterGraef 0:d26c1b55cfca 530
DieterGraef 0:d26c1b55cfca 531 CHAPDEBUG(LOG_INFO, ("ChapReceiveResponse: Rcvd id %d.\n", id));
DieterGraef 0:d26c1b55cfca 532
DieterGraef 0:d26c1b55cfca 533 if (cstate->serverstate == CHAPSS_CLOSED ||
DieterGraef 0:d26c1b55cfca 534 cstate->serverstate == CHAPSS_PENDING) {
DieterGraef 0:d26c1b55cfca 535 CHAPDEBUG(LOG_INFO, ("ChapReceiveResponse: in state %d\n",
DieterGraef 0:d26c1b55cfca 536 cstate->serverstate));
DieterGraef 0:d26c1b55cfca 537 return;
DieterGraef 0:d26c1b55cfca 538 }
DieterGraef 0:d26c1b55cfca 539
DieterGraef 0:d26c1b55cfca 540 if (id != cstate->chal_id) {
DieterGraef 0:d26c1b55cfca 541 return; /* doesn't match ID of last challenge */
DieterGraef 0:d26c1b55cfca 542 }
DieterGraef 0:d26c1b55cfca 543
DieterGraef 0:d26c1b55cfca 544 /*
DieterGraef 0:d26c1b55cfca 545 * If we have received a duplicate or bogus Response,
DieterGraef 0:d26c1b55cfca 546 * we have to send the same answer (Success/Failure)
DieterGraef 0:d26c1b55cfca 547 * as we did for the first Response we saw.
DieterGraef 0:d26c1b55cfca 548 */
DieterGraef 0:d26c1b55cfca 549 if (cstate->serverstate == CHAPSS_OPEN) {
DieterGraef 0:d26c1b55cfca 550 ChapSendStatus(cstate, CHAP_SUCCESS);
DieterGraef 0:d26c1b55cfca 551 return;
DieterGraef 0:d26c1b55cfca 552 }
DieterGraef 0:d26c1b55cfca 553 if (cstate->serverstate == CHAPSS_BADAUTH) {
DieterGraef 0:d26c1b55cfca 554 ChapSendStatus(cstate, CHAP_FAILURE);
DieterGraef 0:d26c1b55cfca 555 return;
DieterGraef 0:d26c1b55cfca 556 }
DieterGraef 0:d26c1b55cfca 557
DieterGraef 0:d26c1b55cfca 558 if (len < 2) {
DieterGraef 0:d26c1b55cfca 559 CHAPDEBUG(LOG_INFO, ("ChapReceiveResponse: rcvd short packet.\n"));
DieterGraef 0:d26c1b55cfca 560 return;
DieterGraef 0:d26c1b55cfca 561 }
DieterGraef 0:d26c1b55cfca 562 GETCHAR(remmd_len, inp); /* get length of MD */
DieterGraef 0:d26c1b55cfca 563 remmd = inp; /* get pointer to MD */
DieterGraef 0:d26c1b55cfca 564 INCPTR(remmd_len, inp);
DieterGraef 0:d26c1b55cfca 565
DieterGraef 0:d26c1b55cfca 566 len -= sizeof (u_char) + remmd_len;
DieterGraef 0:d26c1b55cfca 567 if (len < 0) {
DieterGraef 0:d26c1b55cfca 568 CHAPDEBUG(LOG_INFO, ("ChapReceiveResponse: rcvd short packet.\n"));
DieterGraef 0:d26c1b55cfca 569 return;
DieterGraef 0:d26c1b55cfca 570 }
DieterGraef 0:d26c1b55cfca 571
DieterGraef 0:d26c1b55cfca 572 UNTIMEOUT(ChapChallengeTimeout, cstate);
DieterGraef 0:d26c1b55cfca 573
DieterGraef 0:d26c1b55cfca 574 if (len >= (int)sizeof(rhostname)) {
DieterGraef 0:d26c1b55cfca 575 len = sizeof(rhostname) - 1;
DieterGraef 0:d26c1b55cfca 576 }
DieterGraef 0:d26c1b55cfca 577 BCOPY(inp, rhostname, len);
DieterGraef 0:d26c1b55cfca 578 rhostname[len] = '\000';
DieterGraef 0:d26c1b55cfca 579
DieterGraef 0:d26c1b55cfca 580 CHAPDEBUG(LOG_INFO, ("ChapReceiveResponse: received name field: %s\n",
DieterGraef 0:d26c1b55cfca 581 rhostname));
DieterGraef 0:d26c1b55cfca 582
DieterGraef 0:d26c1b55cfca 583 /*
DieterGraef 0:d26c1b55cfca 584 * Get secret for authenticating them with us,
DieterGraef 0:d26c1b55cfca 585 * do the hash ourselves, and compare the result.
DieterGraef 0:d26c1b55cfca 586 */
DieterGraef 0:d26c1b55cfca 587 code = CHAP_FAILURE;
DieterGraef 0:d26c1b55cfca 588 if (!get_secret(cstate->unit, rhostname, cstate->chal_name,
DieterGraef 0:d26c1b55cfca 589 secret, &secret_len, 1)) {
DieterGraef 0:d26c1b55cfca 590 CHAPDEBUG(LOG_WARNING, ("No CHAP secret found for authenticating %s\n",
DieterGraef 0:d26c1b55cfca 591 rhostname));
DieterGraef 0:d26c1b55cfca 592 } else {
DieterGraef 0:d26c1b55cfca 593 /* generate MD based on negotiated type */
DieterGraef 0:d26c1b55cfca 594 switch (cstate->chal_type) {
DieterGraef 0:d26c1b55cfca 595
DieterGraef 0:d26c1b55cfca 596 case CHAP_DIGEST_MD5: /* only MD5 is defined for now */
DieterGraef 0:d26c1b55cfca 597 if (remmd_len != MD5_SIGNATURE_SIZE) {
DieterGraef 0:d26c1b55cfca 598 break; /* it's not even the right length */
DieterGraef 0:d26c1b55cfca 599 }
DieterGraef 0:d26c1b55cfca 600 MD5Init(&mdContext);
DieterGraef 0:d26c1b55cfca 601 MD5Update(&mdContext, &cstate->chal_id, 1);
DieterGraef 0:d26c1b55cfca 602 MD5Update(&mdContext, (u_char*)secret, secret_len);
DieterGraef 0:d26c1b55cfca 603 MD5Update(&mdContext, cstate->challenge, cstate->chal_len);
DieterGraef 0:d26c1b55cfca 604 MD5Final(hash, &mdContext);
DieterGraef 0:d26c1b55cfca 605
DieterGraef 0:d26c1b55cfca 606 /* compare local and remote MDs and send the appropriate status */
DieterGraef 0:d26c1b55cfca 607 if (memcmp (hash, remmd, MD5_SIGNATURE_SIZE) == 0) {
DieterGraef 0:d26c1b55cfca 608 code = CHAP_SUCCESS; /* they are the same! */
DieterGraef 0:d26c1b55cfca 609 }
DieterGraef 0:d26c1b55cfca 610 break;
DieterGraef 0:d26c1b55cfca 611
DieterGraef 0:d26c1b55cfca 612 default:
DieterGraef 0:d26c1b55cfca 613 CHAPDEBUG(LOG_INFO, ("unknown digest type %d\n", cstate->chal_type));
DieterGraef 0:d26c1b55cfca 614 }
DieterGraef 0:d26c1b55cfca 615 }
DieterGraef 0:d26c1b55cfca 616
DieterGraef 0:d26c1b55cfca 617 BZERO(secret, sizeof(secret));
DieterGraef 0:d26c1b55cfca 618 ChapSendStatus(cstate, code);
DieterGraef 0:d26c1b55cfca 619
DieterGraef 0:d26c1b55cfca 620 if (code == CHAP_SUCCESS) {
DieterGraef 0:d26c1b55cfca 621 old_state = cstate->serverstate;
DieterGraef 0:d26c1b55cfca 622 cstate->serverstate = CHAPSS_OPEN;
DieterGraef 0:d26c1b55cfca 623 if (old_state == CHAPSS_INITIAL_CHAL) {
DieterGraef 0:d26c1b55cfca 624 auth_peer_success(cstate->unit, PPP_CHAP, rhostname, len);
DieterGraef 0:d26c1b55cfca 625 }
DieterGraef 0:d26c1b55cfca 626 if (cstate->chal_interval != 0) {
DieterGraef 0:d26c1b55cfca 627 TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval);
DieterGraef 0:d26c1b55cfca 628 }
DieterGraef 0:d26c1b55cfca 629 } else {
DieterGraef 0:d26c1b55cfca 630 CHAPDEBUG(LOG_ERR, ("CHAP peer authentication failed\n"));
DieterGraef 0:d26c1b55cfca 631 cstate->serverstate = CHAPSS_BADAUTH;
DieterGraef 0:d26c1b55cfca 632 auth_peer_fail(cstate->unit, PPP_CHAP);
DieterGraef 0:d26c1b55cfca 633 }
DieterGraef 0:d26c1b55cfca 634 }
DieterGraef 0:d26c1b55cfca 635
DieterGraef 0:d26c1b55cfca 636 /*
DieterGraef 0:d26c1b55cfca 637 * ChapReceiveSuccess - Receive Success
DieterGraef 0:d26c1b55cfca 638 */
DieterGraef 0:d26c1b55cfca 639 static void
DieterGraef 0:d26c1b55cfca 640 ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int len)
DieterGraef 0:d26c1b55cfca 641 {
DieterGraef 0:d26c1b55cfca 642 LWIP_UNUSED_ARG(id);
DieterGraef 0:d26c1b55cfca 643 LWIP_UNUSED_ARG(inp);
DieterGraef 0:d26c1b55cfca 644
DieterGraef 0:d26c1b55cfca 645 CHAPDEBUG(LOG_INFO, ("ChapReceiveSuccess: Rcvd id %d.\n", id));
DieterGraef 0:d26c1b55cfca 646
DieterGraef 0:d26c1b55cfca 647 if (cstate->clientstate == CHAPCS_OPEN) {
DieterGraef 0:d26c1b55cfca 648 /* presumably an answer to a duplicate response */
DieterGraef 0:d26c1b55cfca 649 return;
DieterGraef 0:d26c1b55cfca 650 }
DieterGraef 0:d26c1b55cfca 651
DieterGraef 0:d26c1b55cfca 652 if (cstate->clientstate != CHAPCS_RESPONSE) {
DieterGraef 0:d26c1b55cfca 653 /* don't know what this is */
DieterGraef 0:d26c1b55cfca 654 CHAPDEBUG(LOG_INFO, ("ChapReceiveSuccess: in state %d\n",
DieterGraef 0:d26c1b55cfca 655 cstate->clientstate));
DieterGraef 0:d26c1b55cfca 656 return;
DieterGraef 0:d26c1b55cfca 657 }
DieterGraef 0:d26c1b55cfca 658
DieterGraef 0:d26c1b55cfca 659 UNTIMEOUT(ChapResponseTimeout, cstate);
DieterGraef 0:d26c1b55cfca 660
DieterGraef 0:d26c1b55cfca 661 /*
DieterGraef 0:d26c1b55cfca 662 * Print message.
DieterGraef 0:d26c1b55cfca 663 */
DieterGraef 0:d26c1b55cfca 664 if (len > 0) {
DieterGraef 0:d26c1b55cfca 665 PRINTMSG(inp, len);
DieterGraef 0:d26c1b55cfca 666 }
DieterGraef 0:d26c1b55cfca 667
DieterGraef 0:d26c1b55cfca 668 cstate->clientstate = CHAPCS_OPEN;
DieterGraef 0:d26c1b55cfca 669
DieterGraef 0:d26c1b55cfca 670 auth_withpeer_success(cstate->unit, PPP_CHAP);
DieterGraef 0:d26c1b55cfca 671 }
DieterGraef 0:d26c1b55cfca 672
DieterGraef 0:d26c1b55cfca 673
DieterGraef 0:d26c1b55cfca 674 /*
DieterGraef 0:d26c1b55cfca 675 * ChapReceiveFailure - Receive failure.
DieterGraef 0:d26c1b55cfca 676 */
DieterGraef 0:d26c1b55cfca 677 static void
DieterGraef 0:d26c1b55cfca 678 ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int len)
DieterGraef 0:d26c1b55cfca 679 {
DieterGraef 0:d26c1b55cfca 680 LWIP_UNUSED_ARG(id);
DieterGraef 0:d26c1b55cfca 681 LWIP_UNUSED_ARG(inp);
DieterGraef 0:d26c1b55cfca 682
DieterGraef 0:d26c1b55cfca 683 CHAPDEBUG(LOG_INFO, ("ChapReceiveFailure: Rcvd id %d.\n", id));
DieterGraef 0:d26c1b55cfca 684
DieterGraef 0:d26c1b55cfca 685 if (cstate->clientstate != CHAPCS_RESPONSE) {
DieterGraef 0:d26c1b55cfca 686 /* don't know what this is */
DieterGraef 0:d26c1b55cfca 687 CHAPDEBUG(LOG_INFO, ("ChapReceiveFailure: in state %d\n",
DieterGraef 0:d26c1b55cfca 688 cstate->clientstate));
DieterGraef 0:d26c1b55cfca 689 return;
DieterGraef 0:d26c1b55cfca 690 }
DieterGraef 0:d26c1b55cfca 691
DieterGraef 0:d26c1b55cfca 692 UNTIMEOUT(ChapResponseTimeout, cstate);
DieterGraef 0:d26c1b55cfca 693
DieterGraef 0:d26c1b55cfca 694 /*
DieterGraef 0:d26c1b55cfca 695 * Print message.
DieterGraef 0:d26c1b55cfca 696 */
DieterGraef 0:d26c1b55cfca 697 if (len > 0) {
DieterGraef 0:d26c1b55cfca 698 PRINTMSG(inp, len);
DieterGraef 0:d26c1b55cfca 699 }
DieterGraef 0:d26c1b55cfca 700
DieterGraef 0:d26c1b55cfca 701 CHAPDEBUG(LOG_ERR, ("CHAP authentication failed\n"));
DieterGraef 0:d26c1b55cfca 702 auth_withpeer_fail(cstate->unit, PPP_CHAP); /* lwip: just sets the PPP error code on this unit to PPPERR_AUTHFAIL */
DieterGraef 0:d26c1b55cfca 703 }
DieterGraef 0:d26c1b55cfca 704
DieterGraef 0:d26c1b55cfca 705
DieterGraef 0:d26c1b55cfca 706 /*
DieterGraef 0:d26c1b55cfca 707 * ChapSendChallenge - Send an Authenticate challenge.
DieterGraef 0:d26c1b55cfca 708 */
DieterGraef 0:d26c1b55cfca 709 static void
DieterGraef 0:d26c1b55cfca 710 ChapSendChallenge(chap_state *cstate)
DieterGraef 0:d26c1b55cfca 711 {
DieterGraef 0:d26c1b55cfca 712 u_char *outp;
DieterGraef 0:d26c1b55cfca 713 int chal_len, name_len;
DieterGraef 0:d26c1b55cfca 714 int outlen;
DieterGraef 0:d26c1b55cfca 715
DieterGraef 0:d26c1b55cfca 716 chal_len = cstate->chal_len;
DieterGraef 0:d26c1b55cfca 717 name_len = (int)strlen(cstate->chal_name);
DieterGraef 0:d26c1b55cfca 718 outlen = CHAP_HEADERLEN + sizeof (u_char) + chal_len + name_len;
DieterGraef 0:d26c1b55cfca 719 outp = outpacket_buf[cstate->unit];
DieterGraef 0:d26c1b55cfca 720
DieterGraef 0:d26c1b55cfca 721 MAKEHEADER(outp, PPP_CHAP); /* paste in a CHAP header */
DieterGraef 0:d26c1b55cfca 722
DieterGraef 0:d26c1b55cfca 723 PUTCHAR(CHAP_CHALLENGE, outp);
DieterGraef 0:d26c1b55cfca 724 PUTCHAR(cstate->chal_id, outp);
DieterGraef 0:d26c1b55cfca 725 PUTSHORT(outlen, outp);
DieterGraef 0:d26c1b55cfca 726
DieterGraef 0:d26c1b55cfca 727 PUTCHAR(chal_len, outp); /* put length of challenge */
DieterGraef 0:d26c1b55cfca 728 BCOPY(cstate->challenge, outp, chal_len);
DieterGraef 0:d26c1b55cfca 729 INCPTR(chal_len, outp);
DieterGraef 0:d26c1b55cfca 730
DieterGraef 0:d26c1b55cfca 731 BCOPY(cstate->chal_name, outp, name_len); /* append hostname */
DieterGraef 0:d26c1b55cfca 732
DieterGraef 0:d26c1b55cfca 733 pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN);
DieterGraef 0:d26c1b55cfca 734
DieterGraef 0:d26c1b55cfca 735 CHAPDEBUG(LOG_INFO, ("ChapSendChallenge: Sent id %d.\n", cstate->chal_id));
DieterGraef 0:d26c1b55cfca 736
DieterGraef 0:d26c1b55cfca 737 TIMEOUT(ChapChallengeTimeout, cstate, cstate->timeouttime);
DieterGraef 0:d26c1b55cfca 738 ++cstate->chal_transmits;
DieterGraef 0:d26c1b55cfca 739 }
DieterGraef 0:d26c1b55cfca 740
DieterGraef 0:d26c1b55cfca 741
DieterGraef 0:d26c1b55cfca 742 /*
DieterGraef 0:d26c1b55cfca 743 * ChapSendStatus - Send a status response (ack or nak).
DieterGraef 0:d26c1b55cfca 744 */
DieterGraef 0:d26c1b55cfca 745 static void
DieterGraef 0:d26c1b55cfca 746 ChapSendStatus(chap_state *cstate, int code)
DieterGraef 0:d26c1b55cfca 747 {
DieterGraef 0:d26c1b55cfca 748 u_char *outp;
DieterGraef 0:d26c1b55cfca 749 int outlen, msglen;
DieterGraef 0:d26c1b55cfca 750 char msg[256]; /* @todo: this can be a char*, no strcpy needed */
DieterGraef 0:d26c1b55cfca 751
DieterGraef 0:d26c1b55cfca 752 if (code == CHAP_SUCCESS) {
DieterGraef 0:d26c1b55cfca 753 strcpy(msg, "Welcome!");
DieterGraef 0:d26c1b55cfca 754 } else {
DieterGraef 0:d26c1b55cfca 755 strcpy(msg, "I don't like you. Go 'way.");
DieterGraef 0:d26c1b55cfca 756 }
DieterGraef 0:d26c1b55cfca 757 msglen = (int)strlen(msg);
DieterGraef 0:d26c1b55cfca 758
DieterGraef 0:d26c1b55cfca 759 outlen = CHAP_HEADERLEN + msglen;
DieterGraef 0:d26c1b55cfca 760 outp = outpacket_buf[cstate->unit];
DieterGraef 0:d26c1b55cfca 761
DieterGraef 0:d26c1b55cfca 762 MAKEHEADER(outp, PPP_CHAP); /* paste in a header */
DieterGraef 0:d26c1b55cfca 763
DieterGraef 0:d26c1b55cfca 764 PUTCHAR(code, outp);
DieterGraef 0:d26c1b55cfca 765 PUTCHAR(cstate->chal_id, outp);
DieterGraef 0:d26c1b55cfca 766 PUTSHORT(outlen, outp);
DieterGraef 0:d26c1b55cfca 767 BCOPY(msg, outp, msglen);
DieterGraef 0:d26c1b55cfca 768 pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN);
DieterGraef 0:d26c1b55cfca 769
DieterGraef 0:d26c1b55cfca 770 CHAPDEBUG(LOG_INFO, ("ChapSendStatus: Sent code %d, id %d.\n", code,
DieterGraef 0:d26c1b55cfca 771 cstate->chal_id));
DieterGraef 0:d26c1b55cfca 772 }
DieterGraef 0:d26c1b55cfca 773
DieterGraef 0:d26c1b55cfca 774 /*
DieterGraef 0:d26c1b55cfca 775 * ChapGenChallenge is used to generate a pseudo-random challenge string of
DieterGraef 0:d26c1b55cfca 776 * a pseudo-random length between min_len and max_len. The challenge
DieterGraef 0:d26c1b55cfca 777 * string and its length are stored in *cstate, and various other fields of
DieterGraef 0:d26c1b55cfca 778 * *cstate are initialized.
DieterGraef 0:d26c1b55cfca 779 */
DieterGraef 0:d26c1b55cfca 780
DieterGraef 0:d26c1b55cfca 781 static void
DieterGraef 0:d26c1b55cfca 782 ChapGenChallenge(chap_state *cstate)
DieterGraef 0:d26c1b55cfca 783 {
DieterGraef 0:d26c1b55cfca 784 int chal_len;
DieterGraef 0:d26c1b55cfca 785 u_char *ptr = cstate->challenge;
DieterGraef 0:d26c1b55cfca 786 int i;
DieterGraef 0:d26c1b55cfca 787
DieterGraef 0:d26c1b55cfca 788 /* pick a random challenge length between MIN_CHALLENGE_LENGTH and
DieterGraef 0:d26c1b55cfca 789 MAX_CHALLENGE_LENGTH */
DieterGraef 0:d26c1b55cfca 790 chal_len = (unsigned)
DieterGraef 0:d26c1b55cfca 791 ((((magic() >> 16) *
DieterGraef 0:d26c1b55cfca 792 (MAX_CHALLENGE_LENGTH - MIN_CHALLENGE_LENGTH)) >> 16)
DieterGraef 0:d26c1b55cfca 793 + MIN_CHALLENGE_LENGTH);
DieterGraef 0:d26c1b55cfca 794 LWIP_ASSERT("chal_len <= 0xff", chal_len <= 0xffff);
DieterGraef 0:d26c1b55cfca 795 cstate->chal_len = (u_char)chal_len;
DieterGraef 0:d26c1b55cfca 796 cstate->chal_id = ++cstate->id;
DieterGraef 0:d26c1b55cfca 797 cstate->chal_transmits = 0;
DieterGraef 0:d26c1b55cfca 798
DieterGraef 0:d26c1b55cfca 799 /* generate a random string */
DieterGraef 0:d26c1b55cfca 800 for (i = 0; i < chal_len; i++ ) {
DieterGraef 0:d26c1b55cfca 801 *ptr++ = (char) (magic() & 0xff);
DieterGraef 0:d26c1b55cfca 802 }
DieterGraef 0:d26c1b55cfca 803 }
DieterGraef 0:d26c1b55cfca 804
DieterGraef 0:d26c1b55cfca 805 /*
DieterGraef 0:d26c1b55cfca 806 * ChapSendResponse - send a response packet with values as specified
DieterGraef 0:d26c1b55cfca 807 * in *cstate.
DieterGraef 0:d26c1b55cfca 808 */
DieterGraef 0:d26c1b55cfca 809 /* ARGSUSED */
DieterGraef 0:d26c1b55cfca 810 static void
DieterGraef 0:d26c1b55cfca 811 ChapSendResponse(chap_state *cstate)
DieterGraef 0:d26c1b55cfca 812 {
DieterGraef 0:d26c1b55cfca 813 u_char *outp;
DieterGraef 0:d26c1b55cfca 814 int outlen, md_len, name_len;
DieterGraef 0:d26c1b55cfca 815
DieterGraef 0:d26c1b55cfca 816 md_len = cstate->resp_length;
DieterGraef 0:d26c1b55cfca 817 name_len = (int)strlen(cstate->resp_name);
DieterGraef 0:d26c1b55cfca 818 outlen = CHAP_HEADERLEN + sizeof (u_char) + md_len + name_len;
DieterGraef 0:d26c1b55cfca 819 outp = outpacket_buf[cstate->unit];
DieterGraef 0:d26c1b55cfca 820
DieterGraef 0:d26c1b55cfca 821 MAKEHEADER(outp, PPP_CHAP);
DieterGraef 0:d26c1b55cfca 822
DieterGraef 0:d26c1b55cfca 823 PUTCHAR(CHAP_RESPONSE, outp); /* we are a response */
DieterGraef 0:d26c1b55cfca 824 PUTCHAR(cstate->resp_id, outp); /* copy id from challenge packet */
DieterGraef 0:d26c1b55cfca 825 PUTSHORT(outlen, outp); /* packet length */
DieterGraef 0:d26c1b55cfca 826
DieterGraef 0:d26c1b55cfca 827 PUTCHAR(md_len, outp); /* length of MD */
DieterGraef 0:d26c1b55cfca 828 BCOPY(cstate->response, outp, md_len); /* copy MD to buffer */
DieterGraef 0:d26c1b55cfca 829 INCPTR(md_len, outp);
DieterGraef 0:d26c1b55cfca 830
DieterGraef 0:d26c1b55cfca 831 BCOPY(cstate->resp_name, outp, name_len); /* append our name */
DieterGraef 0:d26c1b55cfca 832
DieterGraef 0:d26c1b55cfca 833 /* send the packet */
DieterGraef 0:d26c1b55cfca 834 pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN);
DieterGraef 0:d26c1b55cfca 835
DieterGraef 0:d26c1b55cfca 836 cstate->clientstate = CHAPCS_RESPONSE;
DieterGraef 0:d26c1b55cfca 837 TIMEOUT(ChapResponseTimeout, cstate, cstate->timeouttime);
DieterGraef 0:d26c1b55cfca 838 ++cstate->resp_transmits;
DieterGraef 0:d26c1b55cfca 839 }
DieterGraef 0:d26c1b55cfca 840
DieterGraef 0:d26c1b55cfca 841 #if PPP_ADDITIONAL_CALLBACKS
DieterGraef 0:d26c1b55cfca 842 static char *ChapCodenames[] = {
DieterGraef 0:d26c1b55cfca 843 "Challenge", "Response", "Success", "Failure"
DieterGraef 0:d26c1b55cfca 844 };
DieterGraef 0:d26c1b55cfca 845 /*
DieterGraef 0:d26c1b55cfca 846 * ChapPrintPkt - print the contents of a CHAP packet.
DieterGraef 0:d26c1b55cfca 847 */
DieterGraef 0:d26c1b55cfca 848 static int
DieterGraef 0:d26c1b55cfca 849 ChapPrintPkt( u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
DieterGraef 0:d26c1b55cfca 850 {
DieterGraef 0:d26c1b55cfca 851 int code, id, len;
DieterGraef 0:d26c1b55cfca 852 int clen, nlen;
DieterGraef 0:d26c1b55cfca 853 u_char x;
DieterGraef 0:d26c1b55cfca 854
DieterGraef 0:d26c1b55cfca 855 if (plen < CHAP_HEADERLEN) {
DieterGraef 0:d26c1b55cfca 856 return 0;
DieterGraef 0:d26c1b55cfca 857 }
DieterGraef 0:d26c1b55cfca 858 GETCHAR(code, p);
DieterGraef 0:d26c1b55cfca 859 GETCHAR(id, p);
DieterGraef 0:d26c1b55cfca 860 GETSHORT(len, p);
DieterGraef 0:d26c1b55cfca 861 if (len < CHAP_HEADERLEN || len > plen) {
DieterGraef 0:d26c1b55cfca 862 return 0;
DieterGraef 0:d26c1b55cfca 863 }
DieterGraef 0:d26c1b55cfca 864
DieterGraef 0:d26c1b55cfca 865 if (code >= 1 && code <= sizeof(ChapCodenames) / sizeof(char *)) {
DieterGraef 0:d26c1b55cfca 866 printer(arg, " %s", ChapCodenames[code-1]);
DieterGraef 0:d26c1b55cfca 867 } else {
DieterGraef 0:d26c1b55cfca 868 printer(arg, " code=0x%x", code);
DieterGraef 0:d26c1b55cfca 869 }
DieterGraef 0:d26c1b55cfca 870 printer(arg, " id=0x%x", id);
DieterGraef 0:d26c1b55cfca 871 len -= CHAP_HEADERLEN;
DieterGraef 0:d26c1b55cfca 872 switch (code) {
DieterGraef 0:d26c1b55cfca 873 case CHAP_CHALLENGE:
DieterGraef 0:d26c1b55cfca 874 case CHAP_RESPONSE:
DieterGraef 0:d26c1b55cfca 875 if (len < 1) {
DieterGraef 0:d26c1b55cfca 876 break;
DieterGraef 0:d26c1b55cfca 877 }
DieterGraef 0:d26c1b55cfca 878 clen = p[0];
DieterGraef 0:d26c1b55cfca 879 if (len < clen + 1) {
DieterGraef 0:d26c1b55cfca 880 break;
DieterGraef 0:d26c1b55cfca 881 }
DieterGraef 0:d26c1b55cfca 882 ++p;
DieterGraef 0:d26c1b55cfca 883 nlen = len - clen - 1;
DieterGraef 0:d26c1b55cfca 884 printer(arg, " <");
DieterGraef 0:d26c1b55cfca 885 for (; clen > 0; --clen) {
DieterGraef 0:d26c1b55cfca 886 GETCHAR(x, p);
DieterGraef 0:d26c1b55cfca 887 printer(arg, "%.2x", x);
DieterGraef 0:d26c1b55cfca 888 }
DieterGraef 0:d26c1b55cfca 889 printer(arg, ">, name = %.*Z", nlen, p);
DieterGraef 0:d26c1b55cfca 890 break;
DieterGraef 0:d26c1b55cfca 891 case CHAP_FAILURE:
DieterGraef 0:d26c1b55cfca 892 case CHAP_SUCCESS:
DieterGraef 0:d26c1b55cfca 893 printer(arg, " %.*Z", len, p);
DieterGraef 0:d26c1b55cfca 894 break;
DieterGraef 0:d26c1b55cfca 895 default:
DieterGraef 0:d26c1b55cfca 896 for (clen = len; clen > 0; --clen) {
DieterGraef 0:d26c1b55cfca 897 GETCHAR(x, p);
DieterGraef 0:d26c1b55cfca 898 printer(arg, " %.2x", x);
DieterGraef 0:d26c1b55cfca 899 }
DieterGraef 0:d26c1b55cfca 900 }
DieterGraef 0:d26c1b55cfca 901
DieterGraef 0:d26c1b55cfca 902 return len + CHAP_HEADERLEN;
DieterGraef 0:d26c1b55cfca 903 }
DieterGraef 0:d26c1b55cfca 904 #endif /* PPP_ADDITIONAL_CALLBACKS */
DieterGraef 0:d26c1b55cfca 905
DieterGraef 0:d26c1b55cfca 906 #endif /* CHAP_SUPPORT */
DieterGraef 0:d26c1b55cfca 907
DieterGraef 0:d26c1b55cfca 908 #endif /* PPP_SUPPORT */