blob: cb9600bcca5101faf2cff25f64c5523264602831 [file] [log] [blame]
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +00001/*
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.com06060692012-05-15 20:50:29 +000013 * 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 Aring4ca24ac2014-10-25 09:41:04 +020024#include <linux/ieee802154.h>
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000025
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000026#include <net/mac802154.h>
27#include <net/netlink.h>
Alexander Aring5ad60d32014-10-25 09:41:02 +020028#include <net/cfg802154.h>
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000029#include <linux/nl802154.h>
30
Alexander Aring0f1556b2014-10-25 09:41:00 +020031#include "ieee802154_i.h"
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000032
Alexander Aringa5e1ec52014-10-25 17:16:35 +020033void mac802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000034{
35 struct sk_buff *skb2;
Alexander Aring036562f2014-10-25 17:16:36 +020036 struct ieee802154_sub_if_data *sdata;
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000037 u16 crc = crc_ccitt(0, skb->data, skb->len);
38 u8 *data;
39
40 rcu_read_lock();
Alexander Aringd98be452014-10-25 17:16:38 +020041 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Phoebe Buckheister2d3b5b02014-06-11 12:03:07 +020042 if (sdata->type != IEEE802154_DEV_MONITOR ||
43 !netif_running(sdata->dev))
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000044 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
58static 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
64void mac802154_monitor_setup(struct net_device *dev)
65{
Alexander Aring036562f2014-10-25 17:16:36 +020066 struct ieee802154_sub_if_data *sdata;
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000067
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 Aring59d19cd2014-10-25 17:16:40 +020081 sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Alexander Aring036562f2014-10-25 17:16:36 +020082 sdata->type = IEEE802154_DEV_MONITOR;
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000083
Alexander Aring036562f2014-10-25 17:16:36 +020084 sdata->chan = MAC802154_CHAN_NONE; /* not initialized */
85 sdata->page = 0;
alex.bluesman.smirnov@gmail.com06060692012-05-15 20:50:29 +000086}