Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cfg80211: unify cfg80211_roamed() and cfg80211_roamed_bss()

cfg80211_roamed() and cfg80211_roamed_bss() take the same arguments
except that cfg80211_roamed() requires the BSSID and
cfg80211_roamed_bss() requires the bss entry.

Unify the two functions by using a struct for driver initiated
roaming information so that either the BSSID or the bss entry can be
passed as an argument to the unified function.

Signed-off-by: Avraham Stern <avraham.stern@intel.com>
[modified the ath6k, brcm80211, rndis and wlan-ng drivers accordingly]
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
[modify brcmfmac to remove the useless cast, spotted by Arend]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Avraham Stern and committed by
Johannes Berg
29ce6ecb 21a8e9dd

+123 -129
+8 -2
drivers/net/wireless/ath/ath6kl/cfg80211.c
··· 806 806 WLAN_STATUS_SUCCESS, GFP_KERNEL); 807 807 cfg80211_put_bss(ar->wiphy, bss); 808 808 } else if (vif->sme_state == SME_CONNECTED) { 809 + struct cfg80211_roam_info roam_info = { 810 + .bss = bss, 811 + .req_ie = assoc_req_ie, 812 + .req_ie_len = assoc_req_len, 813 + .resp_ie = assoc_resp_ie, 814 + .resp_ie_len = assoc_resp_len, 815 + }; 809 816 /* inform roam event to cfg80211 */ 810 - cfg80211_roamed_bss(vif->ndev, bss, assoc_req_ie, assoc_req_len, 811 - assoc_resp_ie, assoc_resp_len, GFP_KERNEL); 817 + cfg80211_roamed(vif->ndev, &roam_info, GFP_KERNEL); 812 818 } 813 819 } 814 820
+10 -3
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
··· 5359 5359 struct ieee80211_supported_band *band; 5360 5360 struct brcmf_bss_info_le *bi; 5361 5361 struct brcmu_chan ch; 5362 + struct cfg80211_roam_info roam_info = {}; 5362 5363 u32 freq; 5363 5364 s32 err = 0; 5364 5365 u8 *buf; ··· 5398 5397 5399 5398 done: 5400 5399 kfree(buf); 5401 - cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid, 5402 - conn_info->req_ie, conn_info->req_ie_len, 5403 - conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); 5400 + 5401 + roam_info.channel = notify_channel; 5402 + roam_info.bssid = profile->bssid; 5403 + roam_info.req_ie = conn_info->req_ie; 5404 + roam_info.req_ie_len = conn_info->req_ie_len; 5405 + roam_info.resp_ie = conn_info->resp_ie; 5406 + roam_info.resp_ie_len = conn_info->resp_ie_len; 5407 + 5408 + cfg80211_roamed(ndev, &roam_info, GFP_KERNEL); 5404 5409 brcmf_dbg(CONN, "Report roaming result\n"); 5405 5410 5406 5411 set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
+13 -6
drivers/net/wireless/rndis_wlan.c
··· 2830 2830 } 2831 2831 2832 2832 if (priv->infra_mode == NDIS_80211_INFRA_INFRA) { 2833 - if (!roamed) 2833 + if (!roamed) { 2834 2834 cfg80211_connect_result(usbdev->net, bssid, req_ie, 2835 2835 req_ie_len, resp_ie, 2836 2836 resp_ie_len, 0, GFP_KERNEL); 2837 - else 2838 - cfg80211_roamed(usbdev->net, 2839 - get_current_channel(usbdev, NULL), 2840 - bssid, req_ie, req_ie_len, 2841 - resp_ie, resp_ie_len, GFP_KERNEL); 2837 + } else { 2838 + struct cfg80211_roam_info roam_info = { 2839 + .channel = get_current_channel(usbdev, NULL), 2840 + .bssid = bssid, 2841 + .req_ie = req_ie, 2842 + .req_ie_len = req_ie_len, 2843 + .resp_ie = resp_ie, 2844 + .resp_ie_len = resp_ie_len, 2845 + }; 2846 + 2847 + cfg80211_roamed(usbdev->net, &roam_info, GFP_KERNEL); 2848 + } 2842 2849 } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC) 2843 2850 cfg80211_ibss_joined(usbdev->net, bssid, 2844 2851 get_current_channel(usbdev, NULL),
+5 -2
drivers/staging/wlan-ng/cfg80211.c
··· 666 666 667 667 void prism2_roamed(struct wlandevice *wlandev) 668 668 { 669 - cfg80211_roamed(wlandev->netdev, NULL, wlandev->bssid, 670 - NULL, 0, NULL, 0, GFP_KERNEL); 669 + struct cfg80211_roam_info roam_info = { 670 + .bssid = wlandev->bssid, 671 + }; 672 + 673 + cfg80211_roamed(wlandev->netdev, &roam_info, GFP_KERNEL); 671 674 } 672 675 673 676 /* Structures for declaring wiphy interface */
+34 -40
include/net/cfg80211.h
··· 2686 2686 * indication of requesting reassociation. 2687 2687 * In both the driver-initiated and new connect() call initiated roaming 2688 2688 * cases, the result of roaming is indicated with a call to 2689 - * cfg80211_roamed() or cfg80211_roamed_bss(). 2690 - * (invoked with the wireless_dev mutex held) 2689 + * cfg80211_roamed(). (invoked with the wireless_dev mutex held) 2691 2690 * @update_connect_params: Update the connect parameters while connected to a 2692 2691 * BSS. The updated parameters can be used by driver/firmware for 2693 2692 * subsequent BSS selection (roaming) decisions and to form the ··· 5389 5390 } 5390 5391 5391 5392 /** 5393 + * struct cfg80211_roam_info - driver initiated roaming information 5394 + * 5395 + * @channel: the channel of the new AP 5396 + * @bss: entry of bss to which STA got roamed (may be %NULL if %bssid is set) 5397 + * @bssid: the BSSID of the new AP (may be %NULL if %bss is set) 5398 + * @req_ie: association request IEs (maybe be %NULL) 5399 + * @req_ie_len: association request IEs length 5400 + * @resp_ie: association response IEs (may be %NULL) 5401 + * @resp_ie_len: assoc response IEs length 5402 + */ 5403 + struct cfg80211_roam_info { 5404 + struct ieee80211_channel *channel; 5405 + struct cfg80211_bss *bss; 5406 + const u8 *bssid; 5407 + const u8 *req_ie; 5408 + size_t req_ie_len; 5409 + const u8 *resp_ie; 5410 + size_t resp_ie_len; 5411 + }; 5412 + 5413 + /** 5392 5414 * cfg80211_roamed - notify cfg80211 of roaming 5393 5415 * 5394 5416 * @dev: network device 5395 - * @channel: the channel of the new AP 5396 - * @bssid: the BSSID of the new AP 5397 - * @req_ie: association request IEs (maybe be %NULL) 5398 - * @req_ie_len: association request IEs length 5399 - * @resp_ie: association response IEs (may be %NULL) 5400 - * @resp_ie_len: assoc response IEs length 5417 + * @info: information about the new BSS. struct &cfg80211_roam_info. 5401 5418 * @gfp: allocation flags 5402 5419 * 5403 - * It should be called by the underlying driver whenever it roamed 5404 - * from one AP to another while connected. 5405 - */ 5406 - void cfg80211_roamed(struct net_device *dev, 5407 - struct ieee80211_channel *channel, 5408 - const u8 *bssid, 5409 - const u8 *req_ie, size_t req_ie_len, 5410 - const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp); 5411 - 5412 - /** 5413 - * cfg80211_roamed_bss - notify cfg80211 of roaming 5414 - * 5415 - * @dev: network device 5416 - * @bss: entry of bss to which STA got roamed 5417 - * @req_ie: association request IEs (maybe be %NULL) 5418 - * @req_ie_len: association request IEs length 5419 - * @resp_ie: association response IEs (may be %NULL) 5420 - * @resp_ie_len: assoc response IEs length 5421 - * @gfp: allocation flags 5422 - * 5423 - * This is just a wrapper to notify cfg80211 of roaming event with driver 5424 - * passing bss to avoid a race in timeout of the bss entry. It should be 5425 - * called by the underlying driver whenever it roamed from one AP to another 5426 - * while connected. Drivers which have roaming implemented in firmware 5427 - * may use this function to avoid a race in bss entry timeout where the bss 5428 - * entry of the new AP is seen in the driver, but gets timed out by the time 5429 - * it is accessed in __cfg80211_roamed() due to delay in scheduling 5420 + * This function may be called with the driver passing either the BSSID of the 5421 + * new AP or passing the bss entry to avoid a race in timeout of the bss entry. 5422 + * It should be called by the underlying driver whenever it roamed from one AP 5423 + * to another while connected. Drivers which have roaming implemented in 5424 + * firmware should pass the bss entry to avoid a race in bss entry timeout where 5425 + * the bss entry of the new AP is seen in the driver, but gets timed out by the 5426 + * time it is accessed in __cfg80211_roamed() due to delay in scheduling 5430 5427 * rdev->event_work. In case of any failures, the reference is released 5431 - * either in cfg80211_roamed_bss() or in __cfg80211_romed(), Otherwise, 5432 - * it will be released while diconneting from the current bss. 5428 + * either in cfg80211_roamed() or in __cfg80211_romed(), Otherwise, it will be 5429 + * released while diconneting from the current bss. 5433 5430 */ 5434 - void cfg80211_roamed_bss(struct net_device *dev, struct cfg80211_bss *bss, 5435 - const u8 *req_ie, size_t req_ie_len, 5436 - const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp); 5431 + void cfg80211_roamed(struct net_device *dev, struct cfg80211_roam_info *info, 5432 + gfp_t gfp); 5437 5433 5438 5434 /** 5439 5435 * cfg80211_disconnected - notify cfg80211 that connection was dropped
+2 -10
net/wireless/core.h
··· 224 224 225 225 union { 226 226 struct cfg80211_connect_resp_params cr; 227 - struct { 228 - const u8 *req_ie; 229 - const u8 *resp_ie; 230 - size_t req_ie_len; 231 - size_t resp_ie_len; 232 - struct cfg80211_bss *bss; 233 - } rm; 227 + struct cfg80211_roam_info rm; 234 228 struct { 235 229 const u8 *ie; 236 230 size_t ie_len; ··· 384 390 struct net_device *dev, u16 reason, 385 391 bool wextev); 386 392 void __cfg80211_roamed(struct wireless_dev *wdev, 387 - struct cfg80211_bss *bss, 388 - const u8 *req_ie, size_t req_ie_len, 389 - const u8 *resp_ie, size_t resp_ie_len); 393 + struct cfg80211_roam_info *info); 390 394 int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev, 391 395 struct wireless_dev *wdev); 392 396 void cfg80211_autodisconnect_wk(struct work_struct *work);
+10 -8
net/wireless/nl80211.c
··· 13646 13646 } 13647 13647 13648 13648 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 13649 - struct net_device *netdev, const u8 *bssid, 13650 - const u8 *req_ie, size_t req_ie_len, 13651 - const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) 13649 + struct net_device *netdev, 13650 + struct cfg80211_roam_info *info, gfp_t gfp) 13652 13651 { 13653 13652 struct sk_buff *msg; 13654 13653 void *hdr; 13654 + const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; 13655 13655 13656 - msg = nlmsg_new(100 + req_ie_len + resp_ie_len, gfp); 13656 + msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp); 13657 13657 if (!msg) 13658 13658 return; 13659 13659 ··· 13666 13666 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 13667 13667 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 13668 13668 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || 13669 - (req_ie && 13670 - nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || 13671 - (resp_ie && 13672 - nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) 13669 + (info->req_ie && 13670 + nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, 13671 + info->req_ie)) || 13672 + (info->resp_ie && 13673 + nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, 13674 + info->resp_ie))) 13673 13675 goto nla_put_failure; 13674 13676 13675 13677 genlmsg_end(msg, hdr);
+2 -3
net/wireless/nl80211.h
··· 56 56 struct cfg80211_connect_resp_params *params, 57 57 gfp_t gfp); 58 58 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 59 - struct net_device *netdev, const u8 *bssid, 60 - const u8 *req_ie, size_t req_ie_len, 61 - const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp); 59 + struct net_device *netdev, 60 + struct cfg80211_roam_info *info, gfp_t gfp); 62 61 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, 63 62 struct net_device *netdev, u16 reason, 64 63 const u8 *ie, size_t ie_len, bool from_ap);
+38 -52
net/wireless/sme.c
··· 5 5 * 6 6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 7 7 * Copyright (C) 2009 Intel Corporation. All rights reserved. 8 + * Copyright 2017 Intel Deutschland GmbH 8 9 */ 9 10 10 11 #include <linux/etherdevice.h> ··· 871 870 872 871 /* Consumes bss object one way or another */ 873 872 void __cfg80211_roamed(struct wireless_dev *wdev, 874 - struct cfg80211_bss *bss, 875 - const u8 *req_ie, size_t req_ie_len, 876 - const u8 *resp_ie, size_t resp_ie_len) 873 + struct cfg80211_roam_info *info) 877 874 { 878 875 #ifdef CONFIG_CFG80211_WEXT 879 876 union iwreq_data wrqu; ··· 889 890 cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub); 890 891 wdev->current_bss = NULL; 891 892 892 - cfg80211_hold_bss(bss_from_pub(bss)); 893 - wdev->current_bss = bss_from_pub(bss); 893 + if (WARN_ON(!info->bss)) 894 + return; 895 + 896 + cfg80211_hold_bss(bss_from_pub(info->bss)); 897 + wdev->current_bss = bss_from_pub(info->bss); 894 898 895 899 nl80211_send_roamed(wiphy_to_rdev(wdev->wiphy), 896 - wdev->netdev, bss->bssid, 897 - req_ie, req_ie_len, resp_ie, resp_ie_len, 898 - GFP_KERNEL); 900 + wdev->netdev, info, GFP_KERNEL); 899 901 900 902 #ifdef CONFIG_CFG80211_WEXT 901 - if (req_ie) { 903 + if (info->req_ie) { 902 904 memset(&wrqu, 0, sizeof(wrqu)); 903 - wrqu.data.length = req_ie_len; 905 + wrqu.data.length = info->req_ie_len; 904 906 wireless_send_event(wdev->netdev, IWEVASSOCREQIE, 905 - &wrqu, req_ie); 907 + &wrqu, info->req_ie); 906 908 } 907 909 908 - if (resp_ie) { 910 + if (info->resp_ie) { 909 911 memset(&wrqu, 0, sizeof(wrqu)); 910 - wrqu.data.length = resp_ie_len; 912 + wrqu.data.length = info->resp_ie_len; 911 913 wireless_send_event(wdev->netdev, IWEVASSOCRESPIE, 912 - &wrqu, resp_ie); 914 + &wrqu, info->resp_ie); 913 915 } 914 916 915 917 memset(&wrqu, 0, sizeof(wrqu)); 916 918 wrqu.ap_addr.sa_family = ARPHRD_ETHER; 917 - memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); 918 - memcpy(wdev->wext.prev_bssid, bss->bssid, ETH_ALEN); 919 + memcpy(wrqu.ap_addr.sa_data, info->bss->bssid, ETH_ALEN); 920 + memcpy(wdev->wext.prev_bssid, info->bss->bssid, ETH_ALEN); 919 921 wdev->wext.prev_bssid_valid = true; 920 922 wireless_send_event(wdev->netdev, SIOCGIWAP, &wrqu, NULL); 921 923 #endif 922 924 923 925 return; 924 926 out: 925 - cfg80211_put_bss(wdev->wiphy, bss); 927 + cfg80211_put_bss(wdev->wiphy, info->bss); 926 928 } 927 929 928 - void cfg80211_roamed(struct net_device *dev, 929 - struct ieee80211_channel *channel, 930 - const u8 *bssid, 931 - const u8 *req_ie, size_t req_ie_len, 932 - const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) 933 - { 934 - struct wireless_dev *wdev = dev->ieee80211_ptr; 935 - struct cfg80211_bss *bss; 936 - 937 - bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, wdev->ssid, 938 - wdev->ssid_len, 939 - wdev->conn_bss_type, IEEE80211_PRIVACY_ANY); 940 - if (WARN_ON(!bss)) 941 - return; 942 - 943 - cfg80211_roamed_bss(dev, bss, req_ie, req_ie_len, resp_ie, 944 - resp_ie_len, gfp); 945 - } 946 - EXPORT_SYMBOL(cfg80211_roamed); 947 - 948 - /* Consumes bss object one way or another */ 949 - void cfg80211_roamed_bss(struct net_device *dev, 950 - struct cfg80211_bss *bss, const u8 *req_ie, 951 - size_t req_ie_len, const u8 *resp_ie, 952 - size_t resp_ie_len, gfp_t gfp) 930 + /* Consumes info->bss object one way or another */ 931 + void cfg80211_roamed(struct net_device *dev, struct cfg80211_roam_info *info, 932 + gfp_t gfp) 953 933 { 954 934 struct wireless_dev *wdev = dev->ieee80211_ptr; 955 935 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 956 936 struct cfg80211_event *ev; 957 937 unsigned long flags; 958 938 959 - if (WARN_ON(!bss)) 939 + if (!info->bss) { 940 + info->bss = cfg80211_get_bss(wdev->wiphy, info->channel, 941 + info->bssid, wdev->ssid, 942 + wdev->ssid_len, 943 + wdev->conn_bss_type, 944 + IEEE80211_PRIVACY_ANY); 945 + } 946 + 947 + if (WARN_ON(!info->bss)) 960 948 return; 961 949 962 - ev = kzalloc(sizeof(*ev) + req_ie_len + resp_ie_len, gfp); 950 + ev = kzalloc(sizeof(*ev) + info->req_ie_len + info->resp_ie_len, gfp); 963 951 if (!ev) { 964 - cfg80211_put_bss(wdev->wiphy, bss); 952 + cfg80211_put_bss(wdev->wiphy, info->bss); 965 953 return; 966 954 } 967 955 968 956 ev->type = EVENT_ROAMED; 969 957 ev->rm.req_ie = ((u8 *)ev) + sizeof(*ev); 970 - ev->rm.req_ie_len = req_ie_len; 971 - memcpy((void *)ev->rm.req_ie, req_ie, req_ie_len); 972 - ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + req_ie_len; 973 - ev->rm.resp_ie_len = resp_ie_len; 974 - memcpy((void *)ev->rm.resp_ie, resp_ie, resp_ie_len); 975 - ev->rm.bss = bss; 958 + ev->rm.req_ie_len = info->req_ie_len; 959 + memcpy((void *)ev->rm.req_ie, info->req_ie, info->req_ie_len); 960 + ev->rm.resp_ie = ((u8 *)ev) + sizeof(*ev) + info->req_ie_len; 961 + ev->rm.resp_ie_len = info->resp_ie_len; 962 + memcpy((void *)ev->rm.resp_ie, info->resp_ie, info->resp_ie_len); 963 + ev->rm.bss = info->bss; 976 964 977 965 spin_lock_irqsave(&wdev->event_lock, flags); 978 966 list_add_tail(&ev->list, &wdev->event_list); 979 967 spin_unlock_irqrestore(&wdev->event_lock, flags); 980 968 queue_work(cfg80211_wq, &rdev->event_work); 981 969 } 982 - EXPORT_SYMBOL(cfg80211_roamed_bss); 970 + EXPORT_SYMBOL(cfg80211_roamed); 983 971 984 972 void __cfg80211_disconnected(struct net_device *dev, const u8 *ie, 985 973 size_t ie_len, u16 reason, bool from_ap)
+1 -3
net/wireless/util.c
··· 946 946 ev->cr.status == WLAN_STATUS_SUCCESS); 947 947 break; 948 948 case EVENT_ROAMED: 949 - __cfg80211_roamed(wdev, ev->rm.bss, ev->rm.req_ie, 950 - ev->rm.req_ie_len, ev->rm.resp_ie, 951 - ev->rm.resp_ie_len); 949 + __cfg80211_roamed(wdev, &ev->rm); 952 950 break; 953 951 case EVENT_DISCONNECTED: 954 952 __cfg80211_disconnected(wdev->netdev,