rx.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
  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. atomic_inc(&sdata->bss->num_sta_ps);
  557. set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL);
  558. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  559. printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
  560. sdata->dev->name, sta->sta.addr, sta->sta.aid);
  561. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  562. }
  563. static int ap_sta_ps_end(struct sta_info *sta)
  564. {
  565. struct ieee80211_sub_if_data *sdata = sta->sdata;
  566. struct ieee80211_local *local = sdata->local;
  567. struct sk_buff *skb;
  568. int sent = 0;
  569. struct ieee80211_tx_info *info;
  570. atomic_dec(&sdata->bss->num_sta_ps);
  571. clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL);
  572. if (!skb_queue_empty(&sta->ps_tx_buf))
  573. sta_info_clear_tim_bit(sta);
  574. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  575. printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n",
  576. sdata->dev->name, sta->sta.addr, sta->sta.aid);
  577. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  578. /* Send all buffered frames to the station */
  579. while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
  580. info = IEEE80211_SKB_CB(skb);
  581. sent++;
  582. info->flags |= IEEE80211_TX_CTL_REQUEUE;
  583. dev_queue_xmit(skb);
  584. }
  585. while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
  586. info = IEEE80211_SKB_CB(skb);
  587. local->total_ps_buffered--;
  588. sent++;
  589. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  590. printk(KERN_DEBUG "%s: STA %pM aid %d send PS frame "
  591. "since STA not sleeping anymore\n", sdata->dev->name,
  592. sta->sta.addr, sta->sta.aid);
  593. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  594. info->flags |= IEEE80211_TX_CTL_REQUEUE;
  595. dev_queue_xmit(skb);
  596. }
  597. return sent;
  598. }
  599. static ieee80211_rx_result debug_noinline
  600. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  601. {
  602. struct sta_info *sta = rx->sta;
  603. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  604. if (!sta)
  605. return RX_CONTINUE;
  606. /* Update last_rx only for IBSS packets which are for the current
  607. * BSSID to avoid keeping the current IBSS network alive in cases where
  608. * other STAs are using different BSSID. */
  609. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  610. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  611. NL80211_IFTYPE_ADHOC);
  612. if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
  613. sta->last_rx = jiffies;
  614. } else
  615. if (!is_multicast_ether_addr(hdr->addr1) ||
  616. rx->sdata->vif.type == NL80211_IFTYPE_STATION) {
  617. /* Update last_rx only for unicast frames in order to prevent
  618. * the Probe Request frames (the only broadcast frames from a
  619. * STA in infrastructure mode) from keeping a connection alive.
  620. * Mesh beacons will update last_rx when if they are found to
  621. * match the current local configuration when processed.
  622. */
  623. sta->last_rx = jiffies;
  624. }
  625. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  626. return RX_CONTINUE;
  627. sta->rx_fragments++;
  628. sta->rx_bytes += rx->skb->len;
  629. sta->last_signal = rx->status->signal;
  630. sta->last_qual = rx->status->qual;
  631. sta->last_noise = rx->status->noise;
  632. if (!ieee80211_has_morefrags(hdr->frame_control) &&
  633. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  634. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
  635. /* Change STA power saving mode only in the end of a frame
  636. * exchange sequence */
  637. if (test_sta_flags(sta, WLAN_STA_PS) &&
  638. !ieee80211_has_pm(hdr->frame_control))
  639. rx->sent_ps_buffered += ap_sta_ps_end(sta);
  640. else if (!test_sta_flags(sta, WLAN_STA_PS) &&
  641. ieee80211_has_pm(hdr->frame_control))
  642. ap_sta_ps_start(sta);
  643. }
  644. /* Drop data::nullfunc frames silently, since they are used only to
  645. * control station power saving mode. */
  646. if (ieee80211_is_nullfunc(hdr->frame_control)) {
  647. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  648. /* Update counter and free packet here to avoid counting this
  649. * as a dropped packed. */
  650. sta->rx_packets++;
  651. dev_kfree_skb(rx->skb);
  652. return RX_QUEUED;
  653. }
  654. return RX_CONTINUE;
  655. } /* ieee80211_rx_h_sta_process */
  656. static inline struct ieee80211_fragment_entry *
  657. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  658. unsigned int frag, unsigned int seq, int rx_queue,
  659. struct sk_buff **skb)
  660. {
  661. struct ieee80211_fragment_entry *entry;
  662. int idx;
  663. idx = sdata->fragment_next;
  664. entry = &sdata->fragments[sdata->fragment_next++];
  665. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  666. sdata->fragment_next = 0;
  667. if (!skb_queue_empty(&entry->skb_list)) {
  668. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  669. struct ieee80211_hdr *hdr =
  670. (struct ieee80211_hdr *) entry->skb_list.next->data;
  671. printk(KERN_DEBUG "%s: RX reassembly removed oldest "
  672. "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
  673. "addr1=%pM addr2=%pM\n",
  674. sdata->dev->name, idx,
  675. jiffies - entry->first_frag_time, entry->seq,
  676. entry->last_frag, hdr->addr1, hdr->addr2);
  677. #endif
  678. __skb_queue_purge(&entry->skb_list);
  679. }
  680. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  681. *skb = NULL;
  682. entry->first_frag_time = jiffies;
  683. entry->seq = seq;
  684. entry->rx_queue = rx_queue;
  685. entry->last_frag = frag;
  686. entry->ccmp = 0;
  687. entry->extra_len = 0;
  688. return entry;
  689. }
  690. static inline struct ieee80211_fragment_entry *
  691. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  692. unsigned int frag, unsigned int seq,
  693. int rx_queue, struct ieee80211_hdr *hdr)
  694. {
  695. struct ieee80211_fragment_entry *entry;
  696. int i, idx;
  697. idx = sdata->fragment_next;
  698. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  699. struct ieee80211_hdr *f_hdr;
  700. idx--;
  701. if (idx < 0)
  702. idx = IEEE80211_FRAGMENT_MAX - 1;
  703. entry = &sdata->fragments[idx];
  704. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  705. entry->rx_queue != rx_queue ||
  706. entry->last_frag + 1 != frag)
  707. continue;
  708. f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
  709. /*
  710. * Check ftype and addresses are equal, else check next fragment
  711. */
  712. if (((hdr->frame_control ^ f_hdr->frame_control) &
  713. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  714. compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
  715. compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
  716. continue;
  717. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  718. __skb_queue_purge(&entry->skb_list);
  719. continue;
  720. }
  721. return entry;
  722. }
  723. return NULL;
  724. }
  725. static ieee80211_rx_result debug_noinline
  726. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  727. {
  728. struct ieee80211_hdr *hdr;
  729. u16 sc;
  730. __le16 fc;
  731. unsigned int frag, seq;
  732. struct ieee80211_fragment_entry *entry;
  733. struct sk_buff *skb;
  734. hdr = (struct ieee80211_hdr *)rx->skb->data;
  735. fc = hdr->frame_control;
  736. sc = le16_to_cpu(hdr->seq_ctrl);
  737. frag = sc & IEEE80211_SCTL_FRAG;
  738. if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
  739. (rx->skb)->len < 24 ||
  740. is_multicast_ether_addr(hdr->addr1))) {
  741. /* not fragmented */
  742. goto out;
  743. }
  744. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  745. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  746. if (frag == 0) {
  747. /* This is the first fragment of a new frame. */
  748. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  749. rx->queue, &(rx->skb));
  750. if (rx->key && rx->key->conf.alg == ALG_CCMP &&
  751. ieee80211_has_protected(fc)) {
  752. /* Store CCMP PN so that we can verify that the next
  753. * fragment has a sequential PN value. */
  754. entry->ccmp = 1;
  755. memcpy(entry->last_pn,
  756. rx->key->u.ccmp.rx_pn[rx->queue],
  757. CCMP_PN_LEN);
  758. }
  759. return RX_QUEUED;
  760. }
  761. /* This is a fragment for a frame that should already be pending in
  762. * fragment cache. Add this fragment to the end of the pending entry.
  763. */
  764. entry = ieee80211_reassemble_find(rx->sdata, frag, seq, rx->queue, hdr);
  765. if (!entry) {
  766. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  767. return RX_DROP_MONITOR;
  768. }
  769. /* Verify that MPDUs within one MSDU have sequential PN values.
  770. * (IEEE 802.11i, 8.3.3.4.5) */
  771. if (entry->ccmp) {
  772. int i;
  773. u8 pn[CCMP_PN_LEN], *rpn;
  774. if (!rx->key || rx->key->conf.alg != ALG_CCMP)
  775. return RX_DROP_UNUSABLE;
  776. memcpy(pn, entry->last_pn, CCMP_PN_LEN);
  777. for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
  778. pn[i]++;
  779. if (pn[i])
  780. break;
  781. }
  782. rpn = rx->key->u.ccmp.rx_pn[rx->queue];
  783. if (memcmp(pn, rpn, CCMP_PN_LEN))
  784. return RX_DROP_UNUSABLE;
  785. memcpy(entry->last_pn, pn, CCMP_PN_LEN);
  786. }
  787. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  788. __skb_queue_tail(&entry->skb_list, rx->skb);
  789. entry->last_frag = frag;
  790. entry->extra_len += rx->skb->len;
  791. if (ieee80211_has_morefrags(fc)) {
  792. rx->skb = NULL;
  793. return RX_QUEUED;
  794. }
  795. rx->skb = __skb_dequeue(&entry->skb_list);
  796. if (skb_tailroom(rx->skb) < entry->extra_len) {
  797. I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
  798. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  799. GFP_ATOMIC))) {
  800. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  801. __skb_queue_purge(&entry->skb_list);
  802. return RX_DROP_UNUSABLE;
  803. }
  804. }
  805. while ((skb = __skb_dequeue(&entry->skb_list))) {
  806. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  807. dev_kfree_skb(skb);
  808. }
  809. /* Complete frame has been reassembled - process it now */
  810. rx->flags |= IEEE80211_RX_FRAGMENTED;
  811. out:
  812. if (rx->sta)
  813. rx->sta->rx_packets++;
  814. if (is_multicast_ether_addr(hdr->addr1))
  815. rx->local->dot11MulticastReceivedFrameCount++;
  816. else
  817. ieee80211_led_rx(rx->local);
  818. return RX_CONTINUE;
  819. }
  820. static ieee80211_rx_result debug_noinline
  821. ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
  822. {
  823. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  824. struct sk_buff *skb;
  825. int no_pending_pkts;
  826. __le16 fc = ((struct ieee80211_hdr *)rx->skb->data)->frame_control;
  827. if (likely(!rx->sta || !ieee80211_is_pspoll(fc) ||
  828. !(rx->flags & IEEE80211_RX_RA_MATCH)))
  829. return RX_CONTINUE;
  830. if ((sdata->vif.type != NL80211_IFTYPE_AP) &&
  831. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
  832. return RX_DROP_UNUSABLE;
  833. skb = skb_dequeue(&rx->sta->tx_filtered);
  834. if (!skb) {
  835. skb = skb_dequeue(&rx->sta->ps_tx_buf);
  836. if (skb)
  837. rx->local->total_ps_buffered--;
  838. }
  839. no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
  840. skb_queue_empty(&rx->sta->ps_tx_buf);
  841. if (skb) {
  842. struct ieee80211_hdr *hdr =
  843. (struct ieee80211_hdr *) skb->data;
  844. /*
  845. * Tell TX path to send one frame even though the STA may
  846. * still remain is PS mode after this frame exchange.
  847. */
  848. set_sta_flags(rx->sta, WLAN_STA_PSPOLL);
  849. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  850. printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n",
  851. rx->sta->sta.addr, rx->sta->sta.aid,
  852. skb_queue_len(&rx->sta->ps_tx_buf));
  853. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  854. /* Use MoreData flag to indicate whether there are more
  855. * buffered frames for this STA */
  856. if (no_pending_pkts)
  857. hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
  858. else
  859. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  860. dev_queue_xmit(skb);
  861. if (no_pending_pkts)
  862. sta_info_clear_tim_bit(rx->sta);
  863. #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
  864. } else if (!rx->sent_ps_buffered) {
  865. /*
  866. * FIXME: This can be the result of a race condition between
  867. * us expiring a frame and the station polling for it.
  868. * Should we send it a null-func frame indicating we
  869. * have nothing buffered for it?
  870. */
  871. printk(KERN_DEBUG "%s: STA %pM sent PS Poll even "
  872. "though there are no buffered frames for it\n",
  873. rx->dev->name, rx->sta->sta.addr);
  874. #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
  875. }
  876. /* Free PS Poll skb here instead of returning RX_DROP that would
  877. * count as an dropped frame. */
  878. dev_kfree_skb(rx->skb);
  879. return RX_QUEUED;
  880. }
  881. static ieee80211_rx_result debug_noinline
  882. ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
  883. {
  884. u8 *data = rx->skb->data;
  885. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)data;
  886. if (!ieee80211_is_data_qos(hdr->frame_control))
  887. return RX_CONTINUE;
  888. /* remove the qos control field, update frame type and meta-data */
  889. memmove(data + IEEE80211_QOS_CTL_LEN, data,
  890. ieee80211_hdrlen(hdr->frame_control) - IEEE80211_QOS_CTL_LEN);
  891. hdr = (struct ieee80211_hdr *)skb_pull(rx->skb, IEEE80211_QOS_CTL_LEN);
  892. /* change frame type to non QOS */
  893. hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  894. return RX_CONTINUE;
  895. }
  896. static int
  897. ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  898. {
  899. if (unlikely(!rx->sta ||
  900. !test_sta_flags(rx->sta, WLAN_STA_AUTHORIZED)))
  901. return -EACCES;
  902. return 0;
  903. }
  904. static int
  905. ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  906. {
  907. /*
  908. * Pass through unencrypted frames if the hardware has
  909. * decrypted them already.
  910. */
  911. if (rx->status->flag & RX_FLAG_DECRYPTED)
  912. return 0;
  913. /* Drop unencrypted frames if key is set. */
  914. if (unlikely(!ieee80211_has_protected(fc) &&
  915. !ieee80211_is_nullfunc(fc) &&
  916. (rx->key || rx->sdata->drop_unencrypted)))
  917. return -EACCES;
  918. return 0;
  919. }
  920. static int
  921. ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
  922. {
  923. struct net_device *dev = rx->dev;
  924. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
  925. u16 hdrlen, ethertype;
  926. u8 *payload;
  927. u8 dst[ETH_ALEN];
  928. u8 src[ETH_ALEN] __aligned(2);
  929. struct sk_buff *skb = rx->skb;
  930. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  931. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  932. return -1;
  933. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  934. /* convert IEEE 802.11 header + possible LLC headers into Ethernet
  935. * header
  936. * IEEE 802.11 address fields:
  937. * ToDS FromDS Addr1 Addr2 Addr3 Addr4
  938. * 0 0 DA SA BSSID n/a
  939. * 0 1 DA BSSID SA n/a
  940. * 1 0 BSSID SA DA n/a
  941. * 1 1 RA TA DA SA
  942. */
  943. memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
  944. memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
  945. switch (hdr->frame_control &
  946. cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
  947. case __constant_cpu_to_le16(IEEE80211_FCTL_TODS):
  948. if (unlikely(sdata->vif.type != NL80211_IFTYPE_AP &&
  949. sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
  950. return -1;
  951. break;
  952. case __constant_cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
  953. if (unlikely(sdata->vif.type != NL80211_IFTYPE_WDS &&
  954. sdata->vif.type != NL80211_IFTYPE_MESH_POINT))
  955. return -1;
  956. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  957. struct ieee80211s_hdr *meshdr = (struct ieee80211s_hdr *)
  958. (skb->data + hdrlen);
  959. hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
  960. if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
  961. memcpy(dst, meshdr->eaddr1, ETH_ALEN);
  962. memcpy(src, meshdr->eaddr2, ETH_ALEN);
  963. }
  964. }
  965. break;
  966. case __constant_cpu_to_le16(IEEE80211_FCTL_FROMDS):
  967. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  968. (is_multicast_ether_addr(dst) &&
  969. !compare_ether_addr(src, dev->dev_addr)))
  970. return -1;
  971. break;
  972. case __constant_cpu_to_le16(0):
  973. if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
  974. return -1;
  975. break;
  976. }
  977. if (unlikely(skb->len - hdrlen < 8))
  978. return -1;
  979. payload = skb->data + hdrlen;
  980. ethertype = (payload[6] << 8) | payload[7];
  981. if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
  982. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  983. compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
  984. /* remove RFC1042 or Bridge-Tunnel encapsulation and
  985. * replace EtherType */
  986. skb_pull(skb, hdrlen + 6);
  987. memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
  988. memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
  989. } else {
  990. struct ethhdr *ehdr;
  991. __be16 len;
  992. skb_pull(skb, hdrlen);
  993. len = htons(skb->len);
  994. ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
  995. memcpy(ehdr->h_dest, dst, ETH_ALEN);
  996. memcpy(ehdr->h_source, src, ETH_ALEN);
  997. ehdr->h_proto = len;
  998. }
  999. return 0;
  1000. }
  1001. /*
  1002. * requires that rx->skb is a frame with ethernet header
  1003. */
  1004. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  1005. {
  1006. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  1007. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1008. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1009. /*
  1010. * Allow EAPOL frames to us/the PAE group address regardless
  1011. * of whether the frame was encrypted or not.
  1012. */
  1013. if (ehdr->h_proto == htons(ETH_P_PAE) &&
  1014. (compare_ether_addr(ehdr->h_dest, rx->dev->dev_addr) == 0 ||
  1015. compare_ether_addr(ehdr->h_dest, pae_group_addr) == 0))
  1016. return true;
  1017. if (ieee80211_802_1x_port_control(rx) ||
  1018. ieee80211_drop_unencrypted(rx, fc))
  1019. return false;
  1020. return true;
  1021. }
  1022. /*
  1023. * requires that rx->skb is a frame with ethernet header
  1024. */
  1025. static void
  1026. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  1027. {
  1028. struct net_device *dev = rx->dev;
  1029. struct ieee80211_local *local = rx->local;
  1030. struct sk_buff *skb, *xmit_skb;
  1031. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1032. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1033. struct sta_info *dsta;
  1034. skb = rx->skb;
  1035. xmit_skb = NULL;
  1036. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1037. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1038. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  1039. (rx->flags & IEEE80211_RX_RA_MATCH)) {
  1040. if (is_multicast_ether_addr(ehdr->h_dest)) {
  1041. /*
  1042. * send multicast frames both to higher layers in
  1043. * local net stack and back to the wireless medium
  1044. */
  1045. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1046. if (!xmit_skb && net_ratelimit())
  1047. printk(KERN_DEBUG "%s: failed to clone "
  1048. "multicast frame\n", dev->name);
  1049. } else {
  1050. dsta = sta_info_get(local, skb->data);
  1051. if (dsta && dsta->sdata->dev == dev) {
  1052. /*
  1053. * The destination station is associated to
  1054. * this AP (in this VLAN), so send the frame
  1055. * directly to it and do not pass it to local
  1056. * net stack.
  1057. */
  1058. xmit_skb = skb;
  1059. skb = NULL;
  1060. }
  1061. }
  1062. }
  1063. if (skb) {
  1064. /* deliver to local stack */
  1065. skb->protocol = eth_type_trans(skb, dev);
  1066. memset(skb->cb, 0, sizeof(skb->cb));
  1067. netif_rx(skb);
  1068. }
  1069. if (xmit_skb) {
  1070. /* send to wireless media */
  1071. xmit_skb->protocol = htons(ETH_P_802_3);
  1072. skb_reset_network_header(xmit_skb);
  1073. skb_reset_mac_header(xmit_skb);
  1074. dev_queue_xmit(xmit_skb);
  1075. }
  1076. }
  1077. static ieee80211_rx_result debug_noinline
  1078. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  1079. {
  1080. struct net_device *dev = rx->dev;
  1081. struct ieee80211_local *local = rx->local;
  1082. u16 ethertype;
  1083. u8 *payload;
  1084. struct sk_buff *skb = rx->skb, *frame = NULL;
  1085. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1086. __le16 fc = hdr->frame_control;
  1087. const struct ethhdr *eth;
  1088. int remaining, err;
  1089. u8 dst[ETH_ALEN];
  1090. u8 src[ETH_ALEN];
  1091. if (unlikely(!ieee80211_is_data(fc)))
  1092. return RX_CONTINUE;
  1093. if (unlikely(!ieee80211_is_data_present(fc)))
  1094. return RX_DROP_MONITOR;
  1095. if (!(rx->flags & IEEE80211_RX_AMSDU))
  1096. return RX_CONTINUE;
  1097. err = ieee80211_data_to_8023(rx);
  1098. if (unlikely(err))
  1099. return RX_DROP_UNUSABLE;
  1100. skb->dev = dev;
  1101. dev->stats.rx_packets++;
  1102. dev->stats.rx_bytes += skb->len;
  1103. /* skip the wrapping header */
  1104. eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
  1105. if (!eth)
  1106. return RX_DROP_UNUSABLE;
  1107. while (skb != frame) {
  1108. u8 padding;
  1109. __be16 len = eth->h_proto;
  1110. unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
  1111. remaining = skb->len;
  1112. memcpy(dst, eth->h_dest, ETH_ALEN);
  1113. memcpy(src, eth->h_source, ETH_ALEN);
  1114. padding = ((4 - subframe_len) & 0x3);
  1115. /* the last MSDU has no padding */
  1116. if (subframe_len > remaining)
  1117. return RX_DROP_UNUSABLE;
  1118. skb_pull(skb, sizeof(struct ethhdr));
  1119. /* if last subframe reuse skb */
  1120. if (remaining <= subframe_len + padding)
  1121. frame = skb;
  1122. else {
  1123. frame = dev_alloc_skb(local->hw.extra_tx_headroom +
  1124. subframe_len);
  1125. if (frame == NULL)
  1126. return RX_DROP_UNUSABLE;
  1127. skb_reserve(frame, local->hw.extra_tx_headroom +
  1128. sizeof(struct ethhdr));
  1129. memcpy(skb_put(frame, ntohs(len)), skb->data,
  1130. ntohs(len));
  1131. eth = (struct ethhdr *) skb_pull(skb, ntohs(len) +
  1132. padding);
  1133. if (!eth) {
  1134. dev_kfree_skb(frame);
  1135. return RX_DROP_UNUSABLE;
  1136. }
  1137. }
  1138. skb_reset_network_header(frame);
  1139. frame->dev = dev;
  1140. frame->priority = skb->priority;
  1141. rx->skb = frame;
  1142. payload = frame->data;
  1143. ethertype = (payload[6] << 8) | payload[7];
  1144. if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
  1145. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  1146. compare_ether_addr(payload,
  1147. bridge_tunnel_header) == 0)) {
  1148. /* remove RFC1042 or Bridge-Tunnel
  1149. * encapsulation and replace EtherType */
  1150. skb_pull(frame, 6);
  1151. memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  1152. memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  1153. } else {
  1154. memcpy(skb_push(frame, sizeof(__be16)),
  1155. &len, sizeof(__be16));
  1156. memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  1157. memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  1158. }
  1159. if (!ieee80211_frame_allowed(rx, fc)) {
  1160. if (skb == frame) /* last frame */
  1161. return RX_DROP_UNUSABLE;
  1162. dev_kfree_skb(frame);
  1163. continue;
  1164. }
  1165. ieee80211_deliver_skb(rx);
  1166. }
  1167. return RX_QUEUED;
  1168. }
  1169. #ifdef CONFIG_MAC80211_MESH
  1170. static ieee80211_rx_result
  1171. ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
  1172. {
  1173. struct ieee80211_hdr *hdr;
  1174. struct ieee80211s_hdr *mesh_hdr;
  1175. unsigned int hdrlen;
  1176. struct sk_buff *skb = rx->skb, *fwd_skb;
  1177. hdr = (struct ieee80211_hdr *) skb->data;
  1178. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1179. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  1180. if (!ieee80211_is_data(hdr->frame_control))
  1181. return RX_CONTINUE;
  1182. if (!mesh_hdr->ttl)
  1183. /* illegal frame */
  1184. return RX_DROP_MONITOR;
  1185. if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6){
  1186. struct ieee80211_sub_if_data *sdata;
  1187. struct mesh_path *mppath;
  1188. sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  1189. rcu_read_lock();
  1190. mppath = mpp_path_lookup(mesh_hdr->eaddr2, sdata);
  1191. if (!mppath) {
  1192. mpp_path_add(mesh_hdr->eaddr2, hdr->addr4, sdata);
  1193. } else {
  1194. spin_lock_bh(&mppath->state_lock);
  1195. mppath->exp_time = jiffies;
  1196. if (compare_ether_addr(mppath->mpp, hdr->addr4) != 0)
  1197. memcpy(mppath->mpp, hdr->addr4, ETH_ALEN);
  1198. spin_unlock_bh(&mppath->state_lock);
  1199. }
  1200. rcu_read_unlock();
  1201. }
  1202. if (compare_ether_addr(rx->dev->dev_addr, hdr->addr3) == 0)
  1203. return RX_CONTINUE;
  1204. mesh_hdr->ttl--;
  1205. if (rx->flags & IEEE80211_RX_RA_MATCH) {
  1206. if (!mesh_hdr->ttl)
  1207. IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
  1208. dropped_frames_ttl);
  1209. else {
  1210. struct ieee80211_hdr *fwd_hdr;
  1211. fwd_skb = skb_copy(skb, GFP_ATOMIC);
  1212. if (!fwd_skb && net_ratelimit())
  1213. printk(KERN_DEBUG "%s: failed to clone mesh frame\n",
  1214. rx->dev->name);
  1215. fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
  1216. /*
  1217. * Save TA to addr1 to send TA a path error if a
  1218. * suitable next hop is not found
  1219. */
  1220. memcpy(fwd_hdr->addr1, fwd_hdr->addr2, ETH_ALEN);
  1221. memcpy(fwd_hdr->addr2, rx->dev->dev_addr, ETH_ALEN);
  1222. fwd_skb->dev = rx->local->mdev;
  1223. fwd_skb->iif = rx->dev->ifindex;
  1224. dev_queue_xmit(fwd_skb);
  1225. }
  1226. }
  1227. if (is_multicast_ether_addr(hdr->addr3) ||
  1228. rx->dev->flags & IFF_PROMISC)
  1229. return RX_CONTINUE;
  1230. else
  1231. return RX_DROP_MONITOR;
  1232. }
  1233. #endif
  1234. static ieee80211_rx_result debug_noinline
  1235. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  1236. {
  1237. struct net_device *dev = rx->dev;
  1238. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1239. __le16 fc = hdr->frame_control;
  1240. int err;
  1241. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  1242. return RX_CONTINUE;
  1243. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  1244. return RX_DROP_MONITOR;
  1245. err = ieee80211_data_to_8023(rx);
  1246. if (unlikely(err))
  1247. return RX_DROP_UNUSABLE;
  1248. if (!ieee80211_frame_allowed(rx, fc))
  1249. return RX_DROP_MONITOR;
  1250. rx->skb->dev = dev;
  1251. dev->stats.rx_packets++;
  1252. dev->stats.rx_bytes += rx->skb->len;
  1253. ieee80211_deliver_skb(rx);
  1254. return RX_QUEUED;
  1255. }
  1256. static ieee80211_rx_result debug_noinline
  1257. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
  1258. {
  1259. struct ieee80211_local *local = rx->local;
  1260. struct ieee80211_hw *hw = &local->hw;
  1261. struct sk_buff *skb = rx->skb;
  1262. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  1263. struct tid_ampdu_rx *tid_agg_rx;
  1264. u16 start_seq_num;
  1265. u16 tid;
  1266. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  1267. return RX_CONTINUE;
  1268. if (ieee80211_is_back_req(bar->frame_control)) {
  1269. if (!rx->sta)
  1270. return RX_CONTINUE;
  1271. tid = le16_to_cpu(bar->control) >> 12;
  1272. if (rx->sta->ampdu_mlme.tid_state_rx[tid]
  1273. != HT_AGG_STATE_OPERATIONAL)
  1274. return RX_CONTINUE;
  1275. tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid];
  1276. start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
  1277. /* reset session timer */
  1278. if (tid_agg_rx->timeout) {
  1279. unsigned long expires =
  1280. jiffies + (tid_agg_rx->timeout / 1000) * HZ;
  1281. mod_timer(&tid_agg_rx->session_timer, expires);
  1282. }
  1283. /* manage reordering buffer according to requested */
  1284. /* sequence number */
  1285. rcu_read_lock();
  1286. ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
  1287. start_seq_num, 1);
  1288. rcu_read_unlock();
  1289. return RX_DROP_UNUSABLE;
  1290. }
  1291. return RX_CONTINUE;
  1292. }
  1293. static ieee80211_rx_result debug_noinline
  1294. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  1295. {
  1296. struct ieee80211_local *local = rx->local;
  1297. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  1298. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  1299. int len = rx->skb->len;
  1300. if (!ieee80211_is_action(mgmt->frame_control))
  1301. return RX_CONTINUE;
  1302. if (!rx->sta)
  1303. return RX_DROP_MONITOR;
  1304. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  1305. return RX_DROP_MONITOR;
  1306. /* all categories we currently handle have action_code */
  1307. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  1308. return RX_DROP_MONITOR;
  1309. /*
  1310. * FIXME: revisit this, I'm sure we should handle most
  1311. * of these frames in other modes as well!
  1312. */
  1313. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1314. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  1315. return RX_CONTINUE;
  1316. switch (mgmt->u.action.category) {
  1317. case WLAN_CATEGORY_BACK:
  1318. switch (mgmt->u.action.u.addba_req.action_code) {
  1319. case WLAN_ACTION_ADDBA_REQ:
  1320. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1321. sizeof(mgmt->u.action.u.addba_req)))
  1322. return RX_DROP_MONITOR;
  1323. ieee80211_process_addba_request(local, rx->sta, mgmt, len);
  1324. break;
  1325. case WLAN_ACTION_ADDBA_RESP:
  1326. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1327. sizeof(mgmt->u.action.u.addba_resp)))
  1328. return RX_DROP_MONITOR;
  1329. ieee80211_process_addba_resp(local, rx->sta, mgmt, len);
  1330. break;
  1331. case WLAN_ACTION_DELBA:
  1332. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1333. sizeof(mgmt->u.action.u.delba)))
  1334. return RX_DROP_MONITOR;
  1335. ieee80211_process_delba(sdata, rx->sta, mgmt, len);
  1336. break;
  1337. }
  1338. break;
  1339. case WLAN_CATEGORY_SPECTRUM_MGMT:
  1340. if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
  1341. return RX_DROP_MONITOR;
  1342. switch (mgmt->u.action.u.measurement.action_code) {
  1343. case WLAN_ACTION_SPCT_MSR_REQ:
  1344. if (len < (IEEE80211_MIN_ACTION_SIZE +
  1345. sizeof(mgmt->u.action.u.measurement)))
  1346. return RX_DROP_MONITOR;
  1347. ieee80211_process_measurement_req(sdata, mgmt, len);
  1348. break;
  1349. }
  1350. break;
  1351. default:
  1352. return RX_CONTINUE;
  1353. }
  1354. rx->sta->rx_packets++;
  1355. dev_kfree_skb(rx->skb);
  1356. return RX_QUEUED;
  1357. }
  1358. static ieee80211_rx_result debug_noinline
  1359. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  1360. {
  1361. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
  1362. if (!(rx->flags & IEEE80211_RX_RA_MATCH))
  1363. return RX_DROP_MONITOR;
  1364. if (ieee80211_vif_is_mesh(&sdata->vif))
  1365. return ieee80211_mesh_rx_mgmt(sdata, rx->skb, rx->status);
  1366. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  1367. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  1368. return RX_DROP_MONITOR;
  1369. if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
  1370. return RX_DROP_MONITOR;
  1371. ieee80211_sta_rx_mgmt(sdata, rx->skb, rx->status);
  1372. return RX_QUEUED;
  1373. }
  1374. static void ieee80211_rx_michael_mic_report(struct net_device *dev,
  1375. struct ieee80211_hdr *hdr,
  1376. struct ieee80211_rx_data *rx)
  1377. {
  1378. int keyidx;
  1379. unsigned int hdrlen;
  1380. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1381. if (rx->skb->len >= hdrlen + 4)
  1382. keyidx = rx->skb->data[hdrlen + 3] >> 6;
  1383. else
  1384. keyidx = -1;
  1385. if (!rx->sta) {
  1386. /*
  1387. * Some hardware seem to generate incorrect Michael MIC
  1388. * reports; ignore them to avoid triggering countermeasures.
  1389. */
  1390. goto ignore;
  1391. }
  1392. if (!ieee80211_has_protected(hdr->frame_control))
  1393. goto ignore;
  1394. if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) {
  1395. /*
  1396. * APs with pairwise keys should never receive Michael MIC
  1397. * errors for non-zero keyidx because these are reserved for
  1398. * group keys and only the AP is sending real multicast
  1399. * frames in the BSS.
  1400. */
  1401. goto ignore;
  1402. }
  1403. if (!ieee80211_is_data(hdr->frame_control) &&
  1404. !ieee80211_is_auth(hdr->frame_control))
  1405. goto ignore;
  1406. mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr);
  1407. ignore:
  1408. dev_kfree_skb(rx->skb);
  1409. rx->skb = NULL;
  1410. }
  1411. /* TODO: use IEEE80211_RX_FRAGMENTED */
  1412. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
  1413. {
  1414. struct ieee80211_sub_if_data *sdata;
  1415. struct ieee80211_local *local = rx->local;
  1416. struct ieee80211_rtap_hdr {
  1417. struct ieee80211_radiotap_header hdr;
  1418. u8 flags;
  1419. u8 rate;
  1420. __le16 chan_freq;
  1421. __le16 chan_flags;
  1422. } __attribute__ ((packed)) *rthdr;
  1423. struct sk_buff *skb = rx->skb, *skb2;
  1424. struct net_device *prev_dev = NULL;
  1425. struct ieee80211_rx_status *status = rx->status;
  1426. if (rx->flags & IEEE80211_RX_CMNTR_REPORTED)
  1427. goto out_free_skb;
  1428. if (skb_headroom(skb) < sizeof(*rthdr) &&
  1429. pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
  1430. goto out_free_skb;
  1431. rthdr = (void *)skb_push(skb, sizeof(*rthdr));
  1432. memset(rthdr, 0, sizeof(*rthdr));
  1433. rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
  1434. rthdr->hdr.it_present =
  1435. cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  1436. (1 << IEEE80211_RADIOTAP_RATE) |
  1437. (1 << IEEE80211_RADIOTAP_CHANNEL));
  1438. rthdr->rate = rx->rate->bitrate / 5;
  1439. rthdr->chan_freq = cpu_to_le16(status->freq);
  1440. if (status->band == IEEE80211_BAND_5GHZ)
  1441. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
  1442. IEEE80211_CHAN_5GHZ);
  1443. else
  1444. rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
  1445. IEEE80211_CHAN_2GHZ);
  1446. skb_set_mac_header(skb, 0);
  1447. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1448. skb->pkt_type = PACKET_OTHERHOST;
  1449. skb->protocol = htons(ETH_P_802_2);
  1450. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1451. if (!netif_running(sdata->dev))
  1452. continue;
  1453. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  1454. !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  1455. continue;
  1456. if (prev_dev) {
  1457. skb2 = skb_clone(skb, GFP_ATOMIC);
  1458. if (skb2) {
  1459. skb2->dev = prev_dev;
  1460. netif_rx(skb2);
  1461. }
  1462. }
  1463. prev_dev = sdata->dev;
  1464. sdata->dev->stats.rx_packets++;
  1465. sdata->dev->stats.rx_bytes += skb->len;
  1466. }
  1467. if (prev_dev) {
  1468. skb->dev = prev_dev;
  1469. netif_rx(skb);
  1470. skb = NULL;
  1471. } else
  1472. goto out_free_skb;
  1473. rx->flags |= IEEE80211_RX_CMNTR_REPORTED;
  1474. return;
  1475. out_free_skb:
  1476. dev_kfree_skb(skb);
  1477. }
  1478. static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
  1479. struct ieee80211_rx_data *rx,
  1480. struct sk_buff *skb)
  1481. {
  1482. ieee80211_rx_result res = RX_DROP_MONITOR;
  1483. rx->skb = skb;
  1484. rx->sdata = sdata;
  1485. rx->dev = sdata->dev;
  1486. #define CALL_RXH(rxh) \
  1487. do { \
  1488. res = rxh(rx); \
  1489. if (res != RX_CONTINUE) \
  1490. goto rxh_done; \
  1491. } while (0);
  1492. CALL_RXH(ieee80211_rx_h_passive_scan)
  1493. CALL_RXH(ieee80211_rx_h_check)
  1494. CALL_RXH(ieee80211_rx_h_decrypt)
  1495. CALL_RXH(ieee80211_rx_h_sta_process)
  1496. CALL_RXH(ieee80211_rx_h_defragment)
  1497. CALL_RXH(ieee80211_rx_h_ps_poll)
  1498. CALL_RXH(ieee80211_rx_h_michael_mic_verify)
  1499. /* must be after MMIC verify so header is counted in MPDU mic */
  1500. CALL_RXH(ieee80211_rx_h_remove_qos_control)
  1501. CALL_RXH(ieee80211_rx_h_amsdu)
  1502. #ifdef CONFIG_MAC80211_MESH
  1503. if (ieee80211_vif_is_mesh(&sdata->vif))
  1504. CALL_RXH(ieee80211_rx_h_mesh_fwding);
  1505. #endif
  1506. CALL_RXH(ieee80211_rx_h_data)
  1507. CALL_RXH(ieee80211_rx_h_ctrl)
  1508. CALL_RXH(ieee80211_rx_h_action)
  1509. CALL_RXH(ieee80211_rx_h_mgmt)
  1510. #undef CALL_RXH
  1511. rxh_done:
  1512. switch (res) {
  1513. case RX_DROP_MONITOR:
  1514. I802_DEBUG_INC(sdata->local->rx_handlers_drop);
  1515. if (rx->sta)
  1516. rx->sta->rx_dropped++;
  1517. /* fall through */
  1518. case RX_CONTINUE:
  1519. ieee80211_rx_cooked_monitor(rx);
  1520. break;
  1521. case RX_DROP_UNUSABLE:
  1522. I802_DEBUG_INC(sdata->local->rx_handlers_drop);
  1523. if (rx->sta)
  1524. rx->sta->rx_dropped++;
  1525. dev_kfree_skb(rx->skb);
  1526. break;
  1527. case RX_QUEUED:
  1528. I802_DEBUG_INC(sdata->local->rx_handlers_queued);
  1529. break;
  1530. }
  1531. }
  1532. /* main receive path */
  1533. static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
  1534. u8 *bssid, struct ieee80211_rx_data *rx,
  1535. struct ieee80211_hdr *hdr)
  1536. {
  1537. int multicast = is_multicast_ether_addr(hdr->addr1);
  1538. switch (sdata->vif.type) {
  1539. case NL80211_IFTYPE_STATION:
  1540. if (!bssid)
  1541. return 0;
  1542. if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
  1543. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  1544. return 0;
  1545. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1546. } else if (!multicast &&
  1547. compare_ether_addr(sdata->dev->dev_addr,
  1548. hdr->addr1) != 0) {
  1549. if (!(sdata->dev->flags & IFF_PROMISC))
  1550. return 0;
  1551. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1552. }
  1553. break;
  1554. case NL80211_IFTYPE_ADHOC:
  1555. if (!bssid)
  1556. return 0;
  1557. if (ieee80211_is_beacon(hdr->frame_control)) {
  1558. return 1;
  1559. }
  1560. else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
  1561. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  1562. return 0;
  1563. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1564. } else if (!multicast &&
  1565. compare_ether_addr(sdata->dev->dev_addr,
  1566. hdr->addr1) != 0) {
  1567. if (!(sdata->dev->flags & IFF_PROMISC))
  1568. return 0;
  1569. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1570. } else if (!rx->sta)
  1571. rx->sta = ieee80211_ibss_add_sta(sdata, rx->skb,
  1572. bssid, hdr->addr2,
  1573. BIT(rx->status->rate_idx));
  1574. break;
  1575. case NL80211_IFTYPE_MESH_POINT:
  1576. if (!multicast &&
  1577. compare_ether_addr(sdata->dev->dev_addr,
  1578. hdr->addr1) != 0) {
  1579. if (!(sdata->dev->flags & IFF_PROMISC))
  1580. return 0;
  1581. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1582. }
  1583. break;
  1584. case NL80211_IFTYPE_AP_VLAN:
  1585. case NL80211_IFTYPE_AP:
  1586. if (!bssid) {
  1587. if (compare_ether_addr(sdata->dev->dev_addr,
  1588. hdr->addr1))
  1589. return 0;
  1590. } else if (!ieee80211_bssid_match(bssid,
  1591. sdata->dev->dev_addr)) {
  1592. if (!(rx->flags & IEEE80211_RX_IN_SCAN))
  1593. return 0;
  1594. rx->flags &= ~IEEE80211_RX_RA_MATCH;
  1595. }
  1596. break;
  1597. case NL80211_IFTYPE_WDS:
  1598. if (bssid || !ieee80211_is_data(hdr->frame_control))
  1599. return 0;
  1600. if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
  1601. return 0;
  1602. break;
  1603. case NL80211_IFTYPE_MONITOR:
  1604. /* take everything */
  1605. break;
  1606. case NL80211_IFTYPE_UNSPECIFIED:
  1607. case __NL80211_IFTYPE_AFTER_LAST:
  1608. /* should never get here */
  1609. WARN_ON(1);
  1610. break;
  1611. }
  1612. return 1;
  1613. }
  1614. /*
  1615. * This is the actual Rx frames handler. as it blongs to Rx path it must
  1616. * be called with rcu_read_lock protection.
  1617. */
  1618. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  1619. struct sk_buff *skb,
  1620. struct ieee80211_rx_status *status,
  1621. struct ieee80211_rate *rate)
  1622. {
  1623. struct ieee80211_local *local = hw_to_local(hw);
  1624. struct ieee80211_sub_if_data *sdata;
  1625. struct ieee80211_hdr *hdr;
  1626. struct ieee80211_rx_data rx;
  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.rate = rate;
  1637. if (ieee80211_is_data(hdr->frame_control) || ieee80211_is_mgmt(hdr->frame_control))
  1638. local->dot11ReceivedFragmentCount++;
  1639. rx.sta = sta_info_get(local, hdr->addr2);
  1640. if (rx.sta) {
  1641. rx.sdata = rx.sta->sdata;
  1642. rx.dev = rx.sta->sdata->dev;
  1643. }
  1644. if ((status->flag & RX_FLAG_MMIC_ERROR)) {
  1645. ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx);
  1646. return;
  1647. }
  1648. if (unlikely(local->sw_scanning || local->hw_scanning))
  1649. rx.flags |= IEEE80211_RX_IN_SCAN;
  1650. ieee80211_parse_qos(&rx);
  1651. ieee80211_verify_ip_alignment(&rx);
  1652. skb = rx.skb;
  1653. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  1654. if (!netif_running(sdata->dev))
  1655. continue;
  1656. if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
  1657. continue;
  1658. bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  1659. rx.flags |= IEEE80211_RX_RA_MATCH;
  1660. prepares = prepare_for_handlers(sdata, bssid, &rx, hdr);
  1661. if (!prepares)
  1662. continue;
  1663. /*
  1664. * frame is destined for this interface, but if it's not
  1665. * also for the previous one we handle that after the
  1666. * loop to avoid copying the SKB once too much
  1667. */
  1668. if (!prev) {
  1669. prev = sdata;
  1670. continue;
  1671. }
  1672. /*
  1673. * frame was destined for the previous interface
  1674. * so invoke RX handlers for it
  1675. */
  1676. skb_new = skb_copy(skb, GFP_ATOMIC);
  1677. if (!skb_new) {
  1678. if (net_ratelimit())
  1679. printk(KERN_DEBUG "%s: failed to copy "
  1680. "multicast frame for %s\n",
  1681. wiphy_name(local->hw.wiphy),
  1682. prev->dev->name);
  1683. continue;
  1684. }
  1685. ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
  1686. prev = sdata;
  1687. }
  1688. if (prev)
  1689. ieee80211_invoke_rx_handlers(prev, &rx, skb);
  1690. else
  1691. dev_kfree_skb(skb);
  1692. }
  1693. #define SEQ_MODULO 0x1000
  1694. #define SEQ_MASK 0xfff
  1695. static inline int seq_less(u16 sq1, u16 sq2)
  1696. {
  1697. return (((sq1 - sq2) & SEQ_MASK) > (SEQ_MODULO >> 1));
  1698. }
  1699. static inline u16 seq_inc(u16 sq)
  1700. {
  1701. return ((sq + 1) & SEQ_MASK);
  1702. }
  1703. static inline u16 seq_sub(u16 sq1, u16 sq2)
  1704. {
  1705. return ((sq1 - sq2) & SEQ_MASK);
  1706. }
  1707. /*
  1708. * As it function blongs to Rx path it must be called with
  1709. * the proper rcu_read_lock protection for its flow.
  1710. */
  1711. u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
  1712. struct tid_ampdu_rx *tid_agg_rx,
  1713. struct sk_buff *skb, u16 mpdu_seq_num,
  1714. int bar_req)
  1715. {
  1716. struct ieee80211_local *local = hw_to_local(hw);
  1717. struct ieee80211_rx_status status;
  1718. u16 head_seq_num, buf_size;
  1719. int index;
  1720. struct ieee80211_supported_band *sband;
  1721. struct ieee80211_rate *rate;
  1722. buf_size = tid_agg_rx->buf_size;
  1723. head_seq_num = tid_agg_rx->head_seq_num;
  1724. /* frame with out of date sequence number */
  1725. if (seq_less(mpdu_seq_num, head_seq_num)) {
  1726. dev_kfree_skb(skb);
  1727. return 1;
  1728. }
  1729. /* if frame sequence number exceeds our buffering window size or
  1730. * block Ack Request arrived - release stored frames */
  1731. if ((!seq_less(mpdu_seq_num, head_seq_num + buf_size)) || (bar_req)) {
  1732. /* new head to the ordering buffer */
  1733. if (bar_req)
  1734. head_seq_num = mpdu_seq_num;
  1735. else
  1736. head_seq_num =
  1737. seq_inc(seq_sub(mpdu_seq_num, buf_size));
  1738. /* release stored frames up to new head to stack */
  1739. while (seq_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  1740. index = seq_sub(tid_agg_rx->head_seq_num,
  1741. tid_agg_rx->ssn)
  1742. % tid_agg_rx->buf_size;
  1743. if (tid_agg_rx->reorder_buf[index]) {
  1744. /* release the reordered frames to stack */
  1745. memcpy(&status,
  1746. tid_agg_rx->reorder_buf[index]->cb,
  1747. sizeof(status));
  1748. sband = local->hw.wiphy->bands[status.band];
  1749. rate = &sband->bitrates[status.rate_idx];
  1750. __ieee80211_rx_handle_packet(hw,
  1751. tid_agg_rx->reorder_buf[index],
  1752. &status, rate);
  1753. tid_agg_rx->stored_mpdu_num--;
  1754. tid_agg_rx->reorder_buf[index] = NULL;
  1755. }
  1756. tid_agg_rx->head_seq_num =
  1757. seq_inc(tid_agg_rx->head_seq_num);
  1758. }
  1759. if (bar_req)
  1760. return 1;
  1761. }
  1762. /* now the new frame is always in the range of the reordering */
  1763. /* buffer window */
  1764. index = seq_sub(mpdu_seq_num, tid_agg_rx->ssn)
  1765. % tid_agg_rx->buf_size;
  1766. /* check if we already stored this frame */
  1767. if (tid_agg_rx->reorder_buf[index]) {
  1768. dev_kfree_skb(skb);
  1769. return 1;
  1770. }
  1771. /* if arrived mpdu is in the right order and nothing else stored */
  1772. /* release it immediately */
  1773. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  1774. tid_agg_rx->stored_mpdu_num == 0) {
  1775. tid_agg_rx->head_seq_num =
  1776. seq_inc(tid_agg_rx->head_seq_num);
  1777. return 0;
  1778. }
  1779. /* put the frame in the reordering buffer */
  1780. tid_agg_rx->reorder_buf[index] = skb;
  1781. tid_agg_rx->stored_mpdu_num++;
  1782. /* release the buffer until next missing frame */
  1783. index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
  1784. % tid_agg_rx->buf_size;
  1785. while (tid_agg_rx->reorder_buf[index]) {
  1786. /* release the reordered frame back to stack */
  1787. memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
  1788. sizeof(status));
  1789. sband = local->hw.wiphy->bands[status.band];
  1790. rate = &sband->bitrates[status.rate_idx];
  1791. __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
  1792. &status, rate);
  1793. tid_agg_rx->stored_mpdu_num--;
  1794. tid_agg_rx->reorder_buf[index] = NULL;
  1795. tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
  1796. index = seq_sub(tid_agg_rx->head_seq_num,
  1797. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  1798. }
  1799. return 1;
  1800. }
  1801. static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
  1802. struct sk_buff *skb)
  1803. {
  1804. struct ieee80211_hw *hw = &local->hw;
  1805. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1806. struct sta_info *sta;
  1807. struct tid_ampdu_rx *tid_agg_rx;
  1808. u16 sc;
  1809. u16 mpdu_seq_num;
  1810. u8 ret = 0;
  1811. int tid;
  1812. sta = sta_info_get(local, hdr->addr2);
  1813. if (!sta)
  1814. return ret;
  1815. /* filter the QoS data rx stream according to
  1816. * STA/TID and check if this STA/TID is on aggregation */
  1817. if (!ieee80211_is_data_qos(hdr->frame_control))
  1818. goto end_reorder;
  1819. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  1820. if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL)
  1821. goto end_reorder;
  1822. tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
  1823. /* qos null data frames are excluded */
  1824. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  1825. goto end_reorder;
  1826. /* new un-ordered ampdu frame - process it */
  1827. /* reset session timer */
  1828. if (tid_agg_rx->timeout) {
  1829. unsigned long expires =
  1830. jiffies + (tid_agg_rx->timeout / 1000) * HZ;
  1831. mod_timer(&tid_agg_rx->session_timer, expires);
  1832. }
  1833. /* if this mpdu is fragmented - terminate rx aggregation session */
  1834. sc = le16_to_cpu(hdr->seq_ctrl);
  1835. if (sc & IEEE80211_SCTL_FRAG) {
  1836. ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
  1837. tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
  1838. ret = 1;
  1839. goto end_reorder;
  1840. }
  1841. /* according to mpdu sequence number deal with reordering buffer */
  1842. mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1843. ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
  1844. mpdu_seq_num, 0);
  1845. end_reorder:
  1846. return ret;
  1847. }
  1848. /*
  1849. * This is the receive path handler. It is called by a low level driver when an
  1850. * 802.11 MPDU is received from the hardware.
  1851. */
  1852. void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
  1853. struct ieee80211_rx_status *status)
  1854. {
  1855. struct ieee80211_local *local = hw_to_local(hw);
  1856. struct ieee80211_rate *rate = NULL;
  1857. struct ieee80211_supported_band *sband;
  1858. if (status->band < 0 ||
  1859. status->band >= IEEE80211_NUM_BANDS) {
  1860. WARN_ON(1);
  1861. return;
  1862. }
  1863. sband = local->hw.wiphy->bands[status->band];
  1864. if (!sband ||
  1865. status->rate_idx < 0 ||
  1866. status->rate_idx >= sband->n_bitrates) {
  1867. WARN_ON(1);
  1868. return;
  1869. }
  1870. rate = &sband->bitrates[status->rate_idx];
  1871. /*
  1872. * key references and virtual interfaces are protected using RCU
  1873. * and this requires that we are in a read-side RCU section during
  1874. * receive processing
  1875. */
  1876. rcu_read_lock();
  1877. /*
  1878. * Frames with failed FCS/PLCP checksum are not returned,
  1879. * all other frames are returned without radiotap header
  1880. * if it was previously present.
  1881. * Also, frames with less than 16 bytes are dropped.
  1882. */
  1883. skb = ieee80211_rx_monitor(local, skb, status, rate);
  1884. if (!skb) {
  1885. rcu_read_unlock();
  1886. return;
  1887. }
  1888. if (!ieee80211_rx_reorder_ampdu(local, skb))
  1889. __ieee80211_rx_handle_packet(hw, skb, status, rate);
  1890. rcu_read_unlock();
  1891. }
  1892. EXPORT_SYMBOL(__ieee80211_rx);
  1893. /* This is a version of the rx handler that can be called from hard irq
  1894. * context. Post the skb on the queue and schedule the tasklet */
  1895. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
  1896. struct ieee80211_rx_status *status)
  1897. {
  1898. struct ieee80211_local *local = hw_to_local(hw);
  1899. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  1900. skb->dev = local->mdev;
  1901. /* copy status into skb->cb for use by tasklet */
  1902. memcpy(skb->cb, status, sizeof(*status));
  1903. skb->pkt_type = IEEE80211_RX_MSG;
  1904. skb_queue_tail(&local->skb_queue, skb);
  1905. tasklet_schedule(&local->tasklet);
  1906. }
  1907. EXPORT_SYMBOL(ieee80211_rx_irqsafe);