mesh_plink.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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_ATOMIC);
  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->dev->dev_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(local, hw_addr);
  211. if (!sta) {
  212. sta = mesh_plink_alloc(sdata, hw_addr, rates);
  213. if (!sta) {
  214. rcu_read_unlock();
  215. return;
  216. }
  217. if (sta_info_insert(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(local, 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. if (!mesh_plink_free_count(sdata)) {
  437. mpl_dbg("Mesh plink error: no more free plinks\n");
  438. rcu_read_unlock();
  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. rcu_read_unlock();
  446. return;
  447. }
  448. if (sta_info_insert(sta)) {
  449. rcu_read_unlock();
  450. return;
  451. }
  452. event = OPN_ACPT;
  453. spin_lock_bh(&sta->lock);
  454. } else {
  455. spin_lock_bh(&sta->lock);
  456. switch (ftype) {
  457. case PLINK_OPEN:
  458. if (!mesh_plink_free_count(sdata) ||
  459. (sta->plid && sta->plid != plid))
  460. event = OPN_IGNR;
  461. else
  462. event = OPN_ACPT;
  463. break;
  464. case PLINK_CONFIRM:
  465. if (!mesh_plink_free_count(sdata) ||
  466. (sta->llid != llid || sta->plid != plid))
  467. event = CNF_IGNR;
  468. else
  469. event = CNF_ACPT;
  470. break;
  471. case PLINK_CLOSE:
  472. if (sta->plink_state == PLINK_ESTAB)
  473. /* Do not check for llid or plid. This does not
  474. * follow the standard but since multiple plinks
  475. * per sta are not supported, it is necessary in
  476. * order to avoid a livelock when MP A sees an
  477. * establish peer link to MP B but MP B does not
  478. * see it. This can be caused by a timeout in
  479. * B's peer link establishment or B beign
  480. * restarted.
  481. */
  482. event = CLS_ACPT;
  483. else if (sta->plid != plid)
  484. event = CLS_IGNR;
  485. else if (ie_len == 7 && sta->llid != llid)
  486. event = CLS_IGNR;
  487. else
  488. event = CLS_ACPT;
  489. break;
  490. default:
  491. mpl_dbg("Mesh plink: unknown frame subtype\n");
  492. spin_unlock_bh(&sta->lock);
  493. rcu_read_unlock();
  494. return;
  495. }
  496. }
  497. mpl_dbg("Mesh plink (peer, state, llid, plid, event): %pM %s %d %d %d\n",
  498. mgmt->sa, mplstates[sta->plink_state],
  499. le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
  500. event);
  501. reason = 0;
  502. switch (sta->plink_state) {
  503. /* spin_unlock as soon as state is updated at each case */
  504. case PLINK_LISTEN:
  505. switch (event) {
  506. case CLS_ACPT:
  507. mesh_plink_fsm_restart(sta);
  508. spin_unlock_bh(&sta->lock);
  509. break;
  510. case OPN_ACPT:
  511. sta->plink_state = PLINK_OPN_RCVD;
  512. sta->plid = plid;
  513. get_random_bytes(&llid, 2);
  514. sta->llid = llid;
  515. mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
  516. spin_unlock_bh(&sta->lock);
  517. mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
  518. 0, 0);
  519. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr,
  520. llid, plid, 0);
  521. break;
  522. default:
  523. spin_unlock_bh(&sta->lock);
  524. break;
  525. }
  526. break;
  527. case PLINK_OPN_SNT:
  528. switch (event) {
  529. case OPN_RJCT:
  530. case CNF_RJCT:
  531. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  532. case CLS_ACPT:
  533. if (!reason)
  534. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  535. sta->reason = reason;
  536. sta->plink_state = PLINK_HOLDING;
  537. if (!mod_plink_timer(sta,
  538. dot11MeshHoldingTimeout(sdata)))
  539. sta->ignore_plink_timer = true;
  540. llid = sta->llid;
  541. spin_unlock_bh(&sta->lock);
  542. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
  543. plid, reason);
  544. break;
  545. case OPN_ACPT:
  546. /* retry timer is left untouched */
  547. sta->plink_state = PLINK_OPN_RCVD;
  548. sta->plid = plid;
  549. llid = sta->llid;
  550. spin_unlock_bh(&sta->lock);
  551. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
  552. plid, 0);
  553. break;
  554. case CNF_ACPT:
  555. sta->plink_state = PLINK_CNF_RCVD;
  556. if (!mod_plink_timer(sta,
  557. dot11MeshConfirmTimeout(sdata)))
  558. sta->ignore_plink_timer = true;
  559. spin_unlock_bh(&sta->lock);
  560. break;
  561. default:
  562. spin_unlock_bh(&sta->lock);
  563. break;
  564. }
  565. break;
  566. case PLINK_OPN_RCVD:
  567. switch (event) {
  568. case OPN_RJCT:
  569. case CNF_RJCT:
  570. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  571. case CLS_ACPT:
  572. if (!reason)
  573. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  574. sta->reason = reason;
  575. sta->plink_state = PLINK_HOLDING;
  576. if (!mod_plink_timer(sta,
  577. dot11MeshHoldingTimeout(sdata)))
  578. sta->ignore_plink_timer = true;
  579. llid = sta->llid;
  580. spin_unlock_bh(&sta->lock);
  581. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
  582. plid, reason);
  583. break;
  584. case OPN_ACPT:
  585. llid = sta->llid;
  586. spin_unlock_bh(&sta->lock);
  587. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
  588. plid, 0);
  589. break;
  590. case CNF_ACPT:
  591. del_timer(&sta->plink_timer);
  592. sta->plink_state = PLINK_ESTAB;
  593. mesh_plink_inc_estab_count(sdata);
  594. spin_unlock_bh(&sta->lock);
  595. mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
  596. sta->sta.addr);
  597. break;
  598. default:
  599. spin_unlock_bh(&sta->lock);
  600. break;
  601. }
  602. break;
  603. case PLINK_CNF_RCVD:
  604. switch (event) {
  605. case OPN_RJCT:
  606. case CNF_RJCT:
  607. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  608. case CLS_ACPT:
  609. if (!reason)
  610. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  611. sta->reason = reason;
  612. sta->plink_state = PLINK_HOLDING;
  613. if (!mod_plink_timer(sta,
  614. dot11MeshHoldingTimeout(sdata)))
  615. sta->ignore_plink_timer = true;
  616. llid = sta->llid;
  617. spin_unlock_bh(&sta->lock);
  618. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
  619. plid, reason);
  620. break;
  621. case OPN_ACPT:
  622. del_timer(&sta->plink_timer);
  623. sta->plink_state = PLINK_ESTAB;
  624. mesh_plink_inc_estab_count(sdata);
  625. spin_unlock_bh(&sta->lock);
  626. mpl_dbg("Mesh plink with %pM ESTABLISHED\n",
  627. sta->sta.addr);
  628. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
  629. plid, 0);
  630. break;
  631. default:
  632. spin_unlock_bh(&sta->lock);
  633. break;
  634. }
  635. break;
  636. case PLINK_ESTAB:
  637. switch (event) {
  638. case CLS_ACPT:
  639. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  640. sta->reason = reason;
  641. __mesh_plink_deactivate(sta);
  642. sta->plink_state = PLINK_HOLDING;
  643. llid = sta->llid;
  644. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  645. spin_unlock_bh(&sta->lock);
  646. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
  647. plid, reason);
  648. break;
  649. case OPN_ACPT:
  650. llid = sta->llid;
  651. spin_unlock_bh(&sta->lock);
  652. mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
  653. plid, 0);
  654. break;
  655. default:
  656. spin_unlock_bh(&sta->lock);
  657. break;
  658. }
  659. break;
  660. case PLINK_HOLDING:
  661. switch (event) {
  662. case CLS_ACPT:
  663. if (del_timer(&sta->plink_timer))
  664. sta->ignore_plink_timer = 1;
  665. mesh_plink_fsm_restart(sta);
  666. spin_unlock_bh(&sta->lock);
  667. break;
  668. case OPN_ACPT:
  669. case CNF_ACPT:
  670. case OPN_RJCT:
  671. case CNF_RJCT:
  672. llid = sta->llid;
  673. reason = sta->reason;
  674. spin_unlock_bh(&sta->lock);
  675. mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr,
  676. llid, plid, reason);
  677. break;
  678. default:
  679. spin_unlock_bh(&sta->lock);
  680. }
  681. break;
  682. default:
  683. /* should not get here, PLINK_BLOCKED is dealt with at the
  684. * beggining of the function
  685. */
  686. spin_unlock_bh(&sta->lock);
  687. break;
  688. }
  689. rcu_read_unlock();
  690. }