mesh_plink.c 20 KB

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