alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007, 2008, 2009 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.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 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/skbuff.h> |
| 22 | #include <linux/if_arp.h> |
| 23 | #include <linux/crc-ccitt.h> |
Alexander Aring | 4ca24ac | 2014-10-25 09:41:04 +0200 | [diff] [blame] | 24 | #include <linux/ieee802154.h> |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 25 | |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 26 | #include <net/mac802154.h> |
| 27 | #include <net/netlink.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 28 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 29 | #include <linux/nl802154.h> |
| 30 | |
Alexander Aring | 0f1556b | 2014-10-25 09:41:00 +0200 | [diff] [blame] | 31 | #include "ieee802154_i.h" |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 32 | |
Alexander Aring | a5e1ec5 | 2014-10-25 17:16:35 +0200 | [diff] [blame] | 33 | void mac802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb) |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 34 | { |
| 35 | struct sk_buff *skb2; |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 36 | struct ieee802154_sub_if_data *sdata; |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 37 | u16 crc = crc_ccitt(0, skb->data, skb->len); |
| 38 | u8 *data; |
| 39 | |
| 40 | rcu_read_lock(); |
Alexander Aring | d98be45 | 2014-10-25 17:16:38 +0200 | [diff] [blame] | 41 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Phoebe Buckheister | 2d3b5b0 | 2014-06-11 12:03:07 +0200 | [diff] [blame] | 42 | if (sdata->type != IEEE802154_DEV_MONITOR || |
| 43 | !netif_running(sdata->dev)) |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 44 | continue; |
| 45 | |
| 46 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 47 | skb2->dev = sdata->dev; |
| 48 | skb2->pkt_type = PACKET_HOST; |
| 49 | data = skb_put(skb2, 2); |
| 50 | data[0] = crc & 0xff; |
| 51 | data[1] = crc >> 8; |
| 52 | |
| 53 | netif_rx_ni(skb2); |
| 54 | } |
| 55 | rcu_read_unlock(); |
| 56 | } |
| 57 | |
| 58 | static const struct net_device_ops mac802154_monitor_ops = { |
| 59 | .ndo_open = mac802154_slave_open, |
| 60 | .ndo_stop = mac802154_slave_close, |
| 61 | .ndo_start_xmit = mac802154_monitor_xmit, |
| 62 | }; |
| 63 | |
| 64 | void mac802154_monitor_setup(struct net_device *dev) |
| 65 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 66 | struct ieee802154_sub_if_data *sdata; |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 67 | |
| 68 | dev->addr_len = 0; |
| 69 | dev->hard_header_len = 0; |
| 70 | dev->needed_tailroom = 2; /* room for FCS */ |
| 71 | dev->mtu = IEEE802154_MTU; |
| 72 | dev->tx_queue_len = 10; |
| 73 | dev->type = ARPHRD_IEEE802154_MONITOR; |
| 74 | dev->flags = IFF_NOARP | IFF_BROADCAST; |
| 75 | dev->watchdog_timeo = 0; |
| 76 | |
| 77 | dev->destructor = free_netdev; |
| 78 | dev->netdev_ops = &mac802154_monitor_ops; |
| 79 | dev->ml_priv = &mac802154_mlme_reduced; |
| 80 | |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 81 | sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 82 | sdata->type = IEEE802154_DEV_MONITOR; |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 83 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 84 | sdata->chan = MAC802154_CHAN_NONE; /* not initialized */ |
| 85 | sdata->page = 0; |
alex.bluesman.smirnov@gmail.com | 0606069 | 2012-05-15 20:50:29 +0000 | [diff] [blame] | 86 | } |