]>
Commit | Line | Data |
---|---|---|
29cbe68c JB |
1 | #include <linux/ieee80211.h> |
2 | #include <net/cfg80211.h> | |
3 | #include "core.h" | |
4 | ||
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 | ||
13 | #define MESH_PATH_TIMEOUT 5000 | |
14 | ||
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_DIAM_TRAVERSAL_TIME 50 | |
21 | ||
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 | ||
30 | /* Default maximum number of established plinks per interface */ | |
31 | #define MESH_MAX_ESTAB_PLINKS 32 | |
32 | ||
33 | #define MESH_MAX_PREQ_RETRIES 4 | |
34 | ||
35 | ||
36 | const struct mesh_config default_mesh_config = { | |
37 | .dot11MeshRetryTimeout = MESH_RET_T, | |
38 | .dot11MeshConfirmTimeout = MESH_CONF_T, | |
39 | .dot11MeshHoldingTimeout = MESH_HOLD_T, | |
40 | .dot11MeshMaxRetries = MESH_MAX_RETR, | |
41 | .dot11MeshTTL = MESH_TTL, | |
42 | .element_ttl = MESH_DEFAULT_ELEMENT_TTL, | |
43 | .auto_open_plinks = true, | |
44 | .dot11MeshMaxPeerLinks = MESH_MAX_ESTAB_PLINKS, | |
45 | .dot11MeshHWMPactivePathTimeout = MESH_PATH_TIMEOUT, | |
46 | .dot11MeshHWMPpreqMinInterval = MESH_PREQ_MIN_INT, | |
47 | .dot11MeshHWMPnetDiameterTraversalTime = MESH_DIAM_TRAVERSAL_TIME, | |
48 | .dot11MeshHWMPmaxPREQretries = MESH_MAX_PREQ_RETRIES, | |
49 | .path_refresh_time = MESH_PATH_REFRESH_TIME, | |
50 | .min_discovery_timeout = MESH_MIN_DISCOVERY_TIMEOUT, | |
51 | }; | |
52 | ||
c80d545d JC |
53 | const struct mesh_setup default_mesh_setup = { |
54 | .path_sel_proto = IEEE80211_PATH_PROTOCOL_HWMP, | |
55 | .path_metric = IEEE80211_PATH_METRIC_AIRTIME, | |
581a8b0f JC |
56 | .ie = NULL, |
57 | .ie_len = 0, | |
5cff5e01 | 58 | .is_secure = false, |
c80d545d | 59 | }; |
29cbe68c JB |
60 | |
61 | int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev, | |
62 | struct net_device *dev, | |
c80d545d | 63 | const struct mesh_setup *setup, |
29cbe68c JB |
64 | const struct mesh_config *conf) |
65 | { | |
66 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
29cbe68c JB |
67 | int err; |
68 | ||
69 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != IEEE80211_MAX_MESH_ID_LEN); | |
70 | ||
71 | ASSERT_WDEV_LOCK(wdev); | |
72 | ||
73 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
74 | return -EOPNOTSUPP; | |
75 | ||
15d5dda6 JC |
76 | if (!(rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
77 | setup->is_secure) | |
78 | return -EOPNOTSUPP; | |
79 | ||
29cbe68c JB |
80 | if (wdev->mesh_id_len) |
81 | return -EALREADY; | |
82 | ||
c80d545d | 83 | if (!setup->mesh_id_len) |
29cbe68c JB |
84 | return -EINVAL; |
85 | ||
86 | if (!rdev->ops->join_mesh) | |
87 | return -EOPNOTSUPP; | |
88 | ||
c80d545d | 89 | err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, setup); |
29cbe68c | 90 | if (!err) { |
c80d545d JC |
91 | memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len); |
92 | wdev->mesh_id_len = setup->mesh_id_len; | |
29cbe68c JB |
93 | } |
94 | ||
95 | return err; | |
96 | } | |
97 | ||
98 | int cfg80211_join_mesh(struct cfg80211_registered_device *rdev, | |
99 | struct net_device *dev, | |
c80d545d | 100 | const struct mesh_setup *setup, |
29cbe68c JB |
101 | const struct mesh_config *conf) |
102 | { | |
103 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
104 | int err; | |
105 | ||
106 | wdev_lock(wdev); | |
c80d545d | 107 | err = __cfg80211_join_mesh(rdev, dev, setup, conf); |
29cbe68c JB |
108 | wdev_unlock(wdev); |
109 | ||
110 | return err; | |
111 | } | |
112 | ||
113 | static int __cfg80211_leave_mesh(struct cfg80211_registered_device *rdev, | |
114 | struct net_device *dev) | |
115 | { | |
116 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
117 | int err; | |
118 | ||
119 | ASSERT_WDEV_LOCK(wdev); | |
120 | ||
121 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
122 | return -EOPNOTSUPP; | |
123 | ||
124 | if (!rdev->ops->leave_mesh) | |
125 | return -EOPNOTSUPP; | |
126 | ||
127 | if (!wdev->mesh_id_len) | |
128 | return -ENOTCONN; | |
129 | ||
130 | err = rdev->ops->leave_mesh(&rdev->wiphy, dev); | |
131 | if (!err) | |
132 | wdev->mesh_id_len = 0; | |
133 | return err; | |
134 | } | |
135 | ||
136 | int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev, | |
137 | struct net_device *dev) | |
138 | { | |
139 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
140 | int err; | |
141 | ||
142 | wdev_lock(wdev); | |
143 | err = __cfg80211_leave_mesh(rdev, dev); | |
144 | wdev_unlock(wdev); | |
145 | ||
146 | return err; | |
147 | } |