2 * Copyright 2007-2012 Siemens AG
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.
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.
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>
20 #include <linux/netdevice.h>
21 #include <linux/if_arp.h>
22 #include <linux/crc-ccitt.h>
23 #include <asm/unaligned.h>
25 #include <net/rtnetlink.h>
26 #include <net/ieee802154_netdev.h>
27 #include <net/mac802154.h>
28 #include <net/cfg802154.h>
30 #include "ieee802154_i.h"
31 #include "driver-ops.h"
33 void ieee802154_xmit_worker(struct work_struct
*work
)
35 struct ieee802154_local
*local
=
36 container_of(work
, struct ieee802154_local
, tx_work
);
37 struct sk_buff
*skb
= local
->tx_skb
;
38 struct net_device
*dev
= skb
->dev
;
43 /* check if ifdown occurred while schedule */
44 if (!netif_running(dev
))
47 res
= drv_xmit_sync(local
, skb
);
51 ieee802154_xmit_complete(&local
->hw
, skb
, false);
53 dev
->stats
.tx_packets
++;
54 dev
->stats
.tx_bytes
+= skb
->len
;
61 /* Restart the netif queue on each sub_if_data object. */
62 ieee802154_wake_queue(&local
->hw
);
65 netdev_dbg(dev
, "transmission failed\n");
69 ieee802154_tx(struct ieee802154_local
*local
, struct sk_buff
*skb
)
71 struct net_device
*dev
= skb
->dev
;
74 if (!(local
->hw
.flags
& IEEE802154_HW_TX_OMIT_CKSUM
)) {
75 u16 crc
= crc_ccitt(0, skb
->data
, skb
->len
);
77 put_unaligned_le16(crc
, skb_put(skb
, 2));
80 /* Stop the netif queue on each sub_if_data object. */
81 ieee802154_stop_queue(&local
->hw
);
83 /* async is priority, otherwise sync is fallback */
84 if (local
->ops
->xmit_async
) {
85 ret
= drv_xmit_async(local
, skb
);
87 ieee802154_wake_queue(&local
->hw
);
91 dev
->stats
.tx_packets
++;
92 dev
->stats
.tx_bytes
+= skb
->len
;
95 queue_work(local
->workqueue
, &local
->tx_work
);
106 ieee802154_monitor_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
108 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
110 skb
->skb_iif
= dev
->ifindex
;
112 return ieee802154_tx(sdata
->local
, skb
);
116 ieee802154_subif_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
118 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
121 /* TODO we should move it to wpan_dev_hard_header and dev_hard_header
122 * functions. The reason is wireshark will show a mac header which is
123 * with security fields but the payload is not encrypted.
125 rc
= mac802154_llsec_encrypt(&sdata
->sec
, skb
);
127 netdev_warn(dev
, "encryption failed: %i\n", rc
);
132 skb
->skb_iif
= dev
->ifindex
;
134 return ieee802154_tx(sdata
->local
, skb
);