mesh_plink.c 19 KB

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