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