mesh_ps.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2012-2013, Marco Porsch <marco.porsch@s2005.tu-chemnitz.de>
  4. * Copyright 2012-2013, cozybit Inc.
  5. * Copyright (C) 2021 Intel Corporation
  6. * Copyright (C) 2023 Intel Corporation
  7. */
  8. #include "mesh.h"
  9. #include "wme.h"
  10. /* mesh PS management */
  11. /**
  12. * mps_qos_null_get - create pre-addressed QoS Null frame for mesh powersave
  13. * @sta: the station to get the frame for
  14. *
  15. * Returns: A newly allocated SKB
  16. */
  17. static struct sk_buff *mps_qos_null_get(struct sta_info *sta)
  18. {
  19. struct ieee80211_sub_if_data *sdata = sta->sdata;
  20. struct ieee80211_local *local = sdata->local;
  21. struct ieee80211_hdr *nullfunc; /* use 4addr header */
  22. struct sk_buff *skb;
  23. int size = sizeof(*nullfunc);
  24. __le16 fc;
  25. skb = dev_alloc_skb(local->hw.extra_tx_headroom + size + 2);
  26. if (!skb)
  27. return NULL;
  28. skb_reserve(skb, local->hw.extra_tx_headroom);
  29. nullfunc = skb_put(skb, size);
  30. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
  31. ieee80211_fill_mesh_addresses(nullfunc, &fc, sta->sta.addr,
  32. sdata->vif.addr);
  33. nullfunc->frame_control = fc;
  34. nullfunc->duration_id = 0;
  35. nullfunc->seq_ctrl = 0;
  36. /* no address resolution for this frame -> set addr 1 immediately */
  37. memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
  38. skb_put_zero(skb, 2); /* append QoS control field */
  39. ieee80211_mps_set_frame_flags(sdata, sta, nullfunc);
  40. return skb;
  41. }
  42. /**
  43. * mps_qos_null_tx - send a QoS Null to indicate link-specific power mode
  44. * @sta: the station to send to
  45. */
  46. static void mps_qos_null_tx(struct sta_info *sta)
  47. {
  48. struct sk_buff *skb;
  49. skb = mps_qos_null_get(sta);
  50. if (!skb)
  51. return;
  52. mps_dbg(sta->sdata, "announcing peer-specific power mode to %pM\n",
  53. sta->sta.addr);
  54. /* don't unintentionally start a MPSP */
  55. if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
  56. u8 *qc = ieee80211_get_qos_ctl((void *) skb->data);
  57. qc[0] |= IEEE80211_QOS_CTL_EOSP;
  58. }
  59. ieee80211_tx_skb(sta->sdata, skb);
  60. }
  61. /**
  62. * ieee80211_mps_local_status_update - track status of local link-specific PMs
  63. *
  64. * @sdata: local mesh subif
  65. *
  66. * sets the non-peer power mode and triggers the driver PS (re-)configuration
  67. * Return BSS_CHANGED_BEACON if a beacon update is necessary.
  68. *
  69. * Returns: BSS_CHANGED_BEACON if a beacon update is in order.
  70. */
  71. u64 ieee80211_mps_local_status_update(struct ieee80211_sub_if_data *sdata)
  72. {
  73. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  74. struct sta_info *sta;
  75. bool peering = false;
  76. int light_sleep_cnt = 0;
  77. int deep_sleep_cnt = 0;
  78. u64 changed = 0;
  79. enum nl80211_mesh_power_mode nonpeer_pm;
  80. rcu_read_lock();
  81. list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
  82. if (sdata != sta->sdata)
  83. continue;
  84. switch (sta->mesh->plink_state) {
  85. case NL80211_PLINK_OPN_SNT:
  86. case NL80211_PLINK_OPN_RCVD:
  87. case NL80211_PLINK_CNF_RCVD:
  88. peering = true;
  89. break;
  90. case NL80211_PLINK_ESTAB:
  91. if (sta->mesh->local_pm == NL80211_MESH_POWER_LIGHT_SLEEP)
  92. light_sleep_cnt++;
  93. else if (sta->mesh->local_pm == NL80211_MESH_POWER_DEEP_SLEEP)
  94. deep_sleep_cnt++;
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. rcu_read_unlock();
  101. /*
  102. * Set non-peer mode to active during peering/scanning/authentication
  103. * (see IEEE802.11-2012 13.14.8.3). The non-peer mesh power mode is
  104. * deep sleep if the local STA is in light or deep sleep towards at
  105. * least one mesh peer (see 13.14.3.1). Otherwise, set it to the
  106. * user-configured default value.
  107. */
  108. if (peering) {
  109. mps_dbg(sdata, "setting non-peer PM to active for peering\n");
  110. nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
  111. } else if (light_sleep_cnt || deep_sleep_cnt) {
  112. mps_dbg(sdata, "setting non-peer PM to deep sleep\n");
  113. nonpeer_pm = NL80211_MESH_POWER_DEEP_SLEEP;
  114. } else {
  115. mps_dbg(sdata, "setting non-peer PM to user value\n");
  116. nonpeer_pm = ifmsh->mshcfg.power_mode;
  117. }
  118. /* need update if sleep counts move between 0 and non-zero */
  119. if (ifmsh->nonpeer_pm != nonpeer_pm ||
  120. !ifmsh->ps_peers_light_sleep != !light_sleep_cnt ||
  121. !ifmsh->ps_peers_deep_sleep != !deep_sleep_cnt)
  122. changed = BSS_CHANGED_BEACON;
  123. ifmsh->nonpeer_pm = nonpeer_pm;
  124. ifmsh->ps_peers_light_sleep = light_sleep_cnt;
  125. ifmsh->ps_peers_deep_sleep = deep_sleep_cnt;
  126. return changed;
  127. }
  128. /**
  129. * ieee80211_mps_set_sta_local_pm - set local PM towards a mesh STA
  130. *
  131. * @sta: mesh STA
  132. * @pm: the power mode to set
  133. * Returns: BSS_CHANGED_BEACON if a beacon update is in order.
  134. */
  135. u64 ieee80211_mps_set_sta_local_pm(struct sta_info *sta,
  136. enum nl80211_mesh_power_mode pm)
  137. {
  138. struct ieee80211_sub_if_data *sdata = sta->sdata;
  139. if (sta->mesh->local_pm == pm)
  140. return 0;
  141. mps_dbg(sdata, "local STA operates in mode %d with %pM\n",
  142. pm, sta->sta.addr);
  143. sta->mesh->local_pm = pm;
  144. /*
  145. * announce peer-specific power mode transition
  146. * (see IEEE802.11-2012 13.14.3.2 and 13.14.3.3)
  147. */
  148. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  149. mps_qos_null_tx(sta);
  150. return ieee80211_mps_local_status_update(sdata);
  151. }
  152. /**
  153. * ieee80211_mps_set_frame_flags - set mesh PS flags in FC (and QoS Control)
  154. *
  155. * @sdata: local mesh subif
  156. * @sta: mesh STA
  157. * @hdr: 802.11 frame header
  158. *
  159. * see IEEE802.11-2012 8.2.4.1.7 and 8.2.4.5.11
  160. *
  161. * NOTE: sta must be given when an individually-addressed QoS frame header
  162. * is handled, for group-addressed and management frames it is not used
  163. */
  164. void ieee80211_mps_set_frame_flags(struct ieee80211_sub_if_data *sdata,
  165. struct sta_info *sta,
  166. struct ieee80211_hdr *hdr)
  167. {
  168. enum nl80211_mesh_power_mode pm;
  169. u8 *qc;
  170. if (WARN_ON(is_unicast_ether_addr(hdr->addr1) &&
  171. ieee80211_is_data_qos(hdr->frame_control) &&
  172. !sta))
  173. return;
  174. if (is_unicast_ether_addr(hdr->addr1) &&
  175. ieee80211_is_data_qos(hdr->frame_control) &&
  176. sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  177. pm = sta->mesh->local_pm;
  178. else
  179. pm = sdata->u.mesh.nonpeer_pm;
  180. if (pm == NL80211_MESH_POWER_ACTIVE)
  181. hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_PM);
  182. else
  183. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  184. if (!ieee80211_is_data_qos(hdr->frame_control))
  185. return;
  186. qc = ieee80211_get_qos_ctl(hdr);
  187. if ((is_unicast_ether_addr(hdr->addr1) &&
  188. pm == NL80211_MESH_POWER_DEEP_SLEEP) ||
  189. (is_multicast_ether_addr(hdr->addr1) &&
  190. sdata->u.mesh.ps_peers_deep_sleep > 0))
  191. qc[1] |= (IEEE80211_QOS_CTL_MESH_PS_LEVEL >> 8);
  192. else
  193. qc[1] &= ~(IEEE80211_QOS_CTL_MESH_PS_LEVEL >> 8);
  194. }
  195. /**
  196. * ieee80211_mps_sta_status_update - update buffering status of neighbor STA
  197. *
  198. * @sta: mesh STA
  199. *
  200. * called after change of peering status or non-peer/peer-specific power mode
  201. */
  202. void ieee80211_mps_sta_status_update(struct sta_info *sta)
  203. {
  204. enum nl80211_mesh_power_mode pm;
  205. bool do_buffer;
  206. /* For non-assoc STA, prevent buffering or frame transmission */
  207. if (sta->sta_state < IEEE80211_STA_ASSOC)
  208. return;
  209. /*
  210. * use peer-specific power mode if peering is established and the
  211. * peer's power mode is known
  212. */
  213. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB &&
  214. sta->mesh->peer_pm != NL80211_MESH_POWER_UNKNOWN)
  215. pm = sta->mesh->peer_pm;
  216. else
  217. pm = sta->mesh->nonpeer_pm;
  218. do_buffer = (pm != NL80211_MESH_POWER_ACTIVE);
  219. /* clear the MPSP flags for non-peers or active STA */
  220. if (sta->mesh->plink_state != NL80211_PLINK_ESTAB) {
  221. clear_sta_flag(sta, WLAN_STA_MPSP_OWNER);
  222. clear_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
  223. } else if (!do_buffer) {
  224. clear_sta_flag(sta, WLAN_STA_MPSP_OWNER);
  225. }
  226. /* Don't let the same PS state be set twice */
  227. if (test_sta_flag(sta, WLAN_STA_PS_STA) == do_buffer)
  228. return;
  229. if (do_buffer) {
  230. set_sta_flag(sta, WLAN_STA_PS_STA);
  231. atomic_inc(&sta->sdata->u.mesh.ps.num_sta_ps);
  232. mps_dbg(sta->sdata, "start PS buffering frames towards %pM\n",
  233. sta->sta.addr);
  234. } else {
  235. ieee80211_sta_ps_deliver_wakeup(sta);
  236. }
  237. }
  238. static void mps_set_sta_peer_pm(struct sta_info *sta,
  239. struct ieee80211_hdr *hdr)
  240. {
  241. enum nl80211_mesh_power_mode pm;
  242. u8 *qc = ieee80211_get_qos_ctl(hdr);
  243. /*
  244. * Test Power Management field of frame control (PW) and
  245. * mesh power save level subfield of QoS control field (PSL)
  246. *
  247. * | PM | PSL| Mesh PM |
  248. * +----+----+---------+
  249. * | 0 |Rsrv| Active |
  250. * | 1 | 0 | Light |
  251. * | 1 | 1 | Deep |
  252. */
  253. if (ieee80211_has_pm(hdr->frame_control)) {
  254. if (qc[1] & (IEEE80211_QOS_CTL_MESH_PS_LEVEL >> 8))
  255. pm = NL80211_MESH_POWER_DEEP_SLEEP;
  256. else
  257. pm = NL80211_MESH_POWER_LIGHT_SLEEP;
  258. } else {
  259. pm = NL80211_MESH_POWER_ACTIVE;
  260. }
  261. if (sta->mesh->peer_pm == pm)
  262. return;
  263. mps_dbg(sta->sdata, "STA %pM enters mode %d\n",
  264. sta->sta.addr, pm);
  265. sta->mesh->peer_pm = pm;
  266. ieee80211_mps_sta_status_update(sta);
  267. }
  268. static void mps_set_sta_nonpeer_pm(struct sta_info *sta,
  269. struct ieee80211_hdr *hdr)
  270. {
  271. enum nl80211_mesh_power_mode pm;
  272. if (ieee80211_has_pm(hdr->frame_control))
  273. pm = NL80211_MESH_POWER_DEEP_SLEEP;
  274. else
  275. pm = NL80211_MESH_POWER_ACTIVE;
  276. if (sta->mesh->nonpeer_pm == pm)
  277. return;
  278. mps_dbg(sta->sdata, "STA %pM sets non-peer mode to %d\n",
  279. sta->sta.addr, pm);
  280. sta->mesh->nonpeer_pm = pm;
  281. ieee80211_mps_sta_status_update(sta);
  282. }
  283. /**
  284. * ieee80211_mps_rx_h_sta_process - frame receive handler for mesh powersave
  285. *
  286. * @sta: STA info that transmitted the frame
  287. * @hdr: IEEE 802.11 (QoS) Header
  288. */
  289. void ieee80211_mps_rx_h_sta_process(struct sta_info *sta,
  290. struct ieee80211_hdr *hdr)
  291. {
  292. if (is_unicast_ether_addr(hdr->addr1) &&
  293. ieee80211_is_data_qos(hdr->frame_control)) {
  294. /*
  295. * individually addressed QoS Data/Null frames contain
  296. * peer link-specific PS mode towards the local STA
  297. */
  298. mps_set_sta_peer_pm(sta, hdr);
  299. /* check for mesh Peer Service Period trigger frames */
  300. ieee80211_mpsp_trigger_process(ieee80211_get_qos_ctl(hdr),
  301. sta, false, false);
  302. } else {
  303. /*
  304. * can only determine non-peer PS mode
  305. * (see IEEE802.11-2012 8.2.4.1.7)
  306. */
  307. mps_set_sta_nonpeer_pm(sta, hdr);
  308. }
  309. }
  310. /* mesh PS frame release */
  311. static void mpsp_trigger_send(struct sta_info *sta, bool rspi, bool eosp)
  312. {
  313. struct ieee80211_sub_if_data *sdata = sta->sdata;
  314. struct sk_buff *skb;
  315. struct ieee80211_hdr *nullfunc;
  316. struct ieee80211_tx_info *info;
  317. u8 *qc;
  318. skb = mps_qos_null_get(sta);
  319. if (!skb)
  320. return;
  321. nullfunc = (struct ieee80211_hdr *) skb->data;
  322. if (!eosp)
  323. nullfunc->frame_control |=
  324. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  325. /*
  326. * | RSPI | EOSP | MPSP triggering |
  327. * +------+------+--------------------+
  328. * | 0 | 0 | local STA is owner |
  329. * | 0 | 1 | no MPSP (MPSP end) |
  330. * | 1 | 0 | both STA are owner |
  331. * | 1 | 1 | peer STA is owner | see IEEE802.11-2012 13.14.9.2
  332. */
  333. qc = ieee80211_get_qos_ctl(nullfunc);
  334. if (rspi)
  335. qc[1] |= (IEEE80211_QOS_CTL_RSPI >> 8);
  336. if (eosp)
  337. qc[0] |= IEEE80211_QOS_CTL_EOSP;
  338. info = IEEE80211_SKB_CB(skb);
  339. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
  340. IEEE80211_TX_CTL_REQ_TX_STATUS;
  341. mps_dbg(sdata, "sending MPSP trigger%s%s to %pM\n",
  342. rspi ? " RSPI" : "", eosp ? " EOSP" : "", sta->sta.addr);
  343. ieee80211_tx_skb(sdata, skb);
  344. }
  345. /**
  346. * mpsp_qos_null_append - append QoS Null frame to MPSP skb queue if needed
  347. * @sta: the station to handle
  348. * @frames: the frame list to append to
  349. *
  350. * To properly end a mesh MPSP the last transmitted frame has to set the EOSP
  351. * flag in the QoS Control field. In case the current tailing frame is not a
  352. * QoS Data frame, append a QoS Null to carry the flag.
  353. */
  354. static void mpsp_qos_null_append(struct sta_info *sta,
  355. struct sk_buff_head *frames)
  356. {
  357. struct ieee80211_sub_if_data *sdata = sta->sdata;
  358. struct sk_buff *new_skb, *skb = skb_peek_tail(frames);
  359. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  360. struct ieee80211_tx_info *info;
  361. if (ieee80211_is_data_qos(hdr->frame_control))
  362. return;
  363. new_skb = mps_qos_null_get(sta);
  364. if (!new_skb)
  365. return;
  366. mps_dbg(sdata, "appending QoS Null in MPSP towards %pM\n",
  367. sta->sta.addr);
  368. /*
  369. * This frame has to be transmitted last. Assign lowest priority to
  370. * make sure it cannot pass other frames when releasing multiple ACs.
  371. */
  372. new_skb->priority = 1;
  373. skb_set_queue_mapping(new_skb, IEEE80211_AC_BK);
  374. ieee80211_set_qos_hdr(sdata, new_skb);
  375. info = IEEE80211_SKB_CB(new_skb);
  376. info->control.vif = &sdata->vif;
  377. info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
  378. __skb_queue_tail(frames, new_skb);
  379. }
  380. /**
  381. * mps_frame_deliver - transmit frames during mesh powersave
  382. *
  383. * @sta: STA info to transmit to
  384. * @n_frames: number of frames to transmit. -1 for all
  385. */
  386. static void mps_frame_deliver(struct sta_info *sta, int n_frames)
  387. {
  388. struct ieee80211_local *local = sta->sdata->local;
  389. int ac;
  390. struct sk_buff_head frames;
  391. struct sk_buff *skb;
  392. bool more_data = false;
  393. skb_queue_head_init(&frames);
  394. /* collect frame(s) from buffers */
  395. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  396. while (n_frames != 0) {
  397. skb = skb_dequeue(&sta->tx_filtered[ac]);
  398. if (!skb) {
  399. skb = skb_dequeue(
  400. &sta->ps_tx_buf[ac]);
  401. if (skb)
  402. local->total_ps_buffered--;
  403. }
  404. if (!skb)
  405. break;
  406. n_frames--;
  407. __skb_queue_tail(&frames, skb);
  408. }
  409. if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
  410. !skb_queue_empty(&sta->ps_tx_buf[ac]))
  411. more_data = true;
  412. }
  413. /* nothing to send? -> EOSP */
  414. if (skb_queue_empty(&frames)) {
  415. mpsp_trigger_send(sta, false, true);
  416. return;
  417. }
  418. /* in a MPSP make sure the last skb is a QoS Data frame */
  419. if (test_sta_flag(sta, WLAN_STA_MPSP_OWNER))
  420. mpsp_qos_null_append(sta, &frames);
  421. mps_dbg(sta->sdata, "sending %d frames to PS STA %pM\n",
  422. skb_queue_len(&frames), sta->sta.addr);
  423. /* prepare collected frames for transmission */
  424. skb_queue_walk(&frames, skb) {
  425. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  426. struct ieee80211_hdr *hdr = (void *) skb->data;
  427. /*
  428. * Tell TX path to send this frame even though the
  429. * STA may still remain is PS mode after this frame
  430. * exchange.
  431. */
  432. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
  433. if (more_data || !skb_queue_is_last(&frames, skb))
  434. hdr->frame_control |=
  435. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  436. else
  437. hdr->frame_control &=
  438. cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  439. if (skb_queue_is_last(&frames, skb) &&
  440. ieee80211_is_data_qos(hdr->frame_control)) {
  441. u8 *qoshdr = ieee80211_get_qos_ctl(hdr);
  442. /* MPSP trigger frame ends service period */
  443. *qoshdr |= IEEE80211_QOS_CTL_EOSP;
  444. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  445. }
  446. }
  447. ieee80211_add_pending_skbs(local, &frames);
  448. sta_info_recalc_tim(sta);
  449. }
  450. /**
  451. * ieee80211_mpsp_trigger_process - track status of mesh Peer Service Periods
  452. *
  453. * @qc: QoS Control field
  454. * @sta: peer to start a MPSP with
  455. * @tx: frame was transmitted by the local STA
  456. * @acked: frame has been transmitted successfully
  457. *
  458. * NOTE: active mode STA may only serve as MPSP owner
  459. */
  460. void ieee80211_mpsp_trigger_process(u8 *qc, struct sta_info *sta,
  461. bool tx, bool acked)
  462. {
  463. u8 rspi = qc[1] & (IEEE80211_QOS_CTL_RSPI >> 8);
  464. u8 eosp = qc[0] & IEEE80211_QOS_CTL_EOSP;
  465. if (tx) {
  466. if (rspi && acked)
  467. set_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
  468. if (eosp)
  469. clear_sta_flag(sta, WLAN_STA_MPSP_OWNER);
  470. else if (acked &&
  471. test_sta_flag(sta, WLAN_STA_PS_STA) &&
  472. !test_and_set_sta_flag(sta, WLAN_STA_MPSP_OWNER))
  473. mps_frame_deliver(sta, -1);
  474. } else {
  475. if (eosp)
  476. clear_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
  477. else if (sta->mesh->local_pm != NL80211_MESH_POWER_ACTIVE)
  478. set_sta_flag(sta, WLAN_STA_MPSP_RECIPIENT);
  479. if (rspi && !test_and_set_sta_flag(sta, WLAN_STA_MPSP_OWNER))
  480. mps_frame_deliver(sta, -1);
  481. }
  482. }
  483. /**
  484. * ieee80211_mps_frame_release - release frames buffered due to mesh power save
  485. *
  486. * @sta: mesh STA
  487. * @elems: IEs of beacon or probe response
  488. *
  489. * For peers if we have individually-addressed frames buffered or the peer
  490. * indicates buffered frames, send a corresponding MPSP trigger frame. Since
  491. * we do not evaluate the awake window duration, QoS Nulls are used as MPSP
  492. * trigger frames. If the neighbour STA is not a peer, only send single frames.
  493. */
  494. void ieee80211_mps_frame_release(struct sta_info *sta,
  495. struct ieee802_11_elems *elems)
  496. {
  497. int ac, buffer_local = 0;
  498. bool has_buffered = false;
  499. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  500. has_buffered = ieee80211_check_tim(elems->tim, elems->tim_len,
  501. sta->mesh->aid);
  502. if (has_buffered)
  503. mps_dbg(sta->sdata, "%pM indicates buffered frames\n",
  504. sta->sta.addr);
  505. /* only transmit to PS STA with announced, non-zero awake window */
  506. if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
  507. (!elems->awake_window || !get_unaligned_le16(elems->awake_window)))
  508. return;
  509. if (!test_sta_flag(sta, WLAN_STA_MPSP_OWNER))
  510. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  511. buffer_local += skb_queue_len(&sta->ps_tx_buf[ac]) +
  512. skb_queue_len(&sta->tx_filtered[ac]);
  513. if (!has_buffered && !buffer_local)
  514. return;
  515. if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
  516. mpsp_trigger_send(sta, has_buffered, !buffer_local);
  517. else
  518. mps_frame_deliver(sta, 1);
  519. }