alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 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 | * |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 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> |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 23 | #include <net/ieee802154_netdev.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 24 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 25 | |
Alexander Aring | 0f1556b | 2014-10-25 09:41:00 +0200 | [diff] [blame] | 26 | #include "ieee802154_i.h" |
Alexander Aring | 59cb300 | 2014-10-28 18:21:21 +0100 | [diff] [blame] | 27 | #include "driver-ops.h" |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 28 | |
| 29 | struct hw_addr_filt_notify_work { |
| 30 | struct work_struct work; |
| 31 | struct net_device *dev; |
| 32 | unsigned long changed; |
| 33 | }; |
| 34 | |
Alexander Aring | a5e1ec5 | 2014-10-25 17:16:35 +0200 | [diff] [blame] | 35 | static struct ieee802154_local *mac802154_slave_get_priv(struct net_device *dev) |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 36 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 37 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 38 | |
| 39 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 40 | |
Alexander Aring | 04e850f | 2014-10-25 17:16:37 +0200 | [diff] [blame] | 41 | return sdata->local; |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void hw_addr_notify(struct work_struct *work) |
| 45 | { |
| 46 | struct hw_addr_filt_notify_work *nw = container_of(work, |
| 47 | struct hw_addr_filt_notify_work, work); |
Alexander Aring | a5e1ec5 | 2014-10-25 17:16:35 +0200 | [diff] [blame] | 48 | struct ieee802154_local *local = mac802154_slave_get_priv(nw->dev); |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 49 | int res; |
| 50 | |
Alexander Aring | a5e1ec5 | 2014-10-25 17:16:35 +0200 | [diff] [blame] | 51 | res = local->ops->set_hw_addr_filt(&local->hw, &local->hw.hw_filt, |
| 52 | nw->changed); |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 53 | if (res) |
| 54 | pr_debug("failed changed mask %lx\n", nw->changed); |
| 55 | |
| 56 | kfree(nw); |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static void set_hw_addr_filt(struct net_device *dev, unsigned long changed) |
| 60 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 61 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 62 | struct hw_addr_filt_notify_work *work; |
| 63 | |
| 64 | work = kzalloc(sizeof(*work), GFP_ATOMIC); |
| 65 | if (!work) |
| 66 | return; |
| 67 | |
| 68 | INIT_WORK(&work->work, hw_addr_notify); |
| 69 | work->dev = dev; |
| 70 | work->changed = changed; |
Alexander Aring | f773054 | 2014-10-25 17:16:41 +0200 | [diff] [blame] | 71 | queue_work(sdata->local->workqueue, &work->work); |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 74 | void mac802154_dev_set_short_addr(struct net_device *dev, __le16 val) |
alex.bluesman.smirnov@gmail.com | 48e44d5 | 2012-06-25 23:24:50 +0000 | [diff] [blame] | 75 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 76 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
alex.bluesman.smirnov@gmail.com | 48e44d5 | 2012-06-25 23:24:50 +0000 | [diff] [blame] | 77 | |
| 78 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 79 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 80 | spin_lock_bh(&sdata->mib_lock); |
| 81 | sdata->short_addr = val; |
| 82 | spin_unlock_bh(&sdata->mib_lock); |
alex.bluesman.smirnov@gmail.com | 48e44d5 | 2012-06-25 23:24:50 +0000 | [diff] [blame] | 83 | |
Alexander Aring | 04e850f | 2014-10-25 17:16:37 +0200 | [diff] [blame] | 84 | if ((sdata->local->ops->set_hw_addr_filt) && |
| 85 | (sdata->local->hw.hw_filt.short_addr != sdata->short_addr)) { |
| 86 | sdata->local->hw.hw_filt.short_addr = sdata->short_addr; |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 87 | set_hw_addr_filt(dev, IEEE802154_AFILT_SADDR_CHANGED); |
alex.bluesman.smirnov@gmail.com | 48e44d5 | 2012-06-25 23:24:50 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 91 | __le16 mac802154_dev_get_short_addr(const struct net_device *dev) |
alex.bluesman.smirnov@gmail.com | e885a47 | 2012-07-10 21:22:44 +0000 | [diff] [blame] | 92 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 93 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 94 | __le16 ret; |
alex.bluesman.smirnov@gmail.com | e885a47 | 2012-07-10 21:22:44 +0000 | [diff] [blame] | 95 | |
| 96 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 97 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 98 | spin_lock_bh(&sdata->mib_lock); |
| 99 | ret = sdata->short_addr; |
| 100 | spin_unlock_bh(&sdata->mib_lock); |
alex.bluesman.smirnov@gmail.com | e885a47 | 2012-07-10 21:22:44 +0000 | [diff] [blame] | 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 105 | void mac802154_dev_set_ieee_addr(struct net_device *dev) |
| 106 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 107 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 04e850f | 2014-10-25 17:16:37 +0200 | [diff] [blame] | 108 | struct ieee802154_local *local = sdata->local; |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 109 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 110 | sdata->extended_addr = ieee802154_devaddr_from_raw(dev->dev_addr); |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 111 | |
Alexander Aring | a5e1ec5 | 2014-10-25 17:16:35 +0200 | [diff] [blame] | 112 | if (local->ops->set_hw_addr_filt && |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 113 | local->hw.hw_filt.ieee_addr != sdata->extended_addr) { |
| 114 | local->hw.hw_filt.ieee_addr = sdata->extended_addr; |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 115 | set_hw_addr_filt(dev, IEEE802154_AFILT_IEEEADDR_CHANGED); |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 116 | } |
| 117 | } |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 118 | |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 119 | __le16 mac802154_dev_get_pan_id(const struct net_device *dev) |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 120 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 121 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 122 | __le16 ret; |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 123 | |
| 124 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 125 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 126 | spin_lock_bh(&sdata->mib_lock); |
| 127 | ret = sdata->pan_id; |
| 128 | spin_unlock_bh(&sdata->mib_lock); |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 129 | |
| 130 | return ret; |
| 131 | } |
| 132 | |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 133 | void mac802154_dev_set_pan_id(struct net_device *dev, __le16 val) |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 134 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 135 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 136 | |
| 137 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 138 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 139 | spin_lock_bh(&sdata->mib_lock); |
| 140 | sdata->pan_id = val; |
| 141 | spin_unlock_bh(&sdata->mib_lock); |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 142 | |
Alexander Aring | 04e850f | 2014-10-25 17:16:37 +0200 | [diff] [blame] | 143 | if ((sdata->local->ops->set_hw_addr_filt) && |
| 144 | (sdata->local->hw.hw_filt.pan_id != sdata->pan_id)) { |
| 145 | sdata->local->hw.hw_filt.pan_id = sdata->pan_id; |
Alexander Aring | 57205c1 | 2014-10-25 05:25:09 +0200 | [diff] [blame] | 146 | set_hw_addr_filt(dev, IEEE802154_AFILT_PANID_CHANGED); |
alex.bluesman.smirnov@gmail.com | dcbe4f9 | 2012-06-25 23:24:49 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 149 | |
Tony Cheneau | 0483546 | 2013-03-25 17:59:29 +0000 | [diff] [blame] | 150 | u8 mac802154_dev_get_dsn(const struct net_device *dev) |
| 151 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 152 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Tony Cheneau | 0483546 | 2013-03-25 17:59:29 +0000 | [diff] [blame] | 153 | |
| 154 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 155 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 156 | return sdata->dsn++; |
Tony Cheneau | 0483546 | 2013-03-25 17:59:29 +0000 | [diff] [blame] | 157 | } |
| 158 | |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 159 | void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan) |
| 160 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 161 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 12439a5 | 2014-10-28 18:21:29 +0100 | [diff] [blame^] | 162 | struct ieee802154_local *local = sdata->local; |
| 163 | int res; |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 164 | |
| 165 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 166 | |
Alexander Aring | 12439a5 | 2014-10-28 18:21:29 +0100 | [diff] [blame^] | 167 | res = drv_set_channel(local, page, chan); |
| 168 | if (res) { |
| 169 | pr_debug("set_channel failed\n"); |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 170 | } else { |
Alexander Aring | 12439a5 | 2014-10-28 18:21:29 +0100 | [diff] [blame^] | 171 | mutex_lock(&local->phy->pib_lock); |
| 172 | local->phy->current_channel = chan; |
| 173 | local->phy->current_page = page; |
| 174 | mutex_unlock(&local->phy->pib_lock); |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 175 | } |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 176 | } |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 177 | |
| 178 | |
| 179 | int mac802154_get_params(struct net_device *dev, |
| 180 | struct ieee802154_llsec_params *params) |
| 181 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 182 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 183 | int res; |
| 184 | |
| 185 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 186 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 187 | mutex_lock(&sdata->sec_mtx); |
| 188 | res = mac802154_llsec_get_params(&sdata->sec, params); |
| 189 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 190 | |
| 191 | return res; |
| 192 | } |
| 193 | |
| 194 | int mac802154_set_params(struct net_device *dev, |
| 195 | const struct ieee802154_llsec_params *params, |
| 196 | int changed) |
| 197 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 198 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 199 | int res; |
| 200 | |
| 201 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 202 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 203 | mutex_lock(&sdata->sec_mtx); |
| 204 | res = mac802154_llsec_set_params(&sdata->sec, params, changed); |
| 205 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 206 | |
| 207 | return res; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | int mac802154_add_key(struct net_device *dev, |
| 212 | const struct ieee802154_llsec_key_id *id, |
| 213 | const struct ieee802154_llsec_key *key) |
| 214 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 215 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 216 | int res; |
| 217 | |
| 218 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 219 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 220 | mutex_lock(&sdata->sec_mtx); |
| 221 | res = mac802154_llsec_key_add(&sdata->sec, id, key); |
| 222 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 223 | |
| 224 | return res; |
| 225 | } |
| 226 | |
| 227 | int mac802154_del_key(struct net_device *dev, |
| 228 | const struct ieee802154_llsec_key_id *id) |
| 229 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 230 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 231 | int res; |
| 232 | |
| 233 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 234 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 235 | mutex_lock(&sdata->sec_mtx); |
| 236 | res = mac802154_llsec_key_del(&sdata->sec, id); |
| 237 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 238 | |
| 239 | return res; |
| 240 | } |
| 241 | |
| 242 | |
| 243 | int mac802154_add_dev(struct net_device *dev, |
| 244 | const struct ieee802154_llsec_device *llsec_dev) |
| 245 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 246 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 247 | int res; |
| 248 | |
| 249 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 250 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 251 | mutex_lock(&sdata->sec_mtx); |
| 252 | res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev); |
| 253 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 254 | |
| 255 | return res; |
| 256 | } |
| 257 | |
| 258 | int mac802154_del_dev(struct net_device *dev, __le64 dev_addr) |
| 259 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 260 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 261 | int res; |
| 262 | |
| 263 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 264 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 265 | mutex_lock(&sdata->sec_mtx); |
| 266 | res = mac802154_llsec_dev_del(&sdata->sec, dev_addr); |
| 267 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 268 | |
| 269 | return res; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | int mac802154_add_devkey(struct net_device *dev, |
| 274 | __le64 device_addr, |
| 275 | const struct ieee802154_llsec_device_key *key) |
| 276 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 277 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 278 | int res; |
| 279 | |
| 280 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 281 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 282 | mutex_lock(&sdata->sec_mtx); |
| 283 | res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key); |
| 284 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 285 | |
| 286 | return res; |
| 287 | } |
| 288 | |
| 289 | int mac802154_del_devkey(struct net_device *dev, |
| 290 | __le64 device_addr, |
| 291 | const struct ieee802154_llsec_device_key *key) |
| 292 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 293 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 294 | int res; |
| 295 | |
| 296 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 297 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 298 | mutex_lock(&sdata->sec_mtx); |
| 299 | res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key); |
| 300 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 301 | |
| 302 | return res; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | int mac802154_add_seclevel(struct net_device *dev, |
| 307 | const struct ieee802154_llsec_seclevel *sl) |
| 308 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 309 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 310 | int res; |
| 311 | |
| 312 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 313 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 314 | mutex_lock(&sdata->sec_mtx); |
| 315 | res = mac802154_llsec_seclevel_add(&sdata->sec, sl); |
| 316 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 317 | |
| 318 | return res; |
| 319 | } |
| 320 | |
| 321 | int mac802154_del_seclevel(struct net_device *dev, |
| 322 | const struct ieee802154_llsec_seclevel *sl) |
| 323 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 324 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 325 | int res; |
| 326 | |
| 327 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 328 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 329 | mutex_lock(&sdata->sec_mtx); |
| 330 | res = mac802154_llsec_seclevel_del(&sdata->sec, sl); |
| 331 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 332 | |
| 333 | return res; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | void mac802154_lock_table(struct net_device *dev) |
| 338 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 339 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 340 | |
| 341 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 342 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 343 | mutex_lock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void mac802154_get_table(struct net_device *dev, |
| 347 | struct ieee802154_llsec_table **t) |
| 348 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 349 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 350 | |
| 351 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 352 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 353 | *t = &sdata->sec.table; |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void mac802154_unlock_table(struct net_device *dev) |
| 357 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 358 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 359 | |
| 360 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 361 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 362 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 363 | } |