1 // SPDX-License-Identifier: GPL-2.0
3 * Wireless utility functions
5 * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 #include <linux/export.h>
9 #include <linux/bitops.h>
10 #include <linux/etherdevice.h>
11 #include <linux/slab.h>
12 #include <net/cfg80211.h>
14 #include <net/dsfield.h>
15 #include <linux/if_vlan.h>
16 #include <linux/mpls.h>
17 #include <linux/gcd.h>
22 struct ieee80211_rate
*
23 ieee80211_get_response_rate(struct ieee80211_supported_band
*sband
,
24 u32 basic_rates
, int bitrate
)
26 struct ieee80211_rate
*result
= &sband
->bitrates
[0];
29 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
30 if (!(basic_rates
& BIT(i
)))
32 if (sband
->bitrates
[i
].bitrate
> bitrate
)
34 result
= &sband
->bitrates
[i
];
39 EXPORT_SYMBOL(ieee80211_get_response_rate
);
41 u32
ieee80211_mandatory_rates(struct ieee80211_supported_band
*sband
,
42 enum nl80211_bss_scan_width scan_width
)
44 struct ieee80211_rate
*bitrates
;
45 u32 mandatory_rates
= 0;
46 enum ieee80211_rate_flags mandatory_flag
;
52 if (sband
->band
== NL80211_BAND_2GHZ
) {
53 if (scan_width
== NL80211_BSS_CHAN_WIDTH_5
||
54 scan_width
== NL80211_BSS_CHAN_WIDTH_10
)
55 mandatory_flag
= IEEE80211_RATE_MANDATORY_G
;
57 mandatory_flag
= IEEE80211_RATE_MANDATORY_B
;
59 mandatory_flag
= IEEE80211_RATE_MANDATORY_A
;
62 bitrates
= sband
->bitrates
;
63 for (i
= 0; i
< sband
->n_bitrates
; i
++)
64 if (bitrates
[i
].flags
& mandatory_flag
)
65 mandatory_rates
|= BIT(i
);
66 return mandatory_rates
;
68 EXPORT_SYMBOL(ieee80211_mandatory_rates
);
70 int ieee80211_channel_to_frequency(int chan
, enum nl80211_band band
)
72 /* see 802.11 17.3.8.3.2 and Annex J
73 * there are overlapping channel numbers in 5GHz and 2GHz bands */
75 return 0; /* not supported */
77 case NL80211_BAND_2GHZ
:
81 return 2407 + chan
* 5;
83 case NL80211_BAND_5GHZ
:
84 if (chan
>= 182 && chan
<= 196)
85 return 4000 + chan
* 5;
87 return 5000 + chan
* 5;
89 case NL80211_BAND_60GHZ
:
91 return 56160 + chan
* 2160;
96 return 0; /* not supported */
98 EXPORT_SYMBOL(ieee80211_channel_to_frequency
);
100 int ieee80211_frequency_to_channel(int freq
)
102 /* see 802.11 17.3.8.3.2 and Annex J */
105 else if (freq
< 2484)
106 return (freq
- 2407) / 5;
107 else if (freq
>= 4910 && freq
<= 4980)
108 return (freq
- 4000) / 5;
109 else if (freq
<= 45000) /* DMG band lower limit */
110 return (freq
- 5000) / 5;
111 else if (freq
>= 58320 && freq
<= 64800)
112 return (freq
- 56160) / 2160;
116 EXPORT_SYMBOL(ieee80211_frequency_to_channel
);
118 struct ieee80211_channel
*ieee80211_get_channel(struct wiphy
*wiphy
, int freq
)
120 enum nl80211_band band
;
121 struct ieee80211_supported_band
*sband
;
124 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
125 sband
= wiphy
->bands
[band
];
130 for (i
= 0; i
< sband
->n_channels
; i
++) {
131 if (sband
->channels
[i
].center_freq
== freq
)
132 return &sband
->channels
[i
];
138 EXPORT_SYMBOL(ieee80211_get_channel
);
140 static void set_mandatory_flags_band(struct ieee80211_supported_band
*sband
)
144 switch (sband
->band
) {
145 case NL80211_BAND_5GHZ
:
147 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
148 if (sband
->bitrates
[i
].bitrate
== 60 ||
149 sband
->bitrates
[i
].bitrate
== 120 ||
150 sband
->bitrates
[i
].bitrate
== 240) {
151 sband
->bitrates
[i
].flags
|=
152 IEEE80211_RATE_MANDATORY_A
;
158 case NL80211_BAND_2GHZ
:
160 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
161 if (sband
->bitrates
[i
].bitrate
== 10) {
162 sband
->bitrates
[i
].flags
|=
163 IEEE80211_RATE_MANDATORY_B
|
164 IEEE80211_RATE_MANDATORY_G
;
168 if (sband
->bitrates
[i
].bitrate
== 20 ||
169 sband
->bitrates
[i
].bitrate
== 55 ||
170 sband
->bitrates
[i
].bitrate
== 110 ||
171 sband
->bitrates
[i
].bitrate
== 60 ||
172 sband
->bitrates
[i
].bitrate
== 120 ||
173 sband
->bitrates
[i
].bitrate
== 240) {
174 sband
->bitrates
[i
].flags
|=
175 IEEE80211_RATE_MANDATORY_G
;
179 if (sband
->bitrates
[i
].bitrate
!= 10 &&
180 sband
->bitrates
[i
].bitrate
!= 20 &&
181 sband
->bitrates
[i
].bitrate
!= 55 &&
182 sband
->bitrates
[i
].bitrate
!= 110)
183 sband
->bitrates
[i
].flags
|=
184 IEEE80211_RATE_ERP_G
;
186 WARN_ON(want
!= 0 && want
!= 3 && want
!= 6);
188 case NL80211_BAND_60GHZ
:
189 /* check for mandatory HT MCS 1..4 */
190 WARN_ON(!sband
->ht_cap
.ht_supported
);
191 WARN_ON((sband
->ht_cap
.mcs
.rx_mask
[0] & 0x1e) != 0x1e);
193 case NUM_NL80211_BANDS
:
200 void ieee80211_set_bitrate_flags(struct wiphy
*wiphy
)
202 enum nl80211_band band
;
204 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++)
205 if (wiphy
->bands
[band
])
206 set_mandatory_flags_band(wiphy
->bands
[band
]);
209 bool cfg80211_supported_cipher_suite(struct wiphy
*wiphy
, u32 cipher
)
212 for (i
= 0; i
< wiphy
->n_cipher_suites
; i
++)
213 if (cipher
== wiphy
->cipher_suites
[i
])
218 int cfg80211_validate_key_settings(struct cfg80211_registered_device
*rdev
,
219 struct key_params
*params
, int key_idx
,
220 bool pairwise
, const u8
*mac_addr
)
222 if (key_idx
< 0 || key_idx
> 5)
225 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
228 if (pairwise
&& !mac_addr
)
231 switch (params
->cipher
) {
232 case WLAN_CIPHER_SUITE_TKIP
:
233 case WLAN_CIPHER_SUITE_CCMP
:
234 case WLAN_CIPHER_SUITE_CCMP_256
:
235 case WLAN_CIPHER_SUITE_GCMP
:
236 case WLAN_CIPHER_SUITE_GCMP_256
:
237 /* Disallow pairwise keys with non-zero index unless it's WEP
238 * or a vendor specific cipher (because current deployments use
239 * pairwise WEP keys with non-zero indices and for vendor
240 * specific ciphers this should be validated in the driver or
241 * hardware level - but 802.11i clearly specifies to use zero)
243 if (pairwise
&& key_idx
)
246 case WLAN_CIPHER_SUITE_AES_CMAC
:
247 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
248 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
249 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
250 /* Disallow BIP (group-only) cipher as pairwise cipher */
256 case WLAN_CIPHER_SUITE_WEP40
:
257 case WLAN_CIPHER_SUITE_WEP104
:
264 switch (params
->cipher
) {
265 case WLAN_CIPHER_SUITE_WEP40
:
266 if (params
->key_len
!= WLAN_KEY_LEN_WEP40
)
269 case WLAN_CIPHER_SUITE_TKIP
:
270 if (params
->key_len
!= WLAN_KEY_LEN_TKIP
)
273 case WLAN_CIPHER_SUITE_CCMP
:
274 if (params
->key_len
!= WLAN_KEY_LEN_CCMP
)
277 case WLAN_CIPHER_SUITE_CCMP_256
:
278 if (params
->key_len
!= WLAN_KEY_LEN_CCMP_256
)
281 case WLAN_CIPHER_SUITE_GCMP
:
282 if (params
->key_len
!= WLAN_KEY_LEN_GCMP
)
285 case WLAN_CIPHER_SUITE_GCMP_256
:
286 if (params
->key_len
!= WLAN_KEY_LEN_GCMP_256
)
289 case WLAN_CIPHER_SUITE_WEP104
:
290 if (params
->key_len
!= WLAN_KEY_LEN_WEP104
)
293 case WLAN_CIPHER_SUITE_AES_CMAC
:
294 if (params
->key_len
!= WLAN_KEY_LEN_AES_CMAC
)
297 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
298 if (params
->key_len
!= WLAN_KEY_LEN_BIP_CMAC_256
)
301 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
302 if (params
->key_len
!= WLAN_KEY_LEN_BIP_GMAC_128
)
305 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
306 if (params
->key_len
!= WLAN_KEY_LEN_BIP_GMAC_256
)
311 * We don't know anything about this algorithm,
312 * allow using it -- but the driver must check
313 * all parameters! We still check below whether
314 * or not the driver supports this algorithm,
321 switch (params
->cipher
) {
322 case WLAN_CIPHER_SUITE_WEP40
:
323 case WLAN_CIPHER_SUITE_WEP104
:
324 /* These ciphers do not use key sequence */
326 case WLAN_CIPHER_SUITE_TKIP
:
327 case WLAN_CIPHER_SUITE_CCMP
:
328 case WLAN_CIPHER_SUITE_CCMP_256
:
329 case WLAN_CIPHER_SUITE_GCMP
:
330 case WLAN_CIPHER_SUITE_GCMP_256
:
331 case WLAN_CIPHER_SUITE_AES_CMAC
:
332 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
333 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
334 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
335 if (params
->seq_len
!= 6)
341 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
, params
->cipher
))
347 unsigned int __attribute_const__
ieee80211_hdrlen(__le16 fc
)
349 unsigned int hdrlen
= 24;
351 if (ieee80211_is_data(fc
)) {
352 if (ieee80211_has_a4(fc
))
354 if (ieee80211_is_data_qos(fc
)) {
355 hdrlen
+= IEEE80211_QOS_CTL_LEN
;
356 if (ieee80211_has_order(fc
))
357 hdrlen
+= IEEE80211_HT_CTL_LEN
;
362 if (ieee80211_is_mgmt(fc
)) {
363 if (ieee80211_has_order(fc
))
364 hdrlen
+= IEEE80211_HT_CTL_LEN
;
368 if (ieee80211_is_ctl(fc
)) {
370 * ACK and CTS are 10 bytes, all others 16. To see how
371 * to get this condition consider
372 * subtype mask: 0b0000000011110000 (0x00F0)
373 * ACK subtype: 0b0000000011010000 (0x00D0)
374 * CTS subtype: 0b0000000011000000 (0x00C0)
375 * bits that matter: ^^^ (0x00E0)
376 * value of those: 0b0000000011000000 (0x00C0)
378 if ((fc
& cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
386 EXPORT_SYMBOL(ieee80211_hdrlen
);
388 unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff
*skb
)
390 const struct ieee80211_hdr
*hdr
=
391 (const struct ieee80211_hdr
*)skb
->data
;
394 if (unlikely(skb
->len
< 10))
396 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
397 if (unlikely(hdrlen
> skb
->len
))
401 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb
);
403 static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags
)
405 int ae
= flags
& MESH_FLAGS_AE
;
406 /* 802.11-2012, 8.2.4.7.3 */
411 case MESH_FLAGS_AE_A4
:
413 case MESH_FLAGS_AE_A5_A6
:
418 unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr
*meshhdr
)
420 return __ieee80211_get_mesh_hdrlen(meshhdr
->flags
);
422 EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen
);
424 int ieee80211_data_to_8023_exthdr(struct sk_buff
*skb
, struct ethhdr
*ehdr
,
425 const u8
*addr
, enum nl80211_iftype iftype
)
427 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
429 u8 hdr
[ETH_ALEN
] __aligned(2);
436 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
439 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
440 if (skb
->len
< hdrlen
+ 8)
443 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
445 * IEEE 802.11 address fields:
446 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
447 * 0 0 DA SA BSSID n/a
448 * 0 1 DA BSSID SA n/a
449 * 1 0 BSSID SA DA n/a
452 memcpy(tmp
.h_dest
, ieee80211_get_DA(hdr
), ETH_ALEN
);
453 memcpy(tmp
.h_source
, ieee80211_get_SA(hdr
), ETH_ALEN
);
455 if (iftype
== NL80211_IFTYPE_MESH_POINT
)
456 skb_copy_bits(skb
, hdrlen
, &mesh_flags
, 1);
458 mesh_flags
&= MESH_FLAGS_AE
;
460 switch (hdr
->frame_control
&
461 cpu_to_le16(IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
462 case cpu_to_le16(IEEE80211_FCTL_TODS
):
463 if (unlikely(iftype
!= NL80211_IFTYPE_AP
&&
464 iftype
!= NL80211_IFTYPE_AP_VLAN
&&
465 iftype
!= NL80211_IFTYPE_P2P_GO
))
468 case cpu_to_le16(IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
469 if (unlikely(iftype
!= NL80211_IFTYPE_WDS
&&
470 iftype
!= NL80211_IFTYPE_MESH_POINT
&&
471 iftype
!= NL80211_IFTYPE_AP_VLAN
&&
472 iftype
!= NL80211_IFTYPE_STATION
))
474 if (iftype
== NL80211_IFTYPE_MESH_POINT
) {
475 if (mesh_flags
== MESH_FLAGS_AE_A4
)
477 if (mesh_flags
== MESH_FLAGS_AE_A5_A6
) {
478 skb_copy_bits(skb
, hdrlen
+
479 offsetof(struct ieee80211s_hdr
, eaddr1
),
480 tmp
.h_dest
, 2 * ETH_ALEN
);
482 hdrlen
+= __ieee80211_get_mesh_hdrlen(mesh_flags
);
485 case cpu_to_le16(IEEE80211_FCTL_FROMDS
):
486 if ((iftype
!= NL80211_IFTYPE_STATION
&&
487 iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
488 iftype
!= NL80211_IFTYPE_MESH_POINT
) ||
489 (is_multicast_ether_addr(tmp
.h_dest
) &&
490 ether_addr_equal(tmp
.h_source
, addr
)))
492 if (iftype
== NL80211_IFTYPE_MESH_POINT
) {
493 if (mesh_flags
== MESH_FLAGS_AE_A5_A6
)
495 if (mesh_flags
== MESH_FLAGS_AE_A4
)
496 skb_copy_bits(skb
, hdrlen
+
497 offsetof(struct ieee80211s_hdr
, eaddr1
),
498 tmp
.h_source
, ETH_ALEN
);
499 hdrlen
+= __ieee80211_get_mesh_hdrlen(mesh_flags
);
503 if (iftype
!= NL80211_IFTYPE_ADHOC
&&
504 iftype
!= NL80211_IFTYPE_STATION
&&
505 iftype
!= NL80211_IFTYPE_OCB
)
510 skb_copy_bits(skb
, hdrlen
, &payload
, sizeof(payload
));
511 tmp
.h_proto
= payload
.proto
;
513 if (likely((ether_addr_equal(payload
.hdr
, rfc1042_header
) &&
514 tmp
.h_proto
!= htons(ETH_P_AARP
) &&
515 tmp
.h_proto
!= htons(ETH_P_IPX
)) ||
516 ether_addr_equal(payload
.hdr
, bridge_tunnel_header
)))
517 /* remove RFC1042 or Bridge-Tunnel encapsulation and
518 * replace EtherType */
519 hdrlen
+= ETH_ALEN
+ 2;
521 tmp
.h_proto
= htons(skb
->len
- hdrlen
);
523 pskb_pull(skb
, hdrlen
);
526 ehdr
= skb_push(skb
, sizeof(struct ethhdr
));
527 memcpy(ehdr
, &tmp
, sizeof(tmp
));
531 EXPORT_SYMBOL(ieee80211_data_to_8023_exthdr
);
533 int ieee80211_data_from_8023(struct sk_buff
*skb
, const u8
*addr
,
534 enum nl80211_iftype iftype
,
535 const u8
*bssid
, bool qos
)
537 struct ieee80211_hdr hdr
;
538 u16 hdrlen
, ethertype
;
540 const u8
*encaps_data
;
541 int encaps_len
, skip_header_bytes
;
545 if (unlikely(skb
->len
< ETH_HLEN
))
548 nh_pos
= skb_network_header(skb
) - skb
->data
;
549 h_pos
= skb_transport_header(skb
) - skb
->data
;
551 /* convert Ethernet header to proper 802.11 header (based on
553 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
554 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
557 case NL80211_IFTYPE_AP
:
558 case NL80211_IFTYPE_AP_VLAN
:
559 case NL80211_IFTYPE_P2P_GO
:
560 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
562 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
563 memcpy(hdr
.addr2
, addr
, ETH_ALEN
);
564 memcpy(hdr
.addr3
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
567 case NL80211_IFTYPE_STATION
:
568 case NL80211_IFTYPE_P2P_CLIENT
:
569 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
571 memcpy(hdr
.addr1
, bssid
, ETH_ALEN
);
572 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
573 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
576 case NL80211_IFTYPE_OCB
:
577 case NL80211_IFTYPE_ADHOC
:
579 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
580 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
581 memcpy(hdr
.addr3
, bssid
, ETH_ALEN
);
589 fc
|= cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
593 hdr
.frame_control
= fc
;
597 skip_header_bytes
= ETH_HLEN
;
598 if (ethertype
== ETH_P_AARP
|| ethertype
== ETH_P_IPX
) {
599 encaps_data
= bridge_tunnel_header
;
600 encaps_len
= sizeof(bridge_tunnel_header
);
601 skip_header_bytes
-= 2;
602 } else if (ethertype
>= ETH_P_802_3_MIN
) {
603 encaps_data
= rfc1042_header
;
604 encaps_len
= sizeof(rfc1042_header
);
605 skip_header_bytes
-= 2;
611 skb_pull(skb
, skip_header_bytes
);
612 nh_pos
-= skip_header_bytes
;
613 h_pos
-= skip_header_bytes
;
615 head_need
= hdrlen
+ encaps_len
- skb_headroom(skb
);
617 if (head_need
> 0 || skb_cloned(skb
)) {
618 head_need
= max(head_need
, 0);
622 if (pskb_expand_head(skb
, head_need
, 0, GFP_ATOMIC
))
627 memcpy(skb_push(skb
, encaps_len
), encaps_data
, encaps_len
);
628 nh_pos
+= encaps_len
;
632 memcpy(skb_push(skb
, hdrlen
), &hdr
, hdrlen
);
637 /* Update skb pointers to various headers since this modified frame
638 * is going to go through Linux networking code that may potentially
639 * need things like pointer to IP header. */
640 skb_reset_mac_header(skb
);
641 skb_set_network_header(skb
, nh_pos
);
642 skb_set_transport_header(skb
, h_pos
);
646 EXPORT_SYMBOL(ieee80211_data_from_8023
);
649 __frame_add_frag(struct sk_buff
*skb
, struct page
*page
,
650 void *ptr
, int len
, int size
)
652 struct skb_shared_info
*sh
= skb_shinfo(skb
);
656 page_offset
= ptr
- page_address(page
);
657 skb_add_rx_frag(skb
, sh
->nr_frags
, page
, page_offset
, len
, size
);
661 __ieee80211_amsdu_copy_frag(struct sk_buff
*skb
, struct sk_buff
*frame
,
664 struct skb_shared_info
*sh
= skb_shinfo(skb
);
665 const skb_frag_t
*frag
= &sh
->frags
[0];
666 struct page
*frag_page
;
668 int frag_len
, frag_size
;
669 int head_size
= skb
->len
- skb
->data_len
;
672 frag_page
= virt_to_head_page(skb
->head
);
673 frag_ptr
= skb
->data
;
674 frag_size
= head_size
;
676 while (offset
>= frag_size
) {
678 frag_page
= skb_frag_page(frag
);
679 frag_ptr
= skb_frag_address(frag
);
680 frag_size
= skb_frag_size(frag
);
685 frag_len
= frag_size
- offset
;
687 cur_len
= min(len
, frag_len
);
689 __frame_add_frag(frame
, frag_page
, frag_ptr
, cur_len
, frag_size
);
693 frag_len
= skb_frag_size(frag
);
694 cur_len
= min(len
, frag_len
);
695 __frame_add_frag(frame
, skb_frag_page(frag
),
696 skb_frag_address(frag
), cur_len
, frag_len
);
702 static struct sk_buff
*
703 __ieee80211_amsdu_copy(struct sk_buff
*skb
, unsigned int hlen
,
704 int offset
, int len
, bool reuse_frag
)
706 struct sk_buff
*frame
;
709 if (skb
->len
- offset
< len
)
713 * When reusing framents, copy some data to the head to simplify
714 * ethernet header handling and speed up protocol header processing
715 * in the stack later.
718 cur_len
= min_t(int, len
, 32);
721 * Allocate and reserve two bytes more for payload
722 * alignment since sizeof(struct ethhdr) is 14.
724 frame
= dev_alloc_skb(hlen
+ sizeof(struct ethhdr
) + 2 + cur_len
);
728 skb_reserve(frame
, hlen
+ sizeof(struct ethhdr
) + 2);
729 skb_copy_bits(skb
, offset
, skb_put(frame
, cur_len
), cur_len
);
736 __ieee80211_amsdu_copy_frag(skb
, frame
, offset
, len
);
741 void ieee80211_amsdu_to_8023s(struct sk_buff
*skb
, struct sk_buff_head
*list
,
742 const u8
*addr
, enum nl80211_iftype iftype
,
743 const unsigned int extra_headroom
,
744 const u8
*check_da
, const u8
*check_sa
)
746 unsigned int hlen
= ALIGN(extra_headroom
, 4);
747 struct sk_buff
*frame
= NULL
;
750 int offset
= 0, remaining
;
752 bool reuse_frag
= skb
->head_frag
&& !skb_has_frag_list(skb
);
753 bool reuse_skb
= false;
757 unsigned int subframe_len
;
761 skb_copy_bits(skb
, offset
, ð
, sizeof(eth
));
762 len
= ntohs(eth
.h_proto
);
763 subframe_len
= sizeof(struct ethhdr
) + len
;
764 padding
= (4 - subframe_len
) & 0x3;
766 /* the last MSDU has no padding */
767 remaining
= skb
->len
- offset
;
768 if (subframe_len
> remaining
)
771 offset
+= sizeof(struct ethhdr
);
772 last
= remaining
<= subframe_len
+ padding
;
774 /* FIXME: should we really accept multicast DA? */
775 if ((check_da
&& !is_multicast_ether_addr(eth
.h_dest
) &&
776 !ether_addr_equal(check_da
, eth
.h_dest
)) ||
777 (check_sa
&& !ether_addr_equal(check_sa
, eth
.h_source
))) {
778 offset
+= len
+ padding
;
782 /* reuse skb for the last subframe */
783 if (!skb_is_nonlinear(skb
) && !reuse_frag
&& last
) {
784 skb_pull(skb
, offset
);
788 frame
= __ieee80211_amsdu_copy(skb
, hlen
, offset
, len
,
793 offset
+= len
+ padding
;
796 skb_reset_network_header(frame
);
797 frame
->dev
= skb
->dev
;
798 frame
->priority
= skb
->priority
;
800 payload
= frame
->data
;
801 ethertype
= (payload
[6] << 8) | payload
[7];
802 if (likely((ether_addr_equal(payload
, rfc1042_header
) &&
803 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
804 ether_addr_equal(payload
, bridge_tunnel_header
))) {
805 eth
.h_proto
= htons(ethertype
);
806 skb_pull(frame
, ETH_ALEN
+ 2);
809 memcpy(skb_push(frame
, sizeof(eth
)), ð
, sizeof(eth
));
810 __skb_queue_tail(list
, frame
);
819 __skb_queue_purge(list
);
822 EXPORT_SYMBOL(ieee80211_amsdu_to_8023s
);
824 /* Given a data frame determine the 802.1p/1d tag to use. */
825 unsigned int cfg80211_classify8021d(struct sk_buff
*skb
,
826 struct cfg80211_qos_map
*qos_map
)
829 unsigned char vlan_priority
;
831 /* skb->priority values from 256->263 are magic values to
832 * directly indicate a specific 802.1d priority. This is used
833 * to allow 802.1d priority to be passed directly in from VLAN
836 if (skb
->priority
>= 256 && skb
->priority
<= 263)
837 return skb
->priority
- 256;
839 if (skb_vlan_tag_present(skb
)) {
840 vlan_priority
= (skb_vlan_tag_get(skb
) & VLAN_PRIO_MASK
)
842 if (vlan_priority
> 0)
843 return vlan_priority
;
846 switch (skb
->protocol
) {
847 case htons(ETH_P_IP
):
848 dscp
= ipv4_get_dsfield(ip_hdr(skb
)) & 0xfc;
850 case htons(ETH_P_IPV6
):
851 dscp
= ipv6_get_dsfield(ipv6_hdr(skb
)) & 0xfc;
853 case htons(ETH_P_MPLS_UC
):
854 case htons(ETH_P_MPLS_MC
): {
855 struct mpls_label mpls_tmp
, *mpls
;
857 mpls
= skb_header_pointer(skb
, sizeof(struct ethhdr
),
858 sizeof(*mpls
), &mpls_tmp
);
862 return (ntohl(mpls
->entry
) & MPLS_LS_TC_MASK
)
865 case htons(ETH_P_80221
):
866 /* 802.21 is always network control traffic */
873 unsigned int i
, tmp_dscp
= dscp
>> 2;
875 for (i
= 0; i
< qos_map
->num_des
; i
++) {
876 if (tmp_dscp
== qos_map
->dscp_exception
[i
].dscp
)
877 return qos_map
->dscp_exception
[i
].up
;
880 for (i
= 0; i
< 8; i
++) {
881 if (tmp_dscp
>= qos_map
->up
[i
].low
&&
882 tmp_dscp
<= qos_map
->up
[i
].high
)
889 EXPORT_SYMBOL(cfg80211_classify8021d
);
891 const u8
*ieee80211_bss_get_ie(struct cfg80211_bss
*bss
, u8 ie
)
893 const struct cfg80211_bss_ies
*ies
;
895 ies
= rcu_dereference(bss
->ies
);
899 return cfg80211_find_ie(ie
, ies
->data
, ies
->len
);
901 EXPORT_SYMBOL(ieee80211_bss_get_ie
);
903 void cfg80211_upload_connect_keys(struct wireless_dev
*wdev
)
905 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
906 struct net_device
*dev
= wdev
->netdev
;
909 if (!wdev
->connect_keys
)
912 for (i
= 0; i
< CFG80211_MAX_WEP_KEYS
; i
++) {
913 if (!wdev
->connect_keys
->params
[i
].cipher
)
915 if (rdev_add_key(rdev
, dev
, i
, false, NULL
,
916 &wdev
->connect_keys
->params
[i
])) {
917 netdev_err(dev
, "failed to set key %d\n", i
);
920 if (wdev
->connect_keys
->def
== i
&&
921 rdev_set_default_key(rdev
, dev
, i
, true, true)) {
922 netdev_err(dev
, "failed to set defkey %d\n", i
);
927 kzfree(wdev
->connect_keys
);
928 wdev
->connect_keys
= NULL
;
931 void cfg80211_process_wdev_events(struct wireless_dev
*wdev
)
933 struct cfg80211_event
*ev
;
936 spin_lock_irqsave(&wdev
->event_lock
, flags
);
937 while (!list_empty(&wdev
->event_list
)) {
938 ev
= list_first_entry(&wdev
->event_list
,
939 struct cfg80211_event
, list
);
941 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
945 case EVENT_CONNECT_RESULT
:
946 __cfg80211_connect_result(
949 ev
->cr
.status
== WLAN_STATUS_SUCCESS
);
952 __cfg80211_roamed(wdev
, &ev
->rm
);
954 case EVENT_DISCONNECTED
:
955 __cfg80211_disconnected(wdev
->netdev
,
956 ev
->dc
.ie
, ev
->dc
.ie_len
,
958 !ev
->dc
.locally_generated
);
960 case EVENT_IBSS_JOINED
:
961 __cfg80211_ibss_joined(wdev
->netdev
, ev
->ij
.bssid
,
965 __cfg80211_leave(wiphy_to_rdev(wdev
->wiphy
), wdev
);
972 spin_lock_irqsave(&wdev
->event_lock
, flags
);
974 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
977 void cfg80211_process_rdev_events(struct cfg80211_registered_device
*rdev
)
979 struct wireless_dev
*wdev
;
983 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
)
984 cfg80211_process_wdev_events(wdev
);
987 int cfg80211_change_iface(struct cfg80211_registered_device
*rdev
,
988 struct net_device
*dev
, enum nl80211_iftype ntype
,
989 struct vif_params
*params
)
992 enum nl80211_iftype otype
= dev
->ieee80211_ptr
->iftype
;
996 /* don't support changing VLANs, you just re-create them */
997 if (otype
== NL80211_IFTYPE_AP_VLAN
)
1000 /* cannot change into P2P device or NAN */
1001 if (ntype
== NL80211_IFTYPE_P2P_DEVICE
||
1002 ntype
== NL80211_IFTYPE_NAN
)
1005 if (!rdev
->ops
->change_virtual_intf
||
1006 !(rdev
->wiphy
.interface_modes
& (1 << ntype
)))
1009 /* if it's part of a bridge, reject changing type to station/ibss */
1010 if ((dev
->priv_flags
& IFF_BRIDGE_PORT
) &&
1011 (ntype
== NL80211_IFTYPE_ADHOC
||
1012 ntype
== NL80211_IFTYPE_STATION
||
1013 ntype
== NL80211_IFTYPE_P2P_CLIENT
))
1016 if (ntype
!= otype
) {
1017 dev
->ieee80211_ptr
->use_4addr
= false;
1018 dev
->ieee80211_ptr
->mesh_id_up_len
= 0;
1019 wdev_lock(dev
->ieee80211_ptr
);
1020 rdev_set_qos_map(rdev
, dev
, NULL
);
1021 wdev_unlock(dev
->ieee80211_ptr
);
1024 case NL80211_IFTYPE_AP
:
1025 cfg80211_stop_ap(rdev
, dev
, true);
1027 case NL80211_IFTYPE_ADHOC
:
1028 cfg80211_leave_ibss(rdev
, dev
, false);
1030 case NL80211_IFTYPE_STATION
:
1031 case NL80211_IFTYPE_P2P_CLIENT
:
1032 wdev_lock(dev
->ieee80211_ptr
);
1033 cfg80211_disconnect(rdev
, dev
,
1034 WLAN_REASON_DEAUTH_LEAVING
, true);
1035 wdev_unlock(dev
->ieee80211_ptr
);
1037 case NL80211_IFTYPE_MESH_POINT
:
1038 /* mesh should be handled? */
1044 cfg80211_process_rdev_events(rdev
);
1047 err
= rdev_change_virtual_intf(rdev
, dev
, ntype
, params
);
1049 WARN_ON(!err
&& dev
->ieee80211_ptr
->iftype
!= ntype
);
1051 if (!err
&& params
&& params
->use_4addr
!= -1)
1052 dev
->ieee80211_ptr
->use_4addr
= params
->use_4addr
;
1055 dev
->priv_flags
&= ~IFF_DONT_BRIDGE
;
1057 case NL80211_IFTYPE_STATION
:
1058 if (dev
->ieee80211_ptr
->use_4addr
)
1061 case NL80211_IFTYPE_OCB
:
1062 case NL80211_IFTYPE_P2P_CLIENT
:
1063 case NL80211_IFTYPE_ADHOC
:
1064 dev
->priv_flags
|= IFF_DONT_BRIDGE
;
1066 case NL80211_IFTYPE_P2P_GO
:
1067 case NL80211_IFTYPE_AP
:
1068 case NL80211_IFTYPE_AP_VLAN
:
1069 case NL80211_IFTYPE_WDS
:
1070 case NL80211_IFTYPE_MESH_POINT
:
1073 case NL80211_IFTYPE_MONITOR
:
1074 /* monitor can't bridge anyway */
1076 case NL80211_IFTYPE_UNSPECIFIED
:
1077 case NUM_NL80211_IFTYPES
:
1080 case NL80211_IFTYPE_P2P_DEVICE
:
1081 case NL80211_IFTYPE_NAN
:
1087 if (!err
&& ntype
!= otype
&& netif_running(dev
)) {
1088 cfg80211_update_iface_num(rdev
, ntype
, 1);
1089 cfg80211_update_iface_num(rdev
, otype
, -1);
1095 static u32
cfg80211_calculate_bitrate_ht(struct rate_info
*rate
)
1097 int modulation
, streams
, bitrate
;
1099 /* the formula below does only work for MCS values smaller than 32 */
1100 if (WARN_ON_ONCE(rate
->mcs
>= 32))
1103 modulation
= rate
->mcs
& 7;
1104 streams
= (rate
->mcs
>> 3) + 1;
1106 bitrate
= (rate
->bw
== RATE_INFO_BW_40
) ? 13500000 : 6500000;
1109 bitrate
*= (modulation
+ 1);
1110 else if (modulation
== 4)
1111 bitrate
*= (modulation
+ 2);
1113 bitrate
*= (modulation
+ 3);
1117 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1118 bitrate
= (bitrate
/ 9) * 10;
1120 /* do NOT round down here */
1121 return (bitrate
+ 50000) / 100000;
1124 static u32
cfg80211_calculate_bitrate_60g(struct rate_info
*rate
)
1126 static const u32 __mcs2bitrate
[] = {
1134 [5] = 12512, /* 1251.25 mbps */
1144 [14] = 8662, /* 866.25 mbps */
1154 [24] = 67568, /* 6756.75 mbps */
1165 if (WARN_ON_ONCE(rate
->mcs
>= ARRAY_SIZE(__mcs2bitrate
)))
1168 return __mcs2bitrate
[rate
->mcs
];
1171 static u32
cfg80211_calculate_bitrate_vht(struct rate_info
*rate
)
1173 static const u32 base
[4][10] = {
1183 /* not in the spec, but some devices use this: */
1227 case RATE_INFO_BW_160
:
1230 case RATE_INFO_BW_80
:
1233 case RATE_INFO_BW_40
:
1236 case RATE_INFO_BW_5
:
1237 case RATE_INFO_BW_10
:
1240 case RATE_INFO_BW_20
:
1244 bitrate
= base
[idx
][rate
->mcs
];
1245 bitrate
*= rate
->nss
;
1247 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1248 bitrate
= (bitrate
/ 9) * 10;
1250 /* do NOT round down here */
1251 return (bitrate
+ 50000) / 100000;
1253 WARN_ONCE(1, "invalid rate bw=%d, mcs=%d, nss=%d\n",
1254 rate
->bw
, rate
->mcs
, rate
->nss
);
1258 u32
cfg80211_calculate_bitrate(struct rate_info
*rate
)
1260 if (rate
->flags
& RATE_INFO_FLAGS_MCS
)
1261 return cfg80211_calculate_bitrate_ht(rate
);
1262 if (rate
->flags
& RATE_INFO_FLAGS_60G
)
1263 return cfg80211_calculate_bitrate_60g(rate
);
1264 if (rate
->flags
& RATE_INFO_FLAGS_VHT_MCS
)
1265 return cfg80211_calculate_bitrate_vht(rate
);
1267 return rate
->legacy
;
1269 EXPORT_SYMBOL(cfg80211_calculate_bitrate
);
1271 int cfg80211_get_p2p_attr(const u8
*ies
, unsigned int len
,
1272 enum ieee80211_p2p_attr_id attr
,
1273 u8
*buf
, unsigned int bufsize
)
1276 u16 attr_remaining
= 0;
1277 bool desired_attr
= false;
1278 u16 desired_len
= 0;
1281 unsigned int iedatalen
;
1288 if (iedatalen
+ 2 > len
)
1291 if (ies
[0] != WLAN_EID_VENDOR_SPECIFIC
)
1299 /* check WFA OUI, P2P subtype */
1300 if (iedata
[0] != 0x50 || iedata
[1] != 0x6f ||
1301 iedata
[2] != 0x9a || iedata
[3] != 0x09)
1307 /* check attribute continuation into this IE */
1308 copy
= min_t(unsigned int, attr_remaining
, iedatalen
);
1309 if (copy
&& desired_attr
) {
1310 desired_len
+= copy
;
1312 memcpy(out
, iedata
, min(bufsize
, copy
));
1313 out
+= min(bufsize
, copy
);
1314 bufsize
-= min(bufsize
, copy
);
1318 if (copy
== attr_remaining
)
1322 attr_remaining
-= copy
;
1329 while (iedatalen
> 0) {
1332 /* P2P attribute ID & size must fit */
1335 desired_attr
= iedata
[0] == attr
;
1336 attr_len
= get_unaligned_le16(iedata
+ 1);
1340 copy
= min_t(unsigned int, attr_len
, iedatalen
);
1343 desired_len
+= copy
;
1345 memcpy(out
, iedata
, min(bufsize
, copy
));
1346 out
+= min(bufsize
, copy
);
1347 bufsize
-= min(bufsize
, copy
);
1350 if (copy
== attr_len
)
1356 attr_remaining
= attr_len
- copy
;
1364 if (attr_remaining
&& desired_attr
)
1369 EXPORT_SYMBOL(cfg80211_get_p2p_attr
);
1371 static bool ieee80211_id_in_list(const u8
*ids
, int n_ids
, u8 id
)
1375 for (i
= 0; i
< n_ids
; i
++)
1381 static size_t skip_ie(const u8
*ies
, size_t ielen
, size_t pos
)
1383 /* we assume a validly formed IEs buffer */
1384 u8 len
= ies
[pos
+ 1];
1388 /* the IE itself must have 255 bytes for fragments to follow */
1392 while (pos
< ielen
&& ies
[pos
] == WLAN_EID_FRAGMENT
) {
1400 size_t ieee80211_ie_split_ric(const u8
*ies
, size_t ielen
,
1401 const u8
*ids
, int n_ids
,
1402 const u8
*after_ric
, int n_after_ric
,
1405 size_t pos
= offset
;
1407 while (pos
< ielen
&& ieee80211_id_in_list(ids
, n_ids
, ies
[pos
])) {
1408 if (ies
[pos
] == WLAN_EID_RIC_DATA
&& n_after_ric
) {
1409 pos
= skip_ie(ies
, ielen
, pos
);
1411 while (pos
< ielen
&&
1412 !ieee80211_id_in_list(after_ric
, n_after_ric
,
1414 pos
= skip_ie(ies
, ielen
, pos
);
1416 pos
= skip_ie(ies
, ielen
, pos
);
1422 EXPORT_SYMBOL(ieee80211_ie_split_ric
);
1424 bool ieee80211_operating_class_to_band(u8 operating_class
,
1425 enum nl80211_band
*band
)
1427 switch (operating_class
) {
1431 *band
= NL80211_BAND_5GHZ
;
1437 *band
= NL80211_BAND_2GHZ
;
1440 *band
= NL80211_BAND_60GHZ
;
1446 EXPORT_SYMBOL(ieee80211_operating_class_to_band
);
1448 bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def
*chandef
,
1452 u16 freq
= chandef
->center_freq1
;
1454 if (freq
>= 2412 && freq
<= 2472) {
1455 if (chandef
->width
> NL80211_CHAN_WIDTH_40
)
1458 /* 2.407 GHz, channels 1..13 */
1459 if (chandef
->width
== NL80211_CHAN_WIDTH_40
) {
1460 if (freq
> chandef
->chan
->center_freq
)
1461 *op_class
= 83; /* HT40+ */
1463 *op_class
= 84; /* HT40- */
1472 if (chandef
->width
> NL80211_CHAN_WIDTH_40
)
1475 *op_class
= 82; /* channel 14 */
1479 switch (chandef
->width
) {
1480 case NL80211_CHAN_WIDTH_80
:
1483 case NL80211_CHAN_WIDTH_160
:
1486 case NL80211_CHAN_WIDTH_80P80
:
1489 case NL80211_CHAN_WIDTH_10
:
1490 case NL80211_CHAN_WIDTH_5
:
1491 return false; /* unsupported for now */
1497 /* 5 GHz, channels 36..48 */
1498 if (freq
>= 5180 && freq
<= 5240) {
1500 *op_class
= vht_opclass
;
1501 } else if (chandef
->width
== NL80211_CHAN_WIDTH_40
) {
1502 if (freq
> chandef
->chan
->center_freq
)
1513 /* 5 GHz, channels 52..64 */
1514 if (freq
>= 5260 && freq
<= 5320) {
1516 *op_class
= vht_opclass
;
1517 } else if (chandef
->width
== NL80211_CHAN_WIDTH_40
) {
1518 if (freq
> chandef
->chan
->center_freq
)
1529 /* 5 GHz, channels 100..144 */
1530 if (freq
>= 5500 && freq
<= 5720) {
1532 *op_class
= vht_opclass
;
1533 } else if (chandef
->width
== NL80211_CHAN_WIDTH_40
) {
1534 if (freq
> chandef
->chan
->center_freq
)
1545 /* 5 GHz, channels 149..169 */
1546 if (freq
>= 5745 && freq
<= 5845) {
1548 *op_class
= vht_opclass
;
1549 } else if (chandef
->width
== NL80211_CHAN_WIDTH_40
) {
1550 if (freq
> chandef
->chan
->center_freq
)
1554 } else if (freq
<= 5805) {
1563 /* 56.16 GHz, channel 1..4 */
1564 if (freq
>= 56160 + 2160 * 1 && freq
<= 56160 + 2160 * 4) {
1565 if (chandef
->width
>= NL80211_CHAN_WIDTH_40
)
1572 /* not supported yet */
1575 EXPORT_SYMBOL(ieee80211_chandef_to_operating_class
);
1577 static void cfg80211_calculate_bi_data(struct wiphy
*wiphy
, u32 new_beacon_int
,
1578 u32
*beacon_int_gcd
,
1579 bool *beacon_int_different
)
1581 struct wireless_dev
*wdev
;
1583 *beacon_int_gcd
= 0;
1584 *beacon_int_different
= false;
1586 list_for_each_entry(wdev
, &wiphy
->wdev_list
, list
) {
1587 if (!wdev
->beacon_interval
)
1590 if (!*beacon_int_gcd
) {
1591 *beacon_int_gcd
= wdev
->beacon_interval
;
1595 if (wdev
->beacon_interval
== *beacon_int_gcd
)
1598 *beacon_int_different
= true;
1599 *beacon_int_gcd
= gcd(*beacon_int_gcd
, wdev
->beacon_interval
);
1602 if (new_beacon_int
&& *beacon_int_gcd
!= new_beacon_int
) {
1603 if (*beacon_int_gcd
)
1604 *beacon_int_different
= true;
1605 *beacon_int_gcd
= gcd(*beacon_int_gcd
, new_beacon_int
);
1609 int cfg80211_validate_beacon_int(struct cfg80211_registered_device
*rdev
,
1610 enum nl80211_iftype iftype
, u32 beacon_int
)
1613 * This is just a basic pre-condition check; if interface combinations
1614 * are possible the driver must already be checking those with a call
1615 * to cfg80211_check_combinations(), in which case we'll validate more
1616 * through the cfg80211_calculate_bi_data() call and code in
1617 * cfg80211_iter_combinations().
1620 if (beacon_int
< 10 || beacon_int
> 10000)
1626 int cfg80211_iter_combinations(struct wiphy
*wiphy
,
1627 struct iface_combination_params
*params
,
1628 void (*iter
)(const struct ieee80211_iface_combination
*c
,
1632 const struct ieee80211_regdomain
*regdom
;
1633 enum nl80211_dfs_regions region
= 0;
1635 int num_interfaces
= 0;
1636 u32 used_iftypes
= 0;
1638 bool beacon_int_different
;
1641 * This is a bit strange, since the iteration used to rely only on
1642 * the data given by the driver, but here it now relies on context,
1643 * in form of the currently operating interfaces.
1644 * This is OK for all current users, and saves us from having to
1645 * push the GCD calculations into all the drivers.
1646 * In the future, this should probably rely more on data that's in
1647 * cfg80211 already - the only thing not would appear to be any new
1648 * interfaces (while being brought up) and channel/radar data.
1650 cfg80211_calculate_bi_data(wiphy
, params
->new_beacon_int
,
1651 &beacon_int_gcd
, &beacon_int_different
);
1653 if (params
->radar_detect
) {
1655 regdom
= rcu_dereference(cfg80211_regdomain
);
1657 region
= regdom
->dfs_region
;
1661 for (iftype
= 0; iftype
< NUM_NL80211_IFTYPES
; iftype
++) {
1662 num_interfaces
+= params
->iftype_num
[iftype
];
1663 if (params
->iftype_num
[iftype
] > 0 &&
1664 !(wiphy
->software_iftypes
& BIT(iftype
)))
1665 used_iftypes
|= BIT(iftype
);
1668 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
1669 const struct ieee80211_iface_combination
*c
;
1670 struct ieee80211_iface_limit
*limits
;
1671 u32 all_iftypes
= 0;
1673 c
= &wiphy
->iface_combinations
[i
];
1675 if (num_interfaces
> c
->max_interfaces
)
1677 if (params
->num_different_channels
> c
->num_different_channels
)
1680 limits
= kmemdup(c
->limits
, sizeof(limits
[0]) * c
->n_limits
,
1685 for (iftype
= 0; iftype
< NUM_NL80211_IFTYPES
; iftype
++) {
1686 if (wiphy
->software_iftypes
& BIT(iftype
))
1688 for (j
= 0; j
< c
->n_limits
; j
++) {
1689 all_iftypes
|= limits
[j
].types
;
1690 if (!(limits
[j
].types
& BIT(iftype
)))
1692 if (limits
[j
].max
< params
->iftype_num
[iftype
])
1694 limits
[j
].max
-= params
->iftype_num
[iftype
];
1698 if (params
->radar_detect
!=
1699 (c
->radar_detect_widths
& params
->radar_detect
))
1702 if (params
->radar_detect
&& c
->radar_detect_regions
&&
1703 !(c
->radar_detect_regions
& BIT(region
)))
1706 /* Finally check that all iftypes that we're currently
1707 * using are actually part of this combination. If they
1708 * aren't then we can't use this combination and have
1709 * to continue to the next.
1711 if ((all_iftypes
& used_iftypes
) != used_iftypes
)
1714 if (beacon_int_gcd
) {
1715 if (c
->beacon_int_min_gcd
&&
1716 beacon_int_gcd
< c
->beacon_int_min_gcd
)
1718 if (!c
->beacon_int_min_gcd
&& beacon_int_different
)
1722 /* This combination covered all interface types and
1723 * supported the requested numbers, so we're good.
1733 EXPORT_SYMBOL(cfg80211_iter_combinations
);
1736 cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination
*c
,
1743 int cfg80211_check_combinations(struct wiphy
*wiphy
,
1744 struct iface_combination_params
*params
)
1748 err
= cfg80211_iter_combinations(wiphy
, params
,
1749 cfg80211_iter_sum_ifcombs
, &num
);
1757 EXPORT_SYMBOL(cfg80211_check_combinations
);
1759 int ieee80211_get_ratemask(struct ieee80211_supported_band
*sband
,
1760 const u8
*rates
, unsigned int n_rates
,
1768 if (n_rates
== 0 || n_rates
> NL80211_MAX_SUPP_RATES
)
1773 for (i
= 0; i
< n_rates
; i
++) {
1774 int rate
= (rates
[i
] & 0x7f) * 5;
1777 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1778 if (sband
->bitrates
[j
].bitrate
== rate
) {
1789 * mask must have at least one bit set here since we
1790 * didn't accept a 0-length rates array nor allowed
1791 * entries in the array that didn't exist
1797 unsigned int ieee80211_get_num_supported_channels(struct wiphy
*wiphy
)
1799 enum nl80211_band band
;
1800 unsigned int n_channels
= 0;
1802 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++)
1803 if (wiphy
->bands
[band
])
1804 n_channels
+= wiphy
->bands
[band
]->n_channels
;
1808 EXPORT_SYMBOL(ieee80211_get_num_supported_channels
);
1810 int cfg80211_get_station(struct net_device
*dev
, const u8
*mac_addr
,
1811 struct station_info
*sinfo
)
1813 struct cfg80211_registered_device
*rdev
;
1814 struct wireless_dev
*wdev
;
1816 wdev
= dev
->ieee80211_ptr
;
1820 rdev
= wiphy_to_rdev(wdev
->wiphy
);
1821 if (!rdev
->ops
->get_station
)
1824 return rdev_get_station(rdev
, dev
, mac_addr
, sinfo
);
1826 EXPORT_SYMBOL(cfg80211_get_station
);
1828 void cfg80211_free_nan_func(struct cfg80211_nan_func
*f
)
1835 kfree(f
->serv_spec_info
);
1838 for (i
= 0; i
< f
->num_rx_filters
; i
++)
1839 kfree(f
->rx_filters
[i
].filter
);
1841 for (i
= 0; i
< f
->num_tx_filters
; i
++)
1842 kfree(f
->tx_filters
[i
].filter
);
1844 kfree(f
->rx_filters
);
1845 kfree(f
->tx_filters
);
1848 EXPORT_SYMBOL(cfg80211_free_nan_func
);
1850 bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range
*freq_range
,
1851 u32 center_freq_khz
, u32 bw_khz
)
1853 u32 start_freq_khz
, end_freq_khz
;
1855 start_freq_khz
= center_freq_khz
- (bw_khz
/ 2);
1856 end_freq_khz
= center_freq_khz
+ (bw_khz
/ 2);
1858 if (start_freq_khz
>= freq_range
->start_freq_khz
&&
1859 end_freq_khz
<= freq_range
->end_freq_khz
)
1865 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
1866 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
1867 const unsigned char rfc1042_header
[] __aligned(2) =
1868 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1869 EXPORT_SYMBOL(rfc1042_header
);
1871 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
1872 const unsigned char bridge_tunnel_header
[] __aligned(2) =
1873 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
1874 EXPORT_SYMBOL(bridge_tunnel_header
);