Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +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 | */ |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/random.h> |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 11 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 12 | #include "rate.h" |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 13 | #include "mesh.h" |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 14 | |
| 15 | #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG |
| 16 | #define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args) |
| 17 | #else |
| 18 | #define mpl_dbg(fmt, args...) do { (void)(0); } while (0) |
| 19 | #endif |
| 20 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 21 | #define PLINK_GET_FRAME_SUBTYPE(p) (p) |
| 22 | #define PLINK_GET_LLID(p) (p + 1) |
| 23 | #define PLINK_GET_PLID(p) (p + 3) |
| 24 | |
| 25 | #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \ |
| 26 | jiffies + HZ * t / 1000)) |
| 27 | |
| 28 | /* Peer link cancel reasons, all subject to ANA approval */ |
| 29 | #define MESH_LINK_CANCELLED 2 |
| 30 | #define MESH_MAX_NEIGHBORS 3 |
| 31 | #define MESH_CAPABILITY_POLICY_VIOLATION 4 |
| 32 | #define MESH_CLOSE_RCVD 5 |
| 33 | #define MESH_MAX_RETRIES 6 |
| 34 | #define MESH_CONFIRM_TIMEOUT 7 |
| 35 | #define MESH_SECURITY_ROLE_NEGOTIATION_DIFFERS 8 |
| 36 | #define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9 |
| 37 | #define MESH_SECURITY_FAILED_VERIFICATION 10 |
| 38 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 39 | #define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries) |
| 40 | #define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout) |
| 41 | #define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout) |
| 42 | #define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout) |
| 43 | #define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 44 | |
| 45 | enum plink_frame_type { |
| 46 | PLINK_OPEN = 0, |
| 47 | PLINK_CONFIRM, |
| 48 | PLINK_CLOSE |
| 49 | }; |
| 50 | |
| 51 | enum plink_event { |
| 52 | PLINK_UNDEFINED, |
| 53 | OPN_ACPT, |
| 54 | OPN_RJCT, |
| 55 | OPN_IGNR, |
| 56 | CNF_ACPT, |
| 57 | CNF_RJCT, |
| 58 | CNF_IGNR, |
| 59 | CLS_ACPT, |
| 60 | CLS_IGNR |
| 61 | }; |
| 62 | |
| 63 | static inline |
| 64 | void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata) |
| 65 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 66 | atomic_inc(&sdata->u.mesh.mshstats.estab_plinks); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 67 | mesh_accept_plinks_update(sdata); |
Rui Paulo | 8f2fda9 | 2009-11-09 23:46:41 +0000 | [diff] [blame^] | 68 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline |
| 72 | void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata) |
| 73 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 74 | atomic_dec(&sdata->u.mesh.mshstats.estab_plinks); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 75 | mesh_accept_plinks_update(sdata); |
Rui Paulo | 8f2fda9 | 2009-11-09 23:46:41 +0000 | [diff] [blame^] | 76 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * mesh_plink_fsm_restart - restart a mesh peer link finite state machine |
| 81 | * |
| 82 | * @sta: mes peer link to restart |
| 83 | * |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 84 | * Locking: this function must be called holding sta->lock |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 85 | */ |
| 86 | static inline void mesh_plink_fsm_restart(struct sta_info *sta) |
| 87 | { |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 88 | sta->plink_state = PLINK_LISTEN; |
Luis Carlos Cobo | 37659ff | 2008-02-29 12:13:38 -0800 | [diff] [blame] | 89 | sta->llid = sta->plid = sta->reason = 0; |
| 90 | sta->plink_retries = 0; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 91 | } |
| 92 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 93 | /* |
| 94 | * NOTE: This is just an alias for sta_info_alloc(), see notes |
| 95 | * on it in the lifecycle management section! |
| 96 | */ |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 97 | static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 98 | u8 *hw_addr, u32 rates) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 99 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 100 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 101 | struct sta_info *sta; |
| 102 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 103 | if (local->num_sta >= MESH_MAX_PLINKS) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 104 | return NULL; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 105 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 106 | sta = sta_info_alloc(sdata, hw_addr, GFP_ATOMIC); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 107 | if (!sta) |
| 108 | return NULL; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 109 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 110 | sta->flags = WLAN_STA_AUTHORIZED; |
Johannes Berg | 323ce79 | 2008-09-11 02:45:11 +0200 | [diff] [blame] | 111 | sta->sta.supp_rates[local->hw.conf.channel->band] = rates; |
Christian Lamparter | b973c31 | 2008-12-27 22:19:49 +0100 | [diff] [blame] | 112 | rate_control_rate_init(sta); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 113 | |
| 114 | return sta; |
| 115 | } |
| 116 | |
| 117 | /** |
Johannes Berg | 42096b6 | 2008-02-25 21:36:27 +0100 | [diff] [blame] | 118 | * mesh_plink_deactivate - deactivate mesh peer link |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 119 | * |
| 120 | * @sta: mesh peer link to deactivate |
| 121 | * |
| 122 | * All mesh paths with this peer as next hop will be flushed |
| 123 | * |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 124 | * Locking: the caller must hold sta->lock |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 125 | */ |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 126 | static void __mesh_plink_deactivate(struct sta_info *sta) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 127 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 128 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 129 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 130 | if (sta->plink_state == PLINK_ESTAB) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 131 | mesh_plink_dec_estab_count(sdata); |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 132 | sta->plink_state = PLINK_BLOCKED; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 133 | mesh_path_flush_by_nexthop(sta); |
| 134 | } |
| 135 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 136 | /** |
| 137 | * __mesh_plink_deactivate - deactivate mesh peer link |
| 138 | * |
| 139 | * @sta: mesh peer link to deactivate |
| 140 | * |
| 141 | * All mesh paths with this peer as next hop will be flushed |
| 142 | */ |
| 143 | void mesh_plink_deactivate(struct sta_info *sta) |
| 144 | { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 145 | spin_lock_bh(&sta->lock); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 146 | __mesh_plink_deactivate(sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 147 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 150 | static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 151 | enum plink_frame_type action, u8 *da, __le16 llid, __le16 plid, |
| 152 | __le16 reason) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 153 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 154 | struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
| 155 | struct ieee80211_mgmt *mgmt; |
| 156 | bool include_plid = false; |
| 157 | u8 *pos; |
| 158 | int ie_len; |
| 159 | |
| 160 | if (!skb) |
| 161 | return -1; |
| 162 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 163 | /* 25 is the size of the common mgmt part (24) plus the size of the |
| 164 | * common action part (1) |
| 165 | */ |
| 166 | mgmt = (struct ieee80211_mgmt *) |
| 167 | skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action)); |
| 168 | memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action)); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 169 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 170 | IEEE80211_STYPE_ACTION); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 171 | memcpy(mgmt->da, da, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 172 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 173 | /* BSSID is left zeroed, wildcard value */ |
| 174 | mgmt->u.action.category = PLINK_CATEGORY; |
| 175 | mgmt->u.action.u.plink_action.action_code = action; |
| 176 | |
| 177 | if (action == PLINK_CLOSE) |
| 178 | mgmt->u.action.u.plink_action.aux = reason; |
| 179 | else { |
| 180 | mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0); |
| 181 | if (action == PLINK_CONFIRM) { |
| 182 | pos = skb_put(skb, 4); |
| 183 | /* two-byte status code followed by two-byte AID */ |
| 184 | memset(pos, 0, 4); |
| 185 | } |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 186 | mesh_mgmt_ies_add(skb, sdata); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* Add Peer Link Management element */ |
| 190 | switch (action) { |
| 191 | case PLINK_OPEN: |
| 192 | ie_len = 3; |
| 193 | break; |
| 194 | case PLINK_CONFIRM: |
| 195 | ie_len = 5; |
| 196 | include_plid = true; |
| 197 | break; |
| 198 | case PLINK_CLOSE: |
| 199 | default: |
| 200 | if (!plid) |
| 201 | ie_len = 5; |
| 202 | else { |
| 203 | ie_len = 7; |
| 204 | include_plid = true; |
| 205 | } |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | pos = skb_put(skb, 2 + ie_len); |
| 210 | *pos++ = WLAN_EID_PEER_LINK; |
| 211 | *pos++ = ie_len; |
| 212 | *pos++ = action; |
| 213 | memcpy(pos, &llid, 2); |
| 214 | if (include_plid) { |
| 215 | pos += 2; |
| 216 | memcpy(pos, &plid, 2); |
| 217 | } |
| 218 | if (action == PLINK_CLOSE) { |
| 219 | pos += 2; |
| 220 | memcpy(pos, &reason, 2); |
| 221 | } |
| 222 | |
Jouni Malinen | 1acc97b | 2009-01-08 13:32:07 +0200 | [diff] [blame] | 223 | ieee80211_tx_skb(sdata, skb, 1); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 227 | void mesh_neighbour_update(u8 *hw_addr, u32 rates, struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 228 | bool peer_accepting_plinks) |
| 229 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 230 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 231 | struct sta_info *sta; |
| 232 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 233 | rcu_read_lock(); |
| 234 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 235 | sta = sta_info_get(local, hw_addr); |
| 236 | if (!sta) { |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 237 | sta = mesh_plink_alloc(sdata, hw_addr, rates); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 238 | if (!sta) { |
| 239 | rcu_read_unlock(); |
| 240 | return; |
| 241 | } |
| 242 | if (sta_info_insert(sta)) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 243 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 244 | return; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 245 | } |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | sta->last_rx = jiffies; |
Johannes Berg | 323ce79 | 2008-09-11 02:45:11 +0200 | [diff] [blame] | 249 | sta->sta.supp_rates[local->hw.conf.channel->band] = rates; |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 250 | if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN && |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 251 | sdata->u.mesh.accepting_plinks && |
| 252 | sdata->u.mesh.mshcfg.auto_open_plinks) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 253 | mesh_plink_open(sta); |
| 254 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 255 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static void mesh_plink_timer(unsigned long data) |
| 259 | { |
| 260 | struct sta_info *sta; |
| 261 | __le16 llid, plid, reason; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 262 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 263 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 264 | /* |
| 265 | * This STA is valid because sta_info_destroy() will |
| 266 | * del_timer_sync() this timer after having made sure |
| 267 | * it cannot be readded (by deleting the plink.) |
| 268 | */ |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 269 | sta = (struct sta_info *) data; |
| 270 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 271 | if (sta->sdata->local->quiescing) { |
| 272 | sta->plink_timer_was_running = true; |
| 273 | return; |
| 274 | } |
| 275 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 276 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 277 | if (sta->ignore_plink_timer) { |
| 278 | sta->ignore_plink_timer = false; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 279 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 280 | return; |
| 281 | } |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 282 | mpl_dbg("Mesh plink timer for %pM fired on state %d\n", |
| 283 | sta->sta.addr, sta->plink_state); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 284 | reason = 0; |
| 285 | llid = sta->llid; |
| 286 | plid = sta->plid; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 287 | sdata = sta->sdata; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 288 | |
| 289 | switch (sta->plink_state) { |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 290 | case PLINK_OPN_RCVD: |
| 291 | case PLINK_OPN_SNT: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 292 | /* retry timer */ |
| 293 | if (sta->plink_retries < dot11MeshMaxRetries(sdata)) { |
| 294 | u32 rand; |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 295 | mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n", |
| 296 | sta->sta.addr, sta->plink_retries, |
| 297 | sta->plink_timeout); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 298 | get_random_bytes(&rand, sizeof(u32)); |
| 299 | sta->plink_timeout = sta->plink_timeout + |
| 300 | rand % sta->plink_timeout; |
| 301 | ++sta->plink_retries; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 302 | mod_plink_timer(sta, sta->plink_timeout); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 303 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 304 | mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 305 | 0, 0); |
| 306 | break; |
| 307 | } |
| 308 | reason = cpu_to_le16(MESH_MAX_RETRIES); |
| 309 | /* fall through on else */ |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 310 | case PLINK_CNF_RCVD: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 311 | /* confirm timer */ |
| 312 | if (!reason) |
| 313 | reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT); |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 314 | sta->plink_state = PLINK_HOLDING; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 315 | mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 316 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 317 | mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, plid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 318 | reason); |
| 319 | break; |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 320 | case PLINK_HOLDING: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 321 | /* holding timer */ |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 322 | del_timer(&sta->plink_timer); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 323 | mesh_plink_fsm_restart(sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 324 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 325 | break; |
| 326 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 327 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 328 | break; |
| 329 | } |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 330 | } |
| 331 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 332 | #ifdef CONFIG_PM |
| 333 | void mesh_plink_quiesce(struct sta_info *sta) |
| 334 | { |
| 335 | if (del_timer_sync(&sta->plink_timer)) |
| 336 | sta->plink_timer_was_running = true; |
| 337 | } |
| 338 | |
| 339 | void mesh_plink_restart(struct sta_info *sta) |
| 340 | { |
| 341 | if (sta->plink_timer_was_running) { |
| 342 | add_timer(&sta->plink_timer); |
| 343 | sta->plink_timer_was_running = false; |
| 344 | } |
| 345 | } |
| 346 | #endif |
| 347 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 348 | static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout) |
| 349 | { |
| 350 | sta->plink_timer.expires = jiffies + (HZ * timeout / 1000); |
| 351 | sta->plink_timer.data = (unsigned long) sta; |
| 352 | sta->plink_timer.function = mesh_plink_timer; |
| 353 | sta->plink_timeout = timeout; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 354 | add_timer(&sta->plink_timer); |
| 355 | } |
| 356 | |
| 357 | int mesh_plink_open(struct sta_info *sta) |
| 358 | { |
| 359 | __le16 llid; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 360 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 361 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 362 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 363 | get_random_bytes(&llid, 2); |
| 364 | sta->llid = llid; |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 365 | if (sta->plink_state != PLINK_LISTEN) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 366 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 367 | return -EBUSY; |
| 368 | } |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 369 | sta->plink_state = PLINK_OPN_SNT; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 370 | mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 371 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 372 | mpl_dbg("Mesh plink: starting establishment with %pM\n", |
| 373 | sta->sta.addr); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 374 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 375 | return mesh_plink_frame_tx(sdata, PLINK_OPEN, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 376 | sta->sta.addr, llid, 0, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | void mesh_plink_block(struct sta_info *sta) |
| 380 | { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 381 | spin_lock_bh(&sta->lock); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 382 | __mesh_plink_deactivate(sta); |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 383 | sta->plink_state = PLINK_BLOCKED; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 384 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 387 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 388 | void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 389 | size_t len, struct ieee80211_rx_status *rx_status) |
| 390 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 391 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 392 | struct ieee802_11_elems elems; |
| 393 | struct sta_info *sta; |
| 394 | enum plink_event event; |
| 395 | enum plink_frame_type ftype; |
| 396 | size_t baselen; |
| 397 | u8 ie_len; |
| 398 | u8 *baseaddr; |
| 399 | __le16 plid, llid, reason; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 400 | |
Johannes Berg | 9c80d3d | 2008-09-08 15:41:59 +0200 | [diff] [blame] | 401 | /* need action_code, aux */ |
| 402 | if (len < IEEE80211_MIN_ACTION_SIZE + 3) |
| 403 | return; |
| 404 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 405 | if (is_multicast_ether_addr(mgmt->da)) { |
| 406 | mpl_dbg("Mesh plink: ignore frame from multicast address"); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | baseaddr = mgmt->u.action.u.plink_action.variable; |
| 411 | baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt; |
| 412 | if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) { |
| 413 | baseaddr += 4; |
David Woo | 70bdb6b | 2009-08-12 11:03:44 -0700 | [diff] [blame] | 414 | baselen += 4; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 415 | } |
| 416 | ieee802_11_parse_elems(baseaddr, len - baselen, &elems); |
| 417 | if (!elems.peer_link) { |
| 418 | mpl_dbg("Mesh plink: missing necessary peer link ie\n"); |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | ftype = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link)); |
| 423 | ie_len = elems.peer_link_len; |
| 424 | if ((ftype == PLINK_OPEN && ie_len != 3) || |
| 425 | (ftype == PLINK_CONFIRM && ie_len != 5) || |
| 426 | (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) { |
| 427 | mpl_dbg("Mesh plink: incorrect plink ie length\n"); |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) { |
| 432 | mpl_dbg("Mesh plink: missing necessary ie\n"); |
| 433 | return; |
| 434 | } |
| 435 | /* Note the lines below are correct, the llid in the frame is the plid |
| 436 | * from the point of view of this host. |
| 437 | */ |
| 438 | memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2); |
| 439 | if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7)) |
| 440 | memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2); |
| 441 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 442 | rcu_read_lock(); |
| 443 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 444 | sta = sta_info_get(local, mgmt->sa); |
| 445 | if (!sta && ftype != PLINK_OPEN) { |
| 446 | mpl_dbg("Mesh plink: cls or cnf from unknown peer\n"); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 447 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 448 | return; |
| 449 | } |
| 450 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 451 | if (sta && sta->plink_state == PLINK_BLOCKED) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 452 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 453 | return; |
| 454 | } |
| 455 | |
| 456 | /* Now we will figure out the appropriate event... */ |
| 457 | event = PLINK_UNDEFINED; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 458 | if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, sdata))) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 459 | switch (ftype) { |
| 460 | case PLINK_OPEN: |
| 461 | event = OPN_RJCT; |
| 462 | break; |
| 463 | case PLINK_CONFIRM: |
| 464 | event = CNF_RJCT; |
| 465 | break; |
| 466 | case PLINK_CLOSE: |
| 467 | /* avoid warning */ |
| 468 | break; |
| 469 | } |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 470 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 471 | } else if (!sta) { |
| 472 | /* ftype == PLINK_OPEN */ |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 473 | u32 rates; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 474 | if (!mesh_plink_free_count(sdata)) { |
| 475 | mpl_dbg("Mesh plink error: no more free plinks\n"); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 476 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 477 | return; |
| 478 | } |
| 479 | |
| 480 | rates = ieee80211_sta_get_rates(local, &elems, rx_status->band); |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 481 | sta = mesh_plink_alloc(sdata, mgmt->sa, rates); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 482 | if (!sta) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 483 | mpl_dbg("Mesh plink error: plink table full\n"); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 484 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 485 | return; |
| 486 | } |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 487 | if (sta_info_insert(sta)) { |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 488 | rcu_read_unlock(); |
| 489 | return; |
| 490 | } |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 491 | event = OPN_ACPT; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 492 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 493 | } else { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 494 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 495 | switch (ftype) { |
| 496 | case PLINK_OPEN: |
| 497 | if (!mesh_plink_free_count(sdata) || |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 498 | (sta->plid && sta->plid != plid)) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 499 | event = OPN_IGNR; |
| 500 | else |
| 501 | event = OPN_ACPT; |
| 502 | break; |
| 503 | case PLINK_CONFIRM: |
| 504 | if (!mesh_plink_free_count(sdata) || |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 505 | (sta->llid != llid || sta->plid != plid)) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 506 | event = CNF_IGNR; |
| 507 | else |
| 508 | event = CNF_ACPT; |
| 509 | break; |
| 510 | case PLINK_CLOSE: |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 511 | if (sta->plink_state == PLINK_ESTAB) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 512 | /* Do not check for llid or plid. This does not |
| 513 | * follow the standard but since multiple plinks |
| 514 | * per sta are not supported, it is necessary in |
| 515 | * order to avoid a livelock when MP A sees an |
| 516 | * establish peer link to MP B but MP B does not |
| 517 | * see it. This can be caused by a timeout in |
| 518 | * B's peer link establishment or B beign |
| 519 | * restarted. |
| 520 | */ |
| 521 | event = CLS_ACPT; |
| 522 | else if (sta->plid != plid) |
| 523 | event = CLS_IGNR; |
| 524 | else if (ie_len == 7 && sta->llid != llid) |
| 525 | event = CLS_IGNR; |
| 526 | else |
| 527 | event = CLS_ACPT; |
| 528 | break; |
| 529 | default: |
| 530 | mpl_dbg("Mesh plink: unknown frame subtype\n"); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 531 | spin_unlock_bh(&sta->lock); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 532 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 533 | return; |
| 534 | } |
| 535 | } |
| 536 | |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 537 | mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %d %d %d %d\n", |
| 538 | mgmt->sa, sta->plink_state, |
| 539 | le16_to_cpu(sta->llid), le16_to_cpu(sta->plid), |
| 540 | event); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 541 | reason = 0; |
| 542 | switch (sta->plink_state) { |
| 543 | /* spin_unlock as soon as state is updated at each case */ |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 544 | case PLINK_LISTEN: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 545 | switch (event) { |
| 546 | case CLS_ACPT: |
| 547 | mesh_plink_fsm_restart(sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 548 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 549 | break; |
| 550 | case OPN_ACPT: |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 551 | sta->plink_state = PLINK_OPN_RCVD; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 552 | sta->plid = plid; |
| 553 | get_random_bytes(&llid, 2); |
| 554 | sta->llid = llid; |
| 555 | mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 556 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 557 | mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 558 | 0, 0); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 559 | mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 560 | llid, plid, 0); |
| 561 | break; |
| 562 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 563 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 564 | break; |
| 565 | } |
| 566 | break; |
| 567 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 568 | case PLINK_OPN_SNT: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 569 | switch (event) { |
| 570 | case OPN_RJCT: |
| 571 | case CNF_RJCT: |
| 572 | reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION); |
| 573 | case CLS_ACPT: |
| 574 | if (!reason) |
| 575 | reason = cpu_to_le16(MESH_CLOSE_RCVD); |
| 576 | sta->reason = reason; |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 577 | sta->plink_state = PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 578 | if (!mod_plink_timer(sta, |
| 579 | dot11MeshHoldingTimeout(sdata))) |
| 580 | sta->ignore_plink_timer = true; |
| 581 | |
| 582 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 583 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 584 | mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 585 | plid, reason); |
| 586 | break; |
| 587 | case OPN_ACPT: |
| 588 | /* retry timer is left untouched */ |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 589 | sta->plink_state = PLINK_OPN_RCVD; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 590 | sta->plid = plid; |
| 591 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 592 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 593 | mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 594 | plid, 0); |
| 595 | break; |
| 596 | case CNF_ACPT: |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 597 | sta->plink_state = PLINK_CNF_RCVD; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 598 | if (!mod_plink_timer(sta, |
| 599 | dot11MeshConfirmTimeout(sdata))) |
| 600 | sta->ignore_plink_timer = true; |
| 601 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 602 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 603 | break; |
| 604 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 605 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 606 | break; |
| 607 | } |
| 608 | break; |
| 609 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 610 | case PLINK_OPN_RCVD: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 611 | switch (event) { |
| 612 | case OPN_RJCT: |
| 613 | case CNF_RJCT: |
| 614 | reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION); |
| 615 | case CLS_ACPT: |
| 616 | if (!reason) |
| 617 | reason = cpu_to_le16(MESH_CLOSE_RCVD); |
| 618 | sta->reason = reason; |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 619 | sta->plink_state = PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 620 | if (!mod_plink_timer(sta, |
| 621 | dot11MeshHoldingTimeout(sdata))) |
| 622 | sta->ignore_plink_timer = true; |
| 623 | |
| 624 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 625 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 626 | mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 627 | plid, reason); |
| 628 | break; |
| 629 | case OPN_ACPT: |
| 630 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 631 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 632 | mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 633 | plid, 0); |
| 634 | break; |
| 635 | case CNF_ACPT: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 636 | del_timer(&sta->plink_timer); |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 637 | sta->plink_state = PLINK_ESTAB; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 638 | mesh_plink_inc_estab_count(sdata); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 639 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 640 | mpl_dbg("Mesh plink with %pM ESTABLISHED\n", |
| 641 | sta->sta.addr); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 642 | break; |
| 643 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 644 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 645 | break; |
| 646 | } |
| 647 | break; |
| 648 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 649 | case PLINK_CNF_RCVD: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 650 | switch (event) { |
| 651 | case OPN_RJCT: |
| 652 | case CNF_RJCT: |
| 653 | reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION); |
| 654 | case CLS_ACPT: |
| 655 | if (!reason) |
| 656 | reason = cpu_to_le16(MESH_CLOSE_RCVD); |
| 657 | sta->reason = reason; |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 658 | sta->plink_state = PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 659 | if (!mod_plink_timer(sta, |
| 660 | dot11MeshHoldingTimeout(sdata))) |
| 661 | sta->ignore_plink_timer = true; |
| 662 | |
| 663 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 664 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 665 | mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 666 | plid, reason); |
Johannes Berg | ff59dc7 | 2008-02-25 10:11:50 +0100 | [diff] [blame] | 667 | break; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 668 | case OPN_ACPT: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 669 | del_timer(&sta->plink_timer); |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 670 | sta->plink_state = PLINK_ESTAB; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 671 | mesh_plink_inc_estab_count(sdata); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 672 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 673 | mpl_dbg("Mesh plink with %pM ESTABLISHED\n", |
| 674 | sta->sta.addr); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 675 | mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 676 | plid, 0); |
| 677 | break; |
| 678 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 679 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 680 | break; |
| 681 | } |
| 682 | break; |
| 683 | |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 684 | case PLINK_ESTAB: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 685 | switch (event) { |
| 686 | case CLS_ACPT: |
| 687 | reason = cpu_to_le16(MESH_CLOSE_RCVD); |
| 688 | sta->reason = reason; |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 689 | __mesh_plink_deactivate(sta); |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 690 | sta->plink_state = PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 691 | llid = sta->llid; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 692 | mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 693 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 694 | mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 695 | plid, reason); |
| 696 | break; |
| 697 | case OPN_ACPT: |
| 698 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 699 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 700 | mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid, |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 701 | plid, 0); |
| 702 | break; |
| 703 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 704 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 705 | break; |
| 706 | } |
| 707 | break; |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 708 | case PLINK_HOLDING: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 709 | switch (event) { |
| 710 | case CLS_ACPT: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 711 | if (del_timer(&sta->plink_timer)) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 712 | sta->ignore_plink_timer = 1; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 713 | mesh_plink_fsm_restart(sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 714 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 715 | break; |
| 716 | case OPN_ACPT: |
| 717 | case CNF_ACPT: |
| 718 | case OPN_RJCT: |
| 719 | case CNF_RJCT: |
| 720 | llid = sta->llid; |
| 721 | reason = sta->reason; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 722 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 723 | mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, |
| 724 | llid, plid, reason); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 725 | break; |
| 726 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 727 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 728 | } |
| 729 | break; |
| 730 | default: |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 731 | /* should not get here, PLINK_BLOCKED is dealt with at the |
| 732 | * beggining of the function |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 733 | */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 734 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 735 | break; |
| 736 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 737 | |
| 738 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 739 | } |