status.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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-2024 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. if (skb->dev) {
  493. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  494. if (!sdata->dev)
  495. continue;
  496. if (skb->dev == sdata->dev)
  497. return sdata;
  498. }
  499. return NULL;
  500. }
  501. return rcu_dereference(local->p2p_sdata);
  502. }
  503. static void ieee80211_report_ack_skb(struct ieee80211_local *local,
  504. struct sk_buff *orig_skb,
  505. bool acked, bool dropped,
  506. ktime_t ack_hwtstamp)
  507. {
  508. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(orig_skb);
  509. struct sk_buff *skb;
  510. unsigned long flags;
  511. spin_lock_irqsave(&local->ack_status_lock, flags);
  512. skb = idr_remove(&local->ack_status_frames, info->status_data);
  513. spin_unlock_irqrestore(&local->ack_status_lock, flags);
  514. if (!skb)
  515. return;
  516. if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) {
  517. u64 cookie = IEEE80211_SKB_CB(skb)->ack.cookie;
  518. struct ieee80211_sub_if_data *sdata;
  519. struct ieee80211_hdr *hdr = (void *)skb->data;
  520. bool is_valid_ack_signal =
  521. !!(info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID);
  522. struct cfg80211_tx_status status = {
  523. .cookie = cookie,
  524. .buf = skb->data,
  525. .len = skb->len,
  526. .ack = acked,
  527. };
  528. if (ieee80211_is_timing_measurement(orig_skb) ||
  529. ieee80211_is_ftm(orig_skb)) {
  530. status.tx_tstamp =
  531. ktime_to_ns(skb_hwtstamps(orig_skb)->hwtstamp);
  532. status.ack_tstamp = ktime_to_ns(ack_hwtstamp);
  533. }
  534. rcu_read_lock();
  535. sdata = ieee80211_sdata_from_skb(local, skb);
  536. if (sdata) {
  537. if (skb->protocol == sdata->control_port_protocol ||
  538. skb->protocol == cpu_to_be16(ETH_P_PREAUTH))
  539. cfg80211_control_port_tx_status(&sdata->wdev,
  540. cookie,
  541. skb->data,
  542. skb->len,
  543. acked,
  544. GFP_ATOMIC);
  545. else if (ieee80211_is_any_nullfunc(hdr->frame_control))
  546. cfg80211_probe_status(sdata->dev, hdr->addr1,
  547. cookie, acked,
  548. info->status.ack_signal,
  549. is_valid_ack_signal,
  550. GFP_ATOMIC);
  551. else if (ieee80211_is_mgmt(hdr->frame_control))
  552. cfg80211_mgmt_tx_status_ext(&sdata->wdev,
  553. &status,
  554. GFP_ATOMIC);
  555. else
  556. pr_warn("Unknown status report in ack skb\n");
  557. }
  558. rcu_read_unlock();
  559. dev_kfree_skb_any(skb);
  560. } else if (dropped) {
  561. dev_kfree_skb_any(skb);
  562. } else {
  563. /* consumes skb */
  564. skb_complete_wifi_ack(skb, acked);
  565. }
  566. }
  567. static void ieee80211_handle_smps_status(struct ieee80211_sub_if_data *sdata,
  568. bool acked, u16 status_data)
  569. {
  570. u16 sub_data = u16_get_bits(status_data, IEEE80211_STATUS_SUBDATA_MASK);
  571. enum ieee80211_smps_mode smps_mode = sub_data & 3;
  572. int link_id = (sub_data >> 2);
  573. struct ieee80211_link_data *link;
  574. if (!sdata || !ieee80211_sdata_running(sdata))
  575. return;
  576. if (!acked)
  577. return;
  578. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  579. return;
  580. if (WARN(link_id >= ARRAY_SIZE(sdata->link),
  581. "bad SMPS status link: %d\n", link_id))
  582. return;
  583. link = rcu_dereference(sdata->link[link_id]);
  584. if (!link)
  585. return;
  586. /*
  587. * This update looks racy, but isn't, the only other place
  588. * updating this variable is in managed mode before assoc,
  589. * and we have to be associated to have a status from the
  590. * action frame TX, since we cannot send it while we're not
  591. * associated yet.
  592. */
  593. link->smps_mode = smps_mode;
  594. wiphy_work_queue(sdata->local->hw.wiphy, &link->u.mgd.recalc_smps);
  595. }
  596. static void
  597. ieee80211_handle_teardown_ttlm_status(struct ieee80211_sub_if_data *sdata,
  598. bool acked)
  599. {
  600. if (!sdata || !ieee80211_sdata_running(sdata))
  601. return;
  602. if (!acked)
  603. return;
  604. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  605. return;
  606. wiphy_work_queue(sdata->local->hw.wiphy,
  607. &sdata->u.mgd.teardown_ttlm_work);
  608. }
  609. static void ieee80211_report_used_skb(struct ieee80211_local *local,
  610. struct sk_buff *skb, bool dropped,
  611. ktime_t ack_hwtstamp)
  612. {
  613. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  614. u16 tx_time_est = ieee80211_info_get_tx_time_est(info);
  615. struct ieee80211_hdr *hdr = (void *)skb->data;
  616. bool acked = info->flags & IEEE80211_TX_STAT_ACK;
  617. if (dropped)
  618. acked = false;
  619. if (tx_time_est) {
  620. struct sta_info *sta;
  621. rcu_read_lock();
  622. sta = sta_info_get_by_addrs(local, hdr->addr1, hdr->addr2);
  623. ieee80211_sta_update_pending_airtime(local, sta,
  624. skb_get_queue_mapping(skb),
  625. tx_time_est,
  626. true);
  627. rcu_read_unlock();
  628. }
  629. if (info->flags & IEEE80211_TX_INTFL_MLME_CONN_TX) {
  630. struct ieee80211_sub_if_data *sdata;
  631. rcu_read_lock();
  632. sdata = ieee80211_sdata_from_skb(local, skb);
  633. if (!sdata) {
  634. skb->dev = NULL;
  635. } else if (!dropped) {
  636. /* Check to see if packet is a TDLS teardown packet */
  637. if (ieee80211_is_data(hdr->frame_control) &&
  638. (ieee80211_get_tdls_action(skb) ==
  639. WLAN_TDLS_TEARDOWN)) {
  640. ieee80211_tdls_td_tx_handle(local, sdata, skb,
  641. info->flags);
  642. } else if (ieee80211_s1g_is_twt_setup(skb)) {
  643. if (!acked) {
  644. struct sk_buff *qskb;
  645. qskb = skb_clone(skb, GFP_ATOMIC);
  646. if (qskb) {
  647. skb_queue_tail(&sdata->status_queue,
  648. qskb);
  649. wiphy_work_queue(local->hw.wiphy,
  650. &sdata->work);
  651. }
  652. }
  653. } else {
  654. ieee80211_mgd_conn_tx_status(sdata,
  655. hdr->frame_control,
  656. acked);
  657. }
  658. }
  659. rcu_read_unlock();
  660. } else if (info->status_data_idr) {
  661. ieee80211_report_ack_skb(local, skb, acked, dropped,
  662. ack_hwtstamp);
  663. } else if (info->status_data) {
  664. struct ieee80211_sub_if_data *sdata;
  665. rcu_read_lock();
  666. sdata = ieee80211_sdata_from_skb(local, skb);
  667. switch (u16_get_bits(info->status_data,
  668. IEEE80211_STATUS_TYPE_MASK)) {
  669. case IEEE80211_STATUS_TYPE_SMPS:
  670. ieee80211_handle_smps_status(sdata, acked,
  671. info->status_data);
  672. break;
  673. case IEEE80211_STATUS_TYPE_NEG_TTLM:
  674. ieee80211_handle_teardown_ttlm_status(sdata, acked);
  675. break;
  676. }
  677. rcu_read_unlock();
  678. }
  679. if (!dropped && skb->destructor) {
  680. skb->wifi_acked_valid = 1;
  681. skb->wifi_acked = acked;
  682. }
  683. ieee80211_led_tx(local);
  684. if (skb_has_frag_list(skb)) {
  685. kfree_skb_list(skb_shinfo(skb)->frag_list);
  686. skb_shinfo(skb)->frag_list = NULL;
  687. }
  688. }
  689. /*
  690. * Use a static threshold for now, best value to be determined
  691. * by testing ...
  692. * Should it depend on:
  693. * - on # of retransmissions
  694. * - current throughput (higher value for higher tpt)?
  695. */
  696. #define STA_LOST_PKT_THRESHOLD 50
  697. #define STA_LOST_PKT_TIME HZ /* 1 sec since last ACK */
  698. #define STA_LOST_TDLS_PKT_TIME (10*HZ) /* 10secs since last ACK */
  699. static void ieee80211_lost_packet(struct sta_info *sta,
  700. struct ieee80211_tx_info *info)
  701. {
  702. unsigned long pkt_time = STA_LOST_PKT_TIME;
  703. unsigned int pkt_thr = STA_LOST_PKT_THRESHOLD;
  704. /* If driver relies on its own algorithm for station kickout, skip
  705. * mac80211 packet loss mechanism.
  706. */
  707. if (ieee80211_hw_check(&sta->local->hw, REPORTS_LOW_ACK))
  708. return;
  709. /* This packet was aggregated but doesn't carry status info */
  710. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  711. !(info->flags & IEEE80211_TX_STAT_AMPDU))
  712. return;
  713. sta->deflink.status_stats.lost_packets++;
  714. if (sta->sta.tdls) {
  715. pkt_time = STA_LOST_TDLS_PKT_TIME;
  716. pkt_thr = STA_LOST_PKT_THRESHOLD;
  717. }
  718. /*
  719. * If we're in TDLS mode, make sure that all STA_LOST_PKT_THRESHOLD
  720. * of the last packets were lost, and that no ACK was received in the
  721. * last STA_LOST_TDLS_PKT_TIME ms, before triggering the CQM packet-loss
  722. * mechanism.
  723. * For non-TDLS, use STA_LOST_PKT_THRESHOLD and STA_LOST_PKT_TIME
  724. */
  725. if (sta->deflink.status_stats.lost_packets < pkt_thr ||
  726. !time_after(jiffies, sta->deflink.status_stats.last_pkt_time + pkt_time))
  727. return;
  728. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  729. sta->deflink.status_stats.lost_packets,
  730. GFP_ATOMIC);
  731. sta->deflink.status_stats.lost_packets = 0;
  732. }
  733. static int ieee80211_tx_get_rates(struct ieee80211_hw *hw,
  734. struct ieee80211_tx_info *info,
  735. int *retry_count)
  736. {
  737. int count = -1;
  738. int i;
  739. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  740. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  741. !(info->flags & IEEE80211_TX_STAT_AMPDU)) {
  742. /* just the first aggr frame carry status info */
  743. info->status.rates[i].idx = -1;
  744. info->status.rates[i].count = 0;
  745. break;
  746. } else if (info->status.rates[i].idx < 0) {
  747. break;
  748. } else if (i >= hw->max_report_rates) {
  749. /* the HW cannot have attempted that rate */
  750. info->status.rates[i].idx = -1;
  751. info->status.rates[i].count = 0;
  752. break;
  753. }
  754. count += info->status.rates[i].count;
  755. }
  756. if (count < 0)
  757. count = 0;
  758. *retry_count = count;
  759. return i - 1;
  760. }
  761. void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
  762. int retry_count, bool send_to_cooked,
  763. struct ieee80211_tx_status *status)
  764. {
  765. struct sk_buff *skb2;
  766. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  767. struct ieee80211_sub_if_data *sdata;
  768. struct net_device *prev_dev = NULL;
  769. int rtap_len;
  770. /* send frame to monitor interfaces now */
  771. rtap_len = ieee80211_tx_radiotap_len(info, status);
  772. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  773. pr_err("ieee80211_tx_status: headroom too small\n");
  774. dev_kfree_skb(skb);
  775. return;
  776. }
  777. ieee80211_add_tx_radiotap_header(local, skb, retry_count,
  778. rtap_len, status);
  779. /* XXX: is this sufficient for BPF? */
  780. skb_reset_mac_header(skb);
  781. skb->ip_summed = CHECKSUM_UNNECESSARY;
  782. skb->pkt_type = PACKET_OTHERHOST;
  783. skb->protocol = htons(ETH_P_802_2);
  784. memset(skb->cb, 0, sizeof(skb->cb));
  785. rcu_read_lock();
  786. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  787. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  788. if (!ieee80211_sdata_running(sdata))
  789. continue;
  790. if ((sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) &&
  791. !send_to_cooked)
  792. continue;
  793. if (prev_dev) {
  794. skb2 = skb_clone(skb, GFP_ATOMIC);
  795. if (skb2) {
  796. skb2->dev = prev_dev;
  797. netif_rx(skb2);
  798. }
  799. }
  800. prev_dev = sdata->dev;
  801. }
  802. }
  803. if (prev_dev) {
  804. skb->dev = prev_dev;
  805. netif_rx(skb);
  806. skb = NULL;
  807. }
  808. rcu_read_unlock();
  809. dev_kfree_skb(skb);
  810. }
  811. static void __ieee80211_tx_status(struct ieee80211_hw *hw,
  812. struct ieee80211_tx_status *status,
  813. int rates_idx, int retry_count)
  814. {
  815. struct sk_buff *skb = status->skb;
  816. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  817. struct ieee80211_local *local = hw_to_local(hw);
  818. struct ieee80211_tx_info *info = status->info;
  819. struct sta_info *sta;
  820. __le16 fc;
  821. bool send_to_cooked;
  822. bool acked;
  823. bool noack_success;
  824. struct ieee80211_bar *bar;
  825. int tid = IEEE80211_NUM_TIDS;
  826. fc = hdr->frame_control;
  827. if (status->sta) {
  828. sta = container_of(status->sta, struct sta_info, sta);
  829. if (info->flags & IEEE80211_TX_STATUS_EOSP)
  830. clear_sta_flag(sta, WLAN_STA_SP);
  831. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  832. noack_success = !!(info->flags &
  833. IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  834. /* mesh Peer Service Period support */
  835. if (ieee80211_vif_is_mesh(&sta->sdata->vif) &&
  836. ieee80211_is_data_qos(fc))
  837. ieee80211_mpsp_trigger_process(
  838. ieee80211_get_qos_ctl(hdr), sta, true, acked);
  839. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
  840. (ieee80211_is_data(hdr->frame_control)) &&
  841. (rates_idx != -1))
  842. sta->deflink.tx_stats.last_rate =
  843. info->status.rates[rates_idx];
  844. if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
  845. (ieee80211_is_data_qos(fc))) {
  846. u16 ssn;
  847. u8 *qc;
  848. qc = ieee80211_get_qos_ctl(hdr);
  849. tid = qc[0] & 0xf;
  850. ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
  851. & IEEE80211_SCTL_SEQ);
  852. ieee80211_send_bar(&sta->sdata->vif, hdr->addr1,
  853. tid, ssn);
  854. } else if (ieee80211_is_data_qos(fc)) {
  855. u8 *qc = ieee80211_get_qos_ctl(hdr);
  856. tid = qc[0] & 0xf;
  857. }
  858. if (!acked && ieee80211_is_back_req(fc)) {
  859. u16 control;
  860. /*
  861. * BAR failed, store the last SSN and retry sending
  862. * the BAR when the next unicast transmission on the
  863. * same TID succeeds.
  864. */
  865. bar = (struct ieee80211_bar *) skb->data;
  866. control = le16_to_cpu(bar->control);
  867. if (!(control & IEEE80211_BAR_CTRL_MULTI_TID)) {
  868. u16 ssn = le16_to_cpu(bar->start_seq_num);
  869. tid = (control &
  870. IEEE80211_BAR_CTRL_TID_INFO_MASK) >>
  871. IEEE80211_BAR_CTRL_TID_INFO_SHIFT;
  872. ieee80211_set_bar_pending(sta, tid, ssn);
  873. }
  874. }
  875. if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  876. ieee80211_handle_filtered_frame(local, sta, skb);
  877. return;
  878. } else if (ieee80211_is_data_present(fc)) {
  879. if (!acked && !noack_success)
  880. sta->deflink.status_stats.msdu_failed[tid]++;
  881. sta->deflink.status_stats.msdu_retries[tid] +=
  882. retry_count;
  883. }
  884. if (!(info->flags & IEEE80211_TX_CTL_INJECTED) && acked)
  885. ieee80211_frame_acked(sta, skb);
  886. }
  887. /* SNMP counters
  888. * Fragments are passed to low-level drivers as separate skbs, so these
  889. * are actually fragments, not frames. Update frame counters only for
  890. * the first fragment of the frame. */
  891. if ((info->flags & IEEE80211_TX_STAT_ACK) ||
  892. (info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED)) {
  893. if (ieee80211_is_first_frag(hdr->seq_ctrl)) {
  894. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  895. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  896. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  897. if (retry_count > 0)
  898. I802_DEBUG_INC(local->dot11RetryCount);
  899. if (retry_count > 1)
  900. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  901. }
  902. /* This counter shall be incremented for an acknowledged MPDU
  903. * with an individual address in the address 1 field or an MPDU
  904. * with a multicast address in the address 1 field of type Data
  905. * or Management. */
  906. if (!is_multicast_ether_addr(hdr->addr1) ||
  907. ieee80211_is_data(fc) ||
  908. ieee80211_is_mgmt(fc))
  909. I802_DEBUG_INC(local->dot11TransmittedFragmentCount);
  910. } else {
  911. if (ieee80211_is_first_frag(hdr->seq_ctrl))
  912. I802_DEBUG_INC(local->dot11FailedCount);
  913. }
  914. if (ieee80211_is_any_nullfunc(fc) &&
  915. ieee80211_has_pm(fc) &&
  916. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  917. !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
  918. local->ps_sdata && !(local->scanning)) {
  919. if (info->flags & IEEE80211_TX_STAT_ACK)
  920. local->ps_sdata->u.mgd.flags |=
  921. IEEE80211_STA_NULLFUNC_ACKED;
  922. mod_timer(&local->dynamic_ps_timer,
  923. jiffies + msecs_to_jiffies(10));
  924. }
  925. ieee80211_report_used_skb(local, skb, false, status->ack_hwtstamp);
  926. /* this was a transmitted frame, but now we want to reuse it */
  927. skb_orphan(skb);
  928. /* Need to make a copy before skb->cb gets cleared */
  929. send_to_cooked = !!(info->flags & IEEE80211_TX_CTL_INJECTED) ||
  930. !(ieee80211_is_data(fc));
  931. /*
  932. * This is a bit racy but we can avoid a lot of work
  933. * with this test...
  934. */
  935. if (!local->monitors && (!send_to_cooked || !local->cooked_mntrs)) {
  936. if (status->free_list)
  937. list_add_tail(&skb->list, status->free_list);
  938. else
  939. dev_kfree_skb(skb);
  940. return;
  941. }
  942. /* send to monitor interfaces */
  943. ieee80211_tx_monitor(local, skb, retry_count,
  944. send_to_cooked, status);
  945. }
  946. void ieee80211_tx_status_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
  947. {
  948. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  949. struct ieee80211_local *local = hw_to_local(hw);
  950. struct ieee80211_tx_status status = {
  951. .skb = skb,
  952. .info = IEEE80211_SKB_CB(skb),
  953. };
  954. struct sta_info *sta;
  955. rcu_read_lock();
  956. sta = sta_info_get_by_addrs(local, hdr->addr1, hdr->addr2);
  957. if (sta)
  958. status.sta = &sta->sta;
  959. ieee80211_tx_status_ext(hw, &status);
  960. rcu_read_unlock();
  961. }
  962. EXPORT_SYMBOL(ieee80211_tx_status_skb);
  963. void ieee80211_tx_status_ext(struct ieee80211_hw *hw,
  964. struct ieee80211_tx_status *status)
  965. {
  966. struct ieee80211_local *local = hw_to_local(hw);
  967. struct ieee80211_tx_info *info = status->info;
  968. struct ieee80211_sta *pubsta = status->sta;
  969. struct sk_buff *skb = status->skb;
  970. struct sta_info *sta = NULL;
  971. int rates_idx, retry_count;
  972. bool acked, noack_success, ack_signal_valid;
  973. u16 tx_time_est;
  974. if (pubsta) {
  975. sta = container_of(pubsta, struct sta_info, sta);
  976. if (status->n_rates)
  977. sta->deflink.tx_stats.last_rate_info =
  978. status->rates[status->n_rates - 1].rate_idx;
  979. }
  980. if (skb && (tx_time_est =
  981. ieee80211_info_get_tx_time_est(IEEE80211_SKB_CB(skb))) > 0) {
  982. /* Do this here to avoid the expensive lookup of the sta
  983. * in ieee80211_report_used_skb().
  984. */
  985. ieee80211_sta_update_pending_airtime(local, sta,
  986. skb_get_queue_mapping(skb),
  987. tx_time_est,
  988. true);
  989. ieee80211_info_set_tx_time_est(IEEE80211_SKB_CB(skb), 0);
  990. }
  991. if (!status->info)
  992. goto free;
  993. rates_idx = ieee80211_tx_get_rates(hw, info, &retry_count);
  994. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  995. noack_success = !!(info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  996. ack_signal_valid =
  997. !!(info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID);
  998. if (pubsta) {
  999. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1000. if (!acked && !noack_success)
  1001. sta->deflink.status_stats.retry_failed++;
  1002. sta->deflink.status_stats.retry_count += retry_count;
  1003. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  1004. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1005. skb && !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
  1006. ieee80211_sta_tx_notify(sdata, (void *) skb->data,
  1007. acked, info->status.tx_time);
  1008. if (acked) {
  1009. sta->deflink.status_stats.last_ack = jiffies;
  1010. if (sta->deflink.status_stats.lost_packets)
  1011. sta->deflink.status_stats.lost_packets = 0;
  1012. /* Track when last packet was ACKed */
  1013. sta->deflink.status_stats.last_pkt_time = jiffies;
  1014. /* Reset connection monitor */
  1015. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1016. unlikely(sdata->u.mgd.probe_send_count > 0))
  1017. sdata->u.mgd.probe_send_count = 0;
  1018. if (ack_signal_valid) {
  1019. sta->deflink.status_stats.last_ack_signal =
  1020. (s8)info->status.ack_signal;
  1021. sta->deflink.status_stats.ack_signal_filled = true;
  1022. ewma_avg_signal_add(&sta->deflink.status_stats.avg_ack_signal,
  1023. -info->status.ack_signal);
  1024. }
  1025. } else if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1026. /*
  1027. * The STA is in power save mode, so assume
  1028. * that this TX packet failed because of that.
  1029. */
  1030. if (skb)
  1031. ieee80211_handle_filtered_frame(local, sta, skb);
  1032. return;
  1033. } else if (noack_success) {
  1034. /* nothing to do here, do not account as lost */
  1035. } else {
  1036. ieee80211_lost_packet(sta, info);
  1037. }
  1038. }
  1039. rate_control_tx_status(local, status);
  1040. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  1041. ieee80211s_update_metric(local, sta, status);
  1042. }
  1043. if (skb && !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
  1044. return __ieee80211_tx_status(hw, status, rates_idx,
  1045. retry_count);
  1046. if (acked || noack_success) {
  1047. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  1048. if (!pubsta)
  1049. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  1050. if (retry_count > 0)
  1051. I802_DEBUG_INC(local->dot11RetryCount);
  1052. if (retry_count > 1)
  1053. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  1054. } else {
  1055. I802_DEBUG_INC(local->dot11FailedCount);
  1056. }
  1057. free:
  1058. if (!skb)
  1059. return;
  1060. ieee80211_report_used_skb(local, skb, false, status->ack_hwtstamp);
  1061. if (status->free_list)
  1062. list_add_tail(&skb->list, status->free_list);
  1063. else
  1064. dev_kfree_skb(skb);
  1065. }
  1066. EXPORT_SYMBOL(ieee80211_tx_status_ext);
  1067. void ieee80211_tx_rate_update(struct ieee80211_hw *hw,
  1068. struct ieee80211_sta *pubsta,
  1069. struct ieee80211_tx_info *info)
  1070. {
  1071. struct ieee80211_local *local = hw_to_local(hw);
  1072. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1073. struct ieee80211_tx_status status = {
  1074. .info = info,
  1075. .sta = pubsta,
  1076. };
  1077. rate_control_tx_status(local, &status);
  1078. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
  1079. sta->deflink.tx_stats.last_rate = info->status.rates[0];
  1080. }
  1081. EXPORT_SYMBOL(ieee80211_tx_rate_update);
  1082. void ieee80211_report_low_ack(struct ieee80211_sta *pubsta, u32 num_packets)
  1083. {
  1084. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1085. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  1086. num_packets, GFP_ATOMIC);
  1087. }
  1088. EXPORT_SYMBOL(ieee80211_report_low_ack);
  1089. void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb)
  1090. {
  1091. struct ieee80211_local *local = hw_to_local(hw);
  1092. ktime_t kt = ktime_set(0, 0);
  1093. ieee80211_report_used_skb(local, skb, true, kt);
  1094. dev_kfree_skb_any(skb);
  1095. }
  1096. EXPORT_SYMBOL(ieee80211_free_txskb);
  1097. void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
  1098. struct sk_buff_head *skbs)
  1099. {
  1100. struct sk_buff *skb;
  1101. while ((skb = __skb_dequeue(skbs)))
  1102. ieee80211_free_txskb(hw, skb);
  1103. }
  1104. EXPORT_SYMBOL(ieee80211_purge_tx_queue);