xref: /linux/net/mac802154/mib.c (revision d670b479586e457c7c36604cea08ae236fb933ac)
1 /*
2  * Copyright 2007-2012 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/if_arp.h>
25 
26 #include <net/mac802154.h>
27 #include <net/wpan-phy.h>
28 
29 #include "mac802154.h"
30 
31 struct hw_addr_filt_notify_work {
32 	struct work_struct work;
33 	struct net_device *dev;
34 	unsigned long changed;
35 };
36 
37 struct mac802154_priv *mac802154_slave_get_priv(struct net_device *dev)
38 {
39 	struct mac802154_sub_if_data *priv = netdev_priv(dev);
40 
41 	BUG_ON(dev->type != ARPHRD_IEEE802154);
42 
43 	return priv->hw;
44 }
45 
46 static void hw_addr_notify(struct work_struct *work)
47 {
48 	struct hw_addr_filt_notify_work *nw = container_of(work,
49 			struct hw_addr_filt_notify_work, work);
50 	struct mac802154_priv *hw = mac802154_slave_get_priv(nw->dev);
51 	int res;
52 
53 	res = hw->ops->set_hw_addr_filt(&hw->hw,
54 					&hw->hw.hw_filt,
55 					nw->changed);
56 	if (res)
57 		pr_debug("failed changed mask %lx\n", nw->changed);
58 
59 	kfree(nw);
60 
61 	return;
62 }
63 
64 static void set_hw_addr_filt(struct net_device *dev, unsigned long changed)
65 {
66 	struct mac802154_sub_if_data *priv = netdev_priv(dev);
67 	struct hw_addr_filt_notify_work *work;
68 
69 	work = kzalloc(sizeof(*work), GFP_ATOMIC);
70 	if (!work)
71 		return;
72 
73 	INIT_WORK(&work->work, hw_addr_notify);
74 	work->dev = dev;
75 	work->changed = changed;
76 	queue_work(priv->hw->dev_workqueue, &work->work);
77 
78 	return;
79 }
80 
81 void mac802154_dev_set_ieee_addr(struct net_device *dev)
82 {
83 	struct mac802154_sub_if_data *priv = netdev_priv(dev);
84 	struct mac802154_priv *mac = priv->hw;
85 
86 	if (mac->ops->set_hw_addr_filt &&
87 	    memcmp(mac->hw.hw_filt.ieee_addr,
88 		   dev->dev_addr, IEEE802154_ADDR_LEN)) {
89 		memcpy(mac->hw.hw_filt.ieee_addr,
90 		       dev->dev_addr, IEEE802154_ADDR_LEN);
91 		set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED);
92 	}
93 }
94