mac802154: remove channel attributes from sdata
[deliverable/linux.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 *
ef2486f5 13 * Written by:
14 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
15 * Sergey Lapin <slapin@ossfans.org>
16 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
17 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
18 */
19
20#include <linux/if_arp.h>
21
22#include <net/mac802154.h>
b70ab2e8 23#include <net/ieee802154_netdev.h>
5ad60d36 24#include <net/cfg802154.h>
ef2486f5 25
0f1556bc 26#include "ieee802154_i.h"
59cb300f 27#include "driver-ops.h"
ef2486f5 28
29struct hw_addr_filt_notify_work {
30 struct work_struct work;
31 struct net_device *dev;
32 unsigned long changed;
33};
34
a5e1ec53 35static struct ieee802154_local *mac802154_slave_get_priv(struct net_device *dev)
ef2486f5 36{
59d19cd7 37 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
ef2486f5 38
39 BUG_ON(dev->type != ARPHRD_IEEE802154);
40
04e850fe 41 return sdata->local;
ef2486f5 42}
43
44static void hw_addr_notify(struct work_struct *work)
45{
46 struct hw_addr_filt_notify_work *nw = container_of(work,
47 struct hw_addr_filt_notify_work, work);
a5e1ec53 48 struct ieee802154_local *local = mac802154_slave_get_priv(nw->dev);
ef2486f5 49 int res;
50
a5e1ec53
AA
51 res = local->ops->set_hw_addr_filt(&local->hw, &local->hw.hw_filt,
52 nw->changed);
ef2486f5 53 if (res)
54 pr_debug("failed changed mask %lx\n", nw->changed);
55
56 kfree(nw);
ef2486f5 57}
58
59static void set_hw_addr_filt(struct net_device *dev, unsigned long changed)
60{
59d19cd7 61 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
ef2486f5 62 struct hw_addr_filt_notify_work *work;
63
64 work = kzalloc(sizeof(*work), GFP_ATOMIC);
65 if (!work)
66 return;
67
68 INIT_WORK(&work->work, hw_addr_notify);
69 work->dev = dev;
70 work->changed = changed;
f7730542 71 queue_work(sdata->local->workqueue, &work->work);
ef2486f5 72}
73
b70ab2e8 74void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val)
48e44d50 75{
59d19cd7 76 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
48e44d50 77
78 BUG_ON(dev->type != ARPHRD_IEEE802154);
79
036562f9
AA
80 spin_lock_bh(&sdata->mib_lock);
81 sdata->short_addr = val;
82 spin_unlock_bh(&sdata->mib_lock);
48e44d50 83
04e850fe
AA
84 if ((sdata->local->ops->set_hw_addr_filt) &&
85 (sdata->local->hw.hw_filt.short_addr != sdata->short_addr)) {
86 sdata->local->hw.hw_filt.short_addr = sdata->short_addr;
57205c14 87 set_hw_addr_filt(dev, IEEE802154_AFILT_SADDR_CHANGED);
48e44d50 88 }
89}
90
b70ab2e8 91__le16 mac802154_dev_get_short_addr(const struct net_device *dev)
e885a47a 92{
59d19cd7 93 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
b70ab2e8 94 __le16 ret;
e885a47a 95
96 BUG_ON(dev->type != ARPHRD_IEEE802154);
97
036562f9
AA
98 spin_lock_bh(&sdata->mib_lock);
99 ret = sdata->short_addr;
100 spin_unlock_bh(&sdata->mib_lock);
e885a47a 101
102 return ret;
103}
104
ef2486f5 105void mac802154_dev_set_ieee_addr(struct net_device *dev)
106{
59d19cd7 107 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
04e850fe 108 struct ieee802154_local *local = sdata->local;
ef2486f5 109
036562f9 110 sdata->extended_addr = ieee802154_devaddr_from_raw(dev->dev_addr);
b70ab2e8 111
a5e1ec53 112 if (local->ops->set_hw_addr_filt &&
036562f9
AA
113 local->hw.hw_filt.ieee_addr != sdata->extended_addr) {
114 local->hw.hw_filt.ieee_addr = sdata->extended_addr;
57205c14 115 set_hw_addr_filt(dev, IEEE802154_AFILT_IEEEADDR_CHANGED);
ef2486f5 116 }
117}
dcbe4f93 118
b70ab2e8 119__le16 mac802154_dev_get_pan_id(const struct net_device *dev)
dcbe4f93 120{
59d19cd7 121 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
b70ab2e8 122 __le16 ret;
dcbe4f93 123
124 BUG_ON(dev->type != ARPHRD_IEEE802154);
125
036562f9
AA
126 spin_lock_bh(&sdata->mib_lock);
127 ret = sdata->pan_id;
128 spin_unlock_bh(&sdata->mib_lock);
dcbe4f93 129
130 return ret;
131}
132
b70ab2e8 133void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val)
dcbe4f93 134{
59d19cd7 135 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
dcbe4f93 136
137 BUG_ON(dev->type != ARPHRD_IEEE802154);
138
036562f9
AA
139 spin_lock_bh(&sdata->mib_lock);
140 sdata->pan_id = val;
141 spin_unlock_bh(&sdata->mib_lock);
dcbe4f93 142
04e850fe
AA
143 if ((sdata->local->ops->set_hw_addr_filt) &&
144 (sdata->local->hw.hw_filt.pan_id != sdata->pan_id)) {
145 sdata->local->hw.hw_filt.pan_id = sdata->pan_id;
57205c14 146 set_hw_addr_filt(dev, IEEE802154_AFILT_PANID_CHANGED);
dcbe4f93 147 }
148}
66b69d4d 149
0483546a
TC
150u8 mac802154_dev_get_dsn(const struct net_device *dev)
151{
59d19cd7 152 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0483546a
TC
153
154 BUG_ON(dev->type != ARPHRD_IEEE802154);
155
036562f9 156 return sdata->dsn++;
0483546a
TC
157}
158
66b69d4d 159void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
160{
59d19cd7 161 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
12439a53
AA
162 struct ieee802154_local *local = sdata->local;
163 int res;
66b69d4d 164
165 BUG_ON(dev->type != ARPHRD_IEEE802154);
166
12439a53
AA
167 res = drv_set_channel(local, page, chan);
168 if (res) {
169 pr_debug("set_channel failed\n");
4710d806 170 } else {
12439a53
AA
171 mutex_lock(&local->phy->pib_lock);
172 local->phy->current_channel = chan;
173 local->phy->current_page = page;
174 mutex_unlock(&local->phy->pib_lock);
4710d806 175 }
66b69d4d 176}
29e02374
PB
177
178
179int mac802154_get_params(struct net_device *dev,
180 struct ieee802154_llsec_params *params)
181{
59d19cd7 182 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
183 int res;
184
185 BUG_ON(dev->type != ARPHRD_IEEE802154);
186
036562f9
AA
187 mutex_lock(&sdata->sec_mtx);
188 res = mac802154_llsec_get_params(&sdata->sec, params);
189 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
190
191 return res;
192}
193
194int mac802154_set_params(struct net_device *dev,
195 const struct ieee802154_llsec_params *params,
196 int changed)
197{
59d19cd7 198 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
199 int res;
200
201 BUG_ON(dev->type != ARPHRD_IEEE802154);
202
036562f9
AA
203 mutex_lock(&sdata->sec_mtx);
204 res = mac802154_llsec_set_params(&sdata->sec, params, changed);
205 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
206
207 return res;
208}
209
210
211int mac802154_add_key(struct net_device *dev,
212 const struct ieee802154_llsec_key_id *id,
213 const struct ieee802154_llsec_key *key)
214{
59d19cd7 215 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
216 int res;
217
218 BUG_ON(dev->type != ARPHRD_IEEE802154);
219
036562f9
AA
220 mutex_lock(&sdata->sec_mtx);
221 res = mac802154_llsec_key_add(&sdata->sec, id, key);
222 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
223
224 return res;
225}
226
227int mac802154_del_key(struct net_device *dev,
228 const struct ieee802154_llsec_key_id *id)
229{
59d19cd7 230 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
231 int res;
232
233 BUG_ON(dev->type != ARPHRD_IEEE802154);
234
036562f9
AA
235 mutex_lock(&sdata->sec_mtx);
236 res = mac802154_llsec_key_del(&sdata->sec, id);
237 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
238
239 return res;
240}
241
242
243int mac802154_add_dev(struct net_device *dev,
244 const struct ieee802154_llsec_device *llsec_dev)
245{
59d19cd7 246 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
247 int res;
248
249 BUG_ON(dev->type != ARPHRD_IEEE802154);
250
036562f9
AA
251 mutex_lock(&sdata->sec_mtx);
252 res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
253 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
254
255 return res;
256}
257
258int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
259{
59d19cd7 260 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
261 int res;
262
263 BUG_ON(dev->type != ARPHRD_IEEE802154);
264
036562f9
AA
265 mutex_lock(&sdata->sec_mtx);
266 res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
267 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
268
269 return res;
270}
271
272
273int mac802154_add_devkey(struct net_device *dev,
274 __le64 device_addr,
275 const struct ieee802154_llsec_device_key *key)
276{
59d19cd7 277 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
278 int res;
279
280 BUG_ON(dev->type != ARPHRD_IEEE802154);
281
036562f9
AA
282 mutex_lock(&sdata->sec_mtx);
283 res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
284 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
285
286 return res;
287}
288
289int mac802154_del_devkey(struct net_device *dev,
290 __le64 device_addr,
291 const struct ieee802154_llsec_device_key *key)
292{
59d19cd7 293 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
294 int res;
295
296 BUG_ON(dev->type != ARPHRD_IEEE802154);
297
036562f9
AA
298 mutex_lock(&sdata->sec_mtx);
299 res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
300 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
301
302 return res;
303}
304
305
306int mac802154_add_seclevel(struct net_device *dev,
307 const struct ieee802154_llsec_seclevel *sl)
308{
59d19cd7 309 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
310 int res;
311
312 BUG_ON(dev->type != ARPHRD_IEEE802154);
313
036562f9
AA
314 mutex_lock(&sdata->sec_mtx);
315 res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
316 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
317
318 return res;
319}
320
321int mac802154_del_seclevel(struct net_device *dev,
322 const struct ieee802154_llsec_seclevel *sl)
323{
59d19cd7 324 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
325 int res;
326
327 BUG_ON(dev->type != ARPHRD_IEEE802154);
328
036562f9
AA
329 mutex_lock(&sdata->sec_mtx);
330 res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
331 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
332
333 return res;
334}
335
336
337void mac802154_lock_table(struct net_device *dev)
338{
59d19cd7 339 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
340
341 BUG_ON(dev->type != ARPHRD_IEEE802154);
342
036562f9 343 mutex_lock(&sdata->sec_mtx);
29e02374
PB
344}
345
346void mac802154_get_table(struct net_device *dev,
347 struct ieee802154_llsec_table **t)
348{
59d19cd7 349 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
350
351 BUG_ON(dev->type != ARPHRD_IEEE802154);
352
036562f9 353 *t = &sdata->sec.table;
29e02374
PB
354}
355
356void mac802154_unlock_table(struct net_device *dev)
357{
59d19cd7 358 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
359
360 BUG_ON(dev->type != ARPHRD_IEEE802154);
361
036562f9 362 mutex_unlock(&sdata->sec_mtx);
29e02374 363}
This page took 0.156212 seconds and 5 git commands to generate.