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