int eap_example_peer_step(void)
{
	int res;
	res = eap_peer_sm_step(eap_ctx.eap);

	if (eap_ctx.eapResp) {
		struct wpabuf *resp;
		printf("==> Response\n");
		eap_ctx.eapResp = FALSE;
		resp = eap_get_eapRespData(eap_ctx.eap);
		if (resp) {
			/* Send EAP response to the server */
			eap_example_server_rx(wpabuf_head(resp),
					      wpabuf_len(resp));
			wpabuf_free(resp);
		}
	}

	if (eap_ctx.eapSuccess) {
		res = 0;
		if (eap_key_available(eap_ctx.eap)) {
			const u8 *key;
			size_t key_len;
			key = eap_get_eapKeyData(eap_ctx.eap, &key_len);
			wpa_hexdump(MSG_DEBUG, "EAP keying material",
				    key, key_len);
		}
	}

	return res;
}
Example #2
0
/**
 * eapol_sm_step - EAPOL state machine step function
 * @sm: Pointer to EAPOL state machine allocated with eapol_sm_init()
 *
 * This function is called to notify the state machine about changed external
 * variables. It will step through the EAPOL state machines in loop to process
 * all triggered state changes.
 */
void eapol_sm_step(struct eapol_sm *sm)
{
	int i;

	/* In theory, it should be ok to run this in loop until !changed.
	 * However, it is better to use a limit on number of iterations to
	 * allow events (e.g., SIGTERM) to stop the program cleanly if the
	 * state machine were to generate a busy loop. */
	for (i = 0; i < 100; i++) {
		sm->changed = FALSE;
		SM_STEP_RUN(SUPP_PAE);
		SM_STEP_RUN(KEY_RX);
		SM_STEP_RUN(SUPP_BE);
		if (eap_peer_sm_step(sm->eap))
			sm->changed = TRUE;
		if (!sm->changed)
			break;
	}

	if (sm->changed) {
		/* restart EAPOL state machine step from timeout call in order
		 * to allow other events to be processed. */
		eloop_cancel_timeout(eapol_sm_step_timeout, NULL, sm);
		eloop_register_timeout(0, 0, eapol_sm_step_timeout, NULL, sm);
	}

	if (sm->ctx->cb && sm->cb_status != EAPOL_CB_IN_PROGRESS) {
		int success = sm->cb_status == EAPOL_CB_SUCCESS ? 1 : 0;
		sm->cb_status = EAPOL_CB_IN_PROGRESS;
		sm->ctx->cb(sm, success, sm->ctx->cb_ctx);
	}
}
Example #3
0
int eap_peer_step(void)
{
	unsigned char data[0x4000];
	int res;
	res = eap_peer_sm_step(eap_ctx.eap);
	
	/* This part was not tested properly */
	if(	!eap_ctx.eapSuccess &&
		!eap_ctx.eapRestart &&
		!eap_ctx.eapFail &&
		!eap_ctx.eapResp &&
		!eap_ctx.eapNoResp &&
		!eap_ctx.eapReq
	) {
		struct wpabuf *resp;
		resp = eap_sm_buildIdentity( eap_ctx.eap, 0, 0 );
		if (resp) {
			// Send EAP response to the server 
			memcpy(data,wpabuf_head(resp),wpabuf_len(resp)); // memcpy Maybe useless!!!!
			eap_server_rx(data,  wpabuf_len(resp));		

			wpabuf_free(resp);
		}	
	}
		
	if (eap_ctx.eapResp) {
		struct wpabuf *resp;
		eap_ctx.eapResp = FALSE;
		resp = eap_get_eapRespData(eap_ctx.eap);
		if (resp) {
			/* Send EAP response to the server */
			memcpy(data,wpabuf_head(resp),wpabuf_len(resp)); // memcpy Maybe useless!!!!
			eap_server_rx(data,  wpabuf_len(resp));		
			
			//eap_server_rx(wpabuf_head(resp),
			//		      wpabuf_len(resp));
			wpabuf_free(resp);
		}
	}

	if (eap_ctx.eapSuccess) {
		res = 0;
		if (eap_key_available(eap_ctx.eap)) {
			const u8 *key;
			size_t key_len;
			key = eap_get_eapKeyData(eap_ctx.eap, &key_len);

			memcpy(data,key,key_len);
			eap_key(data, key_len);
			
			wpa_hexdump(MSG_DEBUG, "EAP keying material",
				    key, key_len);
		}
	}
	
	if (eap_ctx.eapFail) {
		res = -1;
	}	
		
	return res;
}