status.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  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 <[email protected]>
  6. * Copyright 2008-2010 Johannes Berg <[email protected]>
  7. * Copyright 2013-2014 Intel Mobile Communications GmbH
  8. * Copyright 2021-2022 Intel Corporation
  9. */
  10. #include <linux/export.h>
  11. #include <linux/etherdevice.h>
  12. #include <net/mac80211.h>
  13. #include <asm/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. struct ieee80211_local *local = sta->local;
  167. struct ieee80211_sub_if_data *sdata = sta->sdata;
  168. if (ieee80211_is_data_qos(mgmt->frame_control)) {
  169. struct ieee80211_hdr *hdr = (void *) skb->data;
  170. u8 *qc = ieee80211_get_qos_ctl(hdr);
  171. u16 tid = qc[0] & 0xf;
  172. ieee80211_check_pending_bar(sta, hdr->addr1, tid);
  173. }
  174. if (ieee80211_is_action(mgmt->frame_control) &&
  175. !ieee80211_has_protected(mgmt->frame_control) &&
  176. mgmt->u.action.category == WLAN_CATEGORY_HT &&
  177. mgmt->u.action.u.ht_smps.action == WLAN_HT_ACTION_SMPS &&
  178. ieee80211_sdata_running(sdata)) {
  179. enum ieee80211_smps_mode smps_mode;
  180. switch (mgmt->u.action.u.ht_smps.smps_control) {
  181. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  182. smps_mode = IEEE80211_SMPS_DYNAMIC;
  183. break;
  184. case WLAN_HT_SMPS_CONTROL_STATIC:
  185. smps_mode = IEEE80211_SMPS_STATIC;
  186. break;
  187. case WLAN_HT_SMPS_CONTROL_DISABLED:
  188. default: /* shouldn't happen since we don't send that */
  189. smps_mode = IEEE80211_SMPS_OFF;
  190. break;
  191. }
  192. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  193. /*
  194. * This update looks racy, but isn't -- if we come
  195. * here we've definitely got a station that we're
  196. * talking to, and on a managed interface that can
  197. * only be the AP. And the only other place updating
  198. * this variable in managed mode is before association.
  199. */
  200. sdata->deflink.smps_mode = smps_mode;
  201. ieee80211_queue_work(&local->hw, &sdata->recalc_smps);
  202. }
  203. }
  204. }
  205. static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn)
  206. {
  207. struct tid_ampdu_tx *tid_tx;
  208. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  209. if (!tid_tx)
  210. return;
  211. tid_tx->failed_bar_ssn = ssn;
  212. tid_tx->bar_pending = true;
  213. }
  214. static int ieee80211_tx_radiotap_len(struct ieee80211_tx_info *info,
  215. struct ieee80211_tx_status *status)
  216. {
  217. struct ieee80211_rate_status *status_rate = NULL;
  218. int len = sizeof(struct ieee80211_radiotap_header);
  219. if (status && status->n_rates)
  220. status_rate = &status->rates[status->n_rates - 1];
  221. /* IEEE80211_RADIOTAP_RATE rate */
  222. if (status_rate && !(status_rate->rate_idx.flags &
  223. (RATE_INFO_FLAGS_MCS |
  224. RATE_INFO_FLAGS_DMG |
  225. RATE_INFO_FLAGS_EDMG |
  226. RATE_INFO_FLAGS_VHT_MCS |
  227. RATE_INFO_FLAGS_HE_MCS)))
  228. len += 2;
  229. else if (info->status.rates[0].idx >= 0 &&
  230. !(info->status.rates[0].flags &
  231. (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS)))
  232. len += 2;
  233. /* IEEE80211_RADIOTAP_TX_FLAGS */
  234. len += 2;
  235. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  236. len += 1;
  237. /* IEEE80211_RADIOTAP_MCS
  238. * IEEE80211_RADIOTAP_VHT */
  239. if (status_rate) {
  240. if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_MCS)
  241. len += 3;
  242. else if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_VHT_MCS)
  243. len = ALIGN(len, 2) + 12;
  244. else if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_HE_MCS)
  245. len = ALIGN(len, 2) + 12;
  246. } else if (info->status.rates[0].idx >= 0) {
  247. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS)
  248. len += 3;
  249. else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS)
  250. len = ALIGN(len, 2) + 12;
  251. }
  252. return len;
  253. }
  254. static void
  255. ieee80211_add_tx_radiotap_header(struct ieee80211_local *local,
  256. struct sk_buff *skb, int retry_count,
  257. int rtap_len, int shift,
  258. struct ieee80211_tx_status *status)
  259. {
  260. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  261. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  262. struct ieee80211_radiotap_header *rthdr;
  263. struct ieee80211_rate_status *status_rate = NULL;
  264. unsigned char *pos;
  265. u16 legacy_rate = 0;
  266. u16 txflags;
  267. if (status && status->n_rates)
  268. status_rate = &status->rates[status->n_rates - 1];
  269. rthdr = skb_push(skb, rtap_len);
  270. memset(rthdr, 0, rtap_len);
  271. rthdr->it_len = cpu_to_le16(rtap_len);
  272. rthdr->it_present =
  273. cpu_to_le32(BIT(IEEE80211_RADIOTAP_TX_FLAGS) |
  274. BIT(IEEE80211_RADIOTAP_DATA_RETRIES));
  275. pos = (unsigned char *)(rthdr + 1);
  276. /*
  277. * XXX: Once radiotap gets the bitmap reset thing the vendor
  278. * extensions proposal contains, we can actually report
  279. * the whole set of tries we did.
  280. */
  281. /* IEEE80211_RADIOTAP_RATE */
  282. if (status_rate) {
  283. if (!(status_rate->rate_idx.flags &
  284. (RATE_INFO_FLAGS_MCS |
  285. RATE_INFO_FLAGS_DMG |
  286. RATE_INFO_FLAGS_EDMG |
  287. RATE_INFO_FLAGS_VHT_MCS |
  288. RATE_INFO_FLAGS_HE_MCS)))
  289. legacy_rate = status_rate->rate_idx.legacy;
  290. } else if (info->status.rates[0].idx >= 0 &&
  291. !(info->status.rates[0].flags & (IEEE80211_TX_RC_MCS |
  292. IEEE80211_TX_RC_VHT_MCS))) {
  293. struct ieee80211_supported_band *sband;
  294. sband = local->hw.wiphy->bands[info->band];
  295. legacy_rate =
  296. sband->bitrates[info->status.rates[0].idx].bitrate;
  297. }
  298. if (legacy_rate) {
  299. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
  300. *pos = DIV_ROUND_UP(legacy_rate, 5 * (1 << shift));
  301. /* padding for tx flags */
  302. pos += 2;
  303. }
  304. /* IEEE80211_RADIOTAP_TX_FLAGS */
  305. txflags = 0;
  306. if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
  307. !is_multicast_ether_addr(hdr->addr1))
  308. txflags |= IEEE80211_RADIOTAP_F_TX_FAIL;
  309. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  310. txflags |= IEEE80211_RADIOTAP_F_TX_CTS;
  311. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  312. txflags |= IEEE80211_RADIOTAP_F_TX_RTS;
  313. put_unaligned_le16(txflags, pos);
  314. pos += 2;
  315. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  316. /* for now report the total retry_count */
  317. *pos = retry_count;
  318. pos++;
  319. if (status_rate && (status_rate->rate_idx.flags & RATE_INFO_FLAGS_MCS))
  320. {
  321. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
  322. pos[0] = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  323. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  324. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  325. if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_SHORT_GI)
  326. pos[1] |= IEEE80211_RADIOTAP_MCS_SGI;
  327. if (status_rate->rate_idx.bw == RATE_INFO_BW_40)
  328. pos[1] |= IEEE80211_RADIOTAP_MCS_BW_40;
  329. pos[2] = status_rate->rate_idx.mcs;
  330. pos += 3;
  331. } else if (status_rate && (status_rate->rate_idx.flags &
  332. RATE_INFO_FLAGS_VHT_MCS))
  333. {
  334. u16 known = local->hw.radiotap_vht_details &
  335. (IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  336. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH);
  337. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
  338. /* required alignment from rthdr */
  339. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  340. /* u16 known - IEEE80211_RADIOTAP_VHT_KNOWN_* */
  341. put_unaligned_le16(known, pos);
  342. pos += 2;
  343. /* u8 flags - IEEE80211_RADIOTAP_VHT_FLAG_* */
  344. if (status_rate->rate_idx.flags & RATE_INFO_FLAGS_SHORT_GI)
  345. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  346. pos++;
  347. /* u8 bandwidth */
  348. switch (status_rate->rate_idx.bw) {
  349. case RATE_INFO_BW_160:
  350. *pos = 11;
  351. break;
  352. case RATE_INFO_BW_80:
  353. *pos = 4;
  354. break;
  355. case RATE_INFO_BW_40:
  356. *pos = 1;
  357. break;
  358. default:
  359. *pos = 0;
  360. break;
  361. }
  362. pos++;
  363. /* u8 mcs_nss[4] */
  364. *pos = (status_rate->rate_idx.mcs << 4) |
  365. status_rate->rate_idx.nss;
  366. pos += 4;
  367. /* u8 coding */
  368. pos++;
  369. /* u8 group_id */
  370. pos++;
  371. /* u16 partial_aid */
  372. pos += 2;
  373. } else if (status_rate && (status_rate->rate_idx.flags &
  374. RATE_INFO_FLAGS_HE_MCS))
  375. {
  376. struct ieee80211_radiotap_he *he;
  377. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
  378. /* required alignment from rthdr */
  379. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  380. he = (struct ieee80211_radiotap_he *)pos;
  381. he->data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_SU |
  382. IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN |
  383. IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN |
  384. IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
  385. he->data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN);
  386. #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
  387. he->data6 |= HE_PREP(DATA6_NSTS, status_rate->rate_idx.nss);
  388. #define CHECK_GI(s) \
  389. BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
  390. (int)NL80211_RATE_INFO_HE_GI_##s)
  391. CHECK_GI(0_8);
  392. CHECK_GI(1_6);
  393. CHECK_GI(3_2);
  394. he->data3 |= HE_PREP(DATA3_DATA_MCS, status_rate->rate_idx.mcs);
  395. he->data3 |= HE_PREP(DATA3_DATA_DCM, status_rate->rate_idx.he_dcm);
  396. he->data5 |= HE_PREP(DATA5_GI, status_rate->rate_idx.he_gi);
  397. switch (status_rate->rate_idx.bw) {
  398. case RATE_INFO_BW_20:
  399. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  400. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
  401. break;
  402. case RATE_INFO_BW_40:
  403. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  404. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
  405. break;
  406. case RATE_INFO_BW_80:
  407. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  408. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
  409. break;
  410. case RATE_INFO_BW_160:
  411. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  412. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
  413. break;
  414. case RATE_INFO_BW_HE_RU:
  415. #define CHECK_RU_ALLOC(s) \
  416. BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
  417. NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
  418. CHECK_RU_ALLOC(26);
  419. CHECK_RU_ALLOC(52);
  420. CHECK_RU_ALLOC(106);
  421. CHECK_RU_ALLOC(242);
  422. CHECK_RU_ALLOC(484);
  423. CHECK_RU_ALLOC(996);
  424. CHECK_RU_ALLOC(2x996);
  425. he->data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  426. status_rate->rate_idx.he_ru_alloc + 4);
  427. break;
  428. default:
  429. WARN_ONCE(1, "Invalid SU BW %d\n", status_rate->rate_idx.bw);
  430. }
  431. pos += sizeof(struct ieee80211_radiotap_he);
  432. }
  433. if (status_rate || info->status.rates[0].idx < 0)
  434. return;
  435. /* IEEE80211_RADIOTAP_MCS
  436. * IEEE80211_RADIOTAP_VHT */
  437. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS) {
  438. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
  439. pos[0] = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  440. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  441. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  442. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  443. pos[1] |= IEEE80211_RADIOTAP_MCS_SGI;
  444. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  445. pos[1] |= IEEE80211_RADIOTAP_MCS_BW_40;
  446. if (info->status.rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD)
  447. pos[1] |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  448. pos[2] = info->status.rates[0].idx;
  449. pos += 3;
  450. } else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
  451. u16 known = local->hw.radiotap_vht_details &
  452. (IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  453. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH);
  454. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
  455. /* required alignment from rthdr */
  456. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  457. /* u16 known - IEEE80211_RADIOTAP_VHT_KNOWN_* */
  458. put_unaligned_le16(known, pos);
  459. pos += 2;
  460. /* u8 flags - IEEE80211_RADIOTAP_VHT_FLAG_* */
  461. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  462. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  463. pos++;
  464. /* u8 bandwidth */
  465. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  466. *pos = 1;
  467. else if (info->status.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  468. *pos = 4;
  469. else if (info->status.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  470. *pos = 11;
  471. else /* IEEE80211_TX_RC_{20_MHZ_WIDTH,FIXME:DUP_DATA} */
  472. *pos = 0;
  473. pos++;
  474. /* u8 mcs_nss[4] */
  475. *pos = (ieee80211_rate_get_vht_mcs(&info->status.rates[0]) << 4) |
  476. ieee80211_rate_get_vht_nss(&info->status.rates[0]);
  477. pos += 4;
  478. /* u8 coding */
  479. pos++;
  480. /* u8 group_id */
  481. pos++;
  482. /* u16 partial_aid */
  483. pos += 2;
  484. }
  485. }
  486. /*
  487. * Handles the tx for TDLS teardown frames.
  488. * If the frame wasn't ACKed by the peer - it will be re-sent through the AP
  489. */
  490. static void ieee80211_tdls_td_tx_handle(struct ieee80211_local *local,
  491. struct ieee80211_sub_if_data *sdata,
  492. struct sk_buff *skb, u32 flags)
  493. {
  494. struct sk_buff *teardown_skb;
  495. struct sk_buff *orig_teardown_skb;
  496. bool is_teardown = false;
  497. /* Get the teardown data we need and free the lock */
  498. spin_lock(&sdata->u.mgd.teardown_lock);
  499. teardown_skb = sdata->u.mgd.teardown_skb;
  500. orig_teardown_skb = sdata->u.mgd.orig_teardown_skb;
  501. if ((skb == orig_teardown_skb) && teardown_skb) {
  502. sdata->u.mgd.teardown_skb = NULL;
  503. sdata->u.mgd.orig_teardown_skb = NULL;
  504. is_teardown = true;
  505. }
  506. spin_unlock(&sdata->u.mgd.teardown_lock);
  507. if (is_teardown) {
  508. /* This mechanism relies on being able to get ACKs */
  509. WARN_ON(!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS));
  510. /* Check if peer has ACKed */
  511. if (flags & IEEE80211_TX_STAT_ACK) {
  512. dev_kfree_skb_any(teardown_skb);
  513. } else {
  514. tdls_dbg(sdata,
  515. "TDLS Resending teardown through AP\n");
  516. ieee80211_subif_start_xmit(teardown_skb, skb->dev);
  517. }
  518. }
  519. }
  520. static struct ieee80211_sub_if_data *
  521. ieee80211_sdata_from_skb(struct ieee80211_local *local, struct sk_buff *skb)
  522. {
  523. struct ieee80211_sub_if_data *sdata;
  524. if (skb->dev) {
  525. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  526. if (!sdata->dev)
  527. continue;
  528. if (skb->dev == sdata->dev)
  529. return sdata;
  530. }
  531. return NULL;
  532. }
  533. return rcu_dereference(local->p2p_sdata);
  534. }
  535. static void ieee80211_report_ack_skb(struct ieee80211_local *local,
  536. struct sk_buff *orig_skb,
  537. bool acked, bool dropped,
  538. ktime_t ack_hwtstamp)
  539. {
  540. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(orig_skb);
  541. struct sk_buff *skb;
  542. unsigned long flags;
  543. spin_lock_irqsave(&local->ack_status_lock, flags);
  544. skb = idr_remove(&local->ack_status_frames, info->ack_frame_id);
  545. spin_unlock_irqrestore(&local->ack_status_lock, flags);
  546. if (!skb)
  547. return;
  548. if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) {
  549. u64 cookie = IEEE80211_SKB_CB(skb)->ack.cookie;
  550. struct ieee80211_sub_if_data *sdata;
  551. struct ieee80211_hdr *hdr = (void *)skb->data;
  552. bool is_valid_ack_signal =
  553. !!(info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID);
  554. struct cfg80211_tx_status status = {
  555. .cookie = cookie,
  556. .buf = skb->data,
  557. .len = skb->len,
  558. .ack = acked,
  559. };
  560. if (ieee80211_is_timing_measurement(orig_skb) ||
  561. ieee80211_is_ftm(orig_skb)) {
  562. status.tx_tstamp =
  563. ktime_to_ns(skb_hwtstamps(orig_skb)->hwtstamp);
  564. status.ack_tstamp = ktime_to_ns(ack_hwtstamp);
  565. }
  566. rcu_read_lock();
  567. sdata = ieee80211_sdata_from_skb(local, skb);
  568. if (sdata) {
  569. if (skb->protocol == sdata->control_port_protocol ||
  570. skb->protocol == cpu_to_be16(ETH_P_PREAUTH))
  571. cfg80211_control_port_tx_status(&sdata->wdev,
  572. cookie,
  573. skb->data,
  574. skb->len,
  575. acked,
  576. GFP_ATOMIC);
  577. else if (ieee80211_is_any_nullfunc(hdr->frame_control))
  578. cfg80211_probe_status(sdata->dev, hdr->addr1,
  579. cookie, acked,
  580. info->status.ack_signal,
  581. is_valid_ack_signal,
  582. GFP_ATOMIC);
  583. else if (ieee80211_is_mgmt(hdr->frame_control))
  584. cfg80211_mgmt_tx_status_ext(&sdata->wdev,
  585. &status,
  586. GFP_ATOMIC);
  587. else
  588. pr_warn("Unknown status report in ack skb\n");
  589. }
  590. rcu_read_unlock();
  591. dev_kfree_skb_any(skb);
  592. } else if (dropped) {
  593. dev_kfree_skb_any(skb);
  594. } else {
  595. /* consumes skb */
  596. skb_complete_wifi_ack(skb, acked);
  597. }
  598. }
  599. static void ieee80211_report_used_skb(struct ieee80211_local *local,
  600. struct sk_buff *skb, bool dropped,
  601. ktime_t ack_hwtstamp)
  602. {
  603. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  604. u16 tx_time_est = ieee80211_info_get_tx_time_est(info);
  605. struct ieee80211_hdr *hdr = (void *)skb->data;
  606. bool acked = info->flags & IEEE80211_TX_STAT_ACK;
  607. if (dropped)
  608. acked = false;
  609. if (tx_time_est) {
  610. struct sta_info *sta;
  611. rcu_read_lock();
  612. sta = sta_info_get_by_addrs(local, hdr->addr1, hdr->addr2);
  613. ieee80211_sta_update_pending_airtime(local, sta,
  614. skb_get_queue_mapping(skb),
  615. tx_time_est,
  616. true);
  617. rcu_read_unlock();
  618. }
  619. if (info->flags & IEEE80211_TX_INTFL_MLME_CONN_TX) {
  620. struct ieee80211_sub_if_data *sdata;
  621. rcu_read_lock();
  622. sdata = ieee80211_sdata_from_skb(local, skb);
  623. if (!sdata) {
  624. skb->dev = NULL;
  625. } else if (!dropped) {
  626. unsigned int hdr_size =
  627. ieee80211_hdrlen(hdr->frame_control);
  628. /* Check to see if packet is a TDLS teardown packet */
  629. if (ieee80211_is_data(hdr->frame_control) &&
  630. (ieee80211_get_tdls_action(skb, hdr_size) ==
  631. WLAN_TDLS_TEARDOWN)) {
  632. ieee80211_tdls_td_tx_handle(local, sdata, skb,
  633. info->flags);
  634. } else if (ieee80211_s1g_is_twt_setup(skb)) {
  635. if (!acked) {
  636. struct sk_buff *qskb;
  637. qskb = skb_clone(skb, GFP_ATOMIC);
  638. if (qskb) {
  639. skb_queue_tail(&sdata->status_queue,
  640. qskb);
  641. ieee80211_queue_work(&local->hw,
  642. &sdata->work);
  643. }
  644. }
  645. } else {
  646. ieee80211_mgd_conn_tx_status(sdata,
  647. hdr->frame_control,
  648. acked);
  649. }
  650. }
  651. rcu_read_unlock();
  652. } else if (info->ack_frame_id) {
  653. ieee80211_report_ack_skb(local, skb, acked, dropped,
  654. ack_hwtstamp);
  655. }
  656. if (!dropped && skb->destructor) {
  657. skb->wifi_acked_valid = 1;
  658. skb->wifi_acked = acked;
  659. }
  660. ieee80211_led_tx(local);
  661. if (skb_has_frag_list(skb)) {
  662. kfree_skb_list(skb_shinfo(skb)->frag_list);
  663. skb_shinfo(skb)->frag_list = NULL;
  664. }
  665. }
  666. /*
  667. * Use a static threshold for now, best value to be determined
  668. * by testing ...
  669. * Should it depend on:
  670. * - on # of retransmissions
  671. * - current throughput (higher value for higher tpt)?
  672. */
  673. #define STA_LOST_PKT_THRESHOLD 50
  674. #define STA_LOST_PKT_TIME HZ /* 1 sec since last ACK */
  675. #define STA_LOST_TDLS_PKT_TIME (10*HZ) /* 10secs since last ACK */
  676. static void ieee80211_lost_packet(struct sta_info *sta,
  677. struct ieee80211_tx_info *info)
  678. {
  679. unsigned long pkt_time = STA_LOST_PKT_TIME;
  680. unsigned int pkt_thr = STA_LOST_PKT_THRESHOLD;
  681. /* If driver relies on its own algorithm for station kickout, skip
  682. * mac80211 packet loss mechanism.
  683. */
  684. if (ieee80211_hw_check(&sta->local->hw, REPORTS_LOW_ACK))
  685. return;
  686. /* This packet was aggregated but doesn't carry status info */
  687. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  688. !(info->flags & IEEE80211_TX_STAT_AMPDU))
  689. return;
  690. sta->deflink.status_stats.lost_packets++;
  691. if (sta->sta.tdls) {
  692. pkt_time = STA_LOST_TDLS_PKT_TIME;
  693. pkt_thr = STA_LOST_PKT_THRESHOLD;
  694. }
  695. /*
  696. * If we're in TDLS mode, make sure that all STA_LOST_PKT_THRESHOLD
  697. * of the last packets were lost, and that no ACK was received in the
  698. * last STA_LOST_TDLS_PKT_TIME ms, before triggering the CQM packet-loss
  699. * mechanism.
  700. * For non-TDLS, use STA_LOST_PKT_THRESHOLD and STA_LOST_PKT_TIME
  701. */
  702. if (sta->deflink.status_stats.lost_packets < pkt_thr ||
  703. !time_after(jiffies, sta->deflink.status_stats.last_pkt_time + pkt_time))
  704. return;
  705. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  706. sta->deflink.status_stats.lost_packets,
  707. GFP_ATOMIC);
  708. sta->deflink.status_stats.lost_packets = 0;
  709. }
  710. static int ieee80211_tx_get_rates(struct ieee80211_hw *hw,
  711. struct ieee80211_tx_info *info,
  712. int *retry_count)
  713. {
  714. int count = -1;
  715. int i;
  716. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  717. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  718. !(info->flags & IEEE80211_TX_STAT_AMPDU)) {
  719. /* just the first aggr frame carry status info */
  720. info->status.rates[i].idx = -1;
  721. info->status.rates[i].count = 0;
  722. break;
  723. } else if (info->status.rates[i].idx < 0) {
  724. break;
  725. } else if (i >= hw->max_report_rates) {
  726. /* the HW cannot have attempted that rate */
  727. info->status.rates[i].idx = -1;
  728. info->status.rates[i].count = 0;
  729. break;
  730. }
  731. count += info->status.rates[i].count;
  732. }
  733. if (count < 0)
  734. count = 0;
  735. *retry_count = count;
  736. return i - 1;
  737. }
  738. void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
  739. int retry_count, int shift, bool send_to_cooked,
  740. struct ieee80211_tx_status *status)
  741. {
  742. struct sk_buff *skb2;
  743. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  744. struct ieee80211_sub_if_data *sdata;
  745. struct net_device *prev_dev = NULL;
  746. int rtap_len;
  747. /* send frame to monitor interfaces now */
  748. rtap_len = ieee80211_tx_radiotap_len(info, status);
  749. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  750. pr_err("ieee80211_tx_status: headroom too small\n");
  751. dev_kfree_skb(skb);
  752. return;
  753. }
  754. ieee80211_add_tx_radiotap_header(local, skb, retry_count,
  755. rtap_len, shift, status);
  756. /* XXX: is this sufficient for BPF? */
  757. skb_reset_mac_header(skb);
  758. skb->ip_summed = CHECKSUM_UNNECESSARY;
  759. skb->pkt_type = PACKET_OTHERHOST;
  760. skb->protocol = htons(ETH_P_802_2);
  761. memset(skb->cb, 0, sizeof(skb->cb));
  762. rcu_read_lock();
  763. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  764. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  765. if (!ieee80211_sdata_running(sdata))
  766. continue;
  767. if ((sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) &&
  768. !send_to_cooked)
  769. continue;
  770. if (prev_dev) {
  771. skb2 = skb_clone(skb, GFP_ATOMIC);
  772. if (skb2) {
  773. skb2->dev = prev_dev;
  774. netif_rx(skb2);
  775. }
  776. }
  777. prev_dev = sdata->dev;
  778. }
  779. }
  780. if (prev_dev) {
  781. skb->dev = prev_dev;
  782. netif_rx(skb);
  783. skb = NULL;
  784. }
  785. rcu_read_unlock();
  786. dev_kfree_skb(skb);
  787. }
  788. static void __ieee80211_tx_status(struct ieee80211_hw *hw,
  789. struct ieee80211_tx_status *status,
  790. int rates_idx, int retry_count)
  791. {
  792. struct sk_buff *skb = status->skb;
  793. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  794. struct ieee80211_local *local = hw_to_local(hw);
  795. struct ieee80211_tx_info *info = status->info;
  796. struct sta_info *sta;
  797. __le16 fc;
  798. bool send_to_cooked;
  799. bool acked;
  800. bool noack_success;
  801. struct ieee80211_bar *bar;
  802. int shift = 0;
  803. int tid = IEEE80211_NUM_TIDS;
  804. fc = hdr->frame_control;
  805. if (status->sta) {
  806. sta = container_of(status->sta, struct sta_info, sta);
  807. shift = ieee80211_vif_get_shift(&sta->sdata->vif);
  808. if (info->flags & IEEE80211_TX_STATUS_EOSP)
  809. clear_sta_flag(sta, WLAN_STA_SP);
  810. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  811. noack_success = !!(info->flags &
  812. IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  813. /* mesh Peer Service Period support */
  814. if (ieee80211_vif_is_mesh(&sta->sdata->vif) &&
  815. ieee80211_is_data_qos(fc))
  816. ieee80211_mpsp_trigger_process(
  817. ieee80211_get_qos_ctl(hdr), sta, true, acked);
  818. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
  819. (ieee80211_is_data(hdr->frame_control)) &&
  820. (rates_idx != -1))
  821. sta->deflink.tx_stats.last_rate =
  822. info->status.rates[rates_idx];
  823. if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
  824. (ieee80211_is_data_qos(fc))) {
  825. u16 ssn;
  826. u8 *qc;
  827. qc = ieee80211_get_qos_ctl(hdr);
  828. tid = qc[0] & 0xf;
  829. ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
  830. & IEEE80211_SCTL_SEQ);
  831. ieee80211_send_bar(&sta->sdata->vif, hdr->addr1,
  832. tid, ssn);
  833. } else if (ieee80211_is_data_qos(fc)) {
  834. u8 *qc = ieee80211_get_qos_ctl(hdr);
  835. tid = qc[0] & 0xf;
  836. }
  837. if (!acked && ieee80211_is_back_req(fc)) {
  838. u16 control;
  839. /*
  840. * BAR failed, store the last SSN and retry sending
  841. * the BAR when the next unicast transmission on the
  842. * same TID succeeds.
  843. */
  844. bar = (struct ieee80211_bar *) skb->data;
  845. control = le16_to_cpu(bar->control);
  846. if (!(control & IEEE80211_BAR_CTRL_MULTI_TID)) {
  847. u16 ssn = le16_to_cpu(bar->start_seq_num);
  848. tid = (control &
  849. IEEE80211_BAR_CTRL_TID_INFO_MASK) >>
  850. IEEE80211_BAR_CTRL_TID_INFO_SHIFT;
  851. ieee80211_set_bar_pending(sta, tid, ssn);
  852. }
  853. }
  854. if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  855. ieee80211_handle_filtered_frame(local, sta, skb);
  856. return;
  857. } else if (ieee80211_is_data_present(fc)) {
  858. if (!acked && !noack_success)
  859. sta->deflink.status_stats.msdu_failed[tid]++;
  860. sta->deflink.status_stats.msdu_retries[tid] +=
  861. retry_count;
  862. }
  863. if (!(info->flags & IEEE80211_TX_CTL_INJECTED) && acked)
  864. ieee80211_frame_acked(sta, skb);
  865. }
  866. /* SNMP counters
  867. * Fragments are passed to low-level drivers as separate skbs, so these
  868. * are actually fragments, not frames. Update frame counters only for
  869. * the first fragment of the frame. */
  870. if ((info->flags & IEEE80211_TX_STAT_ACK) ||
  871. (info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED)) {
  872. if (ieee80211_is_first_frag(hdr->seq_ctrl)) {
  873. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  874. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  875. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  876. if (retry_count > 0)
  877. I802_DEBUG_INC(local->dot11RetryCount);
  878. if (retry_count > 1)
  879. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  880. }
  881. /* This counter shall be incremented for an acknowledged MPDU
  882. * with an individual address in the address 1 field or an MPDU
  883. * with a multicast address in the address 1 field of type Data
  884. * or Management. */
  885. if (!is_multicast_ether_addr(hdr->addr1) ||
  886. ieee80211_is_data(fc) ||
  887. ieee80211_is_mgmt(fc))
  888. I802_DEBUG_INC(local->dot11TransmittedFragmentCount);
  889. } else {
  890. if (ieee80211_is_first_frag(hdr->seq_ctrl))
  891. I802_DEBUG_INC(local->dot11FailedCount);
  892. }
  893. if (ieee80211_is_any_nullfunc(fc) &&
  894. ieee80211_has_pm(fc) &&
  895. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  896. !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
  897. local->ps_sdata && !(local->scanning)) {
  898. if (info->flags & IEEE80211_TX_STAT_ACK)
  899. local->ps_sdata->u.mgd.flags |=
  900. IEEE80211_STA_NULLFUNC_ACKED;
  901. mod_timer(&local->dynamic_ps_timer,
  902. jiffies + msecs_to_jiffies(10));
  903. }
  904. ieee80211_report_used_skb(local, skb, false, status->ack_hwtstamp);
  905. /* this was a transmitted frame, but now we want to reuse it */
  906. skb_orphan(skb);
  907. /* Need to make a copy before skb->cb gets cleared */
  908. send_to_cooked = !!(info->flags & IEEE80211_TX_CTL_INJECTED) ||
  909. !(ieee80211_is_data(fc));
  910. /*
  911. * This is a bit racy but we can avoid a lot of work
  912. * with this test...
  913. */
  914. if (!local->monitors && (!send_to_cooked || !local->cooked_mntrs)) {
  915. if (status->free_list)
  916. list_add_tail(&skb->list, status->free_list);
  917. else
  918. dev_kfree_skb(skb);
  919. return;
  920. }
  921. /* send to monitor interfaces */
  922. ieee80211_tx_monitor(local, skb, retry_count, shift,
  923. send_to_cooked, status);
  924. }
  925. void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
  926. {
  927. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  928. struct ieee80211_local *local = hw_to_local(hw);
  929. struct ieee80211_tx_status status = {
  930. .skb = skb,
  931. .info = IEEE80211_SKB_CB(skb),
  932. };
  933. struct sta_info *sta;
  934. rcu_read_lock();
  935. sta = sta_info_get_by_addrs(local, hdr->addr1, hdr->addr2);
  936. if (sta)
  937. status.sta = &sta->sta;
  938. ieee80211_tx_status_ext(hw, &status);
  939. rcu_read_unlock();
  940. }
  941. EXPORT_SYMBOL(ieee80211_tx_status);
  942. void ieee80211_tx_status_ext(struct ieee80211_hw *hw,
  943. struct ieee80211_tx_status *status)
  944. {
  945. struct ieee80211_local *local = hw_to_local(hw);
  946. struct ieee80211_tx_info *info = status->info;
  947. struct ieee80211_sta *pubsta = status->sta;
  948. struct sk_buff *skb = status->skb;
  949. struct sta_info *sta = NULL;
  950. int rates_idx, retry_count;
  951. bool acked, noack_success, ack_signal_valid;
  952. u16 tx_time_est;
  953. if (pubsta) {
  954. sta = container_of(pubsta, struct sta_info, sta);
  955. if (status->n_rates)
  956. sta->deflink.tx_stats.last_rate_info =
  957. status->rates[status->n_rates - 1].rate_idx;
  958. }
  959. if (skb && (tx_time_est =
  960. ieee80211_info_get_tx_time_est(IEEE80211_SKB_CB(skb))) > 0) {
  961. /* Do this here to avoid the expensive lookup of the sta
  962. * in ieee80211_report_used_skb().
  963. */
  964. ieee80211_sta_update_pending_airtime(local, sta,
  965. skb_get_queue_mapping(skb),
  966. tx_time_est,
  967. true);
  968. ieee80211_info_set_tx_time_est(IEEE80211_SKB_CB(skb), 0);
  969. }
  970. if (!status->info)
  971. goto free;
  972. rates_idx = ieee80211_tx_get_rates(hw, info, &retry_count);
  973. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  974. noack_success = !!(info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  975. ack_signal_valid =
  976. !!(info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID);
  977. if (pubsta) {
  978. struct ieee80211_sub_if_data *sdata = sta->sdata;
  979. if (!acked && !noack_success)
  980. sta->deflink.status_stats.retry_failed++;
  981. sta->deflink.status_stats.retry_count += retry_count;
  982. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  983. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  984. skb && !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
  985. ieee80211_sta_tx_notify(sdata, (void *) skb->data,
  986. acked, info->status.tx_time);
  987. if (acked) {
  988. sta->deflink.status_stats.last_ack = jiffies;
  989. if (sta->deflink.status_stats.lost_packets)
  990. sta->deflink.status_stats.lost_packets = 0;
  991. /* Track when last packet was ACKed */
  992. sta->deflink.status_stats.last_pkt_time = jiffies;
  993. /* Reset connection monitor */
  994. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  995. unlikely(sdata->u.mgd.probe_send_count > 0))
  996. sdata->u.mgd.probe_send_count = 0;
  997. if (ack_signal_valid) {
  998. sta->deflink.status_stats.last_ack_signal =
  999. (s8)info->status.ack_signal;
  1000. sta->deflink.status_stats.ack_signal_filled = true;
  1001. ewma_avg_signal_add(&sta->deflink.status_stats.avg_ack_signal,
  1002. -info->status.ack_signal);
  1003. }
  1004. } else if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1005. /*
  1006. * The STA is in power save mode, so assume
  1007. * that this TX packet failed because of that.
  1008. */
  1009. if (skb)
  1010. ieee80211_handle_filtered_frame(local, sta, skb);
  1011. return;
  1012. } else if (noack_success) {
  1013. /* nothing to do here, do not account as lost */
  1014. } else {
  1015. ieee80211_lost_packet(sta, info);
  1016. }
  1017. }
  1018. rate_control_tx_status(local, status);
  1019. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  1020. ieee80211s_update_metric(local, sta, status);
  1021. }
  1022. if (skb && !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP))
  1023. return __ieee80211_tx_status(hw, status, rates_idx,
  1024. retry_count);
  1025. if (acked || noack_success) {
  1026. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  1027. if (!pubsta)
  1028. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  1029. if (retry_count > 0)
  1030. I802_DEBUG_INC(local->dot11RetryCount);
  1031. if (retry_count > 1)
  1032. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  1033. } else {
  1034. I802_DEBUG_INC(local->dot11FailedCount);
  1035. }
  1036. free:
  1037. if (!skb)
  1038. return;
  1039. ieee80211_report_used_skb(local, skb, false, status->ack_hwtstamp);
  1040. if (status->free_list)
  1041. list_add_tail(&skb->list, status->free_list);
  1042. else
  1043. dev_kfree_skb(skb);
  1044. }
  1045. EXPORT_SYMBOL(ieee80211_tx_status_ext);
  1046. void ieee80211_tx_rate_update(struct ieee80211_hw *hw,
  1047. struct ieee80211_sta *pubsta,
  1048. struct ieee80211_tx_info *info)
  1049. {
  1050. struct ieee80211_local *local = hw_to_local(hw);
  1051. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1052. struct ieee80211_tx_status status = {
  1053. .info = info,
  1054. .sta = pubsta,
  1055. };
  1056. rate_control_tx_status(local, &status);
  1057. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
  1058. sta->deflink.tx_stats.last_rate = info->status.rates[0];
  1059. }
  1060. EXPORT_SYMBOL(ieee80211_tx_rate_update);
  1061. void ieee80211_tx_status_8023(struct ieee80211_hw *hw,
  1062. struct ieee80211_vif *vif,
  1063. struct sk_buff *skb)
  1064. {
  1065. struct ieee80211_sub_if_data *sdata;
  1066. struct ieee80211_tx_status status = {
  1067. .skb = skb,
  1068. .info = IEEE80211_SKB_CB(skb),
  1069. };
  1070. struct sta_info *sta;
  1071. sdata = vif_to_sdata(vif);
  1072. rcu_read_lock();
  1073. if (!ieee80211_lookup_ra_sta(sdata, skb, &sta) && !IS_ERR(sta))
  1074. status.sta = &sta->sta;
  1075. ieee80211_tx_status_ext(hw, &status);
  1076. rcu_read_unlock();
  1077. }
  1078. EXPORT_SYMBOL(ieee80211_tx_status_8023);
  1079. void ieee80211_report_low_ack(struct ieee80211_sta *pubsta, u32 num_packets)
  1080. {
  1081. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1082. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  1083. num_packets, GFP_ATOMIC);
  1084. }
  1085. EXPORT_SYMBOL(ieee80211_report_low_ack);
  1086. void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb)
  1087. {
  1088. struct ieee80211_local *local = hw_to_local(hw);
  1089. ktime_t kt = ktime_set(0, 0);
  1090. ieee80211_report_used_skb(local, skb, true, kt);
  1091. dev_kfree_skb_any(skb);
  1092. }
  1093. EXPORT_SYMBOL(ieee80211_free_txskb);
  1094. void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
  1095. struct sk_buff_head *skbs)
  1096. {
  1097. struct sk_buff *skb;
  1098. while ((skb = __skb_dequeue(skbs)))
  1099. ieee80211_free_txskb(hw, skb);
  1100. }