Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1 | /* |
Rui Paulo | 264d9b7 | 2009-11-09 23:46:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2008, 2009 open80211s Ltd. |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 11 | #include <linux/etherdevice.h> |
Johannes Berg | d26ad37 | 2012-02-20 11:38:41 +0100 | [diff] [blame] | 12 | #include <asm/unaligned.h> |
Javier Cardona | 2cca397 | 2011-09-06 12:10:43 -0700 | [diff] [blame] | 13 | #include "wme.h" |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 14 | #include "mesh.h" |
| 15 | |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 16 | #ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 17 | #define mhwmp_dbg(fmt, args...) \ |
Joe Perches | f0d2320 | 2012-05-15 14:20:30 -0700 | [diff] [blame] | 18 | pr_debug("Mesh HWMP (%s): " fmt "\n", sdata->name, ##args) |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 19 | #else |
| 20 | #define mhwmp_dbg(fmt, args...) do { (void)(0); } while (0) |
| 21 | #endif |
| 22 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 23 | #define TEST_FRAME_LEN 8192 |
| 24 | #define MAX_METRIC 0xffffffff |
| 25 | #define ARITH_SHIFT 8 |
| 26 | |
| 27 | /* Number of frames buffered per destination for unresolved destinations */ |
| 28 | #define MESH_FRAME_QUEUE_LEN 10 |
| 29 | #define MAX_PREQ_QUEUE_LEN 64 |
| 30 | |
| 31 | /* Destination only */ |
| 32 | #define MP_F_DO 0x1 |
| 33 | /* Reply and forward */ |
| 34 | #define MP_F_RF 0x2 |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 35 | /* Unknown Sequence Number */ |
| 36 | #define MP_F_USN 0x01 |
| 37 | /* Reason code Present */ |
| 38 | #define MP_F_RCODE 0x02 |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 39 | |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 40 | static void mesh_queue_preq(struct mesh_path *, u8); |
| 41 | |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 42 | static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae) |
| 43 | { |
| 44 | if (ae) |
| 45 | offset += 6; |
Harvey Harrison | ae7245c | 2008-05-01 22:19:33 -0700 | [diff] [blame] | 46 | return get_unaligned_le32(preq_elem + offset); |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 49 | static inline u32 u16_field_get(u8 *preq_elem, int offset, bool ae) |
| 50 | { |
| 51 | if (ae) |
| 52 | offset += 6; |
| 53 | return get_unaligned_le16(preq_elem + offset); |
| 54 | } |
| 55 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 56 | /* HWMP IE processing macros */ |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 57 | #define AE_F (1<<6) |
| 58 | #define AE_F_SET(x) (*x & AE_F) |
| 59 | #define PREQ_IE_FLAGS(x) (*(x)) |
| 60 | #define PREQ_IE_HOPCOUNT(x) (*(x + 1)) |
| 61 | #define PREQ_IE_TTL(x) (*(x + 2)) |
| 62 | #define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0) |
| 63 | #define PREQ_IE_ORIG_ADDR(x) (x + 7) |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 64 | #define PREQ_IE_ORIG_SN(x) u32_field_get(x, 13, 0) |
| 65 | #define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x)) |
| 66 | #define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x)) |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 67 | #define PREQ_IE_TARGET_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26)) |
| 68 | #define PREQ_IE_TARGET_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27) |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 69 | #define PREQ_IE_TARGET_SN(x) u32_field_get(x, 33, AE_F_SET(x)) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 70 | |
| 71 | |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 72 | #define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x) |
| 73 | #define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x) |
| 74 | #define PREP_IE_TTL(x) PREQ_IE_TTL(x) |
Thomas Pedersen | 25d49e4 | 2011-08-11 19:35:15 -0700 | [diff] [blame] | 75 | #define PREP_IE_ORIG_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21) |
| 76 | #define PREP_IE_ORIG_SN(x) u32_field_get(x, 27, AE_F_SET(x)) |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 77 | #define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x)) |
| 78 | #define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x)) |
Thomas Pedersen | 25d49e4 | 2011-08-11 19:35:15 -0700 | [diff] [blame] | 79 | #define PREP_IE_TARGET_ADDR(x) (x + 3) |
| 80 | #define PREP_IE_TARGET_SN(x) u32_field_get(x, 9, 0) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 81 | |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 82 | #define PERR_IE_TTL(x) (*(x)) |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 83 | #define PERR_IE_TARGET_FLAGS(x) (*(x + 2)) |
| 84 | #define PERR_IE_TARGET_ADDR(x) (x + 3) |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 85 | #define PERR_IE_TARGET_SN(x) u32_field_get(x, 9, 0) |
| 86 | #define PERR_IE_TARGET_RCODE(x) u16_field_get(x, 13, 0) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 87 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 88 | #define MSEC_TO_TU(x) (x*1000/1024) |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 89 | #define SN_GT(x, y) ((s32)(y - x) < 0) |
| 90 | #define SN_LT(x, y) ((s32)(x - y) < 0) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 91 | |
| 92 | #define net_traversal_jiffies(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 93 | msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 94 | #define default_lifetime(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 95 | MSEC_TO_TU(s->u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 96 | #define min_preq_int_jiff(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 97 | (msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval)) |
| 98 | #define max_preq_retries(s) (s->u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 99 | #define disc_timeout_jiff(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 100 | msecs_to_jiffies(sdata->u.mesh.mshcfg.min_discovery_timeout) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 101 | |
| 102 | enum mpath_frame_type { |
| 103 | MPATH_PREQ = 0, |
| 104 | MPATH_PREP, |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 105 | MPATH_PERR, |
| 106 | MPATH_RANN |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 107 | }; |
| 108 | |
Johannes Berg | 15ff636 | 2009-11-17 13:34:04 +0100 | [diff] [blame] | 109 | static const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 110 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 111 | static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags, |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 112 | u8 *orig_addr, __le32 orig_sn, u8 target_flags, u8 *target, |
Johannes Berg | 15ff636 | 2009-11-17 13:34:04 +0100 | [diff] [blame] | 113 | __le32 target_sn, const u8 *da, u8 hop_count, u8 ttl, |
| 114 | __le32 lifetime, __le32 metric, __le32 preq_id, |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 115 | struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 116 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 117 | struct ieee80211_local *local = sdata->local; |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 118 | struct sk_buff *skb; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 119 | struct ieee80211_mgmt *mgmt; |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 120 | u8 *pos, ie_len; |
| 121 | int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.mesh_action) + |
| 122 | sizeof(mgmt->u.action.u.mesh_action); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 123 | |
Javier Cardona | 65e8b0c | 2012-01-17 18:17:46 -0800 | [diff] [blame] | 124 | skb = dev_alloc_skb(local->tx_headroom + |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 125 | hdr_len + |
| 126 | 2 + 37); /* max HWMP IE */ |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 127 | if (!skb) |
| 128 | return -1; |
Javier Cardona | 65e8b0c | 2012-01-17 18:17:46 -0800 | [diff] [blame] | 129 | skb_reserve(skb, local->tx_headroom); |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 130 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); |
| 131 | memset(mgmt, 0, hdr_len); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 132 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 133 | IEEE80211_STYPE_ACTION); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 134 | |
| 135 | memcpy(mgmt->da, da, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 136 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 137 | /* BSSID == SA */ |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 138 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); |
Thomas Pedersen | 25d49e4 | 2011-08-11 19:35:15 -0700 | [diff] [blame] | 139 | mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION; |
| 140 | mgmt->u.action.u.mesh_action.action_code = |
| 141 | WLAN_MESH_ACTION_HWMP_PATH_SELECTION; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 142 | |
| 143 | switch (action) { |
| 144 | case MPATH_PREQ: |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 145 | mhwmp_dbg("sending PREQ to %pM", target); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 146 | ie_len = 37; |
| 147 | pos = skb_put(skb, 2 + ie_len); |
| 148 | *pos++ = WLAN_EID_PREQ; |
| 149 | break; |
| 150 | case MPATH_PREP: |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 151 | mhwmp_dbg("sending PREP to %pM", target); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 152 | ie_len = 31; |
| 153 | pos = skb_put(skb, 2 + ie_len); |
| 154 | *pos++ = WLAN_EID_PREP; |
| 155 | break; |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 156 | case MPATH_RANN: |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 157 | mhwmp_dbg("sending RANN from %pM", orig_addr); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 158 | ie_len = sizeof(struct ieee80211_rann_ie); |
| 159 | pos = skb_put(skb, 2 + ie_len); |
| 160 | *pos++ = WLAN_EID_RANN; |
| 161 | break; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 162 | default: |
Patrick McHardy | 812714d | 2008-05-06 12:52:07 +0200 | [diff] [blame] | 163 | kfree_skb(skb); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 164 | return -ENOTSUPP; |
| 165 | break; |
| 166 | } |
| 167 | *pos++ = ie_len; |
| 168 | *pos++ = flags; |
| 169 | *pos++ = hop_count; |
| 170 | *pos++ = ttl; |
Thomas Pedersen | 25d49e4 | 2011-08-11 19:35:15 -0700 | [diff] [blame] | 171 | if (action == MPATH_PREP) { |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 172 | memcpy(pos, target, ETH_ALEN); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 173 | pos += ETH_ALEN; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 174 | memcpy(pos, &target_sn, 4); |
Thomas Pedersen | 25d49e4 | 2011-08-11 19:35:15 -0700 | [diff] [blame] | 175 | pos += 4; |
| 176 | } else { |
| 177 | if (action == MPATH_PREQ) { |
| 178 | memcpy(pos, &preq_id, 4); |
| 179 | pos += 4; |
| 180 | } |
| 181 | memcpy(pos, orig_addr, ETH_ALEN); |
| 182 | pos += ETH_ALEN; |
| 183 | memcpy(pos, &orig_sn, 4); |
| 184 | pos += 4; |
| 185 | } |
| 186 | memcpy(pos, &lifetime, 4); /* interval for RANN */ |
| 187 | pos += 4; |
| 188 | memcpy(pos, &metric, 4); |
| 189 | pos += 4; |
| 190 | if (action == MPATH_PREQ) { |
| 191 | *pos++ = 1; /* destination count */ |
| 192 | *pos++ = target_flags; |
| 193 | memcpy(pos, target, ETH_ALEN); |
| 194 | pos += ETH_ALEN; |
| 195 | memcpy(pos, &target_sn, 4); |
| 196 | pos += 4; |
| 197 | } else if (action == MPATH_PREP) { |
| 198 | memcpy(pos, orig_addr, ETH_ALEN); |
| 199 | pos += ETH_ALEN; |
| 200 | memcpy(pos, &orig_sn, 4); |
| 201 | pos += 4; |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 202 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 203 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 204 | ieee80211_tx_skb(sdata, skb); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 205 | return 0; |
| 206 | } |
| 207 | |
Javier Cardona | 2cca397 | 2011-09-06 12:10:43 -0700 | [diff] [blame] | 208 | |
| 209 | /* Headroom is not adjusted. Caller should ensure that skb has sufficient |
| 210 | * headroom in case the frame is encrypted. */ |
| 211 | static void prepare_frame_for_deferred_tx(struct ieee80211_sub_if_data *sdata, |
| 212 | struct sk_buff *skb) |
| 213 | { |
Javier Cardona | 2cca397 | 2011-09-06 12:10:43 -0700 | [diff] [blame] | 214 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 215 | |
| 216 | skb_set_mac_header(skb, 0); |
| 217 | skb_set_network_header(skb, 0); |
| 218 | skb_set_transport_header(skb, 0); |
| 219 | |
| 220 | /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */ |
| 221 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
| 222 | skb->priority = 7; |
| 223 | |
| 224 | info->control.vif = &sdata->vif; |
Javier Cardona | 2154c81c | 2011-09-07 17:49:53 -0700 | [diff] [blame] | 225 | ieee80211_set_qos_hdr(sdata, skb); |
Javier Cardona | 2cca397 | 2011-09-06 12:10:43 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 228 | /** |
| 229 | * mesh_send_path error - Sends a PERR mesh management frame |
| 230 | * |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 231 | * @target: broken destination |
| 232 | * @target_sn: SN of the broken destination |
| 233 | * @target_rcode: reason code for this PERR |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 234 | * @ra: node this frame is addressed to |
Javier Cardona | 2cca397 | 2011-09-06 12:10:43 -0700 | [diff] [blame] | 235 | * |
| 236 | * Note: This function may be called with driver locks taken that the driver |
| 237 | * also acquires in the TX path. To avoid a deadlock we don't transmit the |
| 238 | * frame directly but add it to the pending queue instead. |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 239 | */ |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 240 | int mesh_path_error_tx(u8 ttl, u8 *target, __le32 target_sn, |
Johannes Berg | 15ff636 | 2009-11-17 13:34:04 +0100 | [diff] [blame] | 241 | __le16 target_rcode, const u8 *ra, |
| 242 | struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 243 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 244 | struct ieee80211_local *local = sdata->local; |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 245 | struct sk_buff *skb; |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 246 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 247 | struct ieee80211_mgmt *mgmt; |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 248 | u8 *pos, ie_len; |
| 249 | int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.mesh_action) + |
| 250 | sizeof(mgmt->u.action.u.mesh_action); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 251 | |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 252 | if (time_before(jiffies, ifmsh->next_perr)) |
| 253 | return -EAGAIN; |
| 254 | |
Javier Cardona | 65e8b0c | 2012-01-17 18:17:46 -0800 | [diff] [blame] | 255 | skb = dev_alloc_skb(local->tx_headroom + |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 256 | hdr_len + |
| 257 | 2 + 15 /* PERR IE */); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 258 | if (!skb) |
| 259 | return -1; |
Javier Cardona | 65e8b0c | 2012-01-17 18:17:46 -0800 | [diff] [blame] | 260 | skb_reserve(skb, local->tx_headroom); |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 261 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); |
| 262 | memset(mgmt, 0, hdr_len); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 263 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 264 | IEEE80211_STYPE_ACTION); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 265 | |
| 266 | memcpy(mgmt->da, ra, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 267 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Thomas Pedersen | 25d49e4 | 2011-08-11 19:35:15 -0700 | [diff] [blame] | 268 | /* BSSID == SA */ |
| 269 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); |
| 270 | mgmt->u.action.category = WLAN_CATEGORY_MESH_ACTION; |
| 271 | mgmt->u.action.u.mesh_action.action_code = |
| 272 | WLAN_MESH_ACTION_HWMP_PATH_SELECTION; |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 273 | ie_len = 15; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 274 | pos = skb_put(skb, 2 + ie_len); |
| 275 | *pos++ = WLAN_EID_PERR; |
| 276 | *pos++ = ie_len; |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 277 | /* ttl */ |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 278 | *pos++ = ttl; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 279 | /* number of destinations */ |
| 280 | *pos++ = 1; |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 281 | /* |
| 282 | * flags bit, bit 1 is unset if we know the sequence number and |
| 283 | * bit 2 is set if we have a reason code |
| 284 | */ |
| 285 | *pos = 0; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 286 | if (!target_sn) |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 287 | *pos |= MP_F_USN; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 288 | if (target_rcode) |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 289 | *pos |= MP_F_RCODE; |
| 290 | pos++; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 291 | memcpy(pos, target, ETH_ALEN); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 292 | pos += ETH_ALEN; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 293 | memcpy(pos, &target_sn, 4); |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 294 | pos += 4; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 295 | memcpy(pos, &target_rcode, 2); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 296 | |
Javier Cardona | 2cca397 | 2011-09-06 12:10:43 -0700 | [diff] [blame] | 297 | /* see note in function header */ |
| 298 | prepare_frame_for_deferred_tx(sdata, skb); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 299 | ifmsh->next_perr = TU_TO_EXP_TIME( |
| 300 | ifmsh->mshcfg.dot11MeshHWMPperrMinInterval); |
Javier Cardona | 2cca397 | 2011-09-06 12:10:43 -0700 | [diff] [blame] | 301 | ieee80211_add_pending_skb(local, skb); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
Javier Cardona | bfc32e6 | 2009-08-17 17:15:55 -0700 | [diff] [blame] | 305 | void ieee80211s_update_metric(struct ieee80211_local *local, |
Javier Cardona | 35b3fe1c | 2012-06-08 13:30:25 -0700 | [diff] [blame^] | 306 | struct sta_info *sta, struct sk_buff *skb) |
Javier Cardona | bfc32e6 | 2009-08-17 17:15:55 -0700 | [diff] [blame] | 307 | { |
| 308 | struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb); |
| 309 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 310 | int failed; |
| 311 | |
| 312 | if (!ieee80211_is_data(hdr->frame_control)) |
| 313 | return; |
| 314 | |
| 315 | failed = !(txinfo->flags & IEEE80211_TX_STAT_ACK); |
| 316 | |
| 317 | /* moving average, scaled to 100 */ |
Javier Cardona | 35b3fe1c | 2012-06-08 13:30:25 -0700 | [diff] [blame^] | 318 | sta->fail_avg = ((80 * sta->fail_avg + 5) / 100 + 20 * failed); |
| 319 | if (sta->fail_avg > 95) |
| 320 | mesh_plink_broken(sta); |
Javier Cardona | bfc32e6 | 2009-08-17 17:15:55 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 323 | static u32 airtime_link_metric_get(struct ieee80211_local *local, |
| 324 | struct sta_info *sta) |
| 325 | { |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 326 | struct rate_info rinfo; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 327 | /* This should be adjusted for each device */ |
| 328 | int device_constant = 1 << ARITH_SHIFT; |
| 329 | int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT; |
| 330 | int s_unit = 1 << ARITH_SHIFT; |
| 331 | int rate, err; |
| 332 | u32 tx_time, estimated_retx; |
| 333 | u64 result; |
| 334 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 335 | if (sta->fail_avg >= 100) |
| 336 | return MAX_METRIC; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 337 | |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 338 | sta_set_rate_info_tx(sta, &sta->last_tx_rate, &rinfo); |
| 339 | rate = cfg80211_calculate_bitrate(&rinfo); |
| 340 | if (WARN_ON(!rate)) |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 341 | return MAX_METRIC; |
| 342 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 343 | err = (sta->fail_avg << ARITH_SHIFT) / 100; |
| 344 | |
| 345 | /* bitrate is in units of 100 Kbps, while we need rate in units of |
| 346 | * 1Mbps. This will be corrected on tx_time computation. |
| 347 | */ |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 348 | tx_time = (device_constant + 10 * test_frame_len / rate); |
| 349 | estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err)); |
| 350 | result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ; |
| 351 | return (u32)result; |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * hwmp_route_info_get - Update routing info to originator and transmitter |
| 356 | * |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 357 | * @sdata: local mesh subif |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 358 | * @mgmt: mesh management frame |
| 359 | * @hwmp_ie: hwmp information element (PREP or PREQ) |
| 360 | * |
| 361 | * This function updates the path routing information to the originator and the |
Andrey Yurovsky | f99288d | 2009-10-20 12:17:34 -0700 | [diff] [blame] | 362 | * transmitter of a HWMP PREQ or PREP frame. |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 363 | * |
| 364 | * Returns: metric to frame originator or 0 if the frame should not be further |
| 365 | * processed |
| 366 | * |
| 367 | * Notes: this function is the only place (besides user-provided info) where |
| 368 | * path routing information is updated. |
| 369 | */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 370 | static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 371 | struct ieee80211_mgmt *mgmt, |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 372 | u8 *hwmp_ie, enum mpath_frame_type action) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 373 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 374 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 375 | struct mesh_path *mpath; |
| 376 | struct sta_info *sta; |
| 377 | bool fresh_info; |
| 378 | u8 *orig_addr, *ta; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 379 | u32 orig_sn, orig_metric; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 380 | unsigned long orig_lifetime, exp_time; |
| 381 | u32 last_hop_metric, new_metric; |
| 382 | bool process = true; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 383 | |
| 384 | rcu_read_lock(); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 385 | sta = sta_info_get(sdata, mgmt->sa); |
Johannes Berg | dc0b0f7 | 2008-02-23 15:17:20 +0100 | [diff] [blame] | 386 | if (!sta) { |
| 387 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 388 | return 0; |
Johannes Berg | dc0b0f7 | 2008-02-23 15:17:20 +0100 | [diff] [blame] | 389 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 390 | |
| 391 | last_hop_metric = airtime_link_metric_get(local, sta); |
| 392 | /* Update and check originator routing info */ |
| 393 | fresh_info = true; |
| 394 | |
| 395 | switch (action) { |
| 396 | case MPATH_PREQ: |
| 397 | orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 398 | orig_sn = PREQ_IE_ORIG_SN(hwmp_ie); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 399 | orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie); |
| 400 | orig_metric = PREQ_IE_METRIC(hwmp_ie); |
| 401 | break; |
| 402 | case MPATH_PREP: |
Thomas Pedersen | 3c26f1f | 2011-11-24 17:15:22 -0800 | [diff] [blame] | 403 | /* Originator here refers to the MP that was the target in the |
| 404 | * Path Request. We divert from the nomenclature in the draft |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 405 | * so that we can easily use a single function to gather path |
| 406 | * information from both PREQ and PREP frames. |
| 407 | */ |
Thomas Pedersen | 3c26f1f | 2011-11-24 17:15:22 -0800 | [diff] [blame] | 408 | orig_addr = PREP_IE_TARGET_ADDR(hwmp_ie); |
| 409 | orig_sn = PREP_IE_TARGET_SN(hwmp_ie); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 410 | orig_lifetime = PREP_IE_LIFETIME(hwmp_ie); |
| 411 | orig_metric = PREP_IE_METRIC(hwmp_ie); |
| 412 | break; |
| 413 | default: |
Johannes Berg | dc0b0f7 | 2008-02-23 15:17:20 +0100 | [diff] [blame] | 414 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 415 | return 0; |
| 416 | } |
| 417 | new_metric = orig_metric + last_hop_metric; |
| 418 | if (new_metric < orig_metric) |
| 419 | new_metric = MAX_METRIC; |
| 420 | exp_time = TU_TO_EXP_TIME(orig_lifetime); |
| 421 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 422 | if (ether_addr_equal(orig_addr, sdata->vif.addr)) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 423 | /* This MP is the originator, we are not interested in this |
| 424 | * frame, except for updating transmitter's path info. |
| 425 | */ |
| 426 | process = false; |
| 427 | fresh_info = false; |
| 428 | } else { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 429 | mpath = mesh_path_lookup(orig_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 430 | if (mpath) { |
| 431 | spin_lock_bh(&mpath->state_lock); |
| 432 | if (mpath->flags & MESH_PATH_FIXED) |
| 433 | fresh_info = false; |
| 434 | else if ((mpath->flags & MESH_PATH_ACTIVE) && |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 435 | (mpath->flags & MESH_PATH_SN_VALID)) { |
| 436 | if (SN_GT(mpath->sn, orig_sn) || |
| 437 | (mpath->sn == orig_sn && |
Porsch, Marco | 533866b | 2010-02-24 09:53:13 +0100 | [diff] [blame] | 438 | new_metric >= mpath->metric)) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 439 | process = false; |
| 440 | fresh_info = false; |
| 441 | } |
| 442 | } |
| 443 | } else { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 444 | mesh_path_add(orig_addr, sdata); |
| 445 | mpath = mesh_path_lookup(orig_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 446 | if (!mpath) { |
| 447 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | spin_lock_bh(&mpath->state_lock); |
| 451 | } |
| 452 | |
| 453 | if (fresh_info) { |
| 454 | mesh_path_assign_nexthop(mpath, sta); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 455 | mpath->flags |= MESH_PATH_SN_VALID; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 456 | mpath->metric = new_metric; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 457 | mpath->sn = orig_sn; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 458 | mpath->exp_time = time_after(mpath->exp_time, exp_time) |
| 459 | ? mpath->exp_time : exp_time; |
| 460 | mesh_path_activate(mpath); |
| 461 | spin_unlock_bh(&mpath->state_lock); |
| 462 | mesh_path_tx_pending(mpath); |
| 463 | /* draft says preq_id should be saved to, but there does |
| 464 | * not seem to be any use for it, skipping by now |
| 465 | */ |
| 466 | } else |
| 467 | spin_unlock_bh(&mpath->state_lock); |
| 468 | } |
| 469 | |
| 470 | /* Update and check transmitter routing info */ |
| 471 | ta = mgmt->sa; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 472 | if (ether_addr_equal(orig_addr, ta)) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 473 | fresh_info = false; |
| 474 | else { |
| 475 | fresh_info = true; |
| 476 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 477 | mpath = mesh_path_lookup(ta, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 478 | if (mpath) { |
| 479 | spin_lock_bh(&mpath->state_lock); |
| 480 | if ((mpath->flags & MESH_PATH_FIXED) || |
| 481 | ((mpath->flags & MESH_PATH_ACTIVE) && |
| 482 | (last_hop_metric > mpath->metric))) |
| 483 | fresh_info = false; |
| 484 | } else { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 485 | mesh_path_add(ta, sdata); |
| 486 | mpath = mesh_path_lookup(ta, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 487 | if (!mpath) { |
| 488 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | spin_lock_bh(&mpath->state_lock); |
| 492 | } |
| 493 | |
| 494 | if (fresh_info) { |
| 495 | mesh_path_assign_nexthop(mpath, sta); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 496 | mpath->metric = last_hop_metric; |
| 497 | mpath->exp_time = time_after(mpath->exp_time, exp_time) |
| 498 | ? mpath->exp_time : exp_time; |
| 499 | mesh_path_activate(mpath); |
| 500 | spin_unlock_bh(&mpath->state_lock); |
| 501 | mesh_path_tx_pending(mpath); |
| 502 | } else |
| 503 | spin_unlock_bh(&mpath->state_lock); |
| 504 | } |
| 505 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 506 | rcu_read_unlock(); |
| 507 | |
| 508 | return process ? new_metric : 0; |
| 509 | } |
| 510 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 511 | static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 512 | struct ieee80211_mgmt *mgmt, |
David Woo | 57ef5dd | 2009-08-12 11:03:43 -0700 | [diff] [blame] | 513 | u8 *preq_elem, u32 metric) |
| 514 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 515 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 516 | struct mesh_path *mpath = NULL; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 517 | u8 *target_addr, *orig_addr; |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 518 | const u8 *da; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 519 | u8 target_flags, ttl; |
| 520 | u32 orig_sn, target_sn, lifetime; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 521 | bool reply = false; |
| 522 | bool forward = true; |
| 523 | |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 524 | /* Update target SN, if present */ |
| 525 | target_addr = PREQ_IE_TARGET_ADDR(preq_elem); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 526 | orig_addr = PREQ_IE_ORIG_ADDR(preq_elem); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 527 | target_sn = PREQ_IE_TARGET_SN(preq_elem); |
| 528 | orig_sn = PREQ_IE_ORIG_SN(preq_elem); |
| 529 | target_flags = PREQ_IE_TARGET_F(preq_elem); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 530 | |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 531 | mhwmp_dbg("received PREQ from %pM", orig_addr); |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 532 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 533 | if (ether_addr_equal(target_addr, sdata->vif.addr)) { |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 534 | mhwmp_dbg("PREQ is for us"); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 535 | forward = false; |
| 536 | reply = true; |
| 537 | metric = 0; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 538 | if (time_after(jiffies, ifmsh->last_sn_update + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 539 | net_traversal_jiffies(sdata)) || |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 540 | time_before(jiffies, ifmsh->last_sn_update)) { |
| 541 | target_sn = ++ifmsh->sn; |
| 542 | ifmsh->last_sn_update = jiffies; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 543 | } |
| 544 | } else { |
| 545 | rcu_read_lock(); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 546 | mpath = mesh_path_lookup(target_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 547 | if (mpath) { |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 548 | if ((!(mpath->flags & MESH_PATH_SN_VALID)) || |
| 549 | SN_LT(mpath->sn, target_sn)) { |
| 550 | mpath->sn = target_sn; |
| 551 | mpath->flags |= MESH_PATH_SN_VALID; |
| 552 | } else if ((!(target_flags & MP_F_DO)) && |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 553 | (mpath->flags & MESH_PATH_ACTIVE)) { |
| 554 | reply = true; |
| 555 | metric = mpath->metric; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 556 | target_sn = mpath->sn; |
| 557 | if (target_flags & MP_F_RF) |
| 558 | target_flags |= MP_F_DO; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 559 | else |
| 560 | forward = false; |
| 561 | } |
| 562 | } |
| 563 | rcu_read_unlock(); |
| 564 | } |
| 565 | |
| 566 | if (reply) { |
| 567 | lifetime = PREQ_IE_LIFETIME(preq_elem); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 568 | ttl = ifmsh->mshcfg.element_ttl; |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 569 | if (ttl != 0) { |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 570 | mhwmp_dbg("replying to the PREQ"); |
Thomas Pedersen | 3c26f1f | 2011-11-24 17:15:22 -0800 | [diff] [blame] | 571 | mesh_path_sel_frame_tx(MPATH_PREP, 0, orig_addr, |
| 572 | cpu_to_le32(orig_sn), 0, target_addr, |
| 573 | cpu_to_le32(target_sn), mgmt->sa, 0, ttl, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 574 | cpu_to_le32(lifetime), cpu_to_le32(metric), |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 575 | 0, sdata); |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 576 | } else |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 577 | ifmsh->mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 578 | } |
| 579 | |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 580 | if (forward && ifmsh->mshcfg.dot11MeshForwarding) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 581 | u32 preq_id; |
| 582 | u8 hopcount, flags; |
| 583 | |
| 584 | ttl = PREQ_IE_TTL(preq_elem); |
| 585 | lifetime = PREQ_IE_LIFETIME(preq_elem); |
| 586 | if (ttl <= 1) { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 587 | ifmsh->mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 588 | return; |
| 589 | } |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 590 | mhwmp_dbg("forwarding the PREQ from %pM", orig_addr); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 591 | --ttl; |
| 592 | flags = PREQ_IE_FLAGS(preq_elem); |
| 593 | preq_id = PREQ_IE_PREQ_ID(preq_elem); |
| 594 | hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1; |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 595 | da = (mpath && mpath->is_root) ? |
| 596 | mpath->rann_snd_addr : broadcast_addr; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 597 | mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr, |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 598 | cpu_to_le32(orig_sn), target_flags, target_addr, |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 599 | cpu_to_le32(target_sn), da, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 600 | hopcount, ttl, cpu_to_le32(lifetime), |
| 601 | cpu_to_le32(metric), cpu_to_le32(preq_id), |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 602 | sdata); |
Chun-Yeow Yeoh | 7d4e15b | 2012-05-04 14:57:50 +0800 | [diff] [blame] | 603 | if (!is_multicast_ether_addr(da)) |
| 604 | ifmsh->mshstats.fwded_unicast++; |
| 605 | else |
| 606 | ifmsh->mshstats.fwded_mcast++; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 607 | ifmsh->mshstats.fwded_frames++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 612 | static inline struct sta_info * |
| 613 | next_hop_deref_protected(struct mesh_path *mpath) |
| 614 | { |
| 615 | return rcu_dereference_protected(mpath->next_hop, |
| 616 | lockdep_is_held(&mpath->state_lock)); |
| 617 | } |
| 618 | |
| 619 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 620 | static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 621 | struct ieee80211_mgmt *mgmt, |
| 622 | u8 *prep_elem, u32 metric) |
| 623 | { |
Chun-Yeow Yeoh | d665508 | 2012-03-02 02:03:19 +0800 | [diff] [blame] | 624 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 625 | struct mesh_path *mpath; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 626 | u8 *target_addr, *orig_addr; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 627 | u8 ttl, hopcount, flags; |
| 628 | u8 next_hop[ETH_ALEN]; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 629 | u32 target_sn, orig_sn, lifetime; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 630 | |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 631 | mhwmp_dbg("received PREP from %pM", PREP_IE_ORIG_ADDR(prep_elem)); |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 632 | |
Thomas Pedersen | 3c26f1f | 2011-11-24 17:15:22 -0800 | [diff] [blame] | 633 | orig_addr = PREP_IE_ORIG_ADDR(prep_elem); |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 634 | if (ether_addr_equal(orig_addr, sdata->vif.addr)) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 635 | /* destination, no forwarding required */ |
| 636 | return; |
| 637 | |
Chun-Yeow Yeoh | d665508 | 2012-03-02 02:03:19 +0800 | [diff] [blame] | 638 | if (!ifmsh->mshcfg.dot11MeshForwarding) |
| 639 | return; |
| 640 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 641 | ttl = PREP_IE_TTL(prep_elem); |
| 642 | if (ttl <= 1) { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 643 | sdata->u.mesh.mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 644 | return; |
| 645 | } |
| 646 | |
| 647 | rcu_read_lock(); |
Thomas Pedersen | 3c26f1f | 2011-11-24 17:15:22 -0800 | [diff] [blame] | 648 | mpath = mesh_path_lookup(orig_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 649 | if (mpath) |
| 650 | spin_lock_bh(&mpath->state_lock); |
| 651 | else |
| 652 | goto fail; |
| 653 | if (!(mpath->flags & MESH_PATH_ACTIVE)) { |
| 654 | spin_unlock_bh(&mpath->state_lock); |
| 655 | goto fail; |
| 656 | } |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 657 | memcpy(next_hop, next_hop_deref_protected(mpath)->sta.addr, ETH_ALEN); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 658 | spin_unlock_bh(&mpath->state_lock); |
| 659 | --ttl; |
| 660 | flags = PREP_IE_FLAGS(prep_elem); |
| 661 | lifetime = PREP_IE_LIFETIME(prep_elem); |
| 662 | hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1; |
Thomas Pedersen | 3c26f1f | 2011-11-24 17:15:22 -0800 | [diff] [blame] | 663 | target_addr = PREP_IE_TARGET_ADDR(prep_elem); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 664 | target_sn = PREP_IE_TARGET_SN(prep_elem); |
| 665 | orig_sn = PREP_IE_ORIG_SN(prep_elem); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 666 | |
| 667 | mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr, |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 668 | cpu_to_le32(orig_sn), 0, target_addr, |
Porsch, Marco | 533866b | 2010-02-24 09:53:13 +0100 | [diff] [blame] | 669 | cpu_to_le32(target_sn), next_hop, hopcount, |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 670 | ttl, cpu_to_le32(lifetime), cpu_to_le32(metric), |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 671 | 0, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 672 | rcu_read_unlock(); |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 673 | |
| 674 | sdata->u.mesh.mshstats.fwded_unicast++; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 675 | sdata->u.mesh.mshstats.fwded_frames++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 676 | return; |
| 677 | |
| 678 | fail: |
| 679 | rcu_read_unlock(); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 680 | sdata->u.mesh.mshstats.dropped_frames_no_route++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 681 | } |
| 682 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 683 | static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 684 | struct ieee80211_mgmt *mgmt, u8 *perr_elem) |
| 685 | { |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 686 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 687 | struct mesh_path *mpath; |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 688 | u8 ttl; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 689 | u8 *ta, *target_addr; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 690 | u32 target_sn; |
| 691 | u16 target_rcode; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 692 | |
| 693 | ta = mgmt->sa; |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 694 | ttl = PERR_IE_TTL(perr_elem); |
| 695 | if (ttl <= 1) { |
| 696 | ifmsh->mshstats.dropped_frames_ttl++; |
| 697 | return; |
| 698 | } |
| 699 | ttl--; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 700 | target_addr = PERR_IE_TARGET_ADDR(perr_elem); |
| 701 | target_sn = PERR_IE_TARGET_SN(perr_elem); |
| 702 | target_rcode = PERR_IE_TARGET_RCODE(perr_elem); |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 703 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 704 | rcu_read_lock(); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 705 | mpath = mesh_path_lookup(target_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 706 | if (mpath) { |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 707 | struct sta_info *sta; |
| 708 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 709 | spin_lock_bh(&mpath->state_lock); |
Felix Fietkau | 888d04d | 2012-03-01 15:22:09 +0100 | [diff] [blame] | 710 | sta = next_hop_deref_protected(mpath); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 711 | if (mpath->flags & MESH_PATH_ACTIVE && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 712 | ether_addr_equal(ta, sta->sta.addr) && |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 713 | (!(mpath->flags & MESH_PATH_SN_VALID) || |
| 714 | SN_GT(target_sn, mpath->sn))) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 715 | mpath->flags &= ~MESH_PATH_ACTIVE; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 716 | mpath->sn = target_sn; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 717 | spin_unlock_bh(&mpath->state_lock); |
Chun-Yeow Yeoh | d665508 | 2012-03-02 02:03:19 +0800 | [diff] [blame] | 718 | if (!ifmsh->mshcfg.dot11MeshForwarding) |
| 719 | goto endperr; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 720 | mesh_path_error_tx(ttl, target_addr, cpu_to_le32(target_sn), |
| 721 | cpu_to_le16(target_rcode), |
Johannes Berg | 15ff636 | 2009-11-17 13:34:04 +0100 | [diff] [blame] | 722 | broadcast_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 723 | } else |
| 724 | spin_unlock_bh(&mpath->state_lock); |
| 725 | } |
Chun-Yeow Yeoh | d665508 | 2012-03-02 02:03:19 +0800 | [diff] [blame] | 726 | endperr: |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 727 | rcu_read_unlock(); |
| 728 | } |
| 729 | |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 730 | static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata, |
| 731 | struct ieee80211_mgmt *mgmt, |
| 732 | struct ieee80211_rann_ie *rann) |
| 733 | { |
| 734 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 735 | struct ieee80211_local *local = sdata->local; |
| 736 | struct sta_info *sta; |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 737 | struct mesh_path *mpath; |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 738 | u8 ttl, flags, hopcount; |
| 739 | u8 *orig_addr; |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 740 | u32 orig_sn, metric, metric_txsta, interval; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 741 | bool root_is_gate; |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 742 | |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 743 | ttl = rann->rann_ttl; |
| 744 | if (ttl <= 1) { |
| 745 | ifmsh->mshstats.dropped_frames_ttl++; |
| 746 | return; |
| 747 | } |
| 748 | ttl--; |
| 749 | flags = rann->rann_flags; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 750 | root_is_gate = !!(flags & RANN_FLAG_IS_GATE); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 751 | orig_addr = rann->rann_addr; |
Chun-Yeow Yeoh | 292c41a | 2012-03-19 21:38:46 +0800 | [diff] [blame] | 752 | orig_sn = le32_to_cpu(rann->rann_seq); |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 753 | interval = le32_to_cpu(rann->rann_interval); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 754 | hopcount = rann->rann_hopcount; |
Rui Paulo | a6a58b4 | 2009-11-09 23:46:51 +0000 | [diff] [blame] | 755 | hopcount++; |
Chun-Yeow Yeoh | 292c41a | 2012-03-19 21:38:46 +0800 | [diff] [blame] | 756 | metric = le32_to_cpu(rann->rann_metric); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 757 | |
| 758 | /* Ignore our own RANNs */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 759 | if (ether_addr_equal(orig_addr, sdata->vif.addr)) |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 760 | return; |
| 761 | |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 762 | mhwmp_dbg("received RANN from %pM via neighbour %pM (is_gate=%d)", |
| 763 | orig_addr, mgmt->sa, root_is_gate); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 764 | |
| 765 | rcu_read_lock(); |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 766 | sta = sta_info_get(sdata, mgmt->sa); |
| 767 | if (!sta) { |
| 768 | rcu_read_unlock(); |
| 769 | return; |
| 770 | } |
| 771 | |
| 772 | metric_txsta = airtime_link_metric_get(local, sta); |
| 773 | |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 774 | mpath = mesh_path_lookup(orig_addr, sdata); |
| 775 | if (!mpath) { |
| 776 | mesh_path_add(orig_addr, sdata); |
| 777 | mpath = mesh_path_lookup(orig_addr, sdata); |
| 778 | if (!mpath) { |
| 779 | rcu_read_unlock(); |
| 780 | sdata->u.mesh.mshstats.dropped_frames_no_route++; |
| 781 | return; |
| 782 | } |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 783 | } |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 784 | |
| 785 | if ((!(mpath->flags & (MESH_PATH_ACTIVE | MESH_PATH_RESOLVING)) || |
| 786 | time_after(jiffies, mpath->exp_time - 1*HZ)) && |
| 787 | !(mpath->flags & MESH_PATH_FIXED)) { |
| 788 | mhwmp_dbg("%s time to refresh root mpath %pM", sdata->name, |
| 789 | orig_addr); |
| 790 | mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH); |
| 791 | } |
| 792 | |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 793 | if ((SN_LT(mpath->sn, orig_sn) || (mpath->sn == orig_sn && |
| 794 | metric < mpath->rann_metric)) && ifmsh->mshcfg.dot11MeshForwarding) { |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 795 | mesh_path_sel_frame_tx(MPATH_RANN, flags, orig_addr, |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 796 | cpu_to_le32(orig_sn), |
Johannes Berg | 15ff636 | 2009-11-17 13:34:04 +0100 | [diff] [blame] | 797 | 0, NULL, 0, broadcast_addr, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 798 | hopcount, ttl, cpu_to_le32(interval), |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 799 | cpu_to_le32(metric + metric_txsta), |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 800 | 0, sdata); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 801 | mpath->sn = orig_sn; |
Chun-Yeow Yeoh | d2a079f | 2012-03-23 18:48:51 +0800 | [diff] [blame] | 802 | mpath->rann_metric = metric + metric_txsta; |
Chun-Yeow Yeoh | 35bcd59 | 2012-04-10 12:31:56 +0800 | [diff] [blame] | 803 | /* Recording RANNs sender address to send individually |
| 804 | * addressed PREQs destined for root mesh STA */ |
| 805 | memcpy(mpath->rann_snd_addr, mgmt->sa, ETH_ALEN); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 806 | } |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 807 | |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 808 | mpath->is_root = true; |
| 809 | |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 810 | if (root_is_gate) |
| 811 | mesh_path_add_gate(mpath); |
| 812 | |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 813 | rcu_read_unlock(); |
| 814 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 815 | |
| 816 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 817 | void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 818 | struct ieee80211_mgmt *mgmt, |
| 819 | size_t len) |
| 820 | { |
| 821 | struct ieee802_11_elems elems; |
| 822 | size_t baselen; |
| 823 | u32 last_hop_metric; |
Javier Cardona | 9709131 | 2011-10-06 14:54:22 -0700 | [diff] [blame] | 824 | struct sta_info *sta; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 825 | |
Johannes Berg | 9c80d3d | 2008-09-08 15:41:59 +0200 | [diff] [blame] | 826 | /* need action_code */ |
| 827 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
| 828 | return; |
| 829 | |
Javier Cardona | 9709131 | 2011-10-06 14:54:22 -0700 | [diff] [blame] | 830 | rcu_read_lock(); |
| 831 | sta = sta_info_get(sdata, mgmt->sa); |
| 832 | if (!sta || sta->plink_state != NL80211_PLINK_ESTAB) { |
| 833 | rcu_read_unlock(); |
| 834 | return; |
| 835 | } |
| 836 | rcu_read_unlock(); |
| 837 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 838 | baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt; |
| 839 | ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable, |
| 840 | len - baselen, &elems); |
| 841 | |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 842 | if (elems.preq) { |
| 843 | if (elems.preq_len != 37) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 844 | /* Right now we support just 1 destination and no AE */ |
| 845 | return; |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 846 | last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.preq, |
| 847 | MPATH_PREQ); |
| 848 | if (last_hop_metric) |
| 849 | hwmp_preq_frame_process(sdata, mgmt, elems.preq, |
| 850 | last_hop_metric); |
| 851 | } |
| 852 | if (elems.prep) { |
| 853 | if (elems.prep_len != 31) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 854 | /* Right now we support no AE */ |
| 855 | return; |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 856 | last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.prep, |
| 857 | MPATH_PREP); |
| 858 | if (last_hop_metric) |
| 859 | hwmp_prep_frame_process(sdata, mgmt, elems.prep, |
| 860 | last_hop_metric); |
| 861 | } |
| 862 | if (elems.perr) { |
Rui Paulo | d611f06 | 2009-11-09 23:46:50 +0000 | [diff] [blame] | 863 | if (elems.perr_len != 15) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 864 | /* Right now we support only one destination per PERR */ |
| 865 | return; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 866 | hwmp_perr_frame_process(sdata, mgmt, elems.perr); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 867 | } |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame] | 868 | if (elems.rann) |
| 869 | hwmp_rann_frame_process(sdata, mgmt, elems.rann); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | /** |
| 873 | * mesh_queue_preq - queue a PREQ to a given destination |
| 874 | * |
| 875 | * @mpath: mesh path to discover |
| 876 | * @flags: special attributes of the PREQ to be sent |
| 877 | * |
| 878 | * Locking: the function must be called from within a rcu read lock block. |
| 879 | * |
| 880 | */ |
| 881 | static void mesh_queue_preq(struct mesh_path *mpath, u8 flags) |
| 882 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 883 | struct ieee80211_sub_if_data *sdata = mpath->sdata; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 884 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 885 | struct mesh_preq_queue *preq_node; |
| 886 | |
Andrey Yurovsky | 59615b5 | 2009-06-25 16:07:42 -0700 | [diff] [blame] | 887 | preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 888 | if (!preq_node) { |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 889 | mhwmp_dbg("could not allocate PREQ node"); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 890 | return; |
| 891 | } |
| 892 | |
Baruch Siach | 987dafa | 2011-07-28 08:51:05 +0300 | [diff] [blame] | 893 | spin_lock_bh(&ifmsh->mesh_preq_queue_lock); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 894 | if (ifmsh->preq_queue_len == MAX_PREQ_QUEUE_LEN) { |
Baruch Siach | 987dafa | 2011-07-28 08:51:05 +0300 | [diff] [blame] | 895 | spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 896 | kfree(preq_node); |
| 897 | if (printk_ratelimit()) |
Javier Cardona | 7646887 | 2011-08-09 16:45:04 -0700 | [diff] [blame] | 898 | mhwmp_dbg("PREQ node queue full"); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 899 | return; |
| 900 | } |
| 901 | |
Johannes Berg | f2dc798 | 2011-11-18 15:27:31 +0100 | [diff] [blame] | 902 | spin_lock(&mpath->state_lock); |
Javier Cardona | f3011cf | 2011-11-03 21:11:10 -0700 | [diff] [blame] | 903 | if (mpath->flags & MESH_PATH_REQ_QUEUED) { |
Johannes Berg | f2dc798 | 2011-11-18 15:27:31 +0100 | [diff] [blame] | 904 | spin_unlock(&mpath->state_lock); |
Javier Cardona | f3011cf | 2011-11-03 21:11:10 -0700 | [diff] [blame] | 905 | spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); |
Dan Carpenter | 88d5346 | 2011-11-15 09:33:31 +0300 | [diff] [blame] | 906 | kfree(preq_node); |
Javier Cardona | f3011cf | 2011-11-03 21:11:10 -0700 | [diff] [blame] | 907 | return; |
| 908 | } |
| 909 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 910 | memcpy(preq_node->dst, mpath->dst, ETH_ALEN); |
| 911 | preq_node->flags = flags; |
| 912 | |
Javier Cardona | f3011cf | 2011-11-03 21:11:10 -0700 | [diff] [blame] | 913 | mpath->flags |= MESH_PATH_REQ_QUEUED; |
Johannes Berg | f2dc798 | 2011-11-18 15:27:31 +0100 | [diff] [blame] | 914 | spin_unlock(&mpath->state_lock); |
Javier Cardona | f3011cf | 2011-11-03 21:11:10 -0700 | [diff] [blame] | 915 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 916 | list_add_tail(&preq_node->list, &ifmsh->preq_queue.list); |
| 917 | ++ifmsh->preq_queue_len; |
Baruch Siach | 987dafa | 2011-07-28 08:51:05 +0300 | [diff] [blame] | 918 | spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 919 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 920 | if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata))) |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 921 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 922 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 923 | else if (time_before(jiffies, ifmsh->last_preq)) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 924 | /* avoid long wait if did not send preqs for a long time |
| 925 | * and jiffies wrapped around |
| 926 | */ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 927 | ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1; |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 928 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 929 | } else |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 930 | mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 931 | min_preq_int_jiff(sdata)); |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * mesh_path_start_discovery - launch a path discovery from the PREQ queue |
| 936 | * |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 937 | * @sdata: local mesh subif |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 938 | */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 939 | void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 940 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 941 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 942 | struct mesh_preq_queue *preq_node; |
| 943 | struct mesh_path *mpath; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 944 | u8 ttl, target_flags; |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 945 | const u8 *da; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 946 | u32 lifetime; |
| 947 | |
Johannes Berg | a43816d | 2009-07-10 11:39:26 +0200 | [diff] [blame] | 948 | spin_lock_bh(&ifmsh->mesh_preq_queue_lock); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 949 | if (!ifmsh->preq_queue_len || |
| 950 | time_before(jiffies, ifmsh->last_preq + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 951 | min_preq_int_jiff(sdata))) { |
Johannes Berg | a43816d | 2009-07-10 11:39:26 +0200 | [diff] [blame] | 952 | spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 953 | return; |
| 954 | } |
| 955 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 956 | preq_node = list_first_entry(&ifmsh->preq_queue.list, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 957 | struct mesh_preq_queue, list); |
| 958 | list_del(&preq_node->list); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 959 | --ifmsh->preq_queue_len; |
Johannes Berg | a43816d | 2009-07-10 11:39:26 +0200 | [diff] [blame] | 960 | spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 961 | |
| 962 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 963 | mpath = mesh_path_lookup(preq_node->dst, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 964 | if (!mpath) |
| 965 | goto enddiscovery; |
| 966 | |
| 967 | spin_lock_bh(&mpath->state_lock); |
Javier Cardona | f3011cf | 2011-11-03 21:11:10 -0700 | [diff] [blame] | 968 | mpath->flags &= ~MESH_PATH_REQ_QUEUED; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 969 | if (preq_node->flags & PREQ_Q_F_START) { |
| 970 | if (mpath->flags & MESH_PATH_RESOLVING) { |
| 971 | spin_unlock_bh(&mpath->state_lock); |
| 972 | goto enddiscovery; |
| 973 | } else { |
| 974 | mpath->flags &= ~MESH_PATH_RESOLVED; |
| 975 | mpath->flags |= MESH_PATH_RESOLVING; |
| 976 | mpath->discovery_retries = 0; |
| 977 | mpath->discovery_timeout = disc_timeout_jiff(sdata); |
| 978 | } |
| 979 | } else if (!(mpath->flags & MESH_PATH_RESOLVING) || |
| 980 | mpath->flags & MESH_PATH_RESOLVED) { |
| 981 | mpath->flags &= ~MESH_PATH_RESOLVING; |
| 982 | spin_unlock_bh(&mpath->state_lock); |
| 983 | goto enddiscovery; |
| 984 | } |
| 985 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 986 | ifmsh->last_preq = jiffies; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 987 | |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 988 | if (time_after(jiffies, ifmsh->last_sn_update + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 989 | net_traversal_jiffies(sdata)) || |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 990 | time_before(jiffies, ifmsh->last_sn_update)) { |
| 991 | ++ifmsh->sn; |
| 992 | sdata->u.mesh.last_sn_update = jiffies; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 993 | } |
| 994 | lifetime = default_lifetime(sdata); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 995 | ttl = sdata->u.mesh.mshcfg.element_ttl; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 996 | if (ttl == 0) { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 997 | sdata->u.mesh.mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 998 | spin_unlock_bh(&mpath->state_lock); |
| 999 | goto enddiscovery; |
| 1000 | } |
| 1001 | |
| 1002 | if (preq_node->flags & PREQ_Q_F_REFRESH) |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1003 | target_flags = MP_F_DO; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1004 | else |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1005 | target_flags = MP_F_RF; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1006 | |
| 1007 | spin_unlock_bh(&mpath->state_lock); |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 1008 | da = (mpath->is_root) ? mpath->rann_snd_addr : broadcast_addr; |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1009 | mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->vif.addr, |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1010 | cpu_to_le32(ifmsh->sn), target_flags, mpath->dst, |
Chun-Yeow Yeoh | 3d045a5 | 2012-02-28 22:00:06 +0800 | [diff] [blame] | 1011 | cpu_to_le32(mpath->sn), da, 0, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 1012 | ttl, cpu_to_le32(lifetime), 0, |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 1013 | cpu_to_le32(ifmsh->preq_id++), sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1014 | mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout); |
| 1015 | |
| 1016 | enddiscovery: |
| 1017 | rcu_read_unlock(); |
| 1018 | kfree(preq_node); |
| 1019 | } |
| 1020 | |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1021 | /* mesh_nexthop_resolve - lookup next hop for given skb and start path |
| 1022 | * discovery if no forwarding information is found. |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1023 | * |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1024 | * @skb: 802.11 frame to be sent |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1025 | * @sdata: network subif the frame will be sent through |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1026 | * |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1027 | * Returns: 0 if the next hop was found and -ENOENT if the frame was queued. |
| 1028 | * skb is freeed here if no mpath could be allocated. |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1029 | */ |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1030 | int mesh_nexthop_resolve(struct sk_buff *skb, |
| 1031 | struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1032 | { |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 1033 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1034 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1035 | struct mesh_path *mpath; |
| 1036 | struct sk_buff *skb_to_free = NULL; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1037 | u8 *target_addr = hdr->addr3; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1038 | int err = 0; |
| 1039 | |
| 1040 | rcu_read_lock(); |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1041 | err = mesh_nexthop_lookup(skb, sdata); |
| 1042 | if (!err) |
| 1043 | goto endlookup; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1044 | |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1045 | /* no nexthop found, start resolving */ |
| 1046 | mpath = mesh_path_lookup(target_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1047 | if (!mpath) { |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1048 | mesh_path_add(target_addr, sdata); |
| 1049 | mpath = mesh_path_lookup(target_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1050 | if (!mpath) { |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1051 | mesh_path_discard_frame(skb, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1052 | err = -ENOSPC; |
| 1053 | goto endlookup; |
| 1054 | } |
| 1055 | } |
| 1056 | |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1057 | if (!(mpath->flags & MESH_PATH_RESOLVING)) |
| 1058 | mesh_queue_preq(mpath, PREQ_Q_F_START); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1059 | |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1060 | if (skb_queue_len(&mpath->frame_queue) >= MESH_FRAME_QUEUE_LEN) |
| 1061 | skb_to_free = skb_dequeue(&mpath->frame_queue); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1062 | |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1063 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
| 1064 | ieee80211_set_qos_hdr(sdata, skb); |
| 1065 | skb_queue_tail(&mpath->frame_queue, skb); |
| 1066 | err = -ENOENT; |
| 1067 | if (skb_to_free) |
| 1068 | mesh_path_discard_frame(skb_to_free, sdata); |
| 1069 | |
| 1070 | endlookup: |
| 1071 | rcu_read_unlock(); |
| 1072 | return err; |
| 1073 | } |
| 1074 | /** |
| 1075 | * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame. Calling |
| 1076 | * this function is considered "using" the associated mpath, so preempt a path |
| 1077 | * refresh if this mpath expires soon. |
| 1078 | * |
| 1079 | * @skb: 802.11 frame to be sent |
| 1080 | * @sdata: network subif the frame will be sent through |
| 1081 | * |
| 1082 | * Returns: 0 if the next hop was found. Nonzero otherwise. |
| 1083 | */ |
| 1084 | int mesh_nexthop_lookup(struct sk_buff *skb, |
| 1085 | struct ieee80211_sub_if_data *sdata) |
| 1086 | { |
| 1087 | struct mesh_path *mpath; |
| 1088 | struct sta_info *next_hop; |
| 1089 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 1090 | u8 *target_addr = hdr->addr3; |
| 1091 | int err = -ENOENT; |
| 1092 | |
| 1093 | rcu_read_lock(); |
| 1094 | mpath = mesh_path_lookup(target_addr, sdata); |
| 1095 | |
| 1096 | if (!mpath || !(mpath->flags & MESH_PATH_ACTIVE)) |
| 1097 | goto endlookup; |
| 1098 | |
| 1099 | if (time_after(jiffies, |
| 1100 | mpath->exp_time - |
| 1101 | msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 1102 | ether_addr_equal(sdata->vif.addr, hdr->addr4) && |
Thomas Pedersen | 0cfda85 | 2011-11-24 17:15:25 -0800 | [diff] [blame] | 1103 | !(mpath->flags & MESH_PATH_RESOLVING) && |
| 1104 | !(mpath->flags & MESH_PATH_FIXED)) |
| 1105 | mesh_queue_preq(mpath, PREQ_Q_F_START | PREQ_Q_F_REFRESH); |
| 1106 | |
| 1107 | next_hop = rcu_dereference(mpath->next_hop); |
| 1108 | if (next_hop) { |
| 1109 | memcpy(hdr->addr1, next_hop->sta.addr, ETH_ALEN); |
| 1110 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
| 1111 | err = 0; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | endlookup: |
| 1115 | rcu_read_unlock(); |
| 1116 | return err; |
| 1117 | } |
| 1118 | |
| 1119 | void mesh_path_timer(unsigned long data) |
| 1120 | { |
Johannes Berg | dea4096 | 2011-05-12 15:03:32 +0200 | [diff] [blame] | 1121 | struct mesh_path *mpath = (void *) data; |
| 1122 | struct ieee80211_sub_if_data *sdata = mpath->sdata; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 1123 | int ret; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1124 | |
Johannes Berg | dea4096 | 2011-05-12 15:03:32 +0200 | [diff] [blame] | 1125 | if (sdata->local->quiescing) |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1126 | return; |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1127 | |
| 1128 | spin_lock_bh(&mpath->state_lock); |
Luis Carlos Cobo | cfa22c7 | 2008-02-29 15:04:13 -0800 | [diff] [blame] | 1129 | if (mpath->flags & MESH_PATH_RESOLVED || |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 1130 | (!(mpath->flags & MESH_PATH_RESOLVING))) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1131 | mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED); |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 1132 | spin_unlock_bh(&mpath->state_lock); |
| 1133 | } else if (mpath->discovery_retries < max_preq_retries(sdata)) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1134 | ++mpath->discovery_retries; |
| 1135 | mpath->discovery_timeout *= 2; |
Javier Cardona | f3011cf | 2011-11-03 21:11:10 -0700 | [diff] [blame] | 1136 | mpath->flags &= ~MESH_PATH_REQ_QUEUED; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 1137 | spin_unlock_bh(&mpath->state_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1138 | mesh_queue_preq(mpath, 0); |
| 1139 | } else { |
| 1140 | mpath->flags = 0; |
| 1141 | mpath->exp_time = jiffies; |
Javier Cardona | 5ee68e5 | 2011-08-09 16:45:08 -0700 | [diff] [blame] | 1142 | spin_unlock_bh(&mpath->state_lock); |
| 1143 | if (!mpath->is_gate && mesh_gate_num(sdata) > 0) { |
| 1144 | ret = mesh_path_send_to_gates(mpath); |
| 1145 | if (ret) |
| 1146 | mhwmp_dbg("no gate was reachable"); |
| 1147 | } else |
| 1148 | mesh_path_flush_pending(mpath); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1149 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1150 | } |
Rui Paulo | e304bfd | 2009-11-09 23:46:56 +0000 | [diff] [blame] | 1151 | |
| 1152 | void |
| 1153 | mesh_path_tx_root_frame(struct ieee80211_sub_if_data *sdata) |
| 1154 | { |
| 1155 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 1156 | u32 interval = ifmsh->mshcfg.dot11MeshHWMPRannInterval; |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 1157 | u8 flags; |
Rui Paulo | e304bfd | 2009-11-09 23:46:56 +0000 | [diff] [blame] | 1158 | |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 1159 | flags = (ifmsh->mshcfg.dot11MeshGateAnnouncementProtocol) |
| 1160 | ? RANN_FLAG_IS_GATE : 0; |
| 1161 | mesh_path_sel_frame_tx(MPATH_RANN, flags, sdata->vif.addr, |
Rui Paulo | e304bfd | 2009-11-09 23:46:56 +0000 | [diff] [blame] | 1162 | cpu_to_le32(++ifmsh->sn), |
Johannes Berg | 15ff636 | 2009-11-17 13:34:04 +0100 | [diff] [blame] | 1163 | 0, NULL, 0, broadcast_addr, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 1164 | 0, sdata->u.mesh.mshcfg.element_ttl, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 1165 | cpu_to_le32(interval), 0, 0, sdata); |
Rui Paulo | e304bfd | 2009-11-09 23:46:56 +0000 | [diff] [blame] | 1166 | } |