Skip to content

Commit d582cff

Browse files
committed
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: Johannes Berg <johannes.berg@intel.com>
1 parent dfa674d commit d582cff

4 files changed

Lines changed: 113 additions & 45 deletions

File tree

‎include/uapi/linux/nl80211.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,9 @@ enum nl80211_iftype {
16971697
* flag can't be changed, it is only valid while adding a station, and
16981698
* attempts to change it will silently be ignored (rather than rejected
16991699
* as errors.)
1700+
* @NL80211_STA_FLAG_ASSOCIATED: station is associated; used with drivers
1701+
* that support %NL80211_FEATURE_FULL_AP_CLIENT_STATE to transition a
1702+
* previously added station into associated state
17001703
* @NL80211_STA_FLAG_MAX: highest station flag number currently defined
17011704
* @__NL80211_STA_FLAG_AFTER_LAST: internal use
17021705
*/
@@ -1708,6 +1711,7 @@ enum nl80211_sta_flags {
17081711
NL80211_STA_FLAG_MFP,
17091712
NL80211_STA_FLAG_AUTHENTICATED,
17101713
NL80211_STA_FLAG_TDLS_PEER,
1714+
NL80211_STA_FLAG_ASSOCIATED,
17111715

17121716
/* keep last */
17131717
__NL80211_STA_FLAG_AFTER_LAST,
@@ -3140,6 +3144,17 @@ enum nl80211_ap_sme_features {
31403144
* setting
31413145
* @NL80211_FEATURE_P2P_GO_OPPPS: P2P GO implementation supports opportunistic
31423146
* powersave
3147+
* @NL80211_FEATURE_FULL_AP_CLIENT_STATE: The driver supports full state
3148+
* transitions for AP clients. Without this flag (and if the driver
3149+
* doesn't have the AP SME in the device) the driver supports adding
3150+
* stations only when they're associated and adds them in associated
3151+
* state (to later be transitioned into authorized), with this flag
3152+
* they should be added before even sending the authentication reply
3153+
* and then transitioned into authenticated, associated and authorized
3154+
* states using station flags.
3155+
* Note that even for drivers that support this, the default is to add
3156+
* stations in authenticated/associated state, so to add unauthenticated
3157+
* stations the authenticated/associated bits have to be set in the mask.
31433158
*/
31443159
enum nl80211_feature_flags {
31453160
NL80211_FEATURE_SK_TX_STATUS = 1 << 0,
@@ -3155,6 +3170,7 @@ enum nl80211_feature_flags {
31553170
NL80211_FEATURE_NEED_OBSS_SCAN = 1 << 10,
31563171
NL80211_FEATURE_P2P_GO_CTWIN = 1 << 11,
31573172
NL80211_FEATURE_P2P_GO_OPPPS = 1 << 12,
3173+
NL80211_FEATURE_FULL_AP_CLIENT_STATE = 1 << 13,
31583174
};
31593175

31603176
/**

‎net/mac80211/cfg.c‎

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
510510
BIT(NL80211_STA_FLAG_WME) |
511511
BIT(NL80211_STA_FLAG_MFP) |
512512
BIT(NL80211_STA_FLAG_AUTHENTICATED) |
513+
BIT(NL80211_STA_FLAG_ASSOCIATED) |
513514
BIT(NL80211_STA_FLAG_TDLS_PEER);
514515
if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
515516
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)
521522
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
522523
if (test_sta_flag(sta, WLAN_STA_AUTH))
523524
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
525+
if (test_sta_flag(sta, WLAN_STA_ASSOC))
526+
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
524527
if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
525528
sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
526529
}
@@ -1077,6 +1080,58 @@ static void ieee80211_send_layer2_update(struct sta_info *sta)
10771080
netif_rx_ni(skb);
10781081
}
10791082

1083+
static int sta_apply_auth_flags(struct ieee80211_local *local,
1084+
struct sta_info *sta,
1085+
u32 mask, u32 set)
1086+
{
1087+
int ret;
1088+
1089+
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1090+
set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1091+
!test_sta_flag(sta, WLAN_STA_AUTH)) {
1092+
ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1093+
if (ret)
1094+
return ret;
1095+
}
1096+
1097+
if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1098+
set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1099+
!test_sta_flag(sta, WLAN_STA_ASSOC)) {
1100+
ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1101+
if (ret)
1102+
return ret;
1103+
}
1104+
1105+
if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1106+
if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1107+
ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1108+
else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1109+
ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1110+
else
1111+
ret = 0;
1112+
if (ret)
1113+
return ret;
1114+
}
1115+
1116+
if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1117+
!(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1118+
test_sta_flag(sta, WLAN_STA_ASSOC)) {
1119+
ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1120+
if (ret)
1121+
return ret;
1122+
}
1123+
1124+
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1125+
!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1126+
test_sta_flag(sta, WLAN_STA_AUTH)) {
1127+
ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1128+
if (ret)
1129+
return ret;
1130+
}
1131+
1132+
return 0;
1133+
}
1134+
10801135
static int sta_apply_parameters(struct ieee80211_local *local,
10811136
struct sta_info *sta,
10821137
struct station_parameters *params)
@@ -1094,52 +1149,20 @@ static int sta_apply_parameters(struct ieee80211_local *local,
10941149
mask = params->sta_flags_mask;
10951150
set = params->sta_flags_set;
10961151

1097-
/*
1098-
* In mesh mode, we can clear AUTHENTICATED flag but must
1099-
* also make ASSOCIATED follow appropriately for the driver
1100-
* API. See also below, after AUTHORIZED changes.
1101-
*/
1102-
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1103-
/* cfg80211 should not allow this in non-mesh modes */
1104-
if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1105-
return -EINVAL;
1106-
1107-
if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1108-
!test_sta_flag(sta, WLAN_STA_AUTH)) {
1109-
ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1110-
if (ret)
1111-
return ret;
1112-
ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1113-
if (ret)
1114-
return ret;
1115-
}
1116-
}
1117-
1118-
if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1119-
if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1120-
ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1121-
else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1122-
ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1123-
if (ret)
1124-
return ret;
1125-
}
1126-
1127-
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1128-
/* cfg80211 should not allow this in non-mesh modes */
1129-
if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1130-
return -EINVAL;
1131-
1132-
if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1133-
test_sta_flag(sta, WLAN_STA_AUTH)) {
1134-
ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1135-
if (ret)
1136-
return ret;
1137-
ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1138-
if (ret)
1139-
return ret;
1140-
}
1152+
if (ieee80211_vif_is_mesh(&sdata->vif)) {
1153+
/*
1154+
* In mesh mode, ASSOCIATED isn't part of the nl80211
1155+
* API but must follow AUTHENTICATED for driver state.
1156+
*/
1157+
if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1158+
mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1159+
if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1160+
set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
11411161
}
11421162

1163+
ret = sta_apply_auth_flags(local, sta, mask, set);
1164+
if (ret)
1165+
return ret;
11431166

11441167
if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
11451168
if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
@@ -1273,6 +1296,10 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
12731296
if (!sta)
12741297
return -ENOMEM;
12751298

1299+
/*
1300+
* defaults -- if userspace wants something else we'll
1301+
* change it accordingly in sta_apply_parameters()
1302+
*/
12761303
sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
12771304
sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
12781305

‎net/mac80211/main.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
541541
wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
542542
NL80211_FEATURE_SAE |
543543
NL80211_FEATURE_HT_IBSS |
544-
NL80211_FEATURE_VIF_TXPOWER;
544+
NL80211_FEATURE_VIF_TXPOWER |
545+
NL80211_FEATURE_FULL_AP_CLIENT_STATE;
545546

546547
if (!ops->hw_scan)
547548
wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |

‎net/wireless/nl80211.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,11 +3231,21 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
32313231
/* accept only the listed bits */
32323232
if (params.sta_flags_mask &
32333233
~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3234+
BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3235+
BIT(NL80211_STA_FLAG_ASSOCIATED) |
32343236
BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
32353237
BIT(NL80211_STA_FLAG_WME) |
32363238
BIT(NL80211_STA_FLAG_MFP)))
32373239
return -EINVAL;
32383240

