mesh_plink.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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. if (mesh_peer_accepts_plinks(elems) &&
  433. mesh_plink_availables(sdata))
  434. cfg80211_notify_new_peer_candidate(sdata->dev, addr,
  435. elems->ie_start,
  436. elems->total_len,
  437. GFP_KERNEL);
  438. } else
  439. sta = __mesh_sta_info_alloc(sdata, addr);
  440. return sta;
  441. }
  442. /*
  443. * mesh_sta_info_get - return mesh sta info entry for @addr.
  444. *
  445. * @sdata: local meshif
  446. * @addr: peer's address
  447. * @elems: IEs from beacon or mesh peering frame.
  448. *
  449. * Return existing or newly allocated sta_info under RCU read lock.
  450. * (re)initialize with given IEs.
  451. */
  452. static struct sta_info *
  453. mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
  454. u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU)
  455. {
  456. struct sta_info *sta = NULL;
  457. rcu_read_lock();
  458. sta = sta_info_get(sdata, addr);
  459. if (sta) {
  460. mesh_sta_info_init(sdata, sta, elems, false);
  461. } else {
  462. rcu_read_unlock();
  463. /* can't run atomic */
  464. sta = mesh_sta_info_alloc(sdata, addr, elems);
  465. if (!sta) {
  466. rcu_read_lock();
  467. return NULL;
  468. }
  469. mesh_sta_info_init(sdata, sta, elems, true);
  470. if (sta_info_insert_rcu(sta))
  471. return NULL;
  472. }
  473. return sta;
  474. }
  475. /*
  476. * mesh_neighbour_update - update or initialize new mesh neighbor.
  477. *
  478. * @sdata: local meshif
  479. * @addr: peer's address
  480. * @elems: IEs from beacon or mesh peering frame
  481. *
  482. * Initiates peering if appropriate.
  483. */
  484. void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
  485. u8 *hw_addr,
  486. struct ieee802_11_elems *elems)
  487. {
  488. struct sta_info *sta;
  489. u32 changed = 0;
  490. sta = mesh_sta_info_get(sdata, hw_addr, elems);
  491. if (!sta)
  492. goto out;
  493. if (mesh_peer_accepts_plinks(elems) &&
  494. sta->mesh->plink_state == NL80211_PLINK_LISTEN &&
  495. sdata->u.mesh.accepting_plinks &&
  496. sdata->u.mesh.mshcfg.auto_open_plinks &&
  497. rssi_threshold_check(sdata, sta))
  498. changed = mesh_plink_open(sta);
  499. ieee80211_mps_frame_release(sta, elems);
  500. out:
  501. rcu_read_unlock();
  502. ieee80211_mbss_info_change_notify(sdata, changed);
  503. }
  504. static void mesh_plink_timer(unsigned long data)
  505. {
  506. struct sta_info *sta;
  507. u16 reason = 0;
  508. struct ieee80211_sub_if_data *sdata;
  509. struct mesh_config *mshcfg;
  510. enum ieee80211_self_protected_actioncode action = 0;
  511. /*
  512. * This STA is valid because sta_info_destroy() will
  513. * del_timer_sync() this timer after having made sure
  514. * it cannot be readded (by deleting the plink.)
  515. */
  516. sta = (struct sta_info *) data;
  517. if (sta->sdata->local->quiescing)
  518. return;
  519. spin_lock_bh(&sta->mesh->plink_lock);
  520. /* If a timer fires just before a state transition on another CPU,
  521. * we may have already extended the timeout and changed state by the
  522. * time we've acquired the lock and arrived here. In that case,
  523. * skip this timer and wait for the new one.
  524. */
  525. if (time_before(jiffies, sta->mesh->plink_timer.expires)) {
  526. mpl_dbg(sta->sdata,
  527. "Ignoring timer for %pM in state %s (timer adjusted)",
  528. sta->sta.addr, mplstates[sta->mesh->plink_state]);
  529. spin_unlock_bh(&sta->mesh->plink_lock);
  530. return;
  531. }
  532. /* del_timer() and handler may race when entering these states */
  533. if (sta->mesh->plink_state == NL80211_PLINK_LISTEN ||
  534. sta->mesh->plink_state == NL80211_PLINK_ESTAB) {
  535. mpl_dbg(sta->sdata,
  536. "Ignoring timer for %pM in state %s (timer deleted)",
  537. sta->sta.addr, mplstates[sta->mesh->plink_state]);
  538. spin_unlock_bh(&sta->mesh->plink_lock);
  539. return;
  540. }
  541. mpl_dbg(sta->sdata,
  542. "Mesh plink timer for %pM fired on state %s\n",
  543. sta->sta.addr, mplstates[sta->mesh->plink_state]);
  544. sdata = sta->sdata;
  545. mshcfg = &sdata->u.mesh.mshcfg;
  546. switch (sta->mesh->plink_state) {
  547. case NL80211_PLINK_OPN_RCVD:
  548. case NL80211_PLINK_OPN_SNT:
  549. /* retry timer */
  550. if (sta->mesh->plink_retries < mshcfg->dot11MeshMaxRetries) {
  551. u32 rand;
  552. mpl_dbg(sta->sdata,
  553. "Mesh plink for %pM (retry, timeout): %d %d\n",
  554. sta->sta.addr, sta->mesh->plink_retries,
  555. sta->mesh->plink_timeout);
  556. get_random_bytes(&rand, sizeof(u32));
  557. sta->mesh->plink_timeout = sta->mesh->plink_timeout +
  558. rand % sta->mesh->plink_timeout;
  559. ++sta->mesh->plink_retries;
  560. mod_plink_timer(sta, sta->mesh->plink_timeout);
  561. action = WLAN_SP_MESH_PEERING_OPEN;
  562. break;
  563. }
  564. reason = WLAN_REASON_MESH_MAX_RETRIES;
  565. /* fall through on else */
  566. case NL80211_PLINK_CNF_RCVD:
  567. /* confirm timer */
  568. if (!reason)
  569. reason = WLAN_REASON_MESH_CONFIRM_TIMEOUT;
  570. sta->mesh->plink_state = NL80211_PLINK_HOLDING;
  571. mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
  572. action = WLAN_SP_MESH_PEERING_CLOSE;
  573. break;
  574. case NL80211_PLINK_HOLDING:
  575. /* holding timer */
  576. del_timer(&sta->mesh->plink_timer);
  577. mesh_plink_fsm_restart(sta);
  578. break;
  579. default:
  580. break;
  581. }
  582. spin_unlock_bh(&sta->mesh->plink_lock);
  583. if (action)
  584. mesh_plink_frame_tx(sdata, sta, action, sta->sta.addr,
  585. sta->mesh->llid, sta->mesh->plid, reason);
  586. }
  587. static inline void mesh_plink_timer_set(struct sta_info *sta, u32 timeout)
  588. {
  589. sta->mesh->plink_timer.expires = jiffies + msecs_to_jiffies(timeout);
  590. sta->mesh->plink_timer.data = (unsigned long) sta;
  591. sta->mesh->plink_timer.function = mesh_plink_timer;
  592. sta->mesh->plink_timeout = timeout;
  593. add_timer(&sta->mesh->plink_timer);
  594. }
  595. static bool llid_in_use(struct ieee80211_sub_if_data *sdata,
  596. u16 llid)
  597. {
  598. struct ieee80211_local *local = sdata->local;
  599. bool in_use = false;
  600. struct sta_info *sta;
  601. rcu_read_lock();
  602. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  603. if (sdata != sta->sdata)
  604. continue;
  605. if (!memcmp(&sta->mesh->llid, &llid, sizeof(llid))) {
  606. in_use = true;
  607. break;
  608. }
  609. }
  610. rcu_read_unlock();
  611. return in_use;
  612. }
  613. static u16 mesh_get_new_llid(struct ieee80211_sub_if_data *sdata)
  614. {
  615. u16 llid;
  616. do {
  617. get_random_bytes(&llid, sizeof(llid));
  618. } while (llid_in_use(sdata, llid));
  619. return llid;
  620. }
  621. u32 mesh_plink_open(struct sta_info *sta)
  622. {
  623. struct ieee80211_sub_if_data *sdata = sta->sdata;
  624. u32 changed;
  625. if (!test_sta_flag(sta, WLAN_STA_AUTH))
  626. return 0;
  627. spin_lock_bh(&sta->mesh->plink_lock);
  628. sta->mesh->llid = mesh_get_new_llid(sdata);
  629. if (sta->mesh->plink_state != NL80211_PLINK_LISTEN &&
  630. sta->mesh->plink_state != NL80211_PLINK_BLOCKED) {
  631. spin_unlock_bh(&sta->mesh->plink_lock);
  632. return 0;
  633. }
  634. sta->mesh->plink_state = NL80211_PLINK_OPN_SNT;
  635. mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
  636. spin_unlock_bh(&sta->mesh->plink_lock);
  637. mpl_dbg(sdata,
  638. "Mesh plink: starting establishment with %pM\n",
  639. sta->sta.addr);
  640. /* set the non-peer mode to active during peering */
  641. changed = ieee80211_mps_local_status_update(sdata);
  642. mesh_plink_frame_tx(sdata, sta, WLAN_SP_MESH_PEERING_OPEN,
  643. sta->sta.addr, sta->mesh->llid, 0, 0);
  644. return changed;
  645. }
  646. u32 mesh_plink_block(struct sta_info *sta)
  647. {
  648. u32 changed;
  649. spin_lock_bh(&sta->mesh->plink_lock);
  650. changed = __mesh_plink_deactivate(sta);
  651. sta->mesh->plink_state = NL80211_PLINK_BLOCKED;
  652. spin_unlock_bh(&sta->mesh->plink_lock);
  653. return changed;
  654. }
  655. static void mesh_plink_close(struct ieee80211_sub_if_data *sdata,
  656. struct sta_info *sta,
  657. enum plink_event event)
  658. {
  659. struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
  660. u16 reason = (event == CLS_ACPT) ?
  661. WLAN_REASON_MESH_CLOSE : WLAN_REASON_MESH_CONFIG;
  662. sta->mesh->reason = reason;
  663. sta->mesh->plink_state = NL80211_PLINK_HOLDING;
  664. mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
  665. }
  666. static u32 mesh_plink_establish(struct ieee80211_sub_if_data *sdata,
  667. struct sta_info *sta)
  668. {
  669. struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
  670. u32 changed = 0;
  671. del_timer(&sta->mesh->plink_timer);
  672. sta->mesh->plink_state = NL80211_PLINK_ESTAB;
  673. changed |= mesh_plink_inc_estab_count(sdata);
  674. changed |= mesh_set_ht_prot_mode(sdata);
  675. changed |= mesh_set_short_slot_time(sdata);
  676. mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n", sta->sta.addr);
  677. ieee80211_mps_sta_status_update(sta);
  678. changed |= ieee80211_mps_set_sta_local_pm(sta, mshcfg->power_mode);
  679. return changed;
  680. }
  681. /**
  682. * mesh_plink_fsm - step @sta MPM based on @event
  683. *
  684. * @sdata: interface
  685. * @sta: mesh neighbor
  686. * @event: peering event
  687. *
  688. * Return: changed MBSS flags
  689. */
  690. static u32 mesh_plink_fsm(struct ieee80211_sub_if_data *sdata,
  691. struct sta_info *sta, enum plink_event event)
  692. {
  693. struct mesh_config *mshcfg = &sdata->u.mesh.mshcfg;
  694. enum ieee80211_self_protected_actioncode action = 0;
  695. u32 changed = 0;
  696. mpl_dbg(sdata, "peer %pM in state %s got event %s\n", sta->sta.addr,
  697. mplstates[sta->mesh->plink_state], mplevents[event]);
  698. spin_lock_bh(&sta->mesh->plink_lock);
  699. switch (sta->mesh->plink_state) {
  700. case NL80211_PLINK_LISTEN:
  701. switch (event) {
  702. case CLS_ACPT:
  703. mesh_plink_fsm_restart(sta);
  704. break;
  705. case OPN_ACPT:
  706. sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
  707. sta->mesh->llid = mesh_get_new_llid(sdata);
  708. mesh_plink_timer_set(sta,
  709. mshcfg->dot11MeshRetryTimeout);
  710. /* set the non-peer mode to active during peering */
  711. changed |= ieee80211_mps_local_status_update(sdata);
  712. action = WLAN_SP_MESH_PEERING_OPEN;
  713. break;
  714. default:
  715. break;
  716. }
  717. break;
  718. case NL80211_PLINK_OPN_SNT:
  719. switch (event) {
  720. case OPN_RJCT:
  721. case CNF_RJCT:
  722. case CLS_ACPT:
  723. mesh_plink_close(sdata, sta, event);
  724. action = WLAN_SP_MESH_PEERING_CLOSE;
  725. break;
  726. case OPN_ACPT:
  727. /* retry timer is left untouched */
  728. sta->mesh->plink_state = NL80211_PLINK_OPN_RCVD;
  729. action = WLAN_SP_MESH_PEERING_CONFIRM;
  730. break;
  731. case CNF_ACPT:
  732. sta->mesh->plink_state = NL80211_PLINK_CNF_RCVD;
  733. mod_plink_timer(sta, mshcfg->dot11MeshConfirmTimeout);
  734. break;
  735. default:
  736. break;
  737. }
  738. break;
  739. case NL80211_PLINK_OPN_RCVD:
  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. action = WLAN_SP_MESH_PEERING_CONFIRM;
  749. break;
  750. case CNF_ACPT:
  751. changed |= mesh_plink_establish(sdata, sta);
  752. break;
  753. default:
  754. break;
  755. }
  756. break;
  757. case NL80211_PLINK_CNF_RCVD:
  758. switch (event) {
  759. case OPN_RJCT:
  760. case CNF_RJCT:
  761. case CLS_ACPT:
  762. mesh_plink_close(sdata, sta, event);
  763. action = WLAN_SP_MESH_PEERING_CLOSE;
  764. break;
  765. case OPN_ACPT:
  766. changed |= mesh_plink_establish(sdata, sta);
  767. action = WLAN_SP_MESH_PEERING_CONFIRM;
  768. break;
  769. default:
  770. break;
  771. }
  772. break;
  773. case NL80211_PLINK_ESTAB:
  774. switch (event) {
  775. case CLS_ACPT:
  776. changed |= __mesh_plink_deactivate(sta);
  777. changed |= mesh_set_ht_prot_mode(sdata);
  778. changed |= mesh_set_short_slot_time(sdata);
  779. mesh_plink_close(sdata, sta, event);
  780. action = WLAN_SP_MESH_PEERING_CLOSE;
  781. break;
  782. case OPN_ACPT:
  783. action = WLAN_SP_MESH_PEERING_CONFIRM;
  784. break;
  785. default:
  786. break;
  787. }
  788. break;
  789. case NL80211_PLINK_HOLDING:
  790. switch (event) {
  791. case CLS_ACPT:
  792. del_timer(&sta->mesh->plink_timer);
  793. mesh_plink_fsm_restart(sta);
  794. break;
  795. case OPN_ACPT:
  796. case CNF_ACPT:
  797. case OPN_RJCT:
  798. case CNF_RJCT:
  799. action = WLAN_SP_MESH_PEERING_CLOSE;
  800. break;
  801. default:
  802. break;
  803. }
  804. break;
  805. default:
  806. /* should not get here, PLINK_BLOCKED is dealt with at the
  807. * beginning of the function
  808. */
  809. break;
  810. }
  811. spin_unlock_bh(&sta->mesh->plink_lock);
  812. if (action) {
  813. mesh_plink_frame_tx(sdata, sta, action, sta->sta.addr,
  814. sta->mesh->llid, sta->mesh->plid,
  815. sta->mesh->reason);
  816. /* also send confirm in open case */
  817. if (action == WLAN_SP_MESH_PEERING_OPEN) {
  818. mesh_plink_frame_tx(sdata, sta,
  819. WLAN_SP_MESH_PEERING_CONFIRM,
  820. sta->sta.addr, sta->mesh->llid,
  821. sta->mesh->plid, 0);
  822. }
  823. }
  824. return changed;
  825. }
  826. /*
  827. * mesh_plink_get_event - get correct MPM event
  828. *
  829. * @sdata: interface
  830. * @sta: peer, leave NULL if processing a frame from a new suitable peer
  831. * @elems: peering management IEs
  832. * @ftype: frame type
  833. * @llid: peer's peer link ID
  834. * @plid: peer's local link ID
  835. *
  836. * Return: new peering event for @sta, but PLINK_UNDEFINED should be treated as
  837. * an error.
  838. */
  839. static enum plink_event
  840. mesh_plink_get_event(struct ieee80211_sub_if_data *sdata,
  841. struct sta_info *sta,
  842. struct ieee802_11_elems *elems,
  843. enum ieee80211_self_protected_actioncode ftype,
  844. u16 llid, u16 plid)
  845. {
  846. enum plink_event event = PLINK_UNDEFINED;
  847. u8 ie_len = elems->peering_len;
  848. bool matches_local;
  849. matches_local = (ftype == WLAN_SP_MESH_PEERING_CLOSE ||
  850. mesh_matches_local(sdata, elems));
  851. /* deny open request from non-matching peer */
  852. if (!matches_local && !sta) {
  853. event = OPN_RJCT;
  854. goto out;
  855. }
  856. if (!sta) {
  857. if (ftype != WLAN_SP_MESH_PEERING_OPEN) {
  858. mpl_dbg(sdata, "Mesh plink: cls or cnf from unknown peer\n");
  859. goto out;
  860. }
  861. /* ftype == WLAN_SP_MESH_PEERING_OPEN */
  862. if (!mesh_plink_free_count(sdata)) {
  863. mpl_dbg(sdata, "Mesh plink error: no more free plinks\n");
  864. goto out;
  865. }
  866. } else {
  867. if (!test_sta_flag(sta, WLAN_STA_AUTH)) {
  868. mpl_dbg(sdata, "Mesh plink: Action frame from non-authed peer\n");
  869. goto out;
  870. }
  871. if (sta->mesh->plink_state == NL80211_PLINK_BLOCKED)
  872. goto out;
  873. }
  874. /* new matching peer */
  875. if (!sta) {
  876. event = OPN_ACPT;
  877. goto out;
  878. }
  879. switch (ftype) {
  880. case WLAN_SP_MESH_PEERING_OPEN:
  881. if (!matches_local)
  882. event = OPN_RJCT;
  883. if (!mesh_plink_free_count(sdata) ||
  884. (sta->mesh->plid && sta->mesh->plid != plid))
  885. event = OPN_IGNR;
  886. else
  887. event = OPN_ACPT;
  888. break;
  889. case WLAN_SP_MESH_PEERING_CONFIRM:
  890. if (!matches_local)
  891. event = CNF_RJCT;
  892. if (!mesh_plink_free_count(sdata) ||
  893. sta->mesh->llid != llid ||
  894. (sta->mesh->plid && sta->mesh->plid != plid))
  895. event = CNF_IGNR;
  896. else
  897. event = CNF_ACPT;
  898. break;
  899. case WLAN_SP_MESH_PEERING_CLOSE:
  900. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  901. /* Do not check for llid or plid. This does not
  902. * follow the standard but since multiple plinks
  903. * per sta are not supported, it is necessary in
  904. * order to avoid a livelock when MP A sees an
  905. * establish peer link to MP B but MP B does not
  906. * see it. This can be caused by a timeout in
  907. * B's peer link establishment or B beign
  908. * restarted.
  909. */
  910. event = CLS_ACPT;
  911. else if (sta->mesh->plid != plid)
  912. event = CLS_IGNR;
  913. else if (ie_len == 8 && sta->mesh->llid != llid)
  914. event = CLS_IGNR;
  915. else
  916. event = CLS_ACPT;
  917. break;
  918. default:
  919. mpl_dbg(sdata, "Mesh plink: unknown frame subtype\n");
  920. break;
  921. }
  922. out:
  923. return event;
  924. }
  925. static void
  926. mesh_process_plink_frame(struct ieee80211_sub_if_data *sdata,
  927. struct ieee80211_mgmt *mgmt,
  928. struct ieee802_11_elems *elems)
  929. {
  930. struct sta_info *sta;
  931. enum plink_event event;
  932. enum ieee80211_self_protected_actioncode ftype;
  933. u32 changed = 0;
  934. u8 ie_len = elems->peering_len;
  935. u16 plid, llid = 0;
  936. if (!elems->peering) {
  937. mpl_dbg(sdata,
  938. "Mesh plink: missing necessary peer link ie\n");
  939. return;
  940. }
  941. if (elems->rsn_len &&
  942. sdata->u.mesh.security == IEEE80211_MESH_SEC_NONE) {
  943. mpl_dbg(sdata,
  944. "Mesh plink: can't establish link with secure peer\n");
  945. return;
  946. }
  947. ftype = mgmt->u.action.u.self_prot.action_code;
  948. if ((ftype == WLAN_SP_MESH_PEERING_OPEN && ie_len != 4) ||
  949. (ftype == WLAN_SP_MESH_PEERING_CONFIRM && ie_len != 6) ||
  950. (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len != 6
  951. && ie_len != 8)) {
  952. mpl_dbg(sdata,
  953. "Mesh plink: incorrect plink ie length %d %d\n",
  954. ftype, ie_len);
  955. return;
  956. }
  957. if (ftype != WLAN_SP_MESH_PEERING_CLOSE &&
  958. (!elems->mesh_id || !elems->mesh_config)) {
  959. mpl_dbg(sdata, "Mesh plink: missing necessary ie\n");
  960. return;
  961. }
  962. /* Note the lines below are correct, the llid in the frame is the plid
  963. * from the point of view of this host.
  964. */
  965. plid = get_unaligned_le16(PLINK_GET_LLID(elems->peering));
  966. if (ftype == WLAN_SP_MESH_PEERING_CONFIRM ||
  967. (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
  968. llid = get_unaligned_le16(PLINK_GET_PLID(elems->peering));
  969. /* WARNING: Only for sta pointer, is dropped & re-acquired */
  970. rcu_read_lock();
  971. sta = sta_info_get(sdata, mgmt->sa);
  972. if (ftype == WLAN_SP_MESH_PEERING_OPEN &&
  973. !rssi_threshold_check(sdata, sta)) {
  974. mpl_dbg(sdata, "Mesh plink: %pM does not meet rssi threshold\n",
  975. mgmt->sa);
  976. goto unlock_rcu;
  977. }
  978. /* Now we will figure out the appropriate event... */
  979. event = mesh_plink_get_event(sdata, sta, elems, ftype, llid, plid);
  980. if (event == OPN_ACPT) {
  981. rcu_read_unlock();
  982. /* allocate sta entry if necessary and update info */
  983. sta = mesh_sta_info_get(sdata, mgmt->sa, elems);
  984. if (!sta) {
  985. mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
  986. goto unlock_rcu;
  987. }
  988. sta->mesh->plid = plid;
  989. } else if (!sta && event == OPN_RJCT) {
  990. mesh_plink_frame_tx(sdata, NULL, WLAN_SP_MESH_PEERING_CLOSE,
  991. mgmt->sa, 0, plid,
  992. WLAN_REASON_MESH_CONFIG);
  993. goto unlock_rcu;
  994. } else if (!sta || event == PLINK_UNDEFINED) {
  995. /* something went wrong */
  996. goto unlock_rcu;
  997. }
  998. if (event == CNF_ACPT) {
  999. /* 802.11-2012 13.3.7.2 - update plid on CNF if not set */
  1000. if (!sta->mesh->plid)
  1001. sta->mesh->plid = plid;
  1002. sta->mesh->aid = get_unaligned_le16(PLINK_CNF_AID(mgmt));
  1003. }
  1004. changed |= mesh_plink_fsm(sdata, sta, event);
  1005. unlock_rcu:
  1006. rcu_read_unlock();
  1007. if (changed)
  1008. ieee80211_mbss_info_change_notify(sdata, changed);
  1009. }
  1010. void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
  1011. struct ieee80211_mgmt *mgmt, size_t len,
  1012. struct ieee80211_rx_status *rx_status)
  1013. {
  1014. struct ieee802_11_elems elems;
  1015. size_t baselen;
  1016. u8 *baseaddr;
  1017. /* need action_code, aux */
  1018. if (len < IEEE80211_MIN_ACTION_SIZE + 3)
  1019. return;
  1020. if (sdata->u.mesh.user_mpm)
  1021. /* userspace must register for these */
  1022. return;
  1023. if (is_multicast_ether_addr(mgmt->da)) {
  1024. mpl_dbg(sdata,
  1025. "Mesh plink: ignore frame from multicast address\n");
  1026. return;
  1027. }
  1028. baseaddr = mgmt->u.action.u.self_prot.variable;
  1029. baselen = (u8 *) mgmt->u.action.u.self_prot.variable - (u8 *) mgmt;
  1030. if (mgmt->u.action.u.self_prot.action_code ==
  1031. WLAN_SP_MESH_PEERING_CONFIRM) {
  1032. baseaddr += 4;
  1033. baselen += 4;
  1034. if (baselen > len)
  1035. return;
  1036. }
  1037. ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
  1038. mesh_process_plink_frame(sdata, mgmt, &elems);
  1039. }