1 From: Johannes Berg <johannes.berg@intel.com>
2 Date: Sun, 6 Dec 2020 14:54:43 +0200
3 Subject: [PATCH] mac80211: support driver-based disconnect with reconnect hint
5 Support the driver indicating that a disconnection needs
6 to be performed, and pass through the reconnect hint in
9 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
10 Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
11 Link: https://lore.kernel.org/r/iwlwifi.20201206145305.5c8dab7a22a0.I58459fdf6968b16c90cab9c574f0f04ca22b0c79@changeid
12 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
15 --- a/include/net/mac80211.h
16 +++ b/include/net/mac80211.h
17 @@ -5885,6 +5885,17 @@ void ieee80211_beacon_loss(struct ieee80
18 void ieee80211_connection_loss(struct ieee80211_vif *vif);
21 + * ieee80211_disconnect - request disconnection
23 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
24 + * @reconnect: immediate reconnect is desired
26 + * Request disconnection from the current network and, if enabled, send a
27 + * hint to the higher layers that immediate reconnect is desired.
29 +void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect);
32 * ieee80211_resume_disconnect - disconnect from AP after resume
34 * @vif: &struct ieee80211_vif pointer from the add_interface callback.
35 --- a/net/mac80211/ieee80211_i.h
36 +++ b/net/mac80211/ieee80211_i.h
37 @@ -450,7 +450,9 @@ struct ieee80211_if_managed {
38 unsigned long probe_timeout;
41 - bool connection_loss;
42 + u8 connection_loss:1,
43 + driver_disconnect:1,
46 struct cfg80211_bss *associated;
47 struct ieee80211_mgd_auth_data *auth_data;
48 --- a/net/mac80211/mlme.c
49 +++ b/net/mac80211/mlme.c
50 @@ -2725,7 +2725,7 @@ EXPORT_SYMBOL(ieee80211_ap_probereq_get)
52 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
53 const u8 *buf, size_t len, bool tx,
55 + u16 reason, bool reconnect)
57 struct ieee80211_event event = {
59 @@ -2734,7 +2734,7 @@ static void ieee80211_report_disconnect(
63 - cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, false);
64 + cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
66 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
68 @@ -2756,13 +2756,18 @@ static void __ieee80211_disconnect(struc
70 tx = !sdata->csa_block_tx;
72 - /* AP is probably out of range (or not reachable for another reason) so
73 - * remove the bss struct for that AP.
75 - cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
76 + if (!ifmgd->driver_disconnect) {
78 + * AP is probably out of range (or not reachable for another
79 + * reason) so remove the bss struct for that AP.
81 + cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
84 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
85 - WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
86 + ifmgd->driver_disconnect ?
87 + WLAN_REASON_DEAUTH_LEAVING :
88 + WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
90 mutex_lock(&local->mtx);
91 sdata->vif.csa_active = false;
92 @@ -2775,7 +2780,9 @@ static void __ieee80211_disconnect(struc
93 mutex_unlock(&local->mtx);
95 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
96 - WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
97 + WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
99 + ifmgd->reconnect = false;
103 @@ -2794,6 +2801,13 @@ static void ieee80211_beacon_connection_
104 sdata_info(sdata, "Connection to AP %pM lost\n",
106 __ieee80211_disconnect(sdata);
107 + ifmgd->connection_loss = false;
108 + } else if (ifmgd->driver_disconnect) {
110 + "Driver requested disconnection from AP %pM\n",
112 + __ieee80211_disconnect(sdata);
113 + ifmgd->driver_disconnect = false;
115 ieee80211_mgd_probe_ap(sdata, true);
117 @@ -2832,6 +2846,21 @@ void ieee80211_connection_loss(struct ie
119 EXPORT_SYMBOL(ieee80211_connection_loss);
121 +void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
123 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
124 + struct ieee80211_hw *hw = &sdata->local->hw;
126 + trace_api_disconnect(sdata, reconnect);
128 + if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
131 + sdata->u.mgd.driver_disconnect = true;
132 + sdata->u.mgd.reconnect = reconnect;
133 + ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
135 +EXPORT_SYMBOL(ieee80211_disconnect);
137 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
139 @@ -3135,7 +3164,7 @@ static void ieee80211_rx_mgmt_deauth(str
140 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
142 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
144 + reason_code, false);
148 @@ -3184,7 +3213,8 @@ static void ieee80211_rx_mgmt_disassoc(s
150 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
152 - ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
153 + ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
157 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
158 @@ -4204,7 +4234,8 @@ static void ieee80211_rx_mgmt_beacon(str
160 ieee80211_report_disconnect(sdata, deauth_buf,
161 sizeof(deauth_buf), true,
162 - WLAN_REASON_DEAUTH_LEAVING);
163 + WLAN_REASON_DEAUTH_LEAVING,
168 @@ -4349,7 +4380,7 @@ static void ieee80211_sta_connection_los
171 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
176 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
177 @@ -5439,7 +5470,8 @@ int ieee80211_mgd_auth(struct ieee80211_
179 ieee80211_report_disconnect(sdata, frame_buf,
180 sizeof(frame_buf), true,
181 - WLAN_REASON_UNSPECIFIED);
182 + WLAN_REASON_UNSPECIFIED,
186 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
187 @@ -5511,7 +5543,8 @@ int ieee80211_mgd_assoc(struct ieee80211
189 ieee80211_report_disconnect(sdata, frame_buf,
190 sizeof(frame_buf), true,
191 - WLAN_REASON_UNSPECIFIED);
192 + WLAN_REASON_UNSPECIFIED,
196 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
197 @@ -5810,7 +5843,7 @@ int ieee80211_mgd_deauth(struct ieee8021
198 ieee80211_destroy_auth_data(sdata, false);
199 ieee80211_report_disconnect(sdata, frame_buf,
200 sizeof(frame_buf), true,
202 + req->reason_code, false);
206 @@ -5830,7 +5863,7 @@ int ieee80211_mgd_deauth(struct ieee8021
207 ieee80211_destroy_assoc_data(sdata, false, true);
208 ieee80211_report_disconnect(sdata, frame_buf,
209 sizeof(frame_buf), true,
211 + req->reason_code, false);
215 @@ -5845,7 +5878,7 @@ int ieee80211_mgd_deauth(struct ieee8021
216 req->reason_code, tx, frame_buf);
217 ieee80211_report_disconnect(sdata, frame_buf,
218 sizeof(frame_buf), true,
220 + req->reason_code, false);
224 @@ -5878,7 +5911,7 @@ int ieee80211_mgd_disassoc(struct ieee80
227 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
229 + req->reason_code, false);
233 --- a/net/mac80211/trace.h
234 +++ b/net/mac80211/trace.h
237 * Portions of this file
238 * Copyright(c) 2016-2017 Intel Deutschland GmbH
239 -* Copyright (C) 2018 - 2019 Intel Corporation
240 +* Copyright (C) 2018 - 2020 Intel Corporation
243 #if !defined(__MAC80211_DRIVER_TRACE) || defined(TRACE_HEADER_MULTI_READ)
244 @@ -2086,6 +2086,27 @@ TRACE_EVENT(api_connection_loss,
248 +TRACE_EVENT(api_disconnect,
249 + TP_PROTO(struct ieee80211_sub_if_data *sdata, bool reconnect),
251 + TP_ARGS(sdata, reconnect),
255 + __field(int, reconnect)
260 + __entry->reconnect = reconnect;
264 + VIF_PR_FMT " reconnect:%d",
265 + VIF_PR_ARG, __entry->reconnect
269 TRACE_EVENT(api_cqm_rssi_notify,
270 TP_PROTO(struct ieee80211_sub_if_data *sdata,
271 enum nl80211_cqm_rssi_threshold_event rssi_event,