mesh_plink.c 31 KB

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