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