Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 open80211s Ltd. |
| 3 | * Author: Luis Carlos Cobo <luisca@cozybit.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include "mesh.h" |
| 11 | |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 12 | #ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG |
| 13 | #define mhwmp_dbg(fmt, args...) printk(KERN_DEBUG "Mesh HWMP: " fmt, ##args) |
| 14 | #else |
| 15 | #define mhwmp_dbg(fmt, args...) do { (void)(0); } while (0) |
| 16 | #endif |
| 17 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 18 | #define TEST_FRAME_LEN 8192 |
| 19 | #define MAX_METRIC 0xffffffff |
| 20 | #define ARITH_SHIFT 8 |
| 21 | |
| 22 | /* Number of frames buffered per destination for unresolved destinations */ |
| 23 | #define MESH_FRAME_QUEUE_LEN 10 |
| 24 | #define MAX_PREQ_QUEUE_LEN 64 |
| 25 | |
| 26 | /* Destination only */ |
| 27 | #define MP_F_DO 0x1 |
| 28 | /* Reply and forward */ |
| 29 | #define MP_F_RF 0x2 |
| 30 | |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 31 | static void mesh_queue_preq(struct mesh_path *, u8); |
| 32 | |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 33 | static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae) |
| 34 | { |
| 35 | if (ae) |
| 36 | offset += 6; |
Harvey Harrison | ae7245c | 2008-05-01 22:19:33 -0700 | [diff] [blame] | 37 | return get_unaligned_le32(preq_elem + offset); |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 40 | /* HWMP IE processing macros */ |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 41 | #define AE_F (1<<6) |
| 42 | #define AE_F_SET(x) (*x & AE_F) |
| 43 | #define PREQ_IE_FLAGS(x) (*(x)) |
| 44 | #define PREQ_IE_HOPCOUNT(x) (*(x + 1)) |
| 45 | #define PREQ_IE_TTL(x) (*(x + 2)) |
| 46 | #define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0) |
| 47 | #define PREQ_IE_ORIG_ADDR(x) (x + 7) |
| 48 | #define PREQ_IE_ORIG_DSN(x) u32_field_get(x, 13, 0); |
| 49 | #define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x)); |
| 50 | #define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x)); |
| 51 | #define PREQ_IE_DST_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26)) |
| 52 | #define PREQ_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27) |
| 53 | #define PREQ_IE_DST_DSN(x) u32_field_get(x, 33, AE_F_SET(x)); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 54 | |
| 55 | |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 56 | #define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x) |
| 57 | #define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x) |
| 58 | #define PREP_IE_TTL(x) PREQ_IE_TTL(x) |
| 59 | #define PREP_IE_ORIG_ADDR(x) (x + 3) |
| 60 | #define PREP_IE_ORIG_DSN(x) u32_field_get(x, 9, 0); |
| 61 | #define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x)); |
| 62 | #define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x)); |
| 63 | #define PREP_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21) |
| 64 | #define PREP_IE_DST_DSN(x) u32_field_get(x, 27, AE_F_SET(x)); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 65 | |
Luis Carlos Cobo | a00de5d | 2008-02-29 17:07:54 -0800 | [diff] [blame] | 66 | #define PERR_IE_DST_ADDR(x) (x + 2) |
| 67 | #define PERR_IE_DST_DSN(x) u32_field_get(x, 8, 0); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 68 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 69 | #define MSEC_TO_TU(x) (x*1000/1024) |
| 70 | #define DSN_GT(x, y) ((long) (y) - (long) (x) < 0) |
| 71 | #define DSN_LT(x, y) ((long) (x) - (long) (y) < 0) |
| 72 | |
| 73 | #define net_traversal_jiffies(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 74 | msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 75 | #define default_lifetime(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 76 | MSEC_TO_TU(s->u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 77 | #define min_preq_int_jiff(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 78 | (msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval)) |
| 79 | #define max_preq_retries(s) (s->u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 80 | #define disc_timeout_jiff(s) \ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 81 | msecs_to_jiffies(sdata->u.mesh.mshcfg.min_discovery_timeout) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 82 | |
| 83 | enum mpath_frame_type { |
| 84 | MPATH_PREQ = 0, |
| 85 | MPATH_PREP, |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 86 | MPATH_PERR, |
| 87 | MPATH_RANN |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags, |
| 91 | u8 *orig_addr, __le32 orig_dsn, u8 dst_flags, u8 *dst, |
| 92 | __le32 dst_dsn, u8 *da, u8 hop_count, u8 ttl, __le32 lifetime, |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 93 | __le32 metric, __le32 preq_id, struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 94 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 95 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 96 | struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
| 97 | struct ieee80211_mgmt *mgmt; |
| 98 | u8 *pos; |
| 99 | int ie_len; |
| 100 | |
| 101 | if (!skb) |
| 102 | return -1; |
| 103 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 104 | /* 25 is the size of the common mgmt part (24) plus the size of the |
| 105 | * common action part (1) |
| 106 | */ |
| 107 | mgmt = (struct ieee80211_mgmt *) |
| 108 | skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action)); |
| 109 | memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action)); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 110 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 111 | IEEE80211_STYPE_ACTION); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 112 | |
| 113 | memcpy(mgmt->da, da, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 114 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 115 | /* BSSID == SA */ |
| 116 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 117 | mgmt->u.action.category = MESH_PATH_SEL_CATEGORY; |
Rui Paulo | 095de01 | 2009-11-09 23:46:44 +0000 | [diff] [blame] | 118 | mgmt->u.action.u.mesh_action.action_code = MESH_PATH_SEL_ACTION; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 119 | |
| 120 | switch (action) { |
| 121 | case MPATH_PREQ: |
Rui Paulo | f3c0d88 | 2009-11-09 23:46:47 +0000 | [diff] [blame] | 122 | mhwmp_dbg("sending PREQ to %pM\n", dst); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 123 | ie_len = 37; |
| 124 | pos = skb_put(skb, 2 + ie_len); |
| 125 | *pos++ = WLAN_EID_PREQ; |
| 126 | break; |
| 127 | case MPATH_PREP: |
Rui Paulo | f3c0d88 | 2009-11-09 23:46:47 +0000 | [diff] [blame] | 128 | mhwmp_dbg("sending PREP to %pM\n", dst); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 129 | ie_len = 31; |
| 130 | pos = skb_put(skb, 2 + ie_len); |
| 131 | *pos++ = WLAN_EID_PREP; |
| 132 | break; |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 133 | case MPATH_RANN: |
| 134 | mhwmp_dbg("sending RANN from %pM\n", orig_addr); |
| 135 | ie_len = sizeof(struct ieee80211_rann_ie); |
| 136 | pos = skb_put(skb, 2 + ie_len); |
| 137 | *pos++ = WLAN_EID_RANN; |
| 138 | break; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 139 | default: |
Patrick McHardy | 812714d | 2008-05-06 12:52:07 +0200 | [diff] [blame] | 140 | kfree_skb(skb); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 141 | return -ENOTSUPP; |
| 142 | break; |
| 143 | } |
| 144 | *pos++ = ie_len; |
| 145 | *pos++ = flags; |
| 146 | *pos++ = hop_count; |
| 147 | *pos++ = ttl; |
| 148 | if (action == MPATH_PREQ) { |
| 149 | memcpy(pos, &preq_id, 4); |
| 150 | pos += 4; |
| 151 | } |
| 152 | memcpy(pos, orig_addr, ETH_ALEN); |
| 153 | pos += ETH_ALEN; |
| 154 | memcpy(pos, &orig_dsn, 4); |
| 155 | pos += 4; |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 156 | if (action != MPATH_RANN) { |
| 157 | memcpy(pos, &lifetime, 4); |
| 158 | pos += 4; |
| 159 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 160 | memcpy(pos, &metric, 4); |
| 161 | pos += 4; |
| 162 | if (action == MPATH_PREQ) { |
| 163 | /* destination count */ |
| 164 | *pos++ = 1; |
| 165 | *pos++ = dst_flags; |
| 166 | } |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 167 | if (action != MPATH_RANN) { |
| 168 | memcpy(pos, dst, ETH_ALEN); |
| 169 | pos += ETH_ALEN; |
| 170 | memcpy(pos, &dst_dsn, 4); |
| 171 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 172 | |
Jouni Malinen | 1acc97b | 2009-01-08 13:32:07 +0200 | [diff] [blame] | 173 | ieee80211_tx_skb(sdata, skb, 1); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * mesh_send_path error - Sends a PERR mesh management frame |
| 179 | * |
| 180 | * @dst: broken destination |
| 181 | * @dst_dsn: dsn of the broken destination |
| 182 | * @ra: node this frame is addressed to |
| 183 | */ |
| 184 | int mesh_path_error_tx(u8 *dst, __le32 dst_dsn, u8 *ra, |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 185 | struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 186 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 187 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 188 | struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
| 189 | struct ieee80211_mgmt *mgmt; |
| 190 | u8 *pos; |
| 191 | int ie_len; |
| 192 | |
| 193 | if (!skb) |
| 194 | return -1; |
| 195 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 196 | /* 25 is the size of the common mgmt part (24) plus the size of the |
| 197 | * common action part (1) |
| 198 | */ |
| 199 | mgmt = (struct ieee80211_mgmt *) |
| 200 | skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action)); |
| 201 | memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action)); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 202 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 203 | IEEE80211_STYPE_ACTION); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 204 | |
| 205 | memcpy(mgmt->da, ra, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 206 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 207 | /* BSSID is left zeroed, wildcard value */ |
| 208 | mgmt->u.action.category = MESH_PATH_SEL_CATEGORY; |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 209 | mgmt->u.action.u.mesh_action.action_code = MESH_PATH_SEL_ACTION; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 210 | ie_len = 12; |
| 211 | pos = skb_put(skb, 2 + ie_len); |
| 212 | *pos++ = WLAN_EID_PERR; |
| 213 | *pos++ = ie_len; |
| 214 | /* mode flags, reserved */ |
| 215 | *pos++ = 0; |
| 216 | /* number of destinations */ |
| 217 | *pos++ = 1; |
| 218 | memcpy(pos, dst, ETH_ALEN); |
| 219 | pos += ETH_ALEN; |
| 220 | memcpy(pos, &dst_dsn, 4); |
| 221 | |
Jouni Malinen | 1acc97b | 2009-01-08 13:32:07 +0200 | [diff] [blame] | 222 | ieee80211_tx_skb(sdata, skb, 1); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
Javier Cardona | bfc32e6 | 2009-08-17 17:15:55 -0700 | [diff] [blame] | 226 | void ieee80211s_update_metric(struct ieee80211_local *local, |
| 227 | struct sta_info *stainfo, struct sk_buff *skb) |
| 228 | { |
| 229 | struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb); |
| 230 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 231 | int failed; |
| 232 | |
| 233 | if (!ieee80211_is_data(hdr->frame_control)) |
| 234 | return; |
| 235 | |
| 236 | failed = !(txinfo->flags & IEEE80211_TX_STAT_ACK); |
| 237 | |
| 238 | /* moving average, scaled to 100 */ |
| 239 | stainfo->fail_avg = ((80 * stainfo->fail_avg + 5) / 100 + 20 * failed); |
| 240 | if (stainfo->fail_avg > 95) |
| 241 | mesh_plink_broken(stainfo); |
| 242 | } |
| 243 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 244 | static u32 airtime_link_metric_get(struct ieee80211_local *local, |
| 245 | struct sta_info *sta) |
| 246 | { |
| 247 | struct ieee80211_supported_band *sband; |
| 248 | /* This should be adjusted for each device */ |
| 249 | int device_constant = 1 << ARITH_SHIFT; |
| 250 | int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT; |
| 251 | int s_unit = 1 << ARITH_SHIFT; |
| 252 | int rate, err; |
| 253 | u32 tx_time, estimated_retx; |
| 254 | u64 result; |
| 255 | |
| 256 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 257 | |
| 258 | if (sta->fail_avg >= 100) |
| 259 | return MAX_METRIC; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 260 | |
| 261 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS) |
| 262 | return MAX_METRIC; |
| 263 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 264 | err = (sta->fail_avg << ARITH_SHIFT) / 100; |
| 265 | |
| 266 | /* bitrate is in units of 100 Kbps, while we need rate in units of |
| 267 | * 1Mbps. This will be corrected on tx_time computation. |
| 268 | */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 269 | rate = sband->bitrates[sta->last_tx_rate.idx].bitrate; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 270 | tx_time = (device_constant + 10 * test_frame_len / rate); |
| 271 | estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err)); |
| 272 | result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ; |
| 273 | return (u32)result; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * hwmp_route_info_get - Update routing info to originator and transmitter |
| 278 | * |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 279 | * @sdata: local mesh subif |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 280 | * @mgmt: mesh management frame |
| 281 | * @hwmp_ie: hwmp information element (PREP or PREQ) |
| 282 | * |
| 283 | * This function updates the path routing information to the originator and the |
Andrey Yurovsky | f99288d | 2009-10-20 12:17:34 -0700 | [diff] [blame] | 284 | * transmitter of a HWMP PREQ or PREP frame. |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 285 | * |
| 286 | * Returns: metric to frame originator or 0 if the frame should not be further |
| 287 | * processed |
| 288 | * |
| 289 | * Notes: this function is the only place (besides user-provided info) where |
| 290 | * path routing information is updated. |
| 291 | */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 292 | 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] | 293 | struct ieee80211_mgmt *mgmt, |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 294 | u8 *hwmp_ie, enum mpath_frame_type action) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 295 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 296 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 297 | struct mesh_path *mpath; |
| 298 | struct sta_info *sta; |
| 299 | bool fresh_info; |
| 300 | u8 *orig_addr, *ta; |
| 301 | u32 orig_dsn, orig_metric; |
| 302 | unsigned long orig_lifetime, exp_time; |
| 303 | u32 last_hop_metric, new_metric; |
| 304 | bool process = true; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 305 | |
| 306 | rcu_read_lock(); |
| 307 | sta = sta_info_get(local, mgmt->sa); |
Johannes Berg | dc0b0f7 | 2008-02-23 15:17:20 +0100 | [diff] [blame] | 308 | if (!sta) { |
| 309 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 310 | return 0; |
Johannes Berg | dc0b0f7 | 2008-02-23 15:17:20 +0100 | [diff] [blame] | 311 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 312 | |
| 313 | last_hop_metric = airtime_link_metric_get(local, sta); |
| 314 | /* Update and check originator routing info */ |
| 315 | fresh_info = true; |
| 316 | |
| 317 | switch (action) { |
| 318 | case MPATH_PREQ: |
| 319 | orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie); |
| 320 | orig_dsn = PREQ_IE_ORIG_DSN(hwmp_ie); |
| 321 | orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie); |
| 322 | orig_metric = PREQ_IE_METRIC(hwmp_ie); |
| 323 | break; |
| 324 | case MPATH_PREP: |
| 325 | /* Originator here refers to the MP that was the destination in |
| 326 | * the Path Request. The draft refers to that MP as the |
| 327 | * destination address, even though usually it is the origin of |
| 328 | * the PREP frame. We divert from the nomenclature in the draft |
| 329 | * so that we can easily use a single function to gather path |
| 330 | * information from both PREQ and PREP frames. |
| 331 | */ |
| 332 | orig_addr = PREP_IE_ORIG_ADDR(hwmp_ie); |
| 333 | orig_dsn = PREP_IE_ORIG_DSN(hwmp_ie); |
| 334 | orig_lifetime = PREP_IE_LIFETIME(hwmp_ie); |
| 335 | orig_metric = PREP_IE_METRIC(hwmp_ie); |
| 336 | break; |
| 337 | default: |
Johannes Berg | dc0b0f7 | 2008-02-23 15:17:20 +0100 | [diff] [blame] | 338 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 339 | return 0; |
| 340 | } |
| 341 | new_metric = orig_metric + last_hop_metric; |
| 342 | if (new_metric < orig_metric) |
| 343 | new_metric = MAX_METRIC; |
| 344 | exp_time = TU_TO_EXP_TIME(orig_lifetime); |
| 345 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 346 | if (memcmp(orig_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 347 | /* This MP is the originator, we are not interested in this |
| 348 | * frame, except for updating transmitter's path info. |
| 349 | */ |
| 350 | process = false; |
| 351 | fresh_info = false; |
| 352 | } else { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 353 | mpath = mesh_path_lookup(orig_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 354 | if (mpath) { |
| 355 | spin_lock_bh(&mpath->state_lock); |
| 356 | if (mpath->flags & MESH_PATH_FIXED) |
| 357 | fresh_info = false; |
| 358 | else if ((mpath->flags & MESH_PATH_ACTIVE) && |
| 359 | (mpath->flags & MESH_PATH_DSN_VALID)) { |
| 360 | if (DSN_GT(mpath->dsn, orig_dsn) || |
| 361 | (mpath->dsn == orig_dsn && |
| 362 | action == MPATH_PREQ && |
| 363 | new_metric > mpath->metric)) { |
| 364 | process = false; |
| 365 | fresh_info = false; |
| 366 | } |
| 367 | } |
| 368 | } else { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 369 | mesh_path_add(orig_addr, sdata); |
| 370 | mpath = mesh_path_lookup(orig_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 371 | if (!mpath) { |
| 372 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | spin_lock_bh(&mpath->state_lock); |
| 376 | } |
| 377 | |
| 378 | if (fresh_info) { |
| 379 | mesh_path_assign_nexthop(mpath, sta); |
| 380 | mpath->flags |= MESH_PATH_DSN_VALID; |
| 381 | mpath->metric = new_metric; |
| 382 | mpath->dsn = orig_dsn; |
| 383 | mpath->exp_time = time_after(mpath->exp_time, exp_time) |
| 384 | ? mpath->exp_time : exp_time; |
| 385 | mesh_path_activate(mpath); |
| 386 | spin_unlock_bh(&mpath->state_lock); |
| 387 | mesh_path_tx_pending(mpath); |
| 388 | /* draft says preq_id should be saved to, but there does |
| 389 | * not seem to be any use for it, skipping by now |
| 390 | */ |
| 391 | } else |
| 392 | spin_unlock_bh(&mpath->state_lock); |
| 393 | } |
| 394 | |
| 395 | /* Update and check transmitter routing info */ |
| 396 | ta = mgmt->sa; |
| 397 | if (memcmp(orig_addr, ta, ETH_ALEN) == 0) |
| 398 | fresh_info = false; |
| 399 | else { |
| 400 | fresh_info = true; |
| 401 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 402 | mpath = mesh_path_lookup(ta, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 403 | if (mpath) { |
| 404 | spin_lock_bh(&mpath->state_lock); |
| 405 | if ((mpath->flags & MESH_PATH_FIXED) || |
| 406 | ((mpath->flags & MESH_PATH_ACTIVE) && |
| 407 | (last_hop_metric > mpath->metric))) |
| 408 | fresh_info = false; |
| 409 | } else { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 410 | mesh_path_add(ta, sdata); |
| 411 | mpath = mesh_path_lookup(ta, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 412 | if (!mpath) { |
| 413 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 414 | return 0; |
| 415 | } |
| 416 | spin_lock_bh(&mpath->state_lock); |
| 417 | } |
| 418 | |
| 419 | if (fresh_info) { |
| 420 | mesh_path_assign_nexthop(mpath, sta); |
| 421 | mpath->flags &= ~MESH_PATH_DSN_VALID; |
| 422 | mpath->metric = last_hop_metric; |
| 423 | mpath->exp_time = time_after(mpath->exp_time, exp_time) |
| 424 | ? mpath->exp_time : exp_time; |
| 425 | mesh_path_activate(mpath); |
| 426 | spin_unlock_bh(&mpath->state_lock); |
| 427 | mesh_path_tx_pending(mpath); |
| 428 | } else |
| 429 | spin_unlock_bh(&mpath->state_lock); |
| 430 | } |
| 431 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 432 | rcu_read_unlock(); |
| 433 | |
| 434 | return process ? new_metric : 0; |
| 435 | } |
| 436 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 437 | 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] | 438 | struct ieee80211_mgmt *mgmt, |
David Woo | 57ef5dd | 2009-08-12 11:03:43 -0700 | [diff] [blame] | 439 | u8 *preq_elem, u32 metric) |
| 440 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 441 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 442 | struct mesh_path *mpath; |
| 443 | u8 *dst_addr, *orig_addr; |
| 444 | u8 dst_flags, ttl; |
| 445 | u32 orig_dsn, dst_dsn, lifetime; |
| 446 | bool reply = false; |
| 447 | bool forward = true; |
| 448 | |
| 449 | /* Update destination DSN, if present */ |
| 450 | dst_addr = PREQ_IE_DST_ADDR(preq_elem); |
| 451 | orig_addr = PREQ_IE_ORIG_ADDR(preq_elem); |
| 452 | dst_dsn = PREQ_IE_DST_DSN(preq_elem); |
| 453 | orig_dsn = PREQ_IE_ORIG_DSN(preq_elem); |
| 454 | dst_flags = PREQ_IE_DST_F(preq_elem); |
| 455 | |
Rui Paulo | f3c0d88 | 2009-11-09 23:46:47 +0000 | [diff] [blame] | 456 | mhwmp_dbg("received PREQ from %pM\n", orig_addr); |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 457 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 458 | if (memcmp(dst_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) { |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 459 | mhwmp_dbg("PREQ is for us\n"); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 460 | forward = false; |
| 461 | reply = true; |
| 462 | metric = 0; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 463 | if (time_after(jiffies, ifmsh->last_dsn_update + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 464 | net_traversal_jiffies(sdata)) || |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 465 | time_before(jiffies, ifmsh->last_dsn_update)) { |
| 466 | dst_dsn = ++ifmsh->dsn; |
| 467 | ifmsh->last_dsn_update = jiffies; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 468 | } |
| 469 | } else { |
| 470 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 471 | mpath = mesh_path_lookup(dst_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 472 | if (mpath) { |
| 473 | if ((!(mpath->flags & MESH_PATH_DSN_VALID)) || |
| 474 | DSN_LT(mpath->dsn, dst_dsn)) { |
| 475 | mpath->dsn = dst_dsn; |
David Woo | 57ef5dd | 2009-08-12 11:03:43 -0700 | [diff] [blame] | 476 | mpath->flags |= MESH_PATH_DSN_VALID; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 477 | } else if ((!(dst_flags & MP_F_DO)) && |
| 478 | (mpath->flags & MESH_PATH_ACTIVE)) { |
| 479 | reply = true; |
| 480 | metric = mpath->metric; |
| 481 | dst_dsn = mpath->dsn; |
| 482 | if (dst_flags & MP_F_RF) |
| 483 | dst_flags |= MP_F_DO; |
| 484 | else |
| 485 | forward = false; |
| 486 | } |
| 487 | } |
| 488 | rcu_read_unlock(); |
| 489 | } |
| 490 | |
| 491 | if (reply) { |
| 492 | lifetime = PREQ_IE_LIFETIME(preq_elem); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 493 | ttl = ifmsh->mshcfg.dot11MeshTTL; |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 494 | if (ttl != 0) { |
| 495 | mhwmp_dbg("replying to the PREQ\n"); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 496 | mesh_path_sel_frame_tx(MPATH_PREP, 0, dst_addr, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 497 | cpu_to_le32(dst_dsn), 0, orig_addr, |
| 498 | cpu_to_le32(orig_dsn), mgmt->sa, 0, ttl, |
| 499 | cpu_to_le32(lifetime), cpu_to_le32(metric), |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 500 | 0, sdata); |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 501 | } else |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 502 | ifmsh->mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | if (forward) { |
| 506 | u32 preq_id; |
| 507 | u8 hopcount, flags; |
| 508 | |
| 509 | ttl = PREQ_IE_TTL(preq_elem); |
| 510 | lifetime = PREQ_IE_LIFETIME(preq_elem); |
| 511 | if (ttl <= 1) { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 512 | ifmsh->mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 513 | return; |
| 514 | } |
Rui Paulo | f3c0d88 | 2009-11-09 23:46:47 +0000 | [diff] [blame] | 515 | mhwmp_dbg("forwarding the PREQ from %pM\n", orig_addr); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 516 | --ttl; |
| 517 | flags = PREQ_IE_FLAGS(preq_elem); |
| 518 | preq_id = PREQ_IE_PREQ_ID(preq_elem); |
| 519 | hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1; |
| 520 | mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 521 | cpu_to_le32(orig_dsn), dst_flags, dst_addr, |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 522 | cpu_to_le32(dst_dsn), sdata->dev->broadcast, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 523 | hopcount, ttl, cpu_to_le32(lifetime), |
| 524 | cpu_to_le32(metric), cpu_to_le32(preq_id), |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 525 | sdata); |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 526 | ifmsh->mshstats.fwded_mcast++; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 527 | ifmsh->mshstats.fwded_frames++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 532 | 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] | 533 | struct ieee80211_mgmt *mgmt, |
| 534 | u8 *prep_elem, u32 metric) |
| 535 | { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 536 | struct mesh_path *mpath; |
| 537 | u8 *dst_addr, *orig_addr; |
| 538 | u8 ttl, hopcount, flags; |
| 539 | u8 next_hop[ETH_ALEN]; |
| 540 | u32 dst_dsn, orig_dsn, lifetime; |
| 541 | |
Rui Paulo | f3c0d88 | 2009-11-09 23:46:47 +0000 | [diff] [blame] | 542 | mhwmp_dbg("received PREP from %pM\n", PREP_IE_ORIG_ADDR(prep_elem)); |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 543 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 544 | /* Note that we divert from the draft nomenclature and denominate |
| 545 | * destination to what the draft refers to as origininator. So in this |
| 546 | * function destnation refers to the final destination of the PREP, |
| 547 | * which corresponds with the originator of the PREQ which this PREP |
| 548 | * replies |
| 549 | */ |
| 550 | dst_addr = PREP_IE_DST_ADDR(prep_elem); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 551 | if (memcmp(dst_addr, sdata->dev->dev_addr, ETH_ALEN) == 0) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 552 | /* destination, no forwarding required */ |
| 553 | return; |
| 554 | |
| 555 | ttl = PREP_IE_TTL(prep_elem); |
| 556 | if (ttl <= 1) { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 557 | sdata->u.mesh.mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 558 | return; |
| 559 | } |
| 560 | |
| 561 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 562 | mpath = mesh_path_lookup(dst_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 563 | if (mpath) |
| 564 | spin_lock_bh(&mpath->state_lock); |
| 565 | else |
| 566 | goto fail; |
| 567 | if (!(mpath->flags & MESH_PATH_ACTIVE)) { |
| 568 | spin_unlock_bh(&mpath->state_lock); |
| 569 | goto fail; |
| 570 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 571 | memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 572 | spin_unlock_bh(&mpath->state_lock); |
| 573 | --ttl; |
| 574 | flags = PREP_IE_FLAGS(prep_elem); |
| 575 | lifetime = PREP_IE_LIFETIME(prep_elem); |
| 576 | hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1; |
| 577 | orig_addr = PREP_IE_ORIG_ADDR(prep_elem); |
| 578 | dst_dsn = PREP_IE_DST_DSN(prep_elem); |
| 579 | orig_dsn = PREP_IE_ORIG_DSN(prep_elem); |
| 580 | |
| 581 | mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 582 | cpu_to_le32(orig_dsn), 0, dst_addr, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 583 | cpu_to_le32(dst_dsn), mpath->next_hop->sta.addr, hopcount, ttl, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 584 | cpu_to_le32(lifetime), cpu_to_le32(metric), |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 585 | 0, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 586 | rcu_read_unlock(); |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 587 | |
| 588 | sdata->u.mesh.mshstats.fwded_unicast++; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 589 | sdata->u.mesh.mshstats.fwded_frames++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 590 | return; |
| 591 | |
| 592 | fail: |
| 593 | rcu_read_unlock(); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 594 | sdata->u.mesh.mshstats.dropped_frames_no_route++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 595 | return; |
| 596 | } |
| 597 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 598 | 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] | 599 | struct ieee80211_mgmt *mgmt, u8 *perr_elem) |
| 600 | { |
| 601 | struct mesh_path *mpath; |
| 602 | u8 *ta, *dst_addr; |
| 603 | u32 dst_dsn; |
| 604 | |
| 605 | ta = mgmt->sa; |
| 606 | dst_addr = PERR_IE_DST_ADDR(perr_elem); |
| 607 | dst_dsn = PERR_IE_DST_DSN(perr_elem); |
| 608 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 609 | mpath = mesh_path_lookup(dst_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 610 | if (mpath) { |
| 611 | spin_lock_bh(&mpath->state_lock); |
| 612 | if (mpath->flags & MESH_PATH_ACTIVE && |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 613 | memcmp(ta, mpath->next_hop->sta.addr, ETH_ALEN) == 0 && |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 614 | (!(mpath->flags & MESH_PATH_DSN_VALID) || |
| 615 | DSN_GT(dst_dsn, mpath->dsn))) { |
| 616 | mpath->flags &= ~MESH_PATH_ACTIVE; |
| 617 | mpath->dsn = dst_dsn; |
| 618 | spin_unlock_bh(&mpath->state_lock); |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 619 | mesh_path_error_tx(dst_addr, cpu_to_le32(dst_dsn), |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 620 | sdata->dev->broadcast, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 621 | } else |
| 622 | spin_unlock_bh(&mpath->state_lock); |
| 623 | } |
| 624 | rcu_read_unlock(); |
| 625 | } |
| 626 | |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 627 | static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata, |
| 628 | struct ieee80211_mgmt *mgmt, |
| 629 | struct ieee80211_rann_ie *rann) |
| 630 | { |
| 631 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
| 632 | struct mesh_path *mpath; |
| 633 | u8 *ta; |
| 634 | u8 ttl, flags, hopcount; |
| 635 | u8 *orig_addr; |
| 636 | u32 orig_dsn, metric; |
| 637 | |
| 638 | ta = mgmt->sa; |
| 639 | ttl = rann->rann_ttl; |
| 640 | if (ttl <= 1) { |
| 641 | ifmsh->mshstats.dropped_frames_ttl++; |
| 642 | return; |
| 643 | } |
| 644 | ttl--; |
| 645 | flags = rann->rann_flags; |
| 646 | orig_addr = rann->rann_addr; |
| 647 | orig_dsn = rann->rann_seq; |
| 648 | hopcount = rann->rann_hopcount; |
| 649 | metric = rann->rann_metric; |
| 650 | mhwmp_dbg("received RANN from %pM\n", orig_addr); |
| 651 | |
| 652 | rcu_read_lock(); |
| 653 | mpath = mesh_path_lookup(orig_addr, sdata); |
| 654 | if (!mpath) { |
| 655 | mesh_path_add(orig_addr, sdata); |
| 656 | mpath = mesh_path_lookup(orig_addr, sdata); |
| 657 | if (!mpath) { |
| 658 | rcu_read_unlock(); |
| 659 | sdata->u.mesh.mshstats.dropped_frames_no_route++; |
| 660 | return; |
| 661 | } |
| 662 | mesh_queue_preq(mpath, |
| 663 | PREQ_Q_F_START | PREQ_Q_F_REFRESH); |
| 664 | } |
| 665 | if (mpath->dsn < orig_dsn) { |
| 666 | mesh_path_sel_frame_tx(MPATH_RANN, flags, orig_addr, |
| 667 | cpu_to_le32(orig_dsn), |
| 668 | 0, NULL, 0, sdata->dev->broadcast, |
| 669 | hopcount, ttl, 0, cpu_to_le32(metric), |
| 670 | 0, sdata); |
| 671 | mpath->dsn = orig_dsn; |
| 672 | } |
| 673 | rcu_read_unlock(); |
| 674 | } |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 675 | |
| 676 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 677 | 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] | 678 | struct ieee80211_mgmt *mgmt, |
| 679 | size_t len) |
| 680 | { |
| 681 | struct ieee802_11_elems elems; |
| 682 | size_t baselen; |
| 683 | u32 last_hop_metric; |
| 684 | |
Johannes Berg | 9c80d3d | 2008-09-08 15:41:59 +0200 | [diff] [blame] | 685 | /* need action_code */ |
| 686 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
| 687 | return; |
| 688 | |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 689 | baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt; |
| 690 | ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable, |
| 691 | len - baselen, &elems); |
| 692 | |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 693 | if (elems.preq) { |
| 694 | if (elems.preq_len != 37) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 695 | /* Right now we support just 1 destination and no AE */ |
| 696 | return; |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 697 | last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.preq, |
| 698 | MPATH_PREQ); |
| 699 | if (last_hop_metric) |
| 700 | hwmp_preq_frame_process(sdata, mgmt, elems.preq, |
| 701 | last_hop_metric); |
| 702 | } |
| 703 | if (elems.prep) { |
| 704 | if (elems.prep_len != 31) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 705 | /* Right now we support no AE */ |
| 706 | return; |
Rui Paulo | dbb81c4 | 2009-11-09 23:46:46 +0000 | [diff] [blame] | 707 | last_hop_metric = hwmp_route_info_get(sdata, mgmt, elems.prep, |
| 708 | MPATH_PREP); |
| 709 | if (last_hop_metric) |
| 710 | hwmp_prep_frame_process(sdata, mgmt, elems.prep, |
| 711 | last_hop_metric); |
| 712 | } |
| 713 | if (elems.perr) { |
| 714 | if (elems.perr_len != 12) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 715 | /* Right now we support only one destination per PERR */ |
| 716 | return; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 717 | hwmp_perr_frame_process(sdata, mgmt, elems.perr); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 718 | } |
Rui Paulo | 90a5e16 | 2009-11-11 00:01:31 +0000 | [diff] [blame^] | 719 | if (elems.rann) |
| 720 | hwmp_rann_frame_process(sdata, mgmt, elems.rann); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /** |
| 724 | * mesh_queue_preq - queue a PREQ to a given destination |
| 725 | * |
| 726 | * @mpath: mesh path to discover |
| 727 | * @flags: special attributes of the PREQ to be sent |
| 728 | * |
| 729 | * Locking: the function must be called from within a rcu read lock block. |
| 730 | * |
| 731 | */ |
| 732 | static void mesh_queue_preq(struct mesh_path *mpath, u8 flags) |
| 733 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 734 | struct ieee80211_sub_if_data *sdata = mpath->sdata; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 735 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 736 | struct mesh_preq_queue *preq_node; |
| 737 | |
Andrey Yurovsky | 59615b5 | 2009-06-25 16:07:42 -0700 | [diff] [blame] | 738 | preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 739 | if (!preq_node) { |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 740 | mhwmp_dbg("could not allocate PREQ node\n"); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 741 | return; |
| 742 | } |
| 743 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 744 | spin_lock(&ifmsh->mesh_preq_queue_lock); |
| 745 | if (ifmsh->preq_queue_len == MAX_PREQ_QUEUE_LEN) { |
| 746 | spin_unlock(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 747 | kfree(preq_node); |
| 748 | if (printk_ratelimit()) |
Rui Paulo | 27db2e4 | 2009-11-09 23:46:45 +0000 | [diff] [blame] | 749 | mhwmp_dbg("PREQ node queue full\n"); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 750 | return; |
| 751 | } |
| 752 | |
| 753 | memcpy(preq_node->dst, mpath->dst, ETH_ALEN); |
| 754 | preq_node->flags = flags; |
| 755 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 756 | list_add_tail(&preq_node->list, &ifmsh->preq_queue.list); |
| 757 | ++ifmsh->preq_queue_len; |
| 758 | spin_unlock(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 759 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 760 | if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata))) |
Luis R. Rodriguez | c03e20f | 2009-08-04 15:06:26 -0700 | [diff] [blame] | 761 | ieee80211_queue_work(&sdata->local->hw, &ifmsh->work); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 762 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 763 | else if (time_before(jiffies, ifmsh->last_preq)) { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 764 | /* avoid long wait if did not send preqs for a long time |
| 765 | * and jiffies wrapped around |
| 766 | */ |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 767 | ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1; |
Luis R. Rodriguez | c03e20f | 2009-08-04 15:06:26 -0700 | [diff] [blame] | 768 | ieee80211_queue_work(&sdata->local->hw, &ifmsh->work); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 769 | } else |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 770 | mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 771 | min_preq_int_jiff(sdata)); |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * mesh_path_start_discovery - launch a path discovery from the PREQ queue |
| 776 | * |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 777 | * @sdata: local mesh subif |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 778 | */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 779 | void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 780 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 781 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 782 | struct mesh_preq_queue *preq_node; |
| 783 | struct mesh_path *mpath; |
| 784 | u8 ttl, dst_flags; |
| 785 | u32 lifetime; |
| 786 | |
Johannes Berg | a43816d | 2009-07-10 11:39:26 +0200 | [diff] [blame] | 787 | spin_lock_bh(&ifmsh->mesh_preq_queue_lock); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 788 | if (!ifmsh->preq_queue_len || |
| 789 | time_before(jiffies, ifmsh->last_preq + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 790 | min_preq_int_jiff(sdata))) { |
Johannes Berg | a43816d | 2009-07-10 11:39:26 +0200 | [diff] [blame] | 791 | spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 792 | return; |
| 793 | } |
| 794 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 795 | preq_node = list_first_entry(&ifmsh->preq_queue.list, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 796 | struct mesh_preq_queue, list); |
| 797 | list_del(&preq_node->list); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 798 | --ifmsh->preq_queue_len; |
Johannes Berg | a43816d | 2009-07-10 11:39:26 +0200 | [diff] [blame] | 799 | spin_unlock_bh(&ifmsh->mesh_preq_queue_lock); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 800 | |
| 801 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 802 | mpath = mesh_path_lookup(preq_node->dst, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 803 | if (!mpath) |
| 804 | goto enddiscovery; |
| 805 | |
| 806 | spin_lock_bh(&mpath->state_lock); |
| 807 | if (preq_node->flags & PREQ_Q_F_START) { |
| 808 | if (mpath->flags & MESH_PATH_RESOLVING) { |
| 809 | spin_unlock_bh(&mpath->state_lock); |
| 810 | goto enddiscovery; |
| 811 | } else { |
| 812 | mpath->flags &= ~MESH_PATH_RESOLVED; |
| 813 | mpath->flags |= MESH_PATH_RESOLVING; |
| 814 | mpath->discovery_retries = 0; |
| 815 | mpath->discovery_timeout = disc_timeout_jiff(sdata); |
| 816 | } |
| 817 | } else if (!(mpath->flags & MESH_PATH_RESOLVING) || |
| 818 | mpath->flags & MESH_PATH_RESOLVED) { |
| 819 | mpath->flags &= ~MESH_PATH_RESOLVING; |
| 820 | spin_unlock_bh(&mpath->state_lock); |
| 821 | goto enddiscovery; |
| 822 | } |
| 823 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 824 | ifmsh->last_preq = jiffies; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 825 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 826 | if (time_after(jiffies, ifmsh->last_dsn_update + |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 827 | net_traversal_jiffies(sdata)) || |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 828 | time_before(jiffies, ifmsh->last_dsn_update)) { |
| 829 | ++ifmsh->dsn; |
| 830 | sdata->u.mesh.last_dsn_update = jiffies; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 831 | } |
| 832 | lifetime = default_lifetime(sdata); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 833 | ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 834 | if (ttl == 0) { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 835 | sdata->u.mesh.mshstats.dropped_frames_ttl++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 836 | spin_unlock_bh(&mpath->state_lock); |
| 837 | goto enddiscovery; |
| 838 | } |
| 839 | |
| 840 | if (preq_node->flags & PREQ_Q_F_REFRESH) |
| 841 | dst_flags = MP_F_DO; |
| 842 | else |
| 843 | dst_flags = MP_F_RF; |
| 844 | |
| 845 | spin_unlock_bh(&mpath->state_lock); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 846 | mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->dev->dev_addr, |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 847 | cpu_to_le32(ifmsh->dsn), dst_flags, mpath->dst, |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 848 | cpu_to_le32(mpath->dsn), sdata->dev->broadcast, 0, |
Luis Carlos Cobo | aa2b592 | 2008-02-29 14:30:32 -0800 | [diff] [blame] | 849 | ttl, cpu_to_le32(lifetime), 0, |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 850 | cpu_to_le32(ifmsh->preq_id++), sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 851 | mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout); |
| 852 | |
| 853 | enddiscovery: |
| 854 | rcu_read_unlock(); |
| 855 | kfree(preq_node); |
| 856 | } |
| 857 | |
| 858 | /** |
Rami Rosen | 2182b83 | 2009-01-19 13:50:37 +0200 | [diff] [blame] | 859 | * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 860 | * |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 861 | * @skb: 802.11 frame to be sent |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 862 | * @sdata: network subif the frame will be sent through |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 863 | * |
| 864 | * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is |
| 865 | * found, the function will start a path discovery and queue the frame so it is |
| 866 | * sent when the path is resolved. This means the caller must not free the skb |
| 867 | * in this case. |
| 868 | */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 869 | int mesh_nexthop_lookup(struct sk_buff *skb, |
| 870 | struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 871 | { |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 872 | struct sk_buff *skb_to_free = NULL; |
| 873 | struct mesh_path *mpath; |
Luis Carlos Cobo | e32f85f | 2008-08-05 19:34:52 +0200 | [diff] [blame] | 874 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 875 | u8 *dst_addr = hdr->addr3; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 876 | int err = 0; |
| 877 | |
| 878 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 879 | mpath = mesh_path_lookup(dst_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 880 | |
| 881 | if (!mpath) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 882 | mesh_path_add(dst_addr, sdata); |
| 883 | mpath = mesh_path_lookup(dst_addr, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 884 | if (!mpath) { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 885 | sdata->u.mesh.mshstats.dropped_frames_no_route++; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 886 | err = -ENOSPC; |
| 887 | goto endlookup; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | if (mpath->flags & MESH_PATH_ACTIVE) { |
Andrey Yurovsky | a9e3091 | 2009-08-10 12:15:47 -0700 | [diff] [blame] | 892 | if (time_after(jiffies, mpath->exp_time + |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 893 | msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time)) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 894 | && !memcmp(sdata->dev->dev_addr, hdr->addr4, |
| 895 | ETH_ALEN) |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 896 | && !(mpath->flags & MESH_PATH_RESOLVING) |
| 897 | && !(mpath->flags & MESH_PATH_FIXED)) { |
| 898 | mesh_queue_preq(mpath, |
| 899 | PREQ_Q_F_START | PREQ_Q_F_REFRESH); |
| 900 | } |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 901 | memcpy(hdr->addr1, mpath->next_hop->sta.addr, |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 902 | ETH_ALEN); |
| 903 | } else { |
Javier Cardona | 249b405 | 2009-07-07 10:55:03 -0700 | [diff] [blame] | 904 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 905 | if (!(mpath->flags & MESH_PATH_RESOLVING)) { |
| 906 | /* Start discovery only if it is not running yet */ |
| 907 | mesh_queue_preq(mpath, PREQ_Q_F_START); |
| 908 | } |
| 909 | |
| 910 | if (skb_queue_len(&mpath->frame_queue) >= |
Javier Cardona | fe58343 | 2009-08-10 12:15:46 -0700 | [diff] [blame] | 911 | MESH_FRAME_QUEUE_LEN) |
| 912 | skb_to_free = skb_dequeue(&mpath->frame_queue); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 913 | |
Javier Cardona | 249b405 | 2009-07-07 10:55:03 -0700 | [diff] [blame] | 914 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 915 | skb_queue_tail(&mpath->frame_queue, skb); |
| 916 | if (skb_to_free) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 917 | mesh_path_discard_frame(skb_to_free, sdata); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 918 | err = -ENOENT; |
| 919 | } |
| 920 | |
| 921 | endlookup: |
| 922 | rcu_read_unlock(); |
| 923 | return err; |
| 924 | } |
| 925 | |
| 926 | void mesh_path_timer(unsigned long data) |
| 927 | { |
| 928 | struct ieee80211_sub_if_data *sdata; |
| 929 | struct mesh_path *mpath; |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 930 | |
| 931 | rcu_read_lock(); |
| 932 | mpath = (struct mesh_path *) data; |
| 933 | mpath = rcu_dereference(mpath); |
| 934 | if (!mpath) |
| 935 | goto endmpathtimer; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 936 | sdata = mpath->sdata; |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 937 | |
| 938 | if (sdata->local->quiescing) { |
| 939 | rcu_read_unlock(); |
| 940 | return; |
| 941 | } |
| 942 | |
| 943 | spin_lock_bh(&mpath->state_lock); |
Luis Carlos Cobo | cfa22c7 | 2008-02-29 15:04:13 -0800 | [diff] [blame] | 944 | if (mpath->flags & MESH_PATH_RESOLVED || |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 945 | (!(mpath->flags & MESH_PATH_RESOLVING))) |
| 946 | mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED); |
| 947 | else if (mpath->discovery_retries < max_preq_retries(sdata)) { |
| 948 | ++mpath->discovery_retries; |
| 949 | mpath->discovery_timeout *= 2; |
| 950 | mesh_queue_preq(mpath, 0); |
| 951 | } else { |
| 952 | mpath->flags = 0; |
| 953 | mpath->exp_time = jiffies; |
| 954 | mesh_path_flush_pending(mpath); |
| 955 | } |
| 956 | |
| 957 | spin_unlock_bh(&mpath->state_lock); |
| 958 | endmpathtimer: |
| 959 | rcu_read_unlock(); |
Luis Carlos Cobo | 050ac52 | 2008-02-23 15:17:15 +0100 | [diff] [blame] | 960 | } |