mesh_plink.c 19 KB

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