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 <linux/crc32.h>
24 #include <net/net_namespace.h>
25 #include <net/cfg80211.h>
26 #include <net/rtnetlink.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
35 /* privid for wiphys to determine whether they belong to us or not */
36 void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
38 struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
40 struct ieee80211_local *local;
43 local = wiphy_priv(wiphy);
46 EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
48 u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
49 enum nl80211_iftype type)
51 __le16 fc = hdr->frame_control;
53 /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
57 if (ieee80211_is_data(fc)) {
58 if (len < 24) /* drop incorrect hdr len (data) */
61 if (ieee80211_has_a4(fc))
63 if (ieee80211_has_tods(fc))
65 if (ieee80211_has_fromds(fc))
71 if (ieee80211_is_mgmt(fc)) {
72 if (len < 24) /* drop incorrect hdr len (mgmt) */
77 if (ieee80211_is_ctl(fc)) {
78 if(ieee80211_is_pspoll(fc))
81 if (ieee80211_is_back_req(fc)) {
83 case NL80211_IFTYPE_STATION:
85 case NL80211_IFTYPE_AP:
86 case NL80211_IFTYPE_AP_VLAN:
89 break; /* fall through to the return */
97 void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
99 struct sk_buff *skb = tx->skb;
100 struct ieee80211_hdr *hdr;
103 hdr = (struct ieee80211_hdr *) skb->data;
104 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
105 } while ((skb = skb->next));
108 int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
109 int rate, int erp, int short_preamble)
113 /* calculate duration (in microseconds, rounded up to next higher
114 * integer if it includes a fractional microsecond) to send frame of
115 * len bytes (does not include FCS) at the given rate. Duration will
118 * rate is in 100 kbps, so divident is multiplied by 10 in the
119 * DIV_ROUND_UP() operations.
122 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
126 * N_DBPS = DATARATE x 4
127 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
128 * (16 = SIGNAL time, 6 = tail bits)
129 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
132 * 802.11a - 17.5.2: aSIFSTime = 16 usec
133 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
134 * signal ext = 6 usec
136 dur = 16; /* SIFS + signal ext */
137 dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
138 dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
139 dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
140 4 * rate); /* T_SYM x N_SYM */
143 * 802.11b or 802.11g with 802.11b compatibility:
144 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
145 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
147 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
148 * aSIFSTime = 10 usec
149 * aPreambleLength = 144 usec or 72 usec with short preamble
150 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
152 dur = 10; /* aSIFSTime = 10 usec */
153 dur += short_preamble ? (72 + 24) : (144 + 48);
155 dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
161 /* Exported duration function for driver use */
162 __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
163 struct ieee80211_vif *vif,
165 struct ieee80211_rate *rate)
167 struct ieee80211_local *local = hw_to_local(hw);
168 struct ieee80211_sub_if_data *sdata;
171 bool short_preamble = false;
175 sdata = vif_to_sdata(vif);
176 short_preamble = sdata->vif.bss_conf.use_short_preamble;
177 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
178 erp = rate->flags & IEEE80211_RATE_ERP_G;
181 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
184 return cpu_to_le16(dur);
186 EXPORT_SYMBOL(ieee80211_generic_frame_duration);
188 __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
189 struct ieee80211_vif *vif, size_t frame_len,
190 const struct ieee80211_tx_info *frame_txctl)
192 struct ieee80211_local *local = hw_to_local(hw);
193 struct ieee80211_rate *rate;
194 struct ieee80211_sub_if_data *sdata;
198 struct ieee80211_supported_band *sband;
200 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
202 short_preamble = false;
204 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
208 sdata = vif_to_sdata(vif);
209 short_preamble = sdata->vif.bss_conf.use_short_preamble;
210 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
211 erp = rate->flags & IEEE80211_RATE_ERP_G;
215 dur = ieee80211_frame_duration(local, 10, rate->bitrate,
216 erp, short_preamble);
217 /* Data frame duration */
218 dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
219 erp, short_preamble);
221 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
222 erp, short_preamble);
224 return cpu_to_le16(dur);
226 EXPORT_SYMBOL(ieee80211_rts_duration);
228 __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
229 struct ieee80211_vif *vif,
231 const struct ieee80211_tx_info *frame_txctl)
233 struct ieee80211_local *local = hw_to_local(hw);
234 struct ieee80211_rate *rate;
235 struct ieee80211_sub_if_data *sdata;
239 struct ieee80211_supported_band *sband;
241 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
243 short_preamble = false;
245 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
248 sdata = vif_to_sdata(vif);
249 short_preamble = sdata->vif.bss_conf.use_short_preamble;
250 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
251 erp = rate->flags & IEEE80211_RATE_ERP_G;
254 /* Data frame duration */
255 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
256 erp, short_preamble);
257 if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
259 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
260 erp, short_preamble);
263 return cpu_to_le16(dur);
265 EXPORT_SYMBOL(ieee80211_ctstoself_duration);
267 static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
268 enum queue_stop_reason reason)
270 struct ieee80211_local *local = hw_to_local(hw);
272 if (WARN_ON(queue >= hw->queues))
275 __clear_bit(reason, &local->queue_stop_reasons[queue]);
277 if (!skb_queue_empty(&local->pending[queue]) &&
278 local->queue_stop_reasons[queue] ==
279 BIT(IEEE80211_QUEUE_STOP_REASON_PENDING))
280 tasklet_schedule(&local->tx_pending_tasklet);
282 if (local->queue_stop_reasons[queue] != 0)
283 /* someone still has this queue stopped */
286 netif_wake_subqueue(local->mdev, queue);
289 void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
290 enum queue_stop_reason reason)
292 struct ieee80211_local *local = hw_to_local(hw);
295 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
296 __ieee80211_wake_queue(hw, queue, reason);
297 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
300 void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
302 ieee80211_wake_queue_by_reason(hw, queue,
303 IEEE80211_QUEUE_STOP_REASON_DRIVER);
305 EXPORT_SYMBOL(ieee80211_wake_queue);
307 static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
308 enum queue_stop_reason reason)
310 struct ieee80211_local *local = hw_to_local(hw);
312 if (WARN_ON(queue >= hw->queues))
316 * Only stop if it was previously running, this is necessary
317 * for correct pending packets handling because there we may
318 * start (but not wake) the queue and rely on that.
320 if (!local->queue_stop_reasons[queue])
321 netif_stop_subqueue(local->mdev, queue);
323 __set_bit(reason, &local->queue_stop_reasons[queue]);
326 void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
327 enum queue_stop_reason reason)
329 struct ieee80211_local *local = hw_to_local(hw);
332 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
333 __ieee80211_stop_queue(hw, queue, reason);
334 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
337 void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
339 ieee80211_stop_queue_by_reason(hw, queue,
340 IEEE80211_QUEUE_STOP_REASON_DRIVER);
342 EXPORT_SYMBOL(ieee80211_stop_queue);
344 void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
345 enum queue_stop_reason reason)
347 struct ieee80211_local *local = hw_to_local(hw);
351 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
353 for (i = 0; i < hw->queues; i++)
354 __ieee80211_stop_queue(hw, i, reason);
356 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
359 void ieee80211_stop_queues(struct ieee80211_hw *hw)
361 ieee80211_stop_queues_by_reason(hw,
362 IEEE80211_QUEUE_STOP_REASON_DRIVER);
364 EXPORT_SYMBOL(ieee80211_stop_queues);
366 int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
368 struct ieee80211_local *local = hw_to_local(hw);
370 if (WARN_ON(queue >= hw->queues))
373 return __netif_subqueue_stopped(local->mdev, queue);
375 EXPORT_SYMBOL(ieee80211_queue_stopped);
377 void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
378 enum queue_stop_reason reason)
380 struct ieee80211_local *local = hw_to_local(hw);
384 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
386 for (i = 0; i < hw->queues; i++)
387 __ieee80211_wake_queue(hw, i, reason);
389 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
392 void ieee80211_wake_queues(struct ieee80211_hw *hw)
394 ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
396 EXPORT_SYMBOL(ieee80211_wake_queues);
398 void ieee80211_iterate_active_interfaces(
399 struct ieee80211_hw *hw,
400 void (*iterator)(void *data, u8 *mac,
401 struct ieee80211_vif *vif),
404 struct ieee80211_local *local = hw_to_local(hw);
405 struct ieee80211_sub_if_data *sdata;
407 mutex_lock(&local->iflist_mtx);
409 list_for_each_entry(sdata, &local->interfaces, list) {
410 switch (sdata->vif.type) {
411 case __NL80211_IFTYPE_AFTER_LAST:
412 case NL80211_IFTYPE_UNSPECIFIED:
413 case NL80211_IFTYPE_MONITOR:
414 case NL80211_IFTYPE_AP_VLAN:
416 case NL80211_IFTYPE_AP:
417 case NL80211_IFTYPE_STATION:
418 case NL80211_IFTYPE_ADHOC:
419 case NL80211_IFTYPE_WDS:
420 case NL80211_IFTYPE_MESH_POINT:
423 if (netif_running(sdata->dev))
424 iterator(data, sdata->dev->dev_addr,
428 mutex_unlock(&local->iflist_mtx);
430 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
432 void ieee80211_iterate_active_interfaces_atomic(
433 struct ieee80211_hw *hw,
434 void (*iterator)(void *data, u8 *mac,
435 struct ieee80211_vif *vif),
438 struct ieee80211_local *local = hw_to_local(hw);
439 struct ieee80211_sub_if_data *sdata;
443 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
444 switch (sdata->vif.type) {
445 case __NL80211_IFTYPE_AFTER_LAST:
446 case NL80211_IFTYPE_UNSPECIFIED:
447 case NL80211_IFTYPE_MONITOR:
448 case NL80211_IFTYPE_AP_VLAN:
450 case NL80211_IFTYPE_AP:
451 case NL80211_IFTYPE_STATION:
452 case NL80211_IFTYPE_ADHOC:
453 case NL80211_IFTYPE_WDS:
454 case NL80211_IFTYPE_MESH_POINT:
457 if (netif_running(sdata->dev))
458 iterator(data, sdata->dev->dev_addr,
464 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
466 void ieee802_11_parse_elems(u8 *start, size_t len,
467 struct ieee802_11_elems *elems)
469 ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
472 u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
473 struct ieee802_11_elems *elems,
478 bool calc_crc = filter != 0;
480 memset(elems, 0, sizeof(*elems));
481 elems->ie_start = start;
482 elems->total_len = len;
494 if (calc_crc && id < 64 && (filter & BIT(id)))
495 crc = crc32_be(crc, pos - 2, elen + 2);
500 elems->ssid_len = elen;
502 case WLAN_EID_SUPP_RATES:
503 elems->supp_rates = pos;
504 elems->supp_rates_len = elen;
506 case WLAN_EID_FH_PARAMS:
507 elems->fh_params = pos;
508 elems->fh_params_len = elen;
510 case WLAN_EID_DS_PARAMS:
511 elems->ds_params = pos;
512 elems->ds_params_len = elen;
514 case WLAN_EID_CF_PARAMS:
515 elems->cf_params = pos;
516 elems->cf_params_len = elen;
519 if (elen >= sizeof(struct ieee80211_tim_ie)) {
520 elems->tim = (void *)pos;
521 elems->tim_len = elen;
524 case WLAN_EID_IBSS_PARAMS:
525 elems->ibss_params = pos;
526 elems->ibss_params_len = elen;
528 case WLAN_EID_CHALLENGE:
529 elems->challenge = pos;
530 elems->challenge_len = elen;
532 case WLAN_EID_VENDOR_SPECIFIC:
533 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
535 /* Microsoft OUI (00:50:F2) */
538 crc = crc32_be(crc, pos - 2, elen + 2);
541 /* OUI Type 1 - WPA IE */
543 elems->wpa_len = elen;
544 } else if (elen >= 5 && pos[3] == 2) {
545 /* OUI Type 2 - WMM IE */
547 elems->wmm_info = pos;
548 elems->wmm_info_len = elen;
549 } else if (pos[4] == 1) {
550 elems->wmm_param = pos;
551 elems->wmm_param_len = elen;
558 elems->rsn_len = elen;
560 case WLAN_EID_ERP_INFO:
561 elems->erp_info = pos;
562 elems->erp_info_len = elen;
564 case WLAN_EID_EXT_SUPP_RATES:
565 elems->ext_supp_rates = pos;
566 elems->ext_supp_rates_len = elen;
568 case WLAN_EID_HT_CAPABILITY:
569 if (elen >= sizeof(struct ieee80211_ht_cap))
570 elems->ht_cap_elem = (void *)pos;
572 case WLAN_EID_HT_INFORMATION:
573 if (elen >= sizeof(struct ieee80211_ht_info))
574 elems->ht_info_elem = (void *)pos;
576 case WLAN_EID_MESH_ID:
577 elems->mesh_id = pos;
578 elems->mesh_id_len = elen;
580 case WLAN_EID_MESH_CONFIG:
581 elems->mesh_config = pos;
582 elems->mesh_config_len = elen;
584 case WLAN_EID_PEER_LINK:
585 elems->peer_link = pos;
586 elems->peer_link_len = elen;
590 elems->preq_len = elen;
594 elems->prep_len = elen;
598 elems->perr_len = elen;
600 case WLAN_EID_CHANNEL_SWITCH:
601 elems->ch_switch_elem = pos;
602 elems->ch_switch_elem_len = elen;
605 if (!elems->quiet_elem) {
606 elems->quiet_elem = pos;
607 elems->quiet_elem_len = elen;
609 elems->num_of_quiet_elem++;
611 case WLAN_EID_COUNTRY:
612 elems->country_elem = pos;
613 elems->country_elem_len = elen;
615 case WLAN_EID_PWR_CONSTRAINT:
616 elems->pwr_constr_elem = pos;
617 elems->pwr_constr_elem_len = elen;
619 case WLAN_EID_TIMEOUT_INTERVAL:
620 elems->timeout_int = pos;
621 elems->timeout_int_len = elen;
634 void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
636 struct ieee80211_local *local = sdata->local;
637 struct ieee80211_tx_queue_params qparam;
642 if (!local->ops->conf_tx)
645 memset(&qparam, 0, sizeof(qparam));
647 use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) &&
648 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
650 for (queue = 0; queue < local_to_hw(local)->queues; queue++) {
651 /* Set defaults according to 802.11-2007 Table 7-37 */
660 qparam.cw_max = aCWmax;
661 qparam.cw_min = aCWmin;
665 default: /* never happens but let's not leave undefined */
667 qparam.cw_max = aCWmax;
668 qparam.cw_min = aCWmin;
673 qparam.cw_max = aCWmin;
674 qparam.cw_min = (aCWmin + 1) / 2 - 1;
676 qparam.txop = 6016/32;
678 qparam.txop = 3008/32;
682 qparam.cw_max = (aCWmin + 1) / 2 - 1;
683 qparam.cw_min = (aCWmin + 1) / 4 - 1;
685 qparam.txop = 3264/32;
687 qparam.txop = 1504/32;
692 drv_conf_tx(local, queue, &qparam);
696 void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
697 const size_t supp_rates_len,
698 const u8 *supp_rates)
700 struct ieee80211_local *local = sdata->local;
701 int i, have_higher_than_11mbit = 0;
703 /* cf. IEEE 802.11 9.2.12 */
704 for (i = 0; i < supp_rates_len; i++)
705 if ((supp_rates[i] & 0x7f) * 5 > 110)
706 have_higher_than_11mbit = 1;
708 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
709 have_higher_than_11mbit)
710 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
712 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
714 ieee80211_set_wmm_default(sdata);
717 void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
720 skb->dev = sdata->local->mdev;
721 skb_set_mac_header(skb, 0);
722 skb_set_network_header(skb, 0);
723 skb_set_transport_header(skb, 0);
725 skb->iif = sdata->dev->ifindex;
726 skb->do_not_encrypt = !encrypt;
731 int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
734 struct ieee80211_channel *chan;
735 struct ieee80211_local *local = sdata->local;
737 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
739 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
740 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
741 chan->flags & IEEE80211_CHAN_NO_IBSS)
743 local->oper_channel = chan;
744 local->oper_channel_type = NL80211_CHAN_NO_HT;
746 if (local->sw_scanning || local->hw_scanning)
749 ret = ieee80211_hw_config(
750 local, IEEE80211_CONF_CHANGE_CHANNEL);
756 u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
757 enum ieee80211_band band)
759 struct ieee80211_supported_band *sband;
760 struct ieee80211_rate *bitrates;
762 enum ieee80211_rate_flags mandatory_flag;
765 sband = local->hw.wiphy->bands[band];
768 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
771 if (band == IEEE80211_BAND_2GHZ)
772 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
774 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
776 bitrates = sband->bitrates;
778 for (i = 0; i < sband->n_bitrates; i++)
779 if (bitrates[i].flags & mandatory_flag)
780 mandatory_rates |= BIT(i);
781 return mandatory_rates;
784 void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
785 u16 transaction, u16 auth_alg,
786 u8 *extra, size_t extra_len,
787 const u8 *bssid, int encrypt)
789 struct ieee80211_local *local = sdata->local;
791 struct ieee80211_mgmt *mgmt;
793 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
794 sizeof(*mgmt) + 6 + extra_len);
796 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
797 "frame\n", sdata->dev->name);
800 skb_reserve(skb, local->hw.extra_tx_headroom);
802 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
803 memset(mgmt, 0, 24 + 6);
804 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
805 IEEE80211_STYPE_AUTH);
807 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
808 memcpy(mgmt->da, bssid, ETH_ALEN);
809 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
810 memcpy(mgmt->bssid, bssid, ETH_ALEN);
811 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
812 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
813 mgmt->u.auth.status_code = cpu_to_le16(0);
815 memcpy(skb_put(skb, extra_len), extra, extra_len);
817 ieee80211_tx_skb(sdata, skb, encrypt);
820 int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
821 const u8 *ie, size_t ie_len)
823 struct ieee80211_supported_band *sband;
824 u8 *pos, *supp_rates_len, *esupp_rates_len = NULL;
827 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
831 *pos++ = WLAN_EID_SUPP_RATES;
832 supp_rates_len = pos;
835 for (i = 0; i < sband->n_bitrates; i++) {
836 struct ieee80211_rate *rate = &sband->bitrates[i];
838 if (esupp_rates_len) {
839 *esupp_rates_len += 1;
840 } else if (*supp_rates_len == 8) {
841 *pos++ = WLAN_EID_EXT_SUPP_RATES;
842 esupp_rates_len = pos;
845 *supp_rates_len += 1;
847 *pos++ = rate->bitrate / 5;
850 if (sband->ht_cap.ht_supported) {
851 __le16 tmp = cpu_to_le16(sband->ht_cap.cap);
853 *pos++ = WLAN_EID_HT_CAPABILITY;
854 *pos++ = sizeof(struct ieee80211_ht_cap);
855 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
856 memcpy(pos, &tmp, sizeof(u16));
858 /* TODO: needs a define here for << 2 */
859 *pos++ = sband->ht_cap.ampdu_factor |
860 (sband->ht_cap.ampdu_density << 2);
861 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
862 pos += sizeof(sband->ht_cap.mcs);
863 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
867 * If adding more here, adjust code in main.c
868 * that calculates local->scan_ies_len.
872 memcpy(pos, ie, ie_len);
879 void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
880 const u8 *ssid, size_t ssid_len,
881 const u8 *ie, size_t ie_len)
883 struct ieee80211_local *local = sdata->local;
885 struct ieee80211_mgmt *mgmt;
888 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 +
891 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
892 "request\n", sdata->dev->name);
895 skb_reserve(skb, local->hw.extra_tx_headroom);
897 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
899 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
900 IEEE80211_STYPE_PROBE_REQ);
901 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
903 memcpy(mgmt->da, dst, ETH_ALEN);
904 memcpy(mgmt->bssid, dst, ETH_ALEN);
906 memset(mgmt->da, 0xff, ETH_ALEN);
907 memset(mgmt->bssid, 0xff, ETH_ALEN);
909 pos = skb_put(skb, 2 + ssid_len);
910 *pos++ = WLAN_EID_SSID;
912 memcpy(pos, ssid, ssid_len);
915 skb_put(skb, ieee80211_build_preq_ies(local, pos, ie, ie_len));
917 ieee80211_tx_skb(sdata, skb, 0);
920 u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
921 struct ieee802_11_elems *elems,
922 enum ieee80211_band band)
924 struct ieee80211_supported_band *sband;
925 struct ieee80211_rate *bitrates;
929 sband = local->hw.wiphy->bands[band];
933 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
936 bitrates = sband->bitrates;
937 num_rates = sband->n_bitrates;
939 for (i = 0; i < elems->supp_rates_len +
940 elems->ext_supp_rates_len; i++) {
943 if (i < elems->supp_rates_len)
944 rate = elems->supp_rates[i];
945 else if (elems->ext_supp_rates)
946 rate = elems->ext_supp_rates
947 [i - elems->supp_rates_len];
948 own_rate = 5 * (rate & 0x7f);
949 for (j = 0; j < num_rates; j++)
950 if (bitrates[j].bitrate == own_rate)
951 supp_rates |= BIT(j);
956 int ieee80211_reconfig(struct ieee80211_local *local)
958 struct ieee80211_hw *hw = &local->hw;
959 struct ieee80211_sub_if_data *sdata;
960 struct ieee80211_if_init_conf conf;
961 struct sta_info *sta;
964 bool from_suspend = local->suspended;
967 * We're going to start the hardware, at that point
968 * we are no longer suspended and can RX frames.
970 local->suspended = false;
972 /* restart hardware */
973 if (local->open_count) {
974 res = drv_start(local);
976 ieee80211_led_radio(local, hw->conf.radio_enabled);
980 list_for_each_entry(sdata, &local->interfaces, list) {
981 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
982 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
983 netif_running(sdata->dev)) {
984 conf.vif = &sdata->vif;
985 conf.type = sdata->vif.type;
986 conf.mac_addr = sdata->dev->dev_addr;
987 res = drv_add_interface(local, &conf);
992 if (local->ops->sta_notify) {
993 spin_lock_irqsave(&local->sta_lock, flags);
994 list_for_each_entry(sta, &local->sta_list, list) {
996 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
997 sdata = container_of(sdata->bss,
998 struct ieee80211_sub_if_data,
1001 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD,
1004 spin_unlock_irqrestore(&local->sta_lock, flags);
1007 /* Clear Suspend state so that ADDBA requests can be processed */
1011 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
1012 list_for_each_entry_rcu(sta, &local->sta_list, list) {
1013 clear_sta_flags(sta, WLAN_STA_SUSPEND);
1019 /* setup RTS threshold */
1020 drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
1022 /* reconfigure hardware */
1023 ieee80211_hw_config(local, ~0);
1025 netif_addr_lock_bh(local->mdev);
1026 ieee80211_configure_filter(local);
1027 netif_addr_unlock_bh(local->mdev);
1029 /* Finally also reconfigure all the BSS information */
1030 list_for_each_entry(sdata, &local->interfaces, list) {
1032 if (!netif_running(sdata->dev))
1034 switch (sdata->vif.type) {
1035 case NL80211_IFTYPE_STATION:
1036 /* disable beacon change bits */
1037 changed &= ~(BSS_CHANGED_BEACON |
1038 BSS_CHANGED_BEACON_ENABLED);
1040 case NL80211_IFTYPE_ADHOC:
1041 case NL80211_IFTYPE_AP:
1042 case NL80211_IFTYPE_MESH_POINT:
1043 ieee80211_bss_info_change_notify(sdata, changed);
1045 case NL80211_IFTYPE_WDS:
1047 case NL80211_IFTYPE_AP_VLAN:
1048 case NL80211_IFTYPE_MONITOR:
1049 /* ignore virtual */
1051 case NL80211_IFTYPE_UNSPECIFIED:
1052 case __NL80211_IFTYPE_AFTER_LAST:
1059 list_for_each_entry(sdata, &local->interfaces, list)
1060 if (netif_running(sdata->dev))
1061 ieee80211_enable_keys(sdata);
1063 ieee80211_wake_queues_by_reason(hw,
1064 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
1067 * If this is for hw restart things are still running.
1068 * We may want to change that later, however.
1074 local->suspended = false;
1076 list_for_each_entry(sdata, &local->interfaces, list) {
1077 switch(sdata->vif.type) {
1078 case NL80211_IFTYPE_STATION:
1079 ieee80211_sta_restart(sdata);
1081 case NL80211_IFTYPE_ADHOC:
1082 ieee80211_ibss_restart(sdata);
1084 case NL80211_IFTYPE_MESH_POINT:
1085 ieee80211_mesh_restart(sdata);
1092 add_timer(&local->sta_cleanup);
1094 spin_lock_irqsave(&local->sta_lock, flags);
1095 list_for_each_entry(sta, &local->sta_list, list)
1096 mesh_plink_restart(sta);
1097 spin_unlock_irqrestore(&local->sta_lock, flags);