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"
33 /* privid for wiphys to determine whether they belong to us or not */
34 void *mac80211_wiphy_privid
= &mac80211_wiphy_privid
;
36 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
37 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
38 const unsigned char rfc1042_header
[] __aligned(2) =
39 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
41 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
42 const unsigned char bridge_tunnel_header
[] __aligned(2) =
43 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
45 struct ieee80211_hw
*wiphy_to_ieee80211_hw(struct wiphy
*wiphy
)
47 struct ieee80211_local
*local
;
50 local
= wiphy_priv(wiphy
);
53 EXPORT_SYMBOL(wiphy_to_ieee80211_hw
);
55 u8
*ieee80211_get_bssid(struct ieee80211_hdr
*hdr
, size_t len
,
56 enum nl80211_iftype type
)
58 __le16 fc
= hdr
->frame_control
;
60 /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
64 if (ieee80211_is_data(fc
)) {
65 if (len
< 24) /* drop incorrect hdr len (data) */
68 if (ieee80211_has_a4(fc
))
70 if (ieee80211_has_tods(fc
))
72 if (ieee80211_has_fromds(fc
))
78 if (ieee80211_is_mgmt(fc
)) {
79 if (len
< 24) /* drop incorrect hdr len (mgmt) */
84 if (ieee80211_is_ctl(fc
)) {
85 if(ieee80211_is_pspoll(fc
))
88 if (ieee80211_is_back_req(fc
)) {
90 case NL80211_IFTYPE_STATION
:
92 case NL80211_IFTYPE_AP
:
93 case NL80211_IFTYPE_AP_VLAN
:
96 break; /* fall through to the return */
104 unsigned int ieee80211_hdrlen(__le16 fc
)
106 unsigned int hdrlen
= 24;
108 if (ieee80211_is_data(fc
)) {
109 if (ieee80211_has_a4(fc
))
111 if (ieee80211_is_data_qos(fc
))
112 hdrlen
+= IEEE80211_QOS_CTL_LEN
;
116 if (ieee80211_is_ctl(fc
)) {
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)
126 if ((fc
& cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
134 EXPORT_SYMBOL(ieee80211_hdrlen
);
136 unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff
*skb
)
138 const struct ieee80211_hdr
*hdr
= (const struct ieee80211_hdr
*)skb
->data
;
141 if (unlikely(skb
->len
< 10))
143 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
144 if (unlikely(hdrlen
> skb
->len
))
148 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb
);
150 int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr
*meshhdr
)
152 int ae
= meshhdr
->flags
& IEEE80211S_FLAGS_AE
;
168 void ieee80211_tx_set_protected(struct ieee80211_tx_data
*tx
)
170 struct sk_buff
*skb
= tx
->skb
;
171 struct ieee80211_hdr
*hdr
;
174 hdr
= (struct ieee80211_hdr
*) skb
->data
;
175 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
176 } while ((skb
= skb
->next
));
179 int ieee80211_frame_duration(struct ieee80211_local
*local
, size_t len
,
180 int rate
, int erp
, int short_preamble
)
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
189 * rate is in 100 kbps, so divident is multiplied by 10 in the
190 * DIV_ROUND_UP() operations.
193 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_5GHZ
|| erp
) {
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
203 * 802.11a - 17.5.2: aSIFSTime = 16 usec
204 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
205 * signal ext = 6 usec
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 */
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.
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
223 dur
= 10; /* aSIFSTime = 10 usec */
224 dur
+= short_preamble
? (72 + 24) : (144 + 48);
226 dur
+= DIV_ROUND_UP(8 * (len
+ 4) * 10, rate
);
232 /* Exported duration function for driver use */
233 __le16
ieee80211_generic_frame_duration(struct ieee80211_hw
*hw
,
234 struct ieee80211_vif
*vif
,
236 struct ieee80211_rate
*rate
)
238 struct ieee80211_local
*local
= hw_to_local(hw
);
239 struct ieee80211_sub_if_data
*sdata
;
242 bool short_preamble
= false;
246 sdata
= vif_to_sdata(vif
);
247 short_preamble
= sdata
->vif
.bss_conf
.use_short_preamble
;
248 if (sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
)
249 erp
= rate
->flags
& IEEE80211_RATE_ERP_G
;
252 dur
= ieee80211_frame_duration(local
, frame_len
, rate
->bitrate
, erp
,
255 return cpu_to_le16(dur
);
257 EXPORT_SYMBOL(ieee80211_generic_frame_duration
);
259 __le16
ieee80211_rts_duration(struct ieee80211_hw
*hw
,
260 struct ieee80211_vif
*vif
, size_t frame_len
,
261 const struct ieee80211_tx_info
*frame_txctl
)
263 struct ieee80211_local
*local
= hw_to_local(hw
);
264 struct ieee80211_rate
*rate
;
265 struct ieee80211_sub_if_data
*sdata
;
269 struct ieee80211_supported_band
*sband
;
271 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
273 short_preamble
= false;
275 rate
= &sband
->bitrates
[frame_txctl
->control
.rts_cts_rate_idx
];
279 sdata
= vif_to_sdata(vif
);
280 short_preamble
= sdata
->vif
.bss_conf
.use_short_preamble
;
281 if (sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
)
282 erp
= rate
->flags
& IEEE80211_RATE_ERP_G
;
286 dur
= ieee80211_frame_duration(local
, 10, rate
->bitrate
,
287 erp
, short_preamble
);
288 /* Data frame duration */
289 dur
+= ieee80211_frame_duration(local
, frame_len
, rate
->bitrate
,
290 erp
, short_preamble
);
292 dur
+= ieee80211_frame_duration(local
, 10, rate
->bitrate
,
293 erp
, short_preamble
);
295 return cpu_to_le16(dur
);
297 EXPORT_SYMBOL(ieee80211_rts_duration
);
299 __le16
ieee80211_ctstoself_duration(struct ieee80211_hw
*hw
,
300 struct ieee80211_vif
*vif
,
302 const struct ieee80211_tx_info
*frame_txctl
)
304 struct ieee80211_local
*local
= hw_to_local(hw
);
305 struct ieee80211_rate
*rate
;
306 struct ieee80211_sub_if_data
*sdata
;
310 struct ieee80211_supported_band
*sband
;
312 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
314 short_preamble
= false;
316 rate
= &sband
->bitrates
[frame_txctl
->control
.rts_cts_rate_idx
];
319 sdata
= vif_to_sdata(vif
);
320 short_preamble
= sdata
->vif
.bss_conf
.use_short_preamble
;
321 if (sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
)
322 erp
= rate
->flags
& IEEE80211_RATE_ERP_G
;
325 /* Data frame duration */
326 dur
= ieee80211_frame_duration(local
, frame_len
, rate
->bitrate
,
327 erp
, short_preamble
);
328 if (!(frame_txctl
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
330 dur
+= ieee80211_frame_duration(local
, 10, rate
->bitrate
,
331 erp
, short_preamble
);
334 return cpu_to_le16(dur
);
336 EXPORT_SYMBOL(ieee80211_ctstoself_duration
);
338 static void __ieee80211_wake_queue(struct ieee80211_hw
*hw
, int queue
,
339 enum queue_stop_reason reason
)
341 struct ieee80211_local
*local
= hw_to_local(hw
);
343 if (WARN_ON(queue
>= hw
->queues
))
346 __clear_bit(reason
, &local
->queue_stop_reasons
[queue
]);
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
);
353 if (local
->queue_stop_reasons
[queue
] != 0)
354 /* someone still has this queue stopped */
357 netif_wake_subqueue(local
->mdev
, queue
);
360 void ieee80211_wake_queue_by_reason(struct ieee80211_hw
*hw
, int queue
,
361 enum queue_stop_reason reason
)
363 struct ieee80211_local
*local
= hw_to_local(hw
);
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
);
371 void ieee80211_wake_queue(struct ieee80211_hw
*hw
, int queue
)
373 ieee80211_wake_queue_by_reason(hw
, queue
,
374 IEEE80211_QUEUE_STOP_REASON_DRIVER
);
376 EXPORT_SYMBOL(ieee80211_wake_queue
);
378 static void __ieee80211_stop_queue(struct ieee80211_hw
*hw
, int queue
,
379 enum queue_stop_reason reason
)
381 struct ieee80211_local
*local
= hw_to_local(hw
);
383 if (WARN_ON(queue
>= hw
->queues
))
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.
391 if (!local
->queue_stop_reasons
[queue
])
392 netif_stop_subqueue(local
->mdev
, queue
);
394 __set_bit(reason
, &local
->queue_stop_reasons
[queue
]);
397 void ieee80211_stop_queue_by_reason(struct ieee80211_hw
*hw
, int queue
,
398 enum queue_stop_reason reason
)
400 struct ieee80211_local
*local
= hw_to_local(hw
);
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
);
408 void ieee80211_stop_queue(struct ieee80211_hw
*hw
, int queue
)
410 ieee80211_stop_queue_by_reason(hw
, queue
,
411 IEEE80211_QUEUE_STOP_REASON_DRIVER
);
413 EXPORT_SYMBOL(ieee80211_stop_queue
);
415 void ieee80211_stop_queues_by_reason(struct ieee80211_hw
*hw
,
416 enum queue_stop_reason reason
)
418 struct ieee80211_local
*local
= hw_to_local(hw
);
422 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
424 for (i
= 0; i
< hw
->queues
; i
++)
425 __ieee80211_stop_queue(hw
, i
, reason
);
427 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
430 void ieee80211_stop_queues(struct ieee80211_hw
*hw
)
432 ieee80211_stop_queues_by_reason(hw
,
433 IEEE80211_QUEUE_STOP_REASON_DRIVER
);
435 EXPORT_SYMBOL(ieee80211_stop_queues
);
437 int ieee80211_queue_stopped(struct ieee80211_hw
*hw
, int queue
)
439 struct ieee80211_local
*local
= hw_to_local(hw
);
441 if (WARN_ON(queue
>= hw
->queues
))
444 return __netif_subqueue_stopped(local
->mdev
, queue
);
446 EXPORT_SYMBOL(ieee80211_queue_stopped
);
448 void ieee80211_wake_queues_by_reason(struct ieee80211_hw
*hw
,
449 enum queue_stop_reason reason
)
451 struct ieee80211_local
*local
= hw_to_local(hw
);
455 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
457 for (i
= 0; i
< hw
->queues
; i
++)
458 __ieee80211_wake_queue(hw
, i
, reason
);
460 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
463 void ieee80211_wake_queues(struct ieee80211_hw
*hw
)
465 ieee80211_wake_queues_by_reason(hw
, IEEE80211_QUEUE_STOP_REASON_DRIVER
);
467 EXPORT_SYMBOL(ieee80211_wake_queues
);
469 void ieee80211_iterate_active_interfaces(
470 struct ieee80211_hw
*hw
,
471 void (*iterator
)(void *data
, u8
*mac
,
472 struct ieee80211_vif
*vif
),
475 struct ieee80211_local
*local
= hw_to_local(hw
);
476 struct ieee80211_sub_if_data
*sdata
;
478 mutex_lock(&local
->iflist_mtx
);
480 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
481 switch (sdata
->vif
.type
) {
482 case __NL80211_IFTYPE_AFTER_LAST
:
483 case NL80211_IFTYPE_UNSPECIFIED
:
484 case NL80211_IFTYPE_MONITOR
:
485 case NL80211_IFTYPE_AP_VLAN
:
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
:
494 if (netif_running(sdata
->dev
))
495 iterator(data
, sdata
->dev
->dev_addr
,
499 mutex_unlock(&local
->iflist_mtx
);
501 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces
);
503 void ieee80211_iterate_active_interfaces_atomic(
504 struct ieee80211_hw
*hw
,
505 void (*iterator
)(void *data
, u8
*mac
,
506 struct ieee80211_vif
*vif
),
509 struct ieee80211_local
*local
= hw_to_local(hw
);
510 struct ieee80211_sub_if_data
*sdata
;
514 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
515 switch (sdata
->vif
.type
) {
516 case __NL80211_IFTYPE_AFTER_LAST
:
517 case NL80211_IFTYPE_UNSPECIFIED
:
518 case NL80211_IFTYPE_MONITOR
:
519 case NL80211_IFTYPE_AP_VLAN
:
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
:
528 if (netif_running(sdata
->dev
))
529 iterator(data
, sdata
->dev
->dev_addr
,
535 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic
);
537 void ieee802_11_parse_elems(u8
*start
, size_t len
,
538 struct ieee802_11_elems
*elems
)
543 memset(elems
, 0, sizeof(*elems
));
544 elems
->ie_start
= start
;
545 elems
->total_len
= len
;
560 elems
->ssid_len
= elen
;
562 case WLAN_EID_SUPP_RATES
:
563 elems
->supp_rates
= pos
;
564 elems
->supp_rates_len
= elen
;
566 case WLAN_EID_FH_PARAMS
:
567 elems
->fh_params
= pos
;
568 elems
->fh_params_len
= elen
;
570 case WLAN_EID_DS_PARAMS
:
571 elems
->ds_params
= pos
;
572 elems
->ds_params_len
= elen
;
574 case WLAN_EID_CF_PARAMS
:
575 elems
->cf_params
= pos
;
576 elems
->cf_params_len
= elen
;
580 elems
->tim_len
= elen
;
582 case WLAN_EID_IBSS_PARAMS
:
583 elems
->ibss_params
= pos
;
584 elems
->ibss_params_len
= elen
;
586 case WLAN_EID_CHALLENGE
:
587 elems
->challenge
= pos
;
588 elems
->challenge_len
= elen
;
591 if (elen
>= 4 && pos
[0] == 0x00 && pos
[1] == 0x50 &&
593 /* Microsoft OUI (00:50:F2) */
595 /* OUI Type 1 - WPA IE */
597 elems
->wpa_len
= elen
;
598 } else if (elen
>= 5 && pos
[3] == 2) {
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
;
611 elems
->rsn_len
= elen
;
613 case WLAN_EID_ERP_INFO
:
614 elems
->erp_info
= pos
;
615 elems
->erp_info_len
= elen
;
617 case WLAN_EID_EXT_SUPP_RATES
:
618 elems
->ext_supp_rates
= pos
;
619 elems
->ext_supp_rates_len
= elen
;
621 case WLAN_EID_HT_CAPABILITY
:
622 if (elen
>= sizeof(struct ieee80211_ht_cap
))
623 elems
->ht_cap_elem
= (void *)pos
;
625 case WLAN_EID_HT_INFORMATION
:
626 if (elen
>= sizeof(struct ieee80211_ht_info
))
627 elems
->ht_info_elem
= (void *)pos
;
629 case WLAN_EID_MESH_ID
:
630 elems
->mesh_id
= pos
;
631 elems
->mesh_id_len
= elen
;
633 case WLAN_EID_MESH_CONFIG
:
634 elems
->mesh_config
= pos
;
635 elems
->mesh_config_len
= elen
;
637 case WLAN_EID_PEER_LINK
:
638 elems
->peer_link
= pos
;
639 elems
->peer_link_len
= elen
;
643 elems
->preq_len
= elen
;
647 elems
->prep_len
= elen
;
651 elems
->perr_len
= elen
;
653 case WLAN_EID_CHANNEL_SWITCH
:
654 elems
->ch_switch_elem
= pos
;
655 elems
->ch_switch_elem_len
= elen
;
658 if (!elems
->quiet_elem
) {
659 elems
->quiet_elem
= pos
;
660 elems
->quiet_elem_len
= elen
;
662 elems
->num_of_quiet_elem
++;
664 case WLAN_EID_COUNTRY
:
665 elems
->country_elem
= pos
;
666 elems
->country_elem_len
= elen
;
668 case WLAN_EID_PWR_CONSTRAINT
:
669 elems
->pwr_constr_elem
= pos
;
670 elems
->pwr_constr_elem_len
= elen
;
672 case WLAN_EID_TIMEOUT_INTERVAL
:
673 elems
->timeout_int
= pos
;
674 elems
->timeout_int_len
= elen
;
685 void ieee80211_set_wmm_default(struct ieee80211_sub_if_data
*sdata
)
687 struct ieee80211_local
*local
= sdata
->local
;
688 struct ieee80211_tx_queue_params qparam
;
691 if (!local
->ops
->conf_tx
)
694 memset(&qparam
, 0, sizeof(qparam
));
698 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
699 !(sdata
->flags
& IEEE80211_SDATA_OPERATING_GMODE
))
704 qparam
.cw_max
= 1023;
707 for (i
= 0; i
< local_to_hw(local
)->queues
; i
++)
708 local
->ops
->conf_tx(local_to_hw(local
), i
, &qparam
);
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
)
715 struct ieee80211_local
*local
= sdata
->local
;
716 int i
, have_higher_than_11mbit
= 0;
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;
723 if (local
->hw
.conf
.channel
->band
== IEEE80211_BAND_2GHZ
&&
724 have_higher_than_11mbit
)
725 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
727 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
729 ieee80211_set_wmm_default(sdata
);
732 void ieee80211_tx_skb(struct ieee80211_sub_if_data
*sdata
, struct sk_buff
*skb
,
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);
740 skb
->iif
= sdata
->dev
->ifindex
;
741 skb
->do_not_encrypt
= !encrypt
;
746 int ieee80211_set_freq(struct ieee80211_sub_if_data
*sdata
, int freqMHz
)
749 struct ieee80211_channel
*chan
;
750 struct ieee80211_local
*local
= sdata
->local
;
752 chan
= ieee80211_get_channel(local
->hw
.wiphy
, freqMHz
);
754 if (chan
&& !(chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
755 if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
&&
756 chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
758 local
->oper_channel
= chan
;
759 local
->oper_channel_type
= NL80211_CHAN_NO_HT
;
761 if (local
->sw_scanning
|| local
->hw_scanning
)
764 ret
= ieee80211_hw_config(
765 local
, IEEE80211_CONF_CHANGE_CHANNEL
);
771 u32
ieee80211_mandatory_rates(struct ieee80211_local
*local
,
772 enum ieee80211_band band
)
774 struct ieee80211_supported_band
*sband
;
775 struct ieee80211_rate
*bitrates
;
777 enum ieee80211_rate_flags mandatory_flag
;
780 sband
= local
->hw
.wiphy
->bands
[band
];
783 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
786 if (band
== IEEE80211_BAND_2GHZ
)
787 mandatory_flag
= IEEE80211_RATE_MANDATORY_B
;
789 mandatory_flag
= IEEE80211_RATE_MANDATORY_A
;
791 bitrates
= sband
->bitrates
;
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
;
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
)
804 struct ieee80211_local
*local
= sdata
->local
;
806 struct ieee80211_mgmt
*mgmt
;
808 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
809 sizeof(*mgmt
) + 6 + extra_len
);
811 printk(KERN_DEBUG
"%s: failed to allocate buffer for auth "
812 "frame\n", sdata
->dev
->name
);
815 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
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
);
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);
830 memcpy(skb_put(skb
, extra_len
), extra
, extra_len
);
832 ieee80211_tx_skb(sdata
, skb
, encrypt
);
835 int ieee80211_build_preq_ies(struct ieee80211_local
*local
, u8
*buffer
,
836 const u8
*ie
, size_t ie_len
)
838 struct ieee80211_supported_band
*sband
;
839 u8
*pos
, *supp_rates_len
, *esupp_rates_len
= NULL
;
842 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
846 *pos
++ = WLAN_EID_SUPP_RATES
;
847 supp_rates_len
= pos
;
850 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
851 struct ieee80211_rate
*rate
= &sband
->bitrates
[i
];
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
;
860 *supp_rates_len
+= 1;
862 *pos
++ = rate
->bitrate
/ 5;
865 if (sband
->ht_cap
.ht_supported
) {
866 __le16 tmp
= cpu_to_le16(sband
->ht_cap
.cap
);
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
));
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 */
882 * If adding more here, adjust code in main.c
883 * that calculates local->scan_ies_len.
887 memcpy(pos
, ie
, ie_len
);
894 void ieee80211_send_probe_req(struct ieee80211_sub_if_data
*sdata
, u8
*dst
,
895 const u8
*ssid
, size_t ssid_len
,
896 const u8
*ie
, size_t ie_len
)
898 struct ieee80211_local
*local
= sdata
->local
;
900 struct ieee80211_mgmt
*mgmt
;
903 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
) + 200 +
906 printk(KERN_DEBUG
"%s: failed to allocate buffer for probe "
907 "request\n", sdata
->dev
->name
);
910 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
912 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 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
);
918 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
919 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
921 memset(mgmt
->da
, 0xff, ETH_ALEN
);
922 memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
924 pos
= skb_put(skb
, 2 + ssid_len
);
925 *pos
++ = WLAN_EID_SSID
;
927 memcpy(pos
, ssid
, ssid_len
);
930 skb_put(skb
, ieee80211_build_preq_ies(local
, pos
, ie
, ie_len
));
932 ieee80211_tx_skb(sdata
, skb
, 0);
935 u32
ieee80211_sta_get_rates(struct ieee80211_local
*local
,
936 struct ieee802_11_elems
*elems
,
937 enum ieee80211_band band
)
939 struct ieee80211_supported_band
*sband
;
940 struct ieee80211_rate
*bitrates
;
944 sband
= local
->hw
.wiphy
->bands
[band
];
948 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
951 bitrates
= sband
->bitrates
;
952 num_rates
= sband
->n_bitrates
;
954 for (i
= 0; i
< elems
->supp_rates_len
+
955 elems
->ext_supp_rates_len
; i
++) {
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
);
971 int ieee80211_reconfig(struct ieee80211_local
*local
)
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
;
980 /* restart hardware */
981 if (local
->open_count
) {
982 res
= local
->ops
->start(hw
);
984 ieee80211_led_radio(local
, hw
->conf
.radio_enabled
);
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
);
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
,
1008 local
->ops
->sta_notify(hw
, &sdata
->vif
,
1009 STA_NOTIFY_ADD
, &sta
->sta
);
1011 spin_unlock_irqrestore(&local
->sta_lock
, flags
);
1014 /* Clear Suspend state so that ADDBA requests can be processed */
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
);
1026 /* setup RTS threshold */
1027 if (local
->ops
->set_rts_threshold
)
1028 local
->ops
->set_rts_threshold(hw
, local
->rts_threshold
);
1030 /* reconfigure hardware */
1031 ieee80211_hw_config(local
, ~0);
1033 netif_addr_lock_bh(local
->mdev
);
1034 ieee80211_configure_filter(local
);
1035 netif_addr_unlock_bh(local
->mdev
);
1037 /* Finally also reconfigure all the BSS information */
1038 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1040 if (!netif_running(sdata
->dev
))
1042 switch (sdata
->vif
.type
) {
1043 case NL80211_IFTYPE_STATION
:
1044 /* disable beacon change bits */
1045 changed
&= ~IEEE80211_IFCC_BEACON
;
1047 case NL80211_IFTYPE_ADHOC
:
1048 case NL80211_IFTYPE_AP
:
1049 case NL80211_IFTYPE_MESH_POINT
:
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);
1058 if (ieee80211_if_config(sdata
, changed
))
1059 printk(KERN_DEBUG
"%s: failed to configure interface during resume\n",
1062 ieee80211_bss_info_change_notify(sdata
, ~0);
1064 case NL80211_IFTYPE_WDS
:
1066 case NL80211_IFTYPE_AP_VLAN
:
1067 case NL80211_IFTYPE_MONITOR
:
1068 /* ignore virtual */
1070 case NL80211_IFTYPE_UNSPECIFIED
:
1071 case __NL80211_IFTYPE_AFTER_LAST
:
1078 list_for_each_entry(sdata
, &local
->interfaces
, list
)
1079 if (netif_running(sdata
->dev
))
1080 ieee80211_enable_keys(sdata
);
1082 ieee80211_wake_queues_by_reason(hw
,
1083 IEEE80211_QUEUE_STOP_REASON_SUSPEND
);