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