Browse Source

Map STA flags into values defined in driver.h

This removes need for including hostapd/sta_flags.h into driver
wrappers and removes any remaining dependencies between driver flags
and internal hostapd flags.
Jouni Malinen 15 years ago
parent
commit
0de39516ae

+ 15 - 0
hostapd/hostapd.c

@@ -1507,3 +1507,18 @@ int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
 	}
 	return hostapd_set_ieee8021x(hapd, &params);
 }
+
+
+int hostapd_sta_flags_to_drv(int flags)
+{
+	int res = 0;
+	if (flags & WLAN_STA_AUTHORIZED)
+		res |= WPA_STA_AUTHORIZED;
+	if (flags & WLAN_STA_WMM)
+		res |= WPA_STA_WMM;
+	if (flags & WLAN_STA_SHORT_PREAMBLE)
+		res |= WPA_STA_SHORT_PREAMBLE;
+	if (flags & WLAN_STA_MFP)
+		res |= WPA_STA_MFP;
+	return res;
+}

+ 1 - 0
hostapd/hostapd.h

@@ -189,6 +189,7 @@ int hostapd_register_probereq_cb(struct hostapd_data *hapd,
 				 void *ctx);
 int hostapd_set_drv_ieee8021x(struct hostapd_data *hapd, const char *ifname,
 			      int enabled);
+int hostapd_sta_flags_to_drv(int flags);
 
 int eap_server_register_methods(void);
 

+ 7 - 6
hostapd/ieee802_11.c

@@ -1466,7 +1466,7 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
 	struct sta_info *sta;
 	int new_assoc = 1;
 	struct ieee80211_ht_capabilities ht_cap;
-	int set_flags, flags_and, flags_or;
+	int set_flags, total_flags, flags_and, flags_or;
 
 	if (!ok) {
 		hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
@@ -1559,13 +1559,14 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
 		ap_sta_bind_vlan(hapd, sta, 0);
 	}
 
-	set_flags = WLAN_STA_SHORT_PREAMBLE | WLAN_STA_WMM | WLAN_STA_MFP;
+	total_flags = hostapd_sta_flags_to_drv(sta->flags);
+	set_flags = WPA_STA_SHORT_PREAMBLE | WPA_STA_WMM | WPA_STA_MFP;
 	if (!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
 	    sta->flags & WLAN_STA_AUTHORIZED)
-		set_flags |= WLAN_STA_AUTHORIZED;
-	flags_or = sta->flags & set_flags;
-	flags_and = sta->flags | ~set_flags;
-	hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
+		set_flags |= WPA_STA_AUTHORIZED;
+	flags_or = total_flags & set_flags;
+	flags_and = total_flags | ~set_flags;
+	hostapd_sta_set_flags(hapd, sta->addr, total_flags,
 			      flags_or, flags_and);
 
 	if (sta->auth_alg == WLAN_AUTH_FT)

+ 8 - 4
hostapd/ieee802_1x.c

@@ -91,8 +91,10 @@ void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
 			wpa_msg(hapd->msg_ctx, MSG_INFO,
 				AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
 		sta->flags |= WLAN_STA_AUTHORIZED;
-		res = hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
-					    WLAN_STA_AUTHORIZED, ~0);
+		res = hostapd_sta_set_flags(hapd, sta->addr,
+					    hostapd_sta_flags_to_drv(
+						    sta->flags),
+					    WPA_STA_AUTHORIZED, ~0);
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
 			       HOSTAPD_LEVEL_DEBUG, "authorizing port");
 	} else {
@@ -102,8 +104,10 @@ void ieee802_1x_set_sta_authorized(struct hostapd_data *hapd,
 				AP_STA_DISCONNECTED MACSTR,
 				MAC2STR(sta->addr));
 		sta->flags &= ~WLAN_STA_AUTHORIZED;
-		res = hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
-					    0, ~WLAN_STA_AUTHORIZED);
+		res = hostapd_sta_set_flags(hapd, sta->addr,
+					    hostapd_sta_flags_to_drv(
+						    sta->flags),
+					    0, ~WPA_STA_AUTHORIZED);
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
 			       HOSTAPD_LEVEL_DEBUG, "unauthorizing port");
 	}

