mesh_plink.c 19 KB

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