]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/mac802154/mib.c
mac802154: short address setter
[mirror_ubuntu-jammy-kernel.git] / net / mac802154 / mib.c
CommitLineData
ef2486f5 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
31struct hw_addr_filt_notify_work {
32 struct work_struct work;
33 struct net_device *dev;
34 unsigned long changed;
35};
36
37struct 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
46static 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
64static 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
48e44d50 81void mac802154_dev_set_short_addr(struct net_device *dev, u16 val)
82{
83 struct mac802154_sub_if_data *priv = netdev_priv(dev);
84
85 BUG_ON(dev->type != ARPHRD_IEEE802154);
86
87 spin_lock_bh(&priv->mib_lock);
88 priv->short_addr = val;
89 spin_unlock_bh(&priv->mib_lock);
90
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);
95 }
96}
97
ef2486f5 98void mac802154_dev_set_ieee_addr(struct net_device *dev)
99{
100 struct mac802154_sub_if_data *priv = netdev_priv(dev);
101 struct mac802154_priv *mac = priv->hw;
102
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);
109 }
110}
dcbe4f93 111
112u16 mac802154_dev_get_pan_id(const struct net_device *dev)
113{
114 struct mac802154_sub_if_data *priv = netdev_priv(dev);
115 u16 ret;
116
117 BUG_ON(dev->type != ARPHRD_IEEE802154);
118
119 spin_lock_bh(&priv->mib_lock);
120 ret = priv->pan_id;
121 spin_unlock_bh(&priv->mib_lock);
122
123 return ret;
124}
125
126void mac802154_dev_set_pan_id(struct net_device *dev, u16 val)
127{
128 struct mac802154_sub_if_data *priv = netdev_priv(dev);
129
130 BUG_ON(dev->type != ARPHRD_IEEE802154);
131
132 spin_lock_bh(&priv->mib_lock);
133 priv->pan_id = val;
134 spin_unlock_bh(&priv->mib_lock);
135
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);
140 }
141}