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