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