mesh_plink.c 19 KB

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