rx.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431
  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-2010 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. #include <linux/jiffies.h>
  12. #include <linux/slab.h>
  13. #include <linux/kernel.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/rcupdate.h>
  18. #include <linux/export.h>
  19. #include <net/mac80211.h>
  20. #include <net/ieee80211_radiotap.h>
  21. #include <asm/unaligned.h>
  22. #include "ieee80211_i.h"
  23. #include "driver-ops.h"
  24. #include "led.h"
  25. #include "mesh.h"
  26. #include "wep.h"
  27. #include "wpa.h"
  28. #include "tkip.h"
  29. #include "wme.h"
  30. #include "rate.h"
  31. /*
  32. * monitor mode reception
  33. *
  34. * This function cleans up the SKB, i.e. it removes all the stuff
  35. * only useful for monitoring.
  36. */
  37. static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
  38. struct sk_buff *skb)
  39. {
  40. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  41. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
  42. if (likely(skb->len > FCS_LEN))
  43. __pskb_trim(skb, skb->len - FCS_LEN);
  44. else {
  45. /* driver bug */
  46. WARN_ON(1);
  47. dev_kfree_skb(skb);
  48. return NULL;
  49. }
  50. }
  51. if (status->vendor_radiotap_len)
  52. __pskb_pull(skb, status->vendor_radiotap_len);
  53. return skb;
  54. }
  55. static inline int should_drop_frame(struct sk_buff *skb, int present_fcs_len)
  56. {
  57. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  58. struct ieee80211_hdr *hdr;
  59. hdr = (void *)(skb->data + status->vendor_radiotap_len);
  60. if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
  61. RX_FLAG_FAILED_PLCP_CRC |
  62. RX_FLAG_AMPDU_IS_ZEROLEN))
  63. return 1;
  64. if (unlikely(skb->len < 16 + present_fcs_len +
  65. status->vendor_radiotap_len))
  66. return 1;
  67. if (ieee80211_is_ctl(hdr->frame_control) &&
  68. !ieee80211_is_pspoll(hdr->frame_control) &&
  69. !ieee80211_is_back_req(hdr->frame_control))
  70. return 1;
  71. return 0;
  72. }
  73. static int
  74. ieee80211_rx_radiotap_space(struct ieee80211_local *local,
  75. struct ieee80211_rx_status *status)
  76. {
  77. int len;
  78. /* always present fields */
  79. len = sizeof(struct ieee80211_radiotap_header) + 8;
  80. /* allocate extra bitmaps */
  81. if (status->vendor_radiotap_len)
  82. len += 4;
  83. if (status->chains)
  84. len += 4 * hweight8(status->chains);
  85. if (ieee80211_have_rx_timestamp(status)) {
  86. len = ALIGN(len, 8);
  87. len += 8;
  88. }
  89. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  90. len += 1;
  91. /* antenna field, if we don't have per-chain info */
  92. if (!status->chains)
  93. len += 1;
  94. /* padding for RX_FLAGS if necessary */
  95. len = ALIGN(len, 2);
  96. if (status->flag & RX_FLAG_HT) /* HT info */
  97. len += 3;
  98. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  99. len = ALIGN(len, 4);
  100. len += 8;
  101. }
  102. if (status->flag & RX_FLAG_VHT) {
  103. len = ALIGN(len, 2);
  104. len += 12;
  105. }
  106. if (status->chains) {
  107. /* antenna and antenna signal fields */
  108. len += 2 * hweight8(status->chains);
  109. }
  110. if (status->vendor_radiotap_len) {
  111. if (WARN_ON_ONCE(status->vendor_radiotap_align == 0))
  112. status->vendor_radiotap_align = 1;
  113. /* align standard part of vendor namespace */
  114. len = ALIGN(len, 2);
  115. /* allocate standard part of vendor namespace */
  116. len += 6;
  117. /* align vendor-defined part */
  118. len = ALIGN(len, status->vendor_radiotap_align);
  119. /* vendor-defined part is already in skb */
  120. }
  121. return len;
  122. }
  123. /*
  124. * ieee80211_add_rx_radiotap_header - add radiotap header
  125. *
  126. * add a radiotap header containing all the fields which the hardware provided.
  127. */
  128. static void
  129. ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
  130. struct sk_buff *skb,
  131. struct ieee80211_rate *rate,
  132. int rtap_len, bool has_fcs)
  133. {
  134. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  135. struct ieee80211_radiotap_header *rthdr;
  136. unsigned char *pos;
  137. __le32 *it_present;
  138. u32 it_present_val;
  139. u16 rx_flags = 0;
  140. u16 channel_flags = 0;
  141. int mpdulen, chain;
  142. unsigned long chains = status->chains;
  143. mpdulen = skb->len;
  144. if (!(has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)))
  145. mpdulen += FCS_LEN;
  146. rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
  147. memset(rthdr, 0, rtap_len);
  148. it_present = &rthdr->it_present;
  149. /* radiotap header, set always present flags */
  150. rthdr->it_len = cpu_to_le16(rtap_len + status->vendor_radiotap_len);
  151. it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
  152. BIT(IEEE80211_RADIOTAP_CHANNEL) |
  153. BIT(IEEE80211_RADIOTAP_RX_FLAGS);
  154. if (!status->chains)
  155. it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
  156. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  157. it_present_val |=
  158. BIT(IEEE80211_RADIOTAP_EXT) |
  159. BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
  160. put_unaligned_le32(it_present_val, it_present);
  161. it_present++;
  162. it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
  163. BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  164. }
  165. if (status->vendor_radiotap_len) {
  166. it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
  167. BIT(IEEE80211_RADIOTAP_EXT);
  168. put_unaligned_le32(it_present_val, it_present);
  169. it_present++;
  170. it_present_val = status->vendor_radiotap_bitmap;
  171. }
  172. put_unaligned_le32(it_present_val, it_present);
  173. pos = (void *)(it_present + 1);
  174. /* the order of the following fields is important */
  175. /* IEEE80211_RADIOTAP_TSFT */
  176. if (ieee80211_have_rx_timestamp(status)) {
  177. /* padding */
  178. while ((pos - (u8 *)rthdr) & 7)
  179. *pos++ = 0;
  180. put_unaligned_le64(
  181. ieee80211_calculate_rx_timestamp(local, status,
  182. mpdulen, 0),
  183. pos);
  184. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
  185. pos += 8;
  186. }
  187. /* IEEE80211_RADIOTAP_FLAGS */
  188. if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
  189. *pos |= IEEE80211_RADIOTAP_F_FCS;
  190. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  191. *pos |= IEEE80211_RADIOTAP_F_BADFCS;
  192. if (status->flag & RX_FLAG_SHORTPRE)
  193. *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
  194. pos++;
  195. /* IEEE80211_RADIOTAP_RATE */
  196. if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
  197. /*
  198. * Without rate information don't add it. If we have,
  199. * MCS information is a separate field in radiotap,
  200. * added below. The byte here is needed as padding
  201. * for the channel though, so initialise it to 0.
  202. */
  203. *pos = 0;
  204. } else {
  205. int shift = 0;
  206. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  207. if (status->flag & RX_FLAG_10MHZ)
  208. shift = 1;
  209. else if (status->flag & RX_FLAG_5MHZ)
  210. shift = 2;
  211. *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
  212. }
  213. pos++;
  214. /* IEEE80211_RADIOTAP_CHANNEL */
  215. put_unaligned_le16(status->freq, pos);
  216. pos += 2;
  217. if (status->flag & RX_FLAG_10MHZ)
  218. channel_flags |= IEEE80211_CHAN_HALF;
  219. else if (status->flag & RX_FLAG_5MHZ)
  220. channel_flags |= IEEE80211_CHAN_QUARTER;
  221. if (status->band == IEEE80211_BAND_5GHZ)
  222. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
  223. else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  224. channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
  225. else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
  226. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  227. else if (rate)
  228. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  229. else
  230. channel_flags |= IEEE80211_CHAN_2GHZ;
  231. put_unaligned_le16(channel_flags, pos);
  232. pos += 2;
  233. /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
  234. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM &&
  235. !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  236. *pos = status->signal;
  237. rthdr->it_present |=
  238. cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  239. pos++;
  240. }
  241. /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
  242. if (!status->chains) {
  243. /* IEEE80211_RADIOTAP_ANTENNA */
  244. *pos = status->antenna;
  245. pos++;
  246. }
  247. /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
  248. /* IEEE80211_RADIOTAP_RX_FLAGS */
  249. /* ensure 2 byte alignment for the 2 byte field as required */
  250. if ((pos - (u8 *)rthdr) & 1)
  251. *pos++ = 0;
  252. if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
  253. rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
  254. put_unaligned_le16(rx_flags, pos);
  255. pos += 2;
  256. if (status->flag & RX_FLAG_HT) {
  257. unsigned int stbc;
  258. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
  259. *pos++ = local->hw.radiotap_mcs_details;
  260. *pos = 0;
  261. if (status->flag & RX_FLAG_SHORT_GI)
  262. *pos |= IEEE80211_RADIOTAP_MCS_SGI;
  263. if (status->flag & RX_FLAG_40MHZ)
  264. *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
  265. if (status->flag & RX_FLAG_HT_GF)
  266. *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  267. stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
  268. *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
  269. pos++;
  270. *pos++ = status->rate_idx;
  271. }
  272. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  273. u16 flags = 0;
  274. /* ensure 4 byte alignment */
  275. while ((pos - (u8 *)rthdr) & 3)
  276. pos++;
  277. rthdr->it_present |=
  278. cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
  279. put_unaligned_le32(status->ampdu_reference, pos);
  280. pos += 4;
  281. if (status->flag & RX_FLAG_AMPDU_REPORT_ZEROLEN)
  282. flags |= IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN;
  283. if (status->flag & RX_FLAG_AMPDU_IS_ZEROLEN)
  284. flags |= IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN;
  285. if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
  286. flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
  287. if (status->flag & RX_FLAG_AMPDU_IS_LAST)
  288. flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
  289. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
  290. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
  291. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  292. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
  293. put_unaligned_le16(flags, pos);
  294. pos += 2;
  295. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  296. *pos++ = status->ampdu_delimiter_crc;
  297. else
  298. *pos++ = 0;
  299. *pos++ = 0;
  300. }
  301. if (status->flag & RX_FLAG_VHT) {
  302. u16 known = local->hw.radiotap_vht_details;
  303. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
  304. /* known field - how to handle 80+80? */
  305. if (status->flag & RX_FLAG_80P80MHZ)
  306. known &= ~IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  307. put_unaligned_le16(known, pos);
  308. pos += 2;
  309. /* flags */
  310. if (status->flag & RX_FLAG_SHORT_GI)
  311. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  312. pos++;
  313. /* bandwidth */
  314. if (status->flag & RX_FLAG_80MHZ)
  315. *pos++ = 4;
  316. else if (status->flag & RX_FLAG_80P80MHZ)
  317. *pos++ = 0; /* marked not known above */
  318. else if (status->flag & RX_FLAG_160MHZ)
  319. *pos++ = 11;
  320. else if (status->flag & RX_FLAG_40MHZ)
  321. *pos++ = 1;
  322. else /* 20 MHz */
  323. *pos++ = 0;
  324. /* MCS/NSS */
  325. *pos = (status->rate_idx << 4) | status->vht_nss;
  326. pos += 4;
  327. /* coding field */
  328. pos++;
  329. /* group ID */
  330. pos++;
  331. /* partial_aid */
  332. pos += 2;
  333. }
  334. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  335. *pos++ = status->chain_signal[chain];
  336. *pos++ = chain;
  337. }
  338. if (status->vendor_radiotap_len) {
  339. /* ensure 2 byte alignment for the vendor field as required */
  340. if ((pos - (u8 *)rthdr) & 1)
  341. *pos++ = 0;
  342. *pos++ = status->vendor_radiotap_oui[0];
  343. *pos++ = status->vendor_radiotap_oui[1];
  344. *pos++ = status->vendor_radiotap_oui[2];
  345. *pos++ = status->vendor_radiotap_subns;
  346. put_unaligned_le16(status->vendor_radiotap_len, pos);
  347. pos += 2;
  348. /* align the actual payload as requested */
  349. while ((pos - (u8 *)rthdr) & (status->vendor_radiotap_align - 1))
  350. *pos++ = 0;
  351. }
  352. }
  353. /*
  354. * This function copies a received frame to all monitor interfaces and
  355. * returns a cleaned-up SKB that no longer includes the FCS nor the
  356. * radiotap header the driver might have added.
  357. */
  358. static struct sk_buff *
  359. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  360. struct ieee80211_rate *rate)
  361. {
  362. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
  363. struct ieee80211_sub_if_data *sdata;
  364. int needed_headroom;
  365. struct sk_buff *skb, *skb2;
  366. struct net_device *prev_dev = NULL;
  367. int present_fcs_len = 0;
  368. /*
  369. * First, we may need to make a copy of the skb because
  370. * (1) we need to modify it for radiotap (if not present), and
  371. * (2) the other RX handlers will modify the skb we got.
  372. *
  373. * We don't need to, of course, if we aren't going to return
  374. * the SKB because it has a bad FCS/PLCP checksum.
  375. */
  376. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  377. present_fcs_len = FCS_LEN;
  378. /* ensure hdr->frame_control and vendor radiotap data are in skb head */
  379. if (!pskb_may_pull(origskb, 2 + status->vendor_radiotap_len)) {
  380. dev_kfree_skb(origskb);
  381. return NULL;
  382. }
  383. if (!local->monitors) {
  384. if (should_drop_frame(origskb, present_fcs_len)) {
  385. dev_kfree_skb(origskb);
  386. return NULL;
  387. }
  388. return remove_monitor_info(local, origskb);
  389. }
  390. /* room for the radiotap header based on driver features */
  391. needed_headroom = ieee80211_rx_radiotap_space(local, status);
  392. if (should_drop_frame(origskb, present_fcs_len)) {
  393. /* only need to expand headroom if necessary */
  394. skb = origskb;
  395. origskb = NULL;
  396. /*
  397. * This shouldn't trigger often because most devices have an
  398. * RX header they pull before we get here, and that should
  399. * be big enough for our radiotap information. We should
  400. * probably export the length to drivers so that we can have
  401. * them allocate enough headroom to start with.
  402. */
  403. if (skb_headroom(skb) < needed_headroom &&
  404. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  405. dev_kfree_skb(skb);
  406. return NULL;
  407. }
  408. } else {
  409. /*
  410. * Need to make a copy and possibly remove radiotap header
  411. * and FCS from the original.
  412. */
  413. skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
  414. origskb = remove_monitor_info(local, origskb);
  415. if (!skb)
  416. return origskb;
  417. }
  418. /* prepend radiotap information */
  419. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
  420. true);
  421. skb_reset_mac_header(skb);
  422. skb->ip_summed = CHECKSUM_UNNECESSARY;
  423. skb->pkt_type = PACKET_OTHERHOST;
  424. skb->protocol = htons(ETH_P_802_2);
  425. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  426. if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
  427. continue;
  428. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
  429. continue;
  430. if (!ieee80211_sdata_running(sdata))
  431. continue;
  432. if (prev_dev) {
  433. skb2 = skb_clone(skb, GFP_ATOMIC);
  434. if (skb2) {
  435. skb2->dev = prev_dev;
  436. netif_receive_skb(skb2);
  437. }
  438. }
  439. prev_dev = sdata->dev;
  440. sdata->dev->stats.rx_packets++;
  441. sdata->dev->stats.rx_bytes += skb->len;
  442. }
  443. if (prev_dev) {
  444. skb->dev = prev_dev;
  445. netif_receive_skb(skb);
  446. } else
  447. dev_kfree_skb(skb);
  448. return origskb;
  449. }
  450. static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
  451. {
  452. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  453. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  454. int tid, seqno_idx, security_idx;
  455. /* does the frame have a qos control field? */
  456. if (ieee80211_is_data_qos(hdr->frame_control)) {
  457. u8 *qc = ieee80211_get_qos_ctl(hdr);
  458. /* frame has qos control */
  459. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  460. if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
  461. status->rx_flags |= IEEE80211_RX_AMSDU;
  462. seqno_idx = tid;
  463. security_idx = tid;
  464. } else {
  465. /*
  466. * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
  467. *
  468. * Sequence numbers for management frames, QoS data
  469. * frames with a broadcast/multicast address in the
  470. * Address 1 field, and all non-QoS data frames sent
  471. * by QoS STAs are assigned using an additional single
  472. * modulo-4096 counter, [...]
  473. *
  474. * We also use that counter for non-QoS STAs.
  475. */
  476. seqno_idx = IEEE80211_NUM_TIDS;
  477. security_idx = 0;
  478. if (ieee80211_is_mgmt(hdr->frame_control))
  479. security_idx = IEEE80211_NUM_TIDS;
  480. tid = 0;
  481. }
  482. rx->seqno_idx = seqno_idx;
  483. rx->security_idx = security_idx;
  484. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  485. * For now, set skb->priority to 0 for other cases. */
  486. rx->skb->priority = (tid > 7) ? 0 : tid;
  487. }
  488. /**
  489. * DOC: Packet alignment
  490. *
  491. * Drivers always need to pass packets that are aligned to two-byte boundaries
  492. * to the stack.
  493. *
  494. * Additionally, should, if possible, align the payload data in a way that
  495. * guarantees that the contained IP header is aligned to a four-byte
  496. * boundary. In the case of regular frames, this simply means aligning the
  497. * payload to a four-byte boundary (because either the IP header is directly
  498. * contained, or IV/RFC1042 headers that have a length divisible by four are
  499. * in front of it). If the payload data is not properly aligned and the
  500. * architecture doesn't support efficient unaligned operations, mac80211
  501. * will align the data.
  502. *
  503. * With A-MSDU frames, however, the payload data address must yield two modulo
  504. * four because there are 14-byte 802.3 headers within the A-MSDU frames that
  505. * push the IP header further back to a multiple of four again. Thankfully, the
  506. * specs were sane enough this time around to require padding each A-MSDU
  507. * subframe to a length that is a multiple of four.
  508. *
  509. * Padding like Atheros hardware adds which is between the 802.11 header and
  510. * the payload is not supported, the driver is required to move the 802.11
  511. * header to be directly in front of the payload in that case.
  512. */
  513. static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
  514. {
  515. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  516. WARN_ONCE((unsigned long)rx->skb->data & 1,
  517. "unaligned packet at 0x%p\n", rx->skb->data);
  518. #endif
  519. }
  520. /* rx handlers */
  521. static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
  522. {
  523. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  524. if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
  525. return 0;
  526. return ieee80211_is_robust_mgmt_frame(hdr);
  527. }
  528. static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
  529. {
  530. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  531. if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
  532. return 0;
  533. return ieee80211_is_robust_mgmt_frame(hdr);
  534. }
  535. /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
  536. static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
  537. {
  538. struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
  539. struct ieee80211_mmie *mmie;
  540. if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
  541. return -1;
  542. if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
  543. return -1; /* not a robust management frame */
  544. mmie = (struct ieee80211_mmie *)
  545. (skb->data + skb->len - sizeof(*mmie));
  546. if (mmie->element_id != WLAN_EID_MMIE ||
  547. mmie->length != sizeof(*mmie) - 2)
  548. return -1;
  549. return le16_to_cpu(mmie->key_id);
  550. }
  551. static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
  552. {
  553. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  554. char *dev_addr = rx->sdata->vif.addr;
  555. if (ieee80211_is_data(hdr->frame_control)) {
  556. if (is_multicast_ether_addr(hdr->addr1)) {
  557. if (ieee80211_has_tods(hdr->frame_control) ||
  558. !ieee80211_has_fromds(hdr->frame_control))
  559. return RX_DROP_MONITOR;
  560. if (ether_addr_equal(hdr->addr3, dev_addr))
  561. return RX_DROP_MONITOR;
  562. } else {
  563. if (!ieee80211_has_a4(hdr->frame_control))
  564. return RX_DROP_MONITOR;
  565. if (ether_addr_equal(hdr->addr4, dev_addr))
  566. return RX_DROP_MONITOR;
  567. }
  568. }
  569. /* If there is not an established peer link and this is not a peer link
  570. * establisment frame, beacon or probe, drop the frame.
  571. */
  572. if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
  573. struct ieee80211_mgmt *mgmt;
  574. if (!ieee80211_is_mgmt(hdr->frame_control))
  575. return RX_DROP_MONITOR;
  576. if (ieee80211_is_action(hdr->frame_control)) {
  577. u8 category;
  578. /* make sure category field is present */
  579. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
  580. return RX_DROP_MONITOR;
  581. mgmt = (struct ieee80211_mgmt *)hdr;
  582. category = mgmt->u.action.category;
  583. if (category != WLAN_CATEGORY_MESH_ACTION &&
  584. category != WLAN_CATEGORY_SELF_PROTECTED)
  585. return RX_DROP_MONITOR;
  586. return RX_CONTINUE;
  587. }
  588. if (ieee80211_is_probe_req(hdr->frame_control) ||
  589. ieee80211_is_probe_resp(hdr->frame_control) ||
  590. ieee80211_is_beacon(hdr->frame_control) ||
  591. ieee80211_is_auth(hdr->frame_control))
  592. return RX_CONTINUE;
  593. return RX_DROP_MONITOR;
  594. }
  595. return RX_CONTINUE;
  596. }
  597. static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
  598. struct tid_ampdu_rx *tid_agg_rx,
  599. int index,
  600. struct sk_buff_head *frames)
  601. {
  602. struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
  603. struct ieee80211_rx_status *status;
  604. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  605. if (!skb)
  606. goto no_frame;
  607. /* release the frame from the reorder ring buffer */
  608. tid_agg_rx->stored_mpdu_num--;
  609. tid_agg_rx->reorder_buf[index] = NULL;
  610. status = IEEE80211_SKB_RXCB(skb);
  611. status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
  612. __skb_queue_tail(frames, skb);
  613. no_frame:
  614. tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  615. }
  616. static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
  617. struct tid_ampdu_rx *tid_agg_rx,
  618. u16 head_seq_num,
  619. struct sk_buff_head *frames)
  620. {
  621. int index;
  622. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  623. while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  624. index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  625. tid_agg_rx->ssn) %
  626. tid_agg_rx->buf_size;
  627. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  628. frames);
  629. }
  630. }
  631. /*
  632. * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
  633. * the skb was added to the buffer longer than this time ago, the earlier
  634. * frames that have not yet been received are assumed to be lost and the skb
  635. * can be released for processing. This may also release other skb's from the
  636. * reorder buffer if there are no additional gaps between the frames.
  637. *
  638. * Callers must hold tid_agg_rx->reorder_lock.
  639. */
  640. #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
  641. static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
  642. struct tid_ampdu_rx *tid_agg_rx,
  643. struct sk_buff_head *frames)
  644. {
  645. int index, j;
  646. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  647. /* release the buffer until next missing frame */
  648. index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  649. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  650. if (!tid_agg_rx->reorder_buf[index] &&
  651. tid_agg_rx->stored_mpdu_num) {
  652. /*
  653. * No buffers ready to be released, but check whether any
  654. * frames in the reorder buffer have timed out.
  655. */
  656. int skipped = 1;
  657. for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
  658. j = (j + 1) % tid_agg_rx->buf_size) {
  659. if (!tid_agg_rx->reorder_buf[j]) {
  660. skipped++;
  661. continue;
  662. }
  663. if (skipped &&
  664. !time_after(jiffies, tid_agg_rx->reorder_time[j] +
  665. HT_RX_REORDER_BUF_TIMEOUT))
  666. goto set_release_timer;
  667. ht_dbg_ratelimited(sdata,
  668. "release an RX reorder frame due to timeout on earlier frames\n");
  669. ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
  670. frames);
  671. /*
  672. * Increment the head seq# also for the skipped slots.
  673. */
  674. tid_agg_rx->head_seq_num =
  675. (tid_agg_rx->head_seq_num +
  676. skipped) & IEEE80211_SN_MASK;
  677. skipped = 0;
  678. }
  679. } else while (tid_agg_rx->reorder_buf[index]) {
  680. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  681. frames);
  682. index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  683. tid_agg_rx->ssn) %
  684. tid_agg_rx->buf_size;
  685. }
  686. if (tid_agg_rx->stored_mpdu_num) {
  687. j = index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  688. tid_agg_rx->ssn) %
  689. tid_agg_rx->buf_size;
  690. for (; j != (index - 1) % tid_agg_rx->buf_size;
  691. j = (j + 1) % tid_agg_rx->buf_size) {
  692. if (tid_agg_rx->reorder_buf[j])
  693. break;
  694. }
  695. set_release_timer:
  696. mod_timer(&tid_agg_rx->reorder_timer,
  697. tid_agg_rx->reorder_time[j] + 1 +
  698. HT_RX_REORDER_BUF_TIMEOUT);
  699. } else {
  700. del_timer(&tid_agg_rx->reorder_timer);
  701. }
  702. }
  703. /*
  704. * As this function belongs to the RX path it must be under
  705. * rcu_read_lock protection. It returns false if the frame
  706. * can be processed immediately, true if it was consumed.
  707. */
  708. static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
  709. struct tid_ampdu_rx *tid_agg_rx,
  710. struct sk_buff *skb,
  711. struct sk_buff_head *frames)
  712. {
  713. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  714. u16 sc = le16_to_cpu(hdr->seq_ctrl);
  715. u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  716. u16 head_seq_num, buf_size;
  717. int index;
  718. bool ret = true;
  719. spin_lock(&tid_agg_rx->reorder_lock);
  720. buf_size = tid_agg_rx->buf_size;
  721. head_seq_num = tid_agg_rx->head_seq_num;
  722. /* frame with out of date sequence number */
  723. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  724. dev_kfree_skb(skb);
  725. goto out;
  726. }
  727. /*
  728. * If frame the sequence number exceeds our buffering window
  729. * size release some previous frames to make room for this one.
  730. */
  731. if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
  732. head_seq_num = ieee80211_sn_inc(
  733. ieee80211_sn_sub(mpdu_seq_num, buf_size));
  734. /* release stored frames up to new head to stack */
  735. ieee80211_release_reorder_frames(sdata, tid_agg_rx,
  736. head_seq_num, frames);
  737. }
  738. /* Now the new frame is always in the range of the reordering buffer */
  739. index = ieee80211_sn_sub(mpdu_seq_num,
  740. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  741. /* check if we already stored this frame */
  742. if (tid_agg_rx->reorder_buf[index]) {
  743. dev_kfree_skb(skb);
  744. goto out;
  745. }
  746. /*
  747. * If the current MPDU is in the right order and nothing else
  748. * is stored we can process it directly, no need to buffer it.
  749. * If it is first but there's something stored, we may be able
  750. * to release frames after this one.
  751. */
  752. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  753. tid_agg_rx->stored_mpdu_num == 0) {
  754. tid_agg_rx->head_seq_num =
  755. ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  756. ret = false;
  757. goto out;
  758. }
  759. /* put the frame in the reordering buffer */
  760. tid_agg_rx->reorder_buf[index] = skb;
  761. tid_agg_rx->reorder_time[index] = jiffies;
  762. tid_agg_rx->stored_mpdu_num++;
  763. ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
  764. out:
  765. spin_unlock(&tid_agg_rx->reorder_lock);
  766. return ret;
  767. }
  768. /*
  769. * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
  770. * true if the MPDU was buffered, false if it should be processed.
  771. */
  772. static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
  773. struct sk_buff_head *frames)
  774. {
  775. struct sk_buff *skb = rx->skb;
  776. struct ieee80211_local *local = rx->local;
  777. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  778. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  779. struct sta_info *sta = rx->sta;
  780. struct tid_ampdu_rx *tid_agg_rx;
  781. u16 sc;
  782. u8 tid, ack_policy;
  783. if (!ieee80211_is_data_qos(hdr->frame_control))
  784. goto dont_reorder;
  785. /*
  786. * filter the QoS data rx stream according to
  787. * STA/TID and check if this STA/TID is on aggregation
  788. */
  789. if (!sta)
  790. goto dont_reorder;
  791. ack_policy = *ieee80211_get_qos_ctl(hdr) &
  792. IEEE80211_QOS_CTL_ACK_POLICY_MASK;
  793. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  794. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  795. if (!tid_agg_rx)
  796. goto dont_reorder;
  797. /* qos null data frames are excluded */
  798. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  799. goto dont_reorder;
  800. /* not part of a BA session */
  801. if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
  802. ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
  803. goto dont_reorder;
  804. /* not actually part of this BA session */
  805. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  806. goto dont_reorder;
  807. /* new, potentially un-ordered, ampdu frame - process it */
  808. /* reset session timer */
  809. if (tid_agg_rx->timeout)
  810. tid_agg_rx->last_rx = jiffies;
  811. /* if this mpdu is fragmented - terminate rx aggregation session */
  812. sc = le16_to_cpu(hdr->seq_ctrl);
  813. if (sc & IEEE80211_SCTL_FRAG) {
  814. skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  815. skb_queue_tail(&rx->sdata->skb_queue, skb);
  816. ieee80211_queue_work(&local->hw, &rx->sdata->work);
  817. return;
  818. }
  819. /*
  820. * No locking needed -- we will only ever process one
  821. * RX packet at a time, and thus own tid_agg_rx. All
  822. * other code manipulating it needs to (and does) make
  823. * sure that we cannot get to it any more before doing
  824. * anything with it.
  825. */
  826. if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
  827. frames))
  828. return;
  829. dont_reorder:
  830. __skb_queue_tail(frames, skb);
  831. }
  832. static ieee80211_rx_result debug_noinline
  833. ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
  834. {
  835. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  836. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  837. /*
  838. * Drop duplicate 802.11 retransmissions
  839. * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
  840. */
  841. if (rx->skb->len >= 24 && rx->sta &&
  842. !ieee80211_is_ctl(hdr->frame_control) &&
  843. !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
  844. !is_multicast_ether_addr(hdr->addr1)) {
  845. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  846. rx->sta->last_seq_ctrl[rx->seqno_idx] ==
  847. hdr->seq_ctrl)) {
  848. if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
  849. rx->local->dot11FrameDuplicateCount++;
  850. rx->sta->num_duplicates++;
  851. }
  852. return RX_DROP_UNUSABLE;
  853. } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
  854. rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
  855. }
  856. }
  857. if (unlikely(rx->skb->len < 16)) {
  858. I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
  859. return RX_DROP_MONITOR;
  860. }
  861. /* Drop disallowed frame classes based on STA auth/assoc state;
  862. * IEEE 802.11, Chap 5.5.
  863. *
  864. * mac80211 filters only based on association state, i.e. it drops
  865. * Class 3 frames from not associated stations. hostapd sends
  866. * deauth/disassoc frames when needed. In addition, hostapd is
  867. * responsible for filtering on both auth and assoc states.
  868. */
  869. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  870. return ieee80211_rx_mesh_check(rx);
  871. if (unlikely((ieee80211_is_data(hdr->frame_control) ||
  872. ieee80211_is_pspoll(hdr->frame_control)) &&
  873. rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  874. rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
  875. (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
  876. /*
  877. * accept port control frames from the AP even when it's not
  878. * yet marked ASSOC to prevent a race where we don't set the
  879. * assoc bit quickly enough before it sends the first frame
  880. */
  881. if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  882. ieee80211_is_data_present(hdr->frame_control)) {
  883. unsigned int hdrlen;
  884. __be16 ethertype;
  885. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  886. if (rx->skb->len < hdrlen + 8)
  887. return RX_DROP_MONITOR;
  888. skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
  889. if (ethertype == rx->sdata->control_port_protocol)
  890. return RX_CONTINUE;
  891. }
  892. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  893. cfg80211_rx_spurious_frame(rx->sdata->dev,
  894. hdr->addr2,
  895. GFP_ATOMIC))
  896. return RX_DROP_UNUSABLE;
  897. return RX_DROP_MONITOR;
  898. }
  899. return RX_CONTINUE;
  900. }
  901. static ieee80211_rx_result debug_noinline
  902. ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
  903. {
  904. struct ieee80211_local *local;
  905. struct ieee80211_hdr *hdr;
  906. struct sk_buff *skb;
  907. local = rx->local;
  908. skb = rx->skb;
  909. hdr = (struct ieee80211_hdr *) skb->data;
  910. if (!local->pspolling)
  911. return RX_CONTINUE;
  912. if (!ieee80211_has_fromds(hdr->frame_control))
  913. /* this is not from AP */
  914. return RX_CONTINUE;
  915. if (!ieee80211_is_data(hdr->frame_control))
  916. return RX_CONTINUE;
  917. if (!ieee80211_has_moredata(hdr->frame_control)) {
  918. /* AP has no more frames buffered for us */
  919. local->pspolling = false;
  920. return RX_CONTINUE;
  921. }
  922. /* more data bit is set, let's request a new frame from the AP */
  923. ieee80211_send_pspoll(local, rx->sdata);
  924. return RX_CONTINUE;
  925. }
  926. static void sta_ps_start(struct sta_info *sta)
  927. {
  928. struct ieee80211_sub_if_data *sdata = sta->sdata;
  929. struct ieee80211_local *local = sdata->local;
  930. struct ps_data *ps;
  931. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  932. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  933. ps = &sdata->bss->ps;
  934. else
  935. return;
  936. atomic_inc(&ps->num_sta_ps);
  937. set_sta_flag(sta, WLAN_STA_PS_STA);
  938. if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
  939. drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
  940. ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
  941. sta->sta.addr, sta->sta.aid);
  942. }
  943. static void sta_ps_end(struct sta_info *sta)
  944. {
  945. ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
  946. sta->sta.addr, sta->sta.aid);
  947. if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
  948. ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
  949. sta->sta.addr, sta->sta.aid);
  950. return;
  951. }
  952. ieee80211_sta_ps_deliver_wakeup(sta);
  953. }
  954. int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
  955. {
  956. struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
  957. bool in_ps;
  958. WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
  959. /* Don't let the same PS state be set twice */
  960. in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
  961. if ((start && in_ps) || (!start && !in_ps))
  962. return -EINVAL;
  963. if (start)
  964. sta_ps_start(sta_inf);
  965. else
  966. sta_ps_end(sta_inf);
  967. return 0;
  968. }
  969. EXPORT_SYMBOL(ieee80211_sta_ps_transition);
  970. static ieee80211_rx_result debug_noinline
  971. ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
  972. {
  973. struct ieee80211_sub_if_data *sdata = rx->sdata;
  974. struct ieee80211_hdr *hdr = (void *)rx->skb->data;
  975. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  976. int tid, ac;
  977. if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH))
  978. return RX_CONTINUE;
  979. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  980. sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
  981. return RX_CONTINUE;
  982. /*
  983. * The device handles station powersave, so don't do anything about
  984. * uAPSD and PS-Poll frames (the latter shouldn't even come up from
  985. * it to mac80211 since they're handled.)
  986. */
  987. if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
  988. return RX_CONTINUE;
  989. /*
  990. * Don't do anything if the station isn't already asleep. In
  991. * the uAPSD case, the station will probably be marked asleep,
  992. * in the PS-Poll case the station must be confused ...
  993. */
  994. if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
  995. return RX_CONTINUE;
  996. if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
  997. if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
  998. if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
  999. ieee80211_sta_ps_deliver_poll_response(rx->sta);
  1000. else
  1001. set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
  1002. }
  1003. /* Free PS Poll skb here instead of returning RX_DROP that would
  1004. * count as an dropped frame. */
  1005. dev_kfree_skb(rx->skb);
  1006. return RX_QUEUED;
  1007. } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
  1008. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1009. ieee80211_has_pm(hdr->frame_control) &&
  1010. (ieee80211_is_data_qos(hdr->frame_control) ||
  1011. ieee80211_is_qos_nullfunc(hdr->frame_control))) {
  1012. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  1013. ac = ieee802_1d_to_ac[tid & 7];
  1014. /*
  1015. * If this AC is not trigger-enabled do nothing.
  1016. *
  1017. * NB: This could/should check a separate bitmap of trigger-
  1018. * enabled queues, but for now we only implement uAPSD w/o
  1019. * TSPEC changes to the ACs, so they're always the same.
  1020. */
  1021. if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
  1022. return RX_CONTINUE;
  1023. /* if we are in a service period, do nothing */
  1024. if (test_sta_flag(rx->sta, WLAN_STA_SP))
  1025. return RX_CONTINUE;
  1026. if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
  1027. ieee80211_sta_ps_deliver_uapsd(rx->sta);
  1028. else
  1029. set_sta_flag(rx->sta, WLAN_STA_UAPSD);
  1030. }
  1031. return RX_CONTINUE;
  1032. }
  1033. static ieee80211_rx_result debug_noinline
  1034. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  1035. {
  1036. struct sta_info *sta = rx->sta;
  1037. struct sk_buff *skb = rx->skb;
  1038. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1039. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1040. int i;
  1041. if (!sta)
  1042. return RX_CONTINUE;
  1043. /*
  1044. * Update last_rx only for IBSS packets which are for the current
  1045. * BSSID and for station already AUTHORIZED to avoid keeping the
  1046. * current IBSS network alive in cases where other STAs start
  1047. * using different BSSID. This will also give the station another
  1048. * chance to restart the authentication/authorization in case
  1049. * something went wrong the first time.
  1050. */
  1051. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  1052. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  1053. NL80211_IFTYPE_ADHOC);
  1054. if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
  1055. test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
  1056. sta->last_rx = jiffies;
  1057. if (ieee80211_is_data(hdr->frame_control)) {
  1058. sta->last_rx_rate_idx = status->rate_idx;
  1059. sta->last_rx_rate_flag = status->flag;
  1060. sta->last_rx_rate_vht_nss = status->vht_nss;
  1061. }
  1062. }
  1063. } else if (!is_multicast_ether_addr(hdr->addr1)) {
  1064. /*
  1065. * Mesh beacons will update last_rx when if they are found to
  1066. * match the current local configuration when processed.
  1067. */
  1068. sta->last_rx = jiffies;
  1069. if (ieee80211_is_data(hdr->frame_control)) {
  1070. sta->last_rx_rate_idx = status->rate_idx;
  1071. sta->last_rx_rate_flag = status->flag;
  1072. sta->last_rx_rate_vht_nss = status->vht_nss;
  1073. }
  1074. }
  1075. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  1076. return RX_CONTINUE;
  1077. if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
  1078. ieee80211_sta_rx_notify(rx->sdata, hdr);
  1079. sta->rx_fragments++;
  1080. sta->rx_bytes += rx->skb->len;
  1081. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  1082. sta->last_signal = status->signal;
  1083. ewma_add(&sta->avg_signal, -status->signal);
  1084. }
  1085. if (status->chains) {
  1086. sta->chains = status->chains;
  1087. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  1088. int signal = status->chain_signal[i];
  1089. if (!(status->chains & BIT(i)))
  1090. continue;
  1091. sta->chain_signal_last[i] = signal;
  1092. ewma_add(&sta->chain_signal_avg[i], -signal);
  1093. }
  1094. }
  1095. /*
  1096. * Change STA power saving mode only at the end of a frame
  1097. * exchange sequence.
  1098. */
  1099. if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
  1100. !ieee80211_has_morefrags(hdr->frame_control) &&
  1101. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1102. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1103. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
  1104. if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1105. /*
  1106. * Ignore doze->wake transitions that are
  1107. * indicated by non-data frames, the standard
  1108. * is unclear here, but for example going to
  1109. * PS mode and then scanning would cause a
  1110. * doze->wake transition for the probe request,
  1111. * and that is clearly undesirable.
  1112. */
  1113. if (ieee80211_is_data(hdr->frame_control) &&
  1114. !ieee80211_has_pm(hdr->frame_control))
  1115. sta_ps_end(sta);
  1116. } else {
  1117. if (ieee80211_has_pm(hdr->frame_control))
  1118. sta_ps_start(sta);
  1119. }
  1120. }
  1121. /* mesh power save support */
  1122. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1123. ieee80211_mps_rx_h_sta_process(sta, hdr);
  1124. /*
  1125. * Drop (qos-)data::nullfunc frames silently, since they
  1126. * are used only to control station power saving mode.
  1127. */
  1128. if (ieee80211_is_nullfunc(hdr->frame_control) ||
  1129. ieee80211_is_qos_nullfunc(hdr->frame_control)) {
  1130. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  1131. /*
  1132. * If we receive a 4-addr nullfunc frame from a STA
  1133. * that was not moved to a 4-addr STA vlan yet send
  1134. * the event to userspace and for older hostapd drop
  1135. * the frame to the monitor interface.
  1136. */
  1137. if (ieee80211_has_a4(hdr->frame_control) &&
  1138. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1139. (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1140. !rx->sdata->u.vlan.sta))) {
  1141. if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
  1142. cfg80211_rx_unexpected_4addr_frame(
  1143. rx->sdata->dev, sta->sta.addr,
  1144. GFP_ATOMIC);
  1145. return RX_DROP_MONITOR;
  1146. }
  1147. /*
  1148. * Update counter and free packet here to avoid
  1149. * counting this as a dropped packed.
  1150. */
  1151. sta->rx_packets++;
  1152. dev_kfree_skb(rx->skb);
  1153. return RX_QUEUED;
  1154. }
  1155. return RX_CONTINUE;
  1156. } /* ieee80211_rx_h_sta_process */
  1157. static ieee80211_rx_result debug_noinline
  1158. ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
  1159. {
  1160. struct sk_buff *skb = rx->skb;
  1161. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1162. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1163. int keyidx;
  1164. int hdrlen;
  1165. ieee80211_rx_result result = RX_DROP_UNUSABLE;
  1166. struct ieee80211_key *sta_ptk = NULL;
  1167. int mmie_keyidx = -1;
  1168. __le16 fc;
  1169. /*
  1170. * Key selection 101
  1171. *
  1172. * There are four types of keys:
  1173. * - GTK (group keys)
  1174. * - IGTK (group keys for management frames)
  1175. * - PTK (pairwise keys)
  1176. * - STK (station-to-station pairwise keys)
  1177. *
  1178. * When selecting a key, we have to distinguish between multicast
  1179. * (including broadcast) and unicast frames, the latter can only
  1180. * use PTKs and STKs while the former always use GTKs and IGTKs.
  1181. * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
  1182. * unicast frames can also use key indices like GTKs. Hence, if we
  1183. * don't have a PTK/STK we check the key index for a WEP key.
  1184. *
  1185. * Note that in a regular BSS, multicast frames are sent by the
  1186. * AP only, associated stations unicast the frame to the AP first
  1187. * which then multicasts it on their behalf.
  1188. *
  1189. * There is also a slight problem in IBSS mode: GTKs are negotiated
  1190. * with each station, that is something we don't currently handle.
  1191. * The spec seems to expect that one negotiates the same key with
  1192. * every station but there's no such requirement; VLANs could be
  1193. * possible.
  1194. */
  1195. /*
  1196. * No point in finding a key and decrypting if the frame is neither
  1197. * addressed to us nor a multicast frame.
  1198. */
  1199. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  1200. return RX_CONTINUE;
  1201. /* start without a key */
  1202. rx->key = NULL;
  1203. if (rx->sta)
  1204. sta_ptk = rcu_dereference(rx->sta->ptk);
  1205. fc = hdr->frame_control;
  1206. if (!ieee80211_has_protected(fc))
  1207. mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
  1208. if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
  1209. rx->key = sta_ptk;
  1210. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1211. (status->flag & RX_FLAG_IV_STRIPPED))
  1212. return RX_CONTINUE;
  1213. /* Skip decryption if the frame is not protected. */
  1214. if (!ieee80211_has_protected(fc))
  1215. return RX_CONTINUE;
  1216. } else if (mmie_keyidx >= 0) {
  1217. /* Broadcast/multicast robust management frame / BIP */
  1218. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1219. (status->flag & RX_FLAG_IV_STRIPPED))
  1220. return RX_CONTINUE;
  1221. if (mmie_keyidx < NUM_DEFAULT_KEYS ||
  1222. mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  1223. return RX_DROP_MONITOR; /* unexpected BIP keyidx */
  1224. if (rx->sta)
  1225. rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
  1226. if (!rx->key)
  1227. rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
  1228. } else if (!ieee80211_has_protected(fc)) {
  1229. /*
  1230. * The frame was not protected, so skip decryption. However, we
  1231. * need to set rx->key if there is a key that could have been
  1232. * used so that the frame may be dropped if encryption would
  1233. * have been expected.
  1234. */
  1235. struct ieee80211_key *key = NULL;
  1236. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1237. int i;
  1238. if (ieee80211_is_mgmt(fc) &&
  1239. is_multicast_ether_addr(hdr->addr1) &&
  1240. (key = rcu_dereference(rx->sdata->default_mgmt_key)))
  1241. rx->key = key;
  1242. else {
  1243. if (rx->sta) {
  1244. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1245. key = rcu_dereference(rx->sta->gtk[i]);
  1246. if (key)
  1247. break;
  1248. }
  1249. }
  1250. if (!key) {
  1251. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1252. key = rcu_dereference(sdata->keys[i]);
  1253. if (key)
  1254. break;
  1255. }
  1256. }
  1257. if (key)
  1258. rx->key = key;
  1259. }
  1260. return RX_CONTINUE;
  1261. } else {
  1262. u8 keyid;
  1263. /*
  1264. * The device doesn't give us the IV so we won't be
  1265. * able to look up the key. That's ok though, we
  1266. * don't need to decrypt the frame, we just won't
  1267. * be able to keep statistics accurate.
  1268. * Except for key threshold notifications, should
  1269. * we somehow allow the driver to tell us which key
  1270. * the hardware used if this flag is set?
  1271. */
  1272. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1273. (status->flag & RX_FLAG_IV_STRIPPED))
  1274. return RX_CONTINUE;
  1275. hdrlen = ieee80211_hdrlen(fc);
  1276. if (rx->skb->len < 8 + hdrlen)
  1277. return RX_DROP_UNUSABLE; /* TODO: count this? */
  1278. /*
  1279. * no need to call ieee80211_wep_get_keyidx,
  1280. * it verifies a bunch of things we've done already
  1281. */
  1282. skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
  1283. keyidx = keyid >> 6;
  1284. /* check per-station GTK first, if multicast packet */
  1285. if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
  1286. rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
  1287. /* if not found, try default key */
  1288. if (!rx->key) {
  1289. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  1290. /*
  1291. * RSNA-protected unicast frames should always be
  1292. * sent with pairwise or station-to-station keys,
  1293. * but for WEP we allow using a key index as well.
  1294. */
  1295. if (rx->key &&
  1296. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  1297. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
  1298. !is_multicast_ether_addr(hdr->addr1))
  1299. rx->key = NULL;
  1300. }
  1301. }
  1302. if (rx->key) {
  1303. if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
  1304. return RX_DROP_MONITOR;
  1305. rx->key->tx_rx_count++;
  1306. /* TODO: add threshold stuff again */
  1307. } else {
  1308. return RX_DROP_MONITOR;
  1309. }
  1310. switch (rx->key->conf.cipher) {
  1311. case WLAN_CIPHER_SUITE_WEP40:
  1312. case WLAN_CIPHER_SUITE_WEP104:
  1313. result = ieee80211_crypto_wep_decrypt(rx);
  1314. break;
  1315. case WLAN_CIPHER_SUITE_TKIP:
  1316. result = ieee80211_crypto_tkip_decrypt(rx);
  1317. break;
  1318. case WLAN_CIPHER_SUITE_CCMP:
  1319. result = ieee80211_crypto_ccmp_decrypt(rx);
  1320. break;
  1321. case WLAN_CIPHER_SUITE_AES_CMAC:
  1322. result = ieee80211_crypto_aes_cmac_decrypt(rx);
  1323. break;
  1324. default:
  1325. /*
  1326. * We can reach here only with HW-only algorithms
  1327. * but why didn't it decrypt the frame?!
  1328. */
  1329. return RX_DROP_UNUSABLE;
  1330. }
  1331. /* the hdr variable is invalid after the decrypt handlers */
  1332. /* either the frame has been decrypted or will be dropped */
  1333. status->flag |= RX_FLAG_DECRYPTED;
  1334. return result;
  1335. }
  1336. static inline struct ieee80211_fragment_entry *
  1337. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  1338. unsigned int frag, unsigned int seq, int rx_queue,
  1339. struct sk_buff **skb)
  1340. {
  1341. struct ieee80211_fragment_entry *entry;
  1342. entry = &sdata->fragments[sdata->fragment_next++];
  1343. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  1344. sdata->fragment_next = 0;
  1345. if (!skb_queue_empty(&entry->skb_list))
  1346. __skb_queue_purge(&entry->skb_list);
  1347. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  1348. *skb = NULL;
  1349. entry->first_frag_time = jiffies;
  1350. entry->seq = seq;
  1351. entry->rx_queue = rx_queue;
  1352. entry->last_frag = frag;
  1353. entry->ccmp = 0;
  1354. entry->extra_len = 0;
  1355. return entry;
  1356. }
  1357. static inline struct ieee80211_fragment_entry *
  1358. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  1359. unsigned int frag, unsigned int seq,
  1360. int rx_queue, struct ieee80211_hdr *hdr)
  1361. {
  1362. struct ieee80211_fragment_entry *entry;
  1363. int i, idx;
  1364. idx = sdata->fragment_next;
  1365. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  1366. struct ieee80211_hdr *f_hdr;
  1367. idx--;
  1368. if (idx < 0)
  1369. idx = IEEE80211_FRAGMENT_MAX - 1;
  1370. entry = &sdata->fragments[idx];
  1371. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  1372. entry->rx_queue != rx_queue ||
  1373. entry->last_frag + 1 != frag)
  1374. continue;
  1375. f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
  1376. /*
  1377. * Check ftype and addresses are equal, else check next fragment
  1378. */
  1379. if (((hdr->frame_control ^ f_hdr->frame_control) &
  1380. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  1381. !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
  1382. !ether_addr_equal(hdr->addr2, f_hdr->addr2))
  1383. continue;
  1384. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  1385. __skb_queue_purge(&entry->skb_list);
  1386. continue;
  1387. }
  1388. return entry;
  1389. }
  1390. return NULL;
  1391. }
  1392. static ieee80211_rx_result debug_noinline
  1393. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  1394. {
  1395. struct ieee80211_hdr *hdr;
  1396. u16 sc;
  1397. __le16 fc;
  1398. unsigned int frag, seq;
  1399. struct ieee80211_fragment_entry *entry;
  1400. struct sk_buff *skb;
  1401. struct ieee80211_rx_status *status;
  1402. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1403. fc = hdr->frame_control;
  1404. if (ieee80211_is_ctl(fc))
  1405. return RX_CONTINUE;
  1406. sc = le16_to_cpu(hdr->seq_ctrl);
  1407. frag = sc & IEEE80211_SCTL_FRAG;
  1408. if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
  1409. is_multicast_ether_addr(hdr->addr1))) {
  1410. /* not fragmented */
  1411. goto out;
  1412. }
  1413. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  1414. if (skb_linearize(rx->skb))
  1415. return RX_DROP_UNUSABLE;
  1416. /*
  1417. * skb_linearize() might change the skb->data and
  1418. * previously cached variables (in this case, hdr) need to
  1419. * be refreshed with the new data.
  1420. */
  1421. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1422. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1423. if (frag == 0) {
  1424. /* This is the first fragment of a new frame. */
  1425. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  1426. rx->seqno_idx, &(rx->skb));
  1427. if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
  1428. ieee80211_has_protected(fc)) {
  1429. int queue = rx->security_idx;
  1430. /* Store CCMP PN so that we can verify that the next
  1431. * fragment has a sequential PN value. */
  1432. entry->ccmp = 1;
  1433. memcpy(entry->last_pn,
  1434. rx->key->u.ccmp.rx_pn[queue],
  1435. IEEE80211_CCMP_PN_LEN);
  1436. }
  1437. return RX_QUEUED;
  1438. }
  1439. /* This is a fragment for a frame that should already be pending in
  1440. * fragment cache. Add this fragment to the end of the pending entry.
  1441. */
  1442. entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
  1443. rx->seqno_idx, hdr);
  1444. if (!entry) {
  1445. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1446. return RX_DROP_MONITOR;
  1447. }
  1448. /* Verify that MPDUs within one MSDU have sequential PN values.
  1449. * (IEEE 802.11i, 8.3.3.4.5) */
  1450. if (entry->ccmp) {
  1451. int i;
  1452. u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
  1453. int queue;
  1454. if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
  1455. return RX_DROP_UNUSABLE;
  1456. memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
  1457. for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
  1458. pn[i]++;
  1459. if (pn[i])
  1460. break;
  1461. }
  1462. queue = rx->security_idx;
  1463. rpn = rx->key->u.ccmp.rx_pn[queue];
  1464. if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
  1465. return RX_DROP_UNUSABLE;
  1466. memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
  1467. }
  1468. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  1469. __skb_queue_tail(&entry->skb_list, rx->skb);
  1470. entry->last_frag = frag;
  1471. entry->extra_len += rx->skb->len;
  1472. if (ieee80211_has_morefrags(fc)) {
  1473. rx->skb = NULL;
  1474. return RX_QUEUED;
  1475. }
  1476. rx->skb = __skb_dequeue(&entry->skb_list);
  1477. if (skb_tailroom(rx->skb) < entry->extra_len) {
  1478. I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
  1479. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  1480. GFP_ATOMIC))) {
  1481. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1482. __skb_queue_purge(&entry->skb_list);
  1483. return RX_DROP_UNUSABLE;
  1484. }
  1485. }
  1486. while ((skb = __skb_dequeue(&entry->skb_list))) {
  1487. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  1488. dev_kfree_skb(skb);
  1489. }
  1490. /* Complete frame has been reassembled - process it now */
  1491. status = IEEE80211_SKB_RXCB(rx->skb);
  1492. status->rx_flags |= IEEE80211_RX_FRAGMENTED;
  1493. out:
  1494. if (rx->sta)
  1495. rx->sta->rx_packets++;
  1496. if (is_multicast_ether_addr(hdr->addr1))
  1497. rx->local->dot11MulticastReceivedFrameCount++;
  1498. else
  1499. ieee80211_led_rx(rx->local);
  1500. return RX_CONTINUE;
  1501. }
  1502. static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  1503. {
  1504. if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
  1505. return -EACCES;
  1506. return 0;
  1507. }
  1508. static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  1509. {
  1510. struct sk_buff *skb = rx->skb;
  1511. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1512. /*
  1513. * Pass through unencrypted frames if the hardware has
  1514. * decrypted them already.
  1515. */
  1516. if (status->flag & RX_FLAG_DECRYPTED)
  1517. return 0;
  1518. /* Drop unencrypted frames if key is set. */
  1519. if (unlikely(!ieee80211_has_protected(fc) &&
  1520. !ieee80211_is_nullfunc(fc) &&
  1521. ieee80211_is_data(fc) &&
  1522. (rx->key || rx->sdata->drop_unencrypted)))
  1523. return -EACCES;
  1524. return 0;
  1525. }
  1526. static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
  1527. {
  1528. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1529. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1530. __le16 fc = hdr->frame_control;
  1531. /*
  1532. * Pass through unencrypted frames if the hardware has
  1533. * decrypted them already.
  1534. */
  1535. if (status->flag & RX_FLAG_DECRYPTED)
  1536. return 0;
  1537. if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
  1538. if (unlikely(!ieee80211_has_protected(fc) &&
  1539. ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
  1540. rx->key)) {
  1541. if (ieee80211_is_deauth(fc) ||
  1542. ieee80211_is_disassoc(fc))
  1543. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1544. rx->skb->data,
  1545. rx->skb->len);
  1546. return -EACCES;
  1547. }
  1548. /* BIP does not use Protected field, so need to check MMIE */
  1549. if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
  1550. ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
  1551. if (ieee80211_is_deauth(fc) ||
  1552. ieee80211_is_disassoc(fc))
  1553. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1554. rx->skb->data,
  1555. rx->skb->len);
  1556. return -EACCES;
  1557. }
  1558. /*
  1559. * When using MFP, Action frames are not allowed prior to
  1560. * having configured keys.
  1561. */
  1562. if (unlikely(ieee80211_is_action(fc) && !rx->key &&
  1563. ieee80211_is_robust_mgmt_frame(
  1564. (struct ieee80211_hdr *) rx->skb->data)))
  1565. return -EACCES;
  1566. }
  1567. return 0;
  1568. }
  1569. static int
  1570. __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
  1571. {
  1572. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1573. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1574. bool check_port_control = false;
  1575. struct ethhdr *ehdr;
  1576. int ret;
  1577. *port_control = false;
  1578. if (ieee80211_has_a4(hdr->frame_control) &&
  1579. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
  1580. return -1;
  1581. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1582. !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
  1583. if (!sdata->u.mgd.use_4addr)
  1584. return -1;
  1585. else
  1586. check_port_control = true;
  1587. }
  1588. if (is_multicast_ether_addr(hdr->addr1) &&
  1589. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
  1590. return -1;
  1591. ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
  1592. if (ret < 0)
  1593. return ret;
  1594. ehdr = (struct ethhdr *) rx->skb->data;
  1595. if (ehdr->h_proto == rx->sdata->control_port_protocol)
  1596. *port_control = true;
  1597. else if (check_port_control)
  1598. return -1;
  1599. return 0;
  1600. }
  1601. /*
  1602. * requires that rx->skb is a frame with ethernet header
  1603. */
  1604. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  1605. {
  1606. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  1607. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1608. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1609. /*
  1610. * Allow EAPOL frames to us/the PAE group address regardless
  1611. * of whether the frame was encrypted or not.
  1612. */
  1613. if (ehdr->h_proto == rx->sdata->control_port_protocol &&
  1614. (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
  1615. ether_addr_equal(ehdr->h_dest, pae_group_addr)))
  1616. return true;
  1617. if (ieee80211_802_1x_port_control(rx) ||
  1618. ieee80211_drop_unencrypted(rx, fc))
  1619. return false;
  1620. return true;
  1621. }
  1622. /*
  1623. * requires that rx->skb is a frame with ethernet header
  1624. */
  1625. static void
  1626. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  1627. {
  1628. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1629. struct net_device *dev = sdata->dev;
  1630. struct sk_buff *skb, *xmit_skb;
  1631. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1632. struct sta_info *dsta;
  1633. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1634. skb = rx->skb;
  1635. xmit_skb = NULL;
  1636. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1637. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1638. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  1639. (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
  1640. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
  1641. if (is_multicast_ether_addr(ehdr->h_dest)) {
  1642. /*
  1643. * send multicast frames both to higher layers in
  1644. * local net stack and back to the wireless medium
  1645. */
  1646. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1647. if (!xmit_skb)
  1648. net_info_ratelimited("%s: failed to clone multicast frame\n",
  1649. dev->name);
  1650. } else {
  1651. dsta = sta_info_get(sdata, skb->data);
  1652. if (dsta) {
  1653. /*
  1654. * The destination station is associated to
  1655. * this AP (in this VLAN), so send the frame
  1656. * directly to it and do not pass it to local
  1657. * net stack.
  1658. */
  1659. xmit_skb = skb;
  1660. skb = NULL;
  1661. }
  1662. }
  1663. }
  1664. if (skb) {
  1665. int align __maybe_unused;
  1666. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1667. /*
  1668. * 'align' will only take the values 0 or 2 here
  1669. * since all frames are required to be aligned
  1670. * to 2-byte boundaries when being passed to
  1671. * mac80211; the code here works just as well if
  1672. * that isn't true, but mac80211 assumes it can
  1673. * access fields as 2-byte aligned (e.g. for
  1674. * compare_ether_addr)
  1675. */
  1676. align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
  1677. if (align) {
  1678. if (WARN_ON(skb_headroom(skb) < 3)) {
  1679. dev_kfree_skb(skb);
  1680. skb = NULL;
  1681. } else {
  1682. u8 *data = skb->data;
  1683. size_t len = skb_headlen(skb);
  1684. skb->data -= align;
  1685. memmove(skb->data, data, len);
  1686. skb_set_tail_pointer(skb, len);
  1687. }
  1688. }
  1689. #endif
  1690. if (skb) {
  1691. /* deliver to local stack */
  1692. skb->protocol = eth_type_trans(skb, dev);
  1693. memset(skb->cb, 0, sizeof(skb->cb));
  1694. netif_receive_skb(skb);
  1695. }
  1696. }
  1697. if (xmit_skb) {
  1698. /*
  1699. * Send to wireless media and increase priority by 256 to
  1700. * keep the received priority instead of reclassifying
  1701. * the frame (see cfg80211_classify8021d).
  1702. */
  1703. xmit_skb->priority += 256;
  1704. xmit_skb->protocol = htons(ETH_P_802_3);
  1705. skb_reset_network_header(xmit_skb);
  1706. skb_reset_mac_header(xmit_skb);
  1707. dev_queue_xmit(xmit_skb);
  1708. }
  1709. }
  1710. static ieee80211_rx_result debug_noinline
  1711. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  1712. {
  1713. struct net_device *dev = rx->sdata->dev;
  1714. struct sk_buff *skb = rx->skb;
  1715. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1716. __le16 fc = hdr->frame_control;
  1717. struct sk_buff_head frame_list;
  1718. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1719. if (unlikely(!ieee80211_is_data(fc)))
  1720. return RX_CONTINUE;
  1721. if (unlikely(!ieee80211_is_data_present(fc)))
  1722. return RX_DROP_MONITOR;
  1723. if (!(status->rx_flags & IEEE80211_RX_AMSDU))
  1724. return RX_CONTINUE;
  1725. if (ieee80211_has_a4(hdr->frame_control) &&
  1726. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1727. !rx->sdata->u.vlan.sta)
  1728. return RX_DROP_UNUSABLE;
  1729. if (is_multicast_ether_addr(hdr->addr1) &&
  1730. ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1731. rx->sdata->u.vlan.sta) ||
  1732. (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  1733. rx->sdata->u.mgd.use_4addr)))
  1734. return RX_DROP_UNUSABLE;
  1735. skb->dev = dev;
  1736. __skb_queue_head_init(&frame_list);
  1737. if (skb_linearize(skb))
  1738. return RX_DROP_UNUSABLE;
  1739. ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
  1740. rx->sdata->vif.type,
  1741. rx->local->hw.extra_tx_headroom, true);
  1742. while (!skb_queue_empty(&frame_list)) {
  1743. rx->skb = __skb_dequeue(&frame_list);
  1744. if (!ieee80211_frame_allowed(rx, fc)) {
  1745. dev_kfree_skb(rx->skb);
  1746. continue;
  1747. }
  1748. dev->stats.rx_packets++;
  1749. dev->stats.rx_bytes += rx->skb->len;
  1750. ieee80211_deliver_skb(rx);
  1751. }
  1752. return RX_QUEUED;
  1753. }
  1754. #ifdef CONFIG_MAC80211_MESH
  1755. static ieee80211_rx_result
  1756. ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
  1757. {
  1758. struct ieee80211_hdr *fwd_hdr, *hdr;
  1759. struct ieee80211_tx_info *info;
  1760. struct ieee80211s_hdr *mesh_hdr;
  1761. struct sk_buff *skb = rx->skb, *fwd_skb;
  1762. struct ieee80211_local *local = rx->local;
  1763. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1764. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1765. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1766. __le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_NOFORWARD);
  1767. u16 q, hdrlen;
  1768. hdr = (struct ieee80211_hdr *) skb->data;
  1769. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1770. /* make sure fixed part of mesh header is there, also checks skb len */
  1771. if (!pskb_may_pull(rx->skb, hdrlen + 6))
  1772. return RX_DROP_MONITOR;
  1773. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  1774. /* make sure full mesh header is there, also checks skb len */
  1775. if (!pskb_may_pull(rx->skb,
  1776. hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
  1777. return RX_DROP_MONITOR;
  1778. /* reload pointers */
  1779. hdr = (struct ieee80211_hdr *) skb->data;
  1780. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  1781. /* frame is in RMC, don't forward */
  1782. if (ieee80211_is_data(hdr->frame_control) &&
  1783. is_multicast_ether_addr(hdr->addr1) &&
  1784. mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
  1785. return RX_DROP_MONITOR;
  1786. if (!ieee80211_is_data(hdr->frame_control) ||
  1787. !(status->rx_flags & IEEE80211_RX_RA_MATCH))
  1788. return RX_CONTINUE;
  1789. if (!mesh_hdr->ttl)
  1790. return RX_DROP_MONITOR;
  1791. if (mesh_hdr->flags & MESH_FLAGS_AE) {
  1792. struct mesh_path *mppath;
  1793. char *proxied_addr;
  1794. char *mpp_addr;
  1795. if (is_multicast_ether_addr(hdr->addr1)) {
  1796. mpp_addr = hdr->addr3;
  1797. proxied_addr = mesh_hdr->eaddr1;
  1798. } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
  1799. /* has_a4 already checked in ieee80211_rx_mesh_check */
  1800. mpp_addr = hdr->addr4;
  1801. proxied_addr = mesh_hdr->eaddr2;
  1802. } else {
  1803. return RX_DROP_MONITOR;
  1804. }
  1805. rcu_read_lock();
  1806. mppath = mpp_path_lookup(sdata, proxied_addr);
  1807. if (!mppath) {
  1808. mpp_path_add(sdata, proxied_addr, mpp_addr);
  1809. } else {
  1810. spin_lock_bh(&mppath->state_lock);
  1811. if (!ether_addr_equal(mppath->mpp, mpp_addr))
  1812. memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
  1813. spin_unlock_bh(&mppath->state_lock);
  1814. }
  1815. rcu_read_unlock();
  1816. }
  1817. /* Frame has reached destination. Don't forward */
  1818. if (!is_multicast_ether_addr(hdr->addr1) &&
  1819. ether_addr_equal(sdata->vif.addr, hdr->addr3))
  1820. return RX_CONTINUE;
  1821. q = ieee80211_select_queue_80211(sdata, skb, hdr);
  1822. if (ieee80211_queue_stopped(&local->hw, q)) {
  1823. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
  1824. return RX_DROP_MONITOR;
  1825. }
  1826. skb_set_queue_mapping(skb, q);
  1827. if (!--mesh_hdr->ttl) {
  1828. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
  1829. goto out;
  1830. }
  1831. if (!ifmsh->mshcfg.dot11MeshForwarding)
  1832. goto out;
  1833. fwd_skb = skb_copy(skb, GFP_ATOMIC);
  1834. if (!fwd_skb) {
  1835. net_info_ratelimited("%s: failed to clone mesh frame\n",
  1836. sdata->name);
  1837. goto out;
  1838. }
  1839. fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
  1840. fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
  1841. info = IEEE80211_SKB_CB(fwd_skb);
  1842. memset(info, 0, sizeof(*info));
  1843. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  1844. info->control.vif = &rx->sdata->vif;
  1845. info->control.jiffies = jiffies;
  1846. if (is_multicast_ether_addr(fwd_hdr->addr1)) {
  1847. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
  1848. memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
  1849. /* update power mode indication when forwarding */
  1850. ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
  1851. } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
  1852. /* mesh power mode flags updated in mesh_nexthop_lookup */
  1853. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
  1854. } else {
  1855. /* unable to resolve next hop */
  1856. mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
  1857. fwd_hdr->addr3, 0, reason, fwd_hdr->addr2);
  1858. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
  1859. kfree_skb(fwd_skb);
  1860. return RX_DROP_MONITOR;
  1861. }
  1862. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
  1863. ieee80211_add_pending_skb(local, fwd_skb);
  1864. out:
  1865. if (is_multicast_ether_addr(hdr->addr1) ||
  1866. sdata->dev->flags & IFF_PROMISC)
  1867. return RX_CONTINUE;
  1868. else
  1869. return RX_DROP_MONITOR;
  1870. }
  1871. #endif
  1872. static ieee80211_rx_result debug_noinline
  1873. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  1874. {
  1875. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1876. struct ieee80211_local *local = rx->local;
  1877. struct net_device *dev = sdata->dev;
  1878. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1879. __le16 fc = hdr->frame_control;
  1880. bool port_control;
  1881. int err;
  1882. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  1883. return RX_CONTINUE;
  1884. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  1885. return RX_DROP_MONITOR;
  1886. /*
  1887. * Send unexpected-4addr-frame event to hostapd. For older versions,
  1888. * also drop the frame to cooked monitor interfaces.
  1889. */
  1890. if (ieee80211_has_a4(hdr->frame_control) &&
  1891. sdata->vif.type == NL80211_IFTYPE_AP) {
  1892. if (rx->sta &&
  1893. !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
  1894. cfg80211_rx_unexpected_4addr_frame(
  1895. rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
  1896. return RX_DROP_MONITOR;
  1897. }
  1898. err = __ieee80211_data_to_8023(rx, &port_control);
  1899. if (unlikely(err))
  1900. return RX_DROP_UNUSABLE;
  1901. if (!ieee80211_frame_allowed(rx, fc))
  1902. return RX_DROP_MONITOR;
  1903. if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1904. unlikely(port_control) && sdata->bss) {
  1905. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  1906. u.ap);
  1907. dev = sdata->dev;
  1908. rx->sdata = sdata;
  1909. }
  1910. rx->skb->dev = dev;
  1911. dev->stats.rx_packets++;
  1912. dev->stats.rx_bytes += rx->skb->len;
  1913. if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
  1914. !is_multicast_ether_addr(
  1915. ((struct ethhdr *)rx->skb->data)->h_dest) &&
  1916. (!local->scanning &&
  1917. !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
  1918. mod_timer(&local->dynamic_ps_timer, jiffies +
  1919. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  1920. }
  1921. ieee80211_deliver_skb(rx);
  1922. return RX_QUEUED;
  1923. }
  1924. static ieee80211_rx_result debug_noinline
  1925. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
  1926. {
  1927. struct sk_buff *skb = rx->skb;
  1928. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  1929. struct tid_ampdu_rx *tid_agg_rx;
  1930. u16 start_seq_num;
  1931. u16 tid;
  1932. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  1933. return RX_CONTINUE;
  1934. if (ieee80211_is_back_req(bar->frame_control)) {
  1935. struct {
  1936. __le16 control, start_seq_num;
  1937. } __packed bar_data;
  1938. if (!rx->sta)
  1939. return RX_DROP_MONITOR;
  1940. if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
  1941. &bar_data, sizeof(bar_data)))
  1942. return RX_DROP_MONITOR;
  1943. tid = le16_to_cpu(bar_data.control) >> 12;
  1944. tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
  1945. if (!tid_agg_rx)
  1946. return RX_DROP_MONITOR;
  1947. start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
  1948. /* reset session timer */
  1949. if (tid_agg_rx->timeout)
  1950. mod_timer(&tid_agg_rx->session_timer,
  1951. TU_TO_EXP_TIME(tid_agg_rx->timeout));
  1952. spin_lock(&tid_agg_rx->reorder_lock);
  1953. /* release stored frames up to start of BAR */
  1954. ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
  1955. start_seq_num, frames);
  1956. spin_unlock(&tid_agg_rx->reorder_lock);
  1957. kfree_skb(skb);
  1958. return RX_QUEUED;
  1959. }
  1960. /*
  1961. * After this point, we only want management frames,
  1962. * so we can drop all remaining control frames to
  1963. * cooked monitor interfaces.
  1964. */
  1965. return RX_DROP_MONITOR;
  1966. }
  1967. static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
  1968. struct ieee80211_mgmt *mgmt,
  1969. size_t len)
  1970. {
  1971. struct ieee80211_local *local = sdata->local;
  1972. struct sk_buff *skb;
  1973. struct ieee80211_mgmt *resp;
  1974. if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
  1975. /* Not to own unicast address */
  1976. return;
  1977. }
  1978. if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
  1979. !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
  1980. /* Not from the current AP or not associated yet. */
  1981. return;
  1982. }
  1983. if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
  1984. /* Too short SA Query request frame */
  1985. return;
  1986. }
  1987. skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
  1988. if (skb == NULL)
  1989. return;
  1990. skb_reserve(skb, local->hw.extra_tx_headroom);
  1991. resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
  1992. memset(resp, 0, 24);
  1993. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  1994. memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
  1995. memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1996. resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1997. IEEE80211_STYPE_ACTION);
  1998. skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
  1999. resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
  2000. resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
  2001. memcpy(resp->u.action.u.sa_query.trans_id,
  2002. mgmt->u.action.u.sa_query.trans_id,
  2003. WLAN_SA_QUERY_TR_ID_LEN);
  2004. ieee80211_tx_skb(sdata, skb);
  2005. }
  2006. static ieee80211_rx_result debug_noinline
  2007. ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
  2008. {
  2009. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2010. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2011. /*
  2012. * From here on, look only at management frames.
  2013. * Data and control frames are already handled,
  2014. * and unknown (reserved) frames are useless.
  2015. */
  2016. if (rx->skb->len < 24)
  2017. return RX_DROP_MONITOR;
  2018. if (!ieee80211_is_mgmt(mgmt->frame_control))
  2019. return RX_DROP_MONITOR;
  2020. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  2021. ieee80211_is_beacon(mgmt->frame_control) &&
  2022. !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
  2023. int sig = 0;
  2024. if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  2025. sig = status->signal;
  2026. cfg80211_report_obss_beacon(rx->local->hw.wiphy,
  2027. rx->skb->data, rx->skb->len,
  2028. status->freq, sig);
  2029. rx->flags |= IEEE80211_RX_BEACON_REPORTED;
  2030. }
  2031. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  2032. return RX_DROP_MONITOR;
  2033. if (ieee80211_drop_unencrypted_mgmt(rx))
  2034. return RX_DROP_UNUSABLE;
  2035. return RX_CONTINUE;
  2036. }
  2037. static ieee80211_rx_result debug_noinline
  2038. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  2039. {
  2040. struct ieee80211_local *local = rx->local;
  2041. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2042. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2043. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2044. int len = rx->skb->len;
  2045. if (!ieee80211_is_action(mgmt->frame_control))
  2046. return RX_CONTINUE;
  2047. /* drop too small frames */
  2048. if (len < IEEE80211_MIN_ACTION_SIZE)
  2049. return RX_DROP_UNUSABLE;
  2050. if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
  2051. mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
  2052. mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
  2053. return RX_DROP_UNUSABLE;
  2054. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  2055. return RX_DROP_UNUSABLE;
  2056. switch (mgmt->u.action.category) {
  2057. case WLAN_CATEGORY_HT:
  2058. /* reject HT action frames from stations not supporting HT */
  2059. if (!rx->sta->sta.ht_cap.ht_supported)
  2060. goto invalid;
  2061. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2062. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2063. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2064. sdata->vif.type != NL80211_IFTYPE_AP &&
  2065. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2066. break;
  2067. /* verify action & smps_control/chanwidth are present */
  2068. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2069. goto invalid;
  2070. switch (mgmt->u.action.u.ht_smps.action) {
  2071. case WLAN_HT_ACTION_SMPS: {
  2072. struct ieee80211_supported_band *sband;
  2073. enum ieee80211_smps_mode smps_mode;
  2074. /* convert to HT capability */
  2075. switch (mgmt->u.action.u.ht_smps.smps_control) {
  2076. case WLAN_HT_SMPS_CONTROL_DISABLED:
  2077. smps_mode = IEEE80211_SMPS_OFF;
  2078. break;
  2079. case WLAN_HT_SMPS_CONTROL_STATIC:
  2080. smps_mode = IEEE80211_SMPS_STATIC;
  2081. break;
  2082. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  2083. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2084. break;
  2085. default:
  2086. goto invalid;
  2087. }
  2088. /* if no change do nothing */
  2089. if (rx->sta->sta.smps_mode == smps_mode)
  2090. goto handled;
  2091. rx->sta->sta.smps_mode = smps_mode;
  2092. sband = rx->local->hw.wiphy->bands[status->band];
  2093. rate_control_rate_update(local, sband, rx->sta,
  2094. IEEE80211_RC_SMPS_CHANGED);
  2095. goto handled;
  2096. }
  2097. case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
  2098. struct ieee80211_supported_band *sband;
  2099. u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
  2100. enum ieee80211_sta_rx_bandwidth new_bw;
  2101. /* If it doesn't support 40 MHz it can't change ... */
  2102. if (!(rx->sta->sta.ht_cap.cap &
  2103. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  2104. goto handled;
  2105. if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
  2106. new_bw = IEEE80211_STA_RX_BW_20;
  2107. else
  2108. new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
  2109. if (rx->sta->sta.bandwidth == new_bw)
  2110. goto handled;
  2111. sband = rx->local->hw.wiphy->bands[status->band];
  2112. rate_control_rate_update(local, sband, rx->sta,
  2113. IEEE80211_RC_BW_CHANGED);
  2114. goto handled;
  2115. }
  2116. default:
  2117. goto invalid;
  2118. }
  2119. break;
  2120. case WLAN_CATEGORY_PUBLIC:
  2121. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2122. goto invalid;
  2123. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2124. break;
  2125. if (!rx->sta)
  2126. break;
  2127. if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
  2128. break;
  2129. if (mgmt->u.action.u.ext_chan_switch.action_code !=
  2130. WLAN_PUB_ACTION_EXT_CHANSW_ANN)
  2131. break;
  2132. if (len < offsetof(struct ieee80211_mgmt,
  2133. u.action.u.ext_chan_switch.variable))
  2134. goto invalid;
  2135. goto queue;
  2136. case WLAN_CATEGORY_VHT:
  2137. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2138. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2139. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2140. sdata->vif.type != NL80211_IFTYPE_AP &&
  2141. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2142. break;
  2143. /* verify action code is present */
  2144. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2145. goto invalid;
  2146. switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
  2147. case WLAN_VHT_ACTION_OPMODE_NOTIF: {
  2148. u8 opmode;
  2149. /* verify opmode is present */
  2150. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2151. goto invalid;
  2152. opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
  2153. ieee80211_vht_handle_opmode(rx->sdata, rx->sta,
  2154. opmode, status->band,
  2155. false);
  2156. goto handled;
  2157. }
  2158. default:
  2159. break;
  2160. }
  2161. break;
  2162. case WLAN_CATEGORY_BACK:
  2163. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2164. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2165. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2166. sdata->vif.type != NL80211_IFTYPE_AP &&
  2167. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2168. break;
  2169. /* verify action_code is present */
  2170. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2171. break;
  2172. switch (mgmt->u.action.u.addba_req.action_code) {
  2173. case WLAN_ACTION_ADDBA_REQ:
  2174. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2175. sizeof(mgmt->u.action.u.addba_req)))
  2176. goto invalid;
  2177. break;
  2178. case WLAN_ACTION_ADDBA_RESP:
  2179. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2180. sizeof(mgmt->u.action.u.addba_resp)))
  2181. goto invalid;
  2182. break;
  2183. case WLAN_ACTION_DELBA:
  2184. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2185. sizeof(mgmt->u.action.u.delba)))
  2186. goto invalid;
  2187. break;
  2188. default:
  2189. goto invalid;
  2190. }
  2191. goto queue;
  2192. case WLAN_CATEGORY_SPECTRUM_MGMT:
  2193. /* verify action_code is present */
  2194. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2195. break;
  2196. switch (mgmt->u.action.u.measurement.action_code) {
  2197. case WLAN_ACTION_SPCT_MSR_REQ:
  2198. if (status->band != IEEE80211_BAND_5GHZ)
  2199. break;
  2200. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2201. sizeof(mgmt->u.action.u.measurement)))
  2202. break;
  2203. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2204. break;
  2205. ieee80211_process_measurement_req(sdata, mgmt, len);
  2206. goto handled;
  2207. case WLAN_ACTION_SPCT_CHL_SWITCH: {
  2208. u8 *bssid;
  2209. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2210. sizeof(mgmt->u.action.u.chan_switch)))
  2211. break;
  2212. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2213. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2214. break;
  2215. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  2216. bssid = sdata->u.mgd.bssid;
  2217. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  2218. bssid = sdata->u.ibss.bssid;
  2219. else
  2220. break;
  2221. if (!ether_addr_equal(mgmt->bssid, bssid))
  2222. break;
  2223. goto queue;
  2224. }
  2225. }
  2226. break;
  2227. case WLAN_CATEGORY_SA_QUERY:
  2228. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2229. sizeof(mgmt->u.action.u.sa_query)))
  2230. break;
  2231. switch (mgmt->u.action.u.sa_query.action) {
  2232. case WLAN_ACTION_SA_QUERY_REQUEST:
  2233. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2234. break;
  2235. ieee80211_process_sa_query_req(sdata, mgmt, len);
  2236. goto handled;
  2237. }
  2238. break;
  2239. case WLAN_CATEGORY_SELF_PROTECTED:
  2240. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2241. sizeof(mgmt->u.action.u.self_prot.action_code)))
  2242. break;
  2243. switch (mgmt->u.action.u.self_prot.action_code) {
  2244. case WLAN_SP_MESH_PEERING_OPEN:
  2245. case WLAN_SP_MESH_PEERING_CLOSE:
  2246. case WLAN_SP_MESH_PEERING_CONFIRM:
  2247. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2248. goto invalid;
  2249. if (sdata->u.mesh.user_mpm)
  2250. /* userspace handles this frame */
  2251. break;
  2252. goto queue;
  2253. case WLAN_SP_MGK_INFORM:
  2254. case WLAN_SP_MGK_ACK:
  2255. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2256. goto invalid;
  2257. break;
  2258. }
  2259. break;
  2260. case WLAN_CATEGORY_MESH_ACTION:
  2261. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2262. sizeof(mgmt->u.action.u.mesh_action.action_code)))
  2263. break;
  2264. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2265. break;
  2266. if (mesh_action_is_path_sel(mgmt) &&
  2267. !mesh_path_sel_is_hwmp(sdata))
  2268. break;
  2269. goto queue;
  2270. }
  2271. return RX_CONTINUE;
  2272. invalid:
  2273. status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
  2274. /* will return in the next handlers */
  2275. return RX_CONTINUE;
  2276. handled:
  2277. if (rx->sta)
  2278. rx->sta->rx_packets++;
  2279. dev_kfree_skb(rx->skb);
  2280. return RX_QUEUED;
  2281. queue:
  2282. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2283. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2284. ieee80211_queue_work(&local->hw, &sdata->work);
  2285. if (rx->sta)
  2286. rx->sta->rx_packets++;
  2287. return RX_QUEUED;
  2288. }
  2289. static ieee80211_rx_result debug_noinline
  2290. ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
  2291. {
  2292. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2293. int sig = 0;
  2294. /* skip known-bad action frames and return them in the next handler */
  2295. if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
  2296. return RX_CONTINUE;
  2297. /*
  2298. * Getting here means the kernel doesn't know how to handle
  2299. * it, but maybe userspace does ... include returned frames
  2300. * so userspace can register for those to know whether ones
  2301. * it transmitted were processed or returned.
  2302. */
  2303. if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  2304. sig = status->signal;
  2305. if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
  2306. rx->skb->data, rx->skb->len, 0, GFP_ATOMIC)) {
  2307. if (rx->sta)
  2308. rx->sta->rx_packets++;
  2309. dev_kfree_skb(rx->skb);
  2310. return RX_QUEUED;
  2311. }
  2312. return RX_CONTINUE;
  2313. }
  2314. static ieee80211_rx_result debug_noinline
  2315. ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
  2316. {
  2317. struct ieee80211_local *local = rx->local;
  2318. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2319. struct sk_buff *nskb;
  2320. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2321. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2322. if (!ieee80211_is_action(mgmt->frame_control))
  2323. return RX_CONTINUE;
  2324. /*
  2325. * For AP mode, hostapd is responsible for handling any action
  2326. * frames that we didn't handle, including returning unknown
  2327. * ones. For all other modes we will return them to the sender,
  2328. * setting the 0x80 bit in the action category, as required by
  2329. * 802.11-2012 9.24.4.
  2330. * Newer versions of hostapd shall also use the management frame
  2331. * registration mechanisms, but older ones still use cooked
  2332. * monitor interfaces so push all frames there.
  2333. */
  2334. if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
  2335. (sdata->vif.type == NL80211_IFTYPE_AP ||
  2336. sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
  2337. return RX_DROP_MONITOR;
  2338. if (is_multicast_ether_addr(mgmt->da))
  2339. return RX_DROP_MONITOR;
  2340. /* do not return rejected action frames */
  2341. if (mgmt->u.action.category & 0x80)
  2342. return RX_DROP_UNUSABLE;
  2343. nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
  2344. GFP_ATOMIC);
  2345. if (nskb) {
  2346. struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
  2347. nmgmt->u.action.category |= 0x80;
  2348. memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
  2349. memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
  2350. memset(nskb->cb, 0, sizeof(nskb->cb));
  2351. if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
  2352. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
  2353. info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
  2354. IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
  2355. IEEE80211_TX_CTL_NO_CCK_RATE;
  2356. if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
  2357. info->hw_queue =
  2358. local->hw.offchannel_tx_hw_queue;
  2359. }
  2360. __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
  2361. status->band);
  2362. }
  2363. dev_kfree_skb(rx->skb);
  2364. return RX_QUEUED;
  2365. }
  2366. static ieee80211_rx_result debug_noinline
  2367. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  2368. {
  2369. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2370. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  2371. __le16 stype;
  2372. stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  2373. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  2374. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2375. sdata->vif.type != NL80211_IFTYPE_STATION)
  2376. return RX_DROP_MONITOR;
  2377. switch (stype) {
  2378. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  2379. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  2380. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  2381. /* process for all: mesh, mlme, ibss */
  2382. break;
  2383. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  2384. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  2385. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  2386. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  2387. if (is_multicast_ether_addr(mgmt->da) &&
  2388. !is_broadcast_ether_addr(mgmt->da))
  2389. return RX_DROP_MONITOR;
  2390. /* process only for station */
  2391. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2392. return RX_DROP_MONITOR;
  2393. break;
  2394. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  2395. /* process only for ibss and mesh */
  2396. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2397. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  2398. return RX_DROP_MONITOR;
  2399. break;
  2400. default:
  2401. return RX_DROP_MONITOR;
  2402. }
  2403. /* queue up frame and kick off work to process it */
  2404. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2405. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2406. ieee80211_queue_work(&rx->local->hw, &sdata->work);
  2407. if (rx->sta)
  2408. rx->sta->rx_packets++;
  2409. return RX_QUEUED;
  2410. }
  2411. /* TODO: use IEEE80211_RX_FRAGMENTED */
  2412. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
  2413. struct ieee80211_rate *rate)
  2414. {
  2415. struct ieee80211_sub_if_data *sdata;
  2416. struct ieee80211_local *local = rx->local;
  2417. struct sk_buff *skb = rx->skb, *skb2;
  2418. struct net_device *prev_dev = NULL;
  2419. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2420. int needed_headroom;
  2421. /*
  2422. * If cooked monitor has been processed already, then
  2423. * don't do it again. If not, set the flag.
  2424. */
  2425. if (rx->flags & IEEE80211_RX_CMNTR)
  2426. goto out_free_skb;
  2427. rx->flags |= IEEE80211_RX_CMNTR;
  2428. /* If there are no cooked monitor interfaces, just free the SKB */
  2429. if (!local->cooked_mntrs)
  2430. goto out_free_skb;
  2431. /* room for the radiotap header based on driver features */
  2432. needed_headroom = ieee80211_rx_radiotap_space(local, status);
  2433. if (skb_headroom(skb) < needed_headroom &&
  2434. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
  2435. goto out_free_skb;
  2436. /* prepend radiotap information */
  2437. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
  2438. false);
  2439. skb_set_mac_header(skb, 0);
  2440. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2441. skb->pkt_type = PACKET_OTHERHOST;
  2442. skb->protocol = htons(ETH_P_802_2);
  2443. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2444. if (!ieee80211_sdata_running(sdata))
  2445. continue;
  2446. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  2447. !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  2448. continue;
  2449. if (prev_dev) {
  2450. skb2 = skb_clone(skb, GFP_ATOMIC);
  2451. if (skb2) {
  2452. skb2->dev = prev_dev;
  2453. netif_receive_skb(skb2);
  2454. }
  2455. }
  2456. prev_dev = sdata->dev;
  2457. sdata->dev->stats.rx_packets++;
  2458. sdata->dev->stats.rx_bytes += skb->len;
  2459. }
  2460. if (prev_dev) {
  2461. skb->dev = prev_dev;
  2462. netif_receive_skb(skb);
  2463. return;
  2464. }
  2465. out_free_skb:
  2466. dev_kfree_skb(skb);
  2467. }
  2468. static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
  2469. ieee80211_rx_result res)
  2470. {
  2471. switch (res) {
  2472. case RX_DROP_MONITOR:
  2473. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2474. if (rx->sta)
  2475. rx->sta->rx_dropped++;
  2476. /* fall through */
  2477. case RX_CONTINUE: {
  2478. struct ieee80211_rate *rate = NULL;
  2479. struct ieee80211_supported_band *sband;
  2480. struct ieee80211_rx_status *status;
  2481. status = IEEE80211_SKB_RXCB((rx->skb));
  2482. sband = rx->local->hw.wiphy->bands[status->band];
  2483. if (!(status->flag & RX_FLAG_HT) &&
  2484. !(status->flag & RX_FLAG_VHT))
  2485. rate = &sband->bitrates[status->rate_idx];
  2486. ieee80211_rx_cooked_monitor(rx, rate);
  2487. break;
  2488. }
  2489. case RX_DROP_UNUSABLE:
  2490. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2491. if (rx->sta)
  2492. rx->sta->rx_dropped++;
  2493. dev_kfree_skb(rx->skb);
  2494. break;
  2495. case RX_QUEUED:
  2496. I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
  2497. break;
  2498. }
  2499. }
  2500. static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
  2501. struct sk_buff_head *frames)
  2502. {
  2503. ieee80211_rx_result res = RX_DROP_MONITOR;
  2504. struct sk_buff *skb;
  2505. #define CALL_RXH(rxh) \
  2506. do { \
  2507. res = rxh(rx); \
  2508. if (res != RX_CONTINUE) \
  2509. goto rxh_next; \
  2510. } while (0);
  2511. spin_lock_bh(&rx->local->rx_path_lock);
  2512. while ((skb = __skb_dequeue(frames))) {
  2513. /*
  2514. * all the other fields are valid across frames
  2515. * that belong to an aMPDU since they are on the
  2516. * same TID from the same station
  2517. */
  2518. rx->skb = skb;
  2519. CALL_RXH(ieee80211_rx_h_check_more_data)
  2520. CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
  2521. CALL_RXH(ieee80211_rx_h_sta_process)
  2522. CALL_RXH(ieee80211_rx_h_decrypt)
  2523. CALL_RXH(ieee80211_rx_h_defragment)
  2524. CALL_RXH(ieee80211_rx_h_michael_mic_verify)
  2525. /* must be after MMIC verify so header is counted in MPDU mic */
  2526. #ifdef CONFIG_MAC80211_MESH
  2527. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  2528. CALL_RXH(ieee80211_rx_h_mesh_fwding);
  2529. #endif
  2530. CALL_RXH(ieee80211_rx_h_amsdu)
  2531. CALL_RXH(ieee80211_rx_h_data)
  2532. /* special treatment -- needs the queue */
  2533. res = ieee80211_rx_h_ctrl(rx, frames);
  2534. if (res != RX_CONTINUE)
  2535. goto rxh_next;
  2536. CALL_RXH(ieee80211_rx_h_mgmt_check)
  2537. CALL_RXH(ieee80211_rx_h_action)
  2538. CALL_RXH(ieee80211_rx_h_userspace_mgmt)
  2539. CALL_RXH(ieee80211_rx_h_action_return)
  2540. CALL_RXH(ieee80211_rx_h_mgmt)
  2541. rxh_next:
  2542. ieee80211_rx_handlers_result(rx, res);
  2543. #undef CALL_RXH
  2544. }
  2545. spin_unlock_bh(&rx->local->rx_path_lock);
  2546. }
  2547. static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
  2548. {
  2549. struct sk_buff_head reorder_release;
  2550. ieee80211_rx_result res = RX_DROP_MONITOR;
  2551. __skb_queue_head_init(&reorder_release);
  2552. #define CALL_RXH(rxh) \
  2553. do { \
  2554. res = rxh(rx); \
  2555. if (res != RX_CONTINUE) \
  2556. goto rxh_next; \
  2557. } while (0);
  2558. CALL_RXH(ieee80211_rx_h_check)
  2559. ieee80211_rx_reorder_ampdu(rx, &reorder_release);
  2560. ieee80211_rx_handlers(rx, &reorder_release);
  2561. return;
  2562. rxh_next:
  2563. ieee80211_rx_handlers_result(rx, res);
  2564. #undef CALL_RXH
  2565. }
  2566. /*
  2567. * This function makes calls into the RX path, therefore
  2568. * it has to be invoked under RCU read lock.
  2569. */
  2570. void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
  2571. {
  2572. struct sk_buff_head frames;
  2573. struct ieee80211_rx_data rx = {
  2574. .sta = sta,
  2575. .sdata = sta->sdata,
  2576. .local = sta->local,
  2577. /* This is OK -- must be QoS data frame */
  2578. .security_idx = tid,
  2579. .seqno_idx = tid,
  2580. .flags = 0,
  2581. };
  2582. struct tid_ampdu_rx *tid_agg_rx;
  2583. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  2584. if (!tid_agg_rx)
  2585. return;
  2586. __skb_queue_head_init(&frames);
  2587. spin_lock(&tid_agg_rx->reorder_lock);
  2588. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  2589. spin_unlock(&tid_agg_rx->reorder_lock);
  2590. ieee80211_rx_handlers(&rx, &frames);
  2591. }
  2592. /* main receive path */
  2593. static int prepare_for_handlers(struct ieee80211_rx_data *rx,
  2594. struct ieee80211_hdr *hdr)
  2595. {
  2596. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2597. struct sk_buff *skb = rx->skb;
  2598. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2599. u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  2600. int multicast = is_multicast_ether_addr(hdr->addr1);
  2601. switch (sdata->vif.type) {
  2602. case NL80211_IFTYPE_STATION:
  2603. if (!bssid && !sdata->u.mgd.use_4addr)
  2604. return 0;
  2605. if (!multicast &&
  2606. !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
  2607. if (!(sdata->dev->flags & IFF_PROMISC) ||
  2608. sdata->u.mgd.use_4addr)
  2609. return 0;
  2610. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2611. }
  2612. break;
  2613. case NL80211_IFTYPE_ADHOC:
  2614. if (!bssid)
  2615. return 0;
  2616. if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
  2617. ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
  2618. return 0;
  2619. if (ieee80211_is_beacon(hdr->frame_control)) {
  2620. return 1;
  2621. } else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
  2622. return 0;
  2623. } else if (!multicast &&
  2624. !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
  2625. if (!(sdata->dev->flags & IFF_PROMISC))
  2626. return 0;
  2627. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2628. } else if (!rx->sta) {
  2629. int rate_idx;
  2630. if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  2631. rate_idx = 0; /* TODO: HT/VHT rates */
  2632. else
  2633. rate_idx = status->rate_idx;
  2634. ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
  2635. BIT(rate_idx));
  2636. }
  2637. break;
  2638. case NL80211_IFTYPE_MESH_POINT:
  2639. if (!multicast &&
  2640. !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
  2641. if (!(sdata->dev->flags & IFF_PROMISC))
  2642. return 0;
  2643. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2644. }
  2645. break;
  2646. case NL80211_IFTYPE_AP_VLAN:
  2647. case NL80211_IFTYPE_AP:
  2648. if (!bssid) {
  2649. if (!ether_addr_equal(sdata->vif.addr, hdr->addr1))
  2650. return 0;
  2651. } else if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
  2652. /*
  2653. * Accept public action frames even when the
  2654. * BSSID doesn't match, this is used for P2P
  2655. * and location updates. Note that mac80211
  2656. * itself never looks at these frames.
  2657. */
  2658. if (!multicast &&
  2659. !ether_addr_equal(sdata->vif.addr, hdr->addr1))
  2660. return 0;
  2661. if (ieee80211_is_public_action(hdr, skb->len))
  2662. return 1;
  2663. if (!ieee80211_is_beacon(hdr->frame_control))
  2664. return 0;
  2665. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2666. }
  2667. break;
  2668. case NL80211_IFTYPE_WDS:
  2669. if (bssid || !ieee80211_is_data(hdr->frame_control))
  2670. return 0;
  2671. if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
  2672. return 0;
  2673. break;
  2674. case NL80211_IFTYPE_P2P_DEVICE:
  2675. if (!ieee80211_is_public_action(hdr, skb->len) &&
  2676. !ieee80211_is_probe_req(hdr->frame_control) &&
  2677. !ieee80211_is_probe_resp(hdr->frame_control) &&
  2678. !ieee80211_is_beacon(hdr->frame_control))
  2679. return 0;
  2680. if (!ether_addr_equal(sdata->vif.addr, hdr->addr1) &&
  2681. !multicast)
  2682. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2683. break;
  2684. default:
  2685. /* should never get here */
  2686. WARN_ON_ONCE(1);
  2687. break;
  2688. }
  2689. return 1;
  2690. }
  2691. /*
  2692. * This function returns whether or not the SKB
  2693. * was destined for RX processing or not, which,
  2694. * if consume is true, is equivalent to whether
  2695. * or not the skb was consumed.
  2696. */
  2697. static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
  2698. struct sk_buff *skb, bool consume)
  2699. {
  2700. struct ieee80211_local *local = rx->local;
  2701. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2702. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2703. struct ieee80211_hdr *hdr = (void *)skb->data;
  2704. int prepares;
  2705. rx->skb = skb;
  2706. status->rx_flags |= IEEE80211_RX_RA_MATCH;
  2707. prepares = prepare_for_handlers(rx, hdr);
  2708. if (!prepares)
  2709. return false;
  2710. if (!consume) {
  2711. skb = skb_copy(skb, GFP_ATOMIC);
  2712. if (!skb) {
  2713. if (net_ratelimit())
  2714. wiphy_debug(local->hw.wiphy,
  2715. "failed to copy skb for %s\n",
  2716. sdata->name);
  2717. return true;
  2718. }
  2719. rx->skb = skb;
  2720. }
  2721. ieee80211_invoke_rx_handlers(rx);
  2722. return true;
  2723. }
  2724. /*
  2725. * This is the actual Rx frames handler. as it blongs to Rx path it must
  2726. * be called with rcu_read_lock protection.
  2727. */
  2728. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  2729. struct sk_buff *skb)
  2730. {
  2731. struct ieee80211_local *local = hw_to_local(hw);
  2732. struct ieee80211_sub_if_data *sdata;
  2733. struct ieee80211_hdr *hdr;
  2734. __le16 fc;
  2735. struct ieee80211_rx_data rx;
  2736. struct ieee80211_sub_if_data *prev;
  2737. struct sta_info *sta, *tmp, *prev_sta;
  2738. int err = 0;
  2739. fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
  2740. memset(&rx, 0, sizeof(rx));
  2741. rx.skb = skb;
  2742. rx.local = local;
  2743. if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
  2744. local->dot11ReceivedFragmentCount++;
  2745. if (ieee80211_is_mgmt(fc)) {
  2746. /* drop frame if too short for header */
  2747. if (skb->len < ieee80211_hdrlen(fc))
  2748. err = -ENOBUFS;
  2749. else
  2750. err = skb_linearize(skb);
  2751. } else {
  2752. err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
  2753. }
  2754. if (err) {
  2755. dev_kfree_skb(skb);
  2756. return;
  2757. }
  2758. hdr = (struct ieee80211_hdr *)skb->data;
  2759. ieee80211_parse_qos(&rx);
  2760. ieee80211_verify_alignment(&rx);
  2761. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
  2762. ieee80211_is_beacon(hdr->frame_control)))
  2763. ieee80211_scan_rx(local, skb);
  2764. if (ieee80211_is_data(fc)) {
  2765. prev_sta = NULL;
  2766. for_each_sta_info(local, hdr->addr2, sta, tmp) {
  2767. if (!prev_sta) {
  2768. prev_sta = sta;
  2769. continue;
  2770. }
  2771. rx.sta = prev_sta;
  2772. rx.sdata = prev_sta->sdata;
  2773. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  2774. prev_sta = sta;
  2775. }
  2776. if (prev_sta) {
  2777. rx.sta = prev_sta;
  2778. rx.sdata = prev_sta->sdata;
  2779. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  2780. return;
  2781. goto out;
  2782. }
  2783. }
  2784. prev = NULL;
  2785. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2786. if (!ieee80211_sdata_running(sdata))
  2787. continue;
  2788. if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  2789. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  2790. continue;
  2791. /*
  2792. * frame is destined for this interface, but if it's
  2793. * not also for the previous one we handle that after
  2794. * the loop to avoid copying the SKB once too much
  2795. */
  2796. if (!prev) {
  2797. prev = sdata;
  2798. continue;
  2799. }
  2800. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  2801. rx.sdata = prev;
  2802. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  2803. prev = sdata;
  2804. }
  2805. if (prev) {
  2806. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  2807. rx.sdata = prev;
  2808. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  2809. return;
  2810. }
  2811. out:
  2812. dev_kfree_skb(skb);
  2813. }
  2814. /*
  2815. * This is the receive path handler. It is called by a low level driver when an
  2816. * 802.11 MPDU is received from the hardware.
  2817. */
  2818. void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2819. {
  2820. struct ieee80211_local *local = hw_to_local(hw);
  2821. struct ieee80211_rate *rate = NULL;
  2822. struct ieee80211_supported_band *sband;
  2823. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2824. WARN_ON_ONCE(softirq_count() == 0);
  2825. if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
  2826. goto drop;
  2827. sband = local->hw.wiphy->bands[status->band];
  2828. if (WARN_ON(!sband))
  2829. goto drop;
  2830. /*
  2831. * If we're suspending, it is possible although not too likely
  2832. * that we'd be receiving frames after having already partially
  2833. * quiesced the stack. We can't process such frames then since
  2834. * that might, for example, cause stations to be added or other
  2835. * driver callbacks be invoked.
  2836. */
  2837. if (unlikely(local->quiescing || local->suspended))
  2838. goto drop;
  2839. /* We might be during a HW reconfig, prevent Rx for the same reason */
  2840. if (unlikely(local->in_reconfig))
  2841. goto drop;
  2842. /*
  2843. * The same happens when we're not even started,
  2844. * but that's worth a warning.
  2845. */
  2846. if (WARN_ON(!local->started))
  2847. goto drop;
  2848. if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
  2849. /*
  2850. * Validate the rate, unless a PLCP error means that
  2851. * we probably can't have a valid rate here anyway.
  2852. */
  2853. if (status->flag & RX_FLAG_HT) {
  2854. /*
  2855. * rate_idx is MCS index, which can be [0-76]
  2856. * as documented on:
  2857. *
  2858. * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
  2859. *
  2860. * Anything else would be some sort of driver or
  2861. * hardware error. The driver should catch hardware
  2862. * errors.
  2863. */
  2864. if (WARN(status->rate_idx > 76,
  2865. "Rate marked as an HT rate but passed "
  2866. "status->rate_idx is not "
  2867. "an MCS index [0-76]: %d (0x%02x)\n",
  2868. status->rate_idx,
  2869. status->rate_idx))
  2870. goto drop;
  2871. } else if (status->flag & RX_FLAG_VHT) {
  2872. if (WARN_ONCE(status->rate_idx > 9 ||
  2873. !status->vht_nss ||
  2874. status->vht_nss > 8,
  2875. "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
  2876. status->rate_idx, status->vht_nss))
  2877. goto drop;
  2878. } else {
  2879. if (WARN_ON(status->rate_idx >= sband->n_bitrates))
  2880. goto drop;
  2881. rate = &sband->bitrates[status->rate_idx];
  2882. }
  2883. }
  2884. status->rx_flags = 0;
  2885. /*
  2886. * key references and virtual interfaces are protected using RCU
  2887. * and this requires that we are in a read-side RCU section during
  2888. * receive processing
  2889. */
  2890. rcu_read_lock();
  2891. /*
  2892. * Frames with failed FCS/PLCP checksum are not returned,
  2893. * all other frames are returned without radiotap header
  2894. * if it was previously present.
  2895. * Also, frames with less than 16 bytes are dropped.
  2896. */
  2897. skb = ieee80211_rx_monitor(local, skb, rate);
  2898. if (!skb) {
  2899. rcu_read_unlock();
  2900. return;
  2901. }
  2902. ieee80211_tpt_led_trig_rx(local,
  2903. ((struct ieee80211_hdr *)skb->data)->frame_control,
  2904. skb->len);
  2905. __ieee80211_rx_handle_packet(hw, skb);
  2906. rcu_read_unlock();
  2907. return;
  2908. drop:
  2909. kfree_skb(skb);
  2910. }
  2911. EXPORT_SYMBOL(ieee80211_rx);
  2912. /* This is a version of the rx handler that can be called from hard irq
  2913. * context. Post the skb on the queue and schedule the tasklet */
  2914. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
  2915. {
  2916. struct ieee80211_local *local = hw_to_local(hw);
  2917. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  2918. skb->pkt_type = IEEE80211_RX_MSG;
  2919. skb_queue_tail(&local->skb_queue, skb);
  2920. tasklet_schedule(&local->tasklet);
  2921. }
  2922. EXPORT_SYMBOL(ieee80211_rx_irqsafe);