rx.c 94 KB

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