mesh_plink.c 31 KB

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