blob: 73e39c171ffb1a9d27bb011825ecc5cf8f83e24c [file] [log] [blame]
Johannes Berg29cbe682010-12-03 09:20:44 +01001#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
36const 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
Javier Cardonac80d5452010-12-16 17:37:49 -080053const struct mesh_setup default_mesh_setup = {
54 .path_sel_proto = IEEE80211_PATH_PROTOCOL_HWMP,
55 .path_metric = IEEE80211_PATH_METRIC_AIRTIME,
56 .vendor_ie = NULL,
57 .vendor_ie_len = 0,
58};
Johannes Berg29cbe682010-12-03 09:20:44 +010059
60int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
61 struct net_device *dev,
Javier Cardonac80d5452010-12-16 17:37:49 -080062 const struct mesh_setup *setup,
Johannes Berg29cbe682010-12-03 09:20:44 +010063 const struct mesh_config *conf)
64{
65 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg29cbe682010-12-03 09:20:44 +010066 int err;
67
68 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != IEEE80211_MAX_MESH_ID_LEN);
69
70 ASSERT_WDEV_LOCK(wdev);
71
72 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
73 return -EOPNOTSUPP;
74
75 if (wdev->mesh_id_len)
76 return -EALREADY;
77
Javier Cardonac80d5452010-12-16 17:37:49 -080078 if (!setup->mesh_id_len)
Johannes Berg29cbe682010-12-03 09:20:44 +010079 return -EINVAL;
80
81 if (!rdev->ops->join_mesh)
82 return -EOPNOTSUPP;
83
Javier Cardonac80d5452010-12-16 17:37:49 -080084 err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, setup);
Johannes Berg29cbe682010-12-03 09:20:44 +010085 if (!err) {
Javier Cardonac80d5452010-12-16 17:37:49 -080086 memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
87 wdev->mesh_id_len = setup->mesh_id_len;
Johannes Berg29cbe682010-12-03 09:20:44 +010088 }
89
90 return err;
91}
92
93int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
94 struct net_device *dev,
Javier Cardonac80d5452010-12-16 17:37:49 -080095 const struct mesh_setup *setup,
Johannes Berg29cbe682010-12-03 09:20:44 +010096 const struct mesh_config *conf)
97{
98 struct wireless_dev *wdev = dev->ieee80211_ptr;
99 int err;
100
101 wdev_lock(wdev);
Javier Cardonac80d5452010-12-16 17:37:49 -0800102 err = __cfg80211_join_mesh(rdev, dev, setup, conf);
Johannes Berg29cbe682010-12-03 09:20:44 +0100103 wdev_unlock(wdev);
104
105 return err;
106}
107
108static int __cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
109 struct net_device *dev)
110{
111 struct wireless_dev *wdev = dev->ieee80211_ptr;
112 int err;
113
114 ASSERT_WDEV_LOCK(wdev);
115
116 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
117 return -EOPNOTSUPP;
118
119 if (!rdev->ops->leave_mesh)
120 return -EOPNOTSUPP;
121
122 if (!wdev->mesh_id_len)
123 return -ENOTCONN;
124
125 err = rdev->ops->leave_mesh(&rdev->wiphy, dev);
126 if (!err)
127 wdev->mesh_id_len = 0;
128 return err;
129}
130
131int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
132 struct net_device *dev)
133{
134 struct wireless_dev *wdev = dev->ieee80211_ptr;
135 int err;
136
137 wdev_lock(wdev);
138 err = __cfg80211_leave_mesh(rdev, dev);
139 wdev_unlock(wdev);
140
141 return err;
142}