Commit | Line | Data |
---|---|---|
5b641ebe | 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 | * | |
5b641ebe | 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 | ||
20 | #include <linux/netdevice.h> | |
21 | #include <linux/if_arp.h> | |
22 | #include <linux/crc-ccitt.h> | |
061ef8f9 | 23 | #include <asm/unaligned.h> |
5b641ebe | 24 | |
6001d522 | 25 | #include <net/rtnetlink.h> |
b5992fe9 | 26 | #include <net/ieee802154_netdev.h> |
5b641ebe | 27 | #include <net/mac802154.h> |
5ad60d36 | 28 | #include <net/cfg802154.h> |
5b641ebe | 29 | |
0f1556bc | 30 | #include "ieee802154_i.h" |
59cb300f | 31 | #include "driver-ops.h" |
5b641ebe | 32 | |
c22ff7b4 | 33 | void ieee802154_xmit_worker(struct work_struct *work) |
5b641ebe | 34 | { |
c22ff7b4 LB |
35 | struct ieee802154_local *local = |
36 | container_of(work, struct ieee802154_local, tx_work); | |
37 | struct sk_buff *skb = local->tx_skb; | |
409c3b0c | 38 | struct net_device *dev = skb->dev; |
5b641ebe | 39 | int res; |
40 | ||
59cb300f | 41 | res = drv_xmit_sync(local, skb); |
6001d522 AA |
42 | if (res) |
43 | goto err_tx; | |
44 | ||
61f2dcba | 45 | ieee802154_xmit_complete(&local->hw, skb, false); |
6001d522 | 46 | |
409c3b0c AA |
47 | dev->stats.tx_packets++; |
48 | dev->stats.tx_bytes += skb->len; | |
49 | ||
6001d522 AA |
50 | return; |
51 | ||
52 | err_tx: | |
53 | /* Restart the netif queue on each sub_if_data object. */ | |
54 | ieee802154_wake_queue(&local->hw); | |
6001d522 | 55 | kfree_skb(skb); |
409c3b0c | 56 | netdev_dbg(dev, "transmission failed\n"); |
5b641ebe | 57 | } |
58 | ||
dc67c6b3 | 59 | static netdev_tx_t |
e5e584fc | 60 | ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb) |
5b641ebe | 61 | { |
409c3b0c | 62 | struct net_device *dev = skb->dev; |
ed0a5dce | 63 | int ret; |
5b641ebe | 64 | |
90386a7e | 65 | if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) { |
f9c52831 AA |
66 | struct sk_buff *nskb; |
67 | u16 crc; | |
4710d806 | 68 | |
f9c52831 AA |
69 | if (unlikely(skb_tailroom(skb) < IEEE802154_FCS_LEN)) { |
70 | nskb = skb_copy_expand(skb, 0, IEEE802154_FCS_LEN, | |
71 | GFP_ATOMIC); | |
72 | if (likely(nskb)) { | |
73 | consume_skb(skb); | |
74 | skb = nskb; | |
75 | } else { | |
76 | goto err_tx; | |
77 | } | |
78 | } | |
79 | ||
80 | crc = crc_ccitt(0, skb->data, skb->len); | |
061ef8f9 | 81 | put_unaligned_le16(crc, skb_put(skb, 2)); |
5b641ebe | 82 | } |
83 | ||
b5992fe9 | 84 | /* Stop the netif queue on each sub_if_data object. */ |
18d60a0d | 85 | ieee802154_stop_queue(&local->hw); |
b5992fe9 | 86 | |
ed0a5dce AA |
87 | /* async is priority, otherwise sync is fallback */ |
88 | if (local->ops->xmit_async) { | |
59cb300f | 89 | ret = drv_xmit_async(local, skb); |
ed0a5dce AA |
90 | if (ret) { |
91 | ieee802154_wake_queue(&local->hw); | |
92 | goto err_tx; | |
93 | } | |
409c3b0c AA |
94 | |
95 | dev->stats.tx_packets++; | |
96 | dev->stats.tx_bytes += skb->len; | |
ed0a5dce | 97 | } else { |
c22ff7b4 LB |
98 | local->tx_skb = skb; |
99 | queue_work(local->workqueue, &local->tx_work); | |
ed0a5dce | 100 | } |
5b641ebe | 101 | |
102 | return NETDEV_TX_OK; | |
f5588912 VB |
103 | |
104 | err_tx: | |
105 | kfree_skb(skb); | |
106 | return NETDEV_TX_OK; | |
5b641ebe | 107 | } |
50c6fb99 | 108 | |
e5e584fc AA |
109 | netdev_tx_t |
110 | ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
50c6fb99 AA |
111 | { |
112 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | |
50c6fb99 AA |
113 | |
114 | skb->skb_iif = dev->ifindex; | |
50c6fb99 | 115 | |
e5e584fc | 116 | return ieee802154_tx(sdata->local, skb); |
50c6fb99 AA |
117 | } |
118 | ||
e5e584fc AA |
119 | netdev_tx_t |
120 | ieee802154_subif_start_xmit(struct sk_buff *skb, struct net_device *dev) | |
50c6fb99 AA |
121 | { |
122 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | |
50c6fb99 AA |
123 | int rc; |
124 | ||
d58a2fa9 AA |
125 | /* TODO we should move it to wpan_dev_hard_header and dev_hard_header |
126 | * functions. The reason is wireshark will show a mac header which is | |
127 | * with security fields but the payload is not encrypted. | |
128 | */ | |
50c6fb99 AA |
129 | rc = mac802154_llsec_encrypt(&sdata->sec, skb); |
130 | if (rc) { | |
cfa626cb | 131 | netdev_warn(dev, "encryption failed: %i\n", rc); |
50c6fb99 AA |
132 | kfree_skb(skb); |
133 | return NETDEV_TX_OK; | |
134 | } | |
135 | ||
136 | skb->skb_iif = dev->ifindex; | |
50c6fb99 | 137 | |
e5e584fc | 138 | return ieee802154_tx(sdata->local, skb); |
50c6fb99 | 139 | } |