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