3241+
/* but authenticated/associated only if driver handles it */
3242+
if (!(rdev->wiphy.features &
3243+
NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3244+
params.sta_flags_mask &
3245+
(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3246+
BIT(NL80211_STA_FLAG_ASSOCIATED)))
3247+
return -EINVAL;
3248+
32393249
/* must be last in here for error handling */
32403250
params.vlan = get_vlan(info, rdev);
32413251
if (IS_ERR(params.vlan))
@@ -3393,17 +3403,31 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
33933403
/* but don't bother the driver with it */
33943404
params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
33953405

3406+
/* allow authenticated/associated only if driver handles it */
3407+
if (!(rdev->wiphy.features &
3408+
NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3409+
params.sta_flags_mask &
3410+
(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3411+
BIT(NL80211_STA_FLAG_ASSOCIATED)))
3412+
return -EINVAL;
3413+
33963414
/* must be last in here for error handling */
33973415
params.vlan = get_vlan(info, rdev);
33983416
if (IS_ERR(params.vlan))
33993417
return PTR_ERR(params.vlan);
34003418
break;
34013419
case NL80211_IFTYPE_MESH_POINT:
3420+
/* associated is disallowed */
3421+
if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3422+
return -EINVAL;
34023423
/* TDLS peers cannot be added */
34033424
if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
34043425
return -EINVAL;
34053426
break;
34063427
case NL80211_IFTYPE_STATION:
3428+
/* associated is disallowed */
3429+
if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
3430+
return -EINVAL;
34073431
/* Only TDLS peers can be added */
34083432
if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
34093433
return -EINVAL;

0 commit comments

Comments
 (0)