Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

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