mesh_plink.c 31 KB

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