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 | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 2 | /* |
| 3 | * MAC commands interface |
| 4 | * |
| 5 | * Copyright 2007-2012 Siemens AG |
| 6 | * |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 7 | * Written by: |
| 8 | * Sergey Lapin <slapin@ossfans.org> |
| 9 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
| 10 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> |
| 11 | */ |
| 12 | |
| 13 | #include <linux/skbuff.h> |
| 14 | #include <linux/if_arp.h> |
Alexander Aring | 4ca24ac | 2014-10-25 09:41:04 +0200 | [diff] [blame] | 15 | #include <linux/ieee802154.h> |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 16 | |
| 17 | #include <net/ieee802154_netdev.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 18 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 19 | #include <net/mac802154.h> |
| 20 | |
Alexander Aring | 0f1556b | 2014-10-25 09:41:00 +0200 | [diff] [blame] | 21 | #include "ieee802154_i.h" |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 22 | #include "driver-ops.h" |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 23 | |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 24 | static int mac802154_mlme_start_req(struct net_device *dev, |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 25 | struct ieee802154_addr *addr, |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 26 | u8 channel, u8 page, |
| 27 | u8 bcn_ord, u8 sf_ord, |
| 28 | u8 pan_coord, u8 blx, |
| 29 | u8 coord_realign) |
| 30 | { |
Lennert Buytenhek | 641459c | 2015-05-25 15:38:51 +0300 | [diff] [blame] | 31 | struct ieee802154_llsec_params params; |
| 32 | int changed = 0; |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 33 | |
Alexander Aring | 7bea1ea | 2014-11-09 08:36:57 +0100 | [diff] [blame] | 34 | ASSERT_RTNL(); |
| 35 | |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 36 | BUG_ON(addr->mode != IEEE802154_ADDR_SHORT); |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 37 | |
Alexander Aring | c947f7e | 2015-05-22 17:43:54 +0200 | [diff] [blame] | 38 | dev->ieee802154_ptr->pan_id = addr->pan_id; |
| 39 | dev->ieee802154_ptr->short_addr = addr->short_addr; |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 40 | mac802154_dev_set_page_channel(dev, page, channel); |
| 41 | |
Lennert Buytenhek | 641459c | 2015-05-25 15:38:51 +0300 | [diff] [blame] | 42 | params.pan_id = addr->pan_id; |
| 43 | changed |= IEEE802154_LLSEC_PARAM_PAN_ID; |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 44 | |
Lennert Buytenhek | 641459c | 2015-05-25 15:38:51 +0300 | [diff] [blame] | 45 | params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr); |
| 46 | changed |= IEEE802154_LLSEC_PARAM_HWADDR; |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 47 | |
Lennert Buytenhek | 641459c | 2015-05-25 15:38:51 +0300 | [diff] [blame] | 48 | params.coord_hwaddr = params.hwaddr; |
| 49 | changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR; |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 50 | |
Lennert Buytenhek | 641459c | 2015-05-25 15:38:51 +0300 | [diff] [blame] | 51 | params.coord_shortaddr = addr->short_addr; |
| 52 | changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR; |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 53 | |
Lennert Buytenhek | 641459c | 2015-05-25 15:38:51 +0300 | [diff] [blame] | 54 | return mac802154_set_params(dev, ¶ms, changed); |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 57 | static int mac802154_set_mac_params(struct net_device *dev, |
| 58 | const struct ieee802154_mac_params *params) |
| 59 | { |
| 60 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 61 | struct ieee802154_local *local = sdata->local; |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 62 | struct wpan_dev *wpan_dev = &sdata->wpan_dev; |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 63 | int ret; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 64 | |
Alexander Aring | 7bea1ea | 2014-11-09 08:36:57 +0100 | [diff] [blame] | 65 | ASSERT_RTNL(); |
| 66 | |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 67 | /* PHY */ |
| 68 | wpan_dev->wpan_phy->transmit_power = params->transmit_power; |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 69 | wpan_dev->wpan_phy->cca = params->cca; |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 70 | wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level; |
| 71 | |
| 72 | /* MAC */ |
| 73 | wpan_dev->min_be = params->min_be; |
| 74 | wpan_dev->max_be = params->max_be; |
| 75 | wpan_dev->csma_retries = params->csma_retries; |
| 76 | wpan_dev->frame_retries = params->frame_retries; |
| 77 | wpan_dev->lbt = params->lbt; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 78 | |
Alexander Aring | edea8f7 | 2015-05-17 21:44:46 +0200 | [diff] [blame] | 79 | if (local->hw.phy->flags & WPAN_PHY_FLAG_TXPOWER) { |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 80 | ret = drv_set_tx_power(local, params->transmit_power); |
| 81 | if (ret < 0) |
| 82 | return ret; |
| 83 | } |
| 84 | |
Alexander Aring | edea8f7 | 2015-05-17 21:44:46 +0200 | [diff] [blame] | 85 | if (local->hw.phy->flags & WPAN_PHY_FLAG_CCA_MODE) { |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 86 | ret = drv_set_cca_mode(local, ¶ms->cca); |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 87 | if (ret < 0) |
| 88 | return ret; |
| 89 | } |
| 90 | |
Alexander Aring | edea8f7 | 2015-05-17 21:44:46 +0200 | [diff] [blame] | 91 | if (local->hw.phy->flags & WPAN_PHY_FLAG_CCA_ED_LEVEL) { |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 92 | ret = drv_set_cca_ed_level(local, params->cca_ed_level); |
| 93 | if (ret < 0) |
| 94 | return ret; |
| 95 | } |
| 96 | |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static void mac802154_get_mac_params(struct net_device *dev, |
| 101 | struct ieee802154_mac_params *params) |
| 102 | { |
| 103 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 104 | struct wpan_dev *wpan_dev = &sdata->wpan_dev; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 105 | |
Alexander Aring | 7bea1ea | 2014-11-09 08:36:57 +0100 | [diff] [blame] | 106 | ASSERT_RTNL(); |
| 107 | |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 108 | /* PHY */ |
| 109 | params->transmit_power = wpan_dev->wpan_phy->transmit_power; |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 110 | params->cca = wpan_dev->wpan_phy->cca; |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 111 | params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level; |
| 112 | |
| 113 | /* MAC */ |
| 114 | params->min_be = wpan_dev->min_be; |
| 115 | params->max_be = wpan_dev->max_be; |
| 116 | params->csma_retries = wpan_dev->csma_retries; |
| 117 | params->frame_retries = wpan_dev->frame_retries; |
| 118 | params->lbt = wpan_dev->lbt; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Julia Lawall | 29663b0 | 2015-12-23 22:36:32 +0100 | [diff] [blame] | 121 | static const struct ieee802154_llsec_ops mac802154_llsec_ops = { |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 122 | .get_params = mac802154_get_params, |
| 123 | .set_params = mac802154_set_params, |
| 124 | .add_key = mac802154_add_key, |
| 125 | .del_key = mac802154_del_key, |
| 126 | .add_dev = mac802154_add_dev, |
| 127 | .del_dev = mac802154_del_dev, |
| 128 | .add_devkey = mac802154_add_devkey, |
| 129 | .del_devkey = mac802154_del_devkey, |
| 130 | .add_seclevel = mac802154_add_seclevel, |
| 131 | .del_seclevel = mac802154_del_seclevel, |
| 132 | .lock_table = mac802154_lock_table, |
| 133 | .get_table = mac802154_get_table, |
| 134 | .unlock_table = mac802154_unlock_table, |
| 135 | }; |
| 136 | |
alex.bluesman.smirnov@gmail.com | 32bad7e | 2012-06-25 23:24:48 +0000 | [diff] [blame] | 137 | struct ieee802154_mlme_ops mac802154_mlme_wpan = { |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 138 | .start_req = mac802154_mlme_start_req, |
Phoebe Buckheister | e462ded | 2014-03-31 21:37:46 +0200 | [diff] [blame] | 139 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 140 | .llsec = &mac802154_llsec_ops, |
| 141 | |
Phoebe Buckheister | e462ded | 2014-03-31 21:37:46 +0200 | [diff] [blame] | 142 | .set_mac_params = mac802154_set_mac_params, |
| 143 | .get_mac_params = mac802154_get_mac_params, |
alex.bluesman.smirnov@gmail.com | 32bad7e | 2012-06-25 23:24:48 +0000 | [diff] [blame] | 144 | }; |