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