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 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Written by: |
| 20 | * Sergey Lapin <slapin@ossfans.org> |
| 21 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
| 22 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> |
| 23 | */ |
| 24 | |
| 25 | #include <linux/skbuff.h> |
| 26 | #include <linux/if_arp.h> |
| 27 | |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 28 | #include <net/ieee802154.h> |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 29 | #include <net/ieee802154_netdev.h> |
| 30 | #include <net/wpan-phy.h> |
| 31 | #include <net/mac802154.h> |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 32 | #include <net/nl802154.h> |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 33 | |
| 34 | #include "mac802154.h" |
| 35 | |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 36 | static int mac802154_mlme_start_req(struct net_device *dev, |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 37 | struct ieee802154_addr *addr, |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 38 | u8 channel, u8 page, |
| 39 | u8 bcn_ord, u8 sf_ord, |
| 40 | u8 pan_coord, u8 blx, |
| 41 | u8 coord_realign) |
| 42 | { |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 43 | struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev); |
| 44 | int rc = 0; |
| 45 | |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 46 | BUG_ON(addr->mode != IEEE802154_ADDR_SHORT); |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 47 | |
Phoebe Buckheister | ae531b9 | 2014-03-14 21:24:02 +0100 | [diff] [blame] | 48 | mac802154_dev_set_pan_id(dev, addr->pan_id); |
| 49 | mac802154_dev_set_short_addr(dev, addr->short_addr); |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 50 | mac802154_dev_set_ieee_addr(dev); |
| 51 | mac802154_dev_set_page_channel(dev, page, channel); |
| 52 | |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 53 | if (ops->llsec) { |
| 54 | struct ieee802154_llsec_params params; |
| 55 | int changed = 0; |
| 56 | |
| 57 | params.coord_shortaddr = addr->short_addr; |
| 58 | changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR; |
| 59 | |
| 60 | params.pan_id = addr->pan_id; |
| 61 | changed |= IEEE802154_LLSEC_PARAM_PAN_ID; |
| 62 | |
| 63 | params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr); |
| 64 | changed |= IEEE802154_LLSEC_PARAM_HWADDR; |
| 65 | |
| 66 | params.coord_hwaddr = params.hwaddr; |
| 67 | changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR; |
| 68 | |
| 69 | rc = ops->llsec->set_params(dev, ¶ms, changed); |
| 70 | } |
| 71 | |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 72 | /* FIXME: add validation for unused parameters to be sane |
| 73 | * for SoftMAC |
| 74 | */ |
| 75 | ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS); |
| 76 | |
Phoebe Buckheister | 9b0bb4a | 2014-05-16 17:46:43 +0200 | [diff] [blame] | 77 | return rc; |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 78 | } |
| 79 | |
alex.bluesman.smirnov@gmail.com | 4288404 | 2012-07-10 21:22:46 +0000 | [diff] [blame] | 80 | static struct wpan_phy *mac802154_get_phy(const struct net_device *dev) |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 81 | { |
| 82 | struct mac802154_sub_if_data *priv = netdev_priv(dev); |
| 83 | |
| 84 | BUG_ON(dev->type != ARPHRD_IEEE802154); |
| 85 | |
| 86 | return to_phy(get_device(&priv->hw->phy->dev)); |
| 87 | } |
| 88 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 89 | static struct ieee802154_llsec_ops mac802154_llsec_ops = { |
| 90 | .get_params = mac802154_get_params, |
| 91 | .set_params = mac802154_set_params, |
| 92 | .add_key = mac802154_add_key, |
| 93 | .del_key = mac802154_del_key, |
| 94 | .add_dev = mac802154_add_dev, |
| 95 | .del_dev = mac802154_del_dev, |
| 96 | .add_devkey = mac802154_add_devkey, |
| 97 | .del_devkey = mac802154_del_devkey, |
| 98 | .add_seclevel = mac802154_add_seclevel, |
| 99 | .del_seclevel = mac802154_del_seclevel, |
| 100 | .lock_table = mac802154_lock_table, |
| 101 | .get_table = mac802154_get_table, |
| 102 | .unlock_table = mac802154_unlock_table, |
| 103 | }; |
| 104 | |
alex.bluesman.smirnov@gmail.com | 6e2128d | 2012-05-15 20:50:25 +0000 | [diff] [blame] | 105 | struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced = { |
| 106 | .get_phy = mac802154_get_phy, |
| 107 | }; |
alex.bluesman.smirnov@gmail.com | 32bad7e | 2012-06-25 23:24:48 +0000 | [diff] [blame] | 108 | |
| 109 | struct ieee802154_mlme_ops mac802154_mlme_wpan = { |
| 110 | .get_phy = mac802154_get_phy, |
alex.bluesman.smirnov@gmail.com | 5265f46 | 2012-06-25 23:24:52 +0000 | [diff] [blame] | 111 | .start_req = mac802154_mlme_start_req, |
alex.bluesman.smirnov@gmail.com | e885a47 | 2012-07-10 21:22:44 +0000 | [diff] [blame] | 112 | .get_pan_id = mac802154_dev_get_pan_id, |
| 113 | .get_short_addr = mac802154_dev_get_short_addr, |
Tony Cheneau | 0483546 | 2013-03-25 17:59:29 +0000 | [diff] [blame] | 114 | .get_dsn = mac802154_dev_get_dsn, |
Phoebe Buckheister | e462ded | 2014-03-31 21:37:46 +0200 | [diff] [blame] | 115 | |
Phoebe Buckheister | 29e0237 | 2014-05-16 17:46:42 +0200 | [diff] [blame] | 116 | .llsec = &mac802154_llsec_ops, |
| 117 | |
Phoebe Buckheister | e462ded | 2014-03-31 21:37:46 +0200 | [diff] [blame] | 118 | .set_mac_params = mac802154_set_mac_params, |
| 119 | .get_mac_params = mac802154_get_mac_params, |
alex.bluesman.smirnov@gmail.com | 32bad7e | 2012-06-25 23:24:48 +0000 | [diff] [blame] | 120 | }; |