mesh_plink.c 20 KB

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