Skovbrynet / Mbed 2 deprecated TankCounter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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