2 * Copyright (c) 2008, 2009 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
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.
10 #include <linux/kernel.h>
11 #include <linux/random.h>
12 #include "ieee80211_i.h"
16 #define PLINK_GET_LLID(p) (p + 2)
17 #define PLINK_GET_PLID(p) (p + 4)
19 #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
20 jiffies + HZ * t / 1000))
22 /* We only need a valid sta if user configured a minimum rssi_threshold. */
23 #define rssi_threshold_check(sta, sdata) \
24 (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\
25 (sta && (s8) -ewma_read(&sta->avg_signal) > \
26 sdata->u.mesh.mshcfg.rssi_threshold))
40 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data
*sdata
,
41 enum ieee80211_self_protected_actioncode action
,
42 u8
*da
, __le16 llid
, __le16 plid
, __le16 reason
);
45 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
47 * @sta: mesh peer link to restart
49 * Locking: this function must be called holding sta->lock
51 static inline void mesh_plink_fsm_restart(struct sta_info
*sta
)
53 sta
->plink_state
= NL80211_PLINK_LISTEN
;
54 sta
->llid
= sta
->plid
= sta
->reason
= 0;
55 sta
->plink_retries
= 0;
59 * mesh_set_ht_prot_mode - set correct HT protection mode
61 * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
62 * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
63 * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
64 * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
65 * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
66 * HT20 peer is present. Otherwise no-protection mode is selected.
68 static u32
mesh_set_ht_prot_mode(struct ieee80211_sub_if_data
*sdata
)
70 struct ieee80211_local
*local
= sdata
->local
;
74 bool non_ht_sta
= false, ht20_sta
= false;
76 if (sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
80 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
81 if (sdata
!= sta
->sdata
||
82 sta
->plink_state
!= NL80211_PLINK_ESTAB
)
85 switch (sta
->ch_width
) {
86 case NL80211_CHAN_WIDTH_20_NOHT
:
88 "mesh_plink %pM: nonHT sta (%pM) is present\n",
89 sdata
->vif
.addr
, sta
->sta
.addr
);
92 case NL80211_CHAN_WIDTH_20
:
94 "mesh_plink %pM: HT20 sta (%pM) is present\n",
95 sdata
->vif
.addr
, sta
->sta
.addr
);
105 ht_opmode
= IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
;
107 sdata
->vif
.bss_conf
.chandef
.width
> NL80211_CHAN_WIDTH_20
)
108 ht_opmode
= IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
;
110 ht_opmode
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
112 if (sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
) {
113 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
114 sdata
->u
.mesh
.mshcfg
.ht_opmode
= ht_opmode
;
115 changed
= BSS_CHANGED_HT
;
117 "mesh_plink %pM: protection mode changed to %d\n",
118 sdata
->vif
.addr
, ht_opmode
);
125 * __mesh_plink_deactivate - deactivate mesh peer link
127 * @sta: mesh peer link to deactivate
129 * All mesh paths with this peer as next hop will be flushed
130 * Returns beacon changed flag if the beacon content changed.
132 * Locking: the caller must hold sta->lock
134 static u32
__mesh_plink_deactivate(struct sta_info
*sta
)
136 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
139 if (sta
->plink_state
== NL80211_PLINK_ESTAB
)
140 changed
= mesh_plink_dec_estab_count(sdata
);
141 sta
->plink_state
= NL80211_PLINK_BLOCKED
;
142 mesh_path_flush_by_nexthop(sta
);
148 * mesh_plink_deactivate - deactivate mesh peer link
150 * @sta: mesh peer link to deactivate
152 * All mesh paths with this peer as next hop will be flushed
154 void mesh_plink_deactivate(struct sta_info
*sta
)
156 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
159 spin_lock_bh(&sta
->lock
);
160 changed
= __mesh_plink_deactivate(sta
);
161 sta
->reason
= cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED
);
162 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
163 sta
->sta
.addr
, sta
->llid
, sta
->plid
,
165 spin_unlock_bh(&sta
->lock
);
167 ieee80211_bss_info_change_notify(sdata
, changed
);
170 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data
*sdata
,
171 enum ieee80211_self_protected_actioncode action
,
172 u8
*da
, __le16 llid
, __le16 plid
, __le16 reason
) {
173 struct ieee80211_local
*local
= sdata
->local
;
175 struct ieee80211_tx_info
*info
;
176 struct ieee80211_mgmt
*mgmt
;
177 bool include_plid
= false;
178 u16 peering_proto
= 0;
180 int hdr_len
= offsetof(struct ieee80211_mgmt
, u
.action
.u
.self_prot
) +
181 sizeof(mgmt
->u
.action
.u
.self_prot
);
184 skb
= dev_alloc_skb(local
->tx_headroom
+
186 2 + /* capability info */
188 2 + 8 + /* supported rates */
189 2 + (IEEE80211_MAX_SUPP_RATES
- 8) +
190 2 + sdata
->u
.mesh
.mesh_id_len
+
191 2 + sizeof(struct ieee80211_meshconf_ie
) +
192 2 + sizeof(struct ieee80211_ht_cap
) +
193 2 + sizeof(struct ieee80211_ht_operation
) +
194 2 + 8 + /* peering IE */
195 sdata
->u
.mesh
.ie_len
);
198 info
= IEEE80211_SKB_CB(skb
);
199 skb_reserve(skb
, local
->tx_headroom
);
200 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, hdr_len
);
201 memset(mgmt
, 0, hdr_len
);
202 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
203 IEEE80211_STYPE_ACTION
);
204 memcpy(mgmt
->da
, da
, ETH_ALEN
);
205 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
206 memcpy(mgmt
->bssid
, sdata
->vif
.addr
, ETH_ALEN
);
207 mgmt
->u
.action
.category
= WLAN_CATEGORY_SELF_PROTECTED
;
208 mgmt
->u
.action
.u
.self_prot
.action_code
= action
;
210 if (action
!= WLAN_SP_MESH_PEERING_CLOSE
) {
211 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
213 /* capability info */
214 pos
= skb_put(skb
, 2);
216 if (action
== WLAN_SP_MESH_PEERING_CONFIRM
) {
218 pos
= skb_put(skb
, 2);
219 memcpy(pos
+ 2, &plid
, 2);
221 if (ieee80211_add_srates_ie(sdata
, skb
, true, band
) ||
222 ieee80211_add_ext_srates_ie(sdata
, skb
, true, band
) ||
223 mesh_add_rsn_ie(skb
, sdata
) ||
224 mesh_add_meshid_ie(skb
, sdata
) ||
225 mesh_add_meshconf_ie(skb
, sdata
))
227 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
228 info
->flags
|= IEEE80211_TX_CTL_NO_ACK
;
229 if (mesh_add_meshid_ie(skb
, sdata
))
233 /* Add Mesh Peering Management element */
235 case WLAN_SP_MESH_PEERING_OPEN
:
237 case WLAN_SP_MESH_PEERING_CONFIRM
:
241 case WLAN_SP_MESH_PEERING_CLOSE
:
246 ie_len
+= 2; /* reason code */
253 if (WARN_ON(skb_tailroom(skb
) < 2 + ie_len
))
256 pos
= skb_put(skb
, 2 + ie_len
);
257 *pos
++ = WLAN_EID_PEER_MGMT
;
259 memcpy(pos
, &peering_proto
, 2);
261 memcpy(pos
, &llid
, 2);
264 memcpy(pos
, &plid
, 2);
267 if (action
== WLAN_SP_MESH_PEERING_CLOSE
) {
268 memcpy(pos
, &reason
, 2);
272 if (action
!= WLAN_SP_MESH_PEERING_CLOSE
) {
273 if (mesh_add_ht_cap_ie(skb
, sdata
) ||
274 mesh_add_ht_oper_ie(skb
, sdata
))
278 if (mesh_add_vendor_ies(skb
, sdata
))
281 ieee80211_tx_skb(sdata
, skb
);
288 static void mesh_sta_info_init(struct ieee80211_sub_if_data
*sdata
,
289 struct sta_info
*sta
,
290 struct ieee802_11_elems
*elems
, bool insert
)
292 struct ieee80211_local
*local
= sdata
->local
;
293 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
294 struct ieee80211_supported_band
*sband
;
295 u32 rates
, basic_rates
= 0, changed
= 0;
297 sband
= local
->hw
.wiphy
->bands
[band
];
298 rates
= ieee80211_sta_get_rates(local
, elems
, band
, &basic_rates
);
300 spin_lock_bh(&sta
->lock
);
301 sta
->last_rx
= jiffies
;
303 /* rates and capabilities don't change during peering */
304 if (sta
->plink_state
== NL80211_PLINK_ESTAB
)
307 if (sta
->sta
.supp_rates
[band
] != rates
)
308 changed
|= IEEE80211_RC_SUPP_RATES_CHANGED
;
309 sta
->sta
.supp_rates
[band
] = rates
;
310 if (elems
->ht_cap_elem
&&
311 sdata
->vif
.bss_conf
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
)
312 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
316 memset(&sta
->sta
.ht_cap
, 0, sizeof(sta
->sta
.ht_cap
));
318 if (elems
->ht_operation
) {
319 struct cfg80211_chan_def chandef
;
321 if (!(elems
->ht_operation
->ht_param
&
322 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY
))
323 sta
->sta
.ht_cap
.cap
&=
324 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
325 ieee80211_ht_oper_to_chandef(sdata
->vif
.bss_conf
.chandef
.chan
,
326 elems
->ht_operation
, &chandef
);
327 if (sta
->ch_width
!= chandef
.width
)
328 changed
|= IEEE80211_RC_BW_CHANGED
;
329 sta
->ch_width
= chandef
.width
;
333 rate_control_rate_init(sta
);
335 rate_control_rate_update(local
, sband
, sta
, changed
);
337 spin_unlock_bh(&sta
->lock
);
340 static struct sta_info
*
341 __mesh_sta_info_alloc(struct ieee80211_sub_if_data
*sdata
, u8
*hw_addr
)
343 struct sta_info
*sta
;
345 if (sdata
->local
->num_sta
>= MESH_MAX_PLINKS
)
348 sta
= sta_info_alloc(sdata
, hw_addr
, GFP_KERNEL
);
352 sta
->plink_state
= NL80211_PLINK_LISTEN
;
353 init_timer(&sta
->plink_timer
);
355 sta_info_pre_move_state(sta
, IEEE80211_STA_AUTH
);
356 sta_info_pre_move_state(sta
, IEEE80211_STA_ASSOC
);
357 sta_info_pre_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
359 set_sta_flag(sta
, WLAN_STA_WME
);
364 static struct sta_info
*
365 mesh_sta_info_alloc(struct ieee80211_sub_if_data
*sdata
, u8
*addr
,
366 struct ieee802_11_elems
*elems
)
368 struct sta_info
*sta
= NULL
;
370 /* Userspace handles peer allocation when security is enabled */
371 if (sdata
->u
.mesh
.security
& IEEE80211_MESH_SEC_AUTHED
)
372 cfg80211_notify_new_peer_candidate(sdata
->dev
, addr
,
377 sta
= __mesh_sta_info_alloc(sdata
, addr
);
383 * mesh_sta_info_get - return mesh sta info entry for @addr.
385 * @sdata: local meshif
386 * @addr: peer's address
387 * @elems: IEs from beacon or mesh peering frame.
389 * Return existing or newly allocated sta_info under RCU read lock.
390 * (re)initialize with given IEs.
392 static struct sta_info
*
393 mesh_sta_info_get(struct ieee80211_sub_if_data
*sdata
,
394 u8
*addr
, struct ieee802_11_elems
*elems
) __acquires(RCU
)
396 struct sta_info
*sta
= NULL
;
399 sta
= sta_info_get(sdata
, addr
);
401 mesh_sta_info_init(sdata
, sta
, elems
, false);
404 /* can't run atomic */
405 sta
= mesh_sta_info_alloc(sdata
, addr
, elems
);
411 mesh_sta_info_init(sdata
, sta
, elems
, true);
413 if (sta_info_insert_rcu(sta
))
421 * mesh_neighbour_update - update or initialize new mesh neighbor.
423 * @sdata: local meshif
424 * @addr: peer's address
425 * @elems: IEs from beacon or mesh peering frame
427 * Initiates peering if appropriate.
429 void mesh_neighbour_update(struct ieee80211_sub_if_data
*sdata
,
431 struct ieee802_11_elems
*elems
)
433 struct sta_info
*sta
;
435 sta
= mesh_sta_info_get(sdata
, hw_addr
, elems
);
439 if (mesh_peer_accepts_plinks(elems
) &&
440 sta
->plink_state
== NL80211_PLINK_LISTEN
&&
441 sdata
->u
.mesh
.accepting_plinks
&&
442 sdata
->u
.mesh
.mshcfg
.auto_open_plinks
&&
443 rssi_threshold_check(sta
, sdata
))
444 mesh_plink_open(sta
);
450 static void mesh_plink_timer(unsigned long data
)
452 struct sta_info
*sta
;
453 __le16 llid
, plid
, reason
;
454 struct ieee80211_sub_if_data
*sdata
;
455 struct mesh_config
*mshcfg
;
458 * This STA is valid because sta_info_destroy() will
459 * del_timer_sync() this timer after having made sure
460 * it cannot be readded (by deleting the plink.)
462 sta
= (struct sta_info
*) data
;
464 if (sta
->sdata
->local
->quiescing
) {
465 sta
->plink_timer_was_running
= true;
469 spin_lock_bh(&sta
->lock
);
470 if (sta
->ignore_plink_timer
) {
471 sta
->ignore_plink_timer
= false;
472 spin_unlock_bh(&sta
->lock
);
476 "Mesh plink timer for %pM fired on state %d\n",
477 sta
->sta
.addr
, sta
->plink_state
);
482 mshcfg
= &sdata
->u
.mesh
.mshcfg
;
484 switch (sta
->plink_state
) {
485 case NL80211_PLINK_OPN_RCVD
:
486 case NL80211_PLINK_OPN_SNT
:
488 if (sta
->plink_retries
< mshcfg
->dot11MeshMaxRetries
) {
491 "Mesh plink for %pM (retry, timeout): %d %d\n",
492 sta
->sta
.addr
, sta
->plink_retries
,
494 get_random_bytes(&rand
, sizeof(u32
));
495 sta
->plink_timeout
= sta
->plink_timeout
+
496 rand
% sta
->plink_timeout
;
497 ++sta
->plink_retries
;
498 mod_plink_timer(sta
, sta
->plink_timeout
);
499 spin_unlock_bh(&sta
->lock
);
500 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_OPEN
,
501 sta
->sta
.addr
, llid
, 0, 0);
504 reason
= cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES
);
505 /* fall through on else */
506 case NL80211_PLINK_CNF_RCVD
:
509 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT
);
510 sta
->plink_state
= NL80211_PLINK_HOLDING
;
511 mod_plink_timer(sta
, mshcfg
->dot11MeshHoldingTimeout
);
512 spin_unlock_bh(&sta
->lock
);
513 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
514 sta
->sta
.addr
, llid
, plid
, reason
);
516 case NL80211_PLINK_HOLDING
:
518 del_timer(&sta
->plink_timer
);
519 mesh_plink_fsm_restart(sta
);
520 spin_unlock_bh(&sta
->lock
);
523 spin_unlock_bh(&sta
->lock
);
529 void mesh_plink_quiesce(struct sta_info
*sta
)
531 if (del_timer_sync(&sta
->plink_timer
))
532 sta
->plink_timer_was_running
= true;
535 void mesh_plink_restart(struct sta_info
*sta
)
537 if (sta
->plink_timer_was_running
) {
538 add_timer(&sta
->plink_timer
);
539 sta
->plink_timer_was_running
= false;
544 static inline void mesh_plink_timer_set(struct sta_info
*sta
, int timeout
)
546 sta
->plink_timer
.expires
= jiffies
+ (HZ
* timeout
/ 1000);
547 sta
->plink_timer
.data
= (unsigned long) sta
;
548 sta
->plink_timer
.function
= mesh_plink_timer
;
549 sta
->plink_timeout
= timeout
;
550 add_timer(&sta
->plink_timer
);
553 int mesh_plink_open(struct sta_info
*sta
)
556 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
558 if (!test_sta_flag(sta
, WLAN_STA_AUTH
))
561 spin_lock_bh(&sta
->lock
);
562 get_random_bytes(&llid
, 2);
564 if (sta
->plink_state
!= NL80211_PLINK_LISTEN
&&
565 sta
->plink_state
!= NL80211_PLINK_BLOCKED
) {
566 spin_unlock_bh(&sta
->lock
);
569 sta
->plink_state
= NL80211_PLINK_OPN_SNT
;
570 mesh_plink_timer_set(sta
, sdata
->u
.mesh
.mshcfg
.dot11MeshRetryTimeout
);
571 spin_unlock_bh(&sta
->lock
);
573 "Mesh plink: starting establishment with %pM\n",
576 return mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_OPEN
,
577 sta
->sta
.addr
, llid
, 0, 0);
580 void mesh_plink_block(struct sta_info
*sta
)
582 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
585 spin_lock_bh(&sta
->lock
);
586 changed
= __mesh_plink_deactivate(sta
);
587 sta
->plink_state
= NL80211_PLINK_BLOCKED
;
588 spin_unlock_bh(&sta
->lock
);
590 ieee80211_bss_info_change_notify(sdata
, changed
);
594 void mesh_rx_plink_frame(struct ieee80211_sub_if_data
*sdata
, struct ieee80211_mgmt
*mgmt
,
595 size_t len
, struct ieee80211_rx_status
*rx_status
)
597 struct mesh_config
*mshcfg
= &sdata
->u
.mesh
.mshcfg
;
598 struct ieee802_11_elems elems
;
599 struct sta_info
*sta
;
600 enum plink_event event
;
601 enum ieee80211_self_protected_actioncode ftype
;
603 bool matches_local
= true;
607 __le16 plid
, llid
, reason
;
608 static const char *mplstates
[] = {
609 [NL80211_PLINK_LISTEN
] = "LISTEN",
610 [NL80211_PLINK_OPN_SNT
] = "OPN-SNT",
611 [NL80211_PLINK_OPN_RCVD
] = "OPN-RCVD",
612 [NL80211_PLINK_CNF_RCVD
] = "CNF_RCVD",
613 [NL80211_PLINK_ESTAB
] = "ESTAB",
614 [NL80211_PLINK_HOLDING
] = "HOLDING",
615 [NL80211_PLINK_BLOCKED
] = "BLOCKED"
618 /* need action_code, aux */
619 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 3)
622 if (is_multicast_ether_addr(mgmt
->da
)) {
624 "Mesh plink: ignore frame from multicast address\n");
628 baseaddr
= mgmt
->u
.action
.u
.self_prot
.variable
;
629 baselen
= (u8
*) mgmt
->u
.action
.u
.self_prot
.variable
- (u8
*) mgmt
;
630 if (mgmt
->u
.action
.u
.self_prot
.action_code
==
631 WLAN_SP_MESH_PEERING_CONFIRM
) {
635 ieee802_11_parse_elems(baseaddr
, len
- baselen
, &elems
);
636 if (!elems
.peering
) {
638 "Mesh plink: missing necessary peer link ie\n");
642 sdata
->u
.mesh
.security
== IEEE80211_MESH_SEC_NONE
) {
644 "Mesh plink: can't establish link with secure peer\n");
648 ftype
= mgmt
->u
.action
.u
.self_prot
.action_code
;
649 ie_len
= elems
.peering_len
;
650 if ((ftype
== WLAN_SP_MESH_PEERING_OPEN
&& ie_len
!= 4) ||
651 (ftype
== WLAN_SP_MESH_PEERING_CONFIRM
&& ie_len
!= 6) ||
652 (ftype
== WLAN_SP_MESH_PEERING_CLOSE
&& ie_len
!= 6
655 "Mesh plink: incorrect plink ie length %d %d\n",
660 if (ftype
!= WLAN_SP_MESH_PEERING_CLOSE
&&
661 (!elems
.mesh_id
|| !elems
.mesh_config
)) {
662 mpl_dbg(sdata
, "Mesh plink: missing necessary ie\n");
665 /* Note the lines below are correct, the llid in the frame is the plid
666 * from the point of view of this host.
668 memcpy(&plid
, PLINK_GET_LLID(elems
.peering
), 2);
669 if (ftype
== WLAN_SP_MESH_PEERING_CONFIRM
||
670 (ftype
== WLAN_SP_MESH_PEERING_CLOSE
&& ie_len
== 8))
671 memcpy(&llid
, PLINK_GET_PLID(elems
.peering
), 2);
673 /* WARNING: Only for sta pointer, is dropped & re-acquired */
676 sta
= sta_info_get(sdata
, mgmt
->sa
);
677 if (!sta
&& ftype
!= WLAN_SP_MESH_PEERING_OPEN
) {
678 mpl_dbg(sdata
, "Mesh plink: cls or cnf from unknown peer\n");
683 if (ftype
== WLAN_SP_MESH_PEERING_OPEN
&&
684 !rssi_threshold_check(sta
, sdata
)) {
685 mpl_dbg(sdata
, "Mesh plink: %pM does not meet rssi threshold\n",
691 if (sta
&& !test_sta_flag(sta
, WLAN_STA_AUTH
)) {
692 mpl_dbg(sdata
, "Mesh plink: Action frame from non-authed peer\n");
697 if (sta
&& sta
->plink_state
== NL80211_PLINK_BLOCKED
) {
702 /* Now we will figure out the appropriate event... */
703 event
= PLINK_UNDEFINED
;
704 if (ftype
!= WLAN_SP_MESH_PEERING_CLOSE
&&
705 !mesh_matches_local(sdata
, &elems
)) {
706 matches_local
= false;
708 case WLAN_SP_MESH_PEERING_OPEN
:
711 case WLAN_SP_MESH_PEERING_CONFIRM
:
719 if (!sta
&& !matches_local
) {
721 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
723 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
724 mgmt
->sa
, llid
, plid
, reason
);
727 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
728 if (!mesh_plink_free_count(sdata
)) {
729 mpl_dbg(sdata
, "Mesh plink error: no more free plinks\n");
734 } else if (matches_local
) {
736 case WLAN_SP_MESH_PEERING_OPEN
:
737 if (!mesh_plink_free_count(sdata
) ||
738 (sta
->plid
&& sta
->plid
!= plid
))
743 case WLAN_SP_MESH_PEERING_CONFIRM
:
744 if (!mesh_plink_free_count(sdata
) ||
745 (sta
->llid
!= llid
|| sta
->plid
!= plid
))
750 case WLAN_SP_MESH_PEERING_CLOSE
:
751 if (sta
->plink_state
== NL80211_PLINK_ESTAB
)
752 /* Do not check for llid or plid. This does not
753 * follow the standard but since multiple plinks
754 * per sta are not supported, it is necessary in
755 * order to avoid a livelock when MP A sees an
756 * establish peer link to MP B but MP B does not
757 * see it. This can be caused by a timeout in
758 * B's peer link establishment or B beign
762 else if (sta
->plid
!= plid
)
764 else if (ie_len
== 7 && sta
->llid
!= llid
)
770 mpl_dbg(sdata
, "Mesh plink: unknown frame subtype\n");
776 if (event
== OPN_ACPT
) {
778 /* allocate sta entry if necessary and update info */
779 sta
= mesh_sta_info_get(sdata
, mgmt
->sa
, &elems
);
781 mpl_dbg(sdata
, "Mesh plink: failed to init peer!\n");
788 "Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
789 mgmt
->sa
, mplstates
[sta
->plink_state
],
790 le16_to_cpu(sta
->llid
), le16_to_cpu(sta
->plid
),
793 spin_lock_bh(&sta
->lock
);
794 switch (sta
->plink_state
) {
795 /* spin_unlock as soon as state is updated at each case */
796 case NL80211_PLINK_LISTEN
:
799 mesh_plink_fsm_restart(sta
);
800 spin_unlock_bh(&sta
->lock
);
803 sta
->plink_state
= NL80211_PLINK_OPN_RCVD
;
805 get_random_bytes(&llid
, 2);
807 mesh_plink_timer_set(sta
,
808 mshcfg
->dot11MeshRetryTimeout
);
809 spin_unlock_bh(&sta
->lock
);
810 mesh_plink_frame_tx(sdata
,
811 WLAN_SP_MESH_PEERING_OPEN
,
812 sta
->sta
.addr
, llid
, 0, 0);
813 mesh_plink_frame_tx(sdata
,
814 WLAN_SP_MESH_PEERING_CONFIRM
,
815 sta
->sta
.addr
, llid
, plid
, 0);
818 spin_unlock_bh(&sta
->lock
);
823 case NL80211_PLINK_OPN_SNT
:
827 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
830 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
831 sta
->reason
= reason
;
832 sta
->plink_state
= NL80211_PLINK_HOLDING
;
833 if (!mod_plink_timer(sta
,
834 mshcfg
->dot11MeshHoldingTimeout
))
835 sta
->ignore_plink_timer
= true;
838 spin_unlock_bh(&sta
->lock
);
839 mesh_plink_frame_tx(sdata
,
840 WLAN_SP_MESH_PEERING_CLOSE
,
841 sta
->sta
.addr
, llid
, plid
, reason
);
844 /* retry timer is left untouched */
845 sta
->plink_state
= NL80211_PLINK_OPN_RCVD
;
848 spin_unlock_bh(&sta
->lock
);
849 mesh_plink_frame_tx(sdata
,
850 WLAN_SP_MESH_PEERING_CONFIRM
,
851 sta
->sta
.addr
, llid
, plid
, 0);
854 sta
->plink_state
= NL80211_PLINK_CNF_RCVD
;
855 if (!mod_plink_timer(sta
,
856 mshcfg
->dot11MeshConfirmTimeout
))
857 sta
->ignore_plink_timer
= true;
859 spin_unlock_bh(&sta
->lock
);
862 spin_unlock_bh(&sta
->lock
);
867 case NL80211_PLINK_OPN_RCVD
:
871 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
874 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
875 sta
->reason
= reason
;
876 sta
->plink_state
= NL80211_PLINK_HOLDING
;
877 if (!mod_plink_timer(sta
,
878 mshcfg
->dot11MeshHoldingTimeout
))
879 sta
->ignore_plink_timer
= true;
882 spin_unlock_bh(&sta
->lock
);
883 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
884 sta
->sta
.addr
, llid
, plid
, reason
);
888 spin_unlock_bh(&sta
->lock
);
889 mesh_plink_frame_tx(sdata
,
890 WLAN_SP_MESH_PEERING_CONFIRM
,
891 sta
->sta
.addr
, llid
, plid
, 0);
894 del_timer(&sta
->plink_timer
);
895 sta
->plink_state
= NL80211_PLINK_ESTAB
;
896 spin_unlock_bh(&sta
->lock
);
897 changed
|= mesh_plink_inc_estab_count(sdata
);
898 changed
|= mesh_set_ht_prot_mode(sdata
);
899 mpl_dbg(sdata
, "Mesh plink with %pM ESTABLISHED\n",
903 spin_unlock_bh(&sta
->lock
);
908 case NL80211_PLINK_CNF_RCVD
:
912 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
915 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
916 sta
->reason
= reason
;
917 sta
->plink_state
= NL80211_PLINK_HOLDING
;
918 if (!mod_plink_timer(sta
,
919 mshcfg
->dot11MeshHoldingTimeout
))
920 sta
->ignore_plink_timer
= true;
923 spin_unlock_bh(&sta
->lock
);
924 mesh_plink_frame_tx(sdata
,
925 WLAN_SP_MESH_PEERING_CLOSE
,
926 sta
->sta
.addr
, llid
, plid
, reason
);
929 del_timer(&sta
->plink_timer
);
930 sta
->plink_state
= NL80211_PLINK_ESTAB
;
931 spin_unlock_bh(&sta
->lock
);
932 changed
|= mesh_plink_inc_estab_count(sdata
);
933 changed
|= mesh_set_ht_prot_mode(sdata
);
934 mpl_dbg(sdata
, "Mesh plink with %pM ESTABLISHED\n",
936 mesh_plink_frame_tx(sdata
,
937 WLAN_SP_MESH_PEERING_CONFIRM
,
938 sta
->sta
.addr
, llid
, plid
, 0);
941 spin_unlock_bh(&sta
->lock
);
946 case NL80211_PLINK_ESTAB
:
949 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
950 sta
->reason
= reason
;
951 changed
|= __mesh_plink_deactivate(sta
);
952 sta
->plink_state
= NL80211_PLINK_HOLDING
;
954 mod_plink_timer(sta
, mshcfg
->dot11MeshHoldingTimeout
);
955 spin_unlock_bh(&sta
->lock
);
956 changed
|= mesh_set_ht_prot_mode(sdata
);
957 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
958 sta
->sta
.addr
, llid
, plid
, reason
);
962 spin_unlock_bh(&sta
->lock
);
963 mesh_plink_frame_tx(sdata
,
964 WLAN_SP_MESH_PEERING_CONFIRM
,
965 sta
->sta
.addr
, llid
, plid
, 0);
968 spin_unlock_bh(&sta
->lock
);
972 case NL80211_PLINK_HOLDING
:
975 if (del_timer(&sta
->plink_timer
))
976 sta
->ignore_plink_timer
= 1;
977 mesh_plink_fsm_restart(sta
);
978 spin_unlock_bh(&sta
->lock
);
985 reason
= sta
->reason
;
986 spin_unlock_bh(&sta
->lock
);
987 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
988 sta
->sta
.addr
, llid
, plid
, reason
);
991 spin_unlock_bh(&sta
->lock
);
995 /* should not get here, PLINK_BLOCKED is dealt with at the
996 * beginning of the function
998 spin_unlock_bh(&sta
->lock
);
1005 ieee80211_bss_info_change_notify(sdata
, changed
);