libertas: Reduce the WPA key installation time.
[deliverable/linux.git] / net / mac80211 / util.c
CommitLineData
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
JB
30#include "wme.h"
31
32/* privid for wiphys to determine whether they belong to us or not */
33void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
34
35/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
36/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
c97c23e3 37const unsigned char rfc1042_header[] __aligned(2) =
c2d1560a
JB
38 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
39
40/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
c97c23e3 41const unsigned char bridge_tunnel_header[] __aligned(2) =
c2d1560a
JB
42 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
43
c2d1560a 44
71364716 45u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
05c914fe 46 enum nl80211_iftype type)
c2d1560a 47{
a494bb1c 48 __le16 fc = hdr->frame_control;
c2d1560a 49
98f0b0a3
RR
50 /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
51 if (len < 16)
c2d1560a
JB
52 return NULL;
53
a494bb1c 54 if (ieee80211_is_data(fc)) {
98f0b0a3
RR
55 if (len < 24) /* drop incorrect hdr len (data) */
56 return NULL;
a494bb1c
HH
57
58 if (ieee80211_has_a4(fc))
c2d1560a 59 return NULL;
a494bb1c
HH
60 if (ieee80211_has_tods(fc))
61 return hdr->addr1;
62 if (ieee80211_has_fromds(fc))
c2d1560a 63 return hdr->addr2;
a494bb1c
HH
64
65 return hdr->addr3;
66 }
67
68 if (ieee80211_is_mgmt(fc)) {
98f0b0a3
RR
69 if (len < 24) /* drop incorrect hdr len (mgmt) */
70 return NULL;
c2d1560a 71 return hdr->addr3;
a494bb1c
HH
72 }
73
74 if (ieee80211_is_ctl(fc)) {
75 if(ieee80211_is_pspoll(fc))
c2d1560a 76 return hdr->addr1;
a494bb1c
HH
77
78 if (ieee80211_is_back_req(fc)) {
71364716 79 switch (type) {
05c914fe 80 case NL80211_IFTYPE_STATION:
71364716 81 return hdr->addr2;
05c914fe
JB
82 case NL80211_IFTYPE_AP:
83 case NL80211_IFTYPE_AP_VLAN:
71364716
RR
84 return hdr->addr1;
85 default:
a494bb1c 86 break; /* fall through to the return */
71364716
RR
87 }
88 }
c2d1560a
JB
89 }
90
91 return NULL;
92}
93
6693be71
HH
94unsigned int ieee80211_hdrlen(__le16 fc)
95{
96 unsigned int hdrlen = 24;
97
98 if (ieee80211_is_data(fc)) {
99 if (ieee80211_has_a4(fc))
100 hdrlen = 30;
101 if (ieee80211_is_data_qos(fc))
102 hdrlen += IEEE80211_QOS_CTL_LEN;
103 goto out;
104 }
105
106 if (ieee80211_is_ctl(fc)) {
107 /*
108 * ACK and CTS are 10 bytes, all others 16. To see how
109 * to get this condition consider
110 * subtype mask: 0b0000000011110000 (0x00F0)
111 * ACK subtype: 0b0000000011010000 (0x00D0)
112 * CTS subtype: 0b0000000011000000 (0x00C0)
113 * bits that matter: ^^^ (0x00E0)
114 * value of those: 0b0000000011000000 (0x00C0)
115 */
116 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
117 hdrlen = 10;
118 else
119 hdrlen = 16;
120 }
121out:
122 return hdrlen;
123}
124EXPORT_SYMBOL(ieee80211_hdrlen);
125
c9c6950c 126unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
c2d1560a 127{
c9c6950c
HH
128 const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data;
129 unsigned int hdrlen;
c2d1560a
JB
130
131 if (unlikely(skb->len < 10))
132 return 0;
c9c6950c 133 hdrlen = ieee80211_hdrlen(hdr->frame_control);
c2d1560a
JB
134 if (unlikely(hdrlen > skb->len))
135 return 0;
136 return hdrlen;
137}
138EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
139
ee385855
LCC
140int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
141{
142 int ae = meshhdr->flags & IEEE80211S_FLAGS_AE;
143 /* 7.1.3.5a.2 */
144 switch (ae) {
145 case 0:
ef269254 146 return 6;
ee385855 147 case 1:
ef269254 148 return 12;
ee385855 149 case 2:
ef269254 150 return 18;
ee385855 151 case 3:
ef269254 152 return 24;
ee385855 153 default:
ef269254 154 return 6;
ee385855
LCC
155 }
156}
ee385855 157
5cf121c3 158void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
c2d1560a
JB
159{
160 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
161
162 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
5cf121c3 163 if (tx->extra_frag) {
c2d1560a
JB
164 struct ieee80211_hdr *fhdr;
165 int i;
5cf121c3 166 for (i = 0; i < tx->num_extra_frag; i++) {
c2d1560a 167 fhdr = (struct ieee80211_hdr *)
5cf121c3 168 tx->extra_frag[i]->data;
c2d1560a
JB
169 fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
170 }
171 }
172}
173
174int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
175 int rate, int erp, int short_preamble)
176{
177 int dur;
178
179 /* calculate duration (in microseconds, rounded up to next higher
180 * integer if it includes a fractional microsecond) to send frame of
181 * len bytes (does not include FCS) at the given rate. Duration will
182 * also include SIFS.
183 *
184 * rate is in 100 kbps, so divident is multiplied by 10 in the
185 * DIV_ROUND_UP() operations.
186 */
187
8318d78a 188 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
c2d1560a
JB
189 /*
190 * OFDM:
191 *
192 * N_DBPS = DATARATE x 4
193 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
194 * (16 = SIGNAL time, 6 = tail bits)
195 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
196 *
197 * T_SYM = 4 usec
198 * 802.11a - 17.5.2: aSIFSTime = 16 usec
199 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
200 * signal ext = 6 usec
201 */
c2d1560a
JB
202 dur = 16; /* SIFS + signal ext */
203 dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
204 dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
205 dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
206 4 * rate); /* T_SYM x N_SYM */
207 } else {
208 /*
209 * 802.11b or 802.11g with 802.11b compatibility:
210 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
211 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
212 *
213 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
214 * aSIFSTime = 10 usec
215 * aPreambleLength = 144 usec or 72 usec with short preamble
216 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
217 */
218 dur = 10; /* aSIFSTime = 10 usec */
219 dur += short_preamble ? (72 + 24) : (144 + 48);
220
221 dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
222 }
223
224 return dur;
225}
226
227/* Exported duration function for driver use */
32bfd35d
JB
228__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
229 struct ieee80211_vif *vif,
8318d78a
JB
230 size_t frame_len,
231 struct ieee80211_rate *rate)
c2d1560a
JB
232{
233 struct ieee80211_local *local = hw_to_local(hw);
32bfd35d 234 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
c2d1560a
JB
235 u16 dur;
236 int erp;
237
8318d78a
JB
238 erp = 0;
239 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
240 erp = rate->flags & IEEE80211_RATE_ERP_G;
241
242 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
471b3efd 243 sdata->bss_conf.use_short_preamble);
c2d1560a
JB
244
245 return cpu_to_le16(dur);
246}
247EXPORT_SYMBOL(ieee80211_generic_frame_duration);
248
32bfd35d
JB
249__le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
250 struct ieee80211_vif *vif, size_t frame_len,
e039fa4a 251 const struct ieee80211_tx_info *frame_txctl)
c2d1560a
JB
252{
253 struct ieee80211_local *local = hw_to_local(hw);
254 struct ieee80211_rate *rate;
32bfd35d 255 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
471b3efd 256 bool short_preamble;
c2d1560a
JB
257 int erp;
258 u16 dur;
2e92e6f2
JB
259 struct ieee80211_supported_band *sband;
260
261 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
c2d1560a 262
471b3efd 263 short_preamble = sdata->bss_conf.use_short_preamble;
7e9ed188 264
e039fa4a 265 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
8318d78a
JB
266
267 erp = 0;
268 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
269 erp = rate->flags & IEEE80211_RATE_ERP_G;
c2d1560a
JB
270
271 /* CTS duration */
8318d78a 272 dur = ieee80211_frame_duration(local, 10, rate->bitrate,
c2d1560a
JB
273 erp, short_preamble);
274 /* Data frame duration */
8318d78a 275 dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
c2d1560a
JB
276 erp, short_preamble);
277 /* ACK duration */
8318d78a 278 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
c2d1560a
JB
279 erp, short_preamble);
280
281 return cpu_to_le16(dur);
282}
283EXPORT_SYMBOL(ieee80211_rts_duration);
284
32bfd35d
JB
285__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
286 struct ieee80211_vif *vif,
c2d1560a 287 size_t frame_len,
e039fa4a 288 const struct ieee80211_tx_info *frame_txctl)
c2d1560a
JB
289{
290 struct ieee80211_local *local = hw_to_local(hw);
291 struct ieee80211_rate *rate;
32bfd35d 292 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
471b3efd 293 bool short_preamble;
c2d1560a
JB
294 int erp;
295 u16 dur;
2e92e6f2
JB
296 struct ieee80211_supported_band *sband;
297
298 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
c2d1560a 299
471b3efd 300 short_preamble = sdata->bss_conf.use_short_preamble;
7e9ed188 301
e039fa4a 302 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
8318d78a
JB
303 erp = 0;
304 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
305 erp = rate->flags & IEEE80211_RATE_ERP_G;
c2d1560a
JB
306
307 /* Data frame duration */
8318d78a 308 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
c2d1560a 309 erp, short_preamble);
e039fa4a 310 if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
c2d1560a 311 /* ACK duration */
8318d78a 312 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
c2d1560a
JB
313 erp, short_preamble);
314 }
315
316 return cpu_to_le16(dur);
317}
318EXPORT_SYMBOL(ieee80211_ctstoself_duration);
319
c2d1560a
JB
320void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
321{
322 struct ieee80211_local *local = hw_to_local(hw);
323
e2530083 324 if (test_bit(queue, local->queues_pending)) {
f8e79ddd 325 set_bit(queue, local->queues_pending_run);
e2530083
JB
326 tasklet_schedule(&local->tx_pending_tasklet);
327 } else {
51cb6db0 328 netif_wake_subqueue(local->mdev, queue);
c2d1560a
JB
329 }
330}
331EXPORT_SYMBOL(ieee80211_wake_queue);
332
333void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
334{
335 struct ieee80211_local *local = hw_to_local(hw);
336
51cb6db0 337 netif_stop_subqueue(local->mdev, queue);
c2d1560a
JB
338}
339EXPORT_SYMBOL(ieee80211_stop_queue);
340
c2d1560a
JB
341void ieee80211_stop_queues(struct ieee80211_hw *hw)
342{
343 int i;
344
e2530083 345 for (i = 0; i < ieee80211_num_queues(hw); i++)
c2d1560a
JB
346 ieee80211_stop_queue(hw, i);
347}
348EXPORT_SYMBOL(ieee80211_stop_queues);
349
92ab8535
TW
350int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
351{
352 struct ieee80211_local *local = hw_to_local(hw);
353 return __netif_subqueue_stopped(local->mdev, queue);
354}
355EXPORT_SYMBOL(ieee80211_queue_stopped);
356
c2d1560a
JB
357void ieee80211_wake_queues(struct ieee80211_hw *hw)
358{
359 int i;
360
c4680470 361 for (i = 0; i < hw->queues + hw->ampdu_queues; i++)
c2d1560a
JB
362 ieee80211_wake_queue(hw, i);
363}
364EXPORT_SYMBOL(ieee80211_wake_queues);
dabeb344 365
32bfd35d
JB
366void ieee80211_iterate_active_interfaces(
367 struct ieee80211_hw *hw,
368 void (*iterator)(void *data, u8 *mac,
369 struct ieee80211_vif *vif),
370 void *data)
dabeb344
JB
371{
372 struct ieee80211_local *local = hw_to_local(hw);
373 struct ieee80211_sub_if_data *sdata;
374
2f561feb
ID
375 rtnl_lock();
376
377 list_for_each_entry(sdata, &local->interfaces, list) {
378 switch (sdata->vif.type) {
05c914fe
JB
379 case __NL80211_IFTYPE_AFTER_LAST:
380 case NL80211_IFTYPE_UNSPECIFIED:
381 case NL80211_IFTYPE_MONITOR:
382 case NL80211_IFTYPE_AP_VLAN:
2f561feb 383 continue;
05c914fe
JB
384 case NL80211_IFTYPE_AP:
385 case NL80211_IFTYPE_STATION:
386 case NL80211_IFTYPE_ADHOC:
387 case NL80211_IFTYPE_WDS:
388 case NL80211_IFTYPE_MESH_POINT:
2f561feb
ID
389 break;
390 }
2f561feb
ID
391 if (netif_running(sdata->dev))
392 iterator(data, sdata->dev->dev_addr,
393 &sdata->vif);
394 }
395
396 rtnl_unlock();
397}
398EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
399
400void ieee80211_iterate_active_interfaces_atomic(
401 struct ieee80211_hw *hw,
402 void (*iterator)(void *data, u8 *mac,
403 struct ieee80211_vif *vif),
404 void *data)
405{
406 struct ieee80211_local *local = hw_to_local(hw);
407 struct ieee80211_sub_if_data *sdata;
408
e38bad47 409 rcu_read_lock();
dabeb344 410
e38bad47 411 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
51fb61e7 412 switch (sdata->vif.type) {
05c914fe
JB
413 case __NL80211_IFTYPE_AFTER_LAST:
414 case NL80211_IFTYPE_UNSPECIFIED:
415 case NL80211_IFTYPE_MONITOR:
416 case NL80211_IFTYPE_AP_VLAN:
dabeb344 417 continue;
05c914fe
JB
418 case NL80211_IFTYPE_AP:
419 case NL80211_IFTYPE_STATION:
420 case NL80211_IFTYPE_ADHOC:
421 case NL80211_IFTYPE_WDS:
422 case NL80211_IFTYPE_MESH_POINT:
dabeb344
JB
423 break;
424 }
dabeb344
JB
425 if (netif_running(sdata->dev))
426 iterator(data, sdata->dev->dev_addr,
32bfd35d 427 &sdata->vif);
dabeb344 428 }
e38bad47
JB
429
430 rcu_read_unlock();
dabeb344 431}
2f561feb 432EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
37ffc8da
JB
433
434void ieee802_11_parse_elems(u8 *start, size_t len,
435 struct ieee802_11_elems *elems)
436{
437 size_t left = len;
438 u8 *pos = start;
439
440 memset(elems, 0, sizeof(*elems));
441 elems->ie_start = start;
442 elems->total_len = len;
443
444 while (left >= 2) {
445 u8 id, elen;
446
447 id = *pos++;
448 elen = *pos++;
449 left -= 2;
450
451 if (elen > left)
452 return;
453
454 switch (id) {
455 case WLAN_EID_SSID:
456 elems->ssid = pos;
457 elems->ssid_len = elen;
458 break;
459 case WLAN_EID_SUPP_RATES:
460 elems->supp_rates = pos;
461 elems->supp_rates_len = elen;
462 break;
463 case WLAN_EID_FH_PARAMS:
464 elems->fh_params = pos;
465 elems->fh_params_len = elen;
466 break;
467 case WLAN_EID_DS_PARAMS:
468 elems->ds_params = pos;
469 elems->ds_params_len = elen;
470 break;
471 case WLAN_EID_CF_PARAMS:
472 elems->cf_params = pos;
473 elems->cf_params_len = elen;
474 break;
475 case WLAN_EID_TIM:
476 elems->tim = pos;
477 elems->tim_len = elen;
478 break;
479 case WLAN_EID_IBSS_PARAMS:
480 elems->ibss_params = pos;
481 elems->ibss_params_len = elen;
482 break;
483 case WLAN_EID_CHALLENGE:
484 elems->challenge = pos;
485 elems->challenge_len = elen;
486 break;
487 case WLAN_EID_WPA:
488 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
489 pos[2] == 0xf2) {
490 /* Microsoft OUI (00:50:F2) */
491 if (pos[3] == 1) {
492 /* OUI Type 1 - WPA IE */
493 elems->wpa = pos;
494 elems->wpa_len = elen;
495 } else if (elen >= 5 && pos[3] == 2) {
496 if (pos[4] == 0) {
497 elems->wmm_info = pos;
498 elems->wmm_info_len = elen;
499 } else if (pos[4] == 1) {
500 elems->wmm_param = pos;
501 elems->wmm_param_len = elen;
502 }
503 }
504 }
505 break;
506 case WLAN_EID_RSN:
507 elems->rsn = pos;
508 elems->rsn_len = elen;
509 break;
510 case WLAN_EID_ERP_INFO:
511 elems->erp_info = pos;
512 elems->erp_info_len = elen;
513 break;
514 case WLAN_EID_EXT_SUPP_RATES:
515 elems->ext_supp_rates = pos;
516 elems->ext_supp_rates_len = elen;
517 break;
518 case WLAN_EID_HT_CAPABILITY:
519 elems->ht_cap_elem = pos;
520 elems->ht_cap_elem_len = elen;
521 break;
522 case WLAN_EID_HT_EXTRA_INFO:
523 elems->ht_info_elem = pos;
524 elems->ht_info_elem_len = elen;
525 break;
526 case WLAN_EID_MESH_ID:
527 elems->mesh_id = pos;
528 elems->mesh_id_len = elen;
529 break;
530 case WLAN_EID_MESH_CONFIG:
531 elems->mesh_config = pos;
532 elems->mesh_config_len = elen;
533 break;
534 case WLAN_EID_PEER_LINK:
535 elems->peer_link = pos;
536 elems->peer_link_len = elen;
537 break;
538 case WLAN_EID_PREQ:
539 elems->preq = pos;
540 elems->preq_len = elen;
541 break;
542 case WLAN_EID_PREP:
543 elems->prep = pos;
544 elems->prep_len = elen;
545 break;
546 case WLAN_EID_PERR:
547 elems->perr = pos;
548 elems->perr_len = elen;
549 break;
550 case WLAN_EID_CHANNEL_SWITCH:
551 elems->ch_switch_elem = pos;
552 elems->ch_switch_elem_len = elen;
553 break;
554 case WLAN_EID_QUIET:
555 if (!elems->quiet_elem) {
556 elems->quiet_elem = pos;
557 elems->quiet_elem_len = elen;
558 }
559 elems->num_of_quiet_elem++;
560 break;
561 case WLAN_EID_COUNTRY:
562 elems->country_elem = pos;
563 elems->country_elem_len = elen;
564 break;
565 case WLAN_EID_PWR_CONSTRAINT:
566 elems->pwr_constr_elem = pos;
567 elems->pwr_constr_elem_len = elen;
568 break;
569 default:
570 break;
571 }
572
573 left -= elen;
574 pos += elen;
575 }
576}
5825fe10
JB
577
578void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
579{
580 struct ieee80211_local *local = sdata->local;
581 struct ieee80211_tx_queue_params qparam;
582 int i;
583
584 if (!local->ops->conf_tx)
585 return;
586
587 memset(&qparam, 0, sizeof(qparam));
588
589 qparam.aifs = 2;
590
591 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
592 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
593 qparam.cw_min = 31;
594 else
595 qparam.cw_min = 15;
596
597 qparam.cw_max = 1023;
598 qparam.txop = 0;
599
600 for (i = 0; i < local_to_hw(local)->queues; i++)
601 local->ops->conf_tx(local_to_hw(local), i, &qparam);
602}
e50db65c
JB
603
604void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
605 int encrypt)
606{
607 skb->dev = sdata->local->mdev;
608 skb_set_mac_header(skb, 0);
609 skb_set_network_header(skb, 0);
610 skb_set_transport_header(skb, 0);
611
612 skb->iif = sdata->dev->ifindex;
613 skb->do_not_encrypt = !encrypt;
614
615 dev_queue_xmit(skb);
616}
e16751c3
JB
617
618int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
619{
620 int ret = -EINVAL;
621 struct ieee80211_channel *chan;
622 struct ieee80211_local *local = sdata->local;
623
624 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
625
626 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
05c914fe 627 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
e16751c3
JB
628 chan->flags & IEEE80211_CHAN_NO_IBSS) {
629 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
630 "%d MHz\n", sdata->dev->name, chan->center_freq);
631 return ret;
632 }
633 local->oper_channel = chan;
634
c2b13452 635 if (local->sw_scanning || local->hw_scanning)
e16751c3
JB
636 ret = 0;
637 else
638 ret = ieee80211_hw_config(local);
639
640 rate_control_clear(local);
641 }
642
643 return ret;
644}
96dd22ac
JB
645
646u64 ieee80211_mandatory_rates(struct ieee80211_local *local,
647 enum ieee80211_band band)
648{
649 struct ieee80211_supported_band *sband;
650 struct ieee80211_rate *bitrates;
651 u64 mandatory_rates;
652 enum ieee80211_rate_flags mandatory_flag;
653 int i;
654
655 sband = local->hw.wiphy->bands[band];
656 if (!sband) {
657 WARN_ON(1);
658 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
659 }
660
661 if (band == IEEE80211_BAND_2GHZ)
662 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
663 else
664 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
665
666 bitrates = sband->bitrates;
667 mandatory_rates = 0;
668 for (i = 0; i < sband->n_bitrates; i++)
669 if (bitrates[i].flags & mandatory_flag)
670 mandatory_rates |= BIT(i);
671 return mandatory_rates;
672}
This page took 0.189219 seconds and 5 git commands to generate.