+ 7 - 3
src/drivers/driver.h

@@ -494,6 +494,10 @@ struct wpa_bss_params {
 	int rsn_preauth;
 };
 
+#define WPA_STA_AUTHORIZED BIT(0)
+#define WPA_STA_WMM BIT(1)
+#define WPA_STA_SHORT_PREAMBLE BIT(2)
+#define WPA_STA_MFP BIT(3)
 
 /**
  * struct wpa_driver_ops - Driver interface API definition
@@ -1320,9 +1324,9 @@ struct wpa_driver_ops {
 	 * sta_set_flags - Set station flags (AP only)
 	 * @priv: Private driver interface data
 	 * @addr: Station address
-	 * @total_flags: Bitmap of all WLAN_STA_* flags currently set
-	 * @flags_or: Bitmap of WLAN_STA_* flags to add
-	 * @flags_and: Bitmap of WLAN_STA_* flags to us as a mask
+	 * @total_flags: Bitmap of all WPA_STA_* flags currently set
+	 * @flags_or: Bitmap of WPA_STA_* flags to add
+	 * @flags_and: Bitmap of WPA_STA_* flags to us as a mask
 	 * Returns: 0 on success, -1 on failure
 	 */
 	int (*sta_set_flags)(void *priv, const u8 *addr,

+ 2 - 3
src/drivers/driver_atheros.c

@@ -58,7 +58,6 @@
 
 #include "wireless_copy.h"
 
-#include "../hostapd/sta_flags.h"
 #include "driver.h"
 #include "eloop.h"
 #include "priv_netlink.h"
@@ -375,9 +374,9 @@ madwifi_sta_set_flags(void *priv, const u8 *addr, int total_flags,
 		      int flags_or, int flags_and)
 {
 	/* For now, only support setting Authorized flag */
-	if (flags_or & WLAN_STA_AUTHORIZED)
+	if (flags_or & WPA_STA_AUTHORIZED)
 		return madwifi_set_sta_authorized(priv, addr, 1);
-	if (!(flags_and & WLAN_STA_AUTHORIZED))
+	if (!(flags_and & WPA_STA_AUTHORIZED))
 		return madwifi_set_sta_authorized(priv, addr, 0);
 	return 0;
 }

+ 2 - 3
src/drivers/driver_bsd.c

@@ -154,7 +154,6 @@ bsd_set_ssid(int s, const char *ifname, const u8 *ssid, size_t ssid_len)
 #undef WPA_OUI_TYPE
 
 #include "l2_packet/l2_packet.h"
-#include "../../hostapd/sta_flags.h"
 
 struct bsd_driver_data {
 	struct hostapd_data *hapd;		/* back pointer */
@@ -382,9 +381,9 @@ bsd_sta_set_flags(void *priv, const u8 *addr, int total_flags, int flags_or,
 		  int flags_and)
 {
 	/* For now, only support setting Authorized flag */
-	if (flags_or & WLAN_STA_AUTHORIZED)
+	if (flags_or & WPA_STA_AUTHORIZED)
 		return bsd_set_sta_authorized(priv, addr, 1);
-	if (!(flags_and & WLAN_STA_AUTHORIZED))
+	if (!(flags_and & WPA_STA_AUTHORIZED))
 		return bsd_set_sta_authorized(priv, addr, 0);
 	return 0;
 }

+ 7 - 2
src/drivers/driver_hostap.c

@@ -30,7 +30,6 @@
 
 #include "priv_netlink.h"
 #include "common/ieee802_11_defs.h"
-#include "../../hostapd/sta_flags.h"
 
 
 /* MTU to be set for the wlan#ap device; this is mainly needed for IEEE 802.1X
@@ -359,6 +358,12 @@ static int hostap_sta_set_flags(void *priv, const u8 *addr,
 	struct hostap_driver_data *drv = priv;
 	struct prism2_hostapd_param param;
 
+	if (flags_or & WPA_STA_AUTHORIZED)
+		flags_or = BIT(5); /* WLAN_STA_AUTHORIZED */
+	if (!(flags_and & WPA_STA_AUTHORIZED))
+		flags_and = ~BIT(5);
+	else
+		flags_and = ~0;
 	memset(&param, 0, sizeof(param));
 	param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
 	memcpy(param.sta_addr, addr, ETH_ALEN);
@@ -693,7 +698,7 @@ static int hostap_sta_remove(void *priv, const u8 *addr)
 	struct hostap_driver_data *drv = priv;
 	struct prism2_hostapd_param param;
 
-	hostap_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
+	hostap_sta_set_flags(drv, addr, 0, 0, ~WPA_STA_AUTHORIZED);
 
 	memset(&param, 0, sizeof(param));
 	param.cmd = PRISM2_HOSTAPD_REMOVE_STA;

+ 2 - 3
src/drivers/driver_madwifi.c

@@ -74,7 +74,6 @@
 
 #include "priv_netlink.h"
 #include "l2_packet/l2_packet.h"
-#include "../../hostapd/sta_flags.h"
 
 
 struct madwifi_driver_data {
@@ -420,9 +419,9 @@ madwifi_sta_set_flags(void *priv, const u8 *addr, int total_flags,
 		      int flags_or, int flags_and)
 {
 	/* For now, only support setting Authorized flag */
-	if (flags_or & WLAN_STA_AUTHORIZED)
+	if (flags_or & WPA_STA_AUTHORIZED)
 		return madwifi_set_sta_authorized(priv, addr, 1);
-	if (!(flags_and & WLAN_STA_AUTHORIZED))
+	if (!(flags_and & WPA_STA_AUTHORIZED))
 		return madwifi_set_sta_authorized(priv, addr, 0);
 	return 0;
 }

+ 9 - 11
src/drivers/driver_nl80211.c

@@ -35,8 +35,6 @@
 #include <linux/filter.h>
 #include "radiotap.h"
 #include "radiotap_iter.h"
-
-#include "../../hostapd/sta_flags.h"
 #endif /* CONFIG_AP || HOSTAPD */
 
 #ifdef CONFIG_LIBNL20
@@ -3252,7 +3250,7 @@ static int wpa_driver_nl80211_hapd_send_eapol(
 	u8 *pos;
 	int res;
 #if 0 /* FIX */
-	int qos = sta->flags & WLAN_STA_WME;
+	int qos = sta->flags & WPA_STA_WMM;
 #else
 	int qos = 0;
 #endif
@@ -3314,13 +3312,13 @@ static u32 sta_flags_nl80211(int flags)
 {
 	u32 f = 0;
 
-	if (flags & WLAN_STA_AUTHORIZED)
+	if (flags & WPA_STA_AUTHORIZED)
 		f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
-	if (flags & WLAN_STA_WMM)
+	if (flags & WPA_STA_WMM)
 		f |= BIT(NL80211_STA_FLAG_WME);
-	if (flags & WLAN_STA_SHORT_PREAMBLE)
+	if (flags & WPA_STA_SHORT_PREAMBLE)
 		f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
-	if (flags & WLAN_STA_MFP)
+	if (flags & WPA_STA_MFP)
 		f |= BIT(NL80211_STA_FLAG_MFP);
 
 	return f;
@@ -3356,16 +3354,16 @@ static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
 	 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
 	 * can be removed eventually.
 	 */
-	if (total_flags & WLAN_STA_AUTHORIZED)
+	if (total_flags & WPA_STA_AUTHORIZED)
 		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
 
-	if (total_flags & WLAN_STA_WMM)
+	if (total_flags & WPA_STA_WMM)
 		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
 
-	if (total_flags & WLAN_STA_SHORT_PREAMBLE)
+	if (total_flags & WPA_STA_SHORT_PREAMBLE)
 		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
 
-	if (total_flags & WLAN_STA_MFP)
+	if (total_flags & WPA_STA_MFP)
 		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
 
 	if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))