Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
Alexander Aring | 1201cd2 | 2014-11-02 04:18:36 +0100 | [diff] [blame] | 3 | * |
| 4 | * Authors: |
| 5 | * Alexander Aring <aar@pengutronix.de> |
| 6 | * |
| 7 | * Based on: net/mac80211/cfg.c |
| 8 | */ |
| 9 | |
Alexander Aring | d5ae67b | 2014-11-05 20:51:17 +0100 | [diff] [blame] | 10 | #include <net/rtnetlink.h> |
Alexander Aring | 1201cd2 | 2014-11-02 04:18:36 +0100 | [diff] [blame] | 11 | #include <net/cfg802154.h> |
| 12 | |
Alexander Aring | 4a9a816 | 2014-11-02 04:18:38 +0100 | [diff] [blame] | 13 | #include "ieee802154_i.h" |
Alexander Aring | ab0bd56 | 2014-11-12 03:36:55 +0100 | [diff] [blame] | 14 | #include "driver-ops.h" |
Alexander Aring | fdd2068 | 2014-11-02 21:43:05 +0100 | [diff] [blame] | 15 | #include "cfg.h" |
Alexander Aring | 4a9a816 | 2014-11-02 04:18:38 +0100 | [diff] [blame] | 16 | |
| 17 | static struct net_device * |
| 18 | ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy, |
Varka Bhadram | 5b4a1039 | 2015-04-30 17:44:57 +0200 | [diff] [blame] | 19 | const char *name, |
| 20 | unsigned char name_assign_type, int type) |
Alexander Aring | 4a9a816 | 2014-11-02 04:18:38 +0100 | [diff] [blame] | 21 | { |
Alexander Aring | 986a8ab | 2014-11-05 20:51:15 +0100 | [diff] [blame] | 22 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
Alexander Aring | d5ae67b | 2014-11-05 20:51:17 +0100 | [diff] [blame] | 23 | struct net_device *dev; |
Alexander Aring | 986a8ab | 2014-11-05 20:51:15 +0100 | [diff] [blame] | 24 | |
Alexander Aring | d5ae67b | 2014-11-05 20:51:17 +0100 | [diff] [blame] | 25 | rtnl_lock(); |
Varka Bhadram | 5b4a1039 | 2015-04-30 17:44:57 +0200 | [diff] [blame] | 26 | dev = ieee802154_if_add(local, name, name_assign_type, type, |
Alexander Aring | 0e57547 | 2014-11-17 08:20:52 +0100 | [diff] [blame] | 27 | cpu_to_le64(0x0000000000000000ULL)); |
Alexander Aring | d5ae67b | 2014-11-05 20:51:17 +0100 | [diff] [blame] | 28 | rtnl_unlock(); |
| 29 | |
| 30 | return dev; |
Alexander Aring | 4a9a816 | 2014-11-02 04:18:38 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy, |
| 34 | struct net_device *dev) |
| 35 | { |
Alexander Aring | b210b18 | 2014-11-05 20:51:14 +0100 | [diff] [blame] | 36 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 37 | |
| 38 | ieee802154_if_remove(sdata); |
Alexander Aring | 4a9a816 | 2014-11-02 04:18:38 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Alexander Aring | 3cf24cf | 2015-06-24 11:36:36 +0200 | [diff] [blame] | 41 | #ifdef CONFIG_PM |
| 42 | static int ieee802154_suspend(struct wpan_phy *wpan_phy) |
| 43 | { |
| 44 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 45 | |
| 46 | if (!local->open_count) |
| 47 | goto suspend; |
| 48 | |
Miquel Raynal | f0feb34 | 2022-05-19 17:05:13 +0200 | [diff] [blame] | 49 | ieee802154_sync_and_hold_queue(local); |
Alexander Aring | 3cf24cf | 2015-06-24 11:36:36 +0200 | [diff] [blame] | 50 | synchronize_net(); |
| 51 | |
| 52 | /* stop hardware - this must stop RX */ |
| 53 | ieee802154_stop_device(local); |
| 54 | |
| 55 | suspend: |
| 56 | local->suspended = true; |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int ieee802154_resume(struct wpan_phy *wpan_phy) |
| 61 | { |
| 62 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 63 | int ret; |
| 64 | |
| 65 | /* nothing to do if HW shouldn't run */ |
| 66 | if (!local->open_count) |
| 67 | goto wake_up; |
| 68 | |
| 69 | /* restart hardware */ |
Alexander Aring | ac8037c | 2022-10-07 10:53:05 +0200 | [diff] [blame] | 70 | ret = drv_start(local, local->phy->filtering, &local->addr_filt); |
Alexander Aring | 3cf24cf | 2015-06-24 11:36:36 +0200 | [diff] [blame] | 71 | if (ret) |
| 72 | return ret; |
| 73 | |
| 74 | wake_up: |
Miquel Raynal | 20a19d1 | 2022-05-19 17:05:10 +0200 | [diff] [blame] | 75 | ieee802154_release_queue(local); |
Alexander Aring | 3cf24cf | 2015-06-24 11:36:36 +0200 | [diff] [blame] | 76 | local->suspended = false; |
| 77 | return 0; |
| 78 | } |
| 79 | #else |
| 80 | #define ieee802154_suspend NULL |
| 81 | #define ieee802154_resume NULL |
| 82 | #endif |
| 83 | |
Alexander Aring | ab0bd56 | 2014-11-12 03:36:55 +0100 | [diff] [blame] | 84 | static int |
Alexander Aring | f3ea5e4 | 2014-11-17 08:20:51 +0100 | [diff] [blame] | 85 | ieee802154_add_iface(struct wpan_phy *phy, const char *name, |
Varka Bhadram | 5b4a1039 | 2015-04-30 17:44:57 +0200 | [diff] [blame] | 86 | unsigned char name_assign_type, |
Alexander Aring | 0e57547 | 2014-11-17 08:20:52 +0100 | [diff] [blame] | 87 | enum nl802154_iftype type, __le64 extended_addr) |
Alexander Aring | f3ea5e4 | 2014-11-17 08:20:51 +0100 | [diff] [blame] | 88 | { |
| 89 | struct ieee802154_local *local = wpan_phy_priv(phy); |
| 90 | struct net_device *err; |
| 91 | |
Varka Bhadram | 5b4a1039 | 2015-04-30 17:44:57 +0200 | [diff] [blame] | 92 | err = ieee802154_if_add(local, name, name_assign_type, type, |
| 93 | extended_addr); |
Alexander Aring | 36cf942 | 2015-01-02 15:49:41 +0100 | [diff] [blame] | 94 | return PTR_ERR_OR_ZERO(err); |
Alexander Aring | f3ea5e4 | 2014-11-17 08:20:51 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static int |
Alexander Aring | b821ecd | 2014-11-17 08:20:53 +0100 | [diff] [blame] | 98 | ieee802154_del_iface(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev) |
| 99 | { |
| 100 | ieee802154_if_remove(IEEE802154_WPAN_DEV_TO_SUB_IF(wpan_dev)); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int |
Alexander Aring | 6d5fb87 | 2014-11-17 08:20:46 +0100 | [diff] [blame] | 106 | ieee802154_set_channel(struct wpan_phy *wpan_phy, u8 page, u8 channel) |
Alexander Aring | ab0bd56 | 2014-11-12 03:36:55 +0100 | [diff] [blame] | 107 | { |
| 108 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 109 | int ret; |
| 110 | |
| 111 | ASSERT_RTNL(); |
| 112 | |
Alexander Aring | 791021b | 2015-05-17 21:44:44 +0200 | [diff] [blame] | 113 | if (wpan_phy->current_page == page && |
| 114 | wpan_phy->current_channel == channel) |
| 115 | return 0; |
| 116 | |
Miquel Raynal | 3accf47 | 2023-01-25 11:29:23 +0100 | [diff] [blame] | 117 | /* Refuse to change channels during scanning or beaconing */ |
| 118 | if (mac802154_is_scanning(local) || mac802154_is_beaconing(local)) |
Miquel Raynal | 57588c7 | 2023-01-03 17:56:44 +0100 | [diff] [blame] | 119 | return -EBUSY; |
| 120 | |
Alexander Aring | ab0bd56 | 2014-11-12 03:36:55 +0100 | [diff] [blame] | 121 | ret = drv_set_channel(local, page, channel); |
| 122 | if (!ret) { |
| 123 | wpan_phy->current_page = page; |
| 124 | wpan_phy->current_channel = channel; |
Miquel Raynal | 5755cd4 | 2023-01-03 17:56:42 +0100 | [diff] [blame] | 125 | ieee802154_configure_durations(wpan_phy, page, channel); |
Alexander Aring | ab0bd56 | 2014-11-12 03:36:55 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return ret; |
| 129 | } |
| 130 | |
Alexander Aring | 6d5fb87 | 2014-11-17 08:20:46 +0100 | [diff] [blame] | 131 | static int |
Alexander Aring | ba2a950 | 2014-12-10 15:33:13 +0100 | [diff] [blame] | 132 | ieee802154_set_cca_mode(struct wpan_phy *wpan_phy, |
| 133 | const struct wpan_phy_cca *cca) |
| 134 | { |
| 135 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 136 | int ret; |
| 137 | |
| 138 | ASSERT_RTNL(); |
| 139 | |
Alexander Aring | 791021b | 2015-05-17 21:44:44 +0200 | [diff] [blame] | 140 | if (wpan_phy_cca_cmp(&wpan_phy->cca, cca)) |
| 141 | return 0; |
| 142 | |
Alexander Aring | ba2a950 | 2014-12-10 15:33:13 +0100 | [diff] [blame] | 143 | ret = drv_set_cca_mode(local, cca); |
| 144 | if (!ret) |
| 145 | wpan_phy->cca = *cca; |
| 146 | |
| 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | static int |
Alexander Aring | b69644c | 2015-05-27 13:42:10 +0200 | [diff] [blame] | 151 | ieee802154_set_cca_ed_level(struct wpan_phy *wpan_phy, s32 ed_level) |
| 152 | { |
| 153 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 154 | int ret; |
| 155 | |
| 156 | ASSERT_RTNL(); |
| 157 | |
| 158 | if (wpan_phy->cca_ed_level == ed_level) |
| 159 | return 0; |
| 160 | |
| 161 | ret = drv_set_cca_ed_level(local, ed_level); |
| 162 | if (!ret) |
| 163 | wpan_phy->cca_ed_level = ed_level; |
| 164 | |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | static int |
Varka Bhadram | 0f999b0 | 2015-05-27 09:10:54 +0530 | [diff] [blame] | 169 | ieee802154_set_tx_power(struct wpan_phy *wpan_phy, s32 power) |
| 170 | { |
| 171 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 172 | int ret; |
| 173 | |
| 174 | ASSERT_RTNL(); |
| 175 | |
| 176 | if (wpan_phy->transmit_power == power) |
| 177 | return 0; |
| 178 | |
| 179 | ret = drv_set_tx_power(local, power); |
| 180 | if (!ret) |
| 181 | wpan_phy->transmit_power = power; |
| 182 | |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | static int |
Alexander Aring | 6d5fb87 | 2014-11-17 08:20:46 +0100 | [diff] [blame] | 187 | ieee802154_set_pan_id(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
Alexander Aring | ee7b905 | 2014-11-17 08:20:55 +0100 | [diff] [blame] | 188 | __le16 pan_id) |
Alexander Aring | 702bf37 | 2014-11-12 03:36:57 +0100 | [diff] [blame] | 189 | { |
Alexander Aring | d77b485 | 2015-06-21 16:45:20 +0200 | [diff] [blame] | 190 | int ret; |
| 191 | |
Alexander Aring | 702bf37 | 2014-11-12 03:36:57 +0100 | [diff] [blame] | 192 | ASSERT_RTNL(); |
| 193 | |
Alexander Aring | 791021b | 2015-05-17 21:44:44 +0200 | [diff] [blame] | 194 | if (wpan_dev->pan_id == pan_id) |
| 195 | return 0; |
| 196 | |
Alexander Aring | d77b485 | 2015-06-21 16:45:20 +0200 | [diff] [blame] | 197 | ret = mac802154_wpan_update_llsec(wpan_dev->netdev); |
| 198 | if (!ret) |
| 199 | wpan_dev->pan_id = pan_id; |
| 200 | |
| 201 | return ret; |
Alexander Aring | 702bf37 | 2014-11-12 03:36:57 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Alexander Aring | 9830c62 | 2014-11-12 03:36:58 +0100 | [diff] [blame] | 204 | static int |
Alexander Aring | 656a999 | 2014-11-12 03:36:59 +0100 | [diff] [blame] | 205 | ieee802154_set_backoff_exponent(struct wpan_phy *wpan_phy, |
| 206 | struct wpan_dev *wpan_dev, |
Alexander Aring | 6d5fb87 | 2014-11-17 08:20:46 +0100 | [diff] [blame] | 207 | u8 min_be, u8 max_be) |
Alexander Aring | 656a999 | 2014-11-12 03:36:59 +0100 | [diff] [blame] | 208 | { |
Alexander Aring | 656a999 | 2014-11-12 03:36:59 +0100 | [diff] [blame] | 209 | ASSERT_RTNL(); |
| 210 | |
Alexander Aring | 656a999 | 2014-11-12 03:36:59 +0100 | [diff] [blame] | 211 | wpan_dev->min_be = min_be; |
| 212 | wpan_dev->max_be = max_be; |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | static int |
Alexander Aring | 9830c62 | 2014-11-12 03:36:58 +0100 | [diff] [blame] | 217 | ieee802154_set_short_addr(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
Alexander Aring | ee7b905 | 2014-11-17 08:20:55 +0100 | [diff] [blame] | 218 | __le16 short_addr) |
Alexander Aring | 9830c62 | 2014-11-12 03:36:58 +0100 | [diff] [blame] | 219 | { |
| 220 | ASSERT_RTNL(); |
| 221 | |
Alexander Aring | ee7b905 | 2014-11-17 08:20:55 +0100 | [diff] [blame] | 222 | wpan_dev->short_addr = short_addr; |
Alexander Aring | 9830c62 | 2014-11-12 03:36:58 +0100 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
Alexander Aring | 6d5fb87 | 2014-11-17 08:20:46 +0100 | [diff] [blame] | 226 | static int |
| 227 | ieee802154_set_max_csma_backoffs(struct wpan_phy *wpan_phy, |
| 228 | struct wpan_dev *wpan_dev, |
| 229 | u8 max_csma_backoffs) |
Alexander Aring | a01ba76 | 2014-11-12 03:37:01 +0100 | [diff] [blame] | 230 | { |
Alexander Aring | a01ba76 | 2014-11-12 03:37:01 +0100 | [diff] [blame] | 231 | ASSERT_RTNL(); |
| 232 | |
Alexander Aring | a01ba76 | 2014-11-12 03:37:01 +0100 | [diff] [blame] | 233 | wpan_dev->csma_retries = max_csma_backoffs; |
| 234 | return 0; |
| 235 | } |
| 236 | |
Alexander Aring | 6d5fb87 | 2014-11-17 08:20:46 +0100 | [diff] [blame] | 237 | static int |
| 238 | ieee802154_set_max_frame_retries(struct wpan_phy *wpan_phy, |
| 239 | struct wpan_dev *wpan_dev, |
| 240 | s8 max_frame_retries) |
Alexander Aring | 17a3a46 | 2014-11-12 03:37:03 +0100 | [diff] [blame] | 241 | { |
Alexander Aring | 17a3a46 | 2014-11-12 03:37:03 +0100 | [diff] [blame] | 242 | ASSERT_RTNL(); |
| 243 | |
Alexander Aring | 17a3a46 | 2014-11-12 03:37:03 +0100 | [diff] [blame] | 244 | wpan_dev->frame_retries = max_frame_retries; |
| 245 | return 0; |
| 246 | } |
| 247 | |
Alexander Aring | 6d5fb87 | 2014-11-17 08:20:46 +0100 | [diff] [blame] | 248 | static int |
| 249 | ieee802154_set_lbt_mode(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 250 | bool mode) |
Alexander Aring | c8937a1d | 2014-11-12 03:37:05 +0100 | [diff] [blame] | 251 | { |
Alexander Aring | c8937a1d | 2014-11-12 03:37:05 +0100 | [diff] [blame] | 252 | ASSERT_RTNL(); |
| 253 | |
Alexander Aring | c8937a1d | 2014-11-12 03:37:05 +0100 | [diff] [blame] | 254 | wpan_dev->lbt = mode; |
| 255 | return 0; |
| 256 | } |
| 257 | |
Alexander Aring | c91208d | 2015-08-10 21:15:58 +0200 | [diff] [blame] | 258 | static int |
| 259 | ieee802154_set_ackreq_default(struct wpan_phy *wpan_phy, |
| 260 | struct wpan_dev *wpan_dev, bool ackreq) |
| 261 | { |
| 262 | ASSERT_RTNL(); |
| 263 | |
| 264 | wpan_dev->ackreq = ackreq; |
| 265 | return 0; |
| 266 | } |
| 267 | |
Miquel Raynal | 57588c7 | 2023-01-03 17:56:44 +0100 | [diff] [blame] | 268 | static int mac802154_trigger_scan(struct wpan_phy *wpan_phy, |
| 269 | struct cfg802154_scan_request *request) |
| 270 | { |
| 271 | struct ieee802154_sub_if_data *sdata; |
| 272 | |
| 273 | sdata = IEEE802154_WPAN_DEV_TO_SUB_IF(request->wpan_dev); |
| 274 | |
| 275 | ASSERT_RTNL(); |
| 276 | |
| 277 | return mac802154_trigger_scan_locked(sdata, request); |
| 278 | } |
| 279 | |
| 280 | static int mac802154_abort_scan(struct wpan_phy *wpan_phy, |
| 281 | struct wpan_dev *wpan_dev) |
| 282 | { |
| 283 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 284 | struct ieee802154_sub_if_data *sdata; |
| 285 | |
| 286 | sdata = IEEE802154_WPAN_DEV_TO_SUB_IF(wpan_dev); |
| 287 | |
| 288 | ASSERT_RTNL(); |
| 289 | |
| 290 | return mac802154_abort_scan_locked(local, sdata); |
| 291 | } |
| 292 | |
Miquel Raynal | 3accf47 | 2023-01-25 11:29:23 +0100 | [diff] [blame] | 293 | static int mac802154_send_beacons(struct wpan_phy *wpan_phy, |
| 294 | struct cfg802154_beacon_request *request) |
| 295 | { |
| 296 | struct ieee802154_sub_if_data *sdata; |
| 297 | |
| 298 | sdata = IEEE802154_WPAN_DEV_TO_SUB_IF(request->wpan_dev); |
| 299 | |
| 300 | ASSERT_RTNL(); |
| 301 | |
| 302 | return mac802154_send_beacons_locked(sdata, request); |
| 303 | } |
| 304 | |
| 305 | static int mac802154_stop_beacons(struct wpan_phy *wpan_phy, |
| 306 | struct wpan_dev *wpan_dev) |
| 307 | { |
| 308 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
| 309 | struct ieee802154_sub_if_data *sdata; |
| 310 | |
| 311 | sdata = IEEE802154_WPAN_DEV_TO_SUB_IF(wpan_dev); |
| 312 | |
| 313 | ASSERT_RTNL(); |
| 314 | |
| 315 | return mac802154_stop_beacons_locked(local, sdata); |
| 316 | } |
| 317 | |
Alexander Aring | a26c5fd | 2015-09-28 09:00:25 +0200 | [diff] [blame] | 318 | #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL |
| 319 | static void |
| 320 | ieee802154_get_llsec_table(struct wpan_phy *wpan_phy, |
| 321 | struct wpan_dev *wpan_dev, |
| 322 | struct ieee802154_llsec_table **table) |
| 323 | { |
| 324 | struct net_device *dev = wpan_dev->netdev; |
| 325 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 326 | |
| 327 | *table = &sdata->sec.table; |
| 328 | } |
| 329 | |
| 330 | static void |
| 331 | ieee802154_lock_llsec_table(struct wpan_phy *wpan_phy, |
| 332 | struct wpan_dev *wpan_dev) |
| 333 | { |
| 334 | struct net_device *dev = wpan_dev->netdev; |
| 335 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 336 | |
| 337 | mutex_lock(&sdata->sec_mtx); |
| 338 | } |
| 339 | |
| 340 | static void |
| 341 | ieee802154_unlock_llsec_table(struct wpan_phy *wpan_phy, |
| 342 | struct wpan_dev *wpan_dev) |
| 343 | { |
| 344 | struct net_device *dev = wpan_dev->netdev; |
| 345 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 346 | |
| 347 | mutex_unlock(&sdata->sec_mtx); |
| 348 | } |
| 349 | |
| 350 | static int |
| 351 | ieee802154_set_llsec_params(struct wpan_phy *wpan_phy, |
| 352 | struct wpan_dev *wpan_dev, |
| 353 | const struct ieee802154_llsec_params *params, |
| 354 | int changed) |
| 355 | { |
| 356 | struct net_device *dev = wpan_dev->netdev; |
| 357 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 358 | int res; |
| 359 | |
| 360 | mutex_lock(&sdata->sec_mtx); |
| 361 | res = mac802154_llsec_set_params(&sdata->sec, params, changed); |
| 362 | mutex_unlock(&sdata->sec_mtx); |
| 363 | |
| 364 | return res; |
| 365 | } |
| 366 | |
| 367 | static int |
| 368 | ieee802154_get_llsec_params(struct wpan_phy *wpan_phy, |
| 369 | struct wpan_dev *wpan_dev, |
| 370 | struct ieee802154_llsec_params *params) |
| 371 | { |
| 372 | struct net_device *dev = wpan_dev->netdev; |
| 373 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 374 | int res; |
| 375 | |
| 376 | mutex_lock(&sdata->sec_mtx); |
| 377 | res = mac802154_llsec_get_params(&sdata->sec, params); |
| 378 | mutex_unlock(&sdata->sec_mtx); |
| 379 | |
| 380 | return res; |
| 381 | } |
| 382 | |
| 383 | static int |
| 384 | ieee802154_add_llsec_key(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 385 | const struct ieee802154_llsec_key_id *id, |
| 386 | const struct ieee802154_llsec_key *key) |
| 387 | { |
| 388 | struct net_device *dev = wpan_dev->netdev; |
| 389 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 390 | int res; |
| 391 | |
| 392 | mutex_lock(&sdata->sec_mtx); |
| 393 | res = mac802154_llsec_key_add(&sdata->sec, id, key); |
| 394 | mutex_unlock(&sdata->sec_mtx); |
| 395 | |
| 396 | return res; |
| 397 | } |
| 398 | |
| 399 | static int |
| 400 | ieee802154_del_llsec_key(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 401 | const struct ieee802154_llsec_key_id *id) |
| 402 | { |
| 403 | struct net_device *dev = wpan_dev->netdev; |
| 404 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 405 | int res; |
| 406 | |
| 407 | mutex_lock(&sdata->sec_mtx); |
| 408 | res = mac802154_llsec_key_del(&sdata->sec, id); |
| 409 | mutex_unlock(&sdata->sec_mtx); |
| 410 | |
| 411 | return res; |
| 412 | } |
| 413 | |
| 414 | static int |
| 415 | ieee802154_add_seclevel(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 416 | const struct ieee802154_llsec_seclevel *sl) |
| 417 | { |
| 418 | struct net_device *dev = wpan_dev->netdev; |
| 419 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 420 | int res; |
| 421 | |
| 422 | mutex_lock(&sdata->sec_mtx); |
| 423 | res = mac802154_llsec_seclevel_add(&sdata->sec, sl); |
| 424 | mutex_unlock(&sdata->sec_mtx); |
| 425 | |
| 426 | return res; |
| 427 | } |
| 428 | |
| 429 | static int |
| 430 | ieee802154_del_seclevel(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 431 | const struct ieee802154_llsec_seclevel *sl) |
| 432 | { |
| 433 | struct net_device *dev = wpan_dev->netdev; |
| 434 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 435 | int res; |
| 436 | |
| 437 | mutex_lock(&sdata->sec_mtx); |
| 438 | res = mac802154_llsec_seclevel_del(&sdata->sec, sl); |
| 439 | mutex_unlock(&sdata->sec_mtx); |
| 440 | |
| 441 | return res; |
| 442 | } |
| 443 | |
| 444 | static int |
| 445 | ieee802154_add_device(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 446 | const struct ieee802154_llsec_device *dev_desc) |
| 447 | { |
| 448 | struct net_device *dev = wpan_dev->netdev; |
| 449 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 450 | int res; |
| 451 | |
| 452 | mutex_lock(&sdata->sec_mtx); |
| 453 | res = mac802154_llsec_dev_add(&sdata->sec, dev_desc); |
| 454 | mutex_unlock(&sdata->sec_mtx); |
| 455 | |
| 456 | return res; |
| 457 | } |
| 458 | |
| 459 | static int |
| 460 | ieee802154_del_device(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 461 | __le64 extended_addr) |
| 462 | { |
| 463 | struct net_device *dev = wpan_dev->netdev; |
| 464 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 465 | int res; |
| 466 | |
| 467 | mutex_lock(&sdata->sec_mtx); |
| 468 | res = mac802154_llsec_dev_del(&sdata->sec, extended_addr); |
| 469 | mutex_unlock(&sdata->sec_mtx); |
| 470 | |
| 471 | return res; |
| 472 | } |
| 473 | |
| 474 | static int |
| 475 | ieee802154_add_devkey(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 476 | __le64 extended_addr, |
| 477 | const struct ieee802154_llsec_device_key *key) |
| 478 | { |
| 479 | struct net_device *dev = wpan_dev->netdev; |
| 480 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 481 | int res; |
| 482 | |
| 483 | mutex_lock(&sdata->sec_mtx); |
| 484 | res = mac802154_llsec_devkey_add(&sdata->sec, extended_addr, key); |
| 485 | mutex_unlock(&sdata->sec_mtx); |
| 486 | |
| 487 | return res; |
| 488 | } |
| 489 | |
| 490 | static int |
| 491 | ieee802154_del_devkey(struct wpan_phy *wpan_phy, struct wpan_dev *wpan_dev, |
| 492 | __le64 extended_addr, |
| 493 | const struct ieee802154_llsec_device_key *key) |
| 494 | { |
| 495 | struct net_device *dev = wpan_dev->netdev; |
| 496 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
| 497 | int res; |
| 498 | |
| 499 | mutex_lock(&sdata->sec_mtx); |
| 500 | res = mac802154_llsec_devkey_del(&sdata->sec, extended_addr, key); |
| 501 | mutex_unlock(&sdata->sec_mtx); |
| 502 | |
| 503 | return res; |
| 504 | } |
| 505 | #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */ |
| 506 | |
Alexander Aring | 1201cd2 | 2014-11-02 04:18:36 +0100 | [diff] [blame] | 507 | const struct cfg802154_ops mac802154_config_ops = { |
Alexander Aring | 4a9a816 | 2014-11-02 04:18:38 +0100 | [diff] [blame] | 508 | .add_virtual_intf_deprecated = ieee802154_add_iface_deprecated, |
| 509 | .del_virtual_intf_deprecated = ieee802154_del_iface_deprecated, |
Alexander Aring | 3cf24cf | 2015-06-24 11:36:36 +0200 | [diff] [blame] | 510 | .suspend = ieee802154_suspend, |
| 511 | .resume = ieee802154_resume, |
Alexander Aring | f3ea5e4 | 2014-11-17 08:20:51 +0100 | [diff] [blame] | 512 | .add_virtual_intf = ieee802154_add_iface, |
Alexander Aring | b821ecd | 2014-11-17 08:20:53 +0100 | [diff] [blame] | 513 | .del_virtual_intf = ieee802154_del_iface, |
Alexander Aring | ab0bd56 | 2014-11-12 03:36:55 +0100 | [diff] [blame] | 514 | .set_channel = ieee802154_set_channel, |
Alexander Aring | ba2a950 | 2014-12-10 15:33:13 +0100 | [diff] [blame] | 515 | .set_cca_mode = ieee802154_set_cca_mode, |
Alexander Aring | b69644c | 2015-05-27 13:42:10 +0200 | [diff] [blame] | 516 | .set_cca_ed_level = ieee802154_set_cca_ed_level, |
Varka Bhadram | 0f999b0 | 2015-05-27 09:10:54 +0530 | [diff] [blame] | 517 | .set_tx_power = ieee802154_set_tx_power, |
Alexander Aring | 702bf37 | 2014-11-12 03:36:57 +0100 | [diff] [blame] | 518 | .set_pan_id = ieee802154_set_pan_id, |
Alexander Aring | 9830c62 | 2014-11-12 03:36:58 +0100 | [diff] [blame] | 519 | .set_short_addr = ieee802154_set_short_addr, |
Alexander Aring | 656a999 | 2014-11-12 03:36:59 +0100 | [diff] [blame] | 520 | .set_backoff_exponent = ieee802154_set_backoff_exponent, |
Alexander Aring | a01ba76 | 2014-11-12 03:37:01 +0100 | [diff] [blame] | 521 | .set_max_csma_backoffs = ieee802154_set_max_csma_backoffs, |
Alexander Aring | 17a3a46 | 2014-11-12 03:37:03 +0100 | [diff] [blame] | 522 | .set_max_frame_retries = ieee802154_set_max_frame_retries, |
Alexander Aring | c8937a1d | 2014-11-12 03:37:05 +0100 | [diff] [blame] | 523 | .set_lbt_mode = ieee802154_set_lbt_mode, |
Alexander Aring | c91208d | 2015-08-10 21:15:58 +0200 | [diff] [blame] | 524 | .set_ackreq_default = ieee802154_set_ackreq_default, |
Miquel Raynal | 57588c7 | 2023-01-03 17:56:44 +0100 | [diff] [blame] | 525 | .trigger_scan = mac802154_trigger_scan, |
| 526 | .abort_scan = mac802154_abort_scan, |
Miquel Raynal | 3accf47 | 2023-01-25 11:29:23 +0100 | [diff] [blame] | 527 | .send_beacons = mac802154_send_beacons, |
| 528 | .stop_beacons = mac802154_stop_beacons, |
Alexander Aring | a26c5fd | 2015-09-28 09:00:25 +0200 | [diff] [blame] | 529 | #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL |
| 530 | .get_llsec_table = ieee802154_get_llsec_table, |
| 531 | .lock_llsec_table = ieee802154_lock_llsec_table, |
| 532 | .unlock_llsec_table = ieee802154_unlock_llsec_table, |
| 533 | /* TODO above */ |
| 534 | .set_llsec_params = ieee802154_set_llsec_params, |
| 535 | .get_llsec_params = ieee802154_get_llsec_params, |
| 536 | .add_llsec_key = ieee802154_add_llsec_key, |
| 537 | .del_llsec_key = ieee802154_del_llsec_key, |
| 538 | .add_seclevel = ieee802154_add_seclevel, |
| 539 | .del_seclevel = ieee802154_del_seclevel, |
| 540 | .add_device = ieee802154_add_device, |
| 541 | .del_device = ieee802154_del_device, |
| 542 | .add_devkey = ieee802154_add_devkey, |
| 543 | .del_devkey = ieee802154_del_devkey, |
| 544 | #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */ |
Alexander Aring | 1201cd2 | 2014-11-02 04:18:36 +0100 | [diff] [blame] | 545 | }; |