blob: 3596b29ead6b8716aded81244bee99d9626acca5 [file] [log] [blame]
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +00001/*
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 *
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +000013 * 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>
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010023#include <net/ieee802154_netdev.h>
Alexander Aring5ad60d32014-10-25 09:41:02 +020024#include <net/cfg802154.h>
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +000025
Alexander Aring0f1556b2014-10-25 09:41:00 +020026#include "ieee802154_i.h"
Alexander Aring59cb3002014-10-28 18:21:21 +010027#include "driver-ops.h"
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +000028
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010029void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val)
alex.bluesman.smirnov@gmail.com48e44d52012-06-25 23:24:50 +000030{
Alexander Aring59d19cd2014-10-25 17:16:40 +020031 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
alex.bluesman.smirnov@gmail.com48e44d52012-06-25 23:24:50 +000032
33 BUG_ON(dev->type != ARPHRD_IEEE802154);
34
Alexander Aring036562f2014-10-25 17:16:36 +020035 spin_lock_bh(&sdata->mib_lock);
Alexander Aring863e88f2014-11-09 08:36:45 +010036 sdata->wpan_dev.short_addr = val;
Alexander Aring036562f2014-10-25 17:16:36 +020037 spin_unlock_bh(&sdata->mib_lock);
alex.bluesman.smirnov@gmail.com48e44d52012-06-25 23:24:50 +000038}
39
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010040__le16 mac802154_dev_get_short_addr(const struct net_device *dev)
alex.bluesman.smirnov@gmail.come885a472012-07-10 21:22:44 +000041{
Alexander Aring59d19cd2014-10-25 17:16:40 +020042 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010043 __le16 ret;
alex.bluesman.smirnov@gmail.come885a472012-07-10 21:22:44 +000044
45 BUG_ON(dev->type != ARPHRD_IEEE802154);
46
Alexander Aring036562f2014-10-25 17:16:36 +020047 spin_lock_bh(&sdata->mib_lock);
Alexander Aring863e88f2014-11-09 08:36:45 +010048 ret = sdata->wpan_dev.short_addr;
Alexander Aring036562f2014-10-25 17:16:36 +020049 spin_unlock_bh(&sdata->mib_lock);
alex.bluesman.smirnov@gmail.come885a472012-07-10 21:22:44 +000050
51 return ret;
52}
53
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010054__le16 mac802154_dev_get_pan_id(const struct net_device *dev)
alex.bluesman.smirnov@gmail.comdcbe4f92012-06-25 23:24:49 +000055{
Alexander Aring59d19cd2014-10-25 17:16:40 +020056 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010057 __le16 ret;
alex.bluesman.smirnov@gmail.comdcbe4f92012-06-25 23:24:49 +000058
59 BUG_ON(dev->type != ARPHRD_IEEE802154);
60
Alexander Aring036562f2014-10-25 17:16:36 +020061 spin_lock_bh(&sdata->mib_lock);
Alexander Aring863e88f2014-11-09 08:36:45 +010062 ret = sdata->wpan_dev.pan_id;
Alexander Aring036562f2014-10-25 17:16:36 +020063 spin_unlock_bh(&sdata->mib_lock);
alex.bluesman.smirnov@gmail.comdcbe4f92012-06-25 23:24:49 +000064
65 return ret;
66}
67
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010068void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val)
alex.bluesman.smirnov@gmail.comdcbe4f92012-06-25 23:24:49 +000069{
Alexander Aring59d19cd2014-10-25 17:16:40 +020070 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
alex.bluesman.smirnov@gmail.comdcbe4f92012-06-25 23:24:49 +000071
72 BUG_ON(dev->type != ARPHRD_IEEE802154);
73
Alexander Aring036562f2014-10-25 17:16:36 +020074 spin_lock_bh(&sdata->mib_lock);
Alexander Aring863e88f2014-11-09 08:36:45 +010075 sdata->wpan_dev.pan_id = val;
Alexander Aring036562f2014-10-25 17:16:36 +020076 spin_unlock_bh(&sdata->mib_lock);
alex.bluesman.smirnov@gmail.comdcbe4f92012-06-25 23:24:49 +000077}
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +000078
Tony Cheneau04835462013-03-25 17:59:29 +000079u8 mac802154_dev_get_dsn(const struct net_device *dev)
80{
Alexander Aring59d19cd2014-10-25 17:16:40 +020081 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Tony Cheneau04835462013-03-25 17:59:29 +000082
83 BUG_ON(dev->type != ARPHRD_IEEE802154);
84
Alexander Aring863e88f2014-11-09 08:36:45 +010085 return sdata->wpan_dev.dsn++;
Tony Cheneau04835462013-03-25 17:59:29 +000086}
87
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +000088void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
89{
Alexander Aring59d19cd2014-10-25 17:16:40 +020090 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Alexander Aring12439a52014-10-28 18:21:29 +010091 struct ieee802154_local *local = sdata->local;
92 int res;
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +000093
94 BUG_ON(dev->type != ARPHRD_IEEE802154);
95
Alexander Aring12439a52014-10-28 18:21:29 +010096 res = drv_set_channel(local, page, chan);
97 if (res) {
98 pr_debug("set_channel failed\n");
Varka Bhadram4710d802014-07-02 09:01:09 +053099 } else {
Alexander Aring12439a52014-10-28 18:21:29 +0100100 mutex_lock(&local->phy->pib_lock);
101 local->phy->current_channel = chan;
102 local->phy->current_page = page;
103 mutex_unlock(&local->phy->pib_lock);
Varka Bhadram4710d802014-07-02 09:01:09 +0530104 }
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +0000105}
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200106
107
108int mac802154_get_params(struct net_device *dev,
109 struct ieee802154_llsec_params *params)
110{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200111 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200112 int res;
113
114 BUG_ON(dev->type != ARPHRD_IEEE802154);
115
Alexander Aring036562f2014-10-25 17:16:36 +0200116 mutex_lock(&sdata->sec_mtx);
117 res = mac802154_llsec_get_params(&sdata->sec, params);
118 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200119
120 return res;
121}
122
123int mac802154_set_params(struct net_device *dev,
124 const struct ieee802154_llsec_params *params,
125 int changed)
126{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200127 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200128 int res;
129
130 BUG_ON(dev->type != ARPHRD_IEEE802154);
131
Alexander Aring036562f2014-10-25 17:16:36 +0200132 mutex_lock(&sdata->sec_mtx);
133 res = mac802154_llsec_set_params(&sdata->sec, params, changed);
134 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200135
136 return res;
137}
138
139
140int mac802154_add_key(struct net_device *dev,
141 const struct ieee802154_llsec_key_id *id,
142 const struct ieee802154_llsec_key *key)
143{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200144 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200145 int res;
146
147 BUG_ON(dev->type != ARPHRD_IEEE802154);
148
Alexander Aring036562f2014-10-25 17:16:36 +0200149 mutex_lock(&sdata->sec_mtx);
150 res = mac802154_llsec_key_add(&sdata->sec, id, key);
151 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200152
153 return res;
154}
155
156int mac802154_del_key(struct net_device *dev,
157 const struct ieee802154_llsec_key_id *id)
158{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200159 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200160 int res;
161
162 BUG_ON(dev->type != ARPHRD_IEEE802154);
163
Alexander Aring036562f2014-10-25 17:16:36 +0200164 mutex_lock(&sdata->sec_mtx);
165 res = mac802154_llsec_key_del(&sdata->sec, id);
166 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200167
168 return res;
169}
170
171
172int mac802154_add_dev(struct net_device *dev,
173 const struct ieee802154_llsec_device *llsec_dev)
174{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200175 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200176 int res;
177
178 BUG_ON(dev->type != ARPHRD_IEEE802154);
179
Alexander Aring036562f2014-10-25 17:16:36 +0200180 mutex_lock(&sdata->sec_mtx);
181 res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
182 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200183
184 return res;
185}
186
187int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
188{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200189 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200190 int res;
191
192 BUG_ON(dev->type != ARPHRD_IEEE802154);
193
Alexander Aring036562f2014-10-25 17:16:36 +0200194 mutex_lock(&sdata->sec_mtx);
195 res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
196 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200197
198 return res;
199}
200
201
202int mac802154_add_devkey(struct net_device *dev,
203 __le64 device_addr,
204 const struct ieee802154_llsec_device_key *key)
205{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200206 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200207 int res;
208
209 BUG_ON(dev->type != ARPHRD_IEEE802154);
210
Alexander Aring036562f2014-10-25 17:16:36 +0200211 mutex_lock(&sdata->sec_mtx);
212 res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
213 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200214
215 return res;
216}
217
218int mac802154_del_devkey(struct net_device *dev,
219 __le64 device_addr,
220 const struct ieee802154_llsec_device_key *key)
221{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200222 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200223 int res;
224
225 BUG_ON(dev->type != ARPHRD_IEEE802154);
226
Alexander Aring036562f2014-10-25 17:16:36 +0200227 mutex_lock(&sdata->sec_mtx);
228 res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
229 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200230
231 return res;
232}
233
234
235int mac802154_add_seclevel(struct net_device *dev,
236 const struct ieee802154_llsec_seclevel *sl)
237{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200238 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200239 int res;
240
241 BUG_ON(dev->type != ARPHRD_IEEE802154);
242
Alexander Aring036562f2014-10-25 17:16:36 +0200243 mutex_lock(&sdata->sec_mtx);
244 res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
245 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200246
247 return res;
248}
249
250int mac802154_del_seclevel(struct net_device *dev,
251 const struct ieee802154_llsec_seclevel *sl)
252{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200253 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200254 int res;
255
256 BUG_ON(dev->type != ARPHRD_IEEE802154);
257
Alexander Aring036562f2014-10-25 17:16:36 +0200258 mutex_lock(&sdata->sec_mtx);
259 res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
260 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200261
262 return res;
263}
264
265
266void mac802154_lock_table(struct net_device *dev)
267{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200268 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200269
270 BUG_ON(dev->type != ARPHRD_IEEE802154);
271
Alexander Aring036562f2014-10-25 17:16:36 +0200272 mutex_lock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200273}
274
275void mac802154_get_table(struct net_device *dev,
276 struct ieee802154_llsec_table **t)
277{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200278 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200279
280 BUG_ON(dev->type != ARPHRD_IEEE802154);
281
Alexander Aring036562f2014-10-25 17:16:36 +0200282 *t = &sdata->sec.table;
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200283}
284
285void mac802154_unlock_table(struct net_device *dev)
286{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200287 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200288
289 BUG_ON(dev->type != ARPHRD_IEEE802154);
290
Alexander Aring036562f2014-10-25 17:16:36 +0200291 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200292}