Merge branch 'bkl/procfs' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic...
[linux-2.6-block.git] / net / mac80211 / mesh_plink.c
CommitLineData
c3896d2c 1/*
264d9b7d 2 * Copyright (c) 2008, 2009 open80211s Ltd.
c3896d2c
LCC
3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
5a0e3ad6 9#include <linux/gfp.h>
902acc78
JB
10#include <linux/kernel.h>
11#include <linux/random.h>
c3896d2c 12#include "ieee80211_i.h"
2c8dccc7 13#include "rate.h"
c3896d2c 14#include "mesh.h"
c3896d2c
LCC
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
0938393f
RP
22#define PLINK_GET_LLID(p) (p + 4)
23#define PLINK_GET_PLID(p) (p + 6)
c3896d2c
LCC
24
25#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
26 jiffies + HZ * t / 1000))
27
28/* Peer link cancel reasons, all subject to ANA approval */
29#define MESH_LINK_CANCELLED 2
30#define MESH_MAX_NEIGHBORS 3
31#define MESH_CAPABILITY_POLICY_VIOLATION 4
32#define MESH_CLOSE_RCVD 5
33#define MESH_MAX_RETRIES 6
34#define MESH_CONFIRM_TIMEOUT 7
35#define MESH_SECURITY_ROLE_NEGOTIATION_DIFFERS 8
36#define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9
37#define MESH_SECURITY_FAILED_VERIFICATION 10
38
472dbc45
JB
39#define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
40#define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
41#define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
42#define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
43#define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
c3896d2c
LCC
44
45enum plink_frame_type {
46 PLINK_OPEN = 0,
47 PLINK_CONFIRM,
48 PLINK_CLOSE
49};
50
51enum plink_event {
52 PLINK_UNDEFINED,
53 OPN_ACPT,
54 OPN_RJCT,
55 OPN_IGNR,
56 CNF_ACPT,
57 CNF_RJCT,
58 CNF_IGNR,
59 CLS_ACPT,
60 CLS_IGNR
61};
62
63static inline
64void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
65{
472dbc45 66 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
d0709a65 67 mesh_accept_plinks_update(sdata);
8f2fda95 68 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
c3896d2c
LCC
69}
70
71static inline
72void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
73{
472dbc45 74 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
d0709a65 75 mesh_accept_plinks_update(sdata);
8f2fda95 76 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
c3896d2c
LCC
77}
78
79/**
80 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
81 *
23c7a29c 82 * @sta: mesh peer link to restart
c3896d2c 83 *
07346f81 84 * Locking: this function must be called holding sta->lock
c3896d2c
LCC
85 */
86static inline void mesh_plink_fsm_restart(struct sta_info *sta)
87{
b4e08ea1 88 sta->plink_state = PLINK_LISTEN;
37659ff8
LCC
89 sta->llid = sta->plid = sta->reason = 0;
90 sta->plink_retries = 0;
c3896d2c
LCC
91}
92
93e5deb1
JB
93/*
94 * NOTE: This is just an alias for sta_info_alloc(), see notes
95 * on it in the lifecycle management section!
96 */
03e4497e 97static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
881d948c 98 u8 *hw_addr, u32 rates)
c3896d2c 99{
d0709a65 100 struct ieee80211_local *local = sdata->local;
c3896d2c
LCC
101 struct sta_info *sta;
102
c3896d2c 103 if (local->num_sta >= MESH_MAX_PLINKS)
73651ee6 104 return NULL;
c3896d2c 105
34e89507 106 sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
73651ee6
JB
107 if (!sta)
108 return NULL;
c3896d2c 109
07346f81 110 sta->flags = WLAN_STA_AUTHORIZED;
323ce79a 111 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
b973c31a 112 rate_control_rate_init(sta);
c3896d2c
LCC
113
114 return sta;
115}
116
117/**
42096b63 118 * mesh_plink_deactivate - deactivate mesh peer link
c3896d2c
LCC
119 *
120 * @sta: mesh peer link to deactivate
121 *
122 * All mesh paths with this peer as next hop will be flushed
123 *
07346f81 124 * Locking: the caller must hold sta->lock
c3896d2c 125 */
902acc78 126static void __mesh_plink_deactivate(struct sta_info *sta)
c3896d2c 127{
d0709a65
JB
128 struct ieee80211_sub_if_data *sdata = sta->sdata;
129
b4e08ea1 130 if (sta->plink_state == PLINK_ESTAB)
c3896d2c 131 mesh_plink_dec_estab_count(sdata);
b4e08ea1 132 sta->plink_state = PLINK_BLOCKED;
c3896d2c
LCC
133 mesh_path_flush_by_nexthop(sta);
134}
135
902acc78
JB
136/**
137 * __mesh_plink_deactivate - deactivate mesh peer link
138 *
139 * @sta: mesh peer link to deactivate
140 *
141 * All mesh paths with this peer as next hop will be flushed
142 */
143void mesh_plink_deactivate(struct sta_info *sta)
144{
07346f81 145 spin_lock_bh(&sta->lock);
902acc78 146 __mesh_plink_deactivate(sta);
07346f81 147 spin_unlock_bh(&sta->lock);
902acc78
JB
148}
149
f698d856 150static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
c3896d2c
LCC
151 enum plink_frame_type action, u8 *da, __le16 llid, __le16 plid,
152 __le16 reason) {
f698d856 153 struct ieee80211_local *local = sdata->local;
c3896d2c
LCC
154 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
155 struct ieee80211_mgmt *mgmt;
156 bool include_plid = false;
0938393f 157 static const u8 meshpeeringproto[] = { 0x00, 0x0F, 0xAC, 0x2A };
c3896d2c
LCC
158 u8 *pos;
159 int ie_len;
160
161 if (!skb)
162 return -1;
163 skb_reserve(skb, local->hw.extra_tx_headroom);
164 /* 25 is the size of the common mgmt part (24) plus the size of the
165 * common action part (1)
166 */
167 mgmt = (struct ieee80211_mgmt *)
168 skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
169 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
e7827a70
HH
170 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
171 IEEE80211_STYPE_ACTION);
c3896d2c 172 memcpy(mgmt->da, da, ETH_ALEN);
47846c9b 173 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
c3896d2c 174 /* BSSID is left zeroed, wildcard value */
0938393f 175 mgmt->u.action.category = MESH_PLINK_CATEGORY;
c3896d2c
LCC
176 mgmt->u.action.u.plink_action.action_code = action;
177
178 if (action == PLINK_CLOSE)
179 mgmt->u.action.u.plink_action.aux = reason;
180 else {
181 mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
182 if (action == PLINK_CONFIRM) {
183 pos = skb_put(skb, 4);
184 /* two-byte status code followed by two-byte AID */
77fa76bb
RP
185 memset(pos, 0, 2);
186 memcpy(pos + 2, &plid, 2);
c3896d2c 187 }
f698d856 188 mesh_mgmt_ies_add(skb, sdata);
c3896d2c
LCC
189 }
190
191 /* Add Peer Link Management element */
192 switch (action) {
193 case PLINK_OPEN:
0938393f 194 ie_len = 6;
c3896d2c
LCC
195 break;
196 case PLINK_CONFIRM:
0938393f 197 ie_len = 8;
c3896d2c
LCC
198 include_plid = true;
199 break;
200 case PLINK_CLOSE:
201 default:
202 if (!plid)
0938393f 203 ie_len = 8;
c3896d2c 204 else {
0938393f 205 ie_len = 10;
c3896d2c
LCC
206 include_plid = true;
207 }
208 break;
209 }
210
211 pos = skb_put(skb, 2 + ie_len);
212 *pos++ = WLAN_EID_PEER_LINK;
213 *pos++ = ie_len;
0938393f
RP
214 memcpy(pos, meshpeeringproto, sizeof(meshpeeringproto));
215 pos += 4;
c3896d2c
LCC
216 memcpy(pos, &llid, 2);
217 if (include_plid) {
218 pos += 2;
219 memcpy(pos, &plid, 2);
220 }
221 if (action == PLINK_CLOSE) {
222 pos += 2;
223 memcpy(pos, &reason, 2);
224 }
225
62ae67be 226 ieee80211_tx_skb(sdata, skb);
c3896d2c
LCC
227 return 0;
228}
229
881d948c 230void mesh_neighbour_update(u8 *hw_addr, u32 rates, struct ieee80211_sub_if_data *sdata,
c3896d2c
LCC
231 bool peer_accepting_plinks)
232{
f698d856 233 struct ieee80211_local *local = sdata->local;
c3896d2c
LCC
234 struct sta_info *sta;
235
d0709a65
JB
236 rcu_read_lock();
237
abe60632 238 sta = sta_info_get(sdata, hw_addr);
c3896d2c 239 if (!sta) {
34e89507
JB
240 rcu_read_unlock();
241
03e4497e 242 sta = mesh_plink_alloc(sdata, hw_addr, rates);
34e89507 243 if (!sta)
73651ee6 244 return;
34e89507 245 if (sta_info_insert_rcu(sta)) {
d0709a65 246 rcu_read_unlock();
c3896d2c 247 return;
d0709a65 248 }
c3896d2c
LCC
249 }
250
251 sta->last_rx = jiffies;
323ce79a 252 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
b4e08ea1 253 if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
472dbc45
JB
254 sdata->u.mesh.accepting_plinks &&
255 sdata->u.mesh.mshcfg.auto_open_plinks)
c3896d2c
LCC
256 mesh_plink_open(sta);
257
d0709a65 258 rcu_read_unlock();
c3896d2c
LCC
259}
260
261static void mesh_plink_timer(unsigned long data)
262{
263 struct sta_info *sta;
264 __le16 llid, plid, reason;
c3896d2c 265 struct ieee80211_sub_if_data *sdata;
c3896d2c 266
d0709a65
JB
267 /*
268 * This STA is valid because sta_info_destroy() will
269 * del_timer_sync() this timer after having made sure
270 * it cannot be readded (by deleting the plink.)
271 */
c3896d2c
LCC
272 sta = (struct sta_info *) data;
273
5bb644a0
JB
274 if (sta->sdata->local->quiescing) {
275 sta->plink_timer_was_running = true;
276 return;
277 }
278
07346f81 279 spin_lock_bh(&sta->lock);
c3896d2c
LCC
280 if (sta->ignore_plink_timer) {
281 sta->ignore_plink_timer = false;
07346f81 282 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
283 return;
284 }
0c68ae26
JB
285 mpl_dbg("Mesh plink timer for %pM fired on state %d\n",
286 sta->sta.addr, sta->plink_state);
c3896d2c
LCC
287 reason = 0;
288 llid = sta->llid;
289 plid = sta->plid;
d0709a65 290 sdata = sta->sdata;
c3896d2c
LCC
291
292 switch (sta->plink_state) {
b4e08ea1
LCC
293 case PLINK_OPN_RCVD:
294 case PLINK_OPN_SNT:
c3896d2c
LCC
295 /* retry timer */
296 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
297 u32 rand;
0c68ae26
JB
298 mpl_dbg("Mesh plink for %pM (retry, timeout): %d %d\n",
299 sta->sta.addr, sta->plink_retries,
300 sta->plink_timeout);
c3896d2c
LCC
301 get_random_bytes(&rand, sizeof(u32));
302 sta->plink_timeout = sta->plink_timeout +
303 rand % sta->plink_timeout;
304 ++sta->plink_retries;
d0709a65 305 mod_plink_timer(sta, sta->plink_timeout);
07346f81 306 spin_unlock_bh(&sta->lock);
17741cdc 307 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
c3896d2c
LCC
308 0, 0);
309 break;
310 }
311 reason = cpu_to_le16(MESH_MAX_RETRIES);
312 /* fall through on else */
b4e08ea1 313 case PLINK_CNF_RCVD:
c3896d2c
LCC
314 /* confirm timer */
315 if (!reason)
316 reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
b4e08ea1 317 sta->plink_state = PLINK_HOLDING;
d0709a65 318 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
07346f81 319 spin_unlock_bh(&sta->lock);
17741cdc 320 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, plid,
c3896d2c
LCC
321 reason);
322 break;
b4e08ea1 323 case PLINK_HOLDING:
c3896d2c 324 /* holding timer */
d0709a65 325 del_timer(&sta->plink_timer);
c3896d2c 326 mesh_plink_fsm_restart(sta);
07346f81 327 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
328 break;
329 default:
07346f81 330 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
331 break;
332 }
c3896d2c
LCC
333}
334
5bb644a0
JB
335#ifdef CONFIG_PM
336void mesh_plink_quiesce(struct sta_info *sta)
337{
338 if (del_timer_sync(&sta->plink_timer))
339 sta->plink_timer_was_running = true;
340}
341
342void mesh_plink_restart(struct sta_info *sta)
343{
344 if (sta->plink_timer_was_running) {
345 add_timer(&sta->plink_timer);
346 sta->plink_timer_was_running = false;
347 }
348}
349#endif
350
c3896d2c
LCC
351static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
352{
353 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
354 sta->plink_timer.data = (unsigned long) sta;
355 sta->plink_timer.function = mesh_plink_timer;
356 sta->plink_timeout = timeout;
c3896d2c
LCC
357 add_timer(&sta->plink_timer);
358}
359
360int mesh_plink_open(struct sta_info *sta)
361{
362 __le16 llid;
d0709a65 363 struct ieee80211_sub_if_data *sdata = sta->sdata;
c3896d2c 364
07346f81 365 spin_lock_bh(&sta->lock);
c3896d2c
LCC
366 get_random_bytes(&llid, 2);
367 sta->llid = llid;
b4e08ea1 368 if (sta->plink_state != PLINK_LISTEN) {
07346f81 369 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
370 return -EBUSY;
371 }
b4e08ea1 372 sta->plink_state = PLINK_OPN_SNT;
c3896d2c 373 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
07346f81 374 spin_unlock_bh(&sta->lock);
0c68ae26
JB
375 mpl_dbg("Mesh plink: starting establishment with %pM\n",
376 sta->sta.addr);
c3896d2c 377
f698d856 378 return mesh_plink_frame_tx(sdata, PLINK_OPEN,
17741cdc 379 sta->sta.addr, llid, 0, 0);
c3896d2c
LCC
380}
381
382void mesh_plink_block(struct sta_info *sta)
383{
07346f81 384 spin_lock_bh(&sta->lock);
902acc78 385 __mesh_plink_deactivate(sta);
b4e08ea1 386 sta->plink_state = PLINK_BLOCKED;
07346f81 387 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
388}
389
c3896d2c 390
f698d856 391void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
c3896d2c
LCC
392 size_t len, struct ieee80211_rx_status *rx_status)
393{
d0709a65 394 struct ieee80211_local *local = sdata->local;
c3896d2c
LCC
395 struct ieee802_11_elems elems;
396 struct sta_info *sta;
397 enum plink_event event;
398 enum plink_frame_type ftype;
399 size_t baselen;
400 u8 ie_len;
401 u8 *baseaddr;
402 __le16 plid, llid, reason;
1460dd15
RP
403#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
404 static const char *mplstates[] = {
405 [PLINK_LISTEN] = "LISTEN",
406 [PLINK_OPN_SNT] = "OPN-SNT",
407 [PLINK_OPN_RCVD] = "OPN-RCVD",
408 [PLINK_CNF_RCVD] = "CNF_RCVD",
409 [PLINK_ESTAB] = "ESTAB",
410 [PLINK_HOLDING] = "HOLDING",
411 [PLINK_BLOCKED] = "BLOCKED"
412 };
413#endif
c3896d2c 414
9c80d3dc
JB
415 /* need action_code, aux */
416 if (len < IEEE80211_MIN_ACTION_SIZE + 3)
417 return;
418
c3896d2c
LCC
419 if (is_multicast_ether_addr(mgmt->da)) {
420 mpl_dbg("Mesh plink: ignore frame from multicast address");
421 return;
422 }
423
424 baseaddr = mgmt->u.action.u.plink_action.variable;
425 baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
426 if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
427 baseaddr += 4;
70bdb6b2 428 baselen += 4;
c3896d2c
LCC
429 }
430 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
431 if (!elems.peer_link) {
432 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
433 return;
434 }
435
0938393f 436 ftype = mgmt->u.action.u.plink_action.action_code;
c3896d2c 437 ie_len = elems.peer_link_len;
0938393f
RP
438 if ((ftype == PLINK_OPEN && ie_len != 6) ||
439 (ftype == PLINK_CONFIRM && ie_len != 8) ||
440 (ftype == PLINK_CLOSE && ie_len != 8 && ie_len != 10)) {
441 mpl_dbg("Mesh plink: incorrect plink ie length %d %d\n",
442 ftype, ie_len);
c3896d2c
LCC
443 return;
444 }
445
446 if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
447 mpl_dbg("Mesh plink: missing necessary ie\n");
448 return;
449 }
450 /* Note the lines below are correct, the llid in the frame is the plid
451 * from the point of view of this host.
452 */
453 memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
0938393f 454 if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 10))
c3896d2c
LCC
455 memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
456
d0709a65
JB
457 rcu_read_lock();
458
abe60632 459 sta = sta_info_get(sdata, mgmt->sa);
c3896d2c
LCC
460 if (!sta && ftype != PLINK_OPEN) {
461 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
d0709a65 462 rcu_read_unlock();
c3896d2c
LCC
463 return;
464 }
465
b4e08ea1 466 if (sta && sta->plink_state == PLINK_BLOCKED) {
d0709a65 467 rcu_read_unlock();
c3896d2c
LCC
468 return;
469 }
470
471 /* Now we will figure out the appropriate event... */
472 event = PLINK_UNDEFINED;
f698d856 473 if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, sdata))) {
c3896d2c
LCC
474 switch (ftype) {
475 case PLINK_OPEN:
476 event = OPN_RJCT;
477 break;
478 case PLINK_CONFIRM:
479 event = CNF_RJCT;
480 break;
481 case PLINK_CLOSE:
482 /* avoid warning */
483 break;
484 }
07346f81 485 spin_lock_bh(&sta->lock);
c3896d2c
LCC
486 } else if (!sta) {
487 /* ftype == PLINK_OPEN */
881d948c 488 u32 rates;
34e89507
JB
489
490 rcu_read_unlock();
491
c3896d2c
LCC
492 if (!mesh_plink_free_count(sdata)) {
493 mpl_dbg("Mesh plink error: no more free plinks\n");
494 return;
495 }
496
497 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
03e4497e 498 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
73651ee6 499 if (!sta) {
c3896d2c
LCC
500 mpl_dbg("Mesh plink error: plink table full\n");
501 return;
502 }
34e89507 503 if (sta_info_insert_rcu(sta)) {
73651ee6
JB
504 rcu_read_unlock();
505 return;
506 }
c3896d2c 507 event = OPN_ACPT;
07346f81 508 spin_lock_bh(&sta->lock);
c3896d2c 509 } else {
07346f81 510 spin_lock_bh(&sta->lock);
c3896d2c
LCC
511 switch (ftype) {
512 case PLINK_OPEN:
513 if (!mesh_plink_free_count(sdata) ||
d0709a65 514 (sta->plid && sta->plid != plid))
c3896d2c
LCC
515 event = OPN_IGNR;
516 else
517 event = OPN_ACPT;
518 break;
519 case PLINK_CONFIRM:
520 if (!mesh_plink_free_count(sdata) ||
d0709a65 521 (sta->llid != llid || sta->plid != plid))
c3896d2c
LCC
522 event = CNF_IGNR;
523 else
524 event = CNF_ACPT;
525 break;
526 case PLINK_CLOSE:
b4e08ea1 527 if (sta->plink_state == PLINK_ESTAB)
c3896d2c
LCC
528 /* Do not check for llid or plid. This does not
529 * follow the standard but since multiple plinks
530 * per sta are not supported, it is necessary in
531 * order to avoid a livelock when MP A sees an
532 * establish peer link to MP B but MP B does not
533 * see it. This can be caused by a timeout in
534 * B's peer link establishment or B beign
535 * restarted.
536 */
537 event = CLS_ACPT;
538 else if (sta->plid != plid)
539 event = CLS_IGNR;
540 else if (ie_len == 7 && sta->llid != llid)
541 event = CLS_IGNR;
542 else
543 event = CLS_ACPT;
544 break;
545 default:
546 mpl_dbg("Mesh plink: unknown frame subtype\n");
07346f81 547 spin_unlock_bh(&sta->lock);
d0709a65 548 rcu_read_unlock();
c3896d2c
LCC
549 return;
550 }
551 }
552
1460dd15
RP
553 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
554 mgmt->sa, mplstates[sta->plink_state],
0c68ae26
JB
555 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
556 event);
c3896d2c
LCC
557 reason = 0;
558 switch (sta->plink_state) {
559 /* spin_unlock as soon as state is updated at each case */
b4e08ea1 560 case PLINK_LISTEN:
c3896d2c
LCC
561 switch (event) {
562 case CLS_ACPT:
563 mesh_plink_fsm_restart(sta);
07346f81 564 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
565 break;
566 case OPN_ACPT:
b4e08ea1 567 sta->plink_state = PLINK_OPN_RCVD;
c3896d2c
LCC
568 sta->plid = plid;
569 get_random_bytes(&llid, 2);
570 sta->llid = llid;
571 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
07346f81 572 spin_unlock_bh(&sta->lock);
17741cdc 573 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
c3896d2c 574 0, 0);
17741cdc 575 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr,
c3896d2c
LCC
576 llid, plid, 0);
577 break;
578 default:
07346f81 579 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
580 break;
581 }
582 break;
583
b4e08ea1 584 case PLINK_OPN_SNT:
c3896d2c
LCC
585 switch (event) {
586 case OPN_RJCT:
587 case CNF_RJCT:
588 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
589 case CLS_ACPT:
590 if (!reason)
591 reason = cpu_to_le16(MESH_CLOSE_RCVD);
592 sta->reason = reason;
b4e08ea1 593 sta->plink_state = PLINK_HOLDING;
c3896d2c
LCC
594 if (!mod_plink_timer(sta,
595 dot11MeshHoldingTimeout(sdata)))
596 sta->ignore_plink_timer = true;
597
598 llid = sta->llid;
07346f81 599 spin_unlock_bh(&sta->lock);
17741cdc 600 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
c3896d2c
LCC
601 plid, reason);
602 break;
603 case OPN_ACPT:
604 /* retry timer is left untouched */
b4e08ea1 605 sta->plink_state = PLINK_OPN_RCVD;
c3896d2c
LCC
606 sta->plid = plid;
607 llid = sta->llid;
07346f81 608 spin_unlock_bh(&sta->lock);
17741cdc 609 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
c3896d2c
LCC
610 plid, 0);
611 break;
612 case CNF_ACPT:
b4e08ea1 613 sta->plink_state = PLINK_CNF_RCVD;
c3896d2c
LCC
614 if (!mod_plink_timer(sta,
615 dot11MeshConfirmTimeout(sdata)))
616 sta->ignore_plink_timer = true;
617
07346f81 618 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
619 break;
620 default:
07346f81 621 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
622 break;
623 }
624 break;
625
b4e08ea1 626 case PLINK_OPN_RCVD:
c3896d2c
LCC
627 switch (event) {
628 case OPN_RJCT:
629 case CNF_RJCT:
630 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
631 case CLS_ACPT:
632 if (!reason)
633 reason = cpu_to_le16(MESH_CLOSE_RCVD);
634 sta->reason = reason;
b4e08ea1 635 sta->plink_state = PLINK_HOLDING;
c3896d2c
LCC
636 if (!mod_plink_timer(sta,
637 dot11MeshHoldingTimeout(sdata)))
638 sta->ignore_plink_timer = true;
639
640 llid = sta->llid;
07346f81 641 spin_unlock_bh(&sta->lock);
17741cdc 642 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
c3896d2c
LCC
643 plid, reason);
644 break;
645 case OPN_ACPT:
646 llid = sta->llid;
07346f81 647 spin_unlock_bh(&sta->lock);
17741cdc 648 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
c3896d2c
LCC
649 plid, 0);
650 break;
651 case CNF_ACPT:
d0709a65 652 del_timer(&sta->plink_timer);
b4e08ea1 653 sta->plink_state = PLINK_ESTAB;
c3896d2c 654 mesh_plink_inc_estab_count(sdata);
07346f81 655 spin_unlock_bh(&sta->lock);
0c68ae26
JB
656 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
657 sta->sta.addr);
c3896d2c
LCC
658 break;
659 default:
07346f81 660 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
661 break;
662 }
663 break;
664
b4e08ea1 665 case PLINK_CNF_RCVD:
c3896d2c
LCC
666 switch (event) {
667 case OPN_RJCT:
668 case CNF_RJCT:
669 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
670 case CLS_ACPT:
671 if (!reason)
672 reason = cpu_to_le16(MESH_CLOSE_RCVD);
673 sta->reason = reason;
b4e08ea1 674 sta->plink_state = PLINK_HOLDING;
c3896d2c
LCC
675 if (!mod_plink_timer(sta,
676 dot11MeshHoldingTimeout(sdata)))
677 sta->ignore_plink_timer = true;
678
679 llid = sta->llid;
07346f81 680 spin_unlock_bh(&sta->lock);
17741cdc 681 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
c3896d2c 682 plid, reason);
ff59dc76 683 break;
c3896d2c 684 case OPN_ACPT:
d0709a65 685 del_timer(&sta->plink_timer);
b4e08ea1 686 sta->plink_state = PLINK_ESTAB;
c3896d2c 687 mesh_plink_inc_estab_count(sdata);
07346f81 688 spin_unlock_bh(&sta->lock);
0c68ae26
JB
689 mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
690 sta->sta.addr);
17741cdc 691 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
c3896d2c
LCC
692 plid, 0);
693 break;
694 default:
07346f81 695 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
696 break;
697 }
698 break;
699
b4e08ea1 700 case PLINK_ESTAB:
c3896d2c
LCC
701 switch (event) {
702 case CLS_ACPT:
703 reason = cpu_to_le16(MESH_CLOSE_RCVD);
704 sta->reason = reason;
902acc78 705 __mesh_plink_deactivate(sta);
b4e08ea1 706 sta->plink_state = PLINK_HOLDING;
c3896d2c 707 llid = sta->llid;
d0709a65 708 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
07346f81 709 spin_unlock_bh(&sta->lock);
17741cdc 710 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
c3896d2c
LCC
711 plid, reason);
712 break;
713 case OPN_ACPT:
714 llid = sta->llid;
07346f81 715 spin_unlock_bh(&sta->lock);
17741cdc 716 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
c3896d2c
LCC
717 plid, 0);
718 break;
719 default:
07346f81 720 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
721 break;
722 }
723 break;
b4e08ea1 724 case PLINK_HOLDING:
c3896d2c
LCC
725 switch (event) {
726 case CLS_ACPT:
d0709a65 727 if (del_timer(&sta->plink_timer))
c3896d2c 728 sta->ignore_plink_timer = 1;
c3896d2c 729 mesh_plink_fsm_restart(sta);
07346f81 730 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
731 break;
732 case OPN_ACPT:
733 case CNF_ACPT:
734 case OPN_RJCT:
735 case CNF_RJCT:
736 llid = sta->llid;
737 reason = sta->reason;
07346f81 738 spin_unlock_bh(&sta->lock);
17741cdc
JB
739 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr,
740 llid, plid, reason);
c3896d2c
LCC
741 break;
742 default:
07346f81 743 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
744 }
745 break;
746 default:
b4e08ea1 747 /* should not get here, PLINK_BLOCKED is dealt with at the
3ad2f3fb 748 * beginning of the function
c3896d2c 749 */
07346f81 750 spin_unlock_bh(&sta->lock);
c3896d2c
LCC
751 break;
752 }
d0709a65
JB
753
754 rcu_read_unlock();
c3896d2c 755}