diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/mac802154/Makefile | 2 | ||||
-rw-r--r-- | net/mac802154/ieee802154_dev.c | 5 | ||||
-rw-r--r-- | net/mac802154/mac802154.h | 5 | ||||
-rw-r--r-- | net/mac802154/monitor.c | 116 | ||||
-rw-r--r-- | net/mac802154/rx.c | 1 |
5 files changed, 127 insertions, 2 deletions
diff --git a/net/mac802154/Makefile b/net/mac802154/Makefile index 6b348b07a765..ec1bd3fc1273 100644 --- a/net/mac802154/Makefile +++ b/net/mac802154/Makefile | |||
@@ -1,2 +1,2 @@ | |||
1 | obj-$(CONFIG_MAC802154) += mac802154.o | 1 | obj-$(CONFIG_MAC802154) += mac802154.o |
2 | mac802154-objs := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o | 2 | mac802154-objs := ieee802154_dev.o rx.o tx.o mac_cmd.o mib.o monitor.o |
diff --git a/net/mac802154/ieee802154_dev.c b/net/mac802154/ieee802154_dev.c index 9f36760b6c3a..e3edfb0661b0 100644 --- a/net/mac802154/ieee802154_dev.c +++ b/net/mac802154/ieee802154_dev.c | |||
@@ -135,8 +135,11 @@ mac802154_add_iface(struct wpan_phy *phy, const char *name, int type) | |||
135 | struct net_device *dev; | 135 | struct net_device *dev; |
136 | int err = -ENOMEM; | 136 | int err = -ENOMEM; |
137 | 137 | ||
138 | /* No devices is currently added */ | ||
139 | switch (type) { | 138 | switch (type) { |
139 | case IEEE802154_DEV_MONITOR: | ||
140 | dev = alloc_netdev(sizeof(struct mac802154_sub_if_data), | ||
141 | name, mac802154_monitor_setup); | ||
142 | break; | ||
140 | default: | 143 | default: |
141 | dev = NULL; | 144 | dev = NULL; |
142 | err = -EINVAL; | 145 | err = -EINVAL; |
diff --git a/net/mac802154/mac802154.h b/net/mac802154/mac802154.h index 622752622c87..789d9c948aec 100644 --- a/net/mac802154/mac802154.h +++ b/net/mac802154/mac802154.h | |||
@@ -90,11 +90,16 @@ struct mac802154_sub_if_data { | |||
90 | 90 | ||
91 | #define MAC802154_MAX_XMIT_ATTEMPTS 3 | 91 | #define MAC802154_MAX_XMIT_ATTEMPTS 3 |
92 | 92 | ||
93 | #define MAC802154_CHAN_NONE (~(u8)0) /* No channel is assigned */ | ||
94 | |||
93 | extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced; | 95 | extern struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced; |
94 | 96 | ||
95 | int mac802154_slave_open(struct net_device *dev); | 97 | int mac802154_slave_open(struct net_device *dev); |
96 | int mac802154_slave_close(struct net_device *dev); | 98 | int mac802154_slave_close(struct net_device *dev); |
97 | 99 | ||
100 | void mac802154_monitors_rx(struct mac802154_priv *priv, struct sk_buff *skb); | ||
101 | void mac802154_monitor_setup(struct net_device *dev); | ||
102 | |||
98 | netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb, | 103 | netdev_tx_t mac802154_tx(struct mac802154_priv *priv, struct sk_buff *skb, |
99 | u8 page, u8 chan); | 104 | u8 page, u8 chan); |
100 | 105 | ||
diff --git a/net/mac802154/monitor.c b/net/mac802154/monitor.c new file mode 100644 index 000000000000..434a26f76a80 --- /dev/null +++ b/net/mac802154/monitor.c | |||
@@ -0,0 +1,116 @@ | |||
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 | * You should have received a copy of the GNU General Public License along | ||
14 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
16 | * | ||
17 | * Written by: | ||
18 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
19 | * Sergey Lapin <slapin@ossfans.org> | ||
20 | * Maxim Gorbachyov <maxim.gorbachev@siemens.com> | ||
21 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> | ||
22 | */ | ||
23 | |||
24 | #include <linux/netdevice.h> | ||
25 | #include <linux/skbuff.h> | ||
26 | #include <linux/if_arp.h> | ||
27 | #include <linux/crc-ccitt.h> | ||
28 | |||
29 | #include <net/ieee802154.h> | ||
30 | #include <net/mac802154.h> | ||
31 | #include <net/netlink.h> | ||
32 | #include <net/wpan-phy.h> | ||
33 | #include <linux/nl802154.h> | ||
34 | |||
35 | #include "mac802154.h" | ||
36 | |||
37 | static netdev_tx_t mac802154_monitor_xmit(struct sk_buff *skb, | ||
38 | struct net_device *dev) | ||
39 | { | ||
40 | struct mac802154_sub_if_data *priv; | ||
41 | u8 chan, page; | ||
42 | |||
43 | priv = netdev_priv(dev); | ||
44 | |||
45 | /* FIXME: locking */ | ||
46 | chan = priv->hw->phy->current_channel; | ||
47 | page = priv->hw->phy->current_page; | ||
48 | |||
49 | if (chan == MAC802154_CHAN_NONE) /* not initialized */ | ||
50 | return NETDEV_TX_OK; | ||
51 | |||
52 | if (WARN_ON(page >= WPAN_NUM_PAGES) || | ||
53 | WARN_ON(chan >= WPAN_NUM_CHANNELS)) | ||
54 | return NETDEV_TX_OK; | ||
55 | |||
56 | skb->skb_iif = dev->ifindex; | ||
57 | dev->stats.tx_packets++; | ||
58 | dev->stats.tx_bytes += skb->len; | ||
59 | |||
60 | return mac802154_tx(priv->hw, skb, page, chan); | ||
61 | } | ||
62 | |||
63 | |||
64 | void mac802154_monitors_rx(struct mac802154_priv *priv, struct sk_buff *skb) | ||
65 | { | ||
66 | struct sk_buff *skb2; | ||
67 | struct mac802154_sub_if_data *sdata; | ||
68 | u16 crc = crc_ccitt(0, skb->data, skb->len); | ||
69 | u8 *data; | ||
70 | |||
71 | rcu_read_lock(); | ||
72 | list_for_each_entry_rcu(sdata, &priv->slaves, list) { | ||
73 | if (sdata->type != IEEE802154_DEV_MONITOR) | ||
74 | continue; | ||
75 | |||
76 | skb2 = skb_clone(skb, GFP_ATOMIC); | ||
77 | skb2->dev = sdata->dev; | ||
78 | skb2->pkt_type = PACKET_HOST; | ||
79 | data = skb_put(skb2, 2); | ||
80 | data[0] = crc & 0xff; | ||
81 | data[1] = crc >> 8; | ||
82 | |||
83 | netif_rx_ni(skb2); | ||
84 | } | ||
85 | rcu_read_unlock(); | ||
86 | } | ||
87 | |||
88 | static const struct net_device_ops mac802154_monitor_ops = { | ||
89 | .ndo_open = mac802154_slave_open, | ||
90 | .ndo_stop = mac802154_slave_close, | ||
91 | .ndo_start_xmit = mac802154_monitor_xmit, | ||
92 | }; | ||
93 | |||
94 | void mac802154_monitor_setup(struct net_device *dev) | ||
95 | { | ||
96 | struct mac802154_sub_if_data *priv; | ||
97 | |||
98 | dev->addr_len = 0; | ||
99 | dev->hard_header_len = 0; | ||
100 | dev->needed_tailroom = 2; /* room for FCS */ | ||
101 | dev->mtu = IEEE802154_MTU; | ||
102 | dev->tx_queue_len = 10; | ||
103 | dev->type = ARPHRD_IEEE802154_MONITOR; | ||
104 | dev->flags = IFF_NOARP | IFF_BROADCAST; | ||
105 | dev->watchdog_timeo = 0; | ||
106 | |||
107 | dev->destructor = free_netdev; | ||
108 | dev->netdev_ops = &mac802154_monitor_ops; | ||
109 | dev->ml_priv = &mac802154_mlme_reduced; | ||
110 | |||
111 | priv = netdev_priv(dev); | ||
112 | priv->type = IEEE802154_DEV_MONITOR; | ||
113 | |||
114 | priv->chan = MAC802154_CHAN_NONE; /* not initialized */ | ||
115 | priv->page = 0; | ||
116 | } | ||
diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c index d15738fae551..4a7d76d4f8bc 100644 --- a/net/mac802154/rx.c +++ b/net/mac802154/rx.c | |||
@@ -76,6 +76,7 @@ mac802154_subif_rx(struct ieee802154_dev *hw, struct sk_buff *skb, u8 lqi) | |||
76 | skb_trim(skb, skb->len - 2); /* CRC */ | 76 | skb_trim(skb, skb->len - 2); /* CRC */ |
77 | } | 77 | } |
78 | 78 | ||
79 | mac802154_monitors_rx(priv, skb); | ||
79 | out: | 80 | out: |
80 | dev_kfree_skb(skb); | 81 | dev_kfree_skb(skb); |
81 | return; | 82 | return; |