blob: 2851a3f7ac0b2d527521490af060bc387e26d300 [file] [log] [blame]
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +00001/*
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 *
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000013 * 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>
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000022#include <linux/netdevice.h>
23#include <linux/crc-ccitt.h>
24
25#include <net/mac802154.h>
26#include <net/ieee802154_netdev.h>
27
Alexander Aring0f1556b2014-10-25 09:41:00 +020028#include "ieee802154_i.h"
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000029
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000030static void
Alexander Aringc5c47e62014-10-27 17:13:30 +010031mac802154_subif_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000032{
Alexander Aring60741362014-10-25 17:16:39 +020033 struct ieee802154_local *local = hw_to_local(hw);
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000034
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000035 skb->protocol = htons(ETH_P_IEEE802154);
36 skb_reset_mac_header(skb);
37
Alexander Aringa5e1ec52014-10-25 17:16:35 +020038 if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000039 u16 crc;
40
41 if (skb->len < 2) {
42 pr_debug("got invalid frame\n");
Phoebe Buckheister2d3b5b02014-06-11 12:03:07 +020043 goto fail;
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000044 }
45 crc = crc_ccitt(0, skb->data, skb->len);
46 if (crc) {
47 pr_debug("CRC mismatch\n");
Phoebe Buckheister2d3b5b02014-06-11 12:03:07 +020048 goto fail;
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000049 }
50 skb_trim(skb, skb->len - 2); /* CRC */
51 }
52
Alexander Aringa5e1ec52014-10-25 17:16:35 +020053 mac802154_monitors_rx(local, skb);
54 mac802154_wpans_rx(local, skb);
Phoebe Buckheister2d3b5b02014-06-11 12:03:07 +020055
56 return;
57
58fail:
59 kfree_skb(skb);
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000060}
61
Alexander Aringc5c47e62014-10-27 17:13:30 +010062void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000063{
Alexander Aringc5c47e62014-10-27 17:13:30 +010064 mac802154_subif_rx(hw, skb);
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000065}
Alexander Aringc5c47e62014-10-27 17:13:30 +010066EXPORT_SYMBOL(ieee802154_rx);
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000067
68void
Alexander Aring5a504392014-10-25 17:16:34 +020069ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi)
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000070{
Alexander Aring60741362014-10-25 17:16:39 +020071 struct ieee802154_local *local = hw_to_local(hw);
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000072
Alexander Aringc5c47e62014-10-27 17:13:30 +010073 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);
alex.bluesman.smirnov@gmail.com1cd829c2012-05-15 20:50:21 +000077}
78EXPORT_SYMBOL(ieee802154_rx_irqsafe);