History

cfg80211: support immediate reconnect request hint

There are cases where it's necessary to disconnect, but an immediate reconnection is desired. Support a hint to userspace that this is the case, by including a new attribute in the deauth or disassoc event.

Johannes Berg committed 5 years ago

Commit 3bb02141 parent a5a55037 files · +55 −29Browse files

Unified · Split

7 files
  1. include/net/cfg80211.h +3 −1
  2. include/uapi/linux/nl80211.h +6 −0
  3. net/mac80211/mlme.c +3 −2
  4. net/wireless/mlme.c +15 −11
  5. net/wireless/nl80211.c +15 −8
  6. net/wireless/nl80211.h +5 −3
  7. net/wireless/trace.h +8 −4
include/net/cfg80211.h+3−1
@@ -6406,13 +6406,15 @@ void cfg80211_abandon_assoc(struct net_device *dev, struct cfg80211_bss *bss); · 6405 unmodified lines
64066406 * @dev: network device
64076407 * @buf: 802.11 frame (header + body)
64086408 * @len: length of the frame data
6409+ * @reconnect: immediate reconnect is desired (include the nl80211 attribute)
64096410 *
64106411 * This function is called whenever deauthentication has been processed in
64116412 * station mode. This includes both received deauthentication frames and
64126413 * locally generated ones. This function may sleep. The caller must hold the
64136414 * corresponding wdev's mutex.
64146415 */
6415−void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len);
6416+void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len,
6417+ bool reconnect);
64166418
64176419 /**
64186420 * cfg80211_rx_unprot_mlme_mgmt - notification of unprotected mlme mgmt frame
include/uapi/linux/nl80211.h+6−0
@@ -2535,6 +2535,10 @@ enum nl80211_commands { · 2534 unmodified lines
25352535 * This is a u8 attribute that encapsulates one of the values from
25362536 * &enum nl80211_sae_pwe_mechanism.
25372537 *
2538+ * @NL80211_ATTR_RECONNECT_REQUESTED: flag attribute, used with deauth and
2539+ * disassoc events to indicate that an immediate reconnect to the AP
2540+ * is desired.
2541+ *
25382542 * @NUM_NL80211_ATTR: total number of nl80211_attrs available
25392543 * @NL80211_ATTR_MAX: highest attribute number currently defined
25402544 * @__NL80211_ATTR_AFTER_LAST: internal use
@@ -3026,6 +3030,8 @@ enum nl80211_attrs { · 485 unmodified lines
30263030
30273031 NL80211_ATTR_SAE_PWE,
30283032
3033+ NL80211_ATTR_RECONNECT_REQUESTED,
3034+
30293035 /* add attributes here, update the policy in nl80211.c */
30303036
30313037 __NL80211_ATTR_AFTER_LAST,
net/mac80211/mlme.c+3−2
@@ -2741,7 +2741,7 @@ static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, · 2740 unmodified lines
27412741 };
27422742
27432743 if (tx)
2744− cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
2744+ cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, false);
27452745 else
27462746 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
27472747
@@ -4721,7 +4721,8 @@ void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata) · 1973 unmodified lines
47214721 if (ifmgd->auth_data)
47224722 ieee80211_destroy_auth_data(sdata, false);
47234723 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4724− IEEE80211_DEAUTH_FRAME_LEN);
4724+ IEEE80211_DEAUTH_FRAME_LEN,
4725+ false);
47254726 }
47264727
47274728 /* This is a bit of a hack - we should find a better and more generic
net/wireless/mlme.c+15−11
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 *
55 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
66 * Copyright (c) 2015 Intel Deutschland GmbH
7− * Copyright (C) 2019 Intel Corporation
7+ * Copyright (C) 2019-2020 Intel Corporation
88 */
99
1010 #include <linux/kernel.h>
@@ -81,7 +81,8 @@ static void cfg80211_process_auth(struct wireless_dev *wdev, · 70 unmodified lines
8181 }
8282
8383 static void cfg80211_process_deauth(struct wireless_dev *wdev,
84− const u8 *buf, size_t len)
84+ const u8 *buf, size_t len,
85+ bool reconnect)
8586 {
8687 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
8788 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
@@ -89,7 +90,7 @@ static void cfg80211_process_deauth(struct wireless_dev *wdev, · 1 unmodified line
8990 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
9091 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
9192
92− nl80211_send_deauth(rdev, wdev->netdev, buf, len, GFP_KERNEL);
93+ nl80211_send_deauth(rdev, wdev->netdev, buf, len, reconnect, GFP_KERNEL);
9394
9495 if (!wdev->current_bss ||
9596 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid))
@@ -100,7 +101,8 @@ static void cfg80211_process_deauth(struct wireless_dev *wdev, · 4 unmodified lines
100101 }
101102
102103 static void cfg80211_process_disassoc(struct wireless_dev *wdev,
103− const u8 *buf, size_t len)
104+ const u8 *buf, size_t len,
105+ bool reconnect)
104106 {
105107 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
106108 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
@@ -108,7 +110,8 @@ static void cfg80211_process_disassoc(struct wireless_dev *wdev, · 1 unmodified line
108110 u16 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
109111 bool from_ap = !ether_addr_equal(mgmt->sa, wdev->netdev->dev_addr);
110112
111− nl80211_send_disassoc(rdev, wdev->netdev, buf, len, GFP_KERNEL);
113+ nl80211_send_disassoc(rdev, wdev->netdev, buf, len, reconnect,
114+ GFP_KERNEL);
112115
113116 if (WARN_ON(!wdev->current_bss ||
114117 !ether_addr_equal(wdev->current_bss->pub.bssid, bssid)))
@@ -133,9 +136,9 @@ void cfg80211_rx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len) · 18 unmodified lines
133136 if (ieee80211_is_auth(mgmt->frame_control))
134137 cfg80211_process_auth(wdev, buf, len);
135138 else if (ieee80211_is_deauth(mgmt->frame_control))
136− cfg80211_process_deauth(wdev, buf, len);
139+ cfg80211_process_deauth(wdev, buf, len, false);
137140 else if (ieee80211_is_disassoc(mgmt->frame_control))
138− cfg80211_process_disassoc(wdev, buf, len);
141+ cfg80211_process_disassoc(wdev, buf, len, false);
139142 }
140143 EXPORT_SYMBOL(cfg80211_rx_mlme_mgmt);
141144
@@ -180,22 +183,23 @@ void cfg80211_abandon_assoc(struct net_device *dev, struct cfg80211_bss *bss) · 38 unmodified lines
180183 }
181184 EXPORT_SYMBOL(cfg80211_abandon_assoc);
182185
183−void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len)
186+void cfg80211_tx_mlme_mgmt(struct net_device *dev, const u8 *buf, size_t len,
187+ bool reconnect)
184188 {
185189 struct wireless_dev *wdev = dev->ieee80211_ptr;
186190 struct ieee80211_mgmt *mgmt = (void *)buf;
187191
188192 ASSERT_WDEV_LOCK(wdev);
189193
190− trace_cfg80211_tx_mlme_mgmt(dev, buf, len);
194+ trace_cfg80211_tx_mlme_mgmt(dev, buf, len, reconnect);
191195
192196 if (WARN_ON(len < 2))
193197 return;
194198
195199 if (ieee80211_is_deauth(mgmt->frame_control))
196− cfg80211_process_deauth(wdev, buf, len);
200+ cfg80211_process_deauth(wdev, buf, len, reconnect);
197201 else
198− cfg80211_process_disassoc(wdev, buf, len);
202+ cfg80211_process_disassoc(wdev, buf, len, reconnect);
199203 }
200204 EXPORT_SYMBOL(cfg80211_tx_mlme_mgmt);
201205
net/wireless/nl80211.c+15−8
@@ -718,6 +718,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { · 717 unmodified lines
718718 [NL80211_ATTR_SAE_PWE] =
719719 NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK,
720720 NL80211_SAE_PWE_BOTH),
721+ [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT },
721722 };
722723
723724 /* policy for the key attributes */
@@ -15855,7 +15856,7 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, · 15131 unmodified lines
1585515856 const u8 *buf, size_t len,
1585615857 enum nl80211_commands cmd, gfp_t gfp,
1585715858 int uapsd_queues, const u8 *req_ies,
15858− size_t req_ies_len)
15859+ size_t req_ies_len, bool reconnect)
1585915860 {
1586015861 struct sk_buff *msg;
1586115862 void *hdr;
@@ -15877,6 +15878,9 @@ static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, · 15 unmodified lines
1587715878 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
1587815879 goto nla_put_failure;
1587915880
15881+ if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED))
15882+ goto nla_put_failure;
15883+
1588015884 if (uapsd_queues >= 0) {
1588115885 struct nlattr *nla_wmm =
1588215886 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
@@ -15905,7 +15909,8 @@ void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, · 22 unmodified lines
1590515909 size_t len, gfp_t gfp)
1590615910 {
1590715911 nl80211_send_mlme_event(rdev, netdev, buf, len,
15908− NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
15912+ NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0,
15913+ false);
1590915914 }
1591015915
1591115916 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
@@ -15915,23 +15920,25 @@ void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, · 3 unmodified lines
1591515920 {
1591615921 nl80211_send_mlme_event(rdev, netdev, buf, len,
1591715922 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15918− req_ies, req_ies_len);
15923+ req_ies, req_ies_len, false);
1591915924 }
1592015925
1592115926 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
1592215927 struct net_device *netdev, const u8 *buf,
15923− size_t len, gfp_t gfp)
15928+ size_t len, bool reconnect, gfp_t gfp)
1592415929 {
1592515930 nl80211_send_mlme_event(rdev, netdev, buf, len,
15926− NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
15931+ NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0,
15932+ reconnect);
1592715933 }
1592815934
1592915935 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
1593015936 struct net_device *netdev, const u8 *buf,
15931− size_t len, gfp_t gfp)
15937+ size_t len, bool reconnect, gfp_t gfp)
1593215938 {
1593315939 nl80211_send_mlme_event(rdev, netdev, buf, len,
15934− NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
15940+ NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0,
15941+ reconnect);
1593515942 }
1593615943
1593715944 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
@@ -15962,7 +15969,7 @@ void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, · 24 unmodified lines
1596215969
1596315970 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
1596415971 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15965− NULL, 0);
15972+ NULL, 0, false);
1596615973 }
1596715974 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
1596815975
net/wireless/nl80211.h+5−3
@@ -1,7 +1,7 @@
11 /* SPDX-License-Identifier: GPL-2.0 */
22 /*
33 * Portions of this file
4− * Copyright (C) 2018 Intel Corporation
4+ * Copyright (C) 2018, 2020 Intel Corporation
55 */
66 #ifndef __NET_WIRELESS_NL80211_H
77 #define __NET_WIRELESS_NL80211_H
@@ -69,10 +69,12 @@ void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, · 61 unmodified lines
6969 const u8 *req_ies, size_t req_ies_len);
7070 void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
7171 struct net_device *netdev,
72− const u8 *buf, size_t len, gfp_t gfp);
72+ const u8 *buf, size_t len,
73+ bool reconnect, gfp_t gfp);
7374 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
7475 struct net_device *netdev,
75− const u8 *buf, size_t len, gfp_t gfp);
76+ const u8 *buf, size_t len,
77+ bool reconnect, gfp_t gfp);
7678 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
7779 struct net_device *netdev,
7880 const u8 *addr, gfp_t gfp);
net/wireless/trace.h+8−4
@@ -2679,19 +2679,23 @@ DEFINE_EVENT(netdev_frame_event, cfg80211_rx_mlme_mgmt, · 2678 unmodified lines
26792679 );
26802680
26812681 TRACE_EVENT(cfg80211_tx_mlme_mgmt,
2682− TP_PROTO(struct net_device *netdev, const u8 *buf, int len),
2683− TP_ARGS(netdev, buf, len),
2682+ TP_PROTO(struct net_device *netdev, const u8 *buf, int len,
2683+ bool reconnect),
2684+ TP_ARGS(netdev, buf, len, reconnect),
26842685 TP_STRUCT__entry(
26852686 NETDEV_ENTRY
26862687 __dynamic_array(u8, frame, len)
2688+ __field(int, reconnect)
26872689 ),
26882690 TP_fast_assign(
26892691 NETDEV_ASSIGN;
26902692 memcpy(__get_dynamic_array(frame), buf, len);
2693+ __entry->reconnect = reconnect;
26912694 ),
2692− TP_printk(NETDEV_PR_FMT ", ftype:0x%.2x",
2695+ TP_printk(NETDEV_PR_FMT ", ftype:0x%.2x reconnect:%d",
26932696 NETDEV_PR_ARG,
2694− le16_to_cpup((__le16 *)__get_dynamic_array(frame)))
2697+ le16_to_cpup((__le16 *)__get_dynamic_array(frame)),
2698+ __entry->reconnect)
26952699 );
26962700
26972701 DECLARE_EVENT_CLASS(netdev_mac_evt,