Commit | Line | Data |
---|---|---|
c2d1560a JB |
1 | /* |
2 | * Copyright 2002-2005, Instant802 Networks, Inc. | |
3 | * Copyright 2005-2006, Devicescape Software, Inc. | |
4 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> | |
5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * utilities for mac80211 | |
12 | */ | |
13 | ||
14 | #include <net/mac80211.h> | |
15 | #include <linux/netdevice.h> | |
bc3b2d7f | 16 | #include <linux/export.h> |
c2d1560a JB |
17 | #include <linux/types.h> |
18 | #include <linux/slab.h> | |
19 | #include <linux/skbuff.h> | |
20 | #include <linux/etherdevice.h> | |
21 | #include <linux/if_arp.h> | |
c2d1560a | 22 | #include <linux/bitmap.h> |
dd76986b | 23 | #include <linux/crc32.h> |
881d966b | 24 | #include <net/net_namespace.h> |
c2d1560a | 25 | #include <net/cfg80211.h> |
dabeb344 | 26 | #include <net/rtnetlink.h> |
c2d1560a JB |
27 | |
28 | #include "ieee80211_i.h" | |
24487981 | 29 | #include "driver-ops.h" |
2c8dccc7 | 30 | #include "rate.h" |
ee385855 | 31 | #include "mesh.h" |
c2d1560a | 32 | #include "wme.h" |
f2753ddb | 33 | #include "led.h" |
fffd0934 | 34 | #include "wep.h" |
c2d1560a JB |
35 | |
36 | /* privid for wiphys to determine whether they belong to us or not */ | |
8a47cea7 | 37 | const void *const mac80211_wiphy_privid = &mac80211_wiphy_privid; |
c2d1560a | 38 | |
9a95371a LR |
39 | struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) |
40 | { | |
41 | struct ieee80211_local *local; | |
42 | BUG_ON(!wiphy); | |
43 | ||
44 | local = wiphy_priv(wiphy); | |
45 | return &local->hw; | |
46 | } | |
47 | EXPORT_SYMBOL(wiphy_to_ieee80211_hw); | |
c2d1560a | 48 | |
71364716 | 49 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
05c914fe | 50 | enum nl80211_iftype type) |
c2d1560a | 51 | { |
a494bb1c | 52 | __le16 fc = hdr->frame_control; |
c2d1560a | 53 | |
98f0b0a3 RR |
54 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
55 | if (len < 16) | |
c2d1560a JB |
56 | return NULL; |
57 | ||
a494bb1c | 58 | if (ieee80211_is_data(fc)) { |
98f0b0a3 RR |
59 | if (len < 24) /* drop incorrect hdr len (data) */ |
60 | return NULL; | |
a494bb1c HH |
61 | |
62 | if (ieee80211_has_a4(fc)) | |
c2d1560a | 63 | return NULL; |
a494bb1c HH |
64 | if (ieee80211_has_tods(fc)) |
65 | return hdr->addr1; | |
66 | if (ieee80211_has_fromds(fc)) | |
c2d1560a | 67 | return hdr->addr2; |
a494bb1c HH |
68 | |
69 | return hdr->addr3; | |
70 | } | |
71 | ||
72 | if (ieee80211_is_mgmt(fc)) { | |
98f0b0a3 RR |
73 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
74 | return NULL; | |
c2d1560a | 75 | return hdr->addr3; |
a494bb1c HH |
76 | } |
77 | ||
78 | if (ieee80211_is_ctl(fc)) { | |
f359d3fe | 79 | if (ieee80211_is_pspoll(fc)) |
c2d1560a | 80 | return hdr->addr1; |
a494bb1c HH |
81 | |
82 | if (ieee80211_is_back_req(fc)) { | |
71364716 | 83 | switch (type) { |
05c914fe | 84 | case NL80211_IFTYPE_STATION: |
71364716 | 85 | return hdr->addr2; |
05c914fe JB |
86 | case NL80211_IFTYPE_AP: |
87 | case NL80211_IFTYPE_AP_VLAN: | |
71364716 RR |
88 | return hdr->addr1; |
89 | default: | |
a494bb1c | 90 | break; /* fall through to the return */ |
71364716 RR |
91 | } |
92 | } | |
c2d1560a JB |
93 | } |
94 | ||
95 | return NULL; | |
96 | } | |
97 | ||
5cf121c3 | 98 | void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) |
c2d1560a | 99 | { |
252b86c4 | 100 | struct sk_buff *skb; |
2de8e0d9 JB |
101 | struct ieee80211_hdr *hdr; |
102 | ||
252b86c4 | 103 | skb_queue_walk(&tx->skbs, skb) { |
2de8e0d9 JB |
104 | hdr = (struct ieee80211_hdr *) skb->data; |
105 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
252b86c4 | 106 | } |
c2d1560a JB |
107 | } |
108 | ||
4ee73f33 | 109 | int ieee80211_frame_duration(enum ieee80211_band band, size_t len, |
438b61b7 SW |
110 | int rate, int erp, int short_preamble, |
111 | int shift) | |
c2d1560a JB |
112 | { |
113 | int dur; | |
114 | ||
115 | /* calculate duration (in microseconds, rounded up to next higher | |
116 | * integer if it includes a fractional microsecond) to send frame of | |
117 | * len bytes (does not include FCS) at the given rate. Duration will | |
118 | * also include SIFS. | |
119 | * | |
120 | * rate is in 100 kbps, so divident is multiplied by 10 in the | |
121 | * DIV_ROUND_UP() operations. | |
438b61b7 SW |
122 | * |
123 | * shift may be 2 for 5 MHz channels or 1 for 10 MHz channels, and | |
124 | * is assumed to be 0 otherwise. | |
c2d1560a JB |
125 | */ |
126 | ||
4ee73f33 | 127 | if (band == IEEE80211_BAND_5GHZ || erp) { |
c2d1560a JB |
128 | /* |
129 | * OFDM: | |
130 | * | |
131 | * N_DBPS = DATARATE x 4 | |
132 | * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) | |
133 | * (16 = SIGNAL time, 6 = tail bits) | |
134 | * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext | |
135 | * | |
136 | * T_SYM = 4 usec | |
438b61b7 | 137 | * 802.11a - 18.5.2: aSIFSTime = 16 usec |
c2d1560a JB |
138 | * 802.11g - 19.8.4: aSIFSTime = 10 usec + |
139 | * signal ext = 6 usec | |
140 | */ | |
c2d1560a | 141 | dur = 16; /* SIFS + signal ext */ |
438b61b7 SW |
142 | dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */ |
143 | dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */ | |
438b61b7 SW |
144 | |
145 | /* IEEE 802.11-2012 18.3.2.4: all values above are: | |
146 | * * times 4 for 5 MHz | |
147 | * * times 2 for 10 MHz | |
148 | */ | |
149 | dur *= 1 << shift; | |
2103dec1 SW |
150 | |
151 | /* rates should already consider the channel bandwidth, | |
152 | * don't apply divisor again. | |
153 | */ | |
154 | dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, | |
155 | 4 * rate); /* T_SYM x N_SYM */ | |
c2d1560a JB |
156 | } else { |
157 | /* | |
158 | * 802.11b or 802.11g with 802.11b compatibility: | |
159 | * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + | |
160 | * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. | |
161 | * | |
162 | * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 | |
163 | * aSIFSTime = 10 usec | |
164 | * aPreambleLength = 144 usec or 72 usec with short preamble | |
165 | * aPLCPHeaderLength = 48 usec or 24 usec with short preamble | |
166 | */ | |
167 | dur = 10; /* aSIFSTime = 10 usec */ | |
168 | dur += short_preamble ? (72 + 24) : (144 + 48); | |
169 | ||
170 | dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); | |
171 | } | |
172 | ||
173 | return dur; | |
174 | } | |
175 | ||
176 | /* Exported duration function for driver use */ | |
32bfd35d JB |
177 | __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, |
178 | struct ieee80211_vif *vif, | |
4ee73f33 | 179 | enum ieee80211_band band, |
8318d78a JB |
180 | size_t frame_len, |
181 | struct ieee80211_rate *rate) | |
c2d1560a | 182 | { |
25d834e1 | 183 | struct ieee80211_sub_if_data *sdata; |
c2d1560a | 184 | u16 dur; |
438b61b7 | 185 | int erp, shift = 0; |
25d834e1 | 186 | bool short_preamble = false; |
c2d1560a | 187 | |
8318d78a | 188 | erp = 0; |
25d834e1 JB |
189 | if (vif) { |
190 | sdata = vif_to_sdata(vif); | |
bda3933a | 191 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
192 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
193 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
438b61b7 | 194 | shift = ieee80211_vif_get_shift(vif); |
25d834e1 | 195 | } |
8318d78a | 196 | |
4ee73f33 | 197 | dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp, |
438b61b7 | 198 | short_preamble, shift); |
c2d1560a JB |
199 | |
200 | return cpu_to_le16(dur); | |
201 | } | |
202 | EXPORT_SYMBOL(ieee80211_generic_frame_duration); | |
203 | ||
32bfd35d JB |
204 | __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, |
205 | struct ieee80211_vif *vif, size_t frame_len, | |
e039fa4a | 206 | const struct ieee80211_tx_info *frame_txctl) |
c2d1560a JB |
207 | { |
208 | struct ieee80211_local *local = hw_to_local(hw); | |
209 | struct ieee80211_rate *rate; | |
25d834e1 | 210 | struct ieee80211_sub_if_data *sdata; |
471b3efd | 211 | bool short_preamble; |
2103dec1 | 212 | int erp, shift = 0, bitrate; |
c2d1560a | 213 | u16 dur; |
2e92e6f2 JB |
214 | struct ieee80211_supported_band *sband; |
215 | ||
4ee73f33 | 216 | sband = local->hw.wiphy->bands[frame_txctl->band]; |
c2d1560a | 217 | |
25d834e1 | 218 | short_preamble = false; |
7e9ed188 | 219 | |
e039fa4a | 220 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
8318d78a JB |
221 | |
222 | erp = 0; | |
25d834e1 JB |
223 | if (vif) { |
224 | sdata = vif_to_sdata(vif); | |
bda3933a | 225 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
226 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
227 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
438b61b7 | 228 | shift = ieee80211_vif_get_shift(vif); |
25d834e1 | 229 | } |
c2d1560a | 230 | |
2103dec1 SW |
231 | bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift); |
232 | ||
c2d1560a | 233 | /* CTS duration */ |
2103dec1 | 234 | dur = ieee80211_frame_duration(sband->band, 10, bitrate, |
438b61b7 | 235 | erp, short_preamble, shift); |
c2d1560a | 236 | /* Data frame duration */ |
2103dec1 | 237 | dur += ieee80211_frame_duration(sband->band, frame_len, bitrate, |
438b61b7 | 238 | erp, short_preamble, shift); |
c2d1560a | 239 | /* ACK duration */ |
2103dec1 | 240 | dur += ieee80211_frame_duration(sband->band, 10, bitrate, |
438b61b7 | 241 | erp, short_preamble, shift); |
c2d1560a JB |
242 | |
243 | return cpu_to_le16(dur); | |
244 | } | |
245 | EXPORT_SYMBOL(ieee80211_rts_duration); | |
246 | ||
32bfd35d JB |
247 | __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, |
248 | struct ieee80211_vif *vif, | |
c2d1560a | 249 | size_t frame_len, |
e039fa4a | 250 | const struct ieee80211_tx_info *frame_txctl) |
c2d1560a JB |
251 | { |
252 | struct ieee80211_local *local = hw_to_local(hw); | |
253 | struct ieee80211_rate *rate; | |
25d834e1 | 254 | struct ieee80211_sub_if_data *sdata; |
471b3efd | 255 | bool short_preamble; |
2103dec1 | 256 | int erp, shift = 0, bitrate; |
c2d1560a | 257 | u16 dur; |
2e92e6f2 JB |
258 | struct ieee80211_supported_band *sband; |
259 | ||
4ee73f33 | 260 | sband = local->hw.wiphy->bands[frame_txctl->band]; |
c2d1560a | 261 | |
25d834e1 | 262 | short_preamble = false; |
7e9ed188 | 263 | |
e039fa4a | 264 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
8318d78a | 265 | erp = 0; |
25d834e1 JB |
266 | if (vif) { |
267 | sdata = vif_to_sdata(vif); | |
bda3933a | 268 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
269 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
270 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
438b61b7 | 271 | shift = ieee80211_vif_get_shift(vif); |
25d834e1 | 272 | } |
c2d1560a | 273 | |
2103dec1 SW |
274 | bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift); |
275 | ||
c2d1560a | 276 | /* Data frame duration */ |
2103dec1 | 277 | dur = ieee80211_frame_duration(sband->band, frame_len, bitrate, |
438b61b7 | 278 | erp, short_preamble, shift); |
e039fa4a | 279 | if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { |
c2d1560a | 280 | /* ACK duration */ |
2103dec1 | 281 | dur += ieee80211_frame_duration(sband->band, 10, bitrate, |
438b61b7 | 282 | erp, short_preamble, shift); |
c2d1560a JB |
283 | } |
284 | ||
285 | return cpu_to_le16(dur); | |
286 | } | |
287 | EXPORT_SYMBOL(ieee80211_ctstoself_duration); | |
288 | ||
3a25a8c8 JB |
289 | void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue) |
290 | { | |
291 | struct ieee80211_sub_if_data *sdata; | |
a6f38ac3 JB |
292 | int n_acs = IEEE80211_NUM_ACS; |
293 | ||
294 | if (local->hw.queues < IEEE80211_NUM_ACS) | |
295 | n_acs = 1; | |
3a25a8c8 JB |
296 | |
297 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
298 | int ac; | |
299 | ||
f142c6b9 JB |
300 | if (!sdata->dev) |
301 | continue; | |
302 | ||
3a25a8c8 JB |
303 | if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE && |
304 | local->queue_stop_reasons[sdata->vif.cab_queue] != 0) | |
305 | continue; | |
306 | ||
a6f38ac3 | 307 | for (ac = 0; ac < n_acs; ac++) { |
3a25a8c8 JB |
308 | int ac_queue = sdata->vif.hw_queue[ac]; |
309 | ||
310 | if (ac_queue == queue || | |
311 | (sdata->vif.cab_queue == queue && | |
312 | local->queue_stop_reasons[ac_queue] == 0 && | |
313 | skb_queue_empty(&local->pending[ac_queue]))) | |
314 | netif_wake_subqueue(sdata->dev, ac); | |
315 | } | |
316 | } | |
317 | } | |
318 | ||
ce7c9111 | 319 | static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, |
cca07b00 LC |
320 | enum queue_stop_reason reason, |
321 | bool refcounted) | |
c2d1560a JB |
322 | { |
323 | struct ieee80211_local *local = hw_to_local(hw); | |
324 | ||
b5878a2d JB |
325 | trace_wake_queue(local, queue, reason); |
326 | ||
e4e72fb4 JB |
327 | if (WARN_ON(queue >= hw->queues)) |
328 | return; | |
ce7c9111 | 329 | |
ada15125 JB |
330 | if (!test_bit(reason, &local->queue_stop_reasons[queue])) |
331 | return; | |
332 | ||
cca07b00 LC |
333 | if (!refcounted) |
334 | local->q_stop_reasons[queue][reason] = 0; | |
335 | else | |
336 | local->q_stop_reasons[queue][reason]--; | |
337 | ||
338 | if (local->q_stop_reasons[queue][reason] == 0) | |
339 | __clear_bit(reason, &local->queue_stop_reasons[queue]); | |
96f5e66e JB |
340 | |
341 | if (local->queue_stop_reasons[queue] != 0) | |
342 | /* someone still has this queue stopped */ | |
343 | return; | |
344 | ||
7236fe29 JB |
345 | if (skb_queue_empty(&local->pending[queue])) { |
346 | rcu_read_lock(); | |
3a25a8c8 | 347 | ieee80211_propagate_queue_wake(local, queue); |
7236fe29 JB |
348 | rcu_read_unlock(); |
349 | } else | |
3b8d81e0 | 350 | tasklet_schedule(&local->tx_pending_tasklet); |
c2d1560a | 351 | } |
ce7c9111 | 352 | |
96f5e66e | 353 | void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, |
cca07b00 LC |
354 | enum queue_stop_reason reason, |
355 | bool refcounted) | |
ce7c9111 KV |
356 | { |
357 | struct ieee80211_local *local = hw_to_local(hw); | |
358 | unsigned long flags; | |
359 | ||
360 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
cca07b00 | 361 | __ieee80211_wake_queue(hw, queue, reason, refcounted); |
ce7c9111 KV |
362 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
363 | } | |
364 | ||
365 | void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) | |
366 | { | |
367 | ieee80211_wake_queue_by_reason(hw, queue, | |
cca07b00 LC |
368 | IEEE80211_QUEUE_STOP_REASON_DRIVER, |
369 | false); | |
ce7c9111 | 370 | } |
c2d1560a JB |
371 | EXPORT_SYMBOL(ieee80211_wake_queue); |
372 | ||
ce7c9111 | 373 | static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, |
cca07b00 LC |
374 | enum queue_stop_reason reason, |
375 | bool refcounted) | |
c2d1560a JB |
376 | { |
377 | struct ieee80211_local *local = hw_to_local(hw); | |
cf0277e7 | 378 | struct ieee80211_sub_if_data *sdata; |
a6f38ac3 | 379 | int n_acs = IEEE80211_NUM_ACS; |
c2d1560a | 380 | |
b5878a2d JB |
381 | trace_stop_queue(local, queue, reason); |
382 | ||
e4e72fb4 JB |
383 | if (WARN_ON(queue >= hw->queues)) |
384 | return; | |
96f5e66e | 385 | |
cca07b00 LC |
386 | if (!refcounted) |
387 | local->q_stop_reasons[queue][reason] = 1; | |
388 | else | |
389 | local->q_stop_reasons[queue][reason]++; | |
ada15125 | 390 | |
cca07b00 LC |
391 | if (__test_and_set_bit(reason, &local->queue_stop_reasons[queue])) |
392 | return; | |
cf0277e7 | 393 | |
a6f38ac3 JB |
394 | if (local->hw.queues < IEEE80211_NUM_ACS) |
395 | n_acs = 1; | |
396 | ||
cf0277e7 | 397 | rcu_read_lock(); |
3a25a8c8 JB |
398 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
399 | int ac; | |
400 | ||
f142c6b9 JB |
401 | if (!sdata->dev) |
402 | continue; | |
403 | ||
a6f38ac3 | 404 | for (ac = 0; ac < n_acs; ac++) { |
3a25a8c8 JB |
405 | if (sdata->vif.hw_queue[ac] == queue || |
406 | sdata->vif.cab_queue == queue) | |
407 | netif_stop_subqueue(sdata->dev, ac); | |
408 | } | |
409 | } | |
cf0277e7 | 410 | rcu_read_unlock(); |
c2d1560a | 411 | } |
ce7c9111 | 412 | |
96f5e66e | 413 | void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, |
cca07b00 LC |
414 | enum queue_stop_reason reason, |
415 | bool refcounted) | |
ce7c9111 KV |
416 | { |
417 | struct ieee80211_local *local = hw_to_local(hw); | |
418 | unsigned long flags; | |
419 | ||
420 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
cca07b00 | 421 | __ieee80211_stop_queue(hw, queue, reason, refcounted); |
ce7c9111 KV |
422 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
423 | } | |
424 | ||
425 | void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) | |
426 | { | |
427 | ieee80211_stop_queue_by_reason(hw, queue, | |
cca07b00 LC |
428 | IEEE80211_QUEUE_STOP_REASON_DRIVER, |
429 | false); | |
ce7c9111 | 430 | } |
c2d1560a JB |
431 | EXPORT_SYMBOL(ieee80211_stop_queue); |
432 | ||
8f77f384 JB |
433 | void ieee80211_add_pending_skb(struct ieee80211_local *local, |
434 | struct sk_buff *skb) | |
435 | { | |
436 | struct ieee80211_hw *hw = &local->hw; | |
437 | unsigned long flags; | |
a7bc376c | 438 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
3a25a8c8 | 439 | int queue = info->hw_queue; |
a7bc376c JB |
440 | |
441 | if (WARN_ON(!info->control.vif)) { | |
d4fa14cd | 442 | ieee80211_free_txskb(&local->hw, skb); |
a7bc376c JB |
443 | return; |
444 | } | |
8f77f384 JB |
445 | |
446 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
cca07b00 LC |
447 | __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD, |
448 | false); | |
3b8d81e0 | 449 | __skb_queue_tail(&local->pending[queue], skb); |
cca07b00 LC |
450 | __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD, |
451 | false); | |
8f77f384 JB |
452 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
453 | } | |
454 | ||
e3685e03 JB |
455 | void ieee80211_add_pending_skbs(struct ieee80211_local *local, |
456 | struct sk_buff_head *skbs) | |
8f77f384 JB |
457 | { |
458 | struct ieee80211_hw *hw = &local->hw; | |
459 | struct sk_buff *skb; | |
460 | unsigned long flags; | |
b0b97a8a | 461 | int queue, i; |
8f77f384 JB |
462 | |
463 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
8f77f384 | 464 | while ((skb = skb_dequeue(skbs))) { |
a7bc376c JB |
465 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
466 | ||
467 | if (WARN_ON(!info->control.vif)) { | |
d4fa14cd | 468 | ieee80211_free_txskb(&local->hw, skb); |
a7bc376c JB |
469 | continue; |
470 | } | |
471 | ||
3a25a8c8 | 472 | queue = info->hw_queue; |
4644ae89 JB |
473 | |
474 | __ieee80211_stop_queue(hw, queue, | |
cca07b00 LC |
475 | IEEE80211_QUEUE_STOP_REASON_SKB_ADD, |
476 | false); | |
4644ae89 | 477 | |
3b8d81e0 | 478 | __skb_queue_tail(&local->pending[queue], skb); |
8f77f384 JB |
479 | } |
480 | ||
3b8d81e0 | 481 | for (i = 0; i < hw->queues; i++) |
8f77f384 | 482 | __ieee80211_wake_queue(hw, i, |
cca07b00 LC |
483 | IEEE80211_QUEUE_STOP_REASON_SKB_ADD, |
484 | false); | |
8f77f384 | 485 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
8f77f384 JB |
486 | } |
487 | ||
ce7c9111 | 488 | void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, |
445ea4e8 | 489 | unsigned long queues, |
cca07b00 LC |
490 | enum queue_stop_reason reason, |
491 | bool refcounted) | |
c2d1560a | 492 | { |
ce7c9111 KV |
493 | struct ieee80211_local *local = hw_to_local(hw); |
494 | unsigned long flags; | |
c2d1560a JB |
495 | int i; |
496 | ||
ce7c9111 KV |
497 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
498 | ||
445ea4e8 | 499 | for_each_set_bit(i, &queues, hw->queues) |
cca07b00 | 500 | __ieee80211_stop_queue(hw, i, reason, refcounted); |
ce7c9111 KV |
501 | |
502 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
503 | } | |
504 | ||
505 | void ieee80211_stop_queues(struct ieee80211_hw *hw) | |
506 | { | |
445ea4e8 | 507 | ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP, |
cca07b00 LC |
508 | IEEE80211_QUEUE_STOP_REASON_DRIVER, |
509 | false); | |
c2d1560a JB |
510 | } |
511 | EXPORT_SYMBOL(ieee80211_stop_queues); | |
512 | ||
92ab8535 TW |
513 | int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) |
514 | { | |
515 | struct ieee80211_local *local = hw_to_local(hw); | |
3b8d81e0 JB |
516 | unsigned long flags; |
517 | int ret; | |
96f5e66e | 518 | |
e4e72fb4 JB |
519 | if (WARN_ON(queue >= hw->queues)) |
520 | return true; | |
96f5e66e | 521 | |
3b8d81e0 | 522 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
2419ea14 TP |
523 | ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER, |
524 | &local->queue_stop_reasons[queue]); | |
3b8d81e0 JB |
525 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
526 | return ret; | |
92ab8535 TW |
527 | } |
528 | EXPORT_SYMBOL(ieee80211_queue_stopped); | |
529 | ||
ce7c9111 | 530 | void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, |
445ea4e8 | 531 | unsigned long queues, |
cca07b00 LC |
532 | enum queue_stop_reason reason, |
533 | bool refcounted) | |
c2d1560a | 534 | { |
ce7c9111 KV |
535 | struct ieee80211_local *local = hw_to_local(hw); |
536 | unsigned long flags; | |
c2d1560a JB |
537 | int i; |
538 | ||
ce7c9111 KV |
539 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
540 | ||
445ea4e8 | 541 | for_each_set_bit(i, &queues, hw->queues) |
cca07b00 | 542 | __ieee80211_wake_queue(hw, i, reason, refcounted); |
ce7c9111 KV |
543 | |
544 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
545 | } | |
546 | ||
547 | void ieee80211_wake_queues(struct ieee80211_hw *hw) | |
548 | { | |
445ea4e8 | 549 | ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP, |
cca07b00 LC |
550 | IEEE80211_QUEUE_STOP_REASON_DRIVER, |
551 | false); | |
c2d1560a JB |
552 | } |
553 | EXPORT_SYMBOL(ieee80211_wake_queues); | |
dabeb344 | 554 | |
39ecc01d JB |
555 | void ieee80211_flush_queues(struct ieee80211_local *local, |
556 | struct ieee80211_sub_if_data *sdata) | |
557 | { | |
558 | u32 queues; | |
559 | ||
560 | if (!local->ops->flush) | |
561 | return; | |
562 | ||
563 | if (sdata && local->hw.flags & IEEE80211_HW_QUEUE_CONTROL) { | |
564 | int ac; | |
565 | ||
566 | queues = 0; | |
567 | ||
568 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) | |
569 | queues |= BIT(sdata->vif.hw_queue[ac]); | |
570 | if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE) | |
571 | queues |= BIT(sdata->vif.cab_queue); | |
572 | } else { | |
573 | /* all queues */ | |
574 | queues = BIT(local->hw.queues) - 1; | |
575 | } | |
576 | ||
59f48fe2 | 577 | ieee80211_stop_queues_by_reason(&local->hw, queues, |
cca07b00 LC |
578 | IEEE80211_QUEUE_STOP_REASON_FLUSH, |
579 | false); | |
445ea4e8 | 580 | |
77be2c54 | 581 | drv_flush(local, sdata, queues, false); |
445ea4e8 | 582 | |
59f48fe2 | 583 | ieee80211_wake_queues_by_reason(&local->hw, queues, |
cca07b00 LC |
584 | IEEE80211_QUEUE_STOP_REASON_FLUSH, |
585 | false); | |
39ecc01d JB |
586 | } |
587 | ||
c7c71066 JB |
588 | static void __iterate_active_interfaces(struct ieee80211_local *local, |
589 | u32 iter_flags, | |
590 | void (*iterator)(void *data, u8 *mac, | |
591 | struct ieee80211_vif *vif), | |
592 | void *data) | |
dabeb344 | 593 | { |
dabeb344 JB |
594 | struct ieee80211_sub_if_data *sdata; |
595 | ||
c7c71066 | 596 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
2f561feb | 597 | switch (sdata->vif.type) { |
05c914fe | 598 | case NL80211_IFTYPE_MONITOR: |
31eba5bc FF |
599 | if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE)) |
600 | continue; | |
601 | break; | |
05c914fe | 602 | case NL80211_IFTYPE_AP_VLAN: |
2f561feb | 603 | continue; |
2ca27bcf | 604 | default: |
2f561feb ID |
605 | break; |
606 | } | |
8b2c9824 JB |
607 | if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) && |
608 | !(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) | |
609 | continue; | |
9607e6b6 | 610 | if (ieee80211_sdata_running(sdata)) |
47846c9b | 611 | iterator(data, sdata->vif.addr, |
2f561feb ID |
612 | &sdata->vif); |
613 | } | |
614 | ||
c7c71066 JB |
615 | sdata = rcu_dereference_check(local->monitor_sdata, |
616 | lockdep_is_held(&local->iflist_mtx) || | |
617 | lockdep_rtnl_is_held()); | |
8b2c9824 JB |
618 | if (sdata && |
619 | (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL || | |
620 | sdata->flags & IEEE80211_SDATA_IN_DRIVER)) | |
685fb72b | 621 | iterator(data, sdata->vif.addr, &sdata->vif); |
c7c71066 | 622 | } |
685fb72b | 623 | |
c7c71066 JB |
624 | void ieee80211_iterate_active_interfaces( |
625 | struct ieee80211_hw *hw, u32 iter_flags, | |
626 | void (*iterator)(void *data, u8 *mac, | |
627 | struct ieee80211_vif *vif), | |
628 | void *data) | |
629 | { | |
630 | struct ieee80211_local *local = hw_to_local(hw); | |
631 | ||
632 | mutex_lock(&local->iflist_mtx); | |
633 | __iterate_active_interfaces(local, iter_flags, iterator, data); | |
c771c9d8 | 634 | mutex_unlock(&local->iflist_mtx); |
2f561feb ID |
635 | } |
636 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); | |
637 | ||
638 | void ieee80211_iterate_active_interfaces_atomic( | |
8b2c9824 | 639 | struct ieee80211_hw *hw, u32 iter_flags, |
2f561feb ID |
640 | void (*iterator)(void *data, u8 *mac, |
641 | struct ieee80211_vif *vif), | |
642 | void *data) | |
643 | { | |
644 | struct ieee80211_local *local = hw_to_local(hw); | |
2f561feb | 645 | |
e38bad47 | 646 | rcu_read_lock(); |
c7c71066 JB |
647 | __iterate_active_interfaces(local, iter_flags, iterator, data); |
648 | rcu_read_unlock(); | |
649 | } | |
650 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); | |
dabeb344 | 651 | |
c7c71066 JB |
652 | void ieee80211_iterate_active_interfaces_rtnl( |
653 | struct ieee80211_hw *hw, u32 iter_flags, | |
654 | void (*iterator)(void *data, u8 *mac, | |
655 | struct ieee80211_vif *vif), | |
656 | void *data) | |
657 | { | |
658 | struct ieee80211_local *local = hw_to_local(hw); | |
e38bad47 | 659 | |
c7c71066 | 660 | ASSERT_RTNL(); |
685fb72b | 661 | |
c7c71066 | 662 | __iterate_active_interfaces(local, iter_flags, iterator, data); |
dabeb344 | 663 | } |
c7c71066 | 664 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_rtnl); |
37ffc8da | 665 | |
ad7e718c JB |
666 | struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev) |
667 | { | |
668 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
669 | ||
670 | if (!ieee80211_sdata_running(sdata) || | |
671 | !(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) | |
672 | return NULL; | |
673 | return &sdata->vif; | |
674 | } | |
675 | EXPORT_SYMBOL_GPL(wdev_to_ieee80211_vif); | |
676 | ||
42935eca LR |
677 | /* |
678 | * Nothing should have been stuffed into the workqueue during | |
679 | * the suspend->resume cycle. If this WARN is seen then there | |
680 | * is a bug with either the driver suspend or something in | |
681 | * mac80211 stuffing into the workqueue which we haven't yet | |
682 | * cleared during mac80211's suspend cycle. | |
683 | */ | |
684 | static bool ieee80211_can_queue_work(struct ieee80211_local *local) | |
685 | { | |
ceb99fe0 JB |
686 | if (WARN(local->suspended && !local->resuming, |
687 | "queueing ieee80211 work while going to suspend\n")) | |
688 | return false; | |
42935eca LR |
689 | |
690 | return true; | |
691 | } | |
692 | ||
693 | void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work) | |
694 | { | |
695 | struct ieee80211_local *local = hw_to_local(hw); | |
696 | ||
697 | if (!ieee80211_can_queue_work(local)) | |
698 | return; | |
699 | ||
700 | queue_work(local->workqueue, work); | |
701 | } | |
702 | EXPORT_SYMBOL(ieee80211_queue_work); | |
703 | ||
704 | void ieee80211_queue_delayed_work(struct ieee80211_hw *hw, | |
705 | struct delayed_work *dwork, | |
706 | unsigned long delay) | |
707 | { | |
708 | struct ieee80211_local *local = hw_to_local(hw); | |
709 | ||
710 | if (!ieee80211_can_queue_work(local)) | |
711 | return; | |
712 | ||
713 | queue_delayed_work(local->workqueue, dwork, delay); | |
714 | } | |
715 | EXPORT_SYMBOL(ieee80211_queue_delayed_work); | |
716 | ||
35d865af | 717 | u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, |
dd76986b JB |
718 | struct ieee802_11_elems *elems, |
719 | u64 filter, u32 crc) | |
720 | { | |
721 | size_t left = len; | |
35d865af | 722 | const u8 *pos = start; |
dd76986b | 723 | bool calc_crc = filter != 0; |
fcff4f10 | 724 | DECLARE_BITMAP(seen_elems, 256); |
b2e506bf | 725 | const u8 *ie; |
dd76986b | 726 | |
fcff4f10 | 727 | bitmap_zero(seen_elems, 256); |
dd76986b JB |
728 | memset(elems, 0, sizeof(*elems)); |
729 | elems->ie_start = start; | |
730 | elems->total_len = len; | |
731 | ||
732 | while (left >= 2) { | |
733 | u8 id, elen; | |
fcff4f10 | 734 | bool elem_parse_failed; |
dd76986b JB |
735 | |
736 | id = *pos++; | |
737 | elen = *pos++; | |
738 | left -= 2; | |
739 | ||
fcff4f10 PS |
740 | if (elen > left) { |
741 | elems->parse_error = true; | |
dd76986b | 742 | break; |
fcff4f10 PS |
743 | } |
744 | ||
9690fb16 JB |
745 | switch (id) { |
746 | case WLAN_EID_SSID: | |
747 | case WLAN_EID_SUPP_RATES: | |
748 | case WLAN_EID_FH_PARAMS: | |
749 | case WLAN_EID_DS_PARAMS: | |
750 | case WLAN_EID_CF_PARAMS: | |
751 | case WLAN_EID_TIM: | |
752 | case WLAN_EID_IBSS_PARAMS: | |
753 | case WLAN_EID_CHALLENGE: | |
754 | case WLAN_EID_RSN: | |
755 | case WLAN_EID_ERP_INFO: | |
756 | case WLAN_EID_EXT_SUPP_RATES: | |
757 | case WLAN_EID_HT_CAPABILITY: | |
758 | case WLAN_EID_HT_OPERATION: | |
759 | case WLAN_EID_VHT_CAPABILITY: | |
760 | case WLAN_EID_VHT_OPERATION: | |
761 | case WLAN_EID_MESH_ID: | |
762 | case WLAN_EID_MESH_CONFIG: | |
763 | case WLAN_EID_PEER_MGMT: | |
764 | case WLAN_EID_PREQ: | |
765 | case WLAN_EID_PREP: | |
766 | case WLAN_EID_PERR: | |
767 | case WLAN_EID_RANN: | |
768 | case WLAN_EID_CHANNEL_SWITCH: | |
769 | case WLAN_EID_EXT_CHANSWITCH_ANN: | |
770 | case WLAN_EID_COUNTRY: | |
771 | case WLAN_EID_PWR_CONSTRAINT: | |
772 | case WLAN_EID_TIMEOUT_INTERVAL: | |
85220d71 | 773 | case WLAN_EID_SECONDARY_CHANNEL_OFFSET: |
b2e506bf | 774 | case WLAN_EID_WIDE_BW_CHANNEL_SWITCH: |
8f2535b9 | 775 | case WLAN_EID_CHAN_SWITCH_PARAM: |
b2e506bf JB |
776 | /* |
777 | * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible | |
778 | * that if the content gets bigger it might be needed more than once | |
779 | */ | |
9690fb16 JB |
780 | if (test_bit(id, seen_elems)) { |
781 | elems->parse_error = true; | |
782 | left -= elen; | |
783 | pos += elen; | |
784 | continue; | |
785 | } | |
786 | break; | |
fcff4f10 | 787 | } |
dd76986b JB |
788 | |
789 | if (calc_crc && id < 64 && (filter & (1ULL << id))) | |
790 | crc = crc32_be(crc, pos - 2, elen + 2); | |
791 | ||
fcff4f10 PS |
792 | elem_parse_failed = false; |
793 | ||
dd76986b JB |
794 | switch (id) { |
795 | case WLAN_EID_SSID: | |
796 | elems->ssid = pos; | |
797 | elems->ssid_len = elen; | |
798 | break; | |
799 | case WLAN_EID_SUPP_RATES: | |
800 | elems->supp_rates = pos; | |
801 | elems->supp_rates_len = elen; | |
802 | break; | |
dd76986b | 803 | case WLAN_EID_DS_PARAMS: |
1cd8e88e JB |
804 | if (elen >= 1) |
805 | elems->ds_params = pos; | |
806 | else | |
807 | elem_parse_failed = true; | |
dd76986b | 808 | break; |
dd76986b JB |
809 | case WLAN_EID_TIM: |
810 | if (elen >= sizeof(struct ieee80211_tim_ie)) { | |
811 | elems->tim = (void *)pos; | |
812 | elems->tim_len = elen; | |
fcff4f10 PS |
813 | } else |
814 | elem_parse_failed = true; | |
dd76986b | 815 | break; |
dd76986b JB |
816 | case WLAN_EID_CHALLENGE: |
817 | elems->challenge = pos; | |
818 | elems->challenge_len = elen; | |
819 | break; | |
820 | case WLAN_EID_VENDOR_SPECIFIC: | |
821 | if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && | |
822 | pos[2] == 0xf2) { | |
823 | /* Microsoft OUI (00:50:F2) */ | |
824 | ||
825 | if (calc_crc) | |
826 | crc = crc32_be(crc, pos - 2, elen + 2); | |
827 | ||
441a33ba | 828 | if (elen >= 5 && pos[3] == 2) { |
dd76986b JB |
829 | /* OUI Type 2 - WMM IE */ |
830 | if (pos[4] == 0) { | |
831 | elems->wmm_info = pos; | |
832 | elems->wmm_info_len = elen; | |
833 | } else if (pos[4] == 1) { | |
834 | elems->wmm_param = pos; | |
835 | elems->wmm_param_len = elen; | |
836 | } | |
837 | } | |
838 | } | |
839 | break; | |
840 | case WLAN_EID_RSN: | |
841 | elems->rsn = pos; | |
842 | elems->rsn_len = elen; | |
843 | break; | |
844 | case WLAN_EID_ERP_INFO: | |
1946bed9 JB |
845 | if (elen >= 1) |
846 | elems->erp_info = pos; | |
847 | else | |
848 | elem_parse_failed = true; | |
dd76986b JB |
849 | break; |
850 | case WLAN_EID_EXT_SUPP_RATES: | |
851 | elems->ext_supp_rates = pos; | |
852 | elems->ext_supp_rates_len = elen; | |
853 | break; | |
854 | case WLAN_EID_HT_CAPABILITY: | |
855 | if (elen >= sizeof(struct ieee80211_ht_cap)) | |
856 | elems->ht_cap_elem = (void *)pos; | |
fcff4f10 PS |
857 | else |
858 | elem_parse_failed = true; | |
dd76986b | 859 | break; |
074d46d1 JB |
860 | case WLAN_EID_HT_OPERATION: |
861 | if (elen >= sizeof(struct ieee80211_ht_operation)) | |
862 | elems->ht_operation = (void *)pos; | |
fcff4f10 PS |
863 | else |
864 | elem_parse_failed = true; | |
dd76986b | 865 | break; |
818255ea MP |
866 | case WLAN_EID_VHT_CAPABILITY: |
867 | if (elen >= sizeof(struct ieee80211_vht_cap)) | |
868 | elems->vht_cap_elem = (void *)pos; | |
869 | else | |
870 | elem_parse_failed = true; | |
871 | break; | |
872 | case WLAN_EID_VHT_OPERATION: | |
873 | if (elen >= sizeof(struct ieee80211_vht_operation)) | |
874 | elems->vht_operation = (void *)pos; | |
875 | else | |
876 | elem_parse_failed = true; | |
877 | break; | |
bee7f586 JB |
878 | case WLAN_EID_OPMODE_NOTIF: |
879 | if (elen > 0) | |
880 | elems->opmode_notif = pos; | |
881 | else | |
882 | elem_parse_failed = true; | |
883 | break; | |
dd76986b JB |
884 | case WLAN_EID_MESH_ID: |
885 | elems->mesh_id = pos; | |
886 | elems->mesh_id_len = elen; | |
887 | break; | |
888 | case WLAN_EID_MESH_CONFIG: | |
889 | if (elen >= sizeof(struct ieee80211_meshconf_ie)) | |
890 | elems->mesh_config = (void *)pos; | |
fcff4f10 PS |
891 | else |
892 | elem_parse_failed = true; | |
dd76986b JB |
893 | break; |
894 | case WLAN_EID_PEER_MGMT: | |
895 | elems->peering = pos; | |
896 | elems->peering_len = elen; | |
897 | break; | |
3f52b7e3 MP |
898 | case WLAN_EID_MESH_AWAKE_WINDOW: |
899 | if (elen >= 2) | |
900 | elems->awake_window = (void *)pos; | |
901 | break; | |
dd76986b JB |
902 | case WLAN_EID_PREQ: |
903 | elems->preq = pos; | |
904 | elems->preq_len = elen; | |
905 | break; | |
906 | case WLAN_EID_PREP: | |
907 | elems->prep = pos; | |
908 | elems->prep_len = elen; | |
909 | break; | |
910 | case WLAN_EID_PERR: | |
911 | elems->perr = pos; | |
912 | elems->perr_len = elen; | |
913 | break; | |
914 | case WLAN_EID_RANN: | |
915 | if (elen >= sizeof(struct ieee80211_rann_ie)) | |
916 | elems->rann = (void *)pos; | |
fcff4f10 PS |
917 | else |
918 | elem_parse_failed = true; | |
dd76986b JB |
919 | break; |
920 | case WLAN_EID_CHANNEL_SWITCH: | |
5bc1420b JB |
921 | if (elen != sizeof(struct ieee80211_channel_sw_ie)) { |
922 | elem_parse_failed = true; | |
923 | break; | |
924 | } | |
925 | elems->ch_switch_ie = (void *)pos; | |
dd76986b | 926 | break; |
b4f286a1 JB |
927 | case WLAN_EID_EXT_CHANSWITCH_ANN: |
928 | if (elen != sizeof(struct ieee80211_ext_chansw_ie)) { | |
929 | elem_parse_failed = true; | |
930 | break; | |
931 | } | |
932 | elems->ext_chansw_ie = (void *)pos; | |
933 | break; | |
85220d71 JB |
934 | case WLAN_EID_SECONDARY_CHANNEL_OFFSET: |
935 | if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) { | |
936 | elem_parse_failed = true; | |
937 | break; | |
938 | } | |
939 | elems->sec_chan_offs = (void *)pos; | |
940 | break; | |
8f2535b9 CYY |
941 | case WLAN_EID_CHAN_SWITCH_PARAM: |
942 | if (elen != | |
943 | sizeof(*elems->mesh_chansw_params_ie)) { | |
944 | elem_parse_failed = true; | |
945 | break; | |
946 | } | |
947 | elems->mesh_chansw_params_ie = (void *)pos; | |
948 | break; | |
b2e506bf JB |
949 | case WLAN_EID_WIDE_BW_CHANNEL_SWITCH: |
950 | if (!action || | |
951 | elen != sizeof(*elems->wide_bw_chansw_ie)) { | |
952 | elem_parse_failed = true; | |
953 | break; | |
954 | } | |
955 | elems->wide_bw_chansw_ie = (void *)pos; | |
956 | break; | |
957 | case WLAN_EID_CHANNEL_SWITCH_WRAPPER: | |
958 | if (action) { | |
959 | elem_parse_failed = true; | |
960 | break; | |
961 | } | |
962 | /* | |
963 | * This is a bit tricky, but as we only care about | |
964 | * the wide bandwidth channel switch element, so | |
965 | * just parse it out manually. | |
966 | */ | |
967 | ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH, | |
968 | pos, elen); | |
969 | if (ie) { | |
970 | if (ie[1] == sizeof(*elems->wide_bw_chansw_ie)) | |
971 | elems->wide_bw_chansw_ie = | |
972 | (void *)(ie + 2); | |
973 | else | |
974 | elem_parse_failed = true; | |
975 | } | |
976 | break; | |
dd76986b JB |
977 | case WLAN_EID_COUNTRY: |
978 | elems->country_elem = pos; | |
979 | elems->country_elem_len = elen; | |
980 | break; | |
981 | case WLAN_EID_PWR_CONSTRAINT: | |
761a48d2 JB |
982 | if (elen != 1) { |
983 | elem_parse_failed = true; | |
984 | break; | |
985 | } | |
dd76986b | 986 | elems->pwr_constr_elem = pos; |
dd76986b JB |
987 | break; |
988 | case WLAN_EID_TIMEOUT_INTERVAL: | |
79ba1d89 JB |
989 | if (elen >= sizeof(struct ieee80211_timeout_interval_ie)) |
990 | elems->timeout_int = (void *)pos; | |
991 | else | |
992 | elem_parse_failed = true; | |
dd76986b JB |
993 | break; |
994 | default: | |
995 | break; | |
996 | } | |
997 | ||
fcff4f10 PS |
998 | if (elem_parse_failed) |
999 | elems->parse_error = true; | |
1000 | else | |
5df45690 | 1001 | __set_bit(id, seen_elems); |
fcff4f10 | 1002 | |
dd76986b JB |
1003 | left -= elen; |
1004 | pos += elen; | |
1005 | } | |
1006 | ||
fcff4f10 PS |
1007 | if (left != 0) |
1008 | elems->parse_error = true; | |
1009 | ||
dd76986b JB |
1010 | return crc; |
1011 | } | |
1012 | ||
3abead59 JB |
1013 | void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata, |
1014 | bool bss_notify) | |
5825fe10 JB |
1015 | { |
1016 | struct ieee80211_local *local = sdata->local; | |
1017 | struct ieee80211_tx_queue_params qparam; | |
55de908a | 1018 | struct ieee80211_chanctx_conf *chanctx_conf; |
54bcbc69 | 1019 | int ac; |
a8ce8544 | 1020 | bool use_11b, enable_qos; |
aa837e1d | 1021 | int aCWmin, aCWmax; |
5825fe10 JB |
1022 | |
1023 | if (!local->ops->conf_tx) | |
1024 | return; | |
1025 | ||
54bcbc69 JB |
1026 | if (local->hw.queues < IEEE80211_NUM_ACS) |
1027 | return; | |
1028 | ||
5825fe10 JB |
1029 | memset(&qparam, 0, sizeof(qparam)); |
1030 | ||
55de908a JB |
1031 | rcu_read_lock(); |
1032 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); | |
1033 | use_11b = (chanctx_conf && | |
4bf88530 | 1034 | chanctx_conf->def.chan->band == IEEE80211_BAND_2GHZ) && |
aa837e1d | 1035 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE); |
55de908a | 1036 | rcu_read_unlock(); |
5825fe10 | 1037 | |
a8ce8544 SG |
1038 | /* |
1039 | * By default disable QoS in STA mode for old access points, which do | |
1040 | * not support 802.11e. New APs will provide proper queue parameters, | |
1041 | * that we will configure later. | |
1042 | */ | |
1043 | enable_qos = (sdata->vif.type != NL80211_IFTYPE_STATION); | |
1044 | ||
1f4ffde8 FZ |
1045 | /* Set defaults according to 802.11-2007 Table 7-37 */ |
1046 | aCWmax = 1023; | |
1047 | if (use_11b) | |
1048 | aCWmin = 31; | |
1049 | else | |
1050 | aCWmin = 15; | |
1051 | ||
1052 | /* Confiure old 802.11b/g medium access rules. */ | |
1053 | qparam.cw_max = aCWmax; | |
1054 | qparam.cw_min = aCWmin; | |
1055 | qparam.txop = 0; | |
1056 | qparam.aifs = 2; | |
aa837e1d | 1057 | |
1f4ffde8 FZ |
1058 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
1059 | /* Update if QoS is enabled. */ | |
a8ce8544 SG |
1060 | if (enable_qos) { |
1061 | switch (ac) { | |
1062 | case IEEE80211_AC_BK: | |
1063 | qparam.cw_max = aCWmax; | |
1064 | qparam.cw_min = aCWmin; | |
1065 | qparam.txop = 0; | |
1066 | qparam.aifs = 7; | |
1067 | break; | |
1068 | /* never happens but let's not leave undefined */ | |
1069 | default: | |
1070 | case IEEE80211_AC_BE: | |
1071 | qparam.cw_max = aCWmax; | |
1072 | qparam.cw_min = aCWmin; | |
1073 | qparam.txop = 0; | |
1074 | qparam.aifs = 3; | |
1075 | break; | |
1076 | case IEEE80211_AC_VI: | |
1077 | qparam.cw_max = aCWmin; | |
1078 | qparam.cw_min = (aCWmin + 1) / 2 - 1; | |
1079 | if (use_11b) | |
1080 | qparam.txop = 6016/32; | |
1081 | else | |
1082 | qparam.txop = 3008/32; | |
1083 | qparam.aifs = 2; | |
1084 | break; | |
1085 | case IEEE80211_AC_VO: | |
1086 | qparam.cw_max = (aCWmin + 1) / 2 - 1; | |
1087 | qparam.cw_min = (aCWmin + 1) / 4 - 1; | |
1088 | if (use_11b) | |
1089 | qparam.txop = 3264/32; | |
1090 | else | |
1091 | qparam.txop = 1504/32; | |
1092 | qparam.aifs = 2; | |
1093 | break; | |
1094 | } | |
aa837e1d | 1095 | } |
5825fe10 | 1096 | |
ab13315a KV |
1097 | qparam.uapsd = false; |
1098 | ||
54bcbc69 JB |
1099 | sdata->tx_conf[ac] = qparam; |
1100 | drv_conf_tx(local, sdata, ac, &qparam); | |
aa837e1d | 1101 | } |
e1b3ec1a | 1102 | |
f142c6b9 JB |
1103 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR && |
1104 | sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE) { | |
a8ce8544 | 1105 | sdata->vif.bss_conf.qos = enable_qos; |
3abead59 JB |
1106 | if (bss_notify) |
1107 | ieee80211_bss_info_change_notify(sdata, | |
1108 | BSS_CHANGED_QOS); | |
d9734979 | 1109 | } |
5825fe10 | 1110 | } |
e50db65c | 1111 | |
46900298 | 1112 | void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, |
700e8ea6 | 1113 | u16 transaction, u16 auth_alg, u16 status, |
4a3cb702 | 1114 | const u8 *extra, size_t extra_len, const u8 *da, |
1672c0e3 JB |
1115 | const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx, |
1116 | u32 tx_flags) | |
46900298 JB |
1117 | { |
1118 | struct ieee80211_local *local = sdata->local; | |
1119 | struct sk_buff *skb; | |
1120 | struct ieee80211_mgmt *mgmt; | |
fffd0934 | 1121 | int err; |
46900298 | 1122 | |
15e230ab FZ |
1123 | /* 24 + 6 = header + auth_algo + auth_transaction + status_code */ |
1124 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 6 + extra_len); | |
d15b8459 | 1125 | if (!skb) |
46900298 | 1126 | return; |
d15b8459 | 1127 | |
46900298 JB |
1128 | skb_reserve(skb, local->hw.extra_tx_headroom); |
1129 | ||
1130 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); | |
1131 | memset(mgmt, 0, 24 + 6); | |
1132 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
1133 | IEEE80211_STYPE_AUTH); | |
efa6a09d | 1134 | memcpy(mgmt->da, da, ETH_ALEN); |
47846c9b | 1135 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
46900298 JB |
1136 | memcpy(mgmt->bssid, bssid, ETH_ALEN); |
1137 | mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); | |
1138 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); | |
700e8ea6 | 1139 | mgmt->u.auth.status_code = cpu_to_le16(status); |
46900298 JB |
1140 | if (extra) |
1141 | memcpy(skb_put(skb, extra_len), extra, extra_len); | |
46900298 | 1142 | |
fffd0934 JB |
1143 | if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) { |
1144 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
1145 | err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx); | |
1146 | WARN_ON(err); | |
1147 | } | |
1148 | ||
1672c0e3 JB |
1149 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | |
1150 | tx_flags; | |
62ae67be | 1151 | ieee80211_tx_skb(sdata, skb); |
46900298 JB |
1152 | } |
1153 | ||
6ae16775 AQ |
1154 | void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, |
1155 | const u8 *bssid, u16 stype, u16 reason, | |
1156 | bool send_frame, u8 *frame_buf) | |
1157 | { | |
1158 | struct ieee80211_local *local = sdata->local; | |
1159 | struct sk_buff *skb; | |
1160 | struct ieee80211_mgmt *mgmt = (void *)frame_buf; | |
1161 | ||
1162 | /* build frame */ | |
1163 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); | |
1164 | mgmt->duration = 0; /* initialize only */ | |
1165 | mgmt->seq_ctrl = 0; /* initialize only */ | |
1166 | memcpy(mgmt->da, bssid, ETH_ALEN); | |
1167 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); | |
1168 | memcpy(mgmt->bssid, bssid, ETH_ALEN); | |
1169 | /* u.deauth.reason_code == u.disassoc.reason_code */ | |
1170 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); | |
1171 | ||
1172 | if (send_frame) { | |
1173 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
1174 | IEEE80211_DEAUTH_FRAME_LEN); | |
1175 | if (!skb) | |
1176 | return; | |
1177 | ||
1178 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1179 | ||
1180 | /* copy in frame */ | |
1181 | memcpy(skb_put(skb, IEEE80211_DEAUTH_FRAME_LEN), | |
1182 | mgmt, IEEE80211_DEAUTH_FRAME_LEN); | |
1183 | ||
1184 | if (sdata->vif.type != NL80211_IFTYPE_STATION || | |
1185 | !(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED)) | |
1186 | IEEE80211_SKB_CB(skb)->flags |= | |
1187 | IEEE80211_TX_INTFL_DONT_ENCRYPT; | |
1188 | ||
1189 | ieee80211_tx_skb(sdata, skb); | |
1190 | } | |
1191 | } | |
1192 | ||
de95a54b | 1193 | int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, |
c604b9f2 | 1194 | size_t buffer_len, const u8 *ie, size_t ie_len, |
651b5225 | 1195 | enum ieee80211_band band, u32 rate_mask, |
2103dec1 | 1196 | struct cfg80211_chan_def *chandef) |
de95a54b JB |
1197 | { |
1198 | struct ieee80211_supported_band *sband; | |
c604b9f2 | 1199 | u8 *pos = buffer, *end = buffer + buffer_len; |
8e664fb3 JB |
1200 | size_t offset = 0, noffset; |
1201 | int supp_rates_len, i; | |
8dcb2003 JM |
1202 | u8 rates[32]; |
1203 | int num_rates; | |
1204 | int ext_rates_len; | |
2103dec1 SW |
1205 | int shift; |
1206 | u32 rate_flags; | |
de95a54b | 1207 | |
4d36ec58 | 1208 | sband = local->hw.wiphy->bands[band]; |
d811b3d5 AN |
1209 | if (WARN_ON_ONCE(!sband)) |
1210 | return 0; | |
de95a54b | 1211 | |
2103dec1 SW |
1212 | rate_flags = ieee80211_chandef_rate_flags(chandef); |
1213 | shift = ieee80211_chandef_get_shift(chandef); | |
1214 | ||
8dcb2003 JM |
1215 | num_rates = 0; |
1216 | for (i = 0; i < sband->n_bitrates; i++) { | |
1217 | if ((BIT(i) & rate_mask) == 0) | |
1218 | continue; /* skip rate */ | |
2103dec1 SW |
1219 | if ((rate_flags & sband->bitrates[i].flags) != rate_flags) |
1220 | continue; | |
1221 | ||
1222 | rates[num_rates++] = | |
1223 | (u8) DIV_ROUND_UP(sband->bitrates[i].bitrate, | |
1224 | (1 << shift) * 5); | |
8dcb2003 JM |
1225 | } |
1226 | ||
1227 | supp_rates_len = min_t(int, num_rates, 8); | |
8e664fb3 | 1228 | |
c604b9f2 JB |
1229 | if (end - pos < 2 + supp_rates_len) |
1230 | goto out_err; | |
de95a54b | 1231 | *pos++ = WLAN_EID_SUPP_RATES; |
8e664fb3 | 1232 | *pos++ = supp_rates_len; |
8dcb2003 JM |
1233 | memcpy(pos, rates, supp_rates_len); |
1234 | pos += supp_rates_len; | |
8e664fb3 JB |
1235 | |
1236 | /* insert "request information" if in custom IEs */ | |
1237 | if (ie && ie_len) { | |
1238 | static const u8 before_extrates[] = { | |
1239 | WLAN_EID_SSID, | |
1240 | WLAN_EID_SUPP_RATES, | |
1241 | WLAN_EID_REQUEST, | |
1242 | }; | |
1243 | noffset = ieee80211_ie_split(ie, ie_len, | |
1244 | before_extrates, | |
1245 | ARRAY_SIZE(before_extrates), | |
1246 | offset); | |
c604b9f2 JB |
1247 | if (end - pos < noffset - offset) |
1248 | goto out_err; | |
8e664fb3 JB |
1249 | memcpy(pos, ie + offset, noffset - offset); |
1250 | pos += noffset - offset; | |
1251 | offset = noffset; | |
1252 | } | |
1253 | ||
8dcb2003 JM |
1254 | ext_rates_len = num_rates - supp_rates_len; |
1255 | if (ext_rates_len > 0) { | |
c604b9f2 JB |
1256 | if (end - pos < 2 + ext_rates_len) |
1257 | goto out_err; | |
8e664fb3 | 1258 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
8dcb2003 JM |
1259 | *pos++ = ext_rates_len; |
1260 | memcpy(pos, rates + supp_rates_len, ext_rates_len); | |
1261 | pos += ext_rates_len; | |
8e664fb3 JB |
1262 | } |
1263 | ||
2103dec1 | 1264 | if (chandef->chan && sband->band == IEEE80211_BAND_2GHZ) { |
c604b9f2 JB |
1265 | if (end - pos < 3) |
1266 | goto out_err; | |
651b5225 JM |
1267 | *pos++ = WLAN_EID_DS_PARAMS; |
1268 | *pos++ = 1; | |
2103dec1 SW |
1269 | *pos++ = ieee80211_frequency_to_channel( |
1270 | chandef->chan->center_freq); | |
651b5225 JM |
1271 | } |
1272 | ||
8e664fb3 JB |
1273 | /* insert custom IEs that go before HT */ |
1274 | if (ie && ie_len) { | |
1275 | static const u8 before_ht[] = { | |
1276 | WLAN_EID_SSID, | |
1277 | WLAN_EID_SUPP_RATES, | |
1278 | WLAN_EID_REQUEST, | |
1279 | WLAN_EID_EXT_SUPP_RATES, | |
1280 | WLAN_EID_DS_PARAMS, | |
1281 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, | |
1282 | }; | |
1283 | noffset = ieee80211_ie_split(ie, ie_len, | |
1284 | before_ht, ARRAY_SIZE(before_ht), | |
1285 | offset); | |
c604b9f2 JB |
1286 | if (end - pos < noffset - offset) |
1287 | goto out_err; | |
8e664fb3 JB |
1288 | memcpy(pos, ie + offset, noffset - offset); |
1289 | pos += noffset - offset; | |
1290 | offset = noffset; | |
de95a54b JB |
1291 | } |
1292 | ||
c604b9f2 JB |
1293 | if (sband->ht_cap.ht_supported) { |
1294 | if (end - pos < 2 + sizeof(struct ieee80211_ht_cap)) | |
1295 | goto out_err; | |
ef96a842 BG |
1296 | pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, |
1297 | sband->ht_cap.cap); | |
c604b9f2 | 1298 | } |
5ef2d41a | 1299 | |
de95a54b JB |
1300 | /* |
1301 | * If adding more here, adjust code in main.c | |
1302 | * that calculates local->scan_ies_len. | |
1303 | */ | |
1304 | ||
4d952300 | 1305 | /* insert custom IEs that go before VHT */ |
8e664fb3 | 1306 | if (ie && ie_len) { |
4d952300 JB |
1307 | static const u8 before_vht[] = { |
1308 | WLAN_EID_SSID, | |
1309 | WLAN_EID_SUPP_RATES, | |
1310 | WLAN_EID_REQUEST, | |
1311 | WLAN_EID_EXT_SUPP_RATES, | |
1312 | WLAN_EID_DS_PARAMS, | |
1313 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, | |
1314 | WLAN_EID_HT_CAPABILITY, | |
1315 | WLAN_EID_BSS_COEX_2040, | |
1316 | WLAN_EID_EXT_CAPABILITY, | |
1317 | WLAN_EID_SSID_LIST, | |
1318 | WLAN_EID_CHANNEL_USAGE, | |
1319 | WLAN_EID_INTERWORKING, | |
1320 | /* mesh ID can't happen here */ | |
1321 | /* 60 GHz can't happen here right now */ | |
1322 | }; | |
1323 | noffset = ieee80211_ie_split(ie, ie_len, | |
1324 | before_vht, ARRAY_SIZE(before_vht), | |
1325 | offset); | |
c604b9f2 JB |
1326 | if (end - pos < noffset - offset) |
1327 | goto out_err; | |
8e664fb3 JB |
1328 | memcpy(pos, ie + offset, noffset - offset); |
1329 | pos += noffset - offset; | |
4d952300 | 1330 | offset = noffset; |
de95a54b JB |
1331 | } |
1332 | ||
c604b9f2 JB |
1333 | if (sband->vht_cap.vht_supported) { |
1334 | if (end - pos < 2 + sizeof(struct ieee80211_vht_cap)) | |
1335 | goto out_err; | |
ba0afa2f MP |
1336 | pos = ieee80211_ie_build_vht_cap(pos, &sband->vht_cap, |
1337 | sband->vht_cap.cap); | |
c604b9f2 | 1338 | } |
ba0afa2f | 1339 | |
4d952300 JB |
1340 | /* add any remaining custom IEs */ |
1341 | if (ie && ie_len) { | |
1342 | noffset = ie_len; | |
1343 | if (end - pos < noffset - offset) | |
1344 | goto out_err; | |
1345 | memcpy(pos, ie + offset, noffset - offset); | |
1346 | pos += noffset - offset; | |
1347 | } | |
1348 | ||
c604b9f2 JB |
1349 | return pos - buffer; |
1350 | out_err: | |
1351 | WARN_ONCE(1, "not enough space for preq IEs\n"); | |
de95a54b JB |
1352 | return pos - buffer; |
1353 | } | |
1354 | ||
a619a4c0 | 1355 | struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata, |
85a237fe | 1356 | u8 *dst, u32 ratemask, |
6b77863b | 1357 | struct ieee80211_channel *chan, |
a619a4c0 | 1358 | const u8 *ssid, size_t ssid_len, |
a806c558 PS |
1359 | const u8 *ie, size_t ie_len, |
1360 | bool directed) | |
46900298 JB |
1361 | { |
1362 | struct ieee80211_local *local = sdata->local; | |
2103dec1 | 1363 | struct cfg80211_chan_def chandef; |
46900298 JB |
1364 | struct sk_buff *skb; |
1365 | struct ieee80211_mgmt *mgmt; | |
b9a9ada1 | 1366 | int ies_len; |
46900298 | 1367 | |
a806c558 PS |
1368 | /* |
1369 | * Do not send DS Channel parameter for directed probe requests | |
1370 | * in order to maximize the chance that we get a response. Some | |
1371 | * badly-behaved APs don't respond when this parameter is included. | |
1372 | */ | |
2103dec1 | 1373 | chandef.width = sdata->vif.bss_conf.chandef.width; |
a806c558 | 1374 | if (directed) |
2103dec1 | 1375 | chandef.chan = NULL; |
a806c558 | 1376 | else |
2103dec1 | 1377 | chandef.chan = chan; |
651b5225 | 1378 | |
7c12ce8b | 1379 | skb = ieee80211_probereq_get(&local->hw, &sdata->vif, |
b9a9ada1 | 1380 | ssid, ssid_len, 100 + ie_len); |
5b2bbf75 | 1381 | if (!skb) |
b9a9ada1 JB |
1382 | return NULL; |
1383 | ||
1384 | ies_len = ieee80211_build_preq_ies(local, skb_tail_pointer(skb), | |
1385 | skb_tailroom(skb), | |
1386 | ie, ie_len, chan->band, | |
2103dec1 | 1387 | ratemask, &chandef); |
b9a9ada1 | 1388 | skb_put(skb, ies_len); |
7c12ce8b | 1389 | |
46900298 | 1390 | if (dst) { |
7c12ce8b | 1391 | mgmt = (struct ieee80211_mgmt *) skb->data; |
46900298 JB |
1392 | memcpy(mgmt->da, dst, ETH_ALEN); |
1393 | memcpy(mgmt->bssid, dst, ETH_ALEN); | |
46900298 | 1394 | } |
46900298 | 1395 | |
62ae67be | 1396 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
5b2bbf75 | 1397 | |
a619a4c0 JO |
1398 | return skb; |
1399 | } | |
1400 | ||
1401 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, | |
1402 | const u8 *ssid, size_t ssid_len, | |
a806c558 | 1403 | const u8 *ie, size_t ie_len, |
1672c0e3 | 1404 | u32 ratemask, bool directed, u32 tx_flags, |
55de908a | 1405 | struct ieee80211_channel *channel, bool scan) |
a619a4c0 JO |
1406 | { |
1407 | struct sk_buff *skb; | |
1408 | ||
fe94fe05 | 1409 | skb = ieee80211_build_probe_req(sdata, dst, ratemask, channel, |
6b77863b | 1410 | ssid, ssid_len, |
85a237fe | 1411 | ie, ie_len, directed); |
aad14ceb | 1412 | if (skb) { |
1672c0e3 | 1413 | IEEE80211_SKB_CB(skb)->flags |= tx_flags; |
55de908a JB |
1414 | if (scan) |
1415 | ieee80211_tx_skb_tid_band(sdata, skb, 7, channel->band); | |
1416 | else | |
1417 | ieee80211_tx_skb(sdata, skb); | |
aad14ceb | 1418 | } |
46900298 JB |
1419 | } |
1420 | ||
2103dec1 | 1421 | u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata, |
46900298 | 1422 | struct ieee802_11_elems *elems, |
9ebb61a2 | 1423 | enum ieee80211_band band, u32 *basic_rates) |
46900298 JB |
1424 | { |
1425 | struct ieee80211_supported_band *sband; | |
46900298 | 1426 | size_t num_rates; |
2103dec1 SW |
1427 | u32 supp_rates, rate_flags; |
1428 | int i, j, shift; | |
1429 | sband = sdata->local->hw.wiphy->bands[band]; | |
1430 | ||
1431 | rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef); | |
1432 | shift = ieee80211_vif_get_shift(&sdata->vif); | |
46900298 | 1433 | |
4ee73f33 MK |
1434 | if (WARN_ON(!sband)) |
1435 | return 1; | |
46900298 | 1436 | |
46900298 JB |
1437 | num_rates = sband->n_bitrates; |
1438 | supp_rates = 0; | |
1439 | for (i = 0; i < elems->supp_rates_len + | |
1440 | elems->ext_supp_rates_len; i++) { | |
1441 | u8 rate = 0; | |
1442 | int own_rate; | |
9ebb61a2 | 1443 | bool is_basic; |
46900298 JB |
1444 | if (i < elems->supp_rates_len) |
1445 | rate = elems->supp_rates[i]; | |
1446 | else if (elems->ext_supp_rates) | |
1447 | rate = elems->ext_supp_rates | |
1448 | [i - elems->supp_rates_len]; | |
1449 | own_rate = 5 * (rate & 0x7f); | |
9ebb61a2 AN |
1450 | is_basic = !!(rate & 0x80); |
1451 | ||
1452 | if (is_basic && (rate & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY) | |
1453 | continue; | |
1454 | ||
1455 | for (j = 0; j < num_rates; j++) { | |
2103dec1 SW |
1456 | int brate; |
1457 | if ((rate_flags & sband->bitrates[j].flags) | |
1458 | != rate_flags) | |
1459 | continue; | |
1460 | ||
1461 | brate = DIV_ROUND_UP(sband->bitrates[j].bitrate, | |
1462 | 1 << shift); | |
1463 | ||
1464 | if (brate == own_rate) { | |
46900298 | 1465 | supp_rates |= BIT(j); |
9ebb61a2 AN |
1466 | if (basic_rates && is_basic) |
1467 | *basic_rates |= BIT(j); | |
1468 | } | |
1469 | } | |
46900298 JB |
1470 | } |
1471 | return supp_rates; | |
1472 | } | |
f2753ddb | 1473 | |
84f6a01c JB |
1474 | void ieee80211_stop_device(struct ieee80211_local *local) |
1475 | { | |
1476 | ieee80211_led_radio(local, false); | |
67408c8c | 1477 | ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO); |
84f6a01c JB |
1478 | |
1479 | cancel_work_sync(&local->reconfig_filter); | |
84f6a01c JB |
1480 | |
1481 | flush_workqueue(local->workqueue); | |
678f415f | 1482 | drv_stop(local); |
84f6a01c JB |
1483 | } |
1484 | ||
f6837ba8 JB |
1485 | static void ieee80211_handle_reconfig_failure(struct ieee80211_local *local) |
1486 | { | |
1487 | struct ieee80211_sub_if_data *sdata; | |
1488 | struct ieee80211_chanctx *ctx; | |
1489 | ||
1490 | /* | |
1491 | * We get here if during resume the device can't be restarted properly. | |
1492 | * We might also get here if this happens during HW reset, which is a | |
1493 | * slightly different situation and we need to drop all connections in | |
1494 | * the latter case. | |
1495 | * | |
1496 | * Ask cfg80211 to turn off all interfaces, this will result in more | |
1497 | * warnings but at least we'll then get into a clean stopped state. | |
1498 | */ | |
1499 | ||
1500 | local->resuming = false; | |
1501 | local->suspended = false; | |
1502 | local->started = false; | |
1503 | ||
1504 | /* scheduled scan clearly can't be running any more, but tell | |
1505 | * cfg80211 and clear local state | |
1506 | */ | |
1507 | ieee80211_sched_scan_end(local); | |
1508 | ||
1509 | list_for_each_entry(sdata, &local->interfaces, list) | |
1510 | sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER; | |
1511 | ||
1512 | /* Mark channel contexts as not being in the driver any more to avoid | |
1513 | * removing them from the driver during the shutdown process... | |
1514 | */ | |
1515 | mutex_lock(&local->chanctx_mtx); | |
1516 | list_for_each_entry(ctx, &local->chanctx_list, list) | |
1517 | ctx->driver_present = false; | |
1518 | mutex_unlock(&local->chanctx_mtx); | |
1519 | ||
1520 | cfg80211_shutdown_all_interfaces(local->hw.wiphy); | |
1521 | } | |
1522 | ||
153a5fc4 SG |
1523 | static void ieee80211_assign_chanctx(struct ieee80211_local *local, |
1524 | struct ieee80211_sub_if_data *sdata) | |
1525 | { | |
1526 | struct ieee80211_chanctx_conf *conf; | |
1527 | struct ieee80211_chanctx *ctx; | |
1528 | ||
1529 | if (!local->use_chanctx) | |
1530 | return; | |
1531 | ||
1532 | mutex_lock(&local->chanctx_mtx); | |
1533 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, | |
1534 | lockdep_is_held(&local->chanctx_mtx)); | |
1535 | if (conf) { | |
1536 | ctx = container_of(conf, struct ieee80211_chanctx, conf); | |
1537 | drv_assign_vif_chanctx(local, sdata, ctx); | |
1538 | } | |
1539 | mutex_unlock(&local->chanctx_mtx); | |
1540 | } | |
1541 | ||
f2753ddb JB |
1542 | int ieee80211_reconfig(struct ieee80211_local *local) |
1543 | { | |
1544 | struct ieee80211_hw *hw = &local->hw; | |
1545 | struct ieee80211_sub_if_data *sdata; | |
55de908a | 1546 | struct ieee80211_chanctx *ctx; |
f2753ddb | 1547 | struct sta_info *sta; |
2683d65b | 1548 | int res, i; |
d888130a | 1549 | bool reconfig_due_to_wowlan = false; |
d43c6b6e DS |
1550 | struct ieee80211_sub_if_data *sched_scan_sdata; |
1551 | bool sched_scan_stopped = false; | |
d888130a | 1552 | |
8f21b0ad | 1553 | #ifdef CONFIG_PM |
ceb99fe0 JB |
1554 | if (local->suspended) |
1555 | local->resuming = true; | |
f2753ddb | 1556 | |
eecc4800 | 1557 | if (local->wowlan) { |
eecc4800 | 1558 | res = drv_resume(local); |
27b3eb9c | 1559 | local->wowlan = false; |
eecc4800 JB |
1560 | if (res < 0) { |
1561 | local->resuming = false; | |
1562 | return res; | |
1563 | } | |
1564 | if (res == 0) | |
1565 | goto wake_up; | |
1566 | WARN_ON(res > 1); | |
1567 | /* | |
1568 | * res is 1, which means the driver requested | |
1569 | * to go through a regular reset on wakeup. | |
1570 | */ | |
d888130a | 1571 | reconfig_due_to_wowlan = true; |
eecc4800 JB |
1572 | } |
1573 | #endif | |
94f9b97b JB |
1574 | /* everything else happens only if HW was up & running */ |
1575 | if (!local->open_count) | |
1576 | goto wake_up; | |
f2753ddb | 1577 | |
94f9b97b JB |
1578 | /* |
1579 | * Upon resume hardware can sometimes be goofy due to | |
1580 | * various platform / driver / bus issues, so restarting | |
1581 | * the device may at times not work immediately. Propagate | |
1582 | * the error. | |
1583 | */ | |
1584 | res = drv_start(local); | |
1585 | if (res) { | |
f6837ba8 JB |
1586 | if (local->suspended) |
1587 | WARN(1, "Hardware became unavailable upon resume. This could be a software issue prior to suspend or a hardware issue.\n"); | |
1588 | else | |
1589 | WARN(1, "Hardware became unavailable during restart.\n"); | |
1590 | ieee80211_handle_reconfig_failure(local); | |
94f9b97b | 1591 | return res; |
f2753ddb JB |
1592 | } |
1593 | ||
7f281975 YAP |
1594 | /* setup fragmentation threshold */ |
1595 | drv_set_frag_threshold(local, hw->wiphy->frag_threshold); | |
1596 | ||
1597 | /* setup RTS threshold */ | |
1598 | drv_set_rts_threshold(local, hw->wiphy->rts_threshold); | |
1599 | ||
1600 | /* reset coverage class */ | |
1601 | drv_set_coverage_class(local, hw->wiphy->coverage_class); | |
1602 | ||
94f9b97b JB |
1603 | ieee80211_led_radio(local, true); |
1604 | ieee80211_mod_tpt_led_trig(local, | |
1605 | IEEE80211_TPT_LEDTRIG_FL_RADIO, 0); | |
1606 | ||
f2753ddb | 1607 | /* add interfaces */ |
4b6f1dd6 JB |
1608 | sdata = rtnl_dereference(local->monitor_sdata); |
1609 | if (sdata) { | |
3c3e21e7 JB |
1610 | /* in HW restart it exists already */ |
1611 | WARN_ON(local->resuming); | |
4b6f1dd6 JB |
1612 | res = drv_add_interface(local, sdata); |
1613 | if (WARN_ON(res)) { | |
0c2bef46 | 1614 | RCU_INIT_POINTER(local->monitor_sdata, NULL); |
4b6f1dd6 JB |
1615 | synchronize_net(); |
1616 | kfree(sdata); | |
1617 | } | |
1618 | } | |
1619 | ||
f2753ddb JB |
1620 | list_for_each_entry(sdata, &local->interfaces, list) { |
1621 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | |
1622 | sdata->vif.type != NL80211_IFTYPE_MONITOR && | |
1ed32e4f | 1623 | ieee80211_sdata_running(sdata)) |
7b7eab6f | 1624 | res = drv_add_interface(local, sdata); |
f2753ddb JB |
1625 | } |
1626 | ||
55de908a | 1627 | /* add channel contexts */ |
f0dea9c7 AS |
1628 | if (local->use_chanctx) { |
1629 | mutex_lock(&local->chanctx_mtx); | |
1630 | list_for_each_entry(ctx, &local->chanctx_list, list) | |
1631 | WARN_ON(drv_add_chanctx(local, ctx)); | |
1632 | mutex_unlock(&local->chanctx_mtx); | |
55de908a | 1633 | |
7df180f7 ZG |
1634 | list_for_each_entry(sdata, &local->interfaces, list) { |
1635 | if (!ieee80211_sdata_running(sdata)) | |
1636 | continue; | |
1637 | ieee80211_assign_chanctx(local, sdata); | |
1638 | } | |
6352c87f | 1639 | |
7df180f7 ZG |
1640 | sdata = rtnl_dereference(local->monitor_sdata); |
1641 | if (sdata && ieee80211_sdata_running(sdata)) | |
1642 | ieee80211_assign_chanctx(local, sdata); | |
1643 | } | |
fe5f2559 | 1644 | |
f2753ddb | 1645 | /* add STAs back */ |
34e89507 JB |
1646 | mutex_lock(&local->sta_mtx); |
1647 | list_for_each_entry(sta, &local->sta_list, list) { | |
2e8d397e | 1648 | enum ieee80211_sta_state state; |
f09603a2 | 1649 | |
2e8d397e AN |
1650 | if (!sta->uploaded) |
1651 | continue; | |
1652 | ||
1653 | /* AP-mode stations will be added later */ | |
1654 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP) | |
1655 | continue; | |
1656 | ||
1657 | for (state = IEEE80211_STA_NOTEXIST; | |
1658 | state < sta->sta_state; state++) | |
1659 | WARN_ON(drv_sta_state(local, sta->sdata, sta, state, | |
1660 | state + 1)); | |
f2753ddb | 1661 | } |
34e89507 | 1662 | mutex_unlock(&local->sta_mtx); |
f2753ddb | 1663 | |
2683d65b | 1664 | /* reconfigure tx conf */ |
54bcbc69 JB |
1665 | if (hw->queues >= IEEE80211_NUM_ACS) { |
1666 | list_for_each_entry(sdata, &local->interfaces, list) { | |
1667 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN || | |
1668 | sdata->vif.type == NL80211_IFTYPE_MONITOR || | |
1669 | !ieee80211_sdata_running(sdata)) | |
1670 | continue; | |
f6f3def3 | 1671 | |
54bcbc69 JB |
1672 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
1673 | drv_conf_tx(local, sdata, i, | |
1674 | &sdata->tx_conf[i]); | |
1675 | } | |
f6f3def3 | 1676 | } |
2683d65b | 1677 | |
f2753ddb JB |
1678 | /* reconfigure hardware */ |
1679 | ieee80211_hw_config(local, ~0); | |
1680 | ||
f2753ddb | 1681 | ieee80211_configure_filter(local); |
f2753ddb JB |
1682 | |
1683 | /* Finally also reconfigure all the BSS information */ | |
1684 | list_for_each_entry(sdata, &local->interfaces, list) { | |
ac8dd506 JB |
1685 | u32 changed; |
1686 | ||
9607e6b6 | 1687 | if (!ieee80211_sdata_running(sdata)) |
f2753ddb | 1688 | continue; |
ac8dd506 JB |
1689 | |
1690 | /* common change flags for all interface types */ | |
1691 | changed = BSS_CHANGED_ERP_CTS_PROT | | |
1692 | BSS_CHANGED_ERP_PREAMBLE | | |
1693 | BSS_CHANGED_ERP_SLOT | | |
1694 | BSS_CHANGED_HT | | |
1695 | BSS_CHANGED_BASIC_RATES | | |
1696 | BSS_CHANGED_BEACON_INT | | |
1697 | BSS_CHANGED_BSSID | | |
4ced3f74 | 1698 | BSS_CHANGED_CQM | |
55de47f6 | 1699 | BSS_CHANGED_QOS | |
1ea6f9c0 JB |
1700 | BSS_CHANGED_IDLE | |
1701 | BSS_CHANGED_TXPOWER; | |
ac8dd506 | 1702 | |
f2753ddb JB |
1703 | switch (sdata->vif.type) { |
1704 | case NL80211_IFTYPE_STATION: | |
0d392e93 | 1705 | changed |= BSS_CHANGED_ASSOC | |
ab095877 EP |
1706 | BSS_CHANGED_ARP_FILTER | |
1707 | BSS_CHANGED_PS; | |
c65dd147 | 1708 | |
989c6505 AB |
1709 | /* Re-send beacon info report to the driver */ |
1710 | if (sdata->u.mgd.have_beacon) | |
1711 | changed |= BSS_CHANGED_BEACON_INFO; | |
c65dd147 | 1712 | |
8d61ffa5 | 1713 | sdata_lock(sdata); |
ac8dd506 | 1714 | ieee80211_bss_info_change_notify(sdata, changed); |
8d61ffa5 | 1715 | sdata_unlock(sdata); |
ac8dd506 | 1716 | break; |
f2753ddb | 1717 | case NL80211_IFTYPE_ADHOC: |
ac8dd506 JB |
1718 | changed |= BSS_CHANGED_IBSS; |
1719 | /* fall through */ | |
f2753ddb | 1720 | case NL80211_IFTYPE_AP: |
339afbf4 | 1721 | changed |= BSS_CHANGED_SSID | BSS_CHANGED_P2P_PS; |
e7979ac7 | 1722 | |
1041638f | 1723 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
e7979ac7 AN |
1724 | changed |= BSS_CHANGED_AP_PROBE_RESP; |
1725 | ||
1041638f JB |
1726 | if (rcu_access_pointer(sdata->u.ap.beacon)) |
1727 | drv_start_ap(local, sdata); | |
1728 | } | |
1729 | ||
7827493b | 1730 | /* fall through */ |
f2753ddb | 1731 | case NL80211_IFTYPE_MESH_POINT: |
8da34932 JB |
1732 | if (sdata->vif.bss_conf.enable_beacon) { |
1733 | changed |= BSS_CHANGED_BEACON | | |
1734 | BSS_CHANGED_BEACON_ENABLED; | |
1735 | ieee80211_bss_info_change_notify(sdata, changed); | |
1736 | } | |
f2753ddb JB |
1737 | break; |
1738 | case NL80211_IFTYPE_WDS: | |
f2753ddb JB |
1739 | case NL80211_IFTYPE_AP_VLAN: |
1740 | case NL80211_IFTYPE_MONITOR: | |
98104fde | 1741 | case NL80211_IFTYPE_P2P_DEVICE: |
b205786e | 1742 | /* nothing to do */ |
f142c6b9 | 1743 | break; |
f2753ddb | 1744 | case NL80211_IFTYPE_UNSPECIFIED: |
2e161f78 | 1745 | case NUM_NL80211_IFTYPES: |
2ca27bcf JB |
1746 | case NL80211_IFTYPE_P2P_CLIENT: |
1747 | case NL80211_IFTYPE_P2P_GO: | |
f2753ddb JB |
1748 | WARN_ON(1); |
1749 | break; | |
1750 | } | |
1751 | } | |
1752 | ||
8e1b23b9 ES |
1753 | ieee80211_recalc_ps(local, -1); |
1754 | ||
6e1b1b24 EP |
1755 | /* |
1756 | * The sta might be in psm against the ap (e.g. because | |
1757 | * this was the state before a hw restart), so we | |
1758 | * explicitly send a null packet in order to make sure | |
1759 | * it'll sync against the ap (and get out of psm). | |
1760 | */ | |
1761 | if (!(local->hw.conf.flags & IEEE80211_CONF_PS)) { | |
1762 | list_for_each_entry(sdata, &local->interfaces, list) { | |
1763 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
1764 | continue; | |
20f544ee JB |
1765 | if (!sdata->u.mgd.associated) |
1766 | continue; | |
6e1b1b24 EP |
1767 | |
1768 | ieee80211_send_nullfunc(local, sdata, 0); | |
1769 | } | |
1770 | } | |
1771 | ||
2e8d397e AN |
1772 | /* APs are now beaconing, add back stations */ |
1773 | mutex_lock(&local->sta_mtx); | |
1774 | list_for_each_entry(sta, &local->sta_list, list) { | |
1775 | enum ieee80211_sta_state state; | |
1776 | ||
1777 | if (!sta->uploaded) | |
1778 | continue; | |
1779 | ||
1780 | if (sta->sdata->vif.type != NL80211_IFTYPE_AP) | |
1781 | continue; | |
1782 | ||
1783 | for (state = IEEE80211_STA_NOTEXIST; | |
1784 | state < sta->sta_state; state++) | |
1785 | WARN_ON(drv_sta_state(local, sta->sdata, sta, state, | |
1786 | state + 1)); | |
1787 | } | |
1788 | mutex_unlock(&local->sta_mtx); | |
1789 | ||
7b21aea0 ES |
1790 | /* add back keys */ |
1791 | list_for_each_entry(sdata, &local->interfaces, list) | |
1792 | if (ieee80211_sdata_running(sdata)) | |
1793 | ieee80211_enable_keys(sdata); | |
1794 | ||
c6209488 | 1795 | wake_up: |
04800ada AN |
1796 | local->in_reconfig = false; |
1797 | barrier(); | |
1798 | ||
3c3e21e7 JB |
1799 | if (local->monitors == local->open_count && local->monitors > 0) |
1800 | ieee80211_add_virtual_monitor(local); | |
1801 | ||
2a419056 JB |
1802 | /* |
1803 | * Clear the WLAN_STA_BLOCK_BA flag so new aggregation | |
1804 | * sessions can be established after a resume. | |
1805 | * | |
1806 | * Also tear down aggregation sessions since reconfiguring | |
1807 | * them in a hardware restart scenario is not easily done | |
1808 | * right now, and the hardware will have lost information | |
1809 | * about the sessions, but we and the AP still think they | |
1810 | * are active. This is really a workaround though. | |
1811 | */ | |
74e2bd1f | 1812 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
2a419056 JB |
1813 | mutex_lock(&local->sta_mtx); |
1814 | ||
1815 | list_for_each_entry(sta, &local->sta_list, list) { | |
c82c4a80 JB |
1816 | ieee80211_sta_tear_down_BA_sessions( |
1817 | sta, AGG_STOP_LOCAL_REQUEST); | |
c2c98fde | 1818 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); |
74e2bd1f | 1819 | } |
2a419056 JB |
1820 | |
1821 | mutex_unlock(&local->sta_mtx); | |
74e2bd1f | 1822 | } |
74e2bd1f | 1823 | |
445ea4e8 | 1824 | ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP, |
cca07b00 LC |
1825 | IEEE80211_QUEUE_STOP_REASON_SUSPEND, |
1826 | false); | |
f2753ddb | 1827 | |
32769814 AN |
1828 | /* |
1829 | * Reconfigure sched scan if it was interrupted by FW restart or | |
1830 | * suspend. | |
1831 | */ | |
1832 | mutex_lock(&local->mtx); | |
1833 | sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata, | |
1834 | lockdep_is_held(&local->mtx)); | |
1835 | if (sched_scan_sdata && local->sched_scan_req) | |
1836 | /* | |
1837 | * Sched scan stopped, but we don't want to report it. Instead, | |
1838 | * we're trying to reschedule. | |
1839 | */ | |
1840 | if (__ieee80211_request_sched_scan_start(sched_scan_sdata, | |
1841 | local->sched_scan_req)) | |
1842 | sched_scan_stopped = true; | |
1843 | mutex_unlock(&local->mtx); | |
1844 | ||
1845 | if (sched_scan_stopped) | |
e669ba2d | 1846 | cfg80211_sched_scan_stopped_rtnl(local->hw.wiphy); |
32769814 | 1847 | |
5bb644a0 JB |
1848 | /* |
1849 | * If this is for hw restart things are still running. | |
1850 | * We may want to change that later, however. | |
1851 | */ | |
8f21b0ad | 1852 | if (!local->suspended || reconfig_due_to_wowlan) |
9214ad7f | 1853 | drv_restart_complete(local); |
8f21b0ad JB |
1854 | |
1855 | if (!local->suspended) | |
5bb644a0 JB |
1856 | return 0; |
1857 | ||
1858 | #ifdef CONFIG_PM | |
ceb99fe0 | 1859 | /* first set suspended false, then resuming */ |
5bb644a0 | 1860 | local->suspended = false; |
ceb99fe0 JB |
1861 | mb(); |
1862 | local->resuming = false; | |
5bb644a0 | 1863 | |
b8360ab8 JB |
1864 | list_for_each_entry(sdata, &local->interfaces, list) { |
1865 | if (!ieee80211_sdata_running(sdata)) | |
1866 | continue; | |
1867 | if (sdata->vif.type == NL80211_IFTYPE_STATION) | |
1868 | ieee80211_sta_restart(sdata); | |
1869 | } | |
1870 | ||
26d59535 | 1871 | mod_timer(&local->sta_cleanup, jiffies + 1); |
5bb644a0 JB |
1872 | #else |
1873 | WARN_ON(1); | |
1874 | #endif | |
d43c6b6e | 1875 | |
f2753ddb JB |
1876 | return 0; |
1877 | } | |
42935eca | 1878 | |
95acac61 JB |
1879 | void ieee80211_resume_disconnect(struct ieee80211_vif *vif) |
1880 | { | |
1881 | struct ieee80211_sub_if_data *sdata; | |
1882 | struct ieee80211_local *local; | |
1883 | struct ieee80211_key *key; | |
1884 | ||
1885 | if (WARN_ON(!vif)) | |
1886 | return; | |
1887 | ||
1888 | sdata = vif_to_sdata(vif); | |
1889 | local = sdata->local; | |
1890 | ||
1891 | if (WARN_ON(!local->resuming)) | |
1892 | return; | |
1893 | ||
1894 | if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) | |
1895 | return; | |
1896 | ||
1897 | sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME; | |
1898 | ||
1899 | mutex_lock(&local->key_mtx); | |
1900 | list_for_each_entry(key, &sdata->key_list, list) | |
1901 | key->flags |= KEY_FLAG_TAINTED; | |
1902 | mutex_unlock(&local->key_mtx); | |
1903 | } | |
1904 | EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect); | |
1905 | ||
04ecd257 | 1906 | void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata) |
0f78231b | 1907 | { |
04ecd257 JB |
1908 | struct ieee80211_local *local = sdata->local; |
1909 | struct ieee80211_chanctx_conf *chanctx_conf; | |
1910 | struct ieee80211_chanctx *chanctx; | |
025e6be2 | 1911 | |
04ecd257 | 1912 | mutex_lock(&local->chanctx_mtx); |
0f78231b | 1913 | |
04ecd257 JB |
1914 | chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
1915 | lockdep_is_held(&local->chanctx_mtx)); | |
0f78231b | 1916 | |
04ecd257 | 1917 | if (WARN_ON_ONCE(!chanctx_conf)) |
5d8e4237 | 1918 | goto unlock; |
0f78231b | 1919 | |
04ecd257 JB |
1920 | chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf); |
1921 | ieee80211_recalc_smps_chanctx(local, chanctx); | |
5d8e4237 | 1922 | unlock: |
04ecd257 | 1923 | mutex_unlock(&local->chanctx_mtx); |
0f78231b | 1924 | } |
8e664fb3 | 1925 | |
21f659bf EP |
1926 | void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata) |
1927 | { | |
1928 | struct ieee80211_local *local = sdata->local; | |
1929 | struct ieee80211_chanctx_conf *chanctx_conf; | |
1930 | struct ieee80211_chanctx *chanctx; | |
1931 | ||
1932 | mutex_lock(&local->chanctx_mtx); | |
1933 | ||
1934 | chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf, | |
1935 | lockdep_is_held(&local->chanctx_mtx)); | |
1936 | ||
1937 | if (WARN_ON_ONCE(!chanctx_conf)) | |
1938 | goto unlock; | |
1939 | ||
1940 | chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf); | |
1941 | ieee80211_recalc_chanctx_min_def(local, chanctx); | |
1942 | unlock: | |
1943 | mutex_unlock(&local->chanctx_mtx); | |
1944 | } | |
1945 | ||
8e664fb3 JB |
1946 | static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id) |
1947 | { | |
1948 | int i; | |
1949 | ||
1950 | for (i = 0; i < n_ids; i++) | |
1951 | if (ids[i] == id) | |
1952 | return true; | |
1953 | return false; | |
1954 | } | |
1955 | ||
1956 | /** | |
1957 | * ieee80211_ie_split - split an IE buffer according to ordering | |
1958 | * | |
1959 | * @ies: the IE buffer | |
1960 | * @ielen: the length of the IE buffer | |
1961 | * @ids: an array with element IDs that are allowed before | |
1962 | * the split | |
1963 | * @n_ids: the size of the element ID array | |
1964 | * @offset: offset where to start splitting in the buffer | |
1965 | * | |
1966 | * This function splits an IE buffer by updating the @offset | |
1967 | * variable to point to the location where the buffer should be | |
1968 | * split. | |
1969 | * | |
1970 | * It assumes that the given IE buffer is well-formed, this | |
1971 | * has to be guaranteed by the caller! | |
1972 | * | |
1973 | * It also assumes that the IEs in the buffer are ordered | |
1974 | * correctly, if not the result of using this function will not | |
1975 | * be ordered correctly either, i.e. it does no reordering. | |
1976 | * | |
1977 | * The function returns the offset where the next part of the | |
1978 | * buffer starts, which may be @ielen if the entire (remainder) | |
1979 | * of the buffer should be used. | |
1980 | */ | |
1981 | size_t ieee80211_ie_split(const u8 *ies, size_t ielen, | |
1982 | const u8 *ids, int n_ids, size_t offset) | |
1983 | { | |
1984 | size_t pos = offset; | |
1985 | ||
1986 | while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos])) | |
1987 | pos += 2 + ies[pos + 1]; | |
1988 | ||
1989 | return pos; | |
1990 | } | |
1991 | ||
1992 | size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset) | |
1993 | { | |
1994 | size_t pos = offset; | |
1995 | ||
1996 | while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC) | |
1997 | pos += 2 + ies[pos + 1]; | |
1998 | ||
1999 | return pos; | |
2000 | } | |
615f7b9b MV |
2001 | |
2002 | static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata, | |
2003 | int rssi_min_thold, | |
2004 | int rssi_max_thold) | |
2005 | { | |
2006 | trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold); | |
2007 | ||
2008 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) | |
2009 | return; | |
2010 | ||
2011 | /* | |
2012 | * Scale up threshold values before storing it, as the RSSI averaging | |
2013 | * algorithm uses a scaled up value as well. Change this scaling | |
2014 | * factor if the RSSI averaging algorithm changes. | |
2015 | */ | |
2016 | sdata->u.mgd.rssi_min_thold = rssi_min_thold*16; | |
2017 | sdata->u.mgd.rssi_max_thold = rssi_max_thold*16; | |
2018 | } | |
2019 | ||
2020 | void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif, | |
2021 | int rssi_min_thold, | |
2022 | int rssi_max_thold) | |
2023 | { | |
2024 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
2025 | ||
2026 | WARN_ON(rssi_min_thold == rssi_max_thold || | |
2027 | rssi_min_thold > rssi_max_thold); | |
2028 | ||
2029 | _ieee80211_enable_rssi_reports(sdata, rssi_min_thold, | |
2030 | rssi_max_thold); | |
2031 | } | |
2032 | EXPORT_SYMBOL(ieee80211_enable_rssi_reports); | |
2033 | ||
2034 | void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif) | |
2035 | { | |
2036 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
2037 | ||
2038 | _ieee80211_enable_rssi_reports(sdata, 0, 0); | |
2039 | } | |
2040 | EXPORT_SYMBOL(ieee80211_disable_rssi_reports); | |
768db343 | 2041 | |
ef96a842 | 2042 | u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap, |
42e7aa77 AS |
2043 | u16 cap) |
2044 | { | |
2045 | __le16 tmp; | |
2046 | ||
2047 | *pos++ = WLAN_EID_HT_CAPABILITY; | |
2048 | *pos++ = sizeof(struct ieee80211_ht_cap); | |
2049 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); | |
2050 | ||
2051 | /* capability flags */ | |
2052 | tmp = cpu_to_le16(cap); | |
2053 | memcpy(pos, &tmp, sizeof(u16)); | |
2054 | pos += sizeof(u16); | |
2055 | ||
2056 | /* AMPDU parameters */ | |
ef96a842 BG |
2057 | *pos++ = ht_cap->ampdu_factor | |
2058 | (ht_cap->ampdu_density << | |
42e7aa77 AS |
2059 | IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT); |
2060 | ||
2061 | /* MCS set */ | |
ef96a842 BG |
2062 | memcpy(pos, &ht_cap->mcs, sizeof(ht_cap->mcs)); |
2063 | pos += sizeof(ht_cap->mcs); | |
42e7aa77 AS |
2064 | |
2065 | /* extended capabilities */ | |
2066 | pos += sizeof(__le16); | |
2067 | ||
2068 | /* BF capabilities */ | |
2069 | pos += sizeof(__le32); | |
2070 | ||
2071 | /* antenna selection */ | |
2072 | pos += sizeof(u8); | |
2073 | ||
2074 | return pos; | |
2075 | } | |
2076 | ||
ba0afa2f | 2077 | u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap, |
cc3983d8 | 2078 | u32 cap) |
ba0afa2f MP |
2079 | { |
2080 | __le32 tmp; | |
2081 | ||
2082 | *pos++ = WLAN_EID_VHT_CAPABILITY; | |
d4950281 MP |
2083 | *pos++ = sizeof(struct ieee80211_vht_cap); |
2084 | memset(pos, 0, sizeof(struct ieee80211_vht_cap)); | |
ba0afa2f MP |
2085 | |
2086 | /* capability flags */ | |
2087 | tmp = cpu_to_le32(cap); | |
2088 | memcpy(pos, &tmp, sizeof(u32)); | |
2089 | pos += sizeof(u32); | |
2090 | ||
2091 | /* VHT MCS set */ | |
2092 | memcpy(pos, &vht_cap->vht_mcs, sizeof(vht_cap->vht_mcs)); | |
2093 | pos += sizeof(vht_cap->vht_mcs); | |
2094 | ||
2095 | return pos; | |
2096 | } | |
2097 | ||
074d46d1 | 2098 | u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap, |
4bf88530 | 2099 | const struct cfg80211_chan_def *chandef, |
431e3154 | 2100 | u16 prot_mode) |
42e7aa77 | 2101 | { |
074d46d1 | 2102 | struct ieee80211_ht_operation *ht_oper; |
42e7aa77 | 2103 | /* Build HT Information */ |
074d46d1 JB |
2104 | *pos++ = WLAN_EID_HT_OPERATION; |
2105 | *pos++ = sizeof(struct ieee80211_ht_operation); | |
2106 | ht_oper = (struct ieee80211_ht_operation *)pos; | |
4bf88530 JB |
2107 | ht_oper->primary_chan = ieee80211_frequency_to_channel( |
2108 | chandef->chan->center_freq); | |
2109 | switch (chandef->width) { | |
2110 | case NL80211_CHAN_WIDTH_160: | |
2111 | case NL80211_CHAN_WIDTH_80P80: | |
2112 | case NL80211_CHAN_WIDTH_80: | |
2113 | case NL80211_CHAN_WIDTH_40: | |
2114 | if (chandef->center_freq1 > chandef->chan->center_freq) | |
2115 | ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | |
2116 | else | |
2117 | ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW; | |
42e7aa77 | 2118 | break; |
42e7aa77 | 2119 | default: |
074d46d1 | 2120 | ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE; |
42e7aa77 AS |
2121 | break; |
2122 | } | |
aee286c2 | 2123 | if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && |
4bf88530 JB |
2124 | chandef->width != NL80211_CHAN_WIDTH_20_NOHT && |
2125 | chandef->width != NL80211_CHAN_WIDTH_20) | |
074d46d1 | 2126 | ht_oper->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY; |
ff3cc5f4 | 2127 | |
431e3154 | 2128 | ht_oper->operation_mode = cpu_to_le16(prot_mode); |
074d46d1 | 2129 | ht_oper->stbc_param = 0x0000; |
42e7aa77 AS |
2130 | |
2131 | /* It seems that Basic MCS set and Supported MCS set | |
2132 | are identical for the first 10 bytes */ | |
074d46d1 JB |
2133 | memset(&ht_oper->basic_set, 0, 16); |
2134 | memcpy(&ht_oper->basic_set, &ht_cap->mcs, 10); | |
42e7aa77 | 2135 | |
074d46d1 | 2136 | return pos + sizeof(struct ieee80211_ht_operation); |
42e7aa77 AS |
2137 | } |
2138 | ||
4bf88530 | 2139 | void ieee80211_ht_oper_to_chandef(struct ieee80211_channel *control_chan, |
4a3cb702 | 2140 | const struct ieee80211_ht_operation *ht_oper, |
4bf88530 | 2141 | struct cfg80211_chan_def *chandef) |
42e7aa77 AS |
2142 | { |
2143 | enum nl80211_channel_type channel_type; | |
2144 | ||
4bf88530 JB |
2145 | if (!ht_oper) { |
2146 | cfg80211_chandef_create(chandef, control_chan, | |
2147 | NL80211_CHAN_NO_HT); | |
2148 | return; | |
2149 | } | |
42e7aa77 | 2150 | |
074d46d1 | 2151 | switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
42e7aa77 AS |
2152 | case IEEE80211_HT_PARAM_CHA_SEC_NONE: |
2153 | channel_type = NL80211_CHAN_HT20; | |
2154 | break; | |
2155 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | |
2156 | channel_type = NL80211_CHAN_HT40PLUS; | |
2157 | break; | |
2158 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
2159 | channel_type = NL80211_CHAN_HT40MINUS; | |
2160 | break; | |
2161 | default: | |
2162 | channel_type = NL80211_CHAN_NO_HT; | |
2163 | } | |
2164 | ||
4bf88530 | 2165 | cfg80211_chandef_create(chandef, control_chan, channel_type); |
42e7aa77 AS |
2166 | } |
2167 | ||
2103dec1 SW |
2168 | int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef, |
2169 | const struct ieee80211_supported_band *sband, | |
2170 | const u8 *srates, int srates_len, u32 *rates) | |
2171 | { | |
2172 | u32 rate_flags = ieee80211_chandef_rate_flags(chandef); | |
2173 | int shift = ieee80211_chandef_get_shift(chandef); | |
2174 | struct ieee80211_rate *br; | |
2175 | int brate, rate, i, j, count = 0; | |
2176 | ||
2177 | *rates = 0; | |
2178 | ||
2179 | for (i = 0; i < srates_len; i++) { | |
2180 | rate = srates[i] & 0x7f; | |
2181 | ||
2182 | for (j = 0; j < sband->n_bitrates; j++) { | |
2183 | br = &sband->bitrates[j]; | |
2184 | if ((rate_flags & br->flags) != rate_flags) | |
2185 | continue; | |
2186 | ||
2187 | brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5); | |
2188 | if (brate == rate) { | |
2189 | *rates |= BIT(j); | |
2190 | count++; | |
2191 | break; | |
2192 | } | |
2193 | } | |
2194 | } | |
2195 | return count; | |
2196 | } | |
2197 | ||
fc8a7321 | 2198 | int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata, |
6b77863b JB |
2199 | struct sk_buff *skb, bool need_basic, |
2200 | enum ieee80211_band band) | |
768db343 | 2201 | { |
768db343 AN |
2202 | struct ieee80211_local *local = sdata->local; |
2203 | struct ieee80211_supported_band *sband; | |
2103dec1 | 2204 | int rate, shift; |
768db343 | 2205 | u8 i, rates, *pos; |
fc8a7321 | 2206 | u32 basic_rates = sdata->vif.bss_conf.basic_rates; |
2103dec1 | 2207 | u32 rate_flags; |
768db343 | 2208 | |
2103dec1 SW |
2209 | shift = ieee80211_vif_get_shift(&sdata->vif); |
2210 | rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef); | |
6b77863b | 2211 | sband = local->hw.wiphy->bands[band]; |
2103dec1 SW |
2212 | rates = 0; |
2213 | for (i = 0; i < sband->n_bitrates; i++) { | |
2214 | if ((rate_flags & sband->bitrates[i].flags) != rate_flags) | |
2215 | continue; | |
2216 | rates++; | |
2217 | } | |
768db343 AN |
2218 | if (rates > 8) |
2219 | rates = 8; | |
2220 | ||
2221 | if (skb_tailroom(skb) < rates + 2) | |
2222 | return -ENOMEM; | |
2223 | ||
2224 | pos = skb_put(skb, rates + 2); | |
2225 | *pos++ = WLAN_EID_SUPP_RATES; | |
2226 | *pos++ = rates; | |
2227 | for (i = 0; i < rates; i++) { | |
657c3e0c | 2228 | u8 basic = 0; |
2103dec1 SW |
2229 | if ((rate_flags & sband->bitrates[i].flags) != rate_flags) |
2230 | continue; | |
2231 | ||
657c3e0c AN |
2232 | if (need_basic && basic_rates & BIT(i)) |
2233 | basic = 0x80; | |
768db343 | 2234 | rate = sband->bitrates[i].bitrate; |
2103dec1 SW |
2235 | rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
2236 | 5 * (1 << shift)); | |
2237 | *pos++ = basic | (u8) rate; | |
768db343 AN |
2238 | } |
2239 | ||
2240 | return 0; | |
2241 | } | |
2242 | ||
fc8a7321 | 2243 | int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata, |
6b77863b JB |
2244 | struct sk_buff *skb, bool need_basic, |
2245 | enum ieee80211_band band) | |
768db343 | 2246 | { |
768db343 AN |
2247 | struct ieee80211_local *local = sdata->local; |
2248 | struct ieee80211_supported_band *sband; | |
cc63ec76 | 2249 | int rate, shift; |
768db343 | 2250 | u8 i, exrates, *pos; |
fc8a7321 | 2251 | u32 basic_rates = sdata->vif.bss_conf.basic_rates; |
2103dec1 SW |
2252 | u32 rate_flags; |
2253 | ||
2254 | rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef); | |
2255 | shift = ieee80211_vif_get_shift(&sdata->vif); | |
768db343 | 2256 | |
6b77863b | 2257 | sband = local->hw.wiphy->bands[band]; |
2103dec1 SW |
2258 | exrates = 0; |
2259 | for (i = 0; i < sband->n_bitrates; i++) { | |
2260 | if ((rate_flags & sband->bitrates[i].flags) != rate_flags) | |
2261 | continue; | |
2262 | exrates++; | |
2263 | } | |
2264 | ||
768db343 AN |
2265 | if (exrates > 8) |
2266 | exrates -= 8; | |
2267 | else | |
2268 | exrates = 0; | |
2269 | ||
2270 | if (skb_tailroom(skb) < exrates + 2) | |
2271 | return -ENOMEM; | |
2272 | ||
2273 | if (exrates) { | |
2274 | pos = skb_put(skb, exrates + 2); | |
2275 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
2276 | *pos++ = exrates; | |
2277 | for (i = 8; i < sband->n_bitrates; i++) { | |
657c3e0c | 2278 | u8 basic = 0; |
2103dec1 SW |
2279 | if ((rate_flags & sband->bitrates[i].flags) |
2280 | != rate_flags) | |
2281 | continue; | |
657c3e0c AN |
2282 | if (need_basic && basic_rates & BIT(i)) |
2283 | basic = 0x80; | |
2103dec1 SW |
2284 | rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, |
2285 | 5 * (1 << shift)); | |
2286 | *pos++ = basic | (u8) rate; | |
768db343 AN |
2287 | } |
2288 | } | |
2289 | return 0; | |
2290 | } | |
1dae27f8 WYG |
2291 | |
2292 | int ieee80211_ave_rssi(struct ieee80211_vif *vif) | |
2293 | { | |
2294 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
2295 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2296 | ||
be6bcabc WYG |
2297 | if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) { |
2298 | /* non-managed type inferfaces */ | |
2299 | return 0; | |
2300 | } | |
3a7bba64 | 2301 | return ifmgd->ave_beacon_signal / 16; |
1dae27f8 | 2302 | } |
0d8a0a17 | 2303 | EXPORT_SYMBOL_GPL(ieee80211_ave_rssi); |
04ecd257 JB |
2304 | |
2305 | u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs) | |
2306 | { | |
2307 | if (!mcs) | |
2308 | return 1; | |
2309 | ||
2310 | /* TODO: consider rx_highest */ | |
2311 | ||
2312 | if (mcs->rx_mask[3]) | |
2313 | return 4; | |
2314 | if (mcs->rx_mask[2]) | |
2315 | return 3; | |
2316 | if (mcs->rx_mask[1]) | |
2317 | return 2; | |
2318 | return 1; | |
2319 | } | |
f4bda337 TP |
2320 | |
2321 | /** | |
2322 | * ieee80211_calculate_rx_timestamp - calculate timestamp in frame | |
2323 | * @local: mac80211 hw info struct | |
2324 | * @status: RX status | |
2325 | * @mpdu_len: total MPDU length (including FCS) | |
2326 | * @mpdu_offset: offset into MPDU to calculate timestamp at | |
2327 | * | |
2328 | * This function calculates the RX timestamp at the given MPDU offset, taking | |
2329 | * into account what the RX timestamp was. An offset of 0 will just normalize | |
2330 | * the timestamp to TSF at beginning of MPDU reception. | |
2331 | */ | |
2332 | u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local, | |
2333 | struct ieee80211_rx_status *status, | |
2334 | unsigned int mpdu_len, | |
2335 | unsigned int mpdu_offset) | |
2336 | { | |
2337 | u64 ts = status->mactime; | |
2338 | struct rate_info ri; | |
2339 | u16 rate; | |
2340 | ||
2341 | if (WARN_ON(!ieee80211_have_rx_timestamp(status))) | |
2342 | return 0; | |
2343 | ||
2344 | memset(&ri, 0, sizeof(ri)); | |
2345 | ||
2346 | /* Fill cfg80211 rate info */ | |
2347 | if (status->flag & RX_FLAG_HT) { | |
2348 | ri.mcs = status->rate_idx; | |
2349 | ri.flags |= RATE_INFO_FLAGS_MCS; | |
2350 | if (status->flag & RX_FLAG_40MHZ) | |
2351 | ri.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; | |
2352 | if (status->flag & RX_FLAG_SHORT_GI) | |
2353 | ri.flags |= RATE_INFO_FLAGS_SHORT_GI; | |
5614618e JB |
2354 | } else if (status->flag & RX_FLAG_VHT) { |
2355 | ri.flags |= RATE_INFO_FLAGS_VHT_MCS; | |
2356 | ri.mcs = status->rate_idx; | |
2357 | ri.nss = status->vht_nss; | |
2358 | if (status->flag & RX_FLAG_40MHZ) | |
2359 | ri.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; | |
1b8d242a | 2360 | if (status->vht_flag & RX_VHT_FLAG_80MHZ) |
5614618e | 2361 | ri.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH; |
1b8d242a | 2362 | if (status->vht_flag & RX_VHT_FLAG_80P80MHZ) |
5614618e | 2363 | ri.flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH; |
1b8d242a | 2364 | if (status->vht_flag & RX_VHT_FLAG_160MHZ) |
5614618e JB |
2365 | ri.flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH; |
2366 | if (status->flag & RX_FLAG_SHORT_GI) | |
2367 | ri.flags |= RATE_INFO_FLAGS_SHORT_GI; | |
f4bda337 TP |
2368 | } else { |
2369 | struct ieee80211_supported_band *sband; | |
2103dec1 SW |
2370 | int shift = 0; |
2371 | int bitrate; | |
2372 | ||
2373 | if (status->flag & RX_FLAG_10MHZ) | |
2374 | shift = 1; | |
2375 | if (status->flag & RX_FLAG_5MHZ) | |
2376 | shift = 2; | |
f4bda337 TP |
2377 | |
2378 | sband = local->hw.wiphy->bands[status->band]; | |
2103dec1 SW |
2379 | bitrate = sband->bitrates[status->rate_idx].bitrate; |
2380 | ri.legacy = DIV_ROUND_UP(bitrate, (1 << shift)); | |
f4bda337 TP |
2381 | } |
2382 | ||
2383 | rate = cfg80211_calculate_bitrate(&ri); | |
d86aa4f8 JB |
2384 | if (WARN_ONCE(!rate, |
2385 | "Invalid bitrate: flags=0x%x, idx=%d, vht_nss=%d\n", | |
2386 | status->flag, status->rate_idx, status->vht_nss)) | |
2387 | return 0; | |
f4bda337 TP |
2388 | |
2389 | /* rewind from end of MPDU */ | |
2390 | if (status->flag & RX_FLAG_MACTIME_END) | |
2391 | ts -= mpdu_len * 8 * 10 / rate; | |
2392 | ||
2393 | ts += mpdu_offset * 8 * 10 / rate; | |
2394 | ||
2395 | return ts; | |
2396 | } | |
164eb02d SW |
2397 | |
2398 | void ieee80211_dfs_cac_cancel(struct ieee80211_local *local) | |
2399 | { | |
2400 | struct ieee80211_sub_if_data *sdata; | |
d2859df5 | 2401 | struct cfg80211_chan_def chandef; |
164eb02d | 2402 | |
34a3740d | 2403 | mutex_lock(&local->mtx); |
164eb02d SW |
2404 | mutex_lock(&local->iflist_mtx); |
2405 | list_for_each_entry(sdata, &local->interfaces, list) { | |
34a3740d JB |
2406 | /* it might be waiting for the local->mtx, but then |
2407 | * by the time it gets it, sdata->wdev.cac_started | |
2408 | * will no longer be true | |
2409 | */ | |
2410 | cancel_delayed_work(&sdata->dfs_cac_timer_work); | |
164eb02d SW |
2411 | |
2412 | if (sdata->wdev.cac_started) { | |
d2859df5 | 2413 | chandef = sdata->vif.bss_conf.chandef; |
164eb02d SW |
2414 | ieee80211_vif_release_channel(sdata); |
2415 | cfg80211_cac_event(sdata->dev, | |
d2859df5 | 2416 | &chandef, |
164eb02d SW |
2417 | NL80211_RADAR_CAC_ABORTED, |
2418 | GFP_KERNEL); | |
2419 | } | |
2420 | } | |
2421 | mutex_unlock(&local->iflist_mtx); | |
34a3740d | 2422 | mutex_unlock(&local->mtx); |
164eb02d SW |
2423 | } |
2424 | ||
2425 | void ieee80211_dfs_radar_detected_work(struct work_struct *work) | |
2426 | { | |
2427 | struct ieee80211_local *local = | |
2428 | container_of(work, struct ieee80211_local, radar_detected_work); | |
84a3d1c9 | 2429 | struct cfg80211_chan_def chandef = local->hw.conf.chandef; |
164eb02d SW |
2430 | |
2431 | ieee80211_dfs_cac_cancel(local); | |
2432 | ||
2433 | if (local->use_chanctx) | |
2434 | /* currently not handled */ | |
2435 | WARN_ON(1); | |
84a3d1c9 | 2436 | else |
164eb02d | 2437 | cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL); |
164eb02d SW |
2438 | } |
2439 | ||
2440 | void ieee80211_radar_detected(struct ieee80211_hw *hw) | |
2441 | { | |
2442 | struct ieee80211_local *local = hw_to_local(hw); | |
2443 | ||
2444 | trace_api_radar_detected(local); | |
2445 | ||
2446 | ieee80211_queue_work(hw, &local->radar_detected_work); | |
2447 | } | |
2448 | EXPORT_SYMBOL(ieee80211_radar_detected); | |
e6b7cde4 SW |
2449 | |
2450 | u32 ieee80211_chandef_downgrade(struct cfg80211_chan_def *c) | |
2451 | { | |
2452 | u32 ret; | |
2453 | int tmp; | |
2454 | ||
2455 | switch (c->width) { | |
2456 | case NL80211_CHAN_WIDTH_20: | |
2457 | c->width = NL80211_CHAN_WIDTH_20_NOHT; | |
2458 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; | |
2459 | break; | |
2460 | case NL80211_CHAN_WIDTH_40: | |
2461 | c->width = NL80211_CHAN_WIDTH_20; | |
2462 | c->center_freq1 = c->chan->center_freq; | |
2463 | ret = IEEE80211_STA_DISABLE_40MHZ | | |
2464 | IEEE80211_STA_DISABLE_VHT; | |
2465 | break; | |
2466 | case NL80211_CHAN_WIDTH_80: | |
2467 | tmp = (30 + c->chan->center_freq - c->center_freq1)/20; | |
2468 | /* n_P40 */ | |
2469 | tmp /= 2; | |
2470 | /* freq_P40 */ | |
2471 | c->center_freq1 = c->center_freq1 - 20 + 40 * tmp; | |
2472 | c->width = NL80211_CHAN_WIDTH_40; | |
2473 | ret = IEEE80211_STA_DISABLE_VHT; | |
2474 | break; | |
2475 | case NL80211_CHAN_WIDTH_80P80: | |
2476 | c->center_freq2 = 0; | |
2477 | c->width = NL80211_CHAN_WIDTH_80; | |
2478 | ret = IEEE80211_STA_DISABLE_80P80MHZ | | |
2479 | IEEE80211_STA_DISABLE_160MHZ; | |
2480 | break; | |
2481 | case NL80211_CHAN_WIDTH_160: | |
2482 | /* n_P20 */ | |
2483 | tmp = (70 + c->chan->center_freq - c->center_freq1)/20; | |
2484 | /* n_P80 */ | |
2485 | tmp /= 4; | |
2486 | c->center_freq1 = c->center_freq1 - 40 + 80 * tmp; | |
2487 | c->width = NL80211_CHAN_WIDTH_80; | |
2488 | ret = IEEE80211_STA_DISABLE_80P80MHZ | | |
2489 | IEEE80211_STA_DISABLE_160MHZ; | |
2490 | break; | |
2491 | default: | |
2492 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2493 | WARN_ON_ONCE(1); | |
2494 | c->width = NL80211_CHAN_WIDTH_20_NOHT; | |
2495 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; | |
2496 | break; | |
2497 | case NL80211_CHAN_WIDTH_5: | |
2498 | case NL80211_CHAN_WIDTH_10: | |
2499 | WARN_ON_ONCE(1); | |
2500 | /* keep c->width */ | |
2501 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; | |
2502 | break; | |
2503 | } | |
2504 | ||
2505 | WARN_ON_ONCE(!cfg80211_chandef_valid(c)); | |
2506 | ||
2507 | return ret; | |
2508 | } | |
687da132 EG |
2509 | |
2510 | /* | |
2511 | * Returns true if smps_mode_new is strictly more restrictive than | |
2512 | * smps_mode_old. | |
2513 | */ | |
2514 | bool ieee80211_smps_is_restrictive(enum ieee80211_smps_mode smps_mode_old, | |
2515 | enum ieee80211_smps_mode smps_mode_new) | |
2516 | { | |
2517 | if (WARN_ON_ONCE(smps_mode_old == IEEE80211_SMPS_AUTOMATIC || | |
2518 | smps_mode_new == IEEE80211_SMPS_AUTOMATIC)) | |
2519 | return false; | |
2520 | ||
2521 | switch (smps_mode_old) { | |
2522 | case IEEE80211_SMPS_STATIC: | |
2523 | return false; | |
2524 | case IEEE80211_SMPS_DYNAMIC: | |
2525 | return smps_mode_new == IEEE80211_SMPS_STATIC; | |
2526 | case IEEE80211_SMPS_OFF: | |
2527 | return smps_mode_new != IEEE80211_SMPS_OFF; | |
2528 | default: | |
2529 | WARN_ON(1); | |
2530 | } | |
2531 | ||
2532 | return false; | |
2533 | } | |
c6da674a CYY |
2534 | |
2535 | int ieee80211_send_action_csa(struct ieee80211_sub_if_data *sdata, | |
2536 | struct cfg80211_csa_settings *csa_settings) | |
2537 | { | |
2538 | struct sk_buff *skb; | |
2539 | struct ieee80211_mgmt *mgmt; | |
2540 | struct ieee80211_local *local = sdata->local; | |
2541 | int freq; | |
2542 | int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.chan_switch) + | |
2543 | sizeof(mgmt->u.action.u.chan_switch); | |
2544 | u8 *pos; | |
2545 | ||
2546 | if (sdata->vif.type != NL80211_IFTYPE_ADHOC && | |
2547 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT) | |
2548 | return -EOPNOTSUPP; | |
2549 | ||
2550 | skb = dev_alloc_skb(local->tx_headroom + hdr_len + | |
2551 | 5 + /* channel switch announcement element */ | |
2552 | 3 + /* secondary channel offset element */ | |
2553 | 8); /* mesh channel switch parameters element */ | |
2554 | if (!skb) | |
2555 | return -ENOMEM; | |
2556 | ||
2557 | skb_reserve(skb, local->tx_headroom); | |
2558 | mgmt = (struct ieee80211_mgmt *)skb_put(skb, hdr_len); | |
2559 | memset(mgmt, 0, hdr_len); | |
2560 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
2561 | IEEE80211_STYPE_ACTION); | |
2562 | ||
2563 | eth_broadcast_addr(mgmt->da); | |
2564 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); | |
2565 | if (ieee80211_vif_is_mesh(&sdata->vif)) { | |
2566 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); | |
2567 | } else { | |
2568 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; | |
2569 | memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); | |
2570 | } | |
2571 | mgmt->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT; | |
2572 | mgmt->u.action.u.chan_switch.action_code = WLAN_ACTION_SPCT_CHL_SWITCH; | |
2573 | pos = skb_put(skb, 5); | |
2574 | *pos++ = WLAN_EID_CHANNEL_SWITCH; /* EID */ | |
2575 | *pos++ = 3; /* IE length */ | |
2576 | *pos++ = csa_settings->block_tx ? 1 : 0; /* CSA mode */ | |
2577 | freq = csa_settings->chandef.chan->center_freq; | |
2578 | *pos++ = ieee80211_frequency_to_channel(freq); /* channel */ | |
2579 | *pos++ = csa_settings->count; /* count */ | |
2580 | ||
2581 | if (csa_settings->chandef.width == NL80211_CHAN_WIDTH_40) { | |
2582 | enum nl80211_channel_type ch_type; | |
2583 | ||
2584 | skb_put(skb, 3); | |
2585 | *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */ | |
2586 | *pos++ = 1; /* IE length */ | |
2587 | ch_type = cfg80211_get_chandef_type(&csa_settings->chandef); | |
2588 | if (ch_type == NL80211_CHAN_HT40PLUS) | |
2589 | *pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | |
2590 | else | |
2591 | *pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW; | |
2592 | } | |
2593 | ||
2594 | if (ieee80211_vif_is_mesh(&sdata->vif)) { | |
2595 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
c6da674a CYY |
2596 | |
2597 | skb_put(skb, 8); | |
2598 | *pos++ = WLAN_EID_CHAN_SWITCH_PARAM; /* EID */ | |
2599 | *pos++ = 6; /* IE length */ | |
2600 | *pos++ = sdata->u.mesh.mshcfg.dot11MeshTTL; /* Mesh TTL */ | |
2601 | *pos = 0x00; /* Mesh Flag: Tx Restrict, Initiator, Reason */ | |
2602 | *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR; | |
2603 | *pos++ |= csa_settings->block_tx ? | |
2604 | WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00; | |
2605 | put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); /* Reason Cd */ | |
2606 | pos += 2; | |
ca91dc97 | 2607 | put_unaligned_le16(ifmsh->pre_value, pos);/* Precedence Value */ |
c6da674a | 2608 | pos += 2; |
c6da674a CYY |
2609 | } |
2610 | ||
2611 | ieee80211_tx_skb(sdata, skb); | |
2612 | return 0; | |
2613 | } | |
2475b1cc MS |
2614 | |
2615 | bool ieee80211_cs_valid(const struct ieee80211_cipher_scheme *cs) | |
2616 | { | |
2617 | return !(cs == NULL || cs->cipher == 0 || | |
2618 | cs->hdr_len < cs->pn_len + cs->pn_off || | |
2619 | cs->hdr_len <= cs->key_idx_off || | |
2620 | cs->key_idx_shift > 7 || | |
2621 | cs->key_idx_mask == 0); | |
2622 | } | |
2623 | ||
2624 | bool ieee80211_cs_list_valid(const struct ieee80211_cipher_scheme *cs, int n) | |
2625 | { | |
2626 | int i; | |
2627 | ||
2628 | /* Ensure we have enough iftype bitmap space for all iftype values */ | |
2629 | WARN_ON((NUM_NL80211_IFTYPES / 8 + 1) > sizeof(cs[0].iftype)); | |
2630 | ||
2631 | for (i = 0; i < n; i++) | |
2632 | if (!ieee80211_cs_valid(&cs[i])) | |
2633 | return false; | |
2634 | ||
2635 | return true; | |
2636 | } | |
2637 | ||
2638 | const struct ieee80211_cipher_scheme * | |
2639 | ieee80211_cs_get(struct ieee80211_local *local, u32 cipher, | |
2640 | enum nl80211_iftype iftype) | |
2641 | { | |
2642 | const struct ieee80211_cipher_scheme *l = local->hw.cipher_schemes; | |
2643 | int n = local->hw.n_cipher_schemes; | |
2644 | int i; | |
2645 | const struct ieee80211_cipher_scheme *cs = NULL; | |
2646 | ||
2647 | for (i = 0; i < n; i++) { | |
2648 | if (l[i].cipher == cipher) { | |
2649 | cs = &l[i]; | |
2650 | break; | |
2651 | } | |
2652 | } | |
2653 | ||
2654 | if (!cs || !(cs->iftype & BIT(iftype))) | |
2655 | return NULL; | |
2656 | ||
2657 | return cs; | |
2658 | } | |
2659 | ||
2660 | int ieee80211_cs_headroom(struct ieee80211_local *local, | |
2661 | struct cfg80211_crypto_settings *crypto, | |
2662 | enum nl80211_iftype iftype) | |
2663 | { | |
2664 | const struct ieee80211_cipher_scheme *cs; | |
2665 | int headroom = IEEE80211_ENCRYPT_HEADROOM; | |
2666 | int i; | |
2667 | ||
2668 | for (i = 0; i < crypto->n_ciphers_pairwise; i++) { | |
2669 | cs = ieee80211_cs_get(local, crypto->ciphers_pairwise[i], | |
2670 | iftype); | |
2671 | ||
2672 | if (cs && headroom < cs->hdr_len) | |
2673 | headroom = cs->hdr_len; | |
2674 | } | |
2675 | ||
2676 | cs = ieee80211_cs_get(local, crypto->cipher_group, iftype); | |
2677 | if (cs && headroom < cs->hdr_len) | |
2678 | headroom = cs->hdr_len; | |
2679 | ||
2680 | return headroom; | |
2681 | } | |
a7022e65 FF |
2682 | |
2683 | static bool | |
2684 | ieee80211_extend_noa_desc(struct ieee80211_noa_data *data, u32 tsf, int i) | |
2685 | { | |
2686 | s32 end = data->desc[i].start + data->desc[i].duration - (tsf + 1); | |
2687 | int skip; | |
2688 | ||
2689 | if (end > 0) | |
2690 | return false; | |
2691 | ||
2692 | /* End time is in the past, check for repetitions */ | |
2693 | skip = DIV_ROUND_UP(-end, data->desc[i].interval); | |
2694 | if (data->count[i] < 255) { | |
2695 | if (data->count[i] <= skip) { | |
2696 | data->count[i] = 0; | |
2697 | return false; | |
2698 | } | |
2699 | ||
2700 | data->count[i] -= skip; | |
2701 | } | |
2702 | ||
2703 | data->desc[i].start += skip * data->desc[i].interval; | |
2704 | ||
2705 | return true; | |
2706 | } | |
2707 | ||
2708 | static bool | |
2709 | ieee80211_extend_absent_time(struct ieee80211_noa_data *data, u32 tsf, | |
2710 | s32 *offset) | |
2711 | { | |
2712 | bool ret = false; | |
2713 | int i; | |
2714 | ||
2715 | for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) { | |
2716 | s32 cur; | |
2717 | ||
2718 | if (!data->count[i]) | |
2719 | continue; | |
2720 | ||
2721 | if (ieee80211_extend_noa_desc(data, tsf + *offset, i)) | |
2722 | ret = true; | |
2723 | ||
2724 | cur = data->desc[i].start - tsf; | |
2725 | if (cur > *offset) | |
2726 | continue; | |
2727 | ||
2728 | cur = data->desc[i].start + data->desc[i].duration - tsf; | |
2729 | if (cur > *offset) | |
2730 | *offset = cur; | |
2731 | } | |
2732 | ||
2733 | return ret; | |
2734 | } | |
2735 | ||
2736 | static u32 | |
2737 | ieee80211_get_noa_absent_time(struct ieee80211_noa_data *data, u32 tsf) | |
2738 | { | |
2739 | s32 offset = 0; | |
2740 | int tries = 0; | |
2741 | /* | |
2742 | * arbitrary limit, used to avoid infinite loops when combined NoA | |
2743 | * descriptors cover the full time period. | |
2744 | */ | |
2745 | int max_tries = 5; | |
2746 | ||
2747 | ieee80211_extend_absent_time(data, tsf, &offset); | |
2748 | do { | |
2749 | if (!ieee80211_extend_absent_time(data, tsf, &offset)) | |
2750 | break; | |
2751 | ||
2752 | tries++; | |
2753 | } while (tries < max_tries); | |
2754 | ||
2755 | return offset; | |
2756 | } | |
2757 | ||
2758 | void ieee80211_update_p2p_noa(struct ieee80211_noa_data *data, u32 tsf) | |
2759 | { | |
2760 | u32 next_offset = BIT(31) - 1; | |
2761 | int i; | |
2762 | ||
2763 | data->absent = 0; | |
2764 | data->has_next_tsf = false; | |
2765 | for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) { | |
2766 | s32 start; | |
2767 | ||
2768 | if (!data->count[i]) | |
2769 | continue; | |
2770 | ||
2771 | ieee80211_extend_noa_desc(data, tsf, i); | |
2772 | start = data->desc[i].start - tsf; | |
2773 | if (start <= 0) | |
2774 | data->absent |= BIT(i); | |
2775 | ||
2776 | if (next_offset > start) | |
2777 | next_offset = start; | |
2778 | ||
2779 | data->has_next_tsf = true; | |
2780 | } | |
2781 | ||
2782 | if (data->absent) | |
2783 | next_offset = ieee80211_get_noa_absent_time(data, tsf); | |
2784 | ||
2785 | data->next_tsf = tsf + next_offset; | |
2786 | } | |
2787 | EXPORT_SYMBOL(ieee80211_update_p2p_noa); | |
2788 | ||
2789 | int ieee80211_parse_p2p_noa(const struct ieee80211_p2p_noa_attr *attr, | |
2790 | struct ieee80211_noa_data *data, u32 tsf) | |
2791 | { | |
2792 | int ret = 0; | |
2793 | int i; | |
2794 | ||
2795 | memset(data, 0, sizeof(*data)); | |
2796 | ||
2797 | for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) { | |
2798 | const struct ieee80211_p2p_noa_desc *desc = &attr->desc[i]; | |
2799 | ||
2800 | if (!desc->count || !desc->duration) | |
2801 | continue; | |
2802 | ||
2803 | data->count[i] = desc->count; | |
2804 | data->desc[i].start = le32_to_cpu(desc->start_time); | |
2805 | data->desc[i].duration = le32_to_cpu(desc->duration); | |
2806 | data->desc[i].interval = le32_to_cpu(desc->interval); | |
2807 | ||
2808 | if (data->count[i] > 1 && | |
2809 | data->desc[i].interval < data->desc[i].duration) | |
2810 | continue; | |
2811 | ||
2812 | ieee80211_extend_noa_desc(data, tsf, i); | |
2813 | ret++; | |
2814 | } | |
2815 | ||
2816 | if (ret) | |
2817 | ieee80211_update_p2p_noa(data, tsf); | |
2818 | ||
2819 | return ret; | |
2820 | } | |
2821 | EXPORT_SYMBOL(ieee80211_parse_p2p_noa); | |
057d5f4b TP |
2822 | |
2823 | void ieee80211_recalc_dtim(struct ieee80211_local *local, | |
2824 | struct ieee80211_sub_if_data *sdata) | |
2825 | { | |
2826 | u64 tsf = drv_get_tsf(local, sdata); | |
2827 | u64 dtim_count = 0; | |
2828 | u16 beacon_int = sdata->vif.bss_conf.beacon_int * 1024; | |
2829 | u8 dtim_period = sdata->vif.bss_conf.dtim_period; | |
2830 | struct ps_data *ps; | |
2831 | u8 bcns_from_dtim; | |
2832 | ||
2833 | if (tsf == -1ULL || !beacon_int || !dtim_period) | |
2834 | return; | |
2835 | ||
2836 | if (sdata->vif.type == NL80211_IFTYPE_AP || | |
2837 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { | |
2838 | if (!sdata->bss) | |
2839 | return; | |
2840 | ||
2841 | ps = &sdata->bss->ps; | |
2842 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { | |
2843 | ps = &sdata->u.mesh.ps; | |
2844 | } else { | |
2845 | return; | |
2846 | } | |
2847 | ||
2848 | /* | |
2849 | * actually finds last dtim_count, mac80211 will update in | |
2850 | * __beacon_add_tim(). | |
2851 | * dtim_count = dtim_period - (tsf / bcn_int) % dtim_period | |
2852 | */ | |
2853 | do_div(tsf, beacon_int); | |
2854 | bcns_from_dtim = do_div(tsf, dtim_period); | |
2855 | /* just had a DTIM */ | |
2856 | if (!bcns_from_dtim) | |
2857 | dtim_count = 0; | |
2858 | else | |
2859 | dtim_count = dtim_period - bcns_from_dtim; | |
2860 | ||
2861 | ps->dtim_count = dtim_count; | |
2862 | } | |
73de86a3 LC |
2863 | |
2864 | int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, | |
2865 | const struct cfg80211_chan_def *chandef, | |
2866 | enum ieee80211_chanctx_mode chanmode, | |
2867 | u8 radar_detect) | |
2868 | { | |
2869 | struct ieee80211_local *local = sdata->local; | |
2870 | struct ieee80211_sub_if_data *sdata_iter; | |
2871 | enum nl80211_iftype iftype = sdata->wdev.iftype; | |
2872 | int num[NUM_NL80211_IFTYPES]; | |
2873 | struct ieee80211_chanctx *ctx; | |
b6a55015 | 2874 | int num_different_channels = 0; |
73de86a3 LC |
2875 | int total = 1; |
2876 | ||
2877 | lockdep_assert_held(&local->chanctx_mtx); | |
2878 | ||
2879 | if (WARN_ON(hweight32(radar_detect) > 1)) | |
2880 | return -EINVAL; | |
2881 | ||
b6a55015 LC |
2882 | if (WARN_ON(chandef && chanmode == IEEE80211_CHANCTX_SHARED && |
2883 | !chandef->chan)) | |
73de86a3 LC |
2884 | return -EINVAL; |
2885 | ||
b6a55015 LC |
2886 | if (chandef) |
2887 | num_different_channels = 1; | |
2888 | ||
73de86a3 LC |
2889 | if (WARN_ON(iftype >= NUM_NL80211_IFTYPES)) |
2890 | return -EINVAL; | |
2891 | ||
2892 | /* Always allow software iftypes */ | |
2893 | if (local->hw.wiphy->software_iftypes & BIT(iftype)) { | |
2894 | if (radar_detect) | |
2895 | return -EINVAL; | |
2896 | return 0; | |
2897 | } | |
2898 | ||
2899 | memset(num, 0, sizeof(num)); | |
2900 | ||
2901 | if (iftype != NL80211_IFTYPE_UNSPECIFIED) | |
2902 | num[iftype] = 1; | |
2903 | ||
2904 | list_for_each_entry(ctx, &local->chanctx_list, list) { | |
2905 | if (ctx->conf.radar_enabled) | |
2906 | radar_detect |= BIT(ctx->conf.def.width); | |
2907 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) { | |
2908 | num_different_channels++; | |
2909 | continue; | |
2910 | } | |
b6a55015 | 2911 | if (chandef && chanmode == IEEE80211_CHANCTX_SHARED && |
73de86a3 LC |
2912 | cfg80211_chandef_compatible(chandef, |
2913 | &ctx->conf.def)) | |
2914 | continue; | |
2915 | num_different_channels++; | |
2916 | } | |
2917 | ||
2918 | list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) { | |
2919 | struct wireless_dev *wdev_iter; | |
2920 | ||
2921 | wdev_iter = &sdata_iter->wdev; | |
2922 | ||
2923 | if (sdata_iter == sdata || | |
2924 | rcu_access_pointer(sdata_iter->vif.chanctx_conf) == NULL || | |
2925 | local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype)) | |
2926 | continue; | |
2927 | ||
2928 | num[wdev_iter->iftype]++; | |
2929 | total++; | |
2930 | } | |
2931 | ||
2932 | if (total == 1 && !radar_detect) | |
2933 | return 0; | |
2934 | ||
2935 | return cfg80211_check_combinations(local->hw.wiphy, | |
2936 | num_different_channels, | |
2937 | radar_detect, num); | |
2938 | } | |
6fa001bc MK |
2939 | |
2940 | static void | |
2941 | ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c, | |
2942 | void *data) | |
2943 | { | |
2944 | u32 *max_num_different_channels = data; | |
2945 | ||
2946 | *max_num_different_channels = max(*max_num_different_channels, | |
2947 | c->num_different_channels); | |
2948 | } | |
2949 | ||
2950 | int ieee80211_max_num_channels(struct ieee80211_local *local) | |
2951 | { | |
2952 | struct ieee80211_sub_if_data *sdata; | |
2953 | int num[NUM_NL80211_IFTYPES] = {}; | |
2954 | struct ieee80211_chanctx *ctx; | |
2955 | int num_different_channels = 0; | |
2956 | u8 radar_detect = 0; | |
2957 | u32 max_num_different_channels = 1; | |
2958 | int err; | |
2959 | ||
2960 | lockdep_assert_held(&local->chanctx_mtx); | |
2961 | ||
2962 | list_for_each_entry(ctx, &local->chanctx_list, list) { | |
2963 | num_different_channels++; | |
2964 | ||
2965 | if (ctx->conf.radar_enabled) | |
2966 | radar_detect |= BIT(ctx->conf.def.width); | |
2967 | } | |
2968 | ||
2969 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
2970 | num[sdata->wdev.iftype]++; | |
2971 | ||
2972 | err = cfg80211_iter_combinations(local->hw.wiphy, | |
2973 | num_different_channels, radar_detect, | |
2974 | num, ieee80211_iter_max_chans, | |
2975 | &max_num_different_channels); | |
2976 | if (err < 0) | |
2977 | return err; | |
2978 | ||
2979 | return max_num_different_channels; | |
2980 | } |