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