mesh_plink.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
  82. u8 *hw_addr, u64 rates)
  83. {
  84. struct ieee80211_local *local = sdata->local;
  85. struct sta_info *sta;
  86. if (local->num_sta >= MESH_MAX_PLINKS)
  87. return NULL;
  88. sta = sta_info_alloc(sdata, hw_addr, GFP_ATOMIC);
  89. if (!sta)
  90. return NULL;
  91. sta->flags |= WLAN_STA_AUTHORIZED;
  92. sta->supp_rates[local->hw.conf.channel->band] = rates;
  93. return sta;
  94. }
  95. /**
  96. * mesh_plink_deactivate - deactivate mesh peer link
  97. *
  98. * @sta: mesh peer link to deactivate
  99. *
  100. * All mesh paths with this peer as next hop will be flushed
  101. *
  102. * Locking: the caller must hold sta->plink_lock
  103. */
  104. static void __mesh_plink_deactivate(struct sta_info *sta)
  105. {
  106. struct ieee80211_sub_if_data *sdata = sta->sdata;
  107. if (sta->plink_state == PLINK_ESTAB)
  108. mesh_plink_dec_estab_count(sdata);
  109. sta->plink_state = PLINK_BLOCKED;
  110. mesh_path_flush_by_nexthop(sta);
  111. }
  112. /**
  113. * __mesh_plink_deactivate - deactivate mesh peer link
  114. *
  115. * @sta: mesh peer link to deactivate
  116. *
  117. * All mesh paths with this peer as next hop will be flushed
  118. */
  119. void mesh_plink_deactivate(struct sta_info *sta)
  120. {
  121. spin_lock_bh(&sta->plink_lock);
  122. __mesh_plink_deactivate(sta);
  123. spin_unlock_bh(&sta->plink_lock);
  124. }
  125. static int mesh_plink_frame_tx(struct net_device *dev,
  126. enum plink_frame_type action, u8 *da, __le16 llid, __le16 plid,
  127. __le16 reason) {
  128. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  129. struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
  130. struct ieee80211_mgmt *mgmt;
  131. bool include_plid = false;
  132. u8 *pos;
  133. int ie_len;
  134. if (!skb)
  135. return -1;
  136. skb_reserve(skb, local->hw.extra_tx_headroom);
  137. /* 25 is the size of the common mgmt part (24) plus the size of the
  138. * common action part (1)
  139. */
  140. mgmt = (struct ieee80211_mgmt *)
  141. skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
  142. memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
  143. mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
  144. IEEE80211_STYPE_ACTION);
  145. memcpy(mgmt->da, da, ETH_ALEN);
  146. memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
  147. /* BSSID is left zeroed, wildcard value */
  148. mgmt->u.action.category = PLINK_CATEGORY;
  149. mgmt->u.action.u.plink_action.action_code = action;
  150. if (action == PLINK_CLOSE)
  151. mgmt->u.action.u.plink_action.aux = reason;
  152. else {
  153. mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
  154. if (action == PLINK_CONFIRM) {
  155. pos = skb_put(skb, 4);
  156. /* two-byte status code followed by two-byte AID */
  157. memset(pos, 0, 4);
  158. }
  159. mesh_mgmt_ies_add(skb, dev);
  160. }
  161. /* Add Peer Link Management element */
  162. switch (action) {
  163. case PLINK_OPEN:
  164. ie_len = 3;
  165. break;
  166. case PLINK_CONFIRM:
  167. ie_len = 5;
  168. include_plid = true;
  169. break;
  170. case PLINK_CLOSE:
  171. default:
  172. if (!plid)
  173. ie_len = 5;
  174. else {
  175. ie_len = 7;
  176. include_plid = true;
  177. }
  178. break;
  179. }
  180. pos = skb_put(skb, 2 + ie_len);
  181. *pos++ = WLAN_EID_PEER_LINK;
  182. *pos++ = ie_len;
  183. *pos++ = action;
  184. memcpy(pos, &llid, 2);
  185. if (include_plid) {
  186. pos += 2;
  187. memcpy(pos, &plid, 2);
  188. }
  189. if (action == PLINK_CLOSE) {
  190. pos += 2;
  191. memcpy(pos, &reason, 2);
  192. }
  193. ieee80211_sta_tx(dev, skb, 0);
  194. return 0;
  195. }
  196. void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev,
  197. bool peer_accepting_plinks)
  198. {
  199. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  200. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  201. struct sta_info *sta;
  202. rcu_read_lock();
  203. sta = sta_info_get(local, hw_addr);
  204. if (!sta) {
  205. sta = mesh_plink_alloc(sdata, hw_addr, rates);
  206. if (!sta) {
  207. rcu_read_unlock();
  208. return;
  209. }
  210. if (sta_info_insert(sta)) {
  211. sta_info_destroy(sta);
  212. rcu_read_unlock();
  213. return;
  214. }
  215. }
  216. sta->last_rx = jiffies;
  217. sta->supp_rates[local->hw.conf.channel->band] = rates;
  218. if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
  219. sdata->u.sta.accepting_plinks &&
  220. sdata->u.sta.mshcfg.auto_open_plinks)
  221. mesh_plink_open(sta);
  222. rcu_read_unlock();
  223. }
  224. static void mesh_plink_timer(unsigned long data)
  225. {
  226. struct sta_info *sta;
  227. __le16 llid, plid, reason;
  228. struct net_device *dev = NULL;
  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->plink_lock);
  240. if (sta->ignore_plink_timer) {
  241. sta->ignore_plink_timer = false;
  242. spin_unlock_bh(&sta->plink_lock);
  243. return;
  244. }
  245. mpl_dbg("Mesh plink timer for %s fired on state %d\n",
  246. print_mac(mac, sta->addr), sta->plink_state);
  247. reason = 0;
  248. llid = sta->llid;
  249. plid = sta->plid;
  250. sdata = sta->sdata;
  251. dev = sdata->dev;
  252. switch (sta->plink_state) {
  253. case PLINK_OPN_RCVD:
  254. case PLINK_OPN_SNT:
  255. /* retry timer */
  256. if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
  257. u32 rand;
  258. mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n",
  259. print_mac(mac, sta->addr),
  260. sta->plink_retries, sta->plink_timeout);
  261. get_random_bytes(&rand, sizeof(u32));
  262. sta->plink_timeout = sta->plink_timeout +
  263. rand % sta->plink_timeout;
  264. ++sta->plink_retries;
  265. mod_plink_timer(sta, sta->plink_timeout);
  266. spin_unlock_bh(&sta->plink_lock);
  267. mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
  268. 0, 0);
  269. break;
  270. }
  271. reason = cpu_to_le16(MESH_MAX_RETRIES);
  272. /* fall through on else */
  273. case PLINK_CNF_RCVD:
  274. /* confirm timer */
  275. if (!reason)
  276. reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
  277. sta->plink_state = PLINK_HOLDING;
  278. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  279. spin_unlock_bh(&sta->plink_lock);
  280. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid, plid,
  281. reason);
  282. break;
  283. case PLINK_HOLDING:
  284. /* holding timer */
  285. del_timer(&sta->plink_timer);
  286. mesh_plink_fsm_restart(sta);
  287. spin_unlock_bh(&sta->plink_lock);
  288. break;
  289. default:
  290. spin_unlock_bh(&sta->plink_lock);
  291. break;
  292. }
  293. }
  294. static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
  295. {
  296. sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
  297. sta->plink_timer.data = (unsigned long) sta;
  298. sta->plink_timer.function = mesh_plink_timer;
  299. sta->plink_timeout = timeout;
  300. add_timer(&sta->plink_timer);
  301. }
  302. int mesh_plink_open(struct sta_info *sta)
  303. {
  304. __le16 llid;
  305. struct ieee80211_sub_if_data *sdata = sta->sdata;
  306. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  307. DECLARE_MAC_BUF(mac);
  308. #endif
  309. spin_lock_bh(&sta->plink_lock);
  310. get_random_bytes(&llid, 2);
  311. sta->llid = llid;
  312. if (sta->plink_state != PLINK_LISTEN) {
  313. spin_unlock_bh(&sta->plink_lock);
  314. return -EBUSY;
  315. }
  316. sta->plink_state = PLINK_OPN_SNT;
  317. mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
  318. spin_unlock_bh(&sta->plink_lock);
  319. mpl_dbg("Mesh plink: starting establishment with %s\n",
  320. print_mac(mac, sta->addr));
  321. return mesh_plink_frame_tx(sdata->dev, PLINK_OPEN,
  322. sta->addr, llid, 0, 0);
  323. }
  324. void mesh_plink_block(struct sta_info *sta)
  325. {
  326. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  327. DECLARE_MAC_BUF(mac);
  328. #endif
  329. spin_lock_bh(&sta->plink_lock);
  330. __mesh_plink_deactivate(sta);
  331. sta->plink_state = PLINK_BLOCKED;
  332. spin_unlock_bh(&sta->plink_lock);
  333. }
  334. int mesh_plink_close(struct sta_info *sta)
  335. {
  336. struct ieee80211_sub_if_data *sdata = sta->sdata;
  337. __le16 llid, plid, reason;
  338. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  339. DECLARE_MAC_BUF(mac);
  340. #endif
  341. mpl_dbg("Mesh plink: closing link with %s\n",
  342. print_mac(mac, sta->addr));
  343. spin_lock_bh(&sta->plink_lock);
  344. sta->reason = cpu_to_le16(MESH_LINK_CANCELLED);
  345. reason = sta->reason;
  346. if (sta->plink_state == PLINK_LISTEN ||
  347. sta->plink_state == PLINK_BLOCKED) {
  348. mesh_plink_fsm_restart(sta);
  349. spin_unlock_bh(&sta->plink_lock);
  350. return 0;
  351. } else if (sta->plink_state == PLINK_ESTAB) {
  352. __mesh_plink_deactivate(sta);
  353. /* The timer should not be running */
  354. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  355. } else if (!mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)))
  356. sta->ignore_plink_timer = true;
  357. sta->plink_state = PLINK_HOLDING;
  358. llid = sta->llid;
  359. plid = sta->plid;
  360. spin_unlock_bh(&sta->plink_lock);
  361. mesh_plink_frame_tx(sta->sdata->dev, PLINK_CLOSE, sta->addr, llid,
  362. plid, reason);
  363. return 0;
  364. }
  365. void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
  366. size_t len, struct ieee80211_rx_status *rx_status)
  367. {
  368. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  369. struct ieee80211_local *local = sdata->local;
  370. struct ieee802_11_elems elems;
  371. struct sta_info *sta;
  372. enum plink_event event;
  373. enum plink_frame_type ftype;
  374. size_t baselen;
  375. u8 ie_len;
  376. u8 *baseaddr;
  377. __le16 plid, llid, reason;
  378. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  379. DECLARE_MAC_BUF(mac);
  380. #endif
  381. if (is_multicast_ether_addr(mgmt->da)) {
  382. mpl_dbg("Mesh plink: ignore frame from multicast address");
  383. return;
  384. }
  385. baseaddr = mgmt->u.action.u.plink_action.variable;
  386. baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
  387. if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
  388. baseaddr += 4;
  389. baselen -= 4;
  390. }
  391. ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
  392. if (!elems.peer_link) {
  393. mpl_dbg("Mesh plink: missing necessary peer link ie\n");
  394. return;
  395. }
  396. ftype = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link));
  397. ie_len = elems.peer_link_len;
  398. if ((ftype == PLINK_OPEN && ie_len != 3) ||
  399. (ftype == PLINK_CONFIRM && ie_len != 5) ||
  400. (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) {
  401. mpl_dbg("Mesh plink: incorrect plink ie length\n");
  402. return;
  403. }
  404. if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
  405. mpl_dbg("Mesh plink: missing necessary ie\n");
  406. return;
  407. }
  408. /* Note the lines below are correct, the llid in the frame is the plid
  409. * from the point of view of this host.
  410. */
  411. memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
  412. if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7))
  413. memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
  414. rcu_read_lock();
  415. sta = sta_info_get(local, mgmt->sa);
  416. if (!sta && ftype != PLINK_OPEN) {
  417. mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
  418. rcu_read_unlock();
  419. return;
  420. }
  421. if (sta && sta->plink_state == PLINK_BLOCKED) {
  422. rcu_read_unlock();
  423. return;
  424. }
  425. /* Now we will figure out the appropriate event... */
  426. event = PLINK_UNDEFINED;
  427. if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, dev))) {
  428. switch (ftype) {
  429. case PLINK_OPEN:
  430. event = OPN_RJCT;
  431. break;
  432. case PLINK_CONFIRM:
  433. event = CNF_RJCT;
  434. break;
  435. case PLINK_CLOSE:
  436. /* avoid warning */
  437. break;
  438. }
  439. spin_lock_bh(&sta->plink_lock);
  440. } else if (!sta) {
  441. /* ftype == PLINK_OPEN */
  442. u64 rates;
  443. if (!mesh_plink_free_count(sdata)) {
  444. mpl_dbg("Mesh plink error: no more free plinks\n");
  445. rcu_read_unlock();
  446. return;
  447. }
  448. rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
  449. sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
  450. if (!sta) {
  451. mpl_dbg("Mesh plink error: plink table full\n");
  452. rcu_read_unlock();
  453. return;
  454. }
  455. if (sta_info_insert(sta)) {
  456. sta_info_destroy(sta);
  457. rcu_read_unlock();
  458. return;
  459. }
  460. event = OPN_ACPT;
  461. spin_lock_bh(&sta->plink_lock);
  462. } else {
  463. spin_lock_bh(&sta->plink_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->plink_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->plink_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->plink_lock);
  525. mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
  526. 0, 0);
  527. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr,
  528. llid, plid, 0);
  529. break;
  530. default:
  531. spin_unlock_bh(&sta->plink_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->plink_lock);
  550. mesh_plink_frame_tx(dev, PLINK_CLOSE, 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->plink_lock);
  559. mesh_plink_frame_tx(dev, PLINK_CONFIRM, 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->plink_lock);
  568. break;
  569. default:
  570. spin_unlock_bh(&sta->plink_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->plink_lock);
  589. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  590. plid, reason);
  591. break;
  592. case OPN_ACPT:
  593. llid = sta->llid;
  594. spin_unlock_bh(&sta->plink_lock);
  595. mesh_plink_frame_tx(dev, PLINK_CONFIRM, 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->plink_lock);
  603. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  604. print_mac(mac, sta->addr));
  605. break;
  606. default:
  607. spin_unlock_bh(&sta->plink_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->plink_lock);
  626. mesh_plink_frame_tx(dev, PLINK_CLOSE, 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->plink_lock);
  634. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  635. print_mac(mac, sta->addr));
  636. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  637. plid, 0);
  638. break;
  639. default:
  640. spin_unlock_bh(&sta->plink_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->plink_lock);
  654. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  655. plid, reason);
  656. break;
  657. case OPN_ACPT:
  658. llid = sta->llid;
  659. spin_unlock_bh(&sta->plink_lock);
  660. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  661. plid, 0);
  662. break;
  663. default:
  664. spin_unlock_bh(&sta->plink_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->plink_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->plink_lock);
  683. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  684. plid, reason);
  685. break;
  686. default:
  687. spin_unlock_bh(&sta->plink_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->plink_lock);
  695. break;
  696. }
  697. rcu_read_unlock();
  698. }