mac_cmd.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include <linux/skbuff.h>
  25. #include <linux/if_arp.h>
  26. #include <net/ieee802154.h>
  27. #include <net/ieee802154_netdev.h>
  28. #include <net/wpan-phy.h>
  29. #include <net/mac802154.h>
  30. #include <net/nl802154.h>
  31. #include "mac802154.h"
  32. static int mac802154_mlme_start_req(struct net_device *dev,
  33. struct ieee802154_addr *addr,
  34. u8 channel, u8 page,
  35. u8 bcn_ord, u8 sf_ord,
  36. u8 pan_coord, u8 blx,
  37. u8 coord_realign)
  38. {
  39. struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
  40. int rc = 0;
  41. BUG_ON(addr->mode != IEEE802154_ADDR_SHORT);
  42. mac802154_dev_set_pan_id(dev, addr->pan_id);
  43. mac802154_dev_set_short_addr(dev, addr->short_addr);
  44. mac802154_dev_set_ieee_addr(dev);
  45. mac802154_dev_set_page_channel(dev, page, channel);
  46. if (ops->llsec) {
  47. struct ieee802154_llsec_params params;
  48. int changed = 0;
  49. params.coord_shortaddr = addr->short_addr;
  50. changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR;
  51. params.pan_id = addr->pan_id;
  52. changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
  53. params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr);
  54. changed |= IEEE802154_LLSEC_PARAM_HWADDR;
  55. params.coord_hwaddr = params.hwaddr;
  56. changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR;
  57. rc = ops->llsec->set_params(dev, &params, changed);
  58. }
  59. /* FIXME: add validation for unused parameters to be sane
  60. * for SoftMAC
  61. */
  62. ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS);
  63. return rc;
  64. }
  65. static struct wpan_phy *mac802154_get_phy(const struct net_device *dev)
  66. {
  67. struct mac802154_sub_if_data *priv = netdev_priv(dev);
  68. BUG_ON(dev->type != ARPHRD_IEEE802154);
  69. return to_phy(get_device(&priv->hw->phy->dev));
  70. }
  71. static struct ieee802154_llsec_ops mac802154_llsec_ops = {
  72. .get_params = mac802154_get_params,
  73. .set_params = mac802154_set_params,
  74. .add_key = mac802154_add_key,
  75. .del_key = mac802154_del_key,
  76. .add_dev = mac802154_add_dev,
  77. .del_dev = mac802154_del_dev,
  78. .add_devkey = mac802154_add_devkey,
  79. .del_devkey = mac802154_del_devkey,
  80. .add_seclevel = mac802154_add_seclevel,
  81. .del_seclevel = mac802154_del_seclevel,
  82. .lock_table = mac802154_lock_table,
  83. .get_table = mac802154_get_table,
  84. .unlock_table = mac802154_unlock_table,
  85. };
  86. struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced = {
  87. .get_phy = mac802154_get_phy,
  88. };
  89. struct ieee802154_mlme_ops mac802154_mlme_wpan = {
  90. .get_phy = mac802154_get_phy,
  91. .start_req = mac802154_mlme_start_req,
  92. .get_pan_id = mac802154_dev_get_pan_id,
  93. .get_short_addr = mac802154_dev_get_short_addr,
  94. .get_dsn = mac802154_dev_get_dsn,
  95. .llsec = &mac802154_llsec_ops,
  96. .set_mac_params = mac802154_set_mac_params,
  97. .get_mac_params = mac802154_get_mac_params,
  98. };