mesh_plink.c 30 KB

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