mesh_plink.c 31 KB

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