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