tx.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298
  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 2007 Johannes Berg <johannes@sipsolutions.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. *
  12. * Transmit and frame generation functions.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/slab.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/bitmap.h>
  19. #include <linux/rcupdate.h>
  20. #include <net/net_namespace.h>
  21. #include <net/ieee80211_radiotap.h>
  22. #include <net/cfg80211.h>
  23. #include <net/mac80211.h>
  24. #include <asm/unaligned.h>
  25. #include "ieee80211_i.h"
  26. #include "driver-ops.h"
  27. #include "led.h"
  28. #include "mesh.h"
  29. #include "wep.h"
  30. #include "wpa.h"
  31. #include "wme.h"
  32. #include "rate.h"
  33. #define IEEE80211_TX_OK 0
  34. #define IEEE80211_TX_AGAIN 1
  35. #define IEEE80211_TX_PENDING 2
  36. /* misc utils */
  37. static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
  38. int next_frag_len)
  39. {
  40. int rate, mrate, erp, dur, i;
  41. struct ieee80211_rate *txrate;
  42. struct ieee80211_local *local = tx->local;
  43. struct ieee80211_supported_band *sband;
  44. struct ieee80211_hdr *hdr;
  45. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  46. /* assume HW handles this */
  47. if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  48. return 0;
  49. /* uh huh? */
  50. if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
  51. return 0;
  52. sband = local->hw.wiphy->bands[tx->channel->band];
  53. txrate = &sband->bitrates[info->control.rates[0].idx];
  54. erp = txrate->flags & IEEE80211_RATE_ERP_G;
  55. /*
  56. * data and mgmt (except PS Poll):
  57. * - during CFP: 32768
  58. * - during contention period:
  59. * if addr1 is group address: 0
  60. * if more fragments = 0 and addr1 is individual address: time to
  61. * transmit one ACK plus SIFS
  62. * if more fragments = 1 and addr1 is individual address: time to
  63. * transmit next fragment plus 2 x ACK plus 3 x SIFS
  64. *
  65. * IEEE 802.11, 9.6:
  66. * - control response frame (CTS or ACK) shall be transmitted using the
  67. * same rate as the immediately previous frame in the frame exchange
  68. * sequence, if this rate belongs to the PHY mandatory rates, or else
  69. * at the highest possible rate belonging to the PHY rates in the
  70. * BSSBasicRateSet
  71. */
  72. hdr = (struct ieee80211_hdr *)tx->skb->data;
  73. if (ieee80211_is_ctl(hdr->frame_control)) {
  74. /* TODO: These control frames are not currently sent by
  75. * mac80211, but should they be implemented, this function
  76. * needs to be updated to support duration field calculation.
  77. *
  78. * RTS: time needed to transmit pending data/mgmt frame plus
  79. * one CTS frame plus one ACK frame plus 3 x SIFS
  80. * CTS: duration of immediately previous RTS minus time
  81. * required to transmit CTS and its SIFS
  82. * ACK: 0 if immediately previous directed data/mgmt had
  83. * more=0, with more=1 duration in ACK frame is duration
  84. * from previous frame minus time needed to transmit ACK
  85. * and its SIFS
  86. * PS Poll: BIT(15) | BIT(14) | aid
  87. */
  88. return 0;
  89. }
  90. /* data/mgmt */
  91. if (0 /* FIX: data/mgmt during CFP */)
  92. return cpu_to_le16(32768);
  93. if (group_addr) /* Group address as the destination - no ACK */
  94. return 0;
  95. /* Individual destination address:
  96. * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
  97. * CTS and ACK frames shall be transmitted using the highest rate in
  98. * basic rate set that is less than or equal to the rate of the
  99. * immediately previous frame and that is using the same modulation
  100. * (CCK or OFDM). If no basic rate set matches with these requirements,
  101. * the highest mandatory rate of the PHY that is less than or equal to
  102. * the rate of the previous frame is used.
  103. * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
  104. */
  105. rate = -1;
  106. /* use lowest available if everything fails */
  107. mrate = sband->bitrates[0].bitrate;
  108. for (i = 0; i < sband->n_bitrates; i++) {
  109. struct ieee80211_rate *r = &sband->bitrates[i];
  110. if (r->bitrate > txrate->bitrate)
  111. break;
  112. if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
  113. rate = r->bitrate;
  114. switch (sband->band) {
  115. case IEEE80211_BAND_2GHZ: {
  116. u32 flag;
  117. if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  118. flag = IEEE80211_RATE_MANDATORY_G;
  119. else
  120. flag = IEEE80211_RATE_MANDATORY_B;
  121. if (r->flags & flag)
  122. mrate = r->bitrate;
  123. break;
  124. }
  125. case IEEE80211_BAND_5GHZ:
  126. if (r->flags & IEEE80211_RATE_MANDATORY_A)
  127. mrate = r->bitrate;
  128. break;
  129. case IEEE80211_NUM_BANDS:
  130. WARN_ON(1);
  131. break;
  132. }
  133. }
  134. if (rate == -1) {
  135. /* No matching basic rate found; use highest suitable mandatory
  136. * PHY rate */
  137. rate = mrate;
  138. }
  139. /* Time needed to transmit ACK
  140. * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
  141. * to closest integer */
  142. dur = ieee80211_frame_duration(local, 10, rate, erp,
  143. tx->sdata->vif.bss_conf.use_short_preamble);
  144. if (next_frag_len) {
  145. /* Frame is fragmented: duration increases with time needed to
  146. * transmit next fragment plus ACK and 2 x SIFS. */
  147. dur *= 2; /* ACK + SIFS */
  148. /* next fragment */
  149. dur += ieee80211_frame_duration(local, next_frag_len,
  150. txrate->bitrate, erp,
  151. tx->sdata->vif.bss_conf.use_short_preamble);
  152. }
  153. return cpu_to_le16(dur);
  154. }
  155. static int inline is_ieee80211_device(struct ieee80211_local *local,
  156. struct net_device *dev)
  157. {
  158. return local == wdev_priv(dev->ieee80211_ptr);
  159. }
  160. /* tx handlers */
  161. static ieee80211_tx_result debug_noinline
  162. ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
  163. {
  164. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  165. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  166. u32 sta_flags;
  167. if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
  168. return TX_CONTINUE;
  169. if (unlikely(tx->local->sw_scanning) &&
  170. !ieee80211_is_probe_req(hdr->frame_control) &&
  171. !ieee80211_is_nullfunc(hdr->frame_control))
  172. /*
  173. * When software scanning only nullfunc frames (to notify
  174. * the sleep state to the AP) and probe requests (for the
  175. * active scan) are allowed, all other frames should not be
  176. * sent and we should not get here, but if we do
  177. * nonetheless, drop them to avoid sending them
  178. * off-channel. See the link below and
  179. * ieee80211_start_scan() for more.
  180. *
  181. * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
  182. */
  183. return TX_DROP;
  184. if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  185. return TX_CONTINUE;
  186. if (tx->flags & IEEE80211_TX_PS_BUFFERED)
  187. return TX_CONTINUE;
  188. sta_flags = tx->sta ? get_sta_flags(tx->sta) : 0;
  189. if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
  190. if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
  191. tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  192. ieee80211_is_data(hdr->frame_control))) {
  193. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  194. printk(KERN_DEBUG "%s: dropped data frame to not "
  195. "associated station %pM\n",
  196. tx->dev->name, hdr->addr1);
  197. #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
  198. I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
  199. return TX_DROP;
  200. }
  201. } else {
  202. if (unlikely(ieee80211_is_data(hdr->frame_control) &&
  203. tx->local->num_sta == 0 &&
  204. tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) {
  205. /*
  206. * No associated STAs - no need to send multicast
  207. * frames.
  208. */
  209. return TX_DROP;
  210. }
  211. return TX_CONTINUE;
  212. }
  213. return TX_CONTINUE;
  214. }
  215. /* This function is called whenever the AP is about to exceed the maximum limit
  216. * of buffered frames for power saving STAs. This situation should not really
  217. * happen often during normal operation, so dropping the oldest buffered packet
  218. * from each queue should be OK to make some room for new frames. */
  219. static void purge_old_ps_buffers(struct ieee80211_local *local)
  220. {
  221. int total = 0, purged = 0;
  222. struct sk_buff *skb;
  223. struct ieee80211_sub_if_data *sdata;
  224. struct sta_info *sta;
  225. /*
  226. * virtual interfaces are protected by RCU
  227. */
  228. rcu_read_lock();
  229. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  230. struct ieee80211_if_ap *ap;
  231. if (sdata->vif.type != NL80211_IFTYPE_AP)
  232. continue;
  233. ap = &sdata->u.ap;
  234. skb = skb_dequeue(&ap->ps_bc_buf);
  235. if (skb) {
  236. purged++;
  237. dev_kfree_skb(skb);
  238. }
  239. total += skb_queue_len(&ap->ps_bc_buf);
  240. }
  241. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  242. skb = skb_dequeue(&sta->ps_tx_buf);
  243. if (skb) {
  244. purged++;
  245. dev_kfree_skb(skb);
  246. }
  247. total += skb_queue_len(&sta->ps_tx_buf);
  248. }
  249. rcu_read_unlock();
  250. local->total_ps_buffered = total;
  251. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  252. printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
  253. wiphy_name(local->hw.wiphy), purged);
  254. #endif
  255. }
  256. static ieee80211_tx_result
  257. ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
  258. {
  259. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  260. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  261. /*
  262. * broadcast/multicast frame
  263. *
  264. * If any of the associated stations is in power save mode,
  265. * the frame is buffered to be sent after DTIM beacon frame.
  266. * This is done either by the hardware or us.
  267. */
  268. /* powersaving STAs only in AP/VLAN mode */
  269. if (!tx->sdata->bss)
  270. return TX_CONTINUE;
  271. /* no buffering for ordered frames */
  272. if (ieee80211_has_order(hdr->frame_control))
  273. return TX_CONTINUE;
  274. /* no stations in PS mode */
  275. if (!atomic_read(&tx->sdata->bss->num_sta_ps))
  276. return TX_CONTINUE;
  277. /* buffered in mac80211 */
  278. if (tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) {
  279. if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
  280. purge_old_ps_buffers(tx->local);
  281. if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >=
  282. AP_MAX_BC_BUFFER) {
  283. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  284. if (net_ratelimit()) {
  285. printk(KERN_DEBUG "%s: BC TX buffer full - "
  286. "dropping the oldest frame\n",
  287. tx->dev->name);
  288. }
  289. #endif
  290. dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
  291. } else
  292. tx->local->total_ps_buffered++;
  293. skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
  294. return TX_QUEUED;
  295. }
  296. /* buffered in hardware */
  297. info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
  298. return TX_CONTINUE;
  299. }
  300. static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
  301. struct sk_buff *skb)
  302. {
  303. if (!ieee80211_is_mgmt(fc))
  304. return 0;
  305. if (sta == NULL || !test_sta_flags(sta, WLAN_STA_MFP))
  306. return 0;
  307. if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
  308. skb->data))
  309. return 0;
  310. return 1;
  311. }
  312. static ieee80211_tx_result
  313. ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
  314. {
  315. struct sta_info *sta = tx->sta;
  316. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  317. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  318. u32 staflags;
  319. if (unlikely(!sta || ieee80211_is_probe_resp(hdr->frame_control)))
  320. return TX_CONTINUE;
  321. staflags = get_sta_flags(sta);
  322. if (unlikely((staflags & WLAN_STA_PS) &&
  323. !(staflags & WLAN_STA_PSPOLL))) {
  324. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  325. printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries "
  326. "before %d)\n",
  327. sta->sta.addr, sta->sta.aid,
  328. skb_queue_len(&sta->ps_tx_buf));
  329. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  330. if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
  331. purge_old_ps_buffers(tx->local);
  332. if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
  333. struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
  334. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  335. if (net_ratelimit()) {
  336. printk(KERN_DEBUG "%s: STA %pM TX "
  337. "buffer full - dropping oldest frame\n",
  338. tx->dev->name, sta->sta.addr);
  339. }
  340. #endif
  341. dev_kfree_skb(old);
  342. } else
  343. tx->local->total_ps_buffered++;
  344. /* Queue frame to be sent after STA sends an PS Poll frame */
  345. if (skb_queue_empty(&sta->ps_tx_buf))
  346. sta_info_set_tim_bit(sta);
  347. info->control.jiffies = jiffies;
  348. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  349. skb_queue_tail(&sta->ps_tx_buf, tx->skb);
  350. return TX_QUEUED;
  351. }
  352. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  353. else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) {
  354. printk(KERN_DEBUG "%s: STA %pM in PS mode, but pspoll "
  355. "set -> send frame\n", tx->dev->name,
  356. sta->sta.addr);
  357. }
  358. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  359. if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) {
  360. /*
  361. * The sleeping station with pending data is now snoozing.
  362. * It queried us for its buffered frames and will go back
  363. * to deep sleep once it got everything.
  364. *
  365. * inform the driver, in case the hardware does powersave
  366. * frame filtering and keeps a station blacklist on its own
  367. * (e.g: p54), so that frames can be delivered unimpeded.
  368. *
  369. * Note: It should be safe to disable the filter now.
  370. * As, it is really unlikely that we still have any pending
  371. * frame for this station in the hw's buffers/fifos left,
  372. * that is not rejected with a unsuccessful tx_status yet.
  373. */
  374. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
  375. }
  376. return TX_CONTINUE;
  377. }
  378. static ieee80211_tx_result debug_noinline
  379. ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
  380. {
  381. if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
  382. return TX_CONTINUE;
  383. if (tx->flags & IEEE80211_TX_UNICAST)
  384. return ieee80211_tx_h_unicast_ps_buf(tx);
  385. else
  386. return ieee80211_tx_h_multicast_ps_buf(tx);
  387. }
  388. static ieee80211_tx_result debug_noinline
  389. ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
  390. {
  391. struct ieee80211_key *key = NULL;
  392. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  393. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  394. if (unlikely(tx->skb->do_not_encrypt))
  395. tx->key = NULL;
  396. else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
  397. tx->key = key;
  398. else if (ieee80211_is_mgmt(hdr->frame_control) &&
  399. (key = rcu_dereference(tx->sdata->default_mgmt_key)))
  400. tx->key = key;
  401. else if ((key = rcu_dereference(tx->sdata->default_key)))
  402. tx->key = key;
  403. else if (tx->sdata->drop_unencrypted &&
  404. (tx->skb->protocol != cpu_to_be16(ETH_P_PAE)) &&
  405. !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
  406. (!ieee80211_is_robust_mgmt_frame(hdr) ||
  407. (ieee80211_is_action(hdr->frame_control) &&
  408. tx->sta && test_sta_flags(tx->sta, WLAN_STA_MFP)))) {
  409. I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
  410. return TX_DROP;
  411. } else
  412. tx->key = NULL;
  413. if (tx->key) {
  414. tx->key->tx_rx_count++;
  415. /* TODO: add threshold stuff again */
  416. switch (tx->key->conf.alg) {
  417. case ALG_WEP:
  418. if (ieee80211_is_auth(hdr->frame_control))
  419. break;
  420. case ALG_TKIP:
  421. if (!ieee80211_is_data_present(hdr->frame_control))
  422. tx->key = NULL;
  423. break;
  424. case ALG_CCMP:
  425. if (!ieee80211_is_data_present(hdr->frame_control) &&
  426. !ieee80211_use_mfp(hdr->frame_control, tx->sta,
  427. tx->skb))
  428. tx->key = NULL;
  429. break;
  430. case ALG_AES_CMAC:
  431. if (!ieee80211_is_mgmt(hdr->frame_control))
  432. tx->key = NULL;
  433. break;
  434. }
  435. }
  436. if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  437. tx->skb->do_not_encrypt = 1;
  438. return TX_CONTINUE;
  439. }
  440. static ieee80211_tx_result debug_noinline
  441. ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
  442. {
  443. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  444. struct ieee80211_hdr *hdr = (void *)tx->skb->data;
  445. struct ieee80211_supported_band *sband;
  446. struct ieee80211_rate *rate;
  447. int i, len;
  448. bool inval = false, rts = false, short_preamble = false;
  449. struct ieee80211_tx_rate_control txrc;
  450. u32 sta_flags;
  451. memset(&txrc, 0, sizeof(txrc));
  452. sband = tx->local->hw.wiphy->bands[tx->channel->band];
  453. len = min_t(int, tx->skb->len + FCS_LEN,
  454. tx->local->hw.wiphy->frag_threshold);
  455. /* set up the tx rate control struct we give the RC algo */
  456. txrc.hw = local_to_hw(tx->local);
  457. txrc.sband = sband;
  458. txrc.bss_conf = &tx->sdata->vif.bss_conf;
  459. txrc.skb = tx->skb;
  460. txrc.reported_rate.idx = -1;
  461. txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx;
  462. /* set up RTS protection if desired */
  463. if (len > tx->local->hw.wiphy->rts_threshold) {
  464. txrc.rts = rts = true;
  465. }
  466. /*
  467. * Use short preamble if the BSS can handle it, but not for
  468. * management frames unless we know the receiver can handle
  469. * that -- the management frame might be to a station that
  470. * just wants a probe response.
  471. */
  472. if (tx->sdata->vif.bss_conf.use_short_preamble &&
  473. (ieee80211_is_data(hdr->frame_control) ||
  474. (tx->sta && test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
  475. txrc.short_preamble = short_preamble = true;
  476. sta_flags = tx->sta ? get_sta_flags(tx->sta) : 0;
  477. /*
  478. * Lets not bother rate control if we're associated and cannot
  479. * talk to the sta. This should not happen.
  480. */
  481. if (WARN((tx->local->sw_scanning) &&
  482. (sta_flags & WLAN_STA_ASSOC) &&
  483. !rate_usable_index_exists(sband, &tx->sta->sta),
  484. "%s: Dropped data frame as no usable bitrate found while "
  485. "scanning and associated. Target station: "
  486. "%pM on %d GHz band\n",
  487. tx->dev->name, hdr->addr1,
  488. tx->channel->band ? 5 : 2))
  489. return TX_DROP;
  490. /*
  491. * If we're associated with the sta at this point we know we can at
  492. * least send the frame at the lowest bit rate.
  493. */
  494. rate_control_get_rate(tx->sdata, tx->sta, &txrc);
  495. if (unlikely(info->control.rates[0].idx < 0))
  496. return TX_DROP;
  497. if (txrc.reported_rate.idx < 0)
  498. txrc.reported_rate = info->control.rates[0];
  499. if (tx->sta)
  500. tx->sta->last_tx_rate = txrc.reported_rate;
  501. if (unlikely(!info->control.rates[0].count))
  502. info->control.rates[0].count = 1;
  503. if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
  504. (info->flags & IEEE80211_TX_CTL_NO_ACK)))
  505. info->control.rates[0].count = 1;
  506. if (is_multicast_ether_addr(hdr->addr1)) {
  507. /*
  508. * XXX: verify the rate is in the basic rateset
  509. */
  510. return TX_CONTINUE;
  511. }
  512. /*
  513. * set up the RTS/CTS rate as the fastest basic rate
  514. * that is not faster than the data rate
  515. *
  516. * XXX: Should this check all retry rates?
  517. */
  518. if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
  519. s8 baserate = 0;
  520. rate = &sband->bitrates[info->control.rates[0].idx];
  521. for (i = 0; i < sband->n_bitrates; i++) {
  522. /* must be a basic rate */
  523. if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
  524. continue;
  525. /* must not be faster than the data rate */
  526. if (sband->bitrates[i].bitrate > rate->bitrate)
  527. continue;
  528. /* maximum */
  529. if (sband->bitrates[baserate].bitrate <
  530. sband->bitrates[i].bitrate)
  531. baserate = i;
  532. }
  533. info->control.rts_cts_rate_idx = baserate;
  534. }
  535. for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
  536. /*
  537. * make sure there's no valid rate following
  538. * an invalid one, just in case drivers don't
  539. * take the API seriously to stop at -1.
  540. */
  541. if (inval) {
  542. info->control.rates[i].idx = -1;
  543. continue;
  544. }
  545. if (info->control.rates[i].idx < 0) {
  546. inval = true;
  547. continue;
  548. }
  549. /*
  550. * For now assume MCS is already set up correctly, this
  551. * needs to be fixed.
  552. */
  553. if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
  554. WARN_ON(info->control.rates[i].idx > 76);
  555. continue;
  556. }
  557. /* set up RTS protection if desired */
  558. if (rts)
  559. info->control.rates[i].flags |=
  560. IEEE80211_TX_RC_USE_RTS_CTS;
  561. /* RC is busted */
  562. if (WARN_ON_ONCE(info->control.rates[i].idx >=
  563. sband->n_bitrates)) {
  564. info->control.rates[i].idx = -1;
  565. continue;
  566. }
  567. rate = &sband->bitrates[info->control.rates[i].idx];
  568. /* set up short preamble */
  569. if (short_preamble &&
  570. rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
  571. info->control.rates[i].flags |=
  572. IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
  573. /* set up G protection */
  574. if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
  575. rate->flags & IEEE80211_RATE_ERP_G)
  576. info->control.rates[i].flags |=
  577. IEEE80211_TX_RC_USE_CTS_PROTECT;
  578. }
  579. return TX_CONTINUE;
  580. }
  581. static ieee80211_tx_result debug_noinline
  582. ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
  583. {
  584. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  585. if (tx->sta)
  586. info->control.sta = &tx->sta->sta;
  587. return TX_CONTINUE;
  588. }
  589. static ieee80211_tx_result debug_noinline
  590. ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
  591. {
  592. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  593. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  594. u16 *seq;
  595. u8 *qc;
  596. int tid;
  597. /*
  598. * Packet injection may want to control the sequence
  599. * number, if we have no matching interface then we
  600. * neither assign one ourselves nor ask the driver to.
  601. */
  602. if (unlikely(!info->control.vif))
  603. return TX_CONTINUE;
  604. if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
  605. return TX_CONTINUE;
  606. if (ieee80211_hdrlen(hdr->frame_control) < 24)
  607. return TX_CONTINUE;
  608. /*
  609. * Anything but QoS data that has a sequence number field
  610. * (is long enough) gets a sequence number from the global
  611. * counter.
  612. */
  613. if (!ieee80211_is_data_qos(hdr->frame_control)) {
  614. /* driver should assign sequence number */
  615. info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
  616. /* for pure STA mode without beacons, we can do it */
  617. hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
  618. tx->sdata->sequence_number += 0x10;
  619. tx->sdata->sequence_number &= IEEE80211_SCTL_SEQ;
  620. return TX_CONTINUE;
  621. }
  622. /*
  623. * This should be true for injected/management frames only, for
  624. * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
  625. * above since they are not QoS-data frames.
  626. */
  627. if (!tx->sta)
  628. return TX_CONTINUE;
  629. /* include per-STA, per-TID sequence counter */
  630. qc = ieee80211_get_qos_ctl(hdr);
  631. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  632. seq = &tx->sta->tid_seq[tid];
  633. hdr->seq_ctrl = cpu_to_le16(*seq);
  634. /* Increase the sequence number. */
  635. *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
  636. return TX_CONTINUE;
  637. }
  638. static int ieee80211_fragment(struct ieee80211_local *local,
  639. struct sk_buff *skb, int hdrlen,
  640. int frag_threshold)
  641. {
  642. struct sk_buff *tail = skb, *tmp;
  643. int per_fragm = frag_threshold - hdrlen - FCS_LEN;
  644. int pos = hdrlen + per_fragm;
  645. int rem = skb->len - hdrlen - per_fragm;
  646. if (WARN_ON(rem < 0))
  647. return -EINVAL;
  648. while (rem) {
  649. int fraglen = per_fragm;
  650. if (fraglen > rem)
  651. fraglen = rem;
  652. rem -= fraglen;
  653. tmp = dev_alloc_skb(local->tx_headroom +
  654. frag_threshold +
  655. IEEE80211_ENCRYPT_HEADROOM +
  656. IEEE80211_ENCRYPT_TAILROOM);
  657. if (!tmp)
  658. return -ENOMEM;
  659. tail->next = tmp;
  660. tail = tmp;
  661. skb_reserve(tmp, local->tx_headroom +
  662. IEEE80211_ENCRYPT_HEADROOM);
  663. /* copy control information */
  664. memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
  665. skb_copy_queue_mapping(tmp, skb);
  666. tmp->priority = skb->priority;
  667. tmp->do_not_encrypt = skb->do_not_encrypt;
  668. tmp->dev = skb->dev;
  669. tmp->iif = skb->iif;
  670. /* copy header and data */
  671. memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
  672. memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen);
  673. pos += fraglen;
  674. }
  675. skb->len = hdrlen + per_fragm;
  676. return 0;
  677. }
  678. static ieee80211_tx_result debug_noinline
  679. ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
  680. {
  681. struct sk_buff *skb = tx->skb;
  682. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  683. struct ieee80211_hdr *hdr = (void *)skb->data;
  684. int frag_threshold = tx->local->hw.wiphy->frag_threshold;
  685. int hdrlen;
  686. int fragnum;
  687. if (!(tx->flags & IEEE80211_TX_FRAGMENTED))
  688. return TX_CONTINUE;
  689. /*
  690. * Warn when submitting a fragmented A-MPDU frame and drop it.
  691. * This scenario is handled in __ieee80211_tx_prepare but extra
  692. * caution taken here as fragmented ampdu may cause Tx stop.
  693. */
  694. if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
  695. return TX_DROP;
  696. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  697. /* internal error, why is TX_FRAGMENTED set? */
  698. if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
  699. return TX_DROP;
  700. /*
  701. * Now fragment the frame. This will allocate all the fragments and
  702. * chain them (using skb as the first fragment) to skb->next.
  703. * During transmission, we will remove the successfully transmitted
  704. * fragments from this list. When the low-level driver rejects one
  705. * of the fragments then we will simply pretend to accept the skb
  706. * but store it away as pending.
  707. */
  708. if (ieee80211_fragment(tx->local, skb, hdrlen, frag_threshold))
  709. return TX_DROP;
  710. /* update duration/seq/flags of fragments */
  711. fragnum = 0;
  712. do {
  713. int next_len;
  714. const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
  715. hdr = (void *)skb->data;
  716. info = IEEE80211_SKB_CB(skb);
  717. if (skb->next) {
  718. hdr->frame_control |= morefrags;
  719. next_len = skb->next->len;
  720. /*
  721. * No multi-rate retries for fragmented frames, that
  722. * would completely throw off the NAV at other STAs.
  723. */
  724. info->control.rates[1].idx = -1;
  725. info->control.rates[2].idx = -1;
  726. info->control.rates[3].idx = -1;
  727. info->control.rates[4].idx = -1;
  728. BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
  729. info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
  730. } else {
  731. hdr->frame_control &= ~morefrags;
  732. next_len = 0;
  733. }
  734. hdr->duration_id = ieee80211_duration(tx, 0, next_len);
  735. hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
  736. fragnum++;
  737. } while ((skb = skb->next));
  738. return TX_CONTINUE;
  739. }
  740. static ieee80211_tx_result debug_noinline
  741. ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
  742. {
  743. if (!tx->key)
  744. return TX_CONTINUE;
  745. switch (tx->key->conf.alg) {
  746. case ALG_WEP:
  747. return ieee80211_crypto_wep_encrypt(tx);
  748. case ALG_TKIP:
  749. return ieee80211_crypto_tkip_encrypt(tx);
  750. case ALG_CCMP:
  751. return ieee80211_crypto_ccmp_encrypt(tx);
  752. case ALG_AES_CMAC:
  753. return ieee80211_crypto_aes_cmac_encrypt(tx);
  754. }
  755. /* not reached */
  756. WARN_ON(1);
  757. return TX_DROP;
  758. }
  759. static ieee80211_tx_result debug_noinline
  760. ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
  761. {
  762. struct sk_buff *skb = tx->skb;
  763. struct ieee80211_hdr *hdr;
  764. int next_len;
  765. bool group_addr;
  766. do {
  767. hdr = (void *) skb->data;
  768. if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
  769. break; /* must not overwrite AID */
  770. next_len = skb->next ? skb->next->len : 0;
  771. group_addr = is_multicast_ether_addr(hdr->addr1);
  772. hdr->duration_id =
  773. ieee80211_duration(tx, group_addr, next_len);
  774. } while ((skb = skb->next));
  775. return TX_CONTINUE;
  776. }
  777. static ieee80211_tx_result debug_noinline
  778. ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
  779. {
  780. struct sk_buff *skb = tx->skb;
  781. if (!tx->sta)
  782. return TX_CONTINUE;
  783. tx->sta->tx_packets++;
  784. do {
  785. tx->sta->tx_fragments++;
  786. tx->sta->tx_bytes += skb->len;
  787. } while ((skb = skb->next));
  788. return TX_CONTINUE;
  789. }
  790. /* actual transmit path */
  791. /*
  792. * deal with packet injection down monitor interface
  793. * with Radiotap Header -- only called for monitor mode interface
  794. */
  795. static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
  796. struct sk_buff *skb)
  797. {
  798. /*
  799. * this is the moment to interpret and discard the radiotap header that
  800. * must be at the start of the packet injected in Monitor mode
  801. *
  802. * Need to take some care with endian-ness since radiotap
  803. * args are little-endian
  804. */
  805. struct ieee80211_radiotap_iterator iterator;
  806. struct ieee80211_radiotap_header *rthdr =
  807. (struct ieee80211_radiotap_header *) skb->data;
  808. struct ieee80211_supported_band *sband;
  809. int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
  810. sband = tx->local->hw.wiphy->bands[tx->channel->band];
  811. skb->do_not_encrypt = 1;
  812. tx->flags &= ~IEEE80211_TX_FRAGMENTED;
  813. /*
  814. * for every radiotap entry that is present
  815. * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
  816. * entries present, or -EINVAL on error)
  817. */
  818. while (!ret) {
  819. ret = ieee80211_radiotap_iterator_next(&iterator);
  820. if (ret)
  821. continue;
  822. /* see if this argument is something we can use */
  823. switch (iterator.this_arg_index) {
  824. /*
  825. * You must take care when dereferencing iterator.this_arg
  826. * for multibyte types... the pointer is not aligned. Use
  827. * get_unaligned((type *)iterator.this_arg) to dereference
  828. * iterator.this_arg for type "type" safely on all arches.
  829. */
  830. case IEEE80211_RADIOTAP_FLAGS:
  831. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
  832. /*
  833. * this indicates that the skb we have been
  834. * handed has the 32-bit FCS CRC at the end...
  835. * we should react to that by snipping it off
  836. * because it will be recomputed and added
  837. * on transmission
  838. */
  839. if (skb->len < (iterator.max_length + FCS_LEN))
  840. return false;
  841. skb_trim(skb, skb->len - FCS_LEN);
  842. }
  843. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
  844. tx->skb->do_not_encrypt = 0;
  845. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
  846. tx->flags |= IEEE80211_TX_FRAGMENTED;
  847. break;
  848. /*
  849. * Please update the file
  850. * Documentation/networking/mac80211-injection.txt
  851. * when parsing new fields here.
  852. */
  853. default:
  854. break;
  855. }
  856. }
  857. if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
  858. return false;
  859. /*
  860. * remove the radiotap header
  861. * iterator->max_length was sanity-checked against
  862. * skb->len by iterator init
  863. */
  864. skb_pull(skb, iterator.max_length);
  865. return true;
  866. }
  867. /*
  868. * initialises @tx
  869. */
  870. static ieee80211_tx_result
  871. __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
  872. struct sk_buff *skb,
  873. struct net_device *dev)
  874. {
  875. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  876. struct ieee80211_hdr *hdr;
  877. struct ieee80211_sub_if_data *sdata;
  878. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  879. int hdrlen, tid;
  880. u8 *qc, *state;
  881. bool queued = false;
  882. memset(tx, 0, sizeof(*tx));
  883. tx->skb = skb;
  884. tx->dev = dev; /* use original interface */
  885. tx->local = local;
  886. tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  887. tx->channel = local->hw.conf.channel;
  888. /*
  889. * Set this flag (used below to indicate "automatic fragmentation"),
  890. * it will be cleared/left by radiotap as desired.
  891. */
  892. tx->flags |= IEEE80211_TX_FRAGMENTED;
  893. /* process and remove the injection radiotap header */
  894. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  895. if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) {
  896. if (!__ieee80211_parse_tx_radiotap(tx, skb))
  897. return TX_DROP;
  898. /*
  899. * __ieee80211_parse_tx_radiotap has now removed
  900. * the radiotap header that was present and pre-filled
  901. * 'tx' with tx control information.
  902. */
  903. }
  904. /*
  905. * If this flag is set to true anywhere, and we get here,
  906. * we are doing the needed processing, so remove the flag
  907. * now.
  908. */
  909. info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  910. hdr = (struct ieee80211_hdr *) skb->data;
  911. tx->sta = sta_info_get(local, hdr->addr1);
  912. if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
  913. (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)) {
  914. unsigned long flags;
  915. struct tid_ampdu_tx *tid_tx;
  916. qc = ieee80211_get_qos_ctl(hdr);
  917. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  918. spin_lock_irqsave(&tx->sta->lock, flags);
  919. /*
  920. * XXX: This spinlock could be fairly expensive, but see the
  921. * comment in agg-tx.c:ieee80211_agg_tx_operational().
  922. * One way to solve this would be to do something RCU-like
  923. * for managing the tid_tx struct and using atomic bitops
  924. * for the actual state -- by introducing an actual
  925. * 'operational' bit that would be possible. It would
  926. * require changing ieee80211_agg_tx_operational() to
  927. * set that bit, and changing the way tid_tx is managed
  928. * everywhere, including races between that bit and
  929. * tid_tx going away (tid_tx being added can be easily
  930. * committed to memory before the 'operational' bit).
  931. */
  932. tid_tx = tx->sta->ampdu_mlme.tid_tx[tid];
  933. state = &tx->sta->ampdu_mlme.tid_state_tx[tid];
  934. if (*state == HT_AGG_STATE_OPERATIONAL) {
  935. info->flags |= IEEE80211_TX_CTL_AMPDU;
  936. } else if (*state != HT_AGG_STATE_IDLE) {
  937. /* in progress */
  938. queued = true;
  939. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  940. __skb_queue_tail(&tid_tx->pending, skb);
  941. }
  942. spin_unlock_irqrestore(&tx->sta->lock, flags);
  943. if (unlikely(queued))
  944. return TX_QUEUED;
  945. }
  946. if (is_multicast_ether_addr(hdr->addr1)) {
  947. tx->flags &= ~IEEE80211_TX_UNICAST;
  948. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  949. } else {
  950. tx->flags |= IEEE80211_TX_UNICAST;
  951. if (unlikely(local->wifi_wme_noack_test))
  952. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  953. else
  954. info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
  955. }
  956. if (tx->flags & IEEE80211_TX_FRAGMENTED) {
  957. if ((tx->flags & IEEE80211_TX_UNICAST) &&
  958. skb->len + FCS_LEN > local->hw.wiphy->frag_threshold &&
  959. !(info->flags & IEEE80211_TX_CTL_AMPDU))
  960. tx->flags |= IEEE80211_TX_FRAGMENTED;
  961. else
  962. tx->flags &= ~IEEE80211_TX_FRAGMENTED;
  963. }
  964. if (!tx->sta)
  965. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
  966. else if (test_and_clear_sta_flags(tx->sta, WLAN_STA_CLEAR_PS_FILT))
  967. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
  968. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  969. if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
  970. u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
  971. tx->ethertype = (pos[0] << 8) | pos[1];
  972. }
  973. info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
  974. return TX_CONTINUE;
  975. }
  976. /*
  977. * NB: @tx is uninitialised when passed in here
  978. */
  979. static int ieee80211_tx_prepare(struct ieee80211_local *local,
  980. struct ieee80211_tx_data *tx,
  981. struct sk_buff *skb)
  982. {
  983. struct net_device *dev;
  984. dev = dev_get_by_index(&init_net, skb->iif);
  985. if (unlikely(dev && !is_ieee80211_device(local, dev))) {
  986. dev_put(dev);
  987. dev = NULL;
  988. }
  989. if (unlikely(!dev))
  990. return -ENODEV;
  991. /*
  992. * initialises tx with control
  993. *
  994. * return value is safe to ignore here because this function
  995. * can only be invoked for multicast frames
  996. *
  997. * XXX: clean up
  998. */
  999. __ieee80211_tx_prepare(tx, skb, dev);
  1000. dev_put(dev);
  1001. return 0;
  1002. }
  1003. static int __ieee80211_tx(struct ieee80211_local *local,
  1004. struct sk_buff **skbp,
  1005. struct sta_info *sta)
  1006. {
  1007. struct sk_buff *skb = *skbp, *next;
  1008. struct ieee80211_tx_info *info;
  1009. int ret, len;
  1010. bool fragm = false;
  1011. local->mdev->trans_start = jiffies;
  1012. while (skb) {
  1013. if (ieee80211_queue_stopped(&local->hw,
  1014. skb_get_queue_mapping(skb)))
  1015. return IEEE80211_TX_PENDING;
  1016. info = IEEE80211_SKB_CB(skb);
  1017. if (fragm)
  1018. info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
  1019. IEEE80211_TX_CTL_FIRST_FRAGMENT);
  1020. next = skb->next;
  1021. len = skb->len;
  1022. ret = drv_tx(local, skb);
  1023. if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) {
  1024. dev_kfree_skb(skb);
  1025. ret = NETDEV_TX_OK;
  1026. }
  1027. if (ret != NETDEV_TX_OK)
  1028. return IEEE80211_TX_AGAIN;
  1029. *skbp = skb = next;
  1030. ieee80211_led_tx(local, 1);
  1031. fragm = true;
  1032. }
  1033. return IEEE80211_TX_OK;
  1034. }
  1035. /*
  1036. * Invoke TX handlers, return 0 on success and non-zero if the
  1037. * frame was dropped or queued.
  1038. */
  1039. static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
  1040. {
  1041. struct sk_buff *skb = tx->skb;
  1042. ieee80211_tx_result res = TX_DROP;
  1043. #define CALL_TXH(txh) \
  1044. res = txh(tx); \
  1045. if (res != TX_CONTINUE) \
  1046. goto txh_done;
  1047. CALL_TXH(ieee80211_tx_h_check_assoc)
  1048. CALL_TXH(ieee80211_tx_h_ps_buf)
  1049. CALL_TXH(ieee80211_tx_h_select_key)
  1050. CALL_TXH(ieee80211_tx_h_michael_mic_add)
  1051. CALL_TXH(ieee80211_tx_h_rate_ctrl)
  1052. CALL_TXH(ieee80211_tx_h_misc)
  1053. CALL_TXH(ieee80211_tx_h_sequence)
  1054. CALL_TXH(ieee80211_tx_h_fragment)
  1055. /* handlers after fragment must be aware of tx info fragmentation! */
  1056. CALL_TXH(ieee80211_tx_h_encrypt)
  1057. CALL_TXH(ieee80211_tx_h_calculate_duration)
  1058. CALL_TXH(ieee80211_tx_h_stats)
  1059. #undef CALL_TXH
  1060. txh_done:
  1061. if (unlikely(res == TX_DROP)) {
  1062. I802_DEBUG_INC(tx->local->tx_handlers_drop);
  1063. while (skb) {
  1064. struct sk_buff *next;
  1065. next = skb->next;
  1066. dev_kfree_skb(skb);
  1067. skb = next;
  1068. }
  1069. return -1;
  1070. } else if (unlikely(res == TX_QUEUED)) {
  1071. I802_DEBUG_INC(tx->local->tx_handlers_queued);
  1072. return -1;
  1073. }
  1074. return 0;
  1075. }
  1076. static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
  1077. bool txpending)
  1078. {
  1079. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1080. struct ieee80211_tx_data tx;
  1081. ieee80211_tx_result res_prepare;
  1082. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1083. struct sk_buff *next;
  1084. unsigned long flags;
  1085. int ret, retries;
  1086. u16 queue;
  1087. queue = skb_get_queue_mapping(skb);
  1088. WARN_ON(!txpending && !skb_queue_empty(&local->pending[queue]));
  1089. if (unlikely(skb->len < 10)) {
  1090. dev_kfree_skb(skb);
  1091. return;
  1092. }
  1093. rcu_read_lock();
  1094. /* initialises tx */
  1095. res_prepare = __ieee80211_tx_prepare(&tx, skb, dev);
  1096. if (unlikely(res_prepare == TX_DROP)) {
  1097. dev_kfree_skb(skb);
  1098. rcu_read_unlock();
  1099. return;
  1100. } else if (unlikely(res_prepare == TX_QUEUED)) {
  1101. rcu_read_unlock();
  1102. return;
  1103. }
  1104. tx.channel = local->hw.conf.channel;
  1105. info->band = tx.channel->band;
  1106. if (invoke_tx_handlers(&tx))
  1107. goto out;
  1108. retries = 0;
  1109. retry:
  1110. ret = __ieee80211_tx(local, &tx.skb, tx.sta);
  1111. switch (ret) {
  1112. case IEEE80211_TX_OK:
  1113. break;
  1114. case IEEE80211_TX_AGAIN:
  1115. /*
  1116. * Since there are no fragmented frames on A-MPDU
  1117. * queues, there's no reason for a driver to reject
  1118. * a frame there, warn and drop it.
  1119. */
  1120. if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
  1121. goto drop;
  1122. /* fall through */
  1123. case IEEE80211_TX_PENDING:
  1124. skb = tx.skb;
  1125. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  1126. if (__netif_subqueue_stopped(local->mdev, queue)) {
  1127. do {
  1128. next = skb->next;
  1129. skb->next = NULL;
  1130. if (unlikely(txpending))
  1131. skb_queue_head(&local->pending[queue],
  1132. skb);
  1133. else
  1134. skb_queue_tail(&local->pending[queue],
  1135. skb);
  1136. } while ((skb = next));
  1137. /*
  1138. * Make sure nobody will enable the queue on us
  1139. * (without going through the tasklet) nor disable the
  1140. * netdev queue underneath the pending handling code.
  1141. */
  1142. __set_bit(IEEE80211_QUEUE_STOP_REASON_PENDING,
  1143. &local->queue_stop_reasons[queue]);
  1144. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  1145. flags);
  1146. } else {
  1147. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  1148. flags);
  1149. retries++;
  1150. if (WARN(retries > 10, "tx refused but queue active"))
  1151. goto drop;
  1152. goto retry;
  1153. }
  1154. }
  1155. out:
  1156. rcu_read_unlock();
  1157. return;
  1158. drop:
  1159. rcu_read_unlock();
  1160. skb = tx.skb;
  1161. while (skb) {
  1162. next = skb->next;
  1163. dev_kfree_skb(skb);
  1164. skb = next;
  1165. }
  1166. }
  1167. /* device xmit handlers */
  1168. static int ieee80211_skb_resize(struct ieee80211_local *local,
  1169. struct sk_buff *skb,
  1170. int head_need, bool may_encrypt)
  1171. {
  1172. int tail_need = 0;
  1173. /*
  1174. * This could be optimised, devices that do full hardware
  1175. * crypto (including TKIP MMIC) need no tailroom... But we
  1176. * have no drivers for such devices currently.
  1177. */
  1178. if (may_encrypt) {
  1179. tail_need = IEEE80211_ENCRYPT_TAILROOM;
  1180. tail_need -= skb_tailroom(skb);
  1181. tail_need = max_t(int, tail_need, 0);
  1182. }
  1183. if (head_need || tail_need) {
  1184. /* Sorry. Can't account for this any more */
  1185. skb_orphan(skb);
  1186. }
  1187. if (skb_header_cloned(skb))
  1188. I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
  1189. else
  1190. I802_DEBUG_INC(local->tx_expand_skb_head);
  1191. if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
  1192. printk(KERN_DEBUG "%s: failed to reallocate TX buffer\n",
  1193. wiphy_name(local->hw.wiphy));
  1194. return -ENOMEM;
  1195. }
  1196. /* update truesize too */
  1197. skb->truesize += head_need + tail_need;
  1198. return 0;
  1199. }
  1200. int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1201. {
  1202. struct ieee80211_master_priv *mpriv = netdev_priv(dev);
  1203. struct ieee80211_local *local = mpriv->local;
  1204. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1205. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1206. struct net_device *odev = NULL;
  1207. struct ieee80211_sub_if_data *osdata;
  1208. int headroom;
  1209. bool may_encrypt;
  1210. enum {
  1211. NOT_MONITOR,
  1212. FOUND_SDATA,
  1213. UNKNOWN_ADDRESS,
  1214. } monitor_iface = NOT_MONITOR;
  1215. if (skb->iif)
  1216. odev = dev_get_by_index(&init_net, skb->iif);
  1217. if (unlikely(odev && !is_ieee80211_device(local, odev))) {
  1218. dev_put(odev);
  1219. odev = NULL;
  1220. }
  1221. if (unlikely(!odev)) {
  1222. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1223. printk(KERN_DEBUG "%s: Discarded packet with nonexistent "
  1224. "originating device\n", dev->name);
  1225. #endif
  1226. dev_kfree_skb(skb);
  1227. return NETDEV_TX_OK;
  1228. }
  1229. if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
  1230. local->hw.conf.dynamic_ps_timeout > 0 &&
  1231. !local->sw_scanning && !local->hw_scanning && local->ps_sdata) {
  1232. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1233. ieee80211_stop_queues_by_reason(&local->hw,
  1234. IEEE80211_QUEUE_STOP_REASON_PS);
  1235. queue_work(local->hw.workqueue,
  1236. &local->dynamic_ps_disable_work);
  1237. }
  1238. mod_timer(&local->dynamic_ps_timer, jiffies +
  1239. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  1240. }
  1241. memset(info, 0, sizeof(*info));
  1242. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  1243. osdata = IEEE80211_DEV_TO_SUB_IF(odev);
  1244. if (ieee80211_vif_is_mesh(&osdata->vif) &&
  1245. ieee80211_is_data(hdr->frame_control)) {
  1246. if (is_multicast_ether_addr(hdr->addr3))
  1247. memcpy(hdr->addr1, hdr->addr3, ETH_ALEN);
  1248. else
  1249. if (mesh_nexthop_lookup(skb, osdata)) {
  1250. dev_put(odev);
  1251. return NETDEV_TX_OK;
  1252. }
  1253. if (memcmp(odev->dev_addr, hdr->addr4, ETH_ALEN) != 0)
  1254. IEEE80211_IFSTA_MESH_CTR_INC(&osdata->u.mesh,
  1255. fwded_frames);
  1256. } else if (unlikely(osdata->vif.type == NL80211_IFTYPE_MONITOR)) {
  1257. struct ieee80211_sub_if_data *sdata;
  1258. int hdrlen;
  1259. u16 len_rthdr;
  1260. info->flags |= IEEE80211_TX_CTL_INJECTED;
  1261. monitor_iface = UNKNOWN_ADDRESS;
  1262. len_rthdr = ieee80211_get_radiotap_len(skb->data);
  1263. hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
  1264. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1265. /* check the header is complete in the frame */
  1266. if (likely(skb->len >= len_rthdr + hdrlen)) {
  1267. /*
  1268. * We process outgoing injected frames that have a
  1269. * local address we handle as though they are our
  1270. * own frames.
  1271. * This code here isn't entirely correct, the local
  1272. * MAC address is not necessarily enough to find
  1273. * the interface to use; for that proper VLAN/WDS
  1274. * support we will need a different mechanism.
  1275. */
  1276. rcu_read_lock();
  1277. list_for_each_entry_rcu(sdata, &local->interfaces,
  1278. list) {
  1279. if (!netif_running(sdata->dev))
  1280. continue;
  1281. if (sdata->vif.type != NL80211_IFTYPE_AP)
  1282. continue;
  1283. if (compare_ether_addr(sdata->dev->dev_addr,
  1284. hdr->addr2)) {
  1285. dev_hold(sdata->dev);
  1286. dev_put(odev);
  1287. osdata = sdata;
  1288. odev = osdata->dev;
  1289. skb->iif = sdata->dev->ifindex;
  1290. monitor_iface = FOUND_SDATA;
  1291. break;
  1292. }
  1293. }
  1294. rcu_read_unlock();
  1295. }
  1296. }
  1297. may_encrypt = !skb->do_not_encrypt;
  1298. headroom = osdata->local->tx_headroom;
  1299. if (may_encrypt)
  1300. headroom += IEEE80211_ENCRYPT_HEADROOM;
  1301. headroom -= skb_headroom(skb);
  1302. headroom = max_t(int, 0, headroom);
  1303. if (ieee80211_skb_resize(osdata->local, skb, headroom, may_encrypt)) {
  1304. dev_kfree_skb(skb);
  1305. dev_put(odev);
  1306. return NETDEV_TX_OK;
  1307. }
  1308. if (osdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1309. osdata = container_of(osdata->bss,
  1310. struct ieee80211_sub_if_data,
  1311. u.ap);
  1312. if (likely(monitor_iface != UNKNOWN_ADDRESS))
  1313. info->control.vif = &osdata->vif;
  1314. ieee80211_tx(odev, skb, false);
  1315. dev_put(odev);
  1316. return NETDEV_TX_OK;
  1317. }
  1318. int ieee80211_monitor_start_xmit(struct sk_buff *skb,
  1319. struct net_device *dev)
  1320. {
  1321. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1322. struct ieee80211_channel *chan = local->hw.conf.channel;
  1323. struct ieee80211_radiotap_header *prthdr =
  1324. (struct ieee80211_radiotap_header *)skb->data;
  1325. u16 len_rthdr;
  1326. /*
  1327. * Frame injection is not allowed if beaconing is not allowed
  1328. * or if we need radar detection. Beaconing is usually not allowed when
  1329. * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
  1330. * Passive scan is also used in world regulatory domains where
  1331. * your country is not known and as such it should be treated as
  1332. * NO TX unless the channel is explicitly allowed in which case
  1333. * your current regulatory domain would not have the passive scan
  1334. * flag.
  1335. *
  1336. * Since AP mode uses monitor interfaces to inject/TX management
  1337. * frames we can make AP mode the exception to this rule once it
  1338. * supports radar detection as its implementation can deal with
  1339. * radar detection by itself. We can do that later by adding a
  1340. * monitor flag interfaces used for AP support.
  1341. */
  1342. if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
  1343. IEEE80211_CHAN_PASSIVE_SCAN)))
  1344. goto fail;
  1345. /* check for not even having the fixed radiotap header part */
  1346. if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
  1347. goto fail; /* too short to be possibly valid */
  1348. /* is it a header version we can trust to find length from? */
  1349. if (unlikely(prthdr->it_version))
  1350. goto fail; /* only version 0 is supported */
  1351. /* then there must be a radiotap header with a length we can use */
  1352. len_rthdr = ieee80211_get_radiotap_len(skb->data);
  1353. /* does the skb contain enough to deliver on the alleged length? */
  1354. if (unlikely(skb->len < len_rthdr))
  1355. goto fail; /* skb too short for claimed rt header extent */
  1356. skb->dev = local->mdev;
  1357. /* needed because we set skb device to master */
  1358. skb->iif = dev->ifindex;
  1359. /* sometimes we do encrypt injected frames, will be fixed
  1360. * up in radiotap parser if not wanted */
  1361. skb->do_not_encrypt = 0;
  1362. /*
  1363. * fix up the pointers accounting for the radiotap
  1364. * header still being in there. We are being given
  1365. * a precooked IEEE80211 header so no need for
  1366. * normal processing
  1367. */
  1368. skb_set_mac_header(skb, len_rthdr);
  1369. /*
  1370. * these are just fixed to the end of the rt area since we
  1371. * don't have any better information and at this point, nobody cares
  1372. */
  1373. skb_set_network_header(skb, len_rthdr);
  1374. skb_set_transport_header(skb, len_rthdr);
  1375. /* pass the radiotap header up to the next stage intact */
  1376. dev_queue_xmit(skb);
  1377. return NETDEV_TX_OK;
  1378. fail:
  1379. dev_kfree_skb(skb);
  1380. return NETDEV_TX_OK; /* meaning, we dealt with the skb */
  1381. }
  1382. /**
  1383. * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
  1384. * subinterfaces (wlan#, WDS, and VLAN interfaces)
  1385. * @skb: packet to be sent
  1386. * @dev: incoming interface
  1387. *
  1388. * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
  1389. * not be freed, and caller is responsible for either retrying later or freeing
  1390. * skb).
  1391. *
  1392. * This function takes in an Ethernet header and encapsulates it with suitable
  1393. * IEEE 802.11 header based on which interface the packet is coming in. The
  1394. * encapsulated packet will then be passed to master interface, wlan#.11, for
  1395. * transmission (through low-level driver).
  1396. */
  1397. int ieee80211_subif_start_xmit(struct sk_buff *skb,
  1398. struct net_device *dev)
  1399. {
  1400. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1401. struct ieee80211_local *local = sdata->local;
  1402. int ret = NETDEV_TX_BUSY, head_need;
  1403. u16 ethertype, hdrlen, meshhdrlen = 0;
  1404. __le16 fc;
  1405. struct ieee80211_hdr hdr;
  1406. struct ieee80211s_hdr mesh_hdr;
  1407. const u8 *encaps_data;
  1408. int encaps_len, skip_header_bytes;
  1409. int nh_pos, h_pos;
  1410. struct sta_info *sta;
  1411. u32 sta_flags = 0;
  1412. if (unlikely(skb->len < ETH_HLEN)) {
  1413. ret = NETDEV_TX_OK;
  1414. goto fail;
  1415. }
  1416. nh_pos = skb_network_header(skb) - skb->data;
  1417. h_pos = skb_transport_header(skb) - skb->data;
  1418. /* convert Ethernet header to proper 802.11 header (based on
  1419. * operation mode) */
  1420. ethertype = (skb->data[12] << 8) | skb->data[13];
  1421. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  1422. switch (sdata->vif.type) {
  1423. case NL80211_IFTYPE_AP:
  1424. case NL80211_IFTYPE_AP_VLAN:
  1425. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  1426. /* DA BSSID SA */
  1427. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1428. memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
  1429. memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
  1430. hdrlen = 24;
  1431. break;
  1432. case NL80211_IFTYPE_WDS:
  1433. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  1434. /* RA TA DA SA */
  1435. memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
  1436. memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
  1437. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1438. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1439. hdrlen = 30;
  1440. break;
  1441. #ifdef CONFIG_MAC80211_MESH
  1442. case NL80211_IFTYPE_MESH_POINT:
  1443. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  1444. if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
  1445. /* Do not send frames with mesh_ttl == 0 */
  1446. sdata->u.mesh.mshstats.dropped_frames_ttl++;
  1447. ret = NETDEV_TX_OK;
  1448. goto fail;
  1449. }
  1450. memset(&mesh_hdr, 0, sizeof(mesh_hdr));
  1451. if (compare_ether_addr(dev->dev_addr,
  1452. skb->data + ETH_ALEN) == 0) {
  1453. /* RA TA DA SA */
  1454. memset(hdr.addr1, 0, ETH_ALEN);
  1455. memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
  1456. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1457. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1458. meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr, sdata);
  1459. } else {
  1460. /* packet from other interface */
  1461. struct mesh_path *mppath;
  1462. memset(hdr.addr1, 0, ETH_ALEN);
  1463. memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
  1464. memcpy(hdr.addr4, dev->dev_addr, ETH_ALEN);
  1465. if (is_multicast_ether_addr(skb->data))
  1466. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1467. else {
  1468. rcu_read_lock();
  1469. mppath = mpp_path_lookup(skb->data, sdata);
  1470. if (mppath)
  1471. memcpy(hdr.addr3, mppath->mpp, ETH_ALEN);
  1472. else
  1473. memset(hdr.addr3, 0xff, ETH_ALEN);
  1474. rcu_read_unlock();
  1475. }
  1476. mesh_hdr.flags |= MESH_FLAGS_AE_A5_A6;
  1477. mesh_hdr.ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
  1478. put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &mesh_hdr.seqnum);
  1479. memcpy(mesh_hdr.eaddr1, skb->data, ETH_ALEN);
  1480. memcpy(mesh_hdr.eaddr2, skb->data + ETH_ALEN, ETH_ALEN);
  1481. sdata->u.mesh.mesh_seqnum++;
  1482. meshhdrlen = 18;
  1483. }
  1484. hdrlen = 30;
  1485. break;
  1486. #endif
  1487. case NL80211_IFTYPE_STATION:
  1488. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  1489. /* BSSID SA DA */
  1490. memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1491. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1492. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1493. hdrlen = 24;
  1494. break;
  1495. case NL80211_IFTYPE_ADHOC:
  1496. /* DA SA BSSID */
  1497. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1498. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1499. memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
  1500. hdrlen = 24;
  1501. break;
  1502. default:
  1503. ret = NETDEV_TX_OK;
  1504. goto fail;
  1505. }
  1506. /*
  1507. * There's no need to try to look up the destination
  1508. * if it is a multicast address (which can only happen
  1509. * in AP mode)
  1510. */
  1511. if (!is_multicast_ether_addr(hdr.addr1)) {
  1512. rcu_read_lock();
  1513. sta = sta_info_get(local, hdr.addr1);
  1514. if (sta)
  1515. sta_flags = get_sta_flags(sta);
  1516. rcu_read_unlock();
  1517. }
  1518. /* receiver and we are QoS enabled, use a QoS type frame */
  1519. if ((sta_flags & WLAN_STA_WME) && local->hw.queues >= 4) {
  1520. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  1521. hdrlen += 2;
  1522. }
  1523. /*
  1524. * Drop unicast frames to unauthorised stations unless they are
  1525. * EAPOL frames from the local station.
  1526. */
  1527. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  1528. unlikely(!is_multicast_ether_addr(hdr.addr1) &&
  1529. !(sta_flags & WLAN_STA_AUTHORIZED) &&
  1530. !(ethertype == ETH_P_PAE &&
  1531. compare_ether_addr(dev->dev_addr,
  1532. skb->data + ETH_ALEN) == 0))) {
  1533. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1534. if (net_ratelimit())
  1535. printk(KERN_DEBUG "%s: dropped frame to %pM"
  1536. " (unauthorized port)\n", dev->name,
  1537. hdr.addr1);
  1538. #endif
  1539. I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
  1540. ret = NETDEV_TX_OK;
  1541. goto fail;
  1542. }
  1543. hdr.frame_control = fc;
  1544. hdr.duration_id = 0;
  1545. hdr.seq_ctrl = 0;
  1546. skip_header_bytes = ETH_HLEN;
  1547. if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
  1548. encaps_data = bridge_tunnel_header;
  1549. encaps_len = sizeof(bridge_tunnel_header);
  1550. skip_header_bytes -= 2;
  1551. } else if (ethertype >= 0x600) {
  1552. encaps_data = rfc1042_header;
  1553. encaps_len = sizeof(rfc1042_header);
  1554. skip_header_bytes -= 2;
  1555. } else {
  1556. encaps_data = NULL;
  1557. encaps_len = 0;
  1558. }
  1559. skb_pull(skb, skip_header_bytes);
  1560. nh_pos -= skip_header_bytes;
  1561. h_pos -= skip_header_bytes;
  1562. head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
  1563. /*
  1564. * So we need to modify the skb header and hence need a copy of
  1565. * that. The head_need variable above doesn't, so far, include
  1566. * the needed header space that we don't need right away. If we
  1567. * can, then we don't reallocate right now but only after the
  1568. * frame arrives at the master device (if it does...)
  1569. *
  1570. * If we cannot, however, then we will reallocate to include all
  1571. * the ever needed space. Also, if we need to reallocate it anyway,
  1572. * make it big enough for everything we may ever need.
  1573. */
  1574. if (head_need > 0 || skb_cloned(skb)) {
  1575. head_need += IEEE80211_ENCRYPT_HEADROOM;
  1576. head_need += local->tx_headroom;
  1577. head_need = max_t(int, 0, head_need);
  1578. if (ieee80211_skb_resize(local, skb, head_need, true))
  1579. goto fail;
  1580. }
  1581. if (encaps_data) {
  1582. memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
  1583. nh_pos += encaps_len;
  1584. h_pos += encaps_len;
  1585. }
  1586. if (meshhdrlen > 0) {
  1587. memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
  1588. nh_pos += meshhdrlen;
  1589. h_pos += meshhdrlen;
  1590. }
  1591. if (ieee80211_is_data_qos(fc)) {
  1592. __le16 *qos_control;
  1593. qos_control = (__le16*) skb_push(skb, 2);
  1594. memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
  1595. /*
  1596. * Maybe we could actually set some fields here, for now just
  1597. * initialise to zero to indicate no special operation.
  1598. */
  1599. *qos_control = 0;
  1600. } else
  1601. memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
  1602. nh_pos += hdrlen;
  1603. h_pos += hdrlen;
  1604. skb->iif = dev->ifindex;
  1605. skb->dev = local->mdev;
  1606. dev->stats.tx_packets++;
  1607. dev->stats.tx_bytes += skb->len;
  1608. /* Update skb pointers to various headers since this modified frame
  1609. * is going to go through Linux networking code that may potentially
  1610. * need things like pointer to IP header. */
  1611. skb_set_mac_header(skb, 0);
  1612. skb_set_network_header(skb, nh_pos);
  1613. skb_set_transport_header(skb, h_pos);
  1614. dev->trans_start = jiffies;
  1615. dev_queue_xmit(skb);
  1616. return NETDEV_TX_OK;
  1617. fail:
  1618. if (ret == NETDEV_TX_OK)
  1619. dev_kfree_skb(skb);
  1620. return ret;
  1621. }
  1622. /*
  1623. * ieee80211_clear_tx_pending may not be called in a context where
  1624. * it is possible that it packets could come in again.
  1625. */
  1626. void ieee80211_clear_tx_pending(struct ieee80211_local *local)
  1627. {
  1628. int i;
  1629. for (i = 0; i < local->hw.queues; i++)
  1630. skb_queue_purge(&local->pending[i]);
  1631. }
  1632. static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
  1633. struct sk_buff *skb)
  1634. {
  1635. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1636. struct ieee80211_sub_if_data *sdata;
  1637. struct sta_info *sta;
  1638. struct ieee80211_hdr *hdr;
  1639. struct net_device *dev;
  1640. int ret;
  1641. bool result = true;
  1642. /* does interface still exist? */
  1643. dev = dev_get_by_index(&init_net, skb->iif);
  1644. if (!dev) {
  1645. dev_kfree_skb(skb);
  1646. return true;
  1647. }
  1648. /* validate info->control.vif against skb->iif */
  1649. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1650. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1651. sdata = container_of(sdata->bss,
  1652. struct ieee80211_sub_if_data,
  1653. u.ap);
  1654. if (unlikely(info->control.vif && info->control.vif != &sdata->vif)) {
  1655. dev_kfree_skb(skb);
  1656. result = true;
  1657. goto out;
  1658. }
  1659. if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
  1660. ieee80211_tx(dev, skb, true);
  1661. } else {
  1662. hdr = (struct ieee80211_hdr *)skb->data;
  1663. sta = sta_info_get(local, hdr->addr1);
  1664. ret = __ieee80211_tx(local, &skb, sta);
  1665. if (ret != IEEE80211_TX_OK)
  1666. result = false;
  1667. }
  1668. out:
  1669. dev_put(dev);
  1670. return result;
  1671. }
  1672. /*
  1673. * Transmit all pending packets. Called from tasklet, locks master device
  1674. * TX lock so that no new packets can come in.
  1675. */
  1676. void ieee80211_tx_pending(unsigned long data)
  1677. {
  1678. struct ieee80211_local *local = (struct ieee80211_local *)data;
  1679. struct net_device *dev = local->mdev;
  1680. unsigned long flags;
  1681. int i;
  1682. bool next;
  1683. rcu_read_lock();
  1684. netif_tx_lock_bh(dev);
  1685. for (i = 0; i < local->hw.queues; i++) {
  1686. /*
  1687. * If queue is stopped by something other than due to pending
  1688. * frames, or we have no pending frames, proceed to next queue.
  1689. */
  1690. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  1691. next = false;
  1692. if (local->queue_stop_reasons[i] !=
  1693. BIT(IEEE80211_QUEUE_STOP_REASON_PENDING) ||
  1694. skb_queue_empty(&local->pending[i]))
  1695. next = true;
  1696. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  1697. if (next)
  1698. continue;
  1699. /*
  1700. * start the queue now to allow processing our packets,
  1701. * we're under the tx lock here anyway so nothing will
  1702. * happen as a result of this
  1703. */
  1704. netif_start_subqueue(local->mdev, i);
  1705. while (!skb_queue_empty(&local->pending[i])) {
  1706. struct sk_buff *skb = skb_dequeue(&local->pending[i]);
  1707. if (!ieee80211_tx_pending_skb(local, skb)) {
  1708. skb_queue_head(&local->pending[i], skb);
  1709. break;
  1710. }
  1711. }
  1712. /* Start regular packet processing again. */
  1713. if (skb_queue_empty(&local->pending[i]))
  1714. ieee80211_wake_queue_by_reason(&local->hw, i,
  1715. IEEE80211_QUEUE_STOP_REASON_PENDING);
  1716. }
  1717. netif_tx_unlock_bh(dev);
  1718. rcu_read_unlock();
  1719. }
  1720. /* functions for drivers to get certain frames */
  1721. static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
  1722. struct sk_buff *skb,
  1723. struct beacon_data *beacon)
  1724. {
  1725. u8 *pos, *tim;
  1726. int aid0 = 0;
  1727. int i, have_bits = 0, n1, n2;
  1728. /* Generate bitmap for TIM only if there are any STAs in power save
  1729. * mode. */
  1730. if (atomic_read(&bss->num_sta_ps) > 0)
  1731. /* in the hope that this is faster than
  1732. * checking byte-for-byte */
  1733. have_bits = !bitmap_empty((unsigned long*)bss->tim,
  1734. IEEE80211_MAX_AID+1);
  1735. if (bss->dtim_count == 0)
  1736. bss->dtim_count = beacon->dtim_period - 1;
  1737. else
  1738. bss->dtim_count--;
  1739. tim = pos = (u8 *) skb_put(skb, 6);
  1740. *pos++ = WLAN_EID_TIM;
  1741. *pos++ = 4;
  1742. *pos++ = bss->dtim_count;
  1743. *pos++ = beacon->dtim_period;
  1744. if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
  1745. aid0 = 1;
  1746. if (have_bits) {
  1747. /* Find largest even number N1 so that bits numbered 1 through
  1748. * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
  1749. * (N2 + 1) x 8 through 2007 are 0. */
  1750. n1 = 0;
  1751. for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
  1752. if (bss->tim[i]) {
  1753. n1 = i & 0xfe;
  1754. break;
  1755. }
  1756. }
  1757. n2 = n1;
  1758. for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
  1759. if (bss->tim[i]) {
  1760. n2 = i;
  1761. break;
  1762. }
  1763. }
  1764. /* Bitmap control */
  1765. *pos++ = n1 | aid0;
  1766. /* Part Virt Bitmap */
  1767. memcpy(pos, bss->tim + n1, n2 - n1 + 1);
  1768. tim[1] = n2 - n1 + 4;
  1769. skb_put(skb, n2 - n1);
  1770. } else {
  1771. *pos++ = aid0; /* Bitmap control */
  1772. *pos++ = 0; /* Part Virt Bitmap */
  1773. }
  1774. }
  1775. struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
  1776. struct ieee80211_vif *vif)
  1777. {
  1778. struct ieee80211_local *local = hw_to_local(hw);
  1779. struct sk_buff *skb = NULL;
  1780. struct ieee80211_tx_info *info;
  1781. struct ieee80211_sub_if_data *sdata = NULL;
  1782. struct ieee80211_if_ap *ap = NULL;
  1783. struct beacon_data *beacon;
  1784. struct ieee80211_supported_band *sband;
  1785. enum ieee80211_band band = local->hw.conf.channel->band;
  1786. sband = local->hw.wiphy->bands[band];
  1787. rcu_read_lock();
  1788. sdata = vif_to_sdata(vif);
  1789. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1790. ap = &sdata->u.ap;
  1791. beacon = rcu_dereference(ap->beacon);
  1792. if (ap && beacon) {
  1793. /*
  1794. * headroom, head length,
  1795. * tail length and maximum TIM length
  1796. */
  1797. skb = dev_alloc_skb(local->tx_headroom +
  1798. beacon->head_len +
  1799. beacon->tail_len + 256);
  1800. if (!skb)
  1801. goto out;
  1802. skb_reserve(skb, local->tx_headroom);
  1803. memcpy(skb_put(skb, beacon->head_len), beacon->head,
  1804. beacon->head_len);
  1805. /*
  1806. * Not very nice, but we want to allow the driver to call
  1807. * ieee80211_beacon_get() as a response to the set_tim()
  1808. * callback. That, however, is already invoked under the
  1809. * sta_lock to guarantee consistent and race-free update
  1810. * of the tim bitmap in mac80211 and the driver.
  1811. */
  1812. if (local->tim_in_locked_section) {
  1813. ieee80211_beacon_add_tim(ap, skb, beacon);
  1814. } else {
  1815. unsigned long flags;
  1816. spin_lock_irqsave(&local->sta_lock, flags);
  1817. ieee80211_beacon_add_tim(ap, skb, beacon);
  1818. spin_unlock_irqrestore(&local->sta_lock, flags);
  1819. }
  1820. if (beacon->tail)
  1821. memcpy(skb_put(skb, beacon->tail_len),
  1822. beacon->tail, beacon->tail_len);
  1823. } else
  1824. goto out;
  1825. } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  1826. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  1827. struct ieee80211_hdr *hdr;
  1828. struct sk_buff *presp = rcu_dereference(ifibss->presp);
  1829. if (!presp)
  1830. goto out;
  1831. skb = skb_copy(presp, GFP_ATOMIC);
  1832. if (!skb)
  1833. goto out;
  1834. hdr = (struct ieee80211_hdr *) skb->data;
  1835. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1836. IEEE80211_STYPE_BEACON);
  1837. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1838. struct ieee80211_mgmt *mgmt;
  1839. u8 *pos;
  1840. /* headroom, head length, tail length and maximum TIM length */
  1841. skb = dev_alloc_skb(local->tx_headroom + 400);
  1842. if (!skb)
  1843. goto out;
  1844. skb_reserve(skb, local->hw.extra_tx_headroom);
  1845. mgmt = (struct ieee80211_mgmt *)
  1846. skb_put(skb, 24 + sizeof(mgmt->u.beacon));
  1847. memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
  1848. mgmt->frame_control =
  1849. cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
  1850. memset(mgmt->da, 0xff, ETH_ALEN);
  1851. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  1852. /* BSSID is left zeroed, wildcard value */
  1853. mgmt->u.beacon.beacon_int =
  1854. cpu_to_le16(sdata->vif.bss_conf.beacon_int);
  1855. mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
  1856. pos = skb_put(skb, 2);
  1857. *pos++ = WLAN_EID_SSID;
  1858. *pos++ = 0x0;
  1859. mesh_mgmt_ies_add(skb, sdata);
  1860. } else {
  1861. WARN_ON(1);
  1862. goto out;
  1863. }
  1864. info = IEEE80211_SKB_CB(skb);
  1865. skb->do_not_encrypt = 1;
  1866. info->band = band;
  1867. /*
  1868. * XXX: For now, always use the lowest rate
  1869. */
  1870. info->control.rates[0].idx = 0;
  1871. info->control.rates[0].count = 1;
  1872. info->control.rates[1].idx = -1;
  1873. info->control.rates[2].idx = -1;
  1874. info->control.rates[3].idx = -1;
  1875. info->control.rates[4].idx = -1;
  1876. BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
  1877. info->control.vif = vif;
  1878. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  1879. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
  1880. info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
  1881. out:
  1882. rcu_read_unlock();
  1883. return skb;
  1884. }
  1885. EXPORT_SYMBOL(ieee80211_beacon_get);
  1886. void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1887. const void *frame, size_t frame_len,
  1888. const struct ieee80211_tx_info *frame_txctl,
  1889. struct ieee80211_rts *rts)
  1890. {
  1891. const struct ieee80211_hdr *hdr = frame;
  1892. rts->frame_control =
  1893. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  1894. rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
  1895. frame_txctl);
  1896. memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
  1897. memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
  1898. }
  1899. EXPORT_SYMBOL(ieee80211_rts_get);
  1900. void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1901. const void *frame, size_t frame_len,
  1902. const struct ieee80211_tx_info *frame_txctl,
  1903. struct ieee80211_cts *cts)
  1904. {
  1905. const struct ieee80211_hdr *hdr = frame;
  1906. cts->frame_control =
  1907. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  1908. cts->duration = ieee80211_ctstoself_duration(hw, vif,
  1909. frame_len, frame_txctl);
  1910. memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
  1911. }
  1912. EXPORT_SYMBOL(ieee80211_ctstoself_get);
  1913. struct sk_buff *
  1914. ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
  1915. struct ieee80211_vif *vif)
  1916. {
  1917. struct ieee80211_local *local = hw_to_local(hw);
  1918. struct sk_buff *skb = NULL;
  1919. struct sta_info *sta;
  1920. struct ieee80211_tx_data tx;
  1921. struct ieee80211_sub_if_data *sdata;
  1922. struct ieee80211_if_ap *bss = NULL;
  1923. struct beacon_data *beacon;
  1924. struct ieee80211_tx_info *info;
  1925. sdata = vif_to_sdata(vif);
  1926. bss = &sdata->u.ap;
  1927. if (!bss)
  1928. return NULL;
  1929. rcu_read_lock();
  1930. beacon = rcu_dereference(bss->beacon);
  1931. if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head)
  1932. goto out;
  1933. if (bss->dtim_count != 0)
  1934. goto out; /* send buffered bc/mc only after DTIM beacon */
  1935. while (1) {
  1936. skb = skb_dequeue(&bss->ps_bc_buf);
  1937. if (!skb)
  1938. goto out;
  1939. local->total_ps_buffered--;
  1940. if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
  1941. struct ieee80211_hdr *hdr =
  1942. (struct ieee80211_hdr *) skb->data;
  1943. /* more buffered multicast/broadcast frames ==> set
  1944. * MoreData flag in IEEE 802.11 header to inform PS
  1945. * STAs */
  1946. hdr->frame_control |=
  1947. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1948. }
  1949. if (!ieee80211_tx_prepare(local, &tx, skb))
  1950. break;
  1951. dev_kfree_skb_any(skb);
  1952. }
  1953. info = IEEE80211_SKB_CB(skb);
  1954. sta = tx.sta;
  1955. tx.flags |= IEEE80211_TX_PS_BUFFERED;
  1956. tx.channel = local->hw.conf.channel;
  1957. info->band = tx.channel->band;
  1958. if (invoke_tx_handlers(&tx))
  1959. skb = NULL;
  1960. out:
  1961. rcu_read_unlock();
  1962. return skb;
  1963. }
  1964. EXPORT_SYMBOL(ieee80211_get_buffered_bc);