0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/if_arp.h>
0013
0014 #include <net/mac802154.h>
0015 #include <net/ieee802154_netdev.h>
0016 #include <net/cfg802154.h>
0017
0018 #include "ieee802154_i.h"
0019 #include "driver-ops.h"
0020
0021 void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan)
0022 {
0023 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0024 struct ieee802154_local *local = sdata->local;
0025 int res;
0026
0027 ASSERT_RTNL();
0028
0029 BUG_ON(dev->type != ARPHRD_IEEE802154);
0030
0031 res = drv_set_channel(local, page, chan);
0032 if (res) {
0033 pr_debug("set_channel failed\n");
0034 } else {
0035 local->phy->current_channel = chan;
0036 local->phy->current_page = page;
0037 }
0038 }
0039
0040 int mac802154_get_params(struct net_device *dev,
0041 struct ieee802154_llsec_params *params)
0042 {
0043 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0044 int res;
0045
0046 BUG_ON(dev->type != ARPHRD_IEEE802154);
0047
0048 mutex_lock(&sdata->sec_mtx);
0049 res = mac802154_llsec_get_params(&sdata->sec, params);
0050 mutex_unlock(&sdata->sec_mtx);
0051
0052 return res;
0053 }
0054
0055 int mac802154_set_params(struct net_device *dev,
0056 const struct ieee802154_llsec_params *params,
0057 int changed)
0058 {
0059 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0060 int res;
0061
0062 BUG_ON(dev->type != ARPHRD_IEEE802154);
0063
0064 mutex_lock(&sdata->sec_mtx);
0065 res = mac802154_llsec_set_params(&sdata->sec, params, changed);
0066 mutex_unlock(&sdata->sec_mtx);
0067
0068 return res;
0069 }
0070
0071 int mac802154_add_key(struct net_device *dev,
0072 const struct ieee802154_llsec_key_id *id,
0073 const struct ieee802154_llsec_key *key)
0074 {
0075 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0076 int res;
0077
0078 BUG_ON(dev->type != ARPHRD_IEEE802154);
0079
0080 mutex_lock(&sdata->sec_mtx);
0081 res = mac802154_llsec_key_add(&sdata->sec, id, key);
0082 mutex_unlock(&sdata->sec_mtx);
0083
0084 return res;
0085 }
0086
0087 int mac802154_del_key(struct net_device *dev,
0088 const struct ieee802154_llsec_key_id *id)
0089 {
0090 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0091 int res;
0092
0093 BUG_ON(dev->type != ARPHRD_IEEE802154);
0094
0095 mutex_lock(&sdata->sec_mtx);
0096 res = mac802154_llsec_key_del(&sdata->sec, id);
0097 mutex_unlock(&sdata->sec_mtx);
0098
0099 return res;
0100 }
0101
0102 int mac802154_add_dev(struct net_device *dev,
0103 const struct ieee802154_llsec_device *llsec_dev)
0104 {
0105 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0106 int res;
0107
0108 BUG_ON(dev->type != ARPHRD_IEEE802154);
0109
0110 mutex_lock(&sdata->sec_mtx);
0111 res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev);
0112 mutex_unlock(&sdata->sec_mtx);
0113
0114 return res;
0115 }
0116
0117 int mac802154_del_dev(struct net_device *dev, __le64 dev_addr)
0118 {
0119 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0120 int res;
0121
0122 BUG_ON(dev->type != ARPHRD_IEEE802154);
0123
0124 mutex_lock(&sdata->sec_mtx);
0125 res = mac802154_llsec_dev_del(&sdata->sec, dev_addr);
0126 mutex_unlock(&sdata->sec_mtx);
0127
0128 return res;
0129 }
0130
0131 int mac802154_add_devkey(struct net_device *dev,
0132 __le64 device_addr,
0133 const struct ieee802154_llsec_device_key *key)
0134 {
0135 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0136 int res;
0137
0138 BUG_ON(dev->type != ARPHRD_IEEE802154);
0139
0140 mutex_lock(&sdata->sec_mtx);
0141 res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key);
0142 mutex_unlock(&sdata->sec_mtx);
0143
0144 return res;
0145 }
0146
0147 int mac802154_del_devkey(struct net_device *dev,
0148 __le64 device_addr,
0149 const struct ieee802154_llsec_device_key *key)
0150 {
0151 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0152 int res;
0153
0154 BUG_ON(dev->type != ARPHRD_IEEE802154);
0155
0156 mutex_lock(&sdata->sec_mtx);
0157 res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key);
0158 mutex_unlock(&sdata->sec_mtx);
0159
0160 return res;
0161 }
0162
0163 int mac802154_add_seclevel(struct net_device *dev,
0164 const struct ieee802154_llsec_seclevel *sl)
0165 {
0166 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0167 int res;
0168
0169 BUG_ON(dev->type != ARPHRD_IEEE802154);
0170
0171 mutex_lock(&sdata->sec_mtx);
0172 res = mac802154_llsec_seclevel_add(&sdata->sec, sl);
0173 mutex_unlock(&sdata->sec_mtx);
0174
0175 return res;
0176 }
0177
0178 int mac802154_del_seclevel(struct net_device *dev,
0179 const struct ieee802154_llsec_seclevel *sl)
0180 {
0181 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0182 int res;
0183
0184 BUG_ON(dev->type != ARPHRD_IEEE802154);
0185
0186 mutex_lock(&sdata->sec_mtx);
0187 res = mac802154_llsec_seclevel_del(&sdata->sec, sl);
0188 mutex_unlock(&sdata->sec_mtx);
0189
0190 return res;
0191 }
0192
0193 void mac802154_lock_table(struct net_device *dev)
0194 {
0195 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0196
0197 BUG_ON(dev->type != ARPHRD_IEEE802154);
0198
0199 mutex_lock(&sdata->sec_mtx);
0200 }
0201
0202 void mac802154_get_table(struct net_device *dev,
0203 struct ieee802154_llsec_table **t)
0204 {
0205 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0206
0207 BUG_ON(dev->type != ARPHRD_IEEE802154);
0208
0209 *t = &sdata->sec.table;
0210 }
0211
0212 void mac802154_unlock_table(struct net_device *dev)
0213 {
0214 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
0215
0216 BUG_ON(dev->type != ARPHRD_IEEE802154);
0217
0218 mutex_unlock(&sdata->sec_mtx);
0219 }