b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 |
| 4 | |
| 5 | Support the driver indicating that a disconnection needs |
| 6 | to be performed, and pass through the reconnect hint in |
| 7 | this case. |
| 8 | |
| 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> |
| 13 | --- |
| 14 | |
| 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); |
| 19 | |
| 20 | /** |
| 21 | + * ieee80211_disconnect - request disconnection |
| 22 | + * |
| 23 | + * @vif: &struct ieee80211_vif pointer from the add_interface callback. |
| 24 | + * @reconnect: immediate reconnect is desired |
| 25 | + * |
| 26 | + * Request disconnection from the current network and, if enabled, send a |
| 27 | + * hint to the higher layers that immediate reconnect is desired. |
| 28 | + */ |
| 29 | +void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect); |
| 30 | + |
| 31 | +/** |
| 32 | * ieee80211_resume_disconnect - disconnect from AP after resume |
| 33 | * |
| 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; |
| 39 | int probe_send_count; |
| 40 | bool nullfunc_failed; |
| 41 | - bool connection_loss; |
| 42 | + u8 connection_loss:1, |
| 43 | + driver_disconnect:1, |
| 44 | + reconnect:1; |
| 45 | |
| 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 | @@ -2724,7 +2724,7 @@ EXPORT_SYMBOL(ieee80211_ap_probereq_get) |
| 51 | |
| 52 | static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata, |
| 53 | const u8 *buf, size_t len, bool tx, |
| 54 | - u16 reason) |
| 55 | + u16 reason, bool reconnect) |
| 56 | { |
| 57 | struct ieee80211_event event = { |
| 58 | .type = MLME_EVENT, |
| 59 | @@ -2733,7 +2733,7 @@ static void ieee80211_report_disconnect( |
| 60 | }; |
| 61 | |
| 62 | if (tx) |
| 63 | - cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, false); |
| 64 | + cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect); |
| 65 | else |
| 66 | cfg80211_rx_mlme_mgmt(sdata->dev, buf, len); |
| 67 | |
| 68 | @@ -2755,13 +2755,18 @@ static void __ieee80211_disconnect(struc |
| 69 | |
| 70 | tx = !sdata->csa_block_tx; |
| 71 | |
| 72 | - /* AP is probably out of range (or not reachable for another reason) so |
| 73 | - * remove the bss struct for that AP. |
| 74 | - */ |
| 75 | - cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated); |
| 76 | + if (!ifmgd->driver_disconnect) { |
| 77 | + /* |
| 78 | + * AP is probably out of range (or not reachable for another |
| 79 | + * reason) so remove the bss struct for that AP. |
| 80 | + */ |
| 81 | + cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated); |
| 82 | + } |
| 83 | |
| 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, |
| 89 | tx, frame_buf); |
| 90 | mutex_lock(&local->mtx); |
| 91 | sdata->vif.csa_active = false; |
| 92 | @@ -2774,7 +2779,9 @@ static void __ieee80211_disconnect(struc |
| 93 | mutex_unlock(&local->mtx); |
| 94 | |
| 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, |
| 98 | + ifmgd->reconnect); |
| 99 | + ifmgd->reconnect = false; |
| 100 | |
| 101 | sdata_unlock(sdata); |
| 102 | } |
| 103 | @@ -2793,6 +2800,13 @@ static void ieee80211_beacon_connection_ |
| 104 | sdata_info(sdata, "Connection to AP %pM lost\n", |
| 105 | ifmgd->bssid); |
| 106 | __ieee80211_disconnect(sdata); |
| 107 | + ifmgd->connection_loss = false; |
| 108 | + } else if (ifmgd->driver_disconnect) { |
| 109 | + sdata_info(sdata, |
| 110 | + "Driver requested disconnection from AP %pM\n", |
| 111 | + ifmgd->bssid); |
| 112 | + __ieee80211_disconnect(sdata); |
| 113 | + ifmgd->driver_disconnect = false; |
| 114 | } else { |
| 115 | ieee80211_mgd_probe_ap(sdata, true); |
| 116 | } |
| 117 | @@ -2831,6 +2845,21 @@ void ieee80211_connection_loss(struct ie |
| 118 | } |
| 119 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 120 | |
| 121 | +void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect) |
| 122 | +{ |
| 123 | + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 124 | + struct ieee80211_hw *hw = &sdata->local->hw; |
| 125 | + |
| 126 | + trace_api_disconnect(sdata, reconnect); |
| 127 | + |
| 128 | + if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 129 | + return; |
| 130 | + |
| 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); |
| 134 | +} |
| 135 | +EXPORT_SYMBOL(ieee80211_disconnect); |
| 136 | |
| 137 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
| 138 | bool assoc) |
| 139 | @@ -3142,7 +3171,7 @@ static void ieee80211_rx_mgmt_deauth(str |
| 140 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 141 | |
| 142 | ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, |
| 143 | - reason_code); |
| 144 | + reason_code, false); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | @@ -3191,7 +3220,8 @@ static void ieee80211_rx_mgmt_disassoc(s |
| 149 | |
| 150 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 151 | |
| 152 | - ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code); |
| 153 | + ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code, |
| 154 | + false); |
| 155 | } |
| 156 | |
| 157 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
| 158 | @@ -4223,7 +4253,8 @@ static void ieee80211_rx_mgmt_beacon(str |
| 159 | true, deauth_buf); |
| 160 | ieee80211_report_disconnect(sdata, deauth_buf, |
| 161 | sizeof(deauth_buf), true, |
| 162 | - WLAN_REASON_DEAUTH_LEAVING); |
| 163 | + WLAN_REASON_DEAUTH_LEAVING, |
| 164 | + false); |
| 165 | goto free; |
| 166 | } |
| 167 | |
| 168 | @@ -4370,7 +4401,7 @@ static void ieee80211_sta_connection_los |
| 169 | tx, frame_buf); |
| 170 | |
| 171 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 172 | - reason); |
| 173 | + reason, false); |
| 174 | } |
| 175 | |
| 176 | static int ieee80211_auth(struct ieee80211_sub_if_data *sdata) |
| 177 | @@ -5460,7 +5491,8 @@ int ieee80211_mgd_auth(struct ieee80211_ |
| 178 | |
| 179 | ieee80211_report_disconnect(sdata, frame_buf, |
| 180 | sizeof(frame_buf), true, |
| 181 | - WLAN_REASON_UNSPECIFIED); |
| 182 | + WLAN_REASON_UNSPECIFIED, |
| 183 | + false); |
| 184 | } |
| 185 | |
| 186 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
| 187 | @@ -5532,7 +5564,8 @@ int ieee80211_mgd_assoc(struct ieee80211 |
| 188 | |
| 189 | ieee80211_report_disconnect(sdata, frame_buf, |
| 190 | sizeof(frame_buf), true, |
| 191 | - WLAN_REASON_UNSPECIFIED); |
| 192 | + WLAN_REASON_UNSPECIFIED, |
| 193 | + false); |
| 194 | } |
| 195 | |
| 196 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { |
| 197 | @@ -5835,7 +5868,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, |
| 201 | - req->reason_code); |
| 202 | + req->reason_code, false); |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | @@ -5855,7 +5888,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, |
| 210 | - req->reason_code); |
| 211 | + req->reason_code, false); |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | @@ -5870,7 +5903,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, |
| 219 | - req->reason_code); |
| 220 | + req->reason_code, false); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | @@ -5903,7 +5936,7 @@ int ieee80211_mgd_disassoc(struct ieee80 |
| 225 | frame_buf); |
| 226 | |
| 227 | ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true, |
| 228 | - req->reason_code); |
| 229 | + req->reason_code, false); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | --- a/net/mac80211/trace.h |
| 234 | +++ b/net/mac80211/trace.h |
| 235 | @@ -2,7 +2,7 @@ |
| 236 | /* |
| 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 |
| 241 | */ |
| 242 | |
| 243 | #if !defined(__MAC80211_DRIVER_TRACE) || defined(TRACE_HEADER_MULTI_READ) |
| 244 | @@ -2086,6 +2086,27 @@ TRACE_EVENT(api_connection_loss, |
| 245 | ) |
| 246 | ); |
| 247 | |
| 248 | +TRACE_EVENT(api_disconnect, |
| 249 | + TP_PROTO(struct ieee80211_sub_if_data *sdata, bool reconnect), |
| 250 | + |
| 251 | + TP_ARGS(sdata, reconnect), |
| 252 | + |
| 253 | + TP_STRUCT__entry( |
| 254 | + VIF_ENTRY |
| 255 | + __field(int, reconnect) |
| 256 | + ), |
| 257 | + |
| 258 | + TP_fast_assign( |
| 259 | + VIF_ASSIGN; |
| 260 | + __entry->reconnect = reconnect; |
| 261 | + ), |
| 262 | + |
| 263 | + TP_printk( |
| 264 | + VIF_PR_FMT " reconnect:%d", |
| 265 | + VIF_PR_ARG, __entry->reconnect |
| 266 | + ) |
| 267 | +); |
| 268 | + |
| 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, |