1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/workqueue.h>
27#include <linux/netdevice.h>
28#include <linux/crc-ccitt.h>
29
30#include <net/mac802154.h>
31#include <net/ieee802154_netdev.h>
32
33#include "mac802154.h"
34
35
36
37
38
39
40
41
42
43
44
45
46struct rx_work {
47 struct sk_buff *skb;
48 struct work_struct work;
49 struct ieee802154_dev *dev;
50 u8 lqi;
51};
52
53static void
54mac802154_subif_rx(struct ieee802154_dev *hw, struct sk_buff *skb, u8 lqi)
55{
56 struct mac802154_priv *priv = mac802154_to_priv(hw);
57
58 mac_cb(skb)->lqi = lqi;
59 skb->protocol = htons(ETH_P_IEEE802154);
60 skb_reset_mac_header(skb);
61
62 BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb) > sizeof(skb->cb));
63
64 if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
65 u16 crc;
66
67 if (skb->len < 2) {
68 pr_debug("got invalid frame\n");
69 goto out;
70 }
71 crc = crc_ccitt(0, skb->data, skb->len);
72 if (crc) {
73 pr_debug("CRC mismatch\n");
74 goto out;
75 }
76 skb_trim(skb, skb->len - 2);
77 }
78
79 mac802154_monitors_rx(priv, skb);
80 mac802154_wpans_rx(priv, skb);
81out:
82 dev_kfree_skb(skb);
83 return;
84}
85
86static void mac802154_rx_worker(struct work_struct *work)
87{
88 struct rx_work *rw = container_of(work, struct rx_work, work);
89 struct sk_buff *skb = rw->skb;
90
91 mac802154_subif_rx(rw->dev, skb, rw->lqi);
92 kfree(rw);
93}
94
95void
96ieee802154_rx_irqsafe(struct ieee802154_dev *dev, struct sk_buff *skb, u8 lqi)
97{
98 struct mac802154_priv *priv = mac802154_to_priv(dev);
99 struct rx_work *work;
100
101 if (!skb)
102 return;
103
104 work = kzalloc(sizeof(struct rx_work), GFP_ATOMIC);
105 if (!work)
106 return;
107
108 INIT_WORK(&work->work, mac802154_rx_worker);
109 work->skb = skb;
110 work->dev = dev;
111 work->lqi = lqi;
112
113 queue_work(priv->dev_workqueue, &work->work);
114}
115EXPORT_SYMBOL(ieee802154_rx_irqsafe);
116