mesh.c 4.3 KB

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