ieee802154: move wpan-phy.h to cfg802154.h
[deliverable/linux.git] / net / mac802154 / monitor.c
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 *
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>
24
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>
30
31 #include "ieee802154_i.h"
32
33 static netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb,
34 struct net_device *dev)
35 {
36 struct mac802154_sub_if_data *priv;
37 u8 chan, page;
38
39 priv = netdev_priv(dev);
40
41 /* FIXME: locking */
42 chan = priv->hw->phy->current_channel;
43 page = priv->hw->phy->current_page;
44
45 if (chan == MAC802154_CHAN_NONE) /* not initialized */
46 return NETDEV_TX_OK;
47
48 if (WARN_ON(page >= WPAN_NUM_PAGES) ||
49 WARN_ON(chan >= WPAN_NUM_CHANNELS))
50 return NETDEV_TX_OK;
51
52 skb->skb_iif = dev->ifindex;
53 dev->stats.tx_packets++;
54 dev->stats.tx_bytes += skb->len;
55
56 return mac802154_tx(priv->hw, skb, page, chan);
57 }
58
59
60 void mac802154_monitors_rx(struct mac802154_priv *priv, struct sk_buff *skb)
61 {
62 struct sk_buff *skb2;
63 struct mac802154_sub_if_data *sdata;
64 u16 crc = crc_ccitt(0, skb->data, skb->len);
65 u8 *data;
66
67 rcu_read_lock();
68 list_for_each_entry_rcu(sdata, &priv->slaves, list) {
69 if (sdata->type != IEEE802154_DEV_MONITOR ||
70 !netif_running(sdata->dev))
71 continue;
72
73 skb2 = skb_clone(skb, GFP_ATOMIC);
74 skb2->dev = sdata->dev;
75 skb2->pkt_type = PACKET_HOST;
76 data = skb_put(skb2, 2);
77 data[0] = crc & 0xff;
78 data[1] = crc >> 8;
79
80 netif_rx_ni(skb2);
81 }
82 rcu_read_unlock();
83 }
84
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,
89 };
90
91 void mac802154_monitor_setup(struct net_device *dev)
92 {
93 struct mac802154_sub_if_data *priv;
94
95 dev->addr_len = 0;
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;
103
104 dev->destructor = free_netdev;
105 dev->netdev_ops = &mac802154_monitor_ops;
106 dev->ml_priv = &mac802154_mlme_reduced;
107
108 priv = netdev_priv(dev);
109 priv->type = IEEE802154_DEV_MONITOR;
110
111 priv->chan = MAC802154_CHAN_NONE; /* not initialized */
112 priv->page = 0;
113 }
This page took 0.046859 seconds and 5 git commands to generate.