blob: 60ef8972b254a6a96a607821a4c64cfff756cb6a [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);
James Prestwoodddb754a2019-06-12 12:35:10 -0700202 else
203 cfg80211_tx_mgmt_expired(&roc->sdata->wdev,
204 roc->mgmt_tx_cookie,
205 roc->chan, GFP_KERNEL);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100206
207 list_del(&roc->list);
208 kfree(roc);
209}
210
211static unsigned long ieee80211_end_finished_rocs(struct ieee80211_local *local,
212 unsigned long now)
213{
214 struct ieee80211_roc_work *roc, *tmp;
215 long remaining_dur_min = LONG_MAX;
216
217 lockdep_assert_held(&local->mtx);
218
219 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
220 long remaining;
221
222 if (!roc->started)
223 break;
224
225 remaining = roc->start_time +
226 msecs_to_jiffies(roc->duration) -
227 now;
228
Ilan Peer1b894522015-12-06 21:19:15 +0200229 /* In case of HW ROC, it is possible that the HW finished the
230 * ROC session before the actual requested time. In such a case
231 * end the ROC session (disregarding the remaining time).
232 */
233 if (roc->abort || roc->hw_begun || remaining <= 0)
Johannes Bergaaa016c2015-11-23 23:53:51 +0100234 ieee80211_roc_notify_destroy(roc);
235 else
236 remaining_dur_min = min(remaining_dur_min, remaining);
237 }
238
239 return remaining_dur_min;
240}
241
242static bool ieee80211_recalc_sw_work(struct ieee80211_local *local,
243 unsigned long now)
244{
245 long dur = ieee80211_end_finished_rocs(local, now);
246
247 if (dur == LONG_MAX)
248 return false;
249
250 mod_delayed_work(local->workqueue, &local->roc_work, dur);
251 return true;
252}
253
254static void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc,
255 unsigned long start_time)
256{
Johannes Bergaaa016c2015-11-23 23:53:51 +0100257 if (WARN_ON(roc->notified))
Johannes Berg2eb278e2012-06-05 14:28:42 +0200258 return;
259
Johannes Bergaaa016c2015-11-23 23:53:51 +0100260 roc->start_time = start_time;
261 roc->started = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100262
Johannes Berg2eb278e2012-06-05 14:28:42 +0200263 if (roc->mgmt_tx_cookie) {
264 if (!WARN_ON(!roc->frame)) {
Johannes Berg55de9082012-07-26 17:24:39 +0200265 ieee80211_tx_skb_tid_band(roc->sdata, roc->frame, 7,
Johannes Bergb9771d42018-05-28 15:47:41 +0200266 roc->chan->band, 0);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200267 roc->frame = NULL;
268 }
269 } else {
Johannes Berg50febf62012-10-26 16:13:06 +0200270 cfg80211_ready_on_channel(&roc->sdata->wdev, roc->cookie,
Johannes Berg42d97a52012-11-08 18:31:02 +0100271 roc->chan, roc->req_duration,
272 GFP_KERNEL);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200273 }
274
275 roc->notified = true;
276}
277
Johannes Berg21f83582010-12-18 17:20:47 +0100278static void ieee80211_hw_roc_start(struct work_struct *work)
279{
280 struct ieee80211_local *local =
281 container_of(work, struct ieee80211_local, hw_roc_start);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100282 struct ieee80211_roc_work *roc;
Johannes Berg21f83582010-12-18 17:20:47 +0100283
284 mutex_lock(&local->mtx);
285
Johannes Bergaaa016c2015-11-23 23:53:51 +0100286 list_for_each_entry(roc, &local->roc_list, list) {
287 if (!roc->started)
288 break;
Johannes Berg21f83582010-12-18 17:20:47 +0100289
Johannes Berge6a8a3a2015-12-08 23:46:33 +0100290 roc->hw_begun = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100291 ieee80211_handle_roc_started(roc, local->hw_roc_start_time);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200292 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100293
Johannes Berg21f83582010-12-18 17:20:47 +0100294 mutex_unlock(&local->mtx);
295}
296
297void ieee80211_ready_on_channel(struct ieee80211_hw *hw)
298{
299 struct ieee80211_local *local = hw_to_local(hw);
300
Johannes Berg2eb278e2012-06-05 14:28:42 +0200301 local->hw_roc_start_time = jiffies;
302
Johannes Berg21f83582010-12-18 17:20:47 +0100303 trace_api_ready_on_channel(local);
304
305 ieee80211_queue_work(hw, &local->hw_roc_start);
306}
307EXPORT_SYMBOL_GPL(ieee80211_ready_on_channel);
308
Johannes Bergaaa016c2015-11-23 23:53:51 +0100309static void _ieee80211_start_next_roc(struct ieee80211_local *local)
Johannes Berg2eb278e2012-06-05 14:28:42 +0200310{
Johannes Bergaaa016c2015-11-23 23:53:51 +0100311 struct ieee80211_roc_work *roc, *tmp;
312 enum ieee80211_roc_type type;
313 u32 min_dur, max_dur;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200314
315 lockdep_assert_held(&local->mtx);
316
Johannes Bergaaa016c2015-11-23 23:53:51 +0100317 if (WARN_ON(list_empty(&local->roc_list)))
Johannes Berg2eb278e2012-06-05 14:28:42 +0200318 return;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200319
320 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
321 list);
322
Johannes Bergaaa016c2015-11-23 23:53:51 +0100323 if (WARN_ON(roc->started))
Johannes Berg0f6b3f52012-06-20 20:11:33 +0200324 return;
325
Johannes Bergaaa016c2015-11-23 23:53:51 +0100326 min_dur = roc->duration;
327 max_dur = roc->duration;
328 type = roc->type;
329
330 list_for_each_entry(tmp, &local->roc_list, list) {
331 if (tmp == roc)
332 continue;
333 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
334 break;
335 max_dur = max(tmp->duration, max_dur);
336 min_dur = min(tmp->duration, min_dur);
337 type = max(tmp->type, type);
338 }
339
Johannes Berg2eb278e2012-06-05 14:28:42 +0200340 if (local->ops->remain_on_channel) {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100341 int ret = drv_remain_on_channel(local, roc->sdata, roc->chan,
342 max_dur, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200343
344 if (ret) {
345 wiphy_warn(local->hw.wiphy,
346 "failed to start next HW ROC (%d)\n", ret);
347 /*
348 * queue the work struct again to avoid recursion
349 * when multiple failures occur
350 */
Johannes Bergaaa016c2015-11-23 23:53:51 +0100351 list_for_each_entry(tmp, &local->roc_list, list) {
352 if (tmp->sdata != roc->sdata ||
353 tmp->chan != roc->chan)
354 break;
355 tmp->started = true;
356 tmp->abort = true;
357 }
358 ieee80211_queue_work(&local->hw, &local->hw_roc_done);
359 return;
360 }
361
362 /* we'll notify about the start once the HW calls back */
363 list_for_each_entry(tmp, &local->roc_list, list) {
364 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
365 break;
366 tmp->started = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200367 }
368 } else {
Johannes Bergb4b177a2014-05-14 15:34:41 +0200369 /* If actually operating on the desired channel (with at least
370 * 20 MHz channel width) don't stop all the operations but still
371 * treat it as though the ROC operation started properly, so
372 * other ROC operations won't interfere with this one.
373 */
374 roc->on_channel = roc->chan == local->_oper_chandef.chan &&
375 local->_oper_chandef.width != NL80211_CHAN_WIDTH_5 &&
376 local->_oper_chandef.width != NL80211_CHAN_WIDTH_10;
377
378 /* start this ROC */
Johannes Berg2eb278e2012-06-05 14:28:42 +0200379 ieee80211_recalc_idle(local);
380
Johannes Bergb4b177a2014-05-14 15:34:41 +0200381 if (!roc->on_channel) {
382 ieee80211_offchannel_stop_vifs(local);
383
384 local->tmp_channel = roc->chan;
385 ieee80211_hw_config(local, 0);
386 }
Johannes Berg2eb278e2012-06-05 14:28:42 +0200387
Johannes Bergaaa016c2015-11-23 23:53:51 +0100388 ieee80211_queue_delayed_work(&local->hw, &local->roc_work,
389 msecs_to_jiffies(min_dur));
Johannes Berg2eb278e2012-06-05 14:28:42 +0200390
Johannes Bergaaa016c2015-11-23 23:53:51 +0100391 /* tell userspace or send frame(s) */
392 list_for_each_entry(tmp, &local->roc_list, list) {
393 if (tmp->sdata != roc->sdata || tmp->chan != roc->chan)
394 break;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200395
Johannes Bergaaa016c2015-11-23 23:53:51 +0100396 tmp->on_channel = roc->on_channel;
397 ieee80211_handle_roc_started(tmp, jiffies);
398 }
399 }
400}
401
402void ieee80211_start_next_roc(struct ieee80211_local *local)
403{
404 struct ieee80211_roc_work *roc;
405
406 lockdep_assert_held(&local->mtx);
407
408 if (list_empty(&local->roc_list)) {
409 ieee80211_run_deferred_scan(local);
410 return;
411 }
412
Eliad Peller470f4d62015-12-14 16:26:57 +0200413 /* defer roc if driver is not started (i.e. during reconfig) */
414 if (local->in_reconfig)
415 return;
416
Johannes Bergaaa016c2015-11-23 23:53:51 +0100417 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
418 list);
419
420 if (WARN_ON_ONCE(roc->started))
421 return;
422
423 if (local->ops->remain_on_channel) {
424 _ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200425 } else {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100426 /* delay it a bit */
427 ieee80211_queue_delayed_work(&local->hw, &local->roc_work,
428 round_jiffies_relative(HZ/2));
429 }
430}
Johannes Berg2eb278e2012-06-05 14:28:42 +0200431
Johannes Bergaaa016c2015-11-23 23:53:51 +0100432static void __ieee80211_roc_work(struct ieee80211_local *local)
433{
434 struct ieee80211_roc_work *roc;
435 bool on_channel;
436
437 lockdep_assert_held(&local->mtx);
438
439 if (WARN_ON(local->ops->remain_on_channel))
440 return;
441
442 roc = list_first_entry_or_null(&local->roc_list,
443 struct ieee80211_roc_work, list);
444 if (!roc)
445 return;
446
447 if (!roc->started) {
448 WARN_ON(local->use_chanctx);
449 _ieee80211_start_next_roc(local);
450 } else {
451 on_channel = roc->on_channel;
452 if (ieee80211_recalc_sw_work(local, jiffies))
453 return;
454
455 /* careful - roc pointer became invalid during recalc */
456
457 if (!on_channel) {
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +0200458 ieee80211_flush_queues(local, NULL, false);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200459
460 local->tmp_channel = NULL;
461 ieee80211_hw_config(local, 0);
462
Stanislaw Gruszkaaacde9e2012-12-20 14:41:18 +0100463 ieee80211_offchannel_return(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200464 }
465
466 ieee80211_recalc_idle(local);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100467 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200468 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100469}
Johannes Berg2eb278e2012-06-05 14:28:42 +0200470
Johannes Bergaaa016c2015-11-23 23:53:51 +0100471static void ieee80211_roc_work(struct work_struct *work)
472{
473 struct ieee80211_local *local =
474 container_of(work, struct ieee80211_local, roc_work.work);
475
476 mutex_lock(&local->mtx);
477 __ieee80211_roc_work(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200478 mutex_unlock(&local->mtx);
479}
480
Johannes Berg21f83582010-12-18 17:20:47 +0100481static void ieee80211_hw_roc_done(struct work_struct *work)
482{
483 struct ieee80211_local *local =
484 container_of(work, struct ieee80211_local, hw_roc_done);
485
486 mutex_lock(&local->mtx);
487
Johannes Bergaaa016c2015-11-23 23:53:51 +0100488 ieee80211_end_finished_rocs(local, jiffies);
Johannes Berg71ecfa12012-05-31 15:09:27 +0200489
Johannes Berg2eb278e2012-06-05 14:28:42 +0200490 /* if there's another roc, start it now */
491 ieee80211_start_next_roc(local);
Johannes Berg21f83582010-12-18 17:20:47 +0100492
Johannes Berg21f83582010-12-18 17:20:47 +0100493 mutex_unlock(&local->mtx);
494}
495
496void ieee80211_remain_on_channel_expired(struct ieee80211_hw *hw)
497{
498 struct ieee80211_local *local = hw_to_local(hw);
499
500 trace_api_remain_on_channel_expired(local);
501
502 ieee80211_queue_work(hw, &local->hw_roc_done);
503}
504EXPORT_SYMBOL_GPL(ieee80211_remain_on_channel_expired);
505
Johannes Bergaaa016c2015-11-23 23:53:51 +0100506static bool
507ieee80211_coalesce_hw_started_roc(struct ieee80211_local *local,
508 struct ieee80211_roc_work *new_roc,
509 struct ieee80211_roc_work *cur_roc)
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100510{
511 unsigned long now = jiffies;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100512 unsigned long remaining;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100513
Johannes Bergaaa016c2015-11-23 23:53:51 +0100514 if (WARN_ON(!cur_roc->started))
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100515 return false;
516
Johannes Bergaaa016c2015-11-23 23:53:51 +0100517 /* if it was scheduled in the hardware, but not started yet,
518 * we can only combine if the older one had a longer duration
519 */
520 if (!cur_roc->hw_begun && new_roc->duration > cur_roc->duration)
521 return false;
522
523 remaining = cur_roc->start_time +
524 msecs_to_jiffies(cur_roc->duration) -
525 now;
526
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100527 /* if it doesn't fit entirely, schedule a new one */
528 if (new_roc->duration > jiffies_to_msecs(remaining))
529 return false;
530
Johannes Bergaaa016c2015-11-23 23:53:51 +0100531 /* add just after the current one so we combine their finish later */
532 list_add(&new_roc->list, &cur_roc->list);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100533
Johannes Bergaaa016c2015-11-23 23:53:51 +0100534 /* if the existing one has already begun then let this one also
535 * begin, otherwise they'll both be marked properly by the work
536 * struct that runs once the driver notifies us of the beginning
537 */
Johannes Berge6a8a3a2015-12-08 23:46:33 +0100538 if (cur_roc->hw_begun) {
539 new_roc->hw_begun = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100540 ieee80211_handle_roc_started(new_roc, now);
Johannes Berge6a8a3a2015-12-08 23:46:33 +0100541 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100542
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100543 return true;
544}
545
546static int ieee80211_start_roc_work(struct ieee80211_local *local,
547 struct ieee80211_sub_if_data *sdata,
548 struct ieee80211_channel *channel,
549 unsigned int duration, u64 *cookie,
550 struct sk_buff *txskb,
551 enum ieee80211_roc_type type)
552{
553 struct ieee80211_roc_work *roc, *tmp;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100554 bool queued = false, combine_started = true;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100555 int ret;
556
557 lockdep_assert_held(&local->mtx);
558
559 if (local->use_chanctx && !local->ops->remain_on_channel)
560 return -EOPNOTSUPP;
561
562 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
563 if (!roc)
564 return -ENOMEM;
565
566 /*
567 * If the duration is zero, then the driver
568 * wouldn't actually do anything. Set it to
569 * 10 for now.
570 *
571 * TODO: cancel the off-channel operation
572 * when we get the SKB's TX status and
573 * the wait time was zero before.
574 */
575 if (!duration)
576 duration = 10;
577
578 roc->chan = channel;
579 roc->duration = duration;
580 roc->req_duration = duration;
581 roc->frame = txskb;
582 roc->type = type;
583 roc->sdata = sdata;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100584
585 /*
586 * cookie is either the roc cookie (for normal roc)
587 * or the SKB (for mgmt TX)
588 */
589 if (!txskb) {
590 roc->cookie = ieee80211_mgmt_tx_cookie(local);
591 *cookie = roc->cookie;
592 } else {
593 roc->mgmt_tx_cookie = *cookie;
594 }
595
Johannes Bergaaa016c2015-11-23 23:53:51 +0100596 /* if there's no need to queue, handle it immediately */
597 if (list_empty(&local->roc_list) &&
598 !local->scanning && !ieee80211_is_radar_required(local)) {
599 /* if not HW assist, just queue & schedule work */
600 if (!local->ops->remain_on_channel) {
601 list_add_tail(&roc->list, &local->roc_list);
602 ieee80211_queue_delayed_work(&local->hw,
603 &local->roc_work, 0);
604 } else {
605 /* otherwise actually kick it off here
606 * (for error handling)
607 */
608 ret = drv_remain_on_channel(local, sdata, channel,
609 duration, type);
610 if (ret) {
611 kfree(roc);
612 return ret;
613 }
614 roc->started = true;
615 list_add_tail(&roc->list, &local->roc_list);
616 }
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100617
Johannes Bergaaa016c2015-11-23 23:53:51 +0100618 return 0;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100619 }
620
Johannes Bergaaa016c2015-11-23 23:53:51 +0100621 /* otherwise handle queueing */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100622
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100623 list_for_each_entry(tmp, &local->roc_list, list) {
624 if (tmp->chan != channel || tmp->sdata != sdata)
625 continue;
626
627 /*
Johannes Bergaaa016c2015-11-23 23:53:51 +0100628 * Extend this ROC if possible: If it hasn't started, add
629 * just after the new one to combine.
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100630 */
631 if (!tmp->started) {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100632 list_add(&roc->list, &tmp->list);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100633 queued = true;
634 break;
635 }
636
Johannes Bergaaa016c2015-11-23 23:53:51 +0100637 if (!combine_started)
638 continue;
639
640 if (!local->ops->remain_on_channel) {
641 /* If there's no hardware remain-on-channel, and
642 * doing so won't push us over the maximum r-o-c
643 * we allow, then we can just add the new one to
644 * the list and mark it as having started now.
645 * If it would push over the limit, don't try to
646 * combine with other started ones (that haven't
647 * been running as long) but potentially sort it
648 * with others that had the same fate.
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100649 */
Johannes Bergaaa016c2015-11-23 23:53:51 +0100650 unsigned long now = jiffies;
651 u32 elapsed = jiffies_to_msecs(now - tmp->start_time);
652 struct wiphy *wiphy = local->hw.wiphy;
653 u32 max_roc = wiphy->max_remain_on_channel_duration;
654
655 if (elapsed + roc->duration > max_roc) {
656 combine_started = false;
657 continue;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100658 }
659
Johannes Bergaaa016c2015-11-23 23:53:51 +0100660 list_add(&roc->list, &tmp->list);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100661 queued = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100662 roc->on_channel = tmp->on_channel;
663 ieee80211_handle_roc_started(roc, now);
Johannes Berge9db4552015-12-08 13:16:41 +0100664 ieee80211_recalc_sw_work(local, now);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100665 break;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100666 }
Johannes Bergaaa016c2015-11-23 23:53:51 +0100667
668 queued = ieee80211_coalesce_hw_started_roc(local, roc, tmp);
669 if (queued)
670 break;
671 /* if it wasn't queued, perhaps it can be combined with
672 * another that also couldn't get combined previously,
673 * but no need to check for already started ones, since
674 * that can't work.
675 */
676 combine_started = false;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100677 }
678
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100679 if (!queued)
680 list_add_tail(&roc->list, &local->roc_list);
681
682 return 0;
683}
684
685int ieee80211_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
686 struct ieee80211_channel *chan,
687 unsigned int duration, u64 *cookie)
688{
689 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
690 struct ieee80211_local *local = sdata->local;
691 int ret;
692
693 mutex_lock(&local->mtx);
694 ret = ieee80211_start_roc_work(local, sdata, chan,
695 duration, cookie, NULL,
696 IEEE80211_ROC_TYPE_NORMAL);
697 mutex_unlock(&local->mtx);
698
699 return ret;
700}
701
702static int ieee80211_cancel_roc(struct ieee80211_local *local,
703 u64 cookie, bool mgmt_tx)
704{
705 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
706 int ret;
707
Johannes Berg7d37fcd2015-12-01 23:15:26 +0100708 if (!cookie)
709 return -ENOENT;
710
Avraham Stern6e46d8c2017-08-18 15:33:57 +0300711 flush_work(&local->hw_roc_start);
712
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100713 mutex_lock(&local->mtx);
714 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100715 if (!mgmt_tx && roc->cookie != cookie)
716 continue;
717 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
718 continue;
719
720 found = roc;
721 break;
722 }
723
724 if (!found) {
725 mutex_unlock(&local->mtx);
726 return -ENOENT;
727 }
728
Johannes Bergaaa016c2015-11-23 23:53:51 +0100729 if (!found->started) {
730 ieee80211_roc_notify_destroy(found);
731 goto out_unlock;
732 }
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100733
734 if (local->ops->remain_on_channel) {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100735 ret = drv_cancel_remain_on_channel(local);
736 if (WARN_ON_ONCE(ret)) {
737 mutex_unlock(&local->mtx);
738 return ret;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100739 }
740
Johannes Bergaaa016c2015-11-23 23:53:51 +0100741 /* TODO:
742 * if multiple items were combined here then we really shouldn't
743 * cancel them all - we should wait for as much time as needed
744 * for the longest remaining one, and only then cancel ...
745 */
746 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
747 if (!roc->started)
748 break;
749 if (roc == found)
750 found = NULL;
751 ieee80211_roc_notify_destroy(roc);
752 }
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100753
Johannes Bergaaa016c2015-11-23 23:53:51 +0100754 /* that really must not happen - it was started */
755 WARN_ON(found);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100756
Johannes Bergaaa016c2015-11-23 23:53:51 +0100757 ieee80211_start_next_roc(local);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100758 } else {
Johannes Bergaaa016c2015-11-23 23:53:51 +0100759 /* go through work struct to return to the operating channel */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100760 found->abort = true;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100761 mod_delayed_work(local->workqueue, &local->roc_work, 0);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100762 }
763
Johannes Bergaaa016c2015-11-23 23:53:51 +0100764 out_unlock:
765 mutex_unlock(&local->mtx);
766
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100767 return 0;
768}
769
770int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
771 struct wireless_dev *wdev, u64 cookie)
772{
773 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
774 struct ieee80211_local *local = sdata->local;
775
776 return ieee80211_cancel_roc(local, cookie, false);
777}
778
779int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
780 struct cfg80211_mgmt_tx_params *params, u64 *cookie)
781{
782 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
783 struct ieee80211_local *local = sdata->local;
Johannes Berg5ee00db2015-11-24 14:25:49 +0100784 struct sk_buff *skb;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100785 struct sta_info *sta;
786 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
787 bool need_offchan = false;
788 u32 flags;
789 int ret;
790 u8 *data;
791
792 if (params->dont_wait_for_ack)
793 flags = IEEE80211_TX_CTL_NO_ACK;
794 else
795 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
796 IEEE80211_TX_CTL_REQ_TX_STATUS;
797
798 if (params->no_cck)
799 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
800
801 switch (sdata->vif.type) {
802 case NL80211_IFTYPE_ADHOC:
803 if (!sdata->vif.bss_conf.ibss_joined)
804 need_offchan = true;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100805#ifdef CONFIG_MAC80211_MESH
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500806 /* fall through */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100807 case NL80211_IFTYPE_MESH_POINT:
808 if (ieee80211_vif_is_mesh(&sdata->vif) &&
809 !sdata->u.mesh.mesh_id_len)
810 need_offchan = true;
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100811#endif
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500812 /* fall through */
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100813 case NL80211_IFTYPE_AP:
814 case NL80211_IFTYPE_AP_VLAN:
815 case NL80211_IFTYPE_P2P_GO:
816 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
817 !ieee80211_vif_is_mesh(&sdata->vif) &&
818 !rcu_access_pointer(sdata->bss->beacon))
819 need_offchan = true;
820 if (!ieee80211_is_action(mgmt->frame_control) ||
821 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
822 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
823 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
824 break;
825 rcu_read_lock();
Michael Braun1d4de2e2016-10-03 13:14:15 +0200826 sta = sta_info_get_bss(sdata, mgmt->da);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100827 rcu_read_unlock();
828 if (!sta)
829 return -ENOLINK;
830 break;
831 case NL80211_IFTYPE_STATION:
832 case NL80211_IFTYPE_P2P_CLIENT:
833 sdata_lock(sdata);
834 if (!sdata->u.mgd.associated ||
835 (params->offchan && params->wait &&
836 local->ops->remain_on_channel &&
837 memcmp(sdata->u.mgd.associated->bssid,
838 mgmt->bssid, ETH_ALEN)))
839 need_offchan = true;
840 sdata_unlock(sdata);
841 break;
842 case NL80211_IFTYPE_P2P_DEVICE:
843 need_offchan = true;
844 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300845 case NL80211_IFTYPE_NAN:
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100846 default:
847 return -EOPNOTSUPP;
848 }
849
850 /* configurations requiring offchan cannot work if no channel has been
851 * specified
852 */
853 if (need_offchan && !params->chan)
854 return -EINVAL;
855
856 mutex_lock(&local->mtx);
857
858 /* Check if the operating channel is the requested channel */
859 if (!need_offchan) {
860 struct ieee80211_chanctx_conf *chanctx_conf;
861
862 rcu_read_lock();
863 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
864
865 if (chanctx_conf) {
866 need_offchan = params->chan &&
867 (params->chan !=
868 chanctx_conf->def.chan);
869 } else if (!params->chan) {
870 ret = -EINVAL;
871 rcu_read_unlock();
872 goto out_unlock;
873 } else {
874 need_offchan = true;
875 }
876 rcu_read_unlock();
877 }
878
879 if (need_offchan && !params->offchan) {
880 ret = -EBUSY;
881 goto out_unlock;
882 }
883
884 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
885 if (!skb) {
886 ret = -ENOMEM;
887 goto out_unlock;
888 }
889 skb_reserve(skb, local->hw.extra_tx_headroom);
890
Johannes Berg59ae1d12017-06-16 14:29:20 +0200891 data = skb_put_data(skb, params->buf, params->len);
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100892
893 /* Update CSA counters */
894 if (sdata->vif.csa_active &&
895 (sdata->vif.type == NL80211_IFTYPE_AP ||
896 sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
897 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
898 params->n_csa_offsets) {
899 int i;
900 struct beacon_data *beacon = NULL;
901
902 rcu_read_lock();
903
904 if (sdata->vif.type == NL80211_IFTYPE_AP)
905 beacon = rcu_dereference(sdata->u.ap.beacon);
906 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
907 beacon = rcu_dereference(sdata->u.ibss.presp);
908 else if (ieee80211_vif_is_mesh(&sdata->vif))
909 beacon = rcu_dereference(sdata->u.mesh.beacon);
910
911 if (beacon)
912 for (i = 0; i < params->n_csa_offsets; i++)
913 data[params->csa_offsets[i]] =
914 beacon->csa_current_counter;
915
916 rcu_read_unlock();
917 }
918
919 IEEE80211_SKB_CB(skb)->flags = flags;
920
921 skb->dev = sdata->dev;
922
923 if (!params->dont_wait_for_ack) {
924 /* make a copy to preserve the frame contents
925 * in case of encryption.
926 */
Johannes Berg5ee00db2015-11-24 14:25:49 +0100927 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_KERNEL);
928 if (ret) {
Johannes Berga2fcfccb2015-11-23 17:18:35 +0100929 kfree_skb(skb);
930 goto out_unlock;
931 }
932 } else {
933 /* Assign a dummy non-zero cookie, it's not sent to
934 * userspace in this case but we rely on its value
935 * internally in the need_offchan case to distinguish
936 * mgmt-tx from remain-on-channel.
937 */
938 *cookie = 0xffffffff;
939 }
940
941 if (!need_offchan) {
942 ieee80211_tx_skb(sdata, skb);
943 ret = 0;
944 goto out_unlock;
945 }
946
947 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
948 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
949 if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
950 IEEE80211_SKB_CB(skb)->hw_queue =
951 local->hw.offchannel_tx_hw_queue;
952
953 /* This will handle all kinds of coalescing and immediate TX */
954 ret = ieee80211_start_roc_work(local, sdata, params->chan,
955 params->wait, cookie, skb,
956 IEEE80211_ROC_TYPE_MGMT_TX);
957 if (ret)
958 ieee80211_free_txskb(&local->hw, skb);
959 out_unlock:
960 mutex_unlock(&local->mtx);
961 return ret;
962}
963
964int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
965 struct wireless_dev *wdev, u64 cookie)
966{
967 struct ieee80211_local *local = wiphy_priv(wiphy);
968
969 return ieee80211_cancel_roc(local, cookie, true);
970}
971
Johannes Berg2eb278e2012-06-05 14:28:42 +0200972void ieee80211_roc_setup(struct ieee80211_local *local)
Johannes Berg21f83582010-12-18 17:20:47 +0100973{
974 INIT_WORK(&local->hw_roc_start, ieee80211_hw_roc_start);
975 INIT_WORK(&local->hw_roc_done, ieee80211_hw_roc_done);
Johannes Bergaaa016c2015-11-23 23:53:51 +0100976 INIT_DELAYED_WORK(&local->roc_work, ieee80211_roc_work);
Johannes Berg2eb278e2012-06-05 14:28:42 +0200977 INIT_LIST_HEAD(&local->roc_list);
978}
979
Johannes Bergc8f994e2013-03-27 22:49:19 +0100980void ieee80211_roc_purge(struct ieee80211_local *local,
981 struct ieee80211_sub_if_data *sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +0200982{
Johannes Berg2eb278e2012-06-05 14:28:42 +0200983 struct ieee80211_roc_work *roc, *tmp;
Johannes Bergaaa016c2015-11-23 23:53:51 +0100984 bool work_to_do = false;
Johannes Berg2eb278e2012-06-05 14:28:42 +0200985
986 mutex_lock(&local->mtx);
987 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Bergc8f994e2013-03-27 22:49:19 +0100988 if (sdata && roc->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +0200989 continue;
990
Johannes Bergaaa016c2015-11-23 23:53:51 +0100991 if (roc->started) {
992 if (local->ops->remain_on_channel) {
993 /* can race, so ignore return value */
994 drv_cancel_remain_on_channel(local);
995 ieee80211_roc_notify_destroy(roc);
996 } else {
997 roc->abort = true;
998 work_to_do = true;
999 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02001000 } else {
Johannes Bergaaa016c2015-11-23 23:53:51 +01001001 ieee80211_roc_notify_destroy(roc);
Johannes Berg2eb278e2012-06-05 14:28:42 +02001002 }
1003 }
Johannes Bergaaa016c2015-11-23 23:53:51 +01001004 if (work_to_do)
1005 __ieee80211_roc_work(local);
1006 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01001007}