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