rx.c 79 KB

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