Parcourir la source

Moved disassociation processing away from driver_*.c

Jouni Malinen il y a 16 ans
Parent
commit
33eb3c4ec4
5 fichiers modifiés avec 28 ajouts et 67 suppressions
  1. 1 0
      hostapd/driver.h
  2. 1 26
      hostapd/driver_bsd.c
  3. 2 25
      hostapd/driver_madwifi.c
  4. 1 16
      hostapd/driver_test.c
  5. 23 0
      hostapd/hostapd.c

+ 1 - 0
hostapd/driver.h

@@ -218,5 +218,6 @@ void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
 void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, const u8 *addr);
 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
 			const u8 *ie, size_t ielen);
+void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
 
 #endif /* DRIVER_H */

+ 1 - 26
hostapd/driver_bsd.c

@@ -34,12 +34,9 @@
 #include "driver.h"
 #include "ieee802_1x.h"
 #include "eloop.h"
-#include "sta_info.h"
 #include "l2_packet/l2_packet.h"
 
 #include "eapol_sm.h"
-#include "wpa.h"
-#include "radius/radius.h"
 #include "ieee802_11.h"
 #include "common.h"
 
@@ -504,28 +501,6 @@ bsd_sta_disassoc(void *priv, const u8 *addr, int reason_code)
 	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
 }
 
-static int
-bsd_del_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
-{
-	struct hostapd_data *hapd = drv->hapd;
-	struct hostapd_bss_config *conf = hapd->conf;
-	struct sta_info *sta;
-
-	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
-		HOSTAPD_LEVEL_INFO, "deassociated");
-
-	sta = ap_get_sta(hapd, addr);
-	if (sta != NULL) {
-		sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
-		if (conf->wpa)
-			wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
-		sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
-		ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
-		ap_free_sta(hapd, sta);
-	}
-	return 0;
-}
-
 static int
 bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
 {
@@ -593,7 +568,7 @@ bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
 			break;
 		case RTM_IEEE80211_LEAVE:
 			leave = (struct ieee80211_leave_event *) &ifan[1];
-			bsd_del_sta(drv, leave->iev_addr);
+			hostapd_notif_disassoc(drv, leave->iev_addr);
 			break;
 		case RTM_IEEE80211_JOIN:
 #ifdef RTM_IEEE80211_REJOIN

+ 2 - 25
hostapd/driver_madwifi.c

@@ -60,13 +60,9 @@
 #include "ieee802_1x.h"
 #include "eloop.h"
 #include "priv_netlink.h"
-#include "sta_info.h"
 #include "l2_packet/l2_packet.h"
 
-#include "wpa.h"
-#include "radius/radius.h"
 #include "ieee802_11.h"
-#include "accounting.h"
 #include "common.h"
 #include "wps_hostapd.h"
 
@@ -795,26 +791,6 @@ static int madwifi_receive_probe_req(struct madwifi_driver_data *drv)
 	return ret;
 }
 
-static int
-madwifi_del_sta(struct madwifi_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
-{
-	struct hostapd_data *hapd = drv->hapd;
-	struct sta_info *sta;
-
-	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
-		HOSTAPD_LEVEL_INFO, "disassociated");
-
-	sta = ap_get_sta(hapd, addr);
-	if (sta != NULL) {
-		sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
-		wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
-		sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
-		ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
-		ap_free_sta(hapd, sta);
-	}
-	return 0;
-}
-
 #ifdef CONFIG_WPS
 static int
 madwifi_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
@@ -994,7 +970,8 @@ madwifi_wireless_event_wireless(struct madwifi_driver_data *drv,
 
 		switch (iwe->cmd) {
 		case IWEVEXPIRED:
-			madwifi_del_sta(drv, (u8 *) iwe->u.addr.sa_data);
+			hostapd_notif_disassoc(drv->hapd,
+					       (u8 *) iwe->u.addr.sa_data);
 			break;
 		case IWEVREGISTERED:
 			madwifi_new_sta(drv, (u8 *) iwe->u.addr.sa_data);

+ 1 - 16
hostapd/driver_test.c

@@ -21,10 +21,7 @@
 #include "sha1.h"
 #include "eloop.h"
 #include "ieee802_1x.h"
-#include "sta_info.h"
 #include "wpa.h"
-#include "accounting.h"
-#include "radius/radius.h"
 #include "l2_packet/l2_packet.h"
 #include "ieee802_11.h"
 #include "hw_features.h"
@@ -522,24 +519,12 @@ static void test_driver_disassoc(struct test_driver_data *drv,
 				 struct sockaddr_un *from, socklen_t fromlen)
 {
 	struct test_client_socket *cli;
-	struct sta_info *sta;
 
 	cli = test_driver_get_cli(drv, from, fromlen);
 	if (!cli)
 		return;
 
-	hostapd_logger(drv->hapd, cli->addr, HOSTAPD_MODULE_IEEE80211,
-		       HOSTAPD_LEVEL_INFO, "disassociated");
-
-	sta = ap_get_sta(drv->hapd, cli->addr);
-	if (sta != NULL) {
-		sta->flags &= ~WLAN_STA_ASSOC;
-		wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
-		sta->acct_terminate_cause =
-			RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
-		ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
-		ap_free_sta(drv->hapd, sta);
-	}
+	hostapd_notif_disassoc(drv->hapd, cli->addr);
 }
 
 

+ 23 - 0
hostapd/hostapd.c

@@ -33,6 +33,7 @@
 #include "driver_i.h"
 #include "radius/radius_client.h"
 #include "radius/radius_server.h"
+#include "radius/radius.h"
 #include "wpa.h"
 #include "preauth.h"
 #include "wme.h"
@@ -367,6 +368,28 @@ skip_wpa_check:
 }
 
 
+void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
+{
+	struct sta_info *sta;
+
+	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
+		       HOSTAPD_LEVEL_INFO, "disassociated");
+
+	sta = ap_get_sta(hapd, addr);
+	if (sta == NULL) {
+		wpa_printf(MSG_DEBUG, "Disassociation notification for "
+			   "unknown STA " MACSTR, MAC2STR(addr));
+		return;
+	}
+
+	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
+	wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
+	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
+	ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
+	ap_free_sta(hapd, sta);
+}
+
+
 #ifdef EAP_SERVER
 static int hostapd_sim_db_cb_sta(struct hostapd_data *hapd,
 				 struct sta_info *sta, void *ctx)