aboutsummaryrefslogtreecommitdiffstats
path: root/net/ieee80211/ieee80211_tx.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ieee80211/ieee80211_tx.c')
-rw-r--r--net/ieee80211/ieee80211_tx.c310
1 files changed, 228 insertions, 82 deletions
diff --git a/net/ieee80211/ieee80211_tx.c b/net/ieee80211/ieee80211_tx.c
index ecdf9f7a538..4644338ac57 100644
--- a/net/ieee80211/ieee80211_tx.c
+++ b/net/ieee80211/ieee80211_tx.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2 2
3 Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved. 3 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
4 4
5 This program is free software; you can redistribute it and/or modify it 5 This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as 6 under the terms of version 2 of the GNU General Public License as
@@ -128,7 +128,7 @@ payload of each frame is reduced to 492 bytes.
128static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 }; 128static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
129static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 }; 129static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
130 130
131static inline int ieee80211_put_snap(u8 * data, u16 h_proto) 131static inline int ieee80211_copy_snap(u8 * data, u16 h_proto)
132{ 132{
133 struct ieee80211_snap_hdr *snap; 133 struct ieee80211_snap_hdr *snap;
134 u8 *oui; 134 u8 *oui;
@@ -157,31 +157,11 @@ static inline int ieee80211_encrypt_fragment(struct ieee80211_device *ieee,
157 struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx]; 157 struct ieee80211_crypt_data *crypt = ieee->crypt[ieee->tx_keyidx];
158 int res; 158 int res;
159 159
160#ifdef CONFIG_IEEE80211_CRYPT_TKIP
161 struct ieee80211_hdr *header;
162
163 if (ieee->tkip_countermeasures &&
164 crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) {
165 header = (struct ieee80211_hdr *)frag->data;
166 if (net_ratelimit()) {
167 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
168 "TX packet to " MAC_FMT "\n",
169 ieee->dev->name, MAC_ARG(header->addr1));
170 }
171 return -1;
172 }
173#endif
174 /* To encrypt, frame format is: 160 /* To encrypt, frame format is:
175 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */ 161 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */
176
177 // PR: FIXME: Copied from hostap. Check fragmentation/MSDU/MPDU encryption.
178 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
179 * call both MSDU and MPDU encryption functions from here. */
180 atomic_inc(&crypt->refcnt); 162 atomic_inc(&crypt->refcnt);
181 res = 0; 163 res = 0;
182 if (crypt->ops->encrypt_msdu) 164 if (crypt->ops->encrypt_mpdu)
183 res = crypt->ops->encrypt_msdu(frag, hdr_len, crypt->priv);
184 if (res == 0 && crypt->ops->encrypt_mpdu)
185 res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv); 165 res = crypt->ops->encrypt_mpdu(frag, hdr_len, crypt->priv);
186 166
187 atomic_dec(&crypt->refcnt); 167 atomic_dec(&crypt->refcnt);
@@ -236,25 +216,31 @@ static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
236 return txb; 216 return txb;
237} 217}
238 218
239/* SKBs are added to the ieee->tx_queue. */ 219/* Incoming skb is converted to a txb which consists of
220 * a block of 802.11 fragment packets (stored as skbs) */
240int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev) 221int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
241{ 222{
242 struct ieee80211_device *ieee = netdev_priv(dev); 223 struct ieee80211_device *ieee = netdev_priv(dev);
243 struct ieee80211_txb *txb = NULL; 224 struct ieee80211_txb *txb = NULL;
244 struct ieee80211_hdr *frag_hdr; 225 struct ieee80211_hdr_3addr *frag_hdr;
245 int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size; 226 int i, bytes_per_frag, nr_frags, bytes_last_frag, frag_size,
227 rts_required;
246 unsigned long flags; 228 unsigned long flags;
247 struct net_device_stats *stats = &ieee->stats; 229 struct net_device_stats *stats = &ieee->stats;
248 int ether_type, encrypt; 230 int ether_type, encrypt, host_encrypt, host_encrypt_msdu, host_build_iv;
249 int bytes, fc, hdr_len; 231 int bytes, fc, hdr_len;
250 struct sk_buff *skb_frag; 232 struct sk_buff *skb_frag;
251 struct ieee80211_hdr header = { /* Ensure zero initialized */ 233 struct ieee80211_hdr_3addr header = { /* Ensure zero initialized */
252 .duration_id = 0, 234 .duration_id = 0,
253 .seq_ctl = 0 235 .seq_ctl = 0
254 }; 236 };
255 u8 dest[ETH_ALEN], src[ETH_ALEN]; 237 u8 dest[ETH_ALEN], src[ETH_ALEN];
256
257 struct ieee80211_crypt_data *crypt; 238 struct ieee80211_crypt_data *crypt;
239 int priority = skb->priority;
240 int snapped = 0;
241
242 if (ieee->is_queue_full && (*ieee->is_queue_full) (dev, priority))
243 return NETDEV_TX_BUSY;
258 244
259 spin_lock_irqsave(&ieee->lock, flags); 245 spin_lock_irqsave(&ieee->lock, flags);
260 246
@@ -276,7 +262,11 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
276 crypt = ieee->crypt[ieee->tx_keyidx]; 262 crypt = ieee->crypt[ieee->tx_keyidx];
277 263
278 encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) && 264 encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) &&
279 ieee->host_encrypt && crypt && crypt->ops; 265 ieee->sec.encrypt;
266
267 host_encrypt = ieee->host_encrypt && encrypt;
268 host_encrypt_msdu = ieee->host_encrypt_msdu && encrypt;
269 host_build_iv = ieee->host_build_iv && encrypt;
280 270
281 if (!encrypt && ieee->ieee802_1x && 271 if (!encrypt && ieee->ieee802_1x &&
282 ieee->drop_unencrypted && ether_type != ETH_P_PAE) { 272 ieee->drop_unencrypted && ether_type != ETH_P_PAE) {
@@ -285,8 +275,8 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
285 } 275 }
286 276
287 /* Save source and destination addresses */ 277 /* Save source and destination addresses */
288 memcpy(&dest, skb->data, ETH_ALEN); 278 memcpy(dest, skb->data, ETH_ALEN);
289 memcpy(&src, skb->data + ETH_ALEN, ETH_ALEN); 279 memcpy(src, skb->data + ETH_ALEN, ETH_ALEN);
290 280
291 /* Advance the SKB to the start of the payload */ 281 /* Advance the SKB to the start of the payload */
292 skb_pull(skb, sizeof(struct ethhdr)); 282 skb_pull(skb, sizeof(struct ethhdr));
@@ -294,7 +284,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
294 /* Determine total amount of storage required for TXB packets */ 284 /* Determine total amount of storage required for TXB packets */
295 bytes = skb->len + SNAP_SIZE + sizeof(u16); 285 bytes = skb->len + SNAP_SIZE + sizeof(u16);
296 286
297 if (encrypt) 287 if (host_encrypt)
298 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA | 288 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA |
299 IEEE80211_FCTL_PROTECTED; 289 IEEE80211_FCTL_PROTECTED;
300 else 290 else
@@ -302,50 +292,90 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
302 292
303 if (ieee->iw_mode == IW_MODE_INFRA) { 293 if (ieee->iw_mode == IW_MODE_INFRA) {
304 fc |= IEEE80211_FCTL_TODS; 294 fc |= IEEE80211_FCTL_TODS;
305 /* To DS: Addr1 = BSSID, Addr2 = SA, 295 /* To DS: Addr1 = BSSID, Addr2 = SA, Addr3 = DA */
306 Addr3 = DA */ 296 memcpy(header.addr1, ieee->bssid, ETH_ALEN);
307 memcpy(&header.addr1, ieee->bssid, ETH_ALEN); 297 memcpy(header.addr2, src, ETH_ALEN);
308 memcpy(&header.addr2, &src, ETH_ALEN); 298 memcpy(header.addr3, dest, ETH_ALEN);
309 memcpy(&header.addr3, &dest, ETH_ALEN);
310 } else if (ieee->iw_mode == IW_MODE_ADHOC) { 299 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
311 /* not From/To DS: Addr1 = DA, Addr2 = SA, 300 /* not From/To DS: Addr1 = DA, Addr2 = SA, Addr3 = BSSID */
312 Addr3 = BSSID */ 301 memcpy(header.addr1, dest, ETH_ALEN);
313 memcpy(&header.addr1, dest, ETH_ALEN); 302 memcpy(header.addr2, src, ETH_ALEN);
314 memcpy(&header.addr2, src, ETH_ALEN); 303 memcpy(header.addr3, ieee->bssid, ETH_ALEN);
315 memcpy(&header.addr3, ieee->bssid, ETH_ALEN);
316 } 304 }
317 header.frame_ctl = cpu_to_le16(fc); 305 header.frame_ctl = cpu_to_le16(fc);
318 hdr_len = IEEE80211_3ADDR_LEN; 306 hdr_len = IEEE80211_3ADDR_LEN;
319 307
320 /* Determine fragmentation size based on destination (multicast 308 /* Encrypt msdu first on the whole data packet. */
321 * and broadcast are not fragmented) */ 309 if ((host_encrypt || host_encrypt_msdu) &&
322 if (is_multicast_ether_addr(dest) || is_broadcast_ether_addr(dest)) 310 crypt && crypt->ops && crypt->ops->encrypt_msdu) {
323 frag_size = MAX_FRAG_THRESHOLD; 311 int res = 0;
324 else 312 int len = bytes + hdr_len + crypt->ops->extra_msdu_prefix_len +
325 frag_size = ieee->fts; 313 crypt->ops->extra_msdu_postfix_len;
314 struct sk_buff *skb_new = dev_alloc_skb(len);
315
316 if (unlikely(!skb_new))
317 goto failed;
318
319 skb_reserve(skb_new, crypt->ops->extra_msdu_prefix_len);
320 memcpy(skb_put(skb_new, hdr_len), &header, hdr_len);
321 snapped = 1;
322 ieee80211_copy_snap(skb_put(skb_new, SNAP_SIZE + sizeof(u16)),
323 ether_type);
324 memcpy(skb_put(skb_new, skb->len), skb->data, skb->len);
325 res = crypt->ops->encrypt_msdu(skb_new, hdr_len, crypt->priv);
326 if (res < 0) {
327 IEEE80211_ERROR("msdu encryption failed\n");
328 dev_kfree_skb_any(skb_new);
329 goto failed;
330 }
331 dev_kfree_skb_any(skb);
332 skb = skb_new;
333 bytes += crypt->ops->extra_msdu_prefix_len +
334 crypt->ops->extra_msdu_postfix_len;
335 skb_pull(skb, hdr_len);
336 }
326 337
327 /* Determine amount of payload per fragment. Regardless of if 338 if (host_encrypt || ieee->host_open_frag) {
328 * this stack is providing the full 802.11 header, one will 339 /* Determine fragmentation size based on destination (multicast
329 * eventually be affixed to this fragment -- so we must account for 340 * and broadcast are not fragmented) */
330 * it when determining the amount of payload space. */ 341 if (is_multicast_ether_addr(dest))
331 bytes_per_frag = frag_size - IEEE80211_3ADDR_LEN; 342 frag_size = MAX_FRAG_THRESHOLD;
332 if (ieee->config & 343 else
333 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS)) 344 frag_size = ieee->fts;
334 bytes_per_frag -= IEEE80211_FCS_LEN; 345
335 346 /* Determine amount of payload per fragment. Regardless of if
336 /* Each fragment may need to have room for encryptiong pre/postfix */ 347 * this stack is providing the full 802.11 header, one will
337 if (encrypt) 348 * eventually be affixed to this fragment -- so we must account
338 bytes_per_frag -= crypt->ops->extra_prefix_len + 349 * for it when determining the amount of payload space. */
339 crypt->ops->extra_postfix_len; 350 bytes_per_frag = frag_size - IEEE80211_3ADDR_LEN;
340 351 if (ieee->config &
341 /* Number of fragments is the total bytes_per_frag / 352 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
342 * payload_per_fragment */ 353 bytes_per_frag -= IEEE80211_FCS_LEN;
343 nr_frags = bytes / bytes_per_frag; 354
344 bytes_last_frag = bytes % bytes_per_frag; 355 /* Each fragment may need to have room for encryptiong
345 if (bytes_last_frag) 356 * pre/postfix */
357 if (host_encrypt)
358 bytes_per_frag -= crypt->ops->extra_mpdu_prefix_len +
359 crypt->ops->extra_mpdu_postfix_len;
360
361 /* Number of fragments is the total
362 * bytes_per_frag / payload_per_fragment */
363 nr_frags = bytes / bytes_per_frag;
364 bytes_last_frag = bytes % bytes_per_frag;
365 if (bytes_last_frag)
366 nr_frags++;
367 else
368 bytes_last_frag = bytes_per_frag;
369 } else {
370 nr_frags = 1;
371 bytes_per_frag = bytes_last_frag = bytes;
372 frag_size = bytes + IEEE80211_3ADDR_LEN;
373 }
374
375 rts_required = (frag_size > ieee->rts
376 && ieee->config & CFG_IEEE80211_RTS);
377 if (rts_required)
346 nr_frags++; 378 nr_frags++;
347 else
348 bytes_last_frag = bytes_per_frag;
349 379
350 /* When we allocate the TXB we allocate enough space for the reserve 380 /* When we allocate the TXB we allocate enough space for the reserve
351 * and full fragment bytes (bytes_per_frag doesn't include prefix, 381 * and full fragment bytes (bytes_per_frag doesn't include prefix,
@@ -357,15 +387,47 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
357 goto failed; 387 goto failed;
358 } 388 }
359 txb->encrypted = encrypt; 389 txb->encrypted = encrypt;
360 txb->payload_size = bytes; 390 if (host_encrypt)
391 txb->payload_size = frag_size * (nr_frags - 1) +
392 bytes_last_frag;
393 else
394 txb->payload_size = bytes;
395
396 if (rts_required) {
397 skb_frag = txb->fragments[0];
398 frag_hdr =
399 (struct ieee80211_hdr_3addr *)skb_put(skb_frag, hdr_len);
400
401 /*
402 * Set header frame_ctl to the RTS.
403 */
404 header.frame_ctl =
405 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
406 memcpy(frag_hdr, &header, hdr_len);
361 407
362 for (i = 0; i < nr_frags; i++) { 408 /*
409 * Restore header frame_ctl to the original data setting.
410 */
411 header.frame_ctl = cpu_to_le16(fc);
412
413 if (ieee->config &
414 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
415 skb_put(skb_frag, 4);
416
417 txb->rts_included = 1;
418 i = 1;
419 } else
420 i = 0;
421
422 for (; i < nr_frags; i++) {
363 skb_frag = txb->fragments[i]; 423 skb_frag = txb->fragments[i];
364 424
365 if (encrypt) 425 if (host_encrypt || host_build_iv)
366 skb_reserve(skb_frag, crypt->ops->extra_prefix_len); 426 skb_reserve(skb_frag,
427 crypt->ops->extra_mpdu_prefix_len);
367 428
368 frag_hdr = (struct ieee80211_hdr *)skb_put(skb_frag, hdr_len); 429 frag_hdr =
430 (struct ieee80211_hdr_3addr *)skb_put(skb_frag, hdr_len);
369 memcpy(frag_hdr, &header, hdr_len); 431 memcpy(frag_hdr, &header, hdr_len);
370 432
371 /* If this is not the last fragment, then add the MOREFRAGS 433 /* If this is not the last fragment, then add the MOREFRAGS
@@ -379,11 +441,10 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
379 bytes = bytes_last_frag; 441 bytes = bytes_last_frag;
380 } 442 }
381 443
382 /* Put a SNAP header on the first fragment */ 444 if (i == 0 && !snapped) {
383 if (i == 0) { 445 ieee80211_copy_snap(skb_put
384 ieee80211_put_snap(skb_put 446 (skb_frag, SNAP_SIZE + sizeof(u16)),
385 (skb_frag, SNAP_SIZE + sizeof(u16)), 447 ether_type);
386 ether_type);
387 bytes -= SNAP_SIZE + sizeof(u16); 448 bytes -= SNAP_SIZE + sizeof(u16);
388 } 449 }
389 450
@@ -394,8 +455,19 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
394 455
395 /* Encryption routine will move the header forward in order 456 /* Encryption routine will move the header forward in order
396 * to insert the IV between the header and the payload */ 457 * to insert the IV between the header and the payload */
397 if (encrypt) 458 if (host_encrypt)
398 ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len); 459 ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len);
460 else if (host_build_iv) {
461 struct ieee80211_crypt_data *crypt;
462
463 crypt = ieee->crypt[ieee->tx_keyidx];
464 atomic_inc(&crypt->refcnt);
465 if (crypt->ops->build_iv)
466 crypt->ops->build_iv(skb_frag, hdr_len,
467 crypt->priv);
468 atomic_dec(&crypt->refcnt);
469 }
470
399 if (ieee->config & 471 if (ieee->config &
400 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS)) 472 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
401 skb_put(skb_frag, 4); 473 skb_put(skb_frag, 4);
@@ -407,11 +479,20 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
407 dev_kfree_skb_any(skb); 479 dev_kfree_skb_any(skb);
408 480
409 if (txb) { 481 if (txb) {
410 if ((*ieee->hard_start_xmit) (txb, dev) == 0) { 482 int ret = (*ieee->hard_start_xmit) (txb, dev, priority);
483 if (ret == 0) {
411 stats->tx_packets++; 484 stats->tx_packets++;
412 stats->tx_bytes += txb->payload_size; 485 stats->tx_bytes += txb->payload_size;
413 return 0; 486 return 0;
414 } 487 }
488
489 if (ret == NETDEV_TX_BUSY) {
490 printk(KERN_ERR "%s: NETDEV_TX_BUSY returned; "
491 "driver should report queue full via "
492 "ieee_device->is_queue_full.\n",
493 ieee->dev->name);
494 }
495
415 ieee80211_txb_free(txb); 496 ieee80211_txb_free(txb);
416 } 497 }
417 498
@@ -422,7 +503,72 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
422 netif_stop_queue(dev); 503 netif_stop_queue(dev);
423 stats->tx_errors++; 504 stats->tx_errors++;
424 return 1; 505 return 1;
506}
507
508/* Incoming 802.11 strucure is converted to a TXB
509 * a block of 802.11 fragment packets (stored as skbs) */
510int ieee80211_tx_frame(struct ieee80211_device *ieee,
511 struct ieee80211_hdr *frame, int len)
512{
513 struct ieee80211_txb *txb = NULL;
514 unsigned long flags;
515 struct net_device_stats *stats = &ieee->stats;
516 struct sk_buff *skb_frag;
517 int priority = -1;
518
519 spin_lock_irqsave(&ieee->lock, flags);
425 520
521 /* If there is no driver handler to take the TXB, dont' bother
522 * creating it... */
523 if (!ieee->hard_start_xmit) {
524 printk(KERN_WARNING "%s: No xmit handler.\n", ieee->dev->name);
525 goto success;
526 }
527
528 if (unlikely(len < 24)) {
529 printk(KERN_WARNING "%s: skb too small (%d).\n",
530 ieee->dev->name, len);
531 goto success;
532 }
533
534 /* When we allocate the TXB we allocate enough space for the reserve
535 * and full fragment bytes (bytes_per_frag doesn't include prefix,
536 * postfix, header, FCS, etc.) */
537 txb = ieee80211_alloc_txb(1, len, GFP_ATOMIC);
538 if (unlikely(!txb)) {
539 printk(KERN_WARNING "%s: Could not allocate TXB\n",
540 ieee->dev->name);
541 goto failed;
542 }
543 txb->encrypted = 0;
544 txb->payload_size = len;
545
546 skb_frag = txb->fragments[0];
547
548 memcpy(skb_put(skb_frag, len), frame, len);
549
550 if (ieee->config &
551 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
552 skb_put(skb_frag, 4);
553
554 success:
555 spin_unlock_irqrestore(&ieee->lock, flags);
556
557 if (txb) {
558 if ((*ieee->hard_start_xmit) (txb, ieee->dev, priority) == 0) {
559 stats->tx_packets++;
560 stats->tx_bytes += txb->payload_size;
561 return 0;
562 }
563 ieee80211_txb_free(txb);
564 }
565 return 0;
566
567 failed:
568 spin_unlock_irqrestore(&ieee->lock, flags);
569 stats->tx_errors++;
570 return 1;
426} 571}
427 572
573EXPORT_SYMBOL(ieee80211_tx_frame);
428EXPORT_SYMBOL(ieee80211_txb_free); 574EXPORT_SYMBOL(ieee80211_txb_free);