]>
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> | |
23 | ||
b5992fe9 | 24 | #include <net/ieee802154_netdev.h> |
5b641ebe | 25 | #include <net/mac802154.h> |
5ad60d36 | 26 | #include <net/cfg802154.h> |
5b641ebe | 27 | |
0f1556bc | 28 | #include "ieee802154_i.h" |
5b641ebe | 29 | |
30 | /* IEEE 802.15.4 transceivers can sleep during the xmit session, so process | |
31 | * packets through the workqueue. | |
32 | */ | |
fe24371d | 33 | struct wpan_xmit_cb { |
5b641ebe | 34 | struct sk_buff *skb; |
35 | struct work_struct work; | |
a5e1ec53 | 36 | struct ieee802154_local *local; |
5b641ebe | 37 | }; |
38 | ||
fe24371d AA |
39 | static inline struct wpan_xmit_cb *wpan_xmit_cb(const struct sk_buff *skb) |
40 | { | |
41 | BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct wpan_xmit_cb)); | |
42 | ||
43 | return (struct wpan_xmit_cb *)skb->cb; | |
44 | } | |
45 | ||
5b641ebe | 46 | static void mac802154_xmit_worker(struct work_struct *work) |
47 | { | |
fe24371d | 48 | struct wpan_xmit_cb *cb = container_of(work, struct wpan_xmit_cb, work); |
e89e45f2 | 49 | struct ieee802154_local *local = cb->local; |
e89e45f2 | 50 | struct sk_buff *skb = cb->skb; |
5b641ebe | 51 | int res; |
52 | ||
ed0a5dce | 53 | res = local->ops->xmit_sync(&local->hw, skb); |
cdb66bea | 54 | if (res) { |
7dd43d35 | 55 | pr_debug("transmission failed\n"); |
cdb66bea AA |
56 | /* Restart the netif queue on each sub_if_data object. */ |
57 | ieee802154_wake_queue(&local->hw); | |
58 | kfree_skb(skb); | |
59 | } else { | |
60 | /* Restart the netif queue on each sub_if_data object. */ | |
61 | ieee802154_xmit_complete(&local->hw, skb); | |
62 | } | |
5b641ebe | 63 | } |
64 | ||
dc67c6b3 AA |
65 | static netdev_tx_t |
66 | mac802154_tx(struct ieee802154_local *local, struct sk_buff *skb) | |
5b641ebe | 67 | { |
fe24371d | 68 | struct wpan_xmit_cb *cb = wpan_xmit_cb(skb); |
ed0a5dce | 69 | int ret; |
5b641ebe | 70 | |
60741361 | 71 | mac802154_monitors_rx(local, skb); |
72fd5a8b | 72 | |
a5e1ec53 | 73 | if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) { |
5b641ebe | 74 | u16 crc = crc_ccitt(0, skb->data, skb->len); |
75 | u8 *data = skb_put(skb, 2); | |
4710d806 | 76 | |
5b641ebe | 77 | data[0] = crc & 0xff; |
78 | data[1] = crc >> 8; | |
79 | } | |
80 | ||
a5e1ec53 | 81 | if (skb_cow_head(skb, local->hw.extra_tx_headroom)) |
f5588912 | 82 | goto err_tx; |
5b641ebe | 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) { | |
89 | ret = local->ops->xmit_async(&local->hw, skb); | |
90 | if (ret) { | |
91 | ieee802154_wake_queue(&local->hw); | |
92 | goto err_tx; | |
93 | } | |
94 | } else { | |
95 | INIT_WORK(&cb->work, mac802154_xmit_worker); | |
96 | cb->skb = skb; | |
97 | cb->local = local; | |
5b641ebe | 98 | |
ed0a5dce AA |
99 | queue_work(local->workqueue, &cb->work); |
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 AA |
108 | |
109 | netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb, struct net_device *dev) | |
110 | { | |
111 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | |
50c6fb99 AA |
112 | |
113 | skb->skb_iif = dev->ifindex; | |
114 | dev->stats.tx_packets++; | |
115 | dev->stats.tx_bytes += skb->len; | |
116 | ||
dc67c6b3 | 117 | return mac802154_tx(sdata->local, skb); |
50c6fb99 AA |
118 | } |
119 | ||
120 | netdev_tx_t mac802154_wpan_xmit(struct sk_buff *skb, struct net_device *dev) | |
121 | { | |
122 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | |
50c6fb99 AA |
123 | int rc; |
124 | ||
50c6fb99 AA |
125 | rc = mac802154_llsec_encrypt(&sdata->sec, skb); |
126 | if (rc) { | |
127 | pr_warn("encryption failed: %i\n", rc); | |
128 | kfree_skb(skb); | |
129 | return NETDEV_TX_OK; | |
130 | } | |
131 | ||
132 | skb->skb_iif = dev->ifindex; | |
133 | dev->stats.tx_packets++; | |
134 | dev->stats.tx_bytes += skb->len; | |
135 | ||
dc67c6b3 | 136 | return mac802154_tx(sdata->local, skb); |
50c6fb99 | 137 | } |