rx.c 62 KB

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