2 * Copyright 2007, 2008, 2009 Siemens AG
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.
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.
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>
20 #include <linux/netdevice.h>
21 #include <linux/skbuff.h>
22 #include <linux/if_arp.h>
23 #include <linux/crc-ccitt.h>
25 #include <net/ieee802154.h>
26 #include <net/mac802154.h>
27 #include <net/netlink.h>
28 #include <net/cfg802154.h>
29 #include <linux/nl802154.h>
31 #include "ieee802154_i.h"
33 static netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb,
34 struct net_device *dev)
36 struct mac802154_sub_if_data *priv;
39 priv = netdev_priv(dev);
42 chan = priv->hw->phy->current_channel;
43 page = priv->hw->phy->current_page;
45 if (chan == MAC802154_CHAN_NONE) /* not initialized */
48 if (WARN_ON(page >= WPAN_NUM_PAGES) ||
49 WARN_ON(chan >= WPAN_NUM_CHANNELS))
52 skb->skb_iif = dev->ifindex;
53 dev->stats.tx_packets++;
54 dev->stats.tx_bytes += skb->len;
56 return mac802154_tx(priv->hw, skb, page, chan);
60 void mac802154_monitors_rx(struct mac802154_priv *priv, struct sk_buff *skb)
63 struct mac802154_sub_if_data *sdata;
64 u16 crc = crc_ccitt(0, skb->data, skb->len);
68 list_for_each_entry_rcu(sdata, &priv->slaves, list) {
69 if (sdata->type != IEEE802154_DEV_MONITOR ||
70 !netif_running(sdata->dev))
73 skb2 = skb_clone(skb, GFP_ATOMIC);
74 skb2->dev = sdata->dev;
75 skb2->pkt_type = PACKET_HOST;
76 data = skb_put(skb2, 2);
85 static const struct net_device_ops mac802154_monitor_ops = {
86 .ndo_open = mac802154_slave_open,
87 .ndo_stop = mac802154_slave_close,
88 .ndo_start_xmit = mac802154_monitor_xmit,
91 void mac802154_monitor_setup(struct net_device *dev)
93 struct mac802154_sub_if_data *priv;
96 dev->hard_header_len = 0;
97 dev->needed_tailroom = 2; /* room for FCS */
98 dev->mtu = IEEE802154_MTU;
99 dev->tx_queue_len = 10;
100 dev->type = ARPHRD_IEEE802154_MONITOR;
101 dev->flags = IFF_NOARP | IFF_BROADCAST;
102 dev->watchdog_timeo = 0;
104 dev->destructor = free_netdev;
105 dev->netdev_ops = &mac802154_monitor_ops;
106 dev->ml_priv = &mac802154_mlme_reduced;
108 priv = netdev_priv(dev);
109 priv->type = IEEE802154_DEV_MONITOR;
111 priv->chan = MAC802154_CHAN_NONE; /* not initialized */