2 * Wireless utility functions
4 * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
6 #include <linux/bitops.h>
7 #include <linux/etherdevice.h>
8 #include <linux/slab.h>
9 #include <net/cfg80211.h>
13 struct ieee80211_rate *
14 ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
15 u32 basic_rates, int bitrate)
17 struct ieee80211_rate *result = &sband->bitrates[0];
20 for (i = 0; i < sband->n_bitrates; i++) {
21 if (!(basic_rates & BIT(i)))
23 if (sband->bitrates[i].bitrate > bitrate)
25 result = &sband->bitrates[i];
30 EXPORT_SYMBOL(ieee80211_get_response_rate);
32 int ieee80211_channel_to_frequency(int chan)
35 return 2407 + chan * 5;
40 /* FIXME: 802.11j 17.3.8.3.2 */
41 return (chan + 1000) * 5;
43 EXPORT_SYMBOL(ieee80211_channel_to_frequency);
45 int ieee80211_frequency_to_channel(int freq)
51 return (freq - 2407) / 5;
53 /* FIXME: 802.11j 17.3.8.3.2 */
56 EXPORT_SYMBOL(ieee80211_frequency_to_channel);
58 struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
61 enum ieee80211_band band;
62 struct ieee80211_supported_band *sband;
65 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
66 sband = wiphy->bands[band];
71 for (i = 0; i < sband->n_channels; i++) {
72 if (sband->channels[i].center_freq == freq)
73 return &sband->channels[i];
79 EXPORT_SYMBOL(__ieee80211_get_channel);
81 static void set_mandatory_flags_band(struct ieee80211_supported_band *sband,
82 enum ieee80211_band band)
87 case IEEE80211_BAND_5GHZ:
89 for (i = 0; i < sband->n_bitrates; i++) {
90 if (sband->bitrates[i].bitrate == 60 ||
91 sband->bitrates[i].bitrate == 120 ||
92 sband->bitrates[i].bitrate == 240) {
93 sband->bitrates[i].flags |=
94 IEEE80211_RATE_MANDATORY_A;
100 case IEEE80211_BAND_2GHZ:
102 for (i = 0; i < sband->n_bitrates; i++) {
103 if (sband->bitrates[i].bitrate == 10) {
104 sband->bitrates[i].flags |=
105 IEEE80211_RATE_MANDATORY_B |
106 IEEE80211_RATE_MANDATORY_G;
110 if (sband->bitrates[i].bitrate == 20 ||
111 sband->bitrates[i].bitrate == 55 ||
112 sband->bitrates[i].bitrate == 110 ||
113 sband->bitrates[i].bitrate == 60 ||
114 sband->bitrates[i].bitrate == 120 ||
115 sband->bitrates[i].bitrate == 240) {
116 sband->bitrates[i].flags |=
117 IEEE80211_RATE_MANDATORY_G;
121 if (sband->bitrates[i].bitrate != 10 &&
122 sband->bitrates[i].bitrate != 20 &&
123 sband->bitrates[i].bitrate != 55 &&
124 sband->bitrates[i].bitrate != 110)
125 sband->bitrates[i].flags |=
126 IEEE80211_RATE_ERP_G;
128 WARN_ON(want != 0 && want != 3 && want != 6);
130 case IEEE80211_NUM_BANDS:
136 void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
138 enum ieee80211_band band;
140 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
141 if (wiphy->bands[band])
142 set_mandatory_flags_band(wiphy->bands[band], band);
145 int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
146 struct key_params *params, int key_idx,
155 * Disallow pairwise keys with non-zero index unless it's WEP
156 * (because current deployments use pairwise WEP keys with
157 * non-zero indizes but 802.11i clearly specifies to use zero)
159 if (mac_addr && key_idx &&
160 params->cipher != WLAN_CIPHER_SUITE_WEP40 &&
161 params->cipher != WLAN_CIPHER_SUITE_WEP104)
164 switch (params->cipher) {
165 case WLAN_CIPHER_SUITE_WEP40:
166 if (params->key_len != WLAN_KEY_LEN_WEP40)
169 case WLAN_CIPHER_SUITE_TKIP:
170 if (params->key_len != WLAN_KEY_LEN_TKIP)
173 case WLAN_CIPHER_SUITE_CCMP:
174 if (params->key_len != WLAN_KEY_LEN_CCMP)
177 case WLAN_CIPHER_SUITE_WEP104:
178 if (params->key_len != WLAN_KEY_LEN_WEP104)
181 case WLAN_CIPHER_SUITE_AES_CMAC:
182 if (params->key_len != WLAN_KEY_LEN_AES_CMAC)
187 * We don't know anything about this algorithm,
188 * allow using it -- but the driver must check
189 * all parameters! We still check below whether
190 * or not the driver supports this algorithm,
197 switch (params->cipher) {
198 case WLAN_CIPHER_SUITE_WEP40:
199 case WLAN_CIPHER_SUITE_WEP104:
200 /* These ciphers do not use key sequence */
202 case WLAN_CIPHER_SUITE_TKIP:
203 case WLAN_CIPHER_SUITE_CCMP:
204 case WLAN_CIPHER_SUITE_AES_CMAC:
205 if (params->seq_len != 6)
211 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++)
212 if (params->cipher == rdev->wiphy.cipher_suites[i])
214 if (i == rdev->wiphy.n_cipher_suites)
220 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
221 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
222 const unsigned char rfc1042_header[] __aligned(2) =
223 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
224 EXPORT_SYMBOL(rfc1042_header);
226 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
227 const unsigned char bridge_tunnel_header[] __aligned(2) =
228 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
229 EXPORT_SYMBOL(bridge_tunnel_header);
231 unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc)
233 unsigned int hdrlen = 24;
235 if (ieee80211_is_data(fc)) {
236 if (ieee80211_has_a4(fc))
238 if (ieee80211_is_data_qos(fc)) {
239 hdrlen += IEEE80211_QOS_CTL_LEN;
240 if (ieee80211_has_order(fc))
241 hdrlen += IEEE80211_HT_CTL_LEN;
246 if (ieee80211_is_ctl(fc)) {
248 * ACK and CTS are 10 bytes, all others 16. To see how
249 * to get this condition consider
250 * subtype mask: 0b0000000011110000 (0x00F0)
251 * ACK subtype: 0b0000000011010000 (0x00D0)
252 * CTS subtype: 0b0000000011000000 (0x00C0)
253 * bits that matter: ^^^ (0x00E0)
254 * value of those: 0b0000000011000000 (0x00C0)
256 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
264 EXPORT_SYMBOL(ieee80211_hdrlen);
266 unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
268 const struct ieee80211_hdr *hdr =
269 (const struct ieee80211_hdr *)skb->data;
272 if (unlikely(skb->len < 10))
274 hdrlen = ieee80211_hdrlen(hdr->frame_control);
275 if (unlikely(hdrlen > skb->len))
279 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
281 static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
283 int ae = meshhdr->flags & MESH_FLAGS_AE;
288 case MESH_FLAGS_AE_A4:
290 case MESH_FLAGS_AE_A5_A6:
292 case (MESH_FLAGS_AE_A4 | MESH_FLAGS_AE_A5_A6):
299 int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
300 enum nl80211_iftype iftype)
302 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
303 u16 hdrlen, ethertype;
306 u8 src[ETH_ALEN] __aligned(2);
308 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
311 hdrlen = ieee80211_hdrlen(hdr->frame_control);
313 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
315 * IEEE 802.11 address fields:
316 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
317 * 0 0 DA SA BSSID n/a
318 * 0 1 DA BSSID SA n/a
319 * 1 0 BSSID SA DA n/a
322 memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
323 memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
325 switch (hdr->frame_control &
326 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
327 case cpu_to_le16(IEEE80211_FCTL_TODS):
328 if (unlikely(iftype != NL80211_IFTYPE_AP &&
329 iftype != NL80211_IFTYPE_AP_VLAN))
332 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
333 if (unlikely(iftype != NL80211_IFTYPE_WDS &&
334 iftype != NL80211_IFTYPE_MESH_POINT &&
335 iftype != NL80211_IFTYPE_AP_VLAN &&
336 iftype != NL80211_IFTYPE_STATION))
338 if (iftype == NL80211_IFTYPE_MESH_POINT) {
339 struct ieee80211s_hdr *meshdr =
340 (struct ieee80211s_hdr *) (skb->data + hdrlen);
341 /* make sure meshdr->flags is on the linear part */
342 if (!pskb_may_pull(skb, hdrlen + 1))
344 if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
345 skb_copy_bits(skb, hdrlen +
346 offsetof(struct ieee80211s_hdr, eaddr1),
348 skb_copy_bits(skb, hdrlen +
349 offsetof(struct ieee80211s_hdr, eaddr2),
352 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
355 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
356 if ((iftype != NL80211_IFTYPE_STATION &&
357 iftype != NL80211_IFTYPE_MESH_POINT) ||
358 (is_multicast_ether_addr(dst) &&
359 !compare_ether_addr(src, addr)))
361 if (iftype == NL80211_IFTYPE_MESH_POINT) {
362 struct ieee80211s_hdr *meshdr =
363 (struct ieee80211s_hdr *) (skb->data + hdrlen);
364 /* make sure meshdr->flags is on the linear part */
365 if (!pskb_may_pull(skb, hdrlen + 1))
367 if (meshdr->flags & MESH_FLAGS_AE_A4)
368 skb_copy_bits(skb, hdrlen +
369 offsetof(struct ieee80211s_hdr, eaddr1),
371 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
375 if (iftype != NL80211_IFTYPE_ADHOC)
380 if (!pskb_may_pull(skb, hdrlen + 8))
383 payload = skb->data + hdrlen;
384 ethertype = (payload[6] << 8) | payload[7];
386 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
387 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
388 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
389 /* remove RFC1042 or Bridge-Tunnel encapsulation and
390 * replace EtherType */
391 skb_pull(skb, hdrlen + 6);
392 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
393 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
398 skb_pull(skb, hdrlen);
399 len = htons(skb->len);
400 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
401 memcpy(ehdr->h_dest, dst, ETH_ALEN);
402 memcpy(ehdr->h_source, src, ETH_ALEN);
407 EXPORT_SYMBOL(ieee80211_data_to_8023);
409 int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
410 enum nl80211_iftype iftype, u8 *bssid, bool qos)
412 struct ieee80211_hdr hdr;
413 u16 hdrlen, ethertype;
415 const u8 *encaps_data;
416 int encaps_len, skip_header_bytes;
420 if (unlikely(skb->len < ETH_HLEN))
423 nh_pos = skb_network_header(skb) - skb->data;
424 h_pos = skb_transport_header(skb) - skb->data;
426 /* convert Ethernet header to proper 802.11 header (based on
428 ethertype = (skb->data[12] << 8) | skb->data[13];
429 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
432 case NL80211_IFTYPE_AP:
433 case NL80211_IFTYPE_AP_VLAN:
434 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
436 memcpy(hdr.addr1, skb->data, ETH_ALEN);
437 memcpy(hdr.addr2, addr, ETH_ALEN);
438 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
441 case NL80211_IFTYPE_STATION:
442 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
444 memcpy(hdr.addr1, bssid, ETH_ALEN);
445 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
446 memcpy(hdr.addr3, skb->data, ETH_ALEN);
449 case NL80211_IFTYPE_ADHOC:
451 memcpy(hdr.addr1, skb->data, ETH_ALEN);
452 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
453 memcpy(hdr.addr3, bssid, ETH_ALEN);
461 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
465 hdr.frame_control = fc;
469 skip_header_bytes = ETH_HLEN;
470 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
471 encaps_data = bridge_tunnel_header;
472 encaps_len = sizeof(bridge_tunnel_header);
473 skip_header_bytes -= 2;
474 } else if (ethertype > 0x600) {
475 encaps_data = rfc1042_header;
476 encaps_len = sizeof(rfc1042_header);
477 skip_header_bytes -= 2;
483 skb_pull(skb, skip_header_bytes);
484 nh_pos -= skip_header_bytes;
485 h_pos -= skip_header_bytes;
487 head_need = hdrlen + encaps_len - skb_headroom(skb);
489 if (head_need > 0 || skb_cloned(skb)) {
490 head_need = max(head_need, 0);
494 if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) {
495 printk(KERN_ERR "failed to reallocate Tx buffer\n");
498 skb->truesize += head_need;
502 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
503 nh_pos += encaps_len;
507 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
512 /* Update skb pointers to various headers since this modified frame
513 * is going to go through Linux networking code that may potentially
514 * need things like pointer to IP header. */
515 skb_set_mac_header(skb, 0);
516 skb_set_network_header(skb, nh_pos);
517 skb_set_transport_header(skb, h_pos);
521 EXPORT_SYMBOL(ieee80211_data_from_8023);
524 void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
525 const u8 *addr, enum nl80211_iftype iftype,
526 const unsigned int extra_headroom)
528 struct sk_buff *frame = NULL;
531 const struct ethhdr *eth;
533 u8 dst[ETH_ALEN], src[ETH_ALEN];
535 err = ieee80211_data_to_8023(skb, addr, iftype);
539 /* skip the wrapping header */
540 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
544 while (skb != frame) {
546 __be16 len = eth->h_proto;
547 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
549 remaining = skb->len;
550 memcpy(dst, eth->h_dest, ETH_ALEN);
551 memcpy(src, eth->h_source, ETH_ALEN);
553 padding = (4 - subframe_len) & 0x3;
554 /* the last MSDU has no padding */
555 if (subframe_len > remaining)
558 skb_pull(skb, sizeof(struct ethhdr));
559 /* reuse skb for the last subframe */
560 if (remaining <= subframe_len + padding)
563 unsigned int hlen = ALIGN(extra_headroom, 4);
565 * Allocate and reserve two bytes more for payload
566 * alignment since sizeof(struct ethhdr) is 14.
568 frame = dev_alloc_skb(hlen + subframe_len + 2);
572 skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
573 memcpy(skb_put(frame, ntohs(len)), skb->data,
576 eth = (struct ethhdr *)skb_pull(skb, ntohs(len) +
579 dev_kfree_skb(frame);
584 skb_reset_network_header(frame);
585 frame->dev = skb->dev;
586 frame->priority = skb->priority;
588 payload = frame->data;
589 ethertype = (payload[6] << 8) | payload[7];
591 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
592 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
593 compare_ether_addr(payload,
594 bridge_tunnel_header) == 0)) {
595 /* remove RFC1042 or Bridge-Tunnel
596 * encapsulation and replace EtherType */
598 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
599 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
601 memcpy(skb_push(frame, sizeof(__be16)), &len,
603 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
604 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
606 __skb_queue_tail(list, frame);
612 __skb_queue_purge(list);
616 EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
618 /* Given a data frame determine the 802.1p/1d tag to use. */
619 unsigned int cfg80211_classify8021d(struct sk_buff *skb)
623 /* skb->priority values from 256->263 are magic values to
624 * directly indicate a specific 802.1d priority. This is used
625 * to allow 802.1d priority to be passed directly in from VLAN
628 if (skb->priority >= 256 && skb->priority <= 263)
629 return skb->priority - 256;
631 switch (skb->protocol) {
632 case htons(ETH_P_IP):
633 dscp = ip_hdr(skb)->tos & 0xfc;
641 EXPORT_SYMBOL(cfg80211_classify8021d);
643 const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
647 pos = bss->information_elements;
650 end = pos + bss->len_information_elements;
652 while (pos + 1 < end) {
653 if (pos + 2 + pos[1] > end)
662 EXPORT_SYMBOL(ieee80211_bss_get_ie);
664 void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
666 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
667 struct net_device *dev = wdev->netdev;
670 if (!wdev->connect_keys)
673 for (i = 0; i < 6; i++) {
674 if (!wdev->connect_keys->params[i].cipher)
676 if (rdev->ops->add_key(wdev->wiphy, dev, i, NULL,
677 &wdev->connect_keys->params[i])) {
678 printk(KERN_ERR "%s: failed to set key %d\n",
682 if (wdev->connect_keys->def == i)
683 if (rdev->ops->set_default_key(wdev->wiphy, dev, i)) {
684 printk(KERN_ERR "%s: failed to set defkey %d\n",
688 if (wdev->connect_keys->defmgmt == i)
689 if (rdev->ops->set_default_mgmt_key(wdev->wiphy, dev, i))
690 printk(KERN_ERR "%s: failed to set mgtdef %d\n",
694 kfree(wdev->connect_keys);
695 wdev->connect_keys = NULL;
698 static void cfg80211_process_wdev_events(struct wireless_dev *wdev)
700 struct cfg80211_event *ev;
702 const u8 *bssid = NULL;
704 spin_lock_irqsave(&wdev->event_lock, flags);
705 while (!list_empty(&wdev->event_list)) {
706 ev = list_first_entry(&wdev->event_list,
707 struct cfg80211_event, list);
709 spin_unlock_irqrestore(&wdev->event_lock, flags);
713 case EVENT_CONNECT_RESULT:
714 if (!is_zero_ether_addr(ev->cr.bssid))
715 bssid = ev->cr.bssid;
716 __cfg80211_connect_result(
718 ev->cr.req_ie, ev->cr.req_ie_len,
719 ev->cr.resp_ie, ev->cr.resp_ie_len,
721 ev->cr.status == WLAN_STATUS_SUCCESS,
725 __cfg80211_roamed(wdev, ev->rm.bssid,
726 ev->rm.req_ie, ev->rm.req_ie_len,
727 ev->rm.resp_ie, ev->rm.resp_ie_len);
729 case EVENT_DISCONNECTED:
730 __cfg80211_disconnected(wdev->netdev,
731 ev->dc.ie, ev->dc.ie_len,
732 ev->dc.reason, true);
734 case EVENT_IBSS_JOINED:
735 __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
742 spin_lock_irqsave(&wdev->event_lock, flags);
744 spin_unlock_irqrestore(&wdev->event_lock, flags);
747 void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
749 struct wireless_dev *wdev;
752 ASSERT_RDEV_LOCK(rdev);
754 mutex_lock(&rdev->devlist_mtx);
756 list_for_each_entry(wdev, &rdev->netdev_list, list)
757 cfg80211_process_wdev_events(wdev);
759 mutex_unlock(&rdev->devlist_mtx);
762 int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
763 struct net_device *dev, enum nl80211_iftype ntype,
764 u32 *flags, struct vif_params *params)
767 enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
769 ASSERT_RDEV_LOCK(rdev);
771 /* don't support changing VLANs, you just re-create them */
772 if (otype == NL80211_IFTYPE_AP_VLAN)
775 if (!rdev->ops->change_virtual_intf ||
776 !(rdev->wiphy.interface_modes & (1 << ntype)))
779 /* if it's part of a bridge, reject changing type to station/ibss */
780 if ((dev->priv_flags & IFF_BRIDGE_PORT) &&
781 (ntype == NL80211_IFTYPE_ADHOC || ntype == NL80211_IFTYPE_STATION))
784 if (ntype != otype) {
785 dev->ieee80211_ptr->use_4addr = false;
788 case NL80211_IFTYPE_ADHOC:
789 cfg80211_leave_ibss(rdev, dev, false);
791 case NL80211_IFTYPE_STATION:
792 cfg80211_disconnect(rdev, dev,
793 WLAN_REASON_DEAUTH_LEAVING, true);
795 case NL80211_IFTYPE_MESH_POINT:
796 /* mesh should be handled? */
802 cfg80211_process_rdev_events(rdev);
805 err = rdev->ops->change_virtual_intf(&rdev->wiphy, dev,
806 ntype, flags, params);
808 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
810 if (!err && params && params->use_4addr != -1)
811 dev->ieee80211_ptr->use_4addr = params->use_4addr;
814 dev->priv_flags &= ~IFF_DONT_BRIDGE;
816 case NL80211_IFTYPE_STATION:
817 if (dev->ieee80211_ptr->use_4addr)
820 case NL80211_IFTYPE_ADHOC:
821 dev->priv_flags |= IFF_DONT_BRIDGE;
823 case NL80211_IFTYPE_AP:
824 case NL80211_IFTYPE_AP_VLAN:
825 case NL80211_IFTYPE_WDS:
826 case NL80211_IFTYPE_MESH_POINT:
829 case NL80211_IFTYPE_MONITOR:
830 /* monitor can't bridge anyway */
832 case NL80211_IFTYPE_UNSPECIFIED:
833 case NUM_NL80211_IFTYPES:
842 u16 cfg80211_calculate_bitrate(struct rate_info *rate)
844 int modulation, streams, bitrate;
846 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
849 /* the formula below does only work for MCS values smaller than 32 */
853 modulation = rate->mcs & 7;
854 streams = (rate->mcs >> 3) + 1;
856 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
860 bitrate *= (modulation + 1);
861 else if (modulation == 4)
862 bitrate *= (modulation + 2);
864 bitrate *= (modulation + 3);
868 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
869 bitrate = (bitrate / 9) * 10;
871 /* do NOT round down here */
872 return (bitrate + 50000) / 100000;