mesh_plink.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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.sta.mshcfg.dot11MeshMaxRetries)
  35. #define dot11MeshRetryTimeout(s) (s->u.sta.mshcfg.dot11MeshRetryTimeout)
  36. #define dot11MeshConfirmTimeout(s) (s->u.sta.mshcfg.dot11MeshConfirmTimeout)
  37. #define dot11MeshHoldingTimeout(s) (s->u.sta.mshcfg.dot11MeshHoldingTimeout)
  38. #define dot11MeshMaxPeerLinks(s) (s->u.sta.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.sta.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.sta.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->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_sta_tx(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->supp_rates[local->hw.conf.channel->band] = rates;
  219. if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
  220. sdata->u.sta.accepting_plinks &&
  221. sdata->u.sta.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. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  231. DECLARE_MAC_BUF(mac);
  232. #endif
  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. spin_lock_bh(&sta->lock);
  240. if (sta->ignore_plink_timer) {
  241. sta->ignore_plink_timer = false;
  242. spin_unlock_bh(&sta->lock);
  243. return;
  244. }
  245. mpl_dbg("Mesh plink timer for %s fired on state %d\n",
  246. print_mac(mac, sta->addr), sta->plink_state);
  247. reason = 0;
  248. llid = sta->llid;
  249. plid = sta->plid;
  250. sdata = sta->sdata;
  251. switch (sta->plink_state) {
  252. case PLINK_OPN_RCVD:
  253. case PLINK_OPN_SNT:
  254. /* retry timer */
  255. if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
  256. u32 rand;
  257. mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n",
  258. print_mac(mac, sta->addr),
  259. sta->plink_retries, sta->plink_timeout);
  260. get_random_bytes(&rand, sizeof(u32));
  261. sta->plink_timeout = sta->plink_timeout +
  262. rand % sta->plink_timeout;
  263. ++sta->plink_retries;
  264. mod_plink_timer(sta, sta->plink_timeout);
  265. spin_unlock_bh(&sta->lock);
  266. mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->addr, llid,
  267. 0, 0);
  268. break;
  269. }
  270. reason = cpu_to_le16(MESH_MAX_RETRIES);
  271. /* fall through on else */
  272. case PLINK_CNF_RCVD:
  273. /* confirm timer */
  274. if (!reason)
  275. reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
  276. sta->plink_state = PLINK_HOLDING;
  277. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  278. spin_unlock_bh(&sta->lock);
  279. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid, plid,
  280. reason);
  281. break;
  282. case PLINK_HOLDING:
  283. /* holding timer */
  284. del_timer(&sta->plink_timer);
  285. mesh_plink_fsm_restart(sta);
  286. spin_unlock_bh(&sta->lock);
  287. break;
  288. default:
  289. spin_unlock_bh(&sta->lock);
  290. break;
  291. }
  292. }
  293. static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
  294. {
  295. sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
  296. sta->plink_timer.data = (unsigned long) sta;
  297. sta->plink_timer.function = mesh_plink_timer;
  298. sta->plink_timeout = timeout;
  299. add_timer(&sta->plink_timer);
  300. }
  301. int mesh_plink_open(struct sta_info *sta)
  302. {
  303. __le16 llid;
  304. struct ieee80211_sub_if_data *sdata = sta->sdata;
  305. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  306. DECLARE_MAC_BUF(mac);
  307. #endif
  308. spin_lock_bh(&sta->lock);
  309. get_random_bytes(&llid, 2);
  310. sta->llid = llid;
  311. if (sta->plink_state != PLINK_LISTEN) {
  312. spin_unlock_bh(&sta->lock);
  313. return -EBUSY;
  314. }
  315. sta->plink_state = PLINK_OPN_SNT;
  316. mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
  317. spin_unlock_bh(&sta->lock);
  318. mpl_dbg("Mesh plink: starting establishment with %s\n",
  319. print_mac(mac, sta->addr));
  320. return mesh_plink_frame_tx(sdata, PLINK_OPEN,
  321. sta->addr, llid, 0, 0);
  322. }
  323. void mesh_plink_block(struct sta_info *sta)
  324. {
  325. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  326. DECLARE_MAC_BUF(mac);
  327. #endif
  328. spin_lock_bh(&sta->lock);
  329. __mesh_plink_deactivate(sta);
  330. sta->plink_state = PLINK_BLOCKED;
  331. spin_unlock_bh(&sta->lock);
  332. }
  333. int mesh_plink_close(struct sta_info *sta)
  334. {
  335. struct ieee80211_sub_if_data *sdata = sta->sdata;
  336. __le16 llid, plid, reason;
  337. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  338. DECLARE_MAC_BUF(mac);
  339. #endif
  340. mpl_dbg("Mesh plink: closing link with %s\n",
  341. print_mac(mac, sta->addr));
  342. spin_lock_bh(&sta->lock);
  343. sta->reason = cpu_to_le16(MESH_LINK_CANCELLED);
  344. reason = sta->reason;
  345. if (sta->plink_state == PLINK_LISTEN ||
  346. sta->plink_state == PLINK_BLOCKED) {
  347. mesh_plink_fsm_restart(sta);
  348. spin_unlock_bh(&sta->lock);
  349. return 0;
  350. } else if (sta->plink_state == PLINK_ESTAB) {
  351. __mesh_plink_deactivate(sta);
  352. /* The timer should not be running */
  353. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  354. } else if (!mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)))
  355. sta->ignore_plink_timer = true;
  356. sta->plink_state = PLINK_HOLDING;
  357. llid = sta->llid;
  358. plid = sta->plid;
  359. spin_unlock_bh(&sta->lock);
  360. mesh_plink_frame_tx(sta->sdata, PLINK_CLOSE, sta->addr, llid,
  361. plid, reason);
  362. return 0;
  363. }
  364. void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_mgmt *mgmt,
  365. size_t len, struct ieee80211_rx_status *rx_status)
  366. {
  367. struct ieee80211_local *local = sdata->local;
  368. struct ieee802_11_elems elems;
  369. struct sta_info *sta;
  370. enum plink_event event;
  371. enum plink_frame_type ftype;
  372. size_t baselen;
  373. u8 ie_len;
  374. u8 *baseaddr;
  375. __le16 plid, llid, reason;
  376. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  377. DECLARE_MAC_BUF(mac);
  378. #endif
  379. if (is_multicast_ether_addr(mgmt->da)) {
  380. mpl_dbg("Mesh plink: ignore frame from multicast address");
  381. return;
  382. }
  383. baseaddr = mgmt->u.action.u.plink_action.variable;
  384. baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
  385. if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
  386. baseaddr += 4;
  387. baselen -= 4;
  388. }
  389. ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
  390. if (!elems.peer_link) {
  391. mpl_dbg("Mesh plink: missing necessary peer link ie\n");
  392. return;
  393. }
  394. ftype = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link));
  395. ie_len = elems.peer_link_len;
  396. if ((ftype == PLINK_OPEN && ie_len != 3) ||
  397. (ftype == PLINK_CONFIRM && ie_len != 5) ||
  398. (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) {
  399. mpl_dbg("Mesh plink: incorrect plink ie length\n");
  400. return;
  401. }
  402. if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
  403. mpl_dbg("Mesh plink: missing necessary ie\n");
  404. return;
  405. }
  406. /* Note the lines below are correct, the llid in the frame is the plid
  407. * from the point of view of this host.
  408. */
  409. memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
  410. if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7))
  411. memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
  412. rcu_read_lock();
  413. sta = sta_info_get(local, mgmt->sa);
  414. if (!sta && ftype != PLINK_OPEN) {
  415. mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
  416. rcu_read_unlock();
  417. return;
  418. }
  419. if (sta && sta->plink_state == PLINK_BLOCKED) {
  420. rcu_read_unlock();
  421. return;
  422. }
  423. /* Now we will figure out the appropriate event... */
  424. event = PLINK_UNDEFINED;
  425. if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, sdata))) {
  426. switch (ftype) {
  427. case PLINK_OPEN:
  428. event = OPN_RJCT;
  429. break;
  430. case PLINK_CONFIRM:
  431. event = CNF_RJCT;
  432. break;
  433. case PLINK_CLOSE:
  434. /* avoid warning */
  435. break;
  436. }
  437. spin_lock_bh(&sta->lock);
  438. } else if (!sta) {
  439. /* ftype == PLINK_OPEN */
  440. u64 rates;
  441. if (!mesh_plink_free_count(sdata)) {
  442. mpl_dbg("Mesh plink error: no more free plinks\n");
  443. rcu_read_unlock();
  444. return;
  445. }
  446. rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
  447. sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
  448. if (!sta) {
  449. mpl_dbg("Mesh plink error: plink table full\n");
  450. rcu_read_unlock();
  451. return;
  452. }
  453. if (sta_info_insert(sta)) {
  454. rcu_read_unlock();
  455. return;
  456. }
  457. event = OPN_ACPT;
  458. spin_lock_bh(&sta->lock);
  459. } else {
  460. spin_lock_bh(&sta->lock);
  461. switch (ftype) {
  462. case PLINK_OPEN:
  463. if (!mesh_plink_free_count(sdata) ||
  464. (sta->plid && sta->plid != plid))
  465. event = OPN_IGNR;
  466. else
  467. event = OPN_ACPT;
  468. break;
  469. case PLINK_CONFIRM:
  470. if (!mesh_plink_free_count(sdata) ||
  471. (sta->llid != llid || sta->plid != plid))
  472. event = CNF_IGNR;
  473. else
  474. event = CNF_ACPT;
  475. break;
  476. case PLINK_CLOSE:
  477. if (sta->plink_state == PLINK_ESTAB)
  478. /* Do not check for llid or plid. This does not
  479. * follow the standard but since multiple plinks
  480. * per sta are not supported, it is necessary in
  481. * order to avoid a livelock when MP A sees an
  482. * establish peer link to MP B but MP B does not
  483. * see it. This can be caused by a timeout in
  484. * B's peer link establishment or B beign
  485. * restarted.
  486. */
  487. event = CLS_ACPT;
  488. else if (sta->plid != plid)
  489. event = CLS_IGNR;
  490. else if (ie_len == 7 && sta->llid != llid)
  491. event = CLS_IGNR;
  492. else
  493. event = CLS_ACPT;
  494. break;
  495. default:
  496. mpl_dbg("Mesh plink: unknown frame subtype\n");
  497. spin_unlock_bh(&sta->lock);
  498. rcu_read_unlock();
  499. return;
  500. }
  501. }
  502. mpl_dbg("Mesh plink (peer, state, llid, plid, event): %s %d %d %d %d\n",
  503. print_mac(mac, mgmt->sa), sta->plink_state,
  504. le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
  505. event);
  506. reason = 0;
  507. switch (sta->plink_state) {
  508. /* spin_unlock as soon as state is updated at each case */
  509. case PLINK_LISTEN:
  510. switch (event) {
  511. case CLS_ACPT:
  512. mesh_plink_fsm_restart(sta);
  513. spin_unlock_bh(&sta->lock);
  514. break;
  515. case OPN_ACPT:
  516. sta->plink_state = PLINK_OPN_RCVD;
  517. sta->plid = plid;
  518. get_random_bytes(&llid, 2);
  519. sta->llid = llid;
  520. mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
  521. spin_unlock_bh(&sta->lock);
  522. mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->addr, llid,
  523. 0, 0);
  524. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr,
  525. llid, plid, 0);
  526. break;
  527. default:
  528. spin_unlock_bh(&sta->lock);
  529. break;
  530. }
  531. break;
  532. case PLINK_OPN_SNT:
  533. switch (event) {
  534. case OPN_RJCT:
  535. case CNF_RJCT:
  536. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  537. case CLS_ACPT:
  538. if (!reason)
  539. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  540. sta->reason = reason;
  541. sta->plink_state = PLINK_HOLDING;
  542. if (!mod_plink_timer(sta,
  543. dot11MeshHoldingTimeout(sdata)))
  544. sta->ignore_plink_timer = true;
  545. llid = sta->llid;
  546. spin_unlock_bh(&sta->lock);
  547. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid,
  548. plid, reason);
  549. break;
  550. case OPN_ACPT:
  551. /* retry timer is left untouched */
  552. sta->plink_state = PLINK_OPN_RCVD;
  553. sta->plid = plid;
  554. llid = sta->llid;
  555. spin_unlock_bh(&sta->lock);
  556. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid,
  557. plid, 0);
  558. break;
  559. case CNF_ACPT:
  560. sta->plink_state = PLINK_CNF_RCVD;
  561. if (!mod_plink_timer(sta,
  562. dot11MeshConfirmTimeout(sdata)))
  563. sta->ignore_plink_timer = true;
  564. spin_unlock_bh(&sta->lock);
  565. break;
  566. default:
  567. spin_unlock_bh(&sta->lock);
  568. break;
  569. }
  570. break;
  571. case PLINK_OPN_RCVD:
  572. switch (event) {
  573. case OPN_RJCT:
  574. case CNF_RJCT:
  575. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  576. case CLS_ACPT:
  577. if (!reason)
  578. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  579. sta->reason = reason;
  580. sta->plink_state = PLINK_HOLDING;
  581. if (!mod_plink_timer(sta,
  582. dot11MeshHoldingTimeout(sdata)))
  583. sta->ignore_plink_timer = true;
  584. llid = sta->llid;
  585. spin_unlock_bh(&sta->lock);
  586. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid,
  587. plid, reason);
  588. break;
  589. case OPN_ACPT:
  590. llid = sta->llid;
  591. spin_unlock_bh(&sta->lock);
  592. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid,
  593. plid, 0);
  594. break;
  595. case CNF_ACPT:
  596. del_timer(&sta->plink_timer);
  597. sta->plink_state = PLINK_ESTAB;
  598. mesh_plink_inc_estab_count(sdata);
  599. spin_unlock_bh(&sta->lock);
  600. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  601. print_mac(mac, sta->addr));
  602. break;
  603. default:
  604. spin_unlock_bh(&sta->lock);
  605. break;
  606. }
  607. break;
  608. case PLINK_CNF_RCVD:
  609. switch (event) {
  610. case OPN_RJCT:
  611. case CNF_RJCT:
  612. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  613. case CLS_ACPT:
  614. if (!reason)
  615. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  616. sta->reason = reason;
  617. sta->plink_state = PLINK_HOLDING;
  618. if (!mod_plink_timer(sta,
  619. dot11MeshHoldingTimeout(sdata)))
  620. sta->ignore_plink_timer = true;
  621. llid = sta->llid;
  622. spin_unlock_bh(&sta->lock);
  623. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid,
  624. plid, reason);
  625. break;
  626. case OPN_ACPT:
  627. del_timer(&sta->plink_timer);
  628. sta->plink_state = PLINK_ESTAB;
  629. mesh_plink_inc_estab_count(sdata);
  630. spin_unlock_bh(&sta->lock);
  631. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  632. print_mac(mac, sta->addr));
  633. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid,
  634. plid, 0);
  635. break;
  636. default:
  637. spin_unlock_bh(&sta->lock);
  638. break;
  639. }
  640. break;
  641. case PLINK_ESTAB:
  642. switch (event) {
  643. case CLS_ACPT:
  644. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  645. sta->reason = reason;
  646. __mesh_plink_deactivate(sta);
  647. sta->plink_state = PLINK_HOLDING;
  648. llid = sta->llid;
  649. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  650. spin_unlock_bh(&sta->lock);
  651. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid,
  652. plid, reason);
  653. break;
  654. case OPN_ACPT:
  655. llid = sta->llid;
  656. spin_unlock_bh(&sta->lock);
  657. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid,
  658. plid, 0);
  659. break;
  660. default:
  661. spin_unlock_bh(&sta->lock);
  662. break;
  663. }
  664. break;
  665. case PLINK_HOLDING:
  666. switch (event) {
  667. case CLS_ACPT:
  668. if (del_timer(&sta->plink_timer))
  669. sta->ignore_plink_timer = 1;
  670. mesh_plink_fsm_restart(sta);
  671. spin_unlock_bh(&sta->lock);
  672. break;
  673. case OPN_ACPT:
  674. case CNF_ACPT:
  675. case OPN_RJCT:
  676. case CNF_RJCT:
  677. llid = sta->llid;
  678. reason = sta->reason;
  679. spin_unlock_bh(&sta->lock);
  680. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid,
  681. plid, reason);
  682. break;
  683. default:
  684. spin_unlock_bh(&sta->lock);
  685. }
  686. break;
  687. default:
  688. /* should not get here, PLINK_BLOCKED is dealt with at the
  689. * beggining of the function
  690. */
  691. spin_unlock_bh(&sta->lock);
  692. break;
  693. }
  694. rcu_read_unlock();
  695. }