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