blob: 208ba35661f9c79f41e4ddd11728c9d1dc7f1df9 [file] [log] [blame]
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001/*
Rui Paulo264d9b72009-11-09 23:46:58 +00002 * Copyright (c) 2008, 2009 open80211s Ltd.
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01003 * 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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Javier Cardona2cca3972011-09-06 12:10:43 -070011#include "wme.h"
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010012#include "mesh.h"
13
Rui Paulo27db2e42009-11-09 23:46:45 +000014#ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG
Javier Cardona76468872011-08-09 16:45:04 -070015#define mhwmp_dbg(fmt, args...) \
16 printk(KERN_DEBUG "Mesh HWMP (%s): " fmt "\n", sdata->name, ##args)
Rui Paulo27db2e42009-11-09 23:46:45 +000017#else
18#define mhwmp_dbg(fmt, args...) do { (void)(0); } while (0)
19#endif
20
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010021#define TEST_FRAME_LEN 8192
22#define MAX_METRIC 0xffffffff
23#define ARITH_SHIFT 8
24
25/* Number of frames buffered per destination for unresolved destinations */
26#define MESH_FRAME_QUEUE_LEN 10
27#define MAX_PREQ_QUEUE_LEN 64
28
29/* Destination only */
30#define MP_F_DO 0x1
31/* Reply and forward */
32#define MP_F_RF 0x2
Rui Paulod611f062009-11-09 23:46:50 +000033/* Unknown Sequence Number */
34#define MP_F_USN 0x01
35/* Reason code Present */
36#define MP_F_RCODE 0x02
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010037
Rui Paulo90a5e162009-11-11 00:01:31 +000038static void mesh_queue_preq(struct mesh_path *, u8);
39
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080040static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
41{
42 if (ae)
43 offset += 6;
Harvey Harrisonae7245c2008-05-01 22:19:33 -070044 return get_unaligned_le32(preq_elem + offset);
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080045}
46
Rui Paulod611f062009-11-09 23:46:50 +000047static inline u32 u16_field_get(u8 *preq_elem, int offset, bool ae)
48{
49 if (ae)
50 offset += 6;
51 return get_unaligned_le16(preq_elem + offset);
52}
53
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010054/* HWMP IE processing macros */
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080055#define AE_F (1<<6)
56#define AE_F_SET(x) (*x & AE_F)
57#define PREQ_IE_FLAGS(x) (*(x))
58#define PREQ_IE_HOPCOUNT(x) (*(x + 1))
59#define PREQ_IE_TTL(x) (*(x + 2))
60#define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0)
61#define PREQ_IE_ORIG_ADDR(x) (x + 7)
Phil Carmody497888c2011-07-14 15:07:13 +030062#define PREQ_IE_ORIG_SN(x) u32_field_get(x, 13, 0)
63#define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x))
64#define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x))
Rui Paulod19b3bf2009-11-09 23:46:55 +000065#define PREQ_IE_TARGET_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26))
66#define PREQ_IE_TARGET_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27)
Phil Carmody497888c2011-07-14 15:07:13 +030067#define PREQ_IE_TARGET_SN(x) u32_field_get(x, 33, AE_F_SET(x))
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010068
69
Luis Carlos Coboa00de5d2008-02-29 17:07:54 -080070#define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x)
71#define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x)
72#define PREP_IE_TTL(x) PREQ_IE_TTL(x)
Thomas Pedersen25d49e42011-08-11 19:35:15 -070073#define PREP_IE_ORIG_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21)
74#define PREP_IE_ORIG_SN(x) u32_field_get(x, 27, AE_F_SET(x))
Phil Carmody497888c2011-07-14 15:07:13 +030075#define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x))
76#define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x))
Thomas Pedersen25d49e42011-08-11 19:35:15 -070077#define PREP_IE_TARGET_ADDR(x) (x + 3)
78#define PREP_IE_TARGET_SN(x) u32_field_get(x, 9, 0)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010079
Rui Paulod611f062009-11-09 23:46:50 +000080#define PERR_IE_TTL(x) (*(x))
Rui Paulod19b3bf2009-11-09 23:46:55 +000081#define PERR_IE_TARGET_FLAGS(x) (*(x + 2))
82#define PERR_IE_TARGET_ADDR(x) (x + 3)
Phil Carmody497888c2011-07-14 15:07:13 +030083#define PERR_IE_TARGET_SN(x) u32_field_get(x, 9, 0)
84#define PERR_IE_TARGET_RCODE(x) u16_field_get(x, 13, 0)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010085
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010086#define MSEC_TO_TU(x) (x*1000/1024)
Rui Paulod19b3bf2009-11-09 23:46:55 +000087#define SN_GT(x, y) ((long) (y) - (long) (x) < 0)
88#define SN_LT(x, y) ((long) (x) - (long) (y) < 0)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010089
90#define net_traversal_jiffies(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020091 msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010092#define default_lifetime(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020093 MSEC_TO_TU(s->u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010094#define min_preq_int_jiff(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020095 (msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval))
96#define max_preq_retries(s) (s->u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010097#define disc_timeout_jiff(s) \
Johannes Berg472dbc42008-09-11 00:01:49 +020098 msecs_to_jiffies(sdata->u.mesh.mshcfg.min_discovery_timeout)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +010099
100enum mpath_frame_type {
101 MPATH_PREQ = 0,
102 MPATH_PREP,
Rui Paulo90a5e162009-11-11 00:01:31 +0000103 MPATH_PERR,
104 MPATH_RANN
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100105};
106
Johannes Berg15ff6362009-11-17 13:34:04 +0100107static const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
108
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100109static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
Rui Paulod19b3bf2009-11-09 23:46:55 +0000110 u8 *orig_addr, __le32 orig_sn, u8 target_flags, u8 *target,
Johannes Berg15ff6362009-11-17 13:34:04 +0100111 __le32 target_sn, const u8 *da, u8 hop_count, u8 ttl,
112 __le32 lifetime, __le32 metric, __le32 preq_id,
Rui Paulod19b3bf2009-11-09 23:46:55 +0000113 struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100114{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200115 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700116 struct sk_buff *skb;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100117 struct ieee80211_mgmt *mgmt;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700118 u8 *pos, ie_len;
119 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.mesh_action) +
120 sizeof(mgmt->u.action.u.mesh_action);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100121
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700122 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
123 hdr_len +
124 2 + 37); /* max HWMP IE */
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100125 if (!skb)
126 return -1;
127 skb_reserve(skb, local->hw.extra_tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700128 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
129 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700130 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
131 IEEE80211_STYPE_ACTION);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100132
133 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100134 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Rui Paulo90a5e162009-11-11 00:01:31 +0000135 /* BSSID == SA */
Johannes Berg47846c92009-11-25 17:46:19 +0100136 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen25d49e42011-08-11 19:35:15 -0700137 mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
138 mgmt->u.action.u.mesh_action.action_code =
139 WLAN_MESH_ACTION_HWMP_PATH_SELECTION;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100140
141 switch (action) {
142 case MPATH_PREQ:
Javier Cardona76468872011-08-09 16:45:04 -0700143 mhwmp_dbg("sending PREQ to %pM", target);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100144 ie_len = 37;
145 pos = skb_put(skb, 2 + ie_len);
146 *pos++ = WLAN_EID_PREQ;
147 break;
148 case MPATH_PREP:
Javier Cardona76468872011-08-09 16:45:04 -0700149 mhwmp_dbg("sending PREP to %pM", target);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100150 ie_len = 31;
151 pos = skb_put(skb, 2 + ie_len);
152 *pos++ = WLAN_EID_PREP;
153 break;
Rui Paulo90a5e162009-11-11 00:01:31 +0000154 case MPATH_RANN:
Javier Cardona76468872011-08-09 16:45:04 -0700155 mhwmp_dbg("sending RANN from %pM", orig_addr);
Rui Paulo90a5e162009-11-11 00:01:31 +0000156 ie_len = sizeof(struct ieee80211_rann_ie);
157 pos = skb_put(skb, 2 + ie_len);
158 *pos++ = WLAN_EID_RANN;
159 break;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100160 default:
Patrick McHardy812714d2008-05-06 12:52:07 +0200161 kfree_skb(skb);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100162 return -ENOTSUPP;
163 break;
164 }
165 *pos++ = ie_len;
166 *pos++ = flags;
167 *pos++ = hop_count;
168 *pos++ = ttl;
Thomas Pedersen25d49e42011-08-11 19:35:15 -0700169 if (action == MPATH_PREP) {
Rui Paulod19b3bf2009-11-09 23:46:55 +0000170 memcpy(pos, target, ETH_ALEN);
Rui Paulo90a5e162009-11-11 00:01:31 +0000171 pos += ETH_ALEN;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000172 memcpy(pos, &target_sn, 4);
Thomas Pedersen25d49e42011-08-11 19:35:15 -0700173 pos += 4;
174 } else {
175 if (action == MPATH_PREQ) {
176 memcpy(pos, &preq_id, 4);
177 pos += 4;
178 }
179 memcpy(pos, orig_addr, ETH_ALEN);
180 pos += ETH_ALEN;
181 memcpy(pos, &orig_sn, 4);
182 pos += 4;
183 }
184 memcpy(pos, &lifetime, 4); /* interval for RANN */
185 pos += 4;
186 memcpy(pos, &metric, 4);
187 pos += 4;
188 if (action == MPATH_PREQ) {
189 *pos++ = 1; /* destination count */
190 *pos++ = target_flags;
191 memcpy(pos, target, ETH_ALEN);
192 pos += ETH_ALEN;
193 memcpy(pos, &target_sn, 4);
194 pos += 4;
195 } else if (action == MPATH_PREP) {
196 memcpy(pos, orig_addr, ETH_ALEN);
197 pos += ETH_ALEN;
198 memcpy(pos, &orig_sn, 4);
199 pos += 4;
Rui Paulo90a5e162009-11-11 00:01:31 +0000200 }
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100201
Johannes Berg62ae67b2009-11-18 18:42:05 +0100202 ieee80211_tx_skb(sdata, skb);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100203 return 0;
204}
205
Javier Cardona2cca3972011-09-06 12:10:43 -0700206
207/* Headroom is not adjusted. Caller should ensure that skb has sufficient
208 * headroom in case the frame is encrypted. */
209static void prepare_frame_for_deferred_tx(struct ieee80211_sub_if_data *sdata,
210 struct sk_buff *skb)
211{
Javier Cardona2cca3972011-09-06 12:10:43 -0700212 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
213
214 skb_set_mac_header(skb, 0);
215 skb_set_network_header(skb, 0);
216 skb_set_transport_header(skb, 0);
217
218 /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */
219 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
220 skb->priority = 7;
221
222 info->control.vif = &sdata->vif;
Javier Cardona2154c81c2011-09-07 17:49:53 -0700223 ieee80211_set_qos_hdr(sdata, skb);
Javier Cardona2cca3972011-09-06 12:10:43 -0700224}
225
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100226/**
227 * mesh_send_path error - Sends a PERR mesh management frame
228 *
Rui Paulod19b3bf2009-11-09 23:46:55 +0000229 * @target: broken destination
230 * @target_sn: SN of the broken destination
231 * @target_rcode: reason code for this PERR
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100232 * @ra: node this frame is addressed to
Javier Cardona2cca3972011-09-06 12:10:43 -0700233 *
234 * Note: This function may be called with driver locks taken that the driver
235 * also acquires in the TX path. To avoid a deadlock we don't transmit the
236 * frame directly but add it to the pending queue instead.
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100237 */
Rui Paulod19b3bf2009-11-09 23:46:55 +0000238int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn,
Johannes Berg15ff6362009-11-17 13:34:04 +0100239 __le16 target_rcode, const u8 *ra,
240 struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100241{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200242 struct ieee80211_local *local = sdata->local;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700243 struct sk_buff *skb;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100244 struct ieee80211_mgmt *mgmt;
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700245 u8 *pos, ie_len;
246 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.mesh_action) +
247 sizeof(mgmt->u.action.u.mesh_action);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100248
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700249 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
250 hdr_len +
251 2 + 15 /* PERR IE */);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100252 if (!skb)
253 return -1;
Javier Cardona2cca3972011-09-06 12:10:43 -0700254 skb_reserve(skb, local->tx_headroom + local->hw.extra_tx_headroom);
Thomas Pedersen3b69a9c2011-10-26 14:47:25 -0700255 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
256 memset(mgmt, 0, hdr_len);
Harvey Harrisone7827a72008-07-15 18:44:13 -0700257 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
258 IEEE80211_STYPE_ACTION);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100259
260 memcpy(mgmt->da, ra, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100261 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Thomas Pedersen25d49e42011-08-11 19:35:15 -0700262 /* BSSID == SA */
263 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
264 mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION;
265 mgmt->u.action.u.mesh_action.action_code =
266 WLAN_MESH_ACTION_HWMP_PATH_SELECTION;
Rui Paulod611f062009-11-09 23:46:50 +0000267 ie_len = 15;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100268 pos = skb_put(skb, 2 + ie_len);
269 *pos++ = WLAN_EID_PERR;
270 *pos++ = ie_len;
Rui Paulod611f062009-11-09 23:46:50 +0000271 /* ttl */
Javier Cardona45904f22010-12-03 09:20:40 +0100272 *pos++ = ttl;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100273 /* number of destinations */
274 *pos++ = 1;
Rui Paulod611f062009-11-09 23:46:50 +0000275 /*
276 * flags bit, bit 1 is unset if we know the sequence number and
277 * bit 2 is set if we have a reason code
278 */
279 *pos = 0;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000280 if (!target_sn)
Rui Paulod611f062009-11-09 23:46:50 +0000281 *pos |= MP_F_USN;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000282 if (target_rcode)
Rui Paulod611f062009-11-09 23:46:50 +0000283 *pos |= MP_F_RCODE;
284 pos++;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000285 memcpy(pos, target, ETH_ALEN);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100286 pos += ETH_ALEN;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000287 memcpy(pos, &target_sn, 4);
Rui Paulod611f062009-11-09 23:46:50 +0000288 pos += 4;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000289 memcpy(pos, &target_rcode, 2);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100290
Javier Cardona2cca3972011-09-06 12:10:43 -0700291 /* see note in function header */
292 prepare_frame_for_deferred_tx(sdata, skb);
293 ieee80211_add_pending_skb(local, skb);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100294 return 0;
295}
296
Javier Cardonabfc32e62009-08-17 17:15:55 -0700297void ieee80211s_update_metric(struct ieee80211_local *local,
298 struct sta_info *stainfo, struct sk_buff *skb)
299{
300 struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
301 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
302 int failed;
303
304 if (!ieee80211_is_data(hdr->frame_control))
305 return;
306
307 failed = !(txinfo->flags & IEEE80211_TX_STAT_ACK);
308
309 /* moving average, scaled to 100 */
310 stainfo->fail_avg = ((80 * stainfo->fail_avg + 5) / 100 + 20 * failed);
311 if (stainfo->fail_avg > 95)
312 mesh_plink_broken(stainfo);
313}
314
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100315static u32 airtime_link_metric_get(struct ieee80211_local *local,
316 struct sta_info *sta)
317{
318 struct ieee80211_supported_band *sband;
319 /* This should be adjusted for each device */
320 int device_constant = 1 << ARITH_SHIFT;
321 int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT;
322 int s_unit = 1 << ARITH_SHIFT;
323 int rate, err;
324 u32 tx_time, estimated_retx;
325 u64 result;
326
327 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
328
329 if (sta->fail_avg >= 100)
330 return MAX_METRIC;
Johannes Berge6a98542008-10-21 12:40:02 +0200331
332 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
333 return MAX_METRIC;
334
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100335 err = (sta->fail_avg << ARITH_SHIFT) / 100;
336
337 /* bitrate is in units of 100 Kbps, while we need rate in units of
338 * 1Mbps. This will be corrected on tx_time computation.
339 */
Johannes Berge6a98542008-10-21 12:40:02 +0200340 rate = sband->bitrates[sta->last_tx_rate.idx].bitrate;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100341 tx_time = (device_constant + 10 * test_frame_len / rate);
342 estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
343 result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
344 return (u32)result;
345}
346
347/**
348 * hwmp_route_info_get - Update routing info to originator and transmitter
349 *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200350 * @sdata: local mesh subif
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100351 * @mgmt: mesh management frame
352 * @hwmp_ie: hwmp information element (PREP or PREQ)
353 *
354 * This function updates the path routing information to the originator and the
Andrey Yurovskyf99288d2009-10-20 12:17:34 -0700355 * transmitter of a HWMP PREQ or PREP frame.
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100356 *
357 * Returns: metric to frame originator or 0 if the frame should not be further
358 * processed
359 *
360 * Notes: this function is the only place (besides user-provided info) where
361 * path routing information is updated.
362 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200363static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100364 struct ieee80211_mgmt *mgmt,
Rui Paulodbb81c42009-11-09 23:46:46 +0000365 u8 *hwmp_ie, enum mpath_frame_type action)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100366{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200367 struct ieee80211_local *local = sdata->local;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100368 struct mesh_path *mpath;
369 struct sta_info *sta;
370 bool fresh_info;
371 u8 *orig_addr, *ta;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000372 u32 orig_sn, orig_metric;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100373 unsigned long orig_lifetime, exp_time;
374 u32 last_hop_metric, new_metric;
375 bool process = true;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100376
377 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100378 sta = sta_info_get(sdata, mgmt->sa);
Johannes Bergdc0b0f72008-02-23 15:17:20 +0100379 if (!sta) {
380 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100381 return 0;
Johannes Bergdc0b0f72008-02-23 15:17:20 +0100382 }
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100383
384 last_hop_metric = airtime_link_metric_get(local, sta);
385 /* Update and check originator routing info */
386 fresh_info = true;
387
388 switch (action) {
389 case MPATH_PREQ:
390 orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie);
Rui Paulod19b3bf2009-11-09 23:46:55 +0000391 orig_sn = PREQ_IE_ORIG_SN(hwmp_ie);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100392 orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
393 orig_metric = PREQ_IE_METRIC(hwmp_ie);
394 break;
395 case MPATH_PREP:
Thomas Pedersen3c26f1f2011-11-24 17:15:22 -0800396 /* Originator here refers to the MP that was the target in the
397 * Path Request. We divert from the nomenclature in the draft
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100398 * so that we can easily use a single function to gather path
399 * information from both PREQ and PREP frames.
400 */
Thomas Pedersen3c26f1f2011-11-24 17:15:22 -0800401 orig_addr = PREP_IE_TARGET_ADDR(hwmp_ie);
402 orig_sn = PREP_IE_TARGET_SN(hwmp_ie);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100403 orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
404 orig_metric = PREP_IE_METRIC(hwmp_ie);
405 break;
406 default:
Johannes Bergdc0b0f72008-02-23 15:17:20 +0100407 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100408 return 0;
409 }
410 new_metric = orig_metric + last_hop_metric;
411 if (new_metric < orig_metric)
412 new_metric = MAX_METRIC;
413 exp_time = TU_TO_EXP_TIME(orig_lifetime);
414
Johannes Berg47846c92009-11-25 17:46:19 +0100415 if (memcmp(orig_addr, sdata->vif.addr, ETH_ALEN) == 0) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100416 /* This MP is the originator, we are not interested in this
417 * frame, except for updating transmitter's path info.
418 */
419 process = false;
420 fresh_info = false;
421 } else {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200422 mpath = mesh_path_lookup(orig_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100423 if (mpath) {
424 spin_lock_bh(&mpath->state_lock);
425 if (mpath->flags & MESH_PATH_FIXED)
426 fresh_info = false;
427 else if ((mpath->flags & MESH_PATH_ACTIVE) &&
Rui Paulod19b3bf2009-11-09 23:46:55 +0000428 (mpath->flags & MESH_PATH_SN_VALID)) {
429 if (SN_GT(mpath->sn, orig_sn) ||
430 (mpath->sn == orig_sn &&
Porsch, Marco533866b2010-02-24 09:53:13 +0100431 new_metric >= mpath->metric)) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100432 process = false;
433 fresh_info = false;
434 }
435 }
436 } else {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200437 mesh_path_add(orig_addr, sdata);
438 mpath = mesh_path_lookup(orig_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100439 if (!mpath) {
440 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100441 return 0;
442 }
443 spin_lock_bh(&mpath->state_lock);
444 }
445
446 if (fresh_info) {
447 mesh_path_assign_nexthop(mpath, sta);
Rui Paulod19b3bf2009-11-09 23:46:55 +0000448 mpath->flags |= MESH_PATH_SN_VALID;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100449 mpath->metric = new_metric;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000450 mpath->sn = orig_sn;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100451 mpath->exp_time = time_after(mpath->exp_time, exp_time)
452 ? mpath->exp_time : exp_time;
453 mesh_path_activate(mpath);
454 spin_unlock_bh(&mpath->state_lock);
455 mesh_path_tx_pending(mpath);
456 /* draft says preq_id should be saved to, but there does
457 * not seem to be any use for it, skipping by now
458 */
459 } else
460 spin_unlock_bh(&mpath->state_lock);
461 }
462
463 /* Update and check transmitter routing info */
464 ta = mgmt->sa;
465 if (memcmp(orig_addr, ta, ETH_ALEN) == 0)
466 fresh_info = false;
467 else {
468 fresh_info = true;
469
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200470 mpath = mesh_path_lookup(ta, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100471 if (mpath) {
472 spin_lock_bh(&mpath->state_lock);
473 if ((mpath->flags & MESH_PATH_FIXED) ||
474 ((mpath->flags & MESH_PATH_ACTIVE) &&
475 (last_hop_metric > mpath->metric)))
476 fresh_info = false;
477 } else {
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200478 mesh_path_add(ta, sdata);
479 mpath = mesh_path_lookup(ta, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100480 if (!mpath) {
481 rcu_read_unlock();
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100482 return 0;
483 }
484 spin_lock_bh(&mpath->state_lock);
485 }
486
487 if (fresh_info) {
488 mesh_path_assign_nexthop(mpath, sta);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100489 mpath->metric = last_hop_metric;
490 mpath->exp_time = time_after(mpath->exp_time, exp_time)
491 ? mpath->exp_time : exp_time;
492 mesh_path_activate(mpath);
493 spin_unlock_bh(&mpath->state_lock);
494 mesh_path_tx_pending(mpath);
495 } else
496 spin_unlock_bh(&mpath->state_lock);
497 }
498
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100499 rcu_read_unlock();
500
501 return process ? new_metric : 0;
502}
503
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200504static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100505 struct ieee80211_mgmt *mgmt,
David Woo57ef5dd2009-08-12 11:03:43 -0700506 u8 *preq_elem, u32 metric)
507{
Johannes Berg472dbc42008-09-11 00:01:49 +0200508 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100509 struct mesh_path *mpath;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000510 u8 *target_addr, *orig_addr;
511 u8 target_flags, ttl;
512 u32 orig_sn, target_sn, lifetime;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100513 bool reply = false;
514 bool forward = true;
515
Rui Paulod19b3bf2009-11-09 23:46:55 +0000516 /* Update target SN, if present */
517 target_addr = PREQ_IE_TARGET_ADDR(preq_elem);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100518 orig_addr = PREQ_IE_ORIG_ADDR(preq_elem);
Rui Paulod19b3bf2009-11-09 23:46:55 +0000519 target_sn = PREQ_IE_TARGET_SN(preq_elem);
520 orig_sn = PREQ_IE_ORIG_SN(preq_elem);
521 target_flags = PREQ_IE_TARGET_F(preq_elem);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100522
Javier Cardona76468872011-08-09 16:45:04 -0700523 mhwmp_dbg("received PREQ from %pM", orig_addr);
Rui Paulo27db2e42009-11-09 23:46:45 +0000524
Johannes Berg47846c92009-11-25 17:46:19 +0100525 if (memcmp(target_addr, sdata->vif.addr, ETH_ALEN) == 0) {
Javier Cardona76468872011-08-09 16:45:04 -0700526 mhwmp_dbg("PREQ is for us");
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100527 forward = false;
528 reply = true;
529 metric = 0;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000530 if (time_after(jiffies, ifmsh->last_sn_update +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100531 net_traversal_jiffies(sdata)) ||
Rui Paulod19b3bf2009-11-09 23:46:55 +0000532 time_before(jiffies, ifmsh->last_sn_update)) {
533 target_sn = ++ifmsh->sn;
534 ifmsh->last_sn_update = jiffies;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100535 }
536 } else {
537 rcu_read_lock();
Rui Paulod19b3bf2009-11-09 23:46:55 +0000538 mpath = mesh_path_lookup(target_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100539 if (mpath) {
Rui Paulod19b3bf2009-11-09 23:46:55 +0000540 if ((!(mpath->flags & MESH_PATH_SN_VALID)) ||
541 SN_LT(mpath->sn, target_sn)) {
542 mpath->sn = target_sn;
543 mpath->flags |= MESH_PATH_SN_VALID;
544 } else if ((!(target_flags & MP_F_DO)) &&
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100545 (mpath->flags & MESH_PATH_ACTIVE)) {
546 reply = true;
547 metric = mpath->metric;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000548 target_sn = mpath->sn;
549 if (target_flags & MP_F_RF)
550 target_flags |= MP_F_DO;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100551 else
552 forward = false;
553 }
554 }
555 rcu_read_unlock();
556 }
557
558 if (reply) {
559 lifetime = PREQ_IE_LIFETIME(preq_elem);
Javier Cardona45904f22010-12-03 09:20:40 +0100560 ttl = ifmsh->mshcfg.element_ttl;
Rui Paulo27db2e42009-11-09 23:46:45 +0000561 if (ttl != 0) {
Javier Cardona76468872011-08-09 16:45:04 -0700562 mhwmp_dbg("replying to the PREQ");
Thomas Pedersen3c26f1f2011-11-24 17:15:22 -0800563 mesh_path_sel_frame_tx(MPATH_PREP, 0, orig_addr,
564 cpu_to_le32(orig_sn), 0, target_addr,
565 cpu_to_le32(target_sn), mgmt->sa, 0, ttl,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800566 cpu_to_le32(lifetime), cpu_to_le32(metric),
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200567 0, sdata);
Rui Paulo27db2e42009-11-09 23:46:45 +0000568 } else
Johannes Berg472dbc42008-09-11 00:01:49 +0200569 ifmsh->mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100570 }
571
572 if (forward) {
573 u32 preq_id;
574 u8 hopcount, flags;
575
576 ttl = PREQ_IE_TTL(preq_elem);
577 lifetime = PREQ_IE_LIFETIME(preq_elem);
578 if (ttl <= 1) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200579 ifmsh->mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100580 return;
581 }
Javier Cardona76468872011-08-09 16:45:04 -0700582 mhwmp_dbg("forwarding the PREQ from %pM", orig_addr);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100583 --ttl;
584 flags = PREQ_IE_FLAGS(preq_elem);
585 preq_id = PREQ_IE_PREQ_ID(preq_elem);
586 hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1;
587 mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr,
Rui Paulod19b3bf2009-11-09 23:46:55 +0000588 cpu_to_le32(orig_sn), target_flags, target_addr,
Johannes Berg15ff6362009-11-17 13:34:04 +0100589 cpu_to_le32(target_sn), broadcast_addr,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800590 hopcount, ttl, cpu_to_le32(lifetime),
591 cpu_to_le32(metric), cpu_to_le32(preq_id),
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200592 sdata);
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700593 ifmsh->mshstats.fwded_mcast++;
Johannes Berg472dbc42008-09-11 00:01:49 +0200594 ifmsh->mshstats.fwded_frames++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100595 }
596}
597
598
Johannes Berg40b275b2011-05-13 14:15:49 +0200599static inline struct sta_info *
600next_hop_deref_protected(struct mesh_path *mpath)
601{
602 return rcu_dereference_protected(mpath->next_hop,
603 lockdep_is_held(&mpath->state_lock));
604}
605
606
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200607static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100608 struct ieee80211_mgmt *mgmt,
609 u8 *prep_elem, u32 metric)
610{
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100611 struct mesh_path *mpath;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000612 u8 *target_addr, *orig_addr;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100613 u8 ttl, hopcount, flags;
614 u8 next_hop[ETH_ALEN];
Rui Paulod19b3bf2009-11-09 23:46:55 +0000615 u32 target_sn, orig_sn, lifetime;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100616
Javier Cardona76468872011-08-09 16:45:04 -0700617 mhwmp_dbg("received PREP from %pM", PREP_IE_ORIG_ADDR(prep_elem));
Rui Paulodbb81c42009-11-09 23:46:46 +0000618
Thomas Pedersen3c26f1f2011-11-24 17:15:22 -0800619 orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
620 if (memcmp(orig_addr, sdata->vif.addr, ETH_ALEN) == 0)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100621 /* destination, no forwarding required */
622 return;
623
624 ttl = PREP_IE_TTL(prep_elem);
625 if (ttl <= 1) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200626 sdata->u.mesh.mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100627 return;
628 }
629
630 rcu_read_lock();
Thomas Pedersen3c26f1f2011-11-24 17:15:22 -0800631 mpath = mesh_path_lookup(orig_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100632 if (mpath)
633 spin_lock_bh(&mpath->state_lock);
634 else
635 goto fail;
636 if (!(mpath->flags & MESH_PATH_ACTIVE)) {
637 spin_unlock_bh(&mpath->state_lock);
638 goto fail;
639 }
Johannes Berg40b275b2011-05-13 14:15:49 +0200640 memcpy(next_hop, next_hop_deref_protected(mpath)->sta.addr, ETH_ALEN);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100641 spin_unlock_bh(&mpath->state_lock);
642 --ttl;
643 flags = PREP_IE_FLAGS(prep_elem);
644 lifetime = PREP_IE_LIFETIME(prep_elem);
645 hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1;
Thomas Pedersen3c26f1f2011-11-24 17:15:22 -0800646 target_addr = PREP_IE_TARGET_ADDR(prep_elem);
Rui Paulod19b3bf2009-11-09 23:46:55 +0000647 target_sn = PREP_IE_TARGET_SN(prep_elem);
648 orig_sn = PREP_IE_ORIG_SN(prep_elem);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100649
650 mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr,
Rui Paulod19b3bf2009-11-09 23:46:55 +0000651 cpu_to_le32(orig_sn), 0, target_addr,
Porsch, Marco533866b2010-02-24 09:53:13 +0100652 cpu_to_le32(target_sn), next_hop, hopcount,
Rui Paulod19b3bf2009-11-09 23:46:55 +0000653 ttl, cpu_to_le32(lifetime), cpu_to_le32(metric),
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200654 0, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100655 rcu_read_unlock();
Daniel Walkerc8a61a72009-08-18 10:59:00 -0700656
657 sdata->u.mesh.mshstats.fwded_unicast++;
Johannes Berg472dbc42008-09-11 00:01:49 +0200658 sdata->u.mesh.mshstats.fwded_frames++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100659 return;
660
661fail:
662 rcu_read_unlock();
Johannes Berg472dbc42008-09-11 00:01:49 +0200663 sdata->u.mesh.mshstats.dropped_frames_no_route++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100664}
665
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200666static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100667 struct ieee80211_mgmt *mgmt, u8 *perr_elem)
668{
Rui Paulod611f062009-11-09 23:46:50 +0000669 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100670 struct mesh_path *mpath;
Rui Paulod611f062009-11-09 23:46:50 +0000671 u8 ttl;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000672 u8 *ta, *target_addr;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000673 u32 target_sn;
674 u16 target_rcode;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100675
676 ta = mgmt->sa;
Rui Paulod611f062009-11-09 23:46:50 +0000677 ttl = PERR_IE_TTL(perr_elem);
678 if (ttl <= 1) {
679 ifmsh->mshstats.dropped_frames_ttl++;
680 return;
681 }
682 ttl--;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000683 target_addr = PERR_IE_TARGET_ADDR(perr_elem);
684 target_sn = PERR_IE_TARGET_SN(perr_elem);
685 target_rcode = PERR_IE_TARGET_RCODE(perr_elem);
Rui Paulod611f062009-11-09 23:46:50 +0000686
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100687 rcu_read_lock();
Rui Paulod19b3bf2009-11-09 23:46:55 +0000688 mpath = mesh_path_lookup(target_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100689 if (mpath) {
690 spin_lock_bh(&mpath->state_lock);
691 if (mpath->flags & MESH_PATH_ACTIVE &&
Johannes Berg40b275b2011-05-13 14:15:49 +0200692 memcmp(ta, next_hop_deref_protected(mpath)->sta.addr,
693 ETH_ALEN) == 0 &&
Rui Paulod19b3bf2009-11-09 23:46:55 +0000694 (!(mpath->flags & MESH_PATH_SN_VALID) ||
695 SN_GT(target_sn, mpath->sn))) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100696 mpath->flags &= ~MESH_PATH_ACTIVE;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000697 mpath->sn = target_sn;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100698 spin_unlock_bh(&mpath->state_lock);
Rui Paulod19b3bf2009-11-09 23:46:55 +0000699 mesh_path_error_tx(ttl, target_addr, cpu_to_le32(target_sn),
700 cpu_to_le16(target_rcode),
Johannes Berg15ff6362009-11-17 13:34:04 +0100701 broadcast_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100702 } else
703 spin_unlock_bh(&mpath->state_lock);
704 }
705 rcu_read_unlock();
706}
707
Rui Paulo90a5e162009-11-11 00:01:31 +0000708static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata,
709 struct ieee80211_mgmt *mgmt,
710 struct ieee80211_rann_ie *rann)
711{
712 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
713 struct mesh_path *mpath;
Rui Paulo90a5e162009-11-11 00:01:31 +0000714 u8 ttl, flags, hopcount;
715 u8 *orig_addr;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000716 u32 orig_sn, metric;
Javier Cardona0507e152011-08-09 16:45:10 -0700717 u32 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
Javier Cardona5ee68e52011-08-09 16:45:08 -0700718 bool root_is_gate;
Rui Paulo90a5e162009-11-11 00:01:31 +0000719
Rui Paulo90a5e162009-11-11 00:01:31 +0000720 ttl = rann->rann_ttl;
721 if (ttl <= 1) {
722 ifmsh->mshstats.dropped_frames_ttl++;
723 return;
724 }
725 ttl--;
726 flags = rann->rann_flags;
Javier Cardona5ee68e52011-08-09 16:45:08 -0700727 root_is_gate = !!(flags & RANN_FLAG_IS_GATE);
Rui Paulo90a5e162009-11-11 00:01:31 +0000728 orig_addr = rann->rann_addr;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000729 orig_sn = rann->rann_seq;
Rui Paulo90a5e162009-11-11 00:01:31 +0000730 hopcount = rann->rann_hopcount;
Rui Pauloa6a58b42009-11-09 23:46:51 +0000731 hopcount++;
Rui Paulo90a5e162009-11-11 00:01:31 +0000732 metric = rann->rann_metric;
Javier Cardona5ee68e52011-08-09 16:45:08 -0700733
734 /* Ignore our own RANNs */
735 if (memcmp(orig_addr, sdata->vif.addr, ETH_ALEN) == 0)
736 return;
737
738 mhwmp_dbg("received RANN from %pM (is_gate=%d)", orig_addr,
739 root_is_gate);
Rui Paulo90a5e162009-11-11 00:01:31 +0000740
741 rcu_read_lock();
742 mpath = mesh_path_lookup(orig_addr, sdata);
743 if (!mpath) {
744 mesh_path_add(orig_addr, sdata);
745 mpath = mesh_path_lookup(orig_addr, sdata);
746 if (!mpath) {
747 rcu_read_unlock();
748 sdata->u.mesh.mshstats.dropped_frames_no_route++;
749 return;
750 }
Rui Paulo90a5e162009-11-11 00:01:31 +0000751 }
Javier Cardona5ee68e52011-08-09 16:45:08 -0700752
753 if ((!(mpath->flags & (MESH_PATH_ACTIVE | MESH_PATH_RESOLVING)) ||
754 time_after(jiffies, mpath->exp_time - 1*HZ)) &&
755 !(mpath->flags & MESH_PATH_FIXED)) {
756 mhwmp_dbg("%s time to refresh root mpath %pM", sdata->name,
757 orig_addr);
758 mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH);
759 }
760
Rui Paulod19b3bf2009-11-09 23:46:55 +0000761 if (mpath->sn < orig_sn) {
Rui Paulo90a5e162009-11-11 00:01:31 +0000762 mesh_path_sel_frame_tx(MPATH_RANN, flags, orig_addr,
Rui Paulod19b3bf2009-11-09 23:46:55 +0000763 cpu_to_le32(orig_sn),
Johannes Berg15ff6362009-11-17 13:34:04 +0100764 0, NULL, 0, broadcast_addr,
Javier Cardona0507e152011-08-09 16:45:10 -0700765 hopcount, ttl, cpu_to_le32(interval),
Rui Pauloa6a58b42009-11-09 23:46:51 +0000766 cpu_to_le32(metric + mpath->metric),
Rui Paulo90a5e162009-11-11 00:01:31 +0000767 0, sdata);
Rui Paulod19b3bf2009-11-09 23:46:55 +0000768 mpath->sn = orig_sn;
Rui Paulo90a5e162009-11-11 00:01:31 +0000769 }
Javier Cardona5ee68e52011-08-09 16:45:08 -0700770 if (root_is_gate)
771 mesh_path_add_gate(mpath);
772
Rui Paulo90a5e162009-11-11 00:01:31 +0000773 rcu_read_unlock();
774}
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100775
776
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200777void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100778 struct ieee80211_mgmt *mgmt,
779 size_t len)
780{
781 struct ieee802_11_elems elems;
782 size_t baselen;
783 u32 last_hop_metric;
Javier Cardona97091312011-10-06 14:54:22 -0700784 struct sta_info *sta;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100785
Johannes Berg9c80d3d2008-09-08 15:41:59 +0200786 /* need action_code */
787 if (len < IEEE80211_MIN_ACTION_SIZE + 1)
788 return;
789
Javier Cardona97091312011-10-06 14:54:22 -0700790 rcu_read_lock();
791 sta = sta_info_get(sdata, mgmt->sa);
792 if (!sta || sta->plink_state != NL80211_PLINK_ESTAB) {
793 rcu_read_unlock();
794 return;
795 }
796 rcu_read_unlock();
797
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100798 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
799 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
800 len - baselen, &elems);
801
Rui Paulodbb81c42009-11-09 23:46:46 +0000802 if (elems.preq) {
803 if (elems.preq_len != 37)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100804 /* Right now we support just 1 destination and no AE */
805 return;
Rui Paulodbb81c42009-11-09 23:46:46 +0000806 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.preq,
807 MPATH_PREQ);
808 if (last_hop_metric)
809 hwmp_preq_frame_process(sdata, mgmt, elems.preq,
810 last_hop_metric);
811 }
812 if (elems.prep) {
813 if (elems.prep_len != 31)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100814 /* Right now we support no AE */
815 return;
Rui Paulodbb81c42009-11-09 23:46:46 +0000816 last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.prep,
817 MPATH_PREP);
818 if (last_hop_metric)
819 hwmp_prep_frame_process(sdata, mgmt, elems.prep,
820 last_hop_metric);
821 }
822 if (elems.perr) {
Rui Paulod611f062009-11-09 23:46:50 +0000823 if (elems.perr_len != 15)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100824 /* Right now we support only one destination per PERR */
825 return;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200826 hwmp_perr_frame_process(sdata, mgmt, elems.perr);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100827 }
Rui Paulo90a5e162009-11-11 00:01:31 +0000828 if (elems.rann)
829 hwmp_rann_frame_process(sdata, mgmt, elems.rann);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100830}
831
832/**
833 * mesh_queue_preq - queue a PREQ to a given destination
834 *
835 * @mpath: mesh path to discover
836 * @flags: special attributes of the PREQ to be sent
837 *
838 * Locking: the function must be called from within a rcu read lock block.
839 *
840 */
841static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
842{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200843 struct ieee80211_sub_if_data *sdata = mpath->sdata;
Johannes Berg472dbc42008-09-11 00:01:49 +0200844 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100845 struct mesh_preq_queue *preq_node;
846
Andrey Yurovsky59615b52009-06-25 16:07:42 -0700847 preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100848 if (!preq_node) {
Javier Cardona76468872011-08-09 16:45:04 -0700849 mhwmp_dbg("could not allocate PREQ node");
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100850 return;
851 }
852
Baruch Siach987dafa2011-07-28 08:51:05 +0300853 spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
Johannes Berg472dbc42008-09-11 00:01:49 +0200854 if (ifmsh->preq_queue_len == MAX_PREQ_QUEUE_LEN) {
Baruch Siach987dafa2011-07-28 08:51:05 +0300855 spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100856 kfree(preq_node);
857 if (printk_ratelimit())
Javier Cardona76468872011-08-09 16:45:04 -0700858 mhwmp_dbg("PREQ node queue full");
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100859 return;
860 }
861
Johannes Bergf2dc7982011-11-18 15:27:31 +0100862 spin_lock(&mpath->state_lock);
Javier Cardonaf3011cf2011-11-03 21:11:10 -0700863 if (mpath->flags & MESH_PATH_REQ_QUEUED) {
Johannes Bergf2dc7982011-11-18 15:27:31 +0100864 spin_unlock(&mpath->state_lock);
Javier Cardonaf3011cf2011-11-03 21:11:10 -0700865 spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
Dan Carpenter88d53462011-11-15 09:33:31 +0300866 kfree(preq_node);
Javier Cardonaf3011cf2011-11-03 21:11:10 -0700867 return;
868 }
869
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100870 memcpy(preq_node->dst, mpath->dst, ETH_ALEN);
871 preq_node->flags = flags;
872
Javier Cardonaf3011cf2011-11-03 21:11:10 -0700873 mpath->flags |= MESH_PATH_REQ_QUEUED;
Johannes Bergf2dc7982011-11-18 15:27:31 +0100874 spin_unlock(&mpath->state_lock);
Javier Cardonaf3011cf2011-11-03 21:11:10 -0700875
Johannes Berg472dbc42008-09-11 00:01:49 +0200876 list_add_tail(&preq_node->list, &ifmsh->preq_queue.list);
877 ++ifmsh->preq_queue_len;
Baruch Siach987dafa2011-07-28 08:51:05 +0300878 spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100879
Johannes Berg472dbc42008-09-11 00:01:49 +0200880 if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata)))
Johannes Berg64592c82010-06-10 10:21:31 +0200881 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100882
Johannes Berg472dbc42008-09-11 00:01:49 +0200883 else if (time_before(jiffies, ifmsh->last_preq)) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100884 /* avoid long wait if did not send preqs for a long time
885 * and jiffies wrapped around
886 */
Johannes Berg472dbc42008-09-11 00:01:49 +0200887 ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
Johannes Berg64592c82010-06-10 10:21:31 +0200888 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100889 } else
Johannes Berg472dbc42008-09-11 00:01:49 +0200890 mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100891 min_preq_int_jiff(sdata));
892}
893
894/**
895 * mesh_path_start_discovery - launch a path discovery from the PREQ queue
896 *
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200897 * @sdata: local mesh subif
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100898 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200899void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100900{
Johannes Berg472dbc42008-09-11 00:01:49 +0200901 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100902 struct mesh_preq_queue *preq_node;
903 struct mesh_path *mpath;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000904 u8 ttl, target_flags;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100905 u32 lifetime;
906
Johannes Berga43816d2009-07-10 11:39:26 +0200907 spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
Johannes Berg472dbc42008-09-11 00:01:49 +0200908 if (!ifmsh->preq_queue_len ||
909 time_before(jiffies, ifmsh->last_preq +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100910 min_preq_int_jiff(sdata))) {
Johannes Berga43816d2009-07-10 11:39:26 +0200911 spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100912 return;
913 }
914
Johannes Berg472dbc42008-09-11 00:01:49 +0200915 preq_node = list_first_entry(&ifmsh->preq_queue.list,
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100916 struct mesh_preq_queue, list);
917 list_del(&preq_node->list);
Johannes Berg472dbc42008-09-11 00:01:49 +0200918 --ifmsh->preq_queue_len;
Johannes Berga43816d2009-07-10 11:39:26 +0200919 spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100920
921 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200922 mpath = mesh_path_lookup(preq_node->dst, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100923 if (!mpath)
924 goto enddiscovery;
925
926 spin_lock_bh(&mpath->state_lock);
Javier Cardonaf3011cf2011-11-03 21:11:10 -0700927 mpath->flags &= ~MESH_PATH_REQ_QUEUED;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100928 if (preq_node->flags & PREQ_Q_F_START) {
929 if (mpath->flags & MESH_PATH_RESOLVING) {
930 spin_unlock_bh(&mpath->state_lock);
931 goto enddiscovery;
932 } else {
933 mpath->flags &= ~MESH_PATH_RESOLVED;
934 mpath->flags |= MESH_PATH_RESOLVING;
935 mpath->discovery_retries = 0;
936 mpath->discovery_timeout = disc_timeout_jiff(sdata);
937 }
938 } else if (!(mpath->flags & MESH_PATH_RESOLVING) ||
939 mpath->flags & MESH_PATH_RESOLVED) {
940 mpath->flags &= ~MESH_PATH_RESOLVING;
941 spin_unlock_bh(&mpath->state_lock);
942 goto enddiscovery;
943 }
944
Johannes Berg472dbc42008-09-11 00:01:49 +0200945 ifmsh->last_preq = jiffies;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100946
Rui Paulod19b3bf2009-11-09 23:46:55 +0000947 if (time_after(jiffies, ifmsh->last_sn_update +
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100948 net_traversal_jiffies(sdata)) ||
Rui Paulod19b3bf2009-11-09 23:46:55 +0000949 time_before(jiffies, ifmsh->last_sn_update)) {
950 ++ifmsh->sn;
951 sdata->u.mesh.last_sn_update = jiffies;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100952 }
953 lifetime = default_lifetime(sdata);
Javier Cardona45904f22010-12-03 09:20:40 +0100954 ttl = sdata->u.mesh.mshcfg.element_ttl;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100955 if (ttl == 0) {
Johannes Berg472dbc42008-09-11 00:01:49 +0200956 sdata->u.mesh.mshstats.dropped_frames_ttl++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100957 spin_unlock_bh(&mpath->state_lock);
958 goto enddiscovery;
959 }
960
961 if (preq_node->flags & PREQ_Q_F_REFRESH)
Rui Paulod19b3bf2009-11-09 23:46:55 +0000962 target_flags = MP_F_DO;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100963 else
Rui Paulod19b3bf2009-11-09 23:46:55 +0000964 target_flags = MP_F_RF;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100965
966 spin_unlock_bh(&mpath->state_lock);
Johannes Berg47846c92009-11-25 17:46:19 +0100967 mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->vif.addr,
Rui Paulod19b3bf2009-11-09 23:46:55 +0000968 cpu_to_le32(ifmsh->sn), target_flags, mpath->dst,
Johannes Berg15ff6362009-11-17 13:34:04 +0100969 cpu_to_le32(mpath->sn), broadcast_addr, 0,
Luis Carlos Coboaa2b5922008-02-29 14:30:32 -0800970 ttl, cpu_to_le32(lifetime), 0,
Johannes Berg472dbc42008-09-11 00:01:49 +0200971 cpu_to_le32(ifmsh->preq_id++), sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100972 mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
973
974enddiscovery:
975 rcu_read_unlock();
976 kfree(preq_node);
977}
978
979/**
Rami Rosen2182b832009-01-19 13:50:37 +0200980 * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100981 *
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +0200982 * @skb: 802.11 frame to be sent
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200983 * @sdata: network subif the frame will be sent through
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100984 *
985 * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is
986 * found, the function will start a path discovery and queue the frame so it is
987 * sent when the path is resolved. This means the caller must not free the skb
988 * in this case.
989 */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200990int mesh_nexthop_lookup(struct sk_buff *skb,
991 struct ieee80211_sub_if_data *sdata)
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100992{
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100993 struct sk_buff *skb_to_free = NULL;
994 struct mesh_path *mpath;
Johannes Berg40b275b2011-05-13 14:15:49 +0200995 struct sta_info *next_hop;
Luis Carlos Coboe32f85f2008-08-05 19:34:52 +0200996 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000997 u8 *target_addr = hdr->addr3;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +0100998 int err = 0;
999
1000 rcu_read_lock();
Rui Paulod19b3bf2009-11-09 23:46:55 +00001001 mpath = mesh_path_lookup(target_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001002
1003 if (!mpath) {
Rui Paulod19b3bf2009-11-09 23:46:55 +00001004 mesh_path_add(target_addr, sdata);
1005 mpath = mesh_path_lookup(target_addr, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001006 if (!mpath) {
Johannes Berg472dbc42008-09-11 00:01:49 +02001007 sdata->u.mesh.mshstats.dropped_frames_no_route++;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001008 err = -ENOSPC;
1009 goto endlookup;
1010 }
1011 }
1012
1013 if (mpath->flags & MESH_PATH_ACTIVE) {
Joe Perchesf64f9e72009-11-29 16:55:45 -08001014 if (time_after(jiffies,
Javier Cardona7b324d22009-12-09 18:43:01 -08001015 mpath->exp_time -
Joe Perchesf64f9e72009-11-29 16:55:45 -08001016 msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) &&
Johannes Berg47846c92009-11-25 17:46:19 +01001017 !memcmp(sdata->vif.addr, hdr->addr4, ETH_ALEN) &&
Joe Perchesf64f9e72009-11-29 16:55:45 -08001018 !(mpath->flags & MESH_PATH_RESOLVING) &&
1019 !(mpath->flags & MESH_PATH_FIXED)) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001020 mesh_queue_preq(mpath,
1021 PREQ_Q_F_START | PREQ_Q_F_REFRESH);
1022 }
Johannes Berg40b275b2011-05-13 14:15:49 +02001023 next_hop = rcu_dereference(mpath->next_hop);
Thomas Pedersen7e3c8862011-11-24 17:15:21 -08001024 if (next_hop) {
Johannes Berg40b275b2011-05-13 14:15:49 +02001025 memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN);
Thomas Pedersen7e3c8862011-11-24 17:15:21 -08001026 memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
1027 } else
Johannes Berg40b275b2011-05-13 14:15:49 +02001028 err = -ENOENT;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001029 } else {
Javier Cardona249b4052009-07-07 10:55:03 -07001030 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001031 if (!(mpath->flags & MESH_PATH_RESOLVING)) {
1032 /* Start discovery only if it is not running yet */
1033 mesh_queue_preq(mpath, PREQ_Q_F_START);
1034 }
1035
Javier Cardonaf3011cf2011-11-03 21:11:10 -07001036 if (skb_queue_len(&mpath->frame_queue) >= MESH_FRAME_QUEUE_LEN)
Javier Cardonafe583432009-08-10 12:15:46 -07001037 skb_to_free = skb_dequeue(&mpath->frame_queue);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001038
Javier Cardona249b4052009-07-07 10:55:03 -07001039 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
Javier Cardonad0ce1852011-11-03 21:11:13 -07001040 ieee80211_set_qos_hdr(sdata, skb);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001041 skb_queue_tail(&mpath->frame_queue, skb);
1042 if (skb_to_free)
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001043 mesh_path_discard_frame(skb_to_free, sdata);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001044 err = -ENOENT;
1045 }
1046
1047endlookup:
1048 rcu_read_unlock();
1049 return err;
1050}
1051
1052void mesh_path_timer(unsigned long data)
1053{
Johannes Bergdea40962011-05-12 15:03:32 +02001054 struct mesh_path *mpath = (void *) data;
1055 struct ieee80211_sub_if_data *sdata = mpath->sdata;
Javier Cardona5ee68e52011-08-09 16:45:08 -07001056 int ret;
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001057
Johannes Bergdea40962011-05-12 15:03:32 +02001058 if (sdata->local->quiescing)
Johannes Berg5bb644a2009-05-17 11:40:42 +02001059 return;
Johannes Berg5bb644a2009-05-17 11:40:42 +02001060
1061 spin_lock_bh(&mpath->state_lock);
Luis Carlos Cobocfa22c72008-02-29 15:04:13 -08001062 if (mpath->flags & MESH_PATH_RESOLVED ||
Javier Cardona5ee68e52011-08-09 16:45:08 -07001063 (!(mpath->flags & MESH_PATH_RESOLVING))) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001064 mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);
Javier Cardona5ee68e52011-08-09 16:45:08 -07001065 spin_unlock_bh(&mpath->state_lock);
1066 } else if (mpath->discovery_retries < max_preq_retries(sdata)) {
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001067 ++mpath->discovery_retries;
1068 mpath->discovery_timeout *= 2;
Javier Cardonaf3011cf2011-11-03 21:11:10 -07001069 mpath->flags &= ~MESH_PATH_REQ_QUEUED;
Javier Cardona5ee68e52011-08-09 16:45:08 -07001070 spin_unlock_bh(&mpath->state_lock);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001071 mesh_queue_preq(mpath, 0);
1072 } else {
1073 mpath->flags = 0;
1074 mpath->exp_time = jiffies;
Javier Cardona5ee68e52011-08-09 16:45:08 -07001075 spin_unlock_bh(&mpath->state_lock);
1076 if (!mpath->is_gate && mesh_gate_num(sdata) > 0) {
1077 ret = mesh_path_send_to_gates(mpath);
1078 if (ret)
1079 mhwmp_dbg("no gate was reachable");
1080 } else
1081 mesh_path_flush_pending(mpath);
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001082 }
Luis Carlos Cobo050ac522008-02-23 15:17:15 +01001083}
Rui Pauloe304bfd2009-11-09 23:46:56 +00001084
1085void
1086mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata)
1087{
1088 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardona0507e152011-08-09 16:45:10 -07001089 u32 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval;
Javier Cardona16dd7262011-08-09 16:45:11 -07001090 u8 flags;
Rui Pauloe304bfd2009-11-09 23:46:56 +00001091
Javier Cardona16dd7262011-08-09 16:45:11 -07001092 flags = (ifmsh->mshcfg.dot11MeshGateAnnouncementProtocol)
1093 ? RANN_FLAG_IS_GATE : 0;
1094 mesh_path_sel_frame_tx(MPATH_RANN, flags, sdata->vif.addr,
Rui Pauloe304bfd2009-11-09 23:46:56 +00001095 cpu_to_le32(++ifmsh->sn),
Johannes Berg15ff6362009-11-17 13:34:04 +01001096 0, NULL, 0, broadcast_addr,
Javier Cardona45904f22010-12-03 09:20:40 +01001097 0, sdata->u.mesh.mshcfg.element_ttl,
Javier Cardona0507e152011-08-09 16:45:10 -07001098 cpu_to_le32(interval), 0, 0, sdata);
Rui Pauloe304bfd2009-11-09 23:46:56 +00001099}