rx.c 77 KB

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