SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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