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