alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * MAC commands interface |
| 3 | * |
| 4 | * Copyright 2007-2012 Siemens AG |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 15 | * Written by: |
| 16 | * Sergey Lapin <slapin@ossfans.org> |
| 17 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
| 18 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> |
| 19 | */ |
| 20 | |
| 21 | #include <linux/skbuff.h> |
| 22 | #include <linux/if_arp.h> |
Alexander Aring | 4ca24ac | 2014-10-25 09:41:04 +0200 | [diff] [blame] | 23 | #include <linux/ieee802154.h> |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 24 | |
| 25 | #include <net/ieee802154_netdev.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 26 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 27 | #include <net/mac802154.h> |
| 28 | |
Alexander Aring | 0f1556b | 2014-10-25 09:41:00 +0200 | [diff] [blame] | 29 | #include "ieee802154_i.h" |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 30 | #include "driver-ops.h" |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 31 | |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 32 | static int mac802154_mlme_start_req(struct net_device *dev, |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 33 | struct ieee802154_addr *addr, |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 34 | u8 channel, u8 page, |
| 35 | u8 bcn_ord, u8 sf_ord, |
| 36 | u8 pan_coord, u8 blx, |
| 37 | u8 coord_realign) |
| 38 | { |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 39 | struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev); |
| 40 | int rc = 0; |
| 41 | |
Alexander Aring | 7bea1ea | 2014-11-09 08:36:57 +0100 | [diff] [blame] | 42 | ASSERT_RTNL(); |
| 43 | |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 44 | BUG_ON(addr->mode != IEEE802154_ADDR_SHORT); |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 45 | |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 46 | mac802154_dev_set_pan_id(dev, addr->pan_id); |
| 47 | mac802154_dev_set_short_addr(dev, addr->short_addr); |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 48 | mac802154_dev_set_page_channel(dev, page, channel); |
| 49 | |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 50 | if (ops->llsec) { |
| 51 | struct ieee802154_llsec_params params; |
| 52 | int changed = 0; |
| 53 | |
| 54 | params.coord_shortaddr = addr->short_addr; |
| 55 | changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR; |
| 56 | |
| 57 | params.pan_id = addr->pan_id; |
| 58 | changed |= IEEE802154_LLSEC_PARAM_PAN_ID; |
| 59 | |
| 60 | params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr); |
| 61 | changed |= IEEE802154_LLSEC_PARAM_HWADDR; |
| 62 | |
| 63 | params.coord_hwaddr = params.hwaddr; |
| 64 | changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR; |
| 65 | |
| 66 | rc = ops->llsec->set_params(dev, ¶ms, changed); |
| 67 | } |
| 68 | |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 69 | return rc; |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 72 | static int mac802154_set_mac_params(struct net_device *dev, |
| 73 | const struct ieee802154_mac_params *params) |
| 74 | { |
| 75 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 76 | struct ieee802154_local *local = sdata->local; |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 77 | struct wpan_dev *wpan_dev = &sdata->wpan_dev; |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 78 | int ret; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 79 | |
Alexander Aring | 7bea1ea | 2014-11-09 08:36:57 +0100 | [diff] [blame] | 80 | ASSERT_RTNL(); |
| 81 | |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 82 | /* PHY */ |
| 83 | wpan_dev->wpan_phy->transmit_power = params->transmit_power; |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 84 | wpan_dev->wpan_phy->cca = params->cca; |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 85 | wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level; |
| 86 | |
| 87 | /* MAC */ |
| 88 | wpan_dev->min_be = params->min_be; |
| 89 | wpan_dev->max_be = params->max_be; |
| 90 | wpan_dev->csma_retries = params->csma_retries; |
| 91 | wpan_dev->frame_retries = params->frame_retries; |
| 92 | wpan_dev->lbt = params->lbt; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 93 | |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 94 | if (local->hw.flags & IEEE802154_HW_TXPOWER) { |
| 95 | ret = drv_set_tx_power(local, params->transmit_power); |
| 96 | if (ret < 0) |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | if (local->hw.flags & IEEE802154_HW_CCA_MODE) { |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 101 | ret = drv_set_cca_mode(local, ¶ms->cca); |
Alexander Aring | f59f419 | 2014-11-02 04:18:44 +0100 | [diff] [blame] | 102 | if (ret < 0) |
| 103 | return ret; |
| 104 | } |
| 105 | |
| 106 | if (local->hw.flags & IEEE802154_HW_CCA_ED_LEVEL) { |
| 107 | ret = drv_set_cca_ed_level(local, params->cca_ed_level); |
| 108 | if (ret < 0) |
| 109 | return ret; |
| 110 | } |
| 111 | |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static void mac802154_get_mac_params(struct net_device *dev, |
| 116 | struct ieee802154_mac_params *params) |
| 117 | { |
| 118 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 119 | struct wpan_dev *wpan_dev = &sdata->wpan_dev; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 120 | |
Alexander Aring | 7bea1ea | 2014-11-09 08:36:57 +0100 | [diff] [blame] | 121 | ASSERT_RTNL(); |
| 122 | |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 123 | /* PHY */ |
| 124 | params->transmit_power = wpan_dev->wpan_phy->transmit_power; |
Alexander Aring | 7fe9a38 | 2014-12-10 15:33:12 +0100 | [diff] [blame] | 125 | params->cca = wpan_dev->wpan_phy->cca; |
Alexander Aring | 5fb3f02 | 2014-11-09 08:36:46 +0100 | [diff] [blame] | 126 | params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level; |
| 127 | |
| 128 | /* MAC */ |
| 129 | params->min_be = wpan_dev->min_be; |
| 130 | params->max_be = wpan_dev->max_be; |
| 131 | params->csma_retries = wpan_dev->csma_retries; |
| 132 | params->frame_retries = wpan_dev->frame_retries; |
| 133 | params->lbt = wpan_dev->lbt; |
Alexander Aring | c7420c3 | 2014-10-28 18:21:30 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 136 | static struct ieee802154_llsec_ops mac802154_llsec_ops = { |
| 137 | .get_params = mac802154_get_params, |
| 138 | .set_params = mac802154_set_params, |
| 139 | .add_key = mac802154_add_key, |
| 140 | .del_key = mac802154_del_key, |
| 141 | .add_dev = mac802154_add_dev, |
| 142 | .del_dev = mac802154_del_dev, |
| 143 | .add_devkey = mac802154_add_devkey, |
| 144 | .del_devkey = mac802154_del_devkey, |
| 145 | .add_seclevel = mac802154_add_seclevel, |
| 146 | .del_seclevel = mac802154_del_seclevel, |
| 147 | .lock_table = mac802154_lock_table, |
| 148 | .get_table = mac802154_get_table, |
| 149 | .unlock_table = mac802154_unlock_table, |
| 150 | }; |
| 151 | |
alex.bluesman.smirnov@gmail.com | 32bad7e | 2012-06-25 23:24:48 +0000 | [diff] [blame] | 152 | struct ieee802154_mlme_ops mac802154_mlme_wpan = { |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 153 | .start_req = mac802154_mlme_start_req, |
alex.bluesman.smirnov@gmail.com | e885a47 | 2012-07-10 21:22:44 +0000 | [diff] [blame] | 154 | .get_pan_id = mac802154_dev_get_pan_id, |
| 155 | .get_short_addr = mac802154_dev_get_short_addr, |
Tony Cheneau | 0483546 | 2013-03-25 17:59:29 +0000 | [diff] [blame] | 156 | .get_dsn = mac802154_dev_get_dsn, |
Phoebe Buckheister | e462ded | 2014-03-31 21:37:46 +0200 | [diff] [blame] | 157 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 158 | .llsec = &mac802154_llsec_ops, |
| 159 | |
Phoebe Buckheister | e462ded | 2014-03-31 21:37:46 +0200 | [diff] [blame] | 160 | .set_mac_params = mac802154_set_mac_params, |
| 161 | .get_mac_params = mac802154_get_mac_params, |
alex.bluesman.smirnov@gmail.com | 32bad7e | 2012-06-25 23:24:48 +0000 | [diff] [blame] | 162 | }; |