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