Loading...
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright 2007-2012 Siemens AG
4 *
5 * Written by:
6 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
7 * Sergey Lapin <slapin@ossfans.org>
8 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
9 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
10 */
11
12#include <linux/if_arp.h>
13
14#include <net/mac802154.h>
15#include <net/ieee802154_netdev.h>
16#include <net/cfg802154.h>
17
18#include "ieee802154_i.h"
19#include "driver-ops.h"
20
21void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
22{
23 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
24 struct ieee802154_local *local = sdata->local;
25 int res;
26
27 ASSERT_RTNL();
28
29 BUG_ON(dev->type != ARPHRD_IEEE802154);
30
31 res = drv_set_channel(local, page, chan);
32 if (res) {
33 pr_debug("set_channel failed\n");
34 } else {
35 local->phy->current_channel = chan;
36 local->phy->current_page = page;
37 }
38}
39
40int mac802154_get_params(struct net_device *dev,
41 struct ieee802154_llsec_params *params)
42{
43 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
44 int res;
45
46 BUG_ON(dev->type != ARPHRD_IEEE802154);
47
48 mutex_lock(&sdata->sec_mtx);
49 res = mac802154_llsec_get_params(&sdata->sec, params);
50 mutex_unlock(&sdata->sec_mtx);
51
52 return res;
53}
54
55int mac802154_set_params(struct net_device *dev,
56 const struct ieee802154_llsec_params *params,
57 int changed)
58{
59 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
60 int res;
61
62 BUG_ON(dev->type != ARPHRD_IEEE802154);
63
64 mutex_lock(&sdata->sec_mtx);
65 res = mac802154_llsec_set_params(&sdata->sec, params, changed);
66 mutex_unlock(&sdata->sec_mtx);
67
68 return res;
69}
70
71int mac802154_add_key(struct net_device *dev,
72 const struct ieee802154_llsec_key_id *id,
73 const struct ieee802154_llsec_key *key)
74{
75 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
76 int res;
77
78 BUG_ON(dev->type != ARPHRD_IEEE802154);
79
80 mutex_lock(&sdata->sec_mtx);
81 res = mac802154_llsec_key_add(&sdata->sec, id, key);
82 mutex_unlock(&sdata->sec_mtx);
83
84 return res;
85}
86
87int mac802154_del_key(struct net_device *dev,
88 const struct ieee802154_llsec_key_id *id)
89{
90 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
91 int res;
92
93 BUG_ON(dev->type != ARPHRD_IEEE802154);
94
95 mutex_lock(&sdata->sec_mtx);
96 res = mac802154_llsec_key_del(&sdata->sec, id);
97 mutex_unlock(&sdata->sec_mtx);
98
99 return res;
100}
101
102int mac802154_add_dev(struct net_device *dev,
103 const struct ieee802154_llsec_device *llsec_dev)
104{
105 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
106 int res;
107
108 BUG_ON(dev->type != ARPHRD_IEEE802154);
109
110 mutex_lock(&sdata->sec_mtx);
111 res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
112 mutex_unlock(&sdata->sec_mtx);
113
114 return res;
115}
116
117int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
118{
119 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
120 int res;
121
122 BUG_ON(dev->type != ARPHRD_IEEE802154);
123
124 mutex_lock(&sdata->sec_mtx);
125 res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
126 mutex_unlock(&sdata->sec_mtx);
127
128 return res;
129}
130
131int mac802154_add_devkey(struct net_device *dev,
132 __le64 device_addr,
133 const struct ieee802154_llsec_device_key *key)
134{
135 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
136 int res;
137
138 BUG_ON(dev->type != ARPHRD_IEEE802154);
139
140 mutex_lock(&sdata->sec_mtx);
141 res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
142 mutex_unlock(&sdata->sec_mtx);
143
144 return res;
145}
146
147int mac802154_del_devkey(struct net_device *dev,
148 __le64 device_addr,
149 const struct ieee802154_llsec_device_key *key)
150{
151 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
152 int res;
153
154 BUG_ON(dev->type != ARPHRD_IEEE802154);
155
156 mutex_lock(&sdata->sec_mtx);
157 res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
158 mutex_unlock(&sdata->sec_mtx);
159
160 return res;
161}
162
163int mac802154_add_seclevel(struct net_device *dev,
164 const struct ieee802154_llsec_seclevel *sl)
165{
166 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
167 int res;
168
169 BUG_ON(dev->type != ARPHRD_IEEE802154);
170
171 mutex_lock(&sdata->sec_mtx);
172 res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
173 mutex_unlock(&sdata->sec_mtx);
174
175 return res;
176}
177
178int mac802154_del_seclevel(struct net_device *dev,
179 const struct ieee802154_llsec_seclevel *sl)
180{
181 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
182 int res;
183
184 BUG_ON(dev->type != ARPHRD_IEEE802154);
185
186 mutex_lock(&sdata->sec_mtx);
187 res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
188 mutex_unlock(&sdata->sec_mtx);
189
190 return res;
191}
192
193void mac802154_lock_table(struct net_device *dev)
194{
195 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
196
197 BUG_ON(dev->type != ARPHRD_IEEE802154);
198
199 mutex_lock(&sdata->sec_mtx);
200}
201
202void mac802154_get_table(struct net_device *dev,
203 struct ieee802154_llsec_table **t)
204{
205 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
206
207 BUG_ON(dev->type != ARPHRD_IEEE802154);
208
209 *t = &sdata->sec.table;
210}
211
212void mac802154_unlock_table(struct net_device *dev)
213{
214 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
215
216 BUG_ON(dev->type != ARPHRD_IEEE802154);
217
218 mutex_unlock(&sdata->sec_mtx);
219}
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
81void 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}