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 #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
17 #define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
19 #define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
22 #define PLINK_GET_LLID(p) (p + 2)
23 #define PLINK_GET_PLID(p) (p + 4)
25 #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000))
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)
34 /* We only need a valid sta if user configured a minimum rssi_threshold. */
35 #define rssi_threshold_check(sta, sdata) \
36 (sdata->u.mesh.mshcfg.rssi_threshold == 0 ||\
37 (sta && (s8) -ewma_read(&sta->avg_signal) > \
38 sdata->u.mesh.mshcfg.rssi_threshold))
52 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data
*sdata
,
53 enum ieee80211_self_protected_actioncode action
,
54 u8
*da
, __le16 llid
, __le16 plid
, __le16 reason
);
57 void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data
*sdata
)
59 atomic_inc(&sdata
->u
.mesh
.mshstats
.estab_plinks
);
60 mesh_accept_plinks_update(sdata
);
64 void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data
*sdata
)
66 atomic_dec(&sdata
->u
.mesh
.mshstats
.estab_plinks
);
67 mesh_accept_plinks_update(sdata
);
71 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
73 * @sta: mesh peer link to restart
75 * Locking: this function must be called holding sta->lock
77 static inline void mesh_plink_fsm_restart(struct sta_info
*sta
)
79 sta
->plink_state
= NL80211_PLINK_LISTEN
;
80 sta
->llid
= sta
->plid
= sta
->reason
= 0;
81 sta
->plink_retries
= 0;
85 * Allocate mesh sta entry and insert into station table
87 static struct sta_info
*mesh_plink_alloc(struct ieee80211_sub_if_data
*sdata
,
92 if (sdata
->local
->num_sta
>= MESH_MAX_PLINKS
)
95 sta
= sta_info_alloc(sdata
, hw_addr
, GFP_KERNEL
);
99 sta_info_pre_move_state(sta
, IEEE80211_STA_AUTH
);
100 sta_info_pre_move_state(sta
, IEEE80211_STA_ASSOC
);
101 sta_info_pre_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
103 set_sta_flag(sta
, WLAN_STA_WME
);
108 /** mesh_set_ht_prot_mode - set correct HT protection mode
110 * Section 9.23.3.5 of IEEE 80211s standard describes the protection rules for
111 * HT mesh STA in a MBSS. Three HT protection modes are supported for now,
112 * non-HT mixed mode, 20MHz-protection and no-protection mode. non-HT mixed
113 * mode is selected if any non-HT peers are present in our MBSS.
114 * 20MHz-protection mode is selected if all peers in our 20/40MHz MBSS support
115 * HT and atleast one HT20 peer is present. Otherwise no-protection mode is
118 static u32
mesh_set_ht_prot_mode(struct ieee80211_sub_if_data
*sdata
)
120 struct ieee80211_local
*local
= sdata
->local
;
121 struct sta_info
*sta
;
124 bool non_ht_sta
= false, ht20_sta
= false;
126 if (local
->_oper_channel_type
== NL80211_CHAN_NO_HT
)
130 list_for_each_entry_rcu(sta
, &local
->sta_list
, list
) {
131 if (sdata
== sta
->sdata
&&
132 sta
->plink_state
== NL80211_PLINK_ESTAB
) {
133 switch (sta
->ch_type
) {
134 case NL80211_CHAN_NO_HT
:
135 mpl_dbg("mesh_plink %pM: nonHT sta (%pM) is present",
136 sdata
->vif
.addr
, sta
->sta
.addr
);
139 case NL80211_CHAN_HT20
:
140 mpl_dbg("mesh_plink %pM: HT20 sta (%pM) is present",
141 sdata
->vif
.addr
, sta
->sta
.addr
);
152 ht_opmode
= IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
;
153 else if (ht20_sta
&& local
->_oper_channel_type
> NL80211_CHAN_HT20
)
154 ht_opmode
= IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
;
156 ht_opmode
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
158 if (sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
) {
159 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
160 sdata
->u
.mesh
.mshcfg
.ht_opmode
= ht_opmode
;
161 changed
= BSS_CHANGED_HT
;
162 mpl_dbg("mesh_plink %pM: protection mode changed to %d",
163 sdata
->vif
.addr
, ht_opmode
);
170 * __mesh_plink_deactivate - deactivate mesh peer link
172 * @sta: mesh peer link to deactivate
174 * All mesh paths with this peer as next hop will be flushed
176 * Locking: the caller must hold sta->lock
178 static bool __mesh_plink_deactivate(struct sta_info
*sta
)
180 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
181 bool deactivated
= false;
183 if (sta
->plink_state
== NL80211_PLINK_ESTAB
) {
184 mesh_plink_dec_estab_count(sdata
);
187 sta
->plink_state
= NL80211_PLINK_BLOCKED
;
188 mesh_path_flush_by_nexthop(sta
);
194 * mesh_plink_deactivate - deactivate mesh peer link
196 * @sta: mesh peer link to deactivate
198 * All mesh paths with this peer as next hop will be flushed
200 void mesh_plink_deactivate(struct sta_info
*sta
)
202 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
205 spin_lock_bh(&sta
->lock
);
206 deactivated
= __mesh_plink_deactivate(sta
);
207 sta
->reason
= cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED
);
208 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
209 sta
->sta
.addr
, sta
->llid
, sta
->plid
,
211 spin_unlock_bh(&sta
->lock
);
214 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON
);
217 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data
*sdata
,
218 enum ieee80211_self_protected_actioncode action
,
219 u8
*da
, __le16 llid
, __le16 plid
, __le16 reason
) {
220 struct ieee80211_local
*local
= sdata
->local
;
222 struct ieee80211_mgmt
*mgmt
;
223 bool include_plid
= false;
224 u16 peering_proto
= 0;
226 int hdr_len
= offsetof(struct ieee80211_mgmt
, u
.action
.u
.self_prot
) +
227 sizeof(mgmt
->u
.action
.u
.self_prot
);
229 skb
= dev_alloc_skb(local
->tx_headroom
+
231 2 + /* capability info */
233 2 + 8 + /* supported rates */
234 2 + (IEEE80211_MAX_SUPP_RATES
- 8) +
235 2 + sdata
->u
.mesh
.mesh_id_len
+
236 2 + sizeof(struct ieee80211_meshconf_ie
) +
237 2 + sizeof(struct ieee80211_ht_cap
) +
238 2 + sizeof(struct ieee80211_ht_operation
) +
239 2 + 8 + /* peering IE */
240 sdata
->u
.mesh
.ie_len
);
243 skb_reserve(skb
, local
->tx_headroom
);
244 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, hdr_len
);
245 memset(mgmt
, 0, hdr_len
);
246 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
247 IEEE80211_STYPE_ACTION
);
248 memcpy(mgmt
->da
, da
, ETH_ALEN
);
249 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
250 memcpy(mgmt
->bssid
, sdata
->vif
.addr
, ETH_ALEN
);
251 mgmt
->u
.action
.category
= WLAN_CATEGORY_SELF_PROTECTED
;
252 mgmt
->u
.action
.u
.self_prot
.action_code
= action
;
254 if (action
!= WLAN_SP_MESH_PEERING_CLOSE
) {
255 /* capability info */
256 pos
= skb_put(skb
, 2);
258 if (action
== WLAN_SP_MESH_PEERING_CONFIRM
) {
260 pos
= skb_put(skb
, 2);
261 memcpy(pos
+ 2, &plid
, 2);
263 if (ieee80211_add_srates_ie(&sdata
->vif
, skb
, true) ||
264 ieee80211_add_ext_srates_ie(&sdata
->vif
, skb
, true) ||
265 mesh_add_rsn_ie(skb
, sdata
) ||
266 mesh_add_meshid_ie(skb
, sdata
) ||
267 mesh_add_meshconf_ie(skb
, sdata
))
269 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
270 if (mesh_add_meshid_ie(skb
, sdata
))
274 /* Add Mesh Peering Management element */
276 case WLAN_SP_MESH_PEERING_OPEN
:
278 case WLAN_SP_MESH_PEERING_CONFIRM
:
282 case WLAN_SP_MESH_PEERING_CLOSE
:
287 ie_len
+= 2; /* reason code */
293 if (WARN_ON(skb_tailroom(skb
) < 2 + ie_len
))
296 pos
= skb_put(skb
, 2 + ie_len
);
297 *pos
++ = WLAN_EID_PEER_MGMT
;
299 memcpy(pos
, &peering_proto
, 2);
301 memcpy(pos
, &llid
, 2);
304 memcpy(pos
, &plid
, 2);
307 if (action
== WLAN_SP_MESH_PEERING_CLOSE
) {
308 memcpy(pos
, &reason
, 2);
312 if (action
!= WLAN_SP_MESH_PEERING_CLOSE
) {
313 if (mesh_add_ht_cap_ie(skb
, sdata
) ||
314 mesh_add_ht_oper_ie(skb
, sdata
))
318 if (mesh_add_vendor_ies(skb
, sdata
))
321 ieee80211_tx_skb(sdata
, skb
);
325 /* mesh_peer_init - initialize new mesh peer and return resulting sta_info
327 * @sdata: local meshif
328 * @addr: peer's address
329 * @elems: IEs from beacon or mesh peering frame
333 static struct sta_info
*mesh_peer_init(struct ieee80211_sub_if_data
*sdata
,
335 struct ieee802_11_elems
*elems
)
337 struct ieee80211_local
*local
= sdata
->local
;
338 enum ieee80211_band band
= local
->oper_channel
->band
;
339 struct ieee80211_supported_band
*sband
;
340 u32 rates
, basic_rates
= 0;
341 struct sta_info
*sta
;
344 sband
= local
->hw
.wiphy
->bands
[band
];
345 rates
= ieee80211_sta_get_rates(local
, elems
, band
, &basic_rates
);
347 sta
= sta_info_get(sdata
, addr
);
349 sta
= mesh_plink_alloc(sdata
, addr
);
355 spin_lock_bh(&sta
->lock
);
356 sta
->last_rx
= jiffies
;
357 sta
->sta
.supp_rates
[band
] = rates
;
358 if (elems
->ht_cap_elem
&&
359 sdata
->local
->_oper_channel_type
!= NL80211_CHAN_NO_HT
)
360 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
364 memset(&sta
->sta
.ht_cap
, 0, sizeof(sta
->sta
.ht_cap
));
366 if (elems
->ht_operation
) {
367 if (!(elems
->ht_operation
->ht_param
&
368 IEEE80211_HT_PARAM_CHAN_WIDTH_ANY
))
369 sta
->sta
.ht_cap
.cap
&=
370 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
372 ieee80211_ht_oper_to_channel_type(elems
->ht_operation
);
375 rate_control_rate_init(sta
);
376 spin_unlock_bh(&sta
->lock
);
378 if (insert
&& sta_info_insert(sta
))
384 void mesh_neighbour_update(struct ieee80211_sub_if_data
*sdata
,
386 struct ieee802_11_elems
*elems
)
388 struct sta_info
*sta
;
390 /* Userspace handles peer allocation when security is enabled */
391 if (sdata
->u
.mesh
.security
& IEEE80211_MESH_SEC_AUTHED
) {
392 cfg80211_notify_new_peer_candidate(sdata
->dev
, hw_addr
,
400 sta
= mesh_peer_init(sdata
, hw_addr
, elems
);
404 if (mesh_peer_accepts_plinks(elems
) &&
405 sta
->plink_state
== NL80211_PLINK_LISTEN
&&
406 sdata
->u
.mesh
.accepting_plinks
&&
407 sdata
->u
.mesh
.mshcfg
.auto_open_plinks
&&
408 rssi_threshold_check(sta
, sdata
))
409 mesh_plink_open(sta
);
415 static void mesh_plink_timer(unsigned long data
)
417 struct sta_info
*sta
;
418 __le16 llid
, plid
, reason
;
419 struct ieee80211_sub_if_data
*sdata
;
422 * This STA is valid because sta_info_destroy() will
423 * del_timer_sync() this timer after having made sure
424 * it cannot be readded (by deleting the plink.)
426 sta
= (struct sta_info
*) data
;
428 if (sta
->sdata
->local
->quiescing
) {
429 sta
->plink_timer_was_running
= true;
433 spin_lock_bh(&sta
->lock
);
434 if (sta
->ignore_plink_timer
) {
435 sta
->ignore_plink_timer
= false;
436 spin_unlock_bh(&sta
->lock
);
439 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
440 sta
->sta
.addr
, sta
->plink_state
);
446 switch (sta
->plink_state
) {
447 case NL80211_PLINK_OPN_RCVD
:
448 case NL80211_PLINK_OPN_SNT
:
450 if (sta
->plink_retries
< dot11MeshMaxRetries(sdata
)) {
452 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
453 sta
->sta
.addr
, sta
->plink_retries
,
455 get_random_bytes(&rand
, sizeof(u32
));
456 sta
->plink_timeout
= sta
->plink_timeout
+
457 rand
% sta
->plink_timeout
;
458 ++sta
->plink_retries
;
459 mod_plink_timer(sta
, sta
->plink_timeout
);
460 spin_unlock_bh(&sta
->lock
);
461 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_OPEN
,
462 sta
->sta
.addr
, llid
, 0, 0);
465 reason
= cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES
);
466 /* fall through on else */
467 case NL80211_PLINK_CNF_RCVD
:
470 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT
);
471 sta
->plink_state
= NL80211_PLINK_HOLDING
;
472 mod_plink_timer(sta
, dot11MeshHoldingTimeout(sdata
));
473 spin_unlock_bh(&sta
->lock
);
474 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
475 sta
->sta
.addr
, llid
, plid
, reason
);
477 case NL80211_PLINK_HOLDING
:
479 del_timer(&sta
->plink_timer
);
480 mesh_plink_fsm_restart(sta
);
481 spin_unlock_bh(&sta
->lock
);
484 spin_unlock_bh(&sta
->lock
);
490 void mesh_plink_quiesce(struct sta_info
*sta
)
492 if (del_timer_sync(&sta
->plink_timer
))
493 sta
->plink_timer_was_running
= true;
496 void mesh_plink_restart(struct sta_info
*sta
)
498 if (sta
->plink_timer_was_running
) {
499 add_timer(&sta
->plink_timer
);
500 sta
->plink_timer_was_running
= false;
505 static inline void mesh_plink_timer_set(struct sta_info
*sta
, int timeout
)
507 sta
->plink_timer
.expires
= jiffies
+ (HZ
* timeout
/ 1000);
508 sta
->plink_timer
.data
= (unsigned long) sta
;
509 sta
->plink_timer
.function
= mesh_plink_timer
;
510 sta
->plink_timeout
= timeout
;
511 add_timer(&sta
->plink_timer
);
514 int mesh_plink_open(struct sta_info
*sta
)
517 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
519 if (!test_sta_flag(sta
, WLAN_STA_AUTH
))
522 spin_lock_bh(&sta
->lock
);
523 get_random_bytes(&llid
, 2);
525 if (sta
->plink_state
!= NL80211_PLINK_LISTEN
) {
526 spin_unlock_bh(&sta
->lock
);
529 sta
->plink_state
= NL80211_PLINK_OPN_SNT
;
530 mesh_plink_timer_set(sta
, dot11MeshRetryTimeout(sdata
));
531 spin_unlock_bh(&sta
->lock
);
532 mpl_dbg("Mesh plink: starting establishment with %pM\n",
535 return mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_OPEN
,
536 sta
->sta
.addr
, llid
, 0, 0);
539 void mesh_plink_block(struct sta_info
*sta
)
541 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
544 spin_lock_bh(&sta
->lock
);
545 deactivated
= __mesh_plink_deactivate(sta
);
546 sta
->plink_state
= NL80211_PLINK_BLOCKED
;
547 spin_unlock_bh(&sta
->lock
);
550 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON
);
554 void mesh_rx_plink_frame(struct ieee80211_sub_if_data
*sdata
, struct ieee80211_mgmt
*mgmt
,
555 size_t len
, struct ieee80211_rx_status
*rx_status
)
557 struct ieee802_11_elems elems
;
558 struct sta_info
*sta
;
559 enum plink_event event
;
560 enum ieee80211_self_protected_actioncode ftype
;
562 bool matches_local
= true;
566 __le16 plid
, llid
, reason
;
567 #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
568 static const char *mplstates
[] = {
569 [NL80211_PLINK_LISTEN
] = "LISTEN",
570 [NL80211_PLINK_OPN_SNT
] = "OPN-SNT",
571 [NL80211_PLINK_OPN_RCVD
] = "OPN-RCVD",
572 [NL80211_PLINK_CNF_RCVD
] = "CNF_RCVD",
573 [NL80211_PLINK_ESTAB
] = "ESTAB",
574 [NL80211_PLINK_HOLDING
] = "HOLDING",
575 [NL80211_PLINK_BLOCKED
] = "BLOCKED"
579 /* need action_code, aux */
580 if (len
< IEEE80211_MIN_ACTION_SIZE
+ 3)
583 if (is_multicast_ether_addr(mgmt
->da
)) {
584 mpl_dbg("Mesh plink: ignore frame from multicast address");
588 baseaddr
= mgmt
->u
.action
.u
.self_prot
.variable
;
589 baselen
= (u8
*) mgmt
->u
.action
.u
.self_prot
.variable
- (u8
*) mgmt
;
590 if (mgmt
->u
.action
.u
.self_prot
.action_code
==
591 WLAN_SP_MESH_PEERING_CONFIRM
) {
595 ieee802_11_parse_elems(baseaddr
, len
- baselen
, &elems
);
596 if (!elems
.peering
) {
597 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
601 sdata
->u
.mesh
.security
== IEEE80211_MESH_SEC_NONE
) {
602 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
606 ftype
= mgmt
->u
.action
.u
.self_prot
.action_code
;
607 ie_len
= elems
.peering_len
;
608 if ((ftype
== WLAN_SP_MESH_PEERING_OPEN
&& ie_len
!= 4) ||
609 (ftype
== WLAN_SP_MESH_PEERING_CONFIRM
&& ie_len
!= 6) ||
610 (ftype
== WLAN_SP_MESH_PEERING_CLOSE
&& ie_len
!= 6
612 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
617 if (ftype
!= WLAN_SP_MESH_PEERING_CLOSE
&&
618 (!elems
.mesh_id
|| !elems
.mesh_config
)) {
619 mpl_dbg("Mesh plink: missing necessary ie\n");
622 /* Note the lines below are correct, the llid in the frame is the plid
623 * from the point of view of this host.
625 memcpy(&plid
, PLINK_GET_LLID(elems
.peering
), 2);
626 if (ftype
== WLAN_SP_MESH_PEERING_CONFIRM
||
627 (ftype
== WLAN_SP_MESH_PEERING_CLOSE
&& ie_len
== 8))
628 memcpy(&llid
, PLINK_GET_PLID(elems
.peering
), 2);
632 sta
= sta_info_get(sdata
, mgmt
->sa
);
633 if (!sta
&& ftype
!= WLAN_SP_MESH_PEERING_OPEN
) {
634 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
639 if (ftype
== WLAN_SP_MESH_PEERING_OPEN
&&
640 !rssi_threshold_check(sta
, sdata
)) {
641 mpl_dbg("Mesh plink: %pM does not meet rssi threshold\n",
647 if (sta
&& !test_sta_flag(sta
, WLAN_STA_AUTH
)) {
648 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
653 if (sta
&& sta
->plink_state
== NL80211_PLINK_BLOCKED
) {
658 /* Now we will figure out the appropriate event... */
659 event
= PLINK_UNDEFINED
;
660 if (ftype
!= WLAN_SP_MESH_PEERING_CLOSE
&&
661 !mesh_matches_local(sdata
, &elems
)) {
662 matches_local
= false;
664 case WLAN_SP_MESH_PEERING_OPEN
:
667 case WLAN_SP_MESH_PEERING_CONFIRM
:
675 if (!sta
&& !matches_local
) {
677 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
679 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
680 mgmt
->sa
, llid
, plid
, reason
);
683 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
684 if (!mesh_plink_free_count(sdata
)) {
685 mpl_dbg("Mesh plink error: no more free plinks\n");
690 } else if (matches_local
) {
692 case WLAN_SP_MESH_PEERING_OPEN
:
693 if (!mesh_plink_free_count(sdata
) ||
694 (sta
->plid
&& sta
->plid
!= plid
))
699 case WLAN_SP_MESH_PEERING_CONFIRM
:
700 if (!mesh_plink_free_count(sdata
) ||
701 (sta
->llid
!= llid
|| sta
->plid
!= plid
))
706 case WLAN_SP_MESH_PEERING_CLOSE
:
707 if (sta
->plink_state
== NL80211_PLINK_ESTAB
)
708 /* Do not check for llid or plid. This does not
709 * follow the standard but since multiple plinks
710 * per sta are not supported, it is necessary in
711 * order to avoid a livelock when MP A sees an
712 * establish peer link to MP B but MP B does not
713 * see it. This can be caused by a timeout in
714 * B's peer link establishment or B beign
718 else if (sta
->plid
!= plid
)
720 else if (ie_len
== 7 && sta
->llid
!= llid
)
726 mpl_dbg("Mesh plink: unknown frame subtype\n");
732 if (event
== OPN_ACPT
) {
733 /* allocate sta entry if necessary and update info */
734 sta
= mesh_peer_init(sdata
, mgmt
->sa
, &elems
);
736 mpl_dbg("Mesh plink: failed to init peer!\n");
742 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
743 mgmt
->sa
, mplstates
[sta
->plink_state
],
744 le16_to_cpu(sta
->llid
), le16_to_cpu(sta
->plid
),
747 spin_lock_bh(&sta
->lock
);
748 switch (sta
->plink_state
) {
749 /* spin_unlock as soon as state is updated at each case */
750 case NL80211_PLINK_LISTEN
:
753 mesh_plink_fsm_restart(sta
);
754 spin_unlock_bh(&sta
->lock
);
757 sta
->plink_state
= NL80211_PLINK_OPN_RCVD
;
759 get_random_bytes(&llid
, 2);
761 mesh_plink_timer_set(sta
, dot11MeshRetryTimeout(sdata
));
762 spin_unlock_bh(&sta
->lock
);
763 mesh_plink_frame_tx(sdata
,
764 WLAN_SP_MESH_PEERING_OPEN
,
765 sta
->sta
.addr
, llid
, 0, 0);
766 mesh_plink_frame_tx(sdata
,
767 WLAN_SP_MESH_PEERING_CONFIRM
,
768 sta
->sta
.addr
, llid
, plid
, 0);
771 spin_unlock_bh(&sta
->lock
);
776 case NL80211_PLINK_OPN_SNT
:
780 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
783 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
784 sta
->reason
= reason
;
785 sta
->plink_state
= NL80211_PLINK_HOLDING
;
786 if (!mod_plink_timer(sta
,
787 dot11MeshHoldingTimeout(sdata
)))
788 sta
->ignore_plink_timer
= true;
791 spin_unlock_bh(&sta
->lock
);
792 mesh_plink_frame_tx(sdata
,
793 WLAN_SP_MESH_PEERING_CLOSE
,
794 sta
->sta
.addr
, llid
, plid
, reason
);
797 /* retry timer is left untouched */
798 sta
->plink_state
= NL80211_PLINK_OPN_RCVD
;
801 spin_unlock_bh(&sta
->lock
);
802 mesh_plink_frame_tx(sdata
,
803 WLAN_SP_MESH_PEERING_CONFIRM
,
804 sta
->sta
.addr
, llid
, plid
, 0);
807 sta
->plink_state
= NL80211_PLINK_CNF_RCVD
;
808 if (!mod_plink_timer(sta
,
809 dot11MeshConfirmTimeout(sdata
)))
810 sta
->ignore_plink_timer
= true;
812 spin_unlock_bh(&sta
->lock
);
815 spin_unlock_bh(&sta
->lock
);
820 case NL80211_PLINK_OPN_RCVD
:
824 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
827 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
828 sta
->reason
= reason
;
829 sta
->plink_state
= NL80211_PLINK_HOLDING
;
830 if (!mod_plink_timer(sta
,
831 dot11MeshHoldingTimeout(sdata
)))
832 sta
->ignore_plink_timer
= true;
835 spin_unlock_bh(&sta
->lock
);
836 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
837 sta
->sta
.addr
, llid
, plid
, reason
);
841 spin_unlock_bh(&sta
->lock
);
842 mesh_plink_frame_tx(sdata
,
843 WLAN_SP_MESH_PEERING_CONFIRM
,
844 sta
->sta
.addr
, llid
, plid
, 0);
847 del_timer(&sta
->plink_timer
);
848 sta
->plink_state
= NL80211_PLINK_ESTAB
;
849 spin_unlock_bh(&sta
->lock
);
850 mesh_plink_inc_estab_count(sdata
);
851 changed
|= mesh_set_ht_prot_mode(sdata
);
852 changed
|= BSS_CHANGED_BEACON
;
853 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
857 spin_unlock_bh(&sta
->lock
);
862 case NL80211_PLINK_CNF_RCVD
:
866 reason
= cpu_to_le16(WLAN_REASON_MESH_CONFIG
);
869 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
870 sta
->reason
= reason
;
871 sta
->plink_state
= NL80211_PLINK_HOLDING
;
872 if (!mod_plink_timer(sta
,
873 dot11MeshHoldingTimeout(sdata
)))
874 sta
->ignore_plink_timer
= true;
877 spin_unlock_bh(&sta
->lock
);
878 mesh_plink_frame_tx(sdata
,
879 WLAN_SP_MESH_PEERING_CLOSE
,
880 sta
->sta
.addr
, llid
, plid
, reason
);
883 del_timer(&sta
->plink_timer
);
884 sta
->plink_state
= NL80211_PLINK_ESTAB
;
885 spin_unlock_bh(&sta
->lock
);
886 mesh_plink_inc_estab_count(sdata
);
887 changed
|= mesh_set_ht_prot_mode(sdata
);
888 changed
|= BSS_CHANGED_BEACON
;
889 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
891 mesh_plink_frame_tx(sdata
,
892 WLAN_SP_MESH_PEERING_CONFIRM
,
893 sta
->sta
.addr
, llid
, plid
, 0);
896 spin_unlock_bh(&sta
->lock
);
901 case NL80211_PLINK_ESTAB
:
904 reason
= cpu_to_le16(WLAN_REASON_MESH_CLOSE
);
905 sta
->reason
= reason
;
906 __mesh_plink_deactivate(sta
);
907 sta
->plink_state
= NL80211_PLINK_HOLDING
;
909 mod_plink_timer(sta
, dot11MeshHoldingTimeout(sdata
));
910 spin_unlock_bh(&sta
->lock
);
911 changed
|= mesh_set_ht_prot_mode(sdata
);
912 changed
|= BSS_CHANGED_BEACON
;
913 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
914 sta
->sta
.addr
, llid
, plid
, reason
);
918 spin_unlock_bh(&sta
->lock
);
919 mesh_plink_frame_tx(sdata
,
920 WLAN_SP_MESH_PEERING_CONFIRM
,
921 sta
->sta
.addr
, llid
, plid
, 0);
924 spin_unlock_bh(&sta
->lock
);
928 case NL80211_PLINK_HOLDING
:
931 if (del_timer(&sta
->plink_timer
))
932 sta
->ignore_plink_timer
= 1;
933 mesh_plink_fsm_restart(sta
);
934 spin_unlock_bh(&sta
->lock
);
941 reason
= sta
->reason
;
942 spin_unlock_bh(&sta
->lock
);
943 mesh_plink_frame_tx(sdata
, WLAN_SP_MESH_PEERING_CLOSE
,
944 sta
->sta
.addr
, llid
, plid
, reason
);
947 spin_unlock_bh(&sta
->lock
);
951 /* should not get here, PLINK_BLOCKED is dealt with at the
952 * beginning of the function
954 spin_unlock_bh(&sta
->lock
);
961 ieee80211_bss_info_change_notify(sdata
, changed
);