mesh_plink.c 19 KB

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