Lines Matching refs:cstate
147 static void ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int len);
148 static void ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int len);
160 chap_state *cstate = &chap[unit]; in ChapInit() local
162 BZERO(cstate, sizeof(*cstate)); in ChapInit()
163 cstate->unit = unit; in ChapInit()
164 cstate->clientstate = CHAPCS_INITIAL; in ChapInit()
165 cstate->serverstate = CHAPSS_INITIAL; in ChapInit()
166 cstate->timeouttime = CHAP_DEFTIMEOUT; in ChapInit()
167 cstate->max_transmits = CHAP_DEFTRANSMITS; in ChapInit()
179 chap_state *cstate = &chap[unit]; in ChapAuthWithPeer() local
181 cstate->resp_name = our_name; in ChapAuthWithPeer()
182 cstate->resp_type = digest; in ChapAuthWithPeer()
184 if (cstate->clientstate == CHAPCS_INITIAL || in ChapAuthWithPeer()
185 cstate->clientstate == CHAPCS_PENDING) { in ChapAuthWithPeer()
187 cstate->clientstate = CHAPCS_PENDING; in ChapAuthWithPeer()
196 cstate->clientstate = CHAPCS_LISTEN; in ChapAuthWithPeer()
206 chap_state *cstate = &chap[unit]; in ChapAuthPeer() local
208 cstate->chal_name = our_name; in ChapAuthPeer()
209 cstate->chal_type = digest; in ChapAuthPeer()
211 if (cstate->serverstate == CHAPSS_INITIAL || in ChapAuthPeer()
212 cstate->serverstate == CHAPSS_PENDING) { in ChapAuthPeer()
214 cstate->serverstate = CHAPSS_PENDING; in ChapAuthPeer()
218 ChapGenChallenge(cstate); in ChapAuthPeer()
219 ChapSendChallenge(cstate); /* crank it up dude! */ in ChapAuthPeer()
220 cstate->serverstate = CHAPSS_INITIAL_CHAL; in ChapAuthPeer()
230 chap_state *cstate = (chap_state *) arg; in ChapChallengeTimeout() local
234 if (cstate->serverstate != CHAPSS_INITIAL_CHAL && in ChapChallengeTimeout()
235 cstate->serverstate != CHAPSS_RECHALLENGE) { in ChapChallengeTimeout()
239 if (cstate->chal_transmits >= cstate->max_transmits) { in ChapChallengeTimeout()
242 cstate->serverstate = CHAPSS_BADAUTH; in ChapChallengeTimeout()
243 auth_peer_fail(cstate->unit, PPP_CHAP); in ChapChallengeTimeout()
247 ChapSendChallenge(cstate); /* Re-send challenge */ in ChapChallengeTimeout()
257 chap_state *cstate = (chap_state *) arg; in ChapResponseTimeout() local
260 if (cstate->clientstate != CHAPCS_RESPONSE) { in ChapResponseTimeout()
264 ChapSendResponse(cstate); /* re-send response */ in ChapResponseTimeout()
274 chap_state *cstate = (chap_state *) arg; in ChapRechallenge() local
277 if (cstate->serverstate != CHAPSS_OPEN) { in ChapRechallenge()
281 ChapGenChallenge(cstate); in ChapRechallenge()
282 ChapSendChallenge(cstate); in ChapRechallenge()
283 cstate->serverstate = CHAPSS_RECHALLENGE; in ChapRechallenge()
295 chap_state *cstate = &chap[unit]; in ChapLowerUp() local
297 if (cstate->clientstate == CHAPCS_INITIAL) { in ChapLowerUp()
298 cstate->clientstate = CHAPCS_CLOSED; in ChapLowerUp()
299 } else if (cstate->clientstate == CHAPCS_PENDING) { in ChapLowerUp()
300 cstate->clientstate = CHAPCS_LISTEN; in ChapLowerUp()
303 if (cstate->serverstate == CHAPSS_INITIAL) { in ChapLowerUp()
304 cstate->serverstate = CHAPSS_CLOSED; in ChapLowerUp()
305 } else if (cstate->serverstate == CHAPSS_PENDING) { in ChapLowerUp()
306 ChapGenChallenge(cstate); in ChapLowerUp()
307 ChapSendChallenge(cstate); in ChapLowerUp()
308 cstate->serverstate = CHAPSS_INITIAL_CHAL; in ChapLowerUp()
321 chap_state *cstate = &chap[unit]; in ChapLowerDown() local
324 if (cstate->serverstate == CHAPSS_INITIAL_CHAL || in ChapLowerDown()
325 cstate->serverstate == CHAPSS_RECHALLENGE) { in ChapLowerDown()
326 UNTIMEOUT(ChapChallengeTimeout, cstate); in ChapLowerDown()
327 } else if (cstate->serverstate == CHAPSS_OPEN in ChapLowerDown()
328 && cstate->chal_interval != 0) { in ChapLowerDown()
329 UNTIMEOUT(ChapRechallenge, cstate); in ChapLowerDown()
331 if (cstate->clientstate == CHAPCS_RESPONSE) { in ChapLowerDown()
332 UNTIMEOUT(ChapResponseTimeout, cstate); in ChapLowerDown()
334 cstate->clientstate = CHAPCS_INITIAL; in ChapLowerDown()
335 cstate->serverstate = CHAPSS_INITIAL; in ChapLowerDown()
345 chap_state *cstate = &chap[unit]; in ChapProtocolReject() local
347 if (cstate->serverstate != CHAPSS_INITIAL && in ChapProtocolReject()
348 cstate->serverstate != CHAPSS_CLOSED) { in ChapProtocolReject()
351 if (cstate->clientstate != CHAPCS_INITIAL && in ChapProtocolReject()
352 cstate->clientstate != CHAPCS_CLOSED) { in ChapProtocolReject()
365 chap_state *cstate = &chap[unit]; in ChapInput() local
397 ChapReceiveChallenge(cstate, inp, id, len); in ChapInput()
401 ChapReceiveResponse(cstate, inp, id, len); in ChapInput()
405 ChapReceiveFailure(cstate, inp, id, len); in ChapInput()
409 ChapReceiveSuccess(cstate, inp, id, len); in ChapInput()
423 ChapReceiveChallenge(chap_state *cstate, u_char *inp, u_char id, int len) in ChapReceiveChallenge() argument
434 if (cstate->clientstate == CHAPCS_CLOSED || in ChapReceiveChallenge()
435 cstate->clientstate == CHAPCS_PENDING) { in ChapReceiveChallenge()
437 cstate->clientstate)); in ChapReceiveChallenge()
473 if (!get_secret(cstate->unit, cstate->resp_name, rhostname, in ChapReceiveChallenge()
481 if (cstate->clientstate == CHAPCS_RESPONSE) { in ChapReceiveChallenge()
482 UNTIMEOUT(ChapResponseTimeout, cstate); in ChapReceiveChallenge()
485 cstate->resp_id = id; in ChapReceiveChallenge()
486 cstate->resp_transmits = 0; in ChapReceiveChallenge()
489 switch (cstate->resp_type) { in ChapReceiveChallenge()
493 MD5Update(&mdContext, &cstate->resp_id, 1); in ChapReceiveChallenge()
497 BCOPY(hash, cstate->response, MD5_SIGNATURE_SIZE); in ChapReceiveChallenge()
498 cstate->resp_length = MD5_SIGNATURE_SIZE; in ChapReceiveChallenge()
503 ChapMS(cstate, rchallenge, rchallenge_len, secret, secret_len); in ChapReceiveChallenge()
508 CHAPDEBUG(LOG_INFO, ("unknown digest type %d\n", cstate->resp_type)); in ChapReceiveChallenge()
513 ChapSendResponse(cstate); in ChapReceiveChallenge()
521 ChapReceiveResponse(chap_state *cstate, u_char *inp, int id, int len) in ChapReceiveResponse() argument
533 if (cstate->serverstate == CHAPSS_CLOSED || in ChapReceiveResponse()
534 cstate->serverstate == CHAPSS_PENDING) { in ChapReceiveResponse()
536 cstate->serverstate)); in ChapReceiveResponse()
540 if (id != cstate->chal_id) { in ChapReceiveResponse()
549 if (cstate->serverstate == CHAPSS_OPEN) { in ChapReceiveResponse()
550 ChapSendStatus(cstate, CHAP_SUCCESS); in ChapReceiveResponse()
553 if (cstate->serverstate == CHAPSS_BADAUTH) { in ChapReceiveResponse()
554 ChapSendStatus(cstate, CHAP_FAILURE); in ChapReceiveResponse()
572 UNTIMEOUT(ChapChallengeTimeout, cstate); in ChapReceiveResponse()
588 if (!get_secret(cstate->unit, rhostname, cstate->chal_name, in ChapReceiveResponse()
594 switch (cstate->chal_type) { in ChapReceiveResponse()
601 MD5Update(&mdContext, &cstate->chal_id, 1); in ChapReceiveResponse()
603 MD5Update(&mdContext, cstate->challenge, cstate->chal_len); in ChapReceiveResponse()
613 CHAPDEBUG(LOG_INFO, ("unknown digest type %d\n", cstate->chal_type)); in ChapReceiveResponse()
618 ChapSendStatus(cstate, code); in ChapReceiveResponse()
621 old_state = cstate->serverstate; in ChapReceiveResponse()
622 cstate->serverstate = CHAPSS_OPEN; in ChapReceiveResponse()
624 auth_peer_success(cstate->unit, PPP_CHAP, rhostname, len); in ChapReceiveResponse()
626 if (cstate->chal_interval != 0) { in ChapReceiveResponse()
627 TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval); in ChapReceiveResponse()
631 cstate->serverstate = CHAPSS_BADAUTH; in ChapReceiveResponse()
632 auth_peer_fail(cstate->unit, PPP_CHAP); in ChapReceiveResponse()
640 ChapReceiveSuccess(chap_state *cstate, u_char *inp, u_char id, int len) in ChapReceiveSuccess() argument
647 if (cstate->clientstate == CHAPCS_OPEN) { in ChapReceiveSuccess()
652 if (cstate->clientstate != CHAPCS_RESPONSE) { in ChapReceiveSuccess()
655 cstate->clientstate)); in ChapReceiveSuccess()
659 UNTIMEOUT(ChapResponseTimeout, cstate); in ChapReceiveSuccess()
668 cstate->clientstate = CHAPCS_OPEN; in ChapReceiveSuccess()
670 auth_withpeer_success(cstate->unit, PPP_CHAP); in ChapReceiveSuccess()
678 ChapReceiveFailure(chap_state *cstate, u_char *inp, u_char id, int len) in ChapReceiveFailure() argument
685 if (cstate->clientstate != CHAPCS_RESPONSE) { in ChapReceiveFailure()
688 cstate->clientstate)); in ChapReceiveFailure()
692 UNTIMEOUT(ChapResponseTimeout, cstate); in ChapReceiveFailure()
702 …auth_withpeer_fail(cstate->unit, PPP_CHAP); /* lwip: just sets the PPP error code on this unit to … in ChapReceiveFailure()
710 ChapSendChallenge(chap_state *cstate) in ChapSendChallenge() argument
716 chal_len = cstate->chal_len; in ChapSendChallenge()
717 name_len = (int)strlen(cstate->chal_name); in ChapSendChallenge()
719 outp = outpacket_buf[cstate->unit]; in ChapSendChallenge()
724 PUTCHAR(cstate->chal_id, outp); in ChapSendChallenge()
728 BCOPY(cstate->challenge, outp, chal_len); in ChapSendChallenge()
731 BCOPY(cstate->chal_name, outp, name_len); /* append hostname */ in ChapSendChallenge()
733 pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN); in ChapSendChallenge()
735 CHAPDEBUG(LOG_INFO, ("ChapSendChallenge: Sent id %d.\n", cstate->chal_id)); in ChapSendChallenge()
737 TIMEOUT(ChapChallengeTimeout, cstate, cstate->timeouttime); in ChapSendChallenge()
738 ++cstate->chal_transmits; in ChapSendChallenge()
746 ChapSendStatus(chap_state *cstate, int code) in ChapSendStatus() argument
760 outp = outpacket_buf[cstate->unit]; in ChapSendStatus()
765 PUTCHAR(cstate->chal_id, outp); in ChapSendStatus()
768 pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN); in ChapSendStatus()
771 cstate->chal_id)); in ChapSendStatus()
782 ChapGenChallenge(chap_state *cstate) in ChapGenChallenge() argument
785 u_char *ptr = cstate->challenge; in ChapGenChallenge()
795 cstate->chal_len = (u_char)chal_len; in ChapGenChallenge()
796 cstate->chal_id = ++cstate->id; in ChapGenChallenge()
797 cstate->chal_transmits = 0; in ChapGenChallenge()
811 ChapSendResponse(chap_state *cstate) in ChapSendResponse() argument
816 md_len = cstate->resp_length; in ChapSendResponse()
817 name_len = (int)strlen(cstate->resp_name); in ChapSendResponse()
819 outp = outpacket_buf[cstate->unit]; in ChapSendResponse()
824 PUTCHAR(cstate->resp_id, outp); /* copy id from challenge packet */ in ChapSendResponse()
828 BCOPY(cstate->response, outp, md_len); /* copy MD to buffer */ in ChapSendResponse()
831 BCOPY(cstate->resp_name, outp, name_len); /* append our name */ in ChapSendResponse()
834 pppWrite(cstate->unit, outpacket_buf[cstate->unit], outlen + PPP_HDRLEN); in ChapSendResponse()
836 cstate->clientstate = CHAPCS_RESPONSE; in ChapSendResponse()
837 TIMEOUT(ChapResponseTimeout, cstate, cstate->timeouttime); in ChapSendResponse()
838 ++cstate->resp_transmits; in ChapSendResponse()