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>
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.
11 * utilities for mac80211
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>
23 #include <net/net_namespace.h>
24 #include <net/cfg80211.h>
25 #include <net/rtnetlink.h>
27 #include "ieee80211_i.h"
32 /* privid for wiphys to determine whether they belong to us or not */
33 void *mac80211_wiphy_privid
= &mac80211_wiphy_privid
;
35 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
36 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
37 const unsigned char rfc1042_header
[] __aligned(2) =
38 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
40 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
41 const unsigned char bridge_tunnel_header
[] __aligned(2) =
42 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
44 struct ieee80211_hw
*wiphy_to_ieee80211_hw(struct wiphy
*wiphy
)
46 struct ieee80211_local
*local
;
49 local
= wiphy_priv(wiphy
);
52 EXPORT_SYMBOL(wiphy_to_ieee80211_hw
);
54 u8
*ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
,
55 enum nl80211_iftype type
)
57 __le16 fc
= hdr
->frame_control
;
59 /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
63 if (ieee80211_is_data(fc
)) {
64 if (len
< 24) /* drop incorrect hdr len (data) */
67 if (ieee80211_has_a4(fc
))
69 if (ieee80211_has_tods(fc
))
71 if (ieee80211_has_fromds(fc
))
77 if (ieee80211_is_mgmt(fc
)) {
78 if (len
< 24) /* drop incorrect hdr len (mgmt) */
83 if (ieee80211_is_ctl(fc
)) {
84 if(ieee80211_is_pspoll(fc
))
87 if (ieee80211_is_back_req(fc
)) {
89 case NL80211_IFTYPE_STATION
:
91 case NL80211_IFTYPE_AP
:
92 case NL80211_IFTYPE_AP_VLAN
:
95 break; /* fall through to the return */
103 unsigned int ieee80211_hdrlen(__le16 fc
)
105 unsigned int hdrlen
= 24;
107 if (ieee80211_is_data(fc
)) {
108 if (ieee80211_has_a4(fc
))
110 if (ieee80211_is_data_qos(fc
))
111 hdrlen
+= IEEE80211_QOS_CTL_LEN
;
115 if (ieee80211_is_ctl(fc
)) {
117 * ACK and CTS are 10 bytes, all others 16. To see how
118 * to get this condition consider
119 * subtype mask: 0b0000000011110000 (0x00F0)
120 * ACK subtype: 0b0000000011010000 (0x00D0)
121 * CTS subtype: 0b0000000011000000 (0x00C0)
122 * bits that matter: ^^^ (0x00E0)
123 * value of those: 0b0000000011000000 (0x00C0)
125 if ((fc
& cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
133 EXPORT_SYMBOL(ieee80211_hdrlen
);
135 unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff
*skb
)
137 const struct ieee80211_hdr
*hdr
= (const struct ieee80211_hdr
*)skb
->data
;
140 if (unlikely(skb
->len
< 10))
142 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
143 if (unlikely(hdrlen
> skb
->len
))
147 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb
);
149 int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr
*meshhdr
)
151 int ae
= meshhdr
->flags
& IEEE80211S_FLAGS_AE
;
167 void ieee80211_tx_set_protected(struct ieee80211_tx_data
*tx
)
169 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) tx
->skb
->data
;
171 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
172 if (tx
->extra_frag
) {
173 struct ieee80211_hdr
*fhdr
;
175 for (i
= 0; i
< tx
->num_extra_frag
; i
++) {
176 fhdr
= (struct ieee80211_hdr
*)
177 tx
->extra_frag
[i
]->data
;
178 fhdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
183 int ieee80211_frame_duration(struct ieee80211_local
*local
, size_t len
,
184 int rate
, int erp
, int short_preamble
)
188 /* calculate duration (in microseconds, rounded up to next higher
189 * integer if it includes a fractional microsecond) to send frame of
190 * len bytes (does not include FCS) at the given rate. Duration will
193 * rate is in 100 kbps, so divident is multiplied by 10 in the
194 * DIV_ROUND_UP() operations.
197 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_5GHZ
|| erp
) {
201 * N_DBPS = DATARATE x 4
202 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
203 * (16 = SIGNAL time, 6 = tail bits)
204 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
207 * 802.11a - 17.5.2: aSIFSTime = 16 usec
208 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
209 * signal ext = 6 usec
211 dur
= 16; /* SIFS + signal ext */
212 dur
+= 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
213 dur
+= 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
214 dur
+= 4 * DIV_ROUND_UP((16 + 8 * (len
+ 4) + 6) * 10,
215 4 * rate
); /* T_SYM x N_SYM */
218 * 802.11b or 802.11g with 802.11b compatibility:
219 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
220 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
222 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
223 * aSIFSTime = 10 usec
224 * aPreambleLength = 144 usec or 72 usec with short preamble
225 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
227 dur
= 10; /* aSIFSTime = 10 usec */
228 dur
+= short_preamble
? (72 + 24) : (144 + 48);
230 dur
+= DIV_ROUND_UP(8 * (len
+ 4) * 10, rate
);
236 /* Exported duration function for driver use */
237 __le16
ieee80211_generic_frame_duration(struct ieee80211_hw
*hw
,
238 struct ieee80211_vif
*vif
,
240 struct ieee80211_rate
*rate
)
242 struct ieee80211_local
*local
= hw_to_local(hw
);
243 struct ieee80211_sub_if_data
*sdata
;
246 bool short_preamble
= false;
250 sdata
= vif_to_sdata(vif
);
251 short_preamble
= sdata
->vif
.bss_conf
.use_short_preamble
;
252 if (sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
)
253 erp
= rate
->flags
& IEEE80211_RATE_ERP_G
;
256 dur
= ieee80211_frame_duration(local
, frame_len
, rate
->bitrate
, erp
,
259 return cpu_to_le16(dur
);
261 EXPORT_SYMBOL(ieee80211_generic_frame_duration
);
263 __le16
ieee80211_rts_duration(struct ieee80211_hw
*hw
,
264 struct ieee80211_vif
*vif
, size_t frame_len
,
265 const struct ieee80211_tx_info
*frame_txctl
)
267 struct ieee80211_local
*local
= hw_to_local(hw
);
268 struct ieee80211_rate
*rate
;
269 struct ieee80211_sub_if_data
*sdata
;
273 struct ieee80211_supported_band
*sband
;
275 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
277 short_preamble
= false;
279 rate
= &sband
->bitrates
[frame_txctl
->control
.rts_cts_rate_idx
];
283 sdata
= vif_to_sdata(vif
);
284 short_preamble
= sdata
->vif
.bss_conf
.use_short_preamble
;
285 if (sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
)
286 erp
= rate
->flags
& IEEE80211_RATE_ERP_G
;
290 dur
= ieee80211_frame_duration(local
, 10, rate
->bitrate
,
291 erp
, short_preamble
);
292 /* Data frame duration */
293 dur
+= ieee80211_frame_duration(local
, frame_len
, rate
->bitrate
,
294 erp
, short_preamble
);
296 dur
+= ieee80211_frame_duration(local
, 10, rate
->bitrate
,
297 erp
, short_preamble
);
299 return cpu_to_le16(dur
);
301 EXPORT_SYMBOL(ieee80211_rts_duration
);
303 __le16
ieee80211_ctstoself_duration(struct ieee80211_hw
*hw
,
304 struct ieee80211_vif
*vif
,
306 const struct ieee80211_tx_info
*frame_txctl
)
308 struct ieee80211_local
*local
= hw_to_local(hw
);
309 struct ieee80211_rate
*rate
;
310 struct ieee80211_sub_if_data
*sdata
;
314 struct ieee80211_supported_band
*sband
;
316 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
318 short_preamble
= false;
320 rate
= &sband
->bitrates
[frame_txctl
->control
.rts_cts_rate_idx
];
323 sdata
= vif_to_sdata(vif
);
324 short_preamble
= sdata
->vif
.bss_conf
.use_short_preamble
;
325 if (sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
)
326 erp
= rate
->flags
& IEEE80211_RATE_ERP_G
;
329 /* Data frame duration */
330 dur
= ieee80211_frame_duration(local
, frame_len
, rate
->bitrate
,
331 erp
, short_preamble
);
332 if (!(frame_txctl
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
334 dur
+= ieee80211_frame_duration(local
, 10, rate
->bitrate
,
335 erp
, short_preamble
);
338 return cpu_to_le16(dur
);
340 EXPORT_SYMBOL(ieee80211_ctstoself_duration
);
342 static void __ieee80211_wake_queue(struct ieee80211_hw
*hw
, int queue
,
343 enum queue_stop_reason reason
)
345 struct ieee80211_local
*local
= hw_to_local(hw
);
347 if (queue
>= hw
->queues
) {
348 if (local
->ampdu_ac_queue
[queue
- hw
->queues
] < 0)
352 * for virtual aggregation queues, we need to refcount the
353 * internal mac80211 disable (multiple times!), keep track of
354 * driver disable _and_ make sure the regular queue is
357 if (reason
== IEEE80211_QUEUE_STOP_REASON_AGGREGATION
)
358 local
->amdpu_ac_stop_refcnt
[queue
- hw
->queues
]--;
360 __clear_bit(reason
, &local
->queue_stop_reasons
[queue
]);
362 if (local
->queue_stop_reasons
[queue
] ||
363 local
->amdpu_ac_stop_refcnt
[queue
- hw
->queues
])
366 /* now go on to treat the corresponding regular queue */
367 queue
= local
->ampdu_ac_queue
[queue
- hw
->queues
];
368 reason
= IEEE80211_QUEUE_STOP_REASON_AGGREGATION
;
371 __clear_bit(reason
, &local
->queue_stop_reasons
[queue
]);
373 if (local
->queue_stop_reasons
[queue
] != 0)
374 /* someone still has this queue stopped */
377 if (test_bit(queue
, local
->queues_pending
)) {
378 set_bit(queue
, local
->queues_pending_run
);
379 tasklet_schedule(&local
->tx_pending_tasklet
);
381 netif_wake_subqueue(local
->mdev
, queue
);
385 void ieee80211_wake_queue_by_reason(struct ieee80211_hw
*hw
, int queue
,
386 enum queue_stop_reason reason
)
388 struct ieee80211_local
*local
= hw_to_local(hw
);
391 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
392 __ieee80211_wake_queue(hw
, queue
, reason
);
393 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
396 void ieee80211_wake_queue(struct ieee80211_hw
*hw
, int queue
)
398 ieee80211_wake_queue_by_reason(hw
, queue
,
399 IEEE80211_QUEUE_STOP_REASON_DRIVER
);
401 EXPORT_SYMBOL(ieee80211_wake_queue
);
403 static void __ieee80211_stop_queue(struct ieee80211_hw
*hw
, int queue
,
404 enum queue_stop_reason reason
)
406 struct ieee80211_local
*local
= hw_to_local(hw
);
408 if (queue
>= hw
->queues
) {
409 if (local
->ampdu_ac_queue
[queue
- hw
->queues
] < 0)
413 * for virtual aggregation queues, we need to refcount the
414 * internal mac80211 disable (multiple times!), keep track of
415 * driver disable _and_ make sure the regular queue is
418 if (reason
== IEEE80211_QUEUE_STOP_REASON_AGGREGATION
)
419 local
->amdpu_ac_stop_refcnt
[queue
- hw
->queues
]++;
421 __set_bit(reason
, &local
->queue_stop_reasons
[queue
]);
423 /* now go on to treat the corresponding regular queue */
424 queue
= local
->ampdu_ac_queue
[queue
- hw
->queues
];
425 reason
= IEEE80211_QUEUE_STOP_REASON_AGGREGATION
;
428 __set_bit(reason
, &local
->queue_stop_reasons
[queue
]);
430 netif_stop_subqueue(local
->mdev
, queue
);
433 void ieee80211_stop_queue_by_reason(struct ieee80211_hw
*hw
, int queue
,
434 enum queue_stop_reason reason
)
436 struct ieee80211_local
*local
= hw_to_local(hw
);
439 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
440 __ieee80211_stop_queue(hw
, queue
, reason
);
441 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
444 void ieee80211_stop_queue(struct ieee80211_hw
*hw
, int queue
)
446 ieee80211_stop_queue_by_reason(hw
, queue
,
447 IEEE80211_QUEUE_STOP_REASON_DRIVER
);
449 EXPORT_SYMBOL(ieee80211_stop_queue
);
451 void ieee80211_stop_queues_by_reason(struct ieee80211_hw
*hw
,
452 enum queue_stop_reason reason
)
454 struct ieee80211_local
*local
= hw_to_local(hw
);
458 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
460 for (i
= 0; i
< hw
->queues
; i
++)
461 __ieee80211_stop_queue(hw
, i
, reason
);
463 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
466 void ieee80211_stop_queues(struct ieee80211_hw
*hw
)
468 ieee80211_stop_queues_by_reason(hw
,
469 IEEE80211_QUEUE_STOP_REASON_DRIVER
);
471 EXPORT_SYMBOL(ieee80211_stop_queues
);
473 int ieee80211_queue_stopped(struct ieee80211_hw
*hw
, int queue
)
475 struct ieee80211_local
*local
= hw_to_local(hw
);
478 if (queue
>= hw
->queues
) {
479 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
480 queue
= local
->ampdu_ac_queue
[queue
- hw
->queues
];
481 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
486 return __netif_subqueue_stopped(local
->mdev
, queue
);
488 EXPORT_SYMBOL(ieee80211_queue_stopped
);
490 void ieee80211_wake_queues_by_reason(struct ieee80211_hw
*hw
,
491 enum queue_stop_reason reason
)
493 struct ieee80211_local
*local
= hw_to_local(hw
);
497 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
499 for (i
= 0; i
< hw
->queues
+ hw
->ampdu_queues
; i
++)
500 __ieee80211_wake_queue(hw
, i
, reason
);
502 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
505 void ieee80211_wake_queues(struct ieee80211_hw
*hw
)
507 ieee80211_wake_queues_by_reason(hw
, IEEE80211_QUEUE_STOP_REASON_DRIVER
);
509 EXPORT_SYMBOL(ieee80211_wake_queues
);
511 void ieee80211_iterate_active_interfaces(
512 struct ieee80211_hw
*hw
,
513 void (*iterator
)(void *data
, u8
*mac
,
514 struct ieee80211_vif
*vif
),
517 struct ieee80211_local
*local
= hw_to_local(hw
);
518 struct ieee80211_sub_if_data
*sdata
;
520 mutex_lock(&local
->iflist_mtx
);
522 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
523 switch (sdata
->vif
.type
) {
524 case __NL80211_IFTYPE_AFTER_LAST
:
525 case NL80211_IFTYPE_UNSPECIFIED
:
526 case NL80211_IFTYPE_MONITOR
:
527 case NL80211_IFTYPE_AP_VLAN
:
529 case NL80211_IFTYPE_AP
:
530 case NL80211_IFTYPE_STATION
:
531 case NL80211_IFTYPE_ADHOC
:
532 case NL80211_IFTYPE_WDS
:
533 case NL80211_IFTYPE_MESH_POINT
:
536 if (netif_running(sdata
->dev
))
537 iterator(data
, sdata
->dev
->dev_addr
,
541 mutex_unlock(&local
->iflist_mtx
);
543 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces
);
545 void ieee80211_iterate_active_interfaces_atomic(
546 struct ieee80211_hw
*hw
,
547 void (*iterator
)(void *data
, u8
*mac
,
548 struct ieee80211_vif
*vif
),
551 struct ieee80211_local
*local
= hw_to_local(hw
);
552 struct ieee80211_sub_if_data
*sdata
;
556 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
557 switch (sdata
->vif
.type
) {
558 case __NL80211_IFTYPE_AFTER_LAST
:
559 case NL80211_IFTYPE_UNSPECIFIED
:
560 case NL80211_IFTYPE_MONITOR
:
561 case NL80211_IFTYPE_AP_VLAN
:
563 case NL80211_IFTYPE_AP
:
564 case NL80211_IFTYPE_STATION
:
565 case NL80211_IFTYPE_ADHOC
:
566 case NL80211_IFTYPE_WDS
:
567 case NL80211_IFTYPE_MESH_POINT
:
570 if (netif_running(sdata
->dev
))
571 iterator(data
, sdata
->dev
->dev_addr
,
577 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic
);
579 void ieee802_11_parse_elems(u8
*start
, size_t len
,
580 struct ieee802_11_elems
*elems
)
585 memset(elems
, 0, sizeof(*elems
));
586 elems
->ie_start
= start
;
587 elems
->total_len
= len
;
602 elems
->ssid_len
= elen
;
604 case WLAN_EID_SUPP_RATES
:
605 elems
->supp_rates
= pos
;
606 elems
->supp_rates_len
= elen
;
608 case WLAN_EID_FH_PARAMS
:
609 elems
->fh_params
= pos
;
610 elems
->fh_params_len
= elen
;
612 case WLAN_EID_DS_PARAMS
:
613 elems
->ds_params
= pos
;
614 elems
->ds_params_len
= elen
;
616 case WLAN_EID_CF_PARAMS
:
617 elems
->cf_params
= pos
;
618 elems
->cf_params_len
= elen
;
622 elems
->tim_len
= elen
;
624 case WLAN_EID_IBSS_PARAMS
:
625 elems
->ibss_params
= pos
;
626 elems
->ibss_params_len
= elen
;
628 case WLAN_EID_CHALLENGE
:
629 elems
->challenge
= pos
;
630 elems
->challenge_len
= elen
;
633 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
635 /* Microsoft OUI (00:50:F2) */
637 /* OUI Type 1 - WPA IE */
639 elems
->wpa_len
= elen
;
640 } else if (elen
>= 5 && pos
[3] == 2) {
642 elems
->wmm_info
= pos
;
643 elems
->wmm_info_len
= elen
;
644 } else if (pos
[4] == 1) {
645 elems
->wmm_param
= pos
;
646 elems
->wmm_param_len
= elen
;
653 elems
->rsn_len
= elen
;
655 case WLAN_EID_ERP_INFO
:
656 elems
->erp_info
= pos
;
657 elems
->erp_info_len
= elen
;
659 case WLAN_EID_EXT_SUPP_RATES
:
660 elems
->ext_supp_rates
= pos
;
661 elems
->ext_supp_rates_len
= elen
;
663 case WLAN_EID_HT_CAPABILITY
:
664 if (elen
>= sizeof(struct ieee80211_ht_cap
))
665 elems
->ht_cap_elem
= (void *)pos
;
667 case WLAN_EID_HT_INFORMATION
:
668 if (elen
>= sizeof(struct ieee80211_ht_info
))
669 elems
->ht_info_elem
= (void *)pos
;
671 case WLAN_EID_MESH_ID
:
672 elems
->mesh_id
= pos
;
673 elems
->mesh_id_len
= elen
;
675 case WLAN_EID_MESH_CONFIG
:
676 elems
->mesh_config
= pos
;
677 elems
->mesh_config_len
= elen
;
679 case WLAN_EID_PEER_LINK
:
680 elems
->peer_link
= pos
;
681 elems
->peer_link_len
= elen
;
685 elems
->preq_len
= elen
;
689 elems
->prep_len
= elen
;
693 elems
->perr_len
= elen
;
695 case WLAN_EID_CHANNEL_SWITCH
:
696 elems
->ch_switch_elem
= pos
;
697 elems
->ch_switch_elem_len
= elen
;
700 if (!elems
->quiet_elem
) {
701 elems
->quiet_elem
= pos
;
702 elems
->quiet_elem_len
= elen
;
704 elems
->num_of_quiet_elem
++;
706 case WLAN_EID_COUNTRY
:
707 elems
->country_elem
= pos
;
708 elems
->country_elem_len
= elen
;
710 case WLAN_EID_PWR_CONSTRAINT
:
711 elems
->pwr_constr_elem
= pos
;
712 elems
->pwr_constr_elem_len
= elen
;
714 case WLAN_EID_TIMEOUT_INTERVAL
:
715 elems
->timeout_int
= pos
;
716 elems
->timeout_int_len
= elen
;
727 void ieee80211_set_wmm_default(struct ieee80211_sub_if_data
*sdata
)
729 struct ieee80211_local
*local
= sdata
->local
;
730 struct ieee80211_tx_queue_params qparam
;
733 if (!local
->ops
->conf_tx
)
736 memset(&qparam
, 0, sizeof(qparam
));
740 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
741 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
746 qparam
.cw_max
= 1023;
749 for (i
= 0; i
< local_to_hw(local
)->queues
; i
++)
750 local
->ops
->conf_tx(local_to_hw(local
), i
, &qparam
);
753 void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data
*sdata
,
754 const size_t supp_rates_len
,
755 const u8
*supp_rates
)
757 struct ieee80211_local
*local
= sdata
->local
;
758 int i
, have_higher_than_11mbit
= 0;
760 /* cf. IEEE 802.11 9.2.12 */
761 for (i
= 0; i
< supp_rates_len
; i
++)
762 if ((supp_rates
[i
] & 0x7f) * 5 > 110)
763 have_higher_than_11mbit
= 1;
765 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
766 have_higher_than_11mbit
)
767 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
769 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
771 ieee80211_set_wmm_default(sdata
);
774 void ieee80211_tx_skb(struct ieee80211_sub_if_data
*sdata
, struct sk_buff
*skb
,
777 skb
->dev
= sdata
->local
->mdev
;
778 skb_set_mac_header(skb
, 0);
779 skb_set_network_header(skb
, 0);
780 skb_set_transport_header(skb
, 0);
782 skb
->iif
= sdata
->dev
->ifindex
;
783 skb
->do_not_encrypt
= !encrypt
;
788 int ieee80211_set_freq(struct ieee80211_sub_if_data
*sdata
, int freqMHz
)
791 struct ieee80211_channel
*chan
;
792 struct ieee80211_local
*local
= sdata
->local
;
794 chan
= ieee80211_get_channel(local
->hw
.wiphy
, freqMHz
);
796 if (chan
&& !(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
797 if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
&&
798 chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
800 local
->oper_channel
= chan
;
801 local
->oper_channel_type
= NL80211_CHAN_NO_HT
;
803 if (local
->sw_scanning
|| local
->hw_scanning
)
806 ret
= ieee80211_hw_config(
807 local
, IEEE80211_CONF_CHANGE_CHANNEL
);
813 u32
ieee80211_mandatory_rates(struct ieee80211_local
*local
,
814 enum ieee80211_band band
)
816 struct ieee80211_supported_band
*sband
;
817 struct ieee80211_rate
*bitrates
;
819 enum ieee80211_rate_flags mandatory_flag
;
822 sband
= local
->hw
.wiphy
->bands
[band
];
825 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
828 if (band
== IEEE80211_BAND_2GHZ
)
829 mandatory_flag
= IEEE80211_RATE_MANDATORY_B
;
831 mandatory_flag
= IEEE80211_RATE_MANDATORY_A
;
833 bitrates
= sband
->bitrates
;
835 for (i
= 0; i
< sband
->n_bitrates
; i
++)
836 if (bitrates
[i
].flags
& mandatory_flag
)
837 mandatory_rates
|= BIT(i
);
838 return mandatory_rates
;
841 void ieee80211_send_auth(struct ieee80211_sub_if_data
*sdata
,
842 u16 transaction
, u16 auth_alg
,
843 u8
*extra
, size_t extra_len
,
844 const u8
*bssid
, int encrypt
)
846 struct ieee80211_local
*local
= sdata
->local
;
848 struct ieee80211_mgmt
*mgmt
;
849 const u8
*ie_auth
= NULL
;
852 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
853 ie_auth_len
= sdata
->u
.mgd
.ie_auth_len
;
854 ie_auth
= sdata
->u
.mgd
.ie_auth
;
857 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
858 sizeof(*mgmt
) + 6 + extra_len
+ ie_auth_len
);
860 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
861 "frame\n", sdata
->dev
->name
);
864 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
866 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24 + 6);
867 memset(mgmt
, 0, 24 + 6);
868 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
869 IEEE80211_STYPE_AUTH
);
871 mgmt
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
872 memcpy(mgmt
->da
, bssid
, ETH_ALEN
);
873 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
874 memcpy(mgmt
->bssid
, bssid
, ETH_ALEN
);
875 mgmt
->u
.auth
.auth_alg
= cpu_to_le16(auth_alg
);
876 mgmt
->u
.auth
.auth_transaction
= cpu_to_le16(transaction
);
877 mgmt
->u
.auth
.status_code
= cpu_to_le16(0);
879 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
881 memcpy(skb_put(skb
, ie_auth_len
), ie_auth
, ie_auth_len
);
883 ieee80211_tx_skb(sdata
, skb
, encrypt
);
886 void ieee80211_send_probe_req(struct ieee80211_sub_if_data
*sdata
, u8
*dst
,
887 u8
*ssid
, size_t ssid_len
)
889 struct ieee80211_local
*local
= sdata
->local
;
890 struct ieee80211_supported_band
*sband
;
892 struct ieee80211_mgmt
*mgmt
;
893 u8
*pos
, *supp_rates
, *esupp_rates
= NULL
, *extra_preq_ie
= NULL
;
894 int i
, extra_preq_ie_len
= 0;
896 switch (sdata
->vif
.type
) {
897 case NL80211_IFTYPE_STATION
:
898 extra_preq_ie_len
= sdata
->u
.mgd
.ie_probereq_len
;
899 extra_preq_ie
= sdata
->u
.mgd
.ie_probereq
;
905 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200 +
908 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
909 "request\n", sdata
->dev
->name
);
912 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
914 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
916 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
917 IEEE80211_STYPE_PROBE_REQ
);
918 memcpy(mgmt
->sa
, sdata
->dev
->dev_addr
, ETH_ALEN
);
920 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
921 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
923 memset(mgmt
->da
, 0xff, ETH_ALEN
);
924 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
926 pos
= skb_put(skb
, 2 + ssid_len
);
927 *pos
++ = WLAN_EID_SSID
;
929 memcpy(pos
, ssid
, ssid_len
);
931 supp_rates
= skb_put(skb
, 2);
932 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
934 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
936 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
937 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
939 pos
= skb_put(skb
, 1);
941 } else if (supp_rates
[1] == 8) {
942 esupp_rates
= skb_put(skb
, 3);
943 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
945 pos
= &esupp_rates
[2];
947 pos
= skb_put(skb
, 1);
950 *pos
= rate
->bitrate
/ 5;
954 memcpy(skb_put(skb
, extra_preq_ie_len
), extra_preq_ie
,
957 ieee80211_tx_skb(sdata
, skb
, 0);
960 u32
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
961 struct ieee802_11_elems
*elems
,
962 enum ieee80211_band band
)
964 struct ieee80211_supported_band
*sband
;
965 struct ieee80211_rate
*bitrates
;
969 sband
= local
->hw
.wiphy
->bands
[band
];
973 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
976 bitrates
= sband
->bitrates
;
977 num_rates
= sband
->n_bitrates
;
979 for (i
= 0; i
< elems
->supp_rates_len
+
980 elems
->ext_supp_rates_len
; i
++) {
983 if (i
< elems
->supp_rates_len
)
984 rate
= elems
->supp_rates
[i
];
985 else if (elems
->ext_supp_rates
)
986 rate
= elems
->ext_supp_rates
987 [i
- elems
->supp_rates_len
];
988 own_rate
= 5 * (rate
& 0x7f);
989 for (j
= 0; j
< num_rates
; j
++)
990 if (bitrates
[j
].bitrate
== own_rate
)
991 supp_rates
|= BIT(j
);