status.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. * Copyright 2008-2010 Johannes Berg <johannes@sipsolutions.net>
  6. * Copyright 2013-2014 Intel Mobile Communications GmbH
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/export.h>
  13. #include <linux/etherdevice.h>
  14. #include <net/mac80211.h>
  15. #include <asm/unaligned.h>
  16. #include "ieee80211_i.h"
  17. #include "rate.h"
  18. #include "mesh.h"
  19. #include "led.h"
  20. #include "wme.h"
  21. void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
  22. struct sk_buff *skb)
  23. {
  24. struct ieee80211_local *local = hw_to_local(hw);
  25. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  26. int tmp;
  27. skb->pkt_type = IEEE80211_TX_STATUS_MSG;
  28. skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
  29. &local->skb_queue : &local->skb_queue_unreliable, skb);
  30. tmp = skb_queue_len(&local->skb_queue) +
  31. skb_queue_len(&local->skb_queue_unreliable);
  32. while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
  33. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  34. ieee80211_free_txskb(hw, skb);
  35. tmp--;
  36. I802_DEBUG_INC(local->tx_status_drop);
  37. }
  38. tasklet_schedule(&local->tasklet);
  39. }
  40. EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
  41. static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
  42. struct sta_info *sta,
  43. struct sk_buff *skb)
  44. {
  45. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  46. struct ieee80211_hdr *hdr = (void *)skb->data;
  47. int ac;
  48. if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
  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->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING |
  64. IEEE80211_TX_INTFL_RETRANSMISSION;
  65. info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
  66. sta->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 = ieee802_1d_to_ac[tid & 7];
  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_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  169. sta->status_stats.last_ack = jiffies;
  170. if (ieee80211_is_data_qos(mgmt->frame_control)) {
  171. struct ieee80211_hdr *hdr = (void *) skb->data;
  172. u8 *qc = ieee80211_get_qos_ctl(hdr);
  173. u16 tid = qc[0] & 0xf;
  174. ieee80211_check_pending_bar(sta, hdr->addr1, tid);
  175. }
  176. if (ieee80211_is_action(mgmt->frame_control) &&
  177. mgmt->u.action.category == WLAN_CATEGORY_HT &&
  178. mgmt->u.action.u.ht_smps.action == WLAN_HT_ACTION_SMPS &&
  179. ieee80211_sdata_running(sdata)) {
  180. enum ieee80211_smps_mode smps_mode;
  181. switch (mgmt->u.action.u.ht_smps.smps_control) {
  182. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  183. smps_mode = IEEE80211_SMPS_DYNAMIC;
  184. break;
  185. case WLAN_HT_SMPS_CONTROL_STATIC:
  186. smps_mode = IEEE80211_SMPS_STATIC;
  187. break;
  188. case WLAN_HT_SMPS_CONTROL_DISABLED:
  189. default: /* shouldn't happen since we don't send that */
  190. smps_mode = IEEE80211_SMPS_OFF;
  191. break;
  192. }
  193. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  194. /*
  195. * This update looks racy, but isn't -- if we come
  196. * here we've definitely got a station that we're
  197. * talking to, and on a managed interface that can
  198. * only be the AP. And the only other place updating
  199. * this variable in managed mode is before association.
  200. */
  201. sdata->smps_mode = smps_mode;
  202. ieee80211_queue_work(&local->hw, &sdata->recalc_smps);
  203. } else if (sdata->vif.type == NL80211_IFTYPE_AP ||
  204. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  205. sta->known_smps_mode = smps_mode;
  206. }
  207. }
  208. }
  209. static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn)
  210. {
  211. struct tid_ampdu_tx *tid_tx;
  212. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  213. if (!tid_tx)
  214. return;
  215. tid_tx->failed_bar_ssn = ssn;
  216. tid_tx->bar_pending = true;
  217. }
  218. static int ieee80211_tx_radiotap_len(struct ieee80211_tx_info *info)
  219. {
  220. int len = sizeof(struct ieee80211_radiotap_header);
  221. /* IEEE80211_RADIOTAP_RATE rate */
  222. if (info->status.rates[0].idx >= 0 &&
  223. !(info->status.rates[0].flags & (IEEE80211_TX_RC_MCS |
  224. IEEE80211_TX_RC_VHT_MCS)))
  225. len += 2;
  226. /* IEEE80211_RADIOTAP_TX_FLAGS */
  227. len += 2;
  228. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  229. len += 1;
  230. /* IEEE80211_RADIOTAP_MCS
  231. * IEEE80211_RADIOTAP_VHT */
  232. if (info->status.rates[0].idx >= 0) {
  233. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS)
  234. len += 3;
  235. else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS)
  236. len = ALIGN(len, 2) + 12;
  237. }
  238. return len;
  239. }
  240. static void
  241. ieee80211_add_tx_radiotap_header(struct ieee80211_local *local,
  242. struct ieee80211_supported_band *sband,
  243. struct sk_buff *skb, int retry_count,
  244. int rtap_len, int shift)
  245. {
  246. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  247. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  248. struct ieee80211_radiotap_header *rthdr;
  249. unsigned char *pos;
  250. u16 txflags;
  251. rthdr = (struct ieee80211_radiotap_header *) skb_push(skb, rtap_len);
  252. memset(rthdr, 0, rtap_len);
  253. rthdr->it_len = cpu_to_le16(rtap_len);
  254. rthdr->it_present =
  255. cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
  256. (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
  257. pos = (unsigned char *)(rthdr + 1);
  258. /*
  259. * XXX: Once radiotap gets the bitmap reset thing the vendor
  260. * extensions proposal contains, we can actually report
  261. * the whole set of tries we did.
  262. */
  263. /* IEEE80211_RADIOTAP_RATE */
  264. if (info->status.rates[0].idx >= 0 &&
  265. !(info->status.rates[0].flags & (IEEE80211_TX_RC_MCS |
  266. IEEE80211_TX_RC_VHT_MCS))) {
  267. u16 rate;
  268. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  269. rate = sband->bitrates[info->status.rates[0].idx].bitrate;
  270. *pos = DIV_ROUND_UP(rate, 5 * (1 << shift));
  271. /* padding for tx flags */
  272. pos += 2;
  273. }
  274. /* IEEE80211_RADIOTAP_TX_FLAGS */
  275. txflags = 0;
  276. if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
  277. !is_multicast_ether_addr(hdr->addr1))
  278. txflags |= IEEE80211_RADIOTAP_F_TX_FAIL;
  279. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  280. txflags |= IEEE80211_RADIOTAP_F_TX_CTS;
  281. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  282. txflags |= IEEE80211_RADIOTAP_F_TX_RTS;
  283. put_unaligned_le16(txflags, pos);
  284. pos += 2;
  285. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  286. /* for now report the total retry_count */
  287. *pos = retry_count;
  288. pos++;
  289. if (info->status.rates[0].idx < 0)
  290. return;
  291. /* IEEE80211_RADIOTAP_MCS
  292. * IEEE80211_RADIOTAP_VHT */
  293. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS) {
  294. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
  295. pos[0] = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  296. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  297. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  298. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  299. pos[1] |= IEEE80211_RADIOTAP_MCS_SGI;
  300. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  301. pos[1] |= IEEE80211_RADIOTAP_MCS_BW_40;
  302. if (info->status.rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD)
  303. pos[1] |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  304. pos[2] = info->status.rates[0].idx;
  305. pos += 3;
  306. } else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
  307. u16 known = local->hw.radiotap_vht_details &
  308. (IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  309. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH);
  310. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
  311. /* required alignment from rthdr */
  312. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  313. /* u16 known - IEEE80211_RADIOTAP_VHT_KNOWN_* */
  314. put_unaligned_le16(known, pos);
  315. pos += 2;
  316. /* u8 flags - IEEE80211_RADIOTAP_VHT_FLAG_* */
  317. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  318. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  319. pos++;
  320. /* u8 bandwidth */
  321. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  322. *pos = 1;
  323. else if (info->status.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  324. *pos = 4;
  325. else if (info->status.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  326. *pos = 11;
  327. else /* IEEE80211_TX_RC_{20_MHZ_WIDTH,FIXME:DUP_DATA} */
  328. *pos = 0;
  329. pos++;
  330. /* u8 mcs_nss[4] */
  331. *pos = (ieee80211_rate_get_vht_mcs(&info->status.rates[0]) << 4) |
  332. ieee80211_rate_get_vht_nss(&info->status.rates[0]);
  333. pos += 4;
  334. /* u8 coding */
  335. pos++;
  336. /* u8 group_id */
  337. pos++;
  338. /* u16 partial_aid */
  339. pos += 2;
  340. }
  341. }
  342. /*
  343. * Handles the tx for TDLS teardown frames.
  344. * If the frame wasn't ACKed by the peer - it will be re-sent through the AP
  345. */
  346. static void ieee80211_tdls_td_tx_handle(struct ieee80211_local *local,
  347. struct ieee80211_sub_if_data *sdata,
  348. struct sk_buff *skb, u32 flags)
  349. {
  350. struct sk_buff *teardown_skb;
  351. struct sk_buff *orig_teardown_skb;
  352. bool is_teardown = false;
  353. /* Get the teardown data we need and free the lock */
  354. spin_lock(&sdata->u.mgd.teardown_lock);
  355. teardown_skb = sdata->u.mgd.teardown_skb;
  356. orig_teardown_skb = sdata->u.mgd.orig_teardown_skb;
  357. if ((skb == orig_teardown_skb) && teardown_skb) {
  358. sdata->u.mgd.teardown_skb = NULL;
  359. sdata->u.mgd.orig_teardown_skb = NULL;
  360. is_teardown = true;
  361. }
  362. spin_unlock(&sdata->u.mgd.teardown_lock);
  363. if (is_teardown) {
  364. /* This mechanism relies on being able to get ACKs */
  365. WARN_ON(!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS));
  366. /* Check if peer has ACKed */
  367. if (flags & IEEE80211_TX_STAT_ACK) {
  368. dev_kfree_skb_any(teardown_skb);
  369. } else {
  370. tdls_dbg(sdata,
  371. "TDLS Resending teardown through AP\n");
  372. ieee80211_subif_start_xmit(teardown_skb, skb->dev);
  373. }
  374. }
  375. }
  376. static struct ieee80211_sub_if_data *
  377. ieee80211_sdata_from_skb(struct ieee80211_local *local, struct sk_buff *skb)
  378. {
  379. struct ieee80211_sub_if_data *sdata;
  380. if (skb->dev) {
  381. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  382. if (!sdata->dev)
  383. continue;
  384. if (skb->dev == sdata->dev)
  385. return sdata;
  386. }
  387. return NULL;
  388. }
  389. return rcu_dereference(local->p2p_sdata);
  390. }
  391. static void ieee80211_report_ack_skb(struct ieee80211_local *local,
  392. struct ieee80211_tx_info *info,
  393. bool acked, bool dropped)
  394. {
  395. struct sk_buff *skb;
  396. unsigned long flags;
  397. spin_lock_irqsave(&local->ack_status_lock, flags);
  398. skb = idr_find(&local->ack_status_frames, info->ack_frame_id);
  399. if (skb)
  400. idr_remove(&local->ack_status_frames, info->ack_frame_id);
  401. spin_unlock_irqrestore(&local->ack_status_lock, flags);
  402. if (!skb)
  403. return;
  404. if (dropped) {
  405. dev_kfree_skb_any(skb);
  406. return;
  407. }
  408. if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) {
  409. u64 cookie = IEEE80211_SKB_CB(skb)->ack.cookie;
  410. struct ieee80211_sub_if_data *sdata;
  411. struct ieee80211_hdr *hdr = (void *)skb->data;
  412. rcu_read_lock();
  413. sdata = ieee80211_sdata_from_skb(local, skb);
  414. if (sdata) {
  415. if (ieee80211_is_nullfunc(hdr->frame_control) ||
  416. ieee80211_is_qos_nullfunc(hdr->frame_control))
  417. cfg80211_probe_status(sdata->dev, hdr->addr1,
  418. cookie, acked,
  419. GFP_ATOMIC);
  420. else
  421. cfg80211_mgmt_tx_status(&sdata->wdev, cookie,
  422. skb->data, skb->len,
  423. acked, GFP_ATOMIC);
  424. }
  425. rcu_read_unlock();
  426. dev_kfree_skb_any(skb);
  427. } else {
  428. /* consumes skb */
  429. skb_complete_wifi_ack(skb, acked);
  430. }
  431. }
  432. static void ieee80211_report_used_skb(struct ieee80211_local *local,
  433. struct sk_buff *skb, bool dropped)
  434. {
  435. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  436. struct ieee80211_hdr *hdr = (void *)skb->data;
  437. bool acked = info->flags & IEEE80211_TX_STAT_ACK;
  438. if (dropped)
  439. acked = false;
  440. if (info->flags & IEEE80211_TX_INTFL_MLME_CONN_TX) {
  441. struct ieee80211_sub_if_data *sdata;
  442. rcu_read_lock();
  443. sdata = ieee80211_sdata_from_skb(local, skb);
  444. if (!sdata) {
  445. skb->dev = NULL;
  446. } else {
  447. unsigned int hdr_size =
  448. ieee80211_hdrlen(hdr->frame_control);
  449. /* Check to see if packet is a TDLS teardown packet */
  450. if (ieee80211_is_data(hdr->frame_control) &&
  451. (ieee80211_get_tdls_action(skb, hdr_size) ==
  452. WLAN_TDLS_TEARDOWN))
  453. ieee80211_tdls_td_tx_handle(local, sdata, skb,
  454. info->flags);
  455. else
  456. ieee80211_mgd_conn_tx_status(sdata,
  457. hdr->frame_control,
  458. acked);
  459. }
  460. rcu_read_unlock();
  461. } else if (info->ack_frame_id) {
  462. ieee80211_report_ack_skb(local, info, acked, dropped);
  463. }
  464. }
  465. /*
  466. * Use a static threshold for now, best value to be determined
  467. * by testing ...
  468. * Should it depend on:
  469. * - on # of retransmissions
  470. * - current throughput (higher value for higher tpt)?
  471. */
  472. #define STA_LOST_PKT_THRESHOLD 50
  473. #define STA_LOST_TDLS_PKT_THRESHOLD 10
  474. #define STA_LOST_TDLS_PKT_TIME (10*HZ) /* 10secs since last ACK */
  475. static void ieee80211_lost_packet(struct sta_info *sta,
  476. struct ieee80211_tx_info *info)
  477. {
  478. /* If driver relies on its own algorithm for station kickout, skip
  479. * mac80211 packet loss mechanism.
  480. */
  481. if (ieee80211_hw_check(&sta->local->hw, REPORTS_LOW_ACK))
  482. return;
  483. /* This packet was aggregated but doesn't carry status info */
  484. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  485. !(info->flags & IEEE80211_TX_STAT_AMPDU))
  486. return;
  487. sta->status_stats.lost_packets++;
  488. if (!sta->sta.tdls &&
  489. sta->status_stats.lost_packets < STA_LOST_PKT_THRESHOLD)
  490. return;
  491. /*
  492. * If we're in TDLS mode, make sure that all STA_LOST_TDLS_PKT_THRESHOLD
  493. * of the last packets were lost, and that no ACK was received in the
  494. * last STA_LOST_TDLS_PKT_TIME ms, before triggering the CQM packet-loss
  495. * mechanism.
  496. */
  497. if (sta->sta.tdls &&
  498. (sta->status_stats.lost_packets < STA_LOST_TDLS_PKT_THRESHOLD ||
  499. time_before(jiffies,
  500. sta->status_stats.last_tdls_pkt_time +
  501. STA_LOST_TDLS_PKT_TIME)))
  502. return;
  503. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  504. sta->status_stats.lost_packets, GFP_ATOMIC);
  505. sta->status_stats.lost_packets = 0;
  506. }
  507. static int ieee80211_tx_get_rates(struct ieee80211_hw *hw,
  508. struct ieee80211_tx_info *info,
  509. int *retry_count)
  510. {
  511. int rates_idx = -1;
  512. int count = -1;
  513. int i;
  514. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  515. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  516. !(info->flags & IEEE80211_TX_STAT_AMPDU)) {
  517. /* just the first aggr frame carry status info */
  518. info->status.rates[i].idx = -1;
  519. info->status.rates[i].count = 0;
  520. break;
  521. } else if (info->status.rates[i].idx < 0) {
  522. break;
  523. } else if (i >= hw->max_report_rates) {
  524. /* the HW cannot have attempted that rate */
  525. info->status.rates[i].idx = -1;
  526. info->status.rates[i].count = 0;
  527. break;
  528. }
  529. count += info->status.rates[i].count;
  530. }
  531. rates_idx = i - 1;
  532. if (count < 0)
  533. count = 0;
  534. *retry_count = count;
  535. return rates_idx;
  536. }
  537. void ieee80211_tx_status_noskb(struct ieee80211_hw *hw,
  538. struct ieee80211_sta *pubsta,
  539. struct ieee80211_tx_info *info)
  540. {
  541. struct ieee80211_local *local = hw_to_local(hw);
  542. struct ieee80211_supported_band *sband;
  543. int retry_count;
  544. int rates_idx;
  545. bool acked, noack_success;
  546. rates_idx = ieee80211_tx_get_rates(hw, info, &retry_count);
  547. sband = hw->wiphy->bands[info->band];
  548. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  549. noack_success = !!(info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  550. if (pubsta) {
  551. struct sta_info *sta;
  552. sta = container_of(pubsta, struct sta_info, sta);
  553. if (!acked)
  554. sta->status_stats.retry_failed++;
  555. sta->status_stats.retry_count += retry_count;
  556. if (acked) {
  557. sta->status_stats.last_ack = jiffies;
  558. if (sta->status_stats.lost_packets)
  559. sta->status_stats.lost_packets = 0;
  560. /* Track when last TDLS packet was ACKed */
  561. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
  562. sta->status_stats.last_tdls_pkt_time = jiffies;
  563. } else {
  564. ieee80211_lost_packet(sta, info);
  565. }
  566. rate_control_tx_status_noskb(local, sband, sta, info);
  567. }
  568. if (acked || noack_success) {
  569. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  570. if (!pubsta)
  571. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  572. if (retry_count > 0)
  573. I802_DEBUG_INC(local->dot11RetryCount);
  574. if (retry_count > 1)
  575. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  576. } else {
  577. I802_DEBUG_INC(local->dot11FailedCount);
  578. }
  579. }
  580. EXPORT_SYMBOL(ieee80211_tx_status_noskb);
  581. void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
  582. struct ieee80211_supported_band *sband,
  583. int retry_count, int shift, bool send_to_cooked)
  584. {
  585. struct sk_buff *skb2;
  586. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  587. struct ieee80211_sub_if_data *sdata;
  588. struct net_device *prev_dev = NULL;
  589. int rtap_len;
  590. /* send frame to monitor interfaces now */
  591. rtap_len = ieee80211_tx_radiotap_len(info);
  592. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  593. pr_err("ieee80211_tx_status: headroom too small\n");
  594. dev_kfree_skb(skb);
  595. return;
  596. }
  597. ieee80211_add_tx_radiotap_header(local, sband, skb, retry_count,
  598. rtap_len, shift);
  599. /* XXX: is this sufficient for BPF? */
  600. skb_reset_mac_header(skb);
  601. skb->ip_summed = CHECKSUM_UNNECESSARY;
  602. skb->pkt_type = PACKET_OTHERHOST;
  603. skb->protocol = htons(ETH_P_802_2);
  604. memset(skb->cb, 0, sizeof(skb->cb));
  605. rcu_read_lock();
  606. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  607. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  608. if (!ieee80211_sdata_running(sdata))
  609. continue;
  610. if ((sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) &&
  611. !send_to_cooked)
  612. continue;
  613. if (prev_dev) {
  614. skb2 = skb_clone(skb, GFP_ATOMIC);
  615. if (skb2) {
  616. skb2->dev = prev_dev;
  617. netif_rx(skb2);
  618. }
  619. }
  620. prev_dev = sdata->dev;
  621. }
  622. }
  623. if (prev_dev) {
  624. skb->dev = prev_dev;
  625. netif_rx(skb);
  626. skb = NULL;
  627. }
  628. rcu_read_unlock();
  629. dev_kfree_skb(skb);
  630. }
  631. void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
  632. {
  633. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  634. struct ieee80211_local *local = hw_to_local(hw);
  635. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  636. __le16 fc;
  637. struct ieee80211_supported_band *sband;
  638. struct rhlist_head *tmp;
  639. struct sta_info *sta;
  640. int retry_count;
  641. int rates_idx;
  642. bool send_to_cooked;
  643. bool acked;
  644. struct ieee80211_bar *bar;
  645. int shift = 0;
  646. int tid = IEEE80211_NUM_TIDS;
  647. rates_idx = ieee80211_tx_get_rates(hw, info, &retry_count);
  648. rcu_read_lock();
  649. sband = local->hw.wiphy->bands[info->band];
  650. fc = hdr->frame_control;
  651. for_each_sta_info(local, hdr->addr1, sta, tmp) {
  652. /* skip wrong virtual interface */
  653. if (!ether_addr_equal(hdr->addr2, sta->sdata->vif.addr))
  654. continue;
  655. shift = ieee80211_vif_get_shift(&sta->sdata->vif);
  656. if (info->flags & IEEE80211_TX_STATUS_EOSP)
  657. clear_sta_flag(sta, WLAN_STA_SP);
  658. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  659. /* mesh Peer Service Period support */
  660. if (ieee80211_vif_is_mesh(&sta->sdata->vif) &&
  661. ieee80211_is_data_qos(fc))
  662. ieee80211_mpsp_trigger_process(
  663. ieee80211_get_qos_ctl(hdr), sta, true, acked);
  664. if (!acked && test_sta_flag(sta, WLAN_STA_PS_STA)) {
  665. /*
  666. * The STA is in power save mode, so assume
  667. * that this TX packet failed because of that.
  668. */
  669. ieee80211_handle_filtered_frame(local, sta, skb);
  670. rcu_read_unlock();
  671. return;
  672. }
  673. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
  674. (ieee80211_is_data(hdr->frame_control)) &&
  675. (rates_idx != -1))
  676. sta->tx_stats.last_rate =
  677. info->status.rates[rates_idx];
  678. if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
  679. (ieee80211_is_data_qos(fc))) {
  680. u16 ssn;
  681. u8 *qc;
  682. qc = ieee80211_get_qos_ctl(hdr);
  683. tid = qc[0] & 0xf;
  684. ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
  685. & IEEE80211_SCTL_SEQ);
  686. ieee80211_send_bar(&sta->sdata->vif, hdr->addr1,
  687. tid, ssn);
  688. } else if (ieee80211_is_data_qos(fc)) {
  689. u8 *qc = ieee80211_get_qos_ctl(hdr);
  690. tid = qc[0] & 0xf;
  691. }
  692. if (!acked && ieee80211_is_back_req(fc)) {
  693. u16 control;
  694. /*
  695. * BAR failed, store the last SSN and retry sending
  696. * the BAR when the next unicast transmission on the
  697. * same TID succeeds.
  698. */
  699. bar = (struct ieee80211_bar *) skb->data;
  700. control = le16_to_cpu(bar->control);
  701. if (!(control & IEEE80211_BAR_CTRL_MULTI_TID)) {
  702. u16 ssn = le16_to_cpu(bar->start_seq_num);
  703. tid = (control &
  704. IEEE80211_BAR_CTRL_TID_INFO_MASK) >>
  705. IEEE80211_BAR_CTRL_TID_INFO_SHIFT;
  706. ieee80211_set_bar_pending(sta, tid, ssn);
  707. }
  708. }
  709. if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  710. ieee80211_handle_filtered_frame(local, sta, skb);
  711. rcu_read_unlock();
  712. return;
  713. } else {
  714. if (!acked)
  715. sta->status_stats.retry_failed++;
  716. sta->status_stats.retry_count += retry_count;
  717. if (ieee80211_is_data_present(fc)) {
  718. if (!acked)
  719. sta->status_stats.msdu_failed[tid]++;
  720. sta->status_stats.msdu_retries[tid] +=
  721. retry_count;
  722. }
  723. }
  724. rate_control_tx_status(local, sband, sta, skb);
  725. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  726. ieee80211s_update_metric(local, sta, skb);
  727. if (!(info->flags & IEEE80211_TX_CTL_INJECTED) && acked)
  728. ieee80211_frame_acked(sta, skb);
  729. if ((sta->sdata->vif.type == NL80211_IFTYPE_STATION) &&
  730. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  731. ieee80211_sta_tx_notify(sta->sdata, (void *) skb->data,
  732. acked, info->status.tx_time);
  733. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  734. if (info->flags & IEEE80211_TX_STAT_ACK) {
  735. if (sta->status_stats.lost_packets)
  736. sta->status_stats.lost_packets = 0;
  737. /* Track when last TDLS packet was ACKed */
  738. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
  739. sta->status_stats.last_tdls_pkt_time =
  740. jiffies;
  741. } else {
  742. ieee80211_lost_packet(sta, info);
  743. }
  744. }
  745. }
  746. rcu_read_unlock();
  747. ieee80211_led_tx(local);
  748. /* SNMP counters
  749. * Fragments are passed to low-level drivers as separate skbs, so these
  750. * are actually fragments, not frames. Update frame counters only for
  751. * the first fragment of the frame. */
  752. if ((info->flags & IEEE80211_TX_STAT_ACK) ||
  753. (info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED)) {
  754. if (ieee80211_is_first_frag(hdr->seq_ctrl)) {
  755. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  756. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  757. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  758. if (retry_count > 0)
  759. I802_DEBUG_INC(local->dot11RetryCount);
  760. if (retry_count > 1)
  761. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  762. }
  763. /* This counter shall be incremented for an acknowledged MPDU
  764. * with an individual address in the address 1 field or an MPDU
  765. * with a multicast address in the address 1 field of type Data
  766. * or Management. */
  767. if (!is_multicast_ether_addr(hdr->addr1) ||
  768. ieee80211_is_data(fc) ||
  769. ieee80211_is_mgmt(fc))
  770. I802_DEBUG_INC(local->dot11TransmittedFragmentCount);
  771. } else {
  772. if (ieee80211_is_first_frag(hdr->seq_ctrl))
  773. I802_DEBUG_INC(local->dot11FailedCount);
  774. }
  775. if (ieee80211_is_nullfunc(fc) && ieee80211_has_pm(fc) &&
  776. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  777. !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
  778. local->ps_sdata && !(local->scanning)) {
  779. if (info->flags & IEEE80211_TX_STAT_ACK) {
  780. local->ps_sdata->u.mgd.flags |=
  781. IEEE80211_STA_NULLFUNC_ACKED;
  782. } else
  783. mod_timer(&local->dynamic_ps_timer, jiffies +
  784. msecs_to_jiffies(10));
  785. }
  786. ieee80211_report_used_skb(local, skb, false);
  787. /* this was a transmitted frame, but now we want to reuse it */
  788. skb_orphan(skb);
  789. /* Need to make a copy before skb->cb gets cleared */
  790. send_to_cooked = !!(info->flags & IEEE80211_TX_CTL_INJECTED) ||
  791. !(ieee80211_is_data(fc));
  792. /*
  793. * This is a bit racy but we can avoid a lot of work
  794. * with this test...
  795. */
  796. if (!local->monitors && (!send_to_cooked || !local->cooked_mntrs)) {
  797. dev_kfree_skb(skb);
  798. return;
  799. }
  800. /* send to monitor interfaces */
  801. ieee80211_tx_monitor(local, skb, sband, retry_count, shift, send_to_cooked);
  802. }
  803. EXPORT_SYMBOL(ieee80211_tx_status);
  804. void ieee80211_report_low_ack(struct ieee80211_sta *pubsta, u32 num_packets)
  805. {
  806. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  807. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  808. num_packets, GFP_ATOMIC);
  809. }
  810. EXPORT_SYMBOL(ieee80211_report_low_ack);
  811. void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb)
  812. {
  813. struct ieee80211_local *local = hw_to_local(hw);
  814. ieee80211_report_used_skb(local, skb, true);
  815. dev_kfree_skb_any(skb);
  816. }
  817. EXPORT_SYMBOL(ieee80211_free_txskb);
  818. void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
  819. struct sk_buff_head *skbs)
  820. {
  821. struct sk_buff *skb;
  822. while ((skb = __skb_dequeue(skbs)))
  823. ieee80211_free_txskb(hw, skb);
  824. }