HTTPClient using static IP

Dependencies:   mbed

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

Who changed what in which revision?

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