blob: 6e5961d7f639dfe73fe500e9e66ce4cfe9b43e03 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Jouni Malinenb203ffc2009-12-23 13:15:40 +01002/*
3 * Off-channel operation helpers
4 *
5 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
6 * Copyright 2004, Instant802 Networks, Inc.
7 * Copyright 2005, Devicescape Software, Inc.
8 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
9 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
10 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
Jouni Malinenb203ffc2009-12-23 13:15:40 +010011 */
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040012#include <linux/export.h>
Jouni Malinenb203ffc2009-12-23 13:15:40 +010013#include <net/mac80211.h>
14#include "ieee80211_i.h"
Johannes Berg2eb278e2012-06-05 14:28:42 +020015#include "driver-ops.h"
Jouni Malinenb203ffc2009-12-23 13:15:40 +010016
17/*
Ben Greearb23b0252011-02-04 11:54:17 -080018 * Tell our hardware to disable PS.
19 * Optionally inform AP that we will go to sleep so that it will buffer
20 * the frames while we are doing off-channel work. This is optional
21 * because we *may* be doing work on-operating channel, and want our
22 * hardware unconditionally awake, but still let the AP send us normal frames.
Jouni Malinenb203ffc2009-12-23 13:15:40 +010023 */
Rajkumar Manoharan559cef92012-06-18 19:03:52 +053024static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata)
Jouni Malinenb203ffc2009-12-23 13:15:40 +010025{
26 struct ieee80211_local *local = sdata->local;
Luis R. Rodriguez4730d592010-09-16 15:12:31 -040027 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinenb203ffc2009-12-23 13:15:40 +010028
29 local->offchannel_ps_enabled = false;
30
31 /* FIXME: what to do when local->pspolling is true? */
32
33 del_timer_sync(&local->dynamic_ps_timer);
Luis R. Rodriguez3bc3c0d2010-09-16 15:12:33 -040034 del_timer_sync(&ifmgd->bcn_mon_timer);
Luis R. Rodriguez4730d592010-09-16 15:12:31 -040035 del_timer_sync(&ifmgd->conn_mon_timer);
36
Jouni Malinenb203ffc2009-12-23 13:15:40 +010037 cancel_work_sync(&local->dynamic_ps_enable_work);
38
39 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
40 local->offchannel_ps_enabled = true;
41 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
42 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
43 }
44
Rajkumar Manoharan559cef92012-06-18 19:03:52 +053045 if (!local->offchannel_ps_enabled ||
Johannes Berg30686bf2015-06-02 21:39:54 +020046 !ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
Jouni Malinenb203ffc2009-12-23 13:15:40 +010047 /*
48 * If power save was enabled, no need to send a nullfunc
49 * frame because AP knows that we are sleeping. But if the
50 * hardware is creating the nullfunc frame for power save
51 * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
52 * enabled) and power save was enabled, the firmware just
53 * sent a null frame with power save disabled. So we need
54 * to send a new nullfunc frame to inform the AP that we
55 * are again sleeping.
56 */
Johannes Berg076cdcb2015-09-24 16:14:55 +020057 ieee80211_send_nullfunc(local, sdata, true);
Jouni Malinenb203ffc2009-12-23 13:15:40 +010058}
59
60/* inform AP that we are awake again, unless power save is enabled */
61static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
62{
63 struct ieee80211_local *local = sdata->local;
64
65 if (!local->ps_sdata)
Johannes Berg076cdcb2015-09-24 16:14:55 +020066 ieee80211_send_nullfunc(local, sdata, false);
Jouni Malinenb203ffc2009-12-23 13:15:40 +010067 else if (local->offchannel_ps_enabled) {
68 /*
69 * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
70 * will send a nullfunc frame with the powersave bit set
71 * even though the AP already knows that we are sleeping.
72 * This could be avoided by sending a null frame with power
73 * save bit disabled before enabling the power save, but
74 * this doesn't gain anything.
75 *
76 * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
77 * to send a nullfunc frame because AP already knows that
78 * we are sleeping, let's just enable power save mode in
79 * hardware.
80 */
Ben Greearb23b0252011-02-04 11:54:17 -080081 /* TODO: Only set hardware if CONF_PS changed?
82 * TODO: Should we set offchannel_ps_enabled to false?
83 */
Jouni Malinenb203ffc2009-12-23 13:15:40 +010084 local->hw.conf.flags |= IEEE80211_CONF_PS;
85 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
86 } else if (local->hw.conf.dynamic_ps_timeout > 0) {
87 /*
88 * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer
89 * had been running before leaving the operating channel,
90 * restart the timer now and send a nullfunc frame to inform
91 * the AP that we are awake.
92 */
Johannes Berg076cdcb2015-09-24 16:14:55 +020093 ieee80211_send_nullfunc(local, sdata, false);
Jouni Malinenb203ffc2009-12-23 13:15:40 +010094 mod_timer(&local->dynamic_ps_timer, jiffies +
95 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
96 }
Luis R. Rodriguez4730d592010-09-16 15:12:31 -040097
Luis R. Rodriguez3bc3c0d2010-09-16 15:12:33 -040098 ieee80211_sta_reset_beacon_monitor(sdata);
Luis R. Rodriguez4730d592010-09-16 15:12:31 -040099 ieee80211_sta_reset_conn_monitor(sdata);
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100100}
101
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +0100102void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local)
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100103{
104 struct ieee80211_sub_if_data *sdata;
105
Johannes Bergfe57d9f2012-07-26 14:55:08 +0200106 if (WARN_ON(local->use_chanctx))
107 return;
108
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100109 /*
Ben Greearb23b0252011-02-04 11:54:17 -0800110 * notify the AP about us leaving the channel and stop all
111 * STA interfaces.
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100112 */
Seth Forshee6c17b772013-02-11 11:21:07 -0600113
Seth Forshee9c35d7d2013-02-11 11:21:08 -0600114 /*
115 * Stop queues and transmit all frames queued by the driver
116 * before sending nullfunc to enable powersave at the AP.
117 */
Johannes Berg445ea4e2013-02-13 12:25:28 +0100118 ieee80211_stop_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +0300119 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL,
120 false);
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +0200121 ieee80211_flush_queues(local, NULL, false);
Seth Forshee6c17b772013-02-11 11:21:07 -0600122
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100123 mutex_lock(&local->iflist_mtx);
124 list_for_each_entry(sdata, &local->interfaces, list) {
125 if (!ieee80211_sdata_running(sdata))
126 continue;
127
Ayala Beker708d50e2016-09-20 17:31:14 +0300128 if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
129 sdata->vif.type == NL80211_IFTYPE_NAN)
Johannes Bergf142c6b2012-06-18 20:07:15 +0200130 continue;
131
Ben Greearb23b0252011-02-04 11:54:17 -0800132 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
Johannes Berg5b714c62010-08-27 13:45:28 +0200133 set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
Ben Greearb23b0252011-02-04 11:54:17 -0800134
135 /* Check to see if we should disable beaconing. */
Johannes Bergd6a83222012-12-14 14:06:28 +0100136 if (sdata->vif.bss_conf.enable_beacon) {
137 set_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED,
138 &sdata->state);
139 sdata->vif.bss_conf.enable_beacon = false;
Ben Greearb23b0252011-02-04 11:54:17 -0800140 ieee80211_bss_info_change_notify(
141 sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Bergd6a83222012-12-14 14:06:28 +0100142 }
Ben Greearb23b0252011-02-04 11:54:17 -0800143
Seth Forshee6c17b772013-02-11 11:21:07 -0600144 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
145 sdata->u.mgd.associated)
146 ieee80211_offchannel_ps_enable(sdata);
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100147 }
148 mutex_unlock(&local->iflist_mtx);
149}
150
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +0100151void ieee80211_offchannel_return(struct ieee80211_local *local)
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100152{
153 struct ieee80211_sub_if_data *sdata;
154
Johannes Bergfe57d9f2012-07-26 14:55:08 +0200155 if (WARN_ON(local->use_chanctx))
156 return;
157
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100158 mutex_lock(&local->iflist_mtx);
159 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Bergf142c6b2012-06-18 20:07:15 +0200160 if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
161 continue;
162
Eliad Pellerf6e8cb72011-12-23 01:48:06 +0200163 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
164 clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
165
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100166 if (!ieee80211_sdata_running(sdata))
167 continue;
168
169 /* Tell AP we're back */
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +0100170 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
171 sdata->u.mgd.associated)
172 ieee80211_offchannel_ps_disable(sdata);
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100173
Johannes Bergd6a83222012-12-14 14:06:28 +0100174 if (test_and_clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED,
175 &sdata->state)) {
176 sdata->vif.bss_conf.enable_beacon = true;
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100177 ieee80211_bss_info_change_notify(
178 sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Bergd6a83222012-12-14 14:06:28 +0100179 }
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100180 }
181 mutex_unlock(&local->iflist_mtx);
Seth Forshee6c17b772013-02-11 11:21:07 -0600182
Johannes Berg445ea4e2013-02-13 12:25:28 +0100183 ieee80211_wake_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +0300184 IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL,
185 false);
Jouni Malinenb203ffc2009-12-23 13:15:40 +0100186}
Johannes Berg21f83582010-12-18 17:20:47 +0100187
Johannes Bergaaa016c2015-11-23 23:53:51 +0100188static void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +0200189{
Johannes Bergaaa016c2015-11-23 23:53:51 +0100190 /* was never transmitted */
191 if (roc->frame) {
192 cfg80211_mgmt_tx_status(&roc->sdata->wdev, roc->mgmt_tx_cookie,
193 roc->frame->data, roc->frame->len,
194 false, GFP_KERNEL);
195 ieee80211_free_txskb(&roc->sdata->local->hw, roc->frame);
196 }
197
198 if (!roc->mgmt_tx_cookie)
199 cfg80211_remain_on_channel_expired(&roc->sdata->wdev,
200 roc->cookie, roc->chan,
201 GFP_KERNEL);
202
203 list_del(&roc->list);
204 kfree(roc);
205}
206
207static unsigned long ieee80211_end_finished_rocs(struct ieee80211_local *local,
208 unsigned long now)
209{
210 struct ieee80211_roc_work *roc, *tmp;
211 long remaining_dur_min = LONG_MAX;
212
213 lockdep_assert_held(&local->mtx);
214
215 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
216 long remaining;
217
218 if (!roc->started)
219 break;
220
221 remaining = roc->start_time +
222 msecs_to_jiffies(roc->duration) -
223 now;
224
Ilan Peer1b894522015-12-06 21:19:15 +0200225 /* In case of HW ROC, it is possible that the HW finished the
226 * ROC session before the actual requested time. In such a case
227 * end the ROC session (disregarding the remaining time).
228 */
229 if (roc->abort || roc->hw_begun || remaining <= 0)
Johannes Bergaaa016c2015-11-23 23:53:51 +0100230 ieee80211_roc_notify_destroy(roc);
231 else
232 remaining_dur_min = min(remaining_dur_min, remaining);
233 }
234
235 return remaining_dur_min;
236}
237
238static bool ieee80211_recalc_sw_work(struct ieee80211_local *local,
239 unsigned long now)
240{
241 long dur = ieee80211_end_finished_rocs(local, now);
242
243 if (dur == LONG_MAX)
244 return false;
245
246 mod_delayed_work(local->workqueue, &local->roc_work, dur);
247 return true;
248}
249
250static void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc,
251 unsigned long start_time)
252{
Johannes Bergaaa016c2015-11-23 23:53:51 +0100253 if (WARN_ON(roc->notified))
Johannes Berg2eb278e2012-06-05 14:28:42 +0200254 return;
255
Johannes Bergaaa016c2015-11-23 23:53:51 +0100256 roc->start_time = start_time;
257 roc->started = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100258
Johannes Berg2eb278e2012-06-05 14:28:42 +0200259 if (roc->mgmt_tx_cookie) {
260 if (!WARN_ON(!roc->frame)) {
Johannes Berg55de9082012-07-26 17:24:39 +0200261 ieee80211_tx_skb_tid_band(roc->sdata, roc->frame, 7,
Johannes Bergb9771d42018-05-28 15:47:41 +0200262 roc->chan->band, 0);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200263 roc->frame = NULL;
264 }
265 } else {
Johannes Berg50febf62012-10-26 16:13:06 +0200266 cfg80211_ready_on_channel(&roc->sdata->wdev, roc->cookie,
Johannes Berg42d97a52012-11-08 18:31:02 +0100267 roc->chan, roc->req_duration,
268 GFP_KERNEL);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200269 }
270
271 roc->notified = true;
272}
273
Johannes Berg21f83582010-12-18 17:20:47 +0100274static void ieee80211_hw_roc_start(struct work_struct *work)
275{
276 struct ieee80211_local *local =
277 container_of(work, struct ieee80211_local, hw_roc_start);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100278 struct ieee80211_roc_work *roc;
Johannes Berg21f83582010-12-18 17:20:47 +0100279
280 mutex_lock(&local->mtx);
281
Johannes Bergaaa016c2015-11-23 23:53:51 +0100282 list_for_each_entry(roc, &local->roc_list, list) {
283 if (!roc->started)
284 break;
Johannes Berg21f83582010-12-18 17:20:47 +0100285
Johannes Berge6a8a3a2015-12-08 23:46:33 +0100286 roc->hw_begun = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100287 ieee80211_handle_roc_started(roc, local->hw_roc_start_time);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200288 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100289
Johannes Berg21f83582010-12-18 17:20:47 +0100290 mutex_unlock(&local->mtx);
291}
292
293void ieee80211_ready_on_channel(struct ieee80211_hw *hw)
294{
295 struct ieee80211_local *local = hw_to_local(hw);
296
Johannes Berg2eb278e2012-06-05 14:28:42 +0200297 local->hw_roc_start_time = jiffies;
298
Johannes Berg21f83582010-12-18 17:20:47 +0100299 trace_api_ready_on_channel(local);
300
301 ieee80211_queue_work(hw, &local->hw_roc_start);
302}
303EXPORT_SYMBOL_GPL(ieee80211_ready_on_channel);
304
Johannes Bergaaa016c2015-11-23 23:53:51 +0100305static void _ieee80211_start_next_roc(struct ieee80211_local *local)
Johannes Berg2eb278e2012-06-05 14:28:42 +0200306{
Johannes Bergaaa016c2015-11-23 23:53:51 +0100307 struct ieee80211_roc_work *roc, *tmp;
308 enum ieee80211_roc_type type;
309 u32 min_dur, max_dur;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200310
311 lockdep_assert_held(&local->mtx);
312
Johannes Bergaaa016c2015-11-23 23:53:51 +0100313 if (WARN_ON(list_empty(&local->roc_list)))
Johannes Berg2eb278e2012-06-05 14:28:42 +0200314 return;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200315
316 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
317 list);
318
Johannes Bergaaa016c2015-11-23 23:53:51 +0100319 if (WARN_ON(roc->started))
Johannes Berg0f6b3f52012-06-20 20:11:33 +0200320 return;
321
Johannes Bergaaa016c2015-11-23 23:53:51 +0100322 min_dur = roc->duration;
323 max_dur = roc->duration;
324 type = roc->type;
325
326 list_for_each_entry(tmp, &local->roc_list, list) {
327 if (tmp == roc)
328 continue;
329 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
330 break;
331 max_dur = max(tmp->duration, max_dur);
332 min_dur = min(tmp->duration, min_dur);
333 type = max(tmp->type, type);
334 }
335
Johannes Berg2eb278e2012-06-05 14:28:42 +0200336 if (local->ops->remain_on_channel) {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100337 int ret = drv_remain_on_channel(local, roc->sdata, roc->chan,
338 max_dur, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200339
340 if (ret) {
341 wiphy_warn(local->hw.wiphy,
342 "failed to start next HW ROC (%d)\n", ret);
343 /*
344 * queue the work struct again to avoid recursion
345 * when multiple failures occur
346 */
Johannes Bergaaa016c2015-11-23 23:53:51 +0100347 list_for_each_entry(tmp, &local->roc_list, list) {
348 if (tmp->sdata != roc->sdata ||
349 tmp->chan != roc->chan)
350 break;
351 tmp->started = true;
352 tmp->abort = true;
353 }
354 ieee80211_queue_work(&local->hw, &local->hw_roc_done);
355 return;
356 }
357
358 /* we'll notify about the start once the HW calls back */
359 list_for_each_entry(tmp, &local->roc_list, list) {
360 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
361 break;
362 tmp->started = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200363 }
364 } else {
Johannes Bergb4b177a2014-05-14 15:34:41 +0200365 /* If actually operating on the desired channel (with at least
366 * 20 MHz channel width) don't stop all the operations but still
367 * treat it as though the ROC operation started properly, so
368 * other ROC operations won't interfere with this one.
369 */
370 roc->on_channel = roc->chan == local->_oper_chandef.chan &&
371 local->_oper_chandef.width != NL80211_CHAN_WIDTH_5 &&
372 local->_oper_chandef.width != NL80211_CHAN_WIDTH_10;
373
374 /* start this ROC */
Johannes Berg2eb278e2012-06-05 14:28:42 +0200375 ieee80211_recalc_idle(local);
376
Johannes Bergb4b177a2014-05-14 15:34:41 +0200377 if (!roc->on_channel) {
378 ieee80211_offchannel_stop_vifs(local);
379
380 local->tmp_channel = roc->chan;
381 ieee80211_hw_config(local, 0);
382 }
Johannes Berg2eb278e2012-06-05 14:28:42 +0200383
Johannes Bergaaa016c2015-11-23 23:53:51 +0100384 ieee80211_queue_delayed_work(&local->hw, &local->roc_work,
385 msecs_to_jiffies(min_dur));
Johannes Berg2eb278e2012-06-05 14:28:42 +0200386
Johannes Bergaaa016c2015-11-23 23:53:51 +0100387 /* tell userspace or send frame(s) */
388 list_for_each_entry(tmp, &local->roc_list, list) {
389 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
390 break;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200391
Johannes Bergaaa016c2015-11-23 23:53:51 +0100392 tmp->on_channel = roc->on_channel;
393 ieee80211_handle_roc_started(tmp, jiffies);
394 }
395 }
396}
397
398void ieee80211_start_next_roc(struct ieee80211_local *local)
399{
400 struct ieee80211_roc_work *roc;
401
402 lockdep_assert_held(&local->mtx);
403
404 if (list_empty(&local->roc_list)) {
405 ieee80211_run_deferred_scan(local);
406 return;
407 }
408
Eliad Peller470f4d62015-12-14 16:26:57 +0200409 /* defer roc if driver is not started (i.e. during reconfig) */
410 if (local->in_reconfig)
411 return;
412
Johannes Bergaaa016c2015-11-23 23:53:51 +0100413 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
414 list);
415
416 if (WARN_ON_ONCE(roc->started))
417 return;
418
419 if (local->ops->remain_on_channel) {
420 _ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200421 } else {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100422 /* delay it a bit */
423 ieee80211_queue_delayed_work(&local->hw, &local->roc_work,
424 round_jiffies_relative(HZ/2));
425 }
426}
Johannes Berg2eb278e2012-06-05 14:28:42 +0200427
Johannes Bergaaa016c2015-11-23 23:53:51 +0100428static void __ieee80211_roc_work(struct ieee80211_local *local)
429{
430 struct ieee80211_roc_work *roc;
431 bool on_channel;
432
433 lockdep_assert_held(&local->mtx);
434
435 if (WARN_ON(local->ops->remain_on_channel))
436 return;
437
438 roc = list_first_entry_or_null(&local->roc_list,
439 struct ieee80211_roc_work, list);
440 if (!roc)
441 return;
442
443 if (!roc->started) {
444 WARN_ON(local->use_chanctx);
445 _ieee80211_start_next_roc(local);
446 } else {
447 on_channel = roc->on_channel;
448 if (ieee80211_recalc_sw_work(local, jiffies))
449 return;
450
451 /* careful - roc pointer became invalid during recalc */
452
453 if (!on_channel) {
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +0200454 ieee80211_flush_queues(local, NULL, false);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200455
456 local->tmp_channel = NULL;
457 ieee80211_hw_config(local, 0);
458
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +0100459 ieee80211_offchannel_return(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200460 }
461
462 ieee80211_recalc_idle(local);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100463 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200464 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100465}
Johannes Berg2eb278e2012-06-05 14:28:42 +0200466
Johannes Bergaaa016c2015-11-23 23:53:51 +0100467static void ieee80211_roc_work(struct work_struct *work)
468{
469 struct ieee80211_local *local =
470 container_of(work, struct ieee80211_local, roc_work.work);
471
472 mutex_lock(&local->mtx);
473 __ieee80211_roc_work(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200474 mutex_unlock(&local->mtx);
475}
476
Johannes Berg21f83582010-12-18 17:20:47 +0100477static void ieee80211_hw_roc_done(struct work_struct *work)
478{
479 struct ieee80211_local *local =
480 container_of(work, struct ieee80211_local, hw_roc_done);
481
482 mutex_lock(&local->mtx);
483
Johannes Bergaaa016c2015-11-23 23:53:51 +0100484 ieee80211_end_finished_rocs(local, jiffies);
Johannes Berg71ecfa12012-05-31 15:09:27 +0200485
Johannes Berg2eb278e2012-06-05 14:28:42 +0200486 /* if there's another roc, start it now */
487 ieee80211_start_next_roc(local);
Johannes Berg21f83582010-12-18 17:20:47 +0100488
Johannes Berg21f83582010-12-18 17:20:47 +0100489 mutex_unlock(&local->mtx);
490}
491
492void ieee80211_remain_on_channel_expired(struct ieee80211_hw *hw)
493{
494 struct ieee80211_local *local = hw_to_local(hw);
495
496 trace_api_remain_on_channel_expired(local);
497
498 ieee80211_queue_work(hw, &local->hw_roc_done);
499}
500EXPORT_SYMBOL_GPL(ieee80211_remain_on_channel_expired);
501
Johannes Bergaaa016c2015-11-23 23:53:51 +0100502static bool
503ieee80211_coalesce_hw_started_roc(struct ieee80211_local *local,
504 struct ieee80211_roc_work *new_roc,
505 struct ieee80211_roc_work *cur_roc)
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100506{
507 unsigned long now = jiffies;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100508 unsigned long remaining;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100509
Johannes Bergaaa016c2015-11-23 23:53:51 +0100510 if (WARN_ON(!cur_roc->started))
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100511 return false;
512
Johannes Bergaaa016c2015-11-23 23:53:51 +0100513 /* if it was scheduled in the hardware, but not started yet,
514 * we can only combine if the older one had a longer duration
515 */
516 if (!cur_roc->hw_begun && new_roc->duration > cur_roc->duration)
517 return false;
518
519 remaining = cur_roc->start_time +
520 msecs_to_jiffies(cur_roc->duration) -
521 now;
522
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100523 /* if it doesn't fit entirely, schedule a new one */
524 if (new_roc->duration > jiffies_to_msecs(remaining))
525 return false;
526
Johannes Bergaaa016c2015-11-23 23:53:51 +0100527 /* add just after the current one so we combine their finish later */
528 list_add(&new_roc->list, &cur_roc->list);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100529
Johannes Bergaaa016c2015-11-23 23:53:51 +0100530 /* if the existing one has already begun then let this one also
531 * begin, otherwise they'll both be marked properly by the work
532 * struct that runs once the driver notifies us of the beginning
533 */
Johannes Berge6a8a3a2015-12-08 23:46:33 +0100534 if (cur_roc->hw_begun) {
535 new_roc->hw_begun = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100536 ieee80211_handle_roc_started(new_roc, now);
Johannes Berge6a8a3a2015-12-08 23:46:33 +0100537 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100538
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100539 return true;
540}
541
542static int ieee80211_start_roc_work(struct ieee80211_local *local,
543 struct ieee80211_sub_if_data *sdata,
544 struct ieee80211_channel *channel,
545 unsigned int duration, u64 *cookie,
546 struct sk_buff *txskb,
547 enum ieee80211_roc_type type)
548{
549 struct ieee80211_roc_work *roc, *tmp;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100550 bool queued = false, combine_started = true;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100551 int ret;
552
553 lockdep_assert_held(&local->mtx);
554
555 if (local->use_chanctx && !local->ops->remain_on_channel)
556 return -EOPNOTSUPP;
557
558 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
559 if (!roc)
560 return -ENOMEM;
561
562 /*
563 * If the duration is zero, then the driver
564 * wouldn't actually do anything. Set it to
565 * 10 for now.
566 *
567 * TODO: cancel the off-channel operation
568 * when we get the SKB's TX status and
569 * the wait time was zero before.
570 */
571 if (!duration)
572 duration = 10;
573
574 roc->chan = channel;
575 roc->duration = duration;
576 roc->req_duration = duration;
577 roc->frame = txskb;
578 roc->type = type;
579 roc->sdata = sdata;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100580
581 /*
582 * cookie is either the roc cookie (for normal roc)
583 * or the SKB (for mgmt TX)
584 */
585 if (!txskb) {
586 roc->cookie = ieee80211_mgmt_tx_cookie(local);
587 *cookie = roc->cookie;
588 } else {
589 roc->mgmt_tx_cookie = *cookie;
590 }
591
Johannes Bergaaa016c2015-11-23 23:53:51 +0100592 /* if there's no need to queue, handle it immediately */
593 if (list_empty(&local->roc_list) &&
594 !local->scanning && !ieee80211_is_radar_required(local)) {
595 /* if not HW assist, just queue & schedule work */
596 if (!local->ops->remain_on_channel) {
597 list_add_tail(&roc->list, &local->roc_list);
598 ieee80211_queue_delayed_work(&local->hw,
599 &local->roc_work, 0);
600 } else {
601 /* otherwise actually kick it off here
602 * (for error handling)
603 */
604 ret = drv_remain_on_channel(local, sdata, channel,
605 duration, type);
606 if (ret) {
607 kfree(roc);
608 return ret;
609 }
610 roc->started = true;
611 list_add_tail(&roc->list, &local->roc_list);
612 }
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100613
Johannes Bergaaa016c2015-11-23 23:53:51 +0100614 return 0;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100615 }
616
Johannes Bergaaa016c2015-11-23 23:53:51 +0100617 /* otherwise handle queueing */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100618
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100619 list_for_each_entry(tmp, &local->roc_list, list) {
620 if (tmp->chan != channel || tmp->sdata != sdata)
621 continue;
622
623 /*
Johannes Bergaaa016c2015-11-23 23:53:51 +0100624 * Extend this ROC if possible: If it hasn't started, add
625 * just after the new one to combine.
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100626 */
627 if (!tmp->started) {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100628 list_add(&roc->list, &tmp->list);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100629 queued = true;
630 break;
631 }
632
Johannes Bergaaa016c2015-11-23 23:53:51 +0100633 if (!combine_started)
634 continue;
635
636 if (!local->ops->remain_on_channel) {
637 /* If there's no hardware remain-on-channel, and
638 * doing so won't push us over the maximum r-o-c
639 * we allow, then we can just add the new one to
640 * the list and mark it as having started now.
641 * If it would push over the limit, don't try to
642 * combine with other started ones (that haven't
643 * been running as long) but potentially sort it
644 * with others that had the same fate.
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100645 */
Johannes Bergaaa016c2015-11-23 23:53:51 +0100646 unsigned long now = jiffies;
647 u32 elapsed = jiffies_to_msecs(now - tmp->start_time);
648 struct wiphy *wiphy = local->hw.wiphy;
649 u32 max_roc = wiphy->max_remain_on_channel_duration;
650
651 if (elapsed + roc->duration > max_roc) {
652 combine_started = false;
653 continue;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100654 }
655
Johannes Bergaaa016c2015-11-23 23:53:51 +0100656 list_add(&roc->list, &tmp->list);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100657 queued = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100658 roc->on_channel = tmp->on_channel;
659 ieee80211_handle_roc_started(roc, now);
Johannes Berge9db4552015-12-08 13:16:41 +0100660 ieee80211_recalc_sw_work(local, now);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100661 break;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100662 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100663
664 queued = ieee80211_coalesce_hw_started_roc(local, roc, tmp);
665 if (queued)
666 break;
667 /* if it wasn't queued, perhaps it can be combined with
668 * another that also couldn't get combined previously,
669 * but no need to check for already started ones, since
670 * that can't work.
671 */
672 combine_started = false;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100673 }
674
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100675 if (!queued)
676 list_add_tail(&roc->list, &local->roc_list);
677
678 return 0;
679}
680
681int ieee80211_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
682 struct ieee80211_channel *chan,
683 unsigned int duration, u64 *cookie)
684{
685 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
686 struct ieee80211_local *local = sdata->local;
687 int ret;
688
689 mutex_lock(&local->mtx);
690 ret = ieee80211_start_roc_work(local, sdata, chan,
691 duration, cookie, NULL,
692 IEEE80211_ROC_TYPE_NORMAL);
693 mutex_unlock(&local->mtx);
694
695 return ret;
696}
697
698static int ieee80211_cancel_roc(struct ieee80211_local *local,
699 u64 cookie, bool mgmt_tx)
700{
701 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
702 int ret;
703
Johannes Berg7d37fcd2015-12-01 23:15:26 +0100704 if (!cookie)
705 return -ENOENT;
706
Avraham Stern6e46d8c2017-08-18 15:33:57 +0300707 flush_work(&local->hw_roc_start);
708
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100709 mutex_lock(&local->mtx);
710 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100711 if (!mgmt_tx && roc->cookie != cookie)
712 continue;
713 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
714 continue;
715
716 found = roc;
717 break;
718 }
719
720 if (!found) {
721 mutex_unlock(&local->mtx);
722 return -ENOENT;
723 }
724
Johannes Bergaaa016c2015-11-23 23:53:51 +0100725 if (!found->started) {
726 ieee80211_roc_notify_destroy(found);
727 goto out_unlock;
728 }
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100729
730 if (local->ops->remain_on_channel) {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100731 ret = drv_cancel_remain_on_channel(local);
732 if (WARN_ON_ONCE(ret)) {
733 mutex_unlock(&local->mtx);
734 return ret;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100735 }
736
Johannes Bergaaa016c2015-11-23 23:53:51 +0100737 /* TODO:
738 * if multiple items were combined here then we really shouldn't
739 * cancel them all - we should wait for as much time as needed
740 * for the longest remaining one, and only then cancel ...
741 */
742 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
743 if (!roc->started)
744 break;
745 if (roc == found)
746 found = NULL;
747 ieee80211_roc_notify_destroy(roc);
748 }
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100749
Johannes Bergaaa016c2015-11-23 23:53:51 +0100750 /* that really must not happen - it was started */
751 WARN_ON(found);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100752
Johannes Bergaaa016c2015-11-23 23:53:51 +0100753 ieee80211_start_next_roc(local);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100754 } else {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100755 /* go through work struct to return to the operating channel */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100756 found->abort = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100757 mod_delayed_work(local->workqueue, &local->roc_work, 0);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100758 }
759
Johannes Bergaaa016c2015-11-23 23:53:51 +0100760 out_unlock:
761 mutex_unlock(&local->mtx);
762
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100763 return 0;
764}
765
766int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
767 struct wireless_dev *wdev, u64 cookie)
768{
769 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
770 struct ieee80211_local *local = sdata->local;
771
772 return ieee80211_cancel_roc(local, cookie, false);
773}
774
775int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
776 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
777{
778 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
779 struct ieee80211_local *local = sdata->local;
Johannes Berg5ee00db2015-11-24 14:25:49 +0100780 struct sk_buff *skb;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100781 struct sta_info *sta;
782 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
783 bool need_offchan = false;
784 u32 flags;
785 int ret;
786 u8 *data;
787
788 if (params->dont_wait_for_ack)
789 flags = IEEE80211_TX_CTL_NO_ACK;
790 else
791 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
792 IEEE80211_TX_CTL_REQ_TX_STATUS;
793
794 if (params->no_cck)
795 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
796
797 switch (sdata->vif.type) {
798 case NL80211_IFTYPE_ADHOC:
799 if (!sdata->vif.bss_conf.ibss_joined)
800 need_offchan = true;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100801#ifdef CONFIG_MAC80211_MESH
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500802 /* fall through */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100803 case NL80211_IFTYPE_MESH_POINT:
804 if (ieee80211_vif_is_mesh(&sdata->vif) &&
805 !sdata->u.mesh.mesh_id_len)
806 need_offchan = true;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100807#endif
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500808 /* fall through */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100809 case NL80211_IFTYPE_AP:
810 case NL80211_IFTYPE_AP_VLAN:
811 case NL80211_IFTYPE_P2P_GO:
812 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
813 !ieee80211_vif_is_mesh(&sdata->vif) &&
814 !rcu_access_pointer(sdata->bss->beacon))
815 need_offchan = true;
816 if (!ieee80211_is_action(mgmt->frame_control) ||
817 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
818 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
819 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
820 break;
821 rcu_read_lock();
Michael Braun1d4de2e2016-10-03 13:14:15 +0200822 sta = sta_info_get_bss(sdata, mgmt->da);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100823 rcu_read_unlock();
824 if (!sta)
825 return -ENOLINK;
826 break;
827 case NL80211_IFTYPE_STATION:
828 case NL80211_IFTYPE_P2P_CLIENT:
829 sdata_lock(sdata);
830 if (!sdata->u.mgd.associated ||
831 (params->offchan && params->wait &&
832 local->ops->remain_on_channel &&
833 memcmp(sdata->u.mgd.associated->bssid,
834 mgmt->bssid, ETH_ALEN)))
835 need_offchan = true;
836 sdata_unlock(sdata);
837 break;
838 case NL80211_IFTYPE_P2P_DEVICE:
839 need_offchan = true;
840 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300841 case NL80211_IFTYPE_NAN:
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100842 default:
843 return -EOPNOTSUPP;
844 }
845
846 /* configurations requiring offchan cannot work if no channel has been
847 * specified
848 */
849 if (need_offchan && !params->chan)
850 return -EINVAL;
851
852 mutex_lock(&local->mtx);
853
854 /* Check if the operating channel is the requested channel */
855 if (!need_offchan) {
856 struct ieee80211_chanctx_conf *chanctx_conf;
857
858 rcu_read_lock();
859 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
860
861 if (chanctx_conf) {
862 need_offchan = params->chan &&
863 (params->chan !=
864 chanctx_conf->def.chan);
865 } else if (!params->chan) {
866 ret = -EINVAL;
867 rcu_read_unlock();
868 goto out_unlock;
869 } else {
870 need_offchan = true;
871 }
872 rcu_read_unlock();
873 }
874
875 if (need_offchan && !params->offchan) {
876 ret = -EBUSY;
877 goto out_unlock;
878 }
879
880 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
881 if (!skb) {
882 ret = -ENOMEM;
883 goto out_unlock;
884 }
885 skb_reserve(skb, local->hw.extra_tx_headroom);
886
Johannes Berg59ae1d12017-06-16 14:29:20 +0200887 data = skb_put_data(skb, params->buf, params->len);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100888
889 /* Update CSA counters */
890 if (sdata->vif.csa_active &&
891 (sdata->vif.type == NL80211_IFTYPE_AP ||
892 sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
893 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
894 params->n_csa_offsets) {
895 int i;
896 struct beacon_data *beacon = NULL;
897
898 rcu_read_lock();
899
900 if (sdata->vif.type == NL80211_IFTYPE_AP)
901 beacon = rcu_dereference(sdata->u.ap.beacon);
902 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
903 beacon = rcu_dereference(sdata->u.ibss.presp);
904 else if (ieee80211_vif_is_mesh(&sdata->vif))
905 beacon = rcu_dereference(sdata->u.mesh.beacon);
906
907 if (beacon)
908 for (i = 0; i < params->n_csa_offsets; i++)
909 data[params->csa_offsets[i]] =
910 beacon->csa_current_counter;
911
912 rcu_read_unlock();
913 }
914
915 IEEE80211_SKB_CB(skb)->flags = flags;
916
917 skb->dev = sdata->dev;
918
919 if (!params->dont_wait_for_ack) {
920 /* make a copy to preserve the frame contents
921 * in case of encryption.
922 */
Johannes Berg5ee00db2015-11-24 14:25:49 +0100923 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_KERNEL);
924 if (ret) {
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100925 kfree_skb(skb);
926 goto out_unlock;
927 }
928 } else {
929 /* Assign a dummy non-zero cookie, it's not sent to
930 * userspace in this case but we rely on its value
931 * internally in the need_offchan case to distinguish
932 * mgmt-tx from remain-on-channel.
933 */
934 *cookie = 0xffffffff;
935 }
936
937 if (!need_offchan) {
938 ieee80211_tx_skb(sdata, skb);
939 ret = 0;
940 goto out_unlock;
941 }
942
943 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
944 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
945 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
946 IEEE80211_SKB_CB(skb)->hw_queue =
947 local->hw.offchannel_tx_hw_queue;
948
949 /* This will handle all kinds of coalescing and immediate TX */
950 ret = ieee80211_start_roc_work(local, sdata, params->chan,
951 params->wait, cookie, skb,
952 IEEE80211_ROC_TYPE_MGMT_TX);
953 if (ret)
954 ieee80211_free_txskb(&local->hw, skb);
955 out_unlock:
956 mutex_unlock(&local->mtx);
957 return ret;
958}
959
960int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
961 struct wireless_dev *wdev, u64 cookie)
962{
963 struct ieee80211_local *local = wiphy_priv(wiphy);
964
965 return ieee80211_cancel_roc(local, cookie, true);
966}
967
Johannes Berg2eb278e2012-06-05 14:28:42 +0200968void ieee80211_roc_setup(struct ieee80211_local *local)
Johannes Berg21f83582010-12-18 17:20:47 +0100969{
970 INIT_WORK(&local->hw_roc_start, ieee80211_hw_roc_start);
971 INIT_WORK(&local->hw_roc_done, ieee80211_hw_roc_done);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100972 INIT_DELAYED_WORK(&local->roc_work, ieee80211_roc_work);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200973 INIT_LIST_HEAD(&local->roc_list);
974}
975
Johannes Bergc8f994e2013-03-27 22:49:19 +0100976void ieee80211_roc_purge(struct ieee80211_local *local,
977 struct ieee80211_sub_if_data *sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +0200978{
Johannes Berg2eb278e2012-06-05 14:28:42 +0200979 struct ieee80211_roc_work *roc, *tmp;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100980 bool work_to_do = false;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200981
982 mutex_lock(&local->mtx);
983 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Bergc8f994e2013-03-27 22:49:19 +0100984 if (sdata && roc->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +0200985 continue;
986
Johannes Bergaaa016c2015-11-23 23:53:51 +0100987 if (roc->started) {
988 if (local->ops->remain_on_channel) {
989 /* can race, so ignore return value */
990 drv_cancel_remain_on_channel(local);
991 ieee80211_roc_notify_destroy(roc);
992 } else {
993 roc->abort = true;
994 work_to_do = true;
995 }
Johannes Berg2eb278e2012-06-05 14:28:42 +0200996 } else {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100997 ieee80211_roc_notify_destroy(roc);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200998 }
999 }
Johannes Bergaaa016c2015-11-23 23:53:51 +01001000 if (work_to_do)
1001 __ieee80211_roc_work(local);
1002 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01001003}