mesh_plink.c 19 KB

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