mac_cmd.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * 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. #include <linux/skbuff.h>
  21. #include <linux/if_arp.h>
  22. #include <linux/ieee802154.h>
  23. #include <net/ieee802154_netdev.h>
  24. #include <net/cfg802154.h>
  25. #include <net/mac802154.h>
  26. #include "ieee802154_i.h"
  27. #include "driver-ops.h"
  28. static int mac802154_mlme_start_req(struct net_device *dev,
  29. struct ieee802154_addr *addr,
  30. u8 channel, u8 page,
  31. u8 bcn_ord, u8 sf_ord,
  32. u8 pan_coord, u8 blx,
  33. u8 coord_realign)
  34. {
  35. struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
  36. int rc = 0;
  37. ASSERT_RTNL();
  38. BUG_ON(addr->mode != IEEE802154_ADDR_SHORT);
  39. mac802154_dev_set_pan_id(dev, addr->pan_id);
  40. mac802154_dev_set_short_addr(dev, addr->short_addr);
  41. mac802154_dev_set_page_channel(dev, page, channel);
  42. if (ops->llsec) {
  43. struct ieee802154_llsec_params params;
  44. int changed = 0;
  45. params.coord_shortaddr = addr->short_addr;
  46. changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR;
  47. params.pan_id = addr->pan_id;
  48. changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
  49. params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr);
  50. changed |= IEEE802154_LLSEC_PARAM_HWADDR;
  51. params.coord_hwaddr = params.hwaddr;
  52. changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR;
  53. rc = ops->llsec->set_params(dev, &params, changed);
  54. }
  55. return rc;
  56. }
  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);
  61. struct ieee802154_local *local = sdata->local;
  62. struct wpan_dev *wpan_dev = &sdata->wpan_dev;
  63. int ret;
  64. ASSERT_RTNL();
  65. /* PHY */
  66. wpan_dev->wpan_phy->transmit_power = params->transmit_power;
  67. wpan_dev->wpan_phy->cca = params->cca;
  68. wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level;
  69. /* MAC */
  70. wpan_dev->min_be = params->min_be;
  71. wpan_dev->max_be = params->max_be;
  72. wpan_dev->csma_retries = params->csma_retries;
  73. wpan_dev->frame_retries = params->frame_retries;
  74. wpan_dev->lbt = params->lbt;
  75. if (local->hw.flags & IEEE802154_HW_TXPOWER) {
  76. ret = drv_set_tx_power(local, params->transmit_power);
  77. if (ret < 0)
  78. return ret;
  79. }
  80. if (local->hw.flags & IEEE802154_HW_CCA_MODE) {
  81. ret = drv_set_cca_mode(local, &params->cca);
  82. if (ret < 0)
  83. return ret;
  84. }
  85. if (local->hw.flags & IEEE802154_HW_CCA_ED_LEVEL) {
  86. ret = drv_set_cca_ed_level(local, params->cca_ed_level);
  87. if (ret < 0)
  88. return ret;
  89. }
  90. return 0;
  91. }
  92. static void mac802154_get_mac_params(struct net_device *dev,
  93. struct ieee802154_mac_params *params)
  94. {
  95. struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
  96. struct wpan_dev *wpan_dev = &sdata->wpan_dev;
  97. ASSERT_RTNL();
  98. /* PHY */
  99. params->transmit_power = wpan_dev->wpan_phy->transmit_power;
  100. params->cca = wpan_dev->wpan_phy->cca;
  101. params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level;
  102. /* MAC */
  103. params->min_be = wpan_dev->min_be;
  104. params->max_be = wpan_dev->max_be;
  105. params->csma_retries = wpan_dev->csma_retries;
  106. params->frame_retries = wpan_dev->frame_retries;
  107. params->lbt = wpan_dev->lbt;
  108. }
  109. static struct ieee802154_llsec_ops mac802154_llsec_ops = {
  110. .get_params = mac802154_get_params,
  111. .set_params = mac802154_set_params,
  112. .add_key = mac802154_add_key,
  113. .del_key = mac802154_del_key,
  114. .add_dev = mac802154_add_dev,
  115. .del_dev = mac802154_del_dev,
  116. .add_devkey = mac802154_add_devkey,
  117. .del_devkey = mac802154_del_devkey,
  118. .add_seclevel = mac802154_add_seclevel,
  119. .del_seclevel = mac802154_del_seclevel,
  120. .lock_table = mac802154_lock_table,
  121. .get_table = mac802154_get_table,
  122. .unlock_table = mac802154_unlock_table,
  123. };
  124. struct ieee802154_mlme_ops mac802154_mlme_wpan = {
  125. .start_req = mac802154_mlme_start_req,
  126. .get_pan_id = mac802154_dev_get_pan_id,
  127. .get_short_addr = mac802154_dev_get_short_addr,
  128. .get_dsn = mac802154_dev_get_dsn,
  129. .llsec = &mac802154_llsec_ops,
  130. .set_mac_params = mac802154_set_mac_params,
  131. .get_mac_params = mac802154_get_mac_params,
  132. };