Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2007-2012 Siemens AG |
| 4 | * |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 5 | * Written by: |
| 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> |
| 10 | */ |
| 11 | |
| 12 | #include <linux/if_arp.h> |
| 13 | |
| 14 | #include <net/mac802154.h> |
Phoebe Buckheister | b70ab2e | 2014-03-14 21:23:59 +0100 | [diff] [blame] | 15 | #include <net/ieee802154_netdev.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 16 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 17 | |
Alexander Aring | 0f1556b | 2014-10-25 09:41:00 +0200 | [diff] [blame] | 18 | #include "ieee802154_i.h" |
Alexander Aring | 59cb300 | 2014-10-28 18:21:21 +0100 | [diff] [blame] | 19 | #include "driver-ops.h" |
alex.bluesman.smirnov@gmail.com | ef2486f | 2012-05-15 20:50:26 +0000 | [diff] [blame] | 20 | |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 21 | void mac802154_dev_set_page_channel(struct net_device *dev, u8 page, u8 chan) |
| 22 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 23 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 12439a5 | 2014-10-28 18:21:29 +0100 | [diff] [blame] | 24 | struct ieee802154_local *local = sdata->local; |
| 25 | int res; |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 26 | |
Alexander Aring | 4a3a8c0 | 2015-05-22 17:43:52 +0200 | [diff] [blame] | 27 | ASSERT_RTNL(); |
| 28 | |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 29 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 30 | |
Alexander Aring | 12439a5 | 2014-10-28 18:21:29 +0100 | [diff] [blame] | 31 | res = drv_set_channel(local, page, chan); |
| 32 | if (res) { |
| 33 | pr_debug("set_channel failed\n"); |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 34 | } else { |
Alexander Aring | 12439a5 | 2014-10-28 18:21:29 +0100 | [diff] [blame] | 35 | local->phy->current_channel = chan; |
| 36 | local->phy->current_page = page; |
Varka Bhadram | 4710d80 | 2014-07-02 09:01:09 +0530 | [diff] [blame] | 37 | } |
alex.bluesman.smirnov@gmail.com | 66b69d4 | 2012-06-25 23:24:51 +0000 | [diff] [blame] | 38 | } |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 39 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 40 | int mac802154_get_params(struct net_device *dev, |
| 41 | struct ieee802154_llsec_params *params) |
| 42 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 43 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 44 | int res; |
| 45 | |
| 46 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 47 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 48 | mutex_lock(&sdata->sec_mtx); |
| 49 | res = mac802154_llsec_get_params(&sdata->sec, params); |
| 50 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 51 | |
| 52 | return res; |
| 53 | } |
| 54 | |
| 55 | int mac802154_set_params(struct net_device *dev, |
| 56 | const struct ieee802154_llsec_params *params, |
| 57 | int changed) |
| 58 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 59 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 60 | int res; |
| 61 | |
| 62 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 63 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 64 | mutex_lock(&sdata->sec_mtx); |
| 65 | res = mac802154_llsec_set_params(&sdata->sec, params, changed); |
| 66 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 67 | |
| 68 | return res; |
| 69 | } |
| 70 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 71 | int mac802154_add_key(struct net_device *dev, |
| 72 | const struct ieee802154_llsec_key_id *id, |
| 73 | const struct ieee802154_llsec_key *key) |
| 74 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 75 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 76 | int res; |
| 77 | |
| 78 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 79 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 80 | mutex_lock(&sdata->sec_mtx); |
| 81 | res = mac802154_llsec_key_add(&sdata->sec, id, key); |
| 82 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 83 | |
| 84 | return res; |
| 85 | } |
| 86 | |
| 87 | int mac802154_del_key(struct net_device *dev, |
| 88 | const struct ieee802154_llsec_key_id *id) |
| 89 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 90 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 91 | int res; |
| 92 | |
| 93 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 94 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 95 | mutex_lock(&sdata->sec_mtx); |
| 96 | res = mac802154_llsec_key_del(&sdata->sec, id); |
| 97 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 98 | |
| 99 | return res; |
| 100 | } |
| 101 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 102 | int mac802154_add_dev(struct net_device *dev, |
| 103 | const struct ieee802154_llsec_device *llsec_dev) |
| 104 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 105 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 106 | int res; |
| 107 | |
| 108 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 109 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 110 | mutex_lock(&sdata->sec_mtx); |
| 111 | res = mac802154_llsec_dev_add(&sdata->sec, llsec_dev); |
| 112 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 113 | |
| 114 | return res; |
| 115 | } |
| 116 | |
| 117 | int mac802154_del_dev(struct net_device *dev, __le64 dev_addr) |
| 118 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 119 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 120 | int res; |
| 121 | |
| 122 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 123 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 124 | mutex_lock(&sdata->sec_mtx); |
| 125 | res = mac802154_llsec_dev_del(&sdata->sec, dev_addr); |
| 126 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 127 | |
| 128 | return res; |
| 129 | } |
| 130 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 131 | int mac802154_add_devkey(struct net_device *dev, |
| 132 | __le64 device_addr, |
| 133 | const struct ieee802154_llsec_device_key *key) |
| 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); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 136 | int res; |
| 137 | |
| 138 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 139 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 140 | mutex_lock(&sdata->sec_mtx); |
| 141 | res = mac802154_llsec_devkey_add(&sdata->sec, device_addr, key); |
| 142 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 143 | |
| 144 | return res; |
| 145 | } |
| 146 | |
| 147 | int mac802154_del_devkey(struct net_device *dev, |
| 148 | __le64 device_addr, |
| 149 | const struct ieee802154_llsec_device_key *key) |
| 150 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 151 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 152 | int res; |
| 153 | |
| 154 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 155 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 156 | mutex_lock(&sdata->sec_mtx); |
| 157 | res = mac802154_llsec_devkey_del(&sdata->sec, device_addr, key); |
| 158 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 159 | |
| 160 | return res; |
| 161 | } |
| 162 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 163 | int mac802154_add_seclevel(struct net_device *dev, |
| 164 | const struct ieee802154_llsec_seclevel *sl) |
| 165 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 166 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 167 | int res; |
| 168 | |
| 169 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 170 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 171 | mutex_lock(&sdata->sec_mtx); |
| 172 | res = mac802154_llsec_seclevel_add(&sdata->sec, sl); |
| 173 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 174 | |
| 175 | return res; |
| 176 | } |
| 177 | |
| 178 | int mac802154_del_seclevel(struct net_device *dev, |
| 179 | const struct ieee802154_llsec_seclevel *sl) |
| 180 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 181 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 182 | int res; |
| 183 | |
| 184 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 185 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 186 | mutex_lock(&sdata->sec_mtx); |
| 187 | res = mac802154_llsec_seclevel_del(&sdata->sec, sl); |
| 188 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 189 | |
| 190 | return res; |
| 191 | } |
| 192 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 193 | void mac802154_lock_table(struct net_device *dev) |
| 194 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 195 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 196 | |
| 197 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 198 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 199 | mutex_lock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void mac802154_get_table(struct net_device *dev, |
| 203 | struct ieee802154_llsec_table **t) |
| 204 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 205 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 206 | |
| 207 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 208 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 209 | *t = &sdata->sec.table; |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void mac802154_unlock_table(struct net_device *dev) |
| 213 | { |
Alexander Aring | 59d19cd | 2014-10-25 17:16:40 +0200 | [diff] [blame] | 214 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 215 | |
| 216 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 217 | |
Alexander Aring | 036562f | 2014-10-25 17:16:36 +0200 | [diff] [blame] | 218 | mutex_unlock(&sdata->sec_mtx); |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 219 | } |