mesh_plink.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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 "ieee80211_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 IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
  20. #define PLINK_GET_FRAME_SUBTYPE(p) (p)
  21. #define PLINK_GET_LLID(p) (p + 1)
  22. #define PLINK_GET_PLID(p) (p + 3)
  23. #define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
  24. jiffies + HZ * t / 1000))
  25. /* Peer link cancel reasons, all subject to ANA approval */
  26. #define MESH_LINK_CANCELLED 2
  27. #define MESH_MAX_NEIGHBORS 3
  28. #define MESH_CAPABILITY_POLICY_VIOLATION 4
  29. #define MESH_CLOSE_RCVD 5
  30. #define MESH_MAX_RETRIES 6
  31. #define MESH_CONFIRM_TIMEOUT 7
  32. #define MESH_SECURITY_ROLE_NEGOTIATION_DIFFERS 8
  33. #define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9
  34. #define MESH_SECURITY_FAILED_VERIFICATION 10
  35. #define dot11MeshMaxRetries(s) (s->u.sta.mshcfg.dot11MeshMaxRetries)
  36. #define dot11MeshRetryTimeout(s) (s->u.sta.mshcfg.dot11MeshRetryTimeout)
  37. #define dot11MeshConfirmTimeout(s) (s->u.sta.mshcfg.dot11MeshConfirmTimeout)
  38. #define dot11MeshHoldingTimeout(s) (s->u.sta.mshcfg.dot11MeshHoldingTimeout)
  39. #define dot11MeshMaxPeerLinks(s) (s->u.sta.mshcfg.dot11MeshMaxPeerLinks)
  40. enum plink_frame_type {
  41. PLINK_OPEN = 0,
  42. PLINK_CONFIRM,
  43. PLINK_CLOSE
  44. };
  45. enum plink_event {
  46. PLINK_UNDEFINED,
  47. OPN_ACPT,
  48. OPN_RJCT,
  49. OPN_IGNR,
  50. CNF_ACPT,
  51. CNF_RJCT,
  52. CNF_IGNR,
  53. CLS_ACPT,
  54. CLS_IGNR
  55. };
  56. static inline
  57. void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
  58. {
  59. atomic_inc(&sdata->u.sta.mshstats.estab_plinks);
  60. mesh_accept_plinks_update(sdata);
  61. }
  62. static inline
  63. void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
  64. {
  65. atomic_dec(&sdata->u.sta.mshstats.estab_plinks);
  66. mesh_accept_plinks_update(sdata);
  67. }
  68. /**
  69. * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
  70. *
  71. * @sta: mes peer link to restart
  72. *
  73. * Locking: this function must be called holding sta->plink_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, u64 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->supp_rates[local->hw.conf.channel->band] = rates;
  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->plink_lock
  107. */
  108. static void __mesh_plink_deactivate(struct sta_info *sta)
  109. {
  110. struct ieee80211_sub_if_data *sdata = sta->sdata;
  111. if (sta->plink_state == PLINK_ESTAB)
  112. mesh_plink_dec_estab_count(sdata);
  113. sta->plink_state = PLINK_BLOCKED;
  114. mesh_path_flush_by_nexthop(sta);
  115. }
  116. /**
  117. * __mesh_plink_deactivate - deactivate mesh peer link
  118. *
  119. * @sta: mesh peer link to deactivate
  120. *
  121. * All mesh paths with this peer as next hop will be flushed
  122. */
  123. void mesh_plink_deactivate(struct sta_info *sta)
  124. {
  125. spin_lock_bh(&sta->plink_lock);
  126. __mesh_plink_deactivate(sta);
  127. spin_unlock_bh(&sta->plink_lock);
  128. }
  129. static int mesh_plink_frame_tx(struct net_device *dev,
  130. enum plink_frame_type action, u8 *da, __le16 llid, __le16 plid,
  131. __le16 reason) {
  132. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  133. struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
  134. struct ieee80211_mgmt *mgmt;
  135. bool include_plid = false;
  136. u8 *pos;
  137. int ie_len;
  138. if (!skb)
  139. return -1;
  140. skb_reserve(skb, local->hw.extra_tx_headroom);
  141. /* 25 is the size of the common mgmt part (24) plus the size of the
  142. * common action part (1)
  143. */
  144. mgmt = (struct ieee80211_mgmt *)
  145. skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
  146. memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
  147. mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
  148. IEEE80211_STYPE_ACTION);
  149. memcpy(mgmt->da, da, ETH_ALEN);
  150. memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
  151. /* BSSID is left zeroed, wildcard value */
  152. mgmt->u.action.category = PLINK_CATEGORY;
  153. mgmt->u.action.u.plink_action.action_code = action;
  154. if (action == PLINK_CLOSE)
  155. mgmt->u.action.u.plink_action.aux = reason;
  156. else {
  157. mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
  158. if (action == PLINK_CONFIRM) {
  159. pos = skb_put(skb, 4);
  160. /* two-byte status code followed by two-byte AID */
  161. memset(pos, 0, 4);
  162. }
  163. mesh_mgmt_ies_add(skb, dev);
  164. }
  165. /* Add Peer Link Management element */
  166. switch (action) {
  167. case PLINK_OPEN:
  168. ie_len = 3;
  169. break;
  170. case PLINK_CONFIRM:
  171. ie_len = 5;
  172. include_plid = true;
  173. break;
  174. case PLINK_CLOSE:
  175. default:
  176. if (!plid)
  177. ie_len = 5;
  178. else {
  179. ie_len = 7;
  180. include_plid = true;
  181. }
  182. break;
  183. }
  184. pos = skb_put(skb, 2 + ie_len);
  185. *pos++ = WLAN_EID_PEER_LINK;
  186. *pos++ = ie_len;
  187. *pos++ = action;
  188. memcpy(pos, &llid, 2);
  189. if (include_plid) {
  190. pos += 2;
  191. memcpy(pos, &plid, 2);
  192. }
  193. if (action == PLINK_CLOSE) {
  194. pos += 2;
  195. memcpy(pos, &reason, 2);
  196. }
  197. ieee80211_sta_tx(dev, skb, 0);
  198. return 0;
  199. }
  200. void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev,
  201. bool peer_accepting_plinks)
  202. {
  203. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  204. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  205. struct sta_info *sta;
  206. rcu_read_lock();
  207. sta = sta_info_get(local, hw_addr);
  208. if (!sta) {
  209. sta = mesh_plink_alloc(sdata, hw_addr, rates);
  210. if (!sta) {
  211. rcu_read_unlock();
  212. return;
  213. }
  214. if (sta_info_insert(sta)) {
  215. rcu_read_unlock();
  216. return;
  217. }
  218. }
  219. sta->last_rx = jiffies;
  220. sta->supp_rates[local->hw.conf.channel->band] = rates;
  221. if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
  222. sdata->u.sta.accepting_plinks &&
  223. sdata->u.sta.mshcfg.auto_open_plinks)
  224. mesh_plink_open(sta);
  225. rcu_read_unlock();
  226. }
  227. static void mesh_plink_timer(unsigned long data)
  228. {
  229. struct sta_info *sta;
  230. __le16 llid, plid, reason;
  231. struct net_device *dev = NULL;
  232. struct ieee80211_sub_if_data *sdata;
  233. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  234. DECLARE_MAC_BUF(mac);
  235. #endif
  236. /*
  237. * This STA is valid because sta_info_destroy() will
  238. * del_timer_sync() this timer after having made sure
  239. * it cannot be readded (by deleting the plink.)
  240. */
  241. sta = (struct sta_info *) data;
  242. spin_lock_bh(&sta->plink_lock);
  243. if (sta->ignore_plink_timer) {
  244. sta->ignore_plink_timer = false;
  245. spin_unlock_bh(&sta->plink_lock);
  246. return;
  247. }
  248. mpl_dbg("Mesh plink timer for %s fired on state %d\n",
  249. print_mac(mac, sta->addr), sta->plink_state);
  250. reason = 0;
  251. llid = sta->llid;
  252. plid = sta->plid;
  253. sdata = sta->sdata;
  254. dev = sdata->dev;
  255. switch (sta->plink_state) {
  256. case PLINK_OPN_RCVD:
  257. case PLINK_OPN_SNT:
  258. /* retry timer */
  259. if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
  260. u32 rand;
  261. mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n",
  262. print_mac(mac, sta->addr),
  263. sta->plink_retries, sta->plink_timeout);
  264. get_random_bytes(&rand, sizeof(u32));
  265. sta->plink_timeout = sta->plink_timeout +
  266. rand % sta->plink_timeout;
  267. ++sta->plink_retries;
  268. mod_plink_timer(sta, sta->plink_timeout);
  269. spin_unlock_bh(&sta->plink_lock);
  270. mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
  271. 0, 0);
  272. break;
  273. }
  274. reason = cpu_to_le16(MESH_MAX_RETRIES);
  275. /* fall through on else */
  276. case PLINK_CNF_RCVD:
  277. /* confirm timer */
  278. if (!reason)
  279. reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
  280. sta->plink_state = PLINK_HOLDING;
  281. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  282. spin_unlock_bh(&sta->plink_lock);
  283. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid, plid,
  284. reason);
  285. break;
  286. case PLINK_HOLDING:
  287. /* holding timer */
  288. del_timer(&sta->plink_timer);
  289. mesh_plink_fsm_restart(sta);
  290. spin_unlock_bh(&sta->plink_lock);
  291. break;
  292. default:
  293. spin_unlock_bh(&sta->plink_lock);
  294. break;
  295. }
  296. }
  297. static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
  298. {
  299. sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
  300. sta->plink_timer.data = (unsigned long) sta;
  301. sta->plink_timer.function = mesh_plink_timer;
  302. sta->plink_timeout = timeout;
  303. add_timer(&sta->plink_timer);
  304. }
  305. int mesh_plink_open(struct sta_info *sta)
  306. {
  307. __le16 llid;
  308. struct ieee80211_sub_if_data *sdata = sta->sdata;
  309. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  310. DECLARE_MAC_BUF(mac);
  311. #endif
  312. spin_lock_bh(&sta->plink_lock);
  313. get_random_bytes(&llid, 2);
  314. sta->llid = llid;
  315. if (sta->plink_state != PLINK_LISTEN) {
  316. spin_unlock_bh(&sta->plink_lock);
  317. return -EBUSY;
  318. }
  319. sta->plink_state = PLINK_OPN_SNT;
  320. mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
  321. spin_unlock_bh(&sta->plink_lock);
  322. mpl_dbg("Mesh plink: starting establishment with %s\n",
  323. print_mac(mac, sta->addr));
  324. return mesh_plink_frame_tx(sdata->dev, PLINK_OPEN,
  325. sta->addr, llid, 0, 0);
  326. }
  327. void mesh_plink_block(struct sta_info *sta)
  328. {
  329. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  330. DECLARE_MAC_BUF(mac);
  331. #endif
  332. spin_lock_bh(&sta->plink_lock);
  333. __mesh_plink_deactivate(sta);
  334. sta->plink_state = PLINK_BLOCKED;
  335. spin_unlock_bh(&sta->plink_lock);
  336. }
  337. int mesh_plink_close(struct sta_info *sta)
  338. {
  339. struct ieee80211_sub_if_data *sdata = sta->sdata;
  340. __le16 llid, plid, reason;
  341. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  342. DECLARE_MAC_BUF(mac);
  343. #endif
  344. mpl_dbg("Mesh plink: closing link with %s\n",
  345. print_mac(mac, sta->addr));
  346. spin_lock_bh(&sta->plink_lock);
  347. sta->reason = cpu_to_le16(MESH_LINK_CANCELLED);
  348. reason = sta->reason;
  349. if (sta->plink_state == PLINK_LISTEN ||
  350. sta->plink_state == PLINK_BLOCKED) {
  351. mesh_plink_fsm_restart(sta);
  352. spin_unlock_bh(&sta->plink_lock);
  353. return 0;
  354. } else if (sta->plink_state == PLINK_ESTAB) {
  355. __mesh_plink_deactivate(sta);
  356. /* The timer should not be running */
  357. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  358. } else if (!mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)))
  359. sta->ignore_plink_timer = true;
  360. sta->plink_state = PLINK_HOLDING;
  361. llid = sta->llid;
  362. plid = sta->plid;
  363. spin_unlock_bh(&sta->plink_lock);
  364. mesh_plink_frame_tx(sta->sdata->dev, PLINK_CLOSE, sta->addr, llid,
  365. plid, reason);
  366. return 0;
  367. }
  368. void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
  369. size_t len, struct ieee80211_rx_status *rx_status)
  370. {
  371. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  372. struct ieee80211_local *local = sdata->local;
  373. struct ieee802_11_elems elems;
  374. struct sta_info *sta;
  375. enum plink_event event;
  376. enum plink_frame_type ftype;
  377. size_t baselen;
  378. u8 ie_len;
  379. u8 *baseaddr;
  380. __le16 plid, llid, reason;
  381. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  382. DECLARE_MAC_BUF(mac);
  383. #endif
  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 = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link));
  400. ie_len = elems.peer_link_len;
  401. if ((ftype == PLINK_OPEN && ie_len != 3) ||
  402. (ftype == PLINK_CONFIRM && ie_len != 5) ||
  403. (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) {
  404. mpl_dbg("Mesh plink: incorrect plink ie length\n");
  405. return;
  406. }
  407. if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
  408. mpl_dbg("Mesh plink: missing necessary ie\n");
  409. return;
  410. }
  411. /* Note the lines below are correct, the llid in the frame is the plid
  412. * from the point of view of this host.
  413. */
  414. memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
  415. if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7))
  416. memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
  417. rcu_read_lock();
  418. sta = sta_info_get(local, mgmt->sa);
  419. if (!sta && ftype != PLINK_OPEN) {
  420. mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
  421. rcu_read_unlock();
  422. return;
  423. }
  424. if (sta && sta->plink_state == PLINK_BLOCKED) {
  425. rcu_read_unlock();
  426. return;
  427. }
  428. /* Now we will figure out the appropriate event... */
  429. event = PLINK_UNDEFINED;
  430. if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, dev))) {
  431. switch (ftype) {
  432. case PLINK_OPEN:
  433. event = OPN_RJCT;
  434. break;
  435. case PLINK_CONFIRM:
  436. event = CNF_RJCT;
  437. break;
  438. case PLINK_CLOSE:
  439. /* avoid warning */
  440. break;
  441. }
  442. spin_lock_bh(&sta->plink_lock);
  443. } else if (!sta) {
  444. /* ftype == PLINK_OPEN */
  445. u64 rates;
  446. if (!mesh_plink_free_count(sdata)) {
  447. mpl_dbg("Mesh plink error: no more free plinks\n");
  448. rcu_read_unlock();
  449. return;
  450. }
  451. rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
  452. sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
  453. if (!sta) {
  454. mpl_dbg("Mesh plink error: plink table full\n");
  455. rcu_read_unlock();
  456. return;
  457. }
  458. if (sta_info_insert(sta)) {
  459. rcu_read_unlock();
  460. return;
  461. }
  462. event = OPN_ACPT;
  463. spin_lock_bh(&sta->plink_lock);
  464. } else {
  465. spin_lock_bh(&sta->plink_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->plink_lock);
  503. rcu_read_unlock();
  504. return;
  505. }
  506. }
  507. mpl_dbg("Mesh plink (peer, state, llid, plid, event): %s %d %d %d %d\n",
  508. print_mac(mac, mgmt->sa), 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->plink_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->plink_lock);
  527. mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
  528. 0, 0);
  529. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr,
  530. llid, plid, 0);
  531. break;
  532. default:
  533. spin_unlock_bh(&sta->plink_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->plink_lock);
  552. mesh_plink_frame_tx(dev, PLINK_CLOSE, 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->plink_lock);
  561. mesh_plink_frame_tx(dev, PLINK_CONFIRM, 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->plink_lock);
  570. break;
  571. default:
  572. spin_unlock_bh(&sta->plink_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->plink_lock);
  591. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  592. plid, reason);
  593. break;
  594. case OPN_ACPT:
  595. llid = sta->llid;
  596. spin_unlock_bh(&sta->plink_lock);
  597. mesh_plink_frame_tx(dev, PLINK_CONFIRM, 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. mesh_plink_inc_estab_count(sdata);
  604. spin_unlock_bh(&sta->plink_lock);
  605. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  606. print_mac(mac, sta->addr));
  607. break;
  608. default:
  609. spin_unlock_bh(&sta->plink_lock);
  610. break;
  611. }
  612. break;
  613. case PLINK_CNF_RCVD:
  614. switch (event) {
  615. case OPN_RJCT:
  616. case CNF_RJCT:
  617. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  618. case CLS_ACPT:
  619. if (!reason)
  620. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  621. sta->reason = reason;
  622. sta->plink_state = PLINK_HOLDING;
  623. if (!mod_plink_timer(sta,
  624. dot11MeshHoldingTimeout(sdata)))
  625. sta->ignore_plink_timer = true;
  626. llid = sta->llid;
  627. spin_unlock_bh(&sta->plink_lock);
  628. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  629. plid, reason);
  630. break;
  631. case OPN_ACPT:
  632. del_timer(&sta->plink_timer);
  633. sta->plink_state = PLINK_ESTAB;
  634. mesh_plink_inc_estab_count(sdata);
  635. spin_unlock_bh(&sta->plink_lock);
  636. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  637. print_mac(mac, sta->addr));
  638. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  639. plid, 0);
  640. break;
  641. default:
  642. spin_unlock_bh(&sta->plink_lock);
  643. break;
  644. }
  645. break;
  646. case PLINK_ESTAB:
  647. switch (event) {
  648. case CLS_ACPT:
  649. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  650. sta->reason = reason;
  651. __mesh_plink_deactivate(sta);
  652. sta->plink_state = PLINK_HOLDING;
  653. llid = sta->llid;
  654. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  655. spin_unlock_bh(&sta->plink_lock);
  656. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  657. plid, reason);
  658. break;
  659. case OPN_ACPT:
  660. llid = sta->llid;
  661. spin_unlock_bh(&sta->plink_lock);
  662. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  663. plid, 0);
  664. break;
  665. default:
  666. spin_unlock_bh(&sta->plink_lock);
  667. break;
  668. }
  669. break;
  670. case PLINK_HOLDING:
  671. switch (event) {
  672. case CLS_ACPT:
  673. if (del_timer(&sta->plink_timer))
  674. sta->ignore_plink_timer = 1;
  675. mesh_plink_fsm_restart(sta);
  676. spin_unlock_bh(&sta->plink_lock);
  677. break;
  678. case OPN_ACPT:
  679. case CNF_ACPT:
  680. case OPN_RJCT:
  681. case CNF_RJCT:
  682. llid = sta->llid;
  683. reason = sta->reason;
  684. spin_unlock_bh(&sta->plink_lock);
  685. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  686. plid, reason);
  687. break;
  688. default:
  689. spin_unlock_bh(&sta->plink_lock);
  690. }
  691. break;
  692. default:
  693. /* should not get here, PLINK_BLOCKED is dealt with at the
  694. * beggining of the function
  695. */
  696. spin_unlock_bh(&sta->plink_lock);
  697. break;
  698. }
  699. rcu_read_unlock();
  700. }