mac80211: reorder mesh_plink to remove forward decl
[deliverable/linux.git] / net / mac80211 / mesh_plink.c
CommitLineData
c3896d2c 1/*
264d9b7d 2 * Copyright (c) 2008, 2009 open80211s Ltd.
c3896d2c
LCC
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 */
5a0e3ad6 9#include <linux/gfp.h>
902acc78
JB
10#include <linux/kernel.h>
11#include <linux/random.h>
c3896d2c 12#include "ieee80211_i.h"
2c8dccc7 13#include "rate.h"
c3896d2c 14#include "mesh.h"
c3896d2c 15
8db09850
TP
16#define PLINK_GET_LLID(p) (p + 2)
17#define PLINK_GET_PLID(p) (p + 4)
c3896d2c 18
433f5bc1 19#define mod_plink_timer(s, t) (mod_timer(&s->mesh->plink_timer, \
cc57ac53 20 jiffies + msecs_to_jiffies(t)))
c3896d2c 21
c3896d2c
LCC
22enum plink_event {
23 PLINK_UNDEFINED,
24 OPN_ACPT,
25 OPN_RJCT,
26 OPN_IGNR,
27 CNF_ACPT,
28 CNF_RJCT,
29 CNF_IGNR,
30 CLS_ACPT,
31 CLS_IGNR
32};
33
95e48add
TP
34static const char * const mplstates[] = {
35 [NL80211_PLINK_LISTEN] = "LISTEN",
36 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
37 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
38 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
39 [NL80211_PLINK_ESTAB] = "ESTAB",
40 [NL80211_PLINK_HOLDING] = "HOLDING",
41 [NL80211_PLINK_BLOCKED] = "BLOCKED"
42};
43
44static const char * const mplevents[] = {
45 [PLINK_UNDEFINED] = "NONE",
46 [OPN_ACPT] = "OPN_ACPT",
47 [OPN_RJCT] = "OPN_RJCT",
48 [OPN_IGNR] = "OPN_IGNR",
49 [CNF_ACPT] = "CNF_ACPT",
50 [CNF_RJCT] = "CNF_RJCT",
51 [CNF_IGNR] = "CNF_IGNR",
52 [CLS_ACPT] = "CLS_ACPT",
53 [CLS_IGNR] = "CLS_IGNR"
54};
55
36c9bb29
BC
56/* We only need a valid sta if user configured a minimum rssi_threshold. */
57static bool rssi_threshold_check(struct ieee80211_sub_if_data *sdata,
58 struct sta_info *sta)
59{
60 s32 rssi_threshold = sdata->u.mesh.mshcfg.rssi_threshold;
61 return rssi_threshold == 0 ||
62 (sta && (s8) -ewma_read(&sta->avg_signal) > rssi_threshold);
63}
64
c3896d2c
LCC
65/**
66 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
67 *
23c7a29c 68 * @sta: mesh peer link to restart
c3896d2c 69 *
433f5bc1 70 * Locking: this function must be called holding sta->mesh->plink_lock
c3896d2c
LCC
71 */
72static inline void mesh_plink_fsm_restart(struct sta_info *sta)
73{
433f5bc1
JB
74 lockdep_assert_held(&sta->mesh->plink_lock);
75 sta->mesh->plink_state = NL80211_PLINK_LISTEN;
76 sta->mesh->llid = sta->mesh->plid = sta->mesh->reason = 0;
77 sta->mesh->plink_retries = 0;
c3896d2c
LCC
78}
79
3b144658
TP
80/*
81 * mesh_set_short_slot_time - enable / disable ERP short slot time.
82 *
83 * The standard indirectly mandates mesh STAs to turn off short slot time by
84 * disallowing advertising this (802.11-2012 8.4.1.4), but that doesn't mean we
85 * can't be sneaky about it. Enable short slot time if all mesh STAs in the
86 * MBSS support ERP rates.
87 *
88 * Returns BSS_CHANGED_ERP_SLOT or 0 for no change.
89 */
90static u32 mesh_set_short_slot_time(struct ieee80211_sub_if_data *sdata)
91{
92 struct ieee80211_local *local = sdata->local;
93 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
94 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
95 struct sta_info *sta;
96 u32 erp_rates = 0, changed = 0;
97 int i;
98 bool short_slot = false;
99
100 if (band == IEEE80211_BAND_5GHZ) {
101 /* (IEEE 802.11-2012 19.4.5) */
102 short_slot = true;
103 goto out;
ea1b2b45 104 } else if (band != IEEE80211_BAND_2GHZ)
3b144658
TP
105 goto out;
106
107 for (i = 0; i < sband->n_bitrates; i++)
108 if (sband->bitrates[i].flags & IEEE80211_RATE_ERP_G)
109 erp_rates |= BIT(i);
110
111 if (!erp_rates)
112 goto out;
113
114 rcu_read_lock();
115 list_for_each_entry_rcu(sta, &local->sta_list, list) {
116 if (sdata != sta->sdata ||
433f5bc1 117 sta->mesh->plink_state != NL80211_PLINK_ESTAB)
3b144658
TP
118 continue;
119
120 short_slot = false;
121 if (erp_rates & sta->sta.supp_rates[band])
122 short_slot = true;
123 else
124 break;
125 }
126 rcu_read_unlock();
127
128out:
129 if (sdata->vif.bss_conf.use_short_slot != short_slot) {
130 sdata->vif.bss_conf.use_short_slot = short_slot;
131 changed = BSS_CHANGED_ERP_SLOT;
132 mpl_dbg(sdata, "mesh_plink %pM: ERP short slot time %d\n",
133 sdata->vif.addr, short_slot);
134 }
135 return changed;
136}
137
2c53040f 138/**
cbf9322e 139 * mesh_set_ht_prot_mode - set correct HT protection mode
57aac7c5 140 *
cbf9322e
AN
141 * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
142 * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
143 * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
144 * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
145 * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
146 * HT20 peer is present. Otherwise no-protection mode is selected.
57aac7c5
AN
147 */
148static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
149{
150 struct ieee80211_local *local = sdata->local;
151 struct sta_info *sta;
57aac7c5
AN
152 u16 ht_opmode;
153 bool non_ht_sta = false, ht20_sta = false;
154
0418a445
SW
155 switch (sdata->vif.bss_conf.chandef.width) {
156 case NL80211_CHAN_WIDTH_20_NOHT:
157 case NL80211_CHAN_WIDTH_5:
158 case NL80211_CHAN_WIDTH_10:
57aac7c5 159 return 0;
0418a445
SW
160 default:
161 break;
162 }
57aac7c5
AN
163
164 rcu_read_lock();
165 list_for_each_entry_rcu(sta, &local->sta_list, list) {
cbf9322e 166 if (sdata != sta->sdata ||
433f5bc1 167 sta->mesh->plink_state != NL80211_PLINK_ESTAB)
cbf9322e
AN
168 continue;
169
52ac8c48
TP
170 if (sta->sta.bandwidth > IEEE80211_STA_RX_BW_20)
171 continue;
172
173 if (!sta->sta.ht_cap.ht_supported) {
174 mpl_dbg(sdata, "nonHT sta (%pM) is present\n",
175 sta->sta.addr);
cbf9322e 176 non_ht_sta = true;
cbf9322e 177 break;
57aac7c5 178 }
52ac8c48
TP
179
180 mpl_dbg(sdata, "HT20 sta (%pM) is present\n", sta->sta.addr);
181 ht20_sta = true;
57aac7c5 182 }
57aac7c5
AN
183 rcu_read_unlock();
184
185 if (non_ht_sta)
186 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
466f310d 187 else if (ht20_sta &&
4bf88530 188 sdata->vif.bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
57aac7c5
AN
189 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
190 else
191 ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
192
52ac8c48
TP
193 if (sdata->vif.bss_conf.ht_operation_mode == ht_opmode)
194 return 0;
57aac7c5 195
52ac8c48
TP
196 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
197 sdata->u.mesh.mshcfg.ht_opmode = ht_opmode;
198 mpl_dbg(sdata, "selected new HT protection mode %d\n", ht_opmode);
199 return BSS_CHANGED_HT;
57aac7c5
AN
200}
201
f698d856 202static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
bf7cd94d 203 enum ieee80211_self_protected_actioncode action,
6f101ef0 204 u8 *da, u16 llid, u16 plid, u16 reason)
bf7cd94d 205{
f698d856 206 struct ieee80211_local *local = sdata->local;
3b69a9c5 207 struct sk_buff *skb;
e7570dfb 208 struct ieee80211_tx_info *info;
c3896d2c
LCC
209 struct ieee80211_mgmt *mgmt;
210 bool include_plid = false;
8db09850 211 u16 peering_proto = 0;
3b69a9c5
TP
212 u8 *pos, ie_len = 4;
213 int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
214 sizeof(mgmt->u.action.u.self_prot);
f609a43d 215 int err = -ENOMEM;
3b69a9c5 216
65e8b0cc 217 skb = dev_alloc_skb(local->tx_headroom +
3b69a9c5
TP
218 hdr_len +
219 2 + /* capability info */
220 2 + /* AID */
221 2 + 8 + /* supported rates */
222 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
223 2 + sdata->u.mesh.mesh_id_len +
224 2 + sizeof(struct ieee80211_meshconf_ie) +
176f3608 225 2 + sizeof(struct ieee80211_ht_cap) +
074d46d1 226 2 + sizeof(struct ieee80211_ht_operation) +
3b69a9c5
TP
227 2 + 8 + /* peering IE */
228 sdata->u.mesh.ie_len);
c3896d2c 229 if (!skb)
87d84c45 230 return err;
e7570dfb 231 info = IEEE80211_SKB_CB(skb);
65e8b0cc 232 skb_reserve(skb, local->tx_headroom);
3b69a9c5
TP
233 mgmt = (struct ieee80211_mgmt *) skb_put(skb, hdr_len);
234 memset(mgmt, 0, hdr_len);
e7827a70
HH
235 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
236 IEEE80211_STYPE_ACTION);
c3896d2c 237 memcpy(mgmt->da, da, ETH_ALEN);
47846c9b 238 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
915b5c50 239 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
8db09850
TP
240 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
241 mgmt->u.action.u.self_prot.action_code = action;
c3896d2c 242
8db09850 243 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
55de908a
JB
244 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
245
8db09850
TP
246 /* capability info */
247 pos = skb_put(skb, 2);
248 memset(pos, 0, 2);
54ef656b 249 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
8db09850
TP
250 /* AID */
251 pos = skb_put(skb, 2);
2ea752cd 252 put_unaligned_le16(plid, pos);
c3896d2c 253 }
55de908a
JB
254 if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
255 ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
bf7cd94d
JB
256 mesh_add_rsn_ie(sdata, skb) ||
257 mesh_add_meshid_ie(sdata, skb) ||
258 mesh_add_meshconf_ie(sdata, skb))
f609a43d 259 goto free;
8db09850 260 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
e7570dfb 261 info->flags |= IEEE80211_TX_CTL_NO_ACK;
bf7cd94d 262 if (mesh_add_meshid_ie(sdata, skb))
f609a43d 263 goto free;
c3896d2c
LCC
264 }
265
8db09850 266 /* Add Mesh Peering Management element */
c3896d2c 267 switch (action) {
54ef656b 268 case WLAN_SP_MESH_PEERING_OPEN:
c3896d2c 269 break;
54ef656b 270 case WLAN_SP_MESH_PEERING_CONFIRM:
8db09850 271 ie_len += 2;
c3896d2c
LCC
272 include_plid = true;
273 break;
54ef656b 274 case WLAN_SP_MESH_PEERING_CLOSE:
8db09850
TP
275 if (plid) {
276 ie_len += 2;
c3896d2c
LCC
277 include_plid = true;
278 }
8db09850 279 ie_len += 2; /* reason code */
c3896d2c 280 break;
8db09850 281 default:
f609a43d
TP
282 err = -EINVAL;
283 goto free;
c3896d2c
LCC
284 }
285
8db09850 286 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
f609a43d 287 goto free;
8db09850 288
c3896d2c 289 pos = skb_put(skb, 2 + ie_len);
8db09850 290 *pos++ = WLAN_EID_PEER_MGMT;
c3896d2c 291 *pos++ = ie_len;
8db09850
TP
292 memcpy(pos, &peering_proto, 2);
293 pos += 2;
6f101ef0 294 put_unaligned_le16(llid, pos);
8db09850 295 pos += 2;
c3896d2c 296 if (include_plid) {
6f101ef0 297 put_unaligned_le16(plid, pos);
8db09850 298 pos += 2;
c3896d2c 299 }
54ef656b 300 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
6f101ef0 301 put_unaligned_le16(reason, pos);
8db09850 302 pos += 2;
c3896d2c 303 }
176f3608
TP
304
305 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
bf7cd94d
JB
306 if (mesh_add_ht_cap_ie(sdata, skb) ||
307 mesh_add_ht_oper_ie(sdata, skb))
f609a43d 308 goto free;
176f3608
TP
309 }
310
bf7cd94d 311 if (mesh_add_vendor_ies(sdata, skb))
f609a43d 312 goto free;
c3896d2c 313
62ae67be 314 ieee80211_tx_skb(sdata, skb);
c3896d2c 315 return 0;
f609a43d
TP
316free:
317 kfree_skb(skb);
318 return err;
c3896d2c
LCC
319}
320
fa87a656
BC
321/**
322 * __mesh_plink_deactivate - deactivate mesh peer link
323 *
324 * @sta: mesh peer link to deactivate
325 *
326 * All mesh paths with this peer as next hop will be flushed
327 * Returns beacon changed flag if the beacon content changed.
328 *
329 * Locking: the caller must hold sta->mesh->plink_lock
330 */
331static u32 __mesh_plink_deactivate(struct sta_info *sta)
332{
333 struct ieee80211_sub_if_data *sdata = sta->sdata;
334 u32 changed = 0;
335
336 lockdep_assert_held(&sta->mesh->plink_lock);
337
338 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
339 changed = mesh_plink_dec_estab_count(sdata);
340 sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
341 mesh_path_flush_by_nexthop(sta);
342
343 ieee80211_mps_sta_status_update(sta);
344 changed |= ieee80211_mps_set_sta_local_pm(sta,
345 NL80211_MESH_POWER_UNKNOWN);
346
347 return changed;
348}
349
350/**
351 * mesh_plink_deactivate - deactivate mesh peer link
352 *
353 * @sta: mesh peer link to deactivate
354 *
355 * All mesh paths with this peer as next hop will be flushed
356 */
357u32 mesh_plink_deactivate(struct sta_info *sta)
358{
359 struct ieee80211_sub_if_data *sdata = sta->sdata;
360 u32 changed;
361
362 spin_lock_bh(&sta->mesh->plink_lock);
363 changed = __mesh_plink_deactivate(sta);
364 sta->mesh->reason = WLAN_REASON_MESH_PEER_CANCELED;
365 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
366 sta->sta.addr, sta->mesh->llid, sta->mesh->plid,
367 sta->mesh->reason);
368 spin_unlock_bh(&sta->mesh->plink_lock);
369
370 return changed;
371}
372
296fcba3
TP
373static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
374 struct sta_info *sta,
375 struct ieee802_11_elems *elems, bool insert)
c3896d2c 376{
f698d856 377 struct ieee80211_local *local = sdata->local;
55de908a 378 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
54ab1ffb 379 struct ieee80211_supported_band *sband;
f68d776a 380 u32 rates, basic_rates = 0, changed = 0;
abcff6ef 381 enum ieee80211_sta_rx_bandwidth bw = sta->sta.bandwidth;
c3896d2c 382
f743ff49 383 sband = local->hw.wiphy->bands[band];
2103dec1 384 rates = ieee80211_sta_get_rates(sdata, elems, band, &basic_rates);
d0709a65 385
433f5bc1 386 spin_lock_bh(&sta->mesh->plink_lock);
c3896d2c 387 sta->last_rx = jiffies;
296fcba3
TP
388
389 /* rates and capabilities don't change during peering */
433f5bc1
JB
390 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB &&
391 sta->mesh->processed_beacon)
296fcba3 392 goto out;
433f5bc1 393 sta->mesh->processed_beacon = true;
bae35d92 394
f68d776a
TP
395 if (sta->sta.supp_rates[band] != rates)
396 changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
f743ff49 397 sta->sta.supp_rates[band] = rates;
54ab1ffb 398
52ac8c48
TP
399 if (ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
400 elems->ht_cap_elem, sta))
401 changed |= IEEE80211_RC_BW_CHANGED;
4bf88530 402
abcff6ef
JD
403 if (bw != sta->sta.bandwidth)
404 changed |= IEEE80211_RC_BW_CHANGED;
405
52ac8c48
TP
406 /* HT peer is operating 20MHz-only */
407 if (elems->ht_operation &&
408 !(elems->ht_operation->ht_param &
409 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
410 if (sta->sta.bandwidth != IEEE80211_STA_RX_BW_20)
f68d776a 411 changed |= IEEE80211_RC_BW_CHANGED;
52ac8c48 412 sta->sta.bandwidth = IEEE80211_STA_RX_BW_20;
57aac7c5 413 }
c7d25828 414
59cf1d65
HS
415 if (insert)
416 rate_control_rate_init(sta);
f68d776a
TP
417 else
418 rate_control_rate_update(local, sband, sta, changed);
296fcba3 419out:
433f5bc1 420 spin_unlock_bh(&sta->mesh->plink_lock);
296fcba3
TP
421}
422
423static struct sta_info *
424__mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
425{
426 struct sta_info *sta;
54ab1ffb 427
296fcba3 428 if (sdata->local->num_sta >= MESH_MAX_PLINKS)
e87278e7
TP
429 return NULL;
430
296fcba3
TP
431 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
432 if (!sta)
433 return NULL;
434
433f5bc1 435 sta->mesh->plink_state = NL80211_PLINK_LISTEN;
a74a8c84 436 sta->sta.wme = true;
296fcba3
TP
437
438 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
439 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
440 sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
441
296fcba3
TP
442 return sta;
443}
444
445static struct sta_info *
446mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
447 struct ieee802_11_elems *elems)
448{
449 struct sta_info *sta = NULL;
450
a6dad6a2
TP
451 /* Userspace handles station allocation */
452 if (sdata->u.mesh.user_mpm ||
453 sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
296fcba3
TP
454 cfg80211_notify_new_peer_candidate(sdata->dev, addr,
455 elems->ie_start,
456 elems->total_len,
457 GFP_KERNEL);
458 else
459 sta = __mesh_sta_info_alloc(sdata, addr);
460
54ab1ffb
TP
461 return sta;
462}
463
296fcba3
TP
464/*
465 * mesh_sta_info_get - return mesh sta info entry for @addr.
466 *
467 * @sdata: local meshif
468 * @addr: peer's address
469 * @elems: IEs from beacon or mesh peering frame.
470 *
471 * Return existing or newly allocated sta_info under RCU read lock.
472 * (re)initialize with given IEs.
473 */
474static struct sta_info *
475mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
476 u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU)
477{
478 struct sta_info *sta = NULL;
479
480 rcu_read_lock();
481 sta = sta_info_get(sdata, addr);
482 if (sta) {
483 mesh_sta_info_init(sdata, sta, elems, false);
484 } else {
485 rcu_read_unlock();
486 /* can't run atomic */
487 sta = mesh_sta_info_alloc(sdata, addr, elems);
488 if (!sta) {
489 rcu_read_lock();
490 return NULL;
491 }
492
3b4797bc
TP
493 mesh_sta_info_init(sdata, sta, elems, true);
494
296fcba3
TP
495 if (sta_info_insert_rcu(sta))
496 return NULL;
497 }
498
499 return sta;
500}
501
502/*
503 * mesh_neighbour_update - update or initialize new mesh neighbor.
504 *
505 * @sdata: local meshif
506 * @addr: peer's address
507 * @elems: IEs from beacon or mesh peering frame
508 *
509 * Initiates peering if appropriate.
510 */
f743ff49
TP
511void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
512 u8 *hw_addr,
54ab1ffb
TP
513 struct ieee802_11_elems *elems)
514{
515 struct sta_info *sta;
39886b61 516 u32 changed = 0;
54ab1ffb 517
296fcba3 518 sta = mesh_sta_info_get(sdata, hw_addr, elems);
54ab1ffb
TP
519 if (!sta)
520 goto out;
521
1570ca59 522 if (mesh_peer_accepts_plinks(elems) &&
433f5bc1 523 sta->mesh->plink_state == NL80211_PLINK_LISTEN &&
54ab1ffb
TP
524 sdata->u.mesh.accepting_plinks &&
525 sdata->u.mesh.mshcfg.auto_open_plinks &&
36c9bb29 526 rssi_threshold_check(sdata, sta))
39886b61 527 changed = mesh_plink_open(sta);
c3896d2c 528
3f52b7e3 529 ieee80211_mps_frame_release(sta, elems);
54ab1ffb 530out:
d0709a65 531 rcu_read_unlock();
2b5e1967 532 ieee80211_mbss_info_change_notify(sdata, changed);
c3896d2c
LCC
533}
534
535static void mesh_plink_timer(unsigned long data)
536{
537 struct sta_info *sta;
6f101ef0 538 u16 reason = 0;
c3896d2c 539 struct ieee80211_sub_if_data *sdata;
453e66f2 540 struct mesh_config *mshcfg;
4efec451 541 enum ieee80211_self_protected_actioncode action = 0;
c3896d2c 542
d0709a65
JB
543 /*
544 * This STA is valid because sta_info_destroy() will
545 * del_timer_sync() this timer after having made sure
546 * it cannot be readded (by deleting the plink.)
547 */
c3896d2c
LCC
548 sta = (struct sta_info *) data;
549
690205f1 550 if (sta->sdata->local->quiescing)
5bb644a0 551 return;
5bb644a0 552
433f5bc1 553 spin_lock_bh(&sta->mesh->plink_lock);
2b470c39
BC
554
555 /* If a timer fires just before a state transition on another CPU,
556 * we may have already extended the timeout and changed state by the
557 * time we've acquired the lock and arrived here. In that case,
558 * skip this timer and wait for the new one.
559 */
433f5bc1 560 if (time_before(jiffies, sta->mesh->plink_timer.expires)) {
2b470c39
BC
561 mpl_dbg(sta->sdata,
562 "Ignoring timer for %pM in state %s (timer adjusted)",
433f5bc1
JB
563 sta->sta.addr, mplstates[sta->mesh->plink_state]);
564 spin_unlock_bh(&sta->mesh->plink_lock);
c3896d2c
LCC
565 return;
566 }
2b470c39
BC
567
568 /* del_timer() and handler may race when entering these states */
433f5bc1
JB
569 if (sta->mesh->plink_state == NL80211_PLINK_LISTEN ||
570 sta->mesh->plink_state == NL80211_PLINK_ESTAB) {
2b470c39
BC
571 mpl_dbg(sta->sdata,
572 "Ignoring timer for %pM in state %s (timer deleted)",
433f5bc1
JB
573 sta->sta.addr, mplstates[sta->mesh->plink_state]);
574 spin_unlock_bh(&sta->mesh->plink_lock);
2b470c39
BC
575 return;
576 }
577
bdcbd8e0 578 mpl_dbg(sta->sdata,
3088f7d2 579 "Mesh plink timer for %pM fired on state %s\n",
433f5bc1 580 sta->sta.addr, mplstates[sta->mesh->plink_state]);
d0709a65 581 sdata = sta->sdata;
453e66f2 582 mshcfg = &sdata->u.mesh.mshcfg;
c3896d2c 583
433f5bc1 584 switch (sta->mesh->plink_state) {
57cf8043
JC
585 case NL80211_PLINK_OPN_RCVD:
586 case NL80211_PLINK_OPN_SNT:
c3896d2c 587 /* retry timer */
433f5bc1 588 if (sta->mesh->plink_retries < mshcfg->dot11MeshMaxRetries) {
c3896d2c 589 u32 rand;
bdcbd8e0
JB
590 mpl_dbg(sta->sdata,
591 "Mesh plink for %pM (retry, timeout): %d %d\n",
433f5bc1
JB
592 sta->sta.addr, sta->mesh->plink_retries,
593 sta->mesh->plink_timeout);
c3896d2c 594 get_random_bytes(&rand, sizeof(u32));
433f5bc1
JB
595 sta->mesh->plink_timeout = sta->mesh->plink_timeout +
596 rand % sta->mesh->plink_timeout;
597 ++sta->mesh->plink_retries;
598 mod_plink_timer(sta, sta->mesh->plink_timeout);
4efec451 599 action = WLAN_SP_MESH_PEERING_OPEN;
c3896d2c
LCC
600 break;
601 }
6f101ef0 602 reason = WLAN_REASON_MESH_MAX_RETRIES;
c3896d2c 603 /* fall through on else */
57cf8043 604 case NL80211_PLINK_CNF_RCVD:
c3896d2c
LCC
605 /* confirm timer */
606 if (!reason)
6f101ef0 607 reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
433f5bc1 608 sta->mesh->plink_state = NL80211_PLINK_HOLDING;
453e66f2 609 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
4efec451 610 action = WLAN_SP_MESH_PEERING_CLOSE;
c3896d2c 611 break;
57cf8043 612 case NL80211_PLINK_HOLDING:
c3896d2c 613 /* holding timer */
433f5bc1 614 del_timer(&sta->mesh->plink_timer);
c3896d2c 615 mesh_plink_fsm_restart(sta);
c3896d2c
LCC
616 break;
617 default:
c3896d2c
LCC
618 break;
619 }
433f5bc1 620 spin_unlock_bh(&sta->mesh->plink_lock);
4efec451
TP
621 if (action)
622 mesh_plink_frame_tx(sdata, action, sta->sta.addr,
433f5bc1 623 sta->mesh->llid, sta->mesh->plid, reason);
c3896d2c
LCC
624}
625
0df2f6c1 626static inline void mesh_plink_timer_set(struct sta_info *sta, u32 timeout)
c3896d2c 627{
433f5bc1
JB
628 sta->mesh->plink_timer.expires = jiffies + msecs_to_jiffies(timeout);
629 sta->mesh->plink_timer.data = (unsigned long) sta;
630 sta->mesh->plink_timer.function = mesh_plink_timer;
631 sta->mesh->plink_timeout = timeout;
632 add_timer(&sta->mesh->plink_timer);
c3896d2c
LCC
633}
634
204d1304 635static bool llid_in_use(struct ieee80211_sub_if_data *sdata,
6f101ef0 636 u16 llid)
204d1304
TP
637{
638 struct ieee80211_local *local = sdata->local;
639 bool in_use = false;
640 struct sta_info *sta;
641
642 rcu_read_lock();
643 list_for_each_entry_rcu(sta, &local->sta_list, list) {
433f5bc1 644 if (!memcmp(&sta->mesh->llid, &llid, sizeof(llid))) {
204d1304
TP
645 in_use = true;
646 break;
647 }
648 }
649 rcu_read_unlock();
650
651 return in_use;
652}
653
6f101ef0 654static u16 mesh_get_new_llid(struct ieee80211_sub_if_data *sdata)
204d1304
TP
655{
656 u16 llid;
657
658 do {
659 get_random_bytes(&llid, sizeof(llid));
660 /* for mesh PS we still only have the AID range for TIM bits */
661 llid = (llid % IEEE80211_MAX_AID) + 1;
6f101ef0 662 } while (llid_in_use(sdata, llid));
204d1304 663
6f101ef0 664 return llid;
204d1304
TP
665}
666
39886b61 667u32 mesh_plink_open(struct sta_info *sta)
c3896d2c 668{
d0709a65 669 struct ieee80211_sub_if_data *sdata = sta->sdata;
39886b61 670 u32 changed;
c3896d2c 671
c2c98fde 672 if (!test_sta_flag(sta, WLAN_STA_AUTH))
39886b61 673 return 0;
53e80511 674
433f5bc1
JB
675 spin_lock_bh(&sta->mesh->plink_lock);
676 sta->mesh->llid = mesh_get_new_llid(sdata);
677 if (sta->mesh->plink_state != NL80211_PLINK_LISTEN &&
678 sta->mesh->plink_state != NL80211_PLINK_BLOCKED) {
679 spin_unlock_bh(&sta->mesh->plink_lock);
39886b61 680 return 0;
c3896d2c 681 }
433f5bc1 682 sta->mesh->plink_state = NL80211_PLINK_OPN_SNT;
453e66f2 683 mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
433f5bc1 684 spin_unlock_bh(&sta->mesh->plink_lock);
bdcbd8e0
JB
685 mpl_dbg(sdata,
686 "Mesh plink: starting establishment with %pM\n",
0c68ae26 687 sta->sta.addr);
c3896d2c 688
3f52b7e3 689 /* set the non-peer mode to active during peering */
39886b61 690 changed = ieee80211_mps_local_status_update(sdata);
3f52b7e3 691
39886b61 692 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
433f5bc1 693 sta->sta.addr, sta->mesh->llid, 0, 0);
39886b61 694 return changed;
c3896d2c
LCC
695}
696
39886b61 697u32 mesh_plink_block(struct sta_info *sta)
c3896d2c 698{
df323818 699 u32 changed;
c9370197 700
433f5bc1 701 spin_lock_bh(&sta->mesh->plink_lock);
df323818 702 changed = __mesh_plink_deactivate(sta);
433f5bc1
JB
703 sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
704 spin_unlock_bh(&sta->mesh->plink_lock);
c9370197 705
39886b61 706 return changed;
c3896d2c
LCC
707}
708
e76d67f0
BC
709static void mesh_plink_close(struct ieee80211_sub_if_data *sdata,
710 struct sta_info *sta,
711 enum plink_event event)
712{
713 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
6f101ef0
CYY
714 u16 reason = (event == CLS_ACPT) ?
715 WLAN_REASON_MESH_CLOSE : WLAN_REASON_MESH_CONFIG;
e76d67f0 716
433f5bc1
JB
717 sta->mesh->reason = reason;
718 sta->mesh->plink_state = NL80211_PLINK_HOLDING;
272a9e26 719 mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
e76d67f0
BC
720}
721
722static u32 mesh_plink_establish(struct ieee80211_sub_if_data *sdata,
723 struct sta_info *sta)
724{
725 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
726 u32 changed = 0;
727
433f5bc1
JB
728 del_timer(&sta->mesh->plink_timer);
729 sta->mesh->plink_state = NL80211_PLINK_ESTAB;
e76d67f0
BC
730 changed |= mesh_plink_inc_estab_count(sdata);
731 changed |= mesh_set_ht_prot_mode(sdata);
732 changed |= mesh_set_short_slot_time(sdata);
733 mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n", sta->sta.addr);
734 ieee80211_mps_sta_status_update(sta);
735 changed |= ieee80211_mps_set_sta_local_pm(sta, mshcfg->power_mode);
736 return changed;
737}
738
c7e67811
TP
739/**
740 * mesh_plink_fsm - step @sta MPM based on @event
741 *
742 * @sdata: interface
743 * @sta: mesh neighbor
744 * @event: peering event
745 *
746 * Return: changed MBSS flags
747 */
748static u32 mesh_plink_fsm(struct ieee80211_sub_if_data *sdata,
749 struct sta_info *sta, enum plink_event event)
750{
751 struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
752 enum ieee80211_self_protected_actioncode action = 0;
753 u32 changed = 0;
754
755 mpl_dbg(sdata, "peer %pM in state %s got event %s\n", sta->sta.addr,
433f5bc1 756 mplstates[sta->mesh->plink_state], mplevents[event]);
c7e67811 757
433f5bc1
JB
758 spin_lock_bh(&sta->mesh->plink_lock);
759 switch (sta->mesh->plink_state) {
c7e67811
TP
760 case NL80211_PLINK_LISTEN:
761 switch (event) {
762 case CLS_ACPT:
763 mesh_plink_fsm_restart(sta);
764 break;
765 case OPN_ACPT:
433f5bc1
JB
766 sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
767 sta->mesh->llid = mesh_get_new_llid(sdata);
c7e67811
TP
768 mesh_plink_timer_set(sta,
769 mshcfg->dot11MeshRetryTimeout);
770
771 /* set the non-peer mode to active during peering */
772 changed |= ieee80211_mps_local_status_update(sdata);
773 action = WLAN_SP_MESH_PEERING_OPEN;
774 break;
775 default:
776 break;
777 }
778 break;
779 case NL80211_PLINK_OPN_SNT:
780 switch (event) {
781 case OPN_RJCT:
782 case CNF_RJCT:
783 case CLS_ACPT:
784 mesh_plink_close(sdata, sta, event);
785 action = WLAN_SP_MESH_PEERING_CLOSE;
786 break;
787 case OPN_ACPT:
788 /* retry timer is left untouched */
433f5bc1 789 sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
c7e67811
TP
790 action = WLAN_SP_MESH_PEERING_CONFIRM;
791 break;
792 case CNF_ACPT:
433f5bc1 793 sta->mesh->plink_state = NL80211_PLINK_CNF_RCVD;
2b470c39 794 mod_plink_timer(sta, mshcfg->dot11MeshConfirmTimeout);
c7e67811
TP
795 break;
796 default:
797 break;
798 }
799 break;
800 case NL80211_PLINK_OPN_RCVD:
801 switch (event) {
802 case OPN_RJCT:
803 case CNF_RJCT:
804 case CLS_ACPT:
805 mesh_plink_close(sdata, sta, event);
806 action = WLAN_SP_MESH_PEERING_CLOSE;
807 break;
808 case OPN_ACPT:
809 action = WLAN_SP_MESH_PEERING_CONFIRM;
810 break;
811 case CNF_ACPT:
812 changed |= mesh_plink_establish(sdata, sta);
813 break;
814 default:
815 break;
816 }
817 break;
818 case NL80211_PLINK_CNF_RCVD:
819 switch (event) {
820 case OPN_RJCT:
821 case CNF_RJCT:
822 case CLS_ACPT:
823 mesh_plink_close(sdata, sta, event);
824 action = WLAN_SP_MESH_PEERING_CLOSE;
825 break;
826 case OPN_ACPT:
827 changed |= mesh_plink_establish(sdata, sta);
828 action = WLAN_SP_MESH_PEERING_CONFIRM;
829 break;
830 default:
831 break;
832 }
833 break;
834 case NL80211_PLINK_ESTAB:
835 switch (event) {
836 case CLS_ACPT:
837 changed |= __mesh_plink_deactivate(sta);
838 changed |= mesh_set_ht_prot_mode(sdata);
839 changed |= mesh_set_short_slot_time(sdata);
840 mesh_plink_close(sdata, sta, event);
841 action = WLAN_SP_MESH_PEERING_CLOSE;
842 break;
843 case OPN_ACPT:
844 action = WLAN_SP_MESH_PEERING_CONFIRM;
845 break;
846 default:
847 break;
848 }
849 break;
850 case NL80211_PLINK_HOLDING:
851 switch (event) {
852 case CLS_ACPT:
433f5bc1 853 del_timer(&sta->mesh->plink_timer);
c7e67811
TP
854 mesh_plink_fsm_restart(sta);
855 break;
856 case OPN_ACPT:
857 case CNF_ACPT:
858 case OPN_RJCT:
859 case CNF_RJCT:
860 action = WLAN_SP_MESH_PEERING_CLOSE;
861 break;
862 default:
863 break;
864 }
865 break;
866 default:
867 /* should not get here, PLINK_BLOCKED is dealt with at the
868 * beginning of the function
869 */
870 break;
871 }
433f5bc1 872 spin_unlock_bh(&sta->mesh->plink_lock);
c7e67811
TP
873 if (action) {
874 mesh_plink_frame_tx(sdata, action, sta->sta.addr,
433f5bc1
JB
875 sta->mesh->llid, sta->mesh->plid,
876 sta->mesh->reason);
c7e67811
TP
877
878 /* also send confirm in open case */
879 if (action == WLAN_SP_MESH_PEERING_OPEN) {
880 mesh_plink_frame_tx(sdata,
881 WLAN_SP_MESH_PEERING_CONFIRM,
433f5bc1
JB
882 sta->sta.addr, sta->mesh->llid,
883 sta->mesh->plid, 0);
c7e67811
TP
884 }
885 }
886
887 return changed;
888}
889
c99a89ed
TP
890/*
891 * mesh_plink_get_event - get correct MPM event
892 *
893 * @sdata: interface
894 * @sta: peer, leave NULL if processing a frame from a new suitable peer
895 * @elems: peering management IEs
896 * @ftype: frame type
897 * @llid: peer's peer link ID
898 * @plid: peer's local link ID
899 *
900 * Return: new peering event for @sta, but PLINK_UNDEFINED should be treated as
901 * an error.
902 */
903static enum plink_event
904mesh_plink_get_event(struct ieee80211_sub_if_data *sdata,
905 struct sta_info *sta,
906 struct ieee802_11_elems *elems,
907 enum ieee80211_self_protected_actioncode ftype,
6f101ef0 908 u16 llid, u16 plid)
c99a89ed
TP
909{
910 enum plink_event event = PLINK_UNDEFINED;
911 u8 ie_len = elems->peering_len;
912 bool matches_local;
913
914 matches_local = (ftype == WLAN_SP_MESH_PEERING_CLOSE ||
915 mesh_matches_local(sdata, elems));
916
917 /* deny open request from non-matching peer */
918 if (!matches_local && !sta) {
919 event = OPN_RJCT;
920 goto out;
921 }
922
923 if (!sta) {
924 if (ftype != WLAN_SP_MESH_PEERING_OPEN) {
925 mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
926 goto out;
927 }
928 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
929 if (!mesh_plink_free_count(sdata)) {
930 mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
931 goto out;
932 }
933 } else {
934 if (!test_sta_flag(sta, WLAN_STA_AUTH)) {
935 mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
936 goto out;
937 }
433f5bc1 938 if (sta->mesh->plink_state == NL80211_PLINK_BLOCKED)
c99a89ed
TP
939 goto out;
940 }
941
942 /* new matching peer */
943 if (!sta) {
944 event = OPN_ACPT;
945 goto out;
946 }
947
948 switch (ftype) {
949 case WLAN_SP_MESH_PEERING_OPEN:
950 if (!matches_local)
951 event = OPN_RJCT;
952 if (!mesh_plink_free_count(sdata) ||
433f5bc1 953 (sta->mesh->plid && sta->mesh->plid != plid))
c99a89ed
TP
954 event = OPN_IGNR;
955 else
956 event = OPN_ACPT;
957 break;
958 case WLAN_SP_MESH_PEERING_CONFIRM:
959 if (!matches_local)
960 event = CNF_RJCT;
961 if (!mesh_plink_free_count(sdata) ||
433f5bc1
JB
962 sta->mesh->llid != llid ||
963 (sta->mesh->plid && sta->mesh->plid != plid))
c99a89ed
TP
964 event = CNF_IGNR;
965 else
966 event = CNF_ACPT;
967 break;
968 case WLAN_SP_MESH_PEERING_CLOSE:
433f5bc1 969 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
c99a89ed
TP
970 /* Do not check for llid or plid. This does not
971 * follow the standard but since multiple plinks
972 * per sta are not supported, it is necessary in
973 * order to avoid a livelock when MP A sees an
974 * establish peer link to MP B but MP B does not
975 * see it. This can be caused by a timeout in
976 * B's peer link establishment or B beign
977 * restarted.
978 */
979 event = CLS_ACPT;
433f5bc1 980 else if (sta->mesh->plid != plid)
c99a89ed 981 event = CLS_IGNR;
433f5bc1 982 else if (ie_len == 8 && sta->mesh->llid != llid)
c99a89ed
TP
983 event = CLS_IGNR;
984 else
985 event = CLS_ACPT;
986 break;
987 default:
988 mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
989 break;
990 }
991
992out:
993 return event;
994}
995
05a23ae9
TP
996static void
997mesh_process_plink_frame(struct ieee80211_sub_if_data *sdata,
998 struct ieee80211_mgmt *mgmt,
999 struct ieee802_11_elems *elems)
c3896d2c 1000{
05a23ae9 1001
c3896d2c
LCC
1002 struct sta_info *sta;
1003 enum plink_event event;
54ef656b 1004 enum ieee80211_self_protected_actioncode ftype;
57aac7c5 1005 u32 changed = 0;
c99a89ed 1006 u8 ie_len = elems->peering_len;
6f101ef0 1007 u16 plid, llid = 0;
c3896d2c 1008
05a23ae9 1009 if (!elems->peering) {
bdcbd8e0
JB
1010 mpl_dbg(sdata,
1011 "Mesh plink: missing necessary peer link ie\n");
c3896d2c
LCC
1012 return;
1013 }
bf7cd94d 1014
05a23ae9 1015 if (elems->rsn_len &&
bf7cd94d 1016 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
bdcbd8e0
JB
1017 mpl_dbg(sdata,
1018 "Mesh plink: can't establish link with secure peer\n");
5cff5e01
JC
1019 return;
1020 }
c3896d2c 1021
8db09850 1022 ftype = mgmt->u.action.u.self_prot.action_code;
8db09850
TP
1023 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
1024 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
1025 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
1026 && ie_len != 8)) {
bdcbd8e0
JB
1027 mpl_dbg(sdata,
1028 "Mesh plink: incorrect plink ie length %d %d\n",
1029 ftype, ie_len);
c3896d2c
LCC
1030 return;
1031 }
1032
54ef656b 1033 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
05a23ae9 1034 (!elems->mesh_id || !elems->mesh_config)) {
bdcbd8e0 1035 mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
c3896d2c
LCC
1036 return;
1037 }
1038 /* Note the lines below are correct, the llid in the frame is the plid
1039 * from the point of view of this host.
1040 */
f8134fed 1041 plid = get_unaligned_le16(PLINK_GET_LLID(elems->peering));
54ef656b 1042 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
f8134fed
BC
1043 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
1044 llid = get_unaligned_le16(PLINK_GET_PLID(elems->peering));
c3896d2c 1045
296fcba3 1046 /* WARNING: Only for sta pointer, is dropped & re-acquired */
d0709a65
JB
1047 rcu_read_lock();
1048
abe60632 1049 sta = sta_info_get(sdata, mgmt->sa);
32cb05bf 1050
55335137 1051 if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
36c9bb29 1052 !rssi_threshold_check(sdata, sta)) {
bdcbd8e0 1053 mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
3d4f9699 1054 mgmt->sa);
fc10302e 1055 goto unlock_rcu;
55335137
AN
1056 }
1057
c3896d2c 1058 /* Now we will figure out the appropriate event... */
c99a89ed 1059 event = mesh_plink_get_event(sdata, sta, elems, ftype, llid, plid);
54ab1ffb
TP
1060
1061 if (event == OPN_ACPT) {
296fcba3 1062 rcu_read_unlock();
54ab1ffb 1063 /* allocate sta entry if necessary and update info */
05a23ae9 1064 sta = mesh_sta_info_get(sdata, mgmt->sa, elems);
54ab1ffb 1065 if (!sta) {
bdcbd8e0 1066 mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
fc10302e 1067 goto unlock_rcu;
54ab1ffb 1068 }
433f5bc1 1069 sta->mesh->plid = plid;
c99a89ed
TP
1070 } else if (!sta && event == OPN_RJCT) {
1071 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
1072 mgmt->sa, 0, plid,
6f101ef0 1073 WLAN_REASON_MESH_CONFIG);
c99a89ed
TP
1074 goto unlock_rcu;
1075 } else if (!sta || event == PLINK_UNDEFINED) {
1076 /* something went wrong */
1077 goto unlock_rcu;
c3896d2c
LCC
1078 }
1079
6c6fa496 1080 /* 802.11-2012 13.3.7.2 - update plid on CNF if not set */
433f5bc1
JB
1081 if (!sta->mesh->plid && event == CNF_ACPT)
1082 sta->mesh->plid = plid;
6c6fa496 1083
c7e67811 1084 changed |= mesh_plink_fsm(sdata, sta, event);
d0709a65 1085
fc10302e 1086unlock_rcu:
d0709a65 1087 rcu_read_unlock();
57aac7c5 1088
ecccd072 1089 if (changed)
2b5e1967 1090 ieee80211_mbss_info_change_notify(sdata, changed);
c3896d2c 1091}
05a23ae9
TP
1092
1093void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
1094 struct ieee80211_mgmt *mgmt, size_t len,
1095 struct ieee80211_rx_status *rx_status)
1096{
1097 struct ieee802_11_elems elems;
1098 size_t baselen;
1099 u8 *baseaddr;
1100
1101 /* need action_code, aux */
1102 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
1103 return;
1104
1105 if (sdata->u.mesh.user_mpm)
1106 /* userspace must register for these */
1107 return;
1108
1109 if (is_multicast_ether_addr(mgmt->da)) {
1110 mpl_dbg(sdata,
1111 "Mesh plink: ignore frame from multicast address\n");
1112 return;
1113 }
1114
1115 baseaddr = mgmt->u.action.u.self_prot.variable;
1116 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
1117 if (mgmt->u.action.u.self_prot.action_code ==
1118 WLAN_SP_MESH_PEERING_CONFIRM) {
1119 baseaddr += 4;
1120 baselen += 4;
b3e7de87
BC
1121
1122 if (baselen > len)
1123 return;
05a23ae9
TP
1124 }
1125 ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
1126 mesh_process_plink_frame(sdata, mgmt, &elems);
1127}
This page took 0.561064 seconds and 5 git commands to generate.