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