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