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

📄 sta_info.c

📁 最新的Host AP 新添加了许多pcmcia 的驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
	case STA_DEAUTH:	case STA_REMOVE:		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,			       HOSTAPD_LEVEL_INFO, "deauthenticated due to "			       "inactivity");		if (!sta->acct_terminate_cause)			sta->acct_terminate_cause =				RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;		mlme_deauthenticate_indication(			hapd, sta,			WLAN_REASON_PREV_AUTH_NOT_VALID);		ap_free_sta(hapd, sta);		break;	}}static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx){	struct hostapd_data *hapd = eloop_ctx;	struct sta_info *sta = timeout_ctx;	u8 addr[ETH_ALEN];	if (!(sta->flags & WLAN_STA_AUTH))		return;	mlme_deauthenticate_indication(hapd, sta,				       WLAN_REASON_PREV_AUTH_NOT_VALID);	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,		       HOSTAPD_LEVEL_INFO, "deauthenticated due to "		       "session timeout");	sta->acct_terminate_cause =		RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;	os_memcpy(addr, sta->addr, ETH_ALEN);	ap_free_sta(hapd, sta);	hostapd_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);}void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,			    u32 session_timeout){	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,		       HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "		       "seconds", session_timeout);	eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);	eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,			       hapd, sta);}void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta){	eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);}struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr){	struct sta_info *sta;	sta = ap_get_sta(hapd, addr);	if (sta)		return sta;	wpa_printf(MSG_DEBUG, "  New STA");	if (hapd->num_sta >= hapd->conf->max_num_sta) {		/* FIX: might try to remove some old STAs first? */		wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",			   hapd->num_sta, hapd->conf->max_num_sta);		return NULL;	}	sta = os_zalloc(sizeof(struct sta_info));	if (sta == NULL) {		wpa_printf(MSG_ERROR, "malloc failed");		return NULL;	}	sta->acct_interim_interval = hapd->conf->radius->acct_interim_interval;	/* initialize STA info data */	eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,			       ap_handle_timer, hapd, sta);	os_memcpy(sta->addr, addr, ETH_ALEN);	sta->next = hapd->sta_list;	hapd->sta_list = sta;	hapd->num_sta++;	ap_sta_hash_add(hapd, sta);	sta->ssid = &hapd->conf->ssid;	return sta;}static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta){	ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);	wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",		   MAC2STR(sta->addr));	if (hostapd_sta_remove(hapd, sta->addr) &&	    sta->flags & WLAN_STA_ASSOC) {		wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR			   " from kernel driver.", MAC2STR(sta->addr));		return -1;	}	return 0;}static int ap_sta_in_other_bss(struct hostapd_data *hapd,			       struct sta_info *sta, u32 flags){	struct hostapd_iface *iface = hapd->iface;	size_t i;	for (i = 0; i < iface->num_bss; i++) {		struct hostapd_data *bss = iface->bss[i];		struct sta_info *sta2;		/* bss should always be set during operation, but it may be		 * NULL during reconfiguration. Assume the STA is not		 * associated to another BSS in that case to avoid NULL pointer		 * dereferences. */		if (bss == hapd || bss == NULL)			continue;		sta2 = ap_get_sta(bss, sta->addr);		if (sta2 && ((sta2->flags & flags) == flags))			return 1;	}	return 0;}void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,			 u16 reason){	wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,		   hapd->conf->iface, MAC2STR(sta->addr));	sta->flags &= ~WLAN_STA_ASSOC;	if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))		ap_sta_remove(hapd, sta);	sta->timeout_next = STA_DEAUTH;	eloop_cancel_timeout(ap_handle_timer, hapd, sta);	eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,			       ap_handle_timer, hapd, sta);	accounting_sta_stop(hapd, sta);	ieee802_1x_free_station(sta);	mlme_disassociate_indication(hapd, sta, reason);}void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,			   u16 reason){	wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,		   hapd->conf->iface, MAC2STR(sta->addr));	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);	if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))		ap_sta_remove(hapd, sta);	sta->timeout_next = STA_REMOVE;	eloop_cancel_timeout(ap_handle_timer, hapd, sta);	eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,			       ap_handle_timer, hapd, sta);	accounting_sta_stop(hapd, sta);	ieee802_1x_free_station(sta);	mlme_deauthenticate_indication(hapd, sta, reason);}int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,		     int old_vlanid){	const char *iface;	struct hostapd_vlan *vlan = NULL;	/*	 * Do not proceed furthur if the vlan id remains same. We do not want	 * duplicate dynamic vlan entries.	 */	if (sta->vlan_id == old_vlanid)		return 0;	/*	 * During 1x reauth, if the vlan id changes, then remove the old id and	 * proceed furthur to add the new one.	 */	if (old_vlanid > 0)		vlan_remove_dynamic(hapd, old_vlanid);	iface = hapd->conf->iface;	if (sta->ssid->vlan[0])		iface = sta->ssid->vlan;	if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)		sta->vlan_id = 0;	else if (sta->vlan_id > 0) {		vlan = hapd->conf->vlan;		while (vlan) {			if (vlan->vlan_id == sta->vlan_id ||			    vlan->vlan_id == VLAN_ID_WILDCARD) {				iface = vlan->ifname;				break;			}			vlan = vlan->next;		}	}	if (sta->vlan_id > 0 && vlan == NULL) {		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,			       HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "			       "binding station to (vlan_id=%d)",			       sta->vlan_id);		return -1;	} else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {		vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);		if (vlan == NULL) {			hostapd_logger(hapd, sta->addr,				       HOSTAPD_MODULE_IEEE80211,				       HOSTAPD_LEVEL_DEBUG, "could not add "				       "dynamic VLAN interface for vlan_id=%d",				       sta->vlan_id);			return -1;		}		iface = vlan->ifname;		if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {			hostapd_logger(hapd, sta->addr,				       HOSTAPD_MODULE_IEEE80211,				       HOSTAPD_LEVEL_DEBUG, "could not "				       "configure encryption for dynamic VLAN "				       "interface for vlan_id=%d",				       sta->vlan_id);		}		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,			       HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "			       "interface '%s'", iface);	} else if (vlan && vlan->vlan_id == sta->vlan_id) {		if (sta->vlan_id > 0) {			vlan->dynamic_vlan++;			hostapd_logger(hapd, sta->addr,				       HOSTAPD_MODULE_IEEE80211,				       HOSTAPD_LEVEL_DEBUG, "updated existing "				       "dynamic VLAN interface '%s'", iface);		}		/*		 * Update encryption configuration for statically generated		 * VLAN interface. This is only used for static WEP		 * configuration for the case where hostapd did not yet know		 * which keys are to be used when the interface was added.		 */		if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {			hostapd_logger(hapd, sta->addr,				       HOSTAPD_MODULE_IEEE80211,				       HOSTAPD_LEVEL_DEBUG, "could not "				       "configure encryption for VLAN "				       "interface for vlan_id=%d",				       sta->vlan_id);		}	}	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,		       HOSTAPD_LEVEL_DEBUG, "binding station to interface "		       "'%s'", iface);	if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)		wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");	return hostapd_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);}#ifdef CONFIG_IEEE80211Wint ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta){	u32 tu;	struct os_time now, passed;	os_get_time(&now);	os_time_sub(&now, &sta->sa_query_start, &passed);	tu = (passed.sec * 1000000 + passed.usec) / 1024;	if (hapd->conf->assoc_sa_query_max_timeout < tu) {		hostapd_logger(hapd, sta->addr,			       HOSTAPD_MODULE_IEEE80211,			       HOSTAPD_LEVEL_DEBUG,			       "association SA Query timed out");		sta->sa_query_timed_out = 1;		os_free(sta->sa_query_trans_id);		sta->sa_query_trans_id = NULL;		sta->sa_query_count = 0;		eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);		return 1;	}	return 0;}static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx){	struct hostapd_data *hapd = eloop_ctx;	struct sta_info *sta = timeout_ctx;	unsigned int timeout, sec, usec;	u8 *trans_id, *nbuf;	if (sta->sa_query_count > 0 &&	    ap_check_sa_query_timeout(hapd, sta))		return;	nbuf = os_realloc(sta->sa_query_trans_id,			  (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);	if (nbuf == NULL)		return;	if (sta->sa_query_count == 0) {		/* Starting a new SA Query procedure */		os_get_time(&sta->sa_query_start);	}	trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;	sta->sa_query_trans_id = nbuf;	sta->sa_query_count++;	os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);	timeout = hapd->conf->assoc_sa_query_retry_timeout;	sec = ((timeout / 1000) * 1024) / 1000;	usec = (timeout % 1000) * 1024;	eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,		       HOSTAPD_LEVEL_DEBUG,		       "association SA Query attempt %d", sta->sa_query_count);	ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);}void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta){	ap_sa_query_timer(hapd, sta);}void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta){	eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);	os_free(sta->sa_query_trans_id);	sta->sa_query_trans_id = NULL;	sta->sa_query_count = 0;}#endif /* CONFIG_IEEE80211W */

⌨️ 快捷键说明

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