mesh_plink.c 31 KB

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