ext4: make local symbol ext4_initxattrs static
[linux/fpc-iii.git] / net / mac80211 / mesh_plink.c
blob7e57f5d07f660ad7b19c432f95518952382832b9
1 /*
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.
8 */
9 #include <linux/gfp.h>
10 #include <linux/kernel.h>
11 #include <linux/random.h>
12 #include "ieee80211_i.h"
13 #include "rate.h"
14 #include "mesh.h"
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
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 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
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);
50 static inline
51 void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
53 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
54 mesh_accept_plinks_update(sdata);
57 static inline
58 void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
60 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
61 mesh_accept_plinks_update(sdata);
64 /**
65 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
67 * @sta: mesh peer link to restart
69 * Locking: this function must be called holding sta->lock
71 static inline void mesh_plink_fsm_restart(struct sta_info *sta)
73 sta->plink_state = NL80211_PLINK_LISTEN;
74 sta->llid = sta->plid = sta->reason = 0;
75 sta->plink_retries = 0;
79 * NOTE: This is just an alias for sta_info_alloc(), see notes
80 * on it in the lifecycle management section!
82 static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
83 u8 *hw_addr, u32 rates)
85 struct ieee80211_local *local = sdata->local;
86 struct sta_info *sta;
88 if (local->num_sta >= MESH_MAX_PLINKS)
89 return NULL;
91 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
92 if (!sta)
93 return NULL;
95 set_sta_flag(sta, WLAN_STA_AUTH);
96 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
97 set_sta_flag(sta, WLAN_STA_WME);
98 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
99 rate_control_rate_init(sta);
101 return sta;
105 * __mesh_plink_deactivate - deactivate mesh peer link
107 * @sta: mesh peer link to deactivate
109 * All mesh paths with this peer as next hop will be flushed
111 * Locking: the caller must hold sta->lock
113 static bool __mesh_plink_deactivate(struct sta_info *sta)
115 struct ieee80211_sub_if_data *sdata = sta->sdata;
116 bool deactivated = false;
118 if (sta->plink_state == NL80211_PLINK_ESTAB) {
119 mesh_plink_dec_estab_count(sdata);
120 deactivated = true;
122 sta->plink_state = NL80211_PLINK_BLOCKED;
123 mesh_path_flush_by_nexthop(sta);
125 return deactivated;
129 * mesh_plink_deactivate - deactivate mesh peer link
131 * @sta: mesh peer link to deactivate
133 * All mesh paths with this peer as next hop will be flushed
135 void mesh_plink_deactivate(struct sta_info *sta)
137 struct ieee80211_sub_if_data *sdata = sta->sdata;
138 bool deactivated;
140 spin_lock_bh(&sta->lock);
141 deactivated = __mesh_plink_deactivate(sta);
142 sta->reason = cpu_to_le16(WLAN_REASON_MESH_PEER_CANCELED);
143 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
144 sta->sta.addr, sta->llid, sta->plid,
145 sta->reason);
146 spin_unlock_bh(&sta->lock);
148 if (deactivated)
149 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
152 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
153 enum ieee80211_self_protected_actioncode action,
154 u8 *da, __le16 llid, __le16 plid, __le16 reason) {
155 struct ieee80211_local *local = sdata->local;
156 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400 +
157 sdata->u.mesh.ie_len);
158 struct ieee80211_mgmt *mgmt;
159 bool include_plid = false;
160 int ie_len = 4;
161 u16 peering_proto = 0;
162 u8 *pos;
164 if (!skb)
165 return -1;
166 skb_reserve(skb, local->hw.extra_tx_headroom);
167 /* 25 is the size of the common mgmt part (24) plus the size of the
168 * common action part (1)
170 mgmt = (struct ieee80211_mgmt *)
171 skb_put(skb, 25 + sizeof(mgmt->u.action.u.self_prot));
172 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.self_prot));
173 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
174 IEEE80211_STYPE_ACTION);
175 memcpy(mgmt->da, da, ETH_ALEN);
176 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
177 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
178 mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
179 mgmt->u.action.u.self_prot.action_code = action;
181 if (action != WLAN_SP_MESH_PEERING_CLOSE) {
182 /* capability info */
183 pos = skb_put(skb, 2);
184 memset(pos, 0, 2);
185 if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
186 /* AID */
187 pos = skb_put(skb, 2);
188 memcpy(pos + 2, &plid, 2);
190 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
191 ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
192 mesh_add_rsn_ie(skb, sdata) ||
193 mesh_add_meshid_ie(skb, sdata) ||
194 mesh_add_meshconf_ie(skb, sdata))
195 return -1;
196 } else { /* WLAN_SP_MESH_PEERING_CLOSE */
197 if (mesh_add_meshid_ie(skb, sdata))
198 return -1;
201 /* Add Mesh Peering Management element */
202 switch (action) {
203 case WLAN_SP_MESH_PEERING_OPEN:
204 break;
205 case WLAN_SP_MESH_PEERING_CONFIRM:
206 ie_len += 2;
207 include_plid = true;
208 break;
209 case WLAN_SP_MESH_PEERING_CLOSE:
210 if (plid) {
211 ie_len += 2;
212 include_plid = true;
214 ie_len += 2; /* reason code */
215 break;
216 default:
217 return -EINVAL;
220 if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
221 return -ENOMEM;
223 pos = skb_put(skb, 2 + ie_len);
224 *pos++ = WLAN_EID_PEER_MGMT;
225 *pos++ = ie_len;
226 memcpy(pos, &peering_proto, 2);
227 pos += 2;
228 memcpy(pos, &llid, 2);
229 pos += 2;
230 if (include_plid) {
231 memcpy(pos, &plid, 2);
232 pos += 2;
234 if (action == WLAN_SP_MESH_PEERING_CLOSE) {
235 memcpy(pos, &reason, 2);
236 pos += 2;
238 if (mesh_add_vendor_ies(skb, sdata))
239 return -1;
241 ieee80211_tx_skb(sdata, skb);
242 return 0;
245 void mesh_neighbour_update(u8 *hw_addr, u32 rates,
246 struct ieee80211_sub_if_data *sdata,
247 struct ieee802_11_elems *elems)
249 struct ieee80211_local *local = sdata->local;
250 struct sta_info *sta;
252 rcu_read_lock();
254 sta = sta_info_get(sdata, hw_addr);
255 if (!sta) {
256 rcu_read_unlock();
257 /* Userspace handles peer allocation when security is enabled
258 * */
259 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
260 cfg80211_notify_new_peer_candidate(sdata->dev, hw_addr,
261 elems->ie_start, elems->total_len,
262 GFP_KERNEL);
263 else
264 sta = mesh_plink_alloc(sdata, hw_addr, rates);
265 if (!sta)
266 return;
267 if (sta_info_insert_rcu(sta)) {
268 rcu_read_unlock();
269 return;
273 sta->last_rx = jiffies;
274 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
275 if (mesh_peer_accepts_plinks(elems) &&
276 sta->plink_state == NL80211_PLINK_LISTEN &&
277 sdata->u.mesh.accepting_plinks &&
278 sdata->u.mesh.mshcfg.auto_open_plinks)
279 mesh_plink_open(sta);
281 rcu_read_unlock();
284 static void mesh_plink_timer(unsigned long data)
286 struct sta_info *sta;
287 __le16 llid, plid, reason;
288 struct ieee80211_sub_if_data *sdata;
291 * This STA is valid because sta_info_destroy() will
292 * del_timer_sync() this timer after having made sure
293 * it cannot be readded (by deleting the plink.)
295 sta = (struct sta_info *) data;
297 if (sta->sdata->local->quiescing) {
298 sta->plink_timer_was_running = true;
299 return;
302 spin_lock_bh(&sta->lock);
303 if (sta->ignore_plink_timer) {
304 sta->ignore_plink_timer = false;
305 spin_unlock_bh(&sta->lock);
306 return;
308 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
309 sta->sta.addr, sta->plink_state);
310 reason = 0;
311 llid = sta->llid;
312 plid = sta->plid;
313 sdata = sta->sdata;
315 switch (sta->plink_state) {
316 case NL80211_PLINK_OPN_RCVD:
317 case NL80211_PLINK_OPN_SNT:
318 /* retry timer */
319 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
320 u32 rand;
321 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
322 sta->sta.addr, sta->plink_retries,
323 sta->plink_timeout);
324 get_random_bytes(&rand, sizeof(u32));
325 sta->plink_timeout = sta->plink_timeout +
326 rand % sta->plink_timeout;
327 ++sta->plink_retries;
328 mod_plink_timer(sta, sta->plink_timeout);
329 spin_unlock_bh(&sta->lock);
330 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
331 sta->sta.addr, llid, 0, 0);
332 break;
334 reason = cpu_to_le16(WLAN_REASON_MESH_MAX_RETRIES);
335 /* fall through on else */
336 case NL80211_PLINK_CNF_RCVD:
337 /* confirm timer */
338 if (!reason)
339 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIRM_TIMEOUT);
340 sta->plink_state = NL80211_PLINK_HOLDING;
341 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
342 spin_unlock_bh(&sta->lock);
343 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
344 sta->sta.addr, llid, plid, reason);
345 break;
346 case NL80211_PLINK_HOLDING:
347 /* holding timer */
348 del_timer(&sta->plink_timer);
349 mesh_plink_fsm_restart(sta);
350 spin_unlock_bh(&sta->lock);
351 break;
352 default:
353 spin_unlock_bh(&sta->lock);
354 break;
358 #ifdef CONFIG_PM
359 void mesh_plink_quiesce(struct sta_info *sta)
361 if (del_timer_sync(&sta->plink_timer))
362 sta->plink_timer_was_running = true;
365 void mesh_plink_restart(struct sta_info *sta)
367 if (sta->plink_timer_was_running) {
368 add_timer(&sta->plink_timer);
369 sta->plink_timer_was_running = false;
372 #endif
374 static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
376 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
377 sta->plink_timer.data = (unsigned long) sta;
378 sta->plink_timer.function = mesh_plink_timer;
379 sta->plink_timeout = timeout;
380 add_timer(&sta->plink_timer);
383 int mesh_plink_open(struct sta_info *sta)
385 __le16 llid;
386 struct ieee80211_sub_if_data *sdata = sta->sdata;
388 if (!test_sta_flag(sta, WLAN_STA_AUTH))
389 return -EPERM;
391 spin_lock_bh(&sta->lock);
392 get_random_bytes(&llid, 2);
393 sta->llid = llid;
394 if (sta->plink_state != NL80211_PLINK_LISTEN) {
395 spin_unlock_bh(&sta->lock);
396 return -EBUSY;
398 sta->plink_state = NL80211_PLINK_OPN_SNT;
399 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
400 spin_unlock_bh(&sta->lock);
401 mpl_dbg("Mesh plink: starting establishment with %pM\n",
402 sta->sta.addr);
404 return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
405 sta->sta.addr, llid, 0, 0);
408 void mesh_plink_block(struct sta_info *sta)
410 struct ieee80211_sub_if_data *sdata = sta->sdata;
411 bool deactivated;
413 spin_lock_bh(&sta->lock);
414 deactivated = __mesh_plink_deactivate(sta);
415 sta->plink_state = NL80211_PLINK_BLOCKED;
416 spin_unlock_bh(&sta->lock);
418 if (deactivated)
419 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
423 void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
424 size_t len, struct ieee80211_rx_status *rx_status)
426 struct ieee80211_local *local = sdata->local;
427 struct ieee802_11_elems elems;
428 struct sta_info *sta;
429 enum plink_event event;
430 enum ieee80211_self_protected_actioncode ftype;
431 size_t baselen;
432 bool deactivated, matches_local = true;
433 u8 ie_len;
434 u8 *baseaddr;
435 __le16 plid, llid, reason;
436 #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
437 static const char *mplstates[] = {
438 [NL80211_PLINK_LISTEN] = "LISTEN",
439 [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
440 [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
441 [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
442 [NL80211_PLINK_ESTAB] = "ESTAB",
443 [NL80211_PLINK_HOLDING] = "HOLDING",
444 [NL80211_PLINK_BLOCKED] = "BLOCKED"
446 #endif
448 /* need action_code, aux */
449 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
450 return;
452 if (is_multicast_ether_addr(mgmt->da)) {
453 mpl_dbg("Mesh plink: ignore frame from multicast address");
454 return;
457 baseaddr = mgmt->u.action.u.self_prot.variable;
458 baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
459 if (mgmt->u.action.u.self_prot.action_code ==
460 WLAN_SP_MESH_PEERING_CONFIRM) {
461 baseaddr += 4;
462 baselen += 4;
464 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
465 if (!elems.peering) {
466 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
467 return;
469 if (elems.rsn_len &&
470 sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
471 mpl_dbg("Mesh plink: can't establish link with secure peer\n");
472 return;
475 ftype = mgmt->u.action.u.self_prot.action_code;
476 ie_len = elems.peering_len;
477 if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
478 (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
479 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
480 && ie_len != 8)) {
481 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
482 ftype, ie_len);
483 return;
486 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
487 (!elems.mesh_id || !elems.mesh_config)) {
488 mpl_dbg("Mesh plink: missing necessary ie\n");
489 return;
491 /* Note the lines below are correct, the llid in the frame is the plid
492 * from the point of view of this host.
494 memcpy(&plid, PLINK_GET_LLID(elems.peering), 2);
495 if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
496 (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
497 memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
499 rcu_read_lock();
501 sta = sta_info_get(sdata, mgmt->sa);
502 if (!sta && ftype != WLAN_SP_MESH_PEERING_OPEN) {
503 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
504 rcu_read_unlock();
505 return;
508 if (sta && !test_sta_flag(sta, WLAN_STA_AUTH)) {
509 mpl_dbg("Mesh plink: Action frame from non-authed peer\n");
510 rcu_read_unlock();
511 return;
514 if (sta && sta->plink_state == NL80211_PLINK_BLOCKED) {
515 rcu_read_unlock();
516 return;
519 /* Now we will figure out the appropriate event... */
520 event = PLINK_UNDEFINED;
521 if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
522 (!mesh_matches_local(&elems, sdata))) {
523 matches_local = false;
524 switch (ftype) {
525 case WLAN_SP_MESH_PEERING_OPEN:
526 event = OPN_RJCT;
527 break;
528 case WLAN_SP_MESH_PEERING_CONFIRM:
529 event = CNF_RJCT;
530 break;
531 default:
532 break;
536 if (!sta && !matches_local) {
537 rcu_read_unlock();
538 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
539 llid = 0;
540 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
541 mgmt->sa, llid, plid, reason);
542 return;
543 } else if (!sta) {
544 /* ftype == WLAN_SP_MESH_PEERING_OPEN */
545 u32 rates;
547 rcu_read_unlock();
549 if (!mesh_plink_free_count(sdata)) {
550 mpl_dbg("Mesh plink error: no more free plinks\n");
551 return;
554 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
555 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
556 if (!sta) {
557 mpl_dbg("Mesh plink error: plink table full\n");
558 return;
560 if (sta_info_insert_rcu(sta)) {
561 rcu_read_unlock();
562 return;
564 event = OPN_ACPT;
565 spin_lock_bh(&sta->lock);
566 } else if (matches_local) {
567 spin_lock_bh(&sta->lock);
568 switch (ftype) {
569 case WLAN_SP_MESH_PEERING_OPEN:
570 if (!mesh_plink_free_count(sdata) ||
571 (sta->plid && sta->plid != plid))
572 event = OPN_IGNR;
573 else
574 event = OPN_ACPT;
575 break;
576 case WLAN_SP_MESH_PEERING_CONFIRM:
577 if (!mesh_plink_free_count(sdata) ||
578 (sta->llid != llid || sta->plid != plid))
579 event = CNF_IGNR;
580 else
581 event = CNF_ACPT;
582 break;
583 case WLAN_SP_MESH_PEERING_CLOSE:
584 if (sta->plink_state == NL80211_PLINK_ESTAB)
585 /* Do not check for llid or plid. This does not
586 * follow the standard but since multiple plinks
587 * per sta are not supported, it is necessary in
588 * order to avoid a livelock when MP A sees an
589 * establish peer link to MP B but MP B does not
590 * see it. This can be caused by a timeout in
591 * B's peer link establishment or B beign
592 * restarted.
594 event = CLS_ACPT;
595 else if (sta->plid != plid)
596 event = CLS_IGNR;
597 else if (ie_len == 7 && sta->llid != llid)
598 event = CLS_IGNR;
599 else
600 event = CLS_ACPT;
601 break;
602 default:
603 mpl_dbg("Mesh plink: unknown frame subtype\n");
604 spin_unlock_bh(&sta->lock);
605 rcu_read_unlock();
606 return;
608 } else {
609 spin_lock_bh(&sta->lock);
612 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
613 mgmt->sa, mplstates[sta->plink_state],
614 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
615 event);
616 reason = 0;
617 switch (sta->plink_state) {
618 /* spin_unlock as soon as state is updated at each case */
619 case NL80211_PLINK_LISTEN:
620 switch (event) {
621 case CLS_ACPT:
622 mesh_plink_fsm_restart(sta);
623 spin_unlock_bh(&sta->lock);
624 break;
625 case OPN_ACPT:
626 sta->plink_state = NL80211_PLINK_OPN_RCVD;
627 sta->plid = plid;
628 get_random_bytes(&llid, 2);
629 sta->llid = llid;
630 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
631 spin_unlock_bh(&sta->lock);
632 mesh_plink_frame_tx(sdata,
633 WLAN_SP_MESH_PEERING_OPEN,
634 sta->sta.addr, llid, 0, 0);
635 mesh_plink_frame_tx(sdata,
636 WLAN_SP_MESH_PEERING_CONFIRM,
637 sta->sta.addr, llid, plid, 0);
638 break;
639 default:
640 spin_unlock_bh(&sta->lock);
641 break;
643 break;
645 case NL80211_PLINK_OPN_SNT:
646 switch (event) {
647 case OPN_RJCT:
648 case CNF_RJCT:
649 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
650 case CLS_ACPT:
651 if (!reason)
652 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
653 sta->reason = reason;
654 sta->plink_state = NL80211_PLINK_HOLDING;
655 if (!mod_plink_timer(sta,
656 dot11MeshHoldingTimeout(sdata)))
657 sta->ignore_plink_timer = true;
659 llid = sta->llid;
660 spin_unlock_bh(&sta->lock);
661 mesh_plink_frame_tx(sdata,
662 WLAN_SP_MESH_PEERING_CLOSE,
663 sta->sta.addr, llid, plid, reason);
664 break;
665 case OPN_ACPT:
666 /* retry timer is left untouched */
667 sta->plink_state = NL80211_PLINK_OPN_RCVD;
668 sta->plid = plid;
669 llid = sta->llid;
670 spin_unlock_bh(&sta->lock);
671 mesh_plink_frame_tx(sdata,
672 WLAN_SP_MESH_PEERING_CONFIRM,
673 sta->sta.addr, llid, plid, 0);
674 break;
675 case CNF_ACPT:
676 sta->plink_state = NL80211_PLINK_CNF_RCVD;
677 if (!mod_plink_timer(sta,
678 dot11MeshConfirmTimeout(sdata)))
679 sta->ignore_plink_timer = true;
681 spin_unlock_bh(&sta->lock);
682 break;
683 default:
684 spin_unlock_bh(&sta->lock);
685 break;
687 break;
689 case NL80211_PLINK_OPN_RCVD:
690 switch (event) {
691 case OPN_RJCT:
692 case CNF_RJCT:
693 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
694 case CLS_ACPT:
695 if (!reason)
696 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
697 sta->reason = reason;
698 sta->plink_state = NL80211_PLINK_HOLDING;
699 if (!mod_plink_timer(sta,
700 dot11MeshHoldingTimeout(sdata)))
701 sta->ignore_plink_timer = true;
703 llid = sta->llid;
704 spin_unlock_bh(&sta->lock);
705 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
706 sta->sta.addr, llid, plid, reason);
707 break;
708 case OPN_ACPT:
709 llid = sta->llid;
710 spin_unlock_bh(&sta->lock);
711 mesh_plink_frame_tx(sdata,
712 WLAN_SP_MESH_PEERING_CONFIRM,
713 sta->sta.addr, llid, plid, 0);
714 break;
715 case CNF_ACPT:
716 del_timer(&sta->plink_timer);
717 sta->plink_state = NL80211_PLINK_ESTAB;
718 spin_unlock_bh(&sta->lock);
719 mesh_plink_inc_estab_count(sdata);
720 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
721 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
722 sta->sta.addr);
723 break;
724 default:
725 spin_unlock_bh(&sta->lock);
726 break;
728 break;
730 case NL80211_PLINK_CNF_RCVD:
731 switch (event) {
732 case OPN_RJCT:
733 case CNF_RJCT:
734 reason = cpu_to_le16(WLAN_REASON_MESH_CONFIG);
735 case CLS_ACPT:
736 if (!reason)
737 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
738 sta->reason = reason;
739 sta->plink_state = NL80211_PLINK_HOLDING;
740 if (!mod_plink_timer(sta,
741 dot11MeshHoldingTimeout(sdata)))
742 sta->ignore_plink_timer = true;
744 llid = sta->llid;
745 spin_unlock_bh(&sta->lock);
746 mesh_plink_frame_tx(sdata,
747 WLAN_SP_MESH_PEERING_CLOSE,
748 sta->sta.addr, llid, plid, reason);
749 break;
750 case OPN_ACPT:
751 del_timer(&sta->plink_timer);
752 sta->plink_state = NL80211_PLINK_ESTAB;
753 spin_unlock_bh(&sta->lock);
754 mesh_plink_inc_estab_count(sdata);
755 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
756 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
757 sta->sta.addr);
758 mesh_plink_frame_tx(sdata,
759 WLAN_SP_MESH_PEERING_CONFIRM,
760 sta->sta.addr, llid, plid, 0);
761 break;
762 default:
763 spin_unlock_bh(&sta->lock);
764 break;
766 break;
768 case NL80211_PLINK_ESTAB:
769 switch (event) {
770 case CLS_ACPT:
771 reason = cpu_to_le16(WLAN_REASON_MESH_CLOSE);
772 sta->reason = reason;
773 deactivated = __mesh_plink_deactivate(sta);
774 sta->plink_state = NL80211_PLINK_HOLDING;
775 llid = sta->llid;
776 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
777 spin_unlock_bh(&sta->lock);
778 if (deactivated)
779 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
780 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
781 sta->sta.addr, llid, plid, reason);
782 break;
783 case OPN_ACPT:
784 llid = sta->llid;
785 spin_unlock_bh(&sta->lock);
786 mesh_plink_frame_tx(sdata,
787 WLAN_SP_MESH_PEERING_CONFIRM,
788 sta->sta.addr, llid, plid, 0);
789 break;
790 default:
791 spin_unlock_bh(&sta->lock);
792 break;
794 break;
795 case NL80211_PLINK_HOLDING:
796 switch (event) {
797 case CLS_ACPT:
798 if (del_timer(&sta->plink_timer))
799 sta->ignore_plink_timer = 1;
800 mesh_plink_fsm_restart(sta);
801 spin_unlock_bh(&sta->lock);
802 break;
803 case OPN_ACPT:
804 case CNF_ACPT:
805 case OPN_RJCT:
806 case CNF_RJCT:
807 llid = sta->llid;
808 reason = sta->reason;
809 spin_unlock_bh(&sta->lock);
810 mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
811 sta->sta.addr, llid, plid, reason);
812 break;
813 default:
814 spin_unlock_bh(&sta->lock);
816 break;
817 default:
818 /* should not get here, PLINK_BLOCKED is dealt with at the
819 * beginning of the function
821 spin_unlock_bh(&sta->lock);
822 break;
825 rcu_read_unlock();