]>
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> | |
16 | #include <linux/types.h> | |
17 | #include <linux/slab.h> | |
18 | #include <linux/skbuff.h> | |
19 | #include <linux/etherdevice.h> | |
20 | #include <linux/if_arp.h> | |
c2d1560a | 21 | #include <linux/bitmap.h> |
881d966b | 22 | #include <net/net_namespace.h> |
c2d1560a | 23 | #include <net/cfg80211.h> |
dabeb344 | 24 | #include <net/rtnetlink.h> |
c2d1560a JB |
25 | |
26 | #include "ieee80211_i.h" | |
24487981 | 27 | #include "driver-ops.h" |
2c8dccc7 | 28 | #include "rate.h" |
ee385855 | 29 | #include "mesh.h" |
c2d1560a | 30 | #include "wme.h" |
f2753ddb | 31 | #include "led.h" |
fffd0934 | 32 | #include "wep.h" |
c2d1560a JB |
33 | |
34 | /* privid for wiphys to determine whether they belong to us or not */ | |
35 | void *mac80211_wiphy_privid = &mac80211_wiphy_privid; | |
36 | ||
9a95371a LR |
37 | struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) |
38 | { | |
39 | struct ieee80211_local *local; | |
40 | BUG_ON(!wiphy); | |
41 | ||
42 | local = wiphy_priv(wiphy); | |
43 | return &local->hw; | |
44 | } | |
45 | EXPORT_SYMBOL(wiphy_to_ieee80211_hw); | |
c2d1560a | 46 | |
71364716 | 47 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
05c914fe | 48 | enum nl80211_iftype type) |
c2d1560a | 49 | { |
a494bb1c | 50 | __le16 fc = hdr->frame_control; |
c2d1560a | 51 | |
98f0b0a3 RR |
52 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
53 | if (len < 16) | |
c2d1560a JB |
54 | return NULL; |
55 | ||
a494bb1c | 56 | if (ieee80211_is_data(fc)) { |
98f0b0a3 RR |
57 | if (len < 24) /* drop incorrect hdr len (data) */ |
58 | return NULL; | |
a494bb1c HH |
59 | |
60 | if (ieee80211_has_a4(fc)) | |
c2d1560a | 61 | return NULL; |
a494bb1c HH |
62 | if (ieee80211_has_tods(fc)) |
63 | return hdr->addr1; | |
64 | if (ieee80211_has_fromds(fc)) | |
c2d1560a | 65 | return hdr->addr2; |
a494bb1c HH |
66 | |
67 | return hdr->addr3; | |
68 | } | |
69 | ||
70 | if (ieee80211_is_mgmt(fc)) { | |
98f0b0a3 RR |
71 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
72 | return NULL; | |
c2d1560a | 73 | return hdr->addr3; |
a494bb1c HH |
74 | } |
75 | ||
76 | if (ieee80211_is_ctl(fc)) { | |
77 | if(ieee80211_is_pspoll(fc)) | |
c2d1560a | 78 | return hdr->addr1; |
a494bb1c HH |
79 | |
80 | if (ieee80211_is_back_req(fc)) { | |
71364716 | 81 | switch (type) { |
05c914fe | 82 | case NL80211_IFTYPE_STATION: |
71364716 | 83 | return hdr->addr2; |
05c914fe JB |
84 | case NL80211_IFTYPE_AP: |
85 | case NL80211_IFTYPE_AP_VLAN: | |
71364716 RR |
86 | return hdr->addr1; |
87 | default: | |
a494bb1c | 88 | break; /* fall through to the return */ |
71364716 RR |
89 | } |
90 | } | |
c2d1560a JB |
91 | } |
92 | ||
93 | return NULL; | |
94 | } | |
95 | ||
5cf121c3 | 96 | void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) |
c2d1560a | 97 | { |
2de8e0d9 JB |
98 | struct sk_buff *skb = tx->skb; |
99 | struct ieee80211_hdr *hdr; | |
100 | ||
101 | do { | |
102 | hdr = (struct ieee80211_hdr *) skb->data; | |
103 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
104 | } while ((skb = skb->next)); | |
c2d1560a JB |
105 | } |
106 | ||
107 | int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, | |
108 | int rate, int erp, int short_preamble) | |
109 | { | |
110 | int dur; | |
111 | ||
112 | /* calculate duration (in microseconds, rounded up to next higher | |
113 | * integer if it includes a fractional microsecond) to send frame of | |
114 | * len bytes (does not include FCS) at the given rate. Duration will | |
115 | * also include SIFS. | |
116 | * | |
117 | * rate is in 100 kbps, so divident is multiplied by 10 in the | |
118 | * DIV_ROUND_UP() operations. | |
119 | */ | |
120 | ||
8318d78a | 121 | if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) { |
c2d1560a JB |
122 | /* |
123 | * OFDM: | |
124 | * | |
125 | * N_DBPS = DATARATE x 4 | |
126 | * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) | |
127 | * (16 = SIGNAL time, 6 = tail bits) | |
128 | * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext | |
129 | * | |
130 | * T_SYM = 4 usec | |
131 | * 802.11a - 17.5.2: aSIFSTime = 16 usec | |
132 | * 802.11g - 19.8.4: aSIFSTime = 10 usec + | |
133 | * signal ext = 6 usec | |
134 | */ | |
c2d1560a JB |
135 | dur = 16; /* SIFS + signal ext */ |
136 | dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */ | |
137 | dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */ | |
138 | dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, | |
139 | 4 * rate); /* T_SYM x N_SYM */ | |
140 | } else { | |
141 | /* | |
142 | * 802.11b or 802.11g with 802.11b compatibility: | |
143 | * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + | |
144 | * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. | |
145 | * | |
146 | * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 | |
147 | * aSIFSTime = 10 usec | |
148 | * aPreambleLength = 144 usec or 72 usec with short preamble | |
149 | * aPLCPHeaderLength = 48 usec or 24 usec with short preamble | |
150 | */ | |
151 | dur = 10; /* aSIFSTime = 10 usec */ | |
152 | dur += short_preamble ? (72 + 24) : (144 + 48); | |
153 | ||
154 | dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); | |
155 | } | |
156 | ||
157 | return dur; | |
158 | } | |
159 | ||
160 | /* Exported duration function for driver use */ | |
32bfd35d JB |
161 | __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, |
162 | struct ieee80211_vif *vif, | |
8318d78a JB |
163 | size_t frame_len, |
164 | struct ieee80211_rate *rate) | |
c2d1560a JB |
165 | { |
166 | struct ieee80211_local *local = hw_to_local(hw); | |
25d834e1 | 167 | struct ieee80211_sub_if_data *sdata; |
c2d1560a JB |
168 | u16 dur; |
169 | int erp; | |
25d834e1 | 170 | bool short_preamble = false; |
c2d1560a | 171 | |
8318d78a | 172 | erp = 0; |
25d834e1 JB |
173 | if (vif) { |
174 | sdata = vif_to_sdata(vif); | |
bda3933a | 175 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
176 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
177 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
178 | } | |
8318d78a JB |
179 | |
180 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp, | |
25d834e1 | 181 | short_preamble); |
c2d1560a JB |
182 | |
183 | return cpu_to_le16(dur); | |
184 | } | |
185 | EXPORT_SYMBOL(ieee80211_generic_frame_duration); | |
186 | ||
32bfd35d JB |
187 | __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, |
188 | struct ieee80211_vif *vif, size_t frame_len, | |
e039fa4a | 189 | const struct ieee80211_tx_info *frame_txctl) |
c2d1560a JB |
190 | { |
191 | struct ieee80211_local *local = hw_to_local(hw); | |
192 | struct ieee80211_rate *rate; | |
25d834e1 | 193 | struct ieee80211_sub_if_data *sdata; |
471b3efd | 194 | bool short_preamble; |
c2d1560a JB |
195 | int erp; |
196 | u16 dur; | |
2e92e6f2 JB |
197 | struct ieee80211_supported_band *sband; |
198 | ||
199 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
c2d1560a | 200 | |
25d834e1 | 201 | short_preamble = false; |
7e9ed188 | 202 | |
e039fa4a | 203 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
8318d78a JB |
204 | |
205 | erp = 0; | |
25d834e1 JB |
206 | if (vif) { |
207 | sdata = vif_to_sdata(vif); | |
bda3933a | 208 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
209 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
210 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
211 | } | |
c2d1560a JB |
212 | |
213 | /* CTS duration */ | |
8318d78a | 214 | dur = ieee80211_frame_duration(local, 10, rate->bitrate, |
c2d1560a JB |
215 | erp, short_preamble); |
216 | /* Data frame duration */ | |
8318d78a | 217 | dur += ieee80211_frame_duration(local, frame_len, rate->bitrate, |
c2d1560a JB |
218 | erp, short_preamble); |
219 | /* ACK duration */ | |
8318d78a | 220 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
c2d1560a JB |
221 | erp, short_preamble); |
222 | ||
223 | return cpu_to_le16(dur); | |
224 | } | |
225 | EXPORT_SYMBOL(ieee80211_rts_duration); | |
226 | ||
32bfd35d JB |
227 | __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, |
228 | struct ieee80211_vif *vif, | |
c2d1560a | 229 | size_t frame_len, |
e039fa4a | 230 | const struct ieee80211_tx_info *frame_txctl) |
c2d1560a JB |
231 | { |
232 | struct ieee80211_local *local = hw_to_local(hw); | |
233 | struct ieee80211_rate *rate; | |
25d834e1 | 234 | struct ieee80211_sub_if_data *sdata; |
471b3efd | 235 | bool short_preamble; |
c2d1560a JB |
236 | int erp; |
237 | u16 dur; | |
2e92e6f2 JB |
238 | struct ieee80211_supported_band *sband; |
239 | ||
240 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
c2d1560a | 241 | |
25d834e1 | 242 | short_preamble = false; |
7e9ed188 | 243 | |
e039fa4a | 244 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
8318d78a | 245 | erp = 0; |
25d834e1 JB |
246 | if (vif) { |
247 | sdata = vif_to_sdata(vif); | |
bda3933a | 248 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
249 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
250 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
251 | } | |
c2d1560a JB |
252 | |
253 | /* Data frame duration */ | |
8318d78a | 254 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, |
c2d1560a | 255 | erp, short_preamble); |
e039fa4a | 256 | if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { |
c2d1560a | 257 | /* ACK duration */ |
8318d78a | 258 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
c2d1560a JB |
259 | erp, short_preamble); |
260 | } | |
261 | ||
262 | return cpu_to_le16(dur); | |
263 | } | |
264 | EXPORT_SYMBOL(ieee80211_ctstoself_duration); | |
265 | ||
ce7c9111 KV |
266 | static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, |
267 | enum queue_stop_reason reason) | |
c2d1560a JB |
268 | { |
269 | struct ieee80211_local *local = hw_to_local(hw); | |
cf0277e7 | 270 | struct ieee80211_sub_if_data *sdata; |
c2d1560a | 271 | |
b5878a2d JB |
272 | trace_wake_queue(local, queue, reason); |
273 | ||
e4e72fb4 JB |
274 | if (WARN_ON(queue >= hw->queues)) |
275 | return; | |
ce7c9111 | 276 | |
96f5e66e JB |
277 | __clear_bit(reason, &local->queue_stop_reasons[queue]); |
278 | ||
279 | if (local->queue_stop_reasons[queue] != 0) | |
280 | /* someone still has this queue stopped */ | |
281 | return; | |
282 | ||
7236fe29 JB |
283 | if (skb_queue_empty(&local->pending[queue])) { |
284 | rcu_read_lock(); | |
5b714c6a JB |
285 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
286 | if (test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) | |
287 | continue; | |
2337db8d | 288 | netif_wake_subqueue(sdata->dev, queue); |
5b714c6a | 289 | } |
7236fe29 JB |
290 | rcu_read_unlock(); |
291 | } else | |
3b8d81e0 | 292 | tasklet_schedule(&local->tx_pending_tasklet); |
c2d1560a | 293 | } |
ce7c9111 | 294 | |
96f5e66e JB |
295 | void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, |
296 | enum queue_stop_reason reason) | |
ce7c9111 KV |
297 | { |
298 | struct ieee80211_local *local = hw_to_local(hw); | |
299 | unsigned long flags; | |
300 | ||
301 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
302 | __ieee80211_wake_queue(hw, queue, reason); | |
303 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
304 | } | |
305 | ||
306 | void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) | |
307 | { | |
308 | ieee80211_wake_queue_by_reason(hw, queue, | |
309 | IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
310 | } | |
c2d1560a JB |
311 | EXPORT_SYMBOL(ieee80211_wake_queue); |
312 | ||
ce7c9111 KV |
313 | static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, |
314 | enum queue_stop_reason reason) | |
c2d1560a JB |
315 | { |
316 | struct ieee80211_local *local = hw_to_local(hw); | |
cf0277e7 | 317 | struct ieee80211_sub_if_data *sdata; |
c2d1560a | 318 | |
b5878a2d JB |
319 | trace_stop_queue(local, queue, reason); |
320 | ||
e4e72fb4 JB |
321 | if (WARN_ON(queue >= hw->queues)) |
322 | return; | |
96f5e66e | 323 | |
2a577d98 | 324 | __set_bit(reason, &local->queue_stop_reasons[queue]); |
cf0277e7 JB |
325 | |
326 | rcu_read_lock(); | |
327 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
2337db8d | 328 | netif_stop_subqueue(sdata->dev, queue); |
cf0277e7 | 329 | rcu_read_unlock(); |
c2d1560a | 330 | } |
ce7c9111 | 331 | |
96f5e66e JB |
332 | void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, |
333 | enum queue_stop_reason reason) | |
ce7c9111 KV |
334 | { |
335 | struct ieee80211_local *local = hw_to_local(hw); | |
336 | unsigned long flags; | |
337 | ||
338 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
339 | __ieee80211_stop_queue(hw, queue, reason); | |
340 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
341 | } | |
342 | ||
343 | void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) | |
344 | { | |
345 | ieee80211_stop_queue_by_reason(hw, queue, | |
346 | IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
347 | } | |
c2d1560a JB |
348 | EXPORT_SYMBOL(ieee80211_stop_queue); |
349 | ||
8f77f384 JB |
350 | void ieee80211_add_pending_skb(struct ieee80211_local *local, |
351 | struct sk_buff *skb) | |
352 | { | |
353 | struct ieee80211_hw *hw = &local->hw; | |
354 | unsigned long flags; | |
355 | int queue = skb_get_queue_mapping(skb); | |
a7bc376c JB |
356 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
357 | ||
358 | if (WARN_ON(!info->control.vif)) { | |
0819663d | 359 | kfree_skb(skb); |
a7bc376c JB |
360 | return; |
361 | } | |
8f77f384 JB |
362 | |
363 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
364 | __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD); | |
3b8d81e0 | 365 | __skb_queue_tail(&local->pending[queue], skb); |
8f77f384 JB |
366 | __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD); |
367 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
368 | } | |
369 | ||
b0b97a8a JB |
370 | void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local, |
371 | struct sk_buff_head *skbs, | |
372 | void (*fn)(void *data), void *data) | |
8f77f384 JB |
373 | { |
374 | struct ieee80211_hw *hw = &local->hw; | |
375 | struct sk_buff *skb; | |
376 | unsigned long flags; | |
b0b97a8a | 377 | int queue, i; |
8f77f384 JB |
378 | |
379 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
380 | for (i = 0; i < hw->queues; i++) | |
381 | __ieee80211_stop_queue(hw, i, | |
382 | IEEE80211_QUEUE_STOP_REASON_SKB_ADD); | |
383 | ||
384 | while ((skb = skb_dequeue(skbs))) { | |
a7bc376c JB |
385 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
386 | ||
387 | if (WARN_ON(!info->control.vif)) { | |
0819663d | 388 | kfree_skb(skb); |
a7bc376c JB |
389 | continue; |
390 | } | |
391 | ||
8f77f384 | 392 | queue = skb_get_queue_mapping(skb); |
3b8d81e0 | 393 | __skb_queue_tail(&local->pending[queue], skb); |
8f77f384 JB |
394 | } |
395 | ||
50a9432d JB |
396 | if (fn) |
397 | fn(data); | |
398 | ||
3b8d81e0 | 399 | for (i = 0; i < hw->queues; i++) |
8f77f384 JB |
400 | __ieee80211_wake_queue(hw, i, |
401 | IEEE80211_QUEUE_STOP_REASON_SKB_ADD); | |
8f77f384 | 402 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
8f77f384 JB |
403 | } |
404 | ||
b0b97a8a JB |
405 | void ieee80211_add_pending_skbs(struct ieee80211_local *local, |
406 | struct sk_buff_head *skbs) | |
50a9432d | 407 | { |
b0b97a8a | 408 | ieee80211_add_pending_skbs_fn(local, skbs, NULL, NULL); |
50a9432d JB |
409 | } |
410 | ||
ce7c9111 KV |
411 | void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, |
412 | enum queue_stop_reason reason) | |
c2d1560a | 413 | { |
ce7c9111 KV |
414 | struct ieee80211_local *local = hw_to_local(hw); |
415 | unsigned long flags; | |
c2d1560a JB |
416 | int i; |
417 | ||
ce7c9111 KV |
418 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
419 | ||
96f5e66e | 420 | for (i = 0; i < hw->queues; i++) |
ce7c9111 KV |
421 | __ieee80211_stop_queue(hw, i, reason); |
422 | ||
423 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
424 | } | |
425 | ||
426 | void ieee80211_stop_queues(struct ieee80211_hw *hw) | |
427 | { | |
428 | ieee80211_stop_queues_by_reason(hw, | |
429 | IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
c2d1560a JB |
430 | } |
431 | EXPORT_SYMBOL(ieee80211_stop_queues); | |
432 | ||
92ab8535 TW |
433 | int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) |
434 | { | |
435 | struct ieee80211_local *local = hw_to_local(hw); | |
3b8d81e0 JB |
436 | unsigned long flags; |
437 | int ret; | |
96f5e66e | 438 | |
e4e72fb4 JB |
439 | if (WARN_ON(queue >= hw->queues)) |
440 | return true; | |
96f5e66e | 441 | |
3b8d81e0 JB |
442 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
443 | ret = !!local->queue_stop_reasons[queue]; | |
444 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
445 | return ret; | |
92ab8535 TW |
446 | } |
447 | EXPORT_SYMBOL(ieee80211_queue_stopped); | |
448 | ||
ce7c9111 KV |
449 | void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, |
450 | enum queue_stop_reason reason) | |
c2d1560a | 451 | { |
ce7c9111 KV |
452 | struct ieee80211_local *local = hw_to_local(hw); |
453 | unsigned long flags; | |
c2d1560a JB |
454 | int i; |
455 | ||
ce7c9111 KV |
456 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
457 | ||
e4e72fb4 | 458 | for (i = 0; i < hw->queues; i++) |
ce7c9111 KV |
459 | __ieee80211_wake_queue(hw, i, reason); |
460 | ||
461 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
462 | } | |
463 | ||
464 | void ieee80211_wake_queues(struct ieee80211_hw *hw) | |
465 | { | |
466 | ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
c2d1560a JB |
467 | } |
468 | EXPORT_SYMBOL(ieee80211_wake_queues); | |
dabeb344 | 469 | |
32bfd35d JB |
470 | void ieee80211_iterate_active_interfaces( |
471 | struct ieee80211_hw *hw, | |
472 | void (*iterator)(void *data, u8 *mac, | |
473 | struct ieee80211_vif *vif), | |
474 | void *data) | |
dabeb344 JB |
475 | { |
476 | struct ieee80211_local *local = hw_to_local(hw); | |
477 | struct ieee80211_sub_if_data *sdata; | |
478 | ||
c771c9d8 | 479 | mutex_lock(&local->iflist_mtx); |
2f561feb ID |
480 | |
481 | list_for_each_entry(sdata, &local->interfaces, list) { | |
482 | switch (sdata->vif.type) { | |
05c914fe JB |
483 | case NL80211_IFTYPE_MONITOR: |
484 | case NL80211_IFTYPE_AP_VLAN: | |
2f561feb | 485 | continue; |
2ca27bcf | 486 | default: |
2f561feb ID |
487 | break; |
488 | } | |
9607e6b6 | 489 | if (ieee80211_sdata_running(sdata)) |
47846c9b | 490 | iterator(data, sdata->vif.addr, |
2f561feb ID |
491 | &sdata->vif); |
492 | } | |
493 | ||
c771c9d8 | 494 | mutex_unlock(&local->iflist_mtx); |
2f561feb ID |
495 | } |
496 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); | |
497 | ||
498 | void ieee80211_iterate_active_interfaces_atomic( | |
499 | struct ieee80211_hw *hw, | |
500 | void (*iterator)(void *data, u8 *mac, | |
501 | struct ieee80211_vif *vif), | |
502 | void *data) | |
503 | { | |
504 | struct ieee80211_local *local = hw_to_local(hw); | |
505 | struct ieee80211_sub_if_data *sdata; | |
506 | ||
e38bad47 | 507 | rcu_read_lock(); |
dabeb344 | 508 | |
e38bad47 | 509 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
51fb61e7 | 510 | switch (sdata->vif.type) { |
05c914fe JB |
511 | case NL80211_IFTYPE_MONITOR: |
512 | case NL80211_IFTYPE_AP_VLAN: | |
dabeb344 | 513 | continue; |
2ca27bcf | 514 | default: |
dabeb344 JB |
515 | break; |
516 | } | |
9607e6b6 | 517 | if (ieee80211_sdata_running(sdata)) |
47846c9b | 518 | iterator(data, sdata->vif.addr, |
32bfd35d | 519 | &sdata->vif); |
dabeb344 | 520 | } |
e38bad47 JB |
521 | |
522 | rcu_read_unlock(); | |
dabeb344 | 523 | } |
2f561feb | 524 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); |
37ffc8da | 525 | |
42935eca LR |
526 | /* |
527 | * Nothing should have been stuffed into the workqueue during | |
528 | * the suspend->resume cycle. If this WARN is seen then there | |
529 | * is a bug with either the driver suspend or something in | |
530 | * mac80211 stuffing into the workqueue which we haven't yet | |
531 | * cleared during mac80211's suspend cycle. | |
532 | */ | |
533 | static bool ieee80211_can_queue_work(struct ieee80211_local *local) | |
534 | { | |
ceb99fe0 JB |
535 | if (WARN(local->suspended && !local->resuming, |
536 | "queueing ieee80211 work while going to suspend\n")) | |
537 | return false; | |
42935eca LR |
538 | |
539 | return true; | |
540 | } | |
541 | ||
542 | void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work) | |
543 | { | |
544 | struct ieee80211_local *local = hw_to_local(hw); | |
545 | ||
546 | if (!ieee80211_can_queue_work(local)) | |
547 | return; | |
548 | ||
549 | queue_work(local->workqueue, work); | |
550 | } | |
551 | EXPORT_SYMBOL(ieee80211_queue_work); | |
552 | ||
553 | void ieee80211_queue_delayed_work(struct ieee80211_hw *hw, | |
554 | struct delayed_work *dwork, | |
555 | unsigned long delay) | |
556 | { | |
557 | struct ieee80211_local *local = hw_to_local(hw); | |
558 | ||
559 | if (!ieee80211_can_queue_work(local)) | |
560 | return; | |
561 | ||
562 | queue_delayed_work(local->workqueue, dwork, delay); | |
563 | } | |
564 | EXPORT_SYMBOL(ieee80211_queue_delayed_work); | |
565 | ||
37ffc8da JB |
566 | void ieee802_11_parse_elems(u8 *start, size_t len, |
567 | struct ieee802_11_elems *elems) | |
d91f36db JB |
568 | { |
569 | ieee802_11_parse_elems_crc(start, len, elems, 0, 0); | |
570 | } | |
571 | ||
5825fe10 JB |
572 | void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) |
573 | { | |
574 | struct ieee80211_local *local = sdata->local; | |
575 | struct ieee80211_tx_queue_params qparam; | |
aa837e1d JB |
576 | int queue; |
577 | bool use_11b; | |
578 | int aCWmin, aCWmax; | |
5825fe10 JB |
579 | |
580 | if (!local->ops->conf_tx) | |
581 | return; | |
582 | ||
583 | memset(&qparam, 0, sizeof(qparam)); | |
584 | ||
aa837e1d JB |
585 | use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) && |
586 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE); | |
5825fe10 | 587 | |
aa837e1d JB |
588 | for (queue = 0; queue < local_to_hw(local)->queues; queue++) { |
589 | /* Set defaults according to 802.11-2007 Table 7-37 */ | |
590 | aCWmax = 1023; | |
591 | if (use_11b) | |
592 | aCWmin = 31; | |
593 | else | |
594 | aCWmin = 15; | |
595 | ||
596 | switch (queue) { | |
597 | case 3: /* AC_BK */ | |
7ba10a8e JB |
598 | qparam.cw_max = aCWmax; |
599 | qparam.cw_min = aCWmin; | |
aa837e1d JB |
600 | qparam.txop = 0; |
601 | qparam.aifs = 7; | |
602 | break; | |
603 | default: /* never happens but let's not leave undefined */ | |
604 | case 2: /* AC_BE */ | |
7ba10a8e JB |
605 | qparam.cw_max = aCWmax; |
606 | qparam.cw_min = aCWmin; | |
aa837e1d JB |
607 | qparam.txop = 0; |
608 | qparam.aifs = 3; | |
609 | break; | |
610 | case 1: /* AC_VI */ | |
611 | qparam.cw_max = aCWmin; | |
612 | qparam.cw_min = (aCWmin + 1) / 2 - 1; | |
613 | if (use_11b) | |
614 | qparam.txop = 6016/32; | |
615 | else | |
616 | qparam.txop = 3008/32; | |
617 | qparam.aifs = 2; | |
618 | break; | |
619 | case 0: /* AC_VO */ | |
620 | qparam.cw_max = (aCWmin + 1) / 2 - 1; | |
621 | qparam.cw_min = (aCWmin + 1) / 4 - 1; | |
622 | if (use_11b) | |
623 | qparam.txop = 3264/32; | |
624 | else | |
625 | qparam.txop = 1504/32; | |
626 | qparam.aifs = 2; | |
627 | break; | |
628 | } | |
5825fe10 | 629 | |
ab13315a KV |
630 | qparam.uapsd = false; |
631 | ||
f6f3def3 EP |
632 | sdata->tx_conf[queue] = qparam; |
633 | drv_conf_tx(local, sdata, queue, &qparam); | |
aa837e1d | 634 | } |
e1b3ec1a SG |
635 | |
636 | /* after reinitialize QoS TX queues setting to default, | |
637 | * disable QoS at all */ | |
d9734979 S |
638 | |
639 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) { | |
640 | sdata->vif.bss_conf.qos = | |
641 | sdata->vif.type != NL80211_IFTYPE_STATION; | |
642 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); | |
643 | } | |
5825fe10 | 644 | } |
e50db65c | 645 | |
46900298 JB |
646 | void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
647 | const size_t supp_rates_len, | |
648 | const u8 *supp_rates) | |
649 | { | |
650 | struct ieee80211_local *local = sdata->local; | |
651 | int i, have_higher_than_11mbit = 0; | |
652 | ||
653 | /* cf. IEEE 802.11 9.2.12 */ | |
654 | for (i = 0; i < supp_rates_len; i++) | |
655 | if ((supp_rates[i] & 0x7f) * 5 > 110) | |
656 | have_higher_than_11mbit = 1; | |
657 | ||
658 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
659 | have_higher_than_11mbit) | |
660 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
661 | else | |
662 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
663 | ||
664 | ieee80211_set_wmm_default(sdata); | |
665 | } | |
666 | ||
881d948c | 667 | u32 ieee80211_mandatory_rates(struct ieee80211_local *local, |
96dd22ac JB |
668 | enum ieee80211_band band) |
669 | { | |
670 | struct ieee80211_supported_band *sband; | |
671 | struct ieee80211_rate *bitrates; | |
881d948c | 672 | u32 mandatory_rates; |
96dd22ac JB |
673 | enum ieee80211_rate_flags mandatory_flag; |
674 | int i; | |
675 | ||
676 | sband = local->hw.wiphy->bands[band]; | |
677 | if (!sband) { | |
678 | WARN_ON(1); | |
679 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
680 | } | |
681 | ||
682 | if (band == IEEE80211_BAND_2GHZ) | |
683 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; | |
684 | else | |
685 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; | |
686 | ||
687 | bitrates = sband->bitrates; | |
688 | mandatory_rates = 0; | |
689 | for (i = 0; i < sband->n_bitrates; i++) | |
690 | if (bitrates[i].flags & mandatory_flag) | |
691 | mandatory_rates |= BIT(i); | |
692 | return mandatory_rates; | |
693 | } | |
46900298 JB |
694 | |
695 | void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, | |
696 | u16 transaction, u16 auth_alg, | |
fffd0934 JB |
697 | u8 *extra, size_t extra_len, const u8 *bssid, |
698 | const u8 *key, u8 key_len, u8 key_idx) | |
46900298 JB |
699 | { |
700 | struct ieee80211_local *local = sdata->local; | |
701 | struct sk_buff *skb; | |
702 | struct ieee80211_mgmt *mgmt; | |
fffd0934 | 703 | int err; |
46900298 JB |
704 | |
705 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
65fc73ac | 706 | sizeof(*mgmt) + 6 + extra_len); |
d15b8459 | 707 | if (!skb) |
46900298 | 708 | return; |
d15b8459 | 709 | |
46900298 JB |
710 | skb_reserve(skb, local->hw.extra_tx_headroom); |
711 | ||
712 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); | |
713 | memset(mgmt, 0, 24 + 6); | |
714 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
715 | IEEE80211_STYPE_AUTH); | |
46900298 | 716 | memcpy(mgmt->da, bssid, ETH_ALEN); |
47846c9b | 717 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
46900298 JB |
718 | memcpy(mgmt->bssid, bssid, ETH_ALEN); |
719 | mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); | |
720 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); | |
721 | mgmt->u.auth.status_code = cpu_to_le16(0); | |
722 | if (extra) | |
723 | memcpy(skb_put(skb, extra_len), extra, extra_len); | |
46900298 | 724 | |
fffd0934 JB |
725 | if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) { |
726 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
727 | err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx); | |
728 | WARN_ON(err); | |
729 | } | |
730 | ||
62ae67be JB |
731 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
732 | ieee80211_tx_skb(sdata, skb); | |
46900298 JB |
733 | } |
734 | ||
de95a54b | 735 | int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, |
4d36ec58 | 736 | const u8 *ie, size_t ie_len, |
651b5225 JM |
737 | enum ieee80211_band band, u32 rate_mask, |
738 | u8 channel) | |
de95a54b JB |
739 | { |
740 | struct ieee80211_supported_band *sband; | |
8e664fb3 JB |
741 | u8 *pos; |
742 | size_t offset = 0, noffset; | |
743 | int supp_rates_len, i; | |
8dcb2003 JM |
744 | u8 rates[32]; |
745 | int num_rates; | |
746 | int ext_rates_len; | |
de95a54b | 747 | |
4d36ec58 | 748 | sband = local->hw.wiphy->bands[band]; |
de95a54b JB |
749 | |
750 | pos = buffer; | |
751 | ||
8dcb2003 JM |
752 | num_rates = 0; |
753 | for (i = 0; i < sband->n_bitrates; i++) { | |
754 | if ((BIT(i) & rate_mask) == 0) | |
755 | continue; /* skip rate */ | |
756 | rates[num_rates++] = (u8) (sband->bitrates[i].bitrate / 5); | |
757 | } | |
758 | ||
759 | supp_rates_len = min_t(int, num_rates, 8); | |
8e664fb3 | 760 | |
de95a54b | 761 | *pos++ = WLAN_EID_SUPP_RATES; |
8e664fb3 | 762 | *pos++ = supp_rates_len; |
8dcb2003 JM |
763 | memcpy(pos, rates, supp_rates_len); |
764 | pos += supp_rates_len; | |
8e664fb3 JB |
765 | |
766 | /* insert "request information" if in custom IEs */ | |
767 | if (ie && ie_len) { | |
768 | static const u8 before_extrates[] = { | |
769 | WLAN_EID_SSID, | |
770 | WLAN_EID_SUPP_RATES, | |
771 | WLAN_EID_REQUEST, | |
772 | }; | |
773 | noffset = ieee80211_ie_split(ie, ie_len, | |
774 | before_extrates, | |
775 | ARRAY_SIZE(before_extrates), | |
776 | offset); | |
777 | memcpy(pos, ie + offset, noffset - offset); | |
778 | pos += noffset - offset; | |
779 | offset = noffset; | |
780 | } | |
781 | ||
8dcb2003 JM |
782 | ext_rates_len = num_rates - supp_rates_len; |
783 | if (ext_rates_len > 0) { | |
8e664fb3 | 784 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
8dcb2003 JM |
785 | *pos++ = ext_rates_len; |
786 | memcpy(pos, rates + supp_rates_len, ext_rates_len); | |
787 | pos += ext_rates_len; | |
8e664fb3 JB |
788 | } |
789 | ||
651b5225 JM |
790 | if (channel && sband->band == IEEE80211_BAND_2GHZ) { |
791 | *pos++ = WLAN_EID_DS_PARAMS; | |
792 | *pos++ = 1; | |
793 | *pos++ = channel; | |
794 | } | |
795 | ||
8e664fb3 JB |
796 | /* insert custom IEs that go before HT */ |
797 | if (ie && ie_len) { | |
798 | static const u8 before_ht[] = { | |
799 | WLAN_EID_SSID, | |
800 | WLAN_EID_SUPP_RATES, | |
801 | WLAN_EID_REQUEST, | |
802 | WLAN_EID_EXT_SUPP_RATES, | |
803 | WLAN_EID_DS_PARAMS, | |
804 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, | |
805 | }; | |
806 | noffset = ieee80211_ie_split(ie, ie_len, | |
807 | before_ht, ARRAY_SIZE(before_ht), | |
808 | offset); | |
809 | memcpy(pos, ie + offset, noffset - offset); | |
810 | pos += noffset - offset; | |
811 | offset = noffset; | |
de95a54b JB |
812 | } |
813 | ||
42e7aa77 AS |
814 | if (sband->ht_cap.ht_supported) |
815 | pos = ieee80211_ie_build_ht_cap(pos, sband, sband->ht_cap.cap); | |
5ef2d41a | 816 | |
de95a54b JB |
817 | /* |
818 | * If adding more here, adjust code in main.c | |
819 | * that calculates local->scan_ies_len. | |
820 | */ | |
821 | ||
8e664fb3 JB |
822 | /* add any remaining custom IEs */ |
823 | if (ie && ie_len) { | |
824 | noffset = ie_len; | |
825 | memcpy(pos, ie + offset, noffset - offset); | |
826 | pos += noffset - offset; | |
de95a54b JB |
827 | } |
828 | ||
829 | return pos - buffer; | |
830 | } | |
831 | ||
a619a4c0 | 832 | struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata, |
85a237fe | 833 | u8 *dst, u32 ratemask, |
a619a4c0 | 834 | const u8 *ssid, size_t ssid_len, |
a806c558 PS |
835 | const u8 *ie, size_t ie_len, |
836 | bool directed) | |
46900298 JB |
837 | { |
838 | struct ieee80211_local *local = sdata->local; | |
46900298 JB |
839 | struct sk_buff *skb; |
840 | struct ieee80211_mgmt *mgmt; | |
7c12ce8b KV |
841 | size_t buf_len; |
842 | u8 *buf; | |
651b5225 | 843 | u8 chan; |
7c12ce8b KV |
844 | |
845 | /* FIXME: come up with a proper value */ | |
846 | buf = kmalloc(200 + ie_len, GFP_KERNEL); | |
d15b8459 | 847 | if (!buf) |
a619a4c0 | 848 | return NULL; |
46900298 | 849 | |
a806c558 PS |
850 | /* |
851 | * Do not send DS Channel parameter for directed probe requests | |
852 | * in order to maximize the chance that we get a response. Some | |
853 | * badly-behaved APs don't respond when this parameter is included. | |
854 | */ | |
855 | if (directed) | |
856 | chan = 0; | |
857 | else | |
858 | chan = ieee80211_frequency_to_channel( | |
859 | local->hw.conf.channel->center_freq); | |
651b5225 | 860 | |
7c12ce8b | 861 | buf_len = ieee80211_build_preq_ies(local, buf, ie, ie_len, |
8dcb2003 | 862 | local->hw.conf.channel->band, |
85a237fe | 863 | ratemask, chan); |
7c12ce8b KV |
864 | |
865 | skb = ieee80211_probereq_get(&local->hw, &sdata->vif, | |
866 | ssid, ssid_len, | |
867 | buf, buf_len); | |
868 | ||
46900298 | 869 | if (dst) { |
7c12ce8b | 870 | mgmt = (struct ieee80211_mgmt *) skb->data; |
46900298 JB |
871 | memcpy(mgmt->da, dst, ETH_ALEN); |
872 | memcpy(mgmt->bssid, dst, ETH_ALEN); | |
46900298 | 873 | } |
46900298 | 874 | |
62ae67be | 875 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
145b6d1a | 876 | kfree(buf); |
a619a4c0 JO |
877 | |
878 | return skb; | |
879 | } | |
880 | ||
881 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, | |
882 | const u8 *ssid, size_t ssid_len, | |
a806c558 | 883 | const u8 *ie, size_t ie_len, |
aad14ceb | 884 | u32 ratemask, bool directed, bool no_cck) |
a619a4c0 JO |
885 | { |
886 | struct sk_buff *skb; | |
887 | ||
85a237fe JB |
888 | skb = ieee80211_build_probe_req(sdata, dst, ratemask, ssid, ssid_len, |
889 | ie, ie_len, directed); | |
aad14ceb RM |
890 | if (skb) { |
891 | if (no_cck) | |
892 | IEEE80211_SKB_CB(skb)->flags |= | |
893 | IEEE80211_TX_CTL_NO_CCK_RATE; | |
a619a4c0 | 894 | ieee80211_tx_skb(sdata, skb); |
aad14ceb | 895 | } |
46900298 JB |
896 | } |
897 | ||
898 | u32 ieee80211_sta_get_rates(struct ieee80211_local *local, | |
899 | struct ieee802_11_elems *elems, | |
900 | enum ieee80211_band band) | |
901 | { | |
902 | struct ieee80211_supported_band *sband; | |
903 | struct ieee80211_rate *bitrates; | |
904 | size_t num_rates; | |
905 | u32 supp_rates; | |
906 | int i, j; | |
907 | sband = local->hw.wiphy->bands[band]; | |
908 | ||
909 | if (!sband) { | |
910 | WARN_ON(1); | |
911 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
912 | } | |
913 | ||
914 | bitrates = sband->bitrates; | |
915 | num_rates = sband->n_bitrates; | |
916 | supp_rates = 0; | |
917 | for (i = 0; i < elems->supp_rates_len + | |
918 | elems->ext_supp_rates_len; i++) { | |
919 | u8 rate = 0; | |
920 | int own_rate; | |
921 | if (i < elems->supp_rates_len) | |
922 | rate = elems->supp_rates[i]; | |
923 | else if (elems->ext_supp_rates) | |
924 | rate = elems->ext_supp_rates | |
925 | [i - elems->supp_rates_len]; | |
926 | own_rate = 5 * (rate & 0x7f); | |
927 | for (j = 0; j < num_rates; j++) | |
928 | if (bitrates[j].bitrate == own_rate) | |
929 | supp_rates |= BIT(j); | |
930 | } | |
931 | return supp_rates; | |
932 | } | |
f2753ddb | 933 | |
84f6a01c JB |
934 | void ieee80211_stop_device(struct ieee80211_local *local) |
935 | { | |
936 | ieee80211_led_radio(local, false); | |
67408c8c | 937 | ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO); |
84f6a01c JB |
938 | |
939 | cancel_work_sync(&local->reconfig_filter); | |
84f6a01c JB |
940 | |
941 | flush_workqueue(local->workqueue); | |
678f415f | 942 | drv_stop(local); |
84f6a01c JB |
943 | } |
944 | ||
f2753ddb JB |
945 | int ieee80211_reconfig(struct ieee80211_local *local) |
946 | { | |
947 | struct ieee80211_hw *hw = &local->hw; | |
948 | struct ieee80211_sub_if_data *sdata; | |
f2753ddb | 949 | struct sta_info *sta; |
2683d65b | 950 | int res, i; |
5bb644a0 | 951 | |
eecc4800 | 952 | #ifdef CONFIG_PM |
ceb99fe0 JB |
953 | if (local->suspended) |
954 | local->resuming = true; | |
f2753ddb | 955 | |
eecc4800 JB |
956 | if (local->wowlan) { |
957 | local->wowlan = false; | |
958 | res = drv_resume(local); | |
959 | if (res < 0) { | |
960 | local->resuming = false; | |
961 | return res; | |
962 | } | |
963 | if (res == 0) | |
964 | goto wake_up; | |
965 | WARN_ON(res > 1); | |
966 | /* | |
967 | * res is 1, which means the driver requested | |
968 | * to go through a regular reset on wakeup. | |
969 | */ | |
970 | } | |
971 | #endif | |
972 | ||
94f9b97b JB |
973 | /* setup fragmentation threshold */ |
974 | drv_set_frag_threshold(local, hw->wiphy->frag_threshold); | |
975 | ||
976 | /* setup RTS threshold */ | |
977 | drv_set_rts_threshold(local, hw->wiphy->rts_threshold); | |
978 | ||
979 | /* reset coverage class */ | |
980 | drv_set_coverage_class(local, hw->wiphy->coverage_class); | |
981 | ||
982 | /* everything else happens only if HW was up & running */ | |
983 | if (!local->open_count) | |
984 | goto wake_up; | |
f2753ddb | 985 | |
94f9b97b JB |
986 | /* |
987 | * Upon resume hardware can sometimes be goofy due to | |
988 | * various platform / driver / bus issues, so restarting | |
989 | * the device may at times not work immediately. Propagate | |
990 | * the error. | |
991 | */ | |
992 | res = drv_start(local); | |
993 | if (res) { | |
994 | WARN(local->suspended, "Hardware became unavailable " | |
995 | "upon resume. This could be a software issue " | |
996 | "prior to suspend or a hardware issue.\n"); | |
997 | return res; | |
f2753ddb JB |
998 | } |
999 | ||
94f9b97b JB |
1000 | ieee80211_led_radio(local, true); |
1001 | ieee80211_mod_tpt_led_trig(local, | |
1002 | IEEE80211_TPT_LEDTRIG_FL_RADIO, 0); | |
1003 | ||
f2753ddb JB |
1004 | /* add interfaces */ |
1005 | list_for_each_entry(sdata, &local->interfaces, list) { | |
1006 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | |
1007 | sdata->vif.type != NL80211_IFTYPE_MONITOR && | |
1ed32e4f | 1008 | ieee80211_sdata_running(sdata)) |
7b7eab6f | 1009 | res = drv_add_interface(local, sdata); |
f2753ddb JB |
1010 | } |
1011 | ||
1012 | /* add STAs back */ | |
34e89507 JB |
1013 | mutex_lock(&local->sta_mtx); |
1014 | list_for_each_entry(sta, &local->sta_list, list) { | |
1015 | if (sta->uploaded) { | |
5bb644a0 | 1016 | sdata = sta->sdata; |
f2753ddb JB |
1017 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
1018 | sdata = container_of(sdata->bss, | |
1019 | struct ieee80211_sub_if_data, | |
1020 | u.ap); | |
1021 | ||
f785d83a | 1022 | memset(&sta->sta.drv_priv, 0, hw->sta_data_size); |
34e89507 | 1023 | WARN_ON(drv_sta_add(local, sdata, &sta->sta)); |
f2753ddb | 1024 | } |
f2753ddb | 1025 | } |
34e89507 | 1026 | mutex_unlock(&local->sta_mtx); |
f2753ddb | 1027 | |
2683d65b | 1028 | /* reconfigure tx conf */ |
f6f3def3 EP |
1029 | list_for_each_entry(sdata, &local->interfaces, list) { |
1030 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN || | |
1031 | sdata->vif.type == NL80211_IFTYPE_MONITOR || | |
1032 | !ieee80211_sdata_running(sdata)) | |
1033 | continue; | |
1034 | ||
1035 | for (i = 0; i < hw->queues; i++) | |
1036 | drv_conf_tx(local, sdata, i, &sdata->tx_conf[i]); | |
1037 | } | |
2683d65b | 1038 | |
f2753ddb JB |
1039 | /* reconfigure hardware */ |
1040 | ieee80211_hw_config(local, ~0); | |
1041 | ||
f2753ddb | 1042 | ieee80211_configure_filter(local); |
f2753ddb JB |
1043 | |
1044 | /* Finally also reconfigure all the BSS information */ | |
1045 | list_for_each_entry(sdata, &local->interfaces, list) { | |
ac8dd506 JB |
1046 | u32 changed; |
1047 | ||
9607e6b6 | 1048 | if (!ieee80211_sdata_running(sdata)) |
f2753ddb | 1049 | continue; |
ac8dd506 JB |
1050 | |
1051 | /* common change flags for all interface types */ | |
1052 | changed = BSS_CHANGED_ERP_CTS_PROT | | |
1053 | BSS_CHANGED_ERP_PREAMBLE | | |
1054 | BSS_CHANGED_ERP_SLOT | | |
1055 | BSS_CHANGED_HT | | |
1056 | BSS_CHANGED_BASIC_RATES | | |
1057 | BSS_CHANGED_BEACON_INT | | |
1058 | BSS_CHANGED_BSSID | | |
4ced3f74 | 1059 | BSS_CHANGED_CQM | |
55de47f6 EP |
1060 | BSS_CHANGED_QOS | |
1061 | BSS_CHANGED_IDLE; | |
ac8dd506 | 1062 | |
f2753ddb JB |
1063 | switch (sdata->vif.type) { |
1064 | case NL80211_IFTYPE_STATION: | |
ac8dd506 | 1065 | changed |= BSS_CHANGED_ASSOC; |
a7b545f7 | 1066 | mutex_lock(&sdata->u.mgd.mtx); |
ac8dd506 | 1067 | ieee80211_bss_info_change_notify(sdata, changed); |
a7b545f7 | 1068 | mutex_unlock(&sdata->u.mgd.mtx); |
ac8dd506 | 1069 | break; |
f2753ddb | 1070 | case NL80211_IFTYPE_ADHOC: |
ac8dd506 JB |
1071 | changed |= BSS_CHANGED_IBSS; |
1072 | /* fall through */ | |
f2753ddb | 1073 | case NL80211_IFTYPE_AP: |
7827493b AN |
1074 | changed |= BSS_CHANGED_SSID; |
1075 | /* fall through */ | |
f2753ddb | 1076 | case NL80211_IFTYPE_MESH_POINT: |
ac8dd506 JB |
1077 | changed |= BSS_CHANGED_BEACON | |
1078 | BSS_CHANGED_BEACON_ENABLED; | |
2d0ddec5 | 1079 | ieee80211_bss_info_change_notify(sdata, changed); |
f2753ddb JB |
1080 | break; |
1081 | case NL80211_IFTYPE_WDS: | |
1082 | break; | |
1083 | case NL80211_IFTYPE_AP_VLAN: | |
1084 | case NL80211_IFTYPE_MONITOR: | |
1085 | /* ignore virtual */ | |
1086 | break; | |
1087 | case NL80211_IFTYPE_UNSPECIFIED: | |
2e161f78 | 1088 | case NUM_NL80211_IFTYPES: |
2ca27bcf JB |
1089 | case NL80211_IFTYPE_P2P_CLIENT: |
1090 | case NL80211_IFTYPE_P2P_GO: | |
f2753ddb JB |
1091 | WARN_ON(1); |
1092 | break; | |
1093 | } | |
1094 | } | |
1095 | ||
8e1b23b9 ES |
1096 | ieee80211_recalc_ps(local, -1); |
1097 | ||
2a419056 JB |
1098 | /* |
1099 | * Clear the WLAN_STA_BLOCK_BA flag so new aggregation | |
1100 | * sessions can be established after a resume. | |
1101 | * | |
1102 | * Also tear down aggregation sessions since reconfiguring | |
1103 | * them in a hardware restart scenario is not easily done | |
1104 | * right now, and the hardware will have lost information | |
1105 | * about the sessions, but we and the AP still think they | |
1106 | * are active. This is really a workaround though. | |
1107 | */ | |
74e2bd1f | 1108 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
2a419056 JB |
1109 | mutex_lock(&local->sta_mtx); |
1110 | ||
1111 | list_for_each_entry(sta, &local->sta_list, list) { | |
53f73c09 | 1112 | ieee80211_sta_tear_down_BA_sessions(sta, true); |
c2c98fde | 1113 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); |
74e2bd1f | 1114 | } |
2a419056 JB |
1115 | |
1116 | mutex_unlock(&local->sta_mtx); | |
74e2bd1f | 1117 | } |
74e2bd1f | 1118 | |
f2753ddb JB |
1119 | /* add back keys */ |
1120 | list_for_each_entry(sdata, &local->interfaces, list) | |
9607e6b6 | 1121 | if (ieee80211_sdata_running(sdata)) |
f2753ddb JB |
1122 | ieee80211_enable_keys(sdata); |
1123 | ||
eecc4800 | 1124 | wake_up: |
f2753ddb JB |
1125 | ieee80211_wake_queues_by_reason(hw, |
1126 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); | |
1127 | ||
5bb644a0 JB |
1128 | /* |
1129 | * If this is for hw restart things are still running. | |
1130 | * We may want to change that later, however. | |
1131 | */ | |
ceb99fe0 | 1132 | if (!local->suspended) |
5bb644a0 JB |
1133 | return 0; |
1134 | ||
1135 | #ifdef CONFIG_PM | |
ceb99fe0 | 1136 | /* first set suspended false, then resuming */ |
5bb644a0 | 1137 | local->suspended = false; |
ceb99fe0 JB |
1138 | mb(); |
1139 | local->resuming = false; | |
5bb644a0 JB |
1140 | |
1141 | list_for_each_entry(sdata, &local->interfaces, list) { | |
1142 | switch(sdata->vif.type) { | |
1143 | case NL80211_IFTYPE_STATION: | |
1144 | ieee80211_sta_restart(sdata); | |
1145 | break; | |
1146 | case NL80211_IFTYPE_ADHOC: | |
1147 | ieee80211_ibss_restart(sdata); | |
1148 | break; | |
1149 | case NL80211_IFTYPE_MESH_POINT: | |
1150 | ieee80211_mesh_restart(sdata); | |
1151 | break; | |
1152 | default: | |
1153 | break; | |
1154 | } | |
1155 | } | |
1156 | ||
26d59535 | 1157 | mod_timer(&local->sta_cleanup, jiffies + 1); |
5bb644a0 | 1158 | |
34e89507 | 1159 | mutex_lock(&local->sta_mtx); |
5bb644a0 JB |
1160 | list_for_each_entry(sta, &local->sta_list, list) |
1161 | mesh_plink_restart(sta); | |
34e89507 | 1162 | mutex_unlock(&local->sta_mtx); |
5bb644a0 JB |
1163 | #else |
1164 | WARN_ON(1); | |
1165 | #endif | |
f2753ddb JB |
1166 | return 0; |
1167 | } | |
42935eca | 1168 | |
95acac61 JB |
1169 | void ieee80211_resume_disconnect(struct ieee80211_vif *vif) |
1170 | { | |
1171 | struct ieee80211_sub_if_data *sdata; | |
1172 | struct ieee80211_local *local; | |
1173 | struct ieee80211_key *key; | |
1174 | ||
1175 | if (WARN_ON(!vif)) | |
1176 | return; | |
1177 | ||
1178 | sdata = vif_to_sdata(vif); | |
1179 | local = sdata->local; | |
1180 | ||
1181 | if (WARN_ON(!local->resuming)) | |
1182 | return; | |
1183 | ||
1184 | if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) | |
1185 | return; | |
1186 | ||
1187 | sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME; | |
1188 | ||
1189 | mutex_lock(&local->key_mtx); | |
1190 | list_for_each_entry(key, &sdata->key_list, list) | |
1191 | key->flags |= KEY_FLAG_TAINTED; | |
1192 | mutex_unlock(&local->key_mtx); | |
1193 | } | |
1194 | EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect); | |
1195 | ||
0f78231b JB |
1196 | static int check_mgd_smps(struct ieee80211_if_managed *ifmgd, |
1197 | enum ieee80211_smps_mode *smps_mode) | |
1198 | { | |
1199 | if (ifmgd->associated) { | |
1200 | *smps_mode = ifmgd->ap_smps; | |
1201 | ||
1202 | if (*smps_mode == IEEE80211_SMPS_AUTOMATIC) { | |
1203 | if (ifmgd->powersave) | |
1204 | *smps_mode = IEEE80211_SMPS_DYNAMIC; | |
1205 | else | |
1206 | *smps_mode = IEEE80211_SMPS_OFF; | |
1207 | } | |
1208 | ||
1209 | return 1; | |
1210 | } | |
1211 | ||
1212 | return 0; | |
1213 | } | |
1214 | ||
1215 | /* must hold iflist_mtx */ | |
025e6be2 | 1216 | void ieee80211_recalc_smps(struct ieee80211_local *local) |
0f78231b JB |
1217 | { |
1218 | struct ieee80211_sub_if_data *sdata; | |
1219 | enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_OFF; | |
1220 | int count = 0; | |
1221 | ||
46a5ebaf | 1222 | lockdep_assert_held(&local->iflist_mtx); |
0f78231b JB |
1223 | |
1224 | /* | |
1225 | * This function could be improved to handle multiple | |
1226 | * interfaces better, but right now it makes any | |
1227 | * non-station interfaces force SM PS to be turned | |
1228 | * off. If there are multiple station interfaces it | |
1229 | * could also use the best possible mode, e.g. if | |
1230 | * one is in static and the other in dynamic then | |
1231 | * dynamic is ok. | |
1232 | */ | |
1233 | ||
1234 | list_for_each_entry(sdata, &local->interfaces, list) { | |
26a58456 | 1235 | if (!ieee80211_sdata_running(sdata)) |
0f78231b JB |
1236 | continue; |
1237 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
1238 | goto set; | |
025e6be2 JB |
1239 | |
1240 | count += check_mgd_smps(&sdata->u.mgd, &smps_mode); | |
0f78231b JB |
1241 | |
1242 | if (count > 1) { | |
1243 | smps_mode = IEEE80211_SMPS_OFF; | |
1244 | break; | |
1245 | } | |
1246 | } | |
1247 | ||
1248 | if (smps_mode == local->smps_mode) | |
1249 | return; | |
1250 | ||
1251 | set: | |
1252 | local->smps_mode = smps_mode; | |
1253 | /* changed flag is auto-detected for this */ | |
1254 | ieee80211_hw_config(local, 0); | |
1255 | } | |
8e664fb3 JB |
1256 | |
1257 | static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id) | |
1258 | { | |
1259 | int i; | |
1260 | ||
1261 | for (i = 0; i < n_ids; i++) | |
1262 | if (ids[i] == id) | |
1263 | return true; | |
1264 | return false; | |
1265 | } | |
1266 | ||
1267 | /** | |
1268 | * ieee80211_ie_split - split an IE buffer according to ordering | |
1269 | * | |
1270 | * @ies: the IE buffer | |
1271 | * @ielen: the length of the IE buffer | |
1272 | * @ids: an array with element IDs that are allowed before | |
1273 | * the split | |
1274 | * @n_ids: the size of the element ID array | |
1275 | * @offset: offset where to start splitting in the buffer | |
1276 | * | |
1277 | * This function splits an IE buffer by updating the @offset | |
1278 | * variable to point to the location where the buffer should be | |
1279 | * split. | |
1280 | * | |
1281 | * It assumes that the given IE buffer is well-formed, this | |
1282 | * has to be guaranteed by the caller! | |
1283 | * | |
1284 | * It also assumes that the IEs in the buffer are ordered | |
1285 | * correctly, if not the result of using this function will not | |
1286 | * be ordered correctly either, i.e. it does no reordering. | |
1287 | * | |
1288 | * The function returns the offset where the next part of the | |
1289 | * buffer starts, which may be @ielen if the entire (remainder) | |
1290 | * of the buffer should be used. | |
1291 | */ | |
1292 | size_t ieee80211_ie_split(const u8 *ies, size_t ielen, | |
1293 | const u8 *ids, int n_ids, size_t offset) | |
1294 | { | |
1295 | size_t pos = offset; | |
1296 | ||
1297 | while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos])) | |
1298 | pos += 2 + ies[pos + 1]; | |
1299 | ||
1300 | return pos; | |
1301 | } | |
1302 | ||
1303 | size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset) | |
1304 | { | |
1305 | size_t pos = offset; | |
1306 | ||
1307 | while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC) | |
1308 | pos += 2 + ies[pos + 1]; | |
1309 | ||
1310 | return pos; | |
1311 | } | |
615f7b9b MV |
1312 | |
1313 | static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata, | |
1314 | int rssi_min_thold, | |
1315 | int rssi_max_thold) | |
1316 | { | |
1317 | trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold); | |
1318 | ||
1319 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) | |
1320 | return; | |
1321 | ||
1322 | /* | |
1323 | * Scale up threshold values before storing it, as the RSSI averaging | |
1324 | * algorithm uses a scaled up value as well. Change this scaling | |
1325 | * factor if the RSSI averaging algorithm changes. | |
1326 | */ | |
1327 | sdata->u.mgd.rssi_min_thold = rssi_min_thold*16; | |
1328 | sdata->u.mgd.rssi_max_thold = rssi_max_thold*16; | |
1329 | } | |
1330 | ||
1331 | void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif, | |
1332 | int rssi_min_thold, | |
1333 | int rssi_max_thold) | |
1334 | { | |
1335 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1336 | ||
1337 | WARN_ON(rssi_min_thold == rssi_max_thold || | |
1338 | rssi_min_thold > rssi_max_thold); | |
1339 | ||
1340 | _ieee80211_enable_rssi_reports(sdata, rssi_min_thold, | |
1341 | rssi_max_thold); | |
1342 | } | |
1343 | EXPORT_SYMBOL(ieee80211_enable_rssi_reports); | |
1344 | ||
1345 | void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif) | |
1346 | { | |
1347 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1348 | ||
1349 | _ieee80211_enable_rssi_reports(sdata, 0, 0); | |
1350 | } | |
1351 | EXPORT_SYMBOL(ieee80211_disable_rssi_reports); | |
768db343 | 1352 | |
42e7aa77 AS |
1353 | u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_supported_band *sband, |
1354 | u16 cap) | |
1355 | { | |
1356 | __le16 tmp; | |
1357 | ||
1358 | *pos++ = WLAN_EID_HT_CAPABILITY; | |
1359 | *pos++ = sizeof(struct ieee80211_ht_cap); | |
1360 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); | |
1361 | ||
1362 | /* capability flags */ | |
1363 | tmp = cpu_to_le16(cap); | |
1364 | memcpy(pos, &tmp, sizeof(u16)); | |
1365 | pos += sizeof(u16); | |
1366 | ||
1367 | /* AMPDU parameters */ | |
1368 | *pos++ = sband->ht_cap.ampdu_factor | | |
1369 | (sband->ht_cap.ampdu_density << | |
1370 | IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT); | |
1371 | ||
1372 | /* MCS set */ | |
1373 | memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); | |
1374 | pos += sizeof(sband->ht_cap.mcs); | |
1375 | ||
1376 | /* extended capabilities */ | |
1377 | pos += sizeof(__le16); | |
1378 | ||
1379 | /* BF capabilities */ | |
1380 | pos += sizeof(__le32); | |
1381 | ||
1382 | /* antenna selection */ | |
1383 | pos += sizeof(u8); | |
1384 | ||
1385 | return pos; | |
1386 | } | |
1387 | ||
1388 | u8 *ieee80211_ie_build_ht_info(u8 *pos, | |
1389 | struct ieee80211_sta_ht_cap *ht_cap, | |
1390 | struct ieee80211_channel *channel, | |
1391 | enum nl80211_channel_type channel_type) | |
1392 | { | |
1393 | struct ieee80211_ht_info *ht_info; | |
1394 | /* Build HT Information */ | |
1395 | *pos++ = WLAN_EID_HT_INFORMATION; | |
1396 | *pos++ = sizeof(struct ieee80211_ht_info); | |
1397 | ht_info = (struct ieee80211_ht_info *)pos; | |
1398 | ht_info->control_chan = | |
1399 | ieee80211_frequency_to_channel(channel->center_freq); | |
1400 | switch (channel_type) { | |
1401 | case NL80211_CHAN_HT40MINUS: | |
1402 | ht_info->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW; | |
1403 | break; | |
1404 | case NL80211_CHAN_HT40PLUS: | |
1405 | ht_info->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | |
1406 | break; | |
1407 | case NL80211_CHAN_HT20: | |
1408 | default: | |
1409 | ht_info->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE; | |
1410 | break; | |
1411 | } | |
1412 | if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) | |
1413 | ht_info->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY; | |
1414 | ht_info->operation_mode = 0x0000; | |
1415 | ht_info->stbc_param = 0x0000; | |
1416 | ||
1417 | /* It seems that Basic MCS set and Supported MCS set | |
1418 | are identical for the first 10 bytes */ | |
1419 | memset(&ht_info->basic_set, 0, 16); | |
1420 | memcpy(&ht_info->basic_set, &ht_cap->mcs, 10); | |
1421 | ||
1422 | return pos + sizeof(struct ieee80211_ht_info); | |
1423 | } | |
1424 | ||
1425 | enum nl80211_channel_type | |
1426 | ieee80211_ht_info_to_channel_type(struct ieee80211_ht_info *ht_info) | |
1427 | { | |
1428 | enum nl80211_channel_type channel_type; | |
1429 | ||
1430 | if (!ht_info) | |
1431 | return NL80211_CHAN_NO_HT; | |
1432 | ||
1433 | switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { | |
1434 | case IEEE80211_HT_PARAM_CHA_SEC_NONE: | |
1435 | channel_type = NL80211_CHAN_HT20; | |
1436 | break; | |
1437 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | |
1438 | channel_type = NL80211_CHAN_HT40PLUS; | |
1439 | break; | |
1440 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
1441 | channel_type = NL80211_CHAN_HT40MINUS; | |
1442 | break; | |
1443 | default: | |
1444 | channel_type = NL80211_CHAN_NO_HT; | |
1445 | } | |
1446 | ||
1447 | return channel_type; | |
1448 | } | |
1449 | ||
768db343 AN |
1450 | int ieee80211_add_srates_ie(struct ieee80211_vif *vif, struct sk_buff *skb) |
1451 | { | |
1452 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1453 | struct ieee80211_local *local = sdata->local; | |
1454 | struct ieee80211_supported_band *sband; | |
1455 | int rate; | |
1456 | u8 i, rates, *pos; | |
1457 | ||
1458 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
1459 | rates = sband->n_bitrates; | |
1460 | if (rates > 8) | |
1461 | rates = 8; | |
1462 | ||
1463 | if (skb_tailroom(skb) < rates + 2) | |
1464 | return -ENOMEM; | |
1465 | ||
1466 | pos = skb_put(skb, rates + 2); | |
1467 | *pos++ = WLAN_EID_SUPP_RATES; | |
1468 | *pos++ = rates; | |
1469 | for (i = 0; i < rates; i++) { | |
1470 | rate = sband->bitrates[i].bitrate; | |
1471 | *pos++ = (u8) (rate / 5); | |
1472 | } | |
1473 | ||
1474 | return 0; | |
1475 | } | |
1476 | ||
1477 | int ieee80211_add_ext_srates_ie(struct ieee80211_vif *vif, struct sk_buff *skb) | |
1478 | { | |
1479 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1480 | struct ieee80211_local *local = sdata->local; | |
1481 | struct ieee80211_supported_band *sband; | |
1482 | int rate; | |
1483 | u8 i, exrates, *pos; | |
1484 | ||
1485 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
1486 | exrates = sband->n_bitrates; | |
1487 | if (exrates > 8) | |
1488 | exrates -= 8; | |
1489 | else | |
1490 | exrates = 0; | |
1491 | ||
1492 | if (skb_tailroom(skb) < exrates + 2) | |
1493 | return -ENOMEM; | |
1494 | ||
1495 | if (exrates) { | |
1496 | pos = skb_put(skb, exrates + 2); | |
1497 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
1498 | *pos++ = exrates; | |
1499 | for (i = 8; i < sband->n_bitrates; i++) { | |
1500 | rate = sband->bitrates[i].bitrate; | |
1501 | *pos++ = (u8) (rate / 5); | |
1502 | } | |
1503 | } | |
1504 | return 0; | |
1505 | } |