mesh_plink.c 20 KB

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