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