]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/mac802154/mib.c
Merge tag 'media/v5.15-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[mirror_ubuntu-jammy-kernel.git] / net / mac802154 / mib.c
CommitLineData
1802d0be 1// SPDX-License-Identifier: GPL-2.0-only
ef2486f5 2/*
3 * Copyright 2007-2012 Siemens AG
4 *
ef2486f5 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>
b70ab2e8 15#include <net/ieee802154_netdev.h>
5ad60d36 16#include <net/cfg802154.h>
ef2486f5 17
0f1556bc 18#include "ieee802154_i.h"
59cb300f 19#include "driver-ops.h"
ef2486f5 20
66b69d4d 21void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
22{
59d19cd7 23 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
12439a53
AA
24 struct ieee802154_local *local = sdata->local;
25 int res;
66b69d4d 26
4a3a8c0c
AA
27 ASSERT_RTNL();
28
66b69d4d 29 BUG_ON(dev->type != ARPHRD_IEEE802154);
30
12439a53
AA
31 res = drv_set_channel(local, page, chan);
32 if (res) {
33 pr_debug("set_channel failed\n");
4710d806 34 } else {
12439a53
AA
35 local->phy->current_channel = chan;
36 local->phy->current_page = page;
4710d806 37 }
66b69d4d 38}
29e02374 39
29e02374
PB
40int mac802154_get_params(struct net_device *dev,
41 struct ieee802154_llsec_params *params)
42{
59d19cd7 43 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
44 int res;
45
46 BUG_ON(dev->type != ARPHRD_IEEE802154);
47
036562f9
AA
48 mutex_lock(&sdata->sec_mtx);
49 res = mac802154_llsec_get_params(&sdata->sec, params);
50 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
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{
59d19cd7 59 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
60 int res;
61
62 BUG_ON(dev->type != ARPHRD_IEEE802154);
63
036562f9
AA
64 mutex_lock(&sdata->sec_mtx);
65 res = mac802154_llsec_set_params(&sdata->sec, params, changed);
66 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
67
68 return res;
69}
70
29e02374
PB
71int mac802154_add_key(struct net_device *dev,
72 const struct ieee802154_llsec_key_id *id,
73 const struct ieee802154_llsec_key *key)
74{
59d19cd7 75 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
76 int res;
77
78 BUG_ON(dev->type != ARPHRD_IEEE802154);
79
036562f9
AA
80 mutex_lock(&sdata->sec_mtx);
81 res = mac802154_llsec_key_add(&sdata->sec, id, key);
82 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
83
84 return res;
85}
86
87int mac802154_del_key(struct net_device *dev,
88 const struct ieee802154_llsec_key_id *id)
89{
59d19cd7 90 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
91 int res;
92
93 BUG_ON(dev->type != ARPHRD_IEEE802154);
94
036562f9
AA
95 mutex_lock(&sdata->sec_mtx);
96 res = mac802154_llsec_key_del(&sdata->sec, id);
97 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
98
99 return res;
100}
101
29e02374
PB
102int mac802154_add_dev(struct net_device *dev,
103 const struct ieee802154_llsec_device *llsec_dev)
104{
59d19cd7 105 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
106 int res;
107
108 BUG_ON(dev->type != ARPHRD_IEEE802154);
109
036562f9
AA
110 mutex_lock(&sdata->sec_mtx);
111 res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
112 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
113
114 return res;
115}
116
117int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
118{
59d19cd7 119 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
120 int res;
121
122 BUG_ON(dev->type != ARPHRD_IEEE802154);
123
036562f9
AA
124 mutex_lock(&sdata->sec_mtx);
125 res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
126 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
127
128 return res;
129}
130
29e02374
PB
131int mac802154_add_devkey(struct net_device *dev,
132 __le64 device_addr,
133 const struct ieee802154_llsec_device_key *key)
134{
59d19cd7 135 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
136 int res;
137
138 BUG_ON(dev->type != ARPHRD_IEEE802154);
139
036562f9
AA
140 mutex_lock(&sdata->sec_mtx);
141 res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
142 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
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{
59d19cd7 151 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
152 int res;
153
154 BUG_ON(dev->type != ARPHRD_IEEE802154);
155
036562f9
AA
156 mutex_lock(&sdata->sec_mtx);
157 res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
158 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
159
160 return res;
161}
162
29e02374
PB
163int mac802154_add_seclevel(struct net_device *dev,
164 const struct ieee802154_llsec_seclevel *sl)
165{
59d19cd7 166 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
167 int res;
168
169 BUG_ON(dev->type != ARPHRD_IEEE802154);
170
036562f9
AA
171 mutex_lock(&sdata->sec_mtx);
172 res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
173 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
174
175 return res;
176}
177
178int mac802154_del_seclevel(struct net_device *dev,
179 const struct ieee802154_llsec_seclevel *sl)
180{
59d19cd7 181 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
182 int res;
183
184 BUG_ON(dev->type != ARPHRD_IEEE802154);
185
036562f9
AA
186 mutex_lock(&sdata->sec_mtx);
187 res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
188 mutex_unlock(&sdata->sec_mtx);
29e02374
PB
189
190 return res;
191}
192
29e02374
PB
193void mac802154_lock_table(struct net_device *dev)
194{
59d19cd7 195 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
196
197 BUG_ON(dev->type != ARPHRD_IEEE802154);
198
036562f9 199 mutex_lock(&sdata->sec_mtx);
29e02374
PB
200}
201
202void mac802154_get_table(struct net_device *dev,
203 struct ieee802154_llsec_table **t)
204{
59d19cd7 205 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
206
207 BUG_ON(dev->type != ARPHRD_IEEE802154);
208
036562f9 209 *t = &sdata->sec.table;
29e02374
PB
210}
211
212void mac802154_unlock_table(struct net_device *dev)
213{
59d19cd7 214 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
29e02374
PB
215
216 BUG_ON(dev->type != ARPHRD_IEEE802154);
217
036562f9 218 mutex_unlock(&sdata->sec_mtx);
29e02374 219}