status.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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_TX_CTL_AMPDU)) {
  50. ieee80211_free_txskb(&local->hw, skb);
  51. return;
  52. }
  53. /*
  54. * This skb 'survived' a round-trip through the driver, and
  55. * hopefully the driver didn't mangle it too badly. However,
  56. * we can definitely not rely on the control information
  57. * being correct. Clear it so we don't get junk there, and
  58. * indicate that it needs new processing, but must not be
  59. * modified/encrypted again.
  60. */
  61. memset(&info->control, 0, sizeof(info->control));
  62. info->control.jiffies = jiffies;
  63. info->control.vif = &sta->sdata->vif;
  64. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING |
  65. IEEE80211_TX_INTFL_RETRANSMISSION;
  66. info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
  67. sta->status_stats.filtered++;
  68. /*
  69. * Clear more-data bit on filtered frames, it might be set
  70. * but later frames might time out so it might have to be
  71. * clear again ... It's all rather unlikely (this frame
  72. * should time out first, right?) but let's not confuse
  73. * peers unnecessarily.
  74. */
  75. if (hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_MOREDATA))
  76. hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  77. if (ieee80211_is_data_qos(hdr->frame_control)) {
  78. u8 *p = ieee80211_get_qos_ctl(hdr);
  79. int tid = *p & IEEE80211_QOS_CTL_TID_MASK;
  80. /*
  81. * Clear EOSP if set, this could happen e.g.
  82. * if an absence period (us being a P2P GO)
  83. * shortens the SP.
  84. */
  85. if (*p & IEEE80211_QOS_CTL_EOSP)
  86. *p &= ~IEEE80211_QOS_CTL_EOSP;
  87. ac = ieee80211_ac_from_tid(tid);
  88. } else {
  89. ac = IEEE80211_AC_BE;
  90. }
  91. /*
  92. * Clear the TX filter mask for this STA when sending the next
  93. * packet. If the STA went to power save mode, this will happen
  94. * when it wakes up for the next time.
  95. */
  96. set_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT);
  97. ieee80211_clear_fast_xmit(sta);
  98. /*
  99. * This code races in the following way:
  100. *
  101. * (1) STA sends frame indicating it will go to sleep and does so
  102. * (2) hardware/firmware adds STA to filter list, passes frame up
  103. * (3) hardware/firmware processes TX fifo and suppresses a frame
  104. * (4) we get TX status before having processed the frame and
  105. * knowing that the STA has gone to sleep.
  106. *
  107. * This is actually quite unlikely even when both those events are
  108. * processed from interrupts coming in quickly after one another or
  109. * even at the same time because we queue both TX status events and
  110. * RX frames to be processed by a tasklet and process them in the
  111. * same order that they were received or TX status last. Hence, there
  112. * is no race as long as the frame RX is processed before the next TX
  113. * status, which drivers can ensure, see below.
  114. *
  115. * Note that this can only happen if the hardware or firmware can
  116. * actually add STAs to the filter list, if this is done by the
  117. * driver in response to set_tim() (which will only reduce the race
  118. * this whole filtering tries to solve, not completely solve it)
  119. * this situation cannot happen.
  120. *
  121. * To completely solve this race drivers need to make sure that they
  122. * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
  123. * functions and
  124. * (b) always process RX events before TX status events if ordering
  125. * can be unknown, for example with different interrupt status
  126. * bits.
  127. * (c) if PS mode transitions are manual (i.e. the flag
  128. * %IEEE80211_HW_AP_LINK_PS is set), always process PS state
  129. * changes before calling TX status events if ordering can be
  130. * unknown.
  131. */
  132. if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
  133. skb_queue_len(&sta->tx_filtered[ac]) < STA_MAX_TX_BUFFER) {
  134. skb_queue_tail(&sta->tx_filtered[ac], skb);
  135. sta_info_recalc_tim(sta);
  136. if (!timer_pending(&local->sta_cleanup))
  137. mod_timer(&local->sta_cleanup,
  138. round_jiffies(jiffies +
  139. STA_INFO_CLEANUP_INTERVAL));
  140. return;
  141. }
  142. if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
  143. !(info->flags & IEEE80211_TX_INTFL_RETRIED)) {
  144. /* Software retry the packet once */
  145. info->flags |= IEEE80211_TX_INTFL_RETRIED;
  146. ieee80211_add_pending_skb(local, skb);
  147. return;
  148. }
  149. ps_dbg_ratelimited(sta->sdata,
  150. "dropped TX filtered frame, queue_len=%d PS=%d @%lu\n",
  151. skb_queue_len(&sta->tx_filtered[ac]),
  152. !!test_sta_flag(sta, WLAN_STA_PS_STA), jiffies);
  153. ieee80211_free_txskb(&local->hw, skb);
  154. }
  155. static void ieee80211_check_pending_bar(struct sta_info *sta, u8 *addr, u8 tid)
  156. {
  157. struct tid_ampdu_tx *tid_tx;
  158. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  159. if (!tid_tx || !tid_tx->bar_pending)
  160. return;
  161. tid_tx->bar_pending = false;
  162. ieee80211_send_bar(&sta->sdata->vif, addr, tid, tid_tx->failed_bar_ssn);
  163. }
  164. static void ieee80211_frame_acked(struct sta_info *sta, struct sk_buff *skb)
  165. {
  166. struct ieee80211_mgmt *mgmt = (void *) skb->data;
  167. struct ieee80211_local *local = sta->local;
  168. struct ieee80211_sub_if_data *sdata = sta->sdata;
  169. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  170. sta->status_stats.last_ack = jiffies;
  171. if (ieee80211_is_data_qos(mgmt->frame_control)) {
  172. struct ieee80211_hdr *hdr = (void *) skb->data;
  173. u8 *qc = ieee80211_get_qos_ctl(hdr);
  174. u16 tid = qc[0] & 0xf;
  175. ieee80211_check_pending_bar(sta, hdr->addr1, tid);
  176. }
  177. if (ieee80211_is_action(mgmt->frame_control) &&
  178. !ieee80211_has_protected(mgmt->frame_control) &&
  179. mgmt->u.action.category == WLAN_CATEGORY_HT &&
  180. mgmt->u.action.u.ht_smps.action == WLAN_HT_ACTION_SMPS &&
  181. ieee80211_sdata_running(sdata)) {
  182. enum ieee80211_smps_mode smps_mode;
  183. switch (mgmt->u.action.u.ht_smps.smps_control) {
  184. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  185. smps_mode = IEEE80211_SMPS_DYNAMIC;
  186. break;
  187. case WLAN_HT_SMPS_CONTROL_STATIC:
  188. smps_mode = IEEE80211_SMPS_STATIC;
  189. break;
  190. case WLAN_HT_SMPS_CONTROL_DISABLED:
  191. default: /* shouldn't happen since we don't send that */
  192. smps_mode = IEEE80211_SMPS_OFF;
  193. break;
  194. }
  195. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  196. /*
  197. * This update looks racy, but isn't -- if we come
  198. * here we've definitely got a station that we're
  199. * talking to, and on a managed interface that can
  200. * only be the AP. And the only other place updating
  201. * this variable in managed mode is before association.
  202. */
  203. sdata->smps_mode = smps_mode;
  204. ieee80211_queue_work(&local->hw, &sdata->recalc_smps);
  205. } else if (sdata->vif.type == NL80211_IFTYPE_AP ||
  206. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  207. sta->known_smps_mode = smps_mode;
  208. }
  209. }
  210. }
  211. static void ieee80211_set_bar_pending(struct sta_info *sta, u8 tid, u16 ssn)
  212. {
  213. struct tid_ampdu_tx *tid_tx;
  214. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  215. if (!tid_tx)
  216. return;
  217. tid_tx->failed_bar_ssn = ssn;
  218. tid_tx->bar_pending = true;
  219. }
  220. static int ieee80211_tx_radiotap_len(struct ieee80211_tx_info *info)
  221. {
  222. int len = sizeof(struct ieee80211_radiotap_header);
  223. /* IEEE80211_RADIOTAP_RATE rate */
  224. if (info->status.rates[0].idx >= 0 &&
  225. !(info->status.rates[0].flags & (IEEE80211_TX_RC_MCS |
  226. IEEE80211_TX_RC_VHT_MCS)))
  227. len += 2;
  228. /* IEEE80211_RADIOTAP_TX_FLAGS */
  229. len += 2;
  230. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  231. len += 1;
  232. /* IEEE80211_RADIOTAP_MCS
  233. * IEEE80211_RADIOTAP_VHT */
  234. if (info->status.rates[0].idx >= 0) {
  235. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS)
  236. len += 3;
  237. else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS)
  238. len = ALIGN(len, 2) + 12;
  239. }
  240. return len;
  241. }
  242. static void
  243. ieee80211_add_tx_radiotap_header(struct ieee80211_local *local,
  244. struct ieee80211_supported_band *sband,
  245. struct sk_buff *skb, int retry_count,
  246. int rtap_len, int shift)
  247. {
  248. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  249. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  250. struct ieee80211_radiotap_header *rthdr;
  251. unsigned char *pos;
  252. u16 txflags;
  253. rthdr = skb_push(skb, rtap_len);
  254. memset(rthdr, 0, rtap_len);
  255. rthdr->it_len = cpu_to_le16(rtap_len);
  256. rthdr->it_present =
  257. cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
  258. (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
  259. pos = (unsigned char *)(rthdr + 1);
  260. /*
  261. * XXX: Once radiotap gets the bitmap reset thing the vendor
  262. * extensions proposal contains, we can actually report
  263. * the whole set of tries we did.
  264. */
  265. /* IEEE80211_RADIOTAP_RATE */
  266. if (info->status.rates[0].idx >= 0 &&
  267. !(info->status.rates[0].flags & (IEEE80211_TX_RC_MCS |
  268. IEEE80211_TX_RC_VHT_MCS))) {
  269. u16 rate;
  270. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  271. rate = sband->bitrates[info->status.rates[0].idx].bitrate;
  272. *pos = DIV_ROUND_UP(rate, 5 * (1 << shift));
  273. /* padding for tx flags */
  274. pos += 2;
  275. }
  276. /* IEEE80211_RADIOTAP_TX_FLAGS */
  277. txflags = 0;
  278. if (!(info->flags & IEEE80211_TX_STAT_ACK) &&
  279. !is_multicast_ether_addr(hdr->addr1))
  280. txflags |= IEEE80211_RADIOTAP_F_TX_FAIL;
  281. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  282. txflags |= IEEE80211_RADIOTAP_F_TX_CTS;
  283. if (info->status.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  284. txflags |= IEEE80211_RADIOTAP_F_TX_RTS;
  285. put_unaligned_le16(txflags, pos);
  286. pos += 2;
  287. /* IEEE80211_RADIOTAP_DATA_RETRIES */
  288. /* for now report the total retry_count */
  289. *pos = retry_count;
  290. pos++;
  291. if (info->status.rates[0].idx < 0)
  292. return;
  293. /* IEEE80211_RADIOTAP_MCS
  294. * IEEE80211_RADIOTAP_VHT */
  295. if (info->status.rates[0].flags & IEEE80211_TX_RC_MCS) {
  296. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
  297. pos[0] = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  298. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  299. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  300. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  301. pos[1] |= IEEE80211_RADIOTAP_MCS_SGI;
  302. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  303. pos[1] |= IEEE80211_RADIOTAP_MCS_BW_40;
  304. if (info->status.rates[0].flags & IEEE80211_TX_RC_GREEN_FIELD)
  305. pos[1] |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  306. pos[2] = info->status.rates[0].idx;
  307. pos += 3;
  308. } else if (info->status.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
  309. u16 known = local->hw.radiotap_vht_details &
  310. (IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  311. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH);
  312. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
  313. /* required alignment from rthdr */
  314. pos = (u8 *)rthdr + ALIGN(pos - (u8 *)rthdr, 2);
  315. /* u16 known - IEEE80211_RADIOTAP_VHT_KNOWN_* */
  316. put_unaligned_le16(known, pos);
  317. pos += 2;
  318. /* u8 flags - IEEE80211_RADIOTAP_VHT_FLAG_* */
  319. if (info->status.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
  320. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  321. pos++;
  322. /* u8 bandwidth */
  323. if (info->status.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
  324. *pos = 1;
  325. else if (info->status.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
  326. *pos = 4;
  327. else if (info->status.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
  328. *pos = 11;
  329. else /* IEEE80211_TX_RC_{20_MHZ_WIDTH,FIXME:DUP_DATA} */
  330. *pos = 0;
  331. pos++;
  332. /* u8 mcs_nss[4] */
  333. *pos = (ieee80211_rate_get_vht_mcs(&info->status.rates[0]) << 4) |
  334. ieee80211_rate_get_vht_nss(&info->status.rates[0]);
  335. pos += 4;
  336. /* u8 coding */
  337. pos++;
  338. /* u8 group_id */
  339. pos++;
  340. /* u16 partial_aid */
  341. pos += 2;
  342. }
  343. }
  344. /*
  345. * Handles the tx for TDLS teardown frames.
  346. * If the frame wasn't ACKed by the peer - it will be re-sent through the AP
  347. */
  348. static void ieee80211_tdls_td_tx_handle(struct ieee80211_local *local,
  349. struct ieee80211_sub_if_data *sdata,
  350. struct sk_buff *skb, u32 flags)
  351. {
  352. struct sk_buff *teardown_skb;
  353. struct sk_buff *orig_teardown_skb;
  354. bool is_teardown = false;
  355. /* Get the teardown data we need and free the lock */
  356. spin_lock(&sdata->u.mgd.teardown_lock);
  357. teardown_skb = sdata->u.mgd.teardown_skb;
  358. orig_teardown_skb = sdata->u.mgd.orig_teardown_skb;
  359. if ((skb == orig_teardown_skb) && teardown_skb) {
  360. sdata->u.mgd.teardown_skb = NULL;
  361. sdata->u.mgd.orig_teardown_skb = NULL;
  362. is_teardown = true;
  363. }
  364. spin_unlock(&sdata->u.mgd.teardown_lock);
  365. if (is_teardown) {
  366. /* This mechanism relies on being able to get ACKs */
  367. WARN_ON(!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS));
  368. /* Check if peer has ACKed */
  369. if (flags & IEEE80211_TX_STAT_ACK) {
  370. dev_kfree_skb_any(teardown_skb);
  371. } else {
  372. tdls_dbg(sdata,
  373. "TDLS Resending teardown through AP\n");
  374. ieee80211_subif_start_xmit(teardown_skb, skb->dev);
  375. }
  376. }
  377. }
  378. static struct ieee80211_sub_if_data *
  379. ieee80211_sdata_from_skb(struct ieee80211_local *local, struct sk_buff *skb)
  380. {
  381. struct ieee80211_sub_if_data *sdata;
  382. if (skb->dev) {
  383. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  384. if (!sdata->dev)
  385. continue;
  386. if (skb->dev == sdata->dev)
  387. return sdata;
  388. }
  389. return NULL;
  390. }
  391. return rcu_dereference(local->p2p_sdata);
  392. }
  393. static void ieee80211_report_ack_skb(struct ieee80211_local *local,
  394. struct ieee80211_tx_info *info,
  395. bool acked, bool dropped)
  396. {
  397. struct sk_buff *skb;
  398. unsigned long flags;
  399. spin_lock_irqsave(&local->ack_status_lock, flags);
  400. skb = 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. if (!dropped && skb->destructor) {
  465. skb->wifi_acked_valid = 1;
  466. skb->wifi_acked = acked;
  467. }
  468. ieee80211_led_tx(local);
  469. }
  470. /*
  471. * Use a static threshold for now, best value to be determined
  472. * by testing ...
  473. * Should it depend on:
  474. * - on # of retransmissions
  475. * - current throughput (higher value for higher tpt)?
  476. */
  477. #define STA_LOST_PKT_THRESHOLD 50
  478. #define STA_LOST_TDLS_PKT_THRESHOLD 10
  479. #define STA_LOST_TDLS_PKT_TIME (10*HZ) /* 10secs since last ACK */
  480. static void ieee80211_lost_packet(struct sta_info *sta,
  481. struct ieee80211_tx_info *info)
  482. {
  483. /* If driver relies on its own algorithm for station kickout, skip
  484. * mac80211 packet loss mechanism.
  485. */
  486. if (ieee80211_hw_check(&sta->local->hw, REPORTS_LOW_ACK))
  487. return;
  488. /* This packet was aggregated but doesn't carry status info */
  489. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  490. !(info->flags & IEEE80211_TX_STAT_AMPDU))
  491. return;
  492. sta->status_stats.lost_packets++;
  493. if (!sta->sta.tdls &&
  494. sta->status_stats.lost_packets < STA_LOST_PKT_THRESHOLD)
  495. return;
  496. /*
  497. * If we're in TDLS mode, make sure that all STA_LOST_TDLS_PKT_THRESHOLD
  498. * of the last packets were lost, and that no ACK was received in the
  499. * last STA_LOST_TDLS_PKT_TIME ms, before triggering the CQM packet-loss
  500. * mechanism.
  501. */
  502. if (sta->sta.tdls &&
  503. (sta->status_stats.lost_packets < STA_LOST_TDLS_PKT_THRESHOLD ||
  504. time_before(jiffies,
  505. sta->status_stats.last_tdls_pkt_time +
  506. STA_LOST_TDLS_PKT_TIME)))
  507. return;
  508. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  509. sta->status_stats.lost_packets, GFP_ATOMIC);
  510. sta->status_stats.lost_packets = 0;
  511. }
  512. static int ieee80211_tx_get_rates(struct ieee80211_hw *hw,
  513. struct ieee80211_tx_info *info,
  514. int *retry_count)
  515. {
  516. int rates_idx = -1;
  517. int count = -1;
  518. int i;
  519. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  520. if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
  521. !(info->flags & IEEE80211_TX_STAT_AMPDU)) {
  522. /* just the first aggr frame carry status info */
  523. info->status.rates[i].idx = -1;
  524. info->status.rates[i].count = 0;
  525. break;
  526. } else if (info->status.rates[i].idx < 0) {
  527. break;
  528. } else if (i >= hw->max_report_rates) {
  529. /* the HW cannot have attempted that rate */
  530. info->status.rates[i].idx = -1;
  531. info->status.rates[i].count = 0;
  532. break;
  533. }
  534. count += info->status.rates[i].count;
  535. }
  536. rates_idx = i - 1;
  537. if (count < 0)
  538. count = 0;
  539. *retry_count = count;
  540. return rates_idx;
  541. }
  542. void ieee80211_tx_monitor(struct ieee80211_local *local, struct sk_buff *skb,
  543. struct ieee80211_supported_band *sband,
  544. int retry_count, int shift, bool send_to_cooked)
  545. {
  546. struct sk_buff *skb2;
  547. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  548. struct ieee80211_sub_if_data *sdata;
  549. struct net_device *prev_dev = NULL;
  550. int rtap_len;
  551. /* send frame to monitor interfaces now */
  552. rtap_len = ieee80211_tx_radiotap_len(info);
  553. if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
  554. pr_err("ieee80211_tx_status: headroom too small\n");
  555. dev_kfree_skb(skb);
  556. return;
  557. }
  558. ieee80211_add_tx_radiotap_header(local, sband, skb, retry_count,
  559. rtap_len, shift);
  560. /* XXX: is this sufficient for BPF? */
  561. skb_reset_mac_header(skb);
  562. skb->ip_summed = CHECKSUM_UNNECESSARY;
  563. skb->pkt_type = PACKET_OTHERHOST;
  564. skb->protocol = htons(ETH_P_802_2);
  565. memset(skb->cb, 0, sizeof(skb->cb));
  566. rcu_read_lock();
  567. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  568. if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
  569. if (!ieee80211_sdata_running(sdata))
  570. continue;
  571. if ((sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) &&
  572. !send_to_cooked)
  573. continue;
  574. if (prev_dev) {
  575. skb2 = skb_clone(skb, GFP_ATOMIC);
  576. if (skb2) {
  577. skb2->dev = prev_dev;
  578. netif_rx(skb2);
  579. }
  580. }
  581. prev_dev = sdata->dev;
  582. }
  583. }
  584. if (prev_dev) {
  585. skb->dev = prev_dev;
  586. netif_rx(skb);
  587. skb = NULL;
  588. }
  589. rcu_read_unlock();
  590. dev_kfree_skb(skb);
  591. }
  592. static void __ieee80211_tx_status(struct ieee80211_hw *hw,
  593. struct ieee80211_tx_status *status)
  594. {
  595. struct sk_buff *skb = status->skb;
  596. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  597. struct ieee80211_local *local = hw_to_local(hw);
  598. struct ieee80211_tx_info *info = status->info;
  599. struct sta_info *sta;
  600. __le16 fc;
  601. struct ieee80211_supported_band *sband;
  602. int retry_count;
  603. int rates_idx;
  604. bool send_to_cooked;
  605. bool acked;
  606. struct ieee80211_bar *bar;
  607. int shift = 0;
  608. int tid = IEEE80211_NUM_TIDS;
  609. rates_idx = ieee80211_tx_get_rates(hw, info, &retry_count);
  610. sband = local->hw.wiphy->bands[info->band];
  611. fc = hdr->frame_control;
  612. if (status->sta) {
  613. sta = container_of(status->sta, struct sta_info, sta);
  614. shift = ieee80211_vif_get_shift(&sta->sdata->vif);
  615. if (info->flags & IEEE80211_TX_STATUS_EOSP)
  616. clear_sta_flag(sta, WLAN_STA_SP);
  617. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  618. /* mesh Peer Service Period support */
  619. if (ieee80211_vif_is_mesh(&sta->sdata->vif) &&
  620. ieee80211_is_data_qos(fc))
  621. ieee80211_mpsp_trigger_process(
  622. ieee80211_get_qos_ctl(hdr), sta, true, acked);
  623. if (!acked && test_sta_flag(sta, WLAN_STA_PS_STA)) {
  624. /*
  625. * The STA is in power save mode, so assume
  626. * that this TX packet failed because of that.
  627. */
  628. ieee80211_handle_filtered_frame(local, sta, skb);
  629. return;
  630. }
  631. if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL) &&
  632. (ieee80211_is_data(hdr->frame_control)) &&
  633. (rates_idx != -1))
  634. sta->tx_stats.last_rate =
  635. info->status.rates[rates_idx];
  636. if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
  637. (ieee80211_is_data_qos(fc))) {
  638. u16 ssn;
  639. u8 *qc;
  640. qc = ieee80211_get_qos_ctl(hdr);
  641. tid = qc[0] & 0xf;
  642. ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
  643. & IEEE80211_SCTL_SEQ);
  644. ieee80211_send_bar(&sta->sdata->vif, hdr->addr1,
  645. tid, ssn);
  646. } else if (ieee80211_is_data_qos(fc)) {
  647. u8 *qc = ieee80211_get_qos_ctl(hdr);
  648. tid = qc[0] & 0xf;
  649. }
  650. if (!acked && ieee80211_is_back_req(fc)) {
  651. u16 control;
  652. /*
  653. * BAR failed, store the last SSN and retry sending
  654. * the BAR when the next unicast transmission on the
  655. * same TID succeeds.
  656. */
  657. bar = (struct ieee80211_bar *) skb->data;
  658. control = le16_to_cpu(bar->control);
  659. if (!(control & IEEE80211_BAR_CTRL_MULTI_TID)) {
  660. u16 ssn = le16_to_cpu(bar->start_seq_num);
  661. tid = (control &
  662. IEEE80211_BAR_CTRL_TID_INFO_MASK) >>
  663. IEEE80211_BAR_CTRL_TID_INFO_SHIFT;
  664. ieee80211_set_bar_pending(sta, tid, ssn);
  665. }
  666. }
  667. if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  668. ieee80211_handle_filtered_frame(local, sta, skb);
  669. return;
  670. } else {
  671. if (!acked)
  672. sta->status_stats.retry_failed++;
  673. sta->status_stats.retry_count += retry_count;
  674. if (ieee80211_is_data_present(fc)) {
  675. if (!acked)
  676. sta->status_stats.msdu_failed[tid]++;
  677. sta->status_stats.msdu_retries[tid] +=
  678. retry_count;
  679. }
  680. }
  681. rate_control_tx_status(local, sband, status);
  682. if (ieee80211_vif_is_mesh(&sta->sdata->vif))
  683. ieee80211s_update_metric(local, sta, skb);
  684. if (!(info->flags & IEEE80211_TX_CTL_INJECTED) && acked)
  685. ieee80211_frame_acked(sta, skb);
  686. if ((sta->sdata->vif.type == NL80211_IFTYPE_STATION) &&
  687. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  688. ieee80211_sta_tx_notify(sta->sdata, (void *) skb->data,
  689. acked, info->status.tx_time);
  690. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  691. if (info->flags & IEEE80211_TX_STAT_ACK) {
  692. if (sta->status_stats.lost_packets)
  693. sta->status_stats.lost_packets = 0;
  694. /* Track when last TDLS packet was ACKed */
  695. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
  696. sta->status_stats.last_tdls_pkt_time =
  697. jiffies;
  698. } else {
  699. ieee80211_lost_packet(sta, info);
  700. }
  701. }
  702. }
  703. /* SNMP counters
  704. * Fragments are passed to low-level drivers as separate skbs, so these
  705. * are actually fragments, not frames. Update frame counters only for
  706. * the first fragment of the frame. */
  707. if ((info->flags & IEEE80211_TX_STAT_ACK) ||
  708. (info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED)) {
  709. if (ieee80211_is_first_frag(hdr->seq_ctrl)) {
  710. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  711. if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
  712. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  713. if (retry_count > 0)
  714. I802_DEBUG_INC(local->dot11RetryCount);
  715. if (retry_count > 1)
  716. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  717. }
  718. /* This counter shall be incremented for an acknowledged MPDU
  719. * with an individual address in the address 1 field or an MPDU
  720. * with a multicast address in the address 1 field of type Data
  721. * or Management. */
  722. if (!is_multicast_ether_addr(hdr->addr1) ||
  723. ieee80211_is_data(fc) ||
  724. ieee80211_is_mgmt(fc))
  725. I802_DEBUG_INC(local->dot11TransmittedFragmentCount);
  726. } else {
  727. if (ieee80211_is_first_frag(hdr->seq_ctrl))
  728. I802_DEBUG_INC(local->dot11FailedCount);
  729. }
  730. if (ieee80211_is_nullfunc(fc) && ieee80211_has_pm(fc) &&
  731. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  732. !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
  733. local->ps_sdata && !(local->scanning)) {
  734. if (info->flags & IEEE80211_TX_STAT_ACK) {
  735. local->ps_sdata->u.mgd.flags |=
  736. IEEE80211_STA_NULLFUNC_ACKED;
  737. } else
  738. mod_timer(&local->dynamic_ps_timer, jiffies +
  739. msecs_to_jiffies(10));
  740. }
  741. ieee80211_report_used_skb(local, skb, false);
  742. /* this was a transmitted frame, but now we want to reuse it */
  743. skb_orphan(skb);
  744. /* Need to make a copy before skb->cb gets cleared */
  745. send_to_cooked = !!(info->flags & IEEE80211_TX_CTL_INJECTED) ||
  746. !(ieee80211_is_data(fc));
  747. /*
  748. * This is a bit racy but we can avoid a lot of work
  749. * with this test...
  750. */
  751. if (!local->monitors && (!send_to_cooked || !local->cooked_mntrs)) {
  752. dev_kfree_skb(skb);
  753. return;
  754. }
  755. /* send to monitor interfaces */
  756. ieee80211_tx_monitor(local, skb, sband, retry_count, shift, send_to_cooked);
  757. }
  758. void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
  759. {
  760. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  761. struct ieee80211_local *local = hw_to_local(hw);
  762. struct ieee80211_tx_status status = {
  763. .skb = skb,
  764. .info = IEEE80211_SKB_CB(skb),
  765. };
  766. struct rhlist_head *tmp;
  767. struct sta_info *sta;
  768. rcu_read_lock();
  769. for_each_sta_info(local, hdr->addr1, sta, tmp) {
  770. /* skip wrong virtual interface */
  771. if (!ether_addr_equal(hdr->addr2, sta->sdata->vif.addr))
  772. continue;
  773. status.sta = &sta->sta;
  774. break;
  775. }
  776. __ieee80211_tx_status(hw, &status);
  777. rcu_read_unlock();
  778. }
  779. EXPORT_SYMBOL(ieee80211_tx_status);
  780. void ieee80211_tx_status_ext(struct ieee80211_hw *hw,
  781. struct ieee80211_tx_status *status)
  782. {
  783. struct ieee80211_local *local = hw_to_local(hw);
  784. struct ieee80211_tx_info *info = status->info;
  785. struct ieee80211_sta *pubsta = status->sta;
  786. struct ieee80211_supported_band *sband;
  787. int retry_count;
  788. bool acked, noack_success;
  789. if (status->skb)
  790. return __ieee80211_tx_status(hw, status);
  791. if (!status->sta)
  792. return;
  793. ieee80211_tx_get_rates(hw, info, &retry_count);
  794. sband = hw->wiphy->bands[info->band];
  795. acked = !!(info->flags & IEEE80211_TX_STAT_ACK);
  796. noack_success = !!(info->flags & IEEE80211_TX_STAT_NOACK_TRANSMITTED);
  797. if (pubsta) {
  798. struct sta_info *sta;
  799. sta = container_of(pubsta, struct sta_info, sta);
  800. if (!acked)
  801. sta->status_stats.retry_failed++;
  802. sta->status_stats.retry_count += retry_count;
  803. if (acked) {
  804. sta->status_stats.last_ack = jiffies;
  805. if (sta->status_stats.lost_packets)
  806. sta->status_stats.lost_packets = 0;
  807. /* Track when last TDLS packet was ACKed */
  808. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH))
  809. sta->status_stats.last_tdls_pkt_time = jiffies;
  810. } else {
  811. ieee80211_lost_packet(sta, info);
  812. }
  813. rate_control_tx_status(local, sband, status);
  814. }
  815. if (acked || noack_success) {
  816. I802_DEBUG_INC(local->dot11TransmittedFrameCount);
  817. if (!pubsta)
  818. I802_DEBUG_INC(local->dot11MulticastTransmittedFrameCount);
  819. if (retry_count > 0)
  820. I802_DEBUG_INC(local->dot11RetryCount);
  821. if (retry_count > 1)
  822. I802_DEBUG_INC(local->dot11MultipleRetryCount);
  823. } else {
  824. I802_DEBUG_INC(local->dot11FailedCount);
  825. }
  826. }
  827. EXPORT_SYMBOL(ieee80211_tx_status_ext);
  828. void ieee80211_report_low_ack(struct ieee80211_sta *pubsta, u32 num_packets)
  829. {
  830. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  831. cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
  832. num_packets, GFP_ATOMIC);
  833. }
  834. EXPORT_SYMBOL(ieee80211_report_low_ack);
  835. void ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb)
  836. {
  837. struct ieee80211_local *local = hw_to_local(hw);
  838. ieee80211_report_used_skb(local, skb, true);
  839. dev_kfree_skb_any(skb);
  840. }
  841. EXPORT_SYMBOL(ieee80211_free_txskb);
  842. void ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
  843. struct sk_buff_head *skbs)
  844. {
  845. struct sk_buff *skb;
  846. while ((skb = __skb_dequeue(skbs)))
  847. ieee80211_free_txskb(hw, skb);
  848. }