mesh_plink.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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 <linux/rculist.h>
  13. #include "ieee80211_i.h"
  14. #include "rate.h"
  15. #include "mesh.h"
  16. #define PLINK_CNF_AID(mgmt) ((mgmt)->u.action.u.self_prot.variable + 2)
  17. #define PLINK_GET_LLID(p) (p + 2)
  18. #define PLINK_GET_PLID(p) (p + 4)
  19. #define mod_plink_timer(s, t) (mod_timer(&s->mesh->plink_timer, \
  20. jiffies + msecs_to_jiffies(t)))
  21. enum plink_event {
  22. PLINK_UNDEFINED,
  23. OPN_ACPT,
  24. OPN_RJCT,
  25. OPN_IGNR,
  26. CNF_ACPT,
  27. CNF_RJCT,
  28. CNF_IGNR,
  29. CLS_ACPT,
  30. CLS_IGNR
  31. };
  32. static const char * const mplstates[] = {
  33. [NL80211_PLINK_LISTEN] = "LISTEN",
  34. [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
  35. [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
  36. [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
  37. [NL80211_PLINK_ESTAB] = "ESTAB",
  38. [NL80211_PLINK_HOLDING] = "HOLDING",
  39. [NL80211_PLINK_BLOCKED] = "BLOCKED"
  40. };
  41. static const char * const mplevents[] = {
  42. [PLINK_UNDEFINED] = "NONE",
  43. [OPN_ACPT] = "OPN_ACPT",
  44. [OPN_RJCT] = "OPN_RJCT",
  45. [OPN_IGNR] = "OPN_IGNR",
  46. [CNF_ACPT] = "CNF_ACPT",
  47. [CNF_RJCT] = "CNF_RJCT",
  48. [CNF_IGNR] = "CNF_IGNR",
  49. [CLS_ACPT] = "CLS_ACPT",
  50. [CLS_IGNR] = "CLS_IGNR"
  51. };
  52. /* We only need a valid sta if user configured a minimum rssi_threshold. */
  53. static bool rssi_threshold_check(struct ieee80211_sub_if_data *sdata,
  54. struct sta_info *sta)
  55. {
  56. s32 rssi_threshold = sdata->u.mesh.mshcfg.rssi_threshold;
  57. return rssi_threshold == 0 ||
  58. (sta &&
  59. (s8)-ewma_signal_read(&sta->rx_stats_avg.signal) >
  60. rssi_threshold);
  61. }
  62. /**
  63. * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
  64. *
  65. * @sta: mesh peer link to restart
  66. *
  67. * Locking: this function must be called holding sta->mesh->plink_lock
  68. */
  69. static inline void mesh_plink_fsm_restart(struct sta_info *sta)
  70. {
  71. lockdep_assert_held(&sta->mesh->plink_lock);
  72. sta->mesh->plink_state = NL80211_PLINK_LISTEN;
  73. sta->mesh->llid = sta->mesh->plid = sta->mesh->reason = 0;
  74. sta->mesh->plink_retries = 0;
  75. }
  76. /*
  77. * mesh_set_short_slot_time - enable / disable ERP short slot time.
  78. *
  79. * The standard indirectly mandates mesh STAs to turn off short slot time by
  80. * disallowing advertising this (802.11-2012 8.4.1.4), but that doesn't mean we
  81. * can't be sneaky about it. Enable short slot time if all mesh STAs in the
  82. * MBSS support ERP rates.
  83. *
  84. * Returns BSS_CHANGED_ERP_SLOT or 0 for no change.
  85. */
  86. static u32 mesh_set_short_slot_time(struct ieee80211_sub_if_data *sdata)
  87. {
  88. struct ieee80211_local *local = sdata->local;
  89. struct ieee80211_supported_band *sband;
  90. struct sta_info *sta;
  91. u32 erp_rates = 0, changed = 0;
  92. int i;
  93. bool short_slot = false;
  94. sband = ieee80211_get_sband(sdata);
  95. if (!sband)
  96. return changed;
  97. if (sband->band == NL80211_BAND_5GHZ) {
  98. /* (IEEE 802.11-2012 19.4.5) */
  99. short_slot = true;
  100. goto out;
  101. } else if (sband->band != NL80211_BAND_2GHZ) {
  102. goto out;
  103. }
  104. for (i = 0; i < sband->n_bitrates; i++)
  105. if (sband->bitrates[i].flags & IEEE80211_RATE_ERP_G)
  106. erp_rates |= BIT(i);
  107. if (!erp_rates)
  108. goto out;
  109. rcu_read_lock();
  110. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  111. if (sdata != sta->sdata ||
  112. sta->mesh->plink_state != NL80211_PLINK_ESTAB)
  113. continue;
  114. short_slot = false;
  115. if (erp_rates & sta->sta.supp_rates[sband->band])
  116. short_slot = true;
  117. else
  118. break;
  119. }
  120. rcu_read_unlock();
  121. out:
  122. if (sdata->vif.bss_conf.use_short_slot != short_slot) {
  123. sdata->vif.bss_conf.use_short_slot = short_slot;
  124. changed = BSS_CHANGED_ERP_SLOT;
  125. mpl_dbg(sdata, "mesh_plink %pM: ERP short slot time %d\n",
  126. sdata->vif.addr, short_slot);
  127. }
  128. return changed;
  129. }
  130. /**
  131. * mesh_set_ht_prot_mode - set correct HT protection mode
  132. *
  133. * Section 9.23.3.5 of IEEE 80211-2012 describes the protection rules for HT
  134. * mesh STA in a MBSS. Three HT protection modes are supported for now, non-HT
  135. * mixed mode, 20MHz-protection and no-protection mode. non-HT mixed mode is
  136. * selected if any non-HT peers are present in our MBSS. 20MHz-protection mode
  137. * is selected if all peers in our 20/40MHz MBSS support HT and atleast one
  138. * HT20 peer is present. Otherwise no-protection mode is selected.
  139. */
  140. static u32 mesh_set_ht_prot_mode(struct ieee80211_sub_if_data *sdata)
  141. {
  142. struct ieee80211_local *local = sdata->local;
  143. struct sta_info *sta;
  144. u16 ht_opmode;
  145. bool non_ht_sta = false, ht20_sta = false;
  146. switch (sdata->vif.bss_conf.chandef.width) {
  147. case NL80211_CHAN_WIDTH_20_NOHT:
  148. case NL80211_CHAN_WIDTH_5:
  149. case NL80211_CHAN_WIDTH_10:
  150. return 0;
  151. default:
  152. break;
  153. }
  154. rcu_read_lock();
  155. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  156. if (sdata != sta->sdata ||
  157. sta->mesh->plink_state != NL80211_PLINK_ESTAB)
  158. continue;
  159. if (sta->sta.bandwidth > IEEE80211_STA_RX_BW_20)
  160. continue;
  161. if (!sta->sta.ht_cap.ht_supported) {
  162. mpl_dbg(sdata, "nonHT sta (%pM) is present\n",
  163. sta->sta.addr);
  164. non_ht_sta = true;
  165. break;
  166. }
  167. mpl_dbg(sdata, "HT20 sta (%pM) is present\n", sta->sta.addr);
  168. ht20_sta = true;
  169. }
  170. rcu_read_unlock();
  171. if (non_ht_sta)
  172. ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED;
  173. else if (ht20_sta &&
  174. sdata->vif.bss_conf.chandef.width > NL80211_CHAN_WIDTH_20)
  175. ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_20MHZ;
  176. else
  177. ht_opmode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
  178. if (sdata->vif.bss_conf.ht_operation_mode == ht_opmode)
  179. return 0;
  180. sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
  181. sdata->u.mesh.mshcfg.ht_opmode = ht_opmode;
  182. mpl_dbg(sdata, "selected new HT protection mode %d\n", ht_opmode);
  183. return BSS_CHANGED_HT;
  184. }
  185. static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
  186. struct sta_info *sta,
  187. enum ieee80211_self_protected_actioncode action,
  188. u8 *da, u16 llid, u16 plid, u16 reason)
  189. {
  190. struct ieee80211_local *local = sdata->local;
  191. struct sk_buff *skb;
  192. struct ieee80211_tx_info *info;
  193. struct ieee80211_mgmt *mgmt;
  194. bool include_plid = false;
  195. u16 peering_proto = 0;
  196. u8 *pos, ie_len = 4;
  197. int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.self_prot) +
  198. sizeof(mgmt->u.action.u.self_prot);
  199. int err = -ENOMEM;
  200. skb = dev_alloc_skb(local->tx_headroom +
  201. hdr_len +
  202. 2 + /* capability info */
  203. 2 + /* AID */
  204. 2 + 8 + /* supported rates */
  205. 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
  206. 2 + sdata->u.mesh.mesh_id_len +
  207. 2 + sizeof(struct ieee80211_meshconf_ie) +
  208. 2 + sizeof(struct ieee80211_ht_cap) +
  209. 2 + sizeof(struct ieee80211_ht_operation) +
  210. 2 + sizeof(struct ieee80211_vht_cap) +
  211. 2 + sizeof(struct ieee80211_vht_operation) +
  212. 2 + 8 + /* peering IE */
  213. sdata->u.mesh.ie_len);
  214. if (!skb)
  215. return err;
  216. info = IEEE80211_SKB_CB(skb);
  217. skb_reserve(skb, local->tx_headroom);
  218. mgmt = skb_put_zero(skb, hdr_len);
  219. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  220. IEEE80211_STYPE_ACTION);
  221. memcpy(mgmt->da, da, ETH_ALEN);
  222. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  223. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  224. mgmt->u.action.category = WLAN_CATEGORY_SELF_PROTECTED;
  225. mgmt->u.action.u.self_prot.action_code = action;
  226. if (action != WLAN_SP_MESH_PEERING_CLOSE) {
  227. struct ieee80211_supported_band *sband;
  228. enum nl80211_band band;
  229. sband = ieee80211_get_sband(sdata);
  230. if (!sband) {
  231. err = -EINVAL;
  232. goto free;
  233. }
  234. band = sband->band;
  235. /* capability info */
  236. pos = skb_put_zero(skb, 2);
  237. if (action == WLAN_SP_MESH_PEERING_CONFIRM) {
  238. /* AID */
  239. pos = skb_put(skb, 2);
  240. put_unaligned_le16(sta->sta.aid, pos);
  241. }
  242. if (ieee80211_add_srates_ie(sdata, skb, true, band) ||
  243. ieee80211_add_ext_srates_ie(sdata, skb, true, band) ||
  244. mesh_add_rsn_ie(sdata, skb) ||
  245. mesh_add_meshid_ie(sdata, skb) ||
  246. mesh_add_meshconf_ie(sdata, skb))
  247. goto free;
  248. } else { /* WLAN_SP_MESH_PEERING_CLOSE */
  249. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  250. if (mesh_add_meshid_ie(sdata, skb))
  251. goto free;
  252. }
  253. /* Add Mesh Peering Management element */
  254. switch (action) {
  255. case WLAN_SP_MESH_PEERING_OPEN:
  256. break;
  257. case WLAN_SP_MESH_PEERING_CONFIRM:
  258. ie_len += 2;
  259. include_plid = true;
  260. break;
  261. case WLAN_SP_MESH_PEERING_CLOSE:
  262. if (plid) {
  263. ie_len += 2;
  264. include_plid = true;
  265. }
  266. ie_len += 2; /* reason code */
  267. break;
  268. default:
  269. err = -EINVAL;
  270. goto free;
  271. }
  272. if (WARN_ON(skb_tailroom(skb) < 2 + ie_len))
  273. goto free;
  274. pos = skb_put(skb, 2 + ie_len);
  275. *pos++ = WLAN_EID_PEER_MGMT;
  276. *pos++ = ie_len;
  277. memcpy(pos, &peering_proto, 2);
  278. pos += 2;
  279. put_unaligned_le16(llid, pos);
  280. pos += 2;
  281. if (include_plid) {
  282. put_unaligned_le16(plid, pos);
  283. pos += 2;
  284. }
  285. if (action == WLAN_SP_MESH_PEERING_CLOSE) {
  286. put_unaligned_le16(reason, pos);
  287. pos += 2;
  288. }
  289. if (action != WLAN_SP_MESH_PEERING_CLOSE) {
  290. if (mesh_add_ht_cap_ie(sdata, skb) ||
  291. mesh_add_ht_oper_ie(sdata, skb) ||
  292. mesh_add_vht_cap_ie(sdata, skb) ||
  293. mesh_add_vht_oper_ie(sdata, skb))
  294. goto free;
  295. }
  296. if (mesh_add_vendor_ies(sdata, skb))
  297. goto free;
  298. ieee80211_tx_skb(sdata, skb);
  299. return 0;
  300. free:
  301. kfree_skb(skb);
  302. return err;
  303. }
  304. /**
  305. * __mesh_plink_deactivate - deactivate mesh peer link
  306. *
  307. * @sta: mesh peer link to deactivate
  308. *
  309. * Mesh paths with this peer as next hop should be flushed
  310. * by the caller outside of plink_lock.
  311. *
  312. * Returns beacon changed flag if the beacon content changed.
  313. *
  314. * Locking: the caller must hold sta->mesh->plink_lock
  315. */
  316. static u32 __mesh_plink_deactivate(struct sta_info *sta)
  317. {
  318. struct ieee80211_sub_if_data *sdata = sta->sdata;
  319. u32 changed = 0;
  320. lockdep_assert_held(&sta->mesh->plink_lock);
  321. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  322. changed = mesh_plink_dec_estab_count(sdata);
  323. sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
  324. ieee80211_mps_sta_status_update(sta);
  325. changed |= ieee80211_mps_set_sta_local_pm(sta,
  326. NL80211_MESH_POWER_UNKNOWN);
  327. return changed;
  328. }
  329. /**
  330. * mesh_plink_deactivate - deactivate mesh peer link
  331. *
  332. * @sta: mesh peer link to deactivate
  333. *
  334. * All mesh paths with this peer as next hop will be flushed
  335. */
  336. u32 mesh_plink_deactivate(struct sta_info *sta)
  337. {
  338. struct ieee80211_sub_if_data *sdata = sta->sdata;
  339. u32 changed;
  340. spin_lock_bh(&sta->mesh->plink_lock);
  341. changed = __mesh_plink_deactivate(sta);
  342. if (!sdata->u.mesh.user_mpm) {
  343. sta->mesh->reason = WLAN_REASON_MESH_PEER_CANCELED;
  344. mesh_plink_frame_tx(sdata, sta, WLAN_SP_MESH_PEERING_CLOSE,
  345. sta->sta.addr, sta->mesh->llid,
  346. sta->mesh->plid, sta->mesh->reason);
  347. }
  348. spin_unlock_bh(&sta->mesh->plink_lock);
  349. if (!sdata->u.mesh.user_mpm)
  350. del_timer_sync(&sta->mesh->plink_timer);
  351. mesh_path_flush_by_nexthop(sta);
  352. /* make sure no readers can access nexthop sta from here on */
  353. synchronize_net();
  354. return changed;
  355. }
  356. static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
  357. struct sta_info *sta,
  358. struct ieee802_11_elems *elems, bool insert)
  359. {
  360. struct ieee80211_local *local = sdata->local;
  361. struct ieee80211_supported_band *sband;
  362. u32 rates, basic_rates = 0, changed = 0;
  363. enum ieee80211_sta_rx_bandwidth bw = sta->sta.bandwidth;
  364. sband = ieee80211_get_sband(sdata);
  365. if (!sband)
  366. return;
  367. rates = ieee80211_sta_get_rates(sdata, elems, sband->band,
  368. &basic_rates);
  369. spin_lock_bh(&sta->mesh->plink_lock);
  370. sta->rx_stats.last_rx = jiffies;
  371. /* rates and capabilities don't change during peering */
  372. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB &&
  373. sta->mesh->processed_beacon)
  374. goto out;
  375. sta->mesh->processed_beacon = true;
  376. if (sta->sta.supp_rates[sband->band] != rates)
  377. changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
  378. sta->sta.supp_rates[sband->band] = rates;
  379. if (ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  380. elems->ht_cap_elem, sta))
  381. changed |= IEEE80211_RC_BW_CHANGED;
  382. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  383. elems->vht_cap_elem, sta);
  384. if (bw != sta->sta.bandwidth)
  385. changed |= IEEE80211_RC_BW_CHANGED;
  386. /* HT peer is operating 20MHz-only */
  387. if (elems->ht_operation &&
  388. !(elems->ht_operation->ht_param &
  389. IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
  390. if (sta->sta.bandwidth != IEEE80211_STA_RX_BW_20)
  391. changed |= IEEE80211_RC_BW_CHANGED;
  392. sta->sta.bandwidth = IEEE80211_STA_RX_BW_20;
  393. }
  394. if (insert)
  395. rate_control_rate_init(sta);
  396. else
  397. rate_control_rate_update(local, sband, sta, changed);
  398. out:
  399. spin_unlock_bh(&sta->mesh->plink_lock);
  400. }
  401. static int mesh_allocate_aid(struct ieee80211_sub_if_data *sdata)
  402. {
  403. struct sta_info *sta;
  404. unsigned long *aid_map;
  405. int aid;
  406. aid_map = kcalloc(BITS_TO_LONGS(IEEE80211_MAX_AID + 1),
  407. sizeof(*aid_map), GFP_KERNEL);
  408. if (!aid_map)
  409. return -ENOMEM;
  410. /* reserve aid 0 for mcast indication */
  411. __set_bit(0, aid_map);
  412. rcu_read_lock();
  413. list_for_each_entry_rcu(sta, &sdata->local->sta_list, list)
  414. __set_bit(sta->sta.aid, aid_map);
  415. rcu_read_unlock();
  416. aid = find_first_zero_bit(aid_map, IEEE80211_MAX_AID + 1);
  417. kfree(aid_map);
  418. if (aid > IEEE80211_MAX_AID)
  419. return -ENOBUFS;
  420. return aid;
  421. }
  422. static struct sta_info *
  423. __mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
  424. {
  425. struct sta_info *sta;
  426. int aid;
  427. if (sdata->local->num_sta >= MESH_MAX_PLINKS)
  428. return NULL;
  429. aid = mesh_allocate_aid(sdata);
  430. if (aid < 0)
  431. return NULL;
  432. sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
  433. if (!sta)
  434. return NULL;
  435. sta->mesh->plink_state = NL80211_PLINK_LISTEN;
  436. sta->sta.wme = true;
  437. sta->sta.aid = aid;
  438. sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
  439. sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
  440. sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
  441. return sta;
  442. }
  443. static struct sta_info *
  444. mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
  445. struct ieee802_11_elems *elems)
  446. {
  447. struct sta_info *sta = NULL;
  448. /* Userspace handles station allocation */
  449. if (sdata->u.mesh.user_mpm ||
  450. sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) {
  451. if (mesh_peer_accepts_plinks(elems) &&
  452. mesh_plink_availables(sdata))
  453. cfg80211_notify_new_peer_candidate(sdata->dev, addr,
  454. elems->ie_start,
  455. elems->total_len,
  456. GFP_KERNEL);
  457. } else
  458. sta = __mesh_sta_info_alloc(sdata, addr);
  459. return sta;
  460. }
  461. /*
  462. * mesh_sta_info_get - return mesh sta info entry for @addr.
  463. *
  464. * @sdata: local meshif
  465. * @addr: peer's address
  466. * @elems: IEs from beacon or mesh peering frame.
  467. *
  468. * Return existing or newly allocated sta_info under RCU read lock.
  469. * (re)initialize with given IEs.
  470. */
  471. static struct sta_info *
  472. mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
  473. u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU)
  474. {
  475. struct sta_info *sta = NULL;
  476. rcu_read_lock();
  477. sta = sta_info_get(sdata, addr);
  478. if (sta) {
  479. mesh_sta_info_init(sdata, sta, elems, false);
  480. } else {
  481. rcu_read_unlock();
  482. /* can't run atomic */
  483. sta = mesh_sta_info_alloc(sdata, addr, elems);
  484. if (!sta) {
  485. rcu_read_lock();
  486. return NULL;
  487. }
  488. mesh_sta_info_init(sdata, sta, elems, true);
  489. if (sta_info_insert_rcu(sta))
  490. return NULL;
  491. }
  492. return sta;
  493. }
  494. /*
  495. * mesh_neighbour_update - update or initialize new mesh neighbor.
  496. *
  497. * @sdata: local meshif
  498. * @addr: peer's address
  499. * @elems: IEs from beacon or mesh peering frame
  500. *
  501. * Initiates peering if appropriate.
  502. */
  503. void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
  504. u8 *hw_addr,
  505. struct ieee802_11_elems *elems)
  506. {
  507. struct sta_info *sta;
  508. u32 changed = 0;
  509. sta = mesh_sta_info_get(sdata, hw_addr, elems);
  510. if (!sta)
  511. goto out;
  512. if (mesh_peer_accepts_plinks(elems) &&
  513. sta->mesh->plink_state == NL80211_PLINK_LISTEN &&
  514. sdata->u.mesh.accepting_plinks &&
  515. sdata->u.mesh.mshcfg.auto_open_plinks &&
  516. rssi_threshold_check(sdata, sta))
  517. changed = mesh_plink_open(sta);
  518. ieee80211_mps_frame_release(sta, elems);
  519. out:
  520. rcu_read_unlock();
  521. ieee80211_mbss_info_change_notify(sdata, changed);
  522. }
  523. static void mesh_plink_timer(unsigned long data)
  524. {
  525. struct sta_info *sta;
  526. u16 reason = 0;
  527. struct ieee80211_sub_if_data *sdata;
  528. struct mesh_config *mshcfg;
  529. enum ieee80211_self_protected_actioncode action = 0;
  530. /*
  531. * This STA is valid because sta_info_destroy() will
  532. * del_timer_sync() this timer after having made sure
  533. * it cannot be readded (by deleting the plink.)
  534. */
  535. sta = (struct sta_info *) data;
  536. if (sta->sdata->local->quiescing)
  537. return;
  538. spin_lock_bh(&sta->mesh->plink_lock);
  539. /* If a timer fires just before a state transition on another CPU,
  540. * we may have already extended the timeout and changed state by the
  541. * time we've acquired the lock and arrived here. In that case,
  542. * skip this timer and wait for the new one.
  543. */
  544. if (time_before(jiffies, sta->mesh->plink_timer.expires)) {
  545. mpl_dbg(sta->sdata,
  546. "Ignoring timer for %pM in state %s (timer adjusted)",
  547. sta->sta.addr, mplstates[sta->mesh->plink_state]);
  548. spin_unlock_bh(&sta->mesh->plink_lock);
  549. return;
  550. }
  551. /* del_timer() and handler may race when entering these states */
  552. if (sta->mesh->plink_state == NL80211_PLINK_LISTEN ||
  553. sta->mesh->plink_state == NL80211_PLINK_ESTAB) {
  554. mpl_dbg(sta->sdata,
  555. "Ignoring timer for %pM in state %s (timer deleted)",
  556. sta->sta.addr, mplstates[sta->mesh->plink_state]);
  557. spin_unlock_bh(&sta->mesh->plink_lock);
  558. return;
  559. }
  560. mpl_dbg(sta->sdata,
  561. "Mesh plink timer for %pM fired on state %s\n",
  562. sta->sta.addr, mplstates[sta->mesh->plink_state]);
  563. sdata = sta->sdata;
  564. mshcfg = &sdata->u.mesh.mshcfg;
  565. switch (sta->mesh->plink_state) {
  566. case NL80211_PLINK_OPN_RCVD:
  567. case NL80211_PLINK_OPN_SNT:
  568. /* retry timer */
  569. if (sta->mesh->plink_retries < mshcfg->dot11MeshMaxRetries) {
  570. u32 rand;
  571. mpl_dbg(sta->sdata,
  572. "Mesh plink for %pM (retry, timeout): %d %d\n",
  573. sta->sta.addr, sta->mesh->plink_retries,
  574. sta->mesh->plink_timeout);
  575. get_random_bytes(&rand, sizeof(u32));
  576. sta->mesh->plink_timeout = sta->mesh->plink_timeout +
  577. rand % sta->mesh->plink_timeout;
  578. ++sta->mesh->plink_retries;
  579. mod_plink_timer(sta, sta->mesh->plink_timeout);
  580. action = WLAN_SP_MESH_PEERING_OPEN;
  581. break;
  582. }
  583. reason = WLAN_REASON_MESH_MAX_RETRIES;
  584. /* fall through on else */
  585. case NL80211_PLINK_CNF_RCVD:
  586. /* confirm timer */
  587. if (!reason)
  588. reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
  589. sta->mesh->plink_state = NL80211_PLINK_HOLDING;
  590. mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
  591. action = WLAN_SP_MESH_PEERING_CLOSE;
  592. break;
  593. case NL80211_PLINK_HOLDING:
  594. /* holding timer */
  595. del_timer(&sta->mesh->plink_timer);
  596. mesh_plink_fsm_restart(sta);
  597. break;
  598. default:
  599. break;
  600. }
  601. spin_unlock_bh(&sta->mesh->plink_lock);
  602. if (action)
  603. mesh_plink_frame_tx(sdata, sta, action, sta->sta.addr,
  604. sta->mesh->llid, sta->mesh->plid, reason);
  605. }
  606. static inline void mesh_plink_timer_set(struct sta_info *sta, u32 timeout)
  607. {
  608. sta->mesh->plink_timer.expires = jiffies + msecs_to_jiffies(timeout);
  609. sta->mesh->plink_timer.data = (unsigned long) sta;
  610. sta->mesh->plink_timer.function = mesh_plink_timer;
  611. sta->mesh->plink_timeout = timeout;
  612. add_timer(&sta->mesh->plink_timer);
  613. }
  614. static bool llid_in_use(struct ieee80211_sub_if_data *sdata,
  615. u16 llid)
  616. {
  617. struct ieee80211_local *local = sdata->local;
  618. bool in_use = false;
  619. struct sta_info *sta;
  620. rcu_read_lock();
  621. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  622. if (sdata != sta->sdata)
  623. continue;
  624. if (!memcmp(&sta->mesh->llid, &llid, sizeof(llid))) {
  625. in_use = true;
  626. break;
  627. }
  628. }
  629. rcu_read_unlock();
  630. return in_use;
  631. }
  632. static u16 mesh_get_new_llid(struct ieee80211_sub_if_data *sdata)
  633. {
  634. u16 llid;
  635. do {
  636. get_random_bytes(&llid, sizeof(llid));
  637. } while (llid_in_use(sdata, llid));
  638. return llid;
  639. }
  640. u32 mesh_plink_open(struct sta_info *sta)
  641. {
  642. struct ieee80211_sub_if_data *sdata = sta->sdata;
  643. u32 changed;
  644. if (!test_sta_flag(sta, WLAN_STA_AUTH))
  645. return 0;
  646. spin_lock_bh(&sta->mesh->plink_lock);
  647. sta->mesh->llid = mesh_get_new_llid(sdata);
  648. if (sta->mesh->plink_state != NL80211_PLINK_LISTEN &&
  649. sta->mesh->plink_state != NL80211_PLINK_BLOCKED) {
  650. spin_unlock_bh(&sta->mesh->plink_lock);
  651. return 0;
  652. }
  653. sta->mesh->plink_state = NL80211_PLINK_OPN_SNT;
  654. mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
  655. spin_unlock_bh(&sta->mesh->plink_lock);
  656. mpl_dbg(sdata,
  657. "Mesh plink: starting establishment with %pM\n",
  658. sta->sta.addr);
  659. /* set the non-peer mode to active during peering */
  660. changed = ieee80211_mps_local_status_update(sdata);
  661. mesh_plink_frame_tx(sdata, sta, WLAN_SP_MESH_PEERING_OPEN,
  662. sta->sta.addr, sta->mesh->llid, 0, 0);
  663. return changed;
  664. }
  665. u32 mesh_plink_block(struct sta_info *sta)
  666. {
  667. u32 changed;
  668. spin_lock_bh(&sta->mesh->plink_lock);
  669. changed = __mesh_plink_deactivate(sta);
  670. sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
  671. spin_unlock_bh(&sta->mesh->plink_lock);
  672. mesh_path_flush_by_nexthop(sta);
  673. return changed;
  674. }
  675. static void mesh_plink_close(struct ieee80211_sub_if_data *sdata,
  676. struct sta_info *sta,
  677. enum plink_event event)
  678. {
  679. struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
  680. u16 reason = (event == CLS_ACPT) ?
  681. WLAN_REASON_MESH_CLOSE : WLAN_REASON_MESH_CONFIG;
  682. sta->mesh->reason = reason;
  683. sta->mesh->plink_state = NL80211_PLINK_HOLDING;
  684. mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
  685. }
  686. static u32 mesh_plink_establish(struct ieee80211_sub_if_data *sdata,
  687. struct sta_info *sta)
  688. {
  689. struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
  690. u32 changed = 0;
  691. del_timer(&sta->mesh->plink_timer);
  692. sta->mesh->plink_state = NL80211_PLINK_ESTAB;
  693. changed |= mesh_plink_inc_estab_count(sdata);
  694. changed |= mesh_set_ht_prot_mode(sdata);
  695. changed |= mesh_set_short_slot_time(sdata);
  696. mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n", sta->sta.addr);
  697. ieee80211_mps_sta_status_update(sta);
  698. changed |= ieee80211_mps_set_sta_local_pm(sta, mshcfg->power_mode);
  699. return changed;
  700. }
  701. /**
  702. * mesh_plink_fsm - step @sta MPM based on @event
  703. *
  704. * @sdata: interface
  705. * @sta: mesh neighbor
  706. * @event: peering event
  707. *
  708. * Return: changed MBSS flags
  709. */
  710. static u32 mesh_plink_fsm(struct ieee80211_sub_if_data *sdata,
  711. struct sta_info *sta, enum plink_event event)
  712. {
  713. struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
  714. enum ieee80211_self_protected_actioncode action = 0;
  715. u32 changed = 0;
  716. bool flush = false;
  717. mpl_dbg(sdata, "peer %pM in state %s got event %s\n", sta->sta.addr,
  718. mplstates[sta->mesh->plink_state], mplevents[event]);
  719. spin_lock_bh(&sta->mesh->plink_lock);
  720. switch (sta->mesh->plink_state) {
  721. case NL80211_PLINK_LISTEN:
  722. switch (event) {
  723. case CLS_ACPT:
  724. mesh_plink_fsm_restart(sta);
  725. break;
  726. case OPN_ACPT:
  727. sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
  728. sta->mesh->llid = mesh_get_new_llid(sdata);
  729. mesh_plink_timer_set(sta,
  730. mshcfg->dot11MeshRetryTimeout);
  731. /* set the non-peer mode to active during peering */
  732. changed |= ieee80211_mps_local_status_update(sdata);
  733. action = WLAN_SP_MESH_PEERING_OPEN;
  734. break;
  735. default:
  736. break;
  737. }
  738. break;
  739. case NL80211_PLINK_OPN_SNT:
  740. switch (event) {
  741. case OPN_RJCT:
  742. case CNF_RJCT:
  743. case CLS_ACPT:
  744. mesh_plink_close(sdata, sta, event);
  745. action = WLAN_SP_MESH_PEERING_CLOSE;
  746. break;
  747. case OPN_ACPT:
  748. /* retry timer is left untouched */
  749. sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
  750. action = WLAN_SP_MESH_PEERING_CONFIRM;
  751. break;
  752. case CNF_ACPT:
  753. sta->mesh->plink_state = NL80211_PLINK_CNF_RCVD;
  754. mod_plink_timer(sta, mshcfg->dot11MeshConfirmTimeout);
  755. break;
  756. default:
  757. break;
  758. }
  759. break;
  760. case NL80211_PLINK_OPN_RCVD:
  761. switch (event) {
  762. case OPN_RJCT:
  763. case CNF_RJCT:
  764. case CLS_ACPT:
  765. mesh_plink_close(sdata, sta, event);
  766. action = WLAN_SP_MESH_PEERING_CLOSE;
  767. break;
  768. case OPN_ACPT:
  769. action = WLAN_SP_MESH_PEERING_CONFIRM;
  770. break;
  771. case CNF_ACPT:
  772. changed |= mesh_plink_establish(sdata, sta);
  773. break;
  774. default:
  775. break;
  776. }
  777. break;
  778. case NL80211_PLINK_CNF_RCVD:
  779. switch (event) {
  780. case OPN_RJCT:
  781. case CNF_RJCT:
  782. case CLS_ACPT:
  783. mesh_plink_close(sdata, sta, event);
  784. action = WLAN_SP_MESH_PEERING_CLOSE;
  785. break;
  786. case OPN_ACPT:
  787. changed |= mesh_plink_establish(sdata, sta);
  788. action = WLAN_SP_MESH_PEERING_CONFIRM;
  789. break;
  790. default:
  791. break;
  792. }
  793. break;
  794. case NL80211_PLINK_ESTAB:
  795. switch (event) {
  796. case CLS_ACPT:
  797. changed |= __mesh_plink_deactivate(sta);
  798. changed |= mesh_set_ht_prot_mode(sdata);
  799. changed |= mesh_set_short_slot_time(sdata);
  800. mesh_plink_close(sdata, sta, event);
  801. action = WLAN_SP_MESH_PEERING_CLOSE;
  802. flush = true;
  803. break;
  804. case OPN_ACPT:
  805. action = WLAN_SP_MESH_PEERING_CONFIRM;
  806. break;
  807. default:
  808. break;
  809. }
  810. break;
  811. case NL80211_PLINK_HOLDING:
  812. switch (event) {
  813. case CLS_ACPT:
  814. del_timer(&sta->mesh->plink_timer);
  815. mesh_plink_fsm_restart(sta);
  816. break;
  817. case OPN_ACPT:
  818. case CNF_ACPT:
  819. case OPN_RJCT:
  820. case CNF_RJCT:
  821. action = WLAN_SP_MESH_PEERING_CLOSE;
  822. break;
  823. default:
  824. break;
  825. }
  826. break;
  827. default:
  828. /* should not get here, PLINK_BLOCKED is dealt with at the
  829. * beginning of the function
  830. */
  831. break;
  832. }
  833. spin_unlock_bh(&sta->mesh->plink_lock);
  834. if (flush)
  835. mesh_path_flush_by_nexthop(sta);
  836. if (action) {
  837. mesh_plink_frame_tx(sdata, sta, action, sta->sta.addr,
  838. sta->mesh->llid, sta->mesh->plid,
  839. sta->mesh->reason);
  840. /* also send confirm in open case */
  841. if (action == WLAN_SP_MESH_PEERING_OPEN) {
  842. mesh_plink_frame_tx(sdata, sta,
  843. WLAN_SP_MESH_PEERING_CONFIRM,
  844. sta->sta.addr, sta->mesh->llid,
  845. sta->mesh->plid, 0);
  846. }
  847. }
  848. return changed;
  849. }
  850. /*
  851. * mesh_plink_get_event - get correct MPM event
  852. *
  853. * @sdata: interface
  854. * @sta: peer, leave NULL if processing a frame from a new suitable peer
  855. * @elems: peering management IEs
  856. * @ftype: frame type
  857. * @llid: peer's peer link ID
  858. * @plid: peer's local link ID
  859. *
  860. * Return: new peering event for @sta, but PLINK_UNDEFINED should be treated as
  861. * an error.
  862. */
  863. static enum plink_event
  864. mesh_plink_get_event(struct ieee80211_sub_if_data *sdata,
  865. struct sta_info *sta,
  866. struct ieee802_11_elems *elems,
  867. enum ieee80211_self_protected_actioncode ftype,
  868. u16 llid, u16 plid)
  869. {
  870. enum plink_event event = PLINK_UNDEFINED;
  871. u8 ie_len = elems->peering_len;
  872. bool matches_local;
  873. matches_local = (ftype == WLAN_SP_MESH_PEERING_CLOSE ||
  874. mesh_matches_local(sdata, elems));
  875. /* deny open request from non-matching peer */
  876. if (!matches_local && !sta) {
  877. event = OPN_RJCT;
  878. goto out;
  879. }
  880. if (!sta) {
  881. if (ftype != WLAN_SP_MESH_PEERING_OPEN) {
  882. mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
  883. goto out;
  884. }
  885. /* ftype == WLAN_SP_MESH_PEERING_OPEN */
  886. if (!mesh_plink_free_count(sdata)) {
  887. mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
  888. goto out;
  889. }
  890. /* new matching peer */
  891. event = OPN_ACPT;
  892. goto out;
  893. } else {
  894. if (!test_sta_flag(sta, WLAN_STA_AUTH)) {
  895. mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
  896. goto out;
  897. }
  898. if (sta->mesh->plink_state == NL80211_PLINK_BLOCKED)
  899. goto out;
  900. }
  901. switch (ftype) {
  902. case WLAN_SP_MESH_PEERING_OPEN:
  903. if (!matches_local)
  904. event = OPN_RJCT;
  905. if (!mesh_plink_free_count(sdata) ||
  906. (sta->mesh->plid && sta->mesh->plid != plid))
  907. event = OPN_IGNR;
  908. else
  909. event = OPN_ACPT;
  910. break;
  911. case WLAN_SP_MESH_PEERING_CONFIRM:
  912. if (!matches_local)
  913. event = CNF_RJCT;
  914. if (!mesh_plink_free_count(sdata) ||
  915. sta->mesh->llid != llid ||
  916. (sta->mesh->plid && sta->mesh->plid != plid))
  917. event = CNF_IGNR;
  918. else
  919. event = CNF_ACPT;
  920. break;
  921. case WLAN_SP_MESH_PEERING_CLOSE:
  922. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  923. /* Do not check for llid or plid. This does not
  924. * follow the standard but since multiple plinks
  925. * per sta are not supported, it is necessary in
  926. * order to avoid a livelock when MP A sees an
  927. * establish peer link to MP B but MP B does not
  928. * see it. This can be caused by a timeout in
  929. * B's peer link establishment or B beign
  930. * restarted.
  931. */
  932. event = CLS_ACPT;
  933. else if (sta->mesh->plid != plid)
  934. event = CLS_IGNR;
  935. else if (ie_len == 8 && sta->mesh->llid != llid)
  936. event = CLS_IGNR;
  937. else
  938. event = CLS_ACPT;
  939. break;
  940. default:
  941. mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
  942. break;
  943. }
  944. out:
  945. return event;
  946. }
  947. static void
  948. mesh_process_plink_frame(struct ieee80211_sub_if_data *sdata,
  949. struct ieee80211_mgmt *mgmt,
  950. struct ieee802_11_elems *elems)
  951. {
  952. struct sta_info *sta;
  953. enum plink_event event;
  954. enum ieee80211_self_protected_actioncode ftype;
  955. u32 changed = 0;
  956. u8 ie_len = elems->peering_len;
  957. u16 plid, llid = 0;
  958. if (!elems->peering) {
  959. mpl_dbg(sdata,
  960. "Mesh plink: missing necessary peer link ie\n");
  961. return;
  962. }
  963. if (elems->rsn_len &&
  964. sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
  965. mpl_dbg(sdata,
  966. "Mesh plink: can't establish link with secure peer\n");
  967. return;
  968. }
  969. ftype = mgmt->u.action.u.self_prot.action_code;
  970. if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
  971. (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
  972. (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
  973. && ie_len != 8)) {
  974. mpl_dbg(sdata,
  975. "Mesh plink: incorrect plink ie length %d %d\n",
  976. ftype, ie_len);
  977. return;
  978. }
  979. if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
  980. (!elems->mesh_id || !elems->mesh_config)) {
  981. mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
  982. return;
  983. }
  984. /* Note the lines below are correct, the llid in the frame is the plid
  985. * from the point of view of this host.
  986. */
  987. plid = get_unaligned_le16(PLINK_GET_LLID(elems->peering));
  988. if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
  989. (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
  990. llid = get_unaligned_le16(PLINK_GET_PLID(elems->peering));
  991. /* WARNING: Only for sta pointer, is dropped & re-acquired */
  992. rcu_read_lock();
  993. sta = sta_info_get(sdata, mgmt->sa);
  994. if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
  995. !rssi_threshold_check(sdata, sta)) {
  996. mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
  997. mgmt->sa);
  998. goto unlock_rcu;
  999. }
  1000. /* Now we will figure out the appropriate event... */
  1001. event = mesh_plink_get_event(sdata, sta, elems, ftype, llid, plid);
  1002. if (event == OPN_ACPT) {
  1003. rcu_read_unlock();
  1004. /* allocate sta entry if necessary and update info */
  1005. sta = mesh_sta_info_get(sdata, mgmt->sa, elems);
  1006. if (!sta) {
  1007. mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
  1008. goto unlock_rcu;
  1009. }
  1010. sta->mesh->plid = plid;
  1011. } else if (!sta && event == OPN_RJCT) {
  1012. mesh_plink_frame_tx(sdata, NULL, WLAN_SP_MESH_PEERING_CLOSE,
  1013. mgmt->sa, 0, plid,
  1014. WLAN_REASON_MESH_CONFIG);
  1015. goto unlock_rcu;
  1016. } else if (!sta || event == PLINK_UNDEFINED) {
  1017. /* something went wrong */
  1018. goto unlock_rcu;
  1019. }
  1020. if (event == CNF_ACPT) {
  1021. /* 802.11-2012 13.3.7.2 - update plid on CNF if not set */
  1022. if (!sta->mesh->plid)
  1023. sta->mesh->plid = plid;
  1024. sta->mesh->aid = get_unaligned_le16(PLINK_CNF_AID(mgmt));
  1025. }
  1026. changed |= mesh_plink_fsm(sdata, sta, event);
  1027. unlock_rcu:
  1028. rcu_read_unlock();
  1029. if (changed)
  1030. ieee80211_mbss_info_change_notify(sdata, changed);
  1031. }
  1032. void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
  1033. struct ieee80211_mgmt *mgmt, size_t len,
  1034. struct ieee80211_rx_status *rx_status)
  1035. {
  1036. struct ieee802_11_elems elems;
  1037. size_t baselen;
  1038. u8 *baseaddr;
  1039. /* need action_code, aux */
  1040. if (len < IEEE80211_MIN_ACTION_SIZE + 3)
  1041. return;
  1042. if (sdata->u.mesh.user_mpm)
  1043. /* userspace must register for these */
  1044. return;
  1045. if (is_multicast_ether_addr(mgmt->da)) {
  1046. mpl_dbg(sdata,
  1047. "Mesh plink: ignore frame from multicast address\n");
  1048. return;
  1049. }
  1050. baseaddr = mgmt->u.action.u.self_prot.variable;
  1051. baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
  1052. if (mgmt->u.action.u.self_prot.action_code ==
  1053. WLAN_SP_MESH_PEERING_CONFIRM) {
  1054. baseaddr += 4;
  1055. baselen += 4;
  1056. if (baselen > len)
  1057. return;
  1058. }
  1059. ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
  1060. mesh_process_plink_frame(sdata, mgmt, &elems);
  1061. }