mesh_plink.c 19 KB

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