mesh_plink.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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 = 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 == ESTAB)
  108. mesh_plink_dec_estab_count(sdata);
  109. sta->plink_state = 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 == 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 OPN_RCVD:
  254. case 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 CNF_RCVD:
  274. /* confirm timer */
  275. if (!reason)
  276. reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
  277. sta->plink_state = 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 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 != LISTEN) {
  313. spin_unlock_bh(&sta->plink_lock);
  314. return -EBUSY;
  315. }
  316. sta->plink_state = 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 = 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 == LISTEN || sta->plink_state == BLOCKED) {
  347. mesh_plink_fsm_restart(sta);
  348. spin_unlock_bh(&sta->plink_lock);
  349. return 0;
  350. } else if (sta->plink_state == 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 = HOLDING;
  357. llid = sta->llid;
  358. plid = sta->plid;
  359. spin_unlock_bh(&sta->plink_lock);
  360. mesh_plink_frame_tx(sta->sdata->dev, PLINK_CLOSE, sta->addr, llid,
  361. plid, reason);
  362. return 0;
  363. }
  364. void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
  365. size_t len, struct ieee80211_rx_status *rx_status)
  366. {
  367. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  368. struct ieee80211_local *local = sdata->local;
  369. struct ieee802_11_elems elems;
  370. struct sta_info *sta;
  371. enum plink_event event;
  372. enum plink_frame_type ftype;
  373. size_t baselen;
  374. u8 ie_len;
  375. u8 *baseaddr;
  376. __le16 plid, llid, reason;
  377. #ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
  378. DECLARE_MAC_BUF(mac);
  379. #endif
  380. if (is_multicast_ether_addr(mgmt->da)) {
  381. mpl_dbg("Mesh plink: ignore frame from multicast address");
  382. return;
  383. }
  384. baseaddr = mgmt->u.action.u.plink_action.variable;
  385. baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
  386. if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
  387. baseaddr += 4;
  388. baselen -= 4;
  389. }
  390. ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
  391. if (!elems.peer_link) {
  392. mpl_dbg("Mesh plink: missing necessary peer link ie\n");
  393. return;
  394. }
  395. ftype = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link));
  396. ie_len = elems.peer_link_len;
  397. if ((ftype == PLINK_OPEN && ie_len != 3) ||
  398. (ftype == PLINK_CONFIRM && ie_len != 5) ||
  399. (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) {
  400. mpl_dbg("Mesh plink: incorrect plink ie length\n");
  401. return;
  402. }
  403. if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
  404. mpl_dbg("Mesh plink: missing necessary ie\n");
  405. return;
  406. }
  407. /* Note the lines below are correct, the llid in the frame is the plid
  408. * from the point of view of this host.
  409. */
  410. memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
  411. if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7))
  412. memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
  413. rcu_read_lock();
  414. sta = sta_info_get(local, mgmt->sa);
  415. if (!sta && ftype != PLINK_OPEN) {
  416. mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
  417. rcu_read_unlock();
  418. return;
  419. }
  420. if (sta && sta->plink_state == BLOCKED) {
  421. rcu_read_unlock();
  422. return;
  423. }
  424. /* Now we will figure out the appropriate event... */
  425. event = PLINK_UNDEFINED;
  426. if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, dev))) {
  427. switch (ftype) {
  428. case PLINK_OPEN:
  429. event = OPN_RJCT;
  430. break;
  431. case PLINK_CONFIRM:
  432. event = CNF_RJCT;
  433. break;
  434. case PLINK_CLOSE:
  435. /* avoid warning */
  436. break;
  437. }
  438. spin_lock_bh(&sta->plink_lock);
  439. } else if (!sta) {
  440. /* ftype == PLINK_OPEN */
  441. u64 rates;
  442. if (!mesh_plink_free_count(sdata)) {
  443. mpl_dbg("Mesh plink error: no more free plinks\n");
  444. rcu_read_unlock();
  445. return;
  446. }
  447. rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
  448. sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
  449. if (!sta) {
  450. mpl_dbg("Mesh plink error: plink table full\n");
  451. rcu_read_unlock();
  452. return;
  453. }
  454. if (sta_info_insert(sta)) {
  455. sta_info_destroy(sta);
  456. rcu_read_unlock();
  457. return;
  458. }
  459. event = OPN_ACPT;
  460. spin_lock_bh(&sta->plink_lock);
  461. } else {
  462. spin_lock_bh(&sta->plink_lock);
  463. switch (ftype) {
  464. case PLINK_OPEN:
  465. if (!mesh_plink_free_count(sdata) ||
  466. (sta->plid && sta->plid != plid))
  467. event = OPN_IGNR;
  468. else
  469. event = OPN_ACPT;
  470. break;
  471. case PLINK_CONFIRM:
  472. if (!mesh_plink_free_count(sdata) ||
  473. (sta->llid != llid || sta->plid != plid))
  474. event = CNF_IGNR;
  475. else
  476. event = CNF_ACPT;
  477. break;
  478. case PLINK_CLOSE:
  479. if (sta->plink_state == ESTAB)
  480. /* Do not check for llid or plid. This does not
  481. * follow the standard but since multiple plinks
  482. * per sta are not supported, it is necessary in
  483. * order to avoid a livelock when MP A sees an
  484. * establish peer link to MP B but MP B does not
  485. * see it. This can be caused by a timeout in
  486. * B's peer link establishment or B beign
  487. * restarted.
  488. */
  489. event = CLS_ACPT;
  490. else if (sta->plid != plid)
  491. event = CLS_IGNR;
  492. else if (ie_len == 7 && sta->llid != llid)
  493. event = CLS_IGNR;
  494. else
  495. event = CLS_ACPT;
  496. break;
  497. default:
  498. mpl_dbg("Mesh plink: unknown frame subtype\n");
  499. spin_unlock_bh(&sta->plink_lock);
  500. rcu_read_unlock();
  501. return;
  502. }
  503. }
  504. mpl_dbg("Mesh plink (peer, state, llid, plid, event): %s %d %d %d %d\n",
  505. print_mac(mac, mgmt->sa), sta->plink_state,
  506. le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
  507. event);
  508. reason = 0;
  509. switch (sta->plink_state) {
  510. /* spin_unlock as soon as state is updated at each case */
  511. case LISTEN:
  512. switch (event) {
  513. case CLS_ACPT:
  514. mesh_plink_fsm_restart(sta);
  515. spin_unlock_bh(&sta->plink_lock);
  516. break;
  517. case OPN_ACPT:
  518. sta->plink_state = OPN_RCVD;
  519. sta->plid = plid;
  520. get_random_bytes(&llid, 2);
  521. sta->llid = llid;
  522. mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
  523. spin_unlock_bh(&sta->plink_lock);
  524. mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
  525. 0, 0);
  526. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr,
  527. llid, plid, 0);
  528. break;
  529. default:
  530. spin_unlock_bh(&sta->plink_lock);
  531. break;
  532. }
  533. break;
  534. case OPN_SNT:
  535. switch (event) {
  536. case OPN_RJCT:
  537. case CNF_RJCT:
  538. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  539. case CLS_ACPT:
  540. if (!reason)
  541. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  542. sta->reason = reason;
  543. sta->plink_state = HOLDING;
  544. if (!mod_plink_timer(sta,
  545. dot11MeshHoldingTimeout(sdata)))
  546. sta->ignore_plink_timer = true;
  547. llid = sta->llid;
  548. spin_unlock_bh(&sta->plink_lock);
  549. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  550. plid, reason);
  551. break;
  552. case OPN_ACPT:
  553. /* retry timer is left untouched */
  554. sta->plink_state = OPN_RCVD;
  555. sta->plid = plid;
  556. llid = sta->llid;
  557. spin_unlock_bh(&sta->plink_lock);
  558. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  559. plid, 0);
  560. break;
  561. case CNF_ACPT:
  562. sta->plink_state = CNF_RCVD;
  563. if (!mod_plink_timer(sta,
  564. dot11MeshConfirmTimeout(sdata)))
  565. sta->ignore_plink_timer = true;
  566. spin_unlock_bh(&sta->plink_lock);
  567. break;
  568. default:
  569. spin_unlock_bh(&sta->plink_lock);
  570. break;
  571. }
  572. break;
  573. case OPN_RCVD:
  574. switch (event) {
  575. case OPN_RJCT:
  576. case CNF_RJCT:
  577. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  578. case CLS_ACPT:
  579. if (!reason)
  580. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  581. sta->reason = reason;
  582. sta->plink_state = HOLDING;
  583. if (!mod_plink_timer(sta,
  584. dot11MeshHoldingTimeout(sdata)))
  585. sta->ignore_plink_timer = true;
  586. llid = sta->llid;
  587. spin_unlock_bh(&sta->plink_lock);
  588. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  589. plid, reason);
  590. break;
  591. case OPN_ACPT:
  592. llid = sta->llid;
  593. spin_unlock_bh(&sta->plink_lock);
  594. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  595. plid, 0);
  596. break;
  597. case CNF_ACPT:
  598. del_timer(&sta->plink_timer);
  599. sta->plink_state = ESTAB;
  600. mesh_plink_inc_estab_count(sdata);
  601. spin_unlock_bh(&sta->plink_lock);
  602. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  603. print_mac(mac, sta->addr));
  604. break;
  605. default:
  606. spin_unlock_bh(&sta->plink_lock);
  607. break;
  608. }
  609. break;
  610. case CNF_RCVD:
  611. switch (event) {
  612. case OPN_RJCT:
  613. case CNF_RJCT:
  614. reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
  615. case CLS_ACPT:
  616. if (!reason)
  617. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  618. sta->reason = reason;
  619. sta->plink_state = HOLDING;
  620. if (!mod_plink_timer(sta,
  621. dot11MeshHoldingTimeout(sdata)))
  622. sta->ignore_plink_timer = true;
  623. llid = sta->llid;
  624. spin_unlock_bh(&sta->plink_lock);
  625. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  626. plid, reason);
  627. break;
  628. case OPN_ACPT:
  629. del_timer(&sta->plink_timer);
  630. sta->plink_state = ESTAB;
  631. mesh_plink_inc_estab_count(sdata);
  632. spin_unlock_bh(&sta->plink_lock);
  633. mpl_dbg("Mesh plink with %s ESTABLISHED\n",
  634. print_mac(mac, sta->addr));
  635. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  636. plid, 0);
  637. break;
  638. default:
  639. spin_unlock_bh(&sta->plink_lock);
  640. break;
  641. }
  642. break;
  643. case ESTAB:
  644. switch (event) {
  645. case CLS_ACPT:
  646. reason = cpu_to_le16(MESH_CLOSE_RCVD);
  647. sta->reason = reason;
  648. __mesh_plink_deactivate(sta);
  649. sta->plink_state = HOLDING;
  650. llid = sta->llid;
  651. mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
  652. spin_unlock_bh(&sta->plink_lock);
  653. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  654. plid, reason);
  655. break;
  656. case OPN_ACPT:
  657. llid = sta->llid;
  658. spin_unlock_bh(&sta->plink_lock);
  659. mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
  660. plid, 0);
  661. break;
  662. default:
  663. spin_unlock_bh(&sta->plink_lock);
  664. break;
  665. }
  666. break;
  667. case HOLDING:
  668. switch (event) {
  669. case CLS_ACPT:
  670. if (del_timer(&sta->plink_timer))
  671. sta->ignore_plink_timer = 1;
  672. mesh_plink_fsm_restart(sta);
  673. spin_unlock_bh(&sta->plink_lock);
  674. break;
  675. case OPN_ACPT:
  676. case CNF_ACPT:
  677. case OPN_RJCT:
  678. case CNF_RJCT:
  679. llid = sta->llid;
  680. reason = sta->reason;
  681. spin_unlock_bh(&sta->plink_lock);
  682. mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
  683. plid, reason);
  684. break;
  685. default:
  686. spin_unlock_bh(&sta->plink_lock);
  687. }
  688. break;
  689. default:
  690. /* should not get here, BLOCKED is dealt with at the beggining
  691. * of the function
  692. */
  693. spin_unlock_bh(&sta->plink_lock);
  694. break;
  695. }
  696. rcu_read_unlock();
  697. }