ath9k: merge a tx power handling fix
[openwrt.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 commit e138e0ef9560c46ce93dbb22a728a57888e94d1c
2 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
3 Date:   Mon Feb 3 13:31:37 2014 +0530
4
5     ath9k: Fix TX power calculation
6     
7     The commit, "ath9k_hw: Fix incorrect Tx control power in AR9003 template"
8     fixed the incorrect values in the eeprom templates, but if
9     boards have already been calibrated with incorrect values,
10     they would still be using the wrong TX power. Fix this by assigning
11     a default value in such cases.
12     
13     Cc: Rajkumar Manoharan <rmanohar@qti.qualcomm.com>
14     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
15
16 commit b9f268b5b01331c3c82179abca551429450e9417
17 Author: Michal Kazior <michal.kazior@tieto.com>
18 Date:   Wed Jan 29 14:22:27 2014 +0100
19
20     cfg80211: consider existing DFS interfaces
21     
22     It was possible to break interface combinations in
23     the following way:
24     
25      combo 1: iftype = AP, num_ifaces = 2, num_chans = 2,
26      combo 2: iftype = AP, num_ifaces = 1, num_chans = 1, radar = HT20
27     
28     With the above interface combinations it was
29     possible to:
30     
31      step 1. start AP on DFS channel by matching combo 2
32      step 2. start AP on non-DFS channel by matching combo 1
33     
34     This was possible beacuse (step 2) did not consider
35     if other interfaces require radar detection.
36     
37     The patch changes how cfg80211 tracks channels -
38     instead of channel itself now a complete chandef
39     is stored.
40     
41     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
42     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
43
44 commit bc9c62f5f511cc395c62dbf4cdd437f23db53b28
45 Author: Antonio Quartulli <antonio@open-mesh.com>
46 Date:   Wed Jan 29 17:53:43 2014 +0100
47
48     cfg80211: fix channel configuration in IBSS join
49     
50     When receiving an IBSS_JOINED event select the BSS object
51     based on the {bssid, channel} couple rather than the bssid
52     only.
53     With the current approach if another cell having the same
54     BSSID (but using a different channel) exists then cfg80211
55     picks up the wrong BSS object.
56     The result is a mismatching channel configuration between
57     cfg80211 and the driver, that can lead to any sort of
58     problem.
59     
60     The issue can be triggered by having an IBSS sitting on
61     given channel and then asking the driver to create a new
62     cell using the same BSSID but with a different frequency.
63     By passing the channel to cfg80211_get_bss() we can solve
64     this ambiguity and retrieve/create the correct BSS object.
65     All the users of cfg80211_ibss_joined() have been changed
66     accordingly.
67     
68     Moreover WARN when cfg80211_ibss_joined() gets a NULL
69     channel as argument and remove a bogus call of the same
70     function in ath6kl (it does not make sense to call
71     cfg80211_ibss_joined() with a zero BSSID on ibss-leave).
72     
73     Cc: Kalle Valo <kvalo@qca.qualcomm.com>
74     Cc: Arend van Spriel <arend@broadcom.com>
75     Cc: Bing Zhao <bzhao@marvell.com>
76     Cc: Jussi Kivilinna <jussi.kivilinna@iki.fi>
77     Cc: libertas-dev@lists.infradead.org
78     Acked-by: Kalle Valo <kvalo@qca.qualcomm.com>
79     Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
80     [minor code cleanup in ath6kl]
81     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
82
83 commit 7e0c41cb41f215aba2c39b1c237bb4d42ec49a85
84 Author: Johannes Berg <johannes.berg@intel.com>
85 Date:   Fri Jan 24 14:41:44 2014 +0100
86
87     mac80211: fix bufferable MMPDU RX handling
88     
89     Action, disassoc and deauth frames are bufferable, and as such don't
90     have the PM bit in the frame control field reserved which means we
91     need to react to the bit when receiving in such a frame.
92     
93     Fix this by introducing a new helper ieee80211_is_bufferable_mmpdu()
94     and using it for the RX path that currently ignores the PM bit in
95     any non-data frames for doze->wake transitions, but listens to it in
96     all frames for wake->doze transitions, both of which are wrong.
97     
98     Also use the new helper in the TX path to clean up the code.
99     
100     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
101
102 commit fc0df6d2343636e3f48a069330d5b972e3d8659d
103 Author: Janusz Dziedzic <janusz.dziedzic@tieto.com>
104 Date:   Fri Jan 24 14:29:21 2014 +0100
105
106     cfg80211: set preset_chandef after channel switch
107     
108     Set preset_chandef in channel switch notification.
109     In other case we will have old preset_chandef.
110     
111     Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
112     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
113
114 commit cdec895e2344987ff171cece96e25d7407a3ebf6
115 Author: Simon Wunderlich <simon@open-mesh.com>
116 Date:   Fri Jan 24 23:48:29 2014 +0100
117
118     mac80211: send ibss probe responses with noack flag
119     
120     Responding to probe requests for scanning clients will often create
121     excessive retries, as it happens quite often that the scanning client
122     already left the channel. Therefore do it like hostapd and send probe
123     responses for wildcard SSID only once by using the noack flag.
124     
125     Signed-off-by: Simon Wunderlich <simon@open-mesh.com>
126     [fix typo & 'wildcard SSID' in commit log]
127     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
128
129 commit 0b865d1e6b9c05052adae9315df7cb195dc60c3b
130 Author: Luciano Coelho <luciano.coelho@intel.com>
131 Date:   Tue Jan 28 17:09:08 2014 +0200
132
133     mac80211: ibss: remove unnecessary call to release channel
134     
135     The ieee80211_vif_use_channel() function calls
136     ieee80211_vif_release_channel(), so there's no need to call it
137     explicitly in __ieee80211_sta_join_ibss().
138     
139     Signed-off-by: Luciano Coelho <luciano.coelho@intel.com>
140     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
141
142 commit e1b6c17e971f0a51ff86c2dac2584c63cd999cd7
143 Author: Michal Kazior <michal.kazior@tieto.com>
144 Date:   Wed Jan 29 07:56:21 2014 +0100
145
146     mac80211: add missing CSA locking
147     
148     The patch adds a missing sdata lock and adds a few
149     lockdeps for easier maintenance.
150     
151     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
152     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
153
154 commit ad17ba7d14d225b109b73c177cd446afb8050598
155 Author: Michal Kazior <michal.kazior@tieto.com>
156 Date:   Wed Jan 29 07:56:20 2014 +0100
157
158     mac80211: fix sdata->radar_required locking
159     
160     radar_required setting wasn't protected by
161     local->mtx in some places. This should prevent
162     from scanning/radar detection/roc colliding.
163     
164     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
165     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
166
167 commit 5fcd5f1808813a3d9e502fd756e01bee8a79c85d
168 Author: Michal Kazior <michal.kazior@tieto.com>
169 Date:   Wed Jan 29 07:56:19 2014 +0100
170
171     mac80211: move csa_active setting in STA CSA
172     
173     The sdata->vif.csa_active could be left set after,
174     e.g. channel context constraints check fail in STA
175     mode leaving the interface in a strange state for
176     a brief period of time until it is disconnected.
177     This was harmless but ugly.
178     
179     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
180     Reviewed-by: Luciano Coelho <luciano.coelho@intel.com>
181     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
182
183 commit e486da4b7eed71821c6b4c1bb9ac62ffd3ab13e9
184 Author: Michal Kazior <michal.kazior@tieto.com>
185 Date:   Wed Jan 29 07:56:18 2014 +0100
186
187     mac80211: fix possible memory leak on AP CSA failure
188     
189     If CSA for AP interface failed and the interface
190     was not stopped afterwards another CSA request
191     would leak sdata->u.ap.next_beacon.
192     
193     Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
194     Reviewed-by: Luciano Coelho <luciano.coelho@intel.com>
195     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
196
197 commit 3a77ba08940682bf3d52cf14f980337324af9d4a
198 Author: Johannes Berg <johannes.berg@intel.com>
199 Date:   Sat Feb 1 00:33:29 2014 +0100
200
201     mac80211: fix fragmentation code, particularly for encryption
202     
203     The "new" fragmentation code (since my rewrite almost 5 years ago)
204     erroneously sets skb->len rather than using skb_trim() to adjust
205     the length of the first fragment after copying out all the others.
206     This leaves the skb tail pointer pointing to after where the data
207     originally ended, and thus causes the encryption MIC to be written
208     at that point, rather than where it belongs: immediately after the
209     data.
210     
211     The impact of this is that if software encryption is done, then
212      a) encryption doesn't work for the first fragment, the connection
213         becomes unusable as the first fragment will never be properly
214         verified at the receiver, the MIC is practically guaranteed to
215         be wrong
216      b) we leak up to 8 bytes of plaintext (!) of the packet out into
217         the air
218     
219     This is only mitigated by the fact that many devices are capable
220     of doing encryption in hardware, in which case this can't happen
221     as the tail pointer is irrelevant in that case. Additionally,
222     fragmentation is not used very frequently and would normally have
223     to be configured manually.
224     
225     Fix this by using skb_trim() properly.
226     
227     Cc: stable@vger.kernel.org
228     Fixes: 2de8e0d999b8 ("mac80211: rewrite fragmentation")
229     Reported-by: Jouni Malinen <j@w1.fi>
230     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
231
232 commit de5f242e0c10e841017e37eb8c38974a642dbca8
233 Author: Sujith Manoharan <c_manoha@qca.qualcomm.com>
234 Date:   Tue Jan 28 06:21:59 2014 +0530
235
236     ath9k: Fix build error on ARM
237     
238     Use mdelay instead of udelay to fix this error:
239     
240     ERROR: "__bad_udelay" [drivers/net/wireless/ath/ath9k/ath9k_hw.ko] undefined!
241     make[1]: *** [__modpost] Error 1
242     make: *** [modules] Error 2
243     
244     Reported-by: Josh Boyer <jwboyer@fedoraproject.org>
245     Signed-off-by: Sujith Manoharan <c_manoha@qca.qualcomm.com>
246
247 commit 8e3ea7a51dfc61810fcefd947f6edcf61125252a
248 Author: Geert Uytterhoeven <geert@linux-m68k.org>
249 Date:   Sun Jan 26 11:53:21 2014 +0100
250
251     ath9k: Fix uninitialized variable in ath9k_has_tx_pending()
252     
253     drivers/net/wireless/ath/ath9k/main.c: In function ‘ath9k_has_tx_pending’:
254     drivers/net/wireless/ath/ath9k/main.c:1869: warning: ‘npend’ may be used uninitialized in this function
255     
256     Introduced by commit 10e2318103f5941aa70c318afe34bc41f1b98529 ("ath9k:
257     optimize ath9k_flush").
258     
259     Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
260
261 commit a4a634a6937ebdd827fa58e8fcdb8ca49a3769f6
262 Author: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
263 Date:   Mon Jan 27 11:07:42 2014 +0200
264
265     mac80211: release the channel in error path in start_ap
266     
267     When the driver cannot start the AP or when the assignement
268     of the beacon goes wrong, we need to unassign the vif.
269     
270     Cc: stable@vger.kernel.org
271     Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
272     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
273
274 commit dfb6889a75c601aedb7450b7e606668e77da6679
275 Author: Johannes Berg <johannes.berg@intel.com>
276 Date:   Wed Jan 22 11:14:19 2014 +0200
277
278     cfg80211: send scan results from work queue
279     
280     Due to the previous commit, when a scan finishes, it is in theory
281     possible to hit the following sequence:
282      1. interface starts being removed
283      2. scan is cancelled by driver and cfg80211 is notified
284      3. scan done work is scheduled
285      4. interface is removed completely, rdev->scan_req is freed,
286         event sent to userspace but scan done work remains pending
287      5. new scan is requested on another virtual interface
288      6. scan done work runs, freeing the still-running scan
289     
290     To fix this situation, hang on to the scan done message and block
291     new scans while that is the case, and only send the message from
292     the work function, regardless of whether the scan_req is already
293     freed from interface removal. This makes step 5 above impossible
294     and changes step 6 to be
295      5. scan done work runs, sending the scan done message
296     
297     As this can't work for wext, so we send the message immediately,
298     but this shouldn't be an issue since we still return -EBUSY.
299     
300     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
301
302 commit 45b7ab41fc08627d9a8428cb413d5d84662a9707
303 Author: Johannes Berg <johannes.berg@intel.com>
304 Date:   Wed Jan 22 11:14:18 2014 +0200
305
306     cfg80211: fix scan done race
307     
308     When an interface/wdev is removed, any ongoing scan should be
309     cancelled by the driver. This will make it call cfg80211, which
310     only queues a work struct. If interface/wdev removal is quick
311     enough, this can leave the scan request pending and processed
312     only after the interface is gone, causing a use-after-free.
313     
314     Fix this by making sure the scan request is not pending after
315     the interface is destroyed. We can't flush or cancel the work
316     item due to locking concerns, but when it'll run it shouldn't
317     find anything to do. This leaves a potential issue, if a new
318     scan gets requested before the work runs, it prematurely stops
319     the running scan, potentially causing another crash. I'll fix
320     that in the next patch.
321     
322     This was particularly observed with P2P_DEVICE wdevs, likely
323     because freeing them is quicker than freeing netdevs.
324     
325     Reported-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
326     Fixes: 4a58e7c38443 ("cfg80211: don't "leak" uncompleted scans")
327     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
328
329 commit ae04fa489ab31b5a10d3cc8399f52761175d4321
330 Author: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
331 Date:   Thu Jan 23 14:28:16 2014 +0200
332
333     mac80211: avoid deadlock revealed by lockdep
334     
335     sdata->u.ap.request_smps_work can’t be flushed synchronously
336     under wdev_lock(wdev) since ieee80211_request_smps_ap_work
337     itself locks the same lock.
338     While at it, reset the driver_smps_mode when the ap is
339     stopped to its default: OFF.
340     
341     This solves:
342     
343     ======================================================
344     [ INFO: possible circular locking dependency detected ]
345     3.12.0-ipeer+ #2 Tainted: G           O
346     -------------------------------------------------------
347     rmmod/2867 is trying to acquire lock:
348       ((&sdata->u.ap.request_smps_work)){+.+...}, at: [<c105b8d0>] flush_work+0x0/0x90
349     
350     but task is already holding lock:
351       (&wdev->mtx){+.+.+.}, at: [<f9b32626>] cfg80211_stop_ap+0x26/0x230 [cfg80211]
352     
353     which lock already depends on the new lock.
354     
355     the existing dependency chain (in reverse order) is:
356     
357     -> #1 (&wdev->mtx){+.+.+.}:
358             [<c10aefa9>] lock_acquire+0x79/0xe0
359             [<c1607a1a>] mutex_lock_nested+0x4a/0x360
360             [<fb06288b>] ieee80211_request_smps_ap_work+0x2b/0x50 [mac80211]
361             [<c105cdd8>] process_one_work+0x198/0x450
362             [<c105d469>] worker_thread+0xf9/0x320
363             [<c10669ff>] kthread+0x9f/0xb0
364             [<c1613397>] ret_from_kernel_thread+0x1b/0x28
365     
366     -> #0 ((&sdata->u.ap.request_smps_work)){+.+...}:
367             [<c10ae9df>] __lock_acquire+0x183f/0x1910
368             [<c10aefa9>] lock_acquire+0x79/0xe0
369             [<c105b917>] flush_work+0x47/0x90
370             [<c105d867>] __cancel_work_timer+0x67/0xe0
371             [<c105d90f>] cancel_work_sync+0xf/0x20
372             [<fb0765cc>] ieee80211_stop_ap+0x8c/0x340 [mac80211]
373             [<f9b3268c>] cfg80211_stop_ap+0x8c/0x230 [cfg80211]
374             [<f9b0d8f9>] cfg80211_leave+0x79/0x100 [cfg80211]
375             [<f9b0da72>] cfg80211_netdev_notifier_call+0xf2/0x4f0 [cfg80211]
376             [<c160f2c9>] notifier_call_chain+0x59/0x130
377             [<c106c6de>] __raw_notifier_call_chain+0x1e/0x30
378             [<c106c70f>] raw_notifier_call_chain+0x1f/0x30
379             [<c14f8213>] call_netdevice_notifiers_info+0x33/0x70
380             [<c14f8263>] call_netdevice_notifiers+0x13/0x20
381             [<c14f82a4>] __dev_close_many+0x34/0xb0
382             [<c14f83fe>] dev_close_many+0x6e/0xc0
383             [<c14f9c77>] rollback_registered_many+0xa7/0x1f0
384             [<c14f9dd4>] unregister_netdevice_many+0x14/0x60
385             [<fb06f4d9>] ieee80211_remove_interfaces+0xe9/0x170 [mac80211]
386             [<fb055116>] ieee80211_unregister_hw+0x56/0x110 [mac80211]
387             [<fa3e9396>] iwl_op_mode_mvm_stop+0x26/0xe0 [iwlmvm]
388             [<f9b9d8ca>] _iwl_op_mode_stop+0x3a/0x70 [iwlwifi]
389             [<f9b9d96f>] iwl_opmode_deregister+0x6f/0x90 [iwlwifi]
390             [<fa405179>] __exit_compat+0xd/0x19 [iwlmvm]
391             [<c10b8bf9>] SyS_delete_module+0x179/0x2b0
392             [<c1613421>] sysenter_do_call+0x12/0x32
393     
394     Fixes: 687da132234f ("mac80211: implement SMPS for AP")
395     Cc: <stable@vger.kernel.org> [3.13]
396     Reported-by: Ilan Peer <ilan.peer@intel.com>
397     Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
398     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
399
400 commit 178b205e96217164fd7c30113464250d0b6f5eca
401 Author: Johannes Berg <johannes.berg@intel.com>
402 Date:   Thu Jan 23 16:32:29 2014 +0100
403
404     cfg80211: re-enable 5/10 MHz support
405     
406     Unfortunately I forgot this during the merge window, but the
407     patch seems small enough to go in as a fix. The userspace API
408     bug that was the reason for disabling it has long been fixed.
409     
410     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
411
412 commit 110a1c79acda14edc83b7c8dc5af9c7ddd23eb61
413 Author: Pontus Fuchs <pontus.fuchs@gmail.com>
414 Date:   Thu Jan 16 15:00:40 2014 +0100
415
416     nl80211: Reset split_start when netlink skb is exhausted
417     
418     When the netlink skb is exhausted split_start is left set. In the
419     subsequent retry, with a larger buffer, the dump is continued from the
420     failing point instead of from the beginning.
421     
422     This was causing my rt28xx based USB dongle to now show up when
423     running "iw list" with an old iw version without split dump support.
424     
425     Cc: stable@vger.kernel.org
426     Fixes: 3713b4e364ef ("nl80211: allow splitting wiphy information in dumps")
427     Signed-off-by: Pontus Fuchs <pontus.fuchs@gmail.com>
428     [avoid the entire workaround when state->split is set]
429     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
430
431 commit b4c31b45ffc7ef110fa9ecc34d7878fe7c5b9da4
432 Author: Eliad Peller <eliad@wizery.com>
433 Date:   Sun Jan 12 11:06:37 2014 +0200
434
435     mac80211: move roc cookie assignment earlier
436     
437     ieee80211_start_roc_work() might add a new roc
438     to existing roc, and tell cfg80211 it has already
439     started.
440     
441     However, this might happen before the roc cookie
442     was set, resulting in REMAIN_ON_CHANNEL (started)
443     event with null cookie. Consequently, it can make
444     wpa_supplicant go out of sync.
445     
446     Fix it by setting the roc cookie earlier.
447     
448     Cc: stable@vger.kernel.org
449     Signed-off-by: Eliad Peller <eliad@wizery.com>
450     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
451
452 commit cfdc9157bfd7bcf88ab4dae08873a9907eba984c
453 Author: Johannes Berg <johannes.berg@intel.com>
454 Date:   Fri Jan 24 14:06:29 2014 +0100
455
456     nl80211: send event when AP operation is stopped
457     
458     There are a few cases, e.g. suspend, where an AP interface is
459     stopped by the kernel rather than by userspace request, most
460     commonly when suspending. To let userspace know about this,
461     send the NL80211_CMD_STOP_AP command as an event every time
462     an AP interface is stopped. This also happens when userspace
463     did in fact request the AP stop, but that's not a problem.
464     
465     For full-MAC drivers this may need to be extended to also
466     cover cases where the device stopped the AP operation for
467     some reason, this a bit more complicated because then all
468     cfg80211 state also needs to be reset; such API is not part
469     of this patch.
470     
471     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
472
473 commit d5d567eda7704f190379ca852a8f9a4112e3eee3
474 Author: Johannes Berg <johannes.berg@intel.com>
475 Date:   Thu Jan 23 16:20:29 2014 +0100
476
477     mac80211: add length check in ieee80211_is_robust_mgmt_frame()
478     
479     A few places weren't checking that the frame passed to the
480     function actually has enough data even though the function
481     clearly documents it must have a payload byte. Make this
482     safer by changing the function to take an skb and checking
483     the length inside. The old version is preserved for now as
484     the rtl* drivers use it and don't have a correct skb.
485     
486     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
487
488 commit f8f6d212a047fc65c7d3442dfc038f65517236fc
489 Author: Johannes Berg <johannes.berg@intel.com>
490 Date:   Fri Jan 24 10:53:53 2014 +0100
491
492     nl80211: fix scheduled scan RSSI matchset attribute confusion
493     
494     The scheduled scan matchsets were intended to be a list of filters,
495     with the found BSS having to pass at least one of them to be passed
496     to the host. When the RSSI attribute was added, however, this was
497     broken and currently wpa_supplicant adds that attribute in its own
498     matchset; however, it doesn't intend that to mean that anything
499     that passes the RSSI filter should be passed to the host, instead
500     it wants it to mean that everything needs to also have higher RSSI.
501     
502     This is semantically problematic because we have a list of filters
503     like [ SSID1, SSID2, SSID3, RSSI ] with no real indication which
504     one should be OR'ed and which one AND'ed.
505     
506     To fix this, move the RSSI filter attribute into each matchset. As
507     we need to stay backward compatible, treat a matchset with only the
508     RSSI attribute as a "default RSSI filter" for all other matchsets,
509     but only if there are other matchsets (an RSSI-only matchset by
510     itself is still desirable.)
511     
512     To make driver implementation easier, keep a global min_rssi_thold
513     for the entire request as well. The only affected driver is ath6kl.
514     
515     I found this when I looked into the code after Raja Mani submitted
516     a patch fixing the n_match_sets calculation to disregard the RSSI,
517     but that patch didn't address the semantic issue.
518     
519     Reported-by: Raja Mani <rmani@qti.qualcomm.com>
520     Acked-by: Luciano Coelho <luciano.coelho@intel.com>
521     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
522
523 commit de553e8545e65a6dc4e45f43df7e1443d4291922
524 Author: Johannes Berg <johannes.berg@intel.com>
525 Date:   Fri Jan 24 10:17:47 2014 +0100
526
527     nl80211: check nla_parse() return values
528     
529     If there's a policy, then nla_parse() return values must be
530     checked, otherwise the policy is useless and there's nothing
531     that ensures the attributes are actually what we expect them
532     to be.
533     
534     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
535
536 commit 652204a0733e9e1c54661d6f9d36e2e1e3b22bb1
537 Author: Karl Beldan <karl.beldan@rivierawaves.com>
538 Date:   Thu Jan 23 20:06:34 2014 +0100
539
540     mac80211: send {ADD,DEL}BA on AC_VO like other mgmt frames, as per spec
541     
542     ATM, {ADD,DEL}BA and BAR frames are sent on the AC matching the TID of
543     the BA parameters. In the discussion [1] about this patch, Johannes
544     recalled that it fixed some races with the DELBA and indeed this
545     behavior was introduced in [2].
546     While [2] is right for the BARs, the part queueing the {ADD,DEL}BAs on
547     their BA params TID AC violates the spec and is more a workaround for
548     some drivers. Helmut expressed some concerns wrt such drivers, in
549     particular DELBAs in rt2x00.
550     
551     ATM, DELBAs are sent after a driver has called (hence "purposely")
552     ieee80211_start_tx_ba_cb_irqsafe and Johannes and Emmanuel gave some
553     details wrt intentions behind the split of the IEEE80211_AMPDU_TX_STOP_*
554     given to the driver ampdu_action supposed to call this function, which
555     could prove handy to people trying to do the right thing in faulty
556     drivers (if their fw/hw don't get in their way).
557     
558     [1] http://mid.gmane.org/1390391564-18481-1-git-send-email-karl.beldan@gmail.com
559     [2] Commit: cf6bb79ad828 ("mac80211: Use appropriate TID for sending BAR, ADDBA and DELBA frames")
560     
561     Signed-off-by: Karl Beldan <karl.beldan@rivierawaves.com>
562     Cc: Helmut Schaa <helmut.schaa@googlemail.com>
563     Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
564     Signed-off-by: Johannes Berg <johannes.berg@intel.com>
565 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
566 +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
567 @@ -790,7 +790,7 @@ void ath6kl_cfg80211_connect_event(struc
568         if (nw_type & ADHOC_NETWORK) {
569                 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "ad-hoc %s selected\n",
570                            nw_type & ADHOC_CREATOR ? "creator" : "joiner");
571 -               cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
572 +               cfg80211_ibss_joined(vif->ndev, bssid, chan, GFP_KERNEL);
573                 cfg80211_put_bss(ar->wiphy, bss);
574                 return;
575         }
576 @@ -861,13 +861,9 @@ void ath6kl_cfg80211_disconnect_event(st
577         }
578  
579         if (vif->nw_type & ADHOC_NETWORK) {
580 -               if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC) {
581 +               if (vif->wdev.iftype != NL80211_IFTYPE_ADHOC)
582                         ath6kl_dbg(ATH6KL_DBG_WLAN_CFG,
583                                    "%s: ath6k not in ibss mode\n", __func__);
584 -                       return;
585 -               }
586 -               memset(bssid, 0, ETH_ALEN);
587 -               cfg80211_ibss_joined(vif->ndev, bssid, GFP_KERNEL);
588                 return;
589         }
590  
591 @@ -3256,6 +3252,15 @@ static int ath6kl_cfg80211_sscan_start(s
592         struct ath6kl_vif *vif = netdev_priv(dev);
593         u16 interval;
594         int ret, rssi_thold;
595 +       int n_match_sets = request->n_match_sets;
596 +
597 +       /*
598 +        * If there's a matchset w/o an SSID, then assume it's just for
599 +        * the RSSI (nothing else is currently supported) and ignore it.
600 +        * The device only supports a global RSSI filter that we set below.
601 +        */
602 +       if (n_match_sets == 1 && !request->match_sets[0].ssid.ssid_len)
603 +               n_match_sets = 0;
604  
605         if (ar->state != ATH6KL_STATE_ON)
606                 return -EIO;
607 @@ -3268,11 +3273,11 @@ static int ath6kl_cfg80211_sscan_start(s
608         ret = ath6kl_set_probed_ssids(ar, vif, request->ssids,
609                                       request->n_ssids,
610                                       request->match_sets,
611 -                                     request->n_match_sets);
612 +                                     n_match_sets);
613         if (ret < 0)
614                 return ret;
615  
616 -       if (!request->n_match_sets) {
617 +       if (!n_match_sets) {
618                 ret = ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
619                                                ALL_BSS_FILTER, 0);
620                 if (ret < 0)
621 @@ -3286,12 +3291,12 @@ static int ath6kl_cfg80211_sscan_start(s
622  
623         if (test_bit(ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD,
624                      ar->fw_capabilities)) {
625 -               if (request->rssi_thold <= NL80211_SCAN_RSSI_THOLD_OFF)
626 +               if (request->min_rssi_thold <= NL80211_SCAN_RSSI_THOLD_OFF)
627                         rssi_thold = 0;
628 -               else if (request->rssi_thold < -127)
629 +               else if (request->min_rssi_thold < -127)
630                         rssi_thold = -127;
631                 else
632 -                       rssi_thold = request->rssi_thold;
633 +                       rssi_thold = request->min_rssi_thold;
634  
635                 ret = ath6kl_wmi_set_rssi_filter_cmd(ar->wmi, vif->fw_vif_idx,
636                                                      rssi_thold);
637 --- a/drivers/net/wireless/ath/ath9k/hw.c
638 +++ b/drivers/net/wireless/ath/ath9k/hw.c
639 @@ -1316,7 +1316,7 @@ static bool ath9k_hw_set_reset(struct at
640         if (AR_SREV_9300_20_OR_LATER(ah))
641                 udelay(50);
642         else if (AR_SREV_9100(ah))
643 -               udelay(10000);
644 +               mdelay(10);
645         else
646                 udelay(100);
647  
648 @@ -2051,9 +2051,8 @@ static bool ath9k_hw_set_power_awake(str
649  
650         REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
651                     AR_RTC_FORCE_WAKE_EN);
652 -
653         if (AR_SREV_9100(ah))
654 -               udelay(10000);
655 +               mdelay(10);
656         else
657                 udelay(50);
658  
659 --- a/drivers/net/wireless/ath/ath9k/main.c
660 +++ b/drivers/net/wireless/ath/ath9k/main.c
661 @@ -1866,7 +1866,7 @@ static void ath9k_set_coverage_class(str
662  
663  static bool ath9k_has_tx_pending(struct ath_softc *sc)
664  {
665 -       int i, npend;
666 +       int i, npend = 0;
667  
668         for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
669                 if (!ATH_TXQ_SETUP(sc, i))
670 --- a/drivers/net/wireless/iwlwifi/mvm/scan.c
671 +++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
672 @@ -595,6 +595,9 @@ static void iwl_scan_offload_build_ssid(
673          * config match list.
674          */
675         for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) {
676 +               /* skip empty SSID matchsets */
677 +               if (!req->match_sets[i].ssid.ssid_len)
678 +                       continue;
679                 scan->direct_scan[i].id = WLAN_EID_SSID;
680                 scan->direct_scan[i].len = req->match_sets[i].ssid.ssid_len;
681                 memcpy(scan->direct_scan[i].ssid, req->match_sets[i].ssid.ssid,
682 --- a/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c
683 +++ b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c
684 @@ -452,7 +452,7 @@ bool rtl88ee_rx_query_desc(struct ieee80
685                         /* During testing, hdr was NULL */
686                         return false;
687                 }
688 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
689 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
690                     (ieee80211_has_protected(hdr->frame_control)))
691                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
692                 else
693 --- a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
694 +++ b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
695 @@ -393,7 +393,7 @@ bool rtl92ce_rx_query_desc(struct ieee80
696                         /* In testing, hdr was NULL here */
697                         return false;
698                 }
699 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
700 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
701                     (ieee80211_has_protected(hdr->frame_control)))
702                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
703                 else
704 --- a/drivers/net/wireless/rtlwifi/rtl8192se/trx.c
705 +++ b/drivers/net/wireless/rtlwifi/rtl8192se/trx.c
706 @@ -310,7 +310,7 @@ bool rtl92se_rx_query_desc(struct ieee80
707                         /* during testing, hdr was NULL here */
708                         return false;
709                 }
710 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
711 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
712                         (ieee80211_has_protected(hdr->frame_control)))
713                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
714                 else
715 --- a/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c
716 +++ b/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c
717 @@ -334,7 +334,7 @@ bool rtl8723ae_rx_query_desc(struct ieee
718                         /* during testing, hdr could be NULL here */
719                         return false;
720                 }
721 -               if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
722 +               if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
723                         (ieee80211_has_protected(hdr->frame_control)))
724                         rx_status->flag &= ~RX_FLAG_DECRYPTED;
725                 else
726 --- a/include/linux/ieee80211.h
727 +++ b/include/linux/ieee80211.h
728 @@ -597,6 +597,20 @@ static inline int ieee80211_is_qos_nullf
729  }
730  
731  /**
732 + * ieee80211_is_bufferable_mmpdu - check if frame is bufferable MMPDU
733 + * @fc: frame control field in little-endian byteorder
734 + */
735 +static inline bool ieee80211_is_bufferable_mmpdu(__le16 fc)
736 +{
737 +       /* IEEE 802.11-2012, definition of "bufferable management frame";
738 +        * note that this ignores the IBSS special case. */
739 +       return ieee80211_is_mgmt(fc) &&
740 +              (ieee80211_is_action(fc) ||
741 +               ieee80211_is_disassoc(fc) ||
742 +               ieee80211_is_deauth(fc));
743 +}
744 +
745 +/**
746   * ieee80211_is_first_frag - check if IEEE80211_SCTL_FRAG is not set
747   * @seq_ctrl: frame sequence control bytes in little-endian byteorder
748   */
749 @@ -2192,10 +2206,10 @@ static inline u8 *ieee80211_get_DA(struc
750  }
751  
752  /**
753 - * ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
754 + * _ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
755   * @hdr: the frame (buffer must include at least the first octet of payload)
756   */
757 -static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
758 +static inline bool _ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
759  {
760         if (ieee80211_is_disassoc(hdr->frame_control) ||
761             ieee80211_is_deauth(hdr->frame_control))
762 @@ -2224,6 +2238,17 @@ static inline bool ieee80211_is_robust_m
763  }
764  
765  /**
766 + * ieee80211_is_robust_mgmt_frame - check if skb contains a robust mgmt frame
767 + * @skb: the skb containing the frame, length will be checked
768 + */
769 +static inline bool ieee80211_is_robust_mgmt_frame(struct sk_buff *skb)
770 +{
771 +       if (skb->len < 25)
772 +               return false;
773 +       return _ieee80211_is_robust_mgmt_frame((void *)skb->data);
774 +}
775 +
776 +/**
777   * ieee80211_is_public_action - check if frame is a public action frame
778   * @hdr: the frame
779   * @len: length of the frame
780 --- a/include/net/cfg80211.h
781 +++ b/include/net/cfg80211.h
782 @@ -1395,9 +1395,11 @@ struct cfg80211_scan_request {
783   * struct cfg80211_match_set - sets of attributes to match
784   *
785   * @ssid: SSID to be matched
786 + * @rssi_thold: don't report scan results below this threshold (in s32 dBm)
787   */
788  struct cfg80211_match_set {
789         struct cfg80211_ssid ssid;
790 +       s32 rssi_thold;
791  };
792  
793  /**
794 @@ -1420,7 +1422,8 @@ struct cfg80211_match_set {
795   * @dev: the interface
796   * @scan_start: start time of the scheduled scan
797   * @channels: channels to scan
798 - * @rssi_thold: don't report scan results below this threshold (in s32 dBm)
799 + * @min_rssi_thold: for drivers only supporting a single threshold, this
800 + *     contains the minimum over all matchsets
801   */
802  struct cfg80211_sched_scan_request {
803         struct cfg80211_ssid *ssids;
804 @@ -1433,7 +1436,7 @@ struct cfg80211_sched_scan_request {
805         u32 flags;
806         struct cfg80211_match_set *match_sets;
807         int n_match_sets;
808 -       s32 rssi_thold;
809 +       s32 min_rssi_thold;
810  
811         /* internal */
812         struct wiphy *wiphy;
813 @@ -3130,8 +3133,8 @@ struct cfg80211_cached_keys;
814   * @identifier: (private) Identifier used in nl80211 to identify this
815   *     wireless device if it has no netdev
816   * @current_bss: (private) Used by the internal configuration code
817 - * @channel: (private) Used by the internal configuration code to track
818 - *     the user-set AP, monitor and WDS channel
819 + * @chandef: (private) Used by the internal configuration code to track
820 + *     the user-set channel definition.
821   * @preset_chandef: (private) Used by the internal configuration code to
822   *     track the channel to be used for AP later
823   * @bssid: (private) Used by the internal configuration code
824 @@ -3195,9 +3198,7 @@ struct wireless_dev {
825  
826         struct cfg80211_internal_bss *current_bss; /* associated / joined */
827         struct cfg80211_chan_def preset_chandef;
828 -
829 -       /* for AP and mesh channel tracking */
830 -       struct ieee80211_channel *channel;
831 +       struct cfg80211_chan_def chandef;
832  
833         bool ibss_fixed;
834         bool ibss_dfs_possible;
835 @@ -3879,6 +3880,7 @@ void cfg80211_michael_mic_failure(struct
836   *
837   * @dev: network device
838   * @bssid: the BSSID of the IBSS joined
839 + * @channel: the channel of the IBSS joined
840   * @gfp: allocation flags
841   *
842   * This function notifies cfg80211 that the device joined an IBSS or
843 @@ -3888,7 +3890,8 @@ void cfg80211_michael_mic_failure(struct
844   * with the locally generated beacon -- this guarantees that there is
845   * always a scan result for this IBSS. cfg80211 will handle the rest.
846   */
847 -void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp);
848 +void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
849 +                         struct ieee80211_channel *channel, gfp_t gfp);
850  
851  /**
852   * cfg80211_notify_new_candidate - notify cfg80211 of a new mesh peer candidate
853 --- a/include/uapi/linux/nl80211.h
854 +++ b/include/uapi/linux/nl80211.h
855 @@ -2442,9 +2442,15 @@ enum nl80211_reg_rule_attr {
856   * enum nl80211_sched_scan_match_attr - scheduled scan match attributes
857   * @__NL80211_SCHED_SCAN_MATCH_ATTR_INVALID: attribute number 0 is reserved
858   * @NL80211_SCHED_SCAN_MATCH_ATTR_SSID: SSID to be used for matching,
859 - * only report BSS with matching SSID.
860 + *     only report BSS with matching SSID.
861   * @NL80211_SCHED_SCAN_MATCH_ATTR_RSSI: RSSI threshold (in dBm) for reporting a
862 - *     BSS in scan results. Filtering is turned off if not specified.
863 + *     BSS in scan results. Filtering is turned off if not specified. Note that
864 + *     if this attribute is in a match set of its own, then it is treated as
865 + *     the default value for all matchsets with an SSID, rather than being a
866 + *     matchset of its own without an RSSI filter. This is due to problems with
867 + *     how this API was implemented in the past. Also, due to the same problem,
868 + *     the only way to create a matchset with only an RSSI filter (with this
869 + *     attribute) is if there's only a single matchset with the RSSI attribute.
870   * @NL80211_SCHED_SCAN_MATCH_ATTR_MAX: highest scheduled scan filter
871   *     attribute number currently defined
872   * @__NL80211_SCHED_SCAN_MATCH_ATTR_AFTER_LAST: internal use
873 --- a/net/mac80211/agg-tx.c
874 +++ b/net/mac80211/agg-tx.c
875 @@ -107,7 +107,7 @@ static void ieee80211_send_addba_request
876         mgmt->u.action.u.addba_req.start_seq_num =
877                                         cpu_to_le16(start_seq_num << 4);
878  
879 -       ieee80211_tx_skb_tid(sdata, skb, tid);
880 +       ieee80211_tx_skb(sdata, skb);
881  }
882  
883  void ieee80211_send_bar(struct ieee80211_vif *vif, u8 *ra, u16 tid, u16 ssn)
884 --- a/net/mac80211/cfg.c
885 +++ b/net/mac80211/cfg.c
886 @@ -970,9 +970,9 @@ static int ieee80211_start_ap(struct wip
887         /* TODO: make hostapd tell us what it wants */
888         sdata->smps_mode = IEEE80211_SMPS_OFF;
889         sdata->needed_rx_chains = sdata->local->rx_chains;
890 -       sdata->radar_required = params->radar_required;
891  
892         mutex_lock(&local->mtx);
893 +       sdata->radar_required = params->radar_required;
894         err = ieee80211_vif_use_channel(sdata, &params->chandef,
895                                         IEEE80211_CHANCTX_SHARED);
896         mutex_unlock(&local->mtx);
897 @@ -1021,8 +1021,10 @@ static int ieee80211_start_ap(struct wip
898                                         IEEE80211_P2P_OPPPS_ENABLE_BIT;
899  
900         err = ieee80211_assign_beacon(sdata, &params->beacon);
901 -       if (err < 0)
902 +       if (err < 0) {
903 +               ieee80211_vif_release_channel(sdata);
904                 return err;
905 +       }
906         changed |= err;
907  
908         err = drv_start_ap(sdata->local, sdata);
909 @@ -1032,6 +1034,7 @@ static int ieee80211_start_ap(struct wip
910                 if (old)
911                         kfree_rcu(old, rcu_head);
912                 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
913 +               ieee80211_vif_release_channel(sdata);
914                 return err;
915         }
916  
917 @@ -1053,6 +1056,7 @@ static int ieee80211_change_beacon(struc
918         int err;
919  
920         sdata = IEEE80211_DEV_TO_SUB_IF(dev);
921 +       sdata_assert_lock(sdata);
922  
923         /* don't allow changing the beacon while CSA is in place - offset
924          * of channel switch counter may change
925 @@ -1080,6 +1084,8 @@ static int ieee80211_stop_ap(struct wiph
926         struct probe_resp *old_probe_resp;
927         struct cfg80211_chan_def chandef;
928  
929 +       sdata_assert_lock(sdata);
930 +
931         old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
932         if (!old_beacon)
933                 return -ENOENT;
934 @@ -1090,8 +1096,6 @@ static int ieee80211_stop_ap(struct wiph
935         kfree(sdata->u.ap.next_beacon);
936         sdata->u.ap.next_beacon = NULL;
937  
938 -       cancel_work_sync(&sdata->u.ap.request_smps_work);
939 -
940         /* turn off carrier for this interface and dependent VLANs */
941         list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
942                 netif_carrier_off(vlan->dev);
943 @@ -1103,6 +1107,7 @@ static int ieee80211_stop_ap(struct wiph
944         kfree_rcu(old_beacon, rcu_head);
945         if (old_probe_resp)
946                 kfree_rcu(old_probe_resp, rcu_head);
947 +       sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
948  
949         __sta_info_flush(sdata, true);
950         ieee80211_free_keys(sdata, true);
951 @@ -2638,6 +2643,24 @@ static int ieee80211_start_roc_work(stru
952         INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
953         INIT_LIST_HEAD(&roc->dependents);
954  
955 +       /*
956 +        * cookie is either the roc cookie (for normal roc)
957 +        * or the SKB (for mgmt TX)
958 +        */
959 +       if (!txskb) {
960 +               /* local->mtx protects this */
961 +               local->roc_cookie_counter++;
962 +               roc->cookie = local->roc_cookie_counter;
963 +               /* wow, you wrapped 64 bits ... more likely a bug */
964 +               if (WARN_ON(roc->cookie == 0)) {
965 +                       roc->cookie = 1;
966 +                       local->roc_cookie_counter++;
967 +               }
968 +               *cookie = roc->cookie;
969 +       } else {
970 +               *cookie = (unsigned long)txskb;
971 +       }
972 +
973         /* if there's one pending or we're scanning, queue this one */
974         if (!list_empty(&local->roc_list) ||
975             local->scanning || local->radar_detect_enabled)
976 @@ -2772,24 +2795,6 @@ static int ieee80211_start_roc_work(stru
977         if (!queued)
978                 list_add_tail(&roc->list, &local->roc_list);
979  
980 -       /*
981 -        * cookie is either the roc cookie (for normal roc)
982 -        * or the SKB (for mgmt TX)
983 -        */
984 -       if (!txskb) {
985 -               /* local->mtx protects this */
986 -               local->roc_cookie_counter++;
987 -               roc->cookie = local->roc_cookie_counter;
988 -               /* wow, you wrapped 64 bits ... more likely a bug */
989 -               if (WARN_ON(roc->cookie == 0)) {
990 -                       roc->cookie = 1;
991 -                       local->roc_cookie_counter++;
992 -               }
993 -               *cookie = roc->cookie;
994 -       } else {
995 -               *cookie = (unsigned long)txskb;
996 -       }
997 -
998         return 0;
999  }
1000  
1001 @@ -3004,8 +3009,10 @@ void ieee80211_csa_finalize_work(struct 
1002         if (!ieee80211_sdata_running(sdata))
1003                 goto unlock;
1004  
1005 -       sdata->radar_required = sdata->csa_radar_required;
1006 +       sdata_assert_lock(sdata);
1007 +
1008         mutex_lock(&local->mtx);
1009 +       sdata->radar_required = sdata->csa_radar_required;
1010         err = ieee80211_vif_change_channel(sdata, &changed);
1011         mutex_unlock(&local->mtx);
1012         if (WARN_ON(err < 0))
1013 @@ -3022,13 +3029,13 @@ void ieee80211_csa_finalize_work(struct 
1014         switch (sdata->vif.type) {
1015         case NL80211_IFTYPE_AP:
1016                 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
1017 +               kfree(sdata->u.ap.next_beacon);
1018 +               sdata->u.ap.next_beacon = NULL;
1019 +
1020                 if (err < 0)
1021                         goto unlock;
1022  
1023                 changed |= err;
1024 -               kfree(sdata->u.ap.next_beacon);
1025 -               sdata->u.ap.next_beacon = NULL;
1026 -
1027                 ieee80211_bss_info_change_notify(sdata, err);
1028                 break;
1029         case NL80211_IFTYPE_ADHOC:
1030 @@ -3066,7 +3073,7 @@ int ieee80211_channel_switch(struct wiph
1031         struct ieee80211_if_mesh __maybe_unused *ifmsh;
1032         int err, num_chanctx;
1033  
1034 -       lockdep_assert_held(&sdata->wdev.mtx);
1035 +       sdata_assert_lock(sdata);
1036  
1037         if (!list_empty(&local->roc_list) || local->scanning)
1038                 return -EBUSY;
1039 --- a/net/mac80211/ht.c
1040 +++ b/net/mac80211/ht.c
1041 @@ -375,7 +375,7 @@ void ieee80211_send_delba(struct ieee802
1042         mgmt->u.action.u.delba.params = cpu_to_le16(params);
1043         mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
1044  
1045 -       ieee80211_tx_skb_tid(sdata, skb, tid);
1046 +       ieee80211_tx_skb(sdata, skb);
1047  }
1048  
1049  void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
1050 @@ -466,7 +466,9 @@ void ieee80211_request_smps_ap_work(stru
1051                              u.ap.request_smps_work);
1052  
1053         sdata_lock(sdata);
1054 -       __ieee80211_request_smps_ap(sdata, sdata->u.ap.driver_smps_mode);
1055 +       if (sdata_dereference(sdata->u.ap.beacon, sdata))
1056 +               __ieee80211_request_smps_ap(sdata,
1057 +                                           sdata->u.ap.driver_smps_mode);
1058         sdata_unlock(sdata);
1059  }
1060  
1061 --- a/net/mac80211/iface.c
1062 +++ b/net/mac80211/iface.c
1063 @@ -770,12 +770,19 @@ static void ieee80211_do_stop(struct iee
1064  
1065         ieee80211_roc_purge(local, sdata);
1066  
1067 -       if (sdata->vif.type == NL80211_IFTYPE_STATION)
1068 +       switch (sdata->vif.type) {
1069 +       case NL80211_IFTYPE_STATION:
1070                 ieee80211_mgd_stop(sdata);
1071 -
1072 -       if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1073 +               break;
1074 +       case NL80211_IFTYPE_ADHOC:
1075                 ieee80211_ibss_stop(sdata);
1076 -
1077 +               break;
1078 +       case NL80211_IFTYPE_AP:
1079 +               cancel_work_sync(&sdata->u.ap.request_smps_work);
1080 +               break;
1081 +       default:
1082 +               break;
1083 +       }
1084  
1085         /*
1086          * Remove all stations associated with this interface.
1087 @@ -827,7 +834,9 @@ static void ieee80211_do_stop(struct iee
1088         cancel_work_sync(&local->dynamic_ps_enable_work);
1089  
1090         cancel_work_sync(&sdata->recalc_smps);
1091 +       sdata_lock(sdata);
1092         sdata->vif.csa_active = false;
1093 +       sdata_unlock(sdata);
1094         cancel_work_sync(&sdata->csa_finalize_work);
1095  
1096         cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1097 --- a/net/mac80211/rx.c
1098 +++ b/net/mac80211/rx.c
1099 @@ -599,10 +599,10 @@ static int ieee80211_is_unicast_robust_m
1100  {
1101         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1102  
1103 -       if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
1104 +       if (is_multicast_ether_addr(hdr->addr1))
1105                 return 0;
1106  
1107 -       return ieee80211_is_robust_mgmt_frame(hdr);
1108 +       return ieee80211_is_robust_mgmt_frame(skb);
1109  }
1110  
1111  
1112 @@ -610,10 +610,10 @@ static int ieee80211_is_multicast_robust
1113  {
1114         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1115  
1116 -       if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
1117 +       if (!is_multicast_ether_addr(hdr->addr1))
1118                 return 0;
1119  
1120 -       return ieee80211_is_robust_mgmt_frame(hdr);
1121 +       return ieee80211_is_robust_mgmt_frame(skb);
1122  }
1123  
1124  
1125 @@ -626,7 +626,7 @@ static int ieee80211_get_mmie_keyidx(str
1126         if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
1127                 return -1;
1128  
1129 -       if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
1130 +       if (!ieee80211_is_robust_mgmt_frame(skb))
1131                 return -1; /* not a robust management frame */
1132  
1133         mmie = (struct ieee80211_mmie *)
1134 @@ -1311,18 +1311,15 @@ ieee80211_rx_h_sta_process(struct ieee80
1135             !ieee80211_has_morefrags(hdr->frame_control) &&
1136             !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
1137             (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
1138 -            rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
1139 +            rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1140 +           /* PM bit is only checked in frames where it isn't reserved,
1141 +            * in AP mode it's reserved in non-bufferable management frames
1142 +            * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
1143 +            */
1144 +           (!ieee80211_is_mgmt(hdr->frame_control) ||
1145 +            ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
1146                 if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
1147 -                       /*
1148 -                        * Ignore doze->wake transitions that are
1149 -                        * indicated by non-data frames, the standard
1150 -                        * is unclear here, but for example going to
1151 -                        * PS mode and then scanning would cause a
1152 -                        * doze->wake transition for the probe request,
1153 -                        * and that is clearly undesirable.
1154 -                        */
1155 -                       if (ieee80211_is_data(hdr->frame_control) &&
1156 -                           !ieee80211_has_pm(hdr->frame_control))
1157 +                       if (!ieee80211_has_pm(hdr->frame_control))
1158                                 sta_ps_end(sta);
1159                 } else {
1160                         if (ieee80211_has_pm(hdr->frame_control))
1161 @@ -1845,8 +1842,7 @@ static int ieee80211_drop_unencrypted_mg
1162                  * having configured keys.
1163                  */
1164                 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1165 -                            ieee80211_is_robust_mgmt_frame(
1166 -                                    (struct ieee80211_hdr *) rx->skb->data)))
1167 +                            ieee80211_is_robust_mgmt_frame(rx->skb)))
1168                         return -EACCES;
1169         }
1170  
1171 --- a/net/mac80211/tx.c
1172 +++ b/net/mac80211/tx.c
1173 @@ -452,8 +452,7 @@ static int ieee80211_use_mfp(__le16 fc, 
1174         if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
1175                 return 0;
1176  
1177 -       if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
1178 -                                           skb->data))
1179 +       if (!ieee80211_is_robust_mgmt_frame(skb))
1180                 return 0;
1181  
1182         return 1;
1183 @@ -525,9 +524,7 @@ ieee80211_tx_h_ps_buf(struct ieee80211_t
1184  
1185         /* only deauth, disassoc and action are bufferable MMPDUs */
1186         if (ieee80211_is_mgmt(hdr->frame_control) &&
1187 -           !ieee80211_is_deauth(hdr->frame_control) &&
1188 -           !ieee80211_is_disassoc(hdr->frame_control) &&
1189 -           !ieee80211_is_action(hdr->frame_control)) {
1190 +           !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) {
1191                 if (tx->flags & IEEE80211_TX_UNICAST)
1192                         info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1193                 return TX_CONTINUE;
1194 @@ -567,7 +564,7 @@ ieee80211_tx_h_select_key(struct ieee802
1195                 tx->key = key;
1196         else if (ieee80211_is_mgmt(hdr->frame_control) &&
1197                  is_multicast_ether_addr(hdr->addr1) &&
1198 -                ieee80211_is_robust_mgmt_frame(hdr) &&
1199 +                ieee80211_is_robust_mgmt_frame(tx->skb) &&
1200                  (key = rcu_dereference(tx->sdata->default_mgmt_key)))
1201                 tx->key = key;
1202         else if (is_multicast_ether_addr(hdr->addr1) &&
1203 @@ -582,12 +579,12 @@ ieee80211_tx_h_select_key(struct ieee802
1204                 tx->key = NULL;
1205         else if (tx->skb->protocol == tx->sdata->control_port_protocol)
1206                 tx->key = NULL;
1207 -       else if (ieee80211_is_robust_mgmt_frame(hdr) &&
1208 +       else if (ieee80211_is_robust_mgmt_frame(tx->skb) &&
1209                  !(ieee80211_is_action(hdr->frame_control) &&
1210                    tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP)))
1211                 tx->key = NULL;
1212         else if (ieee80211_is_mgmt(hdr->frame_control) &&
1213 -                !ieee80211_is_robust_mgmt_frame(hdr))
1214 +                !ieee80211_is_robust_mgmt_frame(tx->skb))
1215                 tx->key = NULL;
1216         else {
1217                 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
1218 @@ -878,7 +875,7 @@ static int ieee80211_fragment(struct iee
1219         }
1220  
1221         /* adjust first fragment's length */
1222 -       skb->len = hdrlen + per_fragm;
1223 +       skb_trim(skb, hdrlen + per_fragm);
1224         return 0;
1225  }
1226  
1227 --- a/net/mac80211/wpa.c
1228 +++ b/net/mac80211/wpa.c
1229 @@ -499,7 +499,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
1230         hdrlen = ieee80211_hdrlen(hdr->frame_control);
1231  
1232         if (!ieee80211_is_data(hdr->frame_control) &&
1233 -           !ieee80211_is_robust_mgmt_frame(hdr))
1234 +           !ieee80211_is_robust_mgmt_frame(skb))
1235                 return RX_CONTINUE;
1236  
1237         data_len = skb->len - hdrlen - IEEE80211_CCMP_HDR_LEN -
1238 --- a/net/wireless/ap.c
1239 +++ b/net/wireless/ap.c
1240 @@ -27,9 +27,10 @@ static int __cfg80211_stop_ap(struct cfg
1241         err = rdev_stop_ap(rdev, dev);
1242         if (!err) {
1243                 wdev->beacon_interval = 0;
1244 -               wdev->channel = NULL;
1245 +               memset(&wdev->chandef, 0, sizeof(wdev->chandef));
1246                 wdev->ssid_len = 0;
1247                 rdev_set_qos_map(rdev, dev, NULL);
1248 +               nl80211_send_ap_stopped(wdev);
1249         }
1250  
1251         return err;
1252 --- a/net/wireless/core.c
1253 +++ b/net/wireless/core.c
1254 @@ -203,8 +203,11 @@ void cfg80211_stop_p2p_device(struct cfg
1255  
1256         rdev->opencount--;
1257  
1258 -       WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev &&
1259 -               !rdev->scan_req->notified);
1260 +       if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
1261 +               if (WARN_ON(!rdev->scan_req->notified))
1262 +                       rdev->scan_req->aborted = true;
1263 +               ___cfg80211_scan_done(rdev, false);
1264 +       }
1265  }
1266  
1267  static int cfg80211_rfkill_set_block(void *data, bool blocked)
1268 @@ -447,9 +450,6 @@ int wiphy_register(struct wiphy *wiphy)
1269         int i;
1270         u16 ifmodes = wiphy->interface_modes;
1271  
1272 -       /* support for 5/10 MHz is broken due to nl80211 API mess - disable */
1273 -       wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_5_10_MHZ;
1274 -
1275         /*
1276          * There are major locking problems in nl80211/mac80211 for CSA,
1277          * disable for all drivers until this has been reworked.
1278 @@ -875,8 +875,11 @@ static int cfg80211_netdev_notifier_call
1279                 break;
1280         case NETDEV_DOWN:
1281                 cfg80211_update_iface_num(rdev, wdev->iftype, -1);
1282 -               WARN_ON(rdev->scan_req && rdev->scan_req->wdev == wdev &&
1283 -                       !rdev->scan_req->notified);
1284 +               if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
1285 +                       if (WARN_ON(!rdev->scan_req->notified))
1286 +                               rdev->scan_req->aborted = true;
1287 +                       ___cfg80211_scan_done(rdev, false);
1288 +               }
1289  
1290                 if (WARN_ON(rdev->sched_scan_req &&
1291                             rdev->sched_scan_req->dev == wdev->netdev)) {
1292 --- a/net/wireless/core.h
1293 +++ b/net/wireless/core.h
1294 @@ -62,6 +62,7 @@ struct cfg80211_registered_device {
1295         struct rb_root bss_tree;
1296         u32 bss_generation;
1297         struct cfg80211_scan_request *scan_req; /* protected by RTNL */
1298 +       struct sk_buff *scan_msg;
1299         struct cfg80211_sched_scan_request *sched_scan_req;
1300         unsigned long suspend_at;
1301         struct work_struct scan_done_wk;
1302 @@ -210,6 +211,7 @@ struct cfg80211_event {
1303                 } dc;
1304                 struct {
1305                         u8 bssid[ETH_ALEN];
1306 +                       struct ieee80211_channel *channel;
1307                 } ij;
1308         };
1309  };
1310 @@ -257,7 +259,8 @@ int __cfg80211_leave_ibss(struct cfg8021
1311                           struct net_device *dev, bool nowext);
1312  int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
1313                         struct net_device *dev, bool nowext);
1314 -void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
1315 +void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
1316 +                           struct ieee80211_channel *channel);
1317  int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
1318                             struct wireless_dev *wdev);
1319  
1320 @@ -361,7 +364,8 @@ int cfg80211_validate_key_settings(struc
1321                                    struct key_params *params, int key_idx,
1322                                    bool pairwise, const u8 *mac_addr);
1323  void __cfg80211_scan_done(struct work_struct *wk);
1324 -void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev);
1325 +void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
1326 +                          bool send_message);
1327  void __cfg80211_sched_scan_results(struct work_struct *wk);
1328  int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
1329                                bool driver_initiated);
1330 @@ -441,7 +445,8 @@ static inline unsigned int elapsed_jiffi
1331  void
1332  cfg80211_get_chan_state(struct wireless_dev *wdev,
1333                         struct ieee80211_channel **chan,
1334 -                       enum cfg80211_chan_mode *chanmode);
1335 +                       enum cfg80211_chan_mode *chanmode,
1336 +                       u8 *radar_detect);
1337  
1338  int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
1339                                  struct cfg80211_chan_def *chandef);
1340 --- a/net/wireless/nl80211.c
1341 +++ b/net/wireless/nl80211.c
1342 @@ -1723,9 +1723,10 @@ static int nl80211_dump_wiphy(struct sk_
1343                                  * We can then retry with the larger buffer.
1344                                  */
1345                                 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1346 -                                   !skb->len &&
1347 +                                   !skb->len && !state->split &&
1348                                     cb->min_dump_alloc < 4096) {
1349                                         cb->min_dump_alloc = 4096;
1350 +                                       state->split_start = 0;
1351                                         rtnl_unlock();
1352                                         return 1;
1353                                 }
1354 @@ -2047,10 +2048,12 @@ static int nl80211_set_wiphy(struct sk_b
1355                 nla_for_each_nested(nl_txq_params,
1356                                     info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
1357                                     rem_txq_params) {
1358 -                       nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1359 -                                 nla_data(nl_txq_params),
1360 -                                 nla_len(nl_txq_params),
1361 -                                 txq_params_policy);
1362 +                       result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
1363 +                                          nla_data(nl_txq_params),
1364 +                                          nla_len(nl_txq_params),
1365 +                                          txq_params_policy);
1366 +                       if (result)
1367 +                               goto bad_res;
1368                         result = parse_txq_params(tb, &txq_params);
1369                         if (result)
1370                                 goto bad_res;
1371 @@ -3289,7 +3292,7 @@ static int nl80211_start_ap(struct sk_bu
1372         if (!err) {
1373                 wdev->preset_chandef = params.chandef;
1374                 wdev->beacon_interval = params.beacon_interval;
1375 -               wdev->channel = params.chandef.chan;
1376 +               wdev->chandef = params.chandef;
1377                 wdev->ssid_len = params.ssid_len;
1378                 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
1379         }
1380 @@ -5210,9 +5213,11 @@ static int nl80211_set_reg(struct sk_buf
1381  
1382         nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
1383                             rem_reg_rules) {
1384 -               nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
1385 -                         nla_data(nl_reg_rule), nla_len(nl_reg_rule),
1386 -                         reg_rule_policy);
1387 +               r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
1388 +                             nla_data(nl_reg_rule), nla_len(nl_reg_rule),
1389 +                             reg_rule_policy);
1390 +               if (r)
1391 +                       goto bad_reg;
1392                 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
1393                 if (r)
1394                         goto bad_reg;
1395 @@ -5277,7 +5282,7 @@ static int nl80211_trigger_scan(struct s
1396         if (!rdev->ops->scan)
1397                 return -EOPNOTSUPP;
1398  
1399 -       if (rdev->scan_req) {
1400 +       if (rdev->scan_req || rdev->scan_msg) {
1401                 err = -EBUSY;
1402                 goto unlock;
1403         }
1404 @@ -5475,6 +5480,7 @@ static int nl80211_start_sched_scan(stru
1405         enum ieee80211_band band;
1406         size_t ie_len;
1407         struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
1408 +       s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
1409  
1410         if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
1411             !rdev->ops->sched_scan_start)
1412 @@ -5509,11 +5515,40 @@ static int nl80211_start_sched_scan(stru
1413         if (n_ssids > wiphy->max_sched_scan_ssids)
1414                 return -EINVAL;
1415  
1416 -       if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
1417 +       /*
1418 +        * First, count the number of 'real' matchsets. Due to an issue with
1419 +        * the old implementation, matchsets containing only the RSSI attribute
1420 +        * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
1421 +        * RSSI for all matchsets, rather than their own matchset for reporting
1422 +        * all APs with a strong RSSI. This is needed to be compatible with
1423 +        * older userspace that treated a matchset with only the RSSI as the
1424 +        * global RSSI for all other matchsets - if there are other matchsets.
1425 +        */
1426 +       if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
1427                 nla_for_each_nested(attr,
1428                                     info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
1429 -                                   tmp)
1430 -                       n_match_sets++;
1431 +                                   tmp) {
1432 +                       struct nlattr *rssi;
1433 +
1434 +                       err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
1435 +                                       nla_data(attr), nla_len(attr),
1436 +                                       nl80211_match_policy);
1437 +                       if (err)
1438 +                               return err;
1439 +                       /* add other standalone attributes here */
1440 +                       if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
1441 +                               n_match_sets++;
1442 +                               continue;
1443 +                       }
1444 +                       rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
1445 +                       if (rssi)
1446 +                               default_match_rssi = nla_get_s32(rssi);
1447 +               }
1448 +       }
1449 +
1450 +       /* However, if there's no other matchset, add the RSSI one */
1451 +       if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
1452 +               n_match_sets = 1;
1453  
1454         if (n_match_sets > wiphy->max_match_sets)
1455                 return -EINVAL;
1456 @@ -5634,11 +5669,22 @@ static int nl80211_start_sched_scan(stru
1457                                     tmp) {
1458                         struct nlattr *ssid, *rssi;
1459  
1460 -                       nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
1461 -                                 nla_data(attr), nla_len(attr),
1462 -                                 nl80211_match_policy);
1463 +                       err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
1464 +                                       nla_data(attr), nla_len(attr),
1465 +                                       nl80211_match_policy);
1466 +                       if (err)
1467 +                               goto out_free;
1468                         ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
1469                         if (ssid) {
1470 +                               if (WARN_ON(i >= n_match_sets)) {
1471 +                                       /* this indicates a programming error,
1472 +                                        * the loop above should have verified
1473 +                                        * things properly
1474 +                                        */
1475 +                                       err = -EINVAL;
1476 +                                       goto out_free;
1477 +                               }
1478 +
1479                                 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
1480                                         err = -EINVAL;
1481                                         goto out_free;
1482 @@ -5647,15 +5693,28 @@ static int nl80211_start_sched_scan(stru
1483                                        nla_data(ssid), nla_len(ssid));
1484                                 request->match_sets[i].ssid.ssid_len =
1485                                         nla_len(ssid);
1486 +                               /* special attribute - old implemenation w/a */
1487 +                               request->match_sets[i].rssi_thold =
1488 +                                       default_match_rssi;
1489 +                               rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
1490 +                               if (rssi)
1491 +                                       request->match_sets[i].rssi_thold =
1492 +                                               nla_get_s32(rssi);
1493                         }
1494 -                       rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
1495 -                       if (rssi)
1496 -                               request->rssi_thold = nla_get_u32(rssi);
1497 -                       else
1498 -                               request->rssi_thold =
1499 -                                                  NL80211_SCAN_RSSI_THOLD_OFF;
1500                         i++;
1501                 }
1502 +
1503 +               /* there was no other matchset, so the RSSI one is alone */
1504 +               if (i == 0)
1505 +                       request->match_sets[0].rssi_thold = default_match_rssi;
1506 +
1507 +               request->min_rssi_thold = INT_MAX;
1508 +               for (i = 0; i < n_match_sets; i++)
1509 +                       request->min_rssi_thold =
1510 +                               min(request->match_sets[i].rssi_thold,
1511 +                                   request->min_rssi_thold);
1512 +       } else {
1513 +               request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
1514         }
1515  
1516         if (info->attrs[NL80211_ATTR_IE]) {
1517 @@ -5751,7 +5810,7 @@ static int nl80211_start_radar_detection
1518  
1519         err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
1520         if (!err) {
1521 -               wdev->channel = chandef.chan;
1522 +               wdev->chandef = chandef;
1523                 wdev->cac_started = true;
1524                 wdev->cac_start_time = jiffies;
1525         }
1526 @@ -7502,16 +7561,19 @@ static int nl80211_set_tx_bitrate_mask(s
1527          * directly to the enum ieee80211_band values used in cfg80211.
1528          */
1529         BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
1530 -       nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
1531 -       {
1532 +       nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
1533                 enum ieee80211_band band = nla_type(tx_rates);
1534 +               int err;
1535 +
1536                 if (band < 0 || band >= IEEE80211_NUM_BANDS)
1537                         return -EINVAL;
1538                 sband = rdev->wiphy.bands[band];
1539                 if (sband == NULL)
1540                         return -EINVAL;
1541 -               nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
1542 -                         nla_len(tx_rates), nl80211_txattr_policy);
1543 +               err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
1544 +                               nla_len(tx_rates), nl80211_txattr_policy);
1545 +               if (err)
1546 +                       return err;
1547                 if (tb[NL80211_TXRATE_LEGACY]) {
1548                         mask.control[band].legacy = rateset_to_mask(
1549                                 sband,
1550 @@ -10054,40 +10116,31 @@ void nl80211_send_scan_start(struct cfg8
1551                                 NL80211_MCGRP_SCAN, GFP_KERNEL);
1552  }
1553  
1554 -void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
1555 -                           struct wireless_dev *wdev)
1556 +struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
1557 +                                      struct wireless_dev *wdev, bool aborted)
1558  {
1559         struct sk_buff *msg;
1560  
1561         msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1562         if (!msg)
1563 -               return;
1564 +               return NULL;
1565  
1566         if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
1567 -                                 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
1568 +                                 aborted ? NL80211_CMD_SCAN_ABORTED :
1569 +                                           NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
1570                 nlmsg_free(msg);
1571 -               return;
1572 +               return NULL;
1573         }
1574  
1575 -       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
1576 -                               NL80211_MCGRP_SCAN, GFP_KERNEL);
1577 +       return msg;
1578  }
1579  
1580 -void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
1581 -                              struct wireless_dev *wdev)
1582 +void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
1583 +                             struct sk_buff *msg)
1584  {
1585 -       struct sk_buff *msg;
1586 -
1587 -       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1588         if (!msg)
1589                 return;
1590  
1591 -       if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
1592 -                                 NL80211_CMD_SCAN_ABORTED) < 0) {
1593 -               nlmsg_free(msg);
1594 -               return;
1595 -       }
1596 -
1597         genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
1598                                 NL80211_MCGRP_SCAN, GFP_KERNEL);
1599  }
1600 @@ -11158,7 +11211,8 @@ void cfg80211_ch_switch_notify(struct ne
1601                     wdev->iftype != NL80211_IFTYPE_MESH_POINT))
1602                 return;
1603  
1604 -       wdev->channel = chandef->chan;
1605 +       wdev->chandef = *chandef;
1606 +       wdev->preset_chandef = *chandef;
1607         nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
1608  }
1609  EXPORT_SYMBOL(cfg80211_ch_switch_notify);
1610 @@ -11673,6 +11727,35 @@ void cfg80211_crit_proto_stopped(struct 
1611  }
1612  EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
1613  
1614 +void nl80211_send_ap_stopped(struct wireless_dev *wdev)
1615 +{
1616 +       struct wiphy *wiphy = wdev->wiphy;
1617 +       struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
1618 +       struct sk_buff *msg;
1619 +       void *hdr;
1620 +
1621 +       msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1622 +       if (!msg)
1623 +               return;
1624 +
1625 +       hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
1626 +       if (!hdr)
1627 +               goto out;
1628 +
1629 +       if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
1630 +           nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
1631 +           nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
1632 +               goto out;
1633 +
1634 +       genlmsg_end(msg, hdr);
1635 +
1636 +       genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
1637 +                               NL80211_MCGRP_MLME, GFP_KERNEL);
1638 +       return;
1639 + out:
1640 +       nlmsg_free(msg);
1641 +}
1642 +
1643  /* initialisation/exit functions */
1644  
1645  int nl80211_init(void)
1646 --- a/net/wireless/nl80211.h
1647 +++ b/net/wireless/nl80211.h
1648 @@ -8,10 +8,10 @@ void nl80211_exit(void);
1649  void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
1650  void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
1651                              struct wireless_dev *wdev);
1652 -void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
1653 -                           struct wireless_dev *wdev);
1654 -void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
1655 -                              struct wireless_dev *wdev);
1656 +struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
1657 +                                      struct wireless_dev *wdev, bool aborted);
1658 +void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
1659 +                             struct sk_buff *msg);
1660  void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
1661                              struct net_device *netdev, u32 cmd);
1662  void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
1663 @@ -74,6 +74,8 @@ nl80211_radar_notify(struct cfg80211_reg
1664                      enum nl80211_radar_event event,
1665                      struct net_device *netdev, gfp_t gfp);
1666  
1667 +void nl80211_send_ap_stopped(struct wireless_dev *wdev);
1668 +
1669  void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev);
1670  
1671  #endif /* __NET_WIRELESS_NL80211_H */
1672 --- a/net/wireless/scan.c
1673 +++ b/net/wireless/scan.c
1674 @@ -161,18 +161,25 @@ static void __cfg80211_bss_expire(struct
1675                 dev->bss_generation++;
1676  }
1677  
1678 -void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev)
1679 +void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
1680 +                          bool send_message)
1681  {
1682         struct cfg80211_scan_request *request;
1683         struct wireless_dev *wdev;
1684 +       struct sk_buff *msg;
1685  #ifdef CPTCFG_CFG80211_WEXT
1686         union iwreq_data wrqu;
1687  #endif
1688  
1689         ASSERT_RTNL();
1690  
1691 -       request = rdev->scan_req;
1692 +       if (rdev->scan_msg) {
1693 +               nl80211_send_scan_result(rdev, rdev->scan_msg);
1694 +               rdev->scan_msg = NULL;
1695 +               return;
1696 +       }
1697  
1698 +       request = rdev->scan_req;
1699         if (!request)
1700                 return;
1701  
1702 @@ -186,18 +193,16 @@ void ___cfg80211_scan_done(struct cfg802
1703         if (wdev->netdev)
1704                 cfg80211_sme_scan_done(wdev->netdev);
1705  
1706 -       if (request->aborted) {
1707 -               nl80211_send_scan_aborted(rdev, wdev);
1708 -       } else {
1709 -               if (request->flags & NL80211_SCAN_FLAG_FLUSH) {
1710 -                       /* flush entries from previous scans */
1711 -                       spin_lock_bh(&rdev->bss_lock);
1712 -                       __cfg80211_bss_expire(rdev, request->scan_start);
1713 -                       spin_unlock_bh(&rdev->bss_lock);
1714 -               }
1715 -               nl80211_send_scan_done(rdev, wdev);
1716 +       if (!request->aborted &&
1717 +           request->flags & NL80211_SCAN_FLAG_FLUSH) {
1718 +               /* flush entries from previous scans */
1719 +               spin_lock_bh(&rdev->bss_lock);
1720 +               __cfg80211_bss_expire(rdev, request->scan_start);
1721 +               spin_unlock_bh(&rdev->bss_lock);
1722         }
1723  
1724 +       msg = nl80211_build_scan_msg(rdev, wdev, request->aborted);
1725 +
1726  #ifdef CPTCFG_CFG80211_WEXT
1727         if (wdev->netdev && !request->aborted) {
1728                 memset(&wrqu, 0, sizeof(wrqu));
1729 @@ -211,6 +216,11 @@ void ___cfg80211_scan_done(struct cfg802
1730  
1731         rdev->scan_req = NULL;
1732         kfree(request);
1733 +
1734 +       if (!send_message)
1735 +               rdev->scan_msg = msg;
1736 +       else
1737 +               nl80211_send_scan_result(rdev, msg);
1738  }
1739  
1740  void __cfg80211_scan_done(struct work_struct *wk)
1741 @@ -221,7 +231,7 @@ void __cfg80211_scan_done(struct work_st
1742                             scan_done_wk);
1743  
1744         rtnl_lock();
1745 -       ___cfg80211_scan_done(rdev);
1746 +       ___cfg80211_scan_done(rdev, true);
1747         rtnl_unlock();
1748  }
1749  
1750 @@ -1079,7 +1089,7 @@ int cfg80211_wext_siwscan(struct net_dev
1751         if (IS_ERR(rdev))
1752                 return PTR_ERR(rdev);
1753  
1754 -       if (rdev->scan_req) {
1755 +       if (rdev->scan_req || rdev->scan_msg) {
1756                 err = -EBUSY;
1757                 goto out;
1758         }
1759 @@ -1481,7 +1491,7 @@ int cfg80211_wext_giwscan(struct net_dev
1760         if (IS_ERR(rdev))
1761                 return PTR_ERR(rdev);
1762  
1763 -       if (rdev->scan_req)
1764 +       if (rdev->scan_req || rdev->scan_msg)
1765                 return -EAGAIN;
1766  
1767         res = ieee80211_scan_results(rdev, info, extra, data->length);
1768 --- a/net/wireless/sme.c
1769 +++ b/net/wireless/sme.c
1770 @@ -67,7 +67,7 @@ static int cfg80211_conn_scan(struct wir
1771         ASSERT_RDEV_LOCK(rdev);
1772         ASSERT_WDEV_LOCK(wdev);
1773  
1774 -       if (rdev->scan_req)
1775 +       if (rdev->scan_req || rdev->scan_msg)
1776                 return -EBUSY;
1777  
1778         if (wdev->conn->params.channel)
1779 --- a/net/mac80211/mlme.c
1780 +++ b/net/mac80211/mlme.c
1781 @@ -1001,7 +1001,6 @@ ieee80211_sta_process_chanswitch(struct 
1782         }
1783  
1784         ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1785 -       sdata->vif.csa_active = true;
1786  
1787         mutex_lock(&local->chanctx_mtx);
1788         if (local->use_chanctx) {
1789 @@ -1039,6 +1038,7 @@ ieee80211_sta_process_chanswitch(struct 
1790         mutex_unlock(&local->chanctx_mtx);
1791  
1792         sdata->csa_chandef = csa_ie.chandef;
1793 +       sdata->vif.csa_active = true;
1794  
1795         if (csa_ie.mode)
1796                 ieee80211_stop_queues_by_reason(&local->hw,
1797 --- a/net/mac80211/chan.c
1798 +++ b/net/mac80211/chan.c
1799 @@ -196,6 +196,8 @@ static bool ieee80211_is_radar_required(
1800  {
1801         struct ieee80211_sub_if_data *sdata;
1802  
1803 +       lockdep_assert_held(&local->mtx);
1804 +
1805         rcu_read_lock();
1806         list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1807                 if (sdata->radar_required) {
1808 --- a/net/mac80211/ibss.c
1809 +++ b/net/mac80211/ibss.c
1810 @@ -294,7 +294,6 @@ static void __ieee80211_sta_join_ibss(st
1811         }
1812  
1813         mutex_lock(&local->mtx);
1814 -       ieee80211_vif_release_channel(sdata);
1815         if (ieee80211_vif_use_channel(sdata, &chandef,
1816                                       ifibss->fixed_channel ?
1817                                         IEEE80211_CHANCTX_SHARED :
1818 @@ -303,6 +302,7 @@ static void __ieee80211_sta_join_ibss(st
1819                 mutex_unlock(&local->mtx);
1820                 return;
1821         }
1822 +       sdata->radar_required = radar_required;
1823         mutex_unlock(&local->mtx);
1824  
1825         memcpy(ifibss->bssid, bssid, ETH_ALEN);
1826 @@ -318,7 +318,6 @@ static void __ieee80211_sta_join_ibss(st
1827         rcu_assign_pointer(ifibss->presp, presp);
1828         mgmt = (void *)presp->head;
1829  
1830 -       sdata->radar_required = radar_required;
1831         sdata->vif.bss_conf.enable_beacon = true;
1832         sdata->vif.bss_conf.beacon_int = beacon_int;
1833         sdata->vif.bss_conf.basic_rates = basic_rates;
1834 @@ -386,7 +385,7 @@ static void __ieee80211_sta_join_ibss(st
1835                                               presp->head_len, 0, GFP_KERNEL);
1836         cfg80211_put_bss(local->hw.wiphy, bss);
1837         netif_carrier_on(sdata->dev);
1838 -       cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
1839 +       cfg80211_ibss_joined(sdata->dev, ifibss->bssid, chan, GFP_KERNEL);
1840  }
1841  
1842  static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
1843 @@ -802,6 +801,8 @@ ieee80211_ibss_process_chanswitch(struct
1844         int err;
1845         u32 sta_flags;
1846  
1847 +       sdata_assert_lock(sdata);
1848 +
1849         sta_flags = IEEE80211_STA_DISABLE_VHT;
1850         switch (ifibss->chandef.width) {
1851         case NL80211_CHAN_WIDTH_5:
1852 @@ -1471,6 +1472,11 @@ static void ieee80211_rx_mgmt_probe_req(
1853         memcpy(((struct ieee80211_mgmt *) skb->data)->da, mgmt->sa, ETH_ALEN);
1854         ibss_dbg(sdata, "Sending ProbeResp to %pM\n", mgmt->sa);
1855         IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1856 +
1857 +       /* avoid excessive retries for probe request to wildcard SSIDs */
1858 +       if (pos[1] == 0)
1859 +               IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_NO_ACK;
1860 +
1861         ieee80211_tx_skb(sdata, skb);
1862  }
1863  
1864 --- a/net/mac80211/mesh.c
1865 +++ b/net/mac80211/mesh.c
1866 @@ -872,6 +872,8 @@ ieee80211_mesh_process_chnswitch(struct 
1867         if (!ifmsh->mesh_id)
1868                 return false;
1869  
1870 +       sdata_assert_lock(sdata);
1871 +
1872         sta_flags = IEEE80211_STA_DISABLE_VHT;
1873         switch (sdata->vif.bss_conf.chandef.width) {
1874         case NL80211_CHAN_WIDTH_20_NOHT:
1875 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
1876 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
1877 @@ -4658,6 +4658,7 @@ brcmf_notify_connect_status(struct brcmf
1878         struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1879         struct net_device *ndev = ifp->ndev;
1880         struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
1881 +       struct ieee80211_channel *chan;
1882         s32 err = 0;
1883  
1884         if (ifp->vif->mode == WL_MODE_AP) {
1885 @@ -4665,9 +4666,10 @@ brcmf_notify_connect_status(struct brcmf
1886         } else if (brcmf_is_linkup(e)) {
1887                 brcmf_dbg(CONN, "Linkup\n");
1888                 if (brcmf_is_ibssmode(ifp->vif)) {
1889 +                       chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
1890                         memcpy(profile->bssid, e->addr, ETH_ALEN);
1891                         wl_inform_ibss(cfg, ndev, e->addr);
1892 -                       cfg80211_ibss_joined(ndev, e->addr, GFP_KERNEL);
1893 +                       cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
1894                         clear_bit(BRCMF_VIF_STATUS_CONNECTING,
1895                                   &ifp->vif->sme_state);
1896                         set_bit(BRCMF_VIF_STATUS_CONNECTED,
1897 --- a/drivers/net/wireless/libertas/cfg.c
1898 +++ b/drivers/net/wireless/libertas/cfg.c
1899 @@ -1766,7 +1766,8 @@ static void lbs_join_post(struct lbs_pri
1900         memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1901         priv->wdev->ssid_len = params->ssid_len;
1902  
1903 -       cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1904 +       cfg80211_ibss_joined(priv->dev, bssid, params->chandef.chan,
1905 +                            GFP_KERNEL);
1906  
1907         /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1908         priv->connect_status = LBS_CONNECTED;
1909 --- a/drivers/net/wireless/mwifiex/cfg80211.c
1910 +++ b/drivers/net/wireless/mwifiex/cfg80211.c
1911 @@ -1881,7 +1881,8 @@ mwifiex_cfg80211_join_ibss(struct wiphy 
1912                                      params->privacy);
1913  done:
1914         if (!ret) {
1915 -               cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, GFP_KERNEL);
1916 +               cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid,
1917 +                                    params->chandef.chan, GFP_KERNEL);
1918                 dev_dbg(priv->adapter->dev,
1919                         "info: joined/created adhoc network with bssid"
1920                         " %pM successfully\n", priv->cfg_bssid);
1921 --- a/drivers/net/wireless/rndis_wlan.c
1922 +++ b/drivers/net/wireless/rndis_wlan.c
1923 @@ -2835,7 +2835,9 @@ static void rndis_wlan_do_link_up_work(s
1924                                         bssid, req_ie, req_ie_len,
1925                                         resp_ie, resp_ie_len, GFP_KERNEL);
1926         } else if (priv->infra_mode == NDIS_80211_INFRA_ADHOC)
1927 -               cfg80211_ibss_joined(usbdev->net, bssid, GFP_KERNEL);
1928 +               cfg80211_ibss_joined(usbdev->net, bssid,
1929 +                                    get_current_channel(usbdev, NULL),
1930 +                                    GFP_KERNEL);
1931  
1932         kfree(info);
1933  
1934 --- a/net/wireless/ibss.c
1935 +++ b/net/wireless/ibss.c
1936 @@ -14,7 +14,8 @@
1937  #include "rdev-ops.h"
1938  
1939  
1940 -void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid)
1941 +void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
1942 +                           struct ieee80211_channel *channel)
1943  {
1944         struct wireless_dev *wdev = dev->ieee80211_ptr;
1945         struct cfg80211_bss *bss;
1946 @@ -28,8 +29,7 @@ void __cfg80211_ibss_joined(struct net_d
1947         if (!wdev->ssid_len)
1948                 return;
1949  
1950 -       bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
1951 -                              wdev->ssid, wdev->ssid_len,
1952 +       bss = cfg80211_get_bss(wdev->wiphy, channel, bssid, NULL, 0,
1953                                WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1954  
1955         if (WARN_ON(!bss))
1956 @@ -54,21 +54,26 @@ void __cfg80211_ibss_joined(struct net_d
1957  #endif
1958  }
1959  
1960 -void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
1961 +void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
1962 +                         struct ieee80211_channel *channel, gfp_t gfp)
1963  {
1964         struct wireless_dev *wdev = dev->ieee80211_ptr;
1965         struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
1966         struct cfg80211_event *ev;
1967         unsigned long flags;
1968  
1969 -       trace_cfg80211_ibss_joined(dev, bssid);
1970 +       trace_cfg80211_ibss_joined(dev, bssid, channel);
1971 +
1972 +       if (WARN_ON(!channel))
1973 +               return;
1974  
1975         ev = kzalloc(sizeof(*ev), gfp);
1976         if (!ev)
1977                 return;
1978  
1979         ev->type = EVENT_IBSS_JOINED;
1980 -       memcpy(ev->cr.bssid, bssid, ETH_ALEN);
1981 +       memcpy(ev->ij.bssid, bssid, ETH_ALEN);
1982 +       ev->ij.channel = channel;
1983  
1984         spin_lock_irqsave(&wdev->event_lock, flags);
1985         list_add_tail(&ev->list, &wdev->event_list);
1986 @@ -117,6 +122,7 @@ int __cfg80211_join_ibss(struct cfg80211
1987  
1988         wdev->ibss_fixed = params->channel_fixed;
1989         wdev->ibss_dfs_possible = params->userspace_handles_dfs;
1990 +       wdev->chandef = params->chandef;
1991  #ifdef CPTCFG_CFG80211_WEXT
1992         wdev->wext.ibss.chandef = params->chandef;
1993  #endif
1994 @@ -200,6 +206,7 @@ static void __cfg80211_clear_ibss(struct
1995  
1996         wdev->current_bss = NULL;
1997         wdev->ssid_len = 0;
1998 +       memset(&wdev->chandef, 0, sizeof(wdev->chandef));
1999  #ifdef CPTCFG_CFG80211_WEXT
2000         if (!nowext)
2001                 wdev->wext.ibss.ssid_len = 0;
2002 --- a/net/wireless/trace.h
2003 +++ b/net/wireless/trace.h
2004 @@ -2278,11 +2278,6 @@ DECLARE_EVENT_CLASS(cfg80211_rx_evt,
2005         TP_printk(NETDEV_PR_FMT ", " MAC_PR_FMT, NETDEV_PR_ARG, MAC_PR_ARG(addr))
2006  );
2007  
2008 -DEFINE_EVENT(cfg80211_rx_evt, cfg80211_ibss_joined,
2009 -       TP_PROTO(struct net_device *netdev, const u8 *addr),
2010 -       TP_ARGS(netdev, addr)
2011 -);
2012 -
2013  DEFINE_EVENT(cfg80211_rx_evt, cfg80211_rx_spurious_frame,
2014         TP_PROTO(struct net_device *netdev, const u8 *addr),
2015         TP_ARGS(netdev, addr)
2016 @@ -2293,6 +2288,24 @@ DEFINE_EVENT(cfg80211_rx_evt, cfg80211_r
2017         TP_ARGS(netdev, addr)
2018  );
2019  
2020 +TRACE_EVENT(cfg80211_ibss_joined,
2021 +       TP_PROTO(struct net_device *netdev, const u8 *bssid,
2022 +                struct ieee80211_channel *channel),
2023 +       TP_ARGS(netdev, bssid, channel),
2024 +       TP_STRUCT__entry(
2025 +               NETDEV_ENTRY
2026 +               MAC_ENTRY(bssid)
2027 +               CHAN_ENTRY
2028 +       ),
2029 +       TP_fast_assign(
2030 +               NETDEV_ASSIGN;
2031 +               MAC_ASSIGN(bssid, bssid);
2032 +               CHAN_ASSIGN(channel);
2033 +       ),
2034 +       TP_printk(NETDEV_PR_FMT ", bssid: " MAC_PR_FMT ", " CHAN_PR_FMT,
2035 +                 NETDEV_PR_ARG, MAC_PR_ARG(bssid), CHAN_PR_ARG)
2036 +);
2037 +
2038  TRACE_EVENT(cfg80211_probe_status,
2039         TP_PROTO(struct net_device *netdev, const u8 *addr, u64 cookie,
2040                  bool acked),
2041 --- a/net/wireless/util.c
2042 +++ b/net/wireless/util.c
2043 @@ -820,7 +820,8 @@ void cfg80211_process_wdev_events(struct
2044                                                 ev->dc.reason, true);
2045                         break;
2046                 case EVENT_IBSS_JOINED:
2047 -                       __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
2048 +                       __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid,
2049 +                                              ev->ij.channel);
2050                         break;
2051                 }
2052                 wdev_unlock(wdev);
2053 @@ -1356,7 +1357,7 @@ int cfg80211_can_use_iftype_chan(struct 
2054                  */
2055                 mutex_lock_nested(&wdev_iter->mtx, 1);
2056                 __acquire(wdev_iter->mtx);
2057 -               cfg80211_get_chan_state(wdev_iter, &ch, &chmode);
2058 +               cfg80211_get_chan_state(wdev_iter, &ch, &chmode, &radar_detect);
2059                 wdev_unlock(wdev_iter);
2060  
2061                 switch (chmode) {
2062 --- a/net/wireless/chan.c
2063 +++ b/net/wireless/chan.c
2064 @@ -642,7 +642,8 @@ int cfg80211_set_monitor_channel(struct 
2065  void
2066  cfg80211_get_chan_state(struct wireless_dev *wdev,
2067                         struct ieee80211_channel **chan,
2068 -                       enum cfg80211_chan_mode *chanmode)
2069 +                       enum cfg80211_chan_mode *chanmode,
2070 +                       u8 *radar_detect)
2071  {
2072         *chan = NULL;
2073         *chanmode = CHAN_MODE_UNDEFINED;
2074 @@ -660,6 +661,11 @@ cfg80211_get_chan_state(struct wireless_
2075                                      !wdev->ibss_dfs_possible)
2076                                   ? CHAN_MODE_SHARED
2077                                   : CHAN_MODE_EXCLUSIVE;
2078 +
2079 +                       /* consider worst-case - IBSS can try to return to the
2080 +                        * original user-specified channel as creator */
2081 +                       if (wdev->ibss_dfs_possible)
2082 +                               *radar_detect |= BIT(wdev->chandef.width);
2083                         return;
2084                 }
2085                 break;
2086 @@ -674,17 +680,26 @@ cfg80211_get_chan_state(struct wireless_
2087         case NL80211_IFTYPE_AP:
2088         case NL80211_IFTYPE_P2P_GO:
2089                 if (wdev->cac_started) {
2090 -                       *chan = wdev->channel;
2091 +                       *chan = wdev->chandef.chan;
2092                         *chanmode = CHAN_MODE_SHARED;
2093 +                       *radar_detect |= BIT(wdev->chandef.width);
2094                 } else if (wdev->beacon_interval) {
2095 -                       *chan = wdev->channel;
2096 +                       *chan = wdev->chandef.chan;
2097                         *chanmode = CHAN_MODE_SHARED;
2098 +
2099 +                       if (cfg80211_chandef_dfs_required(wdev->wiphy,
2100 +                                                         &wdev->chandef))
2101 +                               *radar_detect |= BIT(wdev->chandef.width);
2102                 }
2103                 return;
2104         case NL80211_IFTYPE_MESH_POINT:
2105                 if (wdev->mesh_id_len) {
2106 -                       *chan = wdev->channel;
2107 +                       *chan = wdev->chandef.chan;
2108                         *chanmode = CHAN_MODE_SHARED;
2109 +
2110 +                       if (cfg80211_chandef_dfs_required(wdev->wiphy,
2111 +                                                         &wdev->chandef))
2112 +                               *radar_detect |= BIT(wdev->chandef.width);
2113                 }
2114                 return;
2115         case NL80211_IFTYPE_MONITOR:
2116 --- a/net/wireless/mesh.c
2117 +++ b/net/wireless/mesh.c
2118 @@ -195,7 +195,7 @@ int __cfg80211_join_mesh(struct cfg80211
2119         if (!err) {
2120                 memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
2121                 wdev->mesh_id_len = setup->mesh_id_len;
2122 -               wdev->channel = setup->chandef.chan;
2123 +               wdev->chandef = setup->chandef;
2124         }
2125  
2126         return err;
2127 @@ -244,7 +244,7 @@ int cfg80211_set_mesh_channel(struct cfg
2128                 err = rdev_libertas_set_mesh_channel(rdev, wdev->netdev,
2129                                                      chandef->chan);
2130                 if (!err)
2131 -                       wdev->channel = chandef->chan;
2132 +                       wdev->chandef = *chandef;
2133  
2134                 return err;
2135         }
2136 @@ -276,7 +276,7 @@ static int __cfg80211_leave_mesh(struct 
2137         err = rdev_leave_mesh(rdev, dev);
2138         if (!err) {
2139                 wdev->mesh_id_len = 0;
2140 -               wdev->channel = NULL;
2141 +               memset(&wdev->chandef, 0, sizeof(wdev->chandef));
2142                 rdev_set_qos_map(rdev, dev, NULL);
2143         }
2144  
2145 --- a/net/wireless/mlme.c
2146 +++ b/net/wireless/mlme.c
2147 @@ -772,7 +772,7 @@ void cfg80211_cac_event(struct net_devic
2148         if (WARN_ON(!wdev->cac_started))
2149                 return;
2150  
2151 -       if (WARN_ON(!wdev->channel))
2152 +       if (WARN_ON(!wdev->chandef.chan))
2153                 return;
2154  
2155         switch (event) {
2156 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
2157 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
2158 @@ -5065,6 +5065,10 @@ static u16 ar9003_hw_get_max_edge_power(
2159                         break;
2160                 }
2161         }
2162 +
2163 +       if (is2GHz && !twiceMaxEdgePower)
2164 +               twiceMaxEdgePower = 60;
2165 +
2166         return twiceMaxEdgePower;
2167  }
2168