mesh_ps.c 16 KB

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