⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eapol_sm.c

📁 最新的Host AP 新添加了许多pcmcia 的驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (sm->initializing || eapol_sm_sta_entry_alive(eapol, addr))		SM_STEP_RUN(CTRL_DIR);	if (prev_auth_pae != sm->auth_pae_state ||	    prev_be_auth != sm->be_auth_state ||	    prev_reauth_timer != sm->reauth_timer_state ||	    prev_auth_key_tx != sm->auth_key_tx_state ||	    prev_key_rx != sm->key_rx_state ||	    prev_ctrl_dir != sm->ctrl_dir_state) {		if (--max_steps > 0)			goto restart;		/* Re-run from eloop timeout */		eapol_auth_step(sm);		return;	}	if (eapol_sm_sta_entry_alive(eapol, addr) && sm->eap) {		if (eap_server_sm_step(sm->eap)) {			if (--max_steps > 0)				goto restart;			/* Re-run from eloop timeout */			eapol_auth_step(sm);			return;		}		/* TODO: find a better location for this */		if (sm->eap_if->aaaEapResp) {			sm->eap_if->aaaEapResp = FALSE;			if (sm->eap_if->aaaEapRespData == NULL) {				wpa_printf(MSG_DEBUG, "EAPOL: aaaEapResp set, "					   "but no aaaEapRespData available");				return;			}			sm->eapol->cb.aaa_send(				sm->hapd, sm->sta,				wpabuf_head(sm->eap_if->aaaEapRespData),				wpabuf_len(sm->eap_if->aaaEapRespData));		}	}	if (eapol_sm_sta_entry_alive(eapol, addr))		wpa_auth_sm_notify(sm->sta->wpa_sm);}static void eapol_sm_step_cb(void *eloop_ctx, void *timeout_ctx){	struct eapol_state_machine *sm = eloop_ctx;	eapol_sm_step_run(sm);}/** * eapol_auth_step - Advance EAPOL state machines * @sm: EAPOL state machine * * This function is called to advance EAPOL state machines after any change * that could affect their state. */void eapol_auth_step(struct eapol_state_machine *sm){	/*	 * Run eapol_sm_step_run from a registered timeout to make sure that	 * other possible timeouts/events are processed and to avoid long	 * function call chains.	 */	eloop_register_timeout(0, 0, eapol_sm_step_cb, sm, NULL);}void eapol_auth_initialize(struct eapol_state_machine *sm){	sm->initializing = TRUE;	/* Initialize the state machines by asserting initialize and then	 * deasserting it after one step */	sm->initialize = TRUE;	eapol_sm_step_run(sm);	sm->initialize = FALSE;	eapol_sm_step_run(sm);	sm->initializing = FALSE;	/* Start one second tick for port timers state machine */	eloop_cancel_timeout(eapol_port_timers_tick, NULL, sm);	eloop_register_timeout(1, 0, eapol_port_timers_tick, NULL, sm);}#ifdef HOSTAPD_DUMP_STATEstatic inline const char * port_type_txt(PortTypes pt){	switch (pt) {	case ForceUnauthorized: return "ForceUnauthorized";	case ForceAuthorized: return "ForceAuthorized";	case Auto: return "Auto";	default: return "Unknown";	}}static inline const char * port_state_txt(PortState ps){	switch (ps) {	case Unauthorized: return "Unauthorized";	case Authorized: return "Authorized";	default: return "Unknown";	}}static inline const char * ctrl_dir_txt(ControlledDirection dir){	switch (dir) {	case Both: return "Both";	case In: return "In";	default: return "Unknown";	}}static inline const char * auth_pae_state_txt(int s){	switch (s) {	case AUTH_PAE_INITIALIZE: return "INITIALIZE";	case AUTH_PAE_DISCONNECTED: return "DISCONNECTED";	case AUTH_PAE_CONNECTING: return "CONNECTING";	case AUTH_PAE_AUTHENTICATING: return "AUTHENTICATING";	case AUTH_PAE_AUTHENTICATED: return "AUTHENTICATED";	case AUTH_PAE_ABORTING: return "ABORTING";	case AUTH_PAE_HELD: return "HELD";	case AUTH_PAE_FORCE_AUTH: return "FORCE_AUTH";	case AUTH_PAE_FORCE_UNAUTH: return "FORCE_UNAUTH";	case AUTH_PAE_RESTART: return "RESTART";	default: return "Unknown";	}}static inline const char * be_auth_state_txt(int s){	switch (s) {	case BE_AUTH_REQUEST: return "REQUEST";	case BE_AUTH_RESPONSE: return "RESPONSE";	case BE_AUTH_SUCCESS: return "SUCCESS";	case BE_AUTH_FAIL: return "FAIL";	case BE_AUTH_TIMEOUT: return "TIMEOUT";	case BE_AUTH_IDLE: return "IDLE";	case BE_AUTH_INITIALIZE: return "INITIALIZE";	case BE_AUTH_IGNORE: return "IGNORE";	default: return "Unknown";	}}static inline const char * reauth_timer_state_txt(int s){	switch (s) {	case REAUTH_TIMER_INITIALIZE: return "INITIALIZE";	case REAUTH_TIMER_REAUTHENTICATE: return "REAUTHENTICATE";	default: return "Unknown";	}}static inline const char * auth_key_tx_state_txt(int s){	switch (s) {	case AUTH_KEY_TX_NO_KEY_TRANSMIT: return "NO_KEY_TRANSMIT";	case AUTH_KEY_TX_KEY_TRANSMIT: return "KEY_TRANSMIT";	default: return "Unknown";	}}static inline const char * key_rx_state_txt(int s){	switch (s) {	case KEY_RX_NO_KEY_RECEIVE: return "NO_KEY_RECEIVE";	case KEY_RX_KEY_RECEIVE: return "KEY_RECEIVE";	default: return "Unknown";	}}static inline const char * ctrl_dir_state_txt(int s){	switch (s) {	case CTRL_DIR_FORCE_BOTH: return "FORCE_BOTH";	case CTRL_DIR_IN_OR_BOTH: return "IN_OR_BOTH";	default: return "Unknown";	}}void eapol_auth_dump_state(FILE *f, const char *prefix,			   struct eapol_state_machine *sm){	fprintf(f, "%sEAPOL state machine:\n", prefix);	fprintf(f, "%s  aWhile=%d quietWhile=%d reAuthWhen=%d\n", prefix,		sm->aWhile, sm->quietWhile, sm->reAuthWhen);#define _SB(b) ((b) ? "TRUE" : "FALSE")	fprintf(f,		"%s  authAbort=%s authFail=%s authPortStatus=%s authStart=%s\n"		"%s  authTimeout=%s authSuccess=%s eapFail=%s eapolEap=%s\n"		"%s  eapSuccess=%s eapTimeout=%s initialize=%s "		"keyAvailable=%s\n"		"%s  keyDone=%s keyRun=%s keyTxEnabled=%s portControl=%s\n"		"%s  portEnabled=%s portValid=%s reAuthenticate=%s\n",		prefix, _SB(sm->authAbort), _SB(sm->authFail),		port_state_txt(sm->authPortStatus), _SB(sm->authStart),		prefix, _SB(sm->authTimeout), _SB(sm->authSuccess),		_SB(sm->eap_if->eapFail), _SB(sm->eapolEap),		prefix, _SB(sm->eap_if->eapSuccess),		_SB(sm->eap_if->eapTimeout),		_SB(sm->initialize), _SB(sm->eap_if->eapKeyAvailable),		prefix, _SB(sm->keyDone), _SB(sm->keyRun),		_SB(sm->keyTxEnabled), port_type_txt(sm->portControl),		prefix, _SB(sm->eap_if->portEnabled), _SB(sm->portValid),		_SB(sm->reAuthenticate));	fprintf(f, "%s  Authenticator PAE:\n"		"%s    state=%s\n"		"%s    eapolLogoff=%s eapolStart=%s eapRestart=%s\n"		"%s    portMode=%s reAuthCount=%d\n"		"%s    quietPeriod=%d reAuthMax=%d\n"		"%s    authEntersConnecting=%d\n"		"%s    authEapLogoffsWhileConnecting=%d\n"		"%s    authEntersAuthenticating=%d\n"		"%s    authAuthSuccessesWhileAuthenticating=%d\n"		"%s    authAuthTimeoutsWhileAuthenticating=%d\n"		"%s    authAuthFailWhileAuthenticating=%d\n"		"%s    authAuthEapStartsWhileAuthenticating=%d\n"		"%s    authAuthEapLogoffWhileAuthenticating=%d\n"		"%s    authAuthReauthsWhileAuthenticated=%d\n"		"%s    authAuthEapStartsWhileAuthenticated=%d\n"		"%s    authAuthEapLogoffWhileAuthenticated=%d\n",		prefix, prefix, auth_pae_state_txt(sm->auth_pae_state), prefix,		_SB(sm->eapolLogoff), _SB(sm->eapolStart),		_SB(sm->eap_if->eapRestart),		prefix, port_type_txt(sm->portMode), sm->reAuthCount,		prefix, sm->quietPeriod, sm->reAuthMax,		prefix, sm->authEntersConnecting,		prefix, sm->authEapLogoffsWhileConnecting,		prefix, sm->authEntersAuthenticating,		prefix, sm->authAuthSuccessesWhileAuthenticating,		prefix, sm->authAuthTimeoutsWhileAuthenticating,		prefix, sm->authAuthFailWhileAuthenticating,		prefix, sm->authAuthEapStartsWhileAuthenticating,		prefix, sm->authAuthEapLogoffWhileAuthenticating,		prefix, sm->authAuthReauthsWhileAuthenticated,		prefix, sm->authAuthEapStartsWhileAuthenticated,		prefix, sm->authAuthEapLogoffWhileAuthenticated);	fprintf(f, "%s  Backend Authentication:\n"		"%s    state=%s\n"		"%s    eapNoReq=%s eapReq=%s eapResp=%s\n"		"%s    serverTimeout=%d\n"		"%s    backendResponses=%d\n"		"%s    backendAccessChallenges=%d\n"		"%s    backendOtherRequestsToSupplicant=%d\n"		"%s    backendAuthSuccesses=%d\n"		"%s    backendAuthFails=%d\n",		prefix, prefix,		be_auth_state_txt(sm->be_auth_state),		prefix, _SB(sm->eap_if->eapNoReq), _SB(sm->eap_if->eapReq),		_SB(sm->eap_if->eapResp),		prefix, sm->serverTimeout,		prefix, sm->backendResponses,		prefix, sm->backendAccessChallenges,		prefix, sm->backendOtherRequestsToSupplicant,		prefix, sm->backendAuthSuccesses,		prefix, sm->backendAuthFails);	fprintf(f, "%s  Reauthentication Timer:\n"		"%s    state=%s\n"		"%s    reAuthPeriod=%d reAuthEnabled=%s\n", prefix, prefix,		reauth_timer_state_txt(sm->reauth_timer_state), prefix,		sm->reAuthPeriod, _SB(sm->reAuthEnabled));	fprintf(f, "%s  Authenticator Key Transmit:\n"		"%s    state=%s\n", prefix, prefix,		auth_key_tx_state_txt(sm->auth_key_tx_state));	fprintf(f, "%s  Key Receive:\n"		"%s    state=%s\n"		"%s    rxKey=%s\n", prefix, prefix,		key_rx_state_txt(sm->key_rx_state), prefix, _SB(sm->rxKey));	fprintf(f, "%s  Controlled Directions:\n"		"%s    state=%s\n"		"%s    adminControlledDirections=%s "		"operControlledDirections=%s\n"		"%s    operEdge=%s\n", prefix, prefix,		ctrl_dir_state_txt(sm->ctrl_dir_state),		prefix, ctrl_dir_txt(sm->adminControlledDirections),		ctrl_dir_txt(sm->operControlledDirections),		prefix, _SB(sm->operEdge));#undef _SB}#endif /* HOSTAPD_DUMP_STATE */static int eapol_sm_get_eap_user(void *ctx, const u8 *identity,				 size_t identity_len, int phase2,				 struct eap_user *user){	struct eapol_state_machine *sm = ctx;	return sm->eapol->cb.get_eap_user(sm->hapd, identity, identity_len,					  phase2, user);}static const char * eapol_sm_get_eap_req_id_text(void *ctx, size_t *len){	struct eapol_state_machine *sm = ctx;	*len = sm->eapol->conf.eap_req_id_text_len;	return sm->eapol->conf.eap_req_id_text;}static struct eapol_callbacks eapol_cb ={	.get_eap_user = eapol_sm_get_eap_user,	.get_eap_req_id_text = eapol_sm_get_eap_req_id_text,};int eapol_auth_eap_pending_cb(struct eapol_state_machine *sm, void *ctx){	if (sm == NULL || ctx != sm->eap)		return -1;	eap_sm_pending_cb(sm->eap);	eapol_auth_step(sm);	return 0;}static int eapol_auth_conf_clone(struct eapol_auth_config *dst,				 struct eapol_auth_config *src){	dst->hapd = src->hapd;	dst->eap_reauth_period = src->eap_reauth_period;	dst->wpa = src->wpa;	dst->individual_wep_key_len = src->individual_wep_key_len;	dst->eap_server = src->eap_server;	dst->ssl_ctx = src->ssl_ctx;	dst->eap_sim_db_priv = src->eap_sim_db_priv;	os_free(dst->eap_req_id_text);	if (src->eap_req_id_text) {		dst->eap_req_id_text = os_malloc(src->eap_req_id_text_len);		if (dst->eap_req_id_text == NULL)			return -1;		os_memcpy(dst->eap_req_id_text, src->eap_req_id_text,			  src->eap_req_id_text_len);		dst->eap_req_id_text_len = src->eap_req_id_text_len;	} else {		dst->eap_req_id_text = NULL;		dst->eap_req_id_text_len = 0;	}	if (src->pac_opaque_encr_key) {		dst->pac_opaque_encr_key = os_malloc(16);		os_memcpy(dst->pac_opaque_encr_key, src->pac_opaque_encr_key,			  16);	} else		dst->pac_opaque_encr_key = NULL;	if (src->eap_fast_a_id) {		dst->eap_fast_a_id = os_malloc(src->eap_fast_a_id_len);		if (dst->eap_fast_a_id == NULL) {			os_free(dst->eap_req_id_text);			return -1;		}		os_memcpy(dst->eap_fast_a_id, src->eap_fast_a_id,			  src->eap_fast_a_id_len);		dst->eap_fast_a_id_len = src->eap_fast_a_id_len;	} else		dst->eap_fast_a_id = NULL;	if (src->eap_fast_a_id_info) {		dst->eap_fast_a_id_info = os_strdup(src->eap_fast_a_id_info);		if (dst->eap_fast_a_id_info == NULL) {			os_free(dst->eap_req_id_text);			os_free(dst->eap_fast_a_id);			return -1;		}	} else		dst->eap_fast_a_id_info = NULL;	dst->eap_fast_prov = src->eap_fast_prov;	dst->pac_key_lifetime = src->pac_key_lifetime;	dst->pac_key_refresh_time = src->pac_key_refresh_time;	dst->eap_sim_aka_result_ind = src->eap_sim_aka_result_ind;	dst->tnc = src->tnc;	dst->wps = src->wps;	return 0;}static void eapol_auth_conf_free(struct eapol_auth_config *conf){	os_free(conf->eap_req_id_text);	conf->eap_req_id_text = NULL;	os_free(conf->pac_opaque_encr_key);	conf->pac_opaque_encr_key = NULL;	os_free(conf->eap_fast_a_id);	conf->eap_fast_a_id = NULL;	os_free(conf->eap_fast_a_id_info);	conf->eap_fast_a_id_info = NULL;}struct eapol_authenticator * eapol_auth_init(struct eapol_auth_config *conf,					     struct eapol_auth_cb *cb){	struct eapol_authenticator *eapol;	eapol = os_zalloc(sizeof(*eapol));	if (eapol == NULL)		return NULL;	if (eapol_auth_conf_clone(&eapol->conf, conf) < 0) {		os_free(eapol);		return NULL;	}	eapol->cb.eapol_send = cb->eapol_send;	eapol->cb.aaa_send = cb->aaa_send;	eapol->cb.finished = cb->finished;	eapol->cb.get_eap_user = cb->get_eap_user;	eapol->cb.sta_entry_alive = cb->sta_entry_alive;	eapol->cb.logger = cb->logger;	eapol->cb.set_port_authorized = cb->set_port_authorized;	eapol->cb.abort_auth = cb->abort_auth;	eapol->cb.tx_key = cb->tx_key;	return eapol;}void eapol_auth_deinit(struct eapol_authenticator *eapol){	if (eapol == NULL)		return;	eapol_auth_conf_free(&eapol->conf);	os_free(eapol);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -