mesh.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include <linux/ieee80211.h>
  2. #include <net/cfg80211.h>
  3. #include "nl80211.h"
  4. #include "core.h"
  5. /* Default values, timeouts in ms */
  6. #define MESH_TTL 31
  7. #define MESH_DEFAULT_ELEMENT_TTL 31
  8. #define MESH_MAX_RETR 3
  9. #define MESH_RET_T 100
  10. #define MESH_CONF_T 100
  11. #define MESH_HOLD_T 100
  12. #define MESH_PATH_TIMEOUT 5000
  13. /*
  14. * Minimum interval between two consecutive PREQs originated by the same
  15. * interface
  16. */
  17. #define MESH_PREQ_MIN_INT 10
  18. #define MESH_DIAM_TRAVERSAL_TIME 50
  19. /*
  20. * A path will be refreshed if it is used PATH_REFRESH_TIME milliseconds
  21. * before timing out. This way it will remain ACTIVE and no data frames
  22. * will be unnecessarily held in the pending queue.
  23. */
  24. #define MESH_PATH_REFRESH_TIME 1000
  25. #define MESH_MIN_DISCOVERY_TIMEOUT (2 * MESH_DIAM_TRAVERSAL_TIME)
  26. /* Default maximum number of established plinks per interface */
  27. #define MESH_MAX_ESTAB_PLINKS 32
  28. #define MESH_MAX_PREQ_RETRIES 4
  29. const struct mesh_config default_mesh_config = {
  30. .dot11MeshRetryTimeout = MESH_RET_T,
  31. .dot11MeshConfirmTimeout = MESH_CONF_T,
  32. .dot11MeshHoldingTimeout = MESH_HOLD_T,
  33. .dot11MeshMaxRetries = MESH_MAX_RETR,
  34. .dot11MeshTTL = MESH_TTL,
  35. .element_ttl = MESH_DEFAULT_ELEMENT_TTL,
  36. .auto_open_plinks = true,
  37. .dot11MeshMaxPeerLinks = MESH_MAX_ESTAB_PLINKS,
  38. .dot11MeshHWMPactivePathTimeout = MESH_PATH_TIMEOUT,
  39. .dot11MeshHWMPpreqMinInterval = MESH_PREQ_MIN_INT,
  40. .dot11MeshHWMPnetDiameterTraversalTime = MESH_DIAM_TRAVERSAL_TIME,
  41. .dot11MeshHWMPmaxPREQretries = MESH_MAX_PREQ_RETRIES,
  42. .path_refresh_time = MESH_PATH_REFRESH_TIME,
  43. .min_discovery_timeout = MESH_MIN_DISCOVERY_TIMEOUT,
  44. };
  45. const struct mesh_setup default_mesh_setup = {
  46. .path_sel_proto = IEEE80211_PATH_PROTOCOL_HWMP,
  47. .path_metric = IEEE80211_PATH_METRIC_AIRTIME,
  48. .ie = NULL,
  49. .ie_len = 0,
  50. .is_secure = false,
  51. };
  52. int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  53. struct net_device *dev,
  54. const struct mesh_setup *setup,
  55. const struct mesh_config *conf)
  56. {
  57. struct wireless_dev *wdev = dev->ieee80211_ptr;
  58. int err;
  59. BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != IEEE80211_MAX_MESH_ID_LEN);
  60. ASSERT_WDEV_LOCK(wdev);
  61. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  62. return -EOPNOTSUPP;
  63. if (!(rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
  64. setup->is_secure)
  65. return -EOPNOTSUPP;
  66. if (wdev->mesh_id_len)
  67. return -EALREADY;
  68. if (!setup->mesh_id_len)
  69. return -EINVAL;
  70. if (!rdev->ops->join_mesh)
  71. return -EOPNOTSUPP;
  72. err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, setup);
  73. if (!err) {
  74. memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
  75. wdev->mesh_id_len = setup->mesh_id_len;
  76. }
  77. return err;
  78. }
  79. int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  80. struct net_device *dev,
  81. const struct mesh_setup *setup,
  82. const struct mesh_config *conf)
  83. {
  84. struct wireless_dev *wdev = dev->ieee80211_ptr;
  85. int err;
  86. wdev_lock(wdev);
  87. err = __cfg80211_join_mesh(rdev, dev, setup, conf);
  88. wdev_unlock(wdev);
  89. return err;
  90. }
  91. void cfg80211_notify_new_peer_candidate(struct net_device *dev,
  92. const u8 *macaddr, const u8* ie, u8 ie_len, gfp_t gfp)
  93. {
  94. struct wireless_dev *wdev = dev->ieee80211_ptr;
  95. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
  96. return;
  97. nl80211_send_new_peer_candidate(wiphy_to_dev(wdev->wiphy), dev,
  98. macaddr, ie, ie_len, gfp);
  99. }
  100. EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
  101. static int __cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
  102. struct net_device *dev)
  103. {
  104. struct wireless_dev *wdev = dev->ieee80211_ptr;
  105. int err;
  106. ASSERT_WDEV_LOCK(wdev);
  107. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
  108. return -EOPNOTSUPP;
  109. if (!rdev->ops->leave_mesh)
  110. return -EOPNOTSUPP;
  111. if (!wdev->mesh_id_len)
  112. return -ENOTCONN;
  113. err = rdev->ops->leave_mesh(&rdev->wiphy, dev);
  114. if (!err)
  115. wdev->mesh_id_len = 0;
  116. return err;
  117. }
  118. int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
  119. struct net_device *dev)
  120. {
  121. struct wireless_dev *wdev = dev->ieee80211_ptr;
  122. int err;
  123. wdev_lock(wdev);
  124. err = __cfg80211_leave_mesh(rdev, dev);
  125. wdev_unlock(wdev);
  126. return err;
  127. }