Commit | Line | Data |
---|---|---|
8318d78a JB |
1 | /* |
2 | * Wireless utility functions | |
3 | * | |
d3236553 | 4 | * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net> |
8318d78a | 5 | */ |
d3236553 | 6 | #include <linux/bitops.h> |
e31a16d6 | 7 | #include <linux/etherdevice.h> |
5a0e3ad6 | 8 | #include <linux/slab.h> |
d3236553 | 9 | #include <net/cfg80211.h> |
e31a16d6 | 10 | #include <net/ip.h> |
8318d78a JB |
11 | #include "core.h" |
12 | ||
bd815252 JB |
13 | struct ieee80211_rate * |
14 | ieee80211_get_response_rate(struct ieee80211_supported_band *sband, | |
881d948c | 15 | u32 basic_rates, int bitrate) |
bd815252 JB |
16 | { |
17 | struct ieee80211_rate *result = &sband->bitrates[0]; | |
18 | int i; | |
19 | ||
20 | for (i = 0; i < sband->n_bitrates; i++) { | |
21 | if (!(basic_rates & BIT(i))) | |
22 | continue; | |
23 | if (sband->bitrates[i].bitrate > bitrate) | |
24 | continue; | |
25 | result = &sband->bitrates[i]; | |
26 | } | |
27 | ||
28 | return result; | |
29 | } | |
30 | EXPORT_SYMBOL(ieee80211_get_response_rate); | |
31 | ||
59eb21a6 | 32 | int ieee80211_channel_to_frequency(int chan, enum ieee80211_band band) |
8318d78a | 33 | { |
59eb21a6 BR |
34 | /* see 802.11 17.3.8.3.2 and Annex J |
35 | * there are overlapping channel numbers in 5GHz and 2GHz bands */ | |
36 | if (band == IEEE80211_BAND_5GHZ) { | |
37 | if (chan >= 182 && chan <= 196) | |
38 | return 4000 + chan * 5; | |
39 | else | |
40 | return 5000 + chan * 5; | |
41 | } else { /* IEEE80211_BAND_2GHZ */ | |
42 | if (chan == 14) | |
43 | return 2484; | |
44 | else if (chan < 14) | |
45 | return 2407 + chan * 5; | |
46 | else | |
47 | return 0; /* not supported */ | |
48 | } | |
8318d78a JB |
49 | } |
50 | EXPORT_SYMBOL(ieee80211_channel_to_frequency); | |
51 | ||
52 | int ieee80211_frequency_to_channel(int freq) | |
53 | { | |
59eb21a6 | 54 | /* see 802.11 17.3.8.3.2 and Annex J */ |
8318d78a JB |
55 | if (freq == 2484) |
56 | return 14; | |
59eb21a6 | 57 | else if (freq < 2484) |
8318d78a | 58 | return (freq - 2407) / 5; |
59eb21a6 BR |
59 | else if (freq >= 4910 && freq <= 4980) |
60 | return (freq - 4000) / 5; | |
61 | else | |
62 | return (freq - 5000) / 5; | |
8318d78a JB |
63 | } |
64 | EXPORT_SYMBOL(ieee80211_frequency_to_channel); | |
65 | ||
6c507cd0 JB |
66 | struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy, |
67 | int freq) | |
906c730a JB |
68 | { |
69 | enum ieee80211_band band; | |
70 | struct ieee80211_supported_band *sband; | |
71 | int i; | |
72 | ||
73 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
74 | sband = wiphy->bands[band]; | |
75 | ||
76 | if (!sband) | |
77 | continue; | |
78 | ||
79 | for (i = 0; i < sband->n_channels; i++) { | |
80 | if (sband->channels[i].center_freq == freq) | |
81 | return &sband->channels[i]; | |
82 | } | |
83 | } | |
84 | ||
85 | return NULL; | |
86 | } | |
6c507cd0 | 87 | EXPORT_SYMBOL(__ieee80211_get_channel); |
906c730a | 88 | |
8318d78a JB |
89 | static void set_mandatory_flags_band(struct ieee80211_supported_band *sband, |
90 | enum ieee80211_band band) | |
91 | { | |
92 | int i, want; | |
93 | ||
94 | switch (band) { | |
95 | case IEEE80211_BAND_5GHZ: | |
96 | want = 3; | |
97 | for (i = 0; i < sband->n_bitrates; i++) { | |
98 | if (sband->bitrates[i].bitrate == 60 || | |
99 | sband->bitrates[i].bitrate == 120 || | |
100 | sband->bitrates[i].bitrate == 240) { | |
101 | sband->bitrates[i].flags |= | |
102 | IEEE80211_RATE_MANDATORY_A; | |
103 | want--; | |
104 | } | |
105 | } | |
106 | WARN_ON(want); | |
107 | break; | |
108 | case IEEE80211_BAND_2GHZ: | |
109 | want = 7; | |
110 | for (i = 0; i < sband->n_bitrates; i++) { | |
111 | if (sband->bitrates[i].bitrate == 10) { | |
112 | sband->bitrates[i].flags |= | |
113 | IEEE80211_RATE_MANDATORY_B | | |
114 | IEEE80211_RATE_MANDATORY_G; | |
115 | want--; | |
116 | } | |
117 | ||
118 | if (sband->bitrates[i].bitrate == 20 || | |
119 | sband->bitrates[i].bitrate == 55 || | |
120 | sband->bitrates[i].bitrate == 110 || | |
121 | sband->bitrates[i].bitrate == 60 || | |
122 | sband->bitrates[i].bitrate == 120 || | |
123 | sband->bitrates[i].bitrate == 240) { | |
124 | sband->bitrates[i].flags |= | |
125 | IEEE80211_RATE_MANDATORY_G; | |
126 | want--; | |
127 | } | |
128 | ||
aac09fbf JB |
129 | if (sband->bitrates[i].bitrate != 10 && |
130 | sband->bitrates[i].bitrate != 20 && | |
131 | sband->bitrates[i].bitrate != 55 && | |
132 | sband->bitrates[i].bitrate != 110) | |
8318d78a JB |
133 | sband->bitrates[i].flags |= |
134 | IEEE80211_RATE_ERP_G; | |
135 | } | |
406f2388 | 136 | WARN_ON(want != 0 && want != 3 && want != 6); |
8318d78a JB |
137 | break; |
138 | case IEEE80211_NUM_BANDS: | |
139 | WARN_ON(1); | |
140 | break; | |
141 | } | |
142 | } | |
143 | ||
144 | void ieee80211_set_bitrate_flags(struct wiphy *wiphy) | |
145 | { | |
146 | enum ieee80211_band band; | |
147 | ||
148 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
149 | if (wiphy->bands[band]) | |
150 | set_mandatory_flags_band(wiphy->bands[band], band); | |
151 | } | |
08645126 | 152 | |
38ba3c57 JM |
153 | bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher) |
154 | { | |
155 | int i; | |
156 | for (i = 0; i < wiphy->n_cipher_suites; i++) | |
157 | if (cipher == wiphy->cipher_suites[i]) | |
158 | return true; | |
159 | return false; | |
160 | } | |
161 | ||
fffd0934 JB |
162 | int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev, |
163 | struct key_params *params, int key_idx, | |
e31b8213 | 164 | bool pairwise, const u8 *mac_addr) |
08645126 JB |
165 | { |
166 | if (key_idx > 5) | |
167 | return -EINVAL; | |
168 | ||
e31b8213 JB |
169 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
170 | return -EINVAL; | |
171 | ||
172 | if (pairwise && !mac_addr) | |
173 | return -EINVAL; | |
174 | ||
08645126 JB |
175 | /* |
176 | * Disallow pairwise keys with non-zero index unless it's WEP | |
45cbad6a JO |
177 | * or a vendor specific cipher (because current deployments use |
178 | * pairwise WEP keys with non-zero indices and for vendor specific | |
179 | * ciphers this should be validated in the driver or hardware level | |
180 | * - but 802.11i clearly specifies to use zero) | |
08645126 | 181 | */ |
e31b8213 | 182 | if (pairwise && key_idx && |
45cbad6a JO |
183 | ((params->cipher == WLAN_CIPHER_SUITE_TKIP) || |
184 | (params->cipher == WLAN_CIPHER_SUITE_CCMP) || | |
185 | (params->cipher == WLAN_CIPHER_SUITE_AES_CMAC))) | |
08645126 JB |
186 | return -EINVAL; |
187 | ||
08645126 JB |
188 | switch (params->cipher) { |
189 | case WLAN_CIPHER_SUITE_WEP40: | |
8fc0fee0 | 190 | if (params->key_len != WLAN_KEY_LEN_WEP40) |
08645126 JB |
191 | return -EINVAL; |
192 | break; | |
193 | case WLAN_CIPHER_SUITE_TKIP: | |
8fc0fee0 | 194 | if (params->key_len != WLAN_KEY_LEN_TKIP) |
08645126 JB |
195 | return -EINVAL; |
196 | break; | |
197 | case WLAN_CIPHER_SUITE_CCMP: | |
8fc0fee0 | 198 | if (params->key_len != WLAN_KEY_LEN_CCMP) |
08645126 JB |
199 | return -EINVAL; |
200 | break; | |
201 | case WLAN_CIPHER_SUITE_WEP104: | |
8fc0fee0 | 202 | if (params->key_len != WLAN_KEY_LEN_WEP104) |
08645126 JB |
203 | return -EINVAL; |
204 | break; | |
205 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
8fc0fee0 | 206 | if (params->key_len != WLAN_KEY_LEN_AES_CMAC) |
08645126 JB |
207 | return -EINVAL; |
208 | break; | |
209 | default: | |
7d64b7cc JB |
210 | /* |
211 | * We don't know anything about this algorithm, | |
212 | * allow using it -- but the driver must check | |
213 | * all parameters! We still check below whether | |
214 | * or not the driver supports this algorithm, | |
215 | * of course. | |
216 | */ | |
217 | break; | |
08645126 JB |
218 | } |
219 | ||
9f26a952 JM |
220 | if (params->seq) { |
221 | switch (params->cipher) { | |
222 | case WLAN_CIPHER_SUITE_WEP40: | |
223 | case WLAN_CIPHER_SUITE_WEP104: | |
224 | /* These ciphers do not use key sequence */ | |
225 | return -EINVAL; | |
226 | case WLAN_CIPHER_SUITE_TKIP: | |
227 | case WLAN_CIPHER_SUITE_CCMP: | |
228 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
229 | if (params->seq_len != 6) | |
230 | return -EINVAL; | |
231 | break; | |
232 | } | |
233 | } | |
234 | ||
38ba3c57 | 235 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, params->cipher)) |
fffd0934 JB |
236 | return -EINVAL; |
237 | ||
08645126 JB |
238 | return 0; |
239 | } | |
e31a16d6 ZY |
240 | |
241 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ | |
242 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ | |
243 | const unsigned char rfc1042_header[] __aligned(2) = | |
244 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | |
245 | EXPORT_SYMBOL(rfc1042_header); | |
246 | ||
247 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ | |
248 | const unsigned char bridge_tunnel_header[] __aligned(2) = | |
249 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; | |
250 | EXPORT_SYMBOL(bridge_tunnel_header); | |
251 | ||
633adf1a | 252 | unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc) |
e31a16d6 ZY |
253 | { |
254 | unsigned int hdrlen = 24; | |
255 | ||
256 | if (ieee80211_is_data(fc)) { | |
257 | if (ieee80211_has_a4(fc)) | |
258 | hdrlen = 30; | |
d0dd2de0 | 259 | if (ieee80211_is_data_qos(fc)) { |
e31a16d6 | 260 | hdrlen += IEEE80211_QOS_CTL_LEN; |
d0dd2de0 AT |
261 | if (ieee80211_has_order(fc)) |
262 | hdrlen += IEEE80211_HT_CTL_LEN; | |
263 | } | |
e31a16d6 ZY |
264 | goto out; |
265 | } | |
266 | ||
267 | if (ieee80211_is_ctl(fc)) { | |
268 | /* | |
269 | * ACK and CTS are 10 bytes, all others 16. To see how | |
270 | * to get this condition consider | |
271 | * subtype mask: 0b0000000011110000 (0x00F0) | |
272 | * ACK subtype: 0b0000000011010000 (0x00D0) | |
273 | * CTS subtype: 0b0000000011000000 (0x00C0) | |
274 | * bits that matter: ^^^ (0x00E0) | |
275 | * value of those: 0b0000000011000000 (0x00C0) | |
276 | */ | |
277 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) | |
278 | hdrlen = 10; | |
279 | else | |
280 | hdrlen = 16; | |
281 | } | |
282 | out: | |
283 | return hdrlen; | |
284 | } | |
285 | EXPORT_SYMBOL(ieee80211_hdrlen); | |
286 | ||
287 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) | |
288 | { | |
289 | const struct ieee80211_hdr *hdr = | |
290 | (const struct ieee80211_hdr *)skb->data; | |
291 | unsigned int hdrlen; | |
292 | ||
293 | if (unlikely(skb->len < 10)) | |
294 | return 0; | |
295 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
296 | if (unlikely(hdrlen > skb->len)) | |
297 | return 0; | |
298 | return hdrlen; | |
299 | } | |
300 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); | |
301 | ||
60fd2b67 | 302 | static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) |
e31a16d6 ZY |
303 | { |
304 | int ae = meshhdr->flags & MESH_FLAGS_AE; | |
305 | /* 7.1.3.5a.2 */ | |
306 | switch (ae) { | |
307 | case 0: | |
308 | return 6; | |
3c5772a5 | 309 | case MESH_FLAGS_AE_A4: |
e31a16d6 | 310 | return 12; |
3c5772a5 | 311 | case MESH_FLAGS_AE_A5_A6: |
e31a16d6 | 312 | return 18; |
3c5772a5 | 313 | case (MESH_FLAGS_AE_A4 | MESH_FLAGS_AE_A5_A6): |
e31a16d6 ZY |
314 | return 24; |
315 | default: | |
316 | return 6; | |
317 | } | |
318 | } | |
319 | ||
eaf85ca7 | 320 | int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr, |
e31a16d6 ZY |
321 | enum nl80211_iftype iftype) |
322 | { | |
323 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
324 | u16 hdrlen, ethertype; | |
325 | u8 *payload; | |
326 | u8 dst[ETH_ALEN]; | |
327 | u8 src[ETH_ALEN] __aligned(2); | |
328 | ||
329 | if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) | |
330 | return -1; | |
331 | ||
332 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
333 | ||
334 | /* convert IEEE 802.11 header + possible LLC headers into Ethernet | |
335 | * header | |
336 | * IEEE 802.11 address fields: | |
337 | * ToDS FromDS Addr1 Addr2 Addr3 Addr4 | |
338 | * 0 0 DA SA BSSID n/a | |
339 | * 0 1 DA BSSID SA n/a | |
340 | * 1 0 BSSID SA DA n/a | |
341 | * 1 1 RA TA DA SA | |
342 | */ | |
343 | memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN); | |
344 | memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN); | |
345 | ||
346 | switch (hdr->frame_control & | |
347 | cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { | |
348 | case cpu_to_le16(IEEE80211_FCTL_TODS): | |
349 | if (unlikely(iftype != NL80211_IFTYPE_AP && | |
074ac8df JB |
350 | iftype != NL80211_IFTYPE_AP_VLAN && |
351 | iftype != NL80211_IFTYPE_P2P_GO)) | |
e31a16d6 ZY |
352 | return -1; |
353 | break; | |
354 | case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): | |
355 | if (unlikely(iftype != NL80211_IFTYPE_WDS && | |
f14543ee FF |
356 | iftype != NL80211_IFTYPE_MESH_POINT && |
357 | iftype != NL80211_IFTYPE_AP_VLAN && | |
358 | iftype != NL80211_IFTYPE_STATION)) | |
e31a16d6 ZY |
359 | return -1; |
360 | if (iftype == NL80211_IFTYPE_MESH_POINT) { | |
361 | struct ieee80211s_hdr *meshdr = | |
362 | (struct ieee80211s_hdr *) (skb->data + hdrlen); | |
e3cf8b3f ZY |
363 | /* make sure meshdr->flags is on the linear part */ |
364 | if (!pskb_may_pull(skb, hdrlen + 1)) | |
365 | return -1; | |
e31a16d6 | 366 | if (meshdr->flags & MESH_FLAGS_AE_A5_A6) { |
e3cf8b3f ZY |
367 | skb_copy_bits(skb, hdrlen + |
368 | offsetof(struct ieee80211s_hdr, eaddr1), | |
369 | dst, ETH_ALEN); | |
370 | skb_copy_bits(skb, hdrlen + | |
371 | offsetof(struct ieee80211s_hdr, eaddr2), | |
372 | src, ETH_ALEN); | |
e31a16d6 | 373 | } |
e3cf8b3f | 374 | hdrlen += ieee80211_get_mesh_hdrlen(meshdr); |
e31a16d6 ZY |
375 | } |
376 | break; | |
377 | case cpu_to_le16(IEEE80211_FCTL_FROMDS): | |
3c5772a5 | 378 | if ((iftype != NL80211_IFTYPE_STATION && |
074ac8df JB |
379 | iftype != NL80211_IFTYPE_P2P_CLIENT && |
380 | iftype != NL80211_IFTYPE_MESH_POINT) || | |
e31a16d6 ZY |
381 | (is_multicast_ether_addr(dst) && |
382 | !compare_ether_addr(src, addr))) | |
383 | return -1; | |
3c5772a5 JC |
384 | if (iftype == NL80211_IFTYPE_MESH_POINT) { |
385 | struct ieee80211s_hdr *meshdr = | |
386 | (struct ieee80211s_hdr *) (skb->data + hdrlen); | |
e3cf8b3f ZY |
387 | /* make sure meshdr->flags is on the linear part */ |
388 | if (!pskb_may_pull(skb, hdrlen + 1)) | |
389 | return -1; | |
3c5772a5 | 390 | if (meshdr->flags & MESH_FLAGS_AE_A4) |
e3cf8b3f ZY |
391 | skb_copy_bits(skb, hdrlen + |
392 | offsetof(struct ieee80211s_hdr, eaddr1), | |
393 | src, ETH_ALEN); | |
394 | hdrlen += ieee80211_get_mesh_hdrlen(meshdr); | |
3c5772a5 | 395 | } |
e31a16d6 ZY |
396 | break; |
397 | case cpu_to_le16(0): | |
941c93cd AN |
398 | if (iftype != NL80211_IFTYPE_ADHOC && |
399 | iftype != NL80211_IFTYPE_STATION) | |
400 | return -1; | |
e31a16d6 ZY |
401 | break; |
402 | } | |
403 | ||
e3cf8b3f | 404 | if (!pskb_may_pull(skb, hdrlen + 8)) |
e31a16d6 ZY |
405 | return -1; |
406 | ||
407 | payload = skb->data + hdrlen; | |
408 | ethertype = (payload[6] << 8) | payload[7]; | |
409 | ||
410 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && | |
411 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | |
412 | compare_ether_addr(payload, bridge_tunnel_header) == 0)) { | |
413 | /* remove RFC1042 or Bridge-Tunnel encapsulation and | |
414 | * replace EtherType */ | |
415 | skb_pull(skb, hdrlen + 6); | |
416 | memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); | |
417 | memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); | |
418 | } else { | |
419 | struct ethhdr *ehdr; | |
420 | __be16 len; | |
421 | ||
422 | skb_pull(skb, hdrlen); | |
423 | len = htons(skb->len); | |
424 | ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr)); | |
425 | memcpy(ehdr->h_dest, dst, ETH_ALEN); | |
426 | memcpy(ehdr->h_source, src, ETH_ALEN); | |
427 | ehdr->h_proto = len; | |
428 | } | |
429 | return 0; | |
430 | } | |
431 | EXPORT_SYMBOL(ieee80211_data_to_8023); | |
432 | ||
eaf85ca7 | 433 | int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr, |
e31a16d6 ZY |
434 | enum nl80211_iftype iftype, u8 *bssid, bool qos) |
435 | { | |
436 | struct ieee80211_hdr hdr; | |
437 | u16 hdrlen, ethertype; | |
438 | __le16 fc; | |
439 | const u8 *encaps_data; | |
440 | int encaps_len, skip_header_bytes; | |
441 | int nh_pos, h_pos; | |
442 | int head_need; | |
443 | ||
444 | if (unlikely(skb->len < ETH_HLEN)) | |
445 | return -EINVAL; | |
446 | ||
447 | nh_pos = skb_network_header(skb) - skb->data; | |
448 | h_pos = skb_transport_header(skb) - skb->data; | |
449 | ||
450 | /* convert Ethernet header to proper 802.11 header (based on | |
451 | * operation mode) */ | |
452 | ethertype = (skb->data[12] << 8) | skb->data[13]; | |
453 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); | |
454 | ||
455 | switch (iftype) { | |
456 | case NL80211_IFTYPE_AP: | |
457 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 458 | case NL80211_IFTYPE_P2P_GO: |
e31a16d6 ZY |
459 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); |
460 | /* DA BSSID SA */ | |
461 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | |
462 | memcpy(hdr.addr2, addr, ETH_ALEN); | |
463 | memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); | |
464 | hdrlen = 24; | |
465 | break; | |
466 | case NL80211_IFTYPE_STATION: | |
074ac8df | 467 | case NL80211_IFTYPE_P2P_CLIENT: |
e31a16d6 ZY |
468 | fc |= cpu_to_le16(IEEE80211_FCTL_TODS); |
469 | /* BSSID SA DA */ | |
470 | memcpy(hdr.addr1, bssid, ETH_ALEN); | |
471 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); | |
472 | memcpy(hdr.addr3, skb->data, ETH_ALEN); | |
473 | hdrlen = 24; | |
474 | break; | |
475 | case NL80211_IFTYPE_ADHOC: | |
476 | /* DA SA BSSID */ | |
477 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | |
478 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); | |
479 | memcpy(hdr.addr3, bssid, ETH_ALEN); | |
480 | hdrlen = 24; | |
481 | break; | |
482 | default: | |
483 | return -EOPNOTSUPP; | |
484 | } | |
485 | ||
486 | if (qos) { | |
487 | fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); | |
488 | hdrlen += 2; | |
489 | } | |
490 | ||
491 | hdr.frame_control = fc; | |
492 | hdr.duration_id = 0; | |
493 | hdr.seq_ctrl = 0; | |
494 | ||
495 | skip_header_bytes = ETH_HLEN; | |
496 | if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) { | |
497 | encaps_data = bridge_tunnel_header; | |
498 | encaps_len = sizeof(bridge_tunnel_header); | |
499 | skip_header_bytes -= 2; | |
500 | } else if (ethertype > 0x600) { | |
501 | encaps_data = rfc1042_header; | |
502 | encaps_len = sizeof(rfc1042_header); | |
503 | skip_header_bytes -= 2; | |
504 | } else { | |
505 | encaps_data = NULL; | |
506 | encaps_len = 0; | |
507 | } | |
508 | ||
509 | skb_pull(skb, skip_header_bytes); | |
510 | nh_pos -= skip_header_bytes; | |
511 | h_pos -= skip_header_bytes; | |
512 | ||
513 | head_need = hdrlen + encaps_len - skb_headroom(skb); | |
514 | ||
515 | if (head_need > 0 || skb_cloned(skb)) { | |
516 | head_need = max(head_need, 0); | |
517 | if (head_need) | |
518 | skb_orphan(skb); | |
519 | ||
24616152 | 520 | if (pskb_expand_head(skb, head_need, 0, GFP_ATOMIC)) |
e31a16d6 | 521 | return -ENOMEM; |
24616152 | 522 | |
e31a16d6 ZY |
523 | skb->truesize += head_need; |
524 | } | |
525 | ||
526 | if (encaps_data) { | |
527 | memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len); | |
528 | nh_pos += encaps_len; | |
529 | h_pos += encaps_len; | |
530 | } | |
531 | ||
532 | memcpy(skb_push(skb, hdrlen), &hdr, hdrlen); | |
533 | ||
534 | nh_pos += hdrlen; | |
535 | h_pos += hdrlen; | |
536 | ||
537 | /* Update skb pointers to various headers since this modified frame | |
538 | * is going to go through Linux networking code that may potentially | |
539 | * need things like pointer to IP header. */ | |
540 | skb_set_mac_header(skb, 0); | |
541 | skb_set_network_header(skb, nh_pos); | |
542 | skb_set_transport_header(skb, h_pos); | |
543 | ||
544 | return 0; | |
545 | } | |
546 | EXPORT_SYMBOL(ieee80211_data_from_8023); | |
547 | ||
eaf85ca7 ZY |
548 | |
549 | void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list, | |
550 | const u8 *addr, enum nl80211_iftype iftype, | |
8b3becad YAP |
551 | const unsigned int extra_headroom, |
552 | bool has_80211_header) | |
eaf85ca7 ZY |
553 | { |
554 | struct sk_buff *frame = NULL; | |
555 | u16 ethertype; | |
556 | u8 *payload; | |
557 | const struct ethhdr *eth; | |
558 | int remaining, err; | |
559 | u8 dst[ETH_ALEN], src[ETH_ALEN]; | |
560 | ||
8b3becad YAP |
561 | if (has_80211_header) { |
562 | err = ieee80211_data_to_8023(skb, addr, iftype); | |
563 | if (err) | |
564 | goto out; | |
eaf85ca7 | 565 | |
8b3becad YAP |
566 | /* skip the wrapping header */ |
567 | eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr)); | |
568 | if (!eth) | |
569 | goto out; | |
570 | } else { | |
571 | eth = (struct ethhdr *) skb->data; | |
572 | } | |
eaf85ca7 ZY |
573 | |
574 | while (skb != frame) { | |
575 | u8 padding; | |
576 | __be16 len = eth->h_proto; | |
577 | unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len); | |
578 | ||
579 | remaining = skb->len; | |
580 | memcpy(dst, eth->h_dest, ETH_ALEN); | |
581 | memcpy(src, eth->h_source, ETH_ALEN); | |
582 | ||
583 | padding = (4 - subframe_len) & 0x3; | |
584 | /* the last MSDU has no padding */ | |
585 | if (subframe_len > remaining) | |
586 | goto purge; | |
587 | ||
588 | skb_pull(skb, sizeof(struct ethhdr)); | |
589 | /* reuse skb for the last subframe */ | |
590 | if (remaining <= subframe_len + padding) | |
591 | frame = skb; | |
592 | else { | |
593 | unsigned int hlen = ALIGN(extra_headroom, 4); | |
594 | /* | |
595 | * Allocate and reserve two bytes more for payload | |
596 | * alignment since sizeof(struct ethhdr) is 14. | |
597 | */ | |
598 | frame = dev_alloc_skb(hlen + subframe_len + 2); | |
599 | if (!frame) | |
600 | goto purge; | |
601 | ||
602 | skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2); | |
603 | memcpy(skb_put(frame, ntohs(len)), skb->data, | |
604 | ntohs(len)); | |
605 | ||
606 | eth = (struct ethhdr *)skb_pull(skb, ntohs(len) + | |
607 | padding); | |
608 | if (!eth) { | |
609 | dev_kfree_skb(frame); | |
610 | goto purge; | |
611 | } | |
612 | } | |
613 | ||
614 | skb_reset_network_header(frame); | |
615 | frame->dev = skb->dev; | |
616 | frame->priority = skb->priority; | |
617 | ||
618 | payload = frame->data; | |
619 | ethertype = (payload[6] << 8) | payload[7]; | |
620 | ||
621 | if (likely((compare_ether_addr(payload, rfc1042_header) == 0 && | |
622 | ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || | |
623 | compare_ether_addr(payload, | |
624 | bridge_tunnel_header) == 0)) { | |
625 | /* remove RFC1042 or Bridge-Tunnel | |
626 | * encapsulation and replace EtherType */ | |
627 | skb_pull(frame, 6); | |
628 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); | |
629 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); | |
630 | } else { | |
631 | memcpy(skb_push(frame, sizeof(__be16)), &len, | |
632 | sizeof(__be16)); | |
633 | memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN); | |
634 | memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN); | |
635 | } | |
636 | __skb_queue_tail(list, frame); | |
637 | } | |
638 | ||
639 | return; | |
640 | ||
641 | purge: | |
642 | __skb_queue_purge(list); | |
643 | out: | |
644 | dev_kfree_skb(skb); | |
645 | } | |
646 | EXPORT_SYMBOL(ieee80211_amsdu_to_8023s); | |
647 | ||
e31a16d6 ZY |
648 | /* Given a data frame determine the 802.1p/1d tag to use. */ |
649 | unsigned int cfg80211_classify8021d(struct sk_buff *skb) | |
650 | { | |
651 | unsigned int dscp; | |
652 | ||
653 | /* skb->priority values from 256->263 are magic values to | |
654 | * directly indicate a specific 802.1d priority. This is used | |
655 | * to allow 802.1d priority to be passed directly in from VLAN | |
656 | * tags, etc. | |
657 | */ | |
658 | if (skb->priority >= 256 && skb->priority <= 263) | |
659 | return skb->priority - 256; | |
660 | ||
661 | switch (skb->protocol) { | |
662 | case htons(ETH_P_IP): | |
663 | dscp = ip_hdr(skb)->tos & 0xfc; | |
664 | break; | |
665 | default: | |
666 | return 0; | |
667 | } | |
668 | ||
669 | return dscp >> 5; | |
670 | } | |
671 | EXPORT_SYMBOL(cfg80211_classify8021d); | |
517357c6 JB |
672 | |
673 | const u8 *ieee80211_bss_get_ie(struct cfg80211_bss *bss, u8 ie) | |
674 | { | |
675 | u8 *end, *pos; | |
676 | ||
677 | pos = bss->information_elements; | |
678 | if (pos == NULL) | |
679 | return NULL; | |
680 | end = pos + bss->len_information_elements; | |
681 | ||
682 | while (pos + 1 < end) { | |
683 | if (pos + 2 + pos[1] > end) | |
684 | break; | |
685 | if (pos[0] == ie) | |
686 | return pos; | |
687 | pos += 2 + pos[1]; | |
688 | } | |
689 | ||
690 | return NULL; | |
691 | } | |
692 | EXPORT_SYMBOL(ieee80211_bss_get_ie); | |
fffd0934 JB |
693 | |
694 | void cfg80211_upload_connect_keys(struct wireless_dev *wdev) | |
695 | { | |
696 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
697 | struct net_device *dev = wdev->netdev; | |
698 | int i; | |
699 | ||
700 | if (!wdev->connect_keys) | |
701 | return; | |
702 | ||
703 | for (i = 0; i < 6; i++) { | |
704 | if (!wdev->connect_keys->params[i].cipher) | |
705 | continue; | |
e31b8213 | 706 | if (rdev->ops->add_key(wdev->wiphy, dev, i, false, NULL, |
1e056665 | 707 | &wdev->connect_keys->params[i])) { |
e9c0268f | 708 | netdev_err(dev, "failed to set key %d\n", i); |
1e056665 ZY |
709 | continue; |
710 | } | |
fffd0934 | 711 | if (wdev->connect_keys->def == i) |
dbd2fd65 JB |
712 | if (rdev->ops->set_default_key(wdev->wiphy, dev, |
713 | i, true, true)) { | |
e9c0268f | 714 | netdev_err(dev, "failed to set defkey %d\n", i); |
1e056665 ZY |
715 | continue; |
716 | } | |
fffd0934 JB |
717 | if (wdev->connect_keys->defmgmt == i) |
718 | if (rdev->ops->set_default_mgmt_key(wdev->wiphy, dev, i)) | |
e9c0268f | 719 | netdev_err(dev, "failed to set mgtdef %d\n", i); |
fffd0934 JB |
720 | } |
721 | ||
722 | kfree(wdev->connect_keys); | |
723 | wdev->connect_keys = NULL; | |
724 | } | |
3d54d255 JB |
725 | |
726 | static void cfg80211_process_wdev_events(struct wireless_dev *wdev) | |
727 | { | |
728 | struct cfg80211_event *ev; | |
729 | unsigned long flags; | |
730 | const u8 *bssid = NULL; | |
731 | ||
732 | spin_lock_irqsave(&wdev->event_lock, flags); | |
733 | while (!list_empty(&wdev->event_list)) { | |
734 | ev = list_first_entry(&wdev->event_list, | |
735 | struct cfg80211_event, list); | |
736 | list_del(&ev->list); | |
737 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
738 | ||
739 | wdev_lock(wdev); | |
740 | switch (ev->type) { | |
741 | case EVENT_CONNECT_RESULT: | |
742 | if (!is_zero_ether_addr(ev->cr.bssid)) | |
743 | bssid = ev->cr.bssid; | |
744 | __cfg80211_connect_result( | |
745 | wdev->netdev, bssid, | |
746 | ev->cr.req_ie, ev->cr.req_ie_len, | |
747 | ev->cr.resp_ie, ev->cr.resp_ie_len, | |
748 | ev->cr.status, | |
749 | ev->cr.status == WLAN_STATUS_SUCCESS, | |
750 | NULL); | |
751 | break; | |
752 | case EVENT_ROAMED: | |
ed9d0102 | 753 | __cfg80211_roamed(wdev, ev->rm.channel, ev->rm.bssid, |
3d54d255 JB |
754 | ev->rm.req_ie, ev->rm.req_ie_len, |
755 | ev->rm.resp_ie, ev->rm.resp_ie_len); | |
756 | break; | |
757 | case EVENT_DISCONNECTED: | |
758 | __cfg80211_disconnected(wdev->netdev, | |
759 | ev->dc.ie, ev->dc.ie_len, | |
760 | ev->dc.reason, true); | |
761 | break; | |
762 | case EVENT_IBSS_JOINED: | |
763 | __cfg80211_ibss_joined(wdev->netdev, ev->ij.bssid); | |
764 | break; | |
765 | } | |
766 | wdev_unlock(wdev); | |
767 | ||
768 | kfree(ev); | |
769 | ||
770 | spin_lock_irqsave(&wdev->event_lock, flags); | |
771 | } | |
772 | spin_unlock_irqrestore(&wdev->event_lock, flags); | |
773 | } | |
774 | ||
775 | void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev) | |
776 | { | |
777 | struct wireless_dev *wdev; | |
778 | ||
779 | ASSERT_RTNL(); | |
780 | ASSERT_RDEV_LOCK(rdev); | |
781 | ||
782 | mutex_lock(&rdev->devlist_mtx); | |
783 | ||
784 | list_for_each_entry(wdev, &rdev->netdev_list, list) | |
785 | cfg80211_process_wdev_events(wdev); | |
786 | ||
787 | mutex_unlock(&rdev->devlist_mtx); | |
788 | } | |
789 | ||
790 | int cfg80211_change_iface(struct cfg80211_registered_device *rdev, | |
791 | struct net_device *dev, enum nl80211_iftype ntype, | |
792 | u32 *flags, struct vif_params *params) | |
793 | { | |
794 | int err; | |
795 | enum nl80211_iftype otype = dev->ieee80211_ptr->iftype; | |
796 | ||
797 | ASSERT_RDEV_LOCK(rdev); | |
798 | ||
799 | /* don't support changing VLANs, you just re-create them */ | |
800 | if (otype == NL80211_IFTYPE_AP_VLAN) | |
801 | return -EOPNOTSUPP; | |
802 | ||
803 | if (!rdev->ops->change_virtual_intf || | |
804 | !(rdev->wiphy.interface_modes & (1 << ntype))) | |
805 | return -EOPNOTSUPP; | |
806 | ||
ad4bb6f8 | 807 | /* if it's part of a bridge, reject changing type to station/ibss */ |
f350a0a8 | 808 | if ((dev->priv_flags & IFF_BRIDGE_PORT) && |
074ac8df JB |
809 | (ntype == NL80211_IFTYPE_ADHOC || |
810 | ntype == NL80211_IFTYPE_STATION || | |
811 | ntype == NL80211_IFTYPE_P2P_CLIENT)) | |
ad4bb6f8 JB |
812 | return -EBUSY; |
813 | ||
3d54d255 | 814 | if (ntype != otype) { |
7527a782 JB |
815 | err = cfg80211_can_change_interface(rdev, dev->ieee80211_ptr, |
816 | ntype); | |
817 | if (err) | |
818 | return err; | |
819 | ||
9bc383de | 820 | dev->ieee80211_ptr->use_4addr = false; |
29cbe68c | 821 | dev->ieee80211_ptr->mesh_id_up_len = 0; |
9bc383de | 822 | |
3d54d255 JB |
823 | switch (otype) { |
824 | case NL80211_IFTYPE_ADHOC: | |
825 | cfg80211_leave_ibss(rdev, dev, false); | |
826 | break; | |
827 | case NL80211_IFTYPE_STATION: | |
074ac8df | 828 | case NL80211_IFTYPE_P2P_CLIENT: |
3d54d255 JB |
829 | cfg80211_disconnect(rdev, dev, |
830 | WLAN_REASON_DEAUTH_LEAVING, true); | |
831 | break; | |
832 | case NL80211_IFTYPE_MESH_POINT: | |
833 | /* mesh should be handled? */ | |
834 | break; | |
835 | default: | |
836 | break; | |
837 | } | |
838 | ||
839 | cfg80211_process_rdev_events(rdev); | |
840 | } | |
841 | ||
842 | err = rdev->ops->change_virtual_intf(&rdev->wiphy, dev, | |
843 | ntype, flags, params); | |
844 | ||
845 | WARN_ON(!err && dev->ieee80211_ptr->iftype != ntype); | |
846 | ||
9bc383de JB |
847 | if (!err && params && params->use_4addr != -1) |
848 | dev->ieee80211_ptr->use_4addr = params->use_4addr; | |
849 | ||
ad4bb6f8 JB |
850 | if (!err) { |
851 | dev->priv_flags &= ~IFF_DONT_BRIDGE; | |
852 | switch (ntype) { | |
853 | case NL80211_IFTYPE_STATION: | |
854 | if (dev->ieee80211_ptr->use_4addr) | |
855 | break; | |
856 | /* fall through */ | |
074ac8df | 857 | case NL80211_IFTYPE_P2P_CLIENT: |
ad4bb6f8 JB |
858 | case NL80211_IFTYPE_ADHOC: |
859 | dev->priv_flags |= IFF_DONT_BRIDGE; | |
860 | break; | |
074ac8df | 861 | case NL80211_IFTYPE_P2P_GO: |
ad4bb6f8 JB |
862 | case NL80211_IFTYPE_AP: |
863 | case NL80211_IFTYPE_AP_VLAN: | |
864 | case NL80211_IFTYPE_WDS: | |
865 | case NL80211_IFTYPE_MESH_POINT: | |
866 | /* bridging OK */ | |
867 | break; | |
868 | case NL80211_IFTYPE_MONITOR: | |
869 | /* monitor can't bridge anyway */ | |
870 | break; | |
871 | case NL80211_IFTYPE_UNSPECIFIED: | |
2e161f78 | 872 | case NUM_NL80211_IFTYPES: |
ad4bb6f8 JB |
873 | /* not happening */ |
874 | break; | |
875 | } | |
876 | } | |
877 | ||
3d54d255 JB |
878 | return err; |
879 | } | |
254416aa JL |
880 | |
881 | u16 cfg80211_calculate_bitrate(struct rate_info *rate) | |
882 | { | |
883 | int modulation, streams, bitrate; | |
884 | ||
885 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) | |
886 | return rate->legacy; | |
887 | ||
888 | /* the formula below does only work for MCS values smaller than 32 */ | |
889 | if (rate->mcs >= 32) | |
890 | return 0; | |
891 | ||
892 | modulation = rate->mcs & 7; | |
893 | streams = (rate->mcs >> 3) + 1; | |
894 | ||
895 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? | |
896 | 13500000 : 6500000; | |
897 | ||
898 | if (modulation < 4) | |
899 | bitrate *= (modulation + 1); | |
900 | else if (modulation == 4) | |
901 | bitrate *= (modulation + 2); | |
902 | else | |
903 | bitrate *= (modulation + 3); | |
904 | ||
905 | bitrate *= streams; | |
906 | ||
907 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | |
908 | bitrate = (bitrate / 9) * 10; | |
909 | ||
910 | /* do NOT round down here */ | |
911 | return (bitrate + 50000) / 100000; | |
912 | } | |
56d1893d JB |
913 | |
914 | int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev, | |
915 | u32 beacon_int) | |
916 | { | |
917 | struct wireless_dev *wdev; | |
918 | int res = 0; | |
919 | ||
920 | if (!beacon_int) | |
921 | return -EINVAL; | |
922 | ||
923 | mutex_lock(&rdev->devlist_mtx); | |
924 | ||
925 | list_for_each_entry(wdev, &rdev->netdev_list, list) { | |
926 | if (!wdev->beacon_interval) | |
927 | continue; | |
928 | if (wdev->beacon_interval != beacon_int) { | |
929 | res = -EINVAL; | |
930 | break; | |
931 | } | |
932 | } | |
933 | ||
934 | mutex_unlock(&rdev->devlist_mtx); | |
935 | ||
936 | return res; | |
937 | } | |
7527a782 JB |
938 | |
939 | int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev, | |
940 | struct wireless_dev *wdev, | |
941 | enum nl80211_iftype iftype) | |
942 | { | |
943 | struct wireless_dev *wdev_iter; | |
944 | int num[NUM_NL80211_IFTYPES]; | |
945 | int total = 1; | |
946 | int i, j; | |
947 | ||
948 | ASSERT_RTNL(); | |
949 | ||
950 | /* Always allow software iftypes */ | |
951 | if (rdev->wiphy.software_iftypes & BIT(iftype)) | |
952 | return 0; | |
953 | ||
954 | /* | |
955 | * Drivers will gradually all set this flag, until all | |
956 | * have it we only enforce for those that set it. | |
957 | */ | |
958 | if (!(rdev->wiphy.flags & WIPHY_FLAG_ENFORCE_COMBINATIONS)) | |
959 | return 0; | |
960 | ||
961 | memset(num, 0, sizeof(num)); | |
962 | ||
963 | num[iftype] = 1; | |
964 | ||
965 | mutex_lock(&rdev->devlist_mtx); | |
966 | list_for_each_entry(wdev_iter, &rdev->netdev_list, list) { | |
967 | if (wdev_iter == wdev) | |
968 | continue; | |
969 | if (!netif_running(wdev_iter->netdev)) | |
970 | continue; | |
971 | ||
972 | if (rdev->wiphy.software_iftypes & BIT(wdev_iter->iftype)) | |
973 | continue; | |
974 | ||
975 | num[wdev_iter->iftype]++; | |
976 | total++; | |
977 | } | |
978 | mutex_unlock(&rdev->devlist_mtx); | |
979 | ||
980 | for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) { | |
981 | const struct ieee80211_iface_combination *c; | |
982 | struct ieee80211_iface_limit *limits; | |
983 | ||
984 | c = &rdev->wiphy.iface_combinations[i]; | |
985 | ||
986 | limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits, | |
987 | GFP_KERNEL); | |
988 | if (!limits) | |
989 | return -ENOMEM; | |
990 | if (total > c->max_interfaces) | |
991 | goto cont; | |
992 | ||
993 | for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) { | |
994 | if (rdev->wiphy.software_iftypes & BIT(iftype)) | |
995 | continue; | |
996 | for (j = 0; j < c->n_limits; j++) { | |
997 | if (!(limits[j].types & iftype)) | |
998 | continue; | |
999 | if (limits[j].max < num[iftype]) | |
1000 | goto cont; | |
1001 | limits[j].max -= num[iftype]; | |
1002 | } | |
1003 | } | |
1004 | /* yay, it fits */ | |
1005 | kfree(limits); | |
1006 | return 0; | |
1007 | cont: | |
1008 | kfree(limits); | |
1009 | } | |
1010 | ||
1011 | return -EBUSY; | |
1012 | } | |
34850ab2 JB |
1013 | |
1014 | int ieee80211_get_ratemask(struct ieee80211_supported_band *sband, | |
1015 | const u8 *rates, unsigned int n_rates, | |
1016 | u32 *mask) | |
1017 | { | |
1018 | int i, j; | |
1019 | ||
a401d2bb JB |
1020 | if (!sband) |
1021 | return -EINVAL; | |
1022 | ||
34850ab2 JB |
1023 | if (n_rates == 0 || n_rates > NL80211_MAX_SUPP_RATES) |
1024 | return -EINVAL; | |
1025 | ||
1026 | *mask = 0; | |
1027 | ||
1028 | for (i = 0; i < n_rates; i++) { | |
1029 | int rate = (rates[i] & 0x7f) * 5; | |
1030 | bool found = false; | |
1031 | ||
1032 | for (j = 0; j < sband->n_bitrates; j++) { | |
1033 | if (sband->bitrates[j].bitrate == rate) { | |
1034 | found = true; | |
1035 | *mask |= BIT(j); | |
1036 | break; | |
1037 | } | |
1038 | } | |
1039 | if (!found) | |
1040 | return -EINVAL; | |
1041 | } | |
1042 | ||
1043 | /* | |
1044 | * mask must have at least one bit set here since we | |
1045 | * didn't accept a 0-length rates array nor allowed | |
1046 | * entries in the array that didn't exist | |
1047 | */ | |
1048 | ||
1049 | return 0; | |
1050 | } |