Commit | Line | Data |
---|---|---|
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 | |
b70ab2e8 | 29 | void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val) |
48e44d50 | 30 | { |
59d19cd7 | 31 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
48e44d50 | 32 | |
33 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
34 | ||
036562f9 | 35 | spin_lock_bh(&sdata->mib_lock); |
863e88f2 | 36 | sdata->wpan_dev.short_addr = val; |
036562f9 | 37 | spin_unlock_bh(&sdata->mib_lock); |
48e44d50 | 38 | } |
39 | ||
b70ab2e8 | 40 | __le16 mac802154_dev_get_short_addr(const struct net_device *dev) |
e885a47a | 41 | { |
59d19cd7 | 42 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
b70ab2e8 | 43 | __le16 ret; |
e885a47a | 44 | |
45 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
46 | ||
036562f9 | 47 | spin_lock_bh(&sdata->mib_lock); |
863e88f2 | 48 | ret = sdata->wpan_dev.short_addr; |
036562f9 | 49 | spin_unlock_bh(&sdata->mib_lock); |
e885a47a | 50 | |
51 | return ret; | |
52 | } | |
53 | ||
b70ab2e8 | 54 | __le16 mac802154_dev_get_pan_id(const struct net_device *dev) |
dcbe4f93 | 55 | { |
59d19cd7 | 56 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
b70ab2e8 | 57 | __le16 ret; |
dcbe4f93 | 58 | |
59 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
60 | ||
036562f9 | 61 | spin_lock_bh(&sdata->mib_lock); |
863e88f2 | 62 | ret = sdata->wpan_dev.pan_id; |
036562f9 | 63 | spin_unlock_bh(&sdata->mib_lock); |
dcbe4f93 | 64 | |
65 | return ret; | |
66 | } | |
67 | ||
b70ab2e8 | 68 | void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val) |
dcbe4f93 | 69 | { |
59d19cd7 | 70 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
dcbe4f93 | 71 | |
72 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
73 | ||
036562f9 | 74 | spin_lock_bh(&sdata->mib_lock); |
863e88f2 | 75 | sdata->wpan_dev.pan_id = val; |
036562f9 | 76 | spin_unlock_bh(&sdata->mib_lock); |
dcbe4f93 | 77 | } |
66b69d4d | 78 | |
0483546a TC |
79 | u8 mac802154_dev_get_dsn(const struct net_device *dev) |
80 | { | |
59d19cd7 | 81 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
0483546a TC |
82 | |
83 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
84 | ||
863e88f2 | 85 | return sdata->wpan_dev.dsn++; |
0483546a TC |
86 | } |
87 | ||
66b69d4d | 88 | void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan) |
89 | { | |
59d19cd7 | 90 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
12439a53 AA |
91 | struct ieee802154_local *local = sdata->local; |
92 | int res; | |
66b69d4d | 93 | |
94 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
95 | ||
12439a53 AA |
96 | res = drv_set_channel(local, page, chan); |
97 | if (res) { | |
98 | pr_debug("set_channel failed\n"); | |
4710d806 | 99 | } else { |
12439a53 AA |
100 | 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); | |
4710d806 | 104 | } |
66b69d4d | 105 | } |
29e02374 PB |
106 | |
107 | ||
108 | int mac802154_get_params(struct net_device *dev, | |
109 | struct ieee802154_llsec_params *params) | |
110 | { | |
59d19cd7 | 111 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
112 | int res; |
113 | ||
114 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
115 | ||
036562f9 AA |
116 | mutex_lock(&sdata->sec_mtx); |
117 | res = mac802154_llsec_get_params(&sdata->sec, params); | |
118 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
119 | |
120 | return res; | |
121 | } | |
122 | ||
123 | int mac802154_set_params(struct net_device *dev, | |
124 | const struct ieee802154_llsec_params *params, | |
125 | int changed) | |
126 | { | |
59d19cd7 | 127 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
128 | int res; |
129 | ||
130 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
131 | ||
036562f9 AA |
132 | mutex_lock(&sdata->sec_mtx); |
133 | res = mac802154_llsec_set_params(&sdata->sec, params, changed); | |
134 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
135 | |
136 | return res; | |
137 | } | |
138 | ||
139 | ||
140 | int mac802154_add_key(struct net_device *dev, | |
141 | const struct ieee802154_llsec_key_id *id, | |
142 | const struct ieee802154_llsec_key *key) | |
143 | { | |
59d19cd7 | 144 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
145 | int res; |
146 | ||
147 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
148 | ||
036562f9 AA |
149 | mutex_lock(&sdata->sec_mtx); |
150 | res = mac802154_llsec_key_add(&sdata->sec, id, key); | |
151 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
152 | |
153 | return res; | |
154 | } | |
155 | ||
156 | int mac802154_del_key(struct net_device *dev, | |
157 | const struct ieee802154_llsec_key_id *id) | |
158 | { | |
59d19cd7 | 159 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
160 | int res; |
161 | ||
162 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
163 | ||
036562f9 AA |
164 | mutex_lock(&sdata->sec_mtx); |
165 | res = mac802154_llsec_key_del(&sdata->sec, id); | |
166 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
167 | |
168 | return res; | |
169 | } | |
170 | ||
171 | ||
172 | int mac802154_add_dev(struct net_device *dev, | |
173 | const struct ieee802154_llsec_device *llsec_dev) | |
174 | { | |
59d19cd7 | 175 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
176 | int res; |
177 | ||
178 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
179 | ||
036562f9 AA |
180 | mutex_lock(&sdata->sec_mtx); |
181 | res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev); | |
182 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
183 | |
184 | return res; | |
185 | } | |
186 | ||
187 | int mac802154_del_dev(struct net_device *dev, __le64 dev_addr) | |
188 | { | |
59d19cd7 | 189 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
190 | int res; |
191 | ||
192 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
193 | ||
036562f9 AA |
194 | mutex_lock(&sdata->sec_mtx); |
195 | res = mac802154_llsec_dev_del(&sdata->sec, dev_addr); | |
196 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
197 | |
198 | return res; | |
199 | } | |
200 | ||
201 | ||
202 | int mac802154_add_devkey(struct net_device *dev, | |
203 | __le64 device_addr, | |
204 | const struct ieee802154_llsec_device_key *key) | |
205 | { | |
59d19cd7 | 206 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
207 | int res; |
208 | ||
209 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
210 | ||
036562f9 AA |
211 | mutex_lock(&sdata->sec_mtx); |
212 | res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key); | |
213 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
214 | |
215 | return res; | |
216 | } | |
217 | ||
218 | int mac802154_del_devkey(struct net_device *dev, | |
219 | __le64 device_addr, | |
220 | const struct ieee802154_llsec_device_key *key) | |
221 | { | |
59d19cd7 | 222 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
223 | int res; |
224 | ||
225 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
226 | ||
036562f9 AA |
227 | mutex_lock(&sdata->sec_mtx); |
228 | res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key); | |
229 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
230 | |
231 | return res; | |
232 | } | |
233 | ||
234 | ||
235 | int mac802154_add_seclevel(struct net_device *dev, | |
236 | const struct ieee802154_llsec_seclevel *sl) | |
237 | { | |
59d19cd7 | 238 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
239 | int res; |
240 | ||
241 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
242 | ||
036562f9 AA |
243 | mutex_lock(&sdata->sec_mtx); |
244 | res = mac802154_llsec_seclevel_add(&sdata->sec, sl); | |
245 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
246 | |
247 | return res; | |
248 | } | |
249 | ||
250 | int mac802154_del_seclevel(struct net_device *dev, | |
251 | const struct ieee802154_llsec_seclevel *sl) | |
252 | { | |
59d19cd7 | 253 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
254 | int res; |
255 | ||
256 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
257 | ||
036562f9 AA |
258 | mutex_lock(&sdata->sec_mtx); |
259 | res = mac802154_llsec_seclevel_del(&sdata->sec, sl); | |
260 | mutex_unlock(&sdata->sec_mtx); | |
29e02374 PB |
261 | |
262 | return res; | |
263 | } | |
264 | ||
265 | ||
266 | void mac802154_lock_table(struct net_device *dev) | |
267 | { | |
59d19cd7 | 268 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
269 | |
270 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
271 | ||
036562f9 | 272 | mutex_lock(&sdata->sec_mtx); |
29e02374 PB |
273 | } |
274 | ||
275 | void mac802154_get_table(struct net_device *dev, | |
276 | struct ieee802154_llsec_table **t) | |
277 | { | |
59d19cd7 | 278 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
279 | |
280 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
281 | ||
036562f9 | 282 | *t = &sdata->sec.table; |
29e02374 PB |
283 | } |
284 | ||
285 | void mac802154_unlock_table(struct net_device *dev) | |
286 | { | |
59d19cd7 | 287 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
29e02374 PB |
288 | |
289 | BUG_ON(dev->type != ARPHRD_IEEE802154); | |
290 | ||
036562f9 | 291 | mutex_unlock(&sdata->sec_mtx); |
29e02374 | 292 | } |