2 * Copyright 2007-2012 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.
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.
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>
24 #include <linux/if_arp.h>
26 #include <net/mac802154.h>
27 #include <net/wpan-phy.h>
29 #include "mac802154.h"
31 struct hw_addr_filt_notify_work {
32 struct work_struct work;
33 struct net_device *dev;
34 unsigned long changed;
37 struct mac802154_priv *mac802154_slave_get_priv(struct net_device *dev)
39 struct mac802154_sub_if_data *priv = netdev_priv(dev);
41 BUG_ON(dev->type != ARPHRD_IEEE802154);
46 static void hw_addr_notify(struct work_struct *work)
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);
53 res = hw->ops->set_hw_addr_filt(&hw->hw,
57 pr_debug("failed changed mask %lx\n", nw->changed);
64 static void set_hw_addr_filt(struct net_device *dev, unsigned long changed)
66 struct mac802154_sub_if_data *priv = netdev_priv(dev);
67 struct hw_addr_filt_notify_work *work;
69 work = kzalloc(sizeof(*work), GFP_ATOMIC);
73 INIT_WORK(&work->work, hw_addr_notify);
75 work->changed = changed;
76 queue_work(priv->hw->dev_workqueue, &work->work);
81 void mac802154_dev_set_short_addr(struct net_device *dev, u16 val)
83 struct mac802154_sub_if_data *priv = netdev_priv(dev);
85 BUG_ON(dev->type != ARPHRD_IEEE802154);
87 spin_lock_bh(&priv->mib_lock);
88 priv->short_addr = val;
89 spin_unlock_bh(&priv->mib_lock);
91 if ((priv->hw->ops->set_hw_addr_filt) &&
92 (priv->hw->hw.hw_filt.short_addr != priv->short_addr)) {
93 priv->hw->hw.hw_filt.short_addr = priv->short_addr;
94 set_hw_addr_filt(dev, IEEE802515_AFILT_SADDR_CHANGED);
98 void mac802154_dev_set_ieee_addr(struct net_device *dev)
100 struct mac802154_sub_if_data *priv = netdev_priv(dev);
101 struct mac802154_priv *mac = priv->hw;
103 if (mac->ops->set_hw_addr_filt &&
104 memcmp(mac->hw.hw_filt.ieee_addr,
105 dev->dev_addr, IEEE802154_ADDR_LEN)) {
106 memcpy(mac->hw.hw_filt.ieee_addr,
107 dev->dev_addr, IEEE802154_ADDR_LEN);
108 set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED);
112 u16 mac802154_dev_get_pan_id(const struct net_device *dev)
114 struct mac802154_sub_if_data *priv = netdev_priv(dev);
117 BUG_ON(dev->type != ARPHRD_IEEE802154);
119 spin_lock_bh(&priv->mib_lock);
121 spin_unlock_bh(&priv->mib_lock);
126 void mac802154_dev_set_pan_id(struct net_device *dev, u16 val)
128 struct mac802154_sub_if_data *priv = netdev_priv(dev);
130 BUG_ON(dev->type != ARPHRD_IEEE802154);
132 spin_lock_bh(&priv->mib_lock);
134 spin_unlock_bh(&priv->mib_lock);
136 if ((priv->hw->ops->set_hw_addr_filt) &&
137 (priv->hw->hw.hw_filt.pan_id != priv->pan_id)) {
138 priv->hw->hw.hw_filt.pan_id = priv->pan_id;
139 set_hw_addr_filt(dev, IEEE802515_AFILT_PANID_CHANGED);