2 * Copyright 2007-2012 Siemens AG
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.
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.
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>
20 #include <linux/if_arp.h>
22 #include <net/mac802154.h>
23 #include <net/ieee802154_netdev.h>
24 #include <net/cfg802154.h>
26 #include "ieee802154_i.h"
27 #include "driver-ops.h"
29 void mac802154_dev_set_short_addr(struct net_device
*dev
, __le16 val
)
31 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
33 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
35 spin_lock_bh(&sdata
->mib_lock
);
36 sdata
->wpan_dev
.short_addr
= val
;
37 spin_unlock_bh(&sdata
->mib_lock
);
40 __le16
mac802154_dev_get_short_addr(const struct net_device
*dev
)
42 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
45 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
47 spin_lock_bh(&sdata
->mib_lock
);
48 ret
= sdata
->wpan_dev
.short_addr
;
49 spin_unlock_bh(&sdata
->mib_lock
);
54 __le16
mac802154_dev_get_pan_id(const struct net_device
*dev
)
56 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
59 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
61 spin_lock_bh(&sdata
->mib_lock
);
62 ret
= sdata
->wpan_dev
.pan_id
;
63 spin_unlock_bh(&sdata
->mib_lock
);
68 void mac802154_dev_set_pan_id(struct net_device
*dev
, __le16 val
)
70 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
72 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
74 spin_lock_bh(&sdata
->mib_lock
);
75 sdata
->wpan_dev
.pan_id
= val
;
76 spin_unlock_bh(&sdata
->mib_lock
);
79 u8
mac802154_dev_get_dsn(const struct net_device
*dev
)
81 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
83 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
85 return sdata
->wpan_dev
.dsn
++;
88 void mac802154_dev_set_page_channel(struct net_device
*dev
, u8 page
, u8 chan
)
90 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
91 struct ieee802154_local
*local
= sdata
->local
;
94 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
96 res
= drv_set_channel(local
, page
, chan
);
98 pr_debug("set_channel failed\n");
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
);
107 int mac802154_get_params(struct net_device
*dev
,
108 struct ieee802154_llsec_params
*params
)
110 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
113 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
115 mutex_lock(&sdata
->sec_mtx
);
116 res
= mac802154_llsec_get_params(&sdata
->sec
, params
);
117 mutex_unlock(&sdata
->sec_mtx
);
122 int mac802154_set_params(struct net_device
*dev
,
123 const struct ieee802154_llsec_params
*params
,
126 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
129 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
131 mutex_lock(&sdata
->sec_mtx
);
132 res
= mac802154_llsec_set_params(&sdata
->sec
, params
, changed
);
133 mutex_unlock(&sdata
->sec_mtx
);
138 int mac802154_add_key(struct net_device
*dev
,
139 const struct ieee802154_llsec_key_id
*id
,
140 const struct ieee802154_llsec_key
*key
)
142 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
145 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
147 mutex_lock(&sdata
->sec_mtx
);
148 res
= mac802154_llsec_key_add(&sdata
->sec
, id
, key
);
149 mutex_unlock(&sdata
->sec_mtx
);
154 int mac802154_del_key(struct net_device
*dev
,
155 const struct ieee802154_llsec_key_id
*id
)
157 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
160 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
162 mutex_lock(&sdata
->sec_mtx
);
163 res
= mac802154_llsec_key_del(&sdata
->sec
, id
);
164 mutex_unlock(&sdata
->sec_mtx
);
169 int mac802154_add_dev(struct net_device
*dev
,
170 const struct ieee802154_llsec_device
*llsec_dev
)
172 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
175 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
177 mutex_lock(&sdata
->sec_mtx
);
178 res
= mac802154_llsec_dev_add(&sdata
->sec
, llsec_dev
);
179 mutex_unlock(&sdata
->sec_mtx
);
184 int mac802154_del_dev(struct net_device
*dev
, __le64 dev_addr
)
186 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
189 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
191 mutex_lock(&sdata
->sec_mtx
);
192 res
= mac802154_llsec_dev_del(&sdata
->sec
, dev_addr
);
193 mutex_unlock(&sdata
->sec_mtx
);
198 int mac802154_add_devkey(struct net_device
*dev
,
200 const struct ieee802154_llsec_device_key
*key
)
202 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
205 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
207 mutex_lock(&sdata
->sec_mtx
);
208 res
= mac802154_llsec_devkey_add(&sdata
->sec
, device_addr
, key
);
209 mutex_unlock(&sdata
->sec_mtx
);
214 int mac802154_del_devkey(struct net_device
*dev
,
216 const struct ieee802154_llsec_device_key
*key
)
218 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
221 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
223 mutex_lock(&sdata
->sec_mtx
);
224 res
= mac802154_llsec_devkey_del(&sdata
->sec
, device_addr
, key
);
225 mutex_unlock(&sdata
->sec_mtx
);
230 int mac802154_add_seclevel(struct net_device
*dev
,
231 const struct ieee802154_llsec_seclevel
*sl
)
233 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
236 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
238 mutex_lock(&sdata
->sec_mtx
);
239 res
= mac802154_llsec_seclevel_add(&sdata
->sec
, sl
);
240 mutex_unlock(&sdata
->sec_mtx
);
245 int mac802154_del_seclevel(struct net_device
*dev
,
246 const struct ieee802154_llsec_seclevel
*sl
)
248 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
251 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
253 mutex_lock(&sdata
->sec_mtx
);
254 res
= mac802154_llsec_seclevel_del(&sdata
->sec
, sl
);
255 mutex_unlock(&sdata
->sec_mtx
);
260 void mac802154_lock_table(struct net_device
*dev
)
262 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
264 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
266 mutex_lock(&sdata
->sec_mtx
);
269 void mac802154_get_table(struct net_device
*dev
,
270 struct ieee802154_llsec_table
**t
)
272 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
274 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
276 *t
= &sdata
->sec
.table
;
279 void mac802154_unlock_table(struct net_device
*dev
)
281 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
283 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
285 mutex_unlock(&sdata
->sec_mtx
);