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 &&
330 iftype != NL80211_IFTYPE_P2P_GO))
333 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
334 if (unlikely(iftype != NL80211_IFTYPE_WDS &&
335 iftype != NL80211_IFTYPE_MESH_POINT &&
336 iftype != NL80211_IFTYPE_AP_VLAN &&
337 iftype != NL80211_IFTYPE_STATION))
339 if (iftype == NL80211_IFTYPE_MESH_POINT) {
340 struct ieee80211s_hdr *meshdr =
341 (struct ieee80211s_hdr *) (skb->data + hdrlen);
342 /* make sure meshdr->flags is on the linear part */
343 if (!pskb_may_pull(skb, hdrlen + 1))
345 if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
346 skb_copy_bits(skb, hdrlen +
347 offsetof(struct ieee80211s_hdr, eaddr1),
349 skb_copy_bits(skb, hdrlen +
350 offsetof(struct ieee80211s_hdr, eaddr2),
353 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
356 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
357 if ((iftype != NL80211_IFTYPE_STATION &&
358 iftype != NL80211_IFTYPE_P2P_CLIENT &&
359 iftype != NL80211_IFTYPE_MESH_POINT) ||
360 (is_multicast_ether_addr(dst) &&
361 !compare_ether_addr(src, addr)))
363 if (iftype == NL80211_IFTYPE_MESH_POINT) {
364 struct ieee80211s_hdr *meshdr =
365 (struct ieee80211s_hdr *) (skb->data + hdrlen);
366 /* make sure meshdr->flags is on the linear part */
367 if (!pskb_may_pull(skb, hdrlen + 1))
369 if (meshdr->flags & MESH_FLAGS_AE_A4)
370 skb_copy_bits(skb, hdrlen +
371 offsetof(struct ieee80211s_hdr, eaddr1),
373 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
377 if (iftype != NL80211_IFTYPE_ADHOC)
382 if (!pskb_may_pull(skb, hdrlen + 8))
385 payload = skb->data + hdrlen;
386 ethertype = (payload[6] << 8) | payload[7];
388 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
389 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
390 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
391 /* remove RFC1042 or Bridge-Tunnel encapsulation and
392 * replace EtherType */
393 skb_pull(skb, hdrlen + 6);
394 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
395 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
400 skb_pull(skb, hdrlen);
401 len = htons(skb->len);
402 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
403 memcpy(ehdr->h_dest, dst, ETH_ALEN);
404 memcpy(ehdr->h_source, src, ETH_ALEN);
409 EXPORT_SYMBOL(ieee80211_data_to_8023);
411 int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
412 enum nl80211_iftype iftype, u8 *bssid, bool qos)
414 struct ieee80211_hdr hdr;
415 u16 hdrlen, ethertype;
417 const u8 *encaps_data;
418 int encaps_len, skip_header_bytes;
422 if (unlikely(skb->len < ETH_HLEN))
425 nh_pos = skb_network_header(skb) - skb->data;
426 h_pos = skb_transport_header(skb) - skb->data;
428 /* convert Ethernet header to proper 802.11 header (based on
430 ethertype = (skb->data[12] << 8) | skb->data[13];
431 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
434 case NL80211_IFTYPE_AP:
435 case NL80211_IFTYPE_AP_VLAN:
436 case NL80211_IFTYPE_P2P_GO:
437 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
439 memcpy(hdr.addr1, skb->data, ETH_ALEN);
440 memcpy(hdr.addr2, addr, ETH_ALEN);
441 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
444 case NL80211_IFTYPE_STATION:
445 case NL80211_IFTYPE_P2P_CLIENT:
446 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
448 memcpy(hdr.addr1, bssid, ETH_ALEN);
449 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
450 memcpy(hdr.addr3, skb->data, ETH_ALEN);
453 case NL80211_IFTYPE_ADHOC:
455 memcpy(hdr.addr1, skb->data, ETH_ALEN);
456 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
457 memcpy(hdr.addr3, bssid, ETH_ALEN);
465 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
469 hdr.frame_control = fc;
473 skip_header_bytes = ETH_HLEN;
474 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
475 encaps_data = bridge_tunnel_header;
476 encaps_len = sizeof(bridge_tunnel_header);
477 skip_header_bytes -= 2;
478 } else if (ethertype > 0x600) {
479 encaps_data = rfc1042_header;
480 encaps_len = sizeof(rfc1042_header);
481 skip_header_bytes -= 2;
487 skb_pull(skb, skip_header_bytes);
488 nh_pos -= skip_header_bytes;
489 h_pos -= skip_header_bytes;
491 head_need = hdrlen + encaps_len - skb_headroom(skb);
493 if (head_need > 0 || skb_cloned(skb)) {
494 head_need = max(head_need, 0);
498 if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) {
499 printk(KERN_ERR "failed to reallocate Tx buffer\n");
502 skb->truesize += head_need;
506 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
507 nh_pos += encaps_len;
511 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
516 /* Update skb pointers to various headers since this modified frame
517 * is going to go through Linux networking code that may potentially
518 * need things like pointer to IP header. */
519 skb_set_mac_header(skb, 0);
520 skb_set_network_header(skb, nh_pos);
521 skb_set_transport_header(skb, h_pos);
525 EXPORT_SYMBOL(ieee80211_data_from_8023);
528 void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
529 const u8 *addr, enum nl80211_iftype iftype,
530 const unsigned int extra_headroom)
532 struct sk_buff *frame = NULL;
535 const struct ethhdr *eth;
537 u8 dst[ETH_ALEN], src[ETH_ALEN];
539 err = ieee80211_data_to_8023(skb, addr, iftype);
543 /* skip the wrapping header */
544 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
548 while (skb != frame) {
550 __be16 len = eth->h_proto;
551 unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
553 remaining = skb->len;
554 memcpy(dst, eth->h_dest, ETH_ALEN);
555 memcpy(src, eth->h_source, ETH_ALEN);
557 padding = (4 - subframe_len) & 0x3;
558 /* the last MSDU has no padding */
559 if (subframe_len > remaining)
562 skb_pull(skb, sizeof(struct ethhdr));
563 /* reuse skb for the last subframe */
564 if (remaining <= subframe_len + padding)
567 unsigned int hlen = ALIGN(extra_headroom, 4);
569 * Allocate and reserve two bytes more for payload
570 * alignment since sizeof(struct ethhdr) is 14.
572 frame = dev_alloc_skb(hlen + subframe_len + 2);
576 skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
577 memcpy(skb_put(frame, ntohs(len)), skb->data,
580 eth = (struct ethhdr *)skb_pull(skb, ntohs(len) +
583 dev_kfree_skb(frame);
588 skb_reset_network_header(frame);
589 frame->dev = skb->dev;
590 frame->priority = skb->priority;
592 payload = frame->data;
593 ethertype = (payload[6] << 8) | payload[7];
595 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
596 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
597 compare_ether_addr(payload,
598 bridge_tunnel_header) == 0)) {
599 /* remove RFC1042 or Bridge-Tunnel
600 * encapsulation and replace EtherType */
602 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
603 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
605 memcpy(skb_push(frame, sizeof(__be16)), &len,
607 memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
608 memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
610 __skb_queue_tail(list, frame);
616 __skb_queue_purge(list);
620 EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
622 /* Given a data frame determine the 802.1p/1d tag to use. */
623 unsigned int cfg80211_classify8021d(struct sk_buff *skb)
627 /* skb->priority values from 256->263 are magic values to
628 * directly indicate a specific 802.1d priority. This is used
629 * to allow 802.1d priority to be passed directly in from VLAN
632 if (skb->priority >= 256 && skb->priority <= 263)
633 return skb->priority - 256;
635 switch (skb->protocol) {
636 case htons(ETH_P_IP):
637 dscp = ip_hdr(skb)->tos & 0xfc;
645 EXPORT_SYMBOL(cfg80211_classify8021d);
647 const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie)
651 pos = bss->information_elements;
654 end = pos + bss->len_information_elements;
656 while (pos + 1 < end) {
657 if (pos + 2 + pos[1] > end)
666 EXPORT_SYMBOL(ieee80211_bss_get_ie);
668 void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
670 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
671 struct net_device *dev = wdev->netdev;
674 if (!wdev->connect_keys)
677 for (i = 0; i < 6; i++) {
678 if (!wdev->connect_keys->params[i].cipher)
680 if (rdev->ops->add_key(wdev->wiphy, dev, i, NULL,
681 &wdev->connect_keys->params[i])) {
682 printk(KERN_ERR "%s: failed to set key %d\n",
686 if (wdev->connect_keys->def == i)
687 if (rdev->ops->set_default_key(wdev->wiphy, dev, i)) {
688 printk(KERN_ERR "%s: failed to set defkey %d\n",
692 if (wdev->connect_keys->defmgmt == i)
693 if (rdev->ops->set_default_mgmt_key(wdev->wiphy, dev, i))
694 printk(KERN_ERR "%s: failed to set mgtdef %d\n",
698 kfree(wdev->connect_keys);
699 wdev->connect_keys = NULL;
702 static void cfg80211_process_wdev_events(struct wireless_dev *wdev)
704 struct cfg80211_event *ev;
706 const u8 *bssid = NULL;
708 spin_lock_irqsave(&wdev->event_lock, flags);
709 while (!list_empty(&wdev->event_list)) {
710 ev = list_first_entry(&wdev->event_list,
711 struct cfg80211_event, list);
713 spin_unlock_irqrestore(&wdev->event_lock, flags);
717 case EVENT_CONNECT_RESULT:
718 if (!is_zero_ether_addr(ev->cr.bssid))
719 bssid = ev->cr.bssid;
720 __cfg80211_connect_result(
722 ev->cr.req_ie, ev->cr.req_ie_len,
723 ev->cr.resp_ie, ev->cr.resp_ie_len,
725 ev->cr.status == WLAN_STATUS_SUCCESS,
729 __cfg80211_roamed(wdev, ev->rm.bssid,
730 ev->rm.req_ie, ev->rm.req_ie_len,
731 ev->rm.resp_ie, ev->rm.resp_ie_len);
733 case EVENT_DISCONNECTED:
734 __cfg80211_disconnected(wdev->netdev,
735 ev->dc.ie, ev->dc.ie_len,
736 ev->dc.reason, true);
738 case EVENT_IBSS_JOINED:
739 __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid);
746 spin_lock_irqsave(&wdev->event_lock, flags);
748 spin_unlock_irqrestore(&wdev->event_lock, flags);
751 void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
753 struct wireless_dev *wdev;
756 ASSERT_RDEV_LOCK(rdev);
758 mutex_lock(&rdev->devlist_mtx);
760 list_for_each_entry(wdev, &rdev->netdev_list, list)
761 cfg80211_process_wdev_events(wdev);
763 mutex_unlock(&rdev->devlist_mtx);
766 int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
767 struct net_device *dev, enum nl80211_iftype ntype,
768 u32 *flags, struct vif_params *params)
771 enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
773 ASSERT_RDEV_LOCK(rdev);
775 /* don't support changing VLANs, you just re-create them */
776 if (otype == NL80211_IFTYPE_AP_VLAN)
779 if (!rdev->ops->change_virtual_intf ||
780 !(rdev->wiphy.interface_modes & (1 << ntype)))
783 /* if it's part of a bridge, reject changing type to station/ibss */
784 if ((dev->priv_flags & IFF_BRIDGE_PORT) &&
785 (ntype == NL80211_IFTYPE_ADHOC ||
786 ntype == NL80211_IFTYPE_STATION ||
787 ntype == NL80211_IFTYPE_P2P_CLIENT))
790 if (ntype != otype) {
791 dev->ieee80211_ptr->use_4addr = false;
794 case NL80211_IFTYPE_ADHOC:
795 cfg80211_leave_ibss(rdev, dev, false);
797 case NL80211_IFTYPE_STATION:
798 case NL80211_IFTYPE_P2P_CLIENT:
799 cfg80211_disconnect(rdev, dev,
800 WLAN_REASON_DEAUTH_LEAVING, true);
802 case NL80211_IFTYPE_MESH_POINT:
803 /* mesh should be handled? */
809 cfg80211_process_rdev_events(rdev);
812 err = rdev->ops->change_virtual_intf(&rdev->wiphy, dev,
813 ntype, flags, params);
815 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
817 if (!err && params && params->use_4addr != -1)
818 dev->ieee80211_ptr->use_4addr = params->use_4addr;
821 dev->priv_flags &= ~IFF_DONT_BRIDGE;
823 case NL80211_IFTYPE_STATION:
824 if (dev->ieee80211_ptr->use_4addr)
827 case NL80211_IFTYPE_P2P_CLIENT:
828 case NL80211_IFTYPE_ADHOC:
829 dev->priv_flags |= IFF_DONT_BRIDGE;
831 case NL80211_IFTYPE_P2P_GO:
832 case NL80211_IFTYPE_AP:
833 case NL80211_IFTYPE_AP_VLAN:
834 case NL80211_IFTYPE_WDS:
835 case NL80211_IFTYPE_MESH_POINT:
838 case NL80211_IFTYPE_MONITOR:
839 /* monitor can't bridge anyway */
841 case NL80211_IFTYPE_UNSPECIFIED:
842 case NUM_NL80211_IFTYPES:
851 u16 cfg80211_calculate_bitrate(struct rate_info *rate)
853 int modulation, streams, bitrate;
855 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
858 /* the formula below does only work for MCS values smaller than 32 */
862 modulation = rate->mcs & 7;
863 streams = (rate->mcs >> 3) + 1;
865 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
869 bitrate *= (modulation + 1);
870 else if (modulation == 4)
871 bitrate *= (modulation + 2);
873 bitrate *= (modulation + 3);
877 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
878 bitrate = (bitrate / 9) * 10;
880 /* do NOT round down here */
881 return (bitrate + 50000) / 100000;