Skip to content

Commit f62fab7

Browse files
committed
cfg80211: refactor association parameters
cfg80211_mlme_assoc() has grown far too many arguments, make the caller build almost all of the driver struct and pass that to the function instead. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent dd5ecfe commit f62fab7

4 files changed

Lines changed: 63 additions & 104 deletions

File tree

‎net/wireless/core.h‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,15 @@ int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
330330
int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
331331
struct net_device *dev,
332332
struct ieee80211_channel *chan,
333-
const u8 *bssid, const u8 *prev_bssid,
333+
const u8 *bssid,
334334
const u8 *ssid, int ssid_len,
335-
const u8 *ie, int ie_len, bool use_mfp,
336-
struct cfg80211_crypto_settings *crypt,
337-
u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
338-
struct ieee80211_ht_cap *ht_capa_mask,
339-
struct ieee80211_vht_cap *vht_capa,
340-
struct ieee80211_vht_cap *vht_capa_mask);
335+
struct cfg80211_assoc_request *req);
341336
int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
342-
struct net_device *dev, struct ieee80211_channel *chan,
343-
const u8 *bssid, const u8 *prev_bssid,
337+
struct net_device *dev,
338+
struct ieee80211_channel *chan,
339+
const u8 *bssid,
344340
const u8 *ssid, int ssid_len,
345-
const u8 *ie, int ie_len, bool use_mfp,
346-
struct cfg80211_crypto_settings *crypt,
347-
u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
348-
struct ieee80211_ht_cap *ht_capa_mask,
349-
struct ieee80211_vht_cap *vht_capa,
350-
struct ieee80211_vht_cap *vht_capa_mask);
341+
struct cfg80211_assoc_request *req);
351342
int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
352343
struct net_device *dev, const u8 *bssid,
353344
const u8 *ie, int ie_len, u16 reason,

