blob: 81666e1d779d14affad5c5a32100f6b34a861cd0 [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001// SPDX-License-Identifier: GPL-2.0-only
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +00002/*
3 * Copyright 2007-2012 Siemens AG
4 *
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +00005 * 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>
Phoebe Buckheisterb70ab2e2014-03-14 21:23:59 +010015#include <net/ieee802154_netdev.h>
Alexander Aring5ad60d32014-10-25 09:41:02 +020016#include <net/cfg802154.h>
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +000017
Alexander Aring0f1556b2014-10-25 09:41:00 +020018#include "ieee802154_i.h"
Alexander Aring59cb3002014-10-28 18:21:21 +010019#include "driver-ops.h"
alex.bluesman.smirnov@gmail.comef2486f2012-05-15 20:50:26 +000020
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +000021void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
22{
Alexander Aring59d19cd2014-10-25 17:16:40 +020023 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Alexander Aring12439a52014-10-28 18:21:29 +010024 struct ieee802154_local *local = sdata->local;
25 int res;
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +000026
Alexander Aring4a3a8c02015-05-22 17:43:52 +020027 ASSERT_RTNL();
28
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +000029 BUG_ON(dev->type != ARPHRD_IEEE802154);
30
Alexander Aring12439a52014-10-28 18:21:29 +010031 res = drv_set_channel(local, page, chan);
32 if (res) {
33 pr_debug("set_channel failed\n");
Varka Bhadram4710d802014-07-02 09:01:09 +053034 } else {
Alexander Aring12439a52014-10-28 18:21:29 +010035 local->phy->current_channel = chan;
36 local->phy->current_page = page;
Varka Bhadram4710d802014-07-02 09:01:09 +053037 }
alex.bluesman.smirnov@gmail.com66b69d42012-06-25 23:24:51 +000038}
Phoebe Buckheister29e02372014-05-16 17:46:42 +020039
Phoebe Buckheister29e02372014-05-16 17:46:42 +020040int mac802154_get_params(struct net_device *dev,
41 struct ieee802154_llsec_params *params)
42{
Alexander Aring59d19cd2014-10-25 17:16:40 +020043 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020044 int res;
45
46 BUG_ON(dev->type != ARPHRD_IEEE802154);
47
Alexander Aring036562f2014-10-25 17:16:36 +020048 mutex_lock(&sdata->sec_mtx);
49 res = mac802154_llsec_get_params(&sdata->sec, params);
50 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020051
52 return res;
53}
54
55int mac802154_set_params(struct net_device *dev,
56 const struct ieee802154_llsec_params *params,
57 int changed)
58{
Alexander Aring59d19cd2014-10-25 17:16:40 +020059 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020060 int res;
61
62 BUG_ON(dev->type != ARPHRD_IEEE802154);
63
Alexander Aring036562f2014-10-25 17:16:36 +020064 mutex_lock(&sdata->sec_mtx);
65 res = mac802154_llsec_set_params(&sdata->sec, params, changed);
66 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020067
68 return res;
69}
70
Phoebe Buckheister29e02372014-05-16 17:46:42 +020071int mac802154_add_key(struct net_device *dev,
72 const struct ieee802154_llsec_key_id *id,
73 const struct ieee802154_llsec_key *key)
74{
Alexander Aring59d19cd2014-10-25 17:16:40 +020075 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020076 int res;
77
78 BUG_ON(dev->type != ARPHRD_IEEE802154);
79
Alexander Aring036562f2014-10-25 17:16:36 +020080 mutex_lock(&sdata->sec_mtx);
81 res = mac802154_llsec_key_add(&sdata->sec, id, key);
82 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020083
84 return res;
85}
86
87int mac802154_del_key(struct net_device *dev,
88 const struct ieee802154_llsec_key_id *id)
89{
Alexander Aring59d19cd2014-10-25 17:16:40 +020090 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020091 int res;
92
93 BUG_ON(dev->type != ARPHRD_IEEE802154);
94
Alexander Aring036562f2014-10-25 17:16:36 +020095 mutex_lock(&sdata->sec_mtx);
96 res = mac802154_llsec_key_del(&sdata->sec, id);
97 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +020098
99 return res;
100}
101
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200102int mac802154_add_dev(struct net_device *dev,
103 const struct ieee802154_llsec_device *llsec_dev)
104{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200105 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200106 int res;
107
108 BUG_ON(dev->type != ARPHRD_IEEE802154);
109
Alexander Aring036562f2014-10-25 17:16:36 +0200110 mutex_lock(&sdata->sec_mtx);
111 res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
112 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200113
114 return res;
115}
116
117int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
118{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200119 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200120 int res;
121
122 BUG_ON(dev->type != ARPHRD_IEEE802154);
123
Alexander Aring036562f2014-10-25 17:16:36 +0200124 mutex_lock(&sdata->sec_mtx);
125 res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
126 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200127
128 return res;
129}
130
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200131int mac802154_add_devkey(struct net_device *dev,
132 __le64 device_addr,
133 const struct ieee802154_llsec_device_key *key)
134{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200135 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200136 int res;
137
138 BUG_ON(dev->type != ARPHRD_IEEE802154);
139
Alexander Aring036562f2014-10-25 17:16:36 +0200140 mutex_lock(&sdata->sec_mtx);
141 res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
142 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200143
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{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200151 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200152 int res;
153
154 BUG_ON(dev->type != ARPHRD_IEEE802154);
155
Alexander Aring036562f2014-10-25 17:16:36 +0200156 mutex_lock(&sdata->sec_mtx);
157 res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
158 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200159
160 return res;
161}
162
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200163int mac802154_add_seclevel(struct net_device *dev,
164 const struct ieee802154_llsec_seclevel *sl)
165{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200166 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200167 int res;
168
169 BUG_ON(dev->type != ARPHRD_IEEE802154);
170
Alexander Aring036562f2014-10-25 17:16:36 +0200171 mutex_lock(&sdata->sec_mtx);
172 res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
173 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200174
175 return res;
176}
177
178int mac802154_del_seclevel(struct net_device *dev,
179 const struct ieee802154_llsec_seclevel *sl)
180{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200181 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200182 int res;
183
184 BUG_ON(dev->type != ARPHRD_IEEE802154);
185
Alexander Aring036562f2014-10-25 17:16:36 +0200186 mutex_lock(&sdata->sec_mtx);
187 res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
188 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200189
190 return res;
191}
192
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200193void mac802154_lock_table(struct net_device *dev)
194{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200195 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200196
197 BUG_ON(dev->type != ARPHRD_IEEE802154);
198
Alexander Aring036562f2014-10-25 17:16:36 +0200199 mutex_lock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200200}
201
202void mac802154_get_table(struct net_device *dev,
203 struct ieee802154_llsec_table **t)
204{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200205 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200206
207 BUG_ON(dev->type != ARPHRD_IEEE802154);
208
Alexander Aring036562f2014-10-25 17:16:36 +0200209 *t = &sdata->sec.table;
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200210}
211
212void mac802154_unlock_table(struct net_device *dev)
213{
Alexander Aring59d19cd2014-10-25 17:16:40 +0200214 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200215
216 BUG_ON(dev->type != ARPHRD_IEEE802154);
217
Alexander Aring036562f2014-10-25 17:16:36 +0200218 mutex_unlock(&sdata->sec_mtx);
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200219}