Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 1 | /* |
Rui Paulo | 264d9b7 | 2009-11-09 23:46:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2008, 2009 open80211s Ltd. |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 3 | * Author: Luis Carlos Cobo <luisca@cozybit.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/gfp.h> |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/random.h> |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 12 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 13 | #include "rate.h" |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 14 | #include "mesh.h" |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 15 | |
| 16 | #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG |
| 17 | #define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args) |
| 18 | #else |
| 19 | #define mpl_dbg(fmt, args...) do { (void)(0); } while (0) |
| 20 | #endif |
| 21 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 22 | #define PLINK_GET_LLID(p) (p + 2) |
| 23 | #define PLINK_GET_PLID(p) (p + 4) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 24 | |
| 25 | #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \ |
| 26 | jiffies + HZ * t / 1000)) |
| 27 | |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 28 | #define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries) |
| 29 | #define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout) |
| 30 | #define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout) |
| 31 | #define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout) |
| 32 | #define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 33 | |
Ashok Nagarajan | 3d4f969 | 2012-03-06 12:48:30 -0800 | [diff] [blame] | 34 | /* We only need a valid sta if user configured a minimum rssi_threshold. */ |
| 35 | #define rssi_threshold_check(sta, sdata) \ |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 36 | (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\ |
Ashok Nagarajan | 3d4f969 | 2012-03-06 12:48:30 -0800 | [diff] [blame] | 37 | (sta && (s8) -ewma_read(&sta->avg_signal) > \ |
| 38 | sdata->u.mesh.mshcfg.rssi_threshold)) |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 39 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 40 | enum plink_event { |
| 41 | PLINK_UNDEFINED, |
| 42 | OPN_ACPT, |
| 43 | OPN_RJCT, |
| 44 | OPN_IGNR, |
| 45 | CNF_ACPT, |
| 46 | CNF_RJCT, |
| 47 | CNF_IGNR, |
| 48 | CLS_ACPT, |
| 49 | CLS_IGNR |
| 50 | }; |
| 51 | |
Thomas Pedersen | ba4a14e | 2011-09-20 13:43:32 -0700 | [diff] [blame] | 52 | static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata, |
| 53 | enum ieee80211_self_protected_actioncode action, |
| 54 | u8 *da, __le16 llid, __le16 plid, __le16 reason); |
| 55 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 56 | static inline |
| 57 | void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata) |
| 58 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 59 | atomic_inc(&sdata->u.mesh.mshstats.estab_plinks); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 60 | mesh_accept_plinks_update(sdata); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static inline |
| 64 | void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata) |
| 65 | { |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 66 | atomic_dec(&sdata->u.mesh.mshstats.estab_plinks); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 67 | mesh_accept_plinks_update(sdata); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * mesh_plink_fsm_restart - restart a mesh peer link finite state machine |
| 72 | * |
Rui Paulo | 23c7a29 | 2009-11-09 23:46:42 +0000 | [diff] [blame] | 73 | * @sta: mesh peer link to restart |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 74 | * |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 75 | * Locking: this function must be called holding sta->lock |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 76 | */ |
| 77 | static inline void mesh_plink_fsm_restart(struct sta_info *sta) |
| 78 | { |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 79 | sta->plink_state = NL80211_PLINK_LISTEN; |
Luis Carlos Cobo | 37659ff | 2008-02-29 12:13:38 -0800 | [diff] [blame] | 80 | sta->llid = sta->plid = sta->reason = 0; |
| 81 | sta->plink_retries = 0; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 84 | /* |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 85 | * Allocate mesh sta entry and insert into station table |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 86 | */ |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 87 | static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata, |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 88 | u8 *hw_addr) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 89 | { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 90 | struct sta_info *sta; |
| 91 | |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 92 | if (sdata->local->num_sta >= MESH_MAX_PLINKS) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 93 | return NULL; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 94 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 95 | sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 96 | if (!sta) |
| 97 | return NULL; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 98 | |
Johannes Berg | 83d5cc0 | 2012-01-12 09:31:10 +0100 | [diff] [blame] | 99 | sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); |
| 100 | sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); |
| 101 | sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 102 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 103 | set_sta_flag(sta, WLAN_STA_WME); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 104 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 105 | return sta; |
| 106 | } |
| 107 | |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 108 | /** mesh_set_ht_prot_mode - set correct HT protection mode |
| 109 | * |
| 110 | * Section 9.23.3.5 of IEEE 80211s standard describes the protection rules for |
| 111 | * HT mesh STA in a MBSS. Three HT protection modes are supported for now, |
| 112 | * non-HT mixed mode, 20MHz-protection and no-protection mode. non-HT mixed |
| 113 | * mode is selected if any non-HT peers are present in our MBSS. |
| 114 | * 20MHz-protection mode is selected if all peers in our 20/40MHz MBSS support |
| 115 | * HT and atleast one HT20 peer is present. Otherwise no-protection mode is |
| 116 | * selected. |
| 117 | */ |
| 118 | static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata) |
| 119 | { |
| 120 | struct ieee80211_local *local = sdata->local; |
| 121 | struct sta_info *sta; |
| 122 | u32 changed = 0; |
| 123 | u16 ht_opmode; |
| 124 | bool non_ht_sta = false, ht20_sta = false; |
| 125 | |
| 126 | if (local->_oper_channel_type == NL80211_CHAN_NO_HT) |
| 127 | return 0; |
| 128 | |
| 129 | rcu_read_lock(); |
| 130 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 131 | if (sdata == sta->sdata && |
| 132 | sta->plink_state == NL80211_PLINK_ESTAB) { |
| 133 | switch (sta->ch_type) { |
| 134 | case NL80211_CHAN_NO_HT: |
| 135 | mpl_dbg("mesh_plink %pM: nonHT sta (%pM) is present", |
| 136 | sdata->vif.addr, sta->sta.addr); |
| 137 | non_ht_sta = true; |
| 138 | goto out; |
| 139 | case NL80211_CHAN_HT20: |
| 140 | mpl_dbg("mesh_plink %pM: HT20 sta (%pM) is present", |
| 141 | sdata->vif.addr, sta->sta.addr); |
| 142 | ht20_sta = true; |
| 143 | default: |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | out: |
| 149 | rcu_read_unlock(); |
| 150 | |
| 151 | if (non_ht_sta) |
| 152 | ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED; |
| 153 | else if (ht20_sta && local->_oper_channel_type > NL80211_CHAN_HT20) |
| 154 | ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ; |
| 155 | else |
| 156 | ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE; |
| 157 | |
| 158 | if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) { |
| 159 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame^] | 160 | sdata->u.mesh.mshcfg.ht_opmode = ht_opmode; |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 161 | changed = BSS_CHANGED_HT; |
| 162 | mpl_dbg("mesh_plink %pM: protection mode changed to %d", |
| 163 | sdata->vif.addr, ht_opmode); |
| 164 | } |
| 165 | |
| 166 | return changed; |
| 167 | } |
| 168 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 169 | /** |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 170 | * __mesh_plink_deactivate - deactivate mesh peer link |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 171 | * |
| 172 | * @sta: mesh peer link to deactivate |
| 173 | * |
| 174 | * All mesh paths with this peer as next hop will be flushed |
| 175 | * |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 176 | * Locking: the caller must hold sta->lock |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 177 | */ |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 178 | static bool __mesh_plink_deactivate(struct sta_info *sta) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 179 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 180 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 181 | bool deactivated = false; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 182 | |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 183 | if (sta->plink_state == NL80211_PLINK_ESTAB) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 184 | mesh_plink_dec_estab_count(sdata); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 185 | deactivated = true; |
| 186 | } |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 187 | sta->plink_state = NL80211_PLINK_BLOCKED; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 188 | mesh_path_flush_by_nexthop(sta); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 189 | |
| 190 | return deactivated; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 193 | /** |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 194 | * mesh_plink_deactivate - deactivate mesh peer link |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 195 | * |
| 196 | * @sta: mesh peer link to deactivate |
| 197 | * |
| 198 | * All mesh paths with this peer as next hop will be flushed |
| 199 | */ |
| 200 | void mesh_plink_deactivate(struct sta_info *sta) |
| 201 | { |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 202 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 203 | bool deactivated; |
| 204 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 205 | spin_lock_bh(&sta->lock); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 206 | deactivated = __mesh_plink_deactivate(sta); |
Thomas Pedersen | ba4a14e | 2011-09-20 13:43:32 -0700 | [diff] [blame] | 207 | sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED); |
| 208 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
| 209 | sta->sta.addr, sta->llid, sta->plid, |
| 210 | sta->reason); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 211 | spin_unlock_bh(&sta->lock); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 212 | |
| 213 | if (deactivated) |
| 214 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 215 | } |
| 216 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 217 | static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata, |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 218 | enum ieee80211_self_protected_actioncode action, |
| 219 | u8 *da, __le16 llid, __le16 plid, __le16 reason) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 220 | struct ieee80211_local *local = sdata->local; |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 221 | struct sk_buff *skb; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 222 | struct ieee80211_mgmt *mgmt; |
| 223 | bool include_plid = false; |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 224 | u16 peering_proto = 0; |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 225 | u8 *pos, ie_len = 4; |
| 226 | int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) + |
| 227 | sizeof(mgmt->u.action.u.self_prot); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 228 | |
Javier Cardona | 65e8b0c | 2012-01-17 18:17:46 -0800 | [diff] [blame] | 229 | skb = dev_alloc_skb(local->tx_headroom + |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 230 | hdr_len + |
| 231 | 2 + /* capability info */ |
| 232 | 2 + /* AID */ |
| 233 | 2 + 8 + /* supported rates */ |
| 234 | 2 + (IEEE80211_MAX_SUPP_RATES - 8) + |
| 235 | 2 + sdata->u.mesh.mesh_id_len + |
| 236 | 2 + sizeof(struct ieee80211_meshconf_ie) + |
Thomas Pedersen | 176f360 | 2011-10-26 14:47:27 -0700 | [diff] [blame] | 237 | 2 + sizeof(struct ieee80211_ht_cap) + |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 238 | 2 + sizeof(struct ieee80211_ht_operation) + |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 239 | 2 + 8 + /* peering IE */ |
| 240 | sdata->u.mesh.ie_len); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 241 | if (!skb) |
| 242 | return -1; |
Javier Cardona | 65e8b0c | 2012-01-17 18:17:46 -0800 | [diff] [blame] | 243 | skb_reserve(skb, local->tx_headroom); |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 244 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len); |
| 245 | memset(mgmt, 0, hdr_len); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 246 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 247 | IEEE80211_STYPE_ACTION); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 248 | memcpy(mgmt->da, da, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 249 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Javier Cardona | 915b5c5 | 2011-05-03 16:57:10 -0700 | [diff] [blame] | 250 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 251 | mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED; |
| 252 | mgmt->u.action.u.self_prot.action_code = action; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 253 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 254 | if (action != WLAN_SP_MESH_PEERING_CLOSE) { |
| 255 | /* capability info */ |
| 256 | pos = skb_put(skb, 2); |
| 257 | memset(pos, 0, 2); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 258 | if (action == WLAN_SP_MESH_PEERING_CONFIRM) { |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 259 | /* AID */ |
| 260 | pos = skb_put(skb, 2); |
Rui Paulo | 77fa76b | 2009-11-09 23:46:52 +0000 | [diff] [blame] | 261 | memcpy(pos + 2, &plid, 2); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 262 | } |
Ashok Nagarajan | 657c3e0 | 2012-04-02 21:21:20 -0700 | [diff] [blame] | 263 | if (ieee80211_add_srates_ie(&sdata->vif, skb, true) || |
| 264 | ieee80211_add_ext_srates_ie(&sdata->vif, skb, true) || |
Thomas Pedersen | 082ebb0 | 2011-08-11 19:35:10 -0700 | [diff] [blame] | 265 | mesh_add_rsn_ie(skb, sdata) || |
| 266 | mesh_add_meshid_ie(skb, sdata) || |
| 267 | mesh_add_meshconf_ie(skb, sdata)) |
| 268 | return -1; |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 269 | } else { /* WLAN_SP_MESH_PEERING_CLOSE */ |
| 270 | if (mesh_add_meshid_ie(skb, sdata)) |
| 271 | return -1; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 274 | /* Add Mesh Peering Management element */ |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 275 | switch (action) { |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 276 | case WLAN_SP_MESH_PEERING_OPEN: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 277 | break; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 278 | case WLAN_SP_MESH_PEERING_CONFIRM: |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 279 | ie_len += 2; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 280 | include_plid = true; |
| 281 | break; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 282 | case WLAN_SP_MESH_PEERING_CLOSE: |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 283 | if (plid) { |
| 284 | ie_len += 2; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 285 | include_plid = true; |
| 286 | } |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 287 | ie_len += 2; /* reason code */ |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 288 | break; |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 289 | default: |
| 290 | return -EINVAL; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 293 | if (WARN_ON(skb_tailroom(skb) < 2 + ie_len)) |
| 294 | return -ENOMEM; |
| 295 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 296 | pos = skb_put(skb, 2 + ie_len); |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 297 | *pos++ = WLAN_EID_PEER_MGMT; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 298 | *pos++ = ie_len; |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 299 | memcpy(pos, &peering_proto, 2); |
| 300 | pos += 2; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 301 | memcpy(pos, &llid, 2); |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 302 | pos += 2; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 303 | if (include_plid) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 304 | memcpy(pos, &plid, 2); |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 305 | pos += 2; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 306 | } |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 307 | if (action == WLAN_SP_MESH_PEERING_CLOSE) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 308 | memcpy(pos, &reason, 2); |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 309 | pos += 2; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 310 | } |
Thomas Pedersen | 176f360 | 2011-10-26 14:47:27 -0700 | [diff] [blame] | 311 | |
| 312 | if (action != WLAN_SP_MESH_PEERING_CLOSE) { |
| 313 | if (mesh_add_ht_cap_ie(skb, sdata) || |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 314 | mesh_add_ht_oper_ie(skb, sdata)) |
Thomas Pedersen | 176f360 | 2011-10-26 14:47:27 -0700 | [diff] [blame] | 315 | return -1; |
| 316 | } |
| 317 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 318 | if (mesh_add_vendor_ies(skb, sdata)) |
| 319 | return -1; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 320 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 321 | ieee80211_tx_skb(sdata, skb); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 325 | /* mesh_peer_init - initialize new mesh peer and return resulting sta_info |
| 326 | * |
| 327 | * @sdata: local meshif |
| 328 | * @addr: peer's address |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 329 | * @elems: IEs from beacon or mesh peering frame |
| 330 | * |
| 331 | * call under RCU |
| 332 | */ |
| 333 | static struct sta_info *mesh_peer_init(struct ieee80211_sub_if_data *sdata, |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 334 | u8 *addr, |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 335 | struct ieee802_11_elems *elems) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 336 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 337 | struct ieee80211_local *local = sdata->local; |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 338 | enum ieee80211_band band = local->oper_channel->band; |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 339 | struct ieee80211_supported_band *sband; |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 340 | u32 rates, basic_rates = 0; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 341 | struct sta_info *sta; |
Thomas Pedersen | e87278e | 2012-04-26 15:01:06 -0700 | [diff] [blame] | 342 | bool insert = false; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 343 | |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 344 | sband = local->hw.wiphy->bands[band]; |
| 345 | rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 346 | |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 347 | sta = sta_info_get(sdata, addr); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 348 | if (!sta) { |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 349 | sta = mesh_plink_alloc(sdata, addr); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 350 | if (!sta) |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 351 | return NULL; |
Thomas Pedersen | e87278e | 2012-04-26 15:01:06 -0700 | [diff] [blame] | 352 | insert = true; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 355 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 356 | sta->last_rx = jiffies; |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 357 | sta->sta.supp_rates[band] = rates; |
Thomas Pedersen | e76781e | 2012-04-18 19:24:13 -0700 | [diff] [blame] | 358 | if (elems->ht_cap_elem && |
| 359 | sdata->local->_oper_channel_type != NL80211_CHAN_NO_HT) |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 360 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
| 361 | elems->ht_cap_elem, |
| 362 | &sta->sta.ht_cap); |
| 363 | else |
| 364 | memset(&sta->sta.ht_cap, 0, sizeof(sta->sta.ht_cap)); |
| 365 | |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 366 | if (elems->ht_operation) { |
Thomas Pedersen | c7d2582 | 2012-04-26 15:01:07 -0700 | [diff] [blame] | 367 | if (!(elems->ht_operation->ht_param & |
| 368 | IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) |
| 369 | sta->sta.ht_cap.cap &= |
| 370 | ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 371 | sta->ch_type = |
| 372 | ieee80211_ht_oper_to_channel_type(elems->ht_operation); |
| 373 | } |
Thomas Pedersen | c7d2582 | 2012-04-26 15:01:07 -0700 | [diff] [blame] | 374 | |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 375 | rate_control_rate_init(sta); |
| 376 | spin_unlock_bh(&sta->lock); |
| 377 | |
Thomas Pedersen | e87278e | 2012-04-26 15:01:06 -0700 | [diff] [blame] | 378 | if (insert && sta_info_insert(sta)) |
| 379 | return NULL; |
| 380 | |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 381 | return sta; |
| 382 | } |
| 383 | |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 384 | void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata, |
| 385 | u8 *hw_addr, |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 386 | struct ieee802_11_elems *elems) |
| 387 | { |
| 388 | struct sta_info *sta; |
| 389 | |
| 390 | /* Userspace handles peer allocation when security is enabled */ |
| 391 | if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) { |
| 392 | cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr, |
| 393 | elems->ie_start, |
| 394 | elems->total_len, |
| 395 | GFP_KERNEL); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | rcu_read_lock(); |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 400 | sta = mesh_peer_init(sdata, hw_addr, elems); |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 401 | if (!sta) |
| 402 | goto out; |
| 403 | |
Javier Cardona | 1570ca5 | 2011-04-07 15:08:35 -0700 | [diff] [blame] | 404 | if (mesh_peer_accepts_plinks(elems) && |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 405 | sta->plink_state == NL80211_PLINK_LISTEN && |
| 406 | sdata->u.mesh.accepting_plinks && |
| 407 | sdata->u.mesh.mshcfg.auto_open_plinks && |
| 408 | rssi_threshold_check(sta, sdata)) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 409 | mesh_plink_open(sta); |
| 410 | |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 411 | out: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 412 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static void mesh_plink_timer(unsigned long data) |
| 416 | { |
| 417 | struct sta_info *sta; |
| 418 | __le16 llid, plid, reason; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 419 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 420 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 421 | /* |
| 422 | * This STA is valid because sta_info_destroy() will |
| 423 | * del_timer_sync() this timer after having made sure |
| 424 | * it cannot be readded (by deleting the plink.) |
| 425 | */ |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 426 | sta = (struct sta_info *) data; |
| 427 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 428 | if (sta->sdata->local->quiescing) { |
| 429 | sta->plink_timer_was_running = true; |
| 430 | return; |
| 431 | } |
| 432 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 433 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 434 | if (sta->ignore_plink_timer) { |
| 435 | sta->ignore_plink_timer = false; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 436 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 437 | return; |
| 438 | } |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 439 | mpl_dbg("Mesh plink timer for %pM fired on state %d\n", |
| 440 | sta->sta.addr, sta->plink_state); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 441 | reason = 0; |
| 442 | llid = sta->llid; |
| 443 | plid = sta->plid; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 444 | sdata = sta->sdata; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 445 | |
| 446 | switch (sta->plink_state) { |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 447 | case NL80211_PLINK_OPN_RCVD: |
| 448 | case NL80211_PLINK_OPN_SNT: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 449 | /* retry timer */ |
| 450 | if (sta->plink_retries < dot11MeshMaxRetries(sdata)) { |
| 451 | u32 rand; |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 452 | mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n", |
| 453 | sta->sta.addr, sta->plink_retries, |
| 454 | sta->plink_timeout); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 455 | get_random_bytes(&rand, sizeof(u32)); |
| 456 | sta->plink_timeout = sta->plink_timeout + |
| 457 | rand % sta->plink_timeout; |
| 458 | ++sta->plink_retries; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 459 | mod_plink_timer(sta, sta->plink_timeout); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 460 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 461 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN, |
| 462 | sta->sta.addr, llid, 0, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 463 | break; |
| 464 | } |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 465 | reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 466 | /* fall through on else */ |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 467 | case NL80211_PLINK_CNF_RCVD: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 468 | /* confirm timer */ |
| 469 | if (!reason) |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 470 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT); |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 471 | sta->plink_state = NL80211_PLINK_HOLDING; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 472 | mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 473 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 474 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
| 475 | sta->sta.addr, llid, plid, reason); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 476 | break; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 477 | case NL80211_PLINK_HOLDING: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 478 | /* holding timer */ |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 479 | del_timer(&sta->plink_timer); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 480 | mesh_plink_fsm_restart(sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 481 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 482 | break; |
| 483 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 484 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 485 | break; |
| 486 | } |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 489 | #ifdef CONFIG_PM |
| 490 | void mesh_plink_quiesce(struct sta_info *sta) |
| 491 | { |
| 492 | if (del_timer_sync(&sta->plink_timer)) |
| 493 | sta->plink_timer_was_running = true; |
| 494 | } |
| 495 | |
| 496 | void mesh_plink_restart(struct sta_info *sta) |
| 497 | { |
| 498 | if (sta->plink_timer_was_running) { |
| 499 | add_timer(&sta->plink_timer); |
| 500 | sta->plink_timer_was_running = false; |
| 501 | } |
| 502 | } |
| 503 | #endif |
| 504 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 505 | static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout) |
| 506 | { |
| 507 | sta->plink_timer.expires = jiffies + (HZ * timeout / 1000); |
| 508 | sta->plink_timer.data = (unsigned long) sta; |
| 509 | sta->plink_timer.function = mesh_plink_timer; |
| 510 | sta->plink_timeout = timeout; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 511 | add_timer(&sta->plink_timer); |
| 512 | } |
| 513 | |
| 514 | int mesh_plink_open(struct sta_info *sta) |
| 515 | { |
| 516 | __le16 llid; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 517 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 518 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 519 | if (!test_sta_flag(sta, WLAN_STA_AUTH)) |
Javier Cardona | 53e8051 | 2011-04-07 15:08:32 -0700 | [diff] [blame] | 520 | return -EPERM; |
| 521 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 522 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 523 | get_random_bytes(&llid, 2); |
| 524 | sta->llid = llid; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 525 | if (sta->plink_state != NL80211_PLINK_LISTEN) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 526 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 527 | return -EBUSY; |
| 528 | } |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 529 | sta->plink_state = NL80211_PLINK_OPN_SNT; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 530 | mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 531 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 532 | mpl_dbg("Mesh plink: starting establishment with %pM\n", |
| 533 | sta->sta.addr); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 534 | |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 535 | return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 536 | sta->sta.addr, llid, 0, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | void mesh_plink_block(struct sta_info *sta) |
| 540 | { |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 541 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 542 | bool deactivated; |
| 543 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 544 | spin_lock_bh(&sta->lock); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 545 | deactivated = __mesh_plink_deactivate(sta); |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 546 | sta->plink_state = NL80211_PLINK_BLOCKED; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 547 | spin_unlock_bh(&sta->lock); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 548 | |
| 549 | if (deactivated) |
| 550 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 551 | } |
| 552 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 553 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 554 | 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] | 555 | size_t len, struct ieee80211_rx_status *rx_status) |
| 556 | { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 557 | struct ieee802_11_elems elems; |
| 558 | struct sta_info *sta; |
| 559 | enum plink_event event; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 560 | enum ieee80211_self_protected_actioncode ftype; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 561 | size_t baselen; |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 562 | bool matches_local = true; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 563 | u8 ie_len; |
| 564 | u8 *baseaddr; |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 565 | u32 changed = 0; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 566 | __le16 plid, llid, reason; |
Rui Paulo | 1460dd1 | 2009-11-09 23:46:48 +0000 | [diff] [blame] | 567 | #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG |
| 568 | static const char *mplstates[] = { |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 569 | [NL80211_PLINK_LISTEN] = "LISTEN", |
| 570 | [NL80211_PLINK_OPN_SNT] = "OPN-SNT", |
| 571 | [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD", |
| 572 | [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD", |
| 573 | [NL80211_PLINK_ESTAB] = "ESTAB", |
| 574 | [NL80211_PLINK_HOLDING] = "HOLDING", |
| 575 | [NL80211_PLINK_BLOCKED] = "BLOCKED" |
Rui Paulo | 1460dd1 | 2009-11-09 23:46:48 +0000 | [diff] [blame] | 576 | }; |
| 577 | #endif |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 578 | |
Johannes Berg | 9c80d3d | 2008-09-08 15:41:59 +0200 | [diff] [blame] | 579 | /* need action_code, aux */ |
| 580 | if (len < IEEE80211_MIN_ACTION_SIZE + 3) |
| 581 | return; |
| 582 | |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 583 | if (is_multicast_ether_addr(mgmt->da)) { |
| 584 | mpl_dbg("Mesh plink: ignore frame from multicast address"); |
| 585 | return; |
| 586 | } |
| 587 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 588 | baseaddr = mgmt->u.action.u.self_prot.variable; |
| 589 | baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt; |
| 590 | if (mgmt->u.action.u.self_prot.action_code == |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 591 | WLAN_SP_MESH_PEERING_CONFIRM) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 592 | baseaddr += 4; |
David Woo | 70bdb6b | 2009-08-12 11:03:44 -0700 | [diff] [blame] | 593 | baselen += 4; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 594 | } |
| 595 | ieee802_11_parse_elems(baseaddr, len - baselen, &elems); |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 596 | if (!elems.peering) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 597 | mpl_dbg("Mesh plink: missing necessary peer link ie\n"); |
| 598 | return; |
| 599 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 600 | if (elems.rsn_len && |
| 601 | sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) { |
Javier Cardona | 5cff5e0 | 2011-04-07 15:08:29 -0700 | [diff] [blame] | 602 | mpl_dbg("Mesh plink: can't establish link with secure peer\n"); |
| 603 | return; |
| 604 | } |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 605 | |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 606 | ftype = mgmt->u.action.u.self_prot.action_code; |
| 607 | ie_len = elems.peering_len; |
| 608 | if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) || |
| 609 | (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) || |
| 610 | (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6 |
| 611 | && ie_len != 8)) { |
Rui Paulo | 0938393 | 2009-11-09 23:46:43 +0000 | [diff] [blame] | 612 | mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n", |
| 613 | ftype, ie_len); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 614 | return; |
| 615 | } |
| 616 | |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 617 | if (ftype != WLAN_SP_MESH_PEERING_CLOSE && |
| 618 | (!elems.mesh_id || !elems.mesh_config)) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 619 | mpl_dbg("Mesh plink: missing necessary ie\n"); |
| 620 | return; |
| 621 | } |
| 622 | /* Note the lines below are correct, the llid in the frame is the plid |
| 623 | * from the point of view of this host. |
| 624 | */ |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 625 | memcpy(&plid, PLINK_GET_LLID(elems.peering), 2); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 626 | if (ftype == WLAN_SP_MESH_PEERING_CONFIRM || |
Thomas Pedersen | 8db0985 | 2011-08-12 20:01:00 -0700 | [diff] [blame] | 627 | (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8)) |
| 628 | memcpy(&llid, PLINK_GET_PLID(elems.peering), 2); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 629 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 630 | rcu_read_lock(); |
| 631 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 632 | sta = sta_info_get(sdata, mgmt->sa); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 633 | if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 634 | mpl_dbg("Mesh plink: cls or cnf from unknown peer\n"); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 635 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 636 | return; |
| 637 | } |
| 638 | |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 639 | if (ftype == WLAN_SP_MESH_PEERING_OPEN && |
Ashok Nagarajan | 3d4f969 | 2012-03-06 12:48:30 -0800 | [diff] [blame] | 640 | !rssi_threshold_check(sta, sdata)) { |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 641 | mpl_dbg("Mesh plink: %pM does not meet rssi threshold\n", |
Ashok Nagarajan | 3d4f969 | 2012-03-06 12:48:30 -0800 | [diff] [blame] | 642 | mgmt->sa); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 643 | rcu_read_unlock(); |
| 644 | return; |
| 645 | } |
| 646 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 647 | if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) { |
Javier Cardona | 53e8051 | 2011-04-07 15:08:32 -0700 | [diff] [blame] | 648 | mpl_dbg("Mesh plink: Action frame from non-authed peer\n"); |
| 649 | rcu_read_unlock(); |
| 650 | return; |
| 651 | } |
| 652 | |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 653 | if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 654 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 655 | return; |
| 656 | } |
| 657 | |
| 658 | /* Now we will figure out the appropriate event... */ |
| 659 | event = PLINK_UNDEFINED; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 660 | if (ftype != WLAN_SP_MESH_PEERING_CLOSE && |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 661 | !mesh_matches_local(sdata, &elems)) { |
Christian Lamparter | d12c745 | 2010-10-08 22:27:07 +0200 | [diff] [blame] | 662 | matches_local = false; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 663 | switch (ftype) { |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 664 | case WLAN_SP_MESH_PEERING_OPEN: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 665 | event = OPN_RJCT; |
| 666 | break; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 667 | case WLAN_SP_MESH_PEERING_CONFIRM: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 668 | event = CNF_RJCT; |
| 669 | break; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 670 | default: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 671 | break; |
| 672 | } |
Christian Lamparter | d12c745 | 2010-10-08 22:27:07 +0200 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | if (!sta && !matches_local) { |
| 676 | rcu_read_unlock(); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 677 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
Christian Lamparter | d12c745 | 2010-10-08 22:27:07 +0200 | [diff] [blame] | 678 | llid = 0; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 679 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
| 680 | mgmt->sa, llid, plid, reason); |
Christian Lamparter | d12c745 | 2010-10-08 22:27:07 +0200 | [diff] [blame] | 681 | return; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 682 | } else if (!sta) { |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 683 | /* ftype == WLAN_SP_MESH_PEERING_OPEN */ |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 684 | if (!mesh_plink_free_count(sdata)) { |
| 685 | mpl_dbg("Mesh plink error: no more free plinks\n"); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 686 | rcu_read_unlock(); |
| 687 | return; |
| 688 | } |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 689 | event = OPN_ACPT; |
Christian Lamparter | d12c745 | 2010-10-08 22:27:07 +0200 | [diff] [blame] | 690 | } else if (matches_local) { |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 691 | switch (ftype) { |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 692 | case WLAN_SP_MESH_PEERING_OPEN: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 693 | if (!mesh_plink_free_count(sdata) || |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 694 | (sta->plid && sta->plid != plid)) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 695 | event = OPN_IGNR; |
| 696 | else |
| 697 | event = OPN_ACPT; |
| 698 | break; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 699 | case WLAN_SP_MESH_PEERING_CONFIRM: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 700 | if (!mesh_plink_free_count(sdata) || |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 701 | (sta->llid != llid || sta->plid != plid)) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 702 | event = CNF_IGNR; |
| 703 | else |
| 704 | event = CNF_ACPT; |
| 705 | break; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 706 | case WLAN_SP_MESH_PEERING_CLOSE: |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 707 | if (sta->plink_state == NL80211_PLINK_ESTAB) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 708 | /* Do not check for llid or plid. This does not |
| 709 | * follow the standard but since multiple plinks |
| 710 | * per sta are not supported, it is necessary in |
| 711 | * order to avoid a livelock when MP A sees an |
| 712 | * establish peer link to MP B but MP B does not |
| 713 | * see it. This can be caused by a timeout in |
| 714 | * B's peer link establishment or B beign |
| 715 | * restarted. |
| 716 | */ |
| 717 | event = CLS_ACPT; |
| 718 | else if (sta->plid != plid) |
| 719 | event = CLS_IGNR; |
| 720 | else if (ie_len == 7 && sta->llid != llid) |
| 721 | event = CLS_IGNR; |
| 722 | else |
| 723 | event = CLS_ACPT; |
| 724 | break; |
| 725 | default: |
| 726 | mpl_dbg("Mesh plink: unknown frame subtype\n"); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 727 | rcu_read_unlock(); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 728 | return; |
| 729 | } |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | if (event == OPN_ACPT) { |
| 733 | /* allocate sta entry if necessary and update info */ |
Thomas Pedersen | f743ff4 | 2012-04-18 19:23:43 -0700 | [diff] [blame] | 734 | sta = mesh_peer_init(sdata, mgmt->sa, &elems); |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 735 | if (!sta) { |
| 736 | mpl_dbg("Mesh plink: failed to init peer!\n"); |
| 737 | rcu_read_unlock(); |
| 738 | return; |
| 739 | } |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 740 | } |
| 741 | |
Rui Paulo | 1460dd1 | 2009-11-09 23:46:48 +0000 | [diff] [blame] | 742 | mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n", |
| 743 | mgmt->sa, mplstates[sta->plink_state], |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 744 | le16_to_cpu(sta->llid), le16_to_cpu(sta->plid), |
| 745 | event); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 746 | reason = 0; |
Thomas Pedersen | 54ab1ff | 2012-04-18 19:23:42 -0700 | [diff] [blame] | 747 | spin_lock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 748 | switch (sta->plink_state) { |
| 749 | /* spin_unlock as soon as state is updated at each case */ |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 750 | case NL80211_PLINK_LISTEN: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 751 | switch (event) { |
| 752 | case CLS_ACPT: |
| 753 | mesh_plink_fsm_restart(sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 754 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 755 | break; |
| 756 | case OPN_ACPT: |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 757 | sta->plink_state = NL80211_PLINK_OPN_RCVD; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 758 | sta->plid = plid; |
| 759 | get_random_bytes(&llid, 2); |
| 760 | sta->llid = llid; |
| 761 | mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 762 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 763 | mesh_plink_frame_tx(sdata, |
| 764 | WLAN_SP_MESH_PEERING_OPEN, |
| 765 | sta->sta.addr, llid, 0, 0); |
| 766 | mesh_plink_frame_tx(sdata, |
| 767 | WLAN_SP_MESH_PEERING_CONFIRM, |
| 768 | sta->sta.addr, llid, plid, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 769 | break; |
| 770 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 771 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 772 | break; |
| 773 | } |
| 774 | break; |
| 775 | |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 776 | case NL80211_PLINK_OPN_SNT: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 777 | switch (event) { |
| 778 | case OPN_RJCT: |
| 779 | case CNF_RJCT: |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 780 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 781 | case CLS_ACPT: |
| 782 | if (!reason) |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 783 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 784 | sta->reason = reason; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 785 | sta->plink_state = NL80211_PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 786 | if (!mod_plink_timer(sta, |
| 787 | dot11MeshHoldingTimeout(sdata))) |
| 788 | sta->ignore_plink_timer = true; |
| 789 | |
| 790 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 791 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 792 | mesh_plink_frame_tx(sdata, |
| 793 | WLAN_SP_MESH_PEERING_CLOSE, |
| 794 | sta->sta.addr, llid, plid, reason); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 795 | break; |
| 796 | case OPN_ACPT: |
| 797 | /* retry timer is left untouched */ |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 798 | sta->plink_state = NL80211_PLINK_OPN_RCVD; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 799 | sta->plid = plid; |
| 800 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 801 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 802 | mesh_plink_frame_tx(sdata, |
| 803 | WLAN_SP_MESH_PEERING_CONFIRM, |
| 804 | sta->sta.addr, llid, plid, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 805 | break; |
| 806 | case CNF_ACPT: |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 807 | sta->plink_state = NL80211_PLINK_CNF_RCVD; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 808 | if (!mod_plink_timer(sta, |
| 809 | dot11MeshConfirmTimeout(sdata))) |
| 810 | sta->ignore_plink_timer = true; |
| 811 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 812 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 813 | break; |
| 814 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 815 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 816 | break; |
| 817 | } |
| 818 | break; |
| 819 | |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 820 | case NL80211_PLINK_OPN_RCVD: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 821 | switch (event) { |
| 822 | case OPN_RJCT: |
| 823 | case CNF_RJCT: |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 824 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 825 | case CLS_ACPT: |
| 826 | if (!reason) |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 827 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 828 | sta->reason = reason; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 829 | sta->plink_state = NL80211_PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 830 | if (!mod_plink_timer(sta, |
| 831 | dot11MeshHoldingTimeout(sdata))) |
| 832 | sta->ignore_plink_timer = true; |
| 833 | |
| 834 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 835 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 836 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
| 837 | sta->sta.addr, llid, plid, reason); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 838 | break; |
| 839 | case OPN_ACPT: |
| 840 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 841 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 842 | mesh_plink_frame_tx(sdata, |
| 843 | WLAN_SP_MESH_PEERING_CONFIRM, |
| 844 | sta->sta.addr, llid, plid, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 845 | break; |
| 846 | case CNF_ACPT: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 847 | del_timer(&sta->plink_timer); |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 848 | sta->plink_state = NL80211_PLINK_ESTAB; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 849 | spin_unlock_bh(&sta->lock); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 850 | mesh_plink_inc_estab_count(sdata); |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 851 | changed |= mesh_set_ht_prot_mode(sdata); |
| 852 | changed |= BSS_CHANGED_BEACON; |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 853 | mpl_dbg("Mesh plink with %pM ESTABLISHED\n", |
| 854 | sta->sta.addr); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 855 | break; |
| 856 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 857 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 858 | break; |
| 859 | } |
| 860 | break; |
| 861 | |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 862 | case NL80211_PLINK_CNF_RCVD: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 863 | switch (event) { |
| 864 | case OPN_RJCT: |
| 865 | case CNF_RJCT: |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 866 | reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 867 | case CLS_ACPT: |
| 868 | if (!reason) |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 869 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 870 | sta->reason = reason; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 871 | sta->plink_state = NL80211_PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 872 | if (!mod_plink_timer(sta, |
| 873 | dot11MeshHoldingTimeout(sdata))) |
| 874 | sta->ignore_plink_timer = true; |
| 875 | |
| 876 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 877 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 878 | mesh_plink_frame_tx(sdata, |
| 879 | WLAN_SP_MESH_PEERING_CLOSE, |
| 880 | sta->sta.addr, llid, plid, reason); |
Johannes Berg | ff59dc7 | 2008-02-25 10:11:50 +0100 | [diff] [blame] | 881 | break; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 882 | case OPN_ACPT: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 883 | del_timer(&sta->plink_timer); |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 884 | sta->plink_state = NL80211_PLINK_ESTAB; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 885 | spin_unlock_bh(&sta->lock); |
John W. Linville | c937019 | 2010-06-21 17:14:07 -0400 | [diff] [blame] | 886 | mesh_plink_inc_estab_count(sdata); |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 887 | changed |= mesh_set_ht_prot_mode(sdata); |
| 888 | changed |= BSS_CHANGED_BEACON; |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 889 | mpl_dbg("Mesh plink with %pM ESTABLISHED\n", |
| 890 | sta->sta.addr); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 891 | mesh_plink_frame_tx(sdata, |
| 892 | WLAN_SP_MESH_PEERING_CONFIRM, |
| 893 | sta->sta.addr, llid, plid, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 894 | break; |
| 895 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 896 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 897 | break; |
| 898 | } |
| 899 | break; |
| 900 | |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 901 | case NL80211_PLINK_ESTAB: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 902 | switch (event) { |
| 903 | case CLS_ACPT: |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 904 | reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 905 | sta->reason = reason; |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 906 | __mesh_plink_deactivate(sta); |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 907 | sta->plink_state = NL80211_PLINK_HOLDING; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 908 | llid = sta->llid; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 909 | mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 910 | spin_unlock_bh(&sta->lock); |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 911 | changed |= mesh_set_ht_prot_mode(sdata); |
| 912 | changed |= BSS_CHANGED_BEACON; |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 913 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
| 914 | sta->sta.addr, llid, plid, reason); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 915 | break; |
| 916 | case OPN_ACPT: |
| 917 | llid = sta->llid; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 918 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 919 | mesh_plink_frame_tx(sdata, |
| 920 | WLAN_SP_MESH_PEERING_CONFIRM, |
| 921 | sta->sta.addr, llid, plid, 0); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 922 | break; |
| 923 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 924 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 925 | break; |
| 926 | } |
| 927 | break; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 928 | case NL80211_PLINK_HOLDING: |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 929 | switch (event) { |
| 930 | case CLS_ACPT: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 931 | if (del_timer(&sta->plink_timer)) |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 932 | sta->ignore_plink_timer = 1; |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 933 | mesh_plink_fsm_restart(sta); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 934 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 935 | break; |
| 936 | case OPN_ACPT: |
| 937 | case CNF_ACPT: |
| 938 | case OPN_RJCT: |
| 939 | case CNF_RJCT: |
| 940 | llid = sta->llid; |
| 941 | reason = sta->reason; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 942 | spin_unlock_bh(&sta->lock); |
Thomas Pedersen | 54ef656 | 2011-08-11 19:35:12 -0700 | [diff] [blame] | 943 | mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE, |
| 944 | sta->sta.addr, llid, plid, reason); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 945 | break; |
| 946 | default: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 947 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 948 | } |
| 949 | break; |
| 950 | default: |
Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 951 | /* should not get here, PLINK_BLOCKED is dealt with at the |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 952 | * beginning of the function |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 953 | */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 954 | spin_unlock_bh(&sta->lock); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 955 | break; |
| 956 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 957 | |
| 958 | rcu_read_unlock(); |
Ashok Nagarajan | 57aac7c | 2012-04-30 14:20:30 -0700 | [diff] [blame] | 959 | |
| 960 | if (changed) |
| 961 | ieee80211_bss_info_change_notify(sdata, changed); |
Luis Carlos Cobo | c3896d2 | 2008-02-23 15:17:13 +0100 | [diff] [blame] | 962 | } |