Commit d582cffb authored by Johannes Berg's avatar Johannes Berg

nl80211/mac80211: support full station state in AP mode

Today, stations are added already associated. That is
inefficient if, for example, the driver has no room
for stations any more because then the station will
go through the entire auth/assoc handshake, only to
be kicked out afterwards.

To address this a bit better, at least with drivers
using the new station state callback, allow hostapd
to add stations in unauthenticated mode, just after
receiving the AUTH frame, before even replying. Thus
if there's no more space at that point, it can send
a negative auth frame back. It still needs to handle
later state transition errors though, of course.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent dfa674da
...@@ -1697,6 +1697,9 @@ enum nl80211_iftype { ...@@ -1697,6 +1697,9 @@ enum nl80211_iftype {
* flag can't be changed, it is only valid while adding a station, and * flag can't be changed, it is only valid while adding a station, and
* attempts to change it will silently be ignored (rather than rejected * attempts to change it will silently be ignored (rather than rejected
* as errors.) * as errors.)
* @NL80211_STA_FLAG_ASSOCIATED: station is associated; used with drivers
* that support %NL80211_FEATURE_FULL_AP_CLIENT_STATE to transition a
* previously added station into associated state
* @NL80211_STA_FLAG_MAX: highest station flag number currently defined * @NL80211_STA_FLAG_MAX: highest station flag number currently defined
* @__NL80211_STA_FLAG_AFTER_LAST: internal use * @__NL80211_STA_FLAG_AFTER_LAST: internal use
*/ */
...@@ -1708,6 +1711,7 @@ enum nl80211_sta_flags { ...@@ -1708,6 +1711,7 @@ enum nl80211_sta_flags {
NL80211_STA_FLAG_MFP, NL80211_STA_FLAG_MFP,
NL80211_STA_FLAG_AUTHENTICATED, NL80211_STA_FLAG_AUTHENTICATED,
NL80211_STA_FLAG_TDLS_PEER, NL80211_STA_FLAG_TDLS_PEER,
NL80211_STA_FLAG_ASSOCIATED,
/* keep last */ /* keep last */
__NL80211_STA_FLAG_AFTER_LAST, __NL80211_STA_FLAG_AFTER_LAST,
...@@ -3140,6 +3144,17 @@ enum nl80211_ap_sme_features { ...@@ -3140,6 +3144,17 @@ enum nl80211_ap_sme_features {
* setting * setting
* @NL80211_FEATURE_P2P_GO_OPPPS: P2P GO implementation supports opportunistic * @NL80211_FEATURE_P2P_GO_OPPPS: P2P GO implementation supports opportunistic
* powersave * powersave
* @NL80211_FEATURE_FULL_AP_CLIENT_STATE: The driver supports full state
* transitions for AP clients. Without this flag (and if the driver
* doesn't have the AP SME in the device) the driver supports adding
* stations only when they're associated and adds them in associated
* state (to later be transitioned into authorized), with this flag
* they should be added before even sending the authentication reply
* and then transitioned into authenticated, associated and authorized
* states using station flags.
* Note that even for drivers that support this, the default is to add
* stations in authenticated/associated state, so to add unauthenticated
* stations the authenticated/associated bits have to be set in the mask.
*/ */
enum nl80211_feature_flags { enum nl80211_feature_flags {
NL80211_FEATURE_SK_TX_STATUS = 1 << 0, NL80211_FEATURE_SK_TX_STATUS = 1 << 0,
...@@ -3155,6 +3170,7 @@ enum nl80211_feature_flags { ...@@ -3155,6 +3170,7 @@ enum nl80211_feature_flags {
NL80211_FEATURE_NEED_OBSS_SCAN = 1 << 10, NL80211_FEATURE_NEED_OBSS_SCAN = 1 << 10,
NL80211_FEATURE_P2P_GO_CTWIN = 1 << 11, NL80211_FEATURE_P2P_GO_CTWIN = 1 << 11,
NL80211_FEATURE_P2P_GO_OPPPS = 1 << 12, NL80211_FEATURE_P2P_GO_OPPPS = 1 << 12,
NL80211_FEATURE_FULL_AP_CLIENT_STATE = 1 << 13,
}; };
/** /**
......
...@@ -510,6 +510,7 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo) ...@@ -510,6 +510,7 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
BIT(NL80211_STA_FLAG_WME) | BIT(NL80211_STA_FLAG_WME) |
BIT(NL80211_STA_FLAG_MFP) | BIT(NL80211_STA_FLAG_MFP) |
BIT(NL80211_STA_FLAG_AUTHENTICATED) | BIT(NL80211_STA_FLAG_AUTHENTICATED) |
BIT(NL80211_STA_FLAG_ASSOCIATED) |
BIT(NL80211_STA_FLAG_TDLS_PEER); BIT(NL80211_STA_FLAG_TDLS_PEER);
if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED); sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
...@@ -521,6 +522,8 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo) ...@@ -521,6 +522,8 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP); sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
if (test_sta_flag(sta, WLAN_STA_AUTH)) if (test_sta_flag(sta, WLAN_STA_AUTH))
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED); sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
if (test_sta_flag(sta, WLAN_STA_ASSOC))
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
} }
...@@ -1077,69 +1080,89 @@ static void ieee80211_send_layer2_update(struct sta_info *sta) ...@@ -1077,69 +1080,89 @@ static void ieee80211_send_layer2_update(struct sta_info *sta)
netif_rx_ni(skb); netif_rx_ni(skb);
} }
static int sta_apply_parameters(struct ieee80211_local *local, static int sta_apply_auth_flags(struct ieee80211_local *local,
struct sta_info *sta, struct sta_info *sta,
struct station_parameters *params) u32 mask, u32 set)
{ {
int ret = 0; int ret;
u32 rates;
int i, j;
struct ieee80211_supported_band *sband;
struct ieee80211_sub_if_data *sdata = sta->sdata;
enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
u32 mask, set;
sband = local->hw.wiphy->bands[band];
mask = params->sta_flags_mask;
set = params->sta_flags_set;
/*
* In mesh mode, we can clear AUTHENTICATED flag but must
* also make ASSOCIATED follow appropriately for the driver
* API. See also below, after AUTHORIZED changes.
*/
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
/* cfg80211 should not allow this in non-mesh modes */
if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
return -EINVAL;
if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) && if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
!test_sta_flag(sta, WLAN_STA_AUTH)) { !test_sta_flag(sta, WLAN_STA_AUTH)) {
ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
if (ret) if (ret)
return ret; return ret;
}
if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
!test_sta_flag(sta, WLAN_STA_ASSOC)) {
ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
if (ret) if (ret)
return ret; return ret;
} }
}
if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
else
ret = 0;
if (ret) if (ret)
return ret; return ret;
} }
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
/* cfg80211 should not allow this in non-mesh modes */ !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif))) test_sta_flag(sta, WLAN_STA_ASSOC)) {
return -EINVAL;
if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
test_sta_flag(sta, WLAN_STA_AUTH)) {
ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
if (ret) if (ret)
return ret; return ret;
}
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
test_sta_flag(sta, WLAN_STA_AUTH)) {
ret = sta_info_move_state(sta, IEEE80211_STA_NONE); ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
if (ret) if (ret)
return ret; return ret;
} }
return 0;
}
static int sta_apply_parameters(struct ieee80211_local *local,
struct sta_info *sta,
struct station_parameters *params)
{
int ret = 0;
u32 rates;
int i, j;
struct ieee80211_supported_band *sband;
struct ieee80211_sub_if_data *sdata = sta->sdata;
enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
u32 mask, set;
sband = local->hw.wiphy->bands[band];
mask = params->sta_flags_mask;
set = params->sta_flags_set;
if (ieee80211_vif_is_mesh(&sdata->vif)) {
/*
* In mesh mode, ASSOCIATED isn't part of the nl80211
* API but must follow AUTHENTICATED for driver state.
*/
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
} }
ret = sta_apply_auth_flags(local, sta, mask, set);
if (ret)
return ret;
if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
...@@ -1273,6 +1296,10 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, ...@@ -1273,6 +1296,10 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
if (!sta) if (!sta)
return -ENOMEM; return -ENOMEM;
/*
* defaults -- if userspace wants something else we'll
* change it accordingly in sta_apply_parameters()
*/
sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
......
...@@ -541,7 +541,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, ...@@ -541,7 +541,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
wiphy->features |= NL80211_FEATURE_SK_TX_STATUS | wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
NL80211_FEATURE_SAE | NL80211_FEATURE_SAE |
NL80211_FEATURE_HT_IBSS | NL80211_FEATURE_HT_IBSS |
NL80211_FEATURE_VIF_TXPOWER; NL80211_FEATURE_VIF_TXPOWER |
NL80211_FEATURE_FULL_AP_CLIENT_STATE;
if (!ops->hw_scan) if (!ops->hw_scan)
wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN | wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
......
...@@ -3231,11 +3231,21 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) ...@@ -3231,11 +3231,21 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
/* accept only the listed bits */ /* accept only the listed bits */
if (params.sta_flags_mask & if (params.sta_flags_mask &
~(BIT(NL80211_STA_FLAG_AUTHORIZED) | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
BIT(NL80211_STA_FLAG_AUTHENTICATED) |
BIT(NL80211_STA_FLAG_ASSOCIATED) |
BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
BIT(NL80211_STA_FLAG_WME) | BIT(NL80211_STA_FLAG_WME) |
BIT(NL80211_STA_FLAG_MFP))) BIT(NL80211_STA_FLAG_MFP)))
return -EINVAL; return -EINVAL;
/* but authenticated/associated only if driver handles it */
if (!(rdev->wiphy.features &
NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
params.sta_flags_mask &
(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
BIT(NL80211_STA_FLAG_ASSOCIATED)))
return -EINVAL;
/* must be last in here for error handling */ /* must be last in here for error handling */
params.vlan = get_vlan(info, rdev); params.vlan = get_vlan(info, rdev);
if (IS_ERR(params.vlan)) if (IS_ERR(params.vlan))
...@@ -3393,17 +3403,31 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) ...@@ -3393,17 +3403,31 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
/* but don't bother the driver with it */ /* but don't bother the driver with it */
params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
/* allow authenticated/associated only if driver handles it */
if (!(rdev->wiphy.features &
NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
params.sta_flags_mask &
(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
BIT(NL80211_STA_FLAG_ASSOCIATED)))
return -EINVAL;
/* must be last in here for error handling */ /* must be last in here for error handling */
params.vlan = get_vlan(info, rdev); params.vlan = get_vlan(info, rdev);
if (IS_ERR(params.vlan)) if (IS_ERR(params.vlan))
return PTR_ERR(params.vlan); return PTR_ERR(params.vlan);
break; break;
case NL80211_IFTYPE_MESH_POINT: case NL80211_IFTYPE_MESH_POINT:
/* associated is disallowed */
if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
return -EINVAL;
/* TDLS peers cannot be added */ /* TDLS peers cannot be added */
if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
return -EINVAL; return -EINVAL;
break; break;
case NL80211_IFTYPE_STATION: case NL80211_IFTYPE_STATION:
/* associated is disallowed */
if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
return -EINVAL;
/* Only TDLS peers can be added */ /* Only TDLS peers can be added */
if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment