Commit | Line | Data |
---|---|---|
1cd829c8 | 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 | * | |
1cd829c8 | 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> | |
1cd829c8 | 22 | #include <linux/netdevice.h> |
23 | #include <linux/crc-ccitt.h> | |
24 | ||
25 | #include <net/mac802154.h> | |
26 | #include <net/ieee802154_netdev.h> | |
27 | ||
0f1556bc | 28 | #include "ieee802154_i.h" |
1cd829c8 | 29 | |
1cd829c8 | 30 | static void |
c5c47e67 | 31 | mac802154_subif_rx(struct ieee802154_hw *hw, struct sk_buff *skb) |
1cd829c8 | 32 | { |
60741361 | 33 | struct ieee802154_local *local = hw_to_local(hw); |
1cd829c8 | 34 | |
1cd829c8 | 35 | skb->protocol = htons(ETH_P_IEEE802154); |
36 | skb_reset_mac_header(skb); | |
37 | ||
a5e1ec53 | 38 | if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) { |
1cd829c8 | 39 | u16 crc; |
40 | ||
41 | if (skb->len < 2) { | |
42 | pr_debug("got invalid frame\n"); | |
2d3b5b0a | 43 | goto fail; |
1cd829c8 | 44 | } |
45 | crc = crc_ccitt(0, skb->data, skb->len); | |
46 | if (crc) { | |
47 | pr_debug("CRC mismatch\n"); | |
2d3b5b0a | 48 | goto fail; |
1cd829c8 | 49 | } |
50 | skb_trim(skb, skb->len - 2); /* CRC */ | |
51 | } | |
52 | ||
a5e1ec53 AA |
53 | mac802154_monitors_rx(local, skb); |
54 | mac802154_wpans_rx(local, skb); | |
2d3b5b0a PB |
55 | |
56 | return; | |
57 | ||
58 | fail: | |
59 | kfree_skb(skb); | |
1cd829c8 | 60 | } |
61 | ||
c5c47e67 | 62 | void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb) |
1cd829c8 | 63 | { |
c730c903 AA |
64 | WARN_ON_ONCE(softirq_count() == 0); |
65 | ||
c5c47e67 | 66 | mac802154_subif_rx(hw, skb); |
1cd829c8 | 67 | } |
c5c47e67 | 68 | EXPORT_SYMBOL(ieee802154_rx); |
1cd829c8 | 69 | |
70 | void | |
5a504397 | 71 | ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi) |
1cd829c8 | 72 | { |
60741361 | 73 | struct ieee802154_local *local = hw_to_local(hw); |
1cd829c8 | 74 | |
c5c47e67 AA |
75 | mac_cb(skb)->lqi = lqi; |
76 | skb->pkt_type = IEEE802154_RX_MSG; | |
77 | skb_queue_tail(&local->skb_queue, skb); | |
78 | tasklet_schedule(&local->tasklet); | |
1cd829c8 | 79 | } |
80 | EXPORT_SYMBOL(ieee802154_rx_irqsafe); |