blob: 71fe609612303a2d9d6fc11e263845df26438256 [file] [log] [blame]
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001/*
2 * Copyright (c) 2008 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include "mesh.h"
11
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010012#define TEST_FRAME_LEN 8192
13#define MAX_METRIC 0xffffffff
14#define ARITH_SHIFT 8
15
16/* Number of frames buffered per destination for unresolved destinations */
17#define MESH_FRAME_QUEUE_LEN 10
18#define MAX_PREQ_QUEUE_LEN 64
19
20/* Destination only */
21#define MP_F_DO 0x1
22/* Reply and forward */
23#define MP_F_RF 0x2
24
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080025static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
26{
27 if (ae)
28 offset += 6;
Harvey Harrisonae7245c2008-05-01 22:19:33 -070029 return get_unaligned_le32(preq_elem + offset);
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080030}
31
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010032/* HWMP IE processing macros */
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080033#define AE_F (1<<6)
34#define AE_F_SET(x) (*x & AE_F)
35#define PREQ_IE_FLAGS(x) (*(x))
36#define PREQ_IE_HOPCOUNT(x) (*(x + 1))
37#define PREQ_IE_TTL(x) (*(x + 2))
38#define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0)
39#define PREQ_IE_ORIG_ADDR(x) (x + 7)
40#define PREQ_IE_ORIG_DSN(x) u32_field_get(x, 13, 0);
41#define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x));
42#define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x));
43#define PREQ_IE_DST_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26))
44#define PREQ_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27)
45#define PREQ_IE_DST_DSN(x) u32_field_get(x, 33, AE_F_SET(x));
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010046
47
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080048#define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x)
49#define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x)
50#define PREP_IE_TTL(x) PREQ_IE_TTL(x)
51#define PREP_IE_ORIG_ADDR(x) (x + 3)
52#define PREP_IE_ORIG_DSN(x) u32_field_get(x, 9, 0);
53#define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x));
54#define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x));
55#define PREP_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21)
56#define PREP_IE_DST_DSN(x) u32_field_get(x, 27, AE_F_SET(x));
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010057
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080058#define PERR_IE_DST_ADDR(x) (x + 2)
59#define PERR_IE_DST_DSN(x) u32_field_get(x, 8, 0);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010060
61#define TU_TO_EXP_TIME(x) (jiffies + msecs_to_jiffies(x * 1024 / 1000))
62#define MSEC_TO_TU(x) (x*1000/1024)
63#define DSN_GT(x, y) ((long) (y) - (long) (x) < 0)
64#define DSN_LT(x, y) ((long) (x) - (long) (y) < 0)
65
66#define net_traversal_jiffies(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020067 msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010068#define default_lifetime(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020069 MSEC_TO_TU(s->u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010070#define min_preq_int_jiff(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020071 (msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval))
72#define max_preq_retries(s) (s->u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010073#define disc_timeout_jiff(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020074 msecs_to_jiffies(sdata->u.mesh.mshcfg.min_discovery_timeout)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010075
76enum mpath_frame_type {
77 MPATH_PREQ = 0,
78 MPATH_PREP,
79 MPATH_PERR
80};
81
82static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
83 u8 *orig_addr, __le32 orig_dsn, u8 dst_flags, u8 *dst,
84 __le32 dst_dsn, u8 *da, u8 hop_count, u8 ttl, __le32 lifetime,
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120085 __le32 metric, __le32 preq_id, struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010086{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120087 struct ieee80211_local *local = sdata->local;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010088 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
89 struct ieee80211_mgmt *mgmt;
90 u8 *pos;
91 int ie_len;
92
93 if (!skb)
94 return -1;
95 skb_reserve(skb, local->hw.extra_tx_headroom);
96 /* 25 is the size of the common mgmt part (24) plus the size of the
97 * common action part (1)
98 */
99 mgmt = (struct ieee80211_mgmt *)
100 skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action));
101 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action));
Harvey Harrisone7827a72008-07-15 18:44:13 -0700102 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
103 IEEE80211_STYPE_ACTION);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100104
105 memcpy(mgmt->da, da, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200106 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100107 /* BSSID is left zeroed, wildcard value */
108 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
109 mgmt->u.action.u.mesh_action.action_code = action;
110
111 switch (action) {
112 case MPATH_PREQ:
113 ie_len = 37;
114 pos = skb_put(skb, 2 + ie_len);
115 *pos++ = WLAN_EID_PREQ;
116 break;
117 case MPATH_PREP:
118 ie_len = 31;
119 pos = skb_put(skb, 2 + ie_len);
120 *pos++ = WLAN_EID_PREP;
121 break;
122 default:
Patrick McHardy812714d2008-05-06 12:52:07 +0200123 kfree_skb(skb);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100124 return -ENOTSUPP;
125 break;
126 }
127 *pos++ = ie_len;
128 *pos++ = flags;
129 *pos++ = hop_count;
130 *pos++ = ttl;
131 if (action == MPATH_PREQ) {
132 memcpy(pos, &preq_id, 4);
133 pos += 4;
134 }
135 memcpy(pos, orig_addr, ETH_ALEN);
136 pos += ETH_ALEN;
137 memcpy(pos, &orig_dsn, 4);
138 pos += 4;
139 memcpy(pos, &lifetime, 4);
140 pos += 4;
141 memcpy(pos, &metric, 4);
142 pos += 4;
143 if (action == MPATH_PREQ) {
144 /* destination count */
145 *pos++ = 1;
146 *pos++ = dst_flags;
147 }
148 memcpy(pos, dst, ETH_ALEN);
149 pos += ETH_ALEN;
150 memcpy(pos, &dst_dsn, 4);
151
Johannes Berge50db652008-09-09 15:07:09 +0200152 ieee80211_tx_skb(sdata, skb, 0);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100153 return 0;
154}
155
156/**
157 * mesh_send_path error - Sends a PERR mesh management frame
158 *
159 * @dst: broken destination
160 * @dst_dsn: dsn of the broken destination
161 * @ra: node this frame is addressed to
162 */
163int mesh_path_error_tx(u8 *dst, __le32 dst_dsn, u8 *ra,
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200164 struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100165{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200166 struct ieee80211_local *local = sdata->local;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100167 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
168 struct ieee80211_mgmt *mgmt;
169 u8 *pos;
170 int ie_len;
171
172 if (!skb)
173 return -1;
174 skb_reserve(skb, local->hw.extra_tx_headroom);
175 /* 25 is the size of the common mgmt part (24) plus the size of the
176 * common action part (1)
177 */
178 mgmt = (struct ieee80211_mgmt *)
179 skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action));
180 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action));
Harvey Harrisone7827a72008-07-15 18:44:13 -0700181 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
182 IEEE80211_STYPE_ACTION);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100183
184 memcpy(mgmt->da, ra, ETH_ALEN);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200185 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100186 /* BSSID is left zeroed, wildcard value */
187 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
188 mgmt->u.action.u.mesh_action.action_code = MPATH_PERR;
189 ie_len = 12;
190 pos = skb_put(skb, 2 + ie_len);
191 *pos++ = WLAN_EID_PERR;
192 *pos++ = ie_len;
193 /* mode flags, reserved */
194 *pos++ = 0;
195 /* number of destinations */
196 *pos++ = 1;
197 memcpy(pos, dst, ETH_ALEN);
198 pos += ETH_ALEN;
199 memcpy(pos, &dst_dsn, 4);
200
Johannes Berge50db652008-09-09 15:07:09 +0200201 ieee80211_tx_skb(sdata, skb, 0);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100202 return 0;
203}
204
205static u32 airtime_link_metric_get(struct ieee80211_local *local,
206 struct sta_info *sta)
207{
208 struct ieee80211_supported_band *sband;
209 /* This should be adjusted for each device */
210 int device_constant = 1 << ARITH_SHIFT;
211 int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT;
212 int s_unit = 1 << ARITH_SHIFT;
213 int rate, err;
214 u32 tx_time, estimated_retx;
215 u64 result;
216
217 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
218
219 if (sta->fail_avg >= 100)
220 return MAX_METRIC;
Johannes Berge6a98542008-10-21 12:40:02 +0200221
222 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
223 return MAX_METRIC;
224
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100225 err = (sta->fail_avg << ARITH_SHIFT) / 100;
226
227 /* bitrate is in units of 100 Kbps, while we need rate in units of
228 * 1Mbps. This will be corrected on tx_time computation.
229 */
Johannes Berge6a98542008-10-21 12:40:02 +0200230 rate = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100231 tx_time = (device_constant + 10 * test_frame_len / rate);
232 estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
233 result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
234 return (u32)result;
235}
236
237/**
238 * hwmp_route_info_get - Update routing info to originator and transmitter
239 *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200240 * @sdata: local mesh subif
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100241 * @mgmt: mesh management frame
242 * @hwmp_ie: hwmp information element (PREP or PREQ)
243 *
244 * This function updates the path routing information to the originator and the
245 * transmitter of a HWMP PREQ or PREP fram.
246 *
247 * Returns: metric to frame originator or 0 if the frame should not be further
248 * processed
249 *
250 * Notes: this function is the only place (besides user-provided info) where
251 * path routing information is updated.
252 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200253static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100254 struct ieee80211_mgmt *mgmt,
255 u8 *hwmp_ie)
256{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200257 struct ieee80211_local *local = sdata->local;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100258 struct mesh_path *mpath;
259 struct sta_info *sta;
260 bool fresh_info;
261 u8 *orig_addr, *ta;
262 u32 orig_dsn, orig_metric;
263 unsigned long orig_lifetime, exp_time;
264 u32 last_hop_metric, new_metric;
265 bool process = true;
266 u8 action = mgmt->u.action.u.mesh_action.action_code;
267
268 rcu_read_lock();
269 sta = sta_info_get(local, mgmt->sa);
Johannes Bergdc0b0f72008-02-23 15:17:20 +0100270 if (!sta) {
271 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100272 return 0;
Johannes Bergdc0b0f72008-02-23 15:17:20 +0100273 }
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100274
275 last_hop_metric = airtime_link_metric_get(local, sta);
276 /* Update and check originator routing info */
277 fresh_info = true;
278
279 switch (action) {
280 case MPATH_PREQ:
281 orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie);
282 orig_dsn = PREQ_IE_ORIG_DSN(hwmp_ie);
283 orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
284 orig_metric = PREQ_IE_METRIC(hwmp_ie);
285 break;
286 case MPATH_PREP:
287 /* Originator here refers to the MP that was the destination in
288 * the Path Request. The draft refers to that MP as the
289 * destination address, even though usually it is the origin of
290 * the PREP frame. We divert from the nomenclature in the draft
291 * so that we can easily use a single function to gather path
292 * information from both PREQ and PREP frames.
293 */
294 orig_addr = PREP_IE_ORIG_ADDR(hwmp_ie);
295 orig_dsn = PREP_IE_ORIG_DSN(hwmp_ie);
296 orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
297 orig_metric = PREP_IE_METRIC(hwmp_ie);
298 break;
299 default:
Johannes Bergdc0b0f72008-02-23 15:17:20 +0100300 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100301 return 0;
302 }
303 new_metric = orig_metric + last_hop_metric;
304 if (new_metric < orig_metric)
305 new_metric = MAX_METRIC;
306 exp_time = TU_TO_EXP_TIME(orig_lifetime);
307
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200308 if (memcmp(orig_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100309 /* This MP is the originator, we are not interested in this
310 * frame, except for updating transmitter's path info.
311 */
312 process = false;
313 fresh_info = false;
314 } else {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200315 mpath = mesh_path_lookup(orig_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100316 if (mpath) {
317 spin_lock_bh(&mpath->state_lock);
318 if (mpath->flags & MESH_PATH_FIXED)
319 fresh_info = false;
320 else if ((mpath->flags & MESH_PATH_ACTIVE) &&
321 (mpath->flags & MESH_PATH_DSN_VALID)) {
322 if (DSN_GT(mpath->dsn, orig_dsn) ||
323 (mpath->dsn == orig_dsn &&
324 action == MPATH_PREQ &&
325 new_metric > mpath->metric)) {
326 process = false;
327 fresh_info = false;
328 }
329 }
330 } else {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200331 mesh_path_add(orig_addr, sdata);
332 mpath = mesh_path_lookup(orig_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100333 if (!mpath) {
334 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100335 return 0;
336 }
337 spin_lock_bh(&mpath->state_lock);
338 }
339
340 if (fresh_info) {
341 mesh_path_assign_nexthop(mpath, sta);
342 mpath->flags |= MESH_PATH_DSN_VALID;
343 mpath->metric = new_metric;
344 mpath->dsn = orig_dsn;
345 mpath->exp_time = time_after(mpath->exp_time, exp_time)
346 ? mpath->exp_time : exp_time;
347 mesh_path_activate(mpath);
348 spin_unlock_bh(&mpath->state_lock);
349 mesh_path_tx_pending(mpath);
350 /* draft says preq_id should be saved to, but there does
351 * not seem to be any use for it, skipping by now
352 */
353 } else
354 spin_unlock_bh(&mpath->state_lock);
355 }
356
357 /* Update and check transmitter routing info */
358 ta = mgmt->sa;
359 if (memcmp(orig_addr, ta, ETH_ALEN) == 0)
360 fresh_info = false;
361 else {
362 fresh_info = true;
363
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200364 mpath = mesh_path_lookup(ta, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100365 if (mpath) {
366 spin_lock_bh(&mpath->state_lock);
367 if ((mpath->flags & MESH_PATH_FIXED) ||
368 ((mpath->flags & MESH_PATH_ACTIVE) &&
369 (last_hop_metric > mpath->metric)))
370 fresh_info = false;
371 } else {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200372 mesh_path_add(ta, sdata);
373 mpath = mesh_path_lookup(ta, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100374 if (!mpath) {
375 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100376 return 0;
377 }
378 spin_lock_bh(&mpath->state_lock);
379 }
380
381 if (fresh_info) {
382 mesh_path_assign_nexthop(mpath, sta);
383 mpath->flags &= ~MESH_PATH_DSN_VALID;
384 mpath->metric = last_hop_metric;
385 mpath->exp_time = time_after(mpath->exp_time, exp_time)
386 ? mpath->exp_time : exp_time;
387 mesh_path_activate(mpath);
388 spin_unlock_bh(&mpath->state_lock);
389 mesh_path_tx_pending(mpath);
390 } else
391 spin_unlock_bh(&mpath->state_lock);
392 }
393
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100394 rcu_read_unlock();
395
396 return process ? new_metric : 0;
397}
398
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200399static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100400 struct ieee80211_mgmt *mgmt,
401 u8 *preq_elem, u32 metric) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200402 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100403 struct mesh_path *mpath;
404 u8 *dst_addr, *orig_addr;
405 u8 dst_flags, ttl;
406 u32 orig_dsn, dst_dsn, lifetime;
407 bool reply = false;
408 bool forward = true;
409
410 /* Update destination DSN, if present */
411 dst_addr = PREQ_IE_DST_ADDR(preq_elem);
412 orig_addr = PREQ_IE_ORIG_ADDR(preq_elem);
413 dst_dsn = PREQ_IE_DST_DSN(preq_elem);
414 orig_dsn = PREQ_IE_ORIG_DSN(preq_elem);
415 dst_flags = PREQ_IE_DST_F(preq_elem);
416
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200417 if (memcmp(dst_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100418 forward = false;
419 reply = true;
420 metric = 0;
Johannes Berg472dbc42008-09-11 00:01:49 +0200421 if (time_after(jiffies, ifmsh->last_dsn_update +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100422 net_traversal_jiffies(sdata)) ||
Johannes Berg472dbc42008-09-11 00:01:49 +0200423 time_before(jiffies, ifmsh->last_dsn_update)) {
424 dst_dsn = ++ifmsh->dsn;
425 ifmsh->last_dsn_update = jiffies;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100426 }
427 } else {
428 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200429 mpath = mesh_path_lookup(dst_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100430 if (mpath) {
431 if ((!(mpath->flags & MESH_PATH_DSN_VALID)) ||
432 DSN_LT(mpath->dsn, dst_dsn)) {
433 mpath->dsn = dst_dsn;
434 mpath->flags &= MESH_PATH_DSN_VALID;
435 } else if ((!(dst_flags & MP_F_DO)) &&
436 (mpath->flags & MESH_PATH_ACTIVE)) {
437 reply = true;
438 metric = mpath->metric;
439 dst_dsn = mpath->dsn;
440 if (dst_flags & MP_F_RF)
441 dst_flags |= MP_F_DO;
442 else
443 forward = false;
444 }
445 }
446 rcu_read_unlock();
447 }
448
449 if (reply) {
450 lifetime = PREQ_IE_LIFETIME(preq_elem);
Johannes Berg472dbc42008-09-11 00:01:49 +0200451 ttl = ifmsh->mshcfg.dot11MeshTTL;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100452 if (ttl != 0)
453 mesh_path_sel_frame_tx(MPATH_PREP, 0, dst_addr,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800454 cpu_to_le32(dst_dsn), 0, orig_addr,
455 cpu_to_le32(orig_dsn), mgmt->sa, 0, ttl,
456 cpu_to_le32(lifetime), cpu_to_le32(metric),
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200457 0, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100458 else
Johannes Berg472dbc42008-09-11 00:01:49 +0200459 ifmsh->mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100460 }
461
462 if (forward) {
463 u32 preq_id;
464 u8 hopcount, flags;
465
466 ttl = PREQ_IE_TTL(preq_elem);
467 lifetime = PREQ_IE_LIFETIME(preq_elem);
468 if (ttl <= 1) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200469 ifmsh->mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100470 return;
471 }
472 --ttl;
473 flags = PREQ_IE_FLAGS(preq_elem);
474 preq_id = PREQ_IE_PREQ_ID(preq_elem);
475 hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1;
476 mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800477 cpu_to_le32(orig_dsn), dst_flags, dst_addr,
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200478 cpu_to_le32(dst_dsn), sdata->dev->broadcast,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800479 hopcount, ttl, cpu_to_le32(lifetime),
480 cpu_to_le32(metric), cpu_to_le32(preq_id),
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200481 sdata);
Johannes Berg472dbc42008-09-11 00:01:49 +0200482 ifmsh->mshstats.fwded_frames++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100483 }
484}
485
486
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200487static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100488 struct ieee80211_mgmt *mgmt,
489 u8 *prep_elem, u32 metric)
490{
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100491 struct mesh_path *mpath;
492 u8 *dst_addr, *orig_addr;
493 u8 ttl, hopcount, flags;
494 u8 next_hop[ETH_ALEN];
495 u32 dst_dsn, orig_dsn, lifetime;
496
497 /* Note that we divert from the draft nomenclature and denominate
498 * destination to what the draft refers to as origininator. So in this
499 * function destnation refers to the final destination of the PREP,
500 * which corresponds with the originator of the PREQ which this PREP
501 * replies
502 */
503 dst_addr = PREP_IE_DST_ADDR(prep_elem);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200504 if (memcmp(dst_addr, sdata->dev->dev_addr, ETH_ALEN) == 0)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100505 /* destination, no forwarding required */
506 return;
507
508 ttl = PREP_IE_TTL(prep_elem);
509 if (ttl <= 1) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200510 sdata->u.mesh.mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100511 return;
512 }
513
514 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200515 mpath = mesh_path_lookup(dst_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100516 if (mpath)
517 spin_lock_bh(&mpath->state_lock);
518 else
519 goto fail;
520 if (!(mpath->flags & MESH_PATH_ACTIVE)) {
521 spin_unlock_bh(&mpath->state_lock);
522 goto fail;
523 }
Johannes Berg17741cd2008-09-11 00:02:02 +0200524 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100525 spin_unlock_bh(&mpath->state_lock);
526 --ttl;
527 flags = PREP_IE_FLAGS(prep_elem);
528 lifetime = PREP_IE_LIFETIME(prep_elem);
529 hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1;
530 orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
531 dst_dsn = PREP_IE_DST_DSN(prep_elem);
532 orig_dsn = PREP_IE_ORIG_DSN(prep_elem);
533
534 mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800535 cpu_to_le32(orig_dsn), 0, dst_addr,
Johannes Berg17741cd2008-09-11 00:02:02 +0200536 cpu_to_le32(dst_dsn), mpath->next_hop->sta.addr, hopcount, ttl,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800537 cpu_to_le32(lifetime), cpu_to_le32(metric),
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200538 0, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100539 rcu_read_unlock();
Johannes Berg472dbc42008-09-11 00:01:49 +0200540 sdata->u.mesh.mshstats.fwded_frames++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100541 return;
542
543fail:
544 rcu_read_unlock();
Johannes Berg472dbc42008-09-11 00:01:49 +0200545 sdata->u.mesh.mshstats.dropped_frames_no_route++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100546 return;
547}
548
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200549static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100550 struct ieee80211_mgmt *mgmt, u8 *perr_elem)
551{
552 struct mesh_path *mpath;
553 u8 *ta, *dst_addr;
554 u32 dst_dsn;
555
556 ta = mgmt->sa;
557 dst_addr = PERR_IE_DST_ADDR(perr_elem);
558 dst_dsn = PERR_IE_DST_DSN(perr_elem);
559 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200560 mpath = mesh_path_lookup(dst_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100561 if (mpath) {
562 spin_lock_bh(&mpath->state_lock);
563 if (mpath->flags & MESH_PATH_ACTIVE &&
Johannes Berg17741cd2008-09-11 00:02:02 +0200564 memcmp(ta, mpath->next_hop->sta.addr, ETH_ALEN) == 0 &&
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100565 (!(mpath->flags & MESH_PATH_DSN_VALID) ||
566 DSN_GT(dst_dsn, mpath->dsn))) {
567 mpath->flags &= ~MESH_PATH_ACTIVE;
568 mpath->dsn = dst_dsn;
569 spin_unlock_bh(&mpath->state_lock);
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800570 mesh_path_error_tx(dst_addr, cpu_to_le32(dst_dsn),
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200571 sdata->dev->broadcast, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100572 } else
573 spin_unlock_bh(&mpath->state_lock);
574 }
575 rcu_read_unlock();
576}
577
578
579
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200580void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100581 struct ieee80211_mgmt *mgmt,
582 size_t len)
583{
584 struct ieee802_11_elems elems;
585 size_t baselen;
586 u32 last_hop_metric;
587
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200588 /* need action_code */
589 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
590 return;
591
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100592 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
593 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
594 len - baselen, &elems);
595
596 switch (mgmt->u.action.u.mesh_action.action_code) {
597 case MPATH_PREQ:
598 if (!elems.preq || elems.preq_len != 37)
599 /* Right now we support just 1 destination and no AE */
600 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200601 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.preq);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100602 if (!last_hop_metric)
603 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200604 hwmp_preq_frame_process(sdata, mgmt, elems.preq, last_hop_metric);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100605 break;
606 case MPATH_PREP:
607 if (!elems.prep || elems.prep_len != 31)
608 /* Right now we support no AE */
609 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200610 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.prep);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100611 if (!last_hop_metric)
612 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200613 hwmp_prep_frame_process(sdata, mgmt, elems.prep, last_hop_metric);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100614 break;
615 case MPATH_PERR:
616 if (!elems.perr || elems.perr_len != 12)
617 /* Right now we support only one destination per PERR */
618 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200619 hwmp_perr_frame_process(sdata, mgmt, elems.perr);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100620 default:
621 return;
622 }
623
624}
625
626/**
627 * mesh_queue_preq - queue a PREQ to a given destination
628 *
629 * @mpath: mesh path to discover
630 * @flags: special attributes of the PREQ to be sent
631 *
632 * Locking: the function must be called from within a rcu read lock block.
633 *
634 */
635static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
636{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200637 struct ieee80211_sub_if_data *sdata = mpath->sdata;
Johannes Berg472dbc42008-09-11 00:01:49 +0200638 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100639 struct mesh_preq_queue *preq_node;
640
641 preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_KERNEL);
642 if (!preq_node) {
643 printk(KERN_DEBUG "Mesh HWMP: could not allocate PREQ node\n");
644 return;
645 }
646
Johannes Berg472dbc42008-09-11 00:01:49 +0200647 spin_lock(&ifmsh->mesh_preq_queue_lock);
648 if (ifmsh->preq_queue_len == MAX_PREQ_QUEUE_LEN) {
649 spin_unlock(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100650 kfree(preq_node);
651 if (printk_ratelimit())
652 printk(KERN_DEBUG "Mesh HWMP: PREQ node queue full\n");
653 return;
654 }
655
656 memcpy(preq_node->dst, mpath->dst, ETH_ALEN);
657 preq_node->flags = flags;
658
Johannes Berg472dbc42008-09-11 00:01:49 +0200659 list_add_tail(&preq_node->list, &ifmsh->preq_queue.list);
660 ++ifmsh->preq_queue_len;
661 spin_unlock(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100662
Johannes Berg472dbc42008-09-11 00:01:49 +0200663 if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata)))
664 queue_work(sdata->local->hw.workqueue, &ifmsh->work);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100665
Johannes Berg472dbc42008-09-11 00:01:49 +0200666 else if (time_before(jiffies, ifmsh->last_preq)) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100667 /* avoid long wait if did not send preqs for a long time
668 * and jiffies wrapped around
669 */
Johannes Berg472dbc42008-09-11 00:01:49 +0200670 ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
671 queue_work(sdata->local->hw.workqueue, &ifmsh->work);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100672 } else
Johannes Berg472dbc42008-09-11 00:01:49 +0200673 mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100674 min_preq_int_jiff(sdata));
675}
676
677/**
678 * mesh_path_start_discovery - launch a path discovery from the PREQ queue
679 *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200680 * @sdata: local mesh subif
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100681 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200682void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100683{
Johannes Berg472dbc42008-09-11 00:01:49 +0200684 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100685 struct mesh_preq_queue *preq_node;
686 struct mesh_path *mpath;
687 u8 ttl, dst_flags;
688 u32 lifetime;
689
Johannes Berg472dbc42008-09-11 00:01:49 +0200690 spin_lock(&ifmsh->mesh_preq_queue_lock);
691 if (!ifmsh->preq_queue_len ||
692 time_before(jiffies, ifmsh->last_preq +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100693 min_preq_int_jiff(sdata))) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200694 spin_unlock(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100695 return;
696 }
697
Johannes Berg472dbc42008-09-11 00:01:49 +0200698 preq_node = list_first_entry(&ifmsh->preq_queue.list,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100699 struct mesh_preq_queue, list);
700 list_del(&preq_node->list);
Johannes Berg472dbc42008-09-11 00:01:49 +0200701 --ifmsh->preq_queue_len;
702 spin_unlock(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100703
704 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200705 mpath = mesh_path_lookup(preq_node->dst, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100706 if (!mpath)
707 goto enddiscovery;
708
709 spin_lock_bh(&mpath->state_lock);
710 if (preq_node->flags & PREQ_Q_F_START) {
711 if (mpath->flags & MESH_PATH_RESOLVING) {
712 spin_unlock_bh(&mpath->state_lock);
713 goto enddiscovery;
714 } else {
715 mpath->flags &= ~MESH_PATH_RESOLVED;
716 mpath->flags |= MESH_PATH_RESOLVING;
717 mpath->discovery_retries = 0;
718 mpath->discovery_timeout = disc_timeout_jiff(sdata);
719 }
720 } else if (!(mpath->flags & MESH_PATH_RESOLVING) ||
721 mpath->flags & MESH_PATH_RESOLVED) {
722 mpath->flags &= ~MESH_PATH_RESOLVING;
723 spin_unlock_bh(&mpath->state_lock);
724 goto enddiscovery;
725 }
726
Johannes Berg472dbc42008-09-11 00:01:49 +0200727 ifmsh->last_preq = jiffies;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100728
Johannes Berg472dbc42008-09-11 00:01:49 +0200729 if (time_after(jiffies, ifmsh->last_dsn_update +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100730 net_traversal_jiffies(sdata)) ||
Johannes Berg472dbc42008-09-11 00:01:49 +0200731 time_before(jiffies, ifmsh->last_dsn_update)) {
732 ++ifmsh->dsn;
733 sdata->u.mesh.last_dsn_update = jiffies;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100734 }
735 lifetime = default_lifetime(sdata);
Johannes Berg472dbc42008-09-11 00:01:49 +0200736 ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100737 if (ttl == 0) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200738 sdata->u.mesh.mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100739 spin_unlock_bh(&mpath->state_lock);
740 goto enddiscovery;
741 }
742
743 if (preq_node->flags & PREQ_Q_F_REFRESH)
744 dst_flags = MP_F_DO;
745 else
746 dst_flags = MP_F_RF;
747
748 spin_unlock_bh(&mpath->state_lock);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200749 mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->dev->dev_addr,
Johannes Berg472dbc42008-09-11 00:01:49 +0200750 cpu_to_le32(ifmsh->dsn), dst_flags, mpath->dst,
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200751 cpu_to_le32(mpath->dsn), sdata->dev->broadcast, 0,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800752 ttl, cpu_to_le32(lifetime), 0,
Johannes Berg472dbc42008-09-11 00:01:49 +0200753 cpu_to_le32(ifmsh->preq_id++), sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100754 mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
755
756enddiscovery:
757 rcu_read_unlock();
758 kfree(preq_node);
759}
760
761/**
762 * ieee80211s_lookup_nexthop - put the appropriate next hop on a mesh frame
763 *
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +0200764 * @skb: 802.11 frame to be sent
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200765 * @sdata: network subif the frame will be sent through
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100766 *
767 * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is
768 * found, the function will start a path discovery and queue the frame so it is
769 * sent when the path is resolved. This means the caller must not free the skb
770 * in this case.
771 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200772int mesh_nexthop_lookup(struct sk_buff *skb,
773 struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100774{
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100775 struct sk_buff *skb_to_free = NULL;
776 struct mesh_path *mpath;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +0200777 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
778 u8 *dst_addr = hdr->addr3;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100779 int err = 0;
780
781 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200782 mpath = mesh_path_lookup(dst_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100783
784 if (!mpath) {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200785 mesh_path_add(dst_addr, sdata);
786 mpath = mesh_path_lookup(dst_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100787 if (!mpath) {
788 dev_kfree_skb(skb);
Johannes Berg472dbc42008-09-11 00:01:49 +0200789 sdata->u.mesh.mshstats.dropped_frames_no_route++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100790 err = -ENOSPC;
791 goto endlookup;
792 }
793 }
794
795 if (mpath->flags & MESH_PATH_ACTIVE) {
796 if (time_after(jiffies, mpath->exp_time -
Johannes Berg472dbc42008-09-11 00:01:49 +0200797 msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time))
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200798 && !memcmp(sdata->dev->dev_addr, hdr->addr4,
799 ETH_ALEN)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100800 && !(mpath->flags & MESH_PATH_RESOLVING)
801 && !(mpath->flags & MESH_PATH_FIXED)) {
802 mesh_queue_preq(mpath,
803 PREQ_Q_F_START | PREQ_Q_F_REFRESH);
804 }
Johannes Berg17741cd2008-09-11 00:02:02 +0200805 memcpy(hdr->addr1, mpath->next_hop->sta.addr,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100806 ETH_ALEN);
807 } else {
808 if (!(mpath->flags & MESH_PATH_RESOLVING)) {
809 /* Start discovery only if it is not running yet */
810 mesh_queue_preq(mpath, PREQ_Q_F_START);
811 }
812
813 if (skb_queue_len(&mpath->frame_queue) >=
814 MESH_FRAME_QUEUE_LEN) {
815 skb_to_free = mpath->frame_queue.next;
816 skb_unlink(skb_to_free, &mpath->frame_queue);
817 }
818
819 skb_queue_tail(&mpath->frame_queue, skb);
820 if (skb_to_free)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200821 mesh_path_discard_frame(skb_to_free, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100822 err = -ENOENT;
823 }
824
825endlookup:
826 rcu_read_unlock();
827 return err;
828}
829
830void mesh_path_timer(unsigned long data)
831{
832 struct ieee80211_sub_if_data *sdata;
833 struct mesh_path *mpath;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100834
835 rcu_read_lock();
836 mpath = (struct mesh_path *) data;
837 mpath = rcu_dereference(mpath);
838 if (!mpath)
839 goto endmpathtimer;
840 spin_lock_bh(&mpath->state_lock);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200841 sdata = mpath->sdata;
Luis Carlos Cobocfa22c72008-02-29 15:04:13 -0800842 if (mpath->flags & MESH_PATH_RESOLVED ||
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100843 (!(mpath->flags & MESH_PATH_RESOLVING)))
844 mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);
845 else if (mpath->discovery_retries < max_preq_retries(sdata)) {
846 ++mpath->discovery_retries;
847 mpath->discovery_timeout *= 2;
848 mesh_queue_preq(mpath, 0);
849 } else {
850 mpath->flags = 0;
851 mpath->exp_time = jiffies;
852 mesh_path_flush_pending(mpath);
853 }
854
855 spin_unlock_bh(&mpath->state_lock);
856endmpathtimer:
857 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100858}