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_page_channel(struct net_device
*dev
, u8 page
, u8 chan
)
31 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
32 struct ieee802154_local
*local
= sdata
->local
;
37 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
39 res
= drv_set_channel(local
, page
, chan
);
41 pr_debug("set_channel failed\n");
43 local
->phy
->current_channel
= chan
;
44 local
->phy
->current_page
= page
;
48 int mac802154_get_params(struct net_device
*dev
,
49 struct ieee802154_llsec_params
*params
)
51 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
54 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
56 mutex_lock(&sdata
->sec_mtx
);
57 res
= mac802154_llsec_get_params(&sdata
->sec
, params
);
58 mutex_unlock(&sdata
->sec_mtx
);
63 int mac802154_set_params(struct net_device
*dev
,
64 const struct ieee802154_llsec_params
*params
,
67 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
70 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
72 mutex_lock(&sdata
->sec_mtx
);
73 res
= mac802154_llsec_set_params(&sdata
->sec
, params
, changed
);
74 mutex_unlock(&sdata
->sec_mtx
);
79 int mac802154_add_key(struct net_device
*dev
,
80 const struct ieee802154_llsec_key_id
*id
,
81 const struct ieee802154_llsec_key
*key
)
83 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
86 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
88 mutex_lock(&sdata
->sec_mtx
);
89 res
= mac802154_llsec_key_add(&sdata
->sec
, id
, key
);
90 mutex_unlock(&sdata
->sec_mtx
);
95 int mac802154_del_key(struct net_device
*dev
,
96 const struct ieee802154_llsec_key_id
*id
)
98 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
101 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
103 mutex_lock(&sdata
->sec_mtx
);
104 res
= mac802154_llsec_key_del(&sdata
->sec
, id
);
105 mutex_unlock(&sdata
->sec_mtx
);
110 int mac802154_add_dev(struct net_device
*dev
,
111 const struct ieee802154_llsec_device
*llsec_dev
)
113 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
116 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
118 mutex_lock(&sdata
->sec_mtx
);
119 res
= mac802154_llsec_dev_add(&sdata
->sec
, llsec_dev
);
120 mutex_unlock(&sdata
->sec_mtx
);
125 int mac802154_del_dev(struct net_device
*dev
, __le64 dev_addr
)
127 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
130 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
132 mutex_lock(&sdata
->sec_mtx
);
133 res
= mac802154_llsec_dev_del(&sdata
->sec
, dev_addr
);
134 mutex_unlock(&sdata
->sec_mtx
);
139 int mac802154_add_devkey(struct net_device
*dev
,
141 const struct ieee802154_llsec_device_key
*key
)
143 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
146 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
148 mutex_lock(&sdata
->sec_mtx
);
149 res
= mac802154_llsec_devkey_add(&sdata
->sec
, device_addr
, key
);
150 mutex_unlock(&sdata
->sec_mtx
);
155 int mac802154_del_devkey(struct net_device
*dev
,
157 const struct ieee802154_llsec_device_key
*key
)
159 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
162 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
164 mutex_lock(&sdata
->sec_mtx
);
165 res
= mac802154_llsec_devkey_del(&sdata
->sec
, device_addr
, key
);
166 mutex_unlock(&sdata
->sec_mtx
);
171 int mac802154_add_seclevel(struct net_device
*dev
,
172 const struct ieee802154_llsec_seclevel
*sl
)
174 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
177 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
179 mutex_lock(&sdata
->sec_mtx
);
180 res
= mac802154_llsec_seclevel_add(&sdata
->sec
, sl
);
181 mutex_unlock(&sdata
->sec_mtx
);
186 int mac802154_del_seclevel(struct net_device
*dev
,
187 const struct ieee802154_llsec_seclevel
*sl
)
189 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
192 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
194 mutex_lock(&sdata
->sec_mtx
);
195 res
= mac802154_llsec_seclevel_del(&sdata
->sec
, sl
);
196 mutex_unlock(&sdata
->sec_mtx
);
201 void mac802154_lock_table(struct net_device
*dev
)
203 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
);
210 void mac802154_get_table(struct net_device
*dev
,
211 struct ieee802154_llsec_table
**t
)
213 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
215 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
217 *t
= &sdata
->sec
.table
;
220 void mac802154_unlock_table(struct net_device
*dev
)
222 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
224 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
226 mutex_unlock(&sdata
->sec_mtx
);