rx.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/jiffies.h>
  12. #include <linux/kernel.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/rcupdate.h>
  17. #include <net/mac80211.h>
  18. #include <net/ieee80211_radiotap.h>
  19. #include "ieee80211_i.h"
  20. #include "led.h"
  21. #include "mesh.h"
  22. #include "wep.h"
  23. #include "wpa.h"
  24. #include "tkip.h"
  25. #include "wme.h"
  26. u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
  27. struct tid_ampdu_rx *tid_agg_rx,
  28. struct sk_buff *skb, u16 mpdu_seq_num,
  29. int bar_req);
  30. /*
  31. * monitor mode reception
  32. *
  33. * This function cleans up the SKB, i.e. it removes all the stuff
  34. * only useful for monitoring.
  35. */
  36. static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
  37. struct sk_buff *skb,
  38. int rtap_len)
  39. {
  40. skb_pull(skb, rtap_len);
  41. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
  42. if (likely(skb->len > FCS_LEN))
  43. skb_trim(skb, skb->len - FCS_LEN);
  44. else {
  45. /* driver bug */
  46. WARN_ON(1);
  47. dev_kfree_skb(skb);
  48. skb = NULL;
  49. }
  50. }
  51. return skb;
  52. }
  53. static inline int should_drop_frame(struct ieee80211_rx_status *status,
  54. struct sk_buff *skb,
  55. int present_fcs_len,
  56. int radiotap_len)
  57. {
  58. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  59. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  60. return 1;
  61. if (unlikely(skb->len < 16 + present_fcs_len + radiotap_len))
  62. return 1;
  63. if (ieee80211_is_ctl(hdr->frame_control) &&
  64. !ieee80211_is_pspoll(hdr->frame_control) &&
  65. !ieee80211_is_back_req(hdr->frame_control))
  66. return 1;
  67. return 0;
  68. }
  69. static int
  70. ieee80211_rx_radiotap_len(struct ieee80211_local *local,
  71. struct ieee80211_rx_status *status)
  72. {
  73. int len;
  74. /* always present fields */
  75. len = sizeof(struct ieee80211_radiotap_header) + 9;
  76. if (status->flag & RX_FLAG_TSFT)
  77. len += 8;
  78. if (local->hw.flags & IEEE80211_HW_SIGNAL_DB ||
  79. local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  80. len += 1;
  81. if (local->hw.flags & IEEE80211_HW_NOISE_DBM)
  82. len += 1;
  83. if (len & 1) /* padding for RX_FLAGS if necessary */
  84. len++;
  85. /* make sure radiotap starts at a naturally aligned address */
  86. if (len % 8)
  87. len = roundup(len, 8);
  88. return len;
  89. }
  90. /**
  91. * ieee80211_add_rx_radiotap_header - add radiotap header
  92. *
  93. * add a radiotap header containing all the fields which the hardware provided.
  94. */
  95. static void
  96. ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
  97. struct sk_buff *skb,
  98. struct ieee80211_rx_status *status,
  99. struct ieee80211_rate *rate,
  100. int rtap_len)
  101. {
  102. struct ieee80211_radiotap_header *rthdr;
  103. unsigned char *pos;
  104. rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
  105. memset(rthdr, 0, rtap_len);
  106. /* radiotap header, set always present flags */
  107. rthdr->it_present =
  108. cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  109. (1 << IEEE80211_RADIOTAP_RATE) |
  110. (1 << IEEE80211_RADIOTAP_CHANNEL) |
  111. (1 << IEEE80211_RADIOTAP_ANTENNA) |
  112. (1 << IEEE80211_RADIOTAP_RX_FLAGS));
  113. rthdr->it_len = cpu_to_le16(rtap_len);
  114. pos = (unsigned char *)(rthdr+1);
  115. /* the order of the following fields is important */
  116. /* IEEE80211_RADIOTAP_TSFT */
  117. if (status->flag & RX_FLAG_TSFT) {
  118. *(__le64 *)pos = cpu_to_le64(status->mactime);
  119. rthdr->it_present |=
  120. cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
  121. pos += 8;
  122. }
  123. /* IEEE80211_RADIOTAP_FLAGS */
  124. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  125. *pos |= IEEE80211_RADIOTAP_F_FCS;
  126. if (status->flag & RX_FLAG_SHORTPRE)
  127. *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
  128. pos++;
  129. /* IEEE80211_RADIOTAP_RATE */
  130. *pos = rate->bitrate / 5;
  131. pos++;
  132. /* IEEE80211_RADIOTAP_CHANNEL */
  133. *(__le16 *)pos = cpu_to_le16(status->freq);
  134. pos += 2;
  135. if (status->band == IEEE80211_BAND_5GHZ)
  136. *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_OFDM |
  137. IEEE80211_CHAN_5GHZ);
  138. else if (rate->flags & IEEE80211_RATE_ERP_G)
  139. *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_OFDM |
  140. IEEE80211_CHAN_2GHZ);
  141. else
  142. *(__le16 *)pos = cpu_to_le16(IEEE80211_CHAN_CCK |
  143. IEEE80211_CHAN_2GHZ);
  144. pos += 2;
  145. /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
  146. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  147. *pos = status->signal;
  148. rthdr->it_present |=
  149. cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  150. pos++;
  151. }
  152. /* IEEE80211_RADIOTAP_DBM_ANTNOISE */
  153. if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
  154. *pos = status->noise;
  155. rthdr->it_present |=
  156. cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE);
  157. pos++;
  158. }
  159. /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
  160. /* IEEE80211_RADIOTAP_ANTENNA */
  161. *pos = status->antenna;
  162. pos++;
  163. /* IEEE80211_RADIOTAP_DB_ANTSIGNAL */
  164. if (local->hw.flags & IEEE80211_HW_SIGNAL_DB) {
  165. *pos = status->signal;
  166. rthdr->it_present |=
  167. cpu_to_le32(1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL);
  168. pos++;
  169. }
  170. /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
  171. /* IEEE80211_RADIOTAP_RX_FLAGS */
  172. /* ensure 2 byte alignment for the 2 byte field as required */
  173. if ((pos - (unsigned char *)rthdr) & 1)
  174. pos++;
  175. /* FIXME: when radiotap gets a 'bad PLCP' flag use it here */
  176. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  177. *(__le16 *)pos |= cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
  178. pos += 2;
  179. }
  180. /*
  181. * This function copies a received frame to all monitor interfaces and
  182. * returns a cleaned-up SKB that no longer includes the FCS nor the
  183. * radiotap header the driver might have added.
  184. */
  185. static struct sk_buff *
  186. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  187. struct ieee80211_rx_status *status,
  188. struct ieee80211_rate *rate)
  189. {
  190. struct ieee80211_sub_if_data *sdata;
  191. int needed_headroom = 0;
  192. struct sk_buff *skb, *skb2;
  193. struct net_device *prev_dev = NULL;
  194. int present_fcs_len = 0;
  195. int rtap_len = 0;
  196. /*
  197. * First, we may need to make a copy of the skb because
  198. * (1) we need to modify it for radiotap (if not present), and
  199. * (2) the other RX handlers will modify the skb we got.
  200. *
  201. * We don't need to, of course, if we aren't going to return
  202. * the SKB because it has a bad FCS/PLCP checksum.
  203. */
  204. if (status->flag & RX_FLAG_RADIOTAP)
  205. rtap_len = ieee80211_get_radiotap_len(origskb->data);
  206. else
  207. /* room for the radiotap header based on driver features */
  208. needed_headroom = ieee80211_rx_radiotap_len(local, status);
  209. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  210. present_fcs_len = FCS_LEN;
  211. if (!local->monitors) {
  212. if (should_drop_frame(status, origskb, present_fcs_len,
  213. rtap_len)) {
  214. dev_kfree_skb(origskb);
  215. return NULL;
  216. }
  217. return remove_monitor_info(local, origskb, rtap_len);
  218. }
  219. if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) {
  220. /* only need to expand headroom if necessary */
  221. skb = origskb;
  222. origskb = NULL;
  223. /*
  224. * This shouldn't trigger often because most devices have an
  225. * RX header they pull before we get here, and that should
  226. * be big enough for our radiotap information. We should
  227. * probably export the length to drivers so that we can have
  228. * them allocate enough headroom to start with.
  229. */
  230. if (skb_headroom(skb) < needed_headroom &&
  231. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  232. dev_kfree_skb(skb);
  233. return NULL;
  234. }
  235. } else {
  236. /*
  237. * Need to make a copy and possibly remove radiotap header
  238. * and FCS from the original.
  239. */
  240. skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
  241. origskb = remove_monitor_info(local, origskb, rtap_len);
  242. if (!skb)
  243. return origskb;
  244. }
  245. /* if necessary, prepend radiotap information */
  246. if (!(status->flag & RX_FLAG_RADIOTAP))
  247. ieee80211_add_rx_radiotap_header(local, skb, status, rate,
  248. needed_headroom);
  249. skb_reset_mac_header(skb);
  250. skb->ip_summed = CHECKSUM_UNNECESSARY;
  251. skb->pkt_type = PACKET_OTHERHOST;
  252. skb->protocol = htons(ETH_P_802_2);
  253. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  254. if (!netif_running(sdata->dev))
  255. continue;
  256. if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
  257. continue;
  258. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
  259. continue;
  260. if (prev_dev) {
  261. skb2 = skb_clone(skb, GFP_ATOMIC);
  262. if (skb2) {
  263. skb2->dev = prev_dev;
  264. netif_rx(skb2);
  265. }
  266. }
  267. prev_dev = sdata->dev;
  268. sdata->dev->stats.rx_packets++;
  269. sdata->dev->stats.rx_bytes += skb->len;
  270. }
  271. if (prev_dev) {
  272. skb->dev = prev_dev;
  273. netif_rx(skb);
  274. } else
  275. dev_kfree_skb(skb);
  276. return origskb;
  277. }
  278. static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
  279. {
  280. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  281. int tid;
  282. /* does the frame have a qos control field? */
  283. if (ieee80211_is_data_qos(hdr->frame_control)) {
  284. u8 *qc = ieee80211_get_qos_ctl(hdr);
  285. /* frame has qos control */
  286. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  287. if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
  288. rx->flags |= IEEE80211_RX_AMSDU;
  289. else
  290. rx->flags &= ~IEEE80211_RX_AMSDU;
  291. } else {
  292. /*
  293. * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
  294. *
  295. * Sequence numbers for management frames, QoS data
  296. * frames with a broadcast/multicast address in the
  297. * Address 1 field, and all non-QoS data frames sent
  298. * by QoS STAs are assigned using an additional single
  299. * modulo-4096 counter, [...]
  300. *
  301. * We also use that counter for non-QoS STAs.
  302. */
  303. tid = NUM_RX_DATA_QUEUES - 1;
  304. }
  305. rx->queue = tid;
  306. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  307. * For now, set skb->priority to 0 for other cases. */
  308. rx->skb->priority = (tid > 7) ? 0 : tid;
  309. }
  310. static void ieee80211_verify_ip_alignment(struct ieee80211_rx_data *rx)
  311. {
  312. #ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
  313. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  314. int hdrlen;
  315. if (!ieee80211_is_data_present(hdr->frame_control))
  316. return;
  317. /*
  318. * Drivers are required to align the payload data in a way that
  319. * guarantees that the contained IP header is aligned to a four-
  320. * byte boundary. In the case of regular frames, this simply means
  321. * aligning the payload to a four-byte boundary (because either
  322. * the IP header is directly contained, or IV/RFC1042 headers that
  323. * have a length divisible by four are in front of it.
  324. *
  325. * With A-MSDU frames, however, the payload data address must
  326. * yield two modulo four because there are 14-byte 802.3 headers
  327. * within the A-MSDU frames that push the IP header further back
  328. * to a multiple of four again. Thankfully, the specs were sane
  329. * enough this time around to require padding each A-MSDU subframe
  330. * to a length that is a multiple of four.
  331. *
  332. * Padding like atheros hardware adds which is inbetween the 802.11
  333. * header and the payload is not supported, the driver is required
  334. * to move the 802.11 header further back in that case.
  335. */
  336. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  337. if (rx->flags & IEEE80211_RX_AMSDU)
  338. hdrlen += ETH_HLEN;
  339. WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3);
  340. #endif
  341. }
  342. /* rx handlers */
  343. static ieee80211_rx_result debug_noinline
  344. ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
  345. {
  346. struct ieee80211_local *local = rx->local;
  347. struct sk_buff *skb = rx->skb;
  348. if (unlikely(local->hw_scanning))
  349. return ieee80211_scan_rx(rx->sdata, skb, rx->status);
  350. if (unlikely(local->sw_scanning)) {
  351. /* drop all the other packets during a software scan anyway */
  352. if (ieee80211_scan_rx(rx->sdata, skb, rx->status)
  353. != RX_QUEUED)
  354. dev_kfree_skb(skb);
  355. return RX_QUEUED;
  356. }
  357. if (unlikely(rx->flags & IEEE80211_RX_IN_SCAN)) {
  358. /* scanning finished during invoking of handlers */
  359. I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
  360. return RX_DROP_UNUSABLE;
  361. }
  362. return RX_CONTINUE;
  363. }
  364. static ieee80211_rx_result
  365. ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
  366. {
  367. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  368. unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
  369. if (ieee80211_is_data(hdr->frame_control)) {
  370. if (!ieee80211_has_a4(hdr->frame_control))
  371. return RX_DROP_MONITOR;
  372. if (memcmp(hdr->addr4, rx->dev->dev_addr, ETH_ALEN) == 0)
  373. return RX_DROP_MONITOR;
  374. }
  375. /* If there is not an established peer link and this is not a peer link
  376. * establisment frame, beacon or probe, drop the frame.
  377. */
  378. if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) {
  379. struct ieee80211_mgmt *mgmt;
  380. if (!ieee80211_is_mgmt(hdr->frame_control))
  381. return RX_DROP_MONITOR;
  382. if (ieee80211_is_action(hdr->frame_control)) {
  383. mgmt = (struct ieee80211_mgmt *)hdr;
  384. if (mgmt->u.action.category != PLINK_CATEGORY)
  385. return RX_DROP_MONITOR;
  386. return RX_CONTINUE;
  387. }
  388. if (ieee80211_is_probe_req(hdr->frame_control) ||
  389. ieee80211_is_probe_resp(hdr->frame_control) ||
  390. ieee80211_is_beacon(hdr->frame_control))
  391. return RX_CONTINUE;
  392. return RX_DROP_MONITOR;
  393. }
  394. #define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
  395. if (ieee80211_is_data(hdr->frame_control) &&
  396. is_multicast_ether_addr(hdr->addr1) &&
  397. mesh_rmc_check(hdr->addr4, msh_h_get(hdr, hdrlen), rx->sdata))
  398. return RX_DROP_MONITOR;
  399. #undef msh_h_get
  400. return RX_CONTINUE;
  401. }
  402. static ieee80211_rx_result debug_noinline
  403. ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
  404. {
  405. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  406. /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
  407. if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
  408. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  409. rx->sta->last_seq_ctrl[rx->queue] ==
  410. hdr->seq_ctrl)) {
  411. if (rx->flags & IEEE80211_RX_RA_MATCH) {
  412. rx->local->dot11FrameDuplicateCount++;
  413. rx->sta->num_duplicates++;
  414. }
  415. return RX_DROP_MONITOR;
  416. } else
  417. rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl;
  418. }
  419. if (unlikely(rx->skb->len < 16)) {
  420. I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
  421. return RX_DROP_MONITOR;
  422. }
  423. /* Drop disallowed frame classes based on STA auth/assoc state;
  424. * IEEE 802.11, Chap 5.5.
  425. *
  426. * mac80211 filters only based on association state, i.e. it drops
  427. * Class 3 frames from not associated stations. hostapd sends
  428. * deauth/disassoc frames when needed. In addition, hostapd is
  429. * responsible for filtering on both auth and assoc states.
  430. */
  431. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  432. return ieee80211_rx_mesh_check(rx);
  433. if (unlikely((ieee80211_is_data(hdr->frame_control) ||
  434. ieee80211_is_pspoll(hdr->frame_control)) &&
  435. rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  436. (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) {
  437. if ((!ieee80211_has_fromds(hdr->frame_control) &&
  438. !ieee80211_has_tods(hdr->frame_control) &&
  439. ieee80211_is_data(hdr->frame_control)) ||
  440. !(rx->flags & IEEE80211_RX_RA_MATCH)) {
  441. /* Drop IBSS frames and frames for other hosts
  442. * silently. */
  443. return RX_DROP_MONITOR;
  444. }
  445. return RX_DROP_MONITOR;
  446. }
  447. return RX_CONTINUE;
  448. }
  449. static ieee80211_rx_result debug_noinline
  450. ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
  451. {
  452. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  453. int keyidx;
  454. int hdrlen;
  455. ieee80211_rx_result result = RX_DROP_UNUSABLE;
  456. struct ieee80211_key *stakey = NULL;
  457. /*
  458. * Key selection 101
  459. *
  460. * There are three types of keys:
  461. * - GTK (group keys)
  462. * - PTK (pairwise keys)
  463. * - STK (station-to-station pairwise keys)
  464. *
  465. * When selecting a key, we have to distinguish between multicast
  466. * (including broadcast) and unicast frames, the latter can only
  467. * use PTKs and STKs while the former always use GTKs. Unless, of
  468. * course, actual WEP keys ("pre-RSNA") are used, then unicast
  469. * frames can also use key indizes like GTKs. Hence, if we don't
  470. * have a PTK/STK we check the key index for a WEP key.
  471. *
  472. * Note that in a regular BSS, multicast frames are sent by the
  473. * AP only, associated stations unicast the frame to the AP first
  474. * which then multicasts it on their behalf.
  475. *
  476. * There is also a slight problem in IBSS mode: GTKs are negotiated
  477. * with each station, that is something we don't currently handle.
  478. * The spec seems to expect that one negotiates the same key with
  479. * every station but there's no such requirement; VLANs could be
  480. * possible.
  481. */
  482. if (!ieee80211_has_protected(hdr->frame_control))
  483. return RX_CONTINUE;
  484. /*
  485. * No point in finding a key and decrypting if the frame is neither
  486. * addressed to us nor a multicast frame.
  487. */
  488. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  489. return RX_CONTINUE;
  490. if (rx->sta)
  491. stakey = rcu_dereference(rx->sta->key);
  492. if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
  493. rx->key = stakey;
  494. } else {
  495. /*
  496. * The device doesn't give us the IV so we won't be
  497. * able to look up the key. That's ok though, we
  498. * don't need to decrypt the frame, we just won't
  499. * be able to keep statistics accurate.
  500. * Except for key threshold notifications, should
  501. * we somehow allow the driver to tell us which key
  502. * the hardware used if this flag is set?
  503. */
  504. if ((rx->status->flag & RX_FLAG_DECRYPTED) &&
  505. (rx->status->flag & RX_FLAG_IV_STRIPPED))
  506. return RX_CONTINUE;
  507. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  508. if (rx->skb->len < 8 + hdrlen)
  509. return RX_DROP_UNUSABLE; /* TODO: count this? */
  510. /*
  511. * no need to call ieee80211_wep_get_keyidx,
  512. * it verifies a bunch of things we've done already
  513. */
  514. keyidx = rx->skb->data[hdrlen + 3] >> 6;
  515. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  516. /*
  517. * RSNA-protected unicast frames should always be sent with
  518. * pairwise or station-to-station keys, but for WEP we allow
  519. * using a key index as well.
  520. */
  521. if (rx->key && rx->key->conf.alg != ALG_WEP &&
  522. !is_multicast_ether_addr(hdr->addr1))
  523. rx->key = NULL;
  524. }
  525. if (rx->key) {
  526. rx->key->tx_rx_count++;
  527. /* TODO: add threshold stuff again */
  528. } else {
  529. return RX_DROP_MONITOR;
  530. }
  531. /* Check for weak IVs if possible */
  532. if (rx->sta && rx->key->conf.alg == ALG_WEP &&
  533. ieee80211_is_data(hdr->frame_control) &&
  534. (!(rx->status->flag & RX_FLAG_IV_STRIPPED) ||
  535. !(rx->status->flag & RX_FLAG_DECRYPTED)) &&
  536. ieee80211_wep_is_weak_iv(rx->skb, rx->key))
  537. rx->sta->wep_weak_iv_count++;
  538. switch (rx->key->conf.alg) {
  539. case ALG_WEP:
  540. result = ieee80211_crypto_wep_decrypt(rx);
  541. break;
  542. case ALG_TKIP:
  543. result = ieee80211_crypto_tkip_decrypt(rx);
  544. break;
  545. case ALG_CCMP:
  546. result = ieee80211_crypto_ccmp_decrypt(rx);
  547. break;
  548. }
  549. /* either the frame has been decrypted or will be dropped */
  550. rx->status->flag |= RX_FLAG_DECRYPTED;
  551. return result;
  552. }
  553. static void ap_sta_ps_start(struct sta_info *sta)
  554. {
  555. struct ieee80211_sub_if_data *sdata = sta->sdata;
  556. DECLARE_MAC_BUF(mac);
  557. atomic_inc(&sdata->bss->num_sta_ps);
  558. set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL);
  559. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  560. printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
  561. sdata->dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
  562. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  563. }
  564. static int ap_sta_ps_end(struct sta_info *sta)
  565. {
  566. struct ieee80211_sub_if_data *sdata = sta->sdata;
  567. struct ieee80211_local *local = sdata->local;
  568. struct sk_buff *skb;
  569. int sent = 0;
  570. struct ieee80211_tx_info *info;
  571. DECLARE_MAC_BUF(mac);
  572. atomic_dec(&sdata->bss->num_sta_ps);
  573. clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL);
  574. if (!skb_queue_empty(&sta->ps_tx_buf))
  575. sta_info_clear_tim_bit(sta);
  576. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  577. printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
  578. sdata->dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
  579. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  580. /* Send all buffered frames to the station */
  581. while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
  582. info = IEEE80211_SKB_CB(skb);
  583. sent++;
  584. info->flags |= IEEE80211_TX_CTL_REQUEUE;
  585. dev_queue_xmit(skb);
  586. }
  587. while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
  588. info = IEEE80211_SKB_CB(skb);
  589. local->total_ps_buffered--;
  590. sent++;
  591. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  592. printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
  593. "since STA not sleeping anymore\n", sdata->dev->name,
  594. print_mac(mac, sta->sta.addr), sta->sta.aid);
  595. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  596. info->flags |= IEEE80211_TX_CTL_REQUEUE;
  597. dev_queue_xmit(skb);
  598. }
  599. return sent;
  600. }
  601. static ieee80211_rx_result debug_noinline
  602. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  603. {
  604. struct sta_info *sta = rx->sta;
  605. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  606. if (!sta)
  607. return RX_CONTINUE;
  608. /* Update last_rx only for IBSS packets which are for the current
  609. * BSSID to avoid keeping the current IBSS network alive in cases where
  610. * other STAs are using different BSSID. */
  611. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  612. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  613. NL80211_IFTYPE_ADHOC);
  614. if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
  615. sta->last_rx = jiffies;
  616. } else
  617. if (!is_multicast_ether_addr(hdr->addr1) ||
  618. rx->sdata->vif.type == NL80211_IFTYPE_STATION) {
  619. /* Update last_rx only for unicast frames in order to prevent
  620. * the Probe Request frames (the only broadcast frames from a
  621. * STA in infrastructure mode) from keeping a connection alive.
  622. * Mesh beacons will update last_rx when if they are found to
  623. * match the current local configuration when processed.
  624. */
  625. sta->last_rx = jiffies;
  626. }
  627. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  628. return RX_CONTINUE;
  629. sta->rx_fragments++;
  630. sta->rx_bytes += rx->skb->len;
  631. sta->last_signal = rx->status->signal;
  632. sta->last_qual = rx->status->qual;
  633. sta->last_noise = rx->status->noise;
  634. if (!ieee80211_has_morefrags(hdr->frame_control) &&
  635. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  636. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
  637. /* Change STA power saving mode only in the end of a frame
  638. * exchange sequence */
  639. if (test_sta_flags(sta, WLAN_STA_PS) &&
  640. !ieee80211_has_pm(hdr->frame_control))
  641. rx->sent_ps_buffered += ap_sta_ps_end(sta);
  642. else if (!test_sta_flags(sta, WLAN_STA_PS) &&
  643. ieee80211_has_pm(hdr->frame_control))
  644. ap_sta_ps_start(sta);
  645. }
  646. /* Drop data::nullfunc frames silently, since they are used only to
  647. * control station power saving mode. */
  648. if (ieee80211_is_nullfunc(hdr->frame_control)) {
  649. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  650. /* Update counter and free packet here to avoid counting this
  651. * as a dropped packed. */
  652. sta->rx_packets++;
  653. dev_kfree_skb(rx->skb);
  654. return RX_QUEUED;
  655. }
  656. return RX_CONTINUE;
  657. } /* ieee80211_rx_h_sta_process */
  658. static inline struct ieee80211_fragment_entry *
  659. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  660. unsigned int frag, unsigned int seq, int rx_queue,
  661. struct sk_buff **skb)
  662. {
  663. struct ieee80211_fragment_entry *entry;
  664. int idx;
  665. idx = sdata->fragment_next;
  666. entry = &sdata->fragments[sdata->fragment_next++];
  667. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  668. sdata->fragment_next = 0;
  669. if (!skb_queue_empty(&entry->skb_list)) {
  670. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  671. struct ieee80211_hdr *hdr =
  672. (struct ieee80211_hdr *) entry->skb_list.next->data;
  673. DECLARE_MAC_BUF(mac);
  674. DECLARE_MAC_BUF(mac2);
  675. printk(KERN_DEBUG "%s: RX reassembly removed oldest "
  676. "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
  677. "addr1=%s addr2=%s\n",
  678. sdata->dev->name, idx,
  679. jiffies - entry->first_frag_time, entry->seq,
  680. entry->last_frag, print_mac(mac, hdr->addr1),
  681. print_mac(mac2, hdr->addr2));
  682. #endif
  683. __skb_queue_purge(&entry->skb_list);
  684. }
  685. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  686. *skb = NULL;
  687. entry->first_frag_time = jiffies;
  688. entry->seq = seq;
  689. entry->rx_queue = rx_queue;
  690. entry->last_frag = frag;
  691. entry->ccmp = 0;
  692. entry->extra_len = 0;
  693. return entry;
  694. }
  695. static inline struct ieee80211_fragment_entry *
  696. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  697. unsigned int frag, unsigned int seq,
  698. int rx_queue, struct ieee80211_hdr *hdr)
  699. {
  700. struct ieee80211_fragment_entry *entry;
  701. int i, idx;
  702. idx = sdata->fragment_next;
  703. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  704. struct ieee80211_hdr *f_hdr;
  705. idx--;
  706. if (idx < 0)
  707. idx = IEEE80211_FRAGMENT_MAX - 1;
  708. entry = &sdata->fragments[idx];
  709. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  710. entry->rx_queue != rx_queue ||
  711. entry->last_frag + 1 != frag)
  712. continue;
  713. f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
  714. /*
  715. * Check ftype and addresses are equal, else check next fragment
  716. */
  717. if (((hdr->frame_control ^ f_hdr->frame_control) &
  718. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  719. compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
  720. compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
  721. continue;
  722. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  723. __skb_queue_purge(&entry->skb_list);
  724. continue;
  725. }
  726. return entry;
  727. }
  728. return NULL;
  729. }
  730. static ieee80211_rx_result debug_noinline
  731. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  732. {
  733. struct ieee80211_hdr *hdr;
  734. u16 sc;
  735. __le16 fc;
  736. unsigned int frag, seq;
  737. struct ieee80211_fragment_entry *entry;
  738. struct sk_buff *skb;
  739. DECLARE_MAC_BUF(mac);
  740. hdr = (struct ieee80211_hdr *)rx->skb->data;
  741. fc = hdr->frame_control;
  742. sc = le16_to_cpu(hdr->seq_ctrl);
  743. frag = sc & IEEE80211_SCTL_FRAG;
  744. if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
  745. (rx->skb)->len < 24 ||
  746. is_multicast_ether_addr(hdr->addr1))) {
  747. /* not fragmented */
  748. goto out;
  749. }
  750. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  751. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  752. if (frag == 0) {
  753. /* This is the first fragment of a new frame. */
  754. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  755. rx->queue, &(rx->skb));
  756. if (rx->key && rx->key->conf.alg == ALG_CCMP &&
  757. ieee80211_has_protected(fc)) {
  758. /* Store CCMP PN so that we can verify that the next
  759. * fragment has a sequential PN value. */
  760. entry->ccmp = 1;
  761. memcpy(entry->last_pn,
  762. rx->key->u.ccmp.rx_pn[rx->queue],
  763. CCMP_PN_LEN);
  764. }
  765. return RX_QUEUED;
  766. }
  767. /* This is a fragment for a frame that should already be pending in
  768. * fragment cache. Add this fragment to the end of the pending entry.
  769. */
  770. entry = ieee80211_reassemble_find(rx->sdata, frag, seq, rx->queue, hdr);
  771. if (!entry) {
  772. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  773. return RX_DROP_MONITOR;
  774. }
  775. /* Verify that MPDUs within one MSDU have sequential PN values.
  776. * (IEEE 802.11i, 8.3.3.4.5) */
  777. if (entry->ccmp) {
  778. int i;
  779. u8 pn[CCMP_PN_LEN], *rpn;
  780. if (!rx->key || rx->key->conf.alg != ALG_CCMP)
  781. return RX_DROP_UNUSABLE;
  782. memcpy(pn, entry->last_pn, CCMP_PN_LEN);
  783. for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
  784. pn[i]++;
  785. if (pn[i])
  786. break;
  787. }
  788. rpn = rx->key->u.ccmp.rx_pn[rx->queue];
  789. if (memcmp(pn, rpn, CCMP_PN_LEN))
  790. return RX_DROP_UNUSABLE;
  791. memcpy(entry->last_pn, pn, CCMP_PN_LEN);
  792. }
  793. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  794. __skb_queue_tail(&entry->skb_list, rx->skb);
  795. entry->last_frag = frag;
  796. entry->extra_len += rx->skb->len;
  797. if (ieee80211_has_morefrags(fc)) {
  798. rx->skb = NULL;
  799. return RX_QUEUED;
  800. }
  801. rx->skb = __skb_dequeue(&entry->skb_list);
  802. if (skb_tailroom(rx->skb) < entry->extra_len) {
  803. I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
  804. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  805. GFP_ATOMIC))) {
  806. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  807. __skb_queue_purge(&entry->skb_list);
  808. return RX_DROP_UNUSABLE;
  809. }
  810. }
  811. while ((skb = __skb_dequeue(&entry->skb_list))) {
  812. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  813. dev_kfree_skb(skb);
  814. }
  815. /* Complete frame has been reassembled - process it now */
  816. rx->flags |= IEEE80211_RX_FRAGMENTED;
  817. out:
  818. if (rx->sta)
  819. rx->sta->rx_packets++;
  820. if (is_multicast_ether_addr(hdr->addr1))
  821. rx->local->dot11MulticastReceivedFrameCount++;
  822. else
  823. ieee80211_led_rx(rx->local);
  824. return RX_CONTINUE;
  825. }
  826. static ieee80211_rx_result debug_noinline
  827. ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
  828. {
  829. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  830. struct sk_buff *skb;
  831. int no_pending_pkts;
  832. DECLARE_MAC_BUF(mac);
  833. __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
  834. if (likely(!rx->sta || !ieee80211_is_pspoll(fc) ||
  835. !(rx->flags & IEEE80211_RX_RA_MATCH)))
  836. return RX_CONTINUE;
  837. if ((sdata->vif.type != NL80211_IFTYPE_AP) &&
  838. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
  839. return RX_DROP_UNUSABLE;
  840. skb = skb_dequeue(&rx->sta->tx_filtered);
  841. if (!skb) {
  842. skb = skb_dequeue(&rx->sta->ps_tx_buf);
  843. if (skb)
  844. rx->local->total_ps_buffered--;
  845. }
  846. no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
  847. skb_queue_empty(&rx->sta->ps_tx_buf);
  848. if (skb) {
  849. struct ieee80211_hdr *hdr =
  850. (struct ieee80211_hdr *) skb->data;
  851. /*
  852. * Tell TX path to send one frame even though the STA may
  853. * still remain is PS mode after this frame exchange.
  854. */
  855. set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
  856. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  857. printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
  858. print_mac(mac, rx->sta->sta.addr), rx->sta->sta.aid,
  859. skb_queue_len(&rx->sta->ps_tx_buf));
  860. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  861. /* Use MoreData flag to indicate whether there are more
  862. * buffered frames for this STA */
  863. if (no_pending_pkts)
  864. hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  865. else
  866. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  867. dev_queue_xmit(skb);
  868. if (no_pending_pkts)
  869. sta_info_clear_tim_bit(rx->sta);
  870. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  871. } else if (!rx->sent_ps_buffered) {
  872. /*
  873. * FIXME: This can be the result of a race condition between
  874. * us expiring a frame and the station polling for it.
  875. * Should we send it a null-func frame indicating we
  876. * have nothing buffered for it?
  877. */
  878. printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
  879. "though there are no buffered frames for it\n",
  880. rx->dev->name, print_mac(mac, rx->sta->sta.addr));
  881. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  882. }
  883. /* Free PS Poll skb here instead of returning RX_DROP that would
  884. * count as an dropped frame. */
  885. dev_kfree_skb(rx->skb);
  886. return RX_QUEUED;
  887. }
  888. static ieee80211_rx_result debug_noinline
  889. ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
  890. {
  891. u8 *data = rx->skb->data;
  892. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
  893. if (!ieee80211_is_data_qos(hdr->frame_control))
  894. return RX_CONTINUE;
  895. /* remove the qos control field, update frame type and meta-data */
  896. memmove(data + IEEE80211_QOS_CTL_LEN, data,
  897. ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
  898. hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
  899. /* change frame type to non QOS */
  900. hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  901. return RX_CONTINUE;
  902. }
  903. static int
  904. ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  905. {
  906. if (unlikely(!rx->sta ||
  907. !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED)))
  908. return -EACCES;
  909. return 0;
  910. }
  911. static int
  912. ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  913. {
  914. /*
  915. * Pass through unencrypted frames if the hardware has
  916. * decrypted them already.
  917. */
  918. if (rx->status->flag & RX_FLAG_DECRYPTED)
  919. return 0;
  920. /* Drop unencrypted frames if key is set. */
  921. if (unlikely(!ieee80211_has_protected(fc) &&
  922. !ieee80211_is_nullfunc(fc) &&
  923. (rx->key || rx->sdata->drop_unencrypted)))
  924. return -EACCES;
  925. return 0;
  926. }
  927. static int
  928. ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
  929. {
  930. struct net_device *dev = rx->dev;
  931. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  932. u16 hdrlen, ethertype;
  933. u8 *payload;
  934. u8 dst[ETH_ALEN];
  935. u8 src[ETH_ALEN] __aligned(2);
  936. struct sk_buff *skb = rx->skb;
  937. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  938. DECLARE_MAC_BUF(mac);
  939. DECLARE_MAC_BUF(mac2);
  940. DECLARE_MAC_BUF(mac3);
  941. DECLARE_MAC_BUF(mac4);
  942. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  943. return -1;
  944. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  945. /* convert IEEE 802.11 header + possible LLC headers into Ethernet
  946. * header
  947. * IEEE 802.11 address fields:
  948. * ToDS FromDS Addr1 Addr2 Addr3 Addr4
  949. * 0 0 DA SA BSSID n/a
  950. * 0 1 DA BSSID SA n/a
  951. * 1 0 BSSID SA DA n/a
  952. * 1 1 RA TA DA SA
  953. */
  954. memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
  955. memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
  956. switch (hdr->frame_control &
  957. cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
  958. case __constant_cpu_to_le16(IEEE80211_FCTL_TODS):
  959. if (unlikely(sdata->vif.type != NL80211_IFTYPE_AP &&
  960. sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
  961. return -1;
  962. break;
  963. case __constant_cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
  964. if (unlikely(sdata->vif.type != NL80211_IFTYPE_WDS &&
  965. sdata->vif.type != NL80211_IFTYPE_MESH_POINT))
  966. return -1;
  967. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  968. struct ieee80211s_hdr *meshdr = (struct ieee80211s_hdr *)
  969. (skb->data + hdrlen);
  970. hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
  971. if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
  972. memcpy(dst, meshdr->eaddr1, ETH_ALEN);
  973. memcpy(src, meshdr->eaddr2, ETH_ALEN);
  974. }
  975. }
  976. break;
  977. case __constant_cpu_to_le16(IEEE80211_FCTL_FROMDS):
  978. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  979. (is_multicast_ether_addr(dst) &&
  980. !compare_ether_addr(src, dev->dev_addr)))
  981. return -1;
  982. break;
  983. case __constant_cpu_to_le16(0):
  984. if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
  985. return -1;
  986. break;
  987. }
  988. if (unlikely(skb->len - hdrlen < 8))
  989. return -1;
  990. payload = skb->data + hdrlen;
  991. ethertype = (payload[6] << 8) | payload[7];
  992. if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
  993. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  994. compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
  995. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  996. * replace EtherType */
  997. skb_pull(skb, hdrlen + 6);
  998. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  999. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  1000. } else {
  1001. struct ethhdr *ehdr;
  1002. __be16 len;
  1003. skb_pull(skb, hdrlen);
  1004. len = htons(skb->len);
  1005. ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
  1006. memcpy(ehdr->h_dest, dst, ETH_ALEN);
  1007. memcpy(ehdr->h_source, src, ETH_ALEN);
  1008. ehdr->h_proto = len;
  1009. }
  1010. return 0;
  1011. }
  1012. /*
  1013. * requires that rx->skb is a frame with ethernet header
  1014. */
  1015. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  1016. {
  1017. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  1018. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1019. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1020. /*
  1021. * Allow EAPOL frames to us/the PAE group address regardless
  1022. * of whether the frame was encrypted or not.
  1023. */
  1024. if (ehdr->h_proto == htons(ETH_P_PAE) &&
  1025. (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 ||
  1026. compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
  1027. return true;
  1028. if (ieee80211_802_1x_port_control(rx) ||
  1029. ieee80211_drop_unencrypted(rx, fc))
  1030. return false;
  1031. return true;
  1032. }
  1033. /*
  1034. * requires that rx->skb is a frame with ethernet header
  1035. */
  1036. static void
  1037. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  1038. {
  1039. struct net_device *dev = rx->dev;
  1040. struct ieee80211_local *local = rx->local;
  1041. struct sk_buff *skb, *xmit_skb;
  1042. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1043. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1044. struct sta_info *dsta;
  1045. skb = rx->skb;
  1046. xmit_skb = NULL;
  1047. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1048. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1049. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  1050. (rx->flags & IEEE80211_RX_RA_MATCH)) {
  1051. if (is_multicast_ether_addr(ehdr->h_dest)) {
  1052. /*
  1053. * send multicast frames both to higher layers in
  1054. * local net stack and back to the wireless medium
  1055. */
  1056. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1057. if (!xmit_skb && net_ratelimit())
  1058. printk(KERN_DEBUG "%s: failed to clone "
  1059. "multicast frame\n", dev->name);
  1060. } else {
  1061. dsta = sta_info_get(local, skb->data);
  1062. if (dsta && dsta->sdata->dev == dev) {
  1063. /*
  1064. * The destination station is associated to
  1065. * this AP (in this VLAN), so send the frame
  1066. * directly to it and do not pass it to local
  1067. * net stack.
  1068. */
  1069. xmit_skb = skb;
  1070. skb = NULL;
  1071. }
  1072. }
  1073. }
  1074. if (skb) {
  1075. /* deliver to local stack */
  1076. skb->protocol = eth_type_trans(skb, dev);
  1077. memset(skb->cb, 0, sizeof(skb->cb));
  1078. netif_rx(skb);
  1079. }
  1080. if (xmit_skb) {
  1081. /* send to wireless media */
  1082. xmit_skb->protocol = htons(ETH_P_802_3);
  1083. skb_reset_network_header(xmit_skb);
  1084. skb_reset_mac_header(xmit_skb);
  1085. dev_queue_xmit(xmit_skb);
  1086. }
  1087. }
  1088. static ieee80211_rx_result debug_noinline
  1089. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  1090. {
  1091. struct net_device *dev = rx->dev;
  1092. struct ieee80211_local *local = rx->local;
  1093. u16 ethertype;
  1094. u8 *payload;
  1095. struct sk_buff *skb = rx->skb, *frame = NULL;
  1096. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1097. __le16 fc = hdr->frame_control;
  1098. const struct ethhdr *eth;
  1099. int remaining, err;
  1100. u8 dst[ETH_ALEN];
  1101. u8 src[ETH_ALEN];
  1102. DECLARE_MAC_BUF(mac);
  1103. if (unlikely(!ieee80211_is_data(fc)))
  1104. return RX_CONTINUE;
  1105. if (unlikely(!ieee80211_is_data_present(fc)))
  1106. return RX_DROP_MONITOR;
  1107. if (!(rx->flags & IEEE80211_RX_AMSDU))
  1108. return RX_CONTINUE;
  1109. err = ieee80211_data_to_8023(rx);
  1110. if (unlikely(err))
  1111. return RX_DROP_UNUSABLE;
  1112. skb->dev = dev;
  1113. dev->stats.rx_packets++;
  1114. dev->stats.rx_bytes += skb->len;
  1115. /* skip the wrapping header */
  1116. eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
  1117. if (!eth)
  1118. return RX_DROP_UNUSABLE;
  1119. while (skb != frame) {
  1120. u8 padding;
  1121. __be16 len = eth->h_proto;
  1122. unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
  1123. remaining = skb->len;
  1124. memcpy(dst, eth->h_dest, ETH_ALEN);
  1125. memcpy(src, eth->h_source, ETH_ALEN);
  1126. padding = ((4 - subframe_len) & 0x3);
  1127. /* the last MSDU has no padding */
  1128. if (subframe_len > remaining)
  1129. return RX_DROP_UNUSABLE;
  1130. skb_pull(skb, sizeof(struct ethhdr));
  1131. /* if last subframe reuse skb */
  1132. if (remaining <= subframe_len + padding)
  1133. frame = skb;
  1134. else {
  1135. frame = dev_alloc_skb(local->hw.extra_tx_headroom +
  1136. subframe_len);
  1137. if (frame == NULL)
  1138. return RX_DROP_UNUSABLE;
  1139. skb_reserve(frame, local->hw.extra_tx_headroom +
  1140. sizeof(struct ethhdr));
  1141. memcpy(skb_put(frame, ntohs(len)), skb->data,
  1142. ntohs(len));
  1143. eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
  1144. padding);
  1145. if (!eth) {
  1146. dev_kfree_skb(frame);
  1147. return RX_DROP_UNUSABLE;
  1148. }
  1149. }
  1150. skb_reset_network_header(frame);
  1151. frame->dev = dev;
  1152. frame->priority = skb->priority;
  1153. rx->skb = frame;
  1154. payload = frame->data;
  1155. ethertype = (payload[6] << 8) | payload[7];
  1156. if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
  1157. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  1158. compare_ether_addr(payload,
  1159. bridge_tunnel_header) == 0)) {
  1160. /* remove RFC1042 or Bridge-Tunnel
  1161. * encapsulation and replace EtherType */
  1162. skb_pull(frame, 6);
  1163. memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  1164. memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  1165. } else {
  1166. memcpy(skb_push(frame, sizeof(__be16)),
  1167. &len, sizeof(__be16));
  1168. memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  1169. memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  1170. }
  1171. if (!ieee80211_frame_allowed(rx, fc)) {
  1172. if (skb == frame) /* last frame */
  1173. return RX_DROP_UNUSABLE;
  1174. dev_kfree_skb(frame);
  1175. continue;
  1176. }
  1177. ieee80211_deliver_skb(rx);
  1178. }
  1179. return RX_QUEUED;
  1180. }
  1181. #ifdef CONFIG_MAC80211_MESH
  1182. static ieee80211_rx_result
  1183. ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
  1184. {
  1185. struct ieee80211_hdr *hdr;
  1186. struct ieee80211s_hdr *mesh_hdr;
  1187. unsigned int hdrlen;
  1188. struct sk_buff *skb = rx->skb, *fwd_skb;
  1189. hdr = (struct ieee80211_hdr *) skb->data;
  1190. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1191. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  1192. if (!ieee80211_is_data(hdr->frame_control))
  1193. return RX_CONTINUE;
  1194. if (!mesh_hdr->ttl)
  1195. /* illegal frame */
  1196. return RX_DROP_MONITOR;
  1197. if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6){
  1198. struct ieee80211_sub_if_data *sdata;
  1199. struct mesh_path *mppath;
  1200. sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  1201. rcu_read_lock();
  1202. mppath = mpp_path_lookup(mesh_hdr->eaddr2, sdata);
  1203. if (!mppath) {
  1204. mpp_path_add(mesh_hdr->eaddr2, hdr->addr4, sdata);
  1205. } else {
  1206. spin_lock_bh(&mppath->state_lock);
  1207. mppath->exp_time = jiffies;
  1208. if (compare_ether_addr(mppath->mpp, hdr->addr4) != 0)
  1209. memcpy(mppath->mpp, hdr->addr4, ETH_ALEN);
  1210. spin_unlock_bh(&mppath->state_lock);
  1211. }
  1212. rcu_read_unlock();
  1213. }
  1214. if (compare_ether_addr(rx->dev->dev_addr, hdr->addr3) == 0)
  1215. return RX_CONTINUE;
  1216. mesh_hdr->ttl--;
  1217. if (rx->flags & IEEE80211_RX_RA_MATCH) {
  1218. if (!mesh_hdr->ttl)
  1219. IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
  1220. dropped_frames_ttl);
  1221. else {
  1222. struct ieee80211_hdr *fwd_hdr;
  1223. fwd_skb = skb_copy(skb, GFP_ATOMIC);
  1224. if (!fwd_skb && net_ratelimit())
  1225. printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
  1226. rx->dev->name);
  1227. fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
  1228. /*
  1229. * Save TA to addr1 to send TA a path error if a
  1230. * suitable next hop is not found
  1231. */
  1232. memcpy(fwd_hdr->addr1, fwd_hdr->addr2, ETH_ALEN);
  1233. memcpy(fwd_hdr->addr2, rx->dev->dev_addr, ETH_ALEN);
  1234. fwd_skb->dev = rx->local->mdev;
  1235. fwd_skb->iif = rx->dev->ifindex;
  1236. dev_queue_xmit(fwd_skb);
  1237. }
  1238. }
  1239. if (is_multicast_ether_addr(hdr->addr3) ||
  1240. rx->dev->flags & IFF_PROMISC)
  1241. return RX_CONTINUE;
  1242. else
  1243. return RX_DROP_MONITOR;
  1244. }
  1245. #endif
  1246. static ieee80211_rx_result debug_noinline
  1247. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  1248. {
  1249. struct net_device *dev = rx->dev;
  1250. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1251. __le16 fc = hdr->frame_control;
  1252. int err;
  1253. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  1254. return RX_CONTINUE;
  1255. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  1256. return RX_DROP_MONITOR;
  1257. err = ieee80211_data_to_8023(rx);
  1258. if (unlikely(err))
  1259. return RX_DROP_UNUSABLE;
  1260. if (!ieee80211_frame_allowed(rx, fc))
  1261. return RX_DROP_MONITOR;
  1262. rx->skb->dev = dev;
  1263. dev->stats.rx_packets++;
  1264. dev->stats.rx_bytes += rx->skb->len;
  1265. ieee80211_deliver_skb(rx);
  1266. return RX_QUEUED;
  1267. }
  1268. static ieee80211_rx_result debug_noinline
  1269. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
  1270. {
  1271. struct ieee80211_local *local = rx->local;
  1272. struct ieee80211_hw *hw = &local->hw;
  1273. struct sk_buff *skb = rx->skb;
  1274. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  1275. struct tid_ampdu_rx *tid_agg_rx;
  1276. u16 start_seq_num;
  1277. u16 tid;
  1278. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  1279. return RX_CONTINUE;
  1280. if (ieee80211_is_back_req(bar->frame_control)) {
  1281. if (!rx->sta)
  1282. return RX_CONTINUE;
  1283. tid = le16_to_cpu(bar->control) >> 12;
  1284. if (rx->sta->ampdu_mlme.tid_state_rx[tid]
  1285. != HT_AGG_STATE_OPERATIONAL)
  1286. return RX_CONTINUE;
  1287. tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid];
  1288. start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
  1289. /* reset session timer */
  1290. if (tid_agg_rx->timeout) {
  1291. unsigned long expires =
  1292. jiffies + (tid_agg_rx->timeout / 1000) * HZ;
  1293. mod_timer(&tid_agg_rx->session_timer, expires);
  1294. }
  1295. /* manage reordering buffer according to requested */
  1296. /* sequence number */
  1297. rcu_read_lock();
  1298. ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
  1299. start_seq_num, 1);
  1300. rcu_read_unlock();
  1301. return RX_DROP_UNUSABLE;
  1302. }
  1303. return RX_CONTINUE;
  1304. }
  1305. static ieee80211_rx_result debug_noinline
  1306. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  1307. {
  1308. struct ieee80211_local *local = rx->local;
  1309. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  1310. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  1311. int len = rx->skb->len;
  1312. if (!ieee80211_is_action(mgmt->frame_control))
  1313. return RX_CONTINUE;
  1314. if (!rx->sta)
  1315. return RX_DROP_MONITOR;
  1316. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  1317. return RX_DROP_MONITOR;
  1318. /* all categories we currently handle have action_code */
  1319. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  1320. return RX_DROP_MONITOR;
  1321. /*
  1322. * FIXME: revisit this, I'm sure we should handle most
  1323. * of these frames in other modes as well!
  1324. */
  1325. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1326. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  1327. return RX_CONTINUE;
  1328. switch (mgmt->u.action.category) {
  1329. case WLAN_CATEGORY_BACK:
  1330. switch (mgmt->u.action.u.addba_req.action_code) {
  1331. case WLAN_ACTION_ADDBA_REQ:
  1332. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1333. sizeof(mgmt->u.action.u.addba_req)))
  1334. return RX_DROP_MONITOR;
  1335. ieee80211_process_addba_request(local, rx->sta, mgmt, len);
  1336. break;
  1337. case WLAN_ACTION_ADDBA_RESP:
  1338. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1339. sizeof(mgmt->u.action.u.addba_resp)))
  1340. return RX_DROP_MONITOR;
  1341. ieee80211_process_addba_resp(local, rx->sta, mgmt, len);
  1342. break;
  1343. case WLAN_ACTION_DELBA:
  1344. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1345. sizeof(mgmt->u.action.u.delba)))
  1346. return RX_DROP_MONITOR;
  1347. ieee80211_process_delba(sdata, rx->sta, mgmt, len);
  1348. break;
  1349. }
  1350. break;
  1351. case WLAN_CATEGORY_SPECTRUM_MGMT:
  1352. if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
  1353. return RX_DROP_MONITOR;
  1354. switch (mgmt->u.action.u.measurement.action_code) {
  1355. case WLAN_ACTION_SPCT_MSR_REQ:
  1356. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1357. sizeof(mgmt->u.action.u.measurement)))
  1358. return RX_DROP_MONITOR;
  1359. ieee80211_process_measurement_req(sdata, mgmt, len);
  1360. break;
  1361. }
  1362. break;
  1363. default:
  1364. return RX_CONTINUE;
  1365. }
  1366. rx->sta->rx_packets++;
  1367. dev_kfree_skb(rx->skb);
  1368. return RX_QUEUED;
  1369. }
  1370. static ieee80211_rx_result debug_noinline
  1371. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  1372. {
  1373. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  1374. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  1375. return RX_DROP_MONITOR;
  1376. if (ieee80211_vif_is_mesh(&sdata->vif))
  1377. return ieee80211_mesh_rx_mgmt(sdata, rx->skb, rx->status);
  1378. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1379. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  1380. return RX_DROP_MONITOR;
  1381. if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
  1382. return RX_DROP_MONITOR;
  1383. ieee80211_sta_rx_mgmt(sdata, rx->skb, rx->status);
  1384. return RX_QUEUED;
  1385. }
  1386. static void ieee80211_rx_michael_mic_report(struct net_device *dev,
  1387. struct ieee80211_hdr *hdr,
  1388. struct ieee80211_rx_data *rx)
  1389. {
  1390. int keyidx;
  1391. unsigned int hdrlen;
  1392. DECLARE_MAC_BUF(mac);
  1393. DECLARE_MAC_BUF(mac2);
  1394. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1395. if (rx->skb->len >= hdrlen + 4)
  1396. keyidx = rx->skb->data[hdrlen + 3] >> 6;
  1397. else
  1398. keyidx = -1;
  1399. if (!rx->sta) {
  1400. /*
  1401. * Some hardware seem to generate incorrect Michael MIC
  1402. * reports; ignore them to avoid triggering countermeasures.
  1403. */
  1404. goto ignore;
  1405. }
  1406. if (!ieee80211_has_protected(hdr->frame_control))
  1407. goto ignore;
  1408. if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) {
  1409. /*
  1410. * APs with pairwise keys should never receive Michael MIC
  1411. * errors for non-zero keyidx because these are reserved for
  1412. * group keys and only the AP is sending real multicast
  1413. * frames in the BSS.
  1414. */
  1415. goto ignore;
  1416. }
  1417. if (!ieee80211_is_data(hdr->frame_control) &&
  1418. !ieee80211_is_auth(hdr->frame_control))
  1419. goto ignore;
  1420. mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr);
  1421. ignore:
  1422. dev_kfree_skb(rx->skb);
  1423. rx->skb = NULL;
  1424. }
  1425. /* TODO: use IEEE80211_RX_FRAGMENTED */
  1426. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
  1427. {
  1428. struct ieee80211_sub_if_data *sdata;
  1429. struct ieee80211_local *local = rx->local;
  1430. struct ieee80211_rtap_hdr {
  1431. struct ieee80211_radiotap_header hdr;
  1432. u8 flags;
  1433. u8 rate;
  1434. __le16 chan_freq;
  1435. __le16 chan_flags;
  1436. } __attribute__ ((packed)) *rthdr;
  1437. struct sk_buff *skb = rx->skb, *skb2;
  1438. struct net_device *prev_dev = NULL;
  1439. struct ieee80211_rx_status *status = rx->status;
  1440. if (rx->flags & IEEE80211_RX_CMNTR_REPORTED)
  1441. goto out_free_skb;
  1442. if (skb_headroom(skb) < sizeof(*rthdr) &&
  1443. pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
  1444. goto out_free_skb;
  1445. rthdr = (void *)skb_push(skb, sizeof(*rthdr));
  1446. memset(rthdr, 0, sizeof(*rthdr));
  1447. rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
  1448. rthdr->hdr.it_present =
  1449. cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  1450. (1 << IEEE80211_RADIOTAP_RATE) |
  1451. (1 << IEEE80211_RADIOTAP_CHANNEL));
  1452. rthdr->rate = rx->rate->bitrate / 5;
  1453. rthdr->chan_freq = cpu_to_le16(status->freq);
  1454. if (status->band == IEEE80211_BAND_5GHZ)
  1455. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
  1456. IEEE80211_CHAN_5GHZ);
  1457. else
  1458. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
  1459. IEEE80211_CHAN_2GHZ);
  1460. skb_set_mac_header(skb, 0);
  1461. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1462. skb->pkt_type = PACKET_OTHERHOST;
  1463. skb->protocol = htons(ETH_P_802_2);
  1464. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1465. if (!netif_running(sdata->dev))
  1466. continue;
  1467. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  1468. !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  1469. continue;
  1470. if (prev_dev) {
  1471. skb2 = skb_clone(skb, GFP_ATOMIC);
  1472. if (skb2) {
  1473. skb2->dev = prev_dev;
  1474. netif_rx(skb2);
  1475. }
  1476. }
  1477. prev_dev = sdata->dev;
  1478. sdata->dev->stats.rx_packets++;
  1479. sdata->dev->stats.rx_bytes += skb->len;
  1480. }
  1481. if (prev_dev) {
  1482. skb->dev = prev_dev;
  1483. netif_rx(skb);
  1484. skb = NULL;
  1485. } else
  1486. goto out_free_skb;
  1487. rx->flags |= IEEE80211_RX_CMNTR_REPORTED;
  1488. return;
  1489. out_free_skb:
  1490. dev_kfree_skb(skb);
  1491. }
  1492. static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
  1493. struct ieee80211_rx_data *rx,
  1494. struct sk_buff *skb)
  1495. {
  1496. ieee80211_rx_result res = RX_DROP_MONITOR;
  1497. rx->skb = skb;
  1498. rx->sdata = sdata;
  1499. rx->dev = sdata->dev;
  1500. #define CALL_RXH(rxh) \
  1501. do { \
  1502. res = rxh(rx); \
  1503. if (res != RX_CONTINUE) \
  1504. goto rxh_done; \
  1505. } while (0);
  1506. CALL_RXH(ieee80211_rx_h_passive_scan)
  1507. CALL_RXH(ieee80211_rx_h_check)
  1508. CALL_RXH(ieee80211_rx_h_decrypt)
  1509. CALL_RXH(ieee80211_rx_h_sta_process)
  1510. CALL_RXH(ieee80211_rx_h_defragment)
  1511. CALL_RXH(ieee80211_rx_h_ps_poll)
  1512. CALL_RXH(ieee80211_rx_h_michael_mic_verify)
  1513. /* must be after MMIC verify so header is counted in MPDU mic */
  1514. CALL_RXH(ieee80211_rx_h_remove_qos_control)
  1515. CALL_RXH(ieee80211_rx_h_amsdu)
  1516. #ifdef CONFIG_MAC80211_MESH
  1517. if (ieee80211_vif_is_mesh(&sdata->vif))
  1518. CALL_RXH(ieee80211_rx_h_mesh_fwding);
  1519. #endif
  1520. CALL_RXH(ieee80211_rx_h_data)
  1521. CALL_RXH(ieee80211_rx_h_ctrl)
  1522. CALL_RXH(ieee80211_rx_h_action)
  1523. CALL_RXH(ieee80211_rx_h_mgmt)
  1524. #undef CALL_RXH
  1525. rxh_done:
  1526. switch (res) {
  1527. case RX_DROP_MONITOR:
  1528. I802_DEBUG_INC(sdata->local->rx_handlers_drop);
  1529. if (rx->sta)
  1530. rx->sta->rx_dropped++;
  1531. /* fall through */
  1532. case RX_CONTINUE:
  1533. ieee80211_rx_cooked_monitor(rx);
  1534. break;
  1535. case RX_DROP_UNUSABLE:
  1536. I802_DEBUG_INC(sdata->local->rx_handlers_drop);
  1537. if (rx->sta)
  1538. rx->sta->rx_dropped++;
  1539. dev_kfree_skb(rx->skb);
  1540. break;
  1541. case RX_QUEUED:
  1542. I802_DEBUG_INC(sdata->local->rx_handlers_queued);
  1543. break;
  1544. }
  1545. }
  1546. /* main receive path */
  1547. static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
  1548. u8 *bssid, struct ieee80211_rx_data *rx,
  1549. struct ieee80211_hdr *hdr)
  1550. {
  1551. int multicast = is_multicast_ether_addr(hdr->addr1);
  1552. switch (sdata->vif.type) {
  1553. case NL80211_IFTYPE_STATION:
  1554. if (!bssid)
  1555. return 0;
  1556. if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
  1557. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  1558. return 0;
  1559. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1560. } else if (!multicast &&
  1561. compare_ether_addr(sdata->dev->dev_addr,
  1562. hdr->addr1) != 0) {
  1563. if (!(sdata->dev->flags & IFF_PROMISC))
  1564. return 0;
  1565. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1566. }
  1567. break;
  1568. case NL80211_IFTYPE_ADHOC:
  1569. if (!bssid)
  1570. return 0;
  1571. if (ieee80211_is_beacon(hdr->frame_control)) {
  1572. return 1;
  1573. }
  1574. else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
  1575. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  1576. return 0;
  1577. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1578. } else if (!multicast &&
  1579. compare_ether_addr(sdata->dev->dev_addr,
  1580. hdr->addr1) != 0) {
  1581. if (!(sdata->dev->flags & IFF_PROMISC))
  1582. return 0;
  1583. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1584. } else if (!rx->sta)
  1585. rx->sta = ieee80211_ibss_add_sta(sdata, rx->skb,
  1586. bssid, hdr->addr2,
  1587. BIT(rx->status->rate_idx));
  1588. break;
  1589. case NL80211_IFTYPE_MESH_POINT:
  1590. if (!multicast &&
  1591. compare_ether_addr(sdata->dev->dev_addr,
  1592. hdr->addr1) != 0) {
  1593. if (!(sdata->dev->flags & IFF_PROMISC))
  1594. return 0;
  1595. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1596. }
  1597. break;
  1598. case NL80211_IFTYPE_AP_VLAN:
  1599. case NL80211_IFTYPE_AP:
  1600. if (!bssid) {
  1601. if (compare_ether_addr(sdata->dev->dev_addr,
  1602. hdr->addr1))
  1603. return 0;
  1604. } else if (!ieee80211_bssid_match(bssid,
  1605. sdata->dev->dev_addr)) {
  1606. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  1607. return 0;
  1608. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1609. }
  1610. break;
  1611. case NL80211_IFTYPE_WDS:
  1612. if (bssid || !ieee80211_is_data(hdr->frame_control))
  1613. return 0;
  1614. if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
  1615. return 0;
  1616. break;
  1617. case NL80211_IFTYPE_MONITOR:
  1618. /* take everything */
  1619. break;
  1620. case NL80211_IFTYPE_UNSPECIFIED:
  1621. case __NL80211_IFTYPE_AFTER_LAST:
  1622. /* should never get here */
  1623. WARN_ON(1);
  1624. break;
  1625. }
  1626. return 1;
  1627. }
  1628. /*
  1629. * This is the actual Rx frames handler. as it blongs to Rx path it must
  1630. * be called with rcu_read_lock protection.
  1631. */
  1632. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  1633. struct sk_buff *skb,
  1634. struct ieee80211_rx_status *status,
  1635. struct ieee80211_rate *rate)
  1636. {
  1637. struct ieee80211_local *local = hw_to_local(hw);
  1638. struct ieee80211_sub_if_data *sdata;
  1639. struct ieee80211_hdr *hdr;
  1640. struct ieee80211_rx_data rx;
  1641. int prepares;
  1642. struct ieee80211_sub_if_data *prev = NULL;
  1643. struct sk_buff *skb_new;
  1644. u8 *bssid;
  1645. hdr = (struct ieee80211_hdr *)skb->data;
  1646. memset(&rx, 0, sizeof(rx));
  1647. rx.skb = skb;
  1648. rx.local = local;
  1649. rx.status = status;
  1650. rx.rate = rate;
  1651. if (ieee80211_is_data(hdr->frame_control) || ieee80211_is_mgmt(hdr->frame_control))
  1652. local->dot11ReceivedFragmentCount++;
  1653. rx.sta = sta_info_get(local, hdr->addr2);
  1654. if (rx.sta) {
  1655. rx.sdata = rx.sta->sdata;
  1656. rx.dev = rx.sta->sdata->dev;
  1657. }
  1658. if ((status->flag & RX_FLAG_MMIC_ERROR)) {
  1659. ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx);
  1660. return;
  1661. }
  1662. if (unlikely(local->sw_scanning || local->hw_scanning))
  1663. rx.flags |= IEEE80211_RX_IN_SCAN;
  1664. ieee80211_parse_qos(&rx);
  1665. ieee80211_verify_ip_alignment(&rx);
  1666. skb = rx.skb;
  1667. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1668. if (!netif_running(sdata->dev))
  1669. continue;
  1670. if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
  1671. continue;
  1672. bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  1673. rx.flags |= IEEE80211_RX_RA_MATCH;
  1674. prepares = prepare_for_handlers(sdata, bssid, &rx, hdr);
  1675. if (!prepares)
  1676. continue;
  1677. /*
  1678. * frame is destined for this interface, but if it's not
  1679. * also for the previous one we handle that after the
  1680. * loop to avoid copying the SKB once too much
  1681. */
  1682. if (!prev) {
  1683. prev = sdata;
  1684. continue;
  1685. }
  1686. /*
  1687. * frame was destined for the previous interface
  1688. * so invoke RX handlers for it
  1689. */
  1690. skb_new = skb_copy(skb, GFP_ATOMIC);
  1691. if (!skb_new) {
  1692. if (net_ratelimit())
  1693. printk(KERN_DEBUG "%s: failed to copy "
  1694. "multicast frame for %s\n",
  1695. wiphy_name(local->hw.wiphy),
  1696. prev->dev->name);
  1697. continue;
  1698. }
  1699. ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
  1700. prev = sdata;
  1701. }
  1702. if (prev)
  1703. ieee80211_invoke_rx_handlers(prev, &rx, skb);
  1704. else
  1705. dev_kfree_skb(skb);
  1706. }
  1707. #define SEQ_MODULO 0x1000
  1708. #define SEQ_MASK 0xfff
  1709. static inline int seq_less(u16 sq1, u16 sq2)
  1710. {
  1711. return (((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1));
  1712. }
  1713. static inline u16 seq_inc(u16 sq)
  1714. {
  1715. return ((sq + 1) & SEQ_MASK);
  1716. }
  1717. static inline u16 seq_sub(u16 sq1, u16 sq2)
  1718. {
  1719. return ((sq1 - sq2) & SEQ_MASK);
  1720. }
  1721. /*
  1722. * As it function blongs to Rx path it must be called with
  1723. * the proper rcu_read_lock protection for its flow.
  1724. */
  1725. u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
  1726. struct tid_ampdu_rx *tid_agg_rx,
  1727. struct sk_buff *skb, u16 mpdu_seq_num,
  1728. int bar_req)
  1729. {
  1730. struct ieee80211_local *local = hw_to_local(hw);
  1731. struct ieee80211_rx_status status;
  1732. u16 head_seq_num, buf_size;
  1733. int index;
  1734. struct ieee80211_supported_band *sband;
  1735. struct ieee80211_rate *rate;
  1736. buf_size = tid_agg_rx->buf_size;
  1737. head_seq_num = tid_agg_rx->head_seq_num;
  1738. /* frame with out of date sequence number */
  1739. if (seq_less(mpdu_seq_num, head_seq_num)) {
  1740. dev_kfree_skb(skb);
  1741. return 1;
  1742. }
  1743. /* if frame sequence number exceeds our buffering window size or
  1744. * block Ack Request arrived - release stored frames */
  1745. if ((!seq_less(mpdu_seq_num, head_seq_num + buf_size)) || (bar_req)) {
  1746. /* new head to the ordering buffer */
  1747. if (bar_req)
  1748. head_seq_num = mpdu_seq_num;
  1749. else
  1750. head_seq_num =
  1751. seq_inc(seq_sub(mpdu_seq_num, buf_size));
  1752. /* release stored frames up to new head to stack */
  1753. while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  1754. index = seq_sub(tid_agg_rx->head_seq_num,
  1755. tid_agg_rx->ssn)
  1756. % tid_agg_rx->buf_size;
  1757. if (tid_agg_rx->reorder_buf[index]) {
  1758. /* release the reordered frames to stack */
  1759. memcpy(&status,
  1760. tid_agg_rx->reorder_buf[index]->cb,
  1761. sizeof(status));
  1762. sband = local->hw.wiphy->bands[status.band];
  1763. rate = &sband->bitrates[status.rate_idx];
  1764. __ieee80211_rx_handle_packet(hw,
  1765. tid_agg_rx->reorder_buf[index],
  1766. &status, rate);
  1767. tid_agg_rx->stored_mpdu_num--;
  1768. tid_agg_rx->reorder_buf[index] = NULL;
  1769. }
  1770. tid_agg_rx->head_seq_num =
  1771. seq_inc(tid_agg_rx->head_seq_num);
  1772. }
  1773. if (bar_req)
  1774. return 1;
  1775. }
  1776. /* now the new frame is always in the range of the reordering */
  1777. /* buffer window */
  1778. index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn)
  1779. % tid_agg_rx->buf_size;
  1780. /* check if we already stored this frame */
  1781. if (tid_agg_rx->reorder_buf[index]) {
  1782. dev_kfree_skb(skb);
  1783. return 1;
  1784. }
  1785. /* if arrived mpdu is in the right order and nothing else stored */
  1786. /* release it immediately */
  1787. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  1788. tid_agg_rx->stored_mpdu_num == 0) {
  1789. tid_agg_rx->head_seq_num =
  1790. seq_inc(tid_agg_rx->head_seq_num);
  1791. return 0;
  1792. }
  1793. /* put the frame in the reordering buffer */
  1794. tid_agg_rx->reorder_buf[index] = skb;
  1795. tid_agg_rx->stored_mpdu_num++;
  1796. /* release the buffer until next missing frame */
  1797. index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
  1798. % tid_agg_rx->buf_size;
  1799. while (tid_agg_rx->reorder_buf[index]) {
  1800. /* release the reordered frame back to stack */
  1801. memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
  1802. sizeof(status));
  1803. sband = local->hw.wiphy->bands[status.band];
  1804. rate = &sband->bitrates[status.rate_idx];
  1805. __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
  1806. &status, rate);
  1807. tid_agg_rx->stored_mpdu_num--;
  1808. tid_agg_rx->reorder_buf[index] = NULL;
  1809. tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
  1810. index = seq_sub(tid_agg_rx->head_seq_num,
  1811. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  1812. }
  1813. return 1;
  1814. }
  1815. static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
  1816. struct sk_buff *skb)
  1817. {
  1818. struct ieee80211_hw *hw = &local->hw;
  1819. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1820. struct sta_info *sta;
  1821. struct tid_ampdu_rx *tid_agg_rx;
  1822. u16 sc;
  1823. u16 mpdu_seq_num;
  1824. u8 ret = 0;
  1825. int tid;
  1826. sta = sta_info_get(local, hdr->addr2);
  1827. if (!sta)
  1828. return ret;
  1829. /* filter the QoS data rx stream according to
  1830. * STA/TID and check if this STA/TID is on aggregation */
  1831. if (!ieee80211_is_data_qos(hdr->frame_control))
  1832. goto end_reorder;
  1833. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  1834. if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL)
  1835. goto end_reorder;
  1836. tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
  1837. /* qos null data frames are excluded */
  1838. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  1839. goto end_reorder;
  1840. /* new un-ordered ampdu frame - process it */
  1841. /* reset session timer */
  1842. if (tid_agg_rx->timeout) {
  1843. unsigned long expires =
  1844. jiffies + (tid_agg_rx->timeout / 1000) * HZ;
  1845. mod_timer(&tid_agg_rx->session_timer, expires);
  1846. }
  1847. /* if this mpdu is fragmented - terminate rx aggregation session */
  1848. sc = le16_to_cpu(hdr->seq_ctrl);
  1849. if (sc & IEEE80211_SCTL_FRAG) {
  1850. ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
  1851. tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
  1852. ret = 1;
  1853. goto end_reorder;
  1854. }
  1855. /* according to mpdu sequence number deal with reordering buffer */
  1856. mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1857. ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
  1858. mpdu_seq_num, 0);
  1859. end_reorder:
  1860. return ret;
  1861. }
  1862. /*
  1863. * This is the receive path handler. It is called by a low level driver when an
  1864. * 802.11 MPDU is received from the hardware.
  1865. */
  1866. void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
  1867. struct ieee80211_rx_status *status)
  1868. {
  1869. struct ieee80211_local *local = hw_to_local(hw);
  1870. struct ieee80211_rate *rate = NULL;
  1871. struct ieee80211_supported_band *sband;
  1872. if (status->band < 0 ||
  1873. status->band >= IEEE80211_NUM_BANDS) {
  1874. WARN_ON(1);
  1875. return;
  1876. }
  1877. sband = local->hw.wiphy->bands[status->band];
  1878. if (!sband ||
  1879. status->rate_idx < 0 ||
  1880. status->rate_idx >= sband->n_bitrates) {
  1881. WARN_ON(1);
  1882. return;
  1883. }
  1884. rate = &sband->bitrates[status->rate_idx];
  1885. /*
  1886. * key references and virtual interfaces are protected using RCU
  1887. * and this requires that we are in a read-side RCU section during
  1888. * receive processing
  1889. */
  1890. rcu_read_lock();
  1891. /*
  1892. * Frames with failed FCS/PLCP checksum are not returned,
  1893. * all other frames are returned without radiotap header
  1894. * if it was previously present.
  1895. * Also, frames with less than 16 bytes are dropped.
  1896. */
  1897. skb = ieee80211_rx_monitor(local, skb, status, rate);
  1898. if (!skb) {
  1899. rcu_read_unlock();
  1900. return;
  1901. }
  1902. if (!ieee80211_rx_reorder_ampdu(local, skb))
  1903. __ieee80211_rx_handle_packet(hw, skb, status, rate);
  1904. rcu_read_unlock();
  1905. }
  1906. EXPORT_SYMBOL(__ieee80211_rx);
  1907. /* This is a version of the rx handler that can be called from hard irq
  1908. * context. Post the skb on the queue and schedule the tasklet */
  1909. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
  1910. struct ieee80211_rx_status *status)
  1911. {
  1912. struct ieee80211_local *local = hw_to_local(hw);
  1913. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  1914. skb->dev = local->mdev;
  1915. /* copy status into skb->cb for use by tasklet */
  1916. memcpy(skb->cb, status, sizeof(*status));
  1917. skb->pkt_type = IEEE80211_RX_MSG;
  1918. skb_queue_tail(&local->skb_queue, skb);
  1919. tasklet_schedule(&local->tasklet);
  1920. }
  1921. EXPORT_SYMBOL(ieee80211_rx_irqsafe);