]>
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 | ||
6001d522 | 24 | #include <net/rtnetlink.h> |
b5992fe9 | 25 | #include <net/ieee802154_netdev.h> |
5b641ebe | 26 | #include <net/mac802154.h> |
5ad60d36 | 27 | #include <net/cfg802154.h> |
5b641ebe | 28 | |
0f1556bc | 29 | #include "ieee802154_i.h" |
5b641ebe | 30 | |
31 | /* IEEE 802.15.4 transceivers can sleep during the xmit session, so process | |
32 | * packets through the workqueue. | |
33 | */ | |
fe24371d | 34 | struct wpan_xmit_cb { |
5b641ebe | 35 | struct sk_buff *skb; |
36 | struct work_struct work; | |
a5e1ec53 | 37 | struct ieee802154_local *local; |
5b641ebe | 38 | }; |
39 | ||
fe24371d AA |
40 | static inline struct wpan_xmit_cb *wpan_xmit_cb(const struct sk_buff *skb) |
41 | { | |
42 | BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct wpan_xmit_cb)); | |
43 | ||
44 | return (struct wpan_xmit_cb *)skb->cb; | |
45 | } | |
46 | ||
5b641ebe | 47 | static void mac802154_xmit_worker(struct work_struct *work) |
48 | { | |
fe24371d | 49 | struct wpan_xmit_cb *cb = container_of(work, struct wpan_xmit_cb, work); |
e89e45f2 | 50 | struct ieee802154_local *local = cb->local; |
e89e45f2 | 51 | struct sk_buff *skb = cb->skb; |
409c3b0c | 52 | struct net_device *dev = skb->dev; |
5b641ebe | 53 | int res; |
54 | ||
6001d522 AA |
55 | rtnl_lock(); |
56 | ||
57 | /* check if ifdown occurred while schedule */ | |
409c3b0c | 58 | if (!netif_running(dev)) |
6001d522 AA |
59 | goto err_tx; |
60 | ||
ed0a5dce | 61 | res = local->ops->xmit_sync(&local->hw, skb); |
6001d522 AA |
62 | if (res) |
63 | goto err_tx; | |
64 | ||
65 | ieee802154_xmit_complete(&local->hw, skb); | |
66 | ||
409c3b0c AA |
67 | dev->stats.tx_packets++; |
68 | dev->stats.tx_bytes += skb->len; | |
69 | ||
6001d522 AA |
70 | rtnl_unlock(); |
71 | ||
72 | return; | |
73 | ||
74 | err_tx: | |
75 | /* Restart the netif queue on each sub_if_data object. */ | |
76 | ieee802154_wake_queue(&local->hw); | |
77 | rtnl_unlock(); | |
78 | kfree_skb(skb); | |
409c3b0c | 79 | netdev_dbg(dev, "transmission failed\n"); |
5b641ebe | 80 | } |
81 | ||
dc67c6b3 AA |
82 | static netdev_tx_t |
83 | mac802154_tx(struct ieee802154_local *local, struct sk_buff *skb) | |
5b641ebe | 84 | { |
fe24371d | 85 | struct wpan_xmit_cb *cb = wpan_xmit_cb(skb); |
409c3b0c | 86 | struct net_device *dev = skb->dev; |
ed0a5dce | 87 | int ret; |
5b641ebe | 88 | |
60741361 | 89 | mac802154_monitors_rx(local, skb); |
72fd5a8b | 90 | |
a5e1ec53 | 91 | if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) { |
b7eec52b | 92 | __le16 crc = cpu_to_le16(crc_ccitt(0, skb->data, skb->len)); |
4710d806 | 93 | |
b7eec52b | 94 | memcpy(skb_put(skb, 2), &crc, 2); |
5b641ebe | 95 | } |
96 | ||
a5e1ec53 | 97 | if (skb_cow_head(skb, local->hw.extra_tx_headroom)) |
f5588912 | 98 | goto err_tx; |
5b641ebe | 99 | |
b5992fe9 | 100 | /* Stop the netif queue on each sub_if_data object. */ |
18d60a0d | 101 | ieee802154_stop_queue(&local->hw); |
b5992fe9 | 102 | |
ed0a5dce AA |
103 | /* async is priority, otherwise sync is fallback */ |
104 | if (local->ops->xmit_async) { | |
105 | ret = local->ops->xmit_async(&local->hw, skb); | |
106 | if (ret) { | |
107 | ieee802154_wake_queue(&local->hw); | |
108 | goto err_tx; | |
109 | } | |
409c3b0c AA |
110 | |
111 | dev->stats.tx_packets++; | |
112 | dev->stats.tx_bytes += skb->len; | |
ed0a5dce AA |
113 | } else { |
114 | INIT_WORK(&cb->work, mac802154_xmit_worker); | |
115 | cb->skb = skb; | |
116 | cb->local = local; | |
5b641ebe | 117 | |
ed0a5dce AA |
118 | queue_work(local->workqueue, &cb->work); |
119 | } | |
5b641ebe | 120 | |
121 | return NETDEV_TX_OK; | |
f5588912 VB |
122 | |
123 | err_tx: | |
124 | kfree_skb(skb); | |
125 | return NETDEV_TX_OK; | |
5b641ebe | 126 | } |
50c6fb99 AA |
127 | |
128 | netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb, struct net_device *dev) | |
129 | { | |
130 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | |
50c6fb99 AA |
131 | |
132 | skb->skb_iif = dev->ifindex; | |
50c6fb99 | 133 | |
dc67c6b3 | 134 | return mac802154_tx(sdata->local, skb); |
50c6fb99 AA |
135 | } |
136 | ||
137 | netdev_tx_t mac802154_wpan_xmit(struct sk_buff *skb, struct net_device *dev) | |
138 | { | |
139 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | |
50c6fb99 AA |
140 | int rc; |
141 | ||
50c6fb99 AA |
142 | rc = mac802154_llsec_encrypt(&sdata->sec, skb); |
143 | if (rc) { | |
cfa626cb | 144 | netdev_warn(dev, "encryption failed: %i\n", rc); |
50c6fb99 AA |
145 | kfree_skb(skb); |
146 | return NETDEV_TX_OK; | |
147 | } | |
148 | ||
149 | skb->skb_iif = dev->ifindex; | |
50c6fb99 | 150 | |
dc67c6b3 | 151 | return mac802154_tx(sdata->local, skb); |
50c6fb99 | 152 | } |