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 | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 18 | #include "driver-trace.h" |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 19 | #include "driver-ops.h" |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 20 | |
| 21 | /* |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 22 | * Tell our hardware to disable PS. |
| 23 | * Optionally inform AP that we will go to sleep so that it will buffer |
| 24 | * the frames while we are doing off-channel work. This is optional |
| 25 | * because we *may* be doing work on-operating channel, and want our |
| 26 | * hardware unconditionally awake, but still let the AP send us normal frames. |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 27 | */ |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 28 | static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata, |
| 29 | bool tell_ap) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 30 | { |
| 31 | struct ieee80211_local *local = sdata->local; |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 32 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 33 | |
| 34 | local->offchannel_ps_enabled = false; |
| 35 | |
| 36 | /* FIXME: what to do when local->pspolling is true? */ |
| 37 | |
| 38 | del_timer_sync(&local->dynamic_ps_timer); |
Luis R. Rodriguez | 3bc3c0d | 2010-09-16 15:12:33 -0400 | [diff] [blame] | 39 | del_timer_sync(&ifmgd->bcn_mon_timer); |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 40 | del_timer_sync(&ifmgd->conn_mon_timer); |
| 41 | |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 42 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 43 | |
| 44 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 45 | local->offchannel_ps_enabled = true; |
| 46 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 47 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 48 | } |
| 49 | |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 50 | if (tell_ap && (!local->offchannel_ps_enabled || |
| 51 | !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK))) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 52 | /* |
| 53 | * If power save was enabled, no need to send a nullfunc |
| 54 | * frame because AP knows that we are sleeping. But if the |
| 55 | * hardware is creating the nullfunc frame for power save |
| 56 | * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not |
| 57 | * enabled) and power save was enabled, the firmware just |
| 58 | * sent a null frame with power save disabled. So we need |
| 59 | * to send a new nullfunc frame to inform the AP that we |
| 60 | * are again sleeping. |
| 61 | */ |
| 62 | ieee80211_send_nullfunc(local, sdata, 1); |
| 63 | } |
| 64 | |
| 65 | /* inform AP that we are awake again, unless power save is enabled */ |
| 66 | static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata) |
| 67 | { |
| 68 | struct ieee80211_local *local = sdata->local; |
| 69 | |
| 70 | if (!local->ps_sdata) |
| 71 | ieee80211_send_nullfunc(local, sdata, 0); |
| 72 | else if (local->offchannel_ps_enabled) { |
| 73 | /* |
| 74 | * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware |
| 75 | * will send a nullfunc frame with the powersave bit set |
| 76 | * even though the AP already knows that we are sleeping. |
| 77 | * This could be avoided by sending a null frame with power |
| 78 | * save bit disabled before enabling the power save, but |
| 79 | * this doesn't gain anything. |
| 80 | * |
| 81 | * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need |
| 82 | * to send a nullfunc frame because AP already knows that |
| 83 | * we are sleeping, let's just enable power save mode in |
| 84 | * hardware. |
| 85 | */ |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 86 | /* TODO: Only set hardware if CONF_PS changed? |
| 87 | * TODO: Should we set offchannel_ps_enabled to false? |
| 88 | */ |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 89 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 90 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 91 | } else if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 92 | /* |
| 93 | * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer |
| 94 | * had been running before leaving the operating channel, |
| 95 | * restart the timer now and send a nullfunc frame to inform |
| 96 | * the AP that we are awake. |
| 97 | */ |
| 98 | ieee80211_send_nullfunc(local, sdata, 0); |
| 99 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 100 | msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); |
| 101 | } |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 102 | |
Luis R. Rodriguez | 3bc3c0d | 2010-09-16 15:12:33 -0400 | [diff] [blame] | 103 | ieee80211_sta_reset_beacon_monitor(sdata); |
Luis R. Rodriguez | 4730d59 | 2010-09-16 15:12:31 -0400 | [diff] [blame] | 104 | ieee80211_sta_reset_conn_monitor(sdata); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 107 | void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local, |
| 108 | bool offchannel_ps_enable) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 109 | { |
| 110 | struct ieee80211_sub_if_data *sdata; |
| 111 | |
| 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 | */ |
| 116 | mutex_lock(&local->iflist_mtx); |
| 117 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 118 | if (!ieee80211_sdata_running(sdata)) |
| 119 | continue; |
| 120 | |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 121 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
Johannes Berg | 5b714c6 | 2010-08-27 13:45:28 +0200 | [diff] [blame] | 122 | set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state); |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 123 | |
| 124 | /* Check to see if we should disable beaconing. */ |
| 125 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 126 | sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 127 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
| 128 | ieee80211_bss_info_change_notify( |
| 129 | sdata, BSS_CHANGED_BEACON_ENABLED); |
| 130 | |
| 131 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) { |
John W. Linville | cfa6cb2 | 2010-01-06 17:22:54 -0500 | [diff] [blame] | 132 | netif_tx_stop_all_queues(sdata->dev); |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 133 | if (offchannel_ps_enable && |
| 134 | (sdata->vif.type == NL80211_IFTYPE_STATION) && |
| 135 | sdata->u.mgd.associated) |
| 136 | ieee80211_offchannel_ps_enable(sdata, true); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | mutex_unlock(&local->iflist_mtx); |
| 140 | } |
| 141 | |
| 142 | void ieee80211_offchannel_return(struct ieee80211_local *local, |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 143 | bool offchannel_ps_disable) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 144 | { |
| 145 | struct ieee80211_sub_if_data *sdata; |
| 146 | |
| 147 | mutex_lock(&local->iflist_mtx); |
| 148 | list_for_each_entry(sdata, &local->interfaces, list) { |
Eliad Peller | f6e8cb7 | 2011-12-23 01:48:06 +0200 | [diff] [blame] | 149 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
| 150 | clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state); |
| 151 | |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 152 | if (!ieee80211_sdata_running(sdata)) |
| 153 | continue; |
| 154 | |
| 155 | /* Tell AP we're back */ |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 156 | if (offchannel_ps_disable && |
| 157 | sdata->vif.type == NL80211_IFTYPE_STATION) { |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 158 | if (sdata->u.mgd.associated) |
| 159 | ieee80211_offchannel_ps_disable(sdata); |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Johannes Berg | 5b714c6 | 2010-08-27 13:45:28 +0200 | [diff] [blame] | 162 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 5b714c6 | 2010-08-27 13:45:28 +0200 | [diff] [blame] | 163 | /* |
| 164 | * This may wake up queues even though the driver |
| 165 | * currently has them stopped. This is not very |
| 166 | * likely, since the driver won't have gotten any |
| 167 | * (or hardly any) new packets while we weren't |
| 168 | * on the right channel, and even if it happens |
| 169 | * it will at most lead to queueing up one more |
| 170 | * packet per queue in mac80211 rather than on |
| 171 | * the interface qdisc. |
| 172 | */ |
Benoit Papillault | 9389575 | 2010-01-14 23:20:31 +0100 | [diff] [blame] | 173 | netif_tx_wake_all_queues(sdata->dev); |
Johannes Berg | 5b714c6 | 2010-08-27 13:45:28 +0200 | [diff] [blame] | 174 | } |
Benoit Papillault | 9389575 | 2010-01-14 23:20:31 +0100 | [diff] [blame] | 175 | |
Johannes Berg | e76aadc | 2011-11-29 10:20:02 +0100 | [diff] [blame] | 176 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 177 | sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 178 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
Jouni Malinen | b203ffc | 2009-12-23 13:15:40 +0100 | [diff] [blame] | 179 | ieee80211_bss_info_change_notify( |
| 180 | sdata, BSS_CHANGED_BEACON_ENABLED); |
| 181 | } |
| 182 | mutex_unlock(&local->iflist_mtx); |
| 183 | } |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 184 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 185 | void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc) |
| 186 | { |
| 187 | if (roc->notified) |
| 188 | return; |
| 189 | |
| 190 | if (roc->mgmt_tx_cookie) { |
| 191 | if (!WARN_ON(!roc->frame)) { |
| 192 | ieee80211_tx_skb(roc->sdata, roc->frame); |
| 193 | roc->frame = NULL; |
| 194 | } |
| 195 | } else { |
| 196 | cfg80211_ready_on_channel(roc->sdata->dev, (unsigned long)roc, |
| 197 | roc->chan, roc->chan_type, |
| 198 | roc->req_duration, GFP_KERNEL); |
| 199 | } |
| 200 | |
| 201 | roc->notified = true; |
| 202 | } |
| 203 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 204 | static void ieee80211_hw_roc_start(struct work_struct *work) |
| 205 | { |
| 206 | struct ieee80211_local *local = |
| 207 | container_of(work, struct ieee80211_local, hw_roc_start); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 208 | struct ieee80211_roc_work *roc, *dep, *tmp; |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 209 | |
| 210 | mutex_lock(&local->mtx); |
| 211 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 212 | if (list_empty(&local->roc_list)) |
| 213 | goto out_unlock; |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 214 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 215 | roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work, |
| 216 | list); |
Johannes Berg | 90fc4b3 | 2010-12-18 17:20:48 +0100 | [diff] [blame] | 217 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 218 | if (!roc->started) |
| 219 | goto out_unlock; |
| 220 | |
| 221 | roc->hw_begun = true; |
| 222 | roc->hw_start_time = local->hw_roc_start_time; |
| 223 | |
| 224 | ieee80211_handle_roc_started(roc); |
| 225 | list_for_each_entry_safe(dep, tmp, &roc->dependents, list) { |
| 226 | ieee80211_handle_roc_started(dep); |
| 227 | |
| 228 | if (dep->duration > roc->duration) { |
| 229 | u32 dur = dep->duration; |
| 230 | dep->duration = dur - roc->duration; |
| 231 | roc->duration = dur; |
| 232 | list_del(&dep->list); |
| 233 | list_add(&dep->list, &roc->list); |
| 234 | } |
| 235 | } |
| 236 | out_unlock: |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 237 | mutex_unlock(&local->mtx); |
| 238 | } |
| 239 | |
| 240 | void ieee80211_ready_on_channel(struct ieee80211_hw *hw) |
| 241 | { |
| 242 | struct ieee80211_local *local = hw_to_local(hw); |
| 243 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 244 | local->hw_roc_start_time = jiffies; |
| 245 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 246 | trace_api_ready_on_channel(local); |
| 247 | |
| 248 | ieee80211_queue_work(hw, &local->hw_roc_start); |
| 249 | } |
| 250 | EXPORT_SYMBOL_GPL(ieee80211_ready_on_channel); |
| 251 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 252 | void ieee80211_start_next_roc(struct ieee80211_local *local) |
| 253 | { |
| 254 | struct ieee80211_roc_work *roc; |
| 255 | |
| 256 | lockdep_assert_held(&local->mtx); |
| 257 | |
| 258 | if (list_empty(&local->roc_list)) { |
| 259 | ieee80211_run_deferred_scan(local); |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work, |
| 264 | list); |
| 265 | |
| 266 | if (local->ops->remain_on_channel) { |
| 267 | int ret, duration = roc->duration; |
| 268 | |
| 269 | /* XXX: duplicated, see ieee80211_start_roc_work() */ |
| 270 | if (!duration) |
| 271 | duration = 10; |
| 272 | |
| 273 | ret = drv_remain_on_channel(local, roc->chan, |
| 274 | roc->chan_type, |
| 275 | duration); |
| 276 | |
| 277 | roc->started = true; |
| 278 | |
| 279 | if (ret) { |
| 280 | wiphy_warn(local->hw.wiphy, |
| 281 | "failed to start next HW ROC (%d)\n", ret); |
| 282 | /* |
| 283 | * queue the work struct again to avoid recursion |
| 284 | * when multiple failures occur |
| 285 | */ |
| 286 | ieee80211_remain_on_channel_expired(&local->hw); |
| 287 | } |
| 288 | } else { |
| 289 | /* delay it a bit */ |
| 290 | ieee80211_queue_delayed_work(&local->hw, &roc->work, |
| 291 | round_jiffies_relative(HZ/2)); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc) |
| 296 | { |
| 297 | struct ieee80211_roc_work *dep, *tmp; |
| 298 | |
| 299 | /* was never transmitted */ |
| 300 | if (roc->frame) { |
| 301 | cfg80211_mgmt_tx_status(roc->sdata->dev, |
| 302 | (unsigned long)roc->frame, |
| 303 | roc->frame->data, roc->frame->len, |
| 304 | false, GFP_KERNEL); |
| 305 | kfree_skb(roc->frame); |
| 306 | } |
| 307 | |
| 308 | if (!roc->mgmt_tx_cookie) |
| 309 | cfg80211_remain_on_channel_expired(roc->sdata->dev, |
| 310 | (unsigned long)roc, |
| 311 | roc->chan, roc->chan_type, |
| 312 | GFP_KERNEL); |
| 313 | |
| 314 | list_for_each_entry_safe(dep, tmp, &roc->dependents, list) |
| 315 | ieee80211_roc_notify_destroy(dep); |
| 316 | |
| 317 | kfree(roc); |
| 318 | } |
| 319 | |
| 320 | void ieee80211_sw_roc_work(struct work_struct *work) |
| 321 | { |
| 322 | struct ieee80211_roc_work *roc = |
| 323 | container_of(work, struct ieee80211_roc_work, work.work); |
| 324 | struct ieee80211_sub_if_data *sdata = roc->sdata; |
| 325 | struct ieee80211_local *local = sdata->local; |
| 326 | |
| 327 | mutex_lock(&local->mtx); |
| 328 | |
| 329 | if (roc->abort) |
| 330 | goto finish; |
| 331 | |
| 332 | if (WARN_ON(list_empty(&local->roc_list))) |
| 333 | goto out_unlock; |
| 334 | |
| 335 | if (WARN_ON(roc != list_first_entry(&local->roc_list, |
| 336 | struct ieee80211_roc_work, |
| 337 | list))) |
| 338 | goto out_unlock; |
| 339 | |
| 340 | if (!roc->started) { |
| 341 | struct ieee80211_roc_work *dep; |
| 342 | |
| 343 | /* start this ROC */ |
| 344 | |
| 345 | /* switch channel etc */ |
| 346 | ieee80211_recalc_idle(local); |
| 347 | |
| 348 | local->tmp_channel = roc->chan; |
| 349 | local->tmp_channel_type = roc->chan_type; |
| 350 | ieee80211_hw_config(local, 0); |
| 351 | |
| 352 | /* tell userspace or send frame */ |
| 353 | ieee80211_handle_roc_started(roc); |
| 354 | list_for_each_entry(dep, &roc->dependents, list) |
| 355 | ieee80211_handle_roc_started(dep); |
| 356 | |
| 357 | /* if it was pure TX, just finish right away */ |
| 358 | if (!roc->duration) |
| 359 | goto finish; |
| 360 | |
| 361 | roc->started = true; |
| 362 | ieee80211_queue_delayed_work(&local->hw, &roc->work, |
| 363 | msecs_to_jiffies(roc->duration)); |
| 364 | } else { |
| 365 | /* finish this ROC */ |
| 366 | finish: |
| 367 | list_del(&roc->list); |
| 368 | ieee80211_roc_notify_destroy(roc); |
| 369 | |
| 370 | if (roc->started) { |
| 371 | drv_flush(local, false); |
| 372 | |
| 373 | local->tmp_channel = NULL; |
| 374 | ieee80211_hw_config(local, 0); |
| 375 | |
| 376 | ieee80211_offchannel_return(local, true); |
| 377 | } |
| 378 | |
| 379 | ieee80211_recalc_idle(local); |
| 380 | |
| 381 | ieee80211_start_next_roc(local); |
| 382 | ieee80211_run_deferred_scan(local); |
| 383 | } |
| 384 | |
| 385 | out_unlock: |
| 386 | mutex_unlock(&local->mtx); |
| 387 | } |
| 388 | |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 389 | static void ieee80211_hw_roc_done(struct work_struct *work) |
| 390 | { |
| 391 | struct ieee80211_local *local = |
| 392 | container_of(work, struct ieee80211_local, hw_roc_done); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 393 | struct ieee80211_roc_work *roc; |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 394 | |
| 395 | mutex_lock(&local->mtx); |
| 396 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 397 | if (list_empty(&local->roc_list)) |
| 398 | goto out_unlock; |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 399 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 400 | roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work, |
| 401 | list); |
Johannes Berg | 71ecfa1 | 2012-05-31 15:09:27 +0200 | [diff] [blame] | 402 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 403 | if (!roc->started) |
| 404 | goto out_unlock; |
Johannes Berg | 71ecfa1 | 2012-05-31 15:09:27 +0200 | [diff] [blame] | 405 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 406 | list_del(&roc->list); |
Johannes Berg | 71ecfa1 | 2012-05-31 15:09:27 +0200 | [diff] [blame] | 407 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 408 | ieee80211_roc_notify_destroy(roc); |
Johannes Berg | 71ecfa1 | 2012-05-31 15:09:27 +0200 | [diff] [blame] | 409 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 410 | /* if there's another roc, start it now */ |
| 411 | ieee80211_start_next_roc(local); |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 412 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 413 | /* or scan maybe */ |
| 414 | ieee80211_run_deferred_scan(local); |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 415 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 416 | out_unlock: |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 417 | mutex_unlock(&local->mtx); |
| 418 | } |
| 419 | |
| 420 | void ieee80211_remain_on_channel_expired(struct ieee80211_hw *hw) |
| 421 | { |
| 422 | struct ieee80211_local *local = hw_to_local(hw); |
| 423 | |
| 424 | trace_api_remain_on_channel_expired(local); |
| 425 | |
| 426 | ieee80211_queue_work(hw, &local->hw_roc_done); |
| 427 | } |
| 428 | EXPORT_SYMBOL_GPL(ieee80211_remain_on_channel_expired); |
| 429 | |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 430 | void ieee80211_roc_setup(struct ieee80211_local *local) |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 431 | { |
| 432 | INIT_WORK(&local->hw_roc_start, ieee80211_hw_roc_start); |
| 433 | INIT_WORK(&local->hw_roc_done, ieee80211_hw_roc_done); |
Johannes Berg | 2eb278e | 2012-06-05 14:28:42 +0200 | [diff] [blame^] | 434 | INIT_LIST_HEAD(&local->roc_list); |
| 435 | } |
| 436 | |
| 437 | void ieee80211_roc_purge(struct ieee80211_sub_if_data *sdata) |
| 438 | { |
| 439 | struct ieee80211_local *local = sdata->local; |
| 440 | struct ieee80211_roc_work *roc, *tmp; |
| 441 | LIST_HEAD(tmp_list); |
| 442 | |
| 443 | mutex_lock(&local->mtx); |
| 444 | list_for_each_entry_safe(roc, tmp, &local->roc_list, list) { |
| 445 | if (roc->sdata != sdata) |
| 446 | continue; |
| 447 | |
| 448 | if (roc->started && local->ops->remain_on_channel) { |
| 449 | /* can race, so ignore return value */ |
| 450 | drv_cancel_remain_on_channel(local); |
| 451 | } |
| 452 | |
| 453 | list_move_tail(&roc->list, &tmp_list); |
| 454 | roc->abort = true; |
| 455 | } |
| 456 | |
| 457 | ieee80211_start_next_roc(local); |
| 458 | ieee80211_run_deferred_scan(local); |
| 459 | mutex_unlock(&local->mtx); |
| 460 | |
| 461 | list_for_each_entry_safe(roc, tmp, &tmp_list, list) { |
| 462 | if (local->ops->remain_on_channel) { |
| 463 | list_del(&roc->list); |
| 464 | ieee80211_roc_notify_destroy(roc); |
| 465 | } else { |
| 466 | ieee80211_queue_delayed_work(&local->hw, &roc->work, 0); |
| 467 | |
| 468 | /* work will clean up etc */ |
| 469 | flush_delayed_work(&roc->work); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | WARN_ON_ONCE(!list_empty(&tmp_list)); |
Johannes Berg | 21f8358 | 2010-12-18 17:20:47 +0100 | [diff] [blame] | 474 | } |