1 // SPDX-License-Identifier: GPL-2.0
3 * Wireless utility functions
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
7 * Copyright 2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2022 Intel Corporation
10 #include <linux/export.h>
11 #include <linux/bitops.h>
12 #include <linux/etherdevice.h>
13 #include <linux/slab.h>
14 #include <linux/ieee80211.h>
15 #include <net/cfg80211.h>
17 #include <net/dsfield.h>
18 #include <linux/if_vlan.h>
19 #include <linux/mpls.h>
20 #include <linux/gcd.h>
21 #include <linux/bitfield.h>
22 #include <linux/nospec.h>
27 const struct ieee80211_rate *
28 ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
29 u32 basic_rates, int bitrate)
31 struct ieee80211_rate *result = &sband->bitrates[0];
34 for (i = 0; i < sband->n_bitrates; i++) {
35 if (!(basic_rates & BIT(i)))
37 if (sband->bitrates[i].bitrate > bitrate)
39 result = &sband->bitrates[i];
44 EXPORT_SYMBOL(ieee80211_get_response_rate);
46 u32 ieee80211_mandatory_rates(struct ieee80211_supported_band *sband,
47 enum nl80211_bss_scan_width scan_width)
49 struct ieee80211_rate *bitrates;
50 u32 mandatory_rates = 0;
51 enum ieee80211_rate_flags mandatory_flag;
57 if (sband->band == NL80211_BAND_2GHZ) {
58 if (scan_width == NL80211_BSS_CHAN_WIDTH_5 ||
59 scan_width == NL80211_BSS_CHAN_WIDTH_10)
60 mandatory_flag = IEEE80211_RATE_MANDATORY_G;
62 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
64 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
67 bitrates = sband->bitrates;
68 for (i = 0; i < sband->n_bitrates; i++)
69 if (bitrates[i].flags & mandatory_flag)
70 mandatory_rates |= BIT(i);
71 return mandatory_rates;
73 EXPORT_SYMBOL(ieee80211_mandatory_rates);
75 u32 ieee80211_channel_to_freq_khz(int chan, enum nl80211_band band)
77 /* see 802.11 17.3.8.3.2 and Annex J
78 * there are overlapping channel numbers in 5GHz and 2GHz bands */
80 return 0; /* not supported */
82 case NL80211_BAND_2GHZ:
85 return MHZ_TO_KHZ(2484);
87 return MHZ_TO_KHZ(2407 + chan * 5);
89 case NL80211_BAND_5GHZ:
90 if (chan >= 182 && chan <= 196)
91 return MHZ_TO_KHZ(4000 + chan * 5);
93 return MHZ_TO_KHZ(5000 + chan * 5);
95 case NL80211_BAND_6GHZ:
96 /* see 802.11ax D6.1 27.3.23.2 */
98 return MHZ_TO_KHZ(5935);
100 return MHZ_TO_KHZ(5950 + chan * 5);
102 case NL80211_BAND_60GHZ:
104 return MHZ_TO_KHZ(56160 + chan * 2160);
106 case NL80211_BAND_S1GHZ:
107 return 902000 + chan * 500;
111 return 0; /* not supported */
113 EXPORT_SYMBOL(ieee80211_channel_to_freq_khz);
115 enum nl80211_chan_width
116 ieee80211_s1g_channel_width(const struct ieee80211_channel *chan)
118 if (WARN_ON(!chan || chan->band != NL80211_BAND_S1GHZ))
119 return NL80211_CHAN_WIDTH_20_NOHT;
121 /*S1G defines a single allowed channel width per channel.
122 * Extract that width here.
124 if (chan->flags & IEEE80211_CHAN_1MHZ)
125 return NL80211_CHAN_WIDTH_1;
126 else if (chan->flags & IEEE80211_CHAN_2MHZ)
127 return NL80211_CHAN_WIDTH_2;
128 else if (chan->flags & IEEE80211_CHAN_4MHZ)
129 return NL80211_CHAN_WIDTH_4;
130 else if (chan->flags & IEEE80211_CHAN_8MHZ)
131 return NL80211_CHAN_WIDTH_8;
132 else if (chan->flags & IEEE80211_CHAN_16MHZ)
133 return NL80211_CHAN_WIDTH_16;
135 pr_err("unknown channel width for channel at %dKHz?\n",
136 ieee80211_channel_to_khz(chan));
138 return NL80211_CHAN_WIDTH_1;
140 EXPORT_SYMBOL(ieee80211_s1g_channel_width);
142 int ieee80211_freq_khz_to_channel(u32 freq)
144 /* TODO: just handle MHz for now */
145 freq = KHZ_TO_MHZ(freq);
147 /* see 802.11 17.3.8.3.2 and Annex J */
150 else if (freq < 2484)
151 return (freq - 2407) / 5;
152 else if (freq >= 4910 && freq <= 4980)
153 return (freq - 4000) / 5;
154 else if (freq < 5925)
155 return (freq - 5000) / 5;
156 else if (freq == 5935)
158 else if (freq <= 45000) /* DMG band lower limit */
159 /* see 802.11ax D6.1 27.3.22.2 */
160 return (freq - 5950) / 5;
161 else if (freq >= 58320 && freq <= 70200)
162 return (freq - 56160) / 2160;
166 EXPORT_SYMBOL(ieee80211_freq_khz_to_channel);
168 struct ieee80211_channel *ieee80211_get_channel_khz(struct wiphy *wiphy,
171 enum nl80211_band band;
172 struct ieee80211_supported_band *sband;
175 for (band = 0; band < NUM_NL80211_BANDS; band++) {
176 sband = wiphy->bands[band];
181 for (i = 0; i < sband->n_channels; i++) {
182 struct ieee80211_channel *chan = &sband->channels[i];
184 if (ieee80211_channel_to_khz(chan) == freq)
191 EXPORT_SYMBOL(ieee80211_get_channel_khz);
193 static void set_mandatory_flags_band(struct ieee80211_supported_band *sband)
197 switch (sband->band) {
198 case NL80211_BAND_5GHZ:
199 case NL80211_BAND_6GHZ:
201 for (i = 0; i < sband->n_bitrates; i++) {
202 if (sband->bitrates[i].bitrate == 60 ||
203 sband->bitrates[i].bitrate == 120 ||
204 sband->bitrates[i].bitrate == 240) {
205 sband->bitrates[i].flags |=
206 IEEE80211_RATE_MANDATORY_A;
212 case NL80211_BAND_2GHZ:
213 case NL80211_BAND_LC:
215 for (i = 0; i < sband->n_bitrates; i++) {
216 switch (sband->bitrates[i].bitrate) {
221 sband->bitrates[i].flags |=
222 IEEE80211_RATE_MANDATORY_B |
223 IEEE80211_RATE_MANDATORY_G;
229 sband->bitrates[i].flags |=
230 IEEE80211_RATE_MANDATORY_G;
234 sband->bitrates[i].flags |=
235 IEEE80211_RATE_ERP_G;
239 WARN_ON(want != 0 && want != 3);
241 case NL80211_BAND_60GHZ:
242 /* check for mandatory HT MCS 1..4 */
243 WARN_ON(!sband->ht_cap.ht_supported);
244 WARN_ON((sband->ht_cap.mcs.rx_mask[0] & 0x1e) != 0x1e);
246 case NL80211_BAND_S1GHZ:
247 /* Figure 9-589bd: 3 means unsupported, so != 3 means at least
250 WARN_ON((sband->s1g_cap.nss_mcs[0] & 0x3) == 0x3);
252 case NUM_NL80211_BANDS:
259 void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
261 enum nl80211_band band;
263 for (band = 0; band < NUM_NL80211_BANDS; band++)
264 if (wiphy->bands[band])
265 set_mandatory_flags_band(wiphy->bands[band]);
268 bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher)
271 for (i = 0; i < wiphy->n_cipher_suites; i++)
272 if (cipher == wiphy->cipher_suites[i])
278 cfg80211_igtk_cipher_supported(struct cfg80211_registered_device *rdev)
280 struct wiphy *wiphy = &rdev->wiphy;
283 for (i = 0; i < wiphy->n_cipher_suites; i++) {
284 switch (wiphy->cipher_suites[i]) {
285 case WLAN_CIPHER_SUITE_AES_CMAC:
286 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
287 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
288 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
296 bool cfg80211_valid_key_idx(struct cfg80211_registered_device *rdev,
297 int key_idx, bool pairwise)
303 else if (wiphy_ext_feature_isset(&rdev->wiphy,
304 NL80211_EXT_FEATURE_BEACON_PROTECTION) ||
305 wiphy_ext_feature_isset(&rdev->wiphy,
306 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
308 else if (cfg80211_igtk_cipher_supported(rdev))
313 if (key_idx < 0 || key_idx > max_key_idx)
319 int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
320 struct key_params *params, int key_idx,
321 bool pairwise, const u8 *mac_addr)
323 if (!cfg80211_valid_key_idx(rdev, key_idx, pairwise))
326 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
329 if (pairwise && !mac_addr)
332 switch (params->cipher) {
333 case WLAN_CIPHER_SUITE_TKIP:
334 /* Extended Key ID can only be used with CCMP/GCMP ciphers */
335 if ((pairwise && key_idx) ||
336 params->mode != NL80211_KEY_RX_TX)
339 case WLAN_CIPHER_SUITE_CCMP:
340 case WLAN_CIPHER_SUITE_CCMP_256:
341 case WLAN_CIPHER_SUITE_GCMP:
342 case WLAN_CIPHER_SUITE_GCMP_256:
343 /* IEEE802.11-2016 allows only 0 and - when supporting
344 * Extended Key ID - 1 as index for pairwise keys.
345 * @NL80211_KEY_NO_TX is only allowed for pairwise keys when
346 * the driver supports Extended Key ID.
347 * @NL80211_KEY_SET_TX can't be set when installing and
350 if ((params->mode == NL80211_KEY_NO_TX && !pairwise) ||
351 params->mode == NL80211_KEY_SET_TX)
353 if (wiphy_ext_feature_isset(&rdev->wiphy,
354 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
355 if (pairwise && (key_idx < 0 || key_idx > 1))
357 } else if (pairwise && key_idx) {
361 case WLAN_CIPHER_SUITE_AES_CMAC:
362 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
363 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
364 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
365 /* Disallow BIP (group-only) cipher as pairwise cipher */
371 case WLAN_CIPHER_SUITE_WEP40:
372 case WLAN_CIPHER_SUITE_WEP104:
380 switch (params->cipher) {
381 case WLAN_CIPHER_SUITE_WEP40:
382 if (params->key_len != WLAN_KEY_LEN_WEP40)
385 case WLAN_CIPHER_SUITE_TKIP:
386 if (params->key_len != WLAN_KEY_LEN_TKIP)
389 case WLAN_CIPHER_SUITE_CCMP:
390 if (params->key_len != WLAN_KEY_LEN_CCMP)
393 case WLAN_CIPHER_SUITE_CCMP_256:
394 if (params->key_len != WLAN_KEY_LEN_CCMP_256)
397 case WLAN_CIPHER_SUITE_GCMP:
398 if (params->key_len != WLAN_KEY_LEN_GCMP)
401 case WLAN_CIPHER_SUITE_GCMP_256:
402 if (params->key_len != WLAN_KEY_LEN_GCMP_256)
405 case WLAN_CIPHER_SUITE_WEP104:
406 if (params->key_len != WLAN_KEY_LEN_WEP104)
409 case WLAN_CIPHER_SUITE_AES_CMAC:
410 if (params->key_len != WLAN_KEY_LEN_AES_CMAC)
413 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
414 if (params->key_len != WLAN_KEY_LEN_BIP_CMAC_256)
417 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
418 if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_128)
421 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
422 if (params->key_len != WLAN_KEY_LEN_BIP_GMAC_256)
427 * We don't know anything about this algorithm,
428 * allow using it -- but the driver must check
429 * all parameters! We still check below whether
430 * or not the driver supports this algorithm,
437 switch (params->cipher) {
438 case WLAN_CIPHER_SUITE_WEP40:
439 case WLAN_CIPHER_SUITE_WEP104:
440 /* These ciphers do not use key sequence */
442 case WLAN_CIPHER_SUITE_TKIP:
443 case WLAN_CIPHER_SUITE_CCMP:
444 case WLAN_CIPHER_SUITE_CCMP_256:
445 case WLAN_CIPHER_SUITE_GCMP:
446 case WLAN_CIPHER_SUITE_GCMP_256:
447 case WLAN_CIPHER_SUITE_AES_CMAC:
448 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
449 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
450 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
451 if (params->seq_len != 6)
457 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher))
463 unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc)
465 unsigned int hdrlen = 24;
467 if (ieee80211_is_ext(fc)) {
472 if (ieee80211_is_data(fc)) {
473 if (ieee80211_has_a4(fc))
475 if (ieee80211_is_data_qos(fc)) {
476 hdrlen += IEEE80211_QOS_CTL_LEN;
477 if (ieee80211_has_order(fc))
478 hdrlen += IEEE80211_HT_CTL_LEN;
483 if (ieee80211_is_mgmt(fc)) {
484 if (ieee80211_has_order(fc))
485 hdrlen += IEEE80211_HT_CTL_LEN;
489 if (ieee80211_is_ctl(fc)) {
491 * ACK and CTS are 10 bytes, all others 16. To see how
492 * to get this condition consider
493 * subtype mask: 0b0000000011110000 (0x00F0)
494 * ACK subtype: 0b0000000011010000 (0x00D0)
495 * CTS subtype: 0b0000000011000000 (0x00C0)
496 * bits that matter: ^^^ (0x00E0)
497 * value of those: 0b0000000011000000 (0x00C0)
499 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
507 EXPORT_SYMBOL(ieee80211_hdrlen);
509 unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
511 const struct ieee80211_hdr *hdr =
512 (const struct ieee80211_hdr *)skb->data;
515 if (unlikely(skb->len < 10))
517 hdrlen = ieee80211_hdrlen(hdr->frame_control);
518 if (unlikely(hdrlen > skb->len))
522 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
524 static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags)
526 int ae = flags & MESH_FLAGS_AE;
527 /* 802.11-2012, 8.2.4.7.3 */
532 case MESH_FLAGS_AE_A4:
534 case MESH_FLAGS_AE_A5_A6:
539 unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
541 return __ieee80211_get_mesh_hdrlen(meshhdr->flags);
543 EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
545 bool ieee80211_get_8023_tunnel_proto(const void *hdr, __be16 *proto)
547 const __be16 *hdr_proto = hdr + ETH_ALEN;
549 if (!(ether_addr_equal(hdr, rfc1042_header) &&
550 *hdr_proto != htons(ETH_P_AARP) &&
551 *hdr_proto != htons(ETH_P_IPX)) &&
552 !ether_addr_equal(hdr, bridge_tunnel_header))
559 EXPORT_SYMBOL(ieee80211_get_8023_tunnel_proto);
561 int ieee80211_strip_8023_mesh_hdr(struct sk_buff *skb)
563 const void *mesh_addr;
571 ret = skb_copy_bits(skb, 0, &payload, sizeof(payload));
575 hdrlen = sizeof(payload.eth) + __ieee80211_get_mesh_hdrlen(payload.flags);
577 if (likely(pskb_may_pull(skb, hdrlen + 8) &&
578 ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
579 &payload.eth.h_proto)))
580 hdrlen += ETH_ALEN + 2;
581 else if (!pskb_may_pull(skb, hdrlen))
584 mesh_addr = skb->data + sizeof(payload.eth) + ETH_ALEN;
585 switch (payload.flags & MESH_FLAGS_AE) {
586 case MESH_FLAGS_AE_A4:
587 memcpy(&payload.eth.h_source, mesh_addr, ETH_ALEN);
589 case MESH_FLAGS_AE_A5_A6:
590 memcpy(&payload.eth, mesh_addr, 2 * ETH_ALEN);
596 pskb_pull(skb, hdrlen - sizeof(payload.eth));
597 memcpy(skb->data, &payload.eth, sizeof(payload.eth));
601 EXPORT_SYMBOL(ieee80211_strip_8023_mesh_hdr);
603 int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
604 const u8 *addr, enum nl80211_iftype iftype,
605 u8 data_offset, bool is_amsdu)
607 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
609 u8 hdr[ETH_ALEN] __aligned(2);
615 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
618 hdrlen = ieee80211_hdrlen(hdr->frame_control) + data_offset;
619 if (skb->len < hdrlen)
622 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
624 * IEEE 802.11 address fields:
625 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
626 * 0 0 DA SA BSSID n/a
627 * 0 1 DA BSSID SA n/a
628 * 1 0 BSSID SA DA n/a
631 memcpy(tmp.h_dest, ieee80211_get_DA(hdr), ETH_ALEN);
632 memcpy(tmp.h_source, ieee80211_get_SA(hdr), ETH_ALEN);
634 switch (hdr->frame_control &
635 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
636 case cpu_to_le16(IEEE80211_FCTL_TODS):
637 if (unlikely(iftype != NL80211_IFTYPE_AP &&
638 iftype != NL80211_IFTYPE_AP_VLAN &&
639 iftype != NL80211_IFTYPE_P2P_GO))
642 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
643 if (unlikely(iftype != NL80211_IFTYPE_MESH_POINT &&
644 iftype != NL80211_IFTYPE_AP_VLAN &&
645 iftype != NL80211_IFTYPE_STATION))
648 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
649 if ((iftype != NL80211_IFTYPE_STATION &&
650 iftype != NL80211_IFTYPE_P2P_CLIENT &&
651 iftype != NL80211_IFTYPE_MESH_POINT) ||
652 (is_multicast_ether_addr(tmp.h_dest) &&
653 ether_addr_equal(tmp.h_source, addr)))
657 if (iftype != NL80211_IFTYPE_ADHOC &&
658 iftype != NL80211_IFTYPE_STATION &&
659 iftype != NL80211_IFTYPE_OCB)
664 if (likely(!is_amsdu && iftype != NL80211_IFTYPE_MESH_POINT &&
665 skb_copy_bits(skb, hdrlen, &payload, sizeof(payload)) == 0 &&
666 ieee80211_get_8023_tunnel_proto(&payload, &tmp.h_proto))) {
667 /* remove RFC1042 or Bridge-Tunnel encapsulation */
668 hdrlen += ETH_ALEN + 2;
669 skb_postpull_rcsum(skb, &payload, ETH_ALEN + 2);
671 tmp.h_proto = htons(skb->len - hdrlen);
674 pskb_pull(skb, hdrlen);
677 ehdr = skb_push(skb, sizeof(struct ethhdr));
678 memcpy(ehdr, &tmp, sizeof(tmp));
682 EXPORT_SYMBOL(ieee80211_data_to_8023_exthdr);
685 __frame_add_frag(struct sk_buff *skb, struct page *page,
686 void *ptr, int len, int size)
688 struct skb_shared_info *sh = skb_shinfo(skb);
692 page_offset = ptr - page_address(page);
693 skb_add_rx_frag(skb, sh->nr_frags, page, page_offset, len, size);
697 __ieee80211_amsdu_copy_frag(struct sk_buff *skb, struct sk_buff *frame,
700 struct skb_shared_info *sh = skb_shinfo(skb);
701 const skb_frag_t *frag = &sh->frags[0];
702 struct page *frag_page;
704 int frag_len, frag_size;
705 int head_size = skb->len - skb->data_len;
708 frag_page = virt_to_head_page(skb->head);
709 frag_ptr = skb->data;
710 frag_size = head_size;
712 while (offset >= frag_size) {
714 frag_page = skb_frag_page(frag);
715 frag_ptr = skb_frag_address(frag);
716 frag_size = skb_frag_size(frag);
721 frag_len = frag_size - offset;
723 cur_len = min(len, frag_len);
725 __frame_add_frag(frame, frag_page, frag_ptr, cur_len, frag_size);
729 frag_len = skb_frag_size(frag);
730 cur_len = min(len, frag_len);
731 __frame_add_frag(frame, skb_frag_page(frag),
732 skb_frag_address(frag), cur_len, frag_len);
738 static struct sk_buff *
739 __ieee80211_amsdu_copy(struct sk_buff *skb, unsigned int hlen,
740 int offset, int len, bool reuse_frag,
743 struct sk_buff *frame;
746 if (skb->len - offset < len)
750 * When reusing framents, copy some data to the head to simplify
751 * ethernet header handling and speed up protocol header processing
752 * in the stack later.
755 cur_len = min_t(int, len, min_len);
758 * Allocate and reserve two bytes more for payload
759 * alignment since sizeof(struct ethhdr) is 14.
761 frame = dev_alloc_skb(hlen + sizeof(struct ethhdr) + 2 + cur_len);
765 frame->priority = skb->priority;
766 skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
767 skb_copy_bits(skb, offset, skb_put(frame, cur_len), cur_len);
774 __ieee80211_amsdu_copy_frag(skb, frame, offset, len);
780 ieee80211_amsdu_subframe_length(void *field, u8 mesh_flags, u8 hdr_type)
782 __le16 *field_le = field;
783 __be16 *field_be = field;
787 len = le16_to_cpu(*field_le);
789 len = be16_to_cpu(*field_be);
791 len += __ieee80211_get_mesh_hdrlen(mesh_flags);
796 bool ieee80211_is_valid_amsdu(struct sk_buff *skb, u8 mesh_hdr)
798 int offset = 0, remaining, subframe_len, padding;
800 for (offset = 0; offset < skb->len; offset += subframe_len + padding) {
807 if (skb_copy_bits(skb, offset + 2 * ETH_ALEN, &hdr, sizeof(hdr)) < 0)
810 len = ieee80211_amsdu_subframe_length(&hdr.len, hdr.mesh_flags,
812 subframe_len = sizeof(struct ethhdr) + len;
813 padding = (4 - subframe_len) & 0x3;
814 remaining = skb->len - offset;
816 if (subframe_len > remaining)
822 EXPORT_SYMBOL(ieee80211_is_valid_amsdu);
824 void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
825 const u8 *addr, enum nl80211_iftype iftype,
826 const unsigned int extra_headroom,
827 const u8 *check_da, const u8 *check_sa,
830 unsigned int hlen = ALIGN(extra_headroom, 4);
831 struct sk_buff *frame = NULL;
832 int offset = 0, remaining;
837 bool reuse_frag = skb->head_frag && !skb_has_frag_list(skb);
838 bool reuse_skb = false;
840 int copy_len = sizeof(hdr.eth);
842 if (iftype == NL80211_IFTYPE_MESH_POINT)
843 copy_len = sizeof(hdr);
846 unsigned int subframe_len;
847 int len, mesh_len = 0;
850 skb_copy_bits(skb, offset, &hdr, copy_len);
851 if (iftype == NL80211_IFTYPE_MESH_POINT)
852 mesh_len = __ieee80211_get_mesh_hdrlen(hdr.flags);
853 len = ieee80211_amsdu_subframe_length(&hdr.eth.h_proto, hdr.flags,
855 subframe_len = sizeof(struct ethhdr) + len;
856 padding = (4 - subframe_len) & 0x3;
858 /* the last MSDU has no padding */
859 remaining = skb->len - offset;
860 if (subframe_len > remaining)
862 /* mitigate A-MSDU aggregation injection attacks */
863 if (ether_addr_equal(hdr.eth.h_dest, rfc1042_header))
866 offset += sizeof(struct ethhdr);
867 last = remaining <= subframe_len + padding;
869 /* FIXME: should we really accept multicast DA? */
870 if ((check_da && !is_multicast_ether_addr(hdr.eth.h_dest) &&
871 !ether_addr_equal(check_da, hdr.eth.h_dest)) ||
872 (check_sa && !ether_addr_equal(check_sa, hdr.eth.h_source))) {
873 offset += len + padding;
877 /* reuse skb for the last subframe */
878 if (!skb_is_nonlinear(skb) && !reuse_frag && last) {
879 skb_pull(skb, offset);
883 frame = __ieee80211_amsdu_copy(skb, hlen, offset, len,
884 reuse_frag, 32 + mesh_len);
888 offset += len + padding;
891 skb_reset_network_header(frame);
892 frame->dev = skb->dev;
893 frame->priority = skb->priority;
895 if (likely(iftype != NL80211_IFTYPE_MESH_POINT &&
896 ieee80211_get_8023_tunnel_proto(frame->data, &hdr.eth.h_proto)))
897 skb_pull(frame, ETH_ALEN + 2);
899 memcpy(skb_push(frame, sizeof(hdr.eth)), &hdr.eth, sizeof(hdr.eth));
900 __skb_queue_tail(list, frame);
909 __skb_queue_purge(list);
912 EXPORT_SYMBOL(ieee80211_amsdu_to_8023s);
914 /* Given a data frame determine the 802.1p/1d tag to use. */
915 unsigned int cfg80211_classify8021d(struct sk_buff *skb,
916 struct cfg80211_qos_map *qos_map)
919 unsigned char vlan_priority;
922 /* skb->priority values from 256->263 are magic values to
923 * directly indicate a specific 802.1d priority. This is used
924 * to allow 802.1d priority to be passed directly in from VLAN
927 if (skb->priority >= 256 && skb->priority <= 263) {
928 ret = skb->priority - 256;
932 if (skb_vlan_tag_present(skb)) {
933 vlan_priority = (skb_vlan_tag_get(skb) & VLAN_PRIO_MASK)
935 if (vlan_priority > 0) {
941 switch (skb->protocol) {
942 case htons(ETH_P_IP):
943 dscp = ipv4_get_dsfield(ip_hdr(skb)) & 0xfc;
945 case htons(ETH_P_IPV6):
946 dscp = ipv6_get_dsfield(ipv6_hdr(skb)) & 0xfc;
948 case htons(ETH_P_MPLS_UC):
949 case htons(ETH_P_MPLS_MC): {
950 struct mpls_label mpls_tmp, *mpls;
952 mpls = skb_header_pointer(skb, sizeof(struct ethhdr),
953 sizeof(*mpls), &mpls_tmp);
957 ret = (ntohl(mpls->entry) & MPLS_LS_TC_MASK)
961 case htons(ETH_P_80221):
962 /* 802.21 is always network control traffic */
969 unsigned int i, tmp_dscp = dscp >> 2;
971 for (i = 0; i < qos_map->num_des; i++) {
972 if (tmp_dscp == qos_map->dscp_exception[i].dscp) {
973 ret = qos_map->dscp_exception[i].up;
978 for (i = 0; i < 8; i++) {
979 if (tmp_dscp >= qos_map->up[i].low &&
980 tmp_dscp <= qos_map->up[i].high) {
989 return array_index_nospec(ret, IEEE80211_NUM_TIDS);
991 EXPORT_SYMBOL(cfg80211_classify8021d);
993 const struct element *ieee80211_bss_get_elem(struct cfg80211_bss *bss, u8 id)
995 const struct cfg80211_bss_ies *ies;
997 ies = rcu_dereference(bss->ies);
1001 return cfg80211_find_elem(id, ies->data, ies->len);
1003 EXPORT_SYMBOL(ieee80211_bss_get_elem);
1005 void cfg80211_upload_connect_keys(struct wireless_dev *wdev)
1007 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
1008 struct net_device *dev = wdev->netdev;
1011 if (!wdev->connect_keys)
1014 for (i = 0; i < 4; i++) {
1015 if (!wdev->connect_keys->params[i].cipher)
1017 if (rdev_add_key(rdev, dev, -1, i, false, NULL,
1018 &wdev->connect_keys->params[i])) {
1019 netdev_err(dev, "failed to set key %d\n", i);
1022 if (wdev->connect_keys->def == i &&
1023 rdev_set_default_key(rdev, dev, -1, i, true, true)) {
1024 netdev_err(dev, "failed to set defkey %d\n", i);
1029 kfree_sensitive(wdev->connect_keys);
1030 wdev->connect_keys = NULL;
1033 void cfg80211_process_wdev_events(struct wireless_dev *wdev)
1035 struct cfg80211_event *ev;
1036 unsigned long flags;
1038 spin_lock_irqsave(&wdev->event_lock, flags);
1039 while (!list_empty(&wdev->event_list)) {
1040 ev = list_first_entry(&wdev->event_list,
1041 struct cfg80211_event, list);
1042 list_del(&ev->list);
1043 spin_unlock_irqrestore(&wdev->event_lock, flags);
1047 case EVENT_CONNECT_RESULT:
1048 __cfg80211_connect_result(
1051 ev->cr.status == WLAN_STATUS_SUCCESS);
1054 __cfg80211_roamed(wdev, &ev->rm);
1056 case EVENT_DISCONNECTED:
1057 __cfg80211_disconnected(wdev->netdev,
1058 ev->dc.ie, ev->dc.ie_len,
1060 !ev->dc.locally_generated);
1062 case EVENT_IBSS_JOINED:
1063 __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid,
1067 __cfg80211_leave(wiphy_to_rdev(wdev->wiphy), wdev);
1069 case EVENT_PORT_AUTHORIZED:
1070 __cfg80211_port_authorized(wdev, ev->pa.bssid,
1072 ev->pa.td_bitmap_len);
1079 spin_lock_irqsave(&wdev->event_lock, flags);
1081 spin_unlock_irqrestore(&wdev->event_lock, flags);
1084 void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev)
1086 struct wireless_dev *wdev;
1088 lockdep_assert_held(&rdev->wiphy.mtx);
1090 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list)
1091 cfg80211_process_wdev_events(wdev);
1094 int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
1095 struct net_device *dev, enum nl80211_iftype ntype,
1096 struct vif_params *params)
1099 enum nl80211_iftype otype = dev->ieee80211_ptr->iftype;
1101 lockdep_assert_held(&rdev->wiphy.mtx);
1103 /* don't support changing VLANs, you just re-create them */
1104 if (otype == NL80211_IFTYPE_AP_VLAN)
1107 /* cannot change into P2P device or NAN */
1108 if (ntype == NL80211_IFTYPE_P2P_DEVICE ||
1109 ntype == NL80211_IFTYPE_NAN)
1112 if (!rdev->ops->change_virtual_intf ||
1113 !(rdev->wiphy.interface_modes & (1 << ntype)))
1116 if (ntype != otype) {
1117 /* if it's part of a bridge, reject changing type to station/ibss */
1118 if (netif_is_bridge_port(dev) &&
1119 (ntype == NL80211_IFTYPE_ADHOC ||
1120 ntype == NL80211_IFTYPE_STATION ||
1121 ntype == NL80211_IFTYPE_P2P_CLIENT))
1124 dev->ieee80211_ptr->use_4addr = false;
1125 wdev_lock(dev->ieee80211_ptr);
1126 rdev_set_qos_map(rdev, dev, NULL);
1127 wdev_unlock(dev->ieee80211_ptr);
1130 case NL80211_IFTYPE_AP:
1131 case NL80211_IFTYPE_P2P_GO:
1132 cfg80211_stop_ap(rdev, dev, -1, true);
1134 case NL80211_IFTYPE_ADHOC:
1135 cfg80211_leave_ibss(rdev, dev, false);
1137 case NL80211_IFTYPE_STATION:
1138 case NL80211_IFTYPE_P2P_CLIENT:
1139 wdev_lock(dev->ieee80211_ptr);
1140 cfg80211_disconnect(rdev, dev,
1141 WLAN_REASON_DEAUTH_LEAVING, true);
1142 wdev_unlock(dev->ieee80211_ptr);
1144 case NL80211_IFTYPE_MESH_POINT:
1145 /* mesh should be handled? */
1147 case NL80211_IFTYPE_OCB:
1148 cfg80211_leave_ocb(rdev, dev);
1154 cfg80211_process_rdev_events(rdev);
1155 cfg80211_mlme_purge_registrations(dev->ieee80211_ptr);
1157 memset(&dev->ieee80211_ptr->u, 0,
1158 sizeof(dev->ieee80211_ptr->u));
1159 memset(&dev->ieee80211_ptr->links, 0,
1160 sizeof(dev->ieee80211_ptr->links));
1163 err = rdev_change_virtual_intf(rdev, dev, ntype, params);
1165 WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype);
1167 if (!err && params && params->use_4addr != -1)
1168 dev->ieee80211_ptr->use_4addr = params->use_4addr;
1171 dev->priv_flags &= ~IFF_DONT_BRIDGE;
1173 case NL80211_IFTYPE_STATION:
1174 if (dev->ieee80211_ptr->use_4addr)
1177 case NL80211_IFTYPE_OCB:
1178 case NL80211_IFTYPE_P2P_CLIENT:
1179 case NL80211_IFTYPE_ADHOC:
1180 dev->priv_flags |= IFF_DONT_BRIDGE;
1182 case NL80211_IFTYPE_P2P_GO:
1183 case NL80211_IFTYPE_AP:
1184 case NL80211_IFTYPE_AP_VLAN:
1185 case NL80211_IFTYPE_MESH_POINT:
1188 case NL80211_IFTYPE_MONITOR:
1189 /* monitor can't bridge anyway */
1191 case NL80211_IFTYPE_UNSPECIFIED:
1192 case NUM_NL80211_IFTYPES:
1195 case NL80211_IFTYPE_P2P_DEVICE:
1196 case NL80211_IFTYPE_WDS:
1197 case NL80211_IFTYPE_NAN:
1203 if (!err && ntype != otype && netif_running(dev)) {
1204 cfg80211_update_iface_num(rdev, ntype, 1);
1205 cfg80211_update_iface_num(rdev, otype, -1);
1211 static u32 cfg80211_calculate_bitrate_ht(struct rate_info *rate)
1213 int modulation, streams, bitrate;
1215 /* the formula below does only work for MCS values smaller than 32 */
1216 if (WARN_ON_ONCE(rate->mcs >= 32))
1219 modulation = rate->mcs & 7;
1220 streams = (rate->mcs >> 3) + 1;
1222 bitrate = (rate->bw == RATE_INFO_BW_40) ? 13500000 : 6500000;
1225 bitrate *= (modulation + 1);
1226 else if (modulation == 4)
1227 bitrate *= (modulation + 2);
1229 bitrate *= (modulation + 3);
1233 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1234 bitrate = (bitrate / 9) * 10;
1236 /* do NOT round down here */
1237 return (bitrate + 50000) / 100000;
1240 static u32 cfg80211_calculate_bitrate_dmg(struct rate_info *rate)
1242 static const u32 __mcs2bitrate[] = {
1250 [5] = 12512, /* 1251.25 mbps */
1260 [14] = 8662, /* 866.25 mbps */
1270 [24] = 67568, /* 6756.75 mbps */
1281 if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate)))
1284 return __mcs2bitrate[rate->mcs];
1287 static u32 cfg80211_calculate_bitrate_extended_sc_dmg(struct rate_info *rate)
1289 static const u32 __mcs2bitrate[] = {
1290 [6 - 6] = 26950, /* MCS 9.1 : 2695.0 mbps */
1291 [7 - 6] = 50050, /* MCS 12.1 */
1299 /* Extended SC MCS not defined for base MCS below 6 or above 12 */
1300 if (WARN_ON_ONCE(rate->mcs < 6 || rate->mcs > 12))
1303 return __mcs2bitrate[rate->mcs - 6];
1306 static u32 cfg80211_calculate_bitrate_edmg(struct rate_info *rate)
1308 static const u32 __mcs2bitrate[] = {
1316 [5] = 12512, /* 1251.25 mbps */
1334 if (WARN_ON_ONCE(rate->mcs >= ARRAY_SIZE(__mcs2bitrate)))
1337 return __mcs2bitrate[rate->mcs] * rate->n_bonded_ch;
1340 static u32 cfg80211_calculate_bitrate_vht(struct rate_info *rate)
1342 static const u32 base[4][12] = {
1352 /* not in the spec, but some devices use this: */
1404 case RATE_INFO_BW_160:
1407 case RATE_INFO_BW_80:
1410 case RATE_INFO_BW_40:
1413 case RATE_INFO_BW_5:
1414 case RATE_INFO_BW_10:
1417 case RATE_INFO_BW_20:
1421 bitrate = base[idx][rate->mcs];
1422 bitrate *= rate->nss;
1424 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1425 bitrate = (bitrate / 9) * 10;
1427 /* do NOT round down here */
1428 return (bitrate + 50000) / 100000;
1430 WARN_ONCE(1, "invalid rate bw=%d, mcs=%d, nss=%d\n",
1431 rate->bw, rate->mcs, rate->nss);
1435 static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
1438 u32 mcs_divisors[14] = {
1439 102399, /* 16.666666... */
1440 51201, /* 8.333333... */
1441 34134, /* 5.555555... */
1442 25599, /* 4.166666... */
1443 17067, /* 2.777777... */
1444 12801, /* 2.083333... */
1445 11377, /* 1.851725... */
1446 10239, /* 1.666666... */
1447 8532, /* 1.388888... */
1448 7680, /* 1.250000... */
1449 6828, /* 1.111111... */
1450 6144, /* 1.000000... */
1451 5690, /* 0.926106... */
1452 5120, /* 0.833333... */
1454 u32 rates_160M[3] = { 960777777, 907400000, 816666666 };
1455 u32 rates_969[3] = { 480388888, 453700000, 408333333 };
1456 u32 rates_484[3] = { 229411111, 216666666, 195000000 };
1457 u32 rates_242[3] = { 114711111, 108333333, 97500000 };
1458 u32 rates_106[3] = { 40000000, 37777777, 34000000 };
1459 u32 rates_52[3] = { 18820000, 17777777, 16000000 };
1460 u32 rates_26[3] = { 9411111, 8888888, 8000000 };
1464 if (WARN_ON_ONCE(rate->mcs > 13))
1467 if (WARN_ON_ONCE(rate->he_gi > NL80211_RATE_INFO_HE_GI_3_2))
1469 if (WARN_ON_ONCE(rate->he_ru_alloc >
1470 NL80211_RATE_INFO_HE_RU_ALLOC_2x996))
1472 if (WARN_ON_ONCE(rate->nss < 1 || rate->nss > 8))
1475 if (rate->bw == RATE_INFO_BW_160)
1476 result = rates_160M[rate->he_gi];
1477 else if (rate->bw == RATE_INFO_BW_80 ||
1478 (rate->bw == RATE_INFO_BW_HE_RU &&
1479 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_996))
1480 result = rates_969[rate->he_gi];
1481 else if (rate->bw == RATE_INFO_BW_40 ||
1482 (rate->bw == RATE_INFO_BW_HE_RU &&
1483 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_484))
1484 result = rates_484[rate->he_gi];
1485 else if (rate->bw == RATE_INFO_BW_20 ||
1486 (rate->bw == RATE_INFO_BW_HE_RU &&
1487 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_242))
1488 result = rates_242[rate->he_gi];
1489 else if (rate->bw == RATE_INFO_BW_HE_RU &&
1490 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_106)
1491 result = rates_106[rate->he_gi];
1492 else if (rate->bw == RATE_INFO_BW_HE_RU &&
1493 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_52)
1494 result = rates_52[rate->he_gi];
1495 else if (rate->bw == RATE_INFO_BW_HE_RU &&
1496 rate->he_ru_alloc == NL80211_RATE_INFO_HE_RU_ALLOC_26)
1497 result = rates_26[rate->he_gi];
1499 WARN(1, "invalid HE MCS: bw:%d, ru:%d\n",
1500 rate->bw, rate->he_ru_alloc);
1504 /* now scale to the appropriate MCS */
1507 do_div(tmp, mcs_divisors[rate->mcs]);
1510 /* and take NSS, DCM into account */
1511 result = (result * rate->nss) / 8;
1515 return result / 10000;
1518 static u32 cfg80211_calculate_bitrate_eht(struct rate_info *rate)
1521 static const u32 mcs_divisors[16] = {
1522 102399, /* 16.666666... */
1523 51201, /* 8.333333... */
1524 34134, /* 5.555555... */
1525 25599, /* 4.166666... */
1526 17067, /* 2.777777... */
1527 12801, /* 2.083333... */
1528 11377, /* 1.851725... */
1529 10239, /* 1.666666... */
1530 8532, /* 1.388888... */
1531 7680, /* 1.250000... */
1532 6828, /* 1.111111... */
1533 6144, /* 1.000000... */
1534 5690, /* 0.926106... */
1535 5120, /* 0.833333... */
1536 409600, /* 66.666666... */
1537 204800, /* 33.333333... */
1539 static const u32 rates_996[3] = { 480388888, 453700000, 408333333 };
1540 static const u32 rates_484[3] = { 229411111, 216666666, 195000000 };
1541 static const u32 rates_242[3] = { 114711111, 108333333, 97500000 };
1542 static const u32 rates_106[3] = { 40000000, 37777777, 34000000 };
1543 static const u32 rates_52[3] = { 18820000, 17777777, 16000000 };
1544 static const u32 rates_26[3] = { 9411111, 8888888, 8000000 };
1548 if (WARN_ON_ONCE(rate->mcs > 15))
1550 if (WARN_ON_ONCE(rate->eht_gi > NL80211_RATE_INFO_EHT_GI_3_2))
1552 if (WARN_ON_ONCE(rate->eht_ru_alloc >
1553 NL80211_RATE_INFO_EHT_RU_ALLOC_4x996))
1555 if (WARN_ON_ONCE(rate->nss < 1 || rate->nss > 8))
1558 /* Bandwidth checks for MCS 14 */
1559 if (rate->mcs == 14) {
1560 if ((rate->bw != RATE_INFO_BW_EHT_RU &&
1561 rate->bw != RATE_INFO_BW_80 &&
1562 rate->bw != RATE_INFO_BW_160 &&
1563 rate->bw != RATE_INFO_BW_320) ||
1564 (rate->bw == RATE_INFO_BW_EHT_RU &&
1565 rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_996 &&
1566 rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_2x996 &&
1567 rate->eht_ru_alloc != NL80211_RATE_INFO_EHT_RU_ALLOC_4x996)) {
1568 WARN(1, "invalid EHT BW for MCS 14: bw:%d, ru:%d\n",
1569 rate->bw, rate->eht_ru_alloc);
1574 if (rate->bw == RATE_INFO_BW_320 ||
1575 (rate->bw == RATE_INFO_BW_EHT_RU &&
1576 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_4x996))
1577 result = 4 * rates_996[rate->eht_gi];
1578 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1579 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484)
1580 result = 3 * rates_996[rate->eht_gi] + rates_484[rate->eht_gi];
1581 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1582 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_3x996)
1583 result = 3 * rates_996[rate->eht_gi];
1584 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1585 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484)
1586 result = 2 * rates_996[rate->eht_gi] + rates_484[rate->eht_gi];
1587 else if (rate->bw == RATE_INFO_BW_160 ||
1588 (rate->bw == RATE_INFO_BW_EHT_RU &&
1589 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_2x996))
1590 result = 2 * rates_996[rate->eht_gi];
1591 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1592 rate->eht_ru_alloc ==
1593 NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242)
1594 result = rates_996[rate->eht_gi] + rates_484[rate->eht_gi]
1595 + rates_242[rate->eht_gi];
1596 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1597 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_996P484)
1598 result = rates_996[rate->eht_gi] + rates_484[rate->eht_gi];
1599 else if (rate->bw == RATE_INFO_BW_80 ||
1600 (rate->bw == RATE_INFO_BW_EHT_RU &&
1601 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_996))
1602 result = rates_996[rate->eht_gi];
1603 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1604 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_484P242)
1605 result = rates_484[rate->eht_gi] + rates_242[rate->eht_gi];
1606 else if (rate->bw == RATE_INFO_BW_40 ||
1607 (rate->bw == RATE_INFO_BW_EHT_RU &&
1608 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_484))
1609 result = rates_484[rate->eht_gi];
1610 else if (rate->bw == RATE_INFO_BW_20 ||
1611 (rate->bw == RATE_INFO_BW_EHT_RU &&
1612 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_242))
1613 result = rates_242[rate->eht_gi];
1614 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1615 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_106P26)
1616 result = rates_106[rate->eht_gi] + rates_26[rate->eht_gi];
1617 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1618 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_106)
1619 result = rates_106[rate->eht_gi];
1620 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1621 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_52P26)
1622 result = rates_52[rate->eht_gi] + rates_26[rate->eht_gi];
1623 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1624 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_52)
1625 result = rates_52[rate->eht_gi];
1626 else if (rate->bw == RATE_INFO_BW_EHT_RU &&
1627 rate->eht_ru_alloc == NL80211_RATE_INFO_EHT_RU_ALLOC_26)
1628 result = rates_26[rate->eht_gi];
1630 WARN(1, "invalid EHT MCS: bw:%d, ru:%d\n",
1631 rate->bw, rate->eht_ru_alloc);
1635 /* now scale to the appropriate MCS */
1638 do_div(tmp, mcs_divisors[rate->mcs]);
1646 return result / 10000;
1649 u32 cfg80211_calculate_bitrate(struct rate_info *rate)
1651 if (rate->flags & RATE_INFO_FLAGS_MCS)
1652 return cfg80211_calculate_bitrate_ht(rate);
1653 if (rate->flags & RATE_INFO_FLAGS_DMG)
1654 return cfg80211_calculate_bitrate_dmg(rate);
1655 if (rate->flags & RATE_INFO_FLAGS_EXTENDED_SC_DMG)
1656 return cfg80211_calculate_bitrate_extended_sc_dmg(rate);
1657 if (rate->flags & RATE_INFO_FLAGS_EDMG)
1658 return cfg80211_calculate_bitrate_edmg(rate);
1659 if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
1660 return cfg80211_calculate_bitrate_vht(rate);
1661 if (rate->flags & RATE_INFO_FLAGS_HE_MCS)
1662 return cfg80211_calculate_bitrate_he(rate);
1663 if (rate->flags & RATE_INFO_FLAGS_EHT_MCS)
1664 return cfg80211_calculate_bitrate_eht(rate);
1666 return rate->legacy;
1668 EXPORT_SYMBOL(cfg80211_calculate_bitrate);
1670 int cfg80211_get_p2p_attr(const u8 *ies, unsigned int len,
1671 enum ieee80211_p2p_attr_id attr,
1672 u8 *buf, unsigned int bufsize)
1675 u16 attr_remaining = 0;
1676 bool desired_attr = false;
1677 u16 desired_len = 0;
1680 unsigned int iedatalen;
1687 if (iedatalen + 2 > len)
1690 if (ies[0] != WLAN_EID_VENDOR_SPECIFIC)
1698 /* check WFA OUI, P2P subtype */
1699 if (iedata[0] != 0x50 || iedata[1] != 0x6f ||
1700 iedata[2] != 0x9a || iedata[3] != 0x09)
1706 /* check attribute continuation into this IE */
1707 copy = min_t(unsigned int, attr_remaining, iedatalen);
1708 if (copy && desired_attr) {
1709 desired_len += copy;
1711 memcpy(out, iedata, min(bufsize, copy));
1712 out += min(bufsize, copy);
1713 bufsize -= min(bufsize, copy);
1717 if (copy == attr_remaining)
1721 attr_remaining -= copy;
1728 while (iedatalen > 0) {
1731 /* P2P attribute ID & size must fit */
1734 desired_attr = iedata[0] == attr;
1735 attr_len = get_unaligned_le16(iedata + 1);
1739 copy = min_t(unsigned int, attr_len, iedatalen);
1742 desired_len += copy;
1744 memcpy(out, iedata, min(bufsize, copy));
1745 out += min(bufsize, copy);
1746 bufsize -= min(bufsize, copy);
1749 if (copy == attr_len)
1755 attr_remaining = attr_len - copy;
1763 if (attr_remaining && desired_attr)
1768 EXPORT_SYMBOL(cfg80211_get_p2p_attr);
1770 static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id, bool id_ext)
1774 /* Make sure array values are legal */
1775 if (WARN_ON(ids[n_ids - 1] == WLAN_EID_EXTENSION))
1780 if (ids[i] == WLAN_EID_EXTENSION) {
1781 if (id_ext && (ids[i + 1] == id))
1788 if (ids[i] == id && !id_ext)
1796 static size_t skip_ie(const u8 *ies, size_t ielen, size_t pos)
1798 /* we assume a validly formed IEs buffer */
1799 u8 len = ies[pos + 1];
1803 /* the IE itself must have 255 bytes for fragments to follow */
1807 while (pos < ielen && ies[pos] == WLAN_EID_FRAGMENT) {
1815 size_t ieee80211_ie_split_ric(const u8 *ies, size_t ielen,
1816 const u8 *ids, int n_ids,
1817 const u8 *after_ric, int n_after_ric,
1820 size_t pos = offset;
1822 while (pos < ielen) {
1825 if (ies[pos] == WLAN_EID_EXTENSION)
1827 if ((pos + ext) >= ielen)
1830 if (!ieee80211_id_in_list(ids, n_ids, ies[pos + ext],
1831 ies[pos] == WLAN_EID_EXTENSION))
1834 if (ies[pos] == WLAN_EID_RIC_DATA && n_after_ric) {
1835 pos = skip_ie(ies, ielen, pos);
1837 while (pos < ielen) {
1838 if (ies[pos] == WLAN_EID_EXTENSION)
1843 if ((pos + ext) >= ielen)
1846 if (!ieee80211_id_in_list(after_ric,
1850 pos = skip_ie(ies, ielen, pos);
1855 pos = skip_ie(ies, ielen, pos);
1861 EXPORT_SYMBOL(ieee80211_ie_split_ric);
1863 bool ieee80211_operating_class_to_band(u8 operating_class,
1864 enum nl80211_band *band)
1866 switch (operating_class) {
1870 *band = NL80211_BAND_5GHZ;
1873 *band = NL80211_BAND_6GHZ;
1879 *band = NL80211_BAND_2GHZ;
1882 *band = NL80211_BAND_60GHZ;
1888 EXPORT_SYMBOL(ieee80211_operating_class_to_band);
1890 bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
1894 u32 freq = chandef->center_freq1;
1896 if (freq >= 2412 && freq <= 2472) {
1897 if (chandef->width > NL80211_CHAN_WIDTH_40)
1900 /* 2.407 GHz, channels 1..13 */
1901 if (chandef->width == NL80211_CHAN_WIDTH_40) {
1902 if (freq > chandef->chan->center_freq)
1903 *op_class = 83; /* HT40+ */
1905 *op_class = 84; /* HT40- */
1914 /* channel 14 is only for IEEE 802.11b */
1915 if (chandef->width != NL80211_CHAN_WIDTH_20_NOHT)
1918 *op_class = 82; /* channel 14 */
1922 switch (chandef->width) {
1923 case NL80211_CHAN_WIDTH_80:
1926 case NL80211_CHAN_WIDTH_160:
1929 case NL80211_CHAN_WIDTH_80P80:
1932 case NL80211_CHAN_WIDTH_10:
1933 case NL80211_CHAN_WIDTH_5:
1934 return false; /* unsupported for now */
1940 /* 5 GHz, channels 36..48 */
1941 if (freq >= 5180 && freq <= 5240) {
1943 *op_class = vht_opclass;
1944 } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
1945 if (freq > chandef->chan->center_freq)
1956 /* 5 GHz, channels 52..64 */
1957 if (freq >= 5260 && freq <= 5320) {
1959 *op_class = vht_opclass;
1960 } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
1961 if (freq > chandef->chan->center_freq)
1972 /* 5 GHz, channels 100..144 */
1973 if (freq >= 5500 && freq <= 5720) {
1975 *op_class = vht_opclass;
1976 } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
1977 if (freq > chandef->chan->center_freq)
1988 /* 5 GHz, channels 149..169 */
1989 if (freq >= 5745 && freq <= 5845) {
1991 *op_class = vht_opclass;
1992 } else if (chandef->width == NL80211_CHAN_WIDTH_40) {
1993 if (freq > chandef->chan->center_freq)
1997 } else if (freq <= 5805) {
2006 /* 56.16 GHz, channel 1..4 */
2007 if (freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 6) {
2008 if (chandef->width >= NL80211_CHAN_WIDTH_40)
2015 /* not supported yet */
2018 EXPORT_SYMBOL(ieee80211_chandef_to_operating_class);
2020 static int cfg80211_wdev_bi(struct wireless_dev *wdev)
2022 switch (wdev->iftype) {
2023 case NL80211_IFTYPE_AP:
2024 case NL80211_IFTYPE_P2P_GO:
2025 WARN_ON(wdev->valid_links);
2026 return wdev->links[0].ap.beacon_interval;
2027 case NL80211_IFTYPE_MESH_POINT:
2028 return wdev->u.mesh.beacon_interval;
2029 case NL80211_IFTYPE_ADHOC:
2030 return wdev->u.ibss.beacon_interval;
2038 static void cfg80211_calculate_bi_data(struct wiphy *wiphy, u32 new_beacon_int,
2039 u32 *beacon_int_gcd,
2040 bool *beacon_int_different)
2042 struct wireless_dev *wdev;
2044 *beacon_int_gcd = 0;
2045 *beacon_int_different = false;
2047 list_for_each_entry(wdev, &wiphy->wdev_list, list) {
2050 /* this feature isn't supported with MLO */
2051 if (wdev->valid_links)
2054 wdev_bi = cfg80211_wdev_bi(wdev);
2059 if (!*beacon_int_gcd) {
2060 *beacon_int_gcd = wdev_bi;
2064 if (wdev_bi == *beacon_int_gcd)
2067 *beacon_int_different = true;
2068 *beacon_int_gcd = gcd(*beacon_int_gcd, wdev_bi);
2071 if (new_beacon_int && *beacon_int_gcd != new_beacon_int) {
2072 if (*beacon_int_gcd)
2073 *beacon_int_different = true;
2074 *beacon_int_gcd = gcd(*beacon_int_gcd, new_beacon_int);
2078 int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
2079 enum nl80211_iftype iftype, u32 beacon_int)
2082 * This is just a basic pre-condition check; if interface combinations
2083 * are possible the driver must already be checking those with a call
2084 * to cfg80211_check_combinations(), in which case we'll validate more
2085 * through the cfg80211_calculate_bi_data() call and code in
2086 * cfg80211_iter_combinations().
2089 if (beacon_int < 10 || beacon_int > 10000)
2095 int cfg80211_iter_combinations(struct wiphy *wiphy,
2096 struct iface_combination_params *params,
2097 void (*iter)(const struct ieee80211_iface_combination *c,
2101 const struct ieee80211_regdomain *regdom;
2102 enum nl80211_dfs_regions region = 0;
2104 int num_interfaces = 0;
2105 u32 used_iftypes = 0;
2107 bool beacon_int_different;
2110 * This is a bit strange, since the iteration used to rely only on
2111 * the data given by the driver, but here it now relies on context,
2112 * in form of the currently operating interfaces.
2113 * This is OK for all current users, and saves us from having to
2114 * push the GCD calculations into all the drivers.
2115 * In the future, this should probably rely more on data that's in
2116 * cfg80211 already - the only thing not would appear to be any new
2117 * interfaces (while being brought up) and channel/radar data.
2119 cfg80211_calculate_bi_data(wiphy, params->new_beacon_int,
2120 &beacon_int_gcd, &beacon_int_different);
2122 if (params->radar_detect) {
2124 regdom = rcu_dereference(cfg80211_regdomain);
2126 region = regdom->dfs_region;
2130 for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
2131 num_interfaces += params->iftype_num[iftype];
2132 if (params->iftype_num[iftype] > 0 &&
2133 !cfg80211_iftype_allowed(wiphy, iftype, 0, 1))
2134 used_iftypes |= BIT(iftype);
2137 for (i = 0; i < wiphy->n_iface_combinations; i++) {
2138 const struct ieee80211_iface_combination *c;
2139 struct ieee80211_iface_limit *limits;
2140 u32 all_iftypes = 0;
2142 c = &wiphy->iface_combinations[i];
2144 if (num_interfaces > c->max_interfaces)
2146 if (params->num_different_channels > c->num_different_channels)
2149 limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
2154 for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
2155 if (cfg80211_iftype_allowed(wiphy, iftype, 0, 1))
2157 for (j = 0; j < c->n_limits; j++) {
2158 all_iftypes |= limits[j].types;
2159 if (!(limits[j].types & BIT(iftype)))
2161 if (limits[j].max < params->iftype_num[iftype])
2163 limits[j].max -= params->iftype_num[iftype];
2167 if (params->radar_detect !=
2168 (c->radar_detect_widths & params->radar_detect))
2171 if (params->radar_detect && c->radar_detect_regions &&
2172 !(c->radar_detect_regions & BIT(region)))
2175 /* Finally check that all iftypes that we're currently
2176 * using are actually part of this combination. If they
2177 * aren't then we can't use this combination and have
2178 * to continue to the next.
2180 if ((all_iftypes & used_iftypes) != used_iftypes)
2183 if (beacon_int_gcd) {
2184 if (c->beacon_int_min_gcd &&
2185 beacon_int_gcd < c->beacon_int_min_gcd)
2187 if (!c->beacon_int_min_gcd && beacon_int_different)
2191 /* This combination covered all interface types and
2192 * supported the requested numbers, so we're good.
2202 EXPORT_SYMBOL(cfg80211_iter_combinations);
2205 cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination *c,
2212 int cfg80211_check_combinations(struct wiphy *wiphy,
2213 struct iface_combination_params *params)
2217 err = cfg80211_iter_combinations(wiphy, params,
2218 cfg80211_iter_sum_ifcombs, &num);
2226 EXPORT_SYMBOL(cfg80211_check_combinations);
2228 int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
2229 const u8 *rates, unsigned int n_rates,
2237 if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES)
2242 for (i = 0; i < n_rates; i++) {
2243 int rate = (rates[i] & 0x7f) * 5;
2246 for (j = 0; j < sband->n_bitrates; j++) {
2247 if (sband->bitrates[j].bitrate == rate) {
2258 * mask must have at least one bit set here since we
2259 * didn't accept a 0-length rates array nor allowed
2260 * entries in the array that didn't exist
2266 unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy)
2268 enum nl80211_band band;
2269 unsigned int n_channels = 0;
2271 for (band = 0; band < NUM_NL80211_BANDS; band++)
2272 if (wiphy->bands[band])
2273 n_channels += wiphy->bands[band]->n_channels;
2277 EXPORT_SYMBOL(ieee80211_get_num_supported_channels);
2279 int cfg80211_get_station(struct net_device *dev, const u8 *mac_addr,
2280 struct station_info *sinfo)
2282 struct cfg80211_registered_device *rdev;
2283 struct wireless_dev *wdev;
2285 wdev = dev->ieee80211_ptr;
2289 rdev = wiphy_to_rdev(wdev->wiphy);
2290 if (!rdev->ops->get_station)
2293 memset(sinfo, 0, sizeof(*sinfo));
2295 return rdev_get_station(rdev, dev, mac_addr, sinfo);
2297 EXPORT_SYMBOL(cfg80211_get_station);
2299 void cfg80211_free_nan_func(struct cfg80211_nan_func *f)
2306 kfree(f->serv_spec_info);
2309 for (i = 0; i < f->num_rx_filters; i++)
2310 kfree(f->rx_filters[i].filter);
2312 for (i = 0; i < f->num_tx_filters; i++)
2313 kfree(f->tx_filters[i].filter);
2315 kfree(f->rx_filters);
2316 kfree(f->tx_filters);
2319 EXPORT_SYMBOL(cfg80211_free_nan_func);
2321 bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range,
2322 u32 center_freq_khz, u32 bw_khz)
2324 u32 start_freq_khz, end_freq_khz;
2326 start_freq_khz = center_freq_khz - (bw_khz / 2);
2327 end_freq_khz = center_freq_khz + (bw_khz / 2);
2329 if (start_freq_khz >= freq_range->start_freq_khz &&
2330 end_freq_khz <= freq_range->end_freq_khz)
2336 int cfg80211_sinfo_alloc_tid_stats(struct station_info *sinfo, gfp_t gfp)
2338 sinfo->pertid = kcalloc(IEEE80211_NUM_TIDS + 1,
2339 sizeof(*(sinfo->pertid)),
2346 EXPORT_SYMBOL(cfg80211_sinfo_alloc_tid_stats);
2348 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
2349 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
2350 const unsigned char rfc1042_header[] __aligned(2) =
2351 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
2352 EXPORT_SYMBOL(rfc1042_header);
2354 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
2355 const unsigned char bridge_tunnel_header[] __aligned(2) =
2356 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
2357 EXPORT_SYMBOL(bridge_tunnel_header);
2359 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
2360 struct iapp_layer2_update {
2361 u8 da[ETH_ALEN]; /* broadcast */
2362 u8 sa[ETH_ALEN]; /* STA addr */
2370 void cfg80211_send_layer2_update(struct net_device *dev, const u8 *addr)
2372 struct iapp_layer2_update *msg;
2373 struct sk_buff *skb;
2375 /* Send Level 2 Update Frame to update forwarding tables in layer 2
2378 skb = dev_alloc_skb(sizeof(*msg));
2381 msg = skb_put(skb, sizeof(*msg));
2383 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
2384 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
2386 eth_broadcast_addr(msg->da);
2387 ether_addr_copy(msg->sa, addr);
2388 msg->len = htons(6);
2390 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
2391 msg->control = 0xaf; /* XID response lsb.1111F101.
2392 * F=0 (no poll command; unsolicited frame) */
2393 msg->xid_info[0] = 0x81; /* XID format identifier */
2394 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
2395 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
2398 skb->protocol = eth_type_trans(skb, dev);
2399 memset(skb->cb, 0, sizeof(skb->cb));
2402 EXPORT_SYMBOL(cfg80211_send_layer2_update);
2404 int ieee80211_get_vht_max_nss(struct ieee80211_vht_cap *cap,
2405 enum ieee80211_vht_chanwidth bw,
2406 int mcs, bool ext_nss_bw_capable,
2407 unsigned int max_vht_nss)
2409 u16 map = le16_to_cpu(cap->supp_mcs.rx_mcs_map);
2412 int i, mcs_encoding;
2417 if (WARN_ON(mcs > 9 || max_vht_nss > 8))
2427 /* find max_vht_nss for the given MCS */
2428 for (i = 7; i >= 0; i--) {
2429 int supp = (map >> (2 * i)) & 3;
2434 if (supp >= mcs_encoding) {
2435 max_vht_nss = i + 1;
2441 if (!(cap->supp_mcs.tx_mcs_map &
2442 cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE)))
2445 ext_nss_bw = le32_get_bits(cap->vht_cap_info,
2446 IEEE80211_VHT_CAP_EXT_NSS_BW_MASK);
2447 supp_width = le32_get_bits(cap->vht_cap_info,
2448 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK);
2450 /* if not capable, treat ext_nss_bw as 0 */
2451 if (!ext_nss_bw_capable)
2454 /* This is invalid */
2455 if (supp_width == 3)
2458 /* This is an invalid combination so pretend nothing is supported */
2459 if (supp_width == 2 && (ext_nss_bw == 1 || ext_nss_bw == 2))
2463 * Cover all the special cases according to IEEE 802.11-2016
2464 * Table 9-250. All other cases are either factor of 1 or not
2468 case IEEE80211_VHT_CHANWIDTH_USE_HT:
2469 case IEEE80211_VHT_CHANWIDTH_80MHZ:
2470 if ((supp_width == 1 || supp_width == 2) &&
2472 return 2 * max_vht_nss;
2474 case IEEE80211_VHT_CHANWIDTH_160MHZ:
2475 if (supp_width == 0 &&
2476 (ext_nss_bw == 1 || ext_nss_bw == 2))
2477 return max_vht_nss / 2;
2478 if (supp_width == 0 &&
2480 return (3 * max_vht_nss) / 4;
2481 if (supp_width == 1 &&
2483 return 2 * max_vht_nss;
2485 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
2486 if (supp_width == 0 && ext_nss_bw == 1)
2487 return 0; /* not possible */
2488 if (supp_width == 0 &&
2490 return max_vht_nss / 2;
2491 if (supp_width == 0 &&
2493 return (3 * max_vht_nss) / 4;
2494 if (supp_width == 1 &&
2496 return 0; /* not possible */
2497 if (supp_width == 1 &&
2499 return max_vht_nss / 2;
2500 if (supp_width == 1 &&
2502 return (3 * max_vht_nss) / 4;
2506 /* not covered or invalid combination received */
2509 EXPORT_SYMBOL(ieee80211_get_vht_max_nss);
2511 bool cfg80211_iftype_allowed(struct wiphy *wiphy, enum nl80211_iftype iftype,
2512 bool is_4addr, u8 check_swif)
2515 bool is_vlan = iftype == NL80211_IFTYPE_AP_VLAN;
2517 switch (check_swif) {
2519 if (is_vlan && is_4addr)
2520 return wiphy->flags & WIPHY_FLAG_4ADDR_AP;
2521 return wiphy->interface_modes & BIT(iftype);
2523 if (!(wiphy->software_iftypes & BIT(iftype)) && is_vlan)
2524 return wiphy->flags & WIPHY_FLAG_4ADDR_AP;
2525 return wiphy->software_iftypes & BIT(iftype);
2532 EXPORT_SYMBOL(cfg80211_iftype_allowed);
2534 void cfg80211_remove_link(struct wireless_dev *wdev, unsigned int link_id)
2536 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
2538 ASSERT_WDEV_LOCK(wdev);
2540 switch (wdev->iftype) {
2541 case NL80211_IFTYPE_AP:
2542 case NL80211_IFTYPE_P2P_GO:
2543 __cfg80211_stop_ap(rdev, wdev->netdev, link_id, true);
2546 /* per-link not relevant */
2550 wdev->valid_links &= ~BIT(link_id);
2552 rdev_del_intf_link(rdev, wdev, link_id);
2554 eth_zero_addr(wdev->links[link_id].addr);
2557 void cfg80211_remove_links(struct wireless_dev *wdev)
2559 unsigned int link_id;
2562 if (wdev->valid_links) {
2563 for_each_valid_link(wdev, link_id)
2564 cfg80211_remove_link(wdev, link_id);
2569 int cfg80211_remove_virtual_intf(struct cfg80211_registered_device *rdev,
2570 struct wireless_dev *wdev)
2572 cfg80211_remove_links(wdev);
2574 return rdev_del_virtual_intf(rdev, wdev);
2577 const struct wiphy_iftype_ext_capab *
2578 cfg80211_get_iftype_ext_capa(struct wiphy *wiphy, enum nl80211_iftype type)
2582 for (i = 0; i < wiphy->num_iftype_ext_capab; i++) {
2583 if (wiphy->iftype_ext_capab[i].iftype == type)
2584 return &wiphy->iftype_ext_capab[i];
2589 EXPORT_SYMBOL(cfg80211_get_iftype_ext_capa);