rx.c (d5432503bfb49f3425bad0b850714ffd8b533cfc) | rx.c (c5c47e67bcd24638a059b1b5e9ec18c95f8634ca) |
---|---|
1/* 2 * Copyright (C) 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 * | 1/* 2 * Copyright (C) 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 * |
13 * You should have received a copy of the GNU General Public License along 14 * with this program; if not, write to the Free Software Foundation, Inc., 15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 16 * | |
17 * Written by: 18 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 19 * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 20 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 21 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 22 */ 23 24#include <linux/kernel.h> 25#include <linux/module.h> | 13 * Written by: 14 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com> 15 * Maxim Gorbachyov <maxim.gorbachev@siemens.com> 16 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 17 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> 18 */ 19 20#include <linux/kernel.h> 21#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 | 22#include <linux/netdevice.h> 23#include <linux/crc-ccitt.h> 24 25#include <net/mac802154.h> 26#include <net/ieee802154_netdev.h> 27 |
33#include "mac802154.h" | 28#include "ieee802154_i.h" |
34 | 29 |
35/* The IEEE 802.15.4 standard defines 4 MAC packet types: 36 * - beacon frame 37 * - MAC command frame 38 * - acknowledgement frame 39 * - data frame 40 * 41 * and only the data frame should be pushed to the upper layers, other types 42 * are just internal MAC layer management information. So only data packets 43 * are going to be sent to the networking queue, all other will be processed 44 * right here by using the device workqueue. 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 | 30static void |
54mac802154_subif_rx(struct ieee802154_dev *hw, struct sk_buff *skb, u8 lqi) | 31mac802154_subif_rx(struct ieee802154_hw *hw, struct sk_buff *skb) |
55{ | 32{ |
56 struct mac802154_priv *priv = mac802154_to_priv(hw); | 33 struct ieee802154_local *local = hw_to_local(hw); |
57 | 34 |
58 mac_cb(skb)->lqi = lqi; | |
59 skb->protocol = htons(ETH_P_IEEE802154); 60 skb_reset_mac_header(skb); 61 | 35 skb->protocol = htons(ETH_P_IEEE802154); 36 skb_reset_mac_header(skb); 37 |
62 if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) { | 38 if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) { |
63 u16 crc; 64 65 if (skb->len < 2) { 66 pr_debug("got invalid frame\n"); 67 goto fail; 68 } 69 crc = crc_ccitt(0, skb->data, skb->len); 70 if (crc) { 71 pr_debug("CRC mismatch\n"); 72 goto fail; 73 } 74 skb_trim(skb, skb->len - 2); /* CRC */ 75 } 76 | 39 u16 crc; 40 41 if (skb->len < 2) { 42 pr_debug("got invalid frame\n"); 43 goto fail; 44 } 45 crc = crc_ccitt(0, skb->data, skb->len); 46 if (crc) { 47 pr_debug("CRC mismatch\n"); 48 goto fail; 49 } 50 skb_trim(skb, skb->len - 2); /* CRC */ 51 } 52 |
77 mac802154_monitors_rx(priv, skb); 78 mac802154_wpans_rx(priv, skb); | 53 mac802154_monitors_rx(local, skb); 54 mac802154_wpans_rx(local, skb); |
79 80 return; 81 82fail: 83 kfree_skb(skb); 84} 85 | 55 56 return; 57 58fail: 59 kfree_skb(skb); 60} 61 |
86static void mac802154_rx_worker(struct work_struct *work) | 62void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb) |
87{ | 63{ |
88 struct rx_work *rw = container_of(work, struct rx_work, work); 89 90 mac802154_subif_rx(rw->dev, rw->skb, rw->lqi); 91 kfree(rw); | 64 mac802154_subif_rx(hw, skb); |
92} | 65} |
66EXPORT_SYMBOL(ieee802154_rx); |
|
93 94void | 67 68void |
95ieee802154_rx_irqsafe(struct ieee802154_dev *dev, struct sk_buff *skb, u8 lqi) | 69ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi) |
96{ | 70{ |
97 struct mac802154_priv *priv = mac802154_to_priv(dev); 98 struct rx_work *work; | 71 struct ieee802154_local *local = hw_to_local(hw); |
99 | 72 |
100 if (!skb) 101 return; 102 103 work = kzalloc(sizeof(*work), GFP_ATOMIC); 104 if (!work) 105 return; 106 107 INIT_WORK(&work->work, mac802154_rx_worker); 108 work->skb = skb; 109 work->dev = dev; 110 work->lqi = lqi; 111 112 queue_work(priv->dev_workqueue, &work->work); | 73 mac_cb(skb)->lqi = lqi; 74 skb->pkt_type = IEEE802154_RX_MSG; 75 skb_queue_tail(&local->skb_queue, skb); 76 tasklet_schedule(&local->tasklet); |
113} 114EXPORT_SYMBOL(ieee802154_rx_irqsafe); | 77} 78EXPORT_SYMBOL(ieee802154_rx_irqsafe); |