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