status.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2002-2005, Instant802 Networks, Inc.
  4. * Copyright 2005-2006, Devicescape Software, Inc.
  5. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  6. * Copyright 2008-2010 Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright 2013-2014 Intel Mobile Communications GmbH
  8. * Copyright 2021-2025 Intel Corporation
  9. */
  10. #include <linux/export.h>
  11. #include <linux/etherdevice.h>
  12. #include <net/mac80211.h>
  13. #include <linux/unaligned.h>
  14. #include "ieee80211_i.h"
  15. #include "rate.h"
  16. #include "mesh.h"
  17. #include "led.h"
  18. #include "wme.h"
  19. void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
  20. struct sk_buff *skb)
  21. {
  22. struct ieee80211_local *local = hw_to_local(hw);
  23. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  24. int tmp;
  25. skb->pkt_type = IEEE80211_TX_STATUS_MSG;
  26. skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
  27. &local->skb_queue : &local->skb_queue_unreliable, skb);
  28. tmp = skb_queue_len(&local->skb_queue) +
  29. skb_queue_len(&local->skb_queue_unreliable);
  30. while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
  31. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  32. ieee80211_free_txskb(hw, skb);
  33. tmp--;
  34. I802_DEBUG_INC(local->tx_status_drop);
  35. }
  36. tasklet_schedule(&local->tasklet);
  37. }
  38. EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
  39. static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
  40. struct sta_info *sta,
  41. struct sk_buff *skb)
  42. {
  43. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  44. struct ieee80211_hdr *hdr = (void *)skb->data;
  45. int ac;
  46. if (info->flags & (IEEE80211_TX_CTL_NO_PS_BUFFER |
  47. IEEE80211_TX_CTL_AMPDU |
  48. IEEE80211_TX_CTL_HW_80211_ENCAP)) {
  49. ieee80211_free_txskb(&local->hw, skb);
  50. return;
  51. }
  52. /*
  53. * This skb 'survived' a round-trip through the driver, and
  54. * hopefully the driver didn't mangle it too badly. However,
  55. * we can definitely not rely on the control information
  56. * being correct. Clear it so we don't get junk there, and
  57. * indicate that it needs new processing, but must not be
  58. * modified/encrypted again.
  59. */
  60. memset(&info->control, 0, sizeof(info->control));
  61. info->control.jiffies = jiffies;
  62. info->control.vif = &sta->sdata->vif;
  63. info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
  64. info->flags |= IEEE80211_TX_INTFL_RETRANSMISSION;
  65. info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
  66. sta->deflink.status_stats.filtered++;
  67. /*
  68. * Clear more-data bit on filtered frames, it might be set
  69. * but later frames might time out so it might have to be
  70. * clear again ... It's all rather unlikely (this frame
  71. * should time out first, right?) but let's not confuse
  72. * peers unnecessarily.
  73. */
  74. if (hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_MOREDATA))
  75. hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  76. if (ieee80211_is_data_qos(hdr->frame_control)) {
  77. u8 *p = ieee80211_get_qos_ctl(hdr);
  78. int tid = *p & IEEE80211_QOS_CTL_TID_MASK;
  79. /*
  80. * Clear EOSP if set, this could happen e.g.
  81. * if an absence period (us being a P2P GO)
  82. * shortens the SP.
  83. */
  84. if (*p & IEEE80211_QOS_CTL_EOSP)
  85. *p &= ~IEEE80211_QOS_CTL_EOSP;
  86. ac = ieee80211_ac_from_tid(tid);
  87. } else {
  88. ac = IEEE80211_AC_BE;
  89. }
  90. /*
  91. * Clear the TX filter mask for this STA when sending the next
  92. * packet. If the STA went to power save mode, this will happen
  93. * when it wakes up for the next time.
  94. */
  95. set_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT);
  96. ieee80211_clear_fast_xmit(sta);
  97. /*
  98. * This code races in the following way:
  99. *
  100. * (1) STA sends frame indicating it will go to sleep and does so
  101. * (2) hardware/firmware adds STA to filter list, passes frame up
  102. * (3) hardware/firmware processes TX fifo and suppresses a frame
  103. * (4) we get TX status before having processed the frame and
  104. * knowing that the STA has gone to sleep.
  105. *
  106. * This is actually quite unlikely even when both those events are
  107. * processed from interrupts coming in quickly after one another or
  108. * even at the same time because we queue both TX status events and
  109. * RX frames to be processed by a tasklet and process them in the
  110. * same order that they were received or TX status last. Hence, there
  111. * is no race as long as the frame RX is processed before the next TX
  112. * status, which drivers can ensure, see below.
  113. *
  114. * Note that this can only happen if the hardware or firmware can
  115. * actually add STAs to the filter list, if this is done by the
  116. * driver in response to set_tim() (which will only reduce the race
  117. * this whole filtering tries to solve, not completely solve it)
  118. * this situation cannot happen.
  119. *
  120. * To completely solve this race drivers need to make sure that they
  121. * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
  122. * functions and
  123. * (b) always process RX events before TX status events if ordering
  124. * can be unknown, for example with different interrupt status
  125. * bits.
  126. * (c) if PS mode transitions are manual (i.e. the flag
  127. * %IEEE80211_HW_AP_LINK_PS is set), always process PS state
  128. * changes before calling TX status events if ordering can be
  129. * unknown.
  130. */
  131. if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
  132. skb_queue_len(&sta->tx_filtered[ac]) < STA_MAX_TX_BUFFER) {
  133. skb_queue_tail(&sta->tx_filtered[ac], skb);
  134. sta_info_recalc_tim(sta);
  135. if (!timer_pending(&local->sta_cleanup))
  136. mod_timer(&local->sta_cleanup,
  137. round_jiffies(jiffies +
  138. STA_INFO_CLEANUP_INTERVAL));
  139. return;
  140. }
  141. if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
  142. !(info->flags & IEEE80211_TX_INTFL_RETRIED)) {
  143. /* Software retry the packet once */
  144. info->flags |= IEEE80211_TX_INTFL_RETRIED;
  145. ieee80211_add_pending_skb(local, skb);
  146. return;
  147. }
  148. ps_dbg_ratelimited(sta->sdata,
  149. "dropped TX filtered frame, queue_len=%d PS=%d @%lu\n",
  150. skb_queue_len(&sta->tx_filtered[ac]),
  151. !!test_sta_flag(sta, WLAN_STA_PS_STA), jiffies);
  152. ieee80211_free_txskb(&local->hw, skb);
  153. }
  154. static void ieee80211_check_pending_bar(struct sta_info *sta, u8 *addr, u8 tid)
  155. {
  156. struct tid_ampdu_tx *tid_tx;
  157. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  158. if (!tid_tx || !tid_tx->bar_pending)
  159. return;
  160. tid_tx->bar_pending = false;
  161. ieee80211_send_bar(&sta->sdata->vif, addr, tid, tid_tx->failed_bar_ssn);
  162. }
  163. static void ieee80211_frame_acked(struct sta_info *sta, struct sk_buff *skb)
  164. {
  165. struct ieee80211_mgmt *mgmt = (void *) skb->data;
  166. if (ieee80211_is_data_qos(mgmt->frame_control)) {
  167. struct ieee80211_hdr *hdr = (void *) skb->data;
  168. u8 *qc = ieee80211_get_qos_ctl(hdr);
  169. u16 tid = qc[0] & 0xf;
  170. ieee80211_check_pending_bar(sta, hdr->addr1, tid);
  171. }
  172. }
  173. static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn)
  174. {
  175. struct tid_ampdu_tx *tid_tx;
  176. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  177. if (!tid_tx)
  178. return;
  179. tid_tx->failed_bar_ssn = ssn;
  180. tid_tx->bar_pending = true;
  181. }
  182. static int ieee80211_tx_radiotap_len(struct ieee80211_tx_info *info,
  183. struct ieee80211_tx_status *status)
  184. {
  185. struct ieee80211_rate_status *status_rate = NULL;
  186. int len = sizeof(struct ieee80211_radiotap_header);
  187. if (status && status->n_rates)
  188. status_rate = &status->rates[status->n_rates - 1];
  189. /* IEEE80211_RADIOTAP_RATE rate */
  190. if (status_rate && !(status_rate->rate_idx.flags &
  191. (RATE_INFO_FLAGS_MCS |
  192. RATE_INFO_FLAGS_DMG |
  193. RATE_INFO_FLAGS_EDMG |
  194. RATE_INFO_FLAGS_VHT_MCS |
  195. RATE_INFO_FLAGS_HE_MCS)))
  196. len += 2;
  197. else if (info->status.rates[0].idx >= 0 &&
  198. !(info->status.rates[0].flags &
  199. (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS)))
  200. len += 2;
  201. /* IEEE80211_RADIOTAP_TX_FLAGS */
  202. len += 2;
  203. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  204. len += 1;
  205. /* IEEE80211_RADIOTAP_MCS
  206. * IEEE80211_RADIOTAP_VHT */
  207. if (status_rate) {
  208. if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_MCS)
  209. len += 3;
  210. else if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)
  211. len = ALIGN(len, 2) + 12;
  212. else if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_HE_MCS)
  213. len = ALIGN(len, 2) + 12;
  214. } else if (info->status.rates[0].idx >= 0) {
  215. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS)
  216. len += 3;
  217. else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS)
  218. len = ALIGN(len, 2) + 12;
  219. }
  220. return len;
  221. }
  222. static void
  223. ieee80211_add_tx_radiotap_header(struct ieee80211_local *local,
  224. struct sk_buff *skb, int retry_count,
  225. int rtap_len,
  226. struct ieee80211_tx_status *status)
  227. {
  228. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  229. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  230. struct ieee80211_radiotap_header *rthdr;
  231. struct ieee80211_rate_status *status_rate = NULL;
  232. unsigned char *pos;
  233. u16 legacy_rate = 0;
  234. u16 txflags;
  235. if (status && status->n_rates)
  236. status_rate = &status->rates[status->n_rates - 1];
  237. rthdr = skb_push(skb, rtap_len);
  238. memset(rthdr, 0, rtap_len);
  239. rthdr->it_len = cpu_to_le16(rtap_len);
  240. rthdr->it_present =
  241. cpu_to_le32(BIT(IEEE80211_RADIOTAP_TX_FLAGS) |
  242. BIT(IEEE80211_RADIOTAP_DATA_RETRIES));
  243. pos = (unsigned char *)(rthdr + 1);
  244. /*
  245. * XXX: Once radiotap gets the bitmap reset thing the vendor
  246. * extensions proposal contains, we can actually report
  247. * the whole set of tries we did.
  248. */
  249. /* IEEE80211_RADIOTAP_RATE */
  250. if (status_rate) {
  251. if (!(status_rate->rate_idx.flags &
  252. (RATE_INFO_FLAGS_MCS |
  253. RATE_INFO_FLAGS_DMG |
  254. RATE_INFO_FLAGS_EDMG |
  255. RATE_INFO_FLAGS_VHT_MCS |
  256. RATE_INFO_FLAGS_HE_MCS)))
  257. legacy_rate = status_rate->rate_idx.legacy;
  258. } else if (info->status.rates[0].idx >= 0 &&
  259. !(info->status.rates[0].flags & (IEEE80211_TX_RC_MCS |
  260. IEEE80211_TX_RC_VHT_MCS))) {
  261. struct ieee80211_supported_band *sband;
  262. sband = local->hw.wiphy->bands[info->band];
  263. legacy_rate =
  264. sband->bitrates[info->status.rates[0].idx].bitrate;
  265. }
  266. if (legacy_rate) {
  267. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
  268. *pos = DIV_ROUND_UP(legacy_rate, 5);
  269. /* padding for tx flags */
  270. pos += 2;
  271. }
  272. /* IEEE80211_RADIOTAP_TX_FLAGS */
  273. txflags = 0;
  274. if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
  275. !is_multicast_ether_addr(hdr->addr1))
  276. txflags |= IEEE80211_RADIOTAP_F_TX_FAIL;
  277. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  278. txflags |= IEEE80211_RADIOTAP_F_TX_CTS;
  279. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  280. txflags |= IEEE80211_RADIOTAP_F_TX_RTS;
  281. put_unaligned_le16(txflags, pos);
  282. pos += 2;
  283. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  284. /* for now report the total retry_count */
  285. *pos = retry_count;
  286. pos++;
  287. if (status_rate && (status_rate->rate_idx.flags & RATE_INFO_FLAGS_MCS))
  288. {
  289. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
  290. pos[0] = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  291. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  292. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  293. if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_SHORT_GI)
  294. pos[1] |= IEEE80211_RADIOTAP_MCS_SGI;
  295. if (status_rate->rate_idx.bw == RATE_INFO_BW_40)
  296. pos[1] |= IEEE80211_RADIOTAP_MCS_BW_40;
  297. pos[2] = status_rate->rate_idx.mcs;
  298. pos += 3;
  299. } else if (status_rate && (status_rate->rate_idx.flags &
  300. RATE_INFO_FLAGS_VHT_MCS))
  301. {
  302. u16 known = local->hw.radiotap_vht_details &
  303. (IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  304. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH);
  305. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
  306. /* required alignment from rthdr */
  307. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  308. /* u16 known - IEEE80211_RADIOTAP_VHT_KNOWN_* */
  309. put_unaligned_le16(known, pos);
  310. pos += 2;
  311. /* u8 flags - IEEE80211_RADIOTAP_VHT_FLAG_* */
  312. if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_SHORT_GI)
  313. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  314. pos++;
  315. /* u8 bandwidth */
  316. switch (status_rate->rate_idx.bw) {
  317. case RATE_INFO_BW_160:
  318. *pos = 11;
  319. break;
  320. case RATE_INFO_BW_80:
  321. *pos = 4;
  322. break;
  323. case RATE_INFO_BW_40:
  324. *pos = 1;
  325. break;
  326. default:
  327. *pos = 0;
  328. break;
  329. }
  330. pos++;
  331. /* u8 mcs_nss[4] */
  332. *pos = (status_rate->rate_idx.mcs << 4) |
  333. status_rate->rate_idx.nss;
  334. pos += 4;
  335. /* u8 coding */
  336. pos++;
  337. /* u8 group_id */
  338. pos++;
  339. /* u16 partial_aid */
  340. pos += 2;
  341. } else if (status_rate && (status_rate->rate_idx.flags &
  342. RATE_INFO_FLAGS_HE_MCS))
  343. {
  344. struct ieee80211_radiotap_he *he;
  345. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
  346. /* required alignment from rthdr */
  347. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  348. he = (struct ieee80211_radiotap_he *)pos;
  349. he->data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_SU |
  350. IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN |
  351. IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN |
  352. IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
  353. he->data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN);
  354. #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
  355. he->data6 |= HE_PREP(DATA6_NSTS, status_rate->rate_idx.nss);
  356. #define CHECK_GI(s) \
  357. BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
  358. (int)NL80211_RATE_INFO_HE_GI_##s)
  359. CHECK_GI(0_8);
  360. CHECK_GI(1_6);
  361. CHECK_GI(3_2);
  362. he->data3 |= HE_PREP(DATA3_DATA_MCS, status_rate->rate_idx.mcs);
  363. he->data3 |= HE_PREP(DATA3_DATA_DCM, status_rate->rate_idx.he_dcm);
  364. he->data5 |= HE_PREP(DATA5_GI, status_rate->rate_idx.he_gi);
  365. switch (status_rate->rate_idx.bw) {
  366. case RATE_INFO_BW_20:
  367. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  368. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
  369. break;
  370. case RATE_INFO_BW_40:
  371. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  372. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
  373. break;
  374. case RATE_INFO_BW_80:
  375. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  376. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
  377. break;
  378. case RATE_INFO_BW_160:
  379. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  380. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
  381. break;
  382. case RATE_INFO_BW_HE_RU:
  383. #define CHECK_RU_ALLOC(s) \
  384. BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
  385. NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
  386. CHECK_RU_ALLOC(26);
  387. CHECK_RU_ALLOC(52);
  388. CHECK_RU_ALLOC(106);
  389. CHECK_RU_ALLOC(242);
  390. CHECK_RU_ALLOC(484);
  391. CHECK_RU_ALLOC(996);
  392. CHECK_RU_ALLOC(2x996);
  393. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  394. status_rate->rate_idx.he_ru_alloc + 4);
  395. break;
  396. default:
  397. WARN_ONCE(1, "Invalid SU BW %d\n", status_rate->rate_idx.bw);
  398. }
  399. pos += sizeof(struct ieee80211_radiotap_he);
  400. }
  401. if (status_rate || info->status.rates[0].idx < 0)
  402. return;
  403. /* IEEE80211_RADIOTAP_MCS
  404. * IEEE80211_RADIOTAP_VHT */
  405. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS) {
  406. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
  407. pos[0] = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  408. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  409. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  410. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  411. pos[1] |= IEEE80211_RADIOTAP_MCS_SGI;
  412. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  413. pos[1] |= IEEE80211_RADIOTAP_MCS_BW_40;
  414. if (info->status.rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD)
  415. pos[1] |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  416. pos[2] = info->status.rates[0].idx;
  417. pos += 3;
  418. } else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
  419. u16 known = local->hw.radiotap_vht_details &
  420. (IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  421. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH);
  422. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
  423. /* required alignment from rthdr */
  424. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  425. /* u16 known - IEEE80211_RADIOTAP_VHT_KNOWN_* */
  426. put_unaligned_le16(known, pos);
  427. pos += 2;
  428. /* u8 flags - IEEE80211_RADIOTAP_VHT_FLAG_* */
  429. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  430. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  431. pos++;
  432. /* u8 bandwidth */
  433. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  434. *pos = 1;
  435. else if (info->status.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  436. *pos = 4;
  437. else if (info->status.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  438. *pos = 11;
  439. else /* IEEE80211_TX_RC_{20_MHZ_WIDTH,FIXME:DUP_DATA} */
  440. *pos = 0;
  441. pos++;
  442. /* u8 mcs_nss[4] */
  443. *pos = (ieee80211_rate_get_vht_mcs(&info->status.rates[0]) << 4) |
  444. ieee80211_rate_get_vht_nss(&info->status.rates[0]);
  445. pos += 4;
  446. /* u8 coding */
  447. pos++;
  448. /* u8 group_id */
  449. pos++;
  450. /* u16 partial_aid */
  451. pos += 2;
  452. }
  453. }
  454. /*
  455. * Handles the tx for TDLS teardown frames.
  456. * If the frame wasn't ACKed by the peer - it will be re-sent through the AP
  457. */
  458. static void ieee80211_tdls_td_tx_handle(struct ieee80211_local *local,
  459. struct ieee80211_sub_if_data *sdata,
  460. struct sk_buff *skb, u32 flags)
  461. {
  462. struct sk_buff *teardown_skb;
  463. struct sk_buff *orig_teardown_skb;
  464. bool is_teardown = false;
  465. /* Get the teardown data we need and free the lock */
  466. spin_lock(&sdata->u.mgd.teardown_lock);
  467. teardown_skb = sdata->u.mgd.teardown_skb;
  468. orig_teardown_skb = sdata->u.mgd.orig_teardown_skb;
  469. if ((skb == orig_teardown_skb) && teardown_skb) {
  470. sdata->u.mgd.teardown_skb = NULL;
  471. sdata->u.mgd.orig_teardown_skb = NULL;
  472. is_teardown = true;
  473. }
  474. spin_unlock(&sdata->u.mgd.teardown_lock);
  475. if (is_teardown) {
  476. /* This mechanism relies on being able to get ACKs */
  477. WARN_ON(!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS));
  478. /* Check if peer has ACKed */
  479. if (flags & IEEE80211_TX_STAT_ACK) {
  480. dev_kfree_skb_any(teardown_skb);
  481. } else {
  482. tdls_dbg(sdata,
  483. "TDLS Resending teardown through AP\n");
  484. ieee80211_subif_start_xmit(teardown_skb, skb->dev);
  485. }
  486. }
  487. }
  488. static struct ieee80211_sub_if_data *
  489. ieee80211_sdata_from_skb(struct ieee80211_local *local, struct sk_buff *skb)
  490. {
  491. struct ieee80211_sub_if_data *sdata;
  492. struct ieee80211_hdr *hdr = (void *)skb->data;
  493. if (skb->dev) {
  494. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  495. if (!sdata->dev)
  496. continue;
  497. if (skb->dev == sdata->dev)
  498. return sdata;
  499. }
  500. return NULL;
  501. }
  502. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  503. switch (sdata->vif.type) {
  504. case NL80211_IFTYPE_P2P_DEVICE:
  505. break;
  506. case NL80211_IFTYPE_NAN:
  507. if (sdata->u.nan.started)
  508. break;
  509. fallthrough;
  510. default:
  511. continue;
  512. }
  513. if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
  514. return sdata;
  515. }
  516. return NULL;
  517. }
  518. static void ieee80211_report_ack_skb(struct ieee80211_local *local,
  519. struct sk_buff *orig_skb,
  520. bool acked, bool dropped,
  521. ktime_t ack_hwtstamp)
  522. {
  523. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(orig_skb);
  524. struct sk_buff *skb;
  525. unsigned long flags;
  526. spin_lock_irqsave(&local->ack_status_lock, flags);
  527. skb = idr_remove(&local->ack_status_frames, info->status_data);
  528. spin_unlock_irqrestore(&local->ack_status_lock, flags);
  529. if (!skb)
  530. return;
  531. if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) {
  532. u64 cookie = IEEE80211_SKB_CB(skb)->ack.cookie;
  533. struct ieee80211_sub_if_data *sdata;
  534. struct ieee80211_hdr *hdr = (void *)skb->data;
  535. bool is_valid_ack_signal =
  536. !!(info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID);
  537. struct cfg80211_tx_status status = {
  538. .cookie = cookie,
  539. .buf = skb->data,
  540. .len = skb->len,
  541. .ack = acked,
  542. };
  543. if (ieee80211_is_timing_measurement(orig_skb) ||
  544. ieee80211_is_ftm(orig_skb)) {
  545. status.tx_tstamp =
  546. ktime_to_ns(skb_hwtstamps(orig_skb)->hwtstamp);
  547. status.ack_tstamp = ktime_to_ns(ack_hwtstamp);
  548. }
  549. rcu_read_lock();
  550. sdata = ieee80211_sdata_from_skb(local, skb);
  551. if (sdata) {
  552. if (skb->protocol == sdata->control_port_protocol ||
  553. skb->protocol == cpu_to_be16(ETH_P_PREAUTH))
  554. cfg80211_control_port_tx_status(&sdata->wdev,
  555. cookie,
  556. skb->data,
  557. skb->len,
  558. acked,
  559. GFP_ATOMIC);
  560. else if (ieee80211_is_any_nullfunc(hdr->frame_control))
  561. cfg80211_probe_status(sdata->dev, hdr->addr1,
  562. cookie, acked,
  563. info->status.ack_signal,
  564. is_valid_ack_signal,
  565. GFP_ATOMIC);
  566. else if (ieee80211_is_mgmt(hdr->frame_control))
  567. cfg80211_mgmt_tx_status_ext(&sdata->wdev,
  568. &status,
  569. GFP_ATOMIC);
  570. else
  571. pr_warn("Unknown status report in ack skb\n");
  572. }
  573. rcu_read_unlock();
  574. dev_kfree_skb_any(skb);
  575. } else if (dropped) {
  576. dev_kfree_skb_any(skb);
  577. } else {
  578. /* consumes skb */
  579. skb_complete_wifi_ack(skb, acked);
  580. }
  581. }
  582. static void ieee80211_handle_smps_status(struct ieee80211_sub_if_data *sdata,
  583. bool acked, u16 status_data)
  584. {
  585. u16 sub_data = u16_get_bits(status_data, IEEE80211_STATUS_SUBDATA_MASK);
  586. enum ieee80211_smps_mode smps_mode = sub_data & 3;
  587. int link_id = (sub_data >> 2);
  588. struct ieee80211_link_data *link;
  589. if (!sdata || !ieee80211_sdata_running(sdata))
  590. return;
  591. if (!acked)
  592. return;
  593. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  594. return;
  595. if (WARN(link_id >= ARRAY_SIZE(sdata->link),
  596. "bad SMPS status link: %d\n", link_id))
  597. return;
  598. link = rcu_dereference(sdata->link[link_id]);
  599. if (!link)
  600. return;
  601. /*
  602. * This update looks racy, but isn't, the only other place
  603. * updating this variable is in managed mode before assoc,
  604. * and we have to be associated to have a status from the
  605. * action frame TX, since we cannot send it while we're not
  606. * associated yet.
  607. */
  608. link->smps_mode = smps_mode;
  609. wiphy_work_queue(sdata->local->hw.wiphy, &link->u.mgd.recalc_smps);
  610. }
  611. static void
  612. ieee80211_handle_teardown_ttlm_status(struct ieee80211_sub_if_data *sdata,
  613. bool acked)
  614. {
  615. if (!sdata || !ieee80211_sdata_running(sdata))
  616. return;
  617. if (!acked)
  618. return;
  619. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  620. return;
  621. wiphy_work_queue(sdata->local->hw.wiphy,
  622. &sdata->u.mgd.teardown_ttlm_work);
  623. }
  624. static void ieee80211_report_used_skb(struct ieee80211_local *local,
  625. struct sk_buff *skb, bool dropped,
  626. ktime_t ack_hwtstamp)
  627. {
  628. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  629. u16 tx_time_est = ieee80211_info_get_tx_time_est(info);
  630. struct ieee80211_hdr *hdr = (void *)skb->data;
  631. bool acked = info->flags & IEEE80211_TX_STAT_ACK;
  632. if (dropped)
  633. acked = false;
  634. if (tx_time_est) {
  635. struct sta_info *sta;
  636. rcu_read_lock();
  637. sta = sta_info_get_by_addrs(local, hdr->addr1, hdr->addr2);
  638. ieee80211_sta_update_pending_airtime(local, sta,
  639. skb_get_queue_mapping(skb),
  640. tx_time_est,
  641. true);
  642. rcu_read_unlock();
  643. }
  644. if (info->flags & IEEE80211_TX_INTFL_MLME_CONN_TX) {
  645. struct ieee80211_sub_if_data *sdata;
  646. rcu_read_lock();
  647. sdata = ieee80211_sdata_from_skb(local, skb);
  648. if (!sdata) {
  649. skb->dev = NULL;
  650. } else if (!dropped) {
  651. /* Check to see if packet is a TDLS teardown packet */
  652. if (ieee80211_is_data(hdr->frame_control) &&
  653. (ieee80211_get_tdls_action(skb) ==
  654. WLAN_TDLS_TEARDOWN)) {
  655. ieee80211_tdls_td_tx_handle(local, sdata, skb,
  656. info->flags);
  657. } else if (ieee80211_s1g_is_twt_setup(skb)) {
  658. if (!acked) {
  659. struct sk_buff *qskb;
  660. qskb = skb_clone(skb, GFP_ATOMIC);
  661. if (qskb) {
  662. skb_queue_tail(&sdata->status_queue,
  663. qskb);
  664. wiphy_work_queue(local->hw.wiphy,
  665. &sdata->work);
  666. }
  667. }
  668. } else {
  669. ieee80211_mgd_conn_tx_status(sdata,
  670. hdr->frame_control,
  671. acked);
  672. }
  673. }
  674. rcu_read_unlock();
  675. } else if (info->status_data_idr) {
  676. ieee80211_report_ack_skb(local, skb, acked, dropped,
  677. ack_hwtstamp);
  678. } else if (info->status_data) {
  679. struct ieee80211_sub_if_data *sdata;
  680. rcu_read_lock();
  681. sdata = ieee80211_sdata_from_skb(local, skb);
  682. switch (u16_get_bits(info->status_data,
  683. IEEE80211_STATUS_TYPE_MASK)) {
  684. case IEEE80211_STATUS_TYPE_SMPS:
  685. ieee80211_handle_smps_status(sdata, acked,
  686. info->status_data);
  687. break;
  688. case IEEE80211_STATUS_TYPE_NEG_TTLM:
  689. ieee80211_handle_teardown_ttlm_status(sdata, acked);
  690. break;
  691. }
  692. rcu_read_unlock();
  693. }
  694. if (!dropped && skb->destructor) {
  695. skb->wifi_acked_valid = 1;
  696. skb->wifi_acked = acked;
  697. }
  698. ieee80211_led_tx(local);
  699. if (skb_has_frag_list(skb)) {
  700. kfree_skb_list(skb_shinfo(skb)->frag_list);
  701. skb_shinfo(skb)->frag_list = NULL;
  702. }
  703. }
  704. /*
  705. * Use a static threshold for now, best value to be determined
  706. * by testing ...
  707. * Should it depend on:
  708. * - on # of retransmissions
  709. * - current throughput (higher value for higher tpt)?
  710. */
  711. #define STA_LOST_PKT_THRESHOLD 50
  712. #define STA_LOST_PKT_TIME HZ /* 1 sec since last ACK */
  713. #define STA_LOST_TDLS_PKT_TIME (10*HZ) /* 10secs since last ACK */
  714. static void ieee80211_lost_packet(struct sta_info *sta,
  715. struct ieee80211_tx_info *info)
  716. {
  717. unsigned long pkt_time = STA_LOST_PKT_TIME;
  718. unsigned int pkt_thr = STA_LOST_PKT_THRESHOLD;
  719. /* If driver relies on its own algorithm for station kickout, skip
  720. * mac80211 packet loss mechanism.
  721. */
  722. if (ieee80211_hw_check(&sta->local->hw, REPORTS_LOW_ACK))
  723. return;
  724. /* This packet was aggregated but doesn't carry status info */
  725. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  726. !(info->flags & IEEE80211_TX_STAT_AMPDU))
  727. return;
  728. sta->deflink.status_stats.lost_packets++;
  729. if (sta->sta.tdls) {
  730. pkt_time = STA_LOST_TDLS_PKT_TIME;
  731. pkt_thr = STA_LOST_PKT_THRESHOLD;
  732. }
  733. /*
  734. * If we're in TDLS mode, make sure that all STA_LOST_PKT_THRESHOLD
  735. * of the last packets were lost, and that no ACK was received in the
  736. * last STA_LOST_TDLS_PKT_TIME ms, before triggering the CQM packet-loss
  737. * mechanism.
  738. * For non-TDLS, use STA_LOST_PKT_THRESHOLD and STA_LOST_PKT_TIME
  739. */
  740. if (sta->deflink.status_stats.lost_packets < pkt_thr ||
  741. !time_after(jiffies, sta->deflink.status_stats.last_pkt_time + pkt_time))
  742. return;
  743. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  744. sta->deflink.status_stats.lost_packets,
  745. GFP_ATOMIC);
  746. sta->deflink.status_stats.lost_packets = 0;
  747. }
  748. static int ieee80211_tx_get_rates(struct ieee80211_hw *hw,
  749. struct ieee80211_tx_info *info,
  750. int *retry_count)
  751. {
  752. int count = -1;
  753. int i;
  754. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  755. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  756. !(info->flags & IEEE80211_TX_STAT_AMPDU)) {
  757. /* just the first aggr frame carry status info */
  758. info->status.rates[i].idx = -1;
  759. info->status.rates[i].count = 0;
  760. break;
  761. } else if (info->status.rates[i].idx < 0) {
  762. break;
  763. } else if (i >= hw->max_report_rates) {
  764. /* the HW cannot have attempted that rate */
  765. info->status.rates[i].idx = -1;
  766. info->status.rates[i].count = 0;
  767. break;
  768. }
  769. count += info->status.rates[i].count;
  770. }
  771. if (count < 0)
  772. count = 0;
  773. *retry_count = count;
  774. return i - 1;
  775. }
  776. void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
  777. int retry_count, struct ieee80211_tx_status *status)
  778. {
  779. struct sk_buff *skb2;
  780. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  781. struct ieee80211_sub_if_data *sdata;
  782. struct net_device *prev_dev = NULL;
  783. int rtap_len;
  784. /* send frame to monitor interfaces now */
  785. rtap_len = ieee80211_tx_radiotap_len(info, status);
  786. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  787. pr_err("ieee80211_tx_status: headroom too small\n");
  788. dev_kfree_skb(skb);
  789. return;
  790. }
  791. ieee80211_add_tx_radiotap_header(local, skb, retry_count,
  792. rtap_len, status);
  793. /* XXX: is this sufficient for BPF? */
  794. skb_reset_mac_header(skb);
  795. skb->ip_summed = CHECKSUM_UNNECESSARY;
  796. skb->pkt_type = PACKET_OTHERHOST;
  797. skb->protocol = htons(ETH_P_802_2);
  798. memset(skb->cb, 0, sizeof(skb->cb));
  799. rcu_read_lock();
  800. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  801. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  802. if (!ieee80211_sdata_running(sdata))
  803. continue;
  804. if (sdata->u.mntr.flags & MONITOR_FLAG_SKIP_TX)
  805. continue;
  806. if (prev_dev) {
  807. skb2 = skb_clone(skb, GFP_ATOMIC);
  808. if (skb2) {
  809. skb2->dev = prev_dev;
  810. netif_rx(skb2);
  811. }
  812. }
  813. prev_dev = sdata->dev;
  814. }
  815. }
  816. if (prev_dev) {
  817. skb->dev = prev_dev;
  818. netif_rx(skb);
  819. skb = NULL;
  820. }
  821. rcu_read_unlock();
  822. dev_kfree_skb(skb);
  823. }
  824. static void __ieee80211_tx_status(struct ieee80211_hw *hw,
  825. struct ieee80211_tx_status *status,
  826. int rates_idx, int retry_count)
  827. {
  828. struct sk_buff *skb = status->skb;
  829. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  830. struct ieee80211_local *local = hw_to_local(hw);
  831. struct ieee80211_tx_info *info = status->info;
  832. struct sta_info *sta;
  833. __le16 fc;
  834. bool acked;
  835. bool noack_success;
  836. struct ieee80211_bar *bar;
  837. int tid = IEEE80211_NUM_TIDS;
  838. fc = hdr->frame_control;
  839. if (status->sta) {
  840. sta = container_of(status->sta, struct sta_info, sta);
  841. if (info->flags & IEEE80211_TX_STATUS_EOSP)
  842. clear_sta_flag(sta, WLAN_STA_SP);
  843. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  844. noack_success = !!(info->flags &
  845. IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  846. /* mesh Peer Service Period support */
  847. if (ieee80211_vif_is_mesh(&sta->sdata->vif) &&
  848. ieee80211_is_data_qos(fc))
  849. ieee80211_mpsp_trigger_process(
  850. ieee80211_get_qos_ctl(hdr), sta, true, acked);
  851. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
  852. (ieee80211_is_data(hdr->frame_control)) &&
  853. (rates_idx != -1))
  854. sta->deflink.tx_stats.last_rate =
  855. info->status.rates[rates_idx];
  856. if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
  857. (ieee80211_is_data_qos(fc))) {
  858. u16 ssn;
  859. u8 *qc;
  860. qc = ieee80211_get_qos_ctl(hdr);
  861. tid = qc[0] & 0xf;
  862. ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
  863. & IEEE80211_SCTL_SEQ);
  864. ieee80211_send_bar(&sta->sdata->vif, hdr->addr1,
  865. tid, ssn);
  866. } else if (ieee80211_is_data_qos(fc)) {
  867. u8 *qc = ieee80211_get_qos_ctl(hdr);
  868. tid = qc[0] & 0xf;
  869. }
  870. if (!acked && ieee80211_is_back_req(fc)) {
  871. u16 control;
  872. /*
  873. * BAR failed, store the last SSN and retry sending
  874. * the BAR when the next unicast transmission on the
  875. * same TID succeeds.
  876. */
  877. bar = (struct ieee80211_bar *) skb->data;
  878. control = le16_to_cpu(bar->control);
  879. if (!(control & IEEE80211_BAR_CTRL_MULTI_TID)) {
  880. u16 ssn = le16_to_cpu(bar->start_seq_num);
  881. tid = (control &
  882. IEEE80211_BAR_CTRL_TID_INFO_MASK) >>
  883. IEEE80211_BAR_CTRL_TID_INFO_SHIFT;
  884. ieee80211_set_bar_pending(sta, tid, ssn);
  885. }
  886. }
  887. if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  888. ieee80211_handle_filtered_frame(local, sta, skb);
  889. return;
  890. } else if (ieee80211_is_data_present(fc)) {
  891. if (!acked && !noack_success)
  892. sta->deflink.status_stats.msdu_failed[tid]++;
  893. sta->deflink.status_stats.msdu_retries[tid] +=
  894. retry_count;
  895. }
  896. if (!(info->flags & IEEE80211_TX_CTL_INJECTED) && acked)
  897. ieee80211_frame_acked(sta, skb);
  898. }
  899. /* SNMP counters
  900. * Fragments are passed to low-level drivers as separate skbs, so these
  901. * are actually fragments, not frames. Update frame counters only for
  902. * the first fragment of the frame. */
  903. if ((info->flags & IEEE80211_TX_STAT_ACK) ||
  904. (info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED)) {
  905. if (ieee80211_is_first_frag(hdr->seq_ctrl)) {
  906. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  907. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  908. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  909. if (retry_count > 0)
  910. I802_DEBUG_INC(local->dot11RetryCount);
  911. if (retry_count > 1)
  912. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  913. }
  914. /* This counter shall be incremented for an acknowledged MPDU
  915. * with an individual address in the address 1 field or an MPDU
  916. * with a multicast address in the address 1 field of type Data
  917. * or Management. */
  918. if (!is_multicast_ether_addr(hdr->addr1) ||
  919. ieee80211_is_data(fc) ||
  920. ieee80211_is_mgmt(fc))
  921. I802_DEBUG_INC(local->dot11TransmittedFragmentCount);
  922. } else {
  923. if (ieee80211_is_first_frag(hdr->seq_ctrl))
  924. I802_DEBUG_INC(local->dot11FailedCount);
  925. }
  926. if (ieee80211_is_any_nullfunc(fc) &&
  927. ieee80211_has_pm(fc) &&
  928. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  929. !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
  930. local->ps_sdata && !(local->scanning)) {
  931. if (info->flags & IEEE80211_TX_STAT_ACK)
  932. local->ps_sdata->u.mgd.flags |=
  933. IEEE80211_STA_NULLFUNC_ACKED;
  934. mod_timer(&local->dynamic_ps_timer,
  935. jiffies + msecs_to_jiffies(10));
  936. }
  937. ieee80211_report_used_skb(local, skb, false, status->ack_hwtstamp);
  938. /*
  939. * This is a bit racy but we can avoid a lot of work
  940. * with this test...
  941. */
  942. if (local->tx_mntrs)
  943. ieee80211_tx_monitor(local, skb, retry_count, status);
  944. else if (status->free_list)
  945. list_add_tail(&skb->list, status->free_list);
  946. else
  947. dev_kfree_skb(skb);
  948. }
  949. void ieee80211_tx_status_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
  950. {
  951. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  952. struct ieee80211_local *local = hw_to_local(hw);
  953. struct ieee80211_tx_status status = {
  954. .skb = skb,
  955. .info = IEEE80211_SKB_CB(skb),
  956. };
  957. struct sta_info *sta;
  958. rcu_read_lock();
  959. sta = sta_info_get_by_addrs(local, hdr->addr1, hdr->addr2);
  960. if (sta)
  961. status.sta = &sta->sta;
  962. ieee80211_tx_status_ext(hw, &status);
  963. rcu_read_unlock();
  964. }
  965. EXPORT_SYMBOL(ieee80211_tx_status_skb);
  966. void ieee80211_tx_status_ext(struct ieee80211_hw *hw,
  967. struct ieee80211_tx_status *status)
  968. {
  969. struct ieee80211_local *local = hw_to_local(hw);
  970. struct ieee80211_tx_info *info = status->info;
  971. struct ieee80211_sta *pubsta = status->sta;
  972. struct sk_buff *skb = status->skb;
  973. struct sta_info *sta = NULL;
  974. int rates_idx, retry_count;
  975. bool acked, noack_success, ack_signal_valid;
  976. u16 tx_time_est;
  977. if (pubsta) {
  978. sta = container_of(pubsta, struct sta_info, sta);
  979. if (status->n_rates)
  980. sta->deflink.tx_stats.last_rate_info =
  981. status->rates[status->n_rates - 1].rate_idx;
  982. }
  983. if (skb && (tx_time_est =
  984. ieee80211_info_get_tx_time_est(IEEE80211_SKB_CB(skb))) > 0) {
  985. /* Do this here to avoid the expensive lookup of the sta
  986. * in ieee80211_report_used_skb().
  987. */
  988. ieee80211_sta_update_pending_airtime(local, sta,
  989. skb_get_queue_mapping(skb),
  990. tx_time_est,
  991. true);
  992. ieee80211_info_set_tx_time_est(IEEE80211_SKB_CB(skb), 0);
  993. }
  994. if (!status->info)
  995. goto free;
  996. rates_idx = ieee80211_tx_get_rates(hw, info, &retry_count);
  997. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  998. noack_success = !!(info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  999. ack_signal_valid =
  1000. !!(info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID);
  1001. if (pubsta) {
  1002. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1003. if (!acked && !noack_success)
  1004. sta->deflink.status_stats.retry_failed++;
  1005. sta->deflink.status_stats.retry_count += retry_count;
  1006. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  1007. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1008. skb && !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
  1009. ieee80211_sta_tx_notify(sdata, (void *) skb->data,
  1010. acked, info->status.tx_time);
  1011. if (acked) {
  1012. sta->deflink.status_stats.last_ack = jiffies;
  1013. if (sta->deflink.status_stats.lost_packets)
  1014. sta->deflink.status_stats.lost_packets = 0;
  1015. /* Track when last packet was ACKed */
  1016. sta->deflink.status_stats.last_pkt_time = jiffies;
  1017. /* Reset connection monitor */
  1018. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1019. unlikely(sdata->u.mgd.probe_send_count > 0))
  1020. sdata->u.mgd.probe_send_count = 0;
  1021. if (ack_signal_valid) {
  1022. sta->deflink.status_stats.last_ack_signal =
  1023. (s8)info->status.ack_signal;
  1024. sta->deflink.status_stats.ack_signal_filled = true;
  1025. ewma_avg_signal_add(&sta->deflink.status_stats.avg_ack_signal,
  1026. -info->status.ack_signal);
  1027. }
  1028. } else if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1029. /*
  1030. * The STA is in power save mode, so assume
  1031. * that this TX packet failed because of that.
  1032. */
  1033. if (skb)
  1034. ieee80211_handle_filtered_frame(local, sta, skb);
  1035. return;
  1036. } else if (noack_success) {
  1037. /* nothing to do here, do not account as lost */
  1038. } else {
  1039. ieee80211_lost_packet(sta, info);
  1040. }
  1041. }
  1042. rate_control_tx_status(local, status);
  1043. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  1044. ieee80211s_update_metric(local, sta, status);
  1045. }
  1046. if (skb && !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
  1047. return __ieee80211_tx_status(hw, status, rates_idx,
  1048. retry_count);
  1049. if (acked || noack_success) {
  1050. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  1051. if (!pubsta)
  1052. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  1053. if (retry_count > 0)
  1054. I802_DEBUG_INC(local->dot11RetryCount);
  1055. if (retry_count > 1)
  1056. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  1057. } else {
  1058. I802_DEBUG_INC(local->dot11FailedCount);
  1059. }
  1060. free:
  1061. if (!skb)
  1062. return;
  1063. ieee80211_report_used_skb(local, skb, false, status->ack_hwtstamp);
  1064. if (status->free_list)
  1065. list_add_tail(&skb->list, status->free_list);
  1066. else
  1067. dev_kfree_skb(skb);
  1068. }
  1069. EXPORT_SYMBOL(ieee80211_tx_status_ext);
  1070. void ieee80211_tx_rate_update(struct ieee80211_hw *hw,
  1071. struct ieee80211_sta *pubsta,
  1072. struct ieee80211_tx_info *info)
  1073. {
  1074. struct ieee80211_local *local = hw_to_local(hw);
  1075. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1076. struct ieee80211_tx_status status = {
  1077. .info = info,
  1078. .sta = pubsta,
  1079. };
  1080. rate_control_tx_status(local, &status);
  1081. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
  1082. sta->deflink.tx_stats.last_rate = info->status.rates[0];
  1083. }
  1084. EXPORT_SYMBOL(ieee80211_tx_rate_update);
  1085. void ieee80211_report_low_ack(struct ieee80211_sta *pubsta, u32 num_packets)
  1086. {
  1087. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1088. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  1089. num_packets, GFP_ATOMIC);
  1090. }
  1091. EXPORT_SYMBOL(ieee80211_report_low_ack);
  1092. void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb)
  1093. {
  1094. struct ieee80211_local *local = hw_to_local(hw);
  1095. ktime_t kt = ktime_set(0, 0);
  1096. ieee80211_report_used_skb(local, skb, true, kt);
  1097. dev_kfree_skb_any(skb);
  1098. }
  1099. EXPORT_SYMBOL(ieee80211_free_txskb);
  1100. void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
  1101. struct sk_buff_head *skbs)
  1102. {
  1103. struct sk_buff *skb;
  1104. while ((skb = __skb_dequeue(skbs)))
  1105. ieee80211_free_txskb(hw, skb);
  1106. }
  1107. EXPORT_SYMBOL(ieee80211_purge_tx_queue);