2 * Wireless utility functions
4 * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
6 #include <linux/export.h>
7 #include <linux/bitops.h>
8 #include <linux/etherdevice.h>
9 #include <linux/slab.h>
10 #include <net/cfg80211.h>
14 struct ieee80211_rate
*
15 ieee80211_get_response_rate(struct ieee80211_supported_band
*sband
,
16 u32 basic_rates
, int bitrate
)
18 struct ieee80211_rate
*result
= &sband
->bitrates
[0];
21 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
22 if (!(basic_rates
& BIT(i
)))
24 if (sband
->bitrates
[i
].bitrate
> bitrate
)
26 result
= &sband
->bitrates
[i
];
31 EXPORT_SYMBOL(ieee80211_get_response_rate
);
33 int ieee80211_channel_to_frequency(int chan
, enum ieee80211_band band
)
35 /* see 802.11 17.3.8.3.2 and Annex J
36 * there are overlapping channel numbers in 5GHz and 2GHz bands */
37 if (band
== IEEE80211_BAND_5GHZ
) {
38 if (chan
>= 182 && chan
<= 196)
39 return 4000 + chan
* 5;
41 return 5000 + chan
* 5;
42 } else { /* IEEE80211_BAND_2GHZ */
46 return 2407 + chan
* 5;
48 return 0; /* not supported */
51 EXPORT_SYMBOL(ieee80211_channel_to_frequency
);
53 int ieee80211_frequency_to_channel(int freq
)
55 /* see 802.11 17.3.8.3.2 and Annex J */
59 return (freq
- 2407) / 5;
60 else if (freq
>= 4910 && freq
<= 4980)
61 return (freq
- 4000) / 5;
63 return (freq
- 5000) / 5;
65 EXPORT_SYMBOL(ieee80211_frequency_to_channel
);
67 struct ieee80211_channel
*__ieee80211_get_channel(struct wiphy
*wiphy
,
70 enum ieee80211_band band
;
71 struct ieee80211_supported_band
*sband
;
74 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
75 sband
= wiphy
->bands
[band
];
80 for (i
= 0; i
< sband
->n_channels
; i
++) {
81 if (sband
->channels
[i
].center_freq
== freq
)
82 return &sband
->channels
[i
];
88 EXPORT_SYMBOL(__ieee80211_get_channel
);
90 static void set_mandatory_flags_band(struct ieee80211_supported_band
*sband
,
91 enum ieee80211_band band
)
96 case IEEE80211_BAND_5GHZ
:
98 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
99 if (sband
->bitrates
[i
].bitrate
== 60 ||
100 sband
->bitrates
[i
].bitrate
== 120 ||
101 sband
->bitrates
[i
].bitrate
== 240) {
102 sband
->bitrates
[i
].flags
|=
103 IEEE80211_RATE_MANDATORY_A
;
109 case IEEE80211_BAND_2GHZ
:
111 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
112 if (sband
->bitrates
[i
].bitrate
== 10) {
113 sband
->bitrates
[i
].flags
|=
114 IEEE80211_RATE_MANDATORY_B
|
115 IEEE80211_RATE_MANDATORY_G
;
119 if (sband
->bitrates
[i
].bitrate
== 20 ||
120 sband
->bitrates
[i
].bitrate
== 55 ||
121 sband
->bitrates
[i
].bitrate
== 110 ||
122 sband
->bitrates
[i
].bitrate
== 60 ||
123 sband
->bitrates
[i
].bitrate
== 120 ||
124 sband
->bitrates
[i
].bitrate
== 240) {
125 sband
->bitrates
[i
].flags
|=
126 IEEE80211_RATE_MANDATORY_G
;
130 if (sband
->bitrates
[i
].bitrate
!= 10 &&
131 sband
->bitrates
[i
].bitrate
!= 20 &&
132 sband
->bitrates
[i
].bitrate
!= 55 &&
133 sband
->bitrates
[i
].bitrate
!= 110)
134 sband
->bitrates
[i
].flags
|=
135 IEEE80211_RATE_ERP_G
;
137 WARN_ON(want
!= 0 && want
!= 3 && want
!= 6);
139 case IEEE80211_NUM_BANDS
:
145 void ieee80211_set_bitrate_flags(struct wiphy
*wiphy
)
147 enum ieee80211_band band
;
149 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
150 if (wiphy
->bands
[band
])
151 set_mandatory_flags_band(wiphy
->bands
[band
], band
);
154 bool cfg80211_supported_cipher_suite(struct wiphy
*wiphy
, u32 cipher
)
157 for (i
= 0; i
< wiphy
->n_cipher_suites
; i
++)
158 if (cipher
== wiphy
->cipher_suites
[i
])
163 int cfg80211_validate_key_settings(struct cfg80211_registered_device
*rdev
,
164 struct key_params
*params
, int key_idx
,
165 bool pairwise
, const u8
*mac_addr
)
170 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
173 if (pairwise
&& !mac_addr
)
177 * Disallow pairwise keys with non-zero index unless it's WEP
178 * or a vendor specific cipher (because current deployments use
179 * pairwise WEP keys with non-zero indices and for vendor specific
180 * ciphers this should be validated in the driver or hardware level
181 * - but 802.11i clearly specifies to use zero)
183 if (pairwise
&& key_idx
&&
184 ((params
->cipher
== WLAN_CIPHER_SUITE_TKIP
) ||
185 (params
->cipher
== WLAN_CIPHER_SUITE_CCMP
) ||
186 (params
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)))
189 switch (params
->cipher
) {
190 case WLAN_CIPHER_SUITE_WEP40
:
191 if (params
->key_len
!= WLAN_KEY_LEN_WEP40
)
194 case WLAN_CIPHER_SUITE_TKIP
:
195 if (params
->key_len
!= WLAN_KEY_LEN_TKIP
)
198 case WLAN_CIPHER_SUITE_CCMP
:
199 if (params
->key_len
!= WLAN_KEY_LEN_CCMP
)
202 case WLAN_CIPHER_SUITE_WEP104
:
203 if (params
->key_len
!= WLAN_KEY_LEN_WEP104
)
206 case WLAN_CIPHER_SUITE_AES_CMAC
:
207 if (params
->key_len
!= WLAN_KEY_LEN_AES_CMAC
)
212 * We don't know anything about this algorithm,
213 * allow using it -- but the driver must check
214 * all parameters! We still check below whether
215 * or not the driver supports this algorithm,
222 switch (params
->cipher
) {
223 case WLAN_CIPHER_SUITE_WEP40
:
224 case WLAN_CIPHER_SUITE_WEP104
:
225 /* These ciphers do not use key sequence */
227 case WLAN_CIPHER_SUITE_TKIP
:
228 case WLAN_CIPHER_SUITE_CCMP
:
229 case WLAN_CIPHER_SUITE_AES_CMAC
:
230 if (params
->seq_len
!= 6)
236 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
, params
->cipher
))
242 unsigned int __attribute_const__
ieee80211_hdrlen(__le16 fc
)
244 unsigned int hdrlen
= 24;
246 if (ieee80211_is_data(fc
)) {
247 if (ieee80211_has_a4(fc
))
249 if (ieee80211_is_data_qos(fc
)) {
250 hdrlen
+= IEEE80211_QOS_CTL_LEN
;
251 if (ieee80211_has_order(fc
))
252 hdrlen
+= IEEE80211_HT_CTL_LEN
;
257 if (ieee80211_is_ctl(fc
)) {
259 * ACK and CTS are 10 bytes, all others 16. To see how
260 * to get this condition consider
261 * subtype mask: 0b0000000011110000 (0x00F0)
262 * ACK subtype: 0b0000000011010000 (0x00D0)
263 * CTS subtype: 0b0000000011000000 (0x00C0)
264 * bits that matter: ^^^ (0x00E0)
265 * value of those: 0b0000000011000000 (0x00C0)
267 if ((fc
& cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
275 EXPORT_SYMBOL(ieee80211_hdrlen
);
277 unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff
*skb
)
279 const struct ieee80211_hdr
*hdr
=
280 (const struct ieee80211_hdr
*)skb
->data
;
283 if (unlikely(skb
->len
< 10))
285 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
286 if (unlikely(hdrlen
> skb
->len
))
290 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb
);
292 static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr
*meshhdr
)
294 int ae
= meshhdr
->flags
& MESH_FLAGS_AE
;
299 case MESH_FLAGS_AE_A4
:
301 case MESH_FLAGS_AE_A5_A6
:
303 case (MESH_FLAGS_AE_A4
| MESH_FLAGS_AE_A5_A6
):
310 int ieee80211_data_to_8023(struct sk_buff
*skb
, const u8
*addr
,
311 enum nl80211_iftype iftype
)
313 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
314 u16 hdrlen
, ethertype
;
317 u8 src
[ETH_ALEN
] __aligned(2);
319 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
322 hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
324 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
326 * IEEE 802.11 address fields:
327 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
328 * 0 0 DA SA BSSID n/a
329 * 0 1 DA BSSID SA n/a
330 * 1 0 BSSID SA DA n/a
333 memcpy(dst
, ieee80211_get_DA(hdr
), ETH_ALEN
);
334 memcpy(src
, ieee80211_get_SA(hdr
), ETH_ALEN
);
336 switch (hdr
->frame_control
&
337 cpu_to_le16(IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
)) {
338 case cpu_to_le16(IEEE80211_FCTL_TODS
):
339 if (unlikely(iftype
!= NL80211_IFTYPE_AP
&&
340 iftype
!= NL80211_IFTYPE_AP_VLAN
&&
341 iftype
!= NL80211_IFTYPE_P2P_GO
))
344 case cpu_to_le16(IEEE80211_FCTL_TODS
| IEEE80211_FCTL_FROMDS
):
345 if (unlikely(iftype
!= NL80211_IFTYPE_WDS
&&
346 iftype
!= NL80211_IFTYPE_MESH_POINT
&&
347 iftype
!= NL80211_IFTYPE_AP_VLAN
&&
348 iftype
!= NL80211_IFTYPE_STATION
))
350 if (iftype
== NL80211_IFTYPE_MESH_POINT
) {
351 struct ieee80211s_hdr
*meshdr
=
352 (struct ieee80211s_hdr
*) (skb
->data
+ hdrlen
);
353 /* make sure meshdr->flags is on the linear part */
354 if (!pskb_may_pull(skb
, hdrlen
+ 1))
356 if (meshdr
->flags
& MESH_FLAGS_AE_A5_A6
) {
357 skb_copy_bits(skb
, hdrlen
+
358 offsetof(struct ieee80211s_hdr
, eaddr1
),
360 skb_copy_bits(skb
, hdrlen
+
361 offsetof(struct ieee80211s_hdr
, eaddr2
),
364 hdrlen
+= ieee80211_get_mesh_hdrlen(meshdr
);
367 case cpu_to_le16(IEEE80211_FCTL_FROMDS
):
368 if ((iftype
!= NL80211_IFTYPE_STATION
&&
369 iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
370 iftype
!= NL80211_IFTYPE_MESH_POINT
) ||
371 (is_multicast_ether_addr(dst
) &&
372 !compare_ether_addr(src
, addr
)))
374 if (iftype
== NL80211_IFTYPE_MESH_POINT
) {
375 struct ieee80211s_hdr
*meshdr
=
376 (struct ieee80211s_hdr
*) (skb
->data
+ hdrlen
);
377 /* make sure meshdr->flags is on the linear part */
378 if (!pskb_may_pull(skb
, hdrlen
+ 1))
380 if (meshdr
->flags
& MESH_FLAGS_AE_A4
)
381 skb_copy_bits(skb
, hdrlen
+
382 offsetof(struct ieee80211s_hdr
, eaddr1
),
384 hdrlen
+= ieee80211_get_mesh_hdrlen(meshdr
);
388 if (iftype
!= NL80211_IFTYPE_ADHOC
&&
389 iftype
!= NL80211_IFTYPE_STATION
)
394 if (!pskb_may_pull(skb
, hdrlen
+ 8))
397 payload
= skb
->data
+ hdrlen
;
398 ethertype
= (payload
[6] << 8) | payload
[7];
400 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
401 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
402 compare_ether_addr(payload
, bridge_tunnel_header
) == 0)) {
403 /* remove RFC1042 or Bridge-Tunnel encapsulation and
404 * replace EtherType */
405 skb_pull(skb
, hdrlen
+ 6);
406 memcpy(skb_push(skb
, ETH_ALEN
), src
, ETH_ALEN
);
407 memcpy(skb_push(skb
, ETH_ALEN
), dst
, ETH_ALEN
);
412 skb_pull(skb
, hdrlen
);
413 len
= htons(skb
->len
);
414 ehdr
= (struct ethhdr
*) skb_push(skb
, sizeof(struct ethhdr
));
415 memcpy(ehdr
->h_dest
, dst
, ETH_ALEN
);
416 memcpy(ehdr
->h_source
, src
, ETH_ALEN
);
421 EXPORT_SYMBOL(ieee80211_data_to_8023
);
423 int ieee80211_data_from_8023(struct sk_buff
*skb
, const u8
*addr
,
424 enum nl80211_iftype iftype
, u8
*bssid
, bool qos
)
426 struct ieee80211_hdr hdr
;
427 u16 hdrlen
, ethertype
;
429 const u8
*encaps_data
;
430 int encaps_len
, skip_header_bytes
;
434 if (unlikely(skb
->len
< ETH_HLEN
))
437 nh_pos
= skb_network_header(skb
) - skb
->data
;
438 h_pos
= skb_transport_header(skb
) - skb
->data
;
440 /* convert Ethernet header to proper 802.11 header (based on
442 ethertype
= (skb
->data
[12] << 8) | skb
->data
[13];
443 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_DATA
);
446 case NL80211_IFTYPE_AP
:
447 case NL80211_IFTYPE_AP_VLAN
:
448 case NL80211_IFTYPE_P2P_GO
:
449 fc
|= cpu_to_le16(IEEE80211_FCTL_FROMDS
);
451 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
452 memcpy(hdr
.addr2
, addr
, ETH_ALEN
);
453 memcpy(hdr
.addr3
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
456 case NL80211_IFTYPE_STATION
:
457 case NL80211_IFTYPE_P2P_CLIENT
:
458 fc
|= cpu_to_le16(IEEE80211_FCTL_TODS
);
460 memcpy(hdr
.addr1
, bssid
, ETH_ALEN
);
461 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
462 memcpy(hdr
.addr3
, skb
->data
, ETH_ALEN
);
465 case NL80211_IFTYPE_ADHOC
:
467 memcpy(hdr
.addr1
, skb
->data
, ETH_ALEN
);
468 memcpy(hdr
.addr2
, skb
->data
+ ETH_ALEN
, ETH_ALEN
);
469 memcpy(hdr
.addr3
, bssid
, ETH_ALEN
);
477 fc
|= cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
481 hdr
.frame_control
= fc
;
485 skip_header_bytes
= ETH_HLEN
;
486 if (ethertype
== ETH_P_AARP
|| ethertype
== ETH_P_IPX
) {
487 encaps_data
= bridge_tunnel_header
;
488 encaps_len
= sizeof(bridge_tunnel_header
);
489 skip_header_bytes
-= 2;
490 } else if (ethertype
> 0x600) {
491 encaps_data
= rfc1042_header
;
492 encaps_len
= sizeof(rfc1042_header
);
493 skip_header_bytes
-= 2;
499 skb_pull(skb
, skip_header_bytes
);
500 nh_pos
-= skip_header_bytes
;
501 h_pos
-= skip_header_bytes
;
503 head_need
= hdrlen
+ encaps_len
- skb_headroom(skb
);
505 if (head_need
> 0 || skb_cloned(skb
)) {
506 head_need
= max(head_need
, 0);
510 if (pskb_expand_head(skb
, head_need
, 0, GFP_ATOMIC
))
513 skb
->truesize
+= head_need
;
517 memcpy(skb_push(skb
, encaps_len
), encaps_data
, encaps_len
);
518 nh_pos
+= encaps_len
;
522 memcpy(skb_push(skb
, hdrlen
), &hdr
, hdrlen
);
527 /* Update skb pointers to various headers since this modified frame
528 * is going to go through Linux networking code that may potentially
529 * need things like pointer to IP header. */
530 skb_set_mac_header(skb
, 0);
531 skb_set_network_header(skb
, nh_pos
);
532 skb_set_transport_header(skb
, h_pos
);
536 EXPORT_SYMBOL(ieee80211_data_from_8023
);
539 void ieee80211_amsdu_to_8023s(struct sk_buff
*skb
, struct sk_buff_head
*list
,
540 const u8
*addr
, enum nl80211_iftype iftype
,
541 const unsigned int extra_headroom
,
542 bool has_80211_header
)
544 struct sk_buff
*frame
= NULL
;
547 const struct ethhdr
*eth
;
549 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
551 if (has_80211_header
) {
552 err
= ieee80211_data_to_8023(skb
, addr
, iftype
);
556 /* skip the wrapping header */
557 eth
= (struct ethhdr
*) skb_pull(skb
, sizeof(struct ethhdr
));
561 eth
= (struct ethhdr
*) skb
->data
;
564 while (skb
!= frame
) {
566 __be16 len
= eth
->h_proto
;
567 unsigned int subframe_len
= sizeof(struct ethhdr
) + ntohs(len
);
569 remaining
= skb
->len
;
570 memcpy(dst
, eth
->h_dest
, ETH_ALEN
);
571 memcpy(src
, eth
->h_source
, ETH_ALEN
);
573 padding
= (4 - subframe_len
) & 0x3;
574 /* the last MSDU has no padding */
575 if (subframe_len
> remaining
)
578 skb_pull(skb
, sizeof(struct ethhdr
));
579 /* reuse skb for the last subframe */
580 if (remaining
<= subframe_len
+ padding
)
583 unsigned int hlen
= ALIGN(extra_headroom
, 4);
585 * Allocate and reserve two bytes more for payload
586 * alignment since sizeof(struct ethhdr) is 14.
588 frame
= dev_alloc_skb(hlen
+ subframe_len
+ 2);
592 skb_reserve(frame
, hlen
+ sizeof(struct ethhdr
) + 2);
593 memcpy(skb_put(frame
, ntohs(len
)), skb
->data
,
596 eth
= (struct ethhdr
*)skb_pull(skb
, ntohs(len
) +
599 dev_kfree_skb(frame
);
604 skb_reset_network_header(frame
);
605 frame
->dev
= skb
->dev
;
606 frame
->priority
= skb
->priority
;
608 payload
= frame
->data
;
609 ethertype
= (payload
[6] << 8) | payload
[7];
611 if (likely((compare_ether_addr(payload
, rfc1042_header
) == 0 &&
612 ethertype
!= ETH_P_AARP
&& ethertype
!= ETH_P_IPX
) ||
613 compare_ether_addr(payload
,
614 bridge_tunnel_header
) == 0)) {
615 /* remove RFC1042 or Bridge-Tunnel
616 * encapsulation and replace EtherType */
618 memcpy(skb_push(frame
, ETH_ALEN
), src
, ETH_ALEN
);
619 memcpy(skb_push(frame
, ETH_ALEN
), dst
, ETH_ALEN
);
621 memcpy(skb_push(frame
, sizeof(__be16
)), &len
,
623 memcpy(skb_push(frame
, ETH_ALEN
), src
, ETH_ALEN
);
624 memcpy(skb_push(frame
, ETH_ALEN
), dst
, ETH_ALEN
);
626 __skb_queue_tail(list
, frame
);
632 __skb_queue_purge(list
);
636 EXPORT_SYMBOL(ieee80211_amsdu_to_8023s
);
638 /* Given a data frame determine the 802.1p/1d tag to use. */
639 unsigned int cfg80211_classify8021d(struct sk_buff
*skb
)
643 /* skb->priority values from 256->263 are magic values to
644 * directly indicate a specific 802.1d priority. This is used
645 * to allow 802.1d priority to be passed directly in from VLAN
648 if (skb
->priority
>= 256 && skb
->priority
<= 263)
649 return skb
->priority
- 256;
651 switch (skb
->protocol
) {
652 case htons(ETH_P_IP
):
653 dscp
= ip_hdr(skb
)->tos
& 0xfc;
661 EXPORT_SYMBOL(cfg80211_classify8021d
);
663 const u8
*ieee80211_bss_get_ie(struct cfg80211_bss
*bss
, u8 ie
)
667 pos
= bss
->information_elements
;
670 end
= pos
+ bss
->len_information_elements
;
672 while (pos
+ 1 < end
) {
673 if (pos
+ 2 + pos
[1] > end
)
682 EXPORT_SYMBOL(ieee80211_bss_get_ie
);
684 void cfg80211_upload_connect_keys(struct wireless_dev
*wdev
)
686 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
687 struct net_device
*dev
= wdev
->netdev
;
690 if (!wdev
->connect_keys
)
693 for (i
= 0; i
< 6; i
++) {
694 if (!wdev
->connect_keys
->params
[i
].cipher
)
696 if (rdev
->ops
->add_key(wdev
->wiphy
, dev
, i
, false, NULL
,
697 &wdev
->connect_keys
->params
[i
])) {
698 netdev_err(dev
, "failed to set key %d\n", i
);
701 if (wdev
->connect_keys
->def
== i
)
702 if (rdev
->ops
->set_default_key(wdev
->wiphy
, dev
,
704 netdev_err(dev
, "failed to set defkey %d\n", i
);
707 if (wdev
->connect_keys
->defmgmt
== i
)
708 if (rdev
->ops
->set_default_mgmt_key(wdev
->wiphy
, dev
, i
))
709 netdev_err(dev
, "failed to set mgtdef %d\n", i
);
712 kfree(wdev
->connect_keys
);
713 wdev
->connect_keys
= NULL
;
716 static void cfg80211_process_wdev_events(struct wireless_dev
*wdev
)
718 struct cfg80211_event
*ev
;
720 const u8
*bssid
= NULL
;
722 spin_lock_irqsave(&wdev
->event_lock
, flags
);
723 while (!list_empty(&wdev
->event_list
)) {
724 ev
= list_first_entry(&wdev
->event_list
,
725 struct cfg80211_event
, list
);
727 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
731 case EVENT_CONNECT_RESULT
:
732 if (!is_zero_ether_addr(ev
->cr
.bssid
))
733 bssid
= ev
->cr
.bssid
;
734 __cfg80211_connect_result(
736 ev
->cr
.req_ie
, ev
->cr
.req_ie_len
,
737 ev
->cr
.resp_ie
, ev
->cr
.resp_ie_len
,
739 ev
->cr
.status
== WLAN_STATUS_SUCCESS
,
743 __cfg80211_roamed(wdev
, ev
->rm
.bss
, ev
->rm
.req_ie
,
744 ev
->rm
.req_ie_len
, ev
->rm
.resp_ie
,
747 case EVENT_DISCONNECTED
:
748 __cfg80211_disconnected(wdev
->netdev
,
749 ev
->dc
.ie
, ev
->dc
.ie_len
,
750 ev
->dc
.reason
, true);
752 case EVENT_IBSS_JOINED
:
753 __cfg80211_ibss_joined(wdev
->netdev
, ev
->ij
.bssid
);
760 spin_lock_irqsave(&wdev
->event_lock
, flags
);
762 spin_unlock_irqrestore(&wdev
->event_lock
, flags
);
765 void cfg80211_process_rdev_events(struct cfg80211_registered_device
*rdev
)
767 struct wireless_dev
*wdev
;
770 ASSERT_RDEV_LOCK(rdev
);
772 mutex_lock(&rdev
->devlist_mtx
);
774 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
)
775 cfg80211_process_wdev_events(wdev
);
777 mutex_unlock(&rdev
->devlist_mtx
);
780 int cfg80211_change_iface(struct cfg80211_registered_device
*rdev
,
781 struct net_device
*dev
, enum nl80211_iftype ntype
,
782 u32
*flags
, struct vif_params
*params
)
785 enum nl80211_iftype otype
= dev
->ieee80211_ptr
->iftype
;
787 ASSERT_RDEV_LOCK(rdev
);
789 /* don't support changing VLANs, you just re-create them */
790 if (otype
== NL80211_IFTYPE_AP_VLAN
)
793 if (!rdev
->ops
->change_virtual_intf
||
794 !(rdev
->wiphy
.interface_modes
& (1 << ntype
)))
797 /* if it's part of a bridge, reject changing type to station/ibss */
798 if ((dev
->priv_flags
& IFF_BRIDGE_PORT
) &&
799 (ntype
== NL80211_IFTYPE_ADHOC
||
800 ntype
== NL80211_IFTYPE_STATION
||
801 ntype
== NL80211_IFTYPE_P2P_CLIENT
))
804 if (ntype
!= otype
) {
805 err
= cfg80211_can_change_interface(rdev
, dev
->ieee80211_ptr
,
810 dev
->ieee80211_ptr
->use_4addr
= false;
811 dev
->ieee80211_ptr
->mesh_id_up_len
= 0;
814 case NL80211_IFTYPE_ADHOC
:
815 cfg80211_leave_ibss(rdev
, dev
, false);
817 case NL80211_IFTYPE_STATION
:
818 case NL80211_IFTYPE_P2P_CLIENT
:
819 cfg80211_disconnect(rdev
, dev
,
820 WLAN_REASON_DEAUTH_LEAVING
, true);
822 case NL80211_IFTYPE_MESH_POINT
:
823 /* mesh should be handled? */
829 cfg80211_process_rdev_events(rdev
);
832 err
= rdev
->ops
->change_virtual_intf(&rdev
->wiphy
, dev
,
833 ntype
, flags
, params
);
835 WARN_ON(!err
&& dev
->ieee80211_ptr
->iftype
!= ntype
);
837 if (!err
&& params
&& params
->use_4addr
!= -1)
838 dev
->ieee80211_ptr
->use_4addr
= params
->use_4addr
;
841 dev
->priv_flags
&= ~IFF_DONT_BRIDGE
;
843 case NL80211_IFTYPE_STATION
:
844 if (dev
->ieee80211_ptr
->use_4addr
)
847 case NL80211_IFTYPE_P2P_CLIENT
:
848 case NL80211_IFTYPE_ADHOC
:
849 dev
->priv_flags
|= IFF_DONT_BRIDGE
;
851 case NL80211_IFTYPE_P2P_GO
:
852 case NL80211_IFTYPE_AP
:
853 case NL80211_IFTYPE_AP_VLAN
:
854 case NL80211_IFTYPE_WDS
:
855 case NL80211_IFTYPE_MESH_POINT
:
858 case NL80211_IFTYPE_MONITOR
:
859 /* monitor can't bridge anyway */
861 case NL80211_IFTYPE_UNSPECIFIED
:
862 case NUM_NL80211_IFTYPES
:
871 u16
cfg80211_calculate_bitrate(struct rate_info
*rate
)
873 int modulation
, streams
, bitrate
;
875 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
878 /* the formula below does only work for MCS values smaller than 32 */
882 modulation
= rate
->mcs
& 7;
883 streams
= (rate
->mcs
>> 3) + 1;
885 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
889 bitrate
*= (modulation
+ 1);
890 else if (modulation
== 4)
891 bitrate
*= (modulation
+ 2);
893 bitrate
*= (modulation
+ 3);
897 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
898 bitrate
= (bitrate
/ 9) * 10;
900 /* do NOT round down here */
901 return (bitrate
+ 50000) / 100000;
904 int cfg80211_validate_beacon_int(struct cfg80211_registered_device
*rdev
,
907 struct wireless_dev
*wdev
;
913 mutex_lock(&rdev
->devlist_mtx
);
915 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
916 if (!wdev
->beacon_interval
)
918 if (wdev
->beacon_interval
!= beacon_int
) {
924 mutex_unlock(&rdev
->devlist_mtx
);
929 int cfg80211_can_change_interface(struct cfg80211_registered_device
*rdev
,
930 struct wireless_dev
*wdev
,
931 enum nl80211_iftype iftype
)
933 struct wireless_dev
*wdev_iter
;
934 int num
[NUM_NL80211_IFTYPES
];
940 /* Always allow software iftypes */
941 if (rdev
->wiphy
.software_iftypes
& BIT(iftype
))
945 * Drivers will gradually all set this flag, until all
946 * have it we only enforce for those that set it.
948 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_ENFORCE_COMBINATIONS
))
951 memset(num
, 0, sizeof(num
));
955 mutex_lock(&rdev
->devlist_mtx
);
956 list_for_each_entry(wdev_iter
, &rdev
->netdev_list
, list
) {
957 if (wdev_iter
== wdev
)
959 if (!netif_running(wdev_iter
->netdev
))
962 if (rdev
->wiphy
.software_iftypes
& BIT(wdev_iter
->iftype
))
965 num
[wdev_iter
->iftype
]++;
968 mutex_unlock(&rdev
->devlist_mtx
);
970 for (i
= 0; i
< rdev
->wiphy
.n_iface_combinations
; i
++) {
971 const struct ieee80211_iface_combination
*c
;
972 struct ieee80211_iface_limit
*limits
;
974 c
= &rdev
->wiphy
.iface_combinations
[i
];
976 limits
= kmemdup(c
->limits
, sizeof(limits
[0]) * c
->n_limits
,
980 if (total
> c
->max_interfaces
)
983 for (iftype
= 0; iftype
< NUM_NL80211_IFTYPES
; iftype
++) {
984 if (rdev
->wiphy
.software_iftypes
& BIT(iftype
))
986 for (j
= 0; j
< c
->n_limits
; j
++) {
987 if (!(limits
[j
].types
& iftype
))
989 if (limits
[j
].max
< num
[iftype
])
991 limits
[j
].max
-= num
[iftype
];
1004 int ieee80211_get_ratemask(struct ieee80211_supported_band
*sband
,
1005 const u8
*rates
, unsigned int n_rates
,
1013 if (n_rates
== 0 || n_rates
> NL80211_MAX_SUPP_RATES
)
1018 for (i
= 0; i
< n_rates
; i
++) {
1019 int rate
= (rates
[i
] & 0x7f) * 5;
1022 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1023 if (sband
->bitrates
[j
].bitrate
== rate
) {
1034 * mask must have at least one bit set here since we
1035 * didn't accept a 0-length rates array nor allowed
1036 * entries in the array that didn't exist
1042 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
1043 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
1044 const unsigned char rfc1042_header
[] __aligned(2) =
1045 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
1046 EXPORT_SYMBOL(rfc1042_header
);
1048 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
1049 const unsigned char bridge_tunnel_header
[] __aligned(2) =
1050 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
1051 EXPORT_SYMBOL(bridge_tunnel_header
);