1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2007-2012 Siemens AG
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>
12 #include <linux/if_arp.h>
14 #include <net/mac802154.h>
15 #include <net/ieee802154_netdev.h>
16 #include <net/cfg802154.h>
18 #include "ieee802154_i.h"
19 #include "driver-ops.h"
21 void mac802154_dev_set_page_channel(struct net_device
*dev
, u8 page
, u8 chan
)
23 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
24 struct ieee802154_local
*local
= sdata
->local
;
29 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
31 res
= drv_set_channel(local
, page
, chan
);
33 pr_debug("set_channel failed\n");
35 local
->phy
->current_channel
= chan
;
36 local
->phy
->current_page
= page
;
40 int mac802154_get_params(struct net_device
*dev
,
41 struct ieee802154_llsec_params
*params
)
43 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
46 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
48 mutex_lock(&sdata
->sec_mtx
);
49 res
= mac802154_llsec_get_params(&sdata
->sec
, params
);
50 mutex_unlock(&sdata
->sec_mtx
);
55 int mac802154_set_params(struct net_device
*dev
,
56 const struct ieee802154_llsec_params
*params
,
59 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
62 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
64 mutex_lock(&sdata
->sec_mtx
);
65 res
= mac802154_llsec_set_params(&sdata
->sec
, params
, changed
);
66 mutex_unlock(&sdata
->sec_mtx
);
71 int mac802154_add_key(struct net_device
*dev
,
72 const struct ieee802154_llsec_key_id
*id
,
73 const struct ieee802154_llsec_key
*key
)
75 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
78 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
80 mutex_lock(&sdata
->sec_mtx
);
81 res
= mac802154_llsec_key_add(&sdata
->sec
, id
, key
);
82 mutex_unlock(&sdata
->sec_mtx
);
87 int mac802154_del_key(struct net_device
*dev
,
88 const struct ieee802154_llsec_key_id
*id
)
90 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
93 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
95 mutex_lock(&sdata
->sec_mtx
);
96 res
= mac802154_llsec_key_del(&sdata
->sec
, id
);
97 mutex_unlock(&sdata
->sec_mtx
);
102 int mac802154_add_dev(struct net_device
*dev
,
103 const struct ieee802154_llsec_device
*llsec_dev
)
105 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
108 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
110 mutex_lock(&sdata
->sec_mtx
);
111 res
= mac802154_llsec_dev_add(&sdata
->sec
, llsec_dev
);
112 mutex_unlock(&sdata
->sec_mtx
);
117 int mac802154_del_dev(struct net_device
*dev
, __le64 dev_addr
)
119 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
122 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
124 mutex_lock(&sdata
->sec_mtx
);
125 res
= mac802154_llsec_dev_del(&sdata
->sec
, dev_addr
);
126 mutex_unlock(&sdata
->sec_mtx
);
131 int mac802154_add_devkey(struct net_device
*dev
,
133 const struct ieee802154_llsec_device_key
*key
)
135 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
138 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
140 mutex_lock(&sdata
->sec_mtx
);
141 res
= mac802154_llsec_devkey_add(&sdata
->sec
, device_addr
, key
);
142 mutex_unlock(&sdata
->sec_mtx
);
147 int mac802154_del_devkey(struct net_device
*dev
,
149 const struct ieee802154_llsec_device_key
*key
)
151 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
154 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
156 mutex_lock(&sdata
->sec_mtx
);
157 res
= mac802154_llsec_devkey_del(&sdata
->sec
, device_addr
, key
);
158 mutex_unlock(&sdata
->sec_mtx
);
163 int mac802154_add_seclevel(struct net_device
*dev
,
164 const struct ieee802154_llsec_seclevel
*sl
)
166 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
169 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
171 mutex_lock(&sdata
->sec_mtx
);
172 res
= mac802154_llsec_seclevel_add(&sdata
->sec
, sl
);
173 mutex_unlock(&sdata
->sec_mtx
);
178 int mac802154_del_seclevel(struct net_device
*dev
,
179 const struct ieee802154_llsec_seclevel
*sl
)
181 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
184 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
186 mutex_lock(&sdata
->sec_mtx
);
187 res
= mac802154_llsec_seclevel_del(&sdata
->sec
, sl
);
188 mutex_unlock(&sdata
->sec_mtx
);
193 void mac802154_lock_table(struct net_device
*dev
)
195 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
197 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
199 mutex_lock(&sdata
->sec_mtx
);
202 void mac802154_get_table(struct net_device
*dev
,
203 struct ieee802154_llsec_table
**t
)
205 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
207 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
209 *t
= &sdata
->sec
.table
;
212 void mac802154_unlock_table(struct net_device
*dev
)
214 struct ieee802154_sub_if_data
*sdata
= IEEE802154_DEV_TO_SUB_IF(dev
);
216 BUG_ON(dev
->type
!= ARPHRD_IEEE802154
);
218 mutex_unlock(&sdata
->sec_mtx
);