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