tx.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright 2007-2012 Siemens AG
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * Written by:
  14. * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
  15. * Sergey Lapin <slapin@ossfans.org>
  16. * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
  17. * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
  18. */
  19. #include <linux/netdevice.h>
  20. #include <linux/if_arp.h>
  21. #include <linux/crc-ccitt.h>
  22. #include <asm/unaligned.h>
  23. #include <net/rtnetlink.h>
  24. #include <net/ieee802154_netdev.h>
  25. #include <net/mac802154.h>
  26. #include <net/cfg802154.h>
  27. #include "ieee802154_i.h"
  28. #include "driver-ops.h"
  29. void ieee802154_xmit_worker(struct work_struct *work)
  30. {
  31. struct ieee802154_local *local =
  32. container_of(work, struct ieee802154_local, tx_work);
  33. struct sk_buff *skb = local->tx_skb;
  34. struct net_device *dev = skb->dev;
  35. int res;
  36. res = drv_xmit_sync(local, skb);
  37. if (res)
  38. goto err_tx;
  39. ieee802154_xmit_complete(&local->hw, skb, false);
  40. dev->stats.tx_packets++;
  41. dev->stats.tx_bytes += skb->len;
  42. return;
  43. err_tx:
  44. /* Restart the netif queue on each sub_if_data object. */
  45. ieee802154_wake_queue(&local->hw);
  46. kfree_skb(skb);
  47. netdev_dbg(dev, "transmission failed\n");
  48. }
  49. static netdev_tx_t
  50. ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
  51. {
  52. struct net_device *dev = skb->dev;
  53. int ret;
  54. if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
  55. u16 crc = crc_ccitt(0, skb->data, skb->len);
  56. put_unaligned_le16(crc, skb_put(skb, 2));
  57. }
  58. /* Stop the netif queue on each sub_if_data object. */
  59. ieee802154_stop_queue(&local->hw);
  60. /* async is priority, otherwise sync is fallback */
  61. if (local->ops->xmit_async) {
  62. ret = drv_xmit_async(local, skb);
  63. if (ret) {
  64. ieee802154_wake_queue(&local->hw);
  65. goto err_tx;
  66. }
  67. dev->stats.tx_packets++;
  68. dev->stats.tx_bytes += skb->len;
  69. } else {
  70. local->tx_skb = skb;
  71. queue_work(local->workqueue, &local->tx_work);
  72. }
  73. return NETDEV_TX_OK;
  74. err_tx:
  75. kfree_skb(skb);
  76. return NETDEV_TX_OK;
  77. }
  78. netdev_tx_t
  79. ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev)
  80. {
  81. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  82. skb->skb_iif = dev->ifindex;
  83. return ieee802154_tx(sdata->local, skb);
  84. }
  85. netdev_tx_t
  86. ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev)
  87. {
  88. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  89. int rc;
  90. /* TODO we should move it to wpan_dev_hard_header and dev_hard_header
  91. * functions. The reason is wireshark will show a mac header which is
  92. * with security fields but the payload is not encrypted.
  93. */
  94. rc = mac802154_llsec_encrypt(&sdata->sec, skb);
  95. if (rc) {
  96. netdev_warn(dev, "encryption failed: %i\n", rc);
  97. kfree_skb(skb);
  98. return NETDEV_TX_OK;
  99. }
  100. skb->skb_iif = dev->ifindex;
  101. return ieee802154_tx(sdata->local, skb);
  102. }