‎net/wireless/mlme.c‎

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -363,26 +363,18 @@ void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
363363
int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
364364
struct net_device *dev,
365365
struct ieee80211_channel *chan,
366-
const u8 *bssid, const u8 *prev_bssid,
366+
const u8 *bssid,
367367
const u8 *ssid, int ssid_len,
368-
const u8 *ie, int ie_len, bool use_mfp,
369-
struct cfg80211_crypto_settings *crypt,
370-
u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
371-
struct ieee80211_ht_cap *ht_capa_mask,
372-
struct ieee80211_vht_cap *vht_capa,
373-
struct ieee80211_vht_cap *vht_capa_mask)
368+
struct cfg80211_assoc_request *req)
374369
{
375370
struct wireless_dev *wdev = dev->ieee80211_ptr;
376-
struct cfg80211_assoc_request req;
377371
int err;
378372
bool was_connected = false;
379373

380374
ASSERT_WDEV_LOCK(wdev);
381375

382-
memset(&req, 0, sizeof(req));
383-
384-
if (wdev->current_bss && prev_bssid &&
385-
ether_addr_equal(wdev->current_bss->pub.bssid, prev_bssid)) {
376+
if (wdev->current_bss && req->prev_bssid &&
377+
ether_addr_equal(wdev->current_bss->pub.bssid, req->prev_bssid)) {
386378
/*
387379
* Trying to reassociate: Allow this to proceed and let the old
388380
* association to be dropped when the new one is completed.
@@ -394,47 +386,30 @@ int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
394386
} else if (wdev->current_bss)
395387
return -EALREADY;
396388

397-
req.ie = ie;
398-
req.ie_len = ie_len;
399-
memcpy(&req.crypto, crypt, sizeof(req.crypto));
400-
req.use_mfp = use_mfp;
401-
req.prev_bssid = prev_bssid;
402-
req.flags = assoc_flags;
403-
if (ht_capa)
404-
memcpy(&req.ht_capa, ht_capa, sizeof(req.ht_capa));
405-
if (ht_capa_mask)
406-
memcpy(&req.ht_capa_mask, ht_capa_mask,
407-
sizeof(req.ht_capa_mask));
408-
cfg80211_oper_and_ht_capa(&req.ht_capa_mask,
389+
cfg80211_oper_and_ht_capa(&req->ht_capa_mask,
409390
rdev->wiphy.ht_capa_mod_mask);
410-
if (vht_capa)
411-
memcpy(&req.vht_capa, vht_capa, sizeof(req.vht_capa));
412-
if (vht_capa_mask)
413-
memcpy(&req.vht_capa_mask, vht_capa_mask,
414-
sizeof(req.vht_capa_mask));
415-
cfg80211_oper_and_vht_capa(&req.vht_capa_mask,
391+
cfg80211_oper_and_vht_capa(&req->vht_capa_mask,
416392
rdev->wiphy.vht_capa_mod_mask);
417393

418-
req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
419-
WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
420-
if (!req.bss) {
394+
req->bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
395+
WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
396+
if (!req->bss) {
421397
if (was_connected)
422398
wdev->sme_state = CFG80211_SME_CONNECTED;
423399
return -ENOENT;
424400
}
425401

426-
err = cfg80211_can_use_chan(rdev, wdev, req.bss->channel,
427-
CHAN_MODE_SHARED);
402+
err = cfg80211_can_use_chan(rdev, wdev, chan, CHAN_MODE_SHARED);
428403
if (err)
429404
goto out;
430405

431-
err = rdev_assoc(rdev, dev, &req);
406+
err = rdev_assoc(rdev, dev, req);
432407

433408
out:
434409
if (err) {
435410
if (was_connected)
436411
wdev->sme_state = CFG80211_SME_CONNECTED;
437-
cfg80211_put_bss(&rdev->wiphy, req.bss);
412+
cfg80211_put_bss(&rdev->wiphy, req->bss);
438413
}
439414

440415
return err;
@@ -443,24 +418,17 @@ int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
443418
int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
444419
struct net_device *dev,
445420
struct ieee80211_channel *chan,
446-
const u8 *bssid, const u8 *prev_bssid,
421+
const u8 *bssid,
447422
const u8 *ssid, int ssid_len,
448-
const u8 *ie, int ie_len, bool use_mfp,
449-
struct cfg80211_crypto_settings *crypt,
450-
u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
451-
struct ieee80211_ht_cap *ht_capa_mask,
452-
struct ieee80211_vht_cap *vht_capa,
453-
struct ieee80211_vht_cap *vht_capa_mask)
423+
struct cfg80211_assoc_request *req)
454424
{
455425
struct wireless_dev *wdev = dev->ieee80211_ptr;
456426
int err;
457427

458428
mutex_lock(&rdev->devlist_mtx);
459429
wdev_lock(wdev);
460-
err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
461-
ssid, ssid_len, ie, ie_len, use_mfp, crypt,
462-
assoc_flags, ht_capa, ht_capa_mask,
463-
vht_capa, vht_capa_mask);
430+
err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid,
431+
ssid, ssid_len, req);
464432
wdev_unlock(wdev);
465433
mutex_unlock(&rdev->devlist_mtx);
466434

‎net/wireless/nl80211.c‎

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5984,16 +5984,10 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
59845984
{
59855985
struct cfg80211_registered_device *rdev = info->user_ptr[0];
59865986
struct net_device *dev = info->user_ptr[1];
5987-
struct cfg80211_crypto_settings crypto;
59885987
struct ieee80211_channel *chan;
5989-
const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL;
5990-
int err, ssid_len, ie_len = 0;
5991-
bool use_mfp = false;
5992-
u32 flags = 0;
5993-
struct ieee80211_ht_cap *ht_capa = NULL;
5994-
struct ieee80211_ht_cap *ht_capa_mask = NULL;
5995-
struct ieee80211_vht_cap *vht_capa = NULL;
5996-
struct ieee80211_vht_cap *vht_capa_mask = NULL;
5988+
struct cfg80211_assoc_request req = {};
5989+
const u8 *bssid, *ssid;
5990+
int err, ssid_len = 0;
59975991

59985992
if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
59995993
return -EINVAL;
@@ -6021,54 +6015,58 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
60216015
ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
60226016

60236017
if (info->attrs[NL80211_ATTR_IE]) {
6024-
ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6025-
ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6018+
req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6019+
req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
60266020
}
60276021

60286022
if (info->attrs[NL80211_ATTR_USE_MFP]) {
60296023
enum nl80211_mfp mfp =
60306024
nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
60316025
if (mfp == NL80211_MFP_REQUIRED)
6032-
use_mfp = true;
6026+
req.use_mfp = true;
60336027
else if (mfp != NL80211_MFP_NO)
60346028
return -EINVAL;
60356029
}
60366030

60376031
if (info->attrs[NL80211_ATTR_PREV_BSSID])
6038-
prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
6032+
req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
60396033

60406034
if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6041-
flags |= ASSOC_REQ_DISABLE_HT;
6035+
req.flags |= ASSOC_REQ_DISABLE_HT;
60426036

60436037
if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6044-
ht_capa_mask =
6045-
nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]);
6038+
memcpy(&req.ht_capa_mask,
6039+
nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6040+
sizeof(req.ht_capa_mask));
60466041

60476042
if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6048-
if (!ht_capa_mask)
6043+
if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
60496044
return -EINVAL;
6050-
ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6045+
memcpy(&req.ht_capa,
6046+
nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6047+
sizeof(req.ht_capa));
60516048
}
60526049

60536050
if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
6054-
flags |= ASSOC_REQ_DISABLE_VHT;
6051+
req.flags |= ASSOC_REQ_DISABLE_VHT;
60556052

60566053
if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
6057-
vht_capa_mask =
6058-
nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]);
6054+
memcpy(&req.vht_capa_mask,
6055+
nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6056+
sizeof(req.vht_capa_mask));
60596057

60606058
if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
6061-
if (!vht_capa_mask)
6059+
if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
60626060
return -EINVAL;
6063-
vht_capa = nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6061+
memcpy(&req.vht_capa,
6062+
nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6063+
sizeof(req.vht_capa));
60646064
}
60656065

6066-
err = nl80211_crypto_settings(rdev, info, &crypto, 1);
6066+
err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
60676067
if (!err)
6068-
err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
6069-
ssid, ssid_len, ie, ie_len, use_mfp,
6070-
&crypto, flags, ht_capa, ht_capa_mask,
6071-
vht_capa, vht_capa_mask);
6068+
err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6069+
ssid, ssid_len, &req);
60726070

60736071
return err;
60746072
}

‎net/wireless/sme.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int cfg80211_conn_do_work(struct wireless_dev *wdev)
159159
{
160160
struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
161161
struct cfg80211_connect_params *params;
162-
const u8 *prev_bssid = NULL;
162+
struct cfg80211_assoc_request req = {};
163163
int err;
164164

165165
ASSERT_WDEV_LOCK(wdev);
@@ -186,18 +186,20 @@ static int cfg80211_conn_do_work(struct wireless_dev *wdev)
186186
BUG_ON(!rdev->ops->assoc);
187187
wdev->conn->state = CFG80211_CONN_ASSOCIATING;
188188
if (wdev->conn->prev_bssid_valid)
189-
prev_bssid = wdev->conn->prev_bssid;
190-
err = __cfg80211_mlme_assoc(rdev, wdev->netdev,
191-
params->channel, params->bssid,
192-
prev_bssid,
193-
params->ssid, params->ssid_len,
194-
params->ie, params->ie_len,
195-
params->mfp != NL80211_MFP_NO,
196-
&params->crypto,
197-
params->flags, &params->ht_capa,
198-
&params->ht_capa_mask,
199-
&params->vht_capa,
200-
&params->vht_capa_mask);
189+
req.prev_bssid = wdev->conn->prev_bssid;
190+
req.ie = params->ie;
191+
req.ie_len = params->ie_len;
192+
req.use_mfp = params->mfp != NL80211_MFP_NO;
193+
req.crypto = params->crypto;
194+
req.flags = params->flags;
195+
req.ht_capa = params->ht_capa;
196+
req.ht_capa_mask = params->ht_capa_mask;
197+
req.vht_capa = params->vht_capa;
198+
req.vht_capa_mask = params->vht_capa_mask;
199+
200+
err = __cfg80211_mlme_assoc(rdev, wdev->netdev, params->channel,
201+
params->bssid, params->ssid,
202+
params->ssid_len, &req);
201203
if (err)
202204
__cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
203205
NULL, 0,

0 commit comments

Comments
 (0)