Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Off-channel operation helpers |
| 3 | * |
| 4 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> |
| 5 | * Copyright 2004, Instant802 Networks, Inc. |
| 6 | * Copyright 2005, Devicescape Software, Inc. |
| 7 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 8 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 9 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 16 | #include <net/mac80211.h> |
| 17 | #include "ieee80211_i.h" |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 18 | #include "driver-ops.h" |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 19 | |
| 20 | /* |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 21 | * Tell our hardware to disable PS. |
| 22 | * Optionally inform AP that we will go to sleep so that it will buffer |
| 23 | * the frames while we are doing off-channel work. This is optional |
| 24 | * because we *may* be doing work on-operating channel, and want our |
| 25 | * hardware unconditionally awake, but still let the AP send us normal frames. |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 26 | */ |
Rajkumar Manoharan | 559cef9 | 2012-06-18 19:03:52 +0530 | [diff] [blame] | 27 | static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 28 | { |
| 29 | struct ieee80211_local *local = sdata->local; |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 30 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 31 | |
| 32 | local->offchannel_ps_enabled = false; |
| 33 | |
| 34 | /* FIXME: what to do when local->pspolling is true? */ |
| 35 | |
| 36 | del_timer_sync(&local->dynamic_ps_timer); |
Luis R. Rodriguez | 3bc3c0d | 2010-09-16 15:12:33 -0400 | [diff] [blame] | 37 | del_timer_sync(&ifmgd->bcn_mon_timer); |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 38 | del_timer_sync(&ifmgd->conn_mon_timer); |
| 39 | |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 40 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 41 | |
| 42 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 43 | local->offchannel_ps_enabled = true; |
| 44 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 45 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 46 | } |
| 47 | |
Rajkumar Manoharan | 559cef9 | 2012-06-18 19:03:52 +0530 | [diff] [blame] | 48 | if (!local->offchannel_ps_enabled || |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 49 | !ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 50 | /* |
| 51 | * If power save was enabled, no need to send a nullfunc |
| 52 | * frame because AP knows that we are sleeping. But if the |
| 53 | * hardware is creating the nullfunc frame for power save |
| 54 | * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not |
| 55 | * enabled) and power save was enabled, the firmware just |
| 56 | * sent a null frame with power save disabled. So we need |
| 57 | * to send a new nullfunc frame to inform the AP that we |
| 58 | * are again sleeping. |
| 59 | */ |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 60 | ieee80211_send_nullfunc(local, sdata, true); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /* inform AP that we are awake again, unless power save is enabled */ |
| 64 | static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata) |
| 65 | { |
| 66 | struct ieee80211_local *local = sdata->local; |
| 67 | |
| 68 | if (!local->ps_sdata) |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 69 | ieee80211_send_nullfunc(local, sdata, false); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 70 | else if (local->offchannel_ps_enabled) { |
| 71 | /* |
| 72 | * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware |
| 73 | * will send a nullfunc frame with the powersave bit set |
| 74 | * even though the AP already knows that we are sleeping. |
| 75 | * This could be avoided by sending a null frame with power |
| 76 | * save bit disabled before enabling the power save, but |
| 77 | * this doesn't gain anything. |
| 78 | * |
| 79 | * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need |
| 80 | * to send a nullfunc frame because AP already knows that |
| 81 | * we are sleeping, let's just enable power save mode in |
| 82 | * hardware. |
| 83 | */ |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 84 | /* TODO: Only set hardware if CONF_PS changed? |
| 85 | * TODO: Should we set offchannel_ps_enabled to false? |
| 86 | */ |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 87 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 88 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 89 | } else if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 90 | /* |
| 91 | * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer |
| 92 | * had been running before leaving the operating channel, |
| 93 | * restart the timer now and send a nullfunc frame to inform |
| 94 | * the AP that we are awake. |
| 95 | */ |
Johannes Berg | 076cdcb | 2015-09-24 16:14:55 +0200 | [diff] [blame] | 96 | ieee80211_send_nullfunc(local, sdata, false); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 97 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 98 | msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); |
| 99 | } |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 100 | |
Luis R. Rodriguez | 3bc3c0d | 2010-09-16 15:12:33 -0400 | [diff] [blame] | 101 | ieee80211_sta_reset_beacon_monitor(sdata); |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 102 | ieee80211_sta_reset_conn_monitor(sdata); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Stanislaw Gruszka | aacde9e | 2012-12-20 14:41:18 +0100 | [diff] [blame] | 105 | void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 106 | { |
| 107 | struct ieee80211_sub_if_data *sdata; |
| 108 | |
Johannes Berg | fe57d9f | 2012-07-26 14:55:08 +0200 | [diff] [blame] | 109 | if (WARN_ON(local->use_chanctx)) |
| 110 | return; |
| 111 | |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 112 | /* |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 113 | * notify the AP about us leaving the channel and stop all |
| 114 | * STA interfaces. |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 115 | */ |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 116 | |
Seth Forshee | 9c35d7d | 2013-02-11 11:21:08 -0600 | [diff] [blame] | 117 | /* |
| 118 | * Stop queues and transmit all frames queued by the driver |
| 119 | * before sending nullfunc to enable powersave at the AP. |
| 120 | */ |
Johannes Berg | 445ea4e | 2013-02-13 12:25:28 +0100 | [diff] [blame] | 121 | ieee80211_stop_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP, |
Luciano Coelho | cca07b0 | 2014-06-13 16:30:05 +0300 | [diff] [blame] | 122 | IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL, |
| 123 | false); |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 124 | ieee80211_flush_queues(local, NULL, false); |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 125 | |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 126 | mutex_lock(&local->iflist_mtx); |
| 127 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 128 | if (!ieee80211_sdata_running(sdata)) |
| 129 | continue; |
| 130 | |
Ayala Beker | 708d50e | 2016-09-20 17:31:14 +0300 | [diff] [blame] | 131 | if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE || |
| 132 | sdata->vif.type == NL80211_IFTYPE_NAN) |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 133 | continue; |
| 134 | |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 135 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
Johannes Berg | 5b714c6 | 2010-08-27 13:45:28 +0200 | [diff] [blame] | 136 | set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state); |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 137 | |
| 138 | /* Check to see if we should disable beaconing. */ |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 139 | if (sdata->vif.bss_conf.enable_beacon) { |
| 140 | set_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, |
| 141 | &sdata->state); |
| 142 | sdata->vif.bss_conf.enable_beacon = false; |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 143 | ieee80211_bss_info_change_notify( |
| 144 | sdata, BSS_CHANGED_BEACON_ENABLED); |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 145 | } |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 146 | |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 147 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 148 | sdata->u.mgd.associated) |
| 149 | ieee80211_offchannel_ps_enable(sdata); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 150 | } |
| 151 | mutex_unlock(&local->iflist_mtx); |
| 152 | } |
| 153 | |
Stanislaw Gruszka | aacde9e | 2012-12-20 14:41:18 +0100 | [diff] [blame] | 154 | void ieee80211_offchannel_return(struct ieee80211_local *local) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 155 | { |
| 156 | struct ieee80211_sub_if_data *sdata; |
| 157 | |
Johannes Berg | fe57d9f | 2012-07-26 14:55:08 +0200 | [diff] [blame] | 158 | if (WARN_ON(local->use_chanctx)) |
| 159 | return; |
| 160 | |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 161 | mutex_lock(&local->iflist_mtx); |
| 162 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 163 | if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) |
| 164 | continue; |
| 165 | |
Eliad Peller | f6e8cb7 | 2011-12-23 01:48:06 +0200 | [diff] [blame] | 166 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
| 167 | clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state); |
| 168 | |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 169 | if (!ieee80211_sdata_running(sdata)) |
| 170 | continue; |
| 171 | |
| 172 | /* Tell AP we're back */ |
Stanislaw Gruszka | aacde9e | 2012-12-20 14:41:18 +0100 | [diff] [blame] | 173 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 174 | sdata->u.mgd.associated) |
| 175 | ieee80211_offchannel_ps_disable(sdata); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 176 | |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 177 | if (test_and_clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, |
| 178 | &sdata->state)) { |
| 179 | sdata->vif.bss_conf.enable_beacon = true; |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 180 | ieee80211_bss_info_change_notify( |
| 181 | sdata, BSS_CHANGED_BEACON_ENABLED); |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 182 | } |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 183 | } |
| 184 | mutex_unlock(&local->iflist_mtx); |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 185 | |
Johannes Berg | 445ea4e | 2013-02-13 12:25:28 +0100 | [diff] [blame] | 186 | ieee80211_wake_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP, |
Luciano Coelho | cca07b0 | 2014-06-13 16:30:05 +0300 | [diff] [blame] | 187 | IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL, |
| 188 | false); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 189 | } |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 190 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 191 | static void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc) |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 192 | { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 193 | /* was never transmitted */ |
| 194 | if (roc->frame) { |
| 195 | cfg80211_mgmt_tx_status(&roc->sdata->wdev, roc->mgmt_tx_cookie, |
| 196 | roc->frame->data, roc->frame->len, |
| 197 | false, GFP_KERNEL); |
| 198 | ieee80211_free_txskb(&roc->sdata->local->hw, roc->frame); |
| 199 | } |
| 200 | |
| 201 | if (!roc->mgmt_tx_cookie) |
| 202 | cfg80211_remain_on_channel_expired(&roc->sdata->wdev, |
| 203 | roc->cookie, roc->chan, |
| 204 | GFP_KERNEL); |
| 205 | |
| 206 | list_del(&roc->list); |
| 207 | kfree(roc); |
| 208 | } |
| 209 | |
| 210 | static unsigned long ieee80211_end_finished_rocs(struct ieee80211_local *local, |
| 211 | unsigned long now) |
| 212 | { |
| 213 | struct ieee80211_roc_work *roc, *tmp; |
| 214 | long remaining_dur_min = LONG_MAX; |
| 215 | |
| 216 | lockdep_assert_held(&local->mtx); |
| 217 | |
| 218 | list_for_each_entry_safe(roc, tmp, &local->roc_list, list) { |
| 219 | long remaining; |
| 220 | |
| 221 | if (!roc->started) |
| 222 | break; |
| 223 | |
| 224 | remaining = roc->start_time + |
| 225 | msecs_to_jiffies(roc->duration) - |
| 226 | now; |
| 227 | |
Ilan Peer | 1b89452 | 2015-12-06 21:19:15 +0200 | [diff] [blame] | 228 | /* In case of HW ROC, it is possible that the HW finished the |
| 229 | * ROC session before the actual requested time. In such a case |
| 230 | * end the ROC session (disregarding the remaining time). |
| 231 | */ |
| 232 | if (roc->abort || roc->hw_begun || remaining <= 0) |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 233 | ieee80211_roc_notify_destroy(roc); |
| 234 | else |
| 235 | remaining_dur_min = min(remaining_dur_min, remaining); |
| 236 | } |
| 237 | |
| 238 | return remaining_dur_min; |
| 239 | } |
| 240 | |
| 241 | static bool ieee80211_recalc_sw_work(struct ieee80211_local *local, |
| 242 | unsigned long now) |
| 243 | { |
| 244 | long dur = ieee80211_end_finished_rocs(local, now); |
| 245 | |
| 246 | if (dur == LONG_MAX) |
| 247 | return false; |
| 248 | |
| 249 | mod_delayed_work(local->workqueue, &local->roc_work, dur); |
| 250 | return true; |
| 251 | } |
| 252 | |
| 253 | static void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc, |
| 254 | unsigned long start_time) |
| 255 | { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 256 | if (WARN_ON(roc->notified)) |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 257 | return; |
| 258 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 259 | roc->start_time = start_time; |
| 260 | roc->started = true; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 261 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 262 | if (roc->mgmt_tx_cookie) { |
| 263 | if (!WARN_ON(!roc->frame)) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 264 | ieee80211_tx_skb_tid_band(roc->sdata, roc->frame, 7, |
| 265 | roc->chan->band); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 266 | roc->frame = NULL; |
| 267 | } |
| 268 | } else { |
Johannes Berg | 50febf6 | 2012-10-26 16:13:06 +0200 | [diff] [blame] | 269 | cfg80211_ready_on_channel(&roc->sdata->wdev, roc->cookie, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 270 | roc->chan, roc->req_duration, |
| 271 | GFP_KERNEL); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | roc->notified = true; |
| 275 | } |
| 276 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 277 | static void ieee80211_hw_roc_start(struct work_struct *work) |
| 278 | { |
| 279 | struct ieee80211_local *local = |
| 280 | container_of(work, struct ieee80211_local, hw_roc_start); |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 281 | struct ieee80211_roc_work *roc; |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 282 | |
| 283 | mutex_lock(&local->mtx); |
| 284 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 285 | list_for_each_entry(roc, &local->roc_list, list) { |
| 286 | if (!roc->started) |
| 287 | break; |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 288 | |
Johannes Berg | e6a8a3a | 2015-12-08 23:46:33 +0100 | [diff] [blame] | 289 | roc->hw_begun = true; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 290 | ieee80211_handle_roc_started(roc, local->hw_roc_start_time); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 291 | } |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 292 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 293 | mutex_unlock(&local->mtx); |
| 294 | } |
| 295 | |
| 296 | void ieee80211_ready_on_channel(struct ieee80211_hw *hw) |
| 297 | { |
| 298 | struct ieee80211_local *local = hw_to_local(hw); |
| 299 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 300 | local->hw_roc_start_time = jiffies; |
| 301 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 302 | trace_api_ready_on_channel(local); |
| 303 | |
| 304 | ieee80211_queue_work(hw, &local->hw_roc_start); |
| 305 | } |
| 306 | EXPORT_SYMBOL_GPL(ieee80211_ready_on_channel); |
| 307 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 308 | static void _ieee80211_start_next_roc(struct ieee80211_local *local) |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 309 | { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 310 | struct ieee80211_roc_work *roc, *tmp; |
| 311 | enum ieee80211_roc_type type; |
| 312 | u32 min_dur, max_dur; |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 313 | |
| 314 | lockdep_assert_held(&local->mtx); |
| 315 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 316 | if (WARN_ON(list_empty(&local->roc_list))) |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 317 | return; |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 318 | |
| 319 | roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work, |
| 320 | list); |
| 321 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 322 | if (WARN_ON(roc->started)) |
Johannes Berg | 0f6b3f5 | 2012-06-20 20:11:33 +0200 | [diff] [blame] | 323 | return; |
| 324 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 325 | min_dur = roc->duration; |
| 326 | max_dur = roc->duration; |
| 327 | type = roc->type; |
| 328 | |
| 329 | list_for_each_entry(tmp, &local->roc_list, list) { |
| 330 | if (tmp == roc) |
| 331 | continue; |
| 332 | if (tmp->sdata != roc->sdata || tmp->chan != roc->chan) |
| 333 | break; |
| 334 | max_dur = max(tmp->duration, max_dur); |
| 335 | min_dur = min(tmp->duration, min_dur); |
| 336 | type = max(tmp->type, type); |
| 337 | } |
| 338 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 339 | if (local->ops->remain_on_channel) { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 340 | int ret = drv_remain_on_channel(local, roc->sdata, roc->chan, |
| 341 | max_dur, type); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 342 | |
| 343 | if (ret) { |
| 344 | wiphy_warn(local->hw.wiphy, |
| 345 | "failed to start next HW ROC (%d)\n", ret); |
| 346 | /* |
| 347 | * queue the work struct again to avoid recursion |
| 348 | * when multiple failures occur |
| 349 | */ |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 350 | list_for_each_entry(tmp, &local->roc_list, list) { |
| 351 | if (tmp->sdata != roc->sdata || |
| 352 | tmp->chan != roc->chan) |
| 353 | break; |
| 354 | tmp->started = true; |
| 355 | tmp->abort = true; |
| 356 | } |
| 357 | ieee80211_queue_work(&local->hw, &local->hw_roc_done); |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | /* we'll notify about the start once the HW calls back */ |
| 362 | list_for_each_entry(tmp, &local->roc_list, list) { |
| 363 | if (tmp->sdata != roc->sdata || tmp->chan != roc->chan) |
| 364 | break; |
| 365 | tmp->started = true; |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 366 | } |
| 367 | } else { |
Johannes Berg | b4b177a | 2014-05-14 15:34:41 +0200 | [diff] [blame] | 368 | /* If actually operating on the desired channel (with at least |
| 369 | * 20 MHz channel width) don't stop all the operations but still |
| 370 | * treat it as though the ROC operation started properly, so |
| 371 | * other ROC operations won't interfere with this one. |
| 372 | */ |
| 373 | roc->on_channel = roc->chan == local->_oper_chandef.chan && |
| 374 | local->_oper_chandef.width != NL80211_CHAN_WIDTH_5 && |
| 375 | local->_oper_chandef.width != NL80211_CHAN_WIDTH_10; |
| 376 | |
| 377 | /* start this ROC */ |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 378 | ieee80211_recalc_idle(local); |
| 379 | |
Johannes Berg | b4b177a | 2014-05-14 15:34:41 +0200 | [diff] [blame] | 380 | if (!roc->on_channel) { |
| 381 | ieee80211_offchannel_stop_vifs(local); |
| 382 | |
| 383 | local->tmp_channel = roc->chan; |
| 384 | ieee80211_hw_config(local, 0); |
| 385 | } |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 386 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 387 | ieee80211_queue_delayed_work(&local->hw, &local->roc_work, |
| 388 | msecs_to_jiffies(min_dur)); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 389 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 390 | /* tell userspace or send frame(s) */ |
| 391 | list_for_each_entry(tmp, &local->roc_list, list) { |
| 392 | if (tmp->sdata != roc->sdata || tmp->chan != roc->chan) |
| 393 | break; |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 394 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 395 | tmp->on_channel = roc->on_channel; |
| 396 | ieee80211_handle_roc_started(tmp, jiffies); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | void ieee80211_start_next_roc(struct ieee80211_local *local) |
| 402 | { |
| 403 | struct ieee80211_roc_work *roc; |
| 404 | |
| 405 | lockdep_assert_held(&local->mtx); |
| 406 | |
| 407 | if (list_empty(&local->roc_list)) { |
| 408 | ieee80211_run_deferred_scan(local); |
| 409 | return; |
| 410 | } |
| 411 | |
Eliad Peller | 470f4d6 | 2015-12-14 16:26:57 +0200 | [diff] [blame] | 412 | /* defer roc if driver is not started (i.e. during reconfig) */ |
| 413 | if (local->in_reconfig) |
| 414 | return; |
| 415 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 416 | roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work, |
| 417 | list); |
| 418 | |
| 419 | if (WARN_ON_ONCE(roc->started)) |
| 420 | return; |
| 421 | |
| 422 | if (local->ops->remain_on_channel) { |
| 423 | _ieee80211_start_next_roc(local); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 424 | } else { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 425 | /* delay it a bit */ |
| 426 | ieee80211_queue_delayed_work(&local->hw, &local->roc_work, |
| 427 | round_jiffies_relative(HZ/2)); |
| 428 | } |
| 429 | } |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 430 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 431 | static void __ieee80211_roc_work(struct ieee80211_local *local) |
| 432 | { |
| 433 | struct ieee80211_roc_work *roc; |
| 434 | bool on_channel; |
| 435 | |
| 436 | lockdep_assert_held(&local->mtx); |
| 437 | |
| 438 | if (WARN_ON(local->ops->remain_on_channel)) |
| 439 | return; |
| 440 | |
| 441 | roc = list_first_entry_or_null(&local->roc_list, |
| 442 | struct ieee80211_roc_work, list); |
| 443 | if (!roc) |
| 444 | return; |
| 445 | |
| 446 | if (!roc->started) { |
| 447 | WARN_ON(local->use_chanctx); |
| 448 | _ieee80211_start_next_roc(local); |
| 449 | } else { |
| 450 | on_channel = roc->on_channel; |
| 451 | if (ieee80211_recalc_sw_work(local, jiffies)) |
| 452 | return; |
| 453 | |
| 454 | /* careful - roc pointer became invalid during recalc */ |
| 455 | |
| 456 | if (!on_channel) { |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 457 | ieee80211_flush_queues(local, NULL, false); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 458 | |
| 459 | local->tmp_channel = NULL; |
| 460 | ieee80211_hw_config(local, 0); |
| 461 | |
Stanislaw Gruszka | aacde9e | 2012-12-20 14:41:18 +0100 | [diff] [blame] | 462 | ieee80211_offchannel_return(local); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | ieee80211_recalc_idle(local); |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 466 | ieee80211_start_next_roc(local); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 467 | } |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 468 | } |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 469 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 470 | static void ieee80211_roc_work(struct work_struct *work) |
| 471 | { |
| 472 | struct ieee80211_local *local = |
| 473 | container_of(work, struct ieee80211_local, roc_work.work); |
| 474 | |
| 475 | mutex_lock(&local->mtx); |
| 476 | __ieee80211_roc_work(local); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 477 | mutex_unlock(&local->mtx); |
| 478 | } |
| 479 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 480 | static void ieee80211_hw_roc_done(struct work_struct *work) |
| 481 | { |
| 482 | struct ieee80211_local *local = |
| 483 | container_of(work, struct ieee80211_local, hw_roc_done); |
| 484 | |
| 485 | mutex_lock(&local->mtx); |
| 486 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 487 | ieee80211_end_finished_rocs(local, jiffies); |
Johannes Berg | 71ecfa1 | 2012-05-31 15:09:27 +0200 | [diff] [blame] | 488 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 489 | /* if there's another roc, start it now */ |
| 490 | ieee80211_start_next_roc(local); |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 491 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 492 | mutex_unlock(&local->mtx); |
| 493 | } |
| 494 | |
| 495 | void ieee80211_remain_on_channel_expired(struct ieee80211_hw *hw) |
| 496 | { |
| 497 | struct ieee80211_local *local = hw_to_local(hw); |
| 498 | |
| 499 | trace_api_remain_on_channel_expired(local); |
| 500 | |
| 501 | ieee80211_queue_work(hw, &local->hw_roc_done); |
| 502 | } |
| 503 | EXPORT_SYMBOL_GPL(ieee80211_remain_on_channel_expired); |
| 504 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 505 | static bool |
| 506 | ieee80211_coalesce_hw_started_roc(struct ieee80211_local *local, |
| 507 | struct ieee80211_roc_work *new_roc, |
| 508 | struct ieee80211_roc_work *cur_roc) |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 509 | { |
| 510 | unsigned long now = jiffies; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 511 | unsigned long remaining; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 512 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 513 | if (WARN_ON(!cur_roc->started)) |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 514 | return false; |
| 515 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 516 | /* if it was scheduled in the hardware, but not started yet, |
| 517 | * we can only combine if the older one had a longer duration |
| 518 | */ |
| 519 | if (!cur_roc->hw_begun && new_roc->duration > cur_roc->duration) |
| 520 | return false; |
| 521 | |
| 522 | remaining = cur_roc->start_time + |
| 523 | msecs_to_jiffies(cur_roc->duration) - |
| 524 | now; |
| 525 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 526 | /* if it doesn't fit entirely, schedule a new one */ |
| 527 | if (new_roc->duration > jiffies_to_msecs(remaining)) |
| 528 | return false; |
| 529 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 530 | /* add just after the current one so we combine their finish later */ |
| 531 | list_add(&new_roc->list, &cur_roc->list); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 532 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 533 | /* if the existing one has already begun then let this one also |
| 534 | * begin, otherwise they'll both be marked properly by the work |
| 535 | * struct that runs once the driver notifies us of the beginning |
| 536 | */ |
Johannes Berg | e6a8a3a | 2015-12-08 23:46:33 +0100 | [diff] [blame] | 537 | if (cur_roc->hw_begun) { |
| 538 | new_roc->hw_begun = true; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 539 | ieee80211_handle_roc_started(new_roc, now); |
Johannes Berg | e6a8a3a | 2015-12-08 23:46:33 +0100 | [diff] [blame] | 540 | } |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 541 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 542 | return true; |
| 543 | } |
| 544 | |
| 545 | static int ieee80211_start_roc_work(struct ieee80211_local *local, |
| 546 | struct ieee80211_sub_if_data *sdata, |
| 547 | struct ieee80211_channel *channel, |
| 548 | unsigned int duration, u64 *cookie, |
| 549 | struct sk_buff *txskb, |
| 550 | enum ieee80211_roc_type type) |
| 551 | { |
| 552 | struct ieee80211_roc_work *roc, *tmp; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 553 | bool queued = false, combine_started = true; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 554 | int ret; |
| 555 | |
| 556 | lockdep_assert_held(&local->mtx); |
| 557 | |
| 558 | if (local->use_chanctx && !local->ops->remain_on_channel) |
| 559 | return -EOPNOTSUPP; |
| 560 | |
| 561 | roc = kzalloc(sizeof(*roc), GFP_KERNEL); |
| 562 | if (!roc) |
| 563 | return -ENOMEM; |
| 564 | |
| 565 | /* |
| 566 | * If the duration is zero, then the driver |
| 567 | * wouldn't actually do anything. Set it to |
| 568 | * 10 for now. |
| 569 | * |
| 570 | * TODO: cancel the off-channel operation |
| 571 | * when we get the SKB's TX status and |
| 572 | * the wait time was zero before. |
| 573 | */ |
| 574 | if (!duration) |
| 575 | duration = 10; |
| 576 | |
| 577 | roc->chan = channel; |
| 578 | roc->duration = duration; |
| 579 | roc->req_duration = duration; |
| 580 | roc->frame = txskb; |
| 581 | roc->type = type; |
| 582 | roc->sdata = sdata; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 583 | |
| 584 | /* |
| 585 | * cookie is either the roc cookie (for normal roc) |
| 586 | * or the SKB (for mgmt TX) |
| 587 | */ |
| 588 | if (!txskb) { |
| 589 | roc->cookie = ieee80211_mgmt_tx_cookie(local); |
| 590 | *cookie = roc->cookie; |
| 591 | } else { |
| 592 | roc->mgmt_tx_cookie = *cookie; |
| 593 | } |
| 594 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 595 | /* if there's no need to queue, handle it immediately */ |
| 596 | if (list_empty(&local->roc_list) && |
| 597 | !local->scanning && !ieee80211_is_radar_required(local)) { |
| 598 | /* if not HW assist, just queue & schedule work */ |
| 599 | if (!local->ops->remain_on_channel) { |
| 600 | list_add_tail(&roc->list, &local->roc_list); |
| 601 | ieee80211_queue_delayed_work(&local->hw, |
| 602 | &local->roc_work, 0); |
| 603 | } else { |
| 604 | /* otherwise actually kick it off here |
| 605 | * (for error handling) |
| 606 | */ |
| 607 | ret = drv_remain_on_channel(local, sdata, channel, |
| 608 | duration, type); |
| 609 | if (ret) { |
| 610 | kfree(roc); |
| 611 | return ret; |
| 612 | } |
| 613 | roc->started = true; |
| 614 | list_add_tail(&roc->list, &local->roc_list); |
| 615 | } |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 616 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 617 | return 0; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 618 | } |
| 619 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 620 | /* otherwise handle queueing */ |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 621 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 622 | list_for_each_entry(tmp, &local->roc_list, list) { |
| 623 | if (tmp->chan != channel || tmp->sdata != sdata) |
| 624 | continue; |
| 625 | |
| 626 | /* |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 627 | * Extend this ROC if possible: If it hasn't started, add |
| 628 | * just after the new one to combine. |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 629 | */ |
| 630 | if (!tmp->started) { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 631 | list_add(&roc->list, &tmp->list); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 632 | queued = true; |
| 633 | break; |
| 634 | } |
| 635 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 636 | if (!combine_started) |
| 637 | continue; |
| 638 | |
| 639 | if (!local->ops->remain_on_channel) { |
| 640 | /* If there's no hardware remain-on-channel, and |
| 641 | * doing so won't push us over the maximum r-o-c |
| 642 | * we allow, then we can just add the new one to |
| 643 | * the list and mark it as having started now. |
| 644 | * If it would push over the limit, don't try to |
| 645 | * combine with other started ones (that haven't |
| 646 | * been running as long) but potentially sort it |
| 647 | * with others that had the same fate. |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 648 | */ |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 649 | unsigned long now = jiffies; |
| 650 | u32 elapsed = jiffies_to_msecs(now - tmp->start_time); |
| 651 | struct wiphy *wiphy = local->hw.wiphy; |
| 652 | u32 max_roc = wiphy->max_remain_on_channel_duration; |
| 653 | |
| 654 | if (elapsed + roc->duration > max_roc) { |
| 655 | combine_started = false; |
| 656 | continue; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 657 | } |
| 658 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 659 | list_add(&roc->list, &tmp->list); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 660 | queued = true; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 661 | roc->on_channel = tmp->on_channel; |
| 662 | ieee80211_handle_roc_started(roc, now); |
Johannes Berg | e9db455 | 2015-12-08 13:16:41 +0100 | [diff] [blame] | 663 | ieee80211_recalc_sw_work(local, now); |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 664 | break; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 665 | } |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 666 | |
| 667 | queued = ieee80211_coalesce_hw_started_roc(local, roc, tmp); |
| 668 | if (queued) |
| 669 | break; |
| 670 | /* if it wasn't queued, perhaps it can be combined with |
| 671 | * another that also couldn't get combined previously, |
| 672 | * but no need to check for already started ones, since |
| 673 | * that can't work. |
| 674 | */ |
| 675 | combine_started = false; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 676 | } |
| 677 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 678 | if (!queued) |
| 679 | list_add_tail(&roc->list, &local->roc_list); |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | int ieee80211_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 685 | struct ieee80211_channel *chan, |
| 686 | unsigned int duration, u64 *cookie) |
| 687 | { |
| 688 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 689 | struct ieee80211_local *local = sdata->local; |
| 690 | int ret; |
| 691 | |
| 692 | mutex_lock(&local->mtx); |
| 693 | ret = ieee80211_start_roc_work(local, sdata, chan, |
| 694 | duration, cookie, NULL, |
| 695 | IEEE80211_ROC_TYPE_NORMAL); |
| 696 | mutex_unlock(&local->mtx); |
| 697 | |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | static int ieee80211_cancel_roc(struct ieee80211_local *local, |
| 702 | u64 cookie, bool mgmt_tx) |
| 703 | { |
| 704 | struct ieee80211_roc_work *roc, *tmp, *found = NULL; |
| 705 | int ret; |
| 706 | |
Johannes Berg | 7d37fcd | 2015-12-01 23:15:26 +0100 | [diff] [blame] | 707 | if (!cookie) |
| 708 | return -ENOENT; |
| 709 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 710 | mutex_lock(&local->mtx); |
| 711 | list_for_each_entry_safe(roc, tmp, &local->roc_list, list) { |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 712 | if (!mgmt_tx && roc->cookie != cookie) |
| 713 | continue; |
| 714 | else if (mgmt_tx && roc->mgmt_tx_cookie != cookie) |
| 715 | continue; |
| 716 | |
| 717 | found = roc; |
| 718 | break; |
| 719 | } |
| 720 | |
| 721 | if (!found) { |
| 722 | mutex_unlock(&local->mtx); |
| 723 | return -ENOENT; |
| 724 | } |
| 725 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 726 | if (!found->started) { |
| 727 | ieee80211_roc_notify_destroy(found); |
| 728 | goto out_unlock; |
| 729 | } |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 730 | |
| 731 | if (local->ops->remain_on_channel) { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 732 | ret = drv_cancel_remain_on_channel(local); |
| 733 | if (WARN_ON_ONCE(ret)) { |
| 734 | mutex_unlock(&local->mtx); |
| 735 | return ret; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 736 | } |
| 737 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 738 | /* TODO: |
| 739 | * if multiple items were combined here then we really shouldn't |
| 740 | * cancel them all - we should wait for as much time as needed |
| 741 | * for the longest remaining one, and only then cancel ... |
| 742 | */ |
| 743 | list_for_each_entry_safe(roc, tmp, &local->roc_list, list) { |
| 744 | if (!roc->started) |
| 745 | break; |
| 746 | if (roc == found) |
| 747 | found = NULL; |
| 748 | ieee80211_roc_notify_destroy(roc); |
| 749 | } |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 750 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 751 | /* that really must not happen - it was started */ |
| 752 | WARN_ON(found); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 753 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 754 | ieee80211_start_next_roc(local); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 755 | } else { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 756 | /* go through work struct to return to the operating channel */ |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 757 | found->abort = true; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 758 | mod_delayed_work(local->workqueue, &local->roc_work, 0); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 761 | out_unlock: |
| 762 | mutex_unlock(&local->mtx); |
| 763 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy, |
| 768 | struct wireless_dev *wdev, u64 cookie) |
| 769 | { |
| 770 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 771 | struct ieee80211_local *local = sdata->local; |
| 772 | |
| 773 | return ieee80211_cancel_roc(local, cookie, false); |
| 774 | } |
| 775 | |
| 776 | int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 777 | struct cfg80211_mgmt_tx_params *params, u64 *cookie) |
| 778 | { |
| 779 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 780 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 781 | struct sk_buff *skb; |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 782 | struct sta_info *sta; |
| 783 | const struct ieee80211_mgmt *mgmt = (void *)params->buf; |
| 784 | bool need_offchan = false; |
| 785 | u32 flags; |
| 786 | int ret; |
| 787 | u8 *data; |
| 788 | |
| 789 | if (params->dont_wait_for_ack) |
| 790 | flags = IEEE80211_TX_CTL_NO_ACK; |
| 791 | else |
| 792 | flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX | |
| 793 | IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 794 | |
| 795 | if (params->no_cck) |
| 796 | flags |= IEEE80211_TX_CTL_NO_CCK_RATE; |
| 797 | |
| 798 | switch (sdata->vif.type) { |
| 799 | case NL80211_IFTYPE_ADHOC: |
| 800 | if (!sdata->vif.bss_conf.ibss_joined) |
| 801 | need_offchan = true; |
| 802 | /* fall through */ |
| 803 | #ifdef CONFIG_MAC80211_MESH |
| 804 | case NL80211_IFTYPE_MESH_POINT: |
| 805 | if (ieee80211_vif_is_mesh(&sdata->vif) && |
| 806 | !sdata->u.mesh.mesh_id_len) |
| 807 | need_offchan = true; |
| 808 | /* fall through */ |
| 809 | #endif |
| 810 | case NL80211_IFTYPE_AP: |
| 811 | case NL80211_IFTYPE_AP_VLAN: |
| 812 | case NL80211_IFTYPE_P2P_GO: |
| 813 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC && |
| 814 | !ieee80211_vif_is_mesh(&sdata->vif) && |
| 815 | !rcu_access_pointer(sdata->bss->beacon)) |
| 816 | need_offchan = true; |
| 817 | if (!ieee80211_is_action(mgmt->frame_control) || |
| 818 | mgmt->u.action.category == WLAN_CATEGORY_PUBLIC || |
| 819 | mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED || |
| 820 | mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) |
| 821 | break; |
| 822 | rcu_read_lock(); |
Michael Braun | 1d4de2e | 2016-10-03 13:14:15 +0200 | [diff] [blame] | 823 | sta = sta_info_get_bss(sdata, mgmt->da); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 824 | rcu_read_unlock(); |
| 825 | if (!sta) |
| 826 | return -ENOLINK; |
| 827 | break; |
| 828 | case NL80211_IFTYPE_STATION: |
| 829 | case NL80211_IFTYPE_P2P_CLIENT: |
| 830 | sdata_lock(sdata); |
| 831 | if (!sdata->u.mgd.associated || |
| 832 | (params->offchan && params->wait && |
| 833 | local->ops->remain_on_channel && |
| 834 | memcmp(sdata->u.mgd.associated->bssid, |
| 835 | mgmt->bssid, ETH_ALEN))) |
| 836 | need_offchan = true; |
| 837 | sdata_unlock(sdata); |
| 838 | break; |
| 839 | case NL80211_IFTYPE_P2P_DEVICE: |
| 840 | need_offchan = true; |
| 841 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 842 | case NL80211_IFTYPE_NAN: |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 843 | default: |
| 844 | return -EOPNOTSUPP; |
| 845 | } |
| 846 | |
| 847 | /* configurations requiring offchan cannot work if no channel has been |
| 848 | * specified |
| 849 | */ |
| 850 | if (need_offchan && !params->chan) |
| 851 | return -EINVAL; |
| 852 | |
| 853 | mutex_lock(&local->mtx); |
| 854 | |
| 855 | /* Check if the operating channel is the requested channel */ |
| 856 | if (!need_offchan) { |
| 857 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 858 | |
| 859 | rcu_read_lock(); |
| 860 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 861 | |
| 862 | if (chanctx_conf) { |
| 863 | need_offchan = params->chan && |
| 864 | (params->chan != |
| 865 | chanctx_conf->def.chan); |
| 866 | } else if (!params->chan) { |
| 867 | ret = -EINVAL; |
| 868 | rcu_read_unlock(); |
| 869 | goto out_unlock; |
| 870 | } else { |
| 871 | need_offchan = true; |
| 872 | } |
| 873 | rcu_read_unlock(); |
| 874 | } |
| 875 | |
| 876 | if (need_offchan && !params->offchan) { |
| 877 | ret = -EBUSY; |
| 878 | goto out_unlock; |
| 879 | } |
| 880 | |
| 881 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len); |
| 882 | if (!skb) { |
| 883 | ret = -ENOMEM; |
| 884 | goto out_unlock; |
| 885 | } |
| 886 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 887 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame^] | 888 | data = skb_put_data(skb, params->buf, params->len); |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 889 | |
| 890 | /* Update CSA counters */ |
| 891 | if (sdata->vif.csa_active && |
| 892 | (sdata->vif.type == NL80211_IFTYPE_AP || |
| 893 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT || |
| 894 | sdata->vif.type == NL80211_IFTYPE_ADHOC) && |
| 895 | params->n_csa_offsets) { |
| 896 | int i; |
| 897 | struct beacon_data *beacon = NULL; |
| 898 | |
| 899 | rcu_read_lock(); |
| 900 | |
| 901 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 902 | beacon = rcu_dereference(sdata->u.ap.beacon); |
| 903 | else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 904 | beacon = rcu_dereference(sdata->u.ibss.presp); |
| 905 | else if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 906 | beacon = rcu_dereference(sdata->u.mesh.beacon); |
| 907 | |
| 908 | if (beacon) |
| 909 | for (i = 0; i < params->n_csa_offsets; i++) |
| 910 | data[params->csa_offsets[i]] = |
| 911 | beacon->csa_current_counter; |
| 912 | |
| 913 | rcu_read_unlock(); |
| 914 | } |
| 915 | |
| 916 | IEEE80211_SKB_CB(skb)->flags = flags; |
| 917 | |
| 918 | skb->dev = sdata->dev; |
| 919 | |
| 920 | if (!params->dont_wait_for_ack) { |
| 921 | /* make a copy to preserve the frame contents |
| 922 | * in case of encryption. |
| 923 | */ |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 924 | ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_KERNEL); |
| 925 | if (ret) { |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 926 | kfree_skb(skb); |
| 927 | goto out_unlock; |
| 928 | } |
| 929 | } else { |
| 930 | /* Assign a dummy non-zero cookie, it's not sent to |
| 931 | * userspace in this case but we rely on its value |
| 932 | * internally in the need_offchan case to distinguish |
| 933 | * mgmt-tx from remain-on-channel. |
| 934 | */ |
| 935 | *cookie = 0xffffffff; |
| 936 | } |
| 937 | |
| 938 | if (!need_offchan) { |
| 939 | ieee80211_tx_skb(sdata, skb); |
| 940 | ret = 0; |
| 941 | goto out_unlock; |
| 942 | } |
| 943 | |
| 944 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN | |
| 945 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK; |
| 946 | if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) |
| 947 | IEEE80211_SKB_CB(skb)->hw_queue = |
| 948 | local->hw.offchannel_tx_hw_queue; |
| 949 | |
| 950 | /* This will handle all kinds of coalescing and immediate TX */ |
| 951 | ret = ieee80211_start_roc_work(local, sdata, params->chan, |
| 952 | params->wait, cookie, skb, |
| 953 | IEEE80211_ROC_TYPE_MGMT_TX); |
| 954 | if (ret) |
| 955 | ieee80211_free_txskb(&local->hw, skb); |
| 956 | out_unlock: |
| 957 | mutex_unlock(&local->mtx); |
| 958 | return ret; |
| 959 | } |
| 960 | |
| 961 | int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy, |
| 962 | struct wireless_dev *wdev, u64 cookie) |
| 963 | { |
| 964 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 965 | |
| 966 | return ieee80211_cancel_roc(local, cookie, true); |
| 967 | } |
| 968 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 969 | void ieee80211_roc_setup(struct ieee80211_local *local) |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 970 | { |
| 971 | INIT_WORK(&local->hw_roc_start, ieee80211_hw_roc_start); |
| 972 | INIT_WORK(&local->hw_roc_done, ieee80211_hw_roc_done); |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 973 | INIT_DELAYED_WORK(&local->roc_work, ieee80211_roc_work); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 974 | INIT_LIST_HEAD(&local->roc_list); |
| 975 | } |
| 976 | |
Johannes Berg | c8f994e | 2013-03-27 22:49:19 +0100 | [diff] [blame] | 977 | void ieee80211_roc_purge(struct ieee80211_local *local, |
| 978 | struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 979 | { |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 980 | struct ieee80211_roc_work *roc, *tmp; |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 981 | bool work_to_do = false; |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 982 | |
| 983 | mutex_lock(&local->mtx); |
| 984 | list_for_each_entry_safe(roc, tmp, &local->roc_list, list) { |
Johannes Berg | c8f994e | 2013-03-27 22:49:19 +0100 | [diff] [blame] | 985 | if (sdata && roc->sdata != sdata) |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 986 | continue; |
| 987 | |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 988 | if (roc->started) { |
| 989 | if (local->ops->remain_on_channel) { |
| 990 | /* can race, so ignore return value */ |
| 991 | drv_cancel_remain_on_channel(local); |
| 992 | ieee80211_roc_notify_destroy(roc); |
| 993 | } else { |
| 994 | roc->abort = true; |
| 995 | work_to_do = true; |
| 996 | } |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 997 | } else { |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 998 | ieee80211_roc_notify_destroy(roc); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame] | 999 | } |
| 1000 | } |
Johannes Berg | aaa016c | 2015-11-23 23:53:51 +0100 | [diff] [blame] | 1001 | if (work_to_do) |
| 1002 | __ieee80211_roc_work(local); |
| 1003 | mutex_unlock(&local->mtx); |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 1004 | } |