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> | |
21 | #include <linux/wireless.h> | |
22 | #include <linux/bitmap.h> | |
881d966b | 23 | #include <net/net_namespace.h> |
c2d1560a | 24 | #include <net/cfg80211.h> |
dabeb344 | 25 | #include <net/rtnetlink.h> |
c2d1560a JB |
26 | |
27 | #include "ieee80211_i.h" | |
2c8dccc7 | 28 | #include "rate.h" |
ee385855 | 29 | #include "mesh.h" |
c2d1560a | 30 | #include "wme.h" |
f2753ddb | 31 | #include "led.h" |
c2d1560a JB |
32 | |
33 | /* privid for wiphys to determine whether they belong to us or not */ | |
34 | void *mac80211_wiphy_privid = &mac80211_wiphy_privid; | |
35 | ||
36 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ | |
37 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ | |
c97c23e3 | 38 | const unsigned char rfc1042_header[] __aligned(2) = |
c2d1560a JB |
39 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
40 | ||
41 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ | |
c97c23e3 | 42 | const unsigned char bridge_tunnel_header[] __aligned(2) = |
c2d1560a JB |
43 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
44 | ||
9a95371a LR |
45 | struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) |
46 | { | |
47 | struct ieee80211_local *local; | |
48 | BUG_ON(!wiphy); | |
49 | ||
50 | local = wiphy_priv(wiphy); | |
51 | return &local->hw; | |
52 | } | |
53 | EXPORT_SYMBOL(wiphy_to_ieee80211_hw); | |
c2d1560a | 54 | |
71364716 | 55 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
05c914fe | 56 | enum nl80211_iftype type) |
c2d1560a | 57 | { |
a494bb1c | 58 | __le16 fc = hdr->frame_control; |
c2d1560a | 59 | |
98f0b0a3 RR |
60 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
61 | if (len < 16) | |
c2d1560a JB |
62 | return NULL; |
63 | ||
a494bb1c | 64 | if (ieee80211_is_data(fc)) { |
98f0b0a3 RR |
65 | if (len < 24) /* drop incorrect hdr len (data) */ |
66 | return NULL; | |
a494bb1c HH |
67 | |
68 | if (ieee80211_has_a4(fc)) | |
c2d1560a | 69 | return NULL; |
a494bb1c HH |
70 | if (ieee80211_has_tods(fc)) |
71 | return hdr->addr1; | |
72 | if (ieee80211_has_fromds(fc)) | |
c2d1560a | 73 | return hdr->addr2; |
a494bb1c HH |
74 | |
75 | return hdr->addr3; | |
76 | } | |
77 | ||
78 | if (ieee80211_is_mgmt(fc)) { | |
98f0b0a3 RR |
79 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
80 | return NULL; | |
c2d1560a | 81 | return hdr->addr3; |
a494bb1c HH |
82 | } |
83 | ||
84 | if (ieee80211_is_ctl(fc)) { | |
85 | if(ieee80211_is_pspoll(fc)) | |
c2d1560a | 86 | return hdr->addr1; |
a494bb1c HH |
87 | |
88 | if (ieee80211_is_back_req(fc)) { | |
71364716 | 89 | switch (type) { |
05c914fe | 90 | case NL80211_IFTYPE_STATION: |
71364716 | 91 | return hdr->addr2; |
05c914fe JB |
92 | case NL80211_IFTYPE_AP: |
93 | case NL80211_IFTYPE_AP_VLAN: | |
71364716 RR |
94 | return hdr->addr1; |
95 | default: | |
a494bb1c | 96 | break; /* fall through to the return */ |
71364716 RR |
97 | } |
98 | } | |
c2d1560a JB |
99 | } |
100 | ||
101 | return NULL; | |
102 | } | |
103 | ||
6693be71 HH |
104 | unsigned int ieee80211_hdrlen(__le16 fc) |
105 | { | |
106 | unsigned int hdrlen = 24; | |
107 | ||
108 | if (ieee80211_is_data(fc)) { | |
109 | if (ieee80211_has_a4(fc)) | |
110 | hdrlen = 30; | |
111 | if (ieee80211_is_data_qos(fc)) | |
112 | hdrlen += IEEE80211_QOS_CTL_LEN; | |
113 | goto out; | |
114 | } | |
115 | ||
116 | if (ieee80211_is_ctl(fc)) { | |
117 | /* | |
118 | * ACK and CTS are 10 bytes, all others 16. To see how | |
119 | * to get this condition consider | |
120 | * subtype mask: 0b0000000011110000 (0x00F0) | |
121 | * ACK subtype: 0b0000000011010000 (0x00D0) | |
122 | * CTS subtype: 0b0000000011000000 (0x00C0) | |
123 | * bits that matter: ^^^ (0x00E0) | |
124 | * value of those: 0b0000000011000000 (0x00C0) | |
125 | */ | |
126 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) | |
127 | hdrlen = 10; | |
128 | else | |
129 | hdrlen = 16; | |
130 | } | |
131 | out: | |
132 | return hdrlen; | |
133 | } | |
134 | EXPORT_SYMBOL(ieee80211_hdrlen); | |
135 | ||
c9c6950c | 136 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) |
c2d1560a | 137 | { |
c9c6950c HH |
138 | const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data; |
139 | unsigned int hdrlen; | |
c2d1560a JB |
140 | |
141 | if (unlikely(skb->len < 10)) | |
142 | return 0; | |
c9c6950c | 143 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
c2d1560a JB |
144 | if (unlikely(hdrlen > skb->len)) |
145 | return 0; | |
146 | return hdrlen; | |
147 | } | |
148 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); | |
149 | ||
ee385855 LCC |
150 | int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) |
151 | { | |
152 | int ae = meshhdr->flags & IEEE80211S_FLAGS_AE; | |
153 | /* 7.1.3.5a.2 */ | |
154 | switch (ae) { | |
155 | case 0: | |
ef269254 | 156 | return 6; |
ee385855 | 157 | case 1: |
ef269254 | 158 | return 12; |
ee385855 | 159 | case 2: |
ef269254 | 160 | return 18; |
ee385855 | 161 | case 3: |
ef269254 | 162 | return 24; |
ee385855 | 163 | default: |
ef269254 | 164 | return 6; |
ee385855 LCC |
165 | } |
166 | } | |
ee385855 | 167 | |
5cf121c3 | 168 | void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) |
c2d1560a | 169 | { |
2de8e0d9 JB |
170 | struct sk_buff *skb = tx->skb; |
171 | struct ieee80211_hdr *hdr; | |
172 | ||
173 | do { | |
174 | hdr = (struct ieee80211_hdr *) skb->data; | |
175 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
176 | } while ((skb = skb->next)); | |
c2d1560a JB |
177 | } |
178 | ||
179 | int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, | |
180 | int rate, int erp, int short_preamble) | |
181 | { | |
182 | int dur; | |
183 | ||
184 | /* calculate duration (in microseconds, rounded up to next higher | |
185 | * integer if it includes a fractional microsecond) to send frame of | |
186 | * len bytes (does not include FCS) at the given rate. Duration will | |
187 | * also include SIFS. | |
188 | * | |
189 | * rate is in 100 kbps, so divident is multiplied by 10 in the | |
190 | * DIV_ROUND_UP() operations. | |
191 | */ | |
192 | ||
8318d78a | 193 | if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) { |
c2d1560a JB |
194 | /* |
195 | * OFDM: | |
196 | * | |
197 | * N_DBPS = DATARATE x 4 | |
198 | * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) | |
199 | * (16 = SIGNAL time, 6 = tail bits) | |
200 | * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext | |
201 | * | |
202 | * T_SYM = 4 usec | |
203 | * 802.11a - 17.5.2: aSIFSTime = 16 usec | |
204 | * 802.11g - 19.8.4: aSIFSTime = 10 usec + | |
205 | * signal ext = 6 usec | |
206 | */ | |
c2d1560a JB |
207 | dur = 16; /* SIFS + signal ext */ |
208 | dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */ | |
209 | dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */ | |
210 | dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, | |
211 | 4 * rate); /* T_SYM x N_SYM */ | |
212 | } else { | |
213 | /* | |
214 | * 802.11b or 802.11g with 802.11b compatibility: | |
215 | * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + | |
216 | * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. | |
217 | * | |
218 | * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 | |
219 | * aSIFSTime = 10 usec | |
220 | * aPreambleLength = 144 usec or 72 usec with short preamble | |
221 | * aPLCPHeaderLength = 48 usec or 24 usec with short preamble | |
222 | */ | |
223 | dur = 10; /* aSIFSTime = 10 usec */ | |
224 | dur += short_preamble ? (72 + 24) : (144 + 48); | |
225 | ||
226 | dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); | |
227 | } | |
228 | ||
229 | return dur; | |
230 | } | |
231 | ||
232 | /* Exported duration function for driver use */ | |
32bfd35d JB |
233 | __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, |
234 | struct ieee80211_vif *vif, | |
8318d78a JB |
235 | size_t frame_len, |
236 | struct ieee80211_rate *rate) | |
c2d1560a JB |
237 | { |
238 | struct ieee80211_local *local = hw_to_local(hw); | |
25d834e1 | 239 | struct ieee80211_sub_if_data *sdata; |
c2d1560a JB |
240 | u16 dur; |
241 | int erp; | |
25d834e1 | 242 | bool short_preamble = false; |
c2d1560a | 243 | |
8318d78a | 244 | erp = 0; |
25d834e1 JB |
245 | if (vif) { |
246 | sdata = vif_to_sdata(vif); | |
bda3933a | 247 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
248 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
249 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
250 | } | |
8318d78a JB |
251 | |
252 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp, | |
25d834e1 | 253 | short_preamble); |
c2d1560a JB |
254 | |
255 | return cpu_to_le16(dur); | |
256 | } | |
257 | EXPORT_SYMBOL(ieee80211_generic_frame_duration); | |
258 | ||
32bfd35d JB |
259 | __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, |
260 | struct ieee80211_vif *vif, size_t frame_len, | |
e039fa4a | 261 | const struct ieee80211_tx_info *frame_txctl) |
c2d1560a JB |
262 | { |
263 | struct ieee80211_local *local = hw_to_local(hw); | |
264 | struct ieee80211_rate *rate; | |
25d834e1 | 265 | struct ieee80211_sub_if_data *sdata; |
471b3efd | 266 | bool short_preamble; |
c2d1560a JB |
267 | int erp; |
268 | u16 dur; | |
2e92e6f2 JB |
269 | struct ieee80211_supported_band *sband; |
270 | ||
271 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
c2d1560a | 272 | |
25d834e1 | 273 | short_preamble = false; |
7e9ed188 | 274 | |
e039fa4a | 275 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
8318d78a JB |
276 | |
277 | erp = 0; | |
25d834e1 JB |
278 | if (vif) { |
279 | sdata = vif_to_sdata(vif); | |
bda3933a | 280 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
281 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
282 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
283 | } | |
c2d1560a JB |
284 | |
285 | /* CTS duration */ | |
8318d78a | 286 | dur = ieee80211_frame_duration(local, 10, rate->bitrate, |
c2d1560a JB |
287 | erp, short_preamble); |
288 | /* Data frame duration */ | |
8318d78a | 289 | dur += ieee80211_frame_duration(local, frame_len, rate->bitrate, |
c2d1560a JB |
290 | erp, short_preamble); |
291 | /* ACK duration */ | |
8318d78a | 292 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
c2d1560a JB |
293 | erp, short_preamble); |
294 | ||
295 | return cpu_to_le16(dur); | |
296 | } | |
297 | EXPORT_SYMBOL(ieee80211_rts_duration); | |
298 | ||
32bfd35d JB |
299 | __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, |
300 | struct ieee80211_vif *vif, | |
c2d1560a | 301 | size_t frame_len, |
e039fa4a | 302 | const struct ieee80211_tx_info *frame_txctl) |
c2d1560a JB |
303 | { |
304 | struct ieee80211_local *local = hw_to_local(hw); | |
305 | struct ieee80211_rate *rate; | |
25d834e1 | 306 | struct ieee80211_sub_if_data *sdata; |
471b3efd | 307 | bool short_preamble; |
c2d1560a JB |
308 | int erp; |
309 | u16 dur; | |
2e92e6f2 JB |
310 | struct ieee80211_supported_band *sband; |
311 | ||
312 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
c2d1560a | 313 | |
25d834e1 | 314 | short_preamble = false; |
7e9ed188 | 315 | |
e039fa4a | 316 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
8318d78a | 317 | erp = 0; |
25d834e1 JB |
318 | if (vif) { |
319 | sdata = vif_to_sdata(vif); | |
bda3933a | 320 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
25d834e1 JB |
321 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
322 | erp = rate->flags & IEEE80211_RATE_ERP_G; | |
323 | } | |
c2d1560a JB |
324 | |
325 | /* Data frame duration */ | |
8318d78a | 326 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, |
c2d1560a | 327 | erp, short_preamble); |
e039fa4a | 328 | if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { |
c2d1560a | 329 | /* ACK duration */ |
8318d78a | 330 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
c2d1560a JB |
331 | erp, short_preamble); |
332 | } | |
333 | ||
334 | return cpu_to_le16(dur); | |
335 | } | |
336 | EXPORT_SYMBOL(ieee80211_ctstoself_duration); | |
337 | ||
ce7c9111 KV |
338 | static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, |
339 | enum queue_stop_reason reason) | |
c2d1560a JB |
340 | { |
341 | struct ieee80211_local *local = hw_to_local(hw); | |
342 | ||
e4e72fb4 JB |
343 | if (WARN_ON(queue >= hw->queues)) |
344 | return; | |
ce7c9111 | 345 | |
96f5e66e JB |
346 | __clear_bit(reason, &local->queue_stop_reasons[queue]); |
347 | ||
2a577d98 JB |
348 | if (!skb_queue_empty(&local->pending[queue]) && |
349 | local->queue_stop_reasons[queue] == | |
350 | BIT(IEEE80211_QUEUE_STOP_REASON_PENDING)) | |
351 | tasklet_schedule(&local->tx_pending_tasklet); | |
352 | ||
96f5e66e JB |
353 | if (local->queue_stop_reasons[queue] != 0) |
354 | /* someone still has this queue stopped */ | |
355 | return; | |
356 | ||
2a577d98 | 357 | netif_wake_subqueue(local->mdev, queue); |
c2d1560a | 358 | } |
ce7c9111 | 359 | |
96f5e66e JB |
360 | void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, |
361 | enum queue_stop_reason reason) | |
ce7c9111 KV |
362 | { |
363 | struct ieee80211_local *local = hw_to_local(hw); | |
364 | unsigned long flags; | |
365 | ||
366 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
367 | __ieee80211_wake_queue(hw, queue, reason); | |
368 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
369 | } | |
370 | ||
371 | void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) | |
372 | { | |
373 | ieee80211_wake_queue_by_reason(hw, queue, | |
374 | IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
375 | } | |
c2d1560a JB |
376 | EXPORT_SYMBOL(ieee80211_wake_queue); |
377 | ||
ce7c9111 KV |
378 | static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, |
379 | enum queue_stop_reason reason) | |
c2d1560a JB |
380 | { |
381 | struct ieee80211_local *local = hw_to_local(hw); | |
382 | ||
e4e72fb4 JB |
383 | if (WARN_ON(queue >= hw->queues)) |
384 | return; | |
96f5e66e | 385 | |
2a577d98 JB |
386 | /* |
387 | * Only stop if it was previously running, this is necessary | |
388 | * for correct pending packets handling because there we may | |
389 | * start (but not wake) the queue and rely on that. | |
390 | */ | |
391 | if (!local->queue_stop_reasons[queue]) | |
392 | netif_stop_subqueue(local->mdev, queue); | |
ce7c9111 | 393 | |
2a577d98 | 394 | __set_bit(reason, &local->queue_stop_reasons[queue]); |
c2d1560a | 395 | } |
ce7c9111 | 396 | |
96f5e66e JB |
397 | void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, |
398 | enum queue_stop_reason reason) | |
ce7c9111 KV |
399 | { |
400 | struct ieee80211_local *local = hw_to_local(hw); | |
401 | unsigned long flags; | |
402 | ||
403 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
404 | __ieee80211_stop_queue(hw, queue, reason); | |
405 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
406 | } | |
407 | ||
408 | void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) | |
409 | { | |
410 | ieee80211_stop_queue_by_reason(hw, queue, | |
411 | IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
412 | } | |
c2d1560a JB |
413 | EXPORT_SYMBOL(ieee80211_stop_queue); |
414 | ||
ce7c9111 KV |
415 | void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, |
416 | enum queue_stop_reason reason) | |
c2d1560a | 417 | { |
ce7c9111 KV |
418 | struct ieee80211_local *local = hw_to_local(hw); |
419 | unsigned long flags; | |
c2d1560a JB |
420 | int i; |
421 | ||
ce7c9111 KV |
422 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
423 | ||
96f5e66e | 424 | for (i = 0; i < hw->queues; i++) |
ce7c9111 KV |
425 | __ieee80211_stop_queue(hw, i, reason); |
426 | ||
427 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
428 | } | |
429 | ||
430 | void ieee80211_stop_queues(struct ieee80211_hw *hw) | |
431 | { | |
432 | ieee80211_stop_queues_by_reason(hw, | |
433 | IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
c2d1560a JB |
434 | } |
435 | EXPORT_SYMBOL(ieee80211_stop_queues); | |
436 | ||
92ab8535 TW |
437 | int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) |
438 | { | |
439 | struct ieee80211_local *local = hw_to_local(hw); | |
96f5e66e | 440 | |
e4e72fb4 JB |
441 | if (WARN_ON(queue >= hw->queues)) |
442 | return true; | |
96f5e66e | 443 | |
92ab8535 TW |
444 | return __netif_subqueue_stopped(local->mdev, queue); |
445 | } | |
446 | EXPORT_SYMBOL(ieee80211_queue_stopped); | |
447 | ||
ce7c9111 KV |
448 | void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, |
449 | enum queue_stop_reason reason) | |
c2d1560a | 450 | { |
ce7c9111 KV |
451 | struct ieee80211_local *local = hw_to_local(hw); |
452 | unsigned long flags; | |
c2d1560a JB |
453 | int i; |
454 | ||
ce7c9111 KV |
455 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
456 | ||
e4e72fb4 | 457 | for (i = 0; i < hw->queues; i++) |
ce7c9111 KV |
458 | __ieee80211_wake_queue(hw, i, reason); |
459 | ||
460 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); | |
461 | } | |
462 | ||
463 | void ieee80211_wake_queues(struct ieee80211_hw *hw) | |
464 | { | |
465 | ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER); | |
c2d1560a JB |
466 | } |
467 | EXPORT_SYMBOL(ieee80211_wake_queues); | |
dabeb344 | 468 | |
32bfd35d JB |
469 | void ieee80211_iterate_active_interfaces( |
470 | struct ieee80211_hw *hw, | |
471 | void (*iterator)(void *data, u8 *mac, | |
472 | struct ieee80211_vif *vif), | |
473 | void *data) | |
dabeb344 JB |
474 | { |
475 | struct ieee80211_local *local = hw_to_local(hw); | |
476 | struct ieee80211_sub_if_data *sdata; | |
477 | ||
c771c9d8 | 478 | mutex_lock(&local->iflist_mtx); |
2f561feb ID |
479 | |
480 | list_for_each_entry(sdata, &local->interfaces, list) { | |
481 | switch (sdata->vif.type) { | |
05c914fe JB |
482 | case __NL80211_IFTYPE_AFTER_LAST: |
483 | case NL80211_IFTYPE_UNSPECIFIED: | |
484 | case NL80211_IFTYPE_MONITOR: | |
485 | case NL80211_IFTYPE_AP_VLAN: | |
2f561feb | 486 | continue; |
05c914fe JB |
487 | case NL80211_IFTYPE_AP: |
488 | case NL80211_IFTYPE_STATION: | |
489 | case NL80211_IFTYPE_ADHOC: | |
490 | case NL80211_IFTYPE_WDS: | |
491 | case NL80211_IFTYPE_MESH_POINT: | |
2f561feb ID |
492 | break; |
493 | } | |
2f561feb ID |
494 | if (netif_running(sdata->dev)) |
495 | iterator(data, sdata->dev->dev_addr, | |
496 | &sdata->vif); | |
497 | } | |
498 | ||
c771c9d8 | 499 | mutex_unlock(&local->iflist_mtx); |
2f561feb ID |
500 | } |
501 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); | |
502 | ||
503 | void ieee80211_iterate_active_interfaces_atomic( | |
504 | struct ieee80211_hw *hw, | |
505 | void (*iterator)(void *data, u8 *mac, | |
506 | struct ieee80211_vif *vif), | |
507 | void *data) | |
508 | { | |
509 | struct ieee80211_local *local = hw_to_local(hw); | |
510 | struct ieee80211_sub_if_data *sdata; | |
511 | ||
e38bad47 | 512 | rcu_read_lock(); |
dabeb344 | 513 | |
e38bad47 | 514 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
51fb61e7 | 515 | switch (sdata->vif.type) { |
05c914fe JB |
516 | case __NL80211_IFTYPE_AFTER_LAST: |
517 | case NL80211_IFTYPE_UNSPECIFIED: | |
518 | case NL80211_IFTYPE_MONITOR: | |
519 | case NL80211_IFTYPE_AP_VLAN: | |
dabeb344 | 520 | continue; |
05c914fe JB |
521 | case NL80211_IFTYPE_AP: |
522 | case NL80211_IFTYPE_STATION: | |
523 | case NL80211_IFTYPE_ADHOC: | |
524 | case NL80211_IFTYPE_WDS: | |
525 | case NL80211_IFTYPE_MESH_POINT: | |
dabeb344 JB |
526 | break; |
527 | } | |
dabeb344 JB |
528 | if (netif_running(sdata->dev)) |
529 | iterator(data, sdata->dev->dev_addr, | |
32bfd35d | 530 | &sdata->vif); |
dabeb344 | 531 | } |
e38bad47 JB |
532 | |
533 | rcu_read_unlock(); | |
dabeb344 | 534 | } |
2f561feb | 535 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); |
37ffc8da JB |
536 | |
537 | void ieee802_11_parse_elems(u8 *start, size_t len, | |
538 | struct ieee802_11_elems *elems) | |
539 | { | |
540 | size_t left = len; | |
541 | u8 *pos = start; | |
542 | ||
543 | memset(elems, 0, sizeof(*elems)); | |
544 | elems->ie_start = start; | |
545 | elems->total_len = len; | |
546 | ||
547 | while (left >= 2) { | |
548 | u8 id, elen; | |
549 | ||
550 | id = *pos++; | |
551 | elen = *pos++; | |
552 | left -= 2; | |
553 | ||
554 | if (elen > left) | |
555 | return; | |
556 | ||
557 | switch (id) { | |
558 | case WLAN_EID_SSID: | |
559 | elems->ssid = pos; | |
560 | elems->ssid_len = elen; | |
561 | break; | |
562 | case WLAN_EID_SUPP_RATES: | |
563 | elems->supp_rates = pos; | |
564 | elems->supp_rates_len = elen; | |
565 | break; | |
566 | case WLAN_EID_FH_PARAMS: | |
567 | elems->fh_params = pos; | |
568 | elems->fh_params_len = elen; | |
569 | break; | |
570 | case WLAN_EID_DS_PARAMS: | |
571 | elems->ds_params = pos; | |
572 | elems->ds_params_len = elen; | |
573 | break; | |
574 | case WLAN_EID_CF_PARAMS: | |
575 | elems->cf_params = pos; | |
576 | elems->cf_params_len = elen; | |
577 | break; | |
578 | case WLAN_EID_TIM: | |
579 | elems->tim = pos; | |
580 | elems->tim_len = elen; | |
581 | break; | |
582 | case WLAN_EID_IBSS_PARAMS: | |
583 | elems->ibss_params = pos; | |
584 | elems->ibss_params_len = elen; | |
585 | break; | |
586 | case WLAN_EID_CHALLENGE: | |
587 | elems->challenge = pos; | |
588 | elems->challenge_len = elen; | |
589 | break; | |
590 | case WLAN_EID_WPA: | |
591 | if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && | |
592 | pos[2] == 0xf2) { | |
593 | /* Microsoft OUI (00:50:F2) */ | |
594 | if (pos[3] == 1) { | |
595 | /* OUI Type 1 - WPA IE */ | |
596 | elems->wpa = pos; | |
597 | elems->wpa_len = elen; | |
598 | } else if (elen >= 5 && pos[3] == 2) { | |
599 | if (pos[4] == 0) { | |
600 | elems->wmm_info = pos; | |
601 | elems->wmm_info_len = elen; | |
602 | } else if (pos[4] == 1) { | |
603 | elems->wmm_param = pos; | |
604 | elems->wmm_param_len = elen; | |
605 | } | |
606 | } | |
607 | } | |
608 | break; | |
609 | case WLAN_EID_RSN: | |
610 | elems->rsn = pos; | |
611 | elems->rsn_len = elen; | |
612 | break; | |
613 | case WLAN_EID_ERP_INFO: | |
614 | elems->erp_info = pos; | |
615 | elems->erp_info_len = elen; | |
616 | break; | |
617 | case WLAN_EID_EXT_SUPP_RATES: | |
618 | elems->ext_supp_rates = pos; | |
619 | elems->ext_supp_rates_len = elen; | |
620 | break; | |
621 | case WLAN_EID_HT_CAPABILITY: | |
09914813 JB |
622 | if (elen >= sizeof(struct ieee80211_ht_cap)) |
623 | elems->ht_cap_elem = (void *)pos; | |
37ffc8da | 624 | break; |
d9fe60de JB |
625 | case WLAN_EID_HT_INFORMATION: |
626 | if (elen >= sizeof(struct ieee80211_ht_info)) | |
09914813 | 627 | elems->ht_info_elem = (void *)pos; |
37ffc8da JB |
628 | break; |
629 | case WLAN_EID_MESH_ID: | |
630 | elems->mesh_id = pos; | |
631 | elems->mesh_id_len = elen; | |
632 | break; | |
633 | case WLAN_EID_MESH_CONFIG: | |
634 | elems->mesh_config = pos; | |
635 | elems->mesh_config_len = elen; | |
636 | break; | |
637 | case WLAN_EID_PEER_LINK: | |
638 | elems->peer_link = pos; | |
639 | elems->peer_link_len = elen; | |
640 | break; | |
641 | case WLAN_EID_PREQ: | |
642 | elems->preq = pos; | |
643 | elems->preq_len = elen; | |
644 | break; | |
645 | case WLAN_EID_PREP: | |
646 | elems->prep = pos; | |
647 | elems->prep_len = elen; | |
648 | break; | |
649 | case WLAN_EID_PERR: | |
650 | elems->perr = pos; | |
651 | elems->perr_len = elen; | |
652 | break; | |
653 | case WLAN_EID_CHANNEL_SWITCH: | |
654 | elems->ch_switch_elem = pos; | |
655 | elems->ch_switch_elem_len = elen; | |
656 | break; | |
657 | case WLAN_EID_QUIET: | |
658 | if (!elems->quiet_elem) { | |
659 | elems->quiet_elem = pos; | |
660 | elems->quiet_elem_len = elen; | |
661 | } | |
662 | elems->num_of_quiet_elem++; | |
663 | break; | |
664 | case WLAN_EID_COUNTRY: | |
665 | elems->country_elem = pos; | |
666 | elems->country_elem_len = elen; | |
667 | break; | |
668 | case WLAN_EID_PWR_CONSTRAINT: | |
669 | elems->pwr_constr_elem = pos; | |
670 | elems->pwr_constr_elem_len = elen; | |
671 | break; | |
f797eb7e JM |
672 | case WLAN_EID_TIMEOUT_INTERVAL: |
673 | elems->timeout_int = pos; | |
674 | elems->timeout_int_len = elen; | |
63a5ab82 | 675 | break; |
37ffc8da JB |
676 | default: |
677 | break; | |
678 | } | |
679 | ||
680 | left -= elen; | |
681 | pos += elen; | |
682 | } | |
683 | } | |
5825fe10 JB |
684 | |
685 | void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) | |
686 | { | |
687 | struct ieee80211_local *local = sdata->local; | |
688 | struct ieee80211_tx_queue_params qparam; | |
689 | int i; | |
690 | ||
691 | if (!local->ops->conf_tx) | |
692 | return; | |
693 | ||
694 | memset(&qparam, 0, sizeof(qparam)); | |
695 | ||
696 | qparam.aifs = 2; | |
697 | ||
698 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
699 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)) | |
700 | qparam.cw_min = 31; | |
701 | else | |
702 | qparam.cw_min = 15; | |
703 | ||
704 | qparam.cw_max = 1023; | |
705 | qparam.txop = 0; | |
706 | ||
707 | for (i = 0; i < local_to_hw(local)->queues; i++) | |
708 | local->ops->conf_tx(local_to_hw(local), i, &qparam); | |
709 | } | |
e50db65c | 710 | |
46900298 JB |
711 | void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
712 | const size_t supp_rates_len, | |
713 | const u8 *supp_rates) | |
714 | { | |
715 | struct ieee80211_local *local = sdata->local; | |
716 | int i, have_higher_than_11mbit = 0; | |
717 | ||
718 | /* cf. IEEE 802.11 9.2.12 */ | |
719 | for (i = 0; i < supp_rates_len; i++) | |
720 | if ((supp_rates[i] & 0x7f) * 5 > 110) | |
721 | have_higher_than_11mbit = 1; | |
722 | ||
723 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && | |
724 | have_higher_than_11mbit) | |
725 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
726 | else | |
727 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
728 | ||
729 | ieee80211_set_wmm_default(sdata); | |
730 | } | |
731 | ||
e50db65c JB |
732 | void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
733 | int encrypt) | |
734 | { | |
735 | skb->dev = sdata->local->mdev; | |
736 | skb_set_mac_header(skb, 0); | |
737 | skb_set_network_header(skb, 0); | |
738 | skb_set_transport_header(skb, 0); | |
739 | ||
740 | skb->iif = sdata->dev->ifindex; | |
741 | skb->do_not_encrypt = !encrypt; | |
742 | ||
743 | dev_queue_xmit(skb); | |
744 | } | |
e16751c3 JB |
745 | |
746 | int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz) | |
747 | { | |
748 | int ret = -EINVAL; | |
749 | struct ieee80211_channel *chan; | |
750 | struct ieee80211_local *local = sdata->local; | |
751 | ||
752 | chan = ieee80211_get_channel(local->hw.wiphy, freqMHz); | |
753 | ||
754 | if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) { | |
05c914fe | 755 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
d73782fd | 756 | chan->flags & IEEE80211_CHAN_NO_IBSS) |
e16751c3 | 757 | return ret; |
e16751c3 | 758 | local->oper_channel = chan; |
094d05dc | 759 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
e16751c3 | 760 | |
c2b13452 | 761 | if (local->sw_scanning || local->hw_scanning) |
e16751c3 JB |
762 | ret = 0; |
763 | else | |
e8975581 JB |
764 | ret = ieee80211_hw_config( |
765 | local, IEEE80211_CONF_CHANGE_CHANNEL); | |
e16751c3 JB |
766 | } |
767 | ||
768 | return ret; | |
769 | } | |
96dd22ac | 770 | |
881d948c | 771 | u32 ieee80211_mandatory_rates(struct ieee80211_local *local, |
96dd22ac JB |
772 | enum ieee80211_band band) |
773 | { | |
774 | struct ieee80211_supported_band *sband; | |
775 | struct ieee80211_rate *bitrates; | |
881d948c | 776 | u32 mandatory_rates; |
96dd22ac JB |
777 | enum ieee80211_rate_flags mandatory_flag; |
778 | int i; | |
779 | ||
780 | sband = local->hw.wiphy->bands[band]; | |
781 | if (!sband) { | |
782 | WARN_ON(1); | |
783 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
784 | } | |
785 | ||
786 | if (band == IEEE80211_BAND_2GHZ) | |
787 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; | |
788 | else | |
789 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; | |
790 | ||
791 | bitrates = sband->bitrates; | |
792 | mandatory_rates = 0; | |
793 | for (i = 0; i < sband->n_bitrates; i++) | |
794 | if (bitrates[i].flags & mandatory_flag) | |
795 | mandatory_rates |= BIT(i); | |
796 | return mandatory_rates; | |
797 | } | |
46900298 JB |
798 | |
799 | void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, | |
800 | u16 transaction, u16 auth_alg, | |
801 | u8 *extra, size_t extra_len, | |
802 | const u8 *bssid, int encrypt) | |
803 | { | |
804 | struct ieee80211_local *local = sdata->local; | |
805 | struct sk_buff *skb; | |
806 | struct ieee80211_mgmt *mgmt; | |
46900298 JB |
807 | |
808 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
65fc73ac | 809 | sizeof(*mgmt) + 6 + extra_len); |
46900298 JB |
810 | if (!skb) { |
811 | printk(KERN_DEBUG "%s: failed to allocate buffer for auth " | |
812 | "frame\n", sdata->dev->name); | |
813 | return; | |
814 | } | |
815 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
816 | ||
817 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); | |
818 | memset(mgmt, 0, 24 + 6); | |
819 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
820 | IEEE80211_STYPE_AUTH); | |
821 | if (encrypt) | |
822 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); | |
823 | memcpy(mgmt->da, bssid, ETH_ALEN); | |
824 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
825 | memcpy(mgmt->bssid, bssid, ETH_ALEN); | |
826 | mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); | |
827 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); | |
828 | mgmt->u.auth.status_code = cpu_to_le16(0); | |
829 | if (extra) | |
830 | memcpy(skb_put(skb, extra_len), extra, extra_len); | |
46900298 JB |
831 | |
832 | ieee80211_tx_skb(sdata, skb, encrypt); | |
833 | } | |
834 | ||
de95a54b JB |
835 | int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, |
836 | const u8 *ie, size_t ie_len) | |
837 | { | |
838 | struct ieee80211_supported_band *sband; | |
839 | u8 *pos, *supp_rates_len, *esupp_rates_len = NULL; | |
840 | int i; | |
841 | ||
842 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
843 | ||
844 | pos = buffer; | |
845 | ||
846 | *pos++ = WLAN_EID_SUPP_RATES; | |
847 | supp_rates_len = pos; | |
848 | *pos++ = 0; | |
849 | ||
850 | for (i = 0; i < sband->n_bitrates; i++) { | |
851 | struct ieee80211_rate *rate = &sband->bitrates[i]; | |
852 | ||
853 | if (esupp_rates_len) { | |
854 | *esupp_rates_len += 1; | |
855 | } else if (*supp_rates_len == 8) { | |
856 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
857 | esupp_rates_len = pos; | |
858 | *pos++ = 1; | |
859 | } else | |
860 | *supp_rates_len += 1; | |
861 | ||
862 | *pos++ = rate->bitrate / 5; | |
863 | } | |
864 | ||
5ef2d41a JB |
865 | if (sband->ht_cap.ht_supported) { |
866 | __le16 tmp = cpu_to_le16(sband->ht_cap.cap); | |
867 | ||
868 | *pos++ = WLAN_EID_HT_CAPABILITY; | |
869 | *pos++ = sizeof(struct ieee80211_ht_cap); | |
870 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); | |
871 | memcpy(pos, &tmp, sizeof(u16)); | |
872 | pos += sizeof(u16); | |
873 | /* TODO: needs a define here for << 2 */ | |
874 | *pos++ = sband->ht_cap.ampdu_factor | | |
875 | (sband->ht_cap.ampdu_density << 2); | |
876 | memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); | |
877 | pos += sizeof(sband->ht_cap.mcs); | |
878 | pos += 2 + 4 + 1; /* ext info, BF cap, antsel */ | |
879 | } | |
880 | ||
de95a54b JB |
881 | /* |
882 | * If adding more here, adjust code in main.c | |
883 | * that calculates local->scan_ies_len. | |
884 | */ | |
885 | ||
886 | if (ie) { | |
887 | memcpy(pos, ie, ie_len); | |
888 | pos += ie_len; | |
889 | } | |
890 | ||
891 | return pos - buffer; | |
892 | } | |
893 | ||
46900298 | 894 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, |
de95a54b JB |
895 | const u8 *ssid, size_t ssid_len, |
896 | const u8 *ie, size_t ie_len) | |
46900298 JB |
897 | { |
898 | struct ieee80211_local *local = sdata->local; | |
46900298 JB |
899 | struct sk_buff *skb; |
900 | struct ieee80211_mgmt *mgmt; | |
de95a54b | 901 | u8 *pos; |
46900298 JB |
902 | |
903 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 + | |
65fc73ac | 904 | ie_len); |
46900298 JB |
905 | if (!skb) { |
906 | printk(KERN_DEBUG "%s: failed to allocate buffer for probe " | |
907 | "request\n", sdata->dev->name); | |
908 | return; | |
909 | } | |
910 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
911 | ||
912 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
913 | memset(mgmt, 0, 24); | |
914 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
915 | IEEE80211_STYPE_PROBE_REQ); | |
916 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
917 | if (dst) { | |
918 | memcpy(mgmt->da, dst, ETH_ALEN); | |
919 | memcpy(mgmt->bssid, dst, ETH_ALEN); | |
920 | } else { | |
921 | memset(mgmt->da, 0xff, ETH_ALEN); | |
922 | memset(mgmt->bssid, 0xff, ETH_ALEN); | |
923 | } | |
924 | pos = skb_put(skb, 2 + ssid_len); | |
925 | *pos++ = WLAN_EID_SSID; | |
926 | *pos++ = ssid_len; | |
927 | memcpy(pos, ssid, ssid_len); | |
de95a54b | 928 | pos += ssid_len; |
46900298 | 929 | |
de95a54b | 930 | skb_put(skb, ieee80211_build_preq_ies(local, pos, ie, ie_len)); |
46900298 JB |
931 | |
932 | ieee80211_tx_skb(sdata, skb, 0); | |
933 | } | |
934 | ||
935 | u32 ieee80211_sta_get_rates(struct ieee80211_local *local, | |
936 | struct ieee802_11_elems *elems, | |
937 | enum ieee80211_band band) | |
938 | { | |
939 | struct ieee80211_supported_band *sband; | |
940 | struct ieee80211_rate *bitrates; | |
941 | size_t num_rates; | |
942 | u32 supp_rates; | |
943 | int i, j; | |
944 | sband = local->hw.wiphy->bands[band]; | |
945 | ||
946 | if (!sband) { | |
947 | WARN_ON(1); | |
948 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
949 | } | |
950 | ||
951 | bitrates = sband->bitrates; | |
952 | num_rates = sband->n_bitrates; | |
953 | supp_rates = 0; | |
954 | for (i = 0; i < elems->supp_rates_len + | |
955 | elems->ext_supp_rates_len; i++) { | |
956 | u8 rate = 0; | |
957 | int own_rate; | |
958 | if (i < elems->supp_rates_len) | |
959 | rate = elems->supp_rates[i]; | |
960 | else if (elems->ext_supp_rates) | |
961 | rate = elems->ext_supp_rates | |
962 | [i - elems->supp_rates_len]; | |
963 | own_rate = 5 * (rate & 0x7f); | |
964 | for (j = 0; j < num_rates; j++) | |
965 | if (bitrates[j].bitrate == own_rate) | |
966 | supp_rates |= BIT(j); | |
967 | } | |
968 | return supp_rates; | |
969 | } | |
f2753ddb JB |
970 | |
971 | int ieee80211_reconfig(struct ieee80211_local *local) | |
972 | { | |
973 | struct ieee80211_hw *hw = &local->hw; | |
974 | struct ieee80211_sub_if_data *sdata; | |
975 | struct ieee80211_if_init_conf conf; | |
976 | struct sta_info *sta; | |
977 | unsigned long flags; | |
978 | int res; | |
979 | ||
980 | /* restart hardware */ | |
981 | if (local->open_count) { | |
982 | res = local->ops->start(hw); | |
983 | ||
984 | ieee80211_led_radio(local, hw->conf.radio_enabled); | |
985 | } | |
986 | ||
987 | /* add interfaces */ | |
988 | list_for_each_entry(sdata, &local->interfaces, list) { | |
989 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | |
990 | sdata->vif.type != NL80211_IFTYPE_MONITOR && | |
991 | netif_running(sdata->dev)) { | |
992 | conf.vif = &sdata->vif; | |
993 | conf.type = sdata->vif.type; | |
994 | conf.mac_addr = sdata->dev->dev_addr; | |
995 | res = local->ops->add_interface(hw, &conf); | |
996 | } | |
997 | } | |
998 | ||
999 | /* add STAs back */ | |
1000 | if (local->ops->sta_notify) { | |
1001 | spin_lock_irqsave(&local->sta_lock, flags); | |
1002 | list_for_each_entry(sta, &local->sta_list, list) { | |
1003 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
1004 | sdata = container_of(sdata->bss, | |
1005 | struct ieee80211_sub_if_data, | |
1006 | u.ap); | |
1007 | ||
1008 | local->ops->sta_notify(hw, &sdata->vif, | |
1009 | STA_NOTIFY_ADD, &sta->sta); | |
1010 | } | |
1011 | spin_unlock_irqrestore(&local->sta_lock, flags); | |
1012 | } | |
1013 | ||
1014 | /* Clear Suspend state so that ADDBA requests can be processed */ | |
1015 | ||
1016 | rcu_read_lock(); | |
1017 | ||
1018 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { | |
1019 | list_for_each_entry_rcu(sta, &local->sta_list, list) { | |
1020 | clear_sta_flags(sta, WLAN_STA_SUSPEND); | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | rcu_read_unlock(); | |
1025 | ||
1026 | /* setup RTS threshold */ | |
1027 | if (local->ops->set_rts_threshold) | |
1028 | local->ops->set_rts_threshold(hw, local->rts_threshold); | |
1029 | ||
1030 | /* reconfigure hardware */ | |
1031 | ieee80211_hw_config(local, ~0); | |
1032 | ||
1033 | netif_addr_lock_bh(local->mdev); | |
1034 | ieee80211_configure_filter(local); | |
1035 | netif_addr_unlock_bh(local->mdev); | |
1036 | ||
1037 | /* Finally also reconfigure all the BSS information */ | |
1038 | list_for_each_entry(sdata, &local->interfaces, list) { | |
1039 | u32 changed = ~0; | |
1040 | if (!netif_running(sdata->dev)) | |
1041 | continue; | |
1042 | switch (sdata->vif.type) { | |
1043 | case NL80211_IFTYPE_STATION: | |
1044 | /* disable beacon change bits */ | |
1045 | changed &= ~IEEE80211_IFCC_BEACON; | |
1046 | /* fall through */ | |
1047 | case NL80211_IFTYPE_ADHOC: | |
1048 | case NL80211_IFTYPE_AP: | |
1049 | case NL80211_IFTYPE_MESH_POINT: | |
1050 | /* | |
1051 | * Driver's config_interface can fail if rfkill is | |
1052 | * enabled. Accommodate this return code. | |
1053 | * FIXME: When mac80211 has knowledge of rfkill | |
1054 | * state the code below can change back to: | |
1055 | * WARN(ieee80211_if_config(sdata, changed)); | |
1056 | * ieee80211_bss_info_change_notify(sdata, ~0); | |
1057 | */ | |
1058 | if (ieee80211_if_config(sdata, changed)) | |
1059 | printk(KERN_DEBUG "%s: failed to configure interface during resume\n", | |
1060 | sdata->dev->name); | |
1061 | else | |
1062 | ieee80211_bss_info_change_notify(sdata, ~0); | |
1063 | break; | |
1064 | case NL80211_IFTYPE_WDS: | |
1065 | break; | |
1066 | case NL80211_IFTYPE_AP_VLAN: | |
1067 | case NL80211_IFTYPE_MONITOR: | |
1068 | /* ignore virtual */ | |
1069 | break; | |
1070 | case NL80211_IFTYPE_UNSPECIFIED: | |
1071 | case __NL80211_IFTYPE_AFTER_LAST: | |
1072 | WARN_ON(1); | |
1073 | break; | |
1074 | } | |
1075 | } | |
1076 | ||
1077 | /* add back keys */ | |
1078 | list_for_each_entry(sdata, &local->interfaces, list) | |
1079 | if (netif_running(sdata->dev)) | |
1080 | ieee80211_enable_keys(sdata); | |
1081 | ||
1082 | ieee80211_wake_queues_by_reason(hw, | |
1083 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); | |
1084 | ||
1085 | return 0; | |
1086 | } |