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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 41 | struct ieee802154_sub_if_data *sdata = netdev_priv(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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 45 | return sdata->hw; |
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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 65 | struct ieee802154_sub_if_data *sdata = netdev_priv(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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 75 | queue_work(sdata->hw->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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 80 | struct ieee802154_sub_if_data *sdata = netdev_priv(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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 88 | if ((sdata->hw->ops->set_hw_addr_filt) && |
| 89 | (sdata->hw->hw.hw_filt.short_addr != sdata->short_addr)) { |
| 90 | sdata->hw->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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 97 | struct ieee802154_sub_if_data *sdata = netdev_priv(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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 111 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
| 112 | struct ieee802154_local *local = sdata->hw; |
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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 125 | struct ieee802154_sub_if_data *sdata = netdev_priv(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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 139 | struct ieee802154_sub_if_data *sdata = netdev_priv(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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 147 | if ((sdata->hw->ops->set_hw_addr_filt) && |
| 148 | (sdata->hw->hw.hw_filt.pan_id != sdata->pan_id)) { |
| 149 | sdata->hw->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 | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 156 | struct ieee802154_sub_if_data *sdata = netdev_priv(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 | a5e1ec5 | 2014-10-25 17:16:35 +0200 | [diff] [blame] | 167 | struct ieee802154_local *local = mac802154_slave_get_priv(nw->dev); |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 168 | struct ieee802154_sub_if_data *sdata = netdev_priv(nw->dev); |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 169 | int res; |
| 170 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 171 | mutex_lock(&sdata->hw->phy->pib_lock); |
| 172 | res = local->ops->set_channel(&local->hw, sdata->page, sdata->chan); |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 173 | if (res) { |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 174 | pr_debug("set_channel failed\n"); |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 175 | } else { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 176 | sdata->hw->phy->current_channel = sdata->chan; |
| 177 | sdata->hw->phy->current_page = sdata->page; |
Alan Ott | 9f7f78b | 2013-04-05 13:03:10 +0000 | [diff] [blame] | 178 | } |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 179 | mutex_unlock(&sdata->hw->phy->pib_lock); |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 180 | |
| 181 | kfree(nw); |
| 182 | } |
| 183 | |
| 184 | void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan) |
| 185 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 186 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 187 | struct phy_chan_notify_work *work; |
| 188 | |
| 189 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 190 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 191 | spin_lock_bh(&sdata->mib_lock); |
| 192 | sdata->page = page; |
| 193 | sdata->chan = chan; |
| 194 | spin_unlock_bh(&sdata->mib_lock); |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 195 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 196 | mutex_lock(&sdata->hw->phy->pib_lock); |
| 197 | if (sdata->hw->phy->current_channel != sdata->chan || |
| 198 | sdata->hw->phy->current_page != sdata->page) { |
| 199 | mutex_unlock(&sdata->hw->phy->pib_lock); |
Alan Ott | 9f7f78b | 2013-04-05 13:03:10 +0000 | [diff] [blame] | 200 | |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 201 | work = kzalloc(sizeof(*work), GFP_ATOMIC); |
| 202 | if (!work) |
| 203 | return; |
| 204 | |
| 205 | INIT_WORK(&work->work, phy_chan_notify); |
| 206 | work->dev = dev; |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 207 | queue_work(sdata->hw->dev_workqueue, &work->work); |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 208 | } else { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 209 | mutex_unlock(&sdata->hw->phy->pib_lock); |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 210 | } |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 211 | } |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 212 | |
| 213 | |
| 214 | int mac802154_get_params(struct net_device *dev, |
| 215 | struct ieee802154_llsec_params *params) |
| 216 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 217 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 218 | int res; |
| 219 | |
| 220 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 221 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 222 | mutex_lock(&sdata->sec_mtx); |
| 223 | res = mac802154_llsec_get_params(&sdata->sec, params); |
| 224 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 225 | |
| 226 | return res; |
| 227 | } |
| 228 | |
| 229 | int mac802154_set_params(struct net_device *dev, |
| 230 | const struct ieee802154_llsec_params *params, |
| 231 | int changed) |
| 232 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 233 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 234 | int res; |
| 235 | |
| 236 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 237 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 238 | mutex_lock(&sdata->sec_mtx); |
| 239 | res = mac802154_llsec_set_params(&sdata->sec, params, changed); |
| 240 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 241 | |
| 242 | return res; |
| 243 | } |
| 244 | |
| 245 | |
| 246 | int mac802154_add_key(struct net_device *dev, |
| 247 | const struct ieee802154_llsec_key_id *id, |
| 248 | const struct ieee802154_llsec_key *key) |
| 249 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 250 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 251 | int res; |
| 252 | |
| 253 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 254 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 255 | mutex_lock(&sdata->sec_mtx); |
| 256 | res = mac802154_llsec_key_add(&sdata->sec, id, key); |
| 257 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 258 | |
| 259 | return res; |
| 260 | } |
| 261 | |
| 262 | int mac802154_del_key(struct net_device *dev, |
| 263 | const struct ieee802154_llsec_key_id *id) |
| 264 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 265 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 266 | int res; |
| 267 | |
| 268 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 269 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 270 | mutex_lock(&sdata->sec_mtx); |
| 271 | res = mac802154_llsec_key_del(&sdata->sec, id); |
| 272 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 273 | |
| 274 | return res; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | int mac802154_add_dev(struct net_device *dev, |
| 279 | const struct ieee802154_llsec_device *llsec_dev) |
| 280 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 281 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 282 | int res; |
| 283 | |
| 284 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 285 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 286 | mutex_lock(&sdata->sec_mtx); |
| 287 | res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev); |
| 288 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 289 | |
| 290 | return res; |
| 291 | } |
| 292 | |
| 293 | int mac802154_del_dev(struct net_device *dev, __le64 dev_addr) |
| 294 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 295 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 296 | int res; |
| 297 | |
| 298 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 299 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 300 | mutex_lock(&sdata->sec_mtx); |
| 301 | res = mac802154_llsec_dev_del(&sdata->sec, dev_addr); |
| 302 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 303 | |
| 304 | return res; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | int mac802154_add_devkey(struct net_device *dev, |
| 309 | __le64 device_addr, |
| 310 | const struct ieee802154_llsec_device_key *key) |
| 311 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 312 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 313 | int res; |
| 314 | |
| 315 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 316 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 317 | mutex_lock(&sdata->sec_mtx); |
| 318 | res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key); |
| 319 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 320 | |
| 321 | return res; |
| 322 | } |
| 323 | |
| 324 | int mac802154_del_devkey(struct net_device *dev, |
| 325 | __le64 device_addr, |
| 326 | const struct ieee802154_llsec_device_key *key) |
| 327 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 328 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 329 | int res; |
| 330 | |
| 331 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 332 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 333 | mutex_lock(&sdata->sec_mtx); |
| 334 | res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key); |
| 335 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 336 | |
| 337 | return res; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | int mac802154_add_seclevel(struct net_device *dev, |
| 342 | const struct ieee802154_llsec_seclevel *sl) |
| 343 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 344 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 345 | int res; |
| 346 | |
| 347 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 348 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 349 | mutex_lock(&sdata->sec_mtx); |
| 350 | res = mac802154_llsec_seclevel_add(&sdata->sec, sl); |
| 351 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 352 | |
| 353 | return res; |
| 354 | } |
| 355 | |
| 356 | int mac802154_del_seclevel(struct net_device *dev, |
| 357 | const struct ieee802154_llsec_seclevel *sl) |
| 358 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 359 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 360 | int res; |
| 361 | |
| 362 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 363 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 364 | mutex_lock(&sdata->sec_mtx); |
| 365 | res = mac802154_llsec_seclevel_del(&sdata->sec, sl); |
| 366 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 367 | |
| 368 | return res; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | void mac802154_lock_table(struct net_device *dev) |
| 373 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 374 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 375 | |
| 376 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 377 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 378 | mutex_lock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void mac802154_get_table(struct net_device *dev, |
| 382 | struct ieee802154_llsec_table **t) |
| 383 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 384 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 385 | |
| 386 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 387 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 388 | *t = &sdata->sec.table; |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void mac802154_unlock_table(struct net_device *dev) |
| 392 | { |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 393 | struct ieee802154_sub_if_data *sdata = netdev_priv(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 394 | |
| 395 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 396 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame^] | 397 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 398 | } |