mac802154: rename mac802154_sub_if_data
[deliverable/linux.git] / net / mac802154 / monitor.c
CommitLineData
0606069d 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 *
0606069d 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>
4ca24aca 24#include <linux/ieee802154.h>
0606069d 25
0606069d 26#include <net/mac802154.h>
27#include <net/netlink.h>
5ad60d36 28#include <net/cfg802154.h>
0606069d 29#include <linux/nl802154.h>
30
0f1556bc 31#include "ieee802154_i.h"
0606069d 32
33static netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb,
34 struct net_device *dev)
35{
036562f9 36 struct ieee802154_sub_if_data *sdata;
0606069d 37 u8 chan, page;
38
036562f9 39 sdata = netdev_priv(dev);
0606069d 40
41 /* FIXME: locking */
036562f9
AA
42 chan = sdata->hw->phy->current_channel;
43 page = sdata->hw->phy->current_page;
0606069d 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
036562f9 56 return mac802154_tx(sdata->hw, skb, page, chan);
0606069d 57}
58
59
a5e1ec53 60void mac802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
0606069d 61{
62 struct sk_buff *skb2;
036562f9 63 struct ieee802154_sub_if_data *sdata;
0606069d 64 u16 crc = crc_ccitt(0, skb->data, skb->len);
65 u8 *data;
66
67 rcu_read_lock();
a5e1ec53 68 list_for_each_entry_rcu(sdata, &local->slaves, list) {
2d3b5b0a
PB
69 if (sdata->type != IEEE802154_DEV_MONITOR ||
70 !netif_running(sdata->dev))
0606069d 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
85static 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
91void mac802154_monitor_setup(struct net_device *dev)
92{
036562f9 93 struct ieee802154_sub_if_data *sdata;
0606069d 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
036562f9
AA
108 sdata = netdev_priv(dev);
109 sdata->type = IEEE802154_DEV_MONITOR;
0606069d 110
036562f9
AA
111 sdata->chan = MAC802154_CHAN_NONE; /* not initialized */
112 sdata->page = 0;
0606069d 113}
This page took 0.141564 seconds and 5 git commands to